summaryrefslogtreecommitdiff
path: root/sfx2/source
diff options
context:
space:
mode:
Diffstat (limited to 'sfx2/source')
-rw-r--r--sfx2/source/appl/app.cxx831
-rw-r--r--sfx2/source/appl/app.hrc274
-rw-r--r--sfx2/source/appl/app.src988
-rw-r--r--sfx2/source/appl/appbas.cxx590
-rwxr-xr-xsfx2/source/appl/appbaslib.cxx252
-rw-r--r--sfx2/source/appl/appcfg.cxx1040
-rw-r--r--sfx2/source/appl/appchild.cxx176
-rw-r--r--sfx2/source/appl/appdata.cxx187
-rw-r--r--sfx2/source/appl/appdde.cxx710
-rw-r--r--sfx2/source/appl/appinit.cxx316
-rw-r--r--sfx2/source/appl/appmain.cxx192
-rw-r--r--sfx2/source/appl/appmisc.cxx335
-rw-r--r--sfx2/source/appl/appopen.cxx1359
-rw-r--r--sfx2/source/appl/appquit.cxx174
-rw-r--r--sfx2/source/appl/appreg.cxx153
-rw-r--r--sfx2/source/appl/appserv.cxx1347
-rw-r--r--sfx2/source/appl/appuno.cxx2429
-rw-r--r--sfx2/source/appl/childwin.cxx855
-rw-r--r--sfx2/source/appl/dde.hrc40
-rw-r--r--sfx2/source/appl/dde.src95
-rw-r--r--sfx2/source/appl/fileobj.cxx706
-rw-r--r--sfx2/source/appl/fileobj.hxx95
-rw-r--r--sfx2/source/appl/fwkhelper.cxx59
-rw-r--r--sfx2/source/appl/helpdispatch.cxx123
-rw-r--r--sfx2/source/appl/helpdispatch.hxx54
-rw-r--r--sfx2/source/appl/helpinterceptor.cxx367
-rw-r--r--sfx2/source/appl/helpinterceptor.hxx173
-rw-r--r--sfx2/source/appl/imagemgr.cxx234
-rw-r--r--sfx2/source/appl/imestatuswindow.cxx231
-rw-r--r--sfx2/source/appl/imestatuswindow.hxx125
-rw-r--r--sfx2/source/appl/impldde.cxx448
-rw-r--r--sfx2/source/appl/impldde.hxx78
-rw-r--r--sfx2/source/appl/linkmgr2.cxx636
-rw-r--r--sfx2/source/appl/linksrc.cxx435
-rw-r--r--sfx2/source/appl/lnkbase2.cxx699
-rw-r--r--sfx2/source/appl/module.cxx450
-rw-r--r--sfx2/source/appl/newhelp.cxx3492
-rw-r--r--sfx2/source/appl/newhelp.hrc84
-rw-r--r--sfx2/source/appl/newhelp.hxx614
-rw-r--r--sfx2/source/appl/newhelp.src592
-rw-r--r--sfx2/source/appl/opengrf.cxx292
-rw-r--r--sfx2/source/appl/panelist.hxx50
-rw-r--r--sfx2/source/appl/sfx.src42
-rw-r--r--sfx2/source/appl/sfxhelp.cxx1080
-rw-r--r--sfx2/source/appl/sfxpicklist.cxx473
-rw-r--r--sfx2/source/appl/shutdownicon.cxx965
-rw-r--r--sfx2/source/appl/shutdownicon.hxx175
-rw-r--r--sfx2/source/appl/shutdowniconOs2.cxx94
-rw-r--r--sfx2/source/appl/shutdowniconaqua.mm510
-rw-r--r--sfx2/source/appl/shutdowniconunx.cxx409
-rw-r--r--sfx2/source/appl/shutdowniconw32.cxx977
-rw-r--r--sfx2/source/appl/workwin.cxx3142
-rw-r--r--sfx2/source/appl/xpackcreator.cxx202
-rw-r--r--sfx2/source/appl/xpackcreator.hxx75
-rw-r--r--sfx2/source/bastyp/bastyp.hrc38
-rw-r--r--sfx2/source/bastyp/bastyp.src66
-rw-r--r--sfx2/source/bastyp/bitset.cxx395
-rw-r--r--sfx2/source/bastyp/fltfnc.cxx1227
-rw-r--r--sfx2/source/bastyp/fltfnc.src75
-rw-r--r--sfx2/source/bastyp/fltlst.cxx118
-rw-r--r--sfx2/source/bastyp/fltlst.hxx67
-rw-r--r--sfx2/source/bastyp/frmhtml.cxx163
-rw-r--r--sfx2/source/bastyp/frmhtmlw.cxx381
-rw-r--r--sfx2/source/bastyp/helper.cxx879
-rw-r--r--sfx2/source/bastyp/mieclip.cxx95
-rw-r--r--sfx2/source/bastyp/minarray.cxx736
-rw-r--r--sfx2/source/bastyp/misc.cxx75
-rw-r--r--sfx2/source/bastyp/progress.cxx753
-rw-r--r--sfx2/source/bastyp/sfxhtml.cxx447
-rw-r--r--sfx2/source/bastyp/sfxresid.cxx73
-rw-r--r--sfx2/source/config/config.hrc41
-rw-r--r--sfx2/source/config/config.src35
-rw-r--r--sfx2/source/config/evntconf.cxx294
-rw-r--r--sfx2/source/control/bindings.cxx2433
-rw-r--r--sfx2/source/control/ctrlitem.cxx466
-rwxr-xr-xsfx2/source/control/dispatch.cxx3180
-rw-r--r--sfx2/source/control/macrconf.cxx874
-rw-r--r--sfx2/source/control/macro.cxx708
-rw-r--r--sfx2/source/control/minfitem.cxx104
-rw-r--r--sfx2/source/control/msg.cxx75
-rw-r--r--sfx2/source/control/msgpool.cxx422
-rw-r--r--sfx2/source/control/objface.cxx685
-rw-r--r--sfx2/source/control/querystatus.cxx241
-rw-r--r--sfx2/source/control/request.cxx978
-rw-r--r--sfx2/source/control/sfxstatuslistener.cxx290
-rw-r--r--sfx2/source/control/shell.cxx1298
-rw-r--r--sfx2/source/control/sorgitm.cxx136
-rw-r--r--sfx2/source/control/statcach.cxx577
-rw-r--r--sfx2/source/control/unoctitm.cxx1013
-rw-r--r--sfx2/source/dialog/about.cxx423
-rw-r--r--sfx2/source/dialog/alienwarn.cxx177
-rw-r--r--sfx2/source/dialog/alienwarn.hrc61
-rw-r--r--sfx2/source/dialog/alienwarn.src92
-rw-r--r--sfx2/source/dialog/basedlgs.cxx1059
-rw-r--r--sfx2/source/dialog/dialog.hrc84
-rw-r--r--sfx2/source/dialog/dialog.src132
-rw-r--r--sfx2/source/dialog/dinfdlg.cxx2466
-rw-r--r--sfx2/source/dialog/dinfdlg.hrc177
-rw-r--r--sfx2/source/dialog/dinfdlg.src947
-rw-r--r--sfx2/source/dialog/dinfedt.cxx66
-rw-r--r--sfx2/source/dialog/dinfedt.hrc38
-rw-r--r--sfx2/source/dialog/dinfedt.src125
-rw-r--r--sfx2/source/dialog/dockwin.cxx2021
-rw-r--r--sfx2/source/dialog/filedlghelper.cxx2921
-rw-r--r--sfx2/source/dialog/filedlghelper.src173
-rw-r--r--sfx2/source/dialog/filedlgimpl.hxx238
-rw-r--r--sfx2/source/dialog/filtergrouping.cxx1274
-rw-r--r--sfx2/source/dialog/filtergrouping.hxx106
-rw-r--r--sfx2/source/dialog/intro.cxx110
-rw-r--r--sfx2/source/dialog/itemconnect.cxx408
-rw-r--r--sfx2/source/dialog/mailmodel.cxx1029
-rw-r--r--sfx2/source/dialog/mailwindow.src76
-rw-r--r--sfx2/source/dialog/mgetempl.cxx682
-rw-r--r--sfx2/source/dialog/mgetempl.hrc39
-rw-r--r--sfx2/source/dialog/mgetempl.src166
-rw-r--r--sfx2/source/dialog/navigat.cxx100
-rw-r--r--sfx2/source/dialog/newstyle.cxx108
-rw-r--r--sfx2/source/dialog/newstyle.hrc33
-rw-r--r--sfx2/source/dialog/newstyle.src105
-rw-r--r--sfx2/source/dialog/partwnd.cxx257
-rw-r--r--sfx2/source/dialog/passwd.cxx255
-rw-r--r--sfx2/source/dialog/passwd.hrc52
-rw-r--r--sfx2/source/dialog/passwd.src165
-rw-r--r--sfx2/source/dialog/printopt.cxx545
-rw-r--r--sfx2/source/dialog/printopt.hrc64
-rw-r--r--sfx2/source/dialog/printopt.src377
-rw-r--r--sfx2/source/dialog/recfloat.cxx280
-rw-r--r--sfx2/source/dialog/recfloat.src87
-rw-r--r--sfx2/source/dialog/securitypage.cxx553
-rwxr-xr-xsfx2/source/dialog/securitypage.hrc52
-rw-r--r--sfx2/source/dialog/securitypage.src174
-rwxr-xr-xsfx2/source/dialog/sfxdlg.cxx44
-rw-r--r--sfx2/source/dialog/splitwin.cxx1304
-rw-r--r--sfx2/source/dialog/srchdlg.cxx202
-rw-r--r--sfx2/source/dialog/srchdlg.hrc43
-rw-r--r--sfx2/source/dialog/srchdlg.src116
-rw-r--r--sfx2/source/dialog/styfitem.cxx187
-rw-r--r--sfx2/source/dialog/styledlg.cxx176
-rw-r--r--sfx2/source/dialog/tabdlg.cxx1798
-rw-r--r--sfx2/source/dialog/taskpane.cxx1299
-rw-r--r--sfx2/source/dialog/taskpane.src47
-rw-r--r--sfx2/source/dialog/templdlg.cxx3039
-rw-r--r--sfx2/source/dialog/templdlg.hrc52
-rw-r--r--sfx2/source/dialog/templdlg.src216
-rw-r--r--sfx2/source/dialog/titledockwin.cxx360
-rw-r--r--sfx2/source/dialog/titledockwin.src39
-rw-r--r--sfx2/source/dialog/tplcitem.cxx185
-rw-r--r--sfx2/source/dialog/tplpitem.cxx120
-rw-r--r--sfx2/source/dialog/versdlg.cxx519
-rw-r--r--sfx2/source/dialog/versdlg.hrc48
-rw-r--r--sfx2/source/dialog/versdlg.src222
-rw-r--r--sfx2/source/doc/DocumentMetadataAccess.cxx1432
-rw-r--r--sfx2/source/doc/Metadatable.cxx1703
-rw-r--r--sfx2/source/doc/QuerySaveDocument.cxx49
-rw-r--r--sfx2/source/doc/SfxDocumentMetaData.cxx2384
-rw-r--r--sfx2/source/doc/doc.hrc221
-rw-r--r--sfx2/source/doc/doc.src528
-rw-r--r--sfx2/source/doc/docfac.cxx491
-rw-r--r--sfx2/source/doc/docfile.cxx3934
-rw-r--r--sfx2/source/doc/docfilt.cxx251
-rw-r--r--sfx2/source/doc/docinf.cxx309
-rw-r--r--sfx2/source/doc/docinsert.cxx305
-rw-r--r--sfx2/source/doc/docmacromode.cxx436
-rw-r--r--sfx2/source/doc/docstoragemodifylistener.cxx96
-rw-r--r--sfx2/source/doc/doctdlg.cxx238
-rw-r--r--sfx2/source/doc/doctdlg.hrc42
-rw-r--r--sfx2/source/doc/doctdlg.src152
-rw-r--r--sfx2/source/doc/doctempl.cxx2735
-rw-r--r--sfx2/source/doc/doctempl.src106
-rw-r--r--sfx2/source/doc/doctemplates.cxx2898
-rw-r--r--sfx2/source/doc/doctemplateslocal.cxx263
-rw-r--r--sfx2/source/doc/doctemplateslocal.hxx88
-rw-r--r--sfx2/source/doc/docvor.cxx2466
-rw-r--r--sfx2/source/doc/docvor.hrc75
-rw-r--r--sfx2/source/doc/docvor.src320
-rw-r--r--sfx2/source/doc/frmdescr.cxx329
-rw-r--r--sfx2/source/doc/graphhelp.cxx529
-rw-r--r--sfx2/source/doc/graphhelp.hxx75
-rw-r--r--sfx2/source/doc/graphhelp.src59
-rw-r--r--sfx2/source/doc/guisaveas.cxx1802
-rw-r--r--sfx2/source/doc/iframe.cxx397
-rw-r--r--sfx2/source/doc/new.cxx741
-rw-r--r--sfx2/source/doc/new.hrc57
-rw-r--r--sfx2/source/doc/new.src275
-rw-r--r--sfx2/source/doc/objcont.cxx1281
-rw-r--r--sfx2/source/doc/objembed.cxx317
-rw-r--r--sfx2/source/doc/objitem.cxx135
-rw-r--r--sfx2/source/doc/objmisc.cxx2585
-rw-r--r--sfx2/source/doc/objserv.cxx1515
-rw-r--r--sfx2/source/doc/objstor.cxx3757
-rw-r--r--sfx2/source/doc/objuno.cxx1350
-rw-r--r--sfx2/source/doc/objxtor.cxx1147
-rwxr-xr-xsfx2/source/doc/oleprops.cxx1227
-rwxr-xr-xsfx2/source/doc/oleprops.hxx404
-rw-r--r--sfx2/source/doc/ownsubfilterservice.cxx165
-rw-r--r--sfx2/source/doc/plugin.cxx266
-rwxr-xr-xsfx2/source/doc/printhelper.cxx832
-rwxr-xr-xsfx2/source/doc/printhelper.hxx69
-rw-r--r--sfx2/source/doc/querytemplate.cxx52
-rw-r--r--sfx2/source/doc/querytemplate.hxx44
-rw-r--r--sfx2/source/doc/sfxacldetect.cxx109
-rw-r--r--sfx2/source/doc/sfxbasemodel.cxx4373
-rw-r--r--sfx2/source/doc/sfxmodelfactory.cxx239
-rwxr-xr-xsfx2/source/doc/syspath.cxx48
-rw-r--r--sfx2/source/doc/syspath.hxx44
-rwxr-xr-xsfx2/source/doc/syspathw32.cxx87
-rw-r--r--sfx2/source/explorer/nochaos.cxx215
-rw-r--r--sfx2/source/inc/SfxDocumentMetaData.hxx49
-rw-r--r--sfx2/source/inc/alienwarn.hxx56
-rw-r--r--sfx2/source/inc/appbas.hxx44
-rw-r--r--sfx2/source/inc/appbaslib.hxx140
-rw-r--r--sfx2/source/inc/appdata.hxx182
-rw-r--r--sfx2/source/inc/doctemplates.hxx102
-rw-r--r--sfx2/source/inc/eventsupplier.hxx264
-rw-r--r--sfx2/source/inc/fltfnc.hxx35
-rw-r--r--sfx2/source/inc/fltoptint.hxx78
-rw-r--r--sfx2/source/inc/helper.hxx78
-rw-r--r--sfx2/source/inc/helpid.hrc342
-rw-r--r--sfx2/source/inc/hexplwnd.hxx101
-rw-r--r--sfx2/source/inc/iframe.hxx93
-rw-r--r--sfx2/source/inc/intro.hxx55
-rw-r--r--sfx2/source/inc/mailmodel.hxx105
-rw-r--r--sfx2/source/inc/mnucfga.hxx52
-rw-r--r--sfx2/source/inc/nfltdlg.hxx66
-rw-r--r--sfx2/source/inc/nochaos.hxx40
-rw-r--r--sfx2/source/inc/objmnctl.hxx56
-rw-r--r--sfx2/source/inc/objshimp.hxx176
-rw-r--r--sfx2/source/inc/openflag.hxx41
-rw-r--r--sfx2/source/inc/ownsubfilterservice.hxx90
-rw-r--r--sfx2/source/inc/partwnd.hxx90
-rw-r--r--sfx2/source/inc/plugin.hxx91
-rw-r--r--sfx2/source/inc/preview.hxx73
-rw-r--r--sfx2/source/inc/recfloat.hxx69
-rw-r--r--sfx2/source/inc/referers.hxx36
-rw-r--r--sfx2/source/inc/sfxlocal.hrc75
-rw-r--r--sfx2/source/inc/sfxpicklist.hxx86
-rw-r--r--sfx2/source/inc/sfxtypes.hxx199
-rw-r--r--sfx2/source/inc/sfxurlrelocator.hxx54
-rw-r--r--sfx2/source/inc/slotserv.hxx84
-rw-r--r--sfx2/source/inc/splitwin.hxx133
-rw-r--r--sfx2/source/inc/statcach.hxx182
-rw-r--r--sfx2/source/inc/templdgi.hxx394
-rw-r--r--sfx2/source/inc/tplcitem.hxx52
-rw-r--r--sfx2/source/inc/tplcomp.hxx224
-rw-r--r--sfx2/source/inc/versdlg.hxx109
-rw-r--r--sfx2/source/inc/virtmenu.hxx159
-rw-r--r--sfx2/source/inc/workwin.hxx391
-rw-r--r--sfx2/source/inet/inettbc.cxx303
-rw-r--r--sfx2/source/layout/factory.cxx68
-rw-r--r--sfx2/source/layout/sfxdialog.cxx38
-rw-r--r--sfx2/source/layout/sfxtabdialog.cxx72
-rw-r--r--sfx2/source/layout/sfxtabpage.cxx89
-rw-r--r--sfx2/source/menu/menu.hrc73
-rw-r--r--sfx2/source/menu/menu.src98
-rw-r--r--sfx2/source/menu/mnuitem.cxx583
-rwxr-xr-xsfx2/source/menu/mnumgr.cxx641
-rw-r--r--sfx2/source/menu/objmnctl.cxx165
-rwxr-xr-xsfx2/source/menu/thessubmenu.cxx241
-rw-r--r--sfx2/source/menu/thessubmenu.hxx103
-rw-r--r--sfx2/source/menu/virtmenu.cxx1361
-rw-r--r--sfx2/source/notify/eventsupplier.cxx920
-rw-r--r--sfx2/source/notify/hintpost.cxx110
-rw-r--r--sfx2/source/statbar/stbitem.cxx692
-rw-r--r--sfx2/source/toolbox/imgmgr.cxx426
-rw-r--r--sfx2/source/toolbox/tbxitem.cxx1895
-rw-r--r--sfx2/source/view/frame.cxx994
-rw-r--r--sfx2/source/view/frame2.cxx481
-rw-r--r--sfx2/source/view/frmload.cxx745
-rw-r--r--sfx2/source/view/impframe.hxx100
-rw-r--r--sfx2/source/view/impviewframe.hxx98
-rw-r--r--sfx2/source/view/ipclient.cxx1169
-rw-r--r--sfx2/source/view/orgmgr.cxx832
-rw-r--r--sfx2/source/view/printer.cxx312
-rw-r--r--sfx2/source/view/sfxbasecontroller.cxx1542
-rw-r--r--sfx2/source/view/userinputinterception.cxx278
-rw-r--r--sfx2/source/view/view.hrc120
-rw-r--r--sfx2/source/view/view.src190
-rw-r--r--sfx2/source/view/viewfac.cxx88
-rw-r--r--sfx2/source/view/viewfrm.cxx3599
-rw-r--r--sfx2/source/view/viewfrm2.cxx523
-rw-r--r--sfx2/source/view/viewimp.hxx85
-rw-r--r--sfx2/source/view/viewprn.cxx914
-rw-r--r--sfx2/source/view/viewsh.cxx2326
283 files changed, 151342 insertions, 0 deletions
diff --git a/sfx2/source/appl/app.cxx b/sfx2/source/appl/app.cxx
new file mode 100644
index 000000000000..727d9f17c493
--- /dev/null
+++ b/sfx2/source/appl/app.cxx
@@ -0,0 +1,831 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#if defined UNX
+#include <limits.h>
+#else // UNX
+#include <stdlib.h>
+#define PATH_MAX _MAX_PATH
+#endif // UNX
+
+#include <sfx2/app.hxx>
+#include <sfx2/frame.hxx>
+#include <vos/process.hxx>
+#include <tools/simplerm.hxx>
+#include <tools/config.hxx>
+#include <basic/basrdll.hxx>
+#include <svtools/asynclink.hxx>
+#include <svl/stritem.hxx>
+#include <vcl/sound.hxx>
+#include <svl/eitem.hxx>
+#include <svl/urlbmk.hxx>
+#include <vcl/msgbox.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+
+#include <svl/svdde.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/tempfile.hxx>
+#include <osl/file.hxx>
+
+#define _SVSTDARR_STRINGSDTOR
+#include <svl/svstdarr.hxx>
+
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/frame/XFrameActionListener.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/FrameActionEvent.hpp>
+#include <com/sun/star/frame/FrameAction.hpp>
+#include <com/sun/star/loader/XImplementationLoader.hpp>
+#include <com/sun/star/loader/CannotActivateFactoryException.hpp>
+#include <com/sun/star/mozilla/XPluginInstance.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <com/sun/star/container/XIndexAccess.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/uri/XUriReferenceFactory.hpp>
+#include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
+#include <basic/basmgr.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <vcl/svapp.hxx>
+#include <rtl/logfile.hxx>
+#include <sfx2/appuno.hxx>
+#include "sfx2/sfxhelp.hxx"
+#include <sfx2/request.hxx>
+#include "sfxtypes.hxx"
+#include "sfx2/sfxresid.hxx"
+#include "arrdecl.hxx"
+#include <sfx2/progress.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+#include "fltfnc.hxx"
+#include "nfltdlg.hxx"
+#include <sfx2/new.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/genlink.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "appdata.hxx"
+#include "openflag.hxx"
+#include "app.hrc"
+#include "virtmenu.hxx"
+#include <sfx2/module.hxx>
+#include <sfx2/event.hxx>
+#include "imestatuswindow.hxx"
+#include "workwin.hxx"
+#include <sfx2/module.hxx>
+#include <sfx2/tbxctrl.hxx>
+#include <sfx2/sfxdlg.hxx>
+#include "sfx2/stbitem.hxx"
+#include "eventsupplier.hxx"
+#include <sfx2/dockwin.hxx>
+#include <tools/svlibrary.hxx>
+
+#ifdef DBG_UTIL
+#include <sfx2/tbxctrl.hxx>
+#include <sfx2/mnuitem.hxx>
+#endif
+
+#if defined( WNT ) || defined( OS2 )
+#define DDE_AVAILABLE
+#endif
+
+#include <unotools/saveopt.hxx>
+#include <unotools/undoopt.hxx>
+#include <svtools/helpopt.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/viewoptions.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <unotools/historyoptions.hxx>
+#include <svtools/menuoptions.hxx>
+#include <svtools/miscopt.hxx>
+#include <unotools/useroptions.hxx>
+#include <unotools/startoptions.hxx>
+#include <unotools/securityoptions.hxx>
+#include <unotools/localisationoptions.hxx>
+#include <unotools/inetoptions.hxx>
+#include <unotools/fontoptions.hxx>
+#include <unotools/internaloptions.hxx>
+#include <unotools/workingsetoptions.hxx>
+#include <unotools/syslocaleoptions.hxx>
+#include <unotools/syslocale.hxx>
+#include <framework/addonsoptions.hxx>
+#include <svtools/ttprops.hxx>
+#include <unotools/extendedsecurityoptions.hxx>
+
+using namespace ::com::sun::star;
+
+// Static member
+SfxApplication* SfxApplication::pApp = NULL;
+static BasicDLL* pBasic = NULL;
+
+class SfxPropertyHandler : public PropertyHandler
+{
+ virtual void Property( ApplicationProperty& );
+};
+
+static SfxPropertyHandler* pPropertyHandler = 0;
+
+SfxPropertyHandler* GetOrCreatePropertyHandler()
+{
+ if ( !pPropertyHandler )
+ {
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
+ if ( !pPropertyHandler )
+ pPropertyHandler = new SfxPropertyHandler;
+ }
+
+ return pPropertyHandler;
+}
+
+void SfxPropertyHandler::Property( ApplicationProperty& rProp )
+{
+ TTProperties* pTTProperties = PTR_CAST( TTProperties, &rProp );
+ if ( pTTProperties )
+ {
+ pTTProperties->nPropertyVersion = TT_PROPERTIES_VERSION;
+ switch ( pTTProperties->nActualPR )
+ {
+ case TT_PR_SLOTS:
+ {
+ pTTProperties->nSidOpenUrl = SID_OPENURL;
+ pTTProperties->nSidFileName = SID_FILE_NAME;
+ pTTProperties->nSidNewDocDirect = SID_NEWDOCDIRECT;
+ pTTProperties->nSidCopy = SID_COPY;
+ pTTProperties->nSidPaste = SID_PASTE;
+ pTTProperties->nSidSourceView = SID_SOURCEVIEW;
+ pTTProperties->nSidSelectAll = SID_SELECTALL;
+ pTTProperties->nSidReferer = SID_REFERER;
+ pTTProperties->nActualPR = 0;
+ }
+ break;
+ case TT_PR_DISPATCHER:
+ {
+ // interface for TestTool
+ SfxViewFrame* pViewFrame=0;
+ SfxDispatcher* pDispatcher=0;
+ pViewFrame = SfxViewFrame::Current();
+ if ( !pViewFrame )
+ pViewFrame = SfxViewFrame::GetFirst();
+ if ( pViewFrame )
+ pDispatcher = pViewFrame->GetDispatcher();
+ else
+ pDispatcher = NULL;
+ if ( !pDispatcher )
+ pTTProperties->nActualPR = TT_PR_ERR_NODISPATCHER;
+ else
+ {
+ pDispatcher->SetExecuteMode(EXECUTEMODE_DIALOGASYNCHRON);
+ if ( pTTProperties->mnSID == SID_NEWDOCDIRECT
+ || pTTProperties->mnSID == SID_OPENDOC )
+ {
+ SfxPoolItem** pArgs = pTTProperties->mppArgs;
+ SfxAllItemSet aSet( SFX_APP()->GetPool() );
+ if ( pArgs && *pArgs )
+ {
+ for ( SfxPoolItem **pArg = pArgs; *pArg; ++pArg )
+ aSet.Put( **pArg );
+ }
+ if ( pTTProperties->mnSID == SID_NEWDOCDIRECT )
+ {
+ String aFactory = String::CreateFromAscii("private:factory/");
+ if ( pArgs && *pArgs )
+ {
+ SFX_ITEMSET_ARG( &aSet, pFactoryName, SfxStringItem, SID_NEWDOCDIRECT, FALSE );
+ if ( pFactoryName )
+ aFactory += pFactoryName->GetValue();
+ else
+ aFactory += String::CreateFromAscii("swriter");
+ }
+ else
+ aFactory += String::CreateFromAscii("swriter");
+
+ aSet.Put( SfxStringItem( SID_FILE_NAME, aFactory ) );
+ aSet.ClearItem( SID_NEWDOCDIRECT );
+ pTTProperties->mnSID = SID_OPENDOC;
+ }
+
+ aSet.Put( SfxStringItem( SID_TARGETNAME, DEFINE_CONST_UNICODE("_blank") ) );
+ if ( pDispatcher->ExecuteFunction( pTTProperties->mnSID, aSet, pTTProperties->mnMode )
+ == EXECUTE_NO )
+ pTTProperties->nActualPR = TT_PR_ERR_NOEXECUTE;
+ else
+ pTTProperties->nActualPR = 0;
+ }
+ else
+ {
+ if ( pDispatcher->ExecuteFunction(
+ pTTProperties->mnSID, pTTProperties->mppArgs, pTTProperties->mnMode )
+ == EXECUTE_NO )
+ pTTProperties->nActualPR = TT_PR_ERR_NOEXECUTE;
+ else
+ pTTProperties->nActualPR = 0;
+ }
+ }
+ }
+ break;
+/*
+ case TT_PR_IMG:
+ {
+ SvDataMemberObjectRef aDataObject = new SvDataMemberObject();
+ SvData* pDataBmp = new SvData( FORMAT_BITMAP );
+ pDataBmp->SetData( pTTProperties->mpBmp );
+ aDataObject->Append( pDataBmp );
+ aDataObject->CopyClipboard();
+ pTTProperties->nActualPR = 0;
+ }
+ break;
+*/
+ default:
+ {
+ pTTProperties->nPropertyVersion = 0;
+ }
+ }
+ return;
+ }
+}
+
+#include <framework/imageproducer.hxx>
+#include <framework/acceleratorinfo.hxx>
+#include <framework/sfxhelperfunctions.hxx>
+#include "sfx2/imagemgr.hxx"
+#include "fwkhelper.hxx"
+
+::osl::Mutex SfxApplication::gMutex;
+
+SfxApplication* SfxApplication::GetOrCreate()
+{
+ // SFX on demand
+ ::osl::MutexGuard aGuard(SfxApplication::gMutex);
+ if ( !pApp )
+ {
+ SfxApplication *pNew = new SfxApplication;
+
+ //TODO/CLEANUP
+ //ist das Mutex-Handling OK?
+ static ::osl::Mutex aProtector;
+ ::osl::MutexGuard aGuard2( aProtector );
+
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::SetApp" );
+ pApp = pNew;
+
+ // at the moment a bug may occur when Initialize_Impl returns FALSE, but this is only temporary because all code that may cause such a
+ // fault will be moved outside the SFX
+ pApp->Initialize_Impl();
+
+ ::framework::SetImageProducer( GetImage );
+ ::framework::SetRefreshToolbars( RefreshToolbars );
+ ::framework::SetToolBoxControllerCreator( SfxToolBoxControllerFactory );
+ ::framework::SetStatusBarControllerCreator( SfxStatusBarControllerFactory );
+ ::framework::SetDockingWindowCreator( SfxDockingWindowFactory );
+ ::framework::SetIsDockingWindowVisible( IsDockingWindowVisible );
+ ::framework::SetActivateToolPanel( &SfxViewFrame::ActivateToolPanel );
+
+ SfxHelp* pSfxHelp = new SfxHelp;
+ Application::SetHelp( pSfxHelp );
+ if ( SvtHelpOptions().IsHelpTips() )
+ Help::EnableQuickHelp();
+ else
+ Help::DisableQuickHelp();
+ if ( SvtHelpOptions().IsHelpTips() && SvtHelpOptions().IsExtendedHelp() )
+ Help::EnableBalloonHelp();
+ else
+ Help::DisableBalloonHelp();
+ }
+ return pApp;
+}
+
+SfxApplication::SfxApplication()
+ : pAppData_Impl( 0 )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::SfxApplication" );
+
+ SetName( DEFINE_CONST_UNICODE("StarOffice") );
+ GetpApp()->SetPropertyHandler( GetOrCreatePropertyHandler() );
+
+ SvtViewOptions::AcquireOptions();
+
+ pAppData_Impl = new SfxAppData_Impl( this );
+ pAppData_Impl->UpdateApplicationSettings( SvtMenuOptions().IsEntryHidingEnabled() );
+ pAppData_Impl->m_xImeStatusWindow->init();
+ pApp->PreInit();
+
+ RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ initialize DDE" );
+
+#ifdef DDE_AVAILABLE
+#ifndef DBG_UTIL
+ InitializeDde();
+#else
+ if( !InitializeDde() )
+ {
+ ByteString aStr( "Kein DDE-Service moeglich. Fehler: " );
+ if( GetDdeService() )
+ aStr += ByteString::CreateFromInt32(GetDdeService()->GetError());
+ else
+ aStr += '?';
+ DBG_ASSERT( sal_False, aStr.GetBuffer() );
+ }
+#endif
+#endif
+
+ if ( !InitLabelResMgr( "iso" ) )
+ // no "iso" resource -> search for "ooo" resource
+ InitLabelResMgr( "ooo", true );
+ pBasic = new BasicDLL;
+
+ StarBASIC::SetGlobalErrorHdl( LINK( this, SfxApplication, GlobalBasicErrorHdl_Impl ) );
+
+
+
+ RTL_LOGFILE_CONTEXT_TRACE( aLog, "} initialize DDE" );
+}
+
+SfxApplication::~SfxApplication()
+{
+ Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
+
+ SfxModule::DestroyModules_Impl();
+
+ // delete global options
+ SvtViewOptions::ReleaseOptions();
+ delete pBasic;
+
+ if ( !pAppData_Impl->bDowning )
+ Deinitialize();
+
+ delete pAppData_Impl;
+ pApp = 0;
+}
+
+//====================================================================
+
+const String& SfxApplication::GetLastDir_Impl() const
+
+/* [Beschreibung]
+
+ Interne Methode, mit der im SFx das zuletzt mit der Methode
+ <SfxApplication::SetLastDir_Impl()> gesetzte Verzeichnis
+ zurueckgegeben wird.
+
+ Dieses ist i.d.R. das zuletzt durch den SfxFileDialog
+ angesprochene Verzeichnis.
+
+ [Querverweis]
+ <SfxApplication::SetLastDir_Impl()>
+*/
+
+{
+ return pAppData_Impl->aLastDir;
+}
+
+const String& SfxApplication::GetLastSaveDirectory() const
+
+/* [Beschreibung]
+
+ Wie <SfxApplication::GetLastDir_Impl()>, nur extern
+
+ [Querverweis]
+ <SfxApplication::GetLastDir_Impl()>
+*/
+
+{
+ return GetLastDir_Impl();
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::SetLastDir_Impl
+(
+ const String& rNewDir /* kompletter Verzeichnis-Pfad als String */
+ )
+
+/* [Beschreibung]
+
+ Interne Methode, mit der ein Verzeichnis-Pfad gesetzt wird, der
+ zuletzt (z.B. durch den SfxFileDialog) angesprochen wurde.
+
+ [Querverweis]
+ <SfxApplication::GetLastDir_Impl()>
+*/
+
+{
+ pAppData_Impl->aLastDir = rNewDir;
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::ResetLastDir()
+{
+ String aEmpty;
+ pAppData_Impl->aLastDir = aEmpty;
+}
+
+//--------------------------------------------------------------------
+
+SfxDispatcher* SfxApplication::GetDispatcher_Impl()
+{
+ return pAppData_Impl->pViewFrame? pAppData_Impl->pViewFrame->GetDispatcher(): pAppData_Impl->pAppDispat;
+}
+
+//--------------------------------------------------------------------
+void SfxApplication::SetViewFrame_Impl( SfxViewFrame *pFrame )
+{
+ if ( pFrame != pAppData_Impl->pViewFrame )
+ {
+ // get the containerframes ( if one of the frames is an InPlaceFrame )
+ SfxViewFrame *pOldContainerFrame = pAppData_Impl->pViewFrame;
+ while ( pOldContainerFrame && pOldContainerFrame->GetParentViewFrame_Impl() )
+ pOldContainerFrame = pOldContainerFrame->GetParentViewFrame_Impl();
+ SfxViewFrame *pNewContainerFrame = pFrame;
+ while ( pNewContainerFrame && pNewContainerFrame->GetParentViewFrame_Impl() )
+ pNewContainerFrame = pNewContainerFrame->GetParentViewFrame_Impl();
+
+ // DocWinActivate : both frames belong to the same TopWindow
+ // TopWinActivate : both frames belong to different TopWindows
+// not used anymore!
+// BOOL bDocWinActivate = pOldContainerFrame && pNewContainerFrame &&
+// pOldContainerFrame->GetTopViewFrame() == pNewContainerFrame->GetTopViewFrame();
+ BOOL bTaskActivate = pOldContainerFrame != pNewContainerFrame;
+
+ if ( pOldContainerFrame )
+ {
+ if ( bTaskActivate )
+ NotifyEvent( SfxViewEventHint( SFX_EVENT_DEACTIVATEDOC, GlobalEventConfig::GetEventName(STR_EVENT_DEACTIVATEDOC), pOldContainerFrame->GetObjectShell(), pOldContainerFrame->GetFrame().GetController() ) );
+ pOldContainerFrame->DoDeactivate( bTaskActivate, pFrame );
+
+ if( pOldContainerFrame->GetProgress() )
+ pOldContainerFrame->GetProgress()->Suspend();
+ }
+
+ pAppData_Impl->pViewFrame = pFrame;
+
+ //const SfxObjectShell* pSh = pViewFrame ? pViewFrame->GetObjectShell() : 0;
+ //if ( !pSh )
+ //{
+ // // otherwise BaseURL is set in activation of document
+ // INetURLObject aObject( SvtPathOptions().GetWorkPath() );
+ // aObject.setFinalSlash();
+ // INetURLObject::SetBaseURL( aObject.GetMainURL( INetURLObject::NO_DECODE ) );
+ //}
+
+ if( pNewContainerFrame )
+ {
+ pNewContainerFrame->DoActivate( bTaskActivate );
+ if ( bTaskActivate && pNewContainerFrame->GetObjectShell() )
+ {
+ pNewContainerFrame->GetObjectShell()->PostActivateEvent_Impl( pNewContainerFrame );
+ NotifyEvent(SfxViewEventHint(SFX_EVENT_ACTIVATEDOC, GlobalEventConfig::GetEventName(STR_EVENT_ACTIVATEDOC), pNewContainerFrame->GetObjectShell(), pNewContainerFrame->GetFrame().GetController() ) );
+ }
+
+ SfxProgress *pProgress = pNewContainerFrame->GetProgress();
+ if ( pProgress )
+ {
+ if( pProgress->IsSuspended() )
+ pProgress->Resume();
+ else
+ pProgress->SetState( pProgress->GetState() );
+ }
+
+ if ( pAppData_Impl->pViewFrame->GetViewShell() )
+ {
+ SfxDispatcher* pDisp = pAppData_Impl->pViewFrame->GetDispatcher();
+ pDisp->Flush();
+ pDisp->Update_Impl(sal_True);
+ }
+ }
+ }
+
+ // even if the frame actually didn't change, ensure its document is forwarded
+ // to SfxObjectShell::SetCurrentComponent.
+ // Otherwise, the CurrentComponent might not be correct, in case it has meanwhile
+ // been reset to some other document, by some non-SFX component.
+ // #i49133# / 2007-12-19 / frank.schoenheit@sun.com
+ if ( pFrame && pFrame->GetViewShell() )
+ pFrame->GetViewShell()->SetCurrentDocument();
+}
+
+//--------------------------------------------------------------------
+
+short SfxApplication::QuerySave_Impl( SfxObjectShell& rDoc, sal_Bool /*bAutoSave*/ )
+{
+ if ( !rDoc.IsModified() )
+ return RET_NO;
+
+ String aMsg( SfxResId( STR_ISMODIFIED ) );
+ aMsg.SearchAndReplaceAscii( "%1", rDoc.GetTitle() );
+
+ SfxFrame& rFrame = SfxViewFrame::GetFirst(&rDoc)->GetFrame();
+ rFrame.Appear();
+
+ WinBits nBits = WB_YES_NO_CANCEL | WB_DEF_NO;
+ QueryBox aBox( &rFrame.GetWindow(), nBits, aMsg );
+
+ return aBox.Execute();
+}
+
+//---------------------------------------------------------------------
+
+ResMgr* SfxApplication::CreateResManager( const char *pPrefix )
+{
+ String aMgrName = String::CreateFromAscii( pPrefix );
+ return ResMgr::CreateResMgr(U2S(aMgrName));
+}
+
+//---------------------------------------------------------------------
+
+SimpleResMgr* SfxApplication::CreateSimpleResManager()
+{
+ SimpleResMgr *pRet;
+ const AllSettings& rAllSettings = Application::GetSettings();
+ ::com::sun::star::lang::Locale aLocale = rAllSettings.GetUILocale();
+ pRet = new SimpleResMgr( CREATEVERSIONRESMGR_NAME(sfx), aLocale );
+
+ return pRet;
+}
+
+//--------------------------------------------------------------------
+
+ResMgr* SfxApplication::GetSfxResManager()
+{
+ return SfxResId::GetResMgr();
+}
+
+//--------------------------------------------------------------------
+
+ResMgr* SfxApplication::GetLabelResManager() const
+{
+ return pAppData_Impl->pLabelResMgr;
+}
+
+//--------------------------------------------------------------------
+
+SimpleResMgr* SfxApplication::GetSimpleResManager()
+{
+ if ( !pAppData_Impl->pSimpleResManager )
+ pAppData_Impl->pSimpleResManager = CreateSimpleResManager();
+ return pAppData_Impl->pSimpleResManager;
+}
+
+//------------------------------------------------------------------------
+
+void SfxApplication::SetProgress_Impl
+(
+ SfxProgress *pProgress
+
+)
+{
+ DBG_ASSERT( ( !pAppData_Impl->pProgress && pProgress ) ||
+ ( pAppData_Impl->pProgress && !pProgress ),
+ "Progress acitivation/deacitivation mismatch" );
+
+ if ( pAppData_Impl->pProgress && pProgress )
+ {
+ pAppData_Impl->pProgress->Suspend();
+ pAppData_Impl->pProgress->UnLock();
+ delete pAppData_Impl->pProgress;
+ }
+
+ pAppData_Impl->pProgress = pProgress;
+}
+
+//------------------------------------------------------------------------
+
+sal_uInt16 SfxApplication::GetFreeIndex()
+{
+ return pAppData_Impl->aIndexBitSet.GetFreeIndex()+1;
+}
+
+//------------------------------------------------------------------------
+
+void SfxApplication::ReleaseIndex(sal_uInt16 i)
+{
+ pAppData_Impl->aIndexBitSet.ReleaseIndex(i-1);
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::EnterAsynchronCall_Impl()
+{
+ ++pAppData_Impl->nAsynchronCalls;
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::LeaveAsynchronCall_Impl()
+{
+ --pAppData_Impl->nAsynchronCalls;
+}
+
+//--------------------------------------------------------------------
+
+FASTBOOL SfxApplication::IsInAsynchronCall_Impl() const
+{
+ return pAppData_Impl->nAsynchronCalls > 0;
+}
+
+//--------------------------------------------------------------------
+
+Window* SfxApplication::GetTopWindow() const
+{
+ SfxWorkWindow* pWork = GetWorkWindow_Impl( SfxViewFrame::Current() );
+ return pWork ? pWork->GetWindow() : NULL;
+}
+
+//--------------------------------------------------------------------
+
+uno::Reference< task::XStatusIndicator > SfxApplication::GetStatusIndicator() const
+{
+ if ( !pAppData_Impl->pViewFrame )
+ return uno::Reference< task::XStatusIndicator >();
+
+ SfxViewFrame *pTop = pAppData_Impl->pViewFrame;
+ while ( pTop->GetParentViewFrame_Impl() )
+ pTop = pTop->GetParentViewFrame_Impl();
+
+ return pTop->GetFrame().GetWorkWindow_Impl()->GetStatusIndicator();
+}
+
+SfxTbxCtrlFactArr_Impl& SfxApplication::GetTbxCtrlFactories_Impl() const
+{
+ return *pAppData_Impl->pTbxCtrlFac;
+}
+
+SfxStbCtrlFactArr_Impl& SfxApplication::GetStbCtrlFactories_Impl() const
+{
+ return *pAppData_Impl->pStbCtrlFac;
+}
+
+SfxMenuCtrlFactArr_Impl& SfxApplication::GetMenuCtrlFactories_Impl() const
+{
+ return *pAppData_Impl->pMenuCtrlFac;
+}
+
+SfxViewFrameArr_Impl& SfxApplication::GetViewFrames_Impl() const
+{
+ return *pAppData_Impl->pViewFrames;
+}
+
+SfxViewShellArr_Impl& SfxApplication::GetViewShells_Impl() const
+{
+ return *pAppData_Impl->pViewShells;
+}
+
+SfxObjectShellArr_Impl& SfxApplication::GetObjectShells_Impl() const
+{
+ return *pAppData_Impl->pObjShells;
+}
+
+void SfxApplication::Invalidate( USHORT nId )
+{
+ for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame ) )
+ Invalidate_Impl( pFrame->GetBindings(), nId );
+}
+
+#define DOSTRING( x ) #x
+#define STRING( x ) DOSTRING( x )
+
+typedef long (SAL_CALL *basicide_handle_basic_error)(void*);
+typedef rtl_uString* (SAL_CALL *basicide_choose_macro)(void*, BOOL, rtl_uString*);
+typedef void* (SAL_CALL *basicide_macro_organizer)(INT16);
+
+extern "C" { static void SAL_CALL thisModule() {} }
+
+IMPL_LINK( SfxApplication, GlobalBasicErrorHdl_Impl, StarBASIC*, pStarBasic )
+{
+ // get basctl dllname
+ static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) );
+
+ // load module
+ oslModule handleMod = osl_loadModuleRelative(
+ &thisModule, aLibName.pData, 0 );
+
+ // get symbol
+ ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_handle_basic_error" ) );
+ basicide_handle_basic_error pSymbol = (basicide_handle_basic_error) osl_getFunctionSymbol( handleMod, aSymbol.pData );
+
+ // call basicide_handle_basic_error in basctl
+ long nRet = pSymbol( pStarBasic );
+
+ return nRet;
+}
+
+sal_Bool SfxApplication::IsXScriptURL( const String& rScriptURL )
+{
+ sal_Bool result = FALSE;
+
+ ::com::sun::star::uno::Reference
+ < ::com::sun::star::lang::XMultiServiceFactory > xSMgr =
+ ::comphelper::getProcessServiceFactory();
+
+ ::com::sun::star::uno::Reference
+ < ::com::sun::star::uri::XUriReferenceFactory >
+ xFactory( xSMgr->createInstance(
+ ::rtl::OUString::createFromAscii(
+ "com.sun.star.uri.UriReferenceFactory" ) ),
+ ::com::sun::star::uno::UNO_QUERY );
+
+ if ( xFactory.is() )
+ {
+ try
+ {
+ ::com::sun::star::uno::Reference
+ < ::com::sun::star::uri::XVndSunStarScriptUrl >
+ xUrl( xFactory->parse( rScriptURL ),
+ ::com::sun::star::uno::UNO_QUERY );
+
+ if ( xUrl.is() )
+ {
+ result = TRUE;
+ }
+ }
+ catch ( ::com::sun::star::uno::RuntimeException& )
+ {
+ // ignore, will just return FALSE
+ }
+ }
+ return result;
+}
+
+::rtl::OUString
+SfxApplication::ChooseScript()
+{
+ ::rtl::OUString aScriptURL;
+
+ SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
+ if ( pFact )
+ {
+ OSL_TRACE("create selector dialog");
+
+ const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+ const SfxFrame* pFrame = pViewFrame ? &pViewFrame->GetFrame() : NULL;
+ uno::Reference< frame::XFrame > xFrame( pFrame ? pFrame->GetFrameInterface() : uno::Reference< frame::XFrame >() );
+
+ AbstractScriptSelectorDialog* pDlg =
+ pFact->CreateScriptSelectorDialog( NULL, FALSE, xFrame );
+
+ OSL_TRACE("done, now exec it");
+
+ USHORT nRet = pDlg->Execute();
+
+ OSL_TRACE("has returned");
+
+ if ( nRet == RET_OK )
+ {
+ aScriptURL = pDlg->GetScriptURL();
+ }
+
+ delete pDlg;
+ }
+ return aScriptURL;
+}
+
+void SfxApplication::MacroOrganizer( INT16 nTabId )
+{
+ // get basctl dllname
+ static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) );
+
+ // load module
+ oslModule handleMod = osl_loadModuleRelative(
+ &thisModule, aLibName.pData, 0 );
+
+ // get symbol
+ ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_macro_organizer" ) );
+ basicide_macro_organizer pSymbol = (basicide_macro_organizer) osl_getFunctionSymbol( handleMod, aSymbol.pData );
+
+ // call basicide_choose_macro in basctl
+ pSymbol( nTabId );
+}
+
diff --git a/sfx2/source/appl/app.hrc b/sfx2/source/appl/app.hrc
new file mode 100644
index 000000000000..dca172269443
--- /dev/null
+++ b/sfx2/source/appl/app.hrc
@@ -0,0 +1,274 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_APP_HRC
+#define _SFX_APP_HRC
+
+#include <sfx2/sfx.hrc>
+
+// #defines *****************************************************************
+
+#define ACC_IBM (RID_SFX_APP_START+2)
+#define MSG_ERR_WRITE_CFG (RID_SFX_APP_START+2)
+#define MSG_ERR_READ_CFG (RID_SFX_APP_START+3)
+#define MSG_ERR_OPEN_CFG (RID_SFX_APP_START+4)
+#define MSG_ERR_FILETYPE_CFG (RID_SFX_APP_START+5)
+#define MSG_ERR_VERSION_CFG (RID_SFX_APP_START+6)
+#define MSG_ERR_NO_WEBBROWSER_FOUND (RID_SFX_APP_START+7)
+
+// Note: no longer in use
+// #define MSG_ERR_EXTERNAL_APP_NOT_FOUND (RID_SFX_APP_START+8)
+
+#define MSG_ISPRINTING_QUERYABORT (RID_SFX_APP_START+9)
+#define MSG_CANT_QUIT (RID_SFX_APP_START+10)
+#define STR_ISMODIFIED (RID_SFX_APP_START+11)
+#define STR_AUTOSAVE (RID_SFX_APP_START+12)
+#define STR_MAIL (RID_SFX_APP_START+13)
+#define MSG_ERR_WRITE_SBL (RID_SFX_APP_START+14)
+#define MSG_IS_SERVER (RID_SFX_APP_START+15)
+
+#define STR_RESEXCEPTION (RID_SFX_APP_START+21)
+#define STR_SYSRESEXCEPTION (RID_SFX_APP_START+22)
+#define STR_DOUBLEEXCEPTION (RID_SFX_APP_START+23)
+#define STR_RESWARNING (RID_SFX_APP_START+24)
+#define STR_ERR_NOTEMPLATE (RID_SFX_APP_START+27)
+#define STR_RECOVER_TITLE (RID_SFX_APP_START+28)
+#define STR_RECOVER_QUERY (RID_SFX_APP_START+29)
+#define STR_RECOVER_PREPARED (RID_SFX_APP_START+30)
+#define MSG_ERR_SOINIT (RID_SFX_APP_START+31)
+
+#define MSG_IOERR_FILE_NOT_FOUND (RID_SFX_APP_START+32)
+#define MSG_IOERR_PATH_NOT_FOUND (RID_SFX_APP_START+33)
+#define MSG_IOERR_TOO_MANY_OPEN_FILES (RID_SFX_APP_START+34)
+#define MSG_IOERR_ACCESS_DENIED (RID_SFX_APP_START+35)
+#define MSG_IOERR_INVALID_ACCESS (RID_SFX_APP_START+36)
+#define MSG_IOERR_INVALID_HANDLE (RID_SFX_APP_START+37)
+#define MSG_IOERR_CANNOT_MAKE (RID_SFX_APP_START+38)
+#define MSG_IOERR_SHARING (RID_SFX_APP_START+39)
+#define MSG_IOERR_INVALID_PARAMETER (RID_SFX_APP_START+40)
+#define MSG_IOERR_GENERAL (RID_SFX_APP_START+41)
+
+#define RID_FULLSCREENTOOLBOX (RID_SFX_APP_START+42)
+#define RID_RECORDINGTOOLBOX (RID_SFX_APP_START+43)
+#define RID_ENVTOOLBOX (RID_SFX_APP_START+44)
+
+#define STR_QUITAPP (RID_SFX_APP_START+59)
+#define STR_EXITANDRETURN (RID_SFX_APP_START+60)
+#define STR_ERR_NOFILE (RID_SFX_APP_START+61)
+#define STR_EXTHELPSTATUS (RID_SFX_APP_START+62)
+
+#define STR_ADDRESS_NAME (RID_SFX_APP_START+65)
+
+#define RID_STR_HLPFILENOTEXIST (RID_SFX_APP_START+68)
+#define RID_STR_HLPAPPNOTSTARTED (RID_SFX_APP_START+69)
+
+#define STR_NODOUBLE (RID_SFX_APP_START+75)
+#define STR_NOPRINTER (RID_SFX_APP_START+76)
+
+#define MSG_SIGNAL (RID_SFX_APP_START+77)
+
+#define RID_STR_HELP (RID_SFX_APP_START+79)
+#define RID_STR_NOAUTOSTARTHELPAGENT (RID_SFX_APP_START+80)
+#define RID_HELPBAR (RID_SFX_APP_START+81)
+#define RID_SPECIALCONFIG_ERROR (RID_SFX_APP_START+82)
+
+#define STR_MEMINFO_HEADER (RID_SFX_APP_START+84)
+#define STR_MEMINFO_FOOTER (RID_SFX_APP_START+85)
+#define STR_MEMINFO_OBJINFO (RID_SFX_APP_START+86)
+
+#define RID_PLUGIN (RID_SFX_APP_START+87)
+
+#define RID_WARN_POST_MAILTO (RID_SFX_APP_START+88)
+
+#define RID_STR_NOWELCOMESCREEN (RID_SFX_APP_START+91)
+
+// --> PB 2004-08-20 #i33095#
+/* obsolete
+#define STR_EDITOBJECT (RID_SFX_APP_START+92)
+#define STR_OPENOBJECT (RID_SFX_APP_START+93)
+*/
+
+#define STR_CORRUPT_INSTALLATION (RID_SFX_APP_START+94)
+#define IDS_SBERR_STOREREF (RID_SFX_APP_START+97)
+
+#define CONFIG_PATH_START (RID_SFX_APP_START+98)
+
+#define STR_KEY_ADDINS_PATH (CONFIG_PATH_START+0)
+#define STR_KEY_AUTOCORRECT_DIR (CONFIG_PATH_START+1)
+#define STR_KEY_GLOSSARY_PATH (CONFIG_PATH_START+2)
+#define STR_KEY_BACKUP_PATH (CONFIG_PATH_START+3)
+#define STR_KEY_BASIC_PATH (CONFIG_PATH_START+4)
+#define STR_KEY_BITMAP_PATH (CONFIG_PATH_START+5)
+#define STR_KEY_CONFIG_DIR (CONFIG_PATH_START+6)
+#define STR_KEY_DICTIONARY_PATH (CONFIG_PATH_START+7)
+#define STR_KEY_FAVORITES_DIR (CONFIG_PATH_START+8)
+#define STR_KEY_FILTER_PATH (CONFIG_PATH_START+9)
+#define STR_KEY_GALLERY_DIR (CONFIG_PATH_START+10)
+#define STR_KEY_GRAPHICS_PATH (CONFIG_PATH_START+11)
+#define STR_KEY_HELP_DIR (CONFIG_PATH_START+12)
+#define STR_KEY_LINGUISTIC_DIR (CONFIG_PATH_START+13)
+#define STR_KEY_MODULES_PATH (CONFIG_PATH_START+14)
+#define STR_KEY_PALETTE_PATH (CONFIG_PATH_START+15)
+#define STR_KEY_PLUGINS_PATH (CONFIG_PATH_START+16)
+#define STR_KEY_STORAGE_DIR (CONFIG_PATH_START+17)
+#define STR_KEY_TEMP_PATH (CONFIG_PATH_START+18)
+#define STR_KEY_TEMPLATE_PATH (CONFIG_PATH_START+19)
+#define STR_KEY_USERCONFIG_PATH (CONFIG_PATH_START+20)
+#define STR_KEY_USERDICTIONARY_DIR (CONFIG_PATH_START+21)
+#define STR_KEY_WORK_PATH (CONFIG_PATH_START+22)
+
+#define WIN_HELPINDEX (RID_SFX_APP_START+99)
+#define TP_HELP_CONTENT (RID_SFX_APP_START+100)
+#define TP_HELP_INDEX (RID_SFX_APP_START+101)
+#define TP_HELP_SEARCH (RID_SFX_APP_START+102)
+#define TP_HELP_BOOKMARKS (RID_SFX_APP_START+103)
+#define DLG_HELP_ADDBOOKMARK (RID_SFX_APP_START+104)
+#define MENU_HELP_BOOKMARKS (RID_SFX_APP_START+105)
+#define RID_INFO_NOSEARCHRESULTS (RID_SFX_APP_START+106)
+#define RID_INFO_NOSEARCHTEXTFOUND (RID_SFX_APP_START+107)
+
+#define IMG_HELP_TOOLBOX_INDEX_ON (RID_SFX_APP_START+110)
+#define IMG_HELP_TOOLBOX_INDEX_OFF (RID_SFX_APP_START+111)
+#define IMG_HELP_TOOLBOX_START (RID_SFX_APP_START+112)
+#define IMG_HELP_TOOLBOX_PREV (RID_SFX_APP_START+113)
+#define IMG_HELP_TOOLBOX_NEXT (RID_SFX_APP_START+114)
+#define IMG_HELP_TOOLBOX_PRINT (RID_SFX_APP_START+115)
+#define IMG_HELP_TOOLBOX_BOOKMARKS (RID_SFX_APP_START+116)
+#define IMG_HELP_TOOLBOX_SEARCHDIALOG (RID_SFX_APP_START+117)
+#define IMG_HELP_TOOLBOX_COPY (RID_SFX_APP_START+118)
+
+#define IMG_HELP_CONTENT_BOOK_OPEN (RID_SFX_APP_START+120)
+#define IMG_HELP_CONTENT_BOOK_OPEN_HC (RID_SFX_APP_START+121)
+#define IMG_HELP_CONTENT_BOOK_CLOSED (RID_SFX_APP_START+122)
+#define IMG_HELP_CONTENT_BOOK_CLOSED_HC (RID_SFX_APP_START+123)
+#define IMG_HELP_CONTENT_DOC (RID_SFX_APP_START+124)
+
+#define IMG_HELP_CONTENT_DOC_HC (RID_SFX_APP_START+125) // image
+
+#define IMG_MISSING_1 (RID_SFX_APP_START+126) // image
+#define IMG_MISSING_2 (RID_SFX_APP_START+127) // image
+#define IMG_MISSING_3 (RID_SFX_APP_START+128) // image
+#define IMG_MISSING_4 (RID_SFX_APP_START+129) // image
+
+#define STR_HELP_WINDOW_TITLE (RID_SFX_APP_START+125) // string
+
+#define STR_HELP_BUTTON_INDEX_ON (RID_SFX_APP_START+126)
+#define STR_HELP_BUTTON_START (RID_SFX_APP_START+127)
+#define STR_HELP_BUTTON_PREV (RID_SFX_APP_START+128)
+#define STR_HELP_BUTTON_NEXT (RID_SFX_APP_START+129)
+#define STR_HELP_BUTTON_PRINT (RID_SFX_APP_START+130)
+#define STR_HELP_BUTTON_SOURCEVIEW (RID_SFX_APP_START+131)
+#define STR_HELP_FIRST_MESSAGE (RID_SFX_APP_START+132)
+#define STR_HELP_FIRST_HTML (RID_SFX_APP_START+133)
+
+#define STR_QUICKSTART_EXIT (RID_SFX_APP_START+134)
+#define STR_QUICKSTART_TIP (RID_SFX_APP_START+135)
+#define STR_QUICKSTART_FILEOPEN (RID_SFX_APP_START+136)
+#define STR_QUICKSTART_FROMTEMPLATE (RID_SFX_APP_START+137)
+#define STR_QUICKSTART_PRELAUNCH (RID_SFX_APP_START+138)
+#define STR_QUICKSTART_LNKNAME (RID_SFX_APP_START+139)
+#define STR_HELP_BUTTON_ADDBOOKMARK (RID_SFX_APP_START+140)
+#define STR_HELP_BUTTON_INDEX_OFF (RID_SFX_APP_START+141)
+#define STR_HELP_BUTTON_SEARCHDIALOG (RID_SFX_APP_START+142)
+#define STR_HELP_MENU_TEXT_SELECTION_MODE (RID_SFX_APP_START+143)
+#define STR_HELP_MENU_TEXT_COPY (RID_SFX_APP_START+144)
+#define STR_QUICKSTART_PRELAUNCH_UNX (RID_SFX_APP_START+146)
+#define STR_QUICKSTART_FILE (RID_SFX_APP_START+147)
+#define STR_QUICKSTART_STARTCENTER (RID_SFX_APP_START+148)
+#define STR_QUICKSTART_RECENTDOC (RID_SFX_APP_START+149)
+
+#define RID_HELP_ONSTARTUP_BOX (RID_SFX_APP_START+144)
+#define RID_HELP_ONSTARTUP_TEXT (RID_SFX_APP_START+145)
+
+#define IMG_HELP_TOOLBOX_HC_INDEX_ON (RID_SFX_APP_START+150)
+#define IMG_HELP_TOOLBOX_HC_INDEX_OFF (RID_SFX_APP_START+151)
+#define IMG_HELP_TOOLBOX_HC_START (RID_SFX_APP_START+152)
+#define IMG_HELP_TOOLBOX_HC_PREV (RID_SFX_APP_START+153)
+#define IMG_HELP_TOOLBOX_HC_NEXT (RID_SFX_APP_START+154)
+#define IMG_HELP_TOOLBOX_HC_PRINT (RID_SFX_APP_START+155)
+#define IMG_HELP_TOOLBOX_HC_BOOKMARKS (RID_SFX_APP_START+156)
+#define IMG_HELP_TOOLBOX_HC_SEARCHDIALOG (RID_SFX_APP_START+157)
+#define IMG_HELP_TOOLBOX_HC_COPY (RID_SFX_APP_START+158)
+
+#define IMG_HELP_TOOLBOX_L_INDEX_ON (RID_SFX_APP_START+160)
+#define IMG_HELP_TOOLBOX_L_INDEX_OFF (RID_SFX_APP_START+161)
+#define IMG_HELP_TOOLBOX_L_START (RID_SFX_APP_START+162)
+#define IMG_HELP_TOOLBOX_L_PREV (RID_SFX_APP_START+163)
+#define IMG_HELP_TOOLBOX_L_NEXT (RID_SFX_APP_START+164)
+#define IMG_HELP_TOOLBOX_L_PRINT (RID_SFX_APP_START+165)
+#define IMG_HELP_TOOLBOX_L_BOOKMARKS (RID_SFX_APP_START+166)
+#define IMG_HELP_TOOLBOX_L_SEARCHDIALOG (RID_SFX_APP_START+167)
+#define IMG_HELP_TOOLBOX_L_COPY (RID_SFX_APP_START+168)
+
+#define IMG_HELP_TOOLBOX_HCL_INDEX_ON (RID_SFX_APP_START+170)
+#define IMG_HELP_TOOLBOX_HCL_INDEX_OFF (RID_SFX_APP_START+171)
+#define IMG_HELP_TOOLBOX_HCL_START (RID_SFX_APP_START+172)
+#define IMG_HELP_TOOLBOX_HCL_PREV (RID_SFX_APP_START+173)
+#define IMG_HELP_TOOLBOX_HCL_NEXT (RID_SFX_APP_START+174)
+#define IMG_HELP_TOOLBOX_HCL_PRINT (RID_SFX_APP_START+175)
+#define IMG_HELP_TOOLBOX_HCL_BOOKMARKS (RID_SFX_APP_START+176)
+#define IMG_HELP_TOOLBOX_HCL_SEARCHDIALOG (RID_SFX_APP_START+177)
+#define IMG_HELP_TOOLBOX_HCL_COPY (RID_SFX_APP_START+178)
+
+#define RID_SECURITY_WARNING_HYPERLINK (RID_SFX_APP_START + 180)
+#define RID_SECURITY_WARNING_TITLE (RID_SFX_APP_START + 181)
+
+#define RID_INVALID_URL_MSG (RID_SFX_APP_START + 182)
+#define RID_INVALID_URL_TITLE (RID_SFX_APP_START + 183)
+#define RID_DESKTOP (RID_SFX_APP_START + 184)
+
+// #define RID_XMLSEC_WARNING_BROKENSIGNATURE (RID_SFX_APP_START + 185)
+#define RID_XMLSEC_QUERY_LOSINGSIGNATURE (RID_SFX_APP_START + 186)
+#define RID_XMLSEC_QUERY_SAVEBEFORESIGN (RID_SFX_APP_START + 187)
+ // FREE
+ // FREE
+#define RID_XMLSEC_INFO_WRONGDOCFORMAT (RID_SFX_APP_START + 190)
+
+/* obsolete
+#define RID_WARNING_MACROSDISABLED (RID_SFX_APP_START + 191)
+*/
+
+#define STR_QUERY_UPDATE_LINKS (RID_SFX_APP_START + 192)
+#define STR_DDE_ERROR (RID_SFX_APP_START + 193)
+#define RID_SECURITY_WARNING_NO_HYPERLINKS (RID_SFX_APP_START + 194)
+
+#define RID_SVXSTR_FILELINK (RID_SFX_APP_START + 195)
+#define RID_SVXSTR_GRAFIKLINK (RID_SFX_APP_START + 196)
+#define RID_SVXSTR_EDITGRFLINK (RID_SFX_APP_START + 197)
+
+// strings for error messsages of OpenGraphics dialog
+#define RID_SVXSTR_GRFILTER_OPENERROR (RID_SFX_APP_START + 198)
+#define RID_SVXSTR_GRFILTER_IOERROR (RID_SFX_APP_START + 199)
+#define RID_SVXSTR_GRFILTER_FORMATERROR (RID_SFX_APP_START + 200)
+#define RID_SVXSTR_GRFILTER_VERSIONERROR (RID_SFX_APP_START + 201)
+#define RID_SVXSTR_GRFILTER_FILTERERROR (RID_SFX_APP_START + 202)
+#define RID_SVXSTR_GRFILTER_TOOBIG (RID_SFX_APP_START + 203)
+
+#define MD_DDE_LINKEDIT (RID_SFX_APP_START + 1)
+
+#endif // #ifndef _SFX_APP_HRC
+
+// ******************************************************************* EOF
diff --git a/sfx2/source/appl/app.src b/sfx2/source/appl/app.src
new file mode 100644
index 000000000000..f8a387bba79b
--- /dev/null
+++ b/sfx2/source/appl/app.src
@@ -0,0 +1,988 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+ // include ------------------------------------------------------------------
+
+#include <sfx2/sfx.hrc>
+#include "app.hrc"
+#include "helpid.hrc"
+
+String STR_NONAME
+{
+ Text [ en-US ] = "Untitled" ;
+};
+String STR_CLOSE
+{
+ Text [ en-US ] = "Close" ;
+};
+String STR_STYLE_FILTER_AUTO
+{
+ Text [ en-US ] = "Automatic" ;
+};
+String STR_STANDARD_SHORTCUT
+{
+ Text [ en-US ] = "Standard" ;
+};
+String STR_BYTES
+{
+ Text [ en-US ] = "Bytes" ;
+};
+String STR_KB
+{
+ Text [ en-US ] = "KB" ;
+};
+String STR_MB
+{
+ Text [ en-US ] = "MB" ;
+};
+String STR_GB
+{
+ Text [ en-US ] = "GB" ;
+};
+QueryBox MSG_QUERY_LASTVERSION
+{
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_NO ;
+ Message [ en-US ] = "Cancel all changes?" ;
+};
+
+InfoBox RID_DOCALREADYLOADED_DLG
+{
+ Message [ en-US ] = "Document already open." ;
+};
+
+ErrorBox RID_CANTLOADDOC_DLG
+{
+ Message [ en-US ] = "Cannot open document." ;
+};
+
+ErrorBox MSG_ERR_READ_CFG
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Error reading configuration file." ;
+};
+
+ErrorBox MSG_ERR_WRITE_CFG
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Error writing configuration file." ;
+};
+
+ErrorBox MSG_ERR_OPEN_CFG
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Error opening configuration file." ;
+};
+
+ErrorBox MSG_ERR_FILETYPE_CFG
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "File is not a configuration file." ;
+};
+
+ErrorBox MSG_ERR_VERSION_CFG
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Configuration file contains the wrong version." ;
+};
+
+ErrorBox MSG_ERR_WRITE_SBL
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Error recording BASIC library in\n'@'." ;
+};
+
+ErrorBox MSG_SIGNAL
+{
+ BUTTONS = WB_YES_NO ;
+ DEFBUTTON = WB_DEF_YES ;
+ Message [ en-US ] = "An unexpected program error has occurred.\n\nDo you want to try to save your changes in all open documents before the program is terminated?" ;
+};
+
+ErrorBox MSG_ERR_NO_WEBBROWSER_FOUND
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message[ en-US ] = "%PRODUCTNAME could not find a web browser on your system. Please check your Desktop Preferences or install a web browser (for example, Mozilla) in the default location requested during the browser installation." ;
+};
+
+Resource SID_UNKNOWN
+{
+ String 1 "-" ;
+};
+
+Resource BMP_SFX_COLOR
+{
+ ExtraData =
+ {
+ SID_NEWDOC; // 043
+ SID_OPENDOC; // 044
+ SID_CLOSEDOC; // 045
+ SID_RELOAD; // 046
+ SID_SAVEASDOC; // 047
+ SID_PRINTDOC; // 051
+ SID_SETUPPRINTER; // 053
+ SID_QUITAPP; // 054
+ SID_UNDO; // 055
+ SID_REDO; // 056
+ SID_REPEAT; // 057
+ SID_CUT; // 058
+ SID_COPY; // 059
+ SID_PASTE; // 060
+ SID_DELETE; // 061
+ SID_SELECTALL; // 062
+ SID_SAVEDOC; // 063 vormals 046
+ SID_EXITANDRETURN; // 064 vormals 054
+ SID_RECORDMACRO; // 095
+ SID_EDITMACRO; // 096
+ SID_HELPMENU; // 098
+ SID_CONFIG; // 123
+ SID_CONFIGTOOLBOX; // 124
+ 0;
+ };
+ Bitmap BMP_SFX_SMALL { File = "sco.bmp" ; };
+ Bitmap BMP_SFX_LARGE { File = "lco.bmp" ; };
+};
+
+Resource BMP_SFX_MONO
+{
+ ExtraData =
+ {
+ SID_NEWDOC; // 043
+ SID_OPENDOC; // 044
+ SID_CLOSEDOC; // 045
+ SID_RELOAD; // 046
+ SID_SAVEASDOC; // 047
+ SID_PRINTDOC; // 051
+ SID_SETUPPRINTER; // 053
+ SID_QUITAPP; // 054
+ SID_UNDO; // 055
+ SID_REDO; // 056
+ SID_REPEAT; // 057
+ SID_CUT; // 058
+ SID_COPY; // 059
+ SID_PASTE; // 060
+ SID_DELETE; // 061
+ SID_SELECTALL; // 062
+ SID_SAVEDOC; // 063 vormals 046
+ SID_EXITANDRETURN; // 064 vormals 054
+ SID_RECORDMACRO; // 095
+ SID_EDITMACRO; // 096
+ SID_HELPMENU; // 098
+ SID_CONFIG; // 123
+ SID_CONFIGTOOLBOX; // 124
+ 0;
+ };
+ Bitmap BMP_SFX_SMALL { File = "smo.bmp" ; };
+ Bitmap BMP_SFX_LARGE { File = "lmo.bmp" ; };
+};
+
+WarningBox RID_WARN_POST_MAILTO
+{
+ BUTTONS = WB_OK_CANCEL ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "A form is to be sent by e-mail.\nThis means that the receiver will get to see your e-mail address." ;
+};
+
+String STR_RECOVER_TITLE
+{
+ Text [ en-US ] = "File Recovery" ;
+};
+
+String STR_RECOVER_QUERY
+{
+ Text [ en-US ] = "Should the file \"$1\" be restored?" ;
+};
+
+String GID_INTERN
+{
+ Text [ en-US ] = "Internal" ;
+};
+
+String GID_APPLICATION
+{
+ Text [ en-US ] = "Application" ;
+};
+
+String GID_VIEW
+{
+ Text [ en-US ] = "View" ;
+};
+
+String GID_DOCUMENT
+{
+ Text [ en-US ] = "Documents" ;
+};
+
+String GID_EDIT
+{
+ Text [ en-US ] = "Edit" ;
+};
+
+String GID_MACRO
+{
+ Text [ en-US ] = "BASIC" ;
+};
+
+String GID_OPTIONS
+{
+ Text [ en-US ] = "Options" ;
+};
+
+String GID_MATH
+{
+ Text [ en-US ] = "Math" ;
+};
+
+String GID_NAVIGATOR
+{
+ Text [ en-US ] = "Navigate" ;
+};
+
+String GID_INSERT
+{
+ Text [ en-US ] = "Insert" ;
+};
+
+String GID_FORMAT
+{
+ Text [ en-US ] = "Format" ;
+};
+
+String GID_TEMPLATE
+{
+ Text [ en-US ] = "Templates" ;
+};
+
+String GID_TEXT
+{
+ Text [ en-US ] = "Text" ;
+};
+
+String GID_FRAME
+{
+ Text [ en-US ] = "Frame" ;
+};
+
+String GID_GRAPHIC
+{
+ Text [ en-US ] = "Graphic" ;
+};
+
+String GID_TABLE
+{
+ Text [ en-US ] = "Table" ;
+};
+
+String GID_ENUMERATION
+{
+ Text [ en-US ] = "Numbering" ;
+};
+
+String GID_DATA
+{
+ Text [ en-US ] = "Data" ;
+};
+
+String GID_SPECIAL
+{
+ Text [ en-US ] = "Special Functions" ;
+};
+
+String GID_IMAGE
+{
+ Text [ en-US ] = "Image" ;
+};
+
+String GID_CHART
+{
+ Text [ en-US ] = "Chart" ;
+};
+
+String GID_EXPLORER
+{
+ Text [ en-US ] = "Explorer" ;
+};
+
+String GID_CONNECTOR
+{
+ Text [ en-US ] = "Connector" ;
+};
+
+String GID_MODIFY
+{
+ Text [ en-US ] = "Modify" ;
+};
+
+String GID_DRAWING
+{
+ Text [ en-US ] = "Drawing" ;
+};
+
+String GID_CONTROLS
+{
+ Text [ en-US ] = "Controls" ;
+};
+
+TabDialog SID_OPTIONS
+{
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 244 , 155 ) ;
+ Text [ en-US ] = "Options" ;
+ Moveable = TRUE ;
+ Closeable = TRUE ;
+ TabControl 1
+ {
+ SVLook = TRUE ;
+ Pos = MAP_APPFONT ( 3 , 15 ) ;
+ Size = MAP_APPFONT ( 221 , 130 ) ;
+ PageList =
+ {
+ PageItem
+ {
+ Identifier = RID_SFXPAGE_GENERAL ;
+ Text [ en-US ] = "General" ;
+ PageResID = 256 ;
+ };
+ PageItem
+ {
+ Identifier = RID_SFXPAGE_SAVE ;
+ Text [ en-US ] = "Save" ;
+ PageResID = 257 ;
+ };
+ PageItem
+ {
+ Identifier = RID_SFXPAGE_PATH ;
+ Text [ en-US ] = "Paths" ;
+ PageResID = 258 ;
+ };
+ PageItem
+ {
+ Identifier = RID_SFXPAGE_SPELL ;
+ Text [ en-US ] = "Spellcheck" ;
+ PageResID = 259 ;
+ };
+ };
+ };
+};
+
+InfoBox MSG_CANT_QUIT
+{
+ Message [ en-US ] = "The application cannot be terminated at the moment.\nPlease wait until all print jobs and/or\nOLE actions have finished and close all dialogs." ;
+};
+
+QueryBox MSG_IS_SERVER
+{
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_NO ;
+ Message [ en-US ] = "This application is as object or print server active.\nDo you want to terminate anyway?" ;
+};
+
+String STR_NODOUBLE
+{
+ Text [ en-US ] = "%PRODUCTNAME cannot be started more than once." ;
+};
+
+String STR_NOPRINTER
+{
+ Text [ en-US ] = "Some %PRODUCTNAME functions will not work properly without a printer driver.\nPlease install a printer driver." ;
+};
+
+String STR_ISMODIFIED
+{
+ Text [ en-US ] = "Do you want to save the changes to %1?" ;
+};
+
+String STR_AUTOSAVE
+{
+ Text [ en-US ] = "AutoSave" ;
+};
+
+String STR_RESWARNING
+{
+ Text [ en-US ] = "Limited system resources. Please quit other applications or close some windows before continuing." ;
+};
+String STR_RESEXCEPTION
+{
+ Text [ en-US ] = "There are files missing. Please check application setup." ;
+};
+
+String STR_DOUBLEEXCEPTION
+{
+ Text [ en-US ] = "Another error occurred during the save recovery.\nPossibly, the data could not be entirely saved." ;
+};
+
+String STR_SYSRESEXCEPTION
+{
+ Text [ en-US ] = "System resources exhausted. Please restart the application." ;
+};
+
+ErrorBox MSG_ERR_SOINIT
+{
+ Message [ en-US ] = "Error initializing object-system." ;
+};
+
+String MSG_IOERR_FILE_NOT_FOUND
+{
+ Text [ en-US ] = "The file $(FILE) doesn't exist." ;
+};
+
+String MSG_IOERR_PATH_NOT_FOUND
+{
+ Text [ en-US ] = "The path to file $(FILE) doesn't exist." ;
+};
+
+String MSG_IOERR_TOO_MANY_OPEN_FILES
+{
+ Text [ en-US ] = "The file $(FILE) could not be opened,\nbecause too many files are open.\nPlease close some files and try again." ;
+};
+
+String MSG_IOERR_ACCESS_DENIED
+{
+ Text [ en-US ] = "The file $(FILE) could not be opened due to missing access rights." ;
+};
+
+String MSG_IOERR_INVALID_ACCESS
+{
+ Text [ en-US ] = "The file $(FILE) could not be accessed." ;
+};
+
+String MSG_IOERR_INVALID_HANDLE
+{
+ Text [ en-US ] = "The file $(FILE) could not be opened due to an invalid file handle." ;
+};
+
+String MSG_IOERR_CANNOT_MAKE
+{
+ Text [ en-US ] = "The file $(FILE) could not be created." ;
+};
+
+String MSG_IOERR_SHARING
+{
+ Text [ en-US ] = "Error by shared access to $(FILE)." ;
+};
+
+String MSG_IOERR_INVALID_PARAMETER
+{
+ Text [ en-US ] = "" ;
+};
+
+String MSG_IOERR_GENERAL
+{
+ Text [ en-US ] = "General I/O error accessing $(FILE)." ;
+};
+
+String RID_FULLSCREENTOOLBOX
+{
+ Text = "" ;
+};
+
+ToolBox RID_FULLSCREENTOOLBOX
+{
+ HelpId = HID_FULLSCREENTOOLBOX ;
+ ButtonType = BUTTON_SYMBOL ;
+ LineSpacing = TRUE ;
+ Border = TRUE ;
+ Scroll = TRUE ;
+ SVLook = TRUE ;
+ Moveable = TRUE ;
+ Sizeable = TRUE ;
+ Closeable = TRUE ;
+ Zoomable = TRUE ;
+ Customize = TRUE ;
+ FloatingMode = TRUE ;
+ Hide = TRUE ;
+ _FloatingPosMapMode = MAP_APPFONT ;
+ _FloatingPosX = -50 ;
+ _FloatingPosY = -70 ;
+ FloatingLines = 1 ;
+ HideWhenDeactivate = TRUE ;
+ Align = BOXALIGN_TOP ;
+ ItemList =
+ {
+ ToolBoxItem
+ {
+ Identifier = SID_WIN_FULLSCREEN ;
+ };
+ };
+};
+
+String STR_ERR_NOTEMPLATE
+{
+ Text [ en-US ] = "The selected template has an incorrect format" ;
+};
+
+String STR_ERR_NOFILE
+{
+ Text [ en-US ] = "Can't open file $." ;
+};
+
+String STR_QUITAPP
+{
+ Text [ en-US ] = "E~xit" ;
+};
+
+String STR_EXITANDRETURN
+{
+ Text [ en-US ] = "E~xit & return to " ;
+};
+
+String STR_EXTHELPSTATUS
+{
+ Text [ en-US ] = "Select a command or click to select a theme." ;
+};
+
+String STR_MAIL
+{
+ Text [ en-US ] = "Mail" ;
+};
+
+String STR_ADDRESS_NAME
+{
+ Text [ en-US ] = "Addresses" ;
+};
+
+String RID_STR_HELP
+{
+ Text [ en-US ] = "Help" ;
+};
+
+String RID_STR_NOAUTOSTARTHELPAGENT
+{
+ Text [ en-US ] = "No automatic start at 'XX'" ;
+};
+
+String RID_STR_NOWELCOMESCREEN
+{
+ Text [ en-US ] = "Don't display tips" ;
+};
+
+String RID_HELPBAR
+{
+ Text [ en-US ] = "Help Bar" ;
+};
+
+ToolBox RID_HELPBAR
+{
+ HelpId = HID_HELPBAR ;
+ Hide = TRUE ;
+ ItemList =
+ {
+ ToolBoxItem
+ {
+ Identifier = SID_HELP_INDEX ;
+ };
+ ToolBoxItem
+ {
+ Identifier = SID_HELP_HELPFILEBOX ;
+ };
+ ToolBoxItem
+ {
+ Type = TOOLBOXITEM_SEPARATOR ;
+ };
+ ToolBoxItem
+ {
+ Identifier = SID_HELP_ZOOMOUT;
+ };
+ ToolBoxItem
+ {
+ Identifier = SID_HELP_ZOOMIN;
+ };
+ ToolBoxItem
+ {
+ Type = TOOLBOXITEM_SEPARATOR ;
+ };
+ ToolBoxItem
+ {
+ Identifier = SID_HELP_SEARCH ;
+ };
+ ToolBoxItem
+ {
+ Identifier = SID_HELP_BOOKMARK ;
+ };
+ ToolBoxItem
+ {
+ Identifier = SID_HELP_ANNOTATE ;
+ };
+ /*
+ ToolBoxItem
+ {
+ Type = TOOLBOXITEM_SEPARATOR ;
+ };
+ ToolBoxItem
+ {
+ Identifier = SID_HELP_DOWNLOAD ;
+ };
+*/
+ };
+};
+
+String RID_STR_HLPFILENOTEXIST
+{
+ Text [ en-US ] = "The help file for this topic is not installed." ;
+};
+
+String RID_STR_HLPAPPNOTSTARTED
+{
+ Text [ en-US ] = "The help system could not be started" ;
+};
+
+ //----------------------------------------------------------------------------
+
+String RID_ENVTOOLBOX
+{
+ Text [ en-US ] = "Function Bar" ;
+};
+
+String RID_SPECIALCONFIG_ERROR
+{
+ Text [ en-US ] = "An error has occurred in the special configuration.\nPlease contact your administrator." ;
+};
+
+String STR_MEMINFO_HEADER
+{
+};
+
+String STR_MEMINFO_FOOTER
+{
+ Text = "</table>" ;
+};
+
+String STR_MEMINFO_OBJINFO
+{
+ Text = "<tr><td >$(VISIBLE)</td><td>$(CACHED)</td><td>$(EXPIRE)</td><td>$(JSDIRTY)</td><td>$(JSEXEC)</td><td>$(FORBID)</td><td>$(FACTORY)</td><td>$(URL)</td><td>$(ORIGURL)</td><td>$(POSTSTRING)</td></tr>" ;
+};
+
+String RID_PLUGIN
+{
+ Text [ en-US ] = "Enable plug-ins" ;
+};
+
+String STR_CORRUPT_INSTALLATION
+{
+ Text [ en-US ] = "Important program components could not be initialized correctly.\nPlease start the setup program with the option /Repair." ;
+};
+
+String IDS_SBERR_STOREREF
+{
+ Text [ en-US ] = "Reference will not be saved: " ;
+};
+
+String STR_KEY_CONFIG_DIR
+{
+ Text [ en-US ] = "Configuration" ;
+};
+String STR_KEY_WORK_PATH
+{
+ Text [ en-US ] = "My Documents" ;
+};
+String STR_KEY_GRAPHICS_PATH
+{
+ Text [ en-US ] = "Graphics" ;
+};
+String STR_KEY_BITMAP_PATH
+{
+ Text [ en-US ] = "Icons" ;
+};
+String STR_KEY_BASIC_PATH
+{
+ Text = "BASIC" ;
+};
+
+String STR_KEY_PALETTE_PATH
+{
+ Text [ en-US ] = "Palettes" ;
+};
+String STR_KEY_BACKUP_PATH
+{
+ Text [ en-US ] = "Backups" ;
+};
+String STR_KEY_MODULES_PATH
+{
+ Text [ en-US ] = "Modules" ;
+};
+String STR_KEY_TEMPLATE_PATH
+{
+ Text [ en-US ] = "Templates" ;
+};
+String STR_KEY_GLOSSARY_PATH
+{
+ Text [ en-US ] = "AutoText" ;
+};
+String STR_KEY_DICTIONARY_PATH
+{
+ Text [ en-US ] = "Dictionaries" ;
+};
+String STR_KEY_HELP_DIR
+{
+ Text [ en-US ] = "Help" ;
+};
+String STR_KEY_GALLERY_DIR
+{
+ Text [ en-US ] = "Gallery" ;
+};
+
+String STR_KEY_STORAGE_DIR
+{
+ Text [ en-US ] = "Message Storage" ;
+};
+String STR_KEY_TEMP_PATH
+{
+ Text [ en-US ] = "Temporary files" ;
+};
+String STR_KEY_PLUGINS_PATH
+{
+ Text [ en-US ] = "Plug-ins" ;
+};
+String STR_KEY_FAVORITES_DIR
+{
+ Text [ en-US ] = "Folder Bookmarks" ;
+};
+String STR_KEY_FILTER_PATH
+{
+ Text [ en-US ] = "Filters" ;
+};
+String STR_KEY_ADDINS_PATH
+{
+ Text [ en-US ] = "Add-ins" ;
+};
+String STR_KEY_USERCONFIG_PATH
+{
+ Text [ en-US ] = "User Configuration" ;
+};
+String STR_KEY_USERDICTIONARY_DIR
+{
+ Text [ en-US ] = "User-defined dictionaries" ;
+};
+String STR_KEY_AUTOCORRECT_DIR
+{
+ Text [ en-US ] = "AutoCorrect" ;
+};
+String STR_KEY_LINGUISTIC_DIR
+{
+ Text [ en-US ] = "Writing aids" ;
+};
+String STR_QUICKSTART_EXIT
+{
+ Text [ en-US ] = "Exit Quickstarter" ;
+};
+String STR_QUICKSTART_TIP
+{
+ Text [ en-US ] = "%PRODUCTNAME %PRODUCTVERSION Quickstarter" ;
+};
+String STR_QUICKSTART_FILEOPEN
+{
+ Text [ en-US ] = "Open Document..." ;
+};
+String STR_QUICKSTART_FROMTEMPLATE
+{
+ Text [ en-US ] = "From Template..." ;
+};
+String STR_QUICKSTART_PRELAUNCH
+{
+ Text [ en-US ] = "Load %PRODUCTNAME During System Start-Up" ;
+};
+String STR_QUICKSTART_PRELAUNCH_UNX
+{
+ Text[ en-US ] = "Disable systray Quickstarter";
+};
+String STR_QUICKSTART_LNKNAME
+{
+ Text [ en-US ] = "%PRODUCTNAME %PRODUCTVERSION" ;
+};
+String STR_QUICKSTART_FILE
+{
+ Text [ en-US ] = "File";
+};
+
+String STR_QUICKSTART_STARTCENTER
+{
+ Text [ en-US ] = "Startcenter";
+};
+
+String STR_QUICKSTART_RECENTDOC
+{
+ Text [ en-US ] = "Recent Documents";
+};
+
+String STR_QUERY_UPDATE_LINKS
+{
+ Text [ en-US ] = "Update all links?" ;
+};
+
+String STR_DDE_ERROR
+{
+ Text [ en-US ] = "DDE link to % for % area % are not available." ;
+};
+
+WarningBox RID_SECURITY_WARNING_HYPERLINK
+{
+ HelpId = HID_WARNING_SECURITY_HYPERLINK;
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_NO ;
+ Message [ en-US ] = "This hyperlink is going to open \"%s\". Do you want to proceed?" ;
+};
+
+WarningBox RID_SECURITY_WARNING_NO_HYPERLINKS
+{
+ //HelpId = HID_WARNING_SECURITY_NO_HYPERLINKS;
+ Buttons = WB_OK ;
+ DefButton = WB_DEF_OK ;
+ Message [ en-US ] = "For security reasons, the hyperlink cannot be executed.\nThe stated address will not be opened.";
+};
+
+String RID_SECURITY_WARNING_TITLE
+{
+ Text [ en-US ] = "Security Warning" ;
+};
+
+ErrorBox RID_INVALID_URL_MSG
+{
+ Buttons = WB_OK ;
+ Message [ en-US ] = "The URL is not valid." ;
+};
+
+String RID_INVALID_URL_TITLE
+{
+ Text = "%PRODUCTNAME %PRODUCTVERSION" ;
+};
+
+String RID_DESKTOP
+{
+ Text = "%PRODUCTNAME" ;
+};
+
+QueryBox RID_XMLSEC_QUERY_LOSINGSIGNATURE
+{
+// HelpId = HID_XMLSEC_QUERY_LOSINGSIGNATURE;
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_NO ;
+ Message [ en-US ] = "Saving will remove all existing signatures.\nDo you want to continue saving the document?" ;
+};
+
+QueryBox RID_XMLSEC_QUERY_SAVEBEFORESIGN
+{
+// HelpId = HID_XMLSEC_QUERY_SAVEBEFORESIGN;
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_YES ;
+ Message [ en-US ] = "The document has to be saved before it can be signed.\nDo you want to save the document?" ;
+};
+
+InfoBox RID_XMLSEC_INFO_WRONGDOCFORMAT
+{
+// HelpId = HID_XMLSEC_INFO_WRONGDOCFORMAT;
+ Message [ en-US ] = "This document must be saved in OpenDocument file format before it can be digitally signed." ;
+};
+
+String RID_XMLSEC_DOCUMENTSIGNED
+{
+ Text [ en-US ] = " (Signed)" ;
+};
+
+Image IMG_MISSING_1
+{
+ ImageBitmap = Bitmap { File = "sc05539.bmp" ; };
+};
+
+Image IMG_MISSING_2
+{
+ ImageBitmap = Bitmap { File = "sc05700.bmp" ; };
+};
+
+Image IMG_MISSING_3
+{
+ ImageBitmap = Bitmap { File = "sc06302.bmp" ; };
+};
+
+Image IMG_MISSING_4
+{
+ ImageBitmap = Bitmap { File = "sn064.bmp" ; };
+};
+
+String STR_STANDARD
+{
+ Text [ en-US ] = "Standard" ;
+};
+
+String RID_SVXSTR_FILELINK
+{
+ Text [ en-US ] = "Document" ;
+};
+
+String STR_NONE
+{
+ Text [ en-US ] = "- None -" ;
+};
+String RID_SVXSTR_GRAFIKLINK
+{
+ Text [ en-US ] = "Graphic" ;
+};
+String STR_SFX_FILTERNAME_ALL
+{
+ Text [ en-US ] = "All files (*.*)" ;
+};
+String RID_SVXSTR_EDITGRFLINK
+{
+ Text [ en-US ] = "Link graphics" ;
+};
+// i66948 used in project scripting
+String STR_ERRUNOEVENTBINDUNG
+{
+ Text [ en-US ] = "An appropriate component method %1\ncould not be found.\n\nCheck spelling of method name.";
+};
+String RID_SVXSTR_GRFILTER_OPENERROR
+{
+ Text [ en-US ] = "Graphics file cannot be opened" ;
+};
+String RID_SVXSTR_GRFILTER_IOERROR
+{
+ Text [ en-US ] = "Graphics file cannot be read" ;
+};
+String RID_SVXSTR_GRFILTER_FORMATERROR
+{
+ Text [ en-US ] = "Unknown graphics format" ;
+};
+String RID_SVXSTR_GRFILTER_VERSIONERROR
+{
+ Text [ en-US ] = "This version of the graphics file is not supported" ;
+};
+String RID_SVXSTR_GRFILTER_FILTERERROR
+{
+ Text [ en-US ] = "Graphics filter not found" ;
+};
+String RID_SVXSTR_GRFILTER_TOOBIG
+{
+ Text [ en-US ] = "Not enough memory to insert graphic" ;
+};
+
diff --git a/sfx2/source/appl/appbas.cxx b/sfx2/source/appl/appbas.cxx
new file mode 100644
index 000000000000..7e775cbbb502
--- /dev/null
+++ b/sfx2/source/appl/appbas.cxx
@@ -0,0 +1,590 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/script/XLibraryContainer.hpp>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <basic/basrdll.hxx>
+#include <tools/urlobj.hxx>
+#include <svl/macitem.hxx>
+#include <basic/sbxfac.hxx>
+#include <basic/sbx.hxx>
+#include <vcl/gradient.hxx>
+#include <svl/rectitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/eitem.hxx>
+#include <basic/sbmod.hxx>
+#include <svl/whiter.hxx>
+#include <basic/sbmeth.hxx>
+#include <basic/sbstar.hxx>
+#include <vcl/wrkwin.hxx>
+#include <vcl/msgbox.hxx>
+#include <basic/sbuno.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+
+#include <unotools/undoopt.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/useroptions.hxx>
+#include <unotools/bootstrap.hxx>
+
+#include <sfx2/appuno.hxx>
+#include <sfx2/module.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/app.hxx>
+#include "sfxtypes.hxx"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/msg.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/progress.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/objitem.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/dispatch.hxx>
+#include "sfx2/tplpitem.hxx"
+#include "sfx2/minfitem.hxx"
+#include "app.hrc"
+#include <sfx2/evntconf.hxx>
+#include <sfx2/macrconf.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/dinfdlg.hxx>
+#include "appdata.hxx"
+#include "appbas.hxx"
+#include "sfx2/sfxhelp.hxx"
+#include "sfx2/basmgr.hxx"
+#include "sorgitm.hxx"
+#include "appbaslib.hxx"
+#include <basic/basicmanagerrepository.hxx>
+
+#define ITEMID_SEARCH SID_SEARCH_ITEM
+
+#include <svl/srchitem.hxx>
+#include <vos/socket.hxx>
+
+#define SFX_TYPEMAP
+#define Selection
+#include "sfxslots.hxx"
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::script;
+
+using ::basic::BasicManagerRepository;
+
+// #ifndef STR_VERSION_ID
+// #define STR_VERSION_ID 1
+// #endif
+// #ifndef STR_VERSION_TYPE
+// #define STR_VERSION_TYPE 1
+// #endif
+
+//=========================================================================
+/*ASDBG
+const SfxConstant __FAR_DATA aConstants[] =
+{
+ SFX_USHORT_CONSTANT( "AlignBottom", ALIGN_BOTTOM ),
+ SFX_USHORT_CONSTANT( "AlignTop", ALIGN_TOP ),
+ SFX_USHORT_CONSTANT( "CharSetANSI", CHARSET_ANSI ),
+ SFX_USHORT_CONSTANT( "CharSetDontKnow", CHARSET_DONTKNOW ),
+ SFX_USHORT_CONSTANT( "CharSetIBMPC437", CHARSET_IBMPC_437 ),
+ SFX_USHORT_CONSTANT( "CharSetIBMPC850", CHARSET_IBMPC_850 ),
+ SFX_USHORT_CONSTANT( "CharSetIBMPC860", CHARSET_IBMPC_860 ),
+ SFX_USHORT_CONSTANT( "CharSetIBMPC861", CHARSET_IBMPC_861 ),
+ SFX_USHORT_CONSTANT( "CharSetIBMPC863", CHARSET_IBMPC_863 ),
+ SFX_USHORT_CONSTANT( "CharSetIBMPC865", CHARSET_IBMPC_865 ),
+ SFX_USHORT_CONSTANT( "CharSetIBMPC", CHARSET_IBMPC ),
+ SFX_USHORT_CONSTANT( "CharSetMac", CHARSET_MAC ),
+ SFX_USHORT_CONSTANT( "CharSetSymbol", CHARSET_SYMBOL ),
+ SFX_USHORT_CONSTANT( "CharSetSystem", RTL_TEXTENCODING_UTF8 ),
+ SFX_USHORT_CONSTANT( "FamilyDecorative", FAMILY_DECORATIVE ),
+ SFX_USHORT_CONSTANT( "FamilyDontknow", FAMILY_DONTKNOW ),
+ SFX_USHORT_CONSTANT( "FamilyModern", FAMILY_MODERN ),
+ SFX_USHORT_CONSTANT( "FamilyRoman", FAMILY_ROMAN ),
+ SFX_USHORT_CONSTANT( "FamilyScript", FAMILY_SCRIPT ),
+ SFX_USHORT_CONSTANT( "FamilySwiss", FAMILY_SWISS ),
+ SFX_USHORT_CONSTANT( "FamilySystem", FAMILY_SYSTEM ),
+ SFX_USHORT_CONSTANT( "GradientAxial", GRADIENT_AXIAL ),
+ SFX_USHORT_CONSTANT( "GradientElliptical", GRADIENT_ELLIPTICAL ),
+ SFX_USHORT_CONSTANT( "GradientLinear", GRADIENT_LINEAR ),
+ SFX_USHORT_CONSTANT( "GradientRadial", GRADIENT_RADIAL ),
+ SFX_USHORT_CONSTANT( "GradientRect", GRADIENT_RECT ),
+ SFX_USHORT_CONSTANT( "GradientSquare", GRADIENT_SQUARE ),
+ SFX_USHORT_CONSTANT( "ItalicNone", ITALIC_NONE ),
+ SFX_USHORT_CONSTANT( "ItalicOblique", ITALIC_OBLIQUE ),
+ SFX_USHORT_CONSTANT( "StrikeThroughDouble", STRIKEOUT_DOUBLE ),
+ SFX_USHORT_CONSTANT( "StrikeThroughNone", STRIKEOUT_NONE ),
+ SFX_USHORT_CONSTANT( "StrikeThroughSingle", STRIKEOUT_SINGLE ),
+ SFX_USHORT_CONSTANT( "UnderlineDotted", UNDERLINE_DOTTED ),
+ SFX_USHORT_CONSTANT( "UnderlineDouble", UNDERLINE_DOUBLE ),
+ SFX_USHORT_CONSTANT( "UnderlineNone", UNDERLINE_NONE ),
+ SFX_USHORT_CONSTANT( "UnderlineSingle", UNDERLINE_SINGLE ),
+ SFX_USHORT_CONSTANT( "UnitFoot", FUNIT_FOOT ),
+ SFX_USHORT_CONSTANT( "UnitInch", FUNIT_INCH ),
+ SFX_USHORT_CONSTANT( "UnitMile", FUNIT_MILE ),
+ SFX_USHORT_CONSTANT( "UnitPercent", FUNIT_PERCENT ),
+ SFX_USHORT_CONSTANT( "UnitPoint", FUNIT_POINT ),
+ SFX_USHORT_CONSTANT( "UnitTwip", FUNIT_TWIP ),
+ SFX_USHORT_CONSTANT( "Unit_cm", FUNIT_CM ),
+ SFX_USHORT_CONSTANT( "Unit_m", FUNIT_M ),
+ SFX_USHORT_CONSTANT( "Unit_mm", FUNIT_MM ),
+ SFX_USHORT_CONSTANT( "WeightBlack", WEIGHT_BLACK ),
+ SFX_USHORT_CONSTANT( "WeightBold", WEIGHT_BOLD ),
+ SFX_USHORT_CONSTANT( "WeightDontKnow", WEIGHT_DONTKNOW ),
+ SFX_USHORT_CONSTANT( "WeightLight", WEIGHT_LIGHT ),
+ SFX_USHORT_CONSTANT( "WeightMedium", WEIGHT_MEDIUM ),
+ SFX_USHORT_CONSTANT( "WeightNormal", WEIGHT_NORMAL ),
+ SFX_USHORT_CONSTANT( "WeightSemibold", WEIGHT_SEMIBOLD ),
+ SFX_USHORT_CONSTANT( "WeightSemilight", WEIGHT_SEMILIGHT ),
+ SFX_USHORT_CONSTANT( "WeightThin", WEIGHT_THIN ),
+ SFX_USHORT_CONSTANT( "WeightUltrabold", WEIGHT_ULTRABOLD ),
+ SFX_USHORT_CONSTANT( "WeightUltralight", WEIGHT_ULTRALIGHT )
+};
+*/
+//========================================================================
+
+//------------------------------------------------------------------------
+String lcl_GetVersionString(ResMgr* /*pAppData_ImplResMgr*/)
+{
+ ::rtl::OUString aDefault;
+ String aVersion( utl::Bootstrap::getBuildIdData( aDefault ));
+
+ if ( aVersion.Len() == 0 )
+ {
+ DBG_ERROR( "No BUILDID in bootstrap file found" );
+ }
+
+ aVersion.Erase( 0, aVersion.Search( ':' ) + 1 );
+ aVersion.Erase( aVersion.Search( ')' ) );
+ return aVersion;
+}
+
+//=========================================================================
+sal_uInt16 SfxApplication::SaveBasicManager() const
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+sal_uInt16 SfxApplication::SaveBasicAndDialogContainer() const
+{
+ if ( pAppData_Impl->pBasicManager->isValid() )
+ pAppData_Impl->pBasicManager->storeAllLibraries();
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::RegisterBasicConstants
+(
+ const char*, // Prefix vor Konstanten-Namen
+ const SfxConstant*, // Array von <SfxConstant> Instanzen
+ sal_uInt16 // Anahl der Kontanten in pConsts
+)
+
+/* [Beschreibung]
+
+ Diese Methode meldet Konstanten beim BASIC an. Sie sollte on-demand
+ (in GetSbxObject() der Applikation) gerufen werden. Das Array mu\s
+ alphabetisch nach den Namen sortiert sein!
+
+ Durch den Prefix kann Speicher gespart und das Suchen beschleunigt
+ werden. Im StarOffice soll der Prefix "so" verwendet werden.
+
+
+ [Beispiel]
+
+ const SfxConstant __FAR_DATA aConstants[] =
+ {
+ SFX_BOOL_CONSTANT( "False", sal_False ),
+ SFX_BOOL_CONSTANT( "True", sal_True ),
+ };
+
+ ...
+ SFX_APP()->RegisterBasicConstants( 0, aConstants, 2 );
+ ...
+
+*/
+
+{
+// DBG_ASSERT( pAppData_Impl->pBasicMgr, "no basic available" );
+
+// pAppData_Impl->pBasicMgr->GetLib(0)->Insert(
+// new SfxConstants_Impl( pPrefix, pConsts, nCount ) );
+}
+
+//--------------------------------------------------------------------
+
+SbxVariable* MakeVariable( StarBASIC *pBas, SbxObject *pObject,
+ const char *pName, sal_uInt32 nSID, SbxDataType eType, SbxClassType eClassType )
+{
+ SbxVariable *pVar = pBas->Make( String::CreateFromAscii(pName), eClassType, eType ); //SbxCLASS_PROPERTY
+ pVar->SetUserData( nSID );
+ pVar->SetFlag( SBX_DONTSTORE );
+ pObject->StartListening( pVar->GetBroadcaster() );
+ return pVar;
+}
+
+//--------------------------------------------------------------------
+
+BasicManager* SfxApplication::GetBasicManager()
+{
+// DBG_ASSERT( pAppData_Impl->nBasicCallLevel != 0,
+// "unnecessary call to GetBasicManager() - inefficient!" );
+ if ( pAppData_Impl->nBasicCallLevel == 0 )
+ // sicherheitshalber
+ EnterBasicCall();
+
+ return BasicManagerRepository::getApplicationBasicManager( true );
+}
+
+//--------------------------------------------------------------------
+
+Reference< XLibraryContainer > SfxApplication::GetDialogContainer()
+{
+ if ( !pAppData_Impl->pBasicManager->isValid() )
+ GetBasicManager();
+ return pAppData_Impl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::DIALOGS );
+}
+
+//--------------------------------------------------------------------
+
+Reference< XLibraryContainer > SfxApplication::GetBasicContainer()
+{
+ if ( !pAppData_Impl->pBasicManager->isValid() )
+ GetBasicManager();
+ return pAppData_Impl->pBasicManager->getLibraryContainer( SfxBasicManagerHolder::SCRIPTS );
+}
+
+//--------------------------------------------------------------------
+
+StarBASIC* SfxApplication::GetBasic()
+{
+ return GetBasicManager()->GetLib(0);
+}
+
+//--------------------------------------------------------------------
+
+FASTBOOL SfxApplication::IsInBasicCall() const
+{
+ return 0 != pAppData_Impl->nBasicCallLevel;
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::EnterBasicCall()
+{
+ if ( 1 == ++pAppData_Impl->nBasicCallLevel )
+ {
+ DBG_TRACE( "SfxShellObject: BASIC-on-demand" );
+
+ // das kann l"anger dauern, da Progress nicht geht, wenigstens Sanduhr
+//(mba)/task SfxWaitCursor aWait;
+
+ // zuerst das BASIC laden
+ GetBasic();
+/*
+ // als erstes SfxShellObject das SbxObject der SfxApplication erzeugen
+ SbxObject *pSbx = GetSbxObject();
+ DBG_ASSERT( pSbx, "SfxShellObject: can't create SbxObject for SfxApplication" );
+
+ // die SbxObjects aller Module erzeugen
+ SfxModuleArr_Impl& rArr = GetModules_Impl();
+ for ( sal_uInt16 n = 0; n < rArr.Count(); ++n )
+ {
+ SfxModule *pMod = rArr.GetObject(n);
+ if ( pMod->IsLoaded() )
+ {
+ pSbx = pMod->GetSbxObject();
+ DBG_ASSERT( pSbx, "SfxModule: can't create SbxObject" );
+ }
+ }
+
+ // die SbxObjects aller Tasks erzeugen
+ for ( SfxTask *pTask = SfxTask::GetFirst(); pTask; pTask = SfxTask::GetNext( *pTask ) )
+ pTask->GetSbxObject();
+
+ // die SbxObjects aller SfxObjectShells erzeugen (ggf. Frame-los!)
+ for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst( NULL, sal_False );
+ pObjSh;
+ pObjSh = SfxObjectShell::GetNext(*pObjSh, NULL, sal_False) )
+ {
+ // kein IP-Object oder wenn doch dann initialisiert?
+ SvStorageRef aStorage;
+ if ( !pObjSh->IsHandsOff() )
+ aStorage = pObjSh->GetStorage();
+ if ( !pObjSh->GetInPlaceObject() || aStorage.Is() )
+ {
+ DBG( DbgOutf( "SfxShellObject: BASIC-on-demand for %s",
+ pObjSh->SfxShell::GetName().GetBuffer() ) );
+ pSbx = pObjSh->GetSbxObject();
+ DBG_ASSERT( pSbx, "SfxShellObject: can't create SbxObject" );
+ }
+ }
+
+ // die SbxObjects der SfxShells auf den Stacks der Frames erzeugen
+ for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst(0,sal_False);
+ pFrame;
+ pFrame = SfxViewFrame::GetNext(*pFrame,0,0,sal_False) )
+ {
+ // den Dispatcher des Frames rausholen
+ SfxDispatcher *pDispat = pFrame->GetDispatcher();
+ pDispat->Flush();
+
+ // "uber alle SfxShells auf dem Stack des Dispatchers iterieren
+ // Frame selbst wird ausgespart, da er indirekt angezogen wird,
+ // sofern er ein Dokument enth"alt.
+ for ( sal_uInt16 nStackIdx = pDispat->GetShellLevel(*pFrame);
+ 0 != nStackIdx;
+ --nStackIdx )
+ {
+ DBG( DbgOutf( "SfxShellObject: BASIC-on-demand for level %u", nStackIdx-1 ); )
+ pSbx = pDispat->GetShell(nStackIdx - 1)->GetSbxObject();
+ DBG_ASSERT( pSbx, "SfxShellObject: can't create SbxObject" );
+ }
+
+ if ( !pFrame->GetObjectShell() )
+ {
+ DBG( DbgOutf( "SfxShellObject: BASIC-on-demand for empty frame" ); )
+ pSbx = pFrame->GetSbxObject();
+ DBG_ASSERT( pSbx, "SfxShellObject: can't create SbxObject" );
+ }
+ }
+*/
+ // Factories anmelden
+// SbxBase::AddFactory( new SfxSbxObjectFactory_Impl );
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::LeaveBasicCall()
+{
+ --pAppData_Impl->nBasicCallLevel;
+}
+
+//-------------------------------------------------------------------------
+void SfxApplication::PropExec_Impl( SfxRequest &rReq )
+{
+ rReq.GetArgs();
+ sal_uInt16 nSID = rReq.GetSlot();
+ switch ( nSID )
+ {
+ case SID_CREATE_BASICOBJECT:
+ {
+ SFX_REQUEST_ARG(rReq, pItem, SfxStringItem, nSID, sal_False);
+ if ( pItem )
+ {
+ SbxObject* pObject = SbxBase::CreateObject( pItem->GetValue() );
+ pObject->AddRef();
+//(mba) rReq.SetReturnValue( SfxObjectItem( 0, pObject ) );
+ rReq.Done();
+ }
+ break;
+ }
+
+ case SID_DELETE_BASICOBJECT:
+ {
+ SFX_REQUEST_ARG(rReq, pItem, SfxObjectItem, nSID, sal_False);
+ if ( pItem )
+ {
+//(mba) SbxObject* pObject = pItem->GetObject();
+//(mba) pObject->ReleaseRef();
+ }
+ break;
+ }
+
+ case SID_ATTR_UNDO_COUNT:
+ {
+ SFX_REQUEST_ARG(rReq, pCountItem, SfxUInt16Item, nSID, sal_False);
+ SvtUndoOptions().SetUndoCount( pCountItem->GetValue() );
+ break;
+ }
+
+ case SID_WIN_VISIBLE:
+ {
+ break;
+ }
+
+ case SID_STATUSBARTEXT:
+ {
+ SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, nSID, sal_False);
+ String aText = pStringItem->GetValue();
+ if ( aText.Len() )
+ GetpApp()->ShowStatusText( aText );
+ else
+ GetpApp()->HideStatusText();
+ break;
+ }
+
+ case SID_PLAYMACRO:
+ PlayMacro_Impl( rReq, GetBasic() );
+ break;
+
+ case SID_OFFICE_PRIVATE_USE:
+ case SID_OFFICE_COMMERCIAL_USE:
+ {
+ DBG_ASSERT( sal_False, "SfxApplication::PropExec_Impl()\nSID_OFFICE_PRIVATE_USE & SID_OFFICE_COMMERCIAL_USE are obsolete!\n" );
+ break;
+ }
+
+ case SID_OFFICE_CUSTOMERNUMBER:
+ {
+ SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, nSID, sal_False);
+
+ if ( pStringItem )
+ SvtUserOptions().SetCustomerNumber( pStringItem->GetValue() );
+ break;
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+void SfxApplication::PropState_Impl( SfxItemSet &rSet )
+{
+// SfxViewFrame *pFrame = SfxViewFrame::Current();
+ SfxWhichIter aIter(rSet);
+ for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
+ {
+ switch ( nSID )
+ {
+ case SID_PROGNAME:
+ rSet.Put( SfxStringItem( SID_PROGNAME, GetName() ) );
+ break;
+
+ case SID_ACTIVEDOCUMENT:
+ rSet.Put( SfxObjectItem( SID_ACTIVEDOCUMENT, SfxObjectShell::Current() ) );
+ break;
+
+ case SID_APPLICATION:
+ rSet.Put( SfxObjectItem( SID_APPLICATION, this ) );
+ break;
+
+ case SID_PROGFILENAME:
+ rSet.Put( SfxStringItem( SID_PROGFILENAME, Application::GetAppFileName() ) );
+ break;
+
+ case SID_ATTR_UNDO_COUNT:
+ rSet.Put( SfxUInt16Item( SID_ATTR_UNDO_COUNT, sal::static_int_cast< UINT16 >( SvtUndoOptions().GetUndoCount() ) ) );
+ break;
+
+ case SID_UPDATE_VERSION:
+ rSet.Put( SfxUInt32Item( SID_UPDATE_VERSION, SUPD ) );
+ break;
+
+ case SID_BUILD_VERSION:
+ {
+ String aVersion = lcl_GetVersionString(pAppData_Impl->pLabelResMgr);
+ rSet.Put( SfxUInt32Item( SID_BUILD_VERSION, (sal_uInt32) aVersion.ToInt32() ) );
+ break;
+ }
+
+ case SID_OFFICE_PRIVATE_USE:
+ case SID_OFFICE_COMMERCIAL_USE:
+ {
+ DBG_ASSERT( sal_False, "SfxApplication::PropState_Impl()\nSID_OFFICE_PRIVATE_USE & SID_OFFICE_COMMERCIAL_USE are obsolete!\n" );
+ break;
+ }
+
+ case SID_OFFICE_CUSTOMERNUMBER:
+ {
+ rSet.Put( SfxStringItem( nSID, SvtUserOptions().GetCustomerNumber() ) );
+ break;
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+void SfxApplication::MacroExec_Impl( SfxRequest& rReq )
+{
+ DBG_MEMTEST();
+ if ( SfxMacroConfig::IsMacroSlot( rReq.GetSlot() ) )
+ {
+ // SlotId referenzieren, damit nicht im Execute der Slot abgeschossen
+ // werden kann
+ GetMacroConfig()->RegisterSlotId(rReq.GetSlot());
+ SFX_REQUEST_ARG(rReq, pArgs, SfxStringItem,
+ rReq.GetSlot(), sal_False);
+ String aArgs;
+ if( pArgs ) aArgs = pArgs->GetValue();
+ if ( GetMacroConfig()->ExecuteMacro(rReq.GetSlot(), aArgs ) )
+ rReq.Done();
+ GetMacroConfig()->ReleaseSlotId(rReq.GetSlot());
+ }
+}
+
+//--------------------------------------------------------------------
+void SfxApplication::MacroState_Impl( SfxItemSet& )
+{
+ DBG_MEMTEST();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxApplication::PlayMacro_Impl( SfxRequest &rReq, StarBASIC *pBasic )
+{
+ EnterBasicCall();
+ sal_Bool bOK = sal_False;
+
+ // Makro und asynch-Flag
+ SFX_REQUEST_ARG(rReq,pMacro,SfxStringItem,SID_STATEMENT,sal_False);
+ SFX_REQUEST_ARG(rReq,pAsynch,SfxBoolItem,SID_ASYNCHRON,sal_False);
+
+ if ( pAsynch && pAsynch->GetValue() )
+ {
+ // asynchron ausf"uhren
+ GetDispatcher_Impl()->Execute( SID_PLAYMACRO, SFX_CALLMODE_ASYNCHRON, pMacro, 0L );
+ rReq.Done();
+ }
+ else if ( pMacro )
+ {
+ // Statement aufbereiten
+ DBG_ASSERT( pBasic, "no BASIC found" ) ;
+ String aStatement( '[' );
+ aStatement += pMacro->GetValue();
+ aStatement += ']';
+
+ // P"aventiv den Request abschlie\sen, da er ggf. zerst"ort wird
+ rReq.Done();
+ rReq.ReleaseArgs();
+
+ // Statement ausf"uhren
+ pBasic->Execute( aStatement );
+ bOK = 0 == SbxBase::GetError();
+ SbxBase::ResetError();
+ }
+
+ LeaveBasicCall();
+ rReq.SetReturnValue(SfxBoolItem(0,bOK));
+}
+
+
diff --git a/sfx2/source/appl/appbaslib.cxx b/sfx2/source/appl/appbaslib.cxx
new file mode 100755
index 000000000000..7f4e8cedb637
--- /dev/null
+++ b/sfx2/source/appl/appbaslib.cxx
@@ -0,0 +1,252 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "appbaslib.hxx"
+
+#include <sfx2/sfxuno.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/app.hxx>
+
+#include <basic/basmgr.hxx>
+#include <tools/diagnose_ex.h>
+#include <comphelper/processfactory.hxx>
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::script;
+using namespace ::com::sun::star::embed;
+using ::rtl::OUString;
+using ::osl::MutexGuard;
+using ::osl::Mutex;
+
+//============================================================================
+SfxBasicManagerHolder::SfxBasicManagerHolder()
+ :mpBasicManager( NULL )
+{
+}
+
+void SfxBasicManagerHolder::reset( BasicManager* _pBasicManager )
+{
+ impl_releaseContainers();
+
+ // Note: we do not delete the old BasicManager. BasicManager instances are
+ // nowadays obtained from the BasicManagerRepository, and the ownership is with
+ // the repository.
+ // @see basic::BasicManagerRepository::getApplicationBasicManager
+ // @see basic::BasicManagerRepository::getDocumentBasicManager
+ mpBasicManager = _pBasicManager;
+
+ if ( mpBasicManager )
+ {
+ try
+ {
+ mxBasicContainer.set( mpBasicManager->GetScriptLibraryContainer(), UNO_QUERY_THROW );
+ mxDialogContainer.set( mpBasicManager->GetDialogLibraryContainer(), UNO_QUERY_THROW );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+}
+
+bool SfxBasicManagerHolder::isAnyContainerModified() const
+{
+ OSL_PRECOND( isValid(), "SfxBasicManagerHolder::isAnyContainerModified: not initialized!" );
+
+ if ( mxBasicContainer.is() && mxBasicContainer->isModified() )
+ return true;
+ if ( mxDialogContainer.is() && mxDialogContainer->isModified() )
+ return true;
+
+ return false;
+}
+
+void SfxBasicManagerHolder::storeAllLibraries()
+{
+ OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
+ try
+ {
+ if ( mxBasicContainer.is() )
+ mxBasicContainer->storeLibraries();
+ if ( mxDialogContainer.is() )
+ mxDialogContainer->storeLibraries();
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+}
+
+void SfxBasicManagerHolder::setStorage( const Reference< XStorage >& _rxStorage )
+{
+ try
+ {
+ if ( mxBasicContainer.is() )
+ mxBasicContainer->setRootStorage( _rxStorage );
+ if ( mxDialogContainer.is() )
+ mxDialogContainer->setRootStorage( _rxStorage );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+}
+
+void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference< XStorage >& _rxStorage )
+{
+ OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
+
+ try
+ {
+ if ( mxBasicContainer.is() )
+ mxBasicContainer->storeLibrariesToStorage( _rxStorage );
+ if ( mxDialogContainer.is() )
+ mxDialogContainer->storeLibrariesToStorage( _rxStorage );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+}
+
+Reference< XLibraryContainer > SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType )
+{
+ OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
+
+ switch ( _eType )
+ {
+ case SCRIPTS: return mxBasicContainer.get();
+ case DIALOGS: return mxDialogContainer.get();
+ }
+ DBG_ERROR( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
+ return NULL;
+}
+
+void SfxBasicManagerHolder::impl_releaseContainers()
+{
+ mxBasicContainer.clear();
+ mxDialogContainer.clear();
+}
+
+sal_Bool
+SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence< rtl::OUString >& sModules )
+{
+ if ( mpBasicManager )
+ return mpBasicManager->LegacyPsswdBinaryLimitExceeded( sModules );
+ return sal_True;
+}
+
+//============================================================================
+// Service for application library container
+SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationDialogLibraryContainer )
+
+Sequence< OUString > SfxApplicationDialogLibraryContainer::impl_getStaticSupportedServiceNames()
+{
+ static Sequence< OUString > seqServiceNames( 1 );
+ static sal_Bool bNeedsInit = sal_True;
+
+ MutexGuard aGuard( Mutex::getGlobalMutex() );
+ if( bNeedsInit )
+ {
+ OUString* pSeq = seqServiceNames.getArray();
+ pSeq[0] = OUString::createFromAscii( "com.sun.star.script.ApplicationDialogLibraryContainer" );
+ bNeedsInit = sal_False;
+ }
+ return seqServiceNames;
+}
+
+OUString SfxApplicationDialogLibraryContainer::impl_getStaticImplementationName()
+{
+ static OUString aImplName;
+ static sal_Bool bNeedsInit = sal_True;
+
+ MutexGuard aGuard( Mutex::getGlobalMutex() );
+ if( bNeedsInit )
+ {
+ aImplName = OUString::createFromAscii( "com.sun.star.comp.sfx2.ApplicationDialogLibraryContainer" );
+ bNeedsInit = sal_False;
+ }
+ return aImplName;
+}
+
+Reference< XInterface > SAL_CALL SfxApplicationDialogLibraryContainer::impl_createInstance
+ ( const Reference< XMultiServiceFactory >& )
+ throw( Exception )
+{
+ SFX_APP()->GetBasicManager();
+ Reference< XInterface > xRet =
+ Reference< XInterface >( SFX_APP()->GetDialogContainer(), UNO_QUERY );
+ return xRet;
+}
+
+//============================================================================
+// Service for application library container
+SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationScriptLibraryContainer )
+
+Sequence< OUString > SfxApplicationScriptLibraryContainer::impl_getStaticSupportedServiceNames()
+{
+ static Sequence< OUString > seqServiceNames( 1 );
+ static sal_Bool bNeedsInit = sal_True;
+
+ MutexGuard aGuard( Mutex::getGlobalMutex() );
+ if( bNeedsInit )
+ {
+ OUString* pSeq = seqServiceNames.getArray();
+ pSeq[0] = OUString::createFromAscii( "com.sun.star.script.ApplicationScriptLibraryContainer" );
+ bNeedsInit = sal_False;
+ }
+ return seqServiceNames;
+}
+
+OUString SfxApplicationScriptLibraryContainer::impl_getStaticImplementationName()
+{
+ static OUString aImplName;
+ static sal_Bool bNeedsInit = sal_True;
+
+ MutexGuard aGuard( Mutex::getGlobalMutex() );
+ if( bNeedsInit )
+ {
+ aImplName = OUString::createFromAscii( "com.sun.star.comp.sfx2.ApplicationScriptLibraryContainer" );
+ bNeedsInit = sal_False;
+ }
+ return aImplName;
+}
+
+Reference< XInterface > SAL_CALL SfxApplicationScriptLibraryContainer::impl_createInstance
+ ( const Reference< XMultiServiceFactory >& )
+ throw( Exception )
+{
+ SFX_APP()->GetBasicManager();
+ Reference< XInterface > xRet =
+ Reference< XInterface >( SFX_APP()->GetBasicContainer(), UNO_QUERY );
+ return xRet;
+}
+
diff --git a/sfx2/source/appl/appcfg.cxx b/sfx2/source/appl/appcfg.cxx
new file mode 100644
index 000000000000..c876db373d35
--- /dev/null
+++ b/sfx2/source/appl/appcfg.cxx
@@ -0,0 +1,1040 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#ifndef _COM_SUN_STAR_BEANS_PropertyValue_HPP_
+#include <com/sun/star/beans/PropertyValue.hpp>
+#endif
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/util/XFlushable.hpp>
+
+#ifndef _STDLIB_H
+#include <stdlib.h>
+#endif
+#include <tools/config.hxx>
+#include <vcl/sound.hxx>
+#include <vcl/msgbox.hxx>
+#include <tools/string.hxx>
+#include <svl/itempool.hxx>
+#include <svl/aeitem.hxx>
+#include <svl/slstitm.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/szitem.hxx>
+#include <svl/undo.hxx>
+
+#define _SVSTDARR_STRINGS
+#include <svl/svstdarr.hxx>
+#include <svtools/ttprops.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <sot/exchange.hxx>
+
+#include <svl/isethint.hxx>
+
+#include <unotools/configmgr.hxx>
+#include <tools/urlobj.hxx>
+#include <tools/wldcrd.hxx>
+#include <unotools/saveopt.hxx>
+#include <svtools/helpopt.hxx>
+#include <unotools/undoopt.hxx>
+#include <unotools/securityoptions.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/inetoptions.hxx>
+#include <svtools/miscopt.hxx>
+#include <vcl/toolbox.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <comphelper/processfactory.hxx>
+#include <rtl/ustrbuf.hxx>
+
+#include <sfx2/app.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "sfx2/sfxhelp.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/dispatch.hxx>
+#include <sfx2/objsh.hxx>
+#include "objshimp.hxx"
+#include <sfx2/viewsh.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/evntconf.hxx>
+#include "appdata.hxx"
+#include "workwin.hxx"
+#include <sfx2/macrconf.hxx>
+#include "helper.hxx" // SfxContentHelper::...
+#include "app.hrc"
+#include "sfx2/sfxresid.hxx"
+#include "shutdownicon.hxx"
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::beans;
+
+//-------------------------------------------------------------------------
+
+class SfxEventAsyncer_Impl : public SfxListener
+{
+ SfxEventHint aHint;
+ Timer* pTimer;
+
+public:
+
+ virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
+ SfxEventAsyncer_Impl( const SfxEventHint& rHint );
+ ~SfxEventAsyncer_Impl();
+ DECL_LINK( TimerHdl, Timer*);
+};
+
+// -----------------------------------------------------------------------
+
+void SfxEventAsyncer_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
+{
+ SfxSimpleHint* pHint = PTR_CAST( SfxSimpleHint, &rHint );
+ if( pHint && pHint->GetId() == SFX_HINT_DYING && pTimer->IsActive() )
+ {
+ pTimer->Stop();
+ delete this;
+ }
+}
+
+// -----------------------------------------------------------------------
+
+SfxEventAsyncer_Impl::SfxEventAsyncer_Impl( const SfxEventHint& rHint )
+ : aHint( rHint )
+{
+ if( rHint.GetObjShell() )
+ StartListening( *rHint.GetObjShell() );
+ pTimer = new Timer;
+ pTimer->SetTimeoutHdl( LINK(this, SfxEventAsyncer_Impl, TimerHdl) );
+ pTimer->SetTimeout( 0 );
+ pTimer->Start();
+}
+
+// -----------------------------------------------------------------------
+
+SfxEventAsyncer_Impl::~SfxEventAsyncer_Impl()
+{
+ delete pTimer;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK(SfxEventAsyncer_Impl, TimerHdl, Timer*, pAsyncTimer)
+{
+ (void)pAsyncTimer; // unused variable
+ SfxObjectShellRef xRef( aHint.GetObjShell() );
+ pAsyncTimer->Stop();
+#ifdef DBG_UTIL
+ if (!xRef.Is())
+ {
+ ByteString aTmp( "SfxEvent: ");
+ aTmp += ByteString( String( aHint.GetEventName() ), RTL_TEXTENCODING_UTF8 );
+ DBG_TRACE( aTmp.GetBuffer() );
+ }
+#endif
+ SFX_APP()->Broadcast( aHint );
+ if ( xRef.Is() )
+ xRef->Broadcast( aHint );
+ delete this;
+ return 0L;
+}
+
+
+//--------------------------------------------------------------------
+
+BOOL SfxApplication::GetOptions( SfxItemSet& rSet )
+{
+ BOOL bRet = FALSE;
+ SfxItemPool &rPool = GetPool();
+ String aTRUEStr('1');
+
+ const USHORT *pRanges = rSet.GetRanges();
+ SvtSaveOptions aSaveOptions;
+ SvtUndoOptions aUndoOptions;
+ SvtHelpOptions aHelpOptions;
+ SvtInetOptions aInetOptions;
+ SvtSecurityOptions aSecurityOptions;
+ SvtMiscOptions aMiscOptions;
+
+ while ( *pRanges )
+ {
+ for(USHORT nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
+ {
+ switch(nWhich)
+ {
+ case SID_ATTR_BUTTON_OUTSTYLE3D :
+ if(rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_BUTTON_OUTSTYLE3D ),
+ aMiscOptions.GetToolboxStyle() != TOOLBOX_STYLE_FLAT)))
+ bRet = TRUE;
+ break;
+ case SID_ATTR_BUTTON_BIGSIZE :
+ {
+ if( rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_BUTTON_BIGSIZE ), aMiscOptions.AreCurrentSymbolsLarge() ) ) )
+ bRet = TRUE;
+ break;
+ }
+ case SID_ATTR_BACKUP :
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_BACKUP))
+ if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_BACKUP ),aSaveOptions.IsBackup())))
+ bRet = FALSE;
+ }
+ break;
+ case SID_ATTR_PRETTYPRINTING:
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_DOPRETTYPRINTING))
+ if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_PRETTYPRINTING ), aSaveOptions.IsPrettyPrinting())))
+ bRet = FALSE;
+ }
+ break;
+ case SID_ATTR_WARNALIENFORMAT:
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_WARNALIENFORMAT))
+ if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_WARNALIENFORMAT ), aSaveOptions.IsWarnAlienFormat())))
+ bRet = FALSE;
+ }
+ break;
+ case SID_ATTR_AUTOSAVE :
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_AUTOSAVE))
+ if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_AUTOSAVE ), aSaveOptions.IsAutoSave())))
+ bRet = FALSE;
+ }
+ break;
+ case SID_ATTR_AUTOSAVEPROMPT :
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_AUTOSAVEPROMPT))
+ if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_AUTOSAVEPROMPT ), aSaveOptions.IsAutoSavePrompt())))
+ bRet = FALSE;
+ }
+ break;
+ case SID_ATTR_AUTOSAVEMINUTE :
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_AUTOSAVETIME))
+ if (!rSet.Put( SfxUInt16Item( rPool.GetWhich( SID_ATTR_AUTOSAVEMINUTE ), (UINT16)aSaveOptions.GetAutoSaveTime())))
+ bRet = FALSE;
+ }
+ break;
+ case SID_ATTR_DOCINFO :
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_DOCINFSAVE))
+ if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_DOCINFO ), aSaveOptions.IsDocInfoSave())))
+ bRet = FALSE;
+ }
+ break;
+ case SID_ATTR_WORKINGSET :
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_SAVEWORKINGSET))
+ if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_WORKINGSET ), aSaveOptions.IsSaveWorkingSet())))
+ bRet = FALSE;
+ }
+ break;
+ case SID_ATTR_SAVEDOCVIEW :
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_SAVEDOCVIEW))
+ if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_SAVEDOCVIEW ), aSaveOptions.IsSaveDocView())))
+ bRet = FALSE;
+ }
+ break;
+ case SID_ATTR_METRIC :
+// if(rSet.Put( SfxUInt16Item( rPool.GetWhich( SID_ATTR_METRIC ),
+// pOptions->GetMetric() ) ) )
+// bRet = TRUE;
+ break;
+ case SID_HELPBALLOONS :
+ if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_HELPBALLOONS ),
+ aHelpOptions.IsExtendedHelp() ) ) )
+ bRet = TRUE;
+ break;
+ case SID_HELPTIPS :
+ if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_HELPTIPS ),
+ aHelpOptions.IsHelpTips() ) ) )
+ bRet = TRUE;
+ break;
+ case SID_ATTR_AUTOHELPAGENT :
+ if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_ATTR_AUTOHELPAGENT ),
+ aHelpOptions.IsHelpAgentAutoStartMode() ) ) )
+ bRet = TRUE;
+ break;
+ case SID_HELPAGENT_TIMEOUT :
+ if ( rSet.Put( SfxInt32Item( rPool.GetWhich( SID_HELPAGENT_TIMEOUT ),
+ aHelpOptions.GetHelpAgentTimeoutPeriod() ) ) )
+ bRet = TRUE;
+ break;
+ case SID_ATTR_WELCOMESCREEN :
+ if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_ATTR_WELCOMESCREEN ),
+ aHelpOptions.IsWelcomeScreen() ) ) )
+ bRet = TRUE;
+ break;
+ case SID_HELP_STYLESHEET :
+ if(rSet.Put( SfxStringItem ( rPool.GetWhich( SID_HELP_STYLESHEET ),
+ aHelpOptions.GetHelpStyleSheet() ) ) )
+ bRet = TRUE;
+ break;
+ case SID_ATTR_UNDO_COUNT :
+ if(rSet.Put( SfxUInt16Item ( rPool.GetWhich( SID_ATTR_UNDO_COUNT ),
+ (UINT16)aUndoOptions.GetUndoCount() ) ) )
+ bRet = TRUE;
+ break;
+ case SID_ATTR_QUICKLAUNCHER :
+ {
+ if ( ShutdownIcon::IsQuickstarterInstalled() )
+ {
+ if ( rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_QUICKLAUNCHER ),
+ ShutdownIcon::GetAutostart() ) ) )
+ bRet = TRUE;
+ }
+ else
+ {
+ rSet.DisableItem( rPool.GetWhich( SID_ATTR_QUICKLAUNCHER ) );
+ bRet = TRUE;
+ }
+ break;
+ }
+ case SID_SAVEREL_INET :
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_SAVERELINET))
+ if (!rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_SAVEREL_INET ), aSaveOptions.IsSaveRelINet() )))
+ bRet = FALSE;
+ }
+ break;
+ case SID_SAVEREL_FSYS :
+ {
+ bRet = TRUE;
+ if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_SAVERELFSYS))
+ if (!rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_SAVEREL_FSYS ), aSaveOptions.IsSaveRelFSys() )))
+ bRet = FALSE;
+ }
+ break;
+ case SID_BASIC_ENABLED :
+ {
+ bRet = TRUE;
+ if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::E_BASICMODE))
+ {
+ if ( !rSet.Put( SfxUInt16Item( rPool.GetWhich( SID_BASIC_ENABLED ), sal::static_int_cast< UINT16 >(aSecurityOptions.GetBasicMode()))))
+ bRet = FALSE;
+ }
+ }
+ break;
+ case SID_INET_EXE_PLUGIN :
+ {
+ bRet = TRUE;
+ if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::E_EXECUTEPLUGINS))
+ {
+ if ( !rSet.Put( SfxBoolItem( SID_INET_EXE_PLUGIN, aSecurityOptions.IsExecutePlugins() ) ) )
+ bRet = FALSE;
+ }
+ }
+ break;
+ case SID_MACRO_WARNING :
+ {
+ bRet = TRUE;
+ if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::E_WARNING))
+ {
+ if ( !rSet.Put( SfxBoolItem( SID_MACRO_WARNING, aSecurityOptions.IsWarningEnabled() ) ) )
+ bRet = FALSE;
+ }
+ }
+ break;
+ case SID_MACRO_CONFIRMATION :
+ {
+ bRet = TRUE;
+ if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::E_CONFIRMATION))
+ {
+ if ( !rSet.Put( SfxBoolItem( SID_MACRO_CONFIRMATION, aSecurityOptions.IsConfirmationEnabled() ) ) )
+ bRet = FALSE;
+ }
+ }
+ break;
+ case SID_SECURE_URL :
+ {
+ bRet = TRUE;
+ if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::E_SECUREURLS))
+ {
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > seqURLs = aSecurityOptions.GetSecureURLs();
+ List aList;
+ sal_uInt32 nCount = seqURLs.getLength();
+ sal_uInt32 nURL;
+ for( nURL=0; nURL<nCount; ++nURL )
+ {
+ aList.Insert( new String( seqURLs[nURL] ), LIST_APPEND );
+ }
+ if( !rSet.Put( SfxStringListItem( rPool.GetWhich(SID_SECURE_URL),
+ &aList ) ) )
+ {
+ bRet = FALSE;
+ }
+ for( nURL=0; nURL<nCount; ++nURL )
+ {
+ delete (String*)aList.GetObject(nURL);
+ }
+ aList.Clear();
+ }
+ }
+ break;
+ case SID_ENABLE_METAFILEPRINT :
+#ifdef ENABLE_MISSINGKEYASSERTIONS//MUSTINI
+ DBG_ASSERT(sal_False, "SfxApplication::GetOptions()\nSoffice.ini key \"Common\\MetafilePrint\" is obsolete! .. How I can support SID_ENABLE_METAFILEPRINT any longer?\n");
+#endif
+ break;
+ case SID_INET_PROXY_TYPE :
+ {
+ if( rSet.Put( SfxUInt16Item ( rPool.GetWhich( SID_INET_PROXY_TYPE ),
+ (UINT16)aInetOptions.GetProxyType() )))
+ bRet = TRUE;
+ break;
+ }
+ case SID_INET_HTTP_PROXY_NAME :
+ {
+ if ( rSet.Put( SfxStringItem ( rPool.GetWhich(SID_INET_HTTP_PROXY_NAME ),
+ aInetOptions.GetProxyHttpName() )))
+ bRet = TRUE;
+ break;
+ }
+ case SID_INET_HTTP_PROXY_PORT :
+ if ( rSet.Put( SfxInt32Item( rPool.GetWhich(SID_INET_HTTP_PROXY_PORT ),
+ aInetOptions.GetProxyHttpPort() )))
+ bRet = TRUE;
+ break;
+ case SID_INET_FTP_PROXY_NAME :
+ if ( rSet.Put( SfxStringItem ( rPool.GetWhich(SID_INET_FTP_PROXY_NAME ),
+ aInetOptions.GetProxyFtpName() )))
+ bRet = TRUE;
+ break;
+ case SID_INET_FTP_PROXY_PORT :
+ if ( rSet.Put( SfxInt32Item ( rPool.GetWhich(SID_INET_FTP_PROXY_PORT ),
+ aInetOptions.GetProxyFtpPort() )))
+ bRet = TRUE;
+ break;
+ case SID_INET_SECURITY_PROXY_NAME :
+ case SID_INET_SECURITY_PROXY_PORT :
+#ifdef ENABLE_MISSINGKEYASSERTIONS//MUSTINI
+ DBG_ASSERT( sal_False, "SfxApplication::GetOptions()\nSome INET values no longer supported!\n" );
+#endif
+ break;
+ case SID_INET_NOPROXY :
+ if( rSet.Put( SfxStringItem ( rPool.GetWhich( SID_INET_NOPROXY),
+ aInetOptions.GetProxyNoProxy() )))
+ bRet = TRUE;
+ break;
+ case SID_ATTR_PATHNAME :
+ case SID_ATTR_PATHGROUP :
+ {
+ SfxAllEnumItem aNames(rPool.GetWhich(SID_ATTR_PATHGROUP));
+ SfxAllEnumItem aValues(rPool.GetWhich(SID_ATTR_PATHNAME));
+ SvtPathOptions aPathCfg;
+ for ( USHORT nProp = SvtPathOptions::PATH_ADDIN;
+ nProp <= SvtPathOptions::PATH_WORK; nProp++ )
+ {
+ const String aName( SfxResId( CONFIG_PATH_START + nProp ) );
+ aNames.InsertValue( nProp, aName );
+ String aValue;
+ switch ( nProp )
+ {
+ case SvtPathOptions::PATH_ADDIN: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetAddinPath(), aValue ); break;
+ case SvtPathOptions::PATH_AUTOCORRECT: aValue = aPathCfg.GetAutoCorrectPath(); break;
+ case SvtPathOptions::PATH_AUTOTEXT: aValue = aPathCfg.GetAutoTextPath(); break;
+ case SvtPathOptions::PATH_BACKUP: aValue = aPathCfg.GetBackupPath(); break;
+ case SvtPathOptions::PATH_BASIC: aValue = aPathCfg.GetBasicPath(); break;
+ case SvtPathOptions::PATH_BITMAP: aValue = aPathCfg.GetBitmapPath(); break;
+ case SvtPathOptions::PATH_CONFIG: aValue = aPathCfg.GetConfigPath(); break;
+ case SvtPathOptions::PATH_DICTIONARY: aValue = aPathCfg.GetDictionaryPath(); break;
+ case SvtPathOptions::PATH_FAVORITES: aValue = aPathCfg.GetFavoritesPath(); break;
+ case SvtPathOptions::PATH_FILTER: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetFilterPath(), aValue ); break;
+ case SvtPathOptions::PATH_GALLERY: aValue = aPathCfg.GetGalleryPath(); break;
+ case SvtPathOptions::PATH_GRAPHIC: aValue = aPathCfg.GetGraphicPath(); break;
+ case SvtPathOptions::PATH_HELP: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetHelpPath(), aValue ); break;
+ case SvtPathOptions::PATH_LINGUISTIC: aValue = aPathCfg.GetLinguisticPath(); break;
+ case SvtPathOptions::PATH_MODULE: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetModulePath(), aValue ); break;
+ case SvtPathOptions::PATH_PALETTE: aValue = aPathCfg.GetPalettePath(); break;
+ case SvtPathOptions::PATH_PLUGIN: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetPluginPath(), aValue ); break;
+ case SvtPathOptions::PATH_STORAGE: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetStoragePath(), aValue ); break;
+ case SvtPathOptions::PATH_TEMP: aValue = aPathCfg.GetTempPath(); break;
+ case SvtPathOptions::PATH_TEMPLATE: aValue = aPathCfg.GetTemplatePath(); break;
+ case SvtPathOptions::PATH_USERCONFIG: aValue = aPathCfg.GetUserConfigPath(); break;
+ case SvtPathOptions::PATH_WORK: aValue = aPathCfg.GetWorkPath(); break;
+ }
+ aValues.InsertValue( nProp, aValue );
+ }
+
+ if ( rSet.Put(aNames) || rSet.Put(aValues) )
+ bRet = TRUE;
+ }
+
+ default:
+ DBG_WARNING( "W1:Wrong ID while getting Options!" );
+ break;
+ }
+#ifdef DBG_UTIL
+ if ( !bRet )
+ DBG_ERROR( "Putting options failed!" );
+#endif
+ }
+ pRanges++;
+ }
+
+ return bRet;
+}
+
+//--------------------------------------------------------------------
+BOOL SfxApplication::IsSecureURL( const INetURLObject& rURL, const String* pReferer ) const
+{
+ return SvtSecurityOptions().IsSecureURL( rURL.GetMainURL( INetURLObject::NO_DECODE ), *pReferer );
+}
+//--------------------------------------------------------------------
+// TODO/CLEANUP: wieso zwei SetOptions Methoden?
+void SfxApplication::SetOptions_Impl( const SfxItemSet& rSet )
+{
+ const SfxPoolItem *pItem = 0;
+ SfxItemPool &rPool = GetPool();
+ BOOL bResetSession = FALSE;
+ BOOL bProxiesModified = FALSE;
+
+ SvtSaveOptions aSaveOptions;
+ SvtUndoOptions aUndoOptions;
+ SvtHelpOptions aHelpOptions;
+ SvtSecurityOptions aSecurityOptions;
+ SvtPathOptions aPathOptions;
+ SvtInetOptions aInetOptions;
+ SvtMiscOptions aMiscOptions;
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_BUTTON_OUTSTYLE3D), TRUE, &pItem) )
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ USHORT nOutStyle =
+ ( (const SfxBoolItem *)pItem)->GetValue() ? 0 : TOOLBOX_STYLE_FLAT;
+ aMiscOptions.SetToolboxStyle( nOutStyle );
+ }
+
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_BUTTON_BIGSIZE), TRUE, &pItem) )
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ BOOL bBigSize = ( (const SfxBoolItem*)pItem )->GetValue();
+ aMiscOptions.SetSymbolsSize(
+ sal::static_int_cast< sal_Int16 >(
+ bBigSize ? SFX_SYMBOLS_SIZE_LARGE : SFX_SYMBOLS_SIZE_SMALL ) );
+ SfxViewFrame* pCurrViewFrame = SfxViewFrame::GetFirst();
+ while ( pCurrViewFrame )
+ {
+ // update all "final" dispatchers
+ if ( !pCurrViewFrame->GetActiveChildFrame_Impl() )
+ pCurrViewFrame->GetDispatcher()->Update_Impl(sal_True);
+ pCurrViewFrame = SfxViewFrame::GetNext(*pCurrViewFrame);
+ }
+ }
+
+ // Backup
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_BACKUP), TRUE, &pItem) )
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aSaveOptions.SetBackup( ( (const SfxBoolItem*)pItem )->GetValue() );
+ }
+
+ // PrettyPrinting
+ if ( SFX_ITEM_SET == rSet.GetItemState( rPool.GetWhich( SID_ATTR_PRETTYPRINTING ), TRUE, &pItem ) )
+ {
+ DBG_ASSERT( pItem->ISA( SfxBoolItem ), "BoolItem expected" );
+ aSaveOptions.SetPrettyPrinting( static_cast< const SfxBoolItem*> ( pItem )->GetValue() );
+ }
+
+ // WarnAlienFormat
+ if ( SFX_ITEM_SET == rSet.GetItemState( rPool.GetWhich( SID_ATTR_WARNALIENFORMAT ), TRUE, &pItem ) )
+ {
+ DBG_ASSERT( pItem->ISA( SfxBoolItem ), "BoolItem expected" );
+ aSaveOptions.SetWarnAlienFormat( static_cast< const SfxBoolItem*> ( pItem )->GetValue() );
+ }
+
+ // AutoSave
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVE), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aSaveOptions.SetAutoSave( ( (const SfxBoolItem*)pItem )->GetValue() );
+ }
+
+ // AutoSave-Propt
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVEPROMPT), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aSaveOptions.SetAutoSavePrompt(((const SfxBoolItem *)pItem)->GetValue());
+ }
+
+ // AutoSave-Time
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVEMINUTE), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxUInt16Item), "UInt16Item expected");
+ aSaveOptions.SetAutoSaveTime(((const SfxUInt16Item *)pItem)->GetValue());
+ }
+
+ // DocInfo
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_DOCINFO), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aSaveOptions.SetDocInfoSave(((const SfxBoolItem *)pItem)->GetValue());
+ }
+
+ // offende Dokumente merken
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_WORKINGSET), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aSaveOptions.SetSaveWorkingSet(((const SfxBoolItem *)pItem)->GetValue());
+ }
+
+ // Fenster-Einstellung speichern
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_SAVEDOCVIEW), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aSaveOptions.SetSaveDocView(((const SfxBoolItem *)pItem)->GetValue());
+ }
+
+ // Metric
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_METRIC), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxUInt16Item), "UInt16Item expected");
+// pOptions->SetMetric((FieldUnit)((const SfxUInt16Item*)pItem)->GetValue());
+ }
+
+ // HelpBalloons
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_HELPBALLOONS), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aHelpOptions.SetExtendedHelp(((const SfxBoolItem *)pItem)->GetValue());
+ }
+
+ // HelpTips
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_HELPTIPS), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aHelpOptions.SetHelpTips(((const SfxBoolItem *)pItem)->GetValue());
+ }
+
+ // AutoHelpAgent
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOHELPAGENT ), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aHelpOptions.SetHelpAgentAutoStartMode( ((const SfxBoolItem *)pItem)->GetValue() );
+ }
+
+ // help agent timeout
+ if ( SFX_ITEM_SET == rSet.GetItemState( rPool.GetWhich( SID_HELPAGENT_TIMEOUT ), TRUE, &pItem ) )
+ {
+ DBG_ASSERT(pItem->ISA(SfxInt32Item), "Int32Item expected");
+ aHelpOptions.SetHelpAgentTimeoutPeriod( ( (const SfxInt32Item*)pItem )->GetValue() );
+ }
+
+ // WelcomeScreen
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_WELCOMESCREEN ), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aHelpOptions.SetWelcomeScreen( ((const SfxBoolItem *)pItem)->GetValue() );
+ }
+
+ // WelcomeScreen
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_WELCOMESCREEN_RESET ), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ BOOL bReset = ((const SfxBoolItem *)pItem)->GetValue();
+ if ( bReset )
+ {
+ DBG_ERROR( "Not implemented, may be EOL!" );
+ } }
+
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_HELP_STYLESHEET ), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxStringItem), "StringItem expected");
+ aHelpOptions.SetHelpStyleSheet( ((const SfxStringItem *)pItem)->GetValue() );
+ }
+
+ // SaveRelINet
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_SAVEREL_INET), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aSaveOptions.SetSaveRelINet(((const SfxBoolItem *)pItem)->GetValue());
+ }
+
+ // SaveRelFSys
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_SAVEREL_FSYS), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ aSaveOptions.SetSaveRelFSys(((const SfxBoolItem *)pItem)->GetValue());
+ }
+
+ // Undo-Count
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_UNDO_COUNT), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxUInt16Item), "UInt16Item expected");
+ USHORT nUndoCount = ((const SfxUInt16Item*)pItem)->GetValue();
+ aUndoOptions.SetUndoCount( nUndoCount );
+
+ // um alle Undo-Manager zu erwischen: "uber alle Frames iterieren
+ for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst();
+ pFrame;
+ pFrame = SfxViewFrame::GetNext(*pFrame) )
+ {
+ // den Dispatcher des Frames rausholen
+ SfxDispatcher *pDispat = pFrame->GetDispatcher();
+ pDispat->Flush();
+
+ // "uber alle SfxShells auf dem Stack des Dispatchers iterieren
+ USHORT nIdx = 0;
+ for ( SfxShell *pSh = pDispat->GetShell(nIdx);
+ pSh;
+ ++nIdx, pSh = pDispat->GetShell(nIdx) )
+ {
+ SfxUndoManager *pShUndoMgr = pSh->GetUndoManager();
+ if ( pShUndoMgr )
+ pShUndoMgr->SetMaxUndoActionCount( nUndoCount );
+ }
+ }
+ }
+
+ // Office autostart
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_QUICKLAUNCHER), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+ ShutdownIcon::SetAutostart( ( (const SfxBoolItem*)pItem )->GetValue() != FALSE );
+ }
+
+ // StarBasic Enable
+ if ( SFX_ITEM_SET == rSet.GetItemState(SID_BASIC_ENABLED, TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxUInt16Item), "SfxInt16Item expected");
+ aSecurityOptions.SetBasicMode( (EBasicSecurityMode)( (const SfxUInt16Item*)pItem )->GetValue() );
+ }
+
+ // Execute PlugIns
+ if ( SFX_ITEM_SET == rSet.GetItemState(SID_INET_EXE_PLUGIN, TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "SfxBoolItem expected");
+ aSecurityOptions.SetExecutePlugins( ( (const SfxBoolItem *)pItem )->GetValue() );
+ bResetSession = TRUE;
+ }
+
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_INET_PROXY_TYPE), TRUE, &pItem))
+ {
+ DBG_ASSERT( pItem->ISA(SfxUInt16Item), "UInt16Item expected" );
+ aInetOptions.SetProxyType((SvtInetOptions::ProxyType)( (const SfxUInt16Item*)pItem )->GetValue());
+ bResetSession = TRUE;
+ bProxiesModified = TRUE;
+ }
+
+ if ( SFX_ITEM_SET == rSet.GetItemState( rPool.GetWhich( SID_INET_HTTP_PROXY_NAME ), TRUE, &pItem ) )
+ {
+ DBG_ASSERT( pItem->ISA(SfxStringItem), "StringItem expected" );
+ aInetOptions.SetProxyHttpName( ((const SfxStringItem *)pItem)->GetValue() );
+ bResetSession = TRUE;
+ bProxiesModified = TRUE;
+ }
+ if ( SFX_ITEM_SET == rSet.GetItemState( rPool.GetWhich( SID_INET_HTTP_PROXY_PORT ), TRUE, &pItem ) )
+ {
+ DBG_ASSERT( pItem->ISA(SfxInt32Item), "Int32Item expected" );
+ aInetOptions.SetProxyHttpPort( ( (const SfxInt32Item*)pItem )->GetValue() );
+ bResetSession = TRUE;
+ bProxiesModified = TRUE;
+ }
+ if ( SFX_ITEM_SET == rSet.GetItemState( rPool.GetWhich( SID_INET_FTP_PROXY_NAME ), TRUE, &pItem ) )
+ {
+ DBG_ASSERT( pItem->ISA(SfxStringItem), "StringItem expected" );
+ aInetOptions.SetProxyFtpName( ((const SfxStringItem *)pItem)->GetValue() );
+ bResetSession = TRUE;
+ bProxiesModified = TRUE;
+ }
+ if ( SFX_ITEM_SET == rSet.GetItemState( rPool.GetWhich( SID_INET_FTP_PROXY_PORT ), TRUE, &pItem ) )
+ {
+ DBG_ASSERT( pItem->ISA(SfxInt32Item), "Int32Item expected" );
+ aInetOptions.SetProxyFtpPort( ( (const SfxInt32Item*)pItem )->GetValue() );
+ bResetSession = TRUE;
+ bProxiesModified = TRUE;
+ }
+ if ( SFX_ITEM_SET == rSet.GetItemState(SID_INET_NOPROXY, TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxStringItem), "StringItem expected");
+ aInetOptions.SetProxyNoProxy(((const SfxStringItem *)pItem)->GetValue());
+ bResetSession = TRUE;
+ bProxiesModified = TRUE;
+ }
+
+ // Secure-Referers
+ if ( SFX_ITEM_SET == rSet.GetItemState(SID_SECURE_URL, TRUE, &pItem))
+ {
+ DELETEZ(pAppData_Impl->pSecureURLs);
+
+ DBG_ASSERT(pItem->ISA(SfxStringListItem), "StringListItem expected");
+ const List *pList = ((SfxStringListItem*)pItem)->GetList();
+ sal_uInt32 nCount = pList->Count();
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > seqURLs(nCount);
+ for( sal_uInt32 nPosition=0;nPosition<nCount;++nPosition)
+ {
+ seqURLs[nPosition] = *(const String*)(pList->GetObject(nPosition));
+ }
+ aSecurityOptions.SetSecureURLs( seqURLs );
+ }
+
+ if ( SFX_ITEM_SET == rSet.GetItemState(SID_MACRO_WARNING, TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "SfxBoolItem expected");
+ aSecurityOptions.SetWarningEnabled( ( (const SfxBoolItem *)pItem )->GetValue() );
+ }
+ if ( SFX_ITEM_SET == rSet.GetItemState(SID_MACRO_CONFIRMATION, TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxBoolItem), "SfxBoolItem expected");
+ aSecurityOptions.SetConfirmationEnabled( ( (const SfxBoolItem *)pItem )->GetValue() );
+ }
+
+ // EnableMetafilePrint
+ if ( SFX_ITEM_SET == rSet.GetItemState( rPool.GetWhich( SID_ENABLE_METAFILEPRINT ), TRUE, &pItem ) )
+ {
+#ifdef ENABLE_MISSINGKEYASSERTIONS//MUSTINI
+ DBG_ASSERT(sal_False, "SfxApplication::SetOptions_Impl()\nsoffice.ini key \"MetafilPrint\" not supported any longer!\n");
+#endif
+ }
+
+ // geaenderte Daten speichern
+ aInetOptions.flush();
+}
+
+//--------------------------------------------------------------------
+void SfxApplication::SetOptions(const SfxItemSet &rSet)
+{
+ SvtPathOptions aPathOptions;
+
+ // Daten werden in DocInfo und IniManager gespeichert
+ const SfxPoolItem *pItem = 0;
+ SfxItemPool &rPool = GetPool();
+
+ SfxAllItemSet aSendSet( rSet );
+
+ // PathName
+ if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_PATHNAME), TRUE, &pItem))
+ {
+ DBG_ASSERT(pItem->ISA(SfxAllEnumItem), "AllEnumItem expected");
+ const SfxAllEnumItem* pEnumItem = (const SfxAllEnumItem *)pItem;
+ sal_uInt32 nCount = pEnumItem->GetValueCount();
+ String aNoChangeStr( ' ' );
+ for( sal_uInt32 nPath=0; nPath<nCount; ++nPath )
+ {
+ String sValue = pEnumItem->GetValueTextByPos((USHORT)nPath);
+ if ( sValue != aNoChangeStr )
+ {
+ switch( nPath )
+ {
+ case SvtPathOptions::PATH_ADDIN:
+ {
+ String aTmp;
+ if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
+ aPathOptions.SetAddinPath( aTmp );
+ break;
+ }
+
+ case SvtPathOptions::PATH_AUTOCORRECT: aPathOptions.SetAutoCorrectPath( sValue );break;
+ case SvtPathOptions::PATH_AUTOTEXT: aPathOptions.SetAutoTextPath( sValue );break;
+ case SvtPathOptions::PATH_BACKUP: aPathOptions.SetBackupPath( sValue );break;
+ case SvtPathOptions::PATH_BASIC: aPathOptions.SetBasicPath( sValue );break;
+ case SvtPathOptions::PATH_BITMAP: aPathOptions.SetBitmapPath( sValue );break;
+ case SvtPathOptions::PATH_CONFIG: aPathOptions.SetConfigPath( sValue );break;
+ case SvtPathOptions::PATH_DICTIONARY: aPathOptions.SetDictionaryPath( sValue );break;
+ case SvtPathOptions::PATH_FAVORITES: aPathOptions.SetFavoritesPath( sValue );break;
+ case SvtPathOptions::PATH_FILTER:
+ {
+ String aTmp;
+ if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
+ aPathOptions.SetFilterPath( aTmp );
+ break;
+ }
+ case SvtPathOptions::PATH_GALLERY: aPathOptions.SetGalleryPath( sValue );break;
+ case SvtPathOptions::PATH_GRAPHIC: aPathOptions.SetGraphicPath( sValue );break;
+ case SvtPathOptions::PATH_HELP:
+ {
+ String aTmp;
+ if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
+ aPathOptions.SetHelpPath( aTmp );
+ break;
+ }
+
+ case SvtPathOptions::PATH_LINGUISTIC: aPathOptions.SetLinguisticPath( sValue );break;
+ case SvtPathOptions::PATH_MODULE:
+ {
+ String aTmp;
+ if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
+ aPathOptions.SetModulePath( aTmp );
+ break;
+ }
+
+ case SvtPathOptions::PATH_PALETTE: aPathOptions.SetPalettePath( sValue );break;
+ case SvtPathOptions::PATH_PLUGIN:
+ {
+ String aTmp;
+ if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
+ aPathOptions.SetPluginPath( aTmp );
+ break;
+ }
+
+ case SvtPathOptions::PATH_STORAGE:
+ {
+ String aTmp;
+ if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
+ aPathOptions.SetStoragePath( aTmp );
+ break;
+ }
+
+ case SvtPathOptions::PATH_TEMP: aPathOptions.SetTempPath( sValue );break;
+ case SvtPathOptions::PATH_TEMPLATE: aPathOptions.SetTemplatePath( sValue );break;
+ case SvtPathOptions::PATH_USERCONFIG: aPathOptions.SetUserConfigPath( sValue );break;
+ case SvtPathOptions::PATH_WORK: aPathOptions.SetWorkPath( sValue );break;
+ default: DBG_ERRORFILE("SfxApplication::SetOptions_Impl()\nInvalid path number found for set directories!");
+ }
+ }
+ }
+
+ aSendSet.ClearItem( rPool.GetWhich( SID_ATTR_PATHNAME ) );
+ }
+
+ SetOptions_Impl( rSet );
+
+ // Undo-Count
+ Broadcast( SfxItemSetHint( rSet ) );
+}
+
+//--------------------------------------------------------------------
+
+// alle Dokumente speichern
+
+BOOL SfxApplication::SaveAll_Impl(BOOL bPrompt, BOOL bAutoSave)
+{
+ bAutoSave = FALSE; // functionality moved to new AutoRecovery Service!
+
+ BOOL bFunc = TRUE;
+ short nRet;
+
+ for ( SfxObjectShell *pDoc = SfxObjectShell::GetFirst();
+ pDoc;
+ pDoc = SfxObjectShell::GetNext(*pDoc) )
+ {
+ if( SFX_CREATE_MODE_STANDARD == pDoc->GetCreateMode() &&
+ SfxViewFrame::GetFirst(pDoc) &&
+ !pDoc->IsInModalMode() &&
+ !pDoc->HasModalViews() )
+ {
+ if ( pDoc->GetProgress() == 0 )
+ {
+ if ( !pDoc->IsModified() )
+ continue;
+
+ if ( bPrompt || (bAutoSave && !pDoc->HasName()) )
+ nRet = QuerySave_Impl( *pDoc, bAutoSave );
+ else
+ nRet = RET_YES;
+
+ if ( nRet == RET_YES )
+ {
+ SfxRequest aReq( SID_SAVEDOC, 0, pDoc->GetPool() );
+ const SfxPoolItem *pPoolItem = pDoc->ExecuteSlot( aReq );
+ if ( !pPoolItem || !pPoolItem->ISA(SfxBoolItem) ||
+ !( (const SfxBoolItem*) pPoolItem )->GetValue() )
+ bFunc = FALSE;
+ }
+ else if ( nRet == RET_CANCEL )
+ {
+ bFunc = FALSE;
+ break;
+ }
+ else if ( nRet == RET_NO )
+ {
+ }
+ }
+ }
+ }
+
+ return bFunc;
+}
+
+//--------------------------------------------------------------------
+
+SfxMacroConfig* SfxApplication::GetMacroConfig() const
+{
+ return SfxMacroConfig::GetOrCreate();
+}
+
+//--------------------------------------------------------------------
+SfxEventConfiguration* SfxApplication::GetEventConfig() const
+{
+ if (!pAppData_Impl->pEventConfig)
+ pAppData_Impl->pEventConfig = new SfxEventConfiguration;
+ return pAppData_Impl->pEventConfig;
+}
+
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+void SfxApplication::NotifyEvent( const SfxEventHint& rEventHint, FASTBOOL bSynchron )
+{
+ //DBG_ASSERT(pAppData_Impl->pEventConfig,"Keine Events angemeldet!");
+
+ SfxObjectShell *pDoc = rEventHint.GetObjShell();
+ if ( pDoc && ( pDoc->IsPreview() || !pDoc->Get_Impl()->bInitialized ) )
+ return;
+
+#ifdef DBG_UTIL
+ //::rtl::OUString aName = SfxEventConfiguration::GetEventName_Impl( rEventHint.GetEventId() );
+ //ByteString aTmp( "SfxEvent: ");
+ //aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
+ //DBG_TRACE( aTmp.GetBuffer() );
+#endif
+
+ if ( bSynchron )
+ {
+#ifdef DBG_UTIL
+ if (!pDoc)
+ {
+ ByteString aTmp( "SfxEvent: ");
+ aTmp += ByteString( String( rEventHint.GetEventName() ), RTL_TEXTENCODING_UTF8 );
+ DBG_TRACE( aTmp.GetBuffer() );
+ }
+#endif
+ Broadcast(rEventHint);
+ if ( pDoc )
+ pDoc->Broadcast( rEventHint );
+ }
+ else
+ new SfxEventAsyncer_Impl( rEventHint );
+}
+
+IMPL_OBJHINT( SfxStringHint, String )
+
diff --git a/sfx2/source/appl/appchild.cxx b/sfx2/source/appl/appchild.cxx
new file mode 100644
index 000000000000..b18fc905abdc
--- /dev/null
+++ b/sfx2/source/appl/appchild.cxx
@@ -0,0 +1,176 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+#include <svl/whiter.hxx>
+#include <svl/eitem.hxx>
+
+#include <sfx2/app.hxx>
+#include "appdata.hxx"
+#include "workwin.hxx"
+#include <sfx2/childwin.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/templdlg.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/module.hxx>
+#include <sfx2/sfxsids.hrc>
+
+//=========================================================================
+
+
+void SfxApplication::RegisterChildWindow_Impl( SfxModule *pMod, SfxChildWinFactory *pFact )
+{
+ if ( pMod )
+ {
+ pMod->RegisterChildWindow( pFact );
+ return;
+ }
+
+ if (!pAppData_Impl->pFactArr)
+ pAppData_Impl->pFactArr = new SfxChildWinFactArr_Impl;
+
+//#ifdef DBG_UTIL
+ for (USHORT nFactory=0; nFactory<pAppData_Impl->pFactArr->Count(); ++nFactory)
+ {
+ if (pFact->nId == (*pAppData_Impl->pFactArr)[nFactory]->nId)
+ {
+ pAppData_Impl->pFactArr->Remove( nFactory );
+// DBG_ERROR("ChildWindow mehrfach registriert!");
+// return;
+ }
+ }
+//#endif
+
+ pAppData_Impl->pFactArr->C40_INSERT(
+ SfxChildWinFactory, pFact, pAppData_Impl->pFactArr->Count() );
+}
+
+void SfxApplication::RegisterChildWindowContext_Impl( SfxModule *pMod, USHORT nId,
+ SfxChildWinContextFactory *pFact)
+{
+ SfxChildWinFactArr_Impl *pFactories;
+ SfxChildWinFactory *pF = NULL;
+ if ( pMod )
+ {
+ // Modul "ubergeben, ChildwindowFactory dort suchen
+ pFactories = pMod->GetChildWinFactories_Impl();
+ if ( pFactories )
+ {
+ USHORT nCount = pFactories->Count();
+ for (USHORT nFactory=0; nFactory<nCount; ++nFactory)
+ {
+ SfxChildWinFactory *pFac = (*pFactories)[nFactory];
+ if ( nId == pFac->nId )
+ {
+ // Factory gefunden, Context dort registrieren
+ pF = pFac;
+ break;
+ }
+ }
+ }
+ }
+
+ if ( !pF )
+ {
+ // Factory an der Application suchen
+ DBG_ASSERT( pAppData_Impl, "Keine AppDaten!" );
+ DBG_ASSERT( pAppData_Impl->pFactArr, "Keine Factories!" );
+
+ pFactories = pAppData_Impl->pFactArr;
+ USHORT nCount = pFactories->Count();
+ for (USHORT nFactory=0; nFactory<nCount; ++nFactory)
+ {
+ SfxChildWinFactory *pFac = (*pFactories)[nFactory];
+ if ( nId == pFac->nId )
+ {
+ if ( pMod )
+ {
+ // Wenn der Context von einem Modul registriert wurde,
+ // mu\s die ChildwindowFactory auch dort zur Verf"ugung
+ // stehen, sonst m"u\ste sich die Contextfactory im DLL-Exit
+ // wieder abmelden !
+ pF = new SfxChildWinFactory( pFac->pCtor, pFac->nId,
+ pFac->nPos );
+ pMod->RegisterChildWindow( pF );
+ }
+ else
+ pF = pFac;
+ break;
+ }
+ }
+ }
+
+ if ( pF )
+ {
+ if ( !pF->pArr )
+ pF->pArr = new SfxChildWinContextArr_Impl;
+ pF->pArr->C40_INSERT( SfxChildWinContextFactory, pFact, pF->pArr->Count() );
+ return;
+ }
+
+ DBG_ERROR( "Kein ChildWindow fuer diesen Context!" );
+}
+
+//--------------------------------------------------------------------
+
+SfxChildWinFactArr_Impl& SfxApplication::GetChildWinFactories_Impl() const
+{
+ return ( *(pAppData_Impl->pFactArr));
+}
+
+//--------------------------------------------------------------------
+
+SfxTemplateDialog* SfxApplication::GetTemplateDialog()
+{
+ if ( pAppData_Impl->pViewFrame )
+ {
+ SfxChildWindow *pChild = pAppData_Impl->pViewFrame->GetChildWindow(SfxTemplateDialogWrapper::GetChildWindowId());
+ return pChild ? (SfxTemplateDialog*) pChild->GetWindow() : 0;
+ }
+
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+
+SfxWorkWindow* SfxApplication::GetWorkWindow_Impl(const SfxViewFrame *pFrame) const
+{
+ if ( pFrame )
+ return pFrame->GetFrame().GetWorkWindow_Impl();
+ else if ( pAppData_Impl->pViewFrame )
+ return pAppData_Impl->pViewFrame->GetFrame().GetWorkWindow_Impl();
+ else
+ return NULL;
+}
+
diff --git a/sfx2/source/appl/appdata.cxx b/sfx2/source/appl/appdata.cxx
new file mode 100644
index 000000000000..32b56717293c
--- /dev/null
+++ b/sfx2/source/appl/appdata.cxx
@@ -0,0 +1,187 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <tools/cachestr.hxx>
+#include <tools/config.hxx>
+#ifndef _INETSTRM_HXX //autogen
+#include <svl/inetstrm.hxx>
+#endif
+#include <svl/stritem.hxx>
+
+#define _SVSTDARR_STRINGS
+#include <svl/svstdarr.hxx>
+#include <vos/mutex.hxx>
+
+#include <vcl/menu.hxx>
+#include <vcl/msgbox.hxx>
+#include <svl/dateitem.hxx>
+#include <vcl/menu.hxx>
+#include <vcl/wrkwin.hxx>
+#include "comphelper/processfactory.hxx"
+
+#include <sfx2/viewfrm.hxx>
+#include "appdata.hxx"
+#include <sfx2/dispatch.hxx>
+#include <sfx2/event.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/doctempl.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/docfac.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/request.hxx>
+#include "referers.hxx"
+#include "app.hrc"
+#include "sfx2/sfxresid.hxx"
+#include "objshimp.hxx"
+#include <sfx2/appuno.hxx>
+#include "imestatuswindow.hxx"
+#include "appbaslib.hxx"
+
+#include <basic/basicmanagerrepository.hxx>
+#include <basic/basmgr.hxx>
+
+using ::basic::BasicManagerRepository;
+using ::basic::BasicManagerCreationListener;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::frame::XModel;
+using ::com::sun::star::uno::XInterface;
+
+class SfxBasicManagerCreationListener : public ::basic::BasicManagerCreationListener
+{
+private:
+ SfxAppData_Impl& m_rAppData;
+
+public:
+ SfxBasicManagerCreationListener( SfxAppData_Impl& _rAppData ) :m_rAppData( _rAppData ) { }
+
+ virtual void onBasicManagerCreated( const Reference< XModel >& _rxForDocument, BasicManager& _rBasicManager );
+};
+
+void SfxBasicManagerCreationListener::onBasicManagerCreated( const Reference< XModel >& _rxForDocument, BasicManager& _rBasicManager )
+{
+ if ( _rxForDocument == NULL )
+ m_rAppData.OnApplicationBasicManagerCreated( _rBasicManager );
+}
+
+SfxAppData_Impl::SfxAppData_Impl( SfxApplication* ) :
+ pDdeService( 0 ),
+ pDocTopics( 0 ),
+ pTriggerTopic(0),
+ pDdeService2(0),
+ pFactArr(0),
+ pTopFrames( new SfxFrameArr_Impl ),
+ pInitLinkList(0),
+ pMatcher( 0 ),
+ pLabelResMgr( 0 ),
+ pAppDispatch(NULL),
+ pTemplates( 0 ),
+ pPool(0),
+ pEventConfig(0),
+ pDisabledSlotList( 0 ),
+ pSecureURLs(0),
+ pSaveOptions( 0 ),
+ pUndoOptions( 0 ),
+ pHelpOptions( 0 ),
+ pProgress(0),
+ pTemplateCommon( 0 ),
+ nDocModalMode(0),
+ nAutoTabPageId(0),
+ nBasicCallLevel(0),
+ nRescheduleLocks(0),
+ nInReschedule(0),
+ nAsynchronCalls(0),
+ m_xImeStatusWindow(new sfx2::appl::ImeStatusWindow(comphelper::getProcessServiceFactory()))
+ , pTbxCtrlFac(0)
+ , pStbCtrlFac(0)
+ , pViewFrames(0)
+ , pObjShells(0)
+ , pSfxResManager(0)
+ , pOfaResMgr(0)
+ , pSimpleResManager(0)
+ , pBasicManager( new SfxBasicManagerHolder )
+ , pBasMgrListener( new SfxBasicManagerCreationListener( *this ) )
+ , pViewFrame( 0 )
+ , pSlotPool( 0 )
+ , pResMgr( 0 )
+ , pAppDispat( 0 )
+ , pInterfaces( 0 )
+ , nDocNo(0)
+ , nInterfaces( 0 )
+ , bDowning( sal_True )
+ , bInQuit( sal_False )
+ , bInvalidateOnUnlock( sal_False )
+ , bODFVersionWarningLater( sal_False )
+
+{
+ BasicManagerRepository::registerCreationListener( *pBasMgrListener );
+}
+
+SfxAppData_Impl::~SfxAppData_Impl()
+{
+ DeInitDDE();
+ delete pTopFrames;
+ delete pSecureURLs;
+ delete pBasicManager;
+
+ BasicManagerRepository::revokeCreationListener( *pBasMgrListener );
+ delete pBasMgrListener;
+}
+
+void SfxAppData_Impl::UpdateApplicationSettings( sal_Bool bDontHide )
+{
+ AllSettings aAllSet = Application::GetSettings();
+ StyleSettings aStyleSet = aAllSet.GetStyleSettings();
+ sal_uInt32 nStyleOptions = aStyleSet.GetOptions();
+ if ( bDontHide )
+ nStyleOptions &= ~STYLE_OPTION_HIDEDISABLED;
+ else
+ nStyleOptions |= STYLE_OPTION_HIDEDISABLED;
+ aStyleSet.SetOptions( nStyleOptions );
+ aAllSet.SetStyleSettings( aStyleSet );
+ Application::SetSettings( aAllSet );
+}
+
+SfxDocumentTemplates* SfxAppData_Impl::GetDocumentTemplates()
+{
+ if ( !pTemplates )
+ pTemplates = new SfxDocumentTemplates;
+ else
+ pTemplates->ReInitFromComponent();
+ return pTemplates;
+}
+
+void SfxAppData_Impl::OnApplicationBasicManagerCreated( BasicManager& _rBasicManager )
+{
+ pBasicManager->reset( &_rBasicManager );
+
+ // global constants, additionally to the ones already added by createApplicationBasicManager:
+ // ThisComponent
+ Reference< XInterface > xCurrentComponent = SfxObjectShell::GetCurrentComponent();
+ _rBasicManager.SetGlobalUNOConstant( "ThisComponent", makeAny( xCurrentComponent ) );
+}
diff --git a/sfx2/source/appl/appdde.cxx b/sfx2/source/appl/appdde.cxx
new file mode 100644
index 000000000000..808731f8bba8
--- /dev/null
+++ b/sfx2/source/appl/appdde.cxx
@@ -0,0 +1,710 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <vcl/wrkwin.hxx>
+#include <svl/rectitem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <basic/sbstar.hxx>
+#include <svl/stritem.hxx>
+#include <svl/svdde.hxx>
+#include <sfx2/lnkbase.hxx>
+#include <sfx2/linkmgr.hxx>
+
+#include <tools/urlobj.hxx>
+#include <unotools/pathoptions.hxx>
+#ifndef GCC
+#endif
+
+#include <sfx2/app.hxx>
+#include "appdata.hxx"
+#include <sfx2/objsh.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/dispatch.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/sfxsids.hrc>
+#include "helper.hxx"
+#include <sfx2/docfile.hxx>
+
+//========================================================================
+
+String SfxDdeServiceName_Impl( const String& sIn )
+{
+ ByteString sTemp = U2S( sIn );
+ ByteString sReturn;
+
+ for ( sal_uInt16 n = sTemp.Len(); n; --n )
+ if ( sTemp.Copy( n-1, 1 ).IsAlphaNumericAscii() )
+ sReturn += sTemp.GetChar(n-1);
+
+ return S2U( sReturn );
+}
+
+
+class ImplDdeService : public DdeService
+{
+public:
+ ImplDdeService( const String& rNm )
+ : DdeService( rNm )
+ {}
+ virtual BOOL MakeTopic( const String& );
+
+ virtual String Topics();
+// virtual String Formats();
+// virtual String SysItems();
+// virtual String Status();
+
+ virtual BOOL SysTopicExecute( const String* pStr );
+};
+
+class SfxDdeTriggerTopic_Impl : public DdeTopic
+{
+public:
+ SfxDdeTriggerTopic_Impl()
+ : DdeTopic( DEFINE_CONST_UNICODE("TRIGGER") )
+ {}
+
+ virtual BOOL Execute( const String* );
+};
+
+class SfxDdeDocTopic_Impl : public DdeTopic
+{
+public:
+ SfxObjectShell* pSh;
+ DdeData aData;
+ ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
+
+ SfxDdeDocTopic_Impl( SfxObjectShell* pShell )
+ : DdeTopic( pShell->GetTitle(SFX_TITLE_FULLNAME) ), pSh( pShell )
+ {}
+
+ virtual DdeData* Get( ULONG );
+ virtual BOOL Put( const DdeData* );
+ virtual BOOL Execute( const String* );
+ virtual BOOL StartAdviseLoop();
+ virtual BOOL MakeItem( const String& rItem );
+
+// wird benoetigt?
+// virtual void Connect( long n );
+// virtual void Disconnect( long n );
+// virtual void StopAdviseLoop();
+
+};
+
+
+SV_DECL_PTRARR( SfxDdeDocTopics_Impl, SfxDdeDocTopic_Impl *, 4, 4 )
+SV_IMPL_PTRARR( SfxDdeDocTopics_Impl, SfxDdeDocTopic_Impl *)
+
+//========================================================================
+
+BOOL SfxAppEvent_Impl( ApplicationEvent &rAppEvent,
+ const String &rCmd, const String &rEvent )
+
+/* [Beschreibung]
+
+ Pr"uft, ob 'rCmd' das Event 'rEvent' ist (ohne '(') und baut
+ aus diesem dann ein <ApplicationEvent> zusammen, das per
+ <Application::AppEvent()> ausgef"uhrt werden kann. Ist 'rCmd' das
+ angegegeben Event 'rEvent', dann wird TRUE zur"uckgegeben, sonst FALSE.
+
+
+ [Beispiel]
+
+ rCmd = "Open(\"d:\doc\doc.sdw\")"
+ rEvent = "Open"
+*/
+
+{
+ String aEvent( rEvent );
+ aEvent += '(';
+ if ( rCmd.CompareIgnoreCaseToAscii( aEvent, aEvent.Len() ) == COMPARE_EQUAL )
+ {
+ String aData( rCmd );
+ aData.Erase( 0, aEvent.Len() );
+ if ( aData.Len() > 2 )
+ {
+ // in das ApplicationEvent-Format wandeln
+ aData.Erase( aData.Len()-1, 1 );
+ for ( USHORT n = 0; n < aData.Len(); ++n )
+ {
+ if ( aData.GetChar(n) == 0x0022 ) // " = 22h
+ for ( ; aData.GetChar(++n) != 0x0022 ; )
+ /* empty loop */ ;
+ else if ( aData.GetChar(n) == 0x0020 ) // SPACE = 20h
+ aData.SetChar(n, '\n');
+ }
+ aData.EraseAllChars( 0x0022 );
+ ApplicationAddress aAddr;
+ rAppEvent = ApplicationEvent( String(), aAddr, U2S(rEvent), aData );
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+//-------------------------------------------------------------------------
+
+long SfxApplication::DdeExecute
+(
+ const String& rCmd // in unserer BASIC-Syntax formuliert
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seine SfxApplication-Subklasse gerichtete DDE-Kommandos
+ zu empfangen.
+
+ Die Basisimplementierung versteht die API-Funktionalit"at der
+ betreffenden SfxApplication-Subklasse in BASIC-Syntax. R"uckgabewerte
+ k"onnen dabei leider nicht "ubertragen werden.
+*/
+
+{
+ // Print oder Open-Event?
+ ApplicationEvent aAppEvent;
+ if ( SfxAppEvent_Impl( aAppEvent, rCmd, DEFINE_CONST_UNICODE("Print") ) ||
+ SfxAppEvent_Impl( aAppEvent, rCmd, DEFINE_CONST_UNICODE("Open") ) )
+ GetpApp()->AppEvent( aAppEvent );
+ else
+ {
+ // alle anderen per BASIC
+ EnterBasicCall();
+ StarBASIC* pBasic = GetBasic();
+ DBG_ASSERT( pBasic, "Wo ist mein Basic???" );
+ SbxVariable* pRet = pBasic->Execute( rCmd );
+ LeaveBasicCall();
+ if( !pRet )
+ {
+ SbxBase::ResetError();
+ return 0;
+ }
+ }
+ return 1;
+}
+
+//--------------------------------------------------------------------
+
+long SfxApplication::DdeGetData
+(
+ const String&, // das anzusprechende Item
+ const String&, // in: Format
+ ::com::sun::star::uno::Any& // out: angeforderte Daten
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seine SfxApplication-Subklasse gerichtete DDE-Daten-Anforderungen
+ zu empfangen.
+
+ Die Basisimplementierung liefert keine Daten und gibt 0 zur"uck.
+*/
+
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+long SfxApplication::DdeSetData
+(
+ const String&, // das anzusprechende Item
+ const String&, // in: Format
+ const ::com::sun::star::uno::Any& // out: angeforderte Daten
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seine SfxApplication-Subklasse gerichtete DDE-Daten
+ zu empfangen.
+
+ Die Basisimplementierung nimmt keine Daten entgegen und liefert 0 zur"uck.
+*/
+
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+::sfx2::SvLinkSource* SfxApplication::DdeCreateLinkSource
+(
+ const String& // das zu erzeugende Item
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seiner SfxApplication-Subklasse einen DDE-Hotlink einzurichten
+
+ Die Basisimplementierung erzeugt keinen und liefert 0 zur"uck.
+*/
+
+{
+ return 0;
+}
+
+//========================================================================
+
+long SfxObjectShell::DdeExecute
+(
+ const String& rCmd // in unserer BASIC-Syntax formuliert
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seine SfxObjectShell-Subklasse gerichtete DDE-Kommandos
+ zu empfangen.
+
+ Die Basisimplementierung f"uhrt nichts aus und liefert 0 zur"uck.
+*/
+
+{
+ StarBASIC* pBasic = GetBasic();
+ DBG_ASSERT( pBasic, "Wo ist mein Basic???" ) ;
+ SbxVariable* pRet = pBasic->Execute( rCmd );
+ if( !pRet )
+ {
+ SbxBase::ResetError();
+ return 0;
+ }
+
+ return 1;
+}
+
+//--------------------------------------------------------------------
+
+long SfxObjectShell::DdeGetData
+(
+ const String&, // das anzusprechende Item
+ const String&, // in: Format
+ ::com::sun::star::uno::Any& // out: angeforderte Daten
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seine SfxObjectShell-Subklasse gerichtete DDE-Daten-Anforderungen
+ zu empfangen.
+
+ Die Basisimplementierung liefert keine Daten und gibt 0 zur"uck.
+*/
+
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+long SfxObjectShell::DdeSetData
+(
+ const String&, // das anzusprechende Item
+ const String&, // in: Format
+ const ::com::sun::star::uno::Any& // out: angeforderte Daten
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seine SfxObjectShell-Subklasse gerichtete DDE-Daten
+ zu empfangen.
+
+ Die Basisimplementierung nimmt keine Daten entgegen und liefert 0 zur"uck.
+*/
+
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+::sfx2::SvLinkSource* SfxObjectShell::DdeCreateLinkSource
+(
+ const String& // das zu erzeugende Item
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seiner SfxObjectShell-Subklasse einen DDE-Hotlink einzurichten
+
+ Die Basisimplementierung erzeugt keinen und liefert 0 zur"uck.
+*/
+
+{
+ return 0;
+}
+
+//========================================================================
+
+long SfxViewFrame::DdeExecute
+(
+ const String& rCmd // in unserer BASIC-Syntax formuliert
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seine SfxViewFrame-Subklasse gerichtete DDE-Kommandos
+ zu empfangen.
+
+ Die Basisimplementierung versteht die API-Funktionalit"at des
+ betreffenden SfxViewFrame, der darin dargestellten SfxViewShell und
+ der betreffenden SfxObjectShell-Subklasse in BASIC-Syntax.
+ R"uckgabewerte k"onnen dabei leider nicht "ubertragen werden.
+*/
+
+{
+ if ( GetObjectShell() )
+ return GetObjectShell()->DdeExecute( rCmd );
+
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+long SfxViewFrame::DdeGetData
+(
+ const String&, // das anzusprechende Item
+ const String&, // in: Format
+ ::com::sun::star::uno::Any& // out: angeforderte Daten
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seine SfxViewFrame-Subklasse gerichtete DDE-Daten-Anforderungen
+ zu empfangen.
+
+ Die Basisimplementierung liefert keine Daten und gibt 0 zur"uck.
+*/
+
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+long SfxViewFrame::DdeSetData
+(
+ const String& , // das anzusprechende Item
+ const String& , // in: Format
+ const ::com::sun::star::uno::Any& // out: angeforderte Daten
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seine SfxViewFrame-Subklasse gerichtete DDE-Daten
+ zu empfangen.
+
+ Die Basisimplementierung nimmt keine Daten entgegen und liefert 0 zur"uck.
+*/
+
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+::sfx2::SvLinkSource* SfxViewFrame::DdeCreateLinkSource
+(
+ const String& // das zu erzeugende Item
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann vom Applikationsentwickler "uberladen werden,
+ um an seiner SfxViewFrame-Subklasse einen DDE-Hotlink einzurichten
+
+ Die Basisimplementierung erzeugt keinen und liefert 0 zur"uck.
+*/
+
+{
+ return 0;
+}
+
+//========================================================================
+
+BOOL SfxApplication::InitializeDde()
+{
+ DBG_ASSERT( !pAppData_Impl->pDdeService,
+ "Dde kann nicht mehrfach initialisiert werden" );
+
+ pAppData_Impl->pDdeService = new ImplDdeService( Application::GetAppName() );
+ int nError = pAppData_Impl->pDdeService->GetError();
+ if( !nError )
+ {
+ pAppData_Impl->pDocTopics = new SfxDdeDocTopics_Impl;
+
+ // wir wollen auf jedenfall RTF unterstuetzen!
+ pAppData_Impl->pDdeService->AddFormat( FORMAT_RTF );
+
+ // Config-Pfad als Topic wegen Mehrfachstart
+ INetURLObject aOfficeLockFile( SvtPathOptions().GetUserConfigPath() );
+ aOfficeLockFile.insertName( DEFINE_CONST_UNICODE( "soffice.lck" ) );
+ String aService( SfxDdeServiceName_Impl(
+ aOfficeLockFile.GetMainURL(INetURLObject::DECODE_TO_IURI) ) );
+ aService.ToUpperAscii();
+ pAppData_Impl->pDdeService2 = new ImplDdeService( aService );
+ pAppData_Impl->pTriggerTopic = new SfxDdeTriggerTopic_Impl;
+ pAppData_Impl->pDdeService2->AddTopic( *pAppData_Impl->pTriggerTopic );
+ }
+ return !nError;
+}
+
+void SfxAppData_Impl::DeInitDDE()
+{
+ DELETEZ( pTriggerTopic );
+ DELETEZ( pDdeService2 );
+ DELETEZ( pDocTopics );
+ DELETEZ( pDdeService );
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::AddDdeTopic( SfxObjectShell* pSh )
+{
+ DBG_ASSERT( pAppData_Impl->pDocTopics, "es gibt gar keinen Dde-Service" );
+ //OV: Im Serverbetrieb ist DDE abgeklemmt!
+ if( !pAppData_Impl->pDocTopics )
+ return;
+
+ // doppeltes Eintragen verhindern
+ String sShellNm;
+ BOOL bFnd = FALSE;
+ for( USHORT n = pAppData_Impl->pDocTopics->Count(); n; )
+ if( (*pAppData_Impl->pDocTopics)[ --n ]->pSh == pSh )
+ {
+ // JP 18.03.96 - Bug 26470
+ // falls das Document unbenannt wurde, ist trotzdem ein
+ // neues Topics anzulegen!
+ if( !bFnd )
+ {
+ bFnd = TRUE;
+ (sShellNm = pSh->GetTitle(SFX_TITLE_FULLNAME)).ToLowerAscii();
+ }
+ String sNm( (*pAppData_Impl->pDocTopics)[ n ]->GetName() );
+ if( sShellNm == sNm.ToLowerAscii() )
+ return ;
+ }
+
+ const SfxDdeDocTopic_Impl* pTopic = new SfxDdeDocTopic_Impl( pSh );
+ pAppData_Impl->pDocTopics->Insert( pTopic,
+ pAppData_Impl->pDocTopics->Count() );
+ pAppData_Impl->pDdeService->AddTopic( *pTopic );
+}
+
+void SfxApplication::RemoveDdeTopic( SfxObjectShell* pSh )
+{
+ DBG_ASSERT( pAppData_Impl->pDocTopics, "es gibt gar keinen Dde-Service" );
+ //OV: Im Serverbetrieb ist DDE abgeklemmt!
+ if( !pAppData_Impl->pDocTopics )
+ return;
+
+ SfxDdeDocTopic_Impl* pTopic;
+ for( USHORT n = pAppData_Impl->pDocTopics->Count(); n; )
+ if( ( pTopic = (*pAppData_Impl->pDocTopics)[ --n ])->pSh == pSh )
+ {
+ pAppData_Impl->pDdeService->RemoveTopic( *pTopic );
+ pAppData_Impl->pDocTopics->DeleteAndDestroy( n );
+ }
+}
+
+const DdeService* SfxApplication::GetDdeService() const
+{
+ return pAppData_Impl->pDdeService;
+}
+
+DdeService* SfxApplication::GetDdeService()
+{
+ return pAppData_Impl->pDdeService;
+}
+
+//--------------------------------------------------------------------
+
+BOOL ImplDdeService::MakeTopic( const String& rNm )
+{
+ // Workaround gegen Event nach unserem Main() unter OS/2
+ // passierte wenn man beim Beenden aus dem OffMgr die App neu startet
+ if ( !Application::IsInExecute() )
+ return FALSE;
+
+ // das Topic rNm wird gesucht, haben wir es ?
+ // erstmal nur ueber die ObjectShells laufen und die mit dem
+ // Namen heraussuchen:
+ BOOL bRet = FALSE;
+ String sNm( rNm );
+ sNm.ToLowerAscii();
+ TypeId aType( TYPE(SfxObjectShell) );
+ SfxObjectShell* pShell = SfxObjectShell::GetFirst( &aType );
+ while( pShell )
+ {
+ String sTmp( pShell->GetTitle(SFX_TITLE_FULLNAME) );
+ sTmp.ToLowerAscii();
+ if( sTmp == sNm ) // die wollen wir haben
+ {
+ SFX_APP()->AddDdeTopic( pShell );
+ bRet = TRUE;
+ break;
+ }
+ pShell = SfxObjectShell::GetNext( *pShell, &aType );
+ }
+
+ if( !bRet )
+ {
+ INetURLObject aWorkPath( SvtPathOptions().GetWorkPath() );
+ INetURLObject aFile;
+ if ( aWorkPath.GetNewAbsURL( rNm, &aFile ) &&
+ SfxContentHelper::IsDocument( aFile.GetMainURL( INetURLObject::NO_DECODE ) ) )
+ {
+ // File vorhanden
+
+ // dann versuche die Datei zu laden:
+ SfxStringItem aName( SID_FILE_NAME, aFile.GetMainURL( INetURLObject::NO_DECODE ) );
+ SfxBoolItem aNewView(SID_OPEN_NEW_VIEW, TRUE);
+
+ SfxBoolItem aSilent(SID_SILENT, TRUE);
+ SfxDispatcher* pDispatcher = SFX_APP()->GetDispatcher_Impl();
+ const SfxPoolItem* pRet = pDispatcher->Execute( SID_OPENDOC,
+ SFX_CALLMODE_SYNCHRON,
+ &aName, &aNewView,
+ &aSilent, 0L );
+
+ if( pRet && pRet->ISA( SfxViewFrameItem ) &&
+ ((SfxViewFrameItem*)pRet)->GetFrame() &&
+ 0 != ( pShell = ((SfxViewFrameItem*)pRet)
+ ->GetFrame()->GetObjectShell() ) )
+ {
+ SFX_APP()->AddDdeTopic( pShell );
+ bRet = TRUE;
+ }
+ }
+ }
+ return bRet;
+}
+
+String ImplDdeService::Topics()
+{
+ String sRet;
+ if( GetSysTopic() )
+ sRet += GetSysTopic()->GetName();
+
+ TypeId aType( TYPE(SfxObjectShell) );
+ SfxObjectShell* pShell = SfxObjectShell::GetFirst( &aType );
+ while( pShell )
+ {
+ if( SfxViewFrame::GetFirst( pShell ) )
+ {
+ if( sRet.Len() )
+ sRet += '\t';
+ sRet += pShell->GetTitle(SFX_TITLE_FULLNAME);
+ }
+ pShell = SfxObjectShell::GetNext( *pShell, &aType );
+ }
+ if( sRet.Len() )
+ sRet += DEFINE_CONST_UNICODE("\r\n");
+ return sRet;
+}
+
+BOOL ImplDdeService::SysTopicExecute( const String* pStr )
+{
+ return (BOOL)SFX_APP()->DdeExecute( *pStr );
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxDdeTriggerTopic_Impl::Execute( const String* )
+{
+ return TRUE;
+}
+
+//--------------------------------------------------------------------
+DdeData* SfxDdeDocTopic_Impl::Get( ULONG nFormat )
+{
+ String sMimeType( SotExchange::GetFormatMimeType( nFormat ));
+ ::com::sun::star::uno::Any aValue;
+ long nRet = pSh->DdeGetData( GetCurItem(), sMimeType, aValue );
+ if( nRet && aValue.hasValue() && ( aValue >>= aSeq ) )
+ {
+ aData = DdeData( aSeq.getConstArray(), aSeq.getLength(), nFormat );
+ return &aData;
+ }
+ aSeq.realloc( 0 );
+ return 0;
+}
+
+BOOL SfxDdeDocTopic_Impl::Put( const DdeData* pData )
+{
+ aSeq = ::com::sun::star::uno::Sequence< sal_Int8 >(
+ (sal_Int8*)(const void*)*pData, (long)*pData );
+ BOOL bRet;
+ if( aSeq.getLength() )
+ {
+ ::com::sun::star::uno::Any aValue;
+ aValue <<= aSeq;
+ String sMimeType( SotExchange::GetFormatMimeType( pData->GetFormat() ));
+ bRet = 0 != pSh->DdeSetData( GetCurItem(), sMimeType, aValue );
+ }
+ else
+ bRet = FALSE;
+ return bRet;
+}
+
+BOOL SfxDdeDocTopic_Impl::Execute( const String* pStr )
+{
+ long nRet = pStr ? pSh->DdeExecute( *pStr ) : 0;
+ return 0 != nRet;
+}
+
+BOOL SfxDdeDocTopic_Impl::MakeItem( const String& rItem )
+{
+ AddItem( DdeItem( rItem ) );
+ return TRUE;
+}
+
+BOOL SfxDdeDocTopic_Impl::StartAdviseLoop()
+{
+ BOOL bRet = FALSE;
+ ::sfx2::SvLinkSource* pNewObj = pSh->DdeCreateLinkSource( GetCurItem() );
+ if( pNewObj )
+ {
+ // dann richten wir auch einen entsprechenden SvBaseLink ein
+ String sNm, sTmp( Application::GetAppName() );
+ ::sfx2::MakeLnkName( sNm, &sTmp, pSh->GetTitle(SFX_TITLE_FULLNAME), GetCurItem() );
+ new ::sfx2::SvBaseLink( sNm, OBJECT_DDE_EXTERN, pNewObj );
+ bRet = TRUE;
+ }
+ return bRet;
+}
+
diff --git a/sfx2/source/appl/appinit.cxx b/sfx2/source/appl/appinit.cxx
new file mode 100644
index 000000000000..2aa19901d87c
--- /dev/null
+++ b/sfx2/source/appl/appinit.cxx
@@ -0,0 +1,316 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sfx2/app.hxx>
+#include <com/sun/star/frame/XTerminateListener.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+#include <svtools/soerr.hxx>
+#include <svtools/svtools.hrc>
+#include <unotools/saveopt.hxx>
+#include <unotools/localisationoptions.hxx>
+#include <tools/config.hxx>
+#ifndef _SV_RESARY_HXX
+#include <tools/resary.hxx>
+#endif
+#include <tools/urlobj.hxx>
+#include <svl/intitem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#include <svtools/ehdl.hxx>
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+#include <unotools/configmgr.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <vos/security.hxx>
+#include <ucbhelper/configurationkeys.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/historyoptions.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <cppuhelper/implbase2.hxx>
+
+#include <rtl/logfile.hxx>
+#include <vcl/edit.hxx>
+
+#include <sfx2/unoctitm.hxx>
+#include "app.hrc"
+#include "sfxlocal.hrc"
+#include "appdata.hxx"
+#include "arrdecl.hxx"
+#include <sfx2/dispatch.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/evntconf.hxx>
+#include "intro.hxx"
+#include <sfx2/macrconf.hxx>
+#include <sfx2/mnumgr.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/progress.hxx>
+#include "sfx2/sfxhelp.hxx"
+#include "sfx2/sfxresid.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/viewsh.hxx>
+#include "nochaos.hxx"
+#include <sfx2/fcontnr.hxx>
+#include "helper.hxx" // SfxContentHelper::Kill()
+#include "sfxpicklist.hxx"
+#include <tools/svlibrary.hxx>
+
+#ifdef UNX
+#define stricmp(a,b) strcmp(a,b)
+#endif
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star;
+namespace css = ::com::sun::star;
+
+class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper2< XTerminateListener, XServiceInfo >
+{
+public:
+
+ // XTerminateListener
+ virtual void SAL_CALL queryTermination( const EventObject& aEvent ) throw( TerminationVetoException, RuntimeException );
+ virtual void SAL_CALL notifyTermination( const EventObject& aEvent ) throw( RuntimeException );
+ virtual void SAL_CALL disposing( const EventObject& Source ) throw( RuntimeException );
+
+ // XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName() throw (RuntimeException);
+ virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
+};
+
+void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
+{
+}
+
+void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& ) throw(TerminationVetoException, RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( !SFX_APP()->QueryExit_Impl() )
+ throw TerminationVetoException();
+}
+
+void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent ) throw(RuntimeException )
+{
+ static ::rtl::OUString SERVICE_GLOBALEVENTBROADCASTER = ::rtl::OUString::createFromAscii("com.sun.star.frame.GlobalEventBroadcaster");
+ static ::rtl::OUString EVENT_QUIT_APP = ::rtl::OUString::createFromAscii("OnCloseApp");
+
+ Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY );
+ if( xDesktop.is() == sal_True )
+ xDesktop->removeTerminateListener( this );
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ utl::ConfigManager::GetConfigManager()->StoreConfigItems();
+ SfxApplication* pApp = SFX_APP();
+ pApp->Broadcast( SfxSimpleHint( SFX_HINT_DEINITIALIZING ) );
+ pApp->Get_Impl()->pAppDispatch->ReleaseAll();
+ pApp->Get_Impl()->pAppDispatch->release();
+
+ css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
+ css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(xSMGR->createInstance(SERVICE_GLOBALEVENTBROADCASTER), css::uno::UNO_QUERY);
+ if (xGlobalBroadcaster.is())
+ {
+ css::document::EventObject aEvent2;
+ aEvent2.EventName = EVENT_QUIT_APP;
+ xGlobalBroadcaster->notifyEvent(aEvent2);
+ }
+
+ //pApp->Deinitialize();
+ delete pApp;
+ Application::Quit();
+}
+
+::rtl::OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException)
+{
+ static const ::rtl::OUString IMPLNAME = ::rtl::OUString::createFromAscii("com.sun.star.comp.sfx2.SfxTerminateListener");
+ return IMPLNAME;
+}
+
+::sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException)
+{
+ Sequence< ::rtl::OUString > lNames = getSupportedServiceNames();
+ ::sal_Int32 c = lNames.getLength();
+ ::sal_Int32 i = 0;
+
+ for (i=0; i<c; ++i)
+ {
+ if (lNames[i].equals(sServiceName))
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+Sequence< ::rtl::OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException)
+{
+ // Note: That service does not realy exists .-)
+ // But this implementation is not thought to be registered realy within our service.rdb.
+ // At least we need the implementation name only to identify these service at the global desktop instance.
+ // The desktop must know, which listener will terminate the SfxApplication in real !
+ // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
+ // can react ...
+ static const ::rtl::OUString SERVICENAME = ::rtl::OUString::createFromAscii("com.sun.star.frame.TerminateListener");
+ Sequence< ::rtl::OUString > lNames(1);
+ lNames[0] = SERVICENAME;
+ return lNames;
+}
+
+//====================================================================
+
+#define DOSTRING( x ) #x
+#define STRING( x ) DOSTRING( x )
+
+typedef bool ( *PFunc_getSpecialCharsForEdit)( Window* i_pParent, const Font& i_rFont, String& o_rOutString );
+
+//====================================================================
+// Lazy binding of the GetSpecialCharsForEdit function as it resides in
+// a library above us.
+//====================================================================
+
+extern "C" { static void SAL_CALL thisModule() {} }
+
+String GetSpecialCharsForEdit(Window* pParent, const Font& rFont)
+{
+ static bool bDetermineFunction = false;
+ static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = 0;
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( !bDetermineFunction )
+ {
+ bDetermineFunction = true;
+
+ static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "cui" ) ) );
+ oslModule handleMod = osl_loadModuleRelative(
+ &thisModule, aLibName.pData, 0 );
+
+ // get symbol
+ ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "GetSpecialCharsForEdit" ) );
+ pfunc_getSpecialCharsForEdit = (PFunc_getSpecialCharsForEdit)osl_getFunctionSymbol( handleMod, aSymbol.pData );
+ DBG_ASSERT( pfunc_getSpecialCharsForEdit, "GetSpecialCharsForEdit() not found!" );
+ }
+
+ String aRet;
+ if ( pfunc_getSpecialCharsForEdit )
+ (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
+ return aRet;
+}
+
+//====================================================================
+
+FASTBOOL SfxApplication::Initialize_Impl()
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::Initialize_Impl" );
+
+#ifdef TLX_VALIDATE
+ StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) );
+#endif
+
+ Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
+ if (!xDesktop.is())
+ throw RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Couldn't create mandatory desktop service!" )), xDesktop );
+ xDesktop->addTerminateListener( new SfxTerminateListener_Impl() );
+
+ Application::EnableAutoHelpId();
+
+ pAppData_Impl->pAppDispatch = new SfxStatusDispatcher;
+ pAppData_Impl->pAppDispatch->acquire();
+
+ // SV-Look
+ Help::EnableContextHelp();
+ Help::EnableExtHelp();
+
+ SvtLocalisationOptions aLocalisation;
+ Application::EnableAutoMnemonic ( aLocalisation.IsAutoMnemonic() );
+ Application::SetDialogScaleX ( (short)(aLocalisation.GetDialogScale()) );
+
+
+#ifdef DBG_UTIL
+ // Der SimplerErrorHandler dient Debugzwecken. In der Product werden
+ // nichtgehandelte Fehler durch Errorcode 1 an SFX gegeben.
+ new SimpleErrorHandler;
+#endif
+ new SfxErrorHandler(RID_ERRHDL, ERRCODE_AREA_TOOLS, ERRCODE_AREA_LIB1);
+
+ new SfxErrorHandler(
+ RID_SO_ERROR_HANDLER, ERRCODE_AREA_SO, ERRCODE_AREA_SO_END);
+ new SfxErrorHandler(
+ RID_BASIC_START, ERRCODE_AREA_SBX, ERRCODE_AREA_SBX_END );
+
+ // diverse Pointer
+ SfxPickList::GetOrCreate( SvtHistoryOptions().GetSize( ePICKLIST ) );
+
+ /////////////////////////////////////////////////////////////////
+
+ DBG_ASSERT( !pAppData_Impl->pAppDispat, "AppDispatcher already exists" );
+ pAppData_Impl->pAppDispat = new SfxDispatcher((SfxDispatcher*)0);
+ pAppData_Impl->pSlotPool = new SfxSlotPool;
+ pAppData_Impl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
+ pAppData_Impl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
+ pAppData_Impl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
+ pAppData_Impl->pViewFrames = new SfxViewFrameArr_Impl;
+ pAppData_Impl->pViewShells = new SfxViewShellArr_Impl;
+ pAppData_Impl->pObjShells = new SfxObjectShellArr_Impl;
+ pAppData_Impl->nInterfaces = SFX_INTERFACE_APP+8;
+ pAppData_Impl->pInterfaces = new SfxInterface*[pAppData_Impl->nInterfaces];
+ memset( pAppData_Impl->pInterfaces, 0, sizeof(SfxInterface*) * pAppData_Impl->nInterfaces );
+
+ Registrations_Impl();
+
+ // Subklasse initialisieren
+ pAppData_Impl->bDowning = sal_False;
+ Init();
+
+ // get CHAOS item pool...
+ pAppData_Impl->pPool = NoChaos::GetItemPool();
+ SetPool( pAppData_Impl->pPool );
+
+ if ( pAppData_Impl->bDowning )
+ return sal_False;
+
+ // App-Dispatcher aufbauen
+ pAppData_Impl->pAppDispat->Push(*this);
+ pAppData_Impl->pAppDispat->Flush();
+ pAppData_Impl->pAppDispat->DoActivate_Impl( sal_True, NULL );
+
+ {
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ // Set special characters callback on vcl edit control
+ Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit);
+ }
+
+ return sal_True;
+}
diff --git a/sfx2/source/appl/appmain.cxx b/sfx2/source/appl/appmain.cxx
new file mode 100644
index 000000000000..1bde50fec224
--- /dev/null
+++ b/sfx2/source/appl/appmain.cxx
@@ -0,0 +1,192 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+//#define TF_NEWDESKTOP
+
+#define _SDINTERN_HXX
+
+#include <stdio.h>
+#include <tools/urlobj.hxx>
+#include <tools/config.hxx>
+#include <svtools/ehdl.hxx>
+#include <unotools/startoptions.hxx>
+#include <svl/itempool.hxx>
+#include <svl/urihelper.hxx>
+#include <svtools/helpopt.hxx>
+#include <vos/process.hxx>
+#include <framework/sfxhelperfunctions.hxx>
+#include <rtl/ustring.hxx>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/uno/RuntimeException.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include "sfxtypes.hxx"
+#include "appdata.hxx"
+#include <sfx2/docfac.hxx>
+#include <sfx2/app.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/dispatch.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/fcontnr.hxx>
+#include <sfx2/viewsh.hxx>
+#include "intro.hxx"
+#include <sfx2/msgpool.hxx>
+#include <sfx2/mnumgr.hxx>
+#include <sfx2/appuno.hxx>
+#include "app.hrc"
+#include <sfx2/docfile.hxx>
+#include "workwin.hxx"
+
+#ifdef UNX
+#define stricmp(a,b) strcmp(a,b)
+#endif
+
+
+//===================================================================
+
+DBG_NAME(SfxAppMainNewMenu)
+DBG_NAME(SfxAppMainBmkMenu)
+DBG_NAME(SfxAppMainWizMenu)
+DBG_NAME(SfxAppMainOLEReg)
+DBG_NAME(SfxAppMainCHAOSReg)
+
+//===================================================================
+
+#define SFX_TEMPNAMEBASE_DIR "soffice.tmp"
+#define SFX_KEY_TEMPNAMEBASE "Temp-Dir"
+
+//===================================================================
+
+#ifdef TF_POOLABLE
+static SfxItemInfo __READONLY_DATA aItemInfos[] =
+{
+ { 0, 0 }
+};
+#endif
+
+//===================================================================
+
+TYPEINIT2(SfxApplication,SfxShell,SfxBroadcaster);
+
+//--------------------------------------------------------------------
+void SfxApplication::Init
+(
+)
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode wird vom SFx aus Application:a:Main() gerufen,
+ bevor Execute() ausgef"uhrt wird und
+ - das Intro bereits angezeigt ist,
+ - das Applikationsfenster exisitiert, aber noch hidden ist,
+ - die Bindings bereits existieren (Controller sind anmeldbar),
+ - der Ini- und Config-Manager bereits existiert,
+ - die Standard-Controller bereits exisitieren,
+ - die SFx-Shells ihre Interfaces bereits registriert haben.
+
+ [Querverweise]
+ <SfxApplication::Exit()>
+ <SfxApplication::OpenClients()>
+*/
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::Exit()
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode wird vom SFx aus Application::Main() gerufen,
+ nachdem Execute() beendet ist und
+ - die Konfiguration (SfxConfigManager) bereits gespeichert wurde,
+ - die Fensterpostionen etc. in den SfxIniManager geschrieben wurden,
+ - das Applikationsfenster noch existiert, aber hidden ist
+ - s"amtliche Dokumente und deren Views bereits geschlossen sind.
+ - Dispatcher, Bindings etc. bereits zerst"ort sind
+
+ [Querverweise]
+ <SfxApplication::Init(int,char*[])>
+*/
+
+{
+}
+
+//---------------------------------------------------------------------------
+
+void SfxApplication::PreInit( )
+{
+}
+
+//---------------------------------------------------------------------------
+bool SfxApplication::InitLabelResMgr( const char* _pLabelPrefix, bool _bException )
+{
+ bool bRet = false;
+ // Label-DLL mit diversen Resourcen fuer OEM-Ver. etc. (Intro, Titel, About)
+ DBG_ASSERT( _pLabelPrefix, "Wrong initialisation!" );
+ if ( _pLabelPrefix )
+ {
+ // versuchen, die Label-DLL zu erzeugen
+ pAppData_Impl->pLabelResMgr = CreateResManager( _pLabelPrefix );
+
+ // keine separate Label-DLL vorhanden?
+ if ( !pAppData_Impl->pLabelResMgr )
+ {
+ if ( _bException )
+ {
+ // maybe corrupted installation
+ throw (::com::sun::star::uno::RuntimeException(
+ ::rtl::OUString::createFromAscii("iso resource could not be loaded by SfxApplication"),
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >()));
+ }
+ }
+ else
+ bRet = true;
+ }
+
+ return bRet;
+}
+
+void SfxApplication::Main( )
+{
+}
+
+//-------------------------------------------------------------------------
+
+SfxFilterMatcher& SfxApplication::GetFilterMatcher()
+{
+ if( !pAppData_Impl->pMatcher )
+ {
+ pAppData_Impl->pMatcher = new SfxFilterMatcher();
+ URIHelper::SetMaybeFileHdl( STATIC_LINK(
+ pAppData_Impl->pMatcher, SfxFilterMatcher, MaybeFileHdl_Impl ) );
+ }
+ return *pAppData_Impl->pMatcher;
+}
diff --git a/sfx2/source/appl/appmisc.cxx b/sfx2/source/appl/appmisc.cxx
new file mode 100644
index 000000000000..94b921f8122e
--- /dev/null
+++ b/sfx2/source/appl/appmisc.cxx
@@ -0,0 +1,335 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <vcl/status.hxx>
+#include <vcl/msgbox.hxx>
+#ifndef _VOS_PROCESS_HXX //autogen
+#include <vos/process.hxx>
+#endif
+#include <vos/xception.hxx>
+#include <svl/whiter.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/eitem.hxx>
+#include <svtools/filter.hxx>
+#include <unotools/internaloptions.hxx>
+#include <unotools/pathoptions.hxx>
+#include <com/sun/star/registry/InvalidRegistryException.hpp>
+#ifndef _COM_SUN_STAR_BEANS_PropertyValue_HPP_
+#include <com/sun/star/beans/PropertyValue.hpp>
+#endif
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <com/sun/star/uno/Reference.h>
+#include <tools/config.hxx>
+#include <tools/rcid.h>
+#include <vos/mutex.hxx>
+#ifndef GCC
+#endif
+#include <unotools/configmgr.hxx>
+#include <com/sun/star/frame/XDesktop.hpp>
+
+#include <unotools/ucbstreamhelper.hxx>
+#include <framework/menuconfiguration.hxx>
+#include <comphelper/processfactory.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <unotools/bootstrap.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <osl/file.hxx>
+
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/app.hxx>
+#include "appdata.hxx"
+#include "arrdecl.hxx"
+#include <sfx2/tbxctrl.hxx>
+#include "sfx2/stbitem.hxx"
+#include <sfx2/mnuitem.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include "workwin.hxx"
+#include "intro.hxx"
+#include <sfx2/fcontnr.hxx>
+#include "sfxlocal.hrc"
+#include <sfx2/sfx.hrc>
+#include "app.hrc"
+#include <sfx2/templdlg.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "openflag.hxx"
+#include <sfx2/viewsh.hxx>
+#include <sfx2/objface.hxx>
+#include "helper.hxx" // SfxContentHelper::Kill()
+
+using namespace ::vos;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::container;
+
+//===================================================================
+
+SV_IMPL_PTRARR( SfxTbxCtrlFactArr_Impl, SfxTbxCtrlFactory* );
+SV_IMPL_PTRARR( SfxStbCtrlFactArr_Impl, SfxStbCtrlFactory* );
+SV_IMPL_PTRARR( SfxMenuCtrlFactArr_Impl, SfxMenuCtrlFactory* );
+SV_IMPL_PTRARR( SfxChildWinFactArr_Impl, SfxChildWinFactory* );
+SV_IMPL_PTRARR( SfxModuleArr_Impl, SfxModule* );
+
+//===================================================================
+
+#define SfxApplication
+#include "sfxslots.hxx"
+
+class SfxSpecialConfigError_Impl
+{
+ String aError;
+
+public:
+
+ SfxSpecialConfigError_Impl( const String& rStr );
+ DECL_LINK( TimerHdl, Timer*);
+};
+
+
+SfxSpecialConfigError_Impl::SfxSpecialConfigError_Impl( const String& rStr ) :
+ aError( rStr )
+{
+ Timer *pTimer = new Timer;
+ pTimer->SetTimeoutHdl( LINK(this, SfxSpecialConfigError_Impl, TimerHdl) );
+ pTimer->SetTimeout( 0 );
+ pTimer->Start();
+}
+
+IMPL_LINK( SfxSpecialConfigError_Impl, TimerHdl, Timer*, pTimer )
+{
+ delete pTimer;
+ ErrorBox( 0, WinBits( WB_OK ) , aError ).Execute();
+ delete this;
+ SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_QUITAPP );
+ return 0L;
+}
+
+//====================================================================
+
+#define SFX_ITEMTYPE_STATBAR 4
+
+SFX_IMPL_INTERFACE(SfxApplication,SfxShell,SfxResId(RID_DESKTOP))
+{
+ SFX_STATUSBAR_REGISTRATION(SfxResId(SFX_ITEMTYPE_STATBAR));
+ SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_0);
+ SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_1);
+ SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_2);
+ SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_3);
+ SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_4);
+ SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_5);
+ SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_6);
+ SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_7);
+ SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_8);
+ SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_9);
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::InitializeDisplayName_Impl()
+{
+ SfxAppData_Impl* pAppData = Get_Impl();
+ if ( !pAppData->pLabelResMgr )
+ return;
+
+ String aTitle = Application::GetDisplayName();
+ if ( !aTitle.Len() )
+ {
+ OClearableGuard aGuard( OMutex::getGlobalMutex() );
+
+ // create version string
+/*!!! (pb) don't show a version number at the moment
+ USHORT nProductVersion = ProductVersion::GetVersion().ToInt32();
+ String aVersion( String::CreateFromInt32( nProductVersion / 10 ) );
+ aVersion += 0x002E ; // 2Eh ^= '.'
+ aVersion += ( String::CreateFromInt32( nProductVersion % 10 ) );
+*/
+ // load application title
+ aTitle = String( ResId( RID_APPTITLE, *pAppData->pLabelResMgr ) );
+ // merge version into title
+ aTitle.SearchAndReplaceAscii( "$(VER)", String() /*aVersion*/ );
+
+ aGuard.clear();
+
+#ifdef DBG_UTIL
+ ::rtl::OUString aDefault;
+ aTitle += DEFINE_CONST_UNICODE(" [");
+
+ String aVerId( utl::Bootstrap::getBuildIdData( aDefault ));
+ aTitle += aVerId;
+ aTitle += ']';
+#endif
+ Application::SetDisplayName( aTitle );
+ }
+}
+
+//--------------------------------------------------------------------
+SfxProgress* SfxApplication::GetProgress() const
+
+/* [Beschreibung]
+
+ Liefert den f"ur die gesamte Applikation laufenden SfxProgress
+ oder 0, falls keiner f"ur die gesamte Applikation l"auft.
+
+
+ [Querverweise]
+
+ <SfxProgress::GetActiveProgress(SfxViewFrame*)>
+ <SfxViewFrame::GetProgress()const>
+*/
+
+{
+ return pAppData_Impl->pProgress;
+}
+
+//------------------------------------------------------------------------
+
+SvUShorts* SfxApplication::GetDisabledSlotList_Impl()
+{
+ sal_Bool bError = sal_False;
+ SvUShorts* pList = pAppData_Impl->pDisabledSlotList;
+ if ( !pList )
+ {
+ // Gibt es eine Slotdatei ?
+ INetURLObject aUserObj( SvtPathOptions().GetUserConfigPath() );
+ aUserObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) );
+ SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aUserObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
+ if ( !pStream || pStream->GetError() == ERRCODE_IO_NOTEXISTS )
+ {
+ delete pStream;
+ INetURLObject aObj( SvtPathOptions().GetConfigPath() );
+ aObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) );
+ pStream = ::utl::UcbStreamHelper::CreateStream( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
+ }
+
+ BOOL bSlotsEnabled = SvtInternalOptions().SlotCFGEnabled();
+ BOOL bSlots = ( pStream && !pStream->GetError() );
+ if( bSlots && bSlotsEnabled )
+ {
+ // SlotDatei einlesen
+ String aTitle;
+ pStream->ReadByteString(aTitle);
+ if ( aTitle.CompareToAscii("SfxSlotFile" ) == COMPARE_EQUAL )
+ {
+ sal_uInt16 nCount;
+ (*pStream) >> nCount;
+ pList = pAppData_Impl->pDisabledSlotList =
+ new SvUShorts( nCount < 255 ? (sal_Int8) nCount : 255, 255 );
+
+ sal_uInt16 nSlot;
+ for ( sal_uInt16 n=0; n<nCount; n++ )
+ {
+ (*pStream) >> nSlot;
+ pList->Insert( nSlot, n );
+ }
+
+ pStream->ReadByteString(aTitle);
+ if ( aTitle.CompareToAscii("END" ) != COMPARE_EQUAL || pStream->GetError() )
+ {
+ // Lesen schief gegangen
+ DELETEZ( pList );
+ bError = sal_True;
+ }
+ }
+ else
+ {
+ // Streamerkennung fehlgeschlagen
+ bError = sal_True;
+ }
+ }
+ else if ( bSlots != bSlotsEnabled )
+ {
+ // Wenn kein Slotlist-Eintrag, dann darf auch keine SlotDatei
+ // vorhanden sein
+ bError = sal_True;
+ }
+
+ delete pStream;
+ }
+ else if ( pList == (SvUShorts*) -1L )
+ {
+ return NULL;
+ }
+
+ if ( !pList )
+ pAppData_Impl->pDisabledSlotList = (SvUShorts*) -1L;
+
+ if ( bError )
+ {
+ // Wenn ein Sloteintrag vorhanden ist, aber keine oder eine fehlerhafte
+ // SlotDatei, oder aber eine Slotdatei, aber kein Sloteintrag, dann
+ // gilt dies als fehlerhafte Konfiguration
+ new SfxSpecialConfigError_Impl( String( SfxResId( RID_SPECIALCONFIG_ERROR ) ) );
+ }
+
+ return pList;
+}
+
+
+SfxModule* SfxApplication::GetModule_Impl()
+{
+ SfxModule* pModule = SfxModule::GetActiveModule();
+ if ( !pModule )
+ pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( FALSE ) );
+ if( pModule )
+ return pModule;
+ else
+ {
+ DBG_ERROR( "No module!" );
+ return NULL;
+ }
+}
+
+ISfxTemplateCommon* SfxApplication::GetCurrentTemplateCommon( SfxBindings& rBindings )
+{
+ if( pAppData_Impl->pTemplateCommon )
+ return pAppData_Impl->pTemplateCommon;
+ SfxChildWindow *pChild = rBindings.GetWorkWindow_Impl()->GetChildWindow_Impl(
+ SfxTemplateDialogWrapper::GetChildWindowId() );
+ if ( pChild )
+ return ((SfxTemplateDialog*) pChild->GetWindow())->GetISfxTemplateCommon();
+ return 0;
+}
+
+SfxResourceManager& SfxApplication::GetResourceManager() const { return *pAppData_Impl->pResMgr; }
+BOOL SfxApplication::IsDowning() const { return pAppData_Impl->bDowning; }
+SfxDispatcher* SfxApplication::GetAppDispatcher_Impl() { return pAppData_Impl->pAppDispat; }
+SfxSlotPool& SfxApplication::GetAppSlotPool_Impl() const { return *pAppData_Impl->pSlotPool; }
+//SfxOptions& SfxApplication::GetOptions() { return *pAppData_Impl->pOptions; }
+//const SfxOptions& SfxApplication::GetOptions() const { return *pAppData_Impl->pOptions; }
+
diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx
new file mode 100644
index 000000000000..0f4c1f651082
--- /dev/null
+++ b/sfx2/source/appl/appopen.cxx
@@ -0,0 +1,1359 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/frame/FrameSearchFlag.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XNotifyingDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/frame/DispatchResultState.hpp>
+#include <com/sun/star/frame/XDispatchResultListener.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/system/XSystemShellExecute.hpp>
+#include <com/sun/star/document/XTypeDetection.hpp>
+#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
+#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/document/UpdateDocMode.hpp>
+#include <com/sun/star/task/ErrorCodeRequest.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/uno/Sequence.h>
+#include <comphelper/processfactory.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <rtl/ustring.hxx>
+
+
+#include <comphelper/storagehelper.hxx>
+#include <comphelper/synchronousdispatch.hxx>
+#include <comphelper/configurationhelper.hxx>
+#include <comphelper/sequenceasvector.hxx>
+
+#include <vcl/wrkwin.hxx>
+#include <svl/intitem.hxx>
+#include <vcl/msgbox.hxx>
+#include <svl/stritem.hxx>
+#include <svl/eitem.hxx>
+#include <sfx2/doctempl.hxx>
+#include <svtools/sfxecode.hxx>
+#include <framework/preventduplicateinteraction.hxx>
+#include <svtools/ehdl.hxx>
+#include <basic/sbxobj.hxx>
+#include <svl/urihelper.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <svtools/templdlg.hxx>
+#include <osl/file.hxx>
+#include <unotools/extendedsecurityoptions.hxx>
+#include <comphelper/docpasswordhelper.hxx>
+#include <vcl/svapp.hxx>
+
+#include <vos/mutex.hxx>
+
+#include <rtl/logfile.hxx>
+
+#include <sfx2/app.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/fcontnr.hxx>
+#include <sfx2/new.hxx>
+#include <sfx2/objitem.hxx>
+#include <sfx2/objsh.hxx>
+#include <svl/slstitm.hxx>
+#include "objshimp.hxx"
+#include "openflag.hxx"
+#include <sfx2/passwd.hxx>
+#include "referers.hxx"
+#include <sfx2/request.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/viewsh.hxx>
+#include "app.hrc"
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/objface.hxx>
+#include <sfx2/filedlghelper.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/event.hxx>
+
+#define _SVSTDARR_STRINGSDTOR
+#include <svl/svstdarr.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::system;
+using namespace ::com::sun::star::task;
+using namespace ::com::sun::star::container;
+using namespace ::cppu;
+using namespace ::sfx2;
+
+namespace css = ::com::sun::star;
+
+//=========================================================================
+
+class SfxOpenDocStatusListener_Impl : public WeakImplHelper1< XDispatchResultListener >
+{
+public:
+ BOOL bFinished;
+ BOOL bSuccess;
+ virtual void SAL_CALL dispatchFinished( const DispatchResultEvent& Event ) throw(RuntimeException);
+ virtual void SAL_CALL disposing( const EventObject& Source ) throw(RuntimeException);
+ SfxOpenDocStatusListener_Impl()
+ : bFinished( FALSE )
+ , bSuccess( FALSE )
+ {}
+};
+
+void SAL_CALL SfxOpenDocStatusListener_Impl::dispatchFinished( const DispatchResultEvent& aEvent ) throw(RuntimeException)
+{
+ bSuccess = ( aEvent.State == DispatchResultState::SUCCESS );
+ bFinished = TRUE;
+}
+
+void SAL_CALL SfxOpenDocStatusListener_Impl::disposing( const EventObject& ) throw(RuntimeException)
+{
+}
+
+SfxObjectShellRef SfxApplication::DocAlreadyLoaded
+(
+ const String& rName, // Name des Dokuments mit Pfad
+ BOOL bSilent, // TRUE: nicht nach neuer Sicht fragen
+ BOOL bActivate, // soll bestehende Sicht aktiviert werden
+ BOOL bForbidVisible,
+ const String* pPostStr
+)
+
+/* [Beschreibung]
+
+ Stellt fest, ob ein Dokument mit dem Namen 'rName' bereits geladen
+ ist und liefert einen Pointer darauf zu"uck.
+
+ Ist das Dokument noch nicht geladen, wird ein 0-Pointer zur"uckgeliefert.
+*/
+
+{
+ // zu suchenden Namen als URL aufbereiten
+ INetURLObject aUrlToFind( rName );
+ DBG_ASSERT( aUrlToFind.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL" );
+ String aPostString;
+ if ( pPostStr )
+ aPostString = *pPostStr;
+
+ // noch offen?
+ SfxObjectShellRef xDoc;
+
+ if ( !aUrlToFind.HasError() )
+ {
+ // dann bei den normal geoeffneten Docs
+ if ( !xDoc.Is() )
+ {
+ xDoc = SfxObjectShell::GetFirst( 0, FALSE ); // auch hidden Docs
+ while( xDoc.Is() )
+ {
+ if ( xDoc->GetMedium() &&
+ xDoc->GetCreateMode() == SFX_CREATE_MODE_STANDARD &&
+ !xDoc->IsAbortingImport() && !xDoc->IsLoading() )
+ {
+ // Vergleiche anhand der URLs
+ INetURLObject aUrl( xDoc->GetMedium()->GetName() );
+ if ( !aUrl.HasError() && aUrl == aUrlToFind &&
+ (!bForbidVisible || !SfxViewFrame::GetFirst( xDoc, TRUE )) &&
+ !xDoc->IsLoading())
+ {
+ break;
+ }
+ }
+ xDoc = SfxObjectShell::GetNext( *xDoc, 0, FALSE );
+ }
+ }
+ }
+
+ // gefunden?
+ if ( xDoc.Is() && bActivate )
+ {
+ DBG_ASSERT(
+ !bForbidVisible, "Unsichtbares kann nicht aktiviert werden" );
+
+ SfxViewFrame* pFrame;
+ for( pFrame = SfxViewFrame::GetFirst( xDoc );
+ pFrame && !pFrame->IsVisible();
+ pFrame = SfxViewFrame::GetNext( *pFrame, xDoc ) ) ;
+ if ( pFrame )
+ {
+ SfxViewFrame *pCur = SfxViewFrame::Current();
+ if ( !bSilent && pFrame == pCur )
+ InfoBox( 0, SfxResId(RID_DOCALREADYLOADED_DLG)).Execute();
+ if ( bActivate )
+ {
+ pFrame->MakeActive_Impl( TRUE );
+ }
+ }
+ }
+ return xDoc;
+}
+
+//====================================================================
+
+void SetTemplate_Impl( const String &rFileName,
+ const String &rLongName,
+ SfxObjectShell *pDoc)
+{
+ // write TemplateName to DocumentInfo of document
+ // TemplateDate stays as default (=current date)
+ pDoc->ResetFromTemplate( rLongName, rFileName );
+}
+
+//====================================================================
+class SfxDocPasswordVerifier : public ::comphelper::IDocPasswordVerifier
+{
+public:
+ inline explicit SfxDocPasswordVerifier( const Reference< embed::XStorage >& rxStorage ) :
+ mxStorage( rxStorage ) {}
+
+ virtual ::comphelper::DocPasswordVerifierResult
+ verifyPassword( const ::rtl::OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData );
+ virtual ::comphelper::DocPasswordVerifierResult
+ verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData );
+
+
+private:
+ Reference< embed::XStorage > mxStorage;
+};
+
+//--------------------------------------------------------------------
+::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyPassword( const ::rtl::OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData )
+{
+ o_rEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( rPassword );
+ return verifyEncryptionData( o_rEncryptionData );
+}
+
+
+//--------------------------------------------------------------------
+::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData )
+{
+ ::comphelper::DocPasswordVerifierResult eResult = ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD;
+ try
+ {
+ // check the encryption data
+ // if the data correct is the stream will be opened successfuly
+ // and immediatelly closed
+ ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( mxStorage, rEncryptionData );
+
+ mxStorage->openStreamElement(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ),
+ embed::ElementModes::READ | embed::ElementModes::NOCREATE );
+
+ // no exception -> success
+ eResult = ::comphelper::DocPasswordVerifierResult_OK;
+ }
+ catch( const packages::WrongPasswordException& )
+ {
+ eResult = ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD;
+ }
+ catch( const uno::Exception& )
+ {
+ // unknown error, do not try to ask again
+ eResult = ::comphelper::DocPasswordVerifierResult_ABORT;
+ }
+ return eResult;
+}
+
+//====================================================================
+
+//--------------------------------------------------------------------
+
+sal_uInt32 CheckPasswd_Impl
+(
+ //Window *pWin, // Parent des Dialogs
+ SfxObjectShell* pDoc,
+ SfxItemPool& /*rPool*/, // Pool, falls ein Set erzeugt werden mus
+ SfxMedium* pFile // das Medium, dessen Passwort gfs. erfragt werden soll
+)
+
+/* [Beschreibung]
+
+ Zu einem Medium das Passwort erfragen; funktioniert nur, wenn es sich
+ um einen Storage handelt.
+ Wenn in der Documentinfo das Passwort-Flag gesetzt ist, wird
+ das Passwort vom Benutzer per Dialog erfragt und an dem Set
+ des Mediums gesetzt; das Set wird, wenn nicht vorhanden, erzeugt.
+*/
+{
+ ULONG nRet = ERRCODE_NONE;
+
+ if( ( !pFile->GetFilter() || pFile->IsStorage() ) )
+ {
+ uno::Reference< embed::XStorage > xStorage = pFile->GetStorage( sal_True );
+ if( xStorage.is() )
+ {
+ uno::Reference< beans::XPropertySet > xStorageProps( xStorage, uno::UNO_QUERY );
+ if ( xStorageProps.is() )
+ {
+ sal_Bool bIsEncrypted = sal_False;
+ try {
+ xStorageProps->getPropertyValue( ::rtl::OUString::createFromAscii("HasEncryptedEntries") )
+ >>= bIsEncrypted;
+ } catch( uno::Exception& )
+ {
+ // TODO/LATER:
+ // the storage either has no encrypted elements or it's just
+ // does not allow to detect it, probably it should be implemented laiter
+ /*
+ bIsEncrypted = ( aInfo.Load( xStorage ) && aInfo.IsPasswd() );
+ */
+ }
+
+ if ( bIsEncrypted )
+ {
+ Window* pWin = pDoc ? pDoc->GetDialogParent( pFile ) : NULL;
+ if ( pWin )
+ pWin->Show();
+
+ nRet = ERRCODE_SFX_CANTGETPASSWD;
+
+ SfxItemSet *pSet = pFile->GetItemSet();
+ if( pSet )
+ {
+ Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = pFile->GetInteractionHandler();
+ if( xInteractionHandler.is() )
+ {
+ // use the comphelper password helper to request a password
+ ::rtl::OUString aPassword;
+ SFX_ITEMSET_ARG( pSet, pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False);
+ if ( pPasswordItem )
+ aPassword = pPasswordItem->GetValue();
+
+ uno::Sequence< beans::NamedValue > aEncryptionData;
+ SFX_ITEMSET_ARG( pSet, pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, sal_False);
+ if ( pEncryptionDataItem )
+ pEncryptionDataItem->GetValue() >>= aEncryptionData;
+
+ ::rtl::OUString aDocumentName = INetURLObject( pFile->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
+
+ SfxDocPasswordVerifier aVerifier( xStorage );
+ aEncryptionData = ::comphelper::DocPasswordHelper::requestAndVerifyDocPassword(
+ aVerifier, aEncryptionData, aPassword, xInteractionHandler, aDocumentName, comphelper::DocPasswordRequestType_STANDARD );
+
+ pSet->ClearItem( SID_PASSWORD );
+ pSet->ClearItem( SID_ENCRYPTIONDATA );
+
+ if ( aEncryptionData.getLength() > 0 )
+ {
+ pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) ) );
+
+ try
+ {
+ // update the version list of the medium using the new password
+ pFile->GetVersionList();
+ }
+ catch( uno::Exception& )
+ {
+ // TODO/LATER: set the error code
+ }
+
+ nRet = ERRCODE_NONE;
+ }
+ else
+ nRet = ERRCODE_IO_ABORT;
+ }
+ }
+ }
+ }
+ else
+ {
+ OSL_ENSURE( sal_False, "A storage must implement XPropertySet interface!" );
+ nRet = ERRCODE_SFX_CANTGETPASSWD;
+ }
+ }
+ }
+
+ return nRet;
+}
+
+//--------------------------------------------------------------------
+
+
+ULONG SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const String &rFileName, BOOL bCopy, SfxItemSet* pSet )
+{
+ const SfxFilter* pFilter = NULL;
+ SfxMedium aMedium( rFileName, ( STREAM_READ | STREAM_SHARE_DENYNONE ), FALSE );
+
+ if ( !aMedium.GetStorage( sal_True ).is() )
+ aMedium.GetInStream();
+
+ if ( aMedium.GetError() )
+ {
+ delete pSet;
+ return aMedium.GetErrorCode();
+ }
+
+ aMedium.UseInteractionHandler( TRUE );
+ ULONG nErr = GetFilterMatcher().GuessFilter( aMedium,&pFilter,SFX_FILTER_TEMPLATE, 0 );
+ if ( 0 != nErr)
+ {
+ delete pSet;
+ return ERRCODE_SFX_NOTATEMPLATE;
+ }
+
+ if( !pFilter || !pFilter->IsAllowedAsTemplate() )
+ {
+ delete pSet;
+ return ERRCODE_SFX_NOTATEMPLATE;
+ }
+
+ if ( pFilter->GetFilterFlags() & SFX_FILTER_STARONEFILTER )
+ {
+ DBG_ASSERT( !xDoc.Is(), "Sorry, not implemented!" );
+ delete pSet;
+ SfxStringItem aName( SID_FILE_NAME, rFileName );
+ SfxStringItem aReferer( SID_REFERER, String::CreateFromAscii("private:user") );
+ SfxStringItem aFlags( SID_OPTIONS, String::CreateFromAscii("T") );
+ SfxBoolItem aHidden( SID_HIDDEN, TRUE );
+ const SfxPoolItem *pRet = GetDispatcher_Impl()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, &aName, &aHidden, &aReferer, &aFlags, 0L );
+ const SfxObjectItem *pObj = PTR_CAST( SfxObjectItem, pRet );
+ if ( pObj )
+ xDoc = PTR_CAST( SfxObjectShell, pObj->GetShell() );
+ else
+ {
+ const SfxViewFrameItem *pView = PTR_CAST( SfxViewFrameItem, pRet );
+ if ( pView )
+ {
+ SfxViewFrame *pFrame = pView->GetFrame();
+ if ( pFrame )
+ xDoc = pFrame->GetObjectShell();
+ }
+ }
+
+ if ( !xDoc.Is() )
+ return ERRCODE_SFX_DOLOADFAILED;
+ }
+ else
+ {
+ if ( !xDoc.Is() )
+ xDoc = SfxObjectShell::CreateObject( pFilter->GetServiceName() );
+
+ SfxMedium *pMedium = new SfxMedium( rFileName, STREAM_STD_READ, FALSE, pFilter, pSet );
+ if(!xDoc->DoLoad(pMedium))
+ {
+ ErrCode nErrCode = xDoc->GetErrorCode();
+ xDoc->DoClose();
+ xDoc.Clear();
+ return nErrCode;
+ }
+ }
+
+ if( bCopy )
+ {
+ try
+ {
+ // TODO: introduce error handling
+
+ uno::Reference< embed::XStorage > xTempStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
+ if( !xTempStorage.is() )
+ throw uno::RuntimeException();
+
+ xDoc->GetStorage()->copyToStorage( xTempStorage );
+
+//REMOVE // the following operations should be done in one step
+//REMOVE xDoc->DoHandsOff();
+ if ( !xDoc->DoSaveCompleted( new SfxMedium( xTempStorage, String() ) ) )
+ throw uno::RuntimeException();
+ }
+ catch( uno::Exception& )
+ {
+ xDoc->DoClose();
+ xDoc.Clear();
+
+ // TODO: transfer correct error outside
+ return ERRCODE_SFX_GENERAL;
+ }
+
+ SetTemplate_Impl( rFileName, String(), xDoc );
+ }
+ else
+ SetTemplate_Impl( rFileName, String(), xDoc );
+
+ xDoc->SetNoName();
+ xDoc->InvalidateName();
+ xDoc->SetModified(FALSE);
+ xDoc->ResetError();
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > xModel ( xDoc->GetModel(), ::com::sun::star::uno::UNO_QUERY );
+ if ( xModel.is() )
+ {
+ SfxItemSet* pNew = xDoc->GetMedium()->GetItemSet()->Clone();
+ pNew->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
+ pNew->ClearItem( SID_FILTER_NAME );
+ //pNew->Put( SfxStringItem( SID_FILTER_NAME, xDoc->GetFactory().GetFilter(0)->GetFilterName() ) );
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
+ TransformItems( SID_OPENDOC, *pNew, aArgs );
+ sal_Int32 nLength = aArgs.getLength();
+ aArgs.realloc( nLength + 1 );
+ aArgs[nLength].Name = DEFINE_CONST_UNICODE("Title");
+ aArgs[nLength].Value <<= ::rtl::OUString( xDoc->GetTitle( SFX_TITLE_DETECT ) );
+ xModel->attachResource( ::rtl::OUString(), aArgs );
+ delete pNew;
+ }
+
+ return xDoc->GetErrorCode();
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::NewDocDirectExec_Impl( SfxRequest& rReq )
+{
+ DBG_MEMTEST();
+
+ SFX_REQUEST_ARG( rReq, pFactoryItem, SfxStringItem, SID_NEWDOCDIRECT, FALSE);
+ String aFactName;
+ if ( pFactoryItem )
+ aFactName = pFactoryItem->GetValue();
+ else
+ aFactName = SvtModuleOptions().GetDefaultModuleName();
+
+
+ SfxRequest aReq( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, GetPool() );
+ String aFact = String::CreateFromAscii("private:factory/");
+ aFact += aFactName;
+ aReq.AppendItem( SfxStringItem( SID_FILE_NAME, aFact ) );
+ aReq.AppendItem( SfxFrameItem( SID_DOCFRAME, GetFrame() ) );
+ aReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii( "_default" ) ) );
+
+ // TODO/LATER: Should the other arguments be transfered as well?
+ SFX_REQUEST_ARG( rReq, pDefaultPathItem, SfxStringItem, SID_DEFAULTFILEPATH, FALSE);
+ if ( pDefaultPathItem )
+ aReq.AppendItem( *pDefaultPathItem );
+ SFX_REQUEST_ARG( rReq, pDefaultNameItem, SfxStringItem, SID_DEFAULTFILENAME, FALSE);
+ if ( pDefaultNameItem )
+ aReq.AppendItem( *pDefaultNameItem );
+
+ SFX_APP()->ExecuteSlot( aReq );
+ const SfxViewFrameItem* pItem = PTR_CAST( SfxViewFrameItem, aReq.GetReturnValue() );
+ if ( pItem )
+ rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) );
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::NewDocExec_Impl( SfxRequest& rReq )
+{
+ DBG_MEMTEST();
+
+ // keine Parameter vom BASIC nur Factory angegeben?
+ SFX_REQUEST_ARG(rReq, pTemplNameItem, SfxStringItem, SID_TEMPLATE_NAME, FALSE);
+ SFX_REQUEST_ARG(rReq, pTemplFileNameItem, SfxStringItem, SID_FILE_NAME, FALSE);
+ SFX_REQUEST_ARG(rReq, pTemplRegionNameItem, SfxStringItem, SID_TEMPLATE_REGIONNAME, FALSE);
+
+ SfxObjectShellLock xDoc;
+
+ String aTemplateRegion, aTemplateName, aTemplateFileName;
+ BOOL bDirect = FALSE; // "uber FileName anstelle Region/Template
+ SfxErrorContext aEc(ERRCTX_SFX_NEWDOC);
+ if ( !pTemplNameItem && !pTemplFileNameItem )
+ {
+ Window* pTopWin = GetTopWindow();
+ SvtDocumentTemplateDialog* pDocTemplDlg = new SvtDocumentTemplateDialog( NULL );
+ int nRet = pDocTemplDlg->Execute();
+ sal_Bool bNewWin = sal_False;
+ if ( nRet == RET_OK )
+ {
+ rReq.Done();
+ if ( pTopWin != GetTopWindow() )
+ {
+ // the dialogue opens a document -> a new TopWindow appears
+ pTopWin = GetTopWindow();
+ bNewWin = sal_True;
+ }
+ }
+
+ delete pDocTemplDlg;
+ if ( bNewWin && pTopWin )
+ // after the destruction of the dialogue its parent comes to top,
+ // but we want that the new document is on top
+ pTopWin->ToTop();
+
+ return;
+ }
+ else
+ {
+ // Template-Name
+ if ( pTemplNameItem )
+ aTemplateName = pTemplNameItem->GetValue();
+
+ // Template-Region
+ if ( pTemplRegionNameItem )
+ aTemplateRegion = pTemplRegionNameItem->GetValue();
+
+ // Template-File-Name
+ if ( pTemplFileNameItem )
+ {
+ aTemplateFileName = pTemplFileNameItem->GetValue();
+ bDirect = TRUE;
+ }
+ }
+
+ ULONG lErr = 0;
+ SfxItemSet* pSet = new SfxAllItemSet( GetPool() );
+ pSet->Put( SfxBoolItem( SID_TEMPLATE, TRUE ) );
+ if ( !bDirect )
+ {
+ SfxDocumentTemplates aTmpFac;
+ if( !aTemplateFileName.Len() )
+ aTmpFac.GetFull( aTemplateRegion, aTemplateName, aTemplateFileName );
+
+ if( !aTemplateFileName.Len() )
+ lErr = ERRCODE_SFX_TEMPLATENOTFOUND;
+ }
+
+ INetURLObject aObj( aTemplateFileName );
+ SfxErrorContext aEC( ERRCTX_SFX_LOADTEMPLATE, aObj.PathToFileName() );
+
+ if ( lErr != ERRCODE_NONE )
+ {
+ ULONG lFatalErr = ERRCODE_TOERROR(lErr);
+ if ( lFatalErr )
+ ErrorHandler::HandleError(lErr);
+ }
+ else
+ {
+ SfxCallMode eMode = SFX_CALLMODE_SYNCHRON;
+
+ const SfxPoolItem *pRet=0;
+ SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE("private:user") );
+ SfxStringItem aTarget( SID_TARGETNAME, DEFINE_CONST_UNICODE("_default") );
+ if ( aTemplateFileName.Len() )
+ {
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL!" );
+
+ SfxStringItem aName( SID_FILE_NAME, aObj.GetMainURL( INetURLObject::NO_DECODE ) );
+ SfxStringItem aTemplName( SID_TEMPLATE_NAME, aTemplateName );
+ SfxStringItem aTemplRegionName( SID_TEMPLATE_REGIONNAME, aTemplateRegion );
+ pRet = GetDispatcher_Impl()->Execute( SID_OPENDOC, eMode, &aName, &aTarget, &aReferer, &aTemplName, &aTemplRegionName, 0L );
+ }
+ else
+ {
+ SfxStringItem aName( SID_FILE_NAME, DEFINE_CONST_UNICODE("private:factory") );
+ pRet = GetDispatcher_Impl()->Execute( SID_OPENDOC, eMode, &aName, &aTarget, &aReferer, 0L );
+ }
+
+ if ( pRet )
+ rReq.SetReturnValue( *pRet );
+ }
+}
+
+//---------------------------------------------------------------------------
+
+void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
+{
+ DBG_MEMTEST();
+
+ USHORT nSID = rReq.GetSlot();
+ SFX_REQUEST_ARG( rReq, pFileNameItem, SfxStringItem, SID_FILE_NAME, FALSE );
+ if ( pFileNameItem )
+ {
+ String aCommand( pFileNameItem->GetValue() );
+ const SfxSlot* pSlot = GetInterface()->GetSlot( aCommand );
+ if ( pSlot )
+ {
+ pFileNameItem = NULL;
+ }
+ else
+ {
+ sal_Int32 nIndex = aCommand.SearchAscii("slot:");
+ if ( !nIndex )
+ {
+ USHORT nSlotId = (USHORT) String( aCommand, 5, aCommand.Len()-5 ).ToInt32();
+ if ( nSlotId == SID_OPENDOC )
+ pFileNameItem = NULL;
+ }
+ }
+ }
+
+ if ( !pFileNameItem )
+ {
+ // get FileName from dialog
+ SvStringsDtor* pURLList = NULL;
+ String aFilter;
+ SfxItemSet* pSet = NULL;
+ String aPath;
+ SFX_REQUEST_ARG( rReq, pFolderNameItem, SfxStringItem, SID_PATH, FALSE );
+ if ( pFolderNameItem )
+ aPath = pFolderNameItem->GetValue();
+ else if ( nSID == SID_OPENTEMPLATE )
+ {
+ aPath = SvtPathOptions().GetTemplatePath();
+ sal_Int32 nTokenCount = aPath.GetTokenCount( ';' );
+ aPath = aPath.GetToken(
+ sal::static_int_cast< xub_StrLen >(
+ nTokenCount ? ( nTokenCount - 1 ) : 0 ),
+ ';' );
+ }
+
+ sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG;
+ SFX_REQUEST_ARG( rReq, pSystemDialogItem, SfxBoolItem, SID_FILE_DIALOG, FALSE );
+ if ( pSystemDialogItem )
+ nDialog = pSystemDialogItem->GetValue() ? SFX2_IMPL_DIALOG_SYSTEM : SFX2_IMPL_DIALOG_OOO;
+
+ String sStandardDir;
+
+ SFX_REQUEST_ARG( rReq, pStandardDirItem, SfxStringItem, SID_STANDARD_DIR, FALSE );
+ if ( pStandardDirItem )
+ sStandardDir = pStandardDirItem->GetValue();
+
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > aBlackList;
+
+ SFX_REQUEST_ARG( rReq, pBlackListItem, SfxStringListItem, SID_BLACK_LIST, FALSE );
+ if ( pBlackListItem )
+ pBlackListItem->GetStringList( aBlackList );
+
+
+ ULONG nErr = sfx2::FileOpenDialog_Impl(
+ WB_OPEN | SFXWB_MULTISELECTION | SFXWB_SHOWVERSIONS, String(), pURLList, aFilter, pSet, &aPath, nDialog, sStandardDir, aBlackList );
+
+ if ( nErr == ERRCODE_ABORT )
+ {
+ delete pURLList;
+ return;
+ }
+
+ rReq.SetArgs( *(SfxAllItemSet*)pSet );
+ if (aFilter.Len() >0 )
+ rReq.AppendItem( SfxStringItem( SID_FILTER_NAME, aFilter ) );
+ rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_default") ) );
+ rReq.AppendItem( SfxStringItem( SID_REFERER, String::CreateFromAscii(SFX_REFERER_USER) ) );
+ delete pSet;
+
+ if ( pURLList->Count() )
+ {
+ if ( nSID == SID_OPENTEMPLATE )
+ rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, FALSE ) );
+
+ // This helper wraps an existing (or may new created InteractionHandler)
+ // intercept all incoming interactions and provide usefull informations
+ // later if the following transaction was finished.
+
+ ::framework::PreventDuplicateInteraction* pHandler = new ::framework::PreventDuplicateInteraction(::comphelper::getProcessServiceFactory());
+ css::uno::Reference< css::task::XInteractionHandler > xHandler (static_cast< css::task::XInteractionHandler* >(pHandler), css::uno::UNO_QUERY);
+ css::uno::Reference< css::task::XInteractionHandler > xWrappedHandler;
+
+ // wrap existing handler or create new UUI handler
+ SFX_REQUEST_ARG(rReq, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, FALSE);
+ if (pInteractionItem)
+ {
+ pInteractionItem->GetValue() >>= xWrappedHandler;
+ rReq.RemoveItem( SID_INTERACTIONHANDLER );
+ }
+ if (xWrappedHandler.is())
+ pHandler->setHandler(xWrappedHandler);
+ else
+ pHandler->useDefaultUUIHandler();
+ rReq.AppendItem( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHandler)) );
+
+ // define rules for this handler
+ css::uno::Type aInteraction = ::getCppuType(static_cast< css::task::ErrorCodeRequest* >(0));
+ ::framework::PreventDuplicateInteraction::InteractionInfo aRule (aInteraction, 1);
+ pHandler->addInteractionRule(aRule);
+
+ for ( USHORT i = 0; i < pURLList->Count(); ++i )
+ {
+ String aURL = *(pURLList->GetObject(i));
+ rReq.RemoveItem( SID_FILE_NAME );
+ rReq.AppendItem( SfxStringItem( SID_FILE_NAME, aURL ) );
+
+ // synchron ausf"uhren, damit beim Reschedulen nicht schon das n"achste Dokument
+ // geladen wird
+ // TODO/LATER: use URLList argument and always remove one document after another, each step in asychronous execution, until finished
+ // but only if reschedule is a problem
+ GetDispatcher_Impl()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, *rReq.GetArgs() );
+
+ // check for special interaction "NO MORE DOCUMENTS ALLOWED" and
+ // break loop then. Otherwise we risk showing the same interaction more then once.
+ if ( pHandler->getInteractionInfo(aInteraction, &aRule) )
+ {
+ if (aRule.m_nCallCount > 0)
+ {
+ if (aRule.m_xRequest.is())
+ {
+ css::task::ErrorCodeRequest aRequest;
+ if (aRule.m_xRequest->getRequest() >>= aRequest)
+ {
+ if (aRequest.ErrCode ==
+ sal::static_int_cast< sal_Int32 >(
+ ERRCODE_SFX_NOMOREDOCUMENTSALLOWED))
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ delete pURLList;
+ return;
+ }
+ delete pURLList;
+ }
+
+ if ( !rReq.IsSynchronCall() )
+ {
+ // now check wether a stream is already there
+ // if not: download it in a thread and restart the call
+ // return;
+ }
+
+ BOOL bHyperlinkUsed = FALSE;
+
+ if ( SID_OPENURL == nSID )
+ {
+ // SID_OPENURL does the same as SID_OPENDOC!
+ rReq.SetSlot( SID_OPENDOC );
+ nSID = SID_OPENDOC;
+ }
+ else if ( nSID == SID_OPENTEMPLATE )
+ {
+ rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, FALSE ) );
+ }
+ // pass URL to OS by using ShellExecuter or open it internal
+ // if it seams to be an own format.
+ /* Attention!
+ There exist two possibilities to open hyperlinks:
+ a) using SID_OPENHYPERLINK (new)
+ b) using SID_BROWSE (old)
+ */
+ else if ( nSID == SID_OPENHYPERLINK )
+ {
+ rReq.SetSlot( SID_OPENDOC );
+ nSID = SID_OPENDOC;
+ bHyperlinkUsed = TRUE;
+ }
+
+ // no else here! It's optional ...
+ if (!bHyperlinkUsed)
+ {
+ SFX_REQUEST_ARG(rReq, pHyperLinkUsedItem, SfxBoolItem, SID_BROWSE, FALSE);
+ if ( pHyperLinkUsedItem )
+ bHyperlinkUsed = pHyperLinkUsedItem->GetValue();
+ // no "official" item, so remove it from ItemSet before using UNO-API
+ rReq.RemoveItem( SID_BROWSE );
+ }
+
+ SFX_REQUEST_ARG( rReq, pFileName, SfxStringItem, SID_FILE_NAME, FALSE );
+ String aFileName = pFileName->GetValue();
+
+ String aReferer;
+ SFX_REQUEST_ARG( rReq, pRefererItem, SfxStringItem, SID_REFERER, FALSE );
+ if ( pRefererItem )
+ aReferer = pRefererItem->GetValue();
+
+ SFX_REQUEST_ARG( rReq, pFileFlagsItem, SfxStringItem, SID_OPTIONS, FALSE);
+ if ( pFileFlagsItem )
+ {
+ String aFileFlags = pFileFlagsItem->GetValue();
+ aFileFlags.ToUpperAscii();
+ if ( STRING_NOTFOUND != aFileFlags.Search( 0x0054 ) ) // T = 54h
+ {
+ rReq.RemoveItem( SID_TEMPLATE );
+ rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, TRUE ) );
+ }
+
+ if ( STRING_NOTFOUND != aFileFlags.Search( 0x0048 ) ) // H = 48h
+ {
+ rReq.RemoveItem( SID_HIDDEN );
+ rReq.AppendItem( SfxBoolItem( SID_HIDDEN, TRUE ) );
+ }
+
+ if ( STRING_NOTFOUND != aFileFlags.Search( 0x0052 ) ) // R = 52h
+ {
+ rReq.RemoveItem( SID_DOC_READONLY );
+ rReq.AppendItem( SfxBoolItem( SID_DOC_READONLY, TRUE ) );
+ }
+
+ if ( STRING_NOTFOUND != aFileFlags.Search( 0x0042 ) ) // B = 42h
+ {
+ rReq.RemoveItem( SID_PREVIEW );
+ rReq.AppendItem( SfxBoolItem( SID_PREVIEW, TRUE ) );
+ }
+
+ if ( STRING_NOTFOUND != aFileFlags.Search( 0x0053 ) ) // S = 53h
+ {
+ // not supported anymore
+ //rReq.RemoveItem( SID_SILENT );
+ //rReq.AppendItem( SfxBoolItem( SID_SILENT, TRUE ) );
+ }
+
+ rReq.RemoveItem( SID_OPTIONS );
+ }
+
+ // Mark without URL cannot be handled by hyperlink code
+ if ( bHyperlinkUsed && aFileName.Len() && aFileName.GetChar(0) != '#' )
+ {
+ Reference< ::com::sun::star::document::XTypeDetection > xTypeDetection(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.document.TypeDetection" )),
+ UNO_QUERY );
+ if ( xTypeDetection.is() )
+ {
+ URL aURL;
+ ::rtl::OUString aTypeName;
+
+ aURL.Complete = aFileName;
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( aURL );
+
+ INetProtocol aINetProtocol = INetURLObject( aURL.Complete ).GetProtocol();
+ SvtExtendedSecurityOptions aExtendedSecurityOptions;
+ SvtExtendedSecurityOptions::OpenHyperlinkMode eMode = aExtendedSecurityOptions.GetOpenHyperlinkMode();
+ if ( eMode == SvtExtendedSecurityOptions::OPEN_WITHSECURITYCHECK )
+ {
+ if ( aINetProtocol == INET_PROT_FILE )
+ {
+/*!!! pb: #i49802# no security warning any longer
+ // Check if file URL is a directory. This is not insecure!
+ osl::Directory aDir( aURL.Main );
+ sal_Bool bIsDir = ( aDir.open() == osl::Directory::E_None );
+
+ if ( !bIsDir && !aExtendedSecurityOptions.IsSecureHyperlink( aURL.Complete ) )
+ {
+ // Security check for local files depending on the extension
+ vos::OGuard aGuard( Application::GetSolarMutex() );
+ Window *pWindow = SFX_APP()->GetTopWindow();
+
+ String aSecurityWarningBoxTitle( SfxResId( RID_SECURITY_WARNING_TITLE ));
+ WarningBox aSecurityWarningBox( pWindow, SfxResId( RID_SECURITY_WARNING_HYPERLINK ));
+ aSecurityWarningBox.SetText( aSecurityWarningBoxTitle );
+
+ // Replace %s with the real file name
+ String aMsgText = aSecurityWarningBox.GetMessText();
+ String aMainURL( aURL.Main );
+ String aFileName;
+
+ utl::LocalFileHelper::ConvertURLToPhysicalName( aMainURL, aFileName );
+ aMsgText.SearchAndReplaceAscii( "%s", aFileName );
+ aSecurityWarningBox.SetMessText( aMsgText );
+
+ if( aSecurityWarningBox.Execute() == RET_NO )
+ return;
+ }
+*/
+ }
+ }
+ else if ( eMode == SvtExtendedSecurityOptions::OPEN_NEVER && aINetProtocol != INET_PROT_VND_SUN_STAR_HELP )
+ {
+ vos::OGuard aGuard( Application::GetSolarMutex() );
+ Window *pWindow = SFX_APP()->GetTopWindow();
+
+ String aSecurityWarningBoxTitle( SfxResId( RID_SECURITY_WARNING_TITLE ));
+ WarningBox aSecurityWarningBox( pWindow, SfxResId( RID_SECURITY_WARNING_NO_HYPERLINKS ));
+ aSecurityWarningBox.SetText( aSecurityWarningBoxTitle );
+ aSecurityWarningBox.Execute();
+ return;
+ }
+
+ aTypeName = xTypeDetection->queryTypeByURL( aURL.Main );
+ SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
+ const SfxFilter* pFilter = rMatcher.GetFilter4EA( aTypeName );
+ if ( !pFilter || !( pFilter->IsOwnFormat() ))
+ {
+ // hyperlink does not link to own type => special handling (http, ftp) browser and (other external protocols) OS
+ Reference< XSystemShellExecute > xSystemShellExecute( ::comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" )), UNO_QUERY );
+ if ( xSystemShellExecute.is() )
+ {
+ if ( aINetProtocol == INET_PROT_MAILTO )
+ {
+ // don't dispatch mailto hyperlink to desktop dispatcher
+ rReq.RemoveItem( SID_TARGETNAME );
+ rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_self") ) );
+ }
+ else if ( aINetProtocol == INET_PROT_FTP ||
+ aINetProtocol == INET_PROT_HTTP ||
+ aINetProtocol == INET_PROT_HTTPS )
+ {
+ try
+ {
+ // start browser
+ ::rtl::OUString aURLString( aURL.Complete );
+ xSystemShellExecute->execute( aURLString, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
+ }
+ catch ( ::com::sun::star::lang::IllegalArgumentException& )
+ {
+ vos::OGuard aGuard( Application::GetSolarMutex() );
+ Window *pWindow = SFX_APP()->GetTopWindow();
+ ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute();
+ }
+ catch ( ::com::sun::star::system::SystemShellExecuteException& )
+ {
+ vos::OGuard aGuard( Application::GetSolarMutex() );
+ Window *pWindow = SFX_APP()->GetTopWindow();
+ ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute();
+ }
+
+ return;
+ }
+ else
+ {
+ // check for "internal" protocols that should not be forwarded to the system
+ Sequence < ::rtl::OUString > aProtocols(2);
+
+ // add special protocols that always should be treated as internal
+ aProtocols[0] = ::rtl::OUString::createFromAscii("private:*");
+ aProtocols[1] = ::rtl::OUString::createFromAscii("vnd.sun.star.*");
+
+ try
+ {
+ // get registered protocol handlers from configuration
+ Reference < XNameAccess > xAccess( ::comphelper::ConfigurationHelper::openConfig( ::comphelper::getProcessServiceFactory(),
+ ::rtl::OUString::createFromAscii("org.openoffice.Office.ProtocolHandler/HandlerSet"), ::comphelper::ConfigurationHelper::E_READONLY ), UNO_QUERY );
+ if ( xAccess.is() )
+ {
+ Sequence < ::rtl::OUString > aNames = xAccess->getElementNames();
+ for ( sal_Int32 nName = 0; nName < aNames.getLength(); nName ++)
+ {
+ Reference < XPropertySet > xSet;
+ Any aRet = xAccess->getByName( aNames[nName] );
+ aRet >>= xSet;
+ if ( xSet.is() )
+ {
+ // copy protocols
+ aRet = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("Protocols") );
+ Sequence < ::rtl::OUString > aTmp;
+ aRet >>= aTmp;
+
+ // todo: add operator+= to SequenceAsVector class and use SequenceAsVector for aProtocols
+ sal_Int32 nLength = aProtocols.getLength();
+ aProtocols.realloc( nLength+aTmp.getLength() );
+ for ( sal_Int32 n=0; n<aTmp.getLength(); n++ )
+ aProtocols[(++nLength)-1] = aTmp[n];
+ }
+ }
+ }
+ }
+ catch ( Exception& )
+ {
+ // registered protocols could not be read
+ }
+
+ sal_Bool bFound = sal_False;
+ for ( sal_Int32 nProt=0; nProt<aProtocols.getLength(); nProt++ )
+ {
+ WildCard aPattern(aProtocols[nProt]);
+ if ( aPattern.Matches( aURL.Complete ) )
+ {
+ bFound = sal_True;
+ break;
+ }
+ }
+
+ if ( !bFound )
+ {
+ BOOL bLoadInternal = FALSE;
+
+ // security reservation: => we have to check the referer before executing
+ if (SFX_APP()->IsSecureURL(rtl::OUString(), &aReferer))
+ {
+ ::rtl::OUString aURLString( aURL.Complete );
+
+ try
+ {
+ // give os this file
+ xSystemShellExecute->execute( aURLString, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
+ }
+ catch ( ::com::sun::star::lang::IllegalArgumentException& )
+ {
+ vos::OGuard aGuard( Application::GetSolarMutex() );
+ Window *pWindow = SFX_APP()->GetTopWindow();
+ ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute();
+ }
+ catch ( ::com::sun::star::system::SystemShellExecuteException& )
+ {
+ if ( !pFilter )
+ {
+ vos::OGuard aGuard( Application::GetSolarMutex() );
+ Window *pWindow = SFX_APP()->GetTopWindow();
+ ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute();
+ }
+ else
+ {
+ rReq.RemoveItem( SID_TARGETNAME );
+ rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_default") ) );
+ bLoadInternal = TRUE;
+ }
+ }
+ }
+ else
+ {
+ SfxErrorContext aCtx( ERRCTX_SFX_OPENDOC, aURL.Complete );
+ ErrorHandler::HandleError( ERRCODE_IO_ACCESSDENIED );
+ }
+
+ if ( !bLoadInternal )
+ return;
+ }
+ }
+ }
+ }
+ else
+ {
+ // hyperlink document must be loaded into a new frame
+ rReq.RemoveItem( SID_TARGETNAME );
+ rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_default") ) );
+ }
+ }
+ }
+
+ if ( !SFX_APP()->IsSecureURL( INetURLObject(aFileName), &aReferer ) )
+ {
+ SfxErrorContext aCtx( ERRCTX_SFX_OPENDOC, aFileName );
+ ErrorHandler::HandleError( ERRCODE_IO_ACCESSDENIED );
+ return;
+ }
+
+ SfxFrame* pTargetFrame = NULL;
+ Reference< XFrame > xTargetFrame;
+
+ SFX_REQUEST_ARG(rReq, pFrameItem, SfxFrameItem, SID_DOCFRAME, FALSE);
+ if ( pFrameItem )
+ pTargetFrame = pFrameItem->GetFrame();
+
+ if ( !pTargetFrame )
+ {
+ SFX_REQUEST_ARG(rReq, pUnoFrameItem, SfxUnoFrameItem, SID_FILLFRAME, FALSE);
+ if ( pUnoFrameItem )
+ xTargetFrame = pUnoFrameItem->GetFrame();
+ }
+
+ if ( !pTargetFrame && !xTargetFrame.is() && SfxViewFrame::Current() )
+ pTargetFrame = &SfxViewFrame::Current()->GetFrame();
+
+ // check if caller has set a callback
+ SFX_REQUEST_ARG(rReq, pLinkItem, SfxLinkItem, SID_DONELINK, FALSE );
+
+ // remove from Itemset, because it confuses the parameter transformation
+ if ( pLinkItem )
+ pLinkItem = (SfxLinkItem*) pLinkItem->Clone();
+
+ rReq.RemoveItem( SID_DONELINK );
+
+ // check if the view must be hidden
+ BOOL bHidden = FALSE;
+ SFX_REQUEST_ARG(rReq, pHidItem, SfxBoolItem, SID_HIDDEN, FALSE);
+ if ( pHidItem )
+ bHidden = pHidItem->GetValue();
+
+ // This request is a UI call. We have to set the right values inside the MediaDescriptor
+ // for: InteractionHandler, StatusIndicator, MacroExecutionMode and DocTemplate.
+ // But we have to look for already existing values or for real hidden requests.
+ SFX_REQUEST_ARG(rReq, pPreviewItem, SfxBoolItem, SID_PREVIEW, FALSE);
+ if (!bHidden && ( !pPreviewItem || !pPreviewItem->GetValue() ) )
+ {
+ SFX_REQUEST_ARG(rReq, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, FALSE);
+ SFX_REQUEST_ARG(rReq, pMacroExecItem , SfxUInt16Item, SID_MACROEXECMODE , FALSE);
+ SFX_REQUEST_ARG(rReq, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE , FALSE);
+
+ if (!pInteractionItem)
+ {
+ Reference < ::com::sun::star::task::XInteractionHandler > xHdl( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY );
+ if (xHdl.is())
+ rReq.AppendItem( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) );
+ }
+ if (!pMacroExecItem)
+ rReq.AppendItem( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) );
+ if (!pDocTemplateItem)
+ rReq.AppendItem( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) );
+ }
+
+ // extract target name
+ ::rtl::OUString aTarget;
+ SFX_REQUEST_ARG(rReq, pTargetItem, SfxStringItem, SID_TARGETNAME, FALSE);
+ if ( pTargetItem )
+ aTarget = pTargetItem->GetValue();
+ else
+ {
+ SFX_REQUEST_ARG( rReq, pNewViewItem, SfxBoolItem, SID_OPEN_NEW_VIEW, FALSE );
+ if ( pNewViewItem && pNewViewItem->GetValue() )
+ aTarget = String::CreateFromAscii("_blank" );
+ }
+
+ if ( bHidden )
+ {
+ aTarget = String::CreateFromAscii("_blank");
+ DBG_ASSERT( rReq.IsSynchronCall() || pLinkItem, "Hidden load process must be done synchronously!" );
+ }
+
+ Reference < XController > xController;
+// if ( ( !bIsBlankTarget && pFrame ) || pLinkItem || !rReq.IsSynchronCall() )
+// {
+ // if a frame is given, it must be used for the starting point of the targetting mechanism
+ // this code is also used if asynchronous loading is possible, because loadComponent always is synchron
+ if ( !xTargetFrame.is() )
+ {
+ if ( pTargetFrame )
+ {
+ xTargetFrame = pTargetFrame->GetFrameInterface();
+ }
+ else
+ {
+ xTargetFrame.set( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), UNO_QUERY );
+ }
+ }
+
+ // make URL ready
+ SFX_REQUEST_ARG( rReq, pURLItem, SfxStringItem, SID_FILE_NAME, FALSE );
+ aFileName = pURLItem->GetValue();
+ if( aFileName.Len() && aFileName.GetChar(0) == '#' ) // Mark without URL
+ {
+ SfxViewFrame *pView = pTargetFrame ? pTargetFrame->GetCurrentViewFrame() : 0;
+ if ( !pView )
+ pView = SfxViewFrame::Current();
+ pView->GetViewShell()->JumpToMark( aFileName.Copy(1) );
+ rReq.SetReturnValue( SfxViewFrameItem( 0, pView ) );
+ return;
+ }
+
+ // convert items to properties for framework API calls
+ Sequence < PropertyValue > aArgs;
+ TransformItems( SID_OPENDOC, *rReq.GetArgs(), aArgs );
+
+ // TODO/LATER: either remove LinkItem or create an asynchronous process for it
+ if( bHidden || pLinkItem || rReq.IsSynchronCall() )
+ {
+ // if loading must be done synchron, we must wait for completion to get a return value
+ // find frame by myself; I must konw the exact frame to get the controller for the return value from it
+ //if( aTarget.getLength() )
+ // xTargetFrame = xTargetFrame->findFrame( aTarget, FrameSearchFlag::ALL );
+ Reference < XComponent > xComp;
+
+ try
+ {
+ xComp = ::comphelper::SynchronousDispatch::dispatch( xTargetFrame, aFileName, aTarget, 0, aArgs );
+// Reference < XComponentLoader > xLoader( xTargetFrame, UNO_QUERY );
+// xComp = xLoader->loadComponentFromURL( aFileName, aTarget, 0, aArgs );
+ }
+ catch(const RuntimeException&)
+ {
+ throw;
+ }
+ catch(const ::com::sun::star::uno::Exception&)
+ {
+ }
+
+ Reference < XModel > xModel( xComp, UNO_QUERY );
+ if ( xModel.is() )
+ xController = xModel->getCurrentController();
+ else
+ xController = Reference < XController >( xComp, UNO_QUERY );
+
+ }
+ else
+ {
+ URL aURL;
+ aURL.Complete = aFileName;
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( aURL );
+
+ Reference < XDispatchProvider > xProv( xTargetFrame, UNO_QUERY );
+ Reference < XDispatch > xDisp = xProv.is() ? xProv->queryDispatch( aURL, aTarget, FrameSearchFlag::ALL ) : Reference < XDispatch >();;
+ RTL_LOGFILE_PRODUCT_CONTEXT( aLog2, "PERFORMANCE - SfxApplication::OpenDocExec_Impl" );
+ if ( xDisp.is() )
+ xDisp->dispatch( aURL, aArgs );
+ }
+ /*
+ }
+ else
+ {
+ // synchron loading without a given frame or as blank frame
+ SFX_REQUEST_ARG( rReq, pFileNameItem, SfxStringItem, SID_FILE_NAME, FALSE );
+
+ // Desktop service must exists! dont catch() or check for problems here ...
+ // But loading of documents can fail by other reasons. Handle it more gracefully.
+ Reference < XComponentLoader > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), UNO_QUERY );
+ Reference < XComponent > xComp;
+ try
+ {
+ xComp = xDesktop->loadComponentFromURL( pFileNameItem->GetValue(), aTarget, 0, aArgs );
+ }
+ catch(const RuntimeException&)
+ {
+ throw;
+ }
+ catch(const ::com::sun::star::uno::Exception&)
+ {
+ xDesktop.clear();
+ xComp.clear();
+ }
+
+ Reference < XModel > xModel( xComp, UNO_QUERY );
+ if ( xModel.is() )
+ xController = xModel->getCurrentController();
+ else
+ xController = Reference < XController >( xComp, UNO_QUERY );
+ }*/
+
+ if ( xController.is() )
+ {
+ // try to find the SfxFrame for the controller
+ SfxFrame* pCntrFrame = NULL;
+ for ( SfxViewShell* pShell = SfxViewShell::GetFirst( 0, FALSE ); pShell; pShell = SfxViewShell::GetNext( *pShell, 0, FALSE ) )
+ {
+ if ( pShell->GetController() == xController )
+ {
+ pCntrFrame = &pShell->GetViewFrame()->GetFrame();
+ break;
+ }
+ }
+
+ if ( pCntrFrame )
+ {
+ SfxObjectShell* pSh = pCntrFrame->GetCurrentDocument();
+ DBG_ASSERT( pSh, "Controller without ObjectShell ?!" );
+
+ rReq.SetReturnValue( SfxViewFrameItem( 0, pCntrFrame->GetCurrentViewFrame() ) );
+
+ if ( bHidden )
+ pSh->RestoreNoDelete();
+ }
+ }
+
+ if ( pLinkItem )
+ {
+ SfxPoolItem* pRet = rReq.GetReturnValue()->Clone();
+ pLinkItem->GetValue().Call(pRet);
+ delete pLinkItem;
+ }
+}
diff --git a/sfx2/source/appl/appquit.cxx b/sfx2/source/appl/appquit.cxx
new file mode 100644
index 000000000000..e7d0fd70bf58
--- /dev/null
+++ b/sfx2/source/appl/appquit.cxx
@@ -0,0 +1,174 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <basic/basmgr.hxx>
+#include <basic/sbstar.hxx>
+
+#include <svl/svdde.hxx>
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#include <svl/eitem.hxx>
+
+#include <unotools/saveopt.hxx>
+#include <unotools/misccfg.hxx>
+
+#ifndef GCC
+#endif
+
+#include "app.hrc"
+#include <sfx2/app.hxx>
+#include <sfx2/unoctitm.hxx>
+#include "appdata.hxx"
+#include <sfx2/viewsh.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/printer.hxx>
+#include "arrdecl.hxx"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/event.hxx>
+#include <sfx2/macrconf.hxx>
+#include <sfx2/mnumgr.hxx>
+#include <sfx2/templdlg.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/docfile.hxx>
+#include "sfxtypes.hxx"
+#include "sfxlocal.hrc"
+#include <sfx2/fcontnr.hxx>
+#include "nochaos.hxx"
+#include <sfx2/appuno.hxx>
+#include <sfx2/doctempl.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/docfac.hxx>
+#include "appbaslib.hxx"
+#include <basic/basicmanagerrepository.hxx>
+
+using ::basic::BasicManagerRepository;
+
+//===================================================================
+BOOL SfxApplication::QueryExit_Impl()
+{
+ BOOL bQuit = TRUE;
+
+ // will trotzdem noch jemand, den man nicht abschiessen kann, die App haben?
+ if ( !bQuit )
+ {
+ // nicht wirklich beenden, nur minimieren
+ InfoBox aInfoBox( NULL, SfxResId(MSG_CANT_QUIT) );
+ aInfoBox.Execute();
+ DBG_TRACE( "QueryExit => FALSE (in use)" );
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxApplication::Deinitialize()
+{
+ if ( pAppData_Impl->bDowning )
+ return;
+
+ StarBASIC::Stop();
+
+ // ggf. BASIC speichern
+ BasicManager* pBasMgr = BasicManagerRepository::getApplicationBasicManager( false );
+ if ( pBasMgr && pBasMgr->IsModified() )
+ SaveBasicManager();
+
+ SaveBasicAndDialogContainer();
+
+ pAppData_Impl->bDowning = TRUE; // wegen Timer aus DecAliveCount und QueryExit
+
+ DELETEZ( pAppData_Impl->pTemplates );
+
+ // By definition there shouldn't be any open view frames when we reach
+ // this method. Therefore this call makes no sense and is the source of
+ // some stack traces, which we don't understand.
+ // For more information see:
+ // #123501#
+ //SetViewFrame(0);
+ pAppData_Impl->bDowning = FALSE;
+ DBG_ASSERT( !SfxViewFrame::GetFirst(),
+ "existing SfxViewFrame after Execute" );
+ DBG_ASSERT( !SfxObjectShell::GetFirst(),
+ "existing SfxObjectShell after Execute" );
+ pAppData_Impl->pAppDispat->Pop( *this, SFX_SHELL_POP_UNTIL );
+ pAppData_Impl->pAppDispat->Flush();
+ pAppData_Impl->bDowning = TRUE;
+ pAppData_Impl->pAppDispat->DoDeactivate_Impl( TRUE, NULL );
+
+ // call derived application-exit
+ Exit();
+
+ // Controller u."a. freigeben
+ // dabei sollten auch restliche Komponenten ( Beamer! ) verschwinden
+ BasicManagerRepository::resetApplicationBasicManager();
+ pAppData_Impl->pBasicManager->reset( NULL );
+ // this will also delete pBasMgr
+
+ DBG_ASSERT( pAppData_Impl->pViewFrame == 0, "active foreign ViewFrame" );
+
+ delete[] pAppData_Impl->pInterfaces, pAppData_Impl->pInterfaces = 0;
+
+ // free administration managers
+ DELETEZ(pAppData_Impl->pAppDispat);
+ SfxResId::DeleteResMgr();
+ DELETEZ(pAppData_Impl->pOfaResMgr);
+
+ // ab hier d"urfen keine SvObjects mehr existieren
+ DELETEZ(pAppData_Impl->pMatcher);
+
+ delete pAppData_Impl->pLabelResMgr;
+
+ DELETEX(pAppData_Impl->pSlotPool);
+ DELETEX(pAppData_Impl->pEventConfig);
+ SfxMacroConfig::Release_Impl();
+ DELETEX(pAppData_Impl->pFactArr);
+ DELETEX(pAppData_Impl->pInitLinkList);
+
+ DELETEX(pAppData_Impl->pTbxCtrlFac);
+ DELETEX(pAppData_Impl->pStbCtrlFac);
+ DELETEX(pAppData_Impl->pMenuCtrlFac);
+ DELETEX(pAppData_Impl->pViewFrames);
+ DELETEX(pAppData_Impl->pViewShells);
+ DELETEX(pAppData_Impl->pObjShells);
+
+ //TODO/CLEANTUP
+ //ReleaseArgs could be used instead!
+/* This leak is intended !
+ Otherwise the TestTool cant use .uno:QuitApp ...
+ because every destructed ItemSet work's on an already
+ released pool pointer .-)
+
+ NoChaos::ReleaseItemPool();
+*/
+ pAppData_Impl->pPool = NULL;
+}
diff --git a/sfx2/source/appl/appreg.cxx b/sfx2/source/appl/appreg.cxx
new file mode 100644
index 000000000000..9fd2dfc696d3
--- /dev/null
+++ b/sfx2/source/appl/appreg.cxx
@@ -0,0 +1,153 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <vcl/toolbox.hxx>
+
+#ifndef GCC
+#endif
+
+#include <sfx2/app.hxx>
+#include "appdata.hxx"
+#include "arrdecl.hxx"
+#include "sfx2/sfxhelp.hxx"
+#include <sfx2/templdlg.hxx>
+#include "objmnctl.hxx"
+#include "inettbc.hxx"
+#include "sfx2/stbitem.hxx"
+#include <sfx2/navigat.hxx>
+#include <sfx2/taskpane.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "partwnd.hxx"
+#include <sfx2/sfxsids.hrc>
+#include "recfloat.hxx"
+#include <sfx2/objsh.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/objface.hxx>
+
+//===================================================================
+
+void SfxApplication::Registrations_Impl()
+{
+ // Interfaces
+ SfxApplication::RegisterInterface();
+ SfxModule::RegisterInterface();
+ SfxViewFrame::RegisterInterface();
+ SfxObjectShell::RegisterInterface();
+ SfxViewShell::RegisterInterface();
+
+ // ChildWindows
+ SfxRecordingFloatWrapper_Impl::RegisterChildWindow();
+ SfxNavigatorWrapper::RegisterChildWindow( FALSE, NULL, SFX_CHILDWIN_NEVERHIDE );
+ SfxPartChildWnd_Impl::RegisterChildWindow();
+ SfxTemplateDialogWrapper::RegisterChildWindow(TRUE);
+ SfxDockingWrapper::RegisterChildWindow();
+
+ // Controller
+ SfxToolBoxControl::RegisterControl(SID_REPEAT);
+ SfxURLToolBoxControl_Impl::RegisterControl(SID_OPENURL);
+ SfxAppToolBoxControl_Impl::RegisterControl( SID_NEWDOCDIRECT );
+ SfxAppToolBoxControl_Impl::RegisterControl( SID_AUTOPILOTMENU );
+};
+
+//--------------------------------------------------------------------
+
+void SfxApplication::RegisterToolBoxControl_Impl( SfxModule *pMod, SfxTbxCtrlFactory *pFact )
+{
+ if ( pMod )
+ {
+ pMod->RegisterToolBoxControl( pFact );
+ return;
+ }
+
+#ifdef DBG_UTIL
+ for ( USHORT n=0; n<pAppData_Impl->pTbxCtrlFac->Count(); n++ )
+ {
+ SfxTbxCtrlFactory *pF = (*pAppData_Impl->pTbxCtrlFac)[n];
+ if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
+ (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
+ {
+ DBG_WARNING("TbxController-Registrierung ist nicht eindeutig!");
+ }
+ }
+#endif
+
+ pAppData_Impl->pTbxCtrlFac->C40_INSERT( SfxTbxCtrlFactory, pFact, pAppData_Impl->pTbxCtrlFac->Count() );
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::RegisterStatusBarControl_Impl( SfxModule *pMod, SfxStbCtrlFactory *pFact )
+{
+ if ( pMod )
+ {
+ pMod->RegisterStatusBarControl( pFact );
+ return;
+ }
+
+#ifdef DBG_UTIL
+ for ( USHORT n=0; n<pAppData_Impl->pStbCtrlFac->Count(); n++ )
+ {
+ SfxStbCtrlFactory *pF = (*pAppData_Impl->pStbCtrlFac)[n];
+ if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
+ (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
+ {
+ DBG_WARNING("StbController-Registrierung ist nicht eindeutig!");
+ }
+ }
+#endif
+
+ pAppData_Impl->pStbCtrlFac->C40_INSERT( SfxStbCtrlFactory, pFact, pAppData_Impl->pStbCtrlFac->Count() );
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::RegisterMenuControl_Impl( SfxModule *pMod, SfxMenuCtrlFactory *pFact )
+{
+ if ( pMod )
+ {
+ pMod->RegisterMenuControl( pFact );
+ return;
+ }
+
+#ifdef DBG_UTIL
+ for ( USHORT n=0; n<pAppData_Impl->pMenuCtrlFac->Count(); n++ )
+ {
+ SfxMenuCtrlFactory *pF = (*pAppData_Impl->pMenuCtrlFac)[n];
+ if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
+ (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
+ {
+ DBG_WARNING("MenuController-Registrierung ist nicht eindeutig!");
+ }
+ }
+#endif
+
+ pAppData_Impl->pMenuCtrlFac->C40_INSERT( SfxMenuCtrlFactory, pFact, pAppData_Impl->pMenuCtrlFac->Count() );
+}
diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx
new file mode 100644
index 000000000000..c1858c5b33fb
--- /dev/null
+++ b/sfx2/source/appl/appserv.cxx
@@ -0,0 +1,1347 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/frame/DispatchResultEvent.hpp>
+#include <com/sun/star/frame/DispatchResultState.hpp>
+#include <com/sun/star/task/XJobExecutor.hpp>
+#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/frame/XDispatchHelper.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/util/CloseVetoException.hpp>
+#include <com/sun/star/frame/XLayoutManager.hpp>
+#include <com/sun/star/document/XEmbeddedScripts.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/system/XSystemShellExecute.hpp>
+#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
+#include <com/sun/star/system/SystemShellExecuteException.hpp>
+
+#include <comphelper/processfactory.hxx>
+#include <comphelper/storagehelper.hxx>
+#include "comphelper/configurationhelper.hxx"
+
+#include <svtools/addresstemplate.hxx>
+#include <svl/visitem.hxx>
+#include <unotools/intlwrapper.hxx>
+
+#include <unotools/configmgr.hxx>
+#include <tools/config.hxx>
+#include <tools/diagnose_ex.h>
+#include <vcl/msgbox.hxx>
+#include <svl/intitem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <basic/sbstar.hxx>
+#include <basic/basmgr.hxx>
+#include <basic/basrdll.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+#include <vcl/help.hxx>
+#include <vcl/stdtext.hxx>
+#include <rtl/ustrbuf.hxx>
+
+#include <unotools/pathoptions.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <unotools/regoptions.hxx>
+#include <svtools/helpopt.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <tools/shl.hxx>
+#include <unotools/bootstrap.hxx>
+#include <vos/process.hxx>
+#include <rtl/bootstrap.hxx>
+#include <cppuhelper/exc_hlp.hxx>
+#include <rtl/ustrbuf.hxx>
+
+#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+#include "about.hxx"
+#include "frmload.hxx"
+#include "referers.hxx"
+#include <sfx2/app.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/msg.hxx>
+#include <sfx2/objface.hxx>
+#include <sfx2/objitem.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/hintpost.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+#include "docvor.hxx"
+#include <sfx2/new.hxx>
+#include <sfx2/templdlg.hxx>
+#include "sfxtypes.hxx"
+#include "sfxbasic.hxx"
+#include <sfx2/tabdlg.hxx>
+#include "arrdecl.hxx"
+#include "fltfnc.hxx"
+#include <sfx2/sfx.hrc>
+#include "app.hrc"
+#include <sfx2/passwd.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "arrdecl.hxx"
+#include <sfx2/childwin.hxx>
+#include "appdata.hxx"
+#include <sfx2/macrconf.hxx>
+#include "sfx2/minfitem.hxx"
+#include <sfx2/event.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "sfxpicklist.hxx"
+#include "imestatuswindow.hxx"
+#include <sfx2/sfxdlg.hxx>
+#include <sfx2/dialogs.hrc>
+#include "sorgitm.hxx"
+#include "sfx2/sfxhelp.hxx"
+#include <tools/svlibrary.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::script;
+using namespace ::com::sun::star::system;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::document;
+
+namespace css = com::sun::star;
+
+//-------------------------------------------------------------------------
+long QuitAgain_Impl( void* pObj, void* pArg )
+{
+ SfxApplication* pApp = (SfxApplication*)pObj;
+ Timer* pTimer = (Timer*)pArg;
+ delete pTimer;
+ pApp->GetDispatcher_Impl()->Execute( SID_QUITAPP, SFX_CALLMODE_ASYNCHRON );
+ return 0;
+}
+
+void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
+{
+ DBG_MEMTEST();
+ FASTBOOL bDone = FALSE;
+ switch ( rReq.GetSlot() )
+ {
+ case SID_SETOPTIONS:
+ {
+ if( rReq.GetArgs() )
+ SetOptions_Impl( *rReq.GetArgs() );
+ break;
+ }
+
+ case SID_QUITAPP:
+ case SID_EXITANDRETURN:
+ case SID_LOGOUT:
+ {
+ // protect against reentrant calls
+ if ( pAppData_Impl->bInQuit )
+ return;
+
+ if ( rReq.GetSlot() == SID_LOGOUT )
+ {
+ for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
+ pObjSh; pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
+ {
+ if ( !pObjSh->IsModified() )
+ continue;
+
+ SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjSh );
+ if ( !pFrame || !pFrame->GetWindow().IsReallyVisible() )
+ continue;
+
+ if ( pObjSh->PrepareClose(2) )
+ pObjSh->SetModified( FALSE );
+ else
+ return;
+ }
+
+ String aName = String::CreateFromAscii("vnd.sun.star.cmd:logout");
+ SfxStringItem aNameItem( SID_FILE_NAME, aName );
+ SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE( "private/user" ) );
+ pAppData_Impl->pAppDispat->Execute( SID_OPENDOC, SFX_CALLMODE_SLOT, &aNameItem, &aReferer, 0L );
+ return;
+ }
+
+ // aus verschachtelten Requests nach 100ms nochmal probieren
+ if( Application::GetDispatchLevel() > 1 )
+ {
+ /* Dont save the request for closing the application and try it later
+ again. This is an UI bound functionality ... and the user will try it again
+ if the dialog is closed. But we shouldnt close the application automaticly
+ if this dialog is closed by the user ...
+ So we ignore this request now and wait for a new user decision.
+ */
+ DBG_TRACE1( "QueryExit => FALSE (DispatchLevel == %u)", Application::GetDispatchLevel() );
+ return;
+ }
+
+ // block reentrant calls
+ pAppData_Impl->bInQuit = TRUE;
+ Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
+
+ rReq.ForgetAllArgs();
+
+ // if terminate() failed, pAppData_Impl->bInQuit will now be FALSE, allowing further calls of SID_QUITAPP
+ BOOL bTerminated = xDesktop->terminate();
+ if (!bTerminated)
+ // if terminate() was successful, SfxApplication is now dead!
+ pAppData_Impl->bInQuit = FALSE;
+
+ // Returnwert setzten, ggf. terminieren
+ rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bTerminated ) );
+ return;
+ }
+
+ case SID_CONFIG:
+ case SID_TOOLBOXOPTIONS:
+ case SID_CONFIGSTATUSBAR:
+ case SID_CONFIGMENU:
+ case SID_CONFIGACCEL:
+ case SID_CONFIGEVENT:
+ {
+ SfxAbstractDialogFactory* pFact =
+ SfxAbstractDialogFactory::Create();
+
+ if ( pFact )
+ {
+ SFX_REQUEST_ARG(rReq, pStringItem,
+ SfxStringItem, SID_CONFIG, sal_False);
+
+ SfxItemSet aSet(
+ GetPool(), SID_CONFIG, SID_CONFIG );
+
+ if ( pStringItem )
+ {
+ aSet.Put( SfxStringItem(
+ SID_CONFIG, pStringItem->GetValue() ) );
+ }
+
+ Reference< XFrame > xFrame;
+ const SfxItemSet* pIntSet = rReq.GetInternalArgs_Impl();
+ SFX_ITEMSET_ARG( pIntSet, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, FALSE );
+ if ( pFrameItem )
+ xFrame = pFrameItem->GetFrame();
+
+ SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog(
+ RID_SVXDLG_CUSTOMIZE,
+ NULL, &aSet, xFrame );
+
+ if ( pDlg )
+ {
+ const short nRet = pDlg->Execute();
+
+ if ( nRet )
+ bDone = TRUE;
+
+ delete pDlg;
+ }
+ }
+ break;
+ }
+
+ case SID_CLOSEDOCS:
+ case SID_CLOSEWINS:
+ {
+
+ Reference < XFramesSupplier > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
+ Reference< XIndexAccess > xTasks( xDesktop->getFrames(), UNO_QUERY );
+ if ( !xTasks.is() )
+ break;
+
+ sal_Int32 n=0;
+ do
+ {
+ if ( xTasks->getCount() <= n )
+ break;
+
+ Any aAny = xTasks->getByIndex(n);
+ Reference < XCloseable > xTask;
+ aAny >>= xTask;
+ try
+ {
+ xTask->close(sal_True);
+ n++;
+ }
+ catch( CloseVetoException& )
+ {
+ }
+ }
+ while( sal_True );
+
+ BOOL bOk = ( n == 0);
+ rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
+ bDone = TRUE;
+ break;
+ }
+
+ case SID_SAVEDOCS:
+ {
+ BOOL bOK = TRUE;
+ BOOL bTmpDone = TRUE;
+ for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
+ pObjSh;
+ pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
+ {
+ SfxRequest aReq( SID_SAVEDOC, 0, pObjSh->GetPool() );
+ if ( pObjSh->IsModified() )
+ {
+ pObjSh->ExecuteSlot( aReq );
+ SfxBoolItem *pItem = PTR_CAST( SfxBoolItem, aReq.GetReturnValue() );
+ bTmpDone = aReq.IsDone();
+ if ( !pItem || !pItem->GetValue() )
+ bOK = FALSE;
+ }
+ }
+
+ rReq.SetReturnValue( SfxBoolItem( 0, bOK ) );
+ rReq.Done();
+ break;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_HELPINDEX:
+ case SID_HELP_SUPPORTPAGE:
+ {
+ Help* pHelp = Application::GetHelp();
+ if ( pHelp )
+ {
+ if ( rReq.GetSlot() == SID_HELP_SUPPORTPAGE )
+ {
+ // show Support page with new URL
+ String sHelpURL = SfxHelp::CreateHelpURL( String::CreateFromAscii(".uno:HelpSupport"), String() );
+ String sParams = sHelpURL.Copy( sHelpURL.Search( '?' ) );
+ sHelpURL = String::CreateFromAscii("vnd.sun.star.help://shared/text/shared/05/00000001.xhp");
+ sHelpURL += sParams;
+ sHelpURL += String::CreateFromAscii("&UseDB=no");
+ pHelp->Start( sHelpURL, NULL );
+ }
+ else
+ pHelp->Start( String::CreateFromAscii(".uno:HelpIndex"), NULL ); // show start page
+ bDone = TRUE;
+ }
+ break;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_HELPTIPS:
+ {
+ // Parameter aus werten
+ SFX_REQUEST_ARG(rReq, pOnItem, SfxBoolItem, SID_HELPTIPS, FALSE);
+ bool bOn = pOnItem
+ ? ((SfxBoolItem*)pOnItem)->GetValue()
+ : !Help::IsQuickHelpEnabled();
+
+ // ausf"uhren
+ if ( bOn )
+ Help::EnableQuickHelp();
+ else
+ Help::DisableQuickHelp();
+ SvtHelpOptions().SetHelpTips( bOn );
+ Invalidate(SID_HELPTIPS);
+ bDone = TRUE;
+
+ // ggf. recorden
+ if ( !rReq.IsAPI() )
+ rReq.AppendItem( SfxBoolItem( SID_HELPTIPS, bOn) );
+ break;
+ }
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_EXTENDEDHELP:
+ {
+ Help::StartExtHelp();
+ break;
+ }
+ case SID_HELPBALLOONS:
+ {
+ // Parameter auswerten
+ SFX_REQUEST_ARG(rReq, pOnItem, SfxBoolItem, SID_HELPBALLOONS, FALSE);
+ bool bOn = pOnItem
+ ? ((SfxBoolItem*)pOnItem)->GetValue()
+ : !Help::IsBalloonHelpEnabled();
+
+ // ausf"uhren
+ if ( bOn )
+ Help::EnableBalloonHelp();
+ else
+ Help::DisableBalloonHelp();
+ SvtHelpOptions().SetExtendedHelp( bOn );
+ Invalidate(SID_HELPBALLOONS);
+ bDone = TRUE;
+
+ // ggf. recorden
+ if ( !rReq.IsAPI() )
+ rReq.AppendItem( SfxBoolItem( SID_HELPBALLOONS, bOn) );
+ break;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_HELP_PI:
+ {
+ SvtHelpOptions aHelpOpt;
+ SFX_REQUEST_ARG(rReq, pOnItem, SfxBoolItem, SID_HELP_PI, FALSE);
+ sal_Bool bOn = pOnItem
+ ? ((SfxBoolItem*)pOnItem)->GetValue()
+ : !aHelpOpt.IsHelpAgentAutoStartMode();
+ aHelpOpt.SetHelpAgentAutoStartMode( bOn );
+ Invalidate(SID_HELP_PI);
+ bDone = TRUE;
+ break;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_ABOUT:
+ {
+ const String sCWSSchema( String::CreateFromAscii( "[CWS:" ) );
+ rtl::OUString sDefault;
+ String sBuildId( utl::Bootstrap::getBuildIdData( sDefault ) );
+ OSL_ENSURE( sBuildId.Len() > 0, "No BUILDID in bootstrap file" );
+ if ( sBuildId.Len() > 0 && sBuildId.Search( sCWSSchema ) == STRING_NOTFOUND )
+ {
+ // no cws part in brand buildid -> try basis buildid
+ rtl::OUString sBasisBuildId( DEFINE_CONST_OUSTRING(
+ "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version") ":buildid}" ) );
+ rtl::Bootstrap::expandMacros( sBasisBuildId );
+ sal_Int32 nIndex = sBasisBuildId.indexOf( sCWSSchema );
+ if ( nIndex != -1 )
+ sBuildId += String( sBasisBuildId.copy( nIndex ) );
+ }
+
+ String sProductSource( utl::Bootstrap::getProductSource( sDefault ) );
+ OSL_ENSURE( sProductSource.Len() > 0, "No ProductSource in bootstrap file" );
+
+ // the product source is something like "DEV300", where the
+ // build id is something like "300m12(Build:12345)". For better readability,
+ // strip the duplicate UPD ("300").
+ if ( sProductSource.Len() )
+ {
+ bool bMatchingUPD =
+ ( sProductSource.Len() >= 3 )
+ && ( sBuildId.Len() >= 3 )
+ && ( sProductSource.Copy( sProductSource.Len() - 3 ) == sBuildId.Copy( 0, 3 ) );
+ OSL_ENSURE( bMatchingUPD, "BUILDID and ProductSource do not match in their UPD" );
+ if ( bMatchingUPD )
+ sProductSource = sProductSource.Copy( 0, sProductSource.Len() - 3 );
+
+ // prepend the product source
+ sBuildId.Insert( sProductSource, 0 );
+ }
+
+ // --> PB 2008-10-30 #i94693#
+ /* if the build ids of the basis or ure layer are different from the build id
+ * of the brand layer then show them */
+ rtl::OUString aBasisProductBuildId( DEFINE_CONST_OUSTRING(
+ "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version") ":ProductBuildid}" ) );
+ rtl::Bootstrap::expandMacros( aBasisProductBuildId );
+ rtl::OUString aUREProductBuildId( DEFINE_CONST_OUSTRING(
+ "${$URE_BIN_DIR/" SAL_CONFIGFILE("version") ":ProductBuildid}" ) );
+ rtl::Bootstrap::expandMacros( aUREProductBuildId );
+ if ( sBuildId.Search( String( aBasisProductBuildId ) ) == STRING_NOTFOUND
+ || sBuildId.Search( String( aUREProductBuildId ) ) == STRING_NOTFOUND )
+ {
+ String sTemp( '-' );
+ sTemp += String( aBasisProductBuildId );
+ sTemp += '-';
+ sTemp += String( aUREProductBuildId );
+ sBuildId.Insert( sTemp, sBuildId.Search( ')' ) );
+ }
+ // <--
+
+ // the build id format is "milestone(build)[cwsname]". For readability, it would
+ // be nice to have some more spaces in there.
+ xub_StrLen nPos = 0;
+ if ( ( nPos = sBuildId.Search( sal_Unicode( '(' ) ) ) != STRING_NOTFOUND )
+ sBuildId.Insert( sal_Unicode( ' ' ), nPos );
+ if ( ( nPos = sBuildId.Search( sal_Unicode( '[' ) ) ) != STRING_NOTFOUND )
+ sBuildId.Insert( sal_Unicode( ' ' ), nPos );
+
+ // search for the resource of the about box
+ ResId aDialogResId( RID_DEFAULTABOUT, *pAppData_Impl->pLabelResMgr );
+ ResMgr* pResMgr = pAppData_Impl->pLabelResMgr;
+ if( ! pResMgr->IsAvailable( aDialogResId.SetRT( RSC_MODALDIALOG ) ) )
+ pResMgr = GetOffResManager_Impl();
+
+ aDialogResId.SetResMgr( pResMgr );
+ if ( !pResMgr->IsAvailable( aDialogResId ) )
+ {
+ DBG_ERRORFILE( "No RID_DEFAULTABOUT in label-resource-dll" );
+ }
+
+ // then show the about box
+ AboutDialog* pDlg = new AboutDialog( 0, aDialogResId, sBuildId );
+ pDlg->Execute();
+ delete pDlg;
+ bDone = TRUE;
+ break;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_ORGANIZER:
+ {
+ SfxTemplateOrganizeDlg *pDlg =
+ new SfxTemplateOrganizeDlg(NULL);
+ pDlg->Execute();
+ delete pDlg;
+ bDone = TRUE;
+ break;
+ }
+
+ case SID_TEMPLATE_ADDRESSBOKSOURCE:
+ {
+ svt::AddressBookSourceDialog aDialog(GetTopWindow(), ::comphelper::getProcessServiceFactory());
+ aDialog.Execute();
+ bDone = TRUE;
+ break;
+ }
+
+ case SID_BASICSTOP:
+ StarBASIC::Stop();
+ break;
+
+ case SID_BASICBREAK :
+ BASIC_DLL()->BasicBreak();
+ break;
+
+ case SID_CRASH :
+ {
+ // Provoke a crash:
+ char * crash = 0;
+ *crash = 0;
+ break;
+ }
+
+ case SID_SHOW_IME_STATUS_WINDOW:
+ if (pAppData_Impl->m_xImeStatusWindow->canToggle())
+ {
+ SfxBoolItem const * pItem = static_cast< SfxBoolItem const * >(
+ rReq.GetArg(SID_SHOW_IME_STATUS_WINDOW, false,
+ TYPE(SfxBoolItem)));
+ bool bShow = pItem == 0
+ ? !pAppData_Impl->m_xImeStatusWindow->isShowing()
+ : ( pItem->GetValue() == TRUE );
+ pAppData_Impl->m_xImeStatusWindow->show(bShow);
+ if (pItem == 0)
+ rReq.AppendItem(SfxBoolItem(SID_SHOW_IME_STATUS_WINDOW,
+ bShow));
+ }
+ bDone = true;
+ break;
+
+ case SID_AVAILABLE_TOOLBARS:
+ {
+ SfxStringItem const * pToolbarName = static_cast< SfxStringItem const *>(
+ rReq.GetArg(SID_AVAILABLE_TOOLBARS, false, TYPE(SfxStringItem)));
+
+ if ( pToolbarName )
+ {
+ com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame;
+ Reference < XFramesSupplier > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
+ xFrame = xDesktop->getActiveFrame();
+
+ Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
+ Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
+ aValue >>= xLayoutManager;
+ }
+ catch ( ::com::sun::star::uno::RuntimeException& e )
+ {
+ throw e;
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ }
+ }
+
+ if ( xLayoutManager.is() )
+ {
+ rtl::OUString aToolbarResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ));
+ rtl::OUStringBuffer aBuf( aToolbarResName );
+ aBuf.append( pToolbarName->GetValue() );
+
+ // Parameter auswerten
+ rtl::OUString aToolbarName( aBuf.makeStringAndClear() );
+ BOOL bShow( !xLayoutManager->isElementVisible( aToolbarName ));
+
+ if ( bShow )
+ {
+ xLayoutManager->createElement( aToolbarName );
+ xLayoutManager->showElement( aToolbarName );
+ }
+ else
+ xLayoutManager->hideElement( aToolbarName );
+ }
+ }
+
+ bDone = true;
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ if ( bDone )
+ rReq.Done();
+}
+
+//--------------------------------------------------------------------
+
+void SfxApplication::MiscState_Impl(SfxItemSet &rSet)
+{
+ DBG_MEMTEST();
+
+ LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ const USHORT *pRanges = rSet.GetRanges();
+ DBG_ASSERT(pRanges && *pRanges, "Set ohne Bereich");
+ while ( *pRanges )
+ {
+ for(USHORT nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
+ {
+ switch(nWhich)
+ {
+ case SID_TEMPLATE_ADDRESSBOKSOURCE:
+ if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE) )
+ rSet.Put(SfxVisibilityItem(nWhich, sal_False));
+ break;
+ case SID_EXITANDRETURN:
+ case SID_QUITAPP:
+ {
+ if ( pAppData_Impl->nDocModalMode )
+ rSet.DisableItem(nWhich);
+ else
+ rSet.Put(SfxStringItem(nWhich, String(SfxResId(STR_QUITAPP))));
+ break;
+ }
+
+ case SID_BASICSTOP:
+ if ( !StarBASIC::IsRunning() )
+ rSet.DisableItem(nWhich);
+ break;
+
+ case SID_HELPTIPS:
+ {
+ rSet.Put( SfxBoolItem( SID_HELPTIPS, Help::IsQuickHelpEnabled() ) );
+ }
+ break;
+ case SID_HELPBALLOONS:
+ {
+ rSet.Put( SfxBoolItem( SID_HELPBALLOONS, Help::IsBalloonHelpEnabled() ) );
+ }
+ break;
+ case SID_HELP_PI:
+ {
+ rSet.Put( SfxBoolItem( SID_HELP_PI, SvtHelpOptions().IsHelpAgentAutoStartMode() ) );
+ }
+ break;
+
+ case SID_EXTENDEDHELP:
+ {
+ }
+ break;
+
+ case SID_CLOSEDOCS:
+ case SID_CLOSEWINS:
+ {
+ Reference < XFramesSupplier > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
+ Reference< XIndexAccess > xTasks( xDesktop->getFrames(), UNO_QUERY );
+ if ( !xTasks.is() || !xTasks->getCount() )
+ rSet.DisableItem(nWhich);
+ break;
+ }
+
+ case SID_SAVEDOCS:
+ {
+ BOOL bModified = FALSE;
+ for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
+ pObjSh;
+ pObjSh = SfxObjectShell::GetNext( *pObjSh ) )
+ {
+ if ( pObjSh->IsModified() )
+ {
+ bModified = TRUE;
+ break;
+ }
+ }
+
+ if ( !bModified )
+ rSet.DisableItem( nWhich );
+ break;
+ }
+
+ case SID_SHOW_IME_STATUS_WINDOW:
+ if (pAppData_Impl->m_xImeStatusWindow->canToggle())
+ rSet.Put(SfxBoolItem(
+ SID_SHOW_IME_STATUS_WINDOW,
+ pAppData_Impl->m_xImeStatusWindow->
+ isShowing()));
+ else
+ rSet.DisableItem(SID_SHOW_IME_STATUS_WINDOW);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ ++pRanges;
+ }
+}
+
+static const ::rtl::OUString& getProductRegistrationServiceName( )
+{
+ static ::rtl::OUString s_sServiceName = ::rtl::OUString::createFromAscii( "com.sun.star.setup.ProductRegistration" );
+ return s_sServiceName;
+}
+
+typedef rtl_uString* (SAL_CALL *basicide_choose_macro)(XModel*, BOOL, rtl_uString*);
+typedef void (SAL_CALL *basicide_macro_organizer)( INT16 );
+
+#define DOSTRING( x ) #x
+#define STRING( x ) DOSTRING( x )
+
+extern "C" { static void SAL_CALL thisModule() {} }
+
+::rtl::OUString ChooseMacro( const Reference< XModel >& rxLimitToDocument, BOOL bChooseOnly, const ::rtl::OUString& rMacroDesc = ::rtl::OUString() )
+{
+ // get basctl dllname
+ static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) );
+
+ // load module
+ oslModule handleMod = osl_loadModuleRelative(
+ &thisModule, aLibName.pData, 0 );
+
+ // get symbol
+ ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_choose_macro" ) );
+ basicide_choose_macro pSymbol = (basicide_choose_macro) osl_getFunctionSymbol( handleMod, aSymbol.pData );
+
+ // call basicide_choose_macro in basctl
+ rtl_uString* pScriptURL = pSymbol( rxLimitToDocument.get(), bChooseOnly, rMacroDesc.pData );
+ ::rtl::OUString aScriptURL( pScriptURL );
+ rtl_uString_release( pScriptURL );
+ return aScriptURL;
+}
+
+void MacroOrganizer( INT16 nTabId )
+{
+ // get basctl dllname
+ static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "basctl" ) ) );
+
+ // load module
+ oslModule handleMod = osl_loadModuleRelative(
+ &thisModule, aLibName.pData, 0 );
+
+ // get symbol
+ ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "basicide_macro_organizer" ) );
+ basicide_macro_organizer pSymbol = (basicide_macro_organizer) osl_getFunctionSymbol( handleMod, aSymbol.pData );
+
+ // call basicide_macro_organizer in basctl
+ pSymbol( nTabId );
+}
+
+#define RID_ERRBOX_MODULENOTINSTALLED (RID_OFA_START + 72)
+
+ResMgr* SfxApplication::GetOffResManager_Impl()
+{
+ if ( !pAppData_Impl->pOfaResMgr )
+ pAppData_Impl->pOfaResMgr = CreateResManager( "ofa");
+ return pAppData_Impl->pOfaResMgr;
+}
+
+namespace
+{
+ Window* lcl_getDialogParent( const Reference< XFrame >& _rxFrame, Window* _pFallback )
+ {
+ if ( !_rxFrame.is() )
+ return _pFallback;
+
+ try
+ {
+ Reference< awt::XWindow > xContainerWindow( _rxFrame->getContainerWindow(), UNO_SET_THROW );
+ Window* pWindow = VCLUnoHelper::GetWindow( xContainerWindow );
+ OSL_ENSURE( pWindow, "lcl_getDialogParent: cool, somebody implemented a VCL-less toolkit!" );
+
+ if ( pWindow )
+ return pWindow->GetSystemWindow();
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return _pFallback;
+ }
+
+ const ::rtl::OUString& lcl_getBasicIDEServiceName()
+ {
+ static const ::rtl::OUString s_sBasicName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.BasicIDE" ) );
+ return s_sBasicName;
+ }
+
+ SfxViewFrame* lcl_getBasicIDEViewFrame( SfxObjectShell* i_pBasicIDE )
+ {
+ SfxViewFrame* pView = SfxViewFrame::GetFirst( i_pBasicIDE );
+ while ( pView )
+ {
+ if ( pView->GetObjectShell()->GetFactory().GetDocumentServiceName() == lcl_getBasicIDEServiceName() )
+ break;
+ pView = SfxViewFrame::GetNext( *pView, i_pBasicIDE );
+ }
+ return pView;
+ }
+ Reference< XFrame > lcl_findStartModuleFrame( const ::comphelper::ComponentContext& i_rContext )
+ {
+ try
+ {
+ Reference < XFramesSupplier > xSupplier( i_rContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
+ Reference < XIndexAccess > xContainer( xSupplier->getFrames(), UNO_QUERY_THROW );
+
+ Reference< XModuleManager > xCheck( i_rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW );
+
+ sal_Int32 nCount = xContainer->getCount();
+ for ( sal_Int32 i=0; i<nCount; ++i )
+ {
+ try
+ {
+ Reference < XFrame > xFrame( xContainer->getByIndex(i), UNO_QUERY_THROW );
+ ::rtl::OUString sModule = xCheck->identify( xFrame );
+ if ( sModule.equalsAscii( "com.sun.star.frame.StartModule" ) )
+ return xFrame;
+ }
+ catch( const UnknownModuleException& )
+ {
+ // silence
+ }
+ catch(const Exception&)
+ {
+ // re-throw, caught below
+ throw;
+ }
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return NULL;
+ }
+}
+
+static ::rtl::OUString getConfigurationStringValue(
+ const ::rtl::OUString& rPackage,
+ const ::rtl::OUString& rRelPath,
+ const ::rtl::OUString& rKey,
+ const ::rtl::OUString& rDefaultValue )
+{
+ ::rtl::OUString aDefVal( rDefaultValue );
+
+ try
+ {
+ ::comphelper::ConfigurationHelper::readDirectKey(
+ comphelper::getProcessServiceFactory(),
+ rPackage,
+ rRelPath,
+ rKey,
+ ::comphelper::ConfigurationHelper::E_READONLY) >>= aDefVal;
+ }
+ catch(const com::sun::star::uno::RuntimeException& exRun)
+ { throw exRun; }
+ catch(const com::sun::star::uno::Exception&)
+ {}
+
+ return aDefVal;
+}
+
+void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
+{
+ DBG_MEMTEST();
+ switch ( rReq.GetSlot() )
+ {
+ case SID_OPTIONS_TREEDIALOG:
+ {
+ String sPageURL;
+ SFX_REQUEST_ARG( rReq, pURLItem, SfxStringItem, SID_OPTIONS_PAGEURL, sal_False );
+ if ( pURLItem )
+ sPageURL = pURLItem->GetValue();
+ const SfxItemSet* pArgs = rReq.GetInternalArgs_Impl();
+ const SfxPoolItem* pItem = NULL;
+ Reference < XFrame > xFrame;
+ if ( pArgs && pArgs->GetItemState( SID_FILLFRAME, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ OSL_ENSURE( pItem->ISA( SfxUnoFrameItem ), "SfxApplication::OfaExec_Impl: XFrames are to be transported via SfxUnoFrameItem by now!" );
+ xFrame = static_cast< const SfxUnoFrameItem*>( pItem )->GetFrame();
+ }
+ SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
+ if ( pFact )
+ {
+ VclAbstractDialog* pDlg =
+ pFact->CreateFrameDialog( NULL, xFrame, rReq.GetSlot(), sPageURL );
+ pDlg->Execute();
+ delete pDlg;
+ SfxViewFrame* pView = SfxViewFrame::GetFirst();
+ while ( pView )
+ {
+ pView->GetBindings().InvalidateAll(FALSE);
+ pView = SfxViewFrame::GetNext( *pView );
+ }
+ }
+ break;
+ }
+
+ case SID_MORE_DICTIONARIES:
+ {
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xSMGR =
+ ::comphelper::getProcessServiceFactory();
+ uno::Reference< css::system::XSystemShellExecute > xSystemShell(
+ xSMGR->createInstance( DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute" ) ),
+ uno::UNO_QUERY_THROW );
+
+ // read repository URL from configuration
+ ::rtl::OUString sTemplRepoURL =
+ getConfigurationStringValue(
+ ::rtl::OUString::createFromAscii("org.openoffice.Office.Common"),
+ ::rtl::OUString::createFromAscii("Dictionaries"),
+ ::rtl::OUString::createFromAscii("RepositoryURL"),
+ ::rtl::OUString());
+
+ if ( xSystemShell.is() && sTemplRepoURL.getLength() > 0 )
+ {
+ ::rtl::OUStringBuffer aURLBuf( sTemplRepoURL );
+ aURLBuf.appendAscii( "?" );
+ aURLBuf.appendAscii( "lang=" );
+
+ // read locale from configuration
+ ::rtl::OUString sLocale = getConfigurationStringValue(
+ ::rtl::OUString::createFromAscii("org.openoffice.Setup"),
+ ::rtl::OUString::createFromAscii("L10N"),
+ ::rtl::OUString::createFromAscii("ooLocale"),
+ ::rtl::OUString::createFromAscii("en-US"));
+
+ aURLBuf.append( sLocale );
+ xSystemShell->execute(
+ aURLBuf.makeStringAndClear(),
+ ::rtl::OUString(),
+ css::system::SystemShellExecuteFlags::DEFAULTS );
+ }
+ }
+ catch( const ::com::sun::star::uno::Exception& )
+ {
+ DBG_ERRORFILE( "SfxApplication::OfaExec_Impl(SID_MORE_DICTIONARIES): caught an exception!" );
+ }
+ break;
+ }
+
+ case SID_ONLINE_REGISTRATION:
+ {
+ try
+ {
+ // create the ProductRegistration component
+ Reference< com::sun::star::lang::XMultiServiceFactory > xORB( ::comphelper::getProcessServiceFactory() );
+ Reference< com::sun::star::task::XJobExecutor > xProductRegistration;
+ if ( xORB.is() )
+ xProductRegistration = xProductRegistration.query( xORB->createInstance( getProductRegistrationServiceName() ) );
+ DBG_ASSERT( xProductRegistration.is(), "OfficeApplication::ExecuteApp_Impl: could not create the service!" );
+
+ // tell it that the user wants to register
+ if ( xProductRegistration.is() )
+ {
+ xProductRegistration->trigger( ::rtl::OUString::createFromAscii( "RegistrationRequired" ) );
+ }
+ }
+ catch( const ::com::sun::star::uno::Exception& )
+ {
+ DBG_ERROR( "OfficeApplication::ExecuteApp_Impl(SID_ONLINE_REGISTRATION): caught an exception!" );
+ }
+ }
+ break;
+
+ case SID_BASICIDE_APPEAR:
+ {
+ SfxViewFrame* pView = lcl_getBasicIDEViewFrame( NULL );
+ if ( !pView )
+ {
+ SfxObjectShell* pBasicIDE = SfxObjectShell::CreateObject( lcl_getBasicIDEServiceName() );
+ pBasicIDE->DoInitNew( 0 );
+ pBasicIDE->SetModified( FALSE );
+ try
+ {
+ // load the Basic IDE via direct access to the SFX frame loader. A generic loadComponentFromURL
+ // (which could be done via SfxViewFrame::LoadDocumentIntoFrame) is not feasible here, since the Basic IDE
+ // does not really play nice with the framework's concept. For instance, it is a "singleton document",
+ // which conflicts, at the latest, with the framework's concept of loading into _blank frames.
+ // So, since we know that our frame loader can handle it, we skip the generic framework loader
+ // mechanism, and the type detection (which doesn't know about the Basic IDE).
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ Reference< XSynchronousFrameLoader > xLoader( aContext.createComponent(
+ SfxFrameLoader_Impl::impl_getStaticImplementationName() ), UNO_QUERY_THROW );
+ ::comphelper::NamedValueCollection aLoadArgs;
+ aLoadArgs.put( "Model", pBasicIDE->GetModel() );
+ aLoadArgs.put( "URL", ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/sbasic" ) ) );
+
+ Reference< XFrame > xTargetFrame( lcl_findStartModuleFrame( aContext ) );
+ if ( !xTargetFrame.is() )
+ xTargetFrame = SfxFrame::CreateBlankFrame();
+ ENSURE_OR_THROW( xTargetFrame.is(), "could not obtain a frameto load the Basic IDE into!" );
+
+ xLoader->load( aLoadArgs.getPropertyValues(), xTargetFrame );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
+ pView = lcl_getBasicIDEViewFrame( pBasicIDE );
+ if ( pView )
+ pView->SetName( String( RTL_CONSTASCII_USTRINGPARAM( "BASIC:1" ) ) );
+ }
+
+ if ( pView )
+ pView->GetFrame().Appear();
+
+ const SfxItemSet* pArgs = rReq.GetArgs();
+ if ( pArgs && pView )
+ {
+ SfxViewShell* pViewShell = pView->GetViewShell();
+ SfxObjectShell* pObjShell = pView->GetObjectShell();
+ if ( pViewShell && pObjShell )
+ {
+ SfxRequest aReq( SID_BASICIDE_SHOWWINDOW, SFX_CALLMODE_SYNCHRON, pObjShell->GetPool() );
+ aReq.SetArgs( *pArgs );
+ pViewShell->ExecuteSlot( aReq );
+ }
+ }
+
+ rReq.Done();
+ }
+ break;
+
+ case SID_BASICCHOOSER:
+ {
+ const SfxItemSet* pArgs = rReq.GetArgs();
+ const SfxPoolItem* pItem;
+ BOOL bChooseOnly = FALSE;
+ Reference< XModel > xLimitToModel;
+ if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_RECORDMACRO, sal_False, &pItem) )
+ {
+ BOOL bRecord = ((SfxBoolItem*)pItem)->GetValue();
+ if ( bRecord )
+ {
+ // !Hack
+ bChooseOnly = FALSE;
+ SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
+ OSL_ENSURE( pCurrentShell, "macro recording outside an SFX document?" );
+ if ( pCurrentShell )
+ xLimitToModel = pCurrentShell->GetModel();
+ }
+ }
+
+ rReq.SetReturnValue( SfxStringItem( rReq.GetSlot(), ChooseMacro( xLimitToModel, bChooseOnly ) ) );
+ rReq.Done();
+ }
+ break;
+
+ case SID_MACROORGANIZER:
+ {
+ OSL_TRACE("handling SID_MACROORGANIZER");
+ const SfxItemSet* pArgs = rReq.GetArgs();
+ const SfxPoolItem* pItem;
+ INT16 nTabId = 0;
+ if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_MACROORGANIZER, sal_False, &pItem) )
+ {
+ nTabId = ((SfxUInt16Item*)pItem)->GetValue();
+ }
+
+ SfxApplication::MacroOrganizer( nTabId );
+ rReq.Done();
+ }
+ break;
+
+ case SID_RUNMACRO:
+ {
+ SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
+ OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
+
+ Reference< XFrame > xFrame;
+ const SfxItemSet* pIntSet = rReq.GetInternalArgs_Impl();
+ SFX_ITEMSET_ARG( pIntSet, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, FALSE );
+ if ( pFrameItem )
+ xFrame = pFrameItem->GetFrame();
+
+ if ( !xFrame.is() )
+ {
+ const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+ if ( pViewFrame )
+ xFrame = pViewFrame->GetFrame().GetFrameInterface();
+ }
+
+ do // artificial loop for flow control
+ {
+ AbstractScriptSelectorDialog* pDlg = pFact->CreateScriptSelectorDialog(
+ lcl_getDialogParent( xFrame, GetTopWindow() ), FALSE, xFrame );
+ OSL_ENSURE( pDlg, "SfxApplication::OfaExec_Impl( SID_RUNMACRO ): no dialog!" );
+ if ( !pDlg )
+ break;
+ pDlg->SetRunLabel();
+
+ short nDialogResult = pDlg->Execute();
+ if ( !nDialogResult )
+ break;
+
+ Sequence< Any > args;
+ Sequence< sal_Int16 > outIndex;
+ Sequence< Any > outArgs;
+ Any ret;
+
+ Reference< XInterface > xScriptContext;
+
+ Reference< XController > xController;
+ if ( xFrame.is() )
+ xController = xFrame->getController();
+ if ( xController.is() )
+ xScriptContext = xController->getModel();
+ if ( !xScriptContext.is() )
+ xScriptContext = xController;
+
+ SfxObjectShell::CallXScript( xScriptContext, pDlg->GetScriptURL(), args, ret, outIndex, outArgs );
+ }
+ while ( false );
+ rReq.Done();
+ }
+ break;
+
+ case SID_SCRIPTORGANIZER:
+ {
+ SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
+ OSL_TRACE("SfxApplication::OfaExec_Impl: case ScriptOrg");
+ const SfxItemSet* pArgs = rReq.GetArgs();
+ const SfxPoolItem* pItem;
+ String aLanguage;
+ if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_SCRIPTORGANIZER, sal_False, &pItem) )
+ {
+ aLanguage = ((SfxScriptOrganizerItem*)pItem)->getLanguage();
+ }
+
+ ::rtl::OUString aLang( aLanguage );
+ OSL_TRACE("SfxApplication::OfaExec_Impl: about to create dialog for: %s", ::rtl::OUStringToOString( aLang , RTL_TEXTENCODING_ASCII_US ).pData->buffer);
+ // not sure about the Window*
+ VclAbstractDialog* pDlg = pFact->CreateSvxScriptOrgDialog( GetTopWindow(), aLanguage );
+ if( pDlg )
+ {
+ pDlg->Execute();
+ }
+ else
+ {
+ OSL_TRACE("no dialog!!!");
+ }
+ rReq.Done();
+ }
+ break;
+
+ case SID_OFFICE_CHECK_PLZ:
+ {
+ sal_Bool bRet = sal_False;
+ SFX_REQUEST_ARG(rReq, pStringItem, SfxStringItem, rReq.GetSlot(), sal_False);
+
+ if ( pStringItem )
+ {
+ String aPLZ = pStringItem->GetValue();
+ bRet = TRUE /*!!!SfxIniManager::CheckPLZ( aPLZ )*/;
+ }
+ else
+ SbxBase::SetError( SbxERR_WRONG_ARGS );
+ rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bRet ) );
+ }
+ break;
+
+ case SID_AUTO_CORRECT_DLG:
+ {
+ SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
+ if ( pFact )
+ {
+ SfxItemSet aSet(GetPool(), SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG);
+ const SfxPoolItem* pItem=NULL;
+ const SfxItemSet* pSet = rReq.GetArgs();
+ SfxItemPool* pSetPool = pSet ? pSet->GetPool() : NULL;
+ if ( pSet && pSet->GetItemState( pSetPool->GetWhich( SID_AUTO_CORRECT_DLG ), FALSE, &pItem ) == SFX_ITEM_SET )
+ aSet.Put( *pItem );
+
+ SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog( RID_OFA_AUTOCORR_DLG, NULL, &aSet, NULL );
+ pDlg->Execute();
+ delete pDlg;
+ }
+
+ break;
+ }
+
+ case SID_SD_AUTOPILOT :
+ case SID_NEWSD :
+ {
+ SvtModuleOptions aModuleOpt;
+ if ( !aModuleOpt.IsImpress() )
+ {
+ ErrorBox( 0, ResId( RID_ERRBOX_MODULENOTINSTALLED, *GetOffResManager_Impl() )).Execute();
+ return;
+ }
+
+ Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
+ Reference< com::sun::star::frame::XDispatchProvider > xProv(
+ xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY );
+
+ if ( xProv.is() )
+ {
+ ::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
+ Reference< com::sun::star::frame::XDispatchHelper > xHelper(
+ xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY );
+ if ( xHelper.is() )
+ {
+ Sequence < com::sun::star::beans::PropertyValue > aSeq;
+ if ( rReq.GetArgs() )
+ TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
+ Any aResult = xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aSeq );
+ ::com::sun::star::frame::DispatchResultEvent aEvent;
+ sal_Bool bSuccess = (
+ (aResult >>= aEvent) &&
+ (aEvent.State == ::com::sun::star::frame::DispatchResultState::SUCCESS)
+ );
+ rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
+ }
+ }
+ }
+ break;
+
+ case FN_LABEL :
+ case FN_BUSINESS_CARD :
+ case FN_XFORMS_INIT :
+ {
+ Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
+ Reference< com::sun::star::frame::XDispatchProvider > xProv(
+ xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.text.ModuleDispatcher")), UNO_QUERY );
+
+ if ( xProv.is() )
+ {
+ ::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( GetInterface()->GetSlot( rReq.GetSlot() )->GetUnoName() );
+ Reference< com::sun::star::frame::XDispatchHelper > xHelper(
+ xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY );
+ if ( xHelper.is() )
+ {
+ Sequence < com::sun::star::beans::PropertyValue > aSeq;
+ if ( rReq.GetArgs() )
+ TransformItems( rReq.GetSlot(), *rReq.GetArgs(), aSeq );
+ Any aResult = xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aSeq );
+ ::com::sun::star::frame::DispatchResultEvent aEvent;
+ sal_Bool bSuccess = (
+ (aResult >>= aEvent) &&
+ (aEvent.State == ::com::sun::star::frame::DispatchResultState::SUCCESS)
+ );
+ rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bSuccess ) );
+ }
+ }
+ }
+ break;
+
+ case SID_ADDRESS_DATA_SOURCE:
+ {
+ ::rtl::OUString sDialogServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.AddressBookSourcePilot" ) );
+ try
+ {
+ Reference< com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
+ Reference< com::sun::star::ui::dialogs::XExecutableDialog > xDialog;
+ if (xORB.is())
+ xDialog = Reference< com::sun::star::ui::dialogs::XExecutableDialog >(xORB->createInstance(sDialogServiceName), UNO_QUERY);
+ if (xDialog.is())
+ xDialog->execute();
+ else
+ ShowServiceNotAvailableError(NULL, sDialogServiceName, TRUE);
+ }
+ catch(::com::sun::star::uno::Exception&)
+ {
+ }
+ }
+ break;
+
+ case SID_COMP_BIBLIOGRAPHY:
+ {
+ SfxStringItem aURL(SID_FILE_NAME, String::CreateFromAscii(".component:Bibliography/View1"));
+ SfxStringItem aRef(SID_REFERER, String::CreateFromAscii("private:user"));
+ SfxStringItem aTarget(SID_TARGETNAME, String::CreateFromAscii("_blank"));
+ SfxViewFrame::Current()->GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aURL, &aRef, &aTarget, 0L);
+ }
+ break;
+ }
+}
+
+void SfxApplication::OfaState_Impl(SfxItemSet &rSet)
+{
+ const USHORT *pRanges = rSet.GetRanges();
+ DBG_ASSERT(pRanges && *pRanges, "Set ohne Bereich");
+ while ( *pRanges )
+ {
+ for(USHORT nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
+ {
+ switch(nWhich)
+ {
+ case SID_ONLINE_REGISTRATION:
+ {
+ ::utl::RegOptions aOptions;
+ if ( !aOptions.allowMenu() )
+ rSet.DisableItem( SID_ONLINE_REGISTRATION );
+ }
+ break;
+ }
+ }
+ }
+
+ SvtModuleOptions aModuleOpt;
+
+ if( !aModuleOpt.IsWriter())
+ {
+ rSet.DisableItem( FN_LABEL );
+ rSet.DisableItem( FN_BUSINESS_CARD );
+ rSet.DisableItem( FN_XFORMS_INIT );
+ }
+
+ if ( !aModuleOpt.IsImpress() )
+ rSet.DisableItem( SID_SD_AUTOPILOT );
+}
diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx
new file mode 100644
index 000000000000..60b684d7385f
--- /dev/null
+++ b/sfx2/source/appl/appuno.cxx
@@ -0,0 +1,2429 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#if defined(_MSC_VER) && (_MSC_VER >= 1300)
+#pragma warning( disable : 4290 )
+#endif
+#include <com/sun/star/document/UpdateDocMode.hpp>
+
+#include "sal/config.h"
+
+#include <sfx2/appuno.hxx>
+#include "appbaslib.hxx"
+
+#include "sfx2/dllapi.h"
+
+#include <basic/sbx.hxx>
+#include <svl/itempool.hxx>
+#include <svl/rectitem.hxx>
+#include <tools/debug.hxx>
+#include <tools/wldcrd.hxx>
+
+#include <tools/urlobj.hxx>
+#include <tools/config.hxx>
+#include <basic/sbxmeth.hxx>
+#include <basic/sbmeth.hxx>
+#include <basic/sbxobj.hxx>
+#include <basic/sberrors.hxx>
+#include <basic/basmgr.hxx>
+#include <basic/sbuno.hxx>
+
+#include <basic/sbxcore.hxx>
+#include <svl/ownlist.hxx>
+#include <svl/lckbitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/slstitm.hxx>
+#include <svl/intitem.hxx>
+#include <svl/eitem.hxx>
+#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/XFrameActionListener.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/FrameActionEvent.hpp>
+#include <com/sun/star/frame/FrameAction.hpp>
+#include <com/sun/star/container/XContainer.hpp>
+#include <com/sun/star/container/XIndexContainer.hpp>
+#include <com/sun/star/container/XNameReplace.hpp>
+#include <com/sun/star/container/XContainerListener.hpp>
+#include <com/sun/star/container/XSet.hpp>
+#include <com/sun/star/container/ContainerEvent.hpp>
+#include <com/sun/star/container/XIndexReplace.hpp>
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/awt/XTopWindow.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/awt/PosSize.hpp>
+#include <com/sun/star/registry/RegistryValueType.hpp>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/awt/PosSize.hpp>
+#include <com/sun/star/awt/XButton.hpp>
+#include <com/sun/star/frame/DispatchResultEvent.hpp>
+#include <com/sun/star/frame/DispatchResultState.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/ucb/XContent.hpp>
+
+#include <tools/cachestr.hxx>
+#include <osl/mutex.hxx>
+#include <comphelper/sequence.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <comphelper/interaction.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::registry;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::io;
+
+#include "sfxtypes.hxx"
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <sfx2/msg.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/fcontnr.hxx>
+#include "frmload.hxx"
+#include <sfx2/frame.hxx>
+#include "sfxbasic.hxx"
+#include <sfx2/objsh.hxx>
+#include <sfx2/objuno.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/dispatch.hxx>
+#include "doctemplates.hxx"
+#include "shutdownicon.hxx"
+#include "objshimp.hxx"
+#include "fltoptint.hxx"
+#include <sfx2/docfile.hxx>
+#include <sfx2/sfxbasecontroller.hxx>
+#include <sfx2/brokenpackageint.hxx>
+#include "eventsupplier.hxx"
+#include "xpackcreator.hxx"
+#include "plugin.hxx"
+#include "iframe.hxx"
+#include <ownsubfilterservice.hxx>
+#include "SfxDocumentMetaData.hxx"
+
+#define FRAMELOADER_SERVICENAME "com.sun.star.frame.FrameLoader"
+#define PROTOCOLHANDLER_SERVICENAME "com.sun.star.frame.ProtocolHandler"
+
+static char const sTemplateRegionName[] = "TemplateRegionName";
+static char const sTemplateName[] = "TemplateName";
+static char const sAsTemplate[] = "AsTemplate";
+static char const sOpenNewView[] = "OpenNewView";
+static char const sViewId[] = "ViewId";
+static char const sPluginMode[] = "PluginMode";
+static char const sReadOnly[] = "ReadOnly";
+static char const sStartPresentation[] = "StartPresentation";
+static char const sFrameName[] = "FrameName";
+static char const sMediaType[] = "MediaType";
+static char const sPostData[] = "PostData";
+static char const sCharacterSet[] = "CharacterSet";
+static char const sInputStream[] = "InputStream";
+static char const sStream[] = "Stream";
+static char const sOutputStream[] = "OutputStream";
+static char const sHidden[] = "Hidden";
+static char const sPreview[] = "Preview";
+static char const sViewOnly[] = "ViewOnly";
+static char const sDontEdit[] = "DontEdit";
+static char const sSilent[] = "Silent";
+static char const sJumpMark[] = "JumpMark";
+static char const sFileName[] = "FileName";
+static char const sSalvagedFile[] = "SalvagedFile";
+static char const sStatusInd[] = "StatusIndicator";
+static char const sModel[] = "Model";
+static char const sFrame[] = "Frame";
+static char const sViewData[] = "ViewData";
+static char const sFilterData[] = "FilterData";
+static char const sSelectionOnly[] = "SelectionOnly";
+static char const sFilterFlags[] = "FilterFlags";
+static char const sMacroExecMode[] = "MacroExecutionMode";
+static char const sUpdateDocMode[] = "UpdateDocMode";
+static char const sMinimized[] = "Minimized";
+static char const sInteractionHdl[] = "InteractionHandler";
+static char const sUCBContent[] = "UCBContent";
+static char const sRepairPackage[] = "RepairPackage";
+static char const sDocumentTitle[] = "DocumentTitle";
+static char const sComponentData[] = "ComponentData";
+static char const sComponentContext[] = "ComponentContext";
+static char const sDocumentBaseURL[] = "DocumentBaseURL";
+static char const sHierarchicalDocumentName[] = "HierarchicalDocumentName";
+static char const sCopyStreamIfPossible[] = "CopyStreamIfPossible";
+static char const sNoAutoSave[] = "NoAutoSave";
+static char const sFolderName[] = "FolderName";
+static char const sUseSystemDialog[] = "UseSystemDialog";
+static char const sStandardDir[] = "StandardDir";
+static char const sBlackList[] = "BlackList";
+static char const sModifyPasswordInfo[] = "ModifyPasswordInfo";
+static char const sSuggestedSaveAsDir[] = "SuggestedSaveAsDir";
+static char const sSuggestedSaveAsName[] = "SuggestedSaveAsName";
+static char const sEncryptionData[] = "EncryptionData";
+
+
+void TransformParameters( sal_uInt16 nSlotId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rArgs, SfxAllItemSet& rSet, const SfxSlot* pSlot )
+{
+ if ( !pSlot )
+ pSlot = SFX_SLOTPOOL().GetSlot( nSlotId );
+
+ if ( !pSlot )
+ return;
+
+ if ( nSlotId == SID_OPENURL )
+ nSlotId = SID_OPENDOC;
+ if ( nSlotId == SID_SAVEASURL )
+ nSlotId = SID_SAVEASDOC;
+
+ sal_Int32 nCount = rArgs.getLength();
+ if ( !nCount )
+ return;
+
+ const ::com::sun::star::beans::PropertyValue* pPropsVal = rArgs.getConstArray();
+ if ( !pSlot->IsMode(SFX_SLOT_METHOD) )
+ {
+ // slot is a property
+ const SfxType* pType = pSlot->GetType();
+ SfxPoolItem* pItem = pType->CreateItem();
+ if ( !pItem )
+ {
+#ifdef DBG_UTIL
+ ByteString aStr( "No creator method for item: ");
+ aStr += ByteString::CreateFromInt32( nSlotId );
+ DBG_ERROR( aStr.GetBuffer() );
+#endif
+ return;
+ }
+
+ USHORT nWhich = rSet.GetPool()->GetWhich(nSlotId);
+ BOOL bConvertTwips = ( rSet.GetPool()->GetMetric( nWhich ) == SFX_MAPUNIT_TWIP );
+ pItem->SetWhich( nWhich );
+ USHORT nSubCount = pType->nAttribs;
+
+ const ::com::sun::star::beans::PropertyValue& rProp = pPropsVal[0];
+ String aName = rProp.Name;
+ if ( nCount == 1 && aName.CompareToAscii( pSlot->pUnoName ) == COMPARE_EQUAL )
+ {
+ // there is only one parameter and its name matches the name of the property,
+ // so it's either a simple property or a complex property in one single UNO struct
+ if( pItem->PutValue( rProp.Value, bConvertTwips ? CONVERT_TWIPS : 0 ) )
+ // only use successfully converted items
+ rSet.Put( *pItem );
+#ifdef DBG_UTIL
+ else
+ {
+ ByteString aStr( "Property not convertable: ");
+ aStr += pSlot->pUnoName;
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+#endif
+ }
+#ifdef DBG_UTIL
+ else if ( nSubCount == 0 )
+ {
+ // for a simple property there can be only one parameter and its name *must* match
+ ByteString aStr( "Property name does not match: ");
+ aStr += ByteString( aName, RTL_TEXTENCODING_UTF8 );
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+#endif
+ else
+ {
+ // there is more than one parameter and the property is a complex one
+#ifdef DBG_UTIL
+ // if the dispatch API is used for UI purposes or from the testtool,
+ // it is possible to skip some or all arguments,
+ // but it indicates an error for macro recording;
+ // so this should be notified as a warning only
+ if ( nCount != nSubCount )
+ {
+ ByteString aStr( "MacroPlayer: wrong number of parameters for slot: ");
+ aStr += ByteString::CreateFromInt32( nSlotId );
+ DBG_WARNING( aStr.GetBuffer() );
+ }
+#endif
+ // complex property; collect sub items from the parameter set and reconstruct complex item
+ USHORT nFound=0;
+ for ( sal_uInt16 n=0; n<nCount; n++ )
+ {
+ const ::com::sun::star::beans::PropertyValue& rPropValue = pPropsVal[n];
+ USHORT nSub;
+ for ( nSub=0; nSub<nSubCount; nSub++ )
+ {
+ // search sub item by name
+ ByteString aStr( pSlot->pUnoName );
+ aStr += '.';
+ aStr += ByteString( pType->aAttrib[nSub].pName );
+ const char* pName = aStr.GetBuffer();
+ if ( rPropValue.Name.compareToAscii( pName ) == COMPARE_EQUAL )
+ {
+ BYTE nSubId = (BYTE) (sal_Int8) pType->aAttrib[nSub].nAID;
+ if ( bConvertTwips )
+ nSubId |= CONVERT_TWIPS;
+ if ( pItem->PutValue( rPropValue.Value, nSubId ) )
+ nFound++;
+#ifdef DBG_UTIL
+ else
+ {
+ ByteString aDbgStr( "Property not convertable: ");
+ aDbgStr += pSlot->pUnoName;
+ DBG_ERROR( aDbgStr.GetBuffer() );
+ }
+#endif
+ break;
+ }
+ }
+
+#ifdef DBG_UTIL
+ if ( nSub >= nSubCount )
+ {
+ // there was a parameter with a name that didn't match to any of the members
+ ByteString aStr( "Property name does not match: ");
+ aStr += ByteString( String(rPropValue.Name), RTL_TEXTENCODING_UTF8 );
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+#endif
+ }
+
+ // at least one part of the complex item must be present; other parts can have default values
+ if ( nFound > 0 )
+ rSet.Put( *pItem );
+ }
+
+ delete pItem;
+ }
+ else if ( nCount )
+ {
+#ifdef DBG_UTIL
+ // detect parameters that don't match to any formal argument or one of its members
+ sal_Int32 nFoundArgs = 0;
+#endif
+ // slot is a method
+ for ( sal_uInt16 nArgs=0; nArgs<pSlot->nArgDefCount; nArgs++ )
+ {
+ const SfxFormalArgument &rArg = pSlot->GetFormalArgument( nArgs );
+ SfxPoolItem* pItem = rArg.CreateItem();
+ if ( !pItem )
+ {
+#ifdef DBG_UTIL
+ ByteString aStr( "No creator method for argument: ");
+ aStr += rArg.pName;
+ DBG_ERROR( aStr.GetBuffer() );
+#endif
+ return;
+ }
+
+ USHORT nWhich = rSet.GetPool()->GetWhich(rArg.nSlotId);
+ BOOL bConvertTwips = ( rSet.GetPool()->GetMetric( nWhich ) == SFX_MAPUNIT_TWIP );
+ pItem->SetWhich( nWhich );
+ const SfxType* pType = rArg.pType;
+ USHORT nSubCount = pType->nAttribs;
+ if ( nSubCount == 0 )
+ {
+ // "simple" (base type) argument
+ for ( sal_uInt16 n=0; n<nCount; n++ )
+ {
+ const ::com::sun::star::beans::PropertyValue& rProp = pPropsVal[n];
+ String aName = rProp.Name;
+ if ( aName.CompareToAscii(rArg.pName) == COMPARE_EQUAL )
+ {
+#ifdef DBG_UTIL
+ ++nFoundArgs;
+#endif
+ if( pItem->PutValue( rProp.Value ) )
+ // only use successfully converted items
+ rSet.Put( *pItem );
+#ifdef DBG_UTIL
+ else
+ {
+ ByteString aStr( "Property not convertable: ");
+ aStr += rArg.pName;
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+#endif
+ break;
+ }
+ }
+ }
+ else
+ {
+ // complex argument, could be passed in one struct
+ BOOL bAsWholeItem = FALSE;
+ for ( sal_uInt16 n=0; n<nCount; n++ )
+ {
+ const ::com::sun::star::beans::PropertyValue& rProp = pPropsVal[n];
+ String aName = rProp.Name;
+ if ( aName.CompareToAscii(rArg.pName) == COMPARE_EQUAL )
+ {
+ bAsWholeItem = TRUE;
+#ifdef DBG_UTIL
+ ++nFoundArgs;
+#endif
+ if( pItem->PutValue( rProp.Value ) )
+ // only use successfully converted items
+ rSet.Put( *pItem );
+#ifdef DBG_UTIL
+ else
+ {
+ ByteString aStr( "Property not convertable: ");
+ aStr += rArg.pName;
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+#endif
+ }
+ }
+
+ if ( !bAsWholeItem )
+ {
+ // complex argument; collect sub items from argument array and reconstruct complex item
+ // only put item if at least one member was found and had the correct type
+ // (is this a good idea?! Should we ask for *all* members?)
+ BOOL bRet = FALSE;
+ for ( sal_uInt16 n=0; n<nCount; n++ )
+ {
+ const ::com::sun::star::beans::PropertyValue& rProp = pPropsVal[n];
+ for ( USHORT nSub=0; nSub<nSubCount; nSub++ )
+ {
+ // search sub item by name
+ ByteString aStr( rArg.pName );
+ aStr += '.';
+ aStr += pType->aAttrib[nSub].pName;
+ const char* pName = aStr.GetBuffer();
+ if ( rProp.Name.compareToAscii( pName ) == COMPARE_EQUAL )
+ {
+ // at least one member found ...
+ bRet = TRUE;
+#ifdef DBG_UTIL
+ ++nFoundArgs;
+#endif
+ BYTE nSubId = (BYTE) (sal_Int8) pType->aAttrib[nSub].nAID;
+ if ( bConvertTwips )
+ nSubId |= CONVERT_TWIPS;
+ if (!pItem->PutValue( rProp.Value, nSubId ) )
+ {
+ // ... but it was not convertable
+ bRet = FALSE;
+#ifdef DBG_UTIL
+ ByteString aDbgStr( "Property not convertable: ");
+ aDbgStr += rArg.pName;
+ DBG_ERROR( aDbgStr.GetBuffer() );
+#endif
+ }
+
+ break;
+ }
+ }
+ }
+
+ if ( bRet )
+ // only use successfully converted items
+ rSet.Put( *pItem );
+
+ }
+ }
+
+ delete pItem;
+ }
+
+ // special additional parameters for some slots not seen in the slot definitions
+ // Some of these slots are not considered to be used for macro recording, because they shouldn't be recorded as slots,
+ // but as dispatching or factory or arbitrary URLs to the frame
+ // Some also can use additional arguments that are not recordable (will be changed later,
+ // f.e. "SaveAs" shouldn't support parameters not in the slot definition!)
+ if ( nSlotId == SID_NEWWINDOW )
+ {
+ for ( sal_uInt16 n=0; n<nCount; n++ )
+ {
+ const ::com::sun::star::beans::PropertyValue& rProp = pPropsVal[n];
+ rtl::OUString aName = rProp.Name;
+ if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sFrame)) )
+ {
+ Reference< XFrame > xFrame;
+ OSL_VERIFY( rProp.Value >>= xFrame );
+ rSet.Put( SfxUnoFrameItem( SID_FILLFRAME, xFrame ) );
+ }
+ else
+ if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sHidden)) )
+ {
+ sal_Bool bVal = sal_False;
+ if (rProp.Value >>= bVal)
+ rSet.Put( SfxBoolItem( SID_HIDDEN, bVal ) );
+ }
+ }
+ }
+ else if ( nSlotId == SID_OPENDOC || nSlotId == SID_EXPORTDOC || nSlotId == SID_SAVEASDOC || nSlotId == SID_SAVEDOC ||
+ nSlotId == SID_SAVETO || nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF )
+ {
+ for ( sal_uInt16 n=0; n<nCount; n++ )
+ {
+#ifdef DBG_UTIL
+ ++nFoundArgs;
+#endif
+ const ::com::sun::star::beans::PropertyValue& rProp = pPropsVal[n];
+ rtl::OUString aName = rProp.Name;
+ if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sModel)) )
+ rSet.Put( SfxUnoAnyItem( SID_DOCUMENT, rProp.Value ) );
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sComponentData)) )
+ {
+ rSet.Put( SfxUnoAnyItem( SID_COMPONENTDATA, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sComponentContext)) )
+ {
+ rSet.Put( SfxUnoAnyItem( SID_COMPONENTCONTEXT, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sStatusInd)) )
+ {
+ Reference< ::com::sun::star::task::XStatusIndicator > xVal;
+ sal_Bool bOK = ((rProp.Value >>= xVal) && xVal.is());
+ DBG_ASSERT( bOK, "invalid type for StatusIndicator" );
+ if (bOK)
+ rSet.Put( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sInteractionHdl)) )
+ {
+ Reference< ::com::sun::star::task::XInteractionHandler > xVal;
+ sal_Bool bOK = ((rProp.Value >>= xVal) && xVal.is());
+ DBG_ASSERT( bOK, "invalid type for InteractionHandler" );
+ if (bOK)
+ rSet.Put( SfxUnoAnyItem( SID_INTERACTIONHANDLER, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sViewData)) )
+ rSet.Put( SfxUnoAnyItem( SID_VIEW_DATA, rProp.Value ) );
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sFilterData)) )
+ rSet.Put( SfxUnoAnyItem( SID_FILTER_DATA, rProp.Value ) );
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sInputStream)) )
+ {
+ Reference< XInputStream > xVal;
+ sal_Bool bOK = ((rProp.Value >>= xVal) && xVal.is());
+ DBG_ASSERT( bOK, "invalid type for InputStream" );
+ if (bOK)
+ rSet.Put( SfxUnoAnyItem( SID_INPUTSTREAM, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sStream)) )
+ {
+ Reference< XInputStream > xVal;
+ sal_Bool bOK = ((rProp.Value >>= xVal) && xVal.is());
+ DBG_ASSERT( bOK, "invalid type for Stream" );
+ if (bOK)
+ rSet.Put( SfxUnoAnyItem( SID_STREAM, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sUCBContent)) )
+ {
+ Reference< XContent > xVal;
+ sal_Bool bOK = ((rProp.Value >>= xVal) && xVal.is());
+ DBG_ASSERT( bOK, "invalid type for UCBContent" );
+ if (bOK)
+ rSet.Put( SfxUnoAnyItem( SID_CONTENT, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sOutputStream)) )
+ {
+ Reference< XOutputStream > xVal;
+ sal_Bool bOK = ((rProp.Value >>= xVal) && xVal.is());
+ DBG_ASSERT( bOK, "invalid type for OutputStream" );
+ if (bOK)
+ rSet.Put( SfxUnoAnyItem( SID_OUTPUTSTREAM, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sPostData)) )
+ {
+ Reference< XInputStream > xVal;
+ sal_Bool bOK = (rProp.Value >>= xVal);
+ DBG_ASSERT( bOK, "invalid type for PostData" );
+ if (bOK)
+ rSet.Put( SfxUnoAnyItem( SID_POSTDATA, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sFrame)) )
+ {
+ Reference< XFrame > xFrame;
+ sal_Bool bOK = (rProp.Value >>= xFrame);
+ DBG_ASSERT( bOK, "invalid type for Frame" );
+ if (bOK)
+ rSet.Put( SfxUnoFrameItem( SID_FILLFRAME, xFrame ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sAsTemplate)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for AsTemplate" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_TEMPLATE, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sOpenNewView)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for OpenNewView" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_OPEN_NEW_VIEW, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sViewId)) )
+ {
+ sal_Int16 nVal = -1;
+ sal_Bool bOK = ((rProp.Value >>= nVal) && (nVal != -1));
+ DBG_ASSERT( bOK, "invalid type for ViewId" );
+ if (bOK)
+ rSet.Put( SfxUInt16Item( SID_VIEW_ID, nVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sPluginMode)) )
+ {
+ sal_Int16 nVal = -1;
+ sal_Bool bOK = ((rProp.Value >>= nVal) && (nVal != -1));
+ DBG_ASSERT( bOK, "invalid type for PluginMode" );
+ if (bOK)
+ rSet.Put( SfxUInt16Item( SID_PLUGIN_MODE, nVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sReadOnly)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for ReadOnly" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_DOC_READONLY, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sStartPresentation)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for StartPresentation" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_DOC_STARTPRESENTATION, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sSelectionOnly)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for SelectionOnly" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_SELECTION, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sHidden)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for Hidden" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_HIDDEN, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sMinimized)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for Minimized" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_MINIMIZED, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sSilent)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for Silent" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_SILENT, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sPreview)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for Preview" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_PREVIEW, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sViewOnly)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for ViewOnly" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_VIEWONLY, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sDontEdit)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for ViewOnly" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_EDITDOC, !bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sUseSystemDialog)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for ViewOnly" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_FILE_DIALOG, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sStandardDir)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for StandardDir" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_STANDARD_DIR, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sBlackList)) )
+ {
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > xVal;
+ sal_Bool bOK = (rProp.Value >>= xVal);
+ DBG_ASSERT( bOK, "invalid type or value for BlackList" );
+ if (bOK)
+ {
+ SfxStringListItem stringList(SID_BLACK_LIST);
+ stringList.SetStringList( xVal );
+ rSet.Put( stringList );
+ }
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sFileName)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for FileName" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_FILE_NAME, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sSalvagedFile)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = (rProp.Value >>= sVal);
+ DBG_ASSERT( bOK, "invalid type or value for SalvagedFile" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_DOC_SALVAGE, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sFolderName)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = (rProp.Value >>= sVal);
+ DBG_ASSERT( bOK, "invalid type or value for FolderName" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_PATH, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sFrameName)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = (rProp.Value >>= sVal);
+ DBG_ASSERT( bOK, "invalid type for FrameName" );
+ if (bOK && sVal.getLength())
+ rSet.Put( SfxStringItem( SID_TARGETNAME, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sMediaType)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for MediaType" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_CONTENTTYPE, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sTemplateName)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for TemplateName" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_TEMPLATE_NAME, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sTemplateRegionName)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for TemplateRegionName" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_TEMPLATE_REGIONNAME, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sJumpMark)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for JumpMark" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_JUMPMARK, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sCharacterSet)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for CharacterSet" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_CHARSET, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sFilterFlags)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for FilterFlags" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_FILE_FILTEROPTIONS, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sMacroExecMode)) )
+ {
+ sal_Int16 nVal =-1;
+ sal_Bool bOK = ((rProp.Value >>= nVal) && (nVal != -1));
+ DBG_ASSERT( bOK, "invalid type for MacroExecMode" );
+ if (bOK)
+ rSet.Put( SfxUInt16Item( SID_MACROEXECMODE, nVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sUpdateDocMode)) )
+ {
+ sal_Int16 nVal =-1;
+ sal_Bool bOK = ((rProp.Value >>= nVal) && (nVal != -1));
+ DBG_ASSERT( bOK, "invalid type for UpdateDocMode" );
+ if (bOK)
+ rSet.Put( SfxUInt16Item( SID_UPDATEDOCMODE, nVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sRepairPackage)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for RepairPackage" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_REPAIRPACKAGE, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sDocumentTitle)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for DocumentTitle" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_DOCINFO_TITLE, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sDocumentBaseURL)) )
+ {
+ ::rtl::OUString sVal;
+ // the base url can be set to empty ( for embedded objects for example )
+ sal_Bool bOK = (rProp.Value >>= sVal);
+ DBG_ASSERT( bOK, "invalid type or value for DocumentBaseURL" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_DOC_BASEURL, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sHierarchicalDocumentName)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for HierarchicalDocumentName" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_DOC_HIERARCHICALNAME, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sCopyStreamIfPossible)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for CopyStreamIfPossible" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_COPY_STREAM_IF_POSSIBLE, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sNoAutoSave)) )
+ {
+ sal_Bool bVal = sal_False;
+ sal_Bool bOK = (rProp.Value >>= bVal);
+ DBG_ASSERT( bOK, "invalid type for NoAutoSave" );
+ if (bOK)
+ rSet.Put( SfxBoolItem( SID_NOAUTOSAVE, bVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sModifyPasswordInfo)) )
+ {
+ rSet.Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sEncryptionData)) )
+ {
+ rSet.Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, rProp.Value ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sSuggestedSaveAsDir)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for SuggestedSaveAsDir" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_SUGGESTEDSAVEASDIR, sVal ) );
+ }
+ else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sSuggestedSaveAsName)) )
+ {
+ ::rtl::OUString sVal;
+ sal_Bool bOK = ((rProp.Value >>= sVal) && sVal.getLength());
+ DBG_ASSERT( bOK, "invalid type or value for SuggestedSaveAsName" );
+ if (bOK)
+ rSet.Put( SfxStringItem( SID_SUGGESTEDSAVEASNAME, sVal ) );
+ }
+#ifdef DBG_UTIL
+ else
+ --nFoundArgs;
+#endif
+ }
+ }
+ // --> PB 2007-12-09 #i83757#
+ else
+ {
+ // transform parameter "OptionsPageURL" of slot "OptionsTreeDialog"
+ String sSlotName( DEFINE_CONST_UNICODE( "OptionsTreeDialog" ) );
+ String sPropName( DEFINE_CONST_UNICODE( "OptionsPageURL" ) );
+ if ( sSlotName.EqualsAscii( pSlot->pUnoName ) )
+ {
+ for ( sal_uInt16 n = 0; n < nCount; ++n )
+ {
+ const PropertyValue& rProp = pPropsVal[n];
+ String sName( rProp.Name );
+ if ( sName == sPropName )
+ {
+ ::rtl::OUString sURL;
+ if ( rProp.Value >>= sURL )
+ rSet.Put( SfxStringItem( SID_OPTIONS_PAGEURL, sURL ) );
+ break;
+ }
+ }
+ }
+ }
+ // <--
+#ifdef DB_UTIL
+ if ( nFoundArgs == nCount )
+ {
+ // except for the "special" slots: assure that every argument was convertable
+ ByteString aStr( "MacroPlayer: Some properties didn't match to any formal argument for slot: ");
+ aStr += pSlot->pUnoName;
+ DBG_WARNING( aStr.GetBuffer() );
+ }
+#endif
+ }
+}
+
+void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rArgs, const SfxSlot* pSlot )
+{
+ if ( !pSlot )
+ pSlot = SFX_SLOTPOOL().GetSlot( nSlotId );
+
+ if ( !pSlot)
+ return;
+
+ if ( nSlotId == SID_OPENURL )
+ nSlotId = SID_OPENDOC;
+ if ( nSlotId == SID_SAVEASURL )
+ nSlotId = SID_SAVEASDOC;
+
+ // find number of properties to avoid permanent reallocations in the sequence
+ sal_Int32 nProps=0;
+
+#ifdef DBG_UTIL
+ // trace number of items and compare with number of properties for debugging purposes
+ sal_Int32 nItems=0;
+#endif
+
+ const SfxType *pType = pSlot->GetType();
+ if ( !pSlot->IsMode(SFX_SLOT_METHOD) )
+ {
+ // slot is a property
+ USHORT nWhich = rSet.GetPool()->GetWhich(nSlotId);
+ if ( rSet.GetItemState( nWhich ) == SFX_ITEM_SET ) //???
+ {
+ USHORT nSubCount = pType->nAttribs;
+ if ( nSubCount )
+ // it's a complex property, we want it split into simple types
+ // so we expect to get as many items as we have (sub) members
+ nProps = nSubCount;
+ else
+ // simple property: we expect to get exactly one item
+ nProps++;
+ }
+#ifdef DBG_UTIL
+ else
+ {
+ // we will not rely on the "toggle" ability of some property slots
+ ByteString aStr( "Processing property slot without argument: ");
+ aStr += ByteString::CreateFromInt32( nSlotId );
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+#endif
+
+#ifdef DBG_UTIL
+ nItems++;
+#endif
+ }
+ else
+ {
+ // slot is a method
+ USHORT nFormalArgs = pSlot->GetFormalArgumentCount();
+ for ( USHORT nArg=0; nArg<nFormalArgs; ++nArg )
+ {
+ // check every formal argument of the method
+ const SfxFormalArgument &rArg = pSlot->GetFormalArgument( nArg );
+ USHORT nWhich = rSet.GetPool()->GetWhich( rArg.nSlotId );
+ if ( rSet.GetItemState( nWhich ) == SFX_ITEM_SET ) //???
+ {
+ USHORT nSubCount = rArg.pType->nAttribs;
+ if ( nSubCount )
+ // argument has a complex type, we want it split into simple types
+ // so for this argument we expect to get as many items as we have (sub) members
+ nProps += nSubCount;
+ else
+ // argument of simple type: we expect to get exactly one item for it
+ nProps++;
+#ifdef DBG_UTIL
+ nItems++;
+#endif
+ }
+ }
+
+ // special treatment for slots that are *not* meant to be recorded as slots (except SaveAs/To)
+ if ( nSlotId == SID_OPENDOC || nSlotId == SID_EXPORTDOC || nSlotId == SID_SAVEASDOC || nSlotId == SID_SAVEDOC ||
+ nSlotId == SID_SAVETO || nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF )
+ {
+ sal_Int32 nAdditional=0;
+ if ( rSet.GetItemState( SID_PROGRESS_STATUSBAR_CONTROL ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_INTERACTIONHANDLER ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_DOC_SALVAGE ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_PATH ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_FILE_DIALOG ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_STANDARD_DIR ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_BLACK_LIST ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_CONTENT ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_INPUTSTREAM ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_STREAM ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_OUTPUTSTREAM ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_TEMPLATE ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_OPEN_NEW_VIEW ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_VIEW_ID ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_VIEW_DATA ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_FILTER_DATA ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_PLUGIN_MODE ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_DOC_READONLY ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_DOC_STARTPRESENTATION ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_SELECTION ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_CONTENTTYPE ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_POSTDATA ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_FILLFRAME ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_CHARSET ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_TARGETNAME ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_TEMPLATE_NAME ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_TEMPLATE_REGIONNAME ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_HIDDEN ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_MINIMIZED ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_PREVIEW ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_VIEWONLY ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_EDITDOC ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_SILENT ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_JUMPMARK ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_DOCUMENT ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_MACROEXECMODE ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_UPDATEDOCMODE ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_REPAIRPACKAGE ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_DOCINFO_TITLE ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_COMPONENTDATA ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_COMPONENTCONTEXT ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_DOC_BASEURL ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_DOC_HIERARCHICALNAME ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_COPY_STREAM_IF_POSSIBLE ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_NOAUTOSAVE ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_MODIFYPASSWORDINFO ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_SUGGESTEDSAVEASDIR ) == SFX_ITEM_SET )
+ nAdditional++;
+ if ( rSet.GetItemState( SID_ENCRYPTIONDATA ) == SFX_ITEM_SET )
+ nAdditional++;
+ nAdditional++;
+ if ( rSet.GetItemState( SID_SUGGESTEDSAVEASNAME ) == SFX_ITEM_SET )
+ nAdditional++;
+
+ // consider additional arguments
+ nProps += nAdditional;
+#ifdef DBG_UTIL
+ nItems += nAdditional;
+#endif
+ }
+ }
+
+#ifdef DBG_UTIL
+ // now check the itemset: is there any item that is not convertable using the list of formal arguments
+ // or the table of additional items?!
+ if ( rSet.Count() != nItems )
+ {
+ // detect unknown item and present error message
+ const USHORT *pRanges = rSet.GetRanges();
+ while ( *pRanges )
+ {
+ for(USHORT nId = *pRanges++; nId <= *pRanges; ++nId)
+ {
+ if ( rSet.GetItemState(nId) < SFX_ITEM_SET ) //???
+ // not really set
+ continue;
+
+ if ( !pSlot->IsMode(SFX_SLOT_METHOD) && nId == rSet.GetPool()->GetWhich( pSlot->GetSlotId() ) )
+ continue;
+
+ USHORT nFormalArgs = pSlot->GetFormalArgumentCount();
+ USHORT nArg;
+ for ( nArg=0; nArg<nFormalArgs; ++nArg )
+ {
+ const SfxFormalArgument &rArg = pSlot->GetFormalArgument( nArg );
+ USHORT nWhich = rSet.GetPool()->GetWhich( rArg.nSlotId );
+ if ( nId == nWhich )
+ break;
+ }
+
+ if ( nArg<nFormalArgs )
+ continue;
+
+ if ( nSlotId == SID_OPENDOC || nSlotId == SID_EXPORTDOC || nSlotId == SID_SAVEASDOC || nSlotId == SID_SAVEDOC ||
+ nSlotId == SID_SAVETO || nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF )
+ {
+ if ( nId == SID_DOCFRAME )
+ continue;
+ if ( nId == SID_PROGRESS_STATUSBAR_CONTROL )
+ continue;
+ if ( nId == SID_INTERACTIONHANDLER )
+ continue;
+ if ( nId == SID_VIEW_DATA )
+ continue;
+ if ( nId == SID_FILTER_DATA )
+ continue;
+ if ( nId == SID_DOCUMENT )
+ continue;
+ if ( nId == SID_CONTENT )
+ continue;
+ if ( nId == SID_INPUTSTREAM )
+ continue;
+ if ( nId == SID_STREAM )
+ continue;
+ if ( nId == SID_OUTPUTSTREAM )
+ continue;
+ if ( nId == SID_POSTDATA )
+ continue;
+ if ( nId == SID_FILLFRAME )
+ continue;
+ if ( nId == SID_TEMPLATE )
+ continue;
+ if ( nId == SID_OPEN_NEW_VIEW )
+ continue;
+ if ( nId == SID_VIEW_ID )
+ continue;
+ if ( nId == SID_PLUGIN_MODE )
+ continue;
+ if ( nId == SID_DOC_READONLY )
+ continue;
+ if ( nId == SID_DOC_STARTPRESENTATION )
+ continue;
+ if ( nId == SID_SELECTION )
+ continue;
+ if ( nId == SID_HIDDEN )
+ continue;
+ if ( nId == SID_MINIMIZED )
+ continue;
+ if ( nId == SID_SILENT )
+ continue;
+ if ( nId == SID_PREVIEW )
+ continue;
+ if ( nId == SID_VIEWONLY )
+ continue;
+ if ( nId == SID_EDITDOC )
+ continue;
+ if ( nId == SID_TARGETNAME )
+ continue;
+ if ( nId == SID_DOC_SALVAGE )
+ continue;
+ if ( nId == SID_PATH )
+ continue;
+ if ( nId == SID_FILE_DIALOG )
+ continue;
+ if ( nId == SID_STANDARD_DIR )
+ continue;
+ if ( nId == SID_BLACK_LIST )
+ continue;
+ if ( nId == SID_CONTENTTYPE )
+ continue;
+ if ( nId == SID_TEMPLATE_NAME )
+ continue;
+ if ( nId == SID_TEMPLATE_REGIONNAME )
+ continue;
+ if ( nId == SID_JUMPMARK )
+ continue;
+ if ( nId == SID_CHARSET )
+ continue;
+ if ( nId == SID_MACROEXECMODE )
+ continue;
+ if ( nId == SID_UPDATEDOCMODE )
+ continue;
+ if ( nId == SID_REPAIRPACKAGE )
+ continue;
+ if ( nId == SID_DOCINFO_TITLE )
+ continue;
+ if ( nId == SID_COMPONENTDATA )
+ continue;
+ if ( nId == SID_COMPONENTCONTEXT )
+ continue;
+ if ( nId == SID_DOC_BASEURL )
+ continue;
+ if ( nId == SID_DOC_HIERARCHICALNAME )
+ continue;
+ if ( nId == SID_COPY_STREAM_IF_POSSIBLE )
+ continue;
+ if ( nId == SID_NOAUTOSAVE )
+ continue;
+ if ( nId == SID_ENCRYPTIONDATA )
+ continue;
+
+ // used only internally
+ if ( nId == SID_SAVETO )
+ continue;
+ if ( nId == SID_MODIFYPASSWORDINFO )
+ continue;
+ if ( nId == SID_SUGGESTEDSAVEASDIR )
+ continue;
+ if ( nId == SID_SUGGESTEDSAVEASNAME )
+ continue;
+ }
+
+ ByteString aDbg( "Unknown item detected: ");
+ aDbg += ByteString::CreateFromInt32( nId );
+ DBG_ASSERT( nArg<nFormalArgs, aDbg.GetBuffer() );
+ }
+ }
+ }
+#endif
+
+ if ( !nProps )
+ return;
+
+ // convert every item into a property
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> aSequ( nProps );
+ ::com::sun::star::beans::PropertyValue *pValue = aSequ.getArray();
+
+ sal_Int32 nActProp=0;
+ if ( !pSlot->IsMode(SFX_SLOT_METHOD) )
+ {
+ // slot is a property
+ USHORT nWhich = rSet.GetPool()->GetWhich(nSlotId);
+ BOOL bConvertTwips = ( rSet.GetPool()->GetMetric( nWhich ) == SFX_MAPUNIT_TWIP );
+ SFX_ITEMSET_ARG( &rSet, pItem, SfxPoolItem, nWhich, sal_False );
+ if ( pItem ) //???
+ {
+ USHORT nSubCount = pType->nAttribs;
+ if ( !nSubCount )
+ {
+ //rPool.FillVariable( *pItem, *pVar, eUserMetric );
+ pValue[nActProp].Name = String( String::CreateFromAscii( pSlot->pUnoName ) ) ;
+ if ( !pItem->QueryValue( pValue[nActProp].Value ) )
+ {
+ ByteString aStr( "Item not convertable: ");
+ aStr += ByteString::CreateFromInt32(nSlotId);
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+ }
+ else
+ {
+ // complex type, add a property value for every member of the struct
+ for ( USHORT n=1; n<=nSubCount; ++n )
+ {
+ //rPool.FillVariable( *pItem, *pVar, eUserMetric );
+ BYTE nSubId = (BYTE) (sal_Int8) pType->aAttrib[n-1].nAID;
+ if ( bConvertTwips )
+ nSubId |= CONVERT_TWIPS;
+
+ DBG_ASSERT(( pType->aAttrib[n-1].nAID ) <= 127, "Member ID out of range" );
+ String aName( String::CreateFromAscii( pSlot->pUnoName ) ) ;
+ aName += '.';
+ aName += String( String::CreateFromAscii( pType->aAttrib[n-1].pName ) ) ;
+ pValue[nActProp].Name = aName;
+ if ( !pItem->QueryValue( pValue[nActProp++].Value, nSubId ) )
+ {
+ ByteString aStr( "Sub item ");
+ aStr += ByteString::CreateFromInt32( pType->aAttrib[n-1].nAID );
+ aStr += " not convertable in slot: ";
+ aStr += ByteString::CreateFromInt32(nSlotId);
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ // slot is a method
+ USHORT nFormalArgs = pSlot->GetFormalArgumentCount();
+ for ( USHORT nArg=0; nArg<nFormalArgs; ++nArg )
+ {
+ const SfxFormalArgument &rArg = pSlot->GetFormalArgument( nArg );
+ USHORT nWhich = rSet.GetPool()->GetWhich( rArg.nSlotId );
+ BOOL bConvertTwips = ( rSet.GetPool()->GetMetric( nWhich ) == SFX_MAPUNIT_TWIP );
+ SFX_ITEMSET_ARG( &rSet, pItem, SfxPoolItem, nWhich, sal_False );
+ if ( pItem ) //???
+ {
+ USHORT nSubCount = rArg.pType->nAttribs;
+ if ( !nSubCount )
+ {
+ //rPool.FillVariable( *pItem, *pVar, eUserMetric );
+ pValue[nActProp].Name = String( String::CreateFromAscii( rArg.pName ) ) ;
+ if ( !pItem->QueryValue( pValue[nActProp++].Value ) )
+ {
+ ByteString aStr( "Item not convertable: ");
+ aStr += ByteString::CreateFromInt32(rArg.nSlotId);
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+ }
+ else
+ {
+ // complex type, add a property value for every member of the struct
+ for ( USHORT n = 1; n <= nSubCount; ++n )
+ {
+ //rPool.FillVariable( rItem, *pVar, eUserMetric );
+ BYTE nSubId = (BYTE) (sal_Int8) rArg.pType->aAttrib[n-1].nAID;
+ if ( bConvertTwips )
+ nSubId |= CONVERT_TWIPS;
+
+ DBG_ASSERT((rArg.pType->aAttrib[n-1].nAID) <= 127, "Member ID out of range" );
+ String aName( String::CreateFromAscii( rArg.pName ) ) ;
+ aName += '.';
+ aName += String( String::CreateFromAscii( rArg.pType->aAttrib[n-1].pName ) ) ;
+ pValue[nActProp].Name = aName;
+ if ( !pItem->QueryValue( pValue[nActProp++].Value, nSubId ) )
+ {
+ ByteString aStr( "Sub item ");
+ aStr += ByteString::CreateFromInt32( rArg.pType->aAttrib[n-1].nAID );
+ aStr += " not convertable in slot: ";
+ aStr += ByteString::CreateFromInt32(rArg.nSlotId);
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+ }
+ }
+ }
+ }
+
+ if ( nSlotId == SID_OPENDOC || nSlotId == SID_EXPORTDOC || nSlotId == SID_SAVEASDOC || nSlotId == SID_SAVEDOC ||
+ nSlotId == SID_SAVETO || nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF )
+ {
+ const SfxPoolItem *pItem=0;
+ if ( rSet.GetItemState( SID_COMPONENTDATA, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sComponentData));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_COMPONENTCONTEXT, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sComponentContext));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_PROGRESS_STATUSBAR_CONTROL, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sStatusInd));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_INTERACTIONHANDLER, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sInteractionHdl));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_VIEW_DATA, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sViewData));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_FILTER_DATA, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sFilterData));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_DOCUMENT, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sModel));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_CONTENT, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sUCBContent));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_INPUTSTREAM, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sInputStream));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_STREAM, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sStream));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_OUTPUTSTREAM, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sOutputStream));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_POSTDATA, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sPostData));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_FILLFRAME, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sFrame));
+ if ( pItem->ISA( SfxUsrAnyItem ) )
+ {
+ OSL_ENSURE( false, "TransformItems: transporting an XFrame via an SfxUsrAnyItem is not deprecated!" );
+ pValue[nActProp++].Value = static_cast< const SfxUsrAnyItem* >( pItem )->GetValue();
+ }
+ else if ( pItem->ISA( SfxUnoFrameItem ) )
+ pValue[nActProp++].Value <<= static_cast< const SfxUnoFrameItem* >( pItem )->GetFrame();
+ else
+ OSL_ENSURE( false, "TransformItems: invalid item type for SID_FILLFRAME!" );
+ }
+ if ( rSet.GetItemState( SID_TEMPLATE, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sAsTemplate));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_OPEN_NEW_VIEW, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sOpenNewView));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_VIEW_ID, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sViewId));
+ pValue[nActProp++].Value <<= ( (sal_Int16) ((SfxUInt16Item*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_PLUGIN_MODE, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sPluginMode));
+ pValue[nActProp++].Value <<= ( (sal_Int16) ((SfxUInt16Item*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_DOC_READONLY, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sReadOnly));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_DOC_STARTPRESENTATION, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sStartPresentation));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_SELECTION, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sSelectionOnly));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_HIDDEN, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sHidden));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_MINIMIZED, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sMinimized));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_SILENT, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sSilent));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_PREVIEW, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sPreview));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_VIEWONLY, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sViewOnly));
+ pValue[nActProp++].Value <<= (sal_Bool) (( ((SfxBoolItem*)pItem)->GetValue() ));
+ }
+ if ( rSet.GetItemState( SID_EDITDOC, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sDontEdit));
+ pValue[nActProp++].Value <<= (sal_Bool) (!( ((SfxBoolItem*)pItem)->GetValue() ));
+ }
+ if ( rSet.GetItemState( SID_FILE_DIALOG, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sUseSystemDialog));
+ pValue[nActProp++].Value <<= (sal_Bool) ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_STANDARD_DIR, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sStandardDir));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_BLACK_LIST, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sBlackList));
+
+ com::sun::star::uno::Sequence< rtl::OUString > aList;
+ ((SfxStringListItem*)pItem)->GetStringList( aList );
+ pValue[nActProp++].Value <<= aList ;
+ }
+ if ( rSet.GetItemState( SID_TARGETNAME, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sFrameName));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_DOC_SALVAGE, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sSalvagedFile));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_PATH, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sFolderName));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_CONTENTTYPE, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sMediaType));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_TEMPLATE_NAME, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sTemplateName));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_TEMPLATE_REGIONNAME, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sTemplateRegionName));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_JUMPMARK, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sJumpMark));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+
+ if ( rSet.GetItemState( SID_CHARSET, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sCharacterSet));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_MACROEXECMODE, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sMacroExecMode));
+ pValue[nActProp++].Value <<= ( (sal_Int16) ((SfxUInt16Item*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_UPDATEDOCMODE, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sUpdateDocMode));
+ pValue[nActProp++].Value <<= ( (sal_Int16) ((SfxUInt16Item*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_REPAIRPACKAGE, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sRepairPackage));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_DOCINFO_TITLE, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sDocumentTitle));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_DOC_BASEURL, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sDocumentBaseURL));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_DOC_HIERARCHICALNAME, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sHierarchicalDocumentName));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_COPY_STREAM_IF_POSSIBLE, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sCopyStreamIfPossible));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_NOAUTOSAVE, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sNoAutoSave));
+ pValue[nActProp++].Value <<= ( ((SfxBoolItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_MODIFYPASSWORDINFO, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sModifyPasswordInfo));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_ENCRYPTIONDATA, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sEncryptionData));
+ pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() );
+ }
+ if ( rSet.GetItemState( SID_SUGGESTEDSAVEASDIR, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sSuggestedSaveAsDir));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ if ( rSet.GetItemState( SID_SUGGESTEDSAVEASNAME, sal_False, &pItem ) == SFX_ITEM_SET )
+ {
+ pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sSuggestedSaveAsName));
+ pValue[nActProp++].Value <<= ( ::rtl::OUString(((SfxStringItem*)pItem)->GetValue()) );
+ }
+ }
+ }
+
+ rArgs = aSequ;
+}
+
+SFX_IMPL_XINTERFACE_5( SfxMacroLoader, OWeakObject, ::com::sun::star::frame::XDispatchProvider, ::com::sun::star::frame::XNotifyingDispatch, ::com::sun::star::frame::XDispatch, ::com::sun::star::frame::XSynchronousDispatch,::com::sun::star::lang::XInitialization )
+SFX_IMPL_XTYPEPROVIDER_5( SfxMacroLoader, ::com::sun::star::frame::XDispatchProvider, ::com::sun::star::frame::XNotifyingDispatch, ::com::sun::star::frame::XDispatch, ::com::sun::star::frame::XSynchronousDispatch,::com::sun::star::lang::XInitialization )
+SFX_IMPL_XSERVICEINFO( SfxMacroLoader, PROTOCOLHANDLER_SERVICENAME, "com.sun.star.comp.sfx2.SfxMacroLoader" )
+SFX_IMPL_SINGLEFACTORY( SfxMacroLoader )
+
+void SAL_CALL SfxMacroLoader::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
+{
+ Reference < XFrame > xFrame;
+ if ( aArguments.getLength() )
+ {
+ aArguments[0] >>= xFrame;
+ m_xFrame = xFrame;
+ }
+}
+
+SfxObjectShell* SfxMacroLoader::GetObjectShell_Impl()
+{
+ SfxObjectShell* pDocShell = NULL;
+ Reference < XFrame > xFrame( m_xFrame.get(), UNO_QUERY );
+ if ( xFrame.is() )
+ {
+ SfxFrame* pFrame=0;
+ for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) )
+ {
+ if ( pFrame->GetFrameInterface() == xFrame )
+ break;
+ }
+
+ if ( pFrame )
+ pDocShell = pFrame->GetCurrentDocument();
+ }
+
+ return pDocShell;
+}
+
+// -----------------------------------------------------------------------
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL SfxMacroLoader::queryDispatch(
+ const ::com::sun::star::util::URL& aURL ,
+ const ::rtl::OUString& /*sTargetFrameName*/,
+ sal_Int32 /*nSearchFlags*/ ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatcher;
+ if(aURL.Complete.compareToAscii("macro:",6)==0)
+ xDispatcher = this;
+ return xDispatcher;
+}
+
+// -----------------------------------------------------------------------
+::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatch > > SAL_CALL
+ SfxMacroLoader::queryDispatches( const ::com::sun::star::uno::Sequence < ::com::sun::star::frame::DispatchDescriptor >& seqDescriptor )
+ throw( ::com::sun::star::uno::RuntimeException )
+{
+ sal_Int32 nCount = seqDescriptor.getLength();
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatch > > lDispatcher(nCount);
+ for( sal_Int32 i=0; i<nCount; ++i )
+ lDispatcher[i] = this->queryDispatch( seqDescriptor[i].FeatureURL,
+ seqDescriptor[i].FrameName,
+ seqDescriptor[i].SearchFlags );
+ return lDispatcher;
+}
+
+// -----------------------------------------------------------------------
+void SAL_CALL SfxMacroLoader::dispatchWithNotification( const ::com::sun::star::util::URL& aURL ,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArgs ,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& xListener )
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ sal_uInt32 nPropertyCount = lArgs.getLength();
+ ::rtl::OUString aReferer;
+ for( sal_uInt32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
+ {
+ if( lArgs[nProperty].Name == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Referer")) )
+ {
+ lArgs[nProperty].Value >>= aReferer;
+ break;
+ }
+ }
+
+ ::com::sun::star::uno::Any aAny;
+ ErrCode nErr = loadMacro( aURL.Complete, aAny, GetObjectShell_Impl() );
+ if( xListener.is() )
+ {
+ // always call dispatchFinished(), because we didn't load a document but
+ // executed a macro instead!
+ ::com::sun::star::frame::DispatchResultEvent aEvent;
+
+ aEvent.Source = static_cast< ::cppu::OWeakObject* >(this);
+ if( nErr == ERRCODE_NONE )
+ aEvent.State = ::com::sun::star::frame::DispatchResultState::SUCCESS;
+ else
+ aEvent.State = ::com::sun::star::frame::DispatchResultState::FAILURE;
+
+ xListener->dispatchFinished( aEvent ) ;
+ }
+}
+
+::com::sun::star::uno::Any SAL_CALL SfxMacroLoader::dispatchWithReturnValue(
+ const ::com::sun::star::util::URL& aURL,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::com::sun::star::uno::Any aRet;
+ /*ErrCode nErr = */loadMacro( aURL.Complete, aRet, GetObjectShell_Impl() );
+ return aRet;
+}
+
+// -----------------------------------------------------------------------
+void SAL_CALL SfxMacroLoader::dispatch( const ::com::sun::star::util::URL& aURL ,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArgs )
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ sal_uInt32 nPropertyCount = lArgs.getLength();
+ ::rtl::OUString aReferer;
+ for( sal_uInt32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
+ {
+ if( lArgs[nProperty].Name == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Referer")) )
+ {
+ lArgs[nProperty].Value >>= aReferer;
+ break;
+ }
+ }
+
+ ::com::sun::star::uno::Any aAny;
+ /*ErrCode nErr = */loadMacro( aURL.Complete, aAny, GetObjectShell_Impl() );
+}
+
+// -----------------------------------------------------------------------
+void SAL_CALL SfxMacroLoader::addStatusListener(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& ,
+ const ::com::sun::star::util::URL& )
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ /* TODO
+ How we can handle different listener for further coming or currently running dispatch() jobs
+ without any inconsistency!
+ */
+}
+
+// -----------------------------------------------------------------------
+void SAL_CALL SfxMacroLoader::removeStatusListener(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >&,
+ const ::com::sun::star::util::URL& )
+ throw (::com::sun::star::uno::RuntimeException)
+{
+}
+
+// -----------------------------------------------------------------------
+ErrCode SfxMacroLoader::loadMacro( const ::rtl::OUString& rURL, com::sun::star::uno::Any& rRetval, SfxObjectShell* pSh )
+ throw ( ::com::sun::star::uno::RuntimeException )
+{
+ SfxApplication* pApp = SFX_APP();
+ pApp->EnterBasicCall();
+ SfxObjectShell* pCurrent = pSh;
+ if ( !pCurrent )
+ // all not full qualified names use the BASIC of the given or current document
+ pCurrent = SfxObjectShell::Current();
+
+ // 'macro:///lib.mod.proc(args)' => macro of App-BASIC
+ // 'macro://[docname|.]/lib.mod.proc(args)' => macro of current or qualified document
+ // 'macro://obj.method(args)' => direct API call, execute it via App-BASIC
+ String aMacro( rURL );
+ sal_uInt16 nHashPos = aMacro.Search( '/', 8 );
+ sal_uInt16 nArgsPos = aMacro.Search( '(' );
+ BasicManager *pAppMgr = SFX_APP()->GetBasicManager();
+ BasicManager *pBasMgr = 0;
+ ErrCode nErr = ERRCODE_NONE;
+
+ // should a macro function be executed ( no direct API call)?
+ if ( STRING_NOTFOUND != nHashPos && nHashPos < nArgsPos )
+ {
+ // find BasicManager
+ SfxObjectShell* pDoc = NULL;
+ String aBasMgrName( INetURLObject::decode(aMacro.Copy( 8, nHashPos-8 ), INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET) );
+ if ( !aBasMgrName.Len() )
+ pBasMgr = pAppMgr;
+ else if ( aBasMgrName.EqualsAscii(".") )
+ {
+ // current/actual document
+ pDoc = pCurrent;
+ if (pDoc)
+ pBasMgr = pDoc->GetBasicManager();
+ }
+ else
+ {
+ // full qualified name, find document by name
+ for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst();
+ pObjSh && !pBasMgr;
+ pObjSh = SfxObjectShell::GetNext(*pObjSh) )
+ if ( aBasMgrName == pObjSh->GetTitle(SFX_TITLE_APINAME) )
+ {
+ pDoc = pObjSh;
+ pBasMgr = pDoc->GetBasicManager();
+ }
+ }
+
+ if ( pBasMgr )
+ {
+ if ( pSh && pDoc )
+ {
+ // security check for macros from document basic if an SFX context (pSh) is given
+ if ( !pDoc->AdjustMacroMode( String() ) )
+ // check forbids execution
+ return ERRCODE_IO_ACCESSDENIED;
+ }
+ else if ( pSh && pSh->GetMedium() )
+ {
+ pSh->AdjustMacroMode( String() );
+ SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
+ SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pMacroExecModeItem, SfxUInt16Item, SID_MACROEXECMODE, sal_False);
+ if ( pUpdateDocItem && pMacroExecModeItem
+ && pUpdateDocItem->GetValue() == document::UpdateDocMode::NO_UPDATE
+ && pMacroExecModeItem->GetValue() == document::MacroExecMode::NEVER_EXECUTE )
+ return ERRCODE_IO_ACCESSDENIED;
+ }
+
+ // find BASIC method
+ String aQualifiedMethod( INetURLObject::decode(aMacro.Copy( nHashPos+1 ), INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET) );
+ String aArgs;
+ if ( STRING_NOTFOUND != nArgsPos )
+ {
+ // remove arguments from macro name
+ aArgs = aQualifiedMethod.Copy( nArgsPos - nHashPos - 1 );
+ aQualifiedMethod.Erase( nArgsPos - nHashPos - 1 );
+ }
+
+ SbxMethod *pMethod = SfxQueryMacro( pBasMgr, aQualifiedMethod );
+ if ( pMethod )
+ {
+ // arguments must be quoted
+ String aQuotedArgs;
+ if ( aArgs.Len()<2 || aArgs.GetBuffer()[1] == '\"')
+ // no args or already quoted args
+ aQuotedArgs = aArgs;
+ else
+ {
+ // quote parameters
+ aArgs.Erase(0,1);
+ aArgs.Erase( aArgs.Len()-1,1);
+
+ aQuotedArgs = '(';
+
+ sal_uInt16 nCount = aArgs.GetTokenCount(',');
+ for ( sal_uInt16 n=0; n<nCount; n++ )
+ {
+ aQuotedArgs += '\"';
+ aQuotedArgs += aArgs.GetToken( n, ',' );
+ aQuotedArgs += '\"';
+ if ( n<nCount-1 )
+ aQuotedArgs += ',';
+ }
+
+ aQuotedArgs += ')';
+ }
+
+ Any aOldThisComponent;
+ if ( pSh )
+ {
+ if ( pBasMgr != pAppMgr )
+ // mark document: it executes an own macro, so it's in a modal mode
+ pSh->SetMacroMode_Impl( TRUE );
+ if ( pBasMgr == pAppMgr )
+ {
+ // document is executed via AppBASIC, adjust ThisComponent variable
+ aOldThisComponent = pAppMgr->SetGlobalUNOConstant( "ThisComponent", makeAny( pSh->GetModel() ) );
+ }
+ }
+
+ // add quoted arguments and do the call
+ String aCall( '[' );
+ aCall += pMethod->GetName();
+ aCall += aQuotedArgs;
+ aCall += ']';
+
+ // just to let the shell be alive
+ SfxObjectShellRef rSh = pSh;
+
+ // execute function using its Sbx parent,
+ //SbxVariable* pRet = pMethod->GetParent()->Execute( aCall );
+ //rRetval = sbxToUnoValue( pRet );
+
+ SbxVariable* pRet = pMethod->GetParent()->Execute( aCall );
+ if ( pRet )
+ {
+ USHORT nFlags = pRet->GetFlags();
+ pRet->SetFlag( SBX_READWRITE | SBX_NO_BROADCAST );
+ rRetval = sbxToUnoValue( pRet );
+ pRet->SetFlags( nFlags );
+ }
+
+ nErr = SbxBase::GetError();
+ if ( ( pBasMgr == pAppMgr ) && pSh )
+ {
+ pAppMgr->SetGlobalUNOConstant( "ThisComponent", aOldThisComponent );
+ }
+
+ if ( pSh && pSh->GetModel().is() )
+ // remove flag for modal mode
+ pSh->SetMacroMode_Impl( FALSE );
+ }
+ else
+ nErr = ERRCODE_BASIC_PROC_UNDEFINED;
+ }
+ else
+ nErr = ERRCODE_IO_NOTEXISTS;
+ }
+ else
+ {
+ // direct API call on a specified object
+ String aCall( '[' );
+ aCall += String(INetURLObject::decode(aMacro.Copy(6), INET_HEX_ESCAPE,
+ INetURLObject::DECODE_WITH_CHARSET));
+ aCall += ']';
+ pAppMgr->GetLib(0)->Execute( aCall );
+ nErr = SbxBase::GetError();
+ }
+
+ pApp->LeaveBasicCall();
+ SbxBase::ResetError();
+ return nErr;
+}
+
+SFX_IMPL_XSERVICEINFO( SfxAppDispatchProvider, "com.sun.star.frame.DispatchProvider", "com.sun.star.comp.sfx2.AppDispatchProvider" ) \
+SFX_IMPL_SINGLEFACTORY( SfxAppDispatchProvider );
+
+void SAL_CALL SfxAppDispatchProvider::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
+{
+ Reference < XFrame > xFrame;
+ if ( aArguments.getLength() )
+ {
+ aArguments[0] >>= xFrame;
+ m_xFrame = xFrame;
+ }
+}
+
+Reference < XDispatch > SAL_CALL SfxAppDispatchProvider::queryDispatch(
+ const ::com::sun::star::util::URL& aURL,
+ const ::rtl::OUString& /*sTargetFrameName*/,
+ FrameSearchFlags /*eSearchFlags*/ ) throw( RuntimeException )
+{
+ USHORT nId( 0 );
+ sal_Bool bMasterCommand( sal_False );
+ Reference < XDispatch > xDisp;
+ const SfxSlot* pSlot = 0;
+ SfxDispatcher* pAppDisp = SFX_APP()->GetAppDispatcher_Impl();
+ if ( aURL.Protocol.compareToAscii( "slot:" ) == COMPARE_EQUAL ||
+ aURL.Protocol.compareToAscii( "commandId:" ) == COMPARE_EQUAL )
+ {
+ nId = (USHORT) aURL.Path.toInt32();
+ SfxShell* pShell;
+ pAppDisp->GetShellAndSlot_Impl( nId, &pShell, &pSlot, TRUE, TRUE );
+ }
+ else if ( aURL.Protocol.compareToAscii( ".uno:" ) == COMPARE_EQUAL )
+ {
+ // Support ".uno" commands. Map commands to slotid
+ bMasterCommand = SfxOfficeDispatch::IsMasterUnoCommand( aURL );
+ if ( bMasterCommand )
+ pSlot = pAppDisp->GetSlot( SfxOfficeDispatch::GetMasterUnoCommand( aURL ) );
+ else
+ pSlot = pAppDisp->GetSlot( aURL.Main );
+ }
+
+ if ( pSlot )
+ {
+ SfxOfficeDispatch* pDispatch = new SfxOfficeDispatch( pAppDisp, pSlot, aURL ) ;
+ pDispatch->SetFrame(m_xFrame);
+ pDispatch->SetMasterUnoCommand( bMasterCommand );
+ xDisp = pDispatch;
+ }
+
+ return xDisp;
+}
+
+Sequence< Reference < XDispatch > > SAL_CALL SfxAppDispatchProvider::queryDispatches( const Sequence < DispatchDescriptor >& seqDescriptor )
+throw( RuntimeException )
+{
+ sal_Int32 nCount = seqDescriptor.getLength();
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatch > > lDispatcher(nCount);
+ for( sal_Int32 i=0; i<nCount; ++i )
+ lDispatcher[i] = this->queryDispatch( seqDescriptor[i].FeatureURL,
+ seqDescriptor[i].FrameName,
+ seqDescriptor[i].SearchFlags );
+ return lDispatcher;
+}
+
+Sequence< sal_Int16 > SAL_CALL SfxAppDispatchProvider::getSupportedCommandGroups()
+throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ std::list< sal_Int16 > aGroupList;
+ SfxSlotPool* pAppSlotPool = &SFX_APP()->GetAppSlotPool_Impl();
+
+ const ULONG nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
+
+ // Gruppe anw"ahlen ( Gruppe 0 ist intern )
+ for ( USHORT i=0; i<pAppSlotPool->GetGroupCount(); i++ )
+ {
+ String aName = pAppSlotPool->SeekGroup( i );
+ const SfxSlot* pSfxSlot = pAppSlotPool->FirstSlot();
+ while ( pSfxSlot )
+ {
+ if ( pSfxSlot->GetMode() & nMode )
+ {
+ sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
+ aGroupList.push_back( nCommandGroup );
+ break;
+ }
+ pSfxSlot = pAppSlotPool->NextSlot();
+ }
+ }
+
+ ::com::sun::star::uno::Sequence< sal_Int16 > aSeq =
+ comphelper::containerToSequence< sal_Int16, std::list< sal_Int16 > >( aGroupList );
+
+ return aSeq;
+}
+
+Sequence< ::com::sun::star::frame::DispatchInformation > SAL_CALL SfxAppDispatchProvider::getConfigurableDispatchInformation( sal_Int16 nCmdGroup )
+throw (::com::sun::star::uno::RuntimeException)
+{
+ std::list< ::com::sun::star::frame::DispatchInformation > aCmdList;
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ SfxSlotPool* pAppSlotPool = &SFX_APP()->GetAppSlotPool_Impl();
+
+ if ( pAppSlotPool )
+ {
+ const ULONG nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
+ rtl::OUString aCmdPrefix( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
+
+ // Gruppe anw"ahlen ( Gruppe 0 ist intern )
+ for ( USHORT i=0; i<pAppSlotPool->GetGroupCount(); i++ )
+ {
+ String aName = pAppSlotPool->SeekGroup( i );
+ const SfxSlot* pSfxSlot = pAppSlotPool->FirstSlot();
+ if ( pSfxSlot )
+ {
+ sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
+ if ( nCommandGroup == nCmdGroup )
+ {
+ while ( pSfxSlot )
+ {
+ if ( pSfxSlot->GetMode() & nMode )
+ {
+ ::com::sun::star::frame::DispatchInformation aCmdInfo;
+ ::rtl::OUStringBuffer aBuf( aCmdPrefix );
+ aBuf.appendAscii( pSfxSlot->GetUnoName() );
+ aCmdInfo.Command = aBuf.makeStringAndClear();
+ aCmdInfo.GroupId = nCommandGroup;
+ aCmdList.push_back( aCmdInfo );
+ }
+ pSfxSlot = pAppSlotPool->NextSlot();
+ }
+ }
+ }
+ }
+ }
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > aSeq =
+ comphelper::containerToSequence< ::com::sun::star::frame::DispatchInformation, std::list< ::com::sun::star::frame::DispatchInformation > >( aCmdList );
+
+ return aSeq;
+}
+
+#ifdef TEST_HANDLERS
+#include <cppuhelper/implbase2.hxx>
+
+#include <com/sun/star/awt/XKeyHandler.hdl>
+#include <com/sun/star/awt/XMouseClickHandler.hdl>
+
+class TestKeyHandler: public ::cppu::WeakImplHelper2
+<
+ com::sun::star::awt::XKeyHandler,
+ com::sun::star::lang::XServiceInfo
+>
+{
+public:
+ TestKeyHandler( const com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& ){}
+
+ SFX_DECL_XSERVICEINFO
+ virtual sal_Bool SAL_CALL keyPressed( const ::com::sun::star::awt::KeyEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException);
+ virtual sal_Bool SAL_CALL keyReleased( const ::com::sun::star::awt::KeyEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source)
+ throw (::com::sun::star::uno::RuntimeException);
+};
+
+class TestMouseClickHandler: public ::cppu::WeakImplHelper2
+<
+ com::sun::star::awt::XMouseClickHandler,
+ com::sun::star::lang::XServiceInfo
+>
+{
+public:
+ TestMouseClickHandler( const com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& ){}
+
+ SFX_DECL_XSERVICEINFO
+ virtual sal_Bool SAL_CALL mousePressed( const ::com::sun::star::awt::MouseEvent& e ) throw (::com::sun::star::uno::RuntimeException);
+ virtual sal_Bool SAL_CALL mouseReleased( const ::com::sun::star::awt::MouseEvent& e ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source)
+ throw (::com::sun::star::uno::RuntimeException);
+};
+
+sal_Bool SAL_CALL TestKeyHandler::keyPressed( const ::com::sun::star::awt::KeyEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException)
+{
+ return sal_False;
+}
+
+sal_Bool SAL_CALL TestKeyHandler::keyReleased( const ::com::sun::star::awt::KeyEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException)
+{
+ return sal_False;
+}
+
+void SAL_CALL TestKeyHandler::disposing( const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException)
+{
+}
+
+sal_Bool SAL_CALL TestMouseClickHandler::mousePressed( const ::com::sun::star::awt::MouseEvent& e ) throw (::com::sun::star::uno::RuntimeException)
+{
+ return sal_False;
+}
+
+sal_Bool SAL_CALL TestMouseClickHandler::mouseReleased( const ::com::sun::star::awt::MouseEvent& e ) throw (::com::sun::star::uno::RuntimeException)
+{
+ return sal_False;
+}
+
+void SAL_CALL TestMouseClickHandler::disposing( const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException)
+{
+}
+
+SFX_IMPL_XSERVICEINFO( TestKeyHandler, "com.sun.star.task.Job", "com.sun.star.comp.Office.KeyHandler");
+SFX_IMPL_XSERVICEINFO( TestMouseClickHandler, "com.sun.star.task.Job", "com.sun.star.comp.Office.MouseClickHandler");
+SFX_IMPL_SINGLEFACTORY( TestKeyHandler );
+SFX_IMPL_SINGLEFACTORY( TestMouseClickHandler );
+#endif
+// -----------------------------------------------------------------------
+
+extern "C" {
+
+SFX2_DLLPUBLIC void SAL_CALL component_getImplementationEnvironment(
+ const sal_Char** ppEnvironmentTypeName ,
+ uno_Environment** )
+{
+ *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
+}
+
+SFX2_DLLPUBLIC void* SAL_CALL component_getFactory(
+ const sal_Char* pImplementationName ,
+ void* pServiceManager ,
+ void* )
+{
+ // Set default return value for this operation - if it failed.
+ void* pReturn = NULL ;
+
+ if (
+ ( pImplementationName != NULL ) &&
+ ( pServiceManager != NULL )
+ )
+ {
+ // Define variables which are used in following macros.
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
+ xFactory;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager( reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ) ;
+
+ //=============================================================================
+ // Add new macro line to handle new service.
+ //
+ // !!! ATTENTION !!!
+ // Write no ";" at end of line and dont forget "else" ! (see macro)
+ //=============================================================================
+ IF_NAME_CREATECOMPONENTFACTORY( SfxGlobalEvents_Impl )
+ IF_NAME_CREATECOMPONENTFACTORY( SfxFrameLoader_Impl )
+ IF_NAME_CREATECOMPONENTFACTORY( SfxMacroLoader )
+ IF_NAME_CREATECOMPONENTFACTORY( SfxStandaloneDocumentInfoObject )
+ IF_NAME_CREATECOMPONENTFACTORY( SfxAppDispatchProvider )
+ IF_NAME_CREATECOMPONENTFACTORY( SfxDocTplService )
+ IF_NAME_CREATECOMPONENTFACTORY( ShutdownIcon )
+ IF_NAME_CREATECOMPONENTFACTORY( SfxApplicationScriptLibraryContainer )
+ IF_NAME_CREATECOMPONENTFACTORY( SfxApplicationDialogLibraryContainer )
+#ifdef TEST_HANDLERS
+ IF_NAME_CREATECOMPONENTFACTORY( TestKeyHandler )
+ IF_NAME_CREATECOMPONENTFACTORY( TestMouseClickHandler )
+#endif
+ IF_NAME_CREATECOMPONENTFACTORY( OPackageStructureCreator )
+ #if 0
+ if ( ::sfx2::AppletObject::impl_getStaticImplementationName().equals(
+ ::rtl::OUString::createFromAscii( pImplementationName ) ) )
+ {
+ xFactory = ::sfx2::AppletObject::impl_createFactory();
+ }
+ #endif
+ IF_NAME_CREATECOMPONENTFACTORY( ::sfx2::PluginObject )
+ IF_NAME_CREATECOMPONENTFACTORY( ::sfx2::IFrameObject )
+ IF_NAME_CREATECOMPONENTFACTORY( ::sfx2::OwnSubFilterService )
+ if ( ::comp_SfxDocumentMetaData::_getImplementationName().equals(
+ ::rtl::OUString::createFromAscii( pImplementationName ) ) )
+ {
+ xFactory = ::cppu::createSingleComponentFactory(
+ ::comp_SfxDocumentMetaData::_create,
+ ::comp_SfxDocumentMetaData::_getImplementationName(),
+ ::comp_SfxDocumentMetaData::_getSupportedServiceNames());
+ }
+
+ // Factory is valid - service was found.
+ if ( xFactory.is() )
+ {
+ xFactory->acquire();
+ pReturn = xFactory.get();
+ }
+ }
+ // Return with result of this operation.
+ return pReturn ;
+}
+} // extern "C"
+
+//=========================================================================
+
+void SAL_CALL FilterOptionsContinuation::setFilterOptions(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rProps )
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ rProperties = rProps;
+}
+
+::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL
+ FilterOptionsContinuation::getFilterOptions()
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ return rProperties;
+}
+
+//=========================================================================
+
+RequestFilterOptions::RequestFilterOptions( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > rModel,
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > rProperties )
+{
+ ::rtl::OUString temp;
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > temp2;
+ ::com::sun::star::document::FilterOptionsRequest aOptionsRequest( temp,
+ temp2,
+ rModel,
+ rProperties );
+
+ m_aRequest <<= aOptionsRequest;
+
+ m_pAbort = new comphelper::OInteractionAbort;
+ m_pOptions = new FilterOptionsContinuation;
+
+ m_lContinuations.realloc( 2 );
+ m_lContinuations[0] = ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >( m_pAbort );
+ m_lContinuations[1] = ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >( m_pOptions );
+}
+
+::com::sun::star::uno::Any SAL_CALL RequestFilterOptions::getRequest()
+ throw( ::com::sun::star::uno::RuntimeException )
+{
+ return m_aRequest;
+}
+
+::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >
+ SAL_CALL RequestFilterOptions::getContinuations()
+ throw( ::com::sun::star::uno::RuntimeException )
+{
+ return m_lContinuations;
+}
+
+//=========================================================================
+class RequestPackageReparation_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest >
+{
+ ::com::sun::star::uno::Any m_aRequest;
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > m_lContinuations;
+ comphelper::OInteractionApprove* m_pApprove;
+ comphelper::OInteractionDisapprove* m_pDisapprove;
+
+public:
+ RequestPackageReparation_Impl( ::rtl::OUString aName );
+ sal_Bool isApproved();
+ virtual ::com::sun::star::uno::Any SAL_CALL getRequest() throw( ::com::sun::star::uno::RuntimeException );
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > SAL_CALL getContinuations()
+ throw( ::com::sun::star::uno::RuntimeException );
+};
+
+RequestPackageReparation_Impl::RequestPackageReparation_Impl( ::rtl::OUString aName )
+{
+ ::rtl::OUString temp;
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > temp2;
+ ::com::sun::star::document::BrokenPackageRequest aBrokenPackageRequest( temp,
+ temp2,
+ aName );
+ m_aRequest <<= aBrokenPackageRequest;
+ m_pApprove = new comphelper::OInteractionApprove;
+ m_pDisapprove = new comphelper::OInteractionDisapprove;
+ m_lContinuations.realloc( 2 );
+ m_lContinuations[0] = ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >( m_pApprove );
+ m_lContinuations[1] = ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >( m_pDisapprove );
+}
+
+sal_Bool RequestPackageReparation_Impl::isApproved()
+{
+ return m_pApprove->wasSelected();
+}
+
+::com::sun::star::uno::Any SAL_CALL RequestPackageReparation_Impl::getRequest()
+ throw( ::com::sun::star::uno::RuntimeException )
+{
+ return m_aRequest;
+}
+
+::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >
+ SAL_CALL RequestPackageReparation_Impl::getContinuations()
+ throw( ::com::sun::star::uno::RuntimeException )
+{
+ return m_lContinuations;
+}
+
+RequestPackageReparation::RequestPackageReparation( ::rtl::OUString aName )
+{
+ pImp = new RequestPackageReparation_Impl( aName );
+ pImp->acquire();
+}
+
+RequestPackageReparation::~RequestPackageReparation()
+{
+ pImp->release();
+}
+
+sal_Bool RequestPackageReparation::isApproved()
+{
+ return pImp->isApproved();
+}
+
+com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionRequest > RequestPackageReparation::GetRequest()
+{
+ return com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionRequest >(pImp);
+}
+
+//=========================================================================
+class NotifyBrokenPackage_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest >
+{
+ ::com::sun::star::uno::Any m_aRequest;
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > m_lContinuations;
+ comphelper::OInteractionAbort* m_pAbort;
+
+public:
+ NotifyBrokenPackage_Impl( ::rtl::OUString aName );
+ sal_Bool isAborted();
+ virtual ::com::sun::star::uno::Any SAL_CALL getRequest() throw( ::com::sun::star::uno::RuntimeException );
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > SAL_CALL getContinuations()
+ throw( ::com::sun::star::uno::RuntimeException );
+};
+
+NotifyBrokenPackage_Impl::NotifyBrokenPackage_Impl( ::rtl::OUString aName )
+{
+ ::rtl::OUString temp;
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > temp2;
+ ::com::sun::star::document::BrokenPackageRequest aBrokenPackageRequest( temp,
+ temp2,
+ aName );
+ m_aRequest <<= aBrokenPackageRequest;
+ m_pAbort = new comphelper::OInteractionAbort;
+ m_lContinuations.realloc( 1 );
+ m_lContinuations[0] = ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >( m_pAbort );
+}
+
+sal_Bool NotifyBrokenPackage_Impl::isAborted()
+{
+ return m_pAbort->wasSelected();
+}
+
+::com::sun::star::uno::Any SAL_CALL NotifyBrokenPackage_Impl::getRequest()
+ throw( ::com::sun::star::uno::RuntimeException )
+{
+ return m_aRequest;
+}
+
+::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >
+ SAL_CALL NotifyBrokenPackage_Impl::getContinuations()
+ throw( ::com::sun::star::uno::RuntimeException )
+{
+ return m_lContinuations;
+}
+
+NotifyBrokenPackage::NotifyBrokenPackage( ::rtl::OUString aName )
+{
+ pImp = new NotifyBrokenPackage_Impl( aName );
+ pImp->acquire();
+}
+
+NotifyBrokenPackage::~NotifyBrokenPackage()
+{
+ pImp->release();
+}
+
+sal_Bool NotifyBrokenPackage::isAborted()
+{
+ return pImp->isAborted();
+}
+
+com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionRequest > NotifyBrokenPackage::GetRequest()
+{
+ return com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionRequest >(pImp);
+}
+
diff --git a/sfx2/source/appl/childwin.cxx b/sfx2/source/appl/childwin.cxx
new file mode 100644
index 000000000000..b8e8a92da1b8
--- /dev/null
+++ b/sfx2/source/appl/childwin.cxx
@@ -0,0 +1,855 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef _TOOLBOX_HXX //autogen
+#include <vcl/toolbox.hxx>
+#endif
+#ifndef _RCID_H
+#include <tools/rcid.h>
+#endif
+#include <unotools/viewoptions.hxx>
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <cppuhelper/implbase1.hxx>
+
+#ifndef GCC
+#endif
+
+#include <sfx2/childwin.hxx>
+#include <sfx2/app.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/bindings.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/dockwin.hxx>
+#include <sfx2/dispatch.hxx>
+#include "workwin.hxx"
+
+static const sal_uInt16 nVersion = 2;
+
+DBG_NAME(SfxChildWindow)
+
+SV_IMPL_PTRARR( SfxChildWinContextArr_Impl, SfxChildWinContextFactory* );
+
+struct SfxChildWindow_Impl
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > xListener;
+ SfxChildWinFactory* pFact;
+ sal_Bool bHideNotDelete;
+ sal_Bool bVisible;
+ sal_Bool bHideAtToggle;
+ sal_Bool bWantsFocus;
+ SfxModule* pContextModule;
+ SfxWorkWindow* pWorkWin;
+};
+
+// -----------------------------------------------------------------------
+
+class DisposeListener : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
+{
+ public:
+ DisposeListener( SfxChildWindow* pOwner ,
+ SfxChildWindow_Impl* pData )
+ : m_pOwner( pOwner )
+ , m_pData ( pData )
+ {}
+
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aSource ) throw (::com::sun::star::uno::RuntimeException)
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > xSelfHold( this );
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( aSource.Source, ::com::sun::star::uno::UNO_QUERY );
+ if( xComp.is() )
+ xComp->removeEventListener( this );
+
+ if( m_pOwner && m_pData )
+ {
+ m_pData->xListener = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >();
+
+ if ( m_pData->pWorkWin )
+ {
+ // m_pOwner and m_pData will be killed
+ m_pData->xFrame = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >();
+ m_pData->pWorkWin->GetBindings().Execute( m_pOwner->GetType() );
+ }
+ else
+ {
+ delete m_pOwner;
+ }
+
+ m_pOwner = NULL;
+ m_pData = NULL;
+ }
+ }
+
+ private:
+ SfxChildWindow* m_pOwner;
+ SfxChildWindow_Impl* m_pData ;
+};
+
+// -----------------------------------------------------------------------
+
+sal_Bool GetPosSizeFromString( const String& rStr, Point& rPos, Size& rSize )
+{
+ if ( rStr.GetTokenCount('/') != 4 )
+ return sal_False;
+
+ xub_StrLen nIdx = 0;
+ rPos.X() = rStr.GetToken(0, '/', nIdx).ToInt32();
+ rPos.Y() = rStr.GetToken(0, '/', nIdx).ToInt32();
+ rSize.Width() = rStr.GetToken(0, '/', nIdx).ToInt32();
+ rSize.Height() = rStr.GetToken(0, '/', nIdx).ToInt32();
+
+ // negative sizes are invalid
+ if ( rSize.Width() < 0 || rSize.Height() < 0 )
+ return sal_False;
+
+ return sal_True;
+}
+
+sal_Bool GetSplitSizeFromString( const String& rStr, Size& rSize )
+{
+ xub_StrLen nIndex = rStr.Search( ',' );
+ if ( nIndex != STRING_NOTFOUND )
+ {
+ String aStr = rStr.Copy( nIndex+1 );
+
+ sal_Int32 nCount = aStr.GetTokenCount(';');
+ if ( nCount != 2 )
+ return sal_False;
+
+ rSize.Width() = aStr.GetToken(0, ';' ).ToInt32();
+ rSize.Height() = aStr.GetToken(1, ';' ).ToInt32();
+
+ // negative sizes are invalid
+ if ( rSize.Width() < 0 || rSize.Height() < 0 )
+ return sal_False;
+
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+//=========================================================================
+SfxChildWindow::SfxChildWindow(Window *pParentWindow, sal_uInt16 nId)
+ : pParent(pParentWindow)
+ , nType(nId)
+ , eChildAlignment(SFX_ALIGN_NOALIGNMENT)
+ , pWindow(0L)
+{
+ pImp = new SfxChildWindow_Impl;
+ pImp->pFact = 0L;
+ pImp->bHideNotDelete = sal_False;
+ pImp->bHideAtToggle = sal_False;
+ pImp->bWantsFocus = sal_True;
+ pImp->bVisible = sal_True;
+ pImp->pContextModule = NULL;
+ pImp->pWorkWin = NULL;
+
+ pContext = 0L;
+ DBG_CTOR(SfxChildWindow,0);
+}
+
+void SfxChildWindow::Destroy()
+{
+ if ( GetFrame().is() )
+ {
+ pImp->pWorkWin = NULL;
+ try
+ {
+ ::com::sun::star::uno::Reference < ::com::sun::star::util::XCloseable > xClose( GetFrame(), ::com::sun::star::uno::UNO_QUERY );
+ if ( xClose.is() )
+ xClose->close( sal_True );
+ else
+ GetFrame()->dispose();
+ }
+ catch ( com::sun::star::uno::Exception& )
+ {
+ }
+ }
+ else
+ delete this;
+}
+
+//-------------------------------------------------------------------------
+SfxChildWindow::~SfxChildWindow()
+{
+ DBG_DTOR(SfxChildWindow,0);
+ if ( pContext )
+ delete pContext;
+ if ( pWindow )
+ delete pWindow;
+ delete pImp;
+}
+
+//-------------------------------------------------------------------------
+SfxChildWindow* SfxChildWindow::CreateChildWindow( sal_uInt16 nId,
+ Window *pParent, SfxBindings* pBindings, SfxChildWinInfo& rInfo)
+{
+ SfxChildWindow *pChild=0;
+ SfxChildWinFactory* pFact=0;
+ sal_uInt16 nOldMode = Application::GetSystemWindowMode();
+
+ // Zuerst ChildWindow im SDT suchen; "Uberlagerungen m"ussen mit einem
+ // ChildWindowContext realisiert werden
+ SfxApplication *pApp = SFX_APP();
+ {
+ SfxChildWinFactArr_Impl &rFactories = pApp->GetChildWinFactories_Impl();
+ for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ {
+ pFact = rFactories[nFactory];
+ if ( pFact->nId == nId )
+ {
+ SfxChildWinInfo& rFactInfo = pFact->aInfo;
+ if ( rInfo.bVisible )
+ {
+ if ( pBindings )
+ pBindings->ENTERREGISTRATIONS();
+ SfxChildWinInfo aInfo = rFactInfo;
+ Application::SetSystemWindowMode( SYSTEMWINDOW_MODE_NOAUTOMODE );
+ pChild = pFact->pCtor( pParent, nId, pBindings, &aInfo );
+ Application::SetSystemWindowMode( nOldMode );
+ if ( pBindings )
+ pBindings->LEAVEREGISTRATIONS();
+ }
+
+ break;
+ }
+ }
+ }
+
+ SfxDispatcher *pDisp = pBindings->GetDispatcher_Impl();
+ SfxModule *pMod = pDisp ? SfxModule::GetActiveModule( pDisp->GetFrame() ) :0;
+ if ( !pChild && pMod )
+ {
+ SfxChildWinFactArr_Impl *pFactories = pMod->GetChildWinFactories_Impl();
+ if ( pFactories )
+ {
+ SfxChildWinFactArr_Impl &rFactories = *pFactories;
+ for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ {
+ pFact = rFactories[nFactory];
+ if ( pFact->nId == nId )
+ {
+ SfxChildWinInfo& rFactInfo = pFact->aInfo;
+ if ( rInfo.bVisible )
+ {
+ if ( pBindings )
+ pBindings->ENTERREGISTRATIONS();
+ SfxChildWinInfo aInfo = rFactInfo;
+ Application::SetSystemWindowMode( SYSTEMWINDOW_MODE_NOAUTOMODE );
+ pChild = pFact->pCtor( pParent, nId, pBindings, &aInfo );
+ Application::SetSystemWindowMode( nOldMode );
+ if ( pBindings )
+ pBindings->LEAVEREGISTRATIONS();
+ }
+
+ break;
+ }
+ }
+ }
+ }
+
+ if ( pChild )
+ pChild->SetFactory_Impl( pFact );
+
+ DBG_ASSERT(pFact && (pChild || !rInfo.bVisible), "ChildWindow-Typ nicht registriert!");
+
+ if ( pChild && !pChild->pWindow )
+ {
+ DELETEZ(pChild);
+ DBG_WARNING("ChildWindow hat kein Fenster!");
+ }
+
+ return pChild;
+}
+
+//-------------------------------------------------------------------------
+void SfxChildWindow::SaveStatus(const SfxChildWinInfo& rInfo)
+{
+ sal_uInt16 nID = GetType();
+
+ String aWinData( 'V' );
+ aWinData += String::CreateFromInt32( nVersion );
+ aWinData += ',';
+ aWinData += rInfo.bVisible ? 'V' : 'H';
+ aWinData += ',';
+ aWinData += String::CreateFromInt32( rInfo.nFlags );
+ if ( rInfo.aExtraString.Len() )
+ {
+ aWinData += ',';
+ aWinData += rInfo.aExtraString;
+ }
+
+ SvtViewOptions aWinOpt( E_WINDOW, String::CreateFromInt32( nID ) );
+ // aWinOpt.SetPosition( rInfo.aPos.X(), rInfo.aPos.Y() );
+ // aWinOpt.SetSize( rInfo.aSize.Width(), rInfo.aSize.Height() );
+ aWinOpt.SetWindowState( String( rInfo.aWinState, RTL_TEXTENCODING_UTF8 ) );
+
+ ::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq(1);
+ aSeq[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Data") );
+ aSeq[0].Value <<= ::rtl::OUString( aWinData );
+ aWinOpt.SetUserData( aSeq );
+
+ // ... but save status at runtime!
+ pImp->pFact->aInfo = rInfo;
+}
+
+//-------------------------------------------------------------------------
+void SfxChildWindow::SetAlignment(SfxChildAlignment eAlign)
+{
+ DBG_CHKTHIS(SfxChildWindow,0);
+
+ eChildAlignment = eAlign;
+}
+
+//-------------------------------------------------------------------------
+void SfxChildWindow::SetPosSizePixel(const Point& rPoint, Size& rSize)
+{
+ DBG_CHKTHIS(SfxChildWindow,0);
+
+ pWindow->SetPosSizePixel(rPoint, rSize);
+}
+
+//-------------------------------------------------------------------------
+SfxChildWinInfo SfxChildWindow::GetInfo() const
+{
+ DBG_CHKTHIS(SfxChildWindow,0);
+
+ SfxChildWinInfo aInfo;
+ aInfo.aPos = pWindow->GetPosPixel();
+ aInfo.aSize = pWindow->GetSizePixel();
+ if ( pWindow->IsSystemWindow() )
+ {
+ ULONG nMask = WINDOWSTATE_MASK_POS | WINDOWSTATE_MASK_STATE;
+ if ( pWindow->GetStyle() & WB_SIZEABLE )
+ nMask |= ( WINDOWSTATE_MASK_WIDTH | WINDOWSTATE_MASK_HEIGHT );
+ aInfo.aWinState = ((SystemWindow*)pWindow)->GetWindowState( nMask );
+ }
+ else if ( pWindow->GetType() == RSC_DOCKINGWINDOW )
+ {
+ if (((DockingWindow*)pWindow)->GetFloatingWindow() )
+ aInfo.aWinState = ((DockingWindow*)pWindow)->GetFloatingWindow()->GetWindowState();
+ else
+ {
+ SfxChildWinInfo aTmpInfo;
+ ((SfxDockingWindow*)pWindow)->FillInfo( aTmpInfo );
+ aInfo.aExtraString = aTmpInfo.aExtraString;
+ }
+ }
+
+ aInfo.bVisible = pImp->bVisible;
+ aInfo.nFlags = 0;
+ return aInfo;
+}
+
+//-------------------------------------------------------------------------
+sal_uInt16 SfxChildWindow::GetPosition()
+{
+ return pImp->pFact->nPos;
+}
+
+#if 0
+static void ImplWindowStateFromStr( Point rPos, Size rSize, const ByteString& rStr )
+{
+ ULONG nValidMask = 0;
+ xub_StrLen nIndex = 0;
+ ByteString aTokenStr;
+
+ aTokenStr = rStr.GetToken( 0, ',', nIndex );
+ if ( aTokenStr.Len() )
+ {
+ rPos.X() = aTokenStr.ToInt32();
+ nValidMask |= WINDOWSTATE_MASK_X;
+ }
+
+ aTokenStr = rStr.GetToken( 0, ',', nIndex );
+ if ( aTokenStr.Len() )
+ {
+ rPos.Y() = aTokenStr.ToInt32();
+ nValidMask |= WINDOWSTATE_MASK_Y;
+ }
+
+ aTokenStr = rStr.GetToken( 0, ',', nIndex );
+ if ( aTokenStr.Len() )
+ {
+ rSize.Width() = aTokenStr.ToInt32();
+ nValidMask |= WINDOWSTATE_MASK_WIDTH;
+ }
+
+ aTokenStr = rStr.GetToken( 0, ';', nIndex );
+ if ( aTokenStr.Len() )
+ {
+ rSize.Height() = aTokenStr.ToInt32();
+ nValidMask |= WINDOWSTATE_MASK_HEIGHT;
+ }
+}
+#endif
+
+//-------------------------------------------------------------------------
+void SfxChildWindow::InitializeChildWinFactory_Impl( sal_uInt16 nId, SfxChildWinInfo& rInfo )
+{
+ // load configuration
+ SvtViewOptions aWinOpt( E_WINDOW, String::CreateFromInt32( nId ) );
+
+ if ( aWinOpt.Exists() )
+ rInfo.bVisible = aWinOpt.IsVisible(); // set state from configuration. Can be overwritten by UserData, see below
+
+ ::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq = aWinOpt.GetUserData();
+
+ ::rtl::OUString aTmp;
+ if ( aSeq.getLength() )
+ aSeq[0].Value >>= aTmp;
+
+ String aWinData( aTmp );
+ rInfo.aWinState = ByteString( String(aWinOpt.GetWindowState()), RTL_TEXTENCODING_UTF8 );
+
+ //ImplWindowStateFromStr( rInfo.aPos, rInfo.aSize, ByteString( aWinState, RTL_TEXTENCODING_UTF8 ) );
+
+ if ( aWinData.Len() )
+ {
+ // Nach Versionskennung suchen
+ if ( aWinData.GetChar((sal_uInt16)0) != 0x0056 ) // 'V' = 56h
+ // Keine Versionskennung, daher nicht verwenden
+ return;
+
+ // 'V' l"oschen
+ aWinData.Erase(0,1);
+
+ // Version lesen
+ char cToken = ',';
+ sal_uInt16 nPos = aWinData.Search( cToken );
+ sal_uInt16 nActVersion = (sal_uInt16)aWinData.Copy( 0, nPos + 1 ).ToInt32();
+ if ( nActVersion != nVersion )
+ return;
+
+ aWinData.Erase(0,nPos+1);
+
+ //aWinOpt.GetPosition( rInfo.aPos.X(), rInfo.aPos.Y() );
+ //aWinOpt.GetSize( rInfo.aSize.Width(), rInfo.aSize.Height() );
+
+ // Sichtbarkeit laden: ist als ein char codiert
+ rInfo.bVisible = (aWinData.GetChar(0) == 0x0056); // 'V' = 56h
+ aWinData.Erase(0,1);
+ nPos = aWinData.Search( cToken );
+ if (nPos != STRING_NOTFOUND)
+ {
+ USHORT nNextPos = aWinData.Search( cToken, 2 );
+ if ( nNextPos != STRING_NOTFOUND )
+ {
+ // es gibt noch Extra-Information
+ rInfo.nFlags = (sal_uInt16)aWinData.Copy( nPos+1, nNextPos - nPos - 1 ).ToInt32();
+ aWinData.Erase( nPos, nNextPos-nPos+1 );
+ rInfo.aExtraString = aWinData;
+ }
+ else
+ rInfo.nFlags = (sal_uInt16)aWinData.Copy( nPos+1 ).ToInt32();
+ }
+ }
+}
+
+void SfxChildWindow::CreateContext( sal_uInt16 nContextId, SfxBindings& rBindings )
+{
+ SfxChildWindowContext *pCon = NULL;
+ SfxChildWinFactory* pFact=0;
+ SfxApplication *pApp = SFX_APP();
+ SfxDispatcher *pDisp = rBindings.GetDispatcher_Impl();
+ SfxModule *pMod = pDisp ? SfxModule::GetActiveModule( pDisp->GetFrame() ) :0;
+ if ( pMod )
+ {
+ SfxChildWinFactArr_Impl *pFactories = pMod->GetChildWinFactories_Impl();
+ if ( pFactories )
+ {
+ SfxChildWinFactArr_Impl &rFactories = *pFactories;
+ for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ {
+ pFact = rFactories[nFactory];
+ if ( pFact->nId == GetType() )
+ {
+ DBG_ASSERT( pFact->pArr, "Kein Kontext angemeldet!" );
+ if ( !pFact->pArr )
+ break;
+
+ SfxChildWinContextFactory *pConFact=0;
+ for ( sal_uInt16 n=0; n<pFact->pArr->Count(); ++n )
+ {
+ pConFact = (*pFact->pArr)[n];
+ rBindings.ENTERREGISTRATIONS();
+ if ( pConFact->nContextId == nContextId )
+ {
+ SfxChildWinInfo aInfo = pFact->aInfo;
+ pCon = pConFact->pCtor( GetWindow(), &rBindings, &aInfo );
+ pCon->nContextId = pConFact->nContextId;
+ pImp->pContextModule = pMod;
+ }
+ rBindings.LEAVEREGISTRATIONS();
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ if ( !pCon )
+ {
+ SfxChildWinFactArr_Impl &rFactories = pApp->GetChildWinFactories_Impl();
+ for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ {
+ pFact = rFactories[nFactory];
+ if ( pFact->nId == GetType() )
+ {
+ DBG_ASSERT( pFact->pArr, "Kein Kontext angemeldet!" );
+ if ( !pFact->pArr )
+ break;
+
+ SfxChildWinContextFactory *pConFact=0;
+ for ( sal_uInt16 n=0; n<pFact->pArr->Count(); ++n )
+ {
+ pConFact = (*pFact->pArr)[n];
+ rBindings.ENTERREGISTRATIONS();
+ if ( pConFact->nContextId == nContextId )
+ {
+ SfxChildWinInfo aInfo = pFact->aInfo;
+ pCon = pConFact->pCtor( GetWindow(), &rBindings, &aInfo );
+ pCon->nContextId = pConFact->nContextId;
+ pImp->pContextModule = NULL;
+ }
+ rBindings.LEAVEREGISTRATIONS();
+ }
+ break;
+ }
+ }
+ }
+
+ if ( !pCon )
+ {
+ DBG_ERROR( "Kein geeigneter Context gefunden!" );
+ return;
+ }
+
+ if ( pContext )
+ delete( pContext );
+ pContext = pCon;
+ pContext->GetWindow()->SetSizePixel( pWindow->GetOutputSizePixel() );
+ pContext->GetWindow()->Show();
+}
+
+SfxChildWindowContext::SfxChildWindowContext( sal_uInt16 nId )
+ : pWindow( NULL )
+ , nContextId( nId )
+{
+}
+
+SfxChildWindowContext::~SfxChildWindowContext()
+{
+ delete pWindow;
+}
+
+FloatingWindow* SfxChildWindowContext::GetFloatingWindow() const
+{
+ Window *pParent = pWindow->GetParent();
+ if ( pParent->GetType() == RSC_DOCKINGWINDOW || pParent->GetType() == RSC_TOOLBOX )
+ {
+ return ((DockingWindow*)pParent)->GetFloatingWindow();
+ }
+ else if ( pParent->GetType() == RSC_FLOATINGWINDOW )
+ {
+ return (FloatingWindow*) pParent;
+ }
+ else
+ {
+ DBG_ERROR("Kein FloatingWindow-Context!");
+ return NULL;
+ }
+}
+
+SfxChildAlignment SfxChildWindowContext::GetAlignment() const
+{
+ Window *pParent = pWindow->GetParent();
+ if ( pParent->GetType() == RSC_DOCKINGWINDOW )
+ {
+ return ((SfxDockingWindow*)pParent)->GetAlignment();
+ }
+ else if ( pParent->GetType() == RSC_TOOLBOX )
+ {
+ HACK(noch nicht verwendet und noch nicht implementiert);
+ return SFX_ALIGN_NOALIGNMENT;
+ }
+ else
+ return SFX_ALIGN_NOALIGNMENT;
+}
+
+void SfxChildWindowContext::Resizing( Size& )
+{
+}
+
+sal_Bool SfxChildWindowContext::Close()
+{
+ return sal_True;
+}
+
+void SfxChildWindow::SetFactory_Impl( SfxChildWinFactory *pF )
+{
+ pImp->pFact = pF;
+}
+
+void SfxChildWindow::SetHideNotDelete( sal_Bool bOn )
+{
+ pImp->bHideNotDelete = bOn;
+}
+
+sal_Bool SfxChildWindow::IsHideNotDelete() const
+{
+ return pImp->bHideNotDelete;
+}
+
+void SfxChildWindow::SetHideAtToggle( sal_Bool bOn )
+{
+ pImp->bHideAtToggle = bOn;
+}
+
+sal_Bool SfxChildWindow::IsHideAtToggle() const
+{
+ return pImp->bHideAtToggle;
+}
+
+void SfxChildWindow::SetWantsFocus( BOOL bSet )
+{
+ pImp->bWantsFocus = bSet;
+}
+
+sal_Bool SfxChildWindow::WantsFocus() const
+{
+ return pImp->bWantsFocus;
+}
+
+sal_Bool SfxChildWinInfo::GetExtraData_Impl
+(
+ SfxChildAlignment *pAlign,
+ SfxChildAlignment *pLastAlign,
+ Size *pSize,
+ sal_uInt16 *pLine,
+ sal_uInt16 *pPos
+) const
+{
+ // ung"ultig?
+ if ( !aExtraString.Len() )
+ return sal_False;
+ String aStr;
+ sal_uInt16 nPos = aExtraString.SearchAscii("AL:");
+ if ( nPos == STRING_NOTFOUND )
+ return sal_False;
+
+ // Versuche, den Alignment-String "ALIGN:(...)" einzulesen; wenn
+ // er nicht vorhanden ist, liegt eine "altere Version vor
+ if ( nPos != STRING_NOTFOUND )
+ {
+ sal_uInt16 n1 = aExtraString.Search('(', nPos);
+ if ( n1 != STRING_NOTFOUND )
+ {
+ sal_uInt16 n2 = aExtraString.Search(')', n1);
+ if ( n2 != STRING_NOTFOUND )
+ {
+ // Alignment-String herausschneiden
+ aStr = aExtraString.Copy(nPos, n2 - nPos + 1);
+ aStr.Erase(nPos, n1-nPos+1);
+ }
+ }
+ }
+
+ // Zuerst das Alignment extrahieren
+ if ( !aStr.Len() )
+ return sal_False;
+ if ( pAlign )
+ *pAlign = (SfxChildAlignment) (sal_uInt16) aStr.ToInt32();
+
+ // Dann das LastAlignment
+ nPos = aStr.Search(',');
+ if ( nPos == STRING_NOTFOUND )
+ return sal_False;
+ aStr.Erase(0, nPos+1);
+ if ( pLastAlign )
+ *pLastAlign = (SfxChildAlignment) (sal_uInt16) aStr.ToInt32();
+
+ // Dann die Splitting-Informationen
+ nPos = aStr.Search(',');
+ if ( nPos == STRING_NOTFOUND )
+ // Dockt nicht in einem Splitwindow
+ return sal_True;
+ aStr.Erase(0, nPos+1);
+ Point aChildPos;
+ Size aChildSize;
+ if ( GetPosSizeFromString( aStr, aChildPos, aChildSize ) )
+ {
+ if ( pSize )
+ *pSize = aChildSize;
+ if ( pLine )
+ *pLine = (sal_uInt16) aChildPos.X();
+ if ( pPos )
+ *pPos = (sal_uInt16) aChildPos.Y();
+ return sal_True;
+ }
+ return sal_False;
+}
+
+sal_Bool SfxChildWindow::IsVisible() const
+{
+ return pImp->bVisible;
+}
+
+void SfxChildWindow::SetVisible_Impl( sal_Bool bVis )
+{
+ pImp->bVisible = bVis;
+}
+
+void SfxChildWindow::Hide()
+{
+ switch ( pWindow->GetType() )
+ {
+ case RSC_DOCKINGWINDOW :
+ ((DockingWindow*)pWindow)->Hide();
+ break;
+ case RSC_TOOLBOX :
+ ((ToolBox*)pWindow)->Hide();
+ break;
+ default:
+ pWindow->Hide();
+ break;
+ }
+}
+
+
+
+void SfxChildWindow::Show( USHORT nFlags )
+{
+ switch ( pWindow->GetType() )
+ {
+ case RSC_DOCKINGWINDOW :
+ ((DockingWindow*)pWindow)->Show( TRUE, nFlags );
+ break;
+ case RSC_TOOLBOX :
+ ((ToolBox*)pWindow)->Show( TRUE, nFlags );
+ break;
+ default:
+ pWindow->Show( TRUE, nFlags );
+ break;
+ }
+}
+
+Window* SfxChildWindow::GetContextWindow( SfxModule *pModule ) const
+{
+ return pModule == pImp->pContextModule && pContext ? pContext->GetWindow(): 0;
+}
+
+void SfxChildWindow::SetWorkWindow_Impl( SfxWorkWindow* pWin )
+{
+ pImp->pWorkWin = pWin;
+ if ( pWin && pWindow->HasChildPathFocus() )
+ pImp->pWorkWin->SetActiveChild_Impl( pWindow );
+}
+
+//SfxWorkWindow* SfxChildWindow::GetWorkWindow_Impl() const
+//{
+// return pImp->pWorkWin;
+//}
+
+void SfxChildWindow::Activate_Impl()
+{
+ if(pImp->pWorkWin!=NULL) //@#60568#
+ pImp->pWorkWin->SetActiveChild_Impl( pWindow );
+}
+
+void SfxChildWindow::Deactivate_Impl()
+{
+// pImp->pWorkWin->SetActiveChild_Impl( NULL );
+}
+
+sal_Bool SfxChildWindow::QueryClose()
+{
+ sal_Bool bAllow = sal_True;
+
+ if ( pImp->xFrame.is() )
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > xCtrl = pImp->xFrame->getController();
+ if ( xCtrl.is() )
+ bAllow = xCtrl->suspend( sal_True );
+ }
+
+ if ( bAllow )
+ bAllow = !GetWindow()->IsInModalMode();
+
+ return bAllow;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SfxChildWindow::GetFrame()
+{
+ return pImp->xFrame;
+}
+
+void SfxChildWindow::SetFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > & rFrame )
+{
+ // Do nothing if nothing will be changed ...
+ if( pImp->xFrame != rFrame )
+ {
+ // ... but stop listening on old frame, if connection exist!
+ if( pImp->xFrame.is() )
+ pImp->xFrame->removeEventListener( pImp->xListener );
+
+ // If new frame isnt NULL -> we must guarantee valid listener for disposing events.
+ // Use already existing or create new one.
+ if( rFrame.is() )
+ if( !pImp->xListener.is() )
+ pImp->xListener = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >( new DisposeListener( this, pImp ) );
+
+ // Set new frame in data container
+ // and build new listener connection, if neccessary.
+ pImp->xFrame = rFrame;
+ if( pImp->xFrame.is() )
+ pImp->xFrame->addEventListener( pImp->xListener );
+ }
+}
+
+sal_Bool SfxChildWindow::CanGetFocus() const
+{
+ return !(pImp->pFact->aInfo.nFlags & SFX_CHILDWIN_CANTGETFOCUS);
+}
+
+void SfxChildWindowContext::RegisterChildWindowContext(SfxModule* pMod, USHORT nId, SfxChildWinContextFactory* pFact)
+{
+ SFX_APP()->RegisterChildWindowContext_Impl( pMod, nId, pFact );
+}
+
+void SfxChildWindow::RegisterChildWindow(SfxModule* pMod, SfxChildWinFactory* pFact)
+{
+ SFX_APP()->RegisterChildWindow_Impl( pMod, pFact );
+}
+
diff --git a/sfx2/source/appl/dde.hrc b/sfx2/source/appl/dde.hrc
new file mode 100644
index 000000000000..d3e178606809
--- /dev/null
+++ b/sfx2/source/appl/dde.hrc
@@ -0,0 +1,40 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_DDE_HRC
+#define _SFX_DDE_HRC
+
+#include "app.hrc"
+
+#define ED_DDE_APP 50
+#define ED_DDE_TOPIC 51
+#define ED_DDE_ITEM 52
+#define FT_DDE_APP 53
+#define FT_DDE_TOPIC 54
+#define FT_DDE_ITEM 55
+#define GROUP_DDE_CHG 56
+
+#endif
diff --git a/sfx2/source/appl/dde.src b/sfx2/source/appl/dde.src
new file mode 100644
index 000000000000..18f6517f181c
--- /dev/null
+++ b/sfx2/source/appl/dde.src
@@ -0,0 +1,95 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "dde.hrc"
+
+ModalDialog MD_DDE_LINKEDIT
+{
+ HelpID = "sfx2:ModalDialog:MD_DDE_LINKEDIT";
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 223 , 74 ) ;
+ Text [ en-US ] = "Modify Link" ;
+ Moveable = TRUE ;
+ FixedText FT_DDE_APP
+ {
+ Pos = MAP_APPFONT ( 12 , 16 ) ;
+ Size = MAP_APPFONT ( 40 , 8 ) ;
+ Text [ en-US ] = "~Application:" ;
+ };
+ Edit ED_DDE_APP
+ {
+ HelpID = "sfx2:Edit:MD_DDE_LINKEDIT:ED_DDE_APP";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 55 , 14 ) ;
+ Size = MAP_APPFONT ( 100 , 12 ) ;
+ };
+ FixedText FT_DDE_TOPIC
+ {
+ Pos = MAP_APPFONT ( 12 , 34 ) ;
+ Size = MAP_APPFONT ( 40 , 8 ) ;
+ Text [ en-US ] = "~File:" ;
+ };
+ Edit ED_DDE_TOPIC
+ {
+ HelpID = "sfx2:Edit:MD_DDE_LINKEDIT:ED_DDE_TOPIC";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 55 , 32 ) ;
+ Size = MAP_APPFONT ( 100 , 12 ) ;
+ };
+ FixedText FT_DDE_ITEM
+ {
+ Pos = MAP_APPFONT ( 12 , 52 ) ;
+ Size = MAP_APPFONT ( 40 , 8 ) ;
+ Text [ en-US ] = "~Category:" ;
+ };
+ Edit ED_DDE_ITEM
+ {
+ HelpID = "sfx2:Edit:MD_DDE_LINKEDIT:ED_DDE_ITEM";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 55 , 50 ) ;
+ Size = MAP_APPFONT ( 100 , 12 ) ;
+ };
+ FixedLine GROUP_DDE_CHG
+ {
+ Pos = MAP_APPFONT ( 6 , 3 ) ;
+ Size = MAP_APPFONT ( 155 , 8 ) ;
+ Text [ en-US ] = "Modify link" ;
+ };
+ OKButton 1
+ {
+ Pos = MAP_APPFONT ( 167 , 6 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ DefButton = TRUE ;
+ };
+ CancelButton 1
+ {
+ Pos = MAP_APPFONT ( 167 , 23 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ };
+};
+
diff --git a/sfx2/source/appl/fileobj.cxx b/sfx2/source/appl/fileobj.cxx
new file mode 100644
index 000000000000..cb53305e4b01
--- /dev/null
+++ b/sfx2/source/appl/fileobj.cxx
@@ -0,0 +1,706 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <vcl/wrkwin.hxx>
+#include <vcl/msgbox.hxx>
+#include <tools/urlobj.hxx>
+#include <tools/stream.hxx>
+#include <sot/formats.hxx>
+#include <svtools/filter.hxx>
+#include <sfx2/lnkbase.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/progress.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/filedlghelper.hxx>
+#include <sot/exchange.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <sfx2/docfac.hxx>
+#include <com/sun/star/document/XTypeDetection.hpp>
+#include <comphelper/mediadescriptor.hxx>
+#include <comphelper/processfactory.hxx>
+#include <sfx2/linkmgr.hxx>
+#include <sfx2/opengrf.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "fileobj.hxx"
+#include "app.hrc"
+
+namespace css = ::com::sun::star;
+
+#define FILETYPE_TEXT 1
+#define FILETYPE_GRF 2
+#define FILETYPE_OBJECT 3
+
+struct Impl_DownLoadData
+{
+ Graphic aGrf;
+ Timer aTimer;
+
+ Impl_DownLoadData( const Link& rLink )
+ {
+ aTimer.SetTimeout( 100 );
+ aTimer.SetTimeoutHdl( rLink );
+ aGrf.SetDefaultType();
+ }
+ ~Impl_DownLoadData()
+ {
+ aTimer.Stop();
+ }
+};
+
+// --------------------------------------------------------------------------
+
+
+SvFileObject::SvFileObject() :
+ pDownLoadData( NULL ), pOldParent( NULL ), nType( FILETYPE_TEXT )
+{
+ bLoadAgain = TRUE;
+ bSynchron = bLoadError = bWaitForData = bDataReady = bNativFormat =
+ bClearMedium = bStateChangeCalled = bInCallDownLoad = FALSE;
+}
+
+
+SvFileObject::~SvFileObject()
+{
+ if ( xMed.Is() )
+ {
+ xMed->SetDataAvailableLink( Link() );
+ xMed->SetDoneLink( Link() );
+ xMed.Clear();
+ }
+ delete pDownLoadData;
+}
+
+
+BOOL SvFileObject::GetData( ::com::sun::star::uno::Any & rData,
+ const String & rMimeType,
+ BOOL bGetSynchron )
+{
+ ULONG nFmt = SotExchange::GetFormatStringId( rMimeType );
+ switch( nType )
+ {
+ case FILETYPE_TEXT:
+ if( FORMAT_FILE == nFmt )
+ {
+ // das Medium muss in der Applikation geoffnet werden, um die
+ // relativen Datei Links aufzuloesen!!!! Wird ueber den
+ // LinkManager und damit von dessen Storage erledigt.
+ rData <<= rtl::OUString( sFileNm );
+ }
+ break;
+
+ case FILETYPE_GRF:
+ if( !bLoadError )
+ {
+ SfxMediumRef xTmpMed;
+
+ if( FORMAT_GDIMETAFILE == nFmt || FORMAT_BITMAP == nFmt ||
+ SOT_FORMATSTR_ID_SVXB == nFmt )
+ {
+ Graphic aGrf;
+
+ //JP 15.07.98: Bug 52959
+ // falls das Nativformat doch erwuenscht ist, muss am
+ // Ende das Flag zurueckgesetzt werden.
+// wird einzig und allein im sw/ndgrf.cxx benutzt, wenn der Link vom
+// GraphicNode entfernt wird.
+ BOOL bOldNativFormat = bNativFormat;
+//!!?? bNativFormat = 0 != (ASPECT_ICON & pSvData->GetAspect());
+
+ // falls gedruckt werden soll, warten wir bis die
+ // Daten vorhanden sind
+ if( bGetSynchron )
+ {
+ // testhalber mal ein LoadFile rufen um das nach-
+ // laden ueberahaupt anzustossen
+ if( !xMed.Is() )
+ LoadFile_Impl();
+
+ if( !bInCallDownLoad )
+ {
+ xTmpMed = xMed;
+ while( bWaitForData )
+ Application::Reschedule();
+
+ xMed = xTmpMed;
+ bClearMedium = TRUE;
+ }
+ }
+
+ if( pDownLoadData ||
+ ( !bWaitForData && ( xMed.Is() || // wurde als URL geladen
+ ( bSynchron && LoadFile_Impl() && xMed.Is() ) )) )
+ {
+ // falls
+
+ // falls es uebers Internet gesogen wurde, nicht
+ // wieder versuchen
+ if( !bGetSynchron )
+ bLoadAgain = !xMed->IsRemote();
+ bLoadError = !GetGraphic_Impl( aGrf, xMed->GetInStream() );
+ }
+ else if( !LoadFile_Impl() ||
+ !GetGraphic_Impl( aGrf, xMed.Is() ? xMed->GetInStream() : 0 ))
+ {
+ if( !xMed.Is() )
+ break;
+ aGrf.SetDefaultType();
+ }
+
+ if( SOT_FORMATSTR_ID_SVXB != nFmt )
+ nFmt = (bLoadError || GRAPHIC_BITMAP == aGrf.GetType())
+ ? FORMAT_BITMAP
+ : FORMAT_GDIMETAFILE;
+
+ SvMemoryStream aMemStm( 0, 65535 );
+ switch ( nFmt )
+ {
+ case SOT_FORMATSTR_ID_SVXB:
+ if( GRAPHIC_NONE != aGrf.GetType() )
+ {
+ aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
+ aMemStm << aGrf;
+ }
+ break;
+
+ case FORMAT_BITMAP:
+ if( !aGrf.GetBitmap().IsEmpty())
+ aMemStm << aGrf.GetBitmap();
+ break;
+
+ default:
+ if( aGrf.GetGDIMetaFile().GetActionCount() )
+ {
+ GDIMetaFile aMeta( aGrf.GetGDIMetaFile() );
+ aMeta.Write( aMemStm );
+ }
+ }
+ rData <<= css::uno::Sequence< sal_Int8 >( (sal_Int8*) aMemStm.GetData(),
+ aMemStm.Seek( STREAM_SEEK_TO_END ) );
+
+ bNativFormat = bOldNativFormat;
+
+ // alles fertig?
+ if( xMed.Is() && !bSynchron && bClearMedium )
+ {
+ xMed.Clear();
+ bClearMedium = FALSE;
+ }
+ }
+ }
+ break;
+ case FILETYPE_OBJECT:
+ // TODO/LATER: possibility to insert a new object
+ rData <<= rtl::OUString( sFileNm );
+ break;
+ }
+ return sal_True/*0 != aTypeList.Count()*/;
+}
+
+
+
+
+BOOL SvFileObject::Connect( sfx2::SvBaseLink* pLink )
+{
+ if( !pLink || !pLink->GetLinkManager() )
+ return FALSE;
+
+ // teste doch mal, ob nicht ein anderer Link mit der gleichen
+ // Verbindung schon existiert
+ pLink->GetLinkManager()->GetDisplayNames( pLink, 0, &sFileNm, 0, &sFilter );
+
+ if( OBJECT_CLIENT_GRF == pLink->GetObjType() )
+ {
+ SfxObjectShellRef pShell = pLink->GetLinkManager()->GetPersist();
+ if( pShell.Is() )
+ {
+ if( pShell->IsAbortingImport() )
+ return FALSE;
+
+ if( pShell->GetMedium() )
+ sReferer = pShell->GetMedium()->GetName();
+ }
+ }
+
+ switch( pLink->GetObjType() )
+ {
+ case OBJECT_CLIENT_GRF:
+ nType = FILETYPE_GRF;
+ bSynchron = pLink->IsSynchron();
+ break;
+
+ case OBJECT_CLIENT_FILE:
+ nType = FILETYPE_TEXT;
+ break;
+
+ case OBJECT_CLIENT_OLE:
+ nType = FILETYPE_OBJECT;
+ // TODO/LATER: introduce own type to be used for exchanging
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ SetUpdateTimeout( 0 );
+
+ // und jetzt bei diesem oder gefundenem Pseudo-Object anmelden
+ AddDataAdvise( pLink, SotExchange::GetFormatMimeType( pLink->GetContentType()), 0 );
+ return TRUE;
+}
+
+
+BOOL SvFileObject::LoadFile_Impl()
+{
+ // wir sind noch im Laden!!
+ if( bWaitForData || !bLoadAgain || xMed.Is() || pDownLoadData )
+ return FALSE;
+
+ // z.Z. nur auf die aktuelle DocShell
+ xMed = new SfxMedium( sFileNm, STREAM_STD_READ, TRUE );
+ SvLinkSource::StreamToLoadFrom aStreamToLoadFrom =
+ getStreamToLoadFrom();
+ xMed->setStreamToLoadFrom(
+ aStreamToLoadFrom.m_xInputStreamToLoadFrom,
+ aStreamToLoadFrom.m_bIsReadOnly);
+ // setStreamToLoadFrom(0,0);
+ if( sReferer.Len() )
+ xMed->SetReferer( sReferer );
+
+ if( !bSynchron )
+ {
+ bLoadAgain = bDataReady = bInNewData = FALSE;
+ bWaitForData = TRUE;
+
+ SfxMediumRef xTmpMed = xMed;
+ xMed->SetDataAvailableLink( STATIC_LINK( this, SvFileObject, LoadGrfNewData_Impl ) );
+ bInCallDownLoad = TRUE;
+ xMed->DownLoad( STATIC_LINK( this, SvFileObject, LoadGrfReady_Impl ) );
+ bInCallDownLoad = FALSE;
+
+ bClearMedium = !xMed.Is();
+ if( bClearMedium )
+ xMed = xTmpMed; // falls gleich im DownLoad schon schluss ist
+ return bDataReady;
+ }
+
+ bWaitForData = TRUE;
+ bDataReady = bInNewData = FALSE;
+ xMed->DownLoad();
+ bLoadAgain = !xMed->IsRemote();
+ bWaitForData = FALSE;
+
+ // Grafik ist fertig, also DataChanged von der Statusaederung schicken:
+ SendStateChg_Impl( xMed->GetInStream() && xMed->GetInStream()->GetError()
+ ? sfx2::LinkManager::STATE_LOAD_ERROR : sfx2::LinkManager::STATE_LOAD_OK );
+ return TRUE;
+}
+
+
+BOOL SvFileObject::GetGraphic_Impl( Graphic& rGrf, SvStream* pStream )
+{
+ GraphicFilter* pGF = GraphicFilter::GetGraphicFilter();
+
+ const USHORT nFilter = sFilter.Len() && pGF->GetImportFormatCount()
+ ? pGF->GetImportFormatNumber( sFilter )
+ : GRFILTER_FORMAT_DONTKNOW;
+
+ String aEmptyStr;
+ int nRes;
+
+ // vermeiden, dass ein native Link angelegt wird
+ if( ( !pStream || !pDownLoadData ) && !rGrf.IsLink() &&
+ !rGrf.GetContext() && !bNativFormat )
+ rGrf.SetLink( GfxLink() );
+
+ if( !pStream )
+ nRes = xMed.Is() ? GRFILTER_OPENERROR
+ : pGF->ImportGraphic( rGrf, INetURLObject(sFileNm),
+ nFilter );
+ else if( !pDownLoadData )
+ {
+ pStream->Seek( STREAM_SEEK_TO_BEGIN );
+ nRes = pGF->ImportGraphic( rGrf, aEmptyStr, *pStream, nFilter );
+ }
+ else
+ {
+ nRes = pGF->ImportGraphic( pDownLoadData->aGrf, aEmptyStr,
+ *pStream, nFilter );
+
+ if( pDownLoadData )
+ {
+ rGrf = pDownLoadData->aGrf;
+ if( GRAPHIC_NONE == rGrf.GetType() )
+ rGrf.SetDefaultType();
+
+
+ if( !pDownLoadData->aGrf.GetContext() )
+ {
+ xMed->SetDataAvailableLink( Link() );
+// xMed->SetDoneLink( Link() );
+ delete pDownLoadData, pDownLoadData = 0;
+ bDataReady = TRUE;
+ bWaitForData = FALSE;
+ }
+ else if( FALSE )
+ {
+ // Timer aufsetzen, um zurueck zukehren
+ pDownLoadData->aTimer.Start();
+ }
+ }
+ }
+
+ if( pStream && ERRCODE_IO_PENDING == pStream->GetError() )
+ pStream->ResetError();
+
+#ifdef DBG_UTIL
+ if( nRes )
+ {
+ if( xMed.Is() && !pStream )
+ {
+ DBG_WARNING3( "GrafikFehler [%d] - [%s] URL[%s]",
+ nRes,
+ xMed->GetPhysicalName().GetBuffer(),
+ sFileNm.GetBuffer() );
+ }
+ else
+ {
+ DBG_WARNING2( "GrafikFehler [%d] - [%s]",
+ nRes, sFileNm.GetBuffer() );
+ }
+ }
+#endif
+
+ return GRFILTER_OK == nRes;
+}
+
+/** detect the filter of the given file
+
+ @param _rURL
+ specifies the URL of the file which filter is to detected.<br/>
+ If the URL doesn't denote a valid (existent and accessible) file, the
+ request is silently dropped.
+*/
+String impl_getFilter( const String& _rURL )
+{
+ String sFilter;
+ if ( _rURL.Len() == 0 )
+ return sFilter;
+
+ try
+ {
+ css::uno::Reference< ::com::sun::star::document::XTypeDetection > xTypeDetection(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection") ),
+ css::uno::UNO_QUERY );
+ if ( xTypeDetection.is() )
+ {
+ ::comphelper::MediaDescriptor aDescr;
+ aDescr[ ::comphelper::MediaDescriptor::PROP_URL() ] <<= ::rtl::OUString( _rURL );
+ css::uno::Sequence< css::beans::PropertyValue > aDescrList =
+ aDescr.getAsConstPropertyValueList();
+ ::rtl::OUString sType = xTypeDetection->queryTypeByDescriptor( aDescrList, sal_True );
+ if ( sType.getLength() )
+ {
+ css::uno::Reference< css::container::XNameAccess > xTypeCont( xTypeDetection,
+ css::uno::UNO_QUERY );
+ if ( xTypeCont.is() )
+ {
+ ::comphelper::SequenceAsHashMap lTypeProps( xTypeCont->getByName( sType ) );
+ sFilter = lTypeProps.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii("PreferredFilter"), ::rtl::OUString() );
+ }
+ }
+ }
+ }
+ catch( const css::uno::Exception& )
+ {
+ }
+
+ return sFilter;
+}
+
+void SvFileObject::Edit( Window* pParent, sfx2::SvBaseLink* pLink, const Link& rEndEditHdl )
+{
+ aEndEditLink = rEndEditHdl;
+ String sFile, sRange, sTmpFilter;
+ if( pLink && pLink->GetLinkManager() )
+ {
+ pLink->GetLinkManager()->GetDisplayNames( pLink, 0, &sFile, &sRange, &sTmpFilter );
+
+ switch( pLink->GetObjType() )
+ {
+ case OBJECT_CLIENT_GRF:
+ {
+ nType = FILETYPE_GRF; // falls noch nicht gesetzt
+
+ SvxOpenGraphicDialog aDlg(SfxResId(RID_SVXSTR_EDITGRFLINK));
+ aDlg.EnableLink(sal_False);
+ aDlg.SetPath( sFile, sal_True );
+ aDlg.SetCurrentFilter( sTmpFilter );
+
+ if( !aDlg.Execute() )
+ {
+ sFile = aDlg.GetPath();
+ sFile += ::sfx2::cTokenSeperator;
+ sFile += ::sfx2::cTokenSeperator;
+ sFile += aDlg.GetCurrentFilter();
+
+ if ( aEndEditLink.IsSet() )
+ aEndEditLink.Call( &sFile );
+ }
+ else
+ sFile.Erase();
+ }
+ break;
+
+ case OBJECT_CLIENT_OLE:
+ {
+ nType = FILETYPE_OBJECT; // if not set already
+ pOldParent = Application::GetDefDialogParent();
+ Application::SetDefDialogParent( pParent );
+
+ ::sfx2::FileDialogHelper* pFileDlg =
+ pLink->GetFileDialog( (SFXWB_INSERT | WB_3DLOOK), String() );
+ pFileDlg->StartExecuteModal( LINK( this, SvFileObject, DialogClosedHdl ) );
+ }
+ break;
+
+ case OBJECT_CLIENT_FILE:
+ {
+ nType = FILETYPE_TEXT; // if not set already
+ pOldParent = Application::GetDefDialogParent();
+ Application::SetDefDialogParent( pParent );
+
+ String sFactory;
+ SfxObjectShell* pShell = pLink->GetLinkManager()->GetPersist();
+ if ( pShell )
+ sFactory = pShell->GetFactory().GetFactoryName();
+
+ ::sfx2::FileDialogHelper* pFileDlg =
+ pLink->GetFileDialog( (SFXWB_INSERT | WB_3DLOOK), sFactory );
+ pFileDlg->StartExecuteModal( LINK( this, SvFileObject, DialogClosedHdl ) );
+ }
+ break;
+
+ default:
+ sFile.Erase();
+ }
+ }
+}
+
+IMPL_STATIC_LINK( SvFileObject, LoadGrfReady_Impl, void*, EMPTYARG )
+{
+ // wenn wir von hier kommen, kann es kein Fehler mehr sein
+ pThis->bLoadError = FALSE;
+ pThis->bWaitForData = FALSE;
+ pThis->bInCallDownLoad = FALSE;
+
+ if( !pThis->bInNewData && !pThis->bDataReady )
+ {
+ // Grafik ist fertig, also DataChanged von der Status-
+ // aederung schicken:
+ pThis->bDataReady = TRUE;
+ pThis->SendStateChg_Impl( sfx2::LinkManager::STATE_LOAD_OK );
+
+ // und dann nochmal die Daten senden
+ pThis->NotifyDataChanged();
+ }
+
+ if( pThis->bDataReady )
+ {
+ pThis->bLoadAgain = TRUE;
+ if( pThis->xMed.Is() )
+ {
+ pThis->xMed->SetDataAvailableLink( Link() );
+ pThis->xMed->SetDoneLink( Link() );
+
+ Application::PostUserEvent(
+ STATIC_LINK( pThis, SvFileObject, DelMedium_Impl ),
+ new SfxMediumRef( pThis->xMed ));
+ pThis->xMed.Clear();
+ }
+ if( pThis->pDownLoadData )
+ delete pThis->pDownLoadData, pThis->pDownLoadData = 0;
+ }
+
+ return 0;
+}
+
+IMPL_STATIC_LINK( SvFileObject, DelMedium_Impl, SfxMediumRef*, pDelMed )
+{
+ (void)pThis;
+ delete pDelMed;
+ return 0;
+}
+
+IMPL_STATIC_LINK( SvFileObject, LoadGrfNewData_Impl, void*, EMPTYARG )
+{
+ // wenn wir von hier kommen, kann es kein Fehler mehr sein
+ if( pThis->bInNewData )
+ return 0;
+
+ pThis->bInNewData = TRUE;
+ pThis->bLoadError = FALSE;
+
+ if( !pThis->pDownLoadData )
+ {
+ pThis->pDownLoadData = new Impl_DownLoadData(
+ STATIC_LINK( pThis, SvFileObject, LoadGrfNewData_Impl ) );
+
+ // Null-Link setzen, damit keine temporaeren Grafiken
+ // rausgeswapt werden; der Filter prueft, ob schon
+ // ein Link gesetzt ist => falls dies zutrifft, wird
+ // _kein_ neuer Link gesetzt; der Link muss hier gesetzt werden,
+ // (bevor das erste Mal gefiltert wird), um zu verhindern,
+ // dass der Kontext zurueckgesetzt wird (aynchrones Laden)
+ if( !pThis->bNativFormat )
+ {
+ static GfxLink aDummyLink;
+ pThis->pDownLoadData->aGrf.SetLink( aDummyLink );
+ }
+ }
+
+ pThis->NotifyDataChanged();
+
+ SvStream* pStrm = pThis->xMed.Is() ? pThis->xMed->GetInStream() : 0;
+ if( pStrm && pStrm->GetError() )
+ {
+ if( ERRCODE_IO_PENDING == pStrm->GetError() )
+ pStrm->ResetError();
+
+ // im DataChanged ein DataReady?
+ else if( pThis->bWaitForData && pThis->pDownLoadData )
+ {
+ pThis->bLoadError = TRUE;
+ }
+ }
+
+ if( pThis->bDataReady )
+ {
+ // Grafik ist fertig, also DataChanged von der Status-
+ // aederung schicken:
+ pThis->SendStateChg_Impl( pStrm->GetError() ? sfx2::LinkManager::STATE_LOAD_ERROR : sfx2::LinkManager::STATE_LOAD_OK );
+ }
+
+ pThis->bInNewData = FALSE;
+ return 0;
+}
+
+IMPL_LINK( SvFileObject, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
+{
+ String sFile;
+ Application::SetDefDialogParent( pOldParent );
+
+ if ( FILETYPE_TEXT == nType || FILETYPE_OBJECT == nType )
+ {
+ if ( _pFileDlg && _pFileDlg->GetError() == ERRCODE_NONE )
+ {
+ String sURL( _pFileDlg->GetPath() );
+ sFile = sURL;
+ sFile += ::sfx2::cTokenSeperator;
+ sFile += ::sfx2::cTokenSeperator;
+ sFile += impl_getFilter( sURL );
+ }
+ }
+ else
+ {
+ DBG_ERRORFILE( "SvFileObject::DialogClosedHdl(): wrong file type" );
+ }
+
+ if ( aEndEditLink.IsSet() )
+ aEndEditLink.Call( &sFile );
+ return 0;
+}
+
+/* [Beschreibung]
+
+ Die Methode stellt fest, ob aus einem DDE-Object die Daten gelesen
+ werden kann.
+ Zurueckgegeben wird:
+ ERRCODE_NONE wenn sie komplett gelesen wurde
+ ERRCODE_SO_PENDING wenn sie noch nicht komplett gelesen wurde
+ ERRCODE_SO_FALSE sonst
+*/
+BOOL SvFileObject::IsPending() const
+{
+ return FILETYPE_GRF == nType && !bLoadError &&
+ ( pDownLoadData || bWaitForData );
+}
+BOOL SvFileObject::IsDataComplete() const
+{
+ BOOL bRet = FALSE;
+ if( FILETYPE_GRF != nType )
+ bRet = TRUE;
+ else if( !bLoadError && ( !bWaitForData && !pDownLoadData ))
+ {
+ SvFileObject* pThis = (SvFileObject*)this;
+ if( bDataReady ||
+ ( bSynchron && pThis->LoadFile_Impl() && xMed.Is() ) )
+ bRet = TRUE;
+ else
+ {
+ INetURLObject aUrl( sFileNm );
+ if( aUrl.HasError() ||
+ INET_PROT_NOT_VALID == aUrl.GetProtocol() )
+ bRet = TRUE;
+ }
+ }
+ return bRet;
+}
+
+
+
+void SvFileObject::CancelTransfers()
+{
+ // und aus dem Cache austragen, wenn man mitten im Laden ist
+ if( !bDataReady )
+ {
+ // nicht noch mal aufsetzen
+ bLoadAgain = FALSE;
+ bDataReady = bLoadError = bWaitForData = TRUE;
+ SendStateChg_Impl( sfx2::LinkManager::STATE_LOAD_ABORT );
+ }
+}
+
+
+void SvFileObject::SendStateChg_Impl( sfx2::LinkManager::LinkState nState )
+{
+ if( !bStateChangeCalled && HasDataLinks() )
+ {
+ css::uno::Any aAny;
+ aAny <<= rtl::OUString::valueOf( (sal_Int32)nState );
+ DataChanged( SotExchange::GetFormatName(
+ sfx2::LinkManager::RegisterStatusInfoId()), aAny );
+ bStateChangeCalled = TRUE;
+ }
+}
+
+
diff --git a/sfx2/source/appl/fileobj.hxx b/sfx2/source/appl/fileobj.hxx
new file mode 100644
index 000000000000..50f934a75436
--- /dev/null
+++ b/sfx2/source/appl/fileobj.hxx
@@ -0,0 +1,95 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _FILEOBJ_HXX
+#define _FILEOBJ_HXX
+
+#include <tools/string.hxx>
+#include <sfx2/linksrc.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/linkmgr.hxx>
+
+class Graphic;
+struct Impl_DownLoadData;
+namespace sfx2 { class FileDialogHelper; }
+
+class SvFileObject : public sfx2::SvLinkSource
+{
+ String sFileNm;
+ String sFilter;
+ String sReferer;
+ Link aEndEditLink;
+ SfxMediumRef xMed;
+ Impl_DownLoadData* pDownLoadData;
+ Window* pOldParent;
+
+ BYTE nType;
+
+ BOOL bLoadAgain : 1;
+ BOOL bSynchron : 1;
+ BOOL bLoadError : 1;
+ BOOL bWaitForData : 1;
+ BOOL bInNewData : 1;
+ BOOL bDataReady : 1;
+ BOOL bMedUseCache : 1;
+ BOOL bNativFormat : 1;
+ BOOL bClearMedium : 1;
+ BOOL bStateChangeCalled : 1;
+ BOOL bInCallDownLoad : 1;
+
+ BOOL GetGraphic_Impl( Graphic&, SvStream* pStream = 0 );
+ BOOL LoadFile_Impl();
+ void SendStateChg_Impl( sfx2::LinkManager::LinkState nState );
+
+ DECL_STATIC_LINK( SvFileObject, DelMedium_Impl, SfxMediumRef* );
+ DECL_STATIC_LINK( SvFileObject, LoadGrfReady_Impl, void* );
+ DECL_STATIC_LINK( SvFileObject, LoadGrfNewData_Impl, void* );
+ DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper* );
+
+protected:
+ virtual ~SvFileObject();
+
+public:
+ SvFileObject();
+
+ virtual BOOL GetData( ::com::sun::star::uno::Any & rData /*out param*/,
+ const String & rMimeType,
+ BOOL bSynchron = FALSE );
+
+ virtual BOOL Connect( sfx2::SvBaseLink* );
+ virtual void Edit( Window *, sfx2::SvBaseLink *, const Link& rEndEditHdl );
+
+ // erfrage ob das man direkt auf die Daten zugreifen kann oder ob das
+ // erst angestossen werden muss
+ virtual BOOL IsPending() const;
+ virtual BOOL IsDataComplete() const;
+
+ void CancelTransfers();
+};
+
+
+#endif
+
diff --git a/sfx2/source/appl/fwkhelper.cxx b/sfx2/source/appl/fwkhelper.cxx
new file mode 100644
index 000000000000..1909bcac2e17
--- /dev/null
+++ b/sfx2/source/appl/fwkhelper.cxx
@@ -0,0 +1,59 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/frame/XFrame.hpp>
+#include "sal/config.h"
+
+#include <vos/mutex.hxx>
+#include <vcl/svapp.hxx>
+
+#include "workwin.hxx"
+#include <sfx2/frame.hxx>
+
+void SAL_CALL RefreshToolbars( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( xFrame.is() )
+ {
+ SfxFrame* pFrame=0;
+ for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) )
+ {
+ if ( pFrame->GetFrameInterface() == xFrame )
+ break;
+ }
+
+ if ( pFrame )
+ {
+ SfxWorkWindow* pWrkWin = pFrame->GetWorkWindow_Impl();
+ if ( pWrkWin )
+ pWrkWin->UpdateObjectBars_Impl();
+ }
+ }
+}
diff --git a/sfx2/source/appl/helpdispatch.cxx b/sfx2/source/appl/helpdispatch.cxx
new file mode 100644
index 000000000000..2e1128aea277
--- /dev/null
+++ b/sfx2/source/appl/helpdispatch.cxx
@@ -0,0 +1,123 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "helpdispatch.hxx"
+#include <sfx2/sfxuno.hxx>
+#include "newhelp.hxx"
+#include <tools/debug.hxx>
+#include <tools/urlobj.hxx>
+#include <com/sun/star/frame/XNotifyingDispatch.hpp>
+
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+
+// class HelpInterceptor_Impl --------------------------------------------
+
+HelpDispatch_Impl::HelpDispatch_Impl( HelpInterceptor_Impl& _rInterceptor,
+ const ::com::sun::star::uno::Reference<
+ ::com::sun::star::frame::XDispatch >& _xDisp ) :
+
+ m_rInterceptor ( _rInterceptor ),
+ m_xRealDispatch ( _xDisp )
+
+{
+}
+
+// -----------------------------------------------------------------------
+
+HelpDispatch_Impl::~HelpDispatch_Impl()
+{
+}
+
+// -----------------------------------------------------------------------
+// XDispatch
+
+void SAL_CALL HelpDispatch_Impl::dispatch(
+
+ const URL& aURL, const Sequence< PropertyValue >& aArgs ) throw( RuntimeException )
+
+{
+ DBG_ASSERT( m_xRealDispatch.is(), "invalid dispatch" );
+
+ // search for a keyword (dispatch from the basic ide)
+ sal_Bool bHasKeyword = sal_False;
+ String sKeyword;
+ const PropertyValue* pBegin = aArgs.getConstArray();
+ const PropertyValue* pEnd = pBegin + aArgs.getLength();
+ for ( ; pBegin != pEnd; ++pBegin )
+ {
+ if ( 0 == ( *pBegin ).Name.compareToAscii( "HelpKeyword" ) )
+ {
+ rtl::OUString sHelpKeyword;
+ if ( ( ( *pBegin ).Value >>= sHelpKeyword ) && sHelpKeyword.getLength() > 0 )
+ {
+ sKeyword = String( sHelpKeyword );
+ bHasKeyword = ( sKeyword.Len() > 0 );
+ break;
+ }
+ }
+ }
+
+ // if a keyword was found, then open it
+ SfxHelpWindow_Impl* pHelpWin = m_rInterceptor.GetHelpWindow();
+ DBG_ASSERT( pHelpWin, "invalid HelpWindow" );
+ if ( bHasKeyword )
+ {
+ pHelpWin->OpenKeyword( sKeyword );
+ return;
+ }
+
+ pHelpWin->loadHelpContent(aURL.Complete);
+}
+
+// -----------------------------------------------------------------------
+
+void SAL_CALL HelpDispatch_Impl::addStatusListener(
+
+ const Reference< XStatusListener >& xControl, const URL& aURL ) throw( RuntimeException )
+
+{
+ DBG_ASSERT( m_xRealDispatch.is(), "invalid dispatch" );
+ m_xRealDispatch->addStatusListener( xControl, aURL );
+}
+
+// -----------------------------------------------------------------------
+
+void SAL_CALL HelpDispatch_Impl::removeStatusListener(
+
+ const Reference< XStatusListener >& xControl, const URL& aURL ) throw( RuntimeException )
+
+{
+ DBG_ASSERT( m_xRealDispatch.is(), "invalid dispatch" );
+ m_xRealDispatch->removeStatusListener( xControl, aURL );
+}
+
diff --git a/sfx2/source/appl/helpdispatch.hxx b/sfx2/source/appl/helpdispatch.hxx
new file mode 100644
index 000000000000..b9d1e7b17b63
--- /dev/null
+++ b/sfx2/source/appl/helpdispatch.hxx
@@ -0,0 +1,54 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef SFX_HELPDISPATCH_HXX
+#define SFX_HELPDISPATCH_HXX
+
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <cppuhelper/implbase1.hxx>
+
+#include "helpinterceptor.hxx"
+
+class HelpDispatch_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XDispatch >
+{
+private:
+ HelpInterceptor_Impl& m_rInterceptor;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >
+ m_xRealDispatch;
+
+public:
+ HelpDispatch_Impl( HelpInterceptor_Impl& _rInterceptor,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& _xDisp );
+ ~HelpDispatch_Impl();
+
+ // XDispatch
+ virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, const ::com::sun::star::util::URL& aURL ) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, const ::com::sun::star::util::URL& aURL ) throw(::com::sun::star::uno::RuntimeException);
+};
+
+#endif // #ifndef SFX_HELPDISPATCHER_HXX
+
diff --git a/sfx2/source/appl/helpinterceptor.cxx b/sfx2/source/appl/helpinterceptor.cxx
new file mode 100644
index 000000000000..2d997dcc26ff
--- /dev/null
+++ b/sfx2/source/appl/helpinterceptor.cxx
@@ -0,0 +1,367 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "helpinterceptor.hxx"
+#include "helpdispatch.hxx"
+#include "newhelp.hxx"
+#include <sfx2/sfxuno.hxx>
+#include <tools/urlobj.hxx>
+#include <tools/debug.hxx>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/frame/XNotifyingDispatch.hpp>
+#include <cppuhelper/interfacecontainer.h>
+#include <vcl/window.hxx>
+#include <limits.h>
+
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::lang;
+
+extern void AppendConfigToken_Impl( String& rURL, sal_Bool bQuestionMark ); // sfxhelp.cxx
+
+// class HelpInterceptor_Impl --------------------------------------------
+
+HelpInterceptor_Impl::HelpInterceptor_Impl() :
+
+ m_pHistory ( NULL ),
+ m_nCurPos ( 0 )
+
+{
+}
+
+// -----------------------------------------------------------------------
+
+HelpInterceptor_Impl::~HelpInterceptor_Impl()
+{
+ for ( USHORT i = 0; m_pHistory && i < m_pHistory->Count(); ++i )
+ delete m_pHistory->GetObject(i);
+ delete m_pHistory;
+}
+
+// -----------------------------------------------------------------------
+
+void HelpInterceptor_Impl::addURL( const String& rURL )
+{
+ if ( !m_pHistory )
+ m_pHistory = new HelpHistoryList_Impl;
+ ULONG nCount = m_pHistory->Count();
+ if ( nCount && m_nCurPos < ( nCount - 1 ) )
+ {
+ for ( ULONG i = nCount - 1; i > m_nCurPos; i-- )
+ delete m_pHistory->Remove(i);
+ }
+ Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY);
+ Reference<XController> xController;
+ if(xFrame.is())
+ xController = xFrame->getController();
+ Any aViewData;
+ if(xController.is() && m_pHistory->Count())
+ {
+ m_pHistory->GetObject(m_nCurPos)->aViewData = xController->getViewData();
+ }
+
+ m_aCurrentURL = rURL;
+ Any aEmptyViewData;
+ m_pHistory->Insert( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ), LIST_APPEND );
+ m_nCurPos = m_pHistory->Count() - 1;
+// TODO ?
+ if ( m_xListener.is() )
+ {
+ ::com::sun::star::frame::FeatureStateEvent aEvent;
+ URL aURL;
+ aURL.Complete = rURL;
+ aEvent.FeatureURL = aURL;
+ aEvent.Source = (::com::sun::star::frame::XDispatch*)this;
+ m_xListener->statusChanged( aEvent );
+ }
+
+ m_pWindow->UpdateToolbox();
+}
+
+// -----------------------------------------------------------------------
+
+void HelpInterceptor_Impl::setInterception( Reference< XFrame > xFrame )
+{
+ m_xIntercepted = Reference< XDispatchProviderInterception>( xFrame, UNO_QUERY );
+
+ if ( m_xIntercepted.is() )
+ m_xIntercepted->registerDispatchProviderInterceptor( (XDispatchProviderInterceptor*)this );
+}
+
+// -----------------------------------------------------------------------
+
+void HelpInterceptor_Impl::SetStartURL( const String& rURL )
+{
+ DBG_ASSERT( !m_pHistory, "invalid history" );
+ if ( !m_pHistory )
+ {
+ m_pHistory = new HelpHistoryList_Impl;
+ Any aEmptyViewData;
+ m_pHistory->Insert( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ), ((ULONG)0x0) );
+ m_nCurPos = m_pHistory->Count() - 1;
+
+ m_pWindow->UpdateToolbox();
+ }
+ m_aCurrentURL = rURL;
+}
+
+sal_Bool HelpInterceptor_Impl::HasHistoryPred() const
+{
+ return m_pHistory && ( m_nCurPos > 0 );
+}
+
+sal_Bool HelpInterceptor_Impl::HasHistorySucc() const
+{
+ return m_pHistory && ( m_nCurPos < ( m_pHistory->Count() - 1 ) );
+}
+
+
+// -----------------------------------------------------------------------
+// XDispatchProvider
+
+Reference< XDispatch > SAL_CALL HelpInterceptor_Impl::queryDispatch(
+
+ const URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags )
+
+ throw( RuntimeException )
+
+{
+ Reference< XDispatch > xResult;
+ if ( m_xSlaveDispatcher.is() )
+ xResult = m_xSlaveDispatcher->queryDispatch( aURL, aTargetFrameName, nSearchFlags );
+
+ // INetURLObject aObj( aURL.Complete );
+ // sal_Bool bHelpURL = ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP );
+ BOOL bHelpURL = aURL.Complete.toAsciiLowerCase().match(rtl::OUString::createFromAscii("vnd.sun.star.help"),0);
+
+ if ( bHelpURL )
+ {
+ DBG_ASSERT( xResult.is(), "invalid dispatch" );
+ HelpDispatch_Impl* pHelpDispatch = new HelpDispatch_Impl( *this, xResult );
+ xResult = Reference< XDispatch >( static_cast< ::cppu::OWeakObject* >(pHelpDispatch), UNO_QUERY );
+ }
+
+ return xResult;
+}
+
+// -----------------------------------------------------------------------
+
+Sequence < Reference < XDispatch > > SAL_CALL HelpInterceptor_Impl::queryDispatches(
+
+ const Sequence< DispatchDescriptor >& aDescripts )
+
+ throw( RuntimeException )
+
+{
+ Sequence< Reference< XDispatch > > aReturn( aDescripts.getLength() );
+ Reference< XDispatch >* pReturn = aReturn.getArray();
+ const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
+ for ( sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
+ {
+ *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
+ }
+ return aReturn;
+}
+
+// -----------------------------------------------------------------------
+// XDispatchProviderInterceptor
+
+Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getSlaveDispatchProvider()
+
+ throw( RuntimeException )
+
+{
+ return m_xSlaveDispatcher;
+}
+
+// -----------------------------------------------------------------------
+
+void SAL_CALL HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference< XDispatchProvider >& xNewSlave )
+
+ throw( RuntimeException )
+
+{
+ m_xSlaveDispatcher = xNewSlave;
+}
+
+// -----------------------------------------------------------------------
+
+Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getMasterDispatchProvider()
+
+ throw( RuntimeException )
+
+{
+ return m_xMasterDispatcher;
+}
+
+// -----------------------------------------------------------------------
+
+void SAL_CALL HelpInterceptor_Impl::setMasterDispatchProvider( const Reference< XDispatchProvider >& xNewMaster )
+
+ throw( RuntimeException )
+
+{
+ m_xMasterDispatcher = xNewMaster;
+}
+
+// -----------------------------------------------------------------------
+// XInterceptorInfo
+
+Sequence< ::rtl::OUString > SAL_CALL HelpInterceptor_Impl::getInterceptedURLs()
+
+ throw( RuntimeException )
+
+{
+ Sequence< ::rtl::OUString > aURLList( 1 );
+ aURLList[0] = DEFINE_CONST_UNICODE("vnd.sun.star.help://*");
+ return aURLList;;
+}
+
+// -----------------------------------------------------------------------
+// XDispatch
+
+void SAL_CALL HelpInterceptor_Impl::dispatch(
+ const URL& aURL, const Sequence< ::com::sun::star::beans::PropertyValue >& ) throw( RuntimeException )
+{
+ sal_Bool bBack = ( String( DEFINE_CONST_UNICODE(".uno:Backward") ) == String( aURL.Complete ) );
+ if ( bBack || String( DEFINE_CONST_UNICODE(".uno:Forward") ) == String( aURL.Complete ) )
+ {
+ if ( m_pHistory )
+ {
+ if(m_pHistory->Count() > m_nCurPos)
+ {
+ Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY);
+ Reference<XController> xController;
+ if(xFrame.is())
+ xController = xFrame->getController();
+ if(xController.is())
+ {
+ m_pHistory->GetObject(m_nCurPos)->aViewData = xController->getViewData();
+ }
+ }
+
+ ULONG nPos = ( bBack && m_nCurPos > 0 ) ? --m_nCurPos
+ : ( !bBack && m_nCurPos < m_pHistory->Count() - 1 )
+ ? ++m_nCurPos
+ : ULONG_MAX;
+
+ if ( nPos < ULONG_MAX )
+ {
+ HelpHistoryEntry_Impl* pEntry = m_pHistory->GetObject( nPos );
+ if ( pEntry )
+ m_pWindow->loadHelpContent(pEntry->aURL, sal_False); // false => dont add item to history again!
+ }
+
+ m_pWindow->UpdateToolbox();
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SAL_CALL HelpInterceptor_Impl::addStatusListener(
+ const Reference< XStatusListener >& xControl, const URL& ) throw( RuntimeException )
+{
+ DBG_ASSERT( !m_xListener.is(), "listener already exists" );
+ m_xListener = xControl;
+}
+
+// -----------------------------------------------------------------------
+
+void SAL_CALL HelpInterceptor_Impl::removeStatusListener(
+ const Reference< XStatusListener >&, const URL&) throw( RuntimeException )
+{
+ m_xListener = 0;
+}
+
+// HelpListener_Impl -----------------------------------------------------
+
+HelpListener_Impl::HelpListener_Impl( HelpInterceptor_Impl* pInter )
+{
+ pInterceptor = pInter;
+ pInterceptor->addStatusListener( this, ::com::sun::star::util::URL() );
+}
+
+// -----------------------------------------------------------------------
+
+void SAL_CALL HelpListener_Impl::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
+
+ throw( ::com::sun::star::uno::RuntimeException )
+
+{
+ INetURLObject aObj( Event.FeatureURL.Complete );
+ aFactory = aObj.GetHost();
+ aChangeLink.Call( this );
+}
+
+// -----------------------------------------------------------------------
+
+void SAL_CALL HelpListener_Impl::disposing( const ::com::sun::star::lang::EventObject& )
+
+ throw( ::com::sun::star::uno::RuntimeException )
+
+{
+ pInterceptor->removeStatusListener( this, ::com::sun::star::util::URL() );
+ pInterceptor = NULL;
+}
+/*-- 05.09.2002 12:17:59---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+HelpStatusListener_Impl::HelpStatusListener_Impl(
+ Reference < XDispatch > aDispatch, URL& rURL)
+{
+ aDispatch->addStatusListener(this, rURL);
+}
+/*-- 05.09.2002 12:17:59---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+HelpStatusListener_Impl::~HelpStatusListener_Impl()
+{
+ if(xDispatch.is())
+ xDispatch->removeStatusListener(this, com::sun::star::util::URL());
+}
+/*-- 05.09.2002 12:17:59---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+void HelpStatusListener_Impl::statusChanged(
+ const FeatureStateEvent& rEvent ) throw( RuntimeException )
+{
+ aStateEvent = rEvent;
+}
+/*-- 05.09.2002 12:18:00---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+void HelpStatusListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
+{
+ xDispatch->removeStatusListener(this, com::sun::star::util::URL());
+ xDispatch = 0;
+}
diff --git a/sfx2/source/appl/helpinterceptor.hxx b/sfx2/source/appl/helpinterceptor.hxx
new file mode 100644
index 000000000000..3476f0d305b5
--- /dev/null
+++ b/sfx2/source/appl/helpinterceptor.hxx
@@ -0,0 +1,173 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef INCLUDED_SFX_HELPINTERCEPTOR_HXX
+#define INCLUDED_SFX_HELPINTERCEPTOR_HXX
+
+#ifndef _CPPUHELPER_IMPLBASE2_HXX_
+#include <cppuhelper/implbase3.hxx>
+#endif
+#include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
+#include <com/sun/star/frame/XInterceptorInfo.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/frame/XStatusListener.hpp>
+#include <tools/string.hxx>
+#include <tools/list.hxx>
+#include <tools/link.hxx>
+
+struct HelpHistoryEntry_Impl
+{
+ String aURL;
+ com::sun::star::uno::Any aViewData;
+
+ HelpHistoryEntry_Impl( const String& rURL, const com::sun::star::uno::Any& rViewData ) :
+ aURL( rURL ), aViewData(rViewData) {}
+};
+
+DECLARE_LIST(HelpHistoryList_Impl,HelpHistoryEntry_Impl*)
+
+class SfxHelpWindow_Impl;
+class HelpInterceptor_Impl : public ::cppu::WeakImplHelper3<
+
+ ::com::sun::star::frame::XDispatchProviderInterceptor,
+ ::com::sun::star::frame::XInterceptorInfo,
+ ::com::sun::star::frame::XDispatch >
+
+{
+private:
+friend class HelpDispatch_Impl;
+friend class SfxHelpWindow_Impl;
+
+ // the component which's dispatches we're intercepting
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterception > m_xIntercepted;
+
+ // chaining
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > m_xSlaveDispatcher;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > m_xMasterDispatcher;
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > m_xListener;
+
+ HelpHistoryList_Impl* m_pHistory;
+ SfxHelpWindow_Impl* m_pWindow;
+ ULONG m_nCurPos;
+ String m_aCurrentURL;
+ com::sun::star::uno::Any m_aViewData;
+
+ void addURL( const String& rURL );
+
+public:
+ HelpInterceptor_Impl();
+ ~HelpInterceptor_Impl();
+
+ void setInterception( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame );
+ void SetStartURL( const String& rURL );
+ String GetCurrentURL() const { return m_aCurrentURL; }
+
+
+
+ const com::sun::star::uno::Any& GetViewData()const {return m_aViewData;}
+
+ sal_Bool HasHistoryPred() const; // is there a predecessor for the current in the history
+ sal_Bool HasHistorySucc() const; // is there a successor for the current in the history
+
+ // XDispatchProvider
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL
+ queryDispatch( const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags ) throw(::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > SAL_CALL
+ queryDispatches( const ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw(::com::sun::star::uno::RuntimeException);
+
+ // XDispatchProviderInterceptor
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL
+ getSlaveDispatchProvider( ) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setSlaveDispatchProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& xNewSlave ) throw(::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL
+ getMasterDispatchProvider( ) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setMasterDispatchProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& xNewMaster ) throw(::com::sun::star::uno::RuntimeException);
+
+ // XInterceptorInfo
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
+ getInterceptedURLs( ) throw(::com::sun::star::uno::RuntimeException);
+
+ // XDispatch
+ virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, const ::com::sun::star::util::URL& aURL ) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, const ::com::sun::star::util::URL& aURL ) throw(::com::sun::star::uno::RuntimeException);
+
+ // extras
+ void InitWaiter( SfxHelpWindow_Impl* pWindow )
+ { m_pWindow = pWindow; }
+ SfxHelpWindow_Impl* GetHelpWindow() const { return m_pWindow; }
+};
+
+// HelpListener_Impl -----------------------------------------------------
+
+class HelpListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XStatusListener >
+{
+private:
+ HelpInterceptor_Impl* pInterceptor;
+ Link aChangeLink;
+ String aFactory;
+
+public:
+ HelpListener_Impl( HelpInterceptor_Impl* pInter );
+
+ virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
+ throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& obj )
+ throw( ::com::sun::star::uno::RuntimeException );
+
+ void SetChangeHdl( const Link& rLink ) { aChangeLink = rLink; }
+ String GetFactory() const { return aFactory; }
+};
+// HelpStatusListener_Impl -----------------------------------------------------
+
+class HelpStatusListener_Impl : public
+::cppu::WeakImplHelper1< ::com::sun::star::frame::XStatusListener >
+{
+private:
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatch > xDispatch;
+ ::com::sun::star::frame::FeatureStateEvent aStateEvent;
+
+public:
+ HelpStatusListener_Impl(
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatch > xDispatch,
+ com::sun::star::util::URL& rURL);
+ ~HelpStatusListener_Impl();
+
+ virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
+ throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& obj )
+ throw( ::com::sun::star::uno::RuntimeException );
+ const ::com::sun::star::frame::FeatureStateEvent&
+ GetStateEvent() const {return aStateEvent;}
+};
+
+
+#endif // #ifndef INCLUDED_SFX_HELPINTERCEPTOR_HXX
+
diff --git a/sfx2/source/appl/imagemgr.cxx b/sfx2/source/appl/imagemgr.cxx
new file mode 100644
index 000000000000..b9f4404d5555
--- /dev/null
+++ b/sfx2/source/appl/imagemgr.cxx
@@ -0,0 +1,234 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include "sfx2/imagemgr.hxx"
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/ui/XImageManager.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
+#include <com/sun/star/ui/ImageType.hpp>
+#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
+
+#include <tools/urlobj.hxx>
+#include <svtools/imagemgr.hxx>
+#include <comphelper/processfactory.hxx>
+#include <rtl/ustring.hxx>
+#include <rtl/logfile.hxx>
+
+#include "sfx2/imgmgr.hxx"
+#include <sfx2/app.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/msg.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/docfac.hxx>
+
+#include <hash_map>
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::ui;
+using namespace ::com::sun::star::frame;
+
+typedef std::hash_map< ::rtl::OUString,
+ WeakReference< XImageManager >,
+ ::rtl::OUStringHash,
+ ::std::equal_to< ::rtl::OUString > > ModuleIdToImagegMgr;
+
+static WeakReference< XModuleManager > m_xModuleManager;
+static WeakReference< XModuleUIConfigurationManagerSupplier > m_xModuleCfgMgrSupplier;
+static WeakReference< XURLTransformer > m_xURLTransformer;
+static ModuleIdToImagegMgr m_aModuleIdToImageMgrMap;
+
+Image SAL_CALL GetImage( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, const ::rtl::OUString& aURL, BOOL bBig, BOOL bHiContrast )
+{
+ // TODO/LATeR: shouldn't this become a method at SfxViewFrame?! That would save the UnoTunnel
+ if ( !rFrame.is() )
+ return Image();
+
+ INetURLObject aObj( aURL );
+ INetProtocol nProtocol = aObj.GetProtocol();
+
+ Reference < XController > xController;
+ Reference < XModel > xModel;
+ if ( rFrame.is() )
+ xController = rFrame->getController();
+ if ( xController.is() )
+ xModel = xController->getModel();
+
+ rtl::OUString aCommandURL( aURL );
+ if ( nProtocol == INET_PROT_SLOT )
+ {
+ /*
+ // Support old way to retrieve image via slot URL
+ Reference< XURLTransformer > xURLTransformer = m_xURLTransformer;
+ if ( !xURLTransformer.is() )
+ {
+ xURLTransformer = Reference< XURLTransformer >(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
+ UNO_QUERY );
+ m_xURLTransformer = xURLTransformer;
+ }
+
+ URL aTargetURL;
+ aTargetURL.Complete = aURL;
+ xURLTransformer->parseStrict( aTargetURL );
+ USHORT nId = ( USHORT ) aTargetURL.Path.toInt32();*/
+ USHORT nId = ( USHORT ) String(aURL).Copy(5).ToInt32();
+ const SfxSlot* pSlot = 0;
+ if ( xModel.is() )
+ {
+ Reference < XUnoTunnel > xObj( xModel, UNO_QUERY );
+ Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
+ sal_Int64 nHandle = xObj.is() ? xObj->getSomething( aSeq ) : 0;
+ if ( nHandle )
+ {
+ SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell*>(sal::static_int_cast<sal_IntPtr>( nHandle ));
+ SfxModule* pModule = pDoc->GetFactory().GetModule();
+ pSlot = pModule->GetSlotPool()->GetSlot( nId );
+ }
+ }
+ else
+ pSlot = SfxSlotPool::GetSlotPool().GetSlot( nId );
+
+ if ( pSlot )
+ {
+ aCommandURL = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
+ aCommandURL += rtl::OUString::createFromAscii( pSlot->GetUnoName() );
+ }
+ else
+ aCommandURL = rtl::OUString();
+ }
+
+ Reference< XImageManager > xDocImgMgr;
+ if ( xModel.is() )
+ {
+ Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
+ if ( xSupplier.is() )
+ {
+ Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
+ xDocImgMgr = Reference< XImageManager >( xDocUICfgMgr->getImageManager(), UNO_QUERY );
+ }
+ }
+
+ sal_Int16 nImageType( ::com::sun::star::ui::ImageType::COLOR_NORMAL|
+ ::com::sun::star::ui::ImageType::SIZE_DEFAULT );
+ if ( bBig )
+ nImageType |= ::com::sun::star::ui::ImageType::SIZE_LARGE;
+ if ( bHiContrast )
+ nImageType |= ::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST;
+
+ if ( xDocImgMgr.is() )
+ {
+ Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq;
+ Sequence< rtl::OUString > aImageCmdSeq( 1 );
+ aImageCmdSeq[0] = aCommandURL;
+
+ try
+ {
+ aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq );
+ Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
+ Image aImage( xGraphic );
+
+ if ( !!aImage )
+ return aImage;
+ }
+ catch ( Exception& )
+ {
+ }
+ }
+
+ Reference< XModuleManager > xModuleManager = m_xModuleManager;
+
+ if ( !xModuleManager.is() )
+ {
+ xModuleManager = Reference< XModuleManager >(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.frame.ModuleManager" ))),
+ UNO_QUERY );
+ m_xModuleManager = xModuleManager;
+ }
+
+ try
+ {
+ if ( aCommandURL.getLength() > 0 )
+ {
+ Reference< XImageManager > xModuleImageManager;
+ rtl::OUString aModuleId = xModuleManager->identify( rFrame );
+ ModuleIdToImagegMgr::iterator pIter = m_aModuleIdToImageMgrMap.find( aModuleId );
+ if ( pIter != m_aModuleIdToImageMgrMap.end() )
+ xModuleImageManager = pIter->second;
+ else
+ {
+ Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier = m_xModuleCfgMgrSupplier;
+
+ if ( !xModuleCfgMgrSupplier.is() )
+ {
+ xModuleCfgMgrSupplier = Reference< XModuleUIConfigurationManagerSupplier >(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ))),
+ UNO_QUERY );
+
+ m_xModuleCfgMgrSupplier = xModuleCfgMgrSupplier;
+ }
+
+ Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( aModuleId );
+ xModuleImageManager = Reference< XImageManager >( xUICfgMgr->getImageManager(), UNO_QUERY );
+ m_aModuleIdToImageMgrMap.insert( ModuleIdToImagegMgr::value_type( aModuleId, xModuleImageManager ));
+ }
+
+ Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq;
+ Sequence< rtl::OUString > aImageCmdSeq( 1 );
+ aImageCmdSeq[0] = aCommandURL;
+
+ aGraphicSeq = xModuleImageManager->getImages( nImageType, aImageCmdSeq );
+
+ Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
+ Image aImage( xGraphic );
+
+ if ( !!aImage )
+ return aImage;
+ else if ( nProtocol != INET_PROT_UNO && nProtocol != INET_PROT_SLOT )
+ return SvFileInformationManager::GetImageNoDefault( aObj, bBig, bHiContrast );
+ }
+ }
+ catch ( Exception& )
+ {
+ }
+
+ return Image();
+}
diff --git a/sfx2/source/appl/imestatuswindow.cxx b/sfx2/source/appl/imestatuswindow.cxx
new file mode 100644
index 000000000000..07eb47bd92ad
--- /dev/null
+++ b/sfx2/source/appl/imestatuswindow.cxx
@@ -0,0 +1,231 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "imestatuswindow.hxx"
+
+#include <sfx2/app.hxx>
+#include <sfx2/sfxsids.hrc>
+
+#include "com/sun/star/beans/PropertyState.hpp"
+#include "com/sun/star/beans/PropertyValue.hpp"
+#include "com/sun/star/beans/XPropertySet.hpp"
+#include "com/sun/star/lang/DisposedException.hpp"
+#include "com/sun/star/lang/XMultiServiceFactory.hpp"
+#include "com/sun/star/uno/Any.hxx"
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "com/sun/star/util/XChangesBatch.hpp"
+#include "osl/diagnose.h"
+#include "osl/mutex.hxx"
+#include "rtl/ustring.h"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+#include "vcl/svapp.hxx"
+#include "vos/mutex.hxx"
+
+namespace css = com::sun::star;
+
+using sfx2::appl::ImeStatusWindow;
+
+ImeStatusWindow::ImeStatusWindow(
+ css::uno::Reference< css::lang::XMultiServiceFactory > const &
+ rServiceFactory):
+ m_xServiceFactory(rServiceFactory),
+ m_bDisposed(false)
+{}
+
+void ImeStatusWindow::init()
+{
+ if (Application::CanToggleImeStatusWindow())
+ try
+ {
+ sal_Bool bShow = sal_Bool();
+ if (getConfig()->getPropertyValue(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "ShowStatusWindow")))
+ >>= bShow)
+ Application::ShowImeStatusWindow(bShow);
+ }
+ catch (css::uno::Exception &)
+ {
+ OSL_ENSURE(false, "com.sun.star.uno.Exception");
+ // Degrade gracefully and use the VCL-supplied default if no
+ // configuration is available.
+ }
+}
+
+bool ImeStatusWindow::isShowing()
+{
+ try
+ {
+ sal_Bool bShow = sal_Bool();
+ if (getConfig()->getPropertyValue(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")))
+ >>= bShow)
+ return bShow;
+ }
+ catch (css::uno::Exception &)
+ {
+ OSL_ENSURE(false, "com.sun.star.uno.Exception");
+ // Degrade gracefully and use the VCL-supplied default if no
+ // configuration is available.
+ }
+ return Application::GetShowImeStatusWindowDefault();
+}
+
+void ImeStatusWindow::show(bool bShow)
+{
+ try
+ {
+ css::uno::Reference< css::beans::XPropertySet > xConfig(getConfig());
+ xConfig->setPropertyValue(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")),
+ css::uno::makeAny(static_cast< sal_Bool >(bShow)));
+ css::uno::Reference< css::util::XChangesBatch > xCommit(
+ xConfig, css::uno::UNO_QUERY);
+ // Degrade gracefully by not saving the settings permanently:
+ if (xCommit.is())
+ xCommit->commitChanges();
+ // Alternatively, setting the VCL status could be done even if updating
+ // the configuration failed:
+ Application::ShowImeStatusWindow(bShow);
+ }
+ catch (css::uno::Exception &)
+ {
+ OSL_ENSURE(false, "com.sun.star.uno.Exception");
+ }
+}
+
+bool ImeStatusWindow::canToggle() const
+{
+ return Application::CanToggleImeStatusWindow();
+}
+
+ImeStatusWindow::~ImeStatusWindow()
+{
+ if (m_xConfig.is())
+ // We should never get here, but just in case...
+ try
+ {
+ m_xConfig->removePropertyChangeListener(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")),
+ this);
+ }
+ catch (css::uno::Exception &)
+ {
+ OSL_ENSURE(false, "com.sun.star.uno.RuntimeException");
+ }
+}
+
+void SAL_CALL ImeStatusWindow::disposing(css::lang::EventObject const & )
+ throw (css::uno::RuntimeException)
+{
+ osl::MutexGuard aGuard(m_aMutex);
+ m_xConfig = 0;
+ m_bDisposed = true;
+}
+
+void SAL_CALL
+ImeStatusWindow::propertyChange(css::beans::PropertyChangeEvent const & )
+ throw (css::uno::RuntimeException)
+{
+ vos::OGuard aGuard(Application::GetSolarMutex());
+ SfxApplication* pApp = SfxApplication::Get();
+ if (pApp)
+ pApp->Invalidate(SID_SHOW_IME_STATUS_WINDOW);
+}
+
+css::uno::Reference< css::beans::XPropertySet > ImeStatusWindow::getConfig()
+{
+ css::uno::Reference< css::beans::XPropertySet > xConfig;
+ bool bAdd = false;
+ {
+ osl::MutexGuard aGuard(m_aMutex);
+ if (!m_xConfig.is())
+ {
+ if (m_bDisposed)
+ throw css::lang::DisposedException();
+ if (!m_xServiceFactory.is())
+ throw css::uno::RuntimeException(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "null comphelper::getProcessServiceFactory")),
+ 0);
+ css::uno::Reference< css::lang::XMultiServiceFactory > xProvider(
+ m_xServiceFactory->createInstance(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.configuration.ConfigurationProvider"))),
+ css::uno::UNO_QUERY);
+ if (!xProvider.is())
+ throw css::uno::RuntimeException(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "null com.sun.star.configuration."
+ "ConfigurationProvider")),
+ 0);
+ css::beans::PropertyValue aArg(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")), -1,
+ css::uno::makeAny(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "/org.openoffice.Office.Common/I18N/InputMethod"))),
+ css::beans::PropertyState_DIRECT_VALUE);
+ css::uno::Sequence< css::uno::Any > aArgs(1);
+ aArgs[0] <<= aArg;
+ m_xConfig
+ = css::uno::Reference< css::beans::XPropertySet >(
+ xProvider->createInstanceWithArguments(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.configuration.ConfigurationUpdateAccess")),
+ aArgs),
+ css::uno::UNO_QUERY);
+ if (!m_xConfig.is())
+ throw css::uno::RuntimeException(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "null com.sun.star.configuration."
+ "ConfigurationUpdateAccess")),
+ 0);
+ bAdd = true;
+ }
+ xConfig = m_xConfig;
+ }
+ if (bAdd)
+ // Exceptions here could be handled individually, to support graceful
+ // degradation (no update notification mechanism in this case---but also
+ // no dispose notifications):
+ xConfig->addPropertyChangeListener(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowStatusWindow")),
+ this);
+ return xConfig;
+}
+
diff --git a/sfx2/source/appl/imestatuswindow.hxx b/sfx2/source/appl/imestatuswindow.hxx
new file mode 100644
index 000000000000..4edba523ed30
--- /dev/null
+++ b/sfx2/source/appl/imestatuswindow.hxx
@@ -0,0 +1,125 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#if !defined INCLUDED_SFX2_APPL_IMESTATUSWINDOW_HXX
+#define INCLUDED_SFX2_APPL_IMESTATUSWINDOW_HXX
+
+#include "com/sun/star/beans/XPropertyChangeListener.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "cppuhelper/implbase1.hxx"
+#include "osl/mutex.hxx"
+
+namespace com { namespace sun { namespace star {
+ namespace beans { class XPropertySet; }
+ namespace lang { class XMultiServiceFactory; }
+} } }
+
+namespace sfx2 { namespace appl {
+
+// The MS compiler needs this typedef work-around to accept the using
+// declarations within ImeStatusWindow:
+typedef cppu::WeakImplHelper1< com::sun::star::beans::XPropertyChangeListener >
+ImeStatusWindow_Impl;
+
+/** Control the behavior of any (platform-dependent) IME status windows.
+
+ The decision of whether a status window shall be displayed or not can be
+ stored permanently in the configuration (under key
+ org.openoffice.office.Common/I18N/InputMethod/ShowStatusWindow; if that
+ entry is nil, VCL is asked for a default).
+ */
+class ImeStatusWindow: private ImeStatusWindow_Impl
+{
+public:
+ ImeStatusWindow( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > const& rServiceFactory );
+
+ /** Set up VCL according to the configuration.
+
+ Is it not strictly required that this method is called exactly once
+ (though that will be the typical use).
+
+ Must only be called with the Solar mutex locked.
+ */
+ void init();
+
+ /** Return true if the status window is toggled on.
+
+ This is only meaningful when canToggle returns true.
+
+ Can be called without the Solar mutex locked.
+ */
+ bool isShowing();
+
+ /** Toggle the status window on or off.
+
+ This only works if canToggle returns true (otherwise, any calls of this
+ method are ignored).
+
+ Must only be called with the Solar mutex locked.
+ */
+ void show(bool bShow);
+
+ /** Return true if the status window can be toggled on and off externally.
+
+ Must only be called with the Solar mutex locked.
+ */
+ bool canToggle() const;
+
+ using ImeStatusWindow_Impl::acquire;
+ using ImeStatusWindow_Impl::release;
+ using ImeStatusWindow_Impl::operator new;
+ using ImeStatusWindow_Impl::operator delete;
+
+private:
+ ImeStatusWindow(ImeStatusWindow &); // not implemented
+ void operator =(ImeStatusWindow); // not implemented
+
+ virtual ~ImeStatusWindow();
+
+ virtual void SAL_CALL
+ disposing(com::sun::star::lang::EventObject const & rSource)
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL
+ propertyChange(com::sun::star::beans::PropertyChangeEvent const & rEvent)
+ throw (com::sun::star::uno::RuntimeException);
+
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >
+ getConfig();
+
+ com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
+ m_xServiceFactory;
+
+ osl::Mutex m_aMutex;
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >
+ m_xConfig;
+ bool m_bDisposed;
+};
+
+} }
+
+#endif // INCLUDED_SFX2_APPL_IMESTATUSWINDOW_HXX
diff --git a/sfx2/source/appl/impldde.cxx b/sfx2/source/appl/impldde.cxx
new file mode 100644
index 000000000000..479e8ddea745
--- /dev/null
+++ b/sfx2/source/appl/impldde.cxx
@@ -0,0 +1,448 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#if defined(WNT)
+#include <tools/svwin.h>
+#endif
+
+#include "impldde.hxx"
+
+#include <vcl/svapp.hxx>
+#include <vcl/fixed.hxx>
+#include <vcl/edit.hxx>
+#include <vcl/button.hxx>
+#include <vcl/msgbox.hxx>
+#include <sot/exchange.hxx>
+#include <rtl/ustring.hxx>
+
+#include "dde.hrc"
+#include <sfx2/lnkbase.hxx>
+#include <sfx2/linkmgr.hxx>
+#include "sfx2/sfxresid.hxx"
+
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+
+#include <svl/svdde.hxx>
+#include <sot/formats.hxx>
+
+#define DDELINK_COLD 0
+#define DDELINK_HOT 1
+
+#define DDELINK_ERROR_APP 1
+#define DDELINK_ERROR_DATA 2
+#define DDELINK_ERROR_LINK 3
+
+using namespace ::com::sun::star::uno;
+
+namespace sfx2
+{
+
+class SvDDELinkEditDialog : public ModalDialog
+{
+ FixedText aFtDdeApp;
+ Edit aEdDdeApp;
+ FixedText aFtDdeTopic;
+ Edit aEdDdeTopic;
+ FixedText aFtDdeItem;
+ Edit aEdDdeItem;
+ FixedLine aGroupDdeChg;
+ OKButton aOKButton1;
+ CancelButton aCancelButton1;
+
+ DECL_STATIC_LINK( SvDDELinkEditDialog, EditHdl_Impl, Edit* );
+public:
+ SvDDELinkEditDialog( Window* pParent, SvBaseLink* );
+ String GetCmd() const;
+};
+
+SvDDELinkEditDialog::SvDDELinkEditDialog( Window* pParent, SvBaseLink* pLink )
+ : ModalDialog( pParent, SfxResId( MD_DDE_LINKEDIT ) ),
+ aFtDdeApp( this, SfxResId( FT_DDE_APP ) ),
+ aEdDdeApp( this, SfxResId( ED_DDE_APP ) ),
+ aFtDdeTopic( this, SfxResId( FT_DDE_TOPIC ) ),
+ aEdDdeTopic( this, SfxResId( ED_DDE_TOPIC ) ),
+ aFtDdeItem( this, SfxResId( FT_DDE_ITEM ) ),
+ aEdDdeItem( this, SfxResId( ED_DDE_ITEM ) ),
+ aGroupDdeChg( this, SfxResId( GROUP_DDE_CHG ) ),
+ aOKButton1( this, SfxResId( 1 ) ),
+ aCancelButton1( this, SfxResId( 1 ) )
+{
+ FreeResource();
+
+ String sServer, sTopic, sItem;
+ pLink->GetLinkManager()->GetDisplayNames( pLink, &sServer, &sTopic, &sItem );
+
+ aEdDdeApp.SetText( sServer );
+ aEdDdeTopic.SetText( sTopic );
+ aEdDdeItem.SetText( sItem );
+
+ aEdDdeApp.SetModifyHdl( STATIC_LINK( this, SvDDELinkEditDialog, EditHdl_Impl));
+ aEdDdeTopic.SetModifyHdl( STATIC_LINK( this, SvDDELinkEditDialog, EditHdl_Impl));
+ aEdDdeItem.SetModifyHdl( STATIC_LINK( this, SvDDELinkEditDialog, EditHdl_Impl));
+
+ aOKButton1.Enable( sServer.Len() && sTopic.Len() && sItem.Len() );
+}
+
+String SvDDELinkEditDialog::GetCmd() const
+{
+ String sCmd( aEdDdeApp.GetText() ), sRet;
+ ::sfx2::MakeLnkName( sRet, &sCmd, aEdDdeTopic.GetText(), aEdDdeItem.GetText() );
+ return sRet;
+}
+
+IMPL_STATIC_LINK( SvDDELinkEditDialog, EditHdl_Impl, Edit *, pEdit )
+{
+ (void)pEdit; // unused variable
+ pThis->aOKButton1.Enable( pThis->aEdDdeApp.GetText().Len() &&
+ pThis->aEdDdeTopic.GetText().Len() &&
+ pThis->aEdDdeItem.GetText().Len() );
+ return 0;
+}
+
+/* */
+
+
+SvDDEObject::SvDDEObject()
+ : pConnection( 0 ), pLink( 0 ), pRequest( 0 ), pGetData( 0 ), nError( 0 )
+{
+ SetUpdateTimeout( 100 );
+ bWaitForData = FALSE;
+}
+
+SvDDEObject::~SvDDEObject()
+{
+ delete pLink;
+ delete pRequest;
+ delete pConnection;
+}
+
+BOOL SvDDEObject::GetData( ::com::sun::star::uno::Any & rData /*out param*/,
+ const String & rMimeType,
+ BOOL bSynchron )
+{
+ if( !pConnection )
+ return FALSE;
+
+ if( pConnection->GetError() ) // dann versuchen wir es nochmal
+ {
+ String sServer( pConnection->GetServiceName() );
+ String sTopic( pConnection->GetTopicName() );
+
+ delete pConnection;
+ pConnection = new DdeConnection( sServer, sTopic );
+ if( pConnection->GetError() )
+ nError = DDELINK_ERROR_APP;
+ }
+
+ if( bWaitForData ) // wir sind rekursiv drin, wieder raus
+ return FALSE;
+
+ // Verriegeln gegen Reentrance
+ bWaitForData = TRUE;
+
+ // falls gedruckt werden soll, warten wir bis die Daten vorhanden sind
+ if( bSynchron )
+ {
+ DdeRequest aReq( *pConnection, sItem, 5000 );
+ aReq.SetDataHdl( LINK( this, SvDDEObject, ImplGetDDEData ) );
+ aReq.SetFormat( SotExchange::GetFormatIdFromMimeType( rMimeType ));
+
+ pGetData = &rData;
+
+ do {
+ aReq.Execute();
+ } while( aReq.GetError() && ImplHasOtherFormat( aReq ) );
+
+ if( pConnection->GetError() )
+ nError = DDELINK_ERROR_DATA;
+
+ bWaitForData = FALSE;
+ }
+ else
+ {
+ // ansonsten wird es asynchron ausgefuehrt
+// if( !pLink || !pLink->IsBusy() )
+ {
+ if( pRequest )
+ delete pRequest;
+
+ pRequest = new DdeRequest( *pConnection, sItem );
+ pRequest->SetDataHdl( LINK( this, SvDDEObject, ImplGetDDEData ) );
+ pRequest->SetDoneHdl( LINK( this, SvDDEObject, ImplDoneDDEData ) );
+ pRequest->SetFormat( SotExchange::GetFormatIdFromMimeType(
+ rMimeType ) );
+ pRequest->Execute();
+ }
+
+ ::rtl::OUString aEmptyStr;
+ rData <<= aEmptyStr;
+ }
+ return 0 == pConnection->GetError();
+}
+
+
+BOOL SvDDEObject::Connect( SvBaseLink * pSvLink )
+{
+#if defined(WNT)
+ static BOOL bInWinExec = FALSE;
+#endif
+ USHORT nLinkType = pSvLink->GetUpdateMode();
+ if( pConnection ) // Verbindung steht ja schon
+ {
+ // tja, dann nur noch als Abhaengig eintragen
+ AddDataAdvise( pSvLink,
+ SotExchange::GetFormatMimeType( pSvLink->GetContentType()),
+ LINKUPDATE_ONCALL == nLinkType
+ ? ADVISEMODE_ONLYONCE
+ : 0 );
+ AddConnectAdvise( pSvLink );
+
+ return TRUE;
+ }
+
+ if( !pSvLink->GetLinkManager() )
+ return FALSE;
+
+ String sServer, sTopic;
+ pSvLink->GetLinkManager()->GetDisplayNames( pSvLink, &sServer, &sTopic, &sItem );
+
+ if( !sServer.Len() || !sTopic.Len() || !sItem.Len() )
+ return FALSE;
+
+ pConnection = new DdeConnection( sServer, sTopic );
+ if( pConnection->GetError() )
+ {
+ // kann man denn das System-Topic ansprechen ?
+ // dann ist der Server oben, kennt nur nicht das Topic!
+ if( sTopic.EqualsIgnoreCaseAscii( "SYSTEM" ) )
+ {
+ BOOL bSysTopic;
+ {
+ DdeConnection aTmp( sServer, String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "SYSTEM" ) ) );
+ bSysTopic = !aTmp.GetError();
+ }
+
+ if( bSysTopic )
+ {
+ nError = DDELINK_ERROR_DATA;
+ return FALSE;
+ }
+ // ansonsten unter Win/WinNT die Applikation direkt starten
+ }
+
+#if defined(WNT)
+
+ // Server nicht da, starten und nochmal versuchen
+ if( !bInWinExec )
+ {
+ ByteString aCmdLine( sServer, RTL_TEXTENCODING_ASCII_US );
+ aCmdLine.Append( ".exe " );
+ aCmdLine.Append( ByteString( sTopic, RTL_TEXTENCODING_ASCII_US ) );
+
+ if( WinExec( aCmdLine.GetBuffer(), SW_SHOWMINIMIZED ) < 32 )
+ nError = DDELINK_ERROR_APP;
+ else
+ {
+ USHORT i;
+ for( i=0; i<5; i++ )
+ {
+ bInWinExec = TRUE;
+ Application::Reschedule();
+ bInWinExec = FALSE;
+
+ delete pConnection;
+ pConnection = new DdeConnection( sServer, sTopic );
+ if( !pConnection->GetError() )
+ break;
+ }
+
+ if( i == 5 )
+ {
+ nError = DDELINK_ERROR_APP;
+ }
+ }
+ }
+ else
+#endif // WNT
+ {
+ nError = DDELINK_ERROR_APP;
+ }
+ }
+
+ if( LINKUPDATE_ALWAYS == nLinkType && !pLink && !pConnection->GetError() )
+ {
+ // Hot Link einrichten, Daten kommen irgendwann spaeter
+ pLink = new DdeHotLink( *pConnection, sItem );
+ pLink->SetDataHdl( LINK( this, SvDDEObject, ImplGetDDEData ) );
+ pLink->SetDoneHdl( LINK( this, SvDDEObject, ImplDoneDDEData ) );
+ pLink->SetFormat( pSvLink->GetContentType() );
+ pLink->Execute();
+ }
+
+ if( pConnection->GetError() )
+ return FALSE;
+
+ AddDataAdvise( pSvLink,
+ SotExchange::GetFormatMimeType( pSvLink->GetContentType()),
+ LINKUPDATE_ONCALL == nLinkType
+ ? ADVISEMODE_ONLYONCE
+ : 0 );
+ AddConnectAdvise( pSvLink );
+ SetUpdateTimeout( 0 );
+ return TRUE;
+}
+
+void SvDDEObject::Edit( Window* pParent, sfx2::SvBaseLink* pBaseLink, const Link& rEndEditHdl )
+{
+ SvDDELinkEditDialog aDlg( pParent, pBaseLink );
+ if ( RET_OK == aDlg.Execute() && rEndEditHdl.IsSet() )
+ {
+ String sCommand = aDlg.GetCmd();
+ rEndEditHdl.Call( &sCommand );
+ }
+}
+
+BOOL SvDDEObject::ImplHasOtherFormat( DdeTransaction& rReq )
+{
+ USHORT nFmt = 0;
+ switch( rReq.GetFormat() )
+ {
+ case FORMAT_RTF:
+ nFmt = FORMAT_STRING;
+ break;
+
+ case SOT_FORMATSTR_ID_HTML_SIMPLE:
+ case SOT_FORMATSTR_ID_HTML:
+ nFmt = FORMAT_RTF;
+ break;
+
+ case FORMAT_GDIMETAFILE:
+ nFmt = FORMAT_BITMAP;
+ break;
+
+ case SOT_FORMATSTR_ID_SVXB:
+ nFmt = FORMAT_GDIMETAFILE;
+ break;
+
+ // sonst noch irgendwas ??
+ }
+ if( nFmt )
+ rReq.SetFormat( nFmt ); // damit nochmal versuchen
+ return 0 != nFmt;
+}
+
+BOOL SvDDEObject::IsPending() const
+/* [Beschreibung]
+
+ Die Methode stellt fest, ob aus einem DDE-Object die Daten gelesen
+ werden kann.
+ Zurueckgegeben wird:
+ ERRCODE_NONE wenn sie komplett gelesen wurde
+ ERRCODE_SO_PENDING wenn sie noch nicht komplett gelesen wurde
+ ERRCODE_SO_FALSE sonst
+*/
+{
+ return bWaitForData;
+}
+
+BOOL SvDDEObject::IsDataComplete() const
+{
+ return bWaitForData;
+}
+
+IMPL_LINK( SvDDEObject, ImplGetDDEData, DdeData*, pData )
+{
+ ULONG nFmt = pData->GetFormat();
+ switch( nFmt )
+ {
+ case FORMAT_GDIMETAFILE:
+ break;
+
+ case FORMAT_BITMAP:
+ break;
+
+ default:
+ {
+ const sal_Char* p = (sal_Char*)( pData->operator const void*() );
+ long nLen = FORMAT_STRING == nFmt ? (p ? strlen( p ) : 0) : (long)*pData;
+
+ Sequence< sal_Int8 > aSeq( (const sal_Int8*)p, nLen );
+ if( pGetData )
+ {
+ *pGetData <<= aSeq; // Daten kopieren
+ pGetData = 0; // und den Pointer bei mir zuruecksetzen
+ }
+ else
+ {
+ Any aVal;
+ aVal <<= aSeq;
+ DataChanged( SotExchange::GetFormatMimeType(
+ pData->GetFormat() ), aVal );
+ bWaitForData = FALSE;
+ }
+ }
+ }
+
+ return 0;
+}
+
+IMPL_LINK( SvDDEObject, ImplDoneDDEData, void*, pData )
+{
+ BOOL bValid = (BOOL)(ULONG)pData;
+ if( !bValid && ( pRequest || pLink ))
+ {
+ DdeTransaction* pReq = 0;
+ if( !pLink || ( pLink && pLink->IsBusy() ))
+ pReq = pRequest; // dann kann nur der fertig sein
+ else if( pRequest && pRequest->IsBusy() )
+ pReq = pLink; // dann kann nur der fertig sein
+
+ if( pReq )
+ {
+ if( ImplHasOtherFormat( *pReq ) )
+ {
+ pReq->Execute();
+ }
+ else if( pReq == pRequest )
+ {
+ // das wars dann
+ bWaitForData = FALSE;
+ }
+ }
+ }
+ else
+ // das warten ist beendet
+ bWaitForData = FALSE;
+
+ return 0;
+}
+
+}
diff --git a/sfx2/source/appl/impldde.hxx b/sfx2/source/appl/impldde.hxx
new file mode 100644
index 000000000000..b361df4468d3
--- /dev/null
+++ b/sfx2/source/appl/impldde.hxx
@@ -0,0 +1,78 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _IMPLDDE_HXX
+#define _IMPLDDE_HXX
+
+#include <sfx2/linksrc.hxx>
+#include <tools/string.hxx>
+
+class DdeConnection;
+class DdeData;
+class DdeLink;
+class DdeRequest;
+class DdeTransaction;
+
+namespace sfx2
+{
+
+class SvDDEObject : public SvLinkSource
+{
+ String sItem;
+
+ DdeConnection* pConnection;
+ DdeLink* pLink;
+ DdeRequest* pRequest;
+ ::com::sun::star::uno::Any * pGetData;
+
+ BYTE bWaitForData : 1; // wird auf Daten gewartet?
+ BYTE nError : 7; // Error Code fuer den Dialog
+
+
+ BOOL ImplHasOtherFormat( DdeTransaction& );
+ DECL_LINK( ImplGetDDEData, DdeData* );
+ DECL_LINK( ImplDoneDDEData, void* );
+
+protected:
+ virtual ~SvDDEObject();
+
+public:
+ SvDDEObject();
+
+ virtual BOOL GetData( ::com::sun::star::uno::Any & rData /*out param*/,
+ const String & aMimeType,
+ BOOL bSynchron = FALSE );
+
+ virtual BOOL Connect( SvBaseLink * );
+ virtual void Edit( Window* pParent, sfx2::SvBaseLink* pBaseLink, const Link& rEndEditHdl );
+
+ virtual BOOL IsPending() const;
+ virtual BOOL IsDataComplete() const;
+};
+
+}
+
+#endif
diff --git a/sfx2/source/appl/linkmgr2.cxx b/sfx2/source/appl/linkmgr2.cxx
new file mode 100644
index 000000000000..934b4051a638
--- /dev/null
+++ b/sfx2/source/appl/linkmgr2.cxx
@@ -0,0 +1,636 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sfx2/linkmgr.hxx>
+#include <com/sun/star/document/UpdateDocMode.hpp>
+#include <sfx2/objsh.hxx>
+#include <svl/urihelper.hxx>
+#include <sot/formats.hxx>
+#include <tools/urlobj.hxx>
+#include <sot/exchange.hxx>
+#include <tools/debug.hxx>
+#include <vcl/msgbox.hxx>
+#include <sfx2/lnkbase.hxx>
+#include <sfx2/app.hxx>
+#include <vcl/graph.hxx>
+#include <svl/stritem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <i18npool/mslangid.hxx>
+#include <sfx2/request.hxx>
+
+#include "fileobj.hxx"
+#include "impldde.hxx"
+#include "app.hrc"
+#include "sfx2/sfxresid.hxx"
+
+#define _SVSTDARR_STRINGSDTOR
+#include <svl/svstdarr.hxx>
+
+namespace sfx2
+{
+
+class SvxInternalLink : public sfx2::SvLinkSource
+{
+public:
+ SvxInternalLink() {}
+
+ virtual BOOL Connect( sfx2::SvBaseLink* );
+};
+
+
+SV_IMPL_PTRARR( SvBaseLinks, SvBaseLinkRefPtr )
+
+LinkManager::LinkManager(SfxObjectShell* p)
+ : pPersist( p )
+{
+}
+
+
+LinkManager::~LinkManager()
+{
+ SvBaseLinkRef** ppRef = (SvBaseLinkRef**)aLinkTbl.GetData();
+ for( USHORT n = aLinkTbl.Count(); n; --n, ++ppRef )
+ {
+ if( (*ppRef)->Is() )
+ {
+ (*(*ppRef))->Disconnect();
+ (*(*ppRef))->SetLinkManager( NULL );
+ }
+ delete *ppRef;
+ }
+}
+
+
+/************************************************************************
+|* LinkManager::Remove()
+|*
+|* Beschreibung
+*************************************************************************/
+
+void LinkManager::Remove( SvBaseLink *pLink )
+{
+ // keine Links doppelt einfuegen
+ int bFound = FALSE;
+ SvBaseLinkRef** ppRef = (SvBaseLinkRef**)aLinkTbl.GetData();
+ for( USHORT n = aLinkTbl.Count(); n; --n, ++ppRef )
+ {
+ if( pLink == *(*ppRef) )
+ {
+ (*(*ppRef))->Disconnect();
+ (*(*ppRef))->SetLinkManager( NULL );
+ (*(*ppRef)).Clear();
+ bFound = TRUE;
+ }
+
+ // falls noch leere rum stehen sollten, weg damit
+ if( !(*ppRef)->Is() )
+ {
+ delete *ppRef;
+ aLinkTbl.Remove( aLinkTbl.Count() - n, 1 );
+ if( bFound )
+ return ;
+ --ppRef;
+ }
+ }
+}
+
+
+void LinkManager::Remove( USHORT nPos, USHORT nCnt )
+{
+ if( nCnt && nPos < aLinkTbl.Count() )
+ {
+ if( nPos + nCnt > aLinkTbl.Count() )
+ nCnt = aLinkTbl.Count() - nPos;
+
+ SvBaseLinkRef** ppRef = (SvBaseLinkRef**)aLinkTbl.GetData() + nPos;
+ for( USHORT n = nCnt; n; --n, ++ppRef )
+ {
+ if( (*ppRef)->Is() )
+ {
+ (*(*ppRef))->Disconnect();
+ (*(*ppRef))->SetLinkManager( NULL );
+ }
+ delete *ppRef;
+ }
+ aLinkTbl.Remove( nPos, nCnt );
+ }
+}
+
+
+BOOL LinkManager::Insert( SvBaseLink* pLink )
+{
+ // keine Links doppelt einfuegen
+ for( USHORT n = 0; n < aLinkTbl.Count(); ++n )
+ {
+ SvBaseLinkRef* pTmp = aLinkTbl[ n ];
+ if( !pTmp->Is() )
+ aLinkTbl.DeleteAndDestroy( n-- );
+
+ if( pLink == *pTmp )
+ return FALSE;
+ }
+
+ SvBaseLinkRef* pTmp = new SvBaseLinkRef( pLink );
+ pLink->SetLinkManager( this );
+ aLinkTbl.Insert( pTmp, aLinkTbl.Count() );
+ return TRUE;
+}
+
+
+BOOL LinkManager::InsertLink( SvBaseLink * pLink,
+ USHORT nObjType,
+ USHORT nUpdateMode,
+ const String* pName )
+{
+ // unbedingt zuerst
+ pLink->SetObjType( nObjType );
+ if( pName )
+ pLink->SetName( *pName );
+ pLink->SetUpdateMode( nUpdateMode );
+ return Insert( pLink );
+}
+
+
+BOOL LinkManager::InsertDDELink( SvBaseLink * pLink,
+ const String& rServer,
+ const String& rTopic,
+ const String& rItem )
+{
+ if( !( OBJECT_CLIENT_SO & pLink->GetObjType() ) )
+ return FALSE;
+
+ String sCmd;
+ ::sfx2::MakeLnkName( sCmd, &rServer, rTopic, rItem );
+
+ pLink->SetObjType( OBJECT_CLIENT_DDE );
+ pLink->SetName( sCmd );
+ return Insert( pLink );
+}
+
+
+BOOL LinkManager::InsertDDELink( SvBaseLink * pLink )
+{
+ DBG_ASSERT( OBJECT_CLIENT_SO & pLink->GetObjType(), "no OBJECT_CLIENT_SO" );
+ if( !( OBJECT_CLIENT_SO & pLink->GetObjType() ) )
+ return FALSE;
+
+ if( pLink->GetObjType() == OBJECT_CLIENT_SO )
+ pLink->SetObjType( OBJECT_CLIENT_DDE );
+
+ return Insert( pLink );
+}
+
+
+// erfrage die Strings fuer den Dialog
+BOOL LinkManager::GetDisplayNames( const SvBaseLink * pLink,
+ String* pType,
+ String* pFile,
+ String* pLinkStr,
+ String* pFilter ) const
+{
+ BOOL bRet = FALSE;
+ const String sLNm( pLink->GetLinkSourceName() );
+ if( sLNm.Len() )
+ {
+ switch( pLink->GetObjType() )
+ {
+ case OBJECT_CLIENT_FILE:
+ case OBJECT_CLIENT_GRF:
+ case OBJECT_CLIENT_OLE:
+ {
+ USHORT nPos = 0;
+ String sFile( sLNm.GetToken( 0, ::sfx2::cTokenSeperator, nPos ) );
+ String sRange( sLNm.GetToken( 0, ::sfx2::cTokenSeperator, nPos ) );
+
+ if( pFile )
+ *pFile = sFile;
+ if( pLinkStr )
+ *pLinkStr = sRange;
+ if( pFilter )
+ *pFilter = sLNm.Copy( nPos );
+
+ if( pType )
+ {
+ sal_uInt16 nObjType = pLink->GetObjType();
+ *pType = String( SfxResId(
+ ( OBJECT_CLIENT_FILE == nObjType || OBJECT_CLIENT_OLE == nObjType )
+ ? RID_SVXSTR_FILELINK
+ : RID_SVXSTR_GRAFIKLINK ));
+ }
+ bRet = TRUE;
+ }
+ break;
+ case OBJECT_CLIENT_DDE:
+ {
+ USHORT nTmp = 0;
+ String sCmd( sLNm );
+ String sServer( sCmd.GetToken( 0, cTokenSeperator, nTmp ) );
+ String sTopic( sCmd.GetToken( 0, cTokenSeperator, nTmp ) );
+
+ if( pType )
+ *pType = sServer;
+ if( pFile )
+ *pFile = sTopic;
+ if( pLinkStr )
+ *pLinkStr = sCmd.Copy( nTmp );
+ bRet = TRUE;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ return bRet;
+}
+
+
+void LinkManager::UpdateAllLinks(
+ BOOL bAskUpdate,
+ BOOL /*bCallErrHdl*/,
+ BOOL bUpdateGrfLinks,
+ Window* pParentWin )
+{
+ SvStringsDtor aApps, aTopics, aItems;
+ String sApp, sTopic, sItem;
+
+ // erstmal eine Kopie vom Array machen, damit sich updatende Links in
+ // Links in ... nicht dazwischen funken!!
+ SvPtrarr aTmpArr( 255, 50 );
+ USHORT n;
+ for( n = 0; n < aLinkTbl.Count(); ++n )
+ {
+ SvBaseLink* pLink = *aLinkTbl[ n ];
+ if( !pLink )
+ {
+ Remove( n-- );
+ continue;
+ }
+ aTmpArr.Insert( pLink, aTmpArr.Count() );
+ }
+
+ for( n = 0; n < aTmpArr.Count(); ++n )
+ {
+ SvBaseLink* pLink = (SvBaseLink*)aTmpArr[ n ];
+
+ // suche erstmal im Array nach dem Eintrag
+ USHORT nFndPos = USHRT_MAX;
+ for( USHORT i = 0; i < aLinkTbl.Count(); ++i )
+ if( pLink == *aLinkTbl[ i ] )
+ {
+ nFndPos = i;
+ break;
+ }
+
+ if( USHRT_MAX == nFndPos )
+ continue; // war noch nicht vorhanden!
+
+ // Graphic-Links noch nicht updaten
+ if( !pLink->IsVisible() ||
+ ( !bUpdateGrfLinks && OBJECT_CLIENT_GRF == pLink->GetObjType() ))
+ continue;
+
+ if( bAskUpdate )
+ {
+ int nRet = QueryBox( pParentWin, WB_YES_NO | WB_DEF_YES, SfxResId( STR_QUERY_UPDATE_LINKS ) ).Execute();
+ if( RET_YES != nRet )
+ return ; // es soll nichts geupdatet werden
+ bAskUpdate = FALSE; // einmal reicht
+ }
+
+ pLink->Update();
+ }
+}
+
+/************************************************************************
+|* SvBaseLink::CreateObject()
+|*
+|* Beschreibung
+*************************************************************************/
+
+SvLinkSourceRef LinkManager::CreateObj( SvBaseLink * pLink )
+{
+ switch( pLink->GetObjType() )
+ {
+ case OBJECT_CLIENT_FILE:
+ case OBJECT_CLIENT_GRF:
+ case OBJECT_CLIENT_OLE:
+ return new SvFileObject;
+ case OBJECT_INTERN:
+ return new SvxInternalLink;
+ case OBJECT_CLIENT_DDE:
+ return new SvDDEObject;
+ default:
+ return SvLinkSourceRef();
+ }
+}
+
+BOOL LinkManager::InsertServer( SvLinkSource* pObj )
+{
+ // keine doppelt einfuegen
+ if( !pObj || USHRT_MAX != aServerTbl.GetPos( pObj ) )
+ return FALSE;
+
+ aServerTbl.Insert( pObj, aServerTbl.Count() );
+ return TRUE;
+}
+
+
+void LinkManager::RemoveServer( SvLinkSource* pObj )
+{
+ USHORT nPos = aServerTbl.GetPos( pObj );
+ if( USHRT_MAX != nPos )
+ aServerTbl.Remove( nPos, 1 );
+}
+
+
+void MakeLnkName( String& rName, const String* pType, const String& rFile,
+ const String& rLink, const String* pFilter )
+{
+ if( pType )
+ (rName = *pType).EraseLeadingChars().EraseTrailingChars() += cTokenSeperator;
+ else if( rName.Len() )
+ rName.Erase();
+
+ ((rName += rFile).EraseLeadingChars().EraseTrailingChars() +=
+ cTokenSeperator ).EraseLeadingChars().EraseTrailingChars() += rLink;
+ if( pFilter )
+ ((rName += cTokenSeperator ) += *pFilter).EraseLeadingChars().EraseTrailingChars();
+}
+
+BOOL LinkManager::InsertFileLink( sfx2::SvBaseLink& rLink,
+ USHORT nFileType,
+ const String& rFileNm,
+ const String* pFilterNm,
+ const String* pRange )
+{
+ if( !( OBJECT_CLIENT_SO & rLink.GetObjType() ))
+ return FALSE;
+
+ String sCmd( rFileNm );
+ sCmd += ::sfx2::cTokenSeperator;
+ if( pRange )
+ sCmd += *pRange;
+ if( pFilterNm )
+ ( sCmd += ::sfx2::cTokenSeperator ) += *pFilterNm;
+
+ return InsertLink( &rLink, nFileType, sfx2::LINKUPDATE_ONCALL, &sCmd );
+}
+
+BOOL LinkManager::InsertFileLink( sfx2::SvBaseLink& rLink )
+{
+ if( OBJECT_CLIENT_FILE == ( OBJECT_CLIENT_FILE & rLink.GetObjType() ))
+ return InsertLink( &rLink, rLink.GetObjType(), sfx2::LINKUPDATE_ONCALL );
+ return FALSE;
+}
+
+// eine Uebertragung wird abgebrochen, also alle DownloadMedien canceln
+// (ist zur Zeit nur fuer die FileLinks interressant!)
+void LinkManager::CancelTransfers()
+{
+ SvFileObject* pFileObj;
+ sfx2::SvBaseLink* pLnk;
+
+ const sfx2::SvBaseLinks& rLnks = GetLinks();
+ for( USHORT n = rLnks.Count(); n; )
+ if( 0 != ( pLnk = &(*rLnks[ --n ])) &&
+ OBJECT_CLIENT_FILE == (OBJECT_CLIENT_FILE & pLnk->GetObjType()) &&
+ 0 != ( pFileObj = (SvFileObject*)pLnk->GetObj() ) )
+// 0 != ( pFileObj = (SvFileObject*)SvFileObject::ClassFactory()->
+// CastAndAddRef( pLnk->GetObj() )) )
+ pFileObj->CancelTransfers();
+}
+
+ // um Status Informationen aus dem FileObject an den BaseLink zu
+ // senden, gibt es eine eigene ClipBoardId. Das SvData-Object hat
+ // dann die entsprechenden Informationen als String.
+ // Wird zur Zeit fuer FileObject in Verbindung mit JavaScript benoetigt
+ // - das braucht Informationen ueber Load/Abort/Error
+ULONG LinkManager::RegisterStatusInfoId()
+{
+ static ULONG nFormat = 0;
+
+ if( !nFormat )
+ {
+// wie sieht die neue Schnittstelle aus?
+// nFormat = Exchange::RegisterFormatName( "StatusInfo vom SvxInternalLink" );
+ nFormat = SotExchange::RegisterFormatName(
+ String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(
+ "StatusInfo vom SvxInternalLink" )));
+ }
+ return nFormat;
+}
+
+// ----------------------------------------------------------------------
+
+BOOL LinkManager::GetGraphicFromAny( const String& rMimeType,
+ const ::com::sun::star::uno::Any & rValue,
+ Graphic& rGrf )
+{
+ BOOL bRet = FALSE;
+ ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
+ if( rValue.hasValue() && ( rValue >>= aSeq ) )
+ {
+ SvMemoryStream aMemStm( (void*)aSeq.getConstArray(), aSeq.getLength(),
+ STREAM_READ );
+ aMemStm.Seek( 0 );
+
+ switch( SotExchange::GetFormatIdFromMimeType( rMimeType ) )
+ {
+ case SOT_FORMATSTR_ID_SVXB:
+ {
+ aMemStm >> rGrf;
+ bRet = TRUE;
+ }
+ break;
+ case FORMAT_GDIMETAFILE:
+ {
+ GDIMetaFile aMtf;
+ aMtf.Read( aMemStm );
+ rGrf = aMtf;
+ bRet = TRUE;
+ }
+ break;
+ case FORMAT_BITMAP:
+ {
+ Bitmap aBmp;
+ aMemStm >> aBmp;
+ rGrf = aBmp;
+ bRet = TRUE;
+ }
+ break;
+ }
+ }
+ return bRet;
+}
+
+
+// ----------------------------------------------------------------------
+String lcl_DDE_RelToAbs( const String& rTopic, const String& rBaseURL )
+{
+ String sRet;
+ INetURLObject aURL( rTopic );
+ if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
+ utl::LocalFileHelper::ConvertSystemPathToURL( rTopic, rBaseURL, sRet );
+ if( !sRet.Len() )
+ sRet = URIHelper::SmartRel2Abs( INetURLObject(rBaseURL), rTopic, URIHelper::GetMaybeFileHdl(), true );
+ return sRet;
+}
+
+BOOL SvxInternalLink::Connect( sfx2::SvBaseLink* pLink )
+{
+ SfxObjectShell* pFndShell = 0;
+ USHORT nUpdateMode = com::sun::star::document::UpdateDocMode::NO_UPDATE;
+ String sTopic, sItem, sReferer;
+ if( pLink->GetLinkManager() &&
+ pLink->GetLinkManager()->GetDisplayNames( pLink, 0, &sTopic, &sItem )
+ && sTopic.Len() )
+ {
+ // erstmal nur ueber die DocumentShells laufen und die mit dem
+ // Namen heraussuchen:
+
+ com::sun::star::lang::Locale aLocale;
+ MsLangId::convertLanguageToLocale( LANGUAGE_SYSTEM, aLocale );
+ CharClass aCC( aLocale );
+
+ String sNm( sTopic ), sTmp;
+ aCC.toLower( sNm );
+
+ TypeId aType( TYPE(SfxObjectShell) );
+
+ BOOL bFirst = TRUE;
+ SfxObjectShell* pShell = pLink->GetLinkManager()->GetPersist();
+ if( pShell && pShell->GetMedium() )
+ {
+ sReferer = pShell->GetMedium()->GetBaseURL();
+ SFX_ITEMSET_ARG( pShell->GetMedium()->GetItemSet(), pItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False );
+ if ( pItem )
+ nUpdateMode = pItem->GetValue();
+ }
+
+ String sNmURL( lcl_DDE_RelToAbs( sTopic, sReferer ) );
+ aCC.toLower( sNmURL );
+
+ if ( !pShell )
+ {
+ bFirst = FALSE;
+ pShell = SfxObjectShell::GetFirst( &aType, sal_False );
+ }
+
+ while( pShell )
+ {
+ if( !sTmp.Len() )
+ {
+ sTmp = pShell->GetTitle( SFX_TITLE_FULLNAME );
+ sTmp = lcl_DDE_RelToAbs(sTmp, sReferer );
+ }
+
+
+ aCC.toLower( sTmp );
+ if( sTmp == sNmURL ) // die wollen wir haben
+ {
+ pFndShell = pShell;
+ break;
+ }
+
+ if( bFirst )
+ {
+ bFirst = FALSE;
+ pShell = SfxObjectShell::GetFirst( &aType, sal_False );
+ }
+ else
+ pShell = SfxObjectShell::GetNext( *pShell, &aType, sal_False );
+
+ sTmp.Erase();
+ }
+ }
+
+ // empty topics are not allowed - which document is it
+ if( !sTopic.Len() )
+ return FALSE;
+
+ if( !pFndShell )
+ {
+ // dann versuche die Datei zu laden:
+ INetURLObject aURL( sTopic );
+ INetProtocol eOld = aURL.GetProtocol();
+ aURL.SetURL( sTopic = lcl_DDE_RelToAbs( sTopic, sReferer ) );
+ if( INET_PROT_NOT_VALID != eOld ||
+ INET_PROT_HTTP != aURL.GetProtocol() )
+ {
+ SfxStringItem aName( SID_FILE_NAME, sTopic );
+ SfxBoolItem aMinimized(SID_MINIMIZED, TRUE);
+ SfxBoolItem aHidden(SID_HIDDEN, TRUE);
+ SfxStringItem aTarget( SID_TARGETNAME, String::CreateFromAscii("_blank") );
+ SfxStringItem aReferer( SID_REFERER, sReferer );
+ SfxUInt16Item aUpdate( SID_UPDATEDOCMODE, nUpdateMode );
+ SfxBoolItem aReadOnly(SID_DOC_READONLY, TRUE);
+
+ // #i14200# (DDE-link crashes wordprocessor)
+ SfxAllItemSet aArgs( SFX_APP()->GetPool() );
+ aArgs.Put(aReferer);
+ aArgs.Put(aTarget);
+ aArgs.Put(aHidden);
+ aArgs.Put(aMinimized);
+ aArgs.Put(aName);
+ aArgs.Put(aUpdate);
+ aArgs.Put(aReadOnly);
+ pFndShell = SfxObjectShell::CreateAndLoadObject( aArgs );
+ }
+ }
+
+ BOOL bRet = FALSE;
+ if( pFndShell )
+ {
+ sfx2::SvLinkSource* pNewSrc = pFndShell->DdeCreateLinkSource( sItem );
+ if( pNewSrc )
+ {
+ bRet = TRUE;
+
+ ::com::sun::star::datatransfer::DataFlavor aFl;
+ SotExchange::GetFormatDataFlavor( pLink->GetContentType(), aFl );
+
+ pLink->SetObj( pNewSrc );
+ pNewSrc->AddDataAdvise( pLink, aFl.MimeType,
+ sfx2::LINKUPDATE_ONCALL == pLink->GetUpdateMode()
+ ? ADVISEMODE_ONLYONCE
+ : 0 );
+ }
+ }
+ return bRet;
+}
+
+
+}
+
+
+
diff --git a/sfx2/source/appl/linksrc.cxx b/sfx2/source/appl/linksrc.cxx
new file mode 100644
index 000000000000..e9fbde42328f
--- /dev/null
+++ b/sfx2/source/appl/linksrc.cxx
@@ -0,0 +1,435 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sfx2/linksrc.hxx>
+#include <sfx2/lnkbase.hxx>
+//#include <sot/exchange.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+
+#include <tools/debug.hxx>
+#include <vcl/timer.hxx>
+#include <svl/svarray.hxx>
+
+
+using namespace ::com::sun::star::uno;
+
+namespace sfx2
+{
+
+TYPEINIT0( SvLinkSource )
+
+/************** class SvLinkSourceTimer *********************************/
+class SvLinkSourceTimer : public Timer
+{
+ SvLinkSource * pOwner;
+ virtual void Timeout();
+public:
+ SvLinkSourceTimer( SvLinkSource * pOwn );
+};
+
+SvLinkSourceTimer::SvLinkSourceTimer( SvLinkSource * pOwn )
+ : pOwner( pOwn )
+{
+}
+
+void SvLinkSourceTimer::Timeout()
+{
+ // sicher gegen zerstoeren im Handler
+ SvLinkSourceRef aAdv( pOwner );
+ pOwner->SendDataChanged();
+}
+
+static void StartTimer( SvLinkSourceTimer ** ppTimer, SvLinkSource * pOwner,
+ ULONG nTimeout )
+{
+ if( !*ppTimer )
+ {
+ *ppTimer = new SvLinkSourceTimer( pOwner );
+ (*ppTimer)->SetTimeout( nTimeout );
+ (*ppTimer)->Start();
+ }
+}
+
+
+struct SvLinkSource_Entry_Impl
+{
+ SvBaseLinkRef xSink;
+ String aDataMimeType;
+ USHORT nAdviseModes;
+ BOOL bIsDataSink;
+
+ SvLinkSource_Entry_Impl( SvBaseLink* pLink, const String& rMimeType,
+ USHORT nAdvMode )
+ : xSink( pLink ), aDataMimeType( rMimeType ),
+ nAdviseModes( nAdvMode ), bIsDataSink( TRUE )
+ {}
+
+ SvLinkSource_Entry_Impl( SvBaseLink* pLink )
+ : xSink( pLink ), nAdviseModes( 0 ), bIsDataSink( FALSE )
+ {}
+
+ ~SvLinkSource_Entry_Impl();
+};
+
+SvLinkSource_Entry_Impl::~SvLinkSource_Entry_Impl()
+{
+}
+
+typedef SvLinkSource_Entry_Impl* SvLinkSource_Entry_ImplPtr;
+SV_DECL_PTRARR_DEL( SvLinkSource_Array_Impl, SvLinkSource_Entry_ImplPtr, 4, 4 )
+SV_IMPL_PTRARR( SvLinkSource_Array_Impl, SvLinkSource_Entry_ImplPtr );
+
+class SvLinkSource_EntryIter_Impl
+{
+ SvLinkSource_Array_Impl aArr;
+ const SvLinkSource_Array_Impl& rOrigArr;
+ USHORT nPos;
+public:
+ SvLinkSource_EntryIter_Impl( const SvLinkSource_Array_Impl& rArr );
+ ~SvLinkSource_EntryIter_Impl();
+ SvLinkSource_Entry_Impl* Curr()
+ { return nPos < aArr.Count() ? aArr[ nPos ] : 0; }
+ SvLinkSource_Entry_Impl* Next();
+ sal_Bool IsValidCurrValue( SvLinkSource_Entry_Impl* pEntry );
+};
+
+SvLinkSource_EntryIter_Impl::SvLinkSource_EntryIter_Impl(
+ const SvLinkSource_Array_Impl& rArr )
+ : rOrigArr( rArr ), nPos( 0 )
+{
+ aArr.Insert( &rArr, 0 );
+}
+SvLinkSource_EntryIter_Impl::~SvLinkSource_EntryIter_Impl()
+{
+ aArr.Remove( 0, aArr.Count() );
+}
+
+sal_Bool SvLinkSource_EntryIter_Impl::IsValidCurrValue( SvLinkSource_Entry_Impl* pEntry )
+{
+ return ( nPos < aArr.Count() && aArr[nPos] == pEntry && USHRT_MAX != rOrigArr.GetPos( pEntry ) );
+}
+
+SvLinkSource_Entry_Impl* SvLinkSource_EntryIter_Impl::Next()
+{
+ SvLinkSource_Entry_ImplPtr pRet = 0;
+ if( nPos + 1 < aArr.Count() )
+ {
+ ++nPos;
+ if( rOrigArr.Count() == aArr.Count() &&
+ rOrigArr[ nPos ] == aArr[ nPos ] )
+ pRet = aArr[ nPos ];
+ else
+ {
+ // then we must search the current (or the next) in the orig
+ do {
+ pRet = aArr[ nPos ];
+ if( USHRT_MAX != rOrigArr.GetPos( pRet ))
+ break;
+ pRet = 0;
+ ++nPos;
+ } while( nPos < aArr.Count() );
+
+ if( nPos >= aArr.Count() )
+ pRet = 0;
+ }
+ }
+ return pRet;
+}
+
+struct SvLinkSource_Impl
+{
+ SvLinkSource_Array_Impl aArr;
+ String aDataMimeType;
+ SvLinkSourceTimer * pTimer;
+ ULONG nTimeout;
+ com::sun::star::uno::Reference<com::sun::star::io::XInputStream>
+ m_xInputStreamToLoadFrom;
+ sal_Bool m_bIsReadOnly;
+
+ SvLinkSource_Impl() : pTimer( 0 ), nTimeout( 3000 ) {}
+ ~SvLinkSource_Impl();
+
+ void Closed();
+};
+
+SvLinkSource_Impl::~SvLinkSource_Impl()
+{
+ delete pTimer;
+}
+
+SvLinkSource::SvLinkSource()
+ : pImpl( new SvLinkSource_Impl )
+{
+}
+
+SvLinkSource::~SvLinkSource()
+{
+ delete pImpl;
+}
+
+
+SvLinkSource::StreamToLoadFrom SvLinkSource::getStreamToLoadFrom()
+{
+ return StreamToLoadFrom(
+ pImpl->m_xInputStreamToLoadFrom,
+ pImpl->m_bIsReadOnly);
+}
+
+void SvLinkSource::setStreamToLoadFrom(const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xInputStream,sal_Bool bIsReadOnly )
+{
+ pImpl->m_xInputStreamToLoadFrom = xInputStream;
+ pImpl->m_bIsReadOnly = bIsReadOnly;
+}
+
+// --> OD 2008-06-18 #i88291#
+void SvLinkSource::clearStreamToLoadFrom()
+{
+ pImpl->m_xInputStreamToLoadFrom.clear();
+}
+// <--
+
+void SvLinkSource::Closed()
+{
+ SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
+ for( SvLinkSource_Entry_Impl* p = aIter.Curr(); p; p = aIter.Next() )
+ if( !p->bIsDataSink )
+ p->xSink->Closed();
+}
+
+ULONG SvLinkSource::GetUpdateTimeout() const
+{
+ return pImpl->nTimeout;
+}
+
+void SvLinkSource::SetUpdateTimeout( ULONG nTimeout )
+{
+ pImpl->nTimeout = nTimeout;
+ if( pImpl->pTimer )
+ pImpl->pTimer->SetTimeout( nTimeout );
+}
+
+void SvLinkSource::SendDataChanged()
+{
+ SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
+ for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
+ {
+ if( p->bIsDataSink )
+ {
+ String sDataMimeType( pImpl->aDataMimeType );
+ if( !sDataMimeType.Len() )
+ sDataMimeType = p->aDataMimeType;
+
+ Any aVal;
+ if( ( p->nAdviseModes & ADVISEMODE_NODATA ) ||
+ GetData( aVal, sDataMimeType, TRUE ) )
+ {
+ p->xSink->DataChanged( sDataMimeType, aVal );
+
+ if ( !aIter.IsValidCurrValue( p ) )
+ continue;
+
+ if( p->nAdviseModes & ADVISEMODE_ONLYONCE )
+ {
+ USHORT nFndPos = pImpl->aArr.GetPos( p );
+ if( USHRT_MAX != nFndPos )
+ pImpl->aArr.DeleteAndDestroy( nFndPos );
+ }
+
+ }
+ }
+ }
+ if( pImpl->pTimer )
+ {
+ delete pImpl->pTimer;
+ pImpl->pTimer = NULL;
+ }
+ pImpl->aDataMimeType.Erase();
+}
+
+void SvLinkSource::NotifyDataChanged()
+{
+ if( pImpl->nTimeout )
+ StartTimer( &pImpl->pTimer, this, pImpl->nTimeout ); // Timeout neu
+ else
+ {
+ SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
+ for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
+ if( p->bIsDataSink )
+ {
+ Any aVal;
+ if( ( p->nAdviseModes & ADVISEMODE_NODATA ) ||
+ GetData( aVal, p->aDataMimeType, TRUE ) )
+ {
+ p->xSink->DataChanged( p->aDataMimeType, aVal );
+
+ if ( !aIter.IsValidCurrValue( p ) )
+ continue;
+
+ if( p->nAdviseModes & ADVISEMODE_ONLYONCE )
+ {
+ USHORT nFndPos = pImpl->aArr.GetPos( p );
+ if( USHRT_MAX != nFndPos )
+ pImpl->aArr.DeleteAndDestroy( nFndPos );
+ }
+ }
+ }
+
+ if( pImpl->pTimer )
+ {
+ delete pImpl->pTimer;
+ pImpl->pTimer = NULL;
+ }
+ }
+}
+
+// notify the sink, the mime type is not
+// a selection criterion
+void SvLinkSource::DataChanged( const String & rMimeType,
+ const ::com::sun::star::uno::Any & rVal )
+{
+ if( pImpl->nTimeout && !rVal.hasValue() )
+ { // nur wenn keine Daten mitgegeben wurden
+ // fire all data to the sink, independent of the requested format
+ pImpl->aDataMimeType = rMimeType;
+ StartTimer( &pImpl->pTimer, this, pImpl->nTimeout ); // Timeout neu
+ }
+ else
+ {
+ SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
+ for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
+ {
+ if( p->bIsDataSink )
+ {
+ p->xSink->DataChanged( rMimeType, rVal );
+
+ if ( !aIter.IsValidCurrValue( p ) )
+ continue;
+
+ if( p->nAdviseModes & ADVISEMODE_ONLYONCE )
+ {
+ USHORT nFndPos = pImpl->aArr.GetPos( p );
+ if( USHRT_MAX != nFndPos )
+ pImpl->aArr.DeleteAndDestroy( nFndPos );
+ }
+ }
+ }
+
+ if( pImpl->pTimer )
+ {
+ delete pImpl->pTimer;
+ pImpl->pTimer = NULL;
+ }
+ }
+}
+
+
+// only one link is correct
+void SvLinkSource::AddDataAdvise( SvBaseLink * pLink, const String& rMimeType,
+ USHORT nAdviseModes )
+{
+ SvLinkSource_Entry_ImplPtr pNew = new SvLinkSource_Entry_Impl(
+ pLink, rMimeType, nAdviseModes );
+ pImpl->aArr.Insert( pNew, pImpl->aArr.Count() );
+}
+
+void SvLinkSource::RemoveAllDataAdvise( SvBaseLink * pLink )
+{
+ SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
+ for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
+ if( p->bIsDataSink && &p->xSink == pLink )
+ {
+ USHORT nFndPos = pImpl->aArr.GetPos( p );
+ if( USHRT_MAX != nFndPos )
+ pImpl->aArr.DeleteAndDestroy( nFndPos );
+ }
+}
+
+// only one link is correct
+void SvLinkSource::AddConnectAdvise( SvBaseLink * pLink )
+{
+ SvLinkSource_Entry_ImplPtr pNew = new SvLinkSource_Entry_Impl( pLink );
+ pImpl->aArr.Insert( pNew, pImpl->aArr.Count() );
+}
+
+void SvLinkSource::RemoveConnectAdvise( SvBaseLink * pLink )
+{
+ SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
+ for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
+ if( !p->bIsDataSink && &p->xSink == pLink )
+ {
+ USHORT nFndPos = pImpl->aArr.GetPos( p );
+ if( USHRT_MAX != nFndPos )
+ pImpl->aArr.DeleteAndDestroy( nFndPos );
+ }
+}
+
+BOOL SvLinkSource::HasDataLinks( const SvBaseLink* pLink ) const
+{
+ BOOL bRet = FALSE;
+ const SvLinkSource_Entry_Impl* p;
+ for( USHORT n = 0, nEnd = pImpl->aArr.Count(); n < nEnd; ++n )
+ if( ( p = pImpl->aArr[ n ] )->bIsDataSink &&
+ ( !pLink || &p->xSink == pLink ) )
+ {
+ bRet = TRUE;
+ break;
+ }
+ return bRet;
+}
+
+// TRUE => waitinmg for data
+BOOL SvLinkSource::IsPending() const
+{
+ return FALSE;
+}
+
+// TRUE => data complete loaded
+BOOL SvLinkSource::IsDataComplete() const
+{
+ return TRUE;
+}
+
+BOOL SvLinkSource::Connect( SvBaseLink* )
+{
+ return TRUE;
+}
+
+BOOL SvLinkSource::GetData( ::com::sun::star::uno::Any &, const String &, BOOL )
+{
+ return FALSE;
+}
+
+void SvLinkSource::Edit( Window *, SvBaseLink *, const Link& )
+{
+}
+
+}
+
diff --git a/sfx2/source/appl/lnkbase2.cxx b/sfx2/source/appl/lnkbase2.cxx
new file mode 100644
index 000000000000..6a51783a8a04
--- /dev/null
+++ b/sfx2/source/appl/lnkbase2.cxx
@@ -0,0 +1,699 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+
+#include <sfx2/lnkbase.hxx>
+#include <sot/exchange.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <vcl/msgbox.hxx>
+#include <sfx2/linkmgr.hxx>
+#include <vcl/svapp.hxx>
+#include "app.hrc"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/filedlghelper.hxx>
+#include <tools/debug.hxx>
+#include <svl/svdde.hxx>
+
+using namespace ::com::sun::star::uno;
+
+namespace sfx2
+{
+
+TYPEINIT0( SvBaseLink )
+
+static DdeTopic* FindTopic( const String &, USHORT* = 0 );
+
+class ImplDdeItem;
+
+struct BaseLink_Impl
+{
+ Link m_aEndEditLink;
+ LinkManager* m_pLinkMgr;
+ Window* m_pParentWin;
+ FileDialogHelper* m_pFileDlg;
+ bool m_bIsConnect;
+
+ BaseLink_Impl() :
+ m_pLinkMgr( NULL )
+ , m_pParentWin( NULL )
+ , m_pFileDlg( NULL )
+ , m_bIsConnect( false )
+ {}
+
+ ~BaseLink_Impl()
+ { delete m_pFileDlg; }
+};
+
+// nur fuer die interne Verwaltung
+struct ImplBaseLinkData
+{
+ struct tClientType
+ {
+ // gilt fuer alle Links
+ ULONG nCntntType; // Update Format
+ // nicht Ole-Links
+ BOOL bIntrnlLnk; // ist es ein interner Link
+ USHORT nUpdateMode;// UpdateMode
+ };
+
+ struct tDDEType
+ {
+ ImplDdeItem* pItem;
+ };
+
+ union {
+ tClientType ClientType;
+ tDDEType DDEType;
+ };
+ ImplBaseLinkData()
+ {
+ ClientType.nCntntType = 0;
+ ClientType.bIntrnlLnk = FALSE;
+ ClientType.nUpdateMode = 0;
+ DDEType.pItem = NULL;
+ }
+};
+
+
+class ImplDdeItem : public DdeGetPutItem
+{
+ SvBaseLink* pLink;
+ DdeData aData;
+ Sequence< sal_Int8 > aSeq; // Datacontainer for DdeData !!!
+ BOOL bIsValidData : 1;
+ BOOL bIsInDTOR : 1;
+public:
+ ImplDdeItem( SvBaseLink& rLink, const String& rStr )
+ : DdeGetPutItem( rStr ), pLink( &rLink ), bIsValidData( FALSE ),
+ bIsInDTOR( FALSE )
+ {}
+ virtual ~ImplDdeItem();
+
+ virtual DdeData* Get( ULONG );
+ virtual BOOL Put( const DdeData* );
+ virtual void AdviseLoop( BOOL );
+
+ void Notify()
+ {
+ bIsValidData = FALSE;
+ DdeGetPutItem::NotifyClient();
+ }
+
+ BOOL IsInDTOR() const { return bIsInDTOR; }
+};
+
+
+/************************************************************************
+|* SvBaseLink::SvBaseLink()
+|*
+|* Beschreibung
+*************************************************************************/
+
+SvBaseLink::SvBaseLink()
+{
+ pImpl = new BaseLink_Impl();
+ nObjType = OBJECT_CLIENT_SO;
+ pImplData = new ImplBaseLinkData;
+ bVisible = bSynchron = bUseCache = TRUE;
+ bWasLastEditOK = FALSE;
+}
+
+/************************************************************************
+|* SvBaseLink::SvBaseLink()
+|*
+|* Beschreibung
+*************************************************************************/
+
+SvBaseLink::SvBaseLink( USHORT nUpdateMode, ULONG nContentType )
+{
+ pImpl = new BaseLink_Impl();
+ nObjType = OBJECT_CLIENT_SO;
+ pImplData = new ImplBaseLinkData;
+ bVisible = bSynchron = bUseCache = TRUE;
+ bWasLastEditOK = FALSE;
+
+ // falls es ein Ole-Link wird,
+ pImplData->ClientType.nUpdateMode = nUpdateMode;
+ pImplData->ClientType.nCntntType = nContentType;
+ pImplData->ClientType.bIntrnlLnk = FALSE;
+}
+
+/************************************************************************
+|* SvBaseLink::SvBaseLink()
+|*
+|* Beschreibung
+*************************************************************************/
+
+SvBaseLink::SvBaseLink( const String& rLinkName, USHORT nObjectType, SvLinkSource* pObj )
+{
+ bVisible = bSynchron = bUseCache = TRUE;
+ bWasLastEditOK = FALSE;
+ aLinkName = rLinkName;
+ pImplData = new ImplBaseLinkData;
+ nObjType = nObjectType;
+
+ if( !pObj )
+ {
+ DBG_ASSERT( pObj, "Wo ist mein zu linkendes Object" );
+ return;
+ }
+
+ if( OBJECT_DDE_EXTERN == nObjType )
+ {
+ USHORT nItemStt = 0;
+ DdeTopic* pTopic = FindTopic( aLinkName, &nItemStt );
+ if( pTopic )
+ {
+ // dann haben wir alles zusammen
+ // MM hat gefummelt ???
+ // MM_TODO wie kriege ich den Namen
+ String aStr = aLinkName; // xLinkName->GetDisplayName();
+ aStr = aStr.Copy( nItemStt );
+ pImplData->DDEType.pItem = new ImplDdeItem( *this, aStr );
+ pTopic->InsertItem( pImplData->DDEType.pItem );
+
+ // dann koennen wir uns auch das Advise merken
+ xObj = pObj;
+ }
+ }
+ else if( pObj->Connect( this ) )
+ xObj = pObj;
+}
+
+/************************************************************************
+|* SvBaseLink::~SvBaseLink()
+|*
+|* Beschreibung
+*************************************************************************/
+
+SvBaseLink::~SvBaseLink()
+{
+ Disconnect();
+
+ switch( nObjType )
+ {
+ case OBJECT_DDE_EXTERN:
+ if( !pImplData->DDEType.pItem->IsInDTOR() )
+ delete pImplData->DDEType.pItem;
+ break;
+ }
+
+ delete pImplData;
+}
+
+IMPL_LINK( SvBaseLink, EndEditHdl, String*, _pNewName )
+{
+ String sNewName;
+ if ( _pNewName )
+ sNewName = *_pNewName;
+ if ( !ExecuteEdit( sNewName ) )
+ sNewName.Erase();
+ bWasLastEditOK = ( sNewName.Len() > 0 );
+ if ( pImpl->m_aEndEditLink.IsSet() )
+ pImpl->m_aEndEditLink.Call( this );
+ return 0;
+}
+
+/************************************************************************
+|* SvBaseLink::SetObjType()
+|*
+|* Beschreibung
+*************************************************************************/
+
+void SvBaseLink::SetObjType( USHORT nObjTypeP )
+{
+ DBG_ASSERT( nObjType != OBJECT_CLIENT_DDE, "type already set" );
+ DBG_ASSERT( !xObj.Is(), "object exist" );
+
+ nObjType = nObjTypeP;
+}
+
+/************************************************************************
+|* SvBaseLink::SetName()
+|*
+|* Beschreibung
+*************************************************************************/
+
+void SvBaseLink::SetName( const String & rNm )
+{
+ aLinkName = rNm;
+}
+
+/************************************************************************
+|* SvBaseLink::GetName()
+|*
+|* Beschreibung
+*************************************************************************/
+
+String SvBaseLink::GetName() const
+{
+ return aLinkName;
+}
+
+/************************************************************************
+|* SvBaseLink::SetObj()
+|*
+|* Beschreibung
+*************************************************************************/
+
+void SvBaseLink::SetObj( SvLinkSource * pObj )
+{
+ DBG_ASSERT( (nObjType & OBJECT_CLIENT_SO &&
+ pImplData->ClientType.bIntrnlLnk) ||
+ nObjType == OBJECT_CLIENT_GRF,
+ "no intern link" );
+ xObj = pObj;
+}
+
+/************************************************************************
+|* SvBaseLink::SetLinkSourceName()
+|*
+|* Beschreibung
+*************************************************************************/
+
+void SvBaseLink::SetLinkSourceName( const String & rLnkNm )
+{
+ if( aLinkName == rLnkNm )
+ return;
+
+ AddNextRef(); // sollte ueberfluessig sein
+ // Alte Verbindung weg
+ Disconnect();
+
+ aLinkName = rLnkNm;
+
+ // Neu verbinden
+ _GetRealObject();
+ ReleaseRef(); // sollte ueberfluessig sein
+}
+
+/************************************************************************
+|* SvBaseLink::GetLinkSourceName()
+|*
+|* Beschreibung
+*************************************************************************/
+
+String SvBaseLink::GetLinkSourceName() const
+{
+ return aLinkName;
+}
+
+
+/************************************************************************
+|* SvBaseLink::SetUpdateMode()
+|*
+|* Beschreibung
+*************************************************************************/
+
+void SvBaseLink::SetUpdateMode( USHORT nMode )
+{
+ if( ( OBJECT_CLIENT_SO & nObjType ) &&
+ pImplData->ClientType.nUpdateMode != nMode )
+ {
+ AddNextRef();
+ Disconnect();
+
+ pImplData->ClientType.nUpdateMode = nMode;
+ _GetRealObject();
+ ReleaseRef();
+ }
+}
+
+// --> OD 2008-06-19 #i88291#
+void SvBaseLink::clearStreamToLoadFrom()
+{
+ m_xInputStreamToLoadFrom.clear();
+ if( xObj.Is() )
+ {
+ xObj->clearStreamToLoadFrom();
+ }
+}
+// <--
+
+BOOL SvBaseLink::Update()
+{
+ if( OBJECT_CLIENT_SO & nObjType )
+ {
+ AddNextRef();
+ Disconnect();
+
+ _GetRealObject();
+ ReleaseRef();
+ if( xObj.Is() )
+ {
+ xObj->setStreamToLoadFrom(m_xInputStreamToLoadFrom,m_bIsReadOnly);
+ // m_xInputStreamToLoadFrom = 0;
+ String sMimeType( SotExchange::GetFormatMimeType(
+ pImplData->ClientType.nCntntType ));
+ Any aData;
+
+ if( xObj->GetData( aData, sMimeType ) )
+ {
+ DataChanged( sMimeType, aData );
+ //JP 13.07.00: Bug 76817 - for manual Updates there is no
+ // need to hold the ServerObject
+ if( OBJECT_CLIENT_DDE == nObjType &&
+ LINKUPDATE_ONCALL == GetUpdateMode() && xObj.Is() )
+ xObj->RemoveAllDataAdvise( this );
+ return TRUE;
+ }
+ if( xObj.Is() )
+ {
+ // sollten wir asynschron sein?
+ if( xObj->IsPending() )
+ return TRUE;
+
+ // dann brauchen wir das Object auch nicht mehr
+ AddNextRef();
+ Disconnect();
+ ReleaseRef();
+ }
+ }
+ }
+ return FALSE;
+}
+
+
+USHORT SvBaseLink::GetUpdateMode() const
+{
+ return ( OBJECT_CLIENT_SO & nObjType )
+ ? pImplData->ClientType.nUpdateMode
+ : sal::static_int_cast< USHORT >( LINKUPDATE_ONCALL );
+}
+
+
+void SvBaseLink::_GetRealObject( BOOL bConnect)
+{
+ if( !pImpl->m_pLinkMgr )
+ return;
+
+ DBG_ASSERT( !xObj.Is(), "object already exist" );
+
+ if( OBJECT_CLIENT_DDE == nObjType )
+ {
+ String sServer;
+ if( pImpl->m_pLinkMgr->GetDisplayNames( this, &sServer ) &&
+ sServer == GetpApp()->GetAppName() ) // interner Link !!!
+ {
+ // damit der Internal - Link erzeugt werden kann !!!
+ nObjType = OBJECT_INTERN;
+ xObj = pImpl->m_pLinkMgr->CreateObj( this );
+
+ pImplData->ClientType.bIntrnlLnk = TRUE;
+ nObjType = OBJECT_CLIENT_DDE; // damit wir wissen was es mal war !!
+ }
+ else
+ {
+ pImplData->ClientType.bIntrnlLnk = FALSE;
+ xObj = pImpl->m_pLinkMgr->CreateObj( this );
+ }
+ }
+ else if( (OBJECT_CLIENT_SO & nObjType) )
+ xObj = pImpl->m_pLinkMgr->CreateObj( this );
+
+ if( bConnect && ( !xObj.Is() || !xObj->Connect( this ) ) )
+ Disconnect();
+}
+
+ULONG SvBaseLink::GetContentType() const
+{
+ if( OBJECT_CLIENT_SO & nObjType )
+ return pImplData->ClientType.nCntntType;
+
+ return 0; // alle Formate ?
+}
+
+
+BOOL SvBaseLink::SetContentType( ULONG nType )
+{
+ if( OBJECT_CLIENT_SO & nObjType )
+ {
+ pImplData->ClientType.nCntntType = nType;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+LinkManager* SvBaseLink::GetLinkManager()
+{
+ return pImpl->m_pLinkMgr;
+}
+
+const LinkManager* SvBaseLink::GetLinkManager() const
+{
+ return pImpl->m_pLinkMgr;
+}
+
+void SvBaseLink::SetLinkManager( LinkManager* _pMgr )
+{
+ pImpl->m_pLinkMgr = _pMgr;
+}
+
+void SvBaseLink::Disconnect()
+{
+ if( xObj.Is() )
+ {
+ xObj->RemoveAllDataAdvise( this );
+ xObj->RemoveConnectAdvise( this );
+ xObj.Clear();
+ }
+}
+
+void SvBaseLink::DataChanged( const String &, const ::com::sun::star::uno::Any & )
+{
+ switch( nObjType )
+ {
+ case OBJECT_DDE_EXTERN:
+ if( pImplData->DDEType.pItem )
+ pImplData->DDEType.pItem->Notify();
+ break;
+ }
+}
+
+void SvBaseLink::Edit( Window* pParent, const Link& rEndEditHdl )
+{
+ pImpl->m_pParentWin = pParent;
+ pImpl->m_aEndEditLink = rEndEditHdl;
+ pImpl->m_bIsConnect = ( xObj.Is() != sal_False );
+ if( !pImpl->m_bIsConnect )
+ _GetRealObject( xObj.Is() );
+
+ bool bAsync = false;
+ Link aLink = LINK( this, SvBaseLink, EndEditHdl );
+
+ if( OBJECT_CLIENT_SO & nObjType && pImplData->ClientType.bIntrnlLnk )
+ {
+ if( pImpl->m_pLinkMgr )
+ {
+ SvLinkSourceRef ref = pImpl->m_pLinkMgr->CreateObj( this );
+ if( ref.Is() )
+ {
+ ref->Edit( pParent, this, aLink );
+ bAsync = true;
+ }
+ }
+ }
+ else
+ {
+ xObj->Edit( pParent, this, aLink );
+ bAsync = true;
+ }
+
+ if ( !bAsync )
+ {
+ ExecuteEdit( String() );
+ bWasLastEditOK = FALSE;
+ if ( pImpl->m_aEndEditLink.IsSet() )
+ pImpl->m_aEndEditLink.Call( this );
+ }
+}
+
+bool SvBaseLink::ExecuteEdit( const String& _rNewName )
+{
+ if( _rNewName.Len() != 0 )
+ {
+ SetLinkSourceName( _rNewName );
+ if( !Update() )
+ {
+ String sApp, sTopic, sItem, sError;
+ pImpl->m_pLinkMgr->GetDisplayNames( this, &sApp, &sTopic, &sItem );
+ if( nObjType == OBJECT_CLIENT_DDE )
+ {
+ sError = SfxResId( STR_DDE_ERROR );
+
+ USHORT nFndPos = sError.Search( '%' );
+ if( STRING_NOTFOUND != nFndPos )
+ {
+ sError.Erase( nFndPos, 1 ).Insert( sApp, nFndPos );
+ nFndPos = nFndPos + sApp.Len();
+ }
+ if( STRING_NOTFOUND != ( nFndPos = sError.Search( '%', nFndPos )))
+ {
+ sError.Erase( nFndPos, 1 ).Insert( sTopic, nFndPos );
+ nFndPos = nFndPos + sTopic.Len();
+ }
+ if( STRING_NOTFOUND != ( nFndPos = sError.Search( '%', nFndPos )))
+ sError.Erase( nFndPos, 1 ).Insert( sItem, nFndPos );
+ }
+ else
+ return false;
+
+ ErrorBox( pImpl->m_pParentWin, WB_OK, sError ).Execute();
+ }
+ }
+ else if( !pImpl->m_bIsConnect )
+ Disconnect();
+ pImpl->m_bIsConnect = false;
+ return true;
+}
+
+void SvBaseLink::Closed()
+{
+ if( xObj.Is() )
+ // beim Advise Abmelden
+ xObj->RemoveAllDataAdvise( this );
+}
+
+FileDialogHelper* SvBaseLink::GetFileDialog( sal_uInt32 nFlags, const String& rFactory ) const
+{
+ if ( pImpl->m_pFileDlg )
+ delete pImpl->m_pFileDlg;
+ pImpl->m_pFileDlg = new FileDialogHelper( nFlags, rFactory );
+ return pImpl->m_pFileDlg;
+}
+
+ImplDdeItem::~ImplDdeItem()
+{
+ bIsInDTOR = TRUE;
+ // damit im Disconnect nicht jemand auf die Idee kommt, den Pointer zu
+ // loeschen!!
+ SvBaseLinkRef aRef( pLink );
+ aRef->Disconnect();
+}
+
+DdeData* ImplDdeItem::Get( ULONG nFormat )
+{
+ if( pLink->GetObj() )
+ {
+ // ist das noch gueltig?
+ if( bIsValidData && nFormat == aData.GetFormat() )
+ return &aData;
+
+ Any aValue;
+ String sMimeType( SotExchange::GetFormatMimeType( nFormat ));
+ if( pLink->GetObj()->GetData( aValue, sMimeType ) )
+ {
+ if( aValue >>= aSeq )
+ {
+ aData = DdeData( (const char *)aSeq.getConstArray(), aSeq.getLength(), nFormat );
+
+ bIsValidData = TRUE;
+ return &aData;
+ }
+ }
+ }
+ aSeq.realloc( 0 );
+ bIsValidData = FALSE;
+ return 0;
+}
+
+
+BOOL ImplDdeItem::Put( const DdeData* )
+{
+ DBG_ERROR( "ImplDdeItem::Put not implemented" );
+ return FALSE;
+}
+
+
+void ImplDdeItem::AdviseLoop( BOOL bOpen )
+{
+ // Verbindung wird geschlossen, also Link abmelden
+ if( pLink->GetObj() )
+ {
+ if( bOpen )
+ {
+ // es wird wieder eine Verbindung hergestellt
+ if( OBJECT_DDE_EXTERN == pLink->GetObjType() )
+ {
+ pLink->GetObj()->AddDataAdvise( pLink, String::CreateFromAscii( "text/plain;charset=utf-16" ), ADVISEMODE_NODATA );
+ pLink->GetObj()->AddConnectAdvise( pLink );
+ }
+ }
+ else
+ {
+ // damit im Disconnect nicht jemand auf die Idee kommt,
+ // den Pointer zu loeschen!!
+ SvBaseLinkRef aRef( pLink );
+ aRef->Disconnect();
+ }
+ }
+}
+
+
+static DdeTopic* FindTopic( const String & rLinkName, USHORT* pItemStt )
+{
+ if( 0 == rLinkName.Len() )
+ return 0;
+
+ String sNm( rLinkName );
+ USHORT nTokenPos = 0;
+ String sService( sNm.GetToken( 0, cTokenSeperator, nTokenPos ) );
+
+ DdeServices& rSvc = DdeService::GetServices();
+ for( DdeService* pService = rSvc.First(); pService;
+ pService = rSvc.Next() )
+ if( pService->GetName() == sService )
+ {
+ // dann suchen wir uns das Topic
+ String sTopic( sNm.GetToken( 0, cTokenSeperator, nTokenPos ) );
+ if( pItemStt )
+ *pItemStt = nTokenPos;
+
+ DdeTopics& rTopics = pService->GetTopics();
+
+ for( int i = 0; i < 2; ++i )
+ {
+ for( DdeTopic* pTopic = rTopics.First(); pTopic;
+ pTopic = rTopics.Next() )
+ if( pTopic->GetName() == sTopic )
+ return pTopic;
+
+ // Topic nicht gefunden ?
+ // dann versuchen wir ihn mal anzulegen
+ if( i || !pService->MakeTopic( sTopic ) )
+ break; // hat nicht geklappt, also raus
+ }
+ break;
+ }
+ return 0;
+}
+
+}
diff --git a/sfx2/source/appl/module.cxx b/sfx2/source/appl/module.cxx
new file mode 100644
index 000000000000..ba91d9c1117b
--- /dev/null
+++ b/sfx2/source/appl/module.cxx
@@ -0,0 +1,450 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+
+#include <stdio.h>
+#include <tools/rcid.h>
+
+#include <cstdarg>
+#include <sfx2/module.hxx>
+#include <sfx2/app.hxx>
+#include "arrdecl.hxx"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/msgpool.hxx>
+#include <sfx2/tbxctrl.hxx>
+#include "sfx2/stbitem.hxx"
+#include <sfx2/mnuitem.hxx>
+#include <sfx2/childwin.hxx>
+#include <sfx2/mnumgr.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/objface.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <svl/intitem.hxx>
+#include "sfx2/taskpane.hxx"
+#include <tools/diagnose_ex.h>
+
+#define SfxModule
+#include "sfxslots.hxx"
+
+static SfxModuleArr_Impl* pModules=0;
+
+class SfxModule_Impl
+{
+public:
+
+ SfxSlotPool* pSlotPool;
+ SfxTbxCtrlFactArr_Impl* pTbxCtrlFac;
+ SfxStbCtrlFactArr_Impl* pStbCtrlFac;
+ SfxMenuCtrlFactArr_Impl* pMenuCtrlFac;
+ SfxChildWinFactArr_Impl* pFactArr;
+ ImageList* pImgListSmall;
+ ImageList* pImgListBig;
+ ImageList* pImgListHiSmall;
+ ImageList* pImgListHiBig;
+
+ SfxModule_Impl();
+ ~SfxModule_Impl();
+ ImageList* GetImageList( ResMgr*, BOOL, BOOL bHiContrast = FALSE );
+};
+
+SfxModule_Impl::SfxModule_Impl()
+ : pSlotPool(0)
+{
+}
+
+SfxModule_Impl::~SfxModule_Impl()
+{
+ delete pSlotPool;
+ delete pTbxCtrlFac;
+ delete pStbCtrlFac;
+ delete pMenuCtrlFac;
+ delete pFactArr;
+ delete pImgListSmall;
+ delete pImgListBig;
+ delete pImgListHiSmall;
+ delete pImgListHiBig;
+}
+
+ImageList* SfxModule_Impl::GetImageList( ResMgr* pResMgr, BOOL bBig, BOOL bHiContrast )
+{
+ ImageList*& rpList = bBig ? ( bHiContrast ? pImgListHiBig: pImgListBig ) :
+ ( bHiContrast ? pImgListHiSmall : pImgListSmall );
+ if ( !rpList )
+ {
+ ResId aResId( bBig ? ( bHiContrast ? RID_DEFAULTIMAGELIST_LCH : RID_DEFAULTIMAGELIST_LC ) :
+ ( bHiContrast ? RID_DEFAULTIMAGELIST_SCH : RID_DEFAULTIMAGELIST_SC ), *pResMgr );
+ aResId.SetRT( RSC_IMAGELIST );
+
+ DBG_ASSERT( pResMgr->IsAvailable(aResId), "No default ImageList!" );
+
+ if ( pResMgr->IsAvailable(aResId) )
+ rpList = new ImageList( aResId );
+ else
+ rpList = new ImageList();
+ }
+
+ return rpList; }
+
+TYPEINIT1(SfxModule, SfxShell);
+
+//=========================================================================
+
+SFX_IMPL_INTERFACE(SfxModule,SfxShell,SfxResId(0))
+{
+}
+
+//====================================================================
+
+ResMgr* SfxModule::GetResMgr()
+{
+ return pResMgr;
+}
+
+//====================================================================
+/*
+SfxModule::SfxModule( ResMgr* pMgrP, BOOL bDummyP,
+ SfxObjectFactory* pFactoryP )
+ : pResMgr( pMgrP ), bDummy( bDummyP ), pImpl(0L)
+{
+ Construct_Impl();
+ if ( pFactoryP )
+ pFactoryP->SetModule_Impl( this );
+}
+*/
+SfxModule::SfxModule( ResMgr* pMgrP, BOOL bDummyP,
+ SfxObjectFactory* pFactoryP, ... )
+ : pResMgr( pMgrP ), bDummy( bDummyP ), pImpl(0L)
+{
+ Construct_Impl();
+ va_list pVarArgs;
+ va_start( pVarArgs, pFactoryP );
+ for ( SfxObjectFactory *pArg = pFactoryP; pArg;
+ pArg = va_arg( pVarArgs, SfxObjectFactory* ) )
+ pArg->SetModule_Impl( this );
+ va_end(pVarArgs);
+}
+
+void SfxModule::Construct_Impl()
+{
+ if( !bDummy )
+ {
+ SfxApplication *pApp = SFX_APP();
+ SfxModuleArr_Impl& rArr = GetModules_Impl();
+ SfxModule* pPtr = (SfxModule*)this;
+ rArr.C40_INSERT( SfxModule, pPtr, rArr.Count() );
+ pImpl = new SfxModule_Impl;
+ pImpl->pSlotPool = new SfxSlotPool( &pApp->GetAppSlotPool_Impl(), pResMgr );
+
+ pImpl->pTbxCtrlFac=0;
+ pImpl->pStbCtrlFac=0;
+ pImpl->pMenuCtrlFac=0;
+ pImpl->pFactArr=0;
+ pImpl->pImgListSmall=0;
+ pImpl->pImgListBig=0;
+ pImpl->pImgListHiSmall=0;
+ pImpl->pImgListHiBig=0;
+
+ SetPool( &pApp->GetPool() );
+ }
+}
+
+//====================================================================
+
+SfxModule::~SfxModule()
+{
+ if( !bDummy )
+ {
+ if ( SFX_APP()->Get_Impl() )
+ {
+ // Das Modul wird noch vor dem DeInitialize zerst"ort, also auis dem Array entfernen
+ SfxModuleArr_Impl& rArr = GetModules_Impl();
+ for( USHORT nPos = rArr.Count(); nPos--; )
+ {
+ if( rArr[ nPos ] == this )
+ {
+ rArr.Remove( nPos );
+ break;
+ }
+ }
+
+ delete pImpl;
+ }
+
+ delete pResMgr;
+ }
+}
+
+//-------------------------------------------------------------------------
+
+SfxSlotPool* SfxModule::GetSlotPool() const
+{
+ return pImpl->pSlotPool;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxModule::RegisterChildWindow(SfxChildWinFactory *pFact)
+{
+ DBG_ASSERT( pImpl, "Kein echtes Modul!" );
+
+ if (!pImpl->pFactArr)
+ pImpl->pFactArr = new SfxChildWinFactArr_Impl;
+
+//#ifdef DBG_UTIL
+ for (USHORT nFactory=0; nFactory<pImpl->pFactArr->Count(); ++nFactory)
+ {
+ if (pFact->nId == (*pImpl->pFactArr)[nFactory]->nId)
+ {
+ pImpl->pFactArr->Remove( nFactory );
+ DBG_ERROR("ChildWindow mehrfach registriert!");
+ return;
+ }
+ }
+//#endif
+
+ pImpl->pFactArr->C40_INSERT(
+ SfxChildWinFactory, pFact, pImpl->pFactArr->Count() );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxModule::RegisterChildWindowContext( USHORT nId,
+ SfxChildWinContextFactory *pFact)
+{
+ DBG_ASSERT( pImpl, "Kein echtes Modul!" );
+
+ USHORT nCount = pImpl->pFactArr->Count();
+ for (USHORT nFactory=0; nFactory<nCount; ++nFactory)
+ {
+ SfxChildWinFactory *pF = (*pImpl->pFactArr)[nFactory];
+ if ( nId == pF->nId )
+ {
+ if ( !pF->pArr )
+ pF->pArr = new SfxChildWinContextArr_Impl;
+ pF->pArr->C40_INSERT( SfxChildWinContextFactory, pFact, pF->pArr->Count() );
+ return;
+ }
+ }
+
+ DBG_ERROR( "Kein ChildWindow fuer diesen Context!" );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxModule::RegisterToolBoxControl( SfxTbxCtrlFactory *pFact )
+{
+ if (!pImpl->pTbxCtrlFac)
+ pImpl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
+
+#ifdef DBG_UTIL
+ for ( USHORT n=0; n<pImpl->pTbxCtrlFac->Count(); n++ )
+ {
+ SfxTbxCtrlFactory *pF = (*pImpl->pTbxCtrlFac)[n];
+ if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
+ (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
+ {
+ DBG_WARNING("TbxController-Registrierung ist nicht eindeutig!");
+ }
+ }
+#endif
+
+ pImpl->pTbxCtrlFac->C40_INSERT( SfxTbxCtrlFactory, pFact, pImpl->pTbxCtrlFac->Count() );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxModule::RegisterStatusBarControl( SfxStbCtrlFactory *pFact )
+{
+ if (!pImpl->pStbCtrlFac)
+ pImpl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
+
+#ifdef DBG_UTIL
+ for ( USHORT n=0; n<pImpl->pStbCtrlFac->Count(); n++ )
+ {
+ SfxStbCtrlFactory *pF = (*pImpl->pStbCtrlFac)[n];
+ if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
+ (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
+ {
+ DBG_WARNING("StbController-Registrierung ist nicht eindeutig!");
+ }
+ }
+#endif
+
+ pImpl->pStbCtrlFac->C40_INSERT( SfxStbCtrlFactory, pFact, pImpl->pStbCtrlFac->Count() );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxModule::RegisterMenuControl( SfxMenuCtrlFactory *pFact )
+{
+ if (!pImpl->pMenuCtrlFac)
+ pImpl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
+
+#ifdef DBG_UTIL
+ for ( USHORT n=0; n<pImpl->pMenuCtrlFac->Count(); n++ )
+ {
+ SfxMenuCtrlFactory *pF = (*pImpl->pMenuCtrlFac)[n];
+ if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
+ (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
+ {
+ DBG_WARNING("MenuController-Registrierung ist nicht eindeutig!");
+ }
+ }
+#endif
+
+ pImpl->pMenuCtrlFac->C40_INSERT( SfxMenuCtrlFactory, pFact, pImpl->pMenuCtrlFac->Count() );
+}
+
+//-------------------------------------------------------------------------
+
+SfxTbxCtrlFactArr_Impl* SfxModule::GetTbxCtrlFactories_Impl() const
+{
+ return pImpl->pTbxCtrlFac;
+}
+
+//-------------------------------------------------------------------------
+
+SfxStbCtrlFactArr_Impl* SfxModule::GetStbCtrlFactories_Impl() const
+{
+ return pImpl->pStbCtrlFac;
+}
+
+//-------------------------------------------------------------------------
+
+SfxMenuCtrlFactArr_Impl* SfxModule::GetMenuCtrlFactories_Impl() const
+{
+ return pImpl->pMenuCtrlFac;
+}
+
+//-------------------------------------------------------------------------
+
+SfxChildWinFactArr_Impl* SfxModule::GetChildWinFactories_Impl() const
+{
+ return pImpl->pFactArr;
+}
+
+ImageList* SfxModule::GetImageList_Impl( BOOL bBig )
+{
+ return pImpl->GetImageList( pResMgr, bBig, FALSE );
+}
+
+ImageList* SfxModule::GetImageList_Impl( BOOL bBig, BOOL bHiContrast )
+{
+ return pImpl->GetImageList( pResMgr, bBig, bHiContrast );
+}
+
+SfxTabPage* SfxModule::CreateTabPage( USHORT, Window*, const SfxItemSet& )
+{
+ return NULL;
+}
+
+SfxModuleArr_Impl& SfxModule::GetModules_Impl()
+{
+ if( !pModules )
+ pModules = new SfxModuleArr_Impl;
+ return *pModules;
+};
+
+void SfxModule::DestroyModules_Impl()
+{
+ if ( pModules )
+ {
+ SfxModuleArr_Impl& rModules = *pModules;
+ for( USHORT nPos = rModules.Count(); nPos--; )
+ {
+ SfxModule* pMod = rModules.GetObject(nPos);
+ delete pMod;
+ }
+ }
+}
+
+void SfxModule::Invalidate( USHORT nId )
+{
+ for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame ) )
+ if ( pFrame->GetObjectShell()->GetModule() == this )
+ Invalidate_Impl( pFrame->GetBindings(), nId );
+}
+
+BOOL SfxModule::IsActive() const
+{
+ SfxViewFrame* pFrame = SfxViewFrame::Current();
+ if ( pFrame && pFrame->GetObjectShell()->GetFactory().GetModule() == this )
+ return TRUE;
+ return FALSE;
+}
+
+bool SfxModule::IsChildWindowAvailable( const USHORT i_nId, const SfxViewFrame* i_pViewFrame ) const
+{
+ if ( i_nId != SID_TASKPANE )
+ // by default, assume it is
+ return true;
+
+ const SfxViewFrame* pViewFrame = i_pViewFrame ? i_pViewFrame : GetFrame();
+ ENSURE_OR_RETURN( pViewFrame, "SfxModule::IsChildWindowAvailable: no frame to ask for the module identifier!", false );
+ return ::sfx2::ModuleTaskPane::ModuleHasToolPanels( pViewFrame->GetFrame().GetFrameInterface() );
+}
+
+SfxModule* SfxModule::GetActiveModule( SfxViewFrame* pFrame )
+{
+ if ( !pFrame )
+ pFrame = SfxViewFrame::Current();
+ SfxObjectShell* pSh = 0;
+ if( pFrame )
+ pSh = pFrame->GetObjectShell();
+ return pSh ? pSh->GetModule() : 0;
+}
+
+FieldUnit SfxModule::GetCurrentFieldUnit()
+{
+ FieldUnit eUnit = FUNIT_INCH;
+ SfxModule* pModule = GetActiveModule();
+ if ( pModule )
+ {
+ const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
+ DBG_ASSERT( pItem, "GetFieldUnit(): no item" );
+ if ( pItem )
+ eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
+ }
+ else
+ DBG_ERRORFILE( "GetModuleFieldUnit(): no module found" );
+ return eUnit;
+}
+
+FieldUnit SfxModule::GetFieldUnit() const
+{
+ FieldUnit eUnit = FUNIT_INCH;
+ const SfxPoolItem* pItem = GetItem( SID_ATTR_METRIC );
+ DBG_ASSERT( pItem, "GetFieldUnit(): no item" );
+ if ( pItem )
+ eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
+ return eUnit;
+}
diff --git a/sfx2/source/appl/newhelp.cxx b/sfx2/source/appl/newhelp.cxx
new file mode 100644
index 000000000000..96f4c6b91f5b
--- /dev/null
+++ b/sfx2/source/appl/newhelp.cxx
@@ -0,0 +1,3492 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "newhelp.hxx"
+#include <sfx2/sfxuno.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "helpinterceptor.hxx"
+#include "helper.hxx"
+#include <sfx2/msgpool.hxx>
+#include <sfx2/app.hxx>
+#include "sfxtypes.hxx"
+#include "panelist.hxx"
+#include "sfx2/imgmgr.hxx"
+#include "srchdlg.hxx"
+#include "sfx2/sfxhelp.hxx"
+
+#include "app.hrc"
+#include "newhelp.hrc"
+#include "helpid.hrc"
+
+#include <hash_map>
+#include <rtl/ustrbuf.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/configurationhelper.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/util/CloseVetoException.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/awt/PosSize.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/beans/Property.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/container/XIndexAccess.hpp>
+#include <com/sun/star/frame/XTitle.hpp>
+#include <com/sun/star/frame/XLayoutManager.hpp>
+#include <com/sun/star/frame/DispatchResultState.hpp>
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#ifndef _COM_SUN_STAR_TEXT_XBREAKITERATOR_HPP_
+#include <com/sun/star/i18n/XBreakIterator.hpp>
+#endif
+#include <com/sun/star/i18n/WordType.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/style/XStyle.hpp>
+#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
+#include <com/sun/star/text/XText.hpp>
+#include <com/sun/star/text/XTextCursor.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/XTextRange.hpp>
+#include <com/sun/star/text/XTextViewCursor.hpp>
+#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
+#include <com/sun/star/ucb/CommandAbortedException.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/util/XSearchable.hpp>
+#include <com/sun/star/util/XSearchDescriptor.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/view/XSelectionSupplier.hpp>
+#include <com/sun/star/view/XViewSettingsSupplier.hpp>
+#include <com/sun/star/ui/XDockingAreaAcceptor.hpp>
+#include <svtools/helpopt.hxx>
+#include <unotools/historyoptions.hxx>
+#include <svtools/menuoptions.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/viewoptions.hxx>
+#include <svtools/svtdata.hxx>
+#include <tools/urlobj.hxx>
+#include <tools/cachestr.hxx>
+#include <unotools/streamhelper.hxx>
+#include <svtools/imagemgr.hxx>
+#include <svtools/miscopt.hxx>
+#include <svtools/imgdef.hxx>
+#include <vcl/unohelp.hxx>
+#include <vcl/i18nhelp.hxx>
+
+#include <ucbhelper/content.hxx>
+#include <vcl/msgbox.hxx>
+#include <vcl/waitobj.hxx>
+#include <unotools/ucbhelper.hxx>
+
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/docfac.hxx>
+
+using namespace ::ucbhelper;
+using namespace ::com::sun::star::ucb;
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::i18n;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::style;
+using namespace ::com::sun::star::text;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::view;
+using namespace ::com::sun::star::ui;
+
+using namespace ::comphelper;
+
+extern void AppendConfigToken_Impl( String& rURL, sal_Bool bQuestionMark ); // sfxhelp.cxx
+
+// defines ---------------------------------------------------------------
+
+#define SPLITSET_ID 0
+#define COLSET_ID 1
+#define INDEXWIN_ID 2
+#define TEXTWIN_ID 3
+
+#define TOOLBOX_OFFSET 3
+
+#define TBI_INDEX 1001
+#define TBI_BACKWARD 1002
+#define TBI_FORWARD 1003
+#define TBI_START 1004
+#define TBI_PRINT 1005
+#define TBI_COPY 1006
+#define TBI_BOOKMARKS 1007
+#define TBI_SEARCHDIALOG 1008
+#define TBI_SOURCEVIEW 1009
+#define TBI_SELECTIONMODE 1010
+#define TBI_ONSTARTUP 1011
+
+#define CONFIGNAME_HELPWIN DEFINE_CONST_UNICODE("OfficeHelp")
+#define CONFIGNAME_INDEXWIN DEFINE_CONST_UNICODE("OfficeHelpIndex")
+#define CONFIGNAME_SEARCHPAGE DEFINE_CONST_UNICODE("OfficeHelpSearch")
+#define IMAGE_URL DEFINE_CONST_UNICODE("private:factory/")
+
+#define PROPERTY_KEYWORDLIST DEFINE_CONST_OUSTRING("KeywordList")
+#define PROPERTY_KEYWORDREF DEFINE_CONST_OUSTRING("KeywordRef")
+#define PROPERTY_ANCHORREF DEFINE_CONST_OUSTRING("KeywordAnchorForRef")
+#define PROPERTY_TITLEREF DEFINE_CONST_OUSTRING("KeywordTitleForRef")
+#define PROPERTY_TITLE DEFINE_CONST_OUSTRING("Title")
+#define HELP_URL DEFINE_CONST_OUSTRING("vnd.sun.star.help://")
+#define HELP_SEARCH_TAG DEFINE_CONST_OUSTRING("/?Query=")
+#define USERITEM_NAME DEFINE_CONST_OUSTRING("UserItem")
+
+#define PACKAGE_SETUP DEFINE_CONST_OUSTRING("/org.openoffice.Setup")
+#define PATH_OFFICE_FACTORIES DEFINE_CONST_OUSTRING("Office/Factories/")
+#define KEY_HELP_ON_OPEN DEFINE_CONST_OUSTRING("ooSetupFactoryHelpOnOpen")
+#define KEY_UI_NAME DEFINE_CONST_OUSTRING("ooSetupFactoryUIName")
+
+#define PARSE_URL( aURL ) \
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( \
+ DEFINE_CONST_UNICODE("com.sun.star.util.URLTransformer" )), UNO_QUERY ); \
+ xTrans->parseStrict( aURL )
+
+//.........................................................................
+namespace sfx2
+{
+//.........................................................................
+
+ void HandleTaskPaneList( Window* pWindow, BOOL bAddToList )
+ {
+ Window* pParent = pWindow->GetParent();
+ DBG_ASSERT( pParent, "HandleTaskPaneList(): every window here should have a parent" );
+
+ SystemWindow* pSysWin = pParent->GetSystemWindow();
+ if( pSysWin )
+ {
+ TaskPaneList* pTaskPaneList = pSysWin->GetTaskPaneList();
+ if( pTaskPaneList )
+ {
+ if( bAddToList )
+ pTaskPaneList->AddWindow( pWindow );
+ else
+ pTaskPaneList->RemoveWindow( pWindow );
+ }
+ }
+ }
+
+ /** Prepare a search string for searching or selecting.
+ For searching every search word needs the postfix '*' and the delimiter ' ' if necessary.
+ For selecting the delimiter '|' is required to search with regular expressions.
+ Samples:
+ search string | output for searching | output for selecting
+ -----------------------------------------------------------
+ "text" | "text*" | "text"
+ "text*" | "text*" | "text"
+ "text menu" | "text* menu*" | "text|menu"
+ */
+ String PrepareSearchString( const String& rSearchString,
+ Reference< XBreakIterator > xBreak, bool bForSearch )
+ {
+ String sSearchStr;
+ sal_Int32 nStartPos = 0;
+ const Locale aLocale = Application::GetSettings().GetUILocale();
+ Boundary aBoundary = xBreak->getWordBoundary(
+ rSearchString, nStartPos, aLocale, WordType::ANYWORD_IGNOREWHITESPACES, sal_True );
+
+ while ( aBoundary.startPos != aBoundary.endPos )
+ {
+ nStartPos = aBoundary.endPos;
+ String sSearchToken( rSearchString.Copy(
+ (USHORT)aBoundary.startPos, (USHORT)aBoundary.endPos - (USHORT)aBoundary.startPos ) );
+ if ( sSearchToken.Len() > 0 && ( sSearchToken.Len() > 1 || sSearchToken.GetChar(0) != '.' ) )
+ {
+ if ( bForSearch && sSearchToken.GetChar( sSearchToken.Len() - 1 ) != '*' )
+ sSearchToken += '*';
+
+ if ( sSearchToken.Len() > 1 ||
+ ( sSearchToken.Len() > 0 && sSearchToken.GetChar( 0 ) != '*' ) )
+ {
+ if ( sSearchStr.Len() > 0 )
+ {
+ if ( bForSearch )
+ sSearchStr += ' ';
+ else
+ sSearchStr += '|';
+ }
+ sSearchStr += sSearchToken;
+ }
+ }
+ aBoundary = xBreak->nextWord( rSearchString, nStartPos,
+ aLocale, WordType::ANYWORD_IGNOREWHITESPACES );
+ }
+
+ return sSearchStr;
+ }
+//.........................................................................
+// namespace sfx2
+}
+//.........................................................................
+
+// struct IndexEntry_Impl ------------------------------------------------
+
+struct IndexEntry_Impl
+{
+ sal_Bool m_bSubEntry;
+ String m_aURL;
+
+ IndexEntry_Impl( const String& rURL, sal_Bool bSubEntry ) :
+ m_bSubEntry( bSubEntry ), m_aURL( rURL ) {}
+};
+
+#define NEW_ENTRY( url, bool ) \
+ (void*)(ULONG)( new IndexEntry_Impl( url, bool ) )
+
+// struct ContentEntry_Impl ----------------------------------------------
+
+struct ContentEntry_Impl
+{
+ String aURL;
+ sal_Bool bIsFolder;
+
+ ContentEntry_Impl( const String& rURL, sal_Bool bFolder ) :
+ aURL( rURL ), bIsFolder( bFolder ) {}
+};
+
+// ContentListBox_Impl ---------------------------------------------------
+
+ContentListBox_Impl::ContentListBox_Impl( Window* pParent, const ResId& rResId ) :
+
+ SvTreeListBox( pParent, rResId ),
+
+ aOpenBookImage ( SfxResId( IMG_HELP_CONTENT_BOOK_OPEN ) ),
+ aClosedBookImage ( SfxResId( IMG_HELP_CONTENT_BOOK_CLOSED ) ),
+ aDocumentImage ( SfxResId( IMG_HELP_CONTENT_DOC ) )
+
+{
+ if ( GetSettings().GetStyleSettings().GetHighContrastMode() )
+ {
+ aOpenBookImage = Image( SfxResId( IMG_HELP_CONTENT_BOOK_OPEN_HC ) );
+ aClosedBookImage = Image( SfxResId( IMG_HELP_CONTENT_BOOK_CLOSED_HC ) );
+ aDocumentImage = Image( SfxResId( IMG_HELP_CONTENT_DOC_HC ) );
+ }
+
+ SetStyle( GetStyle() | WB_HIDESELECTION | WB_HSCROLL );
+
+ SetEntryHeight( 16 );
+ SetSelectionMode( SINGLE_SELECTION );
+ SetSpaceBetweenEntries( 2 );
+ SetNodeBitmaps( aClosedBookImage, aOpenBookImage );
+
+ SetSublistOpenWithReturn();
+ SetSublistOpenWithLeftRight();
+
+ InitRoot();
+}
+
+// -----------------------------------------------------------------------
+
+ContentListBox_Impl::~ContentListBox_Impl()
+{
+ USHORT nPos = 0;
+ SvLBoxEntry* pEntry = GetEntry( nPos++ );
+ while ( pEntry )
+ {
+ ::rtl::OUString aTemp( GetEntryText( pEntry ) );
+ ClearChildren( pEntry );
+ delete (ContentEntry_Impl*)pEntry->GetUserData();
+ pEntry = GetEntry( nPos++ );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void ContentListBox_Impl::InitRoot()
+{
+ String aHelpTreeviewURL( DEFINE_CONST_UNICODE("vnd.sun.star.hier://com.sun.star.help.TreeView/") );
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > aList =
+ SfxContentHelper::GetHelpTreeViewContents( aHelpTreeviewURL );
+
+ const ::rtl::OUString* pEntries = aList.getConstArray();
+ UINT32 i, nCount = aList.getLength();
+ for ( i = 0; i < nCount; ++i )
+ {
+ String aRow( pEntries[i] );
+ String aTitle, aURL;
+ xub_StrLen nIdx = 0;
+ aTitle = aRow.GetToken( 0, '\t', nIdx );
+ aURL = aRow.GetToken( 0, '\t', nIdx );
+ sal_Unicode cFolder = aRow.GetToken( 0, '\t', nIdx ).GetChar(0);
+ sal_Bool bIsFolder = ( '1' == cFolder );
+ SvLBoxEntry* pEntry = InsertEntry( aTitle, aOpenBookImage, aClosedBookImage, NULL, TRUE );
+ if ( bIsFolder )
+ pEntry->SetUserData( new ContentEntry_Impl( aURL, sal_True ) );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void ContentListBox_Impl::ClearChildren( SvLBoxEntry* pParent )
+{
+ SvLBoxEntry* pEntry = FirstChild( pParent );
+ while ( pEntry )
+ {
+ ::rtl::OUString aTemp( GetEntryText( pEntry ) );
+ ClearChildren( pEntry );
+ delete (ContentEntry_Impl*)pEntry->GetUserData();
+ pEntry = NextSibling( pEntry );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void ContentListBox_Impl::RequestingChilds( SvLBoxEntry* pParent )
+{
+ try
+ {
+ if ( !pParent->HasChilds() )
+ {
+ if ( pParent->GetUserData() )
+ {
+ String aTmpURL( ( (ContentEntry_Impl*)pParent->GetUserData() )->aURL );
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > aList =
+ SfxContentHelper::GetHelpTreeViewContents( aTmpURL );
+
+ const ::rtl::OUString* pEntries = aList.getConstArray();
+ UINT32 i, nCount = aList.getLength();
+ for ( i = 0; i < nCount; ++i )
+ {
+ String aRow( pEntries[i] );
+ String aTitle, aURL;
+ xub_StrLen nIdx = 0;
+ aTitle = aRow.GetToken( 0, '\t', nIdx );
+ aURL = aRow.GetToken( 0, '\t', nIdx );
+ sal_Unicode cFolder = aRow.GetToken( 0, '\t', nIdx ).GetChar(0);
+ sal_Bool bIsFolder = ( '1' == cFolder );
+ SvLBoxEntry* pEntry = NULL;
+ if ( bIsFolder )
+ {
+ pEntry = InsertEntry( aTitle, aOpenBookImage, aClosedBookImage, pParent, TRUE );
+ pEntry->SetUserData( new ContentEntry_Impl( aURL, sal_True ) );
+ }
+ else
+ {
+ pEntry = InsertEntry( aTitle, aDocumentImage, aDocumentImage, pParent );
+ Any aAny( ::utl::UCBContentHelper::GetProperty( aURL, String(RTL_CONSTASCII_USTRINGPARAM("TargetURL" ) ) ) );
+ rtl::OUString aTargetURL;
+ if ( aAny >>= aTargetURL )
+ pEntry->SetUserData( new ContentEntry_Impl( aTargetURL, sal_False ) );
+ }
+ }
+ }
+ }
+ }
+ catch( Exception& )
+ {
+ DBG_ERROR( "ContentListBox_Impl::RequestingChilds(): unexpected exception" );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+long ContentListBox_Impl::Notify( NotifyEvent& rNEvt )
+{
+ sal_Bool bHandled = sal_False;
+ if ( rNEvt.GetType() == EVENT_KEYINPUT &&
+ KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
+ {
+ GetDoubleClickHdl().Call( NULL );
+ bHandled = sal_True;
+ }
+
+ return bHandled ? 1 : SvTreeListBox::Notify( rNEvt );
+}
+
+// -----------------------------------------------------------------------
+
+String ContentListBox_Impl::GetSelectEntry() const
+{
+ String aRet;
+ SvLBoxEntry* pEntry = FirstSelected();
+ if ( pEntry && !( (ContentEntry_Impl*)pEntry->GetUserData() )->bIsFolder )
+ aRet = ( (ContentEntry_Impl*)pEntry->GetUserData() )->aURL;
+ return aRet;
+}
+
+// class HelpTabPage_Impl ------------------------------------------------
+
+HelpTabPage_Impl::HelpTabPage_Impl(
+ Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin, const ResId& rResId ) :
+
+ TabPage( pParent, rResId ),
+
+ m_pIdxWin( _pIdxWin )
+
+{
+}
+
+// class ContentTabPage_Impl ---------------------------------------------
+
+ContentTabPage_Impl::ContentTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
+
+ HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_CONTENT ) ),
+
+ aContentBox( this, SfxResId( LB_CONTENTS ) )
+
+{
+ FreeResource();
+
+ aContentBox.Show();
+}
+
+// -----------------------------------------------------------------------
+
+void ContentTabPage_Impl::Resize()
+{
+ Size aSize = GetOutputSizePixel();
+ aSize.Width() -= 8;
+ aSize.Height() -= 8;
+ aContentBox.SetPosSizePixel( Point( 4, 4 ), aSize );
+}
+
+// -----------------------------------------------------------------------
+
+void ContentTabPage_Impl::ActivatePage()
+{
+ if ( !m_pIdxWin->WasCursorLeftOrRight() )
+ SetFocusOnBox();
+}
+
+// -----------------------------------------------------------------------
+
+Control* ContentTabPage_Impl::GetLastFocusControl()
+{
+ return &aContentBox;
+}
+
+// class IndexBox_Impl ---------------------------------------------------
+
+IndexBox_Impl::IndexBox_Impl( Window* pParent, const ResId& rResId ) :
+
+ ComboBox( pParent, rResId )
+
+{
+ EnableAutocomplete( TRUE );
+ EnableUserDraw( TRUE );
+}
+
+// -----------------------------------------------------------------------
+
+void IndexBox_Impl::UserDraw( const UserDrawEvent& rUDEvt )
+{
+ IndexEntry_Impl* pEntry = (IndexEntry_Impl*)(ULONG)GetEntryData( rUDEvt.GetItemId() );
+ if ( pEntry && pEntry->m_bSubEntry )
+ {
+ // indent sub entries
+ Point aPos( rUDEvt.GetRect().TopLeft() );
+ aPos.X() += 8;
+ aPos.Y() += ( rUDEvt.GetRect().GetHeight() - rUDEvt.GetDevice()->GetTextHeight() ) / 2;
+ String aEntry( GetEntry( rUDEvt.GetItemId() ) );
+ USHORT nPos = aEntry.Search( ';' );
+ rUDEvt.GetDevice()->DrawText( aPos, ( nPos != STRING_NOTFOUND ) ? aEntry.Copy( nPos + 1 ) : aEntry );
+ }
+ else
+ DrawEntry( rUDEvt, FALSE, TRUE, TRUE );
+}
+
+// -----------------------------------------------------------------------
+
+long IndexBox_Impl::Notify( NotifyEvent& rNEvt )
+{
+ sal_Bool bHandled = sal_False;
+ if ( rNEvt.GetType() == EVENT_KEYINPUT &&
+ KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
+ {
+ GetDoubleClickHdl().Call( NULL );
+ bHandled = sal_True;
+ }
+
+ return bHandled ? 1 : ComboBox::Notify( rNEvt );
+}
+
+// -----------------------------------------------------------------------
+
+void IndexBox_Impl::SelectExecutableEntry()
+{
+ USHORT nPos = GetEntryPos( GetText() );
+ if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
+ {
+ USHORT nOldPos = nPos;
+ String aEntryText;
+ IndexEntry_Impl* pEntry = (IndexEntry_Impl*)(ULONG)GetEntryData( nPos );
+ USHORT nCount = GetEntryCount();
+ while ( nPos < nCount && ( !pEntry || pEntry->m_aURL.Len() == 0 ) )
+ {
+ pEntry = (IndexEntry_Impl*)(ULONG)GetEntryData( ++nPos );
+ aEntryText = GetEntry( nPos );
+ }
+
+ if ( nOldPos != nPos )
+ SetText( aEntryText );
+ }
+}
+
+// class IndexTabPage_Impl -----------------------------------------------
+
+IndexTabPage_Impl::IndexTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
+
+ HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_INDEX ) ),
+
+ aExpressionFT ( this, SfxResId( FT_EXPRESSION ) ),
+ aIndexCB ( this, SfxResId( CB_INDEX ) ),
+ aOpenBtn ( this, SfxResId( PB_OPEN_INDEX ) ),
+
+ bIsActivated ( sal_False )
+
+{
+ FreeResource();
+
+ aOpenBtn.SetClickHdl( LINK( this, IndexTabPage_Impl, OpenHdl ) );
+ Link aTimeoutLink = LINK( this, IndexTabPage_Impl, TimeoutHdl );
+ aFactoryTimer.SetTimeoutHdl( aTimeoutLink );
+ aFactoryTimer.SetTimeout( 300 );
+ aKeywordTimer.SetTimeoutHdl( aTimeoutLink );
+ aFactoryTimer.SetTimeout( 300 );
+
+ nMinWidth = aOpenBtn.GetSizePixel().Width();
+}
+
+// -----------------------------------------------------------------------
+
+IndexTabPage_Impl::~IndexTabPage_Impl()
+{
+ ClearIndex();
+}
+
+// -----------------------------------------------------------------------
+
+namespace sfx2 {
+
+ struct equalOUString
+ {
+ bool operator()( const ::rtl::OUString& rKey1, const ::rtl::OUString& rKey2 ) const
+ {
+ return !!( rKey1 == rKey2 );
+ }
+ };
+
+
+ struct hashOUString
+ {
+ size_t operator()( const ::rtl::OUString& rName ) const
+ {
+ return rName.hashCode();
+ }
+ };
+
+ typedef ::std::hash_map< ::rtl::OUString, int, hashOUString, equalOUString > KeywordInfo;
+}
+
+#define UNIFY_AND_INSERT_TOKEN( aToken ) \
+ it = \
+ aInfo.insert( sfx2::KeywordInfo::value_type( aToken, 0 ) ).first; \
+ if ( ( tmp = it->second++ ) != 0 ) \
+ nPos = aIndexCB.InsertEntry( aToken + rtl::OUString( append, tmp ) ); \
+ else \
+ nPos = aIndexCB.InsertEntry( aToken )
+
+#define INSERT_DATA( j ) \
+ if ( aAnchorList[j].getLength() > 0 ) \
+ { \
+ aData.append( aRefList[j] ).append( sal_Unicode('#') ).append( aAnchorList[j] ); \
+ aIndexCB.SetEntryData( nPos, NEW_ENTRY( aData.makeStringAndClear(), insert ) ); \
+ } \
+ else \
+ aIndexCB.SetEntryData( nPos, NEW_ENTRY( aRefList[j], insert ) );
+
+// -----------------------------------------------------------------------
+
+void IndexTabPage_Impl::InitializeIndex()
+{
+ WaitObject( this );
+
+ // By now more than 256 equal entries are not allowed
+ sal_Unicode append[256];
+ for( int k = 0; k < 256; ++k )
+ append[k] = sal_Unicode( ' ' );
+
+ sfx2::KeywordInfo aInfo;
+ aIndexCB.SetUpdateMode( FALSE );
+
+ try
+ {
+ ::rtl::OUString aURL = HELP_URL;
+ aURL += ::rtl::OUString( sFactory );
+
+ String aTemp = aURL;
+ AppendConfigToken_Impl( aTemp, sal_True );
+ aURL = aTemp;
+
+ Content aCnt( aURL, Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
+ ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = aCnt.getProperties();
+ if ( xInfo->hasPropertyByName( PROPERTY_ANCHORREF ) )
+ {
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > aPropSeq( 4 );
+ aPropSeq[0] = PROPERTY_KEYWORDLIST;
+ aPropSeq[1] = PROPERTY_KEYWORDREF;
+ aPropSeq[2] = PROPERTY_ANCHORREF;
+ aPropSeq[3] = PROPERTY_TITLEREF;
+
+ // abi: use one possibly remote call only
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aAnySeq =
+ aCnt.getPropertyValues( aPropSeq );
+
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > aKeywordList;
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > aKeywordRefList;
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > aAnchorRefList;
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > aTitleRefList;
+
+ if ( ( aAnySeq[0] >>= aKeywordList ) && ( aAnySeq[1] >>= aKeywordRefList ) &&
+ ( aAnySeq[2] >>= aAnchorRefList ) && ( aAnySeq[3] >>= aTitleRefList ) )
+ {
+ sal_Bool insert;
+ USHORT nPos;
+ int ndx,tmp;
+ ::rtl::OUString aIndex, aTempString;
+ ::rtl::OUStringBuffer aData( 128 ); // Capacity of up to 128 characters
+ sfx2::KeywordInfo::iterator it;
+
+ for ( int i = 0; i < aKeywordList.getLength(); ++i )
+ {
+ // abi: Do not copy, but use references
+ const ::rtl::OUString& aKeywordPair = aKeywordList[i];
+ DBG_ASSERT( aKeywordPair.getLength() > 0, "invalid help index" );
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRefList = aKeywordRefList[i];
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aAnchorList = aAnchorRefList[i];
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aTitleList = aTitleRefList[i];
+
+ DBG_ASSERT( aRefList.getLength() == aAnchorList.getLength(),"reference list and title list of different length" );
+
+ insert = ( ( ndx = aKeywordPair.indexOf( sal_Unicode( ';' ) ) ) == -1 ? sal_False : sal_True );
+
+ if ( insert )
+ {
+ aTempString = aKeywordPair.copy( 0, ndx );
+ if ( aIndex != aTempString )
+ {
+ aIndex = aTempString;
+ UNIFY_AND_INSERT_TOKEN( aTempString );
+ }
+ }
+ else
+ aIndex = ::rtl::OUString();
+
+ // Assume the token is trimed
+ UNIFY_AND_INSERT_TOKEN( aKeywordPair );
+
+ sal_uInt32 nRefListLen = aRefList.getLength();
+
+ DBG_ASSERT( aAnchorList.getLength(), "*IndexTabPage_Impl::InitializeIndex(): AnchorList is empty!" ); \
+ DBG_ASSERT( nRefListLen, "*IndexTabPage_Impl::InitializeIndex(): RefList is empty!" ); \
+
+ if ( aAnchorList.getLength() && nRefListLen )
+ {
+ INSERT_DATA( 0 );
+ }
+
+ for ( sal_uInt32 j = 1; j < nRefListLen ; ++j )
+ {
+ aData
+ .append( aKeywordPair )
+ .append( sal_Unicode(' ') )
+ .append( sal_Unicode('-') )
+ .append( sal_Unicode(' ') )
+ .append( aTitleList[j] );
+
+ aTempString = aData.makeStringAndClear();
+ UNIFY_AND_INSERT_TOKEN( aTempString );
+ INSERT_DATA( j );
+ }
+ }
+ }
+ }
+ }
+ catch( Exception& )
+ {
+ DBG_ERROR( "IndexTabPage_Impl::InitializeIndex(): unexpected exception" );
+ }
+
+ aIndexCB.SetUpdateMode( TRUE );
+
+ if ( sKeyword.Len() > 0 )
+ aKeywordLink.Call( this );
+}
+
+#undef INSERT_DATA
+#undef UNIFY_AND_INSERT_TOKEN
+
+// -----------------------------------------------------------------------
+
+void IndexTabPage_Impl::ClearIndex()
+{
+ USHORT nCount = aIndexCB.GetEntryCount();
+ for ( USHORT i = 0; i < nCount; ++i )
+ delete (IndexEntry_Impl*)(ULONG)aIndexCB.GetEntryData(i);
+ aIndexCB.Clear();
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( IndexTabPage_Impl, OpenHdl, PushButton*, EMPTYARG )
+{
+ aIndexCB.GetDoubleClickHdl().Call( &aIndexCB );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( IndexTabPage_Impl, TimeoutHdl, Timer*, pTimer )
+{
+ if ( &aFactoryTimer == pTimer )
+ InitializeIndex();
+ else if ( &aKeywordTimer == pTimer && sKeyword.Len() > 0 )
+ aKeywordLink.Call( this );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+void IndexTabPage_Impl::Resize()
+{
+ Size aSize = GetSizePixel();
+ if ( aSize.Width() < nMinWidth )
+ aSize.Width() = nMinWidth;
+ Point aPnt = aExpressionFT.GetPosPixel();
+ Size aNewSize = aExpressionFT.GetSizePixel();
+ aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
+ aExpressionFT.SetSizePixel( aNewSize );
+
+ Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
+ Size aBtnSize = aOpenBtn.GetSizePixel();
+
+ aPnt = aIndexCB.GetPosPixel();
+ aNewSize = aIndexCB.GetSizePixel();
+ aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
+ aNewSize.Height() = aSize.Height() - aPnt.Y();
+ aNewSize.Height() -= ( aBtnSize.Height() + ( a6Size.Height() * 3 / 2 ) );
+ aIndexCB.SetSizePixel( aNewSize );
+
+ aPnt.X() += ( aNewSize.Width() - aBtnSize.Width() );
+ aPnt.Y() += aNewSize.Height() + ( a6Size.Height() / 2 );
+ long nMinX = aIndexCB.GetPosPixel().X();
+ if ( aPnt.X() < nMinX )
+ aPnt.X() = nMinX;
+ aOpenBtn.SetPosPixel( aPnt );
+}
+
+// -----------------------------------------------------------------------
+
+void IndexTabPage_Impl::ActivatePage()
+{
+ if ( !bIsActivated )
+ {
+ bIsActivated = sal_True;
+ aFactoryTimer.Start();
+ }
+
+ if ( !m_pIdxWin->WasCursorLeftOrRight() )
+ SetFocusOnBox();
+}
+
+// -----------------------------------------------------------------------
+
+Control* IndexTabPage_Impl::GetLastFocusControl()
+{
+ return &aOpenBtn;
+}
+
+// -----------------------------------------------------------------------
+
+void IndexTabPage_Impl::SetDoubleClickHdl( const Link& rLink )
+{
+ aIndexCB.SetDoubleClickHdl( rLink );
+}
+
+// -----------------------------------------------------------------------
+
+void IndexTabPage_Impl::SetFactory( const String& rFactory )
+{
+ String sNewFactory( rFactory );
+ DBG_ASSERT( sNewFactory.Len() > 0, "empty factory" );
+ bool bValid = m_pIdxWin->IsValidFactory( rFactory );
+
+ if ( sFactory.Len() == 0 && !bValid )
+ {
+ sNewFactory = SfxHelp::GetDefaultHelpModule();
+ bValid = true;
+ }
+
+ if ( sNewFactory != sFactory && bValid )
+ {
+ sFactory = sNewFactory;
+ ClearIndex();
+ if ( bIsActivated )
+ aFactoryTimer.Start();
+ }
+}
+
+// -----------------------------------------------------------------------
+
+String IndexTabPage_Impl::GetSelectEntry() const
+{
+ String aRet;
+ IndexEntry_Impl* pEntry = (IndexEntry_Impl*)(ULONG)aIndexCB.GetEntryData( aIndexCB.GetEntryPos( aIndexCB.GetText() ) );
+ if ( pEntry )
+ aRet = pEntry->m_aURL;
+ return aRet;
+}
+
+// -----------------------------------------------------------------------
+
+void IndexTabPage_Impl::SetKeyword( const String& rKeyword )
+{
+ sKeyword = rKeyword;
+
+ if ( aIndexCB.GetEntryCount() > 0 )
+ aKeywordTimer.Start();
+ else if ( !bIsActivated )
+ aFactoryTimer.Start();
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool IndexTabPage_Impl::HasKeyword() const
+{
+ sal_Bool bRet = sal_False;
+ if ( sKeyword.Len() > 0 )
+ {
+ USHORT nPos = aIndexCB.GetEntryPos( sKeyword );
+ bRet = ( nPos != LISTBOX_ENTRY_NOTFOUND );
+ }
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+//added by BerryJia for fixing Bug98251, 2002-12-11
+sal_Bool IndexTabPage_Impl::HasKeywordIgnoreCase()
+{
+ sal_Bool bRet = sal_False;
+ if ( sKeyword.Len() > 0 )
+ {
+ USHORT nEntries = aIndexCB.GetEntryCount();
+ String sIndexItem;
+ const vcl::I18nHelper& rI18nHelper = GetSettings().GetLocaleI18nHelper();
+ for ( USHORT n = 0; n < nEntries; n++)
+ {
+ sIndexItem = aIndexCB.GetEntry( n );
+ if (rI18nHelper.MatchString( sIndexItem, sKeyword ))
+ {
+ sKeyword = sIndexItem;
+ bRet = sal_True;
+ }
+ }
+ }
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+void IndexTabPage_Impl::OpenKeyword()
+{
+ if ( sKeyword.Len() > 0 )
+ {
+ aIndexCB.SetText( sKeyword );
+ aIndexCB.GetDoubleClickHdl().Call( NULL );
+ sKeyword.Erase();
+ }
+}
+
+// class SearchBox_Impl --------------------------------------------------
+
+long SearchBox_Impl::PreNotify( NotifyEvent& rNEvt )
+{
+ sal_Bool bHandled = sal_False;
+ if ( !IsInDropDown() &&
+ rNEvt.GetWindow() == GetSubEdit() &&
+ rNEvt.GetType() == EVENT_KEYINPUT &&
+ KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
+ {
+ aSearchLink.Call( NULL );
+ bHandled = sal_True;
+ }
+ return bHandled ? 1 : ComboBox::PreNotify( rNEvt );
+}
+
+// -----------------------------------------------------------------------
+
+void SearchBox_Impl::Select()
+{
+ if ( !IsTravelSelect() )
+ aSearchLink.Call( NULL );
+}
+
+// class SearchResultsBox_Impl -------------------------------------------
+
+long SearchResultsBox_Impl::Notify( NotifyEvent& rNEvt )
+{
+ sal_Bool bHandled = sal_False;
+ if ( rNEvt.GetType() == EVENT_KEYINPUT &&
+ KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
+ {
+ GetDoubleClickHdl().Call( NULL );
+ bHandled = sal_True;
+ }
+
+ return bHandled ? 1 : ListBox::Notify( rNEvt );
+}
+
+// class SearchTabPage_Impl ----------------------------------------------
+
+SearchTabPage_Impl::SearchTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
+
+ HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_SEARCH ) ),
+
+ aSearchFT ( this, SfxResId( FT_SEARCH ) ),
+ aSearchED ( this, SfxResId( ED_SEARCH ) ),
+ aSearchBtn ( this, SfxResId( PB_SEARCH ) ),
+ aFullWordsCB ( this, SfxResId( CB_FULLWORDS ) ),
+ aScopeCB ( this, SfxResId( CB_SCOPE ) ),
+ aResultsLB ( this, SfxResId( LB_RESULT ) ),
+ aOpenBtn ( this, SfxResId( PB_OPEN_SEARCH ) ),
+ xBreakIterator ( vcl::unohelper::CreateBreakIterator() )
+
+{
+ FreeResource();
+
+ Link aLink = LINK( this, SearchTabPage_Impl, SearchHdl );
+ aSearchED.SetSearchLink( aLink );
+ aSearchBtn.SetClickHdl( aLink );
+ aSearchED.SetModifyHdl( LINK( this, SearchTabPage_Impl, ModifyHdl ) );
+ aOpenBtn.SetClickHdl( LINK( this, SearchTabPage_Impl, OpenHdl ) );
+
+ aMinSize = GetSizePixel();
+
+ SvtViewOptions aViewOpt( E_TABPAGE, CONFIGNAME_SEARCHPAGE );
+ if ( aViewOpt.Exists() )
+ {
+ String aUserData;
+ Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
+ ::rtl::OUString aTemp;
+ if ( aUserItem >>= aTemp )
+ {
+ aUserData = String( aTemp );
+ BOOL bChecked = ( 1 == aUserData.GetToken(0).ToInt32() ) ? TRUE : FALSE;
+ aFullWordsCB.Check( bChecked );
+ bChecked = ( 1 == aUserData.GetToken(1).ToInt32() ) ? TRUE : FALSE;
+ aScopeCB.Check( bChecked );
+
+ for ( USHORT i = 2; i < aUserData.GetTokenCount(); ++i )
+ {
+ String aToken = aUserData.GetToken(i);
+ aSearchED.InsertEntry( INetURLObject::decode(
+ aToken, '%', INetURLObject::DECODE_WITH_CHARSET ) );
+ }
+ }
+ }
+
+ ModifyHdl( &aSearchED );
+}
+
+// -----------------------------------------------------------------------
+
+SearchTabPage_Impl::~SearchTabPage_Impl()
+{
+ SvtViewOptions aViewOpt( E_TABPAGE, CONFIGNAME_SEARCHPAGE );
+ sal_Int32 nChecked = aFullWordsCB.IsChecked() ? 1 : 0;
+ String aUserData = String::CreateFromInt32( nChecked );
+ aUserData += ';';
+ nChecked = aScopeCB.IsChecked() ? 1 : 0;
+ aUserData += String::CreateFromInt32( nChecked );
+ aUserData += ';';
+ USHORT nCount = Min( aSearchED.GetEntryCount(), (USHORT)10 ); // save only 10 entries
+
+ for ( USHORT i = 0; i < nCount; ++i )
+ {
+ rtl::OUString aText = aSearchED.GetEntry(i);
+ aUserData += String(INetURLObject::encode(
+ aText, INetURLObject::PART_UNO_PARAM_VALUE, '%',
+ INetURLObject::ENCODE_ALL ));
+ aUserData += ';';
+ }
+
+ aUserData.EraseTrailingChars(';');
+ Any aUserItem = makeAny( ::rtl::OUString( aUserData ) );
+ aViewOpt.SetUserItem( USERITEM_NAME, aUserItem );
+}
+
+// -----------------------------------------------------------------------
+
+void SearchTabPage_Impl::ClearSearchResults()
+{
+ USHORT nCount = aResultsLB.GetEntryCount();
+ for ( USHORT i = 0; i < nCount; ++i )
+ delete (String*)(ULONG)aResultsLB.GetEntryData(i);
+ aResultsLB.Clear();
+ aResultsLB.Update();
+}
+
+// -----------------------------------------------------------------------
+
+void SearchTabPage_Impl::RememberSearchText( const String& rSearchText )
+{
+ for ( USHORT i = 0; i < aSearchED.GetEntryCount(); ++i )
+ {
+ if ( rSearchText == aSearchED.GetEntry(i) )
+ {
+ aSearchED.RemoveEntry(i);
+ break;
+ }
+ }
+
+ aSearchED.InsertEntry( rSearchText, 0 );
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SearchTabPage_Impl, SearchHdl, PushButton*, EMPTYARG )
+{
+ String aSearchText = TRIM( aSearchED.GetText() );
+ if ( aSearchText.Len() > 0 )
+ {
+ EnterWait();
+ ClearSearchResults();
+ RememberSearchText( aSearchText );
+ String aSearchURL = HELP_URL;
+ aSearchURL += aFactory;
+ aSearchURL += String( HELP_SEARCH_TAG );
+ if ( !aFullWordsCB.IsChecked() )
+ aSearchText = sfx2::PrepareSearchString( aSearchText, xBreakIterator, true );
+ aSearchURL += aSearchText;
+ AppendConfigToken_Impl( aSearchURL, sal_False );
+ if ( aScopeCB.IsChecked() )
+ aSearchURL += DEFINE_CONST_UNICODE("&Scope=Heading");
+ Sequence< ::rtl::OUString > aFactories = SfxContentHelper::GetResultSet( aSearchURL );
+ const ::rtl::OUString* pFacs = aFactories.getConstArray();
+ UINT32 i, nCount = aFactories.getLength();
+ for ( i = 0; i < nCount; ++i )
+ {
+ String aRow( pFacs[i] );
+ String aTitle, aType;
+ xub_StrLen nIdx = 0;
+ aTitle = aRow.GetToken( 0, '\t', nIdx );
+ aType = aRow.GetToken( 0, '\t', nIdx );
+ String* pURL = new String( aRow.GetToken( 0, '\t', nIdx ) );
+ USHORT nPos = aResultsLB.InsertEntry( aTitle );
+ aResultsLB.SetEntryData( nPos, (void*)(ULONG)pURL );
+ }
+ LeaveWait();
+
+ if ( !nCount )
+ {
+ InfoBox aBox( this, SfxResId( RID_INFO_NOSEARCHRESULTS ) );
+ aBox.SetText( String( SfxResId( STR_HELP_WINDOW_TITLE ) ) );
+ aBox.Execute();
+ }
+ }
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SearchTabPage_Impl, OpenHdl, PushButton*, EMPTYARG )
+{
+ aResultsLB.GetDoubleClickHdl().Call( &aResultsLB );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SearchTabPage_Impl, ModifyHdl, Edit*, EMPTYARG )
+{
+ String aSearchText = TRIM( aSearchED.GetText() );
+ aSearchBtn.Enable( aSearchText.Len() > 0 );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+void SearchTabPage_Impl::Resize()
+{
+ Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
+ Size aSize = GetSizePixel();
+ if ( aSize.Width() < aMinSize.Width() )
+ aSize.Width() = aMinSize.Width();
+ Point aPnt = aSearchFT.GetPosPixel();
+ Size aNewSize = aSearchFT.GetSizePixel();
+ aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
+ aSearchFT.SetSizePixel( aNewSize );
+ aNewSize.Height() = aResultsLB.GetSizePixel().Height();
+ aResultsLB.SetSizePixel( aNewSize );
+ aNewSize.Height() = aFullWordsCB.GetSizePixel().Height();
+ aFullWordsCB.SetSizePixel( aNewSize );
+ aScopeCB.SetSizePixel( aNewSize );
+ aNewSize = aSearchED.GetSizePixel();
+ aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 ) -
+ ( aSearchBtn.GetSizePixel().Width() + ( aPnt.X() / 2 ) );
+ aSearchED.SetSizePixel( aNewSize );
+ Point aNewPnt = aSearchBtn.GetPosPixel();
+ aNewPnt.X() = aPnt.X() + aNewSize.Width() + ( aPnt.X() / 2 );
+ aSearchBtn.SetPosPixel( aNewPnt );
+
+ if ( aSize.Height() > aMinSize.Height() )
+ {
+ long n3Height = a6Size.Height() / 2;
+ Size aBtnSize = aOpenBtn.GetSizePixel();
+ long nExtraHeight = aBtnSize.Height() + n3Height;
+
+ aPnt = aResultsLB.GetPosPixel();
+ aNewSize = aResultsLB.GetSizePixel();
+ aNewSize.Height() = aSize.Height() - aPnt.Y();
+ aNewSize.Height() -= ( nExtraHeight + ( a6Size.Height() * 3 / 2 ) );
+ aResultsLB.SetSizePixel( aNewSize );
+
+ aPnt.X() += ( aNewSize.Width() - aBtnSize.Width() );
+ aPnt.Y() += aNewSize.Height() + a6Size.Height();
+ aOpenBtn.SetPosPixel( aPnt );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SearchTabPage_Impl::ActivatePage()
+{
+ if ( !m_pIdxWin->WasCursorLeftOrRight() )
+ aSearchED.GrabFocus();
+}
+
+// -----------------------------------------------------------------------
+
+Control* SearchTabPage_Impl::GetLastFocusControl()
+{
+ return &aOpenBtn;
+}
+
+// -----------------------------------------------------------------------
+
+void SearchTabPage_Impl::SetDoubleClickHdl( const Link& rLink )
+{
+ aResultsLB.SetDoubleClickHdl( rLink );
+}
+
+// -----------------------------------------------------------------------
+
+String SearchTabPage_Impl::GetSelectEntry() const
+{
+ String aRet;
+ String* pData = (String*)(ULONG)aResultsLB.GetEntryData( aResultsLB.GetSelectEntryPos() );
+ if ( pData )
+ aRet = String( *pData );
+ return aRet;
+}
+
+// -----------------------------------------------------------------------
+
+void SearchTabPage_Impl::ClearPage()
+{
+ ClearSearchResults();
+ aSearchED.SetText( String() );
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SearchTabPage_Impl::OpenKeyword( const String& rKeyword )
+{
+ sal_Bool bRet = sal_False;
+ aSearchED.SetText( rKeyword );
+ SearchHdl( NULL );
+ if ( aResultsLB.GetEntryCount() > 0 )
+ {
+ // found keyword -> open it
+ aResultsLB.SelectEntryPos(0);
+ OpenHdl( NULL );
+ bRet = sal_True;
+ }
+
+ return bRet;
+}
+
+// class BookmarksTabPage_Impl -------------------------------------------
+
+void GetBookmarkEntry_Impl
+(
+ Sequence< PropertyValue >& aBookmarkEntry,
+ ::rtl::OUString& rTitle,
+ ::rtl::OUString& rURL
+)
+{
+ for ( int i = 0; i < aBookmarkEntry.getLength(); i++ )
+ {
+ PropertyValue aValue = aBookmarkEntry[i];
+ if ( aValue.Name == HISTORY_PROPERTYNAME_URL )
+ aValue.Value >>= rURL;
+ else if ( aValue.Name == HISTORY_PROPERTYNAME_TITLE )
+ aValue.Value >>= rTitle;
+ }
+}
+
+// -----------------------------------------------------------------------
+
+BookmarksBox_Impl::BookmarksBox_Impl( Window* pParent, const ResId& rResId ) :
+
+ ListBox( pParent, rResId )
+
+{
+}
+
+// -----------------------------------------------------------------------
+
+BookmarksBox_Impl::~BookmarksBox_Impl()
+{
+ // save bookmarks to configuration
+ SvtHistoryOptions aHistOpt;
+ aHistOpt.Clear( eHELPBOOKMARKS );
+ rtl::OUString sEmpty;
+ USHORT nCount = GetEntryCount();
+ for ( USHORT i = 0; i < nCount; ++i )
+ {
+ String aTitle = GetEntry(i);
+ String* pURL = (String*)(ULONG)GetEntryData(i);
+ aHistOpt.AppendItem( eHELPBOOKMARKS, rtl::OUString( *pURL ), sEmpty, rtl::OUString( aTitle ), sEmpty );
+ delete pURL;
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void BookmarksBox_Impl::DoAction( USHORT nAction )
+{
+ switch ( nAction )
+ {
+ case MID_OPEN :
+ GetDoubleClickHdl().Call( NULL );
+ break;
+
+ case MID_RENAME :
+ {
+ USHORT nPos = GetSelectEntryPos();
+ if ( nPos != LISTBOX_ENTRY_NOTFOUND )
+ {
+ SfxAddHelpBookmarkDialog_Impl aDlg( this, sal_True );
+ aDlg.SetTitle( GetEntry( nPos ) );
+ if ( aDlg.Execute() == RET_OK )
+ {
+ String* pURL = (String*)(ULONG)GetEntryData( nPos );
+ RemoveEntry( nPos );
+ rtl::OUString aImageURL = IMAGE_URL;
+ aImageURL += INetURLObject( *pURL ).GetHost();
+ nPos = InsertEntry( aDlg.GetTitle(), SvFileInformationManager::GetImage( aImageURL ) );
+ SetEntryData( nPos, (void*)(ULONG)( new String( *pURL ) ) );
+ SelectEntryPos( nPos );
+ delete pURL;
+ }
+ }
+ break;
+ }
+
+ case MID_DELETE :
+ {
+ USHORT nPos = GetSelectEntryPos();
+ if ( nPos != LISTBOX_ENTRY_NOTFOUND )
+ {
+ RemoveEntry( nPos );
+ USHORT nCount = GetEntryCount();
+ if ( nCount )
+ {
+ if ( nPos >= nCount )
+ nPos = nCount - 1;
+ SelectEntryPos( nPos );
+ }
+ }
+ break;
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
+long BookmarksBox_Impl::Notify( NotifyEvent& rNEvt )
+{
+ long nRet = 0;
+ USHORT nType = rNEvt.GetType();
+ if ( EVENT_KEYINPUT == nType )
+ {
+ USHORT nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
+ if ( KEY_DELETE == nCode && GetEntryCount() > 0 )
+ {
+ DoAction( MID_DELETE );
+ nRet = 1;
+ }
+ else if ( KEY_RETURN == nCode )
+ {
+ GetDoubleClickHdl().Call( NULL );
+ nRet = 1;
+ }
+ }
+ else if ( EVENT_COMMAND == nType )
+ {
+ const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
+ if ( pCEvt->GetCommand() == COMMAND_CONTEXTMENU )
+ {
+ PopupMenu aMenu( SfxResId( MENU_HELP_BOOKMARKS ) );
+ sal_uInt16 nId = aMenu.Execute( this, pCEvt->GetMousePosPixel() );
+ if ( nId != MENU_ITEM_NOTFOUND )
+ DoAction( nId );
+ nRet = 1;
+ }
+ }
+
+ return nRet ? nRet : ListBox::Notify( rNEvt );
+}
+
+// class BookmarksTabPage_Impl -------------------------------------------
+
+BookmarksTabPage_Impl::BookmarksTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
+
+ HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_BOOKMARKS ) ),
+
+ aBookmarksFT ( this, SfxResId( FT_BOOKMARKS ) ),
+ aBookmarksBox ( this, SfxResId( LB_BOOKMARKS ) ),
+ aBookmarksPB ( this, SfxResId( PB_BOOKMARKS ) )
+
+{
+ FreeResource();
+
+ nMinWidth = aBookmarksPB.GetSizePixel().Width();
+
+ aBookmarksPB.SetClickHdl( LINK( this, BookmarksTabPage_Impl, OpenHdl ) );
+
+ // load bookmarks from configuration
+ Sequence< Sequence< PropertyValue > > aBookmarkSeq;
+ aBookmarkSeq = SvtHistoryOptions().GetList( eHELPBOOKMARKS );
+
+ ::rtl::OUString aTitle;
+ ::rtl::OUString aURL;
+
+ UINT32 i, nCount = aBookmarkSeq.getLength();
+ for ( i = 0; i < nCount; ++i )
+ {
+ GetBookmarkEntry_Impl( aBookmarkSeq[i], aTitle, aURL );
+ AddBookmarks( aTitle, aURL );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( BookmarksTabPage_Impl, OpenHdl, PushButton*, EMPTYARG )
+{
+ aBookmarksBox.GetDoubleClickHdl().Call( &aBookmarksBox );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+void BookmarksTabPage_Impl::Resize()
+{
+ Size aSize = GetSizePixel();
+ if ( aSize.Width() < nMinWidth )
+ aSize.Width() = nMinWidth;
+ Point aPnt = aBookmarksFT.GetPosPixel();
+ Size aNewSize = aBookmarksFT.GetSizePixel();
+ aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
+ aBookmarksFT.SetSizePixel( aNewSize );
+
+ Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
+ Size aBtnSize = aBookmarksPB.GetSizePixel();
+
+ aPnt = aBookmarksBox.GetPosPixel();
+ aNewSize = aBookmarksBox.GetSizePixel();
+ aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
+ aNewSize.Height() = aSize.Height() - aPnt.Y();
+ aNewSize.Height() -= ( aBtnSize.Height() + ( a6Size.Height() * 3 / 2 ) );
+ aBookmarksBox.SetSizePixel( aNewSize );
+
+ aPnt.X() += ( aNewSize.Width() - aBtnSize.Width() );
+ aPnt.Y() += aNewSize.Height() + ( a6Size.Height() / 2 );
+ long nMinX = aBookmarksBox.GetPosPixel().X();
+ if ( aPnt.X() < nMinX )
+ aPnt.X() = nMinX;
+ aBookmarksPB.SetPosPixel( aPnt );
+}
+
+// -----------------------------------------------------------------------
+
+void BookmarksTabPage_Impl::ActivatePage()
+{
+ if ( !m_pIdxWin->WasCursorLeftOrRight() )
+ SetFocusOnBox();
+}
+
+// -----------------------------------------------------------------------
+
+Control* BookmarksTabPage_Impl::GetLastFocusControl()
+{
+ return &aBookmarksPB;
+}
+
+// -----------------------------------------------------------------------
+
+void BookmarksTabPage_Impl::SetDoubleClickHdl( const Link& rLink )
+{
+ aBookmarksBox.SetDoubleClickHdl( rLink );
+}
+
+// -----------------------------------------------------------------------
+
+String BookmarksTabPage_Impl::GetSelectEntry() const
+{
+ String aRet;
+ String* pData = (String*)(ULONG)aBookmarksBox.GetEntryData( aBookmarksBox.GetSelectEntryPos() );
+ if ( pData )
+ aRet = String( *pData );
+ return aRet;
+}
+
+// -----------------------------------------------------------------------
+
+void BookmarksTabPage_Impl::AddBookmarks( const String& rTitle, const String& rURL )
+{
+ rtl::OUString aImageURL = IMAGE_URL;
+ aImageURL += INetURLObject( rURL ).GetHost();
+ USHORT nPos = aBookmarksBox.InsertEntry( rTitle, SvFileInformationManager::GetImage( aImageURL ) );
+ aBookmarksBox.SetEntryData( nPos, (void*)(ULONG)( new String( rURL ) ) );
+}
+
+// class SfxHelpIndexWindow_Impl -----------------------------------------
+
+sal_Bool SfxHelpWindow_Impl::splitHelpURL(const ::rtl::OUString& sHelpURL,
+ ::rtl::OUString& sFactory,
+ ::rtl::OUString& sContent,
+ ::rtl::OUString& sAnchor )
+{
+ Reference < XURLTransformer > xParser( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.util.URLTransformer" )), UNO_QUERY_THROW );
+
+ URL aURL;
+ aURL.Complete = sHelpURL;
+ sal_Bool bResult = xParser->parseStrict(aURL);
+
+ sFactory = aURL.Server;
+ sContent = aURL.Path.copy(1); // strip "/"!
+ sAnchor = aURL.Mark;
+
+ return bResult;
+}
+
+::rtl::OUString SfxHelpWindow_Impl::buildHelpURL(const ::rtl::OUString& sFactory ,
+ const ::rtl::OUString& sContent ,
+ const ::rtl::OUString& sAnchor ,
+ sal_Bool bUseQuestionMark)
+{
+ ::rtl::OUStringBuffer sHelpURL(256);
+ sHelpURL.append(HELP_URL);
+ sHelpURL.append(sFactory);
+ sHelpURL.append(sContent);
+ String sURL = String(sHelpURL.makeStringAndClear());
+ AppendConfigToken_Impl(sURL, bUseQuestionMark);
+ if (sAnchor.getLength())
+ sURL += String(sAnchor);
+ return ::rtl::OUString(sURL);
+}
+
+void SfxHelpWindow_Impl::loadHelpContent(const ::rtl::OUString& sHelpURL, sal_Bool bAddToHistory)
+{
+ Reference< XComponentLoader > xLoader(getTextFrame(), UNO_QUERY);
+ if (!xLoader.is())
+ return;
+
+ // --> PB 2007-03-12 #134037#
+ // If a print job runs do not open a new page
+ Reference< XFrame > xTextFrame = pTextWin->getFrame();
+ Reference< XController > xTextController ;
+ if (xTextFrame.is())
+ xTextController = xTextFrame->getController ();
+ if ( xTextController.is() && !xTextController->suspend( sal_True ) )
+ {
+ xTextController->suspend( sal_False );
+ return;
+ }
+ // <--
+
+ // save url to history
+ if (bAddToHistory)
+ pHelpInterceptor->addURL(sHelpURL);
+
+ if ( !IsWait() )
+ EnterWait();
+ sal_Bool bSuccess = sal_False;
+// TODO implement locale fallback ... see below while(sal_True)
+ {
+ try
+ {
+ Reference< XComponent > xContent = xLoader->loadComponentFromURL(sHelpURL, DEFINE_CONST_UNICODE("_self"), 0, Sequence< PropertyValue >());
+ if (xContent.is())
+ {
+ bSuccess = sal_True;
+// break;
+ }
+ }
+ catch(const RuntimeException&)
+ { throw; }
+ catch(const Exception&)
+ { /*break;*/ }
+
+ /* TODO try next locale ...
+ no further locale available? => break loop and show error page
+ */
+ }
+ openDone(sHelpURL, bSuccess);
+ if ( IsWait() )
+ LeaveWait();
+}
+
+SfxHelpIndexWindow_Impl::SfxHelpIndexWindow_Impl( SfxHelpWindow_Impl* _pParent ) :
+
+ Window( _pParent, SfxResId( WIN_HELPINDEX ) ),
+
+ aActiveLB ( this, SfxResId( LB_ACTIVE ) ),
+ aActiveLine ( this, SfxResId( FL_ACTIVE ) ),
+ aTabCtrl ( this, SfxResId( TC_INDEX ) ),
+
+ aIndexKeywordLink ( LINK( this, SfxHelpIndexWindow_Impl, KeywordHdl ) ),
+ pParentWin ( _pParent ),
+
+ pCPage ( NULL ),
+ pIPage ( NULL ),
+ pSPage ( NULL ),
+ pBPage ( NULL ),
+
+ bWasCursorLeftOrRight( false ),
+ bIsInitDone ( false )
+
+{
+ FreeResource();
+
+ sfx2::AddToTaskPaneList( this );
+
+ aTabCtrl.SetActivatePageHdl( LINK( this, SfxHelpIndexWindow_Impl, ActivatePageHdl ) );
+ aTabCtrl.Show();
+
+ sal_Int32 nPageId = HELP_INDEX_PAGE_INDEX;
+ SvtViewOptions aViewOpt( E_TABDIALOG, CONFIGNAME_INDEXWIN );
+ if ( aViewOpt.Exists() )
+ nPageId = aViewOpt.GetPageID();
+ aTabCtrl.SetCurPageId( (USHORT)nPageId );
+ ActivatePageHdl( &aTabCtrl );
+ aActiveLB.SetSelectHdl( LINK( this, SfxHelpIndexWindow_Impl, SelectHdl ) );
+ nMinWidth = ( aActiveLB.GetSizePixel().Width() / 2 );
+
+ aTimer.SetTimeoutHdl( LINK( this, SfxHelpIndexWindow_Impl, InitHdl ) );
+ aTimer.SetTimeout( 200 );
+ aTimer.Start();
+}
+
+// -----------------------------------------------------------------------
+
+SfxHelpIndexWindow_Impl::~SfxHelpIndexWindow_Impl()
+{
+ sfx2::RemoveFromTaskPaneList( this );
+
+ DELETEZ( pCPage );
+ DELETEZ( pIPage );
+ DELETEZ( pSPage );
+ DELETEZ( pBPage );
+
+ for ( USHORT i = 0; i < aActiveLB.GetEntryCount(); ++i )
+ delete (String*)(ULONG)aActiveLB.GetEntryData(i);
+
+ SvtViewOptions aViewOpt( E_TABDIALOG, CONFIGNAME_INDEXWIN );
+ aViewOpt.SetPageID( (sal_Int32)aTabCtrl.GetCurPageId() );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::Initialize()
+{
+ String aHelpURL = HELP_URL;
+ AppendConfigToken_Impl( aHelpURL, sal_True );
+ Sequence< ::rtl::OUString > aFactories = SfxContentHelper::GetResultSet( aHelpURL );
+ const ::rtl::OUString* pFacs = aFactories.getConstArray();
+ UINT32 i, nCount = aFactories.getLength();
+ for ( i = 0; i < nCount; ++i )
+ {
+ String aRow( pFacs[i] );
+ String aTitle, aType, aURL;
+ xub_StrLen nIdx = 0;
+ aTitle = aRow.GetToken( 0, '\t', nIdx );
+ aType = aRow.GetToken( 0, '\t', nIdx );
+ aURL = aRow.GetToken( 0, '\t', nIdx );
+ String* pFactory = new String( INetURLObject( aURL ).GetHost() );
+ USHORT nPos = aActiveLB.InsertEntry( aTitle );
+ aActiveLB.SetEntryData( nPos, (void*)(ULONG)pFactory );
+ }
+
+ aActiveLB.SetDropDownLineCount( (USHORT)nCount );
+ if ( aActiveLB.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND )
+ SetActiveFactory();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::SetActiveFactory()
+{
+ DBG_ASSERT( pIPage, "index page not initialized" );
+ if ( !bIsInitDone && !aActiveLB.GetEntryCount() )
+ {
+ aTimer.Stop();
+ InitHdl( NULL );
+ }
+
+ for ( USHORT i = 0; i < aActiveLB.GetEntryCount(); ++i )
+ {
+ String* pFactory = (String*)(ULONG)aActiveLB.GetEntryData(i);
+ pFactory->ToLowerAscii();
+ if ( *pFactory == pIPage->GetFactory() )
+ {
+ if ( aActiveLB.GetSelectEntryPos() != i )
+ {
+ aActiveLB.SelectEntryPos(i);
+ aSelectFactoryLink.Call( NULL );
+ }
+ break;
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
+HelpTabPage_Impl* SfxHelpIndexWindow_Impl::GetCurrentPage( USHORT& rCurId )
+{
+ rCurId = aTabCtrl.GetCurPageId();
+ HelpTabPage_Impl* pPage = NULL;
+
+ switch ( rCurId )
+ {
+ case HELP_INDEX_PAGE_CONTENTS:
+ {
+ pPage = GetContentPage();
+ break;
+ }
+
+ case HELP_INDEX_PAGE_INDEX:
+ {
+ pPage = GetIndexPage();
+ break;
+ }
+
+ case HELP_INDEX_PAGE_SEARCH:
+ {
+ pPage = GetSearchPage();
+ break;
+ }
+
+ case HELP_INDEX_PAGE_BOOKMARKS:
+ {
+ pPage = GetBookmarksPage();
+ break;
+ }
+ }
+
+ DBG_ASSERT( pPage, "SfxHelpIndexWindow_Impl::GetCurrentPage(): no current page" );
+ return pPage;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpIndexWindow_Impl, ActivatePageHdl, TabControl *, pTabCtrl )
+{
+ USHORT nId = 0;
+ TabPage* pPage = GetCurrentPage( nId );
+ pTabCtrl->SetTabPage( nId, pPage );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpIndexWindow_Impl, SelectHdl, ListBox *, EMPTYARG )
+{
+ aTimer.Start();
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpIndexWindow_Impl, InitHdl, Timer *, EMPTYARG )
+{
+ bIsInitDone = true;
+ Initialize();
+
+ // now use the timer for selection
+ aTimer.SetTimeoutHdl( LINK( this, SfxHelpIndexWindow_Impl, SelectFactoryHdl ) );
+ aTimer.SetTimeout( 1000 );
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpIndexWindow_Impl, SelectFactoryHdl, Timer *, EMPTYARG )
+{
+ String* pFactory = (String*)(ULONG)aActiveLB.GetEntryData( aActiveLB.GetSelectEntryPos() );
+ if ( pFactory )
+ {
+ String aFactory( *pFactory );
+ aFactory.ToLowerAscii();
+ SetFactory( aFactory, sal_False );
+ aSelectFactoryLink.Call( this );
+ }
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpIndexWindow_Impl, KeywordHdl, IndexTabPage_Impl *, EMPTYARG )
+{
+ // keyword found on index?
+ sal_Bool bIndex = pIPage->HasKeyword();
+ //The following two lines are added by BerryJia for fixing Bug98251, 2002-12-11
+ if( !bIndex)
+ bIndex = pIPage->HasKeywordIgnoreCase();
+ // then set index or search page as current.
+ USHORT nPageId = ( bIndex ) ? HELP_INDEX_PAGE_INDEX : HELP_INDEX_PAGE_SEARCH;
+ if ( nPageId != aTabCtrl.GetCurPageId() )
+ {
+ aTabCtrl.SetCurPageId( nPageId );
+ ActivatePageHdl( &aTabCtrl );
+ }
+
+ // at last we open the keyword
+ if ( bIndex )
+ pIPage->OpenKeyword();
+ else if ( !pSPage->OpenKeyword( sKeyword ) )
+ pParentWin->ShowStartPage();
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::Resize()
+{
+ Size aSize = GetOutputSizePixel();
+ if ( aSize.Width() < nMinWidth )
+ aSize.Width() = nMinWidth;
+
+ Point aPnt = aActiveLB.GetPosPixel();
+ Size aNewSize = aActiveLB.GetSizePixel();
+ aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
+ aActiveLB.SetSizePixel( aNewSize );
+ aPnt = aActiveLine.GetPosPixel();
+ aNewSize = aActiveLine.GetSizePixel();
+ aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
+ aActiveLine.SetSizePixel( aNewSize );
+ aPnt = aTabCtrl.GetPosPixel();
+ aNewSize = aSize;
+ aSize.Width() -= aPnt.X();
+ aSize.Height() -= aPnt.Y();
+ aTabCtrl.SetSizePixel( aSize );
+}
+
+// -----------------------------------------------------------------------
+
+long SfxHelpIndexWindow_Impl::PreNotify( NotifyEvent& rNEvt )
+{
+ long nDone = 0;
+ USHORT nType = rNEvt.GetType();
+ if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
+ {
+ const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
+ USHORT nCode = rKeyCode.GetCode();
+
+ if ( KEY_TAB == nCode )
+ {
+ // don't exit index pane with <TAB>
+ USHORT nPageId = 0;
+ HelpTabPage_Impl* pCurPage = GetCurrentPage( nPageId );
+ Control* pControl = pCurPage->GetLastFocusControl();
+ BOOL bShift = rKeyCode.IsShift();
+ BOOL bCtrl = rKeyCode.IsMod1();
+ if ( !bCtrl && bShift && aActiveLB.HasChildPathFocus() )
+ {
+ pControl->GrabFocus();
+ nDone = 1;
+ }
+ else if ( !bCtrl && !bShift && pControl->HasChildPathFocus() )
+ {
+ aActiveLB.GrabFocus();
+ nDone = 1;
+ }
+ else if ( bCtrl )
+ {
+ // <STRG><TAB> moves through the pages
+ if ( nPageId < HELP_INDEX_PAGE_LAST )
+ nPageId++;
+ else
+ nPageId = HELP_INDEX_PAGE_FIRST;
+ aTabCtrl.SetCurPageId( (USHORT)nPageId );
+ ActivatePageHdl( &aTabCtrl );
+ nDone = 1;
+ }
+ }
+ else if ( aTabCtrl.HasFocus() && ( KEY_LEFT == nCode || KEY_RIGHT == nCode ) )
+ {
+ bWasCursorLeftOrRight = true;
+ }
+ }
+
+ return nDone ? nDone : Window::PreNotify( rNEvt );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
+{
+ Window::DataChanged( rDCEvt );
+
+ if ( ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
+ ( rDCEvt.GetType() == DATACHANGED_DISPLAY ) ) &&
+ ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
+ {
+ SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::SetDoubleClickHdl( const Link& rLink )
+{
+ aPageDoubleClickLink = rLink;
+ if ( pCPage )
+ pCPage->SetOpenHdl( aPageDoubleClickLink );
+ if ( pIPage )
+ pIPage->SetDoubleClickHdl( aPageDoubleClickLink );
+ if ( pSPage )
+ pSPage->SetDoubleClickHdl( aPageDoubleClickLink );
+ if ( pBPage )
+ pBPage->SetDoubleClickHdl( aPageDoubleClickLink );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::SetFactory( const String& rFactory, sal_Bool bActive )
+{
+ if ( rFactory.Len() > 0 )
+ {
+ GetIndexPage()->SetFactory( rFactory );
+ // the index page did a check if rFactory is valid,
+ // so the index page always returns a valid factory
+ GetSearchPage()->SetFactory( GetIndexPage()->GetFactory() );
+ if ( bActive )
+ SetActiveFactory();
+ }
+}
+
+// -----------------------------------------------------------------------
+
+String SfxHelpIndexWindow_Impl::GetSelectEntry() const
+{
+ String sRet;
+
+ switch ( aTabCtrl.GetCurPageId() )
+ {
+ case HELP_INDEX_PAGE_CONTENTS:
+ sRet = pCPage->GetSelectEntry();
+ break;
+
+ case HELP_INDEX_PAGE_INDEX:
+ sRet = pIPage->GetSelectEntry();
+ break;
+
+ case HELP_INDEX_PAGE_SEARCH:
+ sRet = pSPage->GetSelectEntry();
+ break;
+
+ case HELP_INDEX_PAGE_BOOKMARKS:
+ sRet = pBPage->GetSelectEntry();
+ break;
+ }
+
+ return sRet;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::AddBookmarks( const String& rTitle, const String& rURL )
+{
+ GetBookmarksPage()->AddBookmarks( rTitle, rURL );
+}
+
+// -----------------------------------------------------------------------
+
+bool SfxHelpIndexWindow_Impl::IsValidFactory( const String& _rFactory )
+{
+ bool bValid = false;
+ for ( USHORT i = 0; i < aActiveLB.GetEntryCount(); ++i )
+ {
+ String* pFactory = (String*)(ULONG)aActiveLB.GetEntryData(i);
+ if ( *pFactory == _rFactory )
+ {
+ bValid = true;
+ break;
+ }
+ }
+ return bValid;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::ClearSearchPage()
+{
+ if ( pSPage )
+ pSPage->ClearPage();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::GrabFocusBack()
+{
+ if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_CONTENTS && pCPage )
+ pCPage->SetFocusOnBox();
+ else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_INDEX && pIPage )
+ pIPage->SetFocusOnBox();
+ else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
+ pSPage->SetFocusOnBox();
+ else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_BOOKMARKS && pBPage )
+ pBPage->SetFocusOnBox();
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxHelpIndexWindow_Impl::HasFocusOnEdit() const
+{
+ sal_Bool bRet = sal_False;
+ if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_INDEX && pIPage )
+ bRet = pIPage->HasFocusOnEdit();
+ else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
+ bRet = pSPage->HasFocusOnEdit();
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+String SfxHelpIndexWindow_Impl::GetSearchText() const
+{
+ String sRet;
+ if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
+ sRet = pSPage->GetSearchText();
+ return sRet;
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxHelpIndexWindow_Impl::IsFullWordSearch() const
+{
+ sal_Bool bRet = sal_False;
+ if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
+ bRet = pSPage->IsFullWordSearch();
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::OpenKeyword( const String& rKeyword )
+{
+ sKeyword = rKeyword;
+ DBG_ASSERT( pIPage, "invalid index page" );
+ pIPage->SetKeyword( sKeyword );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpIndexWindow_Impl::SelectExecutableEntry()
+{
+ if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_INDEX && pIPage )
+ pIPage->SelectExecutableEntry();
+}
+
+// class TextWin_Impl ----------------------------------------------------
+
+TextWin_Impl::TextWin_Impl( Window* p ) : DockingWindow( p, 0 )
+{
+}
+
+TextWin_Impl::~TextWin_Impl()
+{
+}
+
+long TextWin_Impl::Notify( NotifyEvent& rNEvt )
+{
+ if( ( rNEvt.GetType() == EVENT_KEYINPUT ) && rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_TAB )
+ return GetParent()->Notify( rNEvt );
+ else
+ return DockingWindow::Notify( rNEvt );
+}
+
+// -----------------------------------------------------------------------
+// remove docking area acceptor from layoutmanager, so it will not layout anything further .-)
+void lcl_disableLayoutOfFrame(const Reference< XFrame >& xFrame)
+{
+ static const ::rtl::OUString PROP_LAYOUT_MANAGER(DEFINE_CONST_UNICODE("LayoutManager"));
+
+ Reference< XPropertySet > xPropSet(xFrame, UNO_QUERY_THROW);
+ xPropSet->setPropertyValue(PROP_LAYOUT_MANAGER, makeAny(Reference< XLayoutManager >()));
+}
+
+// class SfxHelpTextWindow_Impl ------------------------------------------
+
+SfxHelpTextWindow_Impl::SfxHelpTextWindow_Impl( SfxHelpWindow_Impl* pParent ) :
+
+ Window( pParent, WB_CLIPCHILDREN | WB_TABSTOP | WB_DIALOGCONTROL ),
+
+ aToolBox ( this, 0 ),
+ aOnStartupCB ( this, SfxResId( RID_HELP_ONSTARTUP_BOX ) ),
+ aIndexOnImage ( SfxResId( IMG_HELP_TOOLBOX_INDEX_ON ) ),
+ aIndexOffImage ( SfxResId( IMG_HELP_TOOLBOX_INDEX_OFF ) ),
+ aIndexOnText ( SfxResId( STR_HELP_BUTTON_INDEX_ON ) ),
+ aIndexOffText ( SfxResId( STR_HELP_BUTTON_INDEX_OFF ) ),
+ aOnStartupText ( SfxResId( RID_HELP_ONSTARTUP_TEXT ) ),
+ pHelpWin ( pParent ),
+ pTextWin ( new TextWin_Impl( this ) ),
+ pSrchDlg ( NULL ),
+ nMinPos ( 0 ),
+ bIsDebug ( sal_False ),
+ bIsIndexOn ( sal_False ),
+ bIsInClose ( sal_False ),
+ bIsFullWordSearch ( sal_False )
+
+{
+ sfx2::AddToTaskPaneList( &aToolBox );
+
+ xFrame = Reference < XFrame > ( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.Frame") ), UNO_QUERY );
+ xFrame->initialize( VCLUnoHelper::GetInterface ( pTextWin ) );
+ xFrame->setName( DEFINE_CONST_UNICODE("OFFICE_HELP") );
+ lcl_disableLayoutOfFrame(xFrame);
+
+ aToolBox.SetHelpId( HID_HELP_TOOLBOX );
+
+ aToolBox.InsertItem( TBI_INDEX, aIndexOffText );
+ aToolBox.SetHelpId( TBI_INDEX, HID_HELP_TOOLBOXITEM_INDEX );
+ aToolBox.InsertSeparator();
+ aToolBox.InsertItem( TBI_BACKWARD, String( SfxResId( STR_HELP_BUTTON_PREV ) ) );
+ aToolBox.SetHelpId( TBI_BACKWARD, HID_HELP_TOOLBOXITEM_BACKWARD );
+ aToolBox.InsertItem( TBI_FORWARD, String( SfxResId( STR_HELP_BUTTON_NEXT ) ) );
+ aToolBox.SetHelpId( TBI_FORWARD, HID_HELP_TOOLBOXITEM_FORWARD );
+ aToolBox.InsertItem( TBI_START, String( SfxResId( STR_HELP_BUTTON_START ) ) );
+ aToolBox.SetHelpId( TBI_START, HID_HELP_TOOLBOXITEM_START );
+ aToolBox.InsertSeparator();
+ aToolBox.InsertItem( TBI_PRINT, String( SfxResId( STR_HELP_BUTTON_PRINT ) ) );
+ aToolBox.SetHelpId( TBI_PRINT, HID_HELP_TOOLBOXITEM_PRINT );
+ aToolBox.InsertItem( TBI_BOOKMARKS, String( SfxResId( STR_HELP_BUTTON_ADDBOOKMARK ) ) );
+ aToolBox.SetHelpId( TBI_BOOKMARKS, HID_HELP_TOOLBOXITEM_BOOKMARKS );
+ aToolBox.InsertItem( TBI_SEARCHDIALOG, String( SfxResId( STR_HELP_BUTTON_SEARCHDIALOG ) ) );
+ aToolBox.SetHelpId( TBI_SEARCHDIALOG, HID_HELP_TOOLBOXITEM_SEARCHDIALOG );
+
+ InitToolBoxImages();
+ aToolBox.Show();
+ InitOnStartupBox( false );
+ aOnStartupCB.SetClickHdl( LINK( this, SfxHelpTextWindow_Impl, CheckHdl ) );
+
+ aSelectTimer.SetTimeoutHdl( LINK( this, SfxHelpTextWindow_Impl, SelectHdl ) );
+ aSelectTimer.SetTimeout( 1000 );
+
+ char* pEnv = getenv( "help_debug" );
+ if ( pEnv )
+ bIsDebug = sal_True;
+
+ SvtMiscOptions().AddListenerLink( LINK( this, SfxHelpTextWindow_Impl, NotifyHdl ) );
+
+ if ( !aOnStartupCB.GetHelpId().getLength() )
+ aOnStartupCB.SetHelpId( HID_HELP_ONSTARTUP_BOX );
+}
+
+// -----------------------------------------------------------------------
+
+SfxHelpTextWindow_Impl::~SfxHelpTextWindow_Impl()
+{
+ sfx2::RemoveFromTaskPaneList( &aToolBox );
+
+ bIsInClose = sal_True;
+ SvtMiscOptions().RemoveListenerLink( LINK( this, SfxHelpTextWindow_Impl, NotifyHdl ) );
+ delete pSrchDlg;
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxHelpTextWindow_Impl::HasSelection() const
+{
+ // is there any selection in the text and not only a cursor?
+ sal_Bool bRet = sal_False;
+ Reference < XTextRange > xRange = getCursor();
+ if ( xRange.is() )
+ {
+ Reference < XText > xText = xRange->getText();
+ Reference < XTextCursor > xCursor = xText->createTextCursorByRange( xRange );
+ bRet = !xCursor->isCollapsed();
+ }
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::InitToolBoxImages()
+{
+ sal_Bool bLarge = SvtMiscOptions().AreCurrentSymbolsLarge();
+ sal_Bool bHiContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
+
+ aIndexOnImage = Image( SfxResId(
+ bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_INDEX_ON : IMG_HELP_TOOLBOX_L_INDEX_ON
+ : bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_ON : IMG_HELP_TOOLBOX_INDEX_ON ) );
+ aIndexOffImage = Image( SfxResId(
+ bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_INDEX_OFF : IMG_HELP_TOOLBOX_L_INDEX_OFF
+ : bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_OFF : IMG_HELP_TOOLBOX_INDEX_OFF ) );
+ aToolBox.SetItemImage( TBI_INDEX, bIsIndexOn ? aIndexOffImage : aIndexOnImage );
+
+ aToolBox.SetItemImage( TBI_BACKWARD, Image( SfxResId(
+ bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_PREV : IMG_HELP_TOOLBOX_L_PREV
+ : bHiContrast ? IMG_HELP_TOOLBOX_HC_PREV : IMG_HELP_TOOLBOX_PREV ) ) );
+ aToolBox.SetItemImage( TBI_FORWARD, Image( SfxResId(
+ bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_NEXT : IMG_HELP_TOOLBOX_L_NEXT
+ : bHiContrast ? IMG_HELP_TOOLBOX_HC_NEXT : IMG_HELP_TOOLBOX_NEXT ) ) );
+ aToolBox.SetItemImage( TBI_START, Image( SfxResId(
+ bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_START : IMG_HELP_TOOLBOX_L_START
+ : bHiContrast ? IMG_HELP_TOOLBOX_HC_START : IMG_HELP_TOOLBOX_START ) ) );
+ aToolBox.SetItemImage( TBI_PRINT, Image( SfxResId(
+ bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_PRINT : IMG_HELP_TOOLBOX_L_PRINT
+ : bHiContrast ? IMG_HELP_TOOLBOX_HC_PRINT : IMG_HELP_TOOLBOX_PRINT ) ) );
+ aToolBox.SetItemImage( TBI_BOOKMARKS, Image( SfxResId(
+ bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_BOOKMARKS : IMG_HELP_TOOLBOX_L_BOOKMARKS
+ : bHiContrast ? IMG_HELP_TOOLBOX_HC_BOOKMARKS : IMG_HELP_TOOLBOX_BOOKMARKS ) ) );
+ aToolBox.SetItemImage( TBI_SEARCHDIALOG, Image( SfxResId(
+ bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_SEARCHDIALOG : IMG_HELP_TOOLBOX_L_SEARCHDIALOG
+ : bHiContrast ? IMG_HELP_TOOLBOX_HC_SEARCHDIALOG : IMG_HELP_TOOLBOX_SEARCHDIALOG ) ) );
+
+ Size aSize = aToolBox.CalcWindowSizePixel();
+ aSize.Height() += TOOLBOX_OFFSET;
+ aToolBox.SetPosSizePixel( Point( 0, TOOLBOX_OFFSET ), aSize );
+
+ SvtMiscOptions aMiscOptions;
+ if ( aMiscOptions.GetToolboxStyle() != aToolBox.GetOutStyle() )
+ aToolBox.SetOutStyle( aMiscOptions.GetToolboxStyle() );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::InitOnStartupBox( bool bOnlyText )
+{
+ sCurrentFactory = SfxHelp::GetCurrentModuleIdentifier();
+
+ Reference< XMultiServiceFactory > xMultiServiceFac = ::comphelper::getProcessServiceFactory();
+ Reference< XInterface > xConfig;
+ ::rtl::OUString sPath( PATH_OFFICE_FACTORIES );
+ sPath += sCurrentFactory;
+ ::rtl::OUString sKey( KEY_HELP_ON_OPEN );
+
+ // Attention: This check boy knows two states:
+ // 1) Reading of the config key fails with an exception or by getting an empty Any (!) => check box must be hidden
+ // 2) We read TRUE/FALSE => check box must be shown and enabled/disabled
+
+ bool bHideBox = true;
+ sal_Bool bHelpAtStartup = sal_False;
+ try
+ {
+ xConfiguration = ConfigurationHelper::openConfig(
+ xMultiServiceFac, PACKAGE_SETUP, ConfigurationHelper::E_STANDARD );
+ if ( xConfiguration.is() )
+ {
+ Any aAny = ConfigurationHelper::readRelativeKey( xConfiguration, sPath, sKey );
+ if (aAny >>= bHelpAtStartup)
+ bHideBox = false;
+ }
+ }
+ catch( Exception& )
+ {
+ bHideBox = true;
+ }
+
+ if ( bHideBox )
+ aOnStartupCB.Hide();
+ else
+ {
+ // detect module name
+ String sModuleName;
+
+ if ( xConfiguration.is() )
+ {
+ ::rtl::OUString sTemp;
+ sKey = KEY_UI_NAME;
+ try
+ {
+ Any aAny = ConfigurationHelper::readRelativeKey( xConfiguration, sPath, sKey );
+ aAny >>= sTemp;
+ }
+ catch( Exception& )
+ {
+ DBG_ERRORFILE( "SfxHelpTextWindow_Impl::InitOnStartupBox(): unexpected exception" );
+ }
+ sModuleName = String( sTemp );
+ }
+
+ if ( sModuleName.Len() > 0 )
+ {
+ // set module name in checkbox text
+ String sText( aOnStartupText );
+ sText.SearchAndReplace( String::CreateFromAscii( "%MODULENAME" ), sModuleName );
+ aOnStartupCB.SetText( sText );
+ // and show it
+ aOnStartupCB.Show();
+ // set check state
+ aOnStartupCB.Check( bHelpAtStartup );
+ aOnStartupCB.SaveValue();
+
+ // calculate and set optimal width of the onstartup checkbox
+ String sCBText( DEFINE_CONST_UNICODE( "XXX" ) );
+ sCBText += aOnStartupCB.GetText();
+ long nTextWidth = aOnStartupCB.GetTextWidth( sCBText );
+ Size aSize = aOnStartupCB.GetSizePixel();
+ aSize.Width() = nTextWidth;
+ aOnStartupCB.SetSizePixel( aSize );
+ SetOnStartupBoxPosition();
+ }
+
+ if ( !bOnlyText )
+ {
+ // set position of the checkbox
+ Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
+ Size aTBSize = aToolBox.GetSizePixel();
+ Size aCBSize = aOnStartupCB.GetSizePixel();
+ Point aPnt = aToolBox.GetPosPixel();
+ aPnt.X() += aTBSize.Width() + a3Size.Width();
+ aPnt.Y() += ( ( aTBSize.Height() - aCBSize.Height() ) / 2 );
+ aOnStartupCB.SetPosPixel( aPnt );
+ nMinPos = aPnt.X();
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::SetOnStartupBoxPosition()
+{
+ long nX = Max( GetOutputSizePixel().Width() - aOnStartupCB.GetSizePixel().Width(), nMinPos );
+ Point aPos = aOnStartupCB.GetPosPixel();
+ aPos.X() = nX;
+ aOnStartupCB.SetPosPixel( aPos );
+}
+
+// -----------------------------------------------------------------------
+
+Reference< XBreakIterator > SfxHelpTextWindow_Impl::GetBreakIterator()
+{
+ if ( !xBreakIterator.is() )
+ xBreakIterator = vcl::unohelper::CreateBreakIterator();
+ DBG_ASSERT( xBreakIterator.is(), "Could not create BreakIterator" );
+ return xBreakIterator;
+}
+
+// -----------------------------------------------------------------------
+
+Reference< XTextRange > SfxHelpTextWindow_Impl::getCursor() const
+{
+ // return the current cursor
+ Reference< XTextRange > xCursor;
+
+ try
+ {
+ Reference < XSelectionSupplier > xSelSup( xFrame->getController(), UNO_QUERY );
+ if ( xSelSup.is() )
+ {
+ Any aAny = xSelSup->getSelection();
+ Reference < XIndexAccess > xSelection;
+ if ( aAny >>= xSelection )
+ {
+ if ( xSelection->getCount() == 1 )
+ {
+ aAny = xSelection->getByIndex(0);
+ aAny >>= xCursor;
+ }
+ }
+ }
+ }
+ catch( Exception& )
+ {
+ DBG_ERROR( "SfxHelpTextWindow_Impl::getCursor(): unexpected exception" );
+ }
+
+ return xCursor;
+}
+
+// -----------------------------------------------------------------------
+
+bool SfxHelpTextWindow_Impl::isHandledKey( const KeyCode& _rKeyCode )
+{
+ bool bRet = false;
+ USHORT nCode = _rKeyCode.GetCode();
+
+ // the keys <STRG><A> (select all), <STRG><C> (copy),
+ // <STRG><F> (find), <STRG><P> (print) and <STRG><W> (close window)
+ // were handled in help
+ if ( _rKeyCode.IsMod1() &&
+ ( KEY_A == nCode || KEY_C == nCode || KEY_F == nCode || KEY_P == nCode || KEY_W == nCode ) )
+ {
+ if ( KEY_F == nCode )
+ DoSearch();
+ else
+ bRet = true;
+ }
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpTextWindow_Impl, SelectHdl, Timer*, EMPTYARG )
+{
+ try
+ {
+ // select the words, which are equal to the search text of the search page
+ Reference < XController > xController = xFrame->getController();
+ if ( xController.is() )
+ {
+ // get document
+ Reference < XSearchable > xSearchable( xController->getModel(), UNO_QUERY );
+ if ( xSearchable.is() )
+ {
+ // create descriptor, set string and find all words
+ Reference < XSearchDescriptor > xSrchDesc = xSearchable->createSearchDescriptor();
+ Reference < XPropertySet > xPropSet( xSrchDesc, UNO_QUERY );
+ xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchRegularExpression"),
+ makeAny( sal_Bool( sal_True ) ) );
+ if ( bIsFullWordSearch )
+ xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchWords"),
+ makeAny( sal_Bool( sal_True ) ) );
+
+ String sSearchString = sfx2::PrepareSearchString( aSearchText, GetBreakIterator(), false );
+ xSrchDesc->setSearchString( sSearchString );
+ Reference< XIndexAccess > xSelection = xSearchable->findAll( xSrchDesc );
+
+ // then select all found words
+ Reference < XSelectionSupplier > xSelectionSup( xController, UNO_QUERY );
+ if ( xSelectionSup.is() )
+ {
+ Any aAny;
+ aAny <<= xSelection;
+ xSelectionSup->select( aAny );
+ }
+ }
+ }
+ }
+ catch( Exception& )
+ {
+ DBG_ERROR( "SfxHelpTextWindow_Impl::SelectHdl(): unexpected exception" );
+ }
+
+ return 1;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpTextWindow_Impl, NotifyHdl, SvtMiscOptions*, pOptions )
+{
+ (void)pOptions; // unused variable
+ InitToolBoxImages();
+ Resize();
+ aToolBox.Invalidate();
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpTextWindow_Impl, FindHdl, sfx2::SearchDialog*, pDlg )
+{
+ bool bWrapAround = ( NULL == pDlg );
+ if ( bWrapAround )
+ pDlg = pSrchDlg;
+ DBG_ASSERT( pDlg, "invalid search dialog" );
+ String sSearchText = pDlg->GetSearchText();
+ try
+ {
+ // select the words, which are equal to the search text of the search page
+ Reference < XController > xController = xFrame->getController();
+ if ( xController.is() )
+ {
+ // get document
+ Reference < XSearchable > xSearchable( xController->getModel(), UNO_QUERY );
+ if ( xSearchable.is() )
+ {
+ // create descriptor, set string and find all words
+ Reference < XSearchDescriptor > xSrchDesc = xSearchable->createSearchDescriptor();
+ Reference < XPropertySet > xPropSet( xSrchDesc, UNO_QUERY );
+ xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchWords"), makeAny( sal_Bool( pDlg->IsOnlyWholeWords() != false ) ) );
+ xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchCaseSensitive"), makeAny( sal_Bool( pDlg->IsMarchCase() != false ) ) );
+ xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchBackwards"), makeAny( sal_Bool( pDlg->IsSearchBackwards() != false ) ) );
+ xSrchDesc->setSearchString( sSearchText );
+ Reference< XInterface > xSelection;
+ Reference< XTextRange > xCursor = getCursor();
+
+ if ( xCursor.is() )
+ {
+ if ( pDlg->IsSearchBackwards() )
+ xCursor = xCursor->getStart();
+ xSelection = xSearchable->findNext( xCursor, xSrchDesc );
+ }
+ else
+ xSelection = xSearchable->findFirst( xSrchDesc );
+
+ // then select the found word
+ if ( xSelection.is() )
+ {
+ Reference < XSelectionSupplier > xSelectionSup( xController, UNO_QUERY );
+ if ( xSelectionSup.is() )
+ {
+ Any aAny;
+ aAny <<= xSelection;
+ xSelectionSup->select( aAny );
+ }
+ }
+ else if ( pDlg->IsWrapAround() && !bWrapAround )
+ {
+ Reference < text::XTextViewCursorSupplier > xCrsrSupp( xController, uno::UNO_QUERY );
+ Reference < text::XTextViewCursor > xTVCrsr( xCrsrSupp->getViewCursor(), uno::UNO_QUERY );
+ if ( xTVCrsr.is() )
+ {
+ Reference < text::XTextDocument > xDoc( xController->getModel(), uno::UNO_QUERY );
+ Reference < text::XText > xText = xDoc->getText();
+ if ( xText.is() )
+ {
+ if ( pDlg->IsSearchBackwards() )
+ xTVCrsr->gotoRange( xText->getEnd(), sal_False );
+ else
+ xTVCrsr->gotoRange( xText->getStart(), sal_False );
+ FindHdl( NULL );
+ }
+ }
+ }
+ else
+ {
+ DBG_ASSERT( pSrchDlg, "no search dialog" );
+ InfoBox aBox( pSrchDlg, SfxResId( RID_INFO_NOSEARCHTEXTFOUND ) );
+ aBox.Execute();
+ pSrchDlg->SetFocusOnEdit();
+ }
+ }
+ }
+ }
+ catch( Exception& )
+ {
+ DBG_ERROR( "SfxHelpTextWindow_Impl::SelectHdl(): unexpected exception" );
+ }
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpTextWindow_Impl, CloseHdl, sfx2::SearchDialog*, pDlg )
+{
+ if ( pDlg )
+ delete pSrchDlg;
+ pSrchDlg = NULL;
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpTextWindow_Impl, CheckHdl, CheckBox*, pBox )
+{
+ if ( xConfiguration.is() )
+ {
+ sal_Bool bChecked = pBox->IsChecked();
+ ::rtl::OUString sPath( PATH_OFFICE_FACTORIES );
+ sPath += sCurrentFactory;
+ try
+ {
+ ConfigurationHelper::writeRelativeKey(
+ xConfiguration, sPath, KEY_HELP_ON_OPEN, makeAny( bChecked ) );
+ ConfigurationHelper::flush( xConfiguration );
+ }
+ catch( Exception& )
+ {
+ DBG_ERRORFILE( "SfxHelpTextWindow_Impl::CheckHdl(): unexpected exception" );
+ }
+ }
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::Resize()
+{
+ Size aSize = GetOutputSizePixel();
+ long nToolBoxHeight = aToolBox.GetSizePixel().Height() + TOOLBOX_OFFSET;
+ aSize.Height() -= nToolBoxHeight;
+ pTextWin->SetPosSizePixel( Point( 0, nToolBoxHeight ), aSize );
+ SetOnStartupBoxPosition();
+}
+
+// -----------------------------------------------------------------------
+
+long SfxHelpTextWindow_Impl::PreNotify( NotifyEvent& rNEvt )
+{
+ long nDone = 0;
+ USHORT nType = rNEvt.GetType();
+ if ( EVENT_COMMAND == nType && rNEvt.GetCommandEvent() )
+ {
+ const CommandEvent* pCmdEvt = rNEvt.GetCommandEvent();
+ Window* pCmdWin = rNEvt.GetWindow();
+
+ if ( pCmdEvt->GetCommand() == COMMAND_CONTEXTMENU && pCmdWin != this && pCmdWin != &aToolBox )
+ {
+ sal_Bool bHiContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
+ Point aPos;
+ if ( pCmdEvt->IsMouseEvent() )
+ aPos = pCmdEvt->GetMousePosPixel();
+ else
+ aPos = Point( pTextWin->GetPosPixel().X() + 20, 20 );
+ aPos.Y() += pTextWin->GetPosPixel().Y();
+ PopupMenu aMenu;
+ if ( bIsIndexOn )
+ aMenu.InsertItem( TBI_INDEX, aIndexOffText, Image( SfxResId(
+ bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_OFF : IMG_HELP_TOOLBOX_INDEX_OFF ) ) );
+ else
+ aMenu.InsertItem( TBI_INDEX, aIndexOnText, Image( SfxResId(
+ bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_ON : IMG_HELP_TOOLBOX_INDEX_ON ) ) );
+ aMenu.SetHelpId( TBI_INDEX, HID_HELP_TOOLBOXITEM_INDEX );
+ aMenu.InsertSeparator();
+ aMenu.InsertItem( TBI_BACKWARD, String( SfxResId( STR_HELP_BUTTON_PREV ) ),
+ Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_PREV : IMG_HELP_TOOLBOX_PREV ) ) );
+ aMenu.SetHelpId( TBI_BACKWARD, HID_HELP_TOOLBOXITEM_BACKWARD );
+ aMenu.EnableItem( TBI_BACKWARD, pHelpWin->HasHistoryPredecessor() );
+ aMenu.InsertItem( TBI_FORWARD, String( SfxResId( STR_HELP_BUTTON_NEXT ) ),
+ Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_NEXT : IMG_HELP_TOOLBOX_NEXT ) ) );
+ aMenu.SetHelpId( TBI_FORWARD, HID_HELP_TOOLBOXITEM_FORWARD );
+ aMenu.EnableItem( TBI_FORWARD, pHelpWin->HasHistorySuccessor() );
+ aMenu.InsertItem( TBI_START, String( SfxResId( STR_HELP_BUTTON_START ) ),
+ Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_START : IMG_HELP_TOOLBOX_START ) ) );
+ aMenu.SetHelpId( TBI_START, HID_HELP_TOOLBOXITEM_START );
+ aMenu.InsertSeparator();
+ aMenu.InsertItem( TBI_PRINT, String( SfxResId( STR_HELP_BUTTON_PRINT ) ),
+ Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_PRINT : IMG_HELP_TOOLBOX_PRINT ) ) );
+ aMenu.SetHelpId( TBI_PRINT, HID_HELP_TOOLBOXITEM_PRINT );
+ aMenu.InsertItem( TBI_BOOKMARKS, String( SfxResId( STR_HELP_BUTTON_ADDBOOKMARK ) ),
+ Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_BOOKMARKS : IMG_HELP_TOOLBOX_BOOKMARKS ) ) );
+ aMenu.SetHelpId( TBI_BOOKMARKS, HID_HELP_TOOLBOXITEM_BOOKMARKS );
+ aMenu.InsertItem( TBI_SEARCHDIALOG, String( SfxResId( STR_HELP_BUTTON_SEARCHDIALOG ) ),
+ Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_SEARCHDIALOG : IMG_HELP_TOOLBOX_SEARCHDIALOG ) ) );
+ aMenu.SetHelpId( TBI_SEARCHDIALOG, HID_HELP_TOOLBOXITEM_SEARCHDIALOG );
+ aMenu.InsertSeparator();
+ aMenu.InsertItem( TBI_SELECTIONMODE, String( SfxResId( STR_HELP_MENU_TEXT_SELECTION_MODE ) ) );
+ aMenu.SetHelpId( TBI_SELECTIONMODE, HID_HELP_TEXT_SELECTION_MODE );
+ Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
+ URL aURL;
+ aURL.Complete = DEFINE_CONST_UNICODE(".uno:SelectTextMode");
+ PARSE_URL( aURL );
+ Reference < XDispatch > xDisp = xProv.is() ?
+ xProv->queryDispatch( aURL, rtl::OUString(), 0 ) : Reference < XDispatch >();
+ if(xDisp.is())
+ {
+ HelpStatusListener_Impl* pStateListener;
+ Reference<XStatusListener>xStateListener = pStateListener =
+ new HelpStatusListener_Impl(xDisp, aURL );
+ FeatureStateEvent rEvent = pStateListener->GetStateEvent();
+ sal_Bool bCheck = sal_False;
+ rEvent.State >>= bCheck;
+ aMenu.CheckItem(TBI_SELECTIONMODE, bCheck);
+ }
+ aMenu.InsertSeparator();
+ aMenu.InsertItem( TBI_COPY, String( SfxResId( STR_HELP_MENU_TEXT_COPY ) ),
+ Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_COPY : IMG_HELP_TOOLBOX_COPY ) ) );
+ aMenu.SetHelpId( TBI_COPY, ".uno:Copy" );
+ aMenu.EnableItem( TBI_COPY, HasSelection() );
+
+ if ( bIsDebug )
+ {
+ aMenu.InsertSeparator();
+ aMenu.InsertItem( TBI_SOURCEVIEW, String( SfxResId( STR_HELP_BUTTON_SOURCEVIEW ) ) );
+ }
+
+ if( SvtMenuOptions().IsEntryHidingEnabled() == sal_False )
+ aMenu.SetMenuFlags( aMenu.GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES );
+
+ USHORT nId = aMenu.Execute( this, aPos );
+ pHelpWin->DoAction( nId );
+ nDone = 1;
+ }
+ }
+ else if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
+ {
+ const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
+ const KeyCode& rKeyCode = pKEvt->GetKeyCode();
+ USHORT nKeyGroup = rKeyCode.GetGroup();
+ USHORT nKey = rKeyCode.GetCode();
+ if ( KEYGROUP_ALPHA == nKeyGroup && !isHandledKey( rKeyCode ) )
+ {
+ // do nothing disables the writer accelerators
+ nDone = 1;
+ }
+ else if ( rKeyCode.IsMod1() && ( KEY_F4 == nKey || KEY_W == nKey ) )
+ {
+ // <STRG><F4> or <STRG><W> -> close top frame
+ pHelpWin->CloseWindow();
+ nDone = 1;
+ }
+ else if ( KEY_TAB == nKey && aOnStartupCB.HasChildPathFocus() )
+ {
+ aToolBox.GrabFocus();
+ nDone = 1;
+ }
+ }
+
+ return nDone ? nDone : Window::PreNotify( rNEvt );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::GetFocus()
+{
+ if ( !bIsInClose )
+ {
+ try
+ {
+ if( xFrame.is() )
+ {
+ Reference< ::com::sun::star::awt::XWindow > xWindow = xFrame->getComponentWindow();
+ if( xWindow.is() )
+ xWindow->setFocus();
+ }
+ }
+ catch( Exception& )
+ {
+ DBG_ERRORFILE( "SfxHelpTextWindow_Impl::GetFocus(): unexpected exception" );
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
+{
+ Window::DataChanged( rDCEvt );
+
+ if ( ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
+ ( rDCEvt.GetType() == DATACHANGED_DISPLAY ) ) &&
+ ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
+ {
+ SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
+ InitToolBoxImages();
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::ToggleIndex( sal_Bool bOn )
+{
+ bIsIndexOn = bOn;
+ if ( bIsIndexOn )
+ {
+ aToolBox.SetItemImage( TBI_INDEX, aIndexOffImage );
+ aToolBox.SetItemText( TBI_INDEX, aIndexOffText );
+ }
+ else
+ {
+ aToolBox.SetItemImage( TBI_INDEX, aIndexOnImage );
+ aToolBox.SetItemText( TBI_INDEX, aIndexOnText );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::SelectSearchText( const String& rSearchText, sal_Bool _bIsFullWordSearch )
+{
+ aSearchText = rSearchText;
+ bIsFullWordSearch = _bIsFullWordSearch;
+ aSelectTimer.Start();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::SetPageStyleHeaderOff() const
+{
+#ifdef DBG_UTIL
+ sal_Bool bSetOff = sal_False;
+#endif
+ // set off the pagestyle header to prevent print output of the help URL
+ try
+ {
+ Reference < XController > xController = xFrame->getController();
+ Reference < XSelectionSupplier > xSelSup( xController, UNO_QUERY );
+ if ( xSelSup.is() )
+ {
+ Reference < XIndexAccess > xSelection;
+ if ( xSelSup->getSelection() >>= xSelection )
+ {
+ Reference < XTextRange > xRange;
+ if ( xSelection->getByIndex(0) >>= xRange )
+ {
+ Reference < XText > xText = xRange->getText();
+ Reference < XPropertySet > xProps( xText->createTextCursorByRange( xRange ), UNO_QUERY );
+ ::rtl::OUString sStyleName;
+ if ( xProps->getPropertyValue( DEFINE_CONST_OUSTRING("PageStyleName") ) >>= sStyleName )
+ {
+ Reference < XStyleFamiliesSupplier > xStyles( xController->getModel(), UNO_QUERY );
+ Reference < XNameContainer > xContainer;
+ if ( xStyles->getStyleFamilies()->getByName( DEFINE_CONST_OUSTRING("PageStyles") )
+ >>= xContainer )
+ {
+ Reference < XStyle > xStyle;
+ if ( xContainer->getByName( sStyleName ) >>= xStyle )
+ {
+ Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
+ xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("HeaderIsOn"),
+ makeAny( sal_Bool( sal_False ) ) );
+
+ Reference< XModifiable > xReset(xStyles, UNO_QUERY);
+ xReset->setModified(sal_False);
+#ifdef DBG_UTIL
+ bSetOff = sal_True;
+#endif
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ catch( Exception& )
+ {
+ DBG_ERRORFILE( "SfxHelpTextWindow_Impl::SetPageStyleHeaderOff(): unexpected exception" );
+ }
+
+#ifdef DBG_UTIL
+ if ( !bSetOff )
+ {
+ DBG_ERRORFILE( "SfxHelpTextWindow_Impl::SetPageStyleHeaderOff(): set off failed" );
+ }
+#endif
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::CloseFrame()
+{
+ bIsInClose = sal_True;
+ try
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > xCloseable ( xFrame, ::com::sun::star::uno::UNO_QUERY );
+ if (xCloseable.is())
+ xCloseable->close(sal_True);
+ }
+ catch( ::com::sun::star::util::CloseVetoException& )
+ {
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpTextWindow_Impl::DoSearch()
+{
+ if ( !pSrchDlg )
+ {
+ // create the search dialog
+ pSrchDlg = new sfx2::SearchDialog( pTextWin, DEFINE_CONST_UNICODE("HelpSearchDialog") );
+ // set handler
+ pSrchDlg->SetFindHdl( LINK( this, SfxHelpTextWindow_Impl, FindHdl ) );
+ pSrchDlg->SetCloseHdl( LINK( this, SfxHelpTextWindow_Impl, CloseHdl ) );
+ // get selected text of the help page to set it as the search text
+ Reference< XTextRange > xCursor = getCursor();
+ if ( xCursor.is() )
+ {
+ String sText = xCursor->getString();
+ if ( sText.Len() > 0 )
+ pSrchDlg->SetSearchText( sText );
+ }
+ pSrchDlg->Show();
+ }
+}
+
+// class SfxHelpWindow_Impl ----------------------------------------------
+
+void SfxHelpWindow_Impl::Resize()
+{
+ SplitWindow::Resize();
+ InitSizes();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::Split()
+{
+ static long nMinSplitSize = 5;
+ static long nMaxSplitSize = 99 - nMinSplitSize;
+
+ SplitWindow::Split();
+
+ nIndexSize = GetItemSize( INDEXWIN_ID );
+ nTextSize = GetItemSize( TEXTWIN_ID );
+
+ BOOL bMod = FALSE;
+ if( nIndexSize < nMinSplitSize )
+ {
+ nIndexSize = nMinSplitSize;
+ nTextSize = nMaxSplitSize;
+
+ bMod = TRUE;
+ }
+ else if( nTextSize < nMinSplitSize )
+ {
+ nTextSize = nMinSplitSize;
+ nIndexSize = nMaxSplitSize;
+
+ bMod = TRUE;
+ }
+ else
+ bMod = FALSE;
+
+ if( bMod )
+ {
+ SetItemSize( INDEXWIN_ID, nIndexSize );
+ SetItemSize( TEXTWIN_ID, nTextSize );
+ }
+
+ InitSizes();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::GetFocus()
+{
+ pTextWin->GrabFocus();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::MakeLayout()
+{
+ if ( nHeight > 0 && xWindow.is() )
+ {
+ Window* pScreenWin = VCLUnoHelper::GetWindow( xWindow );
+
+ /* #i55528#
+ Hide() / Show() will produce starnge effects.
+ The returned size (used later to be written back into the configuration)
+ isnt the right after a resize during the window is hidden.
+ If this resize is done if the window is visible evyrthing works as aspected.
+ Some VCL-patches could not solve this problem so I've established the
+ workaround: resize the help window if it's visible .-)
+ */
+// pScreenWin->Hide();
+
+ ::com::sun::star::awt::Rectangle aRect = xWindow->getPosSize();
+ sal_Int32 nOldWidth = bIndex ? nCollapseWidth : nExpandWidth;
+ sal_Int32 nWidth = bIndex ? nExpandWidth : nCollapseWidth;
+ xWindow->setPosSize( aRect.X, aRect.Y, nWidth, nHeight, ::com::sun::star::awt::PosSize::SIZE );
+
+ if ( aRect.Width > 0 && aRect.Height > 0 )
+ {
+ Rectangle aScreenRect = pScreenWin->GetClientWindowExtentsRelative( NULL );
+ Point aNewPos = aScreenRect.TopLeft();
+ sal_Int32 nDiffWidth = nOldWidth - nWidth;
+ aNewPos.X() += nDiffWidth;
+ pScreenWin->SetPosPixel( aNewPos );
+ }
+ else if ( aWinPos.X() > 0 && aWinPos.Y() > 0 )
+ pScreenWin->SetPosPixel( aWinPos );
+
+// pScreenWin->Show();
+ }
+
+ Clear();
+
+ if ( bIndex )
+ {
+ pIndexWin->Show();
+ InsertItem( COLSET_ID, 100, SPLITWINDOW_APPEND, SPLITSET_ID, SWIB_PERCENTSIZE | SWIB_COLSET );
+ InsertItem( INDEXWIN_ID, pIndexWin, nIndexSize, SPLITWINDOW_APPEND, COLSET_ID, SWIB_PERCENTSIZE );
+ InsertItem( TEXTWIN_ID, pTextWin, nTextSize, SPLITWINDOW_APPEND, COLSET_ID, SWIB_PERCENTSIZE );
+ }
+ else
+ {
+ pIndexWin->Hide();
+ InsertItem( COLSET_ID, 100, SPLITWINDOW_APPEND, SPLITSET_ID, SWIB_PERCENTSIZE | SWIB_COLSET );
+ InsertItem( TEXTWIN_ID, pTextWin, 100, SPLITWINDOW_APPEND, 1, SWIB_PERCENTSIZE );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::InitSizes()
+{
+ if ( xWindow.is() )
+ {
+ ::com::sun::star::awt::Rectangle aRect = xWindow->getPosSize();
+ nHeight = aRect.Height;
+
+ if ( bIndex )
+ {
+ nExpandWidth = aRect.Width;
+ nCollapseWidth = nExpandWidth * nTextSize / 100;
+ }
+ else
+ {
+ nCollapseWidth = aRect.Width;
+ nExpandWidth = nCollapseWidth * 100 / nTextSize;
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::LoadConfig()
+{
+ SvtViewOptions aViewOpt( E_WINDOW, CONFIGNAME_HELPWIN );
+ if ( aViewOpt.Exists() )
+ {
+ bIndex = aViewOpt.IsVisible();
+ String aUserData;
+ Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
+ rtl::OUString aTemp;
+ if ( aUserItem >>= aTemp )
+ {
+ aUserData = String( aTemp );
+ DBG_ASSERT( aUserData.GetTokenCount() == 6, "invalid user data" );
+ USHORT nIdx = 0;
+ nIndexSize = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
+ nTextSize = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
+ sal_Int32 nWidth = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
+ nHeight = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
+ aWinPos.X() = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
+ aWinPos.Y() = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
+ if ( bIndex )
+ {
+ nExpandWidth = nWidth;
+ nCollapseWidth = nExpandWidth * nTextSize / 100;
+ }
+ else
+ {
+ nCollapseWidth = nWidth;
+ nExpandWidth = nCollapseWidth * 100 / nTextSize;
+ }
+ }
+
+ pTextWin->ToggleIndex( bIndex );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::SaveConfig()
+{
+ SvtViewOptions aViewOpt( E_WINDOW, CONFIGNAME_HELPWIN );
+ sal_Int32 nW = 0, nH = 0;
+
+ if ( xWindow.is() )
+ {
+ ::com::sun::star::awt::Rectangle aRect = xWindow->getPosSize();
+ nW = aRect.Width;
+ nH = aRect.Height;
+ }
+
+ aViewOpt.SetVisible( bIndex );
+ String aUserData = String::CreateFromInt32( nIndexSize );
+ aUserData += ';';
+ aUserData += String::CreateFromInt32( nTextSize );
+ aUserData += ';';
+ aUserData += String::CreateFromInt32( nW );
+ aUserData += ';';
+ aUserData += String::CreateFromInt32( nH );
+
+ Window* pScreenWin = VCLUnoHelper::GetWindow( xWindow );
+ aWinPos = pScreenWin->GetWindowExtentsRelative( NULL ).TopLeft();
+ aUserData += ';';
+ aUserData += String::CreateFromInt32( aWinPos.X() );
+ aUserData += ';';
+ aUserData += String::CreateFromInt32( aWinPos.Y() );
+
+ aViewOpt.SetUserItem( USERITEM_NAME, makeAny( rtl::OUString( aUserData ) ) );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::ShowStartPage()
+{
+ ::rtl::OUString sHelpURL = SfxHelpWindow_Impl::buildHelpURL(pIndexWin->GetFactory(),
+ DEFINE_CONST_UNICODE("/start"),
+ ::rtl::OUString(),
+ sal_True);
+ loadHelpContent(sHelpURL);
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpWindow_Impl, SelectHdl, ToolBox* , pToolBox )
+{
+ if ( pToolBox )
+ {
+ bGrabFocusToToolBox = pToolBox->HasChildPathFocus();
+ DoAction( pToolBox->GetCurItemId() );
+ }
+
+ return 1;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpWindow_Impl, OpenHdl, SfxHelpIndexWindow_Impl* , EMPTYARG )
+{
+ pIndexWin->SelectExecutableEntry();
+ String aEntry = pIndexWin->GetSelectEntry();
+
+ if ( aEntry.Len() < 1 )
+ return 0;
+
+ ::rtl::OUString sHelpURL;
+
+// INetURLObject aObj(aEntry);
+// BOOL bComplete = ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP );
+
+ BOOL bComplete = rtl::OUString(aEntry).toAsciiLowerCase().match(rtl::OUString::createFromAscii("vnd.sun.star.help"),0);
+
+ if (bComplete)
+ sHelpURL = ::rtl::OUString(aEntry);
+ else
+ {
+ String aId;
+ String aAnchor = String('#');
+ if ( aEntry.GetTokenCount( '#' ) == 2 )
+ {
+ aId = aEntry.GetToken( 0, '#' );
+ aAnchor += aEntry.GetToken( 1, '#' );
+ }
+ else
+ aId = aEntry;
+
+ aEntry = '/';
+ aEntry += aId;
+
+ sHelpURL = SfxHelpWindow_Impl::buildHelpURL(pIndexWin->GetFactory(),
+ aEntry,
+ aAnchor,
+ sal_True);
+ }
+
+ loadHelpContent(sHelpURL);
+
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpWindow_Impl, SelectFactoryHdl, SfxHelpIndexWindow_Impl* , pWin )
+{
+ if ( sTitle.Len() == 0 )
+ sTitle = GetParent()->GetText();
+
+ String aNewTitle = sTitle;
+ aNewTitle += DEFINE_CONST_UNICODE(" - ");
+ aNewTitle += pIndexWin->GetActiveFactoryTitle();
+
+ Reference< XTitle > xTitle(xFrame, UNO_QUERY);
+ if (xTitle.is ())
+ xTitle->setTitle (aNewTitle);
+
+ if ( pWin )
+ ShowStartPage();
+ pIndexWin->ClearSearchPage();
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxHelpWindow_Impl, ChangeHdl, HelpListener_Impl*, pListener )
+{
+ SetFactory( pListener->GetFactory() );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::openDone(const ::rtl::OUString& sURL ,
+ sal_Bool bSuccess)
+{
+ INetURLObject aObj( sURL );
+ if ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP )
+ SetFactory( aObj.GetHost() );
+ if ( IsWait() )
+ LeaveWait();
+ if ( bGrabFocusToToolBox )
+ {
+ pTextWin->GetToolBox().GrabFocus();
+ bGrabFocusToToolBox = sal_False;
+ }
+ else
+ pIndexWin->GrabFocusBack();
+ if ( bSuccess )
+ {
+ // set some view settings: "prevent help tips" and "helpid == 68245"
+ try
+ {
+ Reference < XController > xController = pTextWin->getFrame()->getController();
+ if ( xController.is() )
+ {
+ Reference < XViewSettingsSupplier > xSettings( xController, UNO_QUERY );
+ Reference < XPropertySet > xViewProps = xSettings->getViewSettings();
+ Reference< XPropertySetInfo > xInfo = xViewProps->getPropertySetInfo();
+ Any aBoolAny = makeAny( sal_Bool( sal_True ) );
+ xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("PreventHelpTips"), aBoolAny );
+ xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("ShowGraphics"), aBoolAny );
+ xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("ShowTables"), aBoolAny );
+ xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("HelpURL"), makeAny( DEFINE_CONST_OUSTRING("HID:SFX2_HID_HELP_ONHELP") ) );
+ ::rtl::OUString sProperty( DEFINE_CONST_OUSTRING("IsExecuteHyperlinks") );
+ if ( xInfo->hasPropertyByName( sProperty ) )
+ xViewProps->setPropertyValue( sProperty, aBoolAny );
+ xController->restoreViewData(pHelpInterceptor->GetViewData());
+ }
+ }
+ catch( Exception& )
+ {
+ DBG_ERROR( "SfxHelpWindow_Impl::OpenDoneHdl(): unexpected exception" );
+ }
+
+ // When the SearchPage opens the help doc, then select all words, which are equal to its text
+ String sSearchText = TRIM( pIndexWin->GetSearchText() );
+ if ( sSearchText.Len() > 0 )
+ pTextWin->SelectSearchText( sSearchText, pIndexWin->IsFullWordSearch() );
+
+ // no page style header -> this prevents a print output of the URL
+ pTextWin->SetPageStyleHeaderOff();
+ }
+}
+
+// -----------------------------------------------------------------------
+
+SfxHelpWindow_Impl::SfxHelpWindow_Impl(
+ const ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >& rFrame,
+ Window* pParent, WinBits ) :
+
+ SplitWindow( pParent, WB_3DLOOK | WB_NOSPLITDRAW ),
+
+ xFrame ( rFrame ),
+ pIndexWin ( NULL ),
+ pTextWin ( NULL ),
+ pHelpInterceptor ( new HelpInterceptor_Impl() ),
+ pHelpListener ( new HelpListener_Impl( pHelpInterceptor ) ),
+ nExpandWidth ( 0 ),
+ nCollapseWidth ( 0 ),
+ nHeight ( 0 ),
+ nIndexSize ( 40 ),
+ nTextSize ( 60 ),
+ bIndex ( sal_True ),
+ bGrabFocusToToolBox ( sal_False ),
+ aWinPos ( 0, 0 ),
+ sTitle ( pParent->GetText() )
+{
+ SetHelpId( HID_HELP_WINDOW );
+ SetStyle( GetStyle() | WB_DIALOGCONTROL );
+
+ pHelpInterceptor->InitWaiter( this );
+ pIndexWin = new SfxHelpIndexWindow_Impl( this );
+ pIndexWin->SetDoubleClickHdl( LINK( this, SfxHelpWindow_Impl, OpenHdl ) );
+ pIndexWin->SetSelectFactoryHdl( LINK( this, SfxHelpWindow_Impl, SelectFactoryHdl ) );
+ pIndexWin->Show();
+ pTextWin = new SfxHelpTextWindow_Impl( this );
+ Reference < XFramesSupplier > xSup( rFrame, UNO_QUERY );
+ Reference < XFrames > xFrames = xSup->getFrames();
+ xFrames->append( pTextWin->getFrame() );
+ pTextWin->SetSelectHdl( LINK( this, SfxHelpWindow_Impl, SelectHdl ) );
+ pTextWin->Show();
+ pHelpInterceptor->setInterception( pTextWin->getFrame() );
+ pHelpListener->SetChangeHdl( LINK( this, SfxHelpWindow_Impl, ChangeHdl ) );
+ LoadConfig();
+}
+
+// -----------------------------------------------------------------------
+
+SfxHelpWindow_Impl::~SfxHelpWindow_Impl()
+{
+ SaveConfig();
+ Window* pDel = pIndexWin;
+ pIndexWin = NULL;
+ delete pDel;
+
+ pTextWin->CloseFrame();
+ delete pTextWin;
+}
+
+// -----------------------------------------------------------------------
+
+long SfxHelpWindow_Impl::PreNotify( NotifyEvent& rNEvt )
+{
+ sal_Bool bHandled = sal_False;
+ if ( rNEvt.GetType() == EVENT_KEYINPUT )
+ {
+ // Backward == <ALT><LEFT> or <BACKSPACE> Forward == <ALT><RIGHT>
+ const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
+ USHORT nKey = rKeyCode.GetCode();
+ if ( ( rKeyCode.IsMod2() && ( KEY_LEFT == nKey || KEY_RIGHT == nKey ) ) ||
+ ( !rKeyCode.GetModifier() && KEY_BACKSPACE == nKey && !pIndexWin->HasFocusOnEdit() ) )
+ {
+ DoAction( rKeyCode.GetCode() == KEY_RIGHT ? TBI_FORWARD : TBI_BACKWARD );
+ bHandled = sal_True;
+ }
+ else if ( rKeyCode.IsMod1() && ( KEY_F4 == nKey || KEY_W == nKey ) )
+ {
+ // <STRG><F4> or <STRG><W> -> close top frame
+ CloseWindow();
+ bHandled = sal_True;
+ }
+ }
+ return bHandled ? 1 : Window::PreNotify( rNEvt );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::setContainerWindow( Reference < ::com::sun::star::awt::XWindow > xWin )
+{
+ xWindow = xWin;
+ MakeLayout();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::SetFactory( const String& rFactory )
+{
+ pIndexWin->SetFactory( rFactory, sal_True );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::SetHelpURL( const String& rURL )
+{
+ INetURLObject aObj( rURL );
+ if ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP )
+ SetFactory( aObj.GetHost() );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::DoAction( USHORT nActionId )
+{
+ switch ( nActionId )
+ {
+ case TBI_INDEX :
+ {
+ bIndex = !bIndex;
+ MakeLayout();
+ pTextWin->ToggleIndex( bIndex );
+ break;
+ }
+
+ case TBI_START :
+ {
+ ShowStartPage();
+ break;
+ }
+
+ case TBI_BACKWARD :
+ case TBI_FORWARD :
+ {
+ URL aURL;
+ aURL.Complete = DEFINE_CONST_UNICODE(".uno:Backward");
+ if ( TBI_FORWARD == nActionId )
+ aURL.Complete = DEFINE_CONST_UNICODE(".uno:Forward");
+ PARSE_URL( aURL );
+ pHelpInterceptor->dispatch( aURL, Sequence < PropertyValue >() );
+ break;
+ }
+
+ case TBI_SEARCHDIALOG :
+ {
+ pTextWin->DoSearch();
+ break;
+ }
+
+ case TBI_PRINT :
+ case TBI_SOURCEVIEW :
+ case TBI_COPY :
+ case TBI_SELECTIONMODE:
+ {
+ Reference < XDispatchProvider > xProv( pTextWin->getFrame(), UNO_QUERY );
+ if ( xProv.is() )
+ {
+ URL aURL;
+ if ( TBI_PRINT == nActionId )
+ aURL.Complete = DEFINE_CONST_UNICODE(".uno:Print");
+ else if ( TBI_SOURCEVIEW == nActionId )
+ aURL.Complete = DEFINE_CONST_UNICODE(".uno:SourceView");
+ else if ( TBI_COPY == nActionId )
+ aURL.Complete = DEFINE_CONST_UNICODE(".uno:Copy");
+ else if ( TBI_SELECTIONMODE == nActionId )
+ aURL.Complete = DEFINE_CONST_UNICODE(".uno:SelectTextMode");
+ else
+ aURL.Complete = DEFINE_CONST_UNICODE(".uno:SearchDialog");
+ PARSE_URL( aURL );
+ Reference < XDispatch > xDisp = xProv->queryDispatch( aURL, String(), 0 );
+ if ( xDisp.is() )
+ xDisp->dispatch( aURL, Sequence < PropertyValue >() );
+ }
+ break;
+ }
+
+ case TBI_BOOKMARKS :
+ {
+ String aURL = pHelpInterceptor->GetCurrentURL();
+ if ( aURL.Len() > 0 )
+ {
+ try
+ {
+ Content aCnt( aURL, Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
+ ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = aCnt.getProperties();
+ if ( xInfo->hasPropertyByName( PROPERTY_TITLE ) )
+ {
+ ::com::sun::star::uno::Any aAny = aCnt.getPropertyValue( PROPERTY_TITLE );
+ rtl::OUString aValue;
+ if ( aAny >>= aValue )
+ {
+ String aTitle( aValue );
+ SfxAddHelpBookmarkDialog_Impl aDlg( this, sal_False );
+ aDlg.SetTitle( aTitle );
+ if ( aDlg.Execute() == RET_OK )
+ {
+ aTitle = aDlg.GetTitle();
+ pIndexWin->AddBookmarks( aTitle, aURL );
+ }
+ }
+ }
+ }
+ catch( Exception& )
+ {
+ DBG_ERROR( "SfxHelpWindow_Impl::DoAction(): unexpected exception" );
+ }
+ }
+ break;
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::CloseWindow()
+{
+ try
+ {
+ // search for top frame
+ Reference< XFramesSupplier > xCreator = getTextFrame()->getCreator();
+ while ( xCreator.is() && !xCreator->isTop() )
+ {
+ xCreator = xCreator->getCreator();
+ }
+
+ // when found, close it
+ if ( xCreator.is() && xCreator->isTop() )
+ {
+ Reference < XCloseable > xCloser( xCreator, UNO_QUERY );
+ if ( xCloser.is() )
+ xCloser->close( sal_False );
+ }
+ }
+ catch( Exception& )
+ {
+ DBG_ERRORFILE( "SfxHelpWindow_Impl::CloseWindow(): caught an exception" );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxHelpWindow_Impl::UpdateToolbox()
+{
+ pTextWin->GetToolBox().EnableItem( TBI_BACKWARD, pHelpInterceptor->HasHistoryPred() );
+ pTextWin->GetToolBox().EnableItem( TBI_FORWARD, pHelpInterceptor->HasHistorySucc() );
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxHelpWindow_Impl::HasHistoryPredecessor() const
+{
+ return pHelpInterceptor->HasHistoryPred();
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxHelpWindow_Impl::HasHistorySuccessor() const
+{
+ return pHelpInterceptor->HasHistorySucc();
+}
+
+// class SfxAddHelpBookmarkDialog_Impl -----------------------------------
+
+SfxAddHelpBookmarkDialog_Impl::SfxAddHelpBookmarkDialog_Impl( Window* pParent, sal_Bool bRename ) :
+
+ ModalDialog( pParent, SfxResId( DLG_HELP_ADDBOOKMARK ) ),
+
+ aTitleFT ( this, SfxResId( FT_BOOKMARK_TITLE ) ),
+ aTitleED ( this, SfxResId( ED_BOOKMARK_TITLE ) ),
+ aOKBtn ( this, SfxResId( PB_BOOKMARK_OK ) ),
+ aEscBtn ( this, SfxResId( PB_BOOKMARK_CANCEL ) ),
+ aHelpBtn ( this, SfxResId( PB_BOOKMARK_HELP ) )
+
+{
+ if ( bRename )
+ SetText( String( SfxResId( STR_BOOKMARK_RENAME ) ) );
+
+ FreeResource();
+}
+
+// -----------------------------------------------------------------------
+
+SfxAddHelpBookmarkDialog_Impl::~SfxAddHelpBookmarkDialog_Impl()
+{
+}
+
+// -----------------------------------------------------------------------
+
+void SfxAddHelpBookmarkDialog_Impl::SetTitle( const String& rTitle )
+{
+ aTitleED.SetText( rTitle );
+ aTitleED.SetSelection( Selection( 0, rTitle.Len() ) );
+}
+
diff --git a/sfx2/source/appl/newhelp.hrc b/sfx2/source/appl/newhelp.hrc
new file mode 100644
index 000000000000..7bb9aa85678c
--- /dev/null
+++ b/sfx2/source/appl/newhelp.hrc
@@ -0,0 +1,84 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_NEWHELP_HRC
+#define _SFX_NEWHELP_HRC
+
+// #defines *****************************************************************
+
+// Index Window
+#define LB_ACTIVE 10
+#define FL_ACTIVE 11
+#define TC_INDEX 12
+
+// Index TabPage
+#define FT_EXPRESSION 10
+#define CB_INDEX 11
+#define PB_OPEN_INDEX 12
+
+// Search TabPage
+#define FT_SEARCH 10
+#define ED_SEARCH 11
+#define PB_SEARCH 12
+#define FT_RESULT 13
+#define CB_FULLWORDS 14
+#define CB_SCOPE 15
+#define LB_RESULT 16
+#define PB_OPEN_SEARCH 17
+
+// Bookmarks TabPage
+#define FT_BOOKMARKS 10
+#define LB_BOOKMARKS 11
+#define PB_BOOKMARKS 12
+
+// Content TabPage
+#define LB_CONTENTS 10
+
+// Add to bookmarks dialog
+#define FT_BOOKMARK_TITLE 10
+#define ED_BOOKMARK_TITLE 11
+#define PB_BOOKMARK_OK 12
+#define PB_BOOKMARK_CANCEL 13
+#define PB_BOOKMARK_HELP 14
+#define STR_BOOKMARK_RENAME 15
+
+// Index Window: Id's of the tabpages
+#define HELP_INDEX_PAGE_FIRST 1
+#define HELP_INDEX_PAGE_CONTENTS HELP_INDEX_PAGE_FIRST
+#define HELP_INDEX_PAGE_INDEX 2
+#define HELP_INDEX_PAGE_SEARCH 3
+#define HELP_INDEX_PAGE_BOOKMARKS 4
+#define HELP_INDEX_PAGE_LAST HELP_INDEX_PAGE_BOOKMARKS
+
+// context menu ids
+#define MID_OPEN 1
+#define MID_RENAME 2
+#define MID_DELETE 3
+
+#endif // #ifndef _SFX_NEWHELP_HRC
+
+// ******************************************************************* EOF
+
diff --git a/sfx2/source/appl/newhelp.hxx b/sfx2/source/appl/newhelp.hxx
new file mode 100644
index 000000000000..95a5bfe52230
--- /dev/null
+++ b/sfx2/source/appl/newhelp.hxx
@@ -0,0 +1,614 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef INCLUDED_SFX_NEWHELP_HXX
+#define INCLUDED_SFX_NEWHELP_HXX
+
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/frame/XDispatchResultListener.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+
+namespace com { namespace sun { namespace star { namespace awt { class XWindow; } } } }
+namespace com { namespace sun { namespace star { namespace frame { class XFrame; } } } }
+namespace com { namespace sun { namespace star { namespace i18n { class XBreakIterator; } } } }
+namespace com { namespace sun { namespace star { namespace text { class XTextRange; } } } }
+
+#include <vcl/window.hxx>
+#include <vcl/toolbox.hxx>
+#include <vcl/tabpage.hxx>
+#include <vcl/splitwin.hxx>
+#include <vcl/tabctrl.hxx>
+#include <vcl/combobox.hxx>
+#include <vcl/fixed.hxx>
+#include <vcl/button.hxx>
+#include <vcl/lstbox.hxx>
+#include <vcl/dialog.hxx>
+#include <svtools/svtreebx.hxx>
+#include <unotools/moduleoptions.hxx>
+
+#include "srchdlg.hxx"
+
+// class OpenStatusListener_Impl -----------------------------------------
+
+class OpenStatusListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XDispatchResultListener >
+{
+private:
+ sal_Bool m_bFinished;
+ sal_Bool m_bSuccess;
+ Link m_aOpenLink;
+ String m_sURL;
+
+public:
+ OpenStatusListener_Impl() : m_bFinished( FALSE ), m_bSuccess( FALSE ) {}
+
+ virtual void SAL_CALL dispatchFinished( const ::com::sun::star::frame::DispatchResultEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
+
+ inline sal_Bool IsFinished() const { return m_bFinished; }
+ inline sal_Bool IsSuccessful() const { return m_bSuccess; }
+ inline void SetURL( const String& rURL ) { m_sURL = rURL; }
+ inline String GetURL() const { return m_sURL; }
+ inline void SetOpenHdl( const Link& rLink ) { m_aOpenLink = rLink; }
+};
+
+// ContentListBox_Impl ---------------------------------------------------
+
+class ContentListBox_Impl : public SvTreeListBox
+{
+private:
+ Image aOpenBookImage;
+ Image aClosedBookImage;
+ Image aDocumentImage;
+
+ void InitRoot();
+ void ClearChildren( SvLBoxEntry* pParent );
+
+public:
+ ContentListBox_Impl( Window* pParent, const ResId& rResId );
+ ~ContentListBox_Impl();
+
+
+ virtual void RequestingChilds( SvLBoxEntry* pParent );
+ virtual long Notify( NotifyEvent& rNEvt );
+
+ inline void SetOpenHdl( const Link& rLink ) { SetDoubleClickHdl( rLink ); }
+ String GetSelectEntry() const;
+};
+
+// class HelpTabPage_Impl ------------------------------------------------
+
+class SfxHelpIndexWindow_Impl;
+
+class HelpTabPage_Impl : public TabPage
+{
+protected:
+ SfxHelpIndexWindow_Impl* m_pIdxWin;
+
+public:
+ HelpTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin, const ResId& rResId );
+
+ virtual Control* GetLastFocusControl() = 0;
+};
+
+// class ContentTabPage_Impl ---------------------------------------------
+
+class ContentTabPage_Impl : public HelpTabPage_Impl
+{
+private:
+ ContentListBox_Impl aContentBox;
+
+public:
+ ContentTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin );
+
+ virtual void Resize();
+ virtual void ActivatePage();
+ virtual Control* GetLastFocusControl();
+
+ inline void SetOpenHdl( const Link& rLink ) { aContentBox.SetOpenHdl( rLink ); }
+ inline String GetSelectEntry() const { return aContentBox.GetSelectEntry(); }
+ inline void SetFocusOnBox() { aContentBox.GrabFocus(); }
+};
+
+// class IndexTabPage_Impl -----------------------------------------------
+
+class IndexBox_Impl : public ComboBox
+{
+public:
+ IndexBox_Impl( Window* pParent, const ResId& rResId );
+
+ virtual void UserDraw( const UserDrawEvent& rUDEvt );
+ virtual long Notify( NotifyEvent& rNEvt );
+
+ void SelectExecutableEntry();
+};
+
+class IndexTabPage_Impl : public HelpTabPage_Impl
+{
+private:
+ FixedText aExpressionFT;
+ IndexBox_Impl aIndexCB;
+ PushButton aOpenBtn;
+
+ Timer aFactoryTimer;
+ Timer aKeywordTimer;
+ Link aKeywordLink;
+
+ String sFactory;
+ String sKeyword;
+
+ long nMinWidth;
+ sal_Bool bIsActivated;
+
+ void InitializeIndex();
+ void ClearIndex();
+
+ DECL_LINK( OpenHdl, PushButton* );
+ DECL_LINK( TimeoutHdl, Timer* );
+
+public:
+ IndexTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin );
+ ~IndexTabPage_Impl();
+
+ virtual void Resize();
+ virtual void ActivatePage();
+ virtual Control* GetLastFocusControl();
+
+ void SetDoubleClickHdl( const Link& rLink );
+ void SetFactory( const String& rFactory );
+ inline String GetFactory() const { return sFactory; }
+ String GetSelectEntry() const;
+ inline void SetFocusOnBox() { aIndexCB.GrabFocus(); }
+ inline sal_Bool HasFocusOnEdit() const { return aIndexCB.HasChildPathFocus(); }
+
+ inline void SetKeywordHdl( const Link& rLink ) { aKeywordLink = rLink; }
+ void SetKeyword( const String& rKeyword );
+ sal_Bool HasKeyword() const;
+ sal_Bool HasKeywordIgnoreCase(); //added by BerryJia for fixing Bug98251, 2002-12-11
+ void OpenKeyword();
+
+ inline void SelectExecutableEntry() { aIndexCB.SelectExecutableEntry(); }
+};
+
+// class SearchTabPage_Impl ----------------------------------------------
+
+class SearchBox_Impl : public ComboBox
+{
+private:
+ Link aSearchLink;
+
+public:
+ SearchBox_Impl( Window* pParent, const ResId& rResId ) :
+ ComboBox( pParent, rResId ) { SetDropDownLineCount( 5 ); }
+
+ virtual long PreNotify( NotifyEvent& rNEvt );
+ virtual void Select();
+
+ inline void SetSearchLink( const Link& rLink ) { aSearchLink = rLink; }
+};
+
+class SearchResultsBox_Impl : public ListBox
+{
+public:
+ SearchResultsBox_Impl( Window* pParent, const ResId& rResId ) : ListBox( pParent, rResId ) {}
+
+ virtual long Notify( NotifyEvent& rNEvt );
+};
+
+class SearchTabPage_Impl : public HelpTabPage_Impl
+{
+private:
+ FixedText aSearchFT;
+ SearchBox_Impl aSearchED;
+ PushButton aSearchBtn;
+ CheckBox aFullWordsCB;
+ CheckBox aScopeCB;
+ SearchResultsBox_Impl aResultsLB;
+ PushButton aOpenBtn;
+
+ Size aMinSize;
+ String aFactory;
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >
+ xBreakIterator;
+
+ void ClearSearchResults();
+ void RememberSearchText( const String& rSearchText );
+
+ DECL_LINK( SearchHdl, PushButton* );
+ DECL_LINK( OpenHdl, PushButton* );
+ DECL_LINK( ModifyHdl, Edit* );
+
+public:
+ SearchTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin );
+ ~SearchTabPage_Impl();
+
+ virtual void Resize();
+ virtual void ActivatePage();
+ virtual Control* GetLastFocusControl();
+
+ void SetDoubleClickHdl( const Link& rLink );
+ inline void SetFactory( const String& rFactory ) { aFactory = rFactory; }
+ String GetSelectEntry() const;
+ void ClearPage();
+ inline void SetFocusOnBox() { aResultsLB.GrabFocus(); }
+ inline sal_Bool HasFocusOnEdit() const { return aSearchED.HasChildPathFocus(); }
+ inline String GetSearchText() const { return aSearchED.GetText(); }
+ inline sal_Bool IsFullWordSearch() const { return aFullWordsCB.IsChecked(); }
+ sal_Bool OpenKeyword( const String& rKeyword );
+};
+
+// class BookmarksTabPage_Impl -------------------------------------------
+
+class BookmarksBox_Impl : public ListBox
+{
+private:
+ void DoAction( USHORT nAction );
+
+public:
+ BookmarksBox_Impl( Window* pParent, const ResId& rResId );
+ ~BookmarksBox_Impl();
+
+ virtual long Notify( NotifyEvent& rNEvt );
+};
+
+class BookmarksTabPage_Impl : public HelpTabPage_Impl
+{
+private:
+ FixedText aBookmarksFT;
+ BookmarksBox_Impl aBookmarksBox;
+ PushButton aBookmarksPB;
+
+ long nMinWidth;
+
+ DECL_LINK( OpenHdl, PushButton* );
+
+public:
+ BookmarksTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin );
+
+ virtual void Resize();
+ virtual void ActivatePage();
+ virtual Control* GetLastFocusControl();
+
+ void SetDoubleClickHdl( const Link& rLink );
+ String GetSelectEntry() const;
+ void AddBookmarks( const String& rTitle, const String& rURL );
+ inline void SetFocusOnBox() { aBookmarksBox.GrabFocus(); }
+};
+
+// class SfxHelpIndexWindow_Impl -----------------------------------------
+
+class SfxHelpWindow_Impl;
+
+class SfxHelpIndexWindow_Impl : public Window
+{
+private:
+ ListBox aActiveLB;
+ FixedLine aActiveLine;
+
+ TabControl aTabCtrl;
+ Timer aTimer;
+
+ Link aSelectFactoryLink;
+ Link aPageDoubleClickLink;
+ Link aIndexKeywordLink;
+ String sKeyword;
+
+ SfxHelpWindow_Impl* pParentWin;
+
+ ContentTabPage_Impl* pCPage;
+ IndexTabPage_Impl* pIPage;
+ SearchTabPage_Impl* pSPage;
+ BookmarksTabPage_Impl* pBPage;
+
+ long nMinWidth;
+ bool bWasCursorLeftOrRight;
+ bool bIsInitDone;
+
+ void Initialize();
+ void SetActiveFactory();
+ HelpTabPage_Impl* GetCurrentPage( USHORT& rCurId );
+
+ inline ContentTabPage_Impl* GetContentPage();
+ inline IndexTabPage_Impl* GetIndexPage();
+ inline SearchTabPage_Impl* GetSearchPage();
+ inline BookmarksTabPage_Impl* GetBookmarksPage();
+
+ DECL_LINK( ActivatePageHdl, TabControl* );
+ DECL_LINK( SelectHdl, ListBox* );
+ DECL_LINK( InitHdl, Timer* );
+ DECL_LINK( SelectFactoryHdl, Timer* );
+ DECL_LINK( KeywordHdl, IndexTabPage_Impl* );
+
+public:
+ SfxHelpIndexWindow_Impl( SfxHelpWindow_Impl* pParent );
+ ~SfxHelpIndexWindow_Impl();
+
+ virtual void Resize();
+ virtual long PreNotify( NotifyEvent& rNEvt );
+ virtual void DataChanged( const DataChangedEvent& rDCEvt );
+
+ void SetDoubleClickHdl( const Link& rLink );
+ inline void SetSelectFactoryHdl( const Link& rLink ) { aSelectFactoryLink = rLink; }
+ void SetFactory( const String& rFactory, sal_Bool bActive );
+ inline String GetFactory() const { return pIPage->GetFactory(); }
+ String GetSelectEntry() const;
+ void AddBookmarks( const String& rTitle, const String& rURL );
+ bool IsValidFactory( const String& _rFactory );
+ inline String GetActiveFactoryTitle() const { return aActiveLB.GetSelectEntry(); }
+ inline void UpdateTabControl() { aTabCtrl.Invalidate(); }
+ void ClearSearchPage();
+ void GrabFocusBack();
+ sal_Bool HasFocusOnEdit() const;
+ String GetSearchText() const;
+ sal_Bool IsFullWordSearch() const;
+ void OpenKeyword( const String& rKeyword );
+ void SelectExecutableEntry();
+ inline bool WasCursorLeftOrRight();
+};
+
+// inlines ---------------------------------------------------------------
+
+ContentTabPage_Impl* SfxHelpIndexWindow_Impl::GetContentPage()
+{
+ if ( !pCPage )
+ {
+ pCPage = new ContentTabPage_Impl( &aTabCtrl, this );
+ pCPage->SetOpenHdl( aPageDoubleClickLink );
+ }
+ return pCPage;
+}
+IndexTabPage_Impl* SfxHelpIndexWindow_Impl::GetIndexPage()
+{
+ if ( !pIPage )
+ {
+ pIPage = new IndexTabPage_Impl( &aTabCtrl, this );
+ pIPage->SetDoubleClickHdl( aPageDoubleClickLink );
+ pIPage->SetKeywordHdl( aIndexKeywordLink );
+ }
+ return pIPage;
+}
+
+SearchTabPage_Impl* SfxHelpIndexWindow_Impl::GetSearchPage()
+{
+ if ( !pSPage )
+ {
+ pSPage = new SearchTabPage_Impl( &aTabCtrl, this );
+ pSPage->SetDoubleClickHdl( aPageDoubleClickLink );
+ }
+ return pSPage;
+}
+
+BookmarksTabPage_Impl* SfxHelpIndexWindow_Impl::GetBookmarksPage()
+{
+ if ( !pBPage )
+ {
+ pBPage = new BookmarksTabPage_Impl( &aTabCtrl, this );
+ pBPage->SetDoubleClickHdl( aPageDoubleClickLink );
+ }
+ return pBPage;
+}
+
+bool SfxHelpIndexWindow_Impl::WasCursorLeftOrRight()
+{
+ bool bRet = bWasCursorLeftOrRight;
+ bWasCursorLeftOrRight = false;
+ return bRet;
+}
+
+// class TextWin_Impl ----------------------------------------------------
+
+class TextWin_Impl : public DockingWindow
+{
+public:
+ TextWin_Impl( Window* pParent );
+ virtual ~TextWin_Impl();
+
+ virtual long Notify( NotifyEvent& rNEvt );
+};
+
+// class SfxHelpTextWindow_Impl ------------------------------------------
+
+class SvtMiscOptions;
+class SfxHelpWindow_Impl;
+
+class SfxHelpTextWindow_Impl : public Window
+{
+private:
+ ToolBox aToolBox;
+ CheckBox aOnStartupCB;
+ Timer aSelectTimer;
+ Image aIndexOnImage;
+ Image aIndexOffImage;
+ String aIndexOnText;
+ String aIndexOffText;
+ String aSearchText;
+ String aOnStartupText;
+ ::rtl::OUString sCurrentFactory;
+
+ SfxHelpWindow_Impl* pHelpWin;
+ Window* pTextWin;
+ sfx2::SearchDialog* pSrchDlg;
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >
+ xFrame;
+ ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >
+ xBreakIterator;
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
+ xConfiguration;
+ long nMinPos;
+ sal_Bool bIsDebug;
+ sal_Bool bIsIndexOn;
+ sal_Bool bIsInClose;
+ sal_Bool bIsFullWordSearch;
+
+ sal_Bool HasSelection() const;
+ void InitToolBoxImages();
+ void InitOnStartupBox( bool bOnlyText );
+ void SetOnStartupBoxPosition();
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >
+ GetBreakIterator();
+ ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange >
+ getCursor() const;
+ bool isHandledKey( const KeyCode& _rKeyCode );
+
+ DECL_LINK( SelectHdl, Timer* );
+ DECL_LINK( NotifyHdl, SvtMiscOptions* );
+ DECL_LINK( FindHdl, sfx2::SearchDialog* );
+ DECL_LINK( CloseHdl, sfx2::SearchDialog* );
+ DECL_LINK( CheckHdl, CheckBox* );
+
+public:
+ SfxHelpTextWindow_Impl( SfxHelpWindow_Impl* pParent );
+ ~SfxHelpTextWindow_Impl();
+
+ virtual void Resize();
+ virtual long PreNotify( NotifyEvent& rNEvt );
+ virtual void GetFocus();
+ virtual void DataChanged( const DataChangedEvent& rDCEvt );
+
+ inline ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >
+ getFrame() const { return xFrame; }
+
+ inline void SetSelectHdl( const Link& rLink ) { aToolBox.SetSelectHdl( rLink ); }
+ void ToggleIndex( sal_Bool bOn );
+ void SelectSearchText( const String& rSearchText, sal_Bool _bIsFullWordSearch );
+ void SetPageStyleHeaderOff() const;
+ inline ToolBox& GetToolBox() { return aToolBox; }
+ void CloseFrame();
+ void DoSearch();
+};
+
+// class SfxHelpWindow_Impl ----------------------------------------------
+
+class HelpInterceptor_Impl;
+class HelpListener_Impl;
+class SfxHelpWindow_Impl : public SplitWindow
+{
+private:
+friend class SfxHelpIndexWindow_Impl;
+
+ ::com::sun::star::uno::Reference < ::com::sun::star::awt::XWindow >
+ xWindow;
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchResultListener >
+ xOpenListener;
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >
+ xFrame;
+
+ SfxHelpIndexWindow_Impl* pIndexWin;
+ SfxHelpTextWindow_Impl* pTextWin;
+ HelpInterceptor_Impl* pHelpInterceptor;
+ HelpListener_Impl* pHelpListener;
+
+ sal_Int32 nExpandWidth;
+ sal_Int32 nCollapseWidth;
+ sal_Int32 nHeight;
+ long nIndexSize;
+ long nTextSize;
+ sal_Bool bIndex;
+ sal_Bool bGrabFocusToToolBox;
+ Point aWinPos;
+ String sTitle;
+ String sKeyword;
+
+ virtual void Resize();
+ virtual void Split();
+ virtual void GetFocus();
+
+ void MakeLayout();
+ void InitSizes();
+ void LoadConfig();
+ void SaveConfig();
+ void ShowStartPage();
+
+ DECL_LINK( SelectHdl, ToolBox* );
+ DECL_LINK( OpenHdl, SfxHelpIndexWindow_Impl* );
+ DECL_LINK( SelectFactoryHdl, SfxHelpIndexWindow_Impl* );
+ DECL_LINK( ChangeHdl, HelpListener_Impl* );
+
+public:
+ SfxHelpWindow_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >& rFrame,
+ Window* pParent, WinBits nBits );
+ ~SfxHelpWindow_Impl();
+
+ virtual long PreNotify( NotifyEvent& rNEvt );
+
+ void setContainerWindow(
+ ::com::sun::star::uno::Reference < ::com::sun::star::awt::XWindow > xWin );
+ inline ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >
+ getTextFrame() const { return pTextWin->getFrame(); }
+ inline ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchResultListener >
+ getOpenListener() const { return xOpenListener; }
+
+ void SetFactory( const String& rFactory );
+ void SetHelpURL( const String& rURL );
+ void DoAction( USHORT nActionId );
+ void CloseWindow();
+
+ void UpdateToolbox();
+ inline void OpenKeyword( const String& rKeyword ) { pIndexWin->OpenKeyword( rKeyword ); }
+ inline String GetFactory() const { return pIndexWin->GetFactory(); }
+
+ sal_Bool HasHistoryPredecessor() const; // forward to interceptor
+ sal_Bool HasHistorySuccessor() const; // forward to interceptor
+
+ void openDone(const ::rtl::OUString& sURL ,
+ sal_Bool bSuccess);
+
+ static sal_Bool splitHelpURL(const ::rtl::OUString& sHelpURL,
+ ::rtl::OUString& sFactory,
+ ::rtl::OUString& sContent,
+ ::rtl::OUString& sAnchor );
+
+ static ::rtl::OUString buildHelpURL(const ::rtl::OUString& sFactory ,
+ const ::rtl::OUString& sContent ,
+ const ::rtl::OUString& sAnchor ,
+ sal_Bool bUseQuestionMark);
+
+ void loadHelpContent(const ::rtl::OUString& sHelpURL ,
+ sal_Bool bAddToHistory = sal_True);
+};
+
+class SfxAddHelpBookmarkDialog_Impl : public ModalDialog
+{
+private:
+ FixedText aTitleFT;
+ Edit aTitleED;
+ OKButton aOKBtn;
+ CancelButton aEscBtn;
+ HelpButton aHelpBtn;
+
+public:
+ SfxAddHelpBookmarkDialog_Impl( Window* pParent, sal_Bool bRename = sal_True );
+ ~SfxAddHelpBookmarkDialog_Impl();
+
+ void SetTitle( const String& rTitle );
+ inline String GetTitle() const { return aTitleED.GetText(); }
+};
+
+#endif // #ifndef INCLUDED_SFX_NEWHELP_HXX
+
diff --git a/sfx2/source/appl/newhelp.src b/sfx2/source/appl/newhelp.src
new file mode 100644
index 000000000000..88dfed8ad71e
--- /dev/null
+++ b/sfx2/source/appl/newhelp.src
@@ -0,0 +1,592 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "app.hrc"
+#include "newhelp.hrc"
+#include "helpid.hrc"
+
+Window WIN_HELPINDEX
+{
+ Hide = TRUE ;
+ Size = MAP_APPFONT ( 120 , 200 ) ;
+ DialogControl = TRUE;
+ ListBox LB_ACTIVE
+ {
+ HelpId = HID_HELP_LISTBOX;
+ Border = TRUE ;
+ DropDown = TRUE;
+ Pos = MAP_APPFONT ( 3 , 3 ) ;
+ Size = MAP_APPFONT ( 114 , 40 ) ;
+ };
+ FixedLine FL_ACTIVE
+ {
+ Hide = True;
+ Pos = MAP_APPFONT ( 2, 19 ) ;
+ Size = MAP_APPFONT ( 118 , 1 ) ;
+ };
+ TabControl TC_INDEX
+ {
+ HelpId = HID_HELP_TABCONTROL;
+ Pos = MAP_APPFONT ( 3, 19 ) ;
+ TabStop = TRUE;
+ PageList =
+ {
+ PageItem
+ {
+ Identifier = HELP_INDEX_PAGE_CONTENTS ;
+ Text [ en-US ] = "Contents";
+ };
+ PageItem
+ {
+ Identifier = HELP_INDEX_PAGE_INDEX ;
+ Text [ en-US ] = "Index";
+ };
+ PageItem
+ {
+ Identifier = HELP_INDEX_PAGE_SEARCH ;
+ Text [ en-US ] = "Find";
+ };
+ PageItem
+ {
+ Identifier = HELP_INDEX_PAGE_BOOKMARKS ;
+ Text [ en-US ] = "Bookmarks";
+ };
+ };
+ };
+};
+
+TabPage TP_HELP_INDEX
+{
+ HelpId = HID_HELP_TABPAGE_INDEX;
+ Hide = TRUE ;
+ DialogControl = TRUE;
+ Size = MAP_APPFONT ( 120 , 200 ) ;
+ FixedText FT_EXPRESSION
+ {
+ Pos = MAP_APPFONT ( 6 , 6 ) ;
+ Size = MAP_APPFONT ( 108 , 10 ) ;
+ Text [ en-US ] = "~Search term" ;
+ };
+ ComboBox CB_INDEX
+ {
+ HelpID = "sfx2:ComboBox:TP_HELP_INDEX:CB_INDEX";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 17 ) ;
+ Size = MAP_APPFONT ( 108 , 97 ) ;
+ };
+ PushButton PB_OPEN_INDEX
+ {
+ HelpID = "sfx2:PushButton:TP_HELP_INDEX:PB_OPEN_INDEX";
+ Pos = MAP_APPFONT ( 64 , 115 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~Display" ;
+ };
+};
+
+TabPage TP_HELP_SEARCH
+{
+ HelpId = HID_HELP_TABPAGE_SEARCH;
+ Hide = TRUE ;
+ DialogControl = TRUE;
+ Size = MAP_APPFONT ( 140 , 122 ) ;
+ FixedText FT_SEARCH
+ {
+ Pos = MAP_APPFONT ( 6 , 6 ) ;
+ Size = MAP_APPFONT ( 128 , 10 ) ;
+ Text [ en-US ] = "S~earch term" ;
+ };
+ ComboBox ED_SEARCH
+ {
+ HelpID = "sfx2:ComboBox:TP_HELP_SEARCH:ED_SEARCH";
+ Border = TRUE ;
+ DropDown = TRUE;
+ Pos = MAP_APPFONT ( 6 , 17 ) ;
+ Size = MAP_APPFONT ( 92 , 40 ) ;
+ };
+ PushButton PB_SEARCH
+ {
+ HelpID = "sfx2:PushButton:TP_HELP_SEARCH:PB_SEARCH";
+ Pos = MAP_APPFONT ( 101 , 17 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~Find";
+ };
+ CheckBox CB_FULLWORDS
+ {
+ HelpID = "sfx2:CheckBox:TP_HELP_SEARCH:CB_FULLWORDS";
+ Pos = MAP_APPFONT ( 6, 34 ) ;
+ Size = MAP_APPFONT ( 128 , 10 ) ;
+ Text [ en-US ] = "~Complete words only";
+ };
+ CheckBox CB_SCOPE
+ {
+ HelpID = "sfx2:CheckBox:TP_HELP_SEARCH:CB_SCOPE";
+ Pos = MAP_APPFONT ( 6, 47 ) ;
+ Size = MAP_APPFONT ( 128 , 10 ) ;
+ Text [ en-US ] = "Find in ~headings only";
+ };
+ ListBox LB_RESULT
+ {
+ HelpID = "sfx2:ListBox:TP_HELP_SEARCH:LB_RESULT";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 60 ) ;
+ Size = MAP_APPFONT ( 128 , 30 ) ;
+ };
+ PushButton PB_OPEN_SEARCH
+ {
+ HelpID = "sfx2:PushButton:TP_HELP_SEARCH:PB_OPEN_SEARCH";
+ Pos = MAP_APPFONT ( 84 , 182 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~Display" ;
+ };
+};
+
+TabPage TP_HELP_BOOKMARKS
+{
+ HelpId = HID_HELP_TABPAGE_BOOKMARKS;
+ Hide = TRUE ;
+ DialogControl = TRUE;
+ Size = MAP_APPFONT ( 120 , 200 ) ;
+ FixedText FT_BOOKMARKS
+ {
+ Pos = MAP_APPFONT ( 6 , 6 ) ;
+ Size = MAP_APPFONT ( 108 , 10 ) ;
+ Text [ en-US ] = "~Bookmarks" ;
+ };
+ ListBox LB_BOOKMARKS
+ {
+ HelpID = "sfx2:ListBox:TP_HELP_BOOKMARKS:LB_BOOKMARKS";
+ Border = TRUE ;
+ Sort = TRUE;
+ Pos = MAP_APPFONT ( 6 , 19 ) ;
+ Size = MAP_APPFONT ( 108 , 97 ) ;
+ };
+ PushButton PB_BOOKMARKS
+ {
+ HelpID = "sfx2:PushButton:TP_HELP_BOOKMARKS:PB_BOOKMARKS";
+ Pos = MAP_APPFONT ( 64 , 119 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~Display" ;
+ };
+};
+
+TabPage TP_HELP_CONTENT
+{
+ HelpId = HID_HELP_TABPAGE_CONTENTS;
+ Hide = TRUE ;
+ DialogControl = TRUE;
+ Size = MAP_APPFONT ( 120 , 200 ) ;
+ Control LB_CONTENTS
+ {
+ HelpId = HID_HELP_TREELISTBOX_CONTENTS ;
+ Border = TRUE ;
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 6 , 6 ) ;
+ Size = MAP_APPFONT ( 108 , 188 ) ;
+ };
+};
+
+#define MASKCOLOR_MAGENTA \
+ MaskColor = Color { Red = 0xFFFF ; Green = 0x0000 ; Blue = 0xFFFF ; };
+
+Image IMG_HELP_TOOLBOX_INDEX_ON
+{
+ ImageBitmap = Bitmap { File = "indexon_small.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_INDEX_OFF
+{
+ ImageBitmap = Bitmap { File = "indexoff_small.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_START
+{
+ ImageBitmap = Bitmap { File = "sc06303.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_PREV
+{
+ ImageBitmap = Bitmap { File = "sc06301.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_NEXT
+{
+ ImageBitmap = Bitmap { File = "sc06300.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_PRINT
+{
+ ImageBitmap = Bitmap { File = "sc05504.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_BOOKMARKS
+{
+ ImageBitmap = Bitmap { File = "favourite.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_SEARCHDIALOG
+{
+ ImageBitmap = Bitmap { File = "sc05961.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_COPY
+{
+ ImageBitmap = Bitmap { File = "sc05711.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_CONTENT_BOOK_OPEN
+{
+ ImageBitmap = Bitmap { File = "hlpbookopen.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_CONTENT_BOOK_OPEN_HC
+{
+ ImageBitmap = Bitmap { File = "hlpbookopen_h.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_CONTENT_BOOK_CLOSED
+{
+ ImageBitmap = Bitmap { File = "hlpbookclosed.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_CONTENT_BOOK_CLOSED_HC
+{
+ ImageBitmap = Bitmap { File = "hlpbookclosed_h.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_CONTENT_DOC
+{
+ ImageBitmap = Bitmap { File = "hlpdoc.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_CONTENT_DOC_HC
+{
+ ImageBitmap = Bitmap { File = "hlpdoc_h.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+
+String STR_HELP_WINDOW_TITLE
+{
+ Text [ en-US ] = "%PRODUCTNAME Help";
+};
+String STR_HELP_BUTTON_INDEX_ON
+{
+ Text [ en-US ] = "Show Navigation Pane";
+};
+String STR_HELP_BUTTON_INDEX_OFF
+{
+ Text [ en-US ] = "Hide Navigation Pane";
+};
+String STR_HELP_BUTTON_START
+{
+ Text [ en-US ] = "First Page";
+};
+String STR_HELP_BUTTON_PREV
+{
+ Text [ en-US ] = "Previous Page";
+};
+String STR_HELP_BUTTON_NEXT
+{
+ Text [ en-US ] = "Next Page";
+};
+String STR_HELP_BUTTON_PRINT
+{
+ Text [ en-US ] = "Print...";
+};
+String STR_HELP_BUTTON_ADDBOOKMARK
+{
+ Text [ en-US ] = "Add to Bookmarks...";
+};
+String STR_HELP_BUTTON_SEARCHDIALOG
+{
+ Text [ en-US ] = "Find on this Page...";
+};
+String STR_HELP_BUTTON_SOURCEVIEW
+{
+ Text [ en-US ] = "HTML Source";
+};
+
+String STR_HELP_FIRST_MESSAGE
+{
+ Text [ en-US ] = "The Help is being started...";
+};
+String STR_HELP_FIRST_HTML
+{
+ Text = "<html></head><body><center><br></br><br></br><p><tt>%1</tt></center></body></html>";
+};
+String STR_HELP_MENU_TEXT_SELECTION_MODE
+{
+ Text [ en-US ] = "Select Text";
+};
+String STR_HELP_MENU_TEXT_COPY
+{
+ Text [ en-US ] = "~Copy" ;
+};
+ModalDialog DLG_HELP_ADDBOOKMARK
+{
+ HelpID = "sfx2:ModalDialog:DLG_HELP_ADDBOOKMARK";
+ Size = MAP_APPFONT ( 208 , 43 ) ;
+ Text [ en-US ] = "Add to Bookmarks";
+ MOVEABLE = TRUE ;
+ CLOSEABLE = TRUE ;
+ OUTPUTSIZE = TRUE ;
+ SVLOOK = TRUE ;
+ FixedText FT_BOOKMARK_TITLE
+ {
+ PosSize = MAP_APPFONT ( 6 , 6 , 140 , 10 ) ;
+ Text [ en-US ] = "Bookmark:" ;
+ TABSTOP = FALSE ;
+ GROUP = TRUE ;
+ LEFT = TRUE ;
+ };
+ Edit ED_BOOKMARK_TITLE
+ {
+ HelpID = "sfx2:Edit:DLG_HELP_ADDBOOKMARK:ED_BOOKMARK_TITLE";
+ PosSize = MAP_APPFONT ( 6 , 19 , 140 , 12 ) ;
+ TABSTOP = TRUE ;
+ BORDER = TRUE ;
+ };
+ OKButton PB_BOOKMARK_OK
+ {
+ PosSize = MAP_APPFONT ( 152 , 6 , 50 , 14 ) ;
+ HIDE = FALSE ;
+ TABSTOP = TRUE ;
+ GROUP = TRUE ;
+ Disable = FALSE ;
+ DefButton = TRUE ;
+ };
+ CancelButton PB_BOOKMARK_CANCEL
+ {
+ PosSize = MAP_APPFONT ( 152 , 23 , 50 , 14 ) ;
+ TABSTOP = TRUE ;
+ GROUP = TRUE ;
+ };
+ HelpButton PB_BOOKMARK_HELP
+ {
+ PosSize = MAP_APPFONT ( 152 , 43 , 50 , 14 ) ;
+ TABSTOP = TRUE ;
+ GROUP = TRUE ;
+ Hide = TRUE;
+ };
+ String STR_BOOKMARK_RENAME
+ {
+ Text [ en-US ] = "Rename Bookmark";
+ };
+};
+
+Menu MENU_HELP_BOOKMARKS
+{
+ ItemList =
+ {
+ MenuItem
+ {
+ Identifier = MID_OPEN ;
+ HelpId = HID_HELP_BOOKMARKS_OPEN;
+ Text [ en-US ] = "Display";
+ };
+ MenuItem
+ {
+ Separator = TRUE ;
+ };
+ MenuItem
+ {
+ Identifier = MID_RENAME ;
+ HelpId = HID_HELP_BOOKMARKS_RENAME;
+ Text [ en-US ] = "Rename...";
+ };
+ MenuItem
+ {
+ Identifier = MID_DELETE ;
+ HelpId = HID_HELP_BOOKMARKS_DELETE;
+ Text [ en-US ] = "Delete";
+ };
+ };
+};
+
+InfoBox RID_INFO_NOSEARCHRESULTS
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "No topics found.";
+};
+
+InfoBox RID_INFO_NOSEARCHTEXTFOUND
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "The text you entered was not found.";
+};
+
+Image IMG_HELP_TOOLBOX_HC_INDEX_ON
+{
+ ImageBitmap = Bitmap { File = "indexon_small_h.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HC_INDEX_OFF
+{
+ ImageBitmap = Bitmap { File = "indexoff_small_h.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HC_START
+{
+ ImageBitmap = Bitmap { File = "sch06303.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HC_PREV
+{
+ ImageBitmap = Bitmap { File = "sch06301.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HC_NEXT
+{
+ ImageBitmap = Bitmap { File = "sch06300.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HC_PRINT
+{
+ ImageBitmap = Bitmap { File = "sch05504.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HC_BOOKMARKS
+{
+ ImageBitmap = Bitmap { File = "favourite_h.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HC_SEARCHDIALOG
+{
+ ImageBitmap = Bitmap { File = "sch05961.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HC_COPY
+{
+ ImageBitmap = Bitmap { File = "sch05711.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+
+Image IMG_HELP_TOOLBOX_L_INDEX_ON
+{
+ ImageBitmap = Bitmap { File = "indexon_big.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_L_INDEX_OFF
+{
+ ImageBitmap = Bitmap { File = "indexoff_big.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_L_START
+{
+ ImageBitmap = Bitmap { File = "lc06303.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_L_PREV
+{
+ ImageBitmap = Bitmap { File = "lc06301.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_L_NEXT
+{
+ ImageBitmap = Bitmap { File = "lc06300.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_L_PRINT
+{
+ ImageBitmap = Bitmap { File = "lc05504.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_L_BOOKMARKS
+{
+ ImageBitmap = Bitmap { File = "favourite_big.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_L_SEARCHDIALOG
+{
+ ImageBitmap = Bitmap { File = "lc05961.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_L_COPY
+{
+ ImageBitmap = Bitmap { File = "lc05711.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+
+Image IMG_HELP_TOOLBOX_HCL_INDEX_ON
+{
+ ImageBitmap = Bitmap { File = "indexon_big_h.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HCL_INDEX_OFF
+{
+ ImageBitmap = Bitmap { File = "indexoff_big_h.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HCL_START
+{
+ ImageBitmap = Bitmap { File = "lch06303.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HCL_PREV
+{
+ ImageBitmap = Bitmap { File = "lch06301.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HCL_NEXT
+{
+ ImageBitmap = Bitmap { File = "lch06300.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HCL_PRINT
+{
+ ImageBitmap = Bitmap { File = "lch05504.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HCL_BOOKMARKS
+{
+ ImageBitmap = Bitmap { File = "favourite_big_h.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HCL_SEARCHDIALOG
+{
+ ImageBitmap = Bitmap { File = "lch05961.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+Image IMG_HELP_TOOLBOX_HCL_COPY
+{
+ ImageBitmap = Bitmap { File = "lch05711.bmp" ; };
+ MASKCOLOR_MAGENTA
+};
+
+CheckBox RID_HELP_ONSTARTUP_BOX
+{
+ HelpId = HID_HELP_ONSTARTUP_BOX;
+ Hide = TRUE;
+ TabStop = TRUE;
+ Size = MAP_APPFONT ( 200 , 10 ) ;
+};
+String RID_HELP_ONSTARTUP_TEXT
+{
+ Text [ en-US ] = "~Display %PRODUCTNAME %MODULENAME Help at Startup";
+};
+
diff --git a/sfx2/source/appl/opengrf.cxx b/sfx2/source/appl/opengrf.cxx
new file mode 100644
index 000000000000..328bca2522b5
--- /dev/null
+++ b/sfx2/source/appl/opengrf.cxx
@@ -0,0 +1,292 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <tools/urlobj.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
+#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
+#include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
+#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
+#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
+#include <com/sun/star/ui/dialogs/XFilePreview.hpp>
+#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
+#include <svl/urihelper.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <svtools/transfer.hxx>
+#include <sot/formats.hxx>
+#include <vcl/msgbox.hxx>
+#include <sfx2/filedlghelper.hxx>
+#include <sfx2/docfile.hxx>
+#include <unotools/pathoptions.hxx>
+#include <sfx2/opengrf.hxx>
+#include "app.hrc"
+#include "sfx2/sfxresid.hxx"
+
+//-----------------------------------------------------------------------------
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::ui::dialogs;
+using namespace ::com::sun::star::uno;
+using namespace ::rtl;
+using namespace ::cppu;
+
+
+//-----------------------------------------------------------------------------
+
+USHORT SvxOpenGrfErr2ResId( short err )
+{
+ switch( err )
+ {
+ case GRFILTER_OPENERROR:
+ return RID_SVXSTR_GRFILTER_OPENERROR;
+ case GRFILTER_IOERROR:
+ return RID_SVXSTR_GRFILTER_IOERROR;
+ case GRFILTER_VERSIONERROR:
+ return RID_SVXSTR_GRFILTER_VERSIONERROR;
+ case GRFILTER_FILTERERROR:
+ return RID_SVXSTR_GRFILTER_FILTERERROR;
+ case GRFILTER_FORMATERROR:
+ default:
+ return RID_SVXSTR_GRFILTER_FORMATERROR;
+ }
+}
+
+
+struct SvxOpenGrf_Impl
+{
+ SvxOpenGrf_Impl ();
+
+ sfx2::FileDialogHelper aFileDlg;
+ uno::Reference < XFilePickerControlAccess > xCtrlAcc;
+};
+
+
+SvxOpenGrf_Impl::SvxOpenGrf_Impl() :
+ aFileDlg(SFXWB_GRAPHIC)
+{
+ uno::Reference < XFilePicker > xFP = aFileDlg.GetFilePicker();
+ xCtrlAcc = uno::Reference < XFilePickerControlAccess >(xFP, UNO_QUERY);
+}
+
+
+SvxOpenGraphicDialog::SvxOpenGraphicDialog( const String& rTitle ) :
+ mpImpl( new SvxOpenGrf_Impl )
+{
+ mpImpl->aFileDlg.SetTitle(rTitle);
+}
+
+
+SvxOpenGraphicDialog::~SvxOpenGraphicDialog()
+{
+}
+
+
+short SvxOpenGraphicDialog::Execute()
+{
+ USHORT nImpRet;
+ BOOL bQuitLoop(FALSE);
+
+ while( bQuitLoop == FALSE &&
+ mpImpl->aFileDlg.Execute() == ERRCODE_NONE )
+ {
+ if( GetPath().Len() )
+ {
+ GraphicFilter* pFilter = GraphicFilter::GetGraphicFilter();
+ INetURLObject aObj( GetPath() );
+
+ // check whether we can load the graphic
+ String aCurFilter( GetCurrentFilter() );
+ USHORT nFormatNum = pFilter->GetImportFormatNumber( aCurFilter );
+ USHORT nRetFormat = 0;
+ USHORT nFound = USHRT_MAX;
+
+ // non-local?
+ if ( INET_PROT_FILE != aObj.GetProtocol() )
+ {
+ SfxMedium aMed( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ, TRUE );
+ aMed.DownLoad();
+ SvStream* pStream = aMed.GetInStream();
+
+ if( pStream )
+ nImpRet = pFilter->CanImportGraphic( aObj.GetMainURL( INetURLObject::NO_DECODE ), *pStream, nFormatNum, &nRetFormat );
+ else
+ nImpRet = pFilter->CanImportGraphic( aObj, nFormatNum, &nRetFormat );
+
+ if ( GRFILTER_OK != nImpRet )
+ {
+ if ( !pStream )
+ nImpRet = pFilter->CanImportGraphic( aObj, GRFILTER_FORMAT_DONTKNOW, &nRetFormat );
+ else
+ nImpRet = pFilter->CanImportGraphic( aObj.GetMainURL( INetURLObject::NO_DECODE ), *pStream,
+ GRFILTER_FORMAT_DONTKNOW, &nRetFormat );
+ }
+ }
+ else
+ {
+ if( (nImpRet=pFilter->CanImportGraphic( aObj, nFormatNum, &nRetFormat )) != GRFILTER_OK )
+ nImpRet = pFilter->CanImportGraphic( aObj, GRFILTER_FORMAT_DONTKNOW, &nRetFormat );
+ }
+
+ if ( GRFILTER_OK == nImpRet )
+ nFound = nRetFormat;
+
+ // could not load?
+ if ( nFound == USHRT_MAX )
+ {
+ WarningBox aWarningBox( NULL, WB_3DLOOK | WB_RETRY_CANCEL, String( SfxResId( SvxOpenGrfErr2ResId(nImpRet) ) ) );
+ bQuitLoop = aWarningBox.Execute()==RET_RETRY ? FALSE : TRUE;
+ }
+ else
+ {
+ // setup appropriate filter (so next time, it will work)
+ if( pFilter->GetImportFormatCount() )
+ {
+ String aFormatName(pFilter->GetImportFormatName(nFound));
+ SetCurrentFilter(aFormatName);
+ }
+
+ return nImpRet;
+ }
+ }
+ }
+
+ // cancel
+ return -1;
+}
+
+
+void SvxOpenGraphicDialog::SetPath( const String& rPath )
+{
+ mpImpl->aFileDlg.SetDisplayDirectory(rPath);
+}
+
+void SvxOpenGraphicDialog::SetPath( const String& rPath, sal_Bool bLinkState )
+{
+ SetPath(rPath);
+ AsLink(bLinkState);
+}
+
+
+void SvxOpenGraphicDialog::EnableLink( sal_Bool state )
+{
+ if( mpImpl->xCtrlAcc.is() )
+ {
+ try
+ {
+ mpImpl->xCtrlAcc->enableControl( ExtendedFilePickerElementIds::CHECKBOX_LINK, state );
+ }
+ catch(IllegalArgumentException)
+ {
+#ifdef DBG_UTIL
+ DBG_ERROR( "Cannot enable \"link\" checkbox" );
+#endif
+ }
+ }
+}
+
+
+void SvxOpenGraphicDialog::AsLink(sal_Bool bState)
+{
+ if( mpImpl->xCtrlAcc.is() )
+ {
+ try
+ {
+ Any aAny; aAny <<= bState;
+ mpImpl->xCtrlAcc->setValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, aAny );
+ }
+ catch(IllegalArgumentException)
+ {
+#ifdef DBG_UTIL
+ DBG_ERROR( "Cannot check \"link\" checkbox" );
+#endif
+ }
+ }
+}
+
+
+sal_Bool SvxOpenGraphicDialog::IsAsLink() const
+{
+ try
+ {
+ if( mpImpl->xCtrlAcc.is() )
+ {
+ Any aVal = mpImpl->xCtrlAcc->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0 );
+ DBG_ASSERT(aVal.hasValue(), "Value CBX_INSERT_AS_LINK not found");
+ return aVal.hasValue() ? *(sal_Bool*) aVal.getValue() : sal_False;
+ }
+ }
+ catch(IllegalArgumentException)
+ {
+#ifdef DBG_UTIL
+ DBG_ERROR( "Cannot access \"link\" checkbox" );
+#endif
+ }
+
+ return sal_False;
+}
+
+
+int SvxOpenGraphicDialog::GetGraphic(Graphic& rGraphic) const
+{
+ return mpImpl->aFileDlg.GetGraphic(rGraphic);
+}
+
+
+String SvxOpenGraphicDialog::GetPath() const
+{
+ return mpImpl->aFileDlg.GetPath();
+}
+
+
+String SvxOpenGraphicDialog::GetCurrentFilter() const
+{
+ return mpImpl->aFileDlg.GetCurrentFilter();
+}
+
+
+void SvxOpenGraphicDialog::SetCurrentFilter(const String& rStr)
+{
+ mpImpl->aFileDlg.SetCurrentFilter(rStr);
+}
+
+void SvxOpenGraphicDialog::SetControlHelpIds( const INT16* _pControlId, const char** _pHelpId )
+{
+ mpImpl->aFileDlg.SetControlHelpIds( _pControlId, _pHelpId );
+}
+
+
diff --git a/sfx2/source/appl/panelist.hxx b/sfx2/source/appl/panelist.hxx
new file mode 100644
index 000000000000..2406709aede9
--- /dev/null
+++ b/sfx2/source/appl/panelist.hxx
@@ -0,0 +1,50 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef SFX_PANELIST_HXX
+
+#include <vcl/taskpanelist.hxx> // includes also vcl/window.hxx
+
+namespace sfx2
+{
+ // source in newhelp.cxx
+
+ void HandleTaskPaneList( Window* pWindow, BOOL bAddToList );
+ // pWindow: just a system window or something which is child of a system window
+
+ inline void AddToTaskPaneList( Window* pWindowToBeHandled )
+ {
+ HandleTaskPaneList( pWindowToBeHandled, TRUE );
+ }
+
+ inline void RemoveFromTaskPaneList( Window* pWindowToBeHandled )
+ {
+ HandleTaskPaneList( pWindowToBeHandled, FALSE );
+ }
+}
+
+#endif
diff --git a/sfx2/source/appl/sfx.src b/sfx2/source/appl/sfx.src
new file mode 100644
index 000000000000..c3b734e327de
--- /dev/null
+++ b/sfx2/source/appl/sfx.src
@@ -0,0 +1,42 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <sfx2/sfx.hrc>
+
+String STR_STYLE_FILTER_USED
+{
+ Text [ en-US ] = "Applied Styles" ;
+};
+String STR_STYLE_FILTER_USERDEF
+{
+ Text [ en-US ] = "Custom Styles" ;
+};
+String STR_STYLE_FILTER_ALL
+{
+ Text [ en-US ] = "All Styles" ;
+};
+
diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx
new file mode 100644
index 000000000000..bab37281cb05
--- /dev/null
+++ b/sfx2/source/appl/sfxhelp.cxx
@@ -0,0 +1,1080 @@
+ /*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "sfx2/sfxhelp.hxx"
+
+#include <set>
+#include <algorithm>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/awt/XTopWindow.hpp>
+#include <com/sun/star/awt/PosSize.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/FrameSearchFlag.hpp>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <unotools/configmgr.hxx>
+#include <unotools/configitem.hxx>
+#include <svtools/helpopt.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/configmgr.hxx>
+#include <ucbhelper/content.hxx>
+#include <unotools/pathoptions.hxx>
+#include <rtl/ustring.hxx>
+#include <osl/process.h>
+#include <osl/file.hxx>
+#include <unotools/bootstrap.hxx>
+#include <rtl/uri.hxx>
+#include <vcl/msgbox.hxx>
+#include <svtools/ehdl.hxx>
+#include <svtools/sfxecode.hxx>
+
+#define _SVSTDARR_STRINGSDTOR
+#define _SVSTDARR_ULONGSSORT
+#include <svl/svstdarr.hxx>
+
+#include "newhelp.hxx"
+#include <sfx2/objsh.hxx>
+#include <sfx2/docfac.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "helper.hxx"
+#include "app.hrc"
+#include <sfx2/sfxuno.hxx>
+#include <vcl/svapp.hxx>
+#include <sfx2/frame.hxx>
+#include <rtl/string.hxx>
+
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::lang;
+
+#define ERROR_TAG String( DEFINE_CONST_UNICODE("Error: ") )
+#define PATH_TAG String( DEFINE_CONST_UNICODE("\nPath: ") )
+
+// class NoHelpErrorBox --------------------------------------------------
+
+class NoHelpErrorBox : public ErrorBox
+{
+public:
+ NoHelpErrorBox( Window* _pParent );
+
+ virtual void RequestHelp( const HelpEvent& rHEvt );
+};
+
+NoHelpErrorBox::NoHelpErrorBox( Window* _pParent ) :
+
+ ErrorBox( _pParent, WB_OK, String( SfxResId( RID_STR_HLPFILENOTEXIST ) ) )
+{
+ // Error message: "No help available"
+}
+
+void NoHelpErrorBox::RequestHelp( const HelpEvent& )
+{
+ // do nothing, because no help available
+}
+
+// -----------------------------------------------------------------------
+
+#define STARTERLIST 0
+
+rtl::OUString HelpLocaleString()
+{
+ static rtl::OUString aLocaleStr;
+ if (!aLocaleStr.getLength())
+ {
+ // detect installed locale
+ Any aLocale =
+ ::utl::ConfigManager::GetConfigManager()->GetDirectConfigProperty(
+ ::utl::ConfigManager::LOCALE );
+ aLocale >>= aLocaleStr;
+ bool bOk = aLocaleStr.getLength() != 0;
+ if ( bOk )
+ {
+ rtl::OUString aBaseInstallPath;
+ // utl::Bootstrap::PathStatus aBaseLocateResult =
+ utl::Bootstrap::locateBaseInstallation(aBaseInstallPath);
+ static const char *szHelpPath = "/help/";
+
+ rtl::OUString sHelpPath = aBaseInstallPath +
+ rtl::OUString::createFromAscii(szHelpPath) + aLocaleStr;
+ osl::DirectoryItem aDirItem;
+
+ if (!osl::DirectoryItem::get(sHelpPath, aDirItem) == osl::FileBase::E_None)
+ {
+ bOk = false;
+ String sLang(aLocaleStr);
+ xub_StrLen nSepPos = sLang.Search( '-' );
+ if (nSepPos != STRING_NOTFOUND)
+ {
+ bOk = true;
+ sLang = sLang.Copy( 0, nSepPos );
+ sHelpPath = aBaseInstallPath +
+ rtl::OUString::createFromAscii(szHelpPath) + sLang;
+ if (!osl::DirectoryItem::get(sHelpPath, aDirItem) == osl::FileBase::E_None)
+ bOk = false;
+ }
+ }
+ }
+ if (!bOk)
+ aLocaleStr = rtl::OUString( DEFINE_CONST_UNICODE("en") );
+ }
+ return aLocaleStr;
+}
+
+void AppendConfigToken_Impl( String& rURL, sal_Bool bQuestionMark )
+{
+ ::rtl::OUString aLocaleStr(HelpLocaleString());
+
+ // query part exists?
+ if ( bQuestionMark )
+ // no, so start with '?'
+ rURL += '?';
+ else
+ // yes, so only append with '&'
+ rURL += '&';
+
+ // set parameters
+ rURL += DEFINE_CONST_UNICODE("Language=");
+ rURL += String( aLocaleStr );
+ rURL += DEFINE_CONST_UNICODE("&System=");
+ rURL += SvtHelpOptions().GetSystem();
+
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool GetHelpAnchor_Impl( const String& _rURL, String& _rAnchor )
+{
+ sal_Bool bRet = sal_False;
+ ::rtl::OUString sAnchor;
+
+ // --> OD 2009-07-01 #159496#
+ // do not release solar mutex due to crash regarding accessibility
+// ULONG nSolarCount = Application::ReleaseSolarMutex();
+ // <--
+ try
+ {
+ ::ucbhelper::Content aCnt( INetURLObject( _rURL ).GetMainURL( INetURLObject::NO_DECODE ),
+ Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
+ if ( ( aCnt.getPropertyValue( ::rtl::OUString::createFromAscii( "AnchorName" ) ) >>= sAnchor ) )
+ {
+
+ if ( sAnchor.getLength() > 0 )
+ {
+ _rAnchor = String( sAnchor );
+ bRet = sal_True;
+ }
+ }
+ else
+ {
+ DBG_ERRORFILE( "Property 'AnchorName' is missing" );
+ }
+ }
+ catch( ::com::sun::star::uno::Exception& )
+ {
+ }
+ // --> OD 2009-07-01 #159496#
+// Application::AcquireSolarMutex( nSolarCount );
+ // <--
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+class SfxHelpOptions_Impl : public utl::ConfigItem
+{
+private:
+ std::set < rtl::OString > m_aIds;
+
+public:
+ SfxHelpOptions_Impl();
+ ~SfxHelpOptions_Impl();
+
+ bool HasId( const rtl::OString& rId ) { return m_aIds.size() ? m_aIds.find( rId ) != m_aIds.end() : false; }
+ virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
+ virtual void Commit();
+};
+
+static Sequence< ::rtl::OUString > GetPropertyNames()
+{
+ static const char* aPropNames[] =
+ {
+ "HelpAgentStarterList",
+ };
+
+ const int nCount = sizeof( aPropNames ) / sizeof( const char* );
+ Sequence< ::rtl::OUString > aNames( nCount );
+ ::rtl::OUString* pNames = aNames.getArray();
+ ::rtl::OUString* pEnd = pNames + aNames.getLength();
+ int i = 0;
+ for ( ; pNames != pEnd; ++pNames )
+ *pNames = ::rtl::OUString::createFromAscii( aPropNames[i++] );
+
+ return aNames;
+}
+
+// -----------------------------------------------------------------------
+
+SfxHelpOptions_Impl::SfxHelpOptions_Impl()
+ : ConfigItem( ::rtl::OUString::createFromAscii("Office.SFX/Help") )
+{
+ Sequence< ::rtl::OUString > aNames = GetPropertyNames();
+ Sequence< Any > aValues = GetProperties( aNames );
+ EnableNotification( aNames );
+ const Any* pValues = aValues.getConstArray();
+ DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
+ if ( aValues.getLength() == aNames.getLength() )
+ {
+ for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
+ {
+ DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
+ if ( pValues[nProp].hasValue() )
+ {
+ switch ( nProp )
+ {
+ case STARTERLIST :
+ {
+ ::rtl::OUString aCodedList;
+ if ( pValues[nProp] >>= aCodedList )
+ {
+ rtl::OString aTmp( aCodedList, aCodedList.getLength(), RTL_TEXTENCODING_UTF8 );
+ sal_Int32 nIndex = 0;
+ do
+ {
+ rtl::OString aToken = aTmp.getToken( 0, ',', nIndex );
+ if ( aToken.getLength() )
+ m_aIds.insert( aToken );
+ }
+ while ( nIndex >= 0 );
+ }
+ else {
+ DBG_ERRORFILE( "Wrong property type!" );
+ }
+
+ break;
+ }
+
+ default:
+ DBG_ERRORFILE( "Wrong property!" );
+ break;
+ }
+ }
+ }
+ }
+}
+
+SfxHelpOptions_Impl::~SfxHelpOptions_Impl()
+{
+}
+
+
+void SfxHelpOptions_Impl::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
+{
+}
+
+void SfxHelpOptions_Impl::Commit()
+{
+}
+
+// class SfxHelp_Impl ----------------------------------------------------
+
+class SfxHelp_Impl
+{
+private:
+ sal_Bool m_bIsDebug; // environment variable "help_debug=1"
+ SfxHelpOptions_Impl* m_pOpt; // the options
+ ::std::vector< ::rtl::OUString > m_aModulesList; // list of all installed modules
+ void Load();
+
+public:
+ SfxHelp_Impl( sal_Bool bDebug );
+ ~SfxHelp_Impl();
+
+ SfxHelpOptions_Impl* GetOptions();
+ static String GetHelpText( const rtl::OUString& aCommandURL, const String& rModule );
+ sal_Bool HasModule( const ::rtl::OUString& rModule ); // module installed
+ sal_Bool IsHelpInstalled(); // module list not empty
+};
+
+SfxHelp_Impl::SfxHelp_Impl( sal_Bool bDebug ) :
+
+ m_bIsDebug ( bDebug ),
+ m_pOpt ( NULL )
+
+{
+}
+
+SfxHelp_Impl::~SfxHelp_Impl()
+{
+ delete m_pOpt;
+}
+
+void SfxHelp_Impl::Load()
+{
+ // fill modules list
+ // create the help url (empty, without module and helpid)
+ String sHelpURL( DEFINE_CONST_UNICODE("vnd.sun.star.help://") );
+ AppendConfigToken_Impl( sHelpURL, sal_True );
+
+ // open ucb content and get the list of the help modules
+ // the list contains strings with three tokens "ui title \t type \t url"
+ Sequence< ::rtl::OUString > aAllModulesList = SfxContentHelper::GetResultSet( sHelpURL );
+ sal_Int32 nLen = aAllModulesList.getLength();
+ m_aModulesList.reserve( nLen + 1 );
+ const ::rtl::OUString* pBegin = aAllModulesList.getConstArray();
+ const ::rtl::OUString* pEnd = pBegin + nLen;
+ for ( ; pBegin != pEnd; ++pBegin )
+ {
+ // get one module string
+ String sModule( *pBegin );
+ // extract the url
+ String sURL = sModule.GetToken( 2, '\t' );
+ // insert the module (the host part of the "vnd.sun.star.help" url)
+ m_aModulesList.push_back( ::rtl::OUString( INetURLObject( sURL ).GetHost() ) );
+ }
+}
+
+String SfxHelp_Impl::GetHelpText( const rtl::OUString& aCommandURL, const String& rModule )
+{
+ // create help url
+ String aHelpURL = SfxHelp::CreateHelpURL( aCommandURL, rModule );
+ // added 'active' parameter
+ aHelpURL.Insert( String( DEFINE_CONST_UNICODE("&Active=true") ), aHelpURL.SearchBackward( '#' ) );
+ // load help string
+ return SfxContentHelper::GetActiveHelpString( aHelpURL );
+}
+
+SfxHelpOptions_Impl* SfxHelp_Impl::GetOptions()
+{
+ // create if not exists
+ if ( !m_pOpt )
+ m_pOpt = new SfxHelpOptions_Impl;
+ return m_pOpt;
+}
+
+sal_Bool SfxHelp_Impl::HasModule( const ::rtl::OUString& rModule )
+{
+ if ( !m_aModulesList.size() )
+ Load();
+ return ( ::std::find( m_aModulesList.begin(), m_aModulesList.end(), rModule ) != m_aModulesList.end() );
+}
+
+sal_Bool SfxHelp_Impl::IsHelpInstalled()
+{
+ if ( !m_aModulesList.size() )
+ Load();
+ return ( m_aModulesList.begin() != m_aModulesList.end() );
+}
+
+// class SfxHelp ---------------------------------------------------------
+/* some test code for HID conversion - please don't remove
+
+#include <tools/stream.hxx>
+void TestHids()
+{
+ static const char* aModules[] =
+ {
+ "swriter",
+ "scalc",
+ "simpress",
+ "sdraw",
+ "sdatabase",
+ "smath",
+ "schart",
+ "sbasic"
+ };
+
+ SvFileStream* pOut[] =
+ {
+ 0,0,0,0,0,0,0,0,0
+ };
+
+ String aIn = String::CreateFromAscii("/data/OOo/replacer/hidsin.lst");
+ String aOut = String::CreateFromAscii("/data/OOo/replacer/");
+ SvFileStream aInStrm( aIn, STREAM_READ );
+ ByteString aBuffer;
+ while ( aInStrm.ReadLine( aBuffer ) )
+ {
+ ByteString aHid = aBuffer.GetToken(0, ' ');
+ ByteString aNr = aBuffer.GetToken(1, ' ');
+ bool bFound=false;
+ for (sal_Int32 n= 0; n<8; n++)
+ {
+ bFound = false;
+ String aHelpURL = SfxHelp::CreateHelpURL( String( aNr, RTL_TEXTENCODING_UTF8 ), String( aModules[n], RTL_TEXTENCODING_UTF8 ) );
+ if ( !SfxContentHelper::IsHelpErrorDocument( aHelpURL ) )
+ {
+ if (!pOut[n])
+ {
+ String aTmp( aOut );
+ aTmp += String( aModules[n], RTL_TEXTENCODING_UTF8 );
+ aTmp += String::CreateFromAscii(".lst");
+ pOut[n] = new SvFileStream( aTmp, STREAM_WRITE | STREAM_TRUNC );
+ }
+ pOut[n]->WriteLine( aHid );
+ bFound = true;
+ break;
+ }
+ }
+
+ if (!bFound)
+ {
+ if (!pOut[8])
+ {
+ String aTmp( aOut );
+ aTmp += String( "notfound", RTL_TEXTENCODING_UTF8 );
+ aTmp += String::CreateFromAscii(".lst");
+ pOut[8] = new SvFileStream( aTmp, STREAM_WRITE | STREAM_TRUNC );
+ }
+ pOut[8]->WriteLine( aHid );
+ }
+ }
+
+ for (sal_Int32 n= 0; n<9; n++)
+ DELETEZ( pOut[n] );
+}
+
+void TestHids2()
+{
+ static const char* aModules[] =
+ {
+ "swriter",
+ "scalc",
+ "simpress",
+ "smath",
+ "sbasic"
+ };
+
+ String aOut = String::CreateFromAscii("/data/OOo/replacer/");
+ aOut += String::CreateFromAscii("lost.lst");
+ SvFileStream aOutStrm( aOut, STREAM_WRITE | STREAM_TRUNC );
+ for (sal_Int32 n= 0; n<5; n++)
+ {
+ String aIn = String::CreateFromAscii("/data/OOo/replacer/help/");
+ aIn += String::CreateFromAscii( aModules[n] );
+ aIn += String::CreateFromAscii(".lst");
+ SvFileStream aInStrm( aIn, STREAM_READ );
+ ByteString aBuffer;
+ while ( aInStrm.ReadLine( aBuffer ) )
+ {
+ String aHelpURL = SfxHelp::CreateHelpURL( String( aBuffer, RTL_TEXTENCODING_UTF8 ), String( aModules[n], RTL_TEXTENCODING_UTF8 ) );
+ if ( SfxContentHelper::IsHelpErrorDocument( aHelpURL ) )
+ aOutStrm.WriteLine( aBuffer );
+ }
+ }
+}
+
+#include <tools/stream.hxx>
+void TestHids3()
+{
+ static const char* aModules[] =
+ {
+ "swriter",
+ "scalc",
+ "simpress",
+ "sdraw",
+ "sdatabase",
+ "smath",
+ "schart",
+ "sbasic"
+ };
+
+ SvFileStream* pOut[] =
+ {
+ 0,0,0,0,0,0,0,0,0
+ };
+
+ String aIn = String::CreateFromAscii("/data/OOo/replacer/hidsin.lst");
+ String aOut = String::CreateFromAscii("/data/OOo/replacer/quickhelp/");
+ SvFileStream aInStrm( aIn, STREAM_READ );
+ ByteString aBuffer;
+ while ( aInStrm.ReadLine( aBuffer ) )
+ {
+ ByteString aHid = aBuffer.GetToken(0, ' ');
+ ByteString aNr = aBuffer.GetToken(1, ' ');
+ bool bFound=false;
+ for (sal_Int32 n= 0; n<8; n++)
+ {
+ bFound = false;
+ String aHelpURL = SfxHelp::CreateHelpURL( String( aNr, RTL_TEXTENCODING_UTF8 ), String( aModules[n], RTL_TEXTENCODING_UTF8 ) );
+ if ( SfxContentHelper::GetActiveHelpString( aHelpURL ).Len() )
+// if ( SfxHelp_Impl::GetHelpText( String( aNr, RTL_TEXTENCODING_UTF8 ), String( aModules[n], RTL_TEXTENCODING_UTF8 ) ).Len() )
+ {
+ if (!pOut[n])
+ {
+ String aTmp( aOut );
+ aTmp += String( aModules[n], RTL_TEXTENCODING_UTF8 );
+ aTmp += String::CreateFromAscii(".lst");
+ pOut[n] = new SvFileStream( aTmp, STREAM_WRITE | STREAM_TRUNC );
+ }
+ pOut[n]->WriteLine( aHid );
+ bFound = true;
+ break;
+ }
+ }
+
+ if (!bFound)
+ {
+ if (!pOut[8])
+ {
+ String aTmp( aOut );
+ aTmp += String( "notfound", RTL_TEXTENCODING_UTF8 );
+ aTmp += String::CreateFromAscii(".lst");
+ pOut[8] = new SvFileStream( aTmp, STREAM_WRITE | STREAM_TRUNC );
+ }
+ pOut[8]->WriteLine( aHid );
+ }
+ }
+
+ for (sal_Int32 n= 0; n<9; n++)
+ DELETEZ( pOut[n] );
+}
+
+void TestHids4()
+{
+ static const char* aModules[] =
+ {
+ "swriter",
+ "scalc",
+ "simpress",
+ "smath",
+ "sbasic"
+ };
+
+ String aOut = String::CreateFromAscii("/data/OOo/replacer/quickhelp/");
+ aOut += String::CreateFromAscii("lost.lst");
+ SvFileStream aOutStrm( aOut, STREAM_WRITE | STREAM_TRUNC );
+ for (sal_Int32 n= 0; n<5; n++)
+ {
+ String aIn = String::CreateFromAscii("/data/OOo/replacer/quickhelp/");
+ aIn += String::CreateFromAscii( aModules[n] );
+ aIn += String::CreateFromAscii(".lst");
+ SvFileStream aInStrm( aIn, STREAM_READ );
+ ByteString aBuffer;
+ while ( aInStrm.ReadLine( aBuffer ) )
+ {
+ String aHelpURL = SfxHelp::CreateHelpURL( String( aBuffer, RTL_TEXTENCODING_UTF8 ), String( aModules[n], RTL_TEXTENCODING_UTF8 ) );
+ if ( !SfxContentHelper::GetActiveHelpString( aHelpURL ).Len() )
+ aOutStrm.WriteLine( aBuffer );
+ }
+ }
+}
+*/
+
+SfxHelp::SfxHelp() :
+
+ bIsDebug( sal_False ),
+ pImp ( NULL )
+
+{
+ // read the environment variable "HELP_DEBUG"
+ // if it's set, you will see debug output on active help
+ {
+ ::rtl::OUString sHelpDebug;
+ ::rtl::OUString sEnvVarName( RTL_CONSTASCII_USTRINGPARAM( "HELP_DEBUG" ) );
+ osl_getEnvironment( sEnvVarName.pData, &sHelpDebug.pData );
+ bIsDebug = ( 0 != sHelpDebug.getLength() );
+ }
+
+ pImp = new SfxHelp_Impl( bIsDebug );
+
+ ::rtl::OUString aLocaleStr = HelpLocaleString();
+
+ sal_Int32 nSepPos = aLocaleStr.indexOf( '_' );
+ if ( nSepPos != -1 )
+ {
+ aLanguageStr = aLocaleStr.copy( 0, nSepPos );
+ aCountryStr = aLocaleStr.copy( nSepPos+1 );
+ }
+ else
+ {
+ nSepPos = aLocaleStr.indexOf( '-' );
+ if ( nSepPos != -1 )
+ {
+ aLanguageStr = aLocaleStr.copy( 0, nSepPos );
+ aCountryStr = aLocaleStr.copy( nSepPos+1 );
+ }
+ else
+ {
+ aLanguageStr = aLocaleStr;
+ }
+ }
+}
+
+SfxHelp::~SfxHelp()
+{
+ delete pImp;
+}
+
+::rtl::OUString getDefaultModule_Impl()
+{
+ rtl::OUString sDefaultModule;
+ SvtModuleOptions aModOpt;
+ if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
+ sDefaultModule = DEFINE_CONST_UNICODE("swriter");
+ else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
+ sDefaultModule = DEFINE_CONST_UNICODE("scalc");
+ else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
+ sDefaultModule = DEFINE_CONST_UNICODE("simpress");
+ else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
+ sDefaultModule = DEFINE_CONST_UNICODE("sdraw");
+ else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
+ sDefaultModule = DEFINE_CONST_UNICODE("smath");
+ else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SCHART ) )
+ sDefaultModule = DEFINE_CONST_UNICODE("schart");
+ else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SBASIC ) )
+ sDefaultModule = DEFINE_CONST_UNICODE("sbasic");
+ else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
+ sDefaultModule = DEFINE_CONST_UNICODE("sdatabase");
+ else
+ {
+ DBG_ERRORFILE( "getDefaultModule_Impl(): no module installed" );
+ }
+ return sDefaultModule;
+}
+
+::rtl::OUString getCurrentModuleIdentifier_Impl()
+{
+ ::rtl::OUString sIdentifier;
+ Reference < XFrame > xCurrentFrame;
+ Reference < XModuleManager > xModuleManager( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.ModuleManager") ), UNO_QUERY );
+ Reference < XDesktop > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
+ if ( xDesktop.is() )
+ xCurrentFrame = xDesktop->getCurrentFrame();
+
+ if ( xCurrentFrame.is() && xModuleManager.is() )
+ {
+ try
+ {
+ sIdentifier = xModuleManager->identify( xCurrentFrame );
+ }
+ catch ( ::com::sun::star::frame::UnknownModuleException& )
+ {
+ DBG_WARNING( "SfxHelp::getCurrentModuleIdentifier_Impl(): unknown module (help in help?)" );
+ }
+ catch ( Exception& )
+ {
+ DBG_ERRORFILE( "SfxHelp::getCurrentModuleIdentifier_Impl(): exception of XModuleManager::identify()" );
+ }
+ }
+
+ return sIdentifier;
+}
+
+String SfxHelp::GetHelpModuleName_Impl()
+{
+ String sModuleName;
+ rtl::OUString aFactoryShortName;
+ rtl::OUString aModuleIdentifier = getCurrentModuleIdentifier_Impl();
+
+ if ( aModuleIdentifier.getLength() > 0 )
+ {
+ try
+ {
+ Reference < XModuleManager > xModuleManager(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.ModuleManager") ), UNO_QUERY );
+ Sequence< PropertyValue > lProps;
+ Reference< ::com::sun::star::container::XNameAccess > xCont( xModuleManager, UNO_QUERY);
+ if ( xCont.is() )
+ xCont->getByName( aModuleIdentifier ) >>= lProps;
+ for ( sal_Int32 i = 0; i < lProps.getLength(); ++i )
+ {
+ if ( lProps[i].Name.equalsAscii("ooSetupFactoryShortName") )
+ {
+ lProps[i].Value >>= aFactoryShortName;
+ break;
+ }
+ }
+ }
+ catch ( Exception& )
+ {
+ DBG_ERRORFILE( "SfxHelp::GetHelpModuleName_Impl(): exception of XNameAccess::getByName()" );
+ }
+ }
+
+ rtl::OUString sDefaultModule = getDefaultModule_Impl();
+ if ( aFactoryShortName.getLength() > 0 )
+ {
+ // Map some module identifiers to their "real" help module string.
+ if ( aFactoryShortName.equalsAscii( "chart2" ) )
+ aFactoryShortName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "schart" ) );
+ else if ( aFactoryShortName.equalsAscii( "BasicIDE" ) )
+ aFactoryShortName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "sbasic" ) );
+ else if ( aFactoryShortName.equalsAscii( "sweb" )
+ || aFactoryShortName.equalsAscii( "sglobal" )
+ || aFactoryShortName.equalsAscii( "swxform" ) )
+ aFactoryShortName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "swriter" ) );
+ else if ( aFactoryShortName.equalsAscii( "dbquery" )
+ || aFactoryShortName.equalsAscii( "dbbrowser" )
+ || aFactoryShortName.equalsAscii( "dbrelation" )
+ || aFactoryShortName.equalsAscii( "dbtable" )
+ || aFactoryShortName.equalsAscii( "dbapp" )
+ || aFactoryShortName.equalsAscii( "dbreport" )
+ || aFactoryShortName.equalsAscii( "swreport" )
+ || aFactoryShortName.equalsAscii( "dbbrowser" )
+ || aFactoryShortName.equalsAscii( "swform" ) )
+ aFactoryShortName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "sdatabase" ) );
+ else if ( aFactoryShortName.equalsAscii( "sbibliography" )
+ || aFactoryShortName.equalsAscii( "StartModule" ) )
+ aFactoryShortName = sDefaultModule;
+ }
+ else
+ aFactoryShortName = sDefaultModule;
+
+ sModuleName = String( aFactoryShortName );
+ return sModuleName;
+}
+
+String SfxHelp::CreateHelpURL_Impl( const String& aCommandURL, const String& rModuleName )
+{
+ // build up the help URL
+ String aHelpURL;
+ sal_Bool bHasAnchor = sal_False;
+ String aAnchor;
+
+ String aModuleName( rModuleName );
+ if ( aModuleName.Len() == 0 )
+ aModuleName = getDefaultModule_Impl();
+
+ aHelpURL = String::CreateFromAscii("vnd.sun.star.help://");
+ aHelpURL += aModuleName;
+
+ if ( !aCommandURL.Len() )
+ aHelpURL += String::CreateFromAscii("/start");
+ else
+ {
+ aHelpURL += '/';
+ aHelpURL += String( rtl::Uri::encode( aCommandURL,
+ rtl_UriCharClassRelSegment,
+ rtl_UriEncodeKeepEscapes,
+ RTL_TEXTENCODING_UTF8 ));
+
+ String aTempURL = aHelpURL;
+ AppendConfigToken_Impl( aTempURL, sal_True );
+ bHasAnchor = GetHelpAnchor_Impl( aTempURL, aAnchor );
+ }
+
+ AppendConfigToken_Impl( aHelpURL, sal_True );
+
+ if ( bHasAnchor )
+ {
+ aHelpURL += '#';
+ aHelpURL += aAnchor;
+ }
+
+ return aHelpURL;
+}
+
+SfxHelpWindow_Impl* impl_createHelp(Reference< XFrame >& rHelpTask ,
+ Reference< XFrame >& rHelpContent)
+{
+ Reference < XFrame > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
+
+ // otherwhise - create new help task
+ Reference< XFrame > xHelpTask = xDesktop->findFrame(
+ ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP_TASK")),
+ FrameSearchFlag::TASKS | FrameSearchFlag::CREATE);
+ if (!xHelpTask.is())
+ return 0;
+
+ // create all internal windows and sub frames ...
+ Reference< ::com::sun::star::awt::XWindow > xParentWindow = xHelpTask->getContainerWindow();
+ Window* pParentWindow = VCLUnoHelper::GetWindow( xParentWindow );
+ SfxHelpWindow_Impl* pHelpWindow = new SfxHelpWindow_Impl( xHelpTask, pParentWindow, WB_DOCKBORDER );
+ Reference< ::com::sun::star::awt::XWindow > xHelpWindow = VCLUnoHelper::GetInterface( pHelpWindow );
+
+ Reference< XFrame > xHelpContent;
+ if (xHelpTask->setComponent( xHelpWindow, Reference< XController >() ))
+ {
+ // Customize UI ...
+ xHelpTask->setName( ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP_TASK")) );
+
+ Reference< XPropertySet > xProps(xHelpTask, UNO_QUERY);
+ if (xProps.is())
+ xProps->setPropertyValue(
+ DEFINE_CONST_UNICODE("Title"),
+ makeAny(::rtl::OUString(String(SfxResId(STR_HELP_WINDOW_TITLE)))));
+
+ pHelpWindow->setContainerWindow( xParentWindow );
+ xParentWindow->setVisible(sal_True);
+ xHelpWindow->setVisible(sal_True);
+
+ // This sub frame is created internaly (if we called new SfxHelpWindow_Impl() ...)
+ // It should exist :-)
+ xHelpContent = xHelpTask->findFrame(::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP")), FrameSearchFlag::CHILDREN);
+ }
+
+ if (!xHelpContent.is())
+ delete pHelpWindow;
+
+ xHelpContent->setName(::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP")));
+
+ rHelpTask = xHelpTask;
+ rHelpContent = xHelpContent;
+ return pHelpWindow;
+}
+
+XubString SfxHelp::GetHelpText( const String& aCommandURL, const Window* pWindow )
+{
+ String sModuleName = GetHelpModuleName_Impl();
+ String sHelpText = pImp->GetHelpText( aCommandURL, sModuleName );
+
+ ByteString aNewHelpId;
+
+ if ( pWindow && !sHelpText.Len() )
+ {
+ // no help text found -> try with parent help id.
+ Window* pParent = pWindow->GetParent();
+ while ( pParent )
+ {
+ aNewHelpId = pParent->GetHelpId();
+ sHelpText = pImp->GetHelpText( String( aNewHelpId, RTL_TEXTENCODING_UTF8 ), sModuleName );
+ if ( sHelpText.Len() > 0 )
+ pParent = NULL;
+ else
+ pParent = pParent->GetParent();
+ }
+
+ if ( bIsDebug && !sHelpText.Len() )
+ aNewHelpId.Erase();
+ }
+
+ // add some debug information?
+ if ( bIsDebug )
+ {
+ sHelpText += DEFINE_CONST_UNICODE("\n-------------\n");
+ sHelpText += String( sModuleName );
+ sHelpText += DEFINE_CONST_UNICODE(": ");
+ sHelpText += aCommandURL;
+ if ( aNewHelpId.Len() )
+ {
+ sHelpText += DEFINE_CONST_UNICODE(" - ");
+ sHelpText += String( aNewHelpId, RTL_TEXTENCODING_UTF8 );
+ }
+ }
+
+ return sHelpText;
+}
+
+BOOL SfxHelp::SearchKeyword( const XubString& rKeyword )
+{
+ return Start_Impl( String(), NULL, rKeyword );
+}
+
+BOOL SfxHelp::Start( const String& rURL, const Window* pWindow )
+{
+ return Start_Impl( rURL, pWindow, String() );
+}
+
+BOOL SfxHelp::Start_Impl( const String& rURL, const Window* pWindow, const String& rKeyword )
+{
+ // check if help is available
+ String aHelpRootURL( DEFINE_CONST_OUSTRING("vnd.sun.star.help://") );
+ AppendConfigToken_Impl( aHelpRootURL, sal_True );
+ Sequence< ::rtl::OUString > aFactories = SfxContentHelper::GetResultSet( aHelpRootURL );
+ if ( 0 == aFactories.getLength() )
+ {
+ // no factories -> no help -> error message and return
+ NoHelpErrorBox aErrBox( const_cast< Window* >( pWindow ) );
+ aErrBox.Execute();
+ return FALSE;
+ }
+
+ /* rURL may be
+ - a "real" URL
+ - a HelpID (formerly a long, now a string)
+ If rURL is a URL, CreateHelpURL should be called for this URL
+ If rURL is an arbitrary string, the same should happen, but the URL should be tried out
+ if it delivers real help content. In case only the Help Error Document is returned, the
+ parent of the window for that help was called, is asked for its HelpID.
+ For compatibility reasons this upward search is not implemented for "real" URLs.
+ Help keyword search now is implemented as own method; in former versions it
+ was done via Help::Start, but this implementation conflicted with the upward search.
+ */
+ String aHelpURL;
+ INetURLObject aParser( rURL );
+ INetProtocol nProtocol = aParser.GetProtocol();
+ String aHelpModuleName( GetHelpModuleName_Impl() );
+ switch ( nProtocol )
+ {
+ case INET_PROT_VND_SUN_STAR_HELP:
+ // already a vnd.sun.star.help URL -> nothing to do
+ aHelpURL = rURL;
+ break;
+ default:
+ {
+ // no URL, just a HelpID (maybe empty in case of keyword search)
+ aHelpURL = CreateHelpURL_Impl( rURL, aHelpModuleName );
+ if ( pWindow && SfxContentHelper::IsHelpErrorDocument( aHelpURL ) )
+ {
+ // no help found -> try with parent help id.
+ Window* pParent = pWindow->GetParent();
+ while ( pParent )
+ {
+ ByteString aHelpId = pParent->GetHelpId();
+ aHelpURL = CreateHelpURL( String( aHelpId, RTL_TEXTENCODING_UTF8 ), aHelpModuleName );
+ if ( !SfxContentHelper::IsHelpErrorDocument( aHelpURL ) )
+ break;
+ else
+ {
+ pParent = pParent->GetParent();
+ if ( !pParent )
+ // create help url of start page ( helpid == 0 -> start page)
+ aHelpURL = CreateHelpURL( String(), aHelpModuleName );
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ Reference < XFrame > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
+
+ // check if help window is still open
+ // If not, create a new one and return access directly to the internal sub frame showing the help content
+ // search must be done here; search one desktop level could return an arbitraty frame
+ Reference< XFrame > xHelp = xDesktop->findFrame(
+ ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP_TASK")),
+ FrameSearchFlag::CHILDREN);
+ Reference< XFrame > xHelpContent = xDesktop->findFrame(
+ ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP")),
+ FrameSearchFlag::CHILDREN);
+
+ SfxHelpWindow_Impl* pHelpWindow = 0;
+ if (!xHelp.is())
+ pHelpWindow = impl_createHelp(xHelp, xHelpContent);
+ else
+ pHelpWindow = (SfxHelpWindow_Impl*)VCLUnoHelper::GetWindow(xHelp->getComponentWindow());
+ if (!xHelp.is() || !xHelpContent.is() || !pHelpWindow)
+ return FALSE;
+
+#ifdef DBG_UTIL
+ ByteString aTmp("SfxHelp: HelpId = ");
+ aTmp += ByteString( aHelpURL, RTL_TEXTENCODING_UTF8 );
+ DBG_TRACE( aTmp.GetBuffer() );
+#endif
+
+ pHelpWindow->SetHelpURL( aHelpURL );
+ pHelpWindow->loadHelpContent(aHelpURL);
+ if ( rKeyword.Len() )
+ pHelpWindow->OpenKeyword( rKeyword );
+
+ Reference < ::com::sun::star::awt::XTopWindow > xTopWindow( xHelp->getContainerWindow(), UNO_QUERY );
+ if ( xTopWindow.is() )
+ xTopWindow->toFront();
+
+ return TRUE;
+}
+
+String SfxHelp::CreateHelpURL( const String& aCommandURL, const String& rModuleName )
+{
+ String aURL;
+ SfxHelp* pHelp = SAL_STATIC_CAST( SfxHelp*, Application::GetHelp() );
+ if ( pHelp )
+ aURL = pHelp->CreateHelpURL_Impl( aCommandURL, rModuleName );
+ return aURL;
+}
+
+void SfxHelp::OpenHelpAgent( SfxFrame*, const rtl::OString& sHelpId )
+{
+ SfxHelp* pHelp = SAL_STATIC_CAST( SfxHelp*, Application::GetHelp() );
+ if ( pHelp )
+ pHelp->OpenHelpAgent( sHelpId );
+}
+
+void SfxHelp::OpenHelpAgent( const rtl::OString& sHelpId )
+{
+ if ( SvtHelpOptions().IsHelpAgentAutoStartMode() )
+ {
+ SfxHelpOptions_Impl *pOpt = pImp->GetOptions();
+ if ( !pOpt->HasId( sHelpId ) )
+ return;
+
+ try
+ {
+ URL aURL;
+ aURL.Complete = CreateHelpURL_Impl( String( ByteString(sHelpId), RTL_TEXTENCODING_UTF8 ), GetHelpModuleName_Impl() );
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" ) ), UNO_QUERY );
+ xTrans->parseStrict(aURL);
+
+ Reference < XFrame > xCurrentFrame;
+ Reference < XDesktop > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
+ if ( xDesktop.is() )
+ xCurrentFrame = xDesktop->getCurrentFrame();
+
+ Reference< XDispatchProvider > xDispProv( xCurrentFrame, UNO_QUERY );
+ Reference< XDispatch > xHelpDispatch;
+ if ( xDispProv.is() )
+ xHelpDispatch = xDispProv->queryDispatch(
+ aURL, ::rtl::OUString::createFromAscii("_helpagent"),
+ FrameSearchFlag::PARENT | FrameSearchFlag::SELF );
+
+ DBG_ASSERT( xHelpDispatch.is(), "OpenHelpAgent: could not get a dispatcher!" );
+ if ( xHelpDispatch.is() )
+ xHelpDispatch->dispatch( aURL, Sequence< PropertyValue >() );
+ }
+ catch( const Exception& )
+ {
+ DBG_ERRORFILE( "OpenHelpAgent: caught an exception while executing the dispatch!" );
+ }
+ }
+}
+
+String SfxHelp::GetDefaultHelpModule()
+{
+ return getDefaultModule_Impl();
+}
+
+::rtl::OUString SfxHelp::GetCurrentModuleIdentifier()
+{
+ return getCurrentModuleIdentifier_Impl();
+}
+
diff --git a/sfx2/source/appl/sfxpicklist.cxx b/sfx2/source/appl/sfxpicklist.cxx
new file mode 100644
index 000000000000..0074faac192f
--- /dev/null
+++ b/sfx2/source/appl/sfxpicklist.cxx
@@ -0,0 +1,473 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <unotools/historyoptions.hxx>
+#include <unotools/useroptions.hxx>
+#include <tools/urlobj.hxx>
+#include <framework/menuconfiguration.hxx>
+#include <svl/inethist.hxx>
+#include <svl/stritem.hxx>
+#include <svl/eitem.hxx>
+#include <osl/file.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <cppuhelper/implbase1.hxx>
+
+// ----------------------------------------------------------------------------
+
+#include <sfx2/app.hxx>
+#include "sfxpicklist.hxx"
+#include <sfx2/sfxuno.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/request.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <sfx2/sfx.hrc>
+#include <sfx2/event.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/bindings.hxx>
+#include "referers.hxx"
+#include <sfx2/docfile.hxx>
+#include "objshimp.hxx"
+#include <sfx2/docfilt.hxx>
+
+#include <algorithm>
+
+// ----------------------------------------------------------------------------
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::util;
+
+// ----------------------------------------------------------------------------
+
+osl::Mutex* SfxPickList::pMutex = 0;
+SfxPickList* SfxPickList::pUniqueInstance = 0;
+
+// ----------------------------------------------------------------------------
+
+class StringLength : public ::cppu::WeakImplHelper1< XStringWidth >
+{
+ public:
+ StringLength() {}
+ virtual ~StringLength() {}
+
+ // XStringWidth
+ sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString )
+ throw (::com::sun::star::uno::RuntimeException)
+ {
+ return aString.getLength();
+ }
+};
+
+// ----------------------------------------------------------------------------
+
+osl::Mutex* SfxPickList::GetOrCreateMutex()
+{
+ if ( !pMutex )
+ {
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
+ if ( !pMutex )
+ pMutex = new osl::Mutex;
+ }
+
+ return pMutex;
+}
+
+void SfxPickList::CreatePicklistMenuTitle( Menu* pMenu, USHORT nItemId, const String& aURLString, sal_uInt32 nNo )
+{
+ String aPickEntry;
+
+ if ( nNo < 9 )
+ {
+ aPickEntry += '~';
+ aPickEntry += String::CreateFromInt32( nNo + 1 );
+ }
+ else if ( nNo == 9 )
+ aPickEntry += DEFINE_CONST_UNICODE("1~0");
+ else
+ aPickEntry += String::CreateFromInt32( nNo + 1 );
+ aPickEntry += DEFINE_CONST_UNICODE(": ");
+
+ INetURLObject aURL( aURLString );
+ rtl::OUString aTipHelpText;
+ rtl::OUString aAccessibleName( aPickEntry );
+
+ if ( aURL.GetProtocol() == INET_PROT_FILE )
+ {
+ // Do handle file URL differently => convert it to a system
+ // path and abbreviate it with a special function:
+ String aFileSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) );
+
+// ::utl::LocalFileHelper::ConvertURLToPhysicalName( aURLString, aPhysicalName );
+
+ ::rtl::OUString aSystemPath( aFileSystemPath );
+ ::rtl::OUString aCompactedSystemPath;
+
+ aTipHelpText = aSystemPath;
+ aAccessibleName += aSystemPath;
+ oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, NULL );
+ if ( !nError )
+ aPickEntry += String( aCompactedSystemPath );
+ else
+ aPickEntry += aFileSystemPath;
+
+ if ( aPickEntry.Len() > 50 )
+ {
+ aPickEntry.Erase( 47 );
+ aPickEntry += DEFINE_CONST_UNICODE("...");
+ }
+ }
+ else
+ {
+ // Use INetURLObject to abbreviate all other URLs
+ String aShortURL;
+ aShortURL = aURL.getAbbreviated( m_xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS );
+ aPickEntry += aShortURL;
+ aTipHelpText = aURLString;
+ aAccessibleName += aURLString;
+ }
+
+ // Set menu item text, tip help and accessible name
+ pMenu->SetItemText( nItemId, aPickEntry );
+ pMenu->SetTipHelpText( nItemId, aTipHelpText );
+ pMenu->SetAccessibleName( nItemId, aAccessibleName );
+}
+
+void SfxPickList::RemovePickListEntries()
+{
+ ::osl::MutexGuard aGuard( GetOrCreateMutex() );
+ for ( sal_uInt32 i = 0; i < m_aPicklistVector.size(); i++ )
+ delete m_aPicklistVector[i];
+ m_aPicklistVector.clear();
+}
+
+SfxPickList::PickListEntry* SfxPickList::GetPickListEntry( sal_uInt32 nIndex )
+{
+ OSL_ASSERT( m_aPicklistVector.size() > nIndex );
+
+ if ( nIndex < m_aPicklistVector.size() )
+ return m_aPicklistVector[ nIndex ];
+ else
+ return 0;
+}
+
+SfxPickList* SfxPickList::GetOrCreate( const sal_uInt32 nMenuSize )
+{
+ if ( !pUniqueInstance )
+ {
+ ::osl::MutexGuard aGuard( GetOrCreateMutex() );
+ if ( !pUniqueInstance )
+ pUniqueInstance = new SfxPickList( nMenuSize );
+ }
+
+ return pUniqueInstance;
+}
+
+SfxPickList* SfxPickList::Get()
+{
+ ::osl::MutexGuard aGuard( GetOrCreateMutex() );
+ return pUniqueInstance;
+}
+
+void SfxPickList::Delete()
+{
+ ::osl::MutexGuard aGuard( GetOrCreateMutex() );
+ DELETEZ( pUniqueInstance );
+}
+
+SfxPickList::SfxPickList( sal_uInt32 nAllowedMenuSize ) :
+ m_nAllowedMenuSize( nAllowedMenuSize )
+{
+ m_xStringLength = new StringLength;
+ m_nAllowedMenuSize = ::std::min( m_nAllowedMenuSize, (sal_uInt32)PICKLIST_MAXSIZE );
+ StartListening( *SFX_APP() );
+}
+
+SfxPickList::~SfxPickList()
+{
+ RemovePickListEntries();
+}
+
+void SfxPickList::CreatePickListEntries()
+{
+ RemovePickListEntries();
+
+ // Einlesen der Pickliste
+ Sequence< Sequence< PropertyValue > > seqPicklist = SvtHistoryOptions().GetList( ePICKLIST );
+
+ sal_uInt32 nCount = seqPicklist.getLength();
+ sal_uInt32 nEntries = ::std::min( m_nAllowedMenuSize, nCount );
+
+ for( sal_uInt32 nItem=0; nItem < nEntries; ++nItem )
+ {
+ Sequence< PropertyValue > seqPropertySet = seqPicklist[ nItem ];
+
+ INetURLObject aURL;
+ ::rtl::OUString sURL;
+ ::rtl::OUString sFilter;
+ ::rtl::OUString sTitle;
+ ::rtl::OUString sPassword;
+
+ sal_uInt32 nPropertyCount = seqPropertySet.getLength();
+ for( sal_uInt32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
+ {
+ if( seqPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_URL )
+ {
+ seqPropertySet[nProperty].Value >>= sURL;
+ }
+ else if( seqPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_FILTER )
+ {
+ seqPropertySet[nProperty].Value >>= sFilter;
+ }
+ else if( seqPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_TITLE )
+ {
+ seqPropertySet[nProperty].Value >>= sTitle;
+ }
+ else if( seqPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_PASSWORD )
+ {
+ seqPropertySet[nProperty].Value >>= sPassword;
+ }
+ }
+
+ aURL.SetSmartURL( sURL );
+ aURL.SetPass( SfxStringDecode( sPassword ) );
+
+ PickListEntry *pPick = new PickListEntry( aURL.GetMainURL( INetURLObject::NO_DECODE ), sFilter, sTitle );
+ m_aPicklistVector.push_back( pPick );
+ }
+}
+
+void SfxPickList::CreateMenuEntries( Menu* pMenu )
+{
+ static sal_Bool bPickListMenuInitializing = sal_False;
+
+ ::osl::MutexGuard aGuard( GetOrCreateMutex() );
+
+ if ( bPickListMenuInitializing ) // method is not reentrant!
+ return;
+
+ bPickListMenuInitializing = sal_True;
+ CreatePickListEntries();
+
+ for ( sal_uInt16 nId = START_ITEMID_PICKLIST; nId <= END_ITEMID_PICKLIST; ++nId )
+ pMenu->RemoveItem( pMenu->GetItemPos( nId ) );
+
+ if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR )
+ pMenu->RemoveItem( pMenu->GetItemCount()-1 );
+
+ if ( m_aPicklistVector.size() > 0 &&
+ pMenu->GetItemType( pMenu->GetItemCount()-1 )
+ != MENUITEM_SEPARATOR && m_nAllowedMenuSize )
+ pMenu->InsertSeparator();
+
+ rtl::OUString aEmptyString;
+ for ( sal_uInt32 i = 0; i < m_aPicklistVector.size(); i++ )
+ {
+ PickListEntry* pEntry = GetPickListEntry( i );
+
+ pMenu->InsertItem( (USHORT)(START_ITEMID_PICKLIST + i), aEmptyString );
+ CreatePicklistMenuTitle( pMenu, (USHORT)(START_ITEMID_PICKLIST + i), pEntry->aName, i );
+ }
+
+ bPickListMenuInitializing = sal_False;
+}
+
+void SfxPickList::ExecuteEntry( sal_uInt32 nIndex )
+{
+ ::osl::ClearableMutexGuard aGuard( GetOrCreateMutex() );
+
+ PickListEntry *pPick = SfxPickList::Get()->GetPickListEntry( nIndex );
+
+ if ( pPick )
+ {
+ SfxRequest aReq( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, SFX_APP()->GetPool() );
+ aReq.AppendItem( SfxStringItem( SID_FILE_NAME, pPick->aName ));
+ aReq.AppendItem( SfxStringItem( SID_REFERER, DEFINE_CONST_UNICODE( SFX_REFERER_USER ) ) );
+ aReq.AppendItem( SfxStringItem( SID_TARGETNAME, DEFINE_CONST_UNICODE("_default") ) );
+ String aFilter( pPick->aFilter );
+ aGuard.clear();
+
+ USHORT nPos=aFilter.Search('|');
+ if( nPos != STRING_NOTFOUND )
+ {
+ String aOptions(aFilter.Copy( nPos ).GetBuffer()+1);
+ aFilter.Erase( nPos );
+ aReq.AppendItem( SfxStringItem(SID_FILE_FILTEROPTIONS, aOptions));
+ }
+
+ aReq.AppendItem(SfxStringItem( SID_FILTER_NAME, aFilter ));
+ aReq.AppendItem( SfxBoolItem( SID_TEMPLATE, sal_False ) );
+ SFX_APP()->ExecuteSlot( aReq );
+ }
+}
+
+void SfxPickList::ExecuteMenuEntry( USHORT nId )
+{
+ ExecuteEntry( (sal_uInt32)( nId - START_ITEMID_PICKLIST ) );
+}
+
+String SfxPickList::GetMenuEntryTitle( sal_uInt32 nIndex )
+{
+ PickListEntry *pPick = SfxPickList::Get()->GetPickListEntry( nIndex );
+
+ if ( pPick )
+ return pPick->aTitle;
+ else
+ return String();
+}
+
+void SfxPickList::Notify( SfxBroadcaster&, const SfxHint& rHint )
+{
+ if ( rHint.IsA( TYPE( SfxStringHint )))
+ {
+ SfxStringHint* pStringHint = (SfxStringHint*) &rHint;
+
+ if ( pStringHint->GetId() == SID_OPENURL )
+ INetURLHistory::GetOrCreate()->PutUrl( INetURLObject( pStringHint->GetObject() ));
+ }
+
+ if ( rHint.IsA( TYPE( SfxEventHint )))
+ {
+ SfxEventHint* pEventHint = PTR_CAST(SfxEventHint,&rHint);
+ // nur ObjectShell-bezogene Events mit Medium interessieren
+ SfxObjectShell* pDocSh = pEventHint->GetObjShell();
+ if( !pDocSh )
+ return;
+
+ switch ( pEventHint->GetEventId() )
+ {
+ case SFX_EVENT_CREATEDOC:
+ {
+ sal_Bool bAllowModif = pDocSh->IsEnableSetModified();
+ if ( bAllowModif )
+ pDocSh->EnableSetModified( sal_False );
+
+ using namespace ::com::sun::star;
+ uno::Reference<document::XDocumentProperties> xDocProps(
+ pDocSh->getDocProperties());
+ if (xDocProps.is()) {
+ xDocProps->setAuthor( SvtUserOptions().GetFullName() );
+ ::DateTime now;
+ xDocProps->setCreationDate( util::DateTime(
+ now.Get100Sec(), now.GetSec(), now.GetMin(),
+ now.GetHour(), now.GetDay(), now.GetMonth(),
+ now.GetYear() ) );
+ }
+
+ if ( bAllowModif )
+ pDocSh->EnableSetModified( bAllowModif );
+ }
+ break;
+
+ case SFX_EVENT_OPENDOC:
+ {
+ SfxMedium *pMed = pDocSh->GetMedium();
+ if( !pMed )
+ return;
+
+ // unbenannt-Docs und embedded-Docs nicht in History
+ if ( !pDocSh->HasName() ||
+ SFX_CREATE_MODE_STANDARD != pDocSh->GetCreateMode() )
+ return;
+
+ // Hilfe nicht in History
+ INetURLObject aURL( pDocSh->IsDocShared() ? pDocSh->GetSharedFileURL() : ::rtl::OUString( pMed->GetOrigURL() ) );
+ if ( aURL.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP )
+ return;
+
+ ::rtl::OUString aTitle = pDocSh->GetTitle(SFX_TITLE_PICKLIST);
+ ::rtl::OUString aFilter;
+ const SfxFilter* pFilter = pMed->GetOrigFilter();
+ if ( pFilter )
+ aFilter = pFilter->GetFilterName();
+
+ // add to svtool history options
+ SvtHistoryOptions().AppendItem( eHISTORY,
+ aURL.GetURLNoPass( INetURLObject::NO_DECODE ),
+ aFilter,
+ aTitle,
+ SfxStringEncode( aURL.GetPass() ) );
+ }
+ break;
+
+ case SFX_EVENT_CLOSEDOC:
+ {
+ SfxMedium *pMed = pDocSh->GetMedium();
+ if( !pMed )
+ return;
+
+ // unbenannt-Docs und embedded-Docs nicht in Pickliste
+ if ( !pDocSh->HasName() ||
+ SFX_CREATE_MODE_STANDARD != pDocSh->GetCreateMode() )
+ return;
+
+ // Hilfe nicht in History
+ INetURLObject aURL( pDocSh->IsDocShared() ? pDocSh->GetSharedFileURL() : ::rtl::OUString( pMed->GetOrigURL() ) );
+ if ( aURL.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP )
+ return;
+
+ // only add r/w document into picklist
+ if ( pDocSh->IsReadOnly() || !pMed->IsUpdatePickList() )
+ return;
+
+ // add no document that forbids this (for example Message-Body)
+ SFX_ITEMSET_ARG( pMed->GetItemSet(), pPicklistItem, SfxBoolItem, SID_PICKLIST, sal_False );
+ if (
+ (pPicklistItem && !pPicklistItem->GetValue()) ||
+ (!(pDocSh->Get_Impl()->bWaitingForPicklist) )
+ )
+ return;
+
+ // ignore hidden documents
+ if ( !SfxViewFrame::GetFirst( pDocSh, TRUE ) )
+ return;
+
+ ::rtl::OUString aTitle = pDocSh->GetTitle(SFX_TITLE_PICKLIST);
+ ::rtl::OUString aFilter;
+ const SfxFilter* pFilter = pMed->GetOrigFilter();
+ if ( pFilter )
+ aFilter = pFilter->GetFilterName();
+
+ // add to svtool history options
+ SvtHistoryOptions().AppendItem( ePICKLIST,
+ aURL.GetURLNoPass( INetURLObject::NO_DECODE ),
+ aFilter,
+ aTitle,
+ SfxStringEncode( aURL.GetPass() ) );
+
+ pDocSh->Get_Impl()->bWaitingForPicklist = sal_False;
+
+ if ( aURL.GetProtocol() == INET_PROT_FILE )
+ Application::AddToRecentDocumentList( aURL.GetURLNoPass( INetURLObject::NO_DECODE ), (pFilter) ? pFilter->GetMimeType() : String() );
+ }
+ break;
+ }
+ }
+}
diff --git a/sfx2/source/appl/shutdownicon.cxx b/sfx2/source/appl/shutdownicon.cxx
new file mode 100644
index 000000000000..3c323b05fd72
--- /dev/null
+++ b/sfx2/source/appl/shutdownicon.cxx
@@ -0,0 +1,965 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <shutdownicon.hxx>
+#include <app.hrc>
+#include <sfx2/app.hxx>
+#include <vos/mutex.hxx>
+#include <svtools/imagemgr.hxx>
+#include <svtools/miscopt.hxx>
+// #include <cmdlineargs.hxx>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/frame/XDispatchResultListener.hpp>
+#include <com/sun/star/frame/XNotifyingDispatch.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
+#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
+#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/ControlActions.hpp>
+#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/document/UpdateDocMode.hpp>
+#include <sfx2/filedlghelper.hxx>
+#include <sfx2/fcontnr.hxx>
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+#include <cppuhelper/compbase1.hxx>
+#include <sfx2/dispatch.hxx>
+#include <comphelper/extract.hxx>
+#include <tools/urlobj.hxx>
+#include <osl/security.hxx>
+#include <osl/file.hxx>
+#include <rtl/bootstrap.hxx>
+#include <tools/link.hxx>
+#ifdef UNX // need symlink
+#include <unistd.h>
+#include <errno.h>
+#endif
+#include <vcl/timer.hxx>
+
+#include "sfx2/sfxresid.hxx"
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::ui::dialogs;
+using namespace ::vos;
+#ifdef WNT
+using ::rtl::OUString;
+#else
+using namespace ::rtl;
+#endif
+using namespace ::sfx2;
+
+#ifdef ENABLE_QUICKSTART_APPLET
+# if !defined(WIN32) && !defined(QUARTZ)
+extern "C" { static void SAL_CALL thisModule() {} }
+# endif
+#endif
+
+#if defined(UNX) && defined(ENABLE_SYSTRAY_GTK)
+#define PLUGIN_NAME "libqstart_gtkli.so"
+#endif
+
+class SfxNotificationListener_Impl : public cppu::WeakImplHelper1< XDispatchResultListener >
+{
+public:
+ virtual void SAL_CALL dispatchFinished( const DispatchResultEvent& aEvent ) throw( RuntimeException );
+ virtual void SAL_CALL disposing( const EventObject& aEvent ) throw( RuntimeException );
+};
+
+void SAL_CALL SfxNotificationListener_Impl::dispatchFinished( const DispatchResultEvent& ) throw( RuntimeException )
+{
+ ShutdownIcon::LeaveModalMode();
+}
+
+void SAL_CALL SfxNotificationListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
+{
+}
+
+SFX_IMPL_XSERVICEINFO( ShutdownIcon, "com.sun.star.office.Quickstart", "com.sun.star.comp.desktop.QuickstartWrapper" ) \
+SFX_IMPL_ONEINSTANCEFACTORY( ShutdownIcon );
+
+bool ShutdownIcon::bModalMode = false;
+ShutdownIcon* ShutdownIcon::pShutdownIcon = NULL;
+
+// To remove conditionals
+extern "C" {
+ static void disabled_initSystray() { }
+ static void disabled_deInitSystray() { }
+}
+#define DOSTRING( x ) #x
+#define STRING( x ) DOSTRING( x )
+
+bool ShutdownIcon::LoadModule( osl::Module **pModule,
+ oslGenericFunction *pInit,
+ oslGenericFunction *pDeInit )
+{
+ if ( pModule )
+ {
+ OSL_ASSERT ( pInit && pDeInit );
+ *pInit = *pDeInit = NULL;
+ *pModule = NULL;
+ }
+
+#ifdef ENABLE_QUICKSTART_APPLET
+# ifdef WIN32
+ if ( pModule )
+ {
+ *pInit = win32_init_sys_tray;
+ *pDeInit = win32_shutdown_sys_tray;
+ }
+ return true;
+# elif defined QUARTZ
+ *pInit = aqua_init_systray;
+ *pDeInit = aqua_shutdown_systray;
+ return true;
+# else // UNX
+ osl::Module *pPlugin;
+ pPlugin = new osl::Module();
+
+ oslGenericFunction pTmpInit = NULL;
+ oslGenericFunction pTmpDeInit = NULL;
+ if ( pPlugin->loadRelative( &thisModule, OUString (RTL_CONSTASCII_USTRINGPARAM( STRING( PLUGIN_NAME ) ) ) ) )
+ {
+ pTmpInit = pPlugin->getFunctionSymbol(
+ OUString( RTL_CONSTASCII_USTRINGPARAM( "plugin_init_sys_tray" ) ) );
+ pTmpDeInit = pPlugin->getFunctionSymbol(
+ OUString( RTL_CONSTASCII_USTRINGPARAM( "plugin_shutdown_sys_tray" ) ) );
+ }
+ if ( !pTmpInit || !pTmpDeInit )
+ {
+ delete pPlugin;
+ pPlugin = NULL;
+ }
+ if ( pModule )
+ {
+ *pModule = pPlugin;
+ *pInit = pTmpInit;
+ *pDeInit = pTmpDeInit;
+ }
+ else
+ {
+ bool bRet = pPlugin != NULL;
+ delete pPlugin;
+ return bRet;
+ }
+# endif // UNX
+#endif // ENABLE_QUICKSTART_APPLET
+ if ( pModule )
+ {
+ if ( !*pInit )
+ *pInit = disabled_initSystray;
+ if ( !*pDeInit )
+ *pDeInit = disabled_deInitSystray;
+ }
+
+ return true;
+}
+
+class IdleUnloader : Timer
+{
+ ::osl::Module *m_pModule;
+public:
+ IdleUnloader (::osl::Module **pModule) :
+ m_pModule (*pModule)
+ {
+ *pModule = NULL;
+ Start();
+ }
+ virtual void Timeout()
+ {
+ delete m_pModule;
+ delete this;
+ }
+};
+
+void ShutdownIcon::initSystray()
+{
+ if (m_bInitialized)
+ return;
+ m_bInitialized = true;
+
+ (void) LoadModule( &m_pPlugin, &m_pInitSystray, &m_pDeInitSystray );
+ m_bVeto = true;
+ m_pInitSystray();
+}
+
+void ShutdownIcon::deInitSystray()
+{
+ if (!m_bInitialized)
+ return;
+
+ if (m_pDeInitSystray)
+ m_pDeInitSystray();
+
+ m_bVeto = false;
+ m_pInitSystray = 0;
+ m_pDeInitSystray = 0;
+ new IdleUnloader (&m_pPlugin);
+
+ delete m_pFileDlg;
+ m_pFileDlg = NULL;
+ m_bInitialized = false;
+}
+
+
+ShutdownIcon::ShutdownIcon( Reference< XMultiServiceFactory > aSMgr ) :
+ ShutdownIconServiceBase( m_aMutex ),
+ m_bVeto ( false ),
+ m_bListenForTermination ( false ),
+ m_bSystemDialogs( false ),
+ m_pResMgr( NULL ),
+ m_pFileDlg( NULL ),
+ m_xServiceManager( aSMgr ),
+ m_pInitSystray( 0 ),
+ m_pDeInitSystray( 0 ),
+ m_pPlugin( 0 ),
+ m_bInitialized( false )
+{
+ m_bSystemDialogs = SvtMiscOptions().UseSystemFileDialog();
+}
+
+ShutdownIcon::~ShutdownIcon()
+{
+ deInitSystray();
+ new IdleUnloader (&m_pPlugin);
+}
+
+// ---------------------------------------------------------------------------
+
+void ShutdownIcon::OpenURL( const ::rtl::OUString& aURL, const ::rtl::OUString& rTarget, const Sequence< PropertyValue >& aArgs )
+{
+ if ( getInstance() && getInstance()->m_xDesktop.is() )
+ {
+ Reference < XDispatchProvider > xDispatchProvider( getInstance()->m_xDesktop, UNO_QUERY );
+ if ( xDispatchProvider.is() )
+ {
+ com::sun::star::util::URL aDispatchURL;
+ aDispatchURL.Complete = aURL;
+
+ Reference < com::sun::star::util::XURLTransformer > xURLTransformer(
+ ::comphelper::getProcessServiceFactory()->createInstance( OUString::createFromAscii("com.sun.star.util.URLTransformer") ),
+ com::sun::star::uno::UNO_QUERY );
+ if ( xURLTransformer.is() )
+ {
+ try
+ {
+ Reference< com::sun::star::frame::XDispatch > xDispatch;
+
+ xURLTransformer->parseStrict( aDispatchURL );
+ xDispatch = xDispatchProvider->queryDispatch( aDispatchURL, rTarget, 0 );
+ if ( xDispatch.is() )
+ xDispatch->dispatch( aDispatchURL, aArgs );
+ }
+ catch ( com::sun::star::uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch ( com::sun::star::uno::Exception& )
+ {
+ }
+ }
+ }
+ }
+}
+
+// ---------------------------------------------------------------------------
+
+void ShutdownIcon::FileOpen()
+{
+ if ( getInstance() && getInstance()->m_xDesktop.is() )
+ {
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ EnterModalMode();
+ getInstance()->StartFileDialog();
+ }
+}
+
+// ---------------------------------------------------------------------------
+
+void ShutdownIcon::FromTemplate()
+{
+ if ( getInstance() && getInstance()->m_xDesktop.is() )
+ {
+ Reference < ::com::sun::star::frame::XFramesSupplier > xDesktop ( getInstance()->m_xDesktop, UNO_QUERY);
+ Reference < ::com::sun::star::frame::XFrame > xFrame( xDesktop->getActiveFrame() );
+ if ( !xFrame.is() )
+ xFrame = Reference < ::com::sun::star::frame::XFrame >( xDesktop, UNO_QUERY );
+
+ URL aTargetURL;
+ aTargetURL.Complete = OUString( RTL_CONSTASCII_USTRINGPARAM( "slot:5500" ) );
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( aTargetURL );
+
+ Reference < ::com::sun::star::frame::XDispatchProvider > xProv( xFrame, UNO_QUERY );
+ Reference < ::com::sun::star::frame::XDispatch > xDisp;
+ if ( xProv.is() )
+ {
+ if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL )
+ xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
+ else
+ xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_blank"), 0 );
+ }
+ if ( xDisp.is() )
+ {
+ Sequence<PropertyValue> aArgs(1);
+ PropertyValue* pArg = aArgs.getArray();
+ pArg[0].Name = rtl::OUString::createFromAscii("Referer");
+ pArg[0].Value <<= ::rtl::OUString::createFromAscii("private:user");
+ Reference< ::com::sun::star::frame::XNotifyingDispatch > xNotifyer( xDisp, UNO_QUERY );
+ if ( xNotifyer.is() )
+ {
+ EnterModalMode();
+ xNotifyer->dispatchWithNotification( aTargetURL, aArgs, new SfxNotificationListener_Impl() );
+ }
+ else
+ xDisp->dispatch( aTargetURL, aArgs );
+ }
+ }
+}
+
+// ---------------------------------------------------------------------------
+#include <tools/rcid.h>
+OUString ShutdownIcon::GetResString( int id )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ if( ! m_pResMgr )
+ m_pResMgr = SfxResId::GetResMgr();
+ ResId aResId( id, *m_pResMgr );
+ aResId.SetRT( RSC_STRING );
+ if( !m_pResMgr || !m_pResMgr->IsAvailable( aResId ) )
+ return OUString();
+
+ UniString aRes( ResId(id, *m_pResMgr) );
+ return OUString( aRes );
+}
+
+// ---------------------------------------------------------------------------
+
+OUString ShutdownIcon::GetUrlDescription( const OUString& aUrl )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ return OUString( SvFileInformationManager::GetDescription( INetURLObject( aUrl ) ) );
+}
+
+// ---------------------------------------------------------------------------
+
+void ShutdownIcon::StartFileDialog()
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ bool bDirty = ( m_bSystemDialogs != static_cast<bool>(SvtMiscOptions().UseSystemFileDialog()) );
+
+ if ( m_pFileDlg && bDirty )
+ {
+ // Destroy instance as changing the system file dialog setting
+ // forces us to create a new FileDialogHelper instance!
+ delete m_pFileDlg;
+ m_pFileDlg = NULL;
+ }
+
+ if ( !m_pFileDlg )
+ m_pFileDlg = new FileDialogHelper( WB_OPEN | SFXWB_MULTISELECTION, String() );
+ m_pFileDlg->StartExecuteModal( STATIC_LINK( this, ShutdownIcon, DialogClosedHdl_Impl ) );
+}
+
+// ---------------------------------------------------------------------------
+
+IMPL_STATIC_LINK( ShutdownIcon, DialogClosedHdl_Impl, FileDialogHelper*, EMPTYARG )
+{
+ DBG_ASSERT( pThis->m_pFileDlg, "ShutdownIcon, DialogClosedHdl_Impl(): no file dialog" );
+
+ // use ctor for filling up filters automatically! #89169#
+ if ( ERRCODE_NONE == pThis->m_pFileDlg->GetError() )
+ {
+ Reference< XFilePicker > xPicker = pThis->m_pFileDlg->GetFilePicker();
+
+ try
+ {
+
+ if ( xPicker.is() )
+ {
+
+ Reference < XFilePickerControlAccess > xPickerControls ( xPicker, UNO_QUERY );
+ Reference < XFilterManager > xFilterManager ( xPicker, UNO_QUERY );
+
+ Sequence< OUString > sFiles = xPicker->getFiles();
+ int nFiles = sFiles.getLength();
+
+ int nArgs=3;
+ Sequence< PropertyValue > aArgs(3);
+
+ Reference < com::sun::star::task::XInteractionHandler > xInteraction(
+ ::comphelper::getProcessServiceFactory()->createInstance( OUString::createFromAscii("com.sun.star.task.InteractionHandler") ),
+ com::sun::star::uno::UNO_QUERY );
+
+ aArgs[0].Name = OUString::createFromAscii( "InteractionHandler" );
+ aArgs[0].Value <<= xInteraction;
+
+ sal_Int16 nMacroExecMode = ::com::sun::star::document::MacroExecMode::USE_CONFIG;
+ aArgs[1].Name = OUString::createFromAscii( "MacroExecutionMode" );
+ aArgs[1].Value <<= nMacroExecMode;
+
+ sal_Int16 nUpdateDoc = ::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG;
+ aArgs[2].Name = OUString::createFromAscii( "UpdateDocMode" );
+ aArgs[2].Value <<= nUpdateDoc;
+
+ // pb: #102643# use the filedlghelper to get the current filter name,
+ // because it removes the extensions before you get the filter name.
+ OUString aFilterName( pThis->m_pFileDlg->GetCurrentFilter() );
+
+ if ( xPickerControls.is() )
+ {
+
+ // Set readonly flag
+
+ sal_Bool bReadOnly = sal_False;
+
+
+ xPickerControls->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 ) >>= bReadOnly;
+
+ // #95239#: Only set porperty if readonly is set to TRUE
+
+ if ( bReadOnly )
+ {
+ aArgs.realloc( ++nArgs );
+ aArgs[nArgs-1].Name = OUString::createFromAscii( "ReadOnly" );
+ aArgs[nArgs-1].Value <<= bReadOnly;
+ }
+
+ // Get version string
+
+ sal_Int32 iVersion = -1;
+
+ xPickerControls->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION, ControlActions::GET_SELECTED_ITEM_INDEX ) >>= iVersion;
+
+ if ( iVersion >= 0 )
+ {
+ sal_Int16 uVersion = (sal_Int16)iVersion;
+
+ aArgs.realloc( ++nArgs );
+ aArgs[nArgs-1].Name = OUString::createFromAscii( "Version" );
+ aArgs[nArgs-1].Value <<= uVersion;
+ }
+
+ // Retrieve the current filter
+
+ if ( !aFilterName.getLength() )
+ xPickerControls->getValue( CommonFilePickerElementIds::LISTBOX_FILTER, ControlActions::GET_SELECTED_ITEM ) >>= aFilterName;
+
+ }
+
+
+ // Convert UI filter name to internal filter name
+
+ if ( aFilterName.getLength() )
+ {
+ const SfxFilter* pFilter = SFX_APP()->GetFilterMatcher().GetFilter4UIName( aFilterName, 0, SFX_FILTER_NOTINFILEDLG );
+
+ if ( pFilter )
+ {
+ aFilterName = pFilter->GetFilterName();
+
+ if ( aFilterName.getLength() )
+ {
+ aArgs.realloc( ++nArgs );
+ aArgs[nArgs-1].Name = OUString::createFromAscii( "FilterName" );
+ aArgs[nArgs-1].Value <<= aFilterName;
+ }
+ }
+ }
+
+ if ( 1 == nFiles )
+ OpenURL( sFiles[0], OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ), aArgs );
+ else
+ {
+ OUString aBaseDirURL = sFiles[0];
+ if ( aBaseDirURL.getLength() > 0 && aBaseDirURL[aBaseDirURL.getLength()-1] != '/' )
+ aBaseDirURL += OUString::createFromAscii("/");
+
+ int iFiles;
+ for ( iFiles = 1; iFiles < nFiles; iFiles++ )
+ {
+ OUString aURL = aBaseDirURL;
+ aURL += sFiles[iFiles];
+ OpenURL( aURL, OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ), aArgs );
+ }
+ }
+ }
+ }
+ catch ( ... )
+ {
+ }
+ }
+
+#ifdef WNT
+ // #103346 Destroy dialog to prevent problems with custom controls
+ // This fix is dependent on the dialog settings. Destroying the dialog here will
+ // crash the non-native dialog implementation! Therefore make this dependent on
+ // the settings.
+ if ( SvtMiscOptions().UseSystemFileDialog() )
+ {
+ delete pThis->m_pFileDlg;
+ pThis->m_pFileDlg = NULL;
+ }
+#endif
+
+ LeaveModalMode();
+ return 0;
+}
+
+// ---------------------------------------------------------------------------
+
+void ShutdownIcon::addTerminateListener()
+{
+ ShutdownIcon* pInst = getInstance();
+ if ( ! pInst)
+ return;
+
+ if (pInst->m_bListenForTermination)
+ return;
+
+ Reference< XDesktop > xDesktop = pInst->m_xDesktop;
+ if ( ! xDesktop.is())
+ return;
+
+ xDesktop->addTerminateListener( pInst );
+ pInst->m_bListenForTermination = true;
+}
+
+// ---------------------------------------------------------------------------
+
+void ShutdownIcon::terminateDesktop()
+{
+ ShutdownIcon* pInst = getInstance();
+ if ( ! pInst)
+ return;
+
+ Reference< XDesktop > xDesktop = pInst->m_xDesktop;
+ if ( ! xDesktop.is())
+ return;
+
+ // always remove ourselves as listener
+ xDesktop->removeTerminateListener( pInst );
+ pInst->m_bListenForTermination = true;
+
+ // terminate desktop only if no tasks exist
+ Reference< XFramesSupplier > xSupplier( xDesktop, UNO_QUERY );
+ if ( xSupplier.is() )
+ {
+ Reference< XIndexAccess > xTasks ( xSupplier->getFrames(), UNO_QUERY );
+ if( xTasks.is() )
+ {
+ if( xTasks->getCount() < 1 )
+ xDesktop->terminate();
+ }
+ }
+
+ // remove the instance pointer
+ ShutdownIcon::pShutdownIcon = 0;
+}
+
+// ---------------------------------------------------------------------------
+
+ShutdownIcon* ShutdownIcon::getInstance()
+{
+ OSL_ASSERT( pShutdownIcon );
+ return pShutdownIcon;
+}
+
+// ---------------------------------------------------------------------------
+
+ShutdownIcon* ShutdownIcon::createInstance()
+{
+ if (pShutdownIcon)
+ return pShutdownIcon;
+
+ ShutdownIcon *pIcon = NULL;
+ try {
+ Reference< XMultiServiceFactory > xSMgr( comphelper::getProcessServiceFactory() );
+ pIcon = new ShutdownIcon( xSMgr );
+ pIcon->init ();
+ pShutdownIcon = pIcon;
+ } catch (...) {
+ delete pIcon;
+ }
+
+ return pShutdownIcon;
+}
+
+void ShutdownIcon::init() throw( ::com::sun::star::uno::Exception )
+{
+ // access resource system and sfx only protected by solarmutex
+ vos::OGuard aSolarGuard( Application::GetSolarMutex() );
+ ResMgr *pResMgr = SfxResId::GetResMgr();
+
+ ::osl::ResettableMutexGuard aGuard( m_aMutex );
+ m_pResMgr = pResMgr;
+ aGuard.clear();
+ Reference < XDesktop > xDesktop( m_xServiceManager->createInstance(
+ DEFINE_CONST_UNICODE( "com.sun.star.frame.Desktop" )),
+ UNO_QUERY );
+ aGuard.reset();
+ m_xDesktop = xDesktop;
+}
+
+// ---------------------------------------------------------------------------
+
+void SAL_CALL ShutdownIcon::disposing()
+{
+ m_xServiceManager = Reference< XMultiServiceFactory >();
+ m_xDesktop = Reference< XDesktop >();
+}
+
+// ---------------------------------------------------------------------------
+
+// XEventListener
+void SAL_CALL ShutdownIcon::disposing( const ::com::sun::star::lang::EventObject& )
+ throw(::com::sun::star::uno::RuntimeException)
+{
+}
+
+// ---------------------------------------------------------------------------
+
+// XTerminateListener
+void SAL_CALL ShutdownIcon::queryTermination( const ::com::sun::star::lang::EventObject& )
+throw(::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException)
+{
+ ::osl::ClearableMutexGuard aGuard( m_aMutex );
+
+ if ( m_bVeto )
+ throw ::com::sun::star::frame::TerminationVetoException();
+}
+
+
+// ---------------------------------------------------------------------------
+
+void SAL_CALL ShutdownIcon::notifyTermination( const ::com::sun::star::lang::EventObject& )
+throw(::com::sun::star::uno::RuntimeException)
+{
+}
+
+
+// ---------------------------------------------------------------------------
+
+void SAL_CALL ShutdownIcon::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& aArguments )
+ throw( ::com::sun::star::uno::Exception )
+{
+ ::osl::ResettableMutexGuard aGuard( m_aMutex );
+
+ // third argument only sets veto, everything else will be ignored!
+ if (aArguments.getLength() > 2)
+ {
+ sal_Bool bVeto = sal_True;
+ bVeto = ::cppu::any2bool(aArguments[2]);
+ m_bVeto = bVeto;
+ return;
+ }
+
+ if ( aArguments.getLength() > 0 )
+ {
+ if ( !ShutdownIcon::pShutdownIcon )
+ {
+ try
+ {
+ sal_Bool bQuickstart = sal_False;
+ bQuickstart = ::cppu::any2bool( aArguments[0] );
+ if( !bQuickstart && !GetAutostart() )
+ return;
+ aGuard.clear();
+ init ();
+ aGuard.reset();
+ if ( !m_xDesktop.is() )
+ return;
+
+ /* Create a sub-classed instance - foo */
+ ShutdownIcon::pShutdownIcon = this;
+ initSystray();
+#ifdef OS2
+ // above win32 starts the quickstart thread, but we have
+ // quickstart running only when -quickstart is specified
+ // on command line (next boot).
+ // so if -quickstart was not specified, we cannot issue
+ // quickstart veto on shutdown.
+ if (bQuickstart)
+ {
+ // disable shutdown
+ ShutdownIcon::getInstance()->SetVeto( true );
+ ShutdownIcon::getInstance()->addTerminateListener();
+ }
+#endif
+ }
+ catch(const ::com::sun::star::lang::IllegalArgumentException&)
+ {
+ }
+ }
+ }
+ if ( aArguments.getLength() > 1 )
+ {
+ sal_Bool bAutostart = sal_False;
+ bAutostart = ::cppu::any2bool( aArguments[1] );
+ if (bAutostart && !GetAutostart())
+ SetAutostart( sal_True );
+ if (!bAutostart && GetAutostart())
+ SetAutostart( sal_False );
+ }
+
+}
+
+// -------------------------------
+
+void ShutdownIcon::EnterModalMode()
+{
+ bModalMode = TRUE;
+}
+
+// -------------------------------
+
+void ShutdownIcon::LeaveModalMode()
+{
+ bModalMode = FALSE;
+}
+
+#ifdef WNT
+// defined in shutdowniconw32.cxx
+#elif defined(OS2)
+// defined in shutdowniconOs2.cxx
+#elif defined QUARTZ
+// defined in shutdowniconaqua.cxx
+#else
+bool ShutdownIcon::IsQuickstarterInstalled()
+{
+#ifndef ENABLE_QUICKSTART_APPLET
+ return false;
+#else // !ENABLE_QUICKSTART_APPLET
+#ifdef UNX
+ return LoadModule( NULL, NULL, NULL);
+#endif // UNX
+#endif // !ENABLE_QUICKSTART_APPLET
+}
+#endif // !WNT
+
+// ---------------------------------------------------------------------------
+
+#if defined (ENABLE_QUICKSTART_APPLET) && defined (UNX)
+static OUString getDotAutostart( bool bCreate = false )
+{
+ OUString aShortcut;
+ const char *pConfigHome;
+ if( (pConfigHome = getenv("XDG_CONFIG_HOME") ) )
+ aShortcut = OStringToOUString( OString( pConfigHome ), RTL_TEXTENCODING_UTF8 );
+ else
+ {
+ OUString aHomeURL;
+ osl::Security().getHomeDir( aHomeURL );
+ ::osl::File::getSystemPathFromFileURL( aHomeURL, aShortcut );
+ aShortcut += OUString( RTL_CONSTASCII_USTRINGPARAM( "/.config" ) );
+ }
+ aShortcut += OUString( RTL_CONSTASCII_USTRINGPARAM( "/autostart" ) );
+ if (bCreate)
+ {
+ OUString aShortcutUrl;
+ osl::File::getFileURLFromSystemPath( aShortcut, aShortcutUrl );
+ osl::Directory::createPath( aShortcutUrl );
+ }
+ return aShortcut;
+}
+#endif
+
+rtl::OUString ShutdownIcon::getShortcutName()
+{
+#ifndef ENABLE_QUICKSTART_APPLET
+ return OUString();
+#else
+
+ OUString aShortcutName( RTL_CONSTASCII_USTRINGPARAM( "StarOffice 6.0" ) );
+ ResMgr* pMgr = SfxResId::GetResMgr();
+ if( pMgr )
+ {
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ UniString aRes( SfxResId( STR_QUICKSTART_LNKNAME ) );
+ aShortcutName = OUString( aRes );
+ }
+#ifdef WNT
+ aShortcutName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".lnk" ) );
+
+ OUString aShortcut(GetAutostartFolderNameW32());
+ aShortcut += OUString( RTL_CONSTASCII_USTRINGPARAM( "\\" ) );
+ aShortcut += aShortcutName;
+#else // UNX
+ OUString aShortcut = getDotAutostart();
+ aShortcut += OUString( RTL_CONSTASCII_USTRINGPARAM( "/qstart.desktop" ) );
+#endif // UNX
+ return aShortcut;
+#endif // ENABLE_QUICKSTART_APPLET
+}
+
+bool ShutdownIcon::GetAutostart( )
+{
+#if defined(OS2)
+ return GetAutostartOs2( );
+#elif defined QUARTZ
+ return true;
+#else
+ bool bRet = false;
+#ifdef ENABLE_QUICKSTART_APPLET
+ OUString aShortcut( getShortcutName() );
+ OUString aShortcutUrl;
+ osl::File::getFileURLFromSystemPath( aShortcut, aShortcutUrl );
+ osl::File f( aShortcutUrl );
+ osl::File::RC error = f.open( OpenFlag_Read );
+ if( error == osl::File::E_None )
+ {
+ f.close();
+ bRet = true;
+ }
+#endif // ENABLE_QUICKSTART_APPLET
+ return bRet;
+#endif
+}
+
+void ShutdownIcon::SetAutostart( bool bActivate )
+{
+#ifdef ENABLE_QUICKSTART_APPLET
+ OUString aShortcut( getShortcutName() );
+
+ if( bActivate && IsQuickstarterInstalled() )
+ {
+#ifdef WNT
+ EnableAutostartW32( aShortcut );
+#else // UNX
+ getDotAutostart( true );
+
+ OUString aPath( RTL_CONSTASCII_USTRINGPARAM("${BRAND_BASE_DIR}/share/xdg/qstart.desktop" ) );
+ Bootstrap::expandMacros( aPath );
+
+ OUString aDesktopFile;
+ ::osl::File::getSystemPathFromFileURL( aPath, aDesktopFile );
+
+ OString aDesktopFileUnx = OUStringToOString( aDesktopFile,
+ osl_getThreadTextEncoding() );
+ OString aShortcutUnx = OUStringToOString( aShortcut,
+ osl_getThreadTextEncoding() );
+ if ((0 != symlink(aDesktopFileUnx, aShortcutUnx)) && (errno == EEXIST))
+ {
+ unlink(aShortcutUnx);
+ symlink(aDesktopFileUnx, aShortcutUnx);
+ }
+
+ ShutdownIcon *pIcon = ShutdownIcon::createInstance();
+ if( pIcon )
+ pIcon->initSystray();
+#endif // UNX
+ }
+ else
+ {
+ OUString aShortcutUrl;
+ ::osl::File::getFileURLFromSystemPath( aShortcut, aShortcutUrl );
+ ::osl::File::remove( aShortcutUrl );
+#ifdef UNX
+ if (pShutdownIcon)
+ {
+ ShutdownIcon *pIcon = getInstance();
+ pIcon->deInitSystray();
+ }
+#endif
+ }
+#elif defined OS2
+ SetAutostartOs2( bActivate );
+#else
+ (void)bActivate; // unused variable
+#endif // ENABLE_QUICKSTART_APPLET
+}
+
+static const ::sal_Int32 PROPHANDLE_TERMINATEVETOSTATE = 0;
+
+// XFastPropertySet
+void SAL_CALL ShutdownIcon::setFastPropertyValue( ::sal_Int32 nHandle,
+ const ::com::sun::star::uno::Any& aValue )
+ throw (::com::sun::star::beans::UnknownPropertyException,
+ ::com::sun::star::beans::PropertyVetoException,
+ ::com::sun::star::lang::IllegalArgumentException,
+ ::com::sun::star::lang::WrappedTargetException,
+ ::com::sun::star::uno::RuntimeException)
+{
+ switch(nHandle)
+ {
+ case PROPHANDLE_TERMINATEVETOSTATE :
+ {
+ // use new value in case it's a valid information only
+ ::sal_Bool bState( sal_False );
+ if (! (aValue >>= bState))
+ return;
+
+ m_bVeto = bState;
+ if (m_bVeto && ! m_bListenForTermination)
+ addTerminateListener();
+ }
+ break;
+
+ default :
+ throw ::com::sun::star::beans::UnknownPropertyException();
+ }
+}
+
+// XFastPropertySet
+::com::sun::star::uno::Any SAL_CALL ShutdownIcon::getFastPropertyValue( ::sal_Int32 nHandle )
+ throw (::com::sun::star::beans::UnknownPropertyException,
+ ::com::sun::star::lang::WrappedTargetException,
+ ::com::sun::star::uno::RuntimeException)
+{
+ ::com::sun::star::uno::Any aValue;
+ switch(nHandle)
+ {
+ case PROPHANDLE_TERMINATEVETOSTATE :
+ {
+ bool bState = (m_bListenForTermination && m_bVeto);
+ aValue <<= bState;
+ }
+ break;
+
+ default :
+ throw ::com::sun::star::beans::UnknownPropertyException();
+ }
+
+ return aValue;
+}
diff --git a/sfx2/source/appl/shutdownicon.hxx b/sfx2/source/appl/shutdownicon.hxx
new file mode 100644
index 000000000000..d702f2a50977
--- /dev/null
+++ b/sfx2/source/appl/shutdownicon.hxx
@@ -0,0 +1,175 @@
+
+#ifndef __SHUTDOWNICON_HXX__
+#define __SHUTDOWNICON_HXX__
+
+#include <com/sun/star/frame/XTerminateListener.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/XEventListener.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/beans/XFastPropertySet.hpp>
+#ifndef _RTL_STRING_HXX
+#include <rtl/string.hxx>
+#endif
+#ifndef _RTL_USTRING_HXX
+#include <rtl/ustring.hxx>
+#endif
+#include <osl/mutex.hxx>
+#include <osl/module.hxx>
+#include <sfx2/sfxuno.hxx>
+#include <cppuhelper/compbase4.hxx>
+#include <sfx2/dllapi.h>
+
+class ResMgr;
+namespace sfx2
+{
+ class FileDialogHelper;
+}
+
+typedef ::cppu::WeakComponentImplHelper4<
+ ::com::sun::star::lang::XInitialization,
+ ::com::sun::star::frame::XTerminateListener,
+ ::com::sun::star::lang::XServiceInfo,
+ ::com::sun::star::beans::XFastPropertySet > ShutdownIconServiceBase;
+
+#if defined(USE_APP_SHORTCUTS)
+#define WRITER_URL "private:factory/swriter"
+#define CALC_URL "private:factory/scalc"
+#define IMPRESS_URL "private:factory/simpress"
+#define IMPRESS_WIZARD_URL "private:factory/simpress?slot=6686"
+#define DRAW_URL "private:factory/sdraw"
+#define MATH_URL "private:factory/smath"
+#define BASE_URL "private:factory/sdatabase?Interactive"
+#define STARTMODULE_URL ".uno:ShowStartModule"
+#endif
+
+class SFX2_DLLPUBLIC ShutdownIcon : public ShutdownIconServiceBase
+{
+ ::osl::Mutex m_aMutex;
+ bool m_bVeto;
+ bool m_bListenForTermination;
+ bool m_bSystemDialogs;
+ ResMgr* m_pResMgr;
+ sfx2::FileDialogHelper* m_pFileDlg;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
+
+ static ShutdownIcon *pShutdownIcon; // one instance
+
+ oslGenericFunction m_pInitSystray;
+ oslGenericFunction m_pDeInitSystray;
+ ::osl::Module *m_pPlugin;
+
+ bool m_bInitialized;
+ void initSystray();
+ void deInitSystray();
+
+ static bool LoadModule( osl::Module **pModule,
+ oslGenericFunction *pInit,
+ oslGenericFunction *pDeInit );
+ static void EnterModalMode();
+ static void LeaveModalMode();
+ static rtl::OUString getShortcutName();
+
+ friend class SfxNotificationListener_Impl;
+
+ public:
+ ShutdownIcon( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > aSMgr );
+
+ virtual ~ShutdownIcon();
+
+ SFX_DECL_XSERVICEINFO
+
+ static ShutdownIcon* getInstance();
+ static ShutdownIcon* createInstance();
+
+ static void terminateDesktop();
+ static void addTerminateListener();
+
+ static void FileOpen();
+ static void OpenURL( const ::rtl::OUString& aURL, const ::rtl::OUString& rTarget, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& =
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >( 0 ) );
+ static void FromTemplate();
+
+ static void SetAutostart( bool bActivate );
+ static bool GetAutostart();
+ static bool bModalMode;
+
+ void init() throw( ::com::sun::star::uno::Exception );
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >
+ GetWrapperFactory( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSMgr );
+ static ::rtl::OUString GetImplementationName_static();
+
+ ::rtl::OUString GetResString( int id );
+ ::rtl::OUString GetUrlDescription( const ::rtl::OUString& aUrl );
+
+ void SetVeto( bool bVeto ) { m_bVeto = bVeto;}
+ bool GetVeto() { return m_bVeto; }
+
+ void StartFileDialog();
+ sfx2::FileDialogHelper* GetFileDialog() const { return m_pFileDlg; }
+ static long DialogClosedHdl_Impl( ShutdownIcon*, sfx2::FileDialogHelper* );
+
+ static bool IsQuickstarterInstalled();
+
+ // Component Helper - force override
+ virtual void SAL_CALL disposing();
+
+ // XEventListener
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source )
+ throw(::com::sun::star::uno::RuntimeException);
+
+ // XTerminateListener
+ virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& aEvent )
+ throw(::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& aEvent )
+ throw(::com::sun::star::uno::RuntimeException);
+
+ // XInitialization
+ virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
+ throw( ::com::sun::star::uno::Exception );
+
+ // XFastPropertySet
+ virtual void SAL_CALL setFastPropertyValue( ::sal_Int32 nHandle,
+ const ::com::sun::star::uno::Any& aValue )
+ throw (::com::sun::star::beans::UnknownPropertyException,
+ ::com::sun::star::beans::PropertyVetoException,
+ ::com::sun::star::lang::IllegalArgumentException,
+ ::com::sun::star::lang::WrappedTargetException,
+ ::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Any SAL_CALL getFastPropertyValue( ::sal_Int32 nHandle )
+ throw (::com::sun::star::beans::UnknownPropertyException,
+ ::com::sun::star::lang::WrappedTargetException,
+ ::com::sun::star::uno::RuntimeException);
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDesktop > m_xDesktop;
+
+#ifdef WNT
+ static void EnableAutostartW32( const rtl::OUString &aShortcutName );
+ static rtl::OUString GetAutostartFolderNameW32();
+#endif
+#ifdef OS2
+ static void SetAutostartOs2( bool bActivate );
+ static bool GetAutostartOs2( );
+#endif
+};
+
+extern "C" {
+# ifdef WNT
+ // builtin win32 systray
+ void win32_init_sys_tray();
+ void win32_shutdown_sys_tray();
+# elif defined QUARTZ
+ void aqua_init_systray();
+ void aqua_shutdown_systray();
+# endif
+ // external plugin systray impl.
+ void plugin_init_sys_tray();
+ void plugin_shutdown_sys_tray();
+}
+
+#endif
diff --git a/sfx2/source/appl/shutdowniconOs2.cxx b/sfx2/source/appl/shutdowniconOs2.cxx
new file mode 100644
index 000000000000..936d6f925053
--- /dev/null
+++ b/sfx2/source/appl/shutdowniconOs2.cxx
@@ -0,0 +1,94 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+
+#include <unotools/moduleoptions.hxx>
+
+#include <unotools/dynamicmenuoptions.hxx>
+
+#include "shutdownicon.hxx"
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/task/XJob.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+
+
+using namespace ::rtl;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::task;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::beans;
+using namespace ::osl;
+
+//
+// This ObjectID must match the one created in WarpIN scripts!!
+//
+#define QUICKSTART_OBJID "OO2_QUICKSTART"
+
+bool ShutdownIcon::IsQuickstarterInstalled()
+{
+ HOBJECT hObject;
+ // Check quickstart icon presence
+ hObject = WinQueryObject( "<" QUICKSTART_OBJID ">");
+ if (hObject)
+ return true;
+ // object not found, quickstart not available
+ return false;
+}
+
+void ShutdownIcon::SetAutostartOs2( bool bActivate )
+{
+ HOBJECT hObject;
+
+ if( bActivate && IsQuickstarterInstalled() )
+ {
+ // place quickstart shadow in the startup folder
+ hObject = WinCreateObject( "WPShadow", "dummy",
+ "OBJECTID=<" QUICKSTART_OBJID "_SHW>;SHADOWID=<" QUICKSTART_OBJID ">;",
+ "<WP_START>",
+ CO_UPDATEIFEXISTS);
+ }
+ else
+ {
+ // remove quickstart shadow from the startup folder
+ hObject = WinQueryObject( "<" QUICKSTART_OBJID "_SHW>");
+ if (hObject)
+ WinDestroyObject( hObject);
+ }
+}
+
+bool ShutdownIcon::GetAutostartOs2( )
+{
+ // check for quickstart shadow in the startup folder
+ if (WinQueryObject( "<" QUICKSTART_OBJID "_SHW>"))
+ return true;
+ else
+ return false;
+}
+
+
diff --git a/sfx2/source/appl/shutdowniconaqua.mm b/sfx2/source/appl/shutdowniconaqua.mm
new file mode 100644
index 000000000000..14f12c79b53b
--- /dev/null
+++ b/sfx2/source/appl/shutdowniconaqua.mm
@@ -0,0 +1,510 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "unotools/moduleoptions.hxx"
+#include "unotools/dynamicmenuoptions.hxx"
+#include "unotools/historyoptions.hxx"
+#include "tools/urlobj.hxx"
+#include "osl/file.h"
+#include "comphelper/sequenceashashmap.hxx"
+#include "vos/mutex.hxx"
+#include "sfx2/app.hxx"
+#include "app.hrc"
+#define USE_APP_SHORTCUTS
+#include "shutdownicon.hxx"
+
+#include "com/sun/star/util/XStringWidth.hpp"
+
+#include "cppuhelper/implbase1.hxx"
+
+#include <set>
+#include <vector>
+
+#include "premac.h"
+#include <Cocoa/Cocoa.h>
+#include "postmac.h"
+
+using namespace ::rtl;
+using namespace ::osl;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::task;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::util;
+
+#define MI_OPEN 1
+#define MI_WRITER 2
+#define MI_CALC 3
+#define MI_IMPRESS 4
+#define MI_DRAW 5
+#define MI_BASE 6
+#define MI_MATH 7
+#define MI_TEMPLATE 8
+#define MI_STARTMODULE 9
+
+@interface QSMenuExecute : NSObject
+{
+}
+-(void)executeMenuItem: (NSMenuItem*)pItem;
+-(void)dockIconClicked: (NSObject*)pSender;
+@end
+
+@implementation QSMenuExecute
+-(void)executeMenuItem: (NSMenuItem*)pItem
+{
+ switch( [pItem tag] )
+ {
+ case MI_OPEN:
+ ShutdownIcon::FileOpen();
+ break;
+ case MI_WRITER:
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( WRITER_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case MI_CALC:
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( CALC_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case MI_IMPRESS:
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( IMPRESS_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case MI_DRAW:
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( DRAW_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case MI_BASE:
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( BASE_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case MI_MATH:
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( MATH_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case MI_TEMPLATE:
+ ShutdownIcon::FromTemplate();
+ break;
+ case MI_STARTMODULE:
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( STARTMODULE_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ default:
+ break;
+ }
+}
+
+-(void)dockIconClicked: (NSObject*)pSender
+{
+ // start start module
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( STARTMODULE_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+}
+
+@end
+
+bool ShutdownIcon::IsQuickstarterInstalled()
+{
+ return true;
+}
+
+static NSMenuItem* pDefMenu = nil, *pDockSubMenu = nil;
+static QSMenuExecute* pExecute = nil;
+
+static std::set< OUString > aShortcuts;
+
+static NSString* getAutoreleasedString( const rtl::OUString& rStr )
+{
+ return [[[NSString alloc] initWithCharacters: rStr.getStr() length: rStr.getLength()] autorelease];
+}
+
+struct RecentMenuEntry
+{
+ rtl::OUString aURL;
+ rtl::OUString aFilter;
+ rtl::OUString aTitle;
+ rtl::OUString aPassword;
+};
+
+class RecentFilesStringLength : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth >
+{
+ public:
+ RecentFilesStringLength() {}
+ virtual ~RecentFilesStringLength() {}
+
+ // XStringWidth
+ sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString )
+ throw (::com::sun::star::uno::RuntimeException)
+ {
+ return aString.getLength();
+ }
+};
+
+@interface RecentMenuDelegate : NSObject
+{
+ std::vector< RecentMenuEntry >* m_pRecentFilesItems;
+}
+-(id)init;
+-(void)dealloc;
+-(void)menuNeedsUpdate:(NSMenu *)menu;
+-(void)executeRecentEntry: (NSMenuItem*)item;
+@end
+
+@implementation RecentMenuDelegate
+-(id)init
+{
+ if( (self = [super init]) )
+ {
+ m_pRecentFilesItems = new std::vector< RecentMenuEntry >();
+ }
+ return self;
+}
+
+-(void)dealloc
+{
+ delete m_pRecentFilesItems;
+ [super dealloc];
+}
+
+-(void)menuNeedsUpdate:(NSMenu *)menu
+{
+ // clear menu
+ int nItems = [menu numberOfItems];
+ while( nItems -- )
+ [menu removeItemAtIndex: 0];
+
+ // update recent item list
+ Sequence< Sequence< PropertyValue > > aHistoryList( SvtHistoryOptions().GetList( ePICKLIST ) );
+
+ int nPickListMenuItems = ( aHistoryList.getLength() > 99 ) ? 99 : aHistoryList.getLength();
+
+ m_pRecentFilesItems->clear();
+ if( ( nPickListMenuItems > 0 ) )
+ {
+ for ( int i = 0; i < nPickListMenuItems; i++ )
+ {
+ Sequence< PropertyValue >& rPickListEntry = aHistoryList[i];
+ RecentMenuEntry aRecentFile;
+
+ for ( int j = 0; j < rPickListEntry.getLength(); j++ )
+ {
+ Any a = rPickListEntry[j].Value;
+
+ if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_URL )
+ a >>= aRecentFile.aURL;
+ else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_FILTER )
+ a >>= aRecentFile.aFilter;
+ else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_TITLE )
+ a >>= aRecentFile.aTitle;
+ else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_PASSWORD )
+ a >>= aRecentFile.aPassword;
+ }
+
+ m_pRecentFilesItems->push_back( aRecentFile );
+ }
+ }
+
+ // insert new recent items
+ for ( sal_uInt32 i = 0; i < m_pRecentFilesItems->size(); i++ )
+ {
+ rtl::OUString aMenuTitle;
+ INetURLObject aURL( (*m_pRecentFilesItems)[i].aURL );
+
+ if ( aURL.GetProtocol() == INET_PROT_FILE )
+ {
+ // Do handle file URL differently => convert it to a system
+ // path and abbreviate it with a special function:
+ String aFileSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) );
+
+ ::rtl::OUString aSystemPath( aFileSystemPath );
+ ::rtl::OUString aCompactedSystemPath;
+
+ oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, NULL );
+ if ( !nError )
+ aMenuTitle = String( aCompactedSystemPath );
+ else
+ aMenuTitle = aSystemPath;
+ }
+ else
+ {
+ // Use INetURLObject to abbreviate all other URLs
+ Reference< XStringWidth > xStringLength( new RecentFilesStringLength() );
+ aMenuTitle = aURL.getAbbreviated( xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS );
+ }
+
+ NSMenuItem* pNewItem = [[NSMenuItem alloc] initWithTitle: getAutoreleasedString( aMenuTitle )
+ action: @selector(executeRecentEntry:)
+ keyEquivalent: @""];
+ [pNewItem setTag: i];
+ [pNewItem setTarget: self];
+ [pNewItem setEnabled: YES];
+ [menu addItem: pNewItem];
+ [pNewItem autorelease];
+ }
+}
+
+-(void)executeRecentEntry: (NSMenuItem*)item
+{
+ sal_Int32 nIndex = [item tag];
+ if( ( nIndex >= 0 ) && ( nIndex < static_cast<sal_Int32>( m_pRecentFilesItems->size() ) ) )
+ {
+ const RecentMenuEntry& rRecentFile = (*m_pRecentFilesItems)[ nIndex ];
+ int NUM_OF_PICKLIST_ARGS = 3;
+ Sequence< PropertyValue > aArgsList( NUM_OF_PICKLIST_ARGS );
+
+ aArgsList[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" ));
+ aArgsList[0].Value = makeAny( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:user" ) ) );
+
+ // documents in the picklist will never be opened as templates
+ aArgsList[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AsTemplate" ));
+ aArgsList[1].Value = makeAny( (sal_Bool) sal_False );
+
+ ::rtl::OUString aFilter( rRecentFile.aFilter );
+ sal_Int32 nPos = aFilter.indexOf( '|' );
+ if ( nPos >= 0 )
+ {
+ rtl::OUString aFilterOptions;
+
+ if ( nPos < ( aFilter.getLength() - 1 ) )
+ aFilterOptions = aFilter.copy( nPos+1 );
+
+ aArgsList[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterOptions" ));
+ aArgsList[2].Value = makeAny( aFilterOptions );
+
+ aFilter = aFilter.copy( 0, nPos-1 );
+ aArgsList.realloc( ++NUM_OF_PICKLIST_ARGS );
+ }
+
+ aArgsList[NUM_OF_PICKLIST_ARGS-1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
+ aArgsList[NUM_OF_PICKLIST_ARGS-1].Value = makeAny( aFilter );
+
+ ShutdownIcon::OpenURL( rRecentFile.aURL, OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ), aArgsList );
+ }
+}
+@end
+
+static RecentMenuDelegate* pRecentDelegate = nil;
+
+static rtl::OUString getShortCut( const rtl::OUString i_rTitle )
+{
+ // create shortcut
+ rtl::OUString aKeyEquiv;
+ for( sal_Int32 nIndex = 0; nIndex < i_rTitle.getLength(); nIndex++ )
+ {
+ rtl::OUString aShortcut( i_rTitle.copy( nIndex, 1 ).toAsciiLowerCase() );
+ if( aShortcuts.find( aShortcut ) == aShortcuts.end() )
+ {
+ aShortcuts.insert( aShortcut );
+ aKeyEquiv = aShortcut;
+ break;
+ }
+ }
+
+ return aKeyEquiv;
+}
+
+static void appendMenuItem( NSMenu* i_pMenu, NSMenu* i_pDockMenu, const rtl::OUString& i_rTitle, int i_nTag, const rtl::OUString& i_rKeyEquiv )
+{
+ if( ! i_rTitle.getLength() )
+ return;
+
+ NSMenuItem* pItem = [[NSMenuItem alloc] initWithTitle: getAutoreleasedString( i_rTitle )
+ action: @selector(executeMenuItem:)
+ keyEquivalent: (i_rKeyEquiv.getLength() ? getAutoreleasedString( i_rKeyEquiv ) : @"")
+ ];
+ [pItem setTag: i_nTag];
+ [pItem setTarget: pExecute];
+ [pItem setEnabled: YES];
+ [i_pMenu addItem: pItem];
+
+ if( i_pDockMenu )
+ {
+ // create a similar entry in the dock menu
+ pItem = [[NSMenuItem alloc] initWithTitle: getAutoreleasedString( i_rTitle )
+ action: @selector(executeMenuItem:)
+ keyEquivalent: @""
+ ];
+ [pItem setTag: i_nTag];
+ [pItem setTarget: pExecute];
+ [pItem setEnabled: YES];
+ [i_pDockMenu addItem: pItem];
+ }
+}
+
+static void appendRecentMenu( NSMenu* i_pMenu, NSMenu* i_pDockMenu, const String& i_rTitle )
+{
+ if( ! pRecentDelegate )
+ pRecentDelegate = [[RecentMenuDelegate alloc] init];
+
+ NSMenuItem* pItem = [i_pMenu addItemWithTitle: getAutoreleasedString( i_rTitle )
+ action: @selector(executeMenuItem:)
+ keyEquivalent: @""
+ ];
+ [pItem setEnabled: YES];
+ NSMenu* pRecentMenu = [[NSMenu alloc] initWithTitle: getAutoreleasedString( i_rTitle ) ];
+ [pRecentMenu setDelegate: pRecentDelegate];
+ [pRecentMenu setAutoenablesItems: NO];
+ [pItem setSubmenu: pRecentMenu];
+
+ if( i_pDockMenu )
+ {
+ // create a similar entry in the dock menu
+ pItem = [i_pDockMenu addItemWithTitle: getAutoreleasedString( i_rTitle )
+ action: @selector(executeMenuItem:)
+ keyEquivalent: @""
+ ];
+ [pItem setEnabled: YES];
+ pRecentMenu = [[NSMenu alloc] initWithTitle: getAutoreleasedString( i_rTitle ) ];
+ [pRecentMenu setDelegate: pRecentDelegate];
+ [pRecentMenu setAutoenablesItems: NO];
+ [pItem setSubmenu: pRecentMenu];
+ }
+}
+
+
+extern "C"
+{
+
+void aqua_init_systray()
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance();
+ if( ! pShutdownIcon )
+ return;
+
+ // disable shutdown
+ pShutdownIcon->SetVeto( true );
+ pShutdownIcon->addTerminateListener();
+
+ if( ! pDefMenu )
+ {
+ if( [NSApp respondsToSelector: @selector(addFallbackMenuItem:)] )
+ {
+ aShortcuts.clear();
+
+ pExecute = [[QSMenuExecute alloc] init];
+ pDefMenu = [[NSMenuItem alloc] initWithTitle: getAutoreleasedString( pShutdownIcon->GetResString( STR_QUICKSTART_FILE ) ) action: NULL keyEquivalent: @""];
+ pDockSubMenu = [[NSMenuItem alloc] initWithTitle: getAutoreleasedString( pShutdownIcon->GetResString( STR_QUICKSTART_FILE ) ) action: NULL keyEquivalent: @""];
+ NSMenu* pMenu = [[NSMenu alloc] initWithTitle: getAutoreleasedString( pShutdownIcon->GetResString( STR_QUICKSTART_FILE ) )];
+ [pMenu setAutoenablesItems: NO];
+ NSMenu* pDockMenu = [[NSMenu alloc] initWithTitle: getAutoreleasedString( pShutdownIcon->GetResString( STR_QUICKSTART_FILE ) )];
+ [pDockMenu setAutoenablesItems: NO];
+
+ // collect the URLs of the entries in the File/New menu
+ SvtModuleOptions aModuleOptions;
+ std::set< rtl::OUString > aFileNewAppsAvailable;
+ SvtDynamicMenuOptions aOpt;
+ Sequence < Sequence < PropertyValue > > aNewMenu = aOpt.GetMenu( E_NEWMENU );
+ const rtl::OUString sURLKey( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
+
+ const Sequence< PropertyValue >* pNewMenu = aNewMenu.getConstArray();
+ const Sequence< PropertyValue >* pNewMenuEnd = aNewMenu.getConstArray() + aNewMenu.getLength();
+ for ( ; pNewMenu != pNewMenuEnd; ++pNewMenu )
+ {
+ comphelper::SequenceAsHashMap aEntryItems( *pNewMenu );
+ rtl::OUString sURL( aEntryItems.getUnpackedValueOrDefault( sURLKey, rtl::OUString() ) );
+ if ( sURL.getLength() )
+ aFileNewAppsAvailable.insert( sURL );
+ }
+
+ // describe the menu entries for launching the applications
+ struct MenuEntryDescriptor
+ {
+ SvtModuleOptions::EModule eModuleIdentifier;
+ int nMenuTag;
+ const char* pAsciiURLDescription;
+ } aMenuItems[] =
+ {
+ { SvtModuleOptions::E_SWRITER, MI_WRITER, WRITER_URL },
+ { SvtModuleOptions::E_SCALC, MI_CALC, CALC_URL },
+ { SvtModuleOptions::E_SIMPRESS, MI_IMPRESS, IMPRESS_WIZARD_URL },
+ { SvtModuleOptions::E_SDRAW, MI_DRAW, DRAW_URL },
+ { SvtModuleOptions::E_SDATABASE, MI_BASE, BASE_URL },
+ { SvtModuleOptions::E_SMATH, MI_MATH, MATH_URL }
+ };
+
+ // insert entry for startcenter
+ if( aModuleOptions.IsModuleInstalled( SvtModuleOptions::E_SSTARTMODULE ) )
+ {
+ appendMenuItem( pMenu, nil, pShutdownIcon->GetResString( STR_QUICKSTART_STARTCENTER ), MI_STARTMODULE, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "n" ) ) );
+ if( [NSApp respondsToSelector: @selector(setDockIconClickHandler:)] )
+ [NSApp performSelector:@selector(setDockIconClickHandler:) withObject: pExecute];
+ else
+ DBG_ERROR( "setDockIconClickHandler selector failed on NSApp\n" );
+
+ }
+
+ // insert the menu entries for launching the applications
+ for ( size_t i = 0; i < sizeof( aMenuItems ) / sizeof( aMenuItems[0] ); ++i )
+ {
+ if ( !aModuleOptions.IsModuleInstalled( aMenuItems[i].eModuleIdentifier ) )
+ // the complete application is not even installed
+ continue;
+
+ rtl::OUString sURL( ::rtl::OUString::createFromAscii( aMenuItems[i].pAsciiURLDescription ) );
+
+ if ( aFileNewAppsAvailable.find( sURL ) == aFileNewAppsAvailable.end() )
+ // the application is installed, but the entry has been configured to *not* appear in the File/New
+ // menu => also let not appear it in the quickstarter
+ continue;
+
+ rtl::OUString aKeyEquiv( getShortCut( pShutdownIcon->GetUrlDescription( sURL ) ) );
+
+ appendMenuItem( pMenu, pDockMenu, pShutdownIcon->GetUrlDescription( sURL ), aMenuItems[i].nMenuTag, aKeyEquiv );
+ }
+
+ // insert the remaining menu entries
+
+ // add recent menu
+ appendRecentMenu( pMenu, pDockMenu, pShutdownIcon->GetResString( STR_QUICKSTART_RECENTDOC ) );
+
+ rtl::OUString aTitle( pShutdownIcon->GetResString( STR_QUICKSTART_FROMTEMPLATE ) );
+ rtl::OUString aKeyEquiv( getShortCut( aTitle ) );
+ appendMenuItem( pMenu, pDockMenu, aTitle, MI_TEMPLATE, aKeyEquiv );
+ aTitle = pShutdownIcon->GetResString( STR_QUICKSTART_FILEOPEN );
+ aKeyEquiv = getShortCut( aTitle );
+ appendMenuItem( pMenu, pDockMenu, aTitle, MI_OPEN, aKeyEquiv );
+
+ [pDefMenu setSubmenu: pMenu];
+ [NSApp performSelector:@selector(addFallbackMenuItem:) withObject: pDefMenu];
+
+ if( [NSApp respondsToSelector: @selector(addDockMenuItem:)] )
+ {
+ [pDockSubMenu setSubmenu: pDockMenu];
+ // insert a separator to the dock menu
+ [NSApp performSelector:@selector(addDockMenuItem:) withObject: [NSMenuItem separatorItem]];
+ // and now add the submenu
+ [NSApp performSelector:@selector(addDockMenuItem:) withObject: pDockSubMenu];
+ }
+ else
+ DBG_ERROR( "addDockMenuItem selector failed on NSApp\n" );
+ }
+ else
+ DBG_ERROR( "addFallbackMenuItem selector failed on NSApp\n" );
+ }
+}
+
+void SAL_DLLPUBLIC_EXPORT aqua_shutdown_systray()
+{
+}
+
+}
diff --git a/sfx2/source/appl/shutdowniconunx.cxx b/sfx2/source/appl/shutdowniconunx.cxx
new file mode 100644
index 000000000000..b9799f5818b7
--- /dev/null
+++ b/sfx2/source/appl/shutdowniconunx.cxx
@@ -0,0 +1,409 @@
+
+#ifdef ENABLE_QUICKSTART_APPLET
+
+#include <unotools/moduleoptions.hxx>
+
+#include <unotools/dynamicmenuoptions.hxx>
+
+#include <gtk/gtk.h>
+#include <glib.h>
+#include <eggtray/eggtrayicon.h>
+#include <vos/mutex.hxx>
+#include <vcl/bitmapex.hxx>
+#include <vcl/bmpacc.hxx>
+#include <sfx2/app.hxx>
+#ifndef _SFX_APP_HRC
+#include "app.hrc"
+#endif
+#ifndef __SHUTDOWNICON_HXX__
+#define USE_APP_SHORTCUTS
+#include "shutdownicon.hxx"
+#endif
+
+// Cut/paste from vcl/inc/svids.hrc
+#define SV_ICON_SMALL_START 25000
+
+#define SV_ICON_ID_OFFICE 1
+#define SV_ICON_ID_TEXT 2
+#define SV_ICON_ID_SPREADSHEET 4
+#define SV_ICON_ID_DRAWING 6
+#define SV_ICON_ID_PRESENTATION 8
+#define SV_ICON_ID_DATABASE 14
+#define SV_ICON_ID_FORMULA 15
+#define SV_ICON_ID_TEMPLATE 16
+
+using namespace ::rtl;
+using namespace ::osl;
+
+static ResMgr *pVCLResMgr;
+static EggTrayIcon *pTrayIcon;
+static GtkWidget *pExitMenuItem = NULL;
+static GtkWidget *pOpenMenuItem = NULL;
+
+static void open_url_cb( GtkWidget *, gpointer data )
+{
+ ShutdownIcon::OpenURL( *(OUString *)data,
+ OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+}
+
+static void open_file_cb( GtkWidget * )
+{
+ if ( !ShutdownIcon::bModalMode )
+ ShutdownIcon::FileOpen();
+}
+
+static void open_template_cb( GtkWidget * )
+{
+ if ( !ShutdownIcon::bModalMode )
+ ShutdownIcon::FromTemplate();
+}
+
+static void systray_disable_cb()
+{
+ ShutdownIcon::SetAutostart( false );
+ ShutdownIcon::terminateDesktop();
+}
+
+static void exit_quickstarter_cb( GtkWidget * )
+{
+ egg_tray_icon_cancel_message (pTrayIcon, 1 );
+ ShutdownIcon::getInstance()->terminateDesktop();
+ plugin_shutdown_sys_tray();
+}
+
+static void menu_deactivate_cb( GtkWidget *pMenu )
+{
+ gtk_menu_popdown( GTK_MENU( pMenu ) );
+}
+
+static GdkPixbuf * ResIdToPixbuf( USHORT nResId )
+{
+ ResId aResId( SV_ICON_SMALL_START + nResId, *pVCLResMgr );
+ BitmapEx aIcon( aResId );
+ Bitmap pInSalBitmap = aIcon.GetBitmap();
+ AlphaMask pInSalAlpha = aIcon.GetAlpha();
+
+ BitmapReadAccess* pSalBitmap = pInSalBitmap.AcquireReadAccess();
+ BitmapReadAccess* pSalAlpha = pInSalAlpha.AcquireReadAccess();
+
+ g_return_val_if_fail( pSalBitmap != NULL, NULL );
+
+ Size aSize( pSalBitmap->Width(), pSalBitmap->Height() );
+ g_return_val_if_fail( Size( pSalAlpha->Width(), pSalAlpha->Height() ) == aSize, NULL );
+
+ int nX, nY;
+ guchar *pPixbufData = ( guchar * )g_malloc( 4 * aSize.Width() * aSize.Height() );
+ guchar *pDestData = pPixbufData;
+
+ for( nY = 0; nY < pSalBitmap->Height(); nY++ )
+ {
+ for( nX = 0; nX < pSalBitmap->Width(); nX++ )
+ {
+ BitmapColor aPix;
+ aPix = pSalBitmap->GetPixel( nY, nX );
+ pDestData[0] = aPix.GetRed();
+ pDestData[1] = aPix.GetGreen();
+ pDestData[2] = aPix.GetBlue();
+ if (pSalAlpha)
+ {
+ aPix = pSalAlpha->GetPixel( nY, nX );
+ pDestData[3] = 255 - aPix.GetIndex();
+ }
+ else
+ pDestData[3] = 255;
+ pDestData += 4;
+ }
+ }
+
+ pInSalBitmap.ReleaseAccess( pSalBitmap );
+ if( pSalAlpha )
+ pInSalAlpha.ReleaseAccess( pSalAlpha );
+
+ return gdk_pixbuf_new_from_data( pPixbufData,
+ GDK_COLORSPACE_RGB, TRUE, 8,
+ aSize.Width(), aSize.Height(),
+ aSize.Width() * 4,
+ (GdkPixbufDestroyNotify) g_free,
+ NULL );
+}
+
+extern "C" {
+static void oustring_delete (gpointer data,
+ GClosure * /* closure */)
+{
+ OUString *pURL = (OUString *) data;
+ delete pURL;
+}
+}
+
+static void add_item( GtkMenuShell *pMenuShell, const char *pAsciiURL,
+ OUString *pOverrideLabel,
+ USHORT nResId, GCallback pFnCallback )
+{
+ OUString *pURL = new OUString (OStringToOUString( pAsciiURL,
+ RTL_TEXTENCODING_UTF8 ));
+ OString aLabel;
+ if (pOverrideLabel)
+ aLabel = OUStringToOString (*pOverrideLabel, RTL_TEXTENCODING_UTF8);
+ else
+ {
+ ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance();
+ aLabel = OUStringToOString (pShutdownIcon->GetUrlDescription( *pURL ),
+ RTL_TEXTENCODING_UTF8);
+ }
+
+ GdkPixbuf *pPixbuf= ResIdToPixbuf( nResId );
+ GtkWidget *pImage = gtk_image_new_from_pixbuf( pPixbuf );
+ g_object_unref( G_OBJECT( pPixbuf ) );
+
+ GtkWidget *pMenuItem = gtk_image_menu_item_new_with_label( aLabel );
+ gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM( pMenuItem ), pImage );
+ g_signal_connect_data( pMenuItem, "activate", pFnCallback, pURL,
+ oustring_delete, GConnectFlags(0));
+
+ gtk_menu_shell_append( pMenuShell, pMenuItem );
+}
+
+// Unbelievably nasty
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::task;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::beans;
+
+static void add_ugly_db_item( GtkMenuShell *pMenuShell, const char *pAsciiURL,
+ USHORT nResId, GCallback pFnCallback )
+{
+ SvtDynamicMenuOptions aOpt;
+ Sequence < Sequence < PropertyValue > > aMenu = aOpt.GetMenu( E_NEWMENU );
+ for ( sal_Int32 n=0; n<aMenu.getLength(); n++ )
+ {
+ ::rtl::OUString aURL;
+ ::rtl::OUString aDescription;
+ Sequence < PropertyValue >& aEntry = aMenu[n];
+ for ( sal_Int32 m=0; m<aEntry.getLength(); m++ )
+ {
+ if ( aEntry[m].Name.equalsAsciiL( "URL", 3 ) )
+ aEntry[m].Value >>= aURL;
+ if ( aEntry[m].Name.equalsAsciiL( "Title", 5 ) )
+ aEntry[m].Value >>= aDescription;
+ }
+
+ if ( aURL.equalsAscii( BASE_URL ) && aDescription.getLength() )
+ {
+ add_item (pMenuShell, pAsciiURL, &aDescription, nResId, pFnCallback);
+ break;
+ }
+ }
+}
+
+static GtkWidget *
+add_image_menu_item( GtkMenuShell *pMenuShell,
+ const gchar *stock_id,
+ rtl::OUString aLabel,
+ GCallback activate_cb )
+{
+ OString aUtfLabel = rtl::OUStringToOString (aLabel, RTL_TEXTENCODING_UTF8 );
+
+ GtkWidget *pImage;
+ pImage = gtk_image_new_from_stock( stock_id, GTK_ICON_SIZE_MENU );
+
+ GtkWidget *pMenuItem;
+ pMenuItem = gtk_image_menu_item_new_with_label( aUtfLabel );
+ gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM( pMenuItem ), pImage );
+
+ gtk_menu_shell_append( pMenuShell, pMenuItem );
+ g_signal_connect( pMenuItem, "activate", activate_cb, NULL);
+
+ return pMenuItem;
+}
+
+static void populate_menu( GtkWidget *pMenu )
+{
+ ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance();
+ GtkMenuShell *pMenuShell = GTK_MENU_SHELL( pMenu );
+ SvtModuleOptions aModuleOptions;
+
+ if ( aModuleOptions.IsWriter() )
+ add_item (pMenuShell, WRITER_URL, NULL,
+ SV_ICON_ID_TEXT, G_CALLBACK( open_url_cb ));
+
+ if ( aModuleOptions.IsCalc() )
+ add_item (pMenuShell, CALC_URL, NULL,
+ SV_ICON_ID_SPREADSHEET, G_CALLBACK( open_url_cb ));
+
+ if ( aModuleOptions.IsImpress() )
+ add_item (pMenuShell, IMPRESS_URL, NULL,
+ SV_ICON_ID_PRESENTATION, G_CALLBACK( open_url_cb ));
+
+ if ( aModuleOptions.IsDraw() )
+ add_item (pMenuShell, DRAW_URL, NULL,
+ SV_ICON_ID_DRAWING, G_CALLBACK( open_url_cb ));
+
+ if ( aModuleOptions.IsDataBase() )
+ add_ugly_db_item (pMenuShell, BASE_URL,
+ SV_ICON_ID_DATABASE, G_CALLBACK( open_url_cb ));
+
+ if ( aModuleOptions.IsMath() )
+ add_item (pMenuShell, MATH_URL, NULL,
+ SV_ICON_ID_FORMULA, G_CALLBACK( open_url_cb ));
+
+ OUString aULabel = pShutdownIcon->GetResString( STR_QUICKSTART_FROMTEMPLATE );
+ add_item (pMenuShell, "dummy", &aULabel,
+ SV_ICON_ID_TEMPLATE, G_CALLBACK( open_template_cb ));
+
+ OString aLabel;
+ GtkWidget *pMenuItem;
+
+ pMenuItem = gtk_separator_menu_item_new();
+ gtk_menu_shell_append( pMenuShell, pMenuItem );
+
+ pOpenMenuItem = add_image_menu_item
+ (pMenuShell, GTK_STOCK_OPEN,
+ pShutdownIcon->GetResString( STR_QUICKSTART_FILEOPEN ),
+ G_CALLBACK( open_file_cb ));
+
+ pMenuItem = gtk_separator_menu_item_new();
+ gtk_menu_shell_append( pMenuShell, pMenuItem );
+
+ (void) add_image_menu_item
+ ( pMenuShell, GTK_STOCK_CLOSE,
+ pShutdownIcon->GetResString( STR_QUICKSTART_PRELAUNCH_UNX ),
+ G_CALLBACK( systray_disable_cb ) );
+
+ pMenuItem = gtk_separator_menu_item_new();
+ gtk_menu_shell_append( pMenuShell, pMenuItem );
+
+ pExitMenuItem = add_image_menu_item
+ ( pMenuShell, GTK_STOCK_QUIT,
+ pShutdownIcon->GetResString( STR_QUICKSTART_EXIT ),
+ G_CALLBACK( exit_quickstarter_cb ) );
+
+ gtk_widget_show_all( pMenu );
+}
+
+static void refresh_menu( GtkWidget *pMenu )
+{
+ if (!pExitMenuItem)
+ populate_menu( pMenu );
+
+ bool bModal = ShutdownIcon::bModalMode;
+ gtk_widget_set_sensitive( pExitMenuItem, !bModal);
+ gtk_widget_set_sensitive( pOpenMenuItem, !bModal);
+}
+
+extern "C" {
+static void
+layout_menu( GtkMenu *menu,
+ gint *x, gint *y, gboolean *push_in,
+ gpointer )
+{
+ GtkRequisition req;
+ GtkWidget *ebox = GTK_BIN( pTrayIcon )->child;
+
+ gtk_widget_size_request( GTK_WIDGET( menu ), &req );
+ gdk_window_get_origin( ebox->window, x, y );
+
+ (*x) += ebox->allocation.x;
+ (*y) += ebox->allocation.y;
+
+ if (*y >= gdk_screen_get_height (gtk_widget_get_screen (ebox)) / 2)
+ (*y) -= req.height;
+ else
+ (*y) += ebox->allocation.height;
+
+ *push_in = TRUE;
+}
+}
+
+static gboolean display_menu_cb( GtkWidget *,
+ GdkEventButton *event, GtkWidget *pMenu )
+{
+ if (event->button == 2)
+ return FALSE;
+
+#ifdef TEMPLATE_DIALOG_MORE_POLISHED
+ if (event->button == 1 &&
+ event->type == GDK_2BUTTON_PRESS)
+ {
+ open_template_cb( NULL );
+ return TRUE;
+ }
+ if (event->button == 3)
+ {
+ ... as below ...
+#endif
+
+ refresh_menu( pMenu );
+
+ gtk_menu_popup( GTK_MENU( pMenu ), NULL, NULL,
+ layout_menu, NULL, 0, event->time );
+
+ return TRUE;
+}
+
+extern "C" {
+ static gboolean
+ show_at_idle( gpointer )
+ {
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ gtk_widget_show_all( GTK_WIDGET( pTrayIcon ) );
+ return FALSE;
+ }
+}
+
+void SAL_DLLPUBLIC_EXPORT plugin_init_sys_tray()
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ if( !g_type_from_name( "GdkDisplay" ) )
+ return;
+
+ OString aLabel;
+ ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance();
+
+ aLabel = rtl::OUStringToOString (
+ pShutdownIcon->GetResString( STR_QUICKSTART_TIP ),
+ RTL_TEXTENCODING_UTF8 );
+
+ pTrayIcon = egg_tray_icon_new( aLabel );
+
+ GtkWidget *pParent = gtk_event_box_new();
+ GtkTooltips *pTooltips = gtk_tooltips_new();
+ gtk_tooltips_set_tip( GTK_TOOLTIPS( pTooltips ), pParent, aLabel, NULL );
+
+ GtkWidget *pIconImage = gtk_image_new();
+ gtk_container_add( GTK_CONTAINER( pParent ), pIconImage );
+
+ pVCLResMgr = CREATEVERSIONRESMGR( vcl );
+
+ GdkPixbuf *pPixbuf = ResIdToPixbuf( SV_ICON_ID_OFFICE );
+ gtk_image_set_from_pixbuf( GTK_IMAGE( pIconImage ), pPixbuf );
+ g_object_unref( pPixbuf );
+
+ GtkWidget *pMenu = gtk_menu_new();
+ g_signal_connect (pMenu, "deactivate",
+ G_CALLBACK (menu_deactivate_cb), NULL);
+ g_signal_connect( pParent, "button_press_event",
+ G_CALLBACK( display_menu_cb ), pMenu );
+ gtk_container_add( GTK_CONTAINER( pTrayIcon ), pParent );
+
+ // Show at idle to avoid artefacts at startup
+ g_idle_add (show_at_idle, (gpointer) pTrayIcon);
+
+ // disable shutdown
+ pShutdownIcon->SetVeto( true );
+ pShutdownIcon->addTerminateListener();
+}
+
+void SAL_DLLPUBLIC_EXPORT plugin_shutdown_sys_tray()
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if( !pTrayIcon )
+ return;
+ gtk_widget_destroy( GTK_WIDGET( pTrayIcon ) );
+ pTrayIcon = NULL;
+ pExitMenuItem = NULL;
+ pOpenMenuItem = NULL;
+}
+
+#endif // ENABLE_QUICKSTART_APPLET
diff --git a/sfx2/source/appl/shutdowniconw32.cxx b/sfx2/source/appl/shutdowniconw32.cxx
new file mode 100644
index 000000000000..26fd35272a51
--- /dev/null
+++ b/sfx2/source/appl/shutdowniconw32.cxx
@@ -0,0 +1,977 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifdef WNT
+
+// necessary to include system headers without warnings
+#ifdef _MSC_VER
+#pragma warning(disable:4668 4917)
+#endif
+
+// Support Windows 95 too
+#undef WINVER
+#define WINVER 0x0400
+#define USE_APP_SHORTCUTS
+//
+// the systray icon is only available on windows
+//
+
+#include <unotools/moduleoptions.hxx>
+#include <unotools/dynamicmenuoptions.hxx>
+
+#include "shutdownicon.hxx"
+#include "app.hrc"
+#include <shlobj.h>
+#include <objidl.h>
+#include <stdio.h>
+#include <io.h>
+#include <osl/thread.h>
+#include <setup_native/qswin32.h>
+#include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/task/XJob.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+
+#include <set>
+
+using namespace ::rtl;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::task;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::beans;
+using namespace ::osl;
+
+
+#define EXECUTER_WINDOWCLASS "SO Executer Class"
+#define EXECUTER_WINDOWNAME "SO Executer Window"
+
+
+#define ID_QUICKSTART 1
+#define IDM_EXIT 2
+#if defined(USE_APP_SHORTCUTS)
+# define IDM_OPEN 3
+# define IDM_WRITER 4
+# define IDM_CALC 5
+# define IDM_IMPRESS 6
+# define IDM_DRAW 7
+# define IDM_BASE 8
+# define IDM_TEMPLATE 9
+# define IDM_MATH 12
+#endif
+#define IDM_INSTALL 10
+#define IDM_UNINSTALL 11
+
+
+#define ICON_SO_DEFAULT 1
+#define ICON_TEXT_DOCUMENT 2
+#define ICON_TEXT_TEMPLATE 3
+#define ICON_SPREADSHEET_DOCUMENT 4
+#define ICON_SPREADSHEET_TEMPLATE 5
+#define ICON_DRAWING_DOCUMENT 6
+#define ICON_DRAWING_TEMPLATE 7
+#define ICON_PRESENTATION_DOCUMENT 8
+#define ICON_PRESENTATION_TEMPLATE 9
+#define ICON_PRESENTATION_COMPRESSED 10
+#define ICON_GLOBAL_DOCUMENT 11
+#define ICON_HTML_DOCUMENT 12
+#define ICON_CHART_DOCUMENT 13
+#define ICON_DATABASE_DOCUMENT 14
+#define ICON_MATH_DOCUMENT 15
+#define ICON_TEMPLATE 16
+#define ICON_MACROLIBRARY 17
+#define ICON_CONFIGURATION 18
+#define ICON_OPEN 5 // See index of open folder icon in shell32.dll
+#define ICON_SETUP 500
+
+#define SFX_TASKBAR_NOTIFICATION WM_USER+1
+
+static HWND aListenerWindow = NULL;
+static HWND aExecuterWindow = NULL;
+static HMENU popupMenu = NULL;
+
+static void OnMeasureItem(HWND hwnd, LPMEASUREITEMSTRUCT lpmis);
+static void OnDrawItem(HWND hwnd, LPDRAWITEMSTRUCT lpdis);
+
+typedef struct tagMYITEM
+{
+ OUString text;
+ OUString module;
+ UINT iconId;
+} MYITEM;
+
+// -------------------------------
+
+static bool isNT()
+{
+ static bool bInitialized = false;
+ static bool bWnt = false;
+
+ if( !bInitialized )
+ {
+ bInitialized = true;
+
+ OSVERSIONINFO aVerInfo;
+ aVerInfo.dwOSVersionInfoSize = sizeof( aVerInfo );
+ if ( GetVersionEx( &aVerInfo ) )
+ {
+ if ( aVerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
+ bWnt = true;
+ }
+ }
+ return bWnt;
+}
+
+
+// -------------------------------
+
+static void addMenuItem( HMENU hMenu, UINT id, UINT iconId, const OUString& text, int& pos, int bOwnerdraw, const OUString& module )
+{
+ MENUITEMINFOW mi;
+ memset( &mi, 0, sizeof( MENUITEMINFOW ) );
+
+ mi.cbSize = sizeof( MENUITEMINFOW );
+ if( id == -1 )
+ {
+ mi.fMask=MIIM_TYPE;
+ mi.fType=MFT_SEPARATOR;
+ }
+ else
+ {
+ if( bOwnerdraw )
+ {
+ mi.fMask=MIIM_TYPE | MIIM_STATE | MIIM_ID | MIIM_DATA;
+ mi.fType=MFT_OWNERDRAW;
+ mi.fState=MFS_ENABLED;
+ mi.wID = id;
+
+ MYITEM *pMyItem = new MYITEM;
+ pMyItem->text = text;
+ pMyItem->iconId = iconId;
+ pMyItem->module = module;
+ mi.dwItemData = (DWORD) pMyItem;
+ }
+ else
+ {
+ mi.fMask=MIIM_TYPE | MIIM_STATE | MIIM_ID | MIIM_DATA;
+ mi.fType=MFT_STRING;
+ mi.fState=MFS_ENABLED;
+ mi.wID = id;
+ mi.dwTypeData = (LPWSTR) text.getStr();
+ mi.cch = text.getLength();
+ }
+
+#if defined(USE_APP_SHORTCUTS)
+ if ( IDM_TEMPLATE == id )
+ mi.fState |= MFS_DEFAULT;
+#endif
+ }
+
+ InsertMenuItemW( hMenu, pos++, TRUE, &mi );
+}
+
+// -------------------------------
+
+static HMENU createSystrayMenu( )
+{
+ SvtModuleOptions aModuleOptions;
+
+ HMENU hMenu = CreatePopupMenu();
+ int pos=0;
+
+ ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance();
+ OSL_ENSURE( pShutdownIcon, "ShutdownIcon instance empty!");
+
+ if( !pShutdownIcon )
+ return NULL;
+
+#if defined(USE_APP_SHORTCUTS)
+ // collect the URLs of the entries in the File/New menu
+ ::std::set< ::rtl::OUString > aFileNewAppsAvailable;
+ SvtDynamicMenuOptions aOpt;
+ Sequence < Sequence < PropertyValue > > aNewMenu = aOpt.GetMenu( E_NEWMENU );
+ const ::rtl::OUString sURLKey( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
+
+ const Sequence< PropertyValue >* pNewMenu = aNewMenu.getConstArray();
+ const Sequence< PropertyValue >* pNewMenuEnd = aNewMenu.getConstArray() + aNewMenu.getLength();
+ for ( ; pNewMenu != pNewMenuEnd; ++pNewMenu )
+ {
+ ::comphelper::SequenceAsHashMap aEntryItems( *pNewMenu );
+ ::rtl::OUString sURL( aEntryItems.getUnpackedValueOrDefault( sURLKey, ::rtl::OUString() ) );
+ if ( sURL.getLength() )
+ aFileNewAppsAvailable.insert( sURL );
+ }
+
+ // describe the menu entries for launching the applications
+ struct MenuEntryDescriptor
+ {
+ SvtModuleOptions::EModule eModuleIdentifier;
+ UINT nMenuItemID;
+ UINT nMenuIconID;
+ const char* pAsciiURLDescription;
+ } aMenuItems[] =
+ {
+ { SvtModuleOptions::E_SWRITER, IDM_WRITER, ICON_TEXT_DOCUMENT, WRITER_URL },
+ { SvtModuleOptions::E_SCALC, IDM_CALC, ICON_SPREADSHEET_DOCUMENT, CALC_URL },
+ { SvtModuleOptions::E_SIMPRESS, IDM_IMPRESS,ICON_PRESENTATION_DOCUMENT, IMPRESS_WIZARD_URL },
+ { SvtModuleOptions::E_SDRAW, IDM_DRAW, ICON_DRAWING_DOCUMENT, DRAW_URL },
+ { SvtModuleOptions::E_SDATABASE, IDM_BASE, ICON_DATABASE_DOCUMENT, BASE_URL },
+ { SvtModuleOptions::E_SMATH, IDM_MATH, ICON_MATH_DOCUMENT, MATH_URL },
+ };
+
+ OUString aEmpty;
+
+ // insert the menu entries for launching the applications
+ for ( size_t i = 0; i < sizeof( aMenuItems ) / sizeof( aMenuItems[0] ); ++i )
+ {
+ if ( !aModuleOptions.IsModuleInstalled( aMenuItems[i].eModuleIdentifier ) )
+ // the complete application is not even installed
+ continue;
+
+ ::rtl::OUString sURL( ::rtl::OUString::createFromAscii( aMenuItems[i].pAsciiURLDescription ) );
+
+ if ( aFileNewAppsAvailable.find( sURL ) == aFileNewAppsAvailable.end() )
+ // the application is installed, but the entry has been configured to *not* appear in the File/New
+ // menu => also let not appear it in the quickstarter
+ continue;
+
+ addMenuItem( hMenu, aMenuItems[i].nMenuItemID, aMenuItems[i].nMenuIconID,
+ pShutdownIcon->GetUrlDescription( sURL ), pos, true, aEmpty );
+ }
+
+
+
+ // insert the remaining menu entries
+ addMenuItem( hMenu, IDM_TEMPLATE, ICON_TEMPLATE,
+ pShutdownIcon->GetResString( STR_QUICKSTART_FROMTEMPLATE ), pos, true, aEmpty);
+ addMenuItem( hMenu, static_cast< UINT >( -1 ), 0, OUString(), pos, false, aEmpty );
+ addMenuItem( hMenu, IDM_OPEN, ICON_OPEN, pShutdownIcon->GetResString( STR_QUICKSTART_FILEOPEN ), pos, true, OUString::createFromAscii( "SHELL32" ));
+ addMenuItem( hMenu, static_cast< UINT >( -1 ), 0, OUString(), pos, false, aEmpty );
+#endif
+ addMenuItem( hMenu, IDM_INSTALL,0, pShutdownIcon->GetResString( STR_QUICKSTART_PRELAUNCH ), pos, false, aEmpty );
+ addMenuItem( hMenu, static_cast< UINT >( -1 ), 0, OUString(), pos, false, aEmpty );
+ addMenuItem( hMenu, IDM_EXIT, 0, pShutdownIcon->GetResString( STR_QUICKSTART_EXIT ), pos, false, aEmpty );
+
+ // indicate status of autostart folder
+ CheckMenuItem( hMenu, IDM_INSTALL, MF_BYCOMMAND | (ShutdownIcon::GetAutostart() ? MF_CHECKED : MF_UNCHECKED) );
+
+ return hMenu;
+}
+
+// -------------------------------
+
+static void deleteSystrayMenu( HMENU hMenu )
+{
+ if( !hMenu || !IsMenu( hMenu ))
+ return;
+
+ MENUITEMINFOW mi;
+ MYITEM *pMyItem;
+ int pos=0;
+ memset( &mi, 0, sizeof( mi ) );
+ mi.cbSize = sizeof( mi );
+ mi.fMask = MIIM_DATA;
+
+ while( GetMenuItemInfoW( hMenu, pos++, true, &mi ) )
+ {
+ pMyItem = (MYITEM*) mi.dwItemData;
+ if( pMyItem )
+ {
+ pMyItem->text = OUString();
+ delete pMyItem;
+ }
+ mi.fMask = MIIM_DATA;
+ }
+}
+
+// -------------------------------
+
+static void addTaskbarIcon( HWND hWnd )
+{
+ OUString strTip;
+ if( ShutdownIcon::getInstance() )
+ strTip = ShutdownIcon::getInstance()->GetResString( STR_QUICKSTART_TIP );
+
+ // add taskbar icon
+ NOTIFYICONDATAA nid;
+ nid.hIcon = (HICON)LoadImageA( GetModuleHandle( NULL ), MAKEINTRESOURCE( ICON_SO_DEFAULT ),
+ IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
+ LR_DEFAULTCOLOR | LR_SHARED );
+
+ // better use unicode wrapper here ?
+ strncpy( nid.szTip, ( OUStringToOString(strTip, osl_getThreadTextEncoding()).getStr() ), 64 );
+
+ nid.cbSize = sizeof(nid);
+ nid.hWnd = hWnd;
+ nid.uID = ID_QUICKSTART;
+ nid.uCallbackMessage = SFX_TASKBAR_NOTIFICATION;
+ nid.uFlags = NIF_MESSAGE|NIF_TIP|NIF_ICON;
+
+ Shell_NotifyIconA(NIM_ADD, &nid);
+}
+
+// -------------------------------
+
+/*
+static void removeTaskbarIcon()
+{
+ ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance();
+ OSL_ENSURE( pShutdownIcon, "ShutdownIcon instance empty!");
+
+ if( !pShutdownIcon )
+ return;
+
+ if ( IsWindow( aListenerWindow ))
+ {
+ deleteSystrayMenu( popupMenu );
+
+ NOTIFYICONDATAA nid;
+ nid.cbSize=sizeof(NOTIFYICONDATA);
+ nid.hWnd = aListenerWindow;
+ nid.uID = ID_QUICKSTART;
+ Shell_NotifyIconA(NIM_DELETE, &nid);
+ }
+}
+*/
+
+// -------------------------------
+
+LRESULT CALLBACK listenerWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ static UINT s_uTaskbarRestart = 0;
+ static UINT s_uMsgKillTray = 0;
+
+ switch (uMsg)
+ {
+ case WM_NCCREATE:
+ return TRUE;
+ case WM_CREATE:
+ {
+ // request notfication when taskbar is recreated
+ // we then have to add our icon again
+ s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
+ s_uMsgKillTray = RegisterWindowMessage( SHUTDOWN_QUICKSTART_MESSAGE );
+
+ // create the menu
+ if( !popupMenu )
+ if( (popupMenu = createSystrayMenu( )) == NULL )
+ return -1;
+
+ // and the icon
+ addTaskbarIcon( hWnd );
+
+ // disable shutdown
+ ShutdownIcon::getInstance()->SetVeto( true );
+ ShutdownIcon::getInstance()->addTerminateListener();
+ }
+ return 0;
+
+ case WM_MEASUREITEM:
+ OnMeasureItem(hWnd, (LPMEASUREITEMSTRUCT) lParam);
+ return TRUE;
+
+ case WM_DRAWITEM:
+ OnDrawItem(hWnd, (LPDRAWITEMSTRUCT) lParam);
+ return TRUE;
+
+ case SFX_TASKBAR_NOTIFICATION:
+ switch( lParam )
+ {
+ case WM_LBUTTONDBLCLK:
+#if defined(USE_APP_SHORTCUTS)
+ PostMessage( aExecuterWindow, WM_COMMAND, IDM_TEMPLATE, (LPARAM)hWnd );
+#endif
+ break;
+
+ case WM_RBUTTONDOWN:
+ {
+ POINT pt;
+ GetCursorPos(&pt);
+ SetForegroundWindow( hWnd );
+
+ // update status before showing menu, could have been changed from option page
+ CheckMenuItem( popupMenu, IDM_INSTALL, MF_BYCOMMAND| (ShutdownIcon::GetAutostart() ? MF_CHECKED : MF_UNCHECKED) );
+
+ EnableMenuItem( popupMenu, IDM_EXIT, MF_BYCOMMAND | (ShutdownIcon::bModalMode ? MF_GRAYED : MF_ENABLED) );
+#if defined(USE_APP_SHORTCUTS)
+ EnableMenuItem( popupMenu, IDM_OPEN, MF_BYCOMMAND | (ShutdownIcon::bModalMode ? MF_GRAYED : MF_ENABLED) );
+ EnableMenuItem( popupMenu, IDM_TEMPLATE, MF_BYCOMMAND | (ShutdownIcon::bModalMode ? MF_GRAYED : MF_ENABLED) );
+#endif
+ int m = TrackPopupMenuEx( popupMenu, TPM_RETURNCMD|TPM_LEFTALIGN|TPM_RIGHTBUTTON,
+ pt.x, pt.y, hWnd, NULL );
+ // BUGFIX: See Q135788 (PRB: Menus for Notification Icons Don't Work Correctly)
+ PostMessage( hWnd, NULL, 0, 0 );
+ switch( m )
+ {
+#if defined(USE_APP_SHORTCUTS)
+ case IDM_OPEN:
+ case IDM_WRITER:
+ case IDM_CALC:
+ case IDM_IMPRESS:
+ case IDM_DRAW:
+ case IDM_TEMPLATE:
+ case IDM_BASE:
+ case IDM_MATH:
+ break;
+#endif
+ case IDM_INSTALL:
+ CheckMenuItem( popupMenu, IDM_INSTALL, MF_BYCOMMAND| (ShutdownIcon::GetAutostart() ? MF_CHECKED : MF_UNCHECKED) );
+ break;
+ case IDM_EXIT:
+ // delete taskbar icon
+ NOTIFYICONDATAA nid;
+ nid.cbSize=sizeof(NOTIFYICONDATA);
+ nid.hWnd = hWnd;
+ nid.uID = ID_QUICKSTART;
+ Shell_NotifyIconA(NIM_DELETE, &nid);
+ break;
+ }
+
+ PostMessage( aExecuterWindow, WM_COMMAND, m, (LPARAM)hWnd );
+ }
+ break;
+ }
+ break;
+ case WM_DESTROY:
+ deleteSystrayMenu( popupMenu );
+ // We don't need the Systray Thread anymore
+ PostQuitMessage( 0 );
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ default:
+ if( uMsg == s_uTaskbarRestart )
+ {
+ // re-create taskbar icon
+ addTaskbarIcon( hWnd );
+ }
+ else if ( uMsg == s_uMsgKillTray )
+ {
+ // delete taskbar icon
+ NOTIFYICONDATAA nid;
+ nid.cbSize=sizeof(NOTIFYICONDATA);
+ nid.hWnd = hWnd;
+ nid.uID = ID_QUICKSTART;
+ Shell_NotifyIconA(NIM_DELETE, &nid);
+
+ PostMessage( aExecuterWindow, WM_COMMAND, IDM_EXIT, (LPARAM)hWnd );
+ }
+ else
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ }
+ return 0;
+}
+
+// -------------------------------
+
+static sal_Bool checkOEM() {
+ Reference<XMultiServiceFactory> rFactory = ::comphelper::getProcessServiceFactory();
+ Reference<XJob> rOemJob(rFactory->createInstance(
+ OUString::createFromAscii("com.sun.star.office.OEMPreloadJob")),
+ UNO_QUERY );
+ Sequence<NamedValue> args;
+ sal_Bool bResult = sal_False;
+ if (rOemJob.is())
+ {
+ Any aResult = rOemJob->execute(args);
+ aResult >>= bResult;
+ } else bResult = sal_True;
+ return bResult;
+}
+
+LRESULT CALLBACK executerWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg)
+ {
+ case WM_NCCREATE:
+ return TRUE;
+ case WM_CREATE:
+ return 0;
+
+ case WM_COMMAND:
+ switch( LOWORD(wParam) )
+ {
+#if defined(USE_APP_SHORTCUTS)
+ case IDM_OPEN:
+ if ( !ShutdownIcon::bModalMode && checkOEM() )
+ ShutdownIcon::FileOpen();
+ break;
+ case IDM_WRITER:
+ if (checkOEM())
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( WRITER_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case IDM_CALC:
+ if (checkOEM())
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( CALC_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case IDM_IMPRESS:
+ if (checkOEM())
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( IMPRESS_WIZARD_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case IDM_DRAW:
+ if (checkOEM())
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( DRAW_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case IDM_BASE:
+ if (checkOEM())
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( BASE_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case IDM_MATH:
+ if (checkOEM())
+ ShutdownIcon::OpenURL( OUString( RTL_CONSTASCII_USTRINGPARAM( MATH_URL ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
+ break;
+ case IDM_TEMPLATE:
+ if ( !ShutdownIcon::bModalMode && checkOEM())
+ ShutdownIcon::FromTemplate();
+ break;
+#endif
+ case IDM_INSTALL:
+ ShutdownIcon::SetAutostart( !ShutdownIcon::GetAutostart() );
+ break;
+ case IDM_EXIT:
+ // remove listener and
+ // terminate office if running in background
+ if ( !ShutdownIcon::bModalMode )
+ ShutdownIcon::terminateDesktop();
+ break;
+ }
+ break;
+ case WM_DESTROY:
+ default:
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ }
+ return 0;
+}
+
+// -------------------------------
+
+
+DWORD WINAPI SystrayThread( LPVOID /*lpParam*/ )
+{
+ aListenerWindow = CreateWindowExA(0,
+ QUICKSTART_CLASSNAME, // registered class name
+ QUICKSTART_WINDOWNAME, // window name
+ 0, // window style
+ CW_USEDEFAULT, // horizontal position of window
+ CW_USEDEFAULT, // vertical position of window
+ CW_USEDEFAULT, // window width
+ CW_USEDEFAULT, // window height
+ (HWND) NULL, // handle to parent or owner window
+ NULL, // menu handle or child identifier
+ (HINSTANCE) GetModuleHandle( NULL ), // handle to application instance
+ NULL // window-creation data
+ );
+
+ MSG msg;
+
+ while ( GetMessage( &msg, NULL, 0, 0 ) )
+ {
+ TranslateMessage( &msg );
+ DispatchMessage( &msg );
+ }
+
+ return msg.wParam; // Exit code of WM_QUIT
+}
+
+// -------------------------------
+
+void win32_init_sys_tray()
+{
+ if ( ShutdownIcon::IsQuickstarterInstalled() )
+ {
+ WNDCLASSEXA listenerClass;
+ listenerClass.cbSize = sizeof(WNDCLASSEX);
+ listenerClass.style = 0;
+ listenerClass.lpfnWndProc = listenerWndProc;
+ listenerClass.cbClsExtra = 0;
+ listenerClass.cbWndExtra = 0;
+ listenerClass.hInstance = (HINSTANCE) GetModuleHandle( NULL );
+ listenerClass.hIcon = NULL;
+ listenerClass.hCursor = NULL;
+ listenerClass.hbrBackground = NULL;
+ listenerClass.lpszMenuName = NULL;
+ listenerClass.lpszClassName = QUICKSTART_CLASSNAME;
+ listenerClass.hIconSm = NULL;
+
+ RegisterClassExA(&listenerClass);
+
+ WNDCLASSEXA executerClass;
+ executerClass.cbSize = sizeof(WNDCLASSEX);
+ executerClass.style = 0;
+ executerClass.lpfnWndProc = executerWndProc;
+ executerClass.cbClsExtra = 0;
+ executerClass.cbWndExtra = 0;
+ executerClass.hInstance = (HINSTANCE) GetModuleHandle( NULL );
+ executerClass.hIcon = NULL;
+ executerClass.hCursor = NULL;
+ executerClass.hbrBackground = NULL;
+ executerClass.lpszMenuName = NULL;
+ executerClass.lpszClassName = EXECUTER_WINDOWCLASS;
+ executerClass.hIconSm = NULL;
+
+ RegisterClassExA( &executerClass );
+
+ aExecuterWindow = CreateWindowExA(0,
+ EXECUTER_WINDOWCLASS, // registered class name
+ EXECUTER_WINDOWNAME, // window name
+ 0, // window style
+ CW_USEDEFAULT, // horizontal position of window
+ CW_USEDEFAULT, // vertical position of window
+ CW_USEDEFAULT, // window width
+ CW_USEDEFAULT, // window height
+ (HWND) NULL, // handle to parent or owner window
+ NULL, // menu handle or child identifier
+ (HINSTANCE) GetModuleHandle( NULL ), // handle to application instance
+ NULL // window-creation data
+ );
+
+ DWORD dwThreadId;
+ CreateThread( NULL, 0, SystrayThread, NULL, 0, &dwThreadId );
+ }
+}
+
+// -------------------------------
+
+void win32_shutdown_sys_tray()
+{
+ if ( ShutdownIcon::IsQuickstarterInstalled() )
+ {
+ if( IsWindow( aListenerWindow ) )
+ {
+ DestroyWindow( aListenerWindow );
+ aListenerWindow = NULL;
+ DestroyWindow( aExecuterWindow );
+ aExecuterWindow = NULL;
+ }
+ UnregisterClassA( QUICKSTART_CLASSNAME, GetModuleHandle( NULL ) );
+ UnregisterClassA( EXECUTER_WINDOWCLASS, GetModuleHandle( NULL ) );
+ }
+}
+
+
+
+// -------------------------------
+
+void OnMeasureItem(HWND hwnd, LPMEASUREITEMSTRUCT lpmis)
+{
+ MYITEM *pMyItem = (MYITEM *) lpmis->itemData;
+ HDC hdc = GetDC(hwnd);
+ SIZE size;
+
+ NONCLIENTMETRICS ncm;
+ memset(&ncm, 0, sizeof(ncm));
+ ncm.cbSize = sizeof(ncm);
+
+ SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, (PVOID) &ncm, 0);
+
+ // Assume every menu item can be default and printed bold
+ ncm.lfMenuFont.lfWeight = FW_BOLD;
+
+ HFONT hfntOld = (HFONT) SelectObject(hdc, (HFONT) CreateFontIndirect( &ncm.lfMenuFont ));
+
+ GetTextExtentPoint32W(hdc, reinterpret_cast<LPCWSTR>(pMyItem->text.getStr()),
+ pMyItem->text.getLength(), &size);
+
+ lpmis->itemWidth = size.cx + 4 + GetSystemMetrics( SM_CXSMICON );
+ lpmis->itemHeight = (size.cy > GetSystemMetrics( SM_CYSMICON )) ? size.cy : GetSystemMetrics( SM_CYSMICON );
+ lpmis->itemHeight += 4;
+
+ DeleteObject( SelectObject(hdc, hfntOld) );
+ ReleaseDC(hwnd, hdc);
+}
+
+void OnDrawItem(HWND /*hwnd*/, LPDRAWITEMSTRUCT lpdis)
+{
+ MYITEM *pMyItem = (MYITEM *) lpdis->itemData;
+ COLORREF clrPrevText, clrPrevBkgnd;
+ HFONT hfntOld;
+ HBRUSH hbrOld;
+ int x, y;
+ BOOL fSelected = lpdis->itemState & ODS_SELECTED;
+ BOOL fDisabled = lpdis->itemState & (ODS_DISABLED | ODS_GRAYED);
+
+ // Set the appropriate foreground and background colors.
+
+ RECT aRect = lpdis->rcItem;
+
+ clrPrevBkgnd = SetBkColor( lpdis->hDC, GetSysColor(COLOR_MENU) );
+
+ if ( fDisabled )
+ clrPrevText = SetTextColor( lpdis->hDC, GetSysColor( COLOR_GRAYTEXT ) );
+ else
+ clrPrevText = SetTextColor( lpdis->hDC, GetSysColor( fSelected ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT ) );
+
+ if ( fSelected )
+ clrPrevBkgnd = SetBkColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT) );
+ else
+ clrPrevBkgnd = SetBkColor( lpdis->hDC, GetSysColor(COLOR_MENU) );
+
+ hbrOld = (HBRUSH)SelectObject( lpdis->hDC, CreateSolidBrush( GetBkColor( lpdis->hDC ) ) );
+
+ // Fill background
+ PatBlt(lpdis->hDC, aRect.left, aRect.top, aRect.right-aRect.left, aRect.bottom-aRect.top, PATCOPY);
+
+ int height = aRect.bottom-aRect.top;
+
+ x = aRect.left;
+ y = aRect.top;
+
+ int cx = GetSystemMetrics( SM_CXSMICON );
+ int cy = GetSystemMetrics( SM_CYSMICON );
+ HICON hIcon( 0 );
+ HMODULE hModule( GetModuleHandle( NULL ) );
+
+ if ( pMyItem->module.getLength() > 0 )
+ {
+ LPCWSTR pModuleName = reinterpret_cast<LPCWSTR>( pMyItem->module.getStr() );
+ hModule = GetModuleHandleW( pModuleName );
+ if ( hModule == NULL )
+ {
+ LoadLibraryW( pModuleName );
+ hModule = GetModuleHandleW( pModuleName );
+ }
+ }
+
+ hIcon = (HICON) LoadImageA( hModule, MAKEINTRESOURCE( pMyItem->iconId ),
+ IMAGE_ICON, cx, cy,
+ LR_DEFAULTCOLOR | LR_SHARED );
+
+ // DrawIconEx( lpdis->hDC, x, y+(height-cy)/2, hIcon, cx, cy, 0, NULL, DI_NORMAL );
+
+ HBRUSH hbrIcon = CreateSolidBrush( GetSysColor( COLOR_GRAYTEXT ) );
+
+ DrawStateW( lpdis->hDC, (HBRUSH)hbrIcon, (DRAWSTATEPROC)NULL, (LPARAM)hIcon, (WPARAM)0, x, y+(height-cy)/2, 0, 0, DST_ICON | (fDisabled ? (fSelected ? DSS_MONO : DSS_DISABLED) : DSS_NORMAL) );
+
+ DeleteObject( hbrIcon );
+
+ x += cx + 4; // space for icon
+ aRect.left = x;
+
+ NONCLIENTMETRICS ncm;
+ memset(&ncm, 0, sizeof(ncm));
+ ncm.cbSize = sizeof(ncm);
+
+ SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, (PVOID) &ncm, 0);
+
+ // Print default menu entry with bold font
+ if ( lpdis->itemState & ODS_DEFAULT )
+ ncm.lfMenuFont.lfWeight = FW_BOLD;
+
+ hfntOld = (HFONT) SelectObject(lpdis->hDC, (HFONT) CreateFontIndirect( &ncm.lfMenuFont ));
+
+
+ SIZE size;
+ GetTextExtentPointW( lpdis->hDC, reinterpret_cast<LPCWSTR>(pMyItem->text.getStr()), pMyItem->text.getLength(), &size );
+
+ DrawStateW( lpdis->hDC, (HBRUSH)NULL, (DRAWSTATEPROC)NULL, (LPARAM)pMyItem->text.getStr(), (WPARAM)0, aRect.left, aRect.top + (height - size.cy)/2, 0, 0, DST_TEXT | (fDisabled && !fSelected ? DSS_DISABLED : DSS_NORMAL) );
+
+ // Restore the original font and colors.
+ DeleteObject( SelectObject( lpdis->hDC, hbrOld ) );
+ DeleteObject( SelectObject( lpdis->hDC, hfntOld) );
+ SetTextColor(lpdis->hDC, clrPrevText);
+ SetBkColor(lpdis->hDC, clrPrevBkgnd);
+}
+
+// -------------------------------
+// code from setup2 project
+// -------------------------------
+
+void _SHFree( void *pv )
+{
+ IMalloc *pMalloc;
+ if( NOERROR == SHGetMalloc(&pMalloc) )
+ {
+ pMalloc->Free( pv );
+ pMalloc->Release();
+ }
+}
+
+#define ALLOC(type, n) ((type *) HeapAlloc(GetProcessHeap(), 0, sizeof(type) * n ))
+#define FREE(p) HeapFree(GetProcessHeap(), 0, p)
+
+static OUString _SHGetSpecialFolder( int nFolderID )
+{
+
+ LPITEMIDLIST pidl;
+ HRESULT hHdl = SHGetSpecialFolderLocation( NULL, nFolderID, &pidl );
+ OUString aFolder;
+
+ if( hHdl == NOERROR )
+ {
+ WCHAR *lpFolderA;
+ lpFolderA = ALLOC( WCHAR, 16000 );
+
+ SHGetPathFromIDListW( pidl, lpFolderA );
+ aFolder = OUString( reinterpret_cast<const sal_Unicode*>(lpFolderA) );
+
+ FREE( lpFolderA );
+ _SHFree( pidl );
+ }
+ return aFolder;
+}
+
+OUString ShutdownIcon::GetAutostartFolderNameW32()
+{
+ return _SHGetSpecialFolder(CSIDL_STARTUP);
+}
+
+static HRESULT WINAPI SHCoCreateInstance( LPVOID lpszReserved, REFCLSID clsid, LPUNKNOWN pUnkUnknown, REFIID iid, LPVOID *ppv )
+{
+ HRESULT hResult = E_NOTIMPL;
+ HMODULE hModShell = GetModuleHandle( "SHELL32" );
+
+ if ( hModShell != NULL )
+ {
+ typedef HRESULT (WINAPI *SHCoCreateInstance_PROC)( LPVOID lpszReserved, REFCLSID clsid, LPUNKNOWN pUnkUnknwon, REFIID iid, LPVOID *ppv );
+
+ SHCoCreateInstance_PROC lpfnSHCoCreateInstance = (SHCoCreateInstance_PROC)GetProcAddress( hModShell, MAKEINTRESOURCE(102) );
+
+ if ( lpfnSHCoCreateInstance )
+ hResult = lpfnSHCoCreateInstance( lpszReserved, clsid, pUnkUnknown, iid, ppv );
+ }
+ return hResult;
+}
+
+BOOL CreateShortcut( const OUString& rAbsObject, const OUString& rAbsObjectPath,
+ const OUString& rAbsShortcut, const OUString& rDescription, const OUString& rParameter )
+{
+ HRESULT hres;
+ IShellLink* psl;
+ CLSID clsid_ShellLink = CLSID_ShellLink;
+ CLSID clsid_IShellLink = IID_IShellLink;
+
+ hres = CoCreateInstance( clsid_ShellLink, NULL, CLSCTX_INPROC_SERVER,
+ clsid_IShellLink, (void**)&psl );
+ if( FAILED(hres) )
+ hres = SHCoCreateInstance( NULL, clsid_ShellLink, NULL, clsid_IShellLink, (void**)&psl );
+
+ if( SUCCEEDED(hres) )
+ {
+ IPersistFile* ppf;
+ psl->SetPath( OUStringToOString(rAbsObject, osl_getThreadTextEncoding()).getStr() );
+ psl->SetWorkingDirectory( OUStringToOString(rAbsObjectPath, osl_getThreadTextEncoding()).getStr() );
+ psl->SetDescription( OUStringToOString(rDescription, osl_getThreadTextEncoding()).getStr() );
+ if( rParameter.getLength() )
+ psl->SetArguments( OUStringToOString(rParameter, osl_getThreadTextEncoding()).getStr() );
+
+ CLSID clsid_IPersistFile = IID_IPersistFile;
+ hres = psl->QueryInterface( clsid_IPersistFile, (void**)&ppf );
+
+ if( SUCCEEDED(hres) )
+ {
+ hres = ppf->Save( reinterpret_cast<LPCOLESTR>(rAbsShortcut.getStr()), TRUE );
+ ppf->Release();
+ } else return FALSE;
+ psl->Release();
+ } else return FALSE;
+ return TRUE;
+}
+
+// ------------------
+// install/uninstall
+
+static bool FileExistsW( LPCWSTR lpPath )
+{
+ bool bExists = false;
+ WIN32_FIND_DATAW aFindData;
+
+ HANDLE hFind = FindFirstFileW( lpPath, &aFindData );
+
+ if ( INVALID_HANDLE_VALUE != hFind )
+ {
+ bExists = true;
+ FindClose( hFind );
+ }
+
+ return bExists;
+}
+
+bool ShutdownIcon::IsQuickstarterInstalled()
+{
+ wchar_t aPath[_MAX_PATH];
+ if( isNT() )
+ {
+ GetModuleFileNameW( NULL, aPath, _MAX_PATH-1);
+ }
+ else
+ {
+ char szPathA[_MAX_PATH];
+ GetModuleFileNameA( NULL, szPathA, _MAX_PATH-1);
+
+ // calc the string wcstr len
+ int nNeededWStrBuffSize = MultiByteToWideChar( CP_ACP, 0, szPathA, -1, NULL, 0 );
+
+ // copy the string if necessary
+ if ( nNeededWStrBuffSize > 0 )
+ MultiByteToWideChar( CP_ACP, 0, szPathA, -1, aPath, nNeededWStrBuffSize );
+ }
+
+ OUString aOfficepath( reinterpret_cast<const sal_Unicode*>(aPath) );
+ int i = aOfficepath.lastIndexOf((sal_Char) '\\');
+ if( i != -1 )
+ aOfficepath = aOfficepath.copy(0, i);
+
+ OUString quickstartExe(aOfficepath);
+ quickstartExe += OUString( RTL_CONSTASCII_USTRINGPARAM( "\\quickstart.exe" ) );
+
+ return FileExistsW( reinterpret_cast<LPCWSTR>(quickstartExe.getStr()) );
+}
+
+void ShutdownIcon::EnableAutostartW32( const rtl::OUString &aShortcut )
+{
+ wchar_t aPath[_MAX_PATH];
+ if( isNT() )
+ GetModuleFileNameW( NULL, aPath, _MAX_PATH-1);
+ else
+ {
+ char szPathA[_MAX_PATH];
+ GetModuleFileNameA( NULL, szPathA, _MAX_PATH-1);
+
+ // calc the string wcstr len
+ int nNeededWStrBuffSize = MultiByteToWideChar( CP_ACP, 0, szPathA, -1, NULL, 0 );
+
+ // copy the string if necessary
+ if ( nNeededWStrBuffSize > 0 )
+ MultiByteToWideChar( CP_ACP, 0, szPathA, -1, aPath, nNeededWStrBuffSize );
+ }
+
+ OUString aOfficepath( reinterpret_cast<const sal_Unicode*>(aPath) );
+ int i = aOfficepath.lastIndexOf((sal_Char) '\\');
+ if( i != -1 )
+ aOfficepath = aOfficepath.copy(0, i);
+
+ OUString quickstartExe(aOfficepath);
+ quickstartExe += OUString( RTL_CONSTASCII_USTRINGPARAM( "\\quickstart.exe" ) );
+
+ CreateShortcut( quickstartExe, aOfficepath, aShortcut, OUString(), OUString() );
+}
+
+#endif // WNT
+
+
diff --git a/sfx2/source/appl/workwin.cxx b/sfx2/source/appl/workwin.cxx
new file mode 100644
index 000000000000..2224643bc88f
--- /dev/null
+++ b/sfx2/source/appl/workwin.cxx
@@ -0,0 +1,3142 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+
+#include <stdio.h>
+#include <hash_map>
+
+#include <sfx2/docfile.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/app.hxx>
+#include "workwin.hxx"
+#include <sfx2/viewfrm.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/dockwin.hxx>
+#include <sfx2/viewsh.hxx>
+#include "splitwin.hxx"
+#include <sfx2/msgpool.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/objsh.hxx>
+#include <sfx2/request.hxx> // SFX_ITEMSET_SET
+#include <vcl/taskpanelist.hxx>
+#include <vcl/toolbox.hxx>
+#include <tools/rcid.h>
+#include <tools/diagnose_ex.h>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <svl/itempool.hxx>
+#include <svl/itemiter.hxx>
+#include <svl/whiter.hxx>
+#include <svl/intitem.hxx>
+#ifndef _SFXEITEM_HXX //autogen
+#include <svl/eitem.hxx>
+#endif
+#include <com/sun/star/ui/XUIElement.hpp>
+#include <com/sun/star/frame/XLayoutManager.hpp>
+#include <com/sun/star/frame/XLayoutManagerEventBroadcaster.hpp>
+#include <com/sun/star/frame/LayoutManagerEvents.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+namespace css = ::com::sun::star;
+
+struct ResIdToResName
+{
+ USHORT nId;
+ const char* pName;
+};
+
+static const ResIdToResName pToolBarResToName[] =
+{
+ { 558, "fullscreenbar" },
+ { 560, "standardbar", },
+ { 18001, "formsnavigationbar" },
+ { 18002, "formsfilterbar" },
+ { 18003, "formtextobjectbar" },
+ { 18004, "formcontrols" },
+ { 18005, "moreformcontrols" },
+ { 18006, "formdesign" },
+ { 20050, "toolbar" }, //math
+ { 30001, "objectbar" }, //chart
+ { 30513, "toolbar" }, //chart
+ { 25005, "textobjectbar" }, //calc
+ { 25053, "drawobjectbar" },
+ { 25054, "graphicobjectbar" },
+ { 25001, "formatobjectbar" },
+ { 25006, "previewbar" },
+ { 25035, "toolbar" }, //calc
+ { 23015, "bezierobjectbar" }, //draw/impress
+ { 23019, "gluepointsobjectbar" },
+ { 23030, "graphicobjectbar" },
+ { 23013, "drawingobjectbar" }, //impress
+ { 23016, "textobjectbar" }, //impress
+ { 23028, "textobjectbar" }, //draw
+ { 23011, "toolbar" }, //impress
+ { 23020, "optionsbar" },
+ { 23021, "commontaskbar" },
+ { 23025, "toolbar" }, //draw
+ { 23026, "optionsbar" },
+ { 23027, "drawingobjectbar" }, //draw
+ { 23017, "outlinetoolbar" }, //impress
+ { 23012, "slideviewtoolbar" },
+ { 23014, "slideviewobjectbar" },
+ { 23283, "bezierobjectbar" }, //writer
+ { 23269, "drawingobjectbar" },
+ { 23270, "drawtextobjectbar" },
+ { 23267, "frameobjectbar" },
+ { 23268, "graphicobjectbar" },
+ { 23271, "numobjectbar" },
+ { 23272, "oleobjectbar" },
+ { 23266, "tableobjectbar" },
+ { 23265, "textobjectbar" },
+ { 20631, "previewobjectbar" }, //writer
+ { 20402, "toolbar" }, //web
+ { 20403, "textobjectbar" },
+ { 23273, "toolbar" }, //writer
+ { 20408, "frameobjectbar" }, //web
+ { 20410, "graphicobjectbar" },
+ { 20411, "oleobjectbar" },
+ { 14850, "macrobar" },
+ { 10987, "fontworkobjectbar" }, //global
+ { 10986, "extrusionobjectbar" },
+ { 23022, "formsobjectbar" },
+ { 23310, "viewerbar" }, //writer (plugin)
+ { 25000, "viewerbar" }, //calc (plugin)
+ { 23023, "viewerbar" }, //impress(plugin)
+ { 23024, "viewerbar" }, //draw (plugin)
+ { 23031, "mediaobjectbar" }, //draw/impress
+ { 25060, "mediaobjectbar" }, //calc
+ { 23311, "mediaobjectbar" }, //writer
+ { 0, "" }
+};
+
+DBG_NAME(SfxWorkWindow)
+
+//SV_IMPL_OBJARR( SfxObjectBarArr_Impl, SfxObjectBar_Impl );
+
+//====================================================================
+// Sortiert die Children nach ihrem Alignment
+// Reihenfolge entspricht der im enum SfxChildAlignment (->CHILDWIN.HXX).
+//
+
+// Hilfe, um die "Anderungen am Alignment kompatibal zu machen!
+
+
+SFX_IMPL_XINTERFACE_3( LayoutManagerListener, OWeakObject, ::com::sun::star::frame::XLayoutManagerListener, ::com::sun::star::lang::XEventListener, ::com::sun::star::lang::XComponent )
+SFX_IMPL_XTYPEPROVIDER_3( LayoutManagerListener, ::com::sun::star::frame::XLayoutManagerListener, ::com::sun::star::lang::XEventListener, ::com::sun::star::lang::XComponent )
+
+LayoutManagerListener::LayoutManagerListener(
+ SfxWorkWindow* pWrkWin ) :
+ m_bHasFrame( sal_False ),
+ m_pWrkWin( pWrkWin ),
+ m_aLayoutManagerPropName( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))
+{
+}
+
+LayoutManagerListener::~LayoutManagerListener()
+{
+}
+
+void LayoutManagerListener::setFrame( const css::uno::Reference< css::frame::XFrame >& xFrame )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pWrkWin && !m_bHasFrame )
+ {
+ m_xFrame = xFrame;
+ m_bHasFrame = sal_True;
+
+ if ( xFrame.is() )
+ {
+ css::uno::Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
+ css::uno::Reference< css::frame::XLayoutManagerEventBroadcaster > xLayoutManager;
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ Any aValue = xPropSet->getPropertyValue( m_aLayoutManagerPropName );
+ aValue >>= xLayoutManager;
+
+ if ( xLayoutManager.is() )
+ xLayoutManager->addLayoutManagerEventListener(
+ css::uno::Reference< css::frame::XLayoutManagerListener >(
+ static_cast< OWeakObject* >( this ), css::uno::UNO_QUERY ));
+
+ xPropSet = css::uno::Reference< css::beans::XPropertySet >( xLayoutManager, UNO_QUERY );
+ if ( xPropSet.is() )
+ {
+ aValue = xPropSet->getPropertyValue(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LockCount" )) );
+ aValue >>= m_pWrkWin->m_nLock;
+ }
+ }
+ catch ( css::lang::DisposedException& )
+ {
+ }
+ catch ( css::uno::RuntimeException& e )
+ {
+ throw e;
+ }
+ catch ( css::uno::Exception& )
+ {
+ }
+ }
+ }
+ }
+}
+
+//---------------------------------------------------------------------------------------------------------
+// XComponent
+//---------------------------------------------------------------------------------------------------------
+void SAL_CALL LayoutManagerListener::addEventListener(
+ const css::uno::Reference< css::lang::XEventListener >& )
+throw (::com::sun::star::uno::RuntimeException)
+{
+ // do nothing, only internal class
+}
+
+void SAL_CALL LayoutManagerListener::removeEventListener(
+ const css::uno::Reference< css::lang::XEventListener >& )
+throw (::com::sun::star::uno::RuntimeException)
+{
+ // do nothing, only internal class
+}
+
+void SAL_CALL LayoutManagerListener::dispose()
+throw( css::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ // reset member
+ m_pWrkWin = 0;
+
+ css::uno::Reference< css::frame::XFrame > xFrame( m_xFrame.get(), css::uno::UNO_QUERY );
+ if ( xFrame.is() )
+ {
+ m_xFrame = css::uno::Reference< css::frame::XFrame >();
+ m_bHasFrame = sal_False;
+
+ css::uno::Reference< css::beans::XPropertySet > xPropSet( xFrame, css::uno::UNO_QUERY );
+ css::uno::Reference< css::frame::XLayoutManagerEventBroadcaster > xLayoutManager;
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ css::uno::Any aValue = xPropSet->getPropertyValue( m_aLayoutManagerPropName );
+ aValue >>= xLayoutManager;
+
+ // remove as listener from layout manager
+ if ( xLayoutManager.is() )
+ xLayoutManager->removeLayoutManagerEventListener(
+ css::uno::Reference< css::frame::XLayoutManagerListener >(
+ static_cast< OWeakObject* >( this ), css::uno::UNO_QUERY ));
+ }
+ catch ( css::lang::DisposedException& )
+ {
+ }
+ catch ( css::uno::RuntimeException& e )
+ {
+ throw e;
+ }
+ catch ( css::uno::Exception& )
+ {
+ }
+ }
+ }
+}
+
+//---------------------------------------------------------------------------------------------------------
+// XEventListener
+//---------------------------------------------------------------------------------------------------------
+void SAL_CALL LayoutManagerListener::disposing(
+ const css::lang::EventObject& )
+throw( css::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ m_pWrkWin = 0;
+ m_bHasFrame = sal_False;
+ m_xFrame = css::uno::Reference< css::frame::XFrame >();
+}
+
+//---------------------------------------------------------------------------------------------------------
+// XLayoutManagerEventListener
+//---------------------------------------------------------------------------------------------------------
+void SAL_CALL LayoutManagerListener::layoutEvent(
+ const css::lang::EventObject&,
+ ::sal_Int16 eLayoutEvent,
+ const css::uno::Any& )
+throw (css::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pWrkWin )
+ {
+ if ( eLayoutEvent == css::frame::LayoutManagerEvents::VISIBLE )
+ {
+ m_pWrkWin->MakeVisible_Impl( TRUE );
+ m_pWrkWin->ShowChilds_Impl();
+ m_pWrkWin->ArrangeChilds_Impl( TRUE );
+ }
+ else if ( eLayoutEvent == css::frame::LayoutManagerEvents::INVISIBLE )
+ {
+ m_pWrkWin->MakeVisible_Impl( FALSE );
+ m_pWrkWin->HideChilds_Impl();
+ m_pWrkWin->ArrangeChilds_Impl( TRUE );
+ }
+ else if ( eLayoutEvent == css::frame::LayoutManagerEvents::LOCK )
+ {
+ m_pWrkWin->Lock_Impl( TRUE );
+ }
+ else if ( eLayoutEvent == css::frame::LayoutManagerEvents::UNLOCK )
+ {
+ m_pWrkWin->Lock_Impl( FALSE );
+ }
+ }
+}
+
+//====================================================================
+
+typedef std::hash_map< sal_Int32, rtl::OUString > ToolBarResIdToResourceURLMap;
+
+static sal_Bool bMapInitialized = sal_False;
+static ToolBarResIdToResourceURLMap aResIdToResourceURLMap;
+
+static rtl::OUString GetResourceURLFromResId( USHORT nResId )
+{
+ if ( !bMapInitialized )
+ {
+ osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
+ if ( !bMapInitialized )
+ {
+ sal_Int32 nIndex( 0 );
+ while ( pToolBarResToName[nIndex].nId != 0 )
+ {
+ rtl::OUString aResourceURL( rtl::OUString::createFromAscii( pToolBarResToName[nIndex].pName ));
+ aResIdToResourceURLMap.insert( ToolBarResIdToResourceURLMap::value_type(
+ sal_Int32( pToolBarResToName[nIndex].nId ), aResourceURL ));
+ ++nIndex;
+ }
+ bMapInitialized = sal_True;
+ }
+ }
+
+ ToolBarResIdToResourceURLMap::const_iterator pIter = aResIdToResourceURLMap.find( nResId );
+ if ( pIter != aResIdToResourceURLMap.end() )
+ return pIter->second;
+ else
+ return rtl::OUString();
+}
+
+BOOL IsAppWorkWinToolbox_Impl( USHORT nPos )
+{
+ switch ( nPos )
+ {
+ case SFX_OBJECTBAR_APPLICATION :
+ case SFX_OBJECTBAR_MACRO:
+ case SFX_OBJECTBAR_FULLSCREEN:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+USHORT TbxMatch( USHORT nPos )
+{
+ switch ( nPos )
+ {
+ case SFX_OBJECTBAR_APPLICATION :
+ return 0;
+ case SFX_OBJECTBAR_OPTIONS:
+ return 1;
+ case SFX_OBJECTBAR_MACRO:
+ return 2;
+ case SFX_OBJECTBAR_OBJECT:
+ return 3;
+ case SFX_OBJECTBAR_TOOLS:
+ return 4;
+ case SFX_OBJECTBAR_FULLSCREEN:
+ case SFX_OBJECTBAR_COMMONTASK:
+ case SFX_OBJECTBAR_RECORDING:
+ return nPos+1;
+ default:
+ return nPos;
+ }
+}
+
+USHORT ChildAlignValue(SfxChildAlignment eAlign)
+{
+ USHORT ret = 17;
+
+ switch (eAlign)
+ {
+ case SFX_ALIGN_HIGHESTTOP:
+ ret = 1;
+ break;
+ case SFX_ALIGN_LOWESTBOTTOM:
+ ret = 2;
+ break;
+ case SFX_ALIGN_FIRSTLEFT:
+ ret = 3;
+ break;
+ case SFX_ALIGN_LASTRIGHT:
+ ret = 4;
+ break;
+ case SFX_ALIGN_LEFT:
+ ret = 5;
+ break;
+ case SFX_ALIGN_RIGHT:
+ ret = 6;
+ break;
+ case SFX_ALIGN_FIRSTRIGHT:
+ ret = 7;
+ break;
+ case SFX_ALIGN_LASTLEFT:
+ ret = 8;
+ break;
+ case SFX_ALIGN_TOP:
+ ret = 9;
+ break;
+ case SFX_ALIGN_BOTTOM:
+ ret = 10;
+ break;
+ case SFX_ALIGN_TOOLBOXTOP:
+ ret = 11;
+ break;
+ case SFX_ALIGN_TOOLBOXBOTTOM:
+ ret = 12;
+ break;
+ case SFX_ALIGN_LOWESTTOP:
+ ret = 13;
+ break;
+ case SFX_ALIGN_HIGHESTBOTTOM:
+ ret = 14;
+ break;
+ case SFX_ALIGN_TOOLBOXLEFT:
+ ret = 15;
+ break;
+ case SFX_ALIGN_TOOLBOXRIGHT:
+ ret = 16;
+ break;
+ case SFX_ALIGN_NOALIGNMENT:
+ break; // -Wall not handled...
+ }
+
+ return ret;
+}
+
+USHORT ChildTravelValue( SfxChildAlignment eAlign )
+{
+ USHORT ret = 17;
+
+ switch (eAlign)
+ {
+ case SFX_ALIGN_FIRSTLEFT:
+ ret = 1;
+ break;
+ case SFX_ALIGN_LEFT:
+ ret = 2;
+ break;
+ case SFX_ALIGN_LASTLEFT:
+ ret = 3;
+ break;
+ case SFX_ALIGN_TOOLBOXLEFT:
+ ret = 4;
+ break;
+ case SFX_ALIGN_HIGHESTTOP:
+ ret = 5;
+ break;
+ case SFX_ALIGN_TOP:
+ ret = 6;
+ break;
+ case SFX_ALIGN_TOOLBOXTOP:
+ ret = 7;
+ break;
+ case SFX_ALIGN_LOWESTTOP:
+ ret = 8;
+ break;
+ case SFX_ALIGN_HIGHESTBOTTOM:
+ ret = 9;
+ break;
+ case SFX_ALIGN_TOOLBOXBOTTOM:
+ ret = 10;
+ break;
+ case SFX_ALIGN_BOTTOM:
+ ret = 11;
+ break;
+ case SFX_ALIGN_LOWESTBOTTOM:
+ ret = 12;
+ break;
+ case SFX_ALIGN_TOOLBOXRIGHT:
+ ret = 13;
+ break;
+ case SFX_ALIGN_FIRSTRIGHT:
+ ret = 14;
+ break;
+ case SFX_ALIGN_RIGHT:
+ ret = 15;
+ break;
+ case SFX_ALIGN_LASTRIGHT:
+ ret = 16;
+ break;
+ case SFX_ALIGN_NOALIGNMENT:
+ break; // -Wall not handled.
+ }
+
+ return ret;
+}
+
+void SfxWorkWindow::Sort_Impl()
+{
+ aSortedList.Remove(0, aSortedList.Count());
+ for (USHORT i=0; i<pChilds->Count(); i++)
+ {
+ SfxChild_Impl *pCli = (*pChilds)[i];
+ if (pCli)
+ {
+ USHORT k;
+ for (k=0; k<aSortedList.Count(); k++)
+// if ( (*pChilds)[aSortedList[k]]->eAlign > pCli->eAlign )
+ if (ChildAlignValue((*pChilds)[aSortedList[k]]->eAlign) >
+ ChildAlignValue(pCli->eAlign))
+ break;
+ aSortedList.Insert (i,k);
+ }
+ }
+
+ bSorted = TRUE;
+}
+
+
+//====================================================================
+// ctor f"ur workwin eines Frames
+
+SfxFrameWorkWin_Impl::SfxFrameWorkWin_Impl( Window *pWin, SfxFrame *pFrm, SfxFrame* pMaster )
+ : SfxWorkWindow(
+ pWin,
+ pFrm->GetCurrentViewFrame()->GetBindings(),
+ pFrm->GetParentFrame() ? pFrm->GetParentFrame()->GetWorkWindow_Impl() : NULL )
+ , pMasterFrame( pMaster )
+ , pFrame( pFrm )
+{
+ pConfigShell = pFrm->GetCurrentViewFrame();
+ if ( pConfigShell && pConfigShell->GetObjectShell() )
+ {
+ bShowStatusBar = ( !pConfigShell->GetObjectShell()->IsInPlaceActive() );
+ bDockingAllowed = sal_True;
+ bInternalDockingAllowed = sal_True;
+ }
+
+ // Die ben"otigten SplitWindows (je eins f"ur jede Seite) werden erzeugt
+ for ( USHORT n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
+ {
+ // Die SplitWindows sind direkte ChildWindows des WorkWindows und enthalten
+ // die angedockten Fenster.
+
+ SfxChildAlignment eAlign =
+ ( n == SFX_SPLITWINDOWS_LEFT ? SFX_ALIGN_LEFT :
+ n == SFX_SPLITWINDOWS_RIGHT ? SFX_ALIGN_RIGHT :
+ n == SFX_SPLITWINDOWS_TOP ? SFX_ALIGN_TOP :
+ SFX_ALIGN_BOTTOM );
+ SfxSplitWindow *pSplitWin = new SfxSplitWindow(pWorkWin, eAlign, this, pParent==0 );
+ pSplit[n] = pSplitWin;
+ }
+
+ //nOrigMode = SFX_VISIBILITY_CLIENT;
+ nOrigMode = SFX_VISIBILITY_STANDARD;
+ nUpdateMode = SFX_VISIBILITY_STANDARD;
+}
+
+//====================================================================
+// ctor der Basisklasse
+
+SfxWorkWindow::SfxWorkWindow( Window *pWin, SfxBindings& rB, SfxWorkWindow* pParentWorkwin ) :
+ pParent( pParentWorkwin ),
+ pBindings(&rB),
+ pWorkWin (pWin),
+ pConfigShell( 0 ),
+ pActiveChild( 0 ),
+ nChilds( 0 ),
+ nOrigMode( 0 ),
+ bSorted( TRUE ),
+ bDockingAllowed(TRUE),
+ bInternalDockingAllowed(TRUE),
+ bAllChildsVisible(TRUE),
+ bIsFullScreen( FALSE ),
+ bShowStatusBar( TRUE ),
+ m_nLock( 0 ),
+ m_aStatusBarResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" )),
+ m_aLayoutManagerPropName( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )),
+ m_aTbxTypeName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" )),
+ m_aProgressBarResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/progressbar/progressbar" ))
+{
+ DBG_CTOR(SfxWorkWindow, 0);
+ DBG_ASSERT (pBindings, "Keine Bindings!");
+
+ pBindings->SetWorkWindow_Impl( this );
+
+ pChildWins = new SfxChildWindows_Impl;
+ pChilds = new SfxChildList_Impl;
+
+ // F"ur die ObjectBars wird ein fester Platz in der ChildList reserviert,
+ // damit sie immer in einer definierten Reihenfolge kommen.
+ SfxChild_Impl* pChild=0;
+ for (USHORT n=0; n < SFX_OBJECTBAR_MAX; ++n)
+ pChilds->Insert(0,pChild);
+
+ // create and initialize layout manager listener
+ Reference< com::sun::star::frame::XFrame > xFrame = GetFrameInterface();
+ LayoutManagerListener* pLayoutManagerListener = new LayoutManagerListener( this );
+ m_xLayoutManagerListener = css::uno::Reference< css::lang::XComponent >(
+ static_cast< cppu::OWeakObject* >( pLayoutManagerListener ),
+ css::uno::UNO_QUERY );
+ pLayoutManagerListener->setFrame( xFrame );
+}
+
+//====================================================================
+// dtor
+
+SfxWorkWindow::~SfxWorkWindow()
+{
+ DBG_DTOR(SfxWorkWindow, 0);
+
+ // SplitWindows l"oschen
+ for ( USHORT n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
+ {
+ SfxSplitWindow *p = pSplit[n];
+ if (p->GetWindowCount())
+ ReleaseChild_Impl(*p);
+ delete p;
+ }
+
+ // Hilfsstruktur f"ur Child-Windows l"oschen
+ DBG_ASSERT( pChilds->Count() == 0, "dangling childs" );
+ delete pChilds;
+ delete pChildWins;
+
+ if ( m_xLayoutManagerListener.is() )
+ m_xLayoutManagerListener->dispose();
+}
+
+SystemWindow* SfxWorkWindow::GetTopWindow() const
+{
+ Window* pRet = pWorkWin;
+ while ( pRet && !pRet->IsSystemWindow() )
+ pRet = pRet->GetParent();
+ return (SystemWindow*) pRet;
+}
+
+void SfxWorkWindow::Lock_Impl( BOOL bLock )
+{
+ if ( bLock )
+ m_nLock++;
+ else
+ --m_nLock;
+ if ( m_nLock<0 )
+ {
+ DBG_ERROR("Lock count underflow!");
+ m_nLock = 0;
+ }
+
+ if ( !m_nLock )
+ ArrangeChilds_Impl();
+}
+
+void SfxWorkWindow::ChangeWindow_Impl( Window *pNew )
+{
+ Window *pOld = pWorkWin;
+ pWorkWin = pNew;
+ for ( USHORT nPos = 0; nPos < pChilds->Count(); ++nPos )
+ {
+ SfxChild_Impl *pCli = (*pChilds)[nPos];
+ if ( pCli && pCli->pWin && pCli->pWin->GetParent() == pOld )
+ {
+ pCli->pWin->SetParent( pNew );
+ }
+ }
+}
+
+void SfxWorkWindow::SaveStatus_Impl()
+{
+ USHORT nCount = pChildWins->Count();
+ for ( USHORT n=0; n<nCount; n++ )
+ {
+ SfxChildWin_Impl* pCW = (*pChildWins)[n];
+ SfxChildWindow *pChild = pCW->pWin;
+ if (pChild)
+ {
+ USHORT nFlags = pCW->aInfo.nFlags;
+ pCW->aInfo = pChild->GetInfo();
+ pCW->aInfo.nFlags |= nFlags;
+ SaveStatus_Impl(pChild, pCW->aInfo);
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+// Hilfsmethode zum Freigeben der Childlisten. Wenn danach nicht der dtor
+// aufgerufen wird, sondern weiter gearbeitet wird, mu\s wie im ctor von
+// SfxWorkWindow noch Platz f"ur die Objectbars und SplitWindows reserviert
+// werden.
+
+void SfxWorkWindow::DeleteControllers_Impl()
+{
+ DBG_CHKTHIS(SfxWorkWindow, 0);
+
+ // SplitWindows locken (d.h. Resize-Reaktion an den
+ // DockingWindows unterdr"ucken)
+ USHORT n;
+ for ( n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
+ {
+ SfxSplitWindow *p = pSplit[n];
+ if (p->GetWindowCount())
+ p->Lock();
+ }
+
+ // Child-Windows l"oschen
+ for ( n=0; n<pChildWins->Count(); )
+ {
+ SfxChildWin_Impl* pCW = (*pChildWins)[n];
+ pChildWins->Remove(n);
+ SfxChildWindow *pChild = pCW->pWin;
+ if (pChild)
+ {
+/*
+ USHORT nFlags = pCW->aInfo.nFlags;
+ pCW->aInfo = pChild->GetInfo();
+ pCW->aInfo.nFlags |= nFlags;
+ SaveStatus_Impl(pChild, pCW->aInfo);
+*/
+ pChild->Hide();
+
+ // Wenn das ChildWindow ein direktes Childfenster ist und nicht
+ // in einem SplitWindow liegt, am WorkWindow abmelden.
+ // Nach TH ist eine Abmeldung am Splitwindow nicht erforderlich,
+ // wenn dieses auch gleich mit zerst"ort wird (s.u.).
+ if (pCW->pCli)
+ ReleaseChild_Impl(*pChild->GetWindow());
+ pCW->pWin = 0;
+ pWorkWin->GetSystemWindow()->GetTaskPaneList()->RemoveWindow( pChild->GetWindow() );
+ pChild->Destroy();
+ }
+
+ delete pCW;
+
+ // ATTENTION: The array itself is cleared after this loop!!
+ // Therefore we have to set every array entry to zero as it could be
+ // accessed by calling pChild->Destroy().
+ // See task 128307 (Windows)
+ // Window::NotifyAllChilds() calls SfxWorkWindow::DataChanged_Impl for
+ // 8-bit displays (WM_QUERYPALETTECHANGED message due to focus change)!!
+ //(*pChildWins)[n] = 0;
+ }
+
+ //pChildWins->Remove((USHORT)0, nCount);
+
+ Reference< com::sun::star::frame::XFrame > xFrame = GetFrameInterface();
+ Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
+ Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ Any aValue = xPropSet->getPropertyValue( m_aLayoutManagerPropName );
+ aValue >>= xLayoutManager;
+ }
+ catch ( Exception& )
+ {
+ }
+ }
+
+ if ( xLayoutManager.is() )
+ {
+ xLayoutManager->reset();
+
+ // StatusBar l"oschen
+ ResetStatusBar_Impl();
+
+ // ObjectBars l"oschen( zuletzt, damit pChilds nicht tote Pointer enh"alt )
+ for ( USHORT i = 0; i < aObjBarList.size(); i++ )
+ {
+ // Nicht jede Position mu\s belegt sein
+ USHORT nId = aObjBarList[i].nId;
+ if ( nId )
+ aObjBarList[i].nId = 0;
+ }
+ }
+
+ // ObjectBars werden alle auf einmal released, da sie einen
+ // festen zusammenh"angenden Bereich im Array pChilds belegen
+ pChilds->Remove(0, SFX_OBJECTBAR_MAX);
+ bSorted = FALSE;
+
+ nChilds = 0;
+}
+
+//====================================================================
+// Virtuelle Methode zum Anordnen der Childfenster.
+
+void SfxWorkWindow::ArrangeChilds_Impl( BOOL /*bForce*/)
+{
+ Arrange_Impl();
+}
+
+void SfxFrameWorkWin_Impl::ArrangeChilds_Impl( BOOL bForce )
+{
+ if ( pFrame->IsClosing_Impl() || ( m_nLock && !bForce ))
+ return;
+
+ SfxInPlaceClient *pClient = 0;
+ SfxViewFrame *pF = pFrame->GetCurrentViewFrame();
+ if ( pF && pF->GetViewShell() )
+ pClient = pF->GetViewShell()->GetIPClient();
+
+ if ( pClient )
+ return;
+
+ aClientArea = GetTopRect_Impl();
+ if ( aClientArea.IsEmpty() )
+ return;
+
+ SvBorder aBorder;
+ if ( nChilds )
+ {
+ if ( IsVisible_Impl() )
+ aBorder = Arrange_Impl();
+ }
+
+ // Wenn das aktuelle Dokument der Applikation einen IPClient enth"alt, mu\s
+ // dem dazugeh"origen Objekt durch SetTopToolFramePixel der zur Verf"ugung
+ // stehende Platz zugeteilt werden. Das Objekt zeigt dann seine UITools an
+ // und setzt den App-Border(->SfxInPlaceEnv_Impl::ArrangeChilds_Impl()).
+ // Anderenfalls wird hier direkt der AppBorder gesetzt, um evtl. den Border
+ // zu "uberschreiben, den bisher ein Objekt aus einem anderen Dokument
+ // gesetzt hatte.
+ // Das Objekt setzt, wenn es seine UI-Tools wegnimmt, den SetAppBorder nicht,
+ // damit kein ObjectBar-Zappeln entsteht.
+ // (->SfxInPlaceEnv_Impl::ArrangeChilds_Impl())
+
+ pMasterFrame->SetToolSpaceBorderPixel_Impl( aBorder );
+
+ ArrangeAutoHideWindows( NULL );
+}
+
+//--------------------------------------------------------------------
+
+SvBorder SfxWorkWindow::Arrange_Impl()
+
+/* [Beschreibung]
+
+ Diese Methode ordnet alle sichtbaren ChildFenster so an, da\s die angedockten
+ Fenster nach der Sorierreihenfolge von au\sen nach innen aneinander
+ gesetzt werden. Wenn ein an sich sichtbares Fenster nicht mehr in die
+ noch freie ClientArea pa\st, wird es auf "nicht sichtbar" gesetzt.
+
+*/
+{
+ DBG_CHKTHIS(SfxWorkWindow, 0);
+
+ aClientArea = GetTopRect_Impl();
+ aUpperClientArea = aClientArea;
+
+ SvBorder aBorder;
+ if ( !nChilds )
+ return aBorder;
+
+ if (!bSorted)
+ Sort_Impl();
+
+ Point aPos;
+ Size aSize;
+ Rectangle aTmp( aClientArea );
+
+ for ( USHORT n=0; n<aSortedList.Count(); ++n )
+ {
+ SfxChild_Impl* pCli = (*pChilds)[aSortedList[n]];
+ if ( !pCli->pWin )
+ continue;
+
+ // Zun"achst nehmen wir an, da\s das Fenster Platz hat
+ pCli->nVisible |= CHILD_FITS_IN;
+
+ // Nicht sichtbare Fenster "uberspringen
+ if (pCli->nVisible != CHILD_VISIBLE)
+ continue;
+
+ if ( pCli->bResize )
+ aSize = pCli->aSize;
+ else
+ aSize = pCli->pWin->GetSizePixel();
+
+ SvBorder aTemp = aBorder;
+ BOOL bAllowHiding = TRUE;
+ switch ( pCli->eAlign )
+ {
+ case SFX_ALIGN_HIGHESTTOP:
+ case SFX_ALIGN_TOP:
+ case SFX_ALIGN_TOOLBOXTOP:
+ case SFX_ALIGN_LOWESTTOP:
+ aSize.Width() = aTmp.GetWidth();
+ if ( pCli->pWin->GetType() == WINDOW_SPLITWINDOW )
+ aSize = ((SplitWindow *)(pCli->pWin))->CalcLayoutSizePixel( aSize );
+ bAllowHiding = FALSE;
+ aBorder.Top() += aSize.Height();
+ aPos = aTmp.TopLeft();
+ aTmp.Top() += aSize.Height();
+ if ( pCli->eAlign == SFX_ALIGN_HIGHESTTOP )
+ aUpperClientArea.Top() += aSize.Height();
+ break;
+
+ case SFX_ALIGN_LOWESTBOTTOM:
+ case SFX_ALIGN_BOTTOM:
+ case SFX_ALIGN_TOOLBOXBOTTOM:
+ case SFX_ALIGN_HIGHESTBOTTOM:
+ aSize.Width() = aTmp.GetWidth();
+ if ( pCli->pWin->GetType() == WINDOW_SPLITWINDOW )
+ aSize = ((SplitWindow *)(pCli->pWin))->CalcLayoutSizePixel( aSize );
+ aBorder.Bottom() += aSize.Height();
+ aPos = aTmp.BottomLeft();
+ aPos.Y() -= (aSize.Height()-1);
+ aTmp.Bottom() -= aSize.Height();
+ if ( pCli->eAlign == SFX_ALIGN_LOWESTBOTTOM )
+ aUpperClientArea.Bottom() -= aSize.Height();
+ break;
+
+ case SFX_ALIGN_FIRSTLEFT:
+ case SFX_ALIGN_LEFT:
+ case SFX_ALIGN_LASTLEFT:
+ case SFX_ALIGN_TOOLBOXLEFT:
+ aSize.Height() = aTmp.GetHeight();
+ if ( pCli->pWin->GetType() == WINDOW_SPLITWINDOW )
+ aSize = ((SplitWindow *)(pCli->pWin))->CalcLayoutSizePixel( aSize );
+ bAllowHiding = FALSE;
+ aBorder.Left() += aSize.Width();
+ aPos = aTmp.TopLeft();
+ aTmp.Left() += aSize.Width();
+ if ( pCli->eAlign != SFX_ALIGN_TOOLBOXLEFT )
+ aUpperClientArea.Left() += aSize.Width();
+ break;
+
+ case SFX_ALIGN_FIRSTRIGHT:
+ case SFX_ALIGN_RIGHT:
+ case SFX_ALIGN_LASTRIGHT:
+ case SFX_ALIGN_TOOLBOXRIGHT:
+ aSize.Height() = aTmp.GetHeight();
+ if ( pCli->pWin->GetType() == WINDOW_SPLITWINDOW )
+ aSize = ((SplitWindow *)(pCli->pWin))->CalcLayoutSizePixel( aSize );
+ aBorder.Right() += aSize.Width();
+ aPos = aTmp.TopRight();
+ aPos.X() -= (aSize.Width()-1);
+ aTmp.Right() -= aSize.Width();
+ if ( pCli->eAlign != SFX_ALIGN_TOOLBOXRIGHT )
+ aUpperClientArea.Right() -= aSize.Width();
+ break;
+
+ default:
+ pCli->aSize = pCli->pWin->GetSizePixel();
+ pCli->bResize = FALSE;
+ continue;
+ }
+
+ pCli->pWin->SetPosSizePixel( aPos, aSize );
+ pCli->bResize = FALSE;
+ pCli->aSize = aSize;
+ if( bAllowHiding && !RequestTopToolSpacePixel_Impl( aBorder ) )
+ {
+ pCli->nVisible ^= CHILD_FITS_IN;
+ aBorder = aTemp;
+ }
+ }
+
+ if ( aClientArea.GetWidth() >= aBorder.Left() + aBorder.Right() )
+ {
+ aClientArea.Left() += aBorder.Left();
+ aClientArea.Right() -= aBorder.Right();
+ }
+ else
+ {
+ aBorder.Left() = aClientArea.Left();
+ aBorder.Right() = aClientArea.Right();
+ aClientArea.Right() = aClientArea.Left() = aTmp.Left();
+ }
+
+ if ( aClientArea.GetHeight() >= aBorder.Top() + aBorder.Bottom() )
+ {
+ aClientArea.Top() += aBorder.Top();
+ aClientArea.Bottom() -= aBorder.Bottom();
+ }
+ else
+ {
+ aBorder.Top() = aClientArea.Top();
+ aBorder.Bottom() = aClientArea.Bottom();
+ aClientArea.Top() = aClientArea.Bottom() = aTmp.Top();
+ }
+
+ return IsDockingAllowed() ? aBorder : SvBorder();
+}
+
+//--------------------------------------------------------------------
+// Close-Handler: die Konfiguration der ChildWindows wird gespeichert.
+//
+
+void SfxWorkWindow::Close_Impl()
+{
+ for (USHORT n=0; n<pChildWins->Count(); n++)
+ {
+ SfxChildWin_Impl *pCW = (*pChildWins)[n];
+ SfxChildWindow *pChild = pCW->pWin;
+ if (pChild)
+ {
+ USHORT nFlags = pCW->aInfo.nFlags;
+ pCW->aInfo = pChild->GetInfo();
+ pCW->aInfo.nFlags |= nFlags;
+ SaveStatus_Impl(pChild, pCW->aInfo);
+ }
+ }
+}
+
+BOOL SfxWorkWindow::PrepareClose_Impl()
+{
+ for (USHORT n=0; n<pChildWins->Count(); n++)
+ {
+ SfxChildWin_Impl *pCW = (*pChildWins)[n];
+ SfxChildWindow *pChild = pCW->pWin;
+ if ( pChild && !pChild->QueryClose() )
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+//--------------------------------------------------------------------
+
+SfxChild_Impl* SfxWorkWindow::RegisterChild_Impl( Window& rWindow,
+ SfxChildAlignment eAlign, BOOL bCanGetFocus )
+{
+ DBG_CHKTHIS(SfxWorkWindow, 0);
+ DBG_ASSERT( pChilds->Count() < 255, "too many childs" );
+ DBG_ASSERT( SfxChildAlignValid(eAlign), "invalid align" );
+ DBG_ASSERT( !FindChild_Impl(rWindow), "child registered more than once" );
+
+
+ if ( rWindow.GetParent() != pWorkWin )
+ rWindow.SetParent( pWorkWin );
+
+ SfxChild_Impl *pChild = new SfxChild_Impl(rWindow, rWindow.GetSizePixel(),
+ eAlign, rWindow.IsVisible());
+ pChild->bCanGetFocus = bCanGetFocus;
+
+ pChilds->Insert(pChilds->Count(), pChild);
+ bSorted = FALSE;
+ nChilds++;
+ return (*pChilds)[pChilds->Count()-1];
+}
+
+//--------------------------------------------------------------------
+
+void SfxWorkWindow::AlignChild_Impl( Window& rWindow,
+ const Size& rNewSize,
+ SfxChildAlignment eAlign )
+{
+ DBG_CHKTHIS(SfxWorkWindow, 0);
+// DBG_ASSERT( pChilds, "aligning unregistered child" );
+ DBG_ASSERT( SfxChildAlignValid(eAlign), "invalid align" );
+
+ SfxChild_Impl *pChild = FindChild_Impl(rWindow);
+ if ( pChild )
+ {
+ if (pChild->eAlign != eAlign)
+ bSorted = FALSE;
+
+ pChild->eAlign = eAlign;
+ pChild->aSize = rNewSize;
+ pChild->bResize = TRUE;
+ }
+ else {
+ DBG_ERROR( "aligning unregistered child" );
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxWorkWindow::ReleaseChild_Impl( Window& rWindow )
+{
+ DBG_CHKTHIS(SfxWorkWindow, 0);
+// DBG_ASSERT( pChilds, "releasing unregistered child" );
+
+ SfxChild_Impl *pChild = 0;
+ USHORT nPos;
+ for ( nPos = 0; nPos < pChilds->Count(); ++nPos )
+ {
+ pChild = (*pChilds)[nPos];
+ if ( pChild )
+ if ( pChild->pWin == &rWindow )
+ break;
+ }
+
+ if ( nPos < pChilds->Count() )
+ {
+ bSorted = FALSE;
+ nChilds--;
+ pChilds->Remove(nPos);
+ delete pChild;
+ }
+ else {
+ DBG_ERROR( "releasing unregistered child" );
+ }
+}
+
+//--------------------------------------------------------------------
+
+SfxChild_Impl* SfxWorkWindow::FindChild_Impl( const Window& rWindow ) const
+{
+ DBG_CHKTHIS(SfxWorkWindow, 0);
+
+ SfxChild_Impl *pChild = 0;
+ USHORT nCount = pChilds->Count();
+ for ( USHORT nPos = 0; nPos < nCount; ++nPos )
+ {
+ pChild = (*pChilds)[nPos];
+ if ( pChild )
+ if ( pChild->pWin == &rWindow )
+ return pChild;
+ }
+
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxWorkWindow::ShowChilds_Impl()
+{
+ DBG_CHKTHIS(SfxWorkWindow, 0);
+
+ bool bInvisible = ( !IsVisible_Impl() || ( !pWorkWin->IsReallyVisible() && !pWorkWin->IsReallyShown() ));
+
+ SfxChild_Impl *pCli = 0;
+ for ( USHORT nPos = 0; nPos < pChilds->Count(); ++nPos )
+ {
+ SfxChildWin_Impl* pCW = 0;
+ pCli = (*pChilds)[nPos];
+
+ if ( pCli && pCli->pWin )
+ {
+ // We have to find the SfxChildWin_Impl to retrieve the
+ // SFX_CHILDWIN flags that can influence visibility.
+ for (USHORT n=0; n<pChildWins->Count(); n++)
+ {
+ SfxChildWin_Impl* pCWin = (*pChildWins)[n];
+ SfxChild_Impl* pChild = pCWin->pCli;
+ if ( pChild == pCli )
+ {
+ pCW = pCWin;
+ break;
+ }
+ }
+
+ bool bVisible( !bInvisible );
+ if ( pCW )
+ {
+ // Check flag SFX_CHILDWIN_NEVERHIDE that forces us to show
+ // the child window even in situations where no child window is
+ // visible.
+ sal_uInt16 nFlags = pCW->aInfo.nFlags;
+ bVisible = !bInvisible || ( bInvisible & (( nFlags & SFX_CHILDWIN_NEVERHIDE ) != 0 ));
+ }
+
+ if ( CHILD_VISIBLE == (pCli->nVisible & CHILD_VISIBLE) && bVisible )
+ {
+ USHORT nFlags = pCli->bSetFocus ? 0 : SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE;
+ switch ( pCli->pWin->GetType() )
+ {
+ case RSC_DOCKINGWINDOW :
+ ((DockingWindow*)pCli->pWin)->Show( TRUE, nFlags );
+ break;
+ case RSC_SPLITWINDOW :
+ ((SplitWindow*)pCli->pWin)->Show( TRUE, nFlags );
+ break;
+ default:
+ pCli->pWin->Show( TRUE, nFlags );
+ break;
+ }
+
+ pCli->bSetFocus = FALSE;
+ }
+ else
+ {
+ switch ( pCli->pWin->GetType() )
+ {
+ case RSC_DOCKINGWINDOW :
+ ((DockingWindow*)pCli->pWin)->Hide();
+ break;
+ default:
+ pCli->pWin->Hide();
+ break;
+ }
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxWorkWindow::HideChilds_Impl()
+{
+ SfxChild_Impl *pChild = 0;
+ for ( USHORT nPos = pChilds->Count(); nPos > 0; --nPos )
+ {
+ pChild = (*pChilds)[nPos-1];
+ if (pChild && pChild->pWin)
+ {
+ switch ( pChild->pWin->GetType() )
+ {
+ case RSC_DOCKINGWINDOW :
+ ((DockingWindow*)pChild->pWin)->Hide();
+ break;
+ default:
+ pChild->pWin->Hide();
+ break;
+ }
+ }
+ }
+}
+
+//------------------------------------------------------------------------
+
+void SfxWorkWindow::ResetObjectBars_Impl()
+{
+ USHORT n;
+ for ( n = 0; n < aObjBarList.size(); n++ )
+ aObjBarList[n].bDestroy = sal_True;
+
+ for ( n = 0; n < pChildWins->Count(); ++n )
+ (*pChildWins)[n]->nId = 0;
+}
+
+void SfxWorkWindow::NextObjectBar_Impl( USHORT )
+{
+}
+
+USHORT SfxWorkWindow::HasNextObjectBar_Impl( USHORT, String* )
+{
+ return 0;
+}
+
+//------------------------------------------------------------------------
+
+void SfxWorkWindow::SetObjectBar_Impl( USHORT nPos, sal_uInt32 nResId,
+ SfxInterface* pIFace, const String *pName)
+{
+ DBG_ASSERT( (nPos & SFX_POSITION_MASK) < SFX_OBJECTBAR_MAX,
+ "object bar position overflow" );
+
+ USHORT nRealPos = nPos & SFX_POSITION_MASK;
+ if ( pParent && IsAppWorkWinToolbox_Impl( nRealPos ) )
+ {
+ pParent->SetObjectBar_Impl( nPos, nResId, pIFace, pName );
+ return;
+ }
+
+ SfxObjectBar_Impl aObjBar;
+ aObjBar.pIFace = pIFace;
+ aObjBar.nId = sal::static_int_cast<USHORT>(nResId);
+ aObjBar.nPos = nRealPos;
+ aObjBar.nMode = (nPos & SFX_VISIBILITY_MASK);
+ if (pName)
+ aObjBar.aName = *pName;
+ else
+ aObjBar.aName.Erase();
+
+ for ( USHORT n=0; n<aObjBarList.size(); n++ )
+ {
+ if ( aObjBarList[n].nId == aObjBar.nId )
+ {
+ aObjBarList[n] = aObjBar;
+ return;
+ }
+ }
+
+ aObjBarList.push_back( aObjBar );
+}
+
+//------------------------------------------------------------------------
+
+FASTBOOL SfxWorkWindow::KnowsObjectBar_Impl( USHORT nPos ) const
+
+/* [Beschreibung]
+
+ Stellt fest, ob an der betreffenden Position "uberhaupt eine
+ Objektleiste zur Verf"ugung stehen w"urde. Ist unabh"agig davon,
+ ob diese tats"achlich ein- oder ausgeschaltet ist.
+*/
+
+{
+ USHORT nRealPos = nPos & SFX_POSITION_MASK;
+ if ( pParent && IsAppWorkWinToolbox_Impl( nRealPos ) )
+ return pParent->KnowsObjectBar_Impl( nPos );
+
+ for ( USHORT n=0; n<aObjBarList.size(); n++ )
+ {
+ if ( aObjBarList[n].nPos == nRealPos )
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+//------------------------------------------------------------------------
+
+BOOL SfxWorkWindow::IsVisible_Impl( USHORT nMode ) const
+{
+ switch( nUpdateMode )
+ {
+ case SFX_VISIBILITY_STANDARD:
+ return TRUE;
+ case SFX_VISIBILITY_UNVISIBLE:
+ return FALSE;
+ case SFX_VISIBILITY_PLUGSERVER:
+ case SFX_VISIBILITY_PLUGCLIENT:
+ case SFX_VISIBILITY_CLIENT:
+ case SFX_VISIBILITY_SERVER:
+ return !!(nMode & nUpdateMode);
+ default:
+ return !!(nMode & nOrigMode ) ||
+ nOrigMode == SFX_VISIBILITY_STANDARD;
+ }
+}
+
+Window* SfxWorkWindow::GetObjectBar_Impl( USHORT, sal_uInt32 )
+{
+ return NULL;
+}
+
+//------------------------------------------------------------------------
+void SfxFrameWorkWin_Impl::UpdateObjectBars_Impl()
+{
+ if ( pFrame->IsClosing_Impl() )
+ return;
+
+ SfxWorkWindow *pWork = pParent;
+ while ( pWork )
+ {
+ pWork->SfxWorkWindow::UpdateObjectBars_Impl();
+ pWork = pWork->GetParent_Impl();
+ }
+
+ SfxWorkWindow::UpdateObjectBars_Impl();
+
+// if ( pTask->IsActive() )
+ {
+ pWork = pParent;
+ while ( pWork )
+ {
+ pWork->ArrangeChilds_Impl();
+ pWork = pWork->GetParent_Impl();
+ }
+
+ ArrangeChilds_Impl( FALSE );
+
+ pWork = pParent;
+ while ( pWork )
+ {
+ pWork->ShowChilds_Impl();
+ pWork = pWork->GetParent_Impl();
+ }
+
+ ShowChilds_Impl();
+ }
+
+ ShowChilds_Impl();
+}
+
+Reference< ::com::sun::star::task::XStatusIndicator > SfxWorkWindow::GetStatusIndicator()
+{
+ Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
+ Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+ Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator;
+
+ if ( xPropSet.is() )
+ {
+ Any aValue = xPropSet->getPropertyValue( m_aLayoutManagerPropName );
+ aValue >>= xLayoutManager;
+ if ( xLayoutManager.is() )
+ {
+ xLayoutManager->createElement( m_aProgressBarResName );
+ xLayoutManager->showElement( m_aProgressBarResName );
+
+ Reference< ::com::sun::star::ui::XUIElement > xProgressBar =
+ xLayoutManager->getElement( m_aProgressBarResName );
+ if ( xProgressBar.is() )
+ {
+ xStatusIndicator = Reference< ::com::sun::star::task::XStatusIndicator >(
+ xProgressBar->getRealInterface(), UNO_QUERY );
+ }
+ }
+ }
+
+ return xStatusIndicator;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxWorkWindow::IsPluginMode( SfxObjectShell* pObjShell )
+{
+ if ( pObjShell && pObjShell->GetMedium() )
+ {
+ SFX_ITEMSET_ARG( pObjShell->GetMedium()->GetItemSet(), pViewOnlyItem, SfxBoolItem, SID_VIEWONLY, sal_False );
+ if ( pViewOnlyItem && pViewOnlyItem->GetValue() )
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+//------------------------------------------------------------------------
+
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SfxWorkWindow::GetFrameInterface()
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame;
+
+ SfxDispatcher* pDispatcher( GetBindings().GetDispatcher() );
+ if ( pDispatcher )
+ {
+ SfxViewFrame* pFrame = pDispatcher->GetFrame();
+ if ( pFrame )
+ xFrame = pFrame->GetFrame().GetFrameInterface();
+ }
+
+ return xFrame;
+}
+
+//------------------------------------------------------------------------
+
+void SfxWorkWindow::UpdateObjectBars_Impl()
+{
+ // SplitWindows locken (d.h. Resize-Reaktion an den
+ // DockingWindows unterdr"ucken)
+ USHORT n;
+ for ( n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
+ {
+ SfxSplitWindow *p = pSplit[n];
+ if (p->GetWindowCount())
+ p->Lock();
+ }
+
+ // was man so "ofters braucht, merkt man sich (spart Code und Laufzeit)
+ SFX_APP();
+
+ Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
+ Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+
+ if ( xPropSet.is() )
+ {
+ Any aValue = xPropSet->getPropertyValue( m_aLayoutManagerPropName );
+ aValue >>= xLayoutManager;
+ }
+
+ if ( !xLayoutManager.is() )
+ return;
+
+ sal_Bool bPluginMode( sal_False );
+ SfxDispatcher* pDispatcher( GetBindings().GetDispatcher() );
+
+ if ( pDispatcher )
+ {
+ SfxViewFrame* pFrame = pDispatcher->GetFrame();
+ if ( pFrame )
+ bPluginMode = IsPluginMode( pFrame->GetObjectShell() );
+ }
+
+ // "uber alle Toolboxen iterieren
+ xLayoutManager->lock();
+ for ( n = 0; n < aObjBarList.size(); ++n )
+ {
+ USHORT nId = aObjBarList[n].nId;
+ sal_Bool bDestroy = aObjBarList[n].bDestroy;
+
+ // die Modi bestimmen, f"ur die die ToolBox gilt
+ USHORT nTbxMode = aObjBarList[n].nMode;
+ FASTBOOL bFullScreenTbx = SFX_VISIBILITY_FULLSCREEN ==
+ ( nTbxMode & SFX_VISIBILITY_FULLSCREEN );
+ nTbxMode &= ~SFX_VISIBILITY_FULLSCREEN;
+ nTbxMode &= ~SFX_VISIBILITY_VIEWER;
+
+ // wird in diesem Kontext eine ToolBox gefordert?
+ FASTBOOL bModesMatching = ( nUpdateMode && ( nTbxMode & nUpdateMode) == nUpdateMode );
+ if ( bDestroy )
+ {
+ rtl::OUString aTbxId( m_aTbxTypeName );
+ aTbxId += GetResourceURLFromResId( aObjBarList[n].nId );
+ xLayoutManager->destroyElement( aTbxId );
+ }
+ else if ( nId != 0 && ( ( bModesMatching && !bIsFullScreen ) ||
+ ( bIsFullScreen && bFullScreenTbx ) ) )
+ {
+ rtl::OUString aTbxId( m_aTbxTypeName );
+ aTbxId += GetResourceURLFromResId( aObjBarList[n].nId );
+ if ( !IsDockingAllowed() && !xLayoutManager->isElementFloating( aTbxId ))
+ xLayoutManager->destroyElement( aTbxId );
+ else
+ {
+ xLayoutManager->requestElement( aTbxId );
+ if ( bPluginMode )
+ xLayoutManager->lockWindow( aTbxId );
+ }
+ }
+ else if ( nId != 0 )
+ {
+ // ggf. Toolbox an dieser Position l"oschen
+ rtl::OUString aTbxId( m_aTbxTypeName );
+ aTbxId += GetResourceURLFromResId( aObjBarList[n].nId );
+ xLayoutManager->destroyElement( aTbxId );
+ }
+ }
+
+ UpdateStatusBar_Impl();
+
+ // unlocking automatically forces Layout
+ xLayoutManager->unlock();
+
+ UpdateChildWindows_Impl();
+
+ // SplitWindows wieder ent-locken
+ for ( n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
+ {
+ SfxSplitWindow *p = pSplit[n];
+ if (p->GetWindowCount())
+ p->Lock(FALSE);
+ }
+}
+
+bool SfxWorkWindow::AllowChildWindowCreation_Impl( const SfxChildWin_Impl& i_rCW ) const
+{
+ // or checking the availability of child windows, we need access to the module
+ const SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
+ const SfxObjectShell* pShell = pViewFrame ? pViewFrame->GetObjectShell() : NULL;
+ const SfxModule* pModule = pShell ? pShell->GetModule() : NULL;
+ ENSURE_OR_RETURN( pModule, "SfxWorkWindow::UpdateChildWindows_Impl: did not find an SfxModule to ask for the child win availability!", true );
+ return pModule->IsChildWindowAvailable( i_rCW.nId, pViewFrame );
+}
+
+void SfxWorkWindow::UpdateChildWindows_Impl()
+{
+ // alle vorhandenen oder in den Kontext gekommenen ChildWindows
+ for ( USHORT n=0; n<pChildWins->Count(); n++ )
+ {
+ SfxChildWin_Impl *pCW = (*pChildWins)[n];
+ SfxChildWindow *pChildWin = pCW->pWin;
+ BOOL bCreate = FALSE;
+ if ( pCW->nId && !pCW->bDisabled && (pCW->aInfo.nFlags & SFX_CHILDWIN_ALWAYSAVAILABLE || IsVisible_Impl( pCW->nVisibility ) ) )
+ {
+ // Im Kontext ist ein geeignetes ChildWindow erlaubt;
+ // ist es auch eingeschaltet ?
+ if ( pChildWin == NULL && pCW->bCreate )
+ {
+ // Internal docking is only used for embedding into another
+ // container. We force the floating state of all floatable
+ // child windows.
+ if ( !bInternalDockingAllowed )
+ {
+ // Special case for all non-floatable child windows. We have
+ // to prevent the creation here!
+ bCreate = !( pCW->aInfo.nFlags & SFX_CHILDWIN_FORCEDOCK );
+ }
+ else if ( !IsDockingAllowed() || bIsFullScreen ) // || !bInternalDocking )
+ {
+ // im PresentationMode oder FullScreen nur FloatingWindows
+ SfxChildAlignment eAlign;
+ if ( pCW->aInfo.GetExtraData_Impl( &eAlign ) )
+ bCreate = ( eAlign == SFX_ALIGN_NOALIGNMENT );
+ }
+ else
+ bCreate = TRUE;
+
+ if ( bCreate )
+ bCreate = AllowChildWindowCreation_Impl( *pCW );
+
+ // Momentan kein Fenster da, aber es ist eingeschaltet; Fenster
+ // und ggf. Context erzeugen
+ if ( bCreate )
+ CreateChildWin_Impl( pCW, FALSE );
+
+ if ( !bAllChildsVisible )
+ {
+ if ( pCW->pCli )
+ pCW->pCli->nVisible &= ~CHILD_ACTIVE;
+ }
+ }
+ else if ( pChildWin )
+ {
+ // Fenster existiert schon; soll es auch sichtbar sein ?
+ if ( ( !bIsFullScreen || pChildWin->GetAlignment() == SFX_ALIGN_NOALIGNMENT ) && bAllChildsVisible )
+ {
+ // Updatemode ist kompatibel; auf jeden Fall wieder einschalten
+ bCreate = AllowChildWindowCreation_Impl( *pCW );
+ if ( bCreate )
+ {
+ if ( pCW->pCli )
+ {
+ // Fenster ist direktes Child
+ if ( bAllChildsVisible && ( (IsDockingAllowed() && bInternalDockingAllowed) || pCW->pCli->eAlign == SFX_ALIGN_NOALIGNMENT ) )
+ pCW->pCli->nVisible |= CHILD_NOT_HIDDEN;
+ }
+ else
+ {
+ if ( pCW->bCreate && IsDockingAllowed() && bInternalDockingAllowed )
+ // Fenster liegt in einem SplitWindow
+ ((SfxDockingWindow*)pChildWin->GetWindow())->Reappear_Impl();
+ }
+
+ if ( pCW->nInterfaceId != pChildWin->GetContextId() )
+ pChildWin->CreateContext( pCW->nInterfaceId, GetBindings() );
+ }
+ }
+ }
+ }
+
+ if ( pChildWin && !bCreate )
+ {
+ if ( !pChildWin->QueryClose() || pChildWin->IsHideNotDelete() || Application::IsUICaptured() )
+ {
+ if ( pCW->pCli )
+ {
+ if ( pCW->pCli->nVisible & CHILD_NOT_HIDDEN )
+ pCW->pCli->nVisible ^= CHILD_NOT_HIDDEN;
+ }
+ else
+ ((SfxDockingWindow*)pChildWin->GetWindow())->Disappear_Impl();
+ }
+ else
+ RemoveChildWin_Impl( pCW );
+ }
+ }
+}
+
+void SfxWorkWindow::CreateChildWin_Impl( SfxChildWin_Impl *pCW, BOOL bSetFocus )
+{
+ if ( pCW->aInfo.bVisible != 42 )
+ pCW->aInfo.bVisible = TRUE;
+
+ SfxChildWindow *pChildWin = SfxChildWindow::CreateChildWindow( pCW->nId, pWorkWin, &GetBindings(), pCW->aInfo);
+ if (pChildWin)
+ {
+ if ( bSetFocus )
+ bSetFocus = pChildWin->WantsFocus();
+ pChildWin->SetWorkWindow_Impl( this );
+#if 0
+ // Enable-Status richtig setzen
+ pChildWin->GetWindow()->EnableInput( pCW->bEnable &&
+ ( pWorkWin->IsInputEnabled() /* || pChildWin->GetAlignment() == SFX_ALIGN_NOALIGNMENT */ ) );
+#endif
+ // Zumindest der ExtraString wird beim Auswerten ver"andert, also neu holen
+ SfxChildWinInfo aInfo = pChildWin->GetInfo();
+ pCW->aInfo.aExtraString = aInfo.aExtraString;
+ pCW->aInfo.bVisible = aInfo.bVisible;
+ pCW->aInfo.nFlags |= aInfo.nFlags;
+
+ // Nein !! Sonst kann man keine Fenster defaultmaessig ausschalten ( Partwindow! )
+// pCW->aInfo.bVisible = TRUE;
+
+ // Erzeugung war erfolgreich
+ GetBindings().Invalidate(pCW->nId);
+
+ USHORT nPos = pChildWin->GetPosition();
+ if (nPos != CHILDWIN_NOPOS)
+ {
+ DBG_ASSERT(nPos < SFX_OBJECTBAR_MAX, "Illegal objectbar position!");
+ if ((*pChilds)[TbxMatch(nPos)])// &&
+// pChildWin->GetAlignment() == (*pChilds)[nPos]->eAlign )
+ {
+ // ChildWindow ersetzt ObjectBar
+ (*pChilds)[TbxMatch(nPos)]->nVisible ^= CHILD_NOT_HIDDEN;
+ }
+ }
+
+ // make childwin keyboard accessible
+ pWorkWin->GetSystemWindow()->GetTaskPaneList()->AddWindow( pChildWin->GetWindow() );
+
+ pCW->pWin = pChildWin;
+
+ if ( pChildWin->GetAlignment() == SFX_ALIGN_NOALIGNMENT || pChildWin->GetWindow()->GetParent() == pWorkWin)
+ {
+ // Das Fenster ist entweder nicht angedockt oder au\serhalb
+ // eines SplitWindows angedockt und mu\s daher explizit als
+ // Child registriert werden
+ pCW->pCli = RegisterChild_Impl(*(pChildWin->GetWindow()), pChildWin->GetAlignment(), pChildWin->CanGetFocus());
+ pCW->pCli->nVisible = CHILD_VISIBLE;
+ if ( pChildWin->GetAlignment() != SFX_ALIGN_NOALIGNMENT && bIsFullScreen )
+ pCW->pCli->nVisible ^= CHILD_ACTIVE;
+ pCW->pCli->bSetFocus = bSetFocus;
+ }
+ else
+ {
+ // Ein angedocktes Fenster, dessen Parent nicht das WorkWindow ist,
+ // mu\s in einem SplitWindow liegen und daher nicht explizit
+ // registriert werden.
+ // Das passiert aber schon bei der Initialisierung des
+ // SfxDockingWindows!
+ }
+
+ if ( pCW->nInterfaceId != pChildWin->GetContextId() )
+ pChildWin->CreateContext( pCW->nInterfaceId, GetBindings() );
+
+ // Information in der INI-Datei sichern
+ SaveStatus_Impl(pChildWin, pCW->aInfo);
+ }
+}
+
+void SfxWorkWindow::RemoveChildWin_Impl( SfxChildWin_Impl *pCW )
+{
+ USHORT nId = pCW->nSaveId;
+ SfxChildWindow *pChildWin = pCW->pWin;
+
+ // vorhandenes Fenster geht aus dem Kontext und wird daher entfernt
+ USHORT nPos = pChildWin->GetPosition();
+ if (nPos != CHILDWIN_NOPOS)
+ {
+/*
+ // ChildWindow "uberlagert einen ObjectBar
+ DBG_ASSERT(nPos < SFX_OBJECTBAR_MAX, "Illegal objectbar position!");
+ if ((*pChilds)[TbxMatch(nPos)] &&
+ (aObjBars[nPos].nMode & nUpdateMode) ) //&&
+// pChildWin->GetAlignment() == (*pChilds)[nPos]->eAlign )
+ {
+ // ObjectBar war "uberlagert; jetzt wieder anzeigen
+ (*pChilds)[TbxMatch(nPos)]->nVisible ^= CHILD_NOT_HIDDEN;
+ }
+*/
+ }
+
+ // Information in der INI-Datei sichern
+ USHORT nFlags = pCW->aInfo.nFlags;
+ pCW->aInfo = pChildWin->GetInfo();
+ pCW->aInfo.nFlags |= nFlags;
+ SaveStatus_Impl(pChildWin, pCW->aInfo);
+
+ pChildWin->Hide();
+
+ if ( pCW->pCli )
+ {
+ // ChildWindow ist ein direktes ChildWindow und mu\s sich daher
+ // beim WorkWindow abmelden
+ pCW->pCli = 0;
+ ReleaseChild_Impl(*pChildWin->GetWindow());
+ }
+ else
+ {
+ // ChildWindow liegt in einem SplitWindow und meldet sich
+ // selbst im dtor dort ab
+ }
+
+ pWorkWin->GetSystemWindow()->GetTaskPaneList()->RemoveWindow( pChildWin->GetWindow() );
+ pCW->pWin = 0;
+ pChildWin->Destroy();
+
+ GetBindings().Invalidate( nId );
+}
+
+void SfxWorkWindow::ResetStatusBar_Impl()
+{
+ aStatBar.nId = 0;
+}
+
+//--------------------------------------------------------------------
+void SfxWorkWindow::SetStatusBar_Impl( sal_uInt32 nResId, SfxShell*, SfxBindings& )
+{
+ if ( nResId && bShowStatusBar && IsVisible_Impl() )
+ aStatBar.nId = sal::static_int_cast<USHORT>(nResId);
+}
+
+#define SFX_ITEMTYPE_STATBAR 4
+
+void SfxWorkWindow::SetTempStatusBar_Impl( BOOL bSet )
+{
+ if ( aStatBar.bTemp != bSet && bShowStatusBar && IsVisible_Impl() )
+ {
+ BOOL bOn = FALSE;
+ BOOL bReset = FALSE;
+ if ( bSet && !aStatBar.nId )
+ {
+ bReset = TRUE;
+ SetStatusBar_Impl( SFX_ITEMTYPE_STATBAR, SFX_APP(), GetBindings() );
+ }
+
+ if ( aStatBar.nId && aStatBar.bOn && !bIsFullScreen )
+ bOn = TRUE;
+
+ aStatBar.bTemp = bSet;
+ if ( !bOn || bReset || (!bSet && aStatBar.nId ) )
+ {
+ // Nur was tun, wenn die Temp-Einstellung wirklich was bewirkt
+ UpdateStatusBar_Impl();
+ ArrangeChilds_Impl();
+ ShowChilds_Impl();
+ }
+
+ if ( bReset )
+ ResetStatusBar_Impl();
+ }
+}
+
+void SfxWorkWindow::UpdateStatusBar_Impl()
+{
+ Reference< ::com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
+ Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+
+ Any aValue = xPropSet->getPropertyValue( m_aLayoutManagerPropName );
+ aValue >>= xLayoutManager;
+
+ // keine Statusleiste, wenn keine Id gew"unscht oder bei FullScreenView
+ // oder wenn ausgeschaltet
+ if ( aStatBar.nId && IsDockingAllowed() && bInternalDockingAllowed && bShowStatusBar &&
+ ( (aStatBar.bOn && !bIsFullScreen) || aStatBar.bTemp ) )
+ {
+ // Id hat sich ge"andert, also passenden Statusbarmanager erzeugen,
+ // dieser "ubernimmt die aktuelle Statusleiste;
+ if ( xLayoutManager.is() )
+ xLayoutManager->requestElement( m_aStatusBarResName );
+ }
+ else
+ {
+ // Aktuelle StatusBar vernichten
+ // Der Manager erzeugt die Statusleiste nur, er zerst"ort sie
+ // nicht !
+ if ( xLayoutManager.is() )
+ xLayoutManager->destroyElement( m_aStatusBarResName );
+ }
+}
+
+//------------------------------------------------------------------------
+/*
+void SfxWorkWindow::SetObjectBarVisibility_Impl( USHORT nMask )
+{
+ switch( nMask )
+ {
+ case SFX_VISIBILITY_UNVISIBLE:
+ case SFX_VISIBILITY_STANDARD:
+ case SFX_VISIBILITY_CLIENT:
+ case SFX_VISIBILITY_SERVER:
+ nOrigMode = nMask;
+ }
+ if (nMask != nUpdateMode)
+ nUpdateMode = nMask;
+}*/
+
+void SfxWorkWindow::MakeVisible_Impl( BOOL bVis )
+{
+ if ( bVis )
+ nOrigMode = SFX_VISIBILITY_STANDARD;
+ else
+ nOrigMode = SFX_VISIBILITY_UNVISIBLE;
+
+ if ( nOrigMode != nUpdateMode)
+ nUpdateMode = nOrigMode;
+}
+
+BOOL SfxWorkWindow::IsVisible_Impl()
+{
+ return nOrigMode != SFX_VISIBILITY_UNVISIBLE;
+}
+
+//------------------------------------------------------------------------
+void SfxWorkWindow::HidePopups_Impl(BOOL bHide, BOOL bParent, USHORT nId )
+{
+ for ( USHORT n = 0; n < pChildWins->Count(); ++n )
+ {
+ SfxChildWindow *pCW = (*pChildWins)[n]->pWin;
+ if (pCW && pCW->GetAlignment() == SFX_ALIGN_NOALIGNMENT && pCW->GetType() != nId)
+ {
+ Window *pWin = pCW->GetWindow();
+ SfxChild_Impl *pChild = FindChild_Impl(*pWin);
+ if (bHide)
+ {
+ pChild->nVisible &= ~CHILD_ACTIVE;
+ pCW->Hide();
+ }
+ else
+ {
+ pChild->nVisible |= CHILD_ACTIVE;
+ if ( CHILD_VISIBLE == (pChild->nVisible & CHILD_VISIBLE) )
+ pCW->Show( SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
+ }
+ }
+ }
+
+ if ( bParent && pParent )
+ pParent->HidePopups_Impl( bHide, bParent, nId );
+}
+
+//------------------------------------------------------------------------
+
+void SfxWorkWindow::ConfigChild_Impl(SfxChildIdentifier eChild,
+ SfxDockingConfig eConfig, USHORT nId)
+{
+ SfxDockingWindow* pDockWin=0;
+ USHORT nPos = USHRT_MAX;
+ Window *pWin=0;
+ SfxChildWin_Impl *pCW = 0;
+
+ if ( eChild == SFX_CHILDWIN_OBJECTBAR )
+ {
+ return;
+ }
+ else
+ {
+ // configure direct childwindow
+ for (USHORT n=0; n<pChildWins->Count(); n++)
+ {
+ pCW = (*pChildWins)[n];
+ SfxChildWindow *pChild = pCW->pWin;
+ if ( pChild )
+ {
+ if ( pChild->GetType() == nId )
+ {
+ if ( pChild->GetWindow()->GetType() == RSC_DOCKINGWINDOW )
+ // it's a DockingWindow
+ pDockWin = (SfxDockingWindow*) pChild->GetWindow();
+ else
+ // FloatingWindow or ModelessDialog
+ pWin = pChild->GetWindow();
+ break;
+ }
+ }
+ }
+
+ if ( pDockWin )
+ {
+ if ( eChild == SFX_CHILDWIN_DOCKINGWINDOW || pDockWin->GetAlignment() == SFX_ALIGN_NOALIGNMENT )
+ {
+ if ( eChild == SFX_CHILDWIN_SPLITWINDOW && eConfig == SFX_TOGGLEFLOATMODE)
+ {
+ // DockingWindow was dragged out of a SplitWindow
+ pCW->pCli = RegisterChild_Impl(*pDockWin, pDockWin->GetAlignment(), pCW->pWin->CanGetFocus());
+ pCW->pCli->nVisible = CHILD_VISIBLE;
+ }
+
+ pWin = pDockWin;
+ }
+ else
+ {
+ SfxSplitWindow *pSplitWin = GetSplitWindow_Impl(pDockWin->GetAlignment());
+
+ // configure DockingWindow inside a SplitWindow
+ if ( eConfig == SFX_TOGGLEFLOATMODE)
+ {
+ // DockingWindow was dragged into a SplitWindow
+ pCW->pCli = 0;
+ ReleaseChild_Impl(*pDockWin);
+ }
+
+ pWin = pSplitWin->GetSplitWindow();
+ if ( pSplitWin->GetWindowCount() == 1 )
+ ((SplitWindow*)pWin)->Show( TRUE, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
+ }
+ }
+
+ DBG_ASSERT( pCW, "Unknown window!" );
+ if ( !pCW && pParent )
+ {
+ pParent->ConfigChild_Impl( eChild, eConfig, nId );
+ return;
+ }
+ }
+
+ if ( !bSorted )
+ // windows may have been registered and released without an update until now
+ Sort_Impl();
+
+ SfxChild_Impl *pChild = 0;
+ USHORT n;
+ for ( n=0; n<aSortedList.Count(); ++n )
+ {
+ pChild = (*pChilds)[aSortedList[n]];
+ if ( pChild )
+ if ( pChild->pWin == pWin )
+ break;
+ }
+
+ if ( n < aSortedList.Count() )
+ // sometimes called while toggeling float mode
+ nPos = aSortedList[n];
+
+ switch ( eConfig )
+ {
+ case SFX_SETDOCKINGRECTS :
+ {
+ if ( nPos == USHRT_MAX )
+ return;
+
+// SfxChild_Impl *pChild = (*pChilds)[nPos];
+ Rectangle aOuterRect( GetTopRect_Impl() );
+ aOuterRect.SetPos( pWorkWin->OutputToScreenPixel( aOuterRect.TopLeft() ));
+ Rectangle aInnerRect( aOuterRect );
+ BOOL bTbx = (eChild == SFX_CHILDWIN_OBJECTBAR);
+
+ // Das gerade betroffene Fenster wird bei der Berechnung des
+ // inneren Rechtecks mit eingeschlossen!
+ for ( USHORT m=0; m<aSortedList.Count(); ++m )
+ {
+ USHORT i=aSortedList[m];
+ SfxChild_Impl* pCli = (*pChilds)[i];
+
+ if ( pCli && pCli->nVisible == CHILD_VISIBLE && pCli->pWin )
+ {
+ switch ( pCli->eAlign )
+ {
+ case SFX_ALIGN_TOP:
+ // Objekt-Toolboxen kommen immer zuletzt
+ //if ( bTbx || i <= nPos)
+ aInnerRect.Top() += pCli->aSize.Height();
+ break;
+
+ case SFX_ALIGN_TOOLBOXTOP:
+ // Toolbox geht nur vor, wenn nicht h"ohere Position
+ if ( bTbx && i <= nPos)
+ aInnerRect.Top() += pCli->aSize.Height();
+ break;
+
+ case SFX_ALIGN_HIGHESTTOP:
+ // Geht immer vor
+ aInnerRect.Top() += pCli->aSize.Height();
+ break;
+
+ case SFX_ALIGN_LOWESTTOP:
+ // Wird nur mitgez"ahlt, wenn es das aktuelle Fenster ist
+ if ( i == nPos )
+ aInnerRect.Top() += pCli->aSize.Height();
+ break;
+
+ case SFX_ALIGN_BOTTOM:
+ // Objekt-Toolboxen kommen immer zuletzt
+ //if ( bTbx || i <= nPos)
+ aInnerRect.Bottom() -= pCli->aSize.Height();
+ break;
+
+ case SFX_ALIGN_TOOLBOXBOTTOM:
+ // Toolbox geht nur vor, wenn nicht h"ohere Position
+ if ( bTbx && i <= nPos)
+ aInnerRect.Bottom() -= pCli->aSize.Height();
+ break;
+
+ case SFX_ALIGN_LOWESTBOTTOM:
+ // Geht immer vor
+ aInnerRect.Bottom() -= pCli->aSize.Height();
+ break;
+
+ case SFX_ALIGN_HIGHESTBOTTOM:
+ // Wird nur mitgez"ahlt, wenn es das aktuelle Fenster ist
+ if ( i == nPos )
+ aInnerRect.Bottom() -= pCli->aSize.Height();
+ break;
+
+ case SFX_ALIGN_LEFT:
+ // Toolboxen kommen immer zuletzt
+ //if (bTbx || i <= nPos)
+ aInnerRect.Left() += pCli->aSize.Width();
+ break;
+
+ case SFX_ALIGN_TOOLBOXLEFT:
+ // Toolboxen kommen immer zuletzt
+ if (bTbx && i <= nPos)
+ aInnerRect.Left() += pCli->aSize.Width();
+ break;
+
+ case SFX_ALIGN_FIRSTLEFT:
+ // Geht immer vor
+ aInnerRect.Left() += pCli->aSize.Width();
+ break;
+
+ case SFX_ALIGN_LASTLEFT:
+ // Wird nur mitgez"ahlt, wenn es das aktuelle Fenster ist
+ if (i == nPos)
+ aInnerRect.Left() += pCli->aSize.Width();
+
+ case SFX_ALIGN_RIGHT:
+ // Toolboxen kommen immer zuletzt
+ //if (bTbx || i <= nPos)
+ aInnerRect.Right() -= pCli->aSize.Width();
+ break;
+
+ case SFX_ALIGN_TOOLBOXRIGHT:
+ // Toolboxen kommen immer zuletzt
+ if (bTbx && i <= nPos)
+ aInnerRect.Right() -= pCli->aSize.Width();
+ break;
+
+ case SFX_ALIGN_FIRSTRIGHT:
+ // Wird nur mitgez"ahlt, wenn es das aktuelle Fenster ist
+ if (i == nPos)
+ aInnerRect.Right() -= pCli->aSize.Width();
+ break;
+
+ case SFX_ALIGN_LASTRIGHT:
+ // Geht immer vor
+ aInnerRect.Right() -= pCli->aSize.Width();
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ pDockWin->SetDockingRects(aOuterRect, aInnerRect);
+ break;
+ }
+
+ case SFX_MOVEDOCKINGWINDOW :
+ case SFX_ALIGNDOCKINGWINDOW :
+ case SFX_TOGGLEFLOATMODE:
+ {
+ if ( nPos == USHRT_MAX && !pCW )
+ return;
+
+ SfxChildAlignment eAlign = SFX_ALIGN_NOALIGNMENT;
+ SfxChild_Impl *pCli = ( nPos != USHRT_MAX ) ? (*pChilds)[nPos] : 0;
+ if ( pCli && pDockWin )
+ {
+ eAlign = pDockWin->GetAlignment();
+ if ( eChild == SFX_CHILDWIN_DOCKINGWINDOW || eAlign == SFX_ALIGN_NOALIGNMENT)
+ {
+ // configuration inside the SplitWindow, no change for the SplitWindows' configuration
+ pCli->bResize = TRUE;
+ pCli->aSize = pDockWin->GetSizePixel();
+ }
+ }
+
+ if ( pCli )
+ {
+ if( pCli->eAlign != eAlign )
+ {
+ bSorted = FALSE;
+ pCli->eAlign = eAlign;
+ }
+
+ ArrangeChilds_Impl();
+ ShowChilds_Impl();
+ }
+
+ if ( pCW && pCW->pWin )
+ {
+ // store changed configuration
+ USHORT nFlags = pCW->aInfo.nFlags;
+ pCW->aInfo = pCW->pWin->GetInfo();
+ pCW->aInfo.nFlags |= nFlags;
+ if ( eConfig != SFX_MOVEDOCKINGWINDOW )
+ SaveStatus_Impl( pCW->pWin, pCW->aInfo);
+ }
+
+ break;
+ }
+ }
+}
+
+
+//--------------------------------------------------------------------
+
+void SfxWorkWindow::SetChildWindowVisible_Impl( sal_uInt32 lId, BOOL bEnabled, USHORT nMode )
+{
+ USHORT nInter = (USHORT) ( lId >> 16 );
+ USHORT nId = (USHORT) ( lId & 0xFFFF );
+
+ SfxChildWin_Impl *pCW=NULL;
+ SfxWorkWindow *pWork = pParent;
+
+ // Den obersten parent nehmen; ChildWindows werden immer am WorkWindow
+ // der Task bzw. des Frames oder am AppWorkWindow angemeldet
+ while ( pWork && pWork->pParent )
+ pWork = pWork->pParent;
+
+ if ( pWork )
+ {
+ // Dem Parent schon bekannt ?
+ USHORT nCount = pWork->pChildWins->Count();
+ for (USHORT n=0; n<nCount; n++)
+ if ((*pWork->pChildWins)[n]->nSaveId == nId)
+ {
+ pCW = (*pWork->pChildWins)[n];
+ break;
+ }
+ }
+
+ if ( !pCW )
+ {
+ // Kein Parent oder dem Parent noch unbekannt, dann bei mir suchen
+ USHORT nCount = pChildWins->Count();
+ for (USHORT n=0; n<nCount; n++)
+ if ((*pChildWins)[n]->nSaveId == nId)
+ {
+ pCW = (*pChildWins)[n];
+ break;
+ }
+ }
+
+ if ( !pCW )
+ {
+ // Ist neu, also initialisieren; je nach Flag beim Parent oder bei
+ // mir eintragen
+ pCW = new SfxChildWin_Impl( lId );
+ pCW->nId = nId;
+ InitializeChild_Impl( pCW );
+ if ( pWork && !( pCW->aInfo.nFlags & SFX_CHILDWIN_TASK ) )
+ pWork->pChildWins->Insert( pWork->pChildWins->Count(), pCW );
+ else
+ pChildWins->Insert( pChildWins->Count(), pCW );
+ }
+
+ pCW->nId = nId;
+ if ( nInter )
+ pCW->nInterfaceId = nInter;
+ pCW->nVisibility = nMode;
+ pCW->bEnable = bEnabled;
+#if 0
+ if ( pCW->pWin )
+ pCW->pWin->GetWindow()->EnableInput( bEnabled &&
+ ( pWorkWin->IsInputEnabled() /* || pCW->pWin->GetAlignment() == SFX_ALIGN_NOALIGNMENT */ ) );
+#endif
+ pCW->nVisibility = nMode;
+}
+
+//--------------------------------------------------------------------
+// Der An/Aus-Status eines ChildWindows wird umgeschaltet.
+
+void SfxWorkWindow::ToggleChildWindow_Impl(USHORT nId, BOOL bSetFocus)
+{
+ USHORT nCount = pChildWins->Count();
+ USHORT n;
+ for (n=0; n<nCount; n++)
+ if ((*pChildWins)[n]->nId == nId)
+ break;
+
+ if ( n<nCount )
+ {
+ // Das Fenster ist schon bekannt
+ SfxChildWin_Impl *pCW = (*pChildWins)[n];
+ SfxChildWindow *pChild = pCW->pWin;
+
+ bool bCreationAllowed( true );
+ if ( !bInternalDockingAllowed )
+ {
+ // Special case for all non-floatable child windows. We have
+ // to prevent the creation here!
+ bCreationAllowed = !( pCW->aInfo.nFlags & SFX_CHILDWIN_FORCEDOCK );
+ }
+
+ if ( bCreationAllowed )
+ {
+ if ( pCW->bCreate )
+ {
+ if ( pChild )
+ {
+ if ( pChild->QueryClose() )
+ {
+ pCW->bCreate = FALSE;
+ if ( pChild->IsHideAtToggle() )
+ {
+ ShowChildWindow_Impl( nId, FALSE, bSetFocus );
+ }
+ else
+ {
+ // Fenster soll ausgeschaltet werdem
+ pChild->SetVisible_Impl( FALSE );
+ RemoveChildWin_Impl( pCW );
+ }
+ }
+ }
+ else
+ {
+ // no actual Window exists, yet => just remember the "switched off" state
+ pCW->bCreate = FALSE;
+ }
+ }
+ else
+ {
+ pCW->bCreate = AllowChildWindowCreation_Impl( *pCW );
+ if ( pCW->bCreate )
+ {
+ if ( pChild )
+ {
+ ShowChildWindow_Impl( nId, TRUE, bSetFocus );
+ }
+ else
+ {
+ // create actual Window
+ CreateChildWin_Impl( pCW, bSetFocus );
+ if ( !pCW->pWin )
+ // no success
+ pCW->bCreate = FALSE;
+ }
+ }
+ }
+ }
+
+ ArrangeChilds_Impl();
+ ShowChilds_Impl();
+
+ if ( pCW->bCreate && bCreationAllowed )
+ {
+ if ( !pCW->pCli )
+ {
+ SfxDockingWindow *pDock =
+ (SfxDockingWindow*) pCW->pWin->GetWindow();
+ if ( pDock->IsAutoHide_Impl() )
+ pDock->AutoShow_Impl();
+ }
+ }
+
+ return;
+ }
+ else if ( pParent )
+ {
+ pParent->ToggleChildWindow_Impl( nId, bSetFocus );
+ return;
+ }
+
+#ifdef DBG_UTIL
+ nCount = pChildWins->Count();
+ for (n=0; n<nCount; n++)
+ if ((*pChildWins)[n]->nSaveId == nId)
+ break;
+
+ if ( n < nCount )
+ {
+ DBG_ERROR("ChildWindow ist nicht im Kontext!");
+ }
+ else
+ {
+ DBG_ERROR("ChildWindow ist nicht registriert!");
+ }
+#endif
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxWorkWindow::HasChildWindow_Impl(USHORT nId)
+{
+ USHORT nCount = pChildWins->Count();
+ USHORT n;
+ for (n=0; n<nCount; n++)
+ if ((*pChildWins)[n]->nSaveId == nId)
+ break;
+
+ if (n<nCount)
+ {
+ SfxChildWin_Impl *pCW = (*pChildWins)[n];
+ SfxChildWindow *pChild = pCW->pWin;
+ return ( pChild && pCW->bCreate );
+ }
+
+ if ( pParent )
+ return pParent->HasChildWindow_Impl( nId );
+
+ return FALSE;
+}
+
+BOOL SfxWorkWindow::IsFloating( USHORT nId )
+{
+ SfxChildWin_Impl *pCW=NULL;
+ SfxWorkWindow *pWork = pParent;
+
+ // Den obersten parent nehmen; ChildWindows werden immer am WorkWindow
+ // der Task bzw. des Frames oder am AppWorkWindow angemeldet
+ while ( pWork && pWork->pParent )
+ pWork = pWork->pParent;
+
+ if ( pWork )
+ {
+ // Dem Parent schon bekannt ?
+ USHORT nCount = pWork->pChildWins->Count();
+ for (USHORT n=0; n<nCount; n++)
+ if ((*pWork->pChildWins)[n]->nSaveId == nId)
+ {
+ pCW = (*pWork->pChildWins)[n];
+ break;
+ }
+ }
+
+ if ( !pCW )
+ {
+ // Kein Parent oder dem Parent noch unbekannt, dann bei mir suchen
+ USHORT nCount = pChildWins->Count();
+ for (USHORT n=0; n<nCount; n++)
+ if ((*pChildWins)[n]->nSaveId == nId)
+ {
+ pCW = (*pChildWins)[n];
+ break;
+ }
+ }
+
+ if ( !pCW )
+ {
+ // Ist neu, also initialisieren; je nach Flag beim Parent oder bei
+ // mir eintragen
+ pCW = new SfxChildWin_Impl( nId );
+ pCW->bEnable = FALSE;
+ pCW->nId = 0;
+ pCW->nVisibility = 0;
+ InitializeChild_Impl( pCW );
+ if ( pWork && !( pCW->aInfo.nFlags & SFX_CHILDWIN_TASK ) )
+ pWork->pChildWins->Insert( pWork->pChildWins->Count(), pCW );
+ else
+ pChildWins->Insert( pChildWins->Count(), pCW );
+ }
+
+ SfxChildAlignment eAlign;
+ if ( pCW->aInfo.GetExtraData_Impl( &eAlign ) )
+ return( eAlign == SFX_ALIGN_NOALIGNMENT );
+ else
+ return TRUE;
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxWorkWindow::KnowsChildWindow_Impl(USHORT nId)
+{
+ SfxChildWin_Impl *pCW=0;
+ USHORT nCount = pChildWins->Count();
+ USHORT n;
+ for (n=0; n<nCount; n++)
+ {
+ pCW = (*pChildWins)[n];
+ if ( pCW->nSaveId == nId)
+ break;
+ }
+
+ if (n<nCount)
+ {
+ if ( !(pCW->aInfo.nFlags & SFX_CHILDWIN_ALWAYSAVAILABLE) && !IsVisible_Impl( pCW->nVisibility ) )
+ return FALSE;
+ return pCW->bEnable;
+ }
+ else if ( pParent )
+ return pParent->KnowsChildWindow_Impl( nId );
+ else
+ return FALSE;
+}
+
+//--------------------------------------------------------------------
+
+void SfxWorkWindow::SetChildWindow_Impl(USHORT nId, BOOL bOn, BOOL bSetFocus)
+{
+ SfxChildWin_Impl *pCW=NULL;
+ SfxWorkWindow *pWork = pParent;
+
+ // Den obersten parent nehmen; ChildWindows werden immer am WorkWindow
+ // der Task bzw. des Frames oder am AppWorkWindow angemeldet
+ while ( pWork && pWork->pParent )
+ pWork = pWork->pParent;
+
+ if ( pWork )
+ {
+ // Dem Parent schon bekannt ?
+ USHORT nCount = pWork->pChildWins->Count();
+ for (USHORT n=0; n<nCount; n++)
+ if ((*pWork->pChildWins)[n]->nSaveId == nId)
+ {
+ pCW = (*pWork->pChildWins)[n];
+ break;
+ }
+ }
+
+ if ( !pCW )
+ {
+ // Kein Parent oder dem Parent noch unbekannt, dann bei mir suchen
+ USHORT nCount = pChildWins->Count();
+ for (USHORT n=0; n<nCount; n++)
+ if ((*pChildWins)[n]->nSaveId == nId)
+ {
+ pCW = (*pChildWins)[n];
+ pWork = this;
+ break;
+ }
+ }
+
+ if ( !pCW )
+ {
+ // Ist neu, also initialisieren; je nach Flag beim Parent oder bei
+ // mir eintragen
+ pCW = new SfxChildWin_Impl( nId );
+ InitializeChild_Impl( pCW );
+ if ( !pWork || pCW->aInfo.nFlags & SFX_CHILDWIN_TASK )
+ pWork = this;
+ pWork->pChildWins->Insert( pWork->pChildWins->Count(), pCW );
+ }
+
+ if ( pCW->bCreate != bOn )
+ pWork->ToggleChildWindow_Impl(nId,bSetFocus);
+}
+
+//--------------------------------------------------------------------
+
+void SfxWorkWindow::ShowChildWindow_Impl(USHORT nId, BOOL bVisible, BOOL bSetFocus)
+{
+ USHORT nCount = pChildWins->Count();
+ SfxChildWin_Impl* pCW=0;
+ USHORT n;
+ for (n=0; n<nCount; n++)
+ {
+ pCW = (*pChildWins)[n];
+ if (pCW->nId == nId)
+ break;
+ }
+
+ if ( n<nCount )
+ {
+ SfxChildWindow *pChildWin = pCW->pWin;
+ if ( pChildWin )
+ {
+ if ( bVisible )
+ {
+ if ( pCW->pCli )
+ {
+ pCW->pCli->bSetFocus = bSetFocus;
+ pCW->pCli->nVisible = CHILD_VISIBLE;
+ pChildWin->Show( bSetFocus && pChildWin->WantsFocus() ? 0 : SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
+ }
+ else
+ ((SfxDockingWindow*)pChildWin->GetWindow())->Reappear_Impl();
+
+ }
+ else
+ {
+ if ( pCW->pCli )
+ {
+ pCW->pCli->nVisible = CHILD_VISIBLE ^ CHILD_NOT_HIDDEN;
+ pCW->pWin->Hide();
+ }
+ else
+ ((SfxDockingWindow*)pChildWin->GetWindow())->Disappear_Impl();
+
+ }
+
+ ArrangeChilds_Impl();
+ ShowChilds_Impl();
+ }
+ else if ( bVisible )
+ {
+ SetChildWindow_Impl( nId, TRUE, bSetFocus );
+ pChildWin = pCW->pWin;
+ }
+
+ if ( pChildWin )
+ {
+ pChildWin->SetVisible_Impl( bVisible );
+ USHORT nFlags = pCW->aInfo.nFlags;
+ pCW->aInfo = pChildWin->GetInfo();
+ pCW->aInfo.nFlags |= nFlags;
+ if ( !pCW->bCreate )
+ SaveStatus_Impl( pChildWin, pCW->aInfo );
+ }
+
+ return;
+ }
+
+ if ( pParent )
+ {
+ pParent->ShowChildWindow_Impl( nId, bVisible, bSetFocus );
+ return;
+ }
+
+#ifdef DBG_UTIL
+ nCount = pChildWins->Count();
+ for (n=0; n<nCount; n++)
+ if ((*pChildWins)[n]->nSaveId == nId)
+ break;
+
+ if ( n<nCount )
+ {
+ DBG_ERROR("ChildWindow ist nicht im Kontext!");
+ }
+ else
+ {
+ DBG_ERROR("ChildWindow ist nicht registriert!");
+ }
+#endif
+}
+
+//--------------------------------------------------------------------
+
+SfxChildWindow* SfxWorkWindow::GetChildWindow_Impl(USHORT nId)
+{
+ USHORT nCount = pChildWins->Count();
+ USHORT n;
+ for (n=0; n<nCount; n++)
+ if ((*pChildWins)[n]->nSaveId == nId)
+ break;
+
+ if (n<nCount)
+ return (*pChildWins)[n]->pWin;
+ else if ( pParent )
+ return pParent->GetChildWindow_Impl( nId );
+ return 0;
+}
+
+//------------------------------------------------------------------------
+
+void SfxWorkWindow::ResetChildWindows_Impl()
+{
+// if ( pParent )
+// pParent->ResetChildWindows_Impl();
+
+ for ( USHORT n = 0; n < pChildWins->Count(); ++n )
+ {
+ (*pChildWins)[n]->nId = 0;
+ (*pChildWins)[n]->bEnable = FALSE;
+ }
+}
+
+//------------------------------------------------------------------------
+// Virtuelle Methode, die die Gr"o\se der Fl"ache (client area) des parent
+// windows liefert, in der Child-Fenster angeordnet werden k"onnen.
+// in der ClientArea des parent findet.
+
+Rectangle SfxWorkWindow::GetTopRect_Impl()
+{
+ return Rectangle (Point(), pWorkWin->GetOutputSizePixel() );
+}
+
+//------------------------------------------------------------------------
+// Virtuelle Methode, die die Gr"o\se der Fl"ache (client area) des parent
+// windows liefert, in der Child-Fenster angeordnet werden k"onnen.
+// in der ClientArea des parent findet.
+
+Rectangle SfxFrameWorkWin_Impl::GetTopRect_Impl()
+{
+ return pMasterFrame->GetTopOuterRectPixel_Impl();
+}
+
+//------------------------------------------------------------------------
+// Virtuelle Methode, um herauszufinden, ob ein Child-Fenster noch Platz
+// in der ClientArea des parent findet.
+
+BOOL SfxWorkWindow::RequestTopToolSpacePixel_Impl( SvBorder aBorder )
+{
+ if ( !IsDockingAllowed() ||
+ aClientArea.GetWidth() < aBorder.Left() + aBorder.Right() ||
+ aClientArea.GetHeight() < aBorder.Top() + aBorder.Bottom() )
+ return FALSE;
+ else
+ return TRUE;;
+}
+
+void SfxWorkWindow::SaveStatus_Impl(SfxChildWindow *pChild, const SfxChildWinInfo &rInfo)
+{
+ // Den Status vom Presentation mode wollen wir nicht sichern
+ if ( IsDockingAllowed() && bInternalDockingAllowed )
+ pChild->SaveStatus(rInfo);
+}
+
+void SfxWorkWindow::InitializeChild_Impl(SfxChildWin_Impl *pCW)
+{
+ SfxChildWinFactory* pFact=0;
+ SfxApplication *pApp = SFX_APP();
+ {
+ SfxChildWinFactArr_Impl &rFactories = pApp->GetChildWinFactories_Impl();
+ for ( USHORT nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ {
+ pFact = rFactories[nFactory];
+ if ( pFact->nId == pCW->nSaveId )
+ {
+ pCW->aInfo = pFact->aInfo;
+ SfxChildWindow::InitializeChildWinFactory_Impl(
+ pCW->nSaveId, pCW->aInfo);
+ pCW->bCreate = pCW->aInfo.bVisible;
+ USHORT nFlags = pFact->aInfo.nFlags;
+ if ( nFlags & SFX_CHILDWIN_TASK )
+ pCW->aInfo.nFlags |= SFX_CHILDWIN_TASK;
+ if ( nFlags & SFX_CHILDWIN_CANTGETFOCUS )
+ pCW->aInfo.nFlags |= SFX_CHILDWIN_CANTGETFOCUS;
+ if ( nFlags & SFX_CHILDWIN_FORCEDOCK )
+ pCW->aInfo.nFlags |= SFX_CHILDWIN_FORCEDOCK;
+ pFact->aInfo = pCW->aInfo;
+ return;
+ }
+ }
+ }
+
+ SfxDispatcher *pDisp = pBindings->GetDispatcher_Impl();
+ SfxModule *pMod = pDisp ? SfxModule::GetActiveModule( pDisp->GetFrame() ) :0;
+ if ( pMod )
+ {
+ SfxChildWinFactArr_Impl *pFactories = pMod->GetChildWinFactories_Impl();
+ if ( pFactories )
+ {
+ SfxChildWinFactArr_Impl &rFactories = *pFactories;
+ for ( USHORT nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ {
+ pFact = rFactories[nFactory];
+ if ( pFact->nId == pCW->nSaveId )
+ {
+ pCW->aInfo = pFact->aInfo;
+ SfxChildWindow::InitializeChildWinFactory_Impl(
+ pCW->nSaveId, pCW->aInfo);
+ pCW->bCreate = pCW->aInfo.bVisible;
+ USHORT nFlags = pFact->aInfo.nFlags;
+ if ( nFlags & SFX_CHILDWIN_TASK )
+ pCW->aInfo.nFlags |= SFX_CHILDWIN_TASK;
+ if ( nFlags & SFX_CHILDWIN_CANTGETFOCUS )
+ pCW->aInfo.nFlags |= SFX_CHILDWIN_CANTGETFOCUS;
+ if ( nFlags & SFX_CHILDWIN_FORCEDOCK )
+ pCW->aInfo.nFlags |= SFX_CHILDWIN_FORCEDOCK;
+ if ( nFlags & SFX_CHILDWIN_ALWAYSAVAILABLE )
+ pCW->aInfo.nFlags |= SFX_CHILDWIN_ALWAYSAVAILABLE;
+ pFact->aInfo = pCW->aInfo;
+ return;
+ }
+ }
+ }
+ }
+}
+/*
+SfxStatBar_Impl* SfxWorkWindow::GetStatusBar_Impl()
+{
+ return &aStatBar;
+} */
+
+SfxSplitWindow* SfxWorkWindow::GetSplitWindow_Impl( SfxChildAlignment eAlign )
+{
+ switch ( eAlign )
+ {
+ case SFX_ALIGN_TOP:
+ return pSplit[2];
+
+ case SFX_ALIGN_BOTTOM:
+ return pSplit[3];
+
+ case SFX_ALIGN_LEFT:
+ return pSplit[0];
+
+ case SFX_ALIGN_RIGHT:
+ return pSplit[1];
+
+ default:
+ return 0;
+ }
+}
+
+void SfxWorkWindow::MakeChildsVisible_Impl( BOOL bVis )
+{
+ if ( pParent )
+ pParent->MakeChildsVisible_Impl( bVis );
+
+ bAllChildsVisible = bVis;
+ if ( bVis )
+ {
+ if ( !bSorted )
+ Sort_Impl();
+ for ( USHORT n=0; n<aSortedList.Count(); ++n )
+ {
+ SfxChild_Impl* pCli = (*pChilds)[aSortedList[n]];
+ if ( (pCli->eAlign == SFX_ALIGN_NOALIGNMENT) || (IsDockingAllowed() && bInternalDockingAllowed) )
+ pCli->nVisible |= CHILD_ACTIVE;
+ }
+ }
+ else
+ {
+ if ( !bSorted )
+ Sort_Impl();
+ for ( USHORT n=0; n<aSortedList.Count(); ++n )
+ {
+ SfxChild_Impl* pCli = (*pChilds)[aSortedList[n]];
+ pCli->nVisible &= ~CHILD_ACTIVE;
+ }
+ }
+}
+
+BOOL SfxWorkWindow::IsAutoHideMode( const SfxSplitWindow *pSplitWin )
+{
+ for ( USHORT n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
+ {
+ if ( pSplit[n] != pSplitWin && pSplit[n]->IsAutoHide( TRUE ) )
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+void SfxWorkWindow::EndAutoShow_Impl( Point aPos )
+{
+ if ( pParent )
+ pParent->EndAutoShow_Impl( aPos );
+
+ for ( USHORT n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
+ {
+ SfxSplitWindow *p = pSplit[n];
+ if ( p && p->IsAutoHide() )
+ {
+ Point aLocalPos = p->ScreenToOutputPixel( aPos );
+ Point aEmptyPoint = Point();
+ Rectangle aRect( aEmptyPoint, p->GetSizePixel() );
+ if ( !aRect.IsInside( aLocalPos ) )
+ p->FadeOut();
+ }
+ }
+}
+
+void SfxWorkWindow::ArrangeAutoHideWindows( SfxSplitWindow *pActSplitWin )
+{
+ if ( m_nLock )
+ return;
+
+ if ( pParent )
+ pParent->ArrangeAutoHideWindows( pActSplitWin );
+
+ Rectangle aArea( aUpperClientArea );
+ for ( USHORT n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
+ {
+ // Es werden entweder Dummyfenster oder Fenster im AutoShow-Modus
+ // ( nicht gepinned, FadeIn ) behandelt.
+ // Nur das "ubergebene Fenster darf unsichtbar sein, denn vielleicht
+ // soll daf"ur gerade die Gr"o\se berechnet werden, bevor es angezeigt
+ // wird.
+ SfxSplitWindow* pSplitWin = pSplit[n];
+ BOOL bDummyWindow = !pSplitWin->IsFadeIn();
+ Window *pDummy = pSplitWin->GetSplitWindow();
+ Window *pWin = bDummyWindow ? pDummy : pSplitWin;
+ if ( (pSplitWin->IsPinned() && !bDummyWindow) || (!pWin->IsVisible() && pActSplitWin != pSplitWin) )
+ continue;
+
+ // Breite und Position des Dummy-Fensters als Ausgangspunkt
+ Size aSize = pDummy->GetSizePixel();
+ Point aPos = pDummy->GetPosPixel();
+
+ switch ( n )
+ {
+ case ( 0 ) :
+ {
+ // Linkes SplitWindow
+ // Breite vom Fenster selbst holen, wenn nicht das DummyWindow
+ if ( !bDummyWindow )
+ aSize.Width() = pSplitWin->GetSizePixel().Width();
+
+ // Wenn links ein Window sichtbar ist, beginnt der freie
+ // Bereich rechts davon bzw. bei der Client area
+ long nLeft = aPos.X() + aSize.Width();
+ if ( nLeft > aArea.Left() )
+ aArea.Left() = nLeft;
+ break;
+ }
+ case ( 1 ) :
+ {
+ // Rechtes SplitWindow
+ // Position um Differenz der Breiten korrigieren
+ aPos.X() += aSize.Width();
+
+ // Breite vom Fenster selbst holen, wenn nicht das DummyWindow
+ if ( !bDummyWindow )
+ aSize.Width() = pSplitWin->GetSizePixel().Width();
+
+ aPos.X() -= aSize.Width();
+
+ // Wenn links schon ein Fenster aufgeklappt ist, darf
+ // das rechte nicht dar"uber gehen
+ if ( aPos.X() < aArea.Left() )
+ {
+ aPos.X() = aArea.Left();
+ aSize.Width() = aArea.GetWidth();
+ }
+
+ // Wenn rechts ein Window sichtbar ist, endet der freie
+ // Bereich links davon bzw. bei der Client area
+ long nRight = aPos.X();
+ if ( nRight < aArea.Right() )
+ aArea.Right() = nRight;
+ break;
+ }
+ case ( 2 ) :
+ {
+ // Oberes SplitWindow
+ // H"ohe vom Fenster selbst holen, wenn nicht das DummyWindow
+ if ( !bDummyWindow )
+ aSize.Height() = pSplitWin->GetSizePixel().Height();
+
+ // Breite anpassen, je nachdem ob links oder rechts
+ // schon ein Fenster aufgeklappt ist
+ aPos.X() = aArea.Left();
+ aSize.Width() = aArea.GetWidth();
+
+ // Wenn oben ein Window sichtbar ist, beginnt der freie
+ // Bereich darunter bzw. bei der Client Area
+ long nTop = aPos.Y() + aSize.Height();
+ if ( nTop > aArea.Top() )
+ aArea.Top() = nTop;
+ break;
+ }
+ case ( 3 ) :
+ {
+ // Das untere SplitWindow
+ // Position um Differenz der H"ohen korrigieren
+ aPos.Y() += aSize.Height();
+
+ // H"ohe vom Fenster selbst holen, wenn nicht das DummmyWindow
+ if ( !bDummyWindow )
+ aSize.Height() = pSplitWin->GetSizePixel().Height();
+
+ aPos.Y() -= aSize.Height();
+
+ // Breite anpassen, je nachdem ob links oder rechts
+ // schon ein Fenster aufgeklappt ist
+ aPos.X() = aArea.Left();
+ aSize.Width() = aArea.GetWidth();
+
+ // Wenn oben schon ein Fenster aufgeklappt ist, darf
+ // das untere nicht dar"uber gehen
+ if ( aPos.Y() < aArea.Top() )
+ {
+ aPos.Y() = aArea.Top();
+ aSize.Height() = aArea.GetHeight();
+ }
+
+ break;
+ }
+ }
+
+ if ( !bDummyWindow )
+ // Das FadeIn-Window ist ein Float, dessen Koordinaten in
+ // Screenkoordinaten gesetzt werden
+ pSplitWin->SetPosSizePixel( pWorkWin->OutputToScreenPixel(aPos), aSize );
+ else
+ // Das angedockte DummyWindow
+ pDummy->SetPosSizePixel( aPos, aSize );
+ }
+}
+
+Rectangle SfxWorkWindow::GetFreeArea( BOOL bAutoHide ) const
+{
+ if ( bAutoHide )
+ {
+ Rectangle aArea( aClientArea );
+ for ( USHORT n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
+ {
+ if ( pSplit[n]->IsPinned() || !pSplit[n]->IsVisible() )
+ continue;
+
+ Size aSize = pSplit[n]->GetSizePixel();
+ switch ( n )
+ {
+ case ( 0 ) :
+ aArea.Left() += aSize.Width();
+ break;
+ case ( 1 ) :
+ aArea.Right() -= aSize.Width();
+ break;
+ case ( 2 ) :
+ aArea.Top() += aSize.Height();
+ break;
+ case ( 3 ) :
+ aArea.Bottom() -= aSize.Height();
+ break;
+ }
+ }
+
+ return aArea;
+ }
+ else
+ return aClientArea;
+}
+
+SfxChildWinController_Impl::SfxChildWinController_Impl( USHORT nID, SfxWorkWindow *pWork )
+ : SfxControllerItem( nID, pWork->GetBindings() )
+ , pWorkwin( pWork )
+{}
+
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SfxWorkWindow::CreateDispatch( const String& )
+{
+ return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >();
+}
+
+void SfxChildWinController_Impl::StateChanged(
+ USHORT nSID, SfxItemState eState, const SfxPoolItem* )
+{
+ pWorkwin->DisableChildWindow_Impl( nSID, eState == SFX_ITEM_DISABLED );
+}
+
+void SfxWorkWindow::DisableChildWindow_Impl( USHORT nId, BOOL bDisable )
+{
+ USHORT nCount = pChildWins->Count();
+ USHORT n;
+ for (n=0; n<nCount; n++)
+ if ((*pChildWins)[n]->nSaveId == nId)
+ break;
+ if ( n<nCount && (*pChildWins)[n]->bDisabled != bDisable )
+ {
+ (*pChildWins)[n]->bDisabled = bDisable;
+ UpdateChildWindows_Impl();
+ ArrangeChilds_Impl();
+ ShowChilds_Impl();
+ }
+}
+
+void SfxWorkWindow::SetActiveChild_Impl( Window *pChild )
+{
+ pActiveChild = pChild;
+}
+
+Window* SfxWorkWindow::GetActiveChild_Impl()
+{
+ return pActiveChild;
+}
+
+BOOL SfxWorkWindow::ActivateNextChild_Impl( BOOL bForward )
+{
+ // Alle Kinder gem"a\s Liste sortieren
+ SvUShorts aList;
+ for ( USHORT i=SFX_OBJECTBAR_MAX; i<pChilds->Count(); i++)
+ {
+ SfxChild_Impl *pCli = (*pChilds)[i];
+ if ( pCli && pCli->bCanGetFocus && pCli->pWin )
+ {
+ USHORT k;
+ for (k=0; k<aList.Count(); k++)
+ if ( ChildTravelValue((*pChilds)[aList[k]]->eAlign) > ChildTravelValue(pCli->eAlign) )
+ break;
+ aList.Insert(i,k);
+ }
+ }
+
+ if ( aList.Count() == 0 )
+ return FALSE;
+
+ USHORT nTopValue = ChildTravelValue( SFX_ALIGN_LOWESTTOP );
+ for ( USHORT i=0; i<aList.Count(); i++ )
+ {
+ SfxChild_Impl* pCli = (*pChilds)[aList[i]];
+ if ( pCli->pWin && ChildTravelValue( pCli->eAlign ) > nTopValue )
+ break;
+ }
+
+ USHORT n = bForward ? 0 : aList.Count()-1;
+ SfxChild_Impl *pAct=NULL;
+ if ( pActiveChild )
+ {
+ // Das aktive Fenster suchen
+ for ( n=0; n<aList.Count(); n++ )
+ {
+ SfxChild_Impl* pCli = (*pChilds)[aList[n]];
+ if ( pCli && pCli->pWin && ( pCli->pWin == pActiveChild || !pActiveChild ) )
+ {
+ pAct = pCli;
+ break;
+ }
+ }
+ }
+
+ // dummy entries for the container window
+ aList.Insert( 0xFFFF, 0 );
+ aList.Insert( 0xFFFF, aList.Count() );
+ n = n + 1;
+ if ( pAct )
+ {
+ for ( USHORT i=0; i<SFX_SPLITWINDOWS_MAX; i++ )
+ {
+ // Eventuell ist pAct ein Splitwindow
+ SfxSplitWindow *p = pSplit[i];
+ if ( pAct->pWin == p )
+ {
+ if( p->ActivateNextChild_Impl( bForward ) )
+ return TRUE;
+ break;
+ }
+ }
+
+ // pAct ist ein direktes ChildWindow
+ // mit dem Nachfolger bzw. Vorg"anger des aktiven Fensters weitermachen
+ if ( bForward )
+ n = n+1;
+ else
+ n = n-1;
+
+ if ( n == 0 || n == aList.Count()-1 )
+ return FALSE;
+ }
+
+ for( ;; )
+ {
+ SfxChild_Impl* pCli = (*pChilds)[aList[n]];
+ if ( pCli->pWin )
+ {
+ SfxChild_Impl* pNext = pCli;
+ for ( USHORT i=0; n<SFX_SPLITWINDOWS_MAX; n++ )
+ {
+ // Eventuell ist pNext ein Splitwindow
+ SfxSplitWindow *p = pSplit[i];
+ if ( pNext->pWin == p )
+ {
+ // Das erste/letzte Fenster dort aktivieren
+ p->SetActiveWindow_Impl( NULL );
+ pNext = NULL;
+ if( p->ActivateNextChild_Impl( bForward ) )
+ return TRUE;
+ break;
+ }
+ }
+
+ if ( pNext )
+ {
+ pNext->pWin->GrabFocus();
+ pActiveChild = pNext->pWin;
+ return TRUE;
+ }
+ }
+
+ if ( bForward )
+ n = n+1;
+ else
+ n = n-1;
+
+ if ( n == 0 || n == aList.Count()-1 )
+ break;
+ }
+
+ return FALSE;
+}
+
+void SfxWorkWindow::SetObjectBarCustomizeMode_Impl( BOOL )
+{
+}
+
+void SfxWorkWindow::DataChanged_Impl( const DataChangedEvent& )
+{
+ USHORT n;
+ USHORT nCount = pChildWins->Count();
+ for (n=0; n<nCount; n++)
+ {
+ SfxChildWin_Impl*pCW = (*pChildWins)[n];
+ if ( pCW && pCW->pWin )
+ pCW->pWin->GetWindow()->UpdateSettings( Application::GetSettings() );
+ }
+
+ ArrangeChilds_Impl();
+}
+
diff --git a/sfx2/source/appl/xpackcreator.cxx b/sfx2/source/appl/xpackcreator.cxx
new file mode 100644
index 000000000000..6e6606a67041
--- /dev/null
+++ b/sfx2/source/appl/xpackcreator.cxx
@@ -0,0 +1,202 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/ucb/XCommandEnvironment.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+
+
+#include "xpackcreator.hxx"
+
+#include <sot/stg.hxx>
+#include <sot/storage.hxx>
+#include <tools/stream.hxx>
+#include <unotools/tempfile.hxx>
+#include <unotools/ucbhelper.hxx>
+#include <ucbhelper/content.hxx>
+#include <ucbhelper/commandenvironment.hxx>
+
+using namespace ::com::sun::star;
+
+//-------------------------------------------------------------------------
+uno::Sequence< ::rtl::OUString > SAL_CALL OPackageStructureCreator::impl_getStaticSupportedServiceNames()
+{
+ uno::Sequence< ::rtl::OUString > aRet(2);
+ aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.PackageStructureCreator");
+ aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.PackageStructureCreator");
+ return aRet;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString SAL_CALL OPackageStructureCreator::impl_getStaticImplementationName()
+{
+ return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.PackageStructureCreator");
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< lang::XSingleServiceFactory > SAL_CALL OPackageStructureCreator::impl_createFactory(
+ const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
+{
+ return ::cppu::createOneInstanceFactory( xServiceManager,
+ OPackageStructureCreator::impl_getStaticImplementationName(),
+ OPackageStructureCreator::impl_staticCreateSelfInstance,
+ OPackageStructureCreator::impl_getStaticSupportedServiceNames() );
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OPackageStructureCreator::impl_staticCreateSelfInstance(
+ const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
+{
+ return uno::Reference< uno::XInterface >( *new OPackageStructureCreator( xServiceManager ) );
+}
+
+
+//-------------------------------------------------------------------------
+void SAL_CALL OPackageStructureCreator::convertToPackage( const ::rtl::OUString& aFolderUrl,
+ const uno::Reference< io::XOutputStream >& xTargetStream )
+ throw ( io::IOException,
+ uno::RuntimeException )
+{
+ uno::Reference< ucb::XCommandEnvironment > xComEnv;
+
+ if ( !xTargetStream.is() )
+ throw io::IOException(); // TODO/LATER
+
+ sal_Bool bSuccess = sal_False;
+ ::ucbhelper::Content aContent;
+ if( ::ucbhelper::Content::create( aFolderUrl, xComEnv, aContent ) )
+ {
+ SvStream* pTempStream = NULL;
+
+ ::rtl::OUString aTempURL = ::utl::TempFile().GetURL();
+ try {
+ if ( aContent.isFolder() )
+ {
+ UCBStorage* pUCBStorage = new UCBStorage( aContent,
+ aFolderUrl,
+ STREAM_READ,
+ sal_False,
+ sal_True );
+ SotStorageRef aStorage = new SotStorage( pUCBStorage );
+
+ if ( aTempURL.getLength() )
+ {
+ pTempStream = new SvFileStream( aTempURL, STREAM_STD_READWRITE );
+ SotStorageRef aTargetStorage = new SotStorage( sal_True, *pTempStream );
+ aStorage->CopyTo( aTargetStorage );
+ aTargetStorage->Commit();
+
+ if ( aStorage->GetError() || aTargetStorage->GetError() || pTempStream->GetError() )
+ throw io::IOException();
+
+ aTargetStorage = NULL;
+ aStorage = NULL;
+
+ pTempStream->Seek( 0 );
+
+ uno::Sequence< sal_Int8 > aSeq( 32000 );
+ sal_uInt32 nRead = 0;
+ do {
+ if ( aSeq.getLength() < 32000 )
+ aSeq.realloc( 32000 );
+
+ nRead = pTempStream->Read( aSeq.getArray(), 32000 );
+ if ( nRead < 32000 )
+ aSeq.realloc( nRead );
+ xTargetStream->writeBytes( aSeq );
+ } while( !pTempStream->IsEof() && !pTempStream->GetError() && nRead );
+
+ if ( pTempStream->GetError() )
+ throw io::IOException();
+
+ bSuccess = sal_True;
+ }
+ }
+ }
+ catch ( uno::RuntimeException& )
+ {
+ if ( pTempStream )
+ delete pTempStream;
+
+ if ( aTempURL.getLength() )
+ ::utl::UCBContentHelper::Kill( aTempURL );
+
+ throw;
+ }
+ catch ( io::IOException& )
+ {
+ if ( pTempStream )
+ delete pTempStream;
+
+ if ( aTempURL.getLength() )
+ ::utl::UCBContentHelper::Kill( aTempURL );
+
+ throw;
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ if ( pTempStream )
+ delete pTempStream;
+
+ if ( aTempURL.getLength() )
+ ::utl::UCBContentHelper::Kill( aTempURL );
+ }
+
+ if ( !bSuccess )
+ throw io::IOException(); // TODO/LATER: can't proceed with creation
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString SAL_CALL OPackageStructureCreator::getImplementationName()
+ throw ( uno::RuntimeException )
+{
+ return impl_getStaticImplementationName();
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SAL_CALL OPackageStructureCreator::supportsService( const ::rtl::OUString& ServiceName )
+ throw ( uno::RuntimeException )
+{
+ uno::Sequence< ::rtl::OUString > aSeq = impl_getStaticSupportedServiceNames();
+
+ for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
+ if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
+ return sal_True;
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+uno::Sequence< ::rtl::OUString > SAL_CALL OPackageStructureCreator::getSupportedServiceNames()
+ throw ( uno::RuntimeException )
+{
+ return impl_getStaticSupportedServiceNames();
+}
+
diff --git a/sfx2/source/appl/xpackcreator.hxx b/sfx2/source/appl/xpackcreator.hxx
new file mode 100644
index 000000000000..ff3b84dbec64
--- /dev/null
+++ b/sfx2/source/appl/xpackcreator.hxx
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef __XFACTORY_HXX_
+#define __XFACTORY_HXX_
+
+#include <com/sun/star/embed/XPackageStructureCreator.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+
+#include <cppuhelper/implbase2.hxx>
+
+
+class OPackageStructureCreator : public ::cppu::WeakImplHelper2< ::com::sun::star::embed::XPackageStructureCreator,
+ ::com::sun::star::lang::XServiceInfo >
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
+
+public:
+ OPackageStructureCreator(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory )
+ : m_xFactory( xFactory )
+ {
+ OSL_ENSURE( xFactory.is(), "No service manager is provided!\n" );
+ }
+
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL impl_getStaticSupportedServiceNames();
+
+ static ::rtl::OUString SAL_CALL impl_getStaticImplementationName();
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > SAL_CALL
+ impl_createFactory(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
+ impl_staticCreateSelfInstance(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
+
+ // XPackageStructureCreator
+ virtual void SAL_CALL convertToPackage( const ::rtl::OUString& aFolderUrl, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xTargetStream ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+
+ // XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException);
+ virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException);
+
+};
+
+#endif
+
diff --git a/sfx2/source/bastyp/bastyp.hrc b/sfx2/source/bastyp/bastyp.hrc
new file mode 100644
index 000000000000..b585ac79f035
--- /dev/null
+++ b/sfx2/source/bastyp/bastyp.hrc
@@ -0,0 +1,38 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <sfx2/sfx.hrc>
+
+//fuer das Mapping Fehlercode -> ResId
+
+#define RC_BASTYP RID_SFX_BASTYP_START
+#define STR_FILTER_NOT_INSTALLED (RC_BASTYP + 9)
+#define STR_FILTER_CONSULT_SERVICE (RC_BASTYP + 10)
+#define STR_MEMEXCEPTION (RC_BASTYP + 28)
+#define MSG_MEM_WARN (RC_BASTYP + 29)
+#define STR_HTML_GENERATOR (RC_BASTYP + 30)
+
diff --git a/sfx2/source/bastyp/bastyp.src b/sfx2/source/bastyp/bastyp.src
new file mode 100644
index 000000000000..5ef74f5874b3
--- /dev/null
+++ b/sfx2/source/bastyp/bastyp.src
@@ -0,0 +1,66 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#include "bastyp.hrc"
+
+String STR_HTML_GENERATOR
+{
+ Text = "%PRODUCTNAME %PRODUCTVERSION %PRODUCTEXTENSION (%1)" ;
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/bastyp/bitset.cxx b/sfx2/source/bastyp/bitset.cxx
new file mode 100644
index 000000000000..df35593a9a18
--- /dev/null
+++ b/sfx2/source/bastyp/bitset.cxx
@@ -0,0 +1,395 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <tools/debug.hxx>
+#ifndef GCC
+#endif
+
+#include "bitset.hxx"
+
+#include <string.h> // memset(), memcpy()
+#include <limits.h> // USHRT_MAX
+
+//====================================================================
+// add nOffset to each bit-value in the set
+
+BitSet BitSet::operator<<( USHORT nOffset ) const
+{
+ DBG_MEMTEST();
+ // create a work-copy, return it if nothing to shift
+ BitSet aSet(*this);
+ if ( nOffset == 0 )
+ return aSet;
+
+ // compute the shiftment in long-words and bits
+ USHORT nBlockDiff = nOffset / 32;
+ ULONG nBitValDiff = nOffset % 32;
+
+ // compute the new number of bits
+ for ( USHORT nBlock = 0; nBlock < nBlockDiff; ++nBlock )
+ aSet.nCount = aSet.nCount - CountBits( *(aSet.pBitmap+nBlock) );
+ aSet.nCount = aSet.nCount -
+ CountBits( *(aSet.pBitmap+nBlockDiff) >> (32-nBitValDiff) );
+
+ // shift complete long-words
+ USHORT nTarget, nSource;
+ for ( nTarget = 0, nSource = nBlockDiff;
+ (nSource+1) < aSet.nBlocks;
+ ++nTarget, ++nSource )
+ *(aSet.pBitmap+nTarget) =
+ ( *(aSet.pBitmap+nSource) << nBitValDiff ) |
+ ( *(aSet.pBitmap+nSource+1) >> (32-nBitValDiff) );
+
+ // shift the remainder (if in total minor 32 bits, only this)
+ *(aSet.pBitmap+nTarget) = *(aSet.pBitmap+nSource) << nBitValDiff;
+
+ // determine the last used block
+ while ( *(aSet.pBitmap+nTarget) == 0 )
+ --nTarget;
+
+ // shorten the block-array
+ if ( nTarget < aSet.nBlocks )
+ {
+ ULONG* pNewMap = new ULONG[nTarget];
+ memcpy( pNewMap, aSet.pBitmap, 4 * nTarget );
+ delete [] aSet.pBitmap;
+ aSet.pBitmap = pNewMap;
+ aSet.nBlocks = nTarget;
+ }
+
+ return aSet;
+}
+
+//--------------------------------------------------------------------
+
+// substracts nOffset from each bit-value in the set
+
+BitSet BitSet::operator>>( USHORT ) const
+{
+ DBG_MEMTEST();
+ return BitSet();
+}
+
+//--------------------------------------------------------------------
+
+// internal code for operator= and copy-ctor
+
+void BitSet::CopyFrom( const BitSet& rSet )
+{
+ DBG_MEMTEST();
+ nCount = rSet.nCount;
+ nBlocks = rSet.nBlocks;
+ if ( rSet.nBlocks )
+ {
+ DBG_MEMTEST();
+ pBitmap = new ULONG[nBlocks];
+ memcpy( pBitmap, rSet.pBitmap, 4 * nBlocks );
+ }
+ else
+ pBitmap = 0;
+}
+
+//--------------------------------------------------------------------
+
+// creates an empty bitset
+
+BitSet::BitSet()
+{
+ DBG_MEMTEST();
+ nCount = 0;
+ nBlocks = 0;
+ pBitmap = 0;
+}
+
+//--------------------------------------------------------------------
+
+// creates a copy of bitset rOrig
+
+BitSet::BitSet( const BitSet& rOrig )
+{
+ DBG_MEMTEST();
+ CopyFrom(rOrig);
+}
+
+//--------------------------------------------------------------------
+
+// creates a bitset from an array
+
+BitSet::BitSet( USHORT* pArray, USHORT nSize ):
+ nCount(nSize)
+{
+ DBG_MEMTEST();
+ // find the highest bit to set
+ USHORT nMax = 0;
+ for ( USHORT n = 0; n < nCount; ++n )
+ if ( pArray[n] > nMax )
+ nMax = pArray[n];
+
+ // if there are bits at all
+ if ( nMax > 0 )
+ {
+ // allocate memory for all blocks needed
+ nBlocks = nMax / 32 + 1;
+ pBitmap = new ULONG[nBlocks];
+ memset( pBitmap, 0, 4 * nBlocks );
+
+ // set all the bits
+ for ( USHORT n = 0; n < nCount; ++n )
+ {
+ // compute the block no. and bitvalue
+ USHORT nBlock = n / 32;
+ ULONG nBitVal = 1L << (n % 32);
+
+ // set a single bit
+ if ( ( *(pBitmap+nBlock) & nBitVal ) == 0 )
+ {
+ *(pBitmap+nBlock) |= nBitVal;
+ ++nCount;
+ }
+ }
+ }
+ else
+ {
+ // initalize emtpy set
+ nBlocks = 0;
+ pBitmap = 0;
+ }
+}
+
+//--------------------------------------------------------------------
+
+// frees the storage
+
+BitSet::~BitSet()
+{
+ DBG_MEMTEST();
+ delete [] pBitmap;
+}
+
+//--------------------------------------------------------------------
+
+// creates a bitmap with all bits in rRange set
+
+BitSet::BitSet( const Range& )
+{
+ DBG_MEMTEST();
+}
+
+//--------------------------------------------------------------------
+
+// assignment from another bitset
+
+BitSet& BitSet::operator=( const BitSet& rOrig )
+{
+ DBG_MEMTEST();
+ if ( this != &rOrig )
+ {
+ delete [] pBitmap;
+ CopyFrom(rOrig);
+ }
+ return *this;
+}
+
+//--------------------------------------------------------------------
+
+// assignment from a single bit
+
+BitSet& BitSet::operator=( USHORT nBit )
+{
+ DBG_MEMTEST();
+ delete [] pBitmap;
+
+ nBlocks = nBit / 32;
+ ULONG nBitVal = 1L << (nBit % 32);
+ nCount = 1;
+
+ pBitmap = new ULONG[nBlocks];
+ memset( pBitmap + nBlocks, 0, 4 * nBlocks );
+
+ *(pBitmap+nBlocks) = nBitVal;
+
+ return *this;
+}
+
+//--------------------------------------------------------------------
+
+// creates the asymetric difference with another bitset
+
+BitSet& BitSet::operator-=(USHORT nBit)
+{
+ DBG_MEMTEST();
+ USHORT nBlock = nBit / 32;
+ ULONG nBitVal = 1L << (nBit % 32);
+
+ if ( nBlock >= nBlocks )
+ return *this;
+
+ if ( (*(pBitmap+nBlock) & nBitVal) )
+ {
+ *(pBitmap+nBlock) &= ~nBitVal;
+ --nCount;
+ }
+
+ return *this;
+}
+
+//--------------------------------------------------------------------
+
+// unites with the bits of rSet
+
+BitSet& BitSet::operator|=( const BitSet& rSet )
+{
+ DBG_MEMTEST();
+ USHORT nMax = Min(nBlocks, rSet.nBlocks);
+
+ // expand the bitmap
+ if ( nBlocks < rSet.nBlocks )
+ {
+ ULONG *pNewMap = new ULONG[rSet.nBlocks];
+ memset( pNewMap + nBlocks, 0, 4 * (rSet.nBlocks - nBlocks) );
+
+ if ( pBitmap )
+ {
+ memcpy( pNewMap, pBitmap, 4 * nBlocks );
+ delete [] pBitmap;
+ }
+ pBitmap = pNewMap;
+ nBlocks = rSet.nBlocks;
+ }
+
+ // add the bits blocks by block
+ for ( USHORT nBlock = 0; nBlock < nMax; ++nBlock )
+ {
+ // compute numberof additional bits
+ ULONG nDiff = ~*(pBitmap+nBlock) & *(rSet.pBitmap+nBlock);
+ nCount = nCount + CountBits(nDiff);
+
+ *(pBitmap+nBlock) |= *(rSet.pBitmap+nBlock);
+ }
+
+ return *this;
+}
+
+//--------------------------------------------------------------------
+
+// unites with a single bit
+
+BitSet& BitSet::operator|=( USHORT nBit )
+{
+ DBG_MEMTEST();
+ USHORT nBlock = nBit / 32;
+ ULONG nBitVal = 1L << (nBit % 32);
+
+ if ( nBlock >= nBlocks )
+ {
+ ULONG *pNewMap = new ULONG[nBlock+1];
+ memset( pNewMap + nBlocks, 0, 4 * (nBlock - nBlocks + 1) );
+
+ if ( pBitmap )
+ {
+ memcpy( pNewMap, pBitmap, 4 * nBlocks );
+ delete [] pBitmap;
+ }
+ pBitmap = pNewMap;
+ nBlocks = nBlock+1;
+ }
+
+ if ( (*(pBitmap+nBlock) & nBitVal) == 0 )
+ {
+ *(pBitmap+nBlock) |= nBitVal;
+ ++nCount;
+ }
+
+ return *this;
+}
+
+//--------------------------------------------------------------------
+
+// determines if the bit is set (may be the only one)
+
+BOOL BitSet::Contains( USHORT nBit ) const
+{
+ DBG_MEMTEST();
+ USHORT nBlock = nBit / 32;
+ ULONG nBitVal = 1L << (nBit % 32);
+
+ if ( nBlock >= nBlocks )
+ return FALSE;
+ return ( nBitVal & *(pBitmap+nBlock) ) == nBitVal;
+}
+
+//--------------------------------------------------------------------
+
+// determines if the bitsets are equal
+
+BOOL BitSet::operator==( const BitSet& rSet ) const
+{
+ DBG_MEMTEST();
+ if ( nBlocks != rSet.nBlocks )
+ return FALSE;
+
+ USHORT nBlock = nBlocks;
+ while ( nBlock-- > 0 )
+ if ( *(pBitmap+nBlock) != *(rSet.pBitmap+nBlock) )
+ return FALSE;
+
+ return TRUE;
+}
+
+//--------------------------------------------------------------------
+
+// counts the number of 1-bits in the parameter
+
+USHORT BitSet::CountBits( ULONG nBits )
+{
+ USHORT nCount = 0;
+ int nBit = 32;
+ while ( nBit-- && nBits )
+ { if ( ( (long)nBits ) < 0 )
+ ++nCount;
+ nBits = nBits << 1;
+ }
+ return nCount;
+}
+
+//--------------------------------------------------------------------
+
+USHORT IndexBitSet::GetFreeIndex()
+{
+ for(USHORT i=0;i<USHRT_MAX;i++)
+ if(!Contains(i))
+ {
+ *this|=i;
+ return i;
+ }
+ DBG_ASSERT(FALSE, "IndexBitSet enthaelt mehr als USHRT_MAX Eintraege");
+ return 0;
+}
+
+
diff --git a/sfx2/source/bastyp/fltfnc.cxx b/sfx2/source/bastyp/fltfnc.cxx
new file mode 100644
index 000000000000..12f824ea4255
--- /dev/null
+++ b/sfx2/source/bastyp/fltfnc.cxx
@@ -0,0 +1,1227 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "fltfnc.hxx"
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/container/XEnumeration.hpp>
+#include <com/sun/star/datatransfer/DataFlavor.hpp>
+#include <com/sun/star/document/XTypeDetection.hpp>
+#include <com/sun/star/container/XContainerQuery.hpp>
+
+#include <comphelper/sequenceashashmap.hxx>
+
+#ifndef _EXCHANGE_HXX //autogen
+#include <sot/exchange.hxx>
+#endif
+#include <tools/config.hxx>
+#include <basic/sbmeth.hxx>
+#include <basic/basmgr.hxx>
+#include <basic/sbstar.hxx>
+#include <basic/sbxobj.hxx>
+#include <basic/sbxmeth.hxx>
+#include <basic/sbxcore.hxx>
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#ifndef _RTL_USTRING_HXX //autogen
+#include <rtl/ustring.hxx>
+#endif
+#include <rtl/ustrbuf.hxx>
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/lckbitem.hxx>
+#include <svl/inettype.hxx>
+#include <svl/rectitem.hxx>
+
+#include <sot/storage.hxx>
+#include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XStatusListener.hpp>
+#include <com/sun/star/frame/FrameSearchFlag.hpp>
+#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
+#include <com/sun/star/frame/FeatureStateEvent.hpp>
+#include <com/sun/star/frame/DispatchDescriptor.hpp>
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/frame/XFrameActionListener.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/FrameActionEvent.hpp>
+#include <com/sun/star/frame/FrameAction.hpp>
+#include <com/sun/star/frame/XFrameLoader.hpp>
+#include <com/sun/star/frame/XLoadEventListener.hpp>
+#include <com/sun/star/frame/XFilterDetect.hpp>
+#include <com/sun/star/loader/XImplementationLoader.hpp>
+#include <com/sun/star/loader/CannotActivateFactoryException.hpp>
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+#include <sal/types.h>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/ucb/XContent.hpp>
+#include <rtl/ustring.hxx>
+#include <vos/process.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <comphelper/mediadescriptor.hxx>
+#include <tools/urlobj.hxx>
+
+#include <rtl/logfile.hxx>
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::beans;
+using namespace ::vos;
+#include <svl/ctypeitm.hxx>
+#include <svtools/sfxecode.hxx>
+#include <unotools/syslocale.hxx>
+
+#include "sfx2/sfxhelp.hxx"
+#include "sfxbasic.hxx"
+#include <sfx2/docfilt.hxx>
+#include <sfx2/docfac.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/progress.hxx>
+#include "openflag.hxx"
+#include "bastyp.hrc"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/doctempl.hxx>
+#include <sfx2/frame.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "helper.hxx"
+#include "fltlst.hxx"
+#include <sfx2/request.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/appuno.hxx>
+#include <sfx2/viewfrm.hxx>
+
+static SfxFilterList_Impl* pFilterArr = 0;
+static BOOL bFirstRead = TRUE;
+
+static void CreateFilterArr()
+{
+ pFilterArr = new SfxFilterList_Impl;
+ new SfxFilterListener();
+}
+
+//----------------------------------------------------------------
+inline String ToUpper_Impl( const String &rStr )
+{
+ return SvtSysLocale().GetCharClass().upper( rStr );
+}
+
+//----------------------------------------------------------------
+class SfxFilterContainer_Impl
+{
+public:
+ String aName;
+ String aServiceName;
+
+ SfxFilterContainer_Impl( const String& rName )
+ : aName( rName )
+ {
+ aServiceName = SfxObjectShell::GetServiceNameFromFactory( rName );
+ }
+};
+
+#define IMPL_FORWARD_LOOP( aMethod, ArgType, aArg ) \
+const SfxFilter* SfxFilterContainer::aMethod( ArgType aArg, SfxFilterFlags nMust, SfxFilterFlags nDont ) const \
+{\
+ SfxFilterMatcher aMatch( pImpl->aName ); \
+ return aMatch.aMethod( aArg, nMust, nDont ); \
+}
+
+IMPL_FORWARD_LOOP( GetFilter4Mime, const String&, rMime );
+IMPL_FORWARD_LOOP( GetFilter4ClipBoardId, sal_uInt32, nId );
+IMPL_FORWARD_LOOP( GetFilter4EA, const String&, rEA );
+IMPL_FORWARD_LOOP( GetFilter4Extension, const String&, rExt );
+IMPL_FORWARD_LOOP( GetFilter4FilterName, const String&, rName );
+IMPL_FORWARD_LOOP( GetFilter4UIName, const String&, rName );
+
+const SfxFilter* SfxFilterContainer::GetAnyFilter( SfxFilterFlags nMust, SfxFilterFlags nDont ) const
+{
+ SfxFilterMatcher aMatch( pImpl->aName );
+ return aMatch.GetAnyFilter( nMust, nDont );
+}
+
+//----------------------------------------------------------------
+
+SfxFilterContainer::SfxFilterContainer( const String& rName )
+{
+ pImpl = new SfxFilterContainer_Impl( rName );
+}
+
+//----------------------------------------------------------------
+
+SfxFilterContainer::~SfxFilterContainer()
+{
+}
+
+//----------------------------------------------------------------
+
+const String SfxFilterContainer::GetName() const
+{
+ return pImpl->aName;
+}
+
+const SfxFilter* SfxFilterContainer::GetDefaultFilter_Impl( const String& rName )
+{
+ // Try to find out the type of factory.
+ // Interpret given name as Service- and ShortName!
+ SvtModuleOptions aOpt;
+ SvtModuleOptions::EFactory eFactory = aOpt.ClassifyFactoryByServiceName(rName);
+ if (eFactory == SvtModuleOptions::E_UNKNOWN_FACTORY)
+ eFactory = aOpt.ClassifyFactoryByShortName(rName);
+
+ // could not classify factory by its service nor by its short name.
+ // Must be an unknown factory! => return NULL
+ if (eFactory == SvtModuleOptions::E_UNKNOWN_FACTORY)
+ return NULL;
+
+ // For the following code we need some additional informations.
+ String sServiceName = aOpt.GetFactoryName(eFactory);
+ String sShortName = aOpt.GetFactoryShortName(eFactory);
+ String sDefaultFilter = aOpt.GetFactoryDefaultFilter(eFactory);
+
+ // Try to get the default filter. Dont fiorget to verify it.
+ // May the set default filter does not exists any longer or
+ // does not fit the given factory.
+ const SfxFilterMatcher aMatcher;
+ const SfxFilter* pFilter = aMatcher.GetFilter4FilterName(sDefaultFilter);
+
+ if (
+ (pFilter ) &&
+ (pFilter->GetServiceName().CompareIgnoreCaseToAscii( sServiceName ) != COMPARE_EQUAL)
+ )
+ {
+ pFilter = 0;
+ }
+
+ // If at least no default filter could be located - use any filter of this
+ // factory.
+ if (!pFilter)
+ {
+ if ( bFirstRead )
+ ReadFilters_Impl();
+
+ sal_uInt16 nCount = ( sal_uInt16 ) pFilterArr->Count();
+ for( sal_uInt16 n = 0; n < nCount; n++ )
+ {
+ const SfxFilter* pCheckFilter = pFilterArr->GetObject( n );
+ if ( pCheckFilter->GetServiceName().CompareIgnoreCaseToAscii( sServiceName ) == COMPARE_EQUAL )
+ {
+ pFilter = pCheckFilter;
+ break;
+ }
+ }
+ }
+
+ return pFilter;
+}
+
+
+//----------------------------------------------------------------
+
+class SfxFilterMatcherArr_Impl;
+static SfxFilterMatcherArr_Impl* pImplArr = 0;
+
+// Impl-Data is shared between all FilterMatchers of the same factory
+class SfxFilterMatcher_Impl
+{
+public:
+ ::rtl::OUString aName;
+ SfxFilterList_Impl* pList; // is created on demand
+
+ void InitForIterating() const;
+ void Update();
+ SfxFilterMatcher_Impl()
+ : pList(0)
+ {}
+};
+
+DECL_PTRARRAY( SfxFilterMatcherArr_Impl, SfxFilterMatcher_Impl*, 2, 2 )
+
+SfxFilterMatcher::SfxFilterMatcher( const String& rName )
+ : pImpl( 0 )
+{
+ if ( !pImplArr )
+ // keep track of created filter matchers to recycle the FilterLists
+ pImplArr = new SfxFilterMatcherArr_Impl;
+
+ String aName = SfxObjectShell::GetServiceNameFromFactory( rName );
+ DBG_ASSERT(aName.Len(), "Found boes type :-)");
+ for ( USHORT n=0; n<pImplArr->Count(); n++ )
+ {
+ // find the impl-Data of any comparable FilterMatcher that was created before
+ SfxFilterMatcher_Impl* pImp = pImplArr->GetObject(n);
+ if ( String(pImp->aName) == aName )
+ pImpl = pImp;
+ }
+
+ if ( !pImpl )
+ {
+ // first Matcher created for this factory
+ pImpl = new SfxFilterMatcher_Impl;
+ pImpl->aName = aName;
+ pImplArr->Insert( pImplArr->Count(), pImpl );
+ }
+}
+
+SfxFilterMatcher::SfxFilterMatcher()
+{
+ // global FilterMatcher always uses global filter array (also created on demand)
+ pImpl = new SfxFilterMatcher_Impl;
+}
+
+SfxFilterMatcher::~SfxFilterMatcher()
+{
+ if ( !pImpl->aName.getLength() )
+ // only the global Matcher owns his ImplData
+ delete pImpl;
+}
+
+void SfxFilterMatcher_Impl::Update()
+{
+ if ( pList )
+ {
+ // this List was already used
+ pList->Clear();
+ for ( USHORT n=0; n<pFilterArr->Count(); n++ )
+ {
+ SfxFilter* pFilter = pFilterArr->GetObject(n);
+ if ( pFilter->GetServiceName() == String(aName) )
+ pList->Insert( pFilter, LIST_APPEND );
+ }
+ }
+}
+
+void SfxFilterMatcher_Impl::InitForIterating() const
+{
+ if ( pList )
+ return;
+
+ if ( bFirstRead )
+ // global filter array has not been created yet
+ SfxFilterContainer::ReadFilters_Impl();
+
+ if ( aName.getLength() )
+ {
+ // matcher of factory: use only filters of that document type
+ ((SfxFilterMatcher_Impl*)this)->pList = new SfxFilterList_Impl;
+ ((SfxFilterMatcher_Impl*)this)->Update();
+ }
+ else
+ {
+ // global matcher: use global filter array
+ ((SfxFilterMatcher_Impl*)this)->pList = pFilterArr;
+ }
+}
+
+const SfxFilter* SfxFilterMatcher::GetAnyFilter( SfxFilterFlags nMust, SfxFilterFlags nDont ) const
+{
+ pImpl->InitForIterating();
+ sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count();
+ for( sal_uInt16 n = 0; n < nCount; n++ )
+ {
+ const SfxFilter* pFilter = pImpl->pList->GetObject( n );
+ SfxFilterFlags nFlags = pFilter->GetFilterFlags();
+ if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) )
+ return pFilter;
+ }
+
+ return NULL;
+}
+
+//----------------------------------------------------------------
+
+sal_uInt32 SfxFilterMatcher::GuessFilterIgnoringContent(
+ SfxMedium& rMedium,
+ const SfxFilter**ppFilter,
+ SfxFilterFlags /*nMust*/,
+ SfxFilterFlags /*nDont*/ ) const
+{
+ Reference< XTypeDetection > xDetection( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection")), UNO_QUERY );
+ ::rtl::OUString sTypeName;
+ try
+ {
+ //!MBA: nmust, ndont?
+ sTypeName = xDetection->queryTypeByURL( rMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
+ }
+ catch( Exception& )
+ {
+ }
+
+ *ppFilter = NULL;
+ if ( sTypeName.getLength() )
+ *ppFilter = GetFilter4EA( sTypeName );
+
+ return *ppFilter ? ERRCODE_NONE : ERRCODE_ABORT;
+}
+
+//----------------------------------------------------------------
+
+#define CHECKERROR() \
+if( nErr == 1 || nErr == USHRT_MAX || nErr == ULONG_MAX ) \
+{ \
+ ByteString aText = "Fehler in FilterDetection: Returnwert ";\
+ aText += ByteString::CreateFromInt32(nErr); \
+ if( pFilter ) \
+ { \
+ aText += ' '; \
+ aText += ByteString(U2S(pFilter->GetFilterName())); \
+ } \
+ DBG_ERROR( aText.GetBuffer() ); \
+ nErr = ERRCODE_ABORT; \
+}
+
+//----------------------------------------------------------------
+
+sal_uInt32 SfxFilterMatcher::GuessFilter( SfxMedium& rMedium, const SfxFilter**ppFilter, SfxFilterFlags nMust, SfxFilterFlags nDont ) const
+{
+ return GuessFilterControlDefaultUI( rMedium, ppFilter, nMust, nDont, sal_True );
+}
+
+//----------------------------------------------------------------
+
+sal_uInt32 SfxFilterMatcher::GuessFilterControlDefaultUI( SfxMedium& rMedium, const SfxFilter** ppFilter, SfxFilterFlags nMust, SfxFilterFlags nDont, sal_Bool /*bDefUI*/ ) const
+{
+ const SfxFilter* pOldFilter = *ppFilter;
+
+ // no detection service -> nothing to do !
+ Reference< XTypeDetection > xDetection( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection")), UNO_QUERY );
+ if (!xDetection.is())
+ return ERRCODE_ABORT;
+
+ ::rtl::OUString sTypeName;
+ try
+ {
+ // open the stream one times only ...
+ // Otherwhise it will be tried more then once and show the same interaction more then once ...
+
+ ::rtl::OUString sURL( rMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
+ ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInStream = rMedium.GetInputStream();
+
+ // stream exists => deep detection (with preselection ... if possible)
+ if (xInStream.is())
+ {
+ ::comphelper::MediaDescriptor aDescriptor;
+
+ aDescriptor[::comphelper::MediaDescriptor::PROP_URL() ] <<= sURL;
+ aDescriptor[::comphelper::MediaDescriptor::PROP_INPUTSTREAM() ] <<= xInStream;
+ aDescriptor[::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= rMedium.GetInteractionHandler();
+
+ if ( pImpl->aName.getLength() )
+ aDescriptor[::comphelper::MediaDescriptor::PROP_DOCUMENTSERVICE()] <<= pImpl->aName;
+
+ if ( pOldFilter )
+ {
+ aDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME() ] <<= ::rtl::OUString( pOldFilter->GetTypeName() );
+ aDescriptor[::comphelper::MediaDescriptor::PROP_FILTERNAME()] <<= ::rtl::OUString( pOldFilter->GetFilterName() );
+ }
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lDescriptor = aDescriptor.getAsConstPropertyValueList();
+ sTypeName = xDetection->queryTypeByDescriptor(lDescriptor, sal_True); // lDescriptor is used as In/Out param ... dont use aDescriptor.getAsConstPropertyValueList() directly!
+ }
+ // no stream exists => try flat detection without preselection as fallback
+ else
+ sTypeName = xDetection->queryTypeByURL(sURL);
+
+ if (sTypeName.getLength())
+ {
+ // detect filter by given type
+ // In case of this matcher is bound to a particular document type:
+ // If there is no acceptable type for this document at all, the type detection has possibly returned something else.
+ // The DocumentService property is only a preselection, and all preselections are considered as optional!
+ // This "wrong" type will be sorted out now because we match only allowed filters to the detected type
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > lQuery(1);
+ lQuery[0].Name = ::rtl::OUString::createFromAscii("Name");
+ lQuery[0].Value <<= sTypeName;
+
+ const SfxFilter* pFilter = GetFilterForProps(lQuery, nMust, nDont);
+ if (pFilter)
+ {
+ *ppFilter = pFilter;
+ return ERRCODE_NONE;
+ }
+ }
+ }
+ catch(const Exception&)
+ {}
+
+ return ERRCODE_ABORT;
+}
+
+//----------------------------------------------------------------
+sal_Bool SfxFilterMatcher::IsFilterInstalled_Impl( const SfxFilter* pFilter )
+{
+ if ( pFilter->GetFilterFlags() & SFX_FILTER_MUSTINSTALL )
+ {
+ // Hier k"onnte noch eine Nachinstallation angeboten werden
+ String aText( SfxResId( STR_FILTER_NOT_INSTALLED ) );
+ aText.SearchAndReplaceAscii( "$(FILTER)", pFilter->GetUIName() );
+ QueryBox aQuery( NULL, WB_YES_NO | WB_DEF_YES, aText );
+ short nRet = aQuery.Execute();
+ if ( nRet == RET_YES )
+ {
+#ifdef DBG_UTIL
+ // Setup starten
+ InfoBox( NULL, DEFINE_CONST_UNICODE("Hier soll jetzt das Setup starten!") ).Execute();
+#endif
+ // Installation mu\s hier noch mitteilen, ob es geklappt hat, dann kann das
+ // Filterflag gel"oscht werden
+ }
+
+ return ( !(pFilter->GetFilterFlags() & SFX_FILTER_MUSTINSTALL) );
+ }
+ else if ( pFilter->GetFilterFlags() & SFX_FILTER_CONSULTSERVICE )
+ {
+ String aText( SfxResId( STR_FILTER_CONSULT_SERVICE ) );
+ aText.SearchAndReplaceAscii( "$(FILTER)", pFilter->GetUIName() );
+ InfoBox ( NULL, aText ).Execute();
+ return sal_False;
+ }
+ else
+ return sal_True;
+}
+
+
+sal_uInt32 SfxFilterMatcher::DetectFilter( SfxMedium& rMedium, const SfxFilter**ppFilter, sal_Bool /*bPlugIn*/, sal_Bool bAPI ) const
+/* [Beschreibung]
+
+ Hier wird noch die Filterauswahlbox hochgezogen. Sonst GuessFilter
+ */
+
+{
+ const SfxFilter* pOldFilter = rMedium.GetFilter();
+ if ( pOldFilter )
+ {
+ if( !IsFilterInstalled_Impl( pOldFilter ) )
+ pOldFilter = 0;
+ else
+ {
+ SFX_ITEMSET_ARG( rMedium.GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
+ if ( ( pOldFilter->GetFilterFlags() & SFX_FILTER_PACKED ) && pSalvageItem )
+ // Salvage is always done without packing
+ pOldFilter = 0;
+ }
+ }
+
+ const SfxFilter* pFilter = pOldFilter;
+
+ sal_Bool bPreview = rMedium.IsPreview_Impl();
+ SFX_ITEMSET_ARG(rMedium.GetItemSet(), pReferer, SfxStringItem, SID_REFERER, FALSE);
+ if ( bPreview && rMedium.IsRemote() && ( !pReferer || pReferer->GetValue().CompareToAscii("private:searchfolder:",21 ) != COMPARE_EQUAL ) )
+ return ERRCODE_ABORT;
+
+ ErrCode nErr = GuessFilter( rMedium, &pFilter );
+ if ( nErr == ERRCODE_ABORT )
+ return nErr;
+
+ if ( nErr == ERRCODE_IO_PENDING )
+ {
+ *ppFilter = pFilter;
+ return nErr;
+ }
+
+ if ( !pFilter )
+ {
+ const SfxFilter* pInstallFilter = NULL;
+
+ // Jetzt auch Filter testen, die nicht installiert sind ( ErrCode ist irrelevant )
+ GuessFilter( rMedium, &pInstallFilter, SFX_FILTER_IMPORT, SFX_FILTER_CONSULTSERVICE );
+ if ( pInstallFilter )
+ {
+ if ( IsFilterInstalled_Impl( pInstallFilter ) )
+ // Eventuell wurde der Filter nachinstalliert
+ pFilter = pInstallFilter;
+ }
+ else
+ {
+ // Jetzt auch Filter testen, die erst von Star bezogen werden m"ussen ( ErrCode ist irrelevant )
+ GuessFilter( rMedium, &pInstallFilter, SFX_FILTER_IMPORT, 0 );
+ if ( pInstallFilter )
+ IsFilterInstalled_Impl( pInstallFilter );
+ }
+ }
+
+ sal_Bool bHidden = bPreview;
+ SFX_ITEMSET_ARG( rMedium.GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False);
+ if ( !bHidden && pFlags )
+ {
+ String aFlags( pFlags->GetValue() );
+ aFlags.ToUpperAscii();
+ if( STRING_NOTFOUND != aFlags.Search( 'H' ) )
+ bHidden = sal_True;
+ }
+/*
+ if ( ( !pFilter || nErr == ERRCODE_SFX_CONSULTUSER ) && !bAPI && !bHidden )
+ {
+ if ( !pFilter )
+ pFilter = pOldFilter;
+
+ String aTmpName;
+ if ( pFilter )
+ aTmpName = pFilter->GetUIName();
+
+ SfxFilterMatcher *pMatcher;
+ if( bPlugIn && pFilter )
+ pMatcher = new SfxFilterMatcher( (SfxFilterContainer *) pFilter->GetFilterContainer() );
+ else
+ pMatcher = (SfxFilterMatcher*) this;
+
+ SfxFilterDialog *pDlg = new SfxFilterDialog( 0, &rMedium, *pMatcher, pFilter ? &aTmpName: 0, 0 );
+ const sal_Bool bOk = RET_OK == pDlg->Execute();
+ if (bOk)
+ pFilter = pMatcher->GetFilter4UIName( pDlg->GetSelectEntry());
+
+ if( bPlugIn && pFilter )
+ delete pMatcher;
+ delete pDlg;
+
+ if ( !bOk)
+ nErr = ERRCODE_ABORT;
+ else
+ nErr = ERRCODE_NONE;
+ }
+*/
+ *ppFilter = pFilter;
+
+ if ( bHidden || (bAPI && nErr == ERRCODE_SFX_CONSULTUSER) )
+ nErr = pFilter ? ERRCODE_NONE : ERRCODE_ABORT;
+ return nErr;
+}
+
+const SfxFilter* SfxFilterMatcher::GetFilterForProps( const com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue >& aSeq, SfxFilterFlags nMust, SfxFilterFlags nDont ) const
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
+ ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerQuery > xTypeCFG;
+ if( xServiceManager.is() == sal_True )
+ xTypeCFG = ::com::sun::star::uno::Reference < com::sun::star::container::XContainerQuery >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" ) ), ::com::sun::star::uno::UNO_QUERY );
+ if ( xTypeCFG.is() )
+ {
+ // make query for all types matching the properties
+ ::com::sun::star::uno::Reference < com::sun::star::container::XEnumeration > xEnum = xTypeCFG->createSubSetEnumerationByProperties( aSeq );
+ while ( xEnum->hasMoreElements() )
+ {
+ ::comphelper::SequenceAsHashMap aProps( xEnum->nextElement() );
+ ::rtl::OUString aValue;
+
+ // try to get the preferred filter (works without loading all filters!)
+ if ( (aProps[::rtl::OUString::createFromAscii("PreferredFilter")] >>= aValue) && aValue.getLength() )
+ {
+ const SfxFilter* pFilter = SfxFilter::GetFilterByName( aValue );
+ if ( !pFilter || (pFilter->GetFilterFlags() & nMust) != nMust || (pFilter->GetFilterFlags() & nDont ) )
+ // check for filter flags
+ // pFilter == 0: if preferred filter is a Writer filter, but Writer module is not installed
+ continue;
+
+ if ( pImpl->aName.getLength() )
+ {
+ // if this is not the global FilterMatcher: check if filter matches the document type
+ ::rtl::OUString aService;
+ if ( pFilter->GetServiceName() != String(pImpl->aName) )
+ {
+ // preferred filter belongs to another document type; now we must search the filter
+ pImpl->InitForIterating();
+ aProps[::rtl::OUString::createFromAscii("Name")] >>= aValue;
+ pFilter = GetFilter4EA( aValue, nMust, nDont );
+ if ( pFilter )
+ return pFilter;
+ }
+ else
+ return pFilter;
+ }
+ else
+ return pFilter;
+ }
+ }
+ }
+
+ return 0;
+}
+
+const SfxFilter* SfxFilterMatcher::GetFilter4Mime( const String& rMediaType,SfxFilterFlags nMust, SfxFilterFlags nDont ) const
+{
+ if ( pImpl->pList )
+ {
+ sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count();
+ for( sal_uInt16 n = 0; n < nCount; n++ )
+ {
+ const SfxFilter* pFilter = pImpl->pList->GetObject( n );
+ SfxFilterFlags nFlags = pFilter->GetFilterFlags();
+ if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetMimeType() == rMediaType )
+ return pFilter;
+ }
+
+ return 0;
+ }
+
+ com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1);
+ aSeq[0].Name = ::rtl::OUString::createFromAscii("MediaType");
+ aSeq[0].Value <<= ::rtl::OUString( rMediaType );
+ return GetFilterForProps( aSeq, nMust, nDont );
+}
+
+const SfxFilter* SfxFilterMatcher::GetFilter4EA( const String& rType,SfxFilterFlags nMust, SfxFilterFlags nDont ) const
+{
+ if ( pImpl->pList )
+ {
+ sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count();
+ const SfxFilter* pFirst = 0;
+ for( sal_uInt16 n = 0; n < nCount; n++ )
+ {
+ const SfxFilter* pFilter = pImpl->pList->GetObject( n );
+ SfxFilterFlags nFlags = pFilter->GetFilterFlags();
+ if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetTypeName() == rType )
+ {
+ if (nFlags & SFX_FILTER_PREFERED)
+ return pFilter;
+ if (!pFirst)
+ pFirst = pFilter;
+ }
+ }
+ if (pFirst)
+ return pFirst;
+
+ return 0;
+ }
+
+ com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1);
+ aSeq[0].Name = ::rtl::OUString::createFromAscii("Name");
+ aSeq[0].Value <<= ::rtl::OUString( rType );
+ return GetFilterForProps( aSeq, nMust, nDont );
+}
+
+const SfxFilter* SfxFilterMatcher::GetFilter4Extension( const String& rExt, SfxFilterFlags nMust, SfxFilterFlags nDont ) const
+{
+ if ( pImpl->pList )
+ {
+ sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count();
+ for( sal_uInt16 n = 0; n < nCount; n++ )
+ {
+ const SfxFilter* pFilter = pImpl->pList->GetObject( n );
+ SfxFilterFlags nFlags = pFilter->GetFilterFlags();
+ if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) )
+ {
+ String sWildCard = ToUpper_Impl( pFilter->GetWildcard().GetWildCard() );
+ String sExt = ToUpper_Impl( rExt );
+
+ if (!sExt.Len())
+ continue;
+
+ if (sExt.GetChar(0) != (sal_Unicode)'.')
+ sExt.Insert((sal_Unicode)'.', 0);
+
+ WildCard aCheck(sWildCard, ';');
+ if (aCheck.Matches(sExt))
+ return pFilter;
+ }
+ }
+
+ return 0;
+ }
+
+ // Use extension without dot!
+ String sExt( rExt );
+ if ( sExt.Len() && ( sExt.GetChar(0) == (sal_Unicode)'.' ))
+ sExt.Erase(0,1);
+
+ com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1);
+ aSeq[0].Name = ::rtl::OUString::createFromAscii("Extensions");
+ ::com::sun::star::uno::Sequence < ::rtl::OUString > aExts(1);
+ aExts[0] = sExt;
+ aSeq[0].Value <<= aExts;
+ return GetFilterForProps( aSeq, nMust, nDont );
+}
+
+const SfxFilter* SfxFilterMatcher::GetFilter4ClipBoardId( sal_uInt32 nId, SfxFilterFlags nMust, SfxFilterFlags nDont ) const
+{
+ /*
+ if ( pImpl->pList )
+ {
+ sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count();
+ for( sal_uInt16 n = 0; n < nCount; n++ )
+ {
+ const SfxFilter* pFilter = pImpl->pList->GetObject( n );
+ SfxFilterFlags nFlags = pFilter->GetFilterFlags();
+ if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetFormat() == nId )
+ return pFilter;
+ }
+
+ return 0;
+ }
+ */
+
+ if (nId == 0)
+ return 0;
+
+ com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1);
+ ::rtl::OUString aName = SotExchange::GetFormatName( nId );
+ aSeq[0].Name = ::rtl::OUString::createFromAscii("ClipboardFormat");
+ aSeq[0].Value <<= aName;
+ return GetFilterForProps( aSeq, nMust, nDont );
+}
+
+const SfxFilter* SfxFilterMatcher::GetFilter4UIName( const String& rName, SfxFilterFlags nMust, SfxFilterFlags nDont ) const
+{
+ pImpl->InitForIterating();
+ const SfxFilter* pFirstFilter=0;
+ sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count();
+ for( sal_uInt16 n = 0; n < nCount; n++ )
+ {
+ const SfxFilter* pFilter = pImpl->pList->GetObject( n );
+ SfxFilterFlags nFlags = pFilter->GetFilterFlags();
+ if ( (nFlags & nMust) == nMust &&
+ !(nFlags & nDont ) && pFilter->GetUIName() == rName )
+ {
+ if ( pFilter->GetFilterFlags() & SFX_FILTER_PREFERED )
+ return pFilter;
+ else if ( !pFirstFilter )
+ pFirstFilter = pFilter;
+ }
+ }
+ return pFirstFilter;
+}
+
+const SfxFilter* SfxFilterMatcher::GetFilter4FilterName( const String& rName, SfxFilterFlags nMust, SfxFilterFlags nDont ) const
+{
+ String aName( rName );
+ USHORT nIndex = aName.SearchAscii(": ");
+ if ( nIndex != STRING_NOTFOUND )
+ {
+ DBG_ERROR("Old filter name used!");
+ aName = rName.Copy( nIndex + 2 );
+ }
+
+ if ( bFirstRead )
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
+ ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xFilterCFG ;
+ ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xTypeCFG ;
+ if( xServiceManager.is() == sal_True )
+ {
+ xFilterCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), ::com::sun::star::uno::UNO_QUERY );
+ xTypeCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" ) ), ::com::sun::star::uno::UNO_QUERY );
+ }
+
+ if( xFilterCFG.is() && xTypeCFG.is() )
+ {
+ if ( !pFilterArr )
+ CreateFilterArr();
+ else
+ {
+ for( sal_uInt16 n=0; n<pFilterArr->Count(); n++ )
+ {
+ const SfxFilter* pFilter = pFilterArr->GetObject( n );
+ SfxFilterFlags nFlags = pFilter->GetFilterFlags();
+ if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetFilterName().CompareIgnoreCaseToAscii( aName ) == COMPARE_EQUAL )
+ return pFilter;
+ }
+ }
+
+ SfxFilterContainer::ReadSingleFilter_Impl( rName, xTypeCFG, xFilterCFG, FALSE );
+ }
+ }
+
+ SfxFilterList_Impl* pList = pImpl->pList;
+ if ( !pList )
+ pList = pFilterArr;
+
+ sal_uInt16 nCount = ( sal_uInt16 ) pList->Count();
+ for( sal_uInt16 n = 0; n < nCount; n++ )
+ {
+ const SfxFilter* pFilter = pList->GetObject( n );
+ SfxFilterFlags nFlags = pFilter->GetFilterFlags();
+ if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetFilterName().CompareIgnoreCaseToAscii( aName ) == COMPARE_EQUAL )
+ return pFilter;
+ }
+
+ return NULL;
+}
+
+IMPL_STATIC_LINK( SfxFilterMatcher, MaybeFileHdl_Impl, String*, pString )
+{
+ const SfxFilter* pFilter = pThis->GetFilter4Extension( *pString, SFX_FILTER_IMPORT );
+ if( pFilter && !pFilter->GetWildcard().Matches( String() ) &&
+ pFilter->GetWildcard() != DEFINE_CONST_UNICODE("*.*") && pFilter->GetWildcard() != '*' )
+ return sal_True;
+ return sal_False;
+}
+
+//----------------------------------------------------------------
+
+SfxFilterMatcherIter::SfxFilterMatcherIter(
+ const SfxFilterMatcher* pMatchP,
+ SfxFilterFlags nOrMaskP, SfxFilterFlags nAndMaskP )
+ : nOrMask( nOrMaskP ), nAndMask( nAndMaskP ),
+ nCurrent(0), pMatch( pMatchP->pImpl)
+{
+ if( nOrMask == 0xffff ) //Wg. Fehlbuild auf s
+ nOrMask = 0;
+ pMatch->InitForIterating();
+}
+
+//----------------------------------------------------------------
+
+const SfxFilter* SfxFilterMatcherIter::Find_Impl()
+{
+ const SfxFilter* pFilter = 0;
+ while( nCurrent < pMatch->pList->Count() )
+ {
+ pFilter = pMatch->pList->GetObject(nCurrent++);
+ SfxFilterFlags nFlags = pFilter->GetFilterFlags();
+ if( ((nFlags & nOrMask) == nOrMask ) && !(nFlags & nAndMask ) )
+ break;
+ pFilter = 0;
+ }
+
+ return pFilter;
+}
+
+const SfxFilter* SfxFilterMatcherIter::First()
+{
+ nCurrent = 0;
+ return Find_Impl();
+}
+
+//----------------------------------------------------------------
+
+const SfxFilter* SfxFilterMatcherIter::Next()
+{
+ return Find_Impl();
+}
+
+/*---------------------------------------------------------------
+ helper to build own formated string from given stringlist by
+ using given seperator
+ ---------------------------------------------------------------*/
+::rtl::OUString implc_convertStringlistToString( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& lList ,
+ const sal_Unicode& cSeperator,
+ const ::rtl::OUString& sPrefix )
+{
+ ::rtl::OUStringBuffer sString ( 1000 ) ;
+ sal_Int32 nCount = lList.getLength();
+ sal_Int32 nItem = 0 ;
+ for( nItem=0; nItem<nCount; ++nItem )
+ {
+ if( sPrefix.getLength() > 0 )
+ {
+ sString.append( sPrefix );
+ }
+ sString.append( lList[nItem] );
+ if( nItem+1<nCount )
+ {
+ sString.append( cSeperator );
+ }
+ }
+ return sString.makeStringAndClear();
+}
+
+
+void SfxFilterContainer::ReadSingleFilter_Impl(
+ const ::rtl::OUString& rName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& xTypeCFG,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& xFilterCFG,
+ BOOL bUpdate
+ )
+{
+ ::rtl::OUString sFilterName( rName );
+ SfxFilterList_Impl& rList = *pFilterArr;
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lFilterProperties ;
+ ::com::sun::star::uno::Any aResult;
+ try
+ {
+ aResult = xFilterCFG->getByName( sFilterName );
+ }
+ catch( ::com::sun::star::container::NoSuchElementException& )
+ {
+ aResult = ::com::sun::star::uno::Any();
+ }
+
+ if( aResult >>= lFilterProperties )
+ {
+ // collect informations to add filter to container
+ // (attention: some informations aren't available on filter directly ... you must search for corresponding type too!)
+ sal_Int32 nFlags = 0 ;
+ sal_Int32 nClipboardId = 0 ;
+ sal_Int32 nDocumentIconId = 0 ;
+ sal_Int32 nFormatVersion = 0 ;
+ ::rtl::OUString sMimeType ;
+ ::rtl::OUString sType ;
+ ::rtl::OUString sUIName ;
+ ::rtl::OUString sHumanName ;
+ ::rtl::OUString sDefaultTemplate ;
+ ::rtl::OUString sUserData ;
+ ::rtl::OUString sExtension ;
+ ::rtl::OUString sPattern ;
+ ::rtl::OUString sServiceName ;
+
+ // first get directly available properties
+ sal_Int32 nFilterPropertyCount = lFilterProperties.getLength();
+ sal_Int32 nFilterProperty = 0 ;
+ for( nFilterProperty=0; nFilterProperty<nFilterPropertyCount; ++nFilterProperty )
+ {
+ if( lFilterProperties[nFilterProperty].Name.compareToAscii( "FileFormatVersion" ) == 0 )
+ {
+ lFilterProperties[nFilterProperty].Value >>= nFormatVersion;
+ }
+ else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "TemplateName" ) == 0 )
+ {
+ lFilterProperties[nFilterProperty].Value >>= sDefaultTemplate;
+ }
+ else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "Flags" ) == 0 )
+ {
+ lFilterProperties[nFilterProperty].Value >>= nFlags;
+ }
+ else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "UIName" ) == 0 )
+ {
+ lFilterProperties[nFilterProperty].Value >>= sUIName;
+ }
+ else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "UserData" ) == 0 )
+ {
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > lUserData;
+ lFilterProperties[nFilterProperty].Value >>= lUserData;
+ sUserData = implc_convertStringlistToString( lUserData, ',', ::rtl::OUString() );
+ }
+ else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "DocumentService" ) == 0 )
+ {
+ lFilterProperties[nFilterProperty].Value >>= sServiceName;
+ }
+ else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "Type" ) == 0 )
+ {
+ lFilterProperties[nFilterProperty].Value >>= sType;
+ // Try to get filter .. but look for any exceptions!
+ // May be filter was deleted by another thread ...
+ try
+ {
+ aResult = xTypeCFG->getByName( sType );
+ }
+ catch( ::com::sun::star::container::NoSuchElementException& )
+ {
+ aResult = ::com::sun::star::uno::Any();
+ }
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lTypeProperties;
+ if( aResult >>= lTypeProperties )
+ {
+ // get indirect available properties then (types)
+ sal_Int32 nTypePropertyCount = lTypeProperties.getLength();
+ sal_Int32 nTypeProperty = 0 ;
+ for( nTypeProperty=0; nTypeProperty<nTypePropertyCount; ++nTypeProperty )
+ {
+ if( lTypeProperties[nTypeProperty].Name.compareToAscii( "ClipboardFormat" ) == 0 )
+ {
+ lTypeProperties[nTypeProperty].Value >>= sHumanName;
+ }
+ else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "DocumentIconID" ) == 0 )
+ {
+ lTypeProperties[nTypeProperty].Value >>= nDocumentIconId;
+ }
+ else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "MediaType" ) == 0 )
+ {
+ lTypeProperties[nTypeProperty].Value >>= sMimeType;
+ }
+ else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "Extensions" ) == 0 )
+ {
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > lExtensions;
+ lTypeProperties[nTypeProperty].Value >>= lExtensions;
+ sExtension = implc_convertStringlistToString( lExtensions, ';', DEFINE_CONST_UNICODE("*.") );
+ }
+ else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "URLPattern" ) == 0 )
+ {
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > lPattern;
+ lTypeProperties[nTypeProperty].Value >>= lPattern;
+ sPattern = implc_convertStringlistToString( lPattern, ';', ::rtl::OUString() );
+ }
+ }
+ }
+ }
+ }
+
+ if ( !sServiceName.getLength() )
+ return;
+
+ // old formats are found ... using HumanPresentableName!
+ if( sHumanName.getLength() )
+ {
+ nClipboardId = SotExchange::RegisterFormatName( sHumanName );
+
+ // #100570# For external filters ignore clipboard IDs
+ if((nFlags & SFX_FILTER_STARONEFILTER) == SFX_FILTER_STARONEFILTER)
+ {
+ nClipboardId = 0;
+ }
+ }
+ // register SfxFilter
+ // first erase module name from old filter names!
+ // e.g: "scalc: DIF" => "DIF"
+ sal_Int32 nStartRealName = sFilterName.indexOf( DEFINE_CONST_UNICODE(": "), 0 );
+ if( nStartRealName != -1 )
+ {
+ DBG_ERROR("Old format, not supported!");
+ sFilterName = sFilterName.copy( nStartRealName+2 );
+ }
+
+ SfxFilter* pFilter = bUpdate ? (SfxFilter*) SfxFilter::GetFilterByName( sFilterName ) : 0;
+ BOOL bNew = FALSE;
+ if (!pFilter)
+ {
+ bNew = TRUE;
+ pFilter = new SfxFilter( sFilterName ,
+ sExtension ,
+ nFlags ,
+ nClipboardId ,
+ sType ,
+ (USHORT)nDocumentIconId ,
+ sMimeType ,
+ sUserData ,
+ sServiceName );
+ }
+ else
+ {
+ pFilter->aFilterName = sFilterName;
+ pFilter->aWildCard = WildCard(sExtension, ';');
+ pFilter->nFormatType = nFlags;
+ pFilter->lFormat = nClipboardId;
+ pFilter->aTypeName = sType;
+ pFilter->nDocIcon = (USHORT)nDocumentIconId;
+ pFilter->aMimeType = sMimeType;
+ pFilter->aUserData = sUserData;
+ pFilter->aServiceName = sServiceName;
+ }
+
+ // Don't forget to set right UIName!
+ // Otherwise internal name is used as fallback ...
+ pFilter->SetUIName( sUIName );
+ pFilter->SetDefaultTemplate( sDefaultTemplate );
+ if( nFormatVersion )
+ {
+ pFilter->SetVersion( nFormatVersion );
+ }
+ pFilter->SetURLPattern(sPattern);
+
+ if (bNew)
+ rList.Insert( pFilter, USHRT_MAX );
+ }
+}
+
+void SfxFilterContainer::ReadFilters_Impl( BOOL bUpdate )
+{
+ RTL_LOGFILE_CONTEXT( aMeasure, "sfx2 (as96863) ::SfxFilterContainer::ReadFilters" );
+ if ( !pFilterArr )
+ CreateFilterArr();
+
+ bFirstRead = FALSE;
+ SfxFilterList_Impl& rList = *pFilterArr;
+
+ try
+ {
+ // get the FilterFactory service to access the registered filters ... and types!
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
+ ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xFilterCFG ;
+ ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xTypeCFG ;
+ if( xServiceManager.is() == sal_True )
+ {
+ xFilterCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), ::com::sun::star::uno::UNO_QUERY );
+ xTypeCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" ) ), ::com::sun::star::uno::UNO_QUERY );
+ }
+
+ if(
+ ( xFilterCFG.is() == sal_True ) &&
+ ( xTypeCFG.is() == sal_True )
+ )
+ {
+ // select right query to get right set of filters for search modul
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > lFilterNames = xFilterCFG->getElementNames();
+ if ( lFilterNames.getLength() )
+ {
+ // If list of filters already exist ...
+ // ReadExternalFilters must work in update mode.
+ // Best way seams to mark all filters NOT_INSTALLED
+ // and change it back for all valid filters afterwards.
+ if( rList.Count() > 0 )
+ {
+ bUpdate = TRUE;
+ USHORT nCount = (USHORT)rList.Count();
+ SfxFilter* pFilter;
+ for (USHORT f=0; f<nCount; ++f)
+ {
+ pFilter = NULL;
+ pFilter = rList.GetObject(f);
+ pFilter->nFormatType |= SFX_FILTER_NOTINSTALLED;
+ }
+ }
+
+ // get all properties of filters ... put it into the filter container
+ sal_Int32 nFilterCount = lFilterNames.getLength();
+ sal_Int32 nFilter=0;
+ for( nFilter=0; nFilter<nFilterCount; ++nFilter )
+ {
+ // Try to get filter .. but look for any exceptions!
+ // May be filter was deleted by another thread ...
+ ::rtl::OUString sFilterName = lFilterNames[nFilter];
+
+ // This debug code can be used to break on inserting/updating
+ // special debug filters at runtime.
+ // Otherwise you have to check more then 300 filter names manually .-)
+ // And conditional breakpoints on unicode values seams not to be supported .-(
+ #ifdef DEBUG
+ bool bDBGStop = FALSE;
+ if (sFilterName.indexOf(::rtl::OUString::createFromAscii("DBG_"))>-1)
+ bDBGStop = TRUE;
+ #endif
+
+ ReadSingleFilter_Impl( sFilterName, xTypeCFG, xFilterCFG, bUpdate );
+ }
+ }
+ }
+ }
+ catch( ::com::sun::star::uno::Exception& )
+ {
+ DBG_ASSERT( sal_False, "SfxFilterContainer::ReadFilter()\nException detected. Possible not all filters could be cached.\n" );
+ }
+
+ if ( pImplArr && bUpdate )
+ {
+ // global filter arry was modified, factory specific ones might need an update too
+ for ( USHORT n=0; n<pImplArr->Count(); n++ )
+ pImplArr->GetObject(n)->Update();
+ }
+}
diff --git a/sfx2/source/bastyp/fltfnc.src b/sfx2/source/bastyp/fltfnc.src
new file mode 100644
index 000000000000..4203163eceeb
--- /dev/null
+++ b/sfx2/source/bastyp/fltfnc.src
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+ // include ---------------------------------------------------------------
+#include <sfx2/sfx.hrc>
+#include "bastyp.hrc"
+#include "helpid.hrc"
+String STR_FILTER_NOT_INSTALLED
+{
+ Text [ en-US ] = "The selected filter $(FILTER) has not been installed.\nWould you like to do this now?";
+};
+
+String STR_FILTER_CONSULT_SERVICE
+{
+ Text [ en-US ] = "The selected filter $(FILTER) is not included in your edition.\nYou can find information about orders on our homepage.";
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/bastyp/fltlst.cxx b/sfx2/source/bastyp/fltlst.cxx
new file mode 100644
index 000000000000..aab358b50220
--- /dev/null
+++ b/sfx2/source/bastyp/fltlst.cxx
@@ -0,0 +1,118 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "fltlst.hxx"
+
+//*****************************************************************************************************************
+// includes
+//*****************************************************************************************************************
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/docfac.hxx>
+
+#include <vcl/svapp.hxx>
+#include <vos/mutex.hxx>
+
+//*****************************************************************************************************************
+// namespaces
+//*****************************************************************************************************************
+using namespace ::com::sun::star;
+
+//*****************************************************************************************************************
+// definitions
+//*****************************************************************************************************************
+
+/*-************************************************************************************************************//**
+ @short ctor
+ @descr These initialize an instance of a SfxFilterListener class. Created object listen automaticly
+ on right FilterFactory-Service for all changes and synchronize right SfxFilterContainer with
+ corresponding framework-cache.
+ We use given "sFactory" value to decide which query must be used to fill "pContainer" with new values.
+ Given "pContainer" hold us alive as uno reference and we use it to syschronize it with framework caches.
+ We will die, if he die! see dtor for further informations.
+
+ @seealso dtor
+ @seealso class framework::FilterCache
+ @seealso service ::document::FilterFactory
+
+ @param "sFactory" , short name of module which contains filter container
+ @param "pContainer", pointer to filter container which will be informed
+ @return -
+
+ @onerror We show some assertions in non product version.
+ Otherwise we do nothing!
+ @threadsafe yes
+
+ @last_change 17.10.2001 10:27
+*//*-*************************************************************************************************************/
+SfxFilterListener::SfxFilterListener()
+{
+ uno::Reference< lang::XMultiServiceFactory > xSmgr = ::comphelper::getProcessServiceFactory();
+ if( xSmgr.is() == sal_True )
+ {
+ uno::Reference< util::XRefreshable > xNotifier( xSmgr->createInstance( DEFINE_CONST_OUSTRING("com.sun.star.document.FilterConfigRefresh") ), uno::UNO_QUERY );
+ if( xNotifier.is() == sal_True )
+ {
+ m_xFilterCache = xNotifier;
+ m_xFilterCache->addRefreshListener( this );
+ }
+ }
+}
+
+SfxFilterListener::~SfxFilterListener()
+{
+}
+
+void SAL_CALL SfxFilterListener::refreshed( const lang::EventObject& aSource ) throw( uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ uno::Reference< util::XRefreshable > xContainer( aSource.Source, uno::UNO_QUERY );
+ if(
+ (xContainer.is() ) &&
+ (xContainer==m_xFilterCache)
+ )
+ {
+ SfxFilterContainer::ReadFilters_Impl( TRUE );
+ }
+}
+
+void SAL_CALL SfxFilterListener::disposing( const lang::EventObject& aSource ) throw( uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ uno::Reference< util::XRefreshable > xNotifier( aSource.Source, uno::UNO_QUERY );
+ if (!xNotifier.is())
+ return;
+
+ if (xNotifier == m_xFilterCache)
+ m_xFilterCache.clear();
+}
diff --git a/sfx2/source/bastyp/fltlst.hxx b/sfx2/source/bastyp/fltlst.hxx
new file mode 100644
index 000000000000..b3afb425634d
--- /dev/null
+++ b/sfx2/source/bastyp/fltlst.hxx
@@ -0,0 +1,67 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_FLTLST_HXX
+#define _SFX_FLTLST_HXX
+
+//*****************************************************************************************************************
+// includes
+//*****************************************************************************************************************
+#include <sfx2/fcontnr.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <rtl/ustring.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/util/XRefreshable.hpp>
+#include <com/sun/star/util/XRefreshListener.hpp>
+#include <com/sun/star/document/XEventListener.hpp>
+#include <com/sun/star/lang/EventObject.hpp>
+#include <com/sun/star/uno/RuntimeException.hpp>
+
+//*****************************************************************************************************************
+// declarations
+//*****************************************************************************************************************
+class SfxFilterListener : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XRefreshListener >
+{
+ // member
+ private:
+ ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshable > m_xFilterCache;
+
+ // c++ interface
+ public:
+ SfxFilterListener();
+ ~SfxFilterListener();
+
+ // uno interface
+ public:
+ // XRefreshListener
+ virtual void SAL_CALL refreshed( const ::com::sun::star::lang::EventObject& aSource ) throw( ::com::sun::star::uno::RuntimeException );
+ // XEventListener
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aSource ) throw( ::com::sun::star::uno::RuntimeException );
+
+}; // SfxFilterListener
+
+#endif // _SFX_FLTLST_HXX
diff --git a/sfx2/source/bastyp/frmhtml.cxx b/sfx2/source/bastyp/frmhtml.cxx
new file mode 100644
index 000000000000..8ecfa6b3081a
--- /dev/null
+++ b/sfx2/source/bastyp/frmhtml.cxx
@@ -0,0 +1,163 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <tools/list.hxx>
+#include <tools/table.hxx>
+#include <svtools/htmltokn.h>
+#include <svtools/asynclink.hxx>
+
+#define _SVSTDARR_USHORTS
+#define _SVSTDARR_ULONGS
+#include <svl/svstdarr.hxx>
+
+#include <sfx2/sfx.hrc>
+
+#include <sfx2/frmhtml.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/evntconf.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/fcontnr.hxx>
+#include "sfxtypes.hxx"
+
+#define SFX_HTMLFRMSIZE_REL 0x0001
+#define SFX_HTMLFRMSIZE_PERCENT 0x0002
+
+static sal_Char __READONLY_DATA sHTML_SC_yes[] = "YES";
+static sal_Char __READONLY_DATA sHTML_SC_no[] = "NO";
+static sal_Char __READONLY_DATA sHTML_SC_auto[] = "AUTO";
+
+#define HTML_O_READONLY "READONLY"
+#define HTML_O_EDIT "EDIT"
+
+static HTMLOptionEnum __READONLY_DATA aScollingTable[] =
+{
+ { sHTML_SC_yes, ScrollingYes },
+ { sHTML_SC_no, ScrollingNo },
+ { sHTML_SC_auto, ScrollingAuto },
+ { 0, 0 }
+};
+
+void SfxFrameHTMLParser::ParseFrameOptions( SfxFrameDescriptor *pFrame, const HTMLOptions *pOptions, const String& rBaseURL )
+{
+ // die Optionen holen und setzen
+ Size aMargin( pFrame->GetMargin() );
+
+ // MIB 15.7.97: Netscape scheint marginwidth auf 0 zu setzen, sobald
+ // marginheight gesetzt wird und umgekehrt. Machen wir jetzt wegen
+ // bug #41665# auch so.
+ // Netscape l"a\st aber ein direktes Setzen auf 0 nicht zu, IE4.0 schon.
+ // Den Bug machen wir nicht mit!
+ BOOL bMarginWidth = FALSE, bMarginHeight = FALSE;
+
+ USHORT nArrLen = pOptions->Count();
+ for ( USHORT i=0; i<nArrLen; i++ )
+ {
+ const HTMLOption *pOption = (*pOptions)[i];
+ switch( pOption->GetToken() )
+ {
+ case HTML_O_BORDERCOLOR:
+ {
+ Color aColor;
+ pOption->GetColor( aColor );
+ pFrame->SetWallpaper( Wallpaper( aColor ) );
+ break;
+ }
+ case HTML_O_SRC:
+ pFrame->SetURL(
+ String(
+ INetURLObject::GetAbsURL(
+ rBaseURL, pOption->GetString())) );
+ break;
+ case HTML_O_NAME:
+ pFrame->SetName( pOption->GetString() );
+ break;
+ case HTML_O_MARGINWIDTH:
+ aMargin.Width() = pOption->GetNumber();
+
+// if( aMargin.Width() < 1 )
+// aMargin.Width() = 1;
+ if( !bMarginHeight )
+ aMargin.Height() = 0;
+ bMarginWidth = TRUE;
+ break;
+ case HTML_O_MARGINHEIGHT:
+ aMargin.Height() = pOption->GetNumber();
+
+// if( aMargin.Height() < 1 )
+// aMargin.Height() = 1;
+ if( !bMarginWidth )
+ aMargin.Width() = 0;
+ bMarginHeight = TRUE;
+ break;
+ case HTML_O_SCROLLING:
+ pFrame->SetScrollingMode(
+ (ScrollingMode)pOption->GetEnum( aScollingTable,
+ ScrollingAuto ) );
+ break;
+ case HTML_O_FRAMEBORDER:
+ {
+ String aStr = pOption->GetString();
+ BOOL bBorder = TRUE;
+ if ( aStr.EqualsIgnoreCaseAscii("NO") ||
+ aStr.EqualsIgnoreCaseAscii("0") )
+ bBorder = FALSE;
+ pFrame->SetFrameBorder( bBorder );
+ break;
+ }
+ case HTML_O_NORESIZE:
+ pFrame->SetResizable( FALSE );
+ break;
+ default:
+ if ( pOption->GetTokenString().EqualsIgnoreCaseAscii(
+ HTML_O_READONLY ) )
+ {
+ String aStr = pOption->GetString();
+ BOOL bReadonly = TRUE;
+ if ( aStr.EqualsIgnoreCaseAscii("FALSE") )
+ bReadonly = FALSE;
+ pFrame->SetReadOnly( bReadonly );
+ }
+ else if ( pOption->GetTokenString().EqualsIgnoreCaseAscii(
+ HTML_O_EDIT ) )
+ {
+ String aStr = pOption->GetString();
+ BOOL bEdit = TRUE;
+ if ( aStr.EqualsIgnoreCaseAscii("FALSE") )
+ bEdit = FALSE;
+ pFrame->SetEditable( bEdit );
+ }
+
+ break;
+ }
+ }
+
+ pFrame->SetMargin( aMargin );
+}
diff --git a/sfx2/source/bastyp/frmhtmlw.cxx b/sfx2/source/bastyp/frmhtmlw.cxx
new file mode 100644
index 000000000000..e17151c6e322
--- /dev/null
+++ b/sfx2/source/bastyp/frmhtmlw.cxx
@@ -0,0 +1,381 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef _INETDEF_HXX
+#include <svl/inetdef.hxx>
+#endif
+#include "svtools/htmlkywd.hxx"
+
+//!(dv) #include <chaos2/cntapi.hxx>
+#include <rtl/tencinfo.h>
+
+#include <unotools/configmgr.hxx>
+#include "svl/urihelper.hxx"
+#include <tools/datetime.hxx>
+
+#include <sfx2/frmhtmlw.hxx>
+#include <sfx2/evntconf.hxx>
+#include <sfx2/frame.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/docfile.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/objsh.hxx>
+#include <sfx2/sfx.hrc>
+#include "bastyp.hrc"
+
+#include <comphelper/string.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include <com/sun/star/script/XTypeConverter.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+
+
+// -----------------------------------------------------------------------
+
+using namespace ::com::sun::star;
+
+static sal_Char __READONLY_DATA sHTML_SC_yes[] = "YES";
+static sal_Char __READONLY_DATA sHTML_SC_no[] = "NO";
+static sal_Char __READONLY_DATA sHTML_SC_auto[] = "AUTO";
+static sal_Char __READONLY_DATA sHTML_MIME_text_html[] = "text/html; charset=";
+
+/* not used anymore?
+static HTMLOutEvent __FAR_DATA aFrameSetEventTable[] =
+{
+ { sHTML_O_SDonload, sHTML_O_onload, SFX_EVENT_OPENDOC },
+ { sHTML_O_SDonunload, sHTML_O_onunload, SFX_EVENT_PREPARECLOSEDOC },
+ { sHTML_O_SDonfocus, sHTML_O_onfocus, SFX_EVENT_ACTIVATEDOC },
+ { sHTML_O_SDonblur, sHTML_O_onblur, SFX_EVENT_DEACTIVATEDOC },
+ { 0, 0, 0 }
+};
+*/
+
+#if defined(UNX)
+const sal_Char SfxFrameHTMLWriter::sNewLine[] = "\012";
+#else
+const sal_Char __FAR_DATA SfxFrameHTMLWriter::sNewLine[] = "\015\012";
+#endif
+
+void SfxFrameHTMLWriter::OutMeta( SvStream& rStrm,
+ const sal_Char *pIndent,
+ const String& rName,
+ const String& rContent, BOOL bHTTPEquiv,
+ rtl_TextEncoding eDestEnc,
+ String *pNonConvertableChars )
+{
+ rStrm << sNewLine;
+ if( pIndent )
+ rStrm << pIndent;
+
+ ByteString sOut( '<' );
+ (((sOut += OOO_STRING_SVTOOLS_HTML_meta) += ' ')
+ += (bHTTPEquiv ? OOO_STRING_SVTOOLS_HTML_O_httpequiv : OOO_STRING_SVTOOLS_HTML_O_name)) += "=\"";
+ rStrm << sOut.GetBuffer();
+
+ HTMLOutFuncs::Out_String( rStrm, rName, eDestEnc, pNonConvertableChars );
+
+ ((sOut = "\" ") += OOO_STRING_SVTOOLS_HTML_O_content) += "=\"";
+ rStrm << sOut.GetBuffer();
+
+ HTMLOutFuncs::Out_String( rStrm, rContent, eDestEnc, pNonConvertableChars ) << "\">";
+}
+
+void SfxFrameHTMLWriter::Out_DocInfo( SvStream& rStrm, const String& rBaseURL,
+ const uno::Reference<document::XDocumentProperties> & i_xDocProps,
+ const sal_Char *pIndent,
+ rtl_TextEncoding eDestEnc,
+ String *pNonConvertableChars )
+{
+ const sal_Char *pCharSet =
+ rtl_getBestMimeCharsetFromTextEncoding( eDestEnc );
+
+ if( pCharSet )
+ {
+ String aContentType = String::CreateFromAscii( sHTML_MIME_text_html );
+ aContentType.AppendAscii( pCharSet );
+ OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_content_type, aContentType, TRUE,
+ eDestEnc, pNonConvertableChars );
+ }
+
+ // Titel (auch wenn er leer ist)
+ rStrm << sNewLine;
+ if( pIndent )
+ rStrm << pIndent;
+ HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title );
+ if( i_xDocProps.is() )
+ {
+ const String& rTitle = i_xDocProps->getTitle();
+ if( rTitle.Len() )
+ HTMLOutFuncs::Out_String( rStrm, rTitle, eDestEnc, pNonConvertableChars );
+ }
+ HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title, FALSE );
+
+ // Target-Frame
+ if( i_xDocProps.is() )
+ {
+ const String& rTarget = i_xDocProps->getDefaultTarget();
+ if( rTarget.Len() )
+ {
+ rStrm << sNewLine;
+ if( pIndent )
+ rStrm << pIndent;
+
+ ByteString sOut( '<' );
+ (((sOut += OOO_STRING_SVTOOLS_HTML_base) += ' ') += OOO_STRING_SVTOOLS_HTML_O_target) += "=\"";
+ rStrm << sOut.GetBuffer();
+ HTMLOutFuncs::Out_String( rStrm, rTarget, eDestEnc, pNonConvertableChars )
+ << "\">";
+ }
+ }
+
+ // Who we are
+ String sGenerator( SfxResId( STR_HTML_GENERATOR ) );
+ sGenerator.SearchAndReplaceAscii( "%1", String( DEFINE_CONST_UNICODE( TOOLS_INETDEF_OS ) ) );
+ OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_generator, sGenerator, FALSE, eDestEnc, pNonConvertableChars );
+
+ if( i_xDocProps.is() )
+ {
+ // Reload
+ if( (i_xDocProps->getAutoloadSecs() != 0) ||
+ !i_xDocProps->getAutoloadURL().equalsAscii("") )
+ {
+ String sContent = String::CreateFromInt32(
+ i_xDocProps->getAutoloadSecs() );
+
+ const String &rReloadURL = i_xDocProps->getAutoloadURL();
+ if( rReloadURL.Len() )
+ {
+ sContent.AppendAscii( ";URL=" );
+ sContent += String(
+ URIHelper::simpleNormalizedMakeRelative(
+ rBaseURL, rReloadURL));
+ }
+
+ OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_refresh, sContent, TRUE,
+ eDestEnc, pNonConvertableChars );
+ }
+
+ // Author
+ const String& rAuthor = i_xDocProps->getAuthor();
+ if( rAuthor.Len() )
+ OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_author, rAuthor, FALSE,
+ eDestEnc, pNonConvertableChars );
+
+ // created
+ ::util::DateTime uDT = i_xDocProps->getCreationDate();
+ Date aD(uDT.Day, uDT.Month, uDT.Year);
+ Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
+ String sOut = String::CreateFromInt32(aD.GetDate());
+ sOut += ';';
+ sOut += String::CreateFromInt32(aT.GetTime());
+ OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_created, sOut, FALSE,
+ eDestEnc, pNonConvertableChars );
+
+ // changedby
+ const String& rChangedBy = i_xDocProps->getModifiedBy();
+ if( rChangedBy.Len() )
+ OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changedby, rChangedBy, FALSE,
+ eDestEnc, pNonConvertableChars );
+
+ // changed
+ uDT = i_xDocProps->getModificationDate();
+ Date aD2(uDT.Day, uDT.Month, uDT.Year);
+ Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
+ sOut = String::CreateFromInt32(aD2.GetDate());
+ sOut += ';';
+ sOut += String::CreateFromInt32(aT2.GetTime());
+ OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changed, sOut, FALSE,
+ eDestEnc, pNonConvertableChars );
+
+ // Subject
+ const String& rTheme = i_xDocProps->getSubject();
+ if( rTheme.Len() )
+ OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_classification, rTheme, FALSE,
+ eDestEnc, pNonConvertableChars );
+
+ // Description
+ const String& rComment = i_xDocProps->getDescription();
+ if( rComment.Len() )
+ OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_description, rComment, FALSE,
+ eDestEnc, pNonConvertableChars);
+
+ // Keywords
+ String Keywords = ::comphelper::string::convertCommaSeparated(
+ i_xDocProps->getKeywords());
+ if( Keywords.Len() )
+ OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_keywords, Keywords, FALSE,
+ eDestEnc, pNonConvertableChars);
+
+ uno::Reference < script::XTypeConverter > xConverter(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii("com.sun.star.script.Converter")),
+ uno::UNO_QUERY_THROW );
+ uno::Reference<beans::XPropertySet> xUserDefinedProps(
+ i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+ DBG_ASSERT(xUserDefinedProps.is(), "UserDefinedProperties is null");
+ uno::Reference<beans::XPropertySetInfo> xPropInfo =
+ xUserDefinedProps->getPropertySetInfo();
+ DBG_ASSERT(xPropInfo.is(), "UserDefinedProperties Info is null");
+ uno::Sequence<beans::Property> props = xPropInfo->getProperties();
+ for (sal_Int32 i = 0; i < props.getLength(); ++i) {
+ try {
+ ::rtl::OUString name = props[i].Name;
+ ::rtl::OUString str;
+ uno::Any aStr = xConverter->convertToSimpleType(
+ xUserDefinedProps->getPropertyValue(name),
+ uno::TypeClass_STRING);
+ aStr >>= str;
+ String valstr(str);
+ valstr.EraseTrailingChars();
+ OutMeta( rStrm, pIndent, name, valstr, FALSE,
+ eDestEnc, pNonConvertableChars );
+ } catch (uno::Exception &) {
+ // may happen with concurrent modification...
+ DBG_WARNING("SfxFrameHTMLWriter::Out_DocInfo: exception");
+ }
+ }
+ }
+}
+/*
+void SfxFrameHTMLWriter::OutHeader( rtl_TextEncoding eDestEnc )
+{
+ // <HTML>
+ // <HEAD>
+ // <TITLE>Titel</TITLE>
+ // </HEAD>
+ HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_html ) << sNewLine;
+ HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_head );
+
+ Out_DocInfo( Strm(), &pDoc->GetDocInfo(), "\t", eDestEnc );
+ Strm() << sNewLine;
+ HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_head, FALSE ) << sNewLine;
+
+//! OutScript(); // Hier fehlen noch die Scripten im Header
+}
+*/
+
+void SfxFrameHTMLWriter::Out_FrameDescriptor(
+ SvStream& rOut, const String& rBaseURL, const uno::Reference < beans::XPropertySet >& xSet,
+ rtl_TextEncoding eDestEnc, String *pNonConvertableChars )
+{
+ try
+ {
+ ByteString sOut;
+ ::rtl::OUString aStr;
+ uno::Any aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameURL") );
+ if ( (aAny >>= aStr) && aStr.getLength() )
+ {
+ String aURL = INetURLObject( aStr ).GetMainURL( INetURLObject::DECODE_TO_IURI );
+ if( aURL.Len() )
+ {
+ aURL = URIHelper::simpleNormalizedMakeRelative(
+ rBaseURL, aURL );
+ ((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_src) += "=\"";
+ rOut << sOut.GetBuffer();
+ HTMLOutFuncs::Out_String( rOut, aURL, eDestEnc, pNonConvertableChars );
+ sOut = '\"';
+ }
+ }
+
+ aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameName") );
+ if ( (aAny >>= aStr) && aStr.getLength() )
+ {
+ ((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_name) += "=\"";
+ rOut << sOut.GetBuffer();
+ HTMLOutFuncs::Out_String( rOut, aStr, eDestEnc, pNonConvertableChars );
+ sOut = '\"';
+ }
+
+ sal_Int32 nVal = SIZE_NOT_SET;
+ aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginWidth") );
+ if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
+ (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_marginwidth) += '=') += ByteString::CreateFromInt32( nVal );
+ aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginHeight") );
+ if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
+ (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_marginheight) += '=') += ByteString::CreateFromInt32( nVal );
+
+ sal_Bool bVal = sal_True;
+ aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoScroll") );
+ if ( (aAny >>= bVal) && !bVal )
+ {
+ aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsScrollingMode") );
+ if ( aAny >>= bVal )
+ {
+ const sal_Char *pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
+ (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_scrolling) += '=') += pStr;
+ }
+ }
+
+ // frame border (MS+Netscape-Erweiterung)
+ aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoBorder") );
+ if ( (aAny >>= bVal) && !bVal )
+ {
+ aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsBorder") );
+ if ( aAny >>= bVal )
+ {
+ const char* pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
+ (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_frameborder) += '=') += pStr;
+ }
+ }
+
+ // TODO/LATER: currently not supported attributes
+ // resize
+ //if( !pFrame->IsResizable() )
+ // (sOut += ' ') += sHTML_O_noresize;
+ //
+ //if ( pFrame->GetWallpaper() )
+ //{
+ // ((sOut += ' ') += sHTML_O_bordercolor) += '=';
+ // rOut << sOut.GetBuffer();
+ // HTMLOutFuncs::Out_Color( rOut, pFrame->GetWallpaper()->GetColor(), eDestEnc );
+ //}
+ //else
+ rOut << sOut.GetBuffer();
+ }
+ catch ( uno::Exception& )
+ {
+ }
+}
+
+String SfxFrameHTMLWriter::CreateURL( SfxFrame* pFrame )
+{
+ String aRet;
+ SfxObjectShell* pShell = pFrame->GetCurrentDocument();
+ if( !aRet.Len() && pShell )
+ {
+ aRet = pShell->GetMedium()->GetName();
+//!(dv) CntAnchor::ToPresentationURL( aRet );
+ }
+
+ return aRet;
+}
+
+
diff --git a/sfx2/source/bastyp/helper.cxx b/sfx2/source/bastyp/helper.cxx
new file mode 100644
index 000000000000..091651fedbc2
--- /dev/null
+++ b/sfx2/source/bastyp/helper.cxx
@@ -0,0 +1,879 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "helper.hxx"
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/ucb/CommandAbortedException.hpp>
+#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
+#include <com/sun/star/ucb/NameClash.hpp>
+#include <com/sun/star/ucb/NumberedSortingInfo.hpp>
+#include <com/sun/star/ucb/TransferInfo.hpp>
+#include <com/sun/star/ucb/XAnyCompareFactory.hpp>
+#include <com/sun/star/ucb/XCommandInfo.hpp>
+#include <com/sun/star/ucb/XContentAccess.hpp>
+#include <com/sun/star/ucb/XDynamicResultSet.hpp>
+#include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
+#include <com/sun/star/util/DateTime.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <unotools/localedatawrapper.hxx>
+#include <rtl/strbuf.hxx>
+
+#include <tools/ref.hxx>
+#include <tools/debug.hxx>
+#include <tools/urlobj.hxx>
+#include <tools/datetime.hxx>
+#include <vcl/svapp.hxx>
+#include <ucbhelper/content.hxx>
+#include <ucbhelper/commandenvironment.hxx>
+#include <comphelper/processfactory.hxx>
+#include <osl/file.hxx>
+
+using namespace com::sun::star;
+using namespace rtl;
+using namespace comphelper;
+using namespace osl;
+
+DECLARE_LIST( StringList_Impl, OUString* )
+
+#define CONVERT_DATETIME( aUnoDT, aToolsDT ) \
+ aToolsDT = DateTime( Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year ), \
+ Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds ) );
+
+void AppendDateTime_Impl( const util::DateTime rDT,
+ String& rRow, const LocaleDataWrapper& rWrapper )
+{
+ DateTime aDT;
+ CONVERT_DATETIME( rDT, aDT );
+ String aDateStr = rWrapper.getDate( aDT );
+ aDateStr += String::CreateFromAscii( ", " );
+ aDateStr += rWrapper.getTime( aDT );
+ rRow += aDateStr;
+}
+
+// SfxContentHelper ------------------------------------------------------
+
+sal_Bool SfxContentHelper::Transfer_Impl( const String& rSource, const String& rDest, sal_Bool bMoveData, sal_Int32 nNameClash )
+{
+ sal_Bool bRet = sal_True, bKillSource = sal_False;
+ INetURLObject aSourceObj( rSource );
+ DBG_ASSERT( aSourceObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+
+ INetURLObject aDestObj( rDest );
+ DBG_ASSERT( aDestObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ if ( bMoveData && aSourceObj.GetProtocol() != aDestObj.GetProtocol() )
+ {
+ bMoveData = sal_False;
+ bKillSource = sal_True;
+ }
+ String aName = aDestObj.getName();
+ aDestObj.removeSegment();
+ aDestObj.setFinalSlash();
+
+ try
+ {
+ ::ucbhelper::Content aDestPath( aDestObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
+ uno::Reference< ucb::XCommandInfo > xInfo = aDestPath.getCommands();
+ OUString aTransferName = OUString::createFromAscii( "transfer" );
+ if ( xInfo->hasCommandByName( aTransferName ) )
+ {
+ aDestPath.executeCommand( aTransferName, uno::makeAny(
+ ucb::TransferInfo( bMoveData, aSourceObj.GetMainURL( INetURLObject::NO_DECODE ), aName, nNameClash ) ) );
+ }
+ else
+ {
+ DBG_ERRORFILE( "transfer command not available" );
+ }
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ bRet = sal_False;
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "Any other exception" );
+ bRet = sal_False;
+ }
+
+ if ( bKillSource )
+ SfxContentHelper::Kill( rSource );
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxContentHelper::IsDocument( const String& rContent )
+{
+ sal_Bool bRet = sal_False;
+ INetURLObject aObj( rContent );
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+
+ try
+ {
+ ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
+ bRet = aCnt.isDocument();
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_WARNING( "CommandAbortedException" );
+ }
+ catch( ucb::IllegalIdentifierException& )
+ {
+ DBG_WARNING( "IllegalIdentifierException" );
+ }
+ catch( ucb::ContentCreationException& )
+ {
+ DBG_WARNING( "IllegalIdentifierException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "Any other exception" );
+ }
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxContentHelper::IsFolder( const String& rContent )
+{
+ sal_Bool bRet = sal_False;
+ INetURLObject aObj( rContent );
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ try
+ {
+ ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
+ bRet = aCnt.isFolder();
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_WARNING( "CommandAbortedException" );
+ }
+ catch( ucb::IllegalIdentifierException& )
+ {
+ DBG_WARNING( "IllegalIdentifierException" );
+ }
+ catch( ucb::ContentCreationException& )
+ {
+ DBG_WARNING( "IllegalIdentifierException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "Any other exception" );
+ }
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxContentHelper::GetTitle( const String& rContent, String& rTitle )
+{
+ sal_Bool bRet = sal_False;
+ INetURLObject aObj( rContent );
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ try
+ {
+ ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
+ OUString aTemp;
+ aCnt.getPropertyValue( OUString::createFromAscii( "Title" ) ) >>= aTemp;
+ rTitle = String( aTemp );
+ bRet = sal_True;
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_ERRORFILE( "CommandAbortedException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "Any other exception" );
+ }
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxContentHelper::Kill( const String& rContent )
+{
+ sal_Bool bRet = sal_True;
+ INetURLObject aDeleteObj( rContent );
+ DBG_ASSERT( aDeleteObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+
+ try
+ {
+ ::ucbhelper::Content aCnt( aDeleteObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
+ aCnt.executeCommand( OUString::createFromAscii( "delete" ), uno::makeAny( sal_Bool( sal_True ) ) );
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_WARNING( "CommandAbortedException" );
+ bRet = sal_False;
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "Any other exception" );
+ bRet = sal_False;
+ }
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+uno::Sequence < OUString > SfxContentHelper::GetFolderContents( const String& rFolder, sal_Bool bFolder, sal_Bool bSorted )
+{
+ StringList_Impl* pFiles = NULL;
+ INetURLObject aFolderObj( rFolder );
+ DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ try
+ {
+ ::ucbhelper::Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
+ uno::Reference< sdbc::XResultSet > xResultSet;
+ uno::Sequence< OUString > aProps(2);
+ OUString* pProps = aProps.getArray();
+ pProps[0] = OUString::createFromAscii( "Title" );
+ pProps[1] = OUString::createFromAscii( "IsFolder" );
+
+ try
+ {
+ ::ucbhelper::ResultSetInclude eInclude = bFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY;
+ if ( !bSorted )
+ {
+ xResultSet = aCnt.createCursor( aProps, eInclude );
+ }
+ else
+ {
+ uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
+ xDynResultSet = aCnt.createDynamicCursor( aProps, eInclude );
+
+ uno::Reference < ucb::XAnyCompareFactory > xFactory;
+ uno::Reference < lang::XMultiServiceFactory > xMgr = getProcessServiceFactory();
+ uno::Reference < ucb::XSortedDynamicResultSetFactory > xSRSFac(
+ xMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.ucb.SortedDynamicResultSetFactory") ), uno::UNO_QUERY );
+
+ uno::Sequence< ucb::NumberedSortingInfo > aSortInfo( 2 );
+ ucb::NumberedSortingInfo* pInfo = aSortInfo.getArray();
+ pInfo[ 0 ].ColumnIndex = 2;
+ pInfo[ 0 ].Ascending = sal_False;
+ pInfo[ 1 ].ColumnIndex = 1;
+ pInfo[ 1 ].Ascending = sal_True;
+
+ uno::Reference< ucb::XDynamicResultSet > xDynamicResultSet;
+ xDynamicResultSet =
+ xSRSFac->createSortedDynamicResultSet( xDynResultSet, aSortInfo, xFactory );
+ if ( xDynamicResultSet.is() )
+ {
+ xResultSet = xDynamicResultSet->getStaticResultSet();
+ }
+ }
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_ERRORFILE( "createCursor: CommandAbortedException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "createCursor: Any other exception" );
+ }
+
+ if ( xResultSet.is() )
+ {
+ pFiles = new StringList_Impl;
+ uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
+ try
+ {
+ while ( xResultSet->next() )
+ {
+ OUString aId = xContentAccess->queryContentIdentifierString();
+ OUString* pFile = new OUString( aId );
+ pFiles->Insert( pFile, LIST_APPEND );
+ }
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "XContentAccess::next(): Any other exception" );
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "GetFolderContents: Any other exception" );
+ }
+
+ if ( pFiles )
+ {
+ ULONG nCount = pFiles->Count();
+ uno::Sequence < OUString > aRet( nCount );
+ OUString* pRet = aRet.getArray();
+ for ( ULONG i = 0; i < nCount; ++i )
+ {
+ OUString* pFile = pFiles->GetObject(i);
+ pRet[i] = *( pFile );
+ delete pFile;
+ }
+ delete pFiles;
+ return aRet;
+ }
+ else
+ return uno::Sequence < OUString > ();
+}
+
+// -----------------------------------------------------------------------
+
+uno::Sequence < OUString > SfxContentHelper::GetFolderContentProperties( const String& rFolder, sal_Bool bIsFolder )
+{
+ StringList_Impl* pProperties = NULL;
+ INetURLObject aFolderObj( rFolder );
+ DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
+ uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
+ xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY );
+
+ ::ucbhelper::Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
+ uno::Reference< sdbc::XResultSet > xResultSet;
+ uno::Sequence< OUString > aProps(5);
+ OUString* pProps = aProps.getArray();
+ pProps[0] = OUString::createFromAscii( "Title" );
+ pProps[1] = OUString::createFromAscii( "ContentType" );
+ pProps[2] = OUString::createFromAscii( "Size" );
+ pProps[3] = OUString::createFromAscii( "DateModified" );
+ pProps[4] = OUString::createFromAscii( "IsFolder" );
+
+ try
+ {
+ uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
+ ::ucbhelper::ResultSetInclude eInclude = bIsFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY;
+ xDynResultSet = aCnt.createDynamicCursor( aProps, eInclude );
+
+ uno::Reference < ucb::XAnyCompareFactory > xCmpFactory;
+ uno::Reference < lang::XMultiServiceFactory > xMgr = getProcessServiceFactory();
+ uno::Reference < ucb::XSortedDynamicResultSetFactory > xSRSFac(
+ xMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.ucb.SortedDynamicResultSetFactory") ), uno::UNO_QUERY );
+
+ uno::Sequence< ucb::NumberedSortingInfo > aSortInfo( 2 );
+ ucb::NumberedSortingInfo* pInfo = aSortInfo.getArray();
+ pInfo[ 0 ].ColumnIndex = 5;
+ pInfo[ 0 ].Ascending = sal_False;
+ pInfo[ 1 ].ColumnIndex = 1;
+ pInfo[ 1 ].Ascending = sal_True;
+
+ uno::Reference< ucb::XDynamicResultSet > xDynamicResultSet;
+ xDynamicResultSet =
+ xSRSFac->createSortedDynamicResultSet( xDynResultSet, aSortInfo, xCmpFactory );
+ if ( xDynamicResultSet.is() )
+ {
+ xResultSet = xDynamicResultSet->getStaticResultSet();
+ }
+
+// if ( xDynResultSet.is() )
+// xResultSet = xDynResultSet->getStaticResultSet();
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_ERRORFILE( "createCursor: CommandAbortedException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "createCursor: Any other exception" );
+ }
+
+ if ( xResultSet.is() )
+ {
+ LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ pProperties = new StringList_Impl;
+ uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
+ uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
+ ULONG nFolderPos = LIST_APPEND;
+
+ try
+ {
+ while ( xResultSet->next() )
+ {
+ String aTitle( xRow->getString(1) );
+ String aType( xRow->getString(2) );
+ sal_Int64 nSize = xRow->getLong(3);
+ util::DateTime aDT = xRow->getTimestamp(4);
+ sal_Bool bFolder = xRow->getBoolean(5);
+
+ String aRow = aTitle;
+ aRow += '\t';
+//! aRow += aType;
+//! aRow += '\t';
+ aRow += String::CreateFromInt64( nSize );
+ aRow += '\t';
+ AppendDateTime_Impl( aDT, aRow, aLocaleWrapper );
+ aRow += '\t';
+ aRow += String( xContentAccess->queryContentIdentifierString() );
+ aRow += '\t';
+ aRow += bFolder ? '1' : '0';
+ OUString* pRow = new OUString( aRow );
+ ULONG nPos = LIST_APPEND;
+ if ( bFolder )
+ {
+ if ( LIST_APPEND == nFolderPos )
+ nFolderPos = 0;
+ else
+ nFolderPos++;
+ nPos = nFolderPos;
+ }
+ pProperties->Insert( pRow, nPos );
+ }
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "XContentAccess::next(): Any other exception" );
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "GetFolderContents: Any other exception" );
+ }
+
+ if ( pProperties )
+ {
+ ULONG nCount = pProperties->Count();
+ uno::Sequence < OUString > aRet( nCount );
+ OUString* pRet = aRet.getArray();
+ for ( ULONG i = 0; i < nCount; ++i )
+ {
+ OUString* pProperty = pProperties->GetObject(i);
+ pRet[i] = *( pProperty );
+ delete pProperty;
+ }
+ delete pProperties;
+ return aRet;
+ }
+ else
+ return uno::Sequence < OUString > ();
+}
+
+// -----------------------------------------------------------------------
+
+uno::Sequence < OUString > SfxContentHelper::GetResultSet( const String& rURL )
+{
+ StringList_Impl* pList = NULL;
+ try
+ {
+ ::ucbhelper::Content aCnt( rURL, uno::Reference< ucb::XCommandEnvironment >() );
+ uno::Reference< sdbc::XResultSet > xResultSet;
+ uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
+ uno::Sequence< OUString > aProps(3);
+ OUString* pProps = aProps.getArray();
+ pProps[0] = OUString::createFromAscii( "Title" );
+ pProps[1] = OUString::createFromAscii( "ContentType" );
+ pProps[2] = OUString::createFromAscii( "IsFolder" );
+
+ try
+ {
+ xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
+ if ( xDynResultSet.is() )
+ xResultSet = xDynResultSet->getStaticResultSet();
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_ERRORFILE( "createCursor: CommandAbortedException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "createCursor: Any other exception" );
+ }
+
+ if ( xResultSet.is() )
+ {
+ pList = new StringList_Impl;
+ uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
+ uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
+
+ try
+ {
+ while ( xResultSet->next() )
+ {
+ String aTitle( xRow->getString(1) );
+ String aType( xRow->getString(2) );
+ String aRow = aTitle;
+ aRow += '\t';
+ aRow += aType;
+ aRow += '\t';
+ aRow += String( xContentAccess->queryContentIdentifierString() );
+ OUString* pRow = new OUString( aRow );
+ pList->Insert( pRow, LIST_APPEND );
+ }
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "XContentAccess::next(): Any other exception" );
+ }
+ }
+ }
+ catch( uno::Exception& e )
+ {
+ (void) e;
+ DBG_ERRORFILE(
+ rtl::OUStringToOString(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "GetResultSet: Any other exception: ")) +
+ e.Message),
+ RTL_TEXTENCODING_UTF8).
+ getStr());
+ }
+
+ if ( pList )
+ {
+ ULONG nCount = pList->Count();
+ uno::Sequence < OUString > aRet( nCount );
+ OUString* pRet = aRet.getArray();
+ for ( ULONG i = 0; i < nCount; ++i )
+ {
+ OUString* pEntry = pList->GetObject(i);
+ pRet[i] = *( pEntry );
+ delete pEntry;
+ }
+ delete pList;
+ return aRet;
+ }
+ else
+ return uno::Sequence < OUString > ();
+}
+
+// -----------------------------------------------------------------------
+
+uno::Sequence< OUString > SfxContentHelper::GetHelpTreeViewContents( const String& rURL )
+{
+ StringList_Impl* pProperties = NULL;
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
+ uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
+ xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY );
+
+ ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
+ uno::Reference< sdbc::XResultSet > xResultSet;
+ uno::Sequence< OUString > aProps(2);
+ OUString* pProps = aProps.getArray();
+ pProps[0] = OUString::createFromAscii( "Title" );
+ pProps[1] = OUString::createFromAscii( "IsFolder" );
+
+ try
+ {
+ uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
+ xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
+ if ( xDynResultSet.is() )
+ xResultSet = xDynResultSet->getStaticResultSet();
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ if ( xResultSet.is() )
+ {
+ pProperties = new StringList_Impl;
+ uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
+ uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
+
+ try
+ {
+ while ( xResultSet->next() )
+ {
+ String aTitle( xRow->getString(1) );
+ sal_Bool bFolder = xRow->getBoolean(2);
+ String aRow = aTitle;
+ aRow += '\t';
+ aRow += String( xContentAccess->queryContentIdentifierString() );
+ aRow += '\t';
+ aRow += bFolder ? '1' : '0';
+ OUString* pRow = new OUString( aRow );
+ pProperties->Insert( pRow, LIST_APPEND );
+ }
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ if ( pProperties )
+ {
+ ULONG nCount = pProperties->Count();
+ uno::Sequence < OUString > aRet( nCount );
+ OUString* pRet = aRet.getArray();
+ for ( ULONG i = 0; i < nCount; ++i )
+ {
+ OUString* pProperty = pProperties->GetObject(i);
+ pRet[i] = *( pProperty );
+ delete pProperty;
+ }
+ delete pProperties;
+ return aRet;
+ }
+ else
+ return uno::Sequence < OUString > ();
+}
+
+// -----------------------------------------------------------------------
+
+String SfxContentHelper::GetActiveHelpString( const String& rURL )
+{
+ String aRet;
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
+ uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
+ xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY );
+ ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
+ // open the "active help" stream
+ uno::Reference< io::XInputStream > xStream = aCnt.openStream();
+ // and convert it to a String
+ uno::Sequence< sal_Int8 > lData;
+ sal_Int32 nRead = xStream->readBytes( lData, 1024 );
+ while ( nRead > 0 )
+ {
+ OStringBuffer sBuffer( nRead );
+ for( sal_Int32 i = 0; i < nRead; ++i )
+ sBuffer.append( (sal_Char)lData[i] );
+ OUString sString = OStringToOUString( sBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
+ aRet += String( sString );
+
+ nRead = xStream->readBytes( lData, 1024 );
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return aRet;
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxContentHelper::IsHelpErrorDocument( const String& rURL )
+{
+ sal_Bool bRet = sal_False;
+ try
+ {
+ ::ucbhelper::Content aCnt( INetURLObject( rURL ).GetMainURL( INetURLObject::NO_DECODE ),
+ uno::Reference< ucb::XCommandEnvironment > () );
+ if ( !( aCnt.getPropertyValue( OUString::createFromAscii( "IsErrorDocument" ) ) >>= bRet ) )
+ {
+ DBG_ERRORFILE( "Property 'IsErrorDocument' is missing" );
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxContentHelper::CopyTo( const String& rSource, const String& rDest )
+{
+ return Transfer_Impl( rSource, rDest, sal_False, ucb::NameClash::ERROR );
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxContentHelper::MoveTo( const String& rSource, const String& rDest, sal_Int32 nNameClash )
+{
+ return Transfer_Impl( rSource, rDest, sal_True, nNameClash );
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxContentHelper::MakeFolder( const String& rFolder )
+{
+ INetURLObject aURL( rFolder );
+ DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ String aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+ aURL.removeSegment();
+ uno::Sequence < OUString > aNames(2);
+ OUString* pNames = aNames.getArray();
+ pNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) );
+ pNames[1] = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) );
+ uno::Sequence<uno::Any> aValues(2);
+ uno::Any* pValues = aValues.getArray();
+ pValues[0] = uno::makeAny( OUString( aTitle ) );
+ pValues[1] = uno::makeAny( sal_Bool( sal_True ) );
+ uno::Reference< ucb::XCommandEnvironment > aCmdEnv;
+ sal_Bool bRet = sal_False;
+ try
+ {
+ ::ucbhelper::Content aCnt( aURL.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv );
+ ::ucbhelper::Content aNewFolder;
+ OUString aType( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.staroffice.fsys-folder" ) );
+ bRet = aCnt.insertNewContent( aType, aNames, aValues, aNewFolder );
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ // double name?
+ }
+ catch( ucb::IllegalIdentifierException& )
+ {
+ DBG_ERRORFILE( "Illegal identifier" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "Any other exception" );
+ }
+
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+
+ErrCode SfxContentHelper::QueryDiskSpace( const String& rPath, sal_Int64& rFreeBytes )
+{
+ ErrCode nErr = 0;
+ rFreeBytes = 0;
+ INetURLObject aObj( rPath );
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ try
+ {
+ ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
+ aCnt.getPropertyValue( OUString::createFromAscii( "FreeSpace" ) ) >>= rFreeBytes;
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_ERRORFILE( "CommandAbortedException" );
+ nErr = ERRCODE_IO_GENERAL;
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "Any other exception" );
+ nErr = ERRCODE_IO_GENERAL;
+ }
+ return nErr;
+}
+
+// -----------------------------------------------------------------------
+
+ULONG SfxContentHelper::GetSize( const String& rContent )
+{
+ ULONG nSize = 0;
+ sal_Int64 nTemp = 0;
+ INetURLObject aObj( rContent );
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ try
+ {
+ ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
+ aCnt.getPropertyValue( OUString::createFromAscii( "Size" ) ) >>= nTemp;
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_ERRORFILE( "CommandAbortedException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "Any other exception" );
+ }
+ nSize = (UINT32)nTemp;
+ return nSize;
+}
+
+// -----------------------------------------------------------------------
+// please don't use it (only used in appbas.cxx and appcfg.cxx)
+sal_Bool SfxContentHelper::Exists( const String& rContent )
+{
+ sal_Bool bRet = sal_False;
+ INetURLObject aObj( rContent );
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+
+ try
+ {
+ ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
+ // just try to get the property; if no exception is thrown, the content exists!
+ aCnt.isDocument();
+ bRet = sal_True;
+ }
+ catch( ucb::CommandAbortedException& )
+ {
+ DBG_WARNING( "CommandAbortedException" );
+ }
+ catch( ucb::IllegalIdentifierException& )
+ {
+ DBG_WARNING( "IllegalIdentifierException" );
+ }
+ catch( ucb::ContentCreationException& )
+ {
+ DBG_WARNING( "IllegalIdentifierException" );
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "Any other exception" );
+ }
+
+ return bRet;
+
+}
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxContentHelper::Find( const String& rFolder, const String& rName, String& rFile )
+{
+ sal_Bool bRet = sal_False;
+ rtl::OUString aFile;
+
+ if ( FileBase::searchFileURL( rName, rFolder, aFile ) == FileBase::E_None )
+ {
+ rFile = aFile;
+ bRet = sal_True;
+ }
+
+ return bRet;
+}
+
+
diff --git a/sfx2/source/bastyp/mieclip.cxx b/sfx2/source/bastyp/mieclip.cxx
new file mode 100644
index 000000000000..4154ddc6301b
--- /dev/null
+++ b/sfx2/source/bastyp/mieclip.cxx
@@ -0,0 +1,95 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <tools/stream.hxx>
+#include <tools/cachestr.hxx>
+
+#include <sot/storage.hxx>
+#include <sot/formats.hxx>
+
+#include <sfx2/mieclip.hxx>
+#include <sfx2/sfxuno.hxx>
+
+MSE40HTMLClipFormatObj::~MSE40HTMLClipFormatObj()
+{
+ delete pStrm;
+}
+
+SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream )
+{
+ BOOL bRet = FALSE;
+ if( pStrm )
+ delete pStrm, pStrm = 0;
+
+ ByteString sLine, sVersion;
+ ULONG nStt = 0, nEnd = 0;
+ USHORT nIndex = 0;
+
+ rStream.Seek(STREAM_SEEK_TO_BEGIN);
+ rStream.ResetError();
+
+ if( rStream.ReadLine( sLine ) &&
+ sLine.GetToken( 0, ':', nIndex ) == "Version" )
+ {
+ sVersion = sLine.Copy( nIndex );
+ while( rStream.ReadLine( sLine ) )
+ {
+ nIndex = 0;
+ ByteString sTmp( sLine.GetToken( 0, ':', nIndex ) );
+ if( sTmp == "StartHTML" )
+ nStt = (ULONG)(sLine.Erase( 0, nIndex ).ToInt32());
+ else if( sTmp == "EndHTML" )
+ nEnd = (ULONG)(sLine.Erase( 0, nIndex ).ToInt32());
+ else if( sTmp == "SourceURL" )
+ sBaseURL = String(S2U(sLine.Erase( 0, nIndex )));
+
+ if( nEnd && nStt &&
+ ( sBaseURL.Len() || rStream.Tell() >= nStt ))
+ {
+ bRet = TRUE;
+ break;
+ }
+ }
+ }
+
+ if( bRet )
+ {
+ rStream.Seek( nStt );
+
+ pStrm = new SvCacheStream( ( nEnd - nStt < 0x10000l
+ ? nEnd - nStt + 32
+ : 0 ));
+ *pStrm << rStream;
+ pStrm->SetStreamSize( nEnd - nStt + 1L );
+ pStrm->Seek( STREAM_SEEK_TO_BEGIN );
+ }
+
+ return pStrm;
+}
+
diff --git a/sfx2/source/bastyp/minarray.cxx b/sfx2/source/bastyp/minarray.cxx
new file mode 100644
index 000000000000..978239239cea
--- /dev/null
+++ b/sfx2/source/bastyp/minarray.cxx
@@ -0,0 +1,736 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+
+#include <sfx2/minarray.hxx>
+
+// -----------------------------------------------------------------------
+
+SfxPtrArr::SfxPtrArr( BYTE nInitSize, BYTE nGrowSize ):
+ nUsed( 0 ),
+ nGrow( nGrowSize ? nGrowSize : 1 ),
+ nUnused( nInitSize )
+{
+ DBG_MEMTEST();
+ USHORT nMSCBug = nInitSize;
+
+ if ( nMSCBug > 0 )
+ pData = new void*[nMSCBug];
+ else
+ pData = 0;
+}
+
+// -----------------------------------------------------------------------
+
+SfxPtrArr::SfxPtrArr( const SfxPtrArr& rOrig )
+{
+ DBG_MEMTEST();
+ nUsed = rOrig.nUsed;
+ nGrow = rOrig.nGrow;
+ nUnused = rOrig.nUnused;
+
+ if ( rOrig.pData != 0 )
+ {
+ pData = new void*[nUsed+nUnused];
+ memcpy( pData, rOrig.pData, nUsed*sizeof(void*) );
+ }
+ else
+ pData = 0;
+}
+
+// -----------------------------------------------------------------------
+
+SfxPtrArr::~SfxPtrArr()
+{
+ DBG_MEMTEST();
+ delete [] pData;
+}
+
+// -----------------------------------------------------------------------
+
+SfxPtrArr& SfxPtrArr::operator=( const SfxPtrArr& rOrig )
+{
+ DBG_MEMTEST();
+
+ delete [] pData;
+
+ nUsed = rOrig.nUsed;
+ nGrow = rOrig.nGrow;
+ nUnused = rOrig.nUnused;
+
+ if ( rOrig.pData != 0 )
+ {
+ pData = new void*[nUsed+nUnused];
+ memcpy( pData, rOrig.pData, nUsed*sizeof(void*) );
+ }
+ else
+ pData = 0;
+ return *this;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxPtrArr::Append( void* aElem )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( sal::static_int_cast< unsigned >(nUsed+1) < ( USHRT_MAX / sizeof(void*) ), "array too large" );
+ // musz das Array umkopiert werden?
+ if ( nUnused == 0 )
+ {
+ USHORT nNewSize = (nUsed == 1) ? (nGrow==1 ? 2 : nGrow) : nUsed+nGrow;
+ void** pNewData = new void*[nNewSize];
+ if ( pData )
+ {
+ DBG_ASSERT( nUsed <= nNewSize, "" );
+ memmove( pNewData, pData, sizeof(void*)*nUsed );
+ delete [] pData;
+ }
+ nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed);
+ pData = pNewData;
+ }
+
+ // jetzt hinten in den freien Raum schreiben
+ pData[nUsed] = aElem;
+ ++nUsed;
+ --nUnused;
+}
+
+// -----------------------------------------------------------------------
+
+USHORT SfxPtrArr::Remove( USHORT nPos, USHORT nLen )
+{
+ DBG_MEMTEST();
+ // nLen adjustieren, damit nicht ueber das Ende hinaus geloescht wird
+ nLen = Min( (USHORT)(nUsed-nPos), nLen );
+
+ // einfache Aufgaben erfordern einfache Loesungen!
+ if ( nLen == 0 )
+ return 0;
+
+ // bleibt vielleicht keiner uebrig
+ if ( (nUsed-nLen) == 0 )
+ {
+ delete [] pData;
+ pData = 0;
+ nUsed = 0;
+ nUnused = 0;
+ return nLen;
+ }
+
+ // feststellen, ob das Array dadurch physikalisch schrumpft...
+ if ( (nUnused+nLen) >= nGrow )
+ {
+ // auf die naechste Grow-Grenze aufgerundet verkleinern
+ USHORT nNewUsed = nUsed-nLen;
+ USHORT nNewSize = ((nNewUsed+nGrow-1)/nGrow) * nGrow;
+ DBG_ASSERT( nNewUsed <= nNewSize && nNewUsed+nGrow > nNewSize,
+ "shrink size computation failed" );
+ void** pNewData = new void*[nNewSize];
+ if ( nPos > 0 )
+ {
+ DBG_ASSERT( nPos <= nNewSize, "" );
+ memmove( pNewData, pData, sizeof(void*)*nPos );
+ }
+ if ( nNewUsed != nPos )
+ memmove( pNewData+nPos, pData+nPos+nLen,
+ sizeof(void*)*(nNewUsed-nPos) );
+ delete [] pData;
+ pData = pNewData;
+ nUsed = nNewUsed;
+ nUnused = sal::static_int_cast< BYTE >(nNewSize - nNewUsed);
+ return nLen;
+ }
+
+ // in allen anderen Faellen nur zusammenschieben
+ if ( nUsed-nPos-nLen > 0 )
+ memmove( pData+nPos, pData+nPos+nLen, (nUsed-nPos-nLen)*sizeof(void*) );
+ nUsed = nUsed - nLen;
+ nUnused = sal::static_int_cast< BYTE >(nUnused + nLen);
+ return nLen;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL SfxPtrArr::Remove( void* aElem )
+{
+ DBG_MEMTEST();
+ // einfache Aufgaben ...
+ if ( nUsed == 0 )
+ return FALSE;
+
+ // rueckwaerts, da meist der letzte zuerst wieder entfernt wird
+ void* *pIter = pData + nUsed - 1;
+ for ( USHORT n = 0; n < nUsed; ++n, --pIter )
+ if ( *pIter == aElem )
+ {
+ Remove(nUsed-n-1, 1);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL SfxPtrArr::Replace( void* aOldElem, void* aNewElem )
+{
+ DBG_MEMTEST();
+ // einfache Aufgaben ...
+ if ( nUsed == 0 )
+ return FALSE;
+
+ // rueckwaerts, da meist der letzte zuerst wieder entfernt wird
+ void* *pIter = pData + nUsed - 1;
+ for ( USHORT n = 0; n < nUsed; ++n, --pIter )
+ if ( *pIter == aOldElem )
+ {
+ pData[nUsed-n-1] = aNewElem;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL SfxPtrArr::Contains( const void* rItem ) const
+{
+ DBG_MEMTEST();
+ if ( !nUsed )
+ return FALSE;
+
+ for ( USHORT n = 0; n < nUsed; ++n )
+ {
+ void* p = GetObject(n);
+ if ( p == rItem )
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxPtrArr::Insert( USHORT nPos, void* rElem )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( sal::static_int_cast< unsigned >(nUsed+1) < ( USHRT_MAX / sizeof(void*) ), "array too large" );
+ // musz das Array umkopiert werden?
+ if ( nUnused == 0 )
+ {
+ // auf die naechste Grow-Grenze aufgerundet vergroeszern
+ USHORT nNewSize = nUsed+nGrow;
+ void** pNewData = new void*[nNewSize];
+
+ if ( pData )
+ {
+ DBG_ASSERT( nUsed < nNewSize, "" );
+ memmove( pNewData, pData, sizeof(void*)*nUsed );
+ delete [] pData;
+ }
+ nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed);
+ pData = pNewData;
+ }
+
+ // jetzt den hinteren Teil verschieben
+ if ( nPos < nUsed )
+ memmove( pData+nPos+1, pData+nPos, (nUsed-nPos)*sizeof(void*) );
+
+ // jetzt in den freien Raum schreiben
+ memmove( pData+nPos, &rElem, sizeof(void*) );
+ nUsed += 1;
+ nUnused -= 1;
+}
+
+// class ByteArr ---------------------------------------------------------
+
+ByteArr::ByteArr( BYTE nInitSize, BYTE nGrowSize ):
+ nUsed( 0 ),
+ nGrow( nGrowSize ? nGrowSize : 1 ),
+ nUnused( nInitSize )
+{
+ DBG_MEMTEST();
+ USHORT nMSCBug = nInitSize;
+
+ if ( nInitSize > 0 )
+ pData = new char[nMSCBug];
+ else
+ pData = 0;
+}
+
+// -----------------------------------------------------------------------
+
+ByteArr::ByteArr( const ByteArr& rOrig )
+{
+ DBG_MEMTEST();
+ nUsed = rOrig.nUsed;
+ nGrow = rOrig.nGrow;
+ nUnused = rOrig.nUnused;
+
+ if ( rOrig.pData != 0 )
+ {
+ pData = new char[nUsed+nUnused];
+ memcpy( pData, rOrig.pData, nUsed*sizeof(char) );
+ }
+ else
+ pData = 0;
+}
+
+// -----------------------------------------------------------------------
+
+ByteArr::~ByteArr()
+{
+ DBG_MEMTEST();
+ delete [] pData;
+}
+
+// -----------------------------------------------------------------------
+
+ByteArr& ByteArr::operator=( const ByteArr& rOrig )
+{
+ DBG_MEMTEST();
+
+ delete [] pData;
+
+ nUsed = rOrig.nUsed;
+ nGrow = rOrig.nGrow;
+ nUnused = rOrig.nUnused;
+
+ if ( rOrig.pData != 0 )
+ {
+ pData = new char[nUsed+nUnused];
+ memcpy( pData, rOrig.pData, nUsed*sizeof(char) );
+ }
+ else
+ pData = 0;
+ return *this;
+}
+
+// -----------------------------------------------------------------------
+
+void ByteArr::Append( char aElem )
+{
+ DBG_MEMTEST();
+ // musz das Array umkopiert werden?
+ if ( nUnused == 0 )
+ {
+ USHORT nNewSize = (nUsed == 1) ? (nGrow==1 ? 2 : nGrow) : nUsed+nGrow;
+ char* pNewData = new char[nNewSize];
+ if ( pData )
+ {
+ DBG_ASSERT( nUsed <= nNewSize, "" );
+ memmove( pNewData, pData, sizeof(char)*nUsed );
+ delete [] pData;
+ }
+ nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed);
+ pData = pNewData;
+ }
+
+ // jetzt hinten in den freien Raum schreiben
+ pData[nUsed] = aElem;
+ ++nUsed;
+ --nUnused;
+}
+
+// -----------------------------------------------------------------------
+
+USHORT ByteArr::Remove( USHORT nPos, USHORT nLen )
+{
+ DBG_MEMTEST();
+ // nLen adjustieren, damit nicht ueber das Ende hinaus geloescht wird
+ nLen = Min( (USHORT)(nUsed-nPos), nLen );
+
+ // einfache Aufgaben erfordern einfache Loesungen!
+ if ( nLen == 0 )
+ return 0;
+
+ // bleibt vielleicht keiner uebrig
+ if ( (nUsed-nLen) == 0 )
+ {
+ delete [] pData;
+ pData = 0;
+ nUsed = 0;
+ nUnused = 0;
+ return nLen;
+ }
+
+ // feststellen, ob das Array dadurch physikalisch schrumpft...
+ if ( (nUnused+nLen) >= nGrow )
+ {
+ // auf die naechste Grow-Grenze aufgerundet verkleinern
+ USHORT nNewUsed = nUsed-nLen;
+ USHORT nNewSize = ((nNewUsed+nGrow-1)/nGrow) * nGrow;
+ DBG_ASSERT( nNewUsed <= nNewSize && nNewUsed+nGrow > nNewSize,
+ "shrink size computation failed" );
+ char* pNewData = new char[nNewSize];
+ if ( nPos > 0 )
+ {
+ DBG_ASSERT( nPos <= nNewSize, "" );
+ memmove( pNewData, pData, sizeof(char)*nPos );
+ }
+ if ( nNewUsed != nPos )
+ memmove( pNewData+nPos, pData+nPos+nLen,
+ sizeof(char)*(nNewUsed-nPos) );
+ delete [] pData;
+ pData = pNewData;
+ nUsed = nNewUsed;
+ nUnused = sal::static_int_cast< BYTE >(nNewSize - nNewUsed);
+ return nLen;
+ }
+
+ // in allen anderen Faellen nur zusammenschieben
+ if ( nUsed-nPos-nLen > 0 )
+ memmove( pData+nPos, pData+nPos+nLen, (nUsed-nPos-nLen)*sizeof(char) );
+ nUsed = nUsed - nLen;
+ nUnused = sal::static_int_cast< BYTE >(nUnused + nLen);
+ return nLen;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL ByteArr::Remove( char aElem )
+{
+ DBG_MEMTEST();
+ // einfache Aufgaben ...
+ if ( nUsed == 0 )
+ return FALSE;
+
+ // rueckwaerts, da meist der letzte zuerst wieder entfernt wird
+ char *pIter = pData + nUsed - 1;
+ for ( USHORT n = 0; n < nUsed; ++n, --pIter )
+ if ( *pIter == aElem )
+ {
+ Remove(nUsed-n-1, 1);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL ByteArr::Contains( const char rItem ) const
+{
+ DBG_MEMTEST();
+ if ( !nUsed )
+ return FALSE;
+
+ for ( USHORT n = 0; n < nUsed; ++n )
+ {
+ char p = GetObject(n);
+ if ( p == rItem )
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------
+
+void ByteArr::Insert( USHORT nPos, char rElem )
+{
+ DBG_MEMTEST();
+ // musz das Array umkopiert werden?
+ if ( nUnused == 0 )
+ {
+ // auf die naechste Grow-Grenze aufgerundet vergroeszern
+ USHORT nNewSize = nUsed+nGrow;
+ char* pNewData = new char[nNewSize];
+
+ if ( pData )
+ {
+ DBG_ASSERT( nUsed < nNewSize, "" );
+ memmove( pNewData, pData, sizeof(char)*nUsed );
+ delete [] pData;
+ }
+ nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed);
+ pData = pNewData;
+ }
+
+ // jetzt den hinteren Teil verschieben
+ if ( nPos < nUsed )
+ memmove( pData+nPos+1, pData+nPos, (nUsed-nPos)*sizeof(char) );
+
+ // jetzt in den freien Raum schreiben
+ memmove( pData+nPos, &rElem, sizeof(char) );
+ nUsed += 1;
+ nUnused -= 1;
+}
+
+// -----------------------------------------------------------------------
+
+char ByteArr::operator[]( USHORT nPos ) const
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( nPos < nUsed, "" );
+ return *(pData+nPos);
+}
+
+// -----------------------------------------------------------------------
+
+char& ByteArr::operator [] (USHORT nPos)
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( nPos < nUsed, "" );
+ return *(pData+nPos);
+}
+
+// class WordArr ---------------------------------------------------------
+
+WordArr::WordArr( BYTE nInitSize, BYTE nGrowSize ):
+ nUsed( 0 ),
+ nGrow( nGrowSize ? nGrowSize : 1 ),
+ nUnused( nInitSize )
+{
+ DBG_MEMTEST();
+ USHORT nMSCBug = nInitSize;
+
+ if ( nInitSize > 0 )
+ pData = new short[nMSCBug];
+ else
+ pData = 0;
+}
+
+// -----------------------------------------------------------------------
+
+WordArr::WordArr( const WordArr& rOrig )
+{
+ DBG_MEMTEST();
+ nUsed = rOrig.nUsed;
+ nGrow = rOrig.nGrow;
+ nUnused = rOrig.nUnused;
+
+ if ( rOrig.pData != 0 )
+ {
+ pData = new short[nUsed+nUnused];
+ memcpy( pData, rOrig.pData, nUsed*sizeof(short) );
+ }
+ else
+ pData = 0;
+}
+
+// -----------------------------------------------------------------------
+
+WordArr::~WordArr()
+{
+ DBG_MEMTEST();
+ delete [] pData;
+}
+
+// -----------------------------------------------------------------------
+
+WordArr& WordArr::operator=( const WordArr& rOrig )
+{
+ DBG_MEMTEST();
+
+ delete [] pData;
+
+ nUsed = rOrig.nUsed;
+ nGrow = rOrig.nGrow;
+ nUnused = rOrig.nUnused;
+
+ if ( rOrig.pData != 0 )
+ {
+ pData = new short[nUsed+nUnused];
+ memcpy( pData, rOrig.pData, nUsed*sizeof(short) );
+ }
+ else
+ pData = 0;
+ return *this;
+}
+
+// -----------------------------------------------------------------------
+
+void WordArr::Append( short aElem )
+{
+ DBG_MEMTEST();
+ // musz das Array umkopiert werden?
+ if ( nUnused == 0 )
+ {
+ USHORT nNewSize = (nUsed == 1) ? (nGrow==1 ? 2 : nGrow) : nUsed+nGrow;
+ short* pNewData = new short[nNewSize];
+ if ( pData )
+ {
+ DBG_ASSERT( nUsed <= nNewSize, " " );
+ memmove( pNewData, pData, sizeof(short)*nUsed );
+ delete [] pData;
+ }
+ nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed);
+ pData = pNewData;
+ }
+
+ // jetzt hinten in den freien Raum schreiben
+ pData[nUsed] = aElem;
+ ++nUsed;
+ --nUnused;
+}
+
+// -----------------------------------------------------------------------
+
+USHORT WordArr::Remove( USHORT nPos, USHORT nLen )
+{
+ DBG_MEMTEST();
+ // nLen adjustieren, damit nicht ueber das Ende hinaus geloescht wird
+ nLen = Min( (USHORT)(nUsed-nPos), nLen );
+
+ // einfache Aufgaben erfordern einfache Loesungen!
+ if ( nLen == 0 )
+ return 0;
+
+ // bleibt vielleicht keiner uebrig
+ if ( (nUsed-nLen) == 0 )
+ {
+ delete [] pData;
+ pData = 0;
+ nUsed = 0;
+ nUnused = 0;
+ return nLen;
+ }
+
+ // feststellen, ob das Array dadurch physikalisch schrumpft...
+ if ( (nUnused+nLen) >= nGrow )
+ {
+ // auf die naechste Grow-Grenze aufgerundet verkleinern
+ USHORT nNewUsed = nUsed-nLen;
+ USHORT nNewSize = ((nNewUsed+nGrow-1)/nGrow) * nGrow;
+ DBG_ASSERT( nNewUsed <= nNewSize && nNewUsed+nGrow > nNewSize,
+ "shrink size computation failed" );
+ short* pNewData = new short[nNewSize];
+ if ( nPos > 0 )
+ {
+ DBG_ASSERT( nPos <= nNewSize, "" );
+ memmove( pNewData, pData, sizeof(short)*nPos );
+ }
+ if ( nNewUsed != nPos )
+ memmove( pNewData+nPos, pData+nPos+nLen,
+ sizeof(short)*(nNewUsed-nPos) );
+ delete [] pData;
+ pData = pNewData;
+ nUsed = nNewUsed;
+ nUnused = sal::static_int_cast< BYTE >(nNewSize - nNewUsed);
+ return nLen;
+ }
+
+ // in allen anderen Faellen nur zusammenschieben
+ if ( nUsed-nPos-nLen > 0 )
+ memmove( pData+nPos, pData+nPos+nLen, (nUsed-nPos-nLen)*sizeof(short) );
+ nUsed = nUsed - nLen;
+ nUnused = sal::static_int_cast< BYTE >(nUnused + nLen);
+ return nLen;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL WordArr::Remove( short aElem )
+{
+ DBG_MEMTEST();
+ // einfache Aufgaben ...
+ if ( nUsed == 0 )
+ return FALSE;
+
+ // rueckwaerts, da meist der letzte zuerst wieder entfernt wird
+ short *pIter = pData + nUsed - 1;
+ for ( USHORT n = 0; n < nUsed; ++n, --pIter )
+ if ( *pIter == aElem )
+ {
+ Remove(nUsed-n-1, 1);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL WordArr::Contains( const short rItem ) const
+{
+ DBG_MEMTEST();
+ if ( !nUsed )
+ return FALSE;
+
+ for ( USHORT n = 0; n < nUsed; ++n )
+ {
+ short p = GetObject(n);
+ if ( p == rItem )
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------
+
+void WordArr::Insert( USHORT nPos, short rElem )
+{
+ DBG_MEMTEST();
+ // musz das Array umkopiert werden?
+ if ( nUnused == 0 )
+ {
+ // auf die naechste Grow-Grenze aufgerundet vergroeszern
+ USHORT nNewSize = nUsed+nGrow;
+ short* pNewData = new short[nNewSize];
+
+ if ( pData )
+ {
+ DBG_ASSERT( nUsed < nNewSize, "" );
+ memmove( pNewData, pData, sizeof(short)*nUsed );
+ delete [] pData;
+ }
+ nUnused = sal::static_int_cast< BYTE >(nNewSize-nUsed);
+ pData = pNewData;
+ }
+
+ // jetzt den hinteren Teil verschieben
+ if ( nPos < nUsed )
+ memmove( pData+nPos+1, pData+nPos, (nUsed-nPos)*sizeof(short) );
+
+ // jetzt in den freien Raum schreiben
+ memmove( pData+nPos, &rElem, sizeof(short) );
+ nUsed += 1;
+ nUnused -= 1;
+}
+
+// -----------------------------------------------------------------------
+
+short WordArr::operator[]( USHORT nPos ) const
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( nPos < nUsed, "" );
+ return *(pData+nPos);
+}
+
+// -----------------------------------------------------------------------
+
+short& WordArr::operator [] (USHORT nPos)
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( nPos < nUsed, "" );
+ return *(pData+nPos);
+}
+
+
diff --git a/sfx2/source/bastyp/misc.cxx b/sfx2/source/bastyp/misc.cxx
new file mode 100644
index 000000000000..49938c729b36
--- /dev/null
+++ b/sfx2/source/bastyp/misc.cxx
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+
+#include "sfxtypes.hxx"
+
+//--------------------------------------------------------------------
+
+#if defined(DBG_UTIL) && ( defined(WNT) || defined(OS2) )
+unsigned SfxStack::nLevel = 0;
+#endif
+
+//--------------------------------------------------------------------
+
+String SearchAndReplace( const String &rSource,
+ const String &rToReplace,
+ const String &rReplacement )
+{
+ String aTarget( rSource );
+ USHORT nPos = rSource.Search( rToReplace );
+ if ( nPos != STRING_NOTFOUND )
+ {
+ aTarget.Erase( nPos, rToReplace.Len() );
+ return aTarget.Insert( rReplacement, nPos );
+ }
+ return rSource;
+}
+
+//--------------------------------------------------------------------
+
+String SfxStringEncode( const String &rSource, const char * )
+{
+ String aRet;
+ String aCoded(rSource);
+ return aRet;
+}
+
+//--------------------------------------------------------------------
+
+String SfxStringDecode( const String &, const char * )
+{
+ String aRet;
+ return aRet;
+}
+
+
diff --git a/sfx2/source/bastyp/progress.cxx b/sfx2/source/bastyp/progress.cxx
new file mode 100644
index 000000000000..9650c8155d84
--- /dev/null
+++ b/sfx2/source/bastyp/progress.cxx
@@ -0,0 +1,753 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sfx2/progress.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
+
+#ifndef _SBX_HXX //autogen
+#include <basic/sbx.hxx>
+#endif
+
+#include <svl/eitem.hxx>
+#include <tools/time.hxx>
+
+// wg. nRescheduleLocks
+#include "appdata.hxx"
+#include <sfx2/request.hxx>
+#include <sfx2/frame.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/dispatch.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/docfile.hxx>
+#include "workwin.hxx"
+#include "sfx2/sfxresid.hxx"
+#include "bastyp.hrc"
+#include <sfx2/msg.hxx>
+
+#include <time.h>
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::task;
+
+void AddNumber_Impl( String& aNumber, sal_uInt32 nArg )
+{
+ if ( nArg >= 10240 )
+ {
+ aNumber += String::CreateFromInt32( (sal_uInt16)( ( nArg + 512 ) / 1024 ) );
+ aNumber += ' ';
+ aNumber += SfxResId( STR_KB );
+ }
+ else
+ {
+ aNumber += String::CreateFromInt32( nArg );
+ aNumber += ' ';
+ aNumber += SfxResId( STR_BYTES );
+ }
+}
+
+struct SfxProgress_Impl
+{
+ Reference < XStatusIndicator > xStatusInd;
+ String aText, aStateText;
+ ULONG nMax;
+ clock_t nCreate;
+ clock_t nNextReschedule;
+ BOOL bLocked, bAllDocs;
+ BOOL bWaitMode;
+ BOOL bAllowRescheduling;
+ BOOL bRunning;
+ BOOL bIsStatusText;
+
+ SfxProgress* pActiveProgress;
+ SfxObjectShellRef xObjSh;
+ SfxWorkWindow* pWorkWin;
+ SfxViewFrame* pView;
+
+ SfxProgress_Impl( const String& );
+ void Enable_Impl( BOOL );
+
+};
+
+//========================================================================
+
+#define TIMEOUT_PROGRESS 5L /* 10th s */
+#define MAXPERCENT_PROGRESS 33
+
+#define TIMEOUT_RESCHEDULE 10L /* 10th s */
+#define MAXPERCENT_RESCHEDULE 50
+
+#define Progress
+#include "sfxslots.hxx"
+
+#define aTypeLibInfo aProgressTypeLibImpl
+
+//========================================================================
+extern ULONG Get10ThSec();
+
+// -----------------------------------------------------------------------
+
+void SfxProgress_Impl::Enable_Impl( BOOL bEnable )
+{
+ SfxObjectShell* pDoc = bAllDocs ? NULL : (SfxObjectShell*) xObjSh;
+ SfxViewFrame *pFrame= SfxViewFrame::GetFirst(pDoc);
+ while ( pFrame )
+ {
+ pFrame->Enable(bEnable);
+ pFrame->GetDispatcher()->Lock( !bEnable );
+ pFrame = SfxViewFrame::GetNext(*pFrame, pDoc);
+ }
+
+ if ( pView )
+ {
+ pView->Enable( bEnable );
+ pView->GetDispatcher()->Lock( !bEnable );
+ }
+
+ if ( !pDoc )
+ SFX_APP()->GetAppDispatcher_Impl()->Lock( !bEnable );
+}
+
+// -----------------------------------------------------------------------
+
+SfxProgress_Impl::SfxProgress_Impl( const String &/*rTitle*/ )
+ : pActiveProgress( 0 )
+{
+}
+
+// -----------------------------------------------------------------------
+
+SfxProgress::SfxProgress
+(
+ SfxObjectShell* pObjSh, /* SfxObjectShell, an der die Aktion ausgef"uhrt
+ wird. Kann NULL sein, dann wird die Applikation
+ verwendet */
+
+ const String& rText, /* Text, der in der Statuszeile vor den Statusmonitor
+ erscheint */
+
+ ULONG nRange, /* Maximalwert des Bereiches */
+
+ BOOL bAll /* alle Dokumente oder nur das Dokument des ViewFrames
+ disablen (FALSE) */
+ ,BOOL bWait /* initial den Wait-Pointer aktivieren (TRUE) */
+)
+
+/* [Beschreibung]
+
+ Der Konstruktor der Klasse SfxProgress schaltet den als Parameter
+ "ubergebenen SfxObjectShell und SfxViewFrames, welche dieses Dokument
+ anzeigen in einen Progress-Mode. D.h. solange eine dieser SfxViewFrame
+ Instanzen aktiv ist, ist der dazugeh"orige SfxDispatcher und das
+ dazugeh"orige Window disabled. In der Statuszeile wird ein Balken zur
+ Fortschritts-Anzeige angezeigt.
+*/
+
+: pImp( new SfxProgress_Impl( rText ) ),
+ nVal(0),
+ bSuspended(TRUE)
+{
+ pImp->bRunning = TRUE;
+ pImp->bAllowRescheduling = Application::IsInExecute();;
+
+ pImp->xObjSh = pObjSh;
+ pImp->aText = rText;
+ pImp->nMax = nRange;
+ pImp->bLocked = FALSE;
+ pImp->bWaitMode = bWait;
+ pImp->bIsStatusText = FALSE;
+ pImp->nCreate = Get10ThSec();
+ pImp->nNextReschedule = pImp->nCreate;
+ DBG( DbgOutf( "SfxProgress: created for '%s' at %luds",
+ rText.GetBuffer(), pImp->nCreate ) );
+ pImp->bAllDocs = bAll;
+ pImp->pWorkWin = 0;
+ pImp->pView = 0;
+
+ pImp->pActiveProgress = GetActiveProgress( pObjSh );
+ if ( pObjSh )
+ pObjSh->SetProgress_Impl(this);
+ else if( !pImp->pActiveProgress )
+ SFX_APP()->SetProgress_Impl(this);
+ Resume();
+}
+
+// -----------------------------------------------------------------------
+
+SfxProgress::~SfxProgress()
+
+/* [Beschreibung]
+
+ Der Destruktor der Klasse SfxProgress restauriert den alten Zustand;
+ die Dokumente werden wieder freigeschaltet und die Statuszeile zeigt
+ wieder Items an.
+*/
+
+{
+ Stop();
+ if ( pImp->xStatusInd.is() )
+ pImp->xStatusInd->end();
+
+ if( pImp->bIsStatusText == TRUE )
+ GetpApp()->HideStatusText( );
+ delete pImp;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxProgress::Stop()
+
+/* [Beschreibung]
+
+ Vorzeitiges Beenden des <SfxProgress>.
+*/
+
+{
+ if( pImp->pActiveProgress )
+ {
+ if ( pImp->xObjSh.Is() && pImp->xObjSh->GetProgress() == this )
+ pImp->xObjSh->SetProgress_Impl(0);
+ return;
+ }
+
+ if ( !pImp->bRunning )
+ return;
+ pImp->bRunning = FALSE;
+ DBG( DbgOutf( "SfxProgress: destroyed at %luds", Get10ThSec() ) );
+
+ Suspend();
+ if ( pImp->xObjSh.Is() )
+ pImp->xObjSh->SetProgress_Impl(0);
+ else
+ SFX_APP()->SetProgress_Impl(0);
+ if ( pImp->bLocked )
+ pImp->Enable_Impl(TRUE);
+}
+
+// -----------------------------------------------------------------------
+
+void SfxProgress::SetText
+(
+ const String& /* neuer Text */
+)
+
+/* [Beschreibung]
+
+ "Andert den Text, der links neben dem Fortschritts-Balken
+ angezeigt wird.
+*/
+
+{
+ if( pImp->pActiveProgress ) return;
+ if ( pImp->xStatusInd.is() )
+ {
+ pImp->xStatusInd->reset();
+ pImp->xStatusInd->start( pImp->aText, pImp->nMax );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+const String& SfxProgress::GetStateText_Impl() const
+{
+ return pImp->aStateText;
+}
+
+// -----------------------------------------------------------------------
+/*
+IMPL_STATIC_LINK( SfxProgress, SetStateHdl, PlugInLoadStatus*, pStatus )
+{
+ INetRequest* pReq = 0;
+ const INetHint *pHint = PTR_CAST( INetHint, pStatus->pHint );
+ pReq = PTR_CAST( INetRequest, pStatus->pBC );
+
+ String aString;
+ if( pReq )
+ aString = SfxMedium::GetStatusString( pHint->GetId(), pReq, pHint );
+ if( aString.Len() )
+ {
+ GetpApp()->ShowStatusText( aString );
+ if( pThis )
+ pThis->pImp->bIsStatusText = TRUE;
+ }
+ return 0;
+}
+*/
+
+// -----------------------------------------------------------------------
+
+// muss in AppDaten
+static ULONG nLastTime = 0;
+
+long TimeOut_Impl( void*, void* pArgV )
+{
+ Timer *pArg = (Timer*)pArgV;
+ if( Time::GetSystemTicks() - nLastTime > 3000 )
+ {
+ GetpApp()->HideStatusText();
+ nLastTime = 0;
+ delete pArg;
+ }
+ else pArg->Start();
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL SfxProgress::SetStateText
+(
+ ULONG nNewVal, /* neuer Wert f"ur die Fortschritts-Anzeige */
+ const String& rNewVal, /* Status als Text */
+ ULONG nNewRange /* neuer Maximalwert, 0 f"ur Beibehaltung des alten */
+)
+
+{
+ pImp->aStateText = rNewVal;
+ return SetState( nNewVal, nNewRange );
+}
+
+// -----------------------------------------------------------------------
+
+BOOL SfxProgress::SetState
+(
+ ULONG nNewVal, /* neuer Wert f"ur die Fortschritts-Anzeige */
+
+ ULONG nNewRange /* neuer Maximalwert, 0 f"ur Beibehaltung des alten */
+)
+/* [Beschreibung]
+
+ Setzen des aktuellen Status; nach einem zeitlichen Versatz
+ wird Reschedule aufgerufen.
+
+
+ [R"uckgabewert]
+
+ BOOL TRUE
+ Fortfahren mit der Aktion
+
+ FALSE
+ Abbrechen der Aktion
+*/
+
+{
+ // wurde via Stop-Button angehalten?
+// if ( pImp->IsCancelled() )
+// return FALSE;
+
+ if( pImp->pActiveProgress ) return TRUE;
+
+ // neuen Wert "ubernehmen
+ BOOL bOver=FALSE;
+ nVal = nNewVal;
+
+ // neuer Range?
+ if ( nNewRange && nNewRange != pImp->nMax )
+ {
+ DBG( DbgOutf( "SfxProgress: range changed from %lu to %lu",
+ pImp->nMax, nNewRange ) );
+ pImp->nMax = nNewRange;
+ bOver = TRUE;
+ }
+
+ if ( !pImp->xStatusInd.is() )
+ {
+ // get the active ViewFrame of the document this progress is working on
+ // if it doesn't work on a document, take the current ViewFrame
+ SfxObjectShell* pObjSh = pImp->xObjSh;
+ pImp->pView = SfxViewFrame::Current();
+ DBG_ASSERT( pImp->pView || pObjSh, "Can't make progress bar!");
+ if ( pObjSh && ( !pImp->pView || pObjSh != pImp->pView->GetObjectShell() ) )
+ {
+ // current document does not belong to current ViewFrame; take it's first visible ViewFrame
+ SfxViewFrame* pDocView = SfxViewFrame::GetFirst( pObjSh );
+ if ( pDocView )
+ pImp->pView = pDocView;
+ else
+ {
+ // don't show status indicator for hidden documents (only valid while loading)
+ SfxMedium* pMedium = pObjSh->GetMedium();
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, FALSE );
+ if ( !pHiddenItem || !pHiddenItem->GetValue() )
+ {
+ // not in a view, perhaps it's just loading
+ //SfxFrame* pFrame = pMedium->GetLoadTargetFrame();
+ //if ( pFrame && pFrame->GetCurrentViewFrame() )
+ //{
+ // recycling frame
+ //pImp->pView = pFrame->GetCurrentViewFrame();
+ //}
+ //else
+ {
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pIndicatorItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, FALSE );
+ Reference< XStatusIndicator > xInd;
+ if ( pIndicatorItem && (pIndicatorItem->GetValue()>>=xInd) )
+ pImp->xStatusInd = xInd;
+ }
+ }
+ }
+ }
+ else if ( pImp->pView )
+ {
+ pImp->pWorkWin = SFX_APP()->GetWorkWindow_Impl( pImp->pView );
+ if ( pImp->pWorkWin )
+ pImp->xStatusInd = pImp->pWorkWin->GetStatusIndicator();
+ }
+
+ if ( pImp->xStatusInd.is() )
+ {
+ pImp->xStatusInd->start( pImp->aText, pImp->nMax );
+ pImp->pView = NULL;
+ }
+ }
+
+ if ( pImp->xStatusInd.is() )
+ {
+ pImp->xStatusInd->setValue( nNewVal );
+ }
+
+ return TRUE;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxProgress::Resume()
+
+/* [Beschreibung]
+
+ Nimmt die Anzeige des Status nach einer Unterbrechung wieder auf.
+
+ [Querverweise]
+ <SfxProgress::Suspend()>
+*/
+
+{
+ if( pImp->pActiveProgress ) return;
+ if ( bSuspended )
+ {
+ DBG( DbgOutf( "SfxProgress: resumed" ) );
+ if ( pImp->xStatusInd.is() )
+ {
+ pImp->xStatusInd->start( pImp->aText, pImp->nMax );
+ pImp->xStatusInd->setValue( nVal );
+ }
+
+ if ( pImp->bWaitMode )
+ {
+ if ( pImp->xObjSh.Is() && !pImp->bAllDocs )
+ {
+ for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImp->xObjSh);
+ pFrame;
+ pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) )
+ pFrame->GetWindow().EnterWait();
+ }
+ }
+
+ if ( pImp->xObjSh )
+ {
+ SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImp->xObjSh);
+ if ( pFrame )
+ pFrame->GetBindings().ENTERREGISTRATIONS();
+ }
+
+ bSuspended = FALSE;
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxProgress::Suspend()
+
+/* [Beschreibung]
+
+ Unterbricht die Anzeige des Status
+
+ [Querverweise]
+ <SfxProgress::Resume()>
+*/
+
+{
+ if( pImp->pActiveProgress ) return;
+ if ( !bSuspended )
+ {
+ DBG( DbgOutf( "SfxProgress: suspended" ) );
+ bSuspended = TRUE;
+
+ if ( pImp->xStatusInd.is() )
+ {
+ pImp->xStatusInd->reset();
+ }
+
+ if ( pImp->xObjSh.Is() && !pImp->bAllDocs )
+ {
+ for ( SfxViewFrame *pFrame =
+ SfxViewFrame::GetFirst(pImp->xObjSh);
+ pFrame;
+ pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) )
+ pFrame->GetWindow().LeaveWait();
+ }
+ if ( pImp->xObjSh.Is() )
+ {
+ SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImp->xObjSh);
+ if ( pFrame )
+ pFrame->GetBindings().LEAVEREGISTRATIONS();
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxProgress::Lock()
+{
+ if( pImp->pActiveProgress ) return;
+ // kein Reschedule bei Embedded-Objekten,
+ // da wir gegen das OLE Protokoll wehrlos sind
+ if ( !pImp->xObjSh.Is() )
+ {
+ for ( SfxObjectShell *pDocSh = SfxObjectShell::GetFirst();
+ pDocSh;
+ pDocSh = SfxObjectShell::GetNext(*pDocSh) )
+ {
+ SfxObjectCreateMode eMode = pDocSh->GetCreateMode();
+ if ( ( eMode == SFX_CREATE_MODE_EMBEDDED ) ||
+ ( eMode == SFX_CREATE_MODE_PREVIEW ) )
+ {
+ DBG( DbgOutf( "SfxProgress: not locked because EMBEDDED/PREVIEW found" ) );
+ pImp->bAllowRescheduling = FALSE;
+ }
+ }
+ }
+ else
+ {
+ SfxObjectCreateMode eMode = pImp->xObjSh->GetCreateMode();
+ if ( ( eMode == SFX_CREATE_MODE_EMBEDDED ) ||
+ ( eMode == SFX_CREATE_MODE_PREVIEW ) )
+ {
+ DBG( DbgOutf( "SfxProgress: not locked because ObjectShell is EMBEDDED/PREVIEW" ) );
+ pImp->bAllowRescheduling = FALSE;
+ }
+ }
+
+ pImp->Enable_Impl( FALSE );
+
+ DBG( DbgOutf( "SfxProgress: locked" ) );
+ pImp->bLocked = TRUE;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxProgress::UnLock()
+{
+ if( pImp->pActiveProgress ) return;
+ if ( !pImp->bLocked )
+ return;
+
+ DBG( DbgOutf( "SfxProgress: unlocked" ) );
+ pImp->bLocked = FALSE;
+ pImp->Enable_Impl(TRUE);
+}
+
+// -----------------------------------------------------------------------
+
+void SfxProgress::Reschedule()
+
+/* [Beschreibung]
+
+ Reschedule von au"sen rufbar
+
+*/
+
+{
+ SFX_STACK(SfxProgress::Reschedule);
+
+ if( pImp->pActiveProgress ) return;
+ SfxApplication* pApp = SFX_APP();
+ if ( pImp->bLocked && 0 == pApp->Get_Impl()->nRescheduleLocks )
+ {
+ DBG_ASSERTWARNING( pApp->IsInAsynchronCall_Impl(),
+ "Reschedule in synchron-call-stack" );
+
+ SfxAppData_Impl *pAppData = pApp->Get_Impl();
+ ++pAppData->nInReschedule;
+ Application::Reschedule();
+ --pAppData->nInReschedule;
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxProgress::SetWaitMode
+(
+ BOOL bWait /* TRUE
+ Wartecursor wird verwendet
+
+ FALSE
+ Es wird kein Wartecursor verwendet */
+)
+
+/* [Beschreibung]
+
+ Wartecursor-Modus umschalten.
+
+*/
+
+{
+ if( pImp->pActiveProgress ) return;
+ if ( !bSuspended && pImp->bWaitMode != bWait )
+ {
+ if ( bWait )
+ {
+ if ( pImp->xObjSh.Is() && !pImp->bAllDocs )
+ {
+ for ( SfxViewFrame *pFrame =
+ SfxViewFrame::GetFirst(pImp->xObjSh);
+ pFrame;
+ pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) )
+ pFrame->GetWindow().EnterWait();
+ }
+ }
+ else
+ {
+ if ( pImp->xObjSh.Is() && !pImp->bAllDocs )
+ {
+ for ( SfxViewFrame *pFrame =
+ SfxViewFrame::GetFirst(pImp->xObjSh);
+ pFrame;
+ pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) )
+ pFrame->GetWindow().LeaveWait();
+ }
+ }
+ }
+
+ pImp->bWaitMode = bWait;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL SfxProgress::GetWaitMode() const
+
+/* [Beschreibung]
+
+ Wartecursor-Modus abfragen.
+
+*/
+
+{
+ return pImp->bWaitMode;
+}
+
+// -----------------------------------------------------------------------
+
+SfxProgress* SfxProgress::GetActiveProgress
+(
+ SfxObjectShell* pDocSh /* <SfxObjectShell>, die nach einem laufenden
+ <SfxProgress> gefragt werden soll, oder
+ 0, wenn ein f"ur die gesamte Applikation
+ laufender SfxProgress erfragt werden soll.
+ Der Pointer braucht nur zum Zeitpunkt des
+ Aufrufs g"ultig zu sein. */
+)
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann erfragt werden, ob und welcher <SfxProgress>-
+ f"ur eine bestimmte Instanz von SfxObjectShell oder gar die gesamte
+ Applikation zur Zeit aktiv ist. Dies kann z.B. zum Abfangen von
+ Time-Out-Events etc. verwendet werden.
+
+ Anstelle eines Pointer auf den SfxProgress der SfxObjectShell wird
+ ggf. der auf den SfxProgress der Applikation geliefert, mit der
+ Abfrage 'SfxProgress::GetActiveProgress(pMyDocSh)' wird also
+ insofern vorhanden der SfxProgress von 'pMyDocSh' geliefert,
+ sonst der SfxProgress der Applikation bzw. ein 0-Pointer.
+
+
+ [Anmerkung]
+
+ "auft kein SfxProgress an der Applikation und ebenfalls keiner an
+ der angegebenen SfxObjectShell, dann wird immer 0 zur"uckgeliefert,
+ auch wenn an einer anderen SfxObjectShell ein SfxProgress l"uft.
+
+
+ [Querverweise]
+
+ <SfxApplication::GetProgress()const>
+ <SfxObjectShell::GetProgress()const>
+*/
+
+{
+ if ( !SfxApplication::Get() )
+ return 0;
+
+ SfxProgress *pProgress = 0;
+ if ( pDocSh )
+ pProgress = pDocSh->GetProgress();
+ if ( !pProgress )
+ pProgress = SFX_APP()->GetProgress();
+ return pProgress;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxProgress::EnterLock()
+{
+ SFX_APP()->Get_Impl()->nRescheduleLocks++;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxProgress::LeaveLock()
+{
+ SfxAppData_Impl *pImp = SFX_APP()->Get_Impl();
+ DBG_ASSERT( 0 != pImp->nRescheduleLocks, "SFxProgress::LeaveLock but no locks" );
+ pImp->nRescheduleLocks--;
+}
+
+// -----------------------------------------------------------------------
+
+FASTBOOL SfxProgress::StatusBarManagerGone_Impl
+(
+ SfxStatusBarManager * // dieser <SfxStatusBarManager> wird zerst"ort
+)
+
+/* [Beschreibung]
+
+ Interne Methode zum Benachrichtigen des SfxProgress, da\s der angegebene
+ SfxStatusBarManger zerst"ort wird. Damit der Progress ihn loslassen
+ kann.
+*/
+
+{
+ return TRUE;
+}
+
diff --git a/sfx2/source/bastyp/sfxhtml.cxx b/sfx2/source/bastyp/sfxhtml.cxx
new file mode 100644
index 000000000000..8a4b434f460b
--- /dev/null
+++ b/sfx2/source/bastyp/sfxhtml.cxx
@@ -0,0 +1,447 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <tools/urlobj.hxx>
+
+#include <sfx2/objsh.hxx>
+#include <sfx2/docfile.hxx>
+#include "openflag.hxx"
+
+#include <svtools/htmlkywd.hxx>
+#include <svtools/htmltokn.h>
+#include <svtools/imap.hxx>
+#include <svtools/imapcirc.hxx>
+#include <svtools/imapobj.hxx>
+#include <svtools/imappoly.hxx>
+#include <svtools/imaprect.hxx>
+#ifndef _SVSTDARR_ULONGS_DECL
+#define _SVSTDARR_ULONGS
+#include <svl/svstdarr.hxx>
+#endif
+#include <svl/zforlist.hxx>
+#include <rtl/tencinfo.h>
+#include <tools/tenccvt.hxx>
+
+#include <sfx2/sfxhtml.hxx>
+
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+
+
+using namespace ::com::sun::star;
+
+
+sal_Char __FAR_DATA sHTML_MIME_text[] = "text/";
+sal_Char __FAR_DATA sHTML_MIME_application[] = "application/";
+sal_Char __FAR_DATA sHTML_MIME_experimental[] = "x-";
+
+// <INPUT TYPE=xxx>
+static HTMLOptionEnum __READONLY_DATA aAreaShapeOptEnums[] =
+{
+ { OOO_STRING_SVTOOLS_HTML_SH_rect, IMAP_OBJ_RECTANGLE },
+ { OOO_STRING_SVTOOLS_HTML_SH_rectangle, IMAP_OBJ_RECTANGLE },
+ { OOO_STRING_SVTOOLS_HTML_SH_circ, IMAP_OBJ_CIRCLE },
+ { OOO_STRING_SVTOOLS_HTML_SH_circle, IMAP_OBJ_CIRCLE },
+ { OOO_STRING_SVTOOLS_HTML_SH_poly, IMAP_OBJ_POLYGON },
+ { OOO_STRING_SVTOOLS_HTML_SH_polygon, IMAP_OBJ_POLYGON },
+ { 0, 0 }
+};
+
+SfxHTMLParser::SfxHTMLParser( SvStream& rStream, BOOL bIsNewDoc,
+ SfxMedium *pMed ) :
+ HTMLParser( rStream, bIsNewDoc ),
+ pMedium( pMed ), pDLMedium( 0 ),
+ nMetaTags( 0 )
+{
+ DBG_ASSERT( RTL_TEXTENCODING_DONTKNOW == GetSrcEncoding( ),
+ "SfxHTMLParser::SfxHTMLParser: Wo kommt der ZS her?" );
+ DBG_ASSERT( !IsSwitchToUCS2(),
+ "SfxHTMLParser::SfxHTMLParser: Switch to UCS2?" );
+
+ // Altough the real default encoding is ISO8859-1, we use MS-1252
+ // als default encoding.
+ SetSrcEncoding( GetExtendedCompatibilityTextEncoding( RTL_TEXTENCODING_ISO_8859_1 ) );
+
+ // If the file starts with a BOM, switch to UCS2.
+ SetSwitchToUCS2( TRUE );
+}
+
+__EXPORT SfxHTMLParser::~SfxHTMLParser()
+{
+ DBG_ASSERT( !pDLMedium, "Da ist ein File-Download stehengeblieben" );
+ delete pDLMedium;
+}
+
+BOOL SfxHTMLParser::ParseMapOptions(ImageMap * pImageMap,
+ const HTMLOptions * pOptions)
+{
+ DBG_ASSERT( pImageMap, "ParseMapOptions: keine Image-Map" );
+ DBG_ASSERT( pOptions, "ParseMapOptions: keine Optionen" );
+
+ String aName;
+
+ for( USHORT i=pOptions->Count(); i; )
+ {
+ const HTMLOption *pOption = (*pOptions)[--i];
+ switch( pOption->GetToken() )
+ {
+ case HTML_O_NAME:
+ aName = pOption->GetString();
+ break;
+ }
+ }
+
+ if( aName.Len() )
+ pImageMap->SetName( aName );
+
+ return aName.Len() > 0;
+}
+
+BOOL SfxHTMLParser::ParseAreaOptions(ImageMap * pImageMap, const String& rBaseURL,
+ const HTMLOptions * pOptions,
+ USHORT nEventMouseOver,
+ USHORT nEventMouseOut )
+{
+ DBG_ASSERT( pImageMap, "ParseAreaOptions: keine Image-Map" );
+ DBG_ASSERT( pOptions, "ParseAreaOptions: keine Optionen" );
+
+ USHORT nShape = IMAP_OBJ_RECTANGLE;
+ SvULongs aCoords;
+ String aName, aHRef, aAlt, aTarget, sEmpty;
+ BOOL bNoHRef = FALSE;
+ SvxMacroTableDtor aMacroTbl;
+
+ for( USHORT i=pOptions->Count(); i; )
+ {
+ USHORT nEvent = 0;
+ ScriptType eScrpType = STARBASIC;
+ const HTMLOption *pOption = (*pOptions)[--i];
+ switch( pOption->GetToken() )
+ {
+ case HTML_O_NAME:
+ aName = pOption->GetString();
+ break;
+ case HTML_O_SHAPE:
+ pOption->GetEnum( nShape, aAreaShapeOptEnums );
+ break;
+ case HTML_O_COORDS:
+ pOption->GetNumbers( aCoords, TRUE );
+ break;
+ case HTML_O_HREF:
+ aHRef = INetURLObject::GetAbsURL( rBaseURL, pOption->GetString() );
+ break;
+ case HTML_O_NOHREF:
+ bNoHRef = TRUE;
+ break;
+ case HTML_O_ALT:
+ aAlt = pOption->GetString();
+ break;
+ case HTML_O_TARGET:
+ aTarget = pOption->GetString();
+ break;
+
+ case HTML_O_ONMOUSEOVER:
+ eScrpType = JAVASCRIPT;
+ case HTML_O_SDONMOUSEOVER:
+ nEvent = nEventMouseOver;
+ goto IMAPOBJ_SETEVENT;
+
+ case HTML_O_ONMOUSEOUT:
+ eScrpType = JAVASCRIPT;
+ case HTML_O_SDONMOUSEOUT:
+ nEvent = nEventMouseOut;
+ goto IMAPOBJ_SETEVENT;
+IMAPOBJ_SETEVENT:
+ if( nEvent )
+ {
+ String sTmp( pOption->GetString() );
+ if( sTmp.Len() )
+ {
+ sTmp.ConvertLineEnd();
+ aMacroTbl.Insert( nEvent,
+ new SvxMacro( sTmp, sEmpty, eScrpType ));
+ }
+ }
+ break;
+ }
+ }
+
+ if( bNoHRef )
+ aHRef.Erase();
+
+ BOOL bNewArea = TRUE;
+ switch( nShape )
+ {
+ case IMAP_OBJ_RECTANGLE:
+ if( aCoords.Count() >=4 )
+ {
+ Rectangle aRec( aCoords[0], aCoords[1],
+ aCoords[2], aCoords[3] );
+ IMapRectangleObject aMapRObj( aRec, aHRef, aAlt, String(), aTarget, aName,
+ !bNoHRef );
+ if( aMacroTbl.Count() )
+ aMapRObj.SetMacroTable( aMacroTbl );
+ pImageMap->InsertIMapObject( aMapRObj );
+ }
+ break;
+ case IMAP_OBJ_CIRCLE:
+ if( aCoords.Count() >=3 )
+ {
+ Point aPoint( aCoords[0], aCoords[1] );
+ IMapCircleObject aMapCObj( aPoint, aCoords[2],aHRef, aAlt, String(),
+ aTarget, aName, !bNoHRef );
+ if( aMacroTbl.Count() )
+ aMapCObj.SetMacroTable( aMacroTbl );
+ pImageMap->InsertIMapObject( aMapCObj );
+ }
+ break;
+ case IMAP_OBJ_POLYGON:
+ if( aCoords.Count() >=6 )
+ {
+ USHORT nCount = aCoords.Count() / 2;
+ Polygon aPoly( nCount );
+ for( USHORT i=0; i<nCount; i++ )
+ aPoly[i] = Point( aCoords[2*i], aCoords[2*i+1] );
+ IMapPolygonObject aMapPObj( aPoly, aHRef, aAlt, String(), aTarget, aName,
+ !bNoHRef );
+ if( aMacroTbl.Count() )
+ aMapPObj.SetMacroTable( aMacroTbl );
+ pImageMap->InsertIMapObject( aMapPObj );
+ }
+ break;
+ default:
+ bNewArea = FALSE;
+ }
+
+ return bNewArea;
+}
+
+
+void SfxHTMLParser::StartFileDownload( const String& rURL, int nToken,
+ SfxObjectShell *pSh )
+{
+ DBG_ASSERT( !pDLMedium, "StartFileDwonload bei aktivem Download" );
+ if( pDLMedium )
+ return;
+
+ pDLMedium = new SfxMedium( rURL, SFX_STREAM_READONLY, FALSE );
+ if( pSh )
+ {
+ // Medium registrieren, damit abgebrochen werden kann
+ pSh->RegisterTransfer( *pDLMedium );
+
+ // Target-Frame uebertragen, damit auch javascript:-URLs
+ // "geladen" werden koennen.
+ //const SfxMedium *pShMedium = pSh->GetMedium();
+ //if( pShMedium )
+ // pDLMedium->SetLoadTargetFrame( pShMedium->GetLoadTargetFrame() );
+ }
+
+ // Download anstossen (Achtung: Kann auch synchron sein).
+ if ( TRUE /*pMedium->GetDoneLink() == Link()*/ )
+ pDLMedium->DownLoad();
+ else
+ {
+ // Downloading-Flag auf TRUE setzen. Es werden dann auch
+ // Data-Available-Links, wenn wir in den Pending-Staus gelangen.
+ SetDownloadingFile( TRUE );
+ pDLMedium->DownLoad( STATIC_LINK( this, SfxHTMLParser, FileDownloadDone ) );
+
+ // Wenn das Dowsnloading-Flag noch gesetzt ist erfolgt der Download
+ // asynchron. Wir gehen dann in den Pedning-Staus und warten dort.
+ // Solange sind alle Aufrufe des Data-Avaialble-Link gesperrt.
+ if( IsDownloadingFile() )
+ {
+ // Den aktuellen Zustand einfrieren und in den Pending-Status gehen.
+ // Wenn der Download beendet oder abgebrochen wurde, wird ueber
+ // NewDataRead ein Continue mit dem uebergeben Token angesteossen.
+ SaveState( nToken );
+ eState = SVPAR_PENDING;
+ }
+ }
+}
+
+BOOL SfxHTMLParser::GetFileDownloadMIME( String& rMIME )
+{
+ return pDLMedium && pDLMedium->GetErrorCode()==0 &&
+ pDLMedium->GetMIMEAndRedirect(rMIME)==0;
+}
+
+BOOL SfxHTMLParser::FinishFileDownload( String& rStr )
+{
+ String aStr;
+
+ BOOL bOK = pDLMedium && pDLMedium->GetErrorCode()==0;
+ if( bOK )
+ {
+ SvStream* pStream = pDLMedium->GetInStream();
+ DBG_ASSERT( pStream, "Kein In-Stream vom Medium erhalten" );
+
+ SvMemoryStream aStream;
+ if( pStream ) // HACK wegen #65563#
+ aStream << *pStream;
+
+ aStream.Seek( STREAM_SEEK_TO_END );
+ DBG_ASSERT( aStream.Tell() < STRING_MAXLEN,
+ "File zu lang fuer einen String, Ende abgeschnitten" );
+ xub_StrLen nLen = aStream.Tell() < STRING_MAXLEN
+ ? (xub_StrLen)aStream.Tell()
+ : STRING_MAXLEN;
+
+ // TODO: untested!!!
+ rtl_TextEncoding eEnc =
+ GetExtendedCompatibilityTextEncoding( RTL_TEXTENCODING_ISO_8859_1 );
+ String sMime;
+ if( pDLMedium->GetMIMEAndRedirect( sMime ) == 0 )
+ {
+ rtl_TextEncoding eMimeEnc = GetEncodingByMIME( sMime );
+ if( RTL_TEXTENCODING_DONTKNOW != eMimeEnc )
+ eEnc = eMimeEnc;
+ }
+
+ ByteString sBuffer;
+ sal_Char* pBuffer = sBuffer.AllocBuffer(nLen);
+ aStream.Seek( 0 );
+ aStream.Read((void*)pBuffer, nLen);
+ rStr = String( S2U(pBuffer) );
+ }
+
+ delete pDLMedium;
+ pDLMedium = 0;
+
+ return bOK;
+}
+
+IMPL_STATIC_LINK( SfxHTMLParser, FileDownloadDone, void*, EMPTYARG )
+{
+ // Der Download ist jetzt abgeschlossen. Ausserdem muss/darf der
+ // Data-Available-Link wieder durchgelassen werden.
+ pThis->SetDownloadingFile( FALSE );
+
+ // ... und einmal aufrufen, damit weitergelesen wird.
+ pThis->CallAsyncCallLink();
+
+ return 0;
+}
+
+void SfxHTMLParser::GetScriptType_Impl( SvKeyValueIterator *pHTTPHeader )
+{
+ aScriptType = DEFINE_CONST_UNICODE(SVX_MACRO_LANGUAGE_JAVASCRIPT);
+ eScriptType = JAVASCRIPT;
+ if( pHTTPHeader )
+ {
+ SvKeyValue aKV;
+ for( BOOL bCont = pHTTPHeader->GetFirst( aKV ); bCont;
+ bCont = pHTTPHeader->GetNext( aKV ) )
+ {
+ if( aKV.GetKey().EqualsIgnoreCaseAscii(
+ OOO_STRING_SVTOOLS_HTML_META_content_script_type ) )
+ {
+ if( aKV.GetValue().Len() )
+ {
+ String aTmp( aKV.GetValue() );
+ if( aTmp.EqualsIgnoreCaseAscii( sHTML_MIME_text, 0, 5 ) )
+ aTmp.Erase( 0, 5 );
+ else if( aTmp.EqualsIgnoreCaseAscii( sHTML_MIME_application,
+ 0, 12 ) )
+ aTmp.Erase( 0, 12 );
+ else
+ break;
+
+ if( aTmp.EqualsIgnoreCaseAscii( sHTML_MIME_experimental, 0,
+ 2 ) )
+ {
+ aTmp.Erase( 0, 2 );
+ }
+
+ if( aTmp.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_LG_starbasic ) )
+ {
+ eScriptType = STARBASIC;
+ aScriptType = DEFINE_CONST_UNICODE(SVX_MACRO_LANGUAGE_STARBASIC);
+ }
+ if( !aTmp.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_LG_javascript ) )
+ {
+ eScriptType = EXTENDED_STYPE;
+ aScriptType = aTmp;
+ }
+ }
+ break;
+ }
+ }
+ }
+}
+
+ScriptType SfxHTMLParser::GetScriptType( SvKeyValueIterator *pHTTPHeader ) const
+{
+ if( !aScriptType.Len() )
+ ((SfxHTMLParser *)this)->GetScriptType_Impl( pHTTPHeader );
+
+ return eScriptType;
+}
+
+const String& SfxHTMLParser::GetScriptTypeString(
+ SvKeyValueIterator *pHTTPHeader ) const
+{
+ if( !aScriptType.Len() )
+ ((SfxHTMLParser *)this)->GetScriptType_Impl( pHTTPHeader );
+
+ return aScriptType;
+}
+
+double SfxHTMLParser::GetTableDataOptionsValNum( sal_uInt32& nNumForm,
+ LanguageType& eNumLang, const String& aValStr, const String& aNumStr,
+ SvNumberFormatter& rFormatter )
+{
+ LanguageType eParseLang = (LanguageType )aNumStr.ToInt32();
+ sal_uInt32 nParseForm =
+ rFormatter.GetFormatForLanguageIfBuiltIn( 0, eParseLang );
+ double fVal;
+ rFormatter.IsNumberFormat( aValStr, nParseForm, fVal );
+ if ( aNumStr.GetTokenCount( ';' ) > 2 )
+ {
+ eNumLang = (LanguageType)aNumStr.GetToken( 1, ';' ).ToInt32();
+ xub_StrLen nPos = aNumStr.Search( ';' );
+ nPos = aNumStr.Search( ';', nPos + 1 );
+ String aFormat( aNumStr.Copy( nPos + 1 ) );
+ xub_StrLen nCheckPos;
+ short nType;
+ if ( eNumLang != LANGUAGE_SYSTEM )
+ rFormatter.PutEntry( aFormat, nCheckPos, nType, nNumForm, eNumLang );
+ else
+ rFormatter.PutandConvertEntry( aFormat, nCheckPos, nType, nNumForm,
+ eParseLang, eNumLang );
+ }
+ else
+ {
+ eNumLang = LANGUAGE_SYSTEM;
+ nNumForm = rFormatter.GetFormatForLanguageIfBuiltIn( 0, eNumLang );
+ }
+ return fVal;
+}
+
diff --git a/sfx2/source/bastyp/sfxresid.cxx b/sfx2/source/bastyp/sfxresid.cxx
new file mode 100644
index 000000000000..cf1cd983f76e
--- /dev/null
+++ b/sfx2/source/bastyp/sfxresid.cxx
@@ -0,0 +1,73 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+#include <tools/simplerm.hxx>
+
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/app.hxx>
+
+// -----------------------------------------------------------------------
+
+static ResMgr* pMgr=NULL;
+
+SfxResId::SfxResId( USHORT nId ) :
+
+ ResId( nId, *GetResMgr() )
+{
+}
+
+//============================================================================
+//
+// SfxSimpleResId Implementation.
+//
+//============================================================================
+
+SfxSimpleResId::SfxSimpleResId(USHORT nID):
+ m_sText( SFX_APP()->GetSimpleResManager()->ReadString(nID) )
+{}
+
+ResMgr* SfxResId::GetResMgr()
+{
+ if ( !pMgr )
+ {
+ pMgr = SfxApplication::CreateResManager("sfx");
+ }
+
+ return pMgr;
+}
+
+void SfxResId::DeleteResMgr()
+{
+ DELETEZ( pMgr );
+}
+
+
diff --git a/sfx2/source/config/config.hrc b/sfx2/source/config/config.hrc
new file mode 100644
index 000000000000..582a2972f913
--- /dev/null
+++ b/sfx2/source/config/config.hrc
@@ -0,0 +1,41 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_CONFIG_HRC
+#define _SFX_CONFIG_HRC
+
+#include <sfx2/sfx.hrc>
+
+// #defines *****************************************************************
+
+#define BTN_OK 2
+#define BTN_CANCEL 3
+#define FT_OK 4
+#define FT_CANCEL 5
+
+#endif
+
diff --git a/sfx2/source/config/config.src b/sfx2/source/config/config.src
new file mode 100644
index 000000000000..cb3259e09ad0
--- /dev/null
+++ b/sfx2/source/config/config.src
@@ -0,0 +1,35 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+//#include "config.hrc"
+//#include "sfxlocal.hrc"
+#include <sfx2/sfx.hrc>
+
+String STR_FILTERNAME_CFG
+{
+ Text [ en-US ] = "Configuration" ;
+};
diff --git a/sfx2/source/config/evntconf.cxx b/sfx2/source/config/evntconf.cxx
new file mode 100644
index 000000000000..185ec0626c51
--- /dev/null
+++ b/sfx2/source/config/evntconf.cxx
@@ -0,0 +1,294 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <vcl/msgbox.hxx>
+#include <tools/resary.hxx>
+#include <svl/lstner.hxx>
+#include <basic/basmgr.hxx>
+#include <basic/sbmod.hxx>
+#include <tools/urlobj.hxx>
+#include <basic/sbx.hxx>
+ #include <sot/storage.hxx>
+#include <unotools/securityoptions.hxx>
+
+#include <rtl/ustring.h>
+#include <com/sun/star/uno/Any.hxx>
+#include <framework/eventsconfiguration.hxx>
+#include <comphelper/processfactory.hxx>
+#include <sfx2/evntconf.hxx>
+#include <sfx2/macrconf.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/dispatch.hxx>
+#include "config.hrc"
+#include "sfx2/sfxresid.hxx"
+#include "eventsupplier.hxx"
+
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/container/XNameReplace.hpp>
+#include <com/sun/star/document/XEventsSupplier.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+
+// -----------------------------------------------------------------------
+TYPEINIT1(SfxEventHint, SfxHint);
+TYPEINIT1(SfxEventNamesItem, SfxPoolItem);
+TYPEINIT1(SfxViewEventHint, SfxHint);
+
+using namespace com::sun::star;
+
+SfxEventNamesList& SfxEventNamesList::operator=( const SfxEventNamesList& rTbl )
+{
+ DelDtor();
+ for (USHORT n=0; n<rTbl.Count(); n++ )
+ {
+ SfxEventName* pTmp = ((SfxEventNamesList&)rTbl).GetObject(n);
+ SfxEventName *pNew = new SfxEventName( *pTmp );
+ Insert( pNew, n );
+ }
+ return *this;
+}
+
+void SfxEventNamesList::DelDtor()
+{
+ SfxEventName* pTmp = First();
+ while( pTmp )
+ {
+ delete pTmp;
+ pTmp = Next();
+ }
+ Clear();
+}
+
+int SfxEventNamesItem::operator==( const SfxPoolItem& rAttr ) const
+{
+ DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
+
+ const SfxEventNamesList& rOwn = aEventsList;
+ const SfxEventNamesList& rOther = ( (SfxEventNamesItem&) rAttr ).aEventsList;
+
+ if ( rOwn.Count() != rOther.Count() )
+ return FALSE;
+
+ for ( USHORT nNo = 0; nNo < rOwn.Count(); ++nNo )
+ {
+ const SfxEventName *pOwn = rOwn.GetObject(nNo);
+ const SfxEventName *pOther = rOther.GetObject(nNo);
+ if ( pOwn->mnId != pOther->mnId ||
+ pOwn->maEventName != pOther->maEventName ||
+ pOwn->maUIName != pOther->maUIName )
+ return FALSE;
+ }
+
+ return TRUE;
+
+}
+
+SfxItemPresentation SfxEventNamesItem::GetPresentation( SfxItemPresentation,
+ SfxMapUnit,
+ SfxMapUnit,
+ XubString &rText,
+ const IntlWrapper* ) const
+{
+ rText.Erase();
+ return SFX_ITEM_PRESENTATION_NONE;
+}
+
+SfxPoolItem* SfxEventNamesItem::Clone( SfxItemPool *) const
+{
+ return new SfxEventNamesItem(*this);
+}
+
+SfxPoolItem* SfxEventNamesItem::Create(SvStream &, USHORT) const
+{
+ DBG_ERROR("not streamable!");
+ return new SfxEventNamesItem(Which());
+}
+
+SvStream& SfxEventNamesItem::Store(SvStream &rStream, USHORT ) const
+{
+ DBG_ERROR("not streamable!");
+ return rStream;
+}
+
+USHORT SfxEventNamesItem::GetVersion( USHORT ) const
+{
+ DBG_ERROR("not streamable!");
+ return 0;
+}
+
+void SfxEventNamesItem::AddEvent( const String& rName, const String& rUIName, USHORT nID )
+{
+ aEventsList.Insert( new SfxEventName( nID, rName, rUIName.Len() ? rUIName : rName ) );
+}
+
+
+//==========================================================================
+
+//--------------------------------------------------------------------------
+uno::Any CreateEventData_Impl( const SvxMacro *pMacro )
+{
+/*
+ This function converts a SvxMacro into an Any containing three
+ properties. These properties are EventType and Script. Possible
+ values for EventType ar StarBasic, JavaScript, ...
+ The Script property should contain the URL to the macro and looks
+ like "macro://./standard.module1.main()"
+
+ If pMacro is NULL, we return an empty property sequence, so PropagateEvent_Impl
+ can delete an event binding.
+*/
+ uno::Any aEventData;
+
+ if ( pMacro )
+ {
+ if ( pMacro->GetScriptType() == STARBASIC )
+ {
+ uno::Sequence < beans::PropertyValue > aProperties(3);
+ beans::PropertyValue *pValues = aProperties.getArray();
+
+ ::rtl::OUString aType = ::rtl::OUString::createFromAscii( STAR_BASIC );;
+ ::rtl::OUString aLib = pMacro->GetLibName();
+ ::rtl::OUString aMacro = pMacro->GetMacName();
+
+ pValues[ 0 ].Name = ::rtl::OUString::createFromAscii( PROP_EVENT_TYPE );
+ pValues[ 0 ].Value <<= aType;
+
+ pValues[ 1 ].Name = ::rtl::OUString::createFromAscii( PROP_LIBRARY );
+ pValues[ 1 ].Value <<= aLib;
+
+ pValues[ 2 ].Name = ::rtl::OUString::createFromAscii( PROP_MACRO_NAME );
+ pValues[ 2 ].Value <<= aMacro;
+
+ aEventData <<= aProperties;
+ }
+ else if ( pMacro->GetScriptType() == EXTENDED_STYPE )
+ {
+ uno::Sequence < beans::PropertyValue > aProperties(2);
+ beans::PropertyValue *pValues = aProperties.getArray();
+
+ ::rtl::OUString aLib = pMacro->GetLibName();
+ ::rtl::OUString aMacro = pMacro->GetMacName();
+
+ pValues[ 0 ].Name = ::rtl::OUString::createFromAscii( PROP_EVENT_TYPE );
+ pValues[ 0 ].Value <<= aLib;
+
+ pValues[ 1 ].Name = ::rtl::OUString::createFromAscii( PROP_SCRIPT );
+ pValues[ 1 ].Value <<= aMacro;
+
+ aEventData <<= aProperties;
+ }
+ else if ( pMacro->GetScriptType() == JAVASCRIPT )
+ {
+ uno::Sequence < beans::PropertyValue > aProperties(2);
+ beans::PropertyValue *pValues = aProperties.getArray();
+
+ ::rtl::OUString aMacro = pMacro->GetMacName();
+
+ pValues[ 0 ].Name = ::rtl::OUString::createFromAscii( PROP_EVENT_TYPE );
+ pValues[ 0 ].Value <<= ::rtl::OUString::createFromAscii(SVX_MACRO_LANGUAGE_JAVASCRIPT);
+
+ pValues[ 1 ].Name = ::rtl::OUString::createFromAscii( PROP_MACRO_NAME );
+ pValues[ 1 ].Value <<= aMacro;
+
+ aEventData <<= aProperties;
+ }
+ else
+ {
+ DBG_ERRORFILE( "CreateEventData_Impl(): ScriptType not supported!");
+ }
+ }
+ else
+ {
+ uno::Sequence < beans::PropertyValue > aProperties;
+ aEventData <<= aProperties;
+ }
+
+ return aEventData;
+}
+
+//--------------------------------------------------------------------------
+void PropagateEvent_Impl( SfxObjectShell *pDoc, rtl::OUString aEventName, const SvxMacro* pMacro )
+{
+ uno::Reference < document::XEventsSupplier > xSupplier;
+ if ( pDoc )
+ {
+ xSupplier = uno::Reference < document::XEventsSupplier >( pDoc->GetModel(), uno::UNO_QUERY );
+ }
+ else
+ {
+ xSupplier = uno::Reference < document::XEventsSupplier >
+ ( ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString::createFromAscii("com.sun.star.frame.GlobalEventBroadcaster" )), uno::UNO_QUERY );
+ }
+
+ if ( xSupplier.is() )
+ {
+ uno::Reference < container::XNameReplace > xEvents = xSupplier->getEvents();
+ if ( aEventName.getLength() )
+ {
+ uno::Any aEventData = CreateEventData_Impl( pMacro );
+
+ try
+ {
+ xEvents->replaceByName( aEventName, aEventData );
+ }
+ catch( ::com::sun::star::lang::IllegalArgumentException )
+ { DBG_ERRORFILE( "PropagateEvents_Impl: caught IllegalArgumentException" ); }
+ catch( ::com::sun::star::container::NoSuchElementException )
+ { DBG_ERRORFILE( "PropagateEvents_Impl: caught NoSuchElementException" ); }
+ }
+ else {
+ DBG_WARNING( "PropagateEvents_Impl: Got unkown event" );
+ }
+ }
+}
+
+//--------------------------------------------------------------------------------------------------------
+void SfxEventConfiguration::ConfigureEvent( rtl::OUString aName, const SvxMacro& rMacro, SfxObjectShell *pDoc )
+{
+ SvxMacro *pMacro = NULL;
+ if ( rMacro.GetMacName().Len() )
+ pMacro = new SvxMacro( rMacro.GetMacName(), rMacro.GetLibName(), rMacro.GetScriptType() );
+ if ( pDoc )
+ {
+ PropagateEvent_Impl( pDoc, aName, pMacro );
+ }
+ else
+ {
+ PropagateEvent_Impl( NULL, aName, pMacro );
+ }
+}
+
+// -------------------------------------------------------------------------------------------------------
+SvxMacro* SfxEventConfiguration::ConvertToMacro( const com::sun::star::uno::Any& rElement, SfxObjectShell* pDoc, BOOL bBlowUp )
+{
+ return SfxEvents_Impl::ConvertToMacro( rElement, pDoc, bBlowUp );
+}
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
new file mode 100644
index 000000000000..40f6346de8ee
--- /dev/null
+++ b/sfx2/source/control/bindings.cxx
@@ -0,0 +1,2433 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <hash_map>
+#include <svl/itempool.hxx>
+#include <svl/itemiter.hxx>
+#include <svl/eitem.hxx>
+#include <svl/aeitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/visitem.hxx>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XStatusListener.hpp>
+#include <com/sun/star/frame/FrameSearchFlag.hpp>
+#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
+#include <com/sun/star/frame/FeatureStateEvent.hpp>
+#include <com/sun/star/frame/DispatchDescriptor.hpp>
+#include <com/sun/star/frame/XController.hpp>
+#include <comphelper/processfactory.hxx>
+#include <svtools/itemdel.hxx>
+
+#ifndef GCC
+#endif
+
+// wg. nInReschedule
+#include "appdata.hxx"
+#include <sfx2/bindings.hxx>
+#include <sfx2/msg.hxx>
+#include "statcach.hxx"
+#include <sfx2/ctrlitem.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/objface.hxx>
+#include "sfxtypes.hxx"
+#include "workwin.hxx"
+#include <sfx2/macrconf.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/sfx.hrc>
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/msgpool.hxx>
+
+#include <comphelper/uieventslogger.hxx>
+#include <com/sun/star/frame/XModuleManager.hpp>
+
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+
+DBG_NAME(SfxBindingsMsgPos)
+DBG_NAME(SfxBindingsUpdateServers)
+DBG_NAME(SfxBindingsCreateSet)
+DBG_NAME(SfxBindingsUpdateCtrl1)
+DBG_NAME(SfxBindingsUpdateCtrl2)
+DBG_NAME(SfxBindingsNextJob_Impl0)
+DBG_NAME(SfxBindingsNextJob_Impl)
+DBG_NAME(SfxBindingsUpdate_Impl)
+DBG_NAME(SfxBindingsInvalidateAll)
+
+//====================================================================
+
+static USHORT nTimeOut = 300;
+
+#define TIMEOUT_FIRST nTimeOut
+#define TIMEOUT_UPDATING 20
+#define TIMEOUT_IDLE 2500
+
+static sal_uInt32 nCache1 = 0;
+static sal_uInt32 nCache2 = 0;
+
+typedef std::hash_map< USHORT, bool > InvalidateSlotMap;
+
+//====================================================================
+
+DECL_PTRARRAY(SfxStateCacheArr_Impl, SfxStateCache*, 32, 16)
+
+//====================================================================
+
+class SfxAsyncExec_Impl
+{
+ ::com::sun::star::util::URL aCommand;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp;
+ Timer aTimer;
+
+public:
+
+ SfxAsyncExec_Impl( const ::com::sun::star::util::URL& rCmd, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDisp )
+ : aCommand( rCmd )
+ , xDisp( rDisp )
+ {
+ aTimer.SetTimeoutHdl( LINK(this, SfxAsyncExec_Impl, TimerHdl) );
+ aTimer.SetTimeout( 0 );
+ aTimer.Start();
+ }
+
+ DECL_LINK( TimerHdl, Timer*);
+};
+
+IMPL_LINK(SfxAsyncExec_Impl, TimerHdl, Timer*, pTimer)
+{
+ (void)pTimer; // unused
+ aTimer.Stop();
+
+ Sequence<beans::PropertyValue> aSeq;
+ xDisp->dispatch( aCommand, aSeq );
+
+ delete this;
+ return 0L;
+}
+
+class SfxBindings_Impl
+{
+public:
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchRecorder > xRecorder;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > xProv;
+ SfxUnoControllerArr_Impl*
+ pUnoCtrlArr;
+ SfxWorkWindow* pWorkWin;
+ SfxBindings* pSubBindings;
+ SfxBindings* pSuperBindings;
+ SfxStateCacheArr_Impl* pCaches; // je ein cache fuer jede gebundene
+ sal_uInt16 nCachedFunc1; // index der zuletzt gerufenen
+ sal_uInt16 nCachedFunc2; // index der vorletzt gerufenen
+ sal_uInt16 nMsgPos; // Message-Position, ab der zu aktualisieren ist
+ SfxPopupAction ePopupAction; // in DeleteFloatinWindow() abgefragt
+ sal_Bool bContextChanged;
+ sal_Bool bMsgDirty; // wurde ein MessageServer invalidiert?
+ sal_Bool bAllMsgDirty; // wurden die MessageServer invalidiert?
+ sal_Bool bAllDirty; // nach InvalidateAll
+ sal_Bool bCtrlReleased; // waehrend EnterRegistrations
+ AutoTimer aTimer; // fuer volatile Slots
+ sal_Bool bInUpdate; // fuer Assertions
+ sal_Bool bInNextJob; // fuer Assertions
+ sal_Bool bFirstRound; // Erste Runde im Update
+ sal_uInt16 nFirstShell; // Shell, die in erster Runde bevorzugt wird
+ sal_uInt16 nOwnRegLevel; // z"ahlt die echten Locks, ohne die der SuperBindings
+ InvalidateSlotMap m_aInvalidateSlots; // store slots which are invalidated while in update
+};
+
+//--------------------------------------------------------------------
+
+struct SfxFoundCache_Impl
+{
+ sal_uInt16 nSlotId; // die Slot-Id
+ sal_uInt16 nWhichId; // falls verf"ugbar die Which-Id, sonst nSlotId
+ const SfxSlot* pSlot; // Pointer auf den <Master-Slot>
+ SfxStateCache* pCache; // Pointer auf den StatusCache, ggf. 0
+
+ SfxFoundCache_Impl():
+ nSlotId(0),
+ nWhichId(0),
+ pSlot(0),
+ pCache(0)
+ {}
+
+ SfxFoundCache_Impl(SfxFoundCache_Impl&r):
+ nSlotId(r.nSlotId),
+ nWhichId(r.nWhichId),
+ pSlot(r.pSlot),
+ pCache(r.pCache)
+ {}
+
+ SfxFoundCache_Impl(sal_uInt16 nS, sal_uInt16 nW, const SfxSlot *pS, SfxStateCache *pC ):
+ nSlotId(nS),
+ nWhichId(nW),
+ pSlot(pS),
+ pCache(pC)
+ {}
+
+ int operator<( const SfxFoundCache_Impl &r ) const
+ { return nWhichId < r.nWhichId; }
+
+ int operator==( const SfxFoundCache_Impl &r ) const
+ { return nWhichId== r.nWhichId; }
+};
+
+//--------------------------------------------------------------------------
+
+SV_DECL_PTRARR_SORT_DEL(SfxFoundCacheArr_Impl, SfxFoundCache_Impl*, 16, 16 )
+SV_IMPL_OP_PTRARR_SORT(SfxFoundCacheArr_Impl, SfxFoundCache_Impl*);
+
+//==========================================================================
+
+SfxBindings::SfxBindings()
+: pImp(new SfxBindings_Impl),
+ pDispatcher(0),
+ nRegLevel(1) // geht erst auf 0, wenn Dispatcher gesetzt
+{
+ pImp->nMsgPos = 0;
+ pImp->bAllMsgDirty = sal_True;
+ pImp->bContextChanged = sal_False;
+ pImp->bMsgDirty = sal_True;
+ pImp->bAllDirty = sal_True;
+ pImp->ePopupAction = SFX_POPUP_DELETE;
+ pImp->nCachedFunc1 = 0;
+ pImp->nCachedFunc2 = 0;
+ pImp->bCtrlReleased = sal_False;
+ pImp->bFirstRound = sal_False;
+ pImp->bInNextJob = sal_False;
+ pImp->bInUpdate = sal_False;
+ pImp->pSubBindings = NULL;
+ pImp->pSuperBindings = NULL;
+ pImp->pWorkWin = NULL;
+ pImp->pUnoCtrlArr = NULL;
+ pImp->nOwnRegLevel = nRegLevel;
+
+ // all caches are valid (no pending invalidate-job)
+ // create the list of caches
+ pImp->pCaches = new SfxStateCacheArr_Impl;
+ pImp->aTimer.SetTimeoutHdl( LINK(this, SfxBindings, NextJob_Impl) );
+}
+
+//====================================================================
+
+SfxBindings::~SfxBindings()
+
+/* [Beschreibung]
+
+ Destruktor der Klasse SfxBindings. Die eine, f"ur jede <SfxApplication>
+ existierende Instanz wird von der <SfxApplication> nach Ausf"urhung
+ von <SfxApplication::Exit()> automatisch zerst"ort.
+
+ Noch existierende <SfxControllerItem> Instanzen, die bei dieser
+ SfxBindings Instanz angemeldet sind, werden im Destruktor
+ automatisch zerst"ort. Dies sind i.d.R. Floating-Toolboxen, Value-Sets
+ etc. Arrays von SfxControllerItems d"urfen zu diesem Zeitpunkt nicht
+ mehr exisitieren.
+*/
+
+{
+ // Die SubBindings sollen ja nicht gelocked werden !
+ pImp->pSubBindings = NULL;
+
+ ENTERREGISTRATIONS();
+
+ pImp->aTimer.Stop();
+ DeleteControllers_Impl();
+
+ // Caches selbst l"oschen
+ sal_uInt16 nCount = pImp->pCaches->Count();
+ for ( sal_uInt16 nCache = 0; nCache < nCount; ++nCache )
+ delete pImp->pCaches->GetObject(nCache);
+
+ DELETEZ( pImp->pWorkWin );
+
+ delete pImp->pCaches;
+ delete pImp;
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::DeleteControllers_Impl()
+{
+ // in der ersten Runde den SfxPopupWindows l"oschen
+ sal_uInt16 nCount = pImp->pCaches->Count();
+ sal_uInt16 nCache;
+ for ( nCache = 0; nCache < nCount; ++nCache )
+ {
+ // merken wo man ist
+ SfxStateCache *pCache = pImp->pCaches->GetObject(nCache);
+ sal_uInt16 nSlotId = pCache->GetId();
+
+ // SfxPopupWindow l"oschen lassen
+ pCache->DeleteFloatingWindows();
+
+ // da der Cache verkleinert worden sein kann, wiederaufsetzen
+ sal_uInt16 nNewCount = pImp->pCaches->Count();
+ if ( nNewCount < nCount )
+ {
+ nCache = GetSlotPos(nSlotId);
+ if ( nCache >= nNewCount ||
+ nSlotId != pImp->pCaches->GetObject(nCache)->GetId() )
+ --nCache;
+ nCount = nNewCount;
+ }
+ }
+
+ // alle Caches l"oschen
+ for ( nCache = pImp->pCaches->Count(); nCache > 0; --nCache )
+ {
+ // Cache via ::com::sun::star::sdbcx::Index besorgen
+ SfxStateCache *pCache = pImp->pCaches->GetObject(nCache-1);
+
+ // alle Controller in dem Cache unbinden
+ SfxControllerItem *pNext;
+ for ( SfxControllerItem *pCtrl = pCache->GetItemLink();
+ pCtrl; pCtrl = pNext )
+ {
+ pNext = pCtrl->GetItemLink();
+ pCtrl->UnBind();
+ }
+
+ if ( pCache->GetInternalController() )
+ pCache->GetInternalController()->UnBind();
+
+ // Cache l"oschen
+ if( nCache-1 < pImp->pCaches->Count() )
+ delete (*pImp->pCaches)[nCache-1];
+ pImp->pCaches->Remove(nCache-1, 1);
+ }
+
+ if( pImp->pUnoCtrlArr )
+ {
+ sal_uInt16 nCtrlCount = pImp->pUnoCtrlArr->Count();
+ for ( sal_uInt16 n=nCtrlCount; n>0; n-- )
+ {
+ SfxUnoControllerItem *pCtrl = (*pImp->pUnoCtrlArr)[n-1];
+ pCtrl->ReleaseBindings();
+ }
+
+ DBG_ASSERT( !pImp->pUnoCtrlArr->Count(), "UnoControllerItems nicht entfernt!" );
+ DELETEZ( pImp->pUnoCtrlArr );
+ }
+}
+
+//--------------------------------------------------------------------
+
+SfxPopupAction SfxBindings::GetPopupAction_Impl() const
+{
+ return pImp->ePopupAction;
+}
+
+
+//--------------------------------------------------------------------
+
+void SfxBindings::HidePopups( bool bHide )
+{
+ // SfxPopupWindows hiden
+ HidePopupCtrls_Impl( bHide );
+ SfxBindings *pSub = pImp->pSubBindings;
+ while ( pSub )
+ {
+ pImp->pSubBindings->HidePopupCtrls_Impl( bHide );
+ pSub = pSub->pImp->pSubBindings;
+ }
+
+ // SfxChildWindows hiden
+ DBG_ASSERT( pDispatcher, "HidePopups not allowed without dispatcher" );
+ if ( pImp->pWorkWin )
+ pImp->pWorkWin->HidePopups_Impl( bHide, sal_True );
+}
+
+void SfxBindings::HidePopupCtrls_Impl( FASTBOOL bHide )
+{
+ if ( bHide )
+ {
+ // SfxPopupWindows hiden
+ pImp->ePopupAction = SFX_POPUP_HIDE;
+ }
+ else
+ {
+ // SfxPopupWindows showen
+ pImp->ePopupAction = SFX_POPUP_SHOW;
+ }
+
+ for ( sal_uInt16 nCache = 0; nCache < pImp->pCaches->Count(); ++nCache )
+ pImp->pCaches->GetObject(nCache)->DeleteFloatingWindows();
+ pImp->ePopupAction = SFX_POPUP_DELETE;
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::Update_Impl
+(
+ SfxStateCache* pCache // der upzudatende SfxStatusCache
+)
+{
+ if( pCache->GetDispatch().is() && pCache->GetItemLink() )
+ {
+ pCache->SetCachedState(TRUE);
+ if ( !pCache->GetInternalController() )
+ return;
+ }
+
+ if ( !pDispatcher )
+ return;
+ DBG_PROFSTART(SfxBindingsUpdate_Impl);
+
+ // alle mit derselben Statusmethode zusammensammeln, die dirty sind
+ SfxDispatcher &rDispat = *pDispatcher;
+ const SfxSlot *pRealSlot = 0;
+ const SfxSlotServer* pMsgServer = 0;
+ SfxFoundCacheArr_Impl aFound;
+ SfxItemSet *pSet = CreateSet_Impl( pCache, pRealSlot, &pMsgServer, aFound );
+ sal_Bool bUpdated = sal_False;
+ if ( pSet )
+ {
+ // Status erfragen
+ if ( rDispat._FillState( *pMsgServer, *pSet, pRealSlot ) )
+ {
+ // Status posten
+ const SfxInterface *pInterface =
+ rDispat.GetShell(pMsgServer->GetShellLevel())->GetInterface();
+ for ( sal_uInt16 nPos = 0; nPos < aFound.Count(); ++nPos )
+ {
+ const SfxFoundCache_Impl *pFound = aFound[nPos];
+ sal_uInt16 nWhich = pFound->nWhichId;
+ const SfxPoolItem *pItem = 0;
+ SfxItemState eState = pSet->GetItemState(nWhich, sal_True, &pItem);
+ if ( eState == SFX_ITEM_DEFAULT && SfxItemPool::IsWhich(nWhich) )
+ pItem = &pSet->Get(nWhich);
+ UpdateControllers_Impl( pInterface, aFound[nPos], pItem, eState );
+ }
+ bUpdated = sal_True;
+ }
+
+ delete pSet;
+ }
+
+ if ( !bUpdated && pCache )
+ {
+ // Wenn pCache == NULL und kein SlotServer ( z.B. weil Dispatcher gelockt! ),
+ // darf nat"urlich kein Update versucht werden
+ SfxFoundCache_Impl aFoundCache(
+ pCache->GetId(), 0,
+ pRealSlot, pCache );
+ UpdateControllers_Impl( 0, &aFoundCache, 0, SFX_ITEM_DISABLED);
+ }
+
+ DBG_PROFSTOP(SfxBindingsUpdate_Impl);
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::InvalidateSlotsInMap_Impl()
+{
+ InvalidateSlotMap::const_iterator pIter = pImp->m_aInvalidateSlots.begin();
+ while ( pIter != pImp->m_aInvalidateSlots.end() )
+ {
+ Invalidate( pIter->first );
+ ++pIter;
+ }
+ pImp->m_aInvalidateSlots.clear();
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::AddSlotToInvalidateSlotsMap_Impl( USHORT nId )
+{
+ pImp->m_aInvalidateSlots[nId] = sal_True;
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::Update
+(
+ sal_uInt16 nId // die gebundene und upzudatende Slot-Id
+)
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+
+//!!TLX: Fuehrte zu Vorlagenkatalogstillstand
+// if ( nRegLevel )
+// return;
+
+ if ( pDispatcher )
+ pDispatcher->Flush();
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->Update( nId );
+
+ SfxStateCache* pCache = GetStateCache( nId );
+ if ( pCache )
+ {
+ pImp->bInUpdate = sal_True;
+ if ( pImp->bMsgDirty )
+ {
+ UpdateSlotServer_Impl();
+ pCache = GetStateCache( nId );
+ }
+
+ if (pCache)
+ {
+ BOOL bInternalUpdate = TRUE;
+ if( pCache->GetDispatch().is() && pCache->GetItemLink() )
+ {
+ pCache->SetCachedState(TRUE);
+ bInternalUpdate = ( pCache->GetInternalController() != 0 );
+ }
+
+ if ( bInternalUpdate )
+ {
+ // Status erfragen
+ const SfxSlotServer* pMsgServer = pCache->GetSlotServer(*pDispatcher, pImp->xProv);
+ if ( !pCache->IsControllerDirty() &&
+ ( !pMsgServer ||
+ !pMsgServer->GetSlot()->IsMode(SFX_SLOT_VOLATILE) ) )
+ {
+ pImp->bInUpdate = sal_False;
+ InvalidateSlotsInMap_Impl();
+ return;
+ }
+ if (!pMsgServer)
+ {
+ pCache->SetState(SFX_ITEM_DISABLED, 0);
+ pImp->bInUpdate = sal_False;
+ InvalidateSlotsInMap_Impl();
+ return;
+ }
+
+ Update_Impl(pCache);
+ }
+
+ pImp->bAllDirty = sal_False;
+ }
+
+ pImp->bInUpdate = sal_False;
+ InvalidateSlotsInMap_Impl();
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::Update()
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->Update();
+
+ if ( pDispatcher )
+ {
+ if ( nRegLevel )
+ return;
+
+ pImp->bInUpdate = sal_True;
+ pDispatcher->Flush();
+ pDispatcher->Update_Impl();
+ while ( !NextJob_Impl(0) )
+ ; // loop
+ pImp->bInUpdate = sal_False;
+ InvalidateSlotsInMap_Impl();
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::SetState
+(
+ const SfxItemSet& rSet // zu setzende Status-Werte
+)
+{
+ // wenn gelockt, dann nur invalidieren
+ if ( nRegLevel )
+ {
+ SfxItemIter aIter(rSet);
+ for ( const SfxPoolItem *pItem = aIter.FirstItem();
+ pItem;
+ pItem = aIter.NextItem() )
+ Invalidate( pItem->Which() );
+ }
+ else
+ {
+ // Status d"urfen nur angenommen werden, wenn alle Slot-Pointer gesetzt sind
+ if ( pImp->bMsgDirty )
+ UpdateSlotServer_Impl();
+
+ // "uber das ItemSet iterieren, falls Slot gebunden, updaten
+ //! Bug: WhichIter verwenden und ggf. VoidItems hochschicken
+ SfxItemIter aIter(rSet);
+ for ( const SfxPoolItem *pItem = aIter.FirstItem();
+ pItem;
+ pItem = aIter.NextItem() )
+ {
+ SfxStateCache* pCache =
+ GetStateCache( rSet.GetPool()->GetSlotId(pItem->Which()) );
+ if ( pCache )
+ {
+ // Status updaten
+ if ( !pCache->IsControllerDirty() )
+ pCache->Invalidate(sal_False);
+ pCache->SetState( SFX_ITEM_AVAILABLE, pItem );
+
+ //! nicht implementiert: Updates von EnumSlots via MasterSlots
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::SetState
+(
+ const SfxPoolItem& rItem // zu setzender Status-Wert
+)
+{
+ if ( nRegLevel )
+ {
+ Invalidate( rItem.Which() );
+ }
+ else
+ {
+ // Status d"urfen nur angenommen werden, wenn alle Slot-Pointer gesetzt sind
+ if ( pImp->bMsgDirty )
+ UpdateSlotServer_Impl();
+
+ // falls der Slot gebunden ist, updaten
+ DBG_ASSERT( SfxItemPool::IsSlot( rItem.Which() ),
+ "cannot set items with which-id" );
+ SfxStateCache* pCache = GetStateCache( rItem.Which() );
+ if ( pCache )
+ {
+ // Status updaten
+ if ( !pCache->IsControllerDirty() )
+ pCache->Invalidate(sal_False);
+ pCache->SetState( SFX_ITEM_AVAILABLE, &rItem );
+
+ //! nicht implementiert: Updates von EnumSlots via MasterSlots
+ }
+ }
+}
+
+
+//--------------------------------------------------------------------
+
+SfxStateCache* SfxBindings::GetAnyStateCache_Impl( sal_uInt16 nId )
+{
+ SfxStateCache* pCache = GetStateCache( nId );
+ if ( !pCache && pImp->pSubBindings )
+ return pImp->pSubBindings->GetAnyStateCache_Impl( nId );
+ return pCache;
+}
+
+SfxStateCache* SfxBindings::GetStateCache
+(
+ sal_uInt16 nId /* Slot-Id, deren SfxStatusCache gefunden
+ werden soll */,
+ sal_uInt16* pPos /* 0 bzw. Position, ab der die Bindings
+ bin"ar durchsucht werden sollen. Liefert
+ die Position zur"uck, an der nId gefunden
+ wurde, bzw. an der es einfef"ugt werden
+ w"urde. */
+)
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+ // is the specified function bound?
+ const sal_uInt16 nStart = ( pPos ? *pPos : 0 );
+ const sal_uInt16 nPos = GetSlotPos( nId, nStart );
+
+ if ( nPos < pImp->pCaches->Count() &&
+ (*pImp->pCaches)[nPos]->GetId() == nId )
+ {
+ if ( pPos )
+ *pPos = nPos;
+ return (*pImp->pCaches)[nPos];
+ }
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::InvalidateAll
+(
+ sal_Bool bWithMsg /* sal_True
+ Slot-Server als ung"ultig markieren
+
+ sal_False
+ Slot-Server bleiben g"ultig */
+)
+{
+ DBG_PROFSTART(SfxBindingsInvalidateAll);
+ DBG_ASSERT( !pImp->bInUpdate, "SfxBindings::Invalidate while in update" );
+
+ DBG_MEMTEST();
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->InvalidateAll( bWithMsg );
+
+ // ist schon alles dirty gesetzt oder downing => nicht zu tun
+ if ( !pDispatcher ||
+ ( pImp->bAllDirty && ( !bWithMsg || pImp->bAllMsgDirty ) ) ||
+ SFX_APP()->IsDowning() )
+ {
+ DBG_PROFSTOP(SfxBindingsInvalidateAll);
+ return;
+ }
+
+ pImp->bAllMsgDirty = pImp->bAllMsgDirty || bWithMsg;
+ pImp->bMsgDirty = pImp->bMsgDirty || pImp->bAllMsgDirty || bWithMsg;
+ pImp->bAllDirty = sal_True;
+
+ for ( sal_uInt16 n = 0; n < pImp->pCaches->Count(); ++n )
+ pImp->pCaches->GetObject(n)->Invalidate(bWithMsg);
+/*
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame
+ ( pDispatcher->GetFrame()->GetFrame().GetFrameInterface(), UNO_QUERY );
+
+ if ( bWithMsg && xFrame.is() )
+ xFrame->contextChanged();
+*/
+ pImp->nMsgPos = 0;
+ if ( !nRegLevel )
+ {
+ pImp->aTimer.Stop();
+ pImp->aTimer.SetTimeout(TIMEOUT_FIRST);
+ pImp->aTimer.Start();
+// pImp->bFirstRound = sal_True;
+// pImp->nFirstShell = 0;
+ }
+
+ DBG_PROFSTOP(SfxBindingsInvalidateAll);
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::Invalidate
+(
+ const sal_uInt16* pIds /* numerisch sortiertes 0-terminiertes Array
+ von Slot-Ids (einzel, nicht als Paare!) */
+)
+{
+ DBG_PROFSTART(SfxBindingsInvalidateAll);
+// DBG_ASSERT( !pImp->bInUpdate, "SfxBindings::Invalidate while in update" );
+
+ DBG_MEMTEST();
+
+ if ( pImp->bInUpdate )
+ {
+ sal_Int32 i = 0;
+ while ( pIds[i] != 0 )
+ AddSlotToInvalidateSlotsMap_Impl( pIds[i++] );
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->Invalidate( pIds );
+ return;
+ }
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->Invalidate( pIds );
+
+ // ist schon alles dirty gesetzt oder downing => nicht zu tun
+ if ( !pDispatcher || pImp->bAllDirty || SFX_APP()->IsDowning() )
+ return;
+
+ // in immer kleiner werdenden Berichen bin"ar suchen
+ for ( sal_uInt16 n = GetSlotPos(*pIds);
+ *pIds && n < pImp->pCaches->Count();
+ n = GetSlotPos(*pIds, n) )
+ {
+ // falls SID "uberhaupt gebunden ist, den Cache invalidieren
+ SfxStateCache *pCache = pImp->pCaches->GetObject(n);
+ if ( pCache->GetId() == *pIds )
+ pCache->Invalidate(sal_False);
+
+ // n"achste SID
+ if ( !*++pIds )
+ break;
+ DBG_ASSERT( *pIds > *(pIds-1), "pIds unsorted" );
+ }
+
+ // falls nicht gelockt, Update-Timer starten
+ pImp->nMsgPos = 0;
+ if ( !nRegLevel )
+ {
+ pImp->aTimer.Stop();
+ pImp->aTimer.SetTimeout(TIMEOUT_FIRST);
+ pImp->aTimer.Start();
+// pImp->bFirstRound = sal_True;
+// pImp->nFirstShell = 0;
+ }
+
+ DBG_PROFSTOP(SfxBindingsInvalidateAll);
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::InvalidateShell
+(
+ const SfxShell& rSh /* Die <SfxShell>, deren Slot-Ids
+ invalidiert werden sollen. */,
+
+ sal_Bool bDeep /* sal_True
+ auch die, von der SfxShell
+ ererbten Slot-Ids werden invalidert
+
+ sal_False
+ die ererbten und nicht "uberladenen
+ Slot-Ids werden invalidiert */
+ //! MI: z. Zt. immer bDeep
+)
+{
+ DBG_ASSERT( !pImp->bInUpdate, "SfxBindings::Invalidate while in update" );
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->InvalidateShell( rSh, bDeep );
+
+ if ( !pDispatcher || pImp->bAllDirty || SFX_APP()->IsDowning() )
+ return;
+
+ DBG_PROFSTART(SfxBindingsInvalidateAll);
+ DBG_MEMTEST();
+
+ // Jetzt schon flushen, wird in GetShellLevel(rSh) sowieso gemacht; wichtig,
+ // damit pImp->bAll(Msg)Dirty korrekt gesetzt ist
+ pDispatcher->Flush();
+
+ if ( !pDispatcher ||
+ ( pImp->bAllDirty && pImp->bAllMsgDirty ) ||
+ SFX_APP()->IsDowning() )
+ {
+ // Wenn sowieso demn"achst alle Server geholt werden
+ return;
+ }
+
+ // Level finden
+ sal_uInt16 nLevel = pDispatcher->GetShellLevel(rSh);
+ if ( nLevel != USHRT_MAX )
+ {
+ for ( sal_uInt16 n = 0; n < pImp->pCaches->Count(); ++n )
+ {
+ SfxStateCache *pCache = pImp->pCaches->GetObject(n);
+ const SfxSlotServer *pMsgServer =
+ pCache->GetSlotServer(*pDispatcher, pImp->xProv);
+ if ( pMsgServer && pMsgServer->GetShellLevel() == nLevel )
+ pCache->Invalidate(sal_False);
+ }
+ pImp->nMsgPos = 0;
+ if ( !nRegLevel )
+ {
+ pImp->aTimer.Stop();
+ pImp->aTimer.SetTimeout(TIMEOUT_FIRST);
+ pImp->aTimer.Start();
+ pImp->bFirstRound = sal_True;
+ pImp->nFirstShell = nLevel;
+ }
+ }
+
+ DBG_PROFSTOP(SfxBindingsInvalidateAll);
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::Invalidate
+(
+ sal_uInt16 nId // zu invalidierende Slot-Id
+)
+{
+ DBG_MEMTEST();
+// DBG_ASSERT( !pImp->bInUpdate, "SfxBindings::Invalidate while in update" );
+
+ if ( pImp->bInUpdate )
+ {
+ AddSlotToInvalidateSlotsMap_Impl( nId );
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->Invalidate( nId );
+ return;
+ }
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->Invalidate( nId );
+
+ if ( !pDispatcher || pImp->bAllDirty || SFX_APP()->IsDowning() )
+ return;
+
+ SfxStateCache* pCache = GetStateCache(nId);
+ if ( pCache )
+ {
+ pCache->Invalidate(sal_False);
+ pImp->nMsgPos = Min(GetSlotPos(nId), pImp->nMsgPos);
+ if ( !nRegLevel )
+ {
+ pImp->aTimer.Stop();
+ pImp->aTimer.SetTimeout(TIMEOUT_FIRST);
+ pImp->aTimer.Start();
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::Invalidate
+(
+ sal_uInt16 nId, // zu invalidierende Slot-Id
+ sal_Bool bWithItem, // StateCache clearen ?
+ sal_Bool bWithMsg // SlotServer neu holen ?
+)
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( !pImp->bInUpdate, "SfxBindings::Invalidate while in update" );
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->Invalidate( nId, bWithItem, bWithMsg );
+
+ if ( SFX_APP()->IsDowning() )
+ return;
+
+ SfxStateCache* pCache = GetStateCache(nId);
+ if ( pCache )
+ {
+ if ( bWithItem )
+ pCache->ClearCache();
+ pCache->Invalidate(bWithMsg);
+
+ if ( !pDispatcher || pImp->bAllDirty )
+ return;
+
+ pImp->nMsgPos = Min(GetSlotPos(nId), pImp->nMsgPos);
+ if ( !nRegLevel )
+ {
+ pImp->aTimer.Stop();
+ pImp->aTimer.SetTimeout(TIMEOUT_FIRST);
+ pImp->aTimer.Start();
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+sal_Bool SfxBindings::IsBound( sal_uInt16 nSlotId, sal_uInt16 nStartSearchAt )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+ return GetStateCache(nSlotId, &nStartSearchAt ) != 0;
+}
+
+//--------------------------------------------------------------------
+
+sal_uInt16 SfxBindings::GetSlotPos( sal_uInt16 nId, sal_uInt16 nStartSearchAt )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+ DBG_PROFSTART(SfxBindingsMsgPos);
+
+ // answer immediately if a function-seek comes repeated
+ if ( pImp->nCachedFunc1 < pImp->pCaches->Count() &&
+ (*pImp->pCaches)[pImp->nCachedFunc1]->GetId() == nId )
+ {
+ ++nCache1;
+ DBG_PROFSTOP(SfxBindingsMsgPos);
+ return pImp->nCachedFunc1;
+ }
+ if ( pImp->nCachedFunc2 < pImp->pCaches->Count() &&
+ (*pImp->pCaches)[pImp->nCachedFunc2]->GetId() == nId )
+ {
+ ++nCache2;
+
+ // swap the caches
+ sal_uInt16 nTemp = pImp->nCachedFunc1;
+ pImp->nCachedFunc1 = pImp->nCachedFunc2;
+ pImp->nCachedFunc2 = nTemp;
+ DBG_PROFSTOP(SfxBindingsMsgPos);
+ return pImp->nCachedFunc1;
+ }
+
+ // binary search, if not found, seek to target-position
+ if ( pImp->pCaches->Count() <= nStartSearchAt )
+ {
+ DBG_PROFSTOP(SfxBindingsMsgPos);
+ return 0;
+ }
+ if ( pImp->pCaches->Count() == (nStartSearchAt+1) )
+ {
+ DBG_PROFSTOP(SfxBindingsMsgPos);
+ return (*pImp->pCaches)[nStartSearchAt]->GetId() >= nId ? 0 : 1;
+ }
+ sal_uInt16 nLow = nStartSearchAt;
+ sal_uInt16 nMid = 0;
+ sal_uInt16 nHigh = 0;
+ sal_Bool bFound = sal_False;
+ nHigh = pImp->pCaches->Count() - 1;
+ while ( !bFound && nLow <= nHigh )
+ {
+ nMid = (nLow + nHigh) >> 1;
+ DBG_ASSERT( nMid < pImp->pCaches->Count(), "bsearch ist buggy" );
+ int nDiff = (int) nId - (int) ( ((*pImp->pCaches)[nMid])->GetId() );
+ if ( nDiff < 0)
+ { if ( nMid == 0 )
+ break;
+ nHigh = nMid - 1;
+ }
+ else if ( nDiff > 0 )
+ { nLow = nMid + 1;
+ if ( nLow == 0 )
+ break;
+ }
+ else
+ bFound = sal_True;
+ }
+ sal_uInt16 nPos = bFound ? nMid : nLow;
+ DBG_ASSERT( nPos <= pImp->pCaches->Count(), "" );
+ DBG_ASSERT( nPos == pImp->pCaches->Count() ||
+ nId <= (*pImp->pCaches)[nPos]->GetId(), "" );
+ DBG_ASSERT( nPos == nStartSearchAt ||
+ nId > (*pImp->pCaches)[nPos-1]->GetId(), "" );
+ DBG_ASSERT( ( (nPos+1) >= pImp->pCaches->Count() ) ||
+ nId < (*pImp->pCaches)[nPos+1]->GetId(), "" );
+ pImp->nCachedFunc2 = pImp->nCachedFunc1;
+ pImp->nCachedFunc1 = nPos;
+ DBG_PROFSTOP(SfxBindingsMsgPos);
+ return nPos;
+}
+//--------------------------------------------------------------------
+void SfxBindings::RegisterInternal_Impl( SfxControllerItem& rItem )
+{
+ Register_Impl( rItem, TRUE );
+
+}
+
+void SfxBindings::Register( SfxControllerItem& rItem )
+{
+ Register_Impl( rItem, FALSE );
+}
+
+void SfxBindings::Register_Impl( SfxControllerItem& rItem, BOOL bInternal )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( nRegLevel > 0, "registration without EnterRegistrations" );
+ DBG_ASSERT( !pImp->bInNextJob, "SfxBindings::Register while status-updating" );
+
+ // insert new cache if it does not already exist
+ sal_uInt16 nId = rItem.GetId();
+ sal_uInt16 nPos = GetSlotPos(nId);
+ if ( nPos >= pImp->pCaches->Count() ||
+ (*pImp->pCaches)[nPos]->GetId() != nId )
+ {
+ SfxStateCache* pCache = new SfxStateCache(nId);
+ pImp->pCaches->Insert( nPos, pCache );
+ DBG_ASSERT( nPos == 0 ||
+ (*pImp->pCaches)[nPos]->GetId() >
+ (*pImp->pCaches)[nPos-1]->GetId(), "" );
+ DBG_ASSERT( (nPos == pImp->pCaches->Count()-1) ||
+ (*pImp->pCaches)[nPos]->GetId() <
+ (*pImp->pCaches)[nPos+1]->GetId(), "" );
+ pImp->bMsgDirty = sal_True;
+ }
+
+ // enqueue the new binding
+ if ( bInternal )
+ {
+ (*pImp->pCaches)[nPos]->SetInternalController( &rItem );
+ }
+ else
+ {
+ SfxControllerItem *pOldItem = (*pImp->pCaches)[nPos]->ChangeItemLink(&rItem);
+ rItem.ChangeItemLink(pOldItem);
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::Release( SfxControllerItem& rItem )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+ //! DBG_ASSERT( nRegLevel > 0, "release without EnterRegistrations" );
+ DBG_ASSERT( !pImp->bInNextJob, "SfxBindings::Release while status-updating" );
+ ENTERREGISTRATIONS();
+
+ // find the bound function
+ sal_uInt16 nId = rItem.GetId();
+ sal_uInt16 nPos = GetSlotPos(nId);
+ SfxStateCache* pCache = (*pImp->pCaches)[nPos];
+ if ( pCache->GetId() == nId )
+ {
+ if ( pCache->GetInternalController() == &rItem )
+ {
+ pCache->ReleaseInternalController();
+ }
+ else
+ {
+ // is this the first binding in the list?
+ SfxControllerItem* pItem = pCache->GetItemLink();
+ if ( pItem == &rItem )
+ pCache->ChangeItemLink( rItem.GetItemLink() );
+ else
+ {
+ // search the binding in the list
+ while ( pItem && pItem->GetItemLink() != &rItem )
+ pItem = pItem->GetItemLink();
+
+ // unlink it if it was found
+ if ( pItem )
+ pItem->ChangeItemLink( rItem.GetItemLink() );
+ }
+ }
+
+ // was this the last controller?
+ if ( pCache->GetItemLink() == 0 && !pCache->GetInternalController() )
+ {
+#ifdef slow
+ // remove the BoundFunc
+ delete (*pImp->pCaches)[nPos];
+ pImp->pCaches->Remove(nPos, 1);
+#endif
+ if ( SfxMacroConfig::IsMacroSlot( nId ) )
+ {
+ delete (*pImp->pCaches)[nPos];
+ pImp->pCaches->Remove(nPos, 1);
+ }
+ else
+ pImp->bCtrlReleased = sal_True;
+ }
+ }
+
+ LEAVEREGISTRATIONS();
+}
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxBindings::ExecuteSynchron( sal_uInt16 nId, const SfxPoolItem** ppItems, sal_uInt16 nModi,
+ const SfxPoolItem **ppInternalArgs )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+
+ if( !nId || !pDispatcher )
+ return NULL;
+
+ return Execute_Impl( nId, ppItems, nModi, SFX_CALLMODE_SYNCHRON, ppInternalArgs );
+}
+
+sal_Bool SfxBindings::Execute( sal_uInt16 nId, const SfxPoolItem** ppItems, sal_uInt16 nModi, SfxCallMode nCallMode,
+ const SfxPoolItem **ppInternalArgs )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+
+ if( !nId || !pDispatcher )
+ return sal_False;
+
+ const SfxPoolItem* pRet = Execute_Impl( nId, ppItems, nModi, nCallMode, ppInternalArgs );
+ return ( pRet != 0 );
+}
+
+void SfxBindings::ExecuteGlobal_Impl( USHORT nId )
+{
+ if( nId && pDispatcher )
+ Execute_Impl( nId, NULL, 0, SFX_CALLMODE_ASYNCHRON, NULL, TRUE );
+}
+
+const SfxPoolItem* SfxBindings::Execute_Impl( sal_uInt16 nId, const SfxPoolItem** ppItems, sal_uInt16 nModi, SfxCallMode nCallMode,
+ const SfxPoolItem **ppInternalArgs, BOOL bGlobalOnly )
+{
+ SfxStateCache *pCache = GetStateCache( nId );
+ if ( !pCache )
+ {
+ SfxBindings *pBind = pImp->pSubBindings;
+ while ( pBind )
+ {
+ if ( pBind->GetStateCache( nId ) )
+ return pBind->Execute_Impl( nId, ppItems, nModi, nCallMode, ppInternalArgs, bGlobalOnly );
+ pBind = pBind->pImp->pSubBindings;
+ };
+ }
+
+ SfxDispatcher &rDispatcher = *pDispatcher;
+ rDispatcher.Flush();
+ rDispatcher.GetFrame(); // -Wall is this required???
+
+ // get SlotServer (Slot+ShellLevel) and Shell from cache
+ sal_Bool bDeleteCache = sal_False;
+ if ( !pCache )
+ {
+ // Execution of non cached slots (Accelerators don't use Controllers)
+ // slot is uncached, use SlotCache to handle external dispatch providers
+ pCache = new SfxStateCache( nId );
+ pCache->GetSlotServer( rDispatcher, pImp->xProv );
+ bDeleteCache = sal_True;
+ }
+
+ if ( pCache && pCache->GetDispatch().is() )
+ {
+ DBG_ASSERT( !ppInternalArgs, "Internal args get lost when dispatched!" );
+
+ SfxItemPool &rPool = GetDispatcher()->GetFrame()->GetObjectShell()->GetPool();
+ SfxRequest aReq( nId, nCallMode, rPool );
+ aReq.SetModifier( nModi );
+ if( ppItems )
+ while( *ppItems )
+ aReq.AppendItem( **ppItems++ );
+
+ // cache binds to an external dispatch provider
+ pCache->Dispatch( aReq.GetArgs(), nCallMode == SFX_CALLMODE_SYNCHRON );
+ if ( bDeleteCache )
+ DELETEZ( pCache );
+ SfxPoolItem *pVoid = new SfxVoidItem( nId );
+ DeleteItemOnIdle( pVoid );
+ return pVoid;
+ }
+
+ // slot is handled internally by SfxDispatcher
+ if ( pImp->bMsgDirty )
+ UpdateSlotServer_Impl();
+
+ SfxShell *pShell=0;
+ const SfxSlot *pSlot=0;
+
+ // if slot was uncached, we should have created a cache in this method!
+ DBG_ASSERT( pCache, "This code needs a cache!");
+ const SfxSlotServer* pServer = pCache ? pCache->GetSlotServer( rDispatcher, pImp->xProv ) : 0;
+ if ( !pServer )
+ {
+ return NULL;
+ }
+ else
+ {
+ pShell = rDispatcher.GetShell( pServer->GetShellLevel() );
+ pSlot = pServer->GetSlot();
+ }
+
+ if ( bGlobalOnly )
+ if ( !pShell->ISA(SfxModule) && !pShell->ISA(SfxApplication) && !pShell->ISA(SfxViewFrame) )
+ return NULL;
+
+ SfxItemPool &rPool = pShell->GetPool();
+ SfxRequest aReq( nId, nCallMode, rPool );
+ aReq.SetModifier( nModi );
+ if( ppItems )
+ while( *ppItems )
+ aReq.AppendItem( **ppItems++ );
+ if ( ppInternalArgs )
+ {
+ SfxAllItemSet aSet( rPool );
+ for ( const SfxPoolItem **pArg = ppInternalArgs; *pArg; ++pArg )
+ aSet.Put( **pArg );
+ aReq.SetInternalArgs_Impl( aSet );
+ }
+
+ Execute_Impl( aReq, pSlot, pShell );
+
+ const SfxPoolItem* pRet = aReq.GetReturnValue();
+ if ( !pRet )
+ {
+ SfxPoolItem *pVoid = new SfxVoidItem( nId );
+ DeleteItemOnIdle( pVoid );
+ pRet = pVoid;
+ }
+
+ if ( bDeleteCache )
+ delete pCache;
+
+ return pRet;
+}
+
+void SfxBindings::Execute_Impl( SfxRequest& aReq, const SfxSlot* pSlot, SfxShell* pShell )
+{
+ SfxItemPool &rPool = pShell->GetPool();
+
+ if ( SFX_KIND_ENUM == pSlot->GetKind() )
+ {
+ // bei Enum-Slots muss der Master mit dem Wert des Enums executet werden
+ const SfxSlot *pRealSlot = pShell->GetInterface()->GetRealSlot(pSlot);
+ const sal_uInt16 nSlotId = pRealSlot->GetSlotId();
+ aReq.SetSlot( nSlotId );
+ aReq.AppendItem( SfxAllEnumItem( rPool.GetWhich(nSlotId), pSlot->GetValue() ) );
+ pDispatcher->_Execute( *pShell, *pRealSlot, aReq, aReq.GetCallMode() | SFX_CALLMODE_RECORD );
+ }
+ else if ( SFX_KIND_ATTR == pSlot->GetKind() )
+ {
+ // bei Attr-Slots muss der Which-Wert gemapped werden
+ const sal_uInt16 nSlotId = pSlot->GetSlotId();
+ aReq.SetSlot( nSlotId );
+ if ( pSlot->IsMode(SFX_SLOT_TOGGLE) )
+ {
+ // an togglebare-Attribs (Bools) wird der Wert angeheangt
+ sal_uInt16 nWhich = pSlot->GetWhich(rPool);
+ SfxItemSet aSet(rPool, nWhich, nWhich, 0);
+ SfxStateFunc aFunc = pSlot->GetStateFnc();
+ pShell->CallState( aFunc, aSet );
+ const SfxPoolItem *pOldItem;
+ SfxItemState eState = aSet.GetItemState(nWhich, sal_True, &pOldItem);
+ if ( eState == SFX_ITEM_DISABLED )
+ return;
+
+ if ( SFX_ITEM_AVAILABLE == eState && SfxItemPool::IsWhich(nWhich) )
+ pOldItem = &aSet.Get(nWhich);
+
+ if ( SFX_ITEM_SET == eState ||
+ ( SFX_ITEM_AVAILABLE == eState &&
+ SfxItemPool::IsWhich(nWhich) &&
+ pOldItem ) )
+ {
+ if ( pOldItem->ISA(SfxBoolItem) )
+ {
+ // wir koennen Bools toggeln
+ sal_Bool bOldValue = ((const SfxBoolItem *)pOldItem)->GetValue();
+ SfxBoolItem *pNewItem = (SfxBoolItem*) (pOldItem->Clone());
+ pNewItem->SetValue( !bOldValue );
+ aReq.AppendItem( *pNewItem );
+ delete pNewItem;
+ }
+ else if ( pOldItem->ISA(SfxEnumItemInterface) &&
+ ((SfxEnumItemInterface *)pOldItem)->HasBoolValue())
+ {
+ // und Enums mit Bool-Interface
+ SfxEnumItemInterface *pNewItem =
+ (SfxEnumItemInterface*) (pOldItem->Clone());
+ pNewItem->SetBoolValue(!((SfxEnumItemInterface *)pOldItem)->GetBoolValue());
+ aReq.AppendItem( *pNewItem );
+ delete pNewItem;
+ }
+ else {
+ DBG_ERROR( "Toggle only for Enums and Bools allowed" );
+ }
+ }
+ else if ( SFX_ITEM_DONTCARE == eState )
+ {
+ // ein Status-Item per Factory erzeugen
+ SfxPoolItem *pNewItem = pSlot->GetType()->CreateItem();
+ DBG_ASSERT( pNewItem, "Toggle an Slot ohne ItemFactory" );
+ pNewItem->SetWhich( nWhich );
+
+ if ( pNewItem->ISA(SfxBoolItem) )
+ {
+ // wir koennen Bools toggeln
+ ((SfxBoolItem*)pNewItem)->SetValue( sal_True );
+ aReq.AppendItem( *pNewItem );
+ }
+ else if ( pNewItem->ISA(SfxEnumItemInterface) &&
+ ((SfxEnumItemInterface *)pNewItem)->HasBoolValue())
+ {
+ // und Enums mit Bool-Interface
+ ((SfxEnumItemInterface*)pNewItem)->SetBoolValue(sal_True);
+ aReq.AppendItem( *pNewItem );
+ }
+ else {
+ DBG_ERROR( "Toggle only for Enums and Bools allowed" );
+ }
+ delete pNewItem;
+ }
+ else {
+ DBG_ERROR( "suspicious Toggle-Slot" );
+ }
+ }
+
+ pDispatcher->_Execute( *pShell, *pSlot, aReq, aReq.GetCallMode() | SFX_CALLMODE_RECORD );
+ }
+ else
+ pDispatcher->_Execute( *pShell, *pSlot, aReq, aReq.GetCallMode() | SFX_CALLMODE_RECORD );
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::UpdateSlotServer_Impl()
+{
+ DBG_PROFSTART(SfxBindingsUpdateServers);
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+
+ // synchronisieren
+ pDispatcher->Flush();
+// pDispatcher->Update_Impl();
+
+ if ( pImp->bAllMsgDirty )
+ {
+ if ( !nRegLevel )
+ {
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame
+ ( pDispatcher->GetFrame()->GetFrame().GetFrameInterface(), UNO_QUERY );
+ //if ( xFrame.is() )
+ // xFrame->contextChanged();
+ pImp->bContextChanged = FALSE;
+ }
+ else
+ pImp->bContextChanged = TRUE;
+ }
+
+ const sal_uInt16 nCount = pImp->pCaches->Count();
+ for(sal_uInt16 i = 0; i < nCount; ++i)
+ {
+ SfxStateCache *pCache = pImp->pCaches->GetObject(i);
+ pCache->GetSlotServer(*pDispatcher, pImp->xProv);
+ }
+ pImp->bMsgDirty = pImp->bAllMsgDirty = sal_False;
+
+ Broadcast( SfxSimpleHint(SFX_HINT_DOCCHANGED) );
+
+ DBG_PROFSTOP(SfxBindingsUpdateServers);
+}
+
+//--------------------------------------------------------------------
+
+#ifdef WNT
+int __cdecl CmpUS_Impl(const void *p1, const void *p2)
+#else
+int CmpUS_Impl(const void *p1, const void *p2)
+#endif
+
+/* [Beschreibung]
+
+ Interne Vergleichsfunktion fuer qsort.
+*/
+
+{
+ return *(sal_uInt16 *)p1 - *(sal_uInt16 *)p2;
+}
+
+//--------------------------------------------------------------------
+
+SfxItemSet* SfxBindings::CreateSet_Impl
+(
+ SfxStateCache*& pCache, // in: Status-Cache von nId
+ const SfxSlot*& pRealSlot, // out: RealSlot zu nId
+ const SfxSlotServer** pMsgServer, // out: Slot-Server zu nId
+ SfxFoundCacheArr_Impl& rFound // out: Liste der Caches der Siblings
+)
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+
+ DBG_ASSERT( !pImp->bMsgDirty, "CreateSet_Impl mit dirty MessageServer" );
+
+ const SfxSlotServer* pMsgSvr = pCache->GetSlotServer(*pDispatcher, pImp->xProv);
+ if(!pMsgSvr || !pDispatcher)
+ return 0;
+
+ DBG_PROFSTART(SfxBindingsCreateSet);
+ pRealSlot = 0;
+ *pMsgServer = pMsgSvr;
+
+ sal_uInt16 nShellLevel = pMsgSvr->GetShellLevel();
+ SfxShell *pShell = pDispatcher->GetShell( nShellLevel );
+ if ( !pShell ) // seltener GPF beim Browsen durch Update aus Inet-Notify
+ return 0;
+
+ SfxItemPool &rPool = pShell->GetPool();
+
+ // hole die Status-Methode, von der pCache bedient wird
+ SfxStateFunc pFnc = 0;
+ const SfxInterface *pInterface = pShell->GetInterface();
+ if ( SFX_KIND_ENUM == pMsgSvr->GetSlot()->GetKind() )
+ {
+ pRealSlot = pInterface->GetRealSlot(pMsgSvr->GetSlot());
+ pCache = GetStateCache( pRealSlot->GetSlotId() );
+// DBG_ASSERT( pCache, "Kein Slotcache fuer den Masterslot gefunden!" );
+ }
+ else
+ pRealSlot = pMsgSvr->GetSlot();
+
+ //
+ // Achtung: pCache darf auch NULL sein !!!
+ //
+
+ pFnc = pRealSlot->GetStateFnc();
+
+ // der RealSlot ist immer drin
+ const SfxFoundCache_Impl *pFound = new SfxFoundCache_Impl(
+ pRealSlot->GetSlotId(), pRealSlot->GetWhich(rPool), pRealSlot, pCache );
+ rFound.Insert( pFound );
+
+ USHORT nSlot = pRealSlot->GetSlotId();
+ if ( !SfxMacroConfig::IsMacroSlot( nSlot ) && !(nSlot >= SID_VERB_START && nSlot <= SID_VERB_END) )
+ {
+ pInterface = pInterface->GetRealInterfaceForSlot( pRealSlot );
+ DBG_ASSERT (pInterface,"Slot in angegebener Shell nicht gefunden!");
+ }
+
+ // Durchsuche die Bindings nach den von derselben Funktion bedienten Slots.
+ // Daf"ur kommen nur Slots in Frage, die es im gefundenen Interface gibt.
+
+ // Die Position des Statecaches im StateCache-Array
+ sal_uInt16 nCachePos = pImp->nMsgPos;
+ const SfxSlot *pSibling = pRealSlot->GetNextSlot();
+
+ // Die Slots eines Interfaces sind im Kreis verkettet
+ while ( pSibling > pRealSlot )
+ {
+ SfxStateFunc pSiblingFnc=0;
+ SfxStateCache *pSiblingCache =
+ GetStateCache( pSibling->GetSlotId(), &nCachePos );
+
+ // Ist der Slot "uberhaupt gecached ?
+ if ( pSiblingCache )
+ {
+ const SfxSlotServer *pServ = pSiblingCache->GetSlotServer(*pDispatcher, pImp->xProv);
+ if ( pServ && pServ->GetShellLevel() == nShellLevel )
+ pSiblingFnc = pServ->GetSlot()->GetStateFnc();
+ }
+
+ // Mu\s der Slot "uberhaupt upgedatet werden ?
+ FASTBOOL bInsert = pSiblingCache && pSiblingCache->IsControllerDirty();
+
+ // Bugfix #26161#: Es reicht nicht, nach der selben Shell zu fragen !!
+ FASTBOOL bSameMethod = pSiblingCache && pFnc == pSiblingFnc;
+
+ // Wenn der Slot ein nicht-dirty MasterSlot ist, dann ist vielleicht
+ // einer seiner Slaves dirty ? Dann wird der Masterslot doch eingef"ugt.
+ if ( !bInsert && bSameMethod && pSibling->GetLinkedSlot() )
+ {
+ // auch Slave-Slots auf Binding pru"fen
+ const SfxSlot* pFirstSlave = pSibling->GetLinkedSlot();
+ for ( const SfxSlot *pSlaveSlot = pFirstSlave;
+ !bInsert;
+ pSlaveSlot = pSlaveSlot->GetNextSlot())
+ {
+ // Die Slaves zeigen auf ihren Master
+ DBG_ASSERT(pSlaveSlot->GetLinkedSlot() == pSibling,
+ "Falsche Master/Slave-Beziehung!");
+
+ sal_uInt16 nCurMsgPos = pImp->nMsgPos;
+ const SfxStateCache *pSlaveCache =
+ GetStateCache( pSlaveSlot->GetSlotId(), &nCurMsgPos );
+
+ // Ist der Slave-Slot gecached und dirty ?
+ bInsert = pSlaveCache && pSlaveCache->IsControllerDirty();
+
+ // Slaves sind untereinander im Kreis verkettet
+ if (pSlaveSlot->GetNextSlot() == pFirstSlave)
+ break;
+ }
+ }
+
+ if ( bInsert && bSameMethod )
+ {
+ const SfxFoundCache_Impl *pFoundCache = new SfxFoundCache_Impl(
+ pSibling->GetSlotId(), pSibling->GetWhich(rPool),
+ pSibling, pSiblingCache );
+
+ rFound.Insert( pFoundCache );
+ }
+
+ pSibling = pSibling->GetNextSlot();
+ }
+
+ // aus den Ranges ein Set erzeugen
+ sal_uInt16 *pRanges = new sal_uInt16[rFound.Count() * 2 + 1];
+ int j = 0;
+ USHORT i = 0;
+ while ( i < rFound.Count() )
+ {
+ pRanges[j++] = rFound[i]->nWhichId;
+ // aufeinanderfolgende Zahlen
+ for ( ; i < rFound.Count()-1; ++i )
+ if ( rFound[i]->nWhichId+1 != rFound[i+1]->nWhichId )
+ break;
+ pRanges[j++] = rFound[i++]->nWhichId;
+ }
+ pRanges[j] = 0; // terminierende NULL
+ SfxItemSet *pSet = new SfxItemSet(rPool, pRanges);
+ delete [] pRanges;
+ DBG_PROFSTOP(SfxBindingsCreateSet);
+ return pSet;
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::UpdateControllers_Impl
+(
+ const SfxInterface* pIF, // das diese Id momentan bedienende Interface
+ const SfxFoundCache_Impl* pFound, // Cache, Slot, Which etc.
+ const SfxPoolItem* pItem, // item to send to controller
+ SfxItemState eState // state of item
+)
+{
+ DBG_ASSERT( !pFound->pSlot || SFX_KIND_ENUM != pFound->pSlot->GetKind(),
+ "direct update of enum slot isn't allowed" );
+ DBG_PROFSTART(SfxBindingsUpdateCtrl1);
+
+ SfxStateCache* pCache = pFound->pCache;
+ const SfxSlot* pSlot = pFound->pSlot;
+ DBG_ASSERT( !pCache || !pSlot || pCache->GetId() == pSlot->GetSlotId(), "SID mismatch" );
+
+ // insofern gebunden, die Controller f"uer den Slot selbst updaten
+ if ( pCache && pCache->IsControllerDirty() )
+ {
+ if ( SFX_ITEM_DONTCARE == eState )
+ {
+ // uneindeuting
+ pCache->SetState( SFX_ITEM_DONTCARE, (SfxPoolItem *)-1 );
+ }
+ else if ( SFX_ITEM_DEFAULT == eState &&
+ pFound->nWhichId > SFX_WHICH_MAX )
+ {
+ // kein Status oder Default aber ohne Pool
+ SfxVoidItem aVoid(0);
+ pCache->SetState( SFX_ITEM_UNKNOWN, &aVoid );
+ }
+ else if ( SFX_ITEM_DISABLED == eState )
+ pCache->SetState(SFX_ITEM_DISABLED, 0);
+ else
+ pCache->SetState(SFX_ITEM_AVAILABLE, pItem);
+ }
+
+ DBG_PROFSTOP(SfxBindingsUpdateCtrl1);
+
+ // insofern vorhanden und gebunden, die Controller f"uer Slave-Slots
+ // (Enum-Werte) des Slots updaten
+ DBG_PROFSTART(SfxBindingsUpdateCtrl2);
+ DBG_ASSERT( !pSlot || 0 == pSlot->GetLinkedSlot() || !pItem ||
+ pItem->ISA(SfxEnumItemInterface),
+ "master slot with non-enum-type found" );
+ const SfxSlot *pFirstSlave = pSlot ? pSlot->GetLinkedSlot() : 0;
+ if ( pIF && pFirstSlave)
+ {
+ // Items auf EnumItem casten
+ const SfxEnumItemInterface *pEnumItem =
+ PTR_CAST(SfxEnumItemInterface,pItem);
+ if ( eState == SFX_ITEM_AVAILABLE && !pEnumItem )
+ eState = SFX_ITEM_DONTCARE;
+ else
+ eState = SfxControllerItem::GetItemState( pEnumItem );
+
+ // "uber alle Slaves-Slots iterieren
+ for ( const SfxSlot *pSlave = pFirstSlave; pSlave; pSlave = pSlave->GetNextSlot() )
+ {
+ DBG_ASSERT(pSlave, "Falsche SlaveSlot-Verkettung!");
+ DBG_ASSERT(SFX_KIND_ENUM == pSlave->GetKind(),"non enum slaves aren't allowed");
+ DBG_ASSERT(pSlave->GetMasterSlotId() == pSlot->GetSlotId(),"falscher MasterSlot!");
+
+ // ist die Funktion gebunden?
+ SfxStateCache *pEnumCache = GetStateCache( pSlave->GetSlotId() );
+ if ( pEnumCache )
+ {
+ pEnumCache->Invalidate(sal_False);
+
+ HACK(CONTROL/SELECT Kram)
+ if ( eState == SFX_ITEM_DONTCARE && pFound->nWhichId == 10144 )
+ {
+ SfxVoidItem aVoid(0);
+ pEnumCache->SetState( SFX_ITEM_UNKNOWN, &aVoid );
+
+ if (pSlave->GetNextSlot() == pFirstSlave)
+ break;
+
+ continue;
+ }
+
+ if ( SFX_ITEM_DISABLED == eState || !pEnumItem->IsEnabled( pSlave->GetSlotId()) )
+ {
+ // disabled
+ pEnumCache->SetState(SFX_ITEM_DISABLED, 0);
+ }
+ else if ( SFX_ITEM_AVAILABLE == eState )
+ {
+ // enum-Wert ermitteln
+ sal_uInt16 nValue = pEnumItem->GetEnumValue();
+ SfxBoolItem aBool( pFound->nWhichId, pSlave->GetValue() == nValue );
+ pEnumCache->SetState(SFX_ITEM_AVAILABLE, &aBool);
+ }
+ else
+ {
+ // uneindeuting
+ pEnumCache->SetState( SFX_ITEM_DONTCARE, (SfxPoolItem *)-1 );
+ }
+ }
+
+ if (pSlave->GetNextSlot() == pFirstSlave)
+ break;
+ }
+ }
+
+ DBG_PROFSTOP(SfxBindingsUpdateCtrl2);
+}
+
+
+//--------------------------------------------------------------------
+
+IMPL_LINK( SfxBindings, NextJob_Impl, Timer *, pTimer )
+{
+#ifdef DBG_UTIL
+ // on Windows very often C++ Exceptions (GPF etc.) are caught by MSVCRT or another MS library
+ // try to get them here
+ try
+ {
+#endif
+ const unsigned MAX_INPUT_DELAY = 200;
+
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+
+ DBG_PROFSTART(SfxBindingsNextJob_Impl0);
+
+ if ( Application::GetLastInputInterval() < MAX_INPUT_DELAY && pTimer )
+ {
+ pImp->aTimer.SetTimeout(TIMEOUT_UPDATING);
+ return sal_True;
+ }
+
+ SfxApplication *pSfxApp = SFX_APP();
+
+ if( pDispatcher )
+ pDispatcher->Update_Impl();
+
+ // modifying the SfxObjectInterface-stack without SfxBindings => nothing to do
+ SfxViewFrame* pFrame = pDispatcher->GetFrame();
+ //<!--Modified by PengYunQuan for Validity Cell Range Picker
+ //if ( (pFrame && pFrame->GetObjectShell()->IsInModalMode()) || pSfxApp->IsDowning() || !pImp->pCaches->Count() )
+ if ( (pFrame && !pFrame->GetObjectShell()->AcceptStateUpdate()) || pSfxApp->IsDowning() || !pImp->pCaches->Count() )
+ //-->Modified by PengYunQuan for Validity Cell Range Picker
+ {
+ DBG_PROFSTOP(SfxBindingsNextJob_Impl0);
+ return sal_True;
+ }
+ if ( !pDispatcher || !pDispatcher->IsFlushed() )
+ {
+ DBG_PROFSTOP(SfxBindingsNextJob_Impl0);
+ return sal_True;
+ }
+
+ // gfs. alle Server aktualisieren / geschieht in eigener Zeitscheibe
+ if ( pImp->bMsgDirty )
+ {
+ UpdateSlotServer_Impl();
+ DBG_PROFSTOP(SfxBindingsNextJob_Impl0);
+ return sal_False;
+ }
+
+ DBG_PROFSTOP(SfxBindingsNextJob_Impl0);
+ DBG_PROFSTART(SfxBindingsNextJob_Impl);
+ pImp->bAllDirty = sal_False;
+ pImp->aTimer.SetTimeout(TIMEOUT_UPDATING);
+
+ // at least 10 loops and further if more jobs are available but no input
+ FASTBOOL bPreEmptive = pTimer && !pSfxApp->Get_Impl()->nInReschedule;
+ sal_uInt16 nLoops = 10;
+ pImp->bInNextJob = sal_True;
+ const sal_uInt16 nCount = pImp->pCaches->Count();
+ while ( pImp->nMsgPos < nCount )
+ {
+ // iterate through the bound functions
+ sal_Bool bJobDone = sal_False;
+ while ( !bJobDone )
+ {
+ SfxStateCache* pCache = (*pImp->pCaches)[pImp->nMsgPos];
+ DBG_ASSERT( pCache, "invalid SfxStateCache-position in job queue" );
+ sal_Bool bWasDirty = pCache->IsControllerDirty();
+ if ( bWasDirty )
+ {
+/*
+ sal_Bool bSkip = sal_False;
+ if ( pImp->bFirstRound )
+ {
+ // Falls beim Update eine Shell vorgezogen werden soll,
+ // kommt in einer ersten Update-Runde nur diese dran
+ const SfxSlotServer *pMsgServer =
+ pCache->GetSlotServer(*pDispatcher, pImp->xProv);
+ if ( pMsgServer &&
+ pMsgServer->GetShellLevel() != pImp->nFirstShell )
+ bSkip = sal_True;
+ }
+
+ if ( !bSkip )
+ {
+*/
+ Update_Impl( pCache );
+ DBG_ASSERT( nCount == pImp->pCaches->Count(),
+ "Reschedule in StateChanged => buff" );
+// }
+ }
+
+ // skip to next function binding
+ ++pImp->nMsgPos;
+
+ // keep job if it is not completed, but any input is available
+ bJobDone = pImp->nMsgPos >= nCount;
+ if ( bJobDone && pImp->bFirstRound )
+ {
+ // Update der bevorzugten Shell ist gelaufen, nun d"urfen
+ // auch die anderen
+ bJobDone = sal_False;
+ pImp->bFirstRound = sal_False;
+ pImp->nMsgPos = 0;
+ }
+
+ if ( bWasDirty && !bJobDone && bPreEmptive && (--nLoops == 0) )
+ {
+ DBG_PROFSTOP(SfxBindingsNextJob_Impl);
+ pImp->bInNextJob = sal_False;
+ return sal_False;
+ }
+ }
+ }
+
+ pImp->nMsgPos = 0;
+
+ // check for volatile slots
+ bool bVolatileSlotsPresent = false;
+ for ( sal_uInt16 n = 0; n < nCount; ++n )
+ {
+ SfxStateCache* pCache = (*pImp->pCaches)[n];
+ const SfxSlotServer *pSlotServer = pCache->GetSlotServer(*pDispatcher, pImp->xProv);
+ if ( pSlotServer && pSlotServer->GetSlot()->IsMode(SFX_SLOT_VOLATILE) )
+ {
+ pCache->Invalidate(sal_False);
+ bVolatileSlotsPresent = true;
+ }
+ }
+
+ if (bVolatileSlotsPresent)
+ pImp->aTimer.SetTimeout(TIMEOUT_IDLE);
+ else
+ pImp->aTimer.Stop();
+
+ // Update-Runde ist beendet
+ pImp->bInNextJob = sal_False;
+ Broadcast(SfxSimpleHint(SFX_HINT_UPDATEDONE));
+ DBG_PROFSTOP(SfxBindingsNextJob_Impl);
+ return sal_True;
+#ifdef DBG_UTIL
+ }
+ catch (...)
+ {
+ DBG_ERROR("C++ exception caught!");
+ pImp->bInNextJob = sal_False;
+ }
+
+ return sal_False;
+#endif
+}
+
+//--------------------------------------------------------------------
+
+sal_uInt16 SfxBindings::EnterRegistrations(const char *pFile, int nLine)
+{
+ (void)pFile;
+ (void)nLine;
+ DBG_MEMTEST();
+#ifdef DBG_UTIL
+ ByteString aMsg;
+ aMsg.Fill( Min(nRegLevel, sal_uInt16(8) ) );
+ aMsg += "this = ";
+ aMsg += ByteString::CreateFromInt32((long)this);
+ aMsg += " Level = ";
+ aMsg += ByteString::CreateFromInt32(nRegLevel);
+ aMsg += " SfxBindings::EnterRegistrations ";
+ if(pFile) {
+ aMsg += "File: ";
+ aMsg += pFile;
+ aMsg += " Line: ";
+ aMsg += ByteString::CreateFromInt32(nLine);
+ }
+// FILE* pLog = fopen( "c:\\bindings.log", "a+w" );
+// fwrite( aMsg.GetBuffer(), 1, aMsg.Len(), pLog );
+// fclose( pLog );
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+
+ // Wenn Bindings gelockt werden, auch SubBindings locken
+ if ( pImp->pSubBindings )
+ {
+ pImp->pSubBindings->ENTERREGISTRATIONS();
+
+ // Dieses EnterRegistrations ist f"ur die SubBindings kein "echtes"
+ pImp->pSubBindings->pImp->nOwnRegLevel--;
+
+ // Bindings synchronisieren
+ pImp->pSubBindings->nRegLevel = nRegLevel + pImp->pSubBindings->pImp->nOwnRegLevel + 1;
+ }
+
+ pImp->nOwnRegLevel++;
+
+ // check if this is the outer most level
+ if ( ++nRegLevel == 1 )
+ {
+ // stop background-processing
+ pImp->aTimer.Stop();
+
+ // flush the cache
+ pImp->nCachedFunc1 = 0;
+ pImp->nCachedFunc2 = 0;
+
+ // merken, ob ganze Caches verschwunden sind
+ pImp->bCtrlReleased = sal_False;
+ }
+
+ return nRegLevel;
+}
+//--------------------------------------------------------------------
+
+void SfxBindings::LeaveRegistrations( sal_uInt16 nLevel, const char *pFile, int nLine )
+{
+ (void)nLevel; // unused variable
+ (void)pFile;
+ (void)nLine;
+ DBG_MEMTEST();
+ DBG_ASSERT( nRegLevel, "Leave without Enter" );
+ DBG_ASSERT( nLevel == USHRT_MAX || nLevel == nRegLevel, "wrong Leave" );
+
+ // Nur wenn die SubBindings noch von den SuperBindings gelockt sind, diesen Lock entfernen
+ // ( d.h. wenn es mehr Locks als "echte" Locks dort gibt )
+ if ( pImp->pSubBindings && pImp->pSubBindings->nRegLevel > pImp->pSubBindings->pImp->nOwnRegLevel )
+ {
+ // Bindings synchronisieren
+ pImp->pSubBindings->nRegLevel = nRegLevel + pImp->pSubBindings->pImp->nOwnRegLevel;
+
+ // Dieses LeaveRegistrations ist f"ur die SubBindings kein "echtes"
+ pImp->pSubBindings->pImp->nOwnRegLevel++;
+ pImp->pSubBindings->LEAVEREGISTRATIONS();
+ }
+
+ pImp->nOwnRegLevel--;
+
+ // check if this is the outer most level
+ if ( --nRegLevel == 0 && !SFX_APP()->IsDowning() )
+ {
+ if ( pImp->bContextChanged )
+ {
+ pImp->bContextChanged = FALSE;
+ /*
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame
+ ( pDispatcher->GetFrame()->GetFrame().GetFrameInterface(), UNO_QUERY );
+ if ( xFrame.is() )
+ xFrame->contextChanged();*/
+ }
+
+#ifndef slow
+ SfxViewFrame* pFrame = pDispatcher->GetFrame();
+
+ // ggf unbenutzte Caches entfernen bzw. PlugInInfo aufbereiten
+ if ( pImp->bCtrlReleased )
+ {
+ for ( sal_uInt16 nCache = pImp->pCaches->Count(); nCache > 0; --nCache )
+ {
+ // Cache via ::com::sun::star::sdbcx::Index besorgen
+ SfxStateCache *pCache = pImp->pCaches->GetObject(nCache-1);
+
+ // kein Controller mehr interessiert
+ if ( pCache->GetItemLink() == 0 && !pCache->GetInternalController() )
+ {
+ // Cache entfernen. Safety: first remove and then delete
+ SfxStateCache* pSfxStateCache = (*pImp->pCaches)[nCache-1];
+ pImp->pCaches->Remove(nCache-1, 1);
+ delete pSfxStateCache;
+ }
+ else
+ {
+ // neue Controller mit den alten Items benachrichtigen
+ //!pCache->SetCachedState();
+ }
+ }
+ }
+#endif
+ // restart background-processing
+ pImp->nMsgPos = 0;
+ if ( !pFrame || !pFrame->GetObjectShell() )
+ return;
+ if ( pImp->pCaches && pImp->pCaches->Count() )
+ {
+ pImp->aTimer.Stop();
+ pImp->aTimer.SetTimeout(TIMEOUT_FIRST);
+ pImp->aTimer.Start();
+// pImp->bFirstRound = sal_True;
+ }
+ }
+
+#ifdef DBG_UTIL
+ ByteString aMsg;
+ aMsg.Fill( Min(nRegLevel, sal_uInt16(8)) );
+ aMsg += "this = ";
+ aMsg += ByteString::CreateFromInt32((long)this);
+ aMsg += " Level = ";
+ aMsg += ByteString::CreateFromInt32(nRegLevel);
+ aMsg += " SfxBindings::LeaveRegistrations ";
+ if(pFile) {
+ aMsg += "File: ";
+ aMsg += pFile;
+ aMsg += " Line: ";
+ aMsg += ByteString::CreateFromInt32(nLine);
+ }
+// FILE* pLog = fopen( "c:\\bindings.log", "a+w" );
+// fwrite( aMsg.GetBuffer(), 1, aMsg.Len(), pLog );
+// fclose( pLog );
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+}
+
+//--------------------------------------------------------------------
+
+const SfxSlot* SfxBindings::GetSlot(sal_uInt16 nSlotId)
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->pCaches != 0, "SfxBindings not initialized" );
+
+ // syncronisieren
+ pDispatcher->Flush();
+ if ( pImp->bMsgDirty )
+ UpdateSlotServer_Impl();
+
+ // get the cache for the specified function; return if not bound
+ SfxStateCache* pCache = GetStateCache(nSlotId);
+ return pCache && pCache->GetSlotServer(*pDispatcher, pImp->xProv)?
+ pCache->GetSlotServer(*pDispatcher, pImp->xProv)->GetSlot(): 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::SetDispatcher( SfxDispatcher *pDisp )
+{
+ SfxDispatcher *pOldDispat = pDispatcher;
+ if ( pDisp != pDispatcher )
+ {
+ if ( pOldDispat )
+ {
+ SfxBindings* pBind = pOldDispat->GetBindings();
+ while ( pBind )
+ {
+ if ( pBind->pImp->pSubBindings == this && pBind->pDispatcher != pDisp )
+ pBind->SetSubBindings_Impl( NULL );
+ pBind = pBind->pImp->pSubBindings;
+ }
+ }
+
+ pDispatcher = pDisp;
+
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchProvider > xProv;
+ if ( pDisp )
+ xProv = ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchProvider >
+ ( pDisp->GetFrame()->GetFrame().GetFrameInterface(), UNO_QUERY );
+
+ SetDispatchProvider_Impl( xProv );
+ InvalidateAll( sal_True );
+ InvalidateUnoControllers_Impl();
+
+ if ( pDispatcher && !pOldDispat )
+ {
+ if ( pImp->pSubBindings && pImp->pSubBindings->pDispatcher != pOldDispat )
+ {
+ DBG_ERROR( "SubBindings vor Aktivieren schon gesetzt!" );
+ pImp->pSubBindings->ENTERREGISTRATIONS();
+ }
+ LEAVEREGISTRATIONS();
+ }
+ else if( !pDispatcher )
+ {
+ ENTERREGISTRATIONS();
+ if ( pImp->pSubBindings && pImp->pSubBindings->pDispatcher != pOldDispat )
+ {
+ DBG_ERROR( "SubBindings im Deaktivieren immer noch gesetzt!" );
+ pImp->pSubBindings->LEAVEREGISTRATIONS();
+ }
+ }
+
+ Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
+
+ if ( pDisp )
+ {
+ SfxBindings* pBind = pDisp->GetBindings();
+ while ( pBind && pBind != this )
+ {
+ if ( !pBind->pImp->pSubBindings )
+ {
+ pBind->SetSubBindings_Impl( this );
+ break;
+ }
+
+ pBind = pBind->pImp->pSubBindings;
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxBindings::ClearCache_Impl( sal_uInt16 nSlotId )
+{
+ GetStateCache(nSlotId)->ClearCache();
+}
+
+//--------------------------------------------------------------------
+void SfxBindings::StartUpdate_Impl( sal_Bool bComplete )
+{
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->StartUpdate_Impl( bComplete );
+
+ if ( !bComplete )
+ // Update darf unterbrochen werden
+ NextJob_Impl(&pImp->aTimer);
+ else
+ // alle Slots am St"uck updaten
+ NextJob_Impl(0);
+}
+
+//-------------------------------------------------------------------------
+
+SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, SfxPoolItem* &rpState )
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp;
+ SfxStateCache *pCache = GetStateCache( nSlot );
+ if ( pCache )
+ xDisp = pCache->GetDispatch();
+ if ( xDisp.is() || !pCache )
+ {
+ const SfxSlot* pSlot = SfxSlotPool::GetSlotPool( pDispatcher->GetFrame() ).GetSlot( nSlot );
+ if ( !pSlot || !pSlot->pUnoName )
+ return SFX_ITEM_DISABLED;
+
+ ::com::sun::star::util::URL aURL;
+ ::rtl::OUString aCmd( DEFINE_CONST_UNICODE(".uno:"));
+ aURL.Protocol = aCmd;
+ aURL.Path = ::rtl::OUString::createFromAscii(pSlot->GetUnoName());
+ aCmd += aURL.Path;
+ aURL.Complete = aCmd;
+ aURL.Main = aCmd;
+
+ if ( !xDisp.is() )
+ xDisp = pImp->xProv->queryDispatch( aURL, ::rtl::OUString(), 0 );
+
+ if ( xDisp.is() )
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xTunnel( xDisp, ::com::sun::star::uno::UNO_QUERY );
+ SfxOfficeDispatch* pDisp = NULL;
+ if ( xTunnel.is() )
+ {
+ sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
+ pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
+ }
+
+ if ( !pDisp )
+ {
+ BOOL bDeleteCache = FALSE;
+ if ( !pCache )
+ {
+ pCache = new SfxStateCache( nSlot );
+ pCache->GetSlotServer( *GetDispatcher_Impl(), pImp->xProv );
+ bDeleteCache = TRUE;
+ }
+
+ SfxItemState eState = SFX_ITEM_SET;
+ SfxPoolItem *pItem=NULL;
+ BindDispatch_Impl *pBind = new BindDispatch_Impl( xDisp, aURL, pCache, pSlot );
+ pBind->acquire();
+ xDisp->addStatusListener( pBind, aURL );
+ if ( !pBind->GetStatus().IsEnabled )
+ {
+ eState = SFX_ITEM_DISABLED;
+ }
+ else
+ {
+ ::com::sun::star::uno::Any aAny = pBind->GetStatus().State;
+ ::com::sun::star::uno::Type pType = aAny.getValueType();
+
+ if ( pType == ::getBooleanCppuType() )
+ {
+ sal_Bool bTemp = false;
+ aAny >>= bTemp ;
+ pItem = new SfxBoolItem( nSlot, bTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt16*)0) )
+ {
+ sal_uInt16 nTemp = 0;
+ aAny >>= nTemp ;
+ pItem = new SfxUInt16Item( nSlot, nTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt32*)0) )
+ {
+ sal_uInt32 nTemp = 0;
+ aAny >>= nTemp ;
+ pItem = new SfxUInt32Item( nSlot, nTemp );
+ }
+ else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
+ {
+ ::rtl::OUString sTemp ;
+ aAny >>= sTemp ;
+ pItem = new SfxStringItem( nSlot, sTemp );
+ }
+ else
+ pItem = new SfxVoidItem( nSlot );
+ }
+
+ xDisp->removeStatusListener( pBind, aURL );
+ pBind->Release();
+ rpState = pItem;
+ if ( bDeleteCache )
+ DELETEZ( pCache );
+ return eState;
+ }
+ }
+ }
+
+ // Dann am Dispatcher testen; da die von dort zur"uckgegebenen Items immer
+ // DELETE_ON_IDLE sind, mu\s eine Kopie davon gezogen werden, um einen
+ // Eigent"umer"ubergang zu erm"oglichen
+ const SfxPoolItem *pItem = NULL;
+ SfxItemState eState = pDispatcher->QueryState( nSlot, pItem );
+ if ( eState == SFX_ITEM_SET )
+ {
+ DBG_ASSERT( pItem, "SFX_ITEM_SET aber kein Item!" );
+ if ( pItem )
+ rpState = pItem->Clone();
+ }
+ else if ( eState == SFX_ITEM_AVAILABLE && pItem )
+ {
+ rpState = pItem->Clone();
+ }
+
+ return eState;
+}
+
+void SfxBindings::SetSubBindings_Impl( SfxBindings *pSub )
+{
+ if ( pImp->pSubBindings )
+ {
+ pImp->pSubBindings->SetDispatchProvider_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > () );
+ pImp->pSubBindings->pImp->pSuperBindings = NULL;
+ }
+
+ pImp->pSubBindings = pSub;
+
+ if ( pSub )
+ {
+ pImp->pSubBindings->SetDispatchProvider_Impl( pImp->xProv );
+ pSub->pImp->pSuperBindings = this;
+ }
+}
+
+SfxBindings* SfxBindings::GetSubBindings_Impl( sal_Bool bTop ) const
+{
+ SfxBindings *pRet = pImp->pSubBindings;
+ if ( bTop )
+ {
+ while ( pRet->pImp->pSubBindings )
+ pRet = pRet->pImp->pSubBindings;
+ }
+
+ return pRet;
+}
+
+void SfxBindings::SetWorkWindow_Impl( SfxWorkWindow* pWork )
+{
+ pImp->pWorkWin = pWork;
+}
+
+SfxWorkWindow* SfxBindings::GetWorkWindow_Impl() const
+{
+ return pImp->pWorkWin;
+}
+
+void SfxBindings::RegisterUnoController_Impl( SfxUnoControllerItem* pControl )
+{
+ if ( !pImp->pUnoCtrlArr )
+ pImp->pUnoCtrlArr = new SfxUnoControllerArr_Impl;
+ pImp->pUnoCtrlArr->Insert( pControl, pImp->pUnoCtrlArr->Count() );
+}
+
+void SfxBindings::ReleaseUnoController_Impl( SfxUnoControllerItem* pControl )
+{
+ if ( pImp->pUnoCtrlArr )
+ {
+ sal_uInt16 nPos = pImp->pUnoCtrlArr->GetPos( pControl );
+ if ( nPos != 0xFFFF )
+ {
+ pImp->pUnoCtrlArr->Remove( nPos );
+ return;
+ }
+ }
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->ReleaseUnoController_Impl( pControl );
+}
+
+void SfxBindings::InvalidateUnoControllers_Impl()
+{
+ if ( pImp->pUnoCtrlArr )
+ {
+ sal_uInt16 nCount = pImp->pUnoCtrlArr->Count();
+ for ( sal_uInt16 n=nCount; n>0; n-- )
+ {
+ SfxUnoControllerItem *pCtrl = (*pImp->pUnoCtrlArr)[n-1];
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > xRef( (::cppu::OWeakObject*)pCtrl, ::com::sun::star::uno::UNO_QUERY );
+ pCtrl->ReleaseDispatch();
+ pCtrl->GetNewDispatch();
+ }
+ }
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->InvalidateUnoControllers_Impl();
+}
+
+sal_Bool SfxBindings::IsInUpdate() const
+{
+ sal_Bool bInUpdate = pImp->bInUpdate;
+ if ( !bInUpdate && pImp->pSubBindings )
+ bInUpdate = pImp->pSubBindings->IsInUpdate();
+ return bInUpdate;
+}
+
+void SfxBindings::SetVisibleState( sal_uInt16 nId, sal_Bool bShow )
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp;
+ SfxStateCache *pCache = GetStateCache( nId );
+ if ( pCache )
+ pCache->SetVisibleState( bShow );
+}
+
+void SfxBindings::SetActiveFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > & rFrame )
+{
+ if ( rFrame.is() || !pDispatcher )
+ SetDispatchProvider_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > ( rFrame, ::com::sun::star::uno::UNO_QUERY ) );
+ else
+ SetDispatchProvider_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > (
+ pDispatcher->GetFrame()->GetFrame().GetFrameInterface(), ::com::sun::star::uno::UNO_QUERY ) );
+}
+
+const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SfxBindings::GetActiveFrame() const
+{
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( pImp->xProv, ::com::sun::star::uno::UNO_QUERY );
+ if ( xFrame.is() || !pDispatcher )
+ return xFrame;
+ else
+ return pDispatcher->GetFrame()->GetFrame().GetFrameInterface();
+}
+
+void SfxBindings::SetDispatchProvider_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & rProv )
+{
+ sal_Bool bInvalidate = ( rProv != pImp->xProv );
+ if ( bInvalidate )
+ {
+ pImp->xProv = rProv;
+ InvalidateAll( sal_True );
+ InvalidateUnoControllers_Impl();
+ }
+
+ if ( pImp->pSubBindings )
+ pImp->pSubBindings->SetDispatchProvider_Impl( pImp->xProv );
+}
+
+const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & SfxBindings::GetDispatchProvider_Impl() const
+{
+ return pImp->xProv;
+}
+
+SystemWindow* SfxBindings::GetSystemWindow() const
+{
+ SfxViewFrame *pFrame = pDispatcher->GetFrame();
+ while ( pFrame->GetParentViewFrame_Impl() )
+ pFrame = pFrame->GetParentViewFrame_Impl();
+ SfxViewFrame* pTop = pFrame->GetTopViewFrame();
+ return pTop->GetFrame().GetTopWindow_Impl();
+}
+
+BOOL SfxBindings::ExecuteCommand_Impl( const String& rCommand )
+{
+ ::com::sun::star::util::URL aURL;
+ aURL.Complete = rCommand;
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( aURL );
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp = pImp->xProv->queryDispatch( aURL, ::rtl::OUString(), 0 );
+ if ( xDisp.is() )
+ {
+ if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
+ {
+ ::rtl::OUString sAppName;
+ try
+ {
+ static ::rtl::OUString our_aModuleManagerName = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager =
+ ::comphelper::getProcessServiceFactory();
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager(
+ xServiceManager->createInstance(our_aModuleManagerName)
+ , ::com::sun::star::uno::UNO_QUERY_THROW);
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame(
+ pDispatcher->GetFrame()->GetFrame().GetFrameInterface(), UNO_QUERY_THROW);
+ sAppName = xModuleManager->identify(xFrame);
+ } catch(::com::sun::star::uno::Exception&) {}
+ Sequence<beans::PropertyValue> source;
+ ::comphelper::UiEventsLogger::appendDispatchOrigin(source, sAppName, ::rtl::OUString::createFromAscii("SfxAsyncExec"));
+ ::comphelper::UiEventsLogger::logDispatch(aURL, source);
+ }
+ new SfxAsyncExec_Impl( aURL, xDisp );
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > SfxBindings::GetRecorder() const
+{
+ return pImp->xRecorder;
+}
+
+void SfxBindings::SetRecorder_Impl( com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder >& rRecorder )
+{
+ pImp->xRecorder = rRecorder;
+}
+
+void SfxBindings::ContextChanged_Impl()
+{
+ if ( !pImp->bInUpdate && ( !pImp->bContextChanged || !pImp->bAllMsgDirty ) )
+ {
+ InvalidateAll( TRUE );
+ }
+}
+
+uno::Reference < frame::XDispatch > SfxBindings::GetDispatch( const SfxSlot* pSlot, const util::URL& aURL, sal_Bool bMasterCommand )
+{
+ uno::Reference < frame::XDispatch > xRet;
+ SfxStateCache* pCache = GetStateCache( pSlot->nSlotId );
+ if ( pCache && !bMasterCommand )
+ xRet = pCache->GetInternalDispatch();
+ if ( !xRet.is() )
+ {
+ // dispatches for slaves are unbound, they don't have a state
+ SfxOfficeDispatch* pDispatch = bMasterCommand ?
+ new SfxOfficeDispatch( pDispatcher, pSlot, aURL ) :
+ new SfxOfficeDispatch( *this, pDispatcher, pSlot, aURL );
+
+ pDispatch->SetMasterUnoCommand( bMasterCommand );
+ xRet = uno::Reference < frame::XDispatch >( pDispatch );
+ if ( !pCache )
+ pCache = GetStateCache( pSlot->nSlotId );
+
+ DBG_ASSERT( pCache, "No cache for OfficeDispatch!" );
+ if ( pCache && !bMasterCommand )
+ pCache->SetInternalDispatch( xRet );
+ }
+
+ return xRet;
+}
diff --git a/sfx2/source/control/ctrlitem.cxx b/sfx2/source/control/ctrlitem.cxx
new file mode 100644
index 000000000000..9376b81fa0ff
--- /dev/null
+++ b/sfx2/source/control/ctrlitem.cxx
@@ -0,0 +1,466 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <svl/itempool.hxx>
+#ifndef GCC
+#endif
+
+#include <sfx2/ctrlitem.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/msgpool.hxx>
+#include "statcach.hxx"
+#include <sfx2/viewfrm.hxx>
+
+//====================================================================
+
+DBG_NAME(SfxControllerItem);
+
+//--------------------------------------------------------------------
+#ifdef DBG_UTIL
+
+void SfxControllerItem::CheckConfigure_Impl( ULONG nType )
+{
+ // echter Slot? (also kein Separator etc.)
+ if ( !nId )
+ return;
+
+ // ist die Id "uberhaupt in 'nType' konfigurierbar?
+ const SfxSlot *pSlot = SFX_SLOTPOOL().GetSlot(nId);
+ DBG_ASSERTWARNING( pSlot, "SfxControllerItem: binding not existing slot" );
+ if ( pSlot && !pSlot->IsMode(nType) )
+ {
+ DBG_WARNING( "SfxControllerItem: slot without ...Config-flag" );
+ DbgOutf( "SfxControllerItem: Config-flag missing at SID %5d",
+ pSlot->GetSlotId() );
+ }
+}
+
+#endif
+
+//--------------------------------------------------------------------
+
+// returns the next registered SfxControllerItem with the same id
+
+SfxControllerItem* SfxControllerItem::GetItemLink()
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+ return pNext == this ? 0 : pNext;
+}
+
+//--------------------------------------------------------------------
+
+// returns TRUE if this binding is really bound to a function
+
+BOOL SfxControllerItem::IsBound() const
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+ return pNext != this;
+}
+
+//--------------------------------------------------------------------
+
+// returns the associated function-id or 0 if none
+
+// USHORT SfxControllerItem::GetId() const;
+
+//====================================================================
+
+// registeres with the id at the bindings
+
+void SfxControllerItem::Bind( USHORT nNewId, SfxBindings *pBindinx )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+ DBG_ASSERT(pBindings || pBindinx, "Keine Bindings");
+
+ if ( IsBound() ) {
+ DBG_ASSERT(pBindings, "Keine Bindings");
+ pBindings->Release(*this);
+ }
+
+ nId = nNewId;
+ pNext = 0;
+
+ if (pBindinx)
+ pBindings = pBindinx;
+ pBindings->Register(*this);
+}
+
+void SfxControllerItem::BindInternal_Impl( USHORT nNewId, SfxBindings *pBindinx )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+ DBG_ASSERT(pBindings || pBindinx, "Keine Bindings");
+
+ if ( IsBound() ) {
+ DBG_ASSERT(pBindings, "Keine Bindings");
+ pBindings->Release(*this);
+ }
+
+ nId = nNewId;
+ pNext = 0;
+
+ if (pBindinx)
+ pBindings = pBindinx;
+ pBindings->RegisterInternal_Impl(*this);
+}
+
+
+//====================================================================
+
+void SfxControllerItem::UnBind()
+
+/* [Beschreibung]
+
+ "ost die Verbindung dieses SfxControllerItems mit der SfxBindings-Instanz,
+ an der es zur Zeit gebunden ist. Ab diesem Zeitpunkt erh"alt es keine
+ Statusbenachrichtigungen (<SfxControllerItem::StateChented()>) mehr.
+
+
+ [Querverweise]
+
+ <SfxControllerItem::ReBind()>
+ <SfxControllerItem::ClearCache()>
+*/
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+ DBG_ASSERT(pBindings, "Keine Bindings");
+ DBG_ASSERT( IsBound(), "unbindings unbound SfxControllerItem" );
+
+ pBindings->Release(*this);
+ pNext = this;
+}
+
+//====================================================================
+
+void SfxControllerItem::ReBind()
+
+/* [Beschreibung]
+
+ Binded dieses SfxControllerItem wieder an die SfxBindings-Instanz,
+ an der es zuletzt gebunden war. Ab diesem Zeitpunkt erh"alt es wieder
+ Statusbenachrichtigungen (<SfxControllerItem::StateChented()>).
+
+
+ [Querverweise]
+
+ <SfxControllerItem::UnBind()>
+ <SfxControllerItem::ClearCache()>
+*/
+
+{
+ DBG_MEMTEST();
+DBG_CHKTHIS(SfxControllerItem, 0);
+ DBG_ASSERT(pBindings, "Keine Bindings");
+ DBG_ASSERT( !IsBound(), "bindings rebound SfxControllerItem" );
+
+ pBindings->Register(*this);
+}
+
+//====================================================================
+
+void SfxControllerItem::UpdateSlot()
+
+/* [Beschreibung]
+
+ Holt den Status 'hart' neu.
+
+ [Querverweise]
+
+ <SfxControllerItem::ClearCache()>
+*/
+
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+ DBG_ASSERT(pBindings, "Keine Bindings");
+
+ pBindings->Update( GetId() );
+}
+
+//--------------------------------------------------------------------
+
+void SfxControllerItem::ClearCache()
+
+/* [Beschreibung]
+
+ "oscht den Status-Cache f"ur dieses SfxControllerItem. D.h. beim
+ n"achsten Status-Update wird das <SfxPoolItem> auf jeden Fall geschickt,
+ auch wenn zuvor dasselbe geschickt wurde. Dies wird ben"otigt, wenn
+ ein Controller umgeschaltet werden kann und sich diesen Status
+ selbst merkt.
+
+
+ [Beispiel]
+
+ Der Kombi-Controller f"ur das Einstellen des Fl"achentyps und der
+ konkreten Auspr"agung (Farbe blau oder Schraffur X) kann im Typ
+ umgestellt werden, wird jedoch dann bei der n"achsten Selektion
+ wieder benachrichtigt, auch wenn es dieselben Daten sind.
+
+
+ [Querverweise]
+
+ <SfxControllerItem::UnBind()>
+ <SfxControllerItem::ReBind()>
+*/
+
+
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+ DBG_ASSERT(pBindings, "Keine Bindings");
+
+ pBindings->ClearCache_Impl( GetId() );
+}
+
+//--------------------------------------------------------------------
+
+// replaces the successor in the list of bindings of the same id
+
+SfxControllerItem* SfxControllerItem::ChangeItemLink( SfxControllerItem* pNewLink )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+ SfxControllerItem* pOldLink = pNext;
+ pNext = pNewLink;
+ return pOldLink == this ? 0 : pOldLink;
+}
+
+//--------------------------------------------------------------------
+
+// changes the id of unbound functions (e.g. for sub-menu-ids)
+
+void SfxControllerItem::SetId( USHORT nItemId )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+ DBG_ASSERT( !IsBound(), "changing id of bound binding" );
+ nId = nItemId;
+}
+
+//--------------------------------------------------------------------
+
+// creates a atomic item for a controller without registration
+
+SfxControllerItem::SfxControllerItem():
+ nId(0),
+ pNext(this),
+ pBindings(0)
+{
+ DBG_MEMTEST();
+ DBG_CTOR(SfxControllerItem, 0);
+}
+
+//--------------------------------------------------------------------
+
+// creates a representation of the function nId and registeres it
+
+SfxControllerItem::SfxControllerItem( USHORT nID, SfxBindings &rBindings ):
+ nId(nID),
+ pNext(this),
+ pBindings(&rBindings)
+{
+ DBG_MEMTEST();
+ DBG_CTOR(SfxControllerItem, 0);
+ Bind(nId, &rBindings);
+}
+
+//--------------------------------------------------------------------
+
+// unregisteres the item in the bindings
+
+SfxControllerItem::~SfxControllerItem()
+{
+ DBG_MEMTEST();
+ if ( IsBound() )
+ pBindings->Release(*this);
+ DBG_DTOR(SfxControllerItem, 0);
+}
+
+//--------------------------------------------------------------------
+
+void SfxControllerItem::StateChanged
+(
+ USHORT , // <SID> des ausl"osenden Slot
+ SfxItemState , // <SfxItemState> von 'pState'
+ const SfxPoolItem* // Slot-Status, ggf. 0 oder IsInvalidItem()
+)
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode wird vom SFx gerufen, um <SfxControllerItem>s
+ dar"uber zu benachrichtigen, da\s sich der Status des Slots 'nSID'
+ ge"andert hat. Der neue Wert sowie der von diesem Wert ermittelte
+ Status wird als 'pState' bzw. 'eState' mitgegeben.
+
+ Der Status eines Slots kann sich "andern, wenn z.B. das MDI-Fenster
+ gewechselt wird oder der Slot explizit mit <SfxBindings::Invalidate()>
+ invalidiert wurde.
+
+ Achtung! Die Methode wird nicht gerufen, wenn der Slot ung"ultig wurde,
+ danach jedoch wieder denselben Wert angenommen hat.
+
+ Diese Basisklasse braucht nicht gerufen zu werden, weitere Zwischenstufen
+ jedoch (z.B. <SfxToolboxControl>) sollten gerufen werden.
+*/
+
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+}
+
+//--------------------------------------------------------------------
+
+void SfxControllerItem::DeleteFloatingWindow()
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxControllerItem, 0);
+}
+
+//--------------------------------------------------------------------
+
+void SfxStatusForwarder::StateChanged
+(
+ USHORT nSID, // <SID> des ausl"osenden Slot
+ SfxItemState eState, // <SfxItemState> von 'pState'
+ const SfxPoolItem* pState // Slot-Status, ggf. 0 oder IsInvalidItem()
+)
+
+{
+ pMaster->StateChanged( nSID, eState, pState );
+}
+
+//--------------------------------------------------------------------
+
+SfxStatusForwarder::SfxStatusForwarder(
+ USHORT nSlotId,
+ SfxControllerItem& rMaster ):
+ SfxControllerItem( nSlotId, rMaster.GetBindings() ),
+ pMaster( &rMaster )
+{
+}
+
+//--------------------------------------------------------------------
+
+SfxItemState SfxControllerItem::GetItemState
+(
+ const SfxPoolItem* pState /* Pointer auf das <SfxPoolItem>, dessen
+ Status erfragt werden soll. */
+)
+
+/* [Beschreibung]
+
+ Statische Methode zum Ermitteln des Status des SfxPoolItem-Pointers,
+ in der Methode <SfxControllerItem::StateChanged(const SfxPoolItem*)>
+ zu verwenden.
+
+ [R"uckgabewert]
+
+ SfxItemState SFX_ITEM_UNKNOWN
+ Enabled, aber keine weitere Statusinformation
+ verf"ugbar. Typisch f"ur <Slot>s, die allenfalls
+ zeitweise disabled sind, aber ihre Darstellung sonst
+ nicht "andern.
+
+ SFX_ITEM_DISABLED
+ Disabled und keine weiter Statusinformation
+ verf"ugbar. Alle anderen ggf. angezeigten Werte sollten
+ auf den Default zur"uckgesetzt werden.
+
+ SFX_ITEM_DONTCARE
+ Enabled aber es waren nur uneindeutige Werte
+ verf"ugbar (also keine, die abgefragt werden k"onnen).
+
+ SFX_ITEM_AVAILABLE
+ Enabled und mit verf"ugbarem Wert, der von 'pState'
+ erfragbar ist. Der Typ ist dabei im gesamten
+ Programm eindeutig und durch den Slot festgelegt.
+*/
+
+{
+ return !pState
+ ? SFX_ITEM_DISABLED
+ : IsInvalidItem(pState)
+ ? SFX_ITEM_DONTCARE
+ : pState->ISA(SfxVoidItem) && !pState->Which()
+ ? SFX_ITEM_UNKNOWN
+ : SFX_ITEM_AVAILABLE;
+}
+
+//--------------------------------------------------------------------
+
+SfxMapUnit SfxControllerItem::GetCoreMetric() const
+
+/* [Beschreibung]
+
+ Holt vom zust"andigen Pool die Ma\seinheit ab, in der das Status-Item
+ vorliegt.
+*/
+
+{
+ SfxStateCache *pCache = pBindings->GetStateCache( nId );
+ SfxDispatcher *pDispat = pBindings->GetDispatcher_Impl();
+
+ if ( !pDispat )
+ {
+ SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+ if ( !pViewFrame )
+ SfxViewFrame::GetFirst();
+ if ( pViewFrame )
+ pDispat = pViewFrame->GetDispatcher();
+ }
+
+ if ( pDispat && pCache )
+ {
+ const SfxSlotServer *pServer = pCache->GetSlotServer( *pDispat );
+ if ( pServer )
+ {
+ SfxShell *pSh = pDispat->GetShell( pServer->GetShellLevel() );
+ SfxItemPool &rPool = pSh->GetPool();
+ USHORT nWhich = rPool.GetWhich( nId );
+ return rPool.GetMetric( nWhich );
+ }
+ }
+
+ DBG_WARNING( "W1: Can not find ItemPool!" );
+ return SFX_MAPUNIT_100TH_MM;
+}
+
+//------------------------------------------------------------------------
+
+#ifdef _MSC_VER
+#pragma optimize("g",off)
+#endif
+
+
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
new file mode 100755
index 000000000000..c08d713547a0
--- /dev/null
+++ b/sfx2/source/control/dispatch.cxx
@@ -0,0 +1,3180 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
+#include <com/sun/star/frame/XLayoutManager.hpp>
+#include <svl/itempool.hxx>
+#include <svl/itemiter.hxx>
+#include <svl/whiter.hxx>
+#include <svl/intitem.hxx>
+#ifndef _SFXEITEM_HXX //autogen
+#include <svl/eitem.hxx>
+#endif
+#include <svl/undo.hxx>
+#ifndef _WRKWIN_HXX //autogen
+#include <vcl/wrkwin.hxx>
+#endif
+#include <svtools/ttprops.hxx>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h> // wg. bsearch
+
+#define _SVSTDARR_ULONGS
+#include <svl/svstdarr.hxx>
+#include <svtools/helpopt.hxx>
+#include <com/sun/star/frame/XLayoutManager.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+#ifndef GCC
+#endif
+
+// wg. nAutoPageID
+#include "appdata.hxx"
+#include "sfx2/sfxhelp.hxx"
+#include <sfx2/dispatch.hxx>
+#include <sfx2/minstack.hxx>
+#include <sfx2/msg.hxx>
+#include <sfx2/objface.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/hintpost.hxx>
+#include "slotserv.hxx"
+#include <sfx2/ipclient.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/macrconf.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/childwin.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/mnumgr.hxx>
+#include "workwin.hxx"
+
+namespace css = ::com::sun::star;
+
+//==================================================================
+DBG_NAME(SfxDispatcherFlush)
+DBG_NAME(SfxDispatcherFillState)
+
+//==================================================================
+typedef SfxRequest* SfxRequestPtr;
+SV_IMPL_PTRARR( SfxItemPtrArray, SfxPoolItemPtr );
+SV_DECL_PTRARR_DEL( SfxRequestPtrArray, SfxRequestPtr, 4, 4 )
+SV_IMPL_PTRARR( SfxRequestPtrArray, SfxRequestPtr );
+
+DECL_PTRSTACK(SfxShellStack_Impl, SfxShell*, 8, 4 );
+//==================================================================
+
+struct SfxToDo_Impl
+{
+ SfxShell* pCluster;
+ bool bPush;
+ bool bDelete;
+ bool bUntil;
+
+ SfxToDo_Impl()
+ : pCluster(0)
+ , bPush(false)
+ , bDelete(false)
+ , bUntil(false)
+ {}
+ SfxToDo_Impl( bool bOpPush, bool bOpDelete, bool bOpUntil, SfxShell& rCluster )
+ : pCluster(&rCluster)
+ , bPush(bOpPush)
+ , bDelete(bOpDelete)
+ , bUntil(bOpUntil)
+ {}
+ ~SfxToDo_Impl(){}
+
+ bool operator==( const SfxToDo_Impl& rWith ) const
+ { return pCluster==rWith.pCluster && bPush==rWith.bPush; }
+};
+
+DECL_OBJSTACK(SfxToDoStack_Impl, SfxToDo_Impl, 8, 4);
+IMPL_OBJSTACK(SfxToDoStack_Impl, SfxToDo_Impl);
+
+struct SfxObjectBars_Impl
+{
+ sal_uInt32 nResId; // Resource - und ConfigId der Toolbox
+ sal_uInt16 nMode; // spezielle Sichtbarkeitsflags
+ String aName;
+ SfxInterface* pIFace;
+
+ SfxObjectBars_Impl() :
+ nResId( 0 )
+ {}
+};
+
+//------------------------------------------------------------------
+
+struct SfxDispatcher_Impl
+{
+ SfxRequestPtrArray aReqArr;
+ const SfxSlotServer* pCachedServ1; // zuletzt gerufene Message
+ const SfxSlotServer* pCachedServ2; // vorletzt gerufene Message
+ SfxShellStack_Impl aStack; // aktive Funktionalitaet
+ Timer aTimer; // fuers flushen
+ SfxToDoStack_Impl aToDoStack; // nicht abgearb. Push/Pop
+ SfxViewFrame* pFrame; // 0 oder zugeh"or. Frame
+ SfxDispatcher* pParent; // z.B. AppDispatcher, ggf. 0
+ SfxHintPosterRef xPoster; // asynchrones Execute
+ sal_Bool bFlushing; // sal_True waehrend Flush //?
+ sal_Bool bUpdated; // Update_Impl gelaufen
+ sal_Bool bLocked; // kein Execute
+ sal_Bool bInvalidateOnUnlock;// da fragte jemand
+ sal_Bool bActive; // nicht verwechseln mit gesetzt!
+ sal_Bool* pInCallAliveFlag; // dem Stack den Dtor anzeigen
+ SfxObjectBars_Impl aObjBars[SFX_OBJECTBAR_MAX];
+ SfxObjectBars_Impl aFixedObjBars[SFX_OBJECTBAR_MAX];
+ SvULongs aChildWins;
+ sal_uInt16 nActionLevel; // in EnterAction
+ sal_uInt32 nEventId; // EventId UserEvent
+ sal_Bool bUILocked; // Update abgeklemmt (!zappeln)
+ sal_Bool bNoUI; // UI nur vom Parent Dispatcher
+ sal_Bool bReadOnly; // Dokument ist ReadOnly
+ sal_Bool bQuiet; // nur parent dispatcher verwenden
+ sal_Bool bModal; // nur Slots vom Parent-Dispatcher
+
+ sal_Bool bFilterEnabling; // sal_True=filter enabled slots, 2==ReadOnlyDoc uebersteuert
+ sal_uInt16 nFilterCount; // Anzahl der SIDs in pFilterSIDs
+ const sal_uInt16* pFilterSIDs; // sortiertes Array von SIDs
+ sal_uInt16 nStandardMode; // ExecuteMode f. PlugInDispatcher
+ SvUShorts* pDisableList;
+ sal_uInt32 nDisableFlags;
+};
+
+#define NO_OBJECTBAR 0
+#define OWN_OBJECTBAR 1
+#define OTHER_OBJECTBAR 2
+
+//------------------------------------------------------------------
+
+#define SFX_FLUSH_TIMEOUT 50
+
+//====================================================================
+sal_Bool SfxDispatcher::IsLocked( sal_uInt16 ) const
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann festgestellt werden, ob der SfxDispatcher
+ gesperrt oder freigegeben ist. Ein gesperrter SfxDispatcher
+ f"uhrt keine <SfxRequest>s mehr aus und liefert keine
+ Status-Informationen mehr. Er verh"alt sich so als w"aren alle
+ Slots disabled.
+
+ Der Dispatcher gilt auch als gesperrt, wenn alle Dispatcher
+ gelockt sind (<SfxApplication::LockDispatcher()>) oder der zugeh"orige
+ Top-Frame im modal-mode ist und der angegebene Slot Frame-spezifisch
+ (also nicht von der Application) bedient wird.
+*/
+
+{
+ return pImp->bLocked;
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxDispatcher::IsAppDispatcher() const
+
+/* [Beschreibung]
+
+ Mit dieser Methode l"a\st sich festellen, ob der SfxDispacher der
+ Applikations-Dispatcher ist.
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Es ist der Applikations-Dispatcher.
+
+ sal_False
+ Es ist ein Dispatcher eines SfxViewFrame.
+*/
+
+{
+ return !pImp->pFrame;
+}
+
+//--------------------------------------------------------------------
+int SfxDispatcher::Call_Impl( SfxShell& rShell, const SfxSlot &rSlot, SfxRequest &rReq, sal_Bool bRecord )
+
+/* [Beschreibung]
+
+ Hilfsfunktion zum pr"ufen, ob ein Slot executed werden darf und
+ der Execution selbst.
+*/
+
+{
+ SFX_STACK(SfxDispatcher::Call_Impl);
+
+ // darf der Slot gerufen werden (i.S.v. enabled)
+ if ( rSlot.IsMode(SFX_SLOT_FASTCALL) || rShell.CanExecuteSlot_Impl(rSlot) )
+ {
+ if ( GetFrame() )
+ {
+ // ggf. Recording anwerfen
+ com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
+ GetFrame()->GetFrame().GetFrameInterface(),
+ com::sun::star::uno::UNO_QUERY);
+
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
+ xFrame,
+ com::sun::star::uno::UNO_QUERY);
+
+ if ( xSet.is() )
+ {
+ com::sun::star::uno::Any aProp = xSet->getPropertyValue(::rtl::OUString::createFromAscii("DispatchRecorderSupplier"));
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
+ aProp >>= xSupplier;
+ if(xSupplier.is())
+ xRecorder = xSupplier->getDispatchRecorder();
+
+ if ( bRecord && xRecorder.is() && !rSlot.IsMode(SFX_SLOT_NORECORD) )
+ rReq.Record_Impl( rShell, rSlot, xRecorder, GetFrame() );
+ }
+ }
+
+ // Alles holen, was gebraucht wird, da der Slot den Execute evtl. nicht
+ // "uberlebt, falls es ein 'Pseudoslot' f"ur Macros oder Verben ist
+ sal_Bool bAutoUpdate = rSlot.IsMode(SFX_SLOT_AUTOUPDATE);
+
+ // API-Call-Klammerung und Document-Lock w"ahrend des Calls
+ {
+ // 'this' mu\s im Dtor bescheid sagen
+ sal_Bool bThisDispatcherAlive = sal_True;
+ sal_Bool *pOldInCallAliveFlag = pImp->pInCallAliveFlag;
+ pImp->pInCallAliveFlag = &bThisDispatcherAlive;
+
+ SfxViewFrame* pView = GetFrame();
+ if ( !pView )
+ pView = SfxViewFrame::Current();
+ if ( pView )
+ {
+ rtl::OString aCmd(".uno:");
+ aCmd += rSlot.GetUnoName();
+ SfxHelp::OpenHelpAgent( &pView->GetFrame(), aCmd );
+ }
+
+ SfxExecFunc pFunc = rSlot.GetExecFnc();
+ rShell.CallExec( pFunc, rReq );
+
+ // falls 'this' noch lebt
+ if ( bThisDispatcherAlive )
+ pImp->pInCallAliveFlag = pOldInCallAliveFlag;
+ else
+ {
+ if ( pOldInCallAliveFlag )
+ {
+ // auch verschachtelte Stack-Frames sch"utzen
+ *pOldInCallAliveFlag = sal_False;
+ }
+
+ // do nothing after this object is dead
+ return rReq.IsDone();
+ }
+ }
+
+ if ( rReq.IsDone() )
+ {
+ SfxBindings *pBindings = GetBindings();
+
+ // bei AutoUpdate sofort updaten; "Pseudoslots" d"urfen nicht
+ // Autoupdate sein!
+ if ( bAutoUpdate && pBindings )
+ {
+ const SfxSlot* pSlave = rSlot.GetLinkedSlot();
+ if (pSlave)
+ {
+ // bei Enum-Slots irgendeinen gebundenen Slave-Slot nehmen
+ while (!pBindings->IsBound(pSlave->GetSlotId()) && pSlave != &rSlot )
+ pSlave = pSlave->GetLinkedSlot();
+ pBindings->Invalidate(pSlave->GetSlotId());
+ pBindings->Update(pSlave->GetSlotId());
+ }
+ else
+ {
+ pBindings->Invalidate(rSlot.GetSlotId());
+ pBindings->Update(rSlot.GetSlotId());
+ }
+ }
+
+ return sal_True;
+ }
+ }
+
+ return sal_False;
+}
+
+//====================================================================
+void SfxDispatcher::Construct_Impl( SfxDispatcher* pParent )
+{
+ pImp = new SfxDispatcher_Impl;
+ bFlushed = sal_True;
+ SfxApplication *pSfxApp = SFX_APP();
+
+ pImp->pCachedServ1 = 0;
+ pImp->pCachedServ2 = 0;
+ pImp->bFlushing = sal_False;
+ pImp->bUpdated = sal_False;
+ pImp->bLocked = sal_False;
+ pImp->bActive = sal_False;
+ pImp->pParent = NULL;
+ pImp->bUILocked = sal_False;
+ pImp->bNoUI = sal_False;
+ pImp->bReadOnly = sal_False;
+ pImp->bQuiet = sal_False;
+ pImp->bModal = sal_False;
+ pImp->pInCallAliveFlag = 0;
+ pImp->bFilterEnabling = sal_False;
+ pImp->nFilterCount = 0;
+ pImp->pFilterSIDs = 0;
+ pImp->nStandardMode = 0;
+ pImp->pDisableList = pSfxApp->GetDisabledSlotList_Impl();
+ pImp->nDisableFlags = 0;
+
+ pImp->pParent = pParent;
+
+ pImp->bInvalidateOnUnlock = sal_False;
+ pImp->nActionLevel = 0;
+
+ for (sal_uInt16 n=0; n<SFX_OBJECTBAR_MAX; n++)
+ pImp->aObjBars[n].nResId = 0;
+
+ GenLink aGenLink( LINK(this, SfxDispatcher, PostMsgHandler) );
+
+ pImp->xPoster = new SfxHintPoster(aGenLink);
+
+ pImp->aTimer.SetTimeout(SFX_FLUSH_TIMEOUT);
+ pImp->aTimer.SetTimeoutHdl( LINK(this, SfxDispatcher, EventHdl_Impl ) );
+}
+
+SfxDispatcher::SfxDispatcher( SfxDispatcher* pParent )
+{
+ Construct_Impl( pParent );
+ pImp->pFrame = 0;
+}
+
+SfxDispatcher::SfxDispatcher( SfxViewFrame *pViewFrame )
+
+/* [Beschreibung]
+
+ Der Konstruktor der Klasse SfxDispatcher legt einen leeren Stack
+ von <SfxShell>-Pointern an. Er ist initial nicht gelockt und gilt als
+ geflusht.
+*/
+
+{
+ if ( pViewFrame )
+ {
+ SfxViewFrame *pFrame = pViewFrame->GetParentViewFrame();
+ if ( pFrame )
+ Construct_Impl( pFrame->GetDispatcher() );
+ else
+ Construct_Impl( 0 );
+ }
+ else
+ Construct_Impl( 0 );
+ pImp->pFrame = pViewFrame;
+}
+
+//====================================================================
+SfxDispatcher::~SfxDispatcher()
+
+/* [Beschreibung]
+
+ Der Destruktor der Klasse SfxDispatcher darf nicht gerufen werden,
+ wenn die SfxDispatcher-Instanz aktiv ist. Es d"urfen sich allerdings
+ noch <SfxShell>-Pointer auf dem Stack befinden.
+*/
+
+{
+#ifdef DBG_UTIL
+ ByteString sTemp( "Delete Dispatcher " );
+ sTemp += ByteString::CreateFromInt64( (sal_uIntPtr)this );
+ DBG_TRACE( sTemp.GetBuffer() );
+ DBG_ASSERT( !pImp->bActive, "deleting active Dispatcher" );
+#endif
+
+ // Damit in LeaveRegistrations kein Timer per Reschedule in PlugComm
+ // zuschlaegt
+ pImp->aTimer.Stop();
+ pImp->xPoster->SetEventHdl( Link() );
+
+ // die Stack-Varialblem in Call_Impl benachrichtigen
+ if ( pImp->pInCallAliveFlag )
+ *pImp->pInCallAliveFlag = sal_False;
+
+ // Bindings und App besorgen
+ SfxApplication *pSfxApp = SFX_APP();
+ SfxBindings* pBindings = GetBindings();
+
+// if (pImp->nEventId)
+// pSfxApp->RemoveEventHdl(pImp->nEventId);
+
+ // wenn noch nicht flushed, die Bindings wiederbeleben
+ if ( pBindings && !pSfxApp->IsDowning() && !bFlushed )
+ pBindings->DLEAVEREGISTRATIONS();
+
+ // ggf. bei den Bindings abmelden
+ while ( pBindings )
+ {
+ if ( pBindings->GetDispatcher_Impl() == this)
+ pBindings->SetDispatcher(0);
+ pBindings = pBindings->GetSubBindings_Impl();
+ }
+
+ delete pImp;
+}
+
+//====================================================================
+void SfxDispatcher::Pop
+(
+ SfxShell& rShell, /* Die vom Stack zu nehmende SfxShell-Instanz. */
+
+ sal_uInt16 nMode /* SFX_SHELL_POP_UNTIL
+ Es werden auch alle "uber 'rShell' liegenenden
+ SfxShell's vom Stack genommen.
+
+ SFX_SHELL_POP_DELETE
+ Alle tats"achlich vom Stack genommenen
+ SfxShells werden gel"oscht.
+
+ SFX_SHELL_PUSH (InPlace use only)
+ Die Shell wird gepusht. */
+)
+/* [Beschreibung]
+
+ Mit dieser Methode wird eine oder mehrere <SfxShell> vom SfxDispatcher
+ gepoppt. Die SfxShell wird zun"achst zum poppen vermerkt und
+ es wird ein Timer aufgesetzt. Erst bei Ablauf des Timers wird
+ tats"achlich gepoppt (<SfxDispatcher::Flush()>) und die <SfxBindings>
+ werden invalidiert. W"ahrend der Timer l"auft gleichen sich
+ entgegengesetzte Push und Pop Befehle mit derselben SfxShell aus.
+*/
+
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( rShell.GetInterface(),
+ "pushing SfxShell without previous RegisterInterface()" );
+ DBG_ASSERT( pImp->nActionLevel == 0, "Push or Pop within Action" );
+// DBG_ASSERT( SFX_APP()->IsInAsynchronCall_Impl(),
+// "Dispatcher Push/Pop in synchron-call-stack" );
+
+ bool bDelete = (nMode & SFX_SHELL_POP_DELETE) == SFX_SHELL_POP_DELETE;
+ bool bUntil = (nMode & SFX_SHELL_POP_UNTIL) == SFX_SHELL_POP_UNTIL;
+ bool bPush = (nMode & SFX_SHELL_PUSH) == SFX_SHELL_PUSH;
+
+ SfxApplication *pSfxApp = SFX_APP();
+
+#ifdef DBG_UTIL
+ ByteString aMsg( "-SfxDispatcher(" );
+ aMsg += ByteString::CreateFromInt64( (sal_uIntPtr) this );
+ aMsg += bPush ? ")::Push(" : ")::Pop(";
+ if ( rShell.GetInterface() )
+ aMsg += rShell.GetInterface()->GetClassName();
+ else
+ aMsg += ByteString::CreateFromInt64( (sal_uIntPtr) &rShell );
+ aMsg += bDelete ? ") with delete" : ")";
+ if ( bUntil ) aMsg += " (up to)";
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+
+ // gleiche Shell wie on-Top des ToDo-Stacks?
+ if ( pImp->aToDoStack.Count() && pImp->aToDoStack.Top().pCluster == &rShell )
+ {
+ // inverse Actions heben sich auf
+ if ( pImp->aToDoStack.Top().bPush != bPush )
+ pImp->aToDoStack.Pop();
+ else
+ {
+ DBG_ASSERT( bPush, "SfxInterface pushed more than once" );
+ DBG_ASSERT( !bPush, "SfxInterface popped more than once" );
+ }
+ }
+ else
+ {
+ // ::com::sun::star::chaos::Action merken
+ pImp->aToDoStack.Push( SfxToDo_Impl(bPush, bDelete, bUntil, rShell) );
+ if ( bFlushed )
+ {
+ DBG_TRACE("Unflushed dispatcher!");
+ bFlushed = sal_False;
+ pImp->bUpdated = sal_False;
+
+ // Bindings schlafen legen
+ SfxBindings* pBindings = GetBindings();
+ if ( pBindings )
+ pBindings->DENTERREGISTRATIONS();
+ }
+ }
+
+ if ( !pSfxApp->IsDowning() && pImp->aToDoStack.Count() )
+ {
+ //! if (SFX_APP()->AnyInput(INPUT_KEYBOARD | INPUT_MOUSE) )
+ //! AnyInput haut nicht hin; hier muss noch ein Kriterium gefunden
+ //! werden. Solange wieder immer mit Timer.
+
+ if (sal_True)
+ {
+ // Kein sofortiges Update gewuenscht
+ pImp->aTimer.SetTimeout(SFX_FLUSH_TIMEOUT);
+ pImp->aTimer.SetTimeoutHdl( LINK(this, SfxDispatcher, EventHdl_Impl ) );
+ pImp->aTimer.Start();
+ }
+ else
+ {
+ // Schnellstmoegliches Update (sollte Normalfall sein)
+ pImp->aTimer.Stop();
+ GetpApp()->PostUserEvent(pImp->nEventId, (void*)0);
+ }
+ }
+ else
+ {
+ // doch nichts zu tun
+ pImp->aTimer.Stop();
+
+ // ggf. Bindings wieder aufwecken
+ if ( !pImp->aToDoStack.Count() )
+ {
+ SfxBindings* pBindings = GetBindings();
+ if ( pBindings )
+ pBindings->DLEAVEREGISTRATIONS();
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxDispatcher, EventHdl_Impl, void *, pvoid )
+
+/* [Beschreibung]
+
+ Dieser Handler wird nach <SfxDispatcher::Invalidate()> oder Bewegungen
+ auf dem Stack (<SfxDispatcher::Push()> und <SfxDispatcher::Pop()) gerufen.
+
+ Er flusht den Stack, falls er dirty ist, f"uhrt also die ausstehenden
+ Push und Pop Befehle tats"achlich aus.
+*/
+
+{
+ (void)pvoid; // unused
+ DBG_MEMTEST();
+
+ Flush();
+ Update_Impl();
+ SfxBindings* pBindings = GetBindings();
+ if ( pBindings )
+ pBindings->StartUpdate_Impl(sal_False);
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxDispatcher, EventHdl_Impl, void *, pvoid )
+
+//--------------------------------------------------------------------
+sal_Bool SfxDispatcher::CheckVirtualStack( const SfxShell& rShell, sal_Bool bDeep )
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann gepr"uft werden, ob sich die <SfxShell> rShell
+ auf dem Stack befindet, wenn er geflusht w"are. Dabei wird der
+ SfxDispatcher jedoch nicht tats"achlich geflusht.
+
+ Diese Methode ist u.a. dazu gedacht, Assertions zu erm"oglichen, ohne
+ als Seiteneffekt den SfxDispathcer flushen zu m"ussen.
+*/
+
+{
+ DBG_MEMTEST();
+ SFX_STACK(SfxDispatcher::CheckVirtualStack);
+
+ SfxShellStack_Impl aStack( pImp->aStack );
+ for ( short nToDo = pImp->aToDoStack.Count()-1; nToDo >= 0; --nToDo )
+ {
+ SfxToDo_Impl aToDo( pImp->aToDoStack.Top(nToDo) );
+ if ( aToDo.bPush )
+ aStack.Push( (SfxShell*) aToDo.pCluster );
+ else
+ {
+ SfxShell* pPopped = 0;
+ do
+ {
+ DBG_ASSERT( aStack.Count(), "popping from empty stack" );
+ pPopped = aStack.Pop();
+ }
+ while ( aToDo.bUntil && pPopped != aToDo.pCluster );
+ DBG_ASSERT( pPopped == aToDo.pCluster, "popping unpushed SfxInterface" );
+ }
+ }
+
+ sal_Bool bReturn;
+ if ( bDeep )
+ bReturn = aStack.Contains(&rShell);
+ else
+ bReturn = aStack.Top() == &rShell;
+ return bReturn;
+}
+
+//--------------------------------------------------------------------
+sal_uInt16 SfxDispatcher::GetShellLevel( const SfxShell& rShell )
+
+/* [Beschreibung]
+
+ Ermittelt die Position einer SfxShell im Stack des Dispatchers.
+ Dazu wird dieser ggf. zuvor geflusht.
+
+
+ [Rueckgabewert]
+
+ sal_uInt16 == USRT_MAX
+ Die SfxShell befindet sich nicht auf
+ diesem SfxDispatcher.
+
+ < USHRT_MAX
+ Position der SfxShell auf dem Dispatcher
+ von oben mit 0 beginnend gez"ahlt.
+*/
+
+{
+ DBG_MEMTEST();
+ SFX_STACK(SfxDispatcher::GetShellLevel);
+ Flush();
+
+ for ( sal_uInt16 n = 0; n < pImp->aStack.Count(); ++n )
+ if ( pImp->aStack.Top( n ) == &rShell )
+ return n;
+ if ( pImp->pParent )
+ {
+ sal_uInt16 nRet = pImp->pParent->GetShellLevel(rShell);
+ if ( nRet == USHRT_MAX )
+ return nRet;
+ return nRet + pImp->aStack.Count();
+ }
+
+ return USHRT_MAX;
+}
+
+//--------------------------------------------------------------------
+SfxShell *SfxDispatcher::GetShell(sal_uInt16 nIdx) const
+
+/* [Beschreibung]
+
+ Liefert einen Pointer auf die <SfxShell>, welche sich an der Position
+ nIdx (von oben, letzt-gepushte liegt bei 0) auf dem Stack befindet.
+
+ Dabei wird der SfxDispatcher nicht geflusht.
+
+ Ist der Stack nicht tief genug, wird ein 0-Pointer zur"uckgegeben.
+*/
+
+{
+ DBG_MEMTEST();
+
+ sal_uInt16 nShellCount = pImp->aStack.Count();
+ if ( nIdx < nShellCount )
+ return pImp->aStack.Top(nIdx);
+ else if ( pImp->pParent )
+ return pImp->pParent->GetShell( nIdx - nShellCount );
+ return 0;
+}
+
+//--------------------------------------------------------------------
+SfxBindings* SfxDispatcher::GetBindings() const
+
+/* [Beschreibung]
+
+ Diese Methode liefert einen Pointer auf die <SfxBindings> Instanz
+ zur"uck, an die der SfxDispatcher gerade gebunden ist. Ein SfxDispatcher
+ ist nur dann an SfxBindings gebunden, wenn er <UI-aktiv> ist. Ist
+ er nicht UI-aktiv, wird ein 0-Pointer zur"uckgegeben.
+
+ Der zur"uckgegebene Pointer ist nur im <unmittelbaren Kontext> des
+ Methodenaufrufs g"ultig.
+*/
+
+{
+ if ( pImp->pFrame )
+ return &pImp->pFrame->GetBindings();
+ else
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+SfxViewFrame* SfxDispatcher::GetFrame() const
+
+/* [Beschreibung]
+
+ Liefert einen Pointer auf die <SfxViewFrame> Instanz, der dieser
+ SfxDispatcher geh"ort. Falls es sich um den Applikations-Dispatcher
+ handelt, wird ein 0-Pointer zur"uckgegeben.
+*/
+
+{
+ DBG_MEMTEST();
+ return pImp->pFrame;
+}
+
+//--------------------------------------------------------------------
+void SfxDispatcher::DoActivate_Impl( sal_Bool bMDI, SfxViewFrame* /* pOld */ )
+
+/* [Beschreibung]
+
+ Diese Methode steuert das Aktivieren eines Dispatchers.
+
+ Da der Applikations-Dispatcher immer aktiv ist, entweder als
+ Unterdispatcher des <SfxViewFrame>-Dispatchers oder selbst, wird
+ er nie als ganzes Aktiviert, sondern nur seine einzelnen <SfxShell>s
+ bei <SfxDispatcher::Push(SfxShell&)>.
+
+ Beim Aktivieren eines SfxDispatchers wird an allen auf seinem
+ Stack befindlichen SfxShells, beginnend mit der untersten, der Handler
+ <SfxShell::Activate(sal_Bool)> gerufen.
+*/
+
+{
+ DBG_MEMTEST();
+ SFX_STACK(SfxDispatcher::DoActivate);
+ if ( bMDI )
+ {
+ #ifdef DBG_UTIL
+ ByteString sTemp("Activate Dispatcher ");
+ sTemp += ByteString::CreateFromInt64( (sal_uIntPtr) this );
+ DBG_TRACE(sTemp.GetBuffer());
+ DBG_ASSERT( !pImp->bActive, "Activate-Fehler" );
+ #endif
+ pImp->bActive = sal_True;
+ pImp->bUpdated = sal_False;
+ SfxBindings* pBindings = GetBindings();
+ if ( pBindings )
+ {
+ pBindings->SetDispatcher(this);
+ pBindings->SetActiveFrame( pImp->pFrame->GetFrame().GetFrameInterface() );
+ }
+ }
+ else
+ {
+ #ifdef DBG_UTIL
+ ByteString sTemp("Non-MDI-Activate Dispatcher");
+ sTemp += ByteString::CreateFromInt64( (sal_uIntPtr) this );
+ DBG_TRACE( sTemp.GetBuffer() );
+ #endif
+ }
+
+ if ( IsAppDispatcher() )
+ return;
+
+ for ( int i = int(pImp->aStack.Count()) - 1; i >= 0; --i )
+ pImp->aStack.Top( (sal_uInt16) i )->DoActivate_Impl(pImp->pFrame, bMDI);
+
+ if ( bMDI && pImp->pFrame )
+ {
+ //SfxWorkWindow *pWorkWin = pImp->pFrame->GetFrame().GetWorkWindow_Impl();
+ SfxBindings *pBind = GetBindings();
+ while ( pBind )
+ {
+ pBind->HidePopupCtrls_Impl( FALSE );
+ pBind = pBind->GetSubBindings_Impl();
+ }
+
+ pImp->pFrame->GetFrame().GetWorkWindow_Impl()->HidePopups_Impl( FALSE, FALSE, 1 );
+ }
+
+ if ( pImp->aToDoStack.Count() )
+ {
+ if (sal_True)
+ {
+ // Kein sofortiges Update gewuenscht
+ pImp->aTimer.SetTimeout(SFX_FLUSH_TIMEOUT);
+ pImp->aTimer.SetTimeoutHdl( LINK(this, SfxDispatcher, EventHdl_Impl ) );
+ pImp->aTimer.Start();
+ }
+ else
+ {
+ // Schnellstmoegliches Update (sollte Normalfall sein)
+ pImp->aTimer.Stop();
+ GetpApp()->PostUserEvent(pImp->nEventId, (void*)0);
+ }
+ }
+}
+
+void SfxDispatcher::DoParentActivate_Impl()
+{
+ for ( int i = int(pImp->aStack.Count()) - 1; i >= 0; --i )
+ pImp->aStack.Top( (sal_uInt16) i )->ParentActivate();
+}
+
+//--------------------------------------------------------------------
+void SfxDispatcher::DoDeactivate_Impl( sal_Bool bMDI, SfxViewFrame* pNew )
+
+/* [Beschreibung]
+
+ Diese Methode steuert das Deaktivieren eines Dispatchers.
+
+ Da der Applikations-Dispatcher immer aktiv ist, entweder als
+ Unterdispatcher des <SfxViewFrame>-Dispatchers oder selbst, wird
+ er nie als ganzes Deaktiviert, sondern nur seine einzelnen <SfxShell>s
+ bei <SfxDispatcher::Pop(SfxShell&)>.
+
+ Beim Deaktivieren eines SfxDispatchers wird an allen auf seinem
+ Stack befindlichen SfxShells, beginnend mit der obersten, der Handler
+ <SfxShell::Deactivate(sal_Bool)> gerufen.
+*/
+
+{
+ DBG_MEMTEST();
+ SFX_STACK(SfxDispatcher::DoDeactivate);
+
+ SfxApplication *pSfxApp = SFX_APP();
+
+ if ( bMDI )
+ {
+ DBG_TRACE(ByteString("Deactivate Dispatcher ").Append(ByteString::CreateFromInt64( (sal_uIntPtr) this )).GetBuffer());
+ DBG_ASSERT( pImp->bActive, "Deactivate-Fehler" );
+ pImp->bActive = sal_False;
+
+ if ( pImp->pFrame && !(pImp->pFrame->GetObjectShell()->IsInPlaceActive() ) )
+ {
+ SfxWorkWindow *pWorkWin = pImp->pFrame->GetFrame().GetWorkWindow_Impl();
+ if ( pWorkWin )
+ {
+ for (sal_uInt16 n=0; n<pImp->aChildWins.Count();)
+ {
+ SfxChildWindow *pWin = pWorkWin->GetChildWindow_Impl( (sal_uInt16) ( pImp->aChildWins[n] & 0xFFFF ) );
+ if (!pWin || (pWin && pWin->GetAlignment() == SFX_ALIGN_NOALIGNMENT))
+ pImp->aChildWins.Remove(n);
+ else
+ n++;
+ }
+ }
+ }
+ }
+ else {
+ DBG_TRACE( ByteString ("Non-MDI-DeActivate Dispatcher").Append(ByteString::CreateFromInt64( (sal_uIntPtr) this )).GetBuffer() );
+ }
+
+ if ( IsAppDispatcher() && !pSfxApp->IsDowning() )
+ return;
+
+ for ( sal_uInt16 i = 0; i < pImp->aStack.Count(); ++i )
+ pImp->aStack.Top(i)->DoDeactivate_Impl(pImp->pFrame, bMDI);
+
+ BOOL bHidePopups = bMDI && pImp->pFrame;
+ if ( pNew && pImp->pFrame )
+ {
+ com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xOldFrame(
+ pNew->GetFrame().GetFrameInterface()->getCreator(), com::sun::star::uno::UNO_QUERY );
+
+ com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xMyFrame(
+ GetFrame()->GetFrame().GetFrameInterface(), com::sun::star::uno::UNO_QUERY );
+
+ if ( xOldFrame == xMyFrame )
+ bHidePopups = FALSE;
+ }
+
+ if ( bHidePopups )
+ {
+ //SfxWorkWindow *pWorkWin = pImp->pFrame->GetFrame().GetWorkWindow_Impl();
+ SfxBindings *pBind = GetBindings();
+ while ( pBind )
+ {
+ pBind->HidePopupCtrls_Impl( TRUE );
+ pBind = pBind->GetSubBindings_Impl();
+ }
+
+ pImp->pFrame->GetFrame().GetWorkWindow_Impl()->HidePopups_Impl( TRUE, FALSE, 1 );
+ }
+
+ Flush();
+}
+
+void SfxDispatcher::DoParentDeactivate_Impl()
+{
+ for ( int i = int(pImp->aStack.Count()) - 1; i >= 0; --i )
+ pImp->aStack.Top( (sal_uInt16) i )->ParentDeactivate();
+}
+
+//--------------------------------------------------------------------
+int SfxDispatcher::GetShellAndSlot_Impl
+(
+ sal_uInt16 nSlot, // die zu suchende Slot-Id
+ SfxShell** ppShell, // die SfxShell, welche nSlot z.Zt. bedient
+ const SfxSlot** ppSlot, // der SfxSlot, welcher nSlot z.Zt. bedient
+ sal_Bool bOwnShellsOnly,
+ sal_Bool bModal, // trotz ModalMode
+ sal_Bool bRealSlot
+)
+
+/* [Beschreibung]
+
+ Diese Methode sucht im SfxDispatcher nach der <SfxShell>, von der
+ die Slot-Id nSlot zur Zeit bedient wird. Dazu wird der Dispatcher
+ zuvor geflusht.
+
+
+ [R"uckgabewert]
+
+ int sal_True
+ Die SfxShell wurde gefunden, ppShell und ppSlot
+ sind g"ultig.
+
+ sal_True
+ Die SfxShell wurde nicht gefunden, ppShell und ppSlot
+ sind ung"ultig.
+*/
+
+{
+ SFX_STACK(SfxDispatcher::GetShellAndSlot_Impl);
+
+ Flush();
+ SfxSlotServer aSvr;
+ if ( _FindServer(nSlot, aSvr, bModal) )
+ {
+ if ( bOwnShellsOnly && aSvr.GetShellLevel() >= pImp->aStack.Count() )
+ return sal_False;
+
+ *ppShell = GetShell(aSvr.GetShellLevel());
+ *ppSlot = aSvr.GetSlot();
+ if ( 0 == (*ppSlot)->GetExecFnc() && bRealSlot )
+ *ppSlot = (*ppShell)->GetInterface()->GetRealSlot(*ppSlot);
+ // Check only real slots as enum slots don't have an execute function!
+ if ( bRealSlot && ((0 == *ppSlot) || (0 == (*ppSlot)->GetExecFnc()) ))
+ return sal_False;
+
+#ifdef DBG_UTILx
+ ByteString aMsg( nSlot );
+ aMsg += " found in ";
+ aMsg += (*ppShell)->GetInterface()->GetClassName();
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+
+ return sal_True;
+ }
+
+#ifdef DBG_UTILx
+ ByteString aMsg( nSlot );
+ aMsg += " not found";
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+
+ return sal_False;
+}
+
+/*
+struct Executer : public SfxHint
+{
+ SfxRequest *pRequest;
+ const SfxSlot* pSlot;
+ sal_uInt16 nLevel;
+
+ Executer( SfxRequest* pReq, const SfxSlot* p, sal_uInt16 n )
+ : pRequest( pReq )
+ , pSlot(p)
+ , nLevel(n)
+ {}
+ ~Executer()
+ {delete pRequest;}
+};
+*/
+
+//--------------------------------------------------------------------
+void SfxDispatcher::_Execute
+(
+ SfxShell& rShell, // zu rufende <SfxShell>
+ const SfxSlot& rSlot, // zu rufender <SfxSlot>
+ SfxRequest& rReq, // auszuf"uhrende Funktion (Id und optional Parameter)
+ SfxCallMode eCallMode // synchron, asynchron oder wie beim Slot angegeben
+)
+
+/* [Beschreibung]
+
+ Diese Methode f"uhrt einen Request "uber einen gecachten <Slot-Server>
+ aus.
+*/
+
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( !pImp->bFlushing, "recursive call to dispatcher" );
+ DBG_ASSERT( !pImp->aToDoStack.Count(), "unprepared InPlace _Execute" );
+
+ if ( IsLocked( rSlot.GetSlotId() ) )
+ return;
+
+ sal_uInt16 nSlot = rSlot.GetSlotId();
+ if ( SfxMacroConfig::IsMacroSlot( nSlot ) )
+ SFX_APP()->GetMacroConfig()->RegisterSlotId( nSlot );
+
+ if ( (eCallMode & SFX_CALLMODE_ASYNCHRON) ||
+ ( !(eCallMode & SFX_CALLMODE_SYNCHRON) &&
+ rSlot.IsMode(SFX_SLOT_ASYNCHRON) ) )
+ {
+ SfxDispatcher *pDispat = this;
+ while ( pDispat )
+ {
+ sal_uInt16 nShellCount = pDispat->pImp->aStack.Count();
+ for ( sal_uInt16 n=0; n<nShellCount; n++ )
+ {
+ if ( &rShell == pDispat->pImp->aStack.Top(n) )
+ {
+ if ( eCallMode & SFX_CALLMODE_RECORD )
+ rReq.AllowRecording( TRUE );
+ pDispat->pImp->xPoster->Post(new SfxRequest(rReq));
+// pDispat->pImp->xPoster->Post(new Executer(new SfxRequest(rReq), &rSlot, n ));
+ return;
+ }
+ }
+
+ pDispat = pDispat->pImp->pParent;
+ }
+ }
+ else
+ Call_Impl( rShell, rSlot, rReq, SFX_CALLMODE_RECORD==(eCallMode&SFX_CALLMODE_RECORD) );
+}
+
+//--------------------------------------------------------------------
+void MappedPut_Impl( SfxAllItemSet &rSet, const SfxPoolItem &rItem )
+
+/* [Beschreibung]
+
+ Hilfsfunktion zum putten von rItem unter der im Pool des Item-Sets
+ rSet geltenden Which-Id.
+*/
+
+{
+ // mit ggf. gemappter Which-Id putten
+ const SfxItemPool *pPool = rSet.GetPool();
+ sal_uInt16 nWhich = rItem.Which();
+#ifdef TF_POOLABLE
+ if ( pPool->IsSlot(nWhich) )
+#else
+ if ( pPool->HasMap() && pPool->IsSlot(nWhich) )
+#endif
+ nWhich = pPool->GetWhich(nWhich);
+ rSet.Put( rItem, nWhich );
+}
+
+//--------------------------------------------------------------------
+
+#ifndef SFX_USE_BINDINGS
+#define SFX_USE_BINDINGS 0x8000
+#endif
+
+sal_uInt16 SfxDispatcher::ExecuteFunction( sal_uInt16 nSlot, SfxPoolItem **pArgs,
+ sal_uInt16 nMode )
+{
+ if ( !nMode )
+ nMode = pImp->nStandardMode;
+
+ // via Bindings/Interceptor? (dann ist der Returnwert nicht exakt)
+ sal_Bool bViaBindings = SFX_USE_BINDINGS == ( nMode & SFX_USE_BINDINGS );
+ nMode &= ~sal_uInt16(SFX_USE_BINDINGS);
+ if ( bViaBindings && GetBindings() )
+ return GetBindings()->Execute( nSlot, (const SfxPoolItem **) pArgs, nMode )
+ ? EXECUTE_POSSIBLE
+ : EXECUTE_NO;
+
+ // sonst via Dispatcher
+ if ( IsLocked(nSlot) )
+ return 0;
+ SfxShell *pShell = 0;
+ SfxCallMode eCall = SFX_CALLMODE_SYNCHRON;
+ sal_uInt16 nRet = EXECUTE_NO;
+ const SfxSlot *pSlot = 0;
+ if ( GetShellAndSlot_Impl( nSlot, &pShell, &pSlot, sal_False, sal_False ) )
+ {
+ // Ausf"uhrbarkeit vorher testen
+ if ( pSlot->IsMode( SFX_SLOT_FASTCALL ) ||
+ pShell->CanExecuteSlot_Impl( *pSlot ) )
+ nRet = EXECUTE_POSSIBLE;
+
+ if ( nMode == EXECUTEMODE_ASYNCHRON )
+ eCall = SFX_CALLMODE_ASYNCHRON;
+ else if ( nMode == EXECUTEMODE_DIALOGASYNCHRON && pSlot->IsMode( SFX_SLOT_HASDIALOG ) )
+ eCall = SFX_CALLMODE_ASYNCHRON;
+ else if ( pSlot->GetMode() & SFX_SLOT_ASYNCHRON )
+ eCall = SFX_CALLMODE_ASYNCHRON;
+ sal_Bool bDone = sal_False;
+ if ( pArgs && *pArgs )
+ {
+ SfxAllItemSet aSet( pShell->GetPool() );
+ for ( SfxPoolItem **pArg = pArgs; *pArg; ++pArg )
+ MappedPut_Impl( aSet, **pArg );
+ SfxRequest aReq( nSlot, eCall, aSet );
+ _Execute( *pShell, *pSlot, aReq, eCall );
+ bDone = aReq.IsDone();
+ }
+ else
+ {
+ SfxRequest aReq( nSlot, eCall, pShell->GetPool() );
+ _Execute( *pShell, *pSlot, aReq, eCall );
+ bDone = aReq.IsDone();
+ }
+ }
+
+ return nRet;
+}
+
+sal_uInt16 SfxDispatcher::ExecuteFunction( sal_uInt16 nSlot, const SfxItemSet& rArgs,
+ sal_uInt16 nMode )
+{
+ if ( !nMode )
+ nMode = pImp->nStandardMode;
+
+/*
+ // at the moment not implemented
+ // via Bindings/Interceptor? (dann ist der Returnwert nicht exakt)
+ sal_Bool bViaBindings = SFX_USE_BINDINGS == ( nMode & SFX_USE_BINDINGS );
+ nMode &= ~sal_uInt16(SFX_USE_BINDINGS);
+ if ( bViaBindings && GetBindings() )
+ return GetBindings()->Execute( nSlot, rArgs, nMode )
+ ? EXECUTE_POSSIBLE
+ : EXECUTE_NO;
+*/
+ // sonst via Dispatcher
+ if ( IsLocked(nSlot) )
+ return 0;
+ SfxShell *pShell = 0;
+ SfxCallMode eCall = SFX_CALLMODE_SYNCHRON;
+ sal_uInt16 nRet = EXECUTE_NO;
+ const SfxSlot *pSlot = 0;
+ if ( GetShellAndSlot_Impl( nSlot, &pShell, &pSlot, sal_False, sal_False ) )
+ {
+ // Ausf"uhrbarkeit vorher testen
+ if ( pSlot->IsMode( SFX_SLOT_FASTCALL ) ||
+ pShell->CanExecuteSlot_Impl( *pSlot ) )
+ nRet = EXECUTE_POSSIBLE;
+
+ if ( nMode == EXECUTEMODE_ASYNCHRON )
+ eCall = SFX_CALLMODE_ASYNCHRON;
+ else if ( nMode == EXECUTEMODE_DIALOGASYNCHRON && pSlot->IsMode( SFX_SLOT_HASDIALOG ) )
+ eCall = SFX_CALLMODE_ASYNCHRON;
+ else if ( pSlot->GetMode() & SFX_SLOT_ASYNCHRON )
+ eCall = SFX_CALLMODE_ASYNCHRON;
+ sal_Bool bDone = sal_False;
+ SfxRequest aReq( nSlot, eCall, rArgs );
+ _Execute( *pShell, *pSlot, aReq, eCall );
+ bDone = aReq.IsDone();
+ }
+
+ return nRet;
+}
+
+sal_uInt16 SfxDispatcher::GetSlotId( const String& rCommand )
+{
+ const SfxSlot *pSlot = GetSlot( rCommand );
+ if ( pSlot )
+ return pSlot->GetSlotId();
+ return 0;
+}
+
+const SfxSlot* SfxDispatcher::GetSlot( const String& rCommand )
+{
+ // Anzahl der Shells auf den verkettenten Dispatchern z"ahlen
+ Flush();
+ sal_uInt16 nTotCount = pImp->aStack.Count();
+ if ( pImp->pParent )
+ {
+ SfxDispatcher *pParent = pImp->pParent;
+ while ( pParent )
+ {
+ nTotCount = nTotCount + pParent->pImp->aStack.Count();
+ pParent = pParent->pImp->pParent;
+ }
+ }
+
+ const SfxSlot *pSlot=NULL;
+ sal_uInt16 nFirstShell = 0;
+ for ( sal_uInt16 i = nFirstShell; i < nTotCount; ++i )
+ {
+ SfxShell *pObjShell = GetShell(i);
+ SfxInterface *pIFace = pObjShell->GetInterface();
+ pSlot = pIFace->GetSlot( rCommand );
+ if ( pSlot )
+ return pSlot;
+ }
+
+ return 0;
+}
+
+//--------------------------------------------------------------------
+int SfxExecuteItem::operator==( const SfxPoolItem& rItem ) const
+{
+ SfxExecuteItem& rArg = (SfxExecuteItem& )rItem;
+ sal_uInt16 nCount = Count();
+ if( nCount != rArg.Count() )
+ return sal_False;
+ while( nCount -- )
+ if( *GetObject( nCount ) != *rArg.GetObject( nCount ) )
+ return sal_False;
+ return eCall == rArg.eCall;
+}
+
+//--------------------------------------------------------------------
+SfxPoolItem* SfxExecuteItem::Clone( SfxItemPool* ) const
+{
+ return new SfxExecuteItem( *this );
+}
+
+//--------------------------------------------------------------------
+SfxExecuteItem::SfxExecuteItem( const SfxExecuteItem& rArg )
+ : SfxItemPtrArray(), SfxPoolItem( rArg ), nModifier( 0 )
+{
+ eCall = rArg.eCall;
+ nSlot = rArg.nSlot;
+ sal_uInt16 nCount = rArg.Count();
+ for( sal_uInt16 nPos = 0; nPos < nCount; nPos++ )
+ Insert( rArg[ nPos ]->Clone(), nPos );
+}
+
+//--------------------------------------------------------------------
+SfxExecuteItem::SfxExecuteItem(
+ sal_uInt16 nWhichId, sal_uInt16 nSlotP, SfxCallMode eModeP,
+ const SfxPoolItem* pArg1, ... ) :
+ SfxPoolItem( nWhichId ), nSlot( nSlotP ), eCall( eModeP ), nModifier( 0 )
+{
+ va_list pVarArgs;
+ va_start( pVarArgs, pArg1 );
+ for ( const SfxPoolItem *pArg = pArg1; pArg;
+ pArg = va_arg( pVarArgs, const SfxPoolItem* ) )
+ Insert( pArg->Clone(), Count() );
+ va_end(pVarArgs);
+}
+
+//--------------------------------------------------------------------
+SfxExecuteItem::SfxExecuteItem(
+ sal_uInt16 nWhichId, sal_uInt16 nSlotP, SfxCallMode eModeP )
+ : SfxPoolItem( nWhichId ), nSlot( nSlotP ), eCall( eModeP ), nModifier( 0 )
+{
+}
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxDispatcher::Execute( const SfxExecuteItem& rItem )
+{
+ const SfxPoolItem** pPtr = new const SfxPoolItem*[ rItem.Count() + 1 ];
+ for( sal_uInt16 nPos = rItem.Count(); nPos--; )
+ pPtr[ nPos ] = rItem.GetObject( nPos );
+ pPtr[ rItem.Count() ] = 0;
+ const SfxPoolItem* pRet = Execute(
+ rItem.GetSlot(), rItem.GetCallMode(), pPtr, rItem.GetModifier() );
+
+ delete [] (SfxPoolItem**)pPtr;
+
+ return pRet;
+}
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxDispatcher::Execute(
+ USHORT nSlot,
+ SfxCallMode nCall,
+ SfxItemSet* pArgs,
+ SfxItemSet* pInternalArgs,
+ USHORT nModi)
+{
+ if ( IsLocked(nSlot) )
+ return 0;
+
+ SfxShell *pShell = 0;
+ const SfxSlot *pSlot = 0;
+ if ( GetShellAndSlot_Impl( nSlot, &pShell, &pSlot, sal_False,
+ SFX_CALLMODE_MODAL==(nCall&SFX_CALLMODE_MODAL) ) )
+ {
+ SfxAllItemSet aSet( pShell->GetPool() );
+ if ( pArgs )
+ {
+ SfxItemIter aIter(*pArgs);
+ for ( const SfxPoolItem *pArg = aIter.FirstItem();
+ pArg;
+ pArg = aIter.NextItem() )
+ MappedPut_Impl( aSet, *pArg );
+ }
+ SfxRequest aReq( nSlot, nCall, aSet );
+ if (pInternalArgs)
+ aReq.SetInternalArgs_Impl( *pInternalArgs );
+ aReq.SetModifier( nModi );
+
+ _Execute( *pShell, *pSlot, aReq, nCall );
+ return aReq.GetReturnValue();
+ }
+ return 0;
+}
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxDispatcher::Execute
+(
+ sal_uInt16 nSlot, // die Id der auszufuehrenden Funktion
+ SfxCallMode eCall, // SFX_CALLMODE_SYNCRHON, ..._ASYNCHRON oder ..._SLOT
+ const SfxPoolItem **pArgs, // 0-terminiertes C-Array von Parametern
+ sal_uInt16 nModi,
+ const SfxPoolItem **pInternalArgs // 0-terminiertes C-Array von Parametern
+)
+
+/* [Beschreibung]
+
+ Methode zum Ausf"uhren eines <SfxSlot>s "uber die Slot-Id.
+
+
+ [R"uckgabewert]
+
+ const SfxPoolItem* Pointer auf ein bis zum n"achsten Durchlauf
+ der Message-Loop g"ultiges SfxPoolItem,
+ welches den R"uckgabewert enth"alt.
+
+ Oder ein 0-Pointer, wenn die Funktion nicht
+ ausgef"uhrt wurde (z.B. Abbruch durch den
+ Benutzer).
+*/
+
+{
+ if ( IsLocked(nSlot) )
+ return 0;
+
+ SfxShell *pShell = 0;
+ const SfxSlot *pSlot = 0;
+ if ( GetShellAndSlot_Impl( nSlot, &pShell, &pSlot, sal_False,
+ SFX_CALLMODE_MODAL==(eCall&SFX_CALLMODE_MODAL) ) )
+ {
+ SfxRequest* pReq;
+ if ( pArgs && *pArgs )
+ {
+ SfxAllItemSet aSet( pShell->GetPool() );
+ for ( const SfxPoolItem **pArg = pArgs; *pArg; ++pArg )
+ MappedPut_Impl( aSet, **pArg );
+ pReq = new SfxRequest( nSlot, eCall, aSet );
+ }
+ else
+ pReq = new SfxRequest( nSlot, eCall, pShell->GetPool() );
+ pReq->SetModifier( nModi );
+ if( pInternalArgs && *pInternalArgs)
+ {
+ SfxAllItemSet aSet( SFX_APP()->GetPool() );
+ for ( const SfxPoolItem **pArg = pInternalArgs; *pArg; ++pArg )
+ aSet.Put( **pArg );
+ pReq->SetInternalArgs_Impl( aSet );
+ }
+ _Execute( *pShell, *pSlot, *pReq, eCall );
+ const SfxPoolItem* pRet = pReq->GetReturnValue();
+ delete pReq; return pRet;
+ }
+ return 0;
+}
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxDispatcher::Execute
+(
+ sal_uInt16 nSlot, // die Id der auszufuehrenden Funktion
+ SfxCallMode eCall, // SFX_CALLMODE_SYNCRHON, ..._ASYNCHRON oder ..._SLOT
+ const SfxItemSet &rArgs // <SfxItemSet> mit Parametern
+)
+
+/* [Beschreibung]
+
+ Methode zum Ausf"uhren eines <SfxSlot>s "uber die Slot-Id.
+
+
+ [R"uckgabewert]
+
+ const SfxPoolItem* Pointer auf ein bis zum n"achsten Durchlauf
+ der Message-Loop g"ultiges SfxPoolItem,
+ welches den R"uckgabewert enth"alt.
+
+ Oder ein 0-Pointer, wenn die Funktion nicht
+ ausgef"uhrt wurde (z.B. Abbruch durch den
+ Benutzer).
+*/
+
+{
+ return Execute( nSlot, eCall, 0, rArgs );
+}
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxDispatcher::Execute
+(
+ USHORT nSlot,
+ SfxCallMode eCall,
+ USHORT nModi,
+ const SfxItemSet &rArgs
+)
+{
+ if ( IsLocked(nSlot) )
+ return 0;
+
+ SfxShell *pShell = 0;
+ const SfxSlot *pSlot = 0;
+ if ( GetShellAndSlot_Impl( nSlot, &pShell, &pSlot, sal_False,
+ SFX_CALLMODE_MODAL==(eCall&SFX_CALLMODE_MODAL) ) )
+ {
+ SfxAllItemSet aSet( pShell->GetPool() );
+ SfxItemIter aIter(rArgs);
+ for ( const SfxPoolItem *pArg = aIter.FirstItem();
+ pArg;
+ pArg = aIter.NextItem() )
+ MappedPut_Impl( aSet, *pArg );
+ SfxRequest aReq( nSlot, eCall, aSet );
+ aReq.SetModifier( nModi );
+ _Execute( *pShell, *pSlot, aReq, eCall );
+ return aReq.GetReturnValue();
+ }
+ return 0;
+}
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxDispatcher::_Execute
+(
+ sal_uInt16 nSlot, // die Id der auszufuehrenden Funktion
+ SfxCallMode eCall, // SFX_CALLMODE_SYNCRHON, ..._ASYNCHRON oder ..._SLOT
+ va_list pVarArgs, // Parameterliste ab 2. Parameter
+ const SfxPoolItem* pArg1 // erster Parameter
+)
+
+/* [Beschreibung]
+
+ Methode zum Ausf"uhren eines <SfxSlot>s "uber die Slot-Id.
+
+
+ [R"uckgabewert]
+
+ const SfxPoolItem* Pointer auf ein bis zum n"achsten Durchlauf
+ der Message-Loop g"ultiges SfxPoolItem,
+ welches den R"uckgabewert enth"alt.
+
+ Oder ein 0-Pointer, wenn die Funktion nicht
+ ausgef"uhrt wurde (z.B. Abbruch durch den
+ Benutzer).
+*/
+
+{
+ if ( IsLocked(nSlot) )
+ return 0;
+
+ SfxShell *pShell = 0;
+ const SfxSlot *pSlot = 0;
+ if ( GetShellAndSlot_Impl( nSlot, &pShell, &pSlot, sal_False,
+ SFX_CALLMODE_MODAL==(eCall&SFX_CALLMODE_MODAL) ) )
+ {
+ SfxAllItemSet aSet( pShell->GetPool() );
+
+ for ( const SfxPoolItem *pArg = pArg1;
+ pArg;
+ pArg = va_arg( pVarArgs, const SfxPoolItem* ) )
+ MappedPut_Impl( aSet, *pArg );
+
+ SfxRequest aReq( nSlot, eCall, aSet );
+ _Execute( *pShell, *pSlot, aReq, eCall );
+ return aReq.GetReturnValue();
+ }
+ return 0;
+}
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxDispatcher::Execute
+(
+ sal_uInt16 nSlot, // die Id der auszufuehrenden Funktion
+ SfxCallMode eCall, // SFX_CALLMODE_SYNCRHON, ..._ASYNCHRON oder ..._SLOT
+ const SfxPoolItem* pArg1, // erster Parameter
+ ... // 0-terminiertes Liste Parametern
+)
+
+/* [Beschreibung]
+
+ Methode zum Ausf"uhren eines <SfxSlot>s "uber die Slot-Id.
+
+
+ [Anmerkung]
+
+ Die Parameter werden kopiert, k"onnen daher als Adresse von
+ Stack-Objekten "ubergeben werden.
+
+
+ [R"uckgabewert]
+
+ const SfxPoolItem* Pointer auf ein bis zum n"achsten Durchlauf
+ der Message-Loop g"ultiges SfxPoolItem,
+ welches den R"uckgabewert enth"alt.
+
+ Oder ein 0-Pointer, wenn die Funktion nicht
+ ausgef"uhrt wurde (z.B. Abbruch durch den
+ Benutzer).
+
+
+ [Beispiel]
+
+ pDispatcher->Execute( SID_OPENDOCUMENT, SFX_CALLMODE_SYNCHRON,
+ &SfxStringItem( SID_FILE_NAME, "\\tmp\\temp.sdd" ),
+ &SfxStringItem( SID_FILTER_NAME, "StarDraw Presentation" ),
+ &SfxBoolItem( SID_DOC_READONLY, sal_False ),
+ 0L );
+*/
+
+{
+ if ( IsLocked(nSlot) )
+ return 0;
+
+ SfxShell *pShell = 0;
+ const SfxSlot *pSlot = 0;
+ if ( GetShellAndSlot_Impl( nSlot, &pShell, &pSlot, sal_False,
+ SFX_CALLMODE_MODAL==(eCall&SFX_CALLMODE_MODAL) ) )
+ {
+ SfxAllItemSet aSet( pShell->GetPool() );
+
+ va_list pVarArgs;
+ va_start( pVarArgs, pArg1 );
+ for ( const SfxPoolItem *pArg = pArg1;
+ pArg;
+ pArg = va_arg( pVarArgs, const SfxPoolItem* ) )
+ MappedPut_Impl( aSet, *pArg );
+ va_end(pVarArgs);
+
+ SfxRequest aReq( nSlot, eCall, aSet );
+ _Execute( *pShell, *pSlot, aReq, eCall );
+ return aReq.GetReturnValue();
+ }
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+IMPL_LINK( SfxDispatcher, PostMsgHandler, SfxRequest*, pReq )
+
+/* [Beschreibung]
+
+ Hilfsmethode zum Empfangen der asynchron auszuf"uhrenden <SfxRequest>s.
+*/
+
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( !pImp->bFlushing, "recursive call to dispatcher" );
+ SFX_STACK(SfxDispatcher::PostMsgHandler);
+
+ // ist auch der Pool noch nicht gestorben?
+// SfxRequest* pReq = pExec->pRequest;
+ if ( !pReq->IsCancelled() )
+ {
+ if ( !IsLocked(pReq->GetSlot()) )
+ {
+ Flush();
+ SfxSlotServer aSvr;
+ if ( _FindServer(pReq->GetSlot(), aSvr, HACK(x) sal_True ) )
+// SfxShell *pShell = GetShell(pExec->nLevel);
+// if ( pShell && pShell->GetInterface()->GetSlot( pExec->pSlot->GetSlotId() ) )
+ {
+ const SfxSlot *pSlot = aSvr.GetSlot();
+ SfxShell *pSh = GetShell(aSvr.GetShellLevel());
+
+ DBG( SfxApplication *pSfxApp = SFX_APP() );
+ DBG( pSfxApp->EnterAsynchronCall_Impl() );
+
+ // Wenn pSlot ein "Pseudoslot" f"ur Macros oder Verben ist, kann
+ // er im Call_Impl zerst"ort werden, also nicht mehr benutzen!
+ pReq->SetSynchronCall( sal_False );
+ Call_Impl( *pSh, *pSlot, *pReq, pReq->AllowsRecording() ); //! woher bRecord?
+// Call_Impl( *pShell, *pExec->pSlot, *pReq, sal_True ); //! woher bRecord?
+ DBG( pSfxApp->LeaveAsynchronCall_Impl() );
+ }
+
+// delete pExec;
+ }
+ else
+ {
+// pImp->xPoster->Post(pExec);
+ if ( pImp->bLocked )
+ pImp->aReqArr.Insert( new SfxRequest(*pReq), pImp->aReqArr.Count() );
+ else
+ pImp->xPoster->Post(new SfxRequest(*pReq));
+ }
+ }
+// else
+// delete pExec;
+
+ delete pReq;
+ return 0;
+}
+//--------------------------------------------------------------------
+void SfxDispatcher::EnterAction( const String& rName )
+
+// marks the beginning of a block of actions
+
+{
+ DBG_MEMTEST();
+ Flush();
+ DBG_ASSERT( pImp->aStack.Count() > 0, "EnterAction on empty dispatcher stack" );
+ if ( ++pImp->nActionLevel == 1 )
+ {
+ SfxUndoManager *pUndoMgr = GetShell(0)->GetUndoManager();
+ if ( pUndoMgr )
+ pUndoMgr->EnterListAction( rName, rName HACK(RepeatComment), 0 HACK(ID) );
+ }
+}
+//--------------------------------------------------------------------
+void SfxDispatcher::LeaveAction()
+
+// marks the end of a block of actions
+
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImp->nActionLevel > 0, "EnterAction without LeaveAction" );
+ if ( --pImp->nActionLevel == 0 )
+ {
+ SfxUndoManager *pUndoMgr = GetShell(0)->GetUndoManager();
+ if ( pUndoMgr )
+ pUndoMgr->LeaveListAction();
+ }
+}
+
+//--------------------------------------------------------------------
+void SfxDispatcher::SetMenu_Impl()
+{
+ if ( pImp->pFrame )
+ {
+ SfxViewFrame* pTop = pImp->pFrame->GetTopViewFrame();
+ if ( pTop && pTop->GetBindings().GetDispatcher() == this )
+ {
+ SfxFrame& rFrame = pTop->GetFrame();
+ if ( rFrame.IsMenuBarOn_Impl() )
+ {
+ com::sun::star::uno::Reference < com::sun::star::beans::XPropertySet > xPropSet( rFrame.GetFrameInterface(), com::sun::star::uno::UNO_QUERY );
+ if ( xPropSet.is() )
+ {
+ com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+ com::sun::star::uno::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" ));
+ if ( !xLayoutManager->isElementVisible( aMenuBarURL ) )
+ xLayoutManager->createElement( aMenuBarURL );
+ }
+ }
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+void SfxDispatcher::Update_Impl( sal_Bool bForce )
+{
+ SFX_STACK(SfxDispatcher::Update_Impl);
+
+ Flush();
+
+ if ( !pImp->pFrame || pImp->bUILocked )
+ return;
+
+ SFX_APP(); // -Wall is this required???
+ SfxDispatcher *pDisp = this;
+ sal_Bool bUpdate = bForce;
+ while ( pDisp && pDisp->pImp->pFrame )
+ {
+ SfxWorkWindow *pWork = pDisp->pImp->pFrame->GetFrame().GetWorkWindow_Impl();
+ SfxDispatcher *pAct = pWork->GetBindings().GetDispatcher_Impl();
+ if ( pAct == pDisp || pAct == this )
+ {
+ if ( !bUpdate )
+ bUpdate = !pDisp->pImp->bUpdated;
+ pDisp->pImp->bUpdated = sal_True;
+ }
+ else
+ break;
+
+ pDisp = pDisp->pImp->pParent;
+ }
+
+ if ( !bUpdate || pImp->pFrame->GetFrame().IsClosing_Impl() )
+ return;
+
+ SfxViewFrame* pTop = pImp->pFrame ? pImp->pFrame->GetTopViewFrame() : NULL;
+ sal_Bool bUIActive = pTop && pTop->GetBindings().GetDispatcher() == this;
+
+ if ( !bUIActive && pTop && GetBindings() == &pTop->GetBindings() )
+ // keep own tools internally for collecting
+ GetBindings()->GetDispatcher()->pImp->bUpdated = sal_False;
+
+ SfxBindings* pBindings = GetBindings();
+ if ( pBindings )
+ pBindings->DENTERREGISTRATIONS();
+
+ com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame = pBindings->GetActiveFrame();
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, com::sun::star::uno::UNO_QUERY );
+ com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ com::sun::star::uno::Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )) );
+ aValue >>= xLayoutManager;
+ }
+ catch ( com::sun::star::uno::Exception& )
+ {
+ }
+ }
+
+ if ( xLayoutManager.is() )
+ xLayoutManager->lock();
+
+ sal_Bool bIsIPActive = pImp->pFrame && pImp->pFrame->GetObjectShell()->IsInPlaceActive();
+ SfxInPlaceClient *pClient = pImp->pFrame ? pImp->pFrame->GetViewShell()->GetUIActiveClient() : NULL;
+ if ( bUIActive && /* !bIsIPActive && */ ( !pClient || !pClient->IsObjectUIActive() ) )
+ SetMenu_Impl();
+
+ SfxWorkWindow *pWorkWin = pImp->pFrame->GetFrame().GetWorkWindow_Impl();
+ SfxWorkWindow *pTaskWin = pImp->pFrame->GetTopFrame().GetWorkWindow_Impl();
+ pTaskWin->ResetStatusBar_Impl();
+
+ SfxDispatcher *pDispat = this;
+ while ( pDispat )
+ {
+ SfxWorkWindow *pWork = pDispat->pImp->pFrame->GetFrame().GetWorkWindow_Impl();
+ SfxDispatcher *pAct = pWork->GetBindings().GetDispatcher_Impl();
+ if ( pAct == pDispat || pAct == this )
+ {
+ pWork->ResetObjectBars_Impl();
+ pWork->ResetChildWindows_Impl();
+ }
+
+ pDispat = pDispat->pImp->pParent;
+ }
+
+ sal_Bool bIsActive = sal_False;
+ SfxDispatcher *pActDispat = pWorkWin->GetBindings().GetDispatcher_Impl();
+ pDispat = this;
+ while ( pActDispat && !bIsActive )
+ {
+ if ( pDispat == pActDispat )
+ bIsActive = sal_True;
+ pActDispat = pActDispat->pImp->pParent;
+ }
+
+ _Update_Impl( bUIActive, !bIsIPActive, bIsIPActive, pTaskWin );
+ if ( bUIActive || bIsActive )
+ pWorkWin->UpdateObjectBars_Impl();
+
+ if ( pBindings )
+ pBindings->DLEAVEREGISTRATIONS();
+
+ if ( xLayoutManager.is() )
+ xLayoutManager->unlock();
+
+ return;
+}
+
+void SfxDispatcher::_Update_Impl( sal_Bool bUIActive, sal_Bool bIsMDIApp, sal_Bool bIsIPOwner, SfxWorkWindow *pTaskWin )
+{
+ SFX_APP();
+ SfxWorkWindow *pWorkWin = pImp->pFrame->GetFrame().GetWorkWindow_Impl();
+ sal_Bool bIsActive = sal_False;
+ sal_Bool bIsTaskActive = sal_False;
+ SfxDispatcher *pActDispat = pWorkWin->GetBindings().GetDispatcher_Impl();
+ SfxDispatcher *pDispat = this;
+ while ( pActDispat && !bIsActive )
+ {
+ if ( pDispat == pActDispat )
+ bIsActive = sal_True;
+ pActDispat = pActDispat->pImp->pParent;
+ }
+
+ if ( pImp->pParent && !pImp->bQuiet /* && bUIActive */ )
+ pImp->pParent->_Update_Impl( bUIActive, bIsMDIApp, bIsIPOwner, pTaskWin );
+
+ for (sal_uInt16 n=0; n<SFX_OBJECTBAR_MAX; n++)
+ pImp->aObjBars[n].nResId = 0;
+ pImp->aChildWins.Remove(0, pImp->aChildWins.Count());
+
+ // bQuiet : own shells aren't considered for UI and SlotServer
+ // bNoUI: own Shells aren't considered fors UI
+ if ( pImp->bQuiet || pImp->bNoUI || (pImp->pFrame && pImp->pFrame->GetObjectShell()->IsPreview()) )
+ return;
+
+ sal_uInt32 nStatBarId=0;
+ SfxShell *pStatusBarShell = NULL;
+
+ SfxSlotPool* pSlotPool = &SfxSlotPool::GetSlotPool( GetFrame() );
+ sal_uInt16 nTotCount = pImp->aStack.Count();
+ for ( sal_uInt16 nShell = nTotCount; nShell > 0; --nShell )
+ {
+ SfxShell *pShell = GetShell( nShell-1 );
+ SfxInterface *pIFace = pShell->GetInterface();
+
+ // don't consider shells if "Hidden" oder "Quiet"
+ sal_Bool bReadOnlyShell = IsReadOnlyShell_Impl( nShell-1 );
+ sal_uInt16 nNo;
+ for ( nNo = 0; pIFace && nNo<pIFace->GetObjectBarCount(); ++nNo )
+ {
+ sal_uInt16 nPos = pIFace->GetObjectBarPos(nNo);
+ if ( bReadOnlyShell && !( nPos & SFX_VISIBILITY_READONLYDOC ) )
+ continue;
+
+ // check wether toolbar needs activation of a special feature
+ sal_uInt32 nFeature = pIFace->GetObjectBarFeature(nNo);
+ if ( nFeature && !pShell->HasUIFeature( nFeature ) )
+ continue;
+
+ // check for toolboxes that are exclusively for a viewer
+ if ( pImp->pFrame)
+ {
+ BOOL bViewerTbx = SFX_VISIBILITY_VIEWER == ( nPos & SFX_VISIBILITY_VIEWER );
+ SfxObjectShell* pSh = pImp->pFrame->GetObjectShell();
+ SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_VIEWONLY, sal_False );
+ BOOL bIsViewer = pItem && pItem->GetValue();
+ if ( bIsViewer != bViewerTbx )
+ continue;
+ }
+
+ // always register toolbars, allows to switch them on
+ sal_Bool bVisible = pIFace->IsObjectBarVisible(nNo);
+ if ( !bVisible )
+ nPos &= SFX_POSITION_MASK;
+
+ SfxObjectBars_Impl& rBar = pImp->aObjBars[nPos & SFX_POSITION_MASK];
+ rBar.nMode = nPos;
+ rBar.nResId = pIFace->GetObjectBarResId(nNo).GetId();
+ const String *pName = pIFace->GetObjectBarName(nNo);
+ if ( pName )
+ rBar.aName = *pName;
+ else
+ rBar.aName.Erase();
+ rBar.pIFace = pIFace;
+
+ if ( bUIActive || bIsActive )
+ {
+ pWorkWin->SetObjectBar_Impl(
+ nPos, rBar.nResId, rBar.pIFace, &rBar.aName );
+ }
+
+ if ( !bVisible )
+ rBar.nResId = 0;
+ }
+
+ for ( nNo=0; pIFace && nNo<pIFace->GetChildWindowCount(); nNo++ )
+ {
+ sal_uInt32 nId = pIFace->GetChildWindowId(nNo);
+ const SfxSlot *pSlot = pSlotPool->GetSlot( (sal_uInt16) nId );
+ DBG_ASSERT( pSlot, "Childwindow slot missing!");
+ if ( bReadOnlyShell )
+ {
+ // only show ChildWindows if their slot is allowed for readonly documents
+ if ( pSlot && !pSlot->IsMode( SFX_SLOT_READONLYDOC ) )
+ continue;
+ }
+
+ sal_uInt32 nFeature = pIFace->GetChildWindowFeature(nNo);
+ if ( nFeature && !pShell->HasUIFeature( nFeature ) )
+ continue;
+
+ // slot decides wether a ChildWindow is shown when document is OLE server or OLE client
+ sal_uInt16 nMode = SFX_VISIBILITY_STANDARD;
+ if( pSlot )
+ {
+ if ( pSlot->IsMode(SFX_SLOT_CONTAINER) )
+ {
+ if ( pWorkWin->IsVisible_Impl( SFX_VISIBILITY_CLIENT ) )
+ nMode |= SFX_VISIBILITY_CLIENT;
+ }
+ else
+ {
+ if ( pWorkWin->IsVisible_Impl( SFX_VISIBILITY_SERVER ) )
+ nMode |= SFX_VISIBILITY_SERVER;
+ }
+ }
+
+ if ( bUIActive || bIsActive )
+ pWorkWin->SetChildWindowVisible_Impl( nId, sal_True, nMode );
+ if ( bUIActive || bIsActive || !pWorkWin->IsFloating( (sal_uInt16) ( nId & 0xFFFF ) ) )
+ pImp->aChildWins.Insert( nId, pImp->aChildWins.Count());
+ }
+
+ if ( bIsMDIApp || bIsIPOwner )
+ {
+ sal_uInt32 nId = pIFace->GetStatusBarResId().GetId();
+ if ( nId )
+ {
+ nStatBarId = nId;
+ pStatusBarShell = pShell;
+ }
+ }
+ }
+
+ for ( sal_uInt16 nPos=0; nPos<SFX_OBJECTBAR_MAX; nPos++ )
+ {
+ SfxObjectBars_Impl& rFixed = pImp->aFixedObjBars[nPos];
+ if ( rFixed.nResId )
+ {
+ SfxObjectBars_Impl& rBar = pImp->aObjBars[nPos];
+ rBar = rFixed;
+ pWorkWin->SetObjectBar_Impl( rFixed.nMode,
+ rFixed.nResId, rFixed.pIFace, &rFixed.aName );
+ }
+ }
+
+ if ( pTaskWin && ( bIsMDIApp || bIsIPOwner ) )
+ {
+ SfxDispatcher *pActDispatcher = pTaskWin->GetBindings().GetDispatcher_Impl();
+ SfxDispatcher *pDispatcher = this;
+ while ( pActDispatcher && !bIsTaskActive )
+ {
+ if ( pDispatcher == pActDispatcher )
+ bIsTaskActive = sal_True;
+ pActDispatcher = pActDispatcher->pImp->pParent;
+ }
+
+ if ( bIsTaskActive && nStatBarId && pImp->pFrame )
+ {
+ // internal frames also may control statusbar
+ SfxBindings& rBindings = pImp->pFrame->GetBindings();
+ pImp->pFrame->GetFrame().GetWorkWindow_Impl()->SetStatusBar_Impl( nStatBarId, pStatusBarShell, rBindings );
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+void SfxDispatcher::FlushImpl()
+
+/* [Beschreibung]
+
+ Hilfsmethode zum Ausf"uhren der ausstehenden Push- und Pop-Befehle.
+*/
+
+{
+ DBG_PROFSTART(SfxDispatcherFlush);
+ DBG_MEMTEST();
+ SFX_STACK(SfxDispatcher::FlushImpl);
+
+ DBG_TRACE("Flushing dispatcher!");
+
+#ifdef DBG_UTIL
+ ByteString aMsg( "SfxDispatcher(" );
+ aMsg += ByteString::CreateFromInt64( (sal_uIntPtr) this );
+ aMsg += ")::Flush()";
+#endif
+
+ pImp->aTimer.Stop();
+
+ if ( pImp->pParent )
+ pImp->pParent->Flush();
+
+// if ( pImp->bQuiet )
+// return;
+
+ pImp->bFlushing = !pImp->bFlushing;
+ if ( !pImp->bFlushing )
+ {
+ pImp->bFlushing = sal_True;
+ DBG_PROFSTOP(SfxDispatcherFlush);
+//!
+#ifdef DBG_UTIL_MESSEHACK_AUSKOMMENT
+ DBG_ERROR( "reentering SfxDispatcher::Flush()" );
+ aMsg += " reentering, aborted";
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+ return;
+ }
+
+ SfxApplication *pSfxApp = SFX_APP();
+
+ // in der 1. Runde den echten Stack 'um'bauen
+ SfxToDoStack_Impl aToDoCopy;
+ sal_Bool bModify = sal_False;
+ short nToDo;
+ for ( nToDo = pImp->aToDoStack.Count()-1; nToDo >= 0; --nToDo )
+ {
+ bModify = sal_True;
+
+ SfxToDo_Impl aToDo( pImp->aToDoStack.Top(nToDo) );
+ if ( aToDo.bPush )
+ {
+ // tats"aechlich pushen
+ DBG_ASSERT( !pImp->aStack.Contains( aToDo.pCluster ),
+ "pushed SfxShell already on stack" );
+ pImp->aStack.Push( aToDo.pCluster );
+ aToDo.pCluster->SetDisableFlags( pImp->nDisableFlags );
+
+ // die bewegte Shell merken
+ aToDoCopy.Push( aToDo );
+ }
+ else
+ {
+ // tats"aechlich poppen
+ SfxShell* pPopped = 0;
+ FASTBOOL bFound = sal_False;
+ do
+ {
+ DBG_ASSERT( pImp->aStack.Count(), "popping from empty stack" );
+ pPopped = pImp->aStack.Pop();
+ pPopped->SetDisableFlags( 0 );
+ bFound = pPopped == aToDo.pCluster;
+
+ // die bewegte Shell merken
+ aToDoCopy.Push( SfxToDo_Impl( sal_False, aToDo.bDelete, sal_False, *pPopped) );
+ }
+ while ( aToDo.bUntil && !bFound );
+ DBG_ASSERT( bFound, "wrong SfxShell popped" );
+ }
+
+ if ( nToDo == 0 )
+ pImp->aToDoStack.Clear();
+ }
+
+ // ggf. Bindings invalidieren
+ if ( !pSfxApp->IsDowning() )
+ {
+ if ( bModify )
+ {
+ pImp->pCachedServ1 = 0;
+ pImp->pCachedServ2 = 0;
+ }
+
+ InvalidateBindings_Impl( bModify );
+ }
+
+ pImp->bFlushing = sal_False;
+ pImp->bUpdated = sal_False; // nicht nur bei bModify, falls Doc/Template-Config
+ bFlushed = sal_True;
+ DBG_TRACE("Successfully flushed dispatcher!");
+
+ // in der 2. Runde die Shells aktivieren und ggf. l"oschen
+ for ( nToDo = aToDoCopy.Count()-1; nToDo >= 0; --nToDo )
+ {
+ SfxToDo_Impl aToDo( aToDoCopy.Top(nToDo) );
+ if ( aToDo.bPush )
+ {
+ if ( pImp->bActive )
+ aToDo.pCluster->DoActivate_Impl(pImp->pFrame, sal_True);
+ }
+ else
+ if ( pImp->bActive )
+ aToDo.pCluster->DoDeactivate_Impl(pImp->pFrame, sal_True);
+ }
+ for ( nToDo = aToDoCopy.Count()-1; nToDo >= 0; --nToDo )
+ {
+ SfxToDo_Impl aToDo( aToDoCopy.Top(nToDo) );
+ if ( aToDo.bDelete ) delete aToDo.pCluster;
+ }
+ sal_Bool bAwakeBindings = aToDoCopy.Count() != 0;
+ if( bAwakeBindings )
+ aToDoCopy.Clear();
+
+ // Wenn bei Activate/Deactivate/Delete weitere Stackbewegungen erfolgt sind :
+ if (!bFlushed)
+ // falls jemand Push/Pop gerufen hat, wurde auch EnterReg gerufen!
+ FlushImpl();
+
+ if( bAwakeBindings && GetBindings() )
+ GetBindings()->DLEAVEREGISTRATIONS();
+ DBG_PROFSTOP(SfxDispatcherFlush);
+
+ for (sal_uInt16 n=0; n<SFX_OBJECTBAR_MAX; n++)
+ pImp->aFixedObjBars[n].nResId = 0;
+
+#ifdef DBG_UTIL
+ aMsg += " done";
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+}
+
+//--------------------------------------------------------------------
+void SfxDispatcher::SetSlotFilter
+(
+ HACK(hier muss mal ein enum rein)
+ sal_Bool bEnable, /* sal_True:
+ nur angegebene Slots enablen,
+ alle anderen disablen
+
+ sal_False:
+ die angegebenen Slots disablen,
+ alle anderen zun"achst enablen
+ */
+ sal_uInt16 nCount, // Anzahl der SIDs im folgenden Array
+ const sal_uInt16* pSIDs // sortiertes Array von 'nCount' SIDs
+)
+
+/* [Beschreibung]
+
+ Mit dieser Methode wird ein Filter gesetzt, mit dem gezielt Slots
+ enabled bzw. disabled werden k"onnen. Das "ubergebene Array mu\s
+ bis zum Dtor bzw. n"achsten <SetSlotFilter()> erhalten bleiben, es
+ wird nicht vom Dispatcher gel"oscht, es kann daher static sein.
+
+ In ReadOnly-Dokumenten kann man mit 'bEnable==2' quasi das ReadOnlyDoc
+ Flag von Slots "ubersteuern, dieser werden also wieder gefunden. Auf
+ andere Slots hat das dann keine Auswirkung.
+
+
+ [Beispiel]
+
+ gezieltes disablen der Slots 1, 2 und 3:
+
+ static sal_uInt16 __READONLY_DATA pSIDs[] = { 1, 2, 3 };
+ pDisp->SetSlotFilter( sal_False, sizeof(pSIDs)/sizeof(sal_uInt16), pSIDs );
+
+ nur die Slots 5, 6 und 7 zulassen:
+
+ static sal_uInt16 __READONLY_DATA pSIDs[] = { 5, 6, 7 };
+ pDisp->SetSlotFilter( sal_True, sizeof(pSIDs)/sizeof(sal_uInt16), pSIDs );
+
+ Filter ausschalten:
+
+ pDisp->SetSlotFilter();
+*/
+
+{
+#ifdef DBG_UTIL
+ // Array "uberpr"ufen
+ for ( sal_uInt16 n = 1; n < nCount; ++n )
+ DBG_ASSERT( pSIDs[n] > pSIDs[n-1], "SetSlotFilter: SIDs not sortet" );
+#endif
+
+ if ( pImp->pFilterSIDs )
+ pImp->pFilterSIDs = 0;
+
+ pImp->bFilterEnabling = bEnable;
+ pImp->nFilterCount = nCount;
+ pImp->pFilterSIDs = pSIDs;
+
+ GetBindings()->InvalidateAll(sal_True);
+}
+
+//--------------------------------------------------------------------
+EXTERN_C
+#if defined( PM2 ) && (!defined( CSET ) && !defined ( MTW ) && !defined( WTC ))
+int _stdcall
+#else
+#ifdef WNT
+int _cdecl
+#else
+int
+#endif
+#endif
+
+SfxCompareSIDs_Impl( const void* pSmaller, const void* pBigger )
+{
+ DBG_MEMTEST();
+ return ( (long) *((sal_uInt16*)pSmaller) ) - ( (long) *((sal_uInt16*)pBigger) );
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxDispatcher::IsSlotEnabledByFilter_Impl( sal_uInt16 nSID ) const
+
+/* [Beschreibung]
+
+ Sucht 'nSID' in dem mit <SetSlotFilter()> gesetzten Filter und
+ liefert sal_True, falls die SID erlaubt ist, bzw. sal_False, falls sie
+ durch den Filter disabled ist.
+
+ [R"uckgabewert]
+ sal_Bool 0 => disabled
+ 1 => enabled
+ 2 => enabled even if ReadOnlyDoc
+*/
+
+{
+ // kein Filter?
+ if ( 0 == pImp->nFilterCount )
+ // => alle SIDs erlaubt
+ return sal_True;
+
+ // suchen
+ sal_Bool bFound = 0 != bsearch( &nSID, pImp->pFilterSIDs, pImp->nFilterCount,
+ sizeof(sal_uInt16), SfxCompareSIDs_Impl );
+
+ // even if ReadOnlyDoc
+ if ( 2 == pImp->bFilterEnabling )
+ return bFound ? 2 : 1;
+ // sonst je nach Negativ/Positiv Filter
+ return pImp->bFilterEnabling ? bFound : !bFound;
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxDispatcher::_TryIntercept_Impl
+(
+ sal_uInt16 nSlot, // zu suchende Slot-Id
+ SfxSlotServer& rServer, // zu f"uellende <SfxSlotServer>-Instanz
+ sal_Bool bSelf
+)
+{
+ // Eventuell geh"ort der parent auch zu einer Komponente
+ SfxDispatcher *pParent = pImp->pParent;
+ sal_uInt16 nLevels = pImp->aStack.Count();
+ while ( pParent && pParent->pImp->pFrame )
+ {
+ if ( pParent->pImp->pFrame->GetFrame().HasComponent() )
+ {
+ // Components d"urfen intercepten
+ if ( pParent->_TryIntercept_Impl( nSlot, rServer, sal_True ) )
+ {
+ // Die eigenen Shells zum Shelllevel hinzuz"ahlen
+ rServer.SetShellLevel( rServer.GetShellLevel() + nLevels );
+ return sal_True;
+ }
+ else
+ // Keine weitere Interception
+ break;
+ }
+ else
+ nLevels = nLevels + pParent->pImp->aStack.Count();
+
+ pParent = pParent->pImp->pParent;
+ }
+
+ if ( bSelf )
+ {
+ // Die ComponentViewShell befragen
+ Flush();
+ SfxShell *pObjShell = GetShell(0);
+ SfxInterface *pIFace = pObjShell->GetInterface();
+ const SfxSlot *pSlot = pIFace->GetSlot(nSlot);
+
+ if ( pSlot )
+ {
+ rServer.SetSlot(pSlot);
+ rServer.SetShellLevel(0);
+#ifdef DBG_UTILx
+ String aMsg( nSlot );
+ aMsg += " intercepted";
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+ return sal_True;
+ }
+ }
+
+ return sal_False;
+}
+
+sal_Bool SfxDispatcher::_FindServer
+(
+ sal_uInt16 nSlot, // zu suchende Slot-Id
+ SfxSlotServer& rServer, // zu f"uellnde <SfxSlotServer>-Instanz
+ sal_Bool bModal // trotz ModalMode
+)
+
+/* [Beschreibung]
+
+ Diese Hilfsmethode sucht den <Slot-Server>, der nSlot zur Zeit bedient.
+ Als Ergebnis wird rServer entsprechend gef"ullt.
+
+ Falls bekannt, kann das SfxInterface mitgegeben werden, von welchem
+ nSlot momentan bedient wird.
+
+ Vor der Suche nach nSlot wird der SfxDispatcher geflusht.
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Der Slot wurde gefunden, rServer ist g"ultig.
+
+ sal_False
+ Der Slot wird momentan nicht bedient, rServer
+ ist ung"ultig.
+*/
+
+{
+ SFX_STACK(SfxDispatcher::_FindServer);
+
+ // Dispatcher gelockt? (SID_HELP_PI trotzdem durchlassen)
+ SfxApplication *pSfxApp = SFX_APP();
+ if ( IsLocked(nSlot) )
+ {
+ pImp->bInvalidateOnUnlock = sal_True;
+ return sal_False;
+ }
+
+ // Anzahl der Shells auf den verkettenten Dispatchern z"ahlen
+ Flush();
+ sal_uInt16 nTotCount = pImp->aStack.Count();
+ if ( pImp->pParent )
+ {
+ SfxDispatcher *pParent = pImp->pParent;
+ while ( pParent )
+ {
+ nTotCount = nTotCount + pParent->pImp->aStack.Count();
+ pParent = pParent->pImp->pParent;
+ }
+ }
+
+ // Makro-Slot?
+ if ( SfxMacroConfig::IsMacroSlot( nSlot ) )
+ {
+ const SfxMacroInfo* pInfo = pSfxApp->GetMacroConfig()->GetMacroInfo(nSlot);
+ if ( pInfo )
+ {
+ const SfxSlot* pSlot = pInfo->GetSlot();
+ if ( pSlot )
+ {
+ rServer.SetShellLevel(nTotCount-1);
+ rServer.SetSlot( pSlot );
+ return sal_True;
+ }
+ }
+
+ return sal_False;
+ }
+ // Verb-Slot?
+ else if (nSlot >= SID_VERB_START && nSlot <= SID_VERB_END)
+ {
+ for ( sal_uInt16 nShell = 0;; ++nShell )
+ {
+ SfxShell *pSh = GetShell(nShell);
+ if ( pSh == NULL )
+ return false;
+ if ( pSh->ISA(SfxViewShell) )
+ {
+ const SfxSlot* pSlot = pSh->GetVerbSlot_Impl(nSlot);
+ if ( pSlot )
+ {
+ rServer.SetShellLevel(nShell);
+ rServer.SetSlot( pSlot );
+ return true;
+ }
+ }
+ }
+ }
+
+ // SID gegen gesetzten Filter pr"ufen
+ sal_uInt16 nSlotEnableMode=0;
+ if ( pImp->pFrame )
+ {
+ nSlotEnableMode = IsSlotEnabledByFilter_Impl( nSlot );
+ if ( 0 == nSlotEnableMode )
+ return sal_False;
+ }
+
+ // im Quiet-Mode nur Parent-Dispatcher
+ if ( pImp->bQuiet )
+ {
+ if ( pImp->pParent )
+ {
+ sal_Bool bRet = pImp->pParent->_FindServer( nSlot, rServer, bModal );
+ rServer.SetShellLevel
+ ( rServer.GetShellLevel() + pImp->aStack.Count() );
+ return bRet;
+ }
+ else
+ return sal_False;
+ }
+
+ sal_Bool bReadOnly = ( 2 != nSlotEnableMode && pImp->bReadOnly );
+// ( pImp->pFrame && pImp->pFrame->GetObjectShell() );
+// pImp->pFrame->GetObjectShell()->IsLoading() );
+
+ // durch alle Shells der verketteten Dispatchern von oben nach unten suchen
+#ifdef DBG_UTILx
+ String aStack( "Stack:" );
+#endif
+ sal_uInt16 nFirstShell = pImp->bModal && !bModal ? pImp->aStack.Count() : 0;
+ for ( sal_uInt16 i = nFirstShell; i < nTotCount; ++i )
+ {
+ SfxShell *pObjShell = GetShell(i);
+ SfxInterface *pIFace = pObjShell->GetInterface();
+ const SfxSlot *pSlot = pIFace->GetSlot(nSlot);
+
+ if ( pSlot && pSlot->nDisableFlags && ( pSlot->nDisableFlags & pObjShell->GetDisableFlags() ) != 0 )
+ return sal_False;
+
+ if ( pSlot && !( pSlot->nFlags & SFX_SLOT_READONLYDOC ) && bReadOnly )
+ return sal_False;
+
+ if ( pSlot )
+ {
+ // Slot geh"ort zum Container?
+ FASTBOOL bIsContainerSlot = pSlot->IsMode(SFX_SLOT_CONTAINER);
+ FASTBOOL bIsInPlace = pImp->pFrame && pImp->pFrame->GetObjectShell()->IsInPlaceActive();
+
+ // Shell geh"ort zum Server?
+ // AppDispatcher oder IPFrame-Dispatcher
+ FASTBOOL bIsServerShell = !pImp->pFrame || bIsInPlace;
+
+ // Nat"urlich sind ServerShell-Slots auch ausf"uhrbar, wenn sie auf
+ // einem Container-Dispatcher ohne IPClient ausgef"uhrt werden sollen.
+ if ( !bIsServerShell )
+ {
+ SfxViewShell *pViewSh = pImp->pFrame->GetViewShell();
+ bIsServerShell = !pViewSh || !pViewSh->GetUIActiveClient();
+ }
+
+ // Shell geh"ort zum Container?
+ // AppDispatcher oder kein IPFrameDispatcher
+ FASTBOOL bIsContainerShell = !pImp->pFrame || !bIsInPlace;
+ // Shell und Slot passen zusammen
+ if ( !( ( bIsContainerSlot && bIsContainerShell ) ||
+ ( !bIsContainerSlot && bIsServerShell ) ) )
+ pSlot = 0;
+ }
+
+#ifdef DBG_UTILx
+ if ( pSlot )
+ {
+ String aMsg( nSlot );
+ aMsg += " found in ";
+ aMsg += pObjShell->GetInterface()->GetClassName();
+ DbgTrace( aMsg.GetBuffer() );
+ }
+ else
+ {
+ aStack += " ";
+ aStack += pObjShell->GetInterface()->GetClassName();
+ }
+#endif
+ if ( pSlot && !IsAllowed( nSlot ) )
+ {
+ pSlot = NULL;
+ }
+
+ if ( pSlot )
+ {
+ rServer.SetSlot(pSlot);
+ rServer.SetShellLevel(i);
+ return sal_True;
+ }
+ }
+
+#ifdef DBG_UTILx
+ String aMsg( nSlot );
+ aMsg += " not found in ";
+ aMsg += aStack;
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+ return sal_False;
+}
+
+sal_Bool SfxDispatcher::HasSlot_Impl( sal_uInt16 nSlot )
+{
+ Flush();
+ sal_uInt16 nTotCount = pImp->aStack.Count();
+
+ if ( pImp->pParent && !pImp->pParent->pImp->pFrame )
+ {
+ // the last frame also uses the AppDispatcher
+ nTotCount = nTotCount + pImp->aStack.Count();
+ }
+
+ if ( SfxMacroConfig::IsMacroSlot( nSlot ) )
+ // Makro-Slot?
+ return sal_True;
+ else if (nSlot >= SID_VERB_START && nSlot <= SID_VERB_END)
+ {
+ // Verb-Slot?
+ for ( sal_uInt16 nShell = 0;; ++nShell )
+ {
+ SfxShell *pSh = GetShell(nShell);
+ if ( pSh == NULL )
+ return false;
+ if ( pSh->ISA(SfxViewShell) )
+ return true;
+ }
+ }
+
+ // SID gegen gesetzten Filter pr"ufen
+ sal_uInt16 nSlotEnableMode=0;
+ if ( pImp->pFrame )
+ {
+ nSlotEnableMode = IsSlotEnabledByFilter_Impl( nSlot );
+ if ( 0 == nSlotEnableMode )
+ return sal_False;
+ }
+
+ // im Quiet-Mode nur Parent-Dispatcher
+ if ( pImp->bQuiet )
+ return sal_False;
+
+ sal_Bool bReadOnly = ( 2 != nSlotEnableMode && pImp->bReadOnly );
+// ( pImp->pFrame && pImp->pFrame->GetObjectShell());
+// pImp->pFrame->GetObjectShell()->IsLoading() );
+
+ for ( sal_uInt16 i=0 ; i < nTotCount; ++i )
+ {
+ SfxShell *pObjShell = GetShell(i);
+ SfxInterface *pIFace = pObjShell->GetInterface();
+ const SfxSlot *pSlot = pIFace->GetSlot(nSlot);
+ if ( pSlot && pSlot->nDisableFlags && ( pSlot->nDisableFlags & pObjShell->GetDisableFlags() ) != 0 )
+ return sal_False;
+
+ if ( pSlot && !( pSlot->nFlags & SFX_SLOT_READONLYDOC ) && bReadOnly )
+ return sal_False;
+
+ if ( pSlot )
+ {
+ // Slot geh"ort zum Container?
+ FASTBOOL bIsContainerSlot = pSlot->IsMode(SFX_SLOT_CONTAINER);
+ FASTBOOL bIsInPlace = pImp->pFrame && pImp->pFrame->GetObjectShell()->IsInPlaceActive();
+
+ // Shell geh"ort zum Server?
+ // AppDispatcher oder IPFrame-Dispatcher
+ FASTBOOL bIsServerShell = !pImp->pFrame || bIsInPlace;
+
+ // Nat"urlich sind ServerShell-Slots auch ausf"uhrbar, wenn sie auf
+ // einem Container-Dispatcher ohne IPClient ausgef"uhrt werden sollen.
+ if ( !bIsServerShell )
+ {
+ SfxViewShell *pViewSh = pImp->pFrame->GetViewShell();
+ bIsServerShell = !pViewSh || !pViewSh->GetUIActiveClient();
+ }
+
+ // Shell geh"ort zum Container?
+ // AppDispatcher oder kein IPFrameDispatcher
+ FASTBOOL bIsContainerShell = !pImp->pFrame || !bIsInPlace;
+
+ // Shell und Slot passen zusammen
+ if ( !( ( bIsContainerSlot && bIsContainerShell ) ||
+ ( !bIsContainerSlot && bIsServerShell ) ) )
+ pSlot = 0;
+ }
+
+ if ( pSlot && !IsAllowed( nSlot ) )
+ pSlot = NULL;
+
+ if ( pSlot )
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+
+
+//--------------------------------------------------------------------
+sal_Bool SfxDispatcher::_FillState
+(
+ const SfxSlotServer& rSvr, // abzufragende <Slot-Server>
+ SfxItemSet& rState, // zu f"ullendes <SfxItemSet>
+ const SfxSlot* pRealSlot // ggf. der tats"achliche Slot
+)
+
+/* [Beschreibung]
+
+ Hilfsmethode zum Abfragen des Status des <Slot-Server>s rSvr.
+ In rState m"ussen die gew"unschten Slots-Ids (teilweise in Which-Ids
+ des betreffenden Pools umgewandelt) vorhanden sein.
+
+ Der SfxDispatcher wird vor der Abfrage geflusht.
+*/
+
+{
+ SFX_STACK(SfxDispatcher::_FillState);
+
+ DBG_PROFSTART(SfxDispatcherFillState);
+
+ const SfxSlot *pSlot = rSvr.GetSlot();
+ if ( pSlot && IsLocked( pSlot->GetSlotId() ) )
+ {
+ pImp->bInvalidateOnUnlock = sal_True;
+ DBG_PROFSTOP(SfxDispatcherFillState);
+ return sal_False;
+ }
+
+ if ( pSlot )
+ {
+ DBG_ASSERT(bFlushed, "Dispatcher not flushed after retrieving slot servers!");
+ if ( !bFlushed )
+ return FALSE;
+ // Flush();
+
+ // Objekt ermitteln und Message an diesem Objekt aufrufen
+ SfxShell *pSh = GetShell(rSvr.GetShellLevel());
+ DBG_ASSERT(pSh, "ObjektShell nicht gefunden");
+
+ SfxStateFunc pFunc;
+
+ if (pRealSlot)
+ pFunc = pRealSlot->GetStateFnc();
+ else
+ pFunc = pSlot->GetStateFnc();
+
+ pSh->CallState( pFunc, rState );
+#ifdef DBG_UTIL
+ // pr"ufen, ob IDL (SlotMap) und aktuelle Items "ubereinstimmen
+ if ( DbgIsAssertWarning() && rState.Count() )
+ {
+ SfxInterface *pIF = pSh->GetInterface();
+ SfxItemIter aIter( rState );
+ for ( const SfxPoolItem *pItem = aIter.FirstItem();
+ pItem;
+ pItem = aIter.NextItem() )
+ if ( !IsInvalidItem(pItem) && !pItem->ISA(SfxVoidItem) )
+ {
+ sal_uInt16 nSlotId = rState.GetPool()->GetSlotId(pItem->Which());
+ if ( !pItem->IsA(pIF->GetSlot(nSlotId)->GetType()->Type()) )
+ {
+ ByteString aMsg( "item-type unequal to IDL (=> no BASIC)" );
+ aMsg += "\nwith SID: ";
+ aMsg += ByteString::CreateFromInt32( nSlotId );
+ aMsg += "\nin ";
+ aMsg += pIF->GetClassName();
+ DbgOut( aMsg.GetBuffer(), DBG_OUT_ERROR, __FILE__, __LINE__);
+ }
+ }
+ }
+#endif
+
+ DBG_PROFSTOP(SfxDispatcherFillState);
+ return sal_True;
+ }
+
+ DBG_PROFSTOP(SfxDispatcherFillState);
+ return sal_False;
+}
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxDispatcher::_Execute( const SfxSlotServer &rSvr )
+
+/* [Beschreibung]
+
+ Diese Methode f"uhrt einen Request "uber einen gecachten <Slot-Server>
+ aus.
+*/
+
+{
+ const SfxSlot *pSlot = rSvr.GetSlot();
+ if ( IsLocked( pSlot->GetSlotId() ) )
+ return 0;
+
+ if ( pSlot )
+ {
+ Flush();
+
+ sal_uInt16 nSlot = pSlot->GetSlotId();
+ if ( SfxMacroConfig::IsMacroSlot( nSlot ) )
+ SFX_APP()->GetMacroConfig()->RegisterSlotId( nSlot );
+
+ if ( pSlot->IsMode(SFX_SLOT_ASYNCHRON) )
+ //! ignoriert rSvr
+ {
+ SfxShell *pShell = GetShell( rSvr.GetShellLevel() );
+ SfxDispatcher *pDispat = this;
+ while ( pDispat )
+ {
+ sal_uInt16 nShellCount = pDispat->pImp->aStack.Count();
+ for ( sal_uInt16 n=0; n<nShellCount; n++ )
+ if ( pShell == pDispat->pImp->aStack.Top(n) )
+ {
+ pDispat->pImp->xPoster->Post(
+ new SfxRequest( pSlot->GetSlotId(),
+ SFX_CALLMODE_RECORD, pShell->GetPool() ) );
+// pDispat->pImp->xPoster->Post(new Executer(
+// new SfxRequest( pSlot->GetSlotId(),
+// SFX_CALLMODE_RECORD, pShell->GetPool() ),
+// pSlot, n ));
+ return 0;
+ }
+ }
+ }
+ else
+ {
+ // Objekt ermitteln und Message an diesem Objekt aufrufen
+ SfxShell *pSh = GetShell(rSvr.GetShellLevel());
+ SfxRequest aReq( pSlot->GetSlotId(), SFX_CALLMODE_RECORD, pSh->GetPool() );
+ if ( Call_Impl( *pSh, *pSlot, aReq, sal_True ) ) // von Bindings immer recorden
+ return aReq.GetReturnValue();
+ }
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------
+void SfxDispatcher::ExecutePopup( sal_uInt16 nConfigId,
+ Window *pWin, const Point *pPos,
+ const SfxPoolItem *, ... )
+{
+ ExecutePopup( nConfigId, pWin, pPos );
+}
+
+SfxPopupMenuManager* SfxDispatcher::Popup( sal_uInt16 nConfigId,Window *pWin, const Point *pPos )
+{
+ SfxDispatcher &rDisp = *SFX_APP()->GetDispatcher_Impl();
+ sal_uInt16 nShLevel = 0;
+ SfxShell *pSh;
+ nShLevel=0;
+
+ if ( rDisp.pImp->bQuiet )
+ {
+ nConfigId = 0;
+ nShLevel = rDisp.pImp->aStack.Count();
+ }
+
+ Window *pWindow = pWin ? pWin : rDisp.pImp->pFrame->GetFrame().GetWorkWindow_Impl()->GetWindow();
+ for ( pSh = rDisp.GetShell(nShLevel); pSh; ++nShLevel, pSh = rDisp.GetShell(nShLevel) )
+ {
+ const ResId& rResId = pSh->GetInterface()->GetPopupMenuResId();
+ if ( ( nConfigId == 0 && rResId.GetId() ) || ( nConfigId != 0 && rResId.GetId() == nConfigId ) )
+ {
+ return SfxPopupMenuManager::Popup( rResId, rDisp.GetFrame(), pPos ? *pPos : pWindow->GetPointerPosPixel(), pWindow );
+ }
+ }
+ return 0;
+}
+
+
+//----------------------------------------------------------------------
+void SfxDispatcher::ExecutePopup( sal_uInt16 nConfigId, Window *pWin, const Point *pPos )
+{
+ SfxDispatcher &rDisp = *SFX_APP()->GetDispatcher_Impl();
+ sal_uInt16 nShLevel = 0;
+ SfxShell *pSh;
+/*
+ const SvVerbList *pVerbList = 0;
+ sal_uInt16 nMaxShellLevel = rDisp.pImp->aStack.Count();
+ for ( pSh = rDisp.GetShell(nShLevel);
+ pSh && nShLevel < nMaxShellLevel ;
+ ++nShLevel, pSh = rDisp.GetShell(nShLevel) )
+ {
+ if ( pSh->GetVerbs() )
+ {
+ pVerbList = pSh->GetVerbs();
+ break;
+ }
+ }
+*/
+ nShLevel=0;
+ if ( rDisp.pImp->bQuiet )
+ {
+ nConfigId = 0;
+ nShLevel = rDisp.pImp->aStack.Count();
+ }
+
+ Window *pWindow = pWin ? pWin : rDisp.pImp->pFrame->GetFrame().GetWorkWindow_Impl()->GetWindow();
+ for ( pSh = rDisp.GetShell(nShLevel); pSh; ++nShLevel, pSh = rDisp.GetShell(nShLevel) )
+ {
+ const ResId& rResId = pSh->GetInterface()->GetPopupMenuResId();
+ if ( ( nConfigId == 0 && rResId.GetId() ) || ( nConfigId != 0 && rResId.GetId() == nConfigId ) )
+ {
+ //SfxPopupMenuManager aPop( rResId.GetId(), *rDisp.GetBindings() );
+ //aPop.SetResMgr(rResId.GetResMgr());
+ //aPop.AddClipboardFunctions();
+ //aPop.Initialize();
+ //if ( pVerbList && pVerbList->Count() )
+ // aPop.InsertVerbs(pVerbList);
+ //aPop.RemoveDisabledEntries();
+ //aPop.Execute( pPos ? *pPos : pWindow->GetPointerPosPixel(), pWindow );
+ SfxPopupMenuManager::ExecutePopup( rResId, rDisp.GetFrame(), pPos ? *pPos : pWindow->GetPointerPosPixel(), pWindow );
+ return;
+ }
+ }
+}
+
+//----------------------------------------------------------------------
+void SfxDispatcher::ExecutePopup( const ResId &rId, Window *pWin, const Point *pPos )
+{
+ Window *pWindow = pWin ? pWin : pImp->pFrame->GetFrame().GetWorkWindow_Impl()->GetWindow();
+/*
+ SfxPopupMenuManager aPop( rId, *GetBindings() );
+ aPop.AddClipboardFunctions();
+ aPop.Initialize();
+ aPop.RemoveDisabledEntries();
+ aPop.Execute( pPos ? *pPos : pWindow->GetPointerPosPixel(), pWindow );
+*/
+ SfxPopupMenuManager::ExecutePopup( rId, GetFrame(), pPos ? *pPos : pWindow->GetPointerPosPixel(), pWindow );
+}
+
+//--------------------------------------------------------------------
+void SfxDispatcher::Lock( sal_Bool bLock )
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann der SfxDispatcher gesperrt und freigegeben
+ werden. Ein gesperrter SfxDispatcher f"uhrt keine <SfxRequest>s mehr
+ aus und liefert keine Status-Informationen mehr. Er verh"alt sich
+ so als w"aren alle Slots disabled.
+*/
+
+{
+ SfxBindings* pBindings = GetBindings();
+ if ( !bLock && pImp->bLocked && pImp->bInvalidateOnUnlock )
+ {
+ if ( pBindings )
+ pBindings->InvalidateAll(sal_True);
+ pImp->bInvalidateOnUnlock = sal_False;
+ }
+ else if ( pBindings )
+ pBindings->InvalidateAll(sal_False);
+ pImp->bLocked = bLock;
+ if ( !bLock )
+ {
+ USHORT nCount = pImp->aReqArr.Count();
+ for ( USHORT i=0; i<nCount; i++ )
+ pImp->xPoster->Post( pImp->aReqArr[i] );
+ pImp->aReqArr.Remove( 0, nCount );
+ }
+}
+
+sal_uInt32 SfxDispatcher::GetObjectBarId( sal_uInt16 nPos ) const
+{
+ return pImp->aObjBars[nPos].nResId;
+}
+
+//--------------------------------------------------------------------
+void SfxDispatcher::ResetObjectBars_Impl()
+
+/* [Beschreibung]
+
+ Mit dieser Methode werden alle Objectbar-Anforderungen, die dieser
+ Dispatcher an das AppWindow hat, beseitigt.
+*/
+{
+ for (sal_uInt16 n=0; n<SFX_OBJECTBAR_MAX; n++)
+ pImp->aObjBars[n].nResId = 0;
+ pImp->aChildWins.Remove(0, pImp->aChildWins.Count());
+}
+
+
+//--------------------------------------------------------------------
+void SfxDispatcher::DebugOutput_Impl() const
+{
+#ifdef DBG_UTIL
+
+ sal_uInt16 nOld = (sal_uInt16) DbgGetData()->nTraceOut;
+ DbgGetData()->nTraceOut = DBG_OUT_FILE;
+
+ if (bFlushed)
+ DBG_TRACE("Flushed");
+ if (pImp->bUpdated)
+ DBG_TRACE("Updated");
+
+ for ( sal_uInt16 nShell = pImp->aStack.Count(); nShell > 0; --nShell )
+ {
+ SfxShell *pShell = GetShell(nShell-1);
+ const SfxInterface *pIFace = pShell->GetInterface();
+ DBG_TRACE (pIFace->GetClassName());
+ }
+
+ DbgGetData()->nTraceOut = nOld;
+
+#endif
+}
+
+void SfxDispatcher::LockUI_Impl( sal_Bool bLock )
+{
+ sal_Bool bWasLocked = pImp->bUILocked;
+ pImp->bUILocked = bLock;
+ if ( !bLock && bWasLocked )
+ Update_Impl( sal_True );
+}
+
+//-------------------------------------------------------------------------
+void SfxDispatcher::HideUI( sal_Bool bHide )
+{
+// if ( !bHide && pImp->bReadOnly )
+// bHide = sal_True;
+ sal_Bool bWasHidden = pImp->bNoUI;
+ pImp->bNoUI = bHide;
+ if ( pImp->pFrame )
+ {
+ SfxViewFrame* pTop = pImp->pFrame->GetTopViewFrame();
+ if ( pTop && pTop->GetBindings().GetDispatcher() == this )
+ {
+ SfxFrame& rFrame = pTop->GetFrame();
+ if ( rFrame.IsMenuBarOn_Impl() )
+ {
+ com::sun::star::uno::Reference < com::sun::star::beans::XPropertySet > xPropSet( rFrame.GetFrameInterface(), com::sun::star::uno::UNO_QUERY );
+ if ( xPropSet.is() )
+ {
+ com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+ com::sun::star::uno::Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
+ aValue >>= xLayoutManager;
+ if ( xLayoutManager.is() )
+ xLayoutManager->setVisible( !bHide );
+ }
+ }
+ }
+ }
+
+ if ( bHide != bWasHidden )
+ Update_Impl( sal_True );
+}
+
+void SfxDispatcher::SetReadOnly_Impl( sal_Bool bOn )
+{
+ pImp->bReadOnly = bOn;
+// pImp->bNoUI = bOn;
+}
+
+sal_Bool SfxDispatcher::GetReadOnly_Impl() const
+{
+ return pImp->bReadOnly;
+}
+
+//-------------------------------------------------------------------------
+void SfxDispatcher::SetQuietMode_Impl( sal_Bool bOn )
+
+/* [Beschreibung]
+
+ Bei 'bOn' stellt sich dieser Dispatcher quasi tot und leitet alles
+ an den Parent-Dispatcher weiter.
+*/
+
+{
+ pImp->bQuiet = bOn;
+ SfxBindings* pBindings = GetBindings();
+ if ( pBindings )
+ pBindings->InvalidateAll(sal_True);
+}
+
+//-------------------------------------------------------------------------
+void SfxDispatcher::SetModalMode_Impl( sal_Bool bOn )
+
+/* [Beschreibung]
+
+ Bei 'bOn' werden nur noch Slots des Parent-Dispatchers gefunden.
+*/
+
+{
+ pImp->bModal = bOn;
+ SfxBindings* pBindings = GetBindings();
+ if ( pBindings )
+ pBindings->InvalidateAll(sal_True);
+}
+
+void SfxDispatcher::SetExecuteMode( sal_uInt16 nMode )
+{
+ pImp->nStandardMode = nMode;
+}
+
+SfxItemState SfxDispatcher::QueryState( sal_uInt16 nSlot, const SfxPoolItem* &rpState )
+{
+ SfxShell *pShell = 0;
+ const SfxSlot *pSlot = 0;
+ if ( GetShellAndSlot_Impl( nSlot, &pShell, &pSlot, sal_False, sal_False ) )
+ {
+ rpState = pShell->GetSlotState(nSlot);
+ if ( !rpState )
+ return SFX_ITEM_DISABLED;
+ else
+ return SFX_ITEM_AVAILABLE;
+ }
+
+ return SFX_ITEM_DISABLED;
+}
+
+SfxItemState SfxDispatcher::QueryState( USHORT nSID, ::com::sun::star::uno::Any& rAny )
+{
+ SfxShell *pShell = 0;
+ const SfxSlot *pSlot = 0;
+ if ( GetShellAndSlot_Impl( nSID, &pShell, &pSlot, sal_False, sal_False ) )
+ {
+ const SfxPoolItem* pItem( 0 );
+
+ pItem = pShell->GetSlotState( nSID );
+ if ( !pItem )
+ return SFX_ITEM_DISABLED;
+ else
+ {
+ ::com::sun::star::uno::Any aState;
+ if ( !pItem->ISA(SfxVoidItem) )
+ {
+ USHORT nSubId( 0 );
+ SfxItemPool& rPool = pShell->GetPool();
+ USHORT nWhich = rPool.GetWhich( nSID );
+ if ( rPool.GetMetric( nWhich ) == SFX_MAPUNIT_TWIP )
+ nSubId |= CONVERT_TWIPS;
+ pItem->QueryValue( aState, (BYTE)nSubId );
+ }
+ rAny = aState;
+
+ return SFX_ITEM_AVAILABLE;
+ }
+ }
+
+ return SFX_ITEM_DISABLED;
+}
+
+sal_Bool SfxDispatcher::IsReadOnlyShell_Impl( sal_uInt16 nShell ) const
+{
+ sal_uInt16 nShellCount = pImp->aStack.Count();
+ if ( nShell < nShellCount )
+ {
+ SfxShell* pShell = pImp->aStack.Top( nShell );
+ if( pShell->ISA( SfxModule ) || pShell->ISA( SfxApplication ) || pShell->ISA( SfxViewFrame ) )
+ return sal_False;
+ else
+ return pImp->bReadOnly;
+ }
+ else if ( pImp->pParent )
+ return pImp->pParent->IsReadOnlyShell_Impl( nShell - nShellCount );
+ return sal_True;
+}
+
+// Ein dirty trick, um an die Methoden der private base class von
+// SfxShellStack_Impl heranzukommen
+class StackAccess_Impl : public SfxShellStack_Implarr_
+{};
+
+void SfxDispatcher::InsertShell_Impl( SfxShell& rShell, sal_uInt16 nPos )
+{
+ Flush();
+
+ // Der cast geht, weil SfxShellStack_Impl keine eigenen member hat
+ ((StackAccess_Impl*) (&pImp->aStack))->Insert( nPos, &rShell );
+ rShell.SetDisableFlags( pImp->nDisableFlags );
+ rShell.DoActivate_Impl(pImp->pFrame, sal_True);
+
+ if ( !SFX_APP()->IsDowning() )
+ {
+ pImp->bUpdated = sal_False;
+ pImp->pCachedServ1 = 0;
+ pImp->pCachedServ2 = 0;
+ InvalidateBindings_Impl(sal_True);
+ }
+}
+
+void SfxDispatcher::RemoveShell_Impl( SfxShell& rShell )
+{
+ Flush();
+
+ // Der cast geht, weil SfxShellStack_Impl keine eigenen member hat
+ StackAccess_Impl& rStack = *((StackAccess_Impl*) (&pImp->aStack));
+ sal_uInt16 nCount = rStack.Count();
+ for ( sal_uInt16 n=0; n<nCount; ++n )
+ {
+ if ( rStack[n] == &rShell )
+ {
+ rStack.Remove( n );
+ rShell.SetDisableFlags( 0 );
+ rShell.DoDeactivate_Impl(pImp->pFrame, sal_True);
+ break;
+ }
+ }
+
+ if ( !SFX_APP()->IsDowning() )
+ {
+ pImp->bUpdated = sal_False;
+ pImp->pCachedServ1 = 0;
+ pImp->pCachedServ2 = 0;
+ InvalidateBindings_Impl(sal_True);
+ }
+}
+
+sal_Bool SfxDispatcher::IsAllowed
+(
+ sal_uInt16 nSlot
+) const
+/*
+ [Beschreibung]
+ Die Methode prueft, ob der Zugriff auf diese Schnittstelle erlaubt ist.
+ */
+{
+ if ( !pImp->pDisableList )
+ {
+ return sal_True;
+ }
+
+ // BinSearch in der DisableListe
+ SvUShorts& rList = *pImp->pDisableList;
+ sal_uInt16 nCount = rList.Count();
+ sal_uInt16 nLow = 0, nMid = 0, nHigh;
+ sal_Bool bFound = sal_False;
+ nHigh = nCount - 1;
+
+ while ( !bFound && nLow <= nHigh )
+ {
+ nMid = (nLow + nHigh) >> 1;
+ DBG_ASSERT( nMid < nCount, "bsearch ist buggy" );
+
+ int nDiff = (int) nSlot - (int) rList[nMid];
+ if ( nDiff < 0)
+ {
+ if ( nMid == 0 )
+ break;
+ nHigh = nMid - 1;
+ }
+ else if ( nDiff > 0 )
+ {
+ nLow = nMid + 1;
+ if ( nLow == 0 )
+ break;
+ }
+ else
+ bFound = sal_True;
+ }
+
+#ifdef _DEBUG
+ // Slot in der Liste gefunden ?
+ sal_uInt16 nPos = bFound ? nMid : nLow;
+
+ DBG_ASSERT( nPos <= nCount, "" );
+ DBG_ASSERT( nPos == nCount || nSlot <= rList[nPos], "" );
+ DBG_ASSERT( nPos == 0 || nSlot > rList[nPos-1], "" );
+ DBG_ASSERT( ( (nPos+1) >= nCount ) || nSlot < rList[nPos+1], "" );
+#endif
+
+ return !bFound;
+}
+
+void SfxDispatcher::InvalidateBindings_Impl( sal_Bool bModify )
+{
+ // App-Dispatcher?
+ if ( IsAppDispatcher() )
+ {
+ for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst();
+ pFrame;
+ pFrame = SfxViewFrame::GetNext( *pFrame ) )
+ pFrame->GetBindings().InvalidateAll(bModify);
+ }
+ else
+ {
+ SfxDispatcher *pDisp = GetBindings()->GetDispatcher_Impl();
+ while ( pDisp )
+ {
+ if ( pDisp == this )
+ {
+ GetBindings()->InvalidateAll( bModify );
+ break;
+ }
+
+ pDisp = pDisp->pImp->pParent;
+ }
+ }
+}
+
+sal_Bool SfxDispatcher::IsUpdated_Impl() const
+{
+ return pImp->bUpdated;
+}
+
+void SfxDispatcher::SetDisableFlags( sal_uInt32 nFlags )
+{
+ pImp->nDisableFlags = nFlags;
+ for ( int i = int(pImp->aStack.Count()) - 1; i >= 0; --i )
+ pImp->aStack.Top( (sal_uInt16) i )->SetDisableFlags( nFlags );
+}
+
+sal_uInt32 SfxDispatcher::GetDisableFlags() const
+{
+ return pImp->nDisableFlags;
+}
+
+SfxModule* SfxDispatcher::GetModule() const
+{
+ for ( sal_uInt16 nShell = 0;; ++nShell )
+ {
+ SfxShell *pSh = GetShell(nShell);
+ if ( pSh == NULL )
+ return 0;
+ if ( pSh->ISA(SfxModule) )
+ return (SfxModule*) pSh;
+ }
+}
diff --git a/sfx2/source/control/macrconf.cxx b/sfx2/source/control/macrconf.cxx
new file mode 100644
index 000000000000..079c7180ac1a
--- /dev/null
+++ b/sfx2/source/control/macrconf.cxx
@@ -0,0 +1,874 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <basic/sbstar.hxx>
+#include <basic/basmgr.hxx>
+#ifndef _SBX_HXX //autogen
+#include <basic/sbx.hxx>
+#endif
+#include <svl/intitem.hxx>
+#include <basic/sbmeth.hxx>
+#include <basic/sbmod.hxx>
+#ifndef _BASIC_SBUNO_HXX
+#include <basic/sbuno.hxx>
+#endif
+
+#include <osl/mutex.hxx>
+
+#include <com/sun/star/script/XEngine.hpp>
+#include <com/sun/star/document/MacroExecMode.hpp>
+
+#ifndef GCC
+#endif
+
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+#include <unotools/intlwrapper.hxx>
+
+#include <sfx2/msgpool.hxx>
+#include <sfx2/macrconf.hxx>
+#include "sfxbasic.hxx"
+#include <sfx2/sfx.hrc>
+#include <sfx2/app.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/dispatch.hxx>
+#include "sfx2/minfitem.hxx"
+#include "sfx2/imgmgr.hxx"
+#include <sfx2/evntconf.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/genlink.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <appdata.hxx>
+#include "objshimp.hxx"
+#include <sfx2/request.hxx>
+
+static const sal_uInt16 nCompatVersion = 2;
+static const sal_uInt16 nVersion = 3;
+
+// Static member
+SfxMacroConfig* SfxMacroConfig::pMacroConfig = NULL;
+
+SfxMacroConfig* SfxMacroConfig::GetOrCreate()
+{
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
+ if ( !pMacroConfig )
+ pMacroConfig = new SfxMacroConfig;
+ return pMacroConfig;
+}
+
+void SfxMacroConfig::Release_Impl()
+{
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
+ DELETEZ( pMacroConfig );
+}
+
+//==========================================================================
+
+struct SfxMacroConfig_Impl
+{
+ SfxMacroInfoArr_Impl aArr;
+ sal_uInt32 nEventId;
+ sal_Bool bWaitingForCallback;
+
+ SfxMacroConfig_Impl()
+ : nEventId( 0 )
+ , bWaitingForCallback( sal_False )
+ {}
+};
+
+//==========================================================================
+
+SbMethod* SfxQueryMacro_Impl( BasicManager* pMgr , const String& rMacro,
+ const String &rLibName, const String& rModule )
+{
+ IntlWrapper aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ const CollatorWrapper* pCollator = aIntlWrapper.getCollator();
+ sal_uInt16 nLibCount = pMgr->GetLibCount();
+ for ( sal_uInt16 nLib = 0; nLib < nLibCount; ++nLib )
+ {
+ if ( COMPARE_EQUAL == pCollator->compareString( pMgr->GetLibName( nLib ), rLibName ) )
+ {
+ StarBASIC* pLib = pMgr->GetLib( nLib );
+ if( !pLib )
+ {
+ pMgr->LoadLib( nLib );
+ pLib = pMgr->GetLib( nLib );
+ }
+
+ if( pLib )
+ {
+ sal_uInt16 nModCount = pLib->GetModules()->Count();
+ for( sal_uInt16 nMod = 0; nMod < nModCount; ++nMod )
+ {
+ SbModule* pMod = (SbModule*)pLib->GetModules()->Get( nMod );
+ if ( pMod && COMPARE_EQUAL == pCollator->compareString( pMod->GetName(), rModule ) )
+ {
+ SbMethod* pMethod = (SbMethod*)pMod->Find( rMacro, SbxCLASS_METHOD );
+ if( pMethod )
+ return pMethod;
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+SbMethod* SfxQueryMacro( BasicManager* pMgr , const String& rMacro )
+{
+ sal_uInt16 nLast = 0;
+ String aMacro = rMacro;
+ String aLibName = aMacro.GetToken( 0, '.', nLast );
+ String aModule = aMacro.GetToken( 0, '.', nLast );
+ aMacro.Erase( 0, nLast );
+
+ return SfxQueryMacro_Impl( pMgr, aMacro, aLibName, aModule );
+}
+
+ErrCode SfxCallMacro( BasicManager* pMgr, const String& rCode,
+ SbxArray *pArgs, SbxValue *pRet )
+{
+ ErrCode nErr;
+ SfxApplication *pApp = SFX_APP();
+ pApp->EnterBasicCall();
+ SbMethod* pMethod = SfxQueryMacro( pMgr, rCode );
+ if ( pMethod )
+ {
+ if ( pArgs )
+ pMethod->SetParameters( pArgs );
+ nErr = pMethod->Call( pRet );
+ }
+ else
+ nErr = ERRCODE_BASIC_PROC_UNDEFINED;
+
+ pApp->LeaveBasicCall();
+ return nErr;
+}
+
+//==========================================================================
+
+SfxMacroInfo::SfxMacroInfo( const String& rURL ) :
+ pHelpText(0),
+ nRefCnt(0),
+ bAppBasic(TRUE),
+ nSlotId(0),
+ pSlot(0)
+{
+ if ( rURL.CompareToAscii( "macro:", 6 ) == COMPARE_EQUAL )
+ {
+ String aTmp = rURL.Copy( 6 );
+ if ( aTmp.GetTokenCount('/') > 3 )
+ {
+ // 'macro:///lib.mod.proc(args)' => Macro via App-BASIC-Mgr
+ // 'macro://[docname|.]/lib.mod.proc(args)' => Macro via zugehoerigen Doc-BASIC-Mgr
+ if ( aTmp.CompareToAscii("///", 3 ) != COMPARE_EQUAL )
+ bAppBasic = FALSE;
+ aTmp = rURL.GetToken( 3, '/' );
+ if ( aTmp.GetTokenCount('.') == 3 )
+ {
+ aLibName = aTmp.GetToken( 0, '.' );
+ aModuleName = aTmp.GetToken( 1, '.' );
+ aMethodName = aTmp.GetToken( 2, '.' );
+
+ // Remove arguments to be compatible
+ aMethodName.SearchAndReplaceAscii( "()", String(), sal::static_int_cast< xub_StrLen >(std::max( aMethodName.Len()-2, 0 )));
+ }
+ }
+
+ DBG_ASSERT( aLibName.Len() && aModuleName.Len() && aMethodName.Len(), "Wrong macro URL!" );
+ }
+ else
+ aMethodName = rURL;
+}
+
+SfxMacroInfo::SfxMacroInfo( bool _bAppBasic ) :
+ pHelpText(0),
+ nRefCnt(0),
+ bAppBasic(_bAppBasic),
+ nSlotId(0),
+ pSlot(0)
+{}
+
+//==========================================================================
+
+SfxMacroInfo::SfxMacroInfo(bool _bAppBasic, const String& rLibName,
+ const String& rModuleName, const String& rMethodName) :
+ pHelpText(0),
+ nRefCnt(0),
+ bAppBasic(_bAppBasic),
+ aLibName(rLibName),
+ aModuleName(rModuleName),
+ aMethodName(rMethodName),
+ nSlotId(0),
+ pSlot(0)
+{
+}
+
+//==========================================================================
+
+SfxMacroInfo::SfxMacroInfo(bool _bAppBasic, const String& rQualifiedName )
+: pHelpText(0),
+ nRefCnt(0),
+ bAppBasic(_bAppBasic),
+ nSlotId(0),
+ pSlot(0)
+{
+ sal_uInt16 nCount = rQualifiedName.GetTokenCount('.');
+ aMethodName = rQualifiedName.GetToken( nCount-1, '.' );
+ if ( nCount > 1 )
+ aModuleName = rQualifiedName.GetToken( nCount-2, '.' );
+ if ( nCount > 2 )
+ aLibName = rQualifiedName.GetToken( 0, '.' );
+}
+
+//==========================================================================
+
+SfxMacroInfo::SfxMacroInfo(SfxMacroInfo& rOther) :
+ pHelpText(0),
+ nRefCnt(0),
+ bAppBasic(rOther.bAppBasic),
+ aLibName(rOther.aLibName),
+ aModuleName(rOther.aModuleName),
+ aMethodName(rOther.aMethodName),
+ nSlotId(rOther.nSlotId),
+ pSlot(0)
+{}
+
+//==========================================================================
+
+SfxMacroInfo::~SfxMacroInfo()
+{
+ delete pSlot;
+ delete pHelpText;
+}
+
+//==========================================================================
+
+sal_Bool SfxMacroInfo::operator==(const SfxMacroInfo& rOther) const
+{
+ if ( GetQualifiedName() == rOther.GetQualifiedName() &&
+ bAppBasic == rOther.bAppBasic )
+ return sal_True;
+ else
+ return sal_False;
+}
+
+//==========================================================================
+
+String SfxMacroInfo::GetMacroName() const
+{
+ String aMacroName = aMethodName;
+ aMacroName += '(';
+ aMacroName += aLibName;
+ aMacroName += '.';
+ aMacroName += aModuleName;
+ aMacroName += ')';
+ return aMacroName;
+}
+
+//==========================================================================
+
+String SfxMacroInfo::GetQualifiedName() const
+{
+ String aMacroName;
+ if( aMacroName.Len() || aLibName.Len() )
+ {
+ // Altes Format
+ aMacroName = aLibName;
+ aMacroName += '.';
+ aMacroName += aModuleName;
+ aMacroName += '.';
+ }
+
+ // Wg. ::com::sun::star::script::JavaScript kein Zerlegen des Strings mehr
+ aMacroName += aMethodName;
+ return aMacroName;
+}
+
+String SfxMacroInfo::GetFullQualifiedName() const
+{
+ // Liefert nur Unsinn, wenn f"ur ein ::com::sun::star::script::JavaScript aufgerufen !
+ String aRet;
+ if ( bAppBasic )
+ aRet = SFX_APP()->GetName();
+ aRet += '.';
+ aRet += GetQualifiedName();
+ return aRet;
+}
+
+String SfxMacroInfo::GetURL() const
+{
+ if ( !aLibName.Len() )
+ return aMethodName;
+
+ // 'macro:///lib.mod.proc(args)' => Macro via App-BASIC-Mgr
+ // 'macro://[docname|.]/lib.mod.proc(args)' => Macro via zugehoerigen Doc-BASIC-Mgr
+ // 'macro://obj.method(args)' => Object via App-BASIC-Mgr
+ String aURL( String::CreateFromAscii("macro://") );
+ if ( !bAppBasic )
+ aURL += '.';
+ aURL += '/';
+ aURL += aLibName;
+ aURL += '.';
+ aURL += aModuleName;
+ aURL += '.';
+ aURL += aMethodName;
+ aURL += String::CreateFromAscii("()");
+
+ return aURL;
+}
+
+//==========================================================================
+
+BasicManager* SfxMacroInfo::GetBasicManager() const
+{
+ if (bAppBasic)
+ {
+ return SFX_APP()->GetBasicManager();
+ }
+ else
+ {
+ SfxObjectShell *pCurrDocShell = SfxObjectShell::Current();
+ return pCurrDocShell ? pCurrDocShell->GetBasicManager() :
+ SFX_APP()->GetBasicManager();
+ }
+}
+
+//==========================================================================
+
+String SfxMacroInfo::GetBasicName() const
+{
+ if (bAppBasic)
+ {
+ return SFX_APP()->GetName();
+ }
+ else
+ {
+ SfxObjectShell *pCurrDocShell = SfxObjectShell::Current();
+ if ( pCurrDocShell )
+ return pCurrDocShell->GetTitle();
+ else
+ return SFX_APP()->GetName();
+ }
+}
+
+String SfxMacroInfo::GetHelpText() const
+{
+ if ( pHelpText )
+ return *pHelpText;
+ return String();
+}
+
+String SfxMacroConfig::RequestHelp( sal_uInt16 nId )
+{
+ SfxMacroInfo *pInfo = SFX_APP()->GetMacroConfig()->GetMacroInfo( nId );
+ if ( !pInfo )
+ return String();
+
+ if ( !pInfo->pHelpText )
+ {
+ SbMethod *pMethod =
+ SfxQueryMacro_Impl( pInfo->GetBasicManager(), pInfo->aMethodName,
+ pInfo->aLibName, pInfo->aModuleName );
+ if ( pMethod && pMethod->GetInfo() )
+ pInfo->pHelpText = new String( pMethod->GetInfo()->GetComment() );
+ }
+
+ return pInfo->GetHelpText();
+}
+
+void SfxMacroInfo::SetHelpText( const String& rName )
+{
+ if ( !pHelpText )
+ pHelpText = new String;
+ *pHelpText = rName;
+}
+
+//==========================================================================
+
+SvStream& operator >> (SvStream& rStream, SfxMacroInfo& rInfo)
+{
+ sal_uInt16 nAppBasic, nFileVersion;
+ String aDocName;
+
+ rStream >> nFileVersion;
+ if ( nVersion < nCompatVersion )
+ {
+ // In der 1.Version ohne Versionskennung
+ nAppBasic = nVersion;
+ nFileVersion = 1;
+ rStream.ReadByteString(aDocName,RTL_TEXTENCODING_UTF8);
+ rStream.ReadByteString(rInfo.aLibName,RTL_TEXTENCODING_UTF8);
+ rStream.ReadByteString(rInfo.aModuleName,RTL_TEXTENCODING_UTF8);
+ rStream.ReadByteString(rInfo.aMethodName,RTL_TEXTENCODING_UTF8);
+ }
+ else
+ {
+ String aInput;
+ rStream >> nAppBasic;
+ rStream.ReadByteString(aDocName,RTL_TEXTENCODING_UTF8); // Vorsicht: kann bei AppName Unsinn sein!
+ rStream.ReadByteString(rInfo.aLibName,RTL_TEXTENCODING_UTF8);
+ rStream.ReadByteString(rInfo.aModuleName,RTL_TEXTENCODING_UTF8);
+ rStream.ReadByteString(aInput,RTL_TEXTENCODING_UTF8);
+
+ if ( nFileVersion == nCompatVersion )
+ rInfo.aMethodName = aInput;
+ else
+ {
+ sal_uInt16 nCount = aInput.GetTokenCount('.');
+ rInfo.aMethodName = aInput.GetToken( nCount-1, '.' );
+ if ( nCount > 1 )
+ rInfo.aModuleName = aInput.GetToken( nCount-2, '.' );
+ if ( nCount > 2 )
+ rInfo.aLibName = aInput.GetToken( 0, '.' );
+ }
+ }
+
+ rInfo.bAppBasic = (sal_Bool) nAppBasic;
+ return rStream;
+}
+
+int SfxMacroInfo::Load( SvStream& rStream )
+{
+ rStream >> (*this);
+ nSlotId = SFX_APP()->GetMacroConfig()->GetSlotId(this);
+ return 0;
+}
+
+//==========================================================================
+
+SvStream& operator << (SvStream& rStream, const SfxMacroInfo& rInfo)
+{
+ if ( rInfo.bAppBasic )
+ {
+ rStream << nVersion
+ << (sal_uInt16) rInfo.bAppBasic;
+ rStream.WriteByteString(rInfo.GetBasicName(),RTL_TEXTENCODING_UTF8);
+ rStream.WriteByteString(rInfo.aLibName,RTL_TEXTENCODING_UTF8);
+ rStream.WriteByteString(rInfo.aModuleName,RTL_TEXTENCODING_UTF8);
+ rStream.WriteByteString(rInfo.aMethodName,RTL_TEXTENCODING_UTF8);
+ }
+ else
+ {
+ rStream << nVersion
+ << (sal_uInt16) rInfo.bAppBasic;
+ rStream.WriteByteString(SFX_APP()->GetName(),RTL_TEXTENCODING_UTF8);
+ rStream.WriteByteString(rInfo.aLibName,RTL_TEXTENCODING_UTF8);
+ rStream.WriteByteString(rInfo.aModuleName,RTL_TEXTENCODING_UTF8);
+ rStream.WriteByteString(rInfo.aMethodName,RTL_TEXTENCODING_UTF8);
+ }
+
+ return rStream;
+}
+
+sal_Bool SfxMacroInfo::Compare( const SvxMacro& rMacro ) const
+{
+ String aName = rMacro.GetLibName();
+ aName += '.';
+ aName += rMacro.GetMacName();
+ if ( GetFullQualifiedName() == aName )
+ return sal_True;
+ return sal_False;
+}
+
+//==========================================================================
+
+SfxMacroConfig::SfxMacroConfig()
+{
+ pImp = new SfxMacroConfig_Impl;
+}
+
+//==========================================================================
+
+SfxMacroConfig::~SfxMacroConfig()
+{
+ if ( pImp->nEventId )
+ Application::RemoveUserEvent( pImp->nEventId );
+ delete pImp;
+}
+
+//==========================================================================
+
+SFX_STATE_STUB( SfxApplication, MacroState_Impl )
+SFX_EXEC_STUB( SfxApplication, MacroExec_Impl )
+
+sal_uInt16 SfxMacroConfig::GetSlotId(SfxMacroInfoPtr pInfo)
+{
+ sal_uInt16 nCount = pImp->aArr.Count(); // Macro suchen
+ sal_uInt16 i;
+ for (i=0; i<nCount; i++)
+ if ((*(pImp->aArr)[i]) == (*pInfo))
+ break;
+
+ if (i == nCount)
+ { // Macro noch unbekannt
+ nCount = aIdArray.Count();
+ sal_uInt16 n;
+ for (n=0; n<nCount; n++) // freie SlotId suchen
+ if (aIdArray[n] > SID_MACRO_START + n)
+ break;
+
+ sal_uInt16 nNewSlotId = SID_MACRO_START + n;
+ if ( nNewSlotId > SID_MACRO_END )
+ return 0;
+ aIdArray.Insert( SID_MACRO_START + n, n );
+
+ SfxSlot *pNewSlot = new SfxSlot;
+ pNewSlot->nSlotId = SID_MACRO_START + n;
+ pNewSlot->nGroupId = 0;
+ pNewSlot->nFlags = SFX_SLOT_ASYNCHRON;
+ pNewSlot->nMasterSlotId = 0;
+ pNewSlot->nValue = 0;
+ pNewSlot->fnExec = SFX_STUB_PTR(SfxApplication,MacroExec_Impl);
+ pNewSlot->fnState = SFX_STUB_PTR(SfxApplication,MacroState_Impl);
+ pNewSlot->pType = 0; HACK(SFX_TYPE(SfxVoidItem))
+ pNewSlot->pName = pNewSlot->pMethodName = U2S(pInfo->aMethodName).getStr();
+ pNewSlot->pLinkedSlot = 0;
+ pNewSlot->nArgDefCount = 0;
+ pNewSlot->pFirstArgDef = 0;
+ pNewSlot->pUnoName = 0;
+
+ if (nCount)
+ {
+ SfxSlot *pSlot = (pImp->aArr)[0]->pSlot;
+ pNewSlot->pNextSlot = pSlot->pNextSlot;
+ pSlot->pNextSlot = pNewSlot;
+ }
+ else
+ pNewSlot->pNextSlot = pNewSlot;
+
+ // Macro uebernehmen
+ SfxMacroInfoPtr pNewInfo = new SfxMacroInfo(*pInfo);
+ pNewInfo->nSlotId = SID_MACRO_START + n;
+ pImp->aArr.Insert(pNewInfo,n);
+ pNewInfo->pSlot = pNewSlot;
+ pInfo->nSlotId = pNewInfo->nSlotId;
+ pNewInfo->nRefCnt++;
+ }
+ else
+ {
+ pInfo->nSlotId = (pImp->aArr)[i]->nSlotId;
+ (pImp->aArr)[i]->nRefCnt++;
+ }
+
+ return pInfo->nSlotId;
+}
+
+//==========================================================================
+
+void SfxMacroConfig::ReleaseSlotId(sal_uInt16 nId)
+{
+ DBG_ASSERT( IsMacroSlot( nId ), "SlotId ist kein Macro!");
+
+ sal_uInt16 nCount = pImp->aArr.Count();
+ for (sal_uInt16 i=0; i<nCount; i++)
+ {
+ SfxMacroInfo *pInfo = (pImp->aArr)[i];
+ if (pInfo->nSlotId == nId)
+ {
+ pInfo->nRefCnt--;
+ if (pInfo->nRefCnt == 0)
+ {
+ // Slot wird nicht mehr referenziert, also holen
+ SfxSlot *pSlot = pInfo->pSlot;
+
+ // Slot aus der Verkettung rausnehmen
+ while (pSlot->pNextSlot != pInfo->pSlot)
+ pSlot = (SfxSlot*) pSlot->pNextSlot;
+ pSlot->pNextSlot = pInfo->pSlot->pNextSlot;
+
+ // Slot selbst kurz schlie\sen
+ pSlot = pInfo->pSlot;
+ pSlot->pNextSlot = pSlot;
+
+ // MacroInfo aus Array entfernen, damit sie kein Unheil
+ // anrichten kann
+ pImp->aArr.Remove(i);
+
+ // SlotId wieder freigeben
+ sal_uInt16 nIdCount = aIdArray.Count();
+ for (sal_uInt16 n=0; n<nIdCount; n++)
+ {
+ if (aIdArray[n] == nId)
+ {
+ aIdArray.Remove(n);
+ break;
+ }
+ }
+
+ // Sofern nicht die Applikation heruntergefahren wird, mu\s
+ // der Slot asynchron gel"oscht werden, falls er in seinem
+ // eigenen Execute abgeschossen wird!
+ if ( !SFX_APP()->Get_Impl()->bInQuit )
+ pImp->nEventId = Application::PostUserEvent( LINK(this, SfxMacroConfig, EventHdl_Impl), pInfo );
+ else
+ EventHdl_Impl( pInfo );
+ }
+ return;
+ }
+ }
+
+ DBG_ERROR("Macro-SlotId nicht gefunden!");
+}
+
+//==========================================================================
+
+void SfxMacroConfig::RegisterSlotId(sal_uInt16 nId)
+{
+ DBG_ASSERT( IsMacroSlot( nId ), "SlotId ist kein Macro!");
+
+ sal_uInt16 nCount = pImp->aArr.Count();
+ for (sal_uInt16 i=0; i<nCount; i++)
+ {
+ if ((pImp->aArr)[i]->nSlotId == nId)
+ {
+ (pImp->aArr)[i]->nRefCnt++;
+ return;
+ }
+ }
+
+ DBG_ERROR("Macro-SlotId nicht gefunden!");
+}
+
+//==========================================================================
+
+SfxMacroInfo* SfxMacroConfig::GetMacroInfo(sal_uInt16 nId) const
+{
+ sal_uInt16 nCount = pImp->aArr.Count();
+ for (sal_uInt16 i=0; i<nCount; i++)
+ if ((pImp->aArr)[i]->nSlotId == nId)
+ return (pImp->aArr)[i];
+
+ return 0;
+}
+
+//==========================================================================
+
+const SfxMacroInfo* SfxMacroConfig::GetMacroInfo_Impl( const SvxMacro *pMacro ) const
+{
+ sal_uInt16 nCount = pImp->aArr.Count();
+ for (sal_uInt16 i=0; i<nCount; i++)
+ if ((pImp->aArr)[i]->Compare(*pMacro) )
+ return (pImp->aArr)[i];
+ return 0;
+}
+
+//==========================================================================
+
+sal_Bool SfxMacroConfig::ExecuteMacro( sal_uInt16 nId, const String& rArgs ) const
+{
+ const SfxMacroInfo* pInfo = GetMacroInfo( nId );
+ if ( !pInfo )
+ return sal_False;
+
+ SfxObjectShell* pSh = SfxObjectShell::Current();
+
+ SvxMacro aMacro( pInfo->GetQualifiedName(), pInfo->GetBasicName(), STARBASIC );
+ sal_Bool bRet = ExecuteMacro( pSh, &aMacro, rArgs );
+
+ // Release, da im Dispatcher-Execute ein Register gemacht wurde
+ ((SfxMacroConfig*)this)->ReleaseSlotId( nId );
+ return bRet;
+}
+
+sal_Bool SfxMacroConfig::ExecuteMacro( SfxObjectShell *pSh, const SvxMacro* pMacro, const String& /*rArgs*/ ) const
+{
+ SfxApplication *pApp = SFX_APP();
+
+ // Name des Macros oder Scripts bzw. ScriptCode
+ String aCode( pMacro->GetMacName() );
+ ErrCode nErr = ERRCODE_NONE;
+
+ // Ist es ein Basic-Macro ?
+ ScriptType eSType = pMacro->GetScriptType();
+ sal_Bool bIsBasic = eSType == STARBASIC;
+ sal_Bool bIsStarScript = ( eSType == EXTENDED_STYPE && pMacro->GetLibName().SearchAscii( "StarScript" ) != STRING_NOTFOUND );
+ sal_Bool bIsBasicLibBased = bIsBasic || bIsStarScript || !pSh;
+
+ if ( bIsBasicLibBased )
+ {
+ pApp->EnterBasicCall();
+ BasicManager *pAppMgr = SFX_APP()->GetBasicManager();
+ if( bIsBasic )
+ {
+ // BasicManager von Document?
+ BasicManager *pMgr = pSh ? pSh->GetBasicManager() : NULL;
+
+ // Da leider der Name zwischendurch h"aufig gewechselt hat ...
+ if( SFX_APP()->GetName() == pMacro->GetLibName() ||
+ pMacro->GetLibName().EqualsAscii("StarDesktop") )
+ pMgr = pAppMgr;
+ else if ( pMgr == pAppMgr )
+ pMgr = NULL;
+
+ if ( pSh && pMgr && pMgr != pAppMgr )
+ {
+ if ( !pSh->AdjustMacroMode( String() ) )
+ return sal_False;
+ }
+
+ if ( pSh && pMgr && pMgr == pAppMgr )
+ {
+ ::com::sun::star::uno::Any aOldThisComponent = pAppMgr->SetGlobalUNOConstant( "ThisComponent", makeAny( pSh->GetModel() ) );
+ nErr = Call( 0, aCode, pMgr );
+ pAppMgr->SetGlobalUNOConstant( "ThisComponent", aOldThisComponent );
+ }
+ else if ( pMgr )
+ nErr = Call( 0, aCode, pMgr );
+ else
+ nErr = SbxERR_NO_METHOD;
+
+ }
+
+ pApp->LeaveBasicCall();
+ }
+ else
+ {
+ nErr = SbxERR_NO_METHOD;
+ }
+
+ return ( nErr == ERRCODE_NONE );
+}
+
+sal_Bool SfxMacroConfig::CheckMacro( SfxObjectShell *pSh, const SvxMacro* pMacro ) const
+{
+ SfxApplication *pApp = SFX_APP();
+
+ // Name des Macros oder Scripts bzw. ScriptCode
+ String aCode( pMacro->GetMacName() );
+ ErrCode nErr = ERRCODE_NONE;
+
+ // BasicManager von Document oder Application
+ pApp->EnterBasicCall();
+ BasicManager *pAppMgr = SFX_APP()->GetBasicManager();
+ BasicManager *pMgr = pSh ? pSh->GetBasicManager() : NULL;
+
+ // Da leider der Name zwischendurch h"aufig gewechselt hat ...
+ if( SFX_APP()->GetName() == pMacro->GetLibName() ||
+ pMacro->GetLibName().EqualsAscii("StarDesktop") )
+ pMgr = pAppMgr;
+ else if ( pMgr == pAppMgr )
+ pMgr = NULL;
+
+ if ( !pMgr || !SfxQueryMacro( pMgr, aCode ) )
+ nErr = SbxERR_NO_METHOD;
+ pApp->LeaveBasicCall();
+ return ( nErr == ERRCODE_NONE );
+}
+
+//==========================================================================
+
+sal_Bool SfxMacroConfig::CheckMacro( sal_uInt16 nId ) const
+{
+ const SfxMacroInfo* pInfo = GetMacroInfo( nId );
+ if ( !pInfo )
+ return sal_False;
+
+ // Basic nur initialisieren, wenn default nicht ::com::sun::star::script::JavaScript; dann mu\s
+ // in IsBasic() sowieso das Basic angelegt werden
+ SfxObjectShell* pSh = SfxObjectShell::Current();
+
+ SfxApplication *pApp = SFX_APP();
+ pApp->EnterBasicCall();
+
+ // BasicManager von Document oder Application
+ BasicManager *pAppMgr = SFX_APP()->GetBasicManager();
+ BasicManager *pMgr = pSh ? pSh->GetBasicManager() : NULL;
+
+ if( SFX_APP()->GetName() == pInfo->GetBasicName() )
+ pMgr = SFX_APP()->GetBasicManager();
+ else if ( pMgr == pAppMgr )
+ pMgr = NULL;
+
+ String aFull( pInfo->GetQualifiedName() );
+ sal_Bool bIsBasic = pMgr ? IsBasic( 0, aFull, pMgr ) : sal_False;
+ pApp->LeaveBasicCall();
+ return bIsBasic;
+}
+
+//==========================================================================
+
+IMPL_LINK( SfxMacroConfig, CallbackHdl_Impl, SfxMacroConfig*, pConfig )
+{
+ (void)pConfig; // unused
+ pImp->bWaitingForCallback = sal_False;
+ return 0;
+}
+
+IMPL_LINK( SfxMacroConfig, EventHdl_Impl, SfxMacroInfo*, pInfo )
+{
+ delete pInfo;
+ pImp->nEventId = 0;
+ return 0;
+}
+
+sal_Bool SfxMacroConfig::IsBasic(
+ SbxObject* /*pVCtrl*/,
+ const String& rCode,
+ BasicManager* pMgr )
+{
+ sal_Bool bFound;
+ SFX_APP()->EnterBasicCall();
+ bFound = SfxQueryMacro( pMgr, rCode ) != 0;
+ SFX_APP()->LeaveBasicCall();
+ return bFound;
+}
+
+ErrCode SfxMacroConfig::Call(
+ SbxObject* /*pVCtrl*/,
+ const String& rCode,
+ BasicManager* pMgr,
+ SbxArray *pArgs,
+ SbxValue *pRet )
+{
+ SfxApplication *pApp = SFX_APP();
+ pApp->EnterBasicCall();
+ SbMethod* pMethod = SfxQueryMacro( pMgr, rCode );
+ ErrCode nErr = 0;
+ if( pMethod )
+ {
+ if ( pArgs )
+ pMethod->SetParameters( pArgs );
+ nErr = pMethod->Call( pRet );
+ }
+ else
+ nErr = ERRCODE_BASIC_PROC_UNDEFINED;
+
+ pApp->LeaveBasicCall();
+ return nErr;
+}
+
+
+sal_Bool SfxMacroConfig::IsMacroSlot( sal_uInt16 nId )
+{
+ return ( nId >= SID_MACRO_START && nId <= SID_MACRO_END );
+}
+
+
diff --git a/sfx2/source/control/macro.cxx b/sfx2/source/control/macro.cxx
new file mode 100644
index 000000000000..04a820d8e0ac
--- /dev/null
+++ b/sfx2/source/control/macro.cxx
@@ -0,0 +1,708 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#if OSL_DEBUG_LEVEL > 1
+#include <tools/stream.hxx>
+#endif
+
+#include "macro.hxx"
+#include <sfx2/request.hxx>
+#include <sfx2/msg.hxx>
+
+//====================================================================
+
+SV_DECL_PTRARR_DEL( SfxStatements_Impl, SfxMacroStatement*, 16, 8 )
+SV_IMPL_PTRARR( SfxStatements_Impl, SfxMacroStatement* );
+
+//--------------------------------------------------------------------
+
+struct SfxMacro_Impl
+
+/* [Beschreibung]
+
+ Implementations-Struktur der Klasse <SfxMacro>.
+*/
+
+{
+ SfxMacroMode eMode; /* Zweck der <SfxMacro>-Instanz,
+ Bedeutung siehe enum <SfxMacroMode> */
+ SfxStatements_Impl aList; /* Liste von aufgezeichneten Statements */
+};
+
+//====================================================================
+
+SfxMacroStatement::SfxMacroStatement
+(
+ const SfxShell& /*rShell*/, // <SfxShell>, die den Request ausf"uhrte
+ const String& /*rTarget*/, // Name des Zielobjektes vor der Ausf"urhung
+ BOOL /*bAbsolute*/, // obsolet
+ const SfxSlot& rSlot, // der <SfxSlot>, der das Statement abspielen kann
+ BOOL bRequestDone, // wurde der Request tats"achlich ausgef"uhrt
+ ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >& rArgs
+)
+
+/* [Beschreibung]
+
+ Dieser Konstruktor der Klasse SfxMacroStatement erzeugt ein Statement,
+ bei dem ein Objekt angesprochen wird, welches durch 'rShell' angegeben
+ ist. Dabei erfolgt die Addressierung je nach 'bAbsolute' absolut,
+ also z.B. als '[mydoc.sdc]' oder relativ, also z.B. 'ActiveDocument'.
+
+ Je nach Art der Subklasse von 'rShell' ergeben sich folgende
+ Ausdr"ucke:
+
+ | absolut relativ
+ -----------------------------------------------------------------------
+ SfxApplication' | 'StarCalc' 'Application'
+ SfxViewFrame' | '[mydoc.sdc:1]' 'ActiveWindow'
+ SfxViewShell' | '[mydoc.sdc:1]' 'AvtiveWindow'
+ SfxObjectShell' | '[mydoc.sdc]' 'ActiveDocument'
+ sonstige (Sub-Shells) | '[mydoc.sdc:1]' 'ActiveWindow'
+
+ Dabei sind 'StarCalc' stellvertretend fuer den Namen der Applikation
+ (Application::GetAppName()const). In der absoluten Fassung k"onnte
+ die Selektion auch deskriptiv z.B. als 'CellSelection("A5-D8")')
+ angesprochen werden, dazu mu\ jedoch vom Anwendungsprogrammierer der
+ Konstruktor <SfxMacroStatement::SfxMacroStatement(const String&,
+ const SfxSlot&,BOOL,SfxArguments*)> verwendet werden.
+
+ F"ur das so bezeichnete Objekt wird dann je nach Typ des Slots
+ eine Zuweisung an eines seiner Properties oder der Aufruf einer seiner
+ Methoden ausgedr"uckt.
+
+
+ [Beispiele]
+
+ absolut:
+ SCalc3.OpenDocument( "\docs\mydoc.sdd", "StarDraw Presentation", 0, 0 )
+ [mydoc.sdd].Activate()
+ [mydoc.sdd:1].SwitchToView( 2 )
+ [mydoc.sdc:1:1].CellSelection( "A5-D8" ).LineColor = 192357
+
+ relativ:
+ ActiveWindow.LineColor = 192357
+
+
+ [Querverweise]
+
+ <SfxMacroStatement::SfxMacroStatement(const String&,const SfxSlot&,BOOL,SfxArguments*)>
+ <SfxMacroStatement::SfxMacroStatement(const String&)>
+*/
+
+: nSlotId( rSlot.GetSlotId() ),
+ aArgs( rArgs ),
+ bDone( bRequestDone ),
+ pDummy( 0 )
+{
+ // Workaround Recording nicht exportierter Slots (#25386#)
+ if ( !rSlot.pName )
+ return;
+/*
+ // Objekt-Typ bestimmen
+ FASTBOOL bIsApp = rShell.ISA(SfxApplication);
+ FASTBOOL bIsDoc = rShell.ISA(SfxObjectShell);
+ FASTBOOL bIsWin = !bIsApp && !bIsDoc &&
+ ( rShell.ISA(SfxViewShell) || rShell.ISA(SfxViewFrame) );
+ FASTBOOL bIsSel = !bIsApp && !bIsDoc && !bIsWin;
+
+ // Objekt nicht schon im Slot-Namen enthalten?
+ if ( bIsSel || rSlot.pName[0] == '.' )
+ {
+ // absolutes Aufzeichnen?
+ if ( rSlot.IsMode( SFX_SLOT_RECORDABSOLUTE ) )
+ {
+ // an der Applikation oder am Modul
+ if ( rShell.ISA(SfxApplication) || rShell.ISA(SfxModule) )
+ aStatement = rTarget;
+
+ // am Dokument?
+ // '[' = 5Bh
+ // ']' = 5Dh
+ else if ( rShell.ISA(SfxObjectShell) )
+ {
+ aStatement = 0x005B;
+ aStatement += rTarget;
+ aStatement += 0x005D;
+ }
+
+ else if ( rShell.ISA(SfxViewFrame) )
+ {
+ aStatement = 0x005B;
+ aStatement += String::CreateFromAscii("ViewFrame");//rShell.GetSbxObject()->GetName();
+ aStatement += 0x005D;
+ }
+
+ else
+ {
+ // an der View oder Sub-Shell
+ SfxViewShell *pViewShell = rShell.GetViewShell();
+ aStatement = 0x005B;
+ aStatement += String::CreateFromAscii("ViewShell");//pViewShell->GetViewFrame()->GetSbxObject()->GetName();
+ aStatement += 0x005D;
+ if ( !rShell.ISA(SfxViewFrame) )
+ // an einer Sub-Shell zus"atlich ".Selection" anh"angen
+ aStatement += DEFINE_CONST_UNICODE(".Selection");
+ }
+ }
+ else // relatives Aufzeichnen
+ {
+ // an der Application?
+ if ( rShell.ISA(SfxApplication) )
+ aStatement = DEFINE_CONST_UNICODE("Application");
+
+ // am Modul?
+ else if ( rShell.ISA(SfxModule) )
+ aStatement = DEFINE_CONST_UNICODE("ActiveModule");
+
+ // am Dokument
+ else if ( rShell.ISA(SfxObjectShell) )
+ aStatement = DEFINE_CONST_UNICODE("ActiveDocument");
+
+ // am Window
+ else if ( rShell.ISA(SfxViewShell) || rShell.ISA(SfxViewFrame) )
+ aStatement = DEFINE_CONST_UNICODE("ActiveWindow");
+
+ else
+ // an einer Sub-Shell
+ aStatement = DEFINE_CONST_UNICODE("Selection");
+ }
+ }
+
+ if ( bIsSel )
+ {
+ // bei Selection ggf. noch den Namen der SubShell anh"angen
+ const SfxShellObject *pShObj =
+ (const SfxShellObject*) rShell.GetSbxObject();
+ if ( pShObj )
+ {
+ const SfxShellObject *pParentObj =
+ (const SfxShellObject*) pShObj->GetParent();
+ SfxShell *pParentSh = pParentObj->GetShell();
+ DBG_ASSERT( pParentSh->ISA(SfxViewFrame),
+ "parent of SubShell must be a Frame" );
+ if ( rSlot.pName[0] == '.' )
+ {
+ aStatement += '.';
+ aStatement += rShell.GetSbxObject()->GetName();
+ }
+ }
+ else
+ DBG_ASSERT( rSlot.pName[0] != '0', "recording unnamed object" );
+ }
+*/
+ aStatement = DEFINE_CONST_UNICODE("Selection");
+
+ // an diesen Objekt-Ausdruck den Methoden-/Property-Namen und Parameter
+ GenerateNameAndArgs_Impl( SfxRequest::GetRecordingMacro(), rSlot, bRequestDone, aArgs);
+}
+
+//--------------------------------------------------------------------
+
+SfxMacroStatement::SfxMacroStatement
+(
+ const String& rTarget, // Objekt, was beim Playing angesprochen wird
+ const SfxSlot& rSlot, // der <SfxSlot>, der das Statement abspielen kann
+ BOOL bRequestDone, // wurde der Request tats"achlich ausgef"uhrt
+ ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >& rArgs
+)
+
+/* [Beschreibung]
+
+
+ [Querverweise]
+
+ <SfxMacroStatement::SfxMacroStatement(const String&)>
+ <SfxMacroStatement::SfxMacroStatement(const SfxShell&,BOOL,const SfxSlot&,BOOL,SfxArguments*)>
+*/
+
+: nSlotId( rSlot.GetSlotId() ),
+ aArgs( rArgs ),
+ bDone( bRequestDone ),
+ pDummy( 0 )
+{
+ aStatement = rTarget;
+ aStatement += '.';
+ GenerateNameAndArgs_Impl( SfxRequest::GetRecordingMacro(), rSlot, bRequestDone, aArgs);
+}
+
+//--------------------------------------------------------------------
+
+SfxMacroStatement::SfxMacroStatement
+(
+ const String& rStatement // manuell erzeugte(s) Statement(s)
+)
+
+/* [Beschreibung]
+
+ Dieser Konstruktor erzeugt eine SfxMacroStatement-Instanz, deren
+ Aufbau vollst"andig vom Applikationsentwickler bestimmt wird. Da der
+ angegebene String auch mehrere mit CR/LF getrennte Statements
+ enthalten darf, ist damit ein weitgehender Eingriff in das Aufzeichnen
+ von BASIC-Makros m"oglich, um Spezialf"alle zu behandeln.
+
+
+ [Querverweise]
+
+ <SfxMacroStatement::SfxMacroStatement(const String&,const SfxSlot&,BOOL,SfxArguments*)>
+ <SfxMacroStatement::SfxMacroStatement(const SfxShell&,BOOL,const SfxSlot&,BOOL,SfxArguments*)>
+*/
+
+: nSlotId( 0 ),
+ aStatement( rStatement ),
+ bDone( TRUE ),
+ pDummy( 0 )
+{
+}
+
+//--------------------------------------------------------------------
+
+SfxMacroStatement::SfxMacroStatement
+(
+ const SfxMacroStatement& rOrig // Original, von dem kopiert wird
+)
+
+/* [Beschreibung]
+
+ Copy-Konstruktor der SfxMacroStatement-Klasse.
+*/
+
+: nSlotId( rOrig.nSlotId ),
+ aStatement( rOrig.aStatement ),
+ bDone( rOrig.bDone ),
+ pDummy( 0 )
+{
+ aArgs = rOrig.aArgs;
+}
+
+//--------------------------------------------------------------------
+
+SfxMacroStatement::~SfxMacroStatement()
+
+/* [Beschreibung]
+
+ Destruktor der Klasse SfxMacroStatement. Gibt die Liste der
+ aktuellen Parameter frei.
+*/
+
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxMacroStatement::GenerateNameAndArgs_Impl
+(
+ SfxMacro* /*pMacro*/, // darin wird aufgezeichnet
+ const SfxSlot& rSlot, // der Slot, der das Statement abspielen kann
+ BOOL bRequestDone, // TRUE=wurde ausgef"uhrt, FALSE=abgebrochen
+ ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >& /*rArgs*/
+)
+
+/* [Beschreibung]
+
+ Interne Hilfsmethode zum generieren des Funktions-/Property-Names
+ sowie der Parameter. Diese Methode wird nur verwendet, wenn der
+ Anwendungsprogrammierer keinen eigenen Source an den <SfxRequest>
+ geh"angt hat.
+*/
+
+{
+ if ( aStatement.Len() && aStatement.GetChar( aStatement.Len() - 1 ) != '.'
+ && rSlot.pName[0] != '.' )
+ aStatement += '.';
+
+ // der Name des Slots ist der Name der Methode / des Properties
+ aStatement += String::CreateFromAscii(rSlot.pName);
+ if ( rSlot.IsMode(SFX_SLOT_METHOD) )
+ aStatement += DEFINE_CONST_UNICODE("( ");
+ else
+ aStatement += DEFINE_CONST_UNICODE(" = ");
+
+ // alle zusammengesuchten Parameter rausschreiben
+ if ( aArgs.getLength() )
+ for ( USHORT nArg = 0; nArg < aArgs.getLength(); ++nArg )
+ {
+ // den Parameter textuell darstellen
+ String aArg;
+ ::com::sun::star::uno::Any& rValue = aArgs[nArg].Value;
+ ::com::sun::star::uno::Type pType = rValue.getValueType();
+ if ( pType == ::getBooleanCppuType() )
+ {
+ sal_Bool bTemp = false;
+ rValue >>= bTemp;
+ aArg = bTemp ? DEFINE_CONST_UNICODE("TRUE") : DEFINE_CONST_UNICODE("FALSE");
+ }
+ else if ( pType == ::getCppuType((const sal_Int16*)0) )
+ {
+ sal_uInt16 nTemp = 0;
+ rValue >>= nTemp;
+ aArg = String::CreateFromInt32( (sal_Int32) nTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_Int32*)0) )
+ {
+ sal_uInt32 nTemp = 0;
+ rValue >>= nTemp;
+ aArg = String::CreateFromInt32( nTemp );
+ }
+ else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
+ {
+ ::rtl::OUString sTemp;
+ rValue >>= sTemp;
+
+ // Anf"uhrungszeichen werden verdoppelt
+ XubString aRecordable( sTemp );
+ USHORT nPos = 0;
+ while ( TRUE )
+ {
+ nPos = aRecordable.SearchAndReplace( DEFINE_CONST_UNICODE('"'), DEFINE_CONST_UNICODE("\"\""), nPos );
+ if ( STRING_NOTFOUND == nPos )
+ break;
+ nPos += 2;
+ }
+
+ // nicht druckbare Zeichen werden als chr$(...) geschrieben
+ FASTBOOL bPrevReplaced = FALSE;
+ for ( USHORT n = 0; n < aRecordable.Len(); ++n )
+ {
+ sal_Unicode cChar = aRecordable.GetChar(n);
+ if ( !( cChar>=32 && cChar!=127 ) ) // ALS ERSATZ FUER String::IsPrintable()!
+ {
+ XubString aReplacement( DEFINE_CONST_UNICODE("+chr$(") );
+ aReplacement += cChar;
+
+ if ( bPrevReplaced )
+ {
+ aRecordable.Insert( aReplacement, n - 2 );
+ n = n + aReplacement.Len();
+ aRecordable.SetChar((unsigned short) (n-2), 0x0029);// ')' = 29h
+ aRecordable.Replace( n-1, 2, DEFINE_CONST_UNICODE("+\"") );
+ // ++n;
+ }
+ else
+ {
+ aReplacement += DEFINE_CONST_UNICODE(")+\"");
+ aRecordable.SetChar(n, 0x0022 );// '"' = 22h
+ aRecordable.Insert( aReplacement, n + 1 );
+ n = n + aReplacement.Len();
+ }
+ bPrevReplaced = TRUE;
+ }
+ else
+ bPrevReplaced = FALSE;
+
+ // Argument in Anf"uhrungszeichen
+ aArg = '"';
+ aArg += aRecordable;
+ aArg += '"';
+ }
+/*
+ case SbxBYTE:
+ {
+ // als Zahl darstellen
+ aArg = (USHORT) rVar.GetByte();
+ break;
+ }
+*/
+ }
+ else
+ {
+ OSL_ENSURE(
+ pType == ::getVoidCppuType(), "Unknown Type in recorder!" );
+ }
+
+ // den Parameter anh"angen
+ aStatement += aArg;
+ aStatement += DEFINE_CONST_UNICODE(", ");
+ }
+
+ // Statement beeden
+ if ( aArgs.getLength() )
+ aStatement.Erase( aStatement.Len() - 2, 1 );
+ else
+ aStatement.Erase( aStatement.Len() - 1, 1 );
+ if ( rSlot.IsMode(SFX_SLOT_METHOD) )
+ aStatement += ')';
+
+ if ( !bRequestDone )
+ // nicht als "Done()" gekennzeichnete Statements auskommentieren
+ aStatement.InsertAscii( "rem ", 0 );
+}
+
+//--------------------------------------------------------------------
+
+SfxMacro::SfxMacro
+(
+ SfxMacroMode eMode // Zweck der Instanz, siehe <SfxMacroMode>
+)
+
+/* [Beschreibung]
+
+ Konstruktor der Klasse SfxMacro. Instanzen dieser Klasse werden im
+ SFx zu zwei Zwecken ben"otigt:
+
+ 1. zum Aufzeichnen von Makros
+ In diesem Fall wird der Konstruktor mit SFX_MACRO_RECORDINGABSOLUTE
+ oder SFX_MACRO_RECORDINGRELATIVE aufgerufen. Es sollte sich um eine
+ Instanz einer abgeleiteten Klasse handeln, um in der Ableitung
+ die Information dar"uber unterzubringen, wo das Makro gespeichert
+ werden soll. Ein solches Makro solle sich dann in seinem Destruktor
+ an der vom Benutzer gew"ahlten Stelle speichern.
+
+ 2. zum Zuordnen von exisitierenden Makros
+ In diesem Fall wird der Konstruktor mit SFX_MACRO_EXISTING aufgerufen.
+ Eine solche Instanz wird z.B. ben"otigt, wenn Makros auf Events
+ oder <SfxControllerItem>s konfiguriert werden sollen.
+*/
+
+: pImp( new SfxMacro_Impl )
+
+{
+ pImp->eMode = eMode;
+}
+
+//--------------------------------------------------------------------
+
+SfxMacro::~SfxMacro()
+
+/* [Beschreibung]
+
+ Virtueller Destruktor der Klasse SfxMacro. Dieser sollte in den
+ abgeleiteten Klassen "uberladen werden, um in den Modi
+ SFX_MACRO_RECORDINGABSOLUTE und SFX_MACRO_RECORDINGRELATIVE den
+ aufgezeichneten Source abzuspeichern.
+
+
+ [Querverweise]
+
+ <SfxMacro::GenerateSource()const>
+*/
+
+{
+#if OSL_DEBUG_LEVEL > 1
+ SvFileStream aStream( String::CreateFromAscii("file:///f:/testmacro.bas" ), STREAM_STD_READWRITE | STREAM_TRUNC );
+ aStream << ByteString( GenerateSource(), RTL_TEXTENCODING_UTF8 ).GetBuffer();
+#endif
+ delete pImp;
+}
+
+//--------------------------------------------------------------------
+
+SfxMacroMode SfxMacro::GetMode() const
+
+/* [Beschreibung]
+
+ Liefert den Modus, der besagt zu welchem Zweck das SfxMacro konstruiert
+ wurde.
+
+
+ [Querverweise]
+
+ enum <SfxMacroMode>
+*/
+
+{
+ return pImp->eMode;
+}
+
+//--------------------------------------------------------------------
+
+void SfxMacro::Record
+(
+ SfxMacroStatement* pStatement // aufzuzeichnendes <SfxMacroStatement>
+)
+
+/* [Beschreibung]
+
+ Diese Methode zeichnet das als Parameter "ubergeben Statement auf.
+ Die Instanz auf die der "ubergebe Pointer zeigt, geht in das Eigentum
+ des SfxMacro "uber.
+
+ Der Aufruf ist nur g"ultig, wenn es sich um ein SfxMacro handelt,
+ welches mit SFX_MACRO_RECORDINGABSOLUTE oder SFX_MACRO_RECORDINGRELATIVE
+ konstruiert wirde.
+
+
+ [Querverweise]
+
+ <SfxMacro::Replace(SfxMacroStatement*)>
+ <SfxMacro::Remove()>
+ <SfxMacro::GetLastStatement()const>
+*/
+
+{
+ DBG_ASSERT( pImp->eMode != SFX_MACRO_EXISTING, "invalid call to non-recording SfxMacro" );
+ pImp->aList.C40_INSERT( SfxMacroStatement, pStatement, pImp->aList.Count() );
+}
+
+//--------------------------------------------------------------------
+
+void SfxMacro::Replace
+(
+ SfxMacroStatement* pStatement // aufzuzeichnendes <SfxMacroStatement>
+)
+
+/* [Beschreibung]
+
+ Diese Methode zeichnet das als Parameter "ubergeben Statement auf.
+ Dabei wird das jeweils zuletzt aufgezeichnete Statement "uberschrieben.
+ Die Instanz auf die der "ubergebe Pointer zeigt, geht in das Eigentum
+ des SfxMacro "uber.
+
+ Mit dieser Methode ist es m"oglich, Statements zusammenzufassen. Z.B.
+ anstelle f"unfmal hintereinander 'CursorLeft()' aufzurufen, k"onnte
+ das zu 'CursorLeft(5)' zusammengefa\st werden. Oder anstelle ein Wort
+ Buchstabe f"ur Buchstabe aufzubauen, k"onnte dies durch ein einziges
+ Statement 'InsertString("Hallo")' ersetzt werden.
+
+ Der Aufruf ist nur g"ultig, wenn es sich um ein SfxMacro handelt,
+ welches mit SFX_MACRO_RECORDINGABSOLUTE oder SFX_MACRO_RECORDINGRELATIVE
+ konstruiert wurde und bereits ein aufgezeichnetes Statement vorhanden
+ ist.
+
+
+ [Anmerkung]
+
+ Diese Methode wird typischerweise aus den Execute-Methoden der
+ <SfxSlot>s von den Applikationsentwicklern gerufen.
+
+
+ [Querverweise]
+
+ <SfxMacro::Record(SfxMacroStatement*)>
+ <SfxMacro::Remove()>
+ <SfxMacro::GetLastStatement()const>
+*/
+
+{
+ DBG_ASSERT( pImp->eMode != SFX_MACRO_EXISTING, "invalid call to non-recording SfxMacro" );
+ DBG_ASSERT( pImp->aList.Count(), "no replaceable statement available" );
+ pImp->aList.Remove( pImp->aList.Count() - 1 );
+ pImp->aList.C40_INSERT( SfxMacroStatement,pStatement, pImp->aList.Count() );
+}
+
+//--------------------------------------------------------------------
+
+void SfxMacro::Remove()
+
+/* [Beschreibung]
+
+ Diese Methode l"oscht das zuletzt aufgezeichnete <SfxMacroStatement>
+ und entfernt es aus dem Macro.
+
+ Mit dieser Methode ist es m"oglich, Statements zusammenzufassen. Z.B.
+ anstelle f"unfmal hintereinander 'CursorLeft()' aufzurufen, k"onnte
+ das zu 'CursorLeft(5)' zusammengefa\st werden. Oder anstelle ein Wort
+ Buchstabe f"ur Buchstabe aufzubauen, k"onnte dies durch ein einziges
+ Statement 'InsertString("Hallo")' ersetzt werden.
+
+ Der Aufruf ist nur g"ultig, wenn es sich um ein SfxMacro handelt,
+ welches mit SFX_MACRO_RECORDINGABSOLUTE oder SFX_MACRO_RECORDINGRELATIVE
+ konstruiert wurde und bereits ein aufgezeichnetes Statement vorhanden
+ ist.
+
+
+ [Anmerkung]
+
+ Diese Methode wird typischerweise aus den Execute-Methoden der
+ <SfxSlot>s von den Applikationsentwicklern gerufen.
+
+
+ [Querverweise]
+
+ <SfxMacro::Replace(SfxMacroStatement*)>
+ <SfxMacro::Record(SfxMacroStatement*)>
+ <SfxMacro::GetLastStatement()const>
+*/
+
+{
+ DBG_ASSERT( pImp->eMode != SFX_MACRO_EXISTING, "invalid call to non-recording SfxMacro" );
+ DBG_ASSERT( pImp->aList.Count(), "no replaceable statement available" );
+ pImp->aList.Remove( pImp->aList.Count() - 1 );
+}
+
+//--------------------------------------------------------------------
+
+const SfxMacroStatement* SfxMacro::GetLastStatement() const
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann auf das jeweils zuletzt aufgezeichnete Statement
+ lesend zugegriffen werden. Zusammen mit der Methode
+ <SfxMacro::Replace(SfxMacroStatement*)> ergibt sich dadurch die
+ M"oglichkeit, Statements zusammenzufassen.
+
+ Der Aufruf ist nur g"ultig, wenn es sich um ein SfxMacro handelt,
+ welches mit SFX_MACRO_RECORDINGABSOLUTE oder SFX_MACRO_RECORDINGRELATIVE
+ konstruiert wurde.
+
+
+ [Querverweise]
+
+ <SfxMacro::Record(SfxMacroStatement*)>
+ <SfxMacro::Replace(SfxMacroStatement*)>
+*/
+
+{
+ DBG_ASSERT( pImp->eMode != SFX_MACRO_EXISTING, "invalid call to non-recording SfxMacro" );
+ if ( pImp->aList.Count() )
+ return pImp->aList.GetObject( pImp->aList.Count() - 1 );
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+String SfxMacro::GenerateSource() const
+
+/* [Beschreibung]
+
+ Diese Funktion generiert aus den, seit dem Konstruieren der Instanz
+ bis zum Zeitpunkt des Aufrufs dieser Methode aufgezeichneten
+ <SfxMacroStatement>s einen BASIC-Sourcecode, der die Statements,
+ jedoch nicht den Header ('Sub X') und den Footer ('End Sub') enth"alt.
+
+
+ [Querverweise]
+
+ <SfxMacro::Record(SfxMacroStatement*)>
+ <SfxMacro::Repeat(SfxMacroStatement*)>
+*/
+
+{
+ DBG_ASSERT( pImp->eMode != SFX_MACRO_EXISTING, "invalid call to non-recording SfxMacro" );
+ String aSource;
+ for ( USHORT n = 0; n < pImp->aList.Count(); ++n )
+ {
+ aSource += pImp->aList.GetObject(n)->GetStatement();
+ if ( (n+1) < pImp->aList.Count() )
+ aSource += DEFINE_CONST_UNICODE("\n");
+ }
+
+ return aSource;
+}
+
diff --git a/sfx2/source/control/minfitem.cxx b/sfx2/source/control/minfitem.cxx
new file mode 100644
index 000000000000..b0cdd58d2645
--- /dev/null
+++ b/sfx2/source/control/minfitem.cxx
@@ -0,0 +1,104 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// INCLUDE ---------------------------------------------------------------
+
+#include "sfx2/minfitem.hxx"
+
+// STATIC DATA -----------------------------------------------------------
+
+TYPEINIT1(SfxMacroInfoItem, SfxPoolItem);
+
+// -----------------------------------------------------------------------
+
+SfxMacroInfoItem::SfxMacroInfoItem(
+ USHORT nWhichId, // Slot-ID
+ const BasicManager* pMgr,
+ const String &rLibName,
+ const String &rModuleName,
+ const String &rMethodName,
+ const String &rComment) :
+ SfxPoolItem(nWhichId),
+ pBasicManager(pMgr),
+ aLibName(rLibName),
+ aModuleName(rModuleName),
+ aMethodName(rMethodName),
+ aCommentText(rComment)
+{
+}
+
+// -----------------------------------------------------------------------
+
+// copy ctor
+
+SfxMacroInfoItem::SfxMacroInfoItem(const SfxMacroInfoItem& rCopy):
+ SfxPoolItem(rCopy),
+ pBasicManager(rCopy.pBasicManager),
+ aLibName(rCopy.aLibName),
+ aModuleName(rCopy.aModuleName),
+ aMethodName(rCopy.aMethodName),
+ aCommentText(rCopy.aCommentText)
+{
+}
+
+// -----------------------------------------------------------------------
+
+// op ==
+
+int SfxMacroInfoItem::operator==( const SfxPoolItem& rCmp) const
+{
+ return SfxPoolItem::operator==(rCmp) &&
+ pBasicManager == ((const SfxMacroInfoItem&)rCmp).pBasicManager &&
+ aLibName == ((const SfxMacroInfoItem&)rCmp).aLibName &&
+ aModuleName == ((const SfxMacroInfoItem&)rCmp).aModuleName &&
+ aMethodName == ((const SfxMacroInfoItem&)rCmp).aMethodName &&
+ aCommentText == ((const SfxMacroInfoItem&)rCmp).aCommentText;
+}
+
+// -----------------------------------------------------------------------
+
+SfxPoolItem *SfxMacroInfoItem::Clone( SfxItemPool *) const
+{
+ return new SfxMacroInfoItem(*this);
+}
+
+// -----------------------------------------------------------------------
+
+String SfxMacroInfoItem::GetQualifiedName() const
+{
+ String aMacroName = aLibName;
+ aMacroName += '.';
+ aMacroName += aModuleName;
+ aMacroName += '.';
+ aMacroName += aMethodName;
+ return aMacroName;
+}
+
+
diff --git a/sfx2/source/control/msg.cxx b/sfx2/source/control/msg.cxx
new file mode 100644
index 000000000000..6b05c03160ff
--- /dev/null
+++ b/sfx2/source/control/msg.cxx
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <svl/itempool.hxx>
+#include <svl/eitem.hxx>
+#include <sfx2/msg.hxx>
+
+//====================================================================
+
+SfxSlotKind SfxSlot::GetKind() const
+{
+ if( !nMasterSlotId && !nValue)
+ return (SfxSlotKind) SFX_KIND_STANDARD;
+ if ( nMasterSlotId && fnExec==0 && fnState==0 )
+ {
+ if ( pType->Type() == TYPE(SfxBoolItem) )
+ return (SfxSlotKind) SFX_KIND_ENUM;
+ else
+ {
+ DBG_ERROR( "invalid slot kind detected" );
+ return SFX_KIND_ENUM;
+ }
+ }
+ else
+ return (SfxSlotKind) SFX_KIND_ATTR;
+}
+
+//--------------------------------------------------------------------
+
+USHORT SfxSlot::GetWhich( const SfxItemPool &rPool ) const
+{
+ if ( !nMasterSlotId || nMasterSlotId == USHRT_MAX )
+ ((SfxSlot*) this) -> nMasterSlotId = rPool.GetWhich(nSlotId);
+ return nMasterSlotId;
+}
+
+::rtl::OString SfxSlot::GetCommand() const
+{
+ rtl::OString sRet(".uno:");
+ sRet += pUnoName;
+ return sRet;
+}
+
+::rtl::OUString SfxSlot::GetCommandString() const
+{
+ rtl::OString aCmd(GetCommand());
+ return rtl::OUString( aCmd, aCmd.getLength(), RTL_TEXTENCODING_UTF8 );
+}
+
diff --git a/sfx2/source/control/msgpool.cxx b/sfx2/source/control/msgpool.cxx
new file mode 100644
index 000000000000..10359ba20f73
--- /dev/null
+++ b/sfx2/source/control/msgpool.cxx
@@ -0,0 +1,422 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <tools/stream.hxx>
+#include <rsc/rscsfx.hxx>
+#ifndef GCC
+#endif
+
+// wg. pSlotPool
+#include "appdata.hxx"
+#include <sfx2/msgpool.hxx>
+#include <sfx2/minarray.hxx>
+#include <sfx2/msg.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/objface.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/macrconf.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "arrdecl.hxx"
+#include <sfx2/module.hxx>
+
+#include <sfx2/sfx.hrc>
+
+//====================================================================
+
+struct SfxSIDRegistration_Impl
+{
+ String _aGroup;
+ String _aName;
+ USHORT _nSID;
+};
+
+struct SfxSlotType_Impl
+{
+ USHORT nId;
+ TypeId nType;
+
+ SfxSlotType_Impl( USHORT nTheId, TypeId nTheType ):
+ nId(nTheId), nType(nTheType)
+ {}
+};
+
+DECL_2BYTEARRAY(SfxSlotGroupArr_Impl, USHORT, 6, 4)
+DECL_PTRARRAY(SfxInterfaceArr_Impl, SfxInterface*, 6, 3)
+DECL_PTRARRAY(SfxSlotTypeArr_Impl, SfxSlotType_Impl*, 8, 8)
+
+
+//====================================================================
+
+SfxSlotPool::SfxSlotPool( SfxSlotPool *pParent, ResMgr* pResManager )
+ : _pGroups(0)
+ , _pTypes(0)
+ , _pParentPool( pParent )
+ , _pResMgr( pResManager )
+ , _pInterfaces(0)
+ , _nCurGroup(0)
+ , _nCurInterface(0)
+ , _nCurMsg(0)
+ , _pUnoSlots( 0 )
+{
+ if ( !_pResMgr )
+ _pResMgr = SfxApplication::GetOrCreate()->GetOffResManager_Impl();
+}
+
+//====================================================================
+
+SfxSlotPool::~SfxSlotPool()
+{
+ _pParentPool = 0;
+ for ( SfxInterface *pIF = FirstInterface(); pIF; pIF = FirstInterface() )
+ delete pIF;
+ delete _pInterfaces;
+ delete _pGroups;
+ if ( _pTypes )
+ {
+ for ( USHORT n =_pTypes->Count(); n--; )
+ delete _pTypes->GetObject(n);
+ delete _pTypes;
+ }
+}
+
+//====================================================================
+
+// registers the availability of the Interface of functions
+
+void SfxSlotPool::RegisterInterface( SfxInterface& rInterface )
+{
+ DBG_MEMTEST();
+
+ // add to the list of SfxObjectInterface instances
+ if ( _pInterfaces == 0 )
+ _pInterfaces = new SfxInterfaceArr_Impl;
+ _pInterfaces->Append(&rInterface);
+
+ // bei einem (einzelnen) Null-Slot abbrechen (aus syntaktischen Gr"unden
+ // enthalten interfaces immer mindestens einen Slot)
+ if ( rInterface.Count() == 1 && !rInterface[0]->nSlotId )
+ return;
+
+ // possibly add Interface-id and group-ids of funcs to the list of groups
+ if ( !_pGroups )
+ {
+ _pGroups = new SfxSlotGroupArr_Impl;
+
+ if ( _pParentPool )
+ {
+ // Die Groups im parent Slotpool sind auch hier bekannt
+ SfxSlotGroupArr_Impl& rGroups = *_pParentPool->_pGroups;
+ for ( USHORT n=0; n<rGroups.Count(); n++ )
+ _pGroups->Append( rGroups[n] );
+ }
+ }
+
+ if ( !_pTypes )
+ _pTypes = new SfxSlotTypeArr_Impl;
+ for ( USHORT nFunc = 0; nFunc < rInterface.Count(); ++nFunc )
+ {
+ SfxSlot *pDef = rInterface[nFunc];
+ if ( pDef->GetGroupId() && /* pDef->GetGroupId() != GID_INTERN && */
+ !_pGroups->Contains(pDef->GetGroupId()) )
+ {
+ if (pDef->GetGroupId() == GID_INTERN)
+ _pGroups->Insert(0, pDef->GetGroupId());
+ else
+ _pGroups->Append(pDef->GetGroupId());
+ }
+#if 0
+ const TypeId &rTypeId = pDef->GetType()->Type();
+ if ( /*rTypeId != TYPE(SfxVoidItem) &&*/ rTypeId != 0 )
+ {
+ USHORT nPos;
+ for ( nPos = 0; nPos < _pTypes->Count(); ++nPos )
+ {
+ if ( _pTypes->GetObject(nPos)->nId == pDef->GetSlotId() )
+ {
+ DBG_ASSERT( rTypeId == _pTypes->GetObject(nPos)->nType,
+ "same slot id with unequal item types" );
+ }
+ else if ( _pTypes->GetObject(nPos)->nId > pDef->GetSlotId() )
+ break;
+ }
+ if ( nPos >= _pTypes->Count() ||
+ _pTypes->GetObject(nPos)->nId > pDef->GetSlotId() )
+ _pTypes->Append( new SfxSlotType_Impl( pDef->GetSlotId(), rTypeId ) );
+ }
+#endif
+ }
+}
+
+//====================================================================
+
+TypeId SfxSlotPool::GetSlotType( USHORT nId ) const
+{
+ const SfxSlot* pSlot = (const_cast <SfxSlotPool*> (this))->GetSlot( nId );
+ return pSlot ? pSlot->GetType()->Type() : 0;
+/*
+ for ( USHORT nPos = 0; nPos < _pTypes->Count(); ++nPos )
+ {
+ if ( _pTypes->GetObject(nPos)->nId == nId )
+ return _pTypes->GetObject(nPos)->nType;
+ }
+ return _pParentPool ? _pParentPool->GetSlotType( nId ) : 0;
+ */
+}
+
+//====================================================================
+
+// unregisters the availability of the Interface of functions
+
+void SfxSlotPool::ReleaseInterface( SfxInterface& rInterface )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( _pInterfaces, "releasing SfxInterface, but there are none" );
+ // remove from the list of SfxInterface instances
+ _pInterfaces->Remove(&rInterface);
+}
+
+//--------------------------------------------------------------------
+
+// get the first SfxMessage for a special Id (e.g. for getting check-mode)
+
+const SfxSlot* SfxSlotPool::GetSlot( USHORT nId )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( _pInterfaces != 0, "no Interfaces registered" );
+
+ // Zun"achst die eigenen Interfaces absuchen
+ for ( USHORT nInterf = 0; nInterf < _pInterfaces->Count(); ++nInterf )
+ {
+ const SfxSlot *pDef = _pInterfaces->GetObject(nInterf)->GetSlot(nId);
+ if ( pDef )
+ return pDef;
+ }
+
+ // Dann beim eventuell vorhandenen parent versuchen
+ return _pParentPool ? _pParentPool->GetSlot( nId ) : 0;
+}
+
+//--------------------------------------------------------------------
+
+// skips to the next group
+
+String SfxSlotPool::SeekGroup( USHORT nNo )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( _pInterfaces != 0, "no Interfaces registered" );
+
+ // if the group exists, use it
+ if ( _pGroups && nNo < _pGroups->Count() )
+ {
+ _nCurGroup = nNo;
+ if ( _pParentPool )
+ {
+ // Meistens stimmt die Reihenfolge der Ids "uberein
+ USHORT nParentCount = _pParentPool->_pGroups->Count();
+ if ( nNo < nParentCount && (*_pGroups)[nNo] == (*_pParentPool->_pGroups)[nNo] )
+ _pParentPool->_nCurGroup = nNo;
+ else
+ {
+ // Ansonsten mu\s gesucht werden
+ // Wenn die Gruppe im parent pool nicht gefunden wird, wird
+ // _nCurGroup au\serhalb des g"ultigen Bereiches gesetzt
+ USHORT i;
+ for ( i=1; i<nParentCount; i++ )
+ if ( (*_pGroups)[nNo] == (*_pParentPool->_pGroups)[i] )
+ break;
+ _pParentPool->_nCurGroup = i;
+ }
+ }
+
+ SfxResId aResId( (*_pGroups)[_nCurGroup] );
+ aResId.SetRT(RSC_STRING);
+ if ( !aResId.GetResMgr()->IsAvailable(aResId) )
+ {
+ DBG_ERROR( "GroupId-Name nicht im SFX definiert!" );
+ return String();
+ }
+
+ return String( aResId );
+ }
+
+ return String();
+}
+
+
+//--------------------------------------------------------------------
+
+USHORT SfxSlotPool::GetGroupCount()
+{
+ return _pGroups->Count();
+}
+
+
+//--------------------------------------------------------------------
+
+// internal search loop
+
+const SfxSlot* SfxSlotPool::SeekSlot( USHORT nStartInterface )
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( _pInterfaces != 0, "no Interfaces registered" );
+
+ // Die Numerierung der interfaces startet beim parent pool
+ USHORT nFirstInterface = _pParentPool ? _pParentPool->_pInterfaces->Count() : 0;
+
+ // sind wir am Ende des Parent-Pools angekommen?
+ if ( nStartInterface < nFirstInterface &&
+ _pParentPool->_nCurGroup >= _pParentPool->_pGroups->Count() )
+ nStartInterface = nFirstInterface;
+
+ // liegt das Interface noch im Parent-Pool?
+ if ( nStartInterface < nFirstInterface )
+ {
+ DBG_ASSERT( _pParentPool, "Kein parent pool!" );
+ _nCurInterface = nStartInterface;
+ return _pParentPool->SeekSlot( nStartInterface );
+ }
+
+ // find the first func-def with the current group id
+ USHORT nCount = _pInterfaces->Count() + nFirstInterface;
+ for ( _nCurInterface = nStartInterface;
+ _nCurInterface < nCount;
+ ++_nCurInterface )
+ {
+ SfxInterface* pInterface = (*_pInterfaces)[_nCurInterface-nFirstInterface];
+ for ( _nCurMsg = 0;
+ _nCurMsg < pInterface->Count();
+ ++_nCurMsg )
+ {
+ const SfxSlot* pMsg = (*pInterface)[_nCurMsg];
+ if ( pMsg->GetGroupId() == _pGroups->GetObject(_nCurGroup) )
+ return pMsg;
+ }
+ }
+
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+// skips to the next func in the current group
+
+const SfxSlot* SfxSlotPool::NextSlot()
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( _pInterfaces != 0, "no Interfaces registered" );
+
+ // Die Numerierung der interfaces startet beim parent pool
+ USHORT nFirstInterface = _pParentPool ? _pParentPool->_pInterfaces->Count() : 0;
+
+ if ( _nCurInterface < nFirstInterface && _nCurGroup >= _pParentPool->_pGroups->Count() )
+ _nCurInterface = nFirstInterface;
+
+ if ( _nCurInterface < nFirstInterface )
+ {
+ DBG_ASSERT( _pParentPool, "Kein parent pool!" );
+ const SfxSlot *pSlot = _pParentPool->NextSlot();
+ _nCurInterface = _pParentPool->_nCurInterface;
+ if ( pSlot )
+ return pSlot;
+ if ( _nCurInterface == nFirstInterface )
+ // parent pool ist fertig
+ return SeekSlot( nFirstInterface );
+ }
+
+ USHORT nInterface = _nCurInterface - nFirstInterface;
+ // possibly we are already at the end
+ if ( nInterface >= _pInterfaces->Count() )
+ return 0;
+
+ // look for further matching func-defs within the same Interface
+ SfxInterface* pInterface = (*_pInterfaces)[nInterface];
+ while ( ++_nCurMsg < pInterface->Count() )
+ {
+ SfxSlot* pMsg = (*pInterface)[_nCurMsg];
+ if ( pMsg->GetGroupId() == _pGroups->GetObject(_nCurGroup) )
+ return pMsg;
+ }
+
+ return SeekSlot(++_nCurInterface );
+}
+
+
+//--------------------------------------------------------------------
+
+// SlotName erfragen, gfs. mit HilfeText
+
+//--------------------------------------------------------------------
+
+SfxInterface* SfxSlotPool::FirstInterface()
+{
+ _nCurInterface = 0;
+ if ( !_pInterfaces || !_pInterfaces->Count() )
+ return 0;
+ return _pParentPool ? _pParentPool->FirstInterface() : (*_pInterfaces)[0];
+}
+
+
+//--------------------------------------------------------------------
+
+SfxInterface* SfxSlotPool::NextInterface()
+{
+ _nCurInterface++;
+ USHORT nFirstInterface = _pParentPool ? _pParentPool->_pInterfaces->Count() : 0;
+ if ( _nCurInterface < nFirstInterface )
+ return (*_pParentPool->_pInterfaces)[_nCurInterface];
+ USHORT nInterface = _nCurInterface - nFirstInterface;
+ return nInterface < _pInterfaces->Count() ? (*_pInterfaces)[nInterface] : 0;
+}
+
+const SfxSlot* SfxSlotPool::GetUnoSlot( const String& rName )
+{
+ const SfxSlot *pSlot = NULL;
+ for ( USHORT nInterface=0; nInterface<_pInterfaces->Count(); nInterface++ )
+ {
+ pSlot = (*_pInterfaces)[nInterface]->GetSlot( rName );
+ if ( pSlot )
+ break;
+ }
+
+ if ( !pSlot && _pParentPool )
+ pSlot = _pParentPool->GetUnoSlot( rName );
+
+ return pSlot;
+}
+
+SfxSlotPool& SfxSlotPool::GetSlotPool( SfxViewFrame *pFrame )
+{
+ SfxModule *pMod = SfxModule::GetActiveModule( pFrame );
+ if ( pMod && pMod->GetSlotPool() )
+ return *pMod->GetSlotPool();
+ else
+ return *SFX_APP()->Get_Impl()->pSlotPool;
+}
+
+
diff --git a/sfx2/source/control/objface.cxx b/sfx2/source/control/objface.cxx
new file mode 100644
index 000000000000..d0ce2abae773
--- /dev/null
+++ b/sfx2/source/control/objface.cxx
@@ -0,0 +1,685 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <stdlib.h>
+#include <tools/rcid.h>
+#ifndef GCC
+#endif
+#include <tools/stream.hxx>
+
+#include <sfx2/module.hxx>
+#include <sfx2/objface.hxx>
+#include <sfx2/msg.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/msgpool.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/minarray.hxx>
+#include <sfx2/objsh.hxx>
+
+DBG_NAME(SfxInterface)
+
+//====================================================================
+
+EXTERN_C
+#if defined( PM2 ) && (!defined( CSET ) && !defined ( MTW ) && !defined( WTC ))
+int _stdcall
+#else
+#ifdef WNT
+int _cdecl
+#else
+int
+#endif
+#endif
+
+SfxCompareSlots_Impl( const void* pSmaller, const void* pBigger )
+{
+ DBG_MEMTEST();
+ return ( (int) ((SfxSlot*)pSmaller)->GetSlotId() ) -
+ ( (int) ((SfxSlot*)pBigger)->GetSlotId() );
+}
+
+//=========================================================================
+
+struct SfxObjectUI_Impl
+{
+ USHORT nPos;
+ ResId aResId;
+ BOOL bVisible;
+ BOOL bContext;
+ String* pName;
+ sal_uInt32 nFeature;
+
+ SfxObjectUI_Impl(USHORT n, const ResId& rResId, BOOL bVis, sal_uInt32 nFeat) :
+ nPos(n),
+ aResId(rResId.GetId(), *rResId.GetResMgr()),
+ bVisible(bVis),
+ bContext(FALSE),
+ pName(0),
+ nFeature(nFeat)
+ {
+ aResId.SetRT(rResId.GetRT());
+ }
+
+ ~SfxObjectUI_Impl()
+ {
+ delete pName;
+ }
+};
+
+DECL_PTRARRAY(SfxObjectUIArr_Impl, SfxObjectUI_Impl*, 2, 2)
+
+struct SfxInterface_Impl
+{
+ SfxObjectUIArr_Impl* pObjectBars; // registered ObjectBars
+ SfxObjectUIArr_Impl* pChildWindows; // registered ChildWindows
+ ResId aPopupRes; // registered PopupMenu
+ ResId aStatBarRes; // registered StatusBar
+ SfxModule* pModule;
+ BOOL bRegistered;
+
+ SfxInterface_Impl() :
+ aPopupRes(0,*SfxApplication::GetOrCreate()->GetSfxResManager()),
+ aStatBarRes(0,*SfxApplication::GetOrCreate()->GetSfxResManager())
+ , bRegistered(FALSE)
+ {
+ pObjectBars = new SfxObjectUIArr_Impl;
+ pChildWindows = new SfxObjectUIArr_Impl;
+ }
+
+ ~SfxInterface_Impl()
+ {
+ USHORT n;
+ for (n=0; n<pObjectBars->Count(); n++)
+ delete (*pObjectBars)[n];
+ delete pObjectBars;
+
+ for (n=0; n<pChildWindows->Count(); n++)
+ delete (*pChildWindows)[n];
+ delete pChildWindows;
+ }
+};
+
+static SfxObjectUI_Impl* CreateObjectBarUI_Impl( USHORT nPos, const ResId& rResId, sal_uInt32 nFeature, const String *pStr );
+
+//====================================================================
+
+//====================================================================
+// ctor, registeres a new unit
+
+SfxInterface::SfxInterface( const char *pClassName,
+ const ResId& rNameResId,
+ SfxInterfaceId nId,
+ const SfxInterface* pParent,
+ SfxSlot &rSlotMap, USHORT nSlotCount ):
+ pName(pClassName),
+ pGenoType(pParent),
+ nClassId(nId),
+ aNameResId(rNameResId.GetId(),*rNameResId.GetResMgr()),
+ pImpData(0)
+{
+ pImpData = new SfxInterface_Impl;
+ SetSlotMap( rSlotMap, nSlotCount );
+}
+
+void SfxInterface::Register( SfxModule* pMod )
+{
+ pImpData->bRegistered = TRUE;
+ pImpData->pModule = pMod;
+ if ( pMod )
+ pMod->GetSlotPool()->RegisterInterface(*this);
+ else
+ SFX_APP()->GetAppSlotPool_Impl().RegisterInterface(*this);
+}
+
+void SfxInterface::SetSlotMap( SfxSlot& rSlotMap, USHORT nSlotCount )
+{
+ pSlots = &rSlotMap;
+ nCount = nSlotCount;
+ SfxSlot* pIter = pSlots;
+ if ( 1 == nCount && !pIter->pNextSlot )
+ pIter->pNextSlot = pIter;
+
+ if ( !pIter->pNextSlot )
+ {
+ // sort the SfxSlots by id
+ qsort( pSlots, nCount, sizeof(SfxSlot), SfxCompareSlots_Impl );
+
+ // link masters and slaves
+ USHORT nIter = 1;
+ for ( pIter = pSlots; nIter <= nCount; ++pIter, ++nIter )
+ {
+ //! hier bitte sinnvoll pruefen
+ //! DBG_ASSERT(!(pIter->IsMode(SFX_SLOT_CACHABLE) &&
+ //! pIter->IsMode(SFX_SLOT_VOLATILE)),
+ //! "invalid Flags" );
+ DBG_ASSERT( nIter == nCount ||
+ pIter->GetSlotId() != (pIter+1)->GetSlotId(),
+ "doppelte SID" );
+
+ // jeder Master verweist auf seinen ersten Slave (ENUM), alle
+ // Slaves auf ihren Master.
+ // Slaves verweisen im Ring auf die anderen mit gleichem Master
+ if ( pIter->GetKind() == SFX_KIND_ENUM )
+ {
+ pIter->pLinkedSlot = GetSlot( pIter->nMasterSlotId );
+ DBG_ASSERT( pIter->pLinkedSlot, "slave without master" );
+ if ( !pIter->pLinkedSlot->pLinkedSlot )
+ ( (SfxSlot*) pIter->pLinkedSlot)->pLinkedSlot = pIter;
+
+ if ( 0 == pIter->GetNextSlot() )
+ {
+ SfxSlot *pLastSlot = pIter;
+ for ( USHORT n = nIter; n < Count(); ++n )
+ {
+ SfxSlot *pCurSlot = (pSlots+n);
+ if ( pCurSlot->nMasterSlotId == pIter->nMasterSlotId )
+ {
+ pLastSlot->pNextSlot = pCurSlot;
+ pLastSlot = pCurSlot;
+ }
+ }
+ pLastSlot->pNextSlot = pIter;
+ }
+ }
+ else if ( 0 == pIter->GetNextSlot() )
+ {
+ // Slots verweisen im Ring auf den n"achten mit derselben Statusmethode
+ SfxSlot *pLastSlot = pIter;
+ for ( USHORT n = nIter; n < Count(); ++n )
+ {
+ SfxSlot *pCurSlot = (pSlots+n);
+ if ( pCurSlot->GetStateFnc() == pIter->GetStateFnc() )
+ {
+ pLastSlot->pNextSlot = pCurSlot;
+ pLastSlot = pCurSlot;
+ }
+ }
+ pLastSlot->pNextSlot = pIter;
+ }
+ }
+ }
+#ifdef DBG_UTIL
+ else
+ {
+ USHORT nIter = 1;
+ for ( SfxSlot *pNext = pIter+1; nIter < nCount; ++pNext, ++nIter )
+ {
+
+ if ( pNext->GetSlotId() <= pIter->GetSlotId() )
+ DBG_ERROR ("Falsche Reihenfolge!");
+
+ if ( pIter->GetKind() == SFX_KIND_ENUM )
+ {
+ const SfxSlot *pMasterSlot = GetSlot(pIter->nMasterSlotId);
+ const SfxSlot *pFirstSlave = pMasterSlot->pLinkedSlot;
+ const SfxSlot *pSlave = pFirstSlave;
+ do
+ {
+ if ( pSlave->pLinkedSlot != pMasterSlot )
+ {
+ ByteString aStr("Falsche Master/Slave-Verkettung : ");
+ aStr += ByteString::CreateFromInt32(pMasterSlot->GetSlotId());
+ aStr += " , ";
+ aStr += ByteString::CreateFromInt32(pSlave->GetSlotId());
+ DBG_ERROR(aStr.GetBuffer());
+ }
+
+ if ( pSlave->nMasterSlotId != pMasterSlot->GetSlotId() )
+ {
+ ByteString aStr("Falsche Master/Slave-Ids : ");
+ aStr += ByteString::CreateFromInt32(pMasterSlot->GetSlotId());
+ aStr += " , ";
+ aStr += ByteString::CreateFromInt32(pSlave->GetSlotId());
+ DBG_ERROR(aStr.GetBuffer());
+ }
+
+ pSlave = pSlave->pNextSlot;
+ }
+ while ( pSlave != pFirstSlave );
+ }
+ else
+ {
+ if ( pIter->pLinkedSlot )
+ {
+ if ( pIter->pLinkedSlot->GetKind() != SFX_KIND_ENUM )
+ {
+ ByteString aStr("Slave ist kein enum : ");
+ aStr += ByteString::CreateFromInt32(pIter->GetSlotId());
+ aStr += " , ";
+ aStr += ByteString::CreateFromInt32(pIter->pLinkedSlot->GetSlotId());
+ DBG_ERROR(aStr.GetBuffer());
+ }
+ }
+
+ const SfxSlot *pCurSlot = pIter;
+ do
+ {
+ pCurSlot = pCurSlot->pNextSlot;
+ if ( pCurSlot->GetStateFnc() != pIter->GetStateFnc() )
+ {
+ ByteString aStr("Verkettete Slots mit verschiedenen StateMethods : ");
+ aStr += ByteString::CreateFromInt32(pCurSlot->GetSlotId());
+ aStr += " , ";
+ aStr += ByteString::CreateFromInt32(pIter->GetSlotId());
+ DBG_ERROR(aStr.GetBuffer());
+ }
+ }
+ while ( pCurSlot != pIter );
+ }
+
+ pIter = pNext;
+ }
+ }
+#endif
+}
+
+
+//--------------------------------------------------------------------
+
+
+
+SfxInterface::~SfxInterface()
+{
+ SfxModule *pMod = pImpData->pModule;
+ BOOL bRegistered = pImpData->bRegistered;
+ delete pImpData;
+ DBG_ASSERT( bRegistered, "Interface not registered!" );
+ if ( bRegistered )
+ {
+ if ( pMod )
+ pMod->GetSlotPool()->ReleaseInterface(*this);
+ else
+ SFX_APP()->GetAppSlotPool_Impl().ReleaseInterface(*this);
+ }
+}
+
+//--------------------------------------------------------------------
+
+// searches for the specified func
+
+
+const SfxSlot* SfxInterface::GetSlot( USHORT nFuncId ) const
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxInterface, 0);
+ DBG_ASSERT( this && pSlots && nCount, "" );
+
+ // find the id using binary search
+ void* p = bsearch( &nFuncId, pSlots, nCount, sizeof(SfxSlot),
+ SfxCompareSlots_Impl );
+ if ( !p && pGenoType )
+ return pGenoType->GetSlot( nFuncId );
+
+ return p ? (const SfxSlot*)p : 0;
+}
+
+const SfxSlot* SfxInterface::GetSlot( const String& rCommand ) const
+{
+ static const char UNO_COMMAND[] = ".uno:";
+
+ String aCommand( rCommand );
+ if ( aCommand.SearchAscii( UNO_COMMAND ) == 0 )
+ aCommand.Erase( 0, sizeof( UNO_COMMAND )-1 );
+
+ for ( USHORT n=0; n<nCount; n++ )
+ {
+ if ( (pSlots+n)->pUnoName &&
+ aCommand.CompareIgnoreCaseToAscii( (pSlots+n)->GetUnoName() ) == COMPARE_EQUAL )
+ return pSlots+n;
+ }
+
+ return pGenoType ? pGenoType->GetSlot( aCommand ) : NULL;
+}
+
+//--------------------------------------------------------------------
+
+
+const SfxSlot* SfxInterface::GetRealSlot( const SfxSlot *pSlot ) const
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxInterface, 0);
+ DBG_ASSERT( this && pSlots && nCount, "" );
+
+ if ( !ContainsSlot_Impl(pSlot) )
+ {
+ if(pGenoType)
+ return pGenoType->GetRealSlot(pSlot);
+ DBG_ERROR("fremder Slot");
+ return 0;
+ }
+
+ return pSlot->pLinkedSlot;
+}
+
+//--------------------------------------------------------------------
+
+
+const SfxSlot* SfxInterface::GetRealSlot( USHORT nSlotId ) const
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxInterface, 0);
+ DBG_ASSERT( this && pSlots && nCount, "" );
+
+ const SfxSlot *pSlot = GetSlot(nSlotId);
+ if ( !pSlot )
+ {
+ if(pGenoType)
+ return pGenoType->GetRealSlot(nSlotId);
+ DBG_ERROR("fremder Slot");
+ return 0;
+ }
+
+ return pSlot->pLinkedSlot;
+}
+
+//--------------------------------------------------------------------
+
+
+void SfxInterface::RegisterPopupMenu( const ResId& rResId )
+{
+ DBG_CHKTHIS(SfxInterface, 0);
+ pImpData->aPopupRes = rResId;
+}
+
+//--------------------------------------------------------------------
+
+void SfxInterface::RegisterObjectBar( USHORT nPos, const ResId& rResId,
+ const String *pStr )
+{
+ RegisterObjectBar( nPos, rResId, 0UL, pStr );
+}
+
+
+void SfxInterface::RegisterObjectBar( USHORT nPos, const ResId& rResId, sal_uInt32 nFeature, const String *pStr )
+{
+ SfxObjectUI_Impl* pUI = CreateObjectBarUI_Impl( nPos, rResId, nFeature, pStr );
+ if ( pUI )
+ pImpData->pObjectBars->Append(pUI);
+}
+
+SfxObjectUI_Impl* CreateObjectBarUI_Impl( USHORT nPos, const ResId& rResId, sal_uInt32 nFeature, const String *pStr )
+{
+ if ((nPos & SFX_VISIBILITY_MASK) == 0)
+ nPos |= SFX_VISIBILITY_STANDARD;
+
+ SfxObjectUI_Impl* pUI = new SfxObjectUI_Impl(nPos, rResId, TRUE, nFeature);
+
+ if (pStr == 0)
+ {
+ ResId aResId(rResId);
+ aResId.SetRT(RSC_STRING);
+ aResId.SetResMgr(rResId.GetResMgr());
+ if( ! aResId.GetResMgr() )
+ aResId.SetResMgr( SfxApplication::GetOrCreate()->GetOffResManager_Impl() );
+ if ( !aResId.GetResMgr()->IsAvailable(aResId) )
+ pUI->pName = new String (DEFINE_CONST_UNICODE("NoName"));
+ else
+ pUI->pName = new String(aResId);
+ }
+ else
+ pUI->pName = new String(*pStr);
+
+ return pUI;
+}
+
+const ResId& SfxInterface::GetObjectBarResId( USHORT nNo ) const
+{
+ BOOL bGenoType = (pGenoType != 0 && !pGenoType->HasName());
+ if ( bGenoType )
+ {
+ // Gibt es Toolbars in der Superklasse ?
+ USHORT nBaseCount = pGenoType->GetObjectBarCount();
+ if ( nNo < nBaseCount )
+ // Die der Superklasse kommen zuerst
+ return pGenoType->GetObjectBarResId( nNo );
+ else
+ nNo = nNo - nBaseCount;
+ }
+
+#ifdef DBG_UTIL
+ USHORT nObjBarCount = pImpData->pObjectBars->Count();
+ DBG_ASSERT( nNo<nObjBarCount,"Objectbar ist unbekannt!" );
+#endif
+ return (*pImpData->pObjectBars)[nNo]->aResId;
+}
+
+//--------------------------------------------------------------------
+
+
+USHORT SfxInterface::GetObjectBarPos( USHORT nNo ) const
+{
+ BOOL bGenoType = (pGenoType != 0 && !pGenoType->HasName());
+ if ( bGenoType )
+ {
+ // Gibt es Toolbars in der Superklasse ?
+ USHORT nBaseCount = pGenoType->GetObjectBarCount();
+ if ( nNo < nBaseCount )
+ // Die der Superklasse kommen zuerst
+ return pGenoType->GetObjectBarPos( nNo );
+ else
+ nNo = nNo - nBaseCount;
+ }
+
+#ifdef DBG_UTIL
+ USHORT nObjBarCount = pImpData->pObjectBars->Count();
+ DBG_ASSERT( nNo<nObjBarCount,"Objectbar ist unbekannt!" );
+#endif
+ return (*pImpData->pObjectBars)[nNo]->nPos;
+}
+
+//--------------------------------------------------------------------
+
+
+USHORT SfxInterface::GetObjectBarCount() const
+{
+ if (pGenoType && ! pGenoType->HasName())
+ return pImpData->pObjectBars->Count() + pGenoType->GetObjectBarCount();
+ else
+ return pImpData->pObjectBars->Count();
+}
+
+//--------------------------------------------------------------------
+void SfxInterface::RegisterChildWindow(USHORT nId, BOOL bContext, const String* pChildWinName)
+{
+ RegisterChildWindow( nId, bContext, 0UL, pChildWinName );
+}
+
+void SfxInterface::RegisterChildWindow(USHORT nId, BOOL bContext, sal_uInt32 nFeature, const String*)
+{
+ SfxObjectUI_Impl* pUI = new SfxObjectUI_Impl(0, ResId(nId, *SfxApplication::GetOrCreate()->GetOffResManager_Impl()), TRUE, nFeature);
+ pUI->bContext = bContext;
+ pImpData->pChildWindows->Append(pUI);
+}
+
+void SfxInterface::RegisterStatusBar(const ResId& rResId)
+{
+ pImpData->aStatBarRes = rResId;
+}
+
+
+sal_uInt32 SfxInterface::GetChildWindowId (USHORT nNo) const
+{
+ if ( pGenoType )
+ {
+ // Gibt es ChildWindows in der Superklasse ?
+ USHORT nBaseCount = pGenoType->GetChildWindowCount();
+ if ( nNo < nBaseCount )
+ // Die der Superklasse kommen zuerst
+ return pGenoType->GetChildWindowId( nNo );
+ else
+ nNo = nNo - nBaseCount;
+ }
+
+#ifdef DBG_UTIL
+ USHORT nCWCount = pImpData->pChildWindows->Count();
+ DBG_ASSERT( nNo<nCWCount,"ChildWindow ist unbekannt!" );
+#endif
+ sal_uInt32 nRet = (*pImpData->pChildWindows)[nNo]->aResId.GetId();
+ if ( (*pImpData->pChildWindows)[nNo]->bContext )
+ nRet += sal_uInt32( nClassId ) << 16;
+ return nRet;
+}
+
+sal_uInt32 SfxInterface::GetChildWindowFeature (USHORT nNo) const
+{
+ if ( pGenoType )
+ {
+ // Gibt es ChildWindows in der Superklasse ?
+ USHORT nBaseCount = pGenoType->GetChildWindowCount();
+ if ( nNo < nBaseCount )
+ // Die der Superklasse kommen zuerst
+ return pGenoType->GetChildWindowFeature( nNo );
+ else
+ nNo = nNo - nBaseCount;
+ }
+
+#ifdef DBG_UTIL
+ USHORT nCWCount = pImpData->pChildWindows->Count();
+ DBG_ASSERT( nNo<nCWCount,"ChildWindow ist unbekannt!" );
+#endif
+ return (*pImpData->pChildWindows)[nNo]->nFeature;
+}
+
+//--------------------------------------------------------------------
+
+
+USHORT SfxInterface::GetChildWindowCount() const
+{
+ if (pGenoType)
+ return pImpData->pChildWindows->Count() + pGenoType->GetChildWindowCount();
+ else
+ return pImpData->pChildWindows->Count();
+}
+
+
+const ResId& SfxInterface::GetPopupMenuResId() const
+{
+ return pImpData->aPopupRes;
+}
+
+
+const ResId& SfxInterface::GetStatusBarResId() const
+{
+ if (pImpData->aStatBarRes.GetId() == 0 && pGenoType)
+ return pGenoType->GetStatusBarResId();
+ else
+ return pImpData->aStatBarRes;
+}
+
+
+
+const String* SfxInterface::GetObjectBarName ( USHORT nNo ) const
+{
+ BOOL bGenoType = (pGenoType != 0 && !pGenoType->HasName());
+ if ( bGenoType )
+ {
+ // Gibt es Toolbars in der Superklasse ?
+ USHORT nBaseCount = pGenoType->GetObjectBarCount();
+ if ( nNo < nBaseCount )
+ // Die der Superklasse kommen zuerst
+ return pGenoType->GetObjectBarName( nNo );
+ else
+ nNo = nNo - nBaseCount;
+ }
+
+#ifdef DBG_UTIL
+ USHORT nObjBarCount = pImpData->pObjectBars->Count();
+ DBG_ASSERT( nNo<nObjBarCount,"Objectbar ist unbekannt!" );
+#endif
+ return (*pImpData->pObjectBars)[nNo]->pName;
+}
+
+sal_uInt32 SfxInterface::GetObjectBarFeature ( USHORT nNo ) const
+{
+ BOOL bGenoType = (pGenoType != 0 && !pGenoType->HasName());
+ if ( bGenoType )
+ {
+ // Gibt es Toolbars in der Superklasse ?
+ USHORT nBaseCount = pGenoType->GetObjectBarCount();
+ if ( nNo < nBaseCount )
+ // Die der Superklasse kommen zuerst
+ return pGenoType->GetObjectBarFeature( nNo );
+ else
+ nNo = nNo - nBaseCount;
+ }
+
+#ifdef DBG_UTIL
+ USHORT nObjBarCount = pImpData->pObjectBars->Count();
+ DBG_ASSERT( nNo<nObjBarCount,"Objectbar ist unbekannt!" );
+#endif
+ return (*pImpData->pObjectBars)[nNo]->nFeature;
+}
+
+BOOL SfxInterface::IsObjectBarVisible(USHORT nNo) const
+{
+ BOOL bGenoType = (pGenoType != 0 && !pGenoType->HasName());
+ if ( bGenoType )
+ {
+ // Gibt es Toolbars in der Superklasse ?
+ USHORT nBaseCount = pGenoType->GetObjectBarCount();
+ if ( nNo < nBaseCount )
+ // Die der Superklasse kommen zuerst
+ return pGenoType->IsObjectBarVisible( nNo );
+ else
+ nNo = nNo - nBaseCount;
+ }
+
+#ifdef DBG_UTIL
+ USHORT nObjBarCount = pImpData->pObjectBars->Count();
+ DBG_ASSERT( nNo<nObjBarCount,"Objectbar ist unbekannt!" );
+#endif
+ return (*pImpData->pObjectBars)[nNo]->bVisible;
+}
+
+const SfxInterface* SfxInterface::GetRealInterfaceForSlot( const SfxSlot *pRealSlot ) const
+{
+ DBG_ASSERT( pImpData->bRegistered, "Interface not registered!" );
+ const SfxInterface* pInterface = this;
+
+ // Der Slot k"onnte auch aus dem Interface einer Shell-Basisklasse stammen
+ do
+ {
+ const SfxSlot *pLastSlot = (*pInterface)[pInterface->Count()-1];
+ const SfxSlot *pFirstSlot = (*pInterface)[0];
+
+ // Ist pInterface der Owner von pRealSlot ?
+ if ( pFirstSlot <= pRealSlot && pRealSlot <= pLastSlot )
+ break;
+
+ // Sonst Interface der Superklasse probieren
+ pInterface = pInterface->pGenoType;
+ }
+ while ( pInterface );
+
+ return pInterface;
+}
+
+
+
diff --git a/sfx2/source/control/querystatus.cxx b/sfx2/source/control/querystatus.cxx
new file mode 100644
index 000000000000..bee4a5c87675
--- /dev/null
+++ b/sfx2/source/control/querystatus.cxx
@@ -0,0 +1,241 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <sfx2/querystatus.hxx>
+#include <svl/poolitem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/itemset.hxx>
+#include <svtools/itemdel.hxx>
+#include <svl/visitem.hxx>
+#include <cppuhelper/weak.hxx>
+#include <comphelper/processfactory.hxx>
+#include <vos/mutex.hxx>
+#include <vcl/svapp.hxx>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/status/ItemStatus.hpp>
+#include <com/sun/star/frame/status/ItemState.hpp>
+#include <com/sun/star/frame/status/Visibility.hpp>
+
+using ::rtl::OUString;
+using namespace ::cppu;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::frame::status;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::util;
+
+class SfxQueryStatus_Impl : public ::com::sun::star::frame::XStatusListener ,
+ public ::com::sun::star::lang::XTypeProvider ,
+ public ::cppu::OWeakObject
+{
+ public:
+ SFX_DECL_XINTERFACE_XTYPEPROVIDER
+
+ SfxQueryStatus_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider, USHORT nSlotId, const rtl::OUString& aCommand );
+ virtual ~SfxQueryStatus_Impl();
+
+ // Query method
+ SfxItemState QueryState( SfxPoolItem*& pPoolItem );
+
+ // XEventListener
+ virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
+
+ // XStatusListener
+ virtual void SAL_CALL statusChanged(const ::com::sun::star::frame::FeatureStateEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
+
+ private:
+ SfxQueryStatus_Impl( const SfxQueryStatus& );
+ SfxQueryStatus_Impl();
+ SfxQueryStatus_Impl& operator=( const SfxQueryStatus& );
+
+ sal_Bool m_bQueryInProgress;
+ SfxItemState m_eState;
+ SfxPoolItem* m_pItem;
+ USHORT m_nSlotID;
+ osl::Condition m_aCondition;
+ ::com::sun::star::util::URL m_aCommand;
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatch > m_xDispatch;
+};
+
+SFX_IMPL_XINTERFACE_2( SfxQueryStatus_Impl, OWeakObject, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
+SFX_IMPL_XTYPEPROVIDER_2( SfxQueryStatus_Impl, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
+
+SfxQueryStatus_Impl::SfxQueryStatus_Impl( const Reference< XDispatchProvider >& rDispatchProvider, USHORT nSlotId, const OUString& rCommand ) :
+ cppu::OWeakObject(),
+ m_bQueryInProgress( sal_False ),
+ m_eState( SFX_ITEM_DISABLED ),
+ m_pItem( 0 ),
+ m_nSlotID( nSlotId )
+{
+ m_aCommand.Complete = rCommand;
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( m_aCommand );
+ if ( rDispatchProvider.is() )
+ m_xDispatch = rDispatchProvider->queryDispatch( m_aCommand, rtl::OUString(), 0 );
+ m_aCondition.reset();
+}
+
+SfxQueryStatus_Impl::~SfxQueryStatus_Impl()
+{
+}
+
+void SAL_CALL SfxQueryStatus_Impl::disposing( const EventObject& )
+throw( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ m_xDispatch.clear();
+}
+
+void SAL_CALL SfxQueryStatus_Impl::statusChanged( const FeatureStateEvent& rEvent)
+throw( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ m_pItem = NULL;
+ m_eState = SFX_ITEM_DISABLED;
+
+ if ( rEvent.IsEnabled )
+ {
+ m_eState = SFX_ITEM_AVAILABLE;
+ ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
+
+ if ( pType == ::getBooleanCppuType() )
+ {
+ sal_Bool bTemp = false;
+ rEvent.State >>= bTemp ;
+ m_pItem = new SfxBoolItem( m_nSlotID, bTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt16*)0) )
+ {
+ sal_uInt16 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ m_pItem = new SfxUInt16Item( m_nSlotID, nTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt32*)0) )
+ {
+ sal_uInt32 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ m_pItem = new SfxUInt32Item( m_nSlotID, nTemp );
+ }
+ else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
+ {
+ ::rtl::OUString sTemp ;
+ rEvent.State >>= sTemp ;
+ m_pItem = new SfxStringItem( m_nSlotID, sTemp );
+ }
+ else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
+ {
+ ItemStatus aItemStatus;
+ rEvent.State >>= aItemStatus;
+ m_eState = aItemStatus.State;
+ m_pItem = new SfxVoidItem( m_nSlotID );
+ }
+ else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
+ {
+ Visibility aVisibilityStatus;
+ rEvent.State >>= aVisibilityStatus;
+ m_pItem = new SfxVisibilityItem( m_nSlotID, aVisibilityStatus.bVisible );
+ }
+ else
+ {
+ m_eState = SFX_ITEM_UNKNOWN;
+ m_pItem = new SfxVoidItem( m_nSlotID );
+ }
+ }
+
+ if ( m_pItem )
+ DeleteItemOnIdle( m_pItem );
+
+ try
+ {
+ m_aCondition.set();
+ m_xDispatch->removeStatusListener( Reference< XStatusListener >( static_cast< cppu::OWeakObject* >( this ), UNO_QUERY ),
+ m_aCommand );
+ }
+ catch ( Exception& )
+ {
+ }
+}
+
+// Query method
+SfxItemState SfxQueryStatus_Impl::QueryState( SfxPoolItem*& rpPoolItem )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( !m_bQueryInProgress )
+ {
+ m_pItem = NULL;
+ m_eState = SFX_ITEM_DISABLED;
+
+ if ( m_xDispatch.is() )
+ {
+ try
+ {
+ m_aCondition.reset();
+ m_bQueryInProgress = sal_True;
+ m_xDispatch->addStatusListener( Reference< XStatusListener >( static_cast< cppu::OWeakObject* >( this ), UNO_QUERY ),
+ m_aCommand );
+ }
+ catch ( Exception& )
+ {
+ m_aCondition.set();
+ }
+ }
+ else
+ m_aCondition.set();
+ }
+
+ m_aCondition.wait();
+
+ m_bQueryInProgress = sal_False;
+ rpPoolItem = m_pItem;
+ return m_eState;
+}
+
+//*************************************************************************
+
+SfxQueryStatus::SfxQueryStatus( const Reference< XDispatchProvider >& rDispatchProvider, USHORT nSlotId, const OUString& rCommand )
+{
+ m_pSfxQueryStatusImpl = new SfxQueryStatus_Impl( rDispatchProvider, nSlotId, rCommand );
+ m_xStatusListener = Reference< XStatusListener >(
+ static_cast< cppu::OWeakObject* >( m_pSfxQueryStatusImpl ),
+ UNO_QUERY );
+}
+
+SfxQueryStatus::~SfxQueryStatus()
+{
+}
+
+SfxItemState SfxQueryStatus::QueryState( SfxPoolItem*& rpPoolItem )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ return m_pSfxQueryStatusImpl->QueryState( rpPoolItem );
+}
diff --git a/sfx2/source/control/request.cxx b/sfx2/source/control/request.cxx
new file mode 100644
index 000000000000..88a52d0ad0bf
--- /dev/null
+++ b/sfx2/source/control/request.cxx
@@ -0,0 +1,978 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <com/sun/star/frame/DispatchStatement.hpp>
+#include <com/sun/star/container/XIndexReplace.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
+#include <svl/itemiter.hxx>
+
+#ifndef _ARGS_HXX //autogen
+#include <svl/itempool.hxx>
+#endif
+#include <svtools/itemdel.hxx>
+
+#include <comphelper/processfactory.hxx>
+
+#ifndef GCC
+#endif
+
+#include <svl/smplhint.hxx>
+
+#include <sfx2/request.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/msg.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "macro.hxx"
+#include <sfx2/objface.hxx>
+#include <sfx2/appuno.hxx>
+
+//===================================================================
+
+using namespace ::com::sun::star;
+
+struct SfxRequest_Impl: public SfxListener
+
+/* [Beschreibung]
+
+ Implementations-Struktur der Klasse <SfxRequest>.
+*/
+
+{
+ SfxRequest* pAnti; // Owner wegen sterbendem Pool
+ String aTarget; // ggf. von App gesetztes Zielobjekt
+ SfxItemPool* pPool; // ItemSet mit diesem Pool bauen
+ SfxPoolItem* pRetVal; // R"uckgabewert geh"ort sich selbst
+ SfxShell* pShell; // ausgef"uhrt an dieser Shell
+ const SfxSlot* pSlot; // ausgef"uhrter Slot
+ USHORT nModifier; // welche Modifier waren gedrueckt?
+ BOOL bDone; // "uberhaupt ausgef"uhrt
+ BOOL bIgnored; // vom User abgebrochen
+ BOOL bCancelled; // nicht mehr zustellen
+ BOOL bUseTarget; // aTarget wurde von Applikation gesetzt
+ USHORT nCallMode; // Synch/Asynch/API/Record
+ BOOL bAllowRecording;
+ SfxAllItemSet* pInternalArgs;
+ SfxViewFrame* pViewFrame;
+
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
+
+ SfxRequest_Impl( SfxRequest *pOwner )
+ : pAnti( pOwner)
+ , pPool(0)
+ , nModifier(0)
+ , bCancelled(FALSE)
+ , nCallMode( SFX_CALLMODE_SYNCHRON )
+ , bAllowRecording( FALSE )
+ , pInternalArgs( 0 )
+ , pViewFrame(0)
+ {}
+ ~SfxRequest_Impl() { delete pInternalArgs; }
+
+
+ void SetPool( SfxItemPool *pNewPool );
+ virtual void Notify( SfxBroadcaster &rBC, const SfxHint &rHint );
+ void Record( const uno::Sequence < beans::PropertyValue >& rArgs );
+};
+
+
+//====================================================================
+
+void SfxRequest_Impl::Notify( SfxBroadcaster&, const SfxHint &rHint )
+{
+ SfxSimpleHint *pSimpleHint = PTR_CAST(SfxSimpleHint, &rHint);
+ if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
+ pAnti->Cancel();
+}
+
+//====================================================================
+
+void SfxRequest_Impl::SetPool( SfxItemPool *pNewPool )
+{
+ if ( pNewPool != pPool )
+ {
+ if ( pPool )
+ EndListening( pPool->BC() );
+ pPool = pNewPool;
+ if ( pNewPool )
+ StartListening( pNewPool->BC() );
+ }
+}
+
+//====================================================================
+
+
+SfxRequest::~SfxRequest()
+{
+ DBG_MEMTEST();
+
+ // nicht mit Done() marktierte Requests mit 'rem' rausschreiben
+ if ( pImp->xRecorder.is() && !pImp->bDone && !pImp->bIgnored )
+ pImp->Record( uno::Sequence < beans::PropertyValue >() );
+
+ // Objekt abr"aumen
+ delete pArgs;
+ if ( pImp->pRetVal )
+ DeleteItemOnIdle(pImp->pRetVal);
+ delete pImp;
+}
+//--------------------------------------------------------------------
+
+
+SfxRequest::SfxRequest
+(
+ const SfxRequest& rOrig
+)
+: SfxHint( rOrig ),
+ nSlot(rOrig.nSlot),
+ pArgs(rOrig.pArgs? new SfxAllItemSet(*rOrig.pArgs): 0),
+ pImp( new SfxRequest_Impl(this) )
+{
+ DBG_MEMTEST();
+
+ pImp->bAllowRecording = rOrig.pImp->bAllowRecording;
+ pImp->bDone = FALSE;
+ pImp->bIgnored = FALSE;
+ pImp->pRetVal = 0;
+ pImp->pShell = 0;
+ pImp->pSlot = 0;
+ pImp->nCallMode = rOrig.pImp->nCallMode;
+ pImp->bUseTarget = rOrig.pImp->bUseTarget;
+ pImp->aTarget = rOrig.pImp->aTarget;
+ pImp->nModifier = rOrig.pImp->nModifier;
+
+ // deep copy needed !
+ pImp->pInternalArgs = (rOrig.pImp->pInternalArgs ? new SfxAllItemSet(*rOrig.pImp->pInternalArgs) : 0);
+
+ if ( pArgs )
+ pImp->SetPool( pArgs->GetPool() );
+ else
+ pImp->SetPool( rOrig.pImp->pPool );
+}
+//--------------------------------------------------------------------
+
+
+SfxRequest::SfxRequest
+(
+ SfxViewFrame* pViewFrame,
+ USHORT nSlotId
+
+)
+
+/* [Beschreibung]
+
+ Mit diesem Konstruktor k"onnen Events, die nicht "uber den SfxDispatcher
+ gelaufen sind (z.B aus KeyInput() oder Mouse-Events) nachtr"aglich
+ recorded werden. Dazu wird eine SfxRequest-Instanz mit diesem Konstruktor
+ erzeugt und dann genauso verfahren, wie mit einem SfxRequest, der in
+ eine <Slot-Execute-Methode> als Parameter gegeben wird.
+*/
+
+: nSlot(nSlotId),
+ pArgs(0),
+ pImp( new SfxRequest_Impl(this) )
+{
+ DBG_MEMTEST();
+
+ pImp->bDone = FALSE;
+ pImp->bIgnored = FALSE;
+ pImp->SetPool( &pViewFrame->GetPool() );
+ pImp->pRetVal = 0;
+ pImp->pShell = 0;
+ pImp->pSlot = 0;
+ pImp->nCallMode = SFX_CALLMODE_SYNCHRON;
+ pImp->bUseTarget = FALSE;
+ pImp->pViewFrame = pViewFrame;
+ if( pImp->pViewFrame->GetDispatcher()->GetShellAndSlot_Impl( nSlotId, &pImp->pShell, &pImp->pSlot, TRUE, TRUE ) )
+ {
+ pImp->SetPool( &pImp->pShell->GetPool() );
+ pImp->xRecorder = SfxRequest::GetMacroRecorder( pViewFrame );
+ pImp->aTarget = pImp->pShell->GetName();
+ }
+#ifdef DBG_UTIL
+ else
+ {
+ ByteString aStr( "Recording unsupported slot: ");
+ aStr += ByteString::CreateFromInt32( pImp->pPool->GetSlotId(nSlotId) );
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+#endif
+}
+
+//--------------------------------------------------------------------
+
+
+SfxRequest::SfxRequest
+(
+ USHORT nSlotId, // auszuf"uhrende <Slot-Id>
+ SfxCallMode nMode, // Synch/API/...
+ SfxItemPool& rPool // ggf. f"ur das SfxItemSet f"ur Parameter
+)
+
+// creates a SfxRequest without arguments
+
+: nSlot(nSlotId),
+ pArgs(0),
+ pImp( new SfxRequest_Impl(this) )
+{
+ DBG_MEMTEST();
+
+ pImp->bDone = FALSE;
+ pImp->bIgnored = FALSE;
+ pImp->SetPool( &rPool );
+ pImp->pRetVal = 0;
+ pImp->pShell = 0;
+ pImp->pSlot = 0;
+ pImp->nCallMode = nMode;
+ pImp->bUseTarget = FALSE;
+}
+
+SfxRequest::SfxRequest
+(
+ const SfxSlot* pSlot, // auszuf"uhrende <Slot-Id>
+ const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& rArgs,
+ SfxCallMode nMode, // Synch/API/...
+ SfxItemPool& rPool // ggf. f"ur das SfxItemSet f"ur Parameter
+)
+: nSlot(pSlot->GetSlotId()),
+ pArgs(new SfxAllItemSet(rPool)),
+ pImp( new SfxRequest_Impl(this) )
+{
+ DBG_MEMTEST();
+
+ pImp->bDone = FALSE;
+ pImp->bIgnored = FALSE;
+ pImp->SetPool( &rPool );
+ pImp->pRetVal = 0;
+ pImp->pShell = 0;
+ pImp->pSlot = 0;
+ pImp->nCallMode = nMode;
+ pImp->bUseTarget = FALSE;
+ TransformParameters( nSlot, rArgs, *pArgs, pSlot );
+}
+
+//-----------------------------------------------------------------------
+
+SfxRequest::SfxRequest
+(
+ USHORT nSlotId,
+ USHORT nMode,
+ const SfxAllItemSet& rSfxArgs
+)
+
+// creates a SfxRequest with arguments
+
+: nSlot(nSlotId),
+ pArgs(new SfxAllItemSet(rSfxArgs)),
+ pImp( new SfxRequest_Impl(this) )
+{
+ DBG_MEMTEST();
+
+ pImp->bDone = FALSE;
+ pImp->bIgnored = FALSE;
+ pImp->SetPool( rSfxArgs.GetPool() );
+ pImp->pRetVal = 0;
+ pImp->pShell = 0;
+ pImp->pSlot = 0;
+ pImp->nCallMode = nMode;
+ pImp->bUseTarget = FALSE;
+}
+//--------------------------------------------------------------------
+
+USHORT SfxRequest::GetCallMode() const
+{
+ return pImp->nCallMode;
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxRequest::IsSynchronCall() const
+{
+ return SFX_CALLMODE_SYNCHRON == ( SFX_CALLMODE_SYNCHRON & pImp->nCallMode );
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::SetSynchronCall( BOOL bSynchron )
+{
+ if ( bSynchron )
+ pImp->nCallMode |= SFX_CALLMODE_SYNCHRON;
+ else
+ pImp->nCallMode &= ~(USHORT) SFX_CALLMODE_SYNCHRON;
+}
+
+void SfxRequest::SetInternalArgs_Impl( const SfxAllItemSet& rArgs )
+{
+ delete pImp->pInternalArgs;
+ pImp->pInternalArgs = new SfxAllItemSet( rArgs );
+}
+
+const SfxItemSet* SfxRequest::GetInternalArgs_Impl() const
+{
+ return pImp->pInternalArgs;
+}
+
+//--------------------------------------------------------------------
+
+
+void SfxRequest_Impl::Record
+(
+ const uno::Sequence < beans::PropertyValue >& rArgs // aktuelle Parameter
+)
+
+/* [Beschreibung]
+
+ Interne Hilfsmethode zum erzeugen einer <SfxMacroStatement>-Instanz,
+ welche den bereits ausgef"uhrten SfxRequest wiederholbar beschreibt.
+
+ Die erzeugte Instanz, auf die ein Pointer zur"uckgeliefert wird
+ geht in das Eigentum des Aufrufers "uber.
+*/
+
+{
+ String aCommand = String::CreateFromAscii(".uno:");
+ aCommand.AppendAscii( pSlot->GetUnoName() );
+ ::rtl::OUString aCmd( aCommand );
+ if(xRecorder.is())
+ {
+ uno::Reference< container::XIndexReplace > xReplace( xRecorder, uno::UNO_QUERY );
+ if ( xReplace.is() && aCmd.compareToAscii(".uno:InsertText") == COMPARE_EQUAL )
+ {
+ sal_Int32 nCount = xReplace->getCount();
+ if ( nCount )
+ {
+ frame::DispatchStatement aStatement;
+ uno::Any aElement = xReplace->getByIndex(nCount-1);
+ if ( (aElement >>= aStatement) && aStatement.aCommand == aCmd )
+ {
+ ::rtl::OUString aStr;
+ ::rtl::OUString aNew;
+ aStatement.aArgs[0].Value >>= aStr;
+ rArgs[0].Value >>= aNew;
+ aStr += aNew;
+ aStatement.aArgs[0].Value <<= aStr;
+ aElement <<= aStatement;
+ xReplace->replaceByIndex( nCount-1, aElement );
+ return;
+ }
+ }
+ }
+
+ com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xFactory(
+ ::comphelper::getProcessServiceFactory(),
+ com::sun::star::uno::UNO_QUERY);
+
+ com::sun::star::uno::Reference< com::sun::star::util::XURLTransformer > xTransform(
+ xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer")),
+ com::sun::star::uno::UNO_QUERY);
+
+ com::sun::star::util::URL aURL;
+ aURL.Complete = aCmd;
+ xTransform->parseStrict(aURL);
+
+ if (bDone)
+ xRecorder->recordDispatch(aURL,rArgs);
+ else
+ xRecorder->recordDispatchAsComment(aURL,rArgs);
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::Record_Impl
+(
+ SfxShell& rSh, // die <SfxShell>, die den Request ausgef"uhrt hat
+ const SfxSlot& rSlot, // der <SfxSlot>, der den Request ausgef"uhrt hat
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder, // der Recorder, mit dem aufgezeichnet wird
+ SfxViewFrame* pViewFrame
+)
+
+/* [Beschreibung]
+
+ Diese interne Methode markiert den SfxRequest als in dem angegebenen
+ SfxMakro aufzuzeichnen.
+
+ Pointer auf die Parameter werden in Done() wieder verwendet, m"usseb
+ dann also noch leben.
+*/
+
+{
+ DBG_MEMTEST();
+ pImp->pShell = &rSh;
+ pImp->pSlot = &rSlot;
+ pImp->xRecorder = xRecorder;
+ pImp->aTarget = rSh.GetName();
+ pImp->pViewFrame = pViewFrame;
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::SetArgs( const SfxAllItemSet& rArgs )
+{
+ delete pArgs;
+ pArgs = new SfxAllItemSet(rArgs);
+ pImp->SetPool( pArgs->GetPool() );
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::AppendItem(const SfxPoolItem &rItem)
+{
+ if(!pArgs)
+ pArgs = new SfxAllItemSet(*pImp->pPool);
+ pArgs->Put(rItem, rItem.Which());
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::RemoveItem( USHORT nID )
+{
+ if (pArgs)
+ {
+ pArgs->ClearItem(nID);
+ if ( !pArgs->Count() )
+ DELETEZ(pArgs);
+ }
+}
+
+//--------------------------------------------------------------------
+
+const SfxPoolItem* SfxRequest::GetArg
+(
+ USHORT nSlotId, // Slot-Id oder Which-Id des Parameters
+ FASTBOOL bDeep, // FALSE: nicht in Parent-ItemSets suchen
+ TypeId aType // != 0: RTTI Pruefung mit Assertion
+) const
+{
+ return GetItem( pArgs, nSlotId, bDeep, aType );
+}
+
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxRequest::GetItem
+(
+ const SfxItemSet* pArgs,
+ USHORT nSlotId, // Slot-Id oder Which-Id des Parameters
+ bool bDeep, // false: nicht in Parent-ItemSets suchen
+ TypeId aType // != 0: RTTI Pruefung mit Assertion
+)
+
+/* [Beschreibung]
+
+ Mit dieser Methode wird der Zugriff auf einzelne Parameter im
+ SfxRequest wesentlich vereinfacht. Insbesondere wird die Typpr"ufung
+ (per Assertion) durchgef"uhrt, wodurch die Applikations-Sourcen
+ wesentlich "ubersichtlicher werden. In der PRODUCT-Version wird
+ eine 0 zur"uckgegeben, wenn das gefundene Item nicht von der
+ angegebenen Klasse ist.
+
+
+ [Beispiel]
+
+ void MyShell::Execute( SfxRequest &rReq )
+ {
+ switch ( rReq.GetSlot() )
+ {
+ case SID_MY:
+ {
+ ...
+ // ein Beispiel ohne Verwendung des Makros
+ const SfxInt32Item *pPosItem = (const SfxUInt32Item*)
+ rReq.GetArg( SID_POS, FALSE, TYPE(SfxInt32Item) );
+ USHORT nPos = pPosItem ? pPosItem->GetValue() : 0;
+
+ // ein Beispiel mit Verwendung des Makros
+ SFX_REQUEST_ARG(rReq, pSizeItem, SfxInt32Item, SID_SIZE, FALSE);
+ USHORT nSize = pSizeItem ? pPosItem->GetValue() : 0;
+
+ ...
+ }
+
+ ...
+ }
+ }
+*/
+
+{
+ if ( pArgs )
+ {
+ // ggf. in Which-Id umrechnen
+ USHORT nWhich = pArgs->GetPool()->GetWhich(nSlotId);
+
+ // ist das Item gesetzt oder bei bDeep==TRUE verf"ugbar?
+ const SfxPoolItem *pItem = 0;
+ if ( ( bDeep ? SFX_ITEM_AVAILABLE : SFX_ITEM_SET )
+ <= pArgs->GetItemState( nWhich, bDeep, &pItem ) )
+ {
+ // stimmt der Typ "uberein?
+ if ( !pItem || pItem->IsA(aType) )
+ return pItem;
+
+ // Item da aber falsch => Programmierfehler
+ DBG_ERROR( "invalid argument type" );
+ }
+ }
+
+ // keine Parameter, nicht gefunden oder falschen Typ gefunden
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::SetReturnValue(const SfxPoolItem &rItem)
+{
+ DBG_ASSERT(!pImp->pRetVal, "Returnwert mehrfach setzen?");
+ if(pImp->pRetVal)
+ delete pImp->pRetVal;
+ pImp->pRetVal = rItem.Clone();
+}
+
+//--------------------------------------------------------------------
+
+const SfxPoolItem* SfxRequest::GetReturnValue() const
+{
+ return pImp->pRetVal;
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::Done
+(
+ const SfxItemSet& rSet, /* von der Applikation mitgeteilte Parameter,
+ die z.B. in einem Dialog vom Benuter
+ erfragt wurden, ggf. 0 falls keine
+ Parameter gesetzt wurden */
+
+ FASTBOOL bKeep /* TRUE (default)
+ 'rSet' wird gepeichert und ist "uber
+ GetArgs() abfragbar
+
+ FALSE
+ 'rSet' wird nicht kopiert (schneller) */
+)
+
+/* [Beschreibung]
+
+ Diese Methode mu\s in der <Execute-Methode> des <SfxSlot>s gerufen
+ werden, der den SfxRequest ausgef"uhrt hat, wenn die Ausf"uhrung
+ tats"achlich stattgefunden hat. Wird 'Done()' nicht gerufen, gilt
+ der SfxRequest als abgebrochen.
+
+ Etwaige Returnwerte werden nur durchgereicht, wenn 'Done()' gerufen
+ wurde. Ebenso werden beim Aufzeichnen von Makros nur echte
+ Statements erzeugt, wenn 'Done()' gerufen wurde; f"ur SfxRequests,
+ die nicht derart gekennzeichnet wurden, wird anstelle dessen eine
+ auf die abgebrochene Funktion hinweisende Bemerkung ('rem') eingf"ugt.
+
+
+ [Anmerkung]
+
+ 'Done()' wird z.B. nicht gerufen, wenn ein durch die Funktion gestarteter
+ Dialog vom Benutzer abgebrochen wurde oder das Ausf"uhren aufgrund
+ eines falschen Kontextes (ohne Verwendung separater <SfxShell>s)
+ nicht durchgef"uhrt werden konnte. 'Done()' mu\s sehr wohl gerufen
+ werden, wenn das Ausf"uhren der Funktion zu einem regul"aren Fehler
+ f"uhrte (z.B. Datei konnte nicht ge"offnet werden).
+*/
+
+{
+ Done_Impl( &rSet );
+
+ // ggf. Items merken, damit StarDraw sie abfragen kann
+ if ( bKeep )
+ {
+ if ( !pArgs )
+ {
+ pArgs = new SfxAllItemSet( rSet );
+ pImp->SetPool( pArgs->GetPool() );
+ }
+ else
+ {
+ SfxItemIter aIter(rSet);
+ const SfxPoolItem* pItem = aIter.FirstItem();
+ while(pItem)
+ {
+ if(!IsInvalidItem(pItem))
+ pArgs->Put(*pItem,pItem->Which());
+ pItem = aIter.NextItem();
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+
+void SfxRequest::Done( BOOL bRelease )
+// [<SfxRequest::Done(SfxItemSet&)>]
+{
+ Done_Impl( pArgs );
+ if( bRelease )
+ DELETEZ( pArgs );
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::ForgetAllArgs()
+{
+ DELETEZ( pArgs );
+ DELETEZ( pImp->pInternalArgs );
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxRequest::IsCancelled() const
+{
+ return pImp->bCancelled;
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::Cancel()
+
+/* [Beschreibung]
+
+ Markiert diesen Request als nicht mehr auszufuehren. Wird z.B. gerufen,
+ wenn das Ziel (genauer dessen Pool) stirbt.
+*/
+
+{
+ pImp->bCancelled = TRUE;
+ pImp->SetPool( 0 );
+ DELETEZ( pArgs );
+}
+
+//--------------------------------------------------------------------
+
+
+void SfxRequest::Ignore()
+
+/* [Beschreibung]
+
+ Wird diese Methode anstelle von <SfxRequest::Done()> gerufen, dann
+ wird dieser Request nicht recorded.
+
+
+ [Bespiel]
+
+ Das Selektieren von Tools im StarDraw soll nicht aufgezeichnet werden,
+ dieselben Slots sollen aber zum erzeugen der von den Tools zu
+ erzeugenden Objekte verwendet werde. Also kann nicht NoRecord
+ angegeben werden, dennoch soll u.U. nicht aufgezeichnet werden.
+*/
+
+{
+ // als tats"achlich ausgef"uhrt markieren
+ pImp->bIgnored = TRUE;
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::Done_Impl
+(
+ const SfxItemSet* pSet /* von der Applikation mitgeteilte Parameter,
+ die z.B. in einem Dialog vom Benuter
+ erfragt wurden, ggf. 0 falls keine
+ Parameter gesetzt wurden */
+)
+
+/* [Beschreibung]
+
+ Interne Methode zum als 'done' markieren des SfxRequest und zum Auswerten
+ der Parameter in 'pSet' falls aufgezeichnet wird.
+*/
+
+{
+ // als tats"achlich ausgef"uhrt markieren
+ pImp->bDone = TRUE;
+
+ // nicht Recorden
+ if ( !pImp->xRecorder.is() )
+ return;
+
+ // wurde ein anderer Slot ausgef"uhrt als angefordert (Delegation)
+ if ( nSlot != pImp->pSlot->GetSlotId() )
+ {
+ // Slot neu suchen
+ pImp->pSlot = pImp->pShell->GetInterface()->GetSlot(nSlot);
+ DBG_ASSERT( pImp->pSlot, "delegated SlotId not found" );
+ if ( !pImp->pSlot ) // Hosentr"ger und G"urtel
+ return;
+ }
+
+ // record-f"ahig?
+ // neues Recorden verwendet UnoName!
+ if ( !pImp->pSlot->pUnoName )
+ {
+ ByteString aStr( "Recording not exported slot: ");
+ aStr += ByteString::CreateFromInt32( pImp->pSlot->GetSlotId() );
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+
+ if ( !pImp->pSlot->pUnoName ) // Hosentr"ger und G"urtel
+ return;
+
+ // "ofters ben"otigte Werte
+ SfxItemPool &rPool = pImp->pShell->GetPool();
+
+ // Property-Slot?
+ if ( !pImp->pSlot->IsMode(SFX_SLOT_METHOD) )
+ {
+ // des Property als SfxPoolItem besorgen
+ const SfxPoolItem *pItem;
+ USHORT nWhich = rPool.GetWhich(pImp->pSlot->GetSlotId());
+ SfxItemState eState = pSet ? pSet->GetItemState( nWhich, FALSE, &pItem ) : SFX_ITEM_UNKNOWN;
+#ifdef DBG_UTIL
+ if ( SFX_ITEM_SET != eState )
+ {
+ ByteString aStr( "Recording property not available: ");
+ aStr += ByteString::CreateFromInt32( pImp->pSlot->GetSlotId() );
+ DBG_ERROR( aStr.GetBuffer() );
+ }
+#endif
+ uno::Sequence < beans::PropertyValue > aSeq;
+ if ( eState == SFX_ITEM_SET )
+ TransformItems( pImp->pSlot->GetSlotId(), *pSet, aSeq, pImp->pSlot );
+ pImp->Record( aSeq );
+ }
+
+ // alles in ein einziges Statement aufzeichnen?
+ else if ( pImp->pSlot->IsMode(SFX_SLOT_RECORDPERSET) )
+ {
+ uno::Sequence < beans::PropertyValue > aSeq;
+ if ( pSet )
+ TransformItems( pImp->pSlot->GetSlotId(), *pSet, aSeq, pImp->pSlot );
+ pImp->Record( aSeq );
+ }
+
+ // jedes Item als einzelnes Statement recorden
+ else if ( pImp->pSlot->IsMode(SFX_SLOT_RECORDPERITEM) )
+ {
+ if ( pSet )
+ {
+ // "uber die Items iterieren
+ SfxItemIter aIter(*pSet);
+ for ( const SfxPoolItem* pItem = aIter.FirstItem(); pItem; pItem = aIter.NextItem() )
+ {
+ // die Slot-Id f"ur das einzelne Item ermitteln
+ USHORT nSlotId = rPool.GetSlotId( pItem->Which() );
+ if ( nSlotId == nSlot )
+ {
+ // mit Hosentr"ager und G"urtel reparieren des falschen Flags
+ DBG_ERROR( "recursion RecordPerItem - use RecordPerSet!" );
+ SfxSlot *pSlot = (SfxSlot*) pImp->pSlot;
+ pSlot->nFlags &= ~((ULONG)SFX_SLOT_RECORDPERITEM);
+ pSlot->nFlags &= SFX_SLOT_RECORDPERSET;
+ }
+
+ // einen Sub-Request recorden
+ SfxRequest aReq( pImp->pViewFrame, nSlotId );
+ if ( aReq.pImp->pSlot )
+ aReq.AppendItem( *pItem );
+ aReq.Done();
+ }
+ }
+ else
+ {
+ HACK(hierueber nochmal nachdenken)
+ pImp->Record( uno::Sequence < beans::PropertyValue >() );
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxRequest::IsDone() const
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann abgefragt werden, ob der SfxRequest tats"achlich
+ ausgef"uhrt wurde oder nicht. Wurde ein SfxRequest nicht ausgef"uhrt,
+ liegt dies z.B. daran, da\s der Benutzer abgebrochen hat oder
+ der Kontext f"ur diesen Request falsch war, dieses aber nicht "uber
+ eine separate <SfxShell> realisiert wurde.
+
+ SfxRequest-Instanzen, die hier FALSE liefern, werden nicht recorded.
+
+
+ [Querverweise]
+
+ <SfxRequest::Done(const SfxItemSet&)>
+ <SfxRequest::Done()>
+*/
+
+{
+ return pImp->bDone;
+}
+
+//--------------------------------------------------------------------
+
+SfxMacro* SfxRequest::GetRecordingMacro()
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann abgefragt werden, ob und in welchem <SfxMacro>
+ die SfxRequests gerade aufgezeichnet werden.
+*/
+
+{
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+
+com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > SfxRequest::GetMacroRecorder( SfxViewFrame* pView )
+
+/* [Beschreibung]
+
+ Hier wird versucht einen Recorder fuer dispatch() Aufrufe vom Frame zu bekommen.
+ Dieser ist dort per Property an einem Supplier verfuegbar - aber nur dann, wenn
+ recording angeschaltet wurde.
+ (Siehe auch SfxViewFrame::MiscExec_Impl() und SID_RECORDING)
+*/
+
+{
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
+
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
+ (pView ? pView : SfxViewFrame::Current())->GetFrame().GetFrameInterface(),
+ com::sun::star::uno::UNO_QUERY);
+
+ if(xSet.is())
+ {
+ com::sun::star::uno::Any aProp = xSet->getPropertyValue(rtl::OUString::createFromAscii("DispatchRecorderSupplier"));
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
+ aProp >>= xSupplier;
+ if(xSupplier.is())
+ xRecorder = xSupplier->getDispatchRecorder();
+ }
+
+ return xRecorder;
+}
+
+BOOL SfxRequest::HasMacroRecorder( SfxViewFrame* pView )
+{
+ return GetMacroRecorder( pView ).is();
+}
+
+
+//--------------------------------------------------------------------
+
+BOOL SfxRequest::IsAPI() const
+
+/* [Beschreibung]
+
+ Liefert TRUE, wenn dieser SfxRequest von einer API (z.B. BASIC)
+ erzeugt wurde, sonst FALSE.
+*/
+
+{
+ return SFX_CALLMODE_API == ( SFX_CALLMODE_API & pImp->nCallMode );
+}
+
+//--------------------------------------------------------------------
+
+
+FASTBOOL SfxRequest::IsRecording() const
+
+/* [Beschreibung]
+
+ Liefert TRUE, wenn dieser SfxRequest recorded werden soll, d.h.
+ 1. zu Zeit ein Makro aufgezeichnet wird
+ 2. dieser Request "uberhaupt aufgezeichnet wird
+ 3. der Request nicht von reiner API (z.B. BASIC) ausgeht,
+ sonst FALSE.
+*/
+
+{
+ return ( AllowsRecording() && GetMacroRecorder().is() );
+}
+
+//--------------------------------------------------------------------
+void SfxRequest::SetModifier( USHORT nModi )
+{
+ pImp->nModifier = nModi;
+}
+
+//--------------------------------------------------------------------
+USHORT SfxRequest::GetModifier() const
+{
+ return pImp->nModifier;
+}
+
+//--------------------------------------------------------------------
+
+void SfxRequest::SetTarget( const String &rTarget )
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann das zu recordende Zielobjekt umgesetzt werden.
+
+
+ [Beispiel]
+
+ Die BASIC-Methode 'Open' wird zwar von der Shell 'Application' ausgef"uhrt,
+ aber am Objekt 'Documents' (global) recorded:
+
+ rReq.SetTarget( "Documents" );
+
+ Dies f"uhrt dann zu:
+
+ Documents.Open( ... )
+*/
+
+{
+ pImp->aTarget = rTarget;
+ pImp->bUseTarget = TRUE;
+}
+
+void SfxRequest::AllowRecording( BOOL bSet )
+{
+ pImp->bAllowRecording = bSet;
+}
+
+BOOL SfxRequest::AllowsRecording() const
+{
+ BOOL bAllow = pImp->bAllowRecording;
+ if( !bAllow )
+ bAllow = ( SFX_CALLMODE_API != ( SFX_CALLMODE_API & pImp->nCallMode ) ) &&
+ ( SFX_CALLMODE_RECORD == ( SFX_CALLMODE_RECORD & pImp->nCallMode ) );
+ return bAllow;
+}
+
+void SfxRequest::ReleaseArgs()
+{
+ DELETEZ( pArgs );
+ DELETEZ( pImp->pInternalArgs );
+}
diff --git a/sfx2/source/control/sfxstatuslistener.cxx b/sfx2/source/control/sfxstatuslistener.cxx
new file mode 100644
index 000000000000..c2cf5f164e7c
--- /dev/null
+++ b/sfx2/source/control/sfxstatuslistener.cxx
@@ -0,0 +1,290 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <sfx2/sfxstatuslistener.hxx>
+#include <svl/poolitem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/itemset.hxx>
+#include <svtools/itemdel.hxx>
+#include <svl/visitem.hxx>
+#include <cppuhelper/weak.hxx>
+#include <comphelper/processfactory.hxx>
+#include <vos/mutex.hxx>
+#include <vcl/svapp.hxx>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#include <com/sun/star/frame/status/ItemStatus.hpp>
+#include <com/sun/star/frame/status/ItemState.hpp>
+#include <com/sun/star/frame/status/Visibility.hpp>
+
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/msgpool.hxx>
+
+using ::rtl::OUString;
+using namespace ::cppu;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::frame::status;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::util;
+
+SFX_IMPL_XINTERFACE_3( SfxStatusListener, OWeakObject, ::com::sun::star::lang::XComponent, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
+SFX_IMPL_XTYPEPROVIDER_3( SfxStatusListener, ::com::sun::star::lang::XComponent, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
+
+SfxStatusListener::SfxStatusListener( const Reference< XDispatchProvider >& rDispatchProvider, USHORT nSlotId, const OUString& rCommand ) :
+ cppu::OWeakObject(),
+ m_nSlotID( nSlotId ),
+ m_xDispatchProvider( rDispatchProvider )
+{
+ m_aCommand.Complete = rCommand;
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( m_aCommand );
+ if ( rDispatchProvider.is() )
+ m_xDispatch = rDispatchProvider->queryDispatch( m_aCommand, rtl::OUString(), 0 );
+}
+
+SfxStatusListener::~SfxStatusListener()
+{
+}
+
+// old sfx controller item C++ API
+void SfxStatusListener::StateChanged( USHORT, SfxItemState, const SfxPoolItem* )
+{
+ // must be implemented by sub class
+}
+
+void SfxStatusListener::Bind()
+{
+ if ( !m_xDispatch.is() && m_xDispatchProvider.is() )
+ {
+ m_xDispatch = m_xDispatchProvider->queryDispatch( m_aCommand, rtl::OUString(), 0 );
+ try
+ {
+ Reference< XStatusListener > aStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
+ m_xDispatch->addStatusListener( aStatusListener, m_aCommand );
+ }
+ catch( Exception& )
+ {
+ }
+ }
+}
+
+void SfxStatusListener::Bind( USHORT nSlotId, const rtl::OUString& rNewCommand )
+{
+ // first remove old listener, if we have a dispatch object
+ Reference< XStatusListener > aStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
+ if ( m_xDispatch.is() )
+ m_xDispatch->removeStatusListener( aStatusListener, m_aCommand );
+ if ( m_xDispatchProvider.is() )
+ {
+ // Store new command data and query for new dispatch
+ m_nSlotID = nSlotId;
+ m_aCommand.Complete = rNewCommand;
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( m_aCommand );
+
+ m_xDispatch = m_xDispatchProvider->queryDispatch( m_aCommand, rtl::OUString(), 0 );
+
+ try
+ {
+ m_xDispatch->addStatusListener( aStatusListener, m_aCommand );
+ }
+ catch( Exception& )
+ {
+ }
+ }
+}
+
+void SfxStatusListener::UnBind()
+{
+ if ( m_xDispatch.is() )
+ {
+ Reference< XStatusListener > aStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
+ m_xDispatch->removeStatusListener( aStatusListener, m_aCommand );
+ m_xDispatch.clear();
+ }
+}
+
+void SfxStatusListener::ReBind()
+{
+ Reference< XStatusListener > aStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
+ if ( m_xDispatch.is() )
+ m_xDispatch->removeStatusListener( aStatusListener, m_aCommand );
+ if ( m_xDispatchProvider.is() )
+ {
+ try
+ {
+ m_xDispatch = m_xDispatchProvider->queryDispatch( m_aCommand, rtl::OUString(), 0 );
+ if ( m_xDispatch.is() )
+ m_xDispatch->addStatusListener( aStatusListener, m_aCommand );
+ }
+ catch( Exception& )
+ {
+ }
+ }
+}
+
+// new UNO API
+void SAL_CALL SfxStatusListener::dispose() throw( ::com::sun::star::uno::RuntimeException )
+{
+ if ( m_xDispatch.is() && m_aCommand.Complete.getLength() > 0 )
+ {
+ try
+ {
+ Reference< XStatusListener > aStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
+ m_xDispatch->removeStatusListener( aStatusListener, m_aCommand );
+ }
+ catch ( Exception& )
+ {
+ }
+ }
+
+ m_xDispatch.clear();
+ m_xDispatchProvider.clear();
+}
+
+void SAL_CALL SfxStatusListener::addEventListener( const Reference< XEventListener >& )
+throw ( RuntimeException )
+{
+ // do nothing - this is a wrapper class which does not support listeners
+}
+
+void SAL_CALL SfxStatusListener::removeEventListener( const Reference< XEventListener >& )
+throw ( RuntimeException )
+{
+ // do nothing - this is a wrapper class which does not support listeners
+}
+
+void SAL_CALL SfxStatusListener::disposing( const EventObject& Source )
+throw( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ if ( Source.Source == Reference< XInterface >( m_xDispatch, UNO_QUERY ))
+ m_xDispatch.clear();
+ else if ( Source.Source == Reference< XInterface >( m_xDispatchProvider, UNO_QUERY ))
+ m_xDispatchProvider.clear();
+}
+
+void SAL_CALL SfxStatusListener::statusChanged( const FeatureStateEvent& rEvent)
+throw( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ SfxViewFrame* pViewFrame = NULL;
+ if ( m_xDispatch.is() )
+ {
+ Reference< XUnoTunnel > xTunnel( m_xDispatch, UNO_QUERY );
+ SfxOfficeDispatch* pDisp = NULL;
+ if ( xTunnel.is() )
+ {
+ sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
+ pDisp = reinterpret_cast< SfxOfficeDispatch* >(sal::static_int_cast< sal_IntPtr >( nImplementation ));
+ }
+
+ if ( pDisp )
+ pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
+ }
+
+ SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
+ const SfxSlot* pSlot = rPool.GetSlot( m_nSlotID );
+
+ SfxItemState eState = SFX_ITEM_DISABLED;
+ SfxPoolItem* pItem = NULL;
+ if ( rEvent.IsEnabled )
+ {
+ eState = SFX_ITEM_AVAILABLE;
+ ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
+
+ if ( pType == ::getVoidCppuType() )
+ {
+ pItem = new SfxVoidItem( m_nSlotID );
+ eState = SFX_ITEM_UNKNOWN;
+ }
+ else if ( pType == ::getBooleanCppuType() )
+ {
+ sal_Bool bTemp = false;
+ rEvent.State >>= bTemp ;
+ pItem = new SfxBoolItem( m_nSlotID, bTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt16*)0) )
+ {
+ sal_uInt16 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ pItem = new SfxUInt16Item( m_nSlotID, nTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt32*)0) )
+ {
+ sal_uInt32 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ pItem = new SfxUInt32Item( m_nSlotID, nTemp );
+ }
+ else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
+ {
+ ::rtl::OUString sTemp ;
+ rEvent.State >>= sTemp ;
+ pItem = new SfxStringItem( m_nSlotID, sTemp );
+ }
+ else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
+ {
+ ItemStatus aItemStatus;
+ rEvent.State >>= aItemStatus;
+ eState = aItemStatus.State;
+ pItem = new SfxVoidItem( m_nSlotID );
+ }
+ else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
+ {
+ Visibility aVisibilityStatus;
+ rEvent.State >>= aVisibilityStatus;
+ pItem = new SfxVisibilityItem( m_nSlotID, aVisibilityStatus.bVisible );
+ }
+ else
+ {
+ if ( pSlot )
+ pItem = pSlot->GetType()->CreateItem();
+ if ( pItem )
+ {
+ pItem->SetWhich( m_nSlotID );
+ pItem->PutValue( rEvent.State );
+ }
+ else
+ pItem = new SfxVoidItem( m_nSlotID );
+ }
+ }
+
+ StateChanged( m_nSlotID, eState, pItem );
+ delete pItem;
+}
+
diff --git a/sfx2/source/control/shell.cxx b/sfx2/source/control/shell.cxx
new file mode 100644
index 000000000000..f3df5dc36d0c
--- /dev/null
+++ b/sfx2/source/control/shell.cxx
@@ -0,0 +1,1298 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/embed/VerbDescriptor.hpp>
+#include <com/sun/star/embed/VerbAttributes.hpp>
+#include <basic/sbstar.hxx>
+#include <svl/itempool.hxx>
+#include <svl/undo.hxx>
+#include <svtools/itemdel.hxx>
+#include <svtools/asynclink.hxx>
+#include <basic/sbx.hxx>
+
+#include <unotools/undoopt.hxx>
+
+#ifndef GCC
+#endif
+
+#include <sfx2/app.hxx>
+#include <sfx2/shell.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "sfxbasic.hxx"
+#include <sfx2/objface.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/dispatch.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/request.hxx>
+#include <sfx2/mnumgr.hxx>
+#include "statcach.hxx"
+#include <sfx2/macrconf.hxx>
+#include <sfx2/msgpool.hxx>
+
+//====================================================================
+
+DBG_NAME(SfxShell)
+
+//====================================================================
+
+TYPEINIT0(SfxShell);
+
+//====================================================================
+typedef SfxSlot* SfxSlotPtr;
+SV_DECL_PTRARR_DEL( SfxVerbSlotArr_Impl, SfxSlotPtr, 4, 4)
+SV_IMPL_PTRARR( SfxVerbSlotArr_Impl, SfxSlotPtr);
+
+using namespace com::sun::star;
+
+//=========================================================================
+// SfxShell_Impl
+//=========================================================================
+struct SfxShell_Impl: public SfxBroadcaster
+{
+ String aObjectName;// Name des Sbx-Objects
+ SfxItemArray_Impl aItems; // Datenaustausch auf Item-Basis
+ SfxViewShell* pViewSh; // SfxViewShell falls Shell ViewFrame/ViewShell/SubShell ist
+ SfxViewFrame* pFrame; // Frame, falls <UI-aktiv>
+ SfxRepeatTarget* pRepeatTarget;
+// SbxObjectRef xParent;
+ BOOL bInAppBASIC;
+ BOOL bActive;
+ ULONG nDisableFlags;
+ ULONG nHelpId;
+ svtools::AsynchronLink* pExecuter;
+ svtools::AsynchronLink* pUpdater;
+ SfxVerbSlotArr_Impl aSlotArr;
+ com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor > aVerbList;
+ SfxShell_Impl() : pExecuter( 0 ), pUpdater( 0 ) {}
+ ~SfxShell_Impl() { delete pExecuter; delete pUpdater;}
+};
+
+//====================================================================
+#ifdef DBG_UTIL
+
+String SfxShellIdent_Impl( const SfxShell *pSh )
+
+/* [Beschreibung]
+
+ Interne Hilfesfunktion. Liefert einen die SfxShell 'pSh' beschreibenden
+ String zur"uck. Z.B.: SfxApplication[StarWriter]
+*/
+
+{
+ String aIdent( pSh->ISA(SfxApplication) ? DEFINE_CONST_UNICODE("SfxApplication") :
+ pSh->ISA(SfxViewFrame) ? DEFINE_CONST_UNICODE("SfxViewFrame") :
+ pSh->ISA(SfxViewShell) ? DEFINE_CONST_UNICODE("SfxViewShell") :
+ pSh->ISA(SfxObjectShell) ? DEFINE_CONST_UNICODE("SfxObjectShell") : DEFINE_CONST_UNICODE("SfxShell") );
+ aIdent += '[';
+ aIdent += pSh->GetName();
+ aIdent += ']';
+ return aIdent;
+}
+
+#endif
+//====================================================================
+
+//=========================================================================
+// SfxShell
+//=========================================================================
+
+void __EXPORT SfxShell::EmptyExecStub(SfxShell *, SfxRequest &)
+{
+}
+
+void __EXPORT SfxShell::EmptyStateStub(SfxShell *, SfxItemSet &)
+{
+}
+
+SfxShell::SfxShell()
+
+/* [Beschreibung]
+
+ Der Konstruktor der Klasse SfxShell initialisierung nur einfache
+ Typen, das dazugeh"orige SbxObject wird erst on-demand erzeugt.
+ Daher ist das Anlegen einer SfxShell Instanz sehr billig.
+*/
+
+: pImp(0),
+ pPool(0),
+ pUndoMgr(0)
+{
+ DBG_CTOR(SfxShell, 0);
+ pImp = new SfxShell_Impl;
+ pImp->pViewSh = 0;
+ pImp->pFrame = 0;
+ pImp->pRepeatTarget = 0;
+ pImp->bInAppBASIC = FALSE;
+ pImp->nHelpId = 0L;
+ pImp->bActive = FALSE;
+ pImp->nDisableFlags = 0;
+}
+
+//-------------------------------------------------------------------------
+
+SfxShell::SfxShell( SfxViewShell *pViewSh )
+
+/* [Beschreibung]
+
+ Der Konstruktor der Klasse SfxShell initialisierung nur einfache
+ Typen, das dazugeh"orige SbxObject wird erst on-demand erzeugt.
+ Daher ist das Anlegen einer SfxShell Instanz sehr billig.
+*/
+
+: pImp(0),
+ pPool(0),
+ pUndoMgr(0)
+{
+ DBG_CTOR(SfxShell, 0);
+ pImp = new SfxShell_Impl;
+ pImp->pViewSh = pViewSh;
+ pImp->pFrame = 0;
+ pImp->pRepeatTarget = 0;
+ pImp->bInAppBASIC = FALSE;
+ pImp->nHelpId = 0L;
+ pImp->bActive = FALSE;
+}
+
+//--------------------------------------------------------------------
+
+SfxShell::~SfxShell()
+
+/* [Beschreibung]
+
+ Die Verbindungs zu einem ggf. zugeh"origen SbxObject wird gel"ost.
+ Das SbxObject existiert ggf. weiter, kann aber keine Funktionen
+ mehr ausf"uhren und keine Properties mehr bereitstellen.
+*/
+
+{
+ DBG_DTOR(SfxShell, 0);
+ delete pImp;
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::SetName( const String &rName )
+
+/* [Beschreibung]
+
+ Setzt den Namen des Shell-Objekts. Mit diesem Namen kann die
+ SfxShell-Instanz vom BASIC aus angesprochen werden.
+*/
+
+{
+ pImp->aObjectName = rName;
+}
+
+//--------------------------------------------------------------------
+
+const String& SfxShell::GetName() const
+
+/* [Beschreibung]
+
+ Liefert den Namen des Shell-Objekts. Mit diesem Namen kann die
+ SfxShell-Instanz vom BASIC aus angesprochen werden.
+*/
+
+{
+ return pImp->aObjectName;
+}
+
+//--------------------------------------------------------------------
+
+SvGlobalName SfxShell::GetGlobalName() const
+
+/* [Beschreibung]
+
+ Liefert den Global Unique Identifier des Shell-Objekts. Mit diesem
+ Namen kann die SfxShell-Instanz z.B. via OLE Automation angesprochen
+ werden, bzw. in der Registration-Database gefunden werden.
+*/
+
+{
+ return SvGlobalName();
+}
+
+//--------------------------------------------------------------------
+
+SfxDispatcher* SfxShell::GetDispatcher() const
+
+/* [Beschreibung]
+
+ Diese Methode liefert einen Pointer auf den <SfxDispatcher>, in
+ dem die SfxShell gerade <UI-aktiv> ist bzw. einen 0-Pointer, wenn
+ sie gerade nicht UI-aktiv ist.
+
+ Der zur"uckgegebene Pointer ist nur im unmittelbaren Kontext des
+ Methodenaufrufs g"ultig.
+*/
+
+{
+ return pImp->pFrame ? pImp->pFrame->GetDispatcher() : 0;
+}
+
+//--------------------------------------------------------------------
+
+SfxViewShell* SfxShell::GetViewShell() const
+
+/* [Beschreibung]
+
+ Liefert bei SubShells die SfxViewShell, in der sie liegen. Sonst und
+ falls nicht vom App-Entwickler angegeben liefert diese Methode 0.
+*/
+
+{
+ return pImp->pViewSh;
+}
+
+//--------------------------------------------------------------------
+
+SfxViewFrame* SfxShell::GetFrame() const
+
+/* [Beschreibung]
+
+ Diese Methode liefert einen Pointer auf den <SfxViewFrame>, dem diese
+ SfxShell-Instanz zugeordnet ist oder in dem sie zur Zeit <UI-aktiv> ist.
+ Ein 0-Pointer wird geliefert, wenn diese SfxShell-OInstanz gerade nicht
+ UI-aktiv ist und auch keinem SfxViewFrame fest zugeordnet ist.
+
+ Der zur"uckgegebene Pointer ist nur im unmittelbaren Kontext des
+ Methodenaufrufs g"ultig.
+
+
+ [Anmerkung]
+
+ Nur Instanzen von Subklasse von SfxApplication und SfxObjectShell sollten
+ hier einen 0-Pointer liefern. Ansonsten liegt ein Fehler im Anwendungs-
+ programm vor (falscher Ctor von SfxShell gerufen).
+
+
+ [Querverweise]
+
+ <SfxViewShell::GetViewFrame()const>
+*/
+
+{
+ if ( pImp->pFrame )
+ return pImp->pFrame;
+ if ( pImp->pViewSh )
+ return pImp->pViewSh->GetViewFrame();
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+const SfxPoolItem* SfxShell::GetItem
+(
+ USHORT nSlotId // Slot-Id des zu erfragenden <SfxPoolItem>s
+) const
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann auf beliebige Objekte von Subklassen von
+ <SfxPoolItem> zugegriffen werden. Diese Austauschtechnik wird ben"otigt,
+ wenn z.B. spezielle <SfxToolBoxControl> Subklassen Zugriff auf
+ bestimmte Daten z.B. der <SfxObjectShell> ben"otigen.
+
+ Die zur"uckgelieferte Instanz geh"ort der jeweilige SfxShell und
+ darf nur im unmittelbaren Kontext des Methodenaufrufs verwendet werden.
+
+
+ [Querverweise]
+
+ <SfxShell::PutItem(const SfxPoolItem&)>
+ <SfxShell::RemoveItem(USHORT)>
+*/
+
+{
+ for ( USHORT nPos = 0; nPos < pImp->aItems.Count(); ++nPos )
+ if ( pImp->aItems.GetObject(nPos)->Which() == nSlotId )
+ return pImp->aItems.GetObject(nPos);
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::RemoveItem
+(
+ USHORT nSlotId // Slot-Id des zu l"oschenden <SfxPoolItem>s
+)
+
+/* [Beschreibung]
+
+ Mit dieser Methode k"onnen die allgemein zur Verf"ugung gestellten
+ Instanzen von Subklassen von <SfxPoolItem> aus der SfxShell entfernt
+ werden.
+
+ Die gespeicherte Instanz wird gel"oscht.
+
+
+ [Querverweise]
+
+ <SfxShell::PutItem(const SfxPoolItem&)>
+ <SfxShell::GetItem(USHORT)>
+*/
+
+{
+ for ( USHORT nPos = 0; nPos < pImp->aItems.Count(); ++nPos )
+ if ( pImp->aItems.GetObject(nPos)->Which() == nSlotId )
+ {
+ // Item entfernen und l"oschen
+ SfxPoolItem *pItem = pImp->aItems.GetObject(nPos);
+ delete pItem;
+ pImp->aItems.Remove(nPos);
+
+ // falls aktiv Bindings benachrichtigen
+ SfxDispatcher *pDispat = GetDispatcher();
+ if ( pDispat )
+ {
+ SfxVoidItem aVoid( nSlotId );
+ pDispat->GetBindings()->Broadcast( SfxPoolItemHint( &aVoid ) );
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::PutItem
+(
+ const SfxPoolItem& rItem /* Instanz, von der eine Kopie erstellt wird,
+ die in der SfxShell in einer Liste
+ gespeichert wird. */
+)
+
+/* [Beschreibung]
+
+ Mit dieser Methode k"onnen beliebige Objekte von Subklassen von
+ <SfxPoolItem> zur Verf"ugung gestellt werden. Diese Austauschtechnik
+ wird ben"otigt, wenn z.B. spezielle <SfxToolBoxControl> Subklassen
+ Zugriff auf bestimmte Daten z.B. der <SfxObjectShell> ben"otigen.
+
+ Falls ein SfxPoolItem mit derselben Slot-Id exisitert, wird dieses
+ automatisch gel"oscht.
+
+
+ [Querverweise]
+
+ <SfxShell::RemoveItem(USHORT)>
+ <SfxShell::GetItem(USHORT)>
+*/
+
+{
+ DBG_ASSERT( !rItem.ISA(SfxSetItem), "SetItems aren't allowed here" );
+ DBG_ASSERT( SfxItemPool::IsSlot( rItem.Which() ),
+ "items with Which-Ids aren't allowed here" );
+
+ // MSC auf WNT/W95 machte hier Mist, Vorsicht bei Umstellungen
+ const SfxPoolItem *pItem = rItem.Clone();
+ SfxPoolItemHint aItemHint( (SfxPoolItem*) pItem );
+ const USHORT nWhich = rItem.Which();
+ SfxPoolItem **ppLoopItem = (SfxPoolItem**) pImp->aItems.GetData();
+ USHORT nPos;
+ for ( nPos = 0; nPos < pImp->aItems.Count(); ++nPos, ++ppLoopItem )
+ {
+ if ( (*ppLoopItem)->Which() == nWhich )
+ {
+ // Item austauschen
+ delete *ppLoopItem;
+ pImp->aItems.Remove(nPos);
+ pImp->aItems.Insert( (SfxPoolItemPtr) pItem, nPos );
+
+ // falls aktiv Bindings benachrichtigen
+ SfxDispatcher *pDispat = GetDispatcher();
+ if ( pDispat )
+ {
+ SfxBindings* pBindings = pDispat->GetBindings();
+ pBindings->Broadcast( aItemHint );
+ USHORT nSlotId = nWhich; //pItem->GetSlotId();
+ SfxStateCache* pCache = pBindings->GetStateCache( nSlotId );
+ if ( pCache )
+ {
+ pCache->SetState( SFX_ITEM_AVAILABLE, pItem->Clone(), TRUE );
+ pCache->SetCachedState( TRUE );
+ }
+ }
+ return;
+ }
+ }
+
+ Broadcast( aItemHint );
+ pImp->aItems.Insert((SfxPoolItemPtr)pItem, nPos );
+}
+
+//--------------------------------------------------------------------
+
+SfxInterface* SfxShell::GetInterface() const
+
+/* [Beschreibung]
+
+ Mit dieser virtuellen Methode, die durch das Makro <SFX_DECL_INTERFACE>
+ von jeder Subclass mit eigenen Slots automatisch "uberladen wird, kann
+ auf die zu der Subklasse geh"orende <SfxInterface>-Instanz zugegriffen
+ werden.
+
+ Die Klasse SfxShell selbst hat noch kein eigenes SfxInterface
+ (keine Slots), daher wird ein 0-Pointer zur"uckgeliefert.
+*/
+
+{
+ return GetStaticInterface();
+}
+
+//--------------------------------------------------------------------
+
+SfxBroadcaster* SfxShell::GetBroadcaster()
+
+/* [Beschreibung]
+
+ Liefert einen SfxBroadcaster f"ur diese SfxShell-Instanz bis die
+ Klasse SfxShell von SfxBroadcaster abgeleitet ist.
+*/
+
+{
+ return pImp;
+}
+
+//--------------------------------------------------------------------
+
+SfxUndoManager* SfxShell::GetUndoManager()
+
+/* [Beschreibung]
+
+ Jede Subclass von SfxShell kann "uber einen <SfxUndoManager> verf"ugen.
+ Dieser kann in den abgeleiteten Klasse mit <SfxShell:SetUndoManager()>
+ gesetzt werden.
+
+ Die Klasse SfxShell selbst hat noch keinen SfxUndoManager, es wird
+ daher ein 0-Pointer zur"uckgeliefert.
+*/
+
+{
+ return pUndoMgr;
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::SetUndoManager( SfxUndoManager *pNewUndoMgr )
+
+/* [Beschreibung]
+
+ Setzt einen <SfxUndoManager> f"ur diese <SfxShell> Instanz. F"ur das
+ Undo wird immer nur der Undo-Manager an der jeweils oben auf dem
+ Stack des <SfxDispatcher> liegenden SfxShell verwendet.
+
+ Am "ubergebenen <SfxUndoManager> wird automatisch die aktuelle
+ Max-Undo-Action-Count Einstellung aus den Optionen gesetzt.
+
+ 'pNewUndoMgr' mu\s bis zum Dtor dieser SfxShell-Instanz oder bis
+ zum n"achsten 'SetUndoManager()' existieren.
+*/
+
+{
+ pUndoMgr = pNewUndoMgr;
+ if ( pUndoMgr )
+ pUndoMgr->SetMaxUndoActionCount( (USHORT) SvtUndoOptions().GetUndoCount() );
+}
+
+//--------------------------------------------------------------------
+
+SfxRepeatTarget* SfxShell::GetRepeatTarget() const
+
+/* [Beschreibung]
+
+ Liefert einen Pointer auf die <SfxRepeatTarget>-Instanz, die
+ als RepeatTarget bei SID_REPEAT verwendet wird, wenn der
+ von dieser SfxShell gelieferte <SfxUndoManager> angesprochen wird.
+ Der R"uckgabewert kann 0 sein.
+
+
+ [Anmerkung]
+
+ Eine Ableitung von <SfxShell> oder einer ihrer Subklassen von
+ <SfxRepeatTarget> ist nicht zu empfehlen, da Compiler-Fehler
+ provoziert werden (wegen Call-to-Pointer-to-Member-Function to
+ subclass).
+*/
+
+{
+ return pImp->pRepeatTarget;
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::SetRepeatTarget( SfxRepeatTarget *pTarget )
+
+/* [Beschreibung]
+
+ Setzt den die <SfxRepeatTarget>-Instanz, die bei SID_REPEAT als
+ RepeatTarget verwendet wird, wenn der von dieser SfxShell gelieferte
+ <SfxUndoManager> angesprochen wird. Durch 'pTarget==0' wird SID_REPEAT
+ f"ur diese SfxShell disabled. Die Instanz '*pTarget' mu\s so lange
+ leben, wie sie angemeldet ist.
+
+
+ [Anmerkung]
+
+ Eine Ableitung von <SfxShell> oder einer ihrer Subklassen von
+ <SfxRepeatTarget> ist nicht zu empfehlen, da Compiler-Fehler
+ provoziert werden (wegen Call-to-Pointer-to-Member-Function to
+ subclass).
+*/
+
+{
+ pImp->pRepeatTarget = pTarget;
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::Invalidate
+(
+ USHORT nId /* Zu invalidierende Slot-Id oder Which-Id.
+ Falls diese 0 ist (default), werden
+ alle z.Zt. von dieser Shell bedienten
+ Slot-Ids invalidiert. */
+)
+
+/* [Beschreibung]
+
+ Mit dieser Methode k"onnen Slots der Subclasses "uber die Slot-Id
+ oder alternativ "uber die Which-Id invalidiert werden. Slot-Ids,
+ die von der Subclass ererbt sind, werden ebenfalls invalidert.
+
+ [Querverweise]
+ <SfxBindings::Invalidate(USHORT)>
+ <SfxBindings::InvalidateAll(BOOL)>
+*/
+
+{
+ if ( !GetViewShell() )
+ {
+ DBG_ERROR( "wrong Invalidate method called!" );
+ return;
+ }
+
+ Invalidate_Impl( GetViewShell()->GetViewFrame()->GetBindings(), nId );
+}
+
+void SfxShell::Invalidate_Impl( SfxBindings& rBindings, USHORT nId )
+{
+ if ( nId == 0 )
+ {
+ rBindings.InvalidateShell( *this, FALSE );
+ }
+ else
+ {
+ const SfxInterface *pIF = GetInterface();
+ do
+ {
+ const SfxSlot *pSlot = pIF->GetSlot(nId);
+ if ( pSlot )
+ {
+ // bei Enum-Slots ist der Master-Slot zu invalidieren
+ if ( SFX_KIND_ENUM == pSlot->GetKind() )
+ pSlot = pSlot->GetLinkedSlot();
+
+ // den Slot selbst und ggf. auch alle Slave-Slots invalidieren
+ rBindings.Invalidate( pSlot->GetSlotId() );
+ for ( const SfxSlot *pSlave = pSlot->GetLinkedSlot();
+ pSlave && pIF->ContainsSlot_Impl( pSlave ) &&
+ pSlave->GetLinkedSlot() == pSlot;
+ ++pSlave )
+ rBindings.Invalidate( pSlave->GetSlotId() );
+
+ return;
+ }
+
+ pIF = pIF->GetGenoType();
+ }
+
+ while ( pIF );
+
+ DBG_WARNING( "W3: invalidating slot-id unknown in shell" );
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::DoActivate_Impl( SfxViewFrame *pFrame, BOOL bMDI )
+
+/* [Beschreibung]
+
+ Diese Methode steuert die Aktivierung der SfxShell-Instanz. Zun"achst
+ wird durch Aufruf der virtuellen Methode <SfxShell::Activate(BOOL)>
+ der Subclass die M"oglichkeit gegeben, auf das Event zu reagieren.
+
+ Bei bMDI == TRUE wird das zugeh"orige SbxObject 'scharfgeschaltet',
+ so da\s Methoden des Objekts unqualifiziert (ohne den Namen des Objekts)
+ vom BASIC gefunden werden.
+*/
+
+{
+#ifdef DBG_UTIL
+ const SfxInterface *p_IF = GetInterface();
+ if ( !p_IF )
+ return;
+#endif
+#ifdef DBG_UTIL_VB
+ String aMsg("SfxShell::DoActivate() ");
+ aMsg += (long)this;
+ aMsg += " ";
+ aMsg += GetInterface()->GetName();
+ aMsg += " bMDI ";
+ if ( bMDI ) aMsg += "MDI";
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+
+ if ( bMDI )
+ {
+ // Frame merken, in dem aktiviert wird
+ pImp->pFrame = pFrame;
+ pImp->bActive = TRUE;
+ }
+
+ // Subklasse benachrichtigen
+ Activate(bMDI);
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::DoDeactivate_Impl( SfxViewFrame *pFrame, BOOL bMDI )
+
+/* [Beschreibung]
+
+ Diese Methode steuert die Deaktivierung der SfxShell-Instanz. Bei
+ bMDI == TRUE wird zun"achst das SbxObject in einen Status versetzt,
+ so da\s Methoden vom BASIC aus nur noch qualifiziert gerufen werden
+ k"onnen.
+
+ Dann erh"alt in jedem Fall die Subclass durch Aufruf der virtuellen
+ Methode <SfxShell::Deactivate(BOOL)> die M"oglichkeit auf das Event
+ zu reagieren.
+*/
+
+{
+#ifdef DBG_UTIL
+ const SfxInterface *p_IF = GetInterface();
+ if ( !p_IF )
+ return;
+#endif
+#ifdef DBG_UTIL_VB
+ String aMsg("SfxShell::DoDeactivate()");
+ aMsg += (long)this;
+ aMsg += " ";
+ aMsg += GetInterface()->GetName();
+ aMsg += " bMDI ";
+ if ( bMDI ) aMsg += "MDI";
+ DbgTrace( aMsg.GetBuffer() );
+#endif
+
+ // nur wenn er vom Frame kommt (nicht z.B. pop der BASIC-IDE vom AppDisp)
+ if ( bMDI && pImp->pFrame == pFrame )
+ {
+ // austragen
+ pImp->pFrame = 0;
+ pImp->bActive = FALSE;
+ }
+
+ // Subklasse benachrichtigen
+ Deactivate(bMDI);
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxShell::IsActive() const
+{
+ return pImp->bActive;
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::Activate
+(
+ BOOL /*bMDI*/ /* TRUE
+ der <SfxDispatcher>, auf dem die SfxShell sich
+ befindet, ist aktiv geworden oder die SfxShell
+ Instanz wurde auf einen aktiven SfxDispatcher
+ gepusht. (vergl. SystemWindow::IsMDIActivate())
+
+ FALSE
+ das zum <SfxViewFrame>, auf dessen SfxDispatcher
+ sich die SfxShell Instanz befindet, wurde
+ aktiviert.
+ (z.B. durch einen geschlossenen Dialog) */
+)
+
+/* [Beschreibung]
+
+ Virtuelle Methode, die beim Aktivieren der SfxShell Instanz gerufen
+ wird, um den Subclasses die Gelegenheit zu geben, auf das Aktivieren
+ zu reagieren.
+
+ Die Basisimplementation ist leer und braucht nicht gerufen zu werden.
+
+
+ [Querverweise]
+ StarView SystemWindow::Activate(BOOL)
+*/
+
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::Deactivate
+(
+ BOOL /*bMDI*/ /* TRUE
+ der <SfxDispatcher>, auf dem die SfxShell sich
+ befindet, ist inaktiv geworden oder die SfxShell
+ Instanz wurde auf einen aktiven SfxDispatcher
+ gepoppt. (vergl. SystemWindow::IsMDIActivate())
+
+ FALSE
+ das zum <SfxViewFrame>, auf dessen SfxDispatcher
+ sich die SfxShell Instanz befindet, wurde
+ deaktiviert. (z.B. durch einen Dialog) */
+
+)
+
+/* [Beschreibung]
+
+ Virtuelle Methode, die beim Deaktivieren der SfxShell Instanz gerufen
+ wird, um den Subclasses die Gelegenheit zu geben, auf das Deaktivieren
+ zu reagieren.
+
+ Die Basisimplementation ist leer und braucht nicht gerufen zu werden.
+
+
+ [Querverweise]
+ StarView SystemWindow::Dectivate(BOOL)
+*/
+
+{
+}
+
+void SfxShell::ParentActivate
+(
+)
+
+/* [Beschreibung]
+
+ Ein Parent des <SfxDispatcher>, auf dem die SfxShell sich befindet,
+ ist aktiv geworden, oder die SfxShell Instanz wurde auf einen
+ <SfxDispatcher> gepusht, dessen parent aktiv ist.
+
+ Die Basisimplementation ist leer und braucht nicht gerufen zu werden.
+
+ [Querverweise]
+ SfxShell::Activate()
+*/
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::ParentDeactivate
+(
+)
+
+/* [Beschreibung]
+
+ Der aktive Parent des <SfxDispatcher>, auf dem die SfxShell sich befindet,
+ ist deaktiviert worden.
+
+ Die Basisimplementation ist leer und braucht nicht gerufen zu werden.
+
+ [Querverweise]
+ SfxShell::Deactivate()
+*/
+{
+}
+
+//--------------------------------------------------------------------
+
+ResMgr* SfxShell::GetResMgr() const
+
+/* [Beschreibung]
+
+ Diese Methode liefert den ResMgr der <Resource-DLL>, die von der
+ SfxShell-Instanz verwendet wird. Ist dies ein 0-Pointer, so
+ ist der aktuelle Resource-Manager zu verwenden.
+*/
+
+{
+ return GetInterface()->GetResMgr();
+}
+
+//--------------------------------------------------------------------
+
+FASTBOOL SfxShell::CanExecuteSlot_Impl( const SfxSlot &rSlot )
+
+/* [Beschreibung]
+
+ Diese Methode stellt durch Aufruf der Statusfunktion fest,
+ ob 'rSlot' aktuell ausgef"uhrt werden kann.
+*/
+{
+ // Slot-Status holen
+ SfxItemPool &rPool = GetPool();
+ const USHORT nId = rSlot.GetWhich( rPool );
+ SfxItemSet aSet(rPool, nId, nId);
+ SfxStateFunc pFunc = rSlot.GetStateFnc();
+ CallState( pFunc, aSet );
+ return aSet.GetItemState(nId) != SFX_ITEM_DISABLED;
+}
+
+//--------------------------------------------------------------------
+
+long ShellCall_Impl( void* pObj, void* pArg )
+{
+ ((SfxShell* )pObj)->ExecuteSlot( *(SfxRequest*)pArg, (SfxInterface*)0L );
+ return 0;
+}
+
+/* [Beschreibung]
+ Asynchrones ExecuteSlot fuer das RELOAD
+ */
+
+//--------------------------------------------------------------------
+const SfxPoolItem* SfxShell::ExecuteSlot( SfxRequest& rReq, BOOL bAsync )
+{
+ if( !bAsync )
+ return ExecuteSlot( rReq, (SfxInterface*)0L );
+ else
+ {
+ if( !pImp->pExecuter )
+ pImp->pExecuter = new svtools::AsynchronLink(
+ Link( this, ShellCall_Impl ) );
+ pImp->pExecuter->Call( new SfxRequest( rReq ) );
+ return 0;
+ }
+}
+
+const SfxPoolItem* SfxShell::ExecuteSlot
+(
+ SfxRequest &rReq, // der weiterzuleitende <SfxRequest>
+ const SfxInterface* pIF // default = 0 bedeutet virtuell besorgen
+)
+
+/* [Beschreibung]
+
+ Diese Methode erm"oglicht das Weiterleiten eines <SfxRequest> an
+ die angegebene Basis-<SfxShell>.
+
+
+ [Beispiel]
+
+ In einer von SfxViewShell abgeleiteten Klasse soll SID_PRINTDOCDIRECT
+ abgefangen werden. Unter bestimmten Umst"anden soll vor dem Drucken
+ eine Abfrage erscheinen, und der Request soll ggf. abgebrochen werden.
+
+ Dazu ist in der IDL dieser Subklasse der o.g. Slot einzutragen. Die
+ Execute-Methode enth"alt dann skizziert:
+
+ void SubViewShell::Exec( SfxRequest &rReq )
+ {
+ if ( rReq.GetSlot() == SID_PRINTDOCDIRECT )
+ {
+ 'dialog'
+ if ( 'condition' )
+ ExecuteSlot( rReq, SfxViewShell::GetInterface() );
+ }
+ }
+
+ Es braucht i.d.R. kein rReq.Done() gerufen zu werden, da das bereits
+ die Implementierung der SfxViewShell erledigt bzw. abgebrochen wurde.
+
+
+ [Querverweise]
+
+ <SfxShell::GetSlotState(USHORT,const SfxInterface*,SfxItemSet*)>
+*/
+
+{
+ if ( !pIF )
+ pIF = GetInterface();
+
+ USHORT nSlot = rReq.GetSlot();
+ const SfxSlot* pSlot = NULL;
+ if ( nSlot >= SID_VERB_START && nSlot <= SID_VERB_END )
+ pSlot = GetVerbSlot_Impl(nSlot);
+ if ( !pSlot )
+ pSlot = pIF->GetSlot(nSlot);
+ if ( !pSlot && SfxMacroConfig::IsMacroSlot( nSlot ) )
+ {
+ SfxMacroInfo* pInfo = SFX_APP()->GetMacroConfig()->GetMacroInfo(nSlot);
+ if ( pInfo )
+ pSlot = pInfo->GetSlot();
+ }
+
+ DBG_ASSERT( pSlot, "slot not supported" );
+
+ SfxExecFunc pFunc = pSlot->GetExecFnc();
+ if ( pFunc )
+ CallExec( pFunc, rReq );
+
+ return rReq.GetReturnValue();
+}
+
+//--------------------------------------------------------------------
+
+const SfxPoolItem* SfxShell::GetSlotState
+(
+ USHORT nSlotId, // Slot-Id des zu befragenden Slots
+ const SfxInterface* pIF, // default = 0 bedeutet virtuell besorgen
+ SfxItemSet* pStateSet // SfxItemSet der Slot-State-Methode
+)
+
+/* [Beschreibung]
+
+ Diese Methode liefert den Status des Slots mit der angegebenen Slot-Id
+ "uber das angegebene Interface.
+
+ Ist der Slot disabled oder in dieser SfxShell (und deren Parent-Shells)
+ nicht bekannt, wird ein 0-Pointer zur"uckgeliefert.
+
+ Hat der Slot keinen Status, wird ein SfxVoidItem zur"uckgeliefert.
+
+ Der Status wird bei pStateSet != 0 gleich in diesem Set gesetzt, so
+ da\s <SfxShell>-Subklassen Slots-"uberladen und auch bei der
+ Status-Methode die Basis-Implementierung rufen k"onnen.
+
+
+ [Beispiel]
+
+ In einer von SfxViewShell abgeleiteten Klasse soll SID_PRINTDOCDIRECT
+ abgefangen werden. Unter bestimmten Umst"anden soll vor dem Drucken
+ eine Abfrage erscheinen, und der Request soll ggf. abgebrochen werden.
+
+ Dazu ist in der IDL dieser Subklasse der o.g. Slot einzutragen. Die
+ Status-Methode enth"alt dann skizziert:
+
+ void SubViewShell::PrintState( SfxItemSet &rState )
+ {
+ if ( rState.GetItemState( SID_PRINTDOCDIRECT ) != SFX_ITEM_UNKNOWN )
+ GetSlotState( SID_PRINTDOCDIRECT, SfxViewShell::GetInterface(),
+ &rState );
+ ...
+ }
+
+
+ [Querverweise]
+
+ <SfxShell::ExecuteSlot(SfxRequest&)>
+*/
+
+{
+ // Slot am angegebenen Interface besorgen
+ if ( !pIF )
+ pIF = GetInterface();
+ SfxItemState eState;
+ SfxItemPool &rPool = GetPool();
+
+ const SfxSlot* pSlot = NULL;
+ if ( nSlotId >= SID_VERB_START && nSlotId <= SID_VERB_END )
+ pSlot = GetVerbSlot_Impl(nSlotId);
+ if ( !pSlot )
+ pSlot = pIF->GetSlot(nSlotId);
+ if ( !pSlot && SfxMacroConfig::IsMacroSlot( nSlotId ) )
+ {
+ SfxMacroInfo* pInfo = SFX_APP()->GetMacroConfig()->GetMacroInfo(nSlotId);
+ if ( pInfo )
+ pSlot = pInfo->GetSlot();
+ }
+
+ if ( pSlot )
+ // ggf. auf Which-Id mappen
+ nSlotId = pSlot->GetWhich( rPool );
+
+ // Item und Item-Status besorgen
+ const SfxPoolItem *pItem = NULL;
+ SfxItemSet aSet( rPool, nSlotId, nSlotId ); // pItem stirbt sonst zu fr"uh
+ if ( pSlot )
+ {
+ // Status-Methode rufen
+ SfxStateFunc pFunc = pSlot->GetStateFnc();
+ if ( pFunc )
+ CallState( pFunc, aSet );
+ eState = aSet.GetItemState( nSlotId, TRUE, &pItem );
+
+ // ggf. Default-Item besorgen
+ if ( eState == SFX_ITEM_DEFAULT )
+ {
+ if ( SfxItemPool::IsWhich(nSlotId) )
+ pItem = &rPool.GetDefaultItem(nSlotId);
+ else
+ eState = SFX_ITEM_DONTCARE;
+ }
+ }
+ else
+ eState = SFX_ITEM_UNKNOWN;
+
+ // Item und Item-Status auswerten und ggf. in pStateSet mitpflegen
+ SfxPoolItem *pRetItem = 0;
+ if ( eState <= SFX_ITEM_DISABLED )
+ {
+ if ( pStateSet )
+ pStateSet->DisableItem(nSlotId);
+ return 0;
+ }
+ else if ( eState == SFX_ITEM_DONTCARE )
+ {
+ if ( pStateSet )
+ pStateSet->ClearItem(nSlotId);
+ pRetItem = new SfxVoidItem(0);
+ }
+ else
+ {
+ if ( pStateSet && pStateSet->Put( *pItem ) )
+ return &pStateSet->Get( pItem->Which() );
+ pRetItem = pItem->Clone();
+ }
+ DeleteItemOnIdle(pRetItem);
+
+ return pRetItem;
+}
+
+//--------------------------------------------------------------------
+
+SFX_EXEC_STUB(SfxShell, VerbExec)
+SFX_STATE_STUB(SfxShell, VerbState)
+
+void SfxShell::SetVerbs(const com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor >& aVerbs)
+{
+ SfxViewShell *pViewSh = PTR_CAST ( SfxViewShell, this);
+
+ DBG_ASSERT(pViewSh, "SetVerbs nur an der ViewShell aufrufen!");
+ if ( !pViewSh )
+ return;
+
+ // Zun"achst alle Statecaches dirty machen, damit keiner mehr versucht,
+ // die Slots zu benutzen
+ {
+ SfxBindings *pBindings =
+ pViewSh->GetViewFrame()->GetDispatcher()->GetBindings();
+ USHORT nCount = pImp->aSlotArr.Count();
+ for (USHORT n1=0; n1<nCount ; n1++)
+ {
+ USHORT nId = SID_VERB_START + n1;
+ pBindings->Invalidate(nId, FALSE, TRUE);
+ }
+ }
+
+ USHORT nr=0;
+ for (sal_Int32 n=0; n<aVerbs.getLength(); n++)
+ {
+ USHORT nSlotId = SID_VERB_START + nr++;
+ DBG_ASSERT(nSlotId <= SID_VERB_END, "Zuviele Verben!");
+ if (nSlotId > SID_VERB_END)
+ break;
+
+ SfxSlot *pNewSlot = new SfxSlot;
+ pNewSlot->nSlotId = nSlotId;
+ pNewSlot->nGroupId = 0;
+
+ // Verb-Slots m"ussen asynchron ausgef"uhrt werden, da sie w"ahrend
+ // des Ausf"uhrens zerst"ort werden k"onnten
+ pNewSlot->nFlags = SFX_SLOT_ASYNCHRON | SFX_SLOT_CONTAINER;
+ pNewSlot->nMasterSlotId = 0;
+ pNewSlot->nValue = 0;
+ pNewSlot->fnExec = SFX_STUB_PTR(SfxShell,VerbExec);
+ pNewSlot->fnState = SFX_STUB_PTR(SfxShell,VerbState);
+ pNewSlot->pType = 0; HACK(SFX_TYPE(SfxVoidItem))
+ pNewSlot->pName = U2S(aVerbs[n].VerbName);
+ pNewSlot->pLinkedSlot = 0;
+ pNewSlot->nArgDefCount = 0;
+ pNewSlot->pFirstArgDef = 0;
+ pNewSlot->pUnoName = 0;
+
+ if (pImp->aSlotArr.Count())
+ {
+ SfxSlot *pSlot = (pImp->aSlotArr)[0];
+ pNewSlot->pNextSlot = pSlot->pNextSlot;
+ pSlot->pNextSlot = pNewSlot;
+ }
+ else
+ pNewSlot->pNextSlot = pNewSlot;
+
+ pImp->aSlotArr.Insert(pNewSlot, (USHORT) n);
+ }
+
+ pImp->aVerbList = aVerbs;
+
+ if (pViewSh)
+ {
+ // Der Status von SID_OBJECT wird im Controller direkt an der Shell
+ // abgeholt, es reicht also, ein neues StatusUpdate anzuregen
+ SfxBindings *pBindings = pViewSh->GetViewFrame()->GetDispatcher()->
+ GetBindings();
+ pBindings->Invalidate( SID_OBJECT, TRUE, TRUE );
+ }
+}
+
+//--------------------------------------------------------------------
+
+const com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor >& SfxShell::GetVerbs() const
+{
+ return pImp->aVerbList;
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::VerbExec(SfxRequest& rReq)
+{
+ USHORT nId = rReq.GetSlot();
+ SfxViewShell *pViewShell = GetViewShell();
+ if ( pViewShell )
+ {
+ BOOL bReadOnly = pViewShell->GetObjectShell()->IsReadOnly();
+ com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor > aList = pViewShell->GetVerbs();
+ for (sal_Int32 n=0, nVerb=0; n<aList.getLength(); n++)
+ {
+ // check for ReadOnly verbs
+ if ( bReadOnly && !(aList[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_NEVERDIRTIES) )
+ continue;
+
+ // check for verbs that shouldn't appear in the menu
+ if ( !(aList[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU) )
+ continue;
+
+ if (nId == SID_VERB_START + nVerb++)
+ {
+ pViewShell->DoVerb(aList[n].VerbID);
+ rReq.Done();
+ return;
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::VerbState(SfxItemSet& )
+{
+}
+
+//--------------------------------------------------------------------
+
+const SfxSlot* SfxShell::GetVerbSlot_Impl(USHORT nId) const
+{
+ com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor > rList = pImp->aVerbList;
+
+ DBG_ASSERT(nId >= SID_VERB_START && nId <= SID_VERB_END,"Falsche VerbId!");
+ USHORT nIndex = nId - SID_VERB_START;
+ DBG_ASSERT(nIndex < rList.getLength(),"Falsche VerbId!");
+
+ if (nIndex < rList.getLength())
+ return pImp->aSlotArr[nIndex];
+ else
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxShell::SetHelpId(ULONG nId)
+{
+ pImp->nHelpId = nId;
+}
+
+//--------------------------------------------------------------------
+
+ULONG SfxShell::GetHelpId() const
+{
+ return pImp->nHelpId;
+}
+
+//--------------------------------------------------------------------
+
+SfxObjectShell* SfxShell::GetObjectShell()
+{
+ if ( GetViewShell() )
+ return GetViewShell()->GetViewFrame()->GetObjectShell();
+ else
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+
+sal_Bool SfxShell::HasUIFeature( sal_uInt32 )
+{
+ return sal_False;
+}
+
+long DispatcherUpdate_Impl( void*, void* pArg )
+{
+ ((SfxDispatcher*) pArg)->Update_Impl( TRUE );
+ ((SfxDispatcher*) pArg)->GetBindings()->InvalidateAll(FALSE);
+ return 0;
+}
+
+void SfxShell::UIFeatureChanged()
+{
+ SfxViewFrame *pFrame = GetFrame();
+ if ( pFrame && pFrame->IsVisible() )
+ {
+ // Auch dann Update erzwingen, wenn Dispatcher schon geupdated ist,
+ // sonst bleibt evtl. irgendwas in den gebunkerten Tools stecken.
+ // Asynchron aufrufen, um Rekursionen zu vermeiden
+ if ( !pImp->pUpdater )
+ pImp->pUpdater = new svtools::AsynchronLink( Link( this, DispatcherUpdate_Impl ) );
+
+ // Mehrfachaufrufe gestattet
+ pImp->pUpdater->Call( pFrame->GetDispatcher(), TRUE );
+ }
+}
+
+void SfxShell::SetDisableFlags( ULONG nFlags )
+{
+ pImp->nDisableFlags = nFlags;
+}
+
+ULONG SfxShell::GetDisableFlags() const
+{
+ return pImp->nDisableFlags;
+}
+
+SfxItemSet* SfxShell::CreateItemSet( USHORT )
+{
+ return NULL;
+}
+
+void SfxShell::ApplyItemSet( USHORT, const SfxItemSet& )
+{
+}
+
+void SfxShell::SetViewShell_Impl( SfxViewShell* pView )
+{
+ pImp->pViewSh = pView;
+}
+
+
+
diff --git a/sfx2/source/control/sorgitm.cxx b/sfx2/source/control/sorgitm.cxx
new file mode 100644
index 000000000000..cb24fe34e9b6
--- /dev/null
+++ b/sfx2/source/control/sorgitm.cxx
@@ -0,0 +1,136 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sfx2/sfxsids.hrc>
+#include "sorgitm.hxx"
+// STATIC DATA -----------------------------------------------------------
+
+TYPEINIT1_AUTOFACTORY(SfxScriptOrganizerItem, SfxStringItem);
+
+//------------------------------------------------------------------------
+
+SfxScriptOrganizerItem::SfxScriptOrganizerItem() :
+
+ SfxStringItem()
+
+{
+}
+
+//------------------------------------------------------------------------
+
+SfxScriptOrganizerItem::SfxScriptOrganizerItem( const String& rLanguage ) :
+
+ SfxStringItem( SID_SCRIPTORGANIZER, rLanguage ),
+
+ aLanguage( rLanguage )
+
+{
+}
+
+//------------------------------------------------------------------------
+
+SfxScriptOrganizerItem::SfxScriptOrganizerItem( const SfxScriptOrganizerItem& rItem ) :
+
+ SfxStringItem( rItem ),
+
+ aLanguage( rItem.aLanguage )
+
+{
+}
+
+//------------------------------------------------------------------------
+
+SfxScriptOrganizerItem::~SfxScriptOrganizerItem()
+{
+}
+
+//------------------------------------------------------------------------
+
+SfxPoolItem* SfxScriptOrganizerItem::Clone( SfxItemPool * ) const
+{
+ return new SfxScriptOrganizerItem( *this );
+}
+
+//------------------------------------------------------------------------
+
+int SfxScriptOrganizerItem::operator==( const SfxPoolItem& rItem) const
+{
+ return rItem.Type() == Type() &&
+ SfxStringItem::operator==(rItem) &&
+ aLanguage == ((const SfxScriptOrganizerItem &)rItem).aLanguage;
+}
+
+
+sal_Bool SfxScriptOrganizerItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE nMemberId ) const
+{
+ String aValue;
+ BOOL bIsString = FALSE;
+ sal_Bool bValue = sal_False;
+ nMemberId &= ~CONVERT_TWIPS;
+ switch ( nMemberId )
+ {
+ case 0:
+ case MID_SCRIPT_ORGANIZER_LANGUAGE:
+ bIsString = TRUE;
+ aValue = aLanguage;
+ break;
+ default:
+ DBG_ERROR("Wrong MemberId!");
+ return sal_False;
+ }
+
+ if ( bIsString )
+ rVal <<= ::rtl::OUString( aValue );
+ else
+ rVal <<= bValue;
+ return sal_True;
+}
+
+sal_Bool SfxScriptOrganizerItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId )
+{
+ ::rtl::OUString aValue;
+ sal_Bool bRet = sal_False;
+ nMemberId &= ~CONVERT_TWIPS;
+ switch ( nMemberId )
+ {
+ case 0:
+ case MID_SCRIPT_ORGANIZER_LANGUAGE:
+ bRet = (rVal >>= aValue);
+ if ( bRet )
+ aLanguage = aValue;
+ break;
+ default:
+ DBG_ERROR("Wrong MemberId!");
+ return sal_False;
+ }
+
+ return bRet;
+}
+
diff --git a/sfx2/source/control/statcach.cxx b/sfx2/source/control/statcach.cxx
new file mode 100644
index 000000000000..3fdd14369856
--- /dev/null
+++ b/sfx2/source/control/statcach.cxx
@@ -0,0 +1,577 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifdef SOLARIS
+// HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
+#include <ctime>
+#endif
+
+#include <string> // HACK: prevent conflict between STLPORT and Workshop headers
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/frame/XFrameActionListener.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/FrameActionEvent.hpp>
+#include <com/sun/star/frame/FrameAction.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <cppuhelper/weak.hxx>
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/visitem.hxx>
+#include <comphelper/processfactory.hxx>
+
+#ifndef GCC
+#endif
+
+#include <sfx2/app.hxx>
+#include <sfx2/appuno.hxx>
+#include "statcach.hxx"
+#include <sfx2/msg.hxx>
+#include <sfx2/ctrlitem.hxx>
+#include <sfx2/dispatch.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/viewfrm.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+
+//====================================================================
+
+DBG_NAME(SfxStateCache)
+DBG_NAME(SfxStateCacheSetState)
+
+SFX_IMPL_XINTERFACE_2( BindDispatch_Impl, OWeakObject, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
+SFX_IMPL_XTYPEPROVIDER_2( BindDispatch_Impl, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
+
+//-----------------------------------------------------------------------------
+BindDispatch_Impl::BindDispatch_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > & rDisp, const ::com::sun::star::util::URL& rURL, SfxStateCache *pStateCache, const SfxSlot* pS )
+ : xDisp( rDisp )
+ , aURL( rURL )
+ , pCache( pStateCache )
+ , pSlot( pS )
+{
+ DBG_ASSERT( pCache && pSlot, "Invalid BindDispatch!");
+ aStatus.IsEnabled = sal_True;
+}
+
+void SAL_CALL BindDispatch_Impl::disposing( const ::com::sun::star::lang::EventObject& ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ if ( xDisp.is() )
+ {
+ xDisp->removeStatusListener( (::com::sun::star::frame::XStatusListener*) this, aURL );
+ xDisp = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > ();
+ }
+}
+
+void SAL_CALL BindDispatch_Impl::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& rEvent ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ aStatus = rEvent;
+ if ( !pCache )
+ return;
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > xRef( (::cppu::OWeakObject*)this, ::com::sun::star::uno::UNO_QUERY );
+ if ( aStatus.Requery )
+ pCache->Invalidate( sal_True );
+ else
+ {
+ SfxPoolItem *pItem=NULL;
+ sal_uInt16 nId = pCache->GetId();
+ SfxItemState eState = SFX_ITEM_DISABLED;
+ // pCache->Invalidate( sal_False );
+ if ( !aStatus.IsEnabled )
+ {
+ // default
+ }
+ else if (aStatus.State.hasValue())
+ {
+ eState = SFX_ITEM_AVAILABLE;
+ ::com::sun::star::uno::Any aAny = aStatus.State;
+
+ ::com::sun::star::uno::Type pType = aAny.getValueType();
+ if ( pType == ::getBooleanCppuType() )
+ {
+ sal_Bool bTemp = false;
+ aAny >>= bTemp ;
+ pItem = new SfxBoolItem( nId, bTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt16*)0) )
+ {
+ sal_uInt16 nTemp = 0;
+ aAny >>= nTemp ;
+ pItem = new SfxUInt16Item( nId, nTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt32*)0) )
+ {
+ sal_uInt32 nTemp = 0;
+ aAny >>= nTemp ;
+ pItem = new SfxUInt32Item( nId, nTemp );
+ }
+ else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
+ {
+ ::rtl::OUString sTemp ;
+ aAny >>= sTemp ;
+ pItem = new SfxStringItem( nId, sTemp );
+ }
+ else
+ {
+ if ( pSlot )
+ pItem = pSlot->GetType()->CreateItem();
+ if ( pItem )
+ {
+ pItem->SetWhich( nId );
+ pItem->PutValue( aAny );
+ }
+ else
+ pItem = new SfxVoidItem( nId );
+ }
+ }
+ else
+ {
+ // DONTCARE status
+ pItem = new SfxVoidItem(0);
+ eState = SFX_ITEM_UNKNOWN;
+ }
+
+ for ( SfxControllerItem *pCtrl = pCache->GetItemLink();
+ pCtrl;
+ pCtrl = pCtrl->GetItemLink() )
+ pCtrl->StateChanged( nId, eState, pItem );
+
+ delete pItem;
+ }
+}
+
+void BindDispatch_Impl::Release()
+{
+ if ( xDisp.is() )
+ {
+ xDisp->removeStatusListener( (::com::sun::star::frame::XStatusListener*) this, aURL );
+ xDisp = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > ();
+ }
+
+ pCache = NULL;
+ release();
+}
+
+const ::com::sun::star::frame::FeatureStateEvent& BindDispatch_Impl::GetStatus() const
+{
+ return aStatus;
+}
+
+void BindDispatch_Impl::Dispatch( uno::Sequence < beans::PropertyValue > aProps, sal_Bool bForceSynchron )
+{
+ if ( xDisp.is() && aStatus.IsEnabled )
+ {
+ sal_Int32 nLength = aProps.getLength();
+ aProps.realloc(nLength+1);
+ aProps[nLength].Name = DEFINE_CONST_UNICODE("SynchronMode");
+ aProps[nLength].Value <<= bForceSynchron ;
+ xDisp->dispatch( aURL, aProps );
+ }
+}
+
+//--------------------------------------------------------------------
+
+/* Dieser Konstruktor fuer einen ungueltigen Cache, der sich also
+ bei der ersten Anfrage zun"achst updated.
+ */
+
+SfxStateCache::SfxStateCache( sal_uInt16 nFuncId ):
+ pDispatch( 0 ),
+ nId(nFuncId),
+ pInternalController(0),
+ pController(0),
+ pLastItem( 0 ),
+ eLastState( 0 ),
+ bItemVisible( sal_True )
+{
+ DBG_MEMTEST();
+ DBG_CTOR(SfxStateCache, 0);
+ bCtrlDirty = sal_True;
+ bSlotDirty = sal_True;
+ bItemDirty = sal_True;
+}
+
+//--------------------------------------------------------------------
+
+/* Der Destruktor pr"uft per Assertion, ob noch Controller angemeldet
+ sind.
+ */
+
+SfxStateCache::~SfxStateCache()
+{
+ DBG_MEMTEST();
+ DBG_DTOR(SfxStateCache, 0);
+ DBG_ASSERT( pController == 0 && pInternalController == 0, "es sind noch Controller angemeldet" );
+ if ( !IsInvalidItem(pLastItem) )
+ delete pLastItem;
+ if ( pDispatch )
+ {
+ pDispatch->Release();
+ pDispatch = NULL;
+ }
+}
+
+//--------------------------------------------------------------------
+// invalidates the cache (next request will force update)
+void SfxStateCache::Invalidate( sal_Bool bWithMsg )
+{
+ bCtrlDirty = sal_True;
+ if ( bWithMsg )
+ {
+ bSlotDirty = sal_True;
+ aSlotServ.SetSlot( 0 );
+ if ( pDispatch )
+ {
+ pDispatch->Release();
+ pDispatch = NULL;
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+// gets the corresponding function from the dispatcher or the cache
+
+const SfxSlotServer* SfxStateCache::GetSlotServer( SfxDispatcher &rDispat , const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & xProv )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxStateCache, 0);
+
+ if ( bSlotDirty )
+ {
+ // get the SlotServer; we need it for internal controllers anyway, but also in most cases
+ rDispat._FindServer( nId, aSlotServ, sal_False );
+
+ DBG_ASSERT( !pDispatch, "Old Dispatch not removed!" );
+
+ // we don't need to check the dispatch provider if we only have an internal controller
+ if ( xProv.is() )
+ {
+ const SfxSlot* pSlot = aSlotServ.GetSlot();
+ if ( !pSlot )
+ // get the slot - even if it is disabled on the dispatcher
+ pSlot = SfxSlotPool::GetSlotPool( rDispat.GetFrame() ).GetSlot( nId );
+
+ if ( !pSlot || !pSlot->pUnoName )
+ {
+ bSlotDirty = sal_False;
+ bCtrlDirty = sal_True;
+ return aSlotServ.GetSlot()? &aSlotServ: 0;
+ }
+
+ // create the dispatch URL from the slot data
+ ::com::sun::star::util::URL aURL;
+ ::rtl::OUString aCmd = DEFINE_CONST_UNICODE(".uno:");
+ aURL.Protocol = aCmd;
+ aURL.Path = ::rtl::OUString::createFromAscii( pSlot->GetUnoName() );
+ aCmd += aURL.Path;
+ aURL.Complete = aCmd;
+ aURL.Main = aCmd;
+
+ // try to get a dispatch object for this command
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 );
+ if ( xDisp.is() )
+ {
+ // test the dispatch object if it is just a wrapper for a SfxDispatcher
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xTunnel( xDisp, ::com::sun::star::uno::UNO_QUERY );
+ SfxOfficeDispatch* pDisp = NULL;
+ if ( xTunnel.is() )
+ {
+ sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
+ pDisp = reinterpret_cast< SfxOfficeDispatch* >(sal::static_int_cast< sal_IntPtr >( nImplementation ));
+ }
+
+ if ( pDisp )
+ {
+ // The intercepting object is an SFX component
+ // If this dispatch object does not use the wanted dispatcher or the AppDispatcher, it's treated like any other UNO component
+ // (intercepting by internal dispatches)
+ SfxDispatcher *pDispatcher = pDisp->GetDispatcher_Impl();
+ if ( pDispatcher == &rDispat || pDispatcher == SFX_APP()->GetAppDispatcher_Impl() )
+ {
+ // so we can use it directly
+ bSlotDirty = sal_False;
+ bCtrlDirty = sal_True;
+ return aSlotServ.GetSlot()? &aSlotServ: 0;
+ }
+ }
+
+ // so the dispatch object isn't a SfxDispatcher wrapper or it is one, but it uses another dispatcher, but not rDispat
+ pDispatch = new BindDispatch_Impl( xDisp, aURL, this, pSlot );
+ pDispatch->acquire();
+
+ // flags must be set before adding StatusListener because the dispatch object will set the state
+ bSlotDirty = sal_False;
+ bCtrlDirty = sal_True;
+ xDisp->addStatusListener( pDispatch, aURL );
+ }
+ else if ( rDispat.GetFrame() )
+ {
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchProvider > xFrameProv(
+ rDispat.GetFrame()->GetFrame().GetFrameInterface(), ::com::sun::star::uno::UNO_QUERY );
+ if ( xFrameProv != xProv )
+ return GetSlotServer( rDispat, xFrameProv );
+ }
+ }
+
+ bSlotDirty = sal_False;
+ bCtrlDirty = sal_True;
+ }
+
+ // we *always* return a SlotServer (if there is one); but in case of an external dispatch we might not use it
+ // for the "real" (non internal) controllers
+ return aSlotServ.GetSlot()? &aSlotServ: 0;
+}
+
+
+//--------------------------------------------------------------------
+
+// Status setzen in allen Controllern
+
+void SfxStateCache::SetState
+(
+ SfxItemState eState, // <SfxItemState> von 'pState'
+ const SfxPoolItem* pState, // Status des Slots, ggf. 0 oder -1
+ BOOL bMaybeDirty
+)
+
+/* [Beschreibung]
+
+ Diese Methode verteilt die Status auf alle an dieser SID gebundenen
+ <SfxControllerItem>s. Ist der Wert derselbe wie zuvor und wurde in-
+ zwischen weder ein Controller angemeldet, noch ein Controller invalidiert,
+ dann wird kein Wert weitergeleitet. Dadurch wird z.B. Flackern in
+ ListBoxen vermieden.
+*/
+
+{
+// if ( pDispatch )
+// return;
+ SetState_Impl( eState, pState, bMaybeDirty );
+}
+
+//--------------------------------------------------------------------
+
+void SfxStateCache::SetVisibleState( BOOL bShow )
+{
+ SfxItemState eState( SFX_ITEM_AVAILABLE );
+ const SfxPoolItem* pState( NULL );
+ sal_Bool bNotify( sal_False );
+ sal_Bool bDeleteItem( sal_False );
+
+ if ( bShow != bItemVisible )
+ {
+ bItemVisible = bShow;
+ if ( bShow )
+ {
+ if ( IsInvalidItem(pLastItem) || ( pLastItem == NULL ))
+ {
+ pState = new SfxVoidItem( nId );
+ bDeleteItem = sal_True;
+ }
+ else
+ pState = pLastItem;
+
+ eState = eLastState;
+ bNotify = ( pState != 0 );
+ }
+ else
+ {
+ pState = new SfxVisibilityItem( nId, FALSE );
+ bDeleteItem = sal_True;
+ }
+
+ // Controller updaten
+ if ( !pDispatch && pController )
+ {
+ for ( SfxControllerItem *pCtrl = pController;
+ pCtrl;
+ pCtrl = pCtrl->GetItemLink() )
+ pCtrl->StateChanged( nId, eState, pState );
+ }
+
+ if ( pInternalController )
+ pInternalController->StateChanged( nId, eState, pState );
+
+ if ( !bDeleteItem )
+ delete pState;
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxStateCache::SetState_Impl
+(
+ SfxItemState eState, // <SfxItemState> von 'pState'
+ const SfxPoolItem* pState, // Status des Slots, ggf. 0 oder -1
+ BOOL bMaybeDirty
+)
+{
+ (void)bMaybeDirty; //unused
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxStateCache, 0);
+
+ // wenn zwischen Enter- und LeaveRegistrations ein hartes Update kommt
+ // k"onnen zwischenzeitlich auch Cached ohne Controller exisitieren
+ if ( !pController && !pInternalController )
+ return;
+
+ DBG_ASSERT( bMaybeDirty || !bSlotDirty, "setting state of dirty message" );
+// DBG_ASSERT( bCtrlDirty || ( aSlotServ.GetSlot() && aSlotServ.GetSlot()->IsMode(SFX_SLOT_VOLATILE) ), ! Discussed with MBA
+// "setting state of non dirty controller" );
+ DBG_ASSERT( SfxControllerItem::GetItemState(pState) == eState, "invalid SfxItemState" );
+ DBG_PROFSTART(SfxStateCacheSetState);
+
+ // m"ussen die Controller "uberhaupt benachrichtigt werden?
+ FASTBOOL bNotify = bItemDirty;
+ if ( !bItemDirty )
+ {
+ FASTBOOL bBothAvailable = pLastItem && pState &&
+ !IsInvalidItem(pState) && !IsInvalidItem(pLastItem);
+ DBG_ASSERT( !bBothAvailable || pState != pLastItem, "setting state with own item" );
+ if ( bBothAvailable )
+ bNotify = pState->Type() != pLastItem->Type() ||
+ *pState != *pLastItem;
+ else
+ bNotify = ( pState != pLastItem ) || ( eState != eLastState );
+ }
+
+ if ( bNotify )
+ {
+ // Controller updaten
+ if ( !pDispatch && pController )
+ {
+ for ( SfxControllerItem *pCtrl = pController;
+ pCtrl;
+ pCtrl = pCtrl->GetItemLink() )
+ pCtrl->StateChanged( nId, eState, pState );
+ }
+
+ if ( pInternalController )
+ ((SfxDispatchController_Impl *)pInternalController)->StateChanged( nId, eState, pState, &aSlotServ );
+
+ // neuen Wert merken
+ if ( !IsInvalidItem(pLastItem) )
+ DELETEZ(pLastItem);
+ if ( pState && !IsInvalidItem(pState) )
+ pLastItem = pState->Clone();
+ else
+ pLastItem = 0;
+ eLastState = eState;
+ bItemDirty = sal_False;
+ }
+
+ bCtrlDirty = sal_False;
+ DBG_PROFSTOP(SfxStateCacheSetState);
+}
+
+
+//--------------------------------------------------------------------
+
+// alten Status in allen Controllern nochmal setzen
+
+void SfxStateCache::SetCachedState( BOOL bAlways )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxStateCache, 0);
+ DBG_ASSERT(pController==NULL||pController->GetId()==nId, "Cache mit falschem ControllerItem" );
+ DBG_PROFSTART(SfxStateCacheSetState);
+
+ // nur updaten wenn cached item vorhanden und auch verarbeitbar
+ // (Wenn der State gesendet wird, mu\s sichergestellt sein, da\s ein
+ // Slotserver vorhanden ist, s. SfxControllerItem::GetCoreMetric() )
+ if ( bAlways || ( !bItemDirty && !bSlotDirty ) )
+ {
+ // Controller updaten
+ if ( !pDispatch && pController )
+ {
+ for ( SfxControllerItem *pCtrl = pController;
+ pCtrl;
+ pCtrl = pCtrl->GetItemLink() )
+ pCtrl->StateChanged( nId, eLastState, pLastItem );
+ }
+
+ if ( pInternalController )
+ ((SfxDispatchController_Impl *)pInternalController)->StateChanged( nId, eLastState, pLastItem, &aSlotServ );
+
+ // Controller sind jetzt ok
+ bCtrlDirty = sal_True;
+ }
+
+ DBG_PROFSTOP(SfxStateCacheSetState);
+}
+
+
+//--------------------------------------------------------------------
+
+// FloatingWindows in allen Controls mit dieser Id zerstoeren
+
+void SfxStateCache::DeleteFloatingWindows()
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxStateCache, 0);
+
+ SfxControllerItem *pNextCtrl=0;
+ for ( SfxControllerItem *pCtrl=pController; pCtrl; pCtrl=pNextCtrl )
+ {
+ DBG_TRACE((ByteString("pCtrl: ").Append(ByteString::CreateFromInt64((sal_uIntPtr)pCtrl))).GetBuffer());
+ pNextCtrl = pCtrl->GetItemLink();
+ pCtrl->DeleteFloatingWindow();
+ }
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SfxStateCache::GetDispatch() const
+{
+ if ( pDispatch )
+ return pDispatch->xDisp;
+ return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > ();
+}
+
+void SfxStateCache::Dispatch( const SfxItemSet* pSet, sal_Bool bForceSynchron )
+{
+ // protect pDispatch against destruction in the call
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XStatusListener > xKeepAlive( pDispatch );
+ if ( pDispatch )
+ {
+ uno::Sequence < beans::PropertyValue > aArgs;
+ if (pSet)
+ TransformItems( nId, *pSet, aArgs );
+ pDispatch->Dispatch( aArgs, bForceSynchron );
+ }
+}
+
+
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
new file mode 100644
index 000000000000..f85d0d8e9e49
--- /dev/null
+++ b/sfx2/source/control/unoctitm.cxx
@@ -0,0 +1,1013 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <tools/debug.hxx>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/itemset.hxx>
+#include <svl/visitem.hxx>
+#include <svtools/javacontext.hxx>
+#include <svl/itempool.hxx>
+#include <tools/urlobj.hxx>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/frame/XFrameActionListener.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/FrameActionEvent.hpp>
+#include <com/sun/star/frame/FrameAction.hpp>
+#include <com/sun/star/frame/status/ItemStatus.hpp>
+#include <com/sun/star/frame/status/ItemState.hpp>
+#include <com/sun/star/frame/DispatchResultState.hpp>
+#include <com/sun/star/frame/status/Visibility.hpp>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/sequence.hxx>
+#include <vos/mutex.hxx>
+#include <uno/current_context.hxx>
+#include <vcl/svapp.hxx>
+
+#include <sfx2/app.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/frame.hxx>
+#include <sfx2/ctrlitem.hxx>
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <sfx2/request.hxx>
+#include "statcach.hxx"
+#include <sfx2/msgpool.hxx>
+#include <sfx2/objsh.hxx>
+
+namespace css = ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+//long nOfficeDispatchCount = 0;
+
+enum URLTypeId
+{
+ URLType_BOOL,
+ URLType_BYTE,
+ URLType_SHORT,
+ URLType_LONG,
+ URLType_HYPER,
+ URLType_STRING,
+ URLType_FLOAT,
+ URLType_DOUBLE,
+ URLType_COUNT
+};
+
+const char* URLTypeNames[URLType_COUNT] =
+{
+ "bool",
+ "byte",
+ "short",
+ "long",
+ "hyper",
+ "string",
+ "float",
+ "double"
+};
+
+SFX_IMPL_XINTERFACE_2( SfxUnoControllerItem, OWeakObject, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
+SFX_IMPL_XTYPEPROVIDER_2( SfxUnoControllerItem, ::com::sun::star::frame::XStatusListener, ::com::sun::star::lang::XEventListener )
+
+SfxUnoControllerItem::SfxUnoControllerItem( SfxControllerItem *pItem, SfxBindings& rBind, const String& rCmd )
+ : pCtrlItem( pItem )
+ , pBindings( &rBind )
+{
+ DBG_ASSERT( !pCtrlItem || !pCtrlItem->IsBound(), "ControllerItem fehlerhaft!" );
+
+ aCommand.Complete = rCmd;
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( aCommand );
+ pBindings->RegisterUnoController_Impl( this );
+}
+
+SfxUnoControllerItem::~SfxUnoControllerItem()
+{
+ // tell bindings to forget this controller ( if still connected )
+ if ( pBindings )
+ pBindings->ReleaseUnoController_Impl( this );
+}
+
+void SfxUnoControllerItem::UnBind()
+{
+ // connection to SfxControllerItem is lost
+ pCtrlItem = NULL;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > aRef( (::cppu::OWeakObject*)this, ::com::sun::star::uno::UNO_QUERY );
+ ReleaseDispatch();
+}
+
+void SAL_CALL SfxUnoControllerItem::statusChanged(const ::com::sun::star::frame::FeatureStateEvent& rEvent) throw ( ::com::sun::star::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ DBG_ASSERT( pCtrlItem, "Dispatch hat den StatusListener nicht entfern!" );
+
+ if ( rEvent.Requery )
+ {
+ // Fehler kann nur passieren, wenn das alte Dispatch fehlerhaft implementiert
+ // ist, also removeStatusListener nicht gefunzt hat. Aber sowas soll
+ // ja vorkommen ...
+ // Also besser vor ReleaseDispatch gegen Abflug sch"utzen!
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > aRef( (::cppu::OWeakObject*)this, ::com::sun::star::uno::UNO_QUERY );
+ ReleaseDispatch();
+ if ( pCtrlItem )
+ GetNewDispatch(); // asynchron ??
+ }
+ else if ( pCtrlItem )
+ {
+ SfxItemState eState = SFX_ITEM_DISABLED;
+ SfxPoolItem* pItem = NULL;
+ if ( rEvent.IsEnabled )
+ {
+ eState = SFX_ITEM_AVAILABLE;
+ ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
+
+ if ( pType == ::getBooleanCppuType() )
+ {
+ sal_Bool bTemp = false;
+ rEvent.State >>= bTemp ;
+ pItem = new SfxBoolItem( pCtrlItem->GetId(), bTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt16*)0) )
+ {
+ sal_uInt16 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ pItem = new SfxUInt16Item( pCtrlItem->GetId(), nTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt32*)0) )
+ {
+ sal_uInt32 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ pItem = new SfxUInt32Item( pCtrlItem->GetId(), nTemp );
+ }
+ else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
+ {
+ ::rtl::OUString sTemp ;
+ rEvent.State >>= sTemp ;
+ pItem = new SfxStringItem( pCtrlItem->GetId(), sTemp );
+ }
+ else
+ pItem = new SfxVoidItem( pCtrlItem->GetId() );
+ }
+
+ pCtrlItem->StateChanged( pCtrlItem->GetId(), eState, pItem );
+ delete pItem;
+ }
+}
+
+void SAL_CALL SfxUnoControllerItem::disposing( const ::com::sun::star::lang::EventObject& ) throw ( ::com::sun::star::uno::RuntimeException )
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > aRef( (::cppu::OWeakObject*)this, ::com::sun::star::uno::UNO_QUERY );
+ ReleaseDispatch();
+}
+
+void SfxUnoControllerItem::ReleaseDispatch()
+{
+ if ( xDispatch.is() )
+ {
+ xDispatch->removeStatusListener( (::com::sun::star::frame::XStatusListener*) this, aCommand );
+ xDispatch = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > ();
+ }
+}
+
+void SfxUnoControllerItem::GetNewDispatch()
+{
+ if ( !pBindings )
+ {
+ // Bindings released
+ DBG_ERROR( "Tried to get dispatch, but no Bindings!" );
+ return;
+ }
+
+ // forget old dispatch
+ xDispatch = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > ();
+
+ // no arms, no cookies !
+ if ( !pBindings->GetDispatcher_Impl() || !pBindings->GetDispatcher_Impl()->GetFrame() )
+ return;
+
+ SfxFrame& rFrame = pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame();
+ SfxFrame *pParent = rFrame.GetParentFrame();
+ if ( pParent )
+ // parent may intercept
+ xDispatch = TryGetDispatch( pParent );
+
+ if ( !xDispatch.is() )
+ {
+ // no interception
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = rFrame.GetFrameInterface();
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > xProv( xFrame, ::com::sun::star::uno::UNO_QUERY );
+ if ( xProv.is() )
+ xDispatch = xProv->queryDispatch( aCommand, ::rtl::OUString(), 0 );
+ }
+
+ if ( xDispatch.is() )
+ xDispatch->addStatusListener( (::com::sun::star::frame::XStatusListener*) this, aCommand );
+ else if ( pCtrlItem )
+ pCtrlItem->StateChanged( pCtrlItem->GetId(), SFX_ITEM_DISABLED, NULL );
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SfxUnoControllerItem::TryGetDispatch( SfxFrame *pFrame )
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp;
+ SfxFrame *pParent = pFrame->GetParentFrame();
+ if ( pParent )
+ // parent may intercept
+ xDisp = TryGetDispatch( pParent );
+
+ // only components may intercept
+ if ( !xDisp.is() && pFrame->HasComponent() )
+ {
+ // no interception
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = pFrame->GetFrameInterface();
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > xProv( xFrame, ::com::sun::star::uno::UNO_QUERY );
+ if ( xProv.is() )
+ xDisp = xProv->queryDispatch( aCommand, ::rtl::OUString(), 0 );
+ }
+
+ return xDisp;
+}
+
+void SfxUnoControllerItem::Execute()
+{
+ // dispatch the resource
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq(1);
+ aSeq[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Referer") );
+ aSeq[0].Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("private:select") );
+ if ( xDispatch.is() )
+ xDispatch->dispatch( aCommand, aSeq );
+}
+
+void SfxUnoControllerItem::ReleaseBindings()
+{
+ // connection to binding is lost; so forget the binding and the dispatch
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > aRef( (::cppu::OWeakObject*)this, ::com::sun::star::uno::UNO_QUERY );
+ ReleaseDispatch();
+ if ( pBindings )
+ pBindings->ReleaseUnoController_Impl( this );
+ pBindings = NULL;
+}
+
+void SfxStatusDispatcher::ReleaseAll()
+{
+ ::com::sun::star::lang::EventObject aObject;
+ aObject.Source = (::cppu::OWeakObject*) this;
+ aListeners.disposeAndClear( aObject );
+}
+
+void SAL_CALL SfxStatusDispatcher::dispatch( const ::com::sun::star::util::URL&, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& ) throw ( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL SfxStatusDispatcher::dispatchWithNotification(
+ const ::com::sun::star::util::URL&,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >&,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& ) throw( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+SFX_IMPL_XINTERFACE_2( SfxStatusDispatcher, OWeakObject, ::com::sun::star::frame::XNotifyingDispatch, ::com::sun::star::frame::XDispatch )
+SFX_IMPL_XTYPEPROVIDER_2( SfxStatusDispatcher, ::com::sun::star::frame::XNotifyingDispatch, ::com::sun::star::frame::XDispatch )
+//IMPLNAME "com.sun.star.comp.sfx2.StatusDispatcher",
+
+SfxStatusDispatcher::SfxStatusDispatcher()
+ : aListeners( aMutex )
+{
+}
+
+void SAL_CALL SfxStatusDispatcher::addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & aListener, const ::com::sun::star::util::URL& aURL) throw ( ::com::sun::star::uno::RuntimeException )
+{
+ aListeners.addInterface( aURL.Complete, aListener );
+ if ( aURL.Complete.compareToAscii(".uno:LifeTime")==0 )
+ {
+ ::com::sun::star::frame::FeatureStateEvent aEvent;
+ aEvent.FeatureURL = aURL;
+ aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
+ aEvent.IsEnabled = sal_True;
+ aEvent.Requery = sal_False;
+ aListener->statusChanged( aEvent );
+ }
+}
+
+void SAL_CALL SfxStatusDispatcher::removeStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & aListener, const ::com::sun::star::util::URL& aURL ) throw ( ::com::sun::star::uno::RuntimeException )
+{
+ aListeners.removeInterface( aURL.Complete, aListener );
+}
+
+SFX_IMPL_XINTERFACE_1( SfxOfficeDispatch, SfxStatusDispatcher, ::com::sun::star::lang::XUnoTunnel )
+SFX_IMPL_XTYPEPROVIDER_2( SfxOfficeDispatch, ::com::sun::star::frame::XNotifyingDispatch, ::com::sun::star::lang::XUnoTunnel )
+
+
+//-------------------------------------------------------------------------
+// XUnoTunnel
+sal_Int64 SAL_CALL SfxOfficeDispatch::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException)
+{
+ if ( aIdentifier == impl_getStaticIdentifier() )
+ return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
+ else
+ return 0;
+}
+
+/* ASDBG
+void* SfxOfficeDispatch::getImplementation(Reflection *p)
+{
+ if( p == ::getCppuType((const SfxOfficeDispatch*)0) )
+ return this;
+ else
+ return ::cppu::OWeakObject::getImplementation(p);
+
+}
+
+Reflection* ::getCppuType((const SfxOfficeDispatch*)0)
+{
+ static StandardClassReflection aRefl(
+ 0,
+ createStandardClass(
+ "SfxOfficeDispatch", ::cppu::OWeakObject::get::cppu::OWeakObjectIdlClass(),
+ 1,
+ ::getCppuType((const ::com::sun::star::frame::XDispatch*)0) ) );
+ return &aRefl;
+}
+*/
+
+SfxOfficeDispatch::SfxOfficeDispatch( SfxBindings& rBindings, SfxDispatcher* pDispat, const SfxSlot* pSlot, const ::com::sun::star::util::URL& rURL )
+{
+// nOfficeDispatchCount++;
+
+ // this object is an adapter that shows a ::com::sun::star::frame::XDispatch-Interface to the outside and uses a SfxControllerItem to monitor a state
+ pControllerItem = new SfxDispatchController_Impl( this, &rBindings, pDispat, pSlot, rURL );
+}
+
+SfxOfficeDispatch::SfxOfficeDispatch( SfxDispatcher* pDispat, const SfxSlot* pSlot, const ::com::sun::star::util::URL& rURL )
+{
+// nOfficeDispatchCount++;
+
+ // this object is an adapter that shows a ::com::sun::star::frame::XDispatch-Interface to the outside and uses a SfxControllerItem to monitor a state
+ pControllerItem = new SfxDispatchController_Impl( this, NULL, pDispat, pSlot, rURL );
+}
+
+SfxOfficeDispatch::~SfxOfficeDispatch()
+{
+// --nOfficeDispatchCount;
+
+ if ( pControllerItem )
+ {
+ // when dispatch object is released, destroy its connection to this object and destroy it
+ pControllerItem->UnBindController();
+ delete pControllerItem;
+ }
+}
+
+const ::com::sun::star::uno::Sequence< sal_Int8 >& SfxOfficeDispatch::impl_getStaticIdentifier()
+{
+ // {38 57 CA 80 09 36 11 d4 83 FE 00 50 04 52 6B 21}
+ static sal_uInt8 pGUID[16] = { 0x38, 0x57, 0xCA, 0x80, 0x09, 0x36, 0x11, 0xd4, 0x83, 0xFE, 0x00, 0x50, 0x04, 0x52, 0x6B, 0x21 };
+ static ::com::sun::star::uno::Sequence< sal_Int8 > seqID((sal_Int8*)pGUID,16) ;
+ return seqID ;
+}
+
+
+void SAL_CALL SfxOfficeDispatch::dispatch( const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) throw ( ::com::sun::star::uno::RuntimeException )
+{
+ // ControllerItem is the Impl class
+ if ( pControllerItem )
+ {
+ // The JavaContext contains an interaction handler which is used when
+ // the creation of a Java Virtual Machine fails. The second parameter
+ // indicates, that there shall only be one user notification (message box)
+ // even if the same error (interaction) reoccurs. The effect is, that if a
+ // user selects a menu entry than they may get only one notification that
+ // a JRE is not selected.
+ com::sun::star::uno::ContextLayer layer(
+ new svt::JavaContext( com::sun::star::uno::getCurrentContext(),
+ true) );
+
+ pControllerItem->dispatch( aURL, aArgs, ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchResultListener >() );
+ }
+}
+
+void SAL_CALL SfxOfficeDispatch::dispatchWithNotification( const ::com::sun::star::util::URL& aURL,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ // ControllerItem is the Impl class
+ if ( pControllerItem )
+ {
+ // see comment for SfxOfficeDispatch::dispatch
+ com::sun::star::uno::ContextLayer layer(
+ new svt::JavaContext( com::sun::star::uno::getCurrentContext(),
+ true) );
+
+ pControllerItem->dispatch( aURL, aArgs, rListener );
+ }
+}
+
+void SAL_CALL SfxOfficeDispatch::addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & aListener, const ::com::sun::star::util::URL& aURL) throw ( ::com::sun::star::uno::RuntimeException )
+{
+ GetListeners().addInterface( aURL.Complete, aListener );
+ if ( pControllerItem )
+ {
+ // ControllerItem is the Impl class
+ pControllerItem->addStatusListener( aListener, aURL );
+ }
+}
+
+SfxDispatcher* SfxOfficeDispatch::GetDispatcher_Impl()
+{
+ return pControllerItem->GetDispatcher();
+}
+
+void SfxOfficeDispatch::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
+{
+ if ( pControllerItem )
+ pControllerItem->SetFrame( xFrame );
+}
+
+void SfxOfficeDispatch::SetMasterUnoCommand( sal_Bool bSet )
+{
+ if ( pControllerItem )
+ pControllerItem->setMasterSlaveCommand( bSet );
+}
+
+sal_Bool SfxOfficeDispatch::IsMasterUnoCommand() const
+{
+ if ( pControllerItem )
+ return pControllerItem->isMasterSlaveCommand();
+ return sal_False;
+}
+
+// Determine if URL contains a master/slave command which must be handled a little bit different
+sal_Bool SfxOfficeDispatch::IsMasterUnoCommand( const ::com::sun::star::util::URL& aURL )
+{
+ if ( aURL.Protocol.equalsAscii( ".uno:" ) &&
+ ( aURL.Path.indexOf( '.' ) > 0 ))
+ return sal_True;
+
+ return sal_False;
+}
+
+rtl::OUString SfxOfficeDispatch::GetMasterUnoCommand( const ::com::sun::star::util::URL& aURL )
+{
+ rtl::OUString aMasterCommand;
+ if ( IsMasterUnoCommand( aURL ))
+ {
+ sal_Int32 nIndex = aURL.Path.indexOf( '.' );
+ if ( nIndex > 0 )
+ aMasterCommand = aURL.Path.copy( 0, nIndex );
+ }
+
+ return aMasterCommand;
+}
+
+SfxDispatchController_Impl::SfxDispatchController_Impl(
+ SfxOfficeDispatch* pDisp,
+ SfxBindings* pBind,
+ SfxDispatcher* pDispat,
+ const SfxSlot* pSlot,
+ const ::com::sun::star::util::URL& rURL )
+ : aDispatchURL( rURL )
+ , pDispatcher( pDispat )
+ , pBindings( pBind )
+ , pLastState( 0 )
+ , nSlot( pSlot->GetSlotId() )
+ , pDispatch( pDisp )
+ , bMasterSlave( sal_False )
+ , bVisible( sal_True )
+ , pUnoName( pSlot->pUnoName )
+{
+ if ( aDispatchURL.Protocol.equalsAscii("slot:") && pUnoName )
+ {
+ ByteString aTmp(".uno:");
+ aTmp += pUnoName;
+ aDispatchURL.Complete = ::rtl::OUString::createFromAscii( aTmp.GetBuffer() );
+ Reference < ::com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( aDispatchURL );
+ }
+
+ SetId( nSlot );
+ if ( pBindings )
+ {
+ // Bind immediately to enable the cache to recycle dispatches when asked for the same command
+ // a command in "slot" or in ".uno" notation must be treated as identical commands!
+ pBindings->ENTERREGISTRATIONS();
+ BindInternal_Impl( nSlot, pBindings );
+ pBindings->LEAVEREGISTRATIONS();
+ }
+}
+
+SfxDispatchController_Impl::~SfxDispatchController_Impl()
+{
+ if ( pLastState && !IsInvalidItem( pLastState ) )
+ delete pLastState;
+
+ if ( pDispatch )
+ {
+ // disconnect
+ pDispatch->pControllerItem = NULL;
+
+ // force all listeners to release the dispatch object
+ ::com::sun::star::lang::EventObject aObject;
+ aObject.Source = (::cppu::OWeakObject*) pDispatch;
+ pDispatch->GetListeners().disposeAndClear( aObject );
+ }
+}
+
+void SfxDispatchController_Impl::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame)
+{
+ xFrame = _xFrame;
+}
+
+void SfxDispatchController_Impl::setMasterSlaveCommand( sal_Bool bSet )
+{
+ bMasterSlave = bSet;
+}
+
+sal_Bool SfxDispatchController_Impl::isMasterSlaveCommand() const
+{
+ return bMasterSlave;
+}
+
+void SfxDispatchController_Impl::UnBindController()
+{
+ pDispatch = NULL;
+ if ( IsBound() )
+ {
+ GetBindings().ENTERREGISTRATIONS();
+ SfxControllerItem::UnBind();
+ GetBindings().LEAVEREGISTRATIONS();
+ }
+}
+
+void SfxDispatchController_Impl::addParametersToArgs( const com::sun::star::util::URL& aURL, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs ) const
+{
+ // Extract the parameter from the URL and put them into the property value sequence
+ sal_Int32 nQueryIndex = aURL.Complete.indexOf( '?' );
+ if ( nQueryIndex > 0 )
+ {
+ rtl::OUString aParamString( aURL.Complete.copy( nQueryIndex+1 ));
+ sal_Int32 nIndex = 0;
+ do
+ {
+ rtl::OUString aToken = aParamString.getToken( 0, '&', nIndex );
+
+ sal_Int32 nParmIndex = 0;
+ rtl::OUString aParamType;
+ rtl::OUString aParamName = aToken.getToken( 0, '=', nParmIndex );
+ rtl::OUString aValue = (nParmIndex!=-1) ? aToken.getToken( 0, '=', nParmIndex ) : ::rtl::OUString();
+
+ if ( aParamName.getLength() > 0 )
+ {
+ nParmIndex = 0;
+ aToken = aParamName;
+ aParamName = (nParmIndex!=-1) ? aToken.getToken( 0, ':', nParmIndex ) : ::rtl::OUString();
+ aParamType = (nParmIndex!=-1) ? aToken.getToken( 0, ':', nParmIndex ) : ::rtl::OUString();
+ }
+
+ sal_Int32 nLen = rArgs.getLength();
+ rArgs.realloc( nLen+1 );
+ rArgs[nLen].Name = aParamName;
+
+ if ( aParamType.getLength() == 0 )
+ {
+ // Default: LONG
+ rArgs[nLen].Value <<= aValue.toInt32();
+ }
+ else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_BOOL], 4 ))
+ {
+ // BOOL support
+ rArgs[nLen].Value <<= aValue.toBoolean();
+ }
+ else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_BYTE], 4 ))
+ {
+ // BYTE support
+ rArgs[nLen].Value <<= sal_Int8( aValue.toInt32() );
+ }
+ else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_LONG], 4 ))
+ {
+ // LONG support
+ rArgs[nLen].Value <<= aValue.toInt32();
+ }
+ else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_SHORT], 5 ))
+ {
+ // SHORT support
+ rArgs[nLen].Value <<= sal_Int8( aValue.toInt32() );
+ }
+ else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_HYPER], 5 ))
+ {
+ // HYPER support
+ rArgs[nLen].Value <<= aValue.toInt64();
+ }
+ else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_FLOAT], 5 ))
+ {
+ // FLOAT support
+ rArgs[nLen].Value <<= aValue.toFloat();
+ }
+ else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_STRING], 6 ))
+ {
+ // STRING support
+ rArgs[nLen].Value <<= rtl::OUString( INetURLObject::decode( aValue, '%', INetURLObject::DECODE_WITH_CHARSET ));
+ }
+ else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_DOUBLE], 6))
+ {
+ // DOUBLE support
+ rArgs[nLen].Value <<= aValue.toDouble();
+ }
+ }
+ while ( nIndex >= 0 );
+ }
+}
+
+SfxMapUnit SfxDispatchController_Impl::GetCoreMetric( SfxItemPool& rPool, sal_uInt16 nSlotId )
+{
+ USHORT nWhich = rPool.GetWhich( nSlotId );
+ return rPool.GetMetric( nWhich );
+}
+
+rtl::OUString SfxDispatchController_Impl::getSlaveCommand( const ::com::sun::star::util::URL& rURL )
+{
+ rtl::OUString aSlaveCommand;
+ sal_Int32 nIndex = rURL.Path.indexOf( '.' );
+ if (( nIndex > 0 ) && ( nIndex < rURL.Path.getLength() ))
+ aSlaveCommand = rURL.Path.copy( nIndex+1 );
+ return aSlaveCommand;
+}
+
+void SAL_CALL SfxDispatchController_Impl::dispatch( const ::com::sun::star::util::URL& aURL,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if (
+ pDispatch &&
+ (
+ (aURL.Protocol.equalsAsciiL( ".uno:", 5 ) && aURL.Path == aDispatchURL.Path) ||
+ (aURL.Protocol.equalsAsciiL( "slot:", 5 ) && aURL.Path.toInt32() == GetId())
+ )
+ )
+ {
+ /*
+ if ( !IsBound() && pBindings )
+ {
+ pBindings->ENTERREGISTRATIONS();
+ BindInternal_Impl( nSlot, pBindings );
+ pBindings->LEAVEREGISTRATIONS();
+ } */
+
+ if ( !pDispatcher && pBindings )
+ pDispatcher = GetBindings().GetDispatcher_Impl();
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lNewArgs;
+ sal_Int32 nCount = aArgs.getLength();
+
+ // Support for URL based arguments
+ INetURLObject aURLObj( aURL.Complete );
+ if ( aURLObj.HasParam() )
+ addParametersToArgs( aURL, lNewArgs );
+
+ // Try to find call mode and frame name inside given arguments...
+ SfxCallMode nCall = SFX_CALLMODE_STANDARD;
+ sal_Int32 nMarkArg = -1;
+
+ // Filter arguments which shouldn't be part of the sequence property value
+ sal_Bool bTemp = sal_Bool();
+ sal_uInt16 nModifier(0);
+ std::vector< ::com::sun::star::beans::PropertyValue > aAddArgs;
+ for( sal_Int32 n=0; n<nCount; n++ )
+ {
+ const ::com::sun::star::beans::PropertyValue& rProp = aArgs[n];
+ if( rProp.Name.equalsAsciiL("SynchronMode",12))
+ {
+ if( rProp.Value >>=bTemp )
+ nCall = bTemp ? SFX_CALLMODE_SYNCHRON : SFX_CALLMODE_ASYNCHRON;
+ }
+ else if( rProp.Name.equalsAsciiL("Bookmark",8))
+ {
+ nMarkArg = n;
+ aAddArgs.push_back( aArgs[n] );
+ }
+ else if( rProp.Name.equalsAsciiL("KeyModifier",11))
+ rProp.Value >>= nModifier;
+ else
+ aAddArgs.push_back( aArgs[n] );
+ }
+
+ // Add needed arguments to sequence property value
+ sal_uInt32 nAddArgs = aAddArgs.size();
+ if ( nAddArgs > 0 )
+ {
+ sal_uInt32 nIndex( lNewArgs.getLength() );
+
+ lNewArgs.realloc( lNewArgs.getLength()+aAddArgs.size() );
+ for ( sal_uInt32 i = 0; i < nAddArgs; i++ )
+ lNewArgs[nIndex++] = aAddArgs[i];
+ }
+
+ // Overwrite possible detected sychron argument, if real listener exists (currently no other way)
+ if ( rListener.is() )
+ nCall = SFX_CALLMODE_SYNCHRON;
+
+ if( GetId() == SID_JUMPTOMARK && nMarkArg == - 1 )
+ {
+ // we offer dispatches for SID_JUMPTOMARK if the URL points to a bookmark inside the document
+ // so we must retrieve this as an argument from the parsed URL
+ lNewArgs.realloc( lNewArgs.getLength()+1 );
+ nMarkArg = lNewArgs.getLength()-1;
+ lNewArgs[nMarkArg].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Bookmark"));
+ lNewArgs[nMarkArg].Value <<= aURL.Mark;
+ }
+
+ css::uno::Reference< css::frame::XFrame > xFrameRef(xFrame.get(), css::uno::UNO_QUERY);
+ if (! xFrameRef.is() && pDispatcher)
+ {
+ SfxViewFrame* pViewFrame = pDispatcher->GetFrame();
+ if (pViewFrame)
+ xFrameRef = pViewFrame->GetFrame().GetFrameInterface();
+ }
+ SfxAllItemSet aInternalSet( SFX_APP()->GetPool() );
+ if (xFrameRef.is()) // an empty set is no problem ... but an empty frame reference can be a problem !
+ aInternalSet.Put( SfxUnoFrameItem( SID_FILLFRAME, xFrameRef ) );
+
+ sal_Bool bSuccess = sal_False;
+ sal_Bool bFailure = sal_False;
+ const SfxPoolItem* pItem = NULL;
+ SfxShell* pShell( 0 );
+ // #i102619# Retrieve metric from shell before execution - the shell could be destroyed after execution
+ SfxMapUnit eMapUnit( SFX_MAPUNIT_100TH_MM );
+ if ( pDispatcher->GetBindings() )
+ {
+ if ( !pDispatcher->IsLocked( GetId() ) )
+ {
+ const SfxSlot *pSlot = 0;
+ if ( pDispatcher->GetShellAndSlot_Impl( GetId(), &pShell, &pSlot, sal_False,
+ SFX_CALLMODE_MODAL==(nCall&SFX_CALLMODE_MODAL), FALSE ) )
+ {
+ if ( bMasterSlave )
+ {
+ // Extract slave command and add argument to the args list. Master slot MUST
+ // have a argument that has the same name as the master slot and type is SfxStringItem.
+ sal_Int32 nIndex = lNewArgs.getLength();
+ lNewArgs.realloc( nIndex+1 );
+ lNewArgs[nIndex].Name = rtl::OUString::createFromAscii( pSlot->pUnoName );
+ lNewArgs[nIndex].Value = makeAny( SfxDispatchController_Impl::getSlaveCommand( aDispatchURL ));
+ }
+
+ eMapUnit = GetCoreMetric( pShell->GetPool(), GetId() );
+ SfxAllItemSet aSet( pShell->GetPool() );
+ TransformParameters( GetId(), lNewArgs, aSet, pSlot );
+ if ( aSet.Count() )
+ {
+ // execute with arguments - call directly
+ pItem = pDispatcher->Execute( GetId(), nCall, &aSet, &aInternalSet, nModifier );
+ bSuccess = (pItem != NULL);
+ }
+ else
+ {
+ // execute using bindings, enables support for toggle/enum etc.
+ SfxRequest aReq( GetId(), nCall, pShell->GetPool() );
+ aReq.SetModifier( nModifier );
+ aReq.SetInternalArgs_Impl(aInternalSet);
+ pDispatcher->GetBindings()->Execute_Impl( aReq, pSlot, pShell );
+ pItem = aReq.GetReturnValue();
+ bSuccess = aReq.IsDone() || pItem != NULL;
+ bFailure = aReq.IsCancelled();
+ }
+ }
+#ifdef DBG_UTIL
+ else
+ DBG_WARNING("MacroPlayer: Unknown slot dispatched!");
+#endif
+ }
+ }
+ else
+ {
+ eMapUnit = GetCoreMetric( SFX_APP()->GetPool(), GetId() );
+ // AppDispatcher
+ SfxAllItemSet aSet( SFX_APP()->GetPool() );
+ TransformParameters( GetId(), lNewArgs, aSet );
+
+ if ( aSet.Count() )
+ pItem = pDispatcher->Execute( GetId(), nCall, &aSet, &aInternalSet, nModifier );
+ else
+ // SfxRequests take empty sets as argument sets, GetArgs() returning non-zero!
+ pItem = pDispatcher->Execute( GetId(), nCall, 0, &aInternalSet, nModifier );
+
+ // no bindings, no invalidate ( usually done in SfxDispatcher::Call_Impl()! )
+ if ( SfxApplication::Get() )
+ {
+ SfxDispatcher* pAppDispat = SFX_APP()->GetAppDispatcher_Impl();
+ if ( pAppDispat )
+ {
+ const SfxPoolItem* pState=0;
+ SfxItemState eState = pDispatcher->QueryState( GetId(), pState );
+ StateChanged( GetId(), eState, pState );
+ }
+ }
+
+ bSuccess = (pItem != NULL);
+ }
+
+ if ( rListener.is() )
+ {
+ ::com::sun::star::frame::DispatchResultEvent aEvent;
+ if ( bSuccess )
+ aEvent.State = com::sun::star::frame::DispatchResultState::SUCCESS;
+// else if ( bFailure )
+ else
+ aEvent.State = com::sun::star::frame::DispatchResultState::FAILURE;
+// else
+// aEvent.State = com::sun::star::frame::DispatchResultState::DONTKNOW;
+
+ aEvent.Source = (::com::sun::star::frame::XDispatch*) pDispatch;
+ if ( bSuccess && pItem && !pItem->ISA(SfxVoidItem) )
+ {
+ USHORT nSubId( 0 );
+ if ( eMapUnit == SFX_MAPUNIT_TWIP )
+ nSubId |= CONVERT_TWIPS;
+ pItem->QueryValue( aEvent.Result, (BYTE)nSubId );
+ }
+
+ rListener->dispatchFinished( aEvent );
+ }
+ }
+}
+
+SfxDispatcher* SfxDispatchController_Impl::GetDispatcher()
+{
+ if ( !pDispatcher && pBindings )
+ pDispatcher = GetBindings().GetDispatcher_Impl();
+ return pDispatcher;
+}
+
+void SAL_CALL SfxDispatchController_Impl::addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & aListener, const ::com::sun::star::util::URL& aURL) throw ( ::com::sun::star::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( !pDispatch )
+ return;
+
+ /*if ( !IsBound() && pBindings )
+ {
+ pBindings->ENTERREGISTRATIONS();
+ BindInternal_Impl( nSlot, pBindings );
+ pBindings->LEAVEREGISTRATIONS();
+ } */
+
+ // Use alternative QueryState call to have a valid UNO representation of the state.
+ ::com::sun::star::uno::Any aState;
+ if ( !pDispatcher && pBindings )
+ pDispatcher = GetBindings().GetDispatcher_Impl();
+ SfxItemState eState = pDispatcher->QueryState( GetId(), aState );
+
+ if ( eState == SFX_ITEM_DONTCARE )
+ {
+ // Use special uno struct to transport don't care state
+ ::com::sun::star::frame::status::ItemStatus aItemStatus;
+ aItemStatus.State = ::com::sun::star::frame::status::ItemState::dont_care;
+ aState = makeAny( aItemStatus );
+ }
+
+ ::com::sun::star::frame::FeatureStateEvent aEvent;
+ aEvent.FeatureURL = aURL;
+ aEvent.Source = (::com::sun::star::frame::XDispatch*) pDispatch;
+ aEvent.Requery = sal_False;
+ if ( bVisible )
+ {
+ aEvent.IsEnabled = eState != SFX_ITEM_DISABLED;
+ aEvent.State = aState;
+ }
+ else
+ {
+ ::com::sun::star::frame::status::Visibility aVisibilityStatus;
+ aVisibilityStatus.bVisible = sal_False;
+
+ // MBA: we might decide to *not* disable "invisible" slots, but this would be
+ // a change that needs to adjust at least the testtool
+ aEvent.IsEnabled = sal_False;
+ aEvent.State = makeAny( aVisibilityStatus );
+ }
+
+ aListener->statusChanged( aEvent );
+}
+
+void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState, SfxSlotServer* pSlotServ )
+{
+ if ( !pDispatch )
+ return;
+
+ // Bindings instance notifies controller about a state change, listeners must be notified also
+ // Don't cache visibility state changes as they are volatile. We need our real state to send it
+ // to our controllers after visibility is set to true.
+ sal_Bool bNotify = sal_True;
+ if ( pState && !IsInvalidItem( pState ) )
+ {
+ if ( !pState->ISA( SfxVisibilityItem ) )
+ {
+ sal_Bool bBothAvailable = pLastState && !IsInvalidItem(pLastState);
+ if ( bBothAvailable )
+ bNotify = pState->Type() != pLastState->Type() || *pState != *pLastState;
+ if ( pLastState && !IsInvalidItem( pLastState ) )
+ delete pLastState;
+ pLastState = !IsInvalidItem(pState) ? pState->Clone() : pState;
+ bVisible = sal_True;
+ }
+ else
+ bVisible = ((SfxVisibilityItem *)pState)->GetValue();
+ }
+ else
+ {
+ if ( pLastState && !IsInvalidItem( pLastState ) )
+ delete pLastState;
+ pLastState = pState;
+ }
+
+ ::cppu::OInterfaceContainerHelper* pContnr = pDispatch->GetListeners().getContainer ( aDispatchURL.Complete );
+ if ( bNotify && pContnr )
+ {
+ ::com::sun::star::uno::Any aState;
+ if ( ( eState >= SFX_ITEM_AVAILABLE ) && pState && !IsInvalidItem( pState ) && !pState->ISA(SfxVoidItem) )
+ {
+ // Retrieve metric from pool to have correct sub ID when calling QueryValue
+ USHORT nSubId( 0 );
+ SfxMapUnit eMapUnit( SFX_MAPUNIT_100TH_MM );
+
+ // retrieve the core metric
+ // it's enough to check the objectshell, the only shell that does not use the pool of the document
+ // is SfxViewFrame, but it hasn't any metric parameters
+ // TODO/LATER: what about the FormShell? Does it use any metric data?! Perhaps it should use the Pool of the document!
+ if ( pSlotServ && pDispatcher )
+ {
+ SfxShell* pShell = pDispatcher->GetShell( pSlotServ->GetShellLevel() );
+ DBG_ASSERT( pShell, "Can't get core metric without shell!" );
+ if ( pShell )
+ eMapUnit = GetCoreMetric( pShell->GetPool(), nSID );
+ }
+
+ if ( eMapUnit == SFX_MAPUNIT_TWIP )
+ nSubId |= CONVERT_TWIPS;
+
+ pState->QueryValue( aState, (BYTE)nSubId );
+ }
+ else if ( eState == SFX_ITEM_DONTCARE )
+ {
+ // Use special uno struct to transport don't care state
+ ::com::sun::star::frame::status::ItemStatus aItemStatus;
+ aItemStatus.State = ::com::sun::star::frame::status::ItemState::dont_care;
+ aState = makeAny( aItemStatus );
+ }
+
+ ::com::sun::star::frame::FeatureStateEvent aEvent;
+ aEvent.FeatureURL = aDispatchURL;
+ aEvent.Source = (::com::sun::star::frame::XDispatch*) pDispatch;
+ aEvent.IsEnabled = eState != SFX_ITEM_DISABLED;
+ aEvent.Requery = sal_False;
+ aEvent.State = aState;
+
+ ::cppu::OInterfaceIteratorHelper aIt( *pContnr );
+ while( aIt.hasMoreElements() )
+ {
+ try
+ {
+ ((::com::sun::star::frame::XStatusListener *)aIt.next())->statusChanged( aEvent );
+ }
+ catch( ::com::sun::star::uno::RuntimeException& )
+ {
+ aIt.remove();
+ }
+ }
+ }
+}
+
+void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
+{
+ StateChanged( nSID, eState, pState, 0 );
+}
diff --git a/sfx2/source/dialog/about.cxx b/sfx2/source/dialog/about.cxx
new file mode 100644
index 000000000000..ea7b0a2bb0bd
--- /dev/null
+++ b/sfx2/source/dialog/about.cxx
@@ -0,0 +1,423 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// include ---------------------------------------------------------------
+
+#ifndef _SV_APP_HXX
+#include <vcl/svapp.hxx>
+#endif
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#ifndef GCC
+#endif
+
+#include <tools/stream.hxx>
+#include <tools/urlobj.hxx>
+#include <rtl/bootstrap.hxx>
+#include <unotools/configmgr.hxx>
+#include <unotools/bootstrap.hxx>
+#include <com/sun/star/uno/Any.h>
+#include <unotools/configmgr.hxx>
+#include <vcl/graph.hxx>
+#include <svtools/filter.hxx>
+
+#include <sfx2/sfxuno.hxx>
+#include "about.hxx"
+#include "sfxresid.hxx"
+#include <sfx2/sfxdefs.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/sfxcommands.h>
+#include "dialog.hrc"
+
+// defines ---------------------------------------------------------------
+
+#define SCROLL_OFFSET 1
+#define SPACE_OFFSET 5
+#define SCROLL_TIMER 30
+
+#define WELCOME_URL DEFINE_CONST_UNICODE( "http://www.openoffice.org/welcome/credits.html" )
+
+// class AboutDialog -----------------------------------------------------
+static void layoutText( FixedInfo &rText, long &nY, long nTextWidth, Size a6Size )
+{
+ Point aTextPos = rText.GetPosPixel();
+ aTextPos.X() = a6Size.Width() * 2;
+ aTextPos.Y() = nY;
+ rText.SetPosPixel( aTextPos );
+
+ Size aTxtSiz = rText.GetSizePixel();
+ aTxtSiz.Width() = nTextWidth;
+ Size aCalcSize = rText.CalcMinimumSize( nTextWidth );
+ aTxtSiz.Height() = aCalcSize.Height();
+ rText.SetSizePixel( aTxtSiz );
+
+ nY += aTxtSiz.Height();
+}
+
+static bool impl_loadBitmap(
+ const rtl::OUString &rPath, const rtl::OUString &rBmpFileName,
+ Image &rLogo )
+{
+ rtl::OUString uri( rPath );
+ rtl::Bootstrap::expandMacros( uri );
+ INetURLObject aObj( uri );
+ aObj.insertName( rBmpFileName );
+ SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
+ if ( !aStrm.GetError() )
+ {
+ // Use graphic class to also support more graphic formats (bmp,png,...)
+ Graphic aGraphic;
+
+ GraphicFilter* pGF = GraphicFilter::GetGraphicFilter();
+ pGF->ImportGraphic( aGraphic, String(), aStrm, GRFILTER_FORMAT_DONTKNOW );
+
+ // Default case, we load the intro bitmap from a seperate file
+ // (e.g. staroffice_intro.bmp or starsuite_intro.bmp)
+ BitmapEx aBmp = aGraphic.GetBitmapEx();
+ rLogo = Image( aBmp );
+ return true;
+ }
+ return false;
+}
+
+/** loads the application logo as used in the about dialog and impress slideshow pause screen */
+Image SfxApplication::GetApplicationLogo()
+{
+ Image aAppLogo;
+
+ rtl::OUString aAbouts;
+ bool bLoaded = false;
+ sal_Int32 nIndex = 0;
+ do
+ {
+ bLoaded = impl_loadBitmap(
+ rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
+ aAbouts.getToken( 0, ',', nIndex ), aAppLogo );
+ }
+ while ( !bLoaded && ( nIndex >= 0 ) );
+
+ // fallback to "about.bmp"
+ if ( !bLoaded )
+ {
+ bLoaded = impl_loadBitmap(
+ rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program/edition" ),
+ rtl::OUString::createFromAscii( "about.png" ), aAppLogo );
+ if ( !bLoaded )
+ bLoaded = impl_loadBitmap(
+ rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program/edition" ),
+ rtl::OUString::createFromAscii( "about.bmp" ), aAppLogo );
+ }
+
+ if ( !bLoaded )
+ {
+ bLoaded = impl_loadBitmap(
+ rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
+ rtl::OUString::createFromAscii( "about.png" ), aAppLogo );
+ if ( !bLoaded )
+ bLoaded = impl_loadBitmap(
+ rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
+ rtl::OUString::createFromAscii( "about.bmp" ), aAppLogo );
+ }
+
+ return aAppLogo;
+}
+
+AboutDialog::AboutDialog( Window* pParent, const ResId& rId, const String& rVerStr ) :
+
+ SfxModalDialog ( pParent, rId ),
+
+ aOKButton ( this, ResId( ABOUT_BTN_OK, *rId.GetResMgr() ) ),
+ aVersionText ( this, ResId( ABOUT_FTXT_VERSION, *rId.GetResMgr() ) ),
+ aCopyrightText ( this, ResId( ABOUT_FTXT_COPYRIGHT, *rId.GetResMgr() ) ),
+ aBuildData ( this ),
+ aDeveloperAry ( ResId( ABOUT_STR_DEVELOPER_ARY, *rId.GetResMgr() ) ),
+ aDevVersionStr ( rVerStr ),
+ aAccelStr ( ResId( ABOUT_STR_ACCEL, *rId.GetResMgr() ) ),
+ aCopyrightTextStr( ResId( ABOUT_STR_COPYRIGHT, *rId.GetResMgr() ) ),
+ aTimer (),
+ nOff ( 0 ),
+ m_nDeltaWidth ( 0 ),
+ m_nPendingScrolls( 0 ),
+ bNormal ( TRUE )
+{
+ rtl::OUString sProduct;
+ utl::ConfigManager::GetDirectConfigProperty(utl::ConfigManager::PRODUCTNAME) >>= sProduct;
+
+ // load image from module path
+ aAppLogo = SfxApplication::GetApplicationLogo();
+
+ // Transparenter Font
+ Font aFont = GetFont();
+ aFont.SetTransparent( TRUE );
+ SetFont( aFont );
+
+ // if necessary more info
+ String sVersion = aVersionText.GetText();
+ sVersion.SearchAndReplaceAscii( "$(VER)", Application::GetDisplayName() );
+ sVersion += '\n';
+ sVersion += rVerStr;
+ aVersionText.SetText( sVersion );
+
+ // Initialisierung fuer Aufruf Entwickler
+ if ( aAccelStr.Len() && ByteString(U2S(aAccelStr)).IsAlphaAscii() )
+ {
+ Accelerator *pAccel = 0, *pPrevAccel = 0, *pFirstAccel = 0;
+ aAccelStr.ToUpperAscii();
+
+ for ( USHORT i = 0; i < aAccelStr.Len(); ++i )
+ {
+ pPrevAccel = pAccel;
+ pAccel = new Accelerator;
+ aAccelList.Insert( pAccel, LIST_APPEND );
+ USHORT nKey = aAccelStr.GetChar(i) - 'A' + KEY_A;
+ pAccel->InsertItem( 1, KeyCode( nKey, KEY_MOD1 ) );
+ if ( i > 0 )
+ pPrevAccel->SetAccel( 1, pAccel );
+ if ( i == 0 )
+ pFirstAccel = pAccel;
+ }
+ pAccel->SetSelectHdl( LINK( this, AboutDialog, AccelSelectHdl ) );
+ GetpApp()->InsertAccel( pFirstAccel );
+ }
+
+ // set for background and text the correct system color
+ const StyleSettings& rSettings = GetSettings().GetStyleSettings();
+ Color aWhiteCol( rSettings.GetWindowColor() );
+ Wallpaper aWall( aWhiteCol );
+ SetBackground( aWall );
+ Font aNewFont( aCopyrightText.GetFont() );
+ aNewFont.SetTransparent( TRUE );
+
+ aVersionText.SetFont( aNewFont );
+ aCopyrightText.SetFont( aNewFont );
+
+ aVersionText.SetBackground();
+ aCopyrightText.SetBackground();
+
+ Color aTextColor( rSettings.GetWindowTextColor() );
+ aVersionText.SetControlForeground( aTextColor );
+ aCopyrightText.SetControlForeground( aTextColor );
+ aBuildData.SetBackground( aWall );
+
+ Font aSmallFont = rSettings.GetInfoFont();
+ Size aSmaller = aNewFont.GetSize();
+ aSmaller.Width() = (long) (aSmaller.Width() * 0.75);
+ aSmaller.Height() = (long) (aSmaller.Height() * 0.75);
+ aNewFont.SetSize( aSmaller );
+ aBuildData.SetFont( aNewFont );
+ aBuildData.SetBackground( aWall );
+#ifdef BUILD_VER_STRING
+ String aBuildString( DEFINE_CONST_UNICODE( BUILD_VER_STRING ) );
+#else
+ String aBuildString;
+#endif
+ aBuildData.SetText( aBuildString );
+ aBuildData.Show();
+
+ // determine size and position of the dialog & elements
+ Size aAppLogoSiz = aAppLogo.GetSizePixel();
+ Size aOutSiz = GetOutputSizePixel();
+ aOutSiz.Width() = aAppLogoSiz.Width();
+
+ Size a6Size = aVersionText.LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
+ long nY = aAppLogoSiz.Height() + ( a6Size.Height() * 2 );
+ long nDlgMargin = a6Size.Width() * 4 ;
+ long nCtrlMargin = a6Size.Height() * 2;
+ long nTextWidth = aOutSiz.Width() - nDlgMargin;
+
+ aCopyrightText.SetText( aCopyrightTextStr );
+
+ layoutText( aVersionText, nY, nTextWidth, a6Size );
+ nY += nCtrlMargin;
+
+ // OK-Button-Position (at the bottom and centered)
+ Size aOKSiz = aOKButton.GetSizePixel();
+ Point aOKPnt = aOKButton.GetPosPixel();
+
+ // Multiline edit with Copyright-Text
+ Point aCopyPnt = aCopyrightText.GetPosPixel();
+ Size aCopySize = aCopyrightText.GetSizePixel();
+ aCopySize.Width() = nTextWidth;
+ aCopySize.Height() = aOutSiz.Height() - nY - ( aOKSiz.Height() * 2 ) - nCtrlMargin;
+
+ aCopyPnt.X() = ( aOutSiz.Width() - aCopySize.Width() ) / 2;
+ aCopyPnt.Y() = nY;
+ aCopyrightText.SetPosSizePixel( aCopyPnt, aCopySize );
+
+ nY += aCopySize.Height() + nCtrlMargin;
+ aOKPnt.X() = ( aOutSiz.Width() - aOKSiz.Width() ) / 2;
+ aOKPnt.Y() = nY;
+ aOKButton.SetPosPixel( aOKPnt );
+
+ // Change the width of the dialog
+ SetOutputSizePixel( aOutSiz );
+
+ FreeResource();
+
+ SetHelpId( CMD_SID_ABOUT );
+}
+
+// -----------------------------------------------------------------------
+
+AboutDialog::~AboutDialog()
+{
+ // L"oschen des Entwickleraufrufs
+ if ( aAccelList.Count() )
+ {
+ GetpApp()->RemoveAccel( aAccelList.First() );
+ Accelerator* pAccel = aAccelList.Last();
+
+ while ( pAccel )
+ {
+ delete pAccel;
+ pAccel = aAccelList.Prev();
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( AboutDialog, TimerHdl, Timer *, pTimer )
+{
+ (void)pTimer; //unused
+ ++m_nPendingScrolls;
+ Invalidate( INVALIDATE_NOERASE | INVALIDATE_NOCHILDREN );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( AboutDialog, AccelSelectHdl, Accelerator *, pAccelerator )
+{
+#ifdef YURI_DARIO
+ aCopyrightText.SetHelpText( DEFINE_CONST_UNICODE("Conoscere qualcuno ovunque egli sia, con cui comprendersi nonostante le distanze\n"
+ "e le differenze, puo' trasformare la terra in un giardino. baci Valeria") );
+#endif
+
+ (void)pAccelerator; //unused
+ // init Timer
+ aTimer.SetTimeoutHdl( LINK( this, AboutDialog, TimerHdl ) );
+
+ // init scroll mode
+ nOff = GetOutputSizePixel().Height();
+ MapMode aMapMode( MAP_PIXEL );
+ SetMapMode( aMapMode );
+ bNormal = FALSE;
+
+ // start scroll Timer
+ aTimer.SetTimeout( SCROLL_TIMER );
+ aTimer.Start();
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL AboutDialog::Close()
+{
+ // stop Timer and finish the dialog
+ aTimer.Stop();
+ EndDialog( RET_OK );
+ return( FALSE );
+}
+
+// -----------------------------------------------------------------------
+
+void AboutDialog::Paint( const Rectangle& rRect )
+{
+ SetClipRegion( rRect );
+
+ if ( bNormal ) // not in scroll mode
+ {
+ Point aPos( m_nDeltaWidth / 2, 0 );
+ DrawImage( aPos, aAppLogo );
+ return;
+ }
+
+ // scroll the content
+ const int nDeltaY = -SCROLL_OFFSET * m_nPendingScrolls;
+ if( !nDeltaY )
+ return;
+ nOff += nDeltaY;
+ Scroll( 0, nDeltaY, SCROLL_NOERASE );
+ m_nPendingScrolls = 0;
+
+ // draw the credits text
+ const Font aOrigFont = GetFont();
+ const int nFullWidth = GetOutputSizePixel().Width();
+
+ int nY = nOff;
+ const int nDevCnt = static_cast<int>( aDeveloperAry.Count() );
+ for( int i = 0; i < nDevCnt; ++i )
+ {
+ if( nY >= rRect.Bottom() )
+ break;
+
+ int nPos2 = nY + GetTextHeight() + 3;
+ if( nPos2 >= rRect.Top() + nDeltaY )
+ {
+ const String aStr = aDeveloperAry.GetString(i);
+ const long nVal = aDeveloperAry.GetValue(i);
+
+ if ( nVal )
+ {
+ // emphasize the headers
+ Font aFont = aOrigFont;
+ aFont.SetWeight( (FontWeight)nVal );
+ SetFont( aFont );
+ nPos2 = nY + GetTextHeight() + 3;
+ }
+
+ // clear text background
+ Rectangle aEraseRect( Point(0,nY), Size( nFullWidth, nPos2-nY));
+ Erase( aEraseRect );
+
+ // draw centered text
+ const long nTextWidth = GetTextWidth( aStr );
+ long nX = (nFullWidth - 5 - nTextWidth) / 2;
+ if( nX < 0 )
+ nX = SPACE_OFFSET;
+ const Point aPnt( nX, nY );
+ DrawText( aPnt, aStr );
+
+ // restore the font if needed
+ if( nVal )
+ SetFont( aOrigFont );
+ }
+ nY = nPos2;
+ }
+
+ // close dialog if the whole text has been scrolled
+ if ( nY <= 0 )
+ {
+ bNormal = TRUE;
+ Close();
+ }
+}
diff --git a/sfx2/source/dialog/alienwarn.cxx b/sfx2/source/dialog/alienwarn.cxx
new file mode 100644
index 000000000000..13a0433b7be5
--- /dev/null
+++ b/sfx2/source/dialog/alienwarn.cxx
@@ -0,0 +1,177 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "alienwarn.hxx"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/sfxuno.hxx>
+
+#include "alienwarn.hrc"
+#include "dialog.hrc"
+#include <vcl/msgbox.hxx>
+#include <unotools/saveopt.hxx>
+
+// class SfxAlienWarningDialog -------------------------------------------
+
+SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :
+
+ SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),
+
+ m_aKeepCurrentBtn ( this, SfxResId( PB_NO ) ),
+ m_aSaveODFBtn ( this, SfxResId( PB_YES ) ),
+ m_aMoreInfoBtn ( this, SfxResId( PB_MOREINFO ) ),
+ m_aOptionLine ( this, SfxResId( FL_OPTION ) ),
+ m_aWarningOnBox ( this, SfxResId( CB_WARNING_OFF ) ),
+ m_aQueryImage ( this, SfxResId( FI_QUERY ) ),
+ m_aInfoText ( this, SfxResId( FT_INFOTEXT ) )
+
+{
+ FreeResource();
+
+ // set questionmark image
+ m_aQueryImage.SetImage( QueryBox::GetStandardImage() );
+
+ // replace formatname
+ String sInfoText = m_aInfoText.GetText();
+ sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
+ m_aInfoText.SetText( sInfoText );
+
+ // load value of "warning on" checkbox from save options
+ m_aWarningOnBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_True );
+
+ // set focus to "Keep Current Format" button
+ m_aKeepCurrentBtn.GrabFocus();
+
+ // pb: #i43989# we have no online help for this dialog at the moment
+ // -> hide the "more info" button
+ //m_aMoreInfoBtn.Hide();
+
+ // calculate and set the size of the dialog and its controls
+ InitSize();
+}
+
+// -----------------------------------------------------------------------
+
+SfxAlienWarningDialog::~SfxAlienWarningDialog()
+{
+ // save value of "warning off" checkbox, if necessary
+ SvtSaveOptions aSaveOpt;
+ sal_Bool bChecked = m_aWarningOnBox.IsChecked();
+ if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
+ aSaveOpt.SetWarnAlienFormat( bChecked );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxAlienWarningDialog::InitSize()
+{
+ // if the button text is too wide, then broaden the button
+ long nTxtW = m_aMoreInfoBtn.GetCtrlTextWidth( m_aMoreInfoBtn.GetText() );
+ long nCtrlW = m_aMoreInfoBtn.GetSizePixel().Width();
+ if ( nTxtW >= nCtrlW )
+ {
+ long nDelta = nTxtW - nCtrlW;
+ nDelta += IMPL_EXTRA_BUTTON_WIDTH;
+ Point aNextPoint = m_aKeepCurrentBtn.GetPosPixel();
+ aNextPoint.X() += m_aKeepCurrentBtn.GetSizePixel().Width();
+ Point aNewPoint = m_aMoreInfoBtn.GetPosPixel();
+ aNewPoint.X() -= nDelta;
+ if ( aNextPoint.X() >= aNewPoint.X() )
+ {
+ long nSpace = aNextPoint.X() - aNewPoint.X();
+ nSpace += 2;
+ nDelta -= nSpace;
+ aNewPoint.X() += nSpace;
+ }
+ Size aNewSize = m_aMoreInfoBtn.GetSizePixel();
+ aNewSize.Width() += nDelta;
+ m_aMoreInfoBtn.SetPosSizePixel( aNewPoint, aNewSize );
+ }
+
+ // text of checkbox to wide -> add new line
+ nTxtW = m_aWarningOnBox.GetCtrlTextWidth( m_aWarningOnBox.GetText() ) + IMPL_EXTRA_BUTTON_WIDTH;
+ nCtrlW = m_aWarningOnBox.GetSizePixel().Width();
+ if ( nTxtW >= nCtrlW )
+ {
+ long nTextHeight = m_aWarningOnBox.GetTextHeight();
+ Size aNewSize = m_aWarningOnBox.GetSizePixel();
+ aNewSize.Height() += nTextHeight;
+ m_aWarningOnBox.SetSizePixel( aNewSize );
+ aNewSize = GetSizePixel();
+ aNewSize.Height() += nTextHeight;
+ SetSizePixel( aNewSize );
+ }
+
+ // align the size of the information text control (FixedText) to its content
+ Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
+ long nTxtH = aMinSize.Height();
+ long nCtrlH = m_aInfoText.GetSizePixel().Height();
+ long nDelta = ( nCtrlH - nTxtH );
+ Size aNewSize = m_aInfoText.GetSizePixel();
+ aNewSize.Height() -= nDelta;
+ m_aInfoText.SetSizePixel( aNewSize );
+
+ // new position for the succeeding windows
+ Window* pWins[] =
+ {
+ &m_aSaveODFBtn, &m_aKeepCurrentBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOnBox
+ };
+ Window** pCurrent = pWins;
+ for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
+ {
+ Point aNewPos = (*pCurrent)->GetPosPixel();
+ aNewPos.Y() -= nDelta;
+ (*pCurrent)->SetPosPixel( aNewPos );
+ }
+
+ // new size of the dialog
+ aNewSize = GetSizePixel();
+ aNewSize.Height() -= nDelta;
+ SetSizePixel( aNewSize );
+
+ // recalculate the size and position of the buttons
+ m_aMoreInfoBtn.Hide();
+ nTxtW = m_aKeepCurrentBtn.GetCtrlTextWidth( m_aKeepCurrentBtn.GetText() );
+ long nTemp = m_aSaveODFBtn.GetCtrlTextWidth( m_aSaveODFBtn.GetText() );
+ if ( nTemp > nTxtW )
+ nTxtW = nTemp;
+ nTxtW += IMPL_EXTRA_BUTTON_WIDTH;
+ Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
+ Point aPos = m_aKeepCurrentBtn.GetPosPixel();
+ aPos.X() = ( aNewSize.Width() - (2*nTxtW) - a3Size.Width() ) / 2;
+ long nDefX = m_aWarningOnBox.GetPosPixel().X();
+ if ( nDefX < aPos.X() )
+ aPos.X() = nDefX;
+ aNewSize = m_aKeepCurrentBtn.GetSizePixel();
+ aNewSize.Width() = nTxtW;
+ m_aKeepCurrentBtn.SetPosSizePixel( aPos, aNewSize );
+ aPos.X() += nTxtW + a3Size.Width();
+ m_aSaveODFBtn.SetPosSizePixel( aPos, aNewSize );
+}
+
diff --git a/sfx2/source/dialog/alienwarn.hrc b/sfx2/source/dialog/alienwarn.hrc
new file mode 100644
index 000000000000..e3a23dc57836
--- /dev/null
+++ b/sfx2/source/dialog/alienwarn.hrc
@@ -0,0 +1,61 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_ALIENWARN_HRC
+#define _SFX_ALIENWARN_HRC
+
+#include <svtools/controldims.hrc>
+
+// dialog ids
+
+#define FI_QUERY 10
+#define FT_INFOTEXT 11
+#define PB_YES 12
+#define PB_NO 13
+#define PB_MOREINFO 14
+#define FL_OPTION 15
+#define CB_WARNING_OFF 16
+
+// --------- general metrics ---------
+
+#define SYMBOL_EDGE 20
+#define DIALOG_WIDTH 220
+#define INFO_TEXT_LINES 11
+
+#define AW_COL_1 (RSC_SP_DLG_INNERBORDER_LEFT)
+#define AW_COL_2 (AW_COL_1+SYMBOL_EDGE+RSC_SP_CTRL_DESC_X)
+#define AW_COL_3 (AW_COL_2+RSC_CD_PUSHBUTTON_WIDTH+RSC_SP_CTRL_DESC_X)
+#define AW_COL_4 (DIALOG_WIDTH-RSC_SP_DLG_INNERBORDER_RIGHT-RSC_CD_PUSHBUTTON_WIDTH)
+
+#define AW_ROW_1 (RSC_SP_DLG_INNERBORDER_TOP)
+#define AW_ROW_2 (AW_ROW_1+INFO_TEXT_LINES*RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_CTRL_Y)
+#define AW_ROW_3 (AW_ROW_2+RSC_CD_PUSHBUTTON_HEIGHT+RSC_SP_CTRL_DESC_Y)
+#define AW_ROW_4 (AW_ROW_3+RSC_CD_FIXEDLINE_HEIGHT+RSC_SP_CTRL_DESC_Y)
+
+#define DIALOG_HEIGHT (AW_ROW_4+RSC_CD_CHECKBOX_HEIGHT+RSC_SP_DLG_INNERBORDER_BOTTOM)
+
+#endif
+
diff --git a/sfx2/source/dialog/alienwarn.src b/sfx2/source/dialog/alienwarn.src
new file mode 100644
index 000000000000..ae07b28a4f4d
--- /dev/null
+++ b/sfx2/source/dialog/alienwarn.src
@@ -0,0 +1,92 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "alienwarn.hrc"
+#include "dialog.hrc"
+#include "helpid.hrc"
+
+ModalDialog RID_DLG_ALIEN_WARNING
+{
+ HelpId = HID_WARNING_ALIENFORMAT;
+ Size = MAP_APPFONT( DIALOG_WIDTH, DIALOG_HEIGHT );
+ OutputSize = TRUE;
+ Closeable = FALSE;
+ Moveable = TRUE;
+ SVLook = TRUE;
+
+ Text = "%PRODUCTNAME %PRODUCTVERSION %PRODUCTEXTENSION";
+
+ FixedImage FI_QUERY
+ {
+ Pos = MAP_APPFONT( AW_COL_1, AW_ROW_1 );
+ Size = MAP_APPFONT( SYMBOL_EDGE, SYMBOL_EDGE );
+ };
+ FixedText FT_INFOTEXT
+ {
+ Pos = MAP_APPFONT( AW_COL_2, AW_ROW_1 );
+ Size = MAP_APPFONT( DIALOG_WIDTH-AW_COL_2-RSC_SP_DLG_INNERBORDER_RIGHT, INFO_TEXT_LINES*RSC_CD_FIXEDTEXT_HEIGHT );
+ NoLabel = TRUE;
+ Wordbreak = TRUE;
+ Text [ en-US-old ] = "This document may contain formatting or content that cannot be saved in the %FORMATNAME file format. Do you want to save the document in this format anyway?\n\n- Click 'Yes' to save in %FORMATNAME file format.\n- Click 'No' to use the latest OpenDocument file format and be sure all formatting and content is saved correctly.";
+ Text [ en-US ] = "This document may contain formatting or content that cannot be saved in the %FORMATNAME file format. Do you want to save the document in this format anyway?\n\nUse the latest ODF file format and be sure all formatting and content is saved correctly.";
+ };
+ OKButton PB_NO
+ {
+ Pos = MAP_APPFONT( AW_COL_2, AW_ROW_2 );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ DefButton = TRUE ;
+ Text [ en-US ] = "~Keep Current Format";
+ };
+ CancelButton PB_YES
+ {
+ Pos = MAP_APPFONT( AW_COL_3, AW_ROW_2 );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ Text [ en-US ] = "~Save in ODF Format";
+ };
+ HelpButton PB_MOREINFO
+ {
+ Pos = MAP_APPFONT( AW_COL_4, AW_ROW_2 );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ Hide = TRUE ;
+ Text [ en-US ] = "~More Information...";
+ };
+ FixedLine FL_OPTION
+ {
+ Pos = MAP_APPFONT( 0, AW_ROW_3 );
+ Size = MAP_APPFONT( DIALOG_WIDTH, RSC_CD_FIXEDLINE_HEIGHT );
+ };
+ CheckBox CB_WARNING_OFF
+ {
+ HelpID = "sfx2:CheckBox:RID_DLG_ALIEN_WARNING:CB_WARNING_OFF";
+ Pos = MAP_APPFONT( AW_COL_2, AW_ROW_4 );
+ Size = MAP_APPFONT( DIALOG_WIDTH-AW_COL_2-RSC_SP_DLG_INNERBORDER_RIGHT, RSC_CD_CHECKBOX_HEIGHT );
+ WordBreak = TRUE ;
+ Text [ en-US ] = "~Ask when not saving in ODF format";
+ };
+};
+
+
diff --git a/sfx2/source/dialog/basedlgs.cxx b/sfx2/source/dialog/basedlgs.cxx
new file mode 100644
index 000000000000..5a7f8a1fd900
--- /dev/null
+++ b/sfx2/source/dialog/basedlgs.cxx
@@ -0,0 +1,1059 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// include ---------------------------------------------------------------
+
+#include <stdlib.h>
+#include <vcl/fixed.hxx>
+#include <vcl/help.hxx>
+#include <vcl/msgbox.hxx>
+#include <svl/eitem.hxx>
+#include <unotools/viewoptions.hxx>
+#include <svtools/fixedhyper.hxx>
+#include <svtools/controldims.hrc>
+
+#include <sfx2/basedlgs.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/tabdlg.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/childwin.hxx>
+#include <sfx2/viewsh.hxx>
+#include "sfx2/sfxhelp.hxx"
+#include "workwin.hxx"
+#include "sfx2/sfxresid.hxx"
+#include "dialog.hrc"
+
+using namespace ::com::sun::star::uno;
+using namespace ::rtl;
+
+#define USERITEM_NAME OUString::createFromAscii( "UserItem" )
+
+class SfxModelessDialog_Impl : public SfxListener
+{
+public:
+ ByteString aWinState;
+ SfxChildWindow* pMgr;
+ BOOL bConstructed;
+ void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
+
+ Timer aMoveTimer;
+};
+
+void SfxModelessDialog_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
+{
+ if ( rHint.IsA(TYPE(SfxSimpleHint)) )
+ {
+ switch( ( (SfxSimpleHint&) rHint ).GetId() )
+ {
+ case SFX_HINT_DYING:
+ pMgr->Destroy();
+ break;
+ }
+ }
+}
+
+class SfxFloatingWindow_Impl : public SfxListener
+{
+public:
+ ByteString aWinState;
+ SfxChildWindow* pMgr;
+ BOOL bConstructed;
+ Timer aMoveTimer;
+
+ void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
+};
+
+void SfxFloatingWindow_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
+{
+ if ( rHint.IsA(TYPE(SfxSimpleHint)) )
+ {
+ switch( ( (SfxSimpleHint&) rHint ).GetId() )
+ {
+ case SFX_HINT_DYING:
+ pMgr->Destroy();
+ break;
+ }
+ }
+}
+
+// class SfxModalDefParentHelper -----------------------------------------
+
+SfxModalDefParentHelper::SfxModalDefParentHelper( Window *pWindow)
+{
+ pOld = Application::GetDefDialogParent();
+ Application::SetDefDialogParent( pWindow );
+}
+
+// -----------------------------------------------------------------------
+
+SfxModalDefParentHelper::~SfxModalDefParentHelper()
+{
+ Application::SetDefDialogParent( pOld );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxModalDialog::SetDialogData_Impl()
+{
+ // save settings (position and user data)
+ SvtViewOptions aDlgOpt( E_DIALOG, String::CreateFromInt32( nUniqId ) );
+ aDlgOpt.SetWindowState(
+ OUString::createFromAscii( GetWindowState( WINDOWSTATE_MASK_POS ).GetBuffer() ) );
+ if ( aExtraData.Len() )
+ aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aExtraData ) ) );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxModalDialog::GetDialogData_Impl()
+
+/* [Beschreibung]
+
+ Hilfsfunktion; liest die Dialogposition aus der Ini-Datei
+ und setzt diese am "ubergebenen Window.
+*/
+
+{
+ SvtViewOptions aDlgOpt( E_DIALOG, String::CreateFromInt32( nUniqId ) );
+ if ( aDlgOpt.Exists() )
+ {
+ // load settings
+ SetWindowState( ByteString( aDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US ) );
+ Any aUserItem = aDlgOpt.GetUserItem( USERITEM_NAME );
+ OUString aTemp;
+ if ( aUserItem >>= aTemp )
+ aExtraData = String( aTemp );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxModalDialog::init()
+{
+ GetDialogData_Impl();
+}
+
+// -----------------------------------------------------------------------
+
+SfxModalDialog::SfxModalDialog(Window* pParent, const ResId &rResId )
+
+/* [Beschreibung]
+
+ Konstruktor der allgemeinen Basisklasse f"ur modale Dialoge;
+ ResId wird als ID im ini-file verwendet.
+ Die dort gespeicherte Position wird gesetzt.
+*/
+
+: ModalDialog(pParent, rResId),
+ nUniqId(rResId.GetId()),
+ pInputSet(0),
+ pOutputSet(0)
+{
+ init();
+}
+
+// -----------------------------------------------------------------------
+
+SfxModalDialog::SfxModalDialog(Window* pParent,
+ sal_uInt32 nUniqueId,
+ WinBits nWinStyle) :
+/* [Beschreibung]
+
+ Konstruktor der allgemeinen Basisklasse f"ur modale Dialoge;
+ ID f"ur das ini-file wird explizit "ubergeben.
+ Die dort gespeicherte Position wird gesetzt.
+*/
+
+ ModalDialog(pParent, nWinStyle),
+ nUniqId(nUniqueId),
+ pInputSet(0),
+ pOutputSet(0)
+{
+ init();
+}
+
+// -----------------------------------------------------------------------
+
+SfxModalDialog::~SfxModalDialog()
+
+/* [Beschreibung]
+
+ Dtor; schreibt Dialogposition in das ini-file
+*/
+
+{
+ SetDialogData_Impl();
+ delete pOutputSet;
+}
+
+void SfxModalDialog::CreateOutputItemSet( SfxItemPool& rPool )
+{
+ DBG_ASSERT( !pOutputSet, "Double creation of OutputSet!" );
+ if (!pOutputSet)
+ pOutputSet = new SfxAllItemSet( rPool );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxModalDialog::CreateOutputItemSet( const SfxItemSet& rSet )
+{
+ DBG_ASSERT( !pOutputSet, "Double creation of OutputSet!" );
+ if (!pOutputSet)
+ {
+ pOutputSet = new SfxItemSet( rSet );
+ pOutputSet->ClearItem();
+ }
+}
+
+//-------------------------------------------------------------------------
+void SfxModelessDialog::StateChanged( StateChangedType nStateChange )
+{
+ if ( nStateChange == STATE_CHANGE_INITSHOW )
+ {
+ if ( pImp->aWinState.Len() )
+ {
+ SetWindowState( pImp->aWinState );
+ }
+ else
+ {
+ Point aPos = GetPosPixel();
+ if ( !aPos.X() )
+ {
+ aSize = GetSizePixel();
+
+ Size aParentSize = GetParent()->GetOutputSizePixel();
+ Size aDlgSize = GetSizePixel();
+ aPos.X() += ( aParentSize.Width() - aDlgSize.Width() ) / 2;
+ aPos.Y() += ( aParentSize.Height() - aDlgSize.Height() ) / 2;
+
+ Point aPoint;
+ Rectangle aRect = GetDesktopRectPixel();
+ aPoint.X() = aRect.Right() - aDlgSize.Width();
+ aPoint.Y() = aRect.Bottom() - aDlgSize.Height();
+
+ aPoint = OutputToScreenPixel( aPoint );
+
+ if ( aPos.X() > aPoint.X() )
+ aPos.X() = aPoint.X() ;
+ if ( aPos.Y() > aPoint.Y() )
+ aPos.Y() = aPoint.Y();
+
+ if ( aPos.X() < 0 ) aPos.X() = 0;
+ if ( aPos.Y() < 0 ) aPos.Y() = 0;
+
+ SetPosPixel( aPos );
+ }
+ }
+
+ pImp->bConstructed = TRUE;
+ }
+
+ ModelessDialog::StateChanged( nStateChange );
+}
+
+void SfxModelessDialog::Initialize(SfxChildWinInfo *pInfo)
+
+/* [Beschreibung]
+
+ Initialisierung der Klasse SfxModelessDialog "uber ein SfxChildWinInfo.
+ Die Initialisierung erfolgt erst in einem 2.Schritt
+ nach dem ctor und sollte vom ctor der abgeleiteten Klasse
+ oder von dem des SfxChildWindows aufgerufen werden.
+*/
+
+{
+ pImp->aWinState = pInfo->aWinState;
+}
+
+void SfxModelessDialog::Resize()
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode der Klasse FloatingWindow merkt sich ggf. eine
+ ver"anderte Gr"o\se.
+ Wird diese Methode von einer abgeleiteten Klasse "uberschrieben, mu\s
+ auch SfxFloatingWindow::Resize() gerufen werden.
+*/
+
+{
+ ModelessDialog::Resize();
+ if ( pImp->bConstructed && pImp->pMgr )
+ {
+ // start timer for saving window status information
+ pImp->aMoveTimer.Start();
+ }
+}
+
+void SfxModelessDialog::Move()
+{
+ ModelessDialog::Move();
+ if ( pImp->bConstructed && pImp->pMgr && IsReallyVisible() )
+ {
+ // start timer for saving window status information
+ pImp->aMoveTimer.Start();
+ }
+}
+
+/*
+ Implements a timer event that is triggered by a move or resize of the window
+ This will save config information to Views.xcu with a small delay
+*/
+IMPL_LINK( SfxModelessDialog, TimerHdl, Timer*, EMPTYARG)
+{
+ pImp->aMoveTimer.Stop();
+ if ( pImp->bConstructed && pImp->pMgr )
+ {
+ if ( !IsRollUp() )
+ aSize = GetSizePixel();
+ ULONG nMask = WINDOWSTATE_MASK_POS | WINDOWSTATE_MASK_STATE;
+ if ( GetStyle() & WB_SIZEABLE )
+ nMask |= ( WINDOWSTATE_MASK_WIDTH | WINDOWSTATE_MASK_HEIGHT );
+ pImp->aWinState = GetWindowState( nMask );
+ GetBindings().GetWorkWindow_Impl()->ConfigChild_Impl( SFX_CHILDWIN_DOCKINGWINDOW, SFX_ALIGNDOCKINGWINDOW, pImp->pMgr->GetType() );
+ }
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+SfxModelessDialog::SfxModelessDialog( SfxBindings *pBindinx,
+ SfxChildWindow *pCW,
+ Window* pParent, WinBits nWinBits ) :
+ ModelessDialog (pParent, nWinBits),
+ pBindings(pBindinx),
+ pImp( new SfxModelessDialog_Impl )
+{
+ pImp->pMgr = pCW;
+ pImp->bConstructed = FALSE;
+ SetUniqueId( GetHelpId() );
+ SetHelpId("");
+ if ( pBindinx )
+ pImp->StartListening( *pBindinx );
+ pImp->aMoveTimer.SetTimeout(50);
+ pImp->aMoveTimer.SetTimeoutHdl(LINK(this,SfxModelessDialog,TimerHdl));
+}
+
+// -----------------------------------------------------------------------
+
+SfxModelessDialog::SfxModelessDialog( SfxBindings *pBindinx,
+ SfxChildWindow *pCW, Window *pParent,
+ const ResId& rResId ) :
+ ModelessDialog(pParent, rResId),
+ pBindings(pBindinx),
+ pImp( new SfxModelessDialog_Impl )
+{
+ pImp->pMgr = pCW;
+ pImp->bConstructed = FALSE;
+ SetUniqueId( GetHelpId() );
+ SetHelpId("");
+ if ( pBindinx )
+ pImp->StartListening( *pBindinx );
+ pImp->aMoveTimer.SetTimeout(50);
+ pImp->aMoveTimer.SetTimeoutHdl(LINK(this,SfxModelessDialog,TimerHdl));
+}
+
+// -----------------------------------------------------------------------
+
+long SfxModelessDialog::Notify( NotifyEvent& rEvt )
+
+/* [Beschreibung]
+
+ Wenn ein ModelessDialog aktiviert wird, wird sein ViewFrame aktiviert.
+ Notwendig ist das bei PlugInFrames.
+*/
+
+{
+ if ( rEvt.GetType() == EVENT_GETFOCUS )
+ {
+ pBindings->SetActiveFrame( pImp->pMgr->GetFrame() );
+ pImp->pMgr->Activate_Impl();
+ Window* pWindow = rEvt.GetWindow();
+ rtl::OString sHelpId;
+ while ( !sHelpId.getLength() && pWindow )
+ {
+ sHelpId = pWindow->GetHelpId();
+ pWindow = pWindow->GetParent();
+ }
+
+ if ( sHelpId.getLength() )
+ SfxHelp::OpenHelpAgent( &pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame(), sHelpId );
+ }
+ else if ( rEvt.GetType() == EVENT_LOSEFOCUS && !HasChildPathFocus() )
+ {
+ pBindings->SetActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () );
+ pImp->pMgr->Deactivate_Impl();
+ }
+ else if( rEvt.GetType() == EVENT_KEYINPUT )
+ {
+ // KeyInput zuerst f"ur Dialogfunktionen zulassen ( TAB etc. )
+ if ( !ModelessDialog::Notify( rEvt ) && SfxViewShell::Current() )
+ // dann auch global g"ultige Acceleratoren verwenden
+ return SfxViewShell::Current()->GlobalKeyInput_Impl( *rEvt.GetKeyEvent() );
+ return sal_True;
+ }
+
+ return ModelessDialog::Notify( rEvt );
+}
+
+// -----------------------------------------------------------------------
+
+SfxModelessDialog::~SfxModelessDialog()
+
+/* [Beschreibung]
+
+ Dtor
+*/
+
+{
+ if ( pImp->pMgr->GetFrame().is() && pImp->pMgr->GetFrame() == pBindings->GetActiveFrame() )
+ pBindings->SetActiveFrame( NULL );
+ delete pImp;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxModelessDialog::Close()
+
+/* [Beschreibung]
+
+ Das Fenster wird geschlossen, indem das ChildWindow durch Ausf"uhren des
+ ChildWindow-Slots zerst"ort wird.
+ Wird diese Methode von einer abgeleiteten Klasse "uberschrieben, mu\s
+ danach SfxModelessDialogWindow::Close() gerufen werden, wenn nicht das
+ Close() mit "return sal_False" abgebrochen wird.
+
+*/
+
+{
+ // Execute mit Parametern, da Toggle von einigen ChildWindows ignoriert
+ // werden kann
+ SfxBoolItem aValue( pImp->pMgr->GetType(), sal_False);
+ pBindings->GetDispatcher_Impl()->Execute(
+ pImp->pMgr->GetType(),
+ SFX_CALLMODE_RECORD|SFX_CALLMODE_SYNCHRON, &aValue, 0L );
+ return sal_True;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxModelessDialog::FillInfo(SfxChildWinInfo& rInfo) const
+
+/* [Beschreibung]
+
+ F"ullt ein SfxChildWinInfo mit f"ur SfxModelessDialof spezifischen Daten,
+ damit sie in die INI-Datei geschrieben werden koennen.
+ Es wird angenommen, da\s rInfo alle anderen evt. relevanten Daten in
+ der ChildWindow-Klasse erh"alt.
+ ModelessDialogs haben keine spezifischen Informationen, so dass die
+ Basisimplementierung nichts tut und daher nicht gerufen werden mu\s.
+*/
+
+{
+ rInfo.aSize = aSize;
+ if ( IsRollUp() )
+ rInfo.nFlags |= SFX_CHILDWIN_ZOOMIN;
+}
+
+// -----------------------------------------------------------------------
+
+long SfxFloatingWindow::Notify( NotifyEvent& rEvt )
+
+/* [Beschreibung]
+
+ Wenn ein ModelessDialog aktiviert wird, wird sein ViewFrame aktiviert.
+ Notwendig ist das bei PlugInFrames.
+*/
+
+{
+ if ( rEvt.GetType() == EVENT_GETFOCUS )
+ {
+ pBindings->SetActiveFrame( pImp->pMgr->GetFrame() );
+ pImp->pMgr->Activate_Impl();
+ Window* pWindow = rEvt.GetWindow();
+ rtl::OString sHelpId;
+ while ( !sHelpId.getLength() && pWindow )
+ {
+ sHelpId = pWindow->GetHelpId();
+ pWindow = pWindow->GetParent();
+ }
+
+ if ( sHelpId.getLength() )
+ SfxHelp::OpenHelpAgent( &pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame(), sHelpId );
+ }
+ else if ( rEvt.GetType() == EVENT_LOSEFOCUS )
+ {
+ if ( !HasChildPathFocus() )
+ {
+ pBindings->SetActiveFrame( NULL );
+ pImp->pMgr->Deactivate_Impl();
+ }
+ }
+ else if( rEvt.GetType() == EVENT_KEYINPUT )
+ {
+ // KeyInput zuerst f"ur Dialogfunktionen zulassen
+ if ( !FloatingWindow::Notify( rEvt ) && SfxViewShell::Current() )
+ // dann auch global g"ultige Acceleratoren verwenden
+ return SfxViewShell::Current()->GlobalKeyInput_Impl( *rEvt.GetKeyEvent() );
+ return sal_True;
+ }
+
+ return FloatingWindow::Notify( rEvt );
+}
+
+// -----------------------------------------------------------------------
+
+SfxFloatingWindow::SfxFloatingWindow( SfxBindings *pBindinx,
+ SfxChildWindow *pCW,
+ Window* pParent, WinBits nWinBits) :
+ FloatingWindow (pParent, nWinBits),
+ pBindings(pBindinx),
+ pImp( new SfxFloatingWindow_Impl )
+{
+ pImp->pMgr = pCW;
+ pImp->bConstructed = FALSE;
+ SetUniqueId( GetHelpId() );
+ SetHelpId("");
+ if ( pBindinx )
+ pImp->StartListening( *pBindinx );
+ pImp->aMoveTimer.SetTimeout(50);
+ pImp->aMoveTimer.SetTimeoutHdl(LINK(this,SfxFloatingWindow,TimerHdl));
+}
+
+// -----------------------------------------------------------------------
+
+SfxFloatingWindow::SfxFloatingWindow( SfxBindings *pBindinx,
+ SfxChildWindow *pCW,
+ Window* pParent,
+ const ResId& rResId) :
+ FloatingWindow(pParent, rResId),
+ pBindings(pBindinx),
+ pImp( new SfxFloatingWindow_Impl )
+{
+ pImp->pMgr = pCW;
+ pImp->bConstructed = FALSE;
+ SetUniqueId( GetHelpId() );
+ SetHelpId("");
+ if ( pBindinx )
+ pImp->StartListening( *pBindinx );
+ pImp->aMoveTimer.SetTimeout(50);
+ pImp->aMoveTimer.SetTimeoutHdl(LINK(this,SfxFloatingWindow,TimerHdl));
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxFloatingWindow::Close()
+
+/* [Beschreibung]
+
+ Das Fenster wird geschlossen, indem das ChildWindow durch Ausf"uhren des
+ ChildWindow-Slots zerst"ort wird.
+ Wird diese Methode von einer abgeleiteten Klasse "uberschrieben, mu\s
+ danach SfxFloatingWindow::Close() gerufen werden, wenn nicht das Close()
+ mit "return sal_False" abgebrochen wird.
+
+*/
+
+{
+ // Execute mit Parametern, da Toggle von einigen ChildWindows ignoriert
+ // werden kann
+ SfxBoolItem aValue( pImp->pMgr->GetType(), sal_False);
+ pBindings->GetDispatcher_Impl()->Execute(
+ pImp->pMgr->GetType(),
+ SFX_CALLMODE_RECORD|SFX_CALLMODE_SYNCHRON, &aValue, 0L );
+ return sal_True;
+}
+
+// -----------------------------------------------------------------------
+
+SfxFloatingWindow::~SfxFloatingWindow()
+
+/* [Beschreibung]
+
+ Dtor
+*/
+
+{
+ if ( pImp->pMgr->GetFrame() == pBindings->GetActiveFrame() )
+ pBindings->SetActiveFrame( NULL );
+ delete pImp;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxFloatingWindow::Resize()
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode der Klasse FloatingWindow merkt sich ggf. eine
+ ver"anderte Gr"o\se.
+ Wird diese Methode von einer abgeleiteten Klasse "uberschrieben, mu\s
+ auch SfxFloatingWindow::Resize() gerufen werden.
+*/
+
+{
+ FloatingWindow::Resize();
+ if ( pImp->bConstructed && pImp->pMgr )
+ {
+ // start timer for saving window status information
+ pImp->aMoveTimer.Start();
+ }
+}
+
+void SfxFloatingWindow::Move()
+{
+ FloatingWindow::Move();
+ if ( pImp->bConstructed && pImp->pMgr )
+ {
+ // start timer for saving window status information
+ pImp->aMoveTimer.Start();
+ }
+}
+
+/*
+ Implements a timer event that is triggered by a move or resize of the window
+ This will save config information to Views.xcu with a small delay
+*/
+IMPL_LINK( SfxFloatingWindow, TimerHdl, Timer*, EMPTYARG)
+{
+ pImp->aMoveTimer.Stop();
+ if ( pImp->bConstructed && pImp->pMgr )
+ {
+ if ( !IsRollUp() )
+ aSize = GetSizePixel();
+ ULONG nMask = WINDOWSTATE_MASK_POS | WINDOWSTATE_MASK_STATE;
+ if ( GetStyle() & WB_SIZEABLE )
+ nMask |= ( WINDOWSTATE_MASK_WIDTH | WINDOWSTATE_MASK_HEIGHT );
+ pImp->aWinState = GetWindowState( nMask );
+ GetBindings().GetWorkWindow_Impl()->ConfigChild_Impl( SFX_CHILDWIN_DOCKINGWINDOW, SFX_ALIGNDOCKINGWINDOW, pImp->pMgr->GetType() );
+ }
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+void SfxFloatingWindow::StateChanged( StateChangedType nStateChange )
+{
+ if ( nStateChange == STATE_CHANGE_INITSHOW )
+ {
+ // FloatingWindows are not centered by default
+ if ( pImp->aWinState.Len() )
+ SetWindowState( pImp->aWinState );
+ pImp->bConstructed = TRUE;
+ }
+
+ FloatingWindow::StateChanged( nStateChange );
+}
+
+
+void SfxFloatingWindow::Initialize(SfxChildWinInfo *pInfo)
+
+/* [Beschreibung]
+
+ Initialisierung der Klasse SfxFloatingWindow "uber ein SfxChildWinInfo.
+ Die Initialisierung erfolgt erst in einem 2.Schritt
+ nach dem ctor und sollte vom ctor der abgeleiteten Klasse
+ oder von dem des SfxChildWindows aufgerufen werden.
+*/
+{
+ pImp->aWinState = pInfo->aWinState;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxFloatingWindow::FillInfo(SfxChildWinInfo& rInfo) const
+
+/* [Beschreibung]
+
+ F"ullt ein SfxChildWinInfo mit f"ur SfxFloatingWindow spezifischen Daten,
+ damit sie in die INI-Datei geschrieben werden koennen.
+ Es wird angenommen, da\s rInfo alle anderen evt. relevanten Daten in
+ der ChildWindow-Klasse erh"alt.
+ Eingetragen werden hier gemerkte Gr"o\se und das ZoomIn-Flag.
+ Wird diese Methode "uberschrieben, mu\s zuerst die Basisimplementierung
+ gerufen werden.
+*/
+
+{
+ rInfo.aSize = aSize;
+ if ( IsRollUp() )
+ rInfo.nFlags |= SFX_CHILDWIN_ZOOMIN;
+}
+
+// SfxSingleTabDialog ----------------------------------------------------
+
+IMPL_LINK( SfxSingleTabDialog, OKHdl_Impl, Button *, EMPTYARG )
+
+/* [Beschreibung]
+
+ Ok_Handler; f"ur die gesetzte Page wird FillItemSet() gerufen.
+*/
+
+{
+ if ( !GetInputItemSet() )
+ {
+ // TabPage without ItemSet
+ EndDialog( RET_OK );
+ return 1;
+ }
+
+ if ( !GetOutputItemSet() )
+ {
+ CreateOutputItemSet( *GetInputItemSet() );
+ }
+ sal_Bool bModified = sal_False;
+
+ if ( pImpl->m_pSfxPage->HasExchangeSupport() )
+ {
+ int nRet = pImpl->m_pSfxPage->DeactivatePage( GetOutputSetImpl() );
+ if ( nRet != SfxTabPage::LEAVE_PAGE )
+ return 0;
+ else
+ bModified = ( GetOutputItemSet()->Count() > 0 );
+ }
+ else
+ bModified = pImpl->m_pSfxPage->FillItemSet( *GetOutputSetImpl() );
+
+ if ( bModified )
+ {
+ // auch noch schnell User-Daten im IniManager abspeichern
+ pImpl->m_pSfxPage->FillUserData();
+ String sData( pImpl->m_pSfxPage->GetUserData() );
+ SvtViewOptions aPageOpt( E_TABPAGE, String::CreateFromInt32( GetUniqId() ) );
+ aPageOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( sData ) ) );
+ EndDialog( RET_OK );
+ }
+ else
+ EndDialog( RET_CANCEL );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+SfxSingleTabDialog::SfxSingleTabDialog
+(
+ Window *pParent,
+ const SfxItemSet& rSet,
+ sal_uInt16 nUniqueId
+) :
+
+/* [Beschreibung]
+
+ Konstruktor der allgemeinen Basisklasse f"ur SingleTab-Dialoge;
+ ID f"ur das ini-file wird "ubergeben.
+*/
+
+ SfxModalDialog( pParent, nUniqueId, WinBits( WB_STDMODAL | WB_3DLOOK ) ),
+
+ pOKBtn ( 0 ),
+ pCancelBtn ( 0 ),
+ pHelpBtn ( 0 ),
+ pImpl ( new SingleTabDlgImpl )
+{
+ DBG_WARNING( "please use the ctor with ViewFrame" );
+ SetInputSet( &rSet );
+}
+
+// -----------------------------------------------------------------------
+
+SfxSingleTabDialog::SfxSingleTabDialog
+(
+ Window* pParent,
+ sal_uInt16 nUniqueId,
+ const SfxItemSet* pInSet
+)
+
+/* [Beschreibung]
+
+ Konstruktor der allgemeinen Basisklasse f"ur SingleTab-Dialoge;
+ ID f"ur das ini-file wird "ubergeben.
+ Sollte nicht mehr benutzt werden.
+ */
+
+: SfxModalDialog( pParent, nUniqueId, WinBits( WB_STDMODAL | WB_3DLOOK ) ),
+
+ pOKBtn ( 0 ),
+ pCancelBtn ( 0 ),
+ pHelpBtn ( 0 ),
+ pImpl ( new SingleTabDlgImpl )
+{
+ DBG_WARNING( "bitte den Ctor mit ViewFrame verwenden" );
+ SetInputSet( pInSet );
+}
+
+// -----------------------------------------------------------------------
+
+SfxSingleTabDialog::SfxSingleTabDialog
+(
+ Window* pParent,
+ sal_uInt16 nUniqueId,
+ const String& rInfoURL
+)
+
+/* [Beschreibung]
+
+ Konstruktor der allgemeinen Basisklasse f"ur SingleTab-Dialoge;
+ ID f"ur das ini-file wird "ubergeben.
+ */
+
+: SfxModalDialog( pParent, nUniqueId, WinBits( WB_STDMODAL | WB_3DLOOK ) ),
+
+ pOKBtn ( NULL ),
+ pCancelBtn ( NULL ),
+ pHelpBtn ( NULL ),
+ pImpl ( new SingleTabDlgImpl )
+{
+ pImpl->m_sInfoURL = rInfoURL;
+}
+
+// -----------------------------------------------------------------------
+
+SfxSingleTabDialog::~SfxSingleTabDialog()
+{
+ delete pOKBtn;
+ delete pCancelBtn;
+ delete pHelpBtn;
+ delete pImpl->m_pTabPage;
+ delete pImpl->m_pSfxPage;
+ delete pImpl->m_pLine;
+ delete pImpl->m_pInfoImage;
+ delete pImpl;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxSingleTabDialog::SetPage( TabPage* pNewPage )
+{
+ if ( !pImpl->m_pLine )
+ pImpl->m_pLine = new FixedLine( this );
+
+ if ( !pOKBtn )
+ {
+ pOKBtn = new OKButton( this, WB_DEFBUTTON );
+ pOKBtn->SetClickHdl( LINK( this, SfxSingleTabDialog, OKHdl_Impl ) );
+ }
+
+ if ( pImpl->m_sInfoURL.Len() > 0 && !pImpl->m_pInfoImage )
+ {
+ pImpl->m_pInfoImage = new ::svt::FixedHyperlinkImage( this );
+ Image aInfoImage = Image( SfxResId( IMG_INFO ) );
+ Size aImageSize = aInfoImage.GetSizePixel();
+ aImageSize.Width() += 4;
+ aImageSize.Height() += 4;
+ pImpl->m_pInfoImage->SetSizePixel( aImageSize );
+ pImpl->m_pInfoImage->SetImage( aInfoImage );
+ pImpl->m_pInfoImage->SetURL( pImpl->m_sInfoURL );
+ pImpl->m_pInfoImage->SetClickHdl( pImpl->m_aInfoLink );
+ }
+
+ if ( pImpl->m_pTabPage )
+ delete pImpl->m_pTabPage;
+ if ( pImpl->m_pSfxPage )
+ delete pImpl->m_pSfxPage;
+ pImpl->m_pTabPage = pNewPage;
+
+ if ( pImpl->m_pTabPage )
+ {
+ // Gr"ossen und Positionen anpassen
+ pImpl->m_pTabPage->SetPosPixel( Point() );
+ Size aOutSz( pImpl->m_pTabPage->GetSizePixel() );
+ Size aOffSz = LogicToPixel( Size( RSC_SP_CTRL_X, RSC_SP_CTRL_Y ), MAP_APPFONT );
+ Size aFLSz = LogicToPixel( Size( aOutSz.Width(), RSC_CD_FIXEDLINE_HEIGHT ) );
+ Size aBtnSz = LogicToPixel( Size( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ), MAP_APPFONT );
+
+ Point aPnt( 0, aOutSz.Height() );
+ pImpl->m_pLine->SetPosSizePixel( aPnt, aFLSz );
+ aPnt.X() = aOutSz.Width() - aOffSz.Width() - aBtnSz.Width();
+ aPnt.Y() += aFLSz.Height() + ( aOffSz.Height() / 2 );
+ pOKBtn->SetPosSizePixel( aPnt, aBtnSz );
+
+ if ( pImpl->m_pInfoImage )
+ {
+ aPnt.X() = aOffSz.Width();
+ long nDelta = ( pImpl->m_pInfoImage->GetSizePixel().Height() - aBtnSz.Height() ) / 2;
+ aPnt.Y() -= nDelta;
+ pImpl->m_pInfoImage->SetPosPixel( aPnt );
+ pImpl->m_pInfoImage->Show();
+ }
+
+ aOutSz.Height() += aFLSz.Height() + ( aOffSz.Height() / 2 ) + aBtnSz.Height() + aOffSz.Height();
+ SetOutputSizePixel( aOutSz );
+
+ pImpl->m_pLine->Show();
+ pOKBtn->Show();
+ pImpl->m_pTabPage->Show();
+
+ // Text der TabPage in den Dialog setzen
+ SetText( pImpl->m_pTabPage->GetText() );
+
+ // Dialog bekommt HelpId der TabPage
+ SetHelpId( pImpl->m_pTabPage->GetHelpId() );
+ SetUniqueId( pImpl->m_pTabPage->GetUniqueId() );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxSingleTabDialog::SetTabPage( SfxTabPage* pTabPage,
+ GetTabPageRanges pRangesFunc )
+/* [Beschreibung]
+
+ Setzen einer (neuen) TabPage; eine bereits vorhandene Page
+ wird gel"oscht.
+ Die "ubergebene Page wird durch Aufruf von Reset() mit dem
+ initial "ubergebenen Itemset initialisiert.
+*/
+
+{
+ if ( !pOKBtn )
+ {
+ pOKBtn = new OKButton( this, WB_DEFBUTTON );
+ pOKBtn->SetClickHdl( LINK( this, SfxSingleTabDialog, OKHdl_Impl ) );
+ }
+ if ( !pCancelBtn )
+ pCancelBtn = new CancelButton( this );
+ if ( !pHelpBtn )
+ pHelpBtn = new HelpButton( this );
+
+ if ( pImpl->m_pTabPage )
+ delete pImpl->m_pTabPage;
+ if ( pImpl->m_pSfxPage )
+ delete pImpl->m_pSfxPage;
+ pImpl->m_pSfxPage = pTabPage;
+ fnGetRanges = pRangesFunc;
+
+ if ( pImpl->m_pSfxPage )
+ {
+ // erstmal die User-Daten besorgen, dann erst Reset()
+ SvtViewOptions aPageOpt( E_TABPAGE, String::CreateFromInt32( GetUniqId() ) );
+ String sUserData;
+ Any aUserItem = aPageOpt.GetUserItem( USERITEM_NAME );
+ OUString aTemp;
+ if ( aUserItem >>= aTemp )
+ sUserData = String( aTemp );
+ pImpl->m_pSfxPage->SetUserData( sUserData );
+ pImpl->m_pSfxPage->Reset( *GetInputItemSet() );
+ pImpl->m_pSfxPage->Show();
+
+ // Gr"ossen und Positionen anpassen
+ pImpl->m_pSfxPage->SetPosPixel( Point() );
+ Size aOutSz( pImpl->m_pSfxPage->GetSizePixel() );
+ Size aBtnSiz = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
+ Point aPnt( aOutSz.Width(), LogicToPixel( Point( 0, 6 ), MAP_APPFONT ).Y() );
+ aOutSz.Width() += aBtnSiz.Width() + LogicToPixel( Size( 6, 0 ), MAP_APPFONT ).Width();
+ SetOutputSizePixel( aOutSz );
+ pOKBtn->SetPosSizePixel( aPnt, aBtnSiz );
+ pOKBtn->Show();
+ aPnt.Y() = LogicToPixel( Point( 0, 23 ), MAP_APPFONT ).Y();
+ pCancelBtn->SetPosSizePixel( aPnt, aBtnSiz );
+ pCancelBtn->Show();
+ aPnt.Y() = LogicToPixel( Point( 0, 43 ), MAP_APPFONT ).Y();
+ pHelpBtn->SetPosSizePixel( aPnt, aBtnSiz );
+
+ if ( Help::IsContextHelpEnabled() )
+ pHelpBtn->Show();
+
+ // Text der TabPage in den Dialog setzen
+ SetText( pImpl->m_pSfxPage->GetText() );
+
+ // Dialog bekommt HelpId der TabPage
+ SetHelpId( pImpl->m_pSfxPage->GetHelpId() );
+ SetUniqueId( pImpl->m_pSfxPage->GetUniqueId() );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxSingleTabDialog::SetInfoLink( const Link& rLink )
+{
+ pImpl->m_aInfoLink = rLink;
+}
+
+//--------------------------------------------------------------------
+// Vergleichsfunktion fuer qsort
+
+#ifdef WNT
+int __cdecl BaseDlgsCmpUS_Impl( const void* p1, const void* p2 )
+#else
+#if defined(OS2) && defined(ICC)
+int _Optlink BaseDlgsCmpUS_Impl( const void* p1, const void* p2 )
+#else
+extern "C" int BaseDlgsCmpUS_Impl( const void* p1, const void* p2 )
+#endif
+#endif
+{
+ return *(sal_uInt16*)p1 - *(sal_uInt16*)p2;
+}
+
+// -----------------------------------------------------------------------
+
+/*
+ Bildet das Set "uber die Ranges der Page. Die Page muss die statische
+ Methode f"ur das Erfragen ihrer Ranges bei SetTabPage angegeben haben,
+ liefert also ihr Set onDemand.
+ */
+const sal_uInt16* SfxSingleTabDialog::GetInputRanges( const SfxItemPool& rPool )
+{
+ if ( GetInputItemSet() )
+ {
+ DBG_ERROR( "Set bereits vorhanden!" );
+ return GetInputItemSet()->GetRanges();
+ }
+
+ if ( pRanges )
+ return pRanges;
+ SvUShorts aUS(16, 16);
+
+ if ( fnGetRanges)
+ {
+ const sal_uInt16 *pTmpRanges = (fnGetRanges)();
+ const sal_uInt16 *pIter = pTmpRanges;
+ sal_uInt16 nLen;
+ for ( nLen = 0; *pIter; ++nLen, ++pIter )
+ ;
+ aUS.Insert( pTmpRanges, nLen, aUS.Count() );
+ }
+
+ //! Doppelte Ids entfernen?
+ sal_uInt16 nCount = aUS.Count();
+
+ for ( sal_uInt16 i = 0; i < nCount; ++i )
+ aUS[i] = rPool.GetWhich( aUS[i]) ;
+
+ // sortieren
+ if ( aUS.Count() > 1 )
+ qsort( (void*)aUS.GetData(), aUS.Count(), sizeof(sal_uInt16), BaseDlgsCmpUS_Impl );
+
+ pRanges = new sal_uInt16[aUS.Count() + 1];
+ memcpy( pRanges, aUS.GetData(), sizeof(sal_uInt16) * aUS.Count() );
+ pRanges[aUS.Count()] = 0;
+ return pRanges;
+}
+
diff --git a/sfx2/source/dialog/dialog.hrc b/sfx2/source/dialog/dialog.hrc
new file mode 100644
index 000000000000..7f03bf416431
--- /dev/null
+++ b/sfx2/source/dialog/dialog.hrc
@@ -0,0 +1,84 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_DIALOG_HRC
+#define _SFX_DIALOG_HRC
+
+#include <sfx2/sfx.hrc>
+
+// defines ---------------------------------------------------------------
+
+#define ID_NEW 1
+#define ID_EDIT 2
+#define ID_DELETE 3
+
+#define RC_DIALOG_BEGIN RID_SFX_DIALOG_START
+
+#define RID_DLG_ALIEN_WARNING ( RC_DIALOG_BEGIN + 0)
+#define STR_RESET ( RC_DIALOG_BEGIN + 0)
+
+#define DLG_PASSWD ( RC_DIALOG_BEGIN + 8)
+#define STR_TABPAGE_MANAGESTYLES ( RC_DIALOG_BEGIN + 12)
+#define MSG_TABPAGE_INVALIDNAME ( RC_DIALOG_BEGIN + 13)
+#define MSG_TABPAGE_INVALIDSTYLE ( RC_DIALOG_BEGIN + 14)
+#define DLG_NEW_STYLE_BY_EXAMPLE ( RC_DIALOG_BEGIN + 15)
+#define MSG_POOL_STYLE_NAME ( RC_DIALOG_BEGIN + 16)
+#define MSG_TABPAGE_INVALIDPARENT ( RC_DIALOG_BEGIN + 18)
+
+#define STR_DELETE_STYLE ( RC_DIALOG_BEGIN + 18)
+#define STR_DELETE_STYLE_USED ( RC_DIALOG_BEGIN + 20)
+
+#define MN_CONTEXT_TEMPLDLG ( RC_DIALOG_BEGIN + 46)
+
+#define DLG_VERSIONS ( RC_DIALOG_BEGIN + 69 )
+#define DLG_COMMENTS ( RC_DIALOG_BEGIN + 70 )
+
+#define MSG_ERROR_WRONG_CONFIRM ( RC_DIALOG_BEGIN + 76 )
+
+#define STR_APPLY ( RC_DIALOG_BEGIN + 87 )
+
+#define TP_COMMONPRINTOPTIONS ( RC_DIALOG_BEGIN + 90 )
+#define RID_WARN_PRINTTRANSPARENCY ( RC_DIALOG_BEGIN + 91 )
+
+#define RID_ERRBOX_MAIL_CONFIG ( RC_DIALOG_BEGIN + 92 )
+
+#define IMG_LST_STYLE_DESIGNER_HC ( RC_DIALOG_BEGIN + 99 )
+
+// 100-106 in tbxcust.hrc
+#define STR_MACRO_LOSS ( RC_DIALOG_BEGIN + 107 )
+#define STR_CANCEL_RECORDING ( RC_DIALOG_BEGIN + 108 )
+
+#define RID_DLG_SEARCH ( RC_DIALOG_BEGIN + 109 )
+
+#define STR_PDF_EXPORT_SEND ( RC_DIALOG_BEGIN + 120 )
+#define IMG_INFO ( RC_DIALOG_BEGIN + 122 )
+#define RID_EDIT_DURATIONS ( RC_DIALOG_BEGIN + 123 )
+#define SFX_PB_EDIT ( RC_DIALOG_BEGIN + 124 )
+
+#endif // #ifndef _SFX_DIALOG_HRC
+
+// eof ------------------------------------------------------------------------
+
diff --git a/sfx2/source/dialog/dialog.src b/sfx2/source/dialog/dialog.src
new file mode 100644
index 000000000000..c39425510ae2
--- /dev/null
+++ b/sfx2/source/dialog/dialog.src
@@ -0,0 +1,132 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+ // include ---------------------------------------------------------------
+#include <sfx2/sfx.hrc>
+#include "dialog.hrc"
+#include "helpid.hrc"
+#include "sfxlocal.hrc"
+
+String STR_RESET
+{
+ Text [ en-US ] = "~Reset" ;
+};
+String STR_APPLY
+{
+ Text [ en-US ] = "Apply";
+};
+String STR_TABPAGE_MANAGESTYLES
+{
+ Text [ en-US ] = "Organizer" ;
+};
+InfoBox MSG_TABPAGE_INVALIDNAME
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "This name is already in use." ;
+};
+InfoBox MSG_TABPAGE_INVALIDSTYLE
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "This Style does not exist." ;
+};
+InfoBox MSG_TABPAGE_INVALIDPARENT
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "This Style cannot be used as a base Style,\nbecause it would result in a recursive reference." ;
+};
+InfoBox MSG_POOL_STYLE_NAME
+{
+ Message [ en-US ] = "Name already exists as a default Style.\nPlease choose another name." ;
+};
+String STR_DELETE_STYLE
+{
+ Text [ en-US ] = "Do you really want to delete Style $1?" ;
+};
+String STR_DELETE_STYLE_USED
+{
+ Text [ en-US ] = "You are deleting an applied Style!\n" ;
+};
+Menu MN_CONTEXT_TEMPLDLG
+{
+ ItemList =
+ {
+ MenuItem
+ {
+ Identifier = ID_NEW ;
+ Text [ en-US ] = "New..." ;
+ HelpId = HID_STYLIST_NEW ;
+ };
+ MenuItem
+ {
+ Identifier = ID_EDIT ;
+ Text [ en-US ] = "Modify..." ;
+ HelpId = HID_STYLIST_EDIT ;
+ };
+ MenuItem
+ {
+ Identifier = ID_DELETE ;
+ Text [ en-US ] = "Delete..." ;
+ HelpId = HID_STYLIST_DELETE ;
+ };
+ };
+};
+
+ //------------------------------------------------------------------------
+String SID_NAVIGATOR
+{
+ Text [ en-US ] = "Navigator";
+};
+String SID_TASKPANE
+{
+ Text [ en-US ] = "Task Pane";
+};
+
+ErrorBox MSG_ERROR_WRONG_CONFIRM
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Faulty password confirmation";
+};
+
+String STR_PDF_EXPORT_SEND
+{
+ Text [ en-US ] = "Send" ;
+};
+
+Image IMG_INFO
+{
+ ImageBitmap = Bitmap
+ {
+ File = "info.png" ;
+ };
+};
+
+// ******************************************************************* EOF
+
diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx
new file mode 100644
index 000000000000..3d848d4d5648
--- /dev/null
+++ b/sfx2/source/dialog/dinfdlg.cxx
@@ -0,0 +1,2466 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <tools/urlobj.hxx>
+#include <vcl/msgbox.hxx>
+#include <svl/eitem.hxx>
+#include <vcl/svapp.hxx>
+#include <sfx2/filedlghelper.hxx>
+#include <unotools/localedatawrapper.hxx>
+#include <unotools/cmdoptions.hxx>
+#include <comphelper/processfactory.hxx>
+#include <svl/urihelper.hxx>
+#include <unotools/useroptions.hxx>
+#include <svtools/imagemgr.hxx>
+#include <tools/datetime.hxx>
+
+#include <memory>
+
+#include <comphelper/string.hxx>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/security/DocumentSignatureInformation.hpp>
+#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+#include <unotools/localedatawrapper.hxx>
+#include <unotools/syslocale.hxx>
+#include <rtl/math.hxx>
+#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+#include <com/sun/star/util/DateTime.hpp>
+#include <com/sun/star/util/Date.hpp>
+#include <com/sun/star/util/Time.hpp>
+#include <com/sun/star/util/Duration.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+
+#include <vcl/timer.hxx>
+#include "sfx2/dinfdlg.hxx"
+#include "sfx2/securitypage.hxx"
+#include "sfxresid.hxx"
+#include "dinfedt.hxx"
+#include <sfx2/frame.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/request.hxx>
+//#include "exptypes.hxx"
+#include "helper.hxx"
+#include <sfx2/objsh.hxx>
+#include <sfx2/docfile.hxx>
+#include <comphelper/storagehelper.hxx>
+
+#include <sfx2/sfx.hrc>
+#include "dinfdlg.hrc"
+#include "sfxlocal.hrc"
+#include <dialog.hrc>
+#include <vcl/help.hxx>
+
+#include <algorithm>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::ui::dialogs;
+using namespace ::com::sun::star::uno;
+
+
+struct CustomProperty
+{
+ ::rtl::OUString m_sName;
+ com::sun::star::uno::Any m_aValue;
+
+ CustomProperty( const ::rtl::OUString& sName,
+ const com::sun::star::uno::Any& rValue ) :
+ m_sName( sName ), m_aValue( rValue ) {}
+
+ inline bool operator==( const CustomProperty& rProp )
+ { return m_sName.equals( rProp.m_sName ) && m_aValue == rProp.m_aValue; }
+};
+
+
+static
+bool operator==(const util::DateTime &i_rLeft, const util::DateTime &i_rRight)
+{
+ return i_rLeft.Year == i_rRight.Year
+ && i_rLeft.Month == i_rRight.Month
+ && i_rLeft.Day == i_rRight.Day
+ && i_rLeft.Hours == i_rRight.Hours
+ && i_rLeft.Minutes == i_rRight.Minutes
+ && i_rLeft.Seconds == i_rRight.Seconds
+ && i_rLeft.HundredthSeconds == i_rRight.HundredthSeconds;
+}
+
+// STATIC DATA -----------------------------------------------------------
+
+TYPEINIT1_AUTOFACTORY(SfxDocumentInfoItem, SfxStringItem);
+
+const USHORT HI_NAME = 1;
+const USHORT HI_TYPE = 2;
+const USHORT HI_VALUE = 3;
+const USHORT HI_ACTION = 4;
+
+static const char DOCUMENT_SIGNATURE_MENU_CMD[] = "Signature";
+
+//------------------------------------------------------------------------
+String CreateSizeText( ULONG nSize, BOOL bExtraBytes = TRUE, BOOL bSmartExtraBytes = FALSE );
+String CreateSizeText( ULONG nSize, BOOL bExtraBytes, BOOL bSmartExtraBytes )
+{
+ String aUnitStr = ' ';
+ aUnitStr += String( SfxResId(STR_BYTES) );
+ ULONG nSize1 = nSize;
+ ULONG nSize2 = nSize1;
+ ULONG nMega = 1024 * 1024;
+ ULONG nGiga = nMega * 1024;
+ double fSize = nSize;
+ int nDec = 0;
+ BOOL bGB = FALSE;
+
+ if ( nSize1 >= 10000 && nSize1 < nMega )
+ {
+ nSize1 /= 1024;
+ aUnitStr = ' ';
+ aUnitStr += String( SfxResId(STR_KB) );
+ fSize /= 1024;
+ nDec = 0;
+ }
+ else if ( nSize1 >= nMega && nSize1 < nGiga )
+ {
+ nSize1 /= nMega;
+ aUnitStr = ' ';
+ aUnitStr += String( SfxResId(STR_MB) );
+ fSize /= nMega;
+ nDec = 2;
+ }
+ else if ( nSize1 >= nGiga )
+ {
+ nSize1 /= nGiga;
+ aUnitStr = ' ';
+ aUnitStr += String( SfxResId(STR_GB) );
+ bGB = TRUE;
+ fSize /= nGiga;
+ nDec = 3;
+ }
+ const LocaleDataWrapper& rLocaleWrapper = SvtSysLocale().GetLocaleData();
+ String aSizeStr( rLocaleWrapper.getNum( nSize1, 0 ) );
+ aSizeStr += aUnitStr;
+ if ( bExtraBytes && ( nSize1 < nSize2 ) )
+ {
+ aSizeStr = ::rtl::math::doubleToUString( fSize,
+ rtl_math_StringFormat_F, nDec,
+ rLocaleWrapper.getNumDecimalSep().GetChar(0) );
+ aSizeStr += aUnitStr;
+
+ aSizeStr += DEFINE_CONST_UNICODE(" (");
+ aSizeStr += rLocaleWrapper.getNum( nSize2, 0 );
+ aSizeStr += ' ';
+ aSizeStr += String( SfxResId(STR_BYTES) );
+ aSizeStr += ')';
+ }
+ else if ( bGB && bSmartExtraBytes )
+ {
+ nSize1 = nSize / nMega;
+ aSizeStr = DEFINE_CONST_UNICODE(" (");
+ aSizeStr += rLocaleWrapper.getNum( nSize1, 0 );
+ aSizeStr += aUnitStr;
+ aSizeStr += ')';
+ }
+ return aSizeStr;
+}
+
+String ConvertDateTime_Impl( const String& rName,
+ const util::DateTime& uDT, const LocaleDataWrapper& rWrapper )
+{
+ Date aD(uDT.Day, uDT.Month, uDT.Year);
+ Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
+ const String pDelim ( DEFINE_CONST_UNICODE( ", "));
+ String aStr( rWrapper.getDate( aD ) );
+ aStr += pDelim;
+ aStr += rWrapper.getTime( aT, TRUE, FALSE );
+ String aAuthor = rName;
+ aAuthor.EraseLeadingChars();
+ if ( aAuthor.Len() )
+ {
+ aStr += pDelim;
+ aStr += aAuthor;
+ }
+ return aStr;
+}
+
+//------------------------------------------------------------------------
+
+SfxDocumentInfoItem::SfxDocumentInfoItem()
+ : SfxStringItem()
+ , m_AutoloadDelay(0)
+ , m_AutoloadURL()
+ , m_isAutoloadEnabled(sal_False)
+ , m_DefaultTarget()
+ , m_TemplateName()
+ , m_Author()
+ , m_CreationDate()
+ , m_ModifiedBy()
+ , m_ModificationDate()
+ , m_PrintedBy()
+ , m_PrintDate()
+ , m_EditingCycles(0)
+ , m_EditingDuration(0)
+ , m_Description()
+ , m_Keywords()
+ , m_Subject()
+ , m_Title()
+ , m_bHasTemplate( sal_True )
+ , m_bDeleteUserData( sal_False )
+ , m_bUseUserData( sal_True )
+{
+}
+
+//------------------------------------------------------------------------
+
+SfxDocumentInfoItem::SfxDocumentInfoItem( const String& rFile,
+ const uno::Reference<document::XDocumentProperties>& i_xDocProps,
+ sal_Bool bIs )
+ : SfxStringItem( SID_DOCINFO, rFile )
+ , m_AutoloadDelay( i_xDocProps->getAutoloadSecs() )
+ , m_AutoloadURL( i_xDocProps->getAutoloadURL() )
+ , m_isAutoloadEnabled( (m_AutoloadDelay > 0) || m_AutoloadURL.getLength() )
+ , m_DefaultTarget( i_xDocProps->getDefaultTarget() )
+ , m_TemplateName( i_xDocProps->getTemplateName() )
+ , m_Author( i_xDocProps->getAuthor() )
+ , m_CreationDate( i_xDocProps->getCreationDate() )
+ , m_ModifiedBy( i_xDocProps->getModifiedBy() )
+ , m_ModificationDate( i_xDocProps->getModificationDate() )
+ , m_PrintedBy( i_xDocProps->getPrintedBy() )
+ , m_PrintDate( i_xDocProps->getPrintDate() )
+ , m_EditingCycles( i_xDocProps->getEditingCycles() )
+ , m_EditingDuration( i_xDocProps->getEditingDuration() )
+ , m_Description( i_xDocProps->getDescription() )
+ , m_Keywords( ::comphelper::string::convertCommaSeparated(
+ i_xDocProps->getKeywords()) )
+ , m_Subject( i_xDocProps->getSubject() )
+ , m_Title( i_xDocProps->getTitle() )
+ , m_bHasTemplate( sal_True )
+ , m_bDeleteUserData( sal_False )
+ , m_bUseUserData( bIs )
+{
+ try
+ {
+ Reference< beans::XPropertyContainer > xContainer = i_xDocProps->getUserDefinedProperties();
+ if ( xContainer.is() )
+ {
+ Reference < beans::XPropertySet > xSet( xContainer, UNO_QUERY );
+ const Sequence< beans::Property > lProps = xSet->getPropertySetInfo()->getProperties();
+ const beans::Property* pProps = lProps.getConstArray();
+ sal_Int32 nCount = lProps.getLength();
+ for ( sal_Int32 i = 0; i < nCount; ++i )
+ {
+ // "fix" property? => not a custom property => ignore it!
+ if (!(pProps[i].Attributes &
+ ::com::sun::star::beans::PropertyAttribute::REMOVABLE))
+ {
+ DBG_ASSERT(false, "non-removable user-defined property?");
+ continue;
+ }
+
+ uno::Any aValue = xSet->getPropertyValue(pProps[i].Name);
+ CustomProperty* pProp = new CustomProperty( pProps[i].Name, aValue );
+ m_aCustomProperties.push_back( pProp );
+ }
+ }
+ }
+ catch ( Exception& ) {}
+}
+
+//------------------------------------------------------------------------
+
+SfxDocumentInfoItem::SfxDocumentInfoItem( const SfxDocumentInfoItem& rItem )
+ : SfxStringItem( rItem )
+ , m_AutoloadDelay( rItem.getAutoloadDelay() )
+ , m_AutoloadURL( rItem.getAutoloadURL() )
+ , m_isAutoloadEnabled( rItem.isAutoloadEnabled() )
+ , m_DefaultTarget( rItem.getDefaultTarget() )
+ , m_TemplateName( rItem.getTemplateName() )
+ , m_Author( rItem.getAuthor() )
+ , m_CreationDate( rItem.getCreationDate() )
+ , m_ModifiedBy( rItem.getModifiedBy() )
+ , m_ModificationDate( rItem.getModificationDate() )
+ , m_PrintedBy( rItem.getPrintedBy() )
+ , m_PrintDate( rItem.getPrintDate() )
+ , m_EditingCycles( rItem.getEditingCycles() )
+ , m_EditingDuration( rItem.getEditingDuration() )
+ , m_Description( rItem.getDescription() )
+ , m_Keywords( rItem.getKeywords() )
+ , m_Subject( rItem.getSubject() )
+ , m_Title( rItem.getTitle() )
+ , m_bHasTemplate( rItem.m_bHasTemplate )
+ , m_bDeleteUserData( rItem.m_bDeleteUserData )
+ , m_bUseUserData( rItem.m_bUseUserData )
+{
+ for ( sal_uInt32 i = 0; i < rItem.m_aCustomProperties.size(); i++ )
+ {
+ CustomProperty* pProp = new CustomProperty( rItem.m_aCustomProperties[i]->m_sName,
+ rItem.m_aCustomProperties[i]->m_aValue );
+ m_aCustomProperties.push_back( pProp );
+ }
+}
+
+//------------------------------------------------------------------------
+
+SfxDocumentInfoItem::~SfxDocumentInfoItem()
+{
+ ClearCustomProperties();
+}
+
+//------------------------------------------------------------------------
+
+SfxPoolItem* SfxDocumentInfoItem::Clone( SfxItemPool * ) const
+{
+ return new SfxDocumentInfoItem( *this );
+}
+
+//------------------------------------------------------------------------
+
+int SfxDocumentInfoItem::operator==( const SfxPoolItem& rItem) const
+{
+ if (!(rItem.Type() == Type() && SfxStringItem::operator==(rItem))) {
+ return false;
+ }
+ const SfxDocumentInfoItem& rInfoItem(
+ static_cast<const SfxDocumentInfoItem&>(rItem));
+
+ return
+ m_AutoloadDelay == rInfoItem.m_AutoloadDelay &&
+ m_AutoloadURL == rInfoItem.m_AutoloadURL &&
+ m_isAutoloadEnabled == rInfoItem.m_isAutoloadEnabled &&
+ m_DefaultTarget == rInfoItem.m_DefaultTarget &&
+ m_Author == rInfoItem.m_Author &&
+ m_CreationDate == rInfoItem.m_CreationDate &&
+ m_ModifiedBy == rInfoItem.m_ModifiedBy &&
+ m_ModificationDate == rInfoItem.m_ModificationDate &&
+ m_PrintedBy == rInfoItem.m_PrintedBy &&
+ m_PrintDate == rInfoItem.m_PrintDate &&
+ m_EditingCycles == rInfoItem.m_EditingCycles &&
+ m_EditingDuration == rInfoItem.m_EditingDuration &&
+ m_Description == rInfoItem.m_Description &&
+ m_Keywords == rInfoItem.m_Keywords &&
+ m_Subject == rInfoItem.m_Subject &&
+ m_Title == rInfoItem.m_Title &&
+ m_aCustomProperties.size() == rInfoItem.m_aCustomProperties.size() &&
+ std::equal(m_aCustomProperties.begin(), m_aCustomProperties.end(),
+ rInfoItem.m_aCustomProperties.begin());
+}
+
+//------------------------------------------------------------------------
+
+void SfxDocumentInfoItem::resetUserData(const ::rtl::OUString & i_rAuthor)
+{
+ setAuthor(i_rAuthor);
+ DateTime now;
+ setCreationDate( util::DateTime(
+ now.Get100Sec(), now.GetSec(), now.GetMin(), now.GetHour(),
+ now.GetDay(), now.GetMonth(), now.GetYear() ) );
+ setModifiedBy(::rtl::OUString());
+ setPrintedBy(::rtl::OUString());
+ setModificationDate(util::DateTime());
+ setPrintDate(util::DateTime());
+ setEditingDuration(0);
+ setEditingCycles(1);
+}
+
+//------------------------------------------------------------------------
+
+void SfxDocumentInfoItem::UpdateDocumentInfo(
+ const uno::Reference<document::XDocumentProperties>& i_xDocProps,
+ bool i_bDoNotUpdateUserDefined) const
+{
+ if (isAutoloadEnabled()) {
+ i_xDocProps->setAutoloadSecs(getAutoloadDelay());
+ i_xDocProps->setAutoloadURL(getAutoloadURL());
+ } else {
+ i_xDocProps->setAutoloadSecs(0);
+ i_xDocProps->setAutoloadURL(::rtl::OUString());
+ }
+ i_xDocProps->setDefaultTarget(getDefaultTarget());
+// i_xDocProps->setTemplateName(getTemplateName());
+ i_xDocProps->setAuthor(getAuthor());
+ i_xDocProps->setCreationDate(getCreationDate());
+ i_xDocProps->setModifiedBy(getModifiedBy());
+ i_xDocProps->setModificationDate(getModificationDate());
+ i_xDocProps->setPrintedBy(getPrintedBy());
+ i_xDocProps->setPrintDate(getPrintDate());
+ i_xDocProps->setEditingCycles(getEditingCycles());
+ i_xDocProps->setEditingDuration(getEditingDuration());
+ i_xDocProps->setDescription(getDescription());
+ i_xDocProps->setKeywords(
+ ::comphelper::string::convertCommaSeparated(getKeywords()));
+ i_xDocProps->setSubject(getSubject());
+ i_xDocProps->setTitle(getTitle());
+
+ // this is necessary in case of replaying a recorded macro:
+ // in this case, the macro may contain the 4 old user-defined DocumentInfo
+ // fields, but not any of the DocumentInfo properties;
+ // as a consequence, most of the UserDefined properties of the
+ // DocumentProperties would be summarily deleted here, which does not
+ // seem like a good idea.
+ if (i_bDoNotUpdateUserDefined)
+ return;
+
+ try
+ {
+ Reference< beans::XPropertyContainer > xContainer = i_xDocProps->getUserDefinedProperties();
+ Reference < beans::XPropertySet > xSet( xContainer, UNO_QUERY );
+ Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
+ const Sequence< beans::Property > lProps = xSetInfo->getProperties();
+ const beans::Property* pProps = lProps.getConstArray();
+ sal_Int32 nCount = lProps.getLength();
+ for ( sal_Int32 j = 0; j < nCount; ++j )
+ {
+ if ((pProps[j].Attributes &
+ ::com::sun::star::beans::PropertyAttribute::REMOVABLE))
+ {
+ xContainer->removeProperty( pProps[j].Name );
+ }
+ }
+
+ for ( sal_uInt32 k = 0; k < m_aCustomProperties.size(); ++k )
+ {
+ try
+ {
+ xContainer->addProperty( m_aCustomProperties[k]->m_sName,
+ beans::PropertyAttribute::REMOVABLE, m_aCustomProperties[k]->m_aValue );
+ }
+ catch ( Exception& )
+ {
+ DBG_ERRORFILE( "SfxDocumentInfoItem::updateDocumentInfo(): exception while adding custom properties" );
+ }
+ }
+ }
+ catch ( Exception& )
+ {
+ DBG_ERRORFILE( "SfxDocumentInfoItem::updateDocumentInfo(): exception while removing custom properties" );
+ }
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentInfoItem::IsDeleteUserData() const
+{
+ return m_bDeleteUserData;
+}
+
+void SfxDocumentInfoItem::SetDeleteUserData( sal_Bool bSet )
+{
+ m_bDeleteUserData = bSet;
+}
+
+sal_Bool SfxDocumentInfoItem::IsUseUserData() const
+{
+ return m_bUseUserData;
+}
+
+void SfxDocumentInfoItem::SetUseUserData( sal_Bool bSet )
+{
+ m_bUseUserData = bSet;
+}
+
+std::vector< CustomProperty* > SfxDocumentInfoItem::GetCustomProperties() const
+{
+ std::vector< CustomProperty* > aRet;
+ for ( sal_uInt32 i = 0; i < m_aCustomProperties.size(); i++ )
+ {
+ CustomProperty* pProp = new CustomProperty( m_aCustomProperties[i]->m_sName,
+ m_aCustomProperties[i]->m_aValue );
+ aRet.push_back( pProp );
+ }
+
+ return aRet;
+}
+
+void SfxDocumentInfoItem::ClearCustomProperties()
+{
+ for ( sal_uInt32 i = 0; i < m_aCustomProperties.size(); i++ )
+ delete m_aCustomProperties[i];
+ m_aCustomProperties.clear();
+}
+
+void SfxDocumentInfoItem::AddCustomProperty( const ::rtl::OUString& sName, const Any& rValue )
+{
+ CustomProperty* pProp = new CustomProperty( sName, rValue );
+ m_aCustomProperties.push_back( pProp );
+}
+
+sal_Bool SfxDocumentInfoItem::QueryValue( Any& rVal, BYTE nMemberId ) const
+{
+ String aValue;
+ sal_Int32 nValue = 0;
+ sal_Bool bValue = sal_False;
+ BOOL bIsInt = FALSE;
+ BOOL bIsString = FALSE;
+ nMemberId &= ~CONVERT_TWIPS;
+ switch ( nMemberId )
+ {
+ case MID_DOCINFO_USEUSERDATA:
+ bValue = IsUseUserData();
+ break;
+ case MID_DOCINFO_DELETEUSERDATA:
+ bValue = IsDeleteUserData();
+ break;
+ case MID_DOCINFO_AUTOLOADENABLED:
+ bValue = isAutoloadEnabled();
+ break;
+ case MID_DOCINFO_AUTOLOADSECS:
+ bIsInt = TRUE;
+ nValue = getAutoloadDelay();
+ break;
+ case MID_DOCINFO_AUTOLOADURL:
+ bIsString = TRUE;
+ aValue = getAutoloadURL();
+ break;
+ case MID_DOCINFO_DEFAULTTARGET:
+ bIsString = TRUE;
+ aValue = getDefaultTarget();
+ break;
+ case MID_DOCINFO_DESCRIPTION:
+ bIsString = TRUE;
+ aValue = getDescription();
+ break;
+ case MID_DOCINFO_KEYWORDS:
+ bIsString = TRUE;
+ aValue = getKeywords();
+ break;
+ case MID_DOCINFO_SUBJECT:
+ bIsString = TRUE;
+ aValue = getSubject();
+ break;
+ case MID_DOCINFO_TITLE:
+ bIsString = TRUE;
+ aValue = getTitle();
+ break;
+ default:
+ DBG_ERROR("Wrong MemberId!");
+ return sal_False;
+ }
+
+ if ( bIsString )
+ rVal <<= ::rtl::OUString( aValue );
+ else if ( bIsInt )
+ rVal <<= nValue;
+ else
+ rVal <<= bValue;
+ return sal_True;
+}
+
+sal_Bool SfxDocumentInfoItem::PutValue( const Any& rVal, BYTE nMemberId )
+{
+ ::rtl::OUString aValue;
+ sal_Int32 nValue=0;
+ sal_Bool bValue = sal_False;
+ sal_Bool bRet = sal_False;
+ nMemberId &= ~CONVERT_TWIPS;
+ switch ( nMemberId )
+ {
+ case MID_DOCINFO_USEUSERDATA:
+ bRet = (rVal >>= bValue);
+ if ( bRet )
+ SetUseUserData( bValue );
+ break;
+ case MID_DOCINFO_DELETEUSERDATA:
+ // QUESTION: deleting user data was done here; seems to be superfluous!
+ bRet = (rVal >>= bValue);
+ if ( bRet )
+ SetDeleteUserData( bValue );
+ break;
+ case MID_DOCINFO_AUTOLOADENABLED:
+ bRet = (rVal >>= bValue);
+ if ( bRet )
+ setAutoloadEnabled(bValue);
+ break;
+ case MID_DOCINFO_AUTOLOADSECS:
+ bRet = (rVal >>= nValue);
+ if ( bRet )
+ setAutoloadDelay(nValue);
+ break;
+ case MID_DOCINFO_AUTOLOADURL:
+ bRet = (rVal >>= aValue);
+ if ( bRet )
+ setAutoloadURL(aValue);
+ break;
+ case MID_DOCINFO_DEFAULTTARGET:
+ bRet = (rVal >>= aValue);
+ if ( bRet )
+ setDefaultTarget(aValue);
+ break;
+ case MID_DOCINFO_DESCRIPTION:
+ bRet = (rVal >>= aValue);
+ if ( bRet )
+ setDescription(aValue);
+ break;
+ case MID_DOCINFO_KEYWORDS:
+ bRet = (rVal >>= aValue);
+ if ( bRet )
+ setKeywords(aValue);
+ break;
+ case MID_DOCINFO_SUBJECT:
+ bRet = (rVal >>= aValue);
+ if ( bRet )
+ setSubject(aValue);
+ break;
+ case MID_DOCINFO_TITLE:
+ bRet = (rVal >>= aValue);
+ if ( bRet )
+ setTitle(aValue);
+ break;
+ default:
+ DBG_ERROR("Wrong MemberId!");
+ return sal_False;
+ }
+
+ return bRet;
+}
+
+//------------------------------------------------------------------------
+
+SfxDocumentDescPage::SfxDocumentDescPage( Window * pParent, const SfxItemSet& rItemSet ) :
+
+ SfxTabPage( pParent, SfxResId( TP_DOCINFODESC ), rItemSet ),
+
+ aTitleFt ( this, SfxResId( FT_TITLE ) ),
+ aTitleEd ( this, SfxResId( ED_TITLE ) ),
+ aThemaFt ( this, SfxResId( FT_THEMA ) ),
+ aThemaEd ( this, SfxResId( ED_THEMA ) ),
+ aKeywordsFt ( this, SfxResId( FT_KEYWORDS ) ),
+ aKeywordsEd ( this, SfxResId( ED_KEYWORDS ) ),
+ aCommentFt ( this, SfxResId( FT_COMMENT ) ),
+ aCommentEd ( this, SfxResId( ED_COMMENT ) ),
+
+ pInfoItem ( NULL )
+
+{
+ FreeResource();
+}
+
+//------------------------------------------------------------------------
+
+SfxTabPage *SfxDocumentDescPage::Create(Window *pParent, const SfxItemSet &rItemSet)
+{
+ return new SfxDocumentDescPage(pParent, rItemSet);
+}
+
+//------------------------------------------------------------------------
+
+BOOL SfxDocumentDescPage::FillItemSet(SfxItemSet &rSet)
+{
+ // Pruefung, ob eine Aenderung vorliegt
+ const BOOL bTitleMod = aTitleEd.IsModified();
+ const BOOL bThemeMod = aThemaEd.IsModified();
+ const BOOL bKeywordsMod = aKeywordsEd.IsModified();
+ const BOOL bCommentMod = aCommentEd.IsModified();
+ if( !( bTitleMod || bThemeMod || bKeywordsMod || bCommentMod ) )
+ {
+ return FALSE;
+ }
+
+ // Erzeugung der Ausgabedaten
+ const SfxPoolItem* pItem = NULL;
+ SfxDocumentInfoItem* pInfo = NULL;
+ SfxTabDialog* pDlg = GetTabDialog();
+ const SfxItemSet* pExSet = NULL;
+
+ if ( pDlg )
+ pExSet = pDlg->GetExampleSet();
+
+ if ( pExSet && SFX_ITEM_SET != pExSet->GetItemState( SID_DOCINFO, TRUE, &pItem ) )
+ pInfo = pInfoItem;
+ else if ( pItem )
+ pInfo = new SfxDocumentInfoItem( *(const SfxDocumentInfoItem *)pItem );
+
+ if ( !pInfo )
+ {
+ DBG_ERRORFILE( "SfxDocumentDescPage::FillItemSet(): no item found" );
+ return FALSE;
+ }
+
+ if( bTitleMod )
+ {
+ pInfo->setTitle( aTitleEd.GetText() );
+ }
+ if( bThemeMod )
+ {
+ pInfo->setSubject( aThemaEd.GetText() );
+ }
+ if( bKeywordsMod )
+ {
+ pInfo->setKeywords( aKeywordsEd.GetText() );
+ }
+ if( bCommentMod )
+ {
+ pInfo->setDescription( aCommentEd.GetText() );
+ }
+ rSet.Put( SfxDocumentInfoItem( *pInfo ) );
+ if( pInfo != pInfoItem )
+ {
+ delete pInfo;
+ }
+
+ return TRUE;
+}
+
+//------------------------------------------------------------------------
+
+void SfxDocumentDescPage::Reset(const SfxItemSet &rSet)
+{
+ pInfoItem = &(SfxDocumentInfoItem &)rSet.Get(SID_DOCINFO);
+
+ aTitleEd.SetText( pInfoItem->getTitle() );
+ aThemaEd.SetText( pInfoItem->getSubject() );
+ aKeywordsEd.SetText( pInfoItem->getKeywords() );
+ aCommentEd.SetText( pInfoItem->getDescription() );
+
+ SFX_ITEMSET_ARG( &rSet, pROItem, SfxBoolItem, SID_DOC_READONLY, FALSE );
+ if ( pROItem && pROItem->GetValue() )
+ {
+ aTitleEd.SetReadOnly( TRUE );
+ aThemaEd.SetReadOnly( TRUE );
+ aKeywordsEd.SetReadOnly( TRUE );
+ aCommentEd.SetReadOnly( TRUE );
+ }
+}
+
+//------------------------------------------------------------------------
+
+namespace
+{
+ String GetDateTimeString( sal_Int32 _nDate, sal_Int32 _nTime )
+ {
+ LocaleDataWrapper aWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+
+ Date aDate( _nDate );
+ Time aTime( _nTime );
+ String aStr( aWrapper.getDate( aDate ) );
+ aStr.AppendAscii( ", " );
+ aStr += aWrapper.getTime( aTime );
+ return aStr;
+ }
+
+ // copy from xmlsecurity/source/dialog/resourcemanager.cxx
+ String GetContentPart( const String& _rRawString, const String& _rPartId )
+ {
+ String s;
+
+ xub_StrLen nContStart = _rRawString.Search( _rPartId );
+ if( nContStart != STRING_NOTFOUND )
+ {
+ nContStart = nContStart + _rPartId.Len();
+ ++nContStart; // now it's start of content, directly after Id
+
+ xub_StrLen nContEnd = _rRawString.Search( sal_Unicode( ',' ), nContStart );
+
+ s = String( _rRawString, nContStart, nContEnd - nContStart );
+ }
+
+ return s;
+ }
+
+}
+
+SfxDocumentPage::SfxDocumentPage( Window* pParent, const SfxItemSet& rItemSet ) :
+
+ SfxTabPage( pParent, SfxResId( TP_DOCINFODOC ), rItemSet ),
+
+ aBmp1 ( this, SfxResId( BMP_FILE_1 ) ),
+ aNameED ( this, SfxResId( ED_FILE_NAME ) ),
+
+ aLine1FL ( this, SfxResId( FL_FILE_1 ) ),
+ aTypeFT ( this, SfxResId( FT_FILE_TYP ) ),
+ aShowTypeFT ( this, SfxResId( FT_FILE_SHOW_TYP ) ),
+ aReadOnlyCB ( this, SfxResId( CB_FILE_READONLY ) ),
+ aFileFt ( this, SfxResId( FT_FILE ) ),
+ aFileValFt ( this, SfxResId( FT_FILE_VAL ) ),
+ aSizeFT ( this, SfxResId( FT_FILE_SIZE ) ),
+ aShowSizeFT ( this, SfxResId( FT_FILE_SHOW_SIZE ) ),
+
+ aLine2FL ( this, SfxResId( FL_FILE_2 ) ),
+ aCreateFt ( this, SfxResId( FT_CREATE ) ),
+ aCreateValFt ( this, SfxResId( FT_CREATE_VAL ) ),
+ aChangeFt ( this, SfxResId( FT_CHANGE ) ),
+ aChangeValFt ( this, SfxResId( FT_CHANGE_VAL ) ),
+ aSignedFt ( this, SfxResId( FT_SIGNED ) ),
+ aSignedValFt ( this, SfxResId( FT_SIGNED_VAL ) ),
+ aSignatureBtn ( this, SfxResId( BTN_SIGNATURE ) ),
+ aPrintFt ( this, SfxResId( FT_PRINT ) ),
+ aPrintValFt ( this, SfxResId( FT_PRINT_VAL ) ),
+ aTimeLogFt ( this, SfxResId( FT_TIMELOG ) ),
+ aTimeLogValFt ( this, SfxResId( FT_TIMELOG_VAL ) ),
+ aDocNoFt ( this, SfxResId( FT_DOCNO ) ),
+ aDocNoValFt ( this, SfxResId( FT_DOCNO_VAL ) ),
+ aUseUserDataCB ( this, SfxResId( CB_USE_USERDATA ) ),
+ aDeleteBtn ( this, SfxResId( BTN_DELETE ) ),
+
+ aLine3FL ( this, SfxResId( FL_FILE_3 ) ),
+ aTemplFt ( this, SfxResId( FT_TEMPL ) ),
+ aTemplValFt ( this, SfxResId( FT_TEMPL_VAL ) ),
+
+ aUnknownSize ( SfxResId( STR_UNKNOWNSIZE ) ),
+ aMultiSignedStr ( SfxResId( STR_MULTSIGNED ) ),
+
+ bEnableUseUserData ( FALSE ),
+ bHandleDelete ( FALSE )
+
+{
+ FreeResource();
+
+ ImplUpdateSignatures();
+ aDeleteBtn.SetClickHdl( LINK( this, SfxDocumentPage, DeleteHdl ) );
+ aSignatureBtn.SetClickHdl( LINK( this, SfxDocumentPage, SignatureHdl ) );
+
+ // if the button text is too wide, then broaden it
+ const long nOffset = 12;
+ String sText = aSignatureBtn.GetText();
+ long nTxtW = aSignatureBtn.GetTextWidth( sText );
+ if ( sText.Search( '~' ) == STRING_NOTFOUND )
+ nTxtW += nOffset;
+ long nBtnW = aSignatureBtn.GetSizePixel().Width();
+ if ( nTxtW >= nBtnW )
+ {
+ long nDelta = Max( nTxtW - nBtnW, nOffset/3 );
+ Size aNewSize = aSignatureBtn.GetSizePixel();
+ aNewSize.Width() += nDelta;
+ aSignatureBtn.SetSizePixel( aNewSize );
+ aDeleteBtn.SetSizePixel( aNewSize );
+ // and give them a new position
+ Point aNewPos = aSignatureBtn.GetPosPixel();
+ aNewPos.X() -= nDelta;
+ aSignatureBtn.SetPosPixel( aNewPos );
+ aNewPos = aDeleteBtn.GetPosPixel();
+ aNewPos.X() -= nDelta;
+ aDeleteBtn.SetPosPixel( aNewPos );
+
+ aNewSize = aSignedValFt.GetSizePixel();
+ aNewSize.Width() -= nDelta;
+ aSignedValFt.SetSizePixel( aNewSize );
+ aNewSize = aUseUserDataCB.GetSizePixel();
+ aNewSize.Width() -= nDelta;
+ aUseUserDataCB.SetSizePixel( aNewSize );
+ }
+ // See i96288
+ // Check if the document signature command is enabled
+ // on the main list enable/disable the pushbutton accordingly
+ SvtCommandOptions aCmdOptions;
+ if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED,
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( DOCUMENT_SIGNATURE_MENU_CMD ) ) ) )
+ aSignatureBtn.Disable();
+}
+
+//------------------------------------------------------------------------
+
+IMPL_LINK( SfxDocumentPage, DeleteHdl, PushButton*, EMPTYARG )
+{
+ String aName;
+ if ( bEnableUseUserData && aUseUserDataCB.IsChecked() )
+ aName = SvtUserOptions().GetFullName();
+ LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ DateTime now;
+ util::DateTime uDT(
+ now.Get100Sec(), now.GetSec(), now.GetMin(), now.GetHour(),
+ now.GetDay(), now.GetMonth(), now.GetYear() );
+ aCreateValFt.SetText( ConvertDateTime_Impl( aName, uDT, aLocaleWrapper ) );
+ XubString aEmpty;
+ aChangeValFt.SetText( aEmpty );
+ aPrintValFt.SetText( aEmpty );
+ const Time aTime( 0 );
+ aTimeLogValFt.SetText( aLocaleWrapper.getDuration( aTime ) );
+ aDocNoValFt.SetText( '1' );
+ bHandleDelete = TRUE;
+ return 0;
+}
+
+IMPL_LINK( SfxDocumentPage, SignatureHdl, PushButton*, EMPTYARG )
+{
+ SfxObjectShell* pDoc = SfxObjectShell::Current();
+ if( pDoc )
+ {
+ pDoc->SignDocumentContent();
+
+ ImplUpdateSignatures();
+ }
+
+ return 0;
+}
+
+void SfxDocumentPage::ImplUpdateSignatures()
+{
+ SfxObjectShell* pDoc = SfxObjectShell::Current();
+ if( pDoc )
+ {
+ SfxMedium* pMedium = pDoc->GetMedium();
+ if ( pMedium && pMedium->GetName().Len() && pMedium->GetStorage().is() )
+ {
+ Reference< security::XDocumentDigitalSignatures > xD(
+ comphelper::getProcessServiceFactory()->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ) ), uno::UNO_QUERY );
+
+ if( xD.is() )
+ {
+ String s;
+ Sequence< security::DocumentSignatureInformation > aInfos;
+ aInfos = xD->verifyDocumentContentSignatures( pMedium->GetZipStorageToSign_Impl(),
+ uno::Reference< io::XInputStream >() );
+ if( aInfos.getLength() > 1 )
+ {
+ s = aMultiSignedStr;
+ }
+ else if( aInfos.getLength() == 1 )
+ {
+ String aCN_Id( String::CreateFromAscii( "CN" ) );
+ const security::DocumentSignatureInformation& rInfo = aInfos[ 0 ];
+ s = GetDateTimeString( rInfo.SignatureDate, rInfo.SignatureTime );
+ s.AppendAscii( ", " );
+ s += GetContentPart( rInfo.Signer->getSubjectName(), aCN_Id );
+ }
+ aSignedValFt.SetText( s );
+ }
+ }
+ }
+}
+
+//------------------------------------------------------------------------
+
+SfxTabPage* SfxDocumentPage::Create( Window* pParent, const SfxItemSet& rItemSet )
+{
+ return new SfxDocumentPage( pParent, rItemSet );
+}
+
+//------------------------------------------------------------------------
+
+void SfxDocumentPage::EnableUseUserData()
+{
+ bEnableUseUserData = TRUE;
+ aUseUserDataCB.Show();
+ aDeleteBtn.Show();
+}
+
+//------------------------------------------------------------------------
+
+BOOL SfxDocumentPage::FillItemSet( SfxItemSet& rSet )
+{
+ BOOL bRet = FALSE;
+
+ if ( !bHandleDelete && bEnableUseUserData &&
+ aUseUserDataCB.GetState() != aUseUserDataCB.GetSavedValue() &&
+ GetTabDialog() && GetTabDialog()->GetExampleSet() )
+ {
+ const SfxItemSet* pExpSet = GetTabDialog()->GetExampleSet();
+ const SfxPoolItem* pItem;
+
+ if ( pExpSet && SFX_ITEM_SET == pExpSet->GetItemState( SID_DOCINFO, TRUE, &pItem ) )
+ {
+ SfxDocumentInfoItem* pInfoItem = (SfxDocumentInfoItem*)pItem;
+ BOOL bUseData = ( STATE_CHECK == aUseUserDataCB.GetState() );
+ pInfoItem->SetUseUserData( bUseData );
+/*
+ if ( !bUseData )
+ {
+ // "Benutzerdaten verwenden" ausgeschaltet ->
+ // den Benutzer aus den Stamps l"oschen
+ String aEmptyUser;
+ aInfo.SetCreated(
+ SfxStamp( aEmptyUser, aInfo.GetCreated().GetTime() ) );
+ aInfo.SetChanged(
+ SfxStamp( aEmptyUser, aInfo.GetChanged().GetTime() ) );
+ aInfo.SetPrinted(
+ SfxStamp( aEmptyUser, aInfo.GetPrinted().GetTime() ) );
+ }
+*/
+ rSet.Put( SfxDocumentInfoItem( *pInfoItem ) );
+ bRet = TRUE;
+ }
+ }
+
+ if ( bHandleDelete )
+ {
+ const SfxItemSet* pExpSet = GetTabDialog()->GetExampleSet();
+ const SfxPoolItem* pItem;
+ if ( pExpSet && SFX_ITEM_SET == pExpSet->GetItemState( SID_DOCINFO, TRUE, &pItem ) )
+ {
+ SfxDocumentInfoItem* pInfoItem = (SfxDocumentInfoItem*)pItem;
+ BOOL bUseAuthor = bEnableUseUserData && aUseUserDataCB.IsChecked();
+ SfxDocumentInfoItem newItem( *pInfoItem );
+ newItem.resetUserData( bUseAuthor
+ ? SvtUserOptions().GetFullName()
+ : ::rtl::OUString() );
+ pInfoItem->SetUseUserData( STATE_CHECK == aUseUserDataCB.GetState() );
+ newItem.SetUseUserData( STATE_CHECK == aUseUserDataCB.GetState() );
+
+ newItem.SetDeleteUserData( TRUE );
+ rSet.Put( newItem );
+ bRet = TRUE;
+ }
+ }
+
+ if ( aNameED.IsModified() && aNameED.GetText().Len() )
+ {
+ rSet.Put( SfxStringItem( ID_FILETP_TITLE, aNameED.GetText() ) );
+ bRet = TRUE;
+ }
+
+ if ( /* aReadOnlyCB.IsModified() */ TRUE )
+ {
+ rSet.Put( SfxBoolItem( ID_FILETP_READONLY, aReadOnlyCB.IsChecked() ) );
+ bRet = TRUE;
+ }
+
+ return bRet;
+}
+
+//------------------------------------------------------------------------
+
+void SfxDocumentPage::Reset( const SfxItemSet& rSet )
+{
+ // Bestimmung der Dokumentinformationen
+ const SfxDocumentInfoItem *pInfoItem =
+ &(const SfxDocumentInfoItem &)rSet.Get(SID_DOCINFO);
+
+ // template data
+ if ( pInfoItem->HasTemplate() )
+ {
+ aTemplValFt.SetText( pInfoItem->getTemplateName() );
+ }
+ else
+ {
+ aTemplFt.Hide();
+ aTemplValFt.Hide();
+ }
+
+ // determine file name
+ String aFile( pInfoItem->GetValue() );
+ String aFactory( aFile );
+ if ( aFile.Len() > 2 && aFile.GetChar(0) == '[' )
+ {
+ USHORT nPos = aFile.Search( ']' );
+ aFactory = aFile.Copy( 1, nPos-1 );
+ aFile = aFile.Copy( nPos+1 );
+ }
+
+ // determine name
+ String aName;
+ const SfxPoolItem* pItem = 0;
+ if ( SFX_ITEM_SET != rSet.GetItemState( ID_FILETP_TITLE, FALSE, &pItem ) )
+ {
+ INetURLObject aURL(aFile);
+ aName = aURL.GetName( INetURLObject::DECODE_WITH_CHARSET );
+ if ( !aName.Len() || aURL.GetProtocol() == INET_PROT_PRIVATE )
+ aName = String( SfxResId( STR_NONAME ) );
+ aNameED.SetReadOnly( TRUE );
+ }
+ else
+ {
+ DBG_ASSERT( pItem->IsA( TYPE( SfxStringItem ) ), "SfxDocumentPage:<SfxStringItem> erwartet" );
+ aName = ( ( SfxStringItem* ) pItem )->GetValue();
+ }
+ aNameED.SetText( aName );
+ aNameED.ClearModifyFlag();
+
+ // determine RO-Flag
+ if ( SFX_ITEM_UNKNOWN == rSet.GetItemState( ID_FILETP_READONLY, FALSE, &pItem )
+ || !pItem )
+ aReadOnlyCB.Hide();
+ else
+ aReadOnlyCB.Check( ( (SfxBoolItem*)pItem )->GetValue() );
+
+ // determine context symbol
+ INetURLObject aURL;
+ aURL.SetSmartProtocol( INET_PROT_FILE );
+ aURL.SetSmartURL( aFactory);
+ const String& rMainURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
+ aBmp1.SetImage( SvFileInformationManager::GetImage( aURL, TRUE ) );
+
+ // determine size and type
+ String aSizeText( aUnknownSize );
+ if ( aURL.GetProtocol() == INET_PROT_FILE )
+ aSizeText = CreateSizeText( SfxContentHelper::GetSize( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) );
+ aShowSizeFT.SetText( aSizeText );
+
+ String aDescription = SvFileInformationManager::GetDescription( INetURLObject(rMainURL) );
+ if ( aDescription.Len() == 0 )
+ aDescription = String( SfxResId( STR_SFX_NEWOFFICEDOC ) );
+ aShowTypeFT.SetText( aDescription );
+
+ // determine location
+ aURL.SetSmartURL( aFile);
+ if ( aURL.GetProtocol() == INET_PROT_FILE )
+ {
+ INetURLObject aPath( aURL );
+ aPath.setFinalSlash();
+ aPath.removeSegment();
+ // we know it's a folder -> don't need the final slash, but it's better for WB_PATHELLIPSIS
+ aPath.removeFinalSlash();
+ String aText( aPath.PathToFileName() ); //! (pb) MaxLen?
+ aFileValFt.SetText( aText );
+ }
+ else if ( aURL.GetProtocol() != INET_PROT_PRIVATE )
+ aFileValFt.SetText( aURL.GetPartBeforeLastName() );
+
+ // handle access data
+ sal_Bool m_bUseUserData = pInfoItem->IsUseUserData();
+ LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ aCreateValFt.SetText( ConvertDateTime_Impl( pInfoItem->getAuthor(),
+ pInfoItem->getCreationDate(), aLocaleWrapper ) );
+ util::DateTime aTime( pInfoItem->getModificationDate() );
+// if ( aTime.IsValid() )
+ if ( aTime.Month > 0 )
+ aChangeValFt.SetText( ConvertDateTime_Impl(
+ pInfoItem->getModifiedBy(), aTime, aLocaleWrapper ) );
+ aTime = pInfoItem->getPrintDate();
+// if ( aTime.IsValid())
+ if ( aTime.Month > 0 )
+ aPrintValFt.SetText( ConvertDateTime_Impl( pInfoItem->getPrintedBy(),
+ aTime, aLocaleWrapper ) );
+ const long nTime = pInfoItem->getEditingDuration();
+ if ( m_bUseUserData )
+ {
+ const Time aT( nTime/3600, (nTime%3600)/60, nTime%60 );
+ aTimeLogValFt.SetText( aLocaleWrapper.getDuration( aT ) );
+ aDocNoValFt.SetText( String::CreateFromInt32(
+ pInfoItem->getEditingCycles() ) );
+ }
+
+ TriState eState = (TriState)m_bUseUserData;
+
+ if ( STATE_DONTKNOW == eState )
+ aUseUserDataCB.EnableTriState( TRUE );
+
+ aUseUserDataCB.SetState( eState );
+ aUseUserDataCB.SaveValue();
+ aUseUserDataCB.Enable( bEnableUseUserData );
+ bHandleDelete = FALSE;
+ aDeleteBtn.Enable( bEnableUseUserData );
+}
+
+//------------------------------------------------------------------------
+
+SfxInternetPage::SfxInternetPage( Window* pParent, const SfxItemSet& rItemSet ) :
+
+ SfxTabPage( pParent, SfxResId( TP_DOCINFORELOAD ), rItemSet ),
+
+ aRBNoAutoUpdate ( this, SfxResId( RB_NOAUTOUPDATE ) ),
+
+ aRBReloadUpdate ( this, SfxResId( RB_RELOADUPDATE ) ),
+
+ aRBForwardUpdate ( this, SfxResId( RB_FORWARDUPDATE ) ),
+ aFTEvery ( this, SfxResId( FT_EVERY ) ),
+ aNFReload ( this, SfxResId( ED_RELOAD ) ),
+ aFTReloadSeconds ( this, SfxResId( FT_RELOADSECS ) ),
+ aFTAfter ( this, SfxResId( FT_AFTER ) ),
+ aNFAfter ( this, SfxResId( ED_FORWARD ) ),
+ aFTAfterSeconds ( this, SfxResId( FT_FORWARDSECS ) ),
+ aFTURL ( this, SfxResId( FT_URL ) ),
+ aEDForwardURL ( this, SfxResId( ED_URL ) ),
+ aPBBrowseURL ( this, SfxResId( PB_BROWSEURL ) ),
+ aFTFrame ( this, SfxResId( FT_FRAME ) ),
+ aCBFrame ( this, SfxResId( CB_FRAME ) ),
+
+ aForwardErrorMessg ( SfxResId( STR_FORWARD_ERRMSSG ) ),
+ pInfoItem ( NULL ),
+ pFileDlg ( NULL ),
+ eState ( S_Init )
+
+{
+ FreeResource();
+ pInfoItem = &( SfxDocumentInfoItem& ) rItemSet.Get( SID_DOCINFO );
+ TargetList aList;
+ SfxViewFrame* pFrame = SfxViewFrame::Current();
+ if( pFrame )
+ {
+ pFrame = pFrame->GetTopViewFrame();
+ if( pFrame )
+ {
+ pFrame->GetTargetList( aList );
+
+ String* pObj;
+ for( USHORT nPos = ( USHORT ) aList.Count() ; nPos ; )
+ {
+ pObj = aList.GetObject( --nPos );
+ aCBFrame.InsertEntry( *pObj );
+ delete pObj;
+ }
+ }
+ }
+
+ aRBNoAutoUpdate.SetClickHdl( LINK( this, SfxInternetPage, ClickHdlNoUpdate ) );
+ aRBReloadUpdate.SetClickHdl( LINK( this, SfxInternetPage, ClickHdlReload ) );
+ aRBForwardUpdate.SetClickHdl( LINK( this, SfxInternetPage, ClickHdlForward ) );
+ aPBBrowseURL.SetClickHdl( LINK( this, SfxInternetPage, ClickHdlBrowseURL ) );
+
+ aForwardErrorMessg.SearchAndReplaceAscii( "%PLACEHOLDER%", aRBForwardUpdate.GetText() );
+
+ ChangeState( S_NoUpdate );
+}
+
+//------------------------------------------------------------------------
+
+SfxInternetPage::~SfxInternetPage()
+{
+ delete pFileDlg;
+}
+
+//------------------------------------------------------------------------
+
+void SfxInternetPage::ChangeState( STATE eNewState )
+{
+ DBG_ASSERT( eNewState != S_Init, "*SfxInternetPage::ChangeState(): new state init is supposed to not work here!" );
+
+ if( eState == eNewState )
+ return;
+
+ switch( eState )
+ {
+ case S_Init:
+ EnableNoUpdate( TRUE );
+ EnableReload( FALSE );
+ EnableForward( FALSE );
+ break;
+ case S_NoUpdate:
+ EnableNoUpdate( FALSE );
+ if( eNewState == S_Reload )
+ EnableReload( TRUE );
+ else
+ EnableForward( TRUE );
+ break;
+ case S_Reload:
+ EnableReload( FALSE );
+ if( eNewState == S_NoUpdate )
+ EnableNoUpdate( TRUE );
+ else
+ EnableForward( TRUE );
+ break;
+ case S_Forward:
+ EnableForward( FALSE );
+ if( eNewState == S_NoUpdate )
+ EnableNoUpdate( TRUE );
+ else
+ EnableReload( TRUE );
+ break;
+ default:
+ DBG_ERROR( "*SfxInternetPage::SetState(): unhandled state!" );
+ }
+
+ eState = eNewState;
+}
+
+//------------------------------------------------------------------------
+
+void SfxInternetPage::EnableNoUpdate( BOOL bEnable )
+{
+ if( bEnable )
+ aRBNoAutoUpdate.Check();
+}
+
+//------------------------------------------------------------------------
+
+void SfxInternetPage::EnableReload( BOOL bEnable )
+{
+ aFTEvery.Enable( bEnable );
+ aNFReload.Enable( bEnable );
+ aFTReloadSeconds.Enable( bEnable );
+
+ if( bEnable )
+ aRBReloadUpdate.Check();
+}
+
+//------------------------------------------------------------------------
+
+void SfxInternetPage::EnableForward( BOOL bEnable )
+{
+ aFTAfter.Enable( bEnable );
+ aNFAfter.Enable( bEnable );
+ aFTAfterSeconds.Enable( bEnable );
+ aFTURL.Enable( bEnable );
+ aEDForwardURL.Enable( bEnable );
+ aPBBrowseURL.Enable( bEnable );
+ aFTFrame.Enable( bEnable );
+ aCBFrame.Enable( bEnable );
+
+ if( bEnable )
+ aRBForwardUpdate.Check();
+}
+
+//------------------------------------------------------------------------
+
+IMPL_LINK( SfxInternetPage, ClickHdlNoUpdate, Control*, pCtrl )
+{
+ (void)pCtrl; //unused
+ ChangeState( S_NoUpdate );
+ return 0;
+}
+
+//------------------------------------------------------------------------
+
+IMPL_LINK( SfxInternetPage, ClickHdlReload, Control*, pCtrl )
+{
+ (void)pCtrl; //unused
+ ChangeState( S_Reload );
+ return 0;
+}
+
+//------------------------------------------------------------------------
+
+IMPL_LINK( SfxInternetPage, ClickHdlForward, Control*, pCtrl )
+{
+ (void)pCtrl; //unused
+ ChangeState( S_Forward );
+ return 0;
+}
+
+//------------------------------------------------------------------------
+
+IMPL_LINK( SfxInternetPage, ClickHdlBrowseURL, PushButton*, EMPTYARG )
+{
+ if ( !pFileDlg )
+ pFileDlg = new sfx2::FileDialogHelper( TemplateDescription::FILEOPEN_SIMPLE, WB_OPEN );
+ pFileDlg->SetDisplayDirectory( aEDForwardURL.GetText() );
+ pFileDlg->StartExecuteModal( LINK( this, SfxInternetPage, DialogClosedHdl ) );
+
+ return 0;
+}
+
+//------------------------------------------------------------------------
+
+IMPL_LINK( SfxInternetPage, DialogClosedHdl, sfx2::FileDialogHelper*, EMPTYARG )
+{
+ DBG_ASSERT( pFileDlg, "SfxInternetPage::DialogClosedHdl(): no file dialog" );
+
+ if ( ERRCODE_NONE == pFileDlg->GetError() )
+ aEDForwardURL.SetText( pFileDlg->GetPath() );
+
+ return 0;
+}
+
+//------------------------------------------------------------------------
+
+BOOL SfxInternetPage::FillItemSet( SfxItemSet& rSet )
+{
+ const SfxPoolItem* pItem = NULL;
+ SfxDocumentInfoItem* pInfo = NULL;
+ SfxTabDialog* pDlg = GetTabDialog();
+ const SfxItemSet* pExSet = NULL;
+
+ if( pDlg )
+ pExSet = pDlg->GetExampleSet();
+
+ if( pExSet && SFX_ITEM_SET != pExSet->GetItemState( SID_DOCINFO, TRUE, &pItem ) )
+ pInfo = pInfoItem;
+ else if ( pItem )
+ pInfo = new SfxDocumentInfoItem( *(const SfxDocumentInfoItem*)pItem );
+
+ if ( !pInfo )
+ {
+ DBG_ERRORFILE( "SfxInternetPage::FillItemSet(): no item found" );
+ return FALSE;
+ }
+
+ DBG_ASSERT( eState != S_Init, "*SfxInternetPage::FillItemSet(): state init is not acceptable at this point!" );
+
+ BOOL bEnableReload = FALSE;
+ ::std::auto_ptr< String > aURL( NULL );
+ ::std::auto_ptr< String > aFrame( NULL );
+ ULONG nDelay = 0;
+
+ switch( eState )
+ {
+ case S_NoUpdate:
+ break;
+ case S_Reload:
+ bEnableReload = TRUE;
+ aURL = ::std::auto_ptr< String >( new String() );
+ aFrame = ::std::auto_ptr< String >( new String() );
+ nDelay = static_cast<ULONG>(aNFReload.GetValue());
+ break;
+ case S_Forward:
+ DBG_ASSERT( aEDForwardURL.GetText().Len(), "+SfxInternetPage::FillItemSet(): empty URL should be not possible for forward option!" );
+
+ bEnableReload = TRUE;
+ aURL = ::std::auto_ptr< String >( new String( URIHelper::SmartRel2Abs( INetURLObject(aBaseURL), aEDForwardURL.GetText(), URIHelper::GetMaybeFileHdl(), true ) ) );
+ aFrame = ::std::auto_ptr< String >( new String( aCBFrame.GetText() ) );
+ nDelay = static_cast<ULONG>(aNFAfter.GetValue());
+ break;
+ default:
+ break;
+ }
+
+ pInfo->setAutoloadEnabled( bEnableReload );
+
+ if( bEnableReload )
+ {
+ pInfo->setAutoloadURL( *aURL.get() );
+ pInfo->setDefaultTarget( *aFrame.get() );
+ pInfo->setAutoloadDelay( nDelay );
+ }
+
+ rSet.Put( *pInfo );
+ if( pInfo != pInfoItem )
+ delete pInfo;
+ return TRUE;
+}
+
+//------------------------------------------------------------------------
+
+SfxTabPage *SfxInternetPage::Create( Window* pParent, const SfxItemSet& rItemSet )
+{
+ return new SfxInternetPage(pParent, rItemSet);
+}
+
+//------------------------------------------------------------------------
+
+void SfxInternetPage::Reset( const SfxItemSet& rSet )
+{
+ pInfoItem = &( SfxDocumentInfoItem& ) rSet.Get( SID_DOCINFO );
+ SFX_ITEMSET_ARG( &rSet, pURLItem, SfxStringItem, SID_BASEURL, FALSE );
+ DBG_ASSERT( pURLItem, "No BaseURL provided for InternetTabPage!" );
+ if ( pURLItem )
+ aBaseURL = pURLItem->GetValue();
+
+ STATE eNewState = S_NoUpdate;
+
+ if( pInfoItem->isAutoloadEnabled() )
+ {
+ const String& rURL = pInfoItem->getAutoloadURL();
+
+ if( rURL.Len() )
+ {
+ aNFAfter.SetValue( pInfoItem->getAutoloadDelay() );
+ aEDForwardURL.SetText( rURL );
+ aCBFrame.SetText( pInfoItem->getDefaultTarget() );
+ eNewState = S_Forward;
+ }
+ else
+ {
+ aNFReload.SetValue( pInfoItem->getAutoloadDelay() );
+ eNewState = S_Reload;
+ }
+ }
+
+ ChangeState( eNewState );
+
+ // #102907# ------------------------
+ SFX_ITEMSET_ARG( &rSet, pROItem, SfxBoolItem, SID_DOC_READONLY, FALSE );
+ if ( pROItem && pROItem->GetValue() )
+ {
+ aRBNoAutoUpdate.Disable();
+ aRBReloadUpdate.Disable();
+ aRBForwardUpdate.Disable();
+ aNFReload.Disable();
+ aNFAfter.Disable();
+ aEDForwardURL.Disable();
+ aPBBrowseURL.Disable();
+ aCBFrame.Disable();
+ aFTEvery.Disable();
+ aFTReloadSeconds.Disable();
+ aFTAfter.Disable();
+ aFTAfterSeconds.Disable();
+ aFTURL.Disable();
+ aFTFrame.Disable();
+ }
+}
+
+//------------------------------------------------------------------------
+
+int SfxInternetPage::DeactivatePage( SfxItemSet* /*pSet*/ )
+{
+ int nRet = LEAVE_PAGE;
+
+ if( eState == S_Forward && !aEDForwardURL.GetText().Len() )
+ {
+ ErrorBox aErrBox( this, WB_OK, aForwardErrorMessg );
+ aErrBox.Execute();
+
+ nRet = KEEP_PAGE;
+ }
+
+ return nRet;
+}
+
+//------------------------------------------------------------------------
+
+SfxDocumentInfoDialog::SfxDocumentInfoDialog( Window* pParent,
+ const SfxItemSet& rItemSet ) :
+
+ SfxTabDialog( 0, pParent, SfxResId( SID_DOCINFO ), &rItemSet )
+
+{
+ FreeResource();
+
+ const SfxDocumentInfoItem* pInfoItem =
+ &(const SfxDocumentInfoItem &)rItemSet.Get( SID_DOCINFO );
+
+#ifdef DBG_UTIL
+ SFX_ITEMSET_ARG( &rItemSet, pURLItem, SfxStringItem, SID_BASEURL, FALSE );
+ DBG_ASSERT( pURLItem, "No BaseURL provided for InternetTabPage!" );
+#endif
+
+ // Bestimmung des Titels
+ const SfxPoolItem* pItem = 0;
+ String aTitle( GetText() );
+ if ( SFX_ITEM_SET !=
+ rItemSet.GetItemState( SID_EXPLORER_PROPS_START, FALSE, &pItem ) )
+ {
+ // Dateiname
+ String aFile( pInfoItem->GetValue() );
+
+ INetURLObject aURL;
+ aURL.SetSmartProtocol( INET_PROT_FILE );
+ aURL.SetSmartURL( aFile);
+ if ( INET_PROT_PRIV_SOFFICE != aURL.GetProtocol() )
+ {
+ String aLastName( aURL.GetLastName() );
+ if ( aLastName.Len() )
+ aTitle += aLastName;
+ else
+ aTitle += aFile;
+ }
+ else
+ aTitle += String( SfxResId( STR_NONAME ) );
+ }
+ else
+ {
+ DBG_ASSERT( pItem->IsA( TYPE( SfxStringItem ) ),
+ "SfxDocumentInfoDialog:<SfxStringItem> erwartet" );
+ aTitle += ( ( SfxStringItem* ) pItem )->GetValue();
+ }
+ SetText( aTitle );
+
+ // Eigenschaftenseiten
+ AddTabPage(TP_DOCINFODESC, SfxDocumentDescPage::Create, 0);
+ AddTabPage(TP_DOCINFODOC, SfxDocumentPage::Create, 0);
+ AddTabPage(TP_CUSTOMPROPERTIES, SfxCustomPropertiesPage::Create, 0);
+ AddTabPage(TP_DOCINFORELOAD, SfxInternetPage::Create, 0);
+ AddTabPage(TP_DOCINFOSECURITY, SfxSecurityPage::Create, 0);
+}
+
+// -----------------------------------------------------------------------
+
+void SfxDocumentInfoDialog::PageCreated( USHORT nId, SfxTabPage &rPage )
+{
+ if ( TP_DOCINFODOC == nId )
+ ( (SfxDocumentPage&)rPage ).EnableUseUserData();
+}
+
+// class CustomPropertiesYesNoButton -------------------------------------
+
+CustomPropertiesYesNoButton::CustomPropertiesYesNoButton( Window* pParent, const ResId& rResId ) :
+ Control( pParent, rResId ),
+ m_aYesButton( this, ResId( RB_PROPERTY_YES, *rResId.GetResMgr() ) ),
+ m_aNoButton ( this, ResId( RB_PROPERTY_NO, *rResId.GetResMgr() ) )
+{
+ FreeResource();
+ Wallpaper aWall( Color( COL_TRANSPARENT ) );
+ SetBackground( aWall );
+ SetBorderStyle( WINDOW_BORDER_MONO );
+ CheckNo();
+ m_aYesButton.SetBackground( aWall );
+ m_aNoButton.SetBackground( aWall );
+}
+class DurationDialog_Impl : public ModalDialog
+{
+ FixedLine aDurationFL;
+
+ OKButton aOKPB;
+ CancelButton aCancelPB;
+ HelpButton aHelpPB;
+
+ CheckBox aNegativeCB;
+ FixedText aYearFT;
+ NumericField aYearNF;
+ FixedText aMonthFT;
+ NumericField aMonthNF;
+ FixedText aDayFT;
+ NumericField aDayNF;
+ FixedText aHourFT;
+ NumericField aHourNF;
+ FixedText aMinuteFT;
+ NumericField aMinuteNF;
+ FixedText aSecondFT;
+ NumericField aSecondNF;
+ FixedText aMSecondFT;
+ NumericField aMSecondNF;
+
+public:
+
+ DurationDialog_Impl( Window* pParent, const util::Duration& rDuration );
+ ~DurationDialog_Impl();
+
+ util::Duration GetDuration() const;
+};
+/*-- 20.11.2009 15:40:46---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+DurationDialog_Impl::DurationDialog_Impl(
+ Window* pParent, const util::Duration& rDuration)
+ : ModalDialog( pParent, SfxResId( RID_EDIT_DURATIONS ) ),
+ aDurationFL(this, SfxResId( FL_DURATION )),
+ aOKPB( this, SfxResId( PB_OK )),
+ aCancelPB( this, SfxResId( PB_CANCEL )),
+ aHelpPB( this, SfxResId( PB_HELP )),
+ aNegativeCB(this, SfxResId( CB_NEGATIVE )),
+ aYearFT( this, SfxResId( FT_YEAR )),
+ aYearNF( this, SfxResId( ED_YEAR )),
+ aMonthFT( this, SfxResId( FT_MONTH )),
+ aMonthNF( this, SfxResId( ED_MONTH )),
+ aDayFT( this, SfxResId( FT_DAY )),
+ aDayNF( this, SfxResId( ED_DAY )),
+ aHourFT( this, SfxResId( FT_HOUR )),
+ aHourNF( this, SfxResId( ED_HOUR )),
+ aMinuteFT( this, SfxResId( FT_MINUTE )),
+ aMinuteNF( this, SfxResId( ED_MINUTE )),
+ aSecondFT( this, SfxResId( FT_SECOND )),
+ aSecondNF( this, SfxResId( ED_SECOND )),
+ aMSecondFT( this, SfxResId( FT_MSECOND )),
+ aMSecondNF( this, SfxResId( ED_MSECOND ))
+{
+ FreeResource();
+ aNegativeCB.Check(rDuration.Negative);
+ aYearNF.SetValue(rDuration.Years);
+ aMonthNF.SetValue(rDuration.Months );
+ aDayNF.SetValue(rDuration.Days );
+ aHourNF.SetValue(rDuration.Hours );
+ aMinuteNF.SetValue(rDuration.Minutes);
+ aSecondNF.SetValue(rDuration.Seconds);
+ aMSecondNF.SetValue(rDuration.MilliSeconds);
+}
+/*-- 20.11.2009 16:08:55---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+DurationDialog_Impl::~DurationDialog_Impl()
+{
+}
+/*-- 20.11.2009 15:41:47---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+util::Duration DurationDialog_Impl::GetDuration() const
+{
+ util::Duration aRet;
+ aRet.Negative = aNegativeCB.IsChecked();
+ aRet.Years = aYearNF.GetValue();
+ aRet.Months = aMonthNF.GetValue( );
+ aRet.Days = aDayNF.GetValue( );
+ aRet.Hours = aHourNF.GetValue( );
+ aRet.Minutes = aMinuteNF.GetValue();
+ aRet.Seconds = aSecondNF.GetValue();
+ aRet.MilliSeconds = aMSecondNF.GetValue();
+ return aRet;
+}
+
+/*-- 20.11.2009 15:30:58---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+CustomPropertiesDurationField::CustomPropertiesDurationField( Window* pParent, const ResId& rResId, CustomPropertyLine* pLine ) :
+ Edit( pParent, rResId ), m_pLine( pLine )
+
+{
+ SetDuration( util::Duration(false, 0, 0, 0, 0, 0, 0, 0) );
+}
+/*-- 23.11.2009 08:46:02---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+CustomPropertiesDurationField::~CustomPropertiesDurationField()
+{
+}
+/*-- 23.11.2009 09:23:35---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+void CustomPropertiesDurationField::RequestHelp( const HelpEvent& rHEvt )
+{
+ if( rHEvt.GetMode() & HELPMODE_QUICK )
+ {
+ Size aSize( GetSizePixel() );
+ Rectangle aItemRect( rHEvt.GetMousePosPixel(), aSize );
+ if(Help::IsBalloonHelpEnabled())
+ Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), GetText() );
+ else
+ Help::ShowQuickHelp( this, aItemRect, GetText(),
+ QUICKHELP_LEFT|QUICKHELP_VCENTER );
+ }
+}
+/*-- 20.11.2009 15:30:58---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+void CustomPropertiesDurationField::SetDuration( const util::Duration& rDuration )
+{
+ m_aDuration = rDuration;
+ String sText(rDuration.Negative ? '-' : '+');
+ sText += m_pLine->m_sDurationFormat;
+ sText.SearchAndReplace(String::CreateFromAscii( "%1"), String::CreateFromInt32( rDuration.Years ) );
+ sText.SearchAndReplace(String::CreateFromAscii( "%2"), String::CreateFromInt32( rDuration.Months ) );
+ sText.SearchAndReplace(String::CreateFromAscii( "%3"), String::CreateFromInt32( rDuration.Days ) );
+ sText.SearchAndReplace(String::CreateFromAscii( "%4"), String::CreateFromInt32( rDuration.Hours ) );
+ sText.SearchAndReplace(String::CreateFromAscii( "%5"), String::CreateFromInt32( rDuration.Minutes) );
+ sText.SearchAndReplace(String::CreateFromAscii( "%6"), String::CreateFromInt32( rDuration.Seconds) );
+ SetText( sText );
+}
+/*-- 23.11.2009 08:51:15---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+CustomPropertiesEditButton::CustomPropertiesEditButton( Window* pParent, const ResId& rResId, CustomPropertyLine* pLine ) :
+ PushButton( pParent, rResId ), m_pLine( pLine )
+{
+ SetClickHdl( LINK( this, CustomPropertiesEditButton, ClickHdl ));
+}
+/*-- 23.11.2009 08:51:15---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+CustomPropertiesEditButton::~CustomPropertiesEditButton()
+{
+}
+/*-- 23.11.2009 08:47:37---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+IMPL_LINK( CustomPropertiesEditButton, ClickHdl, PushButton*, EMPTYARG )
+{
+ DurationDialog_Impl* pDurationDlg = new DurationDialog_Impl( this, m_pLine->m_aDurationField.GetDuration() );
+ if( RET_OK == pDurationDlg->Execute() )
+ m_pLine->m_aDurationField.SetDuration( pDurationDlg->GetDuration() );
+ delete pDurationDlg;
+ return 1;
+}
+//--------------------------------------------------------------------------
+void CustomPropertiesYesNoButton::Resize()
+{
+ const long nWidth = GetSizePixel().Width();
+ const long n3Width = LogicToPixel( Size( 3, 3 ), MAP_APPFONT ).Width();
+ const long nNewWidth = ( nWidth / 2 ) - n3Width - 2;
+ Size aSize = m_aYesButton.GetSizePixel();
+ const long nDelta = aSize.Width() - nNewWidth;
+ aSize.Width() = nNewWidth;
+ m_aYesButton.SetSizePixel( aSize );
+ Point aPos = m_aNoButton.GetPosPixel();
+ aPos.X() -= nDelta;
+ m_aNoButton.SetPosSizePixel( aPos, aSize );
+}
+
+// struct CustomPropertyLine ---------------------------------------------
+
+CustomPropertyLine::CustomPropertyLine( Window* pParent ) :
+ m_aNameBox ( pParent, SfxResId( SFX_CB_PROPERTY_NAME ) ),
+ m_aTypeBox ( pParent, SfxResId( SFX_LB_PROPERTY_TYPE ), this ),
+ m_aValueEdit ( pParent, SfxResId( SFX_ED_PROPERTY_VALUE ), this ),
+ m_aDateField ( pParent, SfxResId( SFX_FLD_DATE), this),
+ m_aTimeField ( pParent, SfxResId( SFX_FLD_TIME), this),
+ m_sDurationFormat( SfxResId( SFX_ST_DURATION_FORMAT )),
+ m_aDurationField( pParent, SfxResId( SFX_FLD_DURATION), this),
+ m_aEditButton( pParent, SfxResId( SFX_PB_EDIT ), this),
+ m_aYesNoButton ( pParent, SfxResId( SFX_WIN_PROPERTY_YESNO ) ),
+ m_aRemoveButton ( pParent, SfxResId( SFX_PB_PROPERTY_REMOVE ), this ),
+ m_bIsRemoved ( false ),
+ m_bTypeLostFocus( false )
+
+{
+ m_aTimeField.SetExtFormat( EXTTIMEF_24H_LONG );
+ m_aDateField.SetExtDateFormat( XTDATEF_SYSTEM_SHORT_YYYY );
+
+ m_aRemoveButton.SetModeImage( SfxResId( SFX_IMG_PROPERTY_REMOVE ), BMP_COLOR_NORMAL );
+ m_aRemoveButton.SetModeImage( SfxResId( SFX_IMG_PROPERTY_REMOVE_HC ), BMP_COLOR_HIGHCONTRAST );
+}
+
+void CustomPropertyLine::SetRemoved()
+{
+ DBG_ASSERT( !m_bIsRemoved, "CustomPropertyLine::SetRemoved(): line already removed" );
+ m_bIsRemoved = true;
+ m_aNameBox.Hide();
+ m_aTypeBox.Hide();
+ m_aValueEdit.Hide();
+ m_aDateField.Hide();
+ m_aTimeField.Hide();
+ m_aDurationField.Hide();
+ m_aEditButton.Hide();
+ m_aYesNoButton.Hide();
+ m_aRemoveButton.Hide();
+}
+
+// class CustomPropertiesWindow ------------------------------------------
+
+CustomPropertiesWindow::CustomPropertiesWindow( Window* pParent, const ResId& rResId ) :
+
+ Window( pParent, rResId ),
+ m_aNameBox ( this, SfxResId( SFX_CB_PROPERTY_NAME ) ),
+ m_aTypeBox ( this, SfxResId( SFX_LB_PROPERTY_TYPE ) ),
+ m_aValueEdit ( this, SfxResId( SFX_ED_PROPERTY_VALUE ) ),
+ m_aDateField ( this, SfxResId( SFX_FLD_DATE) ),
+ m_aTimeField ( this, SfxResId( SFX_FLD_TIME) ),
+ m_aDurationField( this, SfxResId( SFX_FLD_DURATION) ),
+ m_aEditButton( this, SfxResId( SFX_PB_EDIT )),
+ m_aYesNoButton ( this, SfxResId( SFX_WIN_PROPERTY_YESNO ) ),
+ m_aRemoveButton ( this, SfxResId( SFX_PB_PROPERTY_REMOVE ) ),
+ m_nScrollPos (0),
+ m_aNumberFormatter( ::comphelper::getProcessServiceFactory(),
+ Application::GetSettings().GetLanguage() )
+
+{
+ m_aEditLoseFocusTimer.SetTimeout( 300 );
+ m_aEditLoseFocusTimer.SetTimeoutHdl( LINK( this, CustomPropertiesWindow, EditTimeoutHdl ) );
+ m_aBoxLoseFocusTimer.SetTimeout( 300 );
+ m_aBoxLoseFocusTimer.SetTimeoutHdl( LINK( this, CustomPropertiesWindow, BoxTimeoutHdl ) );
+}
+
+CustomPropertiesWindow::~CustomPropertiesWindow()
+{
+ m_aEditLoseFocusTimer.Stop();
+ m_aBoxLoseFocusTimer.Stop();
+ ClearAllLines();
+}
+
+IMPL_LINK( CustomPropertiesWindow, TypeHdl, CustomPropertiesTypeBox*, pBox )
+{
+ sal_Int64 nType = sal_Int64( (long)pBox->GetEntryData( pBox->GetSelectEntryPos() ) );
+ CustomPropertyLine* pLine = pBox->GetLine();
+ pLine->m_aValueEdit.Show( (CUSTOM_TYPE_TEXT == nType) || (CUSTOM_TYPE_NUMBER == nType) );
+ pLine->m_aDateField.Show( (CUSTOM_TYPE_DATE == nType) || (CUSTOM_TYPE_DATETIME == nType) );
+ pLine->m_aTimeField.Show( CUSTOM_TYPE_DATETIME == nType );
+ pLine->m_aDurationField.Show( CUSTOM_TYPE_DURATION == nType );
+ pLine->m_aEditButton.Show( CUSTOM_TYPE_DURATION == nType );
+ pLine->m_aYesNoButton.Show( CUSTOM_TYPE_BOOLEAN == nType );
+ //adjust positions of date and time controls
+ if( nType == CUSTOM_TYPE_DATE )
+ {
+ pLine->m_aDateField.SetPosSizePixel(pLine->m_aValueEdit.GetPosPixel(), pLine->m_aValueEdit.GetSizePixel());
+ }
+ else if( nType == CUSTOM_TYPE_DATETIME)
+ {
+ pLine->m_aDateField.SetPosSizePixel( pLine->m_aDatePos, pLine->m_aDateTimeSize );
+ pLine->m_aTimeField.SetPosSizePixel(pLine->m_aTimePos, pLine->m_aDateTimeSize );
+ }
+
+ return 0;
+}
+
+IMPL_LINK( CustomPropertiesWindow, RemoveHdl, CustomPropertiesRemoveButton*, pButton )
+{
+ CustomPropertyLine* pLine = pButton->GetLine();
+ std::vector< CustomPropertyLine* >::iterator pFound =
+ std::find( m_aCustomPropertiesLines.begin(), m_aCustomPropertiesLines.end(), pLine );
+ if ( pFound != m_aCustomPropertiesLines.end() )
+ {
+ pLine = *pFound;
+ pLine->SetRemoved();
+ std::vector< CustomPropertyLine* >::iterator pIter = pFound + 1;
+ const long nDelta = GetLineHeight();
+ for ( ; pIter != m_aCustomPropertiesLines.end(); ++pIter )
+ {
+ pLine = *pIter;
+ if ( pLine->m_bIsRemoved )
+ continue;
+
+ Window* pWindows[] = { &pLine->m_aNameBox, &pLine->m_aTypeBox, &pLine->m_aValueEdit,
+ &pLine->m_aDateField, &pLine->m_aTimeField,
+ &pLine->m_aDurationField, &pLine->m_aEditButton,
+ &pLine->m_aYesNoButton, &pLine->m_aRemoveButton, NULL };
+ Window** pCurrent = pWindows;
+ while ( *pCurrent )
+ {
+ Point aPos = (*pCurrent)->GetPosPixel();
+ aPos.Y() -= nDelta;
+ (*pCurrent)->SetPosPixel( aPos );
+ pCurrent++;
+ }
+ }
+ }
+
+ m_aRemovedHdl.Call(0);
+ return 0;
+}
+
+IMPL_LINK( CustomPropertiesWindow, EditLoseFocusHdl, CustomPropertiesEdit*, pEdit )
+{
+ if ( pEdit )
+ {
+ CustomPropertyLine* pLine = pEdit->GetLine();
+ if ( !pLine->m_bTypeLostFocus )
+ {
+ m_pCurrentLine = pLine;
+ m_aEditLoseFocusTimer.Start();
+ }
+ else
+ pLine->m_bTypeLostFocus = false;
+ }
+ return 0;
+}
+
+IMPL_LINK( CustomPropertiesWindow, BoxLoseFocusHdl, CustomPropertiesTypeBox*, pBox )
+{
+ if ( pBox )
+ {
+ m_pCurrentLine = pBox->GetLine();
+ m_aBoxLoseFocusTimer.Start();
+ }
+
+ return 0;
+}
+
+IMPL_LINK( CustomPropertiesWindow, EditTimeoutHdl, Timer*, EMPTYARG )
+{
+ ValidateLine( m_pCurrentLine, false );
+ return 0;
+}
+
+IMPL_LINK( CustomPropertiesWindow, BoxTimeoutHdl, Timer*, EMPTYARG )
+{
+ ValidateLine( m_pCurrentLine, true );
+ return 0;
+}
+
+bool CustomPropertiesWindow::IsLineValid( CustomPropertyLine* pLine ) const
+{
+ bool bIsValid = true;
+ pLine->m_bTypeLostFocus = false;
+ sal_Int64 nType = sal_Int64(
+ (long)pLine->m_aTypeBox.GetEntryData( pLine->m_aTypeBox.GetSelectEntryPos() ) );
+ String sValue = pLine->m_aValueEdit.GetText();
+ if ( sValue.Len() == 0 )
+ return true;
+
+ double fDummy = 0.0;
+ sal_uInt32 nIndex = 0xFFFFFFFF;
+ if ( CUSTOM_TYPE_NUMBER == nType )
+ nIndex = const_cast< SvNumberFormatter& >(
+ m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM );
+ else if ( CUSTOM_TYPE_DATE == nType )
+ nIndex = const_cast< SvNumberFormatter& >(
+ m_aNumberFormatter).GetFormatIndex( NF_DATE_SYS_DDMMYYYY );
+
+ if ( nIndex != 0xFFFFFFFF )
+ {
+ sal_uInt32 nTemp = nIndex;
+ bIsValid = const_cast< SvNumberFormatter& >(
+ m_aNumberFormatter ).IsNumberFormat( sValue, nIndex, fDummy ) != FALSE;
+ if ( bIsValid && nTemp != nIndex )
+ // sValue is a number but the format doesn't match the index
+ bIsValid = false;
+ }
+
+ return bIsValid;
+}
+
+void CustomPropertiesWindow::ValidateLine( CustomPropertyLine* pLine, bool bIsFromTypeBox )
+{
+ if ( !IsLineValid( pLine ) )
+ {
+ if ( bIsFromTypeBox ) // LoseFocus of TypeBox
+ pLine->m_bTypeLostFocus = true;
+ Window* pParent = GetParent()->GetParent();
+ if ( QueryBox( pParent, SfxResId( SFX_QB_WRONG_TYPE ) ).Execute() == RET_OK )
+ pLine->m_aTypeBox.SelectEntryPos( m_aTypeBox.GetEntryPos( (void*)CUSTOM_TYPE_TEXT ) );
+ else
+ pLine->m_aValueEdit.GrabFocus();
+ }
+}
+
+void CustomPropertiesWindow::InitControls( HeaderBar* pHeaderBar, const ScrollBar* pScrollBar )
+{
+ DBG_ASSERT( pHeaderBar, "CustomPropertiesWindow::InitControls(): invalid headerbar" );
+ DBG_ASSERT( pScrollBar, "CustomPropertiesWindow::InitControls(): invalid scrollbar" );
+
+ m_aNameBox.Hide();
+ m_aTypeBox.Hide();
+ m_aValueEdit.Hide();
+ m_aDateField.Hide();
+ m_aTimeField.Hide();
+ m_aDurationField.Hide();
+ m_aEditButton.Hide();
+ m_aYesNoButton.Hide();
+ m_aRemoveButton.Hide();
+
+ const long nOffset = 4;
+ const long nScrollBarWidth = pScrollBar->GetSizePixel().Width();
+ const long nButtonWidth = m_aRemoveButton.GetSizePixel().Width() + nScrollBarWidth + nOffset;
+ long nTypeWidth = m_aTypeBox.CalcMinimumSize().Width() + ( 2 * nOffset );
+ long nFullWidth = pHeaderBar->GetSizePixel().Width();
+ long nItemWidth = ( nFullWidth - nTypeWidth - nButtonWidth ) / 2;
+ pHeaderBar->SetItemSize( HI_NAME, nItemWidth );
+ pHeaderBar->SetItemSize( HI_TYPE, nTypeWidth );
+ pHeaderBar->SetItemSize( HI_VALUE, nItemWidth );
+ pHeaderBar->SetItemSize( HI_ACTION, nButtonWidth );
+
+ Window* pWindows[] = { &m_aNameBox, &m_aTypeBox, &m_aValueEdit, &m_aRemoveButton, NULL };
+ Window** pCurrent = pWindows;
+ USHORT nPos = 0;
+ while ( *pCurrent )
+ {
+ Rectangle aRect = pHeaderBar->GetItemRect( pHeaderBar->GetItemId( nPos++ ) );
+ Size aSize = (*pCurrent)->GetSizePixel();
+ Point aPos = (*pCurrent)->GetPosPixel();
+ long nWidth = aRect.getWidth() - nOffset;
+ if ( *pCurrent == &m_aRemoveButton )
+ nWidth -= pScrollBar->GetSizePixel().Width();
+ aSize.Width() = nWidth;
+ aPos.X() = aRect.getX() + ( nOffset / 2 );
+ (*pCurrent)->SetPosSizePixel( aPos, aSize );
+
+ if ( *pCurrent == &m_aValueEdit )
+ {
+ Point aDurationPos( aPos );
+ m_aDurationField.SetPosPixel( aDurationPos );
+ Size aDurationSize(aSize);
+ aDurationSize.Width() -= (m_aEditButton.GetSizePixel().Width() + 3 );
+ m_aDurationField.SetSizePixel(aDurationSize);
+ aDurationPos.X() = aPos.X() - m_aEditButton.GetSizePixel().Width() + aSize.Width();
+ m_aEditButton.SetPosPixel(aDurationPos);
+ aSize = m_aYesNoButton.GetSizePixel();
+ aPos = m_aYesNoButton.GetPosPixel();
+ aSize.Width() = nWidth;
+ aPos.X() = aRect.getX() + ( nOffset / 2 );
+ m_aYesNoButton.SetPosSizePixel( aPos, aSize );
+ aSize.Width() /= 2;
+ aSize.Width() -= 2;
+ m_aDateField.SetPosSizePixel( aPos, aSize );
+ aPos.X() += aSize.Width() + 4;
+ m_aTimeField.SetPosSizePixel( aPos, aSize );
+ }
+
+ pCurrent++;
+ }
+
+ m_nLineHeight =
+ ( m_aRemoveButton.GetPosPixel().Y() * 2 ) + m_aRemoveButton.GetSizePixel().Height();
+}
+
+USHORT CustomPropertiesWindow::GetVisibleLineCount() const
+{
+ USHORT nCount = 0;
+ std::vector< CustomPropertyLine* >::const_iterator pIter;
+ for ( pIter = m_aCustomPropertiesLines.begin();
+ pIter != m_aCustomPropertiesLines.end(); ++pIter )
+ {
+ CustomPropertyLine* pLine = *pIter;
+ if ( !pLine->m_bIsRemoved )
+ nCount++;
+ }
+ return nCount;
+}
+
+void CustomPropertiesWindow::AddLine( const ::rtl::OUString& sName, Any& rAny )
+{
+ CustomPropertyLine* pNewLine = new CustomPropertyLine( this );
+ pNewLine->m_aTypeBox.SetSelectHdl( LINK( this, CustomPropertiesWindow, TypeHdl ) );
+ pNewLine->m_aRemoveButton.SetClickHdl( LINK( this, CustomPropertiesWindow, RemoveHdl ) );
+ pNewLine->m_aValueEdit.SetLoseFocusHdl( LINK( this, CustomPropertiesWindow, EditLoseFocusHdl ) );
+ //add lose focus handlers of date/time fields
+
+ pNewLine->m_aTypeBox.SetLoseFocusHdl( LINK( this, CustomPropertiesWindow, BoxLoseFocusHdl ) );
+ long nPos = GetVisibleLineCount() * GetLineHeight();
+ m_aCustomPropertiesLines.push_back( pNewLine );
+ Window* pWindows[] = { &m_aNameBox, &m_aTypeBox, &m_aValueEdit,
+ &m_aDateField, &m_aTimeField,
+ &m_aDurationField, &m_aEditButton,
+ &m_aYesNoButton, &m_aRemoveButton, NULL };
+ Window* pNewWindows[] =
+ { &pNewLine->m_aNameBox, &pNewLine->m_aTypeBox, &pNewLine->m_aValueEdit,
+ &pNewLine->m_aDateField, &pNewLine->m_aTimeField,
+ &pNewLine->m_aDurationField, &pNewLine->m_aEditButton,
+ &pNewLine->m_aYesNoButton, &pNewLine->m_aRemoveButton, NULL };
+ Window** pCurrent = pWindows;
+ Window** pNewCurrent = pNewWindows;
+ while ( *pCurrent )
+ {
+ Size aSize = (*pCurrent)->GetSizePixel();
+ Point aPos = (*pCurrent)->GetPosPixel();
+ aPos.Y() += nPos;
+ aPos.Y() += m_nScrollPos;
+ (*pNewCurrent)->SetPosSizePixel( aPos, aSize );
+ (*pNewCurrent)->Show();
+ pCurrent++;
+ pNewCurrent++;
+ }
+ //
+ pNewLine->m_aDatePos = pNewLine->m_aDateField.GetPosPixel();
+ pNewLine->m_aTimePos = pNewLine->m_aTimeField.GetPosPixel();
+ pNewLine->m_aDateTimeSize = pNewLine->m_aDateField.GetSizePixel();
+
+ double nTmpValue = 0;
+ bool bTmpValue = false;
+ ::rtl::OUString sTmpValue;
+ util::DateTime aTmpDateTime;
+ util::Date aTmpDate;
+ util::Duration aTmpDuration;
+ SvtSysLocale aSysLocale;
+ const LocaleDataWrapper& rLocaleWrapper = aSysLocale.GetLocaleData();
+ pNewLine->m_aNameBox.SetText( sName );
+ sal_Int32 nType = CUSTOM_TYPE_UNKNOWN;
+ String sValue;
+
+ if ( rAny >>= nTmpValue )
+ {
+ sal_uInt32 nIndex = m_aNumberFormatter.GetFormatIndex( NF_NUMBER_SYSTEM );
+ m_aNumberFormatter.GetInputLineString( nTmpValue, nIndex, sValue );
+ pNewLine->m_aValueEdit.SetText( sValue );
+ nType = CUSTOM_TYPE_NUMBER;
+ }
+ else if ( rAny >>= bTmpValue )
+ {
+ sValue = ( bTmpValue ? rLocaleWrapper.getTrueWord() : rLocaleWrapper.getFalseWord() );
+ nType = CUSTOM_TYPE_BOOLEAN;
+ }
+ else if ( rAny >>= sTmpValue )
+ {
+ pNewLine->m_aValueEdit.SetText( sTmpValue );
+ nType = CUSTOM_TYPE_TEXT;
+ }
+ else if ( rAny >>= aTmpDate )
+ {
+ nType = CUSTOM_TYPE_DATE;
+ pNewLine->m_aDateField.SetDate( Date( aTmpDate.Day, aTmpDate.Month, aTmpDate.Year ) );
+
+ }
+ else if ( rAny >>= aTmpDuration )
+ {
+ nType = CUSTOM_TYPE_DURATION;
+ pNewLine->m_aDurationField.SetDuration( aTmpDuration );
+ }
+ else if ( rAny >>= aTmpDateTime )
+ {
+ pNewLine->m_aDateField.SetDate( Date( aTmpDateTime.Day, aTmpDateTime.Month, aTmpDateTime.Year ) );
+ pNewLine->m_aTimeField.SetTime( Time( aTmpDateTime.Hours, aTmpDateTime.Minutes, aTmpDateTime.Seconds, aTmpDateTime.HundredthSeconds ) );
+
+ nType = CUSTOM_TYPE_DATETIME;
+ }
+
+ if ( nType != CUSTOM_TYPE_UNKNOWN )
+ {
+ if ( CUSTOM_TYPE_BOOLEAN == nType )
+ {
+ if ( bTmpValue )
+ pNewLine->m_aYesNoButton.CheckYes();
+ else
+ pNewLine->m_aYesNoButton.CheckNo();
+ }
+ pNewLine->m_aTypeBox.SelectEntryPos( m_aTypeBox.GetEntryPos( (void*)nType ) );
+ }
+
+ TypeHdl( &pNewLine->m_aTypeBox );
+ pNewLine->m_aNameBox.GrabFocus();
+}
+
+bool CustomPropertiesWindow::AreAllLinesValid() const
+{
+ bool bRet = true;
+ std::vector< CustomPropertyLine* >::const_iterator pIter;
+ for ( pIter = m_aCustomPropertiesLines.begin();
+ pIter != m_aCustomPropertiesLines.end(); ++pIter )
+ {
+ CustomPropertyLine* pLine = *pIter;
+ if ( !IsLineValid( pLine ) )
+ {
+ bRet = false;
+ break;
+ }
+ }
+
+ return bRet;
+}
+
+void CustomPropertiesWindow::ClearAllLines()
+{
+ std::vector< CustomPropertyLine* >::iterator pIter;
+ for ( pIter = m_aCustomPropertiesLines.begin();
+ pIter != m_aCustomPropertiesLines.end(); ++pIter )
+ {
+ CustomPropertyLine* pLine = *pIter;
+ pLine->SetRemoved();
+ delete pLine;
+ }
+ m_aCustomPropertiesLines.clear();
+ m_nScrollPos = 0;
+}
+
+void CustomPropertiesWindow::DoScroll( sal_Int32 nNewPos )
+{
+ m_nScrollPos += nNewPos;
+ std::vector< CustomPropertyLine* >::iterator pIter;
+ for ( pIter = m_aCustomPropertiesLines.begin();
+ pIter != m_aCustomPropertiesLines.end(); ++pIter )
+ {
+ CustomPropertyLine* pLine = *pIter;
+ if ( pLine->m_bIsRemoved )
+ continue;
+
+ Window* pWindows[] = { &pLine->m_aNameBox, &pLine->m_aTypeBox, &pLine->m_aValueEdit, &pLine->m_aDurationField,
+ &pLine->m_aYesNoButton, &pLine->m_aRemoveButton, NULL };
+ Window** pCurrent = pWindows;
+ while ( *pCurrent )
+ {
+ Point aPos = (*pCurrent)->GetPosPixel();
+ aPos.Y() += nNewPos;
+ (*pCurrent)->SetPosPixel( aPos );
+ pCurrent++;
+ }
+ }
+}
+
+bool CustomPropertiesWindow::DoesCustomPropertyExist( const String& rName ) const
+{
+ bool bRet = false;
+ std::vector< CustomPropertyLine* >::const_iterator pIter;
+ for ( pIter = m_aCustomPropertiesLines.begin();
+ pIter != m_aCustomPropertiesLines.end(); ++pIter )
+ {
+ CustomPropertyLine* pLine = *pIter;
+ if ( !pLine->m_bIsRemoved && pLine->m_aNameBox.GetText() == rName )
+ {
+ bRet = true;
+ break;
+ }
+ }
+
+ return bRet;
+}
+
+Sequence< beans::PropertyValue > CustomPropertiesWindow::GetCustomProperties() const
+{
+ Sequence< beans::PropertyValue > aPropertiesSeq( m_aCustomPropertiesLines.size() );
+ sal_Int32 i = 0;
+ std::vector< CustomPropertyLine* >::const_iterator pIter;
+ for ( pIter = m_aCustomPropertiesLines.begin();
+ pIter != m_aCustomPropertiesLines.end(); ++pIter, ++i )
+ {
+ CustomPropertyLine* pLine = *pIter;
+ if ( pLine->m_bIsRemoved )
+ continue;
+
+ String sPropertyName = pLine->m_aNameBox.GetText();
+ if ( sPropertyName.Len() > 0 )
+ {
+ aPropertiesSeq[i].Name = sPropertyName;
+ sal_Int64 nType = sal_Int64(
+ (long)pLine->m_aTypeBox.GetEntryData( pLine->m_aTypeBox.GetSelectEntryPos() ) );
+ if ( CUSTOM_TYPE_NUMBER == nType )
+ {
+ double nValue = 0;
+ sal_uInt32 nIndex = const_cast< SvNumberFormatter& >(
+ m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM );
+ BOOL bIsNum = const_cast< SvNumberFormatter& >( m_aNumberFormatter ).
+ IsNumberFormat( pLine->m_aValueEdit.GetText(), nIndex, nValue );
+ if ( bIsNum )
+ aPropertiesSeq[i].Value <<= makeAny( nValue );
+ }
+ else if ( CUSTOM_TYPE_BOOLEAN == nType )
+ {
+ bool bValue = pLine->m_aYesNoButton.IsYesChecked();
+ aPropertiesSeq[i].Value <<= makeAny( bValue );
+ }
+ else if ( CUSTOM_TYPE_DATETIME == nType )
+ {
+ Date aTmpDate = pLine->m_aDateField.GetDate();
+ Time aTmpTime = pLine->m_aTimeField.GetTime();
+ util::DateTime aDateTime(aTmpTime.Get100Sec(), aTmpTime.GetSec(), aTmpTime.GetMin(), aTmpTime.GetHour(),
+ aTmpDate.GetDay(), aTmpDate.GetMonth(), aTmpDate.GetYear() );
+ aPropertiesSeq[i].Value <<= aDateTime;
+ }
+ else if ( CUSTOM_TYPE_DURATION == nType )
+ {
+ aPropertiesSeq[i].Value <<= pLine->m_aDurationField.GetDuration();
+ }
+ else if ( CUSTOM_TYPE_DATE == nType )
+ {
+ Date aTmpDate = pLine->m_aDateField.GetDate();
+ util::Date aDate(aTmpDate.GetDay(), aTmpDate.GetMonth(), aTmpDate.GetYear());
+ aPropertiesSeq[i].Value <<= aDate;
+
+ }
+ else
+ {
+ ::rtl::OUString sValue( pLine->m_aValueEdit.GetText() );
+ aPropertiesSeq[i].Value <<= makeAny( sValue );
+ }
+ }
+ }
+
+ return aPropertiesSeq;
+}
+
+// class CustomPropertiesControl -----------------------------------------
+
+CustomPropertiesControl::CustomPropertiesControl( Window* pParent, const ResId& rResId ) :
+
+ Control( pParent, rResId ),
+
+ m_aHeaderBar ( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER ),
+ m_aPropertiesWin( this, ResId( WIN_PROPERTIES, *rResId.GetResMgr() ) ),
+ m_aVertScroll ( this, ResId( SB_VERTICAL, *rResId.GetResMgr() ) ),
+
+ m_bIsInitialized( false ),
+ m_nThumbPos ( 0 )
+
+{
+ m_aPropertiesWin.SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
+ m_aVertScroll.EnableDrag();
+ m_aVertScroll.Show();
+ long nWidth = GetOutputSizePixel().Width();
+ m_aHeaderBar.SetPosSizePixel( Point(), Size( nWidth, m_aVertScroll.GetPosPixel().Y() ) );
+ const HeaderBarItemBits nHeadBits = HIB_VCENTER | HIB_FIXED | HIB_FIXEDPOS | HIB_LEFT;
+ nWidth = nWidth / 4;
+ ResMgr* pResMgr = rResId.GetResMgr();
+ m_aHeaderBar.InsertItem( HI_NAME, String( ResId( STR_HEADER_NAME, *pResMgr ) ), nWidth, nHeadBits );
+ m_aHeaderBar.InsertItem( HI_TYPE, String( ResId( STR_HEADER_TYPE, *pResMgr ) ), nWidth, nHeadBits );
+ m_aHeaderBar.InsertItem( HI_VALUE, String( ResId( STR_HEADER_VALUE, *pResMgr ) ), nWidth, nHeadBits );
+ m_aHeaderBar.InsertItem( HI_ACTION, String( ResId( STR_HEADER_ACTION, *pResMgr ) ), nWidth, nHeadBits );
+ m_aHeaderBar.Show();
+
+ FreeResource();
+
+ XubString sTEST = m_aHeaderBar.GetItemText( HI_NAME );
+
+ m_aPropertiesWin.InitControls( &m_aHeaderBar, &m_aVertScroll );
+ m_aPropertiesWin.SetRemovedHdl( LINK( this, CustomPropertiesControl, RemovedHdl ) );
+
+ m_aVertScroll.SetRangeMin( 0 );
+ sal_Int32 nScrollOffset = m_aPropertiesWin.GetLineHeight();
+ sal_Int32 nVisibleEntries = m_aPropertiesWin.GetSizePixel().Height() / nScrollOffset;
+ m_aVertScroll.SetRangeMax( nVisibleEntries );
+ m_aVertScroll.SetPageSize( nVisibleEntries - 1 );
+ m_aVertScroll.SetVisibleSize( nVisibleEntries );
+
+ Point aPos = m_aHeaderBar.GetPosPixel();
+ Size aSize = m_aHeaderBar.GetSizePixel();
+ aPos = m_aVertScroll.GetPosPixel();
+ aSize = m_aVertScroll.GetSizePixel();
+
+ Link aScrollLink = LINK( this, CustomPropertiesControl, ScrollHdl );
+ m_aVertScroll.SetScrollHdl( aScrollLink );
+// m_aVertScroll.SetEndScrollHdl( aScrollLink );
+}
+
+CustomPropertiesControl::~CustomPropertiesControl()
+{
+}
+
+void CustomPropertiesControl::Initialize()
+{
+}
+
+IMPL_LINK( CustomPropertiesControl, ScrollHdl, ScrollBar*, pScrollBar )
+{
+ sal_Int32 nOffset = m_aPropertiesWin.GetLineHeight();
+ nOffset *= ( m_nThumbPos - pScrollBar->GetThumbPos() );
+ m_nThumbPos = pScrollBar->GetThumbPos();
+ m_aPropertiesWin.DoScroll( nOffset );
+ return 0;
+}
+
+IMPL_LINK( CustomPropertiesControl, RemovedHdl, void*, EMPTYARG )
+{
+ m_aVertScroll.SetRangeMax( m_aPropertiesWin.GetVisibleLineCount() + 1 );
+ if ( m_aPropertiesWin.GetOutputSizePixel().Height() < m_aPropertiesWin.GetVisibleLineCount() * m_aPropertiesWin.GetLineHeight() )
+ m_aVertScroll.DoScrollAction ( SCROLL_LINEUP );
+ return 0;
+}
+
+void CustomPropertiesControl::AddLine( const ::rtl::OUString& sName, Any& rAny, bool bInteractive )
+{
+ m_aPropertiesWin.AddLine( sName, rAny );
+ m_aVertScroll.SetRangeMax( m_aPropertiesWin.GetVisibleLineCount() + 1 );
+ if ( bInteractive && m_aPropertiesWin.GetOutputSizePixel().Height() < m_aPropertiesWin.GetVisibleLineCount() * m_aPropertiesWin.GetLineHeight() )
+ m_aVertScroll.DoScroll( m_aPropertiesWin.GetVisibleLineCount() + 1 );
+}
+
+// class SfxCustomPropertiesPage -----------------------------------------
+
+SfxCustomPropertiesPage::SfxCustomPropertiesPage( Window* pParent, const SfxItemSet& rItemSet ) :
+
+ SfxTabPage( pParent, SfxResId( TP_CUSTOMPROPERTIES ), rItemSet ),
+ m_aPropertiesFT ( this, SfxResId( FT_PROPERTIES ) ),
+ m_aPropertiesCtrl ( this, SfxResId( CTRL_PROPERTIES ) ),
+ m_aAddBtn ( this, SfxResId( BTN_ADD ) )
+
+{
+ FreeResource();
+
+ m_aAddBtn.SetClickHdl( LINK( this, SfxCustomPropertiesPage, AddHdl ) );
+}
+
+IMPL_LINK( SfxCustomPropertiesPage, AddHdl, PushButton*, EMPTYARG )
+{
+ Any aAny;
+ m_aPropertiesCtrl.AddLine( ::rtl::OUString(), aAny, true );
+ return 0;
+}
+
+BOOL SfxCustomPropertiesPage::FillItemSet( SfxItemSet& rSet )
+{
+ BOOL bModified = FALSE;
+ const SfxPoolItem* pItem = NULL;
+ SfxDocumentInfoItem* pInfo = NULL;
+ bool bMustDelete = false;
+
+ if ( GetTabDialog() && GetTabDialog()->GetExampleSet() )
+ {
+ if( SFX_ITEM_SET !=
+ GetTabDialog()->GetExampleSet()->GetItemState( SID_DOCINFO, TRUE, &pItem ) )
+ pInfo = &( SfxDocumentInfoItem& )rSet.Get( SID_DOCINFO );
+ else
+ {
+ bMustDelete = true;
+ pInfo = new SfxDocumentInfoItem( *( const SfxDocumentInfoItem* ) pItem );
+ }
+ }
+
+ if ( pInfo )
+ {
+ pInfo->ClearCustomProperties();
+ Sequence< beans::PropertyValue > aPropertySeq = m_aPropertiesCtrl.GetCustomProperties();
+ sal_Int32 i = 0, nCount = aPropertySeq.getLength();
+ for ( ; i < nCount; ++i )
+ {
+ if ( aPropertySeq[i].Name.getLength() > 0 )
+ pInfo->AddCustomProperty( aPropertySeq[i].Name, aPropertySeq[i].Value );
+ }
+ }
+
+ bModified = TRUE; //!!!
+ if ( bModified )
+ rSet.Put( *pInfo );
+ if ( bMustDelete )
+ delete pInfo;
+ return bModified;
+}
+
+void SfxCustomPropertiesPage::Reset( const SfxItemSet& rItemSet )
+{
+ m_aPropertiesCtrl.ClearAllLines();
+ const SfxDocumentInfoItem* pInfoItem = &(const SfxDocumentInfoItem &)rItemSet.Get(SID_DOCINFO);
+ std::vector< CustomProperty* > aCustomProps = pInfoItem->GetCustomProperties();
+ for ( sal_uInt32 i = 0; i < aCustomProps.size(); i++ )
+ {
+ m_aPropertiesCtrl.AddLine( aCustomProps[i]->m_sName, aCustomProps[i]->m_aValue, false );
+ }
+}
+
+int SfxCustomPropertiesPage::DeactivatePage( SfxItemSet* /*pSet*/ )
+{
+ int nRet = LEAVE_PAGE;
+ if ( !m_aPropertiesCtrl.AreAllLinesValid() )
+ nRet = KEEP_PAGE;
+ return nRet;
+}
+
+SfxTabPage* SfxCustomPropertiesPage::Create( Window* pParent, const SfxItemSet& rItemSet )
+{
+ return new SfxCustomPropertiesPage( pParent, rItemSet );
+}
+
diff --git a/sfx2/source/dialog/dinfdlg.hrc b/sfx2/source/dialog/dinfdlg.hrc
new file mode 100644
index 000000000000..5453e3606026
--- /dev/null
+++ b/sfx2/source/dialog/dinfdlg.hrc
@@ -0,0 +1,177 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _DINFDLG_HRC
+#define _DINFDLG_HRC
+
+#include <svtools/controldims.hrc>
+
+// const -----------------------------------------------------------------
+
+#define CUSTOM_TYPE_UNKNOWN 0
+#define CUSTOM_TYPE_TEXT 1
+#define CUSTOM_TYPE_NUMBER 2
+#define CUSTOM_TYPE_DATE 3
+#define CUSTOM_TYPE_BOOLEAN 4
+#define CUSTOM_TYPE_DURATION 5
+#define CUSTOM_TYPE_DATETIME 6
+
+// 4 TP_DOCINFORELOAD
+#define PAGE_WIDTH 260
+#define WIDTH_CTRL_SPACE 3
+#define WIDTH_0 10
+#define WIDTH_1 48
+#define WIDTH_2 28
+#define WIDTH_FT1 (WIDTH_1 - WIDTH_CTRL_SPACE)
+#define COL_0 6
+#define COL_1 (COL_0+WIDTH_0)
+#define COL_2 (COL_1+WIDTH_1)
+#define COL_3 (COL_2+WIDTH_2)
+#define COL_4 (COL_3+WIDTH_CTRL_SPACE)
+#define COL_7 (PAGE_WIDTH-2*WIDTH_0)
+#define COL_6 (COL_7-WIDTH_0)
+#define COL_5 (COL_6-WIDTH_CTRL_SPACE)
+#define COL_LAST COL_7
+
+#define ROWDIFF_FT_EDTFLD ((RSC_CD_TEXTBOX_HEIGHT-RSC_CD_FIXEDTEXT_HEIGHT)/2)
+#define ROW_0 6
+#define ROW_1 (ROW_0+16)
+#define ROW_2 (ROW_1+13)
+#define ROW_3 (ROW_2+16)
+#define ROW_4 (ROW_3+13)
+#define ROW_5 (ROW_4+16)
+#define ROW_6 (ROW_5+16)
+
+// defines ---------------------------------------------------------------
+
+#define FT_FILE 1
+#define FT_FILE_VAL 2
+#define FT_CHANGE 3
+#define FT_CHANGE_VAL 4
+#define FT_CREATE 7
+#define FT_CREATE_VAL 8
+#define FT_TITLE 9
+#define ED_TITLE 10
+#define FT_THEMA 11
+#define ED_THEMA 12
+#define FT_KEYWORDS 13
+#define ED_KEYWORDS 14
+#define FT_INFO1 15
+#define ED_INFO1 16
+#define FT_INFO2 17
+#define ED_INFO2 18
+#define FT_INFO3 19
+#define ED_INFO3 20
+#define FT_INFO4 21
+#define ED_INFO4 22
+#define FT_COMMENT 23
+#define ED_COMMENT 24
+#define GB_INFO 30
+#define FT_TEMPL 32
+#define FT_TEMPL_VAL 33
+#define BTN_EDITLABEL 34
+#define FT_TIMELOG 35
+#define FT_TIMELOG_VAL 36
+#define FT_DOCNO 37
+#define FT_DOCNO_VAL 38
+#define FT_URL 43
+#define ED_URL 44
+#define CB_FILE_READONLY 48
+#define CB_USE_USERDATA 49
+#define BMP_FILE_1 50
+#define ED_FILE_NAME 51
+#define FL_FILE_1 52
+#define FT_FILE_TYP 53
+#define FT_FILE_SHOW_TYP 54
+#define FT_FILE_SIZE 55
+#define FT_FILE_SHOW_SIZE 56
+#define FL_FILE_2 57
+#define FT_PRINT 58
+#define FT_PRINT_VAL 59
+#define STR_UNKNOWNSIZE 60
+#define FL_FILE_3 61
+#define BTN_DELETE 62
+
+#define RB_NOAUTOUPDATE 63
+#define RB_RELOADUPDATE 64
+#define RB_FORWARDUPDATE 65
+#define FT_EVERY 66
+#define ED_RELOAD 67
+#define FT_RELOADSECS 68
+#define FT_AFTER 69
+#define ED_FORWARD 70
+#define FT_FORWARDSECS 71
+#define FT_FRAME 72
+#define CB_FRAME 73
+#define PB_BROWSEURL 74
+#define STR_FORWARD_ERRMSSG 75
+
+#define FT_SIGNED 76
+#define FT_SIGNED_VAL 77
+#define STR_MULTSIGNED 78
+#define BTN_SIGNATURE 79
+
+#define WIN_PROPERTIES 90
+#define SB_VERTICAL 91
+#define FT_PROPERTIES 92
+#define CTRL_PROPERTIES 93
+#define BTN_ADD 94
+#define LB_PROPNAME 95
+#define ED_PROPVALUE 96
+#define RB_PROPYES 96
+#define RB_PROPNO 97
+#define LB_PROPTYPE 98
+#define PB_REMOVEPROP 99
+#define RB_PROPERTY_YES 100
+#define RB_PROPERTY_NO 101
+
+#define STR_HEADER_NAME 90
+#define STR_HEADER_TYPE 91
+#define STR_HEADER_VALUE 92
+#define STR_HEADER_ACTION 93
+
+#define PB_OK 100
+#define PB_CANCEL 101
+#define PB_HELP 102
+#define CB_NEGATIVE 103
+#define FT_YEAR 104
+#define ED_YEAR 105
+#define FT_MONTH 106
+#define ED_MONTH 107
+#define FT_DAY 108
+#define ED_DAY 109
+#define FT_HOUR 110
+#define ED_HOUR 111
+#define FT_MINUTE 112
+#define ED_MINUTE 113
+#define FT_SECOND 114
+#define ED_SECOND 115
+#define FT_MSECOND 116
+#define ED_MSECOND 117
+#define FL_DURATION 118
+
+#endif
+
diff --git a/sfx2/source/dialog/dinfdlg.src b/sfx2/source/dialog/dinfdlg.src
new file mode 100644
index 000000000000..c78347e3dba3
--- /dev/null
+++ b/sfx2/source/dialog/dinfdlg.src
@@ -0,0 +1,947 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+ // include ---------------------------------------------------------------
+
+#include "sfx2/sfx.hrc"
+#include "helpid.hrc"
+#include "sfxlocal.hrc"
+#include "dinfdlg.hrc"
+#include "dialog.hrc"
+
+ // TP_DOCINFODESC --------------------------------------------------------
+String STR_SFX_NEWOFFICEDOC
+{
+ Text [ en-US ] = "%PRODUCTNAME document" ;
+};
+
+TabPage TP_DOCINFODESC
+{
+ HelpId = HID_DOCINFODESC ;
+ Hide = TRUE ;
+ Size = MAP_APPFONT ( 260 , 185 ) ;
+ FixedText FT_TITLE
+ {
+ Pos = MAP_APPFONT ( 6 , 7 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "~Title" ;
+ };
+ Edit ED_TITLE
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODESC:ED_TITLE";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 6 ) ;
+ Size = MAP_APPFONT ( 184 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ TabStop = TRUE ;
+ Left = TRUE ;
+ };
+ FixedText FT_THEMA
+ {
+ Pos = MAP_APPFONT ( 6 , 22 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "~Subject" ;
+ };
+ Edit ED_THEMA
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODESC:ED_THEMA";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 21 ) ;
+ Size = MAP_APPFONT ( 184 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ TabStop = TRUE ;
+ Left = TRUE ;
+ };
+ FixedText FT_KEYWORDS
+ {
+ Pos = MAP_APPFONT ( 6 , 37 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "~Keywords" ;
+ };
+ Edit ED_KEYWORDS
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODESC:ED_KEYWORDS";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 36 ) ;
+ Size = MAP_APPFONT ( 184 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ TabStop = TRUE ;
+ Left = TRUE ;
+ };
+ FixedText FT_COMMENT
+ {
+ Pos = MAP_APPFONT ( 6 , 52 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "~Comments" ;
+ };
+ MultiLineEdit ED_COMMENT
+ {
+ HelpID = "sfx2:MultiLineEdit:TP_DOCINFODESC:ED_COMMENT";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 51 ) ;
+ Size = MAP_APPFONT ( 184 , 128 ) ;
+ IgnoreTab = TRUE ;
+ Left = TRUE ;
+ VScroll = TRUE ;
+ };
+};
+
+ // TP_DOCINFODOC ---------------------------------------------------------
+
+TabPage TP_DOCINFODOC
+{
+ HelpId = HID_DOCINFODOC ;
+ Hide = TRUE ;
+ Size = MAP_APPFONT ( 260 , 185 ) ;
+ FixedImage BMP_FILE_1
+ {
+ Pos = MAP_APPFONT ( 6 , 7 ) ;
+ Size = MAP_APPFONT ( 20 , 20 ) ;
+ };
+ Edit ED_FILE_NAME
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:ED_FILE_NAME";
+ Pos = MAP_APPFONT ( 54 , 12 ) ;
+ Size = MAP_APPFONT ( 200 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ Border = TRUE ;
+ };
+ FixedLine FL_FILE_1
+ {
+ Pos = MAP_APPFONT ( 6 , 31 ) ;
+ Size = MAP_APPFONT ( 248 , 1 ) ;
+ };
+ FixedText FT_FILE_TYP
+ {
+ Pos = MAP_APPFONT ( 6 , 37 ) ;
+ Size = MAP_APPFONT ( 70 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "Type:" ;
+ };
+ Edit FT_FILE_SHOW_TYP
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:FT_FILE_SHOW_TYP";
+ Pos = MAP_APPFONT ( 78 , 37 ) ;
+ Size = MAP_APPFONT ( 106 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ };
+ CheckBox CB_FILE_READONLY
+ {
+ HelpID = "sfx2:CheckBox:TP_DOCINFODOC:CB_FILE_READONLY";
+ Pos = MAP_APPFONT ( 163 , 37 ) ;
+ Size = MAP_APPFONT ( 91 , RSC_CD_CHECKBOX_HEIGHT ) ;
+ Text [ en-US ] = "~Read-only" ;
+ };
+ FixedText FT_FILE
+ {
+ Pos = MAP_APPFONT ( 6 , 49 ) ;
+ Size = MAP_APPFONT ( 70 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "Location:" ;
+ };
+ Edit FT_FILE_VAL
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:FT_FILE_VAL";
+ Pos = MAP_APPFONT ( 78 , 49 ) ;
+ Size = MAP_APPFONT ( 176 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ };
+ FixedText FT_FILE_SIZE
+ {
+ Pos = MAP_APPFONT ( 6 , 61 ) ;
+ Size = MAP_APPFONT ( 70 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "Size:" ;
+ };
+ Edit FT_FILE_SHOW_SIZE
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:FT_FILE_SHOW_SIZE";
+ Pos = MAP_APPFONT ( 78 , 61 ) ;
+ Size = MAP_APPFONT ( 176 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ };
+ FixedLine FL_FILE_2
+ {
+ Pos = MAP_APPFONT ( 6 , 74 ) ;
+ Size = MAP_APPFONT ( 248 , 1 ) ;
+ };
+ FixedText FT_CREATE
+ {
+ Pos = MAP_APPFONT ( 6 , 80 ) ;
+ Size = MAP_APPFONT ( 70 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "Created:" ;
+ };
+ Edit FT_CREATE_VAL
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:FT_CREATE_VAL";
+ Pos = MAP_APPFONT ( 78 , 80 ) ;
+ Size = MAP_APPFONT ( 176 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ };
+ FixedText FT_CHANGE
+ {
+ Pos = MAP_APPFONT ( 6 , 92 ) ;
+ Size = MAP_APPFONT ( 70 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "Modified:" ;
+ };
+ Edit FT_CHANGE_VAL
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:FT_CHANGE_VAL";
+ Pos = MAP_APPFONT ( 78 , 92 ) ;
+ Size = MAP_APPFONT ( 176 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ };
+ FixedText FT_SIGNED
+ {
+ Pos = MAP_APPFONT ( 6 , 104 ) ;
+ Size = MAP_APPFONT ( 70 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "Digitally signed:" ;
+ };
+ Edit FT_SIGNED_VAL
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:FT_SIGNED_VAL";
+ Pos = MAP_APPFONT ( 78 , 104 ) ;
+ Size = MAP_APPFONT ( 123 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ };
+ PushButton BTN_SIGNATURE
+ {
+ HelpID = "sfx2:PushButton:TP_DOCINFODOC:BTN_SIGNATURE";
+ Pos = MAP_APPFONT ( 204 , 101 ) ;
+ Size = MAP_APPFONT ( RSC_CD_PUSHBUTTON_WIDTH , RSC_CD_PUSHBUTTON_HEIGHT ) ;
+ Text [ en-US ] = "Digital Signature...";
+ };
+ String STR_MULTSIGNED
+ {
+ Text [ en-US ] = "Multiply signed document" ;
+ };
+ FixedText FT_PRINT
+ {
+ Pos = MAP_APPFONT ( 6 , 116 ) ;
+ Size = MAP_APPFONT ( 70 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "Last printed:" ;
+ };
+ Edit FT_PRINT_VAL
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:FT_PRINT_VAL";
+ Pos = MAP_APPFONT ( 78 , 116 ) ;
+ Size = MAP_APPFONT ( 176 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ };
+ FixedText FT_TIMELOG
+ {
+ Pos = MAP_APPFONT ( 6 , 128 ) ;
+ Size = MAP_APPFONT ( 70 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "Total editing time:" ;
+ };
+ Edit FT_TIMELOG_VAL
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:FT_TIMELOG_VAL";
+ Pos = MAP_APPFONT ( 78 , 128 ) ;
+ Size = MAP_APPFONT ( 30 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ };
+ FixedText FT_DOCNO
+ {
+ Pos = MAP_APPFONT ( 6 , 140 ) ;
+ Size = MAP_APPFONT ( 70 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "Revision number:" ;
+ };
+ Edit FT_DOCNO_VAL
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:FT_DOCNO_VAL";
+ Pos = MAP_APPFONT ( 78 , 140 ) ;
+ Size = MAP_APPFONT ( 30 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ };
+ PushButton BTN_DELETE
+ {
+ HelpID = "sfx2:PushButton:TP_DOCINFODOC:BTN_DELETE";
+ Pos = MAP_APPFONT ( 204 , 150 ) ;
+ Size = MAP_APPFONT ( RSC_CD_PUSHBUTTON_WIDTH , RSC_CD_PUSHBUTTON_HEIGHT ) ;
+ Hide = TRUE;
+ Text [ en-US ] = "Reset";
+ };
+ CheckBox CB_USE_USERDATA
+ {
+ HelpID = "sfx2:CheckBox:TP_DOCINFODOC:CB_USE_USERDATA";
+ Pos = MAP_APPFONT ( 6 , 152 ) ;
+ Size = MAP_APPFONT ( 192 , RSC_CD_CHECKBOX_HEIGHT ) ;
+ Hide = TRUE;
+ Text [ en-US ] = "~Apply user data";
+ };
+ FixedLine FL_FILE_3
+ {
+ Pos = MAP_APPFONT ( 5 , 167 ) ;
+ Size = MAP_APPFONT ( 248 , 1 ) ;
+ };
+ FixedText FT_TEMPL
+ {
+ Pos = MAP_APPFONT ( 5 , 172 ) ;
+ Size = MAP_APPFONT ( 45 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "Template:" ;
+ };
+ Edit FT_TEMPL_VAL
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFODOC:FT_TEMPL_VAL";
+ Pos = MAP_APPFONT ( 78 , 172 ) ;
+ Size = MAP_APPFONT ( 180 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ };
+ String STR_UNKNOWNSIZE
+ {
+ Text [ en-US ] = "unknown" ;
+ };
+};
+
+ // TP_DOCINFOUSER --------------------------------------------------------
+
+TabPage TP_DOCINFOUSER
+{
+ HelpId = HID_DOCINFOUSER ;
+ Hide = TRUE ;
+ Size = MAP_APPFONT ( 260 , 185 ) ;
+ FixedText FT_INFO1
+ {
+ Pos = MAP_APPFONT ( 6 , 6 ) ;
+ Size = MAP_APPFONT ( 248 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ };
+ Edit ED_INFO1
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFOUSER:ED_INFO1";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 17 ) ;
+ Size = MAP_APPFONT ( 248 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ Left = TRUE ;
+ };
+ FixedText FT_INFO2
+ {
+ Pos = MAP_APPFONT ( 6 , 32 ) ;
+ Size = MAP_APPFONT ( 248 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ };
+ Edit ED_INFO2
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFOUSER:ED_INFO2";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 43 ) ;
+ Size = MAP_APPFONT ( 248 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ Left = TRUE ;
+ };
+ FixedText FT_INFO3
+ {
+ Pos = MAP_APPFONT ( 6 , 58 ) ;
+ Size = MAP_APPFONT ( 248 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ };
+ Edit ED_INFO3
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFOUSER:ED_INFO3";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 69 ) ;
+ Size = MAP_APPFONT ( 248 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ Left = TRUE ;
+ };
+ FixedText FT_INFO4
+ {
+ Pos = MAP_APPFONT ( 6 , 84 ) ;
+ Size = MAP_APPFONT ( 248 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ };
+ Edit ED_INFO4
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFOUSER:ED_INFO4";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 95 ) ;
+ Size = MAP_APPFONT ( 248 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ Left = TRUE ;
+ };
+ PushButton BTN_EDITLABEL
+ {
+ HelpID = "sfx2:PushButton:TP_DOCINFOUSER:BTN_EDITLABEL";
+ Pos = MAP_APPFONT ( 194 , 165 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_PUSHBUTTON_HEIGHT ) ;
+ Text [ en-US ] = "~Info fields..." ;
+ };
+};
+
+ // TP_DOCINFOUSER --------------------------------------------------------
+
+TabPage TP_DOCINFORELOAD
+{
+ HelpId = HID_DOCINFORELOAD ;
+ Hide = TRUE ;
+ Size = MAP_APPFONT ( 260 , 185 ) ;
+ RadioButton RB_NOAUTOUPDATE
+ {
+ HelpID = "sfx2:RadioButton:TP_DOCINFORELOAD:RB_NOAUTOUPDATE";
+ TabStop = TRUE ;
+ Pos = MAP_APPFONT( COL_0 , ROW_0 ) ;
+ Size = MAP_APPFONT( COL_7 - COL_1 , RSC_CD_RADIOBUTTON_HEIGHT ) ;
+ Text [ en-US ] = "Do not refresh automatically" ;
+ };
+
+ RadioButton RB_RELOADUPDATE
+ {
+ HelpID = "sfx2:RadioButton:TP_DOCINFORELOAD:RB_RELOADUPDATE";
+ TabStop = TRUE ;
+ Pos = MAP_APPFONT( COL_0, ROW_1 ) ;
+ Size = MAP_APPFONT( COL_7 - COL_1, RSC_CD_RADIOBUTTON_HEIGHT ) ;
+ Text [ en-US ] = "Refresh this document" ;
+ };
+ FixedText FT_EVERY
+ {
+ Pos = MAP_APPFONT ( COL_1 , ROW_2 ) ;
+ Size = MAP_APPFONT ( WIDTH_FT1 , RSC_CD_RADIOBUTTON_HEIGHT ) ;
+ Text [ en-US ] = "every" ;
+ };
+ NumericField ED_RELOAD
+ {
+ HelpID = "sfx2:NumericField:TP_DOCINFORELOAD:ED_RELOAD";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( COL_2 , ROW_2 - ROWDIFF_FT_EDTFLD ) ;
+ Size = MAP_APPFONT ( WIDTH_2 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ Repeat = TRUE ;
+ Spin = TRUE ;
+ Minimum = 1 ;
+ First = 1 ;
+ Last = 60 ;
+ SpinSize = 1 ;
+ Value = 60 ;
+ };
+ FixedText FT_RELOADSECS
+ {
+ Pos = MAP_APPFONT ( COL_4 , ROW_2 ) ;
+ Size = MAP_APPFONT ( COL_7 - COL_4 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "seconds" ;
+ };
+
+ RadioButton RB_FORWARDUPDATE
+ {
+ HelpID = "sfx2:RadioButton:TP_DOCINFORELOAD:RB_FORWARDUPDATE";
+ TabStop = TRUE ;
+ Pos = MAP_APPFONT( COL_0, ROW_3 ) ;
+ Size = MAP_APPFONT( COL_7 - COL_1, RSC_CD_RADIOBUTTON_HEIGHT ) ;
+ Text [ en-US ] = "Redirect from this document" ;
+ };
+ FixedText FT_AFTER
+ {
+ Pos = MAP_APPFONT ( COL_1 , ROW_4 ) ;
+ Size = MAP_APPFONT ( WIDTH_FT1 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "after" ;
+ };
+ NumericField ED_FORWARD
+ {
+ HelpID = "sfx2:NumericField:TP_DOCINFORELOAD:ED_FORWARD";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( COL_2 , ROW_4 - ROWDIFF_FT_EDTFLD ) ;
+ Size = MAP_APPFONT ( WIDTH_2 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ Repeat = TRUE ;
+ Spin = TRUE ;
+ Minimum = 1 ;
+ First = 1 ;
+ Last = 60 ;
+ SpinSize = 1 ;
+ Value = 5 ;
+ };
+ FixedText FT_FORWARDSECS
+ {
+ Pos = MAP_APPFONT ( COL_4 , ROW_4 ) ;
+ Size = MAP_APPFONT ( COL_7 - COL_4 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "seconds" ;
+ };
+ FixedText FT_URL
+ {
+ Pos = MAP_APPFONT ( COL_1 , ROW_5 ) ;
+ Size = MAP_APPFONT ( WIDTH_FT1 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "to URL" ;
+ };
+ Edit ED_URL
+ {
+ HelpID = "sfx2:Edit:TP_DOCINFORELOAD:ED_URL";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( COL_2 , ROW_5 - ROWDIFF_FT_EDTFLD ) ;
+ Size = MAP_APPFONT ( COL_5 - COL_2 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ };
+ PushButton PB_BROWSEURL
+ {
+ HelpID = "sfx2:PushButton:TP_DOCINFORELOAD:PB_BROWSEURL";
+ Pos = MAP_APPFONT ( COL_6 , ROW_5 - ROWDIFF_FT_EDTFLD ) ;
+ Size = MAP_APPFONT ( COL_7 - COL_6 , RSC_CD_PUSHBUTTON_HEIGHT ) ;
+ Text = "..." ;
+ };
+ FixedText FT_FRAME
+ {
+ Pos = MAP_APPFONT ( COL_1 , ROW_6 ) ;
+ Size = MAP_APPFONT ( WIDTH_FT1 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "to frame" ;
+ };
+ ComboBox CB_FRAME
+ {
+ HelpID = "sfx2:ComboBox:TP_DOCINFORELOAD:CB_FRAME";
+ Pos = MAP_APPFONT ( COL_2 , ROW_6 - ROWDIFF_FT_EDTFLD ) ;
+ Size = MAP_APPFONT ( COL_7 - COL_2 , RSC_CD_DROPDOWN_HEIGHT * 10 ) ;
+ DropDown = TRUE ;
+ };
+ String STR_FORWARD_ERRMSSG
+ {
+ Text [ en-US ] = "If you select the option \"%PLACEHOLDER%\", you must enter a URL." ;
+ };
+
+};
+
+// TP_CUSTOMPROPERTIES ---------------------------------------------------
+
+TabPage TP_CUSTOMPROPERTIES
+{
+ HelpId = HID_TP_CUSTOMPROPERTIES ;
+ Hide = TRUE ;
+ Size = MAP_APPFONT ( 260 , 185 ) ;
+ FixedText FT_PROPERTIES
+ {
+ Pos = MAP_APPFONT ( 6 , 7 ) ;
+ Size = MAP_APPFONT ( 248 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "~Properties" ;
+ };
+ Control CTRL_PROPERTIES
+ {
+ HelpId = HID_CTRL_CUSTOMPROPERTIES;
+ Pos = MAP_APPFONT ( 6 , 18 ) ;
+ Size = MAP_APPFONT ( 248 , 141 ) ;
+ Border = TRUE;
+ DialogControl = TRUE;
+ //OutputSize = TRUE ;
+ Window WIN_PROPERTIES
+ {
+ OutputSize = TRUE ;
+ Pos = MAP_APPFONT ( 0 , 10 ) ;
+ Size = MAP_APPFONT ( 240 , 134 ) ;
+ DialogControl = TRUE;
+ };
+ ScrollBar SB_VERTICAL
+ {
+ Pos = MAP_APPFONT ( 238 , 10 ) ;
+ Size = MAP_APPFONT ( 8 , 129 ) ;
+ VScroll = TRUE;
+ };
+ String STR_HEADER_NAME
+ {
+ Text [ en-US ] = "Name" ;
+ };
+ String STR_HEADER_TYPE
+ {
+ Text [ en-US ] = "Type" ;
+ };
+ String STR_HEADER_VALUE
+ {
+ Text [ en-US ] = "Value" ;
+ };
+ String STR_HEADER_ACTION
+ {
+ Text [ en-US ] = "" ;
+ };
+ };
+ PushButton BTN_ADD
+ {
+ HelpID = "sfx2:PushButton:TP_CUSTOMPROPERTIES:BTN_ADD";
+ Pos = MAP_APPFONT( 204 , 165 );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT );
+ Text [ en-US ] = "~Add";
+ };
+};
+
+ComboBox SFX_CB_PROPERTY_NAME
+{
+ Pos = MAP_APPFONT ( 0 , 2 ) ;
+ Size = MAP_APPFONT ( 60 , 72 ) ;
+ TabStop = TRUE ;
+ DropDown = TRUE ;
+ AutoSize = TRUE ;
+ AutoHScroll = TRUE ;
+ DDExtraWidth = TRUE ;
+ QuickHelpText [ en-US ] = "Property Name" ;
+ StringList [ en-US ] =
+ {
+ "Checked by";
+ "Client";
+ "Date completed";
+ "Department";
+ "Destinations";
+ "Disposition";
+ "Division";
+ "Document number";
+ "Editor";
+ "E-Mail";
+ "Forward to";
+ "Group";
+ "Info";
+ "Language";
+ "Mailstop";
+ "Matter";
+ "Office";
+ "Owner";
+ "Project";
+ "Publisher";
+ "Purpose";
+ "Received from";
+ "Recorded by";
+ "Recorded date";
+ "Reference";
+ "Source";
+ "Status";
+ "Telephone number";
+ "Typist";
+ "URL";
+ };
+};
+ListBox SFX_LB_PROPERTY_TYPE
+{
+ Pos = MAP_APPFONT ( 63 , 2 ) ;
+ Size = MAP_APPFONT ( 60 , 80 ) ;
+ DropDown = TRUE;
+ Border = TRUE;
+ CurPos = 0;
+ StringList [ en-US ] =
+ {
+ < "Text" ; CUSTOM_TYPE_TEXT ; > ;
+ < "DateTime" ; CUSTOM_TYPE_DATETIME ; > ;
+ < "Date" ; CUSTOM_TYPE_DATE ; > ;
+ < "Duration" ; CUSTOM_TYPE_DURATION ; > ;
+ < "Number" ; CUSTOM_TYPE_NUMBER ; > ;
+ < "Yes or no" ; CUSTOM_TYPE_BOOLEAN ; > ;
+ };
+};
+Edit SFX_ED_PROPERTY_VALUE
+{
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 127 , 2 ) ;
+ Size = MAP_APPFONT ( 61 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ TabStop = TRUE ;
+ Left = TRUE ;
+};
+DateField SFX_FLD_DATE
+{
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 127 , 2 ) ;
+ Size = MAP_APPFONT ( 29 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ TabStop = TRUE ;
+ Left = TRUE ;
+ Spin = TRUE;
+};
+TimeField SFX_FLD_TIME
+{
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 159 , 2 ) ;
+ Size = MAP_APPFONT ( 29 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ TabStop = TRUE ;
+ Left = TRUE ;
+ Spin = TRUE;
+};
+
+Edit SFX_FLD_DURATION
+{
+ Readonly = TRUE;
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 159 , 2 ) ;
+ Size = MAP_APPFONT ( 61 - RSC_CD_TEXTBOX_HEIGHT - 2, RSC_CD_TEXTBOX_HEIGHT ) ;
+ TabStop = TRUE ;
+};
+PushButton SFX_PB_EDIT
+{
+ Pos = MAP_APPFONT ( 159 , 2 ) ;
+ Size = MAP_APPFONT ( RSC_CD_TEXTBOX_HEIGHT , RSC_CD_TEXTBOX_HEIGHT ) ;
+ Text = "...";
+};
+String SFX_ST_DURATION_FORMAT
+{
+ Text [en-US] = " Y: %1 M: %2 D: %3 H: %4 M: %5 S: %6";
+};
+
+Control SFX_WIN_PROPERTY_YESNO
+{
+ HelpId = HID_CTRL_CUSTOMPROPS_YES_NO;
+ OutputSize = TRUE ;
+ Pos = MAP_APPFONT ( 127 , 2 ) ;
+ Size = MAP_APPFONT ( 61 , RSC_CD_TEXTBOX_HEIGHT ) ;
+ Border = TRUE ;
+ DialogControl = TRUE ;
+ RadioButton RB_PROPERTY_YES
+ {
+ TabStop = TRUE ;
+ Pos = MAP_APPFONT( 1 , 1 ) ;
+ Size = MAP_APPFONT( 28 , RSC_CD_RADIOBUTTON_HEIGHT ) ;
+ Text [ en-US ] = "Yes" ;
+ };
+ RadioButton RB_PROPERTY_NO
+ {
+ TabStop = TRUE ;
+ Pos = MAP_APPFONT( 32 , 1 ) ;
+ Size = MAP_APPFONT( 29 , RSC_CD_RADIOBUTTON_HEIGHT ) ;
+ Text [ en-US ] = "No" ;
+ };
+};
+
+ImageButton SFX_PB_PROPERTY_REMOVE
+{
+ Pos = MAP_APPFONT( 190 , 1 );
+ Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_HEIGHT, RSC_CD_PUSHBUTTON_HEIGHT );
+ QuickHelpText [ en-US ] = "Remove Property" ;
+};
+Image SFX_IMG_PROPERTY_REMOVE
+{
+ ImageBitmap = Bitmap { File = "deleterow.bmp" ; };
+ MaskColor = Color { Red=0xffff; Green=0x0000; Blue=0xffff; };
+};
+Image SFX_IMG_PROPERTY_REMOVE_HC
+{
+ ImageBitmap = Bitmap { File = "deleterow_h.bmp" ; };
+ MaskColor = Color { Red=0xffff; Green=0x0000; Blue=0xffff; };
+};
+
+QueryBox SFX_QB_WRONG_TYPE
+{
+ Buttons = WB_OK_CANCEL ;
+ DefButton = WB_DEF_OK ;
+ Message [ en-US ] = "The value entered does not match the specified type.\nThe value will be stored as text." ;
+};
+
+TabDialog SID_DOCINFO
+{
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Moveable = TRUE ;
+ Text [ en-US ] = "Properties of " ;
+ TabControl 1
+ {
+ SVLook = TRUE ;
+ PageList =
+ {
+ PageItem
+ {
+ Identifier = TP_DOCINFODOC ;
+ Text [ en-US ] = "General" ;
+ };
+ PageItem
+ {
+ Identifier = TP_DOCINFODESC ;
+ Text [ en-US ] = "Description" ;
+ };
+ PageItem
+ {
+ Identifier = TP_CUSTOMPROPERTIES ;
+ Text [ en-US ] = "Custom Properties" ;
+ };
+ PageItem
+ {
+ Identifier = TP_DOCINFORELOAD ;
+ Text [ en-US ] = "Internet" ;
+ };
+ PageItem
+ {
+ Identifier = TP_DOCINFOSECURITY ;
+ Text [ en-US ] = "Security" ;
+ };
+ };
+ };
+};
+
+ModalDialog RID_EDIT_DURATIONS
+{
+ HelpId = HID_DLG_CUSTOMPROPS_DURATION;
+ OutputSize = TRUE ;
+ Size = MAP_APPFONT ( 176 , 140 ) ;
+ Text [ en-US ] = "Edit Duration" ;
+ Moveable = TRUE ;
+ OKButton PB_OK
+ {
+ Pos = MAP_APPFONT ( 120 , 7 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ DefButton = TRUE;
+ };
+ CancelButton PB_CANCEL
+ {
+ Pos = MAP_APPFONT ( 120 , 24 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ };
+ HelpButton PB_HELP
+ {
+ Pos = MAP_APPFONT ( 120 , 48 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ };
+ FixedLine FL_DURATION
+ {
+ Pos = MAP_APPFONT ( 6 , 8 ) ;
+ Size = MAP_APPFONT ( 108 , 8 ) ;
+ Text [ en-US ] = "Duration" ;
+ };
+ CheckBox CB_NEGATIVE
+ {
+ HelpID = "sfx2:CheckBox:RID_EDIT_DURATIONS:CB_NEGATIVE";
+ Pos = MAP_APPFONT ( 6 , 21 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Text [ en-US ] = "~Negative" ;
+ };
+ FixedText FT_YEAR
+ {
+ Pos = MAP_APPFONT ( 6 , 38 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "~Years" ;
+ };
+ NumericField ED_YEAR
+ {
+ HelpID = "sfx2:NumericField:RID_EDIT_DURATIONS:ED_YEAR";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 36 ) ;
+ Size = MAP_APPFONT ( 40, RSC_CD_TEXTBOX_HEIGHT ) ;
+ Repeat = TRUE ;
+ Spin = TRUE ;
+ Minimum = 0 ;
+ First = 1 ;
+ Last = 100 ;
+ SpinSize = 1 ;
+ Value = 0 ;
+ };
+ FixedText FT_MONTH
+ {
+ Pos = MAP_APPFONT ( 6 , 52 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "~Months" ;
+ };
+ NumericField ED_MONTH
+ {
+ HelpID = "sfx2:NumericField:RID_EDIT_DURATIONS:ED_MONTH";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 50 ) ;
+ Size = MAP_APPFONT ( 40, RSC_CD_TEXTBOX_HEIGHT ) ;
+ Repeat = TRUE ;
+ Spin = TRUE ;
+ Minimum = 0 ;
+ First = 1 ;
+ Last = 100 ;
+ SpinSize = 1 ;
+ Value = 0 ;
+ };
+ FixedText FT_DAY
+ {
+ Pos = MAP_APPFONT ( 6 , 66 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "~Days" ;
+ };
+ NumericField ED_DAY
+ {
+ HelpID = "sfx2:NumericField:RID_EDIT_DURATIONS:ED_DAY";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 64 ) ;
+ Size = MAP_APPFONT ( 40, RSC_CD_TEXTBOX_HEIGHT ) ;
+ Repeat = TRUE ;
+ Spin = TRUE ;
+ Minimum = 0 ;
+ First = 1 ;
+ Last = 100 ;
+ SpinSize = 1 ;
+ Value = 0 ;
+ };
+ FixedText FT_HOUR
+ {
+ Pos = MAP_APPFONT ( 6 , 80 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "H~ours" ;
+ };
+ NumericField ED_HOUR
+ {
+ HelpID = "sfx2:NumericField:RID_EDIT_DURATIONS:ED_HOUR";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 78 ) ;
+ Size = MAP_APPFONT ( 40, RSC_CD_TEXTBOX_HEIGHT ) ;
+ Repeat = TRUE ;
+ Spin = TRUE ;
+ Minimum = 0 ;
+ First = 1 ;
+ Last = 100 ;
+ SpinSize = 1 ;
+ Value = 0 ;
+ };
+ FixedText FT_MINUTE
+ {
+ Pos = MAP_APPFONT ( 6 , 94 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "Min~utes" ;
+ };
+ NumericField ED_MINUTE
+ {
+ HelpID = "sfx2:NumericField:RID_EDIT_DURATIONS:ED_MINUTE";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70, 92) ;
+ Size = MAP_APPFONT ( 40, RSC_CD_TEXTBOX_HEIGHT ) ;
+ Repeat = TRUE ;
+ Spin = TRUE ;
+ Minimum = 0 ;
+ First = 1 ;
+ Last = 100 ;
+ SpinSize = 1 ;
+ Value = 0 ;
+ };
+ FixedText FT_SECOND
+ {
+ Pos = MAP_APPFONT ( 6, 108 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "~Seconds" ;
+ };
+ NumericField ED_SECOND
+ {
+ HelpID = "sfx2:NumericField:RID_EDIT_DURATIONS:ED_SECOND";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 106 ) ;
+ Size = MAP_APPFONT ( 40, RSC_CD_TEXTBOX_HEIGHT ) ;
+ Repeat = TRUE ;
+ Spin = TRUE ;
+ Minimum = 0 ;
+ First = 1 ;
+ Last = 100 ;
+ SpinSize = 1 ;
+ Value = 0 ;
+ };
+ FixedText FT_MSECOND
+ {
+ Pos = MAP_APPFONT ( 6 , 122 ) ;
+ Size = MAP_APPFONT ( 60 , RSC_CD_FIXEDTEXT_HEIGHT ) ;
+ Left = TRUE ;
+ Text [ en-US ] = "Millise~conds" ;
+ };
+ NumericField ED_MSECOND
+ {
+ HelpID = "sfx2:NumericField:RID_EDIT_DURATIONS:ED_MSECOND";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 120 ) ;
+ Size = MAP_APPFONT ( 40, RSC_CD_TEXTBOX_HEIGHT ) ;
+ Repeat = TRUE ;
+ Spin = TRUE ;
+ Minimum = 0 ;
+ First = 1 ;
+ Last = 1000 ;
+ SpinSize = 1 ;
+ Value = 0 ;
+ };
+
+
+
+};
diff --git a/sfx2/source/dialog/dinfedt.cxx b/sfx2/source/dialog/dinfedt.cxx
new file mode 100644
index 000000000000..5c250f7cc912
--- /dev/null
+++ b/sfx2/source/dialog/dinfedt.cxx
@@ -0,0 +1,66 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+
+#include "sfx2/dinfedt.hxx"
+#include "sfx2/sfxresid.hxx"
+
+#include <sfx2/sfx.hrc>
+#include "dinfedt.hrc"
+
+// class InfoEdit_Impl ---------------------------------------------------
+
+void InfoEdit_Impl::KeyInput( const KeyEvent& rKEvent )
+{
+ if ( rKEvent.GetCharCode() != '~' )
+ Edit::KeyInput( rKEvent );
+}
+
+// class SfxDocInfoEditDlg -----------------------------------------------
+
+SfxDocInfoEditDlg::SfxDocInfoEditDlg( Window* pParent ) :
+
+ ModalDialog( pParent, SfxResId( DLG_DOCINFO_EDT ) ),
+
+ aInfoFL ( this, SfxResId( FL_INFO ) ),
+ aInfo1ED ( this, SfxResId( ED_INFO1 ) ),
+ aInfo2ED ( this, SfxResId( ED_INFO2 ) ),
+ aInfo3ED ( this, SfxResId( ED_INFO3 ) ),
+ aInfo4ED ( this, SfxResId( ED_INFO4 ) ),
+ aOkBT ( this, SfxResId( BT_OK ) ),
+ aCancelBT ( this, SfxResId( BT_CANCEL ) ),
+ aHelpBtn ( this, SfxResId( BTN_HELP ) )
+
+{
+ FreeResource();
+}
+
diff --git a/sfx2/source/dialog/dinfedt.hrc b/sfx2/source/dialog/dinfedt.hrc
new file mode 100644
index 000000000000..ef52362af2cb
--- /dev/null
+++ b/sfx2/source/dialog/dinfedt.hrc
@@ -0,0 +1,38 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#define BT_OK 1
+#define BT_CANCEL 2
+#define BTN_HELP 3
+#define FT_INFO1 4
+#define ED_INFO1 5
+#define FT_INFO2 6
+#define ED_INFO2 7
+#define FT_INFO3 8
+#define ED_INFO3 9
+#define FT_INFO4 10
+#define ED_INFO4 11
+#define FL_INFO 12
diff --git a/sfx2/source/dialog/dinfedt.src b/sfx2/source/dialog/dinfedt.src
new file mode 100644
index 000000000000..110dccf11c40
--- /dev/null
+++ b/sfx2/source/dialog/dinfedt.src
@@ -0,0 +1,125 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <sfx2/sfx.hrc>
+#include "helpid.hrc"
+#include "dinfedt.hrc"
+
+ModalDialog DLG_DOCINFO_EDT
+{
+ HelpId = HID_DOCINFO_EDT ;
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 166 , 79 ) ;
+ Text [ en-US ] = "Edit Field Names" ;
+ Moveable = TRUE ;
+ FixedLine FL_INFO
+ {
+ Pos = MAP_APPFONT ( 6 , 3 ) ;
+ Size = MAP_APPFONT ( 98 , 8 ) ;
+ Text [ en-US ] = "Names" ;
+ };
+ Edit ED_INFO1
+ {
+ HelpID = "sfx2:Edit:DLG_DOCINFO_EDT:ED_INFO1";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 12 , 14 ) ;
+ Size = MAP_APPFONT ( 86 , 12 ) ;
+ };
+ Edit ED_INFO2
+ {
+ HelpID = "sfx2:Edit:DLG_DOCINFO_EDT:ED_INFO2";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 12 , 29 ) ;
+ Size = MAP_APPFONT ( 86 , 12 ) ;
+ };
+ Edit ED_INFO3
+ {
+ HelpID = "sfx2:Edit:DLG_DOCINFO_EDT:ED_INFO3";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 12 , 44 ) ;
+ Size = MAP_APPFONT ( 86 , 12 ) ;
+ };
+ Edit ED_INFO4
+ {
+ HelpID = "sfx2:Edit:DLG_DOCINFO_EDT:ED_INFO4";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 12 , 59 ) ;
+ Size = MAP_APPFONT ( 86 , 12 ) ;
+ };
+ OKButton BT_OK
+ {
+ Pos = MAP_APPFONT ( 110 , 6 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ DefButton = TRUE ;
+ };
+ CancelButton BT_CANCEL
+ {
+ Pos = MAP_APPFONT ( 110 , 23 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ };
+ HelpButton BTN_HELP
+ {
+ Pos = MAP_APPFONT ( 110 , 43 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ };
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/dialog/dockwin.cxx b/sfx2/source/dialog/dockwin.cxx
new file mode 100644
index 000000000000..4f55dfde21a7
--- /dev/null
+++ b/sfx2/source/dialog/dockwin.cxx
@@ -0,0 +1,2021 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <svl/eitem.hxx>
+#include <vcl/decoview.hxx>
+
+#include <vcl/svapp.hxx>
+#include <vcl/timer.hxx>
+#include <rtl/instance.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include <sfx2/dockwin.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/dispatch.hxx>
+#include "workwin.hxx"
+#include "splitwin.hxx"
+#include <sfx2/viewsh.hxx>
+#include "sfx2/sfxhelp.hxx"
+#include <sfx2/objsh.hxx>
+#include <sfx2/msgpool.hxx>
+
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#include <com/sun/star/lang/XSingleComponentFactory.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+
+#define MAX_TOGGLEAREA_WIDTH 20
+#define MAX_TOGGLEAREA_HEIGHT 20
+
+using namespace ::com::sun::star;
+
+// implemented in 'sfx2/source/appl/childwin.cxx'
+extern sal_Bool GetPosSizeFromString( const String& rStr, Point& rPos, Size& rSize );
+extern sal_Bool GetSplitSizeFromString( const String& rStr, Size& rSize );
+
+// If you want to change the number you also have to:
+// - Add new slot ids to sfxsids.hrc
+// - Add new slots to frmslots.sdi
+// - Add new slot definitions to sfx.sdi
+static const int NUM_OF_DOCKINGWINDOWS = 10;
+
+class SfxTitleDockingWindow;
+class SfxTitleDockingWindow : public SfxDockingWindow
+{
+ Window* m_pWrappedWindow;
+ USHORT m_nID;
+
+public:
+ SfxTitleDockingWindow(
+ SfxBindings* pBindings ,
+ SfxChildWindow* pChildWin ,
+ Window* pParent ,
+ WinBits nBits,
+ USHORT nID);
+ virtual ~SfxTitleDockingWindow();
+
+ Window* GetWrappedWindow() const { return m_pWrappedWindow; }
+ void SetWrappedWindow(Window* const pWindow);
+
+ virtual void StateChanged( StateChangedType nType );
+ virtual long Notify( NotifyEvent& rNEvt );
+ virtual void Resize();
+ virtual void Resizing( Size& rSize );
+ virtual BOOL Close();
+};
+
+namespace
+{
+ struct WindowState
+ {
+ ::rtl::OUString sTitle;
+ };
+}
+
+static uno::WeakReference< container::XNameAccess > m_xWindowStateConfiguration;
+static uno::WeakReference< frame::XModuleManager > m_xModuleManager;
+
+static bool lcl_getWindowState( const uno::Reference< container::XNameAccess >& xWindowStateMgr, const ::rtl::OUString& rResourceURL, WindowState& rWindowState )
+{
+ bool bResult = false;
+
+ try
+ {
+ uno::Any a;
+ uno::Sequence< beans::PropertyValue > aWindowState;
+ a = xWindowStateMgr->getByName( rResourceURL );
+ if ( a >>= aWindowState )
+ {
+ for ( sal_Int32 n = 0; n < aWindowState.getLength(); n++ )
+ {
+ if ( aWindowState[n].Name.equalsAscii( "UIName" ))
+ {
+ aWindowState[n].Value >>= rWindowState.sTitle;
+ }
+ }
+ }
+
+ bResult = true;
+ }
+ catch ( container::NoSuchElementException& )
+ {
+ bResult = false;
+ }
+
+ return bResult;
+}
+
+SfxDockingWrapper::SfxDockingWrapper( Window* pParentWnd ,
+ USHORT nId ,
+ SfxBindings* pBindings ,
+ SfxChildWinInfo* pInfo )
+ : SfxChildWindow( pParentWnd , nId )
+{
+ uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
+ const rtl::OUString aDockWindowResourceURL( RTL_CONSTASCII_USTRINGPARAM( "private:resource/dockingwindow/" ));
+
+ SfxTitleDockingWindow* pTitleDockWindow = new SfxTitleDockingWindow( pBindings, this, pParentWnd,
+ WB_STDDOCKWIN | WB_CLIPCHILDREN | WB_SIZEABLE | WB_3DLOOK | WB_ROLLABLE, nId);
+ pWindow = pTitleDockWindow;
+ eChildAlignment = SFX_ALIGN_NOALIGNMENT;
+
+ // Use factory manager to retrieve XWindow factory. That can be used to instanciate
+ // the real window factory.
+ uno::Reference< lang::XSingleComponentFactory > xFactoryMgr(
+ xServiceManager->createInstance(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.ui.WindowContentFactoryManager"))),
+ uno::UNO_QUERY );
+
+ if (xFactoryMgr.is())
+ {
+ SfxDispatcher* pDispatcher = pBindings->GetDispatcher();
+ uno::Reference< frame::XFrame > xFrame( pDispatcher->GetFrame()->GetFrame().GetFrameInterface(), uno::UNO_QUERY );
+ uno::Sequence< uno::Any > aArgs(2);
+ beans::PropertyValue aPropValue;
+ aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
+ aPropValue.Value = uno::makeAny( xFrame );
+ aArgs[0] <<= aPropValue;
+ aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ));
+
+ // create a resource URL from the nId provided by the sfx2
+ ::rtl::OUString aResourceURL( aDockWindowResourceURL );
+ aResourceURL += ::rtl::OUString::valueOf(sal_Int32(nId));
+ aPropValue.Value = uno::makeAny( aResourceURL );
+ aArgs[1] <<= aPropValue;
+
+ uno::Reference< awt::XWindow > xWindow;
+ try
+ {
+ uno::Reference< beans::XPropertySet > xProps( xServiceManager, uno::UNO_QUERY );
+ uno::Reference< uno::XComponentContext > xContext;
+
+ if ( xProps.is() )
+ xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xContext;
+ if ( xContext.is() )
+ {
+ xWindow = uno::Reference< awt::XWindow>(
+ xFactoryMgr->createInstanceWithArgumentsAndContext( aArgs, xContext ),
+ uno::UNO_QUERY );
+ }
+
+ uno::Reference< frame::XModuleManager > xModuleManager( m_xModuleManager );
+ if ( !xModuleManager.is() )
+ {
+ xModuleManager = uno::Reference< frame::XModuleManager >(
+ xServiceManager->createInstance(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ))),
+ uno::UNO_QUERY );
+ m_xModuleManager = xModuleManager;
+ }
+
+ uno::Reference< container::XNameAccess > xWindowStateConfiguration( m_xWindowStateConfiguration );
+ if ( !xWindowStateConfiguration.is() )
+ {
+ xWindowStateConfiguration = uno::Reference< container::XNameAccess >(
+ xServiceManager->createInstance(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.WindowStateConfiguration" ))),
+ uno::UNO_QUERY );
+ m_xWindowStateConfiguration = xWindowStateConfiguration;
+ }
+
+ ::rtl::OUString sModuleIdentifier = xModuleManager->identify( xFrame );
+
+ uno::Reference< container::XNameAccess > xModuleWindowState(
+ xWindowStateConfiguration->getByName( sModuleIdentifier ),
+ uno::UNO_QUERY );
+ if ( xModuleWindowState.is() )
+ {
+ WindowState aDockWinState;
+ if ( lcl_getWindowState( xModuleWindowState, aResourceURL, aDockWinState ))
+ pTitleDockWindow->SetText( aDockWinState.sTitle );
+ }
+ }
+ catch ( beans::UnknownPropertyException& )
+ {
+ }
+ catch ( uno::RuntimeException& )
+ {
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ Window* pContentWindow = VCLUnoHelper::GetWindow(xWindow);
+ if ( pContentWindow )
+ pContentWindow->SetStyle( pContentWindow->GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
+ pTitleDockWindow->SetWrappedWindow(pContentWindow);
+ }
+
+ pWindow->SetOutputSizePixel( Size( 270, 240 ) );
+
+ ( ( SfxDockingWindow* ) pWindow )->Initialize( pInfo );
+ SetHideNotDelete( TRUE );
+}
+
+SfxChildWindow* SfxDockingWrapper::CreateImpl(
+Window *pParent, sal_uInt16 nId, SfxBindings *pBindings, SfxChildWinInfo* pInfo )
+{
+ SfxChildWindow *pWin = new SfxDockingWrapper(pParent, nId, pBindings, pInfo); return pWin;
+}
+
+sal_uInt16 SfxDockingWrapper::GetChildWindowId ()
+{
+ DBG_ASSERT( false, "This method shouldn't be called!" );
+ return 0;
+}
+
+void SfxDockingWrapper::RegisterChildWindow (sal_Bool bVis, SfxModule *pMod, sal_uInt16 nFlags)
+{
+ // pre-register a couple of docking windows
+ for (int i=0; i < NUM_OF_DOCKINGWINDOWS; i++ )
+ {
+ USHORT nID = USHORT(SID_DOCKWIN_START+i);
+ SfxChildWinFactory *pFact = new SfxChildWinFactory( SfxDockingWrapper::CreateImpl, nID, 0xffff );
+ pFact->aInfo.nFlags |= nFlags;
+ pFact->aInfo.bVisible = bVis;
+ SfxChildWindow::RegisterChildWindow(pMod, pFact);
+ }
+}
+
+SfxChildWinInfo SfxDockingWrapper::GetInfo() const
+{
+ SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
+ ((SfxDockingWindow*)GetWindow())->FillInfo( aInfo );
+ return aInfo;
+};
+
+SfxTitleDockingWindow::SfxTitleDockingWindow( SfxBindings* pBind ,
+ SfxChildWindow* pChildWin ,
+ Window* pParent ,
+ WinBits nBits,
+ USHORT nID ) :
+ SfxDockingWindow( pBind ,
+ pChildWin ,
+ pParent ,
+ nBits ),
+ m_pWrappedWindow(0),
+ m_nID(nID)
+{
+}
+
+SfxTitleDockingWindow::~SfxTitleDockingWindow()
+{
+ delete m_pWrappedWindow;
+}
+
+void SfxTitleDockingWindow::SetWrappedWindow( Window* const pWindow )
+{
+ m_pWrappedWindow = pWindow;
+ if (m_pWrappedWindow)
+ {
+ m_pWrappedWindow->SetParent(this);
+ m_pWrappedWindow->SetSizePixel( GetOutputSizePixel() );
+ m_pWrappedWindow->Show();
+ }
+}
+
+long SfxTitleDockingWindow::Notify( NotifyEvent& rNEvt )
+{
+ return SfxDockingWindow::Notify( rNEvt );
+}
+
+void SfxTitleDockingWindow::StateChanged( StateChangedType nType )
+{
+ if ( nType == STATE_CHANGE_INITSHOW )
+ {
+ Window* pWindow = GetWrappedWindow();
+ if ( pWindow )
+ {
+ pWindow->SetSizePixel( GetOutputSizePixel() );
+ pWindow->Show();
+ }
+ }
+
+ SfxDockingWindow::StateChanged(nType);
+}
+
+void SfxTitleDockingWindow::Resize()
+{
+ SfxDockingWindow::Resize();
+ if (m_pWrappedWindow)
+ m_pWrappedWindow->SetSizePixel( GetOutputSizePixel() );
+}
+
+void SfxTitleDockingWindow::Resizing( Size &rSize )
+{
+ SfxDockingWindow::Resizing( rSize );
+ if (m_pWrappedWindow)
+ m_pWrappedWindow->SetSizePixel( GetOutputSizePixel() );
+}
+
+BOOL SfxTitleDockingWindow::Close()
+{
+ return SfxDockingWindow::Close();
+}
+
+namespace
+{
+ struct ChildrenRegisteredMap : public rtl::Static< bool, ChildrenRegisteredMap > {};
+}
+
+static bool lcl_checkDockingWindowID( USHORT nID )
+{
+ if (nID < SID_DOCKWIN_START || nID >= USHORT(SID_DOCKWIN_START+NUM_OF_DOCKINGWINDOWS))
+ return false;
+ else
+ return true;
+}
+
+static SfxWorkWindow* lcl_getWorkWindowFromXFrame( const uno::Reference< frame::XFrame >& rFrame )
+{
+ // We need to find the corresponding SfxFrame of our XFrame
+ SfxFrame* pFrame = SfxFrame::GetFirst();
+ SfxFrame* pXFrame = 0;
+ while ( pFrame )
+ {
+ uno::Reference< frame::XFrame > xViewShellFrame( pFrame->GetFrameInterface() );
+ if ( xViewShellFrame == rFrame )
+ {
+ pXFrame = pFrame;
+ break;
+ }
+ else
+ pFrame = SfxFrame::GetNext( *pFrame );
+ }
+
+ // If we have a SfxFrame we can retrieve the work window (Sfx layout manager for docking windows)
+ if ( pXFrame )
+ return pXFrame->GetWorkWindow_Impl();
+ else
+ return NULL;
+}
+
+/*
+ Factory function used by the framework layout manager to "create" a docking window with a special name.
+ The string rDockingWindowName MUST BE a valid ID! The ID is pre-defined by a certain slot range located
+ in sfxsids.hrc (currently SID_DOCKWIN_START = 9800).
+*/
+void SAL_CALL SfxDockingWindowFactory( const uno::Reference< frame::XFrame >& rFrame, const rtl::OUString& rDockingWindowName )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ USHORT nID = USHORT(rDockingWindowName.toInt32());
+
+ // Check the range of the provided ID otherwise nothing will happen
+ if ( lcl_checkDockingWindowID( nID ))
+ {
+ SfxWorkWindow* pWorkWindow = lcl_getWorkWindowFromXFrame( rFrame );
+ if ( pWorkWindow )
+ {
+ SfxChildWindow* pChildWindow = pWorkWindow->GetChildWindow_Impl(nID);
+ if ( !pChildWindow )
+ {
+ // Register window at the workwindow child window list
+ pWorkWindow->SetChildWindow_Impl( nID, true, false );
+ }
+ }
+ }
+}
+
+/*
+ Function used by the framework layout manager to determine the visibility state of a docking window with
+ a special name. The string rDockingWindowName MUST BE a valid ID! The ID is pre-defined by a certain slot
+ range located in sfxsids.hrc (currently SID_DOCKWIN_START = 9800).
+*/
+bool SAL_CALL IsDockingWindowVisible( const uno::Reference< frame::XFrame >& rFrame, const rtl::OUString& rDockingWindowName )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ USHORT nID = USHORT(rDockingWindowName.toInt32());
+
+ // Check the range of the provided ID otherwise nothing will happen
+ if ( lcl_checkDockingWindowID( nID ))
+ {
+ SfxWorkWindow* pWorkWindow = lcl_getWorkWindowFromXFrame( rFrame );
+ if ( pWorkWindow )
+ {
+ SfxChildWindow* pChildWindow = pWorkWindow->GetChildWindow_Impl(nID);
+ if ( pChildWindow )
+ return true;
+ }
+ }
+
+ return false;
+}
+
+class SfxDockingWindow_Impl
+{
+friend class SfxDockingWindow;
+
+ SfxChildAlignment eLastAlignment;
+ SfxChildAlignment eDockAlignment;
+ BOOL bConstructed;
+ Size aMinSize;
+ SfxSplitWindow* pSplitWin;
+ BOOL bSplitable;
+// BOOL bAutoHide;
+ Timer aMoveTimer;
+
+ // Folgende members sind nur in der Zeit von StartDocking bis EndDocking
+ // g"ultig:
+ BOOL bEndDocked;
+ Size aSplitSize;
+ long nHorizontalSize;
+ long nVerticalSize;
+ USHORT nLine;
+ USHORT nPos;
+ USHORT nDockLine;
+ USHORT nDockPos;
+ BOOL bNewLine;
+ BOOL bDockingPrevented;
+ ByteString aWinState;
+
+ SfxChildAlignment GetLastAlignment() const
+ { return eLastAlignment; }
+ void SetLastAlignment(SfxChildAlignment eAlign)
+ { eLastAlignment = eAlign; }
+ SfxChildAlignment GetDockAlignment() const
+ { return eDockAlignment; }
+ void SetDockAlignment(SfxChildAlignment eAlign)
+ { eDockAlignment = eAlign; }
+};
+
+//-------------------------------------------------------------------------
+
+void SfxDockingWindow::Resize()
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode der Klasse DockingWindow merkt sich ggf. eine
+ ver"anderte FloatingSize.
+ Wird diese Methode von einer abgeleiteten Klasse "uberschrieben, mu\s
+ auch SfxDockingWindow::Resize() gerufen werden.
+*/
+{
+ DockingWindow::Resize();
+ Invalidate();
+ if ( pImp->bConstructed && pMgr )
+ {
+ if ( IsFloatingMode() )
+ {
+ // start timer for saving window status information
+ pImp->aMoveTimer.Start();
+ }
+ else
+ {
+ Size aSize( GetSizePixel() );
+ switch ( pImp->GetDockAlignment() )
+ {
+ case SFX_ALIGN_LEFT:
+ case SFX_ALIGN_FIRSTLEFT:
+ case SFX_ALIGN_LASTLEFT:
+ case SFX_ALIGN_RIGHT:
+ case SFX_ALIGN_FIRSTRIGHT:
+ case SFX_ALIGN_LASTRIGHT:
+ pImp->nHorizontalSize = aSize.Width();
+ pImp->aSplitSize = aSize;
+ break;
+ case SFX_ALIGN_TOP:
+ case SFX_ALIGN_LOWESTTOP:
+ case SFX_ALIGN_HIGHESTTOP:
+ case SFX_ALIGN_BOTTOM:
+ case SFX_ALIGN_HIGHESTBOTTOM:
+ case SFX_ALIGN_LOWESTBOTTOM:
+ pImp->nVerticalSize = aSize.Height();
+ pImp->aSplitSize = aSize;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxDockingWindow::PrepareToggleFloatingMode()
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode der Klasse DockingWindow erm"oglicht ein Eingreifen
+ in das Umschalten des floating mode.
+ Wird diese Methode von einer abgeleiteten Klasse "uberschrieben, mu\s
+ danach SfxDockingWindow::PrepareToggleFloatingMode() gerufen werden,
+ wenn nicht FALSE zur"uckgegeben wird.
+*/
+
+{
+ if (!pImp->bConstructed)
+ return TRUE;
+
+ if ( (Application::IsInModalMode() && IsFloatingMode()) || !pMgr )
+ return FALSE;
+
+ if ( pImp->bDockingPrevented )
+ return FALSE;
+
+ if (!IsFloatingMode())
+ {
+ // Testen, ob FloatingMode erlaubt ist
+ if ( CheckAlignment(GetAlignment(),SFX_ALIGN_NOALIGNMENT) != SFX_ALIGN_NOALIGNMENT )
+ return FALSE;
+
+ if ( pImp->pSplitWin )
+ {
+ // Das DockingWindow sitzt in einem SplitWindow und wird abgerissen
+ pImp->pSplitWin->RemoveWindow(this/*, FALSE*/);
+ pImp->pSplitWin = 0;
+ }
+ }
+ else if ( pMgr )
+ {
+ pImp->aWinState = GetFloatingWindow()->GetWindowState();
+
+ // Testen, ob es erlaubt ist, anzudocken
+ if (CheckAlignment(GetAlignment(),pImp->GetLastAlignment()) == SFX_ALIGN_NOALIGNMENT)
+ return FALSE;
+
+ // Testen, ob das Workwindow gerade ein Andocken erlaubt
+ SfxWorkWindow *pWorkWin = pBindings->GetWorkWindow_Impl();
+ if ( !pWorkWin->IsDockingAllowed() || !pWorkWin->IsInternalDockingAllowed() )
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDockingWindow::ToggleFloatingMode()
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode der Klasse DockingWindow setzt die internen
+ Daten des SfxDockingWindow und sorgt f"ur korrektes Alignment am
+ parent window.
+ Durch PrepareToggleFloatMode und Initialize ist sichergestellt, da\s
+ pImp->GetLastAlignment() immer eine erlaubtes Alignment liefert.
+ Wird diese Methode von einer abgeleiteten Klasse "uberschrieben, mu\s
+ zuerst SfxDockingWindow::ToggleFloatingMode() gerufen werden.
+*/
+{
+ if ( !pImp->bConstructed || !pMgr )
+ return; // Kein Handler-Aufruf
+
+ // Altes Alignment merken und dann umschalten.
+ // Sv hat jetzt schon umgeschaltet, aber Alignment am SfxDockingWindow
+ // ist noch das alte!
+ // Was war ich bisher ?
+ SfxChildAlignment eLastAlign = GetAlignment();
+
+ SfxWorkWindow *pWorkWin = pBindings->GetWorkWindow_Impl();
+ SfxChildIdentifier eIdent = SFX_CHILDWIN_DOCKINGWINDOW;
+ if ( pImp->bSplitable )
+ eIdent = SFX_CHILDWIN_SPLITWINDOW;
+
+ if (IsFloatingMode())
+ {
+ SetAlignment(SFX_ALIGN_NOALIGNMENT);
+ if ( pImp->aWinState.Len() )
+ GetFloatingWindow()->SetWindowState( pImp->aWinState );
+ else
+ GetFloatingWindow()->SetOutputSizePixel( GetFloatingSize() );
+/*
+ if ( pImp->bSplitable && !pImp->bEndDocked )
+ // Wenn das Fenster vorher in einem SplitWindow lag, kommt von
+ // Sv kein Show
+ Show();
+*/
+ }
+ else
+ {
+ if (pImp->GetDockAlignment() == eLastAlign)
+ {
+ // Wenn ToggleFloatingMode aufgerufen wurde, das DockAlignment
+ // aber noch unver"andert ist, mu\s das ein Toggeln durch DClick
+ // gewesen sein, also LastAlignment verwenden
+ SetAlignment (pImp->GetLastAlignment());
+ if ( !pImp->bSplitable )
+ SetSizePixel( CalcDockingSize(GetAlignment()) );
+ }
+ else
+ {
+ // Toggeln wurde durch Draggen ausgel"ost
+ pImp->nLine = pImp->nDockLine;
+ pImp->nPos = pImp->nDockPos;
+ SetAlignment (pImp->GetDockAlignment());
+ }
+
+ if ( pImp->bSplitable )
+ {
+ // Das DockingWindow kommt jetzt in ein SplitWindow
+ pImp->pSplitWin = pWorkWin->GetSplitWindow_Impl(GetAlignment());
+
+ // Das LastAlignment ist jetzt immer noch das zuletzt angedockte
+ SfxSplitWindow *pSplit = pWorkWin->GetSplitWindow_Impl(pImp->GetLastAlignment());
+
+ DBG_ASSERT( pSplit, "LastAlignment kann nicht stimmen!" );
+ if ( pSplit && pSplit != pImp->pSplitWin )
+ pSplit->ReleaseWindow_Impl(this);
+ if ( pImp->GetDockAlignment() == eLastAlign )
+ pImp->pSplitWin->InsertWindow( this, pImp->aSplitSize );
+ else
+ pImp->pSplitWin->InsertWindow( this, pImp->aSplitSize, pImp->nLine, pImp->nPos, pImp->bNewLine );
+ if ( !pImp->pSplitWin->IsFadeIn() )
+ pImp->pSplitWin->FadeIn();
+ }
+ }
+
+ // altes Alignment festhalten f"ur n"achstes Togglen; erst jetzt setzen
+ // wg. Abmelden beim SplitWindow!
+ pImp->SetLastAlignment(eLastAlign);
+
+ // DockAlignment zur"ucksetzen, falls noch EndDocking gerufen wird
+ pImp->SetDockAlignment(GetAlignment());
+
+ // SfxChildWindow korrekt andocken bzw. entdocken
+ if ( pMgr )
+ pWorkWin->ConfigChild_Impl( eIdent, SFX_TOGGLEFLOATMODE, pMgr->GetType() );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDockingWindow::StartDocking()
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode der Klasse DockingWindow holt vom parent window
+ das innere und "au\sere docking rectangle.
+ Wird diese Methode von einer abgeleiteten Klasse "uberschrieben, mu\s
+ am Ende SfxDockingWindow::StartDocking() gerufen werden.
+*/
+{
+ if ( !pImp->bConstructed || !pMgr )
+ return;
+ SfxChildIdentifier eIdent = SFX_CHILDWIN_DOCKINGWINDOW;
+ if ( pImp->bSplitable )
+ eIdent = SFX_CHILDWIN_SPLITWINDOW;
+ SfxWorkWindow *pWorkWin = pBindings->GetWorkWindow_Impl();
+ pWorkWin->ConfigChild_Impl( eIdent, SFX_SETDOCKINGRECTS, pMgr->GetType() );
+ pImp->SetDockAlignment(GetAlignment());
+
+ if ( pImp->pSplitWin )
+ {
+ // Die aktuellen Docking-Daten besorgen
+ pImp->pSplitWin->GetWindowPos(this, pImp->nLine, pImp->nPos);
+ pImp->nDockLine = pImp->nLine;
+ pImp->nDockPos = pImp->nPos;
+ pImp->bNewLine = FALSE;
+ }
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxDockingWindow::Docking( const Point& rPos, Rectangle& rRect )
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode der Klasse DockingWindow berechnet das aktuelle
+ tracking rectangle. Dazu benutzt sie die Methode CalcAlignment(rPos,rRect),
+ deren Verhalten von abgeleiteten Klassen beeinflu\st werden kann (s.u.).
+ Diese Methode sollte nach M"oglichkeit nicht "uberschrieben werden.
+*/
+{
+ if ( Application::IsInModalMode() )
+ return TRUE;
+
+ if ( !pImp->bConstructed || !pMgr )
+ {
+ rRect.SetSize( Size() );
+ return IsFloatingMode();
+ }
+
+ SfxWorkWindow *pWorkWin = pBindings->GetWorkWindow_Impl();
+ if ( pImp->bDockingPrevented || !pWorkWin->IsInternalDockingAllowed() )
+ return FALSE;
+
+ BOOL bFloatMode = FALSE;
+
+ if ( GetOuterRect().IsInside( rPos ) && !IsDockingPrevented() )
+ {
+ // Maus innerhalb OuterRect : Alignment und Rectangle berechnen
+ SfxChildAlignment eAlign = CalcAlignment(rPos, rRect);
+ if (eAlign == SFX_ALIGN_NOALIGNMENT)
+ bFloatMode = TRUE;
+ pImp->SetDockAlignment(eAlign);
+ }
+ else
+ {
+ // Maus nicht innerhalb OuterRect : muss FloatingWindow sein
+ // Ist das erlaubt ?
+ if (CheckAlignment(pImp->GetDockAlignment(),SFX_ALIGN_NOALIGNMENT) != SFX_ALIGN_NOALIGNMENT)
+ return FALSE;
+ bFloatMode = TRUE;
+ if ( SFX_ALIGN_NOALIGNMENT != pImp->GetDockAlignment() )
+ {
+ // wg. SV-Bug darf rRect nur ver"andert werden, wenn sich das
+ // Alignment "andert !
+ pImp->SetDockAlignment(SFX_ALIGN_NOALIGNMENT);
+ rRect.SetSize(CalcDockingSize(SFX_ALIGN_NOALIGNMENT));
+ }
+ }
+
+ if ( !pImp->bSplitable )
+ {
+ // Bei individuell angedocktem Window wird die Position durch das
+ // Alignment und die docking rects festgelegt.
+ Size aSize = rRect.GetSize();
+ Point aPos;
+
+ switch ( pImp->GetDockAlignment() )
+ {
+ case SFX_ALIGN_LEFT:
+ case SFX_ALIGN_FIRSTLEFT:
+ case SFX_ALIGN_LASTLEFT:
+ aPos = aInnerRect.TopLeft();
+ if ( pImp->GetDockAlignment() == GetAlignment() )
+ aPos.X() -= aSize.Width();
+ break;
+
+ case SFX_ALIGN_TOP:
+ case SFX_ALIGN_LOWESTTOP:
+ case SFX_ALIGN_HIGHESTTOP:
+ aPos = Point(aOuterRect.Left(), aInnerRect.Top());
+ if ( pImp->GetDockAlignment() == GetAlignment() )
+ aPos.Y() -= aSize.Height();
+ break;
+
+ case SFX_ALIGN_RIGHT:
+ case SFX_ALIGN_FIRSTRIGHT:
+ case SFX_ALIGN_LASTRIGHT:
+ aPos = Point(aInnerRect.Right() - rRect.GetSize().Width(),
+ aInnerRect.Top());
+ if ( pImp->GetDockAlignment() == GetAlignment() )
+ aPos.X() += aSize.Width();
+ break;
+
+ case SFX_ALIGN_BOTTOM:
+ case SFX_ALIGN_HIGHESTBOTTOM:
+ case SFX_ALIGN_LOWESTBOTTOM:
+ aPos = Point(aOuterRect.Left(),
+ aInnerRect.Bottom() - rRect.GetSize().Height());
+ if ( pImp->GetDockAlignment() == GetAlignment() )
+ aPos.Y() += aSize.Height();
+ break;
+ default:
+ break;
+ }
+
+ rRect.SetPos(aPos);
+ }
+
+ return bFloatMode;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDockingWindow::EndDocking( const Rectangle& rRect, BOOL bFloatMode )
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode der Klasse DockingWindow sorgt f"ur das korrekte
+ Alignment am parent window.
+ Wird diese Methode von einer abgeleiteten Klasse "uberschrieben, mu\s
+ zuerst SfxDockingWindow::EndDocking() gerufen werden.
+*/
+{
+ if ( !pImp->bConstructed || IsDockingCanceled() || !pMgr )
+ return;
+
+ SfxWorkWindow *pWorkWin = pBindings->GetWorkWindow_Impl();
+ BOOL bReArrange = FALSE;
+ SfxChildIdentifier eIdent = SFX_CHILDWIN_DOCKINGWINDOW;
+ if ( pImp->bSplitable )
+ {
+ eIdent = SFX_CHILDWIN_SPLITWINDOW;
+
+ // Wenn sich das Alignment "andert und das Fenster befindet sich
+ // im angedockten Zustand in einem SplitWindow, mu\s umgemeldet werden
+ // Wenn neu angedockt wird, machen PrepareToggleFloatingMode()
+ // und ToggleFloatingMode() das Ummelden.
+ if ( !bFloatMode )
+ bReArrange = TRUE;
+ }
+
+ if ( bReArrange )
+ {
+ if ( GetAlignment() != pImp->GetDockAlignment() )
+ {
+ // Vor dem Show() mu\s das Ummelden passiert sein, daher kann nicht
+ // die Basisklasse gerufen werden
+ if ( IsFloatingMode() || !pImp->bSplitable )
+ Show( FALSE, SHOW_NOFOCUSCHANGE );
+
+ // Die Gr"o\se f"urs Toggeln setzen
+ pImp->aSplitSize = rRect.GetSize();
+ if ( IsFloatingMode() )
+ {
+ SetFloatingMode( bFloatMode );
+ if ( IsFloatingMode() || !pImp->bSplitable )
+ Show( TRUE, SHOW_NOFOCUSCHANGE );
+ }
+ else
+ {
+ pImp->pSplitWin->RemoveWindow(this,FALSE);
+ pImp->nLine = pImp->nDockLine;
+ pImp->nPos = pImp->nDockPos;
+ pImp->pSplitWin->ReleaseWindow_Impl(this);
+ pImp->pSplitWin = pWorkWin->GetSplitWindow_Impl(pImp->GetDockAlignment());
+ pImp->pSplitWin->InsertWindow( this, pImp->aSplitSize, pImp->nDockLine, pImp->nDockPos, pImp->bNewLine );
+ if ( !pImp->pSplitWin->IsFadeIn() )
+ pImp->pSplitWin->FadeIn();
+ }
+ }
+ else if ( pImp->nLine != pImp->nDockLine || pImp->nPos != pImp->nDockPos || pImp->bNewLine )
+ {
+ // Ich wurde innerhalb meines Splitwindows verschoben.
+ if ( pImp->nLine != pImp->nDockLine )
+ pImp->aSplitSize = rRect.GetSize();
+ pImp->pSplitWin->MoveWindow( this, pImp->aSplitSize, pImp->nDockLine, pImp->nDockPos, pImp->bNewLine );
+ }
+ }
+ else
+ {
+ pImp->bEndDocked = TRUE;
+ DockingWindow::EndDocking(rRect, bFloatMode);
+ pImp->bEndDocked = FALSE;
+ }
+
+ SetAlignment( IsFloatingMode() ? SFX_ALIGN_NOALIGNMENT : pImp->GetDockAlignment() );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDockingWindow::Resizing( Size& /*rSize*/ )
+
+/* [Beschreibung]
+
+ Virtuelle Methode der Klasse DockingWindow.
+ Hier kann das interaktive Umgr"o\sern im FloatingMode beeinflu\t werden,
+ z.B. indem nur diskrete Werte f"ur Breite und/oder H"ohe zugelassen werden.
+ Die Basisimplementation verhindert, da\s die OutputSize kleiner wird als
+ eine mit SetMinOutputSizePixel() gesetzte Gr"o\se.
+*/
+
+{
+/*
+ if(rSize.Width() < pImp->aMinSize.Width())
+ rSize.Width() = pImp->aMinSize.Width();
+ if(rSize.Height() < pImp->aMinSize.Height())
+ rSize.Height() = pImp->aMinSize.Height();
+*/
+}
+
+//-------------------------------------------------------------------------
+
+SfxDockingWindow::SfxDockingWindow( SfxBindings *pBindinx, SfxChildWindow *pCW,
+ Window* pParent, WinBits nWinBits) :
+ DockingWindow (pParent, nWinBits),
+ pBindings(pBindinx),
+ pMgr(pCW),
+ pImp(NULL)
+
+/* [Beschreibung]
+
+ ctor der Klasse SfxDockingWindow. Es wird ein SfxChildWindow ben"otigt,
+ da das Andocken im Sfx "uber SfxChildWindows realisiert wird.
+*/
+
+{
+ if ( GetHelpId().getLength() )
+ {
+ SetUniqueId( GetHelpId() );
+ SetHelpId("");
+ }
+ else
+ {
+ SfxViewFrame* pViewFrame = pBindings->GetDispatcher()->GetFrame();
+ SfxSlotPool* pSlotPool = pViewFrame->GetObjectShell()->GetModule()->GetSlotPool();
+ const SfxSlot* pSlot = pSlotPool->GetSlot( pCW->GetType() );
+ if ( pSlot )
+ {
+ rtl::OString aCmd("SFXDOCKINGWINDOW_");
+ aCmd += pSlot->GetUnoName();
+ SetUniqueId( aCmd );
+ }
+ }
+
+ pImp = new SfxDockingWindow_Impl;
+ pImp->bConstructed = FALSE;
+ pImp->pSplitWin = 0;
+ pImp->bEndDocked = FALSE;
+ pImp->bDockingPrevented = FALSE;
+
+ pImp->bSplitable = TRUE;
+// pImp->bAutoHide = FALSE;
+
+ // Zun"achst auf Defaults setzen; das Alignment wird in der Subklasse gesetzt
+ pImp->nLine = pImp->nDockLine = 0;
+ pImp->nPos = pImp->nDockPos = 0;
+ pImp->bNewLine = FALSE;
+ pImp->SetLastAlignment(SFX_ALIGN_NOALIGNMENT);
+ pImp->aMoveTimer.SetTimeout(50);
+ pImp->aMoveTimer.SetTimeoutHdl(LINK(this,SfxDockingWindow,TimerHdl));
+
+// DBG_ASSERT(pMgr,"DockingWindow erfordert ein SfxChildWindow!");
+}
+
+//-------------------------------------------------------------------------
+
+SfxDockingWindow::SfxDockingWindow( SfxBindings *pBindinx, SfxChildWindow *pCW,
+ Window* pParent, const ResId& rResId) :
+ DockingWindow(pParent, rResId),
+ pBindings(pBindinx),
+ pMgr(pCW),
+ pImp(NULL)
+
+/* [Beschreibung]
+
+ ctor der Klasse SfxDockingWindow. Es wird ein SfxChildWindow ben"otigt,
+ da das Andocken im Sfx "uber SfxChildWindows realisiert wird.
+*/
+
+{
+ if ( GetHelpId().getLength() )
+ {
+ SetUniqueId( GetHelpId() );
+ SetHelpId("");
+ }
+ else
+ {
+ SfxViewFrame* pViewFrame = pBindings->GetDispatcher()->GetFrame();
+ SfxSlotPool* pSlotPool = pViewFrame->GetObjectShell()->GetModule()->GetSlotPool();
+ const SfxSlot* pSlot = pSlotPool->GetSlot( pCW->GetType() );
+ if ( pSlot )
+ {
+ rtl::OString aCmd("SFXDOCKINGWINDOW_");
+ aCmd += pSlot->GetUnoName();
+ SetUniqueId( aCmd );
+ }
+ }
+
+ pImp = new SfxDockingWindow_Impl;
+ pImp->bConstructed = FALSE;
+ pImp->pSplitWin = 0;
+ pImp->bEndDocked = FALSE;
+ pImp->bDockingPrevented = FALSE;
+
+ pImp->bSplitable = TRUE;
+// pImp->bAutoHide = FALSE;
+
+ // Zun"achst auf Defaults setzen; das Alignment wird in der Subklasse gesetzt
+ pImp->nLine = pImp->nDockLine = 0;
+ pImp->nPos = pImp->nDockPos = 0;
+ pImp->bNewLine = FALSE;
+ pImp->SetLastAlignment(SFX_ALIGN_NOALIGNMENT);
+ pImp->aMoveTimer.SetTimeout(50);
+ pImp->aMoveTimer.SetTimeoutHdl(LINK(this,SfxDockingWindow,TimerHdl));
+
+// DBG_ASSERT(pMgr,"DockingWindow erfordert ein SfxChildWindow!");
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDockingWindow::Initialize(SfxChildWinInfo *pInfo)
+/* [Beschreibung]
+
+ Initialisierung der Klasse SfxDockingWindow "uber ein SfxChildWinInfo.
+ Die Initialisierung erfolgt erst in einem 2.Schritt nach dem ctor und sollte
+ vom ctor der abgeleiteten Klasse oder vom ctor des SfxChildWindows
+ aufgerufen werden.
+*/
+{
+ if ( !pMgr )
+ {
+ // Bugfix #39771
+ pImp->SetDockAlignment( SFX_ALIGN_NOALIGNMENT );
+ pImp->bConstructed = TRUE;
+ return;
+ }
+
+ if ( pInfo->nFlags & SFX_CHILDWIN_FORCEDOCK )
+ pImp->bDockingPrevented = TRUE;
+
+ pImp->aSplitSize = GetOutputSizePixel();
+ if ( !GetFloatingSize().Width() )
+ {
+ Size aMinSize( GetMinOutputSizePixel() );
+ SetFloatingSize( pImp->aSplitSize );
+ if ( pImp->aSplitSize.Width() < aMinSize.Width() )
+ pImp->aSplitSize.Width() = aMinSize.Width();
+ if ( pImp->aSplitSize.Height() < aMinSize.Height() )
+ pImp->aSplitSize.Height() = aMinSize.Height();
+ }
+
+ sal_Bool bVertHorzRead( sal_False );
+ if ( pInfo->aExtraString.Len() )
+ {
+ // get information about alignment, split size and position in SplitWindow
+ String aStr;
+ USHORT nPos = pInfo->aExtraString.SearchAscii("AL:");
+ if ( nPos != STRING_NOTFOUND )
+ {
+ // alignment information
+ USHORT n1 = pInfo->aExtraString.Search('(', nPos);
+ if ( n1 != STRING_NOTFOUND )
+ {
+ USHORT n2 = pInfo->aExtraString.Search(')', n1);
+ if ( n2 != STRING_NOTFOUND )
+ {
+ // extract alignment information from extrastring
+ aStr = pInfo->aExtraString.Copy(nPos, n2 - nPos + 1);
+ pInfo->aExtraString.Erase(nPos, n2 - nPos + 1);
+ aStr.Erase(nPos, n1-nPos+1);
+ }
+ }
+ }
+
+ if ( aStr.Len() )
+ {
+ // accept window state only if alignment is also set
+ pImp->aWinState = pInfo->aWinState;
+
+ // check for valid alignment
+ SfxChildAlignment eLocalAlignment = (SfxChildAlignment) (USHORT) aStr.ToInt32();
+ if ( pImp->bDockingPrevented )
+ // docking prevented, ignore old configuration and take alignment from default
+ aStr.Erase();
+ else
+ SetAlignment( eLocalAlignment );
+
+ SfxChildAlignment eAlign = CheckAlignment(GetAlignment(),GetAlignment());
+ if ( eAlign != GetAlignment() )
+ {
+ DBG_ERROR("Invalid Alignment!");
+ SetAlignment( eAlign );
+ aStr.Erase();
+ }
+
+ // get last alignment (for toggeling)
+ nPos = aStr.Search(',');
+ if ( nPos != STRING_NOTFOUND )
+ {
+ aStr.Erase(0, nPos+1);
+ pImp->SetLastAlignment( (SfxChildAlignment) (USHORT) aStr.ToInt32() );
+ }
+
+ nPos = aStr.Search(',');
+ if ( nPos != STRING_NOTFOUND )
+ {
+ // get split size and position in SplitWindow
+ Point aPos;
+ aStr.Erase(0, nPos+1);
+ if ( GetPosSizeFromString( aStr, aPos, pImp->aSplitSize ) )
+ {
+ pImp->nLine = pImp->nDockLine = (USHORT) aPos.X();
+ pImp->nPos = pImp->nDockPos = (USHORT) aPos.Y();
+ pImp->nVerticalSize = pImp->aSplitSize.Height();
+ pImp->nHorizontalSize = pImp->aSplitSize.Width();
+ if ( GetSplitSizeFromString( aStr, pImp->aSplitSize ))
+ bVertHorzRead = sal_True;
+ }
+ }
+ }
+ else {
+ DBG_ERROR( "Information is missing!" );
+ }
+ }
+
+ if ( !bVertHorzRead )
+ {
+ pImp->nVerticalSize = pImp->aSplitSize.Height();
+ pImp->nHorizontalSize = pImp->aSplitSize.Width();
+ }
+
+ SfxWorkWindow *pWorkWin = pBindings->GetWorkWindow_Impl();
+ if ( GetAlignment() != SFX_ALIGN_NOALIGNMENT )
+ {
+ // check if SfxWorkWindow is able to allow docking at its border
+ if (
+ !pWorkWin->IsDockingAllowed() ||
+ !pWorkWin->IsInternalDockingAllowed() ||
+ ( (GetFloatStyle() & WB_STANDALONE) && Application::IsInModalMode()) )
+ {
+ SetAlignment( SFX_ALIGN_NOALIGNMENT );
+ }
+ }
+
+ // detect floating mode
+ // toggeling mode will not execute code in handlers, because pImp->bConstructed is not set yet
+ BOOL bFloatMode = IsFloatingMode();
+ if ( bFloatMode != ((GetAlignment() == SFX_ALIGN_NOALIGNMENT)) )
+ {
+ bFloatMode = !bFloatMode;
+ SetFloatingMode( bFloatMode );
+ if ( bFloatMode )
+ {
+ if ( pImp->aWinState.Len() )
+ GetFloatingWindow()->SetWindowState( pImp->aWinState );
+ else
+ GetFloatingWindow()->SetOutputSizePixel( GetFloatingSize() );
+ }
+ }
+
+ if ( IsFloatingMode() )
+ {
+ // validate last alignment
+ SfxChildAlignment eLastAlign = pImp->GetLastAlignment();
+ if ( eLastAlign == SFX_ALIGN_NOALIGNMENT)
+ eLastAlign = CheckAlignment(eLastAlign, SFX_ALIGN_LEFT);
+ if ( eLastAlign == SFX_ALIGN_NOALIGNMENT)
+ eLastAlign = CheckAlignment(eLastAlign, SFX_ALIGN_RIGHT);
+ if ( eLastAlign == SFX_ALIGN_NOALIGNMENT)
+ eLastAlign = CheckAlignment(eLastAlign, SFX_ALIGN_TOP);
+ if ( eLastAlign == SFX_ALIGN_NOALIGNMENT)
+ eLastAlign = CheckAlignment(eLastAlign, SFX_ALIGN_BOTTOM);
+ pImp->SetLastAlignment(eLastAlign);
+ }
+ else
+ {
+ // docked window must have NOALIGNMENT as last alignment
+ pImp->SetLastAlignment(SFX_ALIGN_NOALIGNMENT);
+
+ if ( pImp->bSplitable )
+ {
+// pImp->bAutoHide = ( pInfo->nFlags & SFX_CHILDWIN_AUTOHIDE) != 0;
+ pImp->pSplitWin = pWorkWin->GetSplitWindow_Impl(GetAlignment());
+ pImp->pSplitWin->InsertWindow(this, pImp->aSplitSize);
+ }
+ else
+ {
+ //?????? Currently not supported
+ // Fenster ist individuell angedockt; Gr"o\se berechnen.
+ // Dazu mu\s sie mit der FloatingSize initialisiert werden, falls
+ // irgendwer sich darauf verl"a\st, da\s eine vern"unftige Gr"o\se
+ // gesetzt ist
+ SetSizePixel(GetFloatingSize());
+ SetSizePixel(CalcDockingSize(GetAlignment()));
+ }
+ }
+
+ // save alignment
+ pImp->SetDockAlignment( GetAlignment() );
+}
+
+void SfxDockingWindow::Initialize_Impl()
+{
+ if ( !pMgr )
+ {
+ // Bugfix #39771
+ pImp->bConstructed = TRUE;
+ return;
+ }
+
+ FloatingWindow* pFloatWin = GetFloatingWindow();
+ BOOL bSet = FALSE;
+ if ( pFloatWin )
+ {
+ bSet = !pFloatWin->IsDefaultPos();
+ }
+ else
+ {
+ Point aPos = GetFloatingPos();
+ if ( aPos != Point() )
+ bSet = TRUE;
+ }
+
+ if ( !bSet)
+ {
+ SfxViewFrame *pFrame = pBindings->GetDispatcher_Impl()->GetFrame();
+ Window* pEditWin = pFrame->GetViewShell()->GetWindow();
+ Point aPos = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
+ aPos = GetParent()->ScreenToOutputPixel( aPos );
+ SetFloatingPos( aPos );
+ }
+
+ if ( pFloatWin )
+ {
+ // initialize floating window
+ if ( !pImp->aWinState.Len() )
+ // window state never set before, get if from defaults
+ pImp->aWinState = pFloatWin->GetWindowState();
+
+ // trick: use VCL method SetWindowState to adjust position and size
+ pFloatWin->SetWindowState( pImp->aWinState );
+
+ // remember floating size for calculating alignment and tracking rectangle
+ SetFloatingSize( pFloatWin->GetSizePixel() );
+
+ // some versions of VCL didn't call resize in the current situation
+ //Resize();
+ }
+
+ // allow calling of docking handlers
+ pImp->bConstructed = TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDockingWindow::FillInfo(SfxChildWinInfo& rInfo) const
+
+/* [Beschreibung]
+
+ F"ullt ein SfxChildWinInfo mit f"ur SfxDockingWindow spezifischen Daten,
+ damit sie in die INI-Datei geschrieben werden koennen.
+ Es wird angenommen, da\s rInfo alle anderen evt. relevanten Daten in
+ der ChildWindow-Klasse erh"alt.
+ Eingetragen werden hier gemerkten Gr"o\sen, das ZoomIn-Flag und die
+ f"ur das Docking relevanten Informationen.
+ Wird diese Methode "uberschrieben, mu\s zuerst die Basisimplementierung
+ gerufen werden.
+*/
+
+{
+ if ( !pMgr )
+ return;
+
+ if ( GetFloatingWindow() && pImp->bConstructed )
+ pImp->aWinState = GetFloatingWindow()->GetWindowState();
+
+ rInfo.aWinState = pImp->aWinState;
+ rInfo.aExtraString = DEFINE_CONST_UNICODE("AL:(");
+ rInfo.aExtraString += String::CreateFromInt32((USHORT) GetAlignment());
+ rInfo.aExtraString += ',';
+ rInfo.aExtraString += String::CreateFromInt32 ((USHORT) pImp->GetLastAlignment());
+ if ( pImp->bSplitable )
+ {
+ Point aPos(pImp->nLine, pImp->nPos);
+ rInfo.aExtraString += ',';
+ rInfo.aExtraString += String::CreateFromInt32( aPos.X() );
+ rInfo.aExtraString += '/';
+ rInfo.aExtraString += String::CreateFromInt32( aPos.Y() );
+ rInfo.aExtraString += '/';
+ rInfo.aExtraString += String::CreateFromInt32( pImp->nHorizontalSize );
+ rInfo.aExtraString += '/';
+ rInfo.aExtraString += String::CreateFromInt32( pImp->nVerticalSize );
+ rInfo.aExtraString += ',';
+ rInfo.aExtraString += String::CreateFromInt32( pImp->aSplitSize.Width() );
+ rInfo.aExtraString += ';';
+ rInfo.aExtraString += String::CreateFromInt32( pImp->aSplitSize.Height() );
+ }
+
+ rInfo.aExtraString += ')';
+}
+
+//-------------------------------------------------------------------------
+
+SfxDockingWindow::~SfxDockingWindow()
+{
+ ReleaseChildWindow_Impl();
+ delete pImp;
+}
+
+void SfxDockingWindow::ReleaseChildWindow_Impl()
+{
+ if ( pMgr && pMgr->GetFrame() == pBindings->GetActiveFrame() )
+ pBindings->SetActiveFrame( NULL );
+
+ if ( pMgr && pImp->pSplitWin && pImp->pSplitWin->IsItemValid( GetType() ) )
+ pImp->pSplitWin->RemoveWindow(this);
+
+ pMgr=NULL;
+}
+
+//-------------------------------------------------------------------------
+
+SfxChildAlignment SfxDockingWindow::CalcAlignment(const Point& rPos, Rectangle& rRect)
+
+/* [Beschreibung]
+
+ Diese Methode berechnet f"ur gegebene Mausposition und tracking rectangle,
+ welches Alignment sich daraus ergeben w"urde. Beim Wechsel des Alignments
+ kann sich auch das tracking rectangle "andern, so dass ein ver"andertes
+ rectangle zur"uckgegeben wird.
+
+ Der Klassenbenutzer kann das Verhalten dieser Methode und damit das Verhalten
+ seiner DockinWindow-Klasse beim Docken beeinflussen, indem er die hier
+ aufgerufene virtuelle Methode
+
+ SfxDockingWindow::CalcDockingSize(SfxChildAlignment eAlign)
+
+ "uberschreibt (s.u.).
+*/
+
+{
+ // calculate hypothetical sizes for different modes
+ Size aFloatingSize(CalcDockingSize(SFX_ALIGN_NOALIGNMENT));
+ Size aVerticalSize(CalcDockingSize(SFX_ALIGN_LEFT));
+ Size aHorizontalSize(CalcDockingSize(SFX_ALIGN_TOP));
+
+ // check if docking is permitted
+ SfxWorkWindow *pWorkWin = pBindings->GetWorkWindow_Impl();
+ if ( !pWorkWin->IsDockingAllowed() )
+ {
+ rRect.SetSize( aFloatingSize );
+ return pImp->GetDockAlignment();
+ }
+
+ // calculate borders to shrink inner area before checking for intersection with tracking rectangle
+ long nLRBorder, nTBBorder;
+ if ( pImp->bSplitable )
+ {
+ // take the smaller size of docked and floating mode
+ Size aSize = pImp->aSplitSize;
+ if ( GetFloatingSize().Height() < aSize.Height() )
+ aSize.Height() = GetFloatingSize().Height();
+ if ( GetFloatingSize().Width() < aSize.Width() )
+ aSize.Width() = GetFloatingSize().Width();
+
+ nLRBorder = aSize.Width();
+ nTBBorder = aSize.Height();
+ }
+ else
+ {
+ nLRBorder = aVerticalSize.Width();
+ nTBBorder = aHorizontalSize.Height();
+ }
+
+ // limit border to predefined constant values
+ if ( nLRBorder > MAX_TOGGLEAREA_WIDTH )
+ nLRBorder = MAX_TOGGLEAREA_WIDTH;
+ if ( nTBBorder > MAX_TOGGLEAREA_WIDTH )
+ nTBBorder = MAX_TOGGLEAREA_WIDTH;
+
+ // shrink area for floating mode if possible
+ Rectangle aInRect = GetInnerRect();
+ if ( aInRect.GetWidth() > nLRBorder )
+ aInRect.Left() += nLRBorder/2;
+ if ( aInRect.GetWidth() > nLRBorder )
+ aInRect.Right() -= nLRBorder/2;
+ if ( aInRect.GetHeight() > nTBBorder )
+ aInRect.Top() += nTBBorder/2;
+ if ( aInRect.GetHeight() > nTBBorder )
+ aInRect.Bottom() -= nTBBorder/2;
+
+ // calculate alignment resulting from docking rectangle
+ BOOL bBecomesFloating = FALSE;
+ SfxChildAlignment eDockAlign = pImp->GetDockAlignment();
+ Rectangle aDockingRect( rRect );
+ if ( !IsFloatingMode() )
+ {
+ // don't use tracking rectangle for alignment check, because it will be too large
+ // to get a floating mode as result - switch to floating size
+ // so the calculation only depends on the position of the rectangle, not the current
+ // docking state of the window
+ aDockingRect.SetSize( GetFloatingSize() );
+
+ // in this mode docking is never done by keyboard, so it's OK to use the mouse position
+ aDockingRect.SetPos( pWorkWin->GetWindow()->OutputToScreenPixel( pWorkWin->GetWindow()->GetPointerPosPixel() ) );
+ }
+
+ Point aPos = aDockingRect.TopLeft();
+ Rectangle aIntersect = GetOuterRect().GetIntersection( aDockingRect );
+ if ( aIntersect.IsEmpty() )
+ // docking rectangle completely outside docking area -> floating mode
+ bBecomesFloating = TRUE;
+ else
+ {
+ // create a small test rect around the mouse position and use this one
+ // instead of the passed rRect to not dock too easily or by accident
+ Rectangle aSmallDockingRect;
+ aSmallDockingRect.SetSize( Size( MAX_TOGGLEAREA_WIDTH, MAX_TOGGLEAREA_HEIGHT ) );
+ Point aNewPos(rPos);
+ aNewPos.X() -= aSmallDockingRect.GetWidth()/2;
+ aNewPos.Y() -= aSmallDockingRect.GetHeight()/2;
+ aSmallDockingRect.SetPos(rPos);
+ Rectangle aIntersectRect = aInRect.GetIntersection( aSmallDockingRect );
+ if ( aIntersectRect == aSmallDockingRect )
+ // docking rectangle completely inside (shrinked) inner area -> floating mode
+ bBecomesFloating = TRUE;
+ }
+
+ if ( bBecomesFloating )
+ {
+ eDockAlign = CheckAlignment(pImp->GetDockAlignment(),SFX_ALIGN_NOALIGNMENT);
+ }
+ else
+ {
+ // docking rectangle is in the "sensible area"
+ Point aInPosTL( aPos.X()-aInRect.Left(), aPos.Y()-aInRect.Top() );
+ Point aInPosBR( aPos.X()-aInRect.Left() + aDockingRect.GetWidth(), aPos.Y()-aInRect.Top() + aDockingRect.GetHeight() );
+ Size aInSize = aInRect.GetSize();
+ BOOL bNoChange = FALSE;
+
+ // check if alignment is still unchanged
+ switch ( GetAlignment() )
+ {
+ case SFX_ALIGN_LEFT:
+ case SFX_ALIGN_FIRSTLEFT:
+ case SFX_ALIGN_LASTLEFT:
+ if (aInPosTL.X() <= 0)
+ {
+ eDockAlign = GetAlignment();
+ bNoChange = TRUE;
+ }
+ break;
+ case SFX_ALIGN_TOP:
+ case SFX_ALIGN_LOWESTTOP:
+ case SFX_ALIGN_HIGHESTTOP:
+ if ( aInPosTL.Y() <= 0)
+ {
+ eDockAlign = GetAlignment();
+ bNoChange = TRUE;
+ }
+ break;
+ case SFX_ALIGN_RIGHT:
+ case SFX_ALIGN_FIRSTRIGHT:
+ case SFX_ALIGN_LASTRIGHT:
+ if ( aInPosBR.X() >= aInSize.Width())
+ {
+ eDockAlign = GetAlignment();
+ bNoChange = TRUE;
+ }
+ break;
+ case SFX_ALIGN_BOTTOM:
+ case SFX_ALIGN_LOWESTBOTTOM:
+ case SFX_ALIGN_HIGHESTBOTTOM:
+ if ( aInPosBR.Y() >= aInSize.Height())
+ {
+ eDockAlign = GetAlignment();
+ bNoChange = TRUE;
+ }
+ break;
+ default:
+ break;
+ }
+
+ if ( !bNoChange )
+ {
+ // alignment will change, test alignment according to distance of the docking rectangles edges
+ BOOL bForbidden = TRUE;
+ if ( aInPosTL.X() <= 0)
+ {
+ eDockAlign = CheckAlignment(pImp->GetDockAlignment(),SFX_ALIGN_LEFT);
+ bForbidden = ( eDockAlign != SFX_ALIGN_LEFT &&
+ eDockAlign != SFX_ALIGN_FIRSTLEFT &&
+ eDockAlign != SFX_ALIGN_LASTLEFT );
+ }
+
+ if ( bForbidden && aInPosTL.Y() <= 0)
+ {
+ eDockAlign = CheckAlignment(pImp->GetDockAlignment(),SFX_ALIGN_TOP);
+ bForbidden = ( eDockAlign != SFX_ALIGN_TOP &&
+ eDockAlign != SFX_ALIGN_HIGHESTTOP &&
+ eDockAlign != SFX_ALIGN_LOWESTTOP );
+ }
+
+ if ( bForbidden && aInPosBR.X() >= aInSize.Width())
+ {
+ eDockAlign = CheckAlignment(pImp->GetDockAlignment(),SFX_ALIGN_RIGHT);
+ bForbidden = ( eDockAlign != SFX_ALIGN_RIGHT &&
+ eDockAlign != SFX_ALIGN_FIRSTRIGHT &&
+ eDockAlign != SFX_ALIGN_LASTRIGHT );
+ }
+
+ if ( bForbidden && aInPosBR.Y() >= aInSize.Height())
+ {
+ eDockAlign = CheckAlignment(pImp->GetDockAlignment(),SFX_ALIGN_BOTTOM);
+ bForbidden = ( eDockAlign != SFX_ALIGN_BOTTOM &&
+ eDockAlign != SFX_ALIGN_HIGHESTBOTTOM &&
+ eDockAlign != SFX_ALIGN_LOWESTBOTTOM );
+ }
+
+ // the calculated alignment was rejected by the window -> take floating mode
+ if ( bForbidden )
+ eDockAlign = CheckAlignment(pImp->GetDockAlignment(),SFX_ALIGN_NOALIGNMENT);
+ }
+ }
+
+ if ( eDockAlign == SFX_ALIGN_NOALIGNMENT )
+ {
+ //Im FloatingMode erh"alt das tracking rectangle die floating size
+ // wg. SV-Bug darf rRect nur ver"andert werden, wenn sich das
+ // Alignment "andert !
+ if ( eDockAlign != pImp->GetDockAlignment() )
+ aDockingRect.SetSize( aFloatingSize );
+ }
+ else if ( pImp->bSplitable )
+ {
+ USHORT nLine, nPos;
+ SfxSplitWindow *pSplitWin = pWorkWin->GetSplitWindow_Impl(eDockAlign);
+ aPos = pSplitWin->ScreenToOutputPixel( aPos );
+ if ( pSplitWin->GetWindowPos( aPos, nLine, nPos ) )
+ {
+ // mouse over splitwindow, get line and position
+ pImp->nDockLine = nLine;
+ pImp->nDockPos = nPos;
+ pImp->bNewLine = FALSE;
+ }
+ else
+ {
+ if ( 0 )
+ {
+ // mouse touches outer border -> treated as floating mode
+ eDockAlign = SFX_ALIGN_NOALIGNMENT;
+ aDockingRect.SetSize( aFloatingSize );
+ rRect = aDockingRect;
+ return eDockAlign;
+ }
+
+ // mouse touches inner border -> create new line
+ if ( eDockAlign == GetAlignment() && pImp->pSplitWin &&
+ pImp->nLine == pImp->pSplitWin->GetLineCount()-1 && pImp->pSplitWin->GetWindowCount(pImp->nLine) == 1 )
+ {
+ // if this window is the only one in the last line, it can't be docked as new line in the same splitwindow
+ pImp->nDockLine = pImp->nLine;
+ pImp->nDockPos = pImp->nPos;
+ pImp->bNewLine = FALSE;
+ }
+ else
+ {
+ // create new line
+ pImp->nDockLine = pSplitWin->GetLineCount();
+ pImp->nDockPos = 0;
+ pImp->bNewLine = TRUE;
+ }
+ }
+
+ BOOL bChanged = pImp->nLine != pImp->nDockLine || pImp->nPos != pImp->nDockPos || eDockAlign != GetAlignment();
+ if ( !bChanged && !IsFloatingMode() )
+ {
+ // window only sightly moved, no change of any property
+ rRect.SetSize( pImp->aSplitSize );
+ rRect.SetPos( aDockingRect.TopLeft() );
+ return eDockAlign;
+ }
+
+ // calculate new size and position
+ Size aSize;
+ Point aPoint = aDockingRect.TopLeft();
+ Size aInnerSize = GetInnerRect().GetSize();
+ if ( eDockAlign == SFX_ALIGN_LEFT || eDockAlign == SFX_ALIGN_RIGHT )
+ {
+ if ( pImp->bNewLine )
+ {
+ // set height to height of free area
+ aSize.Height() = aInnerSize.Height();
+ aSize.Width() = pImp->nHorizontalSize;
+ if ( eDockAlign == SFX_ALIGN_LEFT )
+ {
+ aPoint = aInnerRect.TopLeft();
+ }
+ else
+ {
+ aPoint = aInnerRect.TopRight();
+ aPoint.X() -= aSize.Width();
+ }
+ }
+ else
+ {
+ // get width from splitwindow
+ aSize.Width() = pSplitWin->GetLineSize(nLine);
+ aSize.Height() = pImp->aSplitSize.Height();
+ }
+ }
+ else
+ {
+ if ( pImp->bNewLine )
+ {
+ // set width to width of free area
+ aSize.Width() = aInnerSize.Width();
+ aSize.Height() = pImp->nVerticalSize;
+ if ( eDockAlign == SFX_ALIGN_TOP )
+ {
+ aPoint = aInnerRect.TopLeft();
+ }
+ else
+ {
+ aPoint = aInnerRect.BottomLeft();
+ aPoint.Y() -= aSize.Height();
+ }
+ }
+ else
+ {
+ // get height from splitwindow
+ aSize.Height() = pSplitWin->GetLineSize(nLine);
+ aSize.Width() = pImp->aSplitSize.Width();
+ }
+ }
+
+ aDockingRect.SetSize( aSize );
+ aDockingRect.SetPos( aPoint );
+ }
+ else
+ {
+ // window can be docked, but outside our splitwindows
+ // tracking rectangle only needs to be modified if alignment was changed
+ if ( eDockAlign != pImp->GetDockAlignment() )
+ {
+ switch ( eDockAlign )
+ {
+ case SFX_ALIGN_LEFT:
+ case SFX_ALIGN_RIGHT:
+ case SFX_ALIGN_FIRSTLEFT:
+ aDockingRect.SetPos( aInnerRect.TopLeft() );
+ aDockingRect.SetSize( aVerticalSize );
+ break;
+ case SFX_ALIGN_LASTLEFT:
+ case SFX_ALIGN_FIRSTRIGHT:
+ case SFX_ALIGN_LASTRIGHT:
+ {
+ Point aPt( aInnerRect.TopRight() );
+ aPt.X() -= aDockingRect.GetWidth();
+ aDockingRect.SetPos( aPt );
+ aDockingRect.SetSize( aVerticalSize );
+ break;
+ }
+
+ case SFX_ALIGN_TOP:
+ case SFX_ALIGN_BOTTOM:
+ case SFX_ALIGN_LOWESTTOP:
+ aDockingRect.SetPos( aInnerRect.TopLeft() );
+ aDockingRect.SetSize( aHorizontalSize );
+ break;
+ case SFX_ALIGN_HIGHESTTOP:
+ case SFX_ALIGN_LOWESTBOTTOM:
+ case SFX_ALIGN_HIGHESTBOTTOM:
+ {
+ Point aPt( aInnerRect.BottomLeft() );
+ aPt.Y() -= aDockingRect.GetHeight();
+ aDockingRect.SetPos( aPt );
+ aDockingRect.SetSize( aHorizontalSize );
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ }
+
+ rRect = aDockingRect;
+ return eDockAlign;
+}
+
+//-------------------------------------------------------------------------
+
+Size SfxDockingWindow::CalcDockingSize(SfxChildAlignment eAlign)
+
+/* [Beschreibung]
+
+ Virtuelle Methode der Klasse SfxDockingWindow.
+ Hier wird festgelegt, wie sich die Gr"o\se des DockingWindows abh"angig vom
+ Alignment "andert.
+ Die Basisimplementation setzt im Floating Mode die Gr"o\se auf die gemerkte
+ Floating Size.
+ Bei horizontalem Alignment wird die Breite auf die Breite des "au\seren
+ DockingRects, bei vertikalem Alignment die H"ohe auf die H"ohe des inneren
+ DockingRects (ergibt sich aus der Reihenfolge, in der im SFX ChildWindows
+ ausgegeben werden). Die jeweils andere Gr"o\se wird auf die aktuelle
+ Floating Size gesetzt, hier k"onnte eine abgeleitete Klasse "andernd
+ eingreifen.
+ Die DockingSize mu\s f"ur Left/Right und Top/Bottom jeweils gleich sein.
+*/
+
+{
+ // Achtung: falls das Resizing auch im angedockten Zustand geht, mu\s dabei
+ // auch die Floating Size angepa\st werden !?
+
+ Size aSize = GetFloatingSize();
+ switch (eAlign)
+ {
+ case SFX_ALIGN_TOP:
+ case SFX_ALIGN_BOTTOM:
+ case SFX_ALIGN_LOWESTTOP:
+ case SFX_ALIGN_HIGHESTTOP:
+ case SFX_ALIGN_LOWESTBOTTOM:
+ case SFX_ALIGN_HIGHESTBOTTOM:
+ aSize.Width() = aOuterRect.Right() - aOuterRect.Left();
+ break;
+ case SFX_ALIGN_LEFT:
+ case SFX_ALIGN_RIGHT:
+ case SFX_ALIGN_FIRSTLEFT:
+ case SFX_ALIGN_LASTLEFT:
+ case SFX_ALIGN_FIRSTRIGHT:
+ case SFX_ALIGN_LASTRIGHT:
+ aSize.Height() = aInnerRect.Bottom() - aInnerRect.Top();
+ break;
+ case SFX_ALIGN_NOALIGNMENT:
+ break;
+ default:
+ break;
+ }
+
+ return aSize;
+}
+
+//-------------------------------------------------------------------------
+
+SfxChildAlignment SfxDockingWindow::CheckAlignment(SfxChildAlignment,
+ SfxChildAlignment eAlign)
+
+/* [Beschreibung]
+
+ Virtuelle Methode der Klasse SfxDockingWindow.
+ Hier kann eine abgeleitete Klasse bestimmte Alignments verbieten.
+ Die Basisimplementation verbietet kein Alignment.
+*/
+
+{
+ return eAlign;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxDockingWindow::Close()
+
+/* [Beschreibung]
+
+ Das Fenster wird geschlossen, indem das ChildWindow durch Ausf"uhren des
+ ChildWindow-Slots zerst"ort wird.
+ Wird diese Methode von einer abgeleiteten Klasse "uberschrieben, mu\s
+ danach SfxDockingWindow::Close() gerufen werden, wenn nicht das Close()
+ mit "return FALSE" abgebrochen wird.
+
+*/
+{
+ // Execute mit Parametern, da Toggle von einigen ChildWindows ignoriert
+ // werden kann
+ if ( !pMgr )
+ return TRUE;
+
+ SfxBoolItem aValue( pMgr->GetType(), FALSE);
+ pBindings->GetDispatcher_Impl()->Execute(
+ pMgr->GetType(), SFX_CALLMODE_RECORD | SFX_CALLMODE_ASYNCHRON, &aValue, 0L );
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDockingWindow::Paint(const Rectangle& /*rRect*/)
+
+/* [Beschreibung]
+
+ Es wird im angedockten Zustand eine Begrenzungslinie an der angedockten
+ Kante und ein Rahmen ausgegeben. Dabei wird SVLOOK ber"ucksichtigt.
+*/
+
+{
+ if ( pImp->bSplitable || IsFloatingMode() )
+ return;
+
+ Rectangle aRect = Rectangle(Point(0, 0),
+ GetOutputSizePixel());
+ switch (GetAlignment())
+ {
+ case SFX_ALIGN_TOP:
+ {
+ DrawLine(aRect.BottomLeft(), aRect.BottomRight());
+ aRect.Bottom()--;
+ break;
+ }
+
+ case SFX_ALIGN_BOTTOM:
+ {
+ DrawLine(aRect.TopLeft(), aRect.TopRight());
+ aRect.Top()++;
+ break;
+ }
+
+ case SFX_ALIGN_LEFT:
+ {
+ DrawLine(aRect.TopRight(), aRect.BottomRight());
+ aRect.Right()--;
+ break;
+ }
+
+ case SFX_ALIGN_RIGHT:
+ {
+ DrawLine(aRect.TopLeft(), aRect.BottomLeft());
+ aRect.Left()++;
+ break;
+ }
+ default:
+ break;
+ }
+
+ DecorationView aView( this );
+ aView.DrawFrame( aRect, FRAME_DRAW_OUT );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDockingWindow::SetMinOutputSizePixel( const Size& rSize )
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann eine minimale OutpuSize gesetzt werden, die
+ im Resizing()-Handler abgefragt wird.
+*/
+
+{
+ pImp->aMinSize = rSize;
+ DockingWindow::SetMinOutputSizePixel( rSize );
+}
+
+//-------------------------------------------------------------------------
+
+Size SfxDockingWindow::GetMinOutputSizePixel() const
+
+/* [Beschreibung]
+
+ Die gesetzte minimale Gr"o\se wird zur"uckgegeben.
+*/
+
+{
+ return pImp->aMinSize;
+}
+
+//-------------------------------------------------------------------------
+
+long SfxDockingWindow::Notify( NotifyEvent& rEvt )
+{
+ if ( rEvt.GetType() == EVENT_GETFOCUS )
+ {
+ pBindings->SetActiveFrame( pMgr->GetFrame() );
+
+ if ( pImp->pSplitWin )
+ pImp->pSplitWin->SetActiveWindow_Impl( this );
+ else
+ pMgr->Activate_Impl();
+
+ Window* pWindow = rEvt.GetWindow();
+ rtl::OString sHelpId;
+ while ( !sHelpId.getLength() && pWindow )
+ {
+ sHelpId = pWindow->GetHelpId();
+ pWindow = pWindow->GetParent();
+ }
+
+ if ( sHelpId.getLength() )
+ SfxHelp::OpenHelpAgent( &pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame(), sHelpId );
+
+ // In VCL geht Notify zun"achst an das Fenster selbst,
+ // also base class rufen, sonst erf"ahrt der parent nichts
+ // if ( rEvt.GetWindow() == this ) PB: #i74693# not necessary any longer
+ DockingWindow::Notify( rEvt );
+ return TRUE;
+ }
+ else if( rEvt.GetType() == EVENT_KEYINPUT )
+ {
+ // KeyInput zuerst f"ur Dialogfunktionen zulassen
+ if ( !DockingWindow::Notify( rEvt ) && SfxViewShell::Current() )
+ // dann auch global g"ultige Acceleratoren verwenden
+ return SfxViewShell::Current()->GlobalKeyInput_Impl( *rEvt.GetKeyEvent() );
+ return TRUE;
+ }
+ else if ( rEvt.GetType() == EVENT_LOSEFOCUS && !HasChildPathFocus() )
+ {
+ pBindings->SetActiveFrame( NULL );
+ pMgr->Deactivate_Impl();
+ }
+
+ return DockingWindow::Notify( rEvt );
+}
+
+
+USHORT SfxDockingWindow::GetWinBits_Impl() const
+{
+ USHORT nBits = 0;
+// if ( pImp->bAutoHide )
+// nBits |= SWIB_AUTOHIDE;
+ return nBits;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDockingWindow::SetItemSize_Impl( const Size& rSize )
+{
+ pImp->aSplitSize = rSize;
+
+ SfxWorkWindow *pWorkWin = pBindings->GetWorkWindow_Impl();
+ SfxChildIdentifier eIdent = SFX_CHILDWIN_DOCKINGWINDOW;
+ if ( pImp->bSplitable )
+ eIdent = SFX_CHILDWIN_SPLITWINDOW;
+ pWorkWin->ConfigChild_Impl( eIdent, SFX_ALIGNDOCKINGWINDOW, pMgr->GetType() );
+}
+
+void SfxDockingWindow::Disappear_Impl()
+{
+ if ( pImp->pSplitWin && pImp->pSplitWin->IsItemValid( GetType() ) )
+ pImp->pSplitWin->RemoveWindow(this);
+}
+
+void SfxDockingWindow::Reappear_Impl()
+{
+ if ( pImp->pSplitWin && !pImp->pSplitWin->IsItemValid( GetType() ) )
+ {
+ pImp->pSplitWin->InsertWindow( this, pImp->aSplitSize );
+ }
+}
+
+BOOL SfxDockingWindow::IsAutoHide_Impl() const
+{
+ if ( pImp->pSplitWin )
+ return !pImp->pSplitWin->IsFadeIn();
+ else
+ return FALSE;
+}
+
+BOOL SfxDockingWindow::IsPinned_Impl() const
+{
+ if ( pImp->pSplitWin )
+ return pImp->pSplitWin->IsPinned();
+ else
+ return TRUE;
+}
+void SfxDockingWindow::AutoShow( BOOL bShow )
+{
+ AutoShow_Impl(bShow);
+}
+
+void SfxDockingWindow::AutoShow_Impl( BOOL bShow )
+{
+ if ( pImp->pSplitWin )
+ {
+ if ( bShow )
+ pImp->pSplitWin->FadeIn();
+ else
+ pImp->pSplitWin->FadeOut();
+ }
+}
+
+/*
+void SfxDockingWindow::Pin_Impl( BOOL bPinned )
+{
+ if ( pImp->pSplitWin )
+ pImp->pSplitWin->Pin_Impl( bPinned );
+}
+*/
+
+SfxSplitWindow* SfxDockingWindow::GetSplitWindow_Impl() const
+{
+ return pImp->pSplitWin;
+}
+
+void SfxDockingWindow::FadeIn( BOOL /*bFadeIn*/ )
+{
+}
+
+void SfxDockingWindow::StateChanged( StateChangedType nStateChange )
+{
+ if ( nStateChange == STATE_CHANGE_INITSHOW )
+ Initialize_Impl();
+
+ DockingWindow::StateChanged( nStateChange );
+}
+
+void SfxDockingWindow::Move()
+{
+ if ( pImp )
+ pImp->aMoveTimer.Start();
+}
+
+IMPL_LINK( SfxDockingWindow, TimerHdl, Timer*, EMPTYARG)
+{
+ pImp->aMoveTimer.Stop();
+ if ( IsReallyVisible() && IsFloatingMode() )
+ {
+ if( !GetFloatingWindow()->IsRollUp() )
+ SetFloatingSize( GetOutputSizePixel() );
+ pImp->aWinState = GetFloatingWindow()->GetWindowState();
+ SfxChildIdentifier eIdent = SFX_CHILDWIN_DOCKINGWINDOW;
+ if ( pImp->bSplitable )
+ eIdent = SFX_CHILDWIN_SPLITWINDOW;
+ SfxWorkWindow *pWorkWin = pBindings->GetWorkWindow_Impl();
+ pWorkWin->ConfigChild_Impl( eIdent, SFX_ALIGNDOCKINGWINDOW, pMgr->GetType() );
+ }
+ return 0;
+}
+
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
new file mode 100644
index 000000000000..b740453cf5ff
--- /dev/null
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -0,0 +1,2921 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <sfx2/filedlghelper.hxx>
+#include <sal/types.h>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
+#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
+#include <com/sun/star/ui/dialogs/ControlActions.hpp>
+#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+#include <com/sun/star/ui/dialogs/XControlInformation.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
+#include <com/sun/star/ui/dialogs/XFilePreview.hpp>
+#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
+#include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
+#include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
+#include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
+#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/container/XEnumeration.hpp>
+#include <com/sun/star/container/XContainerQuery.hpp>
+#include <com/sun/star/task/XInteractionRequest.hpp>
+#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
+
+#include <comphelper/processfactory.hxx>
+#include <comphelper/types.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/stillreadwriteinteraction.hxx>
+#include <tools/urlobj.hxx>
+#include <vcl/help.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/ucbhelper.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <vos/thread.hxx>
+#include <vos/mutex.hxx>
+#include <vos/security.hxx>
+#include <vcl/cvtgrf.hxx>
+#include <vcl/msgbox.hxx>
+#include <vcl/mnemonic.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/securityoptions.hxx>
+#include <svl/itemset.hxx>
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/stritem.hxx>
+#include <svtools/filter.hxx>
+#include <unotools/viewoptions.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <svtools/helpid.hrc>
+#include <comphelper/docpasswordrequest.hxx>
+#include <comphelper/docpasswordhelper.hxx>
+#include <ucbhelper/content.hxx>
+#include <ucbhelper/commandenvironment.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/frame.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfac.hxx>
+#include "openflag.hxx"
+#include <sfx2/passwd.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/sfxsids.hrc>
+#include "filedlghelper.hrc"
+#include "filtergrouping.hxx"
+#include <sfx2/request.hxx>
+#include "filedlgimpl.hxx"
+#include <helpid.hrc>
+#include <sfxlocal.hrc>
+
+//-----------------------------------------------------------------------------
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::ui::dialogs;
+using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::rtl;
+using namespace ::cppu;
+
+//-----------------------------------------------------------------------------
+
+#define IODLG_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Save"))
+#define IMPGRF_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Graph"))
+#define USERITEM_NAME ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "UserItem" ))
+
+//-----------------------------------------------------------------------------
+
+namespace sfx2
+{
+
+const OUString* GetLastFilterConfigId( FileDialogHelper::Context _eContext )
+{
+ static const OUString aSD_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SdExportLastFilter" ) );
+ static const OUString aSI_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SiExportLastFilter" ) );
+ static const OUString aSW_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SwExportLastFilter" ) );
+
+ const OUString* pRet = NULL;
+
+ switch( _eContext )
+ {
+ case FileDialogHelper::SD_EXPORT: pRet = &aSD_EXPORT_IDENTIFIER; break;
+ case FileDialogHelper::SI_EXPORT: pRet = &aSI_EXPORT_IDENTIFIER; break;
+ case FileDialogHelper::SW_EXPORT: pRet = &aSW_EXPORT_IDENTIFIER; break;
+ default: break;
+ }
+
+ return pRet;
+}
+
+String EncodeSpaces_Impl( const String& rSource );
+String DecodeSpaces_Impl( const String& rSource );
+
+// ------------------------------------------------------------------------
+// ----------- FileDialogHelper_Impl ---------------------------
+// ------------------------------------------------------------------------
+
+// ------------------------------------------------------------------------
+// XFilePickerListener Methods
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper_Impl::fileSelectionChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ mpAntiImpl->FileSelectionChanged( aEvent );
+}
+
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper_Impl::directoryChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ mpAntiImpl->DirectoryChanged( aEvent );
+}
+
+// ------------------------------------------------------------------------
+OUString SAL_CALL FileDialogHelper_Impl::helpRequested( const FilePickerEvent& aEvent ) throw ( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ return mpAntiImpl->HelpRequested( aEvent );
+}
+
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper_Impl::controlStateChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ mpAntiImpl->ControlStateChanged( aEvent );
+}
+
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper_Impl::dialogSizeChanged() throw ( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ mpAntiImpl->DialogSizeChanged();
+}
+
+// ------------------------------------------------------------------------
+// XDialogClosedListener Methods
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper_Impl::dialogClosed( const DialogClosedEvent& _rEvent ) throw ( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ mpAntiImpl->DialogClosed( _rEvent );
+ postExecute( _rEvent.DialogResult );
+}
+
+// ------------------------------------------------------------------------
+// handle XFilePickerListener events
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::handleFileSelectionChanged( const FilePickerEvent& )
+{
+ if ( mbHasVersions )
+ updateVersions();
+
+ if ( mbShowPreview )
+ maPreViewTimer.Start();
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::handleDirectoryChanged( const FilePickerEvent& )
+{
+ if ( mbShowPreview )
+ TimeOutHdl_Impl( NULL );
+}
+
+// ------------------------------------------------------------------------
+OUString FileDialogHelper_Impl::handleHelpRequested( const FilePickerEvent& aEvent )
+{
+ //!!! todo: cache the help strings (here or TRA)
+
+ rtl::OString sHelpId;
+ // mapping from element id -> help id
+ switch ( aEvent.ElementId )
+ {
+ case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION :
+ sHelpId = HID_FILESAVE_AUTOEXTENSION;
+ break;
+
+ case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD :
+ sHelpId = HID_FILESAVE_SAVEWITHPASSWORD;
+ break;
+
+ case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS :
+ sHelpId = HID_FILESAVE_CUSTOMIZEFILTER;
+ break;
+
+ case ExtendedFilePickerElementIds::CHECKBOX_READONLY :
+ sHelpId = HID_FILEOPEN_READONLY;
+ break;
+
+ case ExtendedFilePickerElementIds::CHECKBOX_LINK :
+ sHelpId = HID_FILEDLG_LINK_CB;
+ break;
+
+ case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW :
+ sHelpId = HID_FILEDLG_PREVIEW_CB;
+ break;
+
+ case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY :
+ sHelpId = HID_FILESAVE_DOPLAY;
+ break;
+
+ case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL :
+ case ExtendedFilePickerElementIds::LISTBOX_VERSION :
+ sHelpId = HID_FILEOPEN_VERSION;
+ break;
+
+ case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL :
+ case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE :
+ sHelpId = HID_FILESAVE_TEMPLATE;
+ break;
+
+ case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL :
+ case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE :
+ sHelpId = HID_FILEOPEN_IMAGE_TEMPLATE;
+ break;
+
+ case ExtendedFilePickerElementIds::CHECKBOX_SELECTION :
+ sHelpId = HID_FILESAVE_SELECTION;
+ break;
+
+ default:
+ DBG_ERRORFILE( "invalid element id" );
+ }
+
+ OUString aHelpText;
+ Help* pHelp = Application::GetHelp();
+ if ( pHelp )
+ aHelpText = String( pHelp->GetHelpText( String( ByteString(sHelpId), RTL_TEXTENCODING_UTF8), NULL ) );
+ return aHelpText;
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::handleControlStateChanged( const FilePickerEvent& aEvent )
+{
+ switch ( aEvent.ElementId )
+ {
+ case CommonFilePickerElementIds::LISTBOX_FILTER:
+ updateFilterOptionsBox();
+ enablePasswordBox( sal_False );
+ updateSelectionBox();
+ // only use it for export and with our own dialog
+ if ( mbExport && !mbSystemPicker )
+ updateExportButton();
+ break;
+
+ case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
+ updatePreviewState();
+ break;
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::handleDialogSizeChanged()
+{
+ if ( mbShowPreview )
+ TimeOutHdl_Impl( NULL );
+}
+
+// ------------------------------------------------------------------------
+// XEventListener Methods
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper_Impl::disposing( const EventObject& ) throw ( RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ dispose();
+}
+
+// ------------------------------------------------------------------------
+// ------------------------------------------------------------------------
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::dispose()
+{
+ if ( mxFileDlg.is() )
+ {
+ // remove the event listener
+ uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
+ if ( xNotifier.is() )
+ xNotifier->removeFilePickerListener( this );
+
+ ::comphelper::disposeComponent( mxFileDlg );
+ mxFileDlg.clear();
+ }
+}
+
+// ------------------------------------------------------------------------
+String FileDialogHelper_Impl::getCurrentFilterUIName() const
+{
+ String aFilterName;
+ uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
+
+ if( xFltMgr.is() )
+ {
+ aFilterName = xFltMgr->getCurrentFilter();
+
+ if ( aFilterName.Len() && isShowFilterExtensionEnabled() )
+ aFilterName = getFilterName( aFilterName );
+ }
+
+ return aFilterName;
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::LoadLastUsedFilter( const OUString& _rContextIdentifier )
+{
+ SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
+
+ if( aDlgOpt.Exists() )
+ {
+ OUString aLastFilter;
+ if( aDlgOpt.GetUserItem( _rContextIdentifier ) >>= aLastFilter )
+ setFilter( aLastFilter );
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::SaveLastUsedFilter( const OUString& _rContextIdentifier )
+{
+ SvtViewOptions( E_DIALOG, IODLG_CONFIGNAME ).SetUserItem( _rContextIdentifier,
+ makeAny( getFilterWithExtension( getFilter() ) ) );
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::SaveLastUsedFilter( void )
+{
+ const OUString* pConfigId = GetLastFilterConfigId( meContext );
+ if( pConfigId )
+ SaveLastUsedFilter( *pConfigId );
+}
+
+// ------------------------------------------------------------------------
+const SfxFilter* FileDialogHelper_Impl::getCurentSfxFilter()
+{
+ String aFilterName = getCurrentFilterUIName();
+
+ const SfxFilter* pFilter = NULL;
+ if ( mpMatcher && aFilterName.Len() )
+ pFilter = mpMatcher->GetFilter4UIName( aFilterName, m_nMustFlags, m_nDontFlags );
+
+ return pFilter;
+}
+
+// ------------------------------------------------------------------------
+sal_Bool FileDialogHelper_Impl::updateExtendedControl( sal_Int16 _nExtendedControlId, sal_Bool _bEnable )
+{
+ sal_Bool bIsEnabled = sal_False;
+
+ uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
+ if ( xCtrlAccess.is() )
+ {
+ try
+ {
+ xCtrlAccess->enableControl( _nExtendedControlId, _bEnable );
+ bIsEnabled = _bEnable;
+ }
+ catch( const IllegalArgumentException& )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::updateExtendedControl: caught an exception!" );
+ }
+ }
+ return bIsEnabled;
+}
+
+// ------------------------------------------------------------------------
+sal_Bool FileDialogHelper_Impl::CheckFilterOptionsCapability( const SfxFilter* _pFilter )
+{
+ sal_Bool bResult = sal_False;
+
+ if( mxFilterCFG.is() && _pFilter )
+ {
+ try {
+ Sequence < PropertyValue > aProps;
+ Any aAny = mxFilterCFG->getByName( _pFilter->GetName() );
+ if ( aAny >>= aProps )
+ {
+ ::rtl::OUString aServiceName;
+ sal_Int32 nPropertyCount = aProps.getLength();
+ for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
+ {
+ if( aProps[nProperty].Name.equals( DEFINE_CONST_OUSTRING( "UIComponent") ) )
+ {
+ aProps[nProperty].Value >>= aServiceName;
+ if( aServiceName.getLength() )
+ bResult = sal_True;
+ }
+ }
+ }
+ }
+ catch( Exception& )
+ {
+ }
+ }
+
+ return bResult;
+}
+
+// ------------------------------------------------------------------------
+sal_Bool FileDialogHelper_Impl::isInOpenMode() const
+{
+ sal_Bool bRet = sal_False;
+
+ switch ( m_nDialogType )
+ {
+ case FILEOPEN_SIMPLE:
+ case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
+ case FILEOPEN_PLAY:
+ case FILEOPEN_READONLY_VERSION:
+ case FILEOPEN_LINK_PREVIEW:
+ bRet = sal_True;
+ }
+
+ return bRet;
+}
+
+// ------------------------------------------------------------------------
+
+void FileDialogHelper_Impl::updateFilterOptionsBox()
+{
+ if ( !m_bHaveFilterOptions )
+ return;
+
+ updateExtendedControl(
+ ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS,
+ CheckFilterOptionsCapability( getCurentSfxFilter() )
+ );
+}
+
+// ------------------------------------------------------------------------
+
+void FileDialogHelper_Impl::updateExportButton()
+{
+ uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
+ if ( xCtrlAccess.is() )
+ {
+ OUString sEllipses( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
+ OUString sOldLabel( xCtrlAccess->getLabel( CommonFilePickerElementIds::PUSHBUTTON_OK ) );
+
+ // initialize button label; we need the label with the mnemonic char
+ if ( !maButtonLabel.getLength() || maButtonLabel.indexOf( MNEMONIC_CHAR ) == -1 )
+ {
+ // cut the ellipses, if necessary
+ sal_Int32 nIndex = sOldLabel.indexOf( sEllipses );
+ if ( -1 == nIndex )
+ nIndex = sOldLabel.getLength();
+ maButtonLabel = sOldLabel.copy( 0, nIndex );
+ }
+
+ OUString sLabel = maButtonLabel;
+ // filter with options -> append ellipses on export button label
+ if ( CheckFilterOptionsCapability( getCurentSfxFilter() ) )
+ sLabel += OUString( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
+
+ if ( sOldLabel != sLabel )
+ {
+ try
+ {
+ xCtrlAccess->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK, sLabel );
+ }
+ catch( const IllegalArgumentException& )
+ {
+ DBG_ERRORFILE( "FileDialogHelper_Impl::updateExportButton: caught an exception!" );
+ }
+ }
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::updateSelectionBox()
+{
+ if ( !mbHasSelectionBox )
+ return;
+
+ // Does the selection box exist?
+ sal_Bool bSelectionBoxFound = sal_False;
+ uno::Reference< XControlInformation > xCtrlInfo( mxFileDlg, UNO_QUERY );
+ if ( xCtrlInfo.is() )
+ {
+ Sequence< ::rtl::OUString > aCtrlList = xCtrlInfo->getSupportedControls();
+ sal_uInt32 nCount = aCtrlList.getLength();
+ for ( sal_uInt32 nCtrl = 0; nCtrl < nCount; ++nCtrl )
+ if ( aCtrlList[ nCtrl ].equalsAscii("SelectionBox") )
+ {
+ bSelectionBoxFound = sal_False;
+ break;
+ }
+ }
+
+ if ( bSelectionBoxFound )
+ {
+ const SfxFilter* pFilter = getCurentSfxFilter();
+ mbSelectionFltrEnabled = updateExtendedControl(
+ ExtendedFilePickerElementIds::CHECKBOX_SELECTION,
+ ( mbSelectionEnabled && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_SUPPORTSSELECTION ) != 0 ) );
+ uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
+ xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, makeAny( (sal_Bool)mbSelection ) );
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::enablePasswordBox( sal_Bool bInit )
+{
+ if ( ! mbHasPassword )
+ return;
+
+ sal_Bool bWasEnabled = mbIsPwdEnabled;
+
+ const SfxFilter* pCurrentFilter = getCurentSfxFilter();
+ mbIsPwdEnabled = updateExtendedControl(
+ ExtendedFilePickerElementIds::CHECKBOX_PASSWORD,
+ pCurrentFilter && ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_ENCRYPTION )
+ );
+
+ if( bInit )
+ {
+ // in case of inintialization previous state is not interesting
+ if( mbIsPwdEnabled )
+ {
+ uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
+ if( mbPwdCheckBoxState )
+ xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
+ }
+ }
+ else if( !bWasEnabled && mbIsPwdEnabled )
+ {
+ uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
+ if( mbPwdCheckBoxState )
+ xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
+ }
+ else if( bWasEnabled && !mbIsPwdEnabled )
+ {
+ // remember user settings until checkbox is enabled
+ uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
+ Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
+ sal_Bool bPassWord = sal_False;
+ mbPwdCheckBoxState = ( aValue >>= bPassWord ) && bPassWord;
+ xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_False ) );
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::updatePreviewState( sal_Bool _bUpdatePreviewWindow )
+{
+ if ( mbHasPreview )
+ {
+ uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
+
+ // check, wether or not we have to display a preview
+ if ( xCtrlAccess.is() )
+ {
+ try
+ {
+ Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
+ sal_Bool bShowPreview = sal_False;
+
+ if ( aValue >>= bShowPreview )
+ {
+ mbShowPreview = bShowPreview;
+
+ // #97633
+ // setShowState has currently no effect for the
+ // OpenOffice FilePicker (see svtools/source/filepicker/iodlg.cxx)
+ uno::Reference< XFilePreview > xFilePreview( mxFileDlg, UNO_QUERY );
+ if ( xFilePreview.is() )
+ xFilePreview->setShowState( mbShowPreview );
+
+ if ( _bUpdatePreviewWindow )
+ TimeOutHdl_Impl( NULL );
+ }
+ }
+ catch( Exception )
+ {
+ DBG_ERRORFILE( "FileDialogHelper_Impl::updatePreviewState: caught an exception!" );
+ }
+ }
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::updateVersions()
+{
+ Sequence < OUString > aEntries;
+ Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
+
+ if ( aPathSeq.getLength() == 1 )
+ {
+ INetURLObject aObj( aPathSeq[0] );
+
+ if ( ( aObj.GetProtocol() == INET_PROT_FILE ) &&
+ ( utl::UCBContentHelper::IsDocument( aObj.GetMainURL( INetURLObject::NO_DECODE ) ) ) )
+ {
+ try
+ {
+ uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
+ aObj.GetMainURL( INetURLObject::NO_DECODE ),
+ embed::ElementModes::READ );
+
+ DBG_ASSERT( xStorage.is(), "The method must return the storage or throw an exception!" );
+ if ( !xStorage.is() )
+ throw uno::RuntimeException();
+
+ uno::Sequence < util::RevisionTag > xVersions = SfxMedium::GetVersionList( xStorage );
+
+ aEntries.realloc( xVersions.getLength() + 1 );
+ aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) );
+
+ for ( sal_Int32 i=0; i<xVersions.getLength(); i++ )
+ aEntries[ i + 1 ] = xVersions[i].Identifier;
+
+ // TODO/LATER: not sure that this information must be shown in future ( binfilter? )
+//REMOVE else
+//REMOVE {
+//REMOVE SfxFilterFlags nMust = SFX_FILTER_IMPORT | SFX_FILTER_OWN;
+//REMOVE SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED | SFX_FILTER_STARONEFILTER;
+//REMOVE if ( SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( pStor->GetFormat(), nMust, nDont ) )
+//REMOVE {
+//REMOVE aEntries.realloc( 1 );
+//REMOVE aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) );
+//REMOVE }
+//REMOVE }
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ }
+
+ uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
+ Any aValue;
+
+ try
+ {
+ xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
+ ControlActions::DELETE_ITEMS, aValue );
+ }
+ catch( IllegalArgumentException ){}
+
+ sal_Int32 nCount = aEntries.getLength();
+
+ if ( nCount )
+ {
+ try
+ {
+ aValue <<= aEntries;
+ xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
+ ControlActions::ADD_ITEMS, aValue );
+
+ Any aPos;
+ aPos <<= (sal_Int32) 0;
+ xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
+ ControlActions::SET_SELECT_ITEM, aPos );
+ }
+ catch( IllegalArgumentException ){}
+ }
+}
+
+// -----------------------------------------------------------------------
+class OReleaseSolarMutex
+{
+private:
+ const sal_Int32 m_nAquireCount;
+public:
+ OReleaseSolarMutex( )
+ :m_nAquireCount( Application::ReleaseSolarMutex() )
+ {
+ }
+ ~OReleaseSolarMutex( )
+ {
+ Application::AcquireSolarMutex( m_nAquireCount );
+ }
+};
+
+// -----------------------------------------------------------------------
+IMPL_LINK( FileDialogHelper_Impl, TimeOutHdl_Impl, Timer*, EMPTYARG )
+{
+ if ( !mbHasPreview )
+ return 0;
+
+ maGraphic.Clear();
+
+ Any aAny;
+ uno::Reference < XFilePreview > xFilePicker( mxFileDlg, UNO_QUERY );
+
+ if ( ! xFilePicker.is() )
+ return 0;
+
+ Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
+
+ if ( mbShowPreview && ( aPathSeq.getLength() == 1 ) )
+ {
+ OUString aURL = aPathSeq[0];
+
+ if ( ERRCODE_NONE == getGraphic( aURL, maGraphic ) )
+ {
+ // #89491
+ // changed the code slightly;
+ // before: the bitmap was scaled and
+ // surrounded a white frame
+ // now: the bitmap will only be scaled
+ // and the filepicker implementation
+ // is responsible for placing it at its
+ // proper position and painting a frame
+
+ Bitmap aBmp = maGraphic.GetBitmap();
+
+ // scale the bitmap to the correct size
+ sal_Int32 nOutWidth = xFilePicker->getAvailableWidth();
+ sal_Int32 nOutHeight = xFilePicker->getAvailableHeight();
+ sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
+ sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
+
+ double nXRatio = (double) nOutWidth / nBmpWidth;
+ double nYRatio = (double) nOutHeight / nBmpHeight;
+
+ if ( nXRatio < nYRatio )
+ aBmp.Scale( nXRatio, nXRatio );
+ else
+ aBmp.Scale( nYRatio, nYRatio );
+
+ // #94505# Convert to true color, to allow CopyPixel
+ aBmp.Convert( BMP_CONVERSION_24BIT );
+
+ // and copy it into the Any
+ SvMemoryStream aData;
+
+ aData << aBmp;
+
+ const Sequence < sal_Int8 > aBuffer(
+ static_cast< const sal_Int8* >(aData.GetData()),
+ aData.GetEndOfData() );
+
+ aAny <<= aBuffer;
+ }
+ }
+
+ try
+ {
+ OReleaseSolarMutex aReleaseForCallback;
+ // clear the preview window
+ xFilePicker->setImage( FilePreviewImageFormats::BITMAP, aAny );
+ }
+ catch( IllegalArgumentException )
+ {
+ }
+
+ return 0;
+}
+
+// ------------------------------------------------------------------------
+ErrCode FileDialogHelper_Impl::getGraphic( const OUString& rURL,
+ Graphic& rGraphic ) const
+{
+ if ( utl::UCBContentHelper::IsFolder( rURL ) )
+ return ERRCODE_IO_NOTAFILE;
+
+ if ( !mpGraphicFilter )
+ return ERRCODE_IO_NOTSUPPORTED;
+
+ // select graphic filter from dialog filter selection
+ OUString aCurFilter( getFilter() );
+
+ sal_uInt16 nFilter = aCurFilter.getLength() && mpGraphicFilter->GetImportFormatCount()
+ ? mpGraphicFilter->GetImportFormatNumber( aCurFilter )
+ : GRFILTER_FORMAT_DONTKNOW;
+
+ INetURLObject aURLObj( rURL );
+
+ if ( aURLObj.HasError() || INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
+ {
+ aURLObj.SetSmartProtocol( INET_PROT_FILE );
+ aURLObj.SetSmartURL( rURL );
+ }
+
+ ErrCode nRet = ERRCODE_NONE;
+
+ sal_uInt32 nFilterImportFlags = GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG;
+ // non-local?
+ if ( INET_PROT_FILE != aURLObj.GetProtocol() )
+ {
+ SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ );
+
+ if( pStream )
+ nRet = mpGraphicFilter->ImportGraphic( rGraphic, rURL, *pStream, nFilter, NULL, nFilterImportFlags );
+ else
+ nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
+ delete pStream;
+ }
+ else
+ {
+ nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
+ }
+
+ return nRet;
+}
+
+// ------------------------------------------------------------------------
+ErrCode FileDialogHelper_Impl::getGraphic( Graphic& rGraphic ) const
+{
+ ErrCode nRet = ERRCODE_NONE;
+
+ if ( ! maGraphic )
+ {
+ OUString aPath;;
+ Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
+
+ if ( aPathSeq.getLength() == 1 )
+ {
+ aPath = aPathSeq[0];
+ }
+
+ if ( aPath.getLength() )
+ nRet = getGraphic( aPath, rGraphic );
+ else
+ nRet = ERRCODE_IO_GENERAL;
+ }
+ else
+ rGraphic = maGraphic;
+
+ return nRet;
+}
+
+// ------------------------------------------------------------------------
+sal_Bool lcl_isSystemFilePicker( const uno::Reference< XFilePicker >& _rxFP )
+{
+ try
+ {
+ uno::Reference< XServiceInfo > xSI( _rxFP, UNO_QUERY );
+ if ( xSI.is() && xSI->supportsService( DEFINE_CONST_OUSTRING( "com.sun.star.ui.dialogs.SystemFilePicker" ) ) )
+ return sal_True;
+ }
+ catch( const Exception& )
+ {
+ }
+ return sal_False;
+}
+
+
+// ------------------------------------------------------------------------
+// ----------- FileDialogHelper_Impl ---------------------------
+// ------------------------------------------------------------------------
+
+FileDialogHelper_Impl::FileDialogHelper_Impl(
+ FileDialogHelper* _pAntiImpl,
+ sal_Int16 nDialogType,
+ sal_Int64 nFlags,
+ sal_Int16 nDialog,
+ Window* _pPreferredParentWindow,
+ const String& sStandardDir,
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList
+ )
+ :m_nDialogType ( nDialogType )
+ ,meContext ( FileDialogHelper::UNKNOWN_CONTEXT )
+{
+ const char* pServiceName=0;
+ if ( nDialog == SFX2_IMPL_DIALOG_SYSTEM )
+ pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
+ else if ( nDialog == SFX2_IMPL_DIALOG_OOO )
+ pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
+ else
+ pServiceName = FILE_OPEN_SERVICE_NAME;
+ OUString aService = ::rtl::OUString::createFromAscii( pServiceName );
+
+ uno::Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
+
+ // create the file open dialog
+ // the flags can be SFXWB_INSERT or SFXWB_MULTISELECTION
+
+ mpPreferredParentWindow = _pPreferredParentWindow;
+ mpAntiImpl = _pAntiImpl;
+ mnError = ERRCODE_NONE;
+ mbHasAutoExt = sal_False;
+ mbHasPassword = sal_False;
+ m_bHaveFilterOptions = sal_False;
+ mbIsPwdEnabled = sal_True;
+ mbHasVersions = sal_False;
+ mbHasPreview = sal_False;
+ mbShowPreview = sal_False;
+ mbHasLink = sal_False;
+ mbDeleteMatcher = sal_False;
+ mbInsert = SFXWB_INSERT == ( nFlags & SFXWB_INSERT );
+ mbExport = SFXWB_EXPORT == ( nFlags & SFXWB_EXPORT );
+ mbIsSaveDlg = sal_False;
+ mbPwdCheckBoxState = sal_False;
+ mbSelection = sal_False;
+ mbSelectionEnabled = sal_True;
+ mbHasSelectionBox = sal_False;
+ mbSelectionFltrEnabled = sal_False;
+
+ // default settings
+ m_nDontFlags = SFX_FILTER_INTERNAL | SFX_FILTER_NOTINFILEDLG | SFX_FILTER_NOTINSTALLED;
+ if( WB_OPEN == ( nFlags & WB_OPEN ) )
+ m_nMustFlags = SFX_FILTER_IMPORT;
+ else
+ m_nMustFlags = SFX_FILTER_EXPORT;
+
+
+ mpMatcher = NULL;
+ mpGraphicFilter = NULL;
+ mnPostUserEventId = 0;
+
+ // create the picker component
+ mxFileDlg = mxFileDlg.query( xFactory->createInstance( aService ) );
+ mbSystemPicker = lcl_isSystemFilePicker( mxFileDlg );
+
+ uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
+ uno::Reference< XInitialization > xInit( mxFileDlg, UNO_QUERY );
+
+ if ( ! mxFileDlg.is() || ! xNotifier.is() )
+ {
+ mnError = ERRCODE_ABORT;
+ return;
+ }
+
+
+ if ( xInit.is() )
+ {
+ sal_Int16 nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
+
+ switch ( m_nDialogType )
+ {
+ case FILEOPEN_SIMPLE:
+ nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
+ break;
+
+ case FILESAVE_SIMPLE:
+ nTemplateDescription = TemplateDescription::FILESAVE_SIMPLE;
+ mbIsSaveDlg = sal_True;
+ break;
+
+ case FILESAVE_AUTOEXTENSION_PASSWORD:
+ nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
+ mbHasPassword = sal_True;
+ mbHasAutoExt = sal_True;
+ mbIsSaveDlg = sal_True;
+ break;
+
+ case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
+ nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS;
+ mbHasPassword = sal_True;
+
+ m_bHaveFilterOptions = sal_True;
+ if( xFactory.is() )
+ {
+ mxFilterCFG = uno::Reference< XNameAccess >(
+ xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
+ UNO_QUERY );
+ }
+
+ mbHasAutoExt = sal_True;
+ mbIsSaveDlg = sal_True;
+ break;
+
+ case FILESAVE_AUTOEXTENSION_SELECTION:
+ nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION;
+ mbHasAutoExt = sal_True;
+ mbIsSaveDlg = sal_True;
+ mbHasSelectionBox = sal_True;
+ if ( mbExport && !mxFilterCFG.is() && xFactory.is() )
+ {
+ mxFilterCFG = uno::Reference< XNameAccess >(
+ xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
+ UNO_QUERY );
+ }
+ break;
+
+ case FILESAVE_AUTOEXTENSION_TEMPLATE:
+ nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE;
+ mbHasAutoExt = sal_True;
+ mbIsSaveDlg = sal_True;
+ break;
+
+ case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
+ nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
+ mbHasPreview = sal_True;
+ mbHasLink = sal_True;
+
+ // aPreviewTimer
+ maPreViewTimer.SetTimeout( 500 );
+ maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
+ break;
+
+ case FILEOPEN_PLAY:
+ nTemplateDescription = TemplateDescription::FILEOPEN_PLAY;
+ break;
+
+ case FILEOPEN_READONLY_VERSION:
+ nTemplateDescription = TemplateDescription::FILEOPEN_READONLY_VERSION;
+ mbHasVersions = sal_True;
+ break;
+
+ case FILEOPEN_LINK_PREVIEW:
+ nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW;
+ mbHasPreview = sal_True;
+ mbHasLink = sal_True;
+ // aPreviewTimer
+ maPreViewTimer.SetTimeout( 500 );
+ maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
+ break;
+
+ case FILESAVE_AUTOEXTENSION:
+ nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION;
+ mbHasAutoExt = sal_True;
+ mbIsSaveDlg = sal_True;
+ break;
+
+ default:
+ DBG_ERRORFILE( "FileDialogHelper::ctor with unknown type" );
+ break;
+ }
+
+
+
+ //Sequence < Any > aInitArguments( mbSystemPicker || !mpPreferredParentWindow ? 1 : 3 );
+ Sequence < Any > aInitArguments( !mpPreferredParentWindow ? 3 : 4 );
+
+ // This is a hack. We currently know that the internal file picker implementation
+ // supports the extended arguments as specified below.
+ // TODO:
+ // a) adjust the service description so that it includes the TemplateDescription and ParentWindow args
+ // b) adjust the implementation of the system file picker to that it recognizes it
+ if ( mbSystemPicker )
+ {
+ aInitArguments[0] <<= nTemplateDescription;
+ }
+ else
+ {
+ aInitArguments[0] <<= NamedValue(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TemplateDescription" ) ),
+ makeAny( nTemplateDescription )
+ );
+
+ ::rtl::OUString sStandardDirTemp = ::rtl::OUString( sStandardDir );
+
+ aInitArguments[1] <<= NamedValue(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StandardDir" ) ),
+ makeAny( sStandardDirTemp )
+ );
+
+ aInitArguments[2] <<= NamedValue(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BlackList" ) ),
+ makeAny( rBlackList )
+ );
+
+
+ if ( mpPreferredParentWindow )
+ aInitArguments[3] <<= NamedValue(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ) ),
+ makeAny( VCLUnoHelper::GetInterface( mpPreferredParentWindow ) )
+ );
+
+
+ }
+
+ try
+ {
+ xInit->initialize( aInitArguments );
+ }
+ catch( const Exception& )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::FileDialogHelper_Impl: could not initialize the picker!" );
+ }
+ }
+
+
+ // set multiselection mode
+ if ( nFlags & SFXWB_MULTISELECTION )
+ mxFileDlg->setMultiSelectionMode( sal_True );
+
+ if ( mbHasLink ) // generate graphic filter only on demand
+ addGraphicFilter();
+
+ // Export dialog
+ if ( mbExport )
+ {
+ mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_EXPORT ) ) ) );
+ try {
+ com::sun::star::uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY_THROW );
+ xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, sal_True );
+ }
+ catch( const Exception & ) { }
+ }
+
+ // the "insert file" dialog needs another title
+ if ( mbInsert )
+ {
+ mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_INSERT ) ) ) );
+ uno::Reference < XFilePickerControlAccess > xExtDlg( mxFileDlg, UNO_QUERY );
+ if ( xExtDlg.is() )
+ {
+ try
+ {
+ xExtDlg->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK,
+ OUString( String( SfxResId( STR_SFX_EXPLORERFILE_BUTTONINSERT ) ) ) );
+ }
+ catch( IllegalArgumentException ){}
+ }
+ }
+
+ // add the event listener
+ xNotifier->addFilePickerListener( this );
+}
+
+// ------------------------------------------------------------------------
+FileDialogHelper_Impl::~FileDialogHelper_Impl()
+{
+ // Remove user event if we haven't received it yet
+ if ( mnPostUserEventId )
+ Application::RemoveUserEvent( mnPostUserEventId );
+ mnPostUserEventId = 0;
+
+ delete mpGraphicFilter;
+
+ if ( mbDeleteMatcher )
+ delete mpMatcher;
+
+ maPreViewTimer.SetTimeoutHdl( Link() );
+
+ ::comphelper::disposeComponent( mxFileDlg );
+}
+
+#define nMagic -1
+
+class PickerThread_Impl : public ::vos::OThread
+{
+ uno::Reference < XFilePicker > mxPicker;
+ ::vos::OMutex maMutex;
+ virtual void SAL_CALL run();
+ sal_Int16 mnRet;
+public:
+ PickerThread_Impl( const uno::Reference < XFilePicker >& rPicker )
+ : mxPicker( rPicker ), mnRet(nMagic) {}
+
+ sal_Int16 GetReturnValue()
+ { ::vos::OGuard aGuard( maMutex ); return mnRet; }
+
+ void SetReturnValue( sal_Int16 aRetValue )
+ { ::vos::OGuard aGuard( maMutex ); mnRet = aRetValue; }
+};
+
+void SAL_CALL PickerThread_Impl::run()
+{
+ try
+ {
+ sal_Int16 n = mxPicker->execute();
+ SetReturnValue( n );
+ }
+ catch( RuntimeException& )
+ {
+ SetReturnValue( ExecutableDialogResults::CANCEL );
+ DBG_ERRORFILE( "RuntimeException caught" );
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId )
+{
+ DBG_ASSERT( _pControlId && _pHelpId, "FileDialogHelper_Impl::setControlHelpIds: invalid array pointers!" );
+ if ( !_pControlId || !_pHelpId )
+ return;
+
+ // forward these ids to the file picker
+ try
+ {
+ const ::rtl::OUString sHelpIdPrefix( RTL_CONSTASCII_USTRINGPARAM( INET_HID_SCHEME ) );
+ // the ids for the single controls
+ uno::Reference< XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
+ if ( xControlAccess.is() )
+ {
+ while ( *_pControlId )
+ {
+ DBG_ASSERT( INetURLObject( rtl::OStringToOUString( *_pHelpId, RTL_TEXTENCODING_UTF8 ) ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" );
+ ::rtl::OUString sId( sHelpIdPrefix );
+ sId += ::rtl::OUString( *_pHelpId, strlen( *_pHelpId ), RTL_TEXTENCODING_UTF8 );
+ xControlAccess->setValue( *_pControlId, ControlActions::SET_HELP_URL, makeAny( sId ) );
+
+ ++_pControlId; ++_pHelpId;
+ }
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::setControlHelpIds: caught an exception while setting the help ids!" );
+ }
+}
+
+// ------------------------------------------------------------------------
+IMPL_LINK( FileDialogHelper_Impl, InitControls, void*, NOTINTERESTEDIN )
+{
+ (void)NOTINTERESTEDIN;
+ mnPostUserEventId = 0;
+ enablePasswordBox( sal_True );
+ updateFilterOptionsBox( );
+ updateSelectionBox( );
+
+ return 0L;
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::preExecute()
+{
+ loadConfig( );
+ setDefaultValues( );
+ updatePreviewState( sal_False );
+
+ implInitializeFileName( );
+ // #106079# / 2002-12-09 / fs@openoffice.org
+
+#if !(defined(MACOSX) && defined(QUARTZ)) && !defined(WNT)
+ // allow for dialog implementations which need to be executed before they return valid values for
+ // current filter and such
+
+ // On Vista (at least SP1) it's the same as on MacOSX, the modal dialog won't let message pass
+ // through before it returns from execution
+ mnPostUserEventId = Application::PostUserEvent( LINK( this, FileDialogHelper_Impl, InitControls ) );
+#else
+ // However, the Mac OS X implementation's pickers run modally in execute and so the event doesn't
+ // get through in time... so we call the methods directly
+ enablePasswordBox( sal_True );
+ updateFilterOptionsBox( );
+ updateSelectionBox( );
+#endif
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::postExecute( sal_Int16 _nResult )
+{
+ if ( ExecutableDialogResults::CANCEL != _nResult )
+ saveConfig();
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::implInitializeFileName( )
+{
+ if ( maFileName.getLength() )
+ {
+ INetURLObject aObj( maPath );
+ aObj.Append( maFileName );
+
+ // in case we're operating as save dialog, and "auto extension" is checked,
+ // cut the extension from the name
+ // #106079# / 2002-12-09 / fs@openoffice.org
+ if ( mbIsSaveDlg && mbHasAutoExt )
+ {
+ try
+ {
+ sal_Bool bAutoExtChecked = sal_False;
+
+ uno::Reference < XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
+ if ( xControlAccess.is()
+ && ( xControlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 )
+ >>= bAutoExtChecked
+ )
+ )
+ {
+ if ( bAutoExtChecked )
+ { // cut the extension
+ aObj.removeExtension( );
+ mxFileDlg->setDefaultName( aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ) );
+ }
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::implInitializeFileName: could not ask for the auto-extension current-value!" );
+ }
+ }
+ }
+}
+
+// ------------------------------------------------------------------------
+sal_Int16 FileDialogHelper_Impl::implDoExecute()
+{
+ preExecute();
+
+ sal_Int16 nRet = ExecutableDialogResults::CANCEL;
+
+//On MacOSX the native file picker has to run in the primordial thread because of drawing issues
+//On Linux the native gtk file picker, when backed by gnome-vfs2, needs to be run in the same
+//primordial thread as the ucb gnome-vfs2 provider was initialized in.
+/*
+#ifdef WNT
+ if ( mbSystemPicker )
+ {
+ PickerThread_Impl* pThread = new PickerThread_Impl( mxFileDlg );
+ pThread->create();
+ while ( pThread->GetReturnValue() == nMagic )
+ Application::Yield();
+ pThread->join();
+ nRet = pThread->GetReturnValue();
+ delete pThread;
+ }
+ else
+#endif
+*/
+ {
+ try
+ {
+#ifdef WNT
+ if ( mbSystemPicker )
+ {
+ OReleaseSolarMutex aSolarMutex;
+ nRet = mxFileDlg->execute();
+ }
+ else
+#endif
+ nRet = mxFileDlg->execute();
+ }
+ catch( const Exception& )
+ {
+ DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
+ }
+ }
+
+ postExecute( nRet );
+
+ return nRet;
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::implStartExecute()
+{
+ DBG_ASSERT( mxFileDlg.is(), "invalid file dialog" );
+
+ preExecute();
+
+ if ( mbSystemPicker )
+ {
+ }
+ else
+ {
+ try
+ {
+ uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( mxFileDlg, UNO_QUERY );
+ if ( xAsyncDlg.is() )
+ xAsyncDlg->startExecuteModal( this );
+ }
+ catch( const Exception& )
+ {
+ DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
+ }
+ }
+}
+
+// ------------------------------------------------------------------------
+String FileDialogHelper_Impl::implEnsureURLExtension(const String& sURL,
+ const String& /*sExtension*/)
+{
+ return sURL;
+ /*
+ // This feature must be active for file save/export only !
+ if (
+ (! mbIsSaveDlg) &&
+ (! mbExport )
+ )
+ return sURL;
+
+ // no extension available (because "ALL *.*" was selected) ?
+ // Nod idea what else should happen here .-)
+ if (sExtension.Len() < 1)
+ return sURL;
+
+ // Some FilePicker implementations already add the right extension ...
+ // or might be the user used the right one already ...
+ // Dont create duplicate extension.
+ INetURLObject aURL(sURL);
+ if (aURL.getExtension().equals(sExtension))
+ return sURL;
+
+ // Ignore any other extension set by the user.
+ // Make sure suitable extension is used always.
+ // e.g. "test.bla.odt" for "ODT"
+ ::rtl::OUStringBuffer sNewURL(256);
+ sNewURL.append (sURL );
+ sNewURL.appendAscii("." );
+ sNewURL.append (sExtension);
+ return sNewURL.makeStringAndClear();
+ */
+}
+
+// ------------------------------------------------------------------------
+void lcl_saveLastURLs(SvStringsDtor*& rpURLList ,
+ ::comphelper::SequenceAsVector< ::rtl::OUString >& lLastURLs )
+{
+ lLastURLs.clear();
+ USHORT c = rpURLList->Count();
+ USHORT i = 0;
+ for (i=0; i<c; ++i)
+ lLastURLs.push_back(*(rpURLList->GetObject(i)));
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::implGetAndCacheFiles(const uno::Reference< XInterface >& xPicker ,
+ SvStringsDtor*& rpURLList,
+ const SfxFilter* pFilter )
+{
+ rpURLList = NULL;
+
+ String sExtension;
+ if (pFilter)
+ {
+ sExtension = pFilter->GetDefaultExtension ();
+ sExtension.EraseAllChars( '*' );
+ sExtension.EraseAllChars( '.' );
+ }
+
+ // a) the new way (optional!)
+ uno::Reference< XFilePicker2 > xPickNew(xPicker, UNO_QUERY);
+ if (xPickNew.is())
+ {
+ rpURLList = new SvStringsDtor;
+ Sequence< OUString > lFiles = xPickNew->getSelectedFiles();
+ ::sal_Int32 nFiles = lFiles.getLength();
+ for (::sal_Int32 i = 0; i < nFiles; i++)
+ {
+ String* pURL = new String(implEnsureURLExtension(lFiles[i], sExtension));
+ rpURLList->Insert( pURL, rpURLList->Count() );
+ }
+ }
+
+ // b) the olde way ... non optional.
+ else
+ {
+ uno::Reference< XFilePicker > xPickOld(xPicker, UNO_QUERY_THROW);
+ Sequence< OUString > lFiles = xPickOld->getFiles();
+ ::sal_Int32 nFiles = lFiles.getLength();
+ if ( nFiles == 1 )
+ {
+ rpURLList = new SvStringsDtor;
+ String* pURL = new String(implEnsureURLExtension(lFiles[0], sExtension));
+ rpURLList->Insert( pURL, 0 );
+ }
+ else
+ if ( nFiles > 1 )
+ {
+ rpURLList = new SvStringsDtor;
+
+ INetURLObject aPath( lFiles[0] );
+ aPath.setFinalSlash();
+
+ for (::sal_Int32 i = 1; i < nFiles; i++)
+ {
+ if (i == 1)
+ aPath.Append( lFiles[i] );
+ else
+ aPath.setName( lFiles[i] );
+
+ String* pURL = new String(implEnsureURLExtension(aPath.GetMainURL( INetURLObject::NO_DECODE ), sExtension) );
+ rpURLList->Insert( pURL, rpURLList->Count() );
+ }
+ }
+ }
+
+ lcl_saveLastURLs(rpURLList, mlLastURLs);
+}
+
+// ------------------------------------------------------------------------
+ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
+ SfxItemSet *& rpSet,
+ String& rFilter )
+{
+ // rFilter is a pure output parameter, it shouldn't be used for anything else
+ // changing this would surely break code
+ // rpSet is in/out parameter, usually just a media-descriptor that can be changed by dialog
+
+ uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
+
+ // retrieves parameters from rpSet
+ // for now only Password is used
+ if ( rpSet )
+ {
+ // check password checkbox if the document had password before
+ if( mbHasPassword )
+ {
+ SFX_ITEMSET_ARG( rpSet, pPassItem, SfxBoolItem, SID_PASSWORDINTERACTION, FALSE );
+ mbPwdCheckBoxState = ( pPassItem != NULL && pPassItem->GetValue() );
+
+ // in case the document has password to modify, the dialog should be shown
+ SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, FALSE );
+ mbPwdCheckBoxState |= ( pPassToModifyItem && pPassToModifyItem->GetValue().hasValue() );
+ }
+
+ SFX_ITEMSET_ARG( rpSet, pSelectItem, SfxBoolItem, SID_SELECTION, FALSE );
+ if ( pSelectItem )
+ mbSelection = pSelectItem->GetValue();
+ else
+ mbSelectionEnabled = sal_False;
+
+ // the password will be set in case user decide so
+ rpSet->ClearItem( SID_PASSWORDINTERACTION );
+ rpSet->ClearItem( SID_PASSWORD );
+ rpSet->ClearItem( SID_ENCRYPTIONDATA );
+ rpSet->ClearItem( SID_RECOMMENDREADONLY );
+ rpSet->ClearItem( SID_MODIFYPASSWORDINFO );
+
+ }
+
+ if ( mbHasPassword && !mbPwdCheckBoxState )
+ {
+ SvtSecurityOptions aSecOpt;
+ mbPwdCheckBoxState = (
+ aSecOpt.IsOptionSet( SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD ) );
+ }
+
+ rpURLList = NULL;
+
+ if ( ! mxFileDlg.is() )
+ return ERRCODE_ABORT;
+
+ if ( ExecutableDialogResults::CANCEL != implDoExecute() )
+ {
+ // create an itemset if there is no
+ if( !rpSet )
+ rpSet = new SfxAllItemSet( SFX_APP()->GetPool() );
+
+ // the item should remain only if it was set by the dialog
+ rpSet->ClearItem( SID_SELECTION );
+
+ if( mbExport )
+ {
+ try
+ {
+ Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
+ sal_Bool bSelection = sal_False;
+ if ( aValue >>= bSelection )
+ rpSet->Put( SfxBoolItem( SID_SELECTION, bSelection ) );
+ }
+ catch( IllegalArgumentException )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
+ }
+ }
+
+
+ // set the read-only flag. When inserting a file, this flag is always set
+ if ( mbInsert )
+ rpSet->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
+ else
+ {
+ if ( ( FILEOPEN_READONLY_VERSION == m_nDialogType ) && xCtrlAccess.is() )
+ {
+ try
+ {
+ Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 );
+ sal_Bool bReadOnly = sal_False;
+ if ( ( aValue >>= bReadOnly ) && bReadOnly )
+ rpSet->Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
+ }
+ catch( IllegalArgumentException )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
+ }
+ }
+ }
+ if ( mbHasVersions && xCtrlAccess.is() )
+ {
+ try
+ {
+ Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
+ ControlActions::GET_SELECTED_ITEM_INDEX );
+ sal_Int32 nVersion = 0;
+ if ( ( aValue >>= nVersion ) && nVersion > 0 )
+ // open a special version; 0 == current version
+ rpSet->Put( SfxInt16Item( SID_VERSION, (short)nVersion ) );
+ }
+ catch( IllegalArgumentException ){}
+ }
+
+ // set the filter
+ getRealFilter( rFilter );
+
+ const SfxFilter* pCurrentFilter = getCurentSfxFilter();
+
+ // fill the rpURLList
+ implGetAndCacheFiles( mxFileDlg, rpURLList, pCurrentFilter );
+ if ( rpURLList == NULL || rpURLList->GetObject(0) == NULL )
+ return ERRCODE_ABORT;
+
+ // check, wether or not we have to display a password box
+ if ( pCurrentFilter && mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() )
+ {
+ try
+ {
+ Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
+ sal_Bool bPassWord = sal_False;
+ if ( ( aValue >>= bPassWord ) && bPassWord )
+ {
+ // ask for a password
+ uno::Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY );
+
+ if( xInteractionHandler.is() )
+ {
+ // TODO: need a save way to distinguish MS filters from other filters
+ // for now MS-filters are the only alien filters that support encryption
+ sal_Bool bMSType = !pCurrentFilter->IsOwnFormat();
+ ::comphelper::DocPasswordRequestType eType = bMSType ?
+ ::comphelper::DocPasswordRequestType_MS :
+ ::comphelper::DocPasswordRequestType_STANDARD;
+
+ ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)), ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ) != 0 ) );
+
+ uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
+ xInteractionHandler->handle( rRequest );
+ if ( pPasswordRequest->isPassword() )
+ {
+ if ( pPasswordRequest->getPassword().getLength() )
+ {
+ // TODO/LATER: The filters should show the password dialog themself in future
+ if ( bMSType )
+ {
+ // all the current MS-filters use MSCodec_Std97 implementation
+ uno::Sequence< sal_Int8 > aUniqueID = ::comphelper::DocPasswordHelper::GenerateRandomByteSequence( 16 );
+ uno::Sequence< sal_Int8 > aEncryptionKey = ::comphelper::DocPasswordHelper::GenerateStd97Key( pPasswordRequest->getPassword(), aUniqueID );
+
+ if ( aEncryptionKey.getLength() )
+ {
+ ::comphelper::SequenceAsHashMap aHashData;
+ aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "STD97EncryptionKey" ) ) ] <<= aEncryptionKey;
+ aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "STD97UniqueID" ) ) ] <<= aUniqueID;
+
+ rpSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aHashData.getAsConstNamedValueList() ) ) );
+ }
+ else
+ return ERRCODE_IO_NOTSUPPORTED;
+ }
+ else
+ {
+ rpSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( ::comphelper::OStorageHelper::CreatePackageEncryptionData( pPasswordRequest->getPassword() ) ) ) );
+ }
+ }
+
+ if ( pPasswordRequest->getRecommendReadOnly() )
+ rpSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) );
+
+ if ( bMSType )
+ {
+ // the empty password has 0 as Hash
+ sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pCurrentFilter->GetServiceName() ) );
+ if ( nHash )
+ rpSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( nHash ) ) );
+ }
+ else
+ {
+ uno::Sequence< beans::PropertyValue > aModifyPasswordInfo = ::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfo( pPasswordRequest->getPasswordToModify() );
+ if ( aModifyPasswordInfo.getLength() )
+ rpSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( aModifyPasswordInfo ) ) );
+ }
+ }
+ else
+ return ERRCODE_ABORT;
+ }
+ }
+ }
+ catch( IllegalArgumentException ){}
+ }
+
+ SaveLastUsedFilter();
+ return ERRCODE_NONE;
+ }
+ else
+ return ERRCODE_ABORT;
+}
+
+// ------------------------------------------------------------------------
+ErrCode FileDialogHelper_Impl::execute()
+{
+ if ( ! mxFileDlg.is() )
+ return ERRCODE_ABORT;
+
+ sal_Int16 nRet = implDoExecute();
+
+ maPath = mxFileDlg->getDisplayDirectory();
+
+ if ( ExecutableDialogResults::CANCEL == nRet )
+ return ERRCODE_ABORT;
+ else
+ {
+ return ERRCODE_NONE;
+ }
+}
+
+// ------------------------------------------------------------------------
+OUString FileDialogHelper_Impl::getPath() const
+{
+ OUString aPath;
+
+ if ( mxFileDlg.is() )
+ aPath = mxFileDlg->getDisplayDirectory();
+
+ if ( !aPath.getLength() )
+ aPath = maPath;
+
+ return aPath;
+}
+
+// ------------------------------------------------------------------------
+OUString FileDialogHelper_Impl::getFilter() const
+{
+ String aFilter = getCurrentFilterUIName();
+
+ if( !aFilter.Len() )
+ aFilter = maCurFilter;
+
+ return aFilter;
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::getRealFilter( String& _rFilter ) const
+{
+ _rFilter = getCurrentFilterUIName();
+
+ if ( !_rFilter.Len() )
+ _rFilter = maCurFilter;
+
+ if ( _rFilter.Len() && mpMatcher )
+ {
+ const SfxFilter* pFilter =
+ mpMatcher->GetFilter4UIName( _rFilter, m_nMustFlags, m_nDontFlags );
+ _rFilter = pFilter ? pFilter->GetFilterName() : _rFilter.Erase();
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::displayFolder( const ::rtl::OUString& _rPath )
+{
+ if ( ! _rPath.getLength() )
+ // nothing to do
+ return;
+
+ /*
+ if ( !::utl::UCBContentHelper::IsFolder( _rPath ) )
+ // only valid folders accepted here
+ return;
+ */
+
+ maPath = _rPath;
+ if ( mxFileDlg.is() )
+ {
+ try
+ {
+ mxFileDlg->setDisplayDirectory( maPath );
+ }
+ catch( const IllegalArgumentException& )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::displayFolder: caught an exception!" );
+ }
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::setFileName( const ::rtl::OUString& _rFile )
+{
+ maFileName = _rFile;
+ if ( mxFileDlg.is() )
+ {
+ try
+ {
+ mxFileDlg->setDefaultName( maFileName );
+ }
+ catch( const IllegalArgumentException& )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::setFileName: caught an exception!" );
+ }
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::setFilter( const OUString& rFilter )
+{
+ DBG_ASSERT( rFilter.indexOf(':') == -1, "Old filter name used!");
+
+ maCurFilter = rFilter;
+
+ if ( rFilter.getLength() && mpMatcher )
+ {
+ const SfxFilter* pFilter = mpMatcher->GetFilter4FilterName(
+ rFilter, m_nMustFlags, m_nDontFlags );
+ if ( pFilter )
+ maCurFilter = pFilter->GetUIName();
+ }
+
+ uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
+
+ if ( maCurFilter.getLength() && xFltMgr.is() )
+ {
+ try
+ {
+ xFltMgr->setCurrentFilter( maCurFilter );
+ }
+ catch( IllegalArgumentException ){}
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::createMatcher( const String& rFactory )
+{
+ mpMatcher = new SfxFilterMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
+ mbDeleteMatcher = sal_True;
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::addFilters( sal_Int64 nFlags,
+ const String& rFactory,
+ SfxFilterFlags nMust,
+ SfxFilterFlags nDont )
+{
+ uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
+
+ if ( ! xFltMgr.is() )
+ return;
+
+ // we still need a matcher to convert UI names to filter names
+ if ( !rFactory.Len() )
+ {
+ SfxApplication *pSfxApp = SFX_APP();
+ mpMatcher = &pSfxApp->GetFilterMatcher();
+ mbDeleteMatcher = sal_False;
+ }
+ else
+ {
+ mpMatcher = new SfxFilterMatcher( rFactory );
+ mbDeleteMatcher = sal_True;
+ }
+
+ uno::Reference< XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
+ uno::Reference< XContainerQuery > xFilterCont(
+ xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.FilterFactory")),
+ UNO_QUERY);
+ if ( ! xFilterCont.is() )
+ return;
+
+ m_nMustFlags |= nMust;
+ m_nDontFlags |= nDont;
+
+ // create the list of filters
+ ::rtl::OUStringBuffer sQuery(256);
+ sQuery.appendAscii("getSortedFilterList()");
+ sQuery.appendAscii(":module=" );
+ sQuery.append (rFactory ); // use long name here !
+ sQuery.appendAscii(":iflags=" );
+ sQuery.append (::rtl::OUString::valueOf((sal_Int32)m_nMustFlags));
+ sQuery.appendAscii(":eflags=" );
+ sQuery.append (::rtl::OUString::valueOf((sal_Int32)m_nDontFlags));
+
+ uno::Reference< XEnumeration > xResult;
+ try
+ {
+ xResult = xFilterCont->createSubSetEnumerationByQuery(sQuery.makeStringAndClear());
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERRORFILE( "Could not get filters from the configuration!" );
+ }
+
+ TSortedFilterList aIter (xResult);
+
+ // no matcher any longer used ...
+ mbDeleteMatcher = sal_False;
+
+ // append the filters
+ ::rtl::OUString sFirstFilter;
+ if ( WB_OPEN == ( nFlags & WB_OPEN ) )
+ ::sfx2::appendFiltersForOpen( aIter, xFltMgr, sFirstFilter, *this );
+ else if ( mbExport )
+ ::sfx2::appendExportFilters( aIter, xFltMgr, sFirstFilter, *this );
+ else
+ ::sfx2::appendFiltersForSave( aIter, xFltMgr, sFirstFilter, *this, rFactory );
+
+ // set our initial selected filter (if we do not already have one)
+ if ( !maSelectFilter.getLength() )
+ maSelectFilter = sFirstFilter;
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::addFilter( const OUString& rFilterName,
+ const OUString& rExtension )
+{
+ uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
+
+ if ( ! xFltMgr.is() )
+ return;
+
+ try
+ {
+ xFltMgr->appendFilter( rFilterName, rExtension );
+
+ if ( !maSelectFilter.getLength() )
+ maSelectFilter = rFilterName;
+ }
+ catch( IllegalArgumentException )
+ {
+#ifdef DBG_UTIL
+ ByteString aMsg( "Could not append Filter" );
+ aMsg += ByteString( String( rFilterName ), RTL_TEXTENCODING_UTF8 );
+ DBG_ERRORFILE( aMsg.GetBuffer() );
+#endif
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::addGraphicFilter()
+{
+ uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
+
+ if ( ! xFltMgr.is() )
+ return;
+
+ // create the list of filters
+ mpGraphicFilter = new GraphicFilter;
+ USHORT i, j, nCount = mpGraphicFilter->GetImportFormatCount();
+
+ // compute the extension string for all known import filters
+ String aExtensions;
+
+ for ( i = 0; i < nCount; i++ )
+ {
+ j = 0;
+ String sWildcard;
+ while( TRUE )
+ {
+ sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
+ if ( !sWildcard.Len() )
+ break;
+ if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
+ {
+ if ( aExtensions.Len() )
+ aExtensions += sal_Unicode(';');
+ aExtensions += sWildcard;
+ }
+ }
+ }
+
+#if defined(WNT)
+ if ( aExtensions.Len() > 240 )
+ aExtensions = DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL );
+#endif
+ sal_Bool bIsInOpenMode = isInOpenMode();
+
+ try
+ {
+ OUString aAllFilterName = String( SfxResId( STR_SFX_IMPORT_ALL ) );
+ aAllFilterName = ::sfx2::addExtension( aAllFilterName, aExtensions, bIsInOpenMode, *this );
+
+ xFltMgr->appendFilter( aAllFilterName, aExtensions );
+ maSelectFilter = aAllFilterName;
+ }
+ catch( IllegalArgumentException )
+ {
+ DBG_ERRORFILE( "Could not append Filter" );
+ }
+
+ // Now add the filter
+ for ( i = 0; i < nCount; i++ )
+ {
+ String aName = mpGraphicFilter->GetImportFormatName( i );
+ String aExt;
+ j = 0;
+ String sWildcard;
+ while( TRUE )
+ {
+ sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
+ if ( !sWildcard.Len() )
+ break;
+ if ( aExt.Search( sWildcard ) == STRING_NOTFOUND )
+ {
+ if ( aExt.Len() )
+ aExt += sal_Unicode(';');
+ aExt += sWildcard;
+ }
+ }
+ aName = ::sfx2::addExtension( aName, aExt, bIsInOpenMode, *this );
+ try
+ {
+ xFltMgr->appendFilter( aName, aExt );
+ }
+ catch( IllegalArgumentException )
+ {
+ DBG_ERRORFILE( "Could not append Filter" );
+ }
+ }
+}
+
+// ------------------------------------------------------------------------
+#define GRF_CONFIG_STR " "
+#define STD_CONFIG_STR "1 "
+
+void FileDialogHelper_Impl::saveConfig()
+{
+ uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
+ Any aValue;
+
+ if ( ! xDlg.is() )
+ return;
+
+ if ( mbHasPreview )
+ {
+ SvtViewOptions aDlgOpt( E_DIALOG, IMPGRF_CONFIGNAME );
+ String aUserData = DEFINE_CONST_UNICODE( GRF_CONFIG_STR );
+
+ try
+ {
+ aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0 );
+ sal_Bool bValue = sal_False;
+ aValue >>= bValue;
+ aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bValue ) );
+
+ aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
+ bValue = sal_False;
+ aValue >>= bValue;
+ aUserData.SetToken( 1, ' ', String::CreateFromInt32( (sal_Int32) bValue ) );
+
+ INetURLObject aObj( getPath() );
+
+ if ( aObj.GetProtocol() == INET_PROT_FILE )
+ aUserData.SetToken( 2, ' ', aObj.GetMainURL( INetURLObject::NO_DECODE ) );
+
+ String aFilter = getFilter();
+ aFilter = EncodeSpaces_Impl( aFilter );
+ aUserData.SetToken( 3, ' ', aFilter );
+
+ aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
+ }
+ catch( IllegalArgumentException ){}
+ }
+ else
+ {
+ sal_Bool bWriteConfig = sal_False;
+ SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
+ String aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
+
+ if ( aDlgOpt.Exists() )
+ {
+ Any aUserItem = aDlgOpt.GetUserItem( USERITEM_NAME );
+ OUString aTemp;
+ if ( aUserItem >>= aTemp )
+ aUserData = String( aTemp );
+ }
+
+ if ( mbHasAutoExt )
+ {
+ try
+ {
+ aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 );
+ sal_Bool bAutoExt = sal_True;
+ aValue >>= bAutoExt;
+ aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bAutoExt ) );
+ bWriteConfig = sal_True;
+ }
+ catch( IllegalArgumentException ){}
+ }
+
+ if ( ! mbIsSaveDlg )
+ {
+ OUString aPath = getPath();
+ if ( aPath.getLength() &&
+ utl::LocalFileHelper::IsLocalFile( aPath ) )
+ {
+ aUserData.SetToken( 1, ' ', aPath );
+ bWriteConfig = sal_True;
+ }
+ }
+
+ if( mbHasSelectionBox && mbSelectionFltrEnabled )
+ {
+ try
+ {
+ aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
+ sal_Bool bSelection = sal_True;
+ aValue >>= bSelection;
+ if ( aUserData.GetTokenCount(' ') < 3 )
+ aUserData.Append(' ');
+ aUserData.SetToken( 2, ' ', String::CreateFromInt32( (sal_Int32) bSelection ) );
+ bWriteConfig = sal_True;
+ }
+ catch( IllegalArgumentException ){}
+ }
+
+ if ( bWriteConfig )
+ aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
+ }
+
+ SfxApplication *pSfxApp = SFX_APP();
+ pSfxApp->SetLastDir_Impl( getPath() );
+}
+
+// ------------------------------------------------------------------------
+namespace
+{
+ static ::rtl::OUString getInitPath( const String& _rFallback, const xub_StrLen _nFallbackToken )
+ {
+ SfxApplication *pSfxApp = SFX_APP();
+ String sPath = pSfxApp->GetLastDir_Impl();
+
+ if ( !sPath.Len() )
+ sPath = _rFallback.GetToken( _nFallbackToken, ' ' );
+
+ // check if the path points to a valid (accessible) directory
+ sal_Bool bValid = sal_False;
+ if ( sPath.Len() )
+ {
+ String sPathCheck( sPath );
+ if ( sPathCheck.GetBuffer()[ sPathCheck.Len() - 1 ] != '/' )
+ sPathCheck += '/';
+ sPathCheck += '.';
+ try
+ {
+ ::ucbhelper::Content aContent( sPathCheck, uno::Reference< ucb::XCommandEnvironment >() );
+ bValid = aContent.isFolder();
+ }
+ catch( Exception& ) {}
+ }
+
+ if ( !bValid )
+ sPath.Erase();
+
+ return sPath;
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::loadConfig()
+{
+ uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
+ Any aValue;
+
+ if ( ! xDlg.is() )
+ return;
+
+ if ( mbHasPreview )
+ {
+ SvtViewOptions aViewOpt( E_DIALOG, IMPGRF_CONFIGNAME );
+ String aUserData;
+
+ if ( aViewOpt.Exists() )
+ {
+ Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
+ OUString aTemp;
+ if ( aUserItem >>= aTemp )
+ aUserData = String( aTemp );
+ }
+
+ if ( aUserData.Len() > 0 )
+ {
+ try
+ {
+ // respect the last "insert as link" state
+ sal_Bool bLink = (sal_Bool) aUserData.GetToken( 0, ' ' ).ToInt32();
+ if ( !xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0 ).hasValue() )
+ {
+ aValue <<= bLink;
+ xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, aValue );
+ }
+
+ // respect the last "show preview" state
+ sal_Bool bShowPreview = (sal_Bool) aUserData.GetToken( 1, ' ' ).ToInt32();
+ if ( !xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 ).hasValue() )
+ {
+ aValue <<= bShowPreview;
+ xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, aValue );
+ }
+
+ if ( !maPath.getLength() )
+ displayFolder( getInitPath( aUserData, 2 ) );
+
+ if ( ! maCurFilter.getLength() )
+ {
+ String aFilter = aUserData.GetToken( 3, ' ' );
+ aFilter = DecodeSpaces_Impl( aFilter );
+ setFilter( aFilter );
+ }
+
+ // set the member so we know that we have to show the preview
+ mbShowPreview = bShowPreview;
+ }
+ catch( IllegalArgumentException ){}
+ }
+
+ if ( !maPath.getLength() )
+ displayFolder( SvtPathOptions().GetGraphicPath() );
+ }
+ else
+ {
+ SvtViewOptions aViewOpt( E_DIALOG, IODLG_CONFIGNAME );
+ String aUserData;
+
+ if ( aViewOpt.Exists() )
+ {
+ Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
+ OUString aTemp;
+ if ( aUserItem >>= aTemp )
+ aUserData = String( aTemp );
+ }
+
+ if ( ! aUserData.Len() )
+ aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
+
+ if ( ! maPath.getLength() )
+ displayFolder( getInitPath( aUserData, 1 ) );
+
+ if ( mbHasAutoExt )
+ {
+ sal_Int32 nFlag = aUserData.GetToken( 0, ' ' ).ToInt32();
+ aValue <<= (sal_Bool) nFlag;
+ try
+ {
+ xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue );
+ }
+ catch( IllegalArgumentException ){}
+ }
+
+ if( mbHasSelectionBox )
+ {
+ sal_Int32 nFlag = aUserData.GetToken( 2, ' ' ).ToInt32();
+ aValue <<= (sal_Bool) nFlag;
+ try
+ {
+ xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, aValue );
+ }
+ catch( IllegalArgumentException ){}
+ }
+
+ if ( !maPath.getLength() )
+ displayFolder( SvtPathOptions().GetWorkPath() );
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper_Impl::setDefaultValues()
+{
+ // when no filter is set, we set the curentFilter to <all>
+ if ( !maCurFilter.getLength() && maSelectFilter.getLength() )
+ {
+ uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
+ try
+ {
+ xFltMgr->setCurrentFilter( maSelectFilter );
+ }
+ catch( IllegalArgumentException )
+ {}
+ }
+
+ // when no path is set, we use the standard 'work' folder
+ if ( ! maPath.getLength() )
+ {
+ OUString aWorkFolder = SvtPathOptions().GetWorkPath();
+ try
+ {
+ mxFileDlg->setDisplayDirectory( aWorkFolder );
+ }
+ catch( const Exception& )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::setDefaultValues: caught an exception while setting the display directory!" );
+ }
+
+ // INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
+ //SetStandardDir( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE ) );
+ }
+}
+
+sal_Bool FileDialogHelper_Impl::isShowFilterExtensionEnabled() const
+{
+ return !maFilters.empty();
+}
+
+void FileDialogHelper_Impl::addFilterPair( const OUString& rFilter,
+ const OUString& rFilterWithExtension )
+{
+ maFilters.push_back( FilterPair( rFilter, rFilterWithExtension ) );
+
+}
+
+OUString FileDialogHelper_Impl::getFilterName( const OUString& rFilterWithExtension ) const
+{
+ OUString sRet;
+ for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
+ {
+ if ( (*pIter).Second == rFilterWithExtension )
+ {
+ sRet = (*pIter).First;
+ break;
+ }
+ }
+ return sRet;
+}
+
+OUString FileDialogHelper_Impl::getFilterWithExtension( const OUString& rFilter ) const
+{
+ OUString sRet;
+ for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
+ {
+ if ( (*pIter).First == rFilter )
+ {
+ sRet = (*pIter).Second;
+ break;
+ }
+ }
+ return sRet;
+}
+
+void FileDialogHelper_Impl::SetContext( FileDialogHelper::Context _eNewContext )
+{
+ meContext = _eNewContext;
+
+ sal_Int32 nNewHelpId = 0;
+ OUString aConfigId;
+
+ switch( _eNewContext )
+ {
+// #104952# dependency to SVX not allowed! When used again, another solution has to be found
+// case FileDialogHelper::SW_INSERT_GRAPHIC:
+// case FileDialogHelper::SC_INSERT_GRAPHIC:
+// case FileDialogHelper::SD_INSERT_GRAPHIC: nNewHelpId = SID_INSERT_GRAPHIC; break;
+ case FileDialogHelper::SW_INSERT_SOUND:
+ case FileDialogHelper::SC_INSERT_SOUND:
+ case FileDialogHelper::SD_INSERT_SOUND: nNewHelpId = SID_INSERT_SOUND; break;
+ case FileDialogHelper::SW_INSERT_VIDEO:
+ case FileDialogHelper::SC_INSERT_VIDEO:
+ case FileDialogHelper::SD_INSERT_VIDEO: nNewHelpId = SID_INSERT_VIDEO; break;
+ default: break;
+ }
+
+ const OUString* pConfigId = GetLastFilterConfigId( _eNewContext );
+ if( pConfigId )
+ LoadLastUsedFilter( *pConfigId );
+}
+
+// ------------------------------------------------------------------------
+// ----------- FileDialogHelper ---------------------------
+// ------------------------------------------------------------------------
+
+FileDialogHelper::FileDialogHelper(
+ sal_Int64 nFlags,
+ const String& rFact,
+ SfxFilterFlags nMust,
+ SfxFilterFlags nDont )
+{
+ mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags );
+ mxImp = mpImp;
+
+ // create the list of filters
+ mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
+}
+
+FileDialogHelper::FileDialogHelper(
+ sal_Int64 nFlags,
+ const String& rFact,
+ sal_Int16 nDialog,
+ SfxFilterFlags nMust,
+ SfxFilterFlags nDont,
+ const String& rStandardDir,
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
+{
+ mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags, nDialog, NULL , rStandardDir, rBlackList );
+ mxImp = mpImp;
+
+ // create the list of filters
+ mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
+}
+
+FileDialogHelper::FileDialogHelper(
+ sal_Int64 nFlags,
+ const String& rFact,
+ sal_Int16 nDialog,
+ SfxFilterFlags nMust,
+ SfxFilterFlags nDont )
+{
+ mpImp = new FileDialogHelper_Impl( this, getDialogType( nFlags ), nFlags, nDialog );
+ mxImp = mpImp;
+
+ // create the list of filters
+ mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
+}
+
+// ------------------------------------------------------------------------
+FileDialogHelper::FileDialogHelper( sal_Int64 nFlags )
+{
+ sal_Int16 nDialogType = getDialogType( nFlags );
+
+ mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags );
+ mxImp = mpImp;
+}
+
+// ------------------------------------------------------------------------
+FileDialogHelper::FileDialogHelper(
+ sal_Int16 nDialogType,
+ sal_Int64 nFlags,
+ const String& rFact,
+ SfxFilterFlags nMust,
+ SfxFilterFlags nDont )
+{
+ mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags );
+ mxImp = mpImp;
+
+ // create the list of filters
+ mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
+}
+
+// ------------------------------------------------------------------------
+FileDialogHelper::FileDialogHelper(
+ sal_Int16 nDialogType,
+ sal_Int64 nFlags,
+ const String& rFact,
+ sal_Int16 nDialog,
+ SfxFilterFlags nMust,
+ SfxFilterFlags nDont,
+ const String& rStandardDir,
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
+{
+ mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, nDialog, NULL, rStandardDir, rBlackList );
+ mxImp = mpImp;
+
+ // create the list of filters
+ mpImp->addFilters( nFlags, SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
+}
+
+// ------------------------------------------------------------------------
+FileDialogHelper::FileDialogHelper(
+ sal_Int16 nDialogType,
+ sal_Int64 nFlags,
+ Window* _pPreferredParent )
+{
+ mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent );
+ mxImp = mpImp;
+}
+
+// ------------------------------------------------------------------------
+FileDialogHelper::FileDialogHelper(
+ sal_Int16 nDialogType,
+ sal_Int64 nFlags,
+ const ::rtl::OUString& aFilterUIName,
+ const ::rtl::OUString& aExtName,
+ const ::rtl::OUString& rStandardDir,
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList,
+ Window* _pPreferredParent )
+{
+ mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent,rStandardDir, rBlackList );
+ mxImp = mpImp;
+
+ // the wildcard here is expected in form "*.extension"
+ ::rtl::OUString aWildcard;
+ if ( aExtName.indexOf( (sal_Unicode)'*' ) != 0 )
+ {
+ if ( aExtName.getLength() && aExtName.indexOf( (sal_Unicode)'.' ) != 0 )
+ aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*." ) );
+ else
+ aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*" ) );
+ }
+
+ aWildcard += aExtName;
+
+ ::rtl::OUString aUIString =
+ ::sfx2::addExtension( aFilterUIName, aWildcard, ( WB_OPEN == ( nFlags & WB_OPEN ) ), *mpImp );
+ AddFilter( aUIString, aWildcard );
+}
+
+// ------------------------------------------------------------------------
+FileDialogHelper::~FileDialogHelper()
+{
+ mpImp->dispose();
+ mxImp.clear();
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper::CreateMatcher( const String& rFactory )
+{
+ mpImp->createMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper::SetControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId )
+{
+ mpImp->setControlHelpIds( _pControlId, _pHelpId );
+}
+
+void FileDialogHelper::SetContext( Context _eNewContext )
+{
+ mpImp->SetContext( _eNewContext );
+}
+
+// ------------------------------------------------------------------------
+IMPL_LINK( FileDialogHelper, ExecuteSystemFilePicker, void*, EMPTYARG )
+{
+ m_nError = mpImp->execute();
+ if ( m_aDialogClosedLink.IsSet() )
+ m_aDialogClosedLink.Call( this );
+
+ return 0L;
+}
+
+// ------------------------------------------------------------------------
+// rDirPath has to be a directory
+ErrCode FileDialogHelper::Execute( SvStringsDtor*& rpURLList,
+ SfxItemSet *& rpSet,
+ String& rFilter,
+ const String& rDirPath )
+{
+ SetDisplayFolder( rDirPath );
+ return mpImp->execute( rpURLList, rpSet, rFilter );
+}
+
+
+// ------------------------------------------------------------------------
+ErrCode FileDialogHelper::Execute()
+{
+ return mpImp->execute();
+}
+
+// ------------------------------------------------------------------------
+ErrCode FileDialogHelper::Execute( SfxItemSet *& rpSet,
+ String& rFilter )
+{
+ ErrCode nRet;
+ SvStringsDtor* pURLList;
+
+ nRet = mpImp->execute( pURLList, rpSet, rFilter );
+
+ delete pURLList;
+
+ return nRet;
+}
+
+void FileDialogHelper::StartExecuteModal( const Link& rEndDialogHdl )
+{
+ m_aDialogClosedLink = rEndDialogHdl;
+ m_nError = ERRCODE_NONE;
+ if ( mpImp->isSystemFilePicker() )
+ Application::PostUserEvent( LINK( this, FileDialogHelper, ExecuteSystemFilePicker ) );
+ else
+ mpImp->implStartExecute();
+}
+
+// ------------------------------------------------------------------------
+
+short FileDialogHelper::GetDialogType() const
+{
+ return mpImp ? mpImp->m_nDialogType : 0;
+}
+
+// ------------------------------------------------------------------------
+
+sal_Bool FileDialogHelper::IsPasswordEnabled() const
+{
+ return mpImp ? mpImp->isPasswordEnabled() : sal_False;
+}
+
+// ------------------------------------------------------------------------
+
+String FileDialogHelper::GetRealFilter() const
+{
+ String sFilter;
+ if ( mpImp )
+ mpImp->getRealFilter( sFilter );
+ return sFilter;
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper::SetTitle( const String& rNewTitle )
+{
+ if ( mpImp->mxFileDlg.is() )
+ mpImp->mxFileDlg->setTitle( rNewTitle );
+}
+
+// ------------------------------------------------------------------------
+String FileDialogHelper::GetPath() const
+{
+ OUString aPath;
+
+ if ( mpImp->mlLastURLs.size() > 0)
+ return mpImp->mlLastURLs[0];
+
+ if ( mpImp->mxFileDlg.is() )
+ {
+ Sequence < OUString > aPathSeq = mpImp->mxFileDlg->getFiles();
+
+ if ( aPathSeq.getLength() == 1 )
+ {
+ aPath = aPathSeq[0];
+ }
+ }
+
+ return aPath;
+}
+
+// ------------------------------------------------------------------------
+Sequence < OUString > FileDialogHelper::GetMPath() const
+{
+ if ( mpImp->mlLastURLs.size() > 0)
+ return mpImp->mlLastURLs.getAsConstList();
+
+ if ( mpImp->mxFileDlg.is() )
+ return mpImp->mxFileDlg->getFiles();
+ else
+ {
+ Sequence < OUString > aEmpty;
+ return aEmpty;
+ }
+}
+
+// ------------------------------------------------------------------------
+Sequence< ::rtl::OUString > FileDialogHelper::GetSelectedFiles() const
+{
+ // a) the new way (optional!)
+ uno::Sequence< ::rtl::OUString > aResultSeq;
+ uno::Reference< XFilePicker2 > xPickNew(mpImp->mxFileDlg, UNO_QUERY);
+ if (xPickNew.is())
+ {
+ aResultSeq = xPickNew->getSelectedFiles();
+ }
+ // b) the olde way ... non optional.
+ else
+ {
+ uno::Reference< XFilePicker > xPickOld(mpImp->mxFileDlg, UNO_QUERY_THROW);
+ Sequence< OUString > lFiles = xPickOld->getFiles();
+ ::sal_Int32 nFiles = lFiles.getLength();
+ if ( nFiles > 1 )
+ {
+ aResultSeq = Sequence< ::rtl::OUString >( nFiles-1 );
+
+ INetURLObject aPath( lFiles[0] );
+ aPath.setFinalSlash();
+
+ for (::sal_Int32 i = 1; i < nFiles; i++)
+ {
+ if (i == 1)
+ aPath.Append( lFiles[i] );
+ else
+ aPath.setName( lFiles[i] );
+
+ aResultSeq[i-1] = ::rtl::OUString(aPath.GetMainURL( INetURLObject::NO_DECODE ));
+ }
+ }
+ else
+ aResultSeq = lFiles;
+ }
+
+ return aResultSeq;
+}
+
+// ------------------------------------------------------------------------
+String FileDialogHelper::GetDisplayDirectory() const
+{
+ return mpImp->getPath();
+}
+
+// ------------------------------------------------------------------------
+String FileDialogHelper::GetCurrentFilter() const
+{
+ return mpImp->getFilter();
+}
+
+// ------------------------------------------------------------------------
+ErrCode FileDialogHelper::GetGraphic( Graphic& rGraphic ) const
+{
+ return mpImp->getGraphic( rGraphic );
+}
+
+// ------------------------------------------------------------------------
+static int impl_isFolder( const OUString& rPath )
+{
+ uno::Reference< task::XInteractionHandler > xHandler;
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
+ xHandler.set( xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.task.InteractionHandler" ) ),
+ uno::UNO_QUERY_THROW );
+ }
+ catch ( Exception const & )
+ {
+ }
+
+ ::rtl::Reference< ::comphelper::StillReadWriteInteraction > aHandler = new ::comphelper::StillReadWriteInteraction( xHandler );
+
+ try
+ {
+ ::ucbhelper::Content aContent(
+ rPath, new ::ucbhelper::CommandEnvironment( static_cast< task::XInteractionHandler* > ( aHandler.get() ), uno::Reference< ucb::XProgressHandler >() ) );
+ if ( aContent.isFolder() )
+ return 1;
+
+ return 0;
+ }
+ catch ( Exception const & )
+ {
+ }
+
+ return -1;
+}
+
+void FileDialogHelper::SetDisplayDirectory( const String& _rPath )
+{
+ if ( !_rPath.Len() )
+ return;
+
+ // if the given path isn't a folder, we cut off the last part
+ // and take it as filename and the rest of the path should be
+ // the folder
+
+ INetURLObject aObj( _rPath );
+
+ ::rtl::OUString sFileName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET );
+ aObj.removeSegment();
+ ::rtl::OUString sPath = aObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ int nIsFolder = impl_isFolder( _rPath );
+ if ( nIsFolder == 0 ||
+ ( nIsFolder == -1 && impl_isFolder( sPath ) == 1 ) )
+ {
+ mpImp->setFileName( sFileName );
+ mpImp->displayFolder( sPath );
+ }
+ else
+ {
+ INetURLObject aObjPathName( _rPath );
+ ::rtl::OUString sFolder( aObjPathName.GetMainURL( INetURLObject::NO_DECODE ) );
+ if ( sFolder.getLength() == 0 )
+ {
+ // _rPath is not a valid path -> fallback to home directory
+ vos:: OSecurity aSecurity;
+ aSecurity.getHomeDir( sFolder );
+ }
+ mpImp->displayFolder( sFolder );
+ }
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper::SetDisplayFolder( const String& _rURL )
+{
+ mpImp->displayFolder( _rURL );
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper::SetFileName( const String& _rFileName )
+{
+ mpImp->setFileName( _rFileName );
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper::AddFilter( const String& rFilterName,
+ const String& rExtension )
+{
+ mpImp->addFilter( rFilterName, rExtension );
+}
+
+// ------------------------------------------------------------------------
+void FileDialogHelper::SetCurrentFilter( const String& rFilter )
+{
+ String sFilter( rFilter );
+ if ( mpImp->isShowFilterExtensionEnabled() )
+ sFilter = mpImp->getFilterWithExtension( rFilter );
+ mpImp->setFilter( sFilter );
+}
+
+// ------------------------------------------------------------------------
+uno::Reference < XFilePicker > FileDialogHelper::GetFilePicker() const
+{
+ return mpImp->mxFileDlg;
+}
+
+// ------------------------------------------------------------------------
+sal_Int16 FileDialogHelper::getDialogType( sal_Int64 nFlags ) const
+{
+ sal_Int16 nDialogType = FILEOPEN_SIMPLE;
+
+ if ( nFlags & WB_SAVEAS )
+ {
+ if ( nFlags & SFXWB_PASSWORD )
+ nDialogType = FILESAVE_AUTOEXTENSION_PASSWORD;
+ else
+ nDialogType = FILESAVE_SIMPLE;
+ }
+ else if ( nFlags & SFXWB_GRAPHIC )
+ {
+ if ( nFlags & SFXWB_SHOWSTYLES )
+ nDialogType = FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
+ else
+ nDialogType = FILEOPEN_LINK_PREVIEW;
+ }
+ else if ( SFXWB_INSERT != ( nFlags & SFXWB_INSERT ) )
+ nDialogType = FILEOPEN_READONLY_VERSION;
+
+ return nDialogType;
+}
+
+// ------------------------------------------------------------------------
+// XFilePickerListener Methods
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper::FileSelectionChanged( const FilePickerEvent& aEvent )
+{
+ mpImp->handleFileSelectionChanged( aEvent );
+}
+
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper::DirectoryChanged( const FilePickerEvent& aEvent )
+{
+ mpImp->handleDirectoryChanged( aEvent );
+}
+
+// ------------------------------------------------------------------------
+OUString SAL_CALL FileDialogHelper::HelpRequested( const FilePickerEvent& aEvent )
+{
+ return mpImp->handleHelpRequested( aEvent );
+}
+
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper::ControlStateChanged( const FilePickerEvent& aEvent )
+{
+ mpImp->handleControlStateChanged( aEvent );
+}
+
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper::DialogSizeChanged()
+{
+ mpImp->handleDialogSizeChanged();
+}
+
+// ------------------------------------------------------------------------
+void SAL_CALL FileDialogHelper::DialogClosed( const DialogClosedEvent& _rEvent )
+{
+ m_nError = ( RET_OK == _rEvent.DialogResult ) ? ERRCODE_NONE : ERRCODE_ABORT;
+ if ( m_aDialogClosedLink.IsSet() )
+ m_aDialogClosedLink.Call( this );
+}
+
+// ------------------------------------------------------------------------
+// ------------------------------------------------------------------------
+// ------------------------------------------------------------------------
+
+ErrCode FileOpenDialog_Impl( sal_Int64 nFlags,
+ const String& rFact,
+ SvStringsDtor *& rpURLList,
+ String& rFilter,
+ SfxItemSet *& rpSet,
+ const String* pPath,
+ sal_Int16 nDialog,
+ const String& rStandardDir,
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList )
+{
+ ErrCode nRet;
+ FileDialogHelper aDialog( nFlags, rFact, nDialog, 0, 0, rStandardDir, rBlackList );
+
+ String aPath;
+ if ( pPath )
+ aPath = *pPath;
+
+ nRet = aDialog.Execute( rpURLList, rpSet, rFilter, aPath );
+ DBG_ASSERT( rFilter.SearchAscii(": ") == STRING_NOTFOUND, "Old filter name used!");
+
+ return nRet;
+}
+
+
+// ------------------------------------------------------------------------
+String EncodeSpaces_Impl( const String& rSource )
+{
+ String sRet( rSource );
+ sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( " " ), DEFINE_CONST_UNICODE( "%20" ) );
+ return sRet;
+}
+
+// ------------------------------------------------------------------------
+String DecodeSpaces_Impl( const String& rSource )
+{
+ String sRet( rSource );
+ sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( "%20" ), DEFINE_CONST_UNICODE( " " ) );
+ return sRet;
+}
+
+// ------------------------------------------------------------------------
+
+} // end of namespace sfx2
+
diff --git a/sfx2/source/dialog/filedlghelper.src b/sfx2/source/dialog/filedlghelper.src
new file mode 100644
index 000000000000..61df13350510
--- /dev/null
+++ b/sfx2/source/dialog/filedlghelper.src
@@ -0,0 +1,173 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// includes ******************************************************************
+
+#include "sfxlocal.hrc"
+#include "filedlghelper.hrc"
+
+//#include "helpid.hrc"
+
+// strings *******************************************************************
+
+String STR_SFX_FILEDLG_ACTUALVERSION
+{
+ Text [ en-US ] = "Current version";
+};
+
+String STR_SFX_EXPLORERFILE_EXPORT
+{
+ Text [ en-US ] = "Export";
+};
+
+String STR_SFX_EXPLORERFILE_INSERT
+{
+ Text [ en-US ] = "Insert" ;
+};
+
+String STR_SFX_EXPLORERFILE_BUTTONINSERT
+{
+ Text [ en-US ] = "~Insert" ;
+};
+
+String STR_SFX_IMPORT_ALL
+{
+ Text [ en-US ] = "<All formats>" ;
+};
+
+String STR_CB_AUTO_EXTENSION
+{
+ Text [ en-US ] = "~Automatic file name extension" ;
+};
+
+String STR_CB_SELECTION
+{
+ Text [ en-US ] = "~Selection" ;
+};
+
+String STR_CB_INSERT_AS_LINK
+{
+ Text [ en-US ] = "~Link" ;
+};
+
+String STR_CB_SHOW_PREVIEW
+{
+ Text [ en-US ] = "Pr~eview" ;
+};
+
+String STR_CB_READONLY
+{
+ Text [ en-US ] = "~Read-only" ;
+};
+
+String STR_CB_PASSWORD
+{
+ Text [ en-US ] = "Save with ~password" ;
+};
+
+String STR_CB_FILTER_OPTIONS
+{
+ Text [ en-US ] = "Edit ~filter settings";
+};
+
+String STR_PB_PLAY
+{
+ Text [ en-US ] = "~Play" ;
+};
+
+String STR_PB_STOP
+{
+ Text [ en-US ] = "Sto~p" ;
+};
+
+String STR_PB_OPEN
+{
+ Text [ en-US ] = "~Open" ;
+};
+
+String STR_PB_SAVE
+{
+ Text [ en-US ] = "~Save" ;
+};
+
+String STR_LB_IMAGE_TEMPLATE
+{
+ Text [ en-US ] = "Style:" ;
+};
+
+String STR_LB_TEMPLATES
+{
+ Text [ en-US ] = "~Templates:" ;
+};
+
+String STR_LB_VERSION
+{
+ Text [ en-US ] = "~Version:";
+};
+
+//******************************************************************** EOF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/dialog/filedlgimpl.hxx b/sfx2/source/dialog/filedlgimpl.hxx
new file mode 100644
index 000000000000..91190b575e1c
--- /dev/null
+++ b/sfx2/source/dialog/filedlgimpl.hxx
@@ -0,0 +1,238 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_FILEDLGIMPL_HXX
+#define _SFX_FILEDLGIMPL_HXX
+
+#include <vcl/timer.hxx>
+#include <vcl/graph.hxx>
+#include <cppuhelper/implbase2.hxx>
+#include <com/sun/star/beans/StringPair.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
+#include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
+#include <sfx2/fcontnr.hxx>
+
+#define _SVSTDARR_STRINGSDTOR
+#include <svl/svstdarr.hxx>
+
+#include <sfx2/filedlghelper.hxx>
+#include <comphelper/sequenceasvector.hxx>
+
+class SfxFilterMatcher;
+class GraphicFilter;
+class FileDialogHelper;
+
+namespace sfx2
+{
+ typedef ::com::sun::star::beans::StringPair FilterPair;
+
+ class FileDialogHelper_Impl :
+ public ::cppu::WeakImplHelper2<
+ ::com::sun::star::ui::dialogs::XFilePickerListener,
+ ::com::sun::star::ui::dialogs::XDialogClosedListener >
+ {
+ friend class FileDialogHelper;
+
+ ::com::sun::star::uno::Reference < ::com::sun::star::ui::dialogs::XFilePicker > mxFileDlg;
+ ::com::sun::star::uno::Reference < ::com::sun::star::container::XNameAccess > mxFilterCFG;
+
+ std::vector< FilterPair > maFilters;
+
+ SfxFilterMatcher* mpMatcher;
+ GraphicFilter* mpGraphicFilter;
+ FileDialogHelper* mpAntiImpl;
+ Window* mpPreferredParentWindow;
+
+ ::comphelper::SequenceAsVector< ::rtl::OUString > mlLastURLs;
+
+ ::rtl::OUString maPath;
+ ::rtl::OUString maFileName;
+ ::rtl::OUString maCurFilter;
+ ::rtl::OUString maSelectFilter;
+ ::rtl::OUString maButtonLabel;
+
+ Timer maPreViewTimer;
+ Graphic maGraphic;
+
+ const short m_nDialogType;
+
+ SfxFilterFlags m_nMustFlags;
+ SfxFilterFlags m_nDontFlags;
+
+ ULONG mnPostUserEventId;
+
+ ErrCode mnError;
+
+ FileDialogHelper::Context meContext;
+
+ sal_Bool mbHasPassword : 1;
+ sal_Bool mbIsPwdEnabled : 1;
+ sal_Bool m_bHaveFilterOptions : 1;
+ sal_Bool mbHasVersions : 1;
+ sal_Bool mbHasAutoExt : 1;
+ sal_Bool mbHasLink : 1;
+ sal_Bool mbHasPreview : 1;
+ sal_Bool mbShowPreview : 1;
+ sal_Bool mbIsSaveDlg : 1;
+ sal_Bool mbExport : 1;
+
+ sal_Bool mbDeleteMatcher : 1;
+ sal_Bool mbInsert : 1;
+ sal_Bool mbSystemPicker : 1;
+ sal_Bool mbPwdCheckBoxState : 1;
+ sal_Bool mbSelection : 1;
+ sal_Bool mbSelectionEnabled : 1;
+ sal_Bool mbHasSelectionBox : 1;
+ sal_Bool mbSelectionFltrEnabled : 1;
+
+ private:
+ void addFilters( sal_Int64 nFlags,
+ const String& rFactory,
+ SfxFilterFlags nMust,
+ SfxFilterFlags nDont );
+ void addFilter( const ::rtl::OUString& rFilterName,
+ const ::rtl::OUString& rExtension );
+ void addGraphicFilter();
+ void enablePasswordBox( sal_Bool bInit );
+ void updateFilterOptionsBox();
+ void updateExportButton();
+ void updateSelectionBox();
+ void updateVersions();
+ void updatePreviewState( sal_Bool _bUpdatePreviewWindow = sal_True );
+ void dispose();
+
+ void loadConfig();
+ void saveConfig();
+
+ const SfxFilter* getCurentSfxFilter();
+ sal_Bool updateExtendedControl( sal_Int16 _nExtendedControlId, sal_Bool _bEnable );
+
+ ErrCode getGraphic( const ::rtl::OUString& rURL, Graphic& rGraphic ) const;
+ void setDefaultValues();
+
+ void preExecute();
+ void postExecute( sal_Int16 _nResult );
+ sal_Int16 implDoExecute();
+ void implStartExecute();
+
+ void correctVirtualDialogType();
+
+ void setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId );
+
+ sal_Bool CheckFilterOptionsCapability( const SfxFilter* _pFilter );
+
+ sal_Bool isInOpenMode() const;
+ String getCurrentFilterUIName() const;
+
+ void LoadLastUsedFilter( const ::rtl::OUString& _rContextIdentifier );
+ void SaveLastUsedFilter( const ::rtl::OUString& _rContextIdentifier );
+ void SaveLastUsedFilter( void );
+
+ void implInitializeFileName( );
+
+ void implGetAndCacheFiles( const ::com::sun::star::uno::Reference< XInterface >& xPicker ,
+ SvStringsDtor*& rpURLList,
+ const SfxFilter* pFilter );
+ String implEnsureURLExtension(const String& sURL ,
+ const String& sExtension);
+
+ DECL_LINK( TimeOutHdl_Impl, Timer* );
+ DECL_LINK( HandleEvent, FileDialogHelper* );
+ DECL_LINK( InitControls, void* );
+
+ public:
+ // XFilePickerListener methods
+ virtual void SAL_CALL fileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL directoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
+ virtual ::rtl::OUString SAL_CALL helpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL controlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL dialogSizeChanged() throw( ::com::sun::star::uno::RuntimeException );
+
+ // XDialogClosedListener methods
+ virtual void SAL_CALL dialogClosed( const ::com::sun::star::ui::dialogs::DialogClosedEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException);
+
+ // XEventListener methods
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException );
+
+ // handle XFilePickerListener events
+ void handleFileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
+ void handleDirectoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
+ ::rtl::OUString handleHelpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
+ void handleControlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
+ void handleDialogSizeChanged();
+
+ // Own methods
+ FileDialogHelper_Impl(
+ FileDialogHelper* _pAntiImpl,
+ const short nDialogType,
+ sal_Int64 nFlags,
+ sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG,
+ Window* _pPreferredParentWindow = NULL,
+ const String& sStandardDir = String::CreateFromAscii( "" ),
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList = ::com::sun::star::uno::Sequence< ::rtl::OUString >()
+ );
+ virtual ~FileDialogHelper_Impl();
+
+ ErrCode execute( SvStringsDtor*& rpURLList,
+ SfxItemSet *& rpSet,
+ String& rFilter );
+ ErrCode execute();
+
+ void setFilter( const ::rtl::OUString& rFilter );
+
+ /** sets the directory which should be browsed
+
+ <p>If the given path does not point to a valid (existent and accessible) folder, the request
+ is silently dropped</p>
+ */
+ void displayFolder( const ::rtl::OUString& rPath );
+ void setFileName( const ::rtl::OUString& _rFile );
+
+ ::rtl::OUString getPath() const;
+ ::rtl::OUString getFilter() const;
+ void getRealFilter( String& _rFilter ) const;
+
+ ErrCode getGraphic( Graphic& rGraphic ) const;
+ void createMatcher( const String& rFactory );
+
+ sal_Bool isShowFilterExtensionEnabled() const;
+ void addFilterPair( const ::rtl::OUString& rFilter,
+ const ::rtl::OUString& rFilterWithExtension );
+ ::rtl::OUString getFilterName( const ::rtl::OUString& rFilterWithExtension ) const;
+ ::rtl::OUString getFilterWithExtension( const ::rtl::OUString& rFilter ) const;
+
+ void SetContext( FileDialogHelper::Context _eNewContext );
+
+ inline sal_Bool isSystemFilePicker() const { return mbSystemPicker; }
+ inline sal_Bool isPasswordEnabled() const { return mbIsPwdEnabled; }
+ };
+
+} // end of namespace sfx2
+
+#endif // _SFX_FILEDLGIMPL_HXX
+
diff --git a/sfx2/source/dialog/filtergrouping.cxx b/sfx2/source/dialog/filtergrouping.cxx
new file mode 100644
index 000000000000..ab75d777c5ff
--- /dev/null
+++ b/sfx2/source/dialog/filtergrouping.cxx
@@ -0,0 +1,1274 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include "filtergrouping.hxx"
+#include <sfx2/fcontnr.hxx>
+#include <sfx2/filedlghelper.hxx>
+#include <sfx2/sfx.hrc>
+#include <sfx2/docfac.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <osl/thread.h>
+#include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
+#include <com/sun/star/beans/StringPair.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <unotools/confignode.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <tools/wldcrd.hxx>
+#include <tools/diagnose_ex.h>
+
+#include <list>
+#include <vector>
+#include <map>
+#include <algorithm>
+
+//........................................................................
+namespace sfx2
+{
+//........................................................................
+
+//#define DISABLE_GROUPING_AND_CLASSIFYING
+ // not using the functionallity herein, yet
+
+ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star::ui::dialogs;
+ using namespace ::com::sun::star::lang;
+ using namespace ::com::sun::star::beans;
+ using namespace ::utl;
+
+ //====================================================================
+ /**
+
+ Some general words about what's going on here ....
+
+ <p>In our file open dialog, usually we display every filter we know. That's how it was before: every filter
+ lead to an own line in the filter list box, e.g. "StarWriter 5.0 Dokument" or "Microsoft Word 97".</p>
+
+ <p>But then the PM came. And everything changed ....</p>
+
+ <p>A basic idea are groups: Why simply listing all the single filters? Couldn't we draw nice separators
+ between the filters which logically belong together? I.e. all the filters which open a document in StarWriter:
+ couldn't we separate them from all the filters which open the document in StarCalc?<br/>
+ So spoke the PM, and engineering obeyed.</p>
+
+ <p>So we have groups. They're just a visual aspect: All the filters of a group are presented together, separated
+ by a line from other groups.</p>
+
+ <p>Let's be honest: How the concrete implementation of the file picker service separates the different groups
+ is a matter of this implementation. We only do this grouping and suggest it to the FilePicker service ...</p>
+
+ <p>Now for the second concept:<br/>
+ Thinking about it (and that's what the PM did), both "StarWriter 5.0 Dokument" and "Microsoft Word 97"
+ describe a text document. It's a text. It's of no interest for the user that one of the texts was saved in
+ MS' format, and one in our own format.<br/>
+ So in a first step, we want to have a filter entry "Text documents". This would cover both above-mentioned
+ filters, as well as any other filters for documents which are texts.</p>
+
+ <p>Such an entry as "Text documents" is - within the scope of this file - called "class" or "filter class".</p>
+
+ <p>In the file-open-dialog, such a class looks like an ordinary filter: it's simply a name in the filter
+ listbox. Selecting means that all the files matching one of the "sub-filters" are displayed (in the example above,
+ this would be "*.sdw", "*.doc" and so on).</p>
+
+ <p>Now there are two types of filter classes: global ones and local ones. "Text documents" is a global class. As
+ well as "Spreadsheets". Or "Web pages".<br/>
+ Let's have a look at a local class: The filters "MS Word 95" and "MS WinWord 6.0" together form the class
+ "Microsoft Word 6.0 / 95" (don't ask for the reasons. At least not me. Ask the PM). There are a lot of such
+ local classes ...</p>
+
+ <p>The difference between global and local classes is as follows: Global classes are presented in an own group.
+ There is one dedicated group at the top of the list, containing all the global groups - no local groups and no
+ single filters.</p>
+
+ <p>Ehm - it was a lie. Not really at the top. Before this group, there is this single "All files" entry. It forms
+ it's own group. But this is uninteresting here.</p>
+
+ <p>Local classes must consist of filters which - without the classification - would all belong to the same group.
+ Then, they're combined to one entry (in the example above: "Microsoft Word 6.0 / 95"), and this entry is inserted
+ into the file picker filter list, instead of the single filters which form the class.</p>
+
+ <p>This is an interesting difference between local and global classes: Filters which are part of a global class
+ are listed in there own group, too. Filters in local classes aren't listed a second time - neither directly (as
+ the filter itself) nor indirectly (as part of another local group).</p>
+
+ <p>The only exception are filters which are part of a global class <em>and</em> a local class. This is allowed.
+ Beeing cotained in two local classes isn't.</p>
+
+ <p>So that's all what you need to know: Understand the concept of "filter classes" (a filter class combines
+ different filters and acts as if it's a filter itself) and the concept of groups (a group just describes a
+ logical correlation of filters and usually is represented to the user by drawing group separators in the filter
+ list).</p>
+
+ <p>If you got it, go try understanding this file :).</p>
+
+ */
+
+
+ //====================================================================
+
+ typedef StringPair FilterDescriptor; // a single filter or a filter class (display name and filter mask)
+ typedef ::std::list< FilterDescriptor > FilterGroup; // a list of single filter entries
+ typedef ::std::list< FilterGroup > GroupedFilterList; // a list of all filters, already grouped
+
+ /// the logical name of a filter
+ typedef ::rtl::OUString FilterName;
+
+ // a struct which holds references from a logical filter name to a filter group entry
+ // used for quick lookup of classes (means class entries - entries representing a class)
+ // which a given filter may belong to
+ typedef ::std::map< ::rtl::OUString, FilterGroup::iterator > FilterGroupEntryReferrer;
+
+ /// a descriptor for a filter class (which in the final dialog is represented by one filter entry)
+ typedef struct _tagFilterClass
+ {
+ ::rtl::OUString sDisplayName; // the display name
+ Sequence< FilterName > aSubFilters; // the (logical) names of the filter which belong to the class
+ } FilterClass;
+
+ typedef ::std::list< FilterClass > FilterClassList;
+ typedef ::std::map< ::rtl::OUString, FilterClassList::iterator > FilterClassReferrer;
+
+ typedef ::std::vector< ::rtl::OUString > StringArray;
+
+// =======================================================================
+// = reading of configuration data
+// =======================================================================
+
+ //--------------------------------------------------------------------
+ void lcl_ReadFilterClass( const OConfigurationNode& _rClassesNode, const ::rtl::OUString& _rLogicalClassName,
+ FilterClass& /* [out] */ _rClass )
+ {
+ static const ::rtl::OUString sDisplaNameNodeName( RTL_CONSTASCII_USTRINGPARAM( "DisplayName" ) );
+ static const ::rtl::OUString sSubFiltersNodeName( RTL_CONSTASCII_USTRINGPARAM( "Filters" ) );
+
+ // the description node for the current class
+ OConfigurationNode aClassDesc = _rClassesNode.openNode( _rLogicalClassName );
+
+ // the values
+ aClassDesc.getNodeValue( sDisplaNameNodeName ) >>= _rClass.sDisplayName;
+ aClassDesc.getNodeValue( sSubFiltersNodeName ) >>= _rClass.aSubFilters;
+ }
+
+ //--------------------------------------------------------------------
+ struct CreateEmptyClassRememberPos : public ::std::unary_function< FilterName, void >
+ {
+ protected:
+ FilterClassList& m_rClassList;
+ FilterClassReferrer& m_rClassesReferrer;
+
+ public:
+ CreateEmptyClassRememberPos( FilterClassList& _rClassList, FilterClassReferrer& _rClassesReferrer )
+ :m_rClassList ( _rClassList )
+ ,m_rClassesReferrer ( _rClassesReferrer )
+ {
+ }
+
+ // operate on a single class name
+ void operator() ( const FilterName& _rLogicalFilterName )
+ {
+ // insert a new (empty) class
+ m_rClassList.push_back( FilterClass() );
+ // get the position of this new entry
+ FilterClassList::iterator aInsertPos = m_rClassList.end();
+ --aInsertPos;
+ // remember this position
+ m_rClassesReferrer.insert( FilterClassReferrer::value_type( _rLogicalFilterName, aInsertPos ) );
+ }
+ };
+
+ //--------------------------------------------------------------------
+ struct ReadGlobalFilter : public ::std::unary_function< FilterName, void >
+ {
+ protected:
+ OConfigurationNode m_aClassesNode;
+ FilterClassReferrer& m_aClassReferrer;
+
+ public:
+ ReadGlobalFilter( const OConfigurationNode& _rClassesNode, FilterClassReferrer& _rClassesReferrer )
+ :m_aClassesNode ( _rClassesNode )
+ ,m_aClassReferrer ( _rClassesReferrer )
+ {
+ }
+
+ // operate on a single logical name
+ void operator() ( const FilterName& _rName )
+ {
+ FilterClassReferrer::iterator aClassRef = m_aClassReferrer.find( _rName );
+ if ( m_aClassReferrer.end() == aClassRef )
+ {
+ // we do not know this global class
+ DBG_ERROR( "ReadGlobalFilter::operator(): unknown filter name!" );
+ // TODO: perhaps we should be more tolerant - at the moment, the filter is dropped
+ // We could silently push_back it to the container ....
+ }
+ else
+ {
+ // read the data of this class into the node referred to by aClassRef
+ lcl_ReadFilterClass( m_aClassesNode, _rName, *aClassRef->second );
+ }
+ }
+ };
+
+ //--------------------------------------------------------------------
+ void lcl_ReadGlobalFilters( const OConfigurationNode& _rFilterClassification, FilterClassList& _rGlobalClasses, StringArray& _rGlobalClassNames )
+ {
+ _rGlobalClasses.clear();
+ _rGlobalClassNames.clear();
+
+ //================================================================
+ // get the list describing the order of all global classes
+ Sequence< ::rtl::OUString > aGlobalClasses;
+ _rFilterClassification.getNodeValue( DEFINE_CONST_OUSTRING( "GlobalFilters/Order" ) ) >>= aGlobalClasses;
+
+ const ::rtl::OUString* pNames = aGlobalClasses.getConstArray();
+ const ::rtl::OUString* pNamesEnd = pNames + aGlobalClasses.getLength();
+
+ // copy the logical names
+ _rGlobalClassNames.resize( aGlobalClasses.getLength() );
+ ::std::copy( pNames, pNamesEnd, _rGlobalClassNames.begin() );
+
+ // Global classes are presented in an own group, so their order matters (while the order of the
+ // "local classes" doesn't).
+ // That's why we can't simply add the global classes to _rGlobalClasses using the order in which they
+ // are returned from the configuration - it is completely undefined, and we need a _defined_ order.
+ FilterClassReferrer aClassReferrer;
+ ::std::for_each(
+ pNames,
+ pNamesEnd,
+ CreateEmptyClassRememberPos( _rGlobalClasses, aClassReferrer )
+ );
+ // now _rGlobalClasses contains a dummy entry for each global class,
+ // while aClassReferrer maps from the logical name of the class to the position within _rGlobalClasses where
+ // it's dummy entry resides
+
+ //================================================================
+ // go for all the single class entries
+ OConfigurationNode aFilterClassesNode =
+ _rFilterClassification.openNode( DEFINE_CONST_OUSTRING( "GlobalFilters/Classes" ) );
+ Sequence< ::rtl::OUString > aFilterClasses = aFilterClassesNode.getNodeNames();
+ ::std::for_each(
+ aFilterClasses.getConstArray(),
+ aFilterClasses.getConstArray() + aFilterClasses.getLength(),
+ ReadGlobalFilter( aFilterClassesNode, aClassReferrer )
+ );
+ }
+
+ //--------------------------------------------------------------------
+ struct ReadLocalFilter : public ::std::unary_function< FilterName, void >
+ {
+ protected:
+ OConfigurationNode m_aClassesNode;
+ FilterClassList& m_rClasses;
+
+ public:
+ ReadLocalFilter( const OConfigurationNode& _rClassesNode, FilterClassList& _rClasses )
+ :m_aClassesNode ( _rClassesNode )
+ ,m_rClasses ( _rClasses )
+ {
+ }
+
+ // operate on a single logical name
+ void operator() ( const FilterName& _rName )
+ {
+ // read the data for this class
+ FilterClass aClass;
+ lcl_ReadFilterClass( m_aClassesNode, _rName, aClass );
+
+ // insert the class descriptor
+ m_rClasses.push_back( aClass );
+ }
+ };
+
+ //--------------------------------------------------------------------
+ void lcl_ReadLocalFilters( const OConfigurationNode& _rFilterClassification, FilterClassList& _rLocalClasses )
+ {
+ _rLocalClasses.clear();
+
+ // the node for the local classes
+ OConfigurationNode aFilterClassesNode =
+ _rFilterClassification.openNode( DEFINE_CONST_OUSTRING( "LocalFilters/Classes" ) );
+ Sequence< ::rtl::OUString > aFilterClasses = aFilterClassesNode.getNodeNames();
+
+ ::std::for_each(
+ aFilterClasses.getConstArray(),
+ aFilterClasses.getConstArray() + aFilterClasses.getLength(),
+ ReadLocalFilter( aFilterClassesNode, _rLocalClasses )
+ );
+ }
+
+ //--------------------------------------------------------------------
+ void lcl_ReadClassification( FilterClassList& _rGlobalClasses, StringArray& _rGlobalClassNames, FilterClassList& _rLocalClasses )
+ {
+ //================================================================
+ // open our config node
+ OConfigurationTreeRoot aFilterClassification = OConfigurationTreeRoot::createWithServiceFactory(
+ ::comphelper::getProcessServiceFactory(),
+ DEFINE_CONST_OUSTRING( "org.openoffice.Office.UI/FilterClassification" ),
+ -1,
+ OConfigurationTreeRoot::CM_READONLY
+ );
+
+ //================================================================
+ // go for the global classes
+ lcl_ReadGlobalFilters( aFilterClassification, _rGlobalClasses, _rGlobalClassNames );
+
+ //================================================================
+ // fo for the local classes
+ lcl_ReadLocalFilters( aFilterClassification, _rLocalClasses );
+
+ }
+
+// =======================================================================
+// = grouping and classifying
+// =======================================================================
+
+ //--------------------------------------------------------------------
+ // a struct which adds helps remembering a reference to a class entry
+ struct ReferToFilterEntry : public ::std::unary_function< FilterName, void >
+ {
+ protected:
+ FilterGroupEntryReferrer& m_rEntryReferrer;
+ FilterGroup::iterator m_aClassPos;
+
+ public:
+ ReferToFilterEntry( FilterGroupEntryReferrer& _rEntryReferrer, const FilterGroup::iterator& _rClassPos )
+ :m_rEntryReferrer( _rEntryReferrer )
+ ,m_aClassPos( _rClassPos )
+ {
+ }
+
+ // operate on a single filter name
+ void operator() ( const FilterName& _rName )
+ {
+#ifdef DBG_UTIL
+ ::std::pair< FilterGroupEntryReferrer::iterator, bool > aInsertRes =
+#endif
+ m_rEntryReferrer.insert( FilterGroupEntryReferrer::value_type( _rName, m_aClassPos ) );
+ DBG_ASSERT( aInsertRes.second, "ReferToFilterEntry::operator(): already have an element for this name!" );
+ }
+ };
+
+ //--------------------------------------------------------------------
+ struct FillClassGroup : public ::std::unary_function< FilterClass, void >
+ {
+ protected:
+ FilterGroup& m_rClassGroup;
+ FilterGroupEntryReferrer& m_rClassReferrer;
+
+ public:
+ FillClassGroup( FilterGroup& _rClassGroup, FilterGroupEntryReferrer& _rClassReferrer )
+ :m_rClassGroup ( _rClassGroup )
+ ,m_rClassReferrer ( _rClassReferrer )
+ {
+ }
+
+ // operate on a single class
+ void operator() ( const FilterClass& _rClass )
+ {
+ // create an empty filter descriptor for the class
+ FilterDescriptor aClassEntry;
+ // set it's name (which is all we know by now)
+ aClassEntry.First = _rClass.sDisplayName;
+
+ // add it to the group
+ m_rClassGroup.push_back( aClassEntry );
+ // the position of the newly added class
+ FilterGroup::iterator aClassEntryPos = m_rClassGroup.end();
+ --aClassEntryPos;
+
+ // and for all the sub filters of the class, remember the class
+ // (respectively the position of the class it the group)
+ ::std::for_each(
+ _rClass.aSubFilters.getConstArray(),
+ _rClass.aSubFilters.getConstArray() + _rClass.aSubFilters.getLength(),
+ ReferToFilterEntry( m_rClassReferrer, aClassEntryPos )
+ );
+ }
+ };
+
+ //--------------------------------------------------------------------
+ static const sal_Unicode s_cWildcardSeparator( ';' );
+
+ //====================================================================
+ const ::rtl::OUString& getSeparatorString()
+ {
+ static ::rtl::OUString s_sSeparatorString( &s_cWildcardSeparator, 1 );
+ return s_sSeparatorString;
+ }
+
+ //====================================================================
+ struct CheckAppendSingleWildcard : public ::std::unary_function< ::rtl::OUString, void >
+ {
+ ::rtl::OUString& _rToBeExtended;
+
+ CheckAppendSingleWildcard( ::rtl::OUString& _rBase ) : _rToBeExtended( _rBase ) { }
+
+ void operator() ( const ::rtl::OUString& _rWC )
+ {
+ // check for double wildcards
+ sal_Int32 nExistentPos = _rToBeExtended.indexOf( _rWC );
+ if ( -1 < nExistentPos )
+ { // found this wildcard (already part of _rToBeExtended)
+ const sal_Unicode* pBuffer = _rToBeExtended.getStr();
+ if ( ( 0 == nExistentPos )
+ || ( s_cWildcardSeparator == pBuffer[ nExistentPos - 1 ] )
+ )
+ { // the wildcard really starts at this position (it starts at pos 0 or the previous character is a separator
+ sal_Int32 nExistentWCEnd = nExistentPos + _rWC.getLength();
+ if ( ( _rToBeExtended.getLength() == nExistentWCEnd )
+ || ( s_cWildcardSeparator == pBuffer[ nExistentWCEnd ] )
+ )
+ { // it's really the complete wildcard we found
+ // (not something like _rWC beeing "*.t" and _rToBeExtended containing "*.txt")
+ // -> outta here
+ return;
+ }
+ }
+ }
+
+ if ( _rToBeExtended.getLength() )
+ _rToBeExtended += getSeparatorString();
+ _rToBeExtended += _rWC;
+ }
+ };
+
+ //====================================================================
+ // a helper struct which adds a fixed (Sfx-)filter to a filter group entry given by iterator
+ struct AppendWildcardToDescriptor : public ::std::unary_function< FilterGroupEntryReferrer::value_type, void >
+ {
+ protected:
+ ::std::vector< ::rtl::OUString > aWildCards;
+
+ public:
+ AppendWildcardToDescriptor( const String& _rWildCard );
+
+ // operate on a single class entry
+ void operator() ( const FilterGroupEntryReferrer::value_type& _rClassReference )
+ {
+ // simply add our wildcards
+ ::std::for_each(
+ aWildCards.begin(),
+ aWildCards.end(),
+ CheckAppendSingleWildcard( _rClassReference.second->Second )
+ );
+ }
+ };
+
+ //====================================================================
+ AppendWildcardToDescriptor::AppendWildcardToDescriptor( const String& _rWildCard )
+ {
+ DBG_ASSERT( _rWildCard.Len(),
+ "AppendWildcardToDescriptor::AppendWildcardToDescriptor: invalid wildcard!" );
+ DBG_ASSERT( _rWildCard.GetBuffer()[0] != s_cWildcardSeparator,
+ "AppendWildcardToDescriptor::AppendWildcardToDescriptor: wildcard already separated!" );
+
+ aWildCards.reserve( _rWildCard.GetTokenCount( s_cWildcardSeparator ) );
+
+ const sal_Unicode* pTokenLoop = _rWildCard.GetBuffer();
+ const sal_Unicode* pTokenLoopEnd = pTokenLoop + _rWildCard.Len();
+ const sal_Unicode* pTokenStart = pTokenLoop;
+ for ( ; pTokenLoop != pTokenLoopEnd; ++pTokenLoop )
+ {
+ if ( ( s_cWildcardSeparator == *pTokenLoop ) && ( pTokenLoop > pTokenStart ) )
+ { // found a new token separator (and a non-empty token)
+ aWildCards.push_back( ::rtl::OUString( pTokenStart, pTokenLoop - pTokenStart ) );
+
+ // search the start of the next token
+ while ( ( pTokenStart != pTokenLoopEnd ) && ( *pTokenStart != s_cWildcardSeparator ) )
+ ++pTokenStart;
+
+ if ( pTokenStart == pTokenLoopEnd )
+ // reached the end
+ break;
+
+ ++pTokenStart;
+ pTokenLoop = pTokenStart;
+ }
+ }
+ if ( pTokenLoop > pTokenStart )
+ // the last one ....
+ aWildCards.push_back( ::rtl::OUString( pTokenStart, pTokenLoop - pTokenStart ) );
+ }
+
+ //--------------------------------------------------------------------
+ void lcl_InitGlobalClasses( GroupedFilterList& _rAllFilters, const FilterClassList& _rGlobalClasses, FilterGroupEntryReferrer& _rGlobalClassesRef )
+ {
+ // we need an extra group in our "all filters" container
+ _rAllFilters.push_front( FilterGroup() );
+ FilterGroup& rGlobalFilters = _rAllFilters.front();
+ // it's important to work on the reference: we want to access the members of this filter group
+ // by an iterator (FilterGroup::const_iterator)
+ // the referrer for the global classes
+
+ // initialize the group
+ ::std::for_each(
+ _rGlobalClasses.begin(),
+ _rGlobalClasses.end(),
+ FillClassGroup( rGlobalFilters, _rGlobalClassesRef )
+ );
+ // now we have:
+ // in rGlobalFilters: a list of FilterDescriptor's, where each's discriptor's display name is set to the name of a class
+ // in aGlobalClassesRef: a mapping from logical filter names to positions within rGlobalFilters
+ // this way, if we encounter an arbitrary filter, we can easily (and efficient) check if it belongs to a global class
+ // and modify the descriptor for this class accordingly
+ }
+
+ //--------------------------------------------------------------------
+ typedef ::std::vector< ::std::pair< FilterGroupEntryReferrer::mapped_type, FilterGroup::iterator > >
+ MapGroupEntry2GroupEntry;
+ // this is not really a map - it's just called this way because it is used as a map
+
+ struct FindGroupEntry : public ::std::unary_function< MapGroupEntry2GroupEntry::value_type, sal_Bool >
+ {
+ FilterGroupEntryReferrer::mapped_type aLookingFor;
+ FindGroupEntry( FilterGroupEntryReferrer::mapped_type _rLookingFor ) : aLookingFor( _rLookingFor ) { }
+
+ sal_Bool operator() ( const MapGroupEntry2GroupEntry::value_type& _rMapEntry )
+ {
+ return _rMapEntry.first == aLookingFor ? sal_True : sal_False;
+ }
+ };
+
+ struct CopyGroupEntryContent : public ::std::unary_function< MapGroupEntry2GroupEntry::value_type, void >
+ {
+ void operator() ( const MapGroupEntry2GroupEntry::value_type& _rMapEntry )
+ {
+#ifdef DBG_UTIL
+ FilterDescriptor aHaveALook = *_rMapEntry.first;
+#endif
+ *_rMapEntry.second = *_rMapEntry.first;
+ }
+ };
+
+ //--------------------------------------------------------------------
+ struct CopyNonEmptyFilter : public ::std::unary_function< FilterDescriptor, void >
+ {
+ FilterGroup& rTarget;
+ CopyNonEmptyFilter( FilterGroup& _rTarget ) :rTarget( _rTarget ) { }
+
+ void operator() ( const FilterDescriptor& _rFilter )
+ {
+ if ( _rFilter.Second.getLength() )
+ rTarget.push_back( _rFilter );
+ }
+ };
+
+ //--------------------------------------------------------------------
+ void lcl_GroupAndClassify( TSortedFilterList& _rFilterMatcher, GroupedFilterList& _rAllFilters )
+ {
+ _rAllFilters.clear();
+
+ // ===============================================================
+ // read the classification of filters
+ FilterClassList aGlobalClasses, aLocalClasses;
+ StringArray aGlobalClassNames;
+ lcl_ReadClassification( aGlobalClasses, aGlobalClassNames, aLocalClasses );
+
+ // ===============================================================
+ // for the global filter classes
+ FilterGroupEntryReferrer aGlobalClassesRef;
+ lcl_InitGlobalClasses( _rAllFilters, aGlobalClasses, aGlobalClassesRef );
+
+ // insert as much placeholders (FilterGroup's) into _rAllFilter for groups as we have global classes
+ // (this assumes that both numbers are the same, which, speaking strictly, must not hold - but it does, as we know ...)
+ sal_Int32 nGlobalClasses = aGlobalClasses.size();
+ while ( nGlobalClasses-- )
+ _rAllFilters.push_back( FilterGroup() );
+
+ // ===============================================================
+ // for the local classes:
+ // if n filters belong to a local class, they do not appear in their respective group explicitly, instead
+ // and entry for the class is added to the group and the extensions of the filters are collected under
+ // this entry
+ FilterGroupEntryReferrer aLocalClassesRef;
+ FilterGroup aCollectedLocals;
+ ::std::for_each(
+ aLocalClasses.begin(),
+ aLocalClasses.end(),
+ FillClassGroup( aCollectedLocals, aLocalClassesRef )
+ );
+ // to map from the position within aCollectedLocals to positions within the real groups
+ // (where they finally belong to)
+ MapGroupEntry2GroupEntry aLocalFinalPositions;
+
+ // ===============================================================
+ // now add the filters
+ // the group which we currently work with
+ GroupedFilterList::iterator aCurrentGroup = _rAllFilters.end(); // no current group
+ // the filter container of the current group - if this changes between two filters, a new group is reached
+ String aCurrentServiceName;
+
+ String sFilterWildcard;
+ ::rtl::OUString sFilterName;
+ // loop through all the filters
+ for ( const SfxFilter* pFilter = _rFilterMatcher.First(); pFilter; pFilter = _rFilterMatcher.Next() )
+ {
+ sFilterName = pFilter->GetFilterName();
+ sFilterWildcard = pFilter->GetWildcard().GetWildCard();
+ AppendWildcardToDescriptor aExtendWildcard( sFilterWildcard );
+
+ DBG_ASSERT( sFilterWildcard.Len(), "sfx2::lcl_GroupAndClassify: invalid wildcard of this filter!" );
+
+ // ===========================================================
+ // check for a change in the group
+ String aServiceName = pFilter->GetServiceName();
+ if ( aServiceName != aCurrentServiceName )
+ { // we reached a new group
+
+ ::rtl::OUString sDocServName = aServiceName;
+
+ // look for the place in _rAllFilters where this ne group belongs - this is determined
+ // by the order of classes in aGlobalClassNames
+ GroupedFilterList::iterator aGroupPos = _rAllFilters.begin();
+ DBG_ASSERT( aGroupPos != _rAllFilters.end(),
+ "sfx2::lcl_GroupAndClassify: invalid all-filters array here!" );
+ // the loop below will work on invalid objects else ...
+ ++aGroupPos;
+ StringArray::iterator aGlobalIter = aGlobalClassNames.begin();
+ while ( ( aGroupPos != _rAllFilters.end() )
+ && ( aGlobalIter != aGlobalClassNames.end() )
+ && ( *aGlobalIter != sDocServName )
+ )
+ {
+ ++aGlobalIter;
+ ++aGroupPos;
+ }
+ if ( aGroupPos != _rAllFilters.end() )
+ // we found a global class name which matchies the doc service name -> fill the filters of this
+ // group in the respective prepared group
+ aCurrentGroup = aGroupPos;
+ else
+ // insert a new entry in our overall-list
+ aCurrentGroup = _rAllFilters.insert( _rAllFilters.end(), FilterGroup() );
+
+ // remember the container to properly detect the next group
+ aCurrentServiceName = aServiceName;
+ }
+
+ DBG_ASSERT( aCurrentGroup != _rAllFilters.end(), "sfx2::lcl_GroupAndClassify: invalid current group!" );
+
+ // ===========================================================
+ // check if the filter is part of a global group
+ ::std::pair< FilterGroupEntryReferrer::iterator, FilterGroupEntryReferrer::iterator >
+ aBelongsTo = aGlobalClassesRef.equal_range( sFilterName );
+ // add the filter to the entries for these classes
+ // (if they exist - if not, the range is empty and the for_each is a no-op)
+ ::std::for_each(
+ aBelongsTo.first,
+ aBelongsTo.second,
+ aExtendWildcard
+ );
+
+ // ===========================================================
+ // add the filter to it's group
+
+ // for this, check if the filter is part of a local filter
+ FilterGroupEntryReferrer::iterator aBelongsToLocal = aLocalClassesRef.find( sFilterName );
+ if ( aLocalClassesRef.end() != aBelongsToLocal )
+ {
+/*
+#ifdef DBG_UTIL
+ const ::rtl::OUString& rLocalClassDisplayName = aBelongsToLocal->second->First;
+ const ::rtl::OUString& rLocalClassExtension = aBelongsToLocal->second->Second;
+#endif
+*/
+ // okay, there is a local class which the filter belongs to
+ // -> append the wildcard
+ aExtendWildcard( *aBelongsToLocal );
+
+ MapGroupEntry2GroupEntry::iterator aThisGroupFinalPos =
+ ::std::find_if( aLocalFinalPositions.begin(), aLocalFinalPositions.end(), FindGroupEntry( aBelongsToLocal->second ) );
+
+ if ( aLocalFinalPositions.end() == aThisGroupFinalPos )
+ { // the position within aCollectedLocals has not been mapped to a final position
+ // within the "real" group (aCollectedLocals is only temporary)
+ // -> do this now (as we just encountered the first filter belonging to this local class
+ // add a new entry which is the "real" group entry
+ aCurrentGroup->push_back( FilterDescriptor( aBelongsToLocal->second->First, String() ) );
+ // the position where we inserted the entry
+ FilterGroup::iterator aInsertPos = aCurrentGroup->end();
+ --aInsertPos;
+ // remember this pos
+ aLocalFinalPositions.push_back( MapGroupEntry2GroupEntry::value_type( aBelongsToLocal->second, aInsertPos ) );
+ }
+ }
+ else
+ aCurrentGroup->push_back( FilterDescriptor( pFilter->GetUIName(), sFilterWildcard ) );
+ }
+
+ // now just complete the infos for the local groups:
+ // During the above loop, they have been collected in aCollectedLocals, but this is only temporary
+ // They have to be copied into their final positions (which are stored in aLocalFinalPositions)
+ ::std::for_each(
+ aLocalFinalPositions.begin(),
+ aLocalFinalPositions.end(),
+ CopyGroupEntryContent()
+ );
+
+ // and remove local groups which do not apply - e.g. have no entries due to the limited content of the
+ // current SfxFilterMatcherIter
+
+ FilterGroup& rGlobalFilters = _rAllFilters.front();
+ FilterGroup aNonEmptyGlobalFilters;
+ ::std::for_each(
+ rGlobalFilters.begin(),
+ rGlobalFilters.end(),
+ CopyNonEmptyFilter( aNonEmptyGlobalFilters )
+ );
+ rGlobalFilters.swap( aNonEmptyGlobalFilters );
+ }
+
+ //--------------------------------------------------------------------
+ struct AppendFilter : public ::std::unary_function< FilterDescriptor, void >
+ {
+ protected:
+ Reference< XFilterManager > m_xFilterManager;
+ FileDialogHelper_Impl* m_pFileDlgImpl;
+ bool m_bAddExtension;
+
+ public:
+ AppendFilter( const Reference< XFilterManager >& _rxFilterManager,
+ FileDialogHelper_Impl* _pImpl, bool _bAddExtension ) :
+
+ m_xFilterManager( _rxFilterManager ),
+ m_pFileDlgImpl ( _pImpl ),
+ m_bAddExtension ( _bAddExtension )
+
+ {
+ DBG_ASSERT( m_xFilterManager.is(), "AppendFilter::AppendFilter: invalid filter manager!" );
+ DBG_ASSERT( m_pFileDlgImpl, "AppendFilter::AppendFilter: invalid filedlg impl!" );
+ }
+
+ // operate on a single filter
+ void operator() ( const FilterDescriptor& _rFilterEntry )
+ {
+ String sDisplayText = m_bAddExtension
+ ? addExtension( _rFilterEntry.First, _rFilterEntry.Second, sal_True, *m_pFileDlgImpl )
+ : _rFilterEntry.First;
+ m_xFilterManager->appendFilter( sDisplayText, _rFilterEntry.Second );
+ }
+ };
+
+// =======================================================================
+// = handling for the "all files" entry
+// =======================================================================
+
+ //--------------------------------------------------------------------
+ sal_Bool lcl_hasAllFilesFilter( TSortedFilterList& _rFilterMatcher, String& /* [out] */ _rAllFilterName )
+ {
+ ::rtl::OUString sUIName;
+ sal_Bool bHasAll = sal_False;
+ _rAllFilterName = String( SfxResId( STR_SFX_FILTERNAME_ALL ) );
+
+ // ===============================================================
+ // check if there's already a filter <ALL>
+ for ( const SfxFilter* pFilter = _rFilterMatcher.First(); pFilter && !bHasAll; pFilter = _rFilterMatcher.Next() )
+ {
+ if ( pFilter->GetUIName() == _rAllFilterName )
+ bHasAll = sal_True;
+ }
+ return bHasAll;
+ }
+
+ //--------------------------------------------------------------------
+ void lcl_EnsureAllFilesEntry( TSortedFilterList& _rFilterMatcher, GroupedFilterList& _rFilters )
+ {
+ // ===============================================================
+ String sAllFilterName;
+ if ( !lcl_hasAllFilesFilter( _rFilterMatcher, sAllFilterName ) )
+ {
+ // get the first group of filters (by definition, this group contains the global classes)
+ DBG_ASSERT( !_rFilters.empty(), "lcl_EnsureAllFilesEntry: invalid filter list!" );
+ if ( !_rFilters.empty() )
+ {
+ FilterGroup& rGlobalClasses = *_rFilters.begin();
+ rGlobalClasses.push_front( FilterDescriptor( sAllFilterName, DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ) ) );
+ }
+ }
+ }
+
+#ifdef DISABLE_GROUPING_AND_CLASSIFYING
+ //--------------------------------------------------------------------
+ void lcl_EnsureAllFilesEntry( TSortedFilterList& _rFilterMatcher, const Reference< XFilterManager >& _rxFilterManager, ::rtl::OUString& _rFirstNonEmpty )
+ {
+ // ===============================================================
+ String sAllFilterName;
+ if ( !lcl_hasAllFilesFilter( _rFilterMatcher, sAllFilterName ) )
+ {
+ try
+ {
+ _rxFilterManager->appendFilter( sAllFilterName, DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ) );
+ _rFirstNonEmpty = sAllFilterName;
+ }
+ catch( const IllegalArgumentException& )
+ {
+#ifdef DBG_UTIL
+ ByteString aMsg( "sfx2::lcl_EnsureAllFilesEntry: could not append Filter" );
+ aMsg += ByteString( String( sAllFilterName ), RTL_TEXTENCODING_UTF8 );
+ DBG_ERROR( aMsg.GetBuffer() );
+#endif
+ }
+ }
+
+ }
+#endif
+
+// =======================================================================
+// = filling an XFilterManager
+// =======================================================================
+
+ //--------------------------------------------------------------------
+ struct AppendFilterGroup : public ::std::unary_function< FilterGroup, void >
+ {
+ protected:
+ Reference< XFilterManager > m_xFilterManager;
+ Reference< XFilterGroupManager > m_xFilterGroupManager;
+ FileDialogHelper_Impl* m_pFileDlgImpl;
+
+ public:
+ AppendFilterGroup( const Reference< XFilterManager >& _rxFilterManager, FileDialogHelper_Impl* _pImpl )
+ :m_xFilterManager ( _rxFilterManager )
+ ,m_xFilterGroupManager ( _rxFilterManager, UNO_QUERY )
+ ,m_pFileDlgImpl ( _pImpl )
+ {
+ DBG_ASSERT( m_xFilterManager.is(), "AppendFilterGroup::AppendFilterGroup: invalid filter manager!" );
+ DBG_ASSERT( m_pFileDlgImpl, "AppendFilterGroup::AppendFilterGroup: invalid filedlg impl!" );
+ }
+
+ void appendGroup( const FilterGroup& _rGroup, bool _bAddExtension )
+ {
+ try
+ {
+ if ( m_xFilterGroupManager.is() )
+ { // the file dialog implementation supports visual grouping of filters
+ // create a representation of the group which is understandable by the XFilterGroupManager
+ if ( _rGroup.size() )
+ {
+ Sequence< StringPair > aFilters( _rGroup.size() );
+ ::std::copy(
+ _rGroup.begin(),
+ _rGroup.end(),
+ aFilters.getArray()
+ );
+ if ( _bAddExtension )
+ {
+ StringPair* pFilters = aFilters.getArray();
+ StringPair* pEnd = pFilters + aFilters.getLength();
+ for ( ; pFilters != pEnd; ++pFilters )
+ pFilters->First = addExtension( pFilters->First, pFilters->Second, sal_True, *m_pFileDlgImpl );
+ }
+ m_xFilterGroupManager->appendFilterGroup( ::rtl::OUString(), aFilters );
+ }
+ }
+ else
+ {
+ ::std::for_each(
+ _rGroup.begin(),
+ _rGroup.end(),
+ AppendFilter( m_xFilterManager, m_pFileDlgImpl, _bAddExtension ) );
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+
+ // operate on a single filter group
+ void operator() ( const FilterGroup& _rGroup )
+ {
+ appendGroup( _rGroup, true );
+ }
+ };
+
+ //--------------------------------------------------------------------
+ TSortedFilterList::TSortedFilterList(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration >& xFilterList)
+ : m_nIterator(0)
+ {
+ if (!xFilterList.is())
+ return;
+
+ m_lFilters.clear();
+ while(xFilterList->hasMoreElements())
+ {
+ ::comphelper::SequenceAsHashMap lFilterProps (xFilterList->nextElement());
+ ::rtl::OUString sFilterName = lFilterProps.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii("Name"),
+ ::rtl::OUString());
+ if (sFilterName.getLength())
+ m_lFilters.push_back(sFilterName);
+ }
+ }
+
+ //--------------------------------------------------------------------
+ const SfxFilter* TSortedFilterList::First()
+ {
+ m_nIterator = 0;
+ return impl_getFilter(m_nIterator);
+ }
+
+ //--------------------------------------------------------------------
+ const SfxFilter* TSortedFilterList::Next()
+ {
+ ++m_nIterator;
+ return impl_getFilter(m_nIterator);
+ }
+
+ //--------------------------------------------------------------------
+ const SfxFilter* TSortedFilterList::impl_getFilter(sal_Int32 nIndex)
+ {
+ if (nIndex<0 || nIndex>=(sal_Int32)m_lFilters.size())
+ return 0;
+ const ::rtl::OUString& sFilterName = m_lFilters[nIndex];
+ if (!sFilterName.getLength())
+ return 0;
+ return SfxFilter::GetFilterByName(String(sFilterName));
+ }
+
+ //--------------------------------------------------------------------
+ void appendFiltersForSave( TSortedFilterList& _rFilterMatcher,
+ const Reference< XFilterManager >& _rxFilterManager,
+ ::rtl::OUString& _rFirstNonEmpty, FileDialogHelper_Impl& _rFileDlgImpl,
+ const ::rtl::OUString& _rFactory )
+ {
+ DBG_ASSERT( _rxFilterManager.is(), "sfx2::appendFiltersForSave: invalid manager!" );
+ if ( !_rxFilterManager.is() )
+ return;
+
+ ::rtl::OUString sUIName;
+ ::rtl::OUString sExtension;
+
+ // retrieve the default filter for this application module.
+ // It must be set as first of the generated filter list.
+ const SfxFilter* pDefaultFilter = SfxFilterContainer::GetDefaultFilter_Impl(_rFactory);
+ // --> PB 2004-11-01 #i32434# only use one extension
+ // (and always the first if there are more than one)
+ sExtension = pDefaultFilter->GetWildcard().GetWildCard().GetToken( 0, ';' );
+ // <--
+ sUIName = addExtension( pDefaultFilter->GetUIName(), sExtension, sal_False, _rFileDlgImpl );
+ try
+ {
+ _rxFilterManager->appendFilter( sUIName, sExtension );
+ if ( !_rFirstNonEmpty.getLength() )
+ _rFirstNonEmpty = sUIName;
+ }
+ catch( IllegalArgumentException )
+ {
+#ifdef DBG_UTIL
+ ByteString aMsg( "Could not append DefaultFilter" );
+ aMsg += ByteString( String( sUIName ), osl_getThreadTextEncoding() );
+ DBG_ERRORFILE( aMsg.GetBuffer() );
+#endif
+ }
+
+ for ( const SfxFilter* pFilter = _rFilterMatcher.First(); pFilter; pFilter = _rFilterMatcher.Next() )
+ {
+ if (pFilter->GetName() == pDefaultFilter->GetName())
+ continue;
+
+ // --> PB 2004-09-21 #i32434# only use one extension
+ // (and always the first if there are more than one)
+ sExtension = pFilter->GetWildcard().GetWildCard().GetToken( 0, ';' );
+ // <--
+ sUIName = addExtension( pFilter->GetUIName(), sExtension, sal_False, _rFileDlgImpl );
+ try
+ {
+ _rxFilterManager->appendFilter( sUIName, sExtension );
+ if ( !_rFirstNonEmpty.getLength() )
+ _rFirstNonEmpty = sUIName;
+ }
+ catch( IllegalArgumentException )
+ {
+ #ifdef DBG_UTIL
+ ByteString aMsg( "Could not append Filter" );
+ aMsg += ByteString( String( sUIName ), osl_getThreadTextEncoding() );
+ DBG_ERRORFILE( aMsg.GetBuffer() );
+ #endif
+ }
+ }
+ }
+
+ struct ExportFilter
+ {
+ ExportFilter( const rtl::OUString& _aUIName, const rtl::OUString& _aWildcard ) :
+ aUIName( _aUIName ), aWildcard( _aWildcard ) {}
+
+ rtl::OUString aUIName;
+ rtl::OUString aWildcard;
+ };
+
+ //--------------------------------------------------------------------
+ void appendExportFilters( TSortedFilterList& _rFilterMatcher,
+ const Reference< XFilterManager >& _rxFilterManager,
+ ::rtl::OUString& _rFirstNonEmpty, FileDialogHelper_Impl& _rFileDlgImpl )
+ {
+ DBG_ASSERT( _rxFilterManager.is(), "sfx2::appendExportFilters: invalid manager!" );
+ if ( !_rxFilterManager.is() )
+ return;
+
+ sal_Int32 nHTMLIndex = -1;
+ sal_Int32 nXHTMLIndex = -1;
+ sal_Int32 nPDFIndex = -1;
+ sal_Int32 nFlashIndex = -1;
+ ::rtl::OUString sUIName;
+ ::rtl::OUString sExtensions;
+ std::vector< ExportFilter > aImportantFilterGroup;
+ std::vector< ExportFilter > aFilterGroup;
+ Reference< XFilterGroupManager > xFilterGroupManager( _rxFilterManager, UNO_QUERY );
+ ::rtl::OUString sTypeName;
+ const ::rtl::OUString sWriterHTMLType( DEFINE_CONST_OUSTRING("writer_web_HTML") );
+ const ::rtl::OUString sGraphicHTMLType( DEFINE_CONST_OUSTRING("graphic_HTML") );
+ const ::rtl::OUString sXHTMLType( DEFINE_CONST_OUSTRING("XHTML_File") );
+ const ::rtl::OUString sPDFType( DEFINE_CONST_OUSTRING("pdf_Portable_Document_Format") );
+ const ::rtl::OUString sFlashType( DEFINE_CONST_OUSTRING("graphic_SWF") );
+
+ for ( const SfxFilter* pFilter = _rFilterMatcher.First(); pFilter; pFilter = _rFilterMatcher.Next() )
+ {
+ sTypeName = pFilter->GetTypeName();
+ sUIName = pFilter->GetUIName();
+ sExtensions = pFilter->GetWildcard().GetWildCard();
+ ExportFilter aExportFilter( sUIName, sExtensions );
+ String aExt = sExtensions;
+
+ if ( nHTMLIndex == -1 &&
+ ( sTypeName.equals( sWriterHTMLType ) || sTypeName.equals( sGraphicHTMLType ) ) )
+ {
+ aImportantFilterGroup.insert( aImportantFilterGroup.begin(), aExportFilter );
+ nHTMLIndex = 0;
+ }
+ else if ( nXHTMLIndex == -1 && sTypeName.equals( sXHTMLType ) )
+ {
+ std::vector< ExportFilter >::iterator aIter = aImportantFilterGroup.begin();
+ if ( nHTMLIndex == -1 )
+ aImportantFilterGroup.insert( aIter, aExportFilter );
+ else
+ aImportantFilterGroup.insert( ++aIter, aExportFilter );
+ nXHTMLIndex = 0;
+ }
+ else if ( nPDFIndex == -1 && sTypeName.equals( sPDFType ) )
+ {
+ std::vector< ExportFilter >::iterator aIter = aImportantFilterGroup.begin();
+ if ( nHTMLIndex != -1 )
+ aIter++;
+ if ( nXHTMLIndex != -1 )
+ aIter++;
+ aImportantFilterGroup.insert( aIter, aExportFilter );
+ nPDFIndex = 0;
+ }
+ else if ( nFlashIndex == -1 && sTypeName.equals( sFlashType ) )
+ {
+ std::vector< ExportFilter >::iterator aIter = aImportantFilterGroup.begin();
+ if ( nHTMLIndex != -1 )
+ aIter++;
+ if ( nXHTMLIndex != -1 )
+ aIter++;
+ if ( nPDFIndex != -1 )
+ aIter++;
+ aImportantFilterGroup.insert( aIter, aExportFilter );
+ nFlashIndex = 0;
+ }
+ else
+ aFilterGroup.push_back( aExportFilter );
+ }
+
+ if ( xFilterGroupManager.is() )
+ {
+ // Add both html/pdf filter as a filter group to get a separator between both groups
+ if ( aImportantFilterGroup.size() > 0 )
+ {
+ Sequence< StringPair > aFilters( aImportantFilterGroup.size() );
+ for ( sal_Int32 i = 0; i < (sal_Int32)aImportantFilterGroup.size(); i++ )
+ {
+ aFilters[i].First = addExtension( aImportantFilterGroup[i].aUIName,
+ aImportantFilterGroup[i].aWildcard,
+ sal_False, _rFileDlgImpl );
+ aFilters[i].Second = aImportantFilterGroup[i].aWildcard;
+ }
+
+ try
+ {
+ xFilterGroupManager->appendFilterGroup( ::rtl::OUString(), aFilters );
+ }
+ catch( IllegalArgumentException )
+ {
+ }
+ }
+
+ if ( aFilterGroup.size() > 0 )
+ {
+ Sequence< StringPair > aFilters( aFilterGroup.size() );
+ for ( sal_Int32 i = 0; i < (sal_Int32)aFilterGroup.size(); i++ )
+ {
+ aFilters[i].First = addExtension( aFilterGroup[i].aUIName,
+ aFilterGroup[i].aWildcard,
+ sal_False, _rFileDlgImpl );
+ aFilters[i].Second = aFilterGroup[i].aWildcard;
+ }
+
+ try
+ {
+ xFilterGroupManager->appendFilterGroup( ::rtl::OUString(), aFilters );
+ }
+ catch( IllegalArgumentException )
+ {
+ }
+ }
+ }
+ else
+ {
+ // Fallback solution just add both filter groups as single filters
+ sal_Int32 n;
+
+ for ( n = 0; n < (sal_Int32)aImportantFilterGroup.size(); n++ )
+ {
+ try
+ {
+ rtl::OUString aUIName = addExtension( aImportantFilterGroup[n].aUIName,
+ aImportantFilterGroup[n].aWildcard,
+ sal_False, _rFileDlgImpl );
+ _rxFilterManager->appendFilter( aUIName, aImportantFilterGroup[n].aWildcard );
+ if ( !_rFirstNonEmpty.getLength() )
+ _rFirstNonEmpty = sUIName;
+
+ }
+ catch( IllegalArgumentException )
+ {
+ #ifdef DBG_UTIL
+ ByteString aMsg( "Could not append Filter" );
+ aMsg += ByteString( String( sUIName ), osl_getThreadTextEncoding() );
+ DBG_ERRORFILE( aMsg.GetBuffer() );
+ #endif
+ }
+ }
+
+ for ( n = 0; n < (sal_Int32)aFilterGroup.size(); n++ )
+ {
+ try
+ {
+ rtl::OUString aUIName = addExtension( aFilterGroup[n].aUIName,
+ aFilterGroup[n].aWildcard,
+ sal_False, _rFileDlgImpl );
+ _rxFilterManager->appendFilter( aUIName, aFilterGroup[n].aWildcard );
+ if ( !_rFirstNonEmpty.getLength() )
+ _rFirstNonEmpty = sUIName;
+
+ }
+ catch( IllegalArgumentException )
+ {
+ #ifdef DBG_UTIL
+ ByteString aMsg( "Could not append Filter" );
+ aMsg += ByteString( String( sUIName ), osl_getThreadTextEncoding() );
+ DBG_ERRORFILE( aMsg.GetBuffer() );
+ #endif
+ }
+ }
+ }
+ }
+
+ //--------------------------------------------------------------------
+ void appendFiltersForOpen( TSortedFilterList& _rFilterMatcher,
+ const Reference< XFilterManager >& _rxFilterManager,
+ ::rtl::OUString& _rFirstNonEmpty, FileDialogHelper_Impl& _rFileDlgImpl )
+ {
+ DBG_ASSERT( _rxFilterManager.is(), "sfx2::appendFiltersForOpen: invalid manager!" );
+ if ( !_rxFilterManager.is() )
+ return;
+
+#ifdef DISABLE_GROUPING_AND_CLASSIFYING
+ // ===============================================================
+ // ensure that there's an entry "all" (with wildcard *.*)
+ lcl_EnsureAllFilesEntry( _rFilterMatcher, _rxFilterManager, _rFirstNonEmpty );
+
+ // ===============================================================
+ appendFilters( _rFilterMatcher, _rxFilterManager, _rFirstNonEmpty );
+#else
+
+ // ===============================================================
+ // group and classify the filters
+ GroupedFilterList aAllFilters;
+ lcl_GroupAndClassify( _rFilterMatcher, aAllFilters );
+
+ // ===============================================================
+ // ensure that we have the one "all files" entry
+ lcl_EnsureAllFilesEntry( _rFilterMatcher, aAllFilters );
+
+ // ===============================================================
+ // the first non-empty string - which we assume is the first overall entry
+ if ( !aAllFilters.empty() )
+ {
+ const FilterGroup& rFirstGroup = *aAllFilters.begin(); // should be the global classes
+ if ( !rFirstGroup.empty() )
+ _rFirstNonEmpty = rFirstGroup.begin()->First;
+ // append first group, without extension
+ AppendFilterGroup aGroup( _rxFilterManager, &_rFileDlgImpl );
+ aGroup.appendGroup( rFirstGroup, false );
+ }
+
+ // ===============================================================
+ // append the filters to the manager
+ if ( !aAllFilters.empty() )
+ {
+ ::std::list< FilterGroup >::iterator pIter = aAllFilters.begin();
+ ++pIter;
+ ::std::for_each(
+ pIter, // first filter group was handled seperately, see above
+ aAllFilters.end(),
+ AppendFilterGroup( _rxFilterManager, &_rFileDlgImpl ) );
+ }
+#endif
+ }
+
+ ::rtl::OUString addExtension( const ::rtl::OUString& _rDisplayText,
+ const ::rtl::OUString& _rExtension,
+ sal_Bool _bForOpen, FileDialogHelper_Impl& _rFileDlgImpl )
+ {
+ static ::rtl::OUString sAllFilter( RTL_CONSTASCII_USTRINGPARAM( "(*.*)" ) );
+ static ::rtl::OUString sOpenBracket( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
+ static ::rtl::OUString sCloseBracket( RTL_CONSTASCII_USTRINGPARAM( ")" ) );
+ ::rtl::OUString sRet = _rDisplayText;
+
+ if ( sRet.indexOf( sAllFilter ) == -1 )
+ {
+ String sExt = _rExtension;
+ if ( !_bForOpen )
+ // show '*' in extensions only when opening a document
+ sExt.EraseAllChars( '*' );
+ sRet += sOpenBracket;
+ sRet += sExt;
+ sRet += sCloseBracket;
+ }
+ _rFileDlgImpl.addFilterPair( _rDisplayText, sRet );
+ return sRet;
+ }
+
+//........................................................................
+} // namespace sfx2
+//........................................................................
+
+
diff --git a/sfx2/source/dialog/filtergrouping.hxx b/sfx2/source/dialog/filtergrouping.hxx
new file mode 100644
index 000000000000..8075186614dd
--- /dev/null
+++ b/sfx2/source/dialog/filtergrouping.hxx
@@ -0,0 +1,106 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef SFX2_FILTERGROUPING_HXX
+#define SFX2_FILTERGROUPING_HXX
+
+#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
+#include <com/sun/star/container/XEnumeration.hpp>
+#include "filedlgimpl.hxx"
+
+class SfxFilterMatcherIter;
+
+//........................................................................
+namespace sfx2
+{
+//........................................................................
+
+ class TSortedFilterList
+ {
+ private:
+
+ ::std::vector< ::rtl::OUString > m_lFilters;
+ sal_Int32 m_nIterator;
+
+ public:
+
+ TSortedFilterList(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration >& xFilterList);
+ const SfxFilter* First();
+ const SfxFilter* Next();
+
+ private:
+ const SfxFilter* impl_getFilter(sal_Int32 nIndex);
+ };
+
+ //--------------------------------------------------------------------
+ /** adds the given filters to the filter manager.
+ <p>To be used when saving generic files.</p>
+ */
+ void appendFiltersForSave(
+ TSortedFilterList& _rFilterMatcher,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilterManager >& _rFilterManager,
+ ::rtl::OUString& /* [out] */ _rFirstNonEmpty,
+ FileDialogHelper_Impl& _rFileDlgImpl,
+ const ::rtl::OUString& _rFactory
+ );
+
+ void appendExportFilters(
+ TSortedFilterList& _rFilterMatcher,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilterManager >& _rFilterManager,
+ ::rtl::OUString& /* [out] */ _rFirstNonEmpty,
+ FileDialogHelper_Impl& _rFileDlgImpl
+ );
+
+ //--------------------------------------------------------------------
+ /** adds the given filters to the filter manager.
+ <p>To be used when opening generic files.</p>
+ */
+ void appendFiltersForOpen(
+ TSortedFilterList& _rFilterMatcher,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilterManager >& _rFilterManager,
+ ::rtl::OUString& /* [out] */ _rFirstNonEmpty,
+ FileDialogHelper_Impl& _rFileDlgImpl
+ );
+
+ //--------------------------------------------------------------------
+ /** adds the given extension to the display text.
+ <p>To be used when opening or save generic files.</p>
+ */
+ ::rtl::OUString addExtension(
+ const ::rtl::OUString& _rDisplayText,
+ const ::rtl::OUString& _rExtension,
+ sal_Bool _bForOpen,
+ FileDialogHelper_Impl& _rFileDlgImpl
+ );
+
+//........................................................................
+} // namespace sfx2
+//........................................................................
+
+#endif // SFX2_FILTERGROUPING_HXX
+
+
diff --git a/sfx2/source/dialog/intro.cxx b/sfx2/source/dialog/intro.cxx
new file mode 100644
index 000000000000..637b89898a3a
--- /dev/null
+++ b/sfx2/source/dialog/intro.cxx
@@ -0,0 +1,110 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+
+#include "intro.hxx"
+
+#include <tools/stream.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/configmgr.hxx>
+#include <com/sun/star/uno/Any.h>
+
+#include <sfx2/sfxuno.hxx>
+
+// -----------------------------------------------------------------------
+
+void IntroWindow_Impl::Init()
+{
+ Size aSize = aIntroBmp.GetSizePixel();
+ SetOutputSizePixel( aSize );
+ Size aScreenSize( GetDesktopRectPixel().GetSize() );
+ Size aWinSize( GetSizePixel() );
+ Point aWinPos( ( aScreenSize.Width() - aWinSize.Width() ) / 2,
+ ( aScreenSize.Height() - aWinSize.Height() ) / 2 );
+ SetPosPixel( aWinPos );
+
+ if ( GetColorCount() >= 16 )
+ {
+ Show();
+ Update();
+ }
+}
+
+// -----------------------------------------------------------------------
+
+IntroWindow_Impl::IntroWindow_Impl( const Bitmap& rBmp ) :
+
+ WorkWindow( NULL, (WinBits)0 ),
+
+ aIntroBmp( rBmp )
+
+{
+ Hide();
+
+ // load bitmap depends on productname ("StarOffice", "StarSuite",...)
+ ::com::sun::star::uno::Any aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME );
+ rtl::OUString aTmp;
+ aRet >>= aTmp;
+ String aBmpFileName = aTmp;
+ aBmpFileName += String( DEFINE_CONST_UNICODE("_intro.bmp") );
+ INetURLObject aObj( SvtPathOptions().GetModulePath(), INET_PROT_FILE );
+ aObj.insertName( aBmpFileName );
+ SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
+ if ( !aStrm.GetError() )
+ aStrm >> aIntroBmp;
+
+ Init();
+}
+
+// -----------------------------------------------------------------------
+
+IntroWindow_Impl::~IntroWindow_Impl()
+{
+ Hide();
+}
+
+// -----------------------------------------------------------------------
+
+void IntroWindow_Impl::Paint( const Rectangle& )
+{
+ DrawBitmap( Point(), aIntroBmp );
+ Flush();
+}
+
+// -----------------------------------------------------------------------
+
+void IntroWindow_Impl::Slide()
+{
+}
+
+
diff --git a/sfx2/source/dialog/itemconnect.cxx b/sfx2/source/dialog/itemconnect.cxx
new file mode 100644
index 000000000000..51ed3bc5304a
--- /dev/null
+++ b/sfx2/source/dialog/itemconnect.cxx
@@ -0,0 +1,408 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <sfx2/itemconnect.hxx>
+
+#include <boost/shared_ptr.hpp>
+#include <list>
+#include <svl/itempool.hxx>
+
+// ============================================================================
+
+namespace sfx {
+
+// ============================================================================
+// Helpers
+// ============================================================================
+
+namespace {
+
+TriState lclConvertToTriState( bool bKnown, bool bIsKnownFlag, bool bIsUnknownFlag )
+{
+ return (bKnown && bIsKnownFlag) ? STATE_CHECK : ((!bKnown && bIsUnknownFlag) ? STATE_NOCHECK : STATE_DONTKNOW);
+}
+
+} // namespace
+
+// ----------------------------------------------------------------------------
+
+USHORT ItemWrapperHelper::GetWhichId( const SfxItemSet& rItemSet, USHORT nSlot )
+{
+ return rItemSet.GetPool()->GetWhich( nSlot );
+}
+
+bool ItemWrapperHelper::IsKnownItem( const SfxItemSet& rItemSet, USHORT nSlot )
+{
+ return rItemSet.GetItemState( GetWhichId( rItemSet, nSlot ), TRUE ) != SFX_ITEM_UNKNOWN;
+}
+
+const SfxPoolItem* ItemWrapperHelper::GetUniqueItem( const SfxItemSet& rItemSet, USHORT nSlot )
+{
+ USHORT nWhich = GetWhichId( rItemSet, nSlot );
+ return (rItemSet.GetItemState( nWhich, TRUE ) >= SFX_ITEM_DEFAULT) ? rItemSet.GetItem( nWhich, TRUE ) : 0;
+}
+
+const SfxPoolItem& ItemWrapperHelper::GetDefaultItem( const SfxItemSet& rItemSet, USHORT nSlot )
+{
+ return rItemSet.GetPool()->GetDefaultItem( GetWhichId( rItemSet, nSlot ) );
+}
+
+void ItemWrapperHelper::RemoveDefaultItem( SfxItemSet& rDestSet, const SfxItemSet& rOldSet, USHORT nSlot )
+{
+ USHORT nWhich = GetWhichId( rDestSet, nSlot );
+ if( rOldSet.GetItemState( nWhich, FALSE ) == SFX_ITEM_DEFAULT )
+ rDestSet.ClearItem( nWhich );
+}
+
+// ============================================================================
+// Base control wrapper classes
+// ============================================================================
+
+ControlWrapperBase::~ControlWrapperBase()
+{
+}
+
+// ============================================================================
+// Single control wrappers
+// ============================================================================
+
+DummyWindowWrapper::DummyWindowWrapper( Window& rWindow ) :
+ SingleControlWrapperType( rWindow )
+{
+}
+
+bool DummyWindowWrapper::IsControlDontKnow() const
+{
+ return false;
+}
+
+void DummyWindowWrapper::SetControlDontKnow( bool )
+{
+}
+
+void* DummyWindowWrapper::GetControlValue() const
+{
+ return 0;
+}
+
+void DummyWindowWrapper::SetControlValue( void* )
+{
+}
+
+// ----------------------------------------------------------------------------
+
+CheckBoxWrapper::CheckBoxWrapper( CheckBox& rCheckBox ) :
+ SingleControlWrapperType( rCheckBox )
+{
+}
+
+bool CheckBoxWrapper::IsControlDontKnow() const
+{
+ return GetControl().GetState() == STATE_DONTKNOW;
+}
+
+void CheckBoxWrapper::SetControlDontKnow( bool bSet )
+{
+ GetControl().EnableTriState( bSet );
+ GetControl().SetState( bSet ? STATE_DONTKNOW : STATE_NOCHECK );
+}
+
+BOOL CheckBoxWrapper::GetControlValue() const
+{
+ return GetControl().IsChecked();
+}
+
+void CheckBoxWrapper::SetControlValue( BOOL bValue )
+{
+ GetControl().Check( bValue );
+}
+
+// ----------------------------------------------------------------------------
+
+EditWrapper::EditWrapper( Edit& rEdit ) :
+ SingleControlWrapperType( rEdit )
+{
+}
+
+bool EditWrapper::IsControlDontKnow() const
+{
+ // no "don't know" state - empty string is a valid value of an Edit
+ return false;
+}
+
+void EditWrapper::SetControlDontKnow( bool bSet )
+{
+ if( bSet )
+ GetControl().SetText( String() );
+}
+
+String EditWrapper::GetControlValue() const
+{
+ return GetControl().GetText();
+}
+
+void EditWrapper::SetControlValue( String aValue )
+{
+ GetControl().SetText( aValue );
+}
+
+// ----------------------------------------------------------------------------
+
+ColorListBoxWrapper::ColorListBoxWrapper(ColorListBox & rListBox):
+ SingleControlWrapper< ColorListBox, Color >(rListBox)
+{}
+
+ColorListBoxWrapper::~ColorListBoxWrapper()
+{}
+
+bool ColorListBoxWrapper::IsControlDontKnow() const
+{
+ return GetControl().GetSelectEntryCount() == 0;
+}
+
+void ColorListBoxWrapper::SetControlDontKnow( bool bSet )
+{
+ if( bSet ) GetControl().SetNoSelection();
+}
+
+Color ColorListBoxWrapper::GetControlValue() const
+{
+ return GetControl().GetSelectEntryColor();
+}
+
+void ColorListBoxWrapper::SetControlValue( Color aColor )
+{
+ GetControl().SelectEntry( aColor );
+}
+
+// ============================================================================
+// Multi control wrappers
+// ============================================================================
+
+typedef std::vector< ControlWrapperBase* > ControlWrpVec;
+typedef ControlWrpVec::iterator ControlWrpVecI;
+typedef ControlWrpVec::const_iterator ControlWrpVecCI;
+
+struct MultiControlWrapperHelper_Impl
+{
+ ControlWrpVec maVec;
+};
+
+MultiControlWrapperHelper::MultiControlWrapperHelper() :
+ mxImpl( new MultiControlWrapperHelper_Impl )
+{
+}
+
+MultiControlWrapperHelper::~MultiControlWrapperHelper()
+{
+}
+
+void MultiControlWrapperHelper::RegisterControlWrapper( ControlWrapperBase& rWrapper )
+{
+ mxImpl->maVec.push_back( &rWrapper );
+}
+
+void MultiControlWrapperHelper::ModifyControl( TriState eEnable, TriState eShow )
+{
+ for( ControlWrpVecI aIt = mxImpl->maVec.begin(), aEnd = mxImpl->maVec.end(); aIt != aEnd; ++aIt )
+ (*aIt)->ModifyControl( eEnable, eShow );
+}
+
+bool MultiControlWrapperHelper::IsControlDontKnow() const
+{
+ bool bIs = !mxImpl->maVec.empty();
+ for( ControlWrpVecCI aIt = mxImpl->maVec.begin(), aEnd = mxImpl->maVec.end(); bIs && (aIt != aEnd); ++aIt )
+ bIs &= (*aIt)->IsControlDontKnow();
+ return bIs;
+}
+
+void MultiControlWrapperHelper::SetControlDontKnow( bool bSet )
+{
+ for( ControlWrpVecI aIt = mxImpl->maVec.begin(), aEnd = mxImpl->maVec.end(); aIt != aEnd; ++aIt )
+ (*aIt)->SetControlDontKnow( bSet );
+}
+
+// ============================================================================
+// Base connection classes
+// ============================================================================
+
+ItemConnectionBase::ItemConnectionBase( ItemConnFlags nFlags ) :
+ mnFlags( nFlags )
+{
+}
+
+ItemConnectionBase::~ItemConnectionBase()
+{
+}
+
+void ItemConnectionBase::Activate( bool bActive )
+{
+ if( bActive ) mnFlags &= ~ITEMCONN_INACTIVE; else mnFlags |= ITEMCONN_INACTIVE;
+}
+
+bool ItemConnectionBase::IsActive() const
+{
+ return !(mnFlags & ITEMCONN_INACTIVE);
+}
+
+void ItemConnectionBase::DoApplyFlags( const SfxItemSet& rItemSet )
+{
+ if( IsActive() )
+ ApplyFlags( rItemSet );
+}
+
+void ItemConnectionBase::DoReset( const SfxItemSet& rItemSet )
+{
+ if( IsActive() )
+ Reset( rItemSet );
+}
+
+bool ItemConnectionBase::DoFillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet )
+{
+ return IsActive() && FillItemSet( rDestSet, rOldSet );
+}
+
+TriState ItemConnectionBase::GetEnableState( bool bKnown ) const
+{
+ return lclConvertToTriState( bKnown, mnFlags & ITEMCONN_ENABLE_KNOWN, mnFlags & ITEMCONN_DISABLE_UNKNOWN );
+}
+
+TriState ItemConnectionBase::GetShowState( bool bKnown ) const
+{
+ return lclConvertToTriState( bKnown, mnFlags & ITEMCONN_SHOW_KNOWN, mnFlags & ITEMCONN_HIDE_UNKNOWN );
+}
+
+// ============================================================================
+// Standard connections
+// ============================================================================
+
+DummyItemConnection::DummyItemConnection( USHORT nSlot, Window& rWindow, ItemConnFlags nFlags ) :
+ ItemConnectionBase( nFlags ),
+ DummyWindowWrapper( rWindow ),
+ mnSlot( nSlot )
+{
+}
+
+void DummyItemConnection::ApplyFlags( const SfxItemSet& rItemSet )
+{
+ bool bKnown = ItemWrapperHelper::IsKnownItem( rItemSet, mnSlot );
+ ModifyControl( GetEnableState( bKnown ), GetShowState( bKnown ) );
+}
+
+void DummyItemConnection::Reset( const SfxItemSet& /*rItemSet*/ )
+{
+}
+
+bool DummyItemConnection::FillItemSet( SfxItemSet& /*rDestSet*/, const SfxItemSet& /*rOldSet*/ )
+{
+ return false; // item set not changed
+}
+
+// ============================================================================
+// Array of connections
+// ============================================================================
+
+class ItemConnectionArrayImpl
+{
+public:
+ void Append( ItemConnectionBase* pConnection );
+
+ void ApplyFlags( const SfxItemSet& rItemSet );
+ void Reset( const SfxItemSet& rItemSet );
+ bool FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet );
+
+private:
+ typedef boost::shared_ptr< ItemConnectionBase > ItemConnectionRef;
+ typedef std::list< ItemConnectionRef > ItemConnectionList;
+ typedef ItemConnectionList::iterator ItemConnectionListIt;
+
+ ItemConnectionList maList;
+};
+
+void ItemConnectionArrayImpl::Append( ItemConnectionBase* pConnection )
+{
+ if( pConnection )
+ maList.push_back( ItemConnectionRef( pConnection ) );
+}
+
+void ItemConnectionArrayImpl::ApplyFlags( const SfxItemSet& rItemSet )
+{
+ for( ItemConnectionListIt aIt = maList.begin(), aEnd = maList.end(); aIt != aEnd; ++aIt )
+ (*aIt)->DoApplyFlags( rItemSet );
+}
+
+void ItemConnectionArrayImpl::Reset( const SfxItemSet& rItemSet )
+{
+ for( ItemConnectionListIt aIt = maList.begin(), aEnd = maList.end(); aIt != aEnd; ++aIt )
+ (*aIt)->DoReset( rItemSet );
+}
+
+bool ItemConnectionArrayImpl::FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet )
+{
+ bool bChanged = false;
+ for( ItemConnectionListIt aIt = maList.begin(), aEnd = maList.end(); aIt != aEnd; ++aIt )
+ bChanged |= (*aIt)->DoFillItemSet( rDestSet, rOldSet );
+ return bChanged;
+}
+
+// ----------------------------------------------------------------------------
+
+ItemConnectionArray::ItemConnectionArray() :
+ mxImpl( new ItemConnectionArrayImpl )
+{
+}
+
+ItemConnectionArray::~ItemConnectionArray()
+{
+}
+
+void ItemConnectionArray::AddConnection( ItemConnectionBase* pConnection )
+{
+ mxImpl->Append( pConnection );
+}
+
+void ItemConnectionArray::ApplyFlags( const SfxItemSet& rItemSet )
+{
+ mxImpl->ApplyFlags( rItemSet );
+}
+
+void ItemConnectionArray::Reset( const SfxItemSet& rItemSet )
+{
+ mxImpl->Reset( rItemSet );
+}
+
+bool ItemConnectionArray::FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet )
+{
+ return mxImpl->FillItemSet( rDestSet, rOldSet );
+}
+
+// ============================================================================
+
+} // namespace sfx
+
diff --git a/sfx2/source/dialog/mailmodel.cxx b/sfx2/source/dialog/mailmodel.cxx
new file mode 100644
index 000000000000..8c05fa424263
--- /dev/null
+++ b/sfx2/source/dialog/mailmodel.cxx
@@ -0,0 +1,1029 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+// includes --------------------------------------------------------------
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/ucb/CommandAbortedException.hpp>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/system/XSimpleMailClientSupplier.hpp>
+#include <com/sun/star/system/SimpleMailClientFlags.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/container/XContainerQuery.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/security/CertificateValidity.hpp>
+#include <com/sun/star/security/DocumentSignatureInformation.hpp>
+#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XStatusListener.hpp>
+#include <com/sun/star/ucb/InsertCommandArgument.hpp>
+#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
+#include <com/sun/star/document/XExporter.hpp>
+#include <rtl/textenc.h>
+#include <rtl/uri.h>
+#include <rtl/uri.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <vcl/msgbox.hxx>
+
+#include <sfx2/mailmodelapi.hxx>
+#include "sfxtypes.hxx"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/sfxsids.hrc>
+#include "dialog.hrc"
+
+#include <unotools/tempfile.hxx>
+#include <unotools/configitem.hxx>
+#include <ucbhelper/content.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/useroptions.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/extract.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <comphelper/sequenceasvector.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/mediadescriptor.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <vcl/svapp.hxx>
+#include <cppuhelper/implbase1.hxx>
+
+// --------------------------------------------------------------
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::system;
+using namespace ::rtl;
+
+namespace css = ::com::sun::star;
+// - class PrepareListener_Impl ------------------------------------------
+class PrepareListener_Impl : public ::cppu::WeakImplHelper1< css::frame::XStatusListener >
+{
+ bool m_bState;
+public:
+ PrepareListener_Impl();
+ virtual ~PrepareListener_Impl();
+
+ // css.frame.XStatusListener
+ virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent)
+ throw(css::uno::RuntimeException);
+
+ // css.lang.XEventListener
+ virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
+ throw(css::uno::RuntimeException);
+
+ bool IsSet() const {return m_bState;}
+};
+
+/*-- 25.08.2010 14:32:49---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+PrepareListener_Impl::PrepareListener_Impl() :
+ m_bState( false )
+{
+}
+/*-- 25.08.2010 14:32:51---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+PrepareListener_Impl::~PrepareListener_Impl()
+{
+}
+/*-- 25.08.2010 14:32:51---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+void PrepareListener_Impl::statusChanged(const css::frame::FeatureStateEvent& rEvent) throw(css::uno::RuntimeException)
+{
+ if( rEvent.IsEnabled )
+ rEvent.State >>= m_bState;
+ else
+ m_bState = sal_False;
+}
+/*-- 25.08.2010 14:32:52---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+void PrepareListener_Impl::disposing(const css::lang::EventObject& /*rEvent*/) throw(css::uno::RuntimeException)
+{
+}
+
+// class AddressList_Impl ------------------------------------------------
+
+typedef String* AddressItemPtr_Impl;
+DECLARE_LIST( AddressList_Impl, AddressItemPtr_Impl )
+
+// class SfxMailModel -----------------------------------------------
+
+static const char PDF_DOCUMENT_TYPE[] = "pdf_Portable_Document_Format";
+static const sal_uInt32 PDF_DOCUMENT_TYPE_LEN = 28;
+
+void SfxMailModel::ClearList( AddressList_Impl* pList )
+{
+ if ( pList )
+ {
+ ULONG i, nCount = pList->Count();
+ for ( i = 0; i < nCount; ++i )
+ delete pList->GetObject(i);
+ pList->Clear();
+ }
+}
+
+void SfxMailModel::MakeValueList( AddressList_Impl* pList, String& rValueList )
+{
+ rValueList.Erase();
+ if ( pList )
+ {
+ ULONG i, nCount = pList->Count();
+ for ( i = 0; i < nCount; ++i )
+ {
+ if ( rValueList.Len() > 0 )
+ rValueList += ',';
+ rValueList += *pList->GetObject(i);
+ }
+ }
+}
+
+sal_Bool HasDocumentValidSignature( const css::uno::Reference< css::frame::XModel >& xModel )
+{
+ try
+ {
+ css::uno::Reference< css::beans::XPropertySet > xPropSet( xModel, css::uno::UNO_QUERY );
+ if ( xPropSet.is() )
+ {
+ Any a = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasValidSignatures" )));
+ sal_Bool bReturn = sal_Bool();
+ if ( a >>= bReturn )
+ return bReturn;
+ }
+ }
+ catch ( css::uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch ( css::uno::Exception& )
+ {
+ }
+
+ return sal_False;
+}
+
+SfxMailModel::SaveResult SfxMailModel::ShowFilterOptionsDialog(
+ uno::Reference< lang::XMultiServiceFactory > xSMGR,
+ uno::Reference< frame::XModel > xModel,
+ const rtl::OUString& rFilterName,
+ const rtl::OUString& rType,
+ bool bModified,
+ sal_Int32& rNumArgs,
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs )
+{
+ SaveResult eRet( SAVE_ERROR );
+
+ try
+ {
+ uno::Sequence < beans::PropertyValue > aProps;
+ ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xFilterCFG =
+ uno::Reference< container::XNameAccess >(
+ xSMGR->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), uno::UNO_QUERY );
+ css::uno::Reference< css::util::XModifiable > xModifiable( xModel, css::uno::UNO_QUERY );
+
+ if ( !xFilterCFG.is() )
+ return eRet;
+
+ uno::Any aAny = xFilterCFG->getByName( rFilterName );
+
+ if ( aAny >>= aProps )
+ {
+ sal_Int32 nPropertyCount = aProps.getLength();
+ for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
+ {
+ if( aProps[nProperty].Name.equals( ::rtl::OUString::createFromAscii( "UIComponent" )) )
+ {
+ ::rtl::OUString aServiceName;
+ aProps[nProperty].Value >>= aServiceName;
+ if( aServiceName.getLength() )
+ {
+ uno::Reference< ui::dialogs::XExecutableDialog > xFilterDialog(
+ xSMGR->createInstance( aServiceName ), uno::UNO_QUERY );
+ uno::Reference< beans::XPropertyAccess > xFilterProperties(
+ xFilterDialog, uno::UNO_QUERY );
+
+ if( xFilterDialog.is() && xFilterProperties.is() )
+ {
+ uno::Sequence< beans::PropertyValue > aPropsForDialog(1);
+ uno::Reference< document::XExporter > xExporter( xFilterDialog, uno::UNO_QUERY );
+
+ if ( rType.equalsAsciiL( PDF_DOCUMENT_TYPE, PDF_DOCUMENT_TYPE_LEN ))
+ {
+ //add an internal property, used to tell the dialog we want to set a different
+ //string for the ok button
+ //used in filter/source/pdf/impdialog.cxx
+ String aOkSendText( SfxResId( STR_PDF_EXPORT_SEND ));
+
+ uno::Sequence< beans::PropertyValue > aFilterDataValue(1);
+ aFilterDataValue[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_OkButtonString" ));
+ aFilterDataValue[0].Value = css::uno::makeAny( ::rtl::OUString( aOkSendText ));
+
+ //add to the filterdata property, the only one the PDF export filter dialog will care for
+ aPropsForDialog[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ));
+ aPropsForDialog[0].Value = css::uno::makeAny( aFilterDataValue );
+
+ //when executing the dialog will merge the persistent FilterData properties
+ xFilterProperties->setPropertyValues( aPropsForDialog );
+ }
+
+ if( xExporter.is() )
+ xExporter->setSourceDocument(
+ uno::Reference< lang::XComponent >( xModel, uno::UNO_QUERY ) );
+
+ if( xFilterDialog->execute() )
+ {
+ //get the filter data
+ uno::Sequence< beans::PropertyValue > aPropsFromDialog = xFilterProperties->getPropertyValues();
+
+ //add them to the args
+ for ( sal_Int32 nInd = 0; nInd < aPropsFromDialog.getLength(); nInd++ )
+ {
+ if( aPropsFromDialog[ nInd ].Name.equals( ::rtl::OUString::createFromAscii( "FilterData" ) ) )
+ {
+ //found the filterdata, add to the storing argument
+ rArgs.realloc( ++rNumArgs );
+ rArgs[rNumArgs-1].Name = aPropsFromDialog[ nInd ].Name;
+ rArgs[rNumArgs-1].Value = aPropsFromDialog[ nInd ].Value;
+ break;
+ }
+ }
+ eRet = SAVE_SUCCESSFULL;
+ }
+ else
+ {
+ // cancel from dialog, then do not send
+ // If the model is not modified, it could be modified by the dispatch calls.
+ // Therefore set back to modified = false. This should not hurt if we call
+ // on a non-modified model.
+ if ( !bModified )
+ {
+ try
+ {
+ xModifiable->setModified( sal_False );
+ }
+ catch( com::sun::star::beans::PropertyVetoException& )
+ {
+ }
+ }
+ eRet = SAVE_CANCELLED;
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ catch( css::uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return eRet;
+}
+
+sal_Int32 SfxMailModel::GetCount() const
+{
+ return maAttachedDocuments.size();
+}
+
+sal_Bool SfxMailModel::IsEmpty() const
+{
+ return maAttachedDocuments.empty();
+}
+
+SfxMailModel::SaveResult SfxMailModel::SaveDocumentAsFormat(
+ const rtl::OUString& aSaveFileName,
+ const css::uno::Reference< css::uno::XInterface >& xFrameOrModel,
+ const rtl::OUString& rType,
+ rtl::OUString& rFileNamePath )
+{
+ SaveResult eRet( SAVE_ERROR );
+ bool bSendAsPDF = (rType.equalsAsciiL( PDF_DOCUMENT_TYPE, PDF_DOCUMENT_TYPE_LEN ));
+
+ css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
+ if (!xSMGR.is())
+ return eRet;
+
+ const rtl::OUString aModuleManager( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ));
+ css::uno::Reference< css::frame::XModuleManager > xModuleManager( xSMGR->createInstance( aModuleManager ), css::uno::UNO_QUERY_THROW );
+ if ( !xModuleManager.is() )
+ return eRet;
+
+ rtl::OUString aModule;
+ try
+ {
+ aModule = xModuleManager->identify( xFrameOrModel );
+ }
+ catch ( css::uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch ( css::uno::Exception& )
+ {
+ }
+
+ css::uno::Reference< css::frame::XFrame > xFrame( xFrameOrModel, css::uno::UNO_QUERY );
+ css::uno::Reference< css::frame::XModel > xModel( xFrameOrModel, css::uno::UNO_QUERY );
+ if ( xFrame.is() )
+ {
+ css::uno::Reference< css::frame::XController > xController = xFrame->getController();
+ if ( xController.is() )
+ xModel = xController->getModel();
+ }
+
+ // We need at least a valid module name and model reference
+ if (( aModule.getLength() > 0 ) && xModel.is() )
+ {
+ bool bModified( false );
+ bool bHasLocation( false );
+ bool bStoreTo( false );
+
+ css::uno::Reference< css::util::XModifiable > xModifiable( xModel, css::uno::UNO_QUERY );
+ css::uno::Reference< css::frame::XStorable > xStorable( xModel, css::uno::UNO_QUERY );
+
+ if ( xModifiable.is() )
+ bModified = xModifiable->isModified();
+ if ( xStorable.is() )
+ {
+ rtl::OUString aLocation = xStorable->getLocation();
+ INetURLObject aFileObj( aLocation );
+
+ bool bPrivateProtocol = ( aFileObj.GetProtocol() == INET_PROT_PRIV_SOFFICE );
+
+ bHasLocation = ( aLocation.getLength() > 0 ) && !bPrivateProtocol;
+ OSL_ASSERT( !bPrivateProtocol );
+ }
+ if ( rType.getLength() > 0 )
+ bStoreTo = true;
+
+ if ( xStorable.is() )
+ {
+ rtl::OUString aFilterName;
+ rtl::OUString aTypeName( rType );
+ rtl::OUString aFileName;
+ rtl::OUString aExtension;
+
+ css::uno::Reference< css::container::XContainerQuery > xContainerQuery(
+ xSMGR->createInstance( rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ))),
+ css::uno::UNO_QUERY );
+
+ if ( bStoreTo )
+ {
+ // Retrieve filter from type
+ css::uno::Sequence< css::beans::NamedValue > aQuery( bSendAsPDF ? 3 : 2 );
+ aQuery[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ));
+ aQuery[0].Value = css::uno::makeAny( aTypeName );
+ aQuery[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ));
+ aQuery[1].Value = css::uno::makeAny( aModule );
+ if( bSendAsPDF )
+ {
+ // #i91419#
+ // FIXME: we want just an export filter. However currently we need
+ // exact flag value as detailed in the filter configuration to get it
+ // this seems to be a bug
+ // without flags we get an import filter here, which is also unwanted
+ aQuery[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Flags" ));
+ aQuery[2].Value = css::uno::makeAny( sal_Int32(0x80042) ); // EXPORT ALIEN 3RDPARTY
+ }
+
+ css::uno::Reference< css::container::XEnumeration > xEnumeration =
+ xContainerQuery->createSubSetEnumerationByProperties( aQuery );
+
+ if ( xEnumeration->hasMoreElements() )
+ {
+ ::comphelper::SequenceAsHashMap aFilterPropsHM( xEnumeration->nextElement() );
+ aFilterName = aFilterPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "Name" ),
+ ::rtl::OUString() );
+ }
+
+ if ( bHasLocation )
+ {
+ // Retrieve filter from media descriptor
+ ::comphelper::SequenceAsHashMap aMediaDescrPropsHM( xModel->getArgs() );
+ rtl::OUString aOrgFilterName = aMediaDescrPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )),
+ ::rtl::OUString() );
+ if ( aOrgFilterName == aFilterName )
+ {
+ // We should save the document in the original format. Therefore this
+ // is not a storeTo operation. To support signing in this case, reset
+ // bStoreTo flag.
+ bStoreTo = false;
+ }
+ }
+ }
+ else
+ {
+ if ( bHasLocation )
+ {
+ // Retrieve filter from media descriptor
+ ::comphelper::SequenceAsHashMap aMediaDescrPropsHM( xModel->getArgs() );
+ aFilterName = aMediaDescrPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )),
+ ::rtl::OUString() );
+ }
+
+ if ( !bHasLocation || ( aFilterName.getLength() == 0 ))
+ {
+ // Retrieve the user defined default filter
+ css::uno::Reference< css::container::XNameAccess > xNameAccess( xModuleManager, css::uno::UNO_QUERY );
+ try
+ {
+ ::comphelper::SequenceAsHashMap aFilterPropsHM( xNameAccess->getByName( aModule ) );
+ aFilterName = aFilterPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "ooSetupFactoryDefaultFilter" ),
+ ::rtl::OUString() );
+ css::uno::Reference< css::container::XNameAccess > xNameAccess2(
+ xContainerQuery, css::uno::UNO_QUERY );
+ if ( xNameAccess2.is() )
+ {
+ ::comphelper::SequenceAsHashMap aFilterPropsHM2( xNameAccess2->getByName( aFilterName ) );
+ aTypeName = aFilterPropsHM2.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "Type" ),
+ ::rtl::OUString() );
+ }
+ }
+ catch ( css::container::NoSuchElementException& )
+ {
+ }
+ catch ( css::beans::UnknownPropertyException& )
+ {
+ }
+ }
+ }
+
+ // No filter found => error
+ // No type and no location => error
+ if (( aFilterName.getLength() == 0 ) ||
+ (( aTypeName.getLength() == 0 ) && !bHasLocation ))
+ return eRet;
+
+ // Determine filen name and extension
+ if ( bHasLocation && !bStoreTo )
+ {
+ INetURLObject aFileObj( xStorable->getLocation() );
+ aExtension = (rtl::OUString)aFileObj.getExtension();
+ }
+ else
+ {
+ css::uno::Reference< container::XNameAccess > xTypeDetection(
+ xSMGR->createInstance( ::rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" ))),
+ css::uno::UNO_QUERY );
+
+
+ if ( xTypeDetection.is() )
+ {
+ try
+ {
+ ::comphelper::SequenceAsHashMap aTypeNamePropsHM( xTypeDetection->getByName( aTypeName ) );
+ uno::Sequence< ::rtl::OUString > aExtensions = aTypeNamePropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "Extensions" ),
+ ::uno::Sequence< ::rtl::OUString >() );
+ if ( aExtensions.getLength() )
+ aExtension = aExtensions[0];
+ }
+ catch ( css::container::NoSuchElementException& )
+ {
+ }
+ }
+ }
+
+ // Use provided save file name. If empty determine file name
+ aFileName = aSaveFileName;
+ if ( aFileName.getLength() == 0 )
+ {
+ if ( !bHasLocation )
+ {
+ // Create a noname file name with the correct extension
+ const rtl::OUString aNoNameFileName( RTL_CONSTASCII_USTRINGPARAM( "noname" ));
+ aFileName = aNoNameFileName;
+ }
+ else
+ {
+ // Determine file name from model
+ INetURLObject aFileObj( xStorable->getLocation() );
+ aFileName = aFileObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::NO_DECODE );
+ }
+ }
+
+ // No file name => error
+ if ( aFileName.getLength() == 0 )
+ return eRet;
+
+ OSL_ASSERT( aFilterName.getLength() > 0 );
+ OSL_ASSERT( aFileName.getLength() > 0 );
+
+ // Creates a temporary directory to store a predefined file into it.
+ // This makes it possible to store the file for "send document as e-mail"
+ // with the original file name. We cannot use the original file as
+ // some mail programs need exclusive access.
+ ::utl::TempFile aTempDir( NULL, sal_True );
+
+ INetURLObject aFilePathObj( aTempDir.GetURL() );
+ aFilePathObj.insertName( aFileName );
+ aFilePathObj.setExtension( aExtension );
+
+ rtl::OUString aFileURL = aFilePathObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ sal_Int32 nNumArgs(0);
+ const rtl::OUString aPasswordPropName( RTL_CONSTASCII_USTRINGPARAM( "Password" ));
+ css::uno::Sequence< css::beans::PropertyValue > aArgs( ++nNumArgs );
+ aArgs[nNumArgs-1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
+ aArgs[nNumArgs-1].Value = css::uno::makeAny( aFilterName );
+
+ ::comphelper::SequenceAsHashMap aMediaDescrPropsHM( xModel->getArgs() );
+ rtl::OUString aPassword = aMediaDescrPropsHM.getUnpackedValueOrDefault(
+ aPasswordPropName,
+ ::rtl::OUString() );
+ if ( aPassword.getLength() > 0 )
+ {
+ aArgs.realloc( ++nNumArgs );
+ aArgs[nNumArgs-1].Name = aPasswordPropName;
+ aArgs[nNumArgs-1].Value = css::uno::makeAny( aPassword );
+ }
+
+ bool bNeedsPreparation = false;
+ css::util::URL aPrepareURL;
+ css::uno::Reference< css::frame::XDispatch > xPrepareDispatch;
+ css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider( xFrame, css::uno::UNO_QUERY );
+ css::uno::Reference< css::util::XURLTransformer > xURLTransformer(
+ xSMGR->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))),
+ css::uno::UNO_QUERY );
+ if( !bSendAsPDF )
+ {
+ try
+ {
+ // check if the document needs to be prepared for sending as mail (embedding of links, removal of invisible content)
+
+ if ( xURLTransformer.is() )
+ {
+ aPrepareURL.Complete = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PrepareMailExport" ));
+ xURLTransformer->parseStrict( aPrepareURL );
+ }
+
+ if ( xDispatchProvider.is() )
+ {
+ xPrepareDispatch = css::uno::Reference< css::frame::XDispatch >(
+ xDispatchProvider->queryDispatch( aPrepareURL, ::rtl::OUString(), 0 ));
+ if ( xPrepareDispatch.is() )
+ {
+ PrepareListener_Impl* pPrepareListener;
+ uno::Reference< css::frame::XStatusListener > xStatusListener = pPrepareListener = new PrepareListener_Impl;
+ xPrepareDispatch->addStatusListener( xStatusListener, aPrepareURL );
+ bNeedsPreparation = pPrepareListener->IsSet();
+ xPrepareDispatch->removeStatusListener( xStatusListener, aPrepareURL );
+ }
+ }
+ }
+ catch ( css::uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch ( css::uno::Exception& )
+ {
+ }
+ }
+
+ if ( bModified || !bHasLocation || bStoreTo || bNeedsPreparation )
+ {
+ // Document is modified, is newly created or should be stored in a special format
+ try
+ {
+ if( bNeedsPreparation && xPrepareDispatch.is() )
+ {
+ if ( xPrepareDispatch.is() )
+ {
+ try
+ {
+ css::uno::Sequence< css::beans::PropertyValue > aDispatchArgs;
+ xPrepareDispatch->dispatch( aPrepareURL, aDispatchArgs );
+ }
+ catch ( css::uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch ( css::uno::Exception& )
+ {
+ }
+ }
+ }
+
+ //check if this is the pdf otput filter (i#64555)
+ if( bSendAsPDF )
+ {
+ SaveResult eShowPDFFilterDialog = ShowFilterOptionsDialog(
+ xSMGR, xModel, aFilterName, rType, bModified, nNumArgs, aArgs );
+
+ // don't continue on dialog cancel or error
+ if ( eShowPDFFilterDialog != SAVE_SUCCESSFULL )
+ return eShowPDFFilterDialog;
+ }
+
+ xStorable->storeToURL( aFileURL, aArgs );
+ rFileNamePath = aFileURL;
+ eRet = SAVE_SUCCESSFULL;
+
+ if( !bSendAsPDF )
+ {
+ css::util::URL aURL;
+ // #i30432# notify that export is finished - the Writer may want to restore removed content
+ if ( xURLTransformer.is() )
+ {
+ aURL.Complete = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:MailExportFinished" ));
+ xURLTransformer->parseStrict( aURL );
+ }
+
+ if ( xDispatchProvider.is() )
+ {
+ css::uno::Reference< css::frame::XDispatch > xDispatch = css::uno::Reference< css::frame::XDispatch >(
+ xDispatchProvider->queryDispatch( aURL, ::rtl::OUString(), 0 ));
+ if ( xDispatch.is() )
+ {
+ try
+ {
+ css::uno::Sequence< css::beans::PropertyValue > aDispatchArgs;
+ xDispatch->dispatch( aURL, aDispatchArgs );
+ }
+ catch ( css::uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch ( css::uno::Exception& )
+ {
+ }
+ }
+ }
+ }
+ // If the model is not modified, it could be modified by the dispatch calls.
+ // Therefore set back to modified = false. This should not hurt if we call
+ // on a non-modified model.
+ if ( !bModified )
+ {
+ try
+ {
+ xModifiable->setModified( sal_False );
+ }
+ catch( com::sun::star::beans::PropertyVetoException& )
+ {
+ }
+ }
+ }
+ catch ( com::sun::star::io::IOException& )
+ {
+ eRet = SAVE_ERROR;
+ }
+ }
+ else
+ {
+ // We need 1:1 copy of the document to preserve an added signature.
+ aArgs.realloc( ++nNumArgs );
+ aArgs[nNumArgs-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyStreamIfPossible" ) );
+ aArgs[nNumArgs-1].Value = css::uno::makeAny( (sal_Bool)sal_True );
+
+ try
+ {
+ xStorable->storeToURL( aFileURL, aArgs );
+ rFileNamePath = aFileURL;
+ eRet = SAVE_SUCCESSFULL;
+ }
+ catch ( com::sun::star::io::IOException& )
+ {
+ eRet = SAVE_ERROR;
+ }
+ }
+ }
+ }
+
+ return eRet;
+}
+
+SfxMailModel::SfxMailModel() :
+ mpToList ( NULL ),
+ mpCcList ( NULL ),
+ mpBccList ( NULL ),
+ mePriority ( PRIO_NORMAL ),
+ mbLoadDone ( sal_True )
+{
+}
+
+SfxMailModel::~SfxMailModel()
+{
+ ClearList( mpToList );
+ delete mpToList;
+ ClearList( mpCcList );
+ delete mpCcList;
+ ClearList( mpBccList );
+ delete mpBccList;
+}
+
+void SfxMailModel::AddAddress( const String& rAddress, AddressRole eRole )
+{
+ // don't add a empty address
+ if ( rAddress.Len() > 0 )
+ {
+ AddressList_Impl* pList = NULL;
+ if ( ROLE_TO == eRole )
+ {
+ if ( !mpToList )
+ // create the list
+ mpToList = new AddressList_Impl;
+ pList = mpToList;
+ }
+ else if ( ROLE_CC == eRole )
+ {
+ if ( !mpCcList )
+ // create the list
+ mpCcList = new AddressList_Impl;
+ pList = mpCcList;
+ }
+ else if ( ROLE_BCC == eRole )
+ {
+ if ( !mpBccList )
+ // create the list
+ mpBccList = new AddressList_Impl;
+ pList = mpBccList;
+ }
+ else
+ {
+ DBG_ERRORFILE( "invalid address role" );
+ }
+
+ if ( pList )
+ {
+ // add address to list
+ AddressItemPtr_Impl pAddress = new String( rAddress );
+ pList->Insert( pAddress, LIST_APPEND );
+ }
+ }
+}
+
+SfxMailModel::SendMailResult SfxMailModel::AttachDocument(
+ const ::rtl::OUString& sDocumentType,
+ const css::uno::Reference< css::uno::XInterface >& xFrameOrModel,
+ const ::rtl::OUString& sAttachmentTitle )
+{
+ rtl::OUString sFileName;
+
+ SaveResult eSaveResult = SaveDocumentAsFormat( sAttachmentTitle, xFrameOrModel, sDocumentType, sFileName );
+ if ( eSaveResult == SAVE_SUCCESSFULL && ( sFileName.getLength() > 0 ) )
+ maAttachedDocuments.push_back(sFileName);
+ return eSaveResult == SAVE_SUCCESSFULL ? SEND_MAIL_OK : SEND_MAIL_ERROR;
+}
+
+SfxMailModel::SendMailResult SfxMailModel::Send( const css::uno::Reference< css::frame::XFrame >& xFrame )
+{
+ OSL_ENSURE(!maAttachedDocuments.empty(),"No document added!");
+ SendMailResult eResult = SEND_MAIL_ERROR;
+ if ( !maAttachedDocuments.empty() )
+ {
+ css::uno::Reference < XMultiServiceFactory > xMgr = ::comphelper::getProcessServiceFactory();
+ if ( xMgr.is() )
+ {
+ css::uno::Reference< XSimpleMailClientSupplier > xSimpleMailClientSupplier;
+
+ // Prefer the SimpleSystemMail service if available
+ xSimpleMailClientSupplier = css::uno::Reference< XSimpleMailClientSupplier >(
+ xMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SimpleSystemMail" ))),
+ UNO_QUERY );
+
+ if ( ! xSimpleMailClientSupplier.is() )
+ {
+ xSimpleMailClientSupplier = css::uno::Reference< XSimpleMailClientSupplier >(
+ xMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SimpleCommandMail" ))),
+ UNO_QUERY );
+ }
+
+ if ( xSimpleMailClientSupplier.is() )
+ {
+ css::uno::Reference< XSimpleMailClient > xSimpleMailClient = xSimpleMailClientSupplier->querySimpleMailClient();
+
+ if ( !xSimpleMailClient.is() )
+ {
+ // no mail client support => message box!
+ return SEND_MAIL_ERROR;
+ }
+
+ // we have a simple mail client
+ css::uno::Reference< XSimpleMailMessage > xSimpleMailMessage = xSimpleMailClient->createSimpleMailMessage();
+ if ( xSimpleMailMessage.is() )
+ {
+ sal_Int32 nSendFlags = SimpleMailClientFlags::DEFAULTS;
+ if ( maFromAddress.Len() == 0 )
+ {
+ // from address not set, try figure out users e-mail address
+ CreateFromAddress_Impl( maFromAddress );
+ }
+ xSimpleMailMessage->setOriginator( maFromAddress );
+
+ sal_Int32 nToCount = mpToList ? mpToList->Count() : 0;
+ sal_Int32 nCcCount = mpCcList ? mpCcList->Count() : 0;
+ sal_Int32 nCcSeqCount = nCcCount;
+
+ // set recipient (only one) for this simple mail server!!
+ if ( nToCount > 1 )
+ {
+ nCcSeqCount = nToCount - 1 + nCcCount;
+ xSimpleMailMessage->setRecipient( *mpToList->GetObject( 0 ));
+ nSendFlags = SimpleMailClientFlags::NO_USER_INTERFACE;
+ }
+ else if ( nToCount == 1 )
+ {
+ xSimpleMailMessage->setRecipient( *mpToList->GetObject( 0 ));
+ nSendFlags = SimpleMailClientFlags::NO_USER_INTERFACE;
+ }
+
+ // all other recipient must be handled with CC recipients!
+ if ( nCcSeqCount > 0 )
+ {
+ sal_Int32 nIndex = 0;
+ Sequence< OUString > aCcRecipientSeq;
+
+ aCcRecipientSeq.realloc( nCcSeqCount );
+ if ( nCcSeqCount > nCcCount )
+ {
+ for ( sal_Int32 i = 1; i < nToCount; ++i )
+ {
+ aCcRecipientSeq[nIndex++] = *mpToList->GetObject(i);
+ }
+ }
+
+ for ( sal_Int32 i = 0; i < nCcCount; i++ )
+ {
+ aCcRecipientSeq[nIndex++] = *mpCcList->GetObject(i);
+ }
+ xSimpleMailMessage->setCcRecipient( aCcRecipientSeq );
+ }
+
+ sal_Int32 nBccCount = mpBccList ? mpBccList->Count() : 0;
+ if ( nBccCount > 0 )
+ {
+ Sequence< OUString > aBccRecipientSeq( nBccCount );
+ for ( sal_Int32 i = 0; i < nBccCount; ++i )
+ {
+ aBccRecipientSeq[i] = *mpBccList->GetObject(i);
+ }
+ xSimpleMailMessage->setBccRecipient( aBccRecipientSeq );
+ }
+
+ Sequence< OUString > aAttachmentSeq(&(maAttachedDocuments[0]),maAttachedDocuments.size());
+
+ xSimpleMailMessage->setSubject( maSubject );
+ xSimpleMailMessage->setAttachement( aAttachmentSeq );
+
+ sal_Bool bSend( sal_False );
+ try
+ {
+ xSimpleMailClient->sendSimpleMailMessage( xSimpleMailMessage, nSendFlags );
+ bSend = sal_True;
+ }
+ catch ( IllegalArgumentException& )
+ {
+ }
+ catch ( Exception& )
+ {
+ }
+
+ if ( bSend == sal_False )
+ {
+ css::uno::Reference< css::awt::XWindow > xParentWindow = xFrame->getContainerWindow();
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ Window* pParentWindow = VCLUnoHelper::GetWindow( xParentWindow );
+
+ ErrorBox aBox( pParentWindow, SfxResId( RID_ERRBOX_MAIL_CONFIG ));
+ aBox.Execute();
+ eResult = SEND_MAIL_CANCELLED;
+ }
+ else
+ eResult = SEND_MAIL_OK;
+ }
+ }
+ }
+ }
+ else
+ eResult = SEND_MAIL_CANCELLED;
+
+ return eResult;
+}
+
+SfxMailModel::SendMailResult SfxMailModel::SaveAndSend( const css::uno::Reference< css::frame::XFrame >& xFrame, const rtl::OUString& rTypeName )
+{
+ SaveResult eSaveResult;
+ SendMailResult eResult = SEND_MAIL_ERROR;
+ rtl::OUString aFileName;
+
+ eSaveResult = SaveDocumentAsFormat( rtl::OUString(), xFrame, rTypeName, aFileName );
+
+ if ( eSaveResult == SAVE_SUCCESSFULL )
+ {
+ maAttachedDocuments.push_back( aFileName );
+ return Send( xFrame );
+ }
+ else if ( eSaveResult == SAVE_CANCELLED )
+ eResult = SEND_MAIL_CANCELLED;
+
+ return eResult;
+}
+
+// functions -------------------------------------------------------------
+
+BOOL CreateFromAddress_Impl( String& rFrom )
+
+/* [Beschreibung]
+
+ Diese Funktion versucht mit Hilfe des IniManagers eine From-Adresse
+ zu erzeugen. daf"ur werden die Felder 'Vorname', 'Name' und 'EMail'
+ aus der Applikations-Ini-Datei ausgelesen. Sollten diese Felder
+ nicht gesetzt sein, wird FALSE zur"uckgegeben.
+
+ [R"uckgabewert]
+
+ TRUE: Adresse konnte erzeugt werden.
+ FALSE: Adresse konnte nicht erzeugt werden.
+*/
+
+{
+ SvtUserOptions aUserCFG;
+ String aName = aUserCFG.GetLastName ();
+ String aFirstName = aUserCFG.GetFirstName ();
+ if ( aFirstName.Len() || aName.Len() )
+ {
+ if ( aFirstName.Len() )
+ {
+ rFrom = TRIM( aFirstName );
+
+ if ( aName.Len() )
+ rFrom += ' ';
+ }
+ rFrom += TRIM( aName );
+ // unerlaubte Zeichen entfernen
+ rFrom.EraseAllChars( '<' );
+ rFrom.EraseAllChars( '>' );
+ rFrom.EraseAllChars( '@' );
+ }
+ String aEmailName = aUserCFG.GetEmail();
+
+ // unerlaubte Zeichen entfernen
+ aEmailName.EraseAllChars( '<' );
+ aEmailName.EraseAllChars( '>' );
+
+ if ( aEmailName.Len() )
+ {
+ if ( rFrom.Len() )
+ rFrom += ' ';
+ ( ( rFrom += '<' ) += TRIM( aEmailName ) ) += '>';
+ }
+ else
+ rFrom.Erase();
+ return ( rFrom.Len() > 0 );
+}
diff --git a/sfx2/source/dialog/mailwindow.src b/sfx2/source/dialog/mailwindow.src
new file mode 100644
index 000000000000..e5648e7f414f
--- /dev/null
+++ b/sfx2/source/dialog/mailwindow.src
@@ -0,0 +1,76 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "dialog.hrc"
+#include "helpid.hrc"
+
+// RID_ERRBOX_MAIL_CONFIG ---------------------------------------------------
+
+ErrorBox RID_ERRBOX_MAIL_CONFIG
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ MESSAGE [ en-US ] = "%PRODUCTNAME was unable to find a working e-mail configuration. Please save this document locally instead and attach it from within your e-mail client." ;
+};
+
+// ------------------------------------------------------------------- EOF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/dialog/mgetempl.cxx b/sfx2/source/dialog/mgetempl.cxx
new file mode 100644
index 000000000000..d97847f5b6e0
--- /dev/null
+++ b/sfx2/source/dialog/mgetempl.cxx
@@ -0,0 +1,682 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// include ---------------------------------------------------------------
+
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#include <vcl/field.hxx>
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/style.hxx>
+#ifndef GCC
+#endif
+
+#include <sfx2/styfitem.hxx>
+#include <sfx2/styledlg.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/mgetempl.hxx>
+#include <sfx2/objsh.hxx>
+#include "sfxtypes.hxx"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/module.hxx>
+
+#include <sfx2/sfx.hrc>
+#include "dialog.hrc"
+#include "mgetempl.hrc"
+
+#ifndef _SFX_STYLE_HRC
+#include <svl/style.hrc>
+#endif
+
+// SfxManageStyleSheetPage -----------------------------------------------
+
+SfxManageStyleSheetPage::SfxManageStyleSheetPage( Window* pParent, const SfxItemSet& rAttrSet ) :
+
+ SfxTabPage( pParent, SfxResId( TP_MANAGE_STYLES ), rAttrSet ),
+
+ aNameFt ( this, SfxResId( FT_NAME ) ),
+ aNameEd ( this, SfxResId( ED_NAME ) ),
+ aNameMLE ( this, SfxResId( MLE_NAME ) ),
+ aAutoCB ( this, SfxResId( CB_AUTO ) ),
+
+ aFollowFt ( this, SfxResId( FT_NEXT ) ),
+ aFollowLb ( this, SfxResId( LB_NEXT ) ),
+
+ aBaseFt ( this, SfxResId( FT_BASE ) ),
+ aBaseLb ( this, SfxResId( LB_BASE ) ),
+
+ aFilterFt ( this, SfxResId( FT_REGION ) ),
+ aFilterLb ( this, SfxResId( LB_REGION ) ),
+
+ aDescFt ( this, SfxResId( FT_DESC ) ),
+ aDescED ( this, SfxResId( ED_DESC ) ),
+ aDescGb ( this, SfxResId( GB_DESC ) ),
+
+ pStyle( &( (SfxStyleDialog*)pParent->GetParent() )->GetStyleSheet() ),
+
+ pItem ( 0 ),
+ bModified ( FALSE ),
+ aName ( pStyle->GetName() ),
+ aFollow ( pStyle->GetFollow() ),
+ aParent ( pStyle->GetParent() ),
+ nFlags ( pStyle->GetMask() )
+
+/* [Beschreibung]
+
+ Konstruktor; initialisiert die ListBoxen mit den Vorlagen
+
+*/
+
+{
+ FreeResource();
+
+ if ( IsBackground() )
+ aDescED.SetBackground( GetBackground() );
+ FixedInfo* pInfo = new FixedInfo( this );
+ aDescED.SetFont( pInfo->GetFont() );
+ delete pInfo;
+
+ aDescED.Hide();
+ aDescFt.Show();
+
+ // diese Page braucht ExchangeSupport
+ SetExchangeSupport();
+
+ ResMgr* pResMgr = SFX_APP()->GetModule_Impl()->GetResMgr();
+ DBG_ASSERT( pResMgr, "kein ResMgr am Modul" );
+ pFamilies = new SfxStyleFamilies( ResId( DLG_STYLE_DESIGNER, *pResMgr ) );
+
+ SfxStyleSheetBasePool* pPool = 0;
+ SfxObjectShell* pDocShell = SfxObjectShell::Current();
+
+ if ( pDocShell )
+ pPool = pDocShell->GetStyleSheetPool();
+ DBG_ASSERT( pPool, "kein Pool oder keine DocShell" );
+
+ if ( pPool )
+ {
+ pPool->SetSearchMask( pStyle->GetFamily() );
+ pPool->First(); // fuer SW - interne Liste updaten
+ }
+
+ if ( !pStyle->GetName().Len() && pPool )
+ {
+ // NullString als Name -> Name generieren
+ String aNoName( SfxResId( STR_NONAME ) );
+ USHORT nNo = 1;
+ String aNo( aNoName );
+ aNoName += String::CreateFromInt32( nNo );
+ while ( pPool->Find( aNoName ) )
+ {
+ ++nNo;
+ aNoName = aNo;
+ aNoName += String::CreateFromInt32( nNo );
+ }
+ pStyle->SetName( aNoName );
+ aName = aNoName;
+ aFollow = pStyle->GetFollow();
+ aParent = pStyle->GetParent();
+ }
+ aNameEd.SetText(pStyle->GetName());
+
+ // Set the field read-only if it is NOT an user-defined style
+ // but allow selecting and copying
+ if ( !pStyle->IsUserDefined() ) {
+ aNameEd.SetReadOnly();
+ aNameEd.Hide();
+
+ aNameMLE.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
+ aNameMLE.SetText( pStyle->GetName() );
+ aNameMLE.EnableCursor( FALSE );
+ aNameMLE.Show();
+ }
+
+ if ( pStyle->HasFollowSupport() && pPool )
+ {
+ SfxStyleSheetBase* pPoolStyle = pPool->First();
+
+ while ( pPoolStyle )
+ {
+ aFollowLb.InsertEntry( pPoolStyle->GetName() );
+ pPoolStyle = pPool->Next();
+ }
+
+ // eine neue Vorlage ist noch nicht im Pool
+ if ( LISTBOX_ENTRY_NOTFOUND == aFollowLb.GetEntryPos( pStyle->GetName() ) )
+ aFollowLb.InsertEntry( pStyle->GetName() );
+ }
+ else
+ {
+ aFollowFt.Hide();
+ aFollowLb.Hide();
+
+ aFilterFt.SetPosPixel( aBaseFt.GetPosPixel() );
+ aFilterLb.SetPosPixel( aBaseLb.GetPosPixel() );
+
+ aBaseFt.SetPosPixel( aFollowFt.GetPosPixel() );
+ aBaseLb.SetPosPixel( aFollowLb.GetPosPixel() );
+ }
+
+ if ( pStyle->HasParentSupport() && pPool )
+ {
+ if ( pStyle->HasClearParentSupport() )
+ // die Basisvorlage darf auf NULL gesetzt werden
+ aBaseLb.InsertEntry( String( SfxResId( STR_NONE ) ) );
+
+ SfxStyleSheetBase* pPoolStyle = pPool->First();
+
+ while ( pPoolStyle )
+ {
+ const String aStr( pPoolStyle->GetName() );
+ // eigener Namen nicht als Basisvorlage
+ if ( aStr != aName )
+ aBaseLb.InsertEntry( aStr );
+ pPoolStyle = pPool->Next();
+ }
+ }
+ else
+ {
+ aBaseFt.Disable();
+ aBaseLb.Disable();
+ }
+ USHORT nCount = pFamilies->Count();
+
+ USHORT i;
+ for ( i = 0; i < nCount; ++i )
+ {
+ pItem = pFamilies->GetObject(i);
+
+ if ( pItem->GetFamily() == pStyle->GetFamily() )
+ break;
+ }
+
+ USHORT nStyleFilterIdx = 0xffff;
+
+ if ( i < nCount )
+ {
+ // Filterflags
+ const SfxStyleFilter& rList = pItem->GetFilterList();
+ nCount = (USHORT)rList.Count();
+ USHORT nIdx = 0;
+ USHORT nMask = pStyle->GetMask() & ~SFXSTYLEBIT_USERDEF;
+
+ if ( !nMask ) // Benutzervorlage?
+ nMask = pStyle->GetMask();
+
+ for ( i = 0; i < nCount; ++i )
+ {
+ SfxFilterTupel* pTupel = rList.GetObject(i);
+
+ if ( pTupel->nFlags != SFXSTYLEBIT_AUTO &&
+ pTupel->nFlags != SFXSTYLEBIT_USED &&
+// pTupel->nFlags != SFXSTYLEBIT_USERDEF &&
+ pTupel->nFlags != SFXSTYLEBIT_ALL )
+ {
+ aFilterLb.InsertEntry( pTupel->aName, nIdx );
+ aFilterLb.SetEntryData(nIdx, (void*)(long)i);
+
+ if ( ( pTupel->nFlags & nMask ) == nMask )
+ nStyleFilterIdx = nIdx;
+ ++nIdx;
+ }
+ }
+
+ if ( nStyleFilterIdx != 0xFFFF )
+ aFilterLb.SelectEntryPos( nStyleFilterIdx );
+ }
+
+ if ( !aFilterLb.GetEntryCount() || !pStyle->IsUserDefined() )
+ {
+ pItem = 0;
+ aFilterFt.Disable();
+ aFilterLb.Disable();
+ }
+ else
+ aFilterLb.SaveValue();
+ SetDescriptionText_Impl();
+
+ if ( aFollowLb.IsEnabled() || aBaseLb.IsEnabled() )
+ {
+ aNameEd.SetGetFocusHdl(
+ LINK( this, SfxManageStyleSheetPage, GetFocusHdl ) );
+ aNameEd.SetLoseFocusHdl(
+ LINK( this, SfxManageStyleSheetPage, LoseFocusHdl ) );
+ }
+ // ist es ein Style mit automatischem Update? (nur SW)
+ if(SFX_ITEM_SET == rAttrSet.GetItemState(SID_ATTR_AUTO_STYLE_UPDATE))
+ {
+ Size aSize = aNameEd.GetSizePixel();
+ aSize.Width() /= 2;
+ aNameEd.SetSizePixel(aSize);
+ aAutoCB.Show();
+ }
+}
+
+//-------------------------------------------------------------------------
+
+SfxManageStyleSheetPage::~SfxManageStyleSheetPage()
+
+/* [Beschreibung]
+
+ Destruktor; Freigabe der Daten
+
+*/
+
+{
+ aNameEd.SetGetFocusHdl( Link() );
+ aNameEd.SetLoseFocusHdl( Link() );
+ delete pFamilies;
+ pItem = 0;
+ pStyle = 0;
+
+}
+
+//-------------------------------------------------------------------------
+
+void SfxManageStyleSheetPage::UpdateName_Impl( ListBox* pBox,
+ const String& rNew )
+
+/* [Beschreibung]
+
+ Nach der "Anderung eines Vorlagennamens die ListBox pBox
+ aktualisieren
+
+ [Parameter]
+
+ ListBox* pBox ListBox, deren Eintr"age aktualisiert
+ werden sollen
+ const String& rNew der neue Name
+
+*/
+
+{
+ if ( pBox->IsEnabled() )
+ {
+ // ist der aktuelle Eintrag, dessen Namen modifizieren wurde
+ const BOOL bSelect = pBox->GetSelectEntry() == aBuf;
+ pBox->RemoveEntry( aBuf );
+ pBox->InsertEntry( rNew );
+
+ if ( bSelect )
+ pBox->SelectEntry( rNew );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+void SfxManageStyleSheetPage::SetDescriptionText_Impl()
+
+/* [Beschreibung]
+
+ Attributbeschreibung setzen. daf"ur die eingestellte Metrik besorgen.
+*/
+
+{
+ SfxMapUnit eUnit = SFX_MAPUNIT_CM;
+// FieldUnit eFieldUnit = pSfxApp->GetOptions().GetMetric();
+ FieldUnit eFieldUnit( FUNIT_CM );
+ SfxModule* pModule = SfxModule::GetActiveModule();
+ if ( pModule )
+ {
+ const SfxPoolItem* pPoolItem = pModule->GetItem( SID_ATTR_METRIC );
+ if ( pPoolItem )
+ eFieldUnit = (FieldUnit)( (SfxUInt16Item*)pPoolItem )->GetValue();
+ }
+
+ switch ( eFieldUnit )
+ {
+ case FUNIT_MM: eUnit = SFX_MAPUNIT_MM; break;
+
+ case FUNIT_CM:
+ case FUNIT_M:
+ case FUNIT_KM: eUnit = SFX_MAPUNIT_CM; break;
+
+ case FUNIT_POINT:
+ case FUNIT_PICA: eUnit = SFX_MAPUNIT_POINT; break;
+
+ case FUNIT_INCH:
+ case FUNIT_FOOT:
+ case FUNIT_MILE: eUnit = SFX_MAPUNIT_INCH; break;
+
+ default:
+ DBG_ERRORFILE( "not supported fieldunit" );
+ }
+ aDescFt.SetText( pStyle->GetDescription( eUnit ) );
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxManageStyleSheetPage, GetFocusHdl, Edit *, pEdit )
+
+/* [Beschreibung]
+
+ StarView Handler; GetFocus-Handler des Edits mit dem Vorlagennamen.
+
+*/
+
+{
+ aBuf = pEdit->GetText().EraseLeadingChars();
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxManageStyleSheetPage, GetFocusHdl, Edit *, pEdit )
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxManageStyleSheetPage, LoseFocusHdl, Edit *, pEdit )
+
+/* [Beschreibung]
+
+ StarView Handler; LoseFocus-Handler des Edits mit dem Vorlagennamen.
+ Dieser aktualisiert ggf. die Listbox mit den Folgevorlagen.
+ In der Listbox mit den Basisvorlagen ist die aktuelle Vorlage
+ selbst nicht enthalten.
+
+*/
+
+{
+ const String aStr( pEdit->GetText().EraseLeadingChars() );
+ pEdit->SetText( aStr );
+ // ggf. Listbox der Basisvorlagen aktualisieren
+ if ( aStr != aBuf )
+ UpdateName_Impl( &aFollowLb, aStr );
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxManageStyleSheetPage, LoseFocusHdl, Edit *, pEdit )
+
+//-------------------------------------------------------------------------
+
+BOOL SfxManageStyleSheetPage::FillItemSet( SfxItemSet& rSet )
+
+/* [Beschreibung]
+
+
+ Handler f"ur das Setzen der (modifizierten) Daten. Wird aus
+ dem Ok des SfxTabDialog gerufen.
+
+ [Parameter]
+
+ SfxItemSet &rAttrSet das Set, das die Daten entgegennimmt.
+
+
+ [R"uckgabewert]
+
+ BOOL TRUE: es hat eine "Anderung der Daten
+ stattgefunden
+ FALSE: es hat keine "Anderung der Daten
+ stattgefunden
+
+ [Querverweise]
+
+ <class SfxTabDialog>
+
+*/
+
+{
+ const USHORT nFilterIdx = aFilterLb.GetSelectEntryPos();
+
+ // Filter setzen
+
+ if ( LISTBOX_ENTRY_NOTFOUND != nFilterIdx &&
+ nFilterIdx != aFilterLb.GetSavedValue() &&
+ aFilterLb.IsEnabled() )
+ {
+ bModified = TRUE;
+ DBG_ASSERT( pItem, "kein Item" );
+ // geht nur bei Benutzervorlagen
+#if OSL_DEBUG_LEVEL > 1
+ USHORT nIdx = (USHORT)(long)aFilterLb.GetEntryData( nFilterIdx );
+ SfxFilterTupel* p;
+ p = pItem->GetFilterList().GetObject( nIdx );
+#endif
+ USHORT nMask = pItem->GetFilterList().GetObject(
+ (USHORT)(long)aFilterLb.GetEntryData( nFilterIdx ) )->nFlags |
+ SFXSTYLEBIT_USERDEF;
+ pStyle->SetMask( nMask );
+ }
+ if(aAutoCB.IsVisible() &&
+ aAutoCB.IsChecked() != aAutoCB.GetSavedValue())
+ {
+ rSet.Put(SfxBoolItem(SID_ATTR_AUTO_STYLE_UPDATE, aAutoCB.IsChecked()));
+ }
+
+ return bModified;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxManageStyleSheetPage::Reset( const SfxItemSet& /*rAttrSet*/ )
+
+/* [Beschreibung]
+
+
+ Handler f"ur das Initialisieren der Seite mit den initialen Daten.
+
+ [Parameter]
+
+ const SfxItemSet &rAttrSet das Set mit den Daten
+
+
+ [Querverweise]
+
+ <class SfxTabDialog>
+
+*/
+
+{
+ bModified = FALSE;
+ String sCmp( pStyle->GetName() );
+
+ if ( sCmp != aName )
+ pStyle->SetName( aName );
+ aNameEd.SetText( aName );
+
+ if ( aFollowLb.IsEnabled() )
+ {
+ sCmp = pStyle->GetFollow();
+
+ if ( sCmp != aFollow )
+ pStyle->SetFollow( aFollow );
+
+ if ( !aFollow.Len() )
+ aFollowLb.SelectEntry( aName );
+ else
+ aFollowLb.SelectEntry( aFollow );
+ }
+
+ if ( aBaseLb.IsEnabled() )
+ {
+ sCmp = pStyle->GetParent();
+
+ if ( sCmp != aParent )
+ pStyle->SetParent( aParent );
+
+ if ( !aParent.Len() )
+ aBaseLb.SelectEntry( String( SfxResId( STR_NONE ) ) );
+ else
+ aBaseLb.SelectEntry( aParent );
+
+ if ( String( SfxResId( STR_STANDARD ) ) == aName )
+ {
+ // die Standardvorlage kann nicht verkn"upft werden
+ aBaseFt.Disable();
+ aBaseLb.Disable();
+ }
+ }
+
+ if ( aFilterLb.IsEnabled() )
+ {
+ USHORT nCmp = pStyle->GetMask();
+
+ if ( nCmp != nFlags )
+ pStyle->SetMask( nFlags );
+ aFilterLb.SelectEntryPos( aFilterLb.GetSavedValue() );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+SfxTabPage* SfxManageStyleSheetPage::Create( Window* pParent,
+ const SfxItemSet &rAttrSet )
+
+/* [Beschreibung]
+
+
+ Factory f"ur das Erzeugen der Seite
+
+ [Querverweise]
+
+ <class SfxTabDialog>
+
+*/
+
+{
+ return new SfxManageStyleSheetPage( pParent, rAttrSet );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxManageStyleSheetPage::ActivatePage( const SfxItemSet& rSet)
+
+/* [Beschreibung]
+
+ ActivatePage- Handler des SfxTabDialog; wird f"ur die Aktualisierung
+ des beschreibenden Textes verwendet, da sich dieser durch "Anderungen
+ der Daten anderer Seiten ge"andert haben kann.
+
+ [Parameter]
+
+ const SfxItemSet& das Set f"ur den Datenaustausch; wird
+ hier nicht verwendet.
+
+ [Querverweise]
+
+ <SfxTabDialog::ActivatePage(const SfxItemSet &)>
+
+*/
+
+{
+ SetDescriptionText_Impl();
+
+ // ist es ein Style mit automatischem Update? (nur SW)
+ const SfxPoolItem* pPoolItem;
+
+ if ( SFX_ITEM_SET ==
+ rSet.GetItemState( SID_ATTR_AUTO_STYLE_UPDATE, FALSE, &pPoolItem ) )
+ aAutoCB.Check( ( (const SfxBoolItem*)pPoolItem )->GetValue() );
+ aAutoCB.SaveValue();
+}
+
+//-------------------------------------------------------------------------
+
+int SfxManageStyleSheetPage::DeactivatePage( SfxItemSet* pItemSet )
+
+/* [Beschreibung]
+
+ DeactivatePage- Handler des SfxTabDialog; die Daten werden
+ an der Vorlage eingestellt, damit die richtige Vererbung
+ f"ur die anderen Seiten des Dialoges vorliegt.
+ Im Fehlerfall wird das Verlassen der Seite unterbunden.
+
+ [Parameter]
+
+ SfxItemSet* das Set f"ur den Datenaustausch; wird hier nicht verwendet.
+
+ [Querverweise]
+
+ <SfxTabDialog::DeactivatePage(SfxItemSet*)>
+
+*/
+
+{
+ int nRet = SfxTabPage::LEAVE_PAGE;
+
+ if ( aNameEd.IsModified() )
+ {
+ // bei <Enter> wird kein LoseFocus() durch StarView ausgel"ost
+ if ( aNameEd.HasFocus() )
+ LoseFocusHdl( &aNameEd );
+
+ if ( !pStyle->SetName( aNameEd.GetText().EraseLeadingChars() ) )
+ {
+ InfoBox aBox( this, SfxResId( MSG_TABPAGE_INVALIDNAME ) );
+ aBox.Execute();
+ aNameEd.GrabFocus();
+ aNameEd.SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
+ return SfxTabPage::KEEP_PAGE;
+ }
+ bModified = TRUE;
+ }
+
+ if ( pStyle->HasFollowSupport() && aFollowLb.IsEnabled() )
+ {
+ const String aFollowEntry( aFollowLb.GetSelectEntry() );
+
+ if ( pStyle->GetFollow() != aFollowEntry )
+ {
+ if ( !pStyle->SetFollow( aFollowEntry ) )
+ {
+ InfoBox aBox( this, SfxResId( MSG_TABPAGE_INVALIDSTYLE ) );
+ aBox.Execute();
+ aFollowLb.GrabFocus();
+ return SfxTabPage::KEEP_PAGE;
+ }
+ bModified = TRUE;
+ }
+ }
+
+ if ( aBaseLb.IsEnabled() )
+ {
+ String aParentEntry( aBaseLb.GetSelectEntry() );
+
+ if ( String( SfxResId( STR_NONE ) ) == aParentEntry || aParentEntry == pStyle->GetName() )
+ aParentEntry.Erase();
+
+ if ( pStyle->GetParent() != aParentEntry )
+ {
+ if ( !pStyle->SetParent( aParentEntry ) )
+ {
+ InfoBox aBox( this, SfxResId( MSG_TABPAGE_INVALIDPARENT ) );
+ aBox.Execute();
+ aBaseLb.GrabFocus();
+ return SfxTabPage::KEEP_PAGE;
+ }
+ bModified = TRUE;
+ nRet |= (int)SfxTabPage::REFRESH_SET;
+ }
+ }
+
+ if ( pItemSet )
+ FillItemSet( *pItemSet );
+
+ return nRet;
+}
+
diff --git a/sfx2/source/dialog/mgetempl.hrc b/sfx2/source/dialog/mgetempl.hrc
new file mode 100644
index 000000000000..a34700846f9c
--- /dev/null
+++ b/sfx2/source/dialog/mgetempl.hrc
@@ -0,0 +1,39 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#define ED_NAME 2
+#define MLE_NAME 13
+#define LB_NEXT 4
+#define FT_BASE 5
+#define LB_BASE 6
+#define LB_REGION 8
+#define FT_DESC 9
+#define GB_DESC 10
+#define FT_REGION 7
+#define FT_NEXT 3
+#define FT_NAME 1
+#define ED_DESC 11
+#define CB_AUTO 12
diff --git a/sfx2/source/dialog/mgetempl.src b/sfx2/source/dialog/mgetempl.src
new file mode 100644
index 000000000000..c478ed715646
--- /dev/null
+++ b/sfx2/source/dialog/mgetempl.src
@@ -0,0 +1,166 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+ // include ---------------------------------------------------------------
+#include <sfx2/sfx.hrc>
+#include "helpid.hrc"
+#include "mgetempl.hrc"
+ // pragma ----------------------------------------------------------------
+
+ // TP_MANAGE_STYLES ------------------------------------------------------
+TabPage TP_MANAGE_STYLES
+{
+ HelpId = HID_MANAGE_STYLES ;
+ Hide = TRUE ;
+ Size = MAP_APPFONT ( 260 , 185 ) ;
+ FixedText FT_NAME
+ {
+ Pos = MAP_APPFONT ( 6 , 8 ) ;
+ Size = MAP_APPFONT ( 61 , 10 ) ;
+ Text [ en-US ] = "~Name" ;
+ };
+ Edit ED_NAME
+ {
+ HelpID = "sfx2:Edit:TP_MANAGE_STYLES:ED_NAME";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 6 ) ;
+ Size = MAP_APPFONT ( 184 , 12 ) ;
+ };
+ MultiLineEdit MLE_NAME
+ {
+ Pos = MAP_APPFONT ( 70 , 8 ) ;
+ Size = MAP_APPFONT ( 80 , 12 ) ;
+ Border = FALSE;
+ ReadOnly = TRUE;
+ Hide = TRUE;
+ };
+ CheckBox CB_AUTO
+ {
+ HelpID = "sfx2:CheckBox:TP_MANAGE_STYLES:CB_AUTO";
+ Pos = MAP_APPFONT ( 164 , 8 ) ;
+ Size = MAP_APPFONT ( 90 , 10 ) ;
+ Hide = TRUE ;
+ Text [ en-US ] = "~AutoUpdate" ;
+ };
+ FixedText FT_NEXT
+ {
+ Pos = MAP_APPFONT ( 6 , 26 ) ;
+ Size = MAP_APPFONT ( 61 , 10 ) ;
+ Text [ en-US ] = "Ne~xt Style" ;
+ };
+ ListBox LB_NEXT
+ {
+ HelpID = "sfx2:ListBox:TP_MANAGE_STYLES:LB_NEXT";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 24 ) ;
+ Size = MAP_APPFONT ( 184 , 65 ) ;
+ DropDown = TRUE ;
+ Sort = TRUE ;
+ };
+ FixedText FT_BASE
+ {
+ Pos = MAP_APPFONT ( 6 , 44 ) ;
+ Size = MAP_APPFONT ( 61 , 10 ) ;
+ /* ### ACHTUNG: Neuer Text in Resource? ~Verknüpft mit : ~Verkn³pft mit */
+ /* ### ACHTUNG: Neuer Text in Resource? ~Verknüpft mit : ~Verkn³pft mit */
+ Text [ en-US ] = "Linked with" ;
+ };
+ ListBox LB_BASE
+ {
+ HelpID = "sfx2:ListBox:TP_MANAGE_STYLES:LB_BASE";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 42 ) ;
+ Size = MAP_APPFONT ( 184 , 65 ) ;
+ DropDown = TRUE ;
+ Sort = TRUE ;
+ };
+ FixedText FT_REGION
+ {
+ Pos = MAP_APPFONT ( 6 , 62 ) ;
+ Size = MAP_APPFONT ( 61 , 10 ) ;
+ Text [ en-US ] = "~Category" ;
+ };
+ ListBox LB_REGION
+ {
+ HelpID = "sfx2:ListBox:TP_MANAGE_STYLES:LB_REGION";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 70 , 60 ) ;
+ Size = MAP_APPFONT ( 184 , 64 ) ;
+ DropDown = TRUE ;
+ };
+ FixedText FT_DESC
+ {
+ Pos = MAP_APPFONT ( 12 , 88 ) ;
+ Size = MAP_APPFONT ( 236 , 85 ) ;
+ WordBreak = TRUE ;
+ Hide = TRUE ;
+ };
+ MultiLineEdit ED_DESC
+ {
+ HelpID = "sfx2:MultiLineEdit:TP_MANAGE_STYLES:ED_DESC";
+ Pos = MAP_APPFONT ( 12 , 88 ) ;
+ Size = MAP_APPFONT ( 236 , 85 ) ;
+ ReadOnly = TRUE ;
+ IgnoreTab = TRUE;
+ };
+ FixedLine GB_DESC
+ {
+ Pos = MAP_APPFONT ( 6 , 77 ) ;
+ Size = MAP_APPFONT ( 248 , 8 ) ;
+ Text [ en-US ] = "Contains" ;
+ };
+};
+ // ********************************************************************** EOF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/dialog/navigat.cxx b/sfx2/source/dialog/navigat.cxx
new file mode 100644
index 000000000000..290886528e24
--- /dev/null
+++ b/sfx2/source/dialog/navigat.cxx
@@ -0,0 +1,100 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// includes *******************************************************************
+
+#ifndef GCC
+#endif
+
+#include <sfx2/navigat.hxx>
+#include <sfx2/sfx.hrc>
+#include <sfx2/app.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "helpid.hrc"
+
+SFX_IMPL_DOCKINGWINDOW( SfxNavigatorWrapper , SID_NAVIGATOR );
+
+SfxNavigatorWrapper::SfxNavigatorWrapper( Window* pParentWnd ,
+ USHORT nId ,
+ SfxBindings* pBindings ,
+ SfxChildWinInfo* pInfo )
+ : SfxChildWindow( pParentWnd , nId )
+{
+ pWindow = new SfxNavigator( pBindings, this, pParentWnd,
+ WB_STDDOCKWIN | WB_CLIPCHILDREN | WB_SIZEABLE | WB_3DLOOK | WB_ROLLABLE);
+ eChildAlignment = SFX_ALIGN_NOALIGNMENT;
+
+ pWindow->SetHelpId ( HID_NAVIGATOR_WINDOW );
+ pWindow->SetOutputSizePixel( Size( 270, 240 ) );
+
+ ( ( SfxDockingWindow* ) pWindow )->Initialize( pInfo );
+ SetHideNotDelete( TRUE );
+}
+
+SfxNavigator::SfxNavigator( SfxBindings* pBind ,
+ SfxChildWindow* pChildWin ,
+ Window* pParent ,
+ WinBits nBits )
+ : SfxDockingWindow( pBind ,
+ pChildWin ,
+ pParent ,
+ nBits )
+ , pWrapper( pChildWin )
+{
+ SetText( String( SfxResId( SID_NAVIGATOR ) ) );
+}
+
+void SfxNavigator::Resize()
+{
+ SfxDockingWindow::Resize();
+ if ( pWrapper->GetContextWindow() )
+ pWrapper->GetContextWindow()->SetSizePixel( GetOutputSizePixel() );
+}
+
+void SfxNavigator::Resizing( Size &rSize )
+{
+ SfxDockingWindow::Resizing( rSize );
+
+ SfxChildWindowContext *pCon = GetChildWindow_Impl()->GetContext_Impl();
+ DBG_ASSERT( pCon, "Kein Context!" );
+ if ( pCon )
+ pCon->Resizing( rSize );
+}
+
+BOOL SfxNavigator::Close()
+{
+ SfxChildWindowContext *pCon = GetChildWindow_Impl()->GetContext_Impl();
+ DBG_ASSERT( pCon, "Kein Context!" );
+ if ( !pCon || pCon->Close() )
+ return SfxDockingWindow::Close();
+ else
+ return FALSE;
+}
+
diff --git a/sfx2/source/dialog/newstyle.cxx b/sfx2/source/dialog/newstyle.cxx
new file mode 100644
index 000000000000..8235333857d5
--- /dev/null
+++ b/sfx2/source/dialog/newstyle.cxx
@@ -0,0 +1,108 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// INCLUDE ---------------------------------------------------------------
+#include <svl/style.hxx>
+#ifndef GCC
+#endif
+
+#include <sfx2/newstyle.hxx>
+#include "dialog.hrc"
+#include "newstyle.hrc"
+#include "sfx2/sfxresid.hxx"
+
+// PRIVATE METHODES ------------------------------------------------------
+
+IMPL_LINK( SfxNewStyleDlg, OKHdl, Control *, pControl )
+{
+ (void)pControl; //unused
+ const String aName( aColBox.GetText() );
+ SfxStyleSheetBase* pStyle = rPool.Find( aName, rPool.GetSearchFamily(), SFXSTYLEBIT_ALL );
+ if ( pStyle )
+ {
+ if ( !pStyle->IsUserDefined() )
+ {
+ InfoBox( this, SfxResId( MSG_POOL_STYLE_NAME ) ).Execute();
+ return 0;
+ }
+
+ if ( RET_YES == aQueryOverwriteBox.Execute() )
+ EndDialog( RET_OK );
+ }
+ else
+ EndDialog( RET_OK );
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxNewStyleDlg, ModifyHdl, ComboBox *, pBox )
+{
+ aOKBtn.Enable( pBox->GetText().EraseAllChars().Len() > 0 );
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxNewStyleDlg, ModifyHdl, ComboBox *, pBox )
+
+// CTOR / DTOR -----------------------------------------------------------
+
+SfxNewStyleDlg::SfxNewStyleDlg( Window* pParent, SfxStyleSheetBasePool& rInPool ) :
+
+ ModalDialog( pParent, SfxResId( DLG_NEW_STYLE_BY_EXAMPLE ) ),
+
+ aColFL ( this, SfxResId( FL_COL ) ),
+ aColBox ( this, SfxResId( LB_COL ) ),
+ aOKBtn ( this, SfxResId( BT_OK ) ),
+ aCancelBtn ( this, SfxResId( BT_CANCEL ) ),
+ aQueryOverwriteBox ( this, SfxResId( MSG_OVERWRITE ) ),
+
+ rPool( rInPool )
+
+{
+ FreeResource();
+
+ aOKBtn.SetClickHdl(LINK(this, SfxNewStyleDlg, OKHdl));
+ aColBox.SetModifyHdl(LINK(this, SfxNewStyleDlg, ModifyHdl));
+ aColBox.SetDoubleClickHdl(LINK(this, SfxNewStyleDlg, OKHdl));
+
+ SfxStyleSheetBase *pStyle = rPool.First();
+ while ( pStyle )
+ {
+ aColBox.InsertEntry(pStyle->GetName());
+ pStyle = rPool.Next();
+ }
+}
+
+// -----------------------------------------------------------------------
+
+__EXPORT SfxNewStyleDlg::~SfxNewStyleDlg()
+{
+}
+
diff --git a/sfx2/source/dialog/newstyle.hrc b/sfx2/source/dialog/newstyle.hrc
new file mode 100644
index 000000000000..0efc04869ba9
--- /dev/null
+++ b/sfx2/source/dialog/newstyle.hrc
@@ -0,0 +1,33 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#define BT_OK 100
+#define BT_CANCEL 101
+#define LB_COL 1
+#define FL_COL 2
+#define MSG_OVERWRITE 3
+
diff --git a/sfx2/source/dialog/newstyle.src b/sfx2/source/dialog/newstyle.src
new file mode 100644
index 000000000000..b5954028779b
--- /dev/null
+++ b/sfx2/source/dialog/newstyle.src
@@ -0,0 +1,105 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <sfx2/sfx.hrc>
+#include "dialog.hrc"
+#include "newstyle.hrc"
+#include "sfx2/sfxcommands.h"
+
+ModalDialog DLG_NEW_STYLE_BY_EXAMPLE
+{
+ HelpId = CMD_SID_STYLE_NEW_BY_EXAMPLE ;
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 177 , 112 ) ;
+ Text [ en-US ] = "Create Style" ;
+ Moveable = TRUE ;
+ FixedLine FL_COL
+ {
+ Pos = MAP_APPFONT ( 6 , 3 ) ;
+ Size = MAP_APPFONT ( 109 , 8 ) ;
+ Text [ en-US ] = "Style name" ;
+ };
+ ComboBox LB_COL
+ {
+ HelpID = "sfx2:ComboBox:DLG_NEW_STYLE_BY_EXAMPLE:LB_COL";
+ Pos = MAP_APPFONT ( 12 , 14 ) ;
+ Size = MAP_APPFONT ( 94 , 92 ) ;
+ TabStop = TRUE ;
+ };
+ OKButton BT_OK
+ {
+ Disable = TRUE ;
+ Pos = MAP_APPFONT ( 121 , 6 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ DefButton = TRUE ;
+ };
+ CancelButton BT_CANCEL
+ {
+ Pos = MAP_APPFONT ( 121 , 23 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ };
+ QueryBox MSG_OVERWRITE
+ {
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_NO ;
+ Message [ en-US ] = "Style already exists. Overwrite?" ;
+ };
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/dialog/partwnd.cxx b/sfx2/source/dialog/partwnd.cxx
new file mode 100644
index 000000000000..cbbe20bfa203
--- /dev/null
+++ b/sfx2/source/dialog/partwnd.cxx
@@ -0,0 +1,257 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// includes ******************************************************************
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/task/XStatusIndicator.hpp>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/util/CloseVetoException.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/awt/PosSize.hpp>
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+
+#include <toolkit/helper/vclunohelper.hxx>
+
+#include <sfx2/sfxsids.hrc>
+#include "partwnd.hxx"
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/frame.hxx>
+#include <sfx2/sfxuno.hxx>
+
+//****************************************************************************
+// SfxPartChildWnd_Impl
+//****************************************************************************
+
+SFX_IMPL_DOCKINGWINDOW( SfxPartChildWnd_Impl, SID_BROWSER );
+
+SfxPartChildWnd_Impl::SfxPartChildWnd_Impl
+(
+ Window* pParentWnd,
+ sal_uInt16 nId,
+ SfxBindings* pBindings,
+ SfxChildWinInfo* pInfo
+)
+ : SfxChildWindow( pParentWnd, nId )
+{
+ // Window erzeugen
+ pWindow = new SfxPartDockWnd_Impl( pBindings, this, pParentWnd, WB_STDDOCKWIN | WB_CLIPCHILDREN | WB_SIZEABLE | WB_3DLOOK );
+ eChildAlignment = SFX_ALIGN_TOP;
+ if ( pInfo )
+ pInfo->nFlags |= SFX_CHILDWIN_FORCEDOCK;
+
+ ((SfxDockingWindow*)pWindow)->SetFloatingSize( Size( 175, 175 ) );
+ pWindow->SetSizePixel( Size( 175, 175 ) );
+
+ ( ( SfxDockingWindow* ) pWindow )->Initialize( pInfo );
+ SetHideNotDelete( TRUE );
+}
+
+SfxPartChildWnd_Impl::~SfxPartChildWnd_Impl()
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = GetFrame();
+
+ // If xFrame=NULL release pMgr! Because this window lives longer then the manager!
+ // In these case we got a xFrame->dispose() call from outside ... and has release our
+ // frame reference in our own DisposingListener.
+ // But don't do it, if xFrame already exist. Then dispose() must come from inside ...
+ // and we need a valid pMgr for further operations ...
+
+ SfxPartDockWnd_Impl* pWin = (SfxPartDockWnd_Impl*) pWindow;
+// if( pWin != NULL && !xFrame.is() )
+// pWin->ReleaseChildWindow_Impl();
+/*
+ // Release frame and window.
+ // If frame reference is valid here ... start dieing from inside by calling dispose().
+ SetFrame( NULL );
+ pWindow = NULL;
+*/
+ if ( pWin && xFrame == pWin->GetBindings().GetActiveFrame() )
+ pWin->GetBindings().SetActiveFrame( NULL );
+/*
+ if( xFrame.is() )
+ {
+ try
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > xCloseable ( xFrame, ::com::sun::star::uno::UNO_QUERY );
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xDisposeable( xFrame, ::com::sun::star::uno::UNO_QUERY );
+ if (xCloseable.is())
+ xCloseable->close(sal_True);
+ else
+ if (xDisposeable.is())
+ xDisposeable->dispose();
+ }
+ catch( ::com::sun::star::util::CloseVetoException& )
+ {
+ }
+ catch( ::com::sun::star::lang::DisposedException& )
+ {
+ }
+ }
+ */
+}
+
+sal_Bool SfxPartChildWnd_Impl::QueryClose()
+{
+ return ( (SfxPartDockWnd_Impl*)pWindow )->QueryClose();
+}
+
+//****************************************************************************
+// SfxPartDockWnd_Impl
+//****************************************************************************
+
+SfxPartDockWnd_Impl::SfxPartDockWnd_Impl
+(
+ SfxBindings* pBind,
+ SfxChildWindow* pChildWin,
+ Window* pParent,
+ WinBits nBits
+)
+ : SfxDockingWindow( pBind, pChildWin, pParent, nBits )
+{
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.Frame") ), ::com::sun::star::uno::UNO_QUERY );
+ xFrame->initialize( VCLUnoHelper::GetInterface ( this ) );
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet(
+ xFrame, ::com::sun::star::uno::UNO_QUERY );
+ try
+ {
+ const ::rtl::OUString aLayoutManager( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ));
+ ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet;
+
+ ::com::sun::star::uno::Any a = xPropSet->getPropertyValue( aLayoutManager );
+ if ( a >>= xLMPropSet )
+ {
+ const ::rtl::OUString aAutomaticToolbars( RTL_CONSTASCII_USTRINGPARAM( "AutomaticToolbars" ));
+ xLMPropSet->setPropertyValue( aAutomaticToolbars, ::com::sun::star::uno::Any( sal_False ));
+ }
+ }
+ catch( ::com::sun::star::uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch( ::com::sun::star::uno::Exception& )
+ {
+ }
+
+ pChildWin->SetFrame( xFrame );
+ if ( pBind->GetDispatcher() )
+ {
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFramesSupplier >
+ xSupp ( pBind->GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface(), ::com::sun::star::uno::UNO_QUERY );
+ if ( xSupp.is() )
+ xSupp->getFrames()->append( xFrame );
+ }
+ else {
+ DBG_ERROR("Bindings without Dispatcher!");
+ }
+}
+
+//****************************************************************************
+
+SfxPartDockWnd_Impl::~SfxPartDockWnd_Impl()
+{
+}
+
+//****************************************************************************
+
+Rectangle impl_Rectangle_Struct2Object( const ::com::sun::star::awt::Rectangle& aRectangleStruct )
+{
+ return Rectangle(aRectangleStruct.X,aRectangleStruct.Y,aRectangleStruct.Width,aRectangleStruct.Height);
+}
+
+void SfxPartDockWnd_Impl::Resize()
+
+/* [Beschreibung]
+ Anpassung der Gr"osse der Controls an die neue Windowgr"osse
+*/
+
+{
+ SfxDockingWindow::Resize();
+}
+
+//****************************************************************************
+
+sal_Bool SfxPartDockWnd_Impl::QueryClose()
+{
+ sal_Bool bClose = sal_True;
+ SfxChildWindow* pChild = GetChildWindow_Impl();
+ if( pChild )
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = pChild->GetFrame();
+ if( xFrame.is() )
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > xCtrl = xFrame->getController();
+ if( xCtrl.is() )
+ bClose = xCtrl->suspend( sal_True );
+ }
+ }
+
+ return bClose;
+}
+
+//****************************************************************************
+
+long SfxPartDockWnd_Impl::Notify( NotifyEvent& rEvt )
+{
+ if( rEvt.GetType() == EVENT_GETFOCUS )
+ {
+ SfxChildWindow* pChild = GetChildWindow_Impl();
+ if( pChild )
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = pChild->GetFrame();
+ if( xFrame.is() )
+ xFrame->activate();
+ }
+ }
+
+ return SfxDockingWindow::Notify( rEvt );
+}
+
+void SfxPartDockWnd_Impl::FillInfo( SfxChildWinInfo& rInfo ) const
+{
+ SfxDockingWindow::FillInfo( rInfo );
+ rInfo.bVisible = sal_False;
+}
+
+
diff --git a/sfx2/source/dialog/passwd.cxx b/sfx2/source/dialog/passwd.cxx
new file mode 100644
index 000000000000..455479b9d125
--- /dev/null
+++ b/sfx2/source/dialog/passwd.cxx
@@ -0,0 +1,255 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// Include ---------------------------------------------------------------
+#include <vcl/msgbox.hxx>
+#ifndef GCC
+#endif
+
+#include <sfx2/passwd.hxx>
+#include "sfxtypes.hxx"
+#include "sfx2/sfxresid.hxx"
+
+#include "dialog.hrc"
+#include "passwd.hrc"
+
+#include "vcl/sound.hxx"
+#include "vcl/arrange.hxx"
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxPasswordDialog, EditModifyHdl, Edit *, pEdit )
+{
+ if( mbAsciiOnly && (pEdit == &maPasswordED || pEdit == &maPassword2ED) )
+ {
+ rtl::OUString aTest( pEdit->GetText() );
+ const sal_Unicode* pTest = aTest.getStr();
+ sal_Int32 nLen = aTest.getLength();
+ rtl::OUStringBuffer aFilter( nLen );
+ bool bReset = false;
+ for( sal_Int32 i = 0; i < nLen; i++ )
+ {
+ if( *pTest > 0x007f )
+ bReset = true;
+ else
+ aFilter.append( *pTest );
+ pTest++;
+ }
+ if( bReset )
+ {
+ Sound::Beep( SOUND_ERROR );
+ pEdit->SetSelection( Selection( 0, nLen ) );
+ pEdit->ReplaceSelected( aFilter.makeStringAndClear() );
+ }
+
+ }
+ bool bEnable = maPasswordED.GetText().Len() >= mnMinLen;
+ if( maPassword2ED.IsVisible() )
+ bEnable = (bEnable && (maPassword2ED.GetText().Len() >= mnMinLen));
+ maOKBtn.Enable( bEnable );
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG )
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxPasswordDialog, OKHdl, OKButton *, EMPTYARG )
+{
+ bool bConfirmFailed = ( ( mnExtras & SHOWEXTRAS_CONFIRM ) == SHOWEXTRAS_CONFIRM ) &&
+ ( GetConfirm() != GetPassword() );
+ if( ( mnExtras & SHOWEXTRAS_CONFIRM2 ) == SHOWEXTRAS_CONFIRM2 && ( GetConfirm2() != GetPassword2() ) )
+ bConfirmFailed = true;
+ if ( bConfirmFailed )
+ {
+ ErrorBox aBox( this, SfxResId( MSG_ERROR_WRONG_CONFIRM ) );
+ aBox.Execute();
+ maConfirmED.SetText( String() );
+ maConfirmED.GrabFocus();
+ }
+ else
+ EndDialog( RET_OK );
+ return 0;
+}
+
+// CTOR / DTOR -----------------------------------------------------------
+
+SfxPasswordDialog::SfxPasswordDialog( Window* pParent, const String* pGroupText ) :
+
+ ModalDialog( pParent, SfxResId ( DLG_PASSWD ) ),
+
+ maPasswordBox ( this, SfxResId( GB_PASSWD_PASSWORD ) ),
+ maUserFT ( this, SfxResId( FT_PASSWD_USER ) ),
+ maUserED ( this, SfxResId( ED_PASSWD_USER ) ),
+ maPasswordFT ( this, SfxResId( FT_PASSWD_PASSWORD ) ),
+ maPasswordED ( this, SfxResId( ED_PASSWD_PASSWORD ) ),
+ maConfirmFT ( this, SfxResId( FT_PASSWD_CONFIRM ) ),
+ maConfirmED ( this, SfxResId( ED_PASSWD_CONFIRM ) ),
+ maPassword2Box ( this, 0 ),
+ maPassword2FT ( this, SfxResId( FT_PASSWD_PASSWORD2 ) ),
+ maPassword2ED ( this, SfxResId( ED_PASSWD_PASSWORD2 ) ),
+ maConfirm2FT ( this, SfxResId( FT_PASSWD_CONFIRM2 ) ),
+ maConfirm2ED ( this, SfxResId( ED_PASSWD_CONFIRM2 ) ),
+ maOKBtn ( this, SfxResId( BTN_PASSWD_OK ) ),
+ maCancelBtn ( this, SfxResId( BTN_PASSWD_CANCEL ) ),
+ maHelpBtn ( this, SfxResId( BTN_PASSWD_HELP ) ),
+
+ mnMinLen ( 1 ),
+ mnExtras ( 0 ),
+ mbAsciiOnly ( false )
+
+{
+ FreeResource();
+
+ // setup layout
+ boost::shared_ptr<vcl::RowOrColumn> xLayout =
+ boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
+ xLayout->setOuterBorder( 0 );
+
+ // get edit size, should be used as minimum
+ Size aEditSize( maUserED.GetSizePixel() );
+
+ // add labelcolumn for the labeled edit fields
+ boost::shared_ptr<vcl::LabelColumn> xEdits( new vcl::LabelColumn( xLayout.get() ) );
+ size_t nChildIndex = xLayout->addChild( xEdits );
+ xLayout->setBorders( nChildIndex, -2, -2, -2, 0 );
+
+ // add group box
+ xEdits->addWindow( &maPasswordBox );
+
+ // add user line
+ xEdits->addRow( &maUserFT, &maUserED, -2, aEditSize );
+
+ // add password line
+ xEdits->addRow( &maPasswordFT, &maPasswordED, -2, aEditSize );
+
+ // add confirm line
+ xEdits->addRow( &maConfirmFT, &maConfirmED, -2, aEditSize );
+
+ // add second group box
+ xEdits->addWindow( &maPassword2Box );
+
+ // add second password line
+ xEdits->addRow( &maPassword2FT, &maPassword2ED, -2, aEditSize );
+
+ // add second confirm line
+ xEdits->addRow( &maConfirm2FT, &maConfirm2ED, -2, aEditSize );
+
+ // add a FixedLine
+ FixedLine* pLine = new FixedLine( this, 0 );
+ pLine->Show();
+ addWindow( pLine, true );
+ xLayout->addWindow( pLine );
+
+ // add button column
+ Size aBtnSize( maCancelBtn.GetSizePixel() );
+ boost::shared_ptr<vcl::RowOrColumn> xButtons( new vcl::RowOrColumn( xLayout.get(), false ) );
+ nChildIndex = xLayout->addChild( xButtons );
+ xLayout->setBorders( nChildIndex, -2, 0, -2, -2 );
+
+ size_t nBtnIndex = xButtons->addWindow( &maHelpBtn, 0, aBtnSize );
+ xButtons->addChild( new vcl::Spacer( xButtons.get() ) );
+ nBtnIndex = xButtons->addWindow( &maOKBtn, 0, aBtnSize );
+ nBtnIndex = xButtons->addWindow( &maCancelBtn, 0, aBtnSize );
+
+ Link aLink = LINK( this, SfxPasswordDialog, EditModifyHdl );
+ maPasswordED.SetModifyHdl( aLink );
+ maPassword2ED.SetModifyHdl( aLink );
+ aLink = LINK( this, SfxPasswordDialog, OKHdl );
+ maOKBtn.SetClickHdl( aLink );
+
+ if ( pGroupText )
+ maPasswordBox.SetText( *pGroupText );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxPasswordDialog::SetMinLen( USHORT nLen )
+{
+ mnMinLen = nLen;
+ EditModifyHdl( NULL );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxPasswordDialog::SetMaxLen( USHORT nLen )
+{
+ maPasswordED.SetMaxTextLen( nLen );
+ maConfirmED.SetMaxTextLen( nLen );
+ EditModifyHdl( NULL );
+}
+
+// -----------------------------------------------------------------------
+
+short SfxPasswordDialog::Execute()
+{
+ maUserFT.Hide();
+ maUserED.Hide();
+ maConfirmFT.Hide();
+ maConfirmED.Hide();
+ maPasswordFT.Hide();
+ maPassword2Box.Hide();
+ maPassword2FT.Hide();
+ maPassword2ED.Hide();
+ maPassword2FT.Hide();
+ maConfirm2FT.Hide();
+ maConfirm2ED.Hide();
+
+ if( mnExtras != SHOWEXTRAS_NONE )
+ maPasswordFT.Show();
+ if( (mnExtras & SHOWEXTRAS_USER ) )
+ {
+ maUserFT.Show();
+ maUserED.Show();
+ }
+ if( (mnExtras & SHOWEXTRAS_CONFIRM ) )
+ {
+ maConfirmFT.Show();
+ maConfirmED.Show();
+ }
+ if( (mnExtras & SHOWEXTRAS_PASSWORD2) )
+ {
+ maPassword2Box.Show();
+ maPassword2FT.Show();
+ maPassword2ED.Show();
+ }
+ if( (mnExtras & SHOWEXTRAS_CONFIRM2 ) )
+ {
+ maConfirm2FT.Show();
+ maConfirm2ED.Show();
+ }
+
+ boost::shared_ptr<vcl::RowOrColumn> xLayout =
+ boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
+ SetSizePixel( xLayout->getOptimalSize( WINDOWSIZE_PREFERRED ) );
+
+ return ModalDialog::Execute();
+}
+
+
diff --git a/sfx2/source/dialog/passwd.hrc b/sfx2/source/dialog/passwd.hrc
new file mode 100644
index 000000000000..5c9b07c7a130
--- /dev/null
+++ b/sfx2/source/dialog/passwd.hrc
@@ -0,0 +1,52 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_PASSWD_HRC
+#define _SFX_PASSWD_HRC
+
+// defines ---------------------------------------------------------------
+
+#define GB_PASSWD_PASSWORD 10
+#define FT_PASSWD_USER 11
+#define ED_PASSWD_USER 12
+#define FT_PASSWD_PASSWORD 13
+#define ED_PASSWD_PASSWORD 14
+#define FT_PASSWD_CONFIRM 15
+#define ED_PASSWD_CONFIRM 16
+
+#define BTN_PASSWD_OK 20
+#define BTN_PASSWD_CANCEL 21
+#define BTN_PASSWD_HELP 22
+
+#define FT_PASSWD_PASSWORD2 25
+#define ED_PASSWD_PASSWORD2 26
+#define FT_PASSWD_CONFIRM2 27
+#define ED_PASSWD_CONFIRM2 28
+
+#endif
+
+// ******************************************************************* EOF
+
diff --git a/sfx2/source/dialog/passwd.src b/sfx2/source/dialog/passwd.src
new file mode 100644
index 000000000000..426fb9986d5a
--- /dev/null
+++ b/sfx2/source/dialog/passwd.src
@@ -0,0 +1,165 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+ // include ---------------------------------------------------------------
+#include "helpid.hrc"
+#include "dialog.hrc"
+#include "passwd.hrc"
+
+ // DLG_PASSWD ------------------------------------------------------------
+ModalDialog DLG_PASSWD
+{
+ HelpId = HID_PASSWD ;
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT( 200, 68 );
+ Text [ en-US ] = "Enter Password" ;
+ Moveable = TRUE ;
+ FixedText FT_PASSWD_USER
+ {
+ Pos = MAP_APPFONT( 12, 15 );
+ Size = MAP_APPFONT( 42, 10 );
+ Text [ en-US ] = "~User";
+ };
+ Edit ED_PASSWD_USER
+ {
+ HelpID = "sfx2:Edit:DLG_PASSWD:ED_PASSWD_USER";
+ Border = TRUE;
+ Pos = MAP_APPFONT( 57, 14 );
+ Size = MAP_APPFONT( 75, 12 );
+ };
+ FixedText FT_PASSWD_PASSWORD
+ {
+ Pos = MAP_APPFONT( 12, 30 );
+ Size = MAP_APPFONT( 42, 10 );
+ Text [ en-US ] = "~Password";
+ };
+ Edit ED_PASSWD_PASSWORD
+ {
+ HelpID = "sfx2:Edit:DLG_PASSWD:ED_PASSWD_PASSWORD";
+ Border = TRUE;
+ PassWord = TRUE;
+ Pos = MAP_APPFONT( 57, 29 );
+ Size = MAP_APPFONT( 75, 12 );
+ };
+ FixedText FT_PASSWD_CONFIRM
+ {
+ Pos = MAP_APPFONT( 12, 45 );
+ Size = MAP_APPFONT( 42, 10 );
+ Text [ en-US ] = "~Confirm";
+ };
+ Edit ED_PASSWD_CONFIRM
+ {
+ HelpID = "sfx2:Edit:DLG_PASSWD:ED_PASSWD_CONFIRM";
+ Border = TRUE;
+ PassWord = TRUE;
+ Pos = MAP_APPFONT( 57, 44 );
+ Size = MAP_APPFONT( 75, 12 );
+ };
+ FixedLine GB_PASSWD_PASSWORD
+ {
+ Pos = MAP_APPFONT( 6, 3 );
+ Size = MAP_APPFONT( 132, 8 );
+ Text [ en-US ] = "Password" ;
+ };
+ FixedText FT_PASSWD_PASSWORD2
+ {
+ Pos = MAP_APPFONT( 12, 30 );
+ Size = MAP_APPFONT( 42, 10 );
+ Text [ en-US ] = "P~assword";
+ };
+ Edit ED_PASSWD_PASSWORD2
+ {
+ Border = TRUE;
+ PassWord = TRUE;
+ Pos = MAP_APPFONT( 57, 29 );
+ Size = MAP_APPFONT( 75, 12 );
+ };
+ FixedText FT_PASSWD_CONFIRM2
+ {
+ Pos = MAP_APPFONT( 12, 45 );
+ Size = MAP_APPFONT( 42, 10 );
+ Text [ en-US ] = "Confir~m";
+ };
+ Edit ED_PASSWD_CONFIRM2
+ {
+ Border = TRUE;
+ PassWord = TRUE;
+ Pos = MAP_APPFONT( 57, 44 );
+ Size = MAP_APPFONT( 75, 12 );
+ };
+ OKButton BTN_PASSWD_OK
+ {
+ Disable = TRUE;
+ Pos = MAP_APPFONT( 144, 6 );
+ Size = MAP_APPFONT( 50, 14 );
+ DefButton = TRUE;
+ };
+ CancelButton BTN_PASSWD_CANCEL
+ {
+ Pos = MAP_APPFONT( 144, 23 );
+ Size = MAP_APPFONT( 50, 14 );
+ };
+ HelpButton BTN_PASSWD_HELP
+ {
+ Pos = MAP_APPFONT( 144, 43 );
+ Size = MAP_APPFONT( 50, 14 );
+ };
+};
+
+// ********************************************************************** EOF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/dialog/printopt.cxx b/sfx2/source/dialog/printopt.cxx
new file mode 100644
index 000000000000..6b26cf9fb504
--- /dev/null
+++ b/sfx2/source/dialog/printopt.cxx
@@ -0,0 +1,545 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+#include <vcl/msgbox.hxx>
+#include <unotools/printwarningoptions.hxx>
+#include <svtools/printoptions.hxx>
+#include <svl/flagitem.hxx>
+
+
+#include "printopt.hrc"
+#include "dialog.hrc"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/viewsh.hxx>
+#include <sfx2/printopt.hxx>
+
+// -----------
+// - statics -
+// -----------
+
+static USHORT aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
+static BOOL bOutputForPrinter = TRUE;
+
+#define DPI_COUNT (sizeof(aDPIArray)/sizeof(aDPIArray[0 ]))
+
+// --------------------------------
+// - SfxCommonPrintOptionsTabPage -
+// --------------------------------
+
+SfxCommonPrintOptionsTabPage::SfxCommonPrintOptionsTabPage( Window* pParent, const SfxItemSet& rSet ) :
+ SfxTabPage( pParent, SfxResId( TP_COMMONPRINTOPTIONS ), rSet ),
+
+ aReduceGB( this, SfxResId( GB_REDUCE ) ),
+ aOutputTypeFT( this, SfxResId( FT_OUTPUTTYPE ) ),
+ aPrinterOutputRB( this, SfxResId( RB_PRINTEROUTPUT ) ),
+ aPrintFileOutputRB( this, SfxResId( RB_PRINTFILEOUTPUT ) ),
+ aOutputGB( this, SfxResId( GB_OUTPUT ) ),
+ aReduceTransparencyCB( this, SfxResId( CB_REDUCETRANSPARENCY ) ),
+ aReduceTransparencyAutoRB( this, SfxResId( RB_REDUCETRANSPARENCY_AUTO ) ),
+ aReduceTransparencyNoneRB( this, SfxResId( RB_REDUCETRANSPARENCY_NONE ) ),
+ aReduceGradientsCB( this, SfxResId( CB_REDUCEGRADIENTS ) ),
+ aReduceGradientsStripesRB( this, SfxResId( RB_REDUCEGRADIENTS_STRIPES ) ),
+ aReduceGradientsColorRB( this, SfxResId( RB_REDUCEGRADIENTS_COLOR ) ),
+ aReduceGradientsStepCountNF( this, SfxResId( NF_REDUCEGRADIENTS_STEPCOUNT ) ),
+ aReduceBitmapsCB( this, SfxResId( CB_REDUCEBITMAPS ) ),
+ aReduceBitmapsOptimalRB( this, SfxResId( RB_REDUCEBITMAPS_OPTIMAL ) ),
+ aReduceBitmapsNormalRB( this, SfxResId( RB_REDUCEBITMAPS_NORMAL ) ),
+ aReduceBitmapsResolutionRB( this, SfxResId( RB_REDUCEBITMAPS_RESOLUTION ) ),
+ aReduceBitmapsResolutionLB( this, SfxResId( LB_REDUCEBITMAPS_RESOLUTION ) ),
+ aReduceBitmapsTransparencyCB( this, SfxResId( CB_REDUCEBITMAPS_TRANSPARENCY ) ),
+ aConvertToGreyscalesCB( this, SfxResId( CB_CONVERTTOGREYSCALES ) ),
+ aWarnGB( this, SfxResId( GB_PRINT_WARN ) ),
+ aPaperSizeCB( this, SfxResId( CB_PAPERSIZE ) ),
+ aPaperOrientationCB( this, SfxResId( CB_PAPERORIENTATION ) ),
+ aTransparencyCB( this, SfxResId( CB_TRANSPARENCY ) )
+{
+ FreeResource();
+
+ aOutputGB.SetStyle( aOutputGB.GetStyle() | WB_NOLABEL );
+
+ if( bOutputForPrinter )
+ {
+ aPrinterOutputRB.Check( TRUE );
+ aOutputGB.SetText( OutputDevice::GetNonMnemonicString( aPrinterOutputRB.GetText() ) );
+ }
+ else
+ {
+ aPrintFileOutputRB.Check( TRUE );
+ aOutputGB.SetText( OutputDevice::GetNonMnemonicString( aPrintFileOutputRB.GetText() ) );
+ }
+
+ aPrinterOutputRB.SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl ) );
+ aPrintFileOutputRB.SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl ) );
+
+ aReduceTransparencyCB.SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl ) );
+ aReduceGradientsCB.SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl ) );
+ aReduceBitmapsCB.SetClickHdl( LINK( this, SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl ) );
+
+ aReduceGradientsStripesRB.SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl ) );
+ aReduceBitmapsResolutionRB.SetToggleHdl( LINK( this, SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl ) );
+
+ // --> PB 2008-06-09 #i89164#
+ // calculate dynamically the width of radiobutton and listbox
+ const long nOffset = 10;
+ Size aOldSize = aReduceBitmapsResolutionRB.GetSizePixel();
+ Size aNewSize = aReduceBitmapsResolutionRB.GetOptimalSize( WINDOWSIZE_PREFERRED );
+ aNewSize.Width() += nOffset;
+ aNewSize.Height() = aOldSize.Height();
+ long nDelta = aOldSize.Width() - aNewSize.Width();
+ aReduceBitmapsResolutionRB.SetSizePixel( aNewSize );
+ Point aPos = aReduceBitmapsResolutionLB.GetPosPixel();
+ aPos.X() -= nDelta;
+ aOldSize = aReduceBitmapsResolutionLB.GetSizePixel();
+ aNewSize = aReduceBitmapsResolutionLB.GetOptimalSize( WINDOWSIZE_PREFERRED );
+ aNewSize.Width() += nOffset;
+ aNewSize.Height() = aOldSize.Height();
+ aReduceBitmapsResolutionLB.SetPosSizePixel( aPos, aNewSize );
+ // <--
+}
+
+// -----------------------------------------------------------------------------
+
+SfxCommonPrintOptionsTabPage::~SfxCommonPrintOptionsTabPage()
+{
+}
+
+// -----------------------------------------------------------------------------
+
+SfxTabPage* SfxCommonPrintOptionsTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
+{
+ return( new SfxCommonPrintOptionsTabPage( pParent, rAttrSet ) );
+}
+
+// -----------------------------------------------------------------------------
+
+Window* SfxCommonPrintOptionsTabPage::GetParentLabeledBy( const Window* pWindow ) const
+{
+ if ( pWindow == (Window *)&aReduceGradientsStepCountNF )
+ return (Window *)&aReduceGradientsStripesRB;
+ else if ( pWindow == (Window *)&aReduceBitmapsResolutionLB )
+ return (Window *)&aReduceBitmapsResolutionRB;
+ else
+ return SfxTabPage::GetParentLabeledBy( pWindow );
+}
+
+Window* SfxCommonPrintOptionsTabPage::GetParentLabelFor( const Window* pWindow ) const
+{
+ if ( pWindow == (Window *)&aReduceGradientsStripesRB )
+ return (Window *)&aReduceGradientsStepCountNF;
+ else if ( pWindow == (Window *)&aReduceBitmapsResolutionRB )
+ return (Window *)&aReduceBitmapsResolutionLB;
+ else
+ return SfxTabPage::GetParentLabelFor( pWindow );
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL SfxCommonPrintOptionsTabPage::FillItemSet( SfxItemSet& /*rSet*/ )
+{
+ SvtPrintWarningOptions aWarnOptions;
+ SvtPrinterOptions aPrinterOptions;
+ SvtPrintFileOptions aPrintFileOptions;
+ BOOL bModified = FALSE;
+
+
+ if( aPaperSizeCB.IsChecked() != aPaperSizeCB.GetSavedValue())
+ aWarnOptions.SetPaperSize(aPaperSizeCB.IsChecked());
+ if( aPaperOrientationCB.IsChecked() != aPaperOrientationCB.GetSavedValue() )
+ aWarnOptions.SetPaperOrientation(aPaperOrientationCB.IsChecked());
+
+ if( aTransparencyCB.IsChecked() != aTransparencyCB.GetSavedValue() )
+ aWarnOptions.SetTransparency( aTransparencyCB.IsChecked() );
+
+ ImplSaveControls( aPrinterOutputRB.IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
+
+ aPrinterOptions.SetPrinterOptions( maPrinterOptions );
+ aPrintFileOptions.SetPrinterOptions( maPrintFileOptions );
+
+ return bModified;
+}
+
+// -----------------------------------------------------------------------------
+
+void SfxCommonPrintOptionsTabPage::Reset( const SfxItemSet& /*rSet*/ )
+{
+ SvtPrintWarningOptions aWarnOptions;
+ SvtPrinterOptions aPrinterOptions;
+ SvtPrintFileOptions aPrintFileOptions;
+
+ aPaperSizeCB.Check( aWarnOptions.IsPaperSize() );
+ aPaperOrientationCB.Check( aWarnOptions.IsPaperOrientation() );
+
+ aTransparencyCB.Check( aWarnOptions.IsTransparency() );
+
+ aPaperSizeCB.SaveValue();
+ aPaperOrientationCB.SaveValue();
+ aTransparencyCB.SaveValue();
+
+ aPrinterOptions.GetPrinterOptions( maPrinterOptions );
+ aPrintFileOptions.GetPrinterOptions( maPrintFileOptions );
+
+ ImplUpdateControls( aPrinterOutputRB.IsChecked() ? &maPrinterOptions : &maPrintFileOptions );
+
+ // --> OD 2008-06-25 #i63982#
+ ImplSetAccessibleNames();
+ // <--
+}
+
+// -----------------------------------------------------------------------------
+
+int SfxCommonPrintOptionsTabPage::DeactivatePage( SfxItemSet* pItemSet )
+{
+ if( pItemSet )
+ FillItemSet( *pItemSet );
+
+ return LEAVE_PAGE;
+}
+
+// -----------------------------------------------------------------------------
+
+void SfxCommonPrintOptionsTabPage::ImplUpdateControls( const PrinterOptions* pCurrentOptions )
+{
+ aReduceTransparencyCB.Check( pCurrentOptions->IsReduceTransparency() );
+
+ if( pCurrentOptions->GetReducedTransparencyMode() == PRINTER_TRANSPARENCY_AUTO )
+ aReduceTransparencyAutoRB.Check( TRUE );
+ else
+ aReduceTransparencyNoneRB.Check( TRUE );
+
+ aReduceGradientsCB.Check( pCurrentOptions->IsReduceGradients() );
+
+ if( pCurrentOptions->GetReducedGradientMode() == PRINTER_GRADIENT_STRIPES )
+ aReduceGradientsStripesRB.Check( TRUE );
+ else
+ aReduceGradientsColorRB.Check( TRUE );
+
+ aReduceGradientsStepCountNF.SetValue( pCurrentOptions->GetReducedGradientStepCount() );
+
+ aReduceBitmapsCB.Check( pCurrentOptions->IsReduceBitmaps() );
+
+ if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_OPTIMAL )
+ aReduceBitmapsOptimalRB.Check( TRUE );
+ else if( pCurrentOptions->GetReducedBitmapMode() == PRINTER_BITMAP_NORMAL )
+ aReduceBitmapsNormalRB.Check( TRUE );
+ else
+ aReduceBitmapsResolutionRB.Check( TRUE );
+
+ const USHORT nDPI = pCurrentOptions->GetReducedBitmapResolution();
+
+ if( nDPI < aDPIArray[ 0 ] )
+ aReduceBitmapsResolutionLB.SelectEntryPos( 0 );
+ else
+ {
+ for( long i = ( DPI_COUNT - 1 ); i >= 0; i-- )
+ {
+ if( nDPI >= aDPIArray[ i ] )
+ {
+ aReduceBitmapsResolutionLB.SelectEntryPos( (USHORT) i );
+ i = -1;
+ }
+ }
+ }
+
+ aReduceBitmapsResolutionLB.SetText( aReduceBitmapsResolutionLB.GetEntry( aReduceBitmapsResolutionLB.GetSelectEntryPos() ) );
+
+ aReduceBitmapsTransparencyCB.Check( pCurrentOptions->IsReducedBitmapIncludesTransparency() );
+ aConvertToGreyscalesCB.Check( pCurrentOptions->IsConvertToGreyscales() );
+
+ ClickReduceTransparencyCBHdl( &aReduceTransparencyCB );
+ ClickReduceGradientsCBHdl( &aReduceGradientsCB );
+ ClickReduceBitmapsCBHdl( &aReduceBitmapsCB );
+}
+
+// -----------------------------------------------------------------------------
+
+void SfxCommonPrintOptionsTabPage::ImplSetAccessibleNames()
+{
+ static const String cSeparator = String::CreateFromAscii( " - " );
+
+ String sReduceText = aReduceGB.GetDisplayText();
+ sReduceText += cSeparator;
+
+ String sAccessibleName = sReduceText;
+ sAccessibleName += aPrinterOutputRB.GetDisplayText();
+ aPrinterOutputRB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sReduceText;
+ sAccessibleName += aPrintFileOutputRB.GetDisplayText();
+ aPrintFileOutputRB.SetAccessibleName( sAccessibleName );
+
+ String sOutputText = sReduceText;
+ sOutputText += aOutputGB.GetDisplayText();
+ sOutputText += cSeparator;
+
+ sAccessibleName = sOutputText;
+ sAccessibleName += aReduceTransparencyCB.GetDisplayText();
+ aReduceTransparencyCB.SetAccessibleName( sAccessibleName );
+
+ String sTransparencyText = aReduceTransparencyCB.GetAccessibleName();
+ sTransparencyText += cSeparator;
+
+ sAccessibleName = sTransparencyText;
+ sAccessibleName += aReduceTransparencyAutoRB.GetDisplayText();
+ aReduceTransparencyAutoRB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sTransparencyText;
+ sAccessibleName += aReduceTransparencyNoneRB.GetDisplayText();
+ aReduceTransparencyNoneRB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sOutputText;
+ sAccessibleName += aReduceGradientsCB.GetDisplayText();
+ aReduceGradientsCB.SetAccessibleName( sAccessibleName );
+
+ String sGradientText = aReduceGradientsCB.GetAccessibleName();
+ sGradientText += cSeparator;
+
+ sAccessibleName = sGradientText;
+ sAccessibleName += aReduceGradientsStripesRB.GetDisplayText();
+ aReduceGradientsStripesRB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = aReduceGradientsStripesRB.GetAccessibleName();
+ aReduceGradientsStepCountNF.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sGradientText;
+ sAccessibleName += aReduceGradientsColorRB.GetDisplayText();
+ aReduceGradientsColorRB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sOutputText;
+ sAccessibleName += aReduceBitmapsCB.GetDisplayText();
+ aReduceBitmapsCB.SetAccessibleName( sAccessibleName );
+
+ String sBitmapText = aReduceBitmapsCB.GetAccessibleName();
+ sBitmapText += cSeparator;
+
+ sAccessibleName = sBitmapText;
+ sAccessibleName += aReduceBitmapsOptimalRB.GetDisplayText();
+ aReduceBitmapsOptimalRB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sBitmapText;
+ sAccessibleName += aReduceBitmapsNormalRB.GetDisplayText();
+ aReduceBitmapsNormalRB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sBitmapText;
+ sAccessibleName += aReduceBitmapsResolutionRB.GetDisplayText();
+ aReduceBitmapsResolutionRB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = aReduceBitmapsResolutionRB.GetAccessibleName();
+ aReduceBitmapsResolutionLB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sBitmapText;
+ sAccessibleName += aReduceBitmapsTransparencyCB.GetDisplayText();
+ aReduceBitmapsTransparencyCB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sOutputText;
+ sAccessibleName += aConvertToGreyscalesCB.GetDisplayText();
+ aConvertToGreyscalesCB.SetAccessibleName( sAccessibleName );
+
+ String sWarnText = aWarnGB.GetDisplayText();
+ sWarnText += cSeparator;
+
+ sAccessibleName = sWarnText;
+ sAccessibleName += aPaperSizeCB.GetDisplayText();
+ aPaperSizeCB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sWarnText;
+ sAccessibleName += aPaperOrientationCB.GetDisplayText();
+ aPaperOrientationCB.SetAccessibleName( sAccessibleName );
+
+ sAccessibleName = sWarnText;
+ sAccessibleName += aTransparencyCB.GetDisplayText();
+ aTransparencyCB.SetAccessibleName( sAccessibleName );
+}
+
+// -----------------------------------------------------------------------------
+
+void SfxCommonPrintOptionsTabPage::ImplSaveControls( PrinterOptions* pCurrentOptions )
+{
+ pCurrentOptions->SetReduceTransparency( aReduceTransparencyCB.IsChecked() );
+ pCurrentOptions->SetReducedTransparencyMode( aReduceTransparencyAutoRB.IsChecked() ? PRINTER_TRANSPARENCY_AUTO : PRINTER_TRANSPARENCY_NONE );
+ pCurrentOptions->SetReduceGradients( aReduceGradientsCB.IsChecked() );
+ pCurrentOptions->SetReducedGradientMode( aReduceGradientsStripesRB.IsChecked() ? PRINTER_GRADIENT_STRIPES : PRINTER_GRADIENT_COLOR );
+ pCurrentOptions->SetReducedGradientStepCount( (USHORT) aReduceGradientsStepCountNF.GetValue() );
+ pCurrentOptions->SetReduceBitmaps( aReduceBitmapsCB.IsChecked() );
+ pCurrentOptions->SetReducedBitmapMode( aReduceBitmapsOptimalRB.IsChecked() ? PRINTER_BITMAP_OPTIMAL :
+ ( aReduceBitmapsNormalRB.IsChecked() ? PRINTER_BITMAP_NORMAL : PRINTER_BITMAP_RESOLUTION ) );
+ pCurrentOptions->SetReducedBitmapResolution( aDPIArray[ Min( (USHORT) aReduceBitmapsResolutionLB.GetSelectEntryPos(),
+ (USHORT)( sizeof( aDPIArray ) / sizeof( aDPIArray[ 0 ] ) - 1 ) ) ] );
+ pCurrentOptions->SetReducedBitmapIncludesTransparency( aReduceBitmapsTransparencyCB.IsChecked() );
+ pCurrentOptions->SetConvertToGreyscales( aConvertToGreyscalesCB.IsChecked() );
+}
+
+// -----------------------------------------------------------------------------
+
+IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceTransparencyCBHdl, CheckBox*, pBox )
+{
+ (void)pBox; //unused
+ const BOOL bReduceTransparency = aReduceTransparencyCB.IsChecked();
+
+ aReduceTransparencyAutoRB.Enable( bReduceTransparency );
+ aReduceTransparencyNoneRB.Enable( bReduceTransparency );
+
+ aTransparencyCB.Enable( !bReduceTransparency );
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceGradientsCBHdl, CheckBox*, pBox )
+{
+ (void)pBox; //unused
+ const BOOL bEnable = aReduceGradientsCB.IsChecked();
+
+ aReduceGradientsStripesRB.Enable( bEnable );
+ aReduceGradientsColorRB.Enable( bEnable );
+ aReduceGradientsStepCountNF.Enable( bEnable );
+
+ ToggleReduceGradientsStripesRBHdl( &aReduceGradientsStripesRB );
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+IMPL_LINK( SfxCommonPrintOptionsTabPage, ClickReduceBitmapsCBHdl, CheckBox*, pBox )
+{
+ (void)pBox; //unused
+ const BOOL bEnable = aReduceBitmapsCB.IsChecked();
+
+ aReduceBitmapsOptimalRB.Enable( bEnable );
+ aReduceBitmapsNormalRB.Enable( bEnable );
+ aReduceBitmapsResolutionRB.Enable( bEnable );
+ aReduceBitmapsTransparencyCB.Enable( bEnable );
+ aReduceBitmapsResolutionLB.Enable( bEnable );
+
+ ToggleReduceBitmapsResolutionRBHdl( &aReduceBitmapsResolutionRB );
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceGradientsStripesRBHdl, RadioButton*, pButton )
+{
+ (void)pButton; //unused
+ const BOOL bEnable = aReduceGradientsCB.IsChecked() && aReduceGradientsStripesRB.IsChecked();
+
+ aReduceGradientsStepCountNF.Enable( bEnable );
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleReduceBitmapsResolutionRBHdl, RadioButton*, pButton )
+{
+ (void)pButton; //unused
+ const BOOL bEnable = aReduceBitmapsCB.IsChecked() && aReduceBitmapsResolutionRB.IsChecked();
+
+ aReduceBitmapsResolutionLB.Enable( bEnable );
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrinterRBHdl, RadioButton*, pButton )
+{
+ if( pButton->IsChecked() )
+ {
+ aOutputGB.SetText( OutputDevice::GetNonMnemonicString( pButton->GetText() ) );
+ ImplUpdateControls( &maPrinterOptions );
+ bOutputForPrinter = TRUE;
+ // --> OD 2008-06-25 #i63982#
+ ImplSetAccessibleNames();
+ // <--
+ }
+ else
+ ImplSaveControls( &maPrinterOptions );
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+IMPL_LINK( SfxCommonPrintOptionsTabPage, ToggleOutputPrintFileRBHdl, RadioButton*, pButton )
+{
+ if( pButton->IsChecked() )
+ {
+ aOutputGB.SetText( OutputDevice::GetNonMnemonicString( pButton->GetText() ) );
+ ImplUpdateControls( &maPrintFileOptions );
+ bOutputForPrinter = FALSE;
+ // --> OD 2008-06-25 #i63982#
+ ImplSetAccessibleNames();
+ // <--
+ }
+ else
+ ImplSaveControls( &maPrintFileOptions );
+
+ return 0;
+}
+
+// -------------------------------
+// - TransparencyPrintWarningBox -
+// -------------------------------
+
+TransparencyPrintWarningBox::TransparencyPrintWarningBox( Window* pParent ) :
+ ModalDialog( pParent, SfxResId( RID_WARN_PRINTTRANSPARENCY ) ),
+ aWarnFI ( this, SfxResId( FI_PRINTTRANSWARN ) ),
+ aWarnFT ( this, SfxResId( FT_PRINTTRANSWARN ) ),
+ aYesBtn ( this, SfxResId( BTN_PRINTTRANS_YES ) ),
+ aNoBtn ( this, SfxResId( BTN_PRINTTRANS_NO ) ),
+ aCancelBtn ( this, SfxResId( BTN_PRINTTRANS_CANCEL ) ),
+ aNoWarnCB ( this, SfxResId( CBX_NOPRINTTRANSWARN ) )
+{
+ FreeResource();
+
+ aWarnFT.SetStyle( aWarnFT.GetStyle() | WB_INFO );
+ aWarnFI.SetImage( WarningBox::GetStandardImage() );
+
+ aNoBtn.SetClickHdl( LINK( this, TransparencyPrintWarningBox, ClickNoBtn ) );
+}
+
+// -----------------------------------------------------------------------------
+
+TransparencyPrintWarningBox::~TransparencyPrintWarningBox()
+{
+}
+
+// -----------------------------------------------------------------------------
+
+IMPL_LINK( TransparencyPrintWarningBox, ClickNoBtn, PushButton*, pButton )
+{
+ (void)pButton; //unused
+ EndDialog( RET_NO );
+ return 0;
+}
diff --git a/sfx2/source/dialog/printopt.hrc b/sfx2/source/dialog/printopt.hrc
new file mode 100644
index 000000000000..38c766c9f56a
--- /dev/null
+++ b/sfx2/source/dialog/printopt.hrc
@@ -0,0 +1,64 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#define GB_REDUCE 1
+
+#define FT_OUTPUTTYPE 2
+#define RB_PRINTEROUTPUT 3
+#define RB_PRINTFILEOUTPUT 4
+
+#define GB_OUTPUT 5
+
+#define CB_REDUCETRANSPARENCY 10
+#define RB_REDUCETRANSPARENCY_AUTO 11
+#define RB_REDUCETRANSPARENCY_NONE 12
+
+#define CB_REDUCEGRADIENTS 20
+#define RB_REDUCEGRADIENTS_STRIPES 21
+#define RB_REDUCEGRADIENTS_COLOR 22
+#define NF_REDUCEGRADIENTS_STEPCOUNT 23
+
+#define CB_REDUCEBITMAPS 30
+#define RB_REDUCEBITMAPS_OPTIMAL 31
+#define RB_REDUCEBITMAPS_NORMAL 32
+#define RB_REDUCEBITMAPS_RESOLUTION 33
+#define CB_REDUCEBITMAPS_TRANSPARENCY 34
+#define LB_REDUCEBITMAPS_RESOLUTION 35
+
+#define CB_CONVERTTOGREYSCALES 40
+
+#define GB_PRINT_WARN 50
+#define CB_PAPERSIZE 51
+#define CB_PAPERORIENTATION 52
+#define CB_TRANSPARENCY 53
+
+#define FI_PRINTTRANSWARN 60
+#define FT_PRINTTRANSWARN 61
+#define BTN_PRINTTRANS_YES 62
+#define BTN_PRINTTRANS_NO 63
+#define BTN_PRINTTRANS_CANCEL 64
+#define CBX_NOPRINTTRANSWARN 65
diff --git a/sfx2/source/dialog/printopt.src b/sfx2/source/dialog/printopt.src
new file mode 100644
index 000000000000..01650f3e9275
--- /dev/null
+++ b/sfx2/source/dialog/printopt.src
@@ -0,0 +1,377 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// include ---------------------------------------------------------------
+
+#include <sfx2/sfx.hrc>
+#include "printopt.hrc"
+#include "dialog.hrc"
+#include "helpid.hrc"
+
+//****************************************************************************
+//
+// TabPage
+//
+//****************************************************************************
+
+TabPage TP_COMMONPRINTOPTIONS
+{
+ HelpID = HID_TP_COMMONPRINTOPTIONS;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 260 , 185 ) ;
+ Hide = TRUE ;
+
+ FixedLine GB_REDUCE
+ {
+ Pos = MAP_APPFONT ( 6, 3 ) ;
+ Size = MAP_APPFONT ( 248 , 8 ) ;
+ Text [ en-US ] = "Reduce print data";
+ };
+ FixedText FT_OUTPUTTYPE
+ {
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 12, 14 ) ;
+ Size = MAP_APPFONT ( 60, 10 ) ;
+ Text [ en-US ] = "Settings for";
+ };
+ RadioButton RB_PRINTEROUTPUT
+ {
+ HelpID = "sfx2:RadioButton:TP_COMMONPRINTOPTIONS:RB_PRINTEROUTPUT";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 81, 14 ) ;
+ Size = MAP_APPFONT ( 60, 10 ) ;
+ Text [ en-US ] = "~Printer";
+ };
+ RadioButton RB_PRINTFILEOUTPUT
+ {
+ HelpID = "sfx2:RadioButton:TP_COMMONPRINTOPTIONS:RB_PRINTFILEOUTPUT";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 142, 14 ) ;
+ Size = MAP_APPFONT ( 100, 10 ) ;
+ Text [ en-US ] = "Print to ~file";
+ };
+
+ // -----------
+
+ FixedLine GB_OUTPUT
+ {
+ Pos = MAP_APPFONT ( 12, 27 ) ;
+ Size = MAP_APPFONT ( 242 , 8 ) ;
+ };
+
+ CheckBox CB_REDUCETRANSPARENCY
+ {
+ HelpID = "sfx2:CheckBox:TP_COMMONPRINTOPTIONS:CB_REDUCETRANSPARENCY";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 18, 38 ) ;
+ Size = MAP_APPFONT ( 115, 10 ) ;
+ Text [ en-US ] = "~Reduce transparency";
+ };
+ RadioButton RB_REDUCETRANSPARENCY_AUTO
+ {
+ HelpID = "sfx2:RadioButton:TP_COMMONPRINTOPTIONS:RB_REDUCETRANSPARENCY_AUTO";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 28, 51 ) ;
+ Size = MAP_APPFONT ( 105, 10 ) ;
+ Text [ en-US ] = "Auto~matically";
+ };
+ RadioButton RB_REDUCETRANSPARENCY_NONE
+ {
+ HelpID = "sfx2:RadioButton:TP_COMMONPRINTOPTIONS:RB_REDUCETRANSPARENCY_NONE";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 28, 64 ) ;
+ Size = MAP_APPFONT ( 105, 10 ) ;
+ Text [ en-US ] = "~No transparency";
+ };
+
+ // -----------
+
+ CheckBox CB_REDUCEGRADIENTS
+ {
+ HelpID = "sfx2:CheckBox:TP_COMMONPRINTOPTIONS:CB_REDUCEGRADIENTS";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 136, 38 ) ;
+ Size = MAP_APPFONT ( 121, 10 ) ;
+ Text [ en-US ] = "Reduce ~gradients";
+ };
+ RadioButton RB_REDUCEGRADIENTS_STRIPES
+ {
+ HelpID = "sfx2:RadioButton:TP_COMMONPRINTOPTIONS:RB_REDUCEGRADIENTS_STRIPES";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 146, 51 ) ;
+ Size = MAP_APPFONT ( 77, 10 ) ;
+ Text [ en-US ] = "Gradient ~stripes";
+ };
+ NumericField NF_REDUCEGRADIENTS_STEPCOUNT
+ {
+ HelpID = "sfx2:NumericField:TP_COMMONPRINTOPTIONS:NF_REDUCEGRADIENTS_STEPCOUNT";
+ TabStop = TRUE;
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 224, 49 ) ;
+ Size = MAP_APPFONT ( 24, 12 ) ;
+ Minimum = 2;
+ Maximum = 256;
+ Spin = TRUE ;
+ Repeat = TRUE ;
+ };
+ RadioButton RB_REDUCEGRADIENTS_COLOR
+ {
+ HelpID = "sfx2:RadioButton:TP_COMMONPRINTOPTIONS:RB_REDUCEGRADIENTS_COLOR";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 146, 64 ) ;
+ Size = MAP_APPFONT ( 108, 10 ) ;
+ Text [ en-US ] = "Intermediate ~color";
+ };
+
+ // -----------
+
+ CheckBox CB_REDUCEBITMAPS
+ {
+ HelpID = "sfx2:CheckBox:TP_COMMONPRINTOPTIONS:CB_REDUCEBITMAPS";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 18, 80 ) ;
+ Size = MAP_APPFONT ( 115, 10 ) ;
+ Text [ en-US ] = "Reduce ~bitmaps";
+ };
+ RadioButton RB_REDUCEBITMAPS_OPTIMAL
+ {
+ HelpID = "sfx2:RadioButton:TP_COMMONPRINTOPTIONS:RB_REDUCEBITMAPS_OPTIMAL";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 28, 93 ) ;
+ Size = MAP_APPFONT ( 226, 10 ) ;
+ Text [ en-US ] = "~High print quality";
+ };
+ RadioButton RB_REDUCEBITMAPS_NORMAL
+ {
+ HelpID = "sfx2:RadioButton:TP_COMMONPRINTOPTIONS:RB_REDUCEBITMAPS_NORMAL";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 28, 106 ) ;
+ Size = MAP_APPFONT ( 226, 10 ) ;
+ Text [ en-US ] = "N~ormal print quality";
+ };
+ RadioButton RB_REDUCEBITMAPS_RESOLUTION
+ {
+ HelpID = "sfx2:RadioButton:TP_COMMONPRINTOPTIONS:RB_REDUCEBITMAPS_RESOLUTION";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 28, 119 ) ;
+ Size = MAP_APPFONT ( 52, 10 ) ;
+ Text [ en-US ] = "Reso~lution";
+ };
+ ListBox LB_REDUCEBITMAPS_RESOLUTION
+ {
+ HelpID = "sfx2:ListBox:TP_COMMONPRINTOPTIONS:LB_REDUCEBITMAPS_RESOLUTION";
+ TabStop = TRUE;
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 81, 117 ) ;
+ Size = MAP_APPFONT ( 60, 100 ) ;
+ DropDown = TRUE;
+
+ StringList [ en-US ] =
+ {
+ < "72 DPI"; 0; > ;
+ < "96 DPI"; 0; > ;
+ < "150 DPI (Fax)"; 0; > ;
+ < "200 DPI (default)"; 0; > ;
+ < "300 DPI"; 0; > ;
+ < "600 DPI"; 0; > ;
+ };
+ };
+ CheckBox CB_REDUCEBITMAPS_TRANSPARENCY
+ {
+ HelpID = "sfx2:CheckBox:TP_COMMONPRINTOPTIONS:CB_REDUCEBITMAPS_TRANSPARENCY";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 28, 132 ) ;
+ Size = MAP_APPFONT ( 226, 10 ) ;
+ Text [ en-US ] = "Include transparent ob~jects";
+ };
+
+ // -----------
+
+ CheckBox CB_CONVERTTOGREYSCALES
+ {
+ HelpID = "sfx2:CheckBox:TP_COMMONPRINTOPTIONS:CB_CONVERTTOGREYSCALES";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 136, 80 ) ;
+ Size = MAP_APPFONT ( 123, 10 ) ;
+ Text [ en-US ] = "Con~vert colors to grayscale";
+ };
+
+ // -----------
+
+ FixedLine GB_PRINT_WARN
+ {
+ Pos = MAP_APPFONT ( 6, 148 ) ;
+ Size = MAP_APPFONT ( 248 , 8 ) ;
+ Text [ en-US ] = "Printer warnings" ;
+ };
+ CheckBox CB_PAPERSIZE
+ {
+ HelpID = "sfx2:CheckBox:TP_COMMONPRINTOPTIONS:CB_PAPERSIZE";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 12, 159 ) ;
+ Size = MAP_APPFONT ( 123, 10 ) ;
+ Text [ en-US ] = "P~aper size" ;
+ };
+ CheckBox CB_PAPERORIENTATION
+ {
+ HelpID = "sfx2:CheckBox:TP_COMMONPRINTOPTIONS:CB_PAPERORIENTATION";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 12, 172 ) ;
+ Size = MAP_APPFONT ( 123 , 10 ) ;
+ Text [ en-US ] = "Pap~er orientation" ;
+ };
+ CheckBox CB_TRANSPARENCY
+ {
+ HelpID = "sfx2:CheckBox:TP_COMMONPRINTOPTIONS:CB_TRANSPARENCY";
+ TabStop = TRUE;
+ Pos = MAP_APPFONT ( 136, 159 ) ;
+ Size = MAP_APPFONT ( 123, 10 ) ;
+ Text [ en-US ] = "~Transparency";
+ };
+};
+
+// --------------
+// - WarningBox -
+// --------------
+
+ModalDialog RID_WARN_PRINTTRANSPARENCY
+{
+ HelpID = "sfx2:ModalDialog:RID_WARN_PRINTTRANSPARENCY";
+ OutputSize = TRUE ;
+ Size = MAP_APPFONT ( 195 , 85 ) ;
+ Text [ en-US ] = "Warning" ;
+ Moveable = TRUE ;
+ FixedImage FI_PRINTTRANSWARN
+ {
+ Pos = MAP_APPFONT ( 6 , 6 ) ;
+ Size = MAP_APPFONT ( 20 , 20 ) ;
+ };
+ FixedText FT_PRINTTRANSWARN
+ {
+ Pos = MAP_APPFONT ( 29 , 6 ) ;
+ Size = MAP_APPFONT ( 163 , 36 ) ;
+ WordBreak = TRUE ;
+ Text [ en-US ] = "Your document contains transparent objects.\nThis may lead to longer printing time on certain\nprinters. Should the aspect of transparency\nbe reduced?";
+ };
+ OKButton BTN_PRINTTRANS_YES
+ {
+ Pos = MAP_APPFONT ( 12 , 48 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ DefButton = TRUE;
+ Text [ en-US ] = "~Yes" ;
+ };
+ PushButton BTN_PRINTTRANS_NO
+ {
+ HelpID = "sfx2:PushButton:RID_WARN_PRINTTRANSPARENCY:BTN_PRINTTRANS_NO";
+ Pos = MAP_APPFONT ( 68 , 48 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~No" ;
+ };
+ CancelButton BTN_PRINTTRANS_CANCEL
+ {
+ Pos = MAP_APPFONT ( 124 , 48 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~Cancel" ;
+ };
+ CheckBox CBX_NOPRINTTRANSWARN
+ {
+ HelpID = "sfx2:CheckBox:RID_WARN_PRINTTRANSPARENCY:CBX_NOPRINTTRANSWARN";
+ Pos = MAP_APPFONT ( 6 , 68 ) ;
+ Size = MAP_APPFONT ( 183 , 10 ) ;
+ Text [ en-US ] = "~Do not show warning again" ;
+ };
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/dialog/recfloat.cxx b/sfx2/source/dialog/recfloat.cxx
new file mode 100644
index 000000000000..aaabdd3e5d74
--- /dev/null
+++ b/sfx2/source/dialog/recfloat.cxx
@@ -0,0 +1,280 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// includes *******************************************************************
+#include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+#include <svl/eitem.hxx>
+#include <svtools/generictoolboxcontroller.hxx>
+#include <vcl/msgbox.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include "recfloat.hxx"
+#include "dialog.hrc"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/app.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/viewsh.hxx>
+#include "sfx2/imagemgr.hxx"
+
+using namespace ::com::sun::star;
+
+static rtl::OUString GetLabelFromCommandURL( const rtl::OUString& rCommandURL, const uno::Reference< frame::XFrame >& xFrame )
+{
+ rtl::OUString aLabel;
+ rtl::OUString aModuleIdentifier;
+ uno::Reference< container::XNameAccess > xUICommandLabels;
+ uno::Reference< lang::XMultiServiceFactory > xServiceManager;
+ uno::Reference< container::XNameAccess > xUICommandDescription;
+ uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager;
+
+ static uno::WeakReference< lang::XMultiServiceFactory > xTmpServiceManager;
+ static uno::WeakReference< container::XNameAccess > xTmpNameAccess;
+ static uno::WeakReference< ::com::sun::star::frame::XModuleManager > xTmpModuleMgr;
+
+ xServiceManager = xTmpServiceManager;
+ if ( !xServiceManager.is() )
+ {
+ xServiceManager = ::comphelper::getProcessServiceFactory();
+ xTmpServiceManager = xServiceManager;
+ }
+
+ xUICommandDescription = xTmpNameAccess;
+ if ( !xUICommandDescription.is() )
+ {
+ xUICommandDescription = uno::Reference< container::XNameAccess >(
+ xServiceManager->createInstance(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.frame.UICommandDescription" ))),
+ uno::UNO_QUERY );
+ xTmpNameAccess = xUICommandDescription;
+ }
+
+ xModuleManager = xTmpModuleMgr;
+ if ( !xModuleManager.is() )
+ {
+ xModuleManager = uno::Reference< ::com::sun::star::frame::XModuleManager >(
+ xServiceManager->createInstance(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.frame.ModuleManager" ))),
+ uno::UNO_QUERY_THROW );
+ xTmpModuleMgr = xModuleManager;
+ }
+
+ // Retrieve label from UI command description service
+ try
+ {
+ try
+ {
+ aModuleIdentifier = xModuleManager->identify( xFrame );
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ if ( xUICommandDescription.is() )
+ {
+ uno::Any a = xUICommandDescription->getByName( aModuleIdentifier );
+ uno::Reference< container::XNameAccess > xUICommands;
+ a >>= xUICommandLabels;
+ }
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ if ( xUICommandLabels.is() )
+ {
+ try
+ {
+ if ( rCommandURL.getLength() > 0 )
+ {
+ uno::Sequence< beans::PropertyValue > aPropSeq;
+ uno::Any a( xUICommandLabels->getByName( rCommandURL ));
+ if ( a >>= aPropSeq )
+ {
+ for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
+ {
+ if ( aPropSeq[i].Name.equalsAscii( "Label" ))
+ {
+ aPropSeq[i].Value >>= aLabel;
+ break;
+ }
+ }
+ }
+ }
+ }
+ catch (uno::Exception& )
+ {
+ }
+ }
+
+ return aLabel;
+}
+
+SFX_IMPL_FLOATINGWINDOW( SfxRecordingFloatWrapper_Impl, SID_RECORDING_FLOATWINDOW );
+
+SfxRecordingFloatWrapper_Impl::SfxRecordingFloatWrapper_Impl( Window* pParentWnd ,
+ USHORT nId ,
+ SfxBindings* pBind ,
+ SfxChildWinInfo* pInfo )
+ : SfxChildWindow( pParentWnd, nId )
+ , pBindings( pBind )
+{
+ pWindow = new SfxRecordingFloat_Impl( pBindings, this, pParentWnd );
+ SetWantsFocus( FALSE );
+ eChildAlignment = SFX_ALIGN_NOALIGNMENT;
+ ( ( SfxFloatingWindow* ) pWindow )->Initialize( pInfo );
+}
+
+SfxRecordingFloatWrapper_Impl::~SfxRecordingFloatWrapper_Impl()
+{
+ SfxBoolItem aItem( FN_PARAM_1, TRUE );
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder = pBindings->GetRecorder();
+ if ( xRecorder.is() )
+ pBindings->GetDispatcher()->Execute( SID_STOP_RECORDING, SFX_CALLMODE_SYNCHRON, &aItem, 0L );
+}
+
+sal_Bool SfxRecordingFloatWrapper_Impl::QueryClose()
+{
+ // asking for recorded macro should be replaced if index access is available!
+ BOOL bRet = TRUE;
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder = pBindings->GetRecorder();
+ if ( xRecorder.is() && xRecorder->getRecordedMacro().getLength() )
+ {
+ QueryBox aBox( GetWindow(), WB_YES_NO | WB_DEF_NO , String( SfxResId( STR_MACRO_LOSS ) ) );
+ aBox.SetText( String( SfxResId(STR_CANCEL_RECORDING) ) );
+ bRet = ( aBox.Execute() == RET_YES );
+ }
+
+ return bRet;
+}
+
+SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(
+ SfxBindings* pBind ,
+ SfxChildWindow* pChildWin ,
+ Window* pParent )
+ : SfxFloatingWindow( pBind,
+ pChildWin,
+ pParent,
+ SfxResId( SID_RECORDING_FLOATWINDOW ) )
+ , pWrapper( pChildWin )
+ , aTbx( this, SfxResId(SID_RECORDING_FLOATWINDOW) )
+{
+ // Retrieve label from helper function
+ uno::Reference< frame::XFrame > xFrame = GetBindings().GetActiveFrame();
+ rtl::OUString aCommandStr( RTL_CONSTASCII_USTRINGPARAM( ".uno:StopRecording" ));
+ aTbx.SetItemText( SID_STOP_RECORDING, GetLabelFromCommandURL( aCommandStr, xFrame ));
+
+ // Determine size of toolbar
+ Size aTbxSize = aTbx.CalcWindowSizePixel();
+ aTbx.SetPosSizePixel( Point(), aTbxSize );
+ SetOutputSizePixel( aTbxSize );
+
+ // create a generic toolbox controller for our internal toolbox
+ svt::GenericToolboxController* pController = new svt::GenericToolboxController(
+ ::comphelper::getProcessServiceFactory(),
+ xFrame,
+ &aTbx,
+ SID_STOP_RECORDING,
+ aCommandStr );
+ xStopRecTbxCtrl = uno::Reference< frame::XToolbarController >(
+ static_cast< cppu::OWeakObject* >( pController ),
+ uno::UNO_QUERY );
+ uno::Reference< util::XUpdatable > xUpdate( xStopRecTbxCtrl, uno::UNO_QUERY );
+ if ( xUpdate.is() )
+ xUpdate->update();
+
+ aTbx.SetSelectHdl( LINK( this, SfxRecordingFloat_Impl, Select ) );
+
+ // start recording
+ SfxBoolItem aItem( SID_RECORDMACRO, TRUE );
+ GetBindings().GetDispatcher()->Execute( SID_RECORDMACRO, SFX_CALLMODE_SYNCHRON, &aItem, 0L );
+}
+
+SfxRecordingFloat_Impl::~SfxRecordingFloat_Impl()
+{
+ try
+ {
+ if ( xStopRecTbxCtrl.is() )
+ {
+ uno::Reference< lang::XComponent > xComp( xStopRecTbxCtrl, uno::UNO_QUERY );
+ xComp->dispose();
+ }
+ }
+ catch ( uno::Exception& )
+ {
+ }
+}
+
+BOOL SfxRecordingFloat_Impl::Close()
+{
+ BOOL bRet = SfxFloatingWindow::Close();
+ return bRet;
+}
+
+void SfxRecordingFloat_Impl::FillInfo( SfxChildWinInfo& rInfo ) const
+{
+ SfxFloatingWindow::FillInfo( rInfo );
+ rInfo.bVisible = sal_False;
+}
+
+void SfxRecordingFloat_Impl::StateChanged( StateChangedType nStateChange )
+{
+ if ( nStateChange == STATE_CHANGE_INITSHOW )
+ {
+ SfxViewFrame *pFrame = GetBindings().GetDispatcher_Impl()->GetFrame();
+ Window* pEditWin = pFrame->GetViewShell()->GetWindow();
+
+ Point aPoint = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
+ aPoint = GetParent()->ScreenToOutputPixel( aPoint );
+ aPoint.X() += 20;
+ aPoint.Y() += 10;
+ SetPosPixel( aPoint );
+ }
+
+ SfxFloatingWindow::StateChanged( nStateChange );
+}
+
+IMPL_LINK( SfxRecordingFloat_Impl, Select, ToolBox*, pToolBar )
+{
+ (void)pToolBar;
+ sal_Int16 nKeyModifier( (sal_Int16)aTbx.GetModifier() );
+ if ( xStopRecTbxCtrl.is() )
+ xStopRecTbxCtrl->execute( nKeyModifier );
+
+ return 1;
+}
diff --git a/sfx2/source/dialog/recfloat.src b/sfx2/source/dialog/recfloat.src
new file mode 100644
index 000000000000..d71270d1e312
--- /dev/null
+++ b/sfx2/source/dialog/recfloat.src
@@ -0,0 +1,87 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+ // include ---------------------------------------------------------------
+#include "helpid.hrc"
+#include "dialog.hrc"
+
+ // -----------------------------------------------------------------------
+#define STD_MASKCOLOR Color { Red = 0xC000; Green = 0xC000; Blue = 0xC000; }
+#define STD_HC_MASKCOLOR Color { Red = 0xFFFF ; Green = 0x0000 ; Blue = 0xFFFF ; }
+
+FloatingWindow SID_RECORDING_FLOATWINDOW
+{
+ HelpID = "sfx2:FloatingWindow:SID_RECORDING_FLOATWINDOW";
+ Moveable = TRUE ;
+ Closeable = TRUE ;
+ Hide = TRUE ;
+ SVLook = TRUE ;
+ Text [ en-US ] = "Record Macro";
+};
+
+ToolBox SID_RECORDING_FLOATWINDOW
+{
+ SVLook = TRUE ;
+ ButtonType = BUTTON_TEXT;
+ ItemList =
+ {
+ ToolBoxItem
+ {
+ Identifier = SID_STOP_RECORDING;
+ Command = ".uno:StopRecording";
+ };
+ };
+};
+
+String STR_MACRO_LOSS
+{
+ Text [ en-US ] = "Do you really want to cancel the recording? Any steps recorded up to this point will be lost.";
+};
+
+String STR_CANCEL_RECORDING
+{
+ Text [ en-US ] = "Cancel Recording";
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/dialog/securitypage.cxx b/sfx2/source/dialog/securitypage.cxx
new file mode 100644
index 000000000000..2ac8f6a43fee
--- /dev/null
+++ b/sfx2/source/dialog/securitypage.cxx
@@ -0,0 +1,553 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "sfx2/securitypage.hxx"
+
+#include "securitypage.hrc"
+#include "sfxresid.hxx"
+
+#include <sfx2/sfx.hrc>
+#include <sfx2/sfxsids.hrc>
+#include <sfx2/objsh.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/passwd.hxx>
+
+#include <vcl/button.hxx>
+#include <vcl/edit.hxx>
+#include <vcl/fixed.hxx>
+#include <vcl/msgbox.hxx>
+#include <svl/eitem.hxx>
+#include <svl/poolitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/PasswordHelper.hxx>
+#include <svtools/xwindowitem.hxx>
+
+
+using namespace ::com::sun::star;
+
+//////////////////////////////////////////////////////////////////////
+
+
+namespace
+{
+ enum RedliningMode { RL_NONE, RL_WRITER, RL_CALC };
+ enum RedlineFunc { RF_ON, RF_PROTECT };
+
+/*
+ bool QueryIsEnabled( USHORT _nSlot )
+ {
+ bool bRes = false;
+ SfxViewShell* pViewSh = SfxViewShell::Current();
+ if (pViewSh)
+ {
+ const SfxPoolItem* pItem;
+ SfxDispatcher* pDisp = pViewSh->GetDispatcher();
+ SfxItemState eState = pDisp->QueryState( _nSlot, pItem );
+ bRes = (eState & SFX_ITEM_DISABLED) == 0;
+ }
+ return bRes;
+ }
+*/
+
+ bool QueryState( USHORT _nSlot, bool& _rValue )
+ {
+ bool bRet = false;
+ SfxViewShell* pViewSh = SfxViewShell::Current();
+ if (pViewSh)
+ {
+ const SfxPoolItem* pItem;
+ SfxDispatcher* pDisp = pViewSh->GetDispatcher();
+ SfxItemState nState = pDisp->QueryState( _nSlot, pItem );
+ bRet = SFX_ITEM_AVAILABLE <= nState;
+ if (bRet)
+ _rValue = ( static_cast< const SfxBoolItem* >( pItem ) )->GetValue();
+ }
+ return bRet;
+ }
+
+
+ bool QueryRecordChangesProtectionState( RedliningMode _eMode, bool& _rValue )
+ {
+ bool bRet = false;
+ if (_eMode != RL_NONE)
+ {
+ USHORT nSlot = _eMode == RL_WRITER ? FN_REDLINE_PROTECT : SID_CHG_PROTECT;
+ bRet = QueryState( nSlot, _rValue );
+ }
+ return bRet;
+ }
+
+
+ bool QueryRecordChangesState( RedliningMode _eMode, bool& _rValue )
+ {
+ bool bRet = false;
+ if (_eMode != RL_NONE)
+ {
+ USHORT nSlot = _eMode == RL_WRITER ? FN_REDLINE_ON : FID_CHG_RECORD;
+ bRet = QueryState( nSlot, _rValue );
+ }
+ return bRet;
+ }
+}
+
+
+//////////////////////////////////////////////////////////////////////
+
+
+static short lcl_GetPassword(
+ Window *pParent,
+ bool bProtect,
+ /*out*/String &rPassword )
+{
+ bool bRes = false;
+ SfxPasswordDialog aPasswdDlg( pParent );
+ const String aTitle( SfxResId( bProtect ? RID_SFX_PROTECT_RECORDS : RID_SFX_UNPROTECT_RECORDS ) );
+ aPasswdDlg.SetText( aTitle );
+ aPasswdDlg.SetMinLen( 1 );
+ if (bProtect)
+ aPasswdDlg.ShowExtras( SHOWEXTRAS_CONFIRM );
+ if (RET_OK == aPasswdDlg.Execute() && aPasswdDlg.GetPassword().Len() > 0)
+ {
+ rPassword = aPasswdDlg.GetPassword();
+ bRes = true;
+ }
+ return bRes;
+}
+
+
+static bool lcl_IsPasswordCorrect( const String &rPassword )
+{
+ bool bRes = false;
+
+ SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
+ uno::Sequence< sal_Int8 > aPasswordHash;
+ pCurDocShell->GetProtectionHash( aPasswordHash );
+
+ // check if supplied password was correct
+ uno::Sequence< sal_Int8 > aNewPasswd( aPasswordHash );
+ SvPasswordHelper::GetHashPassword( aNewPasswd, rPassword );
+ if (SvPasswordHelper::CompareHashPassword( aPasswordHash, rPassword ))
+ bRes = true; // password was correct
+ else
+ InfoBox( NULL, String( SfxResId( RID_SFX_INCORRECT_PASSWORD ) ) ).Execute();
+
+ return bRes;
+}
+
+
+//////////////////////////////////////////////////////////////////////
+
+
+struct SfxSecurityPage_Impl
+{
+ SfxSecurityPage & m_rMyTabPage;
+
+ FixedLine m_aNewPasswordToOpenFL;
+ FixedText m_aNewPasswordToOpenFT;
+ Edit m_aNewPasswordToOpenED;
+ FixedText m_aConfirmPasswordToOpenFT;
+ Edit m_aConfirmPasswordToOpenED;
+ FixedText m_aNewPasswordInfoFT;
+
+ FixedLine m_aNewPasswordToModifyFL;
+ FixedText m_aNewPasswordToModifyFT;
+ Edit m_aNewPasswordToModifyED;
+ FixedText m_aConfirmPasswordToModifyFT;
+ Edit m_aConfirmPasswordToModifyED;
+
+ FixedLine m_aOptionsFL;
+ CheckBox m_aOpenReadonlyCB;
+ CheckBox m_aRecordChangesCB; // for record changes
+ PushButton m_aChangeProtectionPB; // for record changes
+ String m_aProtectSTR; // for record changes
+ String m_aUnProtectSTR; // for record changes
+ RedliningMode m_eRedlingMode; // for record changes
+
+ bool m_bOrigPasswordIsConfirmed;
+ bool m_bNewPasswordIsValid;
+ String m_aNewPassword;
+
+ String m_aEndRedliningWarning;
+ bool m_bEndRedliningWarningDone;
+
+ DECL_LINK( RecordChangesCBToggleHdl, void* );
+ DECL_LINK( ChangeProtectionPBHdl, void* );
+
+ SfxSecurityPage_Impl( SfxSecurityPage &rDlg, const SfxItemSet &rItemSet );
+ ~SfxSecurityPage_Impl();
+
+ BOOL FillItemSet_Impl( SfxItemSet & );
+ void Reset_Impl( const SfxItemSet & );
+};
+
+
+SfxSecurityPage_Impl::SfxSecurityPage_Impl( SfxSecurityPage &rTabPage, const SfxItemSet & ) :
+ m_rMyTabPage (rTabPage),
+ m_aNewPasswordToOpenFL (&rTabPage, SfxResId( PASSWORD_TO_OPEN_FL ) ),
+ m_aNewPasswordToOpenFT (&rTabPage, SfxResId( PASSWORD_TO_OPEN_FT ) ),
+ m_aNewPasswordToOpenED (&rTabPage, SfxResId( PASSWORD_TO_OPEN_ED ) ),
+ m_aConfirmPasswordToOpenFT (&rTabPage, SfxResId( CONFIRM_PASSWORD_TO_OPEN_FT ) ),
+ m_aConfirmPasswordToOpenED (&rTabPage, SfxResId( CONFIRM_PASSWORD_TO_OPEN_ED ) ),
+ m_aNewPasswordInfoFT (&rTabPage, SfxResId( PASSWORD_INFO_FT ) ),
+ m_aNewPasswordToModifyFL (&rTabPage, SfxResId( PASSWORD_TO_MODIFY_FL ) ),
+ m_aNewPasswordToModifyFT (&rTabPage, SfxResId( PASSWORD_TO_MODIFY_FT ) ),
+ m_aNewPasswordToModifyED (&rTabPage, SfxResId( PASSWORD_TO_MODIFY_ED ) ),
+ m_aConfirmPasswordToModifyFT (&rTabPage, SfxResId( CONFIRM_PASSWORD_TO_MODIFY_FT ) ),
+ m_aConfirmPasswordToModifyED (&rTabPage, SfxResId( CONFIRM_PASSWORD_TO_MODIFY_ED ) ),
+ m_aOptionsFL (&rTabPage, SfxResId( OPTIONS_FL ) ),
+ m_aOpenReadonlyCB (&rTabPage, SfxResId( OPEN_READONLY_CB ) ),
+ m_aRecordChangesCB (&rTabPage, SfxResId( RECORD_CHANGES_CB ) ),
+ m_aChangeProtectionPB (&rTabPage, SfxResId( CHANGE_PROTECTION_PB ) ),
+ m_aProtectSTR ( SfxResId( STR_PROTECT ) ),
+ m_aUnProtectSTR ( SfxResId( STR_UNPROTECT ) ),
+ m_eRedlingMode ( RL_NONE ),
+ m_bOrigPasswordIsConfirmed ( false ),
+ m_bNewPasswordIsValid ( false ),
+ m_aEndRedliningWarning ( SfxResId( STR_END_REDLINING_WARNING ) ),
+ m_bEndRedliningWarningDone ( false )
+{
+ m_aChangeProtectionPB.SetText( m_aProtectSTR );
+ // adjust button width if necessary
+ long nBtnTextWidth = 0;
+ long nTemp = m_aChangeProtectionPB.GetCtrlTextWidth( m_aChangeProtectionPB.GetText() );
+ if (nTemp > nBtnTextWidth)
+ nBtnTextWidth = nTemp;
+
+ // force toggle hdl called before visual change of checkbox
+ m_aRecordChangesCB.SetStyle( m_aRecordChangesCB.GetStyle() | WB_EARLYTOGGLE );
+ m_aRecordChangesCB.SetToggleHdl( LINK( this, SfxSecurityPage_Impl, RecordChangesCBToggleHdl ) );
+ m_aChangeProtectionPB.SetClickHdl( LINK( this, SfxSecurityPage_Impl, ChangeProtectionPBHdl ) );
+
+
+ // #i112277: for the time being (OOO 3.3) the following options should not
+ // be available. In the long run however it is planned to implement the yet
+ // missing functionality. Thus now we hide them and move the remaining ones up.
+ m_aNewPasswordToOpenFL.Hide();
+ m_aNewPasswordToOpenFT.Hide();
+ m_aNewPasswordToOpenED.Hide();
+ m_aConfirmPasswordToOpenFT.Hide();
+ m_aConfirmPasswordToOpenED.Hide();
+ m_aNewPasswordInfoFT.Hide();
+ m_aNewPasswordToModifyFL.Hide();
+ m_aNewPasswordToModifyFT.Hide();
+ m_aNewPasswordToModifyED.Hide();
+ m_aConfirmPasswordToModifyFT.Hide();
+ m_aConfirmPasswordToModifyED.Hide();
+ const long nDelta = m_aOptionsFL.GetPosPixel().Y() - m_aNewPasswordToOpenFL.GetPosPixel().Y();
+ Point aPos;
+ aPos = m_aOptionsFL.GetPosPixel();
+ aPos.Y() -= nDelta;
+ m_aOptionsFL.SetPosPixel( aPos );
+ aPos = m_aOpenReadonlyCB.GetPosPixel();
+ aPos.Y() -= nDelta;
+ m_aOpenReadonlyCB.SetPosPixel( aPos );
+ aPos = m_aRecordChangesCB.GetPosPixel();
+ aPos.Y() -= nDelta;
+ m_aRecordChangesCB.SetPosPixel( aPos );
+ aPos = m_aChangeProtectionPB.GetPosPixel();
+ aPos.Y() -= nDelta;
+ m_aChangeProtectionPB.SetPosPixel( aPos );
+}
+
+
+SfxSecurityPage_Impl::~SfxSecurityPage_Impl()
+{
+}
+
+
+BOOL SfxSecurityPage_Impl::FillItemSet_Impl( SfxItemSet & )
+{
+ bool bModified = false;
+
+ SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
+ if (pCurDocShell&& !pCurDocShell->IsReadOnly())
+ {
+ if (m_eRedlingMode != RL_NONE )
+ {
+ const bool bDoRecordChanges = m_aRecordChangesCB.IsChecked();
+ const bool bDoChangeProtection = m_aChangeProtectionPB.GetText() != m_aProtectSTR;
+
+ // sanity checks
+ DBG_ASSERT( bDoRecordChanges || !bDoChangeProtection, "no change recording should imply no change protection" );
+ DBG_ASSERT( bDoChangeProtection || !bDoRecordChanges, "no change protection should imply no change recording" );
+ DBG_ASSERT( !bDoChangeProtection || m_aNewPassword.Len() > 0, "change protection should imply password length is > 0" );
+ DBG_ASSERT( bDoChangeProtection || m_aNewPassword.Len() == 0, "no change protection should imply password length is 0" );
+
+ // change recording
+ if (bDoRecordChanges != pCurDocShell->IsChangeRecording())
+ {
+ pCurDocShell->SetChangeRecording( bDoRecordChanges );
+ bModified = true;
+ }
+
+ // change record protection
+ if (m_bNewPasswordIsValid &&
+ bDoChangeProtection != pCurDocShell->HasChangeRecordProtection())
+ {
+ DBG_ASSERT( !bDoChangeProtection || bDoRecordChanges,
+ "change protection requires record changes to be active!" );
+ pCurDocShell->SetProtectionPassword( m_aNewPassword );
+ bModified = true;
+ }
+ }
+
+ // open read-only?
+ const sal_Bool bDoOpenReadonly = m_aOpenReadonlyCB.IsChecked();
+ if (pCurDocShell->HasSecurityOptOpenReadOnly() &&
+ bDoOpenReadonly != pCurDocShell->IsSecurityOptOpenReadOnly())
+ {
+ pCurDocShell->SetSecurityOptOpenReadOnly( bDoOpenReadonly );
+ bModified = true;
+ }
+ }
+
+ return bModified;
+}
+
+
+void SfxSecurityPage_Impl::Reset_Impl( const SfxItemSet & )
+{
+ SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
+
+ String sNewText = m_aProtectSTR;
+ if (!pCurDocShell)
+ {
+ // no doc -> hide document settings
+ m_aOpenReadonlyCB.Disable();
+ m_aRecordChangesCB.Disable();
+ m_aChangeProtectionPB.Disable();
+ }
+ else
+ {
+ bool bIsHTMLDoc = false;
+ SfxViewShell* pViewSh = SfxViewShell::Current();
+ if (pViewSh)
+ {
+ const SfxPoolItem* pItem;
+ SfxDispatcher* pDisp = pViewSh->GetDispatcher();
+ if (SFX_ITEM_AVAILABLE <= pDisp->QueryState( SID_HTML_MODE, pItem ))
+ {
+ USHORT nMode = static_cast< const SfxUInt16Item* >( pItem )->GetValue();
+ bIsHTMLDoc = ( ( nMode & HTMLMODE_ON ) != 0 );
+ }
+ }
+
+ sal_Bool bIsReadonly = pCurDocShell->IsReadOnly();
+ if (pCurDocShell->HasSecurityOptOpenReadOnly() && !bIsHTMLDoc)
+ {
+ m_aOpenReadonlyCB.Check( pCurDocShell->IsSecurityOptOpenReadOnly() );
+ m_aOpenReadonlyCB.Enable( !bIsReadonly );
+ }
+ else
+ m_aOpenReadonlyCB.Disable();
+
+ bool bRecordChanges;
+ if (QueryRecordChangesState( RL_WRITER, bRecordChanges ) && !bIsHTMLDoc)
+ m_eRedlingMode = RL_WRITER;
+ else if (QueryRecordChangesState( RL_CALC, bRecordChanges ))
+ m_eRedlingMode = RL_CALC;
+ else
+ m_eRedlingMode = RL_NONE;
+
+ if (m_eRedlingMode != RL_NONE)
+ {
+ bool bProtection;
+ QueryRecordChangesProtectionState( m_eRedlingMode, bProtection );
+
+ m_aChangeProtectionPB.Enable( !bIsReadonly );
+ // set the right text
+ if (bProtection)
+ sNewText = m_aUnProtectSTR;
+
+ m_aRecordChangesCB.Check( bRecordChanges );
+ m_aRecordChangesCB.Enable( /*!bProtection && */!bIsReadonly );
+
+ m_bOrigPasswordIsConfirmed = true; // default case if no password is set
+ uno::Sequence< sal_Int8 > aPasswordHash;
+ // check if password is available
+ if (pCurDocShell->GetProtectionHash( aPasswordHash ) &&
+ aPasswordHash.getLength() > 0)
+ m_bOrigPasswordIsConfirmed = false; // password found, needs to be confirmed later on
+ }
+ else
+ {
+ // A Calc document that is shared will have 'm_eRedlingMode == RL_NONE'
+ // In shared documents change recording and protection must be disabled,
+ // similar to documents that do not support change recording at all.
+ m_aRecordChangesCB.Check( FALSE );
+ m_aRecordChangesCB.Disable();
+ m_aChangeProtectionPB.Check( FALSE );
+ m_aChangeProtectionPB.Disable();
+ }
+ }
+
+ m_aChangeProtectionPB.SetText( sNewText );
+}
+
+
+IMPL_LINK( SfxSecurityPage_Impl, RecordChangesCBToggleHdl, void*, EMPTYARG )
+{
+ // when change recording gets disabled protection must be disabled as well
+ if (!m_aRecordChangesCB.IsChecked()) // the new check state is already present, thus the '!'
+ {
+ bool bAlreadyDone = false;
+ if (!m_bEndRedliningWarningDone)
+ {
+ WarningBox aBox( m_rMyTabPage.GetParent(), WinBits(WB_YES_NO | WB_DEF_NO),
+ m_aEndRedliningWarning );
+ if (aBox.Execute() != RET_YES)
+ bAlreadyDone = true;
+ else
+ m_bEndRedliningWarningDone = true;
+ }
+
+ const bool bNeedPasssword = !m_bOrigPasswordIsConfirmed
+ && m_aChangeProtectionPB.GetText() != m_aProtectSTR;
+ if (!bAlreadyDone && bNeedPasssword)
+ {
+ String aPasswordText;
+
+ // dialog canceled or no password provided
+ if (!lcl_GetPassword( m_rMyTabPage.GetParent(), false, aPasswordText ))
+ bAlreadyDone = true;
+
+ // ask for password and if dialog is canceled or no password provided return
+ if (lcl_IsPasswordCorrect( aPasswordText ))
+ m_bOrigPasswordIsConfirmed = true;
+ else
+ bAlreadyDone = true;
+ }
+
+ if (bAlreadyDone)
+ m_aRecordChangesCB.Check( true ); // restore original state
+ else
+ {
+ // remember required values to change protection and change recording in
+ // FillItemSet_Impl later on if password was correct.
+ m_bNewPasswordIsValid = true;
+ m_aNewPassword = String();
+
+ m_aChangeProtectionPB.SetText( m_aProtectSTR );
+ }
+ }
+
+ return 0;
+}
+
+
+IMPL_LINK( SfxSecurityPage_Impl, ChangeProtectionPBHdl, void*, EMPTYARG )
+{
+ if (m_eRedlingMode == RL_NONE)
+ return 0;
+
+ // the push button text is always the opposite of the current state. Thus:
+ const bool bCurrentProtection = m_aChangeProtectionPB.GetText() != m_aProtectSTR;
+
+ // ask user for password (if still necessary)
+ String aPasswordText;
+ bool bNewProtection = !bCurrentProtection;
+ const bool bNeedPassword = bNewProtection || !m_bOrigPasswordIsConfirmed;
+ if (bNeedPassword)
+ {
+ // ask for password and if dialog is canceled or no password provided return
+ if (!lcl_GetPassword( m_rMyTabPage.GetParent(), bNewProtection, aPasswordText ))
+ return 0;
+
+ // provided password still needs to be checked?
+ if (!bNewProtection && !m_bOrigPasswordIsConfirmed)
+ {
+ if (lcl_IsPasswordCorrect( aPasswordText ))
+ m_bOrigPasswordIsConfirmed = true;
+ else
+ return 0;
+ }
+ }
+ DBG_ASSERT( m_bOrigPasswordIsConfirmed, "ooops... this should not have happened!" );
+
+ // remember required values to change protection and change recording in
+ // FillItemSet_Impl later on if password was correct.
+ m_bNewPasswordIsValid = true;
+ m_aNewPassword = bNewProtection? aPasswordText : String();
+
+// // RecordChangesCB is enabled if protection is off
+// m_aRecordChangesCB.Enable( !bNewProtection );
+ m_aRecordChangesCB.Check( bNewProtection );
+ // toggle text of button "Protect" <-> "Unprotect"
+ m_aChangeProtectionPB.SetText( bNewProtection ? m_aUnProtectSTR : m_aProtectSTR );
+
+ return 0;
+}
+
+
+//////////////////////////////////////////////////////////////////////
+
+
+SfxTabPage* SfxSecurityPage::Create( Window * pParent, const SfxItemSet & rItemSet )
+{
+ return new SfxSecurityPage( pParent, rItemSet );
+}
+
+
+SfxSecurityPage::SfxSecurityPage( Window* pParent, const SfxItemSet& rItemSet ) :
+ SfxTabPage( pParent, SfxResId( TP_DOCINFOSECURITY ), rItemSet )
+{
+ m_pImpl = std::auto_ptr< SfxSecurityPage_Impl >(new SfxSecurityPage_Impl( *this, rItemSet ));
+
+ FreeResource();
+}
+
+
+SfxSecurityPage::~SfxSecurityPage()
+{
+}
+
+
+BOOL SfxSecurityPage::FillItemSet( SfxItemSet & rItemSet )
+{
+ bool bModified = false;
+ DBG_ASSERT( m_pImpl.get(), "implementation pointer is 0. Still in c-tor?" );
+ if (m_pImpl.get() != 0)
+ bModified = m_pImpl->FillItemSet_Impl( rItemSet );
+ return bModified;
+}
+
+
+void SfxSecurityPage::Reset( const SfxItemSet & rItemSet )
+{
+ DBG_ASSERT( m_pImpl.get(), "implementation pointer is 0. Still in c-tor?" );
+ if (m_pImpl.get() != 0)
+ m_pImpl->Reset_Impl( rItemSet );
+}
+
+
+//////////////////////////////////////////////////////////////////////
+
+
diff --git a/sfx2/source/dialog/securitypage.hrc b/sfx2/source/dialog/securitypage.hrc
new file mode 100755
index 000000000000..d425131b4772
--- /dev/null
+++ b/sfx2/source/dialog/securitypage.hrc
@@ -0,0 +1,52 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SECURITYPAGE_HRC_
+#define _SECURITYPAGE_HRC_
+
+
+#define PASSWORD_TO_OPEN_FL 1
+#define PASSWORD_TO_OPEN_FT 2
+#define PASSWORD_TO_OPEN_ED 3
+#define CONFIRM_PASSWORD_TO_OPEN_FT 4
+#define CONFIRM_PASSWORD_TO_OPEN_ED 5
+#define PASSWORD_INFO_FT 6
+#define PASSWORD_TO_MODIFY_FL 7
+#define PASSWORD_TO_MODIFY_FT 8
+#define PASSWORD_TO_MODIFY_ED 9
+#define CONFIRM_PASSWORD_TO_MODIFY_FT 10
+#define CONFIRM_PASSWORD_TO_MODIFY_ED 11
+#define OPTIONS_FL 12
+#define OPEN_READONLY_CB 13
+#define RECORD_CHANGES_CB 14
+#define CHANGE_PROTECTION_PB 15
+
+#define STR_PROTECT 101
+#define STR_UNPROTECT 102
+#define STR_END_REDLINING_WARNING 103
+
+#endif
+
diff --git a/sfx2/source/dialog/securitypage.src b/sfx2/source/dialog/securitypage.src
new file mode 100644
index 000000000000..fee60404d01c
--- /dev/null
+++ b/sfx2/source/dialog/securitypage.src
@@ -0,0 +1,174 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "sfx2/sfx.hrc"
+#include "securitypage.hrc"
+#include "helpid.hrc"
+#include "dialog.hrc"
+#include "sfxlocal.hrc"
+
+#include <svtools/controldims.hrc>
+
+
+TabPage TP_DOCINFOSECURITY
+{
+ HelpId = HID_DOCINFOSECURITY ;
+ Hide = TRUE ;
+ Size = MAP_APPFONT ( 260 , 185 ) ;
+
+ FixedLine PASSWORD_TO_OPEN_FL
+ {
+ Pos = MAP_APPFONT( 6, 6 );
+ Size = MAP_APPFONT( 248, RSC_CD_FIXEDLINE_HEIGHT );
+ Text [ en-US ] = "File encryption password";
+ };
+ FixedText PASSWORD_TO_OPEN_FT
+ {
+ Pos = MAP_APPFONT( 12, 20 );
+ Size = MAP_APPFONT( 82, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text [ en-US ] = "~Enter password to open";
+ };
+ Edit PASSWORD_TO_OPEN_ED
+ {
+ HelpId = HID_SECURITYTAB_PASSWORD_TO_OPEN;
+ Pos = MAP_APPFONT( 100, 18 );
+ Size = MAP_APPFONT( 88, RSC_CD_TEXTBOX_HEIGHT );
+ Border = TRUE;
+ PassWord = TRUE;
+ };
+ FixedText CONFIRM_PASSWORD_TO_OPEN_FT
+ {
+ Pos = MAP_APPFONT( 12, 34 );
+ Size = MAP_APPFONT( 82, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text [ en-US ] = "~Reenter password to open";
+ };
+ Edit CONFIRM_PASSWORD_TO_OPEN_ED
+ {
+ HelpId = HID_SECURITYTAB_CONFIRM_PASSWORD_TO_OPEN;
+ Pos = MAP_APPFONT( 100, 32 );
+ Size = MAP_APPFONT( 88, RSC_CD_TEXTBOX_HEIGHT );
+ Border = TRUE;
+ PassWord = TRUE;
+ };
+ FixedText PASSWORD_INFO_FT
+ {
+ Pos = MAP_APPFONT( 12, 48 );
+ Size = MAP_APPFONT( 236, 3 * RSC_CD_FIXEDTEXT_HEIGHT );
+ Text [ en-US ] =
+ "Note: After a password has been set, the document will only open "\
+ "with the password. Should you lose the password, there will be "\
+ "no way to recover the document. Please also note that this password "\
+ "is case-sensitive.";
+ WordBreak = TRUE;
+ };
+ FixedLine PASSWORD_TO_MODIFY_FL
+ {
+ Pos = MAP_APPFONT( 6, 78 );
+ Size = MAP_APPFONT( 248, RSC_CD_FIXEDLINE_HEIGHT );
+ Text [ en-US ] = "File sharing password";
+ };
+ FixedText PASSWORD_TO_MODIFY_FT
+ {
+ Pos = MAP_APPFONT( 12, 92 );
+ Size = MAP_APPFONT( 82, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text [ en-US ] = "Enter password to modify";
+ };
+ Edit PASSWORD_TO_MODIFY_ED
+ {
+ HelpId = HID_SECURITYTAB_PASSWORD_TO_MODIFY;
+ Pos = MAP_APPFONT( 100, 90 );
+ Size = MAP_APPFONT( 88, RSC_CD_TEXTBOX_HEIGHT );
+ Border = TRUE;
+ PassWord = TRUE;
+ };
+ FixedText CONFIRM_PASSWORD_TO_MODIFY_FT
+ {
+ Pos = MAP_APPFONT( 12, 106 );
+ Size = MAP_APPFONT( 82, RSC_CD_FIXEDTEXT_HEIGHT );
+ Text [ en-US ] = "Reenter password to modify";
+ };
+ Edit CONFIRM_PASSWORD_TO_MODIFY_ED
+ {
+ HelpId = HID_SECURITYTAB_CONFIRM_PASSWORD_TO_MODIFY;
+ Pos = MAP_APPFONT( 100, 104 );
+ Size = MAP_APPFONT( 88, RSC_CD_TEXTBOX_HEIGHT );
+ Border = TRUE;
+ PassWord = TRUE;
+ };
+ FixedLine OPTIONS_FL
+ {
+ Pos = MAP_APPFONT( 6, 120 );
+ Size = MAP_APPFONT( 248, RSC_CD_FIXEDLINE_HEIGHT );
+ Text [ en-US ] = "File sharing options";
+ };
+ CheckBox OPEN_READONLY_CB
+ {
+ HelpId = HID_SECURITYTAB_OPEN_FILE_READONLY;
+ Pos = MAP_APPFONT( 12, 133 );
+ Size = MAP_APPFONT( 176, RSC_CD_CHECKBOX_HEIGHT );
+ Text [ en-US ] = "~Open file read-only";
+ };
+ CheckBox RECORD_CHANGES_CB
+ {
+ HelpId = HID_SECURITYTAB_RECORD_CHANGES;
+ Pos = MAP_APPFONT( 12, 147 );
+ Size = MAP_APPFONT( 176, RSC_CD_CHECKBOX_HEIGHT );
+ Text [ en-US ] = "Record ~changes";
+ };
+ PushButton CHANGE_PROTECTION_PB
+ {
+ HelpId = HID_SECURITYTAB_PROTECTION;
+ Pos = MAP_APPFONT( 194, 145 );
+ Size = MAP_APPFONT( 60, RSC_CD_PUSHBUTTON_HEIGHT );
+ };
+ String STR_PROTECT
+ {
+ Text [ en-US ] = "~Protect...";
+ };
+ String STR_UNPROTECT
+ {
+ Text [ en-US ] = "~Unprotect...";
+ };
+ String STR_END_REDLINING_WARNING
+ {
+ Text [ en-US ] = "This action will exit the change recording mode.\nAny information about changes will be lost.\n\nExit change recording mode?\n\n" ;
+ };
+};
+
+String RID_SFX_PROTECT_RECORDS
+{
+ Text [ en-US ] = "Protect Records" ;
+};
+String RID_SFX_UNPROTECT_RECORDS
+{
+ Text [ en-US ] = "Unprotect Records" ;
+};
+String RID_SFX_INCORRECT_PASSWORD
+{
+ Text [ en-US ] = "Incorrect password" ;
+};
+
diff --git a/sfx2/source/dialog/sfxdlg.cxx b/sfx2/source/dialog/sfxdlg.cxx
new file mode 100755
index 000000000000..becab5097ec3
--- /dev/null
+++ b/sfx2/source/dialog/sfxdlg.cxx
@@ -0,0 +1,44 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sfx2/sfxdlg.hxx>
+//#include "cuilib.hxx"
+
+#include <osl/module.hxx>
+#include <tools/string.hxx>
+
+SfxAbstractDialogFactory* SfxAbstractDialogFactory::Create()
+{
+ return dynamic_cast <SfxAbstractDialogFactory*>( VclAbstractDialogFactory::Create() );
+}
+
+SfxAbstractDialogFactory::~SfxAbstractDialogFactory()
+{
+}
diff --git a/sfx2/source/dialog/splitwin.cxx b/sfx2/source/dialog/splitwin.cxx
new file mode 100644
index 000000000000..d4cc7950612f
--- /dev/null
+++ b/sfx2/source/dialog/splitwin.cxx
@@ -0,0 +1,1304 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifdef SOLARIS
+// HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
+#include <ctime>
+#endif
+
+#include <string> // HACK: prevent conflict between STLPORT and Workshop headers
+
+#ifndef _WRKWIN_HXX //autogen
+#include <vcl/wrkwin.hxx>
+#endif
+#include <unotools/viewoptions.hxx>
+#ifndef GCC
+#endif
+
+#include <vcl/timer.hxx>
+
+#include "splitwin.hxx"
+#include "workwin.hxx"
+#include <sfx2/dockwin.hxx>
+#include <sfx2/app.hxx>
+#include "dialog.hrc"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/mnumgr.hxx>
+#include "virtmenu.hxx"
+#include <sfx2/msgpool.hxx>
+#include <sfx2/viewfrm.hxx>
+
+using namespace ::com::sun::star::uno;
+using namespace ::rtl;
+
+#define VERSION 1
+#define nPixel 30L
+#define USERITEM_NAME OUString::createFromAscii( "UserItem" )
+
+struct SfxDock_Impl
+{
+ USHORT nType;
+ SfxDockingWindow* pWin; // SplitWindow hat dieses Fenster
+ BOOL bNewLine;
+ BOOL bHide; // SplitWindow hatte dieses Fenster
+ long nSize;
+};
+
+typedef SfxDock_Impl* SfxDockPtr;
+SV_DECL_PTRARR_DEL( SfxDockArr_Impl, SfxDockPtr, 4, 4)
+SV_IMPL_PTRARR( SfxDockArr_Impl, SfxDockPtr);
+
+class SfxEmptySplitWin_Impl : public SplitWindow
+{
+/* [Beschreibung]
+
+ Das SfxEmptySplitWin_Impldow ist ein leeres SplitWindow, das das SfxSplitWindow
+ im AutoHide-Modus ersetzt. Es dient nur als Platzhalter, um MouseMoves
+ zu empfangen und ggf. das eigentlichte SplitWindow einzublenden
+*/
+friend class SfxSplitWindow;
+
+ SfxSplitWindow* pOwner;
+ BOOL bFadeIn;
+ BOOL bAutoHide;
+ BOOL bSplit;
+ BOOL bEndAutoHide;
+ Timer aTimer;
+ Point aLastPos;
+ USHORT nState;
+
+ SfxEmptySplitWin_Impl( SfxSplitWindow *pParent )
+ : SplitWindow( pParent->GetParent(), WinBits( WB_BORDER | WB_3DLOOK ) )
+ , pOwner( pParent )
+ , bFadeIn( FALSE )
+ , bAutoHide( FALSE )
+ , bSplit( FALSE )
+ , bEndAutoHide( FALSE )
+ , nState( 1 )
+ {
+ aTimer.SetTimeoutHdl(
+ LINK(pOwner, SfxSplitWindow, TimerHdl ) );
+ aTimer.SetTimeout( 200 );
+// EnableDrop( TRUE );
+ SetAlign( pOwner->GetAlign() );
+ Actualize();
+ ShowAutoHideButton( pOwner->IsAutoHideButtonVisible() );
+ ShowFadeInHideButton( TRUE );
+ }
+
+ ~SfxEmptySplitWin_Impl()
+ {
+ aTimer.Stop();
+ }
+
+ virtual void MouseMove( const MouseEvent& );
+ virtual void AutoHide();
+ virtual void FadeIn();
+ void Actualize();
+};
+
+void SfxEmptySplitWin_Impl::Actualize()
+{
+ Size aSize( pOwner->GetSizePixel() );
+ switch ( pOwner->GetAlign() )
+ {
+ case WINDOWALIGN_LEFT:
+ case WINDOWALIGN_RIGHT:
+ aSize.Width() = GetFadeInSize();
+ break;
+ case WINDOWALIGN_TOP:
+ case WINDOWALIGN_BOTTOM:
+ aSize.Height() = GetFadeInSize();
+ break;
+ }
+
+ SetSizePixel( aSize );
+}
+
+void SfxEmptySplitWin_Impl::AutoHide()
+{
+ pOwner->SetPinned_Impl( !pOwner->bPinned );
+ pOwner->SaveConfig_Impl();
+ bAutoHide = TRUE;
+ FadeIn();
+}
+
+void SfxEmptySplitWin_Impl::FadeIn()
+{
+ if (!bAutoHide )
+ bAutoHide = IsFadeNoButtonMode();
+ pOwner->SetFadeIn_Impl( TRUE );
+ pOwner->Show_Impl();
+ if ( bAutoHide )
+ {
+ // Timer zum Schlie\sen aufsetzen; der Aufrufer mu\s selbst sicherstellen,
+ // da\s das Window nicht gleich wieder zu geht ( z.B. durch Setzen des
+ // Focus oder einen modal mode )
+ aLastPos = GetPointerPosPixel();
+ aTimer.Start();
+ }
+ else
+ pOwner->SaveConfig_Impl();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::MouseButtonDown( const MouseEvent& rMEvt )
+{
+ if ( rMEvt.GetClicks() != 2 )
+ SplitWindow::MouseButtonDown( rMEvt );
+}
+
+void SfxEmptySplitWin_Impl::MouseMove( const MouseEvent& rMEvt )
+{
+ SplitWindow::MouseMove( rMEvt );
+}
+
+//-------------------------------------------------------------------------
+
+SfxSplitWindow::SfxSplitWindow( Window* pParent, SfxChildAlignment eAl,
+ SfxWorkWindow *pW, BOOL bWithButtons, WinBits nBits )
+
+/* [Beschreibung]
+
+ Ein SfxSplitWindow verbirgt die rekursive Struktur des SV-Splitwindows
+ nach au\sen, indem es einen tabellenartigen Aufbau mit Zeilen und Spalten
+ ( also maximale Rekursionstiefe 2 ) simuliert.
+ Au\erdem sichert es die Persistenz der Anordnung der SfxDockingWindows.
+*/
+
+: SplitWindow ( pParent, nBits | WB_HIDE ),
+ eAlign(eAl),
+ pWorkWin(pW),
+ pDockArr( new SfxDockArr_Impl ),
+ bLocked(FALSE),
+ bPinned(TRUE),
+ pEmptyWin(NULL),
+ pActive(NULL)
+{
+ if ( bWithButtons )
+ {
+ ShowAutoHideButton( FALSE ); // no autohide button (pin) anymore
+ ShowFadeOutButton( TRUE );
+ }
+
+ // SV-Alignment setzen
+ WindowAlign eTbxAlign;
+ switch ( eAlign )
+ {
+ case SFX_ALIGN_LEFT:
+ eTbxAlign = WINDOWALIGN_LEFT;
+ break;
+ case SFX_ALIGN_RIGHT:
+ eTbxAlign = WINDOWALIGN_RIGHT;
+ break;
+ case SFX_ALIGN_TOP:
+ eTbxAlign = WINDOWALIGN_TOP;
+ break;
+ case SFX_ALIGN_BOTTOM:
+ eTbxAlign = WINDOWALIGN_BOTTOM;
+ bPinned = TRUE;
+ break;
+ default:
+ eTbxAlign = WINDOWALIGN_TOP; // some sort of default...
+ break; // -Wall lots not handled..
+ }
+
+ SetAlign (eTbxAlign);
+ pEmptyWin = new SfxEmptySplitWin_Impl( this );
+ if ( bPinned )
+ {
+ pEmptyWin->bFadeIn = TRUE;
+ pEmptyWin->nState = 2;
+ }
+
+ if ( bWithButtons )
+ {
+ // Konfiguration einlesen
+ String aWindowId = String::CreateFromAscii("SplitWindow");
+ aWindowId += String::CreateFromInt32( (sal_Int32) eTbxAlign );
+ SvtViewOptions aWinOpt( E_WINDOW, aWindowId );
+ String aWinData;
+ Any aUserItem = aWinOpt.GetUserItem( USERITEM_NAME );
+ OUString aTemp;
+ if ( aUserItem >>= aTemp )
+ aWinData = String( aTemp );
+ if ( aWinData.Len() && aWinData.GetChar( (USHORT) 0 ) == 'V' )
+ {
+ pEmptyWin->nState = (USHORT) aWinData.GetToken( 1, ',' ).ToInt32();
+ if ( pEmptyWin->nState & 2 )
+ pEmptyWin->bFadeIn = TRUE;
+ //bPinned = !( pEmptyWin->nState & 1 );
+ bPinned = TRUE; // always assume pinned - floating mode not used anymore
+
+ USHORT i=2;
+ USHORT nCount = (USHORT) aWinData.GetToken(i++, ',').ToInt32();
+ for ( USHORT n=0; n<nCount; n++ )
+ {
+ SfxDock_Impl *pDock = new SfxDock_Impl;
+ pDock->pWin = 0;
+ pDock->bNewLine = FALSE;
+ pDock->bHide = TRUE;
+ pDock->nType = (USHORT) aWinData.GetToken(i++, ',').ToInt32();
+ if ( !pDock->nType )
+ {
+ // K"onnte NewLine bedeuten
+ pDock->nType = (USHORT) aWinData.GetToken(i++, ',').ToInt32();
+ if ( !pDock->nType )
+ {
+ // Lesefehler
+ delete pDock;
+ break;
+ }
+ else
+ pDock->bNewLine = TRUE;
+ }
+
+ pDockArr->Insert(pDock,n);
+ }
+ }
+ }
+ else
+ {
+ bPinned = TRUE;
+ pEmptyWin->bFadeIn = TRUE;
+ pEmptyWin->nState = 2;
+ }
+
+ SetAutoHideState( !bPinned );
+ pEmptyWin->SetAutoHideState( !bPinned );
+}
+
+//-------------------------------------------------------------------------
+
+SfxSplitWindow::~SfxSplitWindow()
+{
+ if ( !pWorkWin->GetParent_Impl() )
+ SaveConfig_Impl();
+
+ if ( pEmptyWin )
+ {
+ // pOwner auf NULL setzen, sonst versucht pEmptyWin, nochmal zu
+ // l"oschen; es wird n"amlich von au\sen immer das Fenster deleted,
+ // das gerade angedockt ist
+ pEmptyWin->pOwner = NULL;
+ delete pEmptyWin;
+ }
+
+ delete pDockArr;
+}
+
+void SfxSplitWindow::SaveConfig_Impl()
+{
+ // Konfiguration abspeichern
+ String aWinData('V');
+ aWinData += String::CreateFromInt32( VERSION );
+ aWinData += ',';
+ aWinData += String::CreateFromInt32( pEmptyWin->nState );
+ aWinData += ',';
+
+ USHORT nCount = 0;
+ USHORT n;
+ for ( n=0; n<pDockArr->Count(); n++ )
+ {
+ SfxDock_Impl *pDock = (*pDockArr)[n];
+ if ( pDock->bHide || pDock->pWin )
+ nCount++;
+ }
+
+ aWinData += String::CreateFromInt32( nCount );
+
+ for ( n=0; n<pDockArr->Count(); n++ )
+ {
+ SfxDock_Impl *pDock = (*pDockArr)[n];
+ if ( !pDock->bHide && !pDock->pWin )
+ continue;
+ if ( pDock->bNewLine )
+ aWinData += DEFINE_CONST_UNICODE(",0");
+ aWinData += ',';
+ aWinData += String::CreateFromInt32( pDock->nType);
+ }
+
+ String aWindowId = String::CreateFromAscii("SplitWindow");
+ aWindowId += String::CreateFromInt32( (sal_Int32) GetAlign() );
+ SvtViewOptions aWinOpt( E_WINDOW, aWindowId );
+ aWinOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aWinData ) ) );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::StartSplit()
+{
+ long nSize = 0;
+ Size aSize = GetSizePixel();
+
+ if ( pEmptyWin )
+ {
+ pEmptyWin->bFadeIn = TRUE;
+ pEmptyWin->bSplit = TRUE;
+ }
+
+ Rectangle aRect = pWorkWin->GetFreeArea( !bPinned );
+ switch ( GetAlign() )
+ {
+ case WINDOWALIGN_LEFT:
+ case WINDOWALIGN_RIGHT:
+ nSize = aSize.Width() + aRect.GetWidth();
+ break;
+ case WINDOWALIGN_TOP:
+ case WINDOWALIGN_BOTTOM:
+ nSize = aSize.Height() + aRect.GetHeight();
+ break;
+ }
+
+ SetMaxSizePixel( nSize );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::SplitResize()
+{
+ if ( bPinned )
+ {
+ pWorkWin->ArrangeChilds_Impl();
+ pWorkWin->ShowChilds_Impl();
+ }
+ else
+ pWorkWin->ArrangeAutoHideWindows( this );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::Split()
+{
+ if ( pEmptyWin )
+ pEmptyWin->bSplit = FALSE;
+
+ SplitWindow::Split();
+
+ USHORT nCount = pDockArr->Count();
+ for ( USHORT n=0; n<nCount; n++ )
+ {
+ SfxDock_Impl *pD = (*pDockArr)[n];
+ if ( pD->pWin )
+ {
+ USHORT nId = pD->nType;
+ long nSize = GetItemSize( nId, SWIB_FIXED );
+ long nSetSize = GetItemSize( GetSet( nId ) );
+ Size aSize;
+
+ if ( IsHorizontal() )
+ {
+ aSize.Width() = nSize;
+ aSize.Height() = nSetSize;
+ }
+ else
+ {
+ aSize.Width() = nSetSize;
+ aSize.Height() = nSize;
+ }
+
+ pD->pWin->SetItemSize_Impl( aSize );
+ }
+ }
+
+ SaveConfig_Impl();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::InsertWindow( SfxDockingWindow* pDockWin, const Size& rSize)
+
+/* [Beschreibung]
+
+ Zum Einf"ugen von SfxDockingWindows kann auch keine Position "ubergeben
+ werden. Das SfxSplitWindow sucht dann die zuletzt gemerkte zu dem
+ "ubergebenen SfxDockingWindow heraus oder h"angt es als letztes neu an.
+
+*/
+{
+ short nLine = -1; // damit erstes Fenster nLine auf 0 hochsetzen kann
+ USHORT nL;
+ USHORT nPos = 0;
+ BOOL bNewLine = TRUE;
+ BOOL bSaveConfig = FALSE;
+ SfxDock_Impl *pFoundDock=0;
+ USHORT nCount = pDockArr->Count();
+ for ( USHORT n=0; n<nCount; n++ )
+ {
+ SfxDock_Impl *pDock = (*pDockArr)[n];
+ if ( pDock->bNewLine )
+ {
+ // Das Fenster er"offnet eine neue Zeile
+ if ( pFoundDock )
+ // Aber hinter dem gerade eingef"ugten Fenster
+ break;
+
+ // Neue Zeile
+ nPos = 0;
+ bNewLine = TRUE;
+ }
+
+ if ( pDock->pWin )
+ {
+ // Es gibt an dieser Stelle gerade ein Fenster
+ if ( bNewLine && !pFoundDock )
+ {
+ // Bisher ist nicht bekannt, in welcher realen Zeile es liegt
+ GetWindowPos( pDock->pWin, nL, nPos );
+ nLine = (short) nL;
+ }
+
+ if ( !pFoundDock )
+ {
+ // Fenster liegt vor dem eingef"ugten
+ nPos++;
+ }
+
+ // Zeile ist schon er"offnet
+ bNewLine = FALSE;
+ if ( pFoundDock )
+ break;
+ }
+
+ if ( pDock->nType == pDockWin->GetType() )
+ {
+ DBG_ASSERT( !pFoundDock && !pDock->pWin, "Fenster ist schon vorhanden!");
+ pFoundDock = pDock;
+ if ( !bNewLine )
+ break;
+ else
+ {
+ // Es wurde zuletzt eine neue Reihe gestartet, aber noch kein
+ // darin liegendes Fenster gefunden; daher weitersuchen, ob noch
+ // ein Fenster in dieser Zeile folgt, um bNewLine korrekt zu setzen.
+ // Dabei darf aber nLine oder nPos nicht mehr ver"andert werden!
+ nLine++;
+ }
+ }
+ }
+
+ if ( !pFoundDock )
+ {
+ // Nicht gefunden, am Ende einf"ugen
+ pFoundDock = new SfxDock_Impl;
+ pFoundDock->bHide = TRUE;
+ pDockArr->Insert( pFoundDock, nCount );
+ pFoundDock->nType = pDockWin->GetType();
+ nLine++;
+ nPos = 0;
+ bNewLine = TRUE;
+ pFoundDock->bNewLine = bNewLine;
+ bSaveConfig = TRUE;
+ }
+
+ pFoundDock->pWin = pDockWin;
+ pFoundDock->bHide = FALSE;
+ InsertWindow_Impl( pFoundDock, rSize, nLine, nPos, bNewLine );
+ if ( bSaveConfig )
+ SaveConfig_Impl();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::ReleaseWindow_Impl(SfxDockingWindow *pDockWin, BOOL bSave)
+
+/* [Beschreibung]
+
+ Das DockingWindow wird nicht mehr in den internen Daten gespeichert.
+*/
+
+{
+ SfxDock_Impl *pDock=0;
+ USHORT nCount = pDockArr->Count();
+ BOOL bFound = FALSE;
+ for ( USHORT n=0; n<nCount; n++ )
+ {
+ pDock = (*pDockArr)[n];
+ if ( pDock->nType == pDockWin->GetType() )
+ {
+ if ( pDock->bNewLine && n<nCount-1 )
+ (*pDockArr)[n+1]->bNewLine = TRUE;
+
+ // Fenster hat schon eine Position, die vergessen wir
+ bFound = TRUE;
+ pDockArr->Remove(n);
+ break;
+ }
+ }
+
+ if ( bFound )
+ delete pDock;
+
+ if ( bSave )
+ SaveConfig_Impl();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::MoveWindow( SfxDockingWindow* pDockWin, const Size& rSize,
+ USHORT nLine, USHORT nPos, BOOL bNewLine)
+
+/* [Beschreibung]
+
+ Das DockingWindow wird innerhalb des Splitwindows verschoben.
+
+*/
+
+{
+ USHORT nL, nP;
+ GetWindowPos( pDockWin, nL, nP );
+
+ if ( nLine > nL && GetItemCount( GetItemId( nL, 0 ) ) == 1 )
+ {
+ // Wenn das letzte Fenster aus seiner Zeile entfernt wird, rutscht
+ // alles eine Zeile nach vorne!
+ nLine--;
+ }
+/*
+ else if ( nLine == nL && nPos > nP )
+ {
+ nPos--;
+ }
+*/
+ RemoveWindow( pDockWin );
+ InsertWindow( pDockWin, rSize, nLine, nPos, bNewLine );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::InsertWindow( SfxDockingWindow* pDockWin, const Size& rSize,
+ USHORT nLine, USHORT nPos, BOOL bNewLine)
+
+/* [Beschreibung]
+
+ Das DockingWindow wird in dieses Splitwindow geschoben und soll die
+ "ubergebene Position und Gr"o\se haben.
+
+*/
+{
+ ReleaseWindow_Impl( pDockWin, FALSE );
+ SfxDock_Impl *pDock = new SfxDock_Impl;
+ pDock->bHide = FALSE;
+ pDock->nType = pDockWin->GetType();
+ pDock->bNewLine = bNewLine;
+ pDock->pWin = pDockWin;
+
+ DBG_ASSERT( nPos==0 || !bNewLine, "Falsche Paramenter!");
+ if ( bNewLine )
+ nPos = 0;
+
+ // Das Fenster mu\s vor dem ersten Fenster eingef"ugt werden, das die
+ // gleiche oder eine gr"o\sere Position hat als pDockWin.
+ USHORT nCount = pDockArr->Count();
+
+ // Wenn gar kein Fenster gefunden wird, wird als erstes eingef"ugt
+ USHORT nInsertPos = 0;
+ for ( USHORT n=0; n<nCount; n++ )
+ {
+ SfxDock_Impl *pD = (*pDockArr)[n];
+
+ if (pD->pWin)
+ {
+ // Ein angedocktes Fenster wurde gefunden
+ // Wenn kein geeignetes Fenster hinter der gew"unschten Einf"ugeposition
+ // gefunden wird, wird am Ende eingef"ugt
+ nInsertPos = nCount;
+ USHORT nL=0, nP=0;
+ GetWindowPos( pD->pWin, nL, nP );
+
+ if ( (nL == nLine && nP == nPos) || nL > nLine )
+ {
+ DBG_ASSERT( nL == nLine || bNewLine || nPos > 0, "Falsche Parameter!" );
+ if ( nL == nLine && nPos == 0 && !bNewLine )
+ {
+ DBG_ASSERT(pD->bNewLine, "Keine neue Zeile?");
+
+ // Das Fenster wird auf nPos==0 eingeschoben
+ pD->bNewLine = FALSE;
+ pDock->bNewLine = TRUE;
+ }
+
+ nInsertPos = n;
+ break;
+ }
+ }
+ }
+
+ pDockArr->Insert(pDock, nInsertPos);
+ InsertWindow_Impl( pDock, rSize, nLine, nPos, bNewLine );
+ SaveConfig_Impl();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::InsertWindow_Impl( SfxDock_Impl* pDock,
+ const Size& rSize,
+ USHORT nLine, USHORT nPos, BOOL bNewLine)
+
+/* [Beschreibung]
+
+ F"ugt ein DockingWindow ein und veranla\st die Neuberechnung der Gr"o\se
+ des Splitwindows.
+*/
+
+{
+ SfxDockingWindow* pDockWin = pDock->pWin;
+
+ USHORT nItemBits = pDockWin->GetWinBits_Impl();
+
+ long nWinSize, nSetSize;
+ if ( IsHorizontal() )
+ {
+ nWinSize = rSize.Width();
+ nSetSize = rSize.Height();
+ }
+ else
+ {
+ nSetSize = rSize.Width();
+ nWinSize = rSize.Height();
+ }
+
+ pDock->nSize = nWinSize;
+
+ BOOL bUpdateMode = IsUpdateMode();
+ if ( bUpdateMode )
+ SetUpdateMode( FALSE );
+
+ if ( bNewLine || nLine == GetItemCount( 0 ) )
+ {
+ // Es soll nicht in eine vorhandene Zeile eingef"ugt werden, sondern
+ // eine neue erzeugt werden
+
+ USHORT nId = 1;
+ for ( USHORT n=0; n<GetItemCount(0); n++ )
+ {
+ if ( GetItemId(n) >= nId )
+ nId = GetItemId(n)+1;
+ }
+
+ // Eine neue nLine-te Zeile erzeugen
+ USHORT nBits = nItemBits;
+ if ( GetAlign() == WINDOWALIGN_TOP || GetAlign() == WINDOWALIGN_BOTTOM )
+ nBits |= SWIB_COLSET;
+ InsertItem( nId, nSetSize, nLine, 0, nBits );
+ }
+
+ // In Zeile mit Position nLine das Fenster einf"ugen
+ // ItemWindowSize auf "Prozentual" setzen, da SV dann das Umgr"o\sern
+ // so macht, wie man erwartet; "Pixel" macht eigentlich nur Sinn, wenn
+ // auch Items mit prozentualen oder relativen Gr"o\sen dabei sind.
+ nItemBits |= SWIB_PERCENTSIZE;
+ bLocked = TRUE;
+ USHORT nSet = GetItemId( nLine );
+ InsertItem( pDockWin->GetType(), pDockWin, nWinSize, nPos, nSet, nItemBits );
+
+ // Splitwindows werden im SFX einmal angelegt und beim Einf"ugen des ersten
+ // DockingWindows sichtbar gemacht.
+ if ( GetItemCount( 0 ) == 1 && GetItemCount( 1 ) == 1 )
+ {
+ // Das Neuarrangieren am WorkWindow und ein Show() auf das SplitWindow
+ // wird vom SfxDockingwindow veranla\st (->SfxWorkWindow::ConfigChild_Impl)
+ if ( !bPinned && !IsFloatingMode() )
+ {
+ bPinned = TRUE;
+ BOOL bFadeIn = ( pEmptyWin->nState & 2 ) != 0;
+ pEmptyWin->bFadeIn = FALSE;
+ SetPinned_Impl( FALSE );
+ pEmptyWin->Actualize();
+ DBG_TRACE( "SfxSplitWindow::InsertWindow_Impl - registering empty Splitwindow" );
+ pWorkWin->RegisterChild_Impl( *GetSplitWindow(), eAlign, TRUE )->nVisible = CHILD_VISIBLE;
+ pWorkWin->ArrangeChilds_Impl();
+ if ( bFadeIn )
+ FadeIn();
+ }
+ else
+ {
+ BOOL bFadeIn = ( pEmptyWin->nState & 2 ) != 0;
+ pEmptyWin->bFadeIn = FALSE;
+ pEmptyWin->Actualize();
+#ifdef DBG_UTIL
+ if ( !bPinned || !pEmptyWin->bFadeIn )
+ {
+ DBG_TRACE( "SfxSplitWindow::InsertWindow_Impl - registering empty Splitwindow" );
+ }
+ else
+ {
+ DBG_TRACE( "SfxSplitWindow::InsertWindow_Impl - registering real Splitwindow" );
+ }
+#endif
+ pWorkWin->RegisterChild_Impl( *GetSplitWindow(), eAlign, TRUE )->nVisible = CHILD_VISIBLE;
+ pWorkWin->ArrangeChilds_Impl();
+ if ( bFadeIn )
+ FadeIn();
+ }
+
+ pWorkWin->ShowChilds_Impl();
+ }
+
+ if ( bUpdateMode )
+ SetUpdateMode( TRUE );
+ bLocked = FALSE;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::RemoveWindow( SfxDockingWindow* pDockWin, BOOL bHide )
+
+/* [Beschreibung]
+
+ Entfernt ein DockingWindow. Wenn es das letzte war, wird das SplitWindow
+ gehidet.
+*/
+{
+ USHORT nSet = GetSet( pDockWin->GetType() );
+
+ // Splitwindows werden im SFX einmal angelegt und nach dem Entfernen
+ // des letzten DockingWindows unsichtbar gemacht.
+ if ( GetItemCount( nSet ) == 1 && GetItemCount( 0 ) == 1 )
+ {
+ // Das Neuarrangieren am WorkWindow wird vom SfxDockingwindow
+ // veranla\st!
+ Hide();
+ pEmptyWin->aTimer.Stop();
+ USHORT nRealState = pEmptyWin->nState;
+ FadeOut_Impl();
+ pEmptyWin->Hide();
+#ifdef DBG_UTIL
+ if ( !bPinned || !pEmptyWin->bFadeIn )
+ {
+ DBG_TRACE( "SfxSplitWindow::RemoveWindow - releasing empty Splitwindow" );
+ }
+ else
+ {
+ DBG_TRACE( "SfxSplitWindow::RemoveWindow - releasing real Splitwindow" );
+ }
+#endif
+ pWorkWin->ReleaseChild_Impl( *GetSplitWindow() );
+ pEmptyWin->nState = nRealState;
+ pWorkWin->ArrangeAutoHideWindows( this );
+ }
+
+ SfxDock_Impl *pDock=0;
+ USHORT nCount = pDockArr->Count();
+ for ( USHORT n=0; n<nCount; n++ )
+ {
+ pDock = (*pDockArr)[n];
+ if ( pDock->nType == pDockWin->GetType() )
+ {
+ pDock->pWin = 0;
+ pDock->bHide = bHide;
+ break;
+ }
+ }
+
+ // Fenster removen, und wenn es das letzte der Zeile war, auch die Zeile
+ // ( Zeile = ItemSet )
+ BOOL bUpdateMode = IsUpdateMode();
+ if ( bUpdateMode )
+ SetUpdateMode( FALSE );
+ bLocked = TRUE;
+
+ RemoveItem( pDockWin->GetType() );
+
+ if ( nSet && !GetItemCount( nSet ) )
+ RemoveItem( nSet );
+
+ if ( bUpdateMode )
+ SetUpdateMode( TRUE );
+ bLocked = FALSE;
+};
+
+//-------------------------------------------------------------------------
+
+BOOL SfxSplitWindow::GetWindowPos( const SfxDockingWindow* pWindow,
+ USHORT& rLine, USHORT& rPos ) const
+/* [Beschreibung]
+
+ Liefert die Id des Itemsets und die des Items f"ur das "ubergebene
+ DockingWindow in der alten Zeilen/Spalten-Bezeichnung zur"uck.
+*/
+
+{
+ USHORT nSet = GetSet ( pWindow->GetType() );
+ if ( nSet == SPLITWINDOW_ITEM_NOTFOUND )
+ return FALSE;
+
+ rPos = GetItemPos( pWindow->GetType(), nSet );
+ rLine = GetItemPos( nSet );
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxSplitWindow::GetWindowPos( const Point& rTestPos,
+ USHORT& rLine, USHORT& rPos ) const
+/* [Beschreibung]
+
+ Liefert die Id des Itemsets und die des Items f"ur das DockingWindow
+ an der "ubergebenen Position in der alten Zeilen/Spalten-Bezeichnung
+ zur"uck.
+*/
+
+{
+ USHORT nId = GetItemId( rTestPos );
+ if ( nId == 0 )
+ return FALSE;
+
+ USHORT nSet = GetSet ( nId );
+ rPos = GetItemPos( nId, nSet );
+ rLine = GetItemPos( nSet );
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+USHORT SfxSplitWindow::GetLineCount() const
+
+/* [Beschreibung]
+
+ Liefert die Zeilenzahl = Zahl der Sub-Itemsets im Root-Set.
+*/
+{
+ return GetItemCount( 0 );
+}
+
+//-------------------------------------------------------------------------
+
+long SfxSplitWindow::GetLineSize( USHORT nLine ) const
+
+/* [Beschreibung]
+
+ Liefert die "Zeilenh"ohe" des nLine-ten Itemsets.
+*/
+{
+ USHORT nId = GetItemId( nLine );
+ return GetItemSize( nId );
+}
+
+//-------------------------------------------------------------------------
+
+USHORT SfxSplitWindow::GetWindowCount( USHORT nLine ) const
+
+/* [Beschreibung]
+
+ Liefert die
+*/
+{
+ USHORT nId = GetItemId( nLine );
+ return GetItemCount( nId );
+}
+
+//-------------------------------------------------------------------------
+
+USHORT SfxSplitWindow::GetWindowCount() const
+
+/* [Beschreibung]
+
+ Liefert die Gesamtzahl aller Fenstert
+*/
+{
+ return GetItemCount( 0 );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::Command( const CommandEvent& rCEvt )
+{
+ SplitWindow::Command( rCEvt );
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxSplitWindow, TimerHdl, Timer*, pTimer)
+{
+ if ( pTimer )
+ pTimer->Stop();
+
+ if ( CursorIsOverRect( FALSE ) || !pTimer )
+ {
+ // Wenn der Mauszeiger innerhalb des Fensters liegt, SplitWindow anzeigen
+ // und Timer zum Schlie\sen aufsetzen
+ pEmptyWin->bAutoHide = TRUE;
+ if ( !IsVisible() )
+ pEmptyWin->FadeIn();
+
+ pEmptyWin->aLastPos = GetPointerPosPixel();
+ pEmptyWin->aTimer.Start();
+ }
+ else if ( pEmptyWin->bAutoHide )
+ {
+ if ( GetPointerPosPixel() != pEmptyWin->aLastPos )
+ {
+ // Die Maus wurd innerhalb der Timerlaugzeit bewegt, also erst einmal
+ // nichts tun
+ pEmptyWin->aLastPos = GetPointerPosPixel();
+ pEmptyWin->aTimer.Start();
+ return 0L;
+ }
+
+ // Speziell f"ur TF_AUTOSHOW_ON_MOUSEMOVE :
+ // Wenn das Fenster nicht sichtbar ist, gibt es nichts zu tun
+ // (Benutzer ist einfach mit der Maus "uber pEmptyWin gefahren)
+ if ( IsVisible() )
+ {
+ pEmptyWin->bEndAutoHide = FALSE;
+ if ( !Application::IsInModalMode() &&
+ !PopupMenu::IsInExecute() &&
+ !pEmptyWin->bSplit && !HasChildPathFocus( TRUE ) )
+ {
+ // W"ahrend ein modaler Dialog oder ein Popupmenu offen sind
+ // oder w"ahrend des Splittens auf keinen Fall zumachen; auch
+ // solange eines der Children den Focus hat, bleibt das
+ // das Fenster offen
+ pEmptyWin->bEndAutoHide = TRUE;
+ }
+
+ if ( pEmptyWin->bEndAutoHide )
+ {
+ // Von mir aus kann Schlu\s sein mit AutoShow
+ // Aber vielleicht will noch ein anderes SfxSplitWindow offen bleiben,
+ // dann bleiben auch alle anderen offen
+ if ( !pWorkWin->IsAutoHideMode( this ) )
+ {
+ FadeOut_Impl();
+ pWorkWin->ArrangeAutoHideWindows( this );
+ }
+ else
+ {
+ pEmptyWin->aLastPos = GetPointerPosPixel();
+ pEmptyWin->aTimer.Start();
+ }
+ }
+ else
+ {
+ pEmptyWin->aLastPos = GetPointerPosPixel();
+ pEmptyWin->aTimer.Start();
+ }
+ }
+ }
+
+ return 0L;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxSplitWindow::CursorIsOverRect( BOOL bForceAdding ) const
+{
+ BOOL bVisible = IsVisible();
+
+ // Auch das kollabierte SplitWindow ber"ucksichtigen
+ Point aPos = pEmptyWin->GetParent()->OutputToScreenPixel( pEmptyWin->GetPosPixel() );
+ Size aSize = pEmptyWin->GetSizePixel();
+
+ if ( bForceAdding )
+ {
+ // Um +/- ein paar Pixel erweitern, sonst ist es zu nerv"os
+ aPos.X() -= nPixel;
+ aPos.Y() -= nPixel;
+ aSize.Width() += 2 * nPixel;
+ aSize.Height() += 2 * nPixel;
+ }
+
+ Rectangle aRect( aPos, aSize );
+
+ if ( bVisible )
+ {
+ Point aVisPos = GetPosPixel();
+ Size aVisSize = GetSizePixel();
+
+ // Um +/- ein paar Pixel erweitern, sonst ist es zu nerv"os
+ aVisPos.X() -= nPixel;
+ aVisPos.Y() -= nPixel;
+ aVisSize.Width() += 2 * nPixel;
+ aVisSize.Height() += 2 * nPixel;
+
+ Rectangle aVisRect( aVisPos, aVisSize );
+ aRect = aRect.GetUnion( aVisRect );
+ }
+
+ if ( aRect.IsInside( OutputToScreenPixel( ((Window*)this)->GetPointerPosPixel() ) ) )
+ return TRUE;
+ return FALSE;
+}
+
+//-------------------------------------------------------------------------
+
+SplitWindow* SfxSplitWindow::GetSplitWindow()
+{
+ if ( !bPinned || !pEmptyWin->bFadeIn )
+ return pEmptyWin;
+ return this;
+}
+
+//-------------------------------------------------------------------------
+BOOL SfxSplitWindow::IsFadeIn() const
+{
+ return pEmptyWin->bFadeIn;
+}
+
+BOOL SfxSplitWindow::IsAutoHide( BOOL bSelf ) const
+{
+ return bSelf ? pEmptyWin->bAutoHide && !pEmptyWin->bEndAutoHide : pEmptyWin->bAutoHide;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::SetPinned_Impl( BOOL bOn )
+{
+ if ( bPinned == bOn )
+ return;
+
+ bPinned = bOn;
+ if ( GetItemCount( 0 ) == 0 )
+ return;
+
+ if ( !bOn )
+ {
+ pEmptyWin->nState |= 1;
+ if ( pEmptyWin->bFadeIn )
+ {
+ // Ersatzfenster anmelden
+ DBG_TRACE( "SfxSplitWindow::SetPinned_Impl - releasing real Splitwindow" );
+ pWorkWin->ReleaseChild_Impl( *this );
+ Hide();
+ pEmptyWin->Actualize();
+ DBG_TRACE( "SfxSplitWindow::SetPinned_Impl - registering empty Splitwindow" );
+ pWorkWin->RegisterChild_Impl( *pEmptyWin, eAlign, TRUE )->nVisible = CHILD_VISIBLE;
+ }
+
+ Point aPos( GetPosPixel() );
+ aPos = GetParent()->OutputToScreenPixel( aPos );
+ SetFloatingPos( aPos );
+ SetFloatingMode( TRUE );
+ GetFloatingWindow()->SetOutputSizePixel( GetOutputSizePixel() );
+
+ if ( pEmptyWin->bFadeIn )
+ Show();
+ }
+ else
+ {
+ pEmptyWin->nState &= ~1;
+ SetOutputSizePixel( GetFloatingWindow()->GetOutputSizePixel() );
+ SetFloatingMode( FALSE );
+
+ if ( pEmptyWin->bFadeIn )
+ {
+ // Ersatzfenster abmelden
+ DBG_TRACE( "SfxSplitWindow::SetPinned_Impl - releasing empty Splitwindow" );
+ pWorkWin->ReleaseChild_Impl( *pEmptyWin );
+ pEmptyWin->Hide();
+ DBG_TRACE( "SfxSplitWindow::SetPinned_Impl - registering real Splitwindow" );
+ pWorkWin->RegisterChild_Impl( *this, eAlign, TRUE )->nVisible = CHILD_VISIBLE;
+ }
+ }
+
+ SetAutoHideState( !bPinned );
+ pEmptyWin->SetAutoHideState( !bPinned );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxSplitWindow::SetFadeIn_Impl( BOOL bOn )
+{
+ if ( bOn == pEmptyWin->bFadeIn )
+ return;
+
+ if ( GetItemCount( 0 ) == 0 )
+ return;
+
+ pEmptyWin->bFadeIn = bOn;
+ if ( bOn )
+ {
+ pEmptyWin->nState |= 2;
+ if ( IsFloatingMode() )
+ {
+ // FloatingWindow ist nicht sichtbar, also anzeigen
+ pWorkWin->ArrangeAutoHideWindows( this );
+ Show();
+ }
+ else
+ {
+ DBG_TRACE( "SfxSplitWindow::SetFadeIn_Impl - releasing empty Splitwindow" );
+ pWorkWin->ReleaseChild_Impl( *pEmptyWin );
+ pEmptyWin->Hide();
+ DBG_TRACE( "SfxSplitWindow::SetFadeIn_Impl - registering real Splitwindow" );
+ pWorkWin->RegisterChild_Impl( *this, eAlign, TRUE )->nVisible = CHILD_VISIBLE;
+ pWorkWin->ArrangeChilds_Impl();
+ pWorkWin->ShowChilds_Impl();
+ }
+ }
+ else
+ {
+ pEmptyWin->bAutoHide = FALSE;
+ pEmptyWin->nState &= ~2;
+ if ( !IsFloatingMode() )
+ {
+ // Das Fenster "schwebt" nicht, soll aber ausgeblendet werden,
+ DBG_TRACE( "SfxSplitWindow::SetFadeIn_Impl - releasing real Splitwindow" );
+ pWorkWin->ReleaseChild_Impl( *this );
+ Hide();
+ pEmptyWin->Actualize();
+ DBG_TRACE( "SfxSplitWindow::SetFadeIn_Impl - registering empty Splitwindow" );
+ pWorkWin->RegisterChild_Impl( *pEmptyWin, eAlign, TRUE )->nVisible = CHILD_VISIBLE;
+ pWorkWin->ArrangeChilds_Impl();
+ pWorkWin->ShowChilds_Impl();
+ pWorkWin->ArrangeAutoHideWindows( this );
+ }
+ else
+ {
+ Hide();
+ pWorkWin->ArrangeAutoHideWindows( this );
+ }
+ }
+}
+
+void SfxSplitWindow::AutoHide()
+{
+ // Wenn dieser Handler am "echten" SplitWindow aufgerufen wird, ist es
+ // entweder angedockt und soll "schwebend" angezeigt werden oder umgekehrt
+ if ( !bPinned )
+ {
+ // Es "schwebt", also wieder andocken
+ SetPinned_Impl( TRUE );
+ pWorkWin->ArrangeChilds_Impl();
+ }
+ else
+ {
+ // In den "Schwebezustand" bringen
+ SetPinned_Impl( FALSE );
+ pWorkWin->ArrangeChilds_Impl();
+ pWorkWin->ArrangeAutoHideWindows( this );
+ }
+
+ pWorkWin->ShowChilds_Impl();
+ SaveConfig_Impl();
+}
+
+void SfxSplitWindow::FadeOut_Impl()
+{
+ if ( pEmptyWin->aTimer.IsActive() )
+ {
+ pEmptyWin->bAutoHide = FALSE;
+ pEmptyWin->aTimer.Stop();
+ }
+
+ SetFadeIn_Impl( FALSE );
+ Show_Impl();
+}
+
+void SfxSplitWindow::FadeOut()
+{
+ FadeOut_Impl();
+ SaveConfig_Impl();
+}
+
+void SfxSplitWindow::FadeIn()
+{
+ SetFadeIn_Impl( TRUE );
+ Show_Impl();
+}
+
+void SfxSplitWindow::Show_Impl()
+{
+ USHORT nCount = pDockArr->Count();
+ for ( USHORT n=0; n<nCount; n++ )
+ {
+ SfxDock_Impl *pDock = (*pDockArr)[n];
+ if ( pDock->pWin )
+ pDock->pWin->FadeIn( pEmptyWin->bFadeIn );
+ }
+}
+/*
+void SfxSplitWindow::Pin_Impl( BOOL bPin )
+{
+ if ( bPinned != bPin )
+ AutoHide();
+}
+*/
+BOOL SfxSplitWindow::ActivateNextChild_Impl( BOOL bForward )
+{
+ // Wenn kein pActive, auf erstes bzw. letztes Fenster gehen ( bei !bForward wird erst in der loop dekrementiert )
+ USHORT nCount = pDockArr->Count();
+ USHORT n = bForward ? 0 : nCount;
+
+ // Wenn Focus innerhalb, dann ein Fenster vor oder zur"uck, wenn m"oglich
+ if ( pActive )
+ {
+ // Aktives Fenster ermitteln
+ for ( n=0; n<nCount; n++ )
+ {
+ SfxDock_Impl *pD = (*pDockArr)[n];
+ if ( pD->pWin && pD->pWin->HasChildPathFocus() )
+ break;
+ }
+
+ if ( bForward )
+ // ein Fenster weiter ( wenn dann n>nCount, wird die Schleife unten gar nicht durchlaufen )
+ n++;
+ }
+
+ if ( bForward )
+ {
+ // N"achstes Fenster suchen
+ for ( USHORT nNext=n; nNext<nCount; nNext++ )
+ {
+ SfxDock_Impl *pD = (*pDockArr)[nNext];
+ if ( pD->pWin )
+ {
+ pD->pWin->GrabFocus();
+ return TRUE;
+ }
+ }
+ }
+ else
+ {
+ // Vorheriges Fenster suchen
+ for ( USHORT nNext=n; nNext--; )
+ {
+ SfxDock_Impl *pD = (*pDockArr)[nNext];
+ if ( pD->pWin )
+ {
+ pD->pWin->GrabFocus();
+ return TRUE;
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+void SfxSplitWindow::SetActiveWindow_Impl( SfxDockingWindow* pWin )
+{
+ pActive = pWin;
+ pWorkWin->SetActiveChild_Impl( this );
+}
+
+
diff --git a/sfx2/source/dialog/srchdlg.cxx b/sfx2/source/dialog/srchdlg.cxx
new file mode 100644
index 000000000000..f4d2392c9017
--- /dev/null
+++ b/sfx2/source/dialog/srchdlg.cxx
@@ -0,0 +1,202 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "srchdlg.hxx"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/sfxuno.hxx>
+
+#include "srchdlg.hrc"
+#include "dialog.hrc"
+#include <tools/debug.hxx>
+#include <unotools/viewoptions.hxx>
+
+using namespace ::com::sun::star::uno;
+
+// ============================================================================
+
+namespace sfx2 {
+
+#define USERITEM_NAME DEFINE_CONST_OUSTRING("UserItem")
+#define MAX_SAVE_COUNT (USHORT)10
+
+// ============================================================================
+// SearchDialog
+// ============================================================================
+
+SearchDialog::SearchDialog( Window* pWindow, const ::rtl::OUString& rConfigName ) :
+
+ ModelessDialog( pWindow, SfxResId( RID_DLG_SEARCH ) ),
+
+ m_aSearchLabel ( this, SfxResId( FT_SEARCH ) ),
+ m_aSearchEdit ( this, SfxResId( ED_SEARCH ) ),
+ m_aWholeWordsBox ( this, SfxResId( CB_WHOLEWORDS ) ),
+ m_aMatchCaseBox ( this, SfxResId( CB_MATCHCASE ) ),
+ m_aWrapAroundBox ( this, SfxResId( CB_WRAPAROUND ) ),
+ m_aBackwardsBox ( this, SfxResId( CB_BACKWARDS ) ),
+ m_aFindBtn ( this, SfxResId( PB_FIND ) ),
+ m_aCancelBtn ( this, SfxResId( PB_CANCELFIND ) ),
+ m_sToggleText ( SfxResId( STR_TOGGLE ) ),
+ m_sConfigName ( rConfigName ),
+ m_bIsConstructed ( false )
+
+{
+ FreeResource();
+
+ // set handler
+ m_aFindBtn.SetClickHdl( LINK( this, SearchDialog, FindHdl ) );
+ m_aBackwardsBox.SetClickHdl( LINK( this, SearchDialog, ToggleHdl ) );
+ // load config: old search strings and the status of the check boxes
+ LoadConfig();
+ // we need to change the text of the WrapAround box, depends on the status of the Backwards box
+ if ( m_aBackwardsBox.IsChecked() )
+ ToggleHdl( &m_aBackwardsBox );
+ // the search edit should have the focus
+ m_aSearchEdit.GrabFocus();
+}
+
+SearchDialog::~SearchDialog()
+{
+ SaveConfig();
+ m_aCloseHdl.Call( NULL );
+}
+
+void SearchDialog::LoadConfig()
+{
+ SvtViewOptions aViewOpt( E_DIALOG, m_sConfigName );
+ if ( aViewOpt.Exists() )
+ {
+ m_sWinState = ByteString( aViewOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US );
+ Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
+ ::rtl::OUString aTemp;
+ if ( aUserItem >>= aTemp )
+ {
+ String sUserData( aTemp );
+ DBG_ASSERT( sUserData.GetTokenCount() == 5, "invalid config data" );
+ xub_StrLen nIdx = 0;
+ String sSearchText = sUserData.GetToken( 0, ';', nIdx );
+ m_aWholeWordsBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
+ m_aMatchCaseBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
+ m_aWrapAroundBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
+ m_aBackwardsBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
+
+ nIdx = 0;
+ while ( nIdx != STRING_NOTFOUND )
+ m_aSearchEdit.InsertEntry( sSearchText.GetToken( 0, '\t', nIdx ) );
+ m_aSearchEdit.SelectEntryPos(0);
+ }
+ }
+ else
+ m_aWrapAroundBox.Check( TRUE );
+}
+
+void SearchDialog::SaveConfig()
+{
+ SvtViewOptions aViewOpt( E_DIALOG, m_sConfigName );
+ aViewOpt.SetWindowState( rtl::OUString::createFromAscii( m_sWinState.GetBuffer() ) );
+ String sUserData;
+ USHORT i = 0, nCount = Min( m_aSearchEdit.GetEntryCount(), MAX_SAVE_COUNT );
+ for ( ; i < nCount; ++i )
+ {
+ sUserData += m_aSearchEdit.GetEntry(i);
+ sUserData += '\t';
+ }
+ sUserData.EraseTrailingChars( '\t' );
+ sUserData += ';';
+ sUserData += String::CreateFromInt32( m_aWholeWordsBox.IsChecked() ? 1 : 0 );
+ sUserData += ';';
+ sUserData += String::CreateFromInt32( m_aMatchCaseBox.IsChecked() ? 1 : 0 );
+ sUserData += ';';
+ sUserData += String::CreateFromInt32( m_aWrapAroundBox.IsChecked() ? 1 : 0 );
+ sUserData += ';';
+ sUserData += String::CreateFromInt32( m_aBackwardsBox.IsChecked() ? 1 : 0 );
+
+ Any aUserItem = makeAny( ::rtl::OUString( sUserData ) );
+ aViewOpt.SetUserItem( USERITEM_NAME, aUserItem );
+}
+
+IMPL_LINK( SearchDialog, FindHdl, PushButton*, EMPTYARG )
+{
+ String sSrchTxt = m_aSearchEdit.GetText();
+ USHORT nPos = m_aSearchEdit.GetEntryPos( sSrchTxt );
+ if ( nPos > 0 && nPos != COMBOBOX_ENTRY_NOTFOUND )
+ m_aSearchEdit.RemoveEntry( nPos );
+ if ( nPos > 0 )
+ m_aSearchEdit.InsertEntry( sSrchTxt, 0 );
+ m_aFindHdl.Call( this );
+ return 0;
+}
+
+IMPL_LINK( SearchDialog, ToggleHdl, CheckBox*, EMPTYARG )
+{
+ String sTemp = m_aWrapAroundBox.GetText();
+ m_aWrapAroundBox.SetText( m_sToggleText );
+ m_sToggleText = sTemp;
+ return 0;
+}
+
+void SearchDialog::SetFocusOnEdit()
+{
+ Selection aSelection( 0, m_aSearchEdit.GetText().Len() );
+ m_aSearchEdit.SetSelection( aSelection );
+ m_aSearchEdit.GrabFocus();
+}
+
+BOOL SearchDialog::Close()
+{
+ BOOL bRet = ModelessDialog::Close();
+ m_aCloseHdl.Call( this );
+ return bRet;
+}
+
+void SearchDialog::StateChanged( StateChangedType nStateChange )
+{
+ if ( nStateChange == STATE_CHANGE_INITSHOW )
+ {
+ if ( m_sWinState.Len() )
+ SetWindowState( m_sWinState );
+ m_bIsConstructed = TRUE;
+ }
+
+ ModelessDialog::StateChanged( nStateChange );
+}
+
+void SearchDialog::Move()
+{
+ ModelessDialog::Move();
+ if ( m_bIsConstructed && IsReallyVisible() )
+ m_sWinState = GetWindowState( WINDOWSTATE_MASK_POS | WINDOWSTATE_MASK_STATE );
+}
+
+// ============================================================================
+
+} // namespace sfx2
+
+// ============================================================================
+
diff --git a/sfx2/source/dialog/srchdlg.hrc b/sfx2/source/dialog/srchdlg.hrc
new file mode 100644
index 000000000000..55fe9ce47d26
--- /dev/null
+++ b/sfx2/source/dialog/srchdlg.hrc
@@ -0,0 +1,43 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_SRCHDLG_HRC_
+#define _SFX_SRCHDLG_HRC_
+
+#define FT_SEARCH 10
+#define ED_SEARCH 11
+#define FL_OPTIONS 12
+#define CB_WHOLEWORDS 13
+#define CB_MATCHCASE 14
+#define CB_WRAPAROUND 15
+#define CB_BACKWARDS 16
+#define PB_FIND 17
+#define PB_CANCELFIND 18
+
+#define STR_TOGGLE 50
+
+#endif // _SFX_SRCHDLG_HRC_
+
diff --git a/sfx2/source/dialog/srchdlg.src b/sfx2/source/dialog/srchdlg.src
new file mode 100644
index 000000000000..d1cee69e9157
--- /dev/null
+++ b/sfx2/source/dialog/srchdlg.src
@@ -0,0 +1,116 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_SRCHDLG_HRC_
+#include "srchdlg.hrc"
+#endif
+#ifndef _SFX_DIALOG_HRC
+#include "dialog.hrc"
+#endif
+#ifndef _SFX_HELPID_HRC
+#include "helpid.hrc"
+#endif
+
+ModelessDialog RID_DLG_SEARCH
+{
+ HelpId = HID_SEARCHDIALOG;
+ OutputSize = TRUE;
+ Moveable = TRUE;
+ Closeable = TRUE;
+ Hide = TRUE;
+ Size = MAP_APPFONT( 218, 84 );
+ Text [ en-US ] = "Find on this Page";
+ FixedText FT_SEARCH
+ {
+ Pos = MAP_APPFONT( 6, 3 );
+ Size = MAP_APPFONT( 150, 8 );
+ Text [ en-US ] = "~Search for";
+ };
+ ComboBox ED_SEARCH
+ {
+ HelpID = "sfx2:ComboBox:RID_DLG_SEARCH:ED_SEARCH";
+ Border = TRUE;
+ Pos = MAP_APPFONT( 6, 14 );
+ Size = MAP_APPFONT( 150, 50 );
+ DropDown = TRUE ;
+ TabStop = TRUE;
+ };
+ CheckBox CB_WHOLEWORDS
+ {
+ HelpID = "sfx2:CheckBox:RID_DLG_SEARCH:CB_WHOLEWORDS";
+ Pos = MAP_APPFONT( 6, 29 );
+ Size = MAP_APPFONT( 150, 10 );
+ Text [ en-US ] = "~Whole words only" ;
+ TabStop = TRUE;
+ };
+ CheckBox CB_MATCHCASE
+ {
+ HelpID = "sfx2:CheckBox:RID_DLG_SEARCH:CB_MATCHCASE";
+ Pos = MAP_APPFONT( 6, 42 );
+ Size = MAP_APPFONT( 150, 10 );
+ Text[ en-US ] = "~Match case";
+ TabStop = TRUE;
+ };
+ CheckBox CB_WRAPAROUND
+ {
+ HelpID = "sfx2:CheckBox:RID_DLG_SEARCH:CB_WRAPAROUND";
+ Pos = MAP_APPFONT( 6, 55 );
+ Size = MAP_APPFONT( 150, 10 );
+ Text [ en-US ] = "Wrap ~around" ;
+ TabStop = TRUE;
+ };
+ CheckBox CB_BACKWARDS
+ {
+ HelpID = "sfx2:CheckBox:RID_DLG_SEARCH:CB_BACKWARDS";
+ Pos = MAP_APPFONT( 6, 68 );
+ Size = MAP_APPFONT( 150, 10 );
+ Text [ en-US ] = "~Backwards" ;
+ TabStop = TRUE;
+ };
+ PushButton PB_FIND
+ {
+ HelpID = "sfx2:PushButton:RID_DLG_SEARCH:PB_FIND";
+ Pos = MAP_APPFONT( 162, 6 );
+ Size = MAP_APPFONT( 50, 14 );
+ Text [ en-US ] = "~Find" ;
+ TabStop = TRUE;
+ DefButton = TRUE ;
+ };
+ CancelButton PB_CANCELFIND
+ {
+ Pos = MAP_APPFONT( 162, 23 );
+ Size = MAP_APPFONT( 50, 14 );
+ Text [ en-US ] = "~Close" ;
+ TabStop = TRUE;
+ };
+
+ String STR_TOGGLE
+ {
+ Text [ en-US ] = "Wrap ~around" ;
+ };
+};
+
diff --git a/sfx2/source/dialog/styfitem.cxx b/sfx2/source/dialog/styfitem.cxx
new file mode 100644
index 000000000000..a33677c6b2ae
--- /dev/null
+++ b/sfx2/source/dialog/styfitem.cxx
@@ -0,0 +1,187 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// INCLUDE ---------------------------------------------------------------
+
+#ifndef GCC
+#endif
+
+#include <sfx2/styfitem.hxx>
+#include <svtools/localresaccess.hxx>
+#include <tools/debug.hxx>
+
+// -----------------------------------------------------------------------
+
+class SfxStyleFamilyItem_Impl
+{
+ Bitmap aBitmap;
+ Image aImage;
+};
+
+// -----------------------------------------------------------------------
+
+// Implementierung des Resource-Konstruktors
+
+SfxStyleFamilyItem::SfxStyleFamilyItem( const ResId &rResId ) :
+
+ Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILY_ITEM ) )
+
+{
+ ULONG nMask = ReadLongRes();
+
+ if(nMask & RSC_SFX_STYLE_ITEM_LIST)
+ {
+ ULONG nCount = ReadLongRes();
+ for( ULONG i = 0; i < nCount; i++ )
+ {
+ SfxFilterTupel *pTupel = new SfxFilterTupel;
+ pTupel->aName = ReadStringRes();
+ long lFlags = ReadLongRes();
+ pTupel->nFlags = (USHORT)lFlags;
+ aFilterList.Insert(pTupel, LIST_APPEND);
+ }
+ }
+ if(nMask & RSC_SFX_STYLE_ITEM_BITMAP)
+ {
+ aBitmap = Bitmap(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
+ IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
+ }
+ if(nMask & RSC_SFX_STYLE_ITEM_TEXT)
+ {
+ aText = ReadStringRes();
+ }
+ if(nMask & RSC_SFX_STYLE_ITEM_HELPTEXT)
+ {
+ aHelpText = ReadStringRes();
+ }
+ if(nMask & RSC_SFX_STYLE_ITEM_STYLEFAMILY)
+ {
+ nFamily = (USHORT)ReadLongRes();
+ }
+ else
+ nFamily = SFX_STYLE_FAMILY_PARA;
+ if(nMask & RSC_SFX_STYLE_ITEM_IMAGE)
+ {
+ aImage = Image(ResId((RSHEADER_TYPE *)GetClassRes(),*rResId.GetResMgr()));
+ IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
+ }
+ else
+ aImage = Image(aBitmap);
+}
+
+// -----------------------------------------------------------------------
+
+// Destruktor; gibt interne Daten frei
+
+SfxStyleFamilyItem::~SfxStyleFamilyItem()
+{
+ SfxFilterTupel *pTupel = aFilterList.First();
+ while(pTupel)
+ {
+ delete pTupel;
+ pTupel = aFilterList.Next();
+ }
+}
+
+// -----------------------------------------------------------------------
+
+// Implementierung des Resource-Konstruktors
+
+SfxStyleFamilies::SfxStyleFamilies( const ResId& rResId ) :
+
+ Resource( rResId.SetRT( RSC_SFX_STYLE_FAMILIES ).SetAutoRelease( FALSE ) ),
+ aEntryList( 4, 1 )
+{
+ ULONG nCount = ReadLongRes();
+ for( ULONG i = 0; i < nCount; i++ )
+ {
+ const ResId aResId((RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr());
+ SfxStyleFamilyItem *pItem = new SfxStyleFamilyItem(aResId);
+ IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
+ aEntryList.Insert(pItem, LIST_APPEND);
+ }
+
+ FreeResource();
+
+ updateImages( rResId, BMP_COLOR_NORMAL );
+}
+
+// -----------------------------------------------------------------------
+
+// Destruktor; gibt interne Daten frei
+
+SfxStyleFamilies::~SfxStyleFamilies()
+{
+ SfxStyleFamilyItem *pItem = aEntryList.First();
+
+ while(pItem)
+ {
+ delete pItem;
+ pItem = aEntryList.Next();
+ }
+}
+
+
+// -----------------------------------------------------------------------
+
+sal_Bool SfxStyleFamilies::updateImages( const ResId& _rId, const BmpColorMode _eMode )
+{
+ sal_Bool bSuccess = sal_False;
+
+ {
+ ::svt::OLocalResourceAccess aLocalRes( _rId );
+
+ // check if the image list is present
+ ResId aImageListId( (sal_uInt16)_eMode + 1, *_rId.GetResMgr() );
+ aImageListId.SetRT( RSC_IMAGELIST );
+
+ if ( aLocalRes.IsAvailableRes( aImageListId ) )
+ { // there is such a list
+ ImageList aImages( aImageListId );
+
+ // number of styles items/images
+ sal_uInt16 nCount = aImages.GetImageCount( );
+ DBG_ASSERT( Count() == nCount, "SfxStyleFamilies::updateImages: found the image list, but missing some bitmaps!" );
+ if ( nCount > Count() )
+ nCount = Count();
+
+ // set the images on the items
+ for ( sal_uInt16 i = 0; i < nCount; ++i )
+ {
+ SfxStyleFamilyItem* pItem = static_cast< SfxStyleFamilyItem* >( aEntryList.GetObject( i ) );
+ pItem->SetImage( aImages.GetImage( aImages.GetImageId( i ) ) );
+ }
+
+ bSuccess = sal_True;
+ }
+ }
+
+ return bSuccess;
+}
diff --git a/sfx2/source/dialog/styledlg.cxx b/sfx2/source/dialog/styledlg.cxx
new file mode 100644
index 000000000000..e1d01de94955
--- /dev/null
+++ b/sfx2/source/dialog/styledlg.cxx
@@ -0,0 +1,176 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// include ---------------------------------------------------------------
+#include <svl/whiter.hxx>
+#include <svl/style.hxx>
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#ifndef GCC
+#endif
+
+#include <sfx2/styledlg.hxx>
+#include <sfx2/mgetempl.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/sfxuno.hxx>
+
+#include "dialog.hrc"
+
+// class SfxStyleDialog --------------------------------------------------
+
+SfxStyleDialog::SfxStyleDialog
+(
+ Window* pParent, // Parent
+ const ResId& rResId, // ResId
+ SfxStyleSheetBase& rStyle, // zu bearbeitendes StyleSheet
+ BOOL bFreeRes, // Flag Resourcen freigeben
+ const String* pUserBtnTxt
+) :
+
+/* [Beschreibung]
+
+ Konstruktor: Verwalten-TabPage zuf"ugen, ExampleSet vom Style setzen.
+*/
+
+ SfxTabDialog( pParent, rResId,
+ rStyle.GetItemSet().Clone(),
+ // auch ohne ParentSupport TRUE "ubergeben, aber erweitert
+ // um den StandardButton zu unterdr"ucken
+ rStyle.HasParentSupport() ? TRUE : 2,
+ pUserBtnTxt ),
+
+ pStyle( &rStyle )
+
+{
+ AddTabPage( ID_TABPAGE_MANAGESTYLES,
+ String( SfxResId( STR_TABPAGE_MANAGESTYLES ) ),
+ SfxManageStyleSheetPage::Create, 0, FALSE, 0 );
+
+ // bei neuer Vorlage immer die Verwaltungsseite als aktuelle
+ // Seite setzen
+
+ if( !rStyle.GetName().Len() )
+ SetCurPageId( ID_TABPAGE_MANAGESTYLES );
+ else
+ {
+ String sTxt( GetText() );
+ sTxt += DEFINE_CONST_UNICODE(": ") ;
+ sTxt += rStyle.GetName();
+ SetText( sTxt );
+ }
+ delete pExampleSet; // im SfxTabDialog::Ctor() schon angelegt
+ pExampleSet = &pStyle->GetItemSet();
+
+ if ( bFreeRes )
+ FreeResource();
+ GetCancelButton().SetClickHdl( LINK(this, SfxStyleDialog, CancelHdl) );
+}
+
+// -----------------------------------------------------------------------
+
+SfxStyleDialog::~SfxStyleDialog()
+
+/* [Beschreibung]
+
+ Destruktor: ExampleSet auf NULL setzen, damit der SfxTabDialog nicht den
+ Set vom Style l"oscht.
+*/
+
+{
+ pExampleSet = 0;
+ pStyle = 0;
+ delete GetInputSetImpl();
+}
+
+// -----------------------------------------------------------------------
+
+const SfxItemSet* SfxStyleDialog::GetRefreshedSet()
+
+/* [Beschreibung]
+
+ Diese wird gerufen, wenn <SfxTabPage::DeactivatePage(SfxItemSet *)>
+ <SfxTabPage::REFRESH_SET> liefert.
+*/
+
+{
+ return GetInputSetImpl();
+}
+
+// -----------------------------------------------------------------------
+
+short SfxStyleDialog::Ok()
+
+/* [Beschreibung]
+
+ "Uberladen, damit immer RET_OK zur"uckgegeben wird.
+*/
+
+{
+ SfxTabDialog::Ok();
+ return RET_OK;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxStyleDialog, CancelHdl, Button *, pButton )
+
+/* [Beschreibung]
+
+ Wenn der Dialog abgebrochen wurde, m"ussen alle schon eingestellten
+ Attribute wieder zur"uckgesetzt werden.
+*/
+
+{
+ (void)pButton; //unused
+ SfxTabPage* pPage = GetTabPage( ID_TABPAGE_MANAGESTYLES );
+
+ const SfxItemSet* pInSet = GetInputSetImpl();
+ SfxWhichIter aIter( *pInSet );
+ USHORT nWhich = aIter.FirstWhich();
+
+ while ( nWhich )
+ {
+ SfxItemState eState = pInSet->GetItemState( nWhich, FALSE );
+
+ if ( SFX_ITEM_DEFAULT == eState )
+ pExampleSet->ClearItem( nWhich );
+ else
+ pExampleSet->Put( pInSet->Get( nWhich ) );
+ nWhich = aIter.NextWhich();
+ }
+
+ if ( pPage )
+ pPage->Reset( *GetInputSetImpl() );
+ EndDialog( RET_CANCEL );
+ return 0;
+}
+
+
diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx
new file mode 100644
index 000000000000..d149bea792dc
--- /dev/null
+++ b/sfx2/source/dialog/tabdlg.cxx
@@ -0,0 +1,1798 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <limits.h>
+#include <stdlib.h>
+#include <vcl/msgbox.hxx>
+#include <unotools/viewoptions.hxx>
+
+#define _SVSTDARR_USHORTS
+#include <svl/svstdarr.hxx>
+
+#include "appdata.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/minarray.hxx>
+#include <sfx2/tabdlg.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/app.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "sfx2/sfxhelp.hxx"
+#include <sfx2/ctrlitem.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/sfxdlg.hxx>
+#include <sfx2/itemconnect.hxx>
+
+#include "dialog.hrc"
+#include "helpid.hrc"
+
+#if ENABLE_LAYOUT_SFX_TABDIALOG
+#undef TabPage
+#undef SfxTabPage
+#define SfxTabPage ::SfxTabPage
+#undef SfxTabDialog
+#endif /* ENABLE_LAYOUT_SFX_TABDIALOG */
+
+using namespace ::com::sun::star::uno;
+using namespace ::rtl;
+
+#define USERITEM_NAME OUString::createFromAscii( "UserItem" )
+
+TYPEINIT1(LAYOUT_NS_SFX_TABDIALOG SfxTabDialogItem,SfxSetItem);
+
+struct TabPageImpl
+{
+ BOOL mbStandard;
+ sfx::ItemConnectionArray maItemConn;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame;
+
+ TabPageImpl() : mbStandard( FALSE ) {}
+};
+
+NAMESPACE_LAYOUT_SFX_TABDIALOG
+
+struct Data_Impl
+{
+ USHORT nId; // Die ID
+ CreateTabPage fnCreatePage; // Pointer auf die Factory
+ GetTabPageRanges fnGetRanges;// Pointer auf die Ranges-Funktion
+ SfxTabPage* pTabPage; // die TabPage selber
+ BOOL bOnDemand; // Flag: ItemSet onDemand
+ BOOL bRefresh; // Flag: Seite mu\s neu initialisiert werden
+
+ // Konstruktor
+ Data_Impl( USHORT Id, CreateTabPage fnPage,
+ GetTabPageRanges fnRanges, BOOL bDemand ) :
+
+ nId ( Id ),
+ fnCreatePage( fnPage ),
+ fnGetRanges ( fnRanges ),
+ pTabPage ( 0 ),
+ bOnDemand ( bDemand ),
+ bRefresh ( FALSE )
+ {
+ if ( !fnCreatePage )
+ {
+ SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
+ if ( pFact )
+ {
+ fnCreatePage = pFact->GetTabPageCreatorFunc( nId );
+ fnGetRanges = pFact->GetTabPageRangesFunc( nId );
+ }
+ }
+ }
+};
+
+SfxTabDialogItem::SfxTabDialogItem( const SfxTabDialogItem& rAttr, SfxItemPool* pItemPool )
+ : SfxSetItem( rAttr, pItemPool )
+{
+}
+
+SfxTabDialogItem::SfxTabDialogItem( USHORT nId, const SfxItemSet& rItemSet )
+ : SfxSetItem( nId, rItemSet )
+{
+}
+
+SfxPoolItem* __EXPORT SfxTabDialogItem::Clone(SfxItemPool* pToPool) const
+{
+ return new SfxTabDialogItem( *this, pToPool );
+}
+
+SfxPoolItem* __EXPORT SfxTabDialogItem::Create(SvStream& /*rStream*/, USHORT /*nVersion*/) const
+{
+ DBG_ERROR( "Use it only in UI!" );
+ return NULL;
+}
+
+class SfxTabDialogController : public SfxControllerItem
+{
+ SfxTabDialog* pDialog;
+ const SfxItemSet* pSet;
+public:
+ SfxTabDialogController( USHORT nSlotId, SfxBindings& rBindings, SfxTabDialog* pDlg )
+ : SfxControllerItem( nSlotId, rBindings )
+ , pDialog( pDlg )
+ , pSet( NULL )
+ {}
+
+ ~SfxTabDialogController();
+
+ DECL_LINK( Execute_Impl, void* );
+ virtual void StateChanged( USHORT nSID, SfxItemState eState, const SfxPoolItem* pState );
+};
+
+SfxTabDialogController::~SfxTabDialogController()
+{
+ delete pSet;
+}
+
+IMPL_LINK( SfxTabDialogController, Execute_Impl, void*, pVoid )
+{
+ (void)pVoid; //unused
+ if ( pDialog->OK_Impl() && pDialog->Ok() )
+ {
+ const SfxPoolItem* aItems[2];
+ SfxTabDialogItem aItem( GetId(), *pDialog->GetOutputItemSet() );
+ aItems[0] = &aItem;
+ aItems[1] = NULL;
+ GetBindings().Execute( GetId(), aItems );
+ }
+
+ return 0;
+}
+
+void SfxTabDialogController::StateChanged( USHORT /*nSID*/, SfxItemState /*eState*/, const SfxPoolItem* pState )
+{
+ const SfxSetItem* pSetItem = PTR_CAST( SfxSetItem, pState );
+ if ( pSetItem )
+ {
+ pSet = pDialog->pSet = pSetItem->GetItemSet().Clone();
+ BOOL bDialogStarted = FALSE;
+ for ( USHORT n=0; n<pDialog->aTabCtrl.GetPageCount(); n++ )
+ {
+ USHORT nPageId = pDialog->aTabCtrl.GetPageId( n );
+ SfxTabPage* pTabPage = dynamic_cast<SfxTabPage*> (pDialog->aTabCtrl.GetTabPage( nPageId ));
+ if ( pTabPage )
+ {
+ pTabPage->Reset( pSetItem->GetItemSet() );
+ bDialogStarted = TRUE;
+ }
+ }
+
+ if ( bDialogStarted )
+ pDialog->Show();
+ }
+ else
+ pDialog->Hide();
+}
+
+DECL_PTRARRAY(SfxTabDlgData_Impl, Data_Impl *, 4,4)
+
+struct TabDlg_Impl
+{
+ BOOL bModified : 1,
+ bModal : 1,
+ bInOK : 1,
+ bHideResetBtn : 1;
+ SfxTabDlgData_Impl* pData;
+
+ PushButton* pApplyButton;
+ SfxTabDialogController* pController;
+
+ TabDlg_Impl( BYTE nCnt ) :
+
+ bModified ( FALSE ),
+ bModal ( TRUE ),
+ bInOK ( FALSE ),
+ bHideResetBtn ( FALSE ),
+ pData ( new SfxTabDlgData_Impl( nCnt ) ),
+ pApplyButton ( NULL ),
+ pController ( NULL )
+ {}
+};
+
+Data_Impl* Find( SfxTabDlgData_Impl& rArr, USHORT nId, USHORT* pPos = 0 );
+
+Data_Impl* Find( SfxTabDlgData_Impl& rArr, USHORT nId, USHORT* pPos )
+{
+ const USHORT nCount = rArr.Count();
+
+ for ( USHORT i = 0; i < nCount; ++i )
+ {
+ Data_Impl* pObj = rArr[i];
+
+ if ( pObj->nId == nId )
+ {
+ if ( pPos )
+ *pPos = i;
+ return pObj;
+ }
+ }
+ return 0;
+}
+
+#if !ENABLE_LAYOUT_SFX_TABDIALOG
+
+void SfxTabPage::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
+{
+ if (pImpl)
+ pImpl->mxFrame = xFrame;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SfxTabPage::GetFrame()
+{
+ if (pImpl)
+ return pImpl->mxFrame;
+ return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >();
+}
+
+SfxTabPage::SfxTabPage( Window *pParent,
+ const ResId &rResId, const SfxItemSet &rAttrSet ) :
+
+/* [Beschreibung]
+
+ Konstruktor
+*/
+
+ TabPage( pParent, rResId ),
+
+ pSet ( &rAttrSet ),
+ bHasExchangeSupport ( FALSE ),
+ pTabDlg ( NULL ),
+ pImpl ( new TabPageImpl )
+
+{
+}
+// -----------------------------------------------------------------------
+SfxTabPage:: SfxTabPage( Window *pParent, WinBits nStyle, const SfxItemSet &rAttrSet ) :
+ TabPage(pParent, nStyle),
+ pSet ( &rAttrSet ),
+ bHasExchangeSupport ( FALSE ),
+ pTabDlg ( NULL ),
+ pImpl ( new TabPageImpl )
+{
+}
+// -----------------------------------------------------------------------
+
+SfxTabPage::~SfxTabPage()
+
+/* [Beschreibung]
+
+ Destruktor
+*/
+
+{
+#if !ENABLE_LAYOUT
+ delete pImpl;
+#endif /* ENABLE_LAYOUT */
+}
+
+// -----------------------------------------------------------------------
+
+BOOL SfxTabPage::FillItemSet( SfxItemSet& rSet )
+{
+ return pImpl->maItemConn.DoFillItemSet( rSet, GetItemSet() );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabPage::Reset( const SfxItemSet& rSet )
+{
+ pImpl->maItemConn.DoApplyFlags( rSet );
+ pImpl->maItemConn.DoReset( rSet );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabPage::ActivatePage( const SfxItemSet& )
+
+/* [Beschreibung]
+
+ Defaultimplementierung der virtuellen ActivatePage-Methode
+ Diese wird gerufen, wenn eine Seite des Dialogs den Datenaustausch
+ zwischen Pages unterst"utzt.
+
+ <SfxTabPage::DeactivatePage(SfxItemSet *)>
+*/
+
+{
+}
+
+// -----------------------------------------------------------------------
+
+int SfxTabPage::DeactivatePage( SfxItemSet* )
+
+/* [Beschreibung]
+
+ Defaultimplementierung der virtuellen DeactivatePage-Methode
+ Diese wird vor dem Verlassen einer Seite durch den Sfx gerufen;
+ die Anwendung kann "uber den Returnwert steuern,
+ ob die Seite verlassen werden soll.
+ Falls die Seite "uber bHasExchangeSupport
+ anzeigt, da\s sie einen Datenaustausch zwischen Seiten
+ unterst"utzt, wird ein Pointer auf das Austausch-Set als
+ Parameter "ubergeben. Dieser nimmt die Daten f"ur den Austausch
+ entgegen; das Set steht anschlie\send als Parameter in
+ <SfxTabPage::ActivatePage(const SfxItemSet &)> zur Verf"ugung.
+
+ [R"uckgabewert]
+
+ LEAVE_PAGE; Verlassen der Seite erlauben
+*/
+
+{
+ return LEAVE_PAGE;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabPage::FillUserData()
+
+/* [Beschreibung]
+
+ virtuelle Methode, wird von der Basisklasse im Destruktor gerufen
+ um spezielle Informationen der TabPage in der Ini-Datei zu speichern.
+ Beim "Uberladen muss ein String zusammengestellt werden, der mit
+ <SetUserData()> dann weggeschrieben wird.
+*/
+
+{
+}
+
+// -----------------------------------------------------------------------
+
+BOOL SfxTabPage::IsReadOnly() const
+
+/* [Description]
+
+*/
+
+{
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------
+
+const SfxPoolItem* SfxTabPage::GetItem( const SfxItemSet& rSet, USHORT nSlot, sal_Bool bDeep )
+
+/* [Beschreibung]
+
+ static Methode: hiermit wird der Code der TabPage-Implementierungen
+ vereinfacht.
+
+*/
+
+{
+ const SfxItemPool* pPool = rSet.GetPool();
+ USHORT nWh = pPool->GetWhich( nSlot, bDeep );
+ const SfxPoolItem* pItem = 0;
+#ifdef DEBUG
+ SfxItemState eState;
+ eState =
+#endif
+ rSet.GetItemState( nWh, TRUE, &pItem ); // -Wall required??
+
+ if ( !pItem && nWh != nSlot )
+ pItem = &pPool->GetDefaultItem( nWh );
+ return pItem;
+}
+
+// -----------------------------------------------------------------------
+
+const SfxPoolItem* SfxTabPage::GetOldItem( const SfxItemSet& rSet,
+ USHORT nSlot, sal_Bool bDeep )
+
+/* [Beschreibung]
+
+ Diese Methode gibt f"ur Vergleiche den alten Wert eines
+ Attributs zur"uck.
+*/
+
+{
+ const SfxItemSet& rOldSet = GetItemSet();
+ USHORT nWh = GetWhich( nSlot, bDeep );
+ const SfxPoolItem* pItem = 0;
+
+ if ( pImpl->mbStandard && rOldSet.GetParent() )
+ pItem = GetItem( *rOldSet.GetParent(), nSlot );
+ else if ( rSet.GetParent() &&
+ SFX_ITEM_DONTCARE == rSet.GetItemState( nWh ) )
+ pItem = GetItem( *rSet.GetParent(), nSlot );
+ else
+ pItem = GetItem( rOldSet, nSlot );
+ return pItem;
+}
+
+// -----------------------------------------------------------------------
+
+const SfxPoolItem* SfxTabPage::GetExchangeItem( const SfxItemSet& rSet,
+ USHORT nSlot )
+
+/* [Beschreibung]
+
+ Diese Methode gibt f"ur Vergleiche den alten Wert eines
+ Attributs zur"uck. Dabei wird ber"ucksichtigt, ob der Dialog
+ gerade mit OK beendet wurde.
+*/
+
+{
+ if ( pTabDlg && !pTabDlg->IsInOK() && pTabDlg->GetExampleSet() )
+ return GetItem( *pTabDlg->GetExampleSet(), nSlot );
+ else
+ return GetOldItem( rSet, nSlot );
+}
+
+// add CHINA001 begin
+void SfxTabPage::PageCreated( SfxAllItemSet /*aSet*/ )
+{
+ DBG_ASSERT(0, "SfxTabPage::PageCreated should not be called");
+}//CHINA001
+// add CHINA001 end
+
+// -----------------------------------------------------------------------
+
+void SfxTabPage::AddItemConnection( sfx::ItemConnectionBase* pConnection )
+{
+ pImpl->maItemConn.AddConnection( pConnection );
+}
+
+#endif /* !ENABLE_LAYOUT_SFX_TABDIALOG */
+
+#if ENABLE_LAYOUT_SFX_TABDIALOG
+#undef ResId
+#define ResId(id, foo) #id
+#undef TabDialog
+#define TabDialog(parent, res_id) Dialog (parent, "tab-dialog.xml", "tab-dialog")
+
+#define aOKBtn(this) aOKBtn (this, "BTN_OK")
+#undef PushButton
+#define PushButton(this) layout::PushButton (this, "BTN_USER")
+#define aCancelBtn(this) aCancelBtn (this, "BTN_CANCEL")
+#define aHelpBtn(this) aHelpBtn (this, "BTN_HELP")
+#define aResetBtn(this) aResetBtn (this, "BTN_RESET")
+#define aBaseFmtBtn(this) aBaseFmtBtn (this, "BTN_BASEFMT")
+#endif /* ENABLE_LAYOUT_SFX_TABDIALOG */
+
+#define INI_LIST(ItemSetPtr) \
+ aTabCtrl ( this, ResId(ID_TABCONTROL,*rResId.GetResMgr() ) ),\
+ aOKBtn ( this ),\
+ pUserBtn ( pUserButtonText? new PushButton(this): 0 ),\
+ aCancelBtn ( this ),\
+ aHelpBtn ( this ),\
+ aResetBtn ( this ),\
+ aBaseFmtBtn ( this ),\
+ pSet ( ItemSetPtr ),\
+ pOutSet ( 0 ),\
+ pImpl ( new TabDlg_Impl( (BYTE)aTabCtrl.GetPageCount() ) ), \
+ pRanges ( 0 ), \
+ nResId ( rResId.GetId() ), \
+ nAppPageId ( USHRT_MAX ), \
+ bItemsReset ( FALSE ),\
+ bFmt ( bEditFmt ),\
+ pExampleSet ( 0 )
+
+// -----------------------------------------------------------------------
+
+SfxTabDialog::SfxTabDialog
+
+/* [Beschreibung]
+
+ Konstruktor
+*/
+
+(
+ SfxViewFrame* pViewFrame, // Frame, zu dem der Dialog geh"ort
+ Window* pParent, // Parent-Fenster
+ const ResId& rResId, // ResourceId
+ const SfxItemSet* pItemSet, // Itemset mit den Daten;
+ // kann NULL sein, wenn Pages onDemand
+ BOOL bEditFmt, // Flag: es werden Vorlagen bearbeitet
+ // wenn ja -> zus"atzlicher Button f"ur Standard
+ const String* pUserButtonText // Text fuer BenutzerButton;
+ // wenn != 0, wird der UserButton erzeugt
+) :
+ TabDialog( pParent, rResId ),
+ pFrame( pViewFrame ),
+ INI_LIST(pItemSet)
+{
+ Init_Impl( bFmt, pUserButtonText );
+}
+
+// -----------------------------------------------------------------------
+
+SfxTabDialog::SfxTabDialog
+
+/* [Beschreibung]
+
+ Konstruktor, tempor"ar ohne Frame
+*/
+
+(
+ Window* pParent, // Parent-Fenster
+ const ResId& rResId, // ResourceId
+ const SfxItemSet* pItemSet, // Itemset mit den Daten; kann NULL sein,
+ // wenn Pages onDemand
+ BOOL bEditFmt, // Flag: es werden Vorlagen bearbeitet
+ // wenn ja -> zus"atzlicher Button f"ur Standard
+ const String* pUserButtonText // Text f"ur BenutzerButton;
+ // wenn != 0, wird der UserButton erzeugt
+) :
+ TabDialog( pParent, rResId ),
+ pFrame( 0 ),
+ INI_LIST(pItemSet)
+{
+ Init_Impl( bFmt, pUserButtonText );
+ DBG_WARNING( "bitte den Ctor mit ViewFrame verwenden" );
+}
+
+SfxTabDialog::SfxTabDialog
+
+/* [Beschreibung]
+
+ Konstruktor, tempor"ar ohne Frame
+*/
+
+(
+ Window* pParent, // Parent-Fenster
+ const ResId& rResId, // ResourceId
+ USHORT nSetId,
+ SfxBindings& rBindings,
+ BOOL bEditFmt, // Flag: es werden Vorlagen bearbeitet
+ // wenn ja -> zus"atzlicher Button f"ur Standard
+ const String* pUserButtonText // Text f"ur BenutzerButton;
+ // wenn != 0, wird der UserButton erzeugt
+) :
+ TabDialog( pParent, rResId ),
+ pFrame( 0 ),
+ INI_LIST(NULL)
+{
+ rBindings.ENTERREGISTRATIONS();
+ pImpl->pController = new SfxTabDialogController( nSetId, rBindings, this );
+ rBindings.LEAVEREGISTRATIONS();
+
+ EnableApplyButton( TRUE );
+ SetApplyHandler( LINK( pImpl->pController, SfxTabDialogController, Execute_Impl ) );
+
+ rBindings.Invalidate( nSetId );
+ rBindings.Update( nSetId );
+ DBG_ASSERT( pSet, "No ItemSet!" );
+
+ Init_Impl( bFmt, pUserButtonText );
+}
+
+// -----------------------------------------------------------------------
+
+#if ENABLE_LAYOUT_SFX_TABDIALOG
+#undef ResId
+#undef TabDialog
+#undef aOKBtn
+#undef PushButton
+#undef aCancelBtn
+#undef aHelpBtn
+#undef aResetBtn
+#undef aBaseFmtBtn
+#endif /* ENABLE_LAYOUT_SFX_TABDIALOG */
+
+SfxTabDialog::~SfxTabDialog()
+{
+ // save settings (screen position and current page)
+ SvtViewOptions aDlgOpt( E_TABDIALOG, String::CreateFromInt32( nResId ) );
+#if !ENABLE_LAYOUT_SFX_TABDIALOG
+ aDlgOpt.SetWindowState( OUString::createFromAscii( GetWindowState( WINDOWSTATE_MASK_POS ).GetBuffer() ) );
+#endif /* !ENABLE_LAYOUT_SFX_TABDIALOG */
+ aDlgOpt.SetPageID( aTabCtrl.GetCurPageId() );
+
+ const USHORT nCount = pImpl->pData->Count();
+ for ( USHORT i = 0; i < nCount; ++i )
+ {
+ Data_Impl* pDataObject = pImpl->pData->GetObject(i);
+
+ if ( pDataObject->pTabPage )
+ {
+ // save settings of all pages (user data)
+ pDataObject->pTabPage->FillUserData();
+ String aPageData( pDataObject->pTabPage->GetUserData() );
+ if ( aPageData.Len() )
+ {
+ // save settings of all pages (user data)
+ SvtViewOptions aPageOpt( E_TABPAGE, String::CreateFromInt32( pDataObject->nId ) );
+ aPageOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aPageData ) ) );
+ }
+
+ if ( pDataObject->bOnDemand )
+ delete (SfxItemSet*)&pDataObject->pTabPage->GetItemSet();
+ delete pDataObject->pTabPage;
+ }
+ delete pDataObject;
+ }
+
+ delete pImpl->pController;
+ delete pImpl->pApplyButton;
+ delete pImpl->pData;
+ delete pImpl;
+ delete pUserBtn;
+ delete pOutSet;
+ delete pExampleSet;
+ delete [] pRanges;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::Init_Impl( BOOL bFmtFlag, const String* pUserButtonText )
+
+/* [Beschreibung]
+
+ interne Initialisierung des Dialogs
+*/
+
+{
+ aOKBtn.SetClickHdl( LINK( this, SfxTabDialog, OkHdl ) );
+ aResetBtn.SetClickHdl( LINK( this, SfxTabDialog, ResetHdl ) );
+ aResetBtn.SetText( String( SfxResId( STR_RESET ) ) );
+ aTabCtrl.SetActivatePageHdl(
+ LINK( this, SfxTabDialog, ActivatePageHdl ) );
+ aTabCtrl.SetDeactivatePageHdl(
+ LINK( this, SfxTabDialog, DeactivatePageHdl ) );
+ aTabCtrl.Show();
+ aOKBtn.Show();
+ aCancelBtn.Show();
+ aHelpBtn.Show();
+ aResetBtn.Show();
+ aResetBtn.SetHelpId( HID_TABDLG_RESET_BTN );
+
+ if ( pUserBtn )
+ {
+ pUserBtn->SetText( *pUserButtonText );
+ pUserBtn->SetClickHdl( LINK( this, SfxTabDialog, UserHdl ) );
+ pUserBtn->Show();
+ }
+
+ /* TODO: Check what is up with bFmt/bFmtFlag. Comment below suggests a
+ different behavior than implemented!! */
+ if ( bFmtFlag )
+ {
+ String aStd( SfxResId( STR_STANDARD_SHORTCUT ) );
+ aBaseFmtBtn.SetText( aStd );
+ aBaseFmtBtn.SetClickHdl( LINK( this, SfxTabDialog, BaseFmtHdl ) );
+ aBaseFmtBtn.SetHelpId( HID_TABDLG_STANDARD_BTN );
+
+ // bFmt = tempor"ares Flag im Ctor() "ubergeben,
+ // wenn bFmt == 2, dann auch TRUE,
+ // zus"atzlich Ausblendung vom StandardButton,
+ // nach der Initialisierung wieder auf TRUE setzen
+ if ( bFmtFlag != 2 )
+ aBaseFmtBtn.Show();
+ else
+ bFmtFlag = TRUE;
+ }
+
+ if ( pSet )
+ {
+ pExampleSet = new SfxItemSet( *pSet );
+ pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::RemoveResetButton()
+{
+ aResetBtn.Hide();
+ pImpl->bHideResetBtn = TRUE;
+}
+
+// -----------------------------------------------------------------------
+
+#if ENABLE_LAYOUT_SFX_TABDIALOG
+#undef TabDialog
+#define TabDialog Dialog
+#endif /* ENABLE_LAYOUT_SFX_TABDIALOG */
+
+short SfxTabDialog::Execute()
+{
+ if ( !aTabCtrl.GetPageCount() )
+ return RET_CANCEL;
+ Start_Impl();
+ return TabDialog::Execute();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::StartExecuteModal( const Link& rEndDialogHdl )
+{
+#if !ENABLE_LAYOUT_SFX_TABDIALOG
+ if ( !aTabCtrl.GetPageCount() )
+ return;
+ Start_Impl();
+ TabDialog::StartExecuteModal( rEndDialogHdl );
+#else
+ rEndDialogHdl.IsSet();
+#endif /* !ENABLE_LAYOUT_SFX_TABDIALOG */
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::Start( BOOL bShow )
+{
+ aCancelBtn.SetClickHdl( LINK( this, SfxTabDialog, CancelHdl ) );
+ pImpl->bModal = FALSE;
+ Start_Impl();
+
+ if ( bShow )
+ Show();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::SetApplyHandler(const Link& _rHdl)
+{
+ DBG_ASSERT( pImpl->pApplyButton, "SfxTabDialog::GetApplyHandler: no apply button enabled!" );
+ if ( pImpl->pApplyButton )
+ pImpl->pApplyButton->SetClickHdl( _rHdl );
+}
+
+// -----------------------------------------------------------------------
+
+Link SfxTabDialog::GetApplyHandler() const
+{
+ DBG_ASSERT( pImpl->pApplyButton, "SfxTabDialog::GetApplyHandler: no button enabled!" );
+ if ( !pImpl->pApplyButton )
+ return Link();
+
+ return pImpl->pApplyButton->GetClickHdl();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::EnableApplyButton(BOOL bEnable)
+{
+ if ( IsApplyButtonEnabled() == bEnable )
+ // nothing to do
+ return;
+
+ // create or remove the apply button
+ if ( bEnable )
+ {
+ pImpl->pApplyButton = new PushButton( this );
+#if !ENABLE_LAYOUT_SFX_TABDIALOG
+ // in the z-order, the apply button should be behind the ok button, thus appearing at the right side of it
+ pImpl->pApplyButton->SetZOrder(&aOKBtn, WINDOW_ZORDER_BEHIND);
+#endif /* ENABLE_LAYOUT_SFX_TABDIALOG */
+ pImpl->pApplyButton->SetText( String( SfxResId( STR_APPLY ) ) );
+ pImpl->pApplyButton->Show();
+
+ pImpl->pApplyButton->SetHelpId( HID_TABDLG_APPLY_BTN );
+ }
+ else
+ {
+ delete pImpl->pApplyButton;
+ pImpl->pApplyButton = NULL;
+ }
+
+#if !ENABLE_LAYOUT_SFX_TABDIALOG
+ // adjust the layout
+ if (IsReallyShown())
+ AdjustLayout();
+#endif /* !ENABLE_LAYOUT_SFX_TABDIALOG */
+}
+
+// -----------------------------------------------------------------------
+
+BOOL SfxTabDialog::IsApplyButtonEnabled() const
+{
+ return ( NULL != pImpl->pApplyButton );
+}
+
+// -----------------------------------------------------------------------
+
+const PushButton* SfxTabDialog::GetApplyButton() const
+{
+ return pImpl->pApplyButton;
+}
+
+// -----------------------------------------------------------------------
+
+PushButton* SfxTabDialog::GetApplyButton()
+{
+ return pImpl->pApplyButton;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::Start_Impl()
+{
+ DBG_ASSERT( pImpl->pData->Count() == aTabCtrl.GetPageCount(), "not all pages registered" );
+ USHORT nActPage = aTabCtrl.GetPageId( 0 );
+
+ // load old settings, when exists
+ SvtViewOptions aDlgOpt( E_TABDIALOG, String::CreateFromInt32( nResId ) );
+ if ( aDlgOpt.Exists() )
+ {
+#if !ENABLE_LAYOUT_SFX_TABDIALOG
+ SetWindowState( ByteString( aDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US ) );
+#endif /* !ENABLE_LAYOUT_SFX_TABDIALOG */
+
+ // initiale TabPage aus Programm/Hilfe/Konfig
+ nActPage = (USHORT)aDlgOpt.GetPageID();
+
+ if ( USHRT_MAX != nAppPageId )
+ nActPage = nAppPageId;
+ else
+ {
+ USHORT nAutoTabPageId = SFX_APP()->Get_Impl()->nAutoTabPageId;
+ if ( nAutoTabPageId )
+ nActPage = nAutoTabPageId;
+ }
+
+ if ( TAB_PAGE_NOTFOUND == aTabCtrl.GetPagePos( nActPage ) )
+ nActPage = aTabCtrl.GetPageId( 0 );
+ }
+ else if ( USHRT_MAX != nAppPageId && TAB_PAGE_NOTFOUND != aTabCtrl.GetPagePos( nAppPageId ) )
+ nActPage = nAppPageId;
+
+ aTabCtrl.SetCurPageId( nActPage );
+ ActivatePageHdl( &aTabCtrl );
+}
+
+void SfxTabDialog::AddTabPage( USHORT nId, BOOL bItemsOnDemand )
+{
+ AddTabPage( nId, 0, 0, bItemsOnDemand );
+}
+
+void SfxTabDialog::AddTabPage( USHORT nId, const String &rRiderText, BOOL bItemsOnDemand, USHORT nPos )
+{
+ AddTabPage( nId, rRiderText, 0, 0, bItemsOnDemand, nPos );
+}
+
+#ifdef SV_HAS_RIDERBITMAPS
+
+void SfxTabDialog::AddTabPage( USHORT nId, const Bitmap &rRiderBitmap, BOOL bItemsOnDemand, USHORT nPos )
+{
+ AddTabPage( nId, rRiderBitmap, 0, 0, bItemsOnDemand, nPos );
+}
+
+#endif
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::AddTabPage
+
+/* [Beschreibung]
+
+ Hinzuf"ugen einer Seite zu dem Dialog.
+ Mu\s korrespondieren zu einem entsprechende Eintrag im
+ TabControl in der Resource des Dialogs.
+*/
+
+(
+ USHORT nId, // ID der Seite
+ CreateTabPage pCreateFunc, // Pointer auf die Factory-Methode
+ GetTabPageRanges pRangesFunc, // Pointer auf die Methode f"ur das
+ // Erfragen der Ranges onDemand
+ BOOL bItemsOnDemand // gibt an, ob das Set dieser Seite beim
+ // Erzeugen der Seite erfragt wird
+)
+{
+ pImpl->pData->Append(
+ new Data_Impl( nId, pCreateFunc, pRangesFunc, bItemsOnDemand ) );
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::AddTabPage
+
+/* [Beschreibung]
+
+ Hinzuf"ugen einer Seite zu dem Dialog.
+ Der Ridertext wird "ubergeben, die Seite hat keine Entsprechung im
+ TabControl in der Resource des Dialogs.
+*/
+
+(
+ USHORT nId,
+ const String& rRiderText,
+ CreateTabPage pCreateFunc,
+ GetTabPageRanges pRangesFunc,
+ BOOL bItemsOnDemand,
+ USHORT nPos
+)
+{
+ DBG_ASSERT( TAB_PAGE_NOTFOUND == aTabCtrl.GetPagePos( nId ),
+ "Doppelte Page-Ids in der Tabpage" );
+ aTabCtrl.InsertPage( nId, rRiderText, nPos );
+ pImpl->pData->Append(
+ new Data_Impl( nId, pCreateFunc, pRangesFunc, bItemsOnDemand ) );
+}
+
+// -----------------------------------------------------------------------
+#ifdef SV_HAS_RIDERBITMAPS
+
+void SfxTabDialog::AddTabPage
+
+/* [Beschreibung]
+
+ Hinzuf"ugen einer Seite zu dem Dialog.
+ Die Riderbitmap wird "ubergeben, die Seite hat keine Entsprechung im
+ TabControl in der Resource des Dialogs.
+*/
+
+(
+ USHORT nId,
+ const Bitmap &rRiderBitmap,
+ CreateTabPage pCreateFunc,
+ GetTabPageRanges pRangesFunc,
+ BOOL bItemsOnDemand,
+ USHORT nPos
+)
+{
+ DBG_ASSERT( TAB_PAGE_NOTFOUND == aTabCtrl.GetPagePos( nId ),
+ "Doppelte Page-Ids in der Tabpage" );
+ aTabCtrl.InsertPage( nId, rRiderBitmap, nPos );
+ pImpl->pData->Append(
+ new Data_Impl( nId, pCreateFunc, pRangesFunc, bItemsOnDemand ) );
+}
+#endif
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::RemoveTabPage( USHORT nId )
+
+/* [Beschreibung]
+
+ L"oschen der TabPage mit der ID nId
+*/
+
+{
+ USHORT nPos = 0;
+ aTabCtrl.RemovePage( nId );
+ Data_Impl* pDataObject = Find( *pImpl->pData, nId, &nPos );
+
+ if ( pDataObject )
+ {
+ if ( pDataObject->pTabPage )
+ {
+ pDataObject->pTabPage->FillUserData();
+ String aPageData( pDataObject->pTabPage->GetUserData() );
+ if ( aPageData.Len() )
+ {
+ // save settings of this page (user data)
+ SvtViewOptions aPageOpt( E_TABPAGE, String::CreateFromInt32( pDataObject->nId ) );
+ aPageOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aPageData ) ) );
+ }
+
+ if ( pDataObject->bOnDemand )
+ delete (SfxItemSet*)&pDataObject->pTabPage->GetItemSet();
+ delete pDataObject->pTabPage;
+ }
+
+ delete pDataObject;
+ pImpl->pData->Remove( nPos );
+ }
+ else
+ {
+ DBG_WARNINGFILE( "TabPage-Id nicht bekannt" );
+ }
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::PageCreated
+
+/* [Beschreibung]
+
+ Defaultimplemetierung der virtuellen Methode.
+ Diese wird unmittelbar nach dem Erzeugen einer Seite gerufen.
+ Hier kann der Dialog direkt an der TabPage Methoden rufen.
+*/
+
+(
+ USHORT, // Id der erzeugten Seite
+ SfxTabPage& // Referenz auf die erzeugte Seite
+)
+{
+}
+
+// -----------------------------------------------------------------------
+
+SfxItemSet* SfxTabDialog::GetInputSetImpl()
+
+/* [Beschreibung]
+
+ Abgeleitete Klassen legen ggf. fuer den InputSet neuen Speicher an.
+ Dieser mu\s im Destruktor auch wieder freigegeben werden. Dazu mu\s
+ diese Methode gerufen werden.
+*/
+
+{
+ return (SfxItemSet*)pSet;
+}
+
+// -----------------------------------------------------------------------
+
+SfxTabPage* SfxTabDialog::GetTabPage( USHORT nPageId ) const
+
+/* [Beschreibung]
+
+ TabPage mit der "Ubergebenen Id zur"uckgeben.
+*/
+
+{
+ USHORT nPos = 0;
+ Data_Impl* pDataObject = Find( *pImpl->pData, nPageId, &nPos );
+
+ if ( pDataObject )
+ return pDataObject->pTabPage;
+ return NULL;
+}
+
+// -----------------------------------------------------------------------
+
+BOOL SfxTabDialog::IsInOK() const
+
+/* [Beschreibung]
+
+*/
+
+{
+ return pImpl->bInOK;
+}
+
+// -----------------------------------------------------------------------
+
+short SfxTabDialog::Ok()
+
+/* [Beschreibung]
+
+ Ok-Handler des Dialogs
+ Das OutputSet wird erstellt und jede Seite wird mit
+ dem bzw. ihrem speziellen OutputSet durch Aufruf der Methode
+ <SfxTabPage::FillItemSet(SfxItemSet &)> dazu aufgefordert,
+ die vom Benuzter eingestellten Daten in das Set zu tun.
+
+ [R"uckgabewert]
+
+ RET_OK: wenn mindestens eine Seite TRUE als Returnwert von
+ FillItemSet geliefert hat, sonst RET_CANCEL.
+*/
+
+{
+ pImpl->bInOK = TRUE;
+
+ if ( !pOutSet )
+ {
+ if ( !pExampleSet && pSet )
+ pOutSet = pSet->Clone( FALSE ); // ohne Items
+ else if ( pExampleSet )
+ pOutSet = new SfxItemSet( *pExampleSet );
+ }
+ BOOL bModified = FALSE;
+
+ const USHORT nCount = pImpl->pData->Count();
+
+ for ( USHORT i = 0; i < nCount; ++i )
+ {
+ Data_Impl* pDataObject = pImpl->pData->GetObject(i);
+ SfxTabPage* pTabPage = pDataObject->pTabPage;
+
+ if ( pTabPage )
+ {
+ if ( pDataObject->bOnDemand )
+ {
+ SfxItemSet& rSet = (SfxItemSet&)pTabPage->GetItemSet();
+ rSet.ClearItem();
+ bModified |= pTabPage->FillItemSet( rSet );
+ }
+ else if ( pSet && !pTabPage->HasExchangeSupport() )
+ {
+ SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
+
+ if ( pTabPage->FillItemSet( aTmp ) )
+ {
+ bModified |= TRUE;
+ pExampleSet->Put( aTmp );
+ pOutSet->Put( aTmp );
+ }
+ }
+ }
+ }
+
+ if ( pImpl->bModified || ( pOutSet && pOutSet->Count() > 0 ) )
+ bModified |= TRUE;
+
+ if ( bFmt == 2 )
+ bModified |= TRUE;
+ return bModified ? RET_OK : RET_CANCEL;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxTabDialog, CancelHdl, Button*, pButton )
+{
+ (void)pButton; //unused
+ Close();
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+SfxItemSet* SfxTabDialog::CreateInputItemSet( USHORT )
+
+/* [Beschreibung]
+
+ Defaultimplemetierung der virtuellen Methode.
+ Diese wird gerufen, wenn Pages ihre Sets onDenamd anlegen
+*/
+
+{
+ DBG_WARNINGFILE( "CreateInputItemSet nicht implementiert" );
+ return new SfxAllItemSet( SFX_APP()->GetPool() );
+}
+
+// -----------------------------------------------------------------------
+
+const SfxItemSet* SfxTabDialog::GetRefreshedSet()
+
+/* [Beschreibung]
+
+ Defaultimplemetierung der virtuellen Methode.
+ Diese wird gerufen, wenn <SfxTabPage::DeactivatePage(SfxItemSet *)>
+ <SfxTabPage::REFRESH_SET> liefert.
+*/
+
+{
+ DBG_ERRORFILE( "GetRefreshedSet nicht implementiert" );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxTabDialog, OkHdl, Button *, EMPTYARG )
+
+/* [Beschreibung]
+
+ Handler des Ok-Buttons
+ Dieser ruft f"ur die aktuelle Seite
+ <SfxTabPage::DeactivatePage(SfxItemSet *)>.
+ Liefert diese <SfxTabPage::LEAVE_PAGE>, wird <SfxTabDialog::Ok()> gerufen
+ und so der Dialog beendet.
+*/
+
+{
+ pImpl->bInOK = TRUE;
+
+ if ( OK_Impl() )
+ {
+ if ( pImpl->bModal )
+ EndDialog( Ok() );
+ else
+ {
+ Ok();
+ Close();
+ }
+ }
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+bool SfxTabDialog::PrepareLeaveCurrentPage()
+{
+ USHORT const nId = aTabCtrl.GetCurPageId();
+ SfxTabPage* pPage = dynamic_cast<SfxTabPage*> (aTabCtrl.GetTabPage( nId ));
+ bool bEnd = !pPage;
+
+ if ( pPage )
+ {
+ int nRet = SfxTabPage::LEAVE_PAGE;
+ if ( pSet )
+ {
+ SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
+
+ if ( pPage->HasExchangeSupport() )
+ nRet = pPage->DeactivatePage( &aTmp );
+ else
+ nRet = pPage->DeactivatePage( NULL );
+
+ if ( ( SfxTabPage::LEAVE_PAGE & nRet ) == SfxTabPage::LEAVE_PAGE
+ && aTmp.Count() )
+ {
+ pExampleSet->Put( aTmp );
+ pOutSet->Put( aTmp );
+ }
+ }
+ else
+ nRet = pPage->DeactivatePage( NULL );
+ bEnd = nRet;
+ }
+
+ return bEnd;
+}
+
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxTabDialog, UserHdl, Button *, EMPTYARG )
+
+/* [Beschreibung]
+
+ Handler des User-Buttons
+ Dieser ruft f"ur die aktuelle Seite
+ <SfxTabPage::DeactivatePage(SfxItemSet *)>.
+ Liefert diese <SfxTabPage::LEAVE_PAGE>, wird <SfxTabDialog::Ok()> gerufen.
+ Mit dem Return-Wert von <SfxTabDialog::Ok()> wird dann der Dialog beendet.
+*/
+
+{
+ if ( PrepareLeaveCurrentPage () )
+ {
+ short nRet = Ok();
+
+ if ( RET_OK == nRet )
+ nRet = RET_USER;
+ else
+ nRet = RET_USER_CANCEL;
+ EndDialog( nRet );
+ }
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxTabDialog, ResetHdl, Button *, EMPTYARG )
+
+/* [Beschreibung]
+
+ Handler hinter dem Zur"ucksetzen-Button.
+ Die aktuelle Page wird mit ihren initialen Daten
+ neu initialisiert; alle Einstellungen, die der Benutzer
+ auf dieser Seite get"atigt hat, werden aufgehoben.
+*/
+
+{
+ const USHORT nId = aTabCtrl.GetCurPageId();
+ Data_Impl* pDataObject = Find( *pImpl->pData, nId );
+ DBG_ASSERT( pDataObject, "Id nicht bekannt" );
+
+ if ( pDataObject->bOnDemand )
+ {
+ // CSet auf AIS hat hier Probleme, daher getrennt
+ const SfxItemSet* pItemSet = &pDataObject->pTabPage->GetItemSet();
+ pDataObject->pTabPage->Reset( *(SfxItemSet*)pItemSet );
+ }
+ else
+ pDataObject->pTabPage->Reset( *pSet );
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxTabDialog, BaseFmtHdl, Button *, EMPTYARG )
+
+/* [Beschreibung]
+
+ Handler hinter dem Standard-Button.
+ Dieser Button steht beim Bearbeiten von StyleSheets zur Verf"ugung.
+ Alle in dem bearbeiteten StyleSheet eingestellten Attribute
+ werden gel"oscht.
+*/
+
+{
+ const USHORT nId = aTabCtrl.GetCurPageId();
+ Data_Impl* pDataObject = Find( *pImpl->pData, nId );
+ DBG_ASSERT( pDataObject, "Id nicht bekannt" );
+ bFmt = 2;
+
+ if ( pDataObject->fnGetRanges )
+ {
+ if ( !pExampleSet )
+ pExampleSet = new SfxItemSet( *pSet );
+
+ const SfxItemPool* pPool = pSet->GetPool();
+ const USHORT* pTmpRanges = (pDataObject->fnGetRanges)();
+ SfxItemSet aTmpSet( *pExampleSet );
+
+ while ( *pTmpRanges )
+ {
+ const USHORT* pU = pTmpRanges + 1;
+
+ if ( *pTmpRanges == *pU )
+ {
+ // Range mit zwei gleichen Werten -> nur ein Item setzen
+ USHORT nWh = pPool->GetWhich( *pTmpRanges );
+ pExampleSet->ClearItem( nWh );
+ aTmpSet.ClearItem( nWh );
+ // am OutSet mit InvalidateItem,
+ // damit die "Anderung wirksam wird
+ pOutSet->InvalidateItem( nWh );
+ }
+ else
+ {
+ // richtiger Range mit mehreren Werten
+ USHORT nTmp = *pTmpRanges, nTmpEnd = *pU;
+ DBG_ASSERT( nTmp <= nTmpEnd, "Range ist falsch sortiert" );
+
+ if ( nTmp > nTmpEnd )
+ {
+ // wenn wirklich falsch sortiert, dann neu setzen
+ USHORT nTmp1 = nTmp;
+ nTmp = nTmpEnd;
+ nTmpEnd = nTmp1;
+ }
+
+ while ( nTmp <= nTmpEnd )
+ {
+ // "uber den Range iterieren, und die Items setzen
+ USHORT nWh = pPool->GetWhich( nTmp );
+ pExampleSet->ClearItem( nWh );
+ aTmpSet.ClearItem( nWh );
+ // am OutSet mit InvalidateItem,
+ // damit die "Anderung wirksam wird
+ pOutSet->InvalidateItem( nWh );
+ nTmp++;
+ }
+ }
+ // zum n"achsten Paar gehen
+ pTmpRanges += 2;
+ }
+ // alle Items neu gesetzt -> dann an der aktuellen Page Reset() rufen
+ DBG_ASSERT( pDataObject->pTabPage, "die Page ist weg" );
+ pDataObject->pTabPage->Reset( aTmpSet );
+ pDataObject->pTabPage->pImpl->mbStandard = TRUE;
+ }
+ return 1;
+}
+
+// -----------------------------------------------------------------------
+
+#if ENABLE_LAYOUT_SFX_TABDIALOG
+#define tabControlWindow pTabCtrl->GetWindow ()
+#else /* !ENABLE_LAYOUT_SFX_TABDIALOG */
+#define tabControlWindow pTabCtrl
+#endif /* !ENABLE_LAYOUT_SFX_TABDIALOG */
+
+IMPL_LINK( SfxTabDialog, ActivatePageHdl, TabControl *, pTabCtrl )
+
+/* [Beschreibung]
+
+ Handler, der vor dem Umschalten auf eine andere Seite
+ durch Starview gerufen wird.
+ Existiert die Seite noch nicht, so wird sie erzeugt und
+ die virtuelle Methode <SfxTabDialog::PageCreated( USHORT, SfxTabPage &)>
+ gerufen. Existiert die Seite bereits, so wird ggf.
+ <SfxTabPage::Reset(const SfxItemSet &)> oder
+ <SfxTabPage::ActivatePage(const SfxItemSet &)> gerufen.
+*/
+
+{
+ USHORT const nId = pTabCtrl->GetCurPageId();
+
+ DBG_ASSERT( pImpl->pData->Count(), "keine Pages angemeldet" );
+ SFX_APP();
+
+ // Tab Page schon da?
+ SfxTabPage* pTabPage = dynamic_cast<SfxTabPage*> (pTabCtrl->GetTabPage( nId ));
+ Data_Impl* pDataObject = Find( *pImpl->pData, nId );
+ DBG_ASSERT( pDataObject, "Id nicht bekannt" );
+
+ // ggf. TabPage erzeugen:
+ if ( !pTabPage )
+ {
+#if ENABLE_LAYOUT_SFX_TABDIALOG
+ if (dynamic_cast<layout SfxTabPage*> (pTabPage))
+ layout::TabPage::global_parent = pTabCtrl->GetWindow ();
+#endif
+ const SfxItemSet* pTmpSet = 0;
+
+ if ( pSet )
+ {
+ if ( bItemsReset && pSet->GetParent() )
+ pTmpSet = pSet->GetParent();
+ else
+ pTmpSet = pSet;
+ }
+
+ if ( pTmpSet && !pDataObject->bOnDemand )
+ pTabPage = (pDataObject->fnCreatePage)( tabControlWindow, *pTmpSet );
+ else
+ pTabPage = (pDataObject->fnCreatePage)
+ ( tabControlWindow, *CreateInputItemSet( nId ) );
+ DBG_ASSERT( NULL == pDataObject->pTabPage, "create TabPage more than once" );
+ pDataObject->pTabPage = pTabPage;
+
+#if !ENABLE_LAYOUT_SFX_TABDIALOG
+ pDataObject->pTabPage->SetTabDialog( this );
+#endif /* ENABLE_LAYOUT_SFX_TABDIALOG */
+ SvtViewOptions aPageOpt( E_TABPAGE, String::CreateFromInt32( pDataObject->nId ) );
+ String sUserData;
+ Any aUserItem = aPageOpt.GetUserItem( USERITEM_NAME );
+ OUString aTemp;
+ if ( aUserItem >>= aTemp )
+ sUserData = String( aTemp );
+ pTabPage->SetUserData( sUserData );
+ Size aSiz = pTabPage->GetSizePixel();
+
+#if ENABLE_LAYOUT
+ Size optimalSize = pTabPage->GetOptimalSize (WINDOWSIZE_MINIMUM);
+#if ENABLE_LAYOUT_SFX_TABDIALOG
+ if (dynamic_cast<layout SfxTabPage*> (pTabPage))
+ {
+ if (optimalSize.Height () && optimalSize.Width ())
+ {
+ optimalSize.Width () = optimalSize.Width ();
+ optimalSize.Height () = optimalSize.Height () + 40;
+ }
+ }
+#endif /* ENABLE_LAYOUT_SFX_TABDIALOG */
+ if (optimalSize.Height () > 0 && optimalSize.Width () > 0 )
+ aSiz = optimalSize;
+#endif /* ENABLE_LAYOUT */
+
+ Size aCtrlSiz = pTabCtrl->GetTabPageSizePixel();
+ // Gr"o/se am TabControl nur dann setzen, wenn < als TabPage
+ if ( aCtrlSiz.Width() < aSiz.Width() ||
+ aCtrlSiz.Height() < aSiz.Height() )
+ {
+ pTabCtrl->SetTabPageSizePixel( aSiz );
+ }
+
+ PageCreated( nId, *pTabPage );
+
+ if ( pDataObject->bOnDemand )
+ pTabPage->Reset( (SfxItemSet &)pTabPage->GetItemSet() );
+ else
+ pTabPage->Reset( *pSet );
+
+ pTabCtrl->SetTabPage( nId, pTabPage );
+ }
+ else if ( pDataObject->bRefresh )
+ pTabPage->Reset( *pSet );
+ pDataObject->bRefresh = FALSE;
+
+#if ENABLE_LAYOUT_SFX_TABDIALOG
+ pTabCtrl->GetPagePos (nId);
+#endif /* ENABLE_LAYOUT_SFX_TABDIALOG */
+
+ if ( pExampleSet )
+ pTabPage->ActivatePage( *pExampleSet );
+ BOOL bReadOnly = pTabPage->IsReadOnly();
+ ( bReadOnly || pImpl->bHideResetBtn ) ? aResetBtn.Hide() : aResetBtn.Show();
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+
+IMPL_LINK( SfxTabDialog, DeactivatePageHdl, TabControl *, pTabCtrl )
+
+/* [Beschreibung]
+
+ Handler, der vor dem Verlassen einer Seite durch Starview gerufen wird.
+
+ [Querverweise]
+
+ <SfxTabPage::DeactivatePage(SfxItemSet *)>
+*/
+
+{
+ USHORT nId = pTabCtrl->GetCurPageId();
+ SFX_APP();
+ SfxTabPage *pPage = dynamic_cast<SfxTabPage*> (pTabCtrl->GetTabPage( nId ));
+ DBG_ASSERT( pPage, "keine aktive Page" );
+#ifdef DBG_UTIL
+ Data_Impl* pDataObject = Find( *pImpl->pData, pTabCtrl->GetCurPageId() );
+ DBG_ASSERT( pDataObject, "keine Datenstruktur zur aktuellen Seite" );
+ if ( pPage->HasExchangeSupport() && pDataObject->bOnDemand )
+ {
+ DBG_WARNING( "Datenaustausch bei ItemsOnDemand ist nicht gewuenscht!" );
+ }
+#endif
+
+ int nRet = SfxTabPage::LEAVE_PAGE;
+
+ if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
+ pExampleSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
+
+ if ( pSet )
+ {
+ SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
+
+ if ( pPage->HasExchangeSupport() )
+ nRet = pPage->DeactivatePage( &aTmp );
+ else
+ nRet = pPage->DeactivatePage( NULL );
+//! else
+//! pPage->FillItemSet( aTmp );
+
+ if ( ( SfxTabPage::LEAVE_PAGE & nRet ) == SfxTabPage::LEAVE_PAGE &&
+ aTmp.Count() )
+ {
+ pExampleSet->Put( aTmp );
+ pOutSet->Put( aTmp );
+ }
+ }
+ else
+ {
+ if ( pPage->HasExchangeSupport() ) //!!!
+ {
+ if ( !pExampleSet )
+ {
+ SfxItemPool* pPool = pPage->GetItemSet().GetPool();
+ pExampleSet =
+ new SfxItemSet( *pPool, GetInputRanges( *pPool ) );
+ }
+ nRet = pPage->DeactivatePage( pExampleSet );
+ }
+ else
+ nRet = pPage->DeactivatePage( NULL );
+ }
+
+ if ( nRet & SfxTabPage::REFRESH_SET )
+ {
+ pSet = GetRefreshedSet();
+ DBG_ASSERT( pSet, "GetRefreshedSet() liefert NULL" );
+ // alle Pages als neu zu initialsieren flaggen
+ const USHORT nCount = pImpl->pData->Count();
+
+ for ( USHORT i = 0; i < nCount; ++i )
+ {
+ Data_Impl* pObj = (*pImpl->pData)[i];
+
+ if ( pObj->pTabPage != pPage ) // eigene Page nicht mehr refreshen
+ pObj->bRefresh = TRUE;
+ else
+ pObj->bRefresh = FALSE;
+ }
+ }
+ if ( nRet & SfxTabPage::LEAVE_PAGE )
+ return TRUE;
+ else
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------
+
+const SfxItemSet* SfxTabDialog::GetOutputItemSet
+
+/* [Beschreibung]
+
+ Liefert die Pages, die ihre Sets onDemand liefern, das OutputItemSet.
+
+ [Querverweise]
+
+ <SfxTabDialog::AddTabPage(USHORT, CreateTabPage, GetTabPageRanges, BOOL)>
+ <SfxTabDialog::AddTabPage(USHORT, const String &, CreateTabPage, GetTabPageRanges, BOOL, USHORT)>
+ <SfxTabDialog::AddTabPage(USHORT, const Bitmap &, CreateTabPage, GetTabPageRanges, BOOL, USHORT)>
+*/
+
+(
+ USHORT nId // die Id, unter der die Seite bei AddTabPage()
+ // hinzugef"ugt wurde.
+) const
+{
+ Data_Impl* pDataObject = Find( *pImpl->pData, nId );
+ DBG_ASSERT( pDataObject, "TabPage nicht gefunden" );
+
+ if ( pDataObject )
+ {
+ if ( !pDataObject->pTabPage )
+ return NULL;
+
+ if ( pDataObject->bOnDemand )
+ return &pDataObject->pTabPage->GetItemSet();
+ // else
+ return pOutSet;
+ }
+ return NULL;
+}
+
+// -----------------------------------------------------------------------
+
+int SfxTabDialog::FillOutputItemSet()
+{
+ int nRet = SfxTabPage::LEAVE_PAGE;
+ if ( OK_Impl() )
+ Ok();
+ else
+ nRet = SfxTabPage::KEEP_PAGE;
+ return nRet;
+}
+
+// -----------------------------------------------------------------------
+
+#ifdef WNT
+int __cdecl TabDlgCmpUS_Impl( const void* p1, const void* p2 )
+#else
+#if defined(OS2) && defined(ICC)
+int _Optlink TabDlgCmpUS_Impl( const void* p1, const void* p2 )
+#else
+extern "C" int TabDlgCmpUS_Impl( const void* p1, const void* p2 )
+#endif
+#endif
+
+/* [Beschreibung]
+
+ Vergleichsfunktion f"ur qsort
+*/
+
+{
+ return *(USHORT*)p1 - *(USHORT*)p2;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::ShowPage( USHORT nId )
+
+/* [Beschreibung]
+
+ Es wird die TabPage mit der "ubergebenen Id aktiviert.
+*/
+
+{
+ aTabCtrl.SetCurPageId( nId );
+ ActivatePageHdl( &aTabCtrl );
+}
+
+// -----------------------------------------------------------------------
+
+const USHORT* SfxTabDialog::GetInputRanges( const SfxItemPool& rPool )
+
+/* [Beschreibung]
+
+ Bildet das Set "uber die Ranges aller Seiten des Dialogs.
+ Die Pages m"ussen die statische Methode f"ur das Erfragen ihrer
+ Ranges bei AddTabPage angegeben haben, liefern also ihre Sets onDemand.
+
+ [Querverweise]
+
+ <SfxTabDialog::AddTabPage(USHORT, CreateTabPage, GetTabPageRanges, BOOL)>
+ <SfxTabDialog::AddTabPage(USHORT, const String &, CreateTabPage, GetTabPageRanges, BOOL, USHORT)>
+ <SfxTabDialog::AddTabPage(USHORT, const Bitmap &, CreateTabPage, GetTabPageRanges, BOOL, USHORT)>
+
+ [R"uckgabewert]
+
+ Pointer auf nullterminiertes Array von USHORTs
+ Dieses Array geh"ort dem Dialog und wird beim
+ Zerst"oren des Dialogs gel"oscht.
+*/
+
+{
+ if ( pSet )
+ {
+ DBG_ERRORFILE( "Set bereits vorhanden!" );
+ return pSet->GetRanges();
+ }
+
+ if ( pRanges )
+ return pRanges;
+ SvUShorts aUS( 16, 16 );
+ USHORT nCount = pImpl->pData->Count();
+
+ USHORT i;
+ for ( i = 0; i < nCount; ++i )
+ {
+ Data_Impl* pDataObject = pImpl->pData->GetObject(i);
+
+ if ( pDataObject->fnGetRanges )
+ {
+ const USHORT* pTmpRanges = (pDataObject->fnGetRanges)();
+ const USHORT* pIter = pTmpRanges;
+
+ USHORT nLen;
+ for( nLen = 0; *pIter; ++nLen, ++pIter )
+ ;
+ aUS.Insert( pTmpRanges, nLen, aUS.Count() );
+ }
+ }
+
+ //! Doppelte Ids entfernen?
+#ifndef TF_POOLABLE
+ if ( rPool.HasMap() )
+#endif
+ {
+ nCount = aUS.Count();
+
+ for ( i = 0; i < nCount; ++i )
+ aUS[i] = rPool.GetWhich( aUS[i] );
+ }
+
+ // sortieren
+ if ( aUS.Count() > 1 )
+ qsort( (void*)aUS.GetData(),
+ aUS.Count(), sizeof(USHORT), TabDlgCmpUS_Impl );
+
+ // Ranges erzeugen
+ //!! Auskommentiert, da fehlerhaft
+ /*
+ pRanges = new USHORT[aUS.Count() * 2 + 1];
+ int j = 0;
+ i = 0;
+
+ while ( i < aUS.Count() )
+ {
+ pRanges[j++] = aUS[i];
+ // aufeinanderfolgende Zahlen
+ for( ; i < aUS.Count()-1; ++i )
+ if ( aUS[i] + 1 != aUS[i+1] )
+ break;
+ pRanges[j++] = aUS[i++];
+ }
+ pRanges[j] = 0; // terminierende NULL
+ */
+
+ pRanges = new USHORT[aUS.Count() + 1];
+ memcpy(pRanges, aUS.GetData(), sizeof(USHORT) * aUS.Count());
+ pRanges[aUS.Count()] = 0;
+ return pRanges;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxTabDialog::SetInputSet( const SfxItemSet* pInSet )
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann nachtr"aglich der Input-Set initial oder
+ neu gesetzt werden.
+*/
+
+{
+ FASTBOOL bSet = ( pSet != NULL );
+
+ pSet = pInSet;
+
+ if ( !bSet && !pExampleSet && !pOutSet )
+ {
+ pExampleSet = new SfxItemSet( *pSet );
+ pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
+ }
+}
+
+long SfxTabDialog::Notify( NotifyEvent& rNEvt )
+{
+ if ( rNEvt.GetType() == EVENT_GETFOCUS )
+ {
+ SfxViewFrame* pViewFrame = GetViewFrame() ? GetViewFrame() : SfxViewFrame::Current();
+ if ( pViewFrame )
+ {
+ Window* pWindow = rNEvt.GetWindow();
+ rtl::OString sHelpId;
+ while ( !sHelpId.getLength() && pWindow )
+ {
+ sHelpId = pWindow->GetHelpId();
+ pWindow = pWindow->GetParent();
+ }
+
+ if ( sHelpId.getLength() )
+ SfxHelp::OpenHelpAgent( &pViewFrame->GetFrame(), sHelpId );
+ }
+ }
+
+ return TabDialog::Notify( rNEvt );
+}
+
+END_NAMESPACE_LAYOUT_SFX_TABDIALOG
diff --git a/sfx2/source/dialog/taskpane.cxx b/sfx2/source/dialog/taskpane.cxx
new file mode 100644
index 000000000000..1c2faac4e8a3
--- /dev/null
+++ b/sfx2/source/dialog/taskpane.cxx
@@ -0,0 +1,1299 @@
+/*************************************************************************
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_sfx2.hxx"
+
+#include "sfx2/taskpane.hxx"
+#include "imagemgr.hxx"
+#include "sfx2/sfxsids.hrc"
+#include "sfx2/bindings.hxx"
+#include "sfx2/dispatch.hxx"
+#include "sfxresid.hxx"
+#include "sfxlocal.hrc"
+#include "helpid.hrc"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/ui/XToolPanel.hpp>
+#include <com/sun/star/ui/XUIElementFactory.hpp>
+#include <com/sun/star/awt/XWindowPeer.hpp>
+#include <com/sun/star/awt/PosSize.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/graphic/XGraphicProvider.hpp>
+#include <com/sun/star/accessibility/XAccessible.hpp>
+#include <com/sun/star/awt/XControl.hpp>
+/** === end UNO includes === **/
+
+#include <comphelper/componentcontext.hxx>
+#include <comphelper/namedvaluecollection.hxx>
+#include <comphelper/types.hxx>
+#include <comphelper/processfactory.hxx>
+#include <tools/diagnose_ex.h>
+#include <svtools/toolpanel/toolpaneldeck.hxx>
+#include <svtools/toolpanel/tablayouter.hxx>
+#include <svtools/toolpanel/drawerlayouter.hxx>
+#include <unotools/confignode.hxx>
+#include <vcl/menu.hxx>
+#include <vcl/svapp.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <tools/urlobj.hxx>
+#include <boost/noncopyable.hpp>
+
+//......................................................................................................................
+namespace sfx2
+{
+//......................................................................................................................
+
+ /** === begin UNO using === **/
+ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::uno::XInterface;
+ using ::com::sun::star::uno::UNO_QUERY;
+ using ::com::sun::star::uno::UNO_QUERY_THROW;
+ using ::com::sun::star::uno::UNO_SET_THROW;
+ using ::com::sun::star::uno::Exception;
+ using ::com::sun::star::uno::RuntimeException;
+ using ::com::sun::star::uno::Any;
+ using ::com::sun::star::uno::makeAny;
+ using ::com::sun::star::uno::Sequence;
+ using ::com::sun::star::uno::Type;
+ using ::com::sun::star::frame::XModuleManager;
+ using ::com::sun::star::container::XNameAccess;
+ using ::com::sun::star::ui::XToolPanel;
+ using ::com::sun::star::ui::XUIElementFactory;
+ using ::com::sun::star::ui::XUIElement;
+ using ::com::sun::star::awt::XWindow;
+ using ::com::sun::star::frame::XModuleManager;
+ using ::com::sun::star::frame::XFrame;
+ using ::com::sun::star::lang::XComponent;
+ using ::com::sun::star::graphic::XGraphicProvider;
+ using ::com::sun::star::graphic::XGraphic;
+ using ::com::sun::star::accessibility::XAccessible;
+ using ::com::sun::star::awt::XControl;
+ /** === end UNO using === **/
+ namespace PosSize = ::com::sun::star::awt::PosSize;
+
+ //==================================================================================================================
+ //= helpers
+ //==================================================================================================================
+ namespace
+ {
+ //--------------------------------------------------------------------------------------------------------------
+ ::utl::OConfigurationTreeRoot lcl_getModuleUIElementStatesConfig( const ::rtl::OUString& i_rModuleIdentifier,
+ const ::rtl::OUString& i_rResourceURL = ::rtl::OUString() )
+ {
+ const ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ ::rtl::OUStringBuffer aPathComposer;
+ try
+ {
+ const Reference< XNameAccess > xModuleAccess( aContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW );
+ const ::comphelper::NamedValueCollection aModuleProps( xModuleAccess->getByName( i_rModuleIdentifier ) );
+
+ const ::rtl::OUString sWindowStateRef( aModuleProps.getOrDefault( "ooSetupFactoryWindowStateConfigRef", ::rtl::OUString() ) );
+
+ aPathComposer.appendAscii( "org.openoffice.Office.UI." );
+ aPathComposer.append( sWindowStateRef );
+ aPathComposer.appendAscii( "/UIElements/States" );
+ if ( i_rResourceURL.getLength() )
+ {
+ aPathComposer.appendAscii( "/" );
+ aPathComposer.append( i_rResourceURL );
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return ::utl::OConfigurationTreeRoot( aContext, aPathComposer.makeStringAndClear(), false );
+ }
+
+ //--------------------------------------------------------------------------------------------------------------
+ ::rtl::OUString lcl_identifyModule( const Reference< XFrame >& i_rDocumentFrame )
+ {
+ ::rtl::OUString sModuleName;
+ try
+ {
+ const ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ const Reference< XModuleManager > xModuleManager( aContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW );
+ sModuleName = xModuleManager->identify( i_rDocumentFrame );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return sModuleName;
+ }
+
+ //--------------------------------------------------------------------------------------------------------------
+ Reference< XFrame > lcl_getFrame( const SfxBindings* i_pBindings )
+ {
+ const SfxViewFrame* pViewFrame = i_pBindings->GetDispatcher()->GetFrame();
+ const SfxFrame& rFrame = pViewFrame->GetFrame();
+ const Reference< XFrame > xFrame( rFrame.GetFrameInterface() );
+ return xFrame;
+ }
+
+ //--------------------------------------------------------------------------------------------------------------
+ ::rtl::OUString lcl_getPanelHelpURL( const ::utl::OConfigurationNode& i_rPanelConfigNode )
+ {
+ const ::rtl::OUString sHelpURL( ::comphelper::getString( i_rPanelConfigNode.getNodeValue( "HelpURL" ) ) );
+ return sHelpURL;
+ }
+
+ //--------------------------------------------------------------------------------------------------------------
+ Image lcl_getPanelImage( const Reference< XFrame >& i_rDocFrame, const ::utl::OConfigurationNode& i_rPanelConfigNode )
+ {
+ const ::rtl::OUString sImageURL( ::comphelper::getString( i_rPanelConfigNode.getNodeValue( "ImageURL" ) ) );
+ if ( sImageURL.getLength() )
+ {
+ try
+ {
+ ::comphelper::NamedValueCollection aMediaProperties;
+ aMediaProperties.put( "URL", sImageURL );
+
+ // special handling: if the ImageURL denotes a CommandName, then retrieve the image for that command
+ const sal_Char* pCommandImagePrefix = "private:commandimage/";
+ const sal_Int32 nCommandImagePrefixLen = strlen( pCommandImagePrefix );
+ if ( sImageURL.compareToAscii( pCommandImagePrefix, nCommandImagePrefixLen ) == 0 )
+ {
+ ::rtl::OUStringBuffer aCommandName;
+ aCommandName.appendAscii( ".uno:" );
+ aCommandName.append( sImageURL.copy( nCommandImagePrefixLen ) );
+ const ::rtl::OUString sCommandName( aCommandName.makeStringAndClear() );
+
+ const BOOL bHiContrast( Application::GetSettings().GetStyleSettings().GetHighContrastMode() );
+ const Image aPanelImage( GetImage( i_rDocFrame, sCommandName, FALSE, bHiContrast ) );
+ return aPanelImage.GetXGraphic();
+ }
+
+ // otherwise, delegate to the GraphicProvider
+ const ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ const Reference< XGraphicProvider > xGraphicProvider( aContext.createComponent( "com.sun.star.graphic.GraphicProvider" ), UNO_QUERY_THROW );
+
+ const Reference< XGraphic > xGraphic( xGraphicProvider->queryGraphic( aMediaProperties.getPropertyValues() ), UNO_SET_THROW );
+ return Image( xGraphic );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+ return Image();
+ }
+ }
+
+ //==================================================================================================================
+ //= TaskPaneDockingWindow
+ //==================================================================================================================
+ //------------------------------------------------------------------------------------------------------------------
+ TaskPaneDockingWindow::TaskPaneDockingWindow( SfxBindings* i_pBindings, TaskPaneWrapper& i_rWrapper, Window* i_pParent, WinBits i_nBits )
+ :TitledDockingWindow( i_pBindings, &i_rWrapper, i_pParent, i_nBits )
+ ,m_aTaskPane( GetContentWindow(), lcl_getFrame( i_pBindings ) )
+ ,m_aPaneController( m_aTaskPane, *this )
+ {
+ m_aTaskPane.Show();
+ SetText( String( SfxResId( SID_TASKPANE ) ) );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TaskPaneDockingWindow::ActivateToolPanel( const ::rtl::OUString& i_rPanelURL )
+ {
+ m_aPaneController.ActivateToolPanel( i_rPanelURL );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TaskPaneDockingWindow::GetFocus()
+ {
+ TitledDockingWindow::GetFocus();
+ m_aTaskPane.GrabFocus();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TaskPaneDockingWindow::onLayoutDone()
+ {
+ m_aTaskPane.SetPosSizePixel( Point(), GetContentWindow().GetOutputSizePixel() );
+ }
+
+ //==================================================================================================================
+ //= TaskPaneWrapper
+ //==================================================================================================================
+ //------------------------------------------------------------------------------------------------------------------
+ SFX_IMPL_DOCKINGWINDOW( TaskPaneWrapper, SID_TASKPANE );
+
+ //------------------------------------------------------------------------------------------------------------------
+ TaskPaneWrapper::TaskPaneWrapper( Window* i_pParent, USHORT i_nId, SfxBindings* i_pBindings, SfxChildWinInfo* i_pInfo )
+ :SfxChildWindow( i_pParent, i_nId )
+ {
+ pWindow = new TaskPaneDockingWindow( i_pBindings, *this, i_pParent,
+ WB_STDDOCKWIN | WB_CLIPCHILDREN | WB_SIZEABLE | WB_3DLOOK | WB_ROLLABLE);
+ eChildAlignment = SFX_ALIGN_RIGHT;
+
+ pWindow->SetHelpId( HID_TASKPANE_WINDOW );
+ pWindow->SetOutputSizePixel( Size( 300, 450 ) );
+
+ dynamic_cast< SfxDockingWindow* >( pWindow )->Initialize( i_pInfo );
+ SetHideNotDelete( TRUE );
+
+ pWindow->Show();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TaskPaneWrapper::ActivateToolPanel( const ::rtl::OUString& i_rPanelURL )
+ {
+ TaskPaneDockingWindow* pDockingWindow = dynamic_cast< TaskPaneDockingWindow* >( GetWindow() );
+ ENSURE_OR_RETURN_VOID( pDockingWindow, "TaskPaneWrapper::ActivateToolPanel: invalid docking window implementation!" );
+ pDockingWindow->ActivateToolPanel( i_rPanelURL );
+ }
+
+ //==================================================================================================================
+ //= CustomPanelUIElement
+ //==================================================================================================================
+ class CustomPanelUIElement
+ {
+ public:
+ CustomPanelUIElement()
+ :m_xUIElement()
+ ,m_xToolPanel()
+ ,m_xPanelWindow()
+ {
+ }
+
+ CustomPanelUIElement( const Reference< XUIElement >& i_rUIElement )
+ :m_xUIElement( i_rUIElement, UNO_SET_THROW )
+ ,m_xToolPanel( i_rUIElement->getRealInterface(), UNO_QUERY_THROW )
+ ,m_xPanelWindow( m_xToolPanel->getWindow(), UNO_SET_THROW )
+ {
+ }
+
+ bool is() const { return m_xPanelWindow.is(); }
+
+ const Reference< XUIElement >& getUIElement() const { return m_xUIElement; }
+ const Reference< XToolPanel >& getToolPanel() const { return m_xToolPanel; }
+ const Reference< XWindow >& getPanelWindow() const { return m_xPanelWindow; }
+
+ private:
+ Reference< XUIElement > m_xUIElement;
+ Reference< XToolPanel > m_xToolPanel;
+ Reference< XWindow > m_xPanelWindow;
+ };
+
+ //==================================================================================================================
+ //= CustomToolPanel
+ //==================================================================================================================
+ class CustomToolPanel : public ::svt::ToolPanelBase
+ {
+ public:
+ CustomToolPanel( const ::utl::OConfigurationNode& i_rPanelWindowState, const Reference< XFrame >& i_rFrame );
+
+ virtual ::rtl::OUString GetDisplayName() const;
+ virtual Image GetImage() const;
+ virtual rtl::OString GetHelpID() const;
+ virtual void Activate( Window& i_rParentWindow );
+ virtual void Deactivate();
+ virtual void SetSizePixel( const Size& i_rPanelWindowSize );
+ virtual void GrabFocus();
+ virtual void Dispose();
+ virtual Reference< XAccessible >
+ CreatePanelAccessible( const Reference< XAccessible >& i_rParentAccessible );
+
+ const ::rtl::OUString&
+ GetResourceURL() const { return m_sResourceURL; }
+
+ protected:
+ ~CustomToolPanel();
+
+ private:
+ bool impl_ensureToolPanelWindow( Window& i_rPanelParentWindow );
+ void impl_updatePanelConfig( const bool i_bVisible ) const;
+
+ private:
+ const ::rtl::OUString m_sUIName;
+ const Image m_aPanelImage;
+ const ::rtl::OUString m_aPanelHelpURL;
+ const ::rtl::OUString m_sResourceURL;
+ const ::rtl::OUString m_sPanelConfigPath;
+ Reference< XFrame > m_xFrame;
+ CustomPanelUIElement m_aCustomPanel;
+ bool m_bAttemptedCreation;
+ };
+
+ //------------------------------------------------------------------------------------------------------------------
+ CustomToolPanel::CustomToolPanel( const ::utl::OConfigurationNode& i_rPanelWindowState, const Reference< XFrame >& i_rFrame )
+ :m_sUIName( ::comphelper::getString( i_rPanelWindowState.getNodeValue( "UIName" ) ) )
+ ,m_aPanelImage( lcl_getPanelImage( i_rFrame, i_rPanelWindowState ) )
+ ,m_aPanelHelpURL( lcl_getPanelHelpURL( i_rPanelWindowState ) )
+ ,m_sResourceURL( i_rPanelWindowState.getLocalName() )
+ ,m_sPanelConfigPath( i_rPanelWindowState.getNodePath() )
+ ,m_xFrame( i_rFrame )
+ ,m_aCustomPanel()
+ ,m_bAttemptedCreation( false )
+ {
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ CustomToolPanel::~CustomToolPanel()
+ {
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ bool CustomToolPanel::impl_ensureToolPanelWindow( Window& i_rPanelParentWindow )
+ {
+ if ( m_bAttemptedCreation )
+ return m_aCustomPanel.is();
+
+ m_bAttemptedCreation = true;
+ try
+ {
+ const ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ const Reference< XUIElementFactory > xFactory( aContext.createComponent( "com.sun.star.ui.UIElementFactoryManager" ), UNO_QUERY_THROW );
+
+ ::comphelper::NamedValueCollection aCreationArgs;
+ aCreationArgs.put( "Frame", makeAny( m_xFrame ) );
+ aCreationArgs.put( "ParentWindow", makeAny( i_rPanelParentWindow.GetComponentInterface() ) );
+
+ const Reference< XUIElement > xElement(
+ xFactory->createUIElement( m_sResourceURL, aCreationArgs.getPropertyValues() ),
+ UNO_SET_THROW );
+
+ m_aCustomPanel = CustomPanelUIElement( xElement );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return m_aCustomPanel.is();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void CustomToolPanel::impl_updatePanelConfig( const bool i_bVisible ) const
+ {
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ ::utl::OConfigurationTreeRoot aConfig( aContext, m_sPanelConfigPath, true );
+
+ aConfig.setNodeValue( "Visible", makeAny( i_bVisible ) );
+ aConfig.commit();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ ::rtl::OUString CustomToolPanel::GetDisplayName() const
+ {
+ return m_sUIName;
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ Image CustomToolPanel::GetImage() const
+ {
+ return m_aPanelImage;
+ }
+
+ static rtl::OString lcl_getHelpId( const ::rtl::OUString& _rHelpURL )
+ {
+ INetURLObject aHID( _rHelpURL );
+ if ( aHID.GetProtocol() == INET_PROT_HID )
+ return rtl::OUStringToOString( aHID.GetURLPath(), RTL_TEXTENCODING_UTF8 );
+ else
+ return rtl::OUStringToOString( _rHelpURL, RTL_TEXTENCODING_UTF8 );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ rtl::OString CustomToolPanel::GetHelpID() const
+ {
+ return lcl_getHelpId( m_aPanelHelpURL );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void CustomToolPanel::Activate( Window& i_rParentWindow )
+ {
+ ENSURE_OR_RETURN_VOID( impl_ensureToolPanelWindow( i_rParentWindow ), "no panel to activate!" );
+
+ // TODO: we might need a mechanism to decide whether the panel should be destroyed/re-created, or (as it is
+ // done now) hidden/shown
+ m_aCustomPanel.getPanelWindow()->setVisible( sal_True );
+
+ // update the panel's configuration
+ impl_updatePanelConfig( true );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void CustomToolPanel::Deactivate()
+ {
+ ENSURE_OR_RETURN_VOID( m_aCustomPanel.is(), "no panel to deactivate!" );
+
+ m_aCustomPanel.getPanelWindow()->setVisible( sal_False );
+
+ // update the panel's configuration
+ impl_updatePanelConfig( false );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void CustomToolPanel::SetSizePixel( const Size& i_rPanelWindowSize )
+ {
+ ENSURE_OR_RETURN_VOID( m_aCustomPanel.is(), "no panel/window to position!" );
+
+ try
+ {
+ m_aCustomPanel.getPanelWindow()->setPosSize( 0, 0, i_rPanelWindowSize.Width(), i_rPanelWindowSize.Height(),
+ PosSize::POSSIZE );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void CustomToolPanel::GrabFocus()
+ {
+ ENSURE_OR_RETURN_VOID( m_aCustomPanel.is(), "no panel/window to focus!" );
+
+ m_aCustomPanel.getPanelWindow()->setFocus();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void CustomToolPanel::Dispose()
+ {
+ if ( !m_bAttemptedCreation )
+ // nothing to dispose
+ return;
+
+ ENSURE_OR_RETURN_VOID( m_aCustomPanel.is(), "no panel to destroy!" );
+ try
+ {
+ Reference< XComponent > xUIElementComponent( m_aCustomPanel.getUIElement(), UNO_QUERY_THROW );
+ xUIElementComponent->dispose();
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ Reference< XAccessible > CustomToolPanel::CreatePanelAccessible( const Reference< XAccessible >& i_rParentAccessible )
+ {
+ ENSURE_OR_RETURN( m_aCustomPanel.is(), "no panel to ask!", NULL );
+
+ Reference< XAccessible > xPanelAccessible;
+ try
+ {
+ xPanelAccessible.set( m_aCustomPanel.getToolPanel()->createAccessible( i_rParentAccessible ), UNO_SET_THROW );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return xPanelAccessible;
+ }
+
+ //==================================================================================================================
+ //= ModuleTaskPane_Impl
+ //==================================================================================================================
+ class ModuleTaskPane_Impl : public ::boost::noncopyable
+ {
+ public:
+ ModuleTaskPane_Impl( ModuleTaskPane& i_rAntiImpl, const Reference< XFrame >& i_rDocumentFrame,
+ const IToolPanelCompare* i_pPanelCompare )
+ :m_rAntiImpl( i_rAntiImpl )
+ ,m_sModuleIdentifier( lcl_identifyModule( i_rDocumentFrame ) )
+ ,m_xFrame( i_rDocumentFrame )
+ ,m_aPanelDeck( i_rAntiImpl )
+ {
+ m_aPanelDeck.Show();
+ OnResize();
+ impl_initFromConfiguration( i_pPanelCompare );
+ }
+
+ ~ModuleTaskPane_Impl()
+ {
+ }
+
+ void OnResize();
+ void OnGetFocus();
+
+ static bool ModuleHasToolPanels( const ::rtl::OUString& i_rModuleIdentifier );
+
+ ::svt::ToolPanelDeck& GetPanelDeck() { return m_aPanelDeck; }
+ const ::svt::ToolPanelDeck& GetPanelDeck() const { return m_aPanelDeck; }
+
+ ::boost::optional< size_t >
+ GetPanelPos( const ::rtl::OUString& i_rResourceURL );
+ ::rtl::OUString
+ GetPanelResourceURL( const size_t i_nPanelPos ) const;
+
+ void SetDrawersLayout();
+ void SetTabsLayout( const ::svt::TabAlignment i_eTabAlignment, const ::svt::TabItemContent i_eTabContent );
+
+ private:
+ void impl_initFromConfiguration( const IToolPanelCompare* i_pPanelCompare );
+
+ static bool
+ impl_isToolPanelResource( const ::rtl::OUString& i_rResourceURL );
+
+ DECL_LINK( OnActivatePanel, void* );
+
+ private:
+ ModuleTaskPane& m_rAntiImpl;
+ const ::rtl::OUString m_sModuleIdentifier;
+ const Reference< XFrame > m_xFrame;
+ ::svt::ToolPanelDeck m_aPanelDeck;
+ };
+
+ //------------------------------------------------------------------------------------------------------------------
+ void ModuleTaskPane_Impl::OnResize()
+ {
+ m_aPanelDeck.SetPosSizePixel( Point(), m_rAntiImpl.GetOutputSizePixel() );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void ModuleTaskPane_Impl::OnGetFocus()
+ {
+ m_aPanelDeck.GrabFocus();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ IMPL_LINK( ModuleTaskPane_Impl, OnActivatePanel, void*, i_pArg )
+ {
+ m_aPanelDeck.ActivatePanel( reinterpret_cast< size_t >( i_pArg ) );
+ return 1L;
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ bool ModuleTaskPane_Impl::impl_isToolPanelResource( const ::rtl::OUString& i_rResourceURL )
+ {
+ return i_rResourceURL.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "private:resource/toolpanel/" ) );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void ModuleTaskPane_Impl::impl_initFromConfiguration( const IToolPanelCompare* i_pPanelCompare )
+ {
+ const ::utl::OConfigurationTreeRoot aWindowStateConfig( lcl_getModuleUIElementStatesConfig( m_sModuleIdentifier ) );
+ if ( !aWindowStateConfig.isValid() )
+ return;
+
+ ::rtl::OUString sFirstVisiblePanelResource;
+ ::rtl::OUString sFirstPanelResource;
+
+ const Sequence< ::rtl::OUString > aUIElements( aWindowStateConfig.getNodeNames() );
+ for ( const ::rtl::OUString* resource = aUIElements.getConstArray();
+ resource != aUIElements.getConstArray() + aUIElements.getLength();
+ ++resource
+ )
+ {
+ if ( !impl_isToolPanelResource( *resource ) )
+ continue;
+
+ sFirstPanelResource = *resource;
+
+ ::utl::OConfigurationNode aResourceNode( aWindowStateConfig.openNode( *resource ) );
+ ::svt::PToolPanel pCustomPanel( new CustomToolPanel( aResourceNode, m_xFrame ) );
+
+ size_t nPanelPos = m_aPanelDeck.GetPanelCount();
+ if ( i_pPanelCompare )
+ {
+ // assuming that nobody will insert hundreths of panels, a simple O(n) search should suffice here ...
+ while ( nPanelPos > 0 )
+ {
+ const short nCompare = i_pPanelCompare->compareToolPanelsURLs(
+ *resource,
+ GetPanelResourceURL( --nPanelPos )
+ );
+ if ( nCompare >= 0 )
+ {
+ ++nPanelPos;
+ break;
+ }
+ }
+ }
+ nPanelPos = m_aPanelDeck.InsertPanel( pCustomPanel, nPanelPos );
+
+ if ( ::comphelper::getBOOL( aResourceNode.getNodeValue( "Visible" ) ) )
+ sFirstVisiblePanelResource = *resource;
+ }
+
+ if ( sFirstVisiblePanelResource.getLength() == 0 )
+ sFirstVisiblePanelResource = sFirstPanelResource;
+
+ if ( sFirstVisiblePanelResource.getLength() )
+ {
+ ::boost::optional< size_t > aPanelPos( GetPanelPos( sFirstVisiblePanelResource ) );
+ OSL_ENSURE( !!aPanelPos, "ModuleTaskPane_Impl::impl_isToolPanelResource: just inserted it, and it's not there?!" );
+ if ( !!aPanelPos )
+ m_rAntiImpl.PostUserEvent( LINK( this, ModuleTaskPane_Impl, OnActivatePanel ), reinterpret_cast< void* >( *aPanelPos ) );
+ }
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ bool ModuleTaskPane_Impl::ModuleHasToolPanels( const ::rtl::OUString& i_rModuleIdentifier )
+ {
+ const ::utl::OConfigurationTreeRoot aWindowStateConfig( lcl_getModuleUIElementStatesConfig( i_rModuleIdentifier ) );
+ if ( !aWindowStateConfig.isValid() )
+ return false;
+
+ const Sequence< ::rtl::OUString > aUIElements( aWindowStateConfig.getNodeNames() );
+ for ( const ::rtl::OUString* resource = aUIElements.getConstArray();
+ resource != aUIElements.getConstArray() + aUIElements.getLength();
+ ++resource
+ )
+ {
+ if ( impl_isToolPanelResource( *resource ) )
+ return true;
+ }
+ return false;
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ ::boost::optional< size_t > ModuleTaskPane_Impl::GetPanelPos( const ::rtl::OUString& i_rResourceURL )
+ {
+ ::boost::optional< size_t > aPanelPos;
+ for ( size_t i = 0; i < m_aPanelDeck.GetPanelCount(); ++i )
+ {
+ const ::svt::PToolPanel pPanel( m_aPanelDeck.GetPanel( i ) );
+ const CustomToolPanel* pCustomPanel = dynamic_cast< const CustomToolPanel* >( pPanel.get() );
+ ENSURE_OR_CONTINUE( pCustomPanel != NULL, "ModuleTaskPane_Impl::GetPanelPos: illegal panel implementation!" );
+ if ( pCustomPanel->GetResourceURL() == i_rResourceURL )
+ {
+ aPanelPos = i;
+ break;
+ }
+ }
+ return aPanelPos;
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ ::rtl::OUString ModuleTaskPane_Impl::GetPanelResourceURL( const size_t i_nPanelPos ) const
+ {
+ ENSURE_OR_RETURN( i_nPanelPos < m_aPanelDeck.GetPanelCount(), "ModuleTaskPane_Impl::GetPanelResourceURL: illegal panel position!", ::rtl::OUString() );
+ const ::svt::PToolPanel pPanel( m_aPanelDeck.GetPanel( i_nPanelPos ) );
+ const CustomToolPanel* pCustomPanel = dynamic_cast< const CustomToolPanel* >( pPanel.get() );
+ ENSURE_OR_RETURN( pCustomPanel != NULL, "ModuleTaskPane_Impl::GetPanelPos: illegal panel implementation!", ::rtl::OUString() );
+ return pCustomPanel->GetResourceURL();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void ModuleTaskPane_Impl::SetDrawersLayout()
+ {
+ const ::svt::PDeckLayouter pLayouter( m_aPanelDeck.GetLayouter() );
+ const ::svt::DrawerDeckLayouter* pDrawerLayouter = dynamic_cast< const ::svt::DrawerDeckLayouter* >( pLayouter.get() );
+ if ( pDrawerLayouter != NULL )
+ // already have the proper layout
+ return;
+ m_aPanelDeck.SetLayouter( new ::svt::DrawerDeckLayouter( m_aPanelDeck, m_aPanelDeck ) );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void ModuleTaskPane_Impl::SetTabsLayout( const ::svt::TabAlignment i_eTabAlignment, const ::svt::TabItemContent i_eTabContent )
+ {
+ ::svt::PDeckLayouter pLayouter( m_aPanelDeck.GetLayouter() );
+ ::svt::TabDeckLayouter* pTabLayouter = dynamic_cast< ::svt::TabDeckLayouter* >( pLayouter.get() );
+ if ( ( pTabLayouter != NULL )
+ && ( pTabLayouter->GetTabAlignment() == i_eTabAlignment )
+ && ( pTabLayouter->GetTabItemContent() == i_eTabContent )
+ )
+ // already have the requested layout
+ return;
+
+ if ( pTabLayouter && ( pTabLayouter->GetTabAlignment() == i_eTabAlignment ) )
+ {
+ // changing only the item content does not require a new layouter instance
+ pTabLayouter->SetTabItemContent( i_eTabContent );
+ return;
+ }
+
+ m_aPanelDeck.SetLayouter( new ::svt::TabDeckLayouter( m_aPanelDeck, m_aPanelDeck, i_eTabAlignment, i_eTabContent ) );
+ }
+
+ //==================================================================================================================
+ //= ModuleTaskPane
+ //==================================================================================================================
+ //------------------------------------------------------------------------------------------------------------------
+ ModuleTaskPane::ModuleTaskPane( Window& i_rParentWindow, const Reference< XFrame >& i_rDocumentFrame )
+ :Window( &i_rParentWindow, WB_DIALOGCONTROL )
+ ,m_pImpl( new ModuleTaskPane_Impl( *this, i_rDocumentFrame, NULL ) )
+ {
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ ModuleTaskPane::ModuleTaskPane( Window& i_rParentWindow, const Reference< XFrame >& i_rDocumentFrame,
+ const IToolPanelCompare& i_rCompare )
+ :Window( &i_rParentWindow, WB_DIALOGCONTROL )
+ ,m_pImpl( new ModuleTaskPane_Impl( *this, i_rDocumentFrame, &i_rCompare ) )
+ {
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ ModuleTaskPane::~ModuleTaskPane()
+ {
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ bool ModuleTaskPane::ModuleHasToolPanels( const ::rtl::OUString& i_rModuleIdentifier )
+ {
+ return ModuleTaskPane_Impl::ModuleHasToolPanels( i_rModuleIdentifier );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ bool ModuleTaskPane::ModuleHasToolPanels( const Reference< XFrame >& i_rDocumentFrame )
+ {
+ return ModuleTaskPane_Impl::ModuleHasToolPanels( lcl_identifyModule( i_rDocumentFrame ) );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void ModuleTaskPane::Resize()
+ {
+ Window::Resize();
+ m_pImpl->OnResize();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void ModuleTaskPane::GetFocus()
+ {
+ Window::GetFocus();
+ m_pImpl->OnGetFocus();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ ::svt::ToolPanelDeck& ModuleTaskPane::GetPanelDeck()
+ {
+ return m_pImpl->GetPanelDeck();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ const ::svt::ToolPanelDeck& ModuleTaskPane::GetPanelDeck() const
+ {
+ return m_pImpl->GetPanelDeck();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ ::boost::optional< size_t > ModuleTaskPane::GetPanelPos( const ::rtl::OUString& i_rResourceURL )
+ {
+ return m_pImpl->GetPanelPos( i_rResourceURL );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ ::rtl::OUString ModuleTaskPane::GetPanelResourceURL( const size_t i_nPanelPos ) const
+ {
+ return m_pImpl->GetPanelResourceURL( i_nPanelPos );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void ModuleTaskPane::SetDrawersLayout()
+ {
+ m_pImpl->SetDrawersLayout();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void ModuleTaskPane::SetTabsLayout( const ::svt::TabAlignment i_eTabAlignment, const ::svt::TabItemContent i_eTabContent )
+ {
+ m_pImpl->SetTabsLayout( i_eTabAlignment, i_eTabContent );
+ }
+
+ // =====================================================================================================================
+ // = PanelSelectorLayout
+ // =====================================================================================================================
+ enum PanelSelectorLayout
+ {
+ LAYOUT_DRAWERS,
+ LAYOUT_TABS_RIGHT,
+ LAYOUT_TABS_LEFT,
+ LAYOUT_TABS_TOP,
+ LAYOUT_TABS_BOTTOM
+ };
+
+ //==================================================================================================================
+ //= helper
+ //==================================================================================================================
+ namespace
+ {
+ PanelSelectorLayout lcl_getTabLayoutFromAlignment( const SfxChildAlignment i_eAlignment )
+ {
+ switch ( i_eAlignment )
+ {
+ case SFX_ALIGN_LEFT:
+ return LAYOUT_TABS_LEFT;
+ case SFX_ALIGN_TOP:
+ return LAYOUT_TABS_TOP;
+ case SFX_ALIGN_BOTTOM:
+ return LAYOUT_TABS_BOTTOM;
+ default:
+ return LAYOUT_TABS_RIGHT;
+ }
+ }
+ }
+
+ // =====================================================================================================================
+ // = PanelDescriptor
+ // =====================================================================================================================
+ /** is a helper class for TaskPaneController_Impl, holding the details about a single panel which is not
+ contained in the IToolPanel implementation itself.
+ */
+ struct PanelDescriptor
+ {
+ ::svt::PToolPanel pPanel;
+ bool bHidden;
+
+ PanelDescriptor()
+ :pPanel()
+ ,bHidden( false )
+ {
+ }
+
+ PanelDescriptor( const ::svt::PToolPanel& i_rPanel )
+ :pPanel( i_rPanel )
+ ,bHidden( false )
+ {
+ }
+ };
+
+ //==================================================================================================================
+ //= TaskPaneController_Impl
+ //==================================================================================================================
+ class TaskPaneController_Impl :public ::boost::noncopyable
+ ,public ::svt::IToolPanelDeckListener
+ {
+ public:
+ TaskPaneController_Impl(
+ ModuleTaskPane& i_rTaskPane,
+ TitledDockingWindow& i_rDockingWindow
+ );
+ ~TaskPaneController_Impl();
+
+ void SetDefaultTitle( const String& i_rTitle );
+ void ActivateToolPanel( const ::rtl::OUString& i_rPanelURL );
+
+ protected:
+ // IToolPanelDeckListener overridables
+ virtual void PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition );
+ virtual void PanelRemoved( const size_t i_nPosition );
+ virtual void ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive );
+ virtual void LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter );
+ virtual void Dying();
+
+ private:
+ DECL_LINK( OnToolboxClicked, ToolBox* );
+ DECL_LINK( OnMenuItemSelected, Menu* );
+ DECL_LINK( DockingChanged, TitledDockingWindow* );
+ ::std::auto_ptr< PopupMenu > impl_createPopupMenu() const;
+
+ /// sets the given layout for the panel selector
+ void impl_setLayout( const PanelSelectorLayout i_eLayout, const bool i_bForce = false );
+
+ /// returns the current layout of the panel selector
+ PanelSelectorLayout
+ impl_getLayout() const { return m_eCurrentLayout; }
+
+ void impl_updateDockingWindowTitle();
+ void impl_togglePanelVisibility( const size_t i_nLogicalPanelIndex );
+ size_t impl_getLogicalPanelIndex( const size_t i_nVisibleIndex );
+
+ private:
+ enum MenuId
+ {
+ MID_UNLOCK_TASK_PANEL = 1,
+ MID_LOCK_TASK_PANEL = 2,
+ MID_LAYOUT_TABS = 3,
+ MID_LAYOUT_DRAWERS = 4,
+ MID_FIRST_PANEL = 5
+ };
+
+ private:
+ typedef ::std::vector< PanelDescriptor > PanelDescriptors;
+
+ ModuleTaskPane& m_rTaskPane;
+ TitledDockingWindow& m_rDockingWindow;
+ USHORT m_nViewMenuID;
+ PanelSelectorLayout m_eCurrentLayout;
+ PanelDescriptors m_aPanelRepository;
+ bool m_bTogglingPanelVisibility;
+ ::rtl::OUString m_sDefaultTitle;
+ };
+
+ //------------------------------------------------------------------------------------------------------------------
+ TaskPaneController_Impl::TaskPaneController_Impl( ModuleTaskPane& i_rTaskPane, TitledDockingWindow& i_rDockingWindow )
+ :m_rTaskPane( i_rTaskPane )
+ ,m_rDockingWindow( i_rDockingWindow )
+ ,m_nViewMenuID( 0 )
+ ,m_eCurrentLayout( LAYOUT_DRAWERS )
+ ,m_aPanelRepository()
+ ,m_bTogglingPanelVisibility( false )
+ ,m_sDefaultTitle()
+ {
+ m_rDockingWindow.ResetToolBox();
+ m_nViewMenuID = m_rDockingWindow.AddDropDownToolBoxItem(
+ String( SfxResId( STR_SFX_TASK_PANE_VIEW ) ),
+ HID_TASKPANE_VIEW_MENU,
+ LINK( this, TaskPaneController_Impl, OnToolboxClicked )
+ );
+ m_rDockingWindow.SetEndDockingHdl( LINK( this, TaskPaneController_Impl, DockingChanged ) );
+ impl_setLayout( LAYOUT_DRAWERS, true );
+
+ m_rTaskPane.GetPanelDeck().AddListener( *this );
+
+ // initialize the panel repository
+ for ( size_t i = 0; i < m_rTaskPane.GetPanelDeck().GetPanelCount(); ++i )
+ {
+ ::svt::PToolPanel pPanel( m_rTaskPane.GetPanelDeck().GetPanel( i ) );
+ m_aPanelRepository.push_back( PanelDescriptor( pPanel ) );
+ }
+
+ SetDefaultTitle( String( SfxResId( STR_SFX_TASKS ) ) );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ TaskPaneController_Impl::~TaskPaneController_Impl()
+ {
+ m_rTaskPane.GetPanelDeck().RemoveListener( *this );
+
+ // remove the panels which are not under the control of the panel deck currently
+ for ( PanelDescriptors::iterator panelPos = m_aPanelRepository.begin();
+ panelPos != m_aPanelRepository.end();
+ ++panelPos
+ )
+ {
+ if ( panelPos->bHidden )
+ panelPos->pPanel->Dispose();
+ }
+ m_aPanelRepository.clear();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ void TaskPaneController_Impl::SetDefaultTitle( const String& i_rTitle )
+ {
+ m_sDefaultTitle = i_rTitle;
+ impl_updateDockingWindowTitle();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController_Impl::ActivateToolPanel( const ::rtl::OUString& i_rPanelURL )
+ {
+ ::boost::optional< size_t > aPanelPos( m_rTaskPane.GetPanelPos( i_rPanelURL ) );
+ ENSURE_OR_RETURN_VOID( !!aPanelPos, "TaskPaneController_Impl::ActivateToolPanel: no such panel!" );
+
+ if ( aPanelPos == m_rTaskPane.GetPanelDeck().GetActivePanel() )
+ {
+ ::svt::PToolPanel pPanel( m_rTaskPane.GetPanelDeck().GetPanel( *aPanelPos ) );
+ pPanel->GrabFocus();
+ }
+ else
+ {
+ m_rTaskPane.GetPanelDeck().ActivatePanel( aPanelPos );
+ }
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ IMPL_LINK( TaskPaneController_Impl, DockingChanged, TitledDockingWindow*, i_pDockingWindow )
+ {
+ ENSURE_OR_RETURN( i_pDockingWindow && &m_rDockingWindow, "TaskPaneController_Impl::DockingChanged: where does this come from?", 0L );
+
+ if ( impl_getLayout() == LAYOUT_DRAWERS )
+ return 0L;
+
+ impl_setLayout( lcl_getTabLayoutFromAlignment( i_pDockingWindow->GetAlignment() ) );
+ return 1L;
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ IMPL_LINK( TaskPaneController_Impl, OnToolboxClicked, ToolBox*, i_pToolBox )
+ {
+ if ( i_pToolBox->GetCurItemId() == m_nViewMenuID )
+ {
+ i_pToolBox->EndSelection();
+
+ ::std::auto_ptr< PopupMenu > pMenu = impl_createPopupMenu();
+ pMenu->SetSelectHdl( LINK( this, TaskPaneController_Impl, OnMenuItemSelected ) );
+
+ // pass toolbox button rect so the menu can stay open on button up
+ Rectangle aMenuRect( i_pToolBox->GetItemRect( m_nViewMenuID ) );
+ aMenuRect.SetPos( i_pToolBox->GetPosPixel() );
+ pMenu->Execute( &m_rDockingWindow, aMenuRect, POPUPMENU_EXECUTE_DOWN );
+ }
+
+ return 0;
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ IMPL_LINK( TaskPaneController_Impl, OnMenuItemSelected, Menu*, i_pMenu )
+ {
+ ENSURE_OR_RETURN( i_pMenu, "TaskPaneController_Impl::OnMenuItemSelected: illegal menu!", 0L );
+
+ i_pMenu->Deactivate();
+ switch ( i_pMenu->GetCurItemId() )
+ {
+ case MID_UNLOCK_TASK_PANEL:
+ m_rDockingWindow.SetFloatingMode( TRUE );
+ break;
+
+ case MID_LOCK_TASK_PANEL:
+ m_rDockingWindow.SetFloatingMode( FALSE );
+ break;
+
+ case MID_LAYOUT_DRAWERS:
+ impl_setLayout( LAYOUT_DRAWERS );
+ break;
+
+ case MID_LAYOUT_TABS:
+ impl_setLayout( lcl_getTabLayoutFromAlignment( m_rDockingWindow.GetAlignment() ) );
+ break;
+
+ default:
+ {
+ size_t nPanelIndex = size_t( i_pMenu->GetCurItemId() - MID_FIRST_PANEL );
+ impl_togglePanelVisibility( nPanelIndex );
+ }
+ break;
+ }
+
+ return 1L;
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ size_t TaskPaneController_Impl::impl_getLogicalPanelIndex( const size_t i_nVisibleIndex )
+ {
+ size_t nLogicalIndex = 0;
+ size_t nVisibleIndex( i_nVisibleIndex );
+ for ( size_t i=0; i < m_aPanelRepository.size(); ++i )
+ {
+ if ( !m_aPanelRepository[i].bHidden )
+ {
+ if ( !nVisibleIndex )
+ break;
+ --nVisibleIndex;
+ }
+ ++nLogicalIndex;
+ }
+ return nLogicalIndex;
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController_Impl::PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition )
+ {
+ if ( m_bTogglingPanelVisibility )
+ return;
+
+ const size_t nLogicalIndex( impl_getLogicalPanelIndex( i_nPosition ) );
+ m_aPanelRepository.insert( m_aPanelRepository.begin() + nLogicalIndex, PanelDescriptor( i_pPanel ) );
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController_Impl::PanelRemoved( const size_t i_nPosition )
+ {
+ if ( m_bTogglingPanelVisibility )
+ return;
+
+ const size_t nLogicalIndex( impl_getLogicalPanelIndex( i_nPosition ) );
+ m_aPanelRepository.erase( m_aPanelRepository.begin() + nLogicalIndex );
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController_Impl::ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive )
+ {
+ if ( impl_getLayout() == LAYOUT_DRAWERS )
+ // no adjustment of the title when we use the classical "drawers" layout
+ return;
+
+ impl_updateDockingWindowTitle( );
+ (void)i_rOldActive;
+ (void)i_rNewActive;
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController_Impl::LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter )
+ {
+ // not interested in
+ (void)i_rNewLayouter;
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController_Impl::Dying()
+ {
+ OSL_ENSURE( false, "TaskPaneController_Impl::Dying: unexpected call!" );
+ // We are expected to live longer than the ToolPanelDeck we work with. Since we remove ourself, in our dtor,
+ // as listener from the panel deck, this method here should never be called.
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController_Impl::impl_togglePanelVisibility( const size_t i_nLogicalPanelIndex )
+ {
+ ENSURE_OR_RETURN_VOID( i_nLogicalPanelIndex < m_aPanelRepository.size(), "illegal index" );
+
+ // get the actual panel index, within the deck
+ size_t nActualPanelIndex(0);
+ for ( size_t i=0; i < i_nLogicalPanelIndex; ++i )
+ {
+ if ( !m_aPanelRepository[i].bHidden )
+ ++nActualPanelIndex;
+ }
+
+ ::boost::optional< size_t > aActivatePanel;
+
+ m_bTogglingPanelVisibility = true;
+ if ( m_aPanelRepository[ i_nLogicalPanelIndex ].bHidden )
+ {
+ OSL_VERIFY( m_rTaskPane.GetPanelDeck().InsertPanel( m_aPanelRepository[ i_nLogicalPanelIndex ].pPanel, nActualPanelIndex ) == nActualPanelIndex );
+ // if there has not been an active panel before, activate the newly inserted one
+ ::boost::optional< size_t > aActivePanel( m_rTaskPane.GetPanelDeck().GetActivePanel() );
+ if ( !aActivePanel )
+ aActivatePanel = nActualPanelIndex;
+ }
+ else
+ {
+ OSL_VERIFY( m_rTaskPane.GetPanelDeck().RemovePanel( nActualPanelIndex ).get() == m_aPanelRepository[ i_nLogicalPanelIndex ].pPanel.get() );
+ }
+ m_bTogglingPanelVisibility = false;
+ m_aPanelRepository[ i_nLogicalPanelIndex ].bHidden = !m_aPanelRepository[ i_nLogicalPanelIndex ].bHidden;
+
+ if ( !!aActivatePanel )
+ m_rTaskPane.GetPanelDeck().ActivatePanel( *aActivatePanel );
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController_Impl::impl_setLayout( const PanelSelectorLayout i_eLayout, const bool i_bForce )
+ {
+ if ( !i_bForce && ( m_eCurrentLayout == i_eLayout ) )
+ return;
+
+ switch ( i_eLayout )
+ {
+ case LAYOUT_DRAWERS:
+ m_rTaskPane.SetDrawersLayout();
+ break;
+ case LAYOUT_TABS_TOP:
+ m_rTaskPane.SetTabsLayout( ::svt::TABS_TOP, ::svt::TABITEM_IMAGE_ONLY );
+ break;
+ case LAYOUT_TABS_BOTTOM:
+ m_rTaskPane.SetTabsLayout( ::svt::TABS_BOTTOM, ::svt::TABITEM_IMAGE_ONLY );
+ break;
+ case LAYOUT_TABS_LEFT:
+ m_rTaskPane.SetTabsLayout( ::svt::TABS_LEFT, ::svt::TABITEM_IMAGE_ONLY );
+ break;
+ case LAYOUT_TABS_RIGHT:
+ m_rTaskPane.SetTabsLayout( ::svt::TABS_RIGHT, ::svt::TABITEM_IMAGE_ONLY );
+ break;
+ }
+ m_eCurrentLayout = i_eLayout;
+
+ impl_updateDockingWindowTitle();
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController_Impl::impl_updateDockingWindowTitle()
+ {
+ ::boost::optional< size_t > aActivePanel( m_rTaskPane.GetPanelDeck().GetActivePanel() );
+ if ( !aActivePanel || ( impl_getLayout() == LAYOUT_DRAWERS ) )
+ m_rDockingWindow.SetTitle( m_sDefaultTitle );
+ else
+ {
+ size_t nNewActive( *aActivePanel );
+ for ( size_t i=0; i < m_aPanelRepository.size(); ++i )
+ {
+ if ( m_aPanelRepository[i].bHidden )
+ continue;
+
+ if ( !nNewActive )
+ {
+ m_rDockingWindow.SetTitle( m_aPanelRepository[i].pPanel->GetDisplayName() );
+ break;
+ }
+ --nNewActive;
+ }
+ }
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------------
+ ::std::auto_ptr< PopupMenu > TaskPaneController_Impl::impl_createPopupMenu() const
+ {
+ ::std::auto_ptr<PopupMenu> pMenu( new PopupMenu );
+ FloatingWindow* pMenuWindow = static_cast< FloatingWindow* >( pMenu->GetWindow() );
+ if ( pMenuWindow != NULL )
+ {
+ pMenuWindow->SetPopupModeFlags ( pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE );
+ }
+
+ // Add one entry for every tool panel element to individually make
+ // them visible or hide them.
+ USHORT nIndex = MID_FIRST_PANEL;
+ for ( size_t i=0; i<m_aPanelRepository.size(); ++i, ++nIndex )
+ {
+ const PanelDescriptor& rPanelDesc( m_aPanelRepository[i] );
+ pMenu->InsertItem( nIndex, rPanelDesc.pPanel->GetDisplayName(), MIB_CHECKABLE );
+ pMenu->CheckItem( nIndex, !rPanelDesc.bHidden );
+ }
+ pMenu->InsertSeparator();
+
+ #if OSL_DEBUG_LEVEL > 0
+ pMenu->InsertItem( MID_LAYOUT_TABS, String::CreateFromAscii( "Tab-Layout (exp.)" ), MIB_CHECKABLE );
+ pMenu->CheckItem( MID_LAYOUT_TABS, impl_getLayout() != LAYOUT_DRAWERS );
+ pMenu->InsertItem( MID_LAYOUT_DRAWERS, String::CreateFromAscii( "Drawer-Layout" ), MIB_CHECKABLE );
+ pMenu->CheckItem( MID_LAYOUT_DRAWERS, impl_getLayout() == LAYOUT_DRAWERS );
+
+ pMenu->InsertSeparator();
+ #endif
+
+ // Add entry for docking or un-docking the tool panel.
+ if ( m_rDockingWindow.IsFloatingMode() )
+ pMenu->InsertItem(
+ MID_LOCK_TASK_PANEL,
+ String( SfxResId( STR_SFX_DOCK ) )
+ );
+ else
+ pMenu->InsertItem(
+ MID_UNLOCK_TASK_PANEL,
+ String( SfxResId( STR_SFX_UNDOCK ) )
+ );
+
+ pMenu->RemoveDisabledEntries( FALSE, FALSE );
+
+ return pMenu;
+ }
+
+ //==================================================================================================================
+ //= TaskPaneController
+ //==================================================================================================================
+ //------------------------------------------------------------------------------------------------------------------
+ TaskPaneController::TaskPaneController( ModuleTaskPane& i_rTaskPane, TitledDockingWindow& i_rDockingWindow )
+ :m_pImpl( new TaskPaneController_Impl( i_rTaskPane, i_rDockingWindow ) )
+ {
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ TaskPaneController::~TaskPaneController()
+ {
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController::SetDefaultTitle( const String& i_rTitle )
+ {
+ m_pImpl->SetDefaultTitle( i_rTitle );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TaskPaneController::ActivateToolPanel( const ::rtl::OUString& i_rPanelURL )
+ {
+ m_pImpl->ActivateToolPanel( i_rPanelURL );
+ }
+
+//......................................................................................................................
+} // namespace sfx2
+//......................................................................................................................
diff --git a/sfx2/source/dialog/taskpane.src b/sfx2/source/dialog/taskpane.src
new file mode 100644
index 000000000000..5a955e8587d1
--- /dev/null
+++ b/sfx2/source/dialog/taskpane.src
@@ -0,0 +1,47 @@
+/*************************************************************************
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <sfx2/sfx.hrc>
+#include "sfxlocal.hrc"
+
+String STR_SFX_DOCK
+{
+ Text [ en-US ] = "Dock";
+};
+
+String STR_SFX_UNDOCK
+{
+ Text [ en-US ] = "Undock";
+};
+
+String STR_SFX_TASK_PANE_VIEW
+{
+ Text [ en-US ] = "View";
+};
+String STR_SFX_TASKS
+{
+ Text [ en-US ] = "Tasks";
+};
diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx
new file mode 100644
index 000000000000..b10e634be231
--- /dev/null
+++ b/sfx2/source/dialog/templdlg.cxx
@@ -0,0 +1,3039 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef _MENU_HXX //autogen
+#include <vcl/menu.hxx>
+#endif
+#include <svl/intitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/style.hxx>
+#ifndef GCC
+#endif
+
+#define _SVSTDARR_STRINGSDTOR
+#include <svl/svstdarr.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <unotools/intlwrapper.hxx>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+
+#include "sfx2/sfxhelp.hxx"
+#include <sfx2/app.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/templdlg.hxx>
+#include "templdgi.hxx"
+#include "tplcitem.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/styfitem.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/newstyle.hxx>
+#include "sfx2/tplpitem.hxx"
+#include "sfx2/sfxresid.hxx"
+
+#include "templdlg.hrc"
+#include <sfx2/sfx.hrc>
+#include "dialog.hrc"
+#include "arrdecl.hxx"
+#include "fltfnc.hxx"
+#include <sfx2/docfilt.hxx>
+#include <sfx2/docfac.hxx>
+#include "docvor.hxx"
+#include <sfx2/doctempl.hxx>
+#include <sfx2/module.hxx>
+#include "sfx2/imgmgr.hxx"
+#include "helpid.hrc"
+#include "appdata.hxx"
+#include <sfx2/viewfrm.hxx>
+
+#include <comphelper/configurationhelper.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::uno;
+
+//=========================================================================
+
+// Fenster wird ab jetzt dynamisch erstellt. Daher hier R"ander usw.
+
+#define SFX_TEMPLDLG_HFRAME 3
+#define SFX_TEMPLDLG_VTOPFRAME 3
+
+#define SFX_TEMPLDLG_VBOTFRAME 3
+#define SFX_TEMPLDLG_MIDHSPACE 3
+#define SFX_TEMPLDLG_MIDVSPACE 3
+#define SFX_TEMPLDLG_FILTERHEIGHT 100
+
+static USHORT nLastItemId = USHRT_MAX;
+
+// filter box has maximum 12 entries visible
+#define MAX_FILTER_ENTRIES 12
+
+//=========================================================================
+
+TYPEINIT0(SfxCommonTemplateDialog_Impl);
+TYPEINIT1(SfxTemplateDialog_Impl,SfxCommonTemplateDialog_Impl);
+TYPEINIT1(SfxTemplateCatalog_Impl,SfxCommonTemplateDialog_Impl);
+
+SFX_IMPL_DOCKINGWINDOW(SfxTemplateDialogWrapper, SID_STYLE_DESIGNER)
+
+//-------------------------------------------------------------------------
+
+// Redirektionsfunktionen
+
+SfxTemplateDialog::SfxTemplateDialog
+(
+ SfxBindings *pBind,
+ SfxChildWindow *pCW,
+ Window *pParent
+)
+
+/* [Beschreibung]
+ Gestalterklasse.
+*/
+ : SfxDockingWindow( pBind, pCW, pParent, SfxResId(DLG_STYLE_DESIGNER) ),
+
+ pImpl( new SfxTemplateDialog_Impl( pParent, pBind, this ) )
+
+{
+ pImpl->updateNonFamilyImages();
+}
+
+//-------------------------------------------------------------------------
+
+SfxTemplateDialog::~SfxTemplateDialog()
+{
+ delete pImpl;
+}
+
+ISfxTemplateCommon* SfxTemplateDialog::GetISfxTemplateCommon()
+{
+ return pImpl->GetISfxTemplateCommon();
+}
+
+void SfxTemplateDialog::SetParagraphFamily()
+{
+ // first select the paragraph family
+ pImpl->FamilySelect( SFX_STYLE_FAMILY_PARA );
+ // then select the automatic filter
+ pImpl->SetAutomaticFilter();
+}
+
+// ------------------------------------------------------------------------
+
+void SfxTemplateDialog::DataChanged( const DataChangedEvent& _rDCEvt )
+{
+ if ( ( DATACHANGED_SETTINGS == _rDCEvt.GetType() ) &&
+ ( 0 != ( SETTINGS_STYLE & _rDCEvt.GetFlags() ) ) )
+ {
+ pImpl->updateFamilyImages();
+ pImpl->updateNonFamilyImages();
+ }
+
+ SfxDockingWindow::DataChanged( _rDCEvt );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateDialog::Update()
+{
+ pImpl->Update();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateDialog::Resize()
+{
+ if(pImpl)
+ pImpl->Resize();
+ SfxDockingWindow::Resize();
+}
+
+
+//-------------------------------------------------------------------------
+
+SfxChildAlignment SfxTemplateDialog::CheckAlignment(SfxChildAlignment eActAlign,SfxChildAlignment eAlign)
+{
+ switch (eAlign)
+ {
+ case SFX_ALIGN_TOP:
+ case SFX_ALIGN_HIGHESTTOP:
+ case SFX_ALIGN_LOWESTTOP:
+ case SFX_ALIGN_BOTTOM:
+ case SFX_ALIGN_LOWESTBOTTOM:
+ case SFX_ALIGN_HIGHESTBOTTOM:
+ return eActAlign;
+
+ case SFX_ALIGN_LEFT:
+ case SFX_ALIGN_RIGHT:
+ case SFX_ALIGN_FIRSTLEFT:
+ case SFX_ALIGN_LASTLEFT:
+ case SFX_ALIGN_FIRSTRIGHT:
+ case SFX_ALIGN_LASTRIGHT:
+ return eAlign;
+
+ default:
+ return eAlign;
+ }
+}
+
+//-------------------------------------------------------------------------
+
+SfxTemplateCatalog::SfxTemplateCatalog(Window *pParent, SfxBindings *pBindings)
+ : SfxModalDialog(pParent,SfxResId(RID_STYLECATALOG))
+{
+ pImpl = new SfxTemplateCatalog_Impl(pParent, pBindings, this);
+}
+
+//-------------------------------------------------------------------------
+
+SfxTemplateCatalog::~SfxTemplateCatalog()
+{
+ delete pImpl;
+}
+
+//-------------------------------------------------------------------------
+
+void DropListBox_Impl::MouseButtonDown( const MouseEvent& rMEvt )
+{
+ nModifier = rMEvt.GetModifier();
+
+ BOOL bHitEmptySpace = ( NULL == GetEntry( rMEvt.GetPosPixel(), TRUE ) );
+ if( bHitEmptySpace && ( rMEvt.GetClicks() == 2 ) && rMEvt.IsMod1() )
+ Control::MouseButtonDown( rMEvt );
+ else
+ SvTreeListBox::MouseButtonDown( rMEvt );
+}
+
+sal_Int8 DropListBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
+
+/* [Description: ]
+ Drop is enabled as long as it is allowed to create a new style by example, i.e. to
+ create a style out of the current selection.
+*/
+
+{
+ if ( IsDropFormatSupported( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
+ {
+ // special case: page styles are allowed to create new styles by example
+ // but not allowed to be created by drag and drop
+ if( pDialog->nActFamily == SfxCommonTemplateDialog_Impl::SfxFamilyIdToNId( SFX_STYLE_FAMILY_PAGE ) ||
+ pDialog->bNewByExampleDisabled )
+ return DND_ACTION_NONE;
+ else
+ return DND_ACTION_COPY;
+ }
+ return SvTreeListBox::AcceptDrop( rEvt );
+}
+
+//-------------------------------------------------------------------------
+
+sal_Int8 DropListBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
+{
+// rEvt.maDropEvent.Context->acceptDrop( DND_ACTION_NONE );
+// rEvt.maDropEvent.Context->dropComplete( TRUE );
+
+ sal_Int8 nRet = DND_ACTION_NONE;
+ SfxObjectShell* pDocShell = pDialog->GetObjectShell();
+ TransferableDataHelper aHelper( rEvt.maDropEvent.Transferable );
+ sal_uInt32 nFormatCount = aHelper.GetFormatCount();
+ if ( pDocShell )
+ {
+ sal_Bool bFormatFound = sal_False;
+
+ for ( sal_uInt32 i = 0; i < nFormatCount; ++i )
+ {
+ SotFormatStringId nId = aHelper.GetFormat(i);
+ TransferableObjectDescriptor aDesc;
+
+ if ( aHelper.GetTransferableObjectDescriptor( nId, aDesc ) )
+ {
+ if ( aDesc.maClassName == pDocShell->GetFactory().GetClassId() )
+ {
+ PostUserEvent( LINK( this, DropListBox_Impl, OnAsyncExecuteDrop ), 0 );
+
+ bFormatFound = sal_True;
+ nRet = rEvt.mnAction;
+ break;
+ }
+ }
+ }
+
+ if ( !bFormatFound )
+ return SvTreeListBox::ExecuteDrop( rEvt );
+ }
+
+ return nRet;
+}
+
+
+IMPL_LINK( DropListBox_Impl, OnAsyncExecuteDrop, SvLBoxEntry*, EMPTYARG )
+{
+ pDialog->ActionSelect( SID_STYLE_NEW_BY_EXAMPLE );
+ return 0;
+}
+
+
+IMPL_LINK( DropListBox_Impl, OnAsyncExecuteError, void*, NOTINTERESTEDIN )
+{
+ (void)NOTINTERESTEDIN; // unused
+ ErrorHandler::HandleError( ERRCODE_IO_WRONGFORMAT );
+
+ return 0;
+}
+
+
+long DropListBox_Impl::Notify( NotifyEvent& rNEvt )
+{
+ long nRet = 0;
+ if( rNEvt.GetType() == EVENT_KEYINPUT )
+ {
+ const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
+ if(!rKeyCode.GetModifier())
+ {
+ if( pDialog->bCanDel && KEY_DELETE == rKeyCode.GetCode())
+ {
+ pDialog->DeleteHdl( NULL );
+ nRet = 1;
+ }
+ else if( KEY_RETURN == rKeyCode.GetCode())
+ {
+ GetDoubleClickHdl().Call(this);
+ nRet = 1;
+ }
+ }
+ }
+ if(!nRet)
+ nRet = SvTreeListBox::Notify( rNEvt );
+ return nRet;
+}
+
+
+//-------------------------------------------------------------------------
+
+
+SfxActionListBox::SfxActionListBox
+(
+ SfxCommonTemplateDialog_Impl* pParent,
+ WinBits nWinBits
+)
+
+/* [Beschreibung]
+
+ ListBox- Klasse, die im Command-Handler ein PopupMenu (Gestalter
+ spezifisch) startet.
+
+*/
+
+: DropListBox_Impl(pParent->GetWindow(), nWinBits, pParent)
+
+{
+ EnableContextMenuHandling();
+}
+
+//-------------------------------------------------------------------------
+
+SfxActionListBox::SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent,
+ const ResId &rResId) :
+ DropListBox_Impl(pParent->GetWindow(), rResId, pParent)
+{
+ EnableContextMenuHandling();
+}
+
+//-------------------------------------------------------------------------
+
+PopupMenu* SfxActionListBox::CreateContextMenu( void )
+{
+ //added by BerryJia for fixing Bug102739 2002-9-9 17:00(Beijing Time)
+ if( !( GetSelectionCount() > 0 ) )
+ {
+ pDialog->EnableEdit( FALSE );
+ pDialog->EnableDel( FALSE );
+ }
+ return pDialog->CreateContextMenu();
+}
+
+//-------------------------------------------------------------------------
+
+SfxTemplateDialogWrapper::SfxTemplateDialogWrapper(Window *pParentWnd,
+ USHORT nId, SfxBindings *p, SfxChildWinInfo *pInfo) :
+ SfxChildWindow(pParentWnd, nId)
+{
+ SfxTemplateDialog *pWin = new SfxTemplateDialog(p, this, pParentWnd);
+ pWindow = pWin;
+ eChildAlignment = SFX_ALIGN_NOALIGNMENT;
+
+ pWin->Initialize( pInfo );
+ pWin->SetMinOutputSizePixel(pWin->pImpl->GetMinOutputSizePixel());
+}
+
+void SfxTemplateDialogWrapper::SetParagraphFamily()
+{
+ // forward to SfxTemplateDialog, because SfxTemplateDialog isn't exported
+ static_cast< SfxTemplateDialog* >( GetWindow() )->SetParagraphFamily();
+}
+
+//=========================================================================
+SV_DECL_PTRARR_DEL(ExpandedEntries, StringPtr,16,8)
+SV_IMPL_PTRARR(ExpandedEntries, StringPtr)
+
+/* [Beschreibung]
+
+ TreeListBox- Klasse f"ur die Anzeige der hierarchischen View
+ der Vorlagen
+
+*/
+
+class StyleTreeListBox_Impl : public DropListBox_Impl
+{
+private:
+ SvLBoxEntry* pCurEntry;
+ SfxCommonTemplateDialog_Impl* pCommon;
+ Link aDoubleClickLink;
+ Link aDropLink;
+ String aParent;
+ String aStyle;
+
+protected:
+ virtual void Command( const CommandEvent& rMEvt );
+ virtual long Notify( NotifyEvent& rNEvt );
+ virtual BOOL DoubleClickHdl();
+ virtual long ExpandingHdl();
+ virtual void ExpandedHdl();
+ virtual BOOL NotifyMoving(SvLBoxEntry* pTarget,
+ SvLBoxEntry* pEntry,
+ SvLBoxEntry*& rpNewParent,
+ ULONG& rNewChildPos);
+public:
+ StyleTreeListBox_Impl( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinStyle = 0);
+
+ void SetDoubleClickHdl(const Link &rLink) { aDoubleClickLink = rLink; }
+ void SetDropHdl(const Link &rLink) { aDropLink = rLink; }
+ using SvLBox::GetParent;
+ const String& GetParent() const { return aParent; }
+ const String& GetStyle() const { return aStyle; }
+ void MakeExpanded_Impl(ExpandedEntries& rEntries) const;
+
+ virtual PopupMenu* CreateContextMenu( void );
+};
+
+//-------------------------------------------------------------------------
+
+
+void StyleTreeListBox_Impl::MakeExpanded_Impl(ExpandedEntries& rEntries) const
+{
+ SvLBoxEntry *pEntry;
+ USHORT nCount=0;
+ for(pEntry=(SvLBoxEntry*)FirstVisible();pEntry;pEntry=(SvLBoxEntry*)NextVisible(pEntry))
+ {
+ if(IsExpanded(pEntry))
+ {
+ StringPtr pString=new String(GetEntryText(pEntry));
+ rEntries.Insert(pString,nCount++);
+ }
+ }
+}
+
+PopupMenu* StyleTreeListBox_Impl::CreateContextMenu()
+{
+ return pDialog->CreateContextMenu();
+}
+
+BOOL StyleTreeListBox_Impl::DoubleClickHdl()
+
+/* [Beschreibung]
+
+
+ DoubleClick-Handler; ruft entsprechenden Link.
+ Virtuelle Methode aus SV.
+
+*/
+{
+ aDoubleClickLink.Call(this);
+ return FALSE;
+}
+
+//-------------------------------------------------------------------------
+
+void StyleTreeListBox_Impl::Command( const CommandEvent& rCEvt )
+
+/* [Beschreibung]
+
+ Command Handler; dieser executed ein PopupMenu (Gestalter
+ spezifisch).
+ Virtuelle Methode aus SV.
+
+*/
+{
+ SvTreeListBox::Command(rCEvt);
+}
+
+//-------------------------------------------------------------------------
+
+long StyleTreeListBox_Impl::Notify( NotifyEvent& rNEvt )
+{
+ // handle <RETURN> as double click
+
+ long nRet = 0;
+ if ( rNEvt.GetType() == EVENT_KEYINPUT )
+ {
+ const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
+ if ( !rKeyCode.GetModifier() && KEY_RETURN == rKeyCode.GetCode() )
+ {
+ aDoubleClickLink.Call( this );
+ nRet = 1;
+ }
+ }
+
+ if ( !nRet )
+ nRet = DropListBox_Impl::Notify( rNEvt );
+
+ return nRet;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL StyleTreeListBox_Impl::NotifyMoving(SvLBoxEntry* pTarget,
+ SvLBoxEntry* pEntry,
+ SvLBoxEntry*& rpNewParent,
+ ULONG& lPos)
+/* [Beschreibung]
+
+ NotifyMoving Handler; dieser leitet per Link das Event an den Dialog
+ weiter.
+ Virtuelle Methode aus SV.
+
+*/
+{
+ if(!pTarget || !pEntry)
+ return FALSE;
+ aParent = GetEntryText(pTarget);
+ aStyle = GetEntryText(pEntry);
+ const BOOL bRet = (BOOL)aDropLink.Call(this);
+ rpNewParent = pTarget;
+ lPos=0;
+ IntlWrapper aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ const CollatorWrapper* pCollator = aIntlWrapper.getCaseCollator();
+ for(SvLBoxEntry *pTmpEntry=FirstChild(pTarget);
+ pTmpEntry && COMPARE_LESS==pCollator->compareString(
+ GetEntryText(pTmpEntry),GetEntryText(pEntry));
+ pTmpEntry=NextSibling(pTmpEntry),lPos++) ;
+
+ return bRet? (BOOL)2: FALSE;
+}
+
+//-------------------------------------------------------------------------
+
+long StyleTreeListBox_Impl::ExpandingHdl()
+
+/* [Beschreibung]
+
+ ExpandingHdl Handler; der aktuelle Eintrag wird gemerkt.
+ Virtuelle Methode aus SV.
+
+ [Querverweise]
+ <StyleTreeListBox_Impl::ExpandedHdl()>
+
+*/
+{
+ pCurEntry = GetCurEntry();
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+void StyleTreeListBox_Impl::ExpandedHdl()
+
+/* [Beschreibung]
+
+ ExpandedHdl Handler;
+ Virtuelle Methode aus SV.
+
+ [Querverweise]
+ <StyleTreeListBox_Impl::ExpandingHdl()>
+
+*/
+
+{
+ SvLBoxEntry *pEntry = GetHdlEntry();
+ if(!IsExpanded(pEntry) && pCurEntry != GetCurEntry())
+ SelectAll( FALSE );
+ pCurEntry = 0;
+}
+
+//-------------------------------------------------------------------------
+
+StyleTreeListBox_Impl::StyleTreeListBox_Impl(
+ SfxCommonTemplateDialog_Impl* pParent, WinBits nWinStyle) :
+ DropListBox_Impl(pParent->GetWindow(), nWinStyle, pParent),
+ pCurEntry(0),
+ pCommon(pParent)
+
+/* [Beschreibung]
+
+ Konstruktor StyleTreeListBox_Impl
+
+*/
+{
+ EnableContextMenuHandling();
+}
+
+//-------------------------------------------------------------------------
+//-------------------------------------------------------------------------
+
+class StyleTreeArr_Impl;
+
+
+/* [Beschreibung]
+
+ Interne Struktur f"ur den Aufbau der hierarchischen View
+
+*/
+
+struct StyleTree_Impl
+{
+ String aName;
+ String aParent;
+ StyleTreeArr_Impl *pChilds;
+ BOOL bIsExpanded;
+ BOOL HasParent() const { return aParent.Len() != 0; }
+
+ StyleTree_Impl(const String &rName, const String &rParent):
+ aName(rName), aParent(rParent), pChilds(0), bIsExpanded(0) {}
+ ~StyleTree_Impl();
+ void Put(StyleTree_Impl* pIns, ULONG lPos=ULONG_MAX);
+ ULONG Count();
+};
+
+typedef StyleTree_Impl* StyleTree_ImplPtr;
+SV_DECL_PTRARR_DEL(StyleTreeArr_Impl, StyleTree_ImplPtr, 16, 8)
+SV_IMPL_PTRARR(StyleTreeArr_Impl, StyleTree_ImplPtr)
+
+
+ULONG StyleTree_Impl::Count()
+{
+ return pChilds ? pChilds->Count() : 0L;
+}
+
+//-------------------------------------------------------------------------
+
+StyleTree_Impl::~StyleTree_Impl()
+{
+ delete pChilds;
+}
+
+//-------------------------------------------------------------------------
+
+void StyleTree_Impl::Put(StyleTree_Impl* pIns, ULONG lPos)
+{
+ if ( !pChilds )
+ pChilds = new StyleTreeArr_Impl;
+
+ if ( ULONG_MAX == lPos )
+ lPos = pChilds->Count();
+ pChilds->Insert( pIns, (USHORT)lPos );
+}
+
+//-------------------------------------------------------------------------
+
+StyleTreeArr_Impl &MakeTree_Impl(StyleTreeArr_Impl &rArr)
+{
+ const USHORT nCount = rArr.Count();
+ // Alle unter ihren Parents einordnen
+ USHORT i;
+ for(i = 0; i < nCount; ++i)
+ {
+ StyleTree_ImplPtr pEntry = rArr[i];
+ if(pEntry->HasParent())
+ {
+ for(USHORT j = 0; j < nCount; ++j)
+ {
+ StyleTree_ImplPtr pCmp = rArr[j];
+ if(pCmp->aName == pEntry->aParent)
+ {
+ // initial sortiert einfuegen
+ USHORT ii;
+ IntlWrapper aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ const CollatorWrapper* pCollator = aIntlWrapper.getCaseCollator();
+ for ( ii = 0;
+ ii < pCmp->Count() && COMPARE_LESS ==
+ pCollator->compareString( (*pCmp->pChilds)[ii]->aName,
+ pEntry->aName);++ii) ;
+ pCmp->Put(pEntry,ii);
+ break;
+ }
+ }
+ }
+ }
+ // alle, die schon unter ihrem Parent eingeordnet wurden
+ // entfernen
+ for(i = 0; i < rArr.Count(); )
+ {
+ if(rArr[i]->HasParent())
+ rArr.Remove(i);
+ else
+ ++i;
+ }
+ return rArr;
+}
+
+//-------------------------------------------------------------------------
+
+
+inline BOOL IsExpanded_Impl( const ExpandedEntries& rEntries,
+ const String &rStr)
+{
+ USHORT nCount=rEntries.Count();
+ for(USHORT n=0;n<nCount;n++)
+ if(*rEntries[n]==rStr)
+ return TRUE;
+ return FALSE;
+}
+
+
+
+SvLBoxEntry* FillBox_Impl(SvTreeListBox *pBox,
+ StyleTree_ImplPtr pEntry,
+ const ExpandedEntries& rEntries,
+ SvLBoxEntry* pParent = 0)
+{
+ SvLBoxEntry* pNewEntry = pBox->InsertEntry(pEntry->aName, pParent);
+ const USHORT nCount = pEntry->pChilds? pEntry->pChilds->Count(): 0;
+ for(USHORT i = 0; i < nCount; ++i)
+ FillBox_Impl(pBox, (*pEntry->pChilds)[i], rEntries, pNewEntry);
+ return pNewEntry;
+}
+
+//-------------------------------------------------------------------------
+
+// Konstruktor
+
+SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, SfxDockingWindow* pW ) :
+
+ aISfxTemplateCommon ( this ),
+ pBindings ( pB ),
+ pWindow ( pW ),
+ pModule ( NULL ),
+ pTimer ( NULL ),
+ m_pStyleFamiliesId ( NULL ),
+ pStyleSheetPool ( NULL ),
+ pTreeBox ( NULL ),
+ pCurObjShell ( NULL ),
+ xModuleManager ( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.ModuleManager") ), UNO_QUERY ),
+ pbDeleted ( NULL ),
+
+ aFmtLb ( this, WB_BORDER | WB_TABSTOP | WB_SORT | WB_QUICK_SEARCH ),
+ aFilterLb ( pW, WB_BORDER | WB_DROPDOWN | WB_TABSTOP ),
+
+ nActFamily ( 0xffff ),
+ nActFilter ( 0 ),
+ nAppFilter ( 0 ),
+
+ bDontUpdate ( FALSE ),
+ bIsWater ( FALSE ),
+ bEnabled ( TRUE ),
+ bUpdate ( FALSE ),
+ bUpdateFamily ( FALSE ),
+ bCanEdit ( FALSE ),
+ bCanDel ( FALSE ),
+ bCanNew ( TRUE ),
+ bWaterDisabled ( FALSE ),
+ bNewByExampleDisabled ( FALSE ),
+ bUpdateByExampleDisabled( FALSE ),
+ bTreeDrag ( TRUE ),
+ bHierarchical ( FALSE ),
+ bBindingUpdate ( TRUE )
+{
+ aFmtLb.SetHelpId( HID_TEMPLATE_FMT );
+ aFilterLb.SetHelpId( HID_TEMPLATE_FILTER );
+ aFmtLb.SetStyle( aFmtLb.GetStyle() | WB_SORT | WB_HIDESELECTION );
+ Font aFont = aFmtLb.GetFont();
+ aFont.SetWeight( WEIGHT_NORMAL );
+ aFmtLb.SetFont( aFont );
+}
+
+//-------------------------------------------------------------------------
+
+SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, ModalDialog* pW ) :
+
+ aISfxTemplateCommon ( this ),
+ pBindings ( pB ),
+ pWindow ( pW ),
+ pModule ( NULL ),
+ pTimer ( NULL ),
+ pStyleSheetPool ( NULL ),
+ pTreeBox ( NULL ),
+ pCurObjShell ( NULL ),
+ pbDeleted ( NULL ),
+
+ aFmtLb ( this, SfxResId( BT_VLIST ) ),
+ aFilterLb ( pW, SfxResId( BT_FLIST ) ),
+
+ nActFamily ( 0xffff ),
+ nActFilter ( 0 ),
+ nAppFilter ( 0 ),
+
+ bDontUpdate ( FALSE ),
+ bIsWater ( FALSE ),
+ bEnabled ( TRUE ),
+ bUpdate ( FALSE ),
+ bUpdateFamily ( FALSE ),
+ bCanEdit ( FALSE ),
+ bCanDel ( FALSE ),
+ bCanNew ( TRUE ),
+ bWaterDisabled ( FALSE ),
+ bNewByExampleDisabled ( FALSE ),
+ bUpdateByExampleDisabled( FALSE ),
+ bTreeDrag ( TRUE ),
+ bHierarchical ( FALSE ),
+ bBindingUpdate ( TRUE )
+
+{
+ aFmtLb.SetStyle( aFmtLb.GetStyle() | WB_SORT );
+}
+
+//-------------------------------------------------------------------------
+
+USHORT SfxCommonTemplateDialog_Impl::StyleNrToInfoOffset(USHORT nId)
+{
+ const SfxStyleFamilyItem *pItem=pStyleFamilies->GetObject(nId);
+ return SfxFamilyIdToNId(pItem->GetFamily())-1;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateDialog_Impl::EnableEdit(BOOL bEnable)
+{
+ SfxCommonTemplateDialog_Impl::EnableEdit( bEnable );
+ if( !bEnable || !bUpdateByExampleDisabled )
+ EnableItem( SID_STYLE_UPDATE_BY_EXAMPLE, bEnable);
+}
+
+//-------------------------------------------------------------------------
+
+
+USHORT SfxCommonTemplateDialog_Impl::InfoOffsetToStyleNr(USHORT nId)
+{
+ for ( USHORT i=0;i<pStyleFamilies->Count();i++ )
+ if ( SfxFamilyIdToNId(pStyleFamilies->GetObject(i)->GetFamily()) == nId+1 )
+ return i;
+ DBG_ERROR("Style Nummer nicht gefunden");
+ return 0;
+}
+
+
+//-------------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::ReadResource()
+{
+ // globale Benutzer-Resource auslesen
+ USHORT i;
+ for(i = 0; i < MAX_FAMILIES; ++i)
+ pFamilyState[i] = 0;
+
+ SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
+ pCurObjShell = pViewFrame->GetObjectShell();
+ ResMgr* pMgr = pCurObjShell ? pCurObjShell->GetResMgr() : NULL;
+ ResId aFamId( DLG_STYLE_DESIGNER, *pMgr );
+ aFamId.SetRT(RSC_SFX_STYLE_FAMILIES);
+ m_pStyleFamiliesId = new ResId( aFamId.GetId(), *pMgr );
+ m_pStyleFamiliesId->SetRT(RSC_SFX_STYLE_FAMILIES);
+ if( !pMgr || !pMgr->IsAvailable( aFamId ) )
+ pStyleFamilies = new SfxStyleFamilies;
+ else
+ pStyleFamilies = new SfxStyleFamilies( aFamId );
+
+ nActFilter = pCurObjShell ? static_cast< USHORT >( LoadFactoryStyleFilter( pCurObjShell ) ) : 0xFFFF;
+ if ( pCurObjShell && 0xFFFF == nActFilter )
+ nActFilter = pCurObjShell->GetAutoStyleFilterIndex();
+
+ // Einfuegen in die Toolbox
+ // umgekehrte Reihenfolge, da immer vorne eingefuegt wird.
+ USHORT nCount = pStyleFamilies->Count();
+
+ pBindings->ENTERREGISTRATIONS();
+
+ for(i = 0; i < nCount; ++i)
+ {
+ USHORT nSlot = 0;
+ switch((USHORT)pStyleFamilies->GetObject(i)->GetFamily())
+ {
+ case SFX_STYLE_FAMILY_CHAR: nSlot = SID_STYLE_FAMILY1; break;
+ case SFX_STYLE_FAMILY_PARA: nSlot = SID_STYLE_FAMILY2; break;
+ case SFX_STYLE_FAMILY_FRAME:nSlot = SID_STYLE_FAMILY3; break;
+ case SFX_STYLE_FAMILY_PAGE: nSlot = SID_STYLE_FAMILY4; break;
+ case SFX_STYLE_FAMILY_PSEUDO: nSlot = SID_STYLE_FAMILY5; break;
+ default: DBG_ERROR("unbekannte StyleFamily"); break;
+ }
+ pBoundItems[i] =
+ new SfxTemplateControllerItem(nSlot, *this, *pBindings);
+ }
+ pBoundItems[i++] = new SfxTemplateControllerItem(
+ SID_STYLE_WATERCAN, *this, *pBindings);
+ pBoundItems[i++] = new SfxTemplateControllerItem(
+ SID_STYLE_NEW_BY_EXAMPLE, *this, *pBindings);
+ pBoundItems[i++] = new SfxTemplateControllerItem(
+ SID_STYLE_UPDATE_BY_EXAMPLE, *this, *pBindings);
+ pBoundItems[i++] = new SfxTemplateControllerItem(
+ SID_STYLE_NEW, *this, *pBindings);
+ pBoundItems[i++] = new SfxTemplateControllerItem(
+ SID_STYLE_DRAGHIERARCHIE, *this, *pBindings);
+ pBoundItems[i++] = new SfxTemplateControllerItem(
+ SID_STYLE_EDIT, *this, *pBindings);
+ pBoundItems[i++] = new SfxTemplateControllerItem(
+ SID_STYLE_DELETE, *this, *pBindings);
+ pBoundItems[i++] = new SfxTemplateControllerItem(
+ SID_STYLE_FAMILY, *this, *pBindings);
+ pBindings->LEAVEREGISTRATIONS();
+
+ for(; i < COUNT_BOUND_FUNC; ++i)
+ pBoundItems[i] = 0;
+
+ StartListening(*pBindings);
+
+//In umgekehrter Reihenfolge des Auftretens in den Stylefamilies einfuegen.
+//Das ist fuer den Toolbar des Gestalters. Die Listbox des Kataloges achtet
+//selbst auf korrekte Reihenfolge.
+
+//Reihenfolgen: Reihenfolge in der Resource = Reihenfolge in Toolbar bzw.
+//Listbox.
+//Reihenfolge aufsteigender SIDs: Niedrige SIDs werden als erstes angezeigt,
+//wenn Vorlagen mehrerer Familien aktiv sind.
+
+ // in the Writer the UpdateStyleByExample Toolbox button is removed and
+ // the NewStyle button gets a PopupMenu
+ if(nCount > 4)
+ ReplaceUpdateButtonByMenu();
+
+ for( ; nCount--; )
+ {
+ const SfxStyleFamilyItem *pItem = pStyleFamilies->GetObject( nCount );
+ USHORT nId = SfxFamilyIdToNId( pItem->GetFamily() );
+ InsertFamilyItem( nId, pItem );
+ }
+
+ LoadedFamilies();
+
+ USHORT nStart = SID_STYLE_FAMILY1;
+ USHORT nEnd = SID_STYLE_FAMILY4;
+
+ for ( i = nStart; i <= nEnd; i++ )
+ pBindings->Update(i);
+
+ pModule = pCurObjShell ? pCurObjShell->GetModule() : NULL;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::ClearResource()
+{
+ ClearFamilyList();
+ DELETEX(pStyleFamilies);
+ USHORT i;
+ for ( i = 0; i < MAX_FAMILIES; ++i )
+ DELETEX(pFamilyState[i]);
+ for ( i = 0; i < COUNT_BOUND_FUNC; ++i )
+ delete pBoundItems[i];
+ pCurObjShell = NULL;
+
+ DELETEZ( m_pStyleFamiliesId );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::Initialize()
+{
+ // globale Benutzer-Resource auslesen
+ ReadResource();
+ pBindings->Invalidate( SID_STYLE_FAMILY );
+ pBindings->Update( SID_STYLE_FAMILY );
+ Update_Impl();
+
+ aFilterLb.SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FilterSelectHdl ) );
+ aFmtLb.SetDoubleClickHdl( LINK( this, SfxCommonTemplateDialog_Impl, ApplyHdl ) );
+ aFmtLb.SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FmtSelectHdl ) );
+
+ aFilterLb.Show();
+ aFmtLb.Show();
+}
+
+//-------------------------------------------------------------------------
+
+SfxCommonTemplateDialog_Impl::~SfxCommonTemplateDialog_Impl()
+{
+ String aEmpty;
+ if ( bIsWater )
+ Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
+ GetWindow()->Hide();
+ DELETEX(pStyleFamilies);
+ DELETEZ( m_pStyleFamiliesId );
+ USHORT i;
+ for ( i = 0; i < MAX_FAMILIES; ++i )
+ DELETEX(pFamilyState[i]);
+ for ( i = 0; i < COUNT_BOUND_FUNC; ++i )
+ delete pBoundItems[i];
+ if ( pStyleSheetPool )
+ EndListening(*pStyleSheetPool);
+ pStyleSheetPool = NULL;
+ delete pTreeBox;
+ delete pTimer;
+ if ( pbDeleted )
+ {
+ pbDeleted->bDead = true;
+ pbDeleted = NULL;
+ }
+}
+
+//-------------------------------------------------------------------------
+
+USHORT SfxCommonTemplateDialog_Impl::SfxFamilyIdToNId( SfxStyleFamily nFamily )
+{
+ switch ( nFamily )
+ {
+ case SFX_STYLE_FAMILY_CHAR: return 1;
+ case SFX_STYLE_FAMILY_PARA: return 2;
+ case SFX_STYLE_FAMILY_FRAME: return 3;
+ case SFX_STYLE_FAMILY_PAGE: return 4;
+ case SFX_STYLE_FAMILY_PSEUDO: return 5;
+ default: return 0;
+ }
+}
+
+void SfxCommonTemplateDialog_Impl::SetAutomaticFilter()
+{
+ USHORT nCount = aFilterLb.GetEntryCount();
+ for ( USHORT i = 0; i < nCount; ++i )
+ {
+ ULONG nFlags = (ULONG)aFilterLb.GetEntryData(i);
+ if ( SFXSTYLEBIT_AUTO == nFlags )
+ {
+ // automatic entry found -> select it
+ aFilterLb.SelectEntryPos(i);
+ // then call the handler to filter the styles
+ FilterSelect( i - 1 );
+ break;
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+// Hilfsfunktion: Zugriff auf aktuelles Family-Item
+const SfxStyleFamilyItem *SfxCommonTemplateDialog_Impl::GetFamilyItem_Impl() const
+{
+ const USHORT nCount = pStyleFamilies->Count();
+ for(USHORT i = 0; i < nCount; ++i)
+ {
+ const SfxStyleFamilyItem *pItem = pStyleFamilies->GetObject(i);
+// if(!pItem)continue;
+ USHORT nId = SfxFamilyIdToNId(pItem->GetFamily());
+ if(nId == nActFamily)
+ return pItem;
+ }
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::SelectStyle(const String &rStr)
+{
+ const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
+ if ( !pItem )
+ return;
+ const SfxStyleFamily eFam = pItem->GetFamily();
+ SfxStyleSheetBase* pStyle = pStyleSheetPool->Find( rStr, eFam, SFXSTYLEBIT_ALL );
+ if( pStyle )
+ EnableEdit( !(pStyle->GetMask() & SFXSTYLEBIT_READONLY) );
+ else
+ EnableEdit(FALSE);
+
+ if ( pTreeBox )
+ {
+ if ( rStr.Len() )
+ {
+ SvLBoxEntry* pEntry = pTreeBox->First();
+ while ( pEntry )
+ {
+ if ( pTreeBox->GetEntryText( pEntry ) == rStr )
+ {
+ pTreeBox->MakeVisible( pEntry );
+ pTreeBox->Select( pEntry );
+ return;
+ }
+ pEntry = pTreeBox->Next( pEntry );
+ }
+ }
+ else
+ pTreeBox->SelectAll( FALSE );
+ }
+ else
+ {
+ BOOL bSelect = ( rStr.Len() > 0 );
+ if ( bSelect )
+ {
+ SvLBoxEntry* pEntry = (SvLBoxEntry*)aFmtLb.FirstVisible();
+ while ( pEntry && aFmtLb.GetEntryText( pEntry ) != rStr )
+ pEntry = (SvLBoxEntry*)aFmtLb.NextVisible( pEntry );
+ if ( !pEntry )
+ bSelect = FALSE;
+ else
+ {
+ aFmtLb.MakeVisible( pEntry );
+ aFmtLb.Select( pEntry );
+ bWaterDisabled = !HasSelectedStyle(); //added by BerryJia for fixing Bug76391 2003-1-22
+ FmtSelectHdl( NULL );
+ }
+ }
+
+ if ( !bSelect )
+ {
+ aFmtLb.SelectAll( FALSE );
+ EnableEdit(FALSE);
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+String SfxCommonTemplateDialog_Impl::GetSelectedEntry() const
+{
+ String aRet;
+ if ( pTreeBox )
+ {
+ SvLBoxEntry* pEntry = pTreeBox->FirstSelected();
+ if ( pEntry )
+ aRet = pTreeBox->GetEntryText( pEntry );
+ }
+ else
+ {
+ SvLBoxEntry* pEntry = aFmtLb.FirstSelected();
+ if ( pEntry )
+ aRet = aFmtLb.GetEntryText( pEntry );
+ }
+ return aRet;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::EnableTreeDrag( BOOL bEnable )
+{
+ if ( pStyleSheetPool )
+ {
+ SfxStyleSheetBase* pStyle = pStyleSheetPool->First();
+ if ( pTreeBox )
+ {
+ if ( pStyle && pStyle->HasParentSupport() && bEnable )
+ pTreeBox->SetDragDropMode(SV_DRAGDROP_CTRL_MOVE);
+ else
+ pTreeBox->SetDragDropMode(SV_DRAGDROP_NONE);
+ }
+ }
+ bTreeDrag = bEnable;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::FillTreeBox()
+{
+ DBG_ASSERT( pTreeBox, "FillTreeBox() without treebox");
+ if(pStyleSheetPool && nActFamily != 0xffff)
+ {
+ const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
+ pStyleSheetPool->SetSearchMask(pItem->GetFamily(), SFXSTYLEBIT_ALL);
+ StyleTreeArr_Impl aArr;
+ SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
+ if(pStyle && pStyle->HasParentSupport() && bTreeDrag )
+ pTreeBox->SetDragDropMode(SV_DRAGDROP_CTRL_MOVE);
+ else
+ pTreeBox->SetDragDropMode(SV_DRAGDROP_NONE);
+ while(pStyle)
+ {
+ StyleTree_ImplPtr pNew =
+ new StyleTree_Impl(pStyle->GetName(), pStyle->GetParent());
+ aArr.Insert(pNew, aArr.Count());
+ pStyle = pStyleSheetPool->Next();
+ }
+ MakeTree_Impl(aArr);
+ ExpandedEntries aEntries;
+ if(pTreeBox)
+ ((const StyleTreeListBox_Impl *)pTreeBox)->
+ MakeExpanded_Impl( aEntries);
+ pTreeBox->SetUpdateMode( FALSE );
+ pTreeBox->Clear();
+ const USHORT nCount = aArr.Count();
+ for(USHORT i = 0; i < nCount; ++i)
+ FillBox_Impl(pTreeBox, aArr[i], aEntries);
+
+// EnableEdit(FALSE);
+ EnableItem(SID_STYLE_WATERCAN,FALSE);
+
+ SfxTemplateItem* pState = pFamilyState[nActFamily-1];
+
+ if ( nCount )
+ pTreeBox->Expand( pTreeBox->First() );
+
+ for ( SvLBoxEntry* pEntry = pTreeBox->First(); pEntry; pEntry = pTreeBox->Next( pEntry ) )
+ {
+ if ( IsExpanded_Impl( aEntries, pTreeBox->GetEntryText( pEntry ) ) )
+ pTreeBox->Expand( pEntry );
+ }
+
+ pTreeBox->SetUpdateMode( TRUE );
+
+ String aStyle;
+ if(pState) //Aktuellen Eintrag selektieren
+ aStyle = pState->GetStyleName();
+ SelectStyle(aStyle);
+ EnableDelete();
+ }
+}
+
+//-------------------------------------------------------------------------
+BOOL SfxCommonTemplateDialog_Impl::HasSelectedStyle() const
+{
+ return pTreeBox? pTreeBox->FirstSelected() != 0:
+ aFmtLb.GetSelectionCount() != 0;
+}
+
+
+//-------------------------------------------------------------------------
+
+// intern: Aktualisierung der Anzeige
+void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(USHORT nFlags) // Flags, was aktualisiert werden soll (s.o.)
+{
+ DBG_ASSERT(nFlags, "nichts zu tun");
+ const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
+ if (!pItem)
+ {
+ // Ist beim Vorlagenkatalog der Fall
+ SfxTemplateItem **ppItem = pFamilyState;
+ const USHORT nFamilyCount = pStyleFamilies->Count();
+ USHORT n;
+ for(n=0;n<nFamilyCount;n++)
+ if(ppItem[StyleNrToInfoOffset(n)])break;
+ if ( n == nFamilyCount )
+ // passiert gelegentlich bei Beichten, Formularen etc.; weiss der Teufel warum
+ return;
+ ppItem+=StyleNrToInfoOffset(n);
+ nAppFilter = (*ppItem)->GetValue();
+ FamilySelect( StyleNrToInfoOffset(n)+1 );
+ pItem = GetFamilyItem_Impl();
+ }
+
+ const SfxStyleFamily eFam = pItem->GetFamily();
+
+ SfxFilterTupel *pT = pItem->GetFilterList().GetObject(nActFilter);
+ USHORT nFilter = pT ? pItem->GetFilterList().GetObject(nActFilter)->nFlags : 0;
+ if(!nFilter) // automatisch
+ nFilter = nAppFilter;
+
+ DBG_ASSERT(pStyleSheetPool, "kein StyleSheetPool");
+ if(pStyleSheetPool)
+ {
+ pStyleSheetPool->SetSearchMask(eFam, nFilter);
+ pItem = GetFamilyItem_Impl();
+ if((nFlags & UPDATE_FAMILY) == UPDATE_FAMILY)
+ {
+ CheckItem(nActFamily, TRUE); // Button in Toolbox checken
+ aFilterLb.SetUpdateMode(FALSE);
+ aFilterLb.Clear();
+ //insert hierarchical at the beginning
+ USHORT nPos = aFilterLb.InsertEntry(String(SfxResId(STR_STYLE_FILTER_HIERARCHICAL)), 0);
+ aFilterLb.SetEntryData( nPos, (void*)(ULONG)SFXSTYLEBIT_ALL );
+ const SfxStyleFilter& rFilter = pItem->GetFilterList();
+ for(USHORT i = 0; i < rFilter.Count(); ++i)
+ {
+ ULONG nFilterFlags = rFilter.GetObject(i)->nFlags;
+ nPos = aFilterLb.InsertEntry( rFilter.GetObject(i)->aName );
+ aFilterLb.SetEntryData( nPos, (void*)nFilterFlags );
+ }
+ if(nActFilter < aFilterLb.GetEntryCount() - 1)
+ aFilterLb.SelectEntryPos(nActFilter + 1);
+ else
+ {
+ nActFilter = 0;
+ aFilterLb.SelectEntryPos(1);
+ SfxFilterTupel *pActT = rFilter.GetObject(nActFilter);
+ USHORT nFilterFlags = pActT ? rFilter.GetObject(nActFilter)->nFlags : 0;
+ pStyleSheetPool->SetSearchMask(eFam, nFilterFlags);
+ }
+
+ //Falls in Treedarstellung wieder Family Hierarchie selektieren
+ if(pTreeBox)
+ aFilterLb.SelectEntry(String(SfxResId(STR_STYLE_FILTER_HIERARCHICAL)));
+
+ // show maximum 12 entries
+ aFilterLb.SetDropDownLineCount( MAX_FILTER_ENTRIES );
+ aFilterLb.SetUpdateMode(TRUE);
+ }
+ else
+ {
+ if( nActFilter < aFilterLb.GetEntryCount() - 1)
+ aFilterLb.SelectEntryPos(nActFilter + 1);
+ else
+ {
+ nActFilter = 0;
+ aFilterLb.SelectEntryPos(1);
+ }
+ }
+
+ if(nFlags & UPDATE_FAMILY_LIST)
+ {
+// EnableEdit(FALSE);
+ EnableItem(SID_STYLE_WATERCAN,FALSE);
+
+ SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
+ SvLBoxEntry* pEntry = aFmtLb.First();
+ SvStringsDtor aStrings;
+
+ while( pStyle )
+ {
+ //Bubblesort
+ for( USHORT nPos = aStrings.Count() + 1 ; nPos-- ;)
+ {
+ if( !nPos || *aStrings[nPos-1] < pStyle->GetName() )
+ {
+ // Die Namen stehen in den Styles, also nicht kopieren
+ // Reingefallen!: Writer hat insgesamt nur 1 Style
+ aStrings.Insert(
+ new String( pStyle->GetName() ), nPos );
+ break;
+ }
+ }
+ pStyle = pStyleSheetPool->Next();
+ }
+
+
+ USHORT nCount = aStrings.Count();
+ USHORT nPos = 0;
+ while( nPos < nCount && pEntry &&
+ *aStrings[ nPos ] == aFmtLb.GetEntryText( pEntry ) )
+ {
+ nPos++;
+ pEntry = aFmtLb.Next( pEntry );
+ }
+
+ if( nPos < nCount || pEntry )
+ {
+ // Box mit den Vorlagen fuellen
+ aFmtLb.SetUpdateMode(FALSE);
+ aFmtLb.Clear();
+
+ nPos = 0;
+ while( nPos < nCount )
+ aFmtLb.InsertEntry( *aStrings.GetObject( nPos++ ));
+ aFmtLb.SetUpdateMode(TRUE);
+ }
+ // aktuelle Vorlage anzeigen
+ SfxTemplateItem *pState = pFamilyState[nActFamily-1];
+ String aStyle;
+ if(pState) //Aktuellen Eintrag selektieren
+ aStyle = pState->GetStyleName();
+ SelectStyle(aStyle);
+ EnableDelete();
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+// Aktualisierung Anzeige: Gie\skanne an/aus
+void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem)
+{
+// EnableItem(SID_STYLE_WATERCAN, pItem != 0);
+ bWaterDisabled = pItem == 0;
+//added by BerryJia for fixing Bug76391 2003-1-7
+ if(!bWaterDisabled)
+ bWaterDisabled = !HasSelectedStyle();
+
+ if(pItem && !bWaterDisabled)
+ {
+ CheckItem(SID_STYLE_WATERCAN, pItem->GetValue());
+ EnableItem( SID_STYLE_WATERCAN, TRUE );
+ }
+ else
+ if(!bWaterDisabled)
+ EnableItem(SID_STYLE_WATERCAN, TRUE);
+ else
+ EnableItem(SID_STYLE_WATERCAN, FALSE);
+
+//Waehrend Giesskannenmodus Statusupdates ignorieren.
+
+ USHORT nCount=pStyleFamilies->Count();
+ pBindings->EnterRegistrations();
+ for(USHORT n=0; n<nCount; n++)
+ {
+ SfxControllerItem *pCItem=pBoundItems[n];
+ BOOL bChecked = pItem && pItem->GetValue();
+ if( pCItem->IsBound() == bChecked )
+ {
+ if( !bChecked )
+ pCItem->ReBind();
+ else
+ pCItem->UnBind();
+ }
+ }
+ pBindings->LeaveRegistrations();
+}
+
+//-------------------------------------------------------------------------
+
+// Item mit dem Status einer Family wird kopiert und gemerkt
+// (Aktualisierung erfolgt, wenn alle Stati aktualisiert worden sind.
+// Siehe auch: <SfxBindings::AddDoneHdl(const Link &)>
+
+void SfxCommonTemplateDialog_Impl::SetFamilyState( USHORT nSlotId, const SfxTemplateItem* pItem )
+{
+ USHORT nIdx = nSlotId - SID_STYLE_FAMILY_START;
+ DELETEZ(pFamilyState[nIdx]);
+ if ( pItem )
+ pFamilyState[nIdx] = new SfxTemplateItem(*pItem);
+ bUpdate = TRUE;
+
+ // Wenn verwendete Vorlagen ( wie zum Teufel findet man das heraus ?? )
+ bUpdateFamily = TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+// Benachrichtigung durch SfxBindings, da"s die Aktualisierung
+// beendet ist. St"o\st die Aktualisierung der Anzeige an.
+
+void SfxCommonTemplateDialog_Impl::Update_Impl()
+{
+ BOOL bDocChanged=FALSE;
+ SfxStyleSheetBasePool* pNewPool = NULL;
+ SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
+ SfxObjectShell* pDocShell = pViewFrame->GetObjectShell();
+ if( pDocShell )
+ pNewPool = pDocShell->GetStyleSheetPool();
+
+ if ( pNewPool != pStyleSheetPool && pDocShell )
+ {
+ SfxModule* pNewModule = pDocShell->GetModule();
+ if( pNewModule && pNewModule != pModule )
+ {
+ ClearResource();
+ ReadResource();
+ }
+ if ( pStyleSheetPool )
+ {
+ EndListening(*pStyleSheetPool);
+ pStyleSheetPool = 0;
+ }
+
+ if ( pNewPool )
+ {
+ StartListening(*pNewPool);
+ pStyleSheetPool = pNewPool;
+ bDocChanged=TRUE;
+ }
+// InvalidateBindings();
+ }
+
+ if (bUpdateFamily)
+ UpdateFamily_Impl();
+
+ USHORT i;
+ for(i = 0; i < MAX_FAMILIES; ++i)
+ if(pFamilyState[i])
+ break;
+ if(i == MAX_FAMILIES || !pNewPool)
+ // nichts erlaubt
+ return;
+
+ SfxTemplateItem *pItem = 0;
+ // aktueller Bereich nicht innerhalb der erlaubten Bereiche
+ // oder Default
+ if(nActFamily == 0xffff || 0 == (pItem = pFamilyState[nActFamily-1] ) )
+ {
+ CheckItem(nActFamily, FALSE);
+ SfxTemplateItem **ppItem = pFamilyState;
+ const USHORT nFamilyCount = pStyleFamilies->Count();
+ USHORT n;
+ for(n=0;n<nFamilyCount;n++)
+ if(ppItem[StyleNrToInfoOffset(n)])break;
+ ppItem+=StyleNrToInfoOffset(n);
+
+ nAppFilter = (*ppItem)->GetValue();
+ FamilySelect( StyleNrToInfoOffset(n)+1 );
+
+ pItem = *ppItem;
+ }
+ else if( bDocChanged )
+ {
+ // andere DocShell -> alles neu
+ CheckItem( nActFamily, TRUE );
+ nActFilter = static_cast< USHORT >( LoadFactoryStyleFilter( pDocShell ) );
+ if ( 0xFFFF == nActFilter )
+ nActFilter = pDocShell->GetAutoStyleFilterIndex();
+
+ nAppFilter = pItem->GetValue();
+ if(!pTreeBox)
+ {
+ UpdateStyles_Impl(UPDATE_FAMILY_LIST);
+ }
+ else
+ FillTreeBox();
+ }
+ else
+ {
+ // anderer Filter fuer automatisch
+ CheckItem( nActFamily, TRUE );
+ const SfxStyleFamilyItem *pStyleItem = GetFamilyItem_Impl();
+#if OSL_DEBUG_LEVEL > 1
+ SfxFilterTupel *pT;
+ pT = pStyleItem->GetFilterList().GetObject(nActFilter);
+#endif
+ if(0 == pStyleItem->GetFilterList().GetObject(nActFilter)->nFlags
+ && nAppFilter != pItem->GetValue())
+ {
+ nAppFilter = pItem->GetValue();
+ if(!pTreeBox)
+ UpdateStyles_Impl(UPDATE_FAMILY_LIST);
+ else
+ FillTreeBox();
+ }
+ else
+ nAppFilter = pItem->GetValue();
+ }
+ const String aStyle(pItem->GetStyleName());
+ SelectStyle(aStyle);
+ EnableDelete();
+ EnableNew( bCanNew );
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxCommonTemplateDialog_Impl, TimeOut, Timer *, pTim )
+{
+ (void)pTim; // unused
+ if(!bDontUpdate)
+ {
+ bDontUpdate=TRUE;
+ if(!pTreeBox)
+ UpdateStyles_Impl(UPDATE_FAMILY_LIST);
+ else
+ {
+ FillTreeBox();
+ SfxTemplateItem *pState = pFamilyState[nActFamily-1];
+ if(pState)
+ {
+ const String aStyle(pState->GetStyleName());
+ SelectStyle(aStyle);
+ EnableDelete();
+ }
+ }
+ bDontUpdate=FALSE;
+ DELETEZ(pTimer);
+ }
+ else
+ pTimer->Start();
+ return 0;
+}
+
+
+//-------------------------------------------------------------------------
+void SfxCommonTemplateDialog_Impl::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
+{
+ // Aktualisierung anstossen
+ if(rHint.Type() == TYPE(SfxSimpleHint))
+ {
+ switch(((SfxSimpleHint&) rHint ).GetId())
+ {
+ case SFX_HINT_UPDATEDONE:
+ {
+ SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
+ SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
+ if (
+ bUpdate &&
+ (
+ !IsCheckedItem(SID_STYLE_WATERCAN) ||
+ (pDocShell && pDocShell->GetStyleSheetPool() != pStyleSheetPool)
+ )
+ )
+ {
+ bUpdate = FALSE;
+ Update_Impl();
+ }
+ else if ( bUpdateFamily )
+ {
+ UpdateFamily_Impl();
+ }
+
+ if( pStyleSheetPool )
+ {
+ String aStr = GetSelectedEntry();
+ if( aStr.Len() && pStyleSheetPool )
+ {
+ const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
+ if( !pItem ) break;
+ const SfxStyleFamily eFam = pItem->GetFamily();
+ SfxStyleSheetBase *pStyle =
+ pStyleSheetPool->Find(
+ aStr, eFam, SFXSTYLEBIT_ALL );
+ if( pStyle )
+ EnableEdit(
+ !(pStyle->GetMask() & SFXSTYLEBIT_READONLY) );
+ else
+ EnableEdit(FALSE);
+ }
+ }
+ break;
+ }
+ // noetig, wenn zwichen Dokumenten umgeschaltet wird,
+ // aber in beiden Dokumenten die gleiche Vorlage gilt.
+ // Nicht sofort Update_Impl rufen, fuer den Fall da\s eines
+ // der Dokumente ein internes InPlaceObjekt ist!
+ case SFX_HINT_DOCCHANGED:
+ bUpdate = TRUE;
+ break;
+ case SFX_HINT_DYING:
+ {
+ EndListening(*pStyleSheetPool);
+ pStyleSheetPool=0;
+ break;
+ }
+ }
+ }
+
+ // Timer nicht aufsetzen, wenn der StyleSheetPool in die Kiste geht, denn
+ // es kann sein, da\s sich ein neuer erst anmeldet, nachdem der Timer
+ // abgelaufen ist - macht sich schlecht in UpdateStyles_Impl() !
+
+ ULONG nId = rHint.ISA(SfxSimpleHint) ? ( (SfxSimpleHint&)rHint ).GetId() : 0;
+
+ if(!bDontUpdate && nId != SFX_HINT_DYING &&
+ (rHint.Type() == TYPE(SfxStyleSheetPoolHint)||
+ rHint.Type() == TYPE(SfxStyleSheetHint) ||
+ rHint.Type() == TYPE( SfxStyleSheetHintExtended )))
+ {
+ if(!pTimer)
+ {
+ pTimer=new Timer;
+ pTimer->SetTimeout(500);
+ pTimer->SetTimeoutHdl(LINK(this,SfxCommonTemplateDialog_Impl,TimeOut));
+ }
+ pTimer->Start();
+
+ }
+}
+
+
+//-------------------------------------------------------------------------
+
+// Anderer Filter; kann durch den Benutzer umgeschaltet werden
+// oder als Folge von Neu oder Bearbeiten, wenn die aktuelle
+// Vorlage einem anderen Filter zugewiesen wurde.
+void SfxCommonTemplateDialog_Impl::FilterSelect(
+ USHORT nEntry, // Idx des neuen Filters
+ BOOL bForce ) // Aktualisierung erzwingen, auch wenn der neue Filter gleich dem aktuellen ist
+{
+ if( nEntry != nActFilter || bForce )
+ {
+ nActFilter = nEntry;
+ SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
+ SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
+ if (pDocShell)
+ {
+ pDocShell->SetAutoStyleFilterIndex(nActFilter);
+ SaveFactoryStyleFilter( pDocShell, nActFilter );
+ }
+
+ SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool;
+ pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0;
+ if ( pOldStyleSheetPool != pStyleSheetPool )
+ {
+ if ( pOldStyleSheetPool )
+ EndListening(*pOldStyleSheetPool);
+ if ( pStyleSheetPool )
+ StartListening(*pOldStyleSheetPool);
+ }
+
+ UpdateStyles_Impl(UPDATE_FAMILY_LIST);
+ }
+}
+
+//-------------------------------------------------------------------------
+
+// Intern: Ausf"uhren von Funktionen "uber den Dispatcher
+BOOL SfxCommonTemplateDialog_Impl::Execute_Impl(
+ USHORT nId, const String &rStr, const String& rRefStr, USHORT nFamily,
+ USHORT nMask, USHORT *pIdx, const USHORT* pModifier)
+{
+ SfxDispatcher &rDispatcher = *SFX_APP()->GetDispatcher_Impl();
+ SfxStringItem aItem(nId, rStr);
+ SfxUInt16Item aFamily(SID_STYLE_FAMILY, nFamily);
+ SfxUInt16Item aMask( SID_STYLE_MASK, nMask );
+ SfxStringItem aUpdName(SID_STYLE_UPD_BY_EX_NAME, rStr);
+ SfxStringItem aRefName( SID_STYLE_REFERENCE, rRefStr );
+ const SfxPoolItem* pItems[ 6 ];
+ USHORT nCount = 0;
+ if( rStr.Len() )
+ pItems[ nCount++ ] = &aItem;
+ pItems[ nCount++ ] = &aFamily;
+ if( nMask )
+ pItems[ nCount++ ] = &aMask;
+ if(SID_STYLE_UPDATE_BY_EXAMPLE == nId)
+ {
+ //Sonderloesung fuer Numerierungsupdate im Writer
+ const String aTemplName(GetSelectedEntry());
+ aUpdName.SetValue(aTemplName);
+ pItems[ nCount++ ] = &aUpdName;
+ }
+ if ( rRefStr.Len() )
+ pItems[ nCount++ ] = &aRefName;
+
+ pItems[ nCount++ ] = 0;
+
+ Deleted aDeleted;
+ pbDeleted = &aDeleted;
+ USHORT nModi = pModifier ? *pModifier : 0;
+ const SfxPoolItem* pItem = rDispatcher.Execute(
+ nId, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL,
+ pItems, nModi );
+
+ // FIXME: Dialog can be destroyed while in Execute() check stack variable for dtor flag!
+ if ( !pItem || aDeleted() )
+ return FALSE;
+
+ if ( nId == SID_STYLE_NEW || SID_STYLE_EDIT == nId )
+ {
+ SfxUInt16Item *pFilterItem = PTR_CAST(SfxUInt16Item, pItem);
+ DBG_ASSERT(pFilterItem, "SfxUINT16Item erwartet");
+ USHORT nFilterFlags = pFilterItem->GetValue() & ~SFXSTYLEBIT_USERDEF;
+ if(!nFilterFlags) // Benutzervorlage?
+ nFilterFlags = pFilterItem->GetValue();
+ const SfxStyleFamilyItem *pFamilyItem = GetFamilyItem_Impl();
+ const USHORT nFilterCount = (USHORT) pFamilyItem->GetFilterList().Count();
+
+ for ( USHORT i = 0; i < nFilterCount; ++i )
+ {
+ const SfxFilterTupel *pTupel =
+ pFamilyItem->GetFilterList().GetObject(i);
+
+ if ( ( pTupel->nFlags & nFilterFlags ) == nFilterFlags && pIdx )
+ *pIdx = i;
+ }
+ }
+
+ // Reset destroyed flag otherwise we use the pointer in the dtor
+ // where the local stack object is already destroyed. This would
+ // overwrite objects on the stack!! See #i100110
+ pbDeleted = NULL;
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+// Handler der Listbox der Filter
+IMPL_LINK( SfxCommonTemplateDialog_Impl, FilterSelectHdl, ListBox *, pBox )
+{
+ if ( pBox->GetSelectEntry() == String(SfxResId(STR_STYLE_FILTER_HIERARCHICAL)) )
+ {
+ if ( !bHierarchical )
+ {
+ // TreeView einschalten
+ bHierarchical=TRUE;
+ const String aSelectEntry( GetSelectedEntry());
+ aFmtLb.Hide();
+ // aFilterLb.Disable();
+
+ pTreeBox = new StyleTreeListBox_Impl(
+ this, WB_HASBUTTONS | WB_HASLINES |
+ WB_BORDER | WB_TABSTOP | WB_HASLINESATROOT |
+ WB_HASBUTTONSATROOT | WB_HIDESELECTION | WB_QUICK_SEARCH );
+ pTreeBox->SetFont( aFmtLb.GetFont() );
+
+ pTreeBox->SetPosSizePixel(aFmtLb.GetPosPixel(), aFmtLb.GetSizePixel());
+ pTreeBox->SetNodeDefaultImages();
+ pTreeBox->SetSelectHdl(
+ LINK(this, SfxCommonTemplateDialog_Impl, FmtSelectHdl));
+ ((StyleTreeListBox_Impl*)pTreeBox)->
+ SetDoubleClickHdl(
+ LINK(this, SfxCommonTemplateDialog_Impl, ApplyHdl));
+ ((StyleTreeListBox_Impl*)pTreeBox)->
+ SetDropHdl(LINK(this, SfxCommonTemplateDialog_Impl, DropHdl));
+ pTreeBox->SetIndent(10);
+
+ FillTreeBox();
+ SelectStyle(aSelectEntry);
+ pTreeBox->Show();
+ }
+ }
+
+ else
+ {
+ DELETEZ(pTreeBox);
+ aFmtLb.Show();
+ // aFilterLb.Enable();
+ // Falls bHierarchical, kann sich die Familie geaendert haben
+ // minus one since hierarchical is inserted at the start
+ FilterSelect(pBox->GetSelectEntryPos() - 1, bHierarchical );
+ bHierarchical=FALSE;
+// UpdateStyles_Impl(UPDATE_FAMILY_LIST); // Anzeige aktualisieren
+ }
+
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+// Select-Handler der Toolbox
+void SfxCommonTemplateDialog_Impl::FamilySelect(USHORT nEntry)
+{
+ if( nEntry != nActFamily )
+ {
+ CheckItem( nActFamily, FALSE );
+ nActFamily = nEntry;
+ SfxDispatcher* pDispat = pBindings->GetDispatcher_Impl();
+ SfxUInt16Item aItem( SID_STYLE_FAMILY, nEntry );
+ pDispat->Execute( SID_STYLE_FAMILY, SFX_CALLMODE_SYNCHRON, &aItem, 0L );
+ pBindings->Invalidate( SID_STYLE_FAMILY );
+ pBindings->Update( SID_STYLE_FAMILY );
+ UpdateFamily_Impl();
+ }
+}
+
+//-------------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::ActionSelect(USHORT nEntry)
+{
+ String aEmpty;
+ switch(nEntry)
+ {
+ case SID_STYLE_WATERCAN:
+ {
+ const BOOL bState = IsCheckedItem(nEntry);
+ BOOL bCheck;
+ SfxBoolItem aBool;
+ // wenn eine Vorlage ausgewaehlt ist.
+ if(!bState && aFmtLb.GetSelectionCount())
+ {
+ const String aTemplName(
+ GetSelectedEntry());
+ Execute_Impl(
+ SID_STYLE_WATERCAN, aTemplName, aEmpty,
+ (USHORT)GetFamilyItem_Impl()->GetFamily() );
+ bCheck = TRUE;
+ }
+ else
+ {
+ Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
+ bCheck = FALSE;
+ }
+ CheckItem(nEntry, bCheck);
+ aBool.SetValue(bCheck);
+ SetWaterCanState(&aBool);
+ break;
+ }
+ case SID_STYLE_NEW_BY_EXAMPLE:
+ {
+ if(pStyleSheetPool && nActFamily != 0xffff)
+ {
+ const SfxStyleFamily eFam=GetFamilyItem_Impl()->GetFamily();
+//pStyleSheetPool->GetSearchFamily();
+ const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
+ USHORT nFilter;
+ if(pItem&&nActFilter!=0xffff)
+ {
+ nFilter = pItem->GetFilterList().GetObject(
+ nActFilter)->nFlags;
+ if(!nFilter) // automatisch
+ nFilter = nAppFilter;
+ }
+ else
+ nFilter=pStyleSheetPool->GetSearchMask();
+ pStyleSheetPool->SetSearchMask( eFam, SFXSTYLEBIT_USERDEF );
+
+ SfxNewStyleDlg *pDlg =
+ // why? : FloatingWindow must not be parent of a modal dialog
+ new SfxNewStyleDlg(pWindow, *pStyleSheetPool);
+ if(RET_OK == pDlg->Execute())
+ {
+ pStyleSheetPool->SetSearchMask(eFam, nFilter);
+ const String aTemplName(pDlg->GetName());
+ Execute_Impl(SID_STYLE_NEW_BY_EXAMPLE,
+ aTemplName, aEmpty,
+ (USHORT)GetFamilyItem_Impl()->GetFamily(),
+ nFilter);
+ }
+ pStyleSheetPool->SetSearchMask( eFam, nFilter );
+ delete pDlg;
+ }
+ break;
+ }
+ case SID_STYLE_UPDATE_BY_EXAMPLE:
+ {
+ Execute_Impl(SID_STYLE_UPDATE_BY_EXAMPLE,
+ aEmpty, aEmpty,
+ (USHORT)GetFamilyItem_Impl()->GetFamily());
+ break;
+ }
+ case SID_TEMPLATE_LOAD:
+ SFX_APP()->GetDispatcher_Impl()->Execute(nEntry);
+ break;
+ default: DBG_ERROR("not implemented"); break;
+ }
+}
+
+//-------------------------------------------------------------------------
+
+static rtl::OUString getModuleIdentifier( const Reference< XModuleManager >& i_xModMgr, SfxObjectShell* i_pObjSh )
+{
+ DBG_ASSERT( i_xModMgr.is(), "getModuleIdentifier(): no XModuleManager" );
+ DBG_ASSERT( i_pObjSh, "getModuleIdentifier(): no ObjectShell" );
+
+ ::rtl::OUString sIdentifier;
+
+ try
+ {
+ sIdentifier = i_xModMgr->identify( i_pObjSh->GetModel() );
+ }
+ catch ( ::com::sun::star::frame::UnknownModuleException& )
+ {
+ DBG_WARNING( "getModuleIdentifier(): unknown module" );
+ }
+ catch ( Exception& )
+ {
+ DBG_ERRORFILE( "getModuleIdentifier(): exception of XModuleManager::identify()" );
+ }
+
+ return sIdentifier;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Int32 SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter( SfxObjectShell* i_pObjSh )
+{
+ DBG_ASSERT( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
+ sal_Int32 nFilter = -1;
+
+ Sequence< PropertyValue > lProps;
+ Reference< ::com::sun::star::container::XNameAccess > xContainer( xModuleManager, UNO_QUERY );
+ if ( xContainer.is() )
+ {
+ ::comphelper::SequenceAsHashMap aFactoryProps(
+ xContainer->getByName( getModuleIdentifier( xModuleManager, i_pObjSh ) ) );
+ sal_Int32 nDefault = -1;
+ nFilter = aFactoryProps.getUnpackedValueOrDefault( DEFINE_CONST_UNICODE("ooSetupFactoryStyleFilter"), nDefault );
+ }
+
+ return nFilter;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::SaveFactoryStyleFilter( SfxObjectShell* i_pObjSh, sal_Int32 i_nFilter )
+{
+ DBG_ASSERT( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
+ Reference< ::com::sun::star::container::XNameReplace > xContainer( xModuleManager, UNO_QUERY );
+ if ( xContainer.is() )
+ {
+ Sequence< PropertyValue > lProps(1);
+ lProps[0].Name = DEFINE_CONST_UNICODE("ooSetupFactoryStyleFilter");
+ lProps[0].Value = makeAny( i_nFilter );;
+ xContainer->replaceByName( getModuleIdentifier( xModuleManager, i_pObjSh ), makeAny( lProps ) );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxCommonTemplateDialog_Impl, DropHdl, StyleTreeListBox_Impl *, pBox )
+{
+ bDontUpdate=TRUE;
+ const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
+ const SfxStyleFamily eFam = pItem->GetFamily();
+ long ret= pStyleSheetPool->SetParent(eFam,pBox->GetStyle(), pBox->GetParent())? 1L: 0L;
+ bDontUpdate=FALSE;
+ return ret;
+}
+
+//-------------------------------------------------------------------------
+
+// Handler des Neu-Buttons
+void SfxCommonTemplateDialog_Impl::NewHdl(void *)
+{
+ String aEmpty;
+ if ( nActFamily != 0xffff )
+ {
+ Window* pTmp;
+ pTmp = Application::GetDefDialogParent();
+ if ( ISA(SfxTemplateDialog_Impl) )
+ Application::SetDefDialogParent( pWindow->GetParent() );
+ else
+ Application::SetDefDialogParent( pWindow );
+
+ const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
+ const SfxStyleFamily eFam=pItem->GetFamily();
+ USHORT nMask;
+ if(pItem&&nActFilter!=0xffff)
+ {
+ nMask = pItem->GetFilterList().GetObject(
+ nActFilter)->nFlags;
+ if(!nMask) // automatisch
+ nMask = nAppFilter;
+ }
+ else
+ nMask=pStyleSheetPool->GetSearchMask();
+
+ pStyleSheetPool->SetSearchMask(eFam,nMask);
+
+ Execute_Impl(SID_STYLE_NEW,
+ aEmpty, GetSelectedEntry(),
+ ( USHORT )GetFamilyItem_Impl()->GetFamily(),
+ nMask);
+
+ Application::SetDefDialogParent( pTmp );
+
+/* {
+ DBG_ASSERT(nFilter < aFilterLb.GetEntryCount(),
+ "Filter ueberindiziert");
+
+ if(!pTreeBox)
+ {
+// aFilterLb.SelectEntryPos(nFilter);
+ FilterSelect(nActFilter, TRUE);
+ }
+ else
+ {
+ FillTreeBox();
+ SfxTemplateItem *pState = pFamilyState[nActFamily-1];
+ if(pState)
+ {
+ const String aStyle(pState->GetStyleName());
+ SelectStyle(aStyle);
+ }
+ EnableDelete();
+ }*/
+// }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+// Handler des Bearbeiten-Buttons
+void SfxCommonTemplateDialog_Impl::EditHdl(void *)
+{
+ if(IsInitialized() && HasSelectedStyle())
+ {
+ USHORT nFilter = nActFilter;
+ String aTemplName(GetSelectedEntry());
+ const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
+ const SfxStyleFamily eFam = pItem->GetFamily();
+ pStyleSheetPool->Find(aTemplName,eFam,SFXSTYLEBIT_ALL); // -Wall required??
+ Window* pTmp;
+ //DefModalDialogParent setzen fuer
+ //Modalitaet der nachfolgenden Dialoge
+ pTmp = Application::GetDefDialogParent();
+ if ( ISA(SfxTemplateDialog_Impl) )
+ Application::SetDefDialogParent( pWindow->GetParent() );
+ else
+ Application::SetDefDialogParent( pWindow );
+ if ( Execute_Impl( SID_STYLE_EDIT, aTemplName, String(),
+ (USHORT)GetFamilyItem_Impl()->GetFamily(), 0, &nFilter ) )
+ {
+// DBG_ASSERT(nFilter < aFilterLb.GetEntryCount(), "Filter ueberindiziert");
+// aTemplName = pStyle->GetName();
+// kann durch Bearbeiten umbenannt worden sein
+/* if(!pTreeBox)
+ {
+ // aFilterLb.SelectEntryPos(nFilter);
+ // FilterSelect(nFilter, TRUE);
+ }
+ else
+ FillTreeBox();*/
+ }
+ Application::SetDefDialogParent( pTmp );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+// Handler des L"oschen-Buttons
+void SfxCommonTemplateDialog_Impl::DeleteHdl(void *)
+{
+ if ( IsInitialized() && HasSelectedStyle() )
+ {
+ const String aTemplName( GetSelectedEntry() );
+ const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
+ SfxStyleSheetBase* pStyle =
+ pStyleSheetPool->Find( aTemplName, pItem->GetFamily(), SFXSTYLEBIT_ALL );
+ if ( pStyle )
+ {
+ String aMsg;
+ if ( pStyle->IsUsed() )
+ aMsg = String( SfxResId( STR_DELETE_STYLE_USED ) );
+ aMsg += String ( SfxResId( STR_DELETE_STYLE ) );
+ aMsg.SearchAndReplaceAscii( "$1", aTemplName );
+#if defined UNX
+ QueryBox aBox( SFX_APP()->GetTopWindow(), WB_YES_NO | WB_DEF_NO, aMsg );
+#else
+ QueryBox aBox( GetWindow(), WB_YES_NO | WB_DEF_NO , aMsg );
+#endif
+ if ( RET_YES == aBox.Execute() )
+ {
+ PrepareDeleteAction();
+
+ if ( pTreeBox ) // Damit die Treelistbox beim L"oschen nicht zuklappt
+ {
+ bDontUpdate = TRUE;
+ }
+ Execute_Impl( SID_STYLE_DELETE, aTemplName,
+ String(), (USHORT)GetFamilyItem_Impl()->GetFamily() );
+
+ if ( pTreeBox )
+ {
+ pTreeBox->RemoveParentKeepChilds( pTreeBox->FirstSelected() );
+ bDontUpdate = FALSE;
+ }
+ }
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::EnableDelete()
+{
+ if(IsInitialized() && HasSelectedStyle())
+ {
+ DBG_ASSERT(pStyleSheetPool, "Kein StyleSheetPool");
+ const String aTemplName(GetSelectedEntry());
+ const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
+ const SfxStyleFamily eFam = pItem->GetFamily();
+ USHORT nFilter = 0;
+ if(pItem->GetFilterList().Count() > nActFilter)
+ nFilter = pItem->GetFilterList().GetObject(nActFilter)->nFlags;
+ if(!nFilter) // automatisch
+ nFilter = nAppFilter;
+ const SfxStyleSheetBase *pStyle =
+ pStyleSheetPool->Find(aTemplName,eFam,
+ pTreeBox? SFXSTYLEBIT_ALL: nFilter);
+ DBG_ASSERT(pStyle, "Style nicht gefunden");
+ if(pStyle && pStyle->IsUserDefined())
+ {
+ EnableDel(TRUE);
+ }
+ else
+ {
+ EnableDel(FALSE);
+ }
+ }
+ else
+ {
+ EnableDel(FALSE);
+ }
+// rBindings.Invalidate( SID_STYLE_DELETE );
+// rBindings.Update( SID_STYLE_DELETE );
+}
+
+//-------------------------------------------------------------------------
+
+// nach Selektion eines Eintrags den Focus gfs. wieder auf das App-Fenster
+// setzen
+void SfxCommonTemplateDialog_Impl::ResetFocus()
+{
+ if(ISA(SfxTemplateDialog_Impl))
+ {
+ SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
+ SfxViewShell *pVu = pViewFrame->GetViewShell();
+ Window *pAppWin = pVu ? pVu->GetWindow(): 0;
+ if(pAppWin)
+ pAppWin->GrabFocus();
+ }
+}
+
+//-------------------------------------------------------------------------
+
+// Doppelclick auf ein StyleSheet in der ListBox, wird angewendet.
+IMPL_LINK( SfxCommonTemplateDialog_Impl, ApplyHdl, Control *, pControl )
+{
+ (void)pControl; //unused
+ // nur, wenn dieser Bereich erlaubt ist
+ if ( IsInitialized() && 0 != pFamilyState[nActFamily-1] &&
+ GetSelectedEntry().Len() )
+ {
+ USHORT nModifier = aFmtLb.GetModifier();
+ Execute_Impl(SID_STYLE_APPLY,
+ GetSelectedEntry(), String(),
+ ( USHORT )GetFamilyItem_Impl()->GetFamily(),
+ 0, 0, &nModifier );
+ if(ISA(SfxTemplateCatalog_Impl))
+ ((SfxTemplateCatalog_Impl*) this)->pReal->EndDialog(RET_OK);
+ }
+ ResetFocus();
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+// Selektion einer Vorlage w"ahrend des Watercan-Status
+IMPL_LINK( SfxCommonTemplateDialog_Impl, FmtSelectHdl, SvTreeListBox *, pListBox )
+{
+ // HilfePI antriggern, wenn von Call als Handler und Bereich erlaubt ist
+ if( !pListBox || pListBox->IsSelected( pListBox->GetHdlEntry() ) )
+ {
+ // nur, wenn Giesskanne an ist
+ if ( IsInitialized() &&
+ IsCheckedItem(SID_STYLE_WATERCAN) &&
+ // nur, wenn dieser Bereich erlaubt ist
+ 0 != pFamilyState[nActFamily-1] )
+ {
+ String aEmpty;
+ Execute_Impl(SID_STYLE_WATERCAN,
+ aEmpty, aEmpty, 0);
+ Execute_Impl(SID_STYLE_WATERCAN,
+ GetSelectedEntry(), aEmpty,
+ ( USHORT )GetFamilyItem_Impl()->GetFamily());
+ }
+// EnableEdit(TRUE);
+ EnableItem(SID_STYLE_WATERCAN, !bWaterDisabled);
+ EnableDelete();
+ }
+ if( pListBox )
+ SelectStyle( pListBox->GetEntryText( pListBox->GetHdlEntry() ));
+
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxCommonTemplateDialog_Impl, MenuSelectHdl, Menu *, pMenu )
+{
+ if( pMenu )
+ {
+ nLastItemId = pMenu->GetCurItemId();
+ Application::PostUserEvent(
+ LINK( this, SfxCommonTemplateDialog_Impl, MenuSelectHdl ), 0 );
+ return TRUE;
+ }
+
+ switch(nLastItemId) {
+ case ID_NEW: NewHdl(0); break;
+ case ID_EDIT: EditHdl(0); break;
+ case ID_DELETE: DeleteHdl(0); break;
+ default: return FALSE;
+ }
+ return TRUE;
+}
+
+// -----------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::ExecuteContextMenu_Impl( const Point& rPos, Window* pWin )
+{
+ // Bug# 94152: This part should never be called, because before this happens, the TreeListBox should captured this!
+ DBG_ASSERT( FALSE, "+SfxCommonTemplateDialog_Impl::ExecuteContextMenu_Impl(): How could this happen? Please infirm developer ASAP!" );
+
+ PopupMenu* pMenu = CreateContextMenu();
+ pMenu->Execute( pWin, rPos );
+ delete pMenu;
+}
+
+// -----------------------------------------------------------------------
+
+SfxStyleFamily SfxCommonTemplateDialog_Impl::GetActualFamily() const
+{
+ const SfxStyleFamilyItem *pFamilyItem = GetFamilyItem_Impl();
+ if( !pFamilyItem || nActFamily == 0xffff )
+ return SFX_STYLE_FAMILY_PARA;
+ else
+ return pFamilyItem->GetFamily();
+}
+
+// -----------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::EnableExample_Impl(USHORT nId, BOOL bEnable)
+{
+ if( nId == SID_STYLE_NEW_BY_EXAMPLE )
+ bNewByExampleDisabled = !bEnable;
+ else if( nId == SID_STYLE_UPDATE_BY_EXAMPLE )
+ bUpdateByExampleDisabled = !bEnable;
+ EnableItem(nId, bEnable);
+}
+
+void SfxCommonTemplateDialog_Impl::PrepareDeleteAction()
+{
+}
+
+// -----------------------------------------------------------------------
+
+PopupMenu* SfxCommonTemplateDialog_Impl::CreateContextMenu( void )
+{
+ if ( bBindingUpdate )
+ {
+ pBindings->Invalidate( SID_STYLE_NEW, TRUE, FALSE );
+ pBindings->Update( SID_STYLE_NEW );
+ bBindingUpdate = FALSE;
+ }
+ PopupMenu* pMenu = new PopupMenu( SfxResId( MN_CONTEXT_TEMPLDLG ) );
+ pMenu->SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, MenuSelectHdl ) );
+ pMenu->EnableItem( ID_EDIT, bCanEdit );
+ pMenu->EnableItem( ID_DELETE, bCanDel );
+ pMenu->EnableItem( ID_NEW, bCanNew );
+
+ return pMenu;
+}
+
+// ------------------------------------------------------------------------
+
+SfxTemplateDialog_Impl::SfxTemplateDialog_Impl(
+ Window* /*pParent*/, SfxBindings* pB, SfxTemplateDialog* pDlgWindow ) :
+
+ SfxCommonTemplateDialog_Impl( pB, pDlgWindow ),
+
+ m_pFloat ( pDlgWindow ),
+ m_bZoomIn ( FALSE ),
+ m_aActionTbL ( pDlgWindow, this ),
+ m_aActionTbR ( pDlgWindow, SfxResId( TB_ACTION ) )
+
+{
+ pDlgWindow->FreeResource();
+ Initialize();
+
+ m_aActionTbL.SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxLSelect));
+ m_aActionTbR.SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxRSelect));
+ m_aActionTbR.SetDropdownClickHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxRClick));
+ m_aActionTbL.Show();
+ m_aActionTbR.Show();
+ Font aFont=aFilterLb.GetFont();
+ aFont.SetWeight( WEIGHT_NORMAL );
+ aFilterLb.SetFont( aFont );
+ m_aActionTbL.SetHelpId( HID_TEMPLDLG_TOOLBOX_LEFT );
+}
+
+// ------------------------------------------------------------------------
+
+void SfxTemplateDialog_Impl::EnableFamilyItem( USHORT nId, BOOL bEnable )
+{
+ m_aActionTbL.EnableItem( nId, bEnable );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateDialog_Impl::InsertFamilyItem(USHORT nId,const SfxStyleFamilyItem *pItem)
+{
+ rtl::OString sHelpId;
+ switch( (USHORT) pItem->GetFamily() )
+ {
+ case SFX_STYLE_FAMILY_CHAR: sHelpId = ".uno:CharStyle"; break;
+ case SFX_STYLE_FAMILY_PARA: sHelpId = ".uno:ParaStyle"; break;
+ case SFX_STYLE_FAMILY_FRAME: sHelpId = ".uno:FrameStyle"; break;
+ case SFX_STYLE_FAMILY_PAGE: sHelpId = ".uno:PageStyle"; break;
+ case SFX_STYLE_FAMILY_PSEUDO: sHelpId = ".uno:ListStyle"; break;
+ default: DBG_ERROR("unknown StyleFamily"); break;
+ }
+ m_aActionTbL.InsertItem( nId, pItem->GetImage(), pItem->GetText(), 0, 0);
+ m_aActionTbL.SetHelpId( nId, sHelpId );
+}
+
+// ------------------------------------------------------------------------
+
+void SfxTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
+{
+ m_aActionTbR.HideItem(SID_STYLE_UPDATE_BY_EXAMPLE);
+ m_aActionTbR.SetItemBits( SID_STYLE_NEW_BY_EXAMPLE,
+ TIB_DROPDOWNONLY|m_aActionTbR.GetItemBits( SID_STYLE_NEW_BY_EXAMPLE ));
+}
+
+// ------------------------------------------------------------------------
+void SfxTemplateDialog_Impl::updateFamilyImages()
+{
+ if ( !m_pStyleFamiliesId )
+ // we do not have a resource id to load the new images from
+ return;
+
+ // let the families collection update the images
+ sal_Bool bIsHighContrast = m_pFloat->GetSettings().GetStyleSettings().GetHighContrastMode();
+ pStyleFamilies->updateImages( *m_pStyleFamiliesId, bIsHighContrast ? BMP_COLOR_HIGHCONTRAST : BMP_COLOR_NORMAL );
+
+ // and set the new images on our toolbox
+ USHORT nLoop = pStyleFamilies->Count();
+ for( ; nLoop--; )
+ {
+ const SfxStyleFamilyItem *pItem = pStyleFamilies->GetObject( nLoop );
+ USHORT nId = SfxFamilyIdToNId( pItem->GetFamily() );
+ m_aActionTbL.SetItemImage( nId, pItem->GetImage() );
+ }
+}
+
+// ------------------------------------------------------------------------
+void SfxTemplateDialog_Impl::updateNonFamilyImages()
+{
+ m_aActionTbR.SetImageList( ImageList( SfxResId(
+ m_pFloat->GetSettings().GetStyleSettings().GetHighContrastMode() ? IMG_LST_STYLE_DESIGNER_HC
+ : DLG_STYLE_DESIGNER ) ) );
+}
+
+// ------------------------------------------------------------------------
+
+void SfxTemplateDialog_Impl::ClearFamilyList()
+{
+ m_aActionTbL.Clear();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxCommonTemplateDialog_Impl::InvalidateBindings()
+{
+ pBindings->Invalidate(SID_STYLE_NEW_BY_EXAMPLE, TRUE, FALSE);
+ pBindings->Update( SID_STYLE_NEW_BY_EXAMPLE );
+ pBindings->Invalidate(SID_STYLE_UPDATE_BY_EXAMPLE, TRUE, FALSE);
+ pBindings->Update( SID_STYLE_UPDATE_BY_EXAMPLE );
+ pBindings->Invalidate( SID_STYLE_WATERCAN, TRUE, FALSE);
+ pBindings->Update( SID_STYLE_WATERCAN );
+ pBindings->Invalidate( SID_STYLE_NEW, TRUE, FALSE );
+ pBindings->Update( SID_STYLE_NEW );
+ pBindings->Invalidate( SID_STYLE_DRAGHIERARCHIE, TRUE, FALSE );
+ pBindings->Update( SID_STYLE_DRAGHIERARCHIE );
+}
+
+//-------------------------------------------------------------------------
+
+SfxTemplateDialog_Impl::~SfxTemplateDialog_Impl()
+{
+/*
+ SfxImageManager* pImgMgr = pBindings->GetImageManager();
+ if ( pImgMgr )
+ {
+ pImgMgr->ReleaseToolBox( &m_aActionTbL );
+ pImgMgr->ReleaseToolBox( &m_aActionTbR );
+ }
+*/
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateDialog_Impl::LoadedFamilies()
+{
+ updateFamilyImages();
+ Resize();
+}
+
+//-------------------------------------------------------------------------
+
+// "Uberladener Resize-Handler ( StarView )
+// Die Groesse der Listboxen wird angepasst
+void SfxTemplateDialog_Impl::Resize()
+{
+ FloatingWindow *pF = m_pFloat->GetFloatingWindow();
+ if ( pF )
+ {
+// if(pF->IsZoomedIn() && m_bZoomIn==FALSE)
+// pF->SetText(String(SfxResId( DLG_STYLE_DESIGNER )));
+// if(!pF->IsZoomedIn() && m_bZoomIn==TRUE && GetFamilyItem_Impl())
+// UpdateStyles_Impl(UPDATE_FAMILY); //Bereich wieder in Titel schreiben
+ m_bZoomIn = pF->IsRollUp();
+ if ( m_bZoomIn )
+ return;
+ }
+
+ Size aDlgSize=m_pFloat->PixelToLogic(m_pFloat->GetOutputSizePixel());
+ Size aSizeATL=m_pFloat->PixelToLogic(m_aActionTbL.CalcWindowSizePixel());
+ Size aSizeATR=m_pFloat->PixelToLogic(m_aActionTbR.CalcWindowSizePixel());
+ Size aMinSize = GetMinOutputSizePixel();
+
+ long nListHeight = m_pFloat->PixelToLogic( aFilterLb.GetSizePixel() ).Height();
+ long nWidth = aDlgSize.Width()- 2 * SFX_TEMPLDLG_HFRAME;
+
+ m_aActionTbL.SetPosSizePixel(m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME,SFX_TEMPLDLG_VTOPFRAME)),
+ m_pFloat->LogicToPixel(aSizeATL));
+
+ // Die Position der rechten Toolbox nur ver"andern, wenn das Fenster
+ // breit genug ist
+ Point aPosATR(aDlgSize.Width()-SFX_TEMPLDLG_HFRAME-aSizeATR.Width(),SFX_TEMPLDLG_VTOPFRAME);
+ if(aDlgSize.Width() >= aMinSize.Width())
+ m_aActionTbR.SetPosPixel(m_pFloat->LogicToPixel(aPosATR));
+ else
+ m_aActionTbR.SetPosPixel( m_pFloat->LogicToPixel(
+ Point( SFX_TEMPLDLG_HFRAME + aSizeATL.Width() + SFX_TEMPLDLG_MIDHSPACE,
+ SFX_TEMPLDLG_VTOPFRAME ) ) );
+
+ m_aActionTbR.SetSizePixel(m_pFloat->LogicToPixel(aSizeATR));
+
+ Point aFilterPos(
+ m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME,
+ aDlgSize.Height()-SFX_TEMPLDLG_VBOTFRAME-nListHeight)) );
+
+ Size aFilterSize(
+ m_pFloat->LogicToPixel(Size(nWidth,SFX_TEMPLDLG_FILTERHEIGHT)) );
+
+ Point aFmtPos(
+ m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME, SFX_TEMPLDLG_VTOPFRAME +
+ SFX_TEMPLDLG_MIDVSPACE+aSizeATL.Height())) );
+ Size aFmtSize(
+ m_pFloat->LogicToPixel(Size(nWidth,
+ aDlgSize.Height() - SFX_TEMPLDLG_VBOTFRAME -
+ SFX_TEMPLDLG_VTOPFRAME - 2*SFX_TEMPLDLG_MIDVSPACE-
+ nListHeight-aSizeATL.Height())) );
+
+ // Die Position der Listboxen nur ver"andern, wenn das Fenster
+ // hoch genug ist
+ if(aDlgSize.Height() >= aMinSize.Height())
+ {
+ aFilterLb.SetPosPixel(aFilterPos);
+ aFmtLb.SetPosPixel( aFmtPos );
+ if(pTreeBox)
+ pTreeBox->SetPosPixel(aFmtPos);
+ }
+ else
+ aFmtSize.Height() += aFilterSize.Height();
+
+ aFilterLb.SetSizePixel(aFilterSize);
+ aFmtLb.SetSizePixel( aFmtSize );
+ if(pTreeBox)
+ pTreeBox->SetSizePixel(aFmtSize);
+}
+
+// -----------------------------------------------------------------------
+
+
+Size SfxTemplateDialog_Impl::GetMinOutputSizePixel()
+{
+ Size aSizeATL=m_pFloat->PixelToLogic(m_aActionTbL.CalcWindowSizePixel());
+ Size aSizeATR=m_pFloat->PixelToLogic(m_aActionTbR.CalcWindowSizePixel());
+ Size aMinSize=Size(
+ aSizeATL.Width()+aSizeATR.Width()+
+ 2*SFX_TEMPLDLG_HFRAME + SFX_TEMPLDLG_MIDHSPACE,
+ 4*aSizeATL.Height()+2*SFX_TEMPLDLG_MIDVSPACE);
+ return aMinSize;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateDialog_Impl::Command( const CommandEvent& rCEvt )
+{
+ if(COMMAND_CONTEXTMENU == rCEvt.GetCommand())
+ ExecuteContextMenu_Impl( rCEvt.GetMousePosPixel(), m_pFloat );
+ else
+ m_pFloat->Command(rCEvt);
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateDialog_Impl::EnableItem(USHORT nMesId, BOOL bCheck)
+{
+ String aEmpty;
+ switch(nMesId)
+ {
+ case SID_STYLE_WATERCAN :
+ if(!bCheck && IsCheckedItem(SID_STYLE_WATERCAN))
+ Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
+ case SID_STYLE_NEW_BY_EXAMPLE:
+ case SID_STYLE_UPDATE_BY_EXAMPLE:
+ m_aActionTbR.EnableItem(nMesId,bCheck);
+ break;
+ }
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateDialog_Impl::CheckItem(USHORT nMesId, BOOL bCheck)
+{
+ switch(nMesId)
+ {
+ case SID_STYLE_WATERCAN :
+ bIsWater=bCheck;
+ m_aActionTbR.CheckItem(SID_STYLE_WATERCAN,bCheck);
+ break;
+ default:
+ m_aActionTbL.CheckItem(nMesId,bCheck); break;
+ }
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxTemplateDialog_Impl::IsCheckedItem(USHORT nMesId)
+{
+ switch(nMesId)
+ {
+ case SID_STYLE_WATERCAN :
+ return m_aActionTbR.GetItemState(SID_STYLE_WATERCAN)==STATE_CHECK;
+ default:
+ return m_aActionTbL.GetItemState(nMesId)==STATE_CHECK;
+ }
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxTemplateDialog_Impl, ToolBoxLSelect, ToolBox *, pBox )
+{
+ const USHORT nEntry = pBox->GetCurItemId();
+ FamilySelect(nEntry);
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxTemplateDialog_Impl, ToolBoxLSelect, ToolBox *, pBox )
+
+//-------------------------------------------------------------------------
+::rtl::OUString lcl_GetLabel(uno::Any& rAny)
+{
+ ::rtl::OUString sRet;
+ uno::Sequence< beans::PropertyValue >aPropSeq;
+ if ( rAny >>= aPropSeq )
+ {
+ for( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
+ {
+ if ( aPropSeq[i].Name.equalsAscii( "Label" ))
+ {
+ aPropSeq[i].Value >>= sRet;
+ break;
+ }
+ }
+ }
+ return sRet;
+}
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxTemplateDialog_Impl, ToolBoxRSelect, ToolBox *, pBox )
+{
+ const USHORT nEntry = pBox->GetCurItemId();
+ if(nEntry != SID_STYLE_NEW_BY_EXAMPLE ||
+ TIB_DROPDOWN != (pBox->GetItemBits(nEntry)&TIB_DROPDOWN))
+ ActionSelect(nEntry);
+ return 0;
+}
+//-------------------------------------------------------------------------
+IMPL_LINK( SfxTemplateDialog_Impl, ToolBoxRClick, ToolBox *, pBox )
+{
+ const USHORT nEntry = pBox->GetCurItemId();
+ if(nEntry == SID_STYLE_NEW_BY_EXAMPLE &&
+ TIB_DROPDOWN == (pBox->GetItemBits(nEntry)&TIB_DROPDOWN))
+ {
+ //create a popup menu in Writer
+ PopupMenu *pMenu = new PopupMenu;
+ uno::Reference< container::XNameAccess > xNameAccess(
+ ::comphelper::getProcessServiceFactory()->
+ createInstance( ::rtl::OUString::createFromAscii(
+ "com.sun.star.frame.UICommandDescription") ), uno::UNO_QUERY );
+ uno::Reference< container::XNameAccess > xUICommands;
+ if ( xNameAccess.is() )
+ {
+ rtl::OUString sTextDoc = ::rtl::OUString::createFromAscii("com.sun.star.text.TextDocument");
+ if(xNameAccess->hasByName(sTextDoc))
+ {
+ uno::Any a = xNameAccess->getByName( sTextDoc );
+ a >>= xUICommands;
+ }
+ }
+ if(!xUICommands.is())
+ return 0;
+ try
+ {
+ uno::Sequence< beans::PropertyValue > aPropSeq;
+ uno::Any aCommand = xUICommands->getByName(::rtl::OUString::createFromAscii(".uno:StyleNewByExample"));
+ ::rtl::OUString sLabel = lcl_GetLabel( aCommand );
+ pMenu->InsertItem( SID_STYLE_NEW_BY_EXAMPLE, sLabel );
+ pMenu->SetHelpId(SID_STYLE_NEW_BY_EXAMPLE, HID_TEMPLDLG_NEWBYEXAMPLE);
+
+ aCommand = xUICommands->getByName(::rtl::OUString::createFromAscii(".uno:StyleUpdateByExample"));
+ sLabel = lcl_GetLabel( aCommand );
+
+ pMenu->InsertItem( SID_STYLE_UPDATE_BY_EXAMPLE, sLabel );
+ pMenu->SetHelpId(SID_STYLE_UPDATE_BY_EXAMPLE, HID_TEMPLDLG_UPDATEBYEXAMPLE);
+
+ aCommand = xUICommands->getByName(::rtl::OUString::createFromAscii(".uno:LoadStyles"));
+ sLabel = lcl_GetLabel( aCommand );
+ pMenu->InsertItem( SID_TEMPLATE_LOAD, sLabel );
+ pMenu->SetHelpId(SID_TEMPLATE_LOAD, ".uno:LoadStyles");
+
+ pMenu->SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, MenuSelectHdl));
+ pMenu->Execute( pBox,
+ pBox->GetItemRect(nEntry),
+ POPUPMENU_EXECUTE_DOWN );
+ pBox->EndSelection();
+ }
+ catch(uno::Exception&)
+ {
+ }
+ delete pMenu;
+ pBox->Invalidate();
+ }
+ return 0;
+}
+//-------------------------------------------------------------------------
+IMPL_LINK( SfxTemplateDialog_Impl, MenuSelectHdl, Menu*, pMenu)
+{
+ USHORT nMenuId = pMenu->GetCurItemId();
+ ActionSelect(nMenuId);
+ return 0;
+}
+//-------------------------------------------------------------------------
+
+SfxTemplateCatalog_Impl::SfxTemplateCatalog_Impl( Window* /*pParent*/, SfxBindings* pB,
+ SfxTemplateCatalog* pTmpWindow ) :
+
+ SfxCommonTemplateDialog_Impl( pB, pTmpWindow ),
+
+ aFamList ( pTmpWindow, SfxResId( BT_TOOL ) ),
+ aOkBtn ( pTmpWindow, SfxResId( BT_OK ) ),
+ aCancelBtn ( pTmpWindow, SfxResId( BT_CANCEL ) ),
+ aNewBtn ( pTmpWindow, SfxResId( BT_NEW ) ),
+ aChangeBtn ( pTmpWindow, SfxResId( BT_EDIT ) ),
+ aDelBtn ( pTmpWindow, SfxResId( BT_DEL ) ),
+ aOrgBtn ( pTmpWindow, SfxResId( BT_ORG ) ),
+ aHelpBtn ( pTmpWindow, SfxResId( BT_HELP ) ),
+ pReal ( pTmpWindow ),
+ aHelper ( pTmpWindow )
+
+{
+ aNewBtn.Disable();
+ aDelBtn.Disable();
+ aChangeBtn.Disable();
+
+ SFX_APP()->Get_Impl()->pTemplateCommon = GetISfxTemplateCommon();
+ pTmpWindow->FreeResource();
+
+ Initialize();
+
+ aFamList.SetSelectHdl( LINK( this, SfxTemplateCatalog_Impl, FamListSelect ) );
+ aOkBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, OkHdl ) );
+ aCancelBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, CancelHdl ) );
+ aNewBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, NewHdl ) );
+ aDelBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, DelHdl ) );
+ aChangeBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, ChangeHdl ) );
+ aOrgBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, OrgHdl ) );
+}
+
+//-------------------------------------------------------------------------
+
+SfxTemplateCatalog_Impl::~SfxTemplateCatalog_Impl()
+{
+ SFX_APP()->Get_Impl()->pTemplateCommon = 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, OkHdl, Button *, pButton )
+{
+ (void)pButton; //unused
+ ApplyHdl( NULL );
+ pReal->EndDialog( RET_OK );
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, OkHdl, Button *, pButton )
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, CancelHdl, Button *, pButton )
+{
+ (void)pButton; //unused
+ pReal->EndDialog( RET_CANCEL );
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, CancelHdl, Button *, pButton )
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, NewHdl, Button *, pButton )
+{
+ (void)pButton; //unused
+ aCancelBtn.SetText( String( SfxResId( STR_CLOSE ) ) );
+ SfxCommonTemplateDialog_Impl::NewHdl( NULL );
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, NewHdl, Button *, pButton )
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, ChangeHdl, Button *, pButton )
+{
+ (void)pButton; //unused
+ aCancelBtn.SetText( String( SfxResId( STR_CLOSE ) ) );
+ SfxCommonTemplateDialog_Impl::EditHdl( NULL );
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, ChangeHdl, Button *, pButton )
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, DelHdl, Button *, pButton )
+{
+ (void)pButton; //unused
+ SfxCommonTemplateDialog_Impl::DeleteHdl( NULL );
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, DelHdl, Button *, pButton )
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxTemplateCatalog_Impl, OrgHdl, Button *, pButton )
+{
+ (void)pButton; //unused
+ aCancelBtn.SetText( String( SfxResId( STR_CLOSE ) ) );
+ SfxDocumentTemplates aTemplates;
+ aTemplates.Construct();
+ SfxTemplateOrganizeDlg* pDlg = new SfxTemplateOrganizeDlg( pReal, &aTemplates );
+ const short nRet = pDlg->Execute();
+ delete pDlg;
+ if ( RET_OK == nRet )
+ Update_Impl();
+ else if ( RET_EDIT_STYLE == nRet )
+ pReal->EndDialog( RET_CANCEL );
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateCatalog_Impl::EnableEdit( BOOL bEnable )
+{
+ SfxCommonTemplateDialog_Impl::EnableEdit( bEnable );
+ aChangeBtn.Enable( bEnable );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateCatalog_Impl::EnableDel( BOOL bEnable )
+{
+ SfxCommonTemplateDialog_Impl::EnableDel( bEnable );
+ aDelBtn.Enable( bEnable );
+}
+
+void SfxTemplateCatalog_Impl::EnableNew(BOOL bEnable)
+{
+ SfxCommonTemplateDialog_Impl::EnableNew( bEnable );
+ aNewBtn.Enable( bEnable );
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, FamListSelect, ListBox *, pList )
+{
+ const USHORT nEntry = aFamIds[pList->GetSelectEntryPos()];
+ FamilySelect(nEntry);
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, FamListSelect, ListBox *, pList )
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateCatalog_Impl::EnableItem( USHORT nMesId, BOOL bCheck )
+{
+ if ( nMesId == SID_STYLE_WATERCAN )
+ aOkBtn.Enable( bCheck );
+ if ( nMesId > SFX_STYLE_FAMILY_PSEUDO || nMesId < SFX_STYLE_FAMILY_CHAR )
+ return;
+
+/* for(USHORT i=0;i<aFamIds.Count&&aFamIds[i]!=nMesId;i++);
+ if(i!=aFamIds.Count())
+ aFamList.SelectEntry(aFamIds[i]);
+ else
+ DBG_ERROR("Entry nicht gefunden");*/
+
+}
+
+//-------------------------------------------------------------------------
+
+void SfxTemplateCatalog_Impl::CheckItem(USHORT nMesId, BOOL /*bCheck*/)
+{
+ if ( nMesId > SFX_STYLE_FAMILY_PSEUDO || nMesId < SFX_STYLE_FAMILY_CHAR )
+ return;
+ USHORT i;
+ for ( i = 0; i < aFamIds.Count() && aFamIds[i] != nMesId; i++ ) ;
+ aFamList.SelectEntryPos(i);
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxTemplateCatalog_Impl::IsCheckedItem(USHORT nMesId)
+{
+ if ( nMesId > SFX_STYLE_FAMILY_PSEUDO || nMesId < SFX_STYLE_FAMILY_CHAR )
+ return FALSE;
+ USHORT i;
+ for ( i = 0; i < aFamIds.Count() && aFamIds[i] != nMesId; i++ )
+ ;
+ return aFamList.IsEntrySelected( String::CreateFromInt32(i) );
+}
+
+//-------------------------------------------------------------------------
+
+// Der Katalog muss nur das Disablen beherrschen, da waehrend seiner
+// Lebenszeit keine Selektionsaenderungen vorgenommen werden koennen
+void SfxTemplateCatalog_Impl::EnableFamilyItem( USHORT nId, BOOL bEnable )
+{
+ if ( !bEnable )
+ for ( USHORT nPos = aFamIds.Count(); nPos--; )
+ if ( aFamIds[ nPos ] == nId )
+ {
+ aFamIds.Remove( nPos );
+ aFamList.RemoveEntry( nPos );
+ }
+}
+
+void SfxTemplateCatalog_Impl::InsertFamilyItem( USHORT nId, const SfxStyleFamilyItem* pItem )
+{
+ if ( nId > SFX_STYLE_FAMILY_PSEUDO || nId < SFX_STYLE_FAMILY_CHAR )
+ return;
+ aFamList.InsertEntry( pItem->GetText(), 0 );
+ aFamIds.Insert( nId, 0 );
+}
+
+void SfxTemplateCatalog_Impl::ClearFamilyList()
+{
+ aFamList.Clear();
+ aFamIds.Remove( 0, aFamIds.Count() );
+}
+
+void SfxTemplateCatalog_Impl::PrepareDeleteAction()
+{
+ aDelBtn.Disable();
+ aCancelBtn.SetText( String( SfxResId( STR_CLOSE ) ) );
+}
+
+
+void SfxCommonTemplateDialog_Impl::SetFamily( USHORT nId )
+{
+ if ( nId != nActFamily )
+ {
+ if ( nActFamily != 0xFFFF )
+ CheckItem( nActFamily, FALSE );
+ nActFamily = nId;
+ if ( nId != 0xFFFF )
+ bUpdateFamily = TRUE;
+ }
+}
+
+void SfxCommonTemplateDialog_Impl::UpdateFamily_Impl()
+{
+ bUpdateFamily = FALSE;
+
+ SfxDispatcher* pDispat = pBindings->GetDispatcher_Impl();
+ SfxViewFrame *pViewFrame = pDispat->GetFrame();
+ SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
+
+ SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool;
+ pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0;
+ if ( pOldStyleSheetPool != pStyleSheetPool )
+ {
+ if ( pOldStyleSheetPool )
+ EndListening(*pOldStyleSheetPool);
+ if ( pStyleSheetPool )
+ StartListening(*pOldStyleSheetPool);
+ }
+
+ bWaterDisabled = FALSE;
+ bCanNew = TRUE;
+ bTreeDrag = TRUE;
+ bUpdateByExampleDisabled = FALSE;
+
+ if ( pStyleSheetPool )
+ {
+ if(!pTreeBox)
+ UpdateStyles_Impl(UPDATE_FAMILY | UPDATE_FAMILY_LIST);
+ else
+ {
+ UpdateStyles_Impl(UPDATE_FAMILY);
+ FillTreeBox();
+ }
+ }
+
+ InvalidateBindings();
+
+ if ( IsCheckedItem( SID_STYLE_WATERCAN ) &&
+ // nur, wenn dieser Bereich erlaubt ist
+ 0 != pFamilyState[ nActFamily - 1 ] )
+ Execute_Impl( SID_STYLE_APPLY, GetSelectedEntry(),
+ String(), (USHORT)GetFamilyItem_Impl()->GetFamily() );
+}
+void SfxCommonTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
+{
+ //does nothing
+}
+
+void SfxTemplateDialog::StateChanged( StateChangedType nStateChange )
+{
+ if ( nStateChange == STATE_CHANGE_INITSHOW )
+ {
+ SfxViewFrame *pFrame = GetBindings().GetDispatcher_Impl()->GetFrame();
+ Window* pEditWin = pFrame->GetViewShell()->GetWindow();
+
+ Size aSize = pEditWin->GetSizePixel();
+ Point aPoint = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
+ aPoint = GetParent()->ScreenToOutputPixel( aPoint );
+ Size aWinSize = GetSizePixel();
+ aPoint.X() += aSize.Width() - aWinSize.Width() - 20;
+ aPoint.Y() += aSize.Height() / 2 - aWinSize.Height() / 2;
+ SetFloatingPos( aPoint );
+ }
+
+ SfxDockingWindow::StateChanged( nStateChange );
+}
+
+/*-- 10.12.2003 11:44:35---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+DropToolBox_Impl::DropToolBox_Impl(Window* pParent, SfxTemplateDialog_Impl* pTemplateDialog) :
+ ToolBox(pParent),
+ DropTargetHelper(this),
+ rParent(*pTemplateDialog)
+{
+}
+/*-- 10.12.2003 11:44:35---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+DropToolBox_Impl::~DropToolBox_Impl()
+{
+}
+/*-- 10.12.2003 11:44:35---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+sal_Int8 DropToolBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
+{
+ sal_Int8 nReturn = DND_ACTION_NONE;
+ USHORT nItemId = GetItemId( rEvt.maPosPixel );
+ if(USHRT_MAX != nItemId && !IsItemChecked( nItemId ))
+ {
+ SetCurItemId(nItemId);
+ GetSelectHdl().Call(this);
+ }
+ // special case: page styles are allowed to create new styles by example
+ // but not allowed to be created by drag and drop
+ if ( nItemId != SfxCommonTemplateDialog_Impl::SfxFamilyIdToNId( SFX_STYLE_FAMILY_PAGE )&&
+ IsDropFormatSupported( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) &&
+ !rParent.bNewByExampleDisabled )
+ {
+ nReturn = DND_ACTION_COPY;
+ }
+ return nReturn;
+}
+/*-- 10.12.2003 11:44:35---------------------------------------------------
+
+ -----------------------------------------------------------------------*/
+sal_Int8 DropToolBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
+{
+ return rParent.aFmtLb.ExecuteDrop(rEvt);
+}
+
diff --git a/sfx2/source/dialog/templdlg.hrc b/sfx2/source/dialog/templdlg.hrc
new file mode 100644
index 000000000000..58563fb9c160
--- /dev/null
+++ b/sfx2/source/dialog/templdlg.hrc
@@ -0,0 +1,52 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#define TB_FMT 1
+#define LB_FMT 3
+#define BTN_EDIT 11
+#define BTN_DELETE 12
+#define TB_ACTION 15
+#define BTN_NEW 10
+#define LB_FILTER 4
+
+#define ID_APPLY_TEMPLATE 10
+
+#define ID_NEW_STYLE_BY_EXAMPLE 20
+#define ID_UPDATE_STYLE_BY_EXAMPLE 21
+#define ID_TREEVIEW 22
+
+#define BT_OK 1
+#define BT_CANCEL 2
+#define BT_ORG 3
+#define BT_DEL 4
+#define BT_EDIT 5
+#define BT_NEW 6
+#define BT_HELP 7
+#define BT_FLIST 8
+#define BT_VLIST 9
+#define BT_TOOL 10
+
+
diff --git a/sfx2/source/dialog/templdlg.src b/sfx2/source/dialog/templdlg.src
new file mode 100644
index 000000000000..60979450d9f6
--- /dev/null
+++ b/sfx2/source/dialog/templdlg.src
@@ -0,0 +1,216 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+ // include ---------------------------------------------------------------
+#include <sfx2/sfx.hrc>
+#include "dialog.hrc"
+#include "templdlg.hrc"
+#include "helpid.hrc"
+
+ImageList DLG_STYLE_DESIGNER
+{
+ Prefix = "sc";
+ MaskColor = Color { Red = 0xFFFF ; Green = 0x0000 ; Blue = 0xFFFF ; };
+ IdList =
+ {
+ SID_STYLE_WATERCAN ;
+ SID_STYLE_NEW_BY_EXAMPLE ;
+ SID_STYLE_UPDATE_BY_EXAMPLE ;
+ };
+ IdCount = { 3 ; };
+};
+ImageList IMG_LST_STYLE_DESIGNER_HC
+{
+ Prefix = "sch";
+ MaskColor = Color { Red = 0xFFFF ; Green = 0x0000 ; Blue = 0xFFFF ; };
+ IdList =
+ {
+ SID_STYLE_WATERCAN ;
+ SID_STYLE_NEW_BY_EXAMPLE ;
+ SID_STYLE_UPDATE_BY_EXAMPLE ;
+ };
+ IdCount = { 3 ; };
+};
+ // RID_STYLECATALOG ------------------------------------------------------
+ModalDialog RID_STYLECATALOG
+{
+ HelpId = CMD_SID_STYLE_CATALOG ;
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 181 , 134 ) ;
+ Text [ en-US ] = "Style Catalog" ;
+ Moveable = TRUE ;
+ OKButton BT_OK
+ {
+ DefButton = TRUE ;
+ Pos = MAP_APPFONT ( 123 , 6 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ };
+ CancelButton BT_CANCEL
+ {
+ Pos = MAP_APPFONT ( 123 , 23 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ };
+ PushButton BT_ORG
+ {
+ HelpID = "sfx2:PushButton:RID_STYLECATALOG:BT_ORG";
+ Pos = MAP_APPFONT ( 123 , 97 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~Organizer..." ;
+ TabStop = TRUE ;
+ };
+ PushButton BT_DEL
+ {
+ HelpID = "sfx2:PushButton:RID_STYLECATALOG:BT_DEL";
+ Pos = MAP_APPFONT ( 123 , 78 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~Delete..." ;
+ TabStop = TRUE ;
+ };
+ PushButton BT_EDIT
+ {
+ HelpID = "sfx2:PushButton:RID_STYLECATALOG:BT_EDIT";
+ Pos = MAP_APPFONT ( 123 , 60 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~Modify..." ;
+ TabStop = TRUE ;
+ };
+ PushButton BT_NEW
+ {
+ HelpID = "sfx2:PushButton:RID_STYLECATALOG:BT_NEW";
+ Pos = MAP_APPFONT ( 123 , 43 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~New..." ;
+ TabStop = TRUE ;
+ };
+ HelpButton BT_HELP
+ {
+ Pos = MAP_APPFONT ( 123 , 114 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ };
+ ListBox BT_TOOL
+ {
+ HelpID = "sfx2:ListBox:RID_STYLECATALOG:BT_TOOL";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 6 ) ;
+ Size = MAP_APPFONT ( 110 , 55 ) ;
+ TabStop = TRUE ;
+ DropDown = TRUE ;
+ };
+ Control BT_VLIST
+ {
+ HelpId = HID_TEMPLATE_FMT ;
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 23 ) ;
+ Size = MAP_APPFONT ( 110 , 89 ) ;
+ TabStop = TRUE ;
+ };
+ ListBox BT_FLIST
+ {
+ HelpID = "sfx2:ListBox:RID_STYLECATALOG:BT_FLIST";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 114 ) ;
+ Size = MAP_APPFONT ( 110 , 77 ) ;
+ TabStop = TRUE ;
+ Hide = TRUE ;
+ DropDown = TRUE ;
+ };
+};
+ // Strings ---------------------------------------------------------------
+String STR_STYLE_FILTER_HIERARCHICAL
+{
+ Text [ en-US ] = "Hierarchical" ;
+};
+ // DLG_STYLE_DESIGNER ----------------------------------------------------
+DockingWindow DLG_STYLE_DESIGNER
+{
+ Text [ en-US ] = "Styles and Formatting" ;
+
+ HelpId = CMD_SID_STYLE_DESIGNER ;
+ OutputSize = TRUE ;
+ Hide = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 116 , 215 ) ;
+ Pos = MAP_APPFONT ( 0 , 0 ) ;
+ Closeable = TRUE ;
+ Zoomable = TRUE ;
+ Sizeable = TRUE ;
+ Dockable = TRUE ;
+ EnableResizing = TRUE ;
+ // HideWhenDeactivate = TRUE;
+ Border = TRUE ;
+ Moveable = TRUE ;
+ ToolBox TB_ACTION
+ {
+ Pos = MAP_APPFONT ( 3 , 3 ) ;
+ Size = MAP_APPFONT ( 57 , 42 ) ;
+ LineCount = 1 ;
+ ItemImageList = DLG_STYLE_DESIGNER ;
+ HelpId = HID_TEMPLDLG_TOOLBOX_RIGHT ;
+ ItemList =
+ {
+ ToolBoxItem
+ {
+ HelpId = HID_TEMPLDLG_WATERCAN ;
+ Identifier = SID_STYLE_WATERCAN ;
+ Text [ en-US ] = "Fill Format Mode" ;
+ };
+ ToolBoxItem
+ {
+ HelpId = HID_TEMPLDLG_NEWBYEXAMPLE ;
+ Identifier = SID_STYLE_NEW_BY_EXAMPLE ;
+ Text [ en-US ] = "New Style from Selection" ;
+ };
+ ToolBoxItem
+ {
+ HelpId = HID_TEMPLDLG_UPDATEBYEXAMPLE ;
+ Identifier = SID_STYLE_UPDATE_BY_EXAMPLE ;
+ Text [ en-US ] = "Update Style" ;
+ };
+ };
+ };
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/dialog/titledockwin.cxx b/sfx2/source/dialog/titledockwin.cxx
new file mode 100644
index 000000000000..680880229324
--- /dev/null
+++ b/sfx2/source/dialog/titledockwin.cxx
@@ -0,0 +1,360 @@
+/*************************************************************************
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_sfx2.hxx"
+
+#include "sfx2/titledockwin.hxx"
+#include "sfx2/bindings.hxx"
+#include "sfx2/dispatch.hxx"
+#include "sfxlocal.hrc"
+#include "sfxresid.hxx"
+
+#include <svl/eitem.hxx>
+
+//......................................................................................................................
+namespace sfx2
+{
+//......................................................................................................................
+
+ //==================================================================================================================
+ //= TitledDockingWindow
+ //==================================================================================================================
+ //------------------------------------------------------------------------------------------------------------------
+ TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, Window* i_pParent,
+ WinBits i_nStyle )
+ :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, i_nStyle )
+ ,m_sTitle()
+ ,m_aToolbox( this )
+ ,m_aContentWindow( this, WB_DIALOGCONTROL )
+ ,m_aBorder( 3, 1, 3, 3 )
+ ,m_bLayoutPending( false )
+ ,m_nTitleBarHeight(0)
+ {
+ impl_construct();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, Window* i_pParent,
+ const ResId& i_rResId )
+ :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, i_rResId )
+ ,m_sTitle()
+ ,m_aToolbox( this )
+ ,m_aContentWindow( this )
+ ,m_aBorder( 3, 1, 3, 3 )
+ ,m_bLayoutPending( false )
+ {
+ impl_construct();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::impl_construct()
+ {
+ SetBackground( Wallpaper() );
+
+ m_aToolbox.SetSelectHdl( LINK( this, TitledDockingWindow, OnToolboxItemSelected ) );
+ m_aToolbox.SetOutStyle( TOOLBOX_STYLE_FLAT );
+ m_aToolbox.SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
+ m_aToolbox.Show();
+ impl_resetToolBox();
+
+ m_aContentWindow.Show();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ TitledDockingWindow::~TitledDockingWindow()
+ {
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::SetTitle( const String& i_rTitle )
+ {
+ m_sTitle = i_rTitle;
+ Invalidate();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ String TitledDockingWindow::GetTitle() const
+ {
+ return impl_getTitle();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::SetText( const String& i_rText )
+ {
+ SfxDockingWindow::SetText( i_rText );
+ if ( m_sTitle.Len() == 0 )
+ // our text is used as title, too => repaint
+ Invalidate();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::Resize()
+ {
+ SfxDockingWindow::Resize();
+ impl_scheduleLayout();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::onLayoutDone()
+ {
+ // not interested in
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::impl_scheduleLayout()
+ {
+ m_bLayoutPending = true;
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::impl_layout()
+ {
+ m_bLayoutPending = false;
+
+ m_aToolbox.ShowItem( 1, !IsFloatingMode() );
+
+ const Size aToolBoxSize( m_aToolbox.CalcWindowSizePixel() );
+ Size aWindowSize( GetOutputSizePixel() );
+
+ // position the tool box
+ m_nTitleBarHeight = GetSettings().GetStyleSettings().GetTitleHeight();
+ if ( aToolBoxSize.Height() > m_nTitleBarHeight )
+ m_nTitleBarHeight = aToolBoxSize.Height();
+ m_aToolbox.SetPosSizePixel(
+ Point(
+ aWindowSize.Width() - aToolBoxSize.Width(),
+ ( m_nTitleBarHeight - aToolBoxSize.Height() ) / 2
+ ),
+ aToolBoxSize
+ );
+
+ // Place the content window.
+ if ( m_nTitleBarHeight < aToolBoxSize.Height() )
+ m_nTitleBarHeight = aToolBoxSize.Height();
+ aWindowSize.Height() -= m_nTitleBarHeight;
+ m_aContentWindow.SetPosSizePixel(
+ Point( m_aBorder.Left(), m_nTitleBarHeight + m_aBorder.Top() ),
+ Size(
+ aWindowSize.Width() - m_aBorder.Left() - m_aBorder.Right(),
+ aWindowSize.Height() - m_aBorder.Top() - m_aBorder.Bottom()
+ )
+ );
+
+ onLayoutDone();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::Paint( const Rectangle& i_rArea )
+ {
+ if ( m_bLayoutPending )
+ impl_layout();
+
+ SfxDockingWindow::Paint( i_rArea );
+
+ Push( PUSH_FONT | PUSH_FILLCOLOR | PUSH_LINECOLOR );
+
+ SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
+ SetLineColor();
+
+ // bold font
+ Font aFont( GetFont() );
+ aFont.SetWeight( WEIGHT_BOLD );
+ SetFont( aFont );
+
+ // Set border values.
+ Size aWindowSize( GetOutputSizePixel() );
+ int nOuterLeft = 0;
+ int nInnerLeft = nOuterLeft + m_aBorder.Left() - 1;
+ int nOuterRight = aWindowSize.Width() - 1;
+ int nInnerRight = nOuterRight - m_aBorder.Right() + 1;
+ int nInnerTop = m_nTitleBarHeight + m_aBorder.Top() - 1;
+ int nOuterBottom = aWindowSize.Height() - 1;
+ int nInnerBottom = nOuterBottom - m_aBorder.Bottom() + 1;
+
+ // Paint title bar background.
+ Rectangle aTitleBarBox( Rectangle(
+ nOuterLeft,
+ 0,
+ nOuterRight,
+ nInnerTop-1
+ ) );
+ DrawRect( aTitleBarBox );
+
+ if ( nInnerLeft > nOuterLeft )
+ DrawRect( Rectangle( nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom ) );
+ if ( nOuterRight > nInnerRight )
+ DrawRect( Rectangle( nInnerRight, nInnerTop, nOuterRight, nInnerBottom ) );
+ if ( nInnerBottom < nOuterBottom )
+ DrawRect( Rectangle( nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom ) );
+
+ // Paint bevel border.
+ SetFillColor();
+ SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
+ if ( m_aBorder.Top() > 0 )
+ DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerLeft, nInnerBottom ) );
+ if ( m_aBorder.Left() > 0 )
+ DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerRight, nInnerTop ) );
+
+ SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
+ if ( m_aBorder.Bottom() > 0 )
+ DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerLeft, nInnerBottom ) );
+ if ( m_aBorder.Right() > 0 )
+ DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerRight, nInnerTop ) );
+
+ // Paint title bar text.
+ SetLineColor( GetSettings().GetStyleSettings().GetActiveTextColor() );
+ aTitleBarBox.Left() += 3;
+ DrawText( aTitleBarBox, impl_getTitle(), TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
+
+ // Restore original values of the output device.
+ Pop();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ String TitledDockingWindow::impl_getTitle() const
+ {
+ return m_sTitle.Len() ? m_sTitle : GetText();
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::impl_resetToolBox()
+ {
+ m_aToolbox.Clear();
+
+ // Get the closer bitmap and set it as right most button.
+ Image aImage( SfxResId( SFX_IMG_CLOSE_DOC ) );
+ Image aImageHC( SfxResId( SFX_IMG_CLOSE_DOC_HC ) );
+ m_aToolbox.InsertItem( 1,
+ GetSettings().GetStyleSettings().GetHighContrastMode()
+ ? aImageHC
+ : aImage
+ );
+ m_aToolbox.ShowItem( 1 );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ USHORT TitledDockingWindow::impl_addDropDownToolBoxItem( const String& i_rItemText, const rtl::OString& i_nHelpId, const Link& i_rCallback )
+ {
+ // Add the menu before the closer button.
+ const USHORT nItemCount( m_aToolbox.GetItemCount() );
+ const USHORT nItemId( nItemCount + 1 );
+ m_aToolbox.InsertItem( nItemId, i_rItemText, TIB_DROPDOWNONLY, nItemCount > 0 ? nItemCount - 1 : TOOLBOX_APPEND );
+ m_aToolbox.SetHelpId( nItemId, i_nHelpId );
+ m_aToolbox.SetClickHdl( i_rCallback );
+ m_aToolbox.SetDropdownClickHdl( i_rCallback );
+
+ // The tool box has likely changed its size. The title bar has to be
+ // resized.
+ impl_scheduleLayout();
+ Invalidate();
+
+ return nItemId;
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ IMPL_LINK( TitledDockingWindow, OnToolboxItemSelected, ToolBox*, pToolBox )
+ {
+ const USHORT nId = pToolBox->GetCurItemId();
+
+ if ( nId == 1 )
+ {
+ // the closer
+ EndTracking();
+ const sal_uInt16 nChildWindowId( GetChildWindow_Impl()->GetType() );
+ const SfxBoolItem aVisibility( nChildWindowId, FALSE );
+ GetBindings().GetDispatcher()->Execute(
+ nChildWindowId,
+ SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
+ &aVisibility,
+ NULL
+ );
+ }
+
+ return 0;
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::StateChanged( StateChangedType i_nType )
+ {
+ switch ( i_nType )
+ {
+ case STATE_CHANGE_INITSHOW:
+ impl_scheduleLayout();
+ break;
+ }
+ SfxDockingWindow::StateChanged( i_nType );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::EndDocking( const Rectangle& i_rRect, BOOL i_bFloatMode )
+ {
+ SfxDockingWindow::EndDocking( i_rRect, i_bFloatMode );
+
+ if ( m_aEndDockingHdl.IsSet() )
+ m_aEndDockingHdl.Call( this );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void TitledDockingWindow::DataChanged( const DataChangedEvent& i_rDataChangedEvent )
+ {
+ SfxDockingWindow::DataChanged( i_rDataChangedEvent );
+
+ switch ( i_rDataChangedEvent.GetType() )
+ {
+ case DATACHANGED_SETTINGS:
+ if ( ( i_rDataChangedEvent.GetFlags() & SETTINGS_STYLE ) == 0)
+ break;
+ // else fall through.
+ case DATACHANGED_FONTS:
+ case DATACHANGED_FONTSUBSTITUTION:
+ {
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+
+ // Font.
+ Font aFont = rStyleSettings.GetAppFont();
+ if ( IsControlFont() )
+ aFont.Merge( GetControlFont() );
+ SetZoomedPointFont( aFont );
+
+ // Color.
+ Color aColor;
+ if ( IsControlForeground() )
+ aColor = GetControlForeground();
+ else
+ aColor = rStyleSettings.GetButtonTextColor();
+ SetTextColor( aColor );
+ SetTextFillColor();
+
+ impl_scheduleLayout();
+ Invalidate();
+ }
+ break;
+ }
+ }
+
+//......................................................................................................................
+} // namespace sfx2
+//......................................................................................................................
diff --git a/sfx2/source/dialog/titledockwin.src b/sfx2/source/dialog/titledockwin.src
new file mode 100644
index 000000000000..3f52e84ab75d
--- /dev/null
+++ b/sfx2/source/dialog/titledockwin.src
@@ -0,0 +1,39 @@
+/*************************************************************************
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <sfx2/sfx.hrc>
+#include "sfxlocal.hrc"
+
+Image SFX_IMG_CLOSE_DOC
+{
+ ImageBitmap = Bitmap { File = "closedoc.png" ; };
+};
+
+Image SFX_IMG_CLOSE_DOC_HC
+{
+ ImageBitmap = Bitmap { File = "closedochc.png" ; };
+};
+
diff --git a/sfx2/source/dialog/tplcitem.cxx b/sfx2/source/dialog/tplcitem.cxx
new file mode 100644
index 000000000000..0e03106b0d5e
--- /dev/null
+++ b/sfx2/source/dialog/tplcitem.cxx
@@ -0,0 +1,185 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// INCLUDE ---------------------------------------------------------------
+
+#include <svl/intitem.hxx>
+#include <vcl/svapp.hxx>
+
+#include <sfx2/templdlg.hxx>
+#include <sfx2/bindings.hxx>
+#include "sfx2/tplpitem.hxx"
+#include "tplcitem.hxx"
+#include "templdgi.hxx"
+
+#include <sfx2/sfx.hrc>
+#include "dialog.hrc"
+
+// STATIC DATA -----------------------------------------------------------
+
+// Konstruktor
+
+SfxTemplateControllerItem::SfxTemplateControllerItem(
+ USHORT nSlotId, // ID
+ SfxCommonTemplateDialog_Impl &rDlg, // Controller-Instanz, dem dieses Item zugeordnet ist.
+ SfxBindings &rBindings):
+ SfxControllerItem(nSlotId, rBindings),
+ rTemplateDlg(rDlg),
+ nWaterCanState(0xff),
+ nUserEventId(0)
+{
+}
+// -----------------------------------------------------------------------
+SfxTemplateControllerItem::~SfxTemplateControllerItem()
+{
+ if(nUserEventId)
+ Application::RemoveUserEvent(nUserEventId);
+}
+
+// -----------------------------------------------------------------------
+
+// Benachrichtigung "uber Status"anderung; wird an den
+// im Konstruktor "ubergebenen Controller propagiert
+
+void SfxTemplateControllerItem::StateChanged( USHORT nSID, SfxItemState eState,
+ const SfxPoolItem* pItem )
+{
+ switch(nSID)
+ {
+ case SID_STYLE_FAMILY1:
+ case SID_STYLE_FAMILY2:
+ case SID_STYLE_FAMILY3:
+ case SID_STYLE_FAMILY4:
+ case SID_STYLE_FAMILY5:
+ {
+ FASTBOOL bAvailable = SFX_ITEM_AVAILABLE == eState;
+ if ( !bAvailable )
+ rTemplateDlg.SetFamilyState(GetId(), 0);
+ else {
+ const SfxTemplateItem *pStateItem = PTR_CAST(
+ SfxTemplateItem, pItem);
+ DBG_ASSERT(pStateItem != 0, "SfxTemplateItem erwartet");
+ rTemplateDlg.SetFamilyState( GetId(), pStateItem );
+ }
+ BOOL bDisable = eState == SFX_ITEM_DISABLED;
+ // Familie Disablen
+ USHORT nFamily = 0;
+ switch( GetId())
+ {
+ case SID_STYLE_FAMILY1:
+ nFamily = 1; break;
+ case SID_STYLE_FAMILY2:
+ nFamily = 2; break;
+ case SID_STYLE_FAMILY3:
+ nFamily = 3; break;
+ case SID_STYLE_FAMILY4:
+ nFamily = 4; break;
+ case SID_STYLE_FAMILY5:
+ nFamily = 5; break;
+ default: DBG_ERROR("unbekannte StyleFamily"); break;
+ }
+ rTemplateDlg.EnableFamilyItem( nFamily, !bDisable );
+ break;
+ }
+ case SID_STYLE_WATERCAN:
+ {
+ if ( eState == SFX_ITEM_DISABLED )
+ nWaterCanState = 0xff;
+ else if( eState == SFX_ITEM_AVAILABLE )
+ {
+ const SfxBoolItem *pStateItem = PTR_CAST(SfxBoolItem, pItem);
+ DBG_ASSERT(pStateItem != 0, "BoolItem erwartet");
+ nWaterCanState = pStateItem->GetValue() ? 1 : 0;
+ }
+ //not necessary if the last event is still on the way
+ if(!nUserEventId)
+ nUserEventId = Application::PostUserEvent( STATIC_LINK(
+ this, SfxTemplateControllerItem, SetWaterCanStateHdl_Impl ) );
+ break;
+ }
+ case SID_STYLE_EDIT:
+ rTemplateDlg.EnableEdit( SFX_ITEM_DISABLED != eState );
+ break;
+ case SID_STYLE_DELETE:
+ rTemplateDlg.EnableDel( SFX_ITEM_DISABLED != eState );
+ break;
+ case SID_STYLE_NEW_BY_EXAMPLE:
+
+ rTemplateDlg.EnableExample_Impl(
+ GetId(), SFX_ITEM_DISABLED != eState );
+ break;
+ case SID_STYLE_UPDATE_BY_EXAMPLE:
+ {
+ rTemplateDlg.EnableExample_Impl(
+ GetId(), eState != SFX_ITEM_DISABLED );
+ // Das Select Disabled dann, falls enabled und Style Readonly
+/* String aStr = rTemplateDlg.GetSelectedEntry();
+ if( aStr.Len() ) rTemplateDlg.SelectStyle( aStr ); */
+ break;
+ }
+ case SID_STYLE_NEW:
+ {
+ rTemplateDlg.EnableNew( SFX_ITEM_DISABLED != eState );
+ break;
+ }
+ case SID_STYLE_DRAGHIERARCHIE:
+ {
+ rTemplateDlg.EnableTreeDrag( SFX_ITEM_DISABLED != eState );
+ break;
+ }
+ case SID_STYLE_FAMILY :
+ {
+ const SfxUInt16Item *pStateItem = PTR_CAST( SfxUInt16Item, pItem);
+ if (pStateItem)
+ rTemplateDlg.SetFamily( pStateItem->GetValue() );
+ break;
+ }
+ }
+}
+/* -----------------------------05.09.2001 10:48------------------------------
+
+ ---------------------------------------------------------------------------*/
+IMPL_STATIC_LINK(SfxTemplateControllerItem, SetWaterCanStateHdl_Impl,
+ SfxTemplateControllerItem*, EMPTYARG)
+{
+ pThis->nUserEventId = 0;
+ SfxBoolItem* pState = 0;
+ switch(pThis->nWaterCanState)
+ {
+ case 0 :
+ case 1 :
+ pState = new SfxBoolItem(SID_STYLE_WATERCAN, pThis->nWaterCanState ? TRUE : FALSE);
+ break;
+ }
+ pThis->rTemplateDlg.SetWaterCanState(pState);
+ delete pState;
+ return 0;
+}
+
diff --git a/sfx2/source/dialog/tplpitem.cxx b/sfx2/source/dialog/tplpitem.cxx
new file mode 100644
index 000000000000..566c379df508
--- /dev/null
+++ b/sfx2/source/dialog/tplpitem.cxx
@@ -0,0 +1,120 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// INCLUDE ---------------------------------------------------------------
+
+#include "sfx2/tplpitem.hxx"
+#include <com/sun/star/frame/status/Template.hpp>
+
+
+// STATIC DATA -----------------------------------------------------------
+
+TYPEINIT1_AUTOFACTORY(SfxTemplateItem, SfxFlagItem);
+
+//=========================================================================
+
+SfxTemplateItem::SfxTemplateItem() :
+ SfxFlagItem()
+{
+}
+
+SfxTemplateItem::SfxTemplateItem
+(
+ USHORT nWhichId, // Slot-ID
+ const String& rStyle, // Name des aktuellen Styles
+ USHORT nValue // Flags f"ur das Filtern bei automatischer Anzeige
+) : SfxFlagItem( nWhichId, nValue ),
+ aStyle( rStyle )
+{
+}
+
+//-------------------------------------------------------------------------
+
+// copy ctor
+SfxTemplateItem::SfxTemplateItem( const SfxTemplateItem& rCopy ) :
+
+ SfxFlagItem( rCopy ),
+
+ aStyle( rCopy.aStyle )
+{
+}
+
+//-------------------------------------------------------------------------
+
+// op ==
+
+int SfxTemplateItem::operator==( const SfxPoolItem& rCmp ) const
+{
+ return ( SfxFlagItem::operator==( rCmp ) &&
+ aStyle == ( (const SfxTemplateItem&)rCmp ).aStyle );
+}
+
+//-------------------------------------------------------------------------
+
+SfxPoolItem* SfxTemplateItem::Clone( SfxItemPool *) const
+{
+ return new SfxTemplateItem(*this);
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SfxTemplateItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ ) const
+{
+ ::com::sun::star::frame::status::Template aTemplate;
+
+ aTemplate.Value = GetValue();
+ aTemplate.StyleName = aStyle;
+ rVal <<= aTemplate;
+
+ return sal_True;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SfxTemplateItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ )
+{
+ ::com::sun::star::frame::status::Template aTemplate;
+
+ if ( rVal >>= aTemplate )
+ {
+ SetValue( sal::static_int_cast< USHORT >( aTemplate.Value ) );
+ aStyle = aTemplate.StyleName;
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+
+BYTE SfxTemplateItem::GetFlagCount() const
+{
+ return sizeof(USHORT) * 8;
+}
+
+
diff --git a/sfx2/source/dialog/versdlg.cxx b/sfx2/source/dialog/versdlg.cxx
new file mode 100644
index 000000000000..f2a0cf2790f3
--- /dev/null
+++ b/sfx2/source/dialog/versdlg.cxx
@@ -0,0 +1,519 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <unotools/localedatawrapper.hxx>
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/itemset.hxx>
+#include <unotools/useroptions.hxx>
+#include <vcl/msgbox.hxx>
+#include <vcl/svapp.hxx>
+#include <tools/datetime.hxx>
+
+#define _SVSTDARR_STRINGSDTOR
+#include <svl/svstdarr.hxx>
+
+#include "versdlg.hrc"
+#include "versdlg.hxx"
+#include <sfx2/viewfrm.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/docfile.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/request.hxx>
+
+#include <sfx2/sfxuno.hxx>
+
+using namespace com::sun::star;
+
+// **************************************************************************
+struct SfxVersionInfo
+{
+ String aName;
+ String aComment;
+ String aAuthor;
+ DateTime aCreationDate;
+
+ SfxVersionInfo();
+ SfxVersionInfo( const SfxVersionInfo& rInfo )
+ { *this = rInfo; }
+
+ SfxVersionInfo& operator=( const SfxVersionInfo &rInfo )
+ {
+ aName = rInfo.aName;
+ aComment = rInfo.aComment;
+ aAuthor = rInfo.aAuthor;
+ aCreationDate = rInfo.aCreationDate;
+ return *this;
+ }
+};
+DECLARE_LIST( _SfxVersionTable, SfxVersionInfo* )
+class SfxVersionTableDtor : public _SfxVersionTable
+{
+public:
+ SfxVersionTableDtor( const sal_uInt16 nInitSz=0, const sal_uInt16 nReSz=1 )
+ : _SfxVersionTable( nInitSz, nReSz )
+ {}
+
+ SfxVersionTableDtor( const SfxVersionTableDtor &rCpy ) :
+ _SfxVersionTable( rCpy )
+ { *this = rCpy; }
+
+ SfxVersionTableDtor( const uno::Sequence < util::RevisionTag >& rInfo );
+
+ ~SfxVersionTableDtor()
+ { DelDtor(); }
+
+ SfxVersionTableDtor& operator=( const SfxVersionTableDtor &rCpy );
+ void DelDtor();
+ SvStream& Read( SvStream & );
+ SvStream& Write( SvStream & ) const;
+ SvStringsDtor* GetVersions() const;
+};
+
+SfxVersionTableDtor::SfxVersionTableDtor( const uno::Sequence < util::RevisionTag >& rInfo )
+{
+ for ( sal_Int32 n=0; n<(sal_Int32)rInfo.getLength(); n++ )
+ {
+ SfxVersionInfo* pInfo = new SfxVersionInfo;
+ pInfo->aName = rInfo[n].Identifier;
+ pInfo->aComment = rInfo[n].Comment;
+ pInfo->aAuthor = rInfo[n].Author;
+
+ Date aDate ( rInfo[n].TimeStamp.Day, rInfo[n].TimeStamp.Month, rInfo[n].TimeStamp.Year );
+ Time aTime ( rInfo[n].TimeStamp.Hours, rInfo[n].TimeStamp.Minutes, rInfo[n].TimeStamp.Seconds, rInfo[n].TimeStamp.HundredthSeconds );
+
+ pInfo->aCreationDate = DateTime( aDate, aTime );
+ Insert( pInfo, Count() );
+ }
+}
+
+void SfxVersionTableDtor::DelDtor()
+{
+ SfxVersionInfo* pTmp = First();
+ while( pTmp )
+ {
+ delete pTmp;
+ pTmp = Next();
+ }
+ Clear();
+}
+
+SfxVersionTableDtor& SfxVersionTableDtor::operator=( const SfxVersionTableDtor& rTbl )
+{
+ DelDtor();
+ SfxVersionInfo* pTmp = ((SfxVersionTableDtor&)rTbl).First();
+ while( pTmp )
+ {
+ SfxVersionInfo *pNew = new SfxVersionInfo( *pTmp );
+ Insert( pNew, LIST_APPEND );
+ pTmp = ((SfxVersionTableDtor&)rTbl).Next();
+ }
+ return *this;
+}
+
+//----------------------------------------------------------------
+//----------------------------------------------------------------
+//----------------------------------------------------------------
+SfxVersionInfo::SfxVersionInfo()
+{
+}
+
+static String ConvertDateTime_Impl(const DateTime& rTime, const LocaleDataWrapper& rWrapper)
+{
+ const String pDelim ( DEFINE_CONST_UNICODE( ", "));
+ String aStr(rWrapper.getDate(rTime));
+ aStr += pDelim;
+ aStr += rWrapper.getTime(rTime, TRUE, FALSE);
+ return aStr;
+}
+
+SvStringsDtor* SfxVersionTableDtor::GetVersions() const
+{
+ SvStringsDtor *pList = new SvStringsDtor;
+ SfxVersionInfo* pInfo = ((SfxVersionTableDtor*) this)->First();
+ LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ while ( pInfo )
+ {
+ String *pString = new String( pInfo->aComment );
+ (*pString) += DEFINE_CONST_UNICODE( "; " );
+ (*pString) += ConvertDateTime_Impl( pInfo->aCreationDate, aLocaleWrapper );
+ pList->Insert( pString, pList->Count() );
+ pInfo = ((SfxVersionTableDtor*) this)->Next();
+ }
+
+ return pList;
+}
+
+// Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert
+static long nTabs_Impl[] =
+{
+ 3, // Number of Tabs
+ 0, 62, 124
+};
+
+void SfxVersionsTabListBox_Impl::KeyInput( const KeyEvent& rKeyEvent )
+{
+ const KeyCode& rCode = rKeyEvent.GetKeyCode();
+ switch ( rCode.GetCode() )
+ {
+ case KEY_RETURN :
+ case KEY_ESCAPE :
+ case KEY_TAB :
+ Window::GetParent()->KeyInput( rKeyEvent );
+ break;
+ default:
+ SvTabListBox::KeyInput( rKeyEvent );
+ break;
+ }
+}
+
+SfxVersionsTabListBox_Impl::SfxVersionsTabListBox_Impl( Window* pParent, const ResId& rResId )
+ : SvTabListBox( pParent, rResId )
+{
+}
+
+SfxVersionDialog::SfxVersionDialog ( SfxViewFrame* pVwFrame, BOOL bIsSaveVersionOnClose )
+ : SfxModalDialog( NULL, SfxResId( DLG_VERSIONS ) )
+ , aNewGroup( this, SfxResId( GB_NEWVERSIONS ) )
+ , aSaveButton( this, SfxResId( PB_SAVE ) )
+ , aSaveCheckBox( this, SfxResId( CB_SAVEONCLOSE ) )
+ , aExistingGroup( this, SfxResId( GB_OLDVERSIONS ) )
+ , aDateTimeText( this, SfxResId( FT_DATETIME ) )
+ , aSavedByText( this, SfxResId( FT_SAVEDBY ) )
+ , aCommentText( this, SfxResId( FT_COMMENTS ) )
+ , aVersionBox( this, SfxResId( TLB_VERSIONS ) )
+ , aCloseButton( this, SfxResId( PB_CLOSE ) )
+ , aOpenButton( this, SfxResId( PB_OPEN ) )
+ , aViewButton( this, SfxResId( PB_VIEW ) )
+ , aDeleteButton( this, SfxResId( PB_DELETE ) )
+ , aCompareButton( this, SfxResId( PB_COMPARE ) )
+ , aHelpButton( this, SfxResId( PB_HELP ) )
+ , pViewFrame( pVwFrame )
+ , mpTable( NULL )
+ , mpLocaleWrapper( NULL )
+ , mbIsSaveVersionOnClose( bIsSaveVersionOnClose )
+{
+ FreeResource();
+
+ Link aClickLink = LINK( this, SfxVersionDialog, ButtonHdl_Impl );
+ aViewButton.SetClickHdl ( aClickLink );
+ aSaveButton.SetClickHdl ( aClickLink );
+ aDeleteButton.SetClickHdl ( aClickLink );
+ aCompareButton.SetClickHdl ( aClickLink );
+ aOpenButton.SetClickHdl ( aClickLink );
+ aSaveCheckBox.SetClickHdl ( aClickLink );
+
+ aVersionBox.SetSelectHdl( LINK( this, SfxVersionDialog, SelectHdl_Impl ) );
+ aVersionBox.SetDoubleClickHdl( LINK( this, SfxVersionDialog, DClickHdl_Impl ) );
+
+ aVersionBox.GrabFocus();
+ aVersionBox.SetStyle( aVersionBox.GetStyle() | WB_HSCROLL | WB_CLIPCHILDREN );
+ aVersionBox.SetSelectionMode( SINGLE_SELECTION );
+ aVersionBox.SetTabs( &nTabs_Impl[0], MAP_APPFONT );
+ aVersionBox.Resize(); // OS: Hack fuer richtige Selektion
+ RecalcDateColumn();
+
+ // set dialog title (filename or docinfo title)
+ String sText = GetText();
+ ( sText += ' ' ) += pViewFrame->GetObjectShell()->GetTitle();
+ SetText( sText );
+
+ Init_Impl();
+}
+
+String ConvertWhiteSpaces_Impl( const String& rText )
+{
+ // converted linebreaks and tabs to blanks; it's necessary for the display
+ String sConverted;
+ const sal_Unicode* pChars = rText.GetBuffer();
+ while ( *pChars )
+ {
+ switch ( *pChars )
+ {
+ case '\n' :
+ case '\t' :
+ sConverted += ' ';
+ break;
+
+ default:
+ sConverted += *pChars;
+ }
+
+ ++pChars;
+ }
+
+ return sConverted;
+}
+
+void SfxVersionDialog::Init_Impl()
+{
+ SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
+ SfxMedium* pMedium = pObjShell->GetMedium();
+ uno::Sequence < util::RevisionTag > aVersions = pMedium->GetVersionList( true );
+ delete mpTable;
+ mpTable = new SfxVersionTableDtor( aVersions );
+ {
+ for ( USHORT n = 0; n < mpTable->Count(); ++n )
+ {
+ SfxVersionInfo *pInfo = mpTable->GetObject(n);
+ String aEntry = ConvertDateTime_Impl( pInfo->aCreationDate, *mpLocaleWrapper );
+ aEntry += '\t';
+ aEntry += pInfo->aAuthor;
+ aEntry += '\t';
+ aEntry += ConvertWhiteSpaces_Impl( pInfo->aComment );
+ SvLBoxEntry *pEntry = aVersionBox.InsertEntry( aEntry );
+ pEntry->SetUserData( pInfo );
+ }
+ }
+
+ aSaveCheckBox.Check( mbIsSaveVersionOnClose );
+
+ BOOL bEnable = !pObjShell->IsReadOnly();
+ aSaveButton.Enable( bEnable );
+ aSaveCheckBox.Enable( bEnable );
+
+ aOpenButton.Disable();
+ aViewButton.Disable();
+ aDeleteButton.Disable();
+ aCompareButton.Disable();
+
+ SelectHdl_Impl( &aVersionBox );
+}
+
+SfxVersionDialog::~SfxVersionDialog ()
+{
+ delete mpTable;
+ delete mpLocaleWrapper;
+}
+
+void SfxVersionDialog::Open_Impl()
+{
+ SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
+
+ SvLBoxEntry *pEntry = aVersionBox.FirstSelected();
+ ULONG nPos = aVersionBox.GetModel()->GetRelPos( pEntry );
+ SfxInt16Item aItem( SID_VERSION, (short)nPos+1 );
+ SfxStringItem aTarget( SID_TARGETNAME, DEFINE_CONST_UNICODE("_blank") );
+ SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE("private:user") );
+ SfxStringItem aFile( SID_FILE_NAME, pObjShell->GetMedium()->GetName() );
+
+ uno::Sequence< beans::NamedValue > aEncryptionData;
+ if ( GetEncryptionData_Impl( pObjShell->GetMedium()->GetItemSet(), aEncryptionData ) )
+ {
+ // there is a password, it should be used during the opening
+ SfxUnoAnyItem aEncryptionDataItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) );
+ pViewFrame->GetDispatcher()->Execute(
+ SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aFile, &aItem, &aTarget, &aReferer, &aEncryptionDataItem, 0L );
+ }
+ else
+ pViewFrame->GetDispatcher()->Execute(
+ SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aFile, &aItem, &aTarget, &aReferer, 0L );
+
+ Close();
+}
+
+void SfxVersionDialog::RecalcDateColumn()
+{
+ // recalculate the datetime column width
+ DateTime aNow;
+ mpLocaleWrapper = new LocaleDataWrapper(
+ ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ String sDateTime = ConvertDateTime_Impl( aNow, *mpLocaleWrapper );
+ long nWidth = aVersionBox.GetTextWidth( sDateTime );
+ nWidth += 15; // a little offset
+ long nTab = aVersionBox.GetTab(1);
+ if ( nWidth > nTab )
+ {
+ // resize columns
+ long nDelta = nWidth - nTab;
+ aVersionBox.SetTab( 1, nTab + nDelta, MAP_PIXEL );
+ nTab = aVersionBox.GetTab(2);
+ aVersionBox.SetTab( 2, nTab + nDelta, MAP_PIXEL );
+
+ // resize and move header
+ Size aSize = aDateTimeText.GetSizePixel();
+ aSize.Width() += nDelta;
+ aDateTimeText.SetSizePixel( aSize );
+ Point aPos = aSavedByText.GetPosPixel();
+ aPos.X() += nDelta;
+ aSavedByText.SetPosPixel( aPos );
+ aPos = aCommentText.GetPosPixel();
+ aPos.X() += nDelta;
+ aCommentText.SetPosPixel( aPos );
+ }
+}
+
+IMPL_LINK( SfxVersionDialog, DClickHdl_Impl, Control*, EMPTYARG )
+{
+ Open_Impl();
+ return 0L;
+}
+
+IMPL_LINK( SfxVersionDialog, SelectHdl_Impl, Control*, EMPTYARG )
+{
+ bool bEnable = ( aVersionBox.FirstSelected() != NULL );
+ SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
+ aDeleteButton.Enable( bEnable!= false && !pObjShell->IsReadOnly() );
+ aOpenButton.Enable( bEnable!= false );
+ aViewButton.Enable( bEnable!= false );
+
+ const SfxPoolItem *pDummy=NULL;
+ SfxItemState eState = pViewFrame->GetDispatcher()->QueryState( SID_DOCUMENT_MERGE, pDummy );
+ eState = pViewFrame->GetDispatcher()->QueryState( SID_DOCUMENT_COMPARE, pDummy );
+ aCompareButton.Enable( bEnable!= false && eState >= SFX_ITEM_AVAILABLE );
+
+ return 0L;
+}
+
+IMPL_LINK( SfxVersionDialog, ButtonHdl_Impl, Button*, pButton )
+{
+ SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
+ SvLBoxEntry *pEntry = aVersionBox.FirstSelected();
+
+ if ( pButton == &aSaveCheckBox )
+ {
+ mbIsSaveVersionOnClose = aSaveCheckBox.IsChecked();
+ }
+ else if ( pButton == &aSaveButton )
+ {
+ SfxVersionInfo aInfo;
+ aInfo.aAuthor = SvtUserOptions().GetFullName();
+ SfxViewVersionDialog_Impl* pDlg = new SfxViewVersionDialog_Impl( this, aInfo, TRUE );
+ short nRet = pDlg->Execute();
+ if ( nRet == RET_OK )
+ {
+ SfxStringItem aComment( SID_DOCINFO_COMMENTS, aInfo.aComment );
+ pObjShell->SetModified( TRUE );
+ const SfxPoolItem* aItems[2];
+ aItems[0] = &aComment;
+ aItems[1] = NULL;
+ pViewFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, aItems, 0 );
+ aVersionBox.SetUpdateMode( FALSE );
+ aVersionBox.Clear();
+ Init_Impl();
+ aVersionBox.SetUpdateMode( TRUE );
+ }
+
+ delete pDlg;
+ }
+ if ( pButton == &aDeleteButton && pEntry )
+ {
+ pObjShell->GetMedium()->RemoveVersion_Impl( ((SfxVersionInfo*) pEntry->GetUserData())->aName );
+ pObjShell->SetModified( TRUE );
+ aVersionBox.SetUpdateMode( FALSE );
+ aVersionBox.Clear();
+ Init_Impl();
+ aVersionBox.SetUpdateMode( TRUE );
+ }
+ else if ( pButton == &aOpenButton && pEntry )
+ {
+ Open_Impl();
+ }
+ else if ( pButton == &aViewButton && pEntry )
+ {
+ SfxVersionInfo* pInfo = (SfxVersionInfo*) pEntry->GetUserData();
+ SfxViewVersionDialog_Impl* pDlg = new SfxViewVersionDialog_Impl( this, *pInfo, FALSE );
+ pDlg->Execute();
+ delete pDlg;
+ }
+ else if ( pEntry && pButton == &aCompareButton )
+ {
+ SfxAllItemSet aSet( pObjShell->GetPool() );
+ ULONG nPos = aVersionBox.GetModel()->GetRelPos( pEntry );
+ aSet.Put( SfxInt16Item( SID_VERSION, (short)nPos+1 ) );
+ aSet.Put( SfxStringItem( SID_FILE_NAME, pObjShell->GetMedium()->GetName() ) );
+
+ SfxItemSet* pSet = pObjShell->GetMedium()->GetItemSet();
+ SFX_ITEMSET_ARG( pSet, pFilterItem, SfxStringItem, SID_FILTER_NAME, FALSE );
+ SFX_ITEMSET_ARG( pSet, pFilterOptItem, SfxStringItem, SID_FILE_FILTEROPTIONS, FALSE );
+ if ( pFilterItem )
+ aSet.Put( *pFilterItem );
+ if ( pFilterOptItem )
+ aSet.Put( *pFilterOptItem );
+
+ pViewFrame->GetDispatcher()->Execute( SID_DOCUMENT_COMPARE, SFX_CALLMODE_ASYNCHRON, aSet );
+ Close();
+ }
+
+ return 0L;
+}
+
+SfxViewVersionDialog_Impl::SfxViewVersionDialog_Impl ( Window *pParent, SfxVersionInfo& rInfo, BOOL bEdit )
+ : SfxModalDialog( pParent, SfxResId( DLG_COMMENTS ) )
+ , aDateTimeText( this, SfxResId( FT_DATETIME ) )
+ , aSavedByText( this, SfxResId( FT_SAVEDBY ) )
+ , aEdit( this, SfxResId( ME_VERSIONS ) )
+ , aOKButton( this, SfxResId( PB_OK ) )
+ , aCancelButton( this, SfxResId( PB_CANCEL ) )
+ , aCloseButton( this, SfxResId( PB_CLOSE ) )
+ , aHelpButton( this, SfxResId( PB_HELP ) )
+ , pInfo( &rInfo )
+{
+ FreeResource();
+
+ LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ aDateTimeText.SetText( aDateTimeText.GetText().Append(ConvertDateTime_Impl( pInfo->aCreationDate, aLocaleWrapper )) );
+ aSavedByText.SetText( aSavedByText.GetText().Append(pInfo->aAuthor) );
+ aEdit.SetText( rInfo.aComment );
+
+ aCloseButton.SetClickHdl ( LINK( this, SfxViewVersionDialog_Impl, ButtonHdl ) );
+ aOKButton.SetClickHdl ( LINK( this, SfxViewVersionDialog_Impl, ButtonHdl ) );
+
+ aEdit.GrabFocus();
+ if ( !bEdit )
+ {
+ aOKButton.Hide();
+ aCancelButton.Hide();
+ aEdit.SetReadOnly( TRUE );
+ }
+ else
+ aCloseButton.Hide();
+}
+
+IMPL_LINK( SfxViewVersionDialog_Impl, ButtonHdl, Button*, pButton )
+{
+ if ( pButton == &aCloseButton )
+ {
+ EndDialog( RET_CANCEL );
+ }
+ else if ( pButton == &aOKButton )
+ {
+ pInfo->aComment = aEdit.GetText();
+ EndDialog( RET_OK );
+ }
+
+ return 0L;
+}
+
diff --git a/sfx2/source/dialog/versdlg.hrc b/sfx2/source/dialog/versdlg.hrc
new file mode 100644
index 000000000000..2de7596221e1
--- /dev/null
+++ b/sfx2/source/dialog/versdlg.hrc
@@ -0,0 +1,48 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <dialog.hrc>
+
+#define GB_NEWVERSIONS 1
+#define PB_SAVE 2
+#define CB_SAVEONCLOSE 3
+#define TLB_VERSIONS 4
+#define PB_DELETE 5
+#define PB_OPEN 6
+#define PB_HELP 7
+#define PB_CLOSE 8
+#define GB_OLDVERSIONS 9
+#define FT_DATETIME 10
+#define FT_SAVEDBY 11
+#define FT_COMMENTS 12
+#define PB_VIEW 13
+#define ME_VERSIONS 14
+#define PB_OK 15
+#define PB_CANCEL 16
+#define PB_COMPARE 17
+#define PB_MERGE 18
+
diff --git a/sfx2/source/dialog/versdlg.src b/sfx2/source/dialog/versdlg.src
new file mode 100644
index 000000000000..927c940e6506
--- /dev/null
+++ b/sfx2/source/dialog/versdlg.src
@@ -0,0 +1,222 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "versdlg.hrc"
+ModalDialog DLG_VERSIONS
+{
+ HelpID = "sfx2:ModalDialog:DLG_VERSIONS";
+ OutputSize = TRUE ;
+ Size = MAP_APPFONT ( 340 , 184 ) ;
+ SvLook = TRUE ;
+ Moveable = TRUE ;
+//! Closeable = TRUE ;
+ FixedLine GB_NEWVERSIONS
+ {
+ Pos = MAP_APPFONT ( 6 , 3 ) ;
+ Size = MAP_APPFONT ( 272 , 8 ) ;
+ Text [ en-US ] = "New versions" ;
+ };
+ PushButton PB_SAVE
+ {
+ HelpID = "sfx2:PushButton:DLG_VERSIONS:PB_SAVE";
+ Pos = MAP_APPFONT ( 12 , 14 ) ;
+ Size = MAP_APPFONT ( 90 , 14 ) ;
+ TabStop = TRUE ;
+ Text [ en-US ] = "Save ~New Version" ;
+ };
+ CheckBox CB_SAVEONCLOSE
+ {
+ HelpID = "sfx2:CheckBox:DLG_VERSIONS:CB_SAVEONCLOSE";
+ Pos = MAP_APPFONT ( 108 , 16 ) ;
+ Size = MAP_APPFONT ( 164 , 10 ) ;
+ TabStop = TRUE ;
+ Text [ en-US ] = "~Always save a version on closing" ;
+ };
+ FixedLine GB_OLDVERSIONS
+ {
+ Pos = MAP_APPFONT ( 6 , 34 ) ;
+ Size = MAP_APPFONT ( 272 , 8 ) ;
+ Text [ en-US ] = "Existing versions" ;
+ };
+ FixedText FT_DATETIME
+ {
+ Pos = MAP_APPFONT ( 15 , 45 ) ;
+ Size = MAP_APPFONT ( 60 , 10 ) ;
+ Text [ en-US ] = "Date and time" ;
+ };
+ FixedText FT_SAVEDBY
+ {
+ Pos = MAP_APPFONT ( 76 , 45 ) ;
+ Size = MAP_APPFONT ( 60 , 10 ) ;
+ Text [ en-US ] = "Saved by" ;
+ };
+ FixedText FT_COMMENTS
+ {
+ Pos = MAP_APPFONT ( 138 , 45 ) ;
+ Size = MAP_APPFONT ( 60 , 10 ) ;
+ Text [ en-US ] = "Comments" ;
+ };
+ Control TLB_VERSIONS
+ {
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 12 , 58 ) ;
+ Size = MAP_APPFONT ( 260 , 114 ) ;
+ TabStop = TRUE ;
+ };
+ CancelButton PB_CLOSE
+ {
+ Pos = MAP_APPFONT ( 284 , 6 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ Text [ en-US ] = "Close" ;
+ };
+ PushButton PB_OPEN
+ {
+ HelpID = "sfx2:PushButton:DLG_VERSIONS:PB_OPEN";
+ Pos = MAP_APPFONT ( 284 , 26 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ Text [ en-US ] = "Open" ;
+ };
+ PushButton PB_VIEW
+ {
+ HelpID = "sfx2:PushButton:DLG_VERSIONS:PB_VIEW";
+ Pos = MAP_APPFONT ( 284 , 43 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ DefButton = TRUE ;
+ Text [ en-US ] = "~Show..." ;
+ };
+ PushButton PB_DELETE
+ {
+ HelpID = "sfx2:PushButton:DLG_VERSIONS:PB_DELETE";
+ Pos = MAP_APPFONT ( 284 , 60 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ Text [ en-US ] = "~Delete" ;
+ };
+ PushButton PB_COMPARE
+ {
+ HelpID = "sfx2:PushButton:DLG_VERSIONS:PB_COMPARE";
+ Pos = MAP_APPFONT ( 284 , 77 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ Text [ en-US ] = "Compare" ;
+ };
+ HelpButton PB_HELP
+ {
+ Pos = MAP_APPFONT ( 284 , 97 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ };
+ Text [ en-US ] = "Versions of" ;
+};
+ModalDialog DLG_COMMENTS
+{
+ HelpID = "sfx2:ModalDialog:DLG_COMMENTS";
+ OutputSize = TRUE ;
+ Size = MAP_APPFONT ( 180 , 118 ) ;
+ SvLook = TRUE ;
+ Moveable = TRUE ;
+ FixedText FT_DATETIME
+ {
+ Pos = MAP_APPFONT ( 6 , 6 ) ;
+ Size = MAP_APPFONT ( 168 , 10 ) ;
+ Text [ en-US ] = "Date and time : " ;
+ };
+ FixedText FT_SAVEDBY
+ {
+ Pos = MAP_APPFONT ( 6 , 19 ) ;
+ Size = MAP_APPFONT ( 168 , 10 ) ;
+ Text [ en-US ] = "Saved by " ;
+ };
+ MultiLineEdit ME_VERSIONS
+ {
+ HelpID = "sfx2:MultiLineEdit:DLG_COMMENTS:ME_VERSIONS";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 32 ) ;
+ Size = MAP_APPFONT ( 168 , 60 ) ;
+ TabStop = TRUE ;
+ };
+ OKButton PB_OK
+ {
+ Pos = MAP_APPFONT ( 15 , 98 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ DefButton = TRUE ;
+ };
+ CancelButton PB_CANCEL
+ {
+ Pos = MAP_APPFONT ( 68 , 98 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ };
+ PushButton PB_CLOSE
+ {
+ HelpID = "sfx2:PushButton:DLG_COMMENTS:PB_CLOSE";
+ Pos = MAP_APPFONT ( 68 , 98 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ Text [ en-US ] = "~Close" ;
+ };
+ HelpButton PB_HELP
+ {
+ Pos = MAP_APPFONT ( 124 , 98 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ TabStop = TRUE ;
+ };
+ Text [ en-US ] = "Insert Version Comment" ;
+};
+String DLG_COMMENTS
+{
+ Text [ en-US ] = "Version comment" ;
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/doc/DocumentMetadataAccess.cxx b/sfx2/source/doc/DocumentMetadataAccess.cxx
new file mode 100644
index 000000000000..df0781be8877
--- /dev/null
+++ b/sfx2/source/doc/DocumentMetadataAccess.cxx
@@ -0,0 +1,1432 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_sfx2.hxx"
+
+#include <sfx2/DocumentMetadataAccess.hxx>
+
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/task/ErrorCodeIOException.hpp>
+#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
+#include <com/sun/star/rdf/FileFormat.hpp>
+#include <com/sun/star/rdf/URIs.hpp>
+#include <com/sun/star/rdf/Statement.hpp>
+#include <com/sun/star/rdf/Literal.hpp>
+#include <com/sun/star/rdf/URI.hpp>
+#include <com/sun/star/rdf/Repository.hpp>
+
+#include <rtl/uuid.h>
+#include <rtl/ustrbuf.hxx>
+#include <rtl/uri.hxx>
+#include <rtl/bootstrap.hxx>
+
+#include <comphelper/interaction.hxx>
+#include <comphelper/makesequence.hxx>
+#include <comphelper/mediadescriptor.hxx>
+#include <comphelper/sequenceasvector.hxx>
+#include <comphelper/storagehelper.hxx>
+
+#include <sfx2/docfile.hxx>
+#include <sfx2/XmlIdRegistry.hxx>
+
+#include <libxml/tree.h> // for xmlValidateNCName
+
+#include <boost/bind.hpp>
+#include <boost/shared_array.hpp>
+#include <boost/tuple/tuple.hpp>
+
+#include <vector>
+#include <set>
+#include <map>
+#include <functional>
+#include <algorithm>
+
+#include <unotools/ucbhelper.hxx>
+#include <com/sun/star/uri/XUriReference.hpp>
+#include <com/sun/star/uri/XUriReferenceFactory.hpp>
+#include <com/sun/star/uri/XVndSunStarPkgUrlReferenceFactory.hpp>
+
+
+/*
+ Note: in the context of this implementation, all rdf.QueryExceptions and
+ rdf.RepositoryExceptions are RuntimeExceptions, and will be reported as such.
+
+ This implementation assumes that it is only used with ODF documents, not mere
+ ODF packages. In other words, we enforce that metadata files must not be
+ called reserved names.
+ */
+
+using namespace ::com::sun::star;
+
+namespace sfx2 {
+
+
+bool isValidNCName(::rtl::OUString const & i_rIdref)
+{
+ const ::rtl::OString id(
+ ::rtl::OUStringToOString(i_rIdref, RTL_TEXTENCODING_UTF8) );
+ return !(xmlValidateNCName(
+ reinterpret_cast<const unsigned char*>(id.getStr()), 0));
+}
+
+////////////////////////////////////////////////////////////////////////////
+
+static const char s_content [] = "content.xml";
+static const char s_styles [] = "styles.xml";
+static const char s_meta [] = "meta.xml";
+static const char s_settings[] = "settings.xml";
+static const char s_manifest[] = "manifest.rdf";
+static const char s_rdfxml [] = "application/rdf+xml";
+static const char s_odfmime [] = "application/vnd.oasis.opendocument.";
+
+////////////////////////////////////////////////////////////////////////////
+
+static bool isContentFile(::rtl::OUString const & i_rPath)
+{
+ return i_rPath.equalsAscii(s_content);
+}
+
+static bool isStylesFile (::rtl::OUString const & i_rPath)
+{
+ return i_rPath.equalsAscii(s_styles);
+}
+
+static bool isReservedFile(::rtl::OUString const & i_rPath)
+{
+ return isContentFile(i_rPath)
+ || isStylesFile(i_rPath)
+ || i_rPath.equalsAscii(s_meta)
+ || i_rPath.equalsAscii(s_settings);
+}
+
+////////////////////////////////////////////////////////////////////////////
+
+uno::Reference<rdf::XURI> createBaseURI(
+ uno::Reference<uno::XComponentContext> const & i_xContext,
+ uno::Reference<embed::XStorage> const & i_xStorage,
+ ::rtl::OUString const & i_rPkgURI, ::rtl::OUString const & i_rSubDocument)
+{
+ if (!i_xContext.is() || !i_xStorage.is() || !i_rPkgURI.getLength()) {
+ throw uno::RuntimeException();
+ }
+
+ // #i108078# workaround non-hierarchical vnd.sun.star.expand URIs
+ // this really should be done somewhere else, not here.
+ ::rtl::OUString pkgURI(i_rPkgURI);
+ if (pkgURI.matchIgnoreAsciiCaseAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:")))
+ {
+ // expand it here (makeAbsolute requires hierarchical URI)
+ pkgURI = pkgURI.copy( RTL_CONSTASCII_LENGTH("vnd.sun.star.expand:") );
+ if (pkgURI.getLength() != 0) {
+ pkgURI = ::rtl::Uri::decode(
+ pkgURI, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8);
+ if (pkgURI.getLength() == 0) {
+ throw uno::RuntimeException();
+ }
+ ::rtl::Bootstrap::expandMacros(pkgURI);
+ }
+ }
+
+ const uno::Reference<lang::XMultiComponentFactory> xServiceFactory(
+ i_xContext->getServiceManager(), uno::UNO_SET_THROW);
+ const uno::Reference<uri::XUriReferenceFactory> xUriFactory(
+ xServiceFactory->createInstanceWithContext(
+ ::rtl::OUString::createFromAscii(
+ "com.sun.star.uri.UriReferenceFactory"), i_xContext),
+ uno::UNO_QUERY_THROW);
+ uno::Reference< uri::XUriReference > xBaseURI;
+
+ const uno::Reference< uri::XUriReference > xPkgURI(
+ xUriFactory->parse(pkgURI), uno::UNO_SET_THROW );
+ xPkgURI->clearFragment();
+
+ // need to know whether the storage is a FileSystemStorage
+ // XServiceInfo would be better, but it is not implemented
+// if ( pkgURI.getLength() && ::utl::UCBContentHelper::IsFolder(pkgURI) )
+ if (true) {
+ xBaseURI.set( xPkgURI, uno::UNO_SET_THROW );
+#if 0
+ } else {
+ const uno::Reference<uri::XVndSunStarPkgUrlReferenceFactory>
+ xPkgUriFactory( xServiceFactory->createInstanceWithContext(
+ ::rtl::OUString::createFromAscii(
+ "com.sun.star.uri.VndSunStarPkgUrlReferenceFactory"),
+ i_xContext),
+ uno::UNO_QUERY_THROW);
+ xBaseURI.set( xPkgUriFactory->createVndSunStarPkgUrlReference(xPkgURI),
+ uno::UNO_SET_THROW );
+#endif
+ }
+ ::rtl::OUStringBuffer buf;
+ if (!xBaseURI->getUriReference().endsWithAsciiL("/", 1))
+ {
+ const sal_Int32 count( xBaseURI->getPathSegmentCount() );
+ if (count > 0)
+ {
+ const ::rtl::OUString last( xBaseURI->getPathSegment(count - 1) );
+ buf.append(last);
+ }
+ buf.append(static_cast<sal_Unicode>('/'));
+ }
+ if (i_rSubDocument.getLength())
+ {
+ buf.append(i_rSubDocument);
+ buf.append(static_cast<sal_Unicode>('/'));
+ }
+ const ::rtl::OUString Path(buf.makeStringAndClear());
+ if (Path.getLength())
+ {
+ const uno::Reference< uri::XUriReference > xPathURI(
+ xUriFactory->parse(Path), uno::UNO_SET_THROW );
+ xBaseURI.set(
+ xUriFactory->makeAbsolute(xBaseURI, xPathURI,
+ true, uri::RelativeUriExcessParentSegments_ERROR),
+ uno::UNO_SET_THROW);
+ }
+
+ return rdf::URI::create(i_xContext, xBaseURI->getUriReference());
+}
+
+////////////////////////////////////////////////////////////////////////////
+
+struct DocumentMetadataAccess_Impl
+{
+ // note: these are all initialized in constructor, and loadFromStorage
+ const uno::Reference<uno::XComponentContext> m_xContext;
+ const IXmlIdRegistrySupplier & m_rXmlIdRegistrySupplier;
+ uno::Reference<rdf::XURI> m_xBaseURI;
+ uno::Reference<rdf::XRepository> m_xRepository;
+ uno::Reference<rdf::XNamedGraph> m_xManifest;
+ DocumentMetadataAccess_Impl(
+ uno::Reference<uno::XComponentContext> const& i_xContext,
+ IXmlIdRegistrySupplier const & i_rRegistrySupplier)
+ : m_xContext(i_xContext)
+ , m_rXmlIdRegistrySupplier(i_rRegistrySupplier)
+ , m_xBaseURI()
+ , m_xRepository()
+ , m_xManifest()
+ {
+ OSL_ENSURE(m_xContext.is(), "context null");
+ }
+};
+
+// this is... a hack.
+template<sal_Int16 Constant>
+/*static*/ uno::Reference<rdf::XURI>
+getURI(uno::Reference< uno::XComponentContext > const & i_xContext)
+{
+ static uno::Reference< rdf::XURI > xURI(
+ rdf::URI::createKnown(i_xContext, Constant), uno::UNO_QUERY_THROW);
+ return xURI;
+}
+
+
+/** would storing the file to a XStorage succeed? */
+static bool isFileNameValid(const ::rtl::OUString & i_rFileName)
+{
+ if (i_rFileName.getLength() <= 0) return false;
+ if (i_rFileName[0] == '/') return false; // no absolute paths!
+ sal_Int32 idx(0);
+ do {
+ const ::rtl::OUString segment(
+ i_rFileName.getToken(0, static_cast<sal_Unicode> ('/'), idx) );
+ if (!segment.getLength() || // no empty segments
+ segment.equalsAscii(".") || // no . segments
+ segment.equalsAscii("..") || // no .. segments
+ !::comphelper::OStorageHelper::IsValidZipEntryFileName(
+ segment, sal_False)) // no invalid characters
+ return false;
+ } while (idx >= 0);
+ return true;
+}
+
+/** split a uri hierarchy into first segment and rest */
+static bool
+splitPath(::rtl::OUString const & i_rPath,
+ ::rtl::OUString & o_rDir, ::rtl::OUString& o_rRest)
+{
+ const sal_Int32 idx(i_rPath.indexOf(static_cast<sal_Unicode>('/')));
+ if (idx < 0 || idx >= i_rPath.getLength()) {
+ o_rDir = ::rtl::OUString();
+ o_rRest = i_rPath;
+ return true;
+ } else if (idx == 0 || idx == i_rPath.getLength() - 1) {
+ // input must not start or end with '/'
+ return false;
+ } else {
+ o_rDir = (i_rPath.copy(0, idx));
+ o_rRest = (i_rPath.copy(idx+1));
+ return true;
+ }
+}
+
+static bool
+splitXmlId(::rtl::OUString const & i_XmlId,
+ ::rtl::OUString & o_StreamName, ::rtl::OUString& o_Idref )
+{
+ const sal_Int32 idx(i_XmlId.indexOf(static_cast<sal_Unicode>('#')));
+ if ((idx <= 0) || (idx >= i_XmlId.getLength() - 1)) {
+ return false;
+ } else {
+ o_StreamName = (i_XmlId.copy(0, idx));
+ o_Idref = (i_XmlId.copy(idx+1));
+ return isValidXmlId(o_StreamName, o_Idref);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////
+
+static uno::Reference<rdf::XURI>
+getURIForStream(struct DocumentMetadataAccess_Impl& i_rImpl,
+ ::rtl::OUString const& i_rPath)
+{
+ const uno::Reference<rdf::XURI> xURI(
+ rdf::URI::createNS( i_rImpl.m_xContext,
+ i_rImpl.m_xBaseURI->getStringValue(), i_rPath),
+ uno::UNO_SET_THROW);
+ return xURI;
+}
+
+/** add statements declaring i_xResource to be a file of type i_xType with
+ path i_rPath to manifest, with optional additional types i_pTypes */
+static void
+addFile(struct DocumentMetadataAccess_Impl & i_rImpl,
+ uno::Reference<rdf::XURI> const& i_xType,
+ ::rtl::OUString const & i_rPath,
+ const uno::Sequence < uno::Reference< rdf::XURI > > * i_pTypes = 0)
+{
+ try {
+ const uno::Reference<rdf::XURI> xURI( getURIForStream(
+ i_rImpl, i_rPath) );
+
+ i_rImpl.m_xManifest->addStatement(i_rImpl.m_xBaseURI.get(),
+ getURI<rdf::URIs::PKG_HASPART>(i_rImpl.m_xContext),
+ xURI.get());
+ i_rImpl.m_xManifest->addStatement(xURI.get(),
+ getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext),
+ i_xType.get());
+ if (i_pTypes) {
+ for (sal_Int32 i = 0; i < i_pTypes->getLength(); ++i) {
+ i_rImpl.m_xManifest->addStatement(xURI.get(),
+ getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext),
+ (*i_pTypes)[i].get());
+ }
+ }
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "addFile: exception"), /*this*/0, uno::makeAny(e));
+ }
+}
+
+/** add content.xml or styles.xml to manifest */
+static bool
+addContentOrStylesFileImpl(struct DocumentMetadataAccess_Impl & i_rImpl,
+ const ::rtl::OUString & i_rPath)
+{
+ uno::Reference<rdf::XURI> xType;
+ if (isContentFile(i_rPath)) {
+ xType.set(getURI<rdf::URIs::ODF_CONTENTFILE>(i_rImpl.m_xContext));
+ } else if (isStylesFile(i_rPath)) {
+ xType.set(getURI<rdf::URIs::ODF_STYLESFILE>(i_rImpl.m_xContext));
+ } else {
+ return false;
+ }
+ addFile(i_rImpl, xType.get(), i_rPath);
+ return true;
+}
+
+/** add metadata file to manifest */
+static void
+addMetadataFileImpl(struct DocumentMetadataAccess_Impl & i_rImpl,
+ const ::rtl::OUString & i_rPath,
+ const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
+{
+ addFile(i_rImpl,
+ getURI<rdf::URIs::PKG_METADATAFILE>(i_rImpl.m_xContext),
+ i_rPath, &i_rTypes);
+}
+
+/** remove a file from the manifest */
+static void
+removeFile(struct DocumentMetadataAccess_Impl & i_rImpl,
+ uno::Reference<rdf::XURI> const& i_xPart)
+{
+ if (!i_xPart.is()) throw uno::RuntimeException();
+ try {
+ i_rImpl.m_xManifest->removeStatements(i_rImpl.m_xBaseURI.get(),
+ getURI<rdf::URIs::PKG_HASPART>(i_rImpl.m_xContext),
+ i_xPart.get());
+ i_rImpl.m_xManifest->removeStatements(i_xPart.get(),
+ getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext), 0);
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii("removeFile: exception"),
+ 0, uno::makeAny(e));
+ }
+}
+
+static ::std::vector< uno::Reference< rdf::XURI > >
+getAllParts(struct DocumentMetadataAccess_Impl & i_rImpl)
+{
+ ::std::vector< uno::Reference< rdf::XURI > > ret;
+ try {
+ const uno::Reference<container::XEnumeration> xEnum(
+ i_rImpl.m_xManifest->getStatements( i_rImpl.m_xBaseURI.get(),
+ getURI<rdf::URIs::PKG_HASPART>(i_rImpl.m_xContext), 0),
+ uno::UNO_SET_THROW);
+ while (xEnum->hasMoreElements()) {
+ rdf::Statement stmt;
+ if (!(xEnum->nextElement() >>= stmt)) {
+ throw uno::RuntimeException();
+ }
+ const uno::Reference<rdf::XURI> xPart(stmt.Object,
+ uno::UNO_QUERY);
+ if (!xPart.is()) continue;
+ ret.push_back(xPart);
+ }
+ return ret;
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii("getAllParts: exception"),
+ 0, uno::makeAny(e));
+ }
+}
+
+static bool
+isPartOfType(struct DocumentMetadataAccess_Impl & i_rImpl,
+ uno::Reference<rdf::XURI> const & i_xPart,
+ uno::Reference<rdf::XURI> const & i_xType)
+{
+ if (!i_xPart.is() || !i_xType.is()) throw uno::RuntimeException();
+ try {
+ const uno::Reference<container::XEnumeration> xEnum(
+ i_rImpl.m_xManifest->getStatements(i_xPart.get(),
+ getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext),
+ i_xType.get()),
+ uno::UNO_SET_THROW);
+ return (xEnum->hasMoreElements());
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii("isPartOfType: exception"),
+ 0, uno::makeAny(e));
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////
+
+static ucb::InteractiveAugmentedIOException
+mkException( ::rtl::OUString const & i_rMessage,
+ ucb::IOErrorCode const i_ErrorCode,
+ ::rtl::OUString const & i_rUri, ::rtl::OUString const & i_rResource)
+{
+ ucb::InteractiveAugmentedIOException iaioe;
+ iaioe.Message = i_rMessage;
+ iaioe.Classification = task::InteractionClassification_ERROR;
+ iaioe.Code = i_ErrorCode;
+
+ const beans::PropertyValue uriProp(::rtl::OUString::createFromAscii("Uri"),
+ -1, uno::makeAny(i_rUri), static_cast<beans::PropertyState>(0));
+ const beans::PropertyValue rnProp(
+ ::rtl::OUString::createFromAscii("ResourceName"),
+ -1, uno::makeAny(i_rResource), static_cast<beans::PropertyState>(0));
+ iaioe.Arguments = ::comphelper::makeSequence(
+ uno::makeAny(uriProp), uno::makeAny(rnProp));
+ return iaioe;
+}
+
+/** error handling policy.
+ <p>If a handler is given, ask it how to proceed:
+ <ul><li>(default:) cancel import, raise exception</li>
+ <li>ignore the error and continue</li>
+ <li>retry the action that led to the error</li></ul></p>
+ N.B.: must not be called before DMA is fully initalized!
+ @returns true iff caller should retry
+ */
+static bool
+handleError( ucb::InteractiveAugmentedIOException const & i_rException,
+ const uno::Reference<task::XInteractionHandler> & i_xHandler)
+{
+ if (!i_xHandler.is()) {
+ throw lang::WrappedTargetException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromStorage: exception"),
+ /* *this*/ 0, uno::makeAny(i_rException));
+ }
+
+ ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest(
+ new ::comphelper::OInteractionRequest(uno::makeAny(i_rException)) );
+ ::rtl::Reference< ::comphelper::OInteractionRetry > pRetry(
+ new ::comphelper::OInteractionRetry );
+ ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove(
+ new ::comphelper::OInteractionApprove );
+ ::rtl::Reference< ::comphelper::OInteractionAbort > pAbort(
+ new ::comphelper::OInteractionAbort );
+ /* this does not seem to work
+ if (i_rException.Code != ucb::IOErrorCode_WRONG_FORMAT) {
+ pRequest->addContinuation( pRetry.get() );
+ }
+ */
+ pRequest->addContinuation( pApprove.get() );
+ pRequest->addContinuation( pAbort.get() );
+ // actually call the handler
+ i_xHandler->handle( pRequest.get() );
+ if (pRetry->wasSelected()) {
+ return true;
+ } else if (pApprove->wasSelected()) {
+ return false;
+ } else {
+ OSL_ENSURE(pAbort->wasSelected(), "no continuation selected?");
+ throw lang::WrappedTargetException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromStorage: exception"),
+ /* *this*/ 0, uno::makeAny(i_rException));
+ }
+}
+
+/** check if storage has content.xml/styles.xml;
+ e.g. ODB files seem to only have content.xml */
+static void
+collectFilesFromStorage(uno::Reference<embed::XStorage> const& i_xStorage,
+ ::rtl::OUString i_Path,
+ std::set< ::rtl::OUString > & o_rFiles)
+{
+ static ::rtl::OUString content(::rtl::OUString::createFromAscii(s_content));
+ static ::rtl::OUString styles (::rtl::OUString::createFromAscii(s_styles ));
+ try {
+ if (i_xStorage->hasByName(content) &&
+ i_xStorage->isStreamElement(content))
+ {
+ o_rFiles.insert(i_Path + content);
+ }
+ if (i_xStorage->hasByName(styles) &&
+ i_xStorage->isStreamElement(styles))
+ {
+ o_rFiles.insert(i_Path + styles);
+ }
+ } catch (uno::Exception &) {
+ OSL_TRACE("collectFilesFromStorage: exception?");
+ }
+}
+
+/** import a metadata file into repository */
+static void
+readStream(struct DocumentMetadataAccess_Impl & i_rImpl,
+ uno::Reference< embed::XStorage > const & i_xStorage,
+ ::rtl::OUString const & i_rPath,
+ ::rtl::OUString const & i_rBaseURI)
+{
+ ::rtl::OUString dir;
+ ::rtl::OUString rest;
+ try {
+ if (!splitPath(i_rPath, dir, rest)) throw uno::RuntimeException();
+ if (dir.equalsAscii("")) {
+ if (i_xStorage->isStreamElement(i_rPath)) {
+ const uno::Reference<io::XStream> xStream(
+ i_xStorage->openStreamElement(i_rPath,
+ embed::ElementModes::READ), uno::UNO_SET_THROW);
+ const uno::Reference<io::XInputStream> xInStream(
+ xStream->getInputStream(), uno::UNO_SET_THROW );
+ const uno::Reference<rdf::XURI> xBaseURI(
+ rdf::URI::create(i_rImpl.m_xContext, i_rBaseURI));
+ const uno::Reference<rdf::XURI> xURI(
+ rdf::URI::createNS(i_rImpl.m_xContext,
+ i_rBaseURI, i_rPath));
+ i_rImpl.m_xRepository->importGraph(rdf::FileFormat::RDF_XML,
+ xInStream, xURI, xBaseURI);
+ } else {
+ throw mkException(::rtl::OUString::createFromAscii(
+ "readStream: is not a stream"),
+ ucb::IOErrorCode_NO_FILE, i_rBaseURI + i_rPath, i_rPath);
+ }
+ } else {
+ if (i_xStorage->isStorageElement(dir)) {
+ const uno::Reference<embed::XStorage> xDir(
+ i_xStorage->openStorageElement(dir,
+ embed::ElementModes::READ));
+ const uno::Reference< beans::XPropertySet > xDirProps(xDir,
+ uno::UNO_QUERY_THROW);
+ try {
+ ::rtl::OUString mimeType;
+ xDirProps->getPropertyValue(
+ ::comphelper::MediaDescriptor::PROP_MEDIATYPE() )
+ >>= mimeType;
+ if (mimeType.matchAsciiL(s_odfmime, sizeof(s_odfmime) - 1))
+ {
+ OSL_TRACE("readStream: "
+ "refusing to recurse into embedded document");
+ return;
+ }
+ } catch (uno::Exception &) { }
+ ::rtl::OUStringBuffer buf(i_rBaseURI);
+ buf.append(dir).append(static_cast<sal_Unicode>('/'));
+ readStream(i_rImpl, xDir, rest, buf.makeStringAndClear() );
+ } else {
+ throw mkException(::rtl::OUString::createFromAscii(
+ "readStream: is not a directory"),
+ ucb::IOErrorCode_NO_DIRECTORY, i_rBaseURI + dir, dir);
+ }
+ }
+ } catch (container::NoSuchElementException & e) {
+ throw mkException(e.Message, ucb::IOErrorCode_NOT_EXISTING_PATH,
+ i_rBaseURI + i_rPath, i_rPath);
+ } catch (io::IOException & e) {
+ throw mkException(e.Message, ucb::IOErrorCode_CANT_READ,
+ i_rBaseURI + i_rPath, i_rPath);
+ } catch (rdf::ParseException & e) {
+ throw mkException(e.Message, ucb::IOErrorCode_WRONG_FORMAT,
+ i_rBaseURI + i_rPath, i_rPath);
+ }
+}
+
+/** import a metadata file into repository */
+static void
+importFile(struct DocumentMetadataAccess_Impl & i_rImpl,
+ uno::Reference<embed::XStorage> const & i_xStorage,
+ ::rtl::OUString const & i_rBaseURI,
+ uno::Reference<task::XInteractionHandler> const & i_xHandler,
+ ::rtl::OUString i_rPath)
+{
+retry:
+ try {
+ readStream(i_rImpl, i_xStorage, i_rPath, i_rBaseURI);
+ } catch (ucb::InteractiveAugmentedIOException & e) {
+ if (handleError(e, i_xHandler)) goto retry;
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii("importFile: exception"),
+ 0, uno::makeAny(e));
+ }
+}
+
+/** actually write a metadata file to the storage */
+static void
+exportStream(struct DocumentMetadataAccess_Impl & i_rImpl,
+ uno::Reference< embed::XStorage > const & i_xStorage,
+ uno::Reference<rdf::XURI> const & i_xGraphName,
+ ::rtl::OUString const & i_rFileName,
+ ::rtl::OUString const & i_rBaseURI)
+{
+ const uno::Reference<io::XStream> xStream(
+ i_xStorage->openStreamElement(i_rFileName,
+ embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE),
+ uno::UNO_SET_THROW);
+ const uno::Reference< beans::XPropertySet > xStreamProps(xStream,
+ uno::UNO_QUERY);
+ if (xStreamProps.is()) { // this is NOT supported in FileSystemStorage
+ xStreamProps->setPropertyValue(
+ ::rtl::OUString::createFromAscii("MediaType"),
+ uno::makeAny(::rtl::OUString::createFromAscii(s_rdfxml)));
+ }
+ const uno::Reference<io::XOutputStream> xOutStream(
+ xStream->getOutputStream(), uno::UNO_SET_THROW );
+ const uno::Reference<rdf::XURI> xBaseURI(
+ rdf::URI::create(i_rImpl.m_xContext, i_rBaseURI));
+ i_rImpl.m_xRepository->exportGraph(rdf::FileFormat::RDF_XML,
+ xOutStream, i_xGraphName, xBaseURI);
+}
+
+/** write a metadata file to the storage */
+static void
+writeStream(struct DocumentMetadataAccess_Impl & i_rImpl,
+ uno::Reference< embed::XStorage > const & i_xStorage,
+ uno::Reference<rdf::XURI> const & i_xGraphName,
+ ::rtl::OUString const & i_rPath,
+ ::rtl::OUString const & i_rBaseURI)
+{
+ ::rtl::OUString dir;
+ ::rtl::OUString rest;
+ if (!splitPath(i_rPath, dir, rest)) throw uno::RuntimeException();
+ try {
+ if (dir.equalsAscii("")) {
+ exportStream(i_rImpl, i_xStorage, i_xGraphName, i_rPath,
+ i_rBaseURI);
+ } else {
+ const uno::Reference<embed::XStorage> xDir(
+ i_xStorage->openStorageElement(dir,
+ embed::ElementModes::WRITE));
+ const uno::Reference< beans::XPropertySet > xDirProps(xDir,
+ uno::UNO_QUERY_THROW);
+ try {
+ ::rtl::OUString mimeType;
+ xDirProps->getPropertyValue(
+ ::comphelper::MediaDescriptor::PROP_MEDIATYPE() )
+ >>= mimeType;
+ if (mimeType.matchAsciiL(s_odfmime, sizeof(s_odfmime) - 1)) {
+ OSL_TRACE("writeStream: "
+ "refusing to recurse into embedded document");
+ return;
+ }
+ } catch (uno::Exception &) { }
+ ::rtl::OUStringBuffer buf(i_rBaseURI);
+ buf.append(dir).append(static_cast<sal_Unicode>('/'));
+ writeStream(i_rImpl, xDir, i_xGraphName, rest,
+ buf.makeStringAndClear());
+ }
+ const uno::Reference<embed::XTransactedObject> xTransaction(
+ i_xStorage, uno::UNO_QUERY);
+ if (xTransaction.is()) {
+ xTransaction->commit();
+ }
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (io::IOException &) {
+ throw;
+ }
+}
+
+static void
+initLoading(struct DocumentMetadataAccess_Impl & i_rImpl,
+ const uno::Reference< embed::XStorage > & i_xStorage,
+ const uno::Reference<rdf::XURI> & i_xBaseURI,
+ const uno::Reference<task::XInteractionHandler> & i_xHandler)
+{
+retry:
+ // clear old data
+ i_rImpl.m_xManifest.clear();
+ // init BaseURI
+ i_rImpl.m_xBaseURI = i_xBaseURI;
+
+ // create repository
+ i_rImpl.m_xRepository.clear();
+ i_rImpl.m_xRepository.set(rdf::Repository::create(i_rImpl.m_xContext),
+ uno::UNO_SET_THROW);
+
+ const ::rtl::OUString manifest (
+ ::rtl::OUString::createFromAscii(s_manifest));
+ const ::rtl::OUString baseURI( i_xBaseURI->getStringValue() );
+ // try to delay raising errors until after initialization is done
+ uno::Any rterr;
+ ucb::InteractiveAugmentedIOException iaioe;
+ bool err(false);
+
+ const uno::Reference <rdf::XURI> xManifest(
+ getURIForStream(i_rImpl, manifest));
+ try {
+ readStream(i_rImpl, i_xStorage, manifest, baseURI);
+ } catch (ucb::InteractiveAugmentedIOException & e) {
+ // no manifest.rdf: this is not an error in ODF < 1.2
+ if (!(ucb::IOErrorCode_NOT_EXISTING_PATH == e.Code)) {
+ iaioe = e;
+ err = true;
+ }
+ } catch (uno::Exception & e) {
+ rterr <<= e;
+ }
+
+ // init manifest graph
+ const uno::Reference<rdf::XNamedGraph> xManifestGraph(
+ i_rImpl.m_xRepository->getGraph(xManifest));
+ i_rImpl.m_xManifest.set(xManifestGraph.is() ? xManifestGraph :
+ i_rImpl.m_xRepository->createGraph(xManifest), uno::UNO_SET_THROW);
+ const uno::Reference<container::XEnumeration> xEnum(
+ i_rImpl.m_xManifest->getStatements(0,
+ getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext),
+ getURI<rdf::URIs::PKG_DOCUMENT>(i_rImpl.m_xContext).get()));
+
+ // document statement
+ i_rImpl.m_xManifest->addStatement(i_rImpl.m_xBaseURI.get(),
+ getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext),
+ getURI<rdf::URIs::PKG_DOCUMENT>(i_rImpl.m_xContext).get());
+
+ OSL_ENSURE(i_rImpl.m_xBaseURI.is(), "base URI is null");
+ OSL_ENSURE(i_rImpl.m_xRepository.is(), "repository is null");
+ OSL_ENSURE(i_rImpl.m_xManifest.is(), "manifest is null");
+
+ if (rterr.hasValue()) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromStorage: "
+ "exception"), 0, rterr);
+ }
+
+ if (err) {
+ if (handleError(iaioe, i_xHandler)) goto retry;
+ }
+}
+
+/** init Impl struct */
+static void init(struct DocumentMetadataAccess_Impl & i_rImpl)
+{
+ try {
+
+ i_rImpl.m_xManifest.set(i_rImpl.m_xRepository->createGraph(
+ getURIForStream(i_rImpl,
+ ::rtl::OUString::createFromAscii(s_manifest))),
+ uno::UNO_SET_THROW);
+
+ // insert the document statement
+ i_rImpl.m_xManifest->addStatement(i_rImpl.m_xBaseURI.get(),
+ getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext),
+ getURI<rdf::URIs::PKG_DOCUMENT>(i_rImpl.m_xContext).get());
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii("init: unexpected exception"), 0,
+ uno::makeAny(e));
+ }
+
+ // add top-level content files
+ if (!addContentOrStylesFileImpl(i_rImpl,
+ ::rtl::OUString::createFromAscii(s_content))) {
+ throw uno::RuntimeException();
+ }
+ if (!addContentOrStylesFileImpl(i_rImpl,
+ ::rtl::OUString::createFromAscii(s_styles))) {
+ throw uno::RuntimeException();
+ }
+}
+
+
+////////////////////////////////////////////////////////////////////////////
+
+DocumentMetadataAccess::DocumentMetadataAccess(
+ uno::Reference< uno::XComponentContext > const & i_xContext,
+ const IXmlIdRegistrySupplier & i_rRegistrySupplier)
+ : m_pImpl(new DocumentMetadataAccess_Impl(i_xContext, i_rRegistrySupplier))
+{
+ // no initalization: must call loadFrom...
+}
+
+DocumentMetadataAccess::DocumentMetadataAccess(
+ uno::Reference< uno::XComponentContext > const & i_xContext,
+ const IXmlIdRegistrySupplier & i_rRegistrySupplier,
+ ::rtl::OUString const & i_rURI)
+ : m_pImpl(new DocumentMetadataAccess_Impl(i_xContext, i_rRegistrySupplier))
+{
+ OSL_ENSURE(i_rURI.getLength(), "DMA::DMA: no URI given!");
+ OSL_ENSURE(i_rURI.endsWithAsciiL("/", 1), "DMA::DMA: URI without / given!");
+ if (!i_rURI.endsWithAsciiL("/", 1)) throw uno::RuntimeException();
+ m_pImpl->m_xBaseURI.set(rdf::URI::create(m_pImpl->m_xContext, i_rURI));
+ m_pImpl->m_xRepository.set(rdf::Repository::create(m_pImpl->m_xContext),
+ uno::UNO_SET_THROW);
+
+ // init repository
+ init(*m_pImpl);
+
+ OSL_ENSURE(m_pImpl->m_xBaseURI.is(), "base URI is null");
+ OSL_ENSURE(m_pImpl->m_xRepository.is(), "repository is null");
+ OSL_ENSURE(m_pImpl->m_xManifest.is(), "manifest is null");
+}
+
+DocumentMetadataAccess::~DocumentMetadataAccess()
+{
+}
+
+
+// ::com::sun::star::rdf::XRepositorySupplier:
+uno::Reference< rdf::XRepository > SAL_CALL
+DocumentMetadataAccess::getRDFRepository() throw (uno::RuntimeException)
+{
+ OSL_ENSURE(m_pImpl->m_xRepository.is(), "repository not initialized");
+ return m_pImpl->m_xRepository;
+}
+
+// ::com::sun::star::rdf::XNode:
+::rtl::OUString SAL_CALL
+DocumentMetadataAccess::getStringValue() throw (uno::RuntimeException)
+{
+ return m_pImpl->m_xBaseURI->getStringValue();
+}
+
+// ::com::sun::star::rdf::XURI:
+::rtl::OUString SAL_CALL
+DocumentMetadataAccess::getNamespace() throw (uno::RuntimeException)
+{
+ return m_pImpl->m_xBaseURI->getNamespace();
+}
+
+::rtl::OUString SAL_CALL
+DocumentMetadataAccess::getLocalName() throw (uno::RuntimeException)
+{
+ return m_pImpl->m_xBaseURI->getLocalName();
+}
+
+// ::com::sun::star::rdf::XDocumentMetadataAccess:
+uno::Reference< rdf::XMetadatable > SAL_CALL
+DocumentMetadataAccess::getElementByMetadataReference(
+ const ::com::sun::star::beans::StringPair & i_rReference)
+throw (uno::RuntimeException)
+{
+ const IXmlIdRegistry * pReg(
+ m_pImpl->m_rXmlIdRegistrySupplier.GetXmlIdRegistry() );
+ if (!pReg) {
+ throw uno::RuntimeException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::getElementByXmlId: no registry"), *this);
+ }
+ return pReg->GetElementByMetadataReference(i_rReference);
+}
+
+uno::Reference< rdf::XMetadatable > SAL_CALL
+DocumentMetadataAccess::getElementByURI(
+ const uno::Reference< rdf::XURI > & i_xURI )
+throw (uno::RuntimeException, lang::IllegalArgumentException)
+{
+ if (!i_xURI.is()) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::getElementByURI: URI is null"), *this, 0);
+ }
+
+ const ::rtl::OUString baseURI( m_pImpl->m_xBaseURI->getStringValue() );
+ const ::rtl::OUString name( i_xURI->getStringValue() );
+ if (!name.match(baseURI)) {
+ return 0;
+ }
+ const ::rtl::OUString relName( name.copy(baseURI.getLength()) );
+ ::rtl::OUString path;
+ ::rtl::OUString idref;
+ if (!splitXmlId(relName, path, idref)) {
+ return 0;
+ }
+
+ return getElementByMetadataReference( beans::StringPair(path, idref) );
+}
+
+
+uno::Sequence< uno::Reference< rdf::XURI > > SAL_CALL
+DocumentMetadataAccess::getMetadataGraphsWithType(
+ const uno::Reference<rdf::XURI> & i_xType)
+throw (uno::RuntimeException, lang::IllegalArgumentException)
+{
+ if (!i_xType.is()) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::getMetadataGraphsWithType: "
+ "type is null"), *this, 0);
+ }
+
+ ::comphelper::SequenceAsVector< uno::Reference< rdf::XURI > > ret;
+ const ::std::vector< uno::Reference< rdf::XURI > > parts(
+ getAllParts(*m_pImpl) );
+ ::std::remove_copy_if(parts.begin(), parts.end(),
+ ::std::back_inserter(ret),
+ ::boost::bind(
+ ::std::logical_not<bool>(),
+ ::boost::bind(&isPartOfType, ::boost::ref(*m_pImpl), _1, i_xType) ));
+ return ret.getAsConstList();
+}
+
+uno::Reference<rdf::XURI> SAL_CALL
+DocumentMetadataAccess::addMetadataFile(const ::rtl::OUString & i_rFileName,
+ const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::ElementExistException)
+{
+ if (!isFileNameValid(i_rFileName)) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::addMetadataFile: invalid FileName"),
+ *this, 0);
+ }
+ if (isReservedFile(i_rFileName)) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::addMetadataFile:"
+ "invalid FileName: reserved"), *this, 0);
+ }
+ for (sal_Int32 i = 0; i < i_rTypes.getLength(); ++i) {
+ if (!i_rTypes[i].is()) {
+ throw lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::addMetadataFile: "
+ "null type"), *this, 2);
+ }
+ }
+
+ const uno::Reference<rdf::XURI> xGraphName(
+ getURIForStream(*m_pImpl, i_rFileName) );
+
+ try {
+ m_pImpl->m_xRepository->createGraph(xGraphName);
+ } catch (rdf::RepositoryException & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::addMetadataFile: exception"),
+ *this, uno::makeAny(e));
+ // note: all other exceptions are propagated
+ }
+
+ addMetadataFileImpl(*m_pImpl, i_rFileName, i_rTypes);
+ return xGraphName;
+}
+
+uno::Reference<rdf::XURI> SAL_CALL
+DocumentMetadataAccess::importMetadataFile(::sal_Int16 i_Format,
+ const uno::Reference< io::XInputStream > & i_xInStream,
+ const ::rtl::OUString & i_rFileName,
+ const uno::Reference< rdf::XURI > & i_xBaseURI,
+ const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ datatransfer::UnsupportedFlavorException,
+ container::ElementExistException, rdf::ParseException, io::IOException)
+{
+ if (!isFileNameValid(i_rFileName)) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::importMetadataFile: invalid FileName"),
+ *this, 0);
+ }
+ if (isReservedFile(i_rFileName)) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::importMetadataFile:"
+ "invalid FileName: reserved"), *this, 0);
+ }
+ for (sal_Int32 i = 0; i < i_rTypes.getLength(); ++i) {
+ if (!i_rTypes[i].is()) {
+ throw lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::importMetadataFile: null type"),
+ *this, 5);
+ }
+ }
+
+ const uno::Reference<rdf::XURI> xGraphName(
+ getURIForStream(*m_pImpl, i_rFileName) );
+
+ try {
+ m_pImpl->m_xRepository->importGraph(
+ i_Format, i_xInStream, xGraphName, i_xBaseURI);
+ } catch (rdf::RepositoryException & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::importMetadataFile: "
+ "RepositoryException"), *this, uno::makeAny(e));
+ // note: all other exceptions are propagated
+ }
+
+ // add to manifest
+ addMetadataFileImpl(*m_pImpl, i_rFileName, i_rTypes);
+ return xGraphName;
+}
+
+void SAL_CALL
+DocumentMetadataAccess::removeMetadataFile(
+ const uno::Reference< rdf::XURI > & i_xGraphName)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::NoSuchElementException)
+{
+ try {
+ m_pImpl->m_xRepository->destroyGraph(i_xGraphName);
+ } catch (rdf::RepositoryException & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::removeMetadataFile: "
+ "RepositoryException"), *this, uno::makeAny(e));
+ // note: all other exceptions are propagated
+ }
+
+ // remove file from manifest
+ removeFile(*m_pImpl, i_xGraphName.get());
+}
+
+void SAL_CALL
+DocumentMetadataAccess::addContentOrStylesFile(
+ const ::rtl::OUString & i_rFileName)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::ElementExistException)
+{
+ if (!isFileNameValid(i_rFileName)) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::addContentOrStylesFile: "
+ "invalid FileName"), *this, 0);
+ }
+
+ if (!addContentOrStylesFileImpl(*m_pImpl, i_rFileName)) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::addContentOrStylesFile: "
+ "invalid FileName: must end with content.xml or styles.xml"),
+ *this, 0);
+ }
+}
+
+void SAL_CALL
+DocumentMetadataAccess::removeContentOrStylesFile(
+ const ::rtl::OUString & i_rFileName)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::NoSuchElementException)
+{
+ if (!isFileNameValid(i_rFileName)) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::removeContentOrStylesFile: "
+ "invalid FileName"), *this, 0);
+ }
+
+ try {
+ const uno::Reference<rdf::XURI> xPart(
+ getURIForStream(*m_pImpl, i_rFileName) );
+ const uno::Reference<container::XEnumeration> xEnum(
+ m_pImpl->m_xManifest->getStatements( m_pImpl->m_xBaseURI.get(),
+ getURI<rdf::URIs::PKG_HASPART>(m_pImpl->m_xContext),
+ xPart.get()),
+ uno::UNO_SET_THROW);
+ if (!xEnum->hasMoreElements()) {
+ throw container::NoSuchElementException(
+ ::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::removeContentOrStylesFile: "
+ "cannot find stream in manifest graph: ") + i_rFileName,
+ *this);
+ }
+
+ // remove file from manifest
+ removeFile(*m_pImpl, xPart);
+
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::removeContentOrStylesFile: exception"),
+ *this, uno::makeAny(e));
+ }
+}
+
+void SAL_CALL DocumentMetadataAccess::loadMetadataFromStorage(
+ const uno::Reference< embed::XStorage > & i_xStorage,
+ const uno::Reference<rdf::XURI> & i_xBaseURI,
+ const uno::Reference<task::XInteractionHandler> & i_xHandler)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ if (!i_xStorage.is()) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromStorage: "
+ "storage is null"), *this, 0);
+ }
+ if (!i_xBaseURI.is()) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromStorage: "
+ "base URI is null"), *this, 1);
+ }
+ const ::rtl::OUString baseURI( i_xBaseURI->getStringValue());
+ if (baseURI.indexOf('#') >= 0) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromStorage: "
+ "base URI not absolute"), *this, 1);
+ }
+ if (!baseURI.getLength() || !baseURI.endsWithAsciiL("/", 1)) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromStorage: "
+ "base URI does not end with slash"), *this, 1);
+ }
+
+ initLoading(*m_pImpl, i_xStorage, i_xBaseURI, i_xHandler);
+
+ std::set< ::rtl::OUString > StgFiles;
+ collectFilesFromStorage(i_xStorage,
+ ::rtl::OUString::createFromAscii(""), StgFiles);
+
+ std::vector< ::rtl::OUString > MfstMetadataFiles;
+
+ try {
+ const ::std::vector< uno::Reference< rdf::XURI > > parts(
+ getAllParts(*m_pImpl) );
+ const uno::Reference<rdf::XURI> xContentFile(
+ getURI<rdf::URIs::ODF_CONTENTFILE>(m_pImpl->m_xContext));
+ const uno::Reference<rdf::XURI> xStylesFile(
+ getURI<rdf::URIs::ODF_STYLESFILE>(m_pImpl->m_xContext));
+ const uno::Reference<rdf::XURI> xMetadataFile(
+ getURI<rdf::URIs::PKG_METADATAFILE>(m_pImpl->m_xContext));
+ const sal_Int32 len( baseURI.getLength() );
+ const ::rtl::OUString manifest (
+ ::rtl::OUString::createFromAscii(s_manifest));
+ for (::std::vector< uno::Reference< rdf::XURI > >::const_iterator it
+ = parts.begin();
+ it != parts.end(); ++it) {
+ const ::rtl::OUString name((*it)->getStringValue());
+ if (!name.match(baseURI)) {
+ OSL_TRACE("loadMetadataFromStorage: graph not in document: %s",
+ ::rtl::OUStringToOString(name, RTL_TEXTENCODING_UTF8)
+ .getStr());
+ continue;
+ }
+ const ::rtl::OUString relName( name.copy(len) );
+ if (relName == manifest) {
+ OSL_TRACE("loadMetadataFromStorage: "
+ "found ourselves a recursive manifest!");
+ continue;
+ }
+ // remove found items from StgFiles
+ StgFiles.erase(relName);
+ if (isContentFile(relName)) {
+ if (!isPartOfType(*m_pImpl, *it, xContentFile)) {
+ const uno::Reference <rdf::XURI> xName(
+ getURIForStream(*m_pImpl, relName) );
+ // add missing type statement
+ m_pImpl->m_xManifest->addStatement(xName.get(),
+ getURI<rdf::URIs::RDF_TYPE>(m_pImpl->m_xContext),
+ xContentFile.get());
+ }
+ } else if (isStylesFile(relName)) {
+ if (!isPartOfType(*m_pImpl, *it, xStylesFile)) {
+ const uno::Reference <rdf::XURI> xName(
+ getURIForStream(*m_pImpl, relName) );
+ // add missing type statement
+ m_pImpl->m_xManifest->addStatement(xName.get(),
+ getURI<rdf::URIs::RDF_TYPE>(m_pImpl->m_xContext),
+ xStylesFile.get());
+ }
+ } else if (isReservedFile(relName)) {
+ OSL_TRACE("loadMetadataFromStorage: "
+ "reserved file name in manifest");
+ } else {
+ if (isPartOfType(*m_pImpl, *it, xMetadataFile)) {
+ MfstMetadataFiles.push_back(relName);
+ }
+ // do not add statement for MetadataFile; it could be
+ // something else! just ignore it...
+ }
+ }
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromStorage: "
+ "exception"), *this, uno::makeAny(e));
+ }
+
+ std::for_each(StgFiles.begin(), StgFiles.end(),
+ boost::bind(addContentOrStylesFileImpl, boost::ref(*m_pImpl), _1));
+
+ std::for_each(MfstMetadataFiles.begin(), MfstMetadataFiles.end(),
+ boost::bind(importFile, boost::ref(*m_pImpl),
+ i_xStorage, baseURI, i_xHandler, _1));
+}
+
+void SAL_CALL DocumentMetadataAccess::storeMetadataToStorage(
+ const uno::Reference< embed::XStorage > & i_xStorage)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ if (!i_xStorage.is()) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::storeMetadataToStorage: "
+ "storage is null"), *this, 0);
+ }
+
+ // export manifest
+ const ::rtl::OUString manifest (
+ ::rtl::OUString::createFromAscii(s_manifest));
+ const uno::Reference <rdf::XURI> xManifest(
+ getURIForStream(*m_pImpl, manifest) );
+ const ::rtl::OUString baseURI( m_pImpl->m_xBaseURI->getStringValue() );
+ try {
+ writeStream(*m_pImpl, i_xStorage, xManifest, manifest, baseURI);
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (io::IOException & e) {
+ throw lang::WrappedTargetException( ::rtl::OUString::createFromAscii(
+ "storeMetadataToStorage: IO exception"), *this, uno::makeAny(e));
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "storeMetadataToStorage: exception"), *this, uno::makeAny(e));
+ }
+
+ // export metadata streams
+ try {
+ const uno::Sequence<uno::Reference<rdf::XURI> > graphs(
+ m_pImpl->m_xRepository->getGraphNames());
+ const sal_Int32 len( baseURI.getLength() );
+ for (sal_Int32 i = 0; i < graphs.getLength(); ++i) {
+ const uno::Reference<rdf::XURI> xName(graphs[i]);
+ const ::rtl::OUString name(xName->getStringValue());
+ if (!name.match(baseURI)) {
+ OSL_TRACE("storeMetadataToStorage: graph not in document: %s",
+ ::rtl::OUStringToOString(name, RTL_TEXTENCODING_UTF8)
+ .getStr());
+ continue;
+ }
+ const ::rtl::OUString relName( name.copy(len) );
+ if (relName == manifest) {
+ continue;
+ }
+ if (!isFileNameValid(relName) || isReservedFile(relName)) {
+ OSL_TRACE("storeMetadataToStorage: invalid file name: %s",
+ ::rtl::OUStringToOString(relName, RTL_TEXTENCODING_UTF8)
+ .getStr());
+ continue;
+ }
+ try {
+ writeStream(*m_pImpl, i_xStorage, xName, relName, baseURI);
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (io::IOException & e) {
+ throw lang::WrappedTargetException(
+ ::rtl::OUString::createFromAscii(
+ "storeMetadataToStorage: IO exception"),
+ *this, uno::makeAny(e));
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "storeMetadataToStorage: exception"),
+ *this, uno::makeAny(e));
+ }
+ }
+ } catch (rdf::RepositoryException & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "storeMetadataToStorage: exception"), *this, uno::makeAny(e));
+ }
+}
+
+void SAL_CALL
+DocumentMetadataAccess::loadMetadataFromMedium(
+ const uno::Sequence< beans::PropertyValue > & i_rMedium)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ uno::Reference<io::XInputStream> xIn;
+ ::comphelper::MediaDescriptor md(i_rMedium);
+ ::rtl::OUString URL;
+ md[ ::comphelper::MediaDescriptor::PROP_URL() ] >>= URL;
+ ::rtl::OUString BaseURL;
+ md[ ::comphelper::MediaDescriptor::PROP_DOCUMENTBASEURL() ] >>= BaseURL;
+ if (md.addInputStream()) {
+ md[ ::comphelper::MediaDescriptor::PROP_INPUTSTREAM() ] >>= xIn;
+ }
+ if (!xIn.is() && URL.equalsAscii("")) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromMedium: "
+ "inalid medium: no URL, no input stream"), *this, 0);
+ }
+ uno::Reference<embed::XStorage> xStorage;
+ try {
+ const uno::Reference<lang::XMultiServiceFactory> xMsf (
+ m_pImpl->m_xContext->getServiceManager(), uno::UNO_QUERY_THROW);
+ if (xIn.is()) {
+ xStorage = ::comphelper::OStorageHelper::GetStorageFromInputStream(
+ xIn, xMsf);
+ } else { // fallback to url
+ xStorage = ::comphelper::OStorageHelper::GetStorageFromURL2(
+ URL, embed::ElementModes::READ, xMsf);
+ }
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (io::IOException &) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetException(
+ ::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromMedium: "
+ "exception"), *this, uno::makeAny(e));
+ }
+ if (!xStorage.is()) {
+ throw uno::RuntimeException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::loadMetadataFromMedium: "
+ "cannot get Storage"), *this);
+ }
+ uno::Reference<rdf::XURI> xBaseURI;
+ try {
+ xBaseURI = createBaseURI(m_pImpl->m_xContext, xStorage, BaseURL);
+ } catch (uno::Exception &) {
+ // fall back to URL
+ try {
+ xBaseURI = createBaseURI(m_pImpl->m_xContext, xStorage, URL);
+ } catch (uno::Exception &) {
+ OSL_ENSURE(false, "cannot create base URI");
+ }
+ }
+ uno::Reference<task::XInteractionHandler> xIH;
+ md[ ::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER() ] >>= xIH;
+ loadMetadataFromStorage(xStorage, xBaseURI, xIH);
+}
+
+void SAL_CALL
+DocumentMetadataAccess::storeMetadataToMedium(
+ const uno::Sequence< beans::PropertyValue > & i_rMedium)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ ::comphelper::MediaDescriptor md(i_rMedium);
+ ::rtl::OUString URL;
+ md[ ::comphelper::MediaDescriptor::PROP_URL() ] >>= URL;
+ if (URL.equalsAscii("")) {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::storeMetadataToMedium: "
+ "invalid medium: no URL"), *this, 0);
+ }
+
+ SfxMedium aMedium(i_rMedium);
+ uno::Reference<embed::XStorage> xStorage(aMedium.GetOutputStorage());
+
+ bool sfx(false);
+ if (xStorage.is()) {
+ sfx = true;
+ } else {
+ const uno::Reference<lang::XMultiServiceFactory> xMsf (
+ m_pImpl->m_xContext->getServiceManager(), uno::UNO_QUERY_THROW);
+ xStorage = ::comphelper::OStorageHelper::GetStorageFromURL2(
+ URL, embed::ElementModes::WRITE, xMsf);
+ }
+
+ if (!xStorage.is()) {
+ throw uno::RuntimeException(::rtl::OUString::createFromAscii(
+ "DocumentMetadataAccess::storeMetadataToMedium: "
+ "cannot get Storage"), *this);
+ }
+ // set MIME type of the storage
+ ::comphelper::MediaDescriptor::const_iterator iter
+ = md.find(::comphelper::MediaDescriptor::PROP_MEDIATYPE());
+ if (iter != md.end()) {
+ uno::Reference< beans::XPropertySet > xProps(xStorage,
+ uno::UNO_QUERY_THROW);
+ try {
+ // this is NOT supported in FileSystemStorage
+ xProps->setPropertyValue(
+ ::comphelper::MediaDescriptor::PROP_MEDIATYPE(),
+ iter->second);
+ } catch (uno::Exception &) { }
+ }
+ storeMetadataToStorage(xStorage);
+
+ if (sfx) {
+ const sal_Bool bOk = aMedium.Commit();
+ aMedium.Close();
+ if ( !bOk ) {
+ sal_uInt32 nError = aMedium.GetError();
+ if ( nError == ERRCODE_NONE ) {
+ nError = ERRCODE_IO_GENERAL;
+ }
+ task::ErrorCodeIOException ex( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(), nError);
+ throw lang::WrappedTargetException(::rtl::OUString(), *this,
+ uno::makeAny(ex));
+ }
+ }
+}
+
+} // namespace sfx2
+
diff --git a/sfx2/source/doc/Metadatable.cxx b/sfx2/source/doc/Metadatable.cxx
new file mode 100644
index 000000000000..94c5826569f2
--- /dev/null
+++ b/sfx2/source/doc/Metadatable.cxx
@@ -0,0 +1,1703 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_sfx2.hxx"
+
+#include <sfx2/Metadatable.hxx>
+#include <sfx2/XmlIdRegistry.hxx>
+
+#include <vos/mutex.hxx>
+#include <vcl/svapp.hxx> // solarmutex
+
+#include <rtl/random.h>
+
+#include <boost/bind.hpp>
+
+#include <memory>
+#include <hash_map>
+#include <list>
+#include <algorithm>
+#if OSL_DEBUG_LEVEL > 0
+#include <typeinfo>
+#endif
+
+
+/** XML ID handling.
+
+ There is an abstract base class <type>XmlIdRegistry</type>, with
+ 2 subclasses <type>XmlIdRegistryDocument</type> for "normal" documents,
+ and <type>XmlIdRegistryClipboard</type> for clipboard documents.
+ These classes are responsible for managing XML IDs for all elements
+ of the model. Only the implementation of the <type>Metadatable</type>
+ base class needs to know the registries, so they are not in the header.
+
+ The handling of XML IDs differs between clipboard and non-clipboard
+ documents in several aspects. Most importantly, non-clipboard documents
+ can have several elements associated with one XML ID.
+ This is necessary because of the weird undo implementation:
+ deleting a text node moves the deleted node to the undo array, but
+ executing undo will then create a <em>copy</em> of that node in the
+ document array. These 2 nodes must have the same XML ID, because
+ we cannot know whether the user will do a redo next, or something else.
+
+ Because we need to have a mechanism for several objects per XML ID anyway,
+ we use that also to enable some usability features:
+ The document registry has a list of Metadatables per XML ID.
+ This list is sorted by priority, i.e., the first element has highest
+ priority. When inserting copies, care must be taken that they are inserted
+ at the right position: either before or after the source.
+ This is done by <method>Metadatable::RegisterAsCopyOf</method>.
+ When a text node is split, then both resulting text nodes are inserted
+ into the list. If the user then deletes one text node, the other one
+ will have the XML ID.
+ Also, when a Metadatable is copied to the clipboard and then pasted,
+ the copy is inserted into the list. If the user then deletes the source,
+ the XML ID is not lost.
+ The goal is that it should be hard to lose an XML ID by accident, which
+ is especially important as long as we do not have an UI that displays them.
+
+ There are two subclasses of <type>Metadatable</type>:
+ <ul><li><type>MetadatableClipboard</type>: for copies in the clipboard</li>
+ <li><type>MetadatableUndo</type>: for undo, because a Metadatable
+ may be destroyed on delete and a new one created on undo.</li></ul>
+ These serve only to track the position in an XML ID list in a document
+ registry, so that future actions can insert objects at the right position.
+ Unfortunately, inserting dummy objects seems to be necessary:
+ <ul><li>it is not sufficent to just remember the saved id, because then
+ the relative priorities might change when executing the undo</li>
+ <li>it is not sufficient to record the position as an integer, because
+ if we delete a text node and then undo, the node will be copied(!),
+ and we will have one more node in the list.<li>
+ <li>it is not sufficient to record the pointer of the previous/next
+ Metadatable, because if we delete a text node, undo, and then
+ do something to clear the redo array, the original text node is
+ destroyed, and is replaced by the copy created by undo</li></ul>
+
+ If content from a non-clipboard document is copied into a clipboard
+ document, a dummy <type>MetadatableClipboard</type> is inserted into the
+ non-clipboard document registry in order to track the position of the
+ source element. When the clipboard content is pasted back into the source
+ document, this dummy object is used to associate the pasted element with
+ that same XML ID.
+
+ If a <type>Metadatable</type> is deleted or merged,
+ <method>Metadatable::CreateUndo</method> is called, and returns a
+ <type>MetadatableUndo<type> instance, which can be used to undo the action
+ by passing it to <method>Metadatable::RestoreMetadata</method>.
+
+ @author mst
+ */
+
+
+using namespace ::com::sun::star;
+
+using ::sfx2::isValidXmlId;
+
+
+namespace sfx2 {
+
+static const char s_content [] = "content.xml";
+static const char s_styles [] = "styles.xml";
+static const char s_prefix [] = "id"; // prefix for generated xml:id
+
+static bool isContentFile(::rtl::OUString const & i_rPath)
+{
+ return i_rPath.equalsAscii(s_content);
+}
+
+static bool isStylesFile (::rtl::OUString const & i_rPath)
+{
+ return i_rPath.equalsAscii(s_styles);
+}
+
+
+//=============================================================================
+// XML ID handling ---------------------------------------------------
+
+/** handles registration of XMetadatable.
+
+ This class is responsible for guaranteeing that XMetadatable objects
+ always have XML IDs that are unique within a stream.
+
+ This is an abstract base class; see subclasses XmlIdRegistryDocument and
+ XmlIdRegistryClipboard.
+
+ @see SwDoc::GetXmlIdRegistry
+ @see SwDocShell::GetXmlIdRegistry
+ */
+class XmlIdRegistry : public sfx2::IXmlIdRegistry
+{
+
+public:
+ XmlIdRegistry();
+
+ virtual ~XmlIdRegistry();
+
+ /** get the ODF element with the given metadata reference. */
+ virtual ::com::sun::star::uno::Reference<
+ ::com::sun::star::rdf::XMetadatable > SAL_CALL
+ GetElementByMetadataReference(
+ const ::com::sun::star::beans::StringPair & i_rReference) const;
+
+ /** register an ODF element at a newly generated, unique metadata reference.
+
+ <p>
+ Find a fresh XML ID, and register it for the element.
+ The generated ID does not occur in any stream of the document.
+ </p>
+ */
+ virtual void RegisterMetadatableAndCreateID(Metadatable& i_xObject) = 0;
+
+ /** try to register an ODF element at a given XML ID, or update its
+ registation to a different XML ID.
+
+ <p>
+ If the given new metadata reference is not already occupied in the
+ document, unregister the element at its old metadata reference if
+ it has one, and register the new metadata reference for the element.
+ Note that this method only ensures that XML IDs are unique per stream,
+ so using the same XML ID in both content.xml and styles.xml is allowed.
+ </p>
+
+ @returns
+ true iff the element has successfully been registered
+ */
+ virtual bool TryRegisterMetadatable(Metadatable& i_xObject,
+ ::rtl::OUString const& i_rStreamName, ::rtl::OUString const& i_rIdref)
+ = 0;
+
+ /** unregister an ODF element.
+
+ <p>
+ Unregister the element at its metadata reference.
+ Does not remove the metadata reference from the element.
+ </p>
+
+ @see RemoveXmlIdForElement
+ */
+ virtual void UnregisterMetadatable(Metadatable const&) = 0;
+
+ /** get the metadata reference for the given element. */
+ ::com::sun::star::beans::StringPair
+ GetXmlIdForElement(Metadatable const&) const;
+
+ /** remove the metadata reference for the given element. */
+ virtual void RemoveXmlIdForElement(Metadatable const&) = 0;
+
+protected:
+
+ virtual bool LookupXmlId(const Metadatable& i_xObject,
+ ::rtl::OUString & o_rStream, ::rtl::OUString & o_rIdref) const = 0;
+
+ virtual Metadatable* LookupElement(const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const = 0;
+};
+
+// XmlIdRegistryDocument ---------------------------------------------
+
+/** non-clipboard documents */
+class XmlIdRegistryDocument : public XmlIdRegistry
+{
+
+public:
+ XmlIdRegistryDocument();
+
+ virtual ~XmlIdRegistryDocument();
+
+ virtual void RegisterMetadatableAndCreateID(Metadatable& i_xObject);
+
+ virtual bool TryRegisterMetadatable(Metadatable& i_xObject,
+ ::rtl::OUString const& i_rStreamName, ::rtl::OUString const& i_rIdref);
+
+ virtual void UnregisterMetadatable(Metadatable const&);
+
+ virtual void RemoveXmlIdForElement(Metadatable const&);
+
+ /** register i_rCopy as a copy of i_rSource,
+ with precedence iff i_bCopyPrecedesSource is true */
+ void RegisterCopy(Metadatable const& i_rSource, Metadatable & i_rCopy,
+ const bool i_bCopyPrecedesSource);
+
+ /** create a Undo Metadatable for i_rObject. */
+ ::boost::shared_ptr<MetadatableUndo> CreateUndo(
+ Metadatable const& i_rObject);
+
+ /** merge i_rMerged and i_rOther into i_rMerged. */
+ void JoinMetadatables(Metadatable & i_rMerged, Metadatable const& i_rOther);
+
+ // unfortunately public, Metadatable::RegisterAsCopyOf needs this
+ virtual bool LookupXmlId(const Metadatable& i_xObject,
+ ::rtl::OUString & o_rStream, ::rtl::OUString & o_rIdref) const;
+
+private:
+
+ virtual Metadatable* LookupElement(const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const;
+
+ struct XmlIdRegistry_Impl;
+ ::std::auto_ptr<XmlIdRegistry_Impl> m_pImpl;
+};
+
+// MetadatableUndo ---------------------------------------------------
+
+/** the horrible Undo Metadatable: is inserted into lists to track position */
+class MetadatableUndo : public Metadatable
+{
+ /// as determined by the stream of the source in original document
+ const bool m_isInContent;
+public:
+ MetadatableUndo(const bool i_isInContent)
+ : m_isInContent(i_isInContent) { }
+ virtual ::sfx2::XmlIdRegistry& GetRegistry()
+ {
+ // N.B. for Undo, m_pReg is initialized by registering this as copy in
+ // CreateUndo; it is never cleared
+ OSL_ENSURE(m_pReg, "no m_pReg in MetadatableUndo ?");
+ return *m_pReg;
+ }
+ virtual bool IsInClipboard() const { return false; }
+ virtual bool IsInUndo() const { return true; }
+ virtual bool IsInContent() const { return m_isInContent; }
+ virtual ::com::sun::star::uno::Reference<
+ ::com::sun::star::rdf::XMetadatable > MakeUnoObject()
+ { OSL_ENSURE(false, "MetadatableUndo::MakeUnoObject"); throw; }
+};
+
+// MetadatableClipboard ----------------------------------------------
+
+/** the horrible Clipboard Metadatable: inserted into lists to track position */
+class MetadatableClipboard : public Metadatable
+{
+ /// as determined by the stream of the source in original document
+ const bool m_isInContent;
+public:
+ MetadatableClipboard(const bool i_isInContent)
+ : m_isInContent(i_isInContent) { }
+ virtual ::sfx2::XmlIdRegistry& GetRegistry()
+ {
+ // N.B. for Clipboard, m_pReg is initialized by registering this as copy in
+ // RegisterAsCopyOf; it is only cleared by OriginNoLongerInBusinessAnymore
+ OSL_ENSURE(m_pReg, "no m_pReg in MetadatableClipboard ?");
+ return *m_pReg;
+ }
+ virtual bool IsInClipboard() const { return true; }
+ virtual bool IsInUndo() const { return false; }
+ virtual bool IsInContent() const { return m_isInContent; }
+ virtual ::com::sun::star::uno::Reference<
+ ::com::sun::star::rdf::XMetadatable > MakeUnoObject()
+ { OSL_ENSURE(false, "MetadatableClipboard::MakeUnoObject"); throw; }
+ void OriginNoLongerInBusinessAnymore() { m_pReg = 0; }
+};
+
+// XmlIdRegistryClipboard --------------------------------------------
+
+class XmlIdRegistryClipboard : public XmlIdRegistry
+{
+
+public:
+ XmlIdRegistryClipboard();
+ virtual ~XmlIdRegistryClipboard();
+
+ virtual void RegisterMetadatableAndCreateID(Metadatable& i_xObject);
+
+ virtual bool TryRegisterMetadatable(Metadatable& i_xObject,
+ ::rtl::OUString const& i_rStreamName, ::rtl::OUString const& i_rIdref);
+
+ virtual void UnregisterMetadatable(Metadatable const&);
+
+ virtual void RemoveXmlIdForElement(Metadatable const&);
+
+ /** register i_rCopy as a copy of i_rSource */
+ MetadatableClipboard & RegisterCopyClipboard(Metadatable & i_rCopy,
+ beans::StringPair const & i_rReference,
+ const bool i_isLatent);
+
+ /** get the Metadatable that links i_rObject to its origin registry */
+ MetadatableClipboard const* SourceLink(Metadatable const& i_rObject);
+
+private:
+ virtual bool LookupXmlId(const Metadatable& i_xObject,
+ ::rtl::OUString & o_rStream, ::rtl::OUString & o_rIdref) const;
+
+ virtual Metadatable* LookupElement(const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const;
+
+ /** create a Clipboard Metadatable for i_rObject. */
+ ::boost::shared_ptr<MetadatableClipboard> CreateClipboard(
+ const bool i_isInContent);
+
+ struct XmlIdRegistry_Impl;
+ ::std::auto_ptr<XmlIdRegistry_Impl> m_pImpl;
+};
+
+
+//=============================================================================
+// XmlIdRegistry
+
+::sfx2::IXmlIdRegistry * createXmlIdRegistry(const bool i_DocIsClipboard)
+{
+ return i_DocIsClipboard
+ ? static_cast<XmlIdRegistry*>( new XmlIdRegistryClipboard )
+ : static_cast<XmlIdRegistry*>( new XmlIdRegistryDocument );
+}
+
+XmlIdRegistry::XmlIdRegistry()
+{
+}
+
+XmlIdRegistry::~XmlIdRegistry()
+{
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::rdf::XMetadatable > SAL_CALL
+XmlIdRegistry::GetElementByMetadataReference(
+ const beans::StringPair & i_rReference) const
+{
+ Metadatable* pObject( LookupElement(i_rReference.First,
+ i_rReference.Second) );
+ return pObject ? pObject->MakeUnoObject() : 0;
+}
+
+beans::StringPair
+XmlIdRegistry::GetXmlIdForElement(const Metadatable& i_rObject) const
+{
+ ::rtl::OUString path;
+ ::rtl::OUString idref;
+ if (LookupXmlId(i_rObject, path, idref))
+ {
+ if (LookupElement(path, idref) == &i_rObject)
+ {
+ return beans::StringPair(path, idref);
+ }
+ }
+ return beans::StringPair();
+}
+
+
+/// generate unique xml:id
+template< typename T >
+/*static*/ ::rtl::OUString create_id(const
+ ::std::hash_map< ::rtl::OUString, T, ::rtl::OUStringHash > & i_rXmlIdMap)
+{
+ static rtlRandomPool s_Pool( rtl_random_createPool() );
+ const ::rtl::OUString prefix( ::rtl::OUString::createFromAscii(s_prefix) );
+ typename ::std::hash_map< ::rtl::OUString, T, ::rtl::OUStringHash >
+ ::const_iterator iter;
+ ::rtl::OUString id;
+ do
+ {
+ sal_Int32 n;
+ rtl_random_getBytes(s_Pool, & n, sizeof(n));
+ id = prefix + ::rtl::OUString::valueOf(static_cast<sal_Int32>(abs(n)));
+ iter = i_rXmlIdMap.find(id);
+ }
+ while (iter != i_rXmlIdMap.end());
+ return id;
+}
+
+//=============================================================================
+// Document XML ID Registry (_Impl)
+
+/// element list
+typedef ::std::list< Metadatable* > XmlIdList_t;
+
+/// Idref -> (content.xml element list, styles.xml element list)
+typedef ::std::hash_map< ::rtl::OUString,
+ ::std::pair< XmlIdList_t, XmlIdList_t >, ::rtl::OUStringHash > XmlIdMap_t;
+
+/// pointer hash template
+template<typename T> struct PtrHash
+{
+ size_t operator() (T const * i_pT) const
+ {
+ return reinterpret_cast<size_t>(i_pT);
+ }
+};
+
+/// element -> (stream name, idref)
+typedef ::std::hash_map< const Metadatable*,
+ ::std::pair< ::rtl::OUString, ::rtl::OUString>, PtrHash<Metadatable> >
+ XmlIdReverseMap_t;
+
+struct XmlIdRegistryDocument::XmlIdRegistry_Impl
+{
+ XmlIdRegistry_Impl()
+ : m_XmlIdMap(), m_XmlIdReverseMap() { }
+
+ bool TryInsertMetadatable(Metadatable& i_xObject,
+ const ::rtl::OUString & i_rStream, const ::rtl::OUString & i_rIdref);
+
+ bool LookupXmlId(const Metadatable& i_xObject,
+ ::rtl::OUString & o_rStream, ::rtl::OUString & o_rIdref) const;
+
+ Metadatable* LookupElement(const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const;
+
+ const XmlIdList_t * LookupElementList(
+ const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const;
+
+ XmlIdList_t * LookupElementList(
+ const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref)
+ {
+ return const_cast<XmlIdList_t*>(
+ const_cast<const XmlIdRegistry_Impl*>(this)
+ ->LookupElementList(i_rStreamName, i_rIdref));
+ }
+
+ XmlIdMap_t m_XmlIdMap;
+ XmlIdReverseMap_t m_XmlIdReverseMap;
+};
+
+// -------------------------------------------------------------------
+
+static void
+rmIter(XmlIdMap_t & i_rXmlIdMap, XmlIdMap_t::iterator const& i_rIter,
+ ::rtl::OUString const & i_rStream, Metadatable const& i_rObject)
+{
+ if (i_rIter != i_rXmlIdMap.end())
+ {
+ XmlIdList_t & rList( isContentFile(i_rStream)
+ ? i_rIter->second.first : i_rIter->second.second );
+ rList.remove(&const_cast<Metadatable&>(i_rObject));
+ if (i_rIter->second.first.empty() && i_rIter->second.second.empty())
+ {
+ i_rXmlIdMap.erase(i_rIter);
+ }
+ }
+}
+
+// -------------------------------------------------------------------
+
+const XmlIdList_t *
+XmlIdRegistryDocument::XmlIdRegistry_Impl::LookupElementList(
+ const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const
+{
+ const XmlIdMap_t::const_iterator iter( m_XmlIdMap.find(i_rIdref) );
+ if (iter != m_XmlIdMap.end())
+ {
+ OSL_ENSURE(!iter->second.first.empty() || !iter->second.second.empty(),
+ "null entry in m_XmlIdMap");
+ return (isContentFile(i_rStreamName))
+ ? &iter->second.first
+ : &iter->second.second;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+Metadatable*
+XmlIdRegistryDocument::XmlIdRegistry_Impl::LookupElement(
+ const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const
+{
+ if (!isValidXmlId(i_rStreamName, i_rIdref))
+ {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "illegal XmlId"), 0, 0);
+ }
+
+ const XmlIdList_t * pList( LookupElementList(i_rStreamName, i_rIdref) );
+ if (pList)
+ {
+ const XmlIdList_t::const_iterator iter(
+ ::std::find_if(pList->begin(), pList->end(),
+ ::boost::bind(
+ ::std::logical_not<bool>(),
+ ::boost::bind(
+ ::std::logical_or<bool>(),
+ ::boost::bind( &Metadatable::IsInUndo, _1 ),
+ ::boost::bind( &Metadatable::IsInClipboard, _1 )
+ ) ) ) );
+ if (iter != pList->end())
+ {
+ return *iter;
+ }
+ }
+ return 0;
+}
+
+bool
+XmlIdRegistryDocument::XmlIdRegistry_Impl::LookupXmlId(
+ const Metadatable& i_rObject,
+ ::rtl::OUString & o_rStream, ::rtl::OUString & o_rIdref) const
+{
+ const XmlIdReverseMap_t::const_iterator iter(
+ m_XmlIdReverseMap.find(&i_rObject) );
+ if (iter != m_XmlIdReverseMap.end())
+ {
+ OSL_ENSURE(!iter->second.first.equalsAscii(""),
+ "null stream in m_XmlIdReverseMap");
+ OSL_ENSURE(!iter->second.second.equalsAscii(""),
+ "null id in m_XmlIdReverseMap");
+ o_rStream = iter->second.first;
+ o_rIdref = iter->second.second;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+bool
+XmlIdRegistryDocument::XmlIdRegistry_Impl::TryInsertMetadatable(
+ Metadatable & i_rObject,
+ const ::rtl::OUString & i_rStreamName, const ::rtl::OUString & i_rIdref)
+{
+ const bool bContent( isContentFile(i_rStreamName) );
+ OSL_ENSURE(isContentFile(i_rStreamName) || isStylesFile(i_rStreamName),
+ "invalid stream");
+
+ XmlIdList_t * pList( LookupElementList(i_rStreamName, i_rIdref) );
+ if (pList)
+ {
+ if (pList->empty())
+ {
+ pList->push_back( &i_rObject );
+ return true;
+ }
+ else
+ {
+ // this is only called from TryRegister now, so check
+ // if all elements in the list are deleted (in undo) or
+ // placeholders, then "steal" the id from them
+ if ( pList->end() == ::std::find_if(pList->begin(), pList->end(),
+ ::boost::bind(
+ ::std::logical_not<bool>(),
+ ::boost::bind(
+ ::std::logical_or<bool>(),
+ ::boost::bind( &Metadatable::IsInUndo, _1 ),
+ ::boost::bind( &Metadatable::IsInClipboard, _1 )
+ ) ) ) )
+ {
+// ??? this is not undoable
+// pList->clear();
+// pList->push_back( &i_rObject );
+ pList->push_front( &i_rObject );
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+ else
+ {
+ m_XmlIdMap.insert(::std::make_pair(i_rIdref, bContent
+ ? ::std::make_pair( XmlIdList_t( 1, &i_rObject ), XmlIdList_t() )
+ : ::std::make_pair( XmlIdList_t(), XmlIdList_t( 1, &i_rObject ) )));
+ return true;
+ }
+}
+
+//=============================================================================
+// Document XML ID Registry
+
+
+XmlIdRegistryDocument::XmlIdRegistryDocument()
+ : m_pImpl( new XmlIdRegistry_Impl )
+{
+}
+
+static void
+removeLink(Metadatable* i_pObject)
+{
+ OSL_ENSURE(i_pObject, "null in list ???");
+ if (!i_pObject) return;
+ if (i_pObject->IsInClipboard())
+ {
+ MetadatableClipboard* pLink(
+ dynamic_cast<MetadatableClipboard*>( i_pObject ) );
+ OSL_ENSURE(pLink, "IsInClipboard, but no MetadatableClipboard ?");
+ if (pLink)
+ {
+ pLink->OriginNoLongerInBusinessAnymore();
+ }
+ }
+}
+
+XmlIdRegistryDocument::~XmlIdRegistryDocument()
+{
+ // notify all list elements that are actually in the clipboard
+ for (XmlIdMap_t::iterator iter(m_pImpl->m_XmlIdMap.begin());
+ iter != m_pImpl->m_XmlIdMap.end(); ++iter)
+ {
+ ::std::for_each(iter->second.first.begin(), iter->second.first.end(),
+ removeLink);
+ ::std::for_each(iter->second.second.begin(), iter->second.second.end(),
+ removeLink);
+ }
+}
+
+bool
+XmlIdRegistryDocument::LookupXmlId(
+ const Metadatable& i_rObject,
+ ::rtl::OUString & o_rStream, ::rtl::OUString & o_rIdref) const
+{
+ return m_pImpl->LookupXmlId(i_rObject, o_rStream, o_rIdref);
+}
+
+Metadatable*
+XmlIdRegistryDocument::LookupElement(
+ const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const
+{
+ return m_pImpl->LookupElement(i_rStreamName, i_rIdref);
+}
+
+bool
+XmlIdRegistryDocument::TryRegisterMetadatable(Metadatable & i_rObject,
+ ::rtl::OUString const& i_rStreamName, ::rtl::OUString const& i_rIdref)
+{
+ OSL_TRACE("TryRegisterMetadatable: %p (%s#%s)\n", &i_rObject,
+ ::rtl::OUStringToOString(i_rStreamName, RTL_TEXTENCODING_UTF8).getStr(),
+ ::rtl::OUStringToOString(i_rIdref, RTL_TEXTENCODING_UTF8).getStr());
+
+ OSL_ENSURE(!dynamic_cast<MetadatableUndo*>(&i_rObject),
+ "TryRegisterMetadatable called for MetadatableUndo?");
+ OSL_ENSURE(!dynamic_cast<MetadatableClipboard*>(&i_rObject),
+ "TryRegisterMetadatable called for MetadatableClipboard?");
+
+ if (!isValidXmlId(i_rStreamName, i_rIdref))
+ {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "illegal XmlId"), 0, 0);
+ }
+ if (i_rObject.IsInContent()
+ ? !isContentFile(i_rStreamName)
+ : !isStylesFile(i_rStreamName))
+ {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "illegal XmlId: wrong stream"), 0, 0);
+ }
+
+ ::rtl::OUString old_path;
+ ::rtl::OUString old_idref;
+ m_pImpl->LookupXmlId(i_rObject, old_path, old_idref);
+ if (old_path == i_rStreamName && old_idref == i_rIdref)
+ {
+ return (m_pImpl->LookupElement(old_path, old_idref) == &i_rObject);
+ }
+ XmlIdMap_t::iterator old_id( m_pImpl->m_XmlIdMap.end() );
+ if (!old_idref.equalsAscii(""))
+ {
+ old_id = m_pImpl->m_XmlIdMap.find(old_idref);
+ OSL_ENSURE(old_id != m_pImpl->m_XmlIdMap.end(), "old id not found");
+ }
+ if (m_pImpl->TryInsertMetadatable(i_rObject, i_rStreamName, i_rIdref))
+ {
+ rmIter(m_pImpl->m_XmlIdMap, old_id, old_path, i_rObject);
+ m_pImpl->m_XmlIdReverseMap[&i_rObject] =
+ ::std::make_pair(i_rStreamName, i_rIdref);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+void
+XmlIdRegistryDocument::RegisterMetadatableAndCreateID(Metadatable & i_rObject)
+{
+ OSL_TRACE("RegisterMetadatableAndCreateID: %p\n", &i_rObject);
+
+ OSL_ENSURE(!dynamic_cast<MetadatableUndo*>(&i_rObject),
+ "RegisterMetadatableAndCreateID called for MetadatableUndo?");
+ OSL_ENSURE(!dynamic_cast<MetadatableClipboard*>(&i_rObject),
+ "RegisterMetadatableAndCreateID called for MetadatableClipboard?");
+
+ const bool isInContent( i_rObject.IsInContent() );
+ const ::rtl::OUString stream( ::rtl::OUString::createFromAscii(
+ isInContent ? s_content : s_styles ) );
+ // check if we have a latent xmlid, and if yes, remove it
+ ::rtl::OUString old_path;
+ ::rtl::OUString old_idref;
+ m_pImpl->LookupXmlId(i_rObject, old_path, old_idref);
+
+ XmlIdMap_t::iterator old_id( m_pImpl->m_XmlIdMap.end() );
+ if (!old_idref.equalsAscii(""))
+ {
+ old_id = m_pImpl->m_XmlIdMap.find(old_idref);
+ OSL_ENSURE(old_id != m_pImpl->m_XmlIdMap.end(), "old id not found");
+ if (m_pImpl->LookupElement(old_path, old_idref) == &i_rObject)
+ {
+ return;
+ }
+ else
+ {
+ // remove latent xmlid
+ rmIter(m_pImpl->m_XmlIdMap, old_id, old_path, i_rObject);
+ }
+ }
+
+ // create id
+ const ::rtl::OUString id( create_id(m_pImpl->m_XmlIdMap) );
+ OSL_ENSURE(m_pImpl->m_XmlIdMap.find(id) == m_pImpl->m_XmlIdMap.end(),
+ "created id is in use");
+ m_pImpl->m_XmlIdMap.insert(::std::make_pair(id, isInContent
+ ? ::std::make_pair( XmlIdList_t( 1, &i_rObject ), XmlIdList_t() )
+ : ::std::make_pair( XmlIdList_t(), XmlIdList_t( 1, &i_rObject ) )));
+ m_pImpl->m_XmlIdReverseMap[&i_rObject] = ::std::make_pair(stream, id);
+}
+
+void XmlIdRegistryDocument::UnregisterMetadatable(const Metadatable& i_rObject)
+{
+ OSL_TRACE("UnregisterMetadatable: %p\n", &i_rObject);
+
+ ::rtl::OUString path;
+ ::rtl::OUString idref;
+ if (!m_pImpl->LookupXmlId(i_rObject, path, idref))
+ {
+ OSL_ENSURE(false, "unregister: no xml id?");
+ return;
+ }
+ const XmlIdMap_t::iterator iter( m_pImpl->m_XmlIdMap.find(idref) );
+ if (iter != m_pImpl->m_XmlIdMap.end())
+ {
+ rmIter(m_pImpl->m_XmlIdMap, iter, path, i_rObject);
+ }
+}
+
+void XmlIdRegistryDocument::RemoveXmlIdForElement(const Metadatable& i_rObject)
+{
+ OSL_TRACE("RemoveXmlIdForElement: %p\n", &i_rObject);
+
+ const XmlIdReverseMap_t::iterator iter(
+ m_pImpl->m_XmlIdReverseMap.find(&i_rObject) );
+ if (iter != m_pImpl->m_XmlIdReverseMap.end())
+ {
+ OSL_ENSURE(!iter->second.second.equalsAscii(""),
+ "null id in m_XmlIdReverseMap");
+ m_pImpl->m_XmlIdReverseMap.erase(iter);
+ }
+}
+
+// -------------------------------------------------------------------
+
+void XmlIdRegistryDocument::RegisterCopy(Metadatable const& i_rSource,
+ Metadatable & i_rCopy, const bool i_bCopyPrecedesSource)
+{
+ OSL_TRACE("RegisterCopy: %p -> %p (%d)\n",
+ &i_rSource, &i_rCopy, i_bCopyPrecedesSource);
+
+ // potential sources: clipboard, undo array, splitNode
+ // assumption: stream change can only happen via clipboard, and is handled
+ // by Metadatable::RegisterAsCopyOf
+ OSL_ENSURE(i_rSource.IsInUndo() || i_rCopy.IsInUndo() ||
+ (i_rSource.IsInContent() == i_rCopy.IsInContent()),
+ "RegisterCopy: not in same stream?");
+
+ ::rtl::OUString path;
+ ::rtl::OUString idref;
+ if (!m_pImpl->LookupXmlId( i_rSource, path, idref ))
+ {
+ OSL_ENSURE(false, "no xml id?");
+ return;
+ }
+ XmlIdList_t * pList ( m_pImpl->LookupElementList(path, idref) );
+ OSL_ENSURE( ::std::find( pList->begin(), pList->end(), &i_rCopy )
+ == pList->end(), "copy already registered???");
+ XmlIdList_t::iterator srcpos(
+ ::std::find( pList->begin(), pList->end(), &i_rSource ) );
+ OSL_ENSURE(srcpos != pList->end(), "source not in list???");
+ if (srcpos == pList->end())
+ {
+ return;
+ }
+ if (i_bCopyPrecedesSource)
+ {
+ pList->insert( srcpos, &i_rCopy );
+ }
+ else
+ {
+ // for undo push_back does not work! must insert right after source
+ pList->insert( ++srcpos, &i_rCopy );
+ }
+ m_pImpl->m_XmlIdReverseMap.insert(::std::make_pair(&i_rCopy,
+ ::std::make_pair(path, idref)));
+}
+
+::boost::shared_ptr<MetadatableUndo>
+XmlIdRegistryDocument::CreateUndo(Metadatable const& i_rObject)
+{
+ OSL_TRACE("CreateUndo: %p\n", &i_rObject);
+
+ return ::boost::shared_ptr<MetadatableUndo>(
+ new MetadatableUndo(i_rObject.IsInContent()) );
+}
+
+/*
+i_rMerged is both a source and the target node of the merge
+i_rOther is the other source, and will be deleted after the merge
+
+dimensions: none|latent|actual empty|nonempty
+i_rMerged(1) i_rOther(2) result
+ *|empty *|empty => 1|2 (arbitrary)
+ *|empty *|nonempty => 2
+ *|nonempty *|empty => 1
+ none|nonempty none|nonempty => none
+ none|nonempty latent|nonempty => 2
+latent|nonempty none|nonempty => 1
+latent|nonempty latent|nonempty => 1|2
+ *|nonempty actual|nonempty => 2
+actual|nonempty *|nonempty => 1
+actual|nonempty actual|nonempty => 1|2
+*/
+void
+XmlIdRegistryDocument::JoinMetadatables(
+ Metadatable & i_rMerged, Metadatable const & i_rOther)
+{
+ OSL_TRACE("JoinMetadatables: %p <- %p\n", &i_rMerged, &i_rOther);
+
+ bool mergedOwnsRef;
+ ::rtl::OUString path;
+ ::rtl::OUString idref;
+ if (m_pImpl->LookupXmlId(i_rMerged, path, idref))
+ {
+ mergedOwnsRef = (m_pImpl->LookupElement(path, idref) == &i_rMerged);
+ }
+ else
+ {
+ OSL_ENSURE(false, "JoinMetadatables: no xmlid?");
+ return;
+ }
+ if (!mergedOwnsRef)
+ {
+ i_rMerged.RemoveMetadataReference();
+ i_rMerged.RegisterAsCopyOf(i_rOther, true);
+ return;
+ }
+ // other cases: merged has actual ref and is nonempty,
+ // other has latent/actual ref and is nonempty: other loses => nothing to do
+}
+
+
+//=============================================================================
+// Clipboard XML ID Registry (_Impl)
+
+struct RMapEntry
+{
+ RMapEntry() : m_pLink() { }
+ RMapEntry(::rtl::OUString const& i_rStream,
+ ::rtl::OUString const& i_rXmlId,
+ ::boost::shared_ptr<MetadatableClipboard> const& i_pLink
+ = ::boost::shared_ptr<MetadatableClipboard>())
+ : m_Stream(i_rStream), m_XmlId(i_rXmlId), m_pLink(i_pLink)
+ {}
+ ::rtl::OUString m_Stream;
+ ::rtl::OUString m_XmlId;
+ // this would have been an auto_ptr, if only that would have compiled...
+ ::boost::shared_ptr<MetadatableClipboard> m_pLink;
+};
+
+/// element -> (stream name, idref, source)
+typedef ::std::hash_map< const Metadatable*,
+ struct RMapEntry,
+ PtrHash<Metadatable> >
+ ClipboardXmlIdReverseMap_t;
+
+/// Idref -> (content.xml element, styles.xml element)
+typedef ::std::hash_map< ::rtl::OUString,
+ ::std::pair< Metadatable*, Metadatable* >, ::rtl::OUStringHash >
+ ClipboardXmlIdMap_t;
+
+struct XmlIdRegistryClipboard::XmlIdRegistry_Impl
+{
+ XmlIdRegistry_Impl()
+ : m_XmlIdMap(), m_XmlIdReverseMap() { }
+
+ bool TryInsertMetadatable(Metadatable& i_xObject,
+ const ::rtl::OUString & i_rStream, const ::rtl::OUString & i_rIdref);
+
+ bool LookupXmlId(const Metadatable& i_xObject,
+ ::rtl::OUString & o_rStream, ::rtl::OUString & o_rIdref,
+ MetadatableClipboard const* &o_rpLink) const;
+
+ Metadatable* LookupElement(const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const;
+
+ Metadatable* const* LookupEntry(const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const;
+
+ Metadatable* * LookupEntry(const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref)
+ {
+ return const_cast<Metadatable**>(
+ const_cast<const XmlIdRegistry_Impl*>(this)
+ ->LookupEntry(i_rStreamName, i_rIdref));
+ }
+
+ ClipboardXmlIdMap_t m_XmlIdMap;
+ ClipboardXmlIdReverseMap_t m_XmlIdReverseMap;
+};
+
+// -------------------------------------------------------------------
+
+static void
+rmIter(ClipboardXmlIdMap_t & i_rXmlIdMap,
+ ClipboardXmlIdMap_t::iterator const& i_rIter,
+ ::rtl::OUString const & i_rStream, Metadatable const& i_rObject)
+{
+ if (i_rIter != i_rXmlIdMap.end())
+ {
+ Metadatable *& rMeta = isContentFile(i_rStream)
+ ? i_rIter->second.first : i_rIter->second.second;
+ if (rMeta == &i_rObject)
+ {
+ rMeta = 0;
+ }
+ if (!i_rIter->second.first && !i_rIter->second.second)
+ {
+ i_rXmlIdMap.erase(i_rIter);
+ }
+ }
+}
+
+// -------------------------------------------------------------------
+
+Metadatable* const*
+XmlIdRegistryClipboard::XmlIdRegistry_Impl::LookupEntry(
+ const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const
+{
+ if (!isValidXmlId(i_rStreamName, i_rIdref))
+ {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "illegal XmlId"), 0, 0);
+ }
+
+ const ClipboardXmlIdMap_t::const_iterator iter( m_XmlIdMap.find(i_rIdref) );
+ if (iter != m_XmlIdMap.end())
+ {
+ OSL_ENSURE(iter->second.first || iter->second.second,
+ "null entry in m_XmlIdMap");
+ return (isContentFile(i_rStreamName))
+ ? &iter->second.first
+ : &iter->second.second;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+Metadatable*
+XmlIdRegistryClipboard::XmlIdRegistry_Impl::LookupElement(
+ const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const
+{
+ Metadatable * const * ppEntry = LookupEntry(i_rStreamName, i_rIdref);
+ return ppEntry ? *ppEntry : 0;
+}
+
+bool
+XmlIdRegistryClipboard::XmlIdRegistry_Impl::LookupXmlId(
+ const Metadatable& i_rObject,
+ ::rtl::OUString & o_rStream, ::rtl::OUString & o_rIdref,
+ MetadatableClipboard const* &o_rpLink) const
+{
+ const ClipboardXmlIdReverseMap_t::const_iterator iter(
+ m_XmlIdReverseMap.find(&i_rObject) );
+ if (iter != m_XmlIdReverseMap.end())
+ {
+ OSL_ENSURE(!iter->second.m_Stream.equalsAscii(""),
+ "null stream in m_XmlIdReverseMap");
+ OSL_ENSURE(!iter->second.m_XmlId.equalsAscii(""),
+ "null id in m_XmlIdReverseMap");
+ o_rStream = iter->second.m_Stream;
+ o_rIdref = iter->second.m_XmlId;
+ o_rpLink = iter->second.m_pLink.get();
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+bool
+XmlIdRegistryClipboard::XmlIdRegistry_Impl::TryInsertMetadatable(
+ Metadatable & i_rObject,
+ const ::rtl::OUString & i_rStreamName, const ::rtl::OUString & i_rIdref)
+{
+ bool bContent( isContentFile(i_rStreamName) );
+ OSL_ENSURE(isContentFile(i_rStreamName) || isStylesFile(i_rStreamName),
+ "invalid stream");
+
+ //wntmsci12 won't parse this:
+// Metadatable ** ppEntry( LookupEntry(i_rStreamName, i_rIdref) );
+ Metadatable ** ppEntry = LookupEntry(i_rStreamName, i_rIdref);
+ if (ppEntry)
+ {
+ if (*ppEntry)
+ {
+ return false;
+ }
+ else
+ {
+ *ppEntry = &i_rObject;
+ return true;
+ }
+ }
+ else
+ {
+ m_XmlIdMap.insert(::std::make_pair(i_rIdref, bContent
+ ? ::std::make_pair( &i_rObject, static_cast<Metadatable*>(0) )
+ : ::std::make_pair( static_cast<Metadatable*>(0), &i_rObject )));
+ return true;
+ }
+}
+
+//=============================================================================
+// Clipboard XML ID Registry
+
+
+XmlIdRegistryClipboard::XmlIdRegistryClipboard()
+ : m_pImpl( new XmlIdRegistry_Impl )
+{
+}
+
+XmlIdRegistryClipboard::~XmlIdRegistryClipboard()
+{
+}
+
+bool
+XmlIdRegistryClipboard::LookupXmlId(
+ const Metadatable& i_rObject,
+ ::rtl::OUString & o_rStream, ::rtl::OUString & o_rIdref) const
+{
+ const MetadatableClipboard * pLink;
+ return m_pImpl->LookupXmlId(i_rObject, o_rStream, o_rIdref, pLink);
+}
+
+Metadatable*
+XmlIdRegistryClipboard::LookupElement(
+ const ::rtl::OUString & i_rStreamName,
+ const ::rtl::OUString & i_rIdref) const
+{
+ return m_pImpl->LookupElement(i_rStreamName, i_rIdref);
+}
+
+bool
+XmlIdRegistryClipboard::TryRegisterMetadatable(Metadatable & i_rObject,
+ ::rtl::OUString const& i_rStreamName, ::rtl::OUString const& i_rIdref)
+{
+ OSL_TRACE("TryRegisterMetadatable: %p (%s#%s)\n", &i_rObject,
+ ::rtl::OUStringToOString(i_rStreamName, RTL_TEXTENCODING_UTF8).getStr(),
+ ::rtl::OUStringToOString(i_rIdref, RTL_TEXTENCODING_UTF8).getStr());
+
+ OSL_ENSURE(!dynamic_cast<MetadatableUndo*>(&i_rObject),
+ "TryRegisterMetadatable called for MetadatableUndo?");
+ OSL_ENSURE(!dynamic_cast<MetadatableClipboard*>(&i_rObject),
+ "TryRegisterMetadatable called for MetadatableClipboard?");
+
+ if (!isValidXmlId(i_rStreamName, i_rIdref))
+ {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "illegal XmlId"), 0, 0);
+ }
+ if (i_rObject.IsInContent()
+ ? !isContentFile(i_rStreamName)
+ : !isStylesFile(i_rStreamName))
+ {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "illegal XmlId: wrong stream"), 0, 0);
+ }
+
+ ::rtl::OUString old_path;
+ ::rtl::OUString old_idref;
+ const MetadatableClipboard * pLink;
+ m_pImpl->LookupXmlId(i_rObject, old_path, old_idref, pLink);
+ if (old_path == i_rStreamName && old_idref == i_rIdref)
+ {
+ return (m_pImpl->LookupElement(old_path, old_idref) == &i_rObject);
+ }
+ ClipboardXmlIdMap_t::iterator old_id( m_pImpl->m_XmlIdMap.end() );
+ if (!old_idref.equalsAscii(""))
+ {
+ old_id = m_pImpl->m_XmlIdMap.find(old_idref);
+ OSL_ENSURE(old_id != m_pImpl->m_XmlIdMap.end(), "old id not found");
+ }
+ if (m_pImpl->TryInsertMetadatable(i_rObject, i_rStreamName, i_rIdref))
+ {
+ rmIter(m_pImpl->m_XmlIdMap, old_id, old_path, i_rObject);
+ m_pImpl->m_XmlIdReverseMap[&i_rObject] =
+ RMapEntry(i_rStreamName, i_rIdref);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+void
+XmlIdRegistryClipboard::RegisterMetadatableAndCreateID(Metadatable & i_rObject)
+{
+ OSL_TRACE("RegisterMetadatableAndCreateID: %p\n", &i_rObject);
+
+ OSL_ENSURE(!dynamic_cast<MetadatableUndo*>(&i_rObject),
+ "RegisterMetadatableAndCreateID called for MetadatableUndo?");
+ OSL_ENSURE(!dynamic_cast<MetadatableClipboard*>(&i_rObject),
+ "RegisterMetadatableAndCreateID called for MetadatableClipboard?");
+
+ bool isInContent( i_rObject.IsInContent() );
+ ::rtl::OUString stream( ::rtl::OUString::createFromAscii(
+ isInContent ? s_content : s_styles ) );
+
+ ::rtl::OUString old_path;
+ ::rtl::OUString old_idref;
+ LookupXmlId(i_rObject, old_path, old_idref);
+ if (!old_idref.equalsAscii("") &&
+ (m_pImpl->LookupElement(old_path, old_idref) == &i_rObject))
+ {
+ return;
+ }
+
+ // create id
+ const ::rtl::OUString id( create_id(m_pImpl->m_XmlIdMap) );
+ OSL_ENSURE(m_pImpl->m_XmlIdMap.find(id) == m_pImpl->m_XmlIdMap.end(),
+ "created id is in use");
+ m_pImpl->m_XmlIdMap.insert(::std::make_pair(id, isInContent
+ ? ::std::make_pair( &i_rObject, static_cast<Metadatable*>(0) )
+ : ::std::make_pair( static_cast<Metadatable*>(0), &i_rObject )));
+ // N.B.: if i_rObject had a latent XmlId, then we implicitly delete the
+ // MetadatableClipboard and thus the latent XmlId here
+ m_pImpl->m_XmlIdReverseMap[&i_rObject] = RMapEntry(stream, id);
+}
+
+void XmlIdRegistryClipboard::UnregisterMetadatable(const Metadatable& i_rObject)
+{
+ OSL_TRACE("UnregisterMetadatable: %p\n", &i_rObject);
+
+ ::rtl::OUString path;
+ ::rtl::OUString idref;
+ const MetadatableClipboard * pLink;
+ if (!m_pImpl->LookupXmlId(i_rObject, path, idref, pLink))
+ {
+ OSL_ENSURE(false, "unregister: no xml id?");
+ return;
+ }
+ const ClipboardXmlIdMap_t::iterator iter( m_pImpl->m_XmlIdMap.find(idref) );
+ if (iter != m_pImpl->m_XmlIdMap.end())
+ {
+ rmIter(m_pImpl->m_XmlIdMap, iter, path, i_rObject);
+ }
+}
+
+
+void XmlIdRegistryClipboard::RemoveXmlIdForElement(const Metadatable& i_rObject)
+{
+ OSL_TRACE("RemoveXmlIdForElement: %p\n", &i_rObject);
+
+ ClipboardXmlIdReverseMap_t::iterator iter(
+ m_pImpl->m_XmlIdReverseMap.find(&i_rObject) );
+ if (iter != m_pImpl->m_XmlIdReverseMap.end())
+ {
+ OSL_ENSURE(!iter->second.m_XmlId.equalsAscii(""),
+ "null id in m_XmlIdReverseMap");
+ m_pImpl->m_XmlIdReverseMap.erase(iter);
+ }
+}
+
+// -------------------------------------------------------------------
+
+::boost::shared_ptr<MetadatableClipboard>
+XmlIdRegistryClipboard::CreateClipboard(const bool i_isInContent)
+{
+ OSL_TRACE("CreateClipboard: \n");
+
+ return ::boost::shared_ptr<MetadatableClipboard>(
+ new MetadatableClipboard(i_isInContent) );
+}
+
+MetadatableClipboard &
+XmlIdRegistryClipboard::RegisterCopyClipboard(Metadatable & i_rCopy,
+ beans::StringPair const & i_rReference,
+ const bool i_isLatent)
+{
+ OSL_TRACE("RegisterCopyClipboard: %p -> "/*"%p"*/"(%s#%s) (%d)\n",
+ /*&i_rSource,*/ &i_rCopy,
+ ::rtl::OUStringToOString(i_rReference.First,
+ RTL_TEXTENCODING_UTF8).getStr(),
+ ::rtl::OUStringToOString(i_rReference.Second,
+ RTL_TEXTENCODING_UTF8).getStr(),
+ i_isLatent);
+
+ // N.B.: when copying to the clipboard, the selection is always inserted
+ // into the body, even if the source is a header/footer!
+ // so we do not check whether the stream is right in this function
+
+ if (!isValidXmlId(i_rReference.First, i_rReference.Second))
+ {
+ throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
+ "illegal XmlId"), 0, 0);
+ }
+
+ if (!i_isLatent)
+ {
+ // this should succeed assuming clipboard has a single source document
+ const bool success( m_pImpl->TryInsertMetadatable(i_rCopy,
+ i_rReference.First, i_rReference.Second) );
+ OSL_ENSURE(success, "RegisterCopyClipboard: TryInsert failed?");
+ (void) success;
+ }
+ const ::boost::shared_ptr<MetadatableClipboard> pLink(
+ CreateClipboard( isContentFile(i_rReference.First)) );
+ m_pImpl->m_XmlIdReverseMap.insert(::std::make_pair(&i_rCopy,
+ RMapEntry(i_rReference.First, i_rReference.Second, pLink)));
+ return *pLink.get();
+}
+
+MetadatableClipboard const*
+XmlIdRegistryClipboard::SourceLink(Metadatable const& i_rObject)
+{
+ ::rtl::OUString path;
+ ::rtl::OUString idref;
+ const MetadatableClipboard * pLink( 0 );
+ m_pImpl->LookupXmlId(i_rObject, path, idref, pLink);
+ return pLink;
+}
+
+
+//=============================================================================
+// Metadatable mixin
+
+
+Metadatable::~Metadatable()
+{
+ RemoveMetadataReference();
+}
+
+void Metadatable::RemoveMetadataReference()
+{
+ try
+ {
+ if (m_pReg)
+ {
+ m_pReg->UnregisterMetadatable( *this );
+ m_pReg->RemoveXmlIdForElement( *this );
+ m_pReg = 0;
+ }
+ }
+ catch (uno::Exception &)
+ {
+ OSL_ENSURE(false, "Metadatable::RemoveMetadataReference: exception");
+ }
+}
+
+// ::com::sun::star::rdf::XMetadatable:
+beans::StringPair
+Metadatable::GetMetadataReference() const
+{
+ if (m_pReg)
+ {
+ return m_pReg->GetXmlIdForElement(*this);
+ }
+ return beans::StringPair();
+}
+
+void
+Metadatable::SetMetadataReference(
+ const ::com::sun::star::beans::StringPair & i_rReference)
+{
+ if (i_rReference.Second.equalsAscii(""))
+ {
+ RemoveMetadataReference();
+ }
+ else
+ {
+ ::rtl::OUString streamName( i_rReference.First );
+ if (streamName.equalsAscii(""))
+ {
+ // handle empty stream name as auto-detect.
+ // necessary for importing flat file format.
+ streamName = ::rtl::OUString::createFromAscii(
+ IsInContent() ? s_content : s_styles );
+ }
+ XmlIdRegistry & rReg( dynamic_cast<XmlIdRegistry&>( GetRegistry() ) );
+ if (rReg.TryRegisterMetadatable(*this, streamName, i_rReference.Second))
+ {
+ m_pReg = &rReg;
+ }
+ else
+ {
+ throw lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii("Metadatable::"
+ "SetMetadataReference: argument is invalid"), /*this*/0, 0);
+ }
+ }
+}
+
+void Metadatable::EnsureMetadataReference()
+{
+ XmlIdRegistry& rReg(
+ m_pReg ? *m_pReg : dynamic_cast<XmlIdRegistry&>( GetRegistry() ) );
+ rReg.RegisterMetadatableAndCreateID( *this );
+ m_pReg = &rReg;
+}
+
+const ::sfx2::IXmlIdRegistry& GetRegistryConst(Metadatable const& i_rObject)
+{
+ return const_cast< Metadatable& >( i_rObject ).GetRegistry();
+}
+
+void
+Metadatable::RegisterAsCopyOf(Metadatable const & i_rSource,
+ const bool i_bCopyPrecedesSource)
+{
+ OSL_ENSURE(typeid(*this) == typeid(i_rSource)
+ || typeid(i_rSource) == typeid(MetadatableUndo)
+ || typeid(*this) == typeid(MetadatableUndo)
+ || typeid(i_rSource) == typeid(MetadatableClipboard)
+ || typeid(*this) == typeid(MetadatableClipboard),
+ "RegisterAsCopyOf element with different class?");
+ OSL_ENSURE(!this->m_pReg, "RegisterAsCopyOf called on element with XmlId?");
+
+ if (this->m_pReg)
+ {
+ RemoveMetadataReference();
+ }
+
+ try
+ {
+ if (i_rSource.m_pReg)
+ {
+ XmlIdRegistry & rReg(
+ dynamic_cast<XmlIdRegistry&>( GetRegistry() ) );
+ if (i_rSource.m_pReg == &rReg)
+ {
+ OSL_ENSURE(!IsInClipboard(),
+ "RegisterAsCopy: both in clipboard?");
+ if (!IsInClipboard())
+ {
+ XmlIdRegistryDocument & rRegDoc(
+ dynamic_cast<XmlIdRegistryDocument&>( rReg ) );
+ rRegDoc.RegisterCopy(i_rSource, *this,
+ i_bCopyPrecedesSource);
+ this->m_pReg = &rRegDoc;
+ }
+ return;
+ }
+ // source is in different document
+ XmlIdRegistryDocument * pRegDoc(
+ dynamic_cast<XmlIdRegistryDocument *>(&rReg) );
+ XmlIdRegistryClipboard * pRegClp(
+ dynamic_cast<XmlIdRegistryClipboard*>(&rReg) );
+
+ if (pRegClp)
+ {
+ beans::StringPair SourceRef(
+ i_rSource.m_pReg->GetXmlIdForElement(i_rSource) );
+ bool isLatent( SourceRef.Second.equalsAscii("") );
+ XmlIdRegistryDocument * pSourceRegDoc(
+ dynamic_cast<XmlIdRegistryDocument*>(i_rSource.m_pReg) );
+ OSL_ENSURE(pSourceRegDoc, "RegisterAsCopyOf: 2 clipboards?");
+ if (!pSourceRegDoc) return;
+ // this is a copy _to_ the clipboard
+ if (isLatent)
+ {
+ pSourceRegDoc->LookupXmlId(i_rSource,
+ SourceRef.First, SourceRef.Second);
+ }
+ Metadatable & rLink(
+ pRegClp->RegisterCopyClipboard(*this, SourceRef, isLatent));
+ this->m_pReg = pRegClp;
+ // register as copy in the non-clipboard registry
+ pSourceRegDoc->RegisterCopy(i_rSource, rLink,
+ false); // i_bCopyPrecedesSource);
+ rLink.m_pReg = pSourceRegDoc;
+ }
+ else if (pRegDoc)
+ {
+ XmlIdRegistryClipboard * pSourceRegClp(
+ dynamic_cast<XmlIdRegistryClipboard*>(i_rSource.m_pReg) );
+ OSL_ENSURE(pSourceRegClp,
+ "RegisterAsCopyOf: 2 non-clipboards?");
+ if (!pSourceRegClp) return;
+ const MetadatableClipboard * pLink(
+ pSourceRegClp->SourceLink(i_rSource) );
+ // may happen if src got its id via UNO call
+ if (!pLink) return;
+ // only register copy if clipboard content is from this SwDoc!
+ if (pLink && (&GetRegistryConst(*pLink) == pRegDoc))
+ {
+ // this is a copy _from_ the clipboard; check if the
+ // element is still in the same stream
+ // N.B.: we check the stream of pLink, not of i_rSource!
+ bool srcInContent( pLink->IsInContent() );
+ bool tgtInContent( this->IsInContent() );
+ if (srcInContent == tgtInContent)
+ {
+ pRegDoc->RegisterCopy(*pLink, *this,
+ true); // i_bCopyPrecedesSource);
+ this->m_pReg = pRegDoc;
+ }
+ // otherwise: stream change! do not register!
+ }
+ }
+ else
+ {
+ OSL_ENSURE(false, "neither RegDoc nor RegClp cannot happen");
+ }
+#if 0
+ {
+ //FIXME: do we need this at all???
+ XmlIdRegistryDocument & rRegDoc(
+ dynamic_cast<XmlIdRegistryDocument&>( rReg ) );
+ {
+ if (rRegDoc.TryRegisterMetadatable(*this, SourceRef))
+ {
+ this->m_pReg = &rRegDoc;
+ }
+ }
+ }
+#endif
+ }
+ }
+ catch (uno::Exception &)
+ {
+ OSL_ENSURE(false, "Metadatable::RegisterAsCopyOf: exception");
+ }
+}
+
+::boost::shared_ptr<MetadatableUndo> Metadatable::CreateUndo() const
+{
+ OSL_ENSURE(!IsInUndo(), "CreateUndo called for object in undo?");
+ OSL_ENSURE(!IsInClipboard(), "CreateUndo called for object in clipboard?");
+ try
+ {
+ if (!IsInClipboard() && !IsInUndo() && m_pReg)
+ {
+ XmlIdRegistryDocument * pRegDoc(
+ dynamic_cast<XmlIdRegistryDocument*>( m_pReg ) );
+ ::boost::shared_ptr<MetadatableUndo> pUndo(
+ pRegDoc->CreateUndo(*this) );
+ pRegDoc->RegisterCopy(*this, *pUndo, false);
+ pUndo->m_pReg = pRegDoc;
+ return pUndo;
+ }
+ }
+ catch (uno::Exception &)
+ {
+ OSL_ENSURE(false, "Metadatable::CreateUndo: exception");
+ }
+ return ::boost::shared_ptr<MetadatableUndo>();
+}
+
+::boost::shared_ptr<MetadatableUndo> Metadatable::CreateUndoForDelete()
+{
+ ::boost::shared_ptr<MetadatableUndo> const pUndo( CreateUndo() );
+ RemoveMetadataReference();
+ return pUndo;
+}
+
+void Metadatable::RestoreMetadata(
+ ::boost::shared_ptr<MetadatableUndo> const& i_pUndo)
+{
+ OSL_ENSURE(!IsInUndo(), "RestoreMetadata called for object in undo?");
+ OSL_ENSURE(!IsInClipboard(),
+ "RestoreMetadata called for object in clipboard?");
+ if (IsInClipboard() || IsInUndo()) return;
+ RemoveMetadataReference();
+ if (i_pUndo)
+ {
+ this->RegisterAsCopyOf(*i_pUndo, true);
+ }
+}
+
+void
+Metadatable::JoinMetadatable(Metadatable const & i_rOther,
+ const bool i_isMergedEmpty, const bool i_isOtherEmpty)
+{
+ OSL_ENSURE(!IsInUndo(), "JoinMetadatables called for object in undo?");
+ OSL_ENSURE(!IsInClipboard(),
+ "JoinMetadatables called for object in clipboard?");
+ if (IsInClipboard() || IsInUndo()) return;
+
+ if (i_isOtherEmpty && !i_isMergedEmpty)
+ {
+ // other is empty, thus loses => nothing to do
+ return;
+ }
+ if (i_isMergedEmpty && !i_isOtherEmpty)
+ {
+ this->RemoveMetadataReference();
+ this->RegisterAsCopyOf(i_rOther, true);
+ return;
+ }
+
+ if (!i_rOther.m_pReg)
+ {
+ // other doesn't have xmlid, thus loses => nothing to do
+ return;
+ }
+ if (!m_pReg)
+ {
+ this->RegisterAsCopyOf(i_rOther, true);
+ // assumption: i_rOther will be deleted, so don't unregister it here
+ return;
+ }
+ try
+ {
+ XmlIdRegistryDocument * pRegDoc(
+ dynamic_cast<XmlIdRegistryDocument*>( m_pReg ) );
+ OSL_ENSURE(pRegDoc, "JoinMetadatable: no pRegDoc?");
+ if (pRegDoc)
+ {
+ pRegDoc->JoinMetadatables(*this, i_rOther);
+ }
+ }
+ catch (uno::Exception &)
+ {
+ OSL_ENSURE(false, "Metadatable::JoinMetadatable: exception");
+ }
+}
+
+
+//=============================================================================
+// XMetadatable mixin
+
+// ::com::sun::star::rdf::XNode:
+::rtl::OUString SAL_CALL MetadatableMixin::getStringValue()
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ return getNamespace() + getLocalName();
+}
+
+// ::com::sun::star::rdf::XURI:
+::rtl::OUString SAL_CALL MetadatableMixin::getLocalName()
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ beans::StringPair mdref( getMetadataReference() );
+ if (!mdref.Second.getLength())
+ {
+ ensureMetadataReference(); // N.B.: side effect!
+ mdref = getMetadataReference();
+ }
+ ::rtl::OUStringBuffer buf;
+ buf.append(mdref.First);
+ buf.append(static_cast<sal_Unicode>('#'));
+ buf.append(mdref.Second);
+ return buf.makeStringAndClear();
+}
+
+::rtl::OUString SAL_CALL MetadatableMixin::getNamespace()
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ const uno::Reference< frame::XModel > xModel( GetModel() );
+ const uno::Reference< rdf::XURI > xDMA( xModel, uno::UNO_QUERY_THROW );
+ return xDMA->getStringValue();
+}
+
+// ::com::sun::star::rdf::XMetadatable:
+beans::StringPair SAL_CALL
+MetadatableMixin::getMetadataReference()
+throw (uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ Metadatable *const pObject( GetCoreObject() );
+ if (!pObject)
+ {
+ throw uno::RuntimeException(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "MetadatableMixin: cannot get core object; not inserted?")),
+ *this);
+ }
+ return pObject->GetMetadataReference();
+}
+
+void SAL_CALL
+MetadatableMixin::setMetadataReference(
+ const beans::StringPair & i_rReference)
+throw (uno::RuntimeException, lang::IllegalArgumentException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ Metadatable *const pObject( GetCoreObject() );
+ if (!pObject)
+ {
+ throw uno::RuntimeException(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "MetadatableMixin: cannot get core object; not inserted?")),
+ *this);
+ }
+ return pObject->SetMetadataReference(i_rReference);
+}
+
+void SAL_CALL MetadatableMixin::ensureMetadataReference()
+throw (uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ Metadatable *const pObject( GetCoreObject() );
+ if (!pObject)
+ {
+ throw uno::RuntimeException(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "MetadatableMixin: cannot get core object; not inserted?")),
+ *this);
+ }
+ return pObject->EnsureMetadataReference();
+}
+
+} // namespace sfx2
+
+
+//=============================================================================
+
+#if OSL_DEBUG_LEVEL > 1
+
+#include <stdio.h>
+
+static void dump(sfx2::XmlIdList_t * pList)
+#ifdef GCC
+__attribute__ ((unused))
+#endif
+;
+static void dump(sfx2::XmlIdList_t * pList)
+{
+ fprintf(stderr, "\nXmlIdList(%p): ", pList);
+ for (sfx2::XmlIdList_t::iterator i = pList->begin(); i != pList->end(); ++i)
+ {
+ fprintf(stderr, "%p ", *i);
+ }
+ fprintf(stderr, "\n");
+}
+
+#endif
+
diff --git a/sfx2/source/doc/QuerySaveDocument.cxx b/sfx2/source/doc/QuerySaveDocument.cxx
new file mode 100644
index 000000000000..1907e54246ab
--- /dev/null
+++ b/sfx2/source/doc/QuerySaveDocument.cxx
@@ -0,0 +1,49 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include "sfx2/QuerySaveDocument.hxx"
+
+#include <sfx2/sfx.hrc>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/sfxuno.hxx>
+#include "doc.hrc"
+#include <vcl/msgbox.hxx>
+
+// -----------------------------------------------------------------------------
+short ExecuteQuerySaveDocument(Window* _pParent,const String& _rTitle)
+{
+ String aText( SfxResId( STR_QUERY_SAVE_DOCUMENT ) );
+ aText.SearchAndReplace( DEFINE_CONST_UNICODE( "$(DOC)" ),
+ _rTitle );
+ QueryBox aQBox( _pParent, WB_YES_NO_CANCEL | WB_DEF_YES, aText );
+ aQBox.SetButtonText( BUTTONID_NO, SfxResId( STR_NOSAVEANDCLOSE ) );
+ aQBox.SetButtonText( BUTTONID_YES, SfxResId( STR_SAVEDOC ) );
+ return aQBox.Execute();
+}
+// -----------------------------------------------------------------------------
diff --git a/sfx2/source/doc/SfxDocumentMetaData.cxx b/sfx2/source/doc/SfxDocumentMetaData.cxx
new file mode 100644
index 000000000000..f18e903eb6e4
--- /dev/null
+++ b/sfx2/source/doc/SfxDocumentMetaData.cxx
@@ -0,0 +1,2384 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_sfx2.hxx"
+
+#include "sal/config.h"
+#include "cppuhelper/factory.hxx"
+#include "cppuhelper/implementationentry.hxx"
+#include "cppuhelper/compbase6.hxx"
+#include "com/sun/star/lang/XServiceInfo.hpp"
+#include "com/sun/star/document/XDocumentProperties.hpp"
+#include "com/sun/star/lang/XInitialization.hpp"
+#include "com/sun/star/util/XCloneable.hpp"
+#include "com/sun/star/util/XModifiable.hpp"
+#include "com/sun/star/xml/sax/XSAXSerializable.hpp"
+
+#include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
+#include "com/sun/star/lang/EventObject.hpp"
+#include "com/sun/star/beans/XPropertySet.hpp"
+#include "com/sun/star/beans/XPropertySetInfo.hpp"
+#include "com/sun/star/beans/PropertyAttribute.hpp"
+#include "com/sun/star/task/ErrorCodeIOException.hpp"
+#include "com/sun/star/embed/XStorage.hpp"
+#include "com/sun/star/embed/XTransactedObject.hpp"
+#include "com/sun/star/embed/ElementModes.hpp"
+#include "com/sun/star/io/XActiveDataControl.hpp"
+#include "com/sun/star/io/XActiveDataSource.hpp"
+#include "com/sun/star/io/XStream.hpp"
+#include "com/sun/star/document/XImporter.hpp"
+#include "com/sun/star/document/XExporter.hpp"
+#include "com/sun/star/document/XFilter.hpp"
+#include "com/sun/star/xml/sax/XParser.hpp"
+#include "com/sun/star/xml/dom/XDocument.hpp"
+#include "com/sun/star/xml/dom/XElement.hpp"
+#include "com/sun/star/xml/dom/XDocumentBuilder.hpp"
+#include "com/sun/star/xml/dom/XSAXDocumentBuilder.hpp"
+#include "com/sun/star/xml/dom/NodeType.hpp"
+#include "com/sun/star/xml/xpath/XXPathAPI.hpp"
+#include "com/sun/star/util/Date.hpp"
+#include "com/sun/star/util/Time.hpp"
+#include "com/sun/star/util/Duration.hpp"
+
+#include "SfxDocumentMetaData.hxx"
+#include "rtl/ustrbuf.hxx"
+#include "tools/debug.hxx"
+#include "tools/string.hxx" // for DBG
+#include "tools/datetime.hxx"
+#include "tools/urlobj.hxx"
+#include "osl/mutex.hxx"
+#include "cppuhelper/basemutex.hxx"
+#include "cppuhelper/interfacecontainer.hxx"
+#include "comphelper/storagehelper.hxx"
+#include "comphelper/mediadescriptor.hxx"
+#include "comphelper/sequenceasvector.hxx"
+#include "comphelper/stlunosequence.hxx"
+#include "sot/storage.hxx"
+#include "sfx2/docfile.hxx"
+#include "sax/tools/converter.hxx"
+
+#include <utility>
+#include <vector>
+#include <map>
+#include <cstring>
+#include <limits>
+
+/**
+ * This file contains the implementation of the service
+ * com.sun.star.document.DocumentProperties.
+ * This service enables access to the meta-data stored in documents.
+ * Currently, this service only handles documents in ODF format.
+ *
+ * The implementation uses an XML DOM to store the properties.
+ * This approach was taken because it allows for preserving arbitrary XML data
+ * in loaded documents, which will be stored unmodified when saving the
+ * document again.
+ *
+ * Upon access, some properties are directly read from and updated in the DOM.
+ * Exception: it seems impossible to get notified upon addition of a property
+ * to a com.sun.star.beans.PropertyBag, which is used for storing user-defined
+ * properties; because of this, user-defined properties are updated in the
+ * XML DOM only when storing the document.
+ * Exception 2: when setting certain properties which correspond to attributes
+ * in the XML DOM, we want to remove the corresponding XML element. Detecting
+ * this condition can get messy, so we store all such properties as members,
+ * and update the DOM tree only when storing the document (in
+ * <method>updateUserDefinedAndAttributes</method>).
+ *
+ * @author mst
+ */
+
+/// anonymous implementation namespace
+namespace {
+
+namespace css = ::com::sun::star;
+
+
+/// a list of attribute-lists, where attribute means name and content
+typedef std::vector<std::vector<std::pair<const char*, ::rtl::OUString> > >
+ AttrVector;
+
+typedef ::cppu::WeakComponentImplHelper6<
+ css::lang::XServiceInfo,
+ css::document::XDocumentProperties,
+ css::lang::XInitialization,
+ css::util::XCloneable,
+ css::util::XModifiable,
+ css::xml::sax::XSAXSerializable>
+ SfxDocumentMetaData_Base;
+
+class SfxDocumentMetaData:
+ private ::cppu::BaseMutex,
+ public SfxDocumentMetaData_Base
+{
+public:
+ explicit SfxDocumentMetaData(
+ css::uno::Reference< css::uno::XComponentContext > const & context);
+
+ // ::com::sun::star::lang::XServiceInfo:
+ virtual ::rtl::OUString SAL_CALL getImplementationName()
+ throw (css::uno::RuntimeException);
+ virtual ::sal_Bool SAL_CALL supportsService(
+ const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException);
+ virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL
+ getSupportedServiceNames() throw (css::uno::RuntimeException);
+
+ // ::com::sun::star::lang::XComponent:
+ virtual void SAL_CALL dispose() throw (css::uno::RuntimeException);
+
+ // ::com::sun::star::document::XDocumentProperties:
+ virtual ::rtl::OUString SAL_CALL getAuthor()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setAuthor(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getGenerator()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setGenerator(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual css::util::DateTime SAL_CALL getCreationDate()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setCreationDate(const css::util::DateTime & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getTitle()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setTitle(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getSubject()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setSubject(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getDescription()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setDescription(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getKeywords()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setKeywords(
+ const css::uno::Sequence< ::rtl::OUString > & the_value)
+ throw (css::uno::RuntimeException);
+ virtual css::lang::Locale SAL_CALL getLanguage()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setLanguage(const css::lang::Locale & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getModifiedBy()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setModifiedBy(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual css::util::DateTime SAL_CALL getModificationDate()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setModificationDate(
+ const css::util::DateTime & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getPrintedBy()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setPrintedBy(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual css::util::DateTime SAL_CALL getPrintDate()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setPrintDate(const css::util::DateTime & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getTemplateName()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setTemplateName(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getTemplateURL()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setTemplateURL(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual css::util::DateTime SAL_CALL getTemplateDate()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setTemplateDate(const css::util::DateTime & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getAutoloadURL()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setAutoloadURL(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::sal_Int32 SAL_CALL getAutoloadSecs()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setAutoloadSecs(::sal_Int32 the_value)
+ throw (css::uno::RuntimeException, css::lang::IllegalArgumentException);
+ virtual ::rtl::OUString SAL_CALL getDefaultTarget()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setDefaultTarget(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual css::uno::Sequence< css::beans::NamedValue > SAL_CALL
+ getDocumentStatistics() throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setDocumentStatistics(
+ const css::uno::Sequence< css::beans::NamedValue > & the_value)
+ throw (css::uno::RuntimeException);
+ virtual ::sal_Int16 SAL_CALL getEditingCycles()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setEditingCycles(::sal_Int16 the_value)
+ throw (css::uno::RuntimeException, css::lang::IllegalArgumentException);
+ virtual ::sal_Int32 SAL_CALL getEditingDuration()
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setEditingDuration(::sal_Int32 the_value)
+ throw (css::uno::RuntimeException, css::lang::IllegalArgumentException);
+ virtual void SAL_CALL resetUserData(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException);
+ virtual css::uno::Reference< css::beans::XPropertyContainer > SAL_CALL
+ getUserDefinedProperties() throw (css::uno::RuntimeException);
+ virtual void SAL_CALL loadFromStorage(
+ const css::uno::Reference< css::embed::XStorage > & Storage,
+ const css::uno::Sequence< css::beans::PropertyValue > & Medium)
+ throw (css::uno::RuntimeException, css::lang::IllegalArgumentException,
+ css::io::WrongFormatException,
+ css::lang::WrappedTargetException, css::io::IOException);
+ virtual void SAL_CALL loadFromMedium(const ::rtl::OUString & URL,
+ const css::uno::Sequence< css::beans::PropertyValue > & Medium)
+ throw (css::uno::RuntimeException,
+ css::io::WrongFormatException,
+ css::lang::WrappedTargetException, css::io::IOException);
+ virtual void SAL_CALL storeToStorage(
+ const css::uno::Reference< css::embed::XStorage > & Storage,
+ const css::uno::Sequence< css::beans::PropertyValue > & Medium)
+ throw (css::uno::RuntimeException, css::lang::IllegalArgumentException,
+ css::lang::WrappedTargetException, css::io::IOException);
+ virtual void SAL_CALL storeToMedium(const ::rtl::OUString & URL,
+ const css::uno::Sequence< css::beans::PropertyValue > & Medium)
+ throw (css::uno::RuntimeException,
+ css::lang::WrappedTargetException, css::io::IOException);
+
+ // ::com::sun::star::lang::XInitialization:
+ virtual void SAL_CALL initialize(
+ const css::uno::Sequence< css::uno::Any > & aArguments)
+ throw (css::uno::RuntimeException, css::uno::Exception);
+
+ // ::com::sun::star::util::XCloneable:
+ virtual css::uno::Reference<css::util::XCloneable> SAL_CALL createClone()
+ throw (css::uno::RuntimeException);
+
+ // ::com::sun::star::util::XModifiable:
+ virtual ::sal_Bool SAL_CALL isModified( )
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL setModified( ::sal_Bool bModified )
+ throw (css::beans::PropertyVetoException, css::uno::RuntimeException);
+
+ // ::com::sun::star::util::XModifyBroadcaster:
+ virtual void SAL_CALL addModifyListener(
+ const css::uno::Reference< css::util::XModifyListener > & xListener)
+ throw (css::uno::RuntimeException);
+ virtual void SAL_CALL removeModifyListener(
+ const css::uno::Reference< css::util::XModifyListener > & xListener)
+ throw (css::uno::RuntimeException);
+
+ // ::com::sun::star::xml::sax::XSAXSerializable
+ virtual void SAL_CALL serialize(
+ const css::uno::Reference<css::xml::sax::XDocumentHandler>& i_xHandler,
+ const css::uno::Sequence< css::beans::StringPair >& i_rNamespaces)
+ throw (css::uno::RuntimeException, css::xml::sax::SAXException);
+
+private:
+ SfxDocumentMetaData(SfxDocumentMetaData &); // not defined
+ SfxDocumentMetaData& operator =(SfxDocumentMetaData &); // not defined
+
+ virtual ~SfxDocumentMetaData() {}
+
+ const css::uno::Reference< css::uno::XComponentContext > m_xContext;
+
+ /// for notification
+ ::cppu::OInterfaceContainerHelper m_NotifyListeners;
+ /// flag: false means not initialized yet, or disposed
+ bool m_isInitialized;
+ /// flag
+ bool m_isModified;
+ /// meta-data DOM tree
+ css::uno::Reference< css::xml::dom::XDocument > m_xDoc;
+ /// meta-data super node in the meta-data DOM tree
+ css::uno::Reference< css::xml::dom::XNode> m_xParent;
+ /// standard meta data (single occurrence)
+ std::map< ::rtl::OUString, css::uno::Reference<css::xml::dom::XNode> >
+ m_meta;
+ /// standard meta data (multiple occurrences)
+ std::map< ::rtl::OUString,
+ std::vector<css::uno::Reference<css::xml::dom::XNode> > > m_metaList;
+ /// user-defined meta data (meta:user-defined) @ATTENTION may be null!
+ css::uno::Reference<css::beans::XPropertyContainer> m_xUserDefined;
+ // now for some meta-data attributes; these are not updated directly in the
+ // DOM because updates (detecting "empty" elements) would be quite messy
+ ::rtl::OUString m_TemplateName;
+ ::rtl::OUString m_TemplateURL;
+ css::util::DateTime m_TemplateDate;
+ ::rtl::OUString m_AutoloadURL;
+ sal_Int32 m_AutoloadSecs;
+ ::rtl::OUString m_DefaultTarget;
+
+ /// check if we are initialized properly
+ void SAL_CALL checkInit() const;
+ // throw (css::uno::RuntimeException);
+ /// initialize state from given DOM tree
+ void SAL_CALL init(css::uno::Reference<css::xml::dom::XDocument> i_xDom);
+ // throw (css::uno::RuntimeException, css::io::WrongFormatException,
+ // css::uno::Exception);
+ /// update element in DOM tree
+ void SAL_CALL updateElement(const char *i_name,
+ std::vector<std::pair<const char *, ::rtl::OUString> >* i_pAttrs = 0);
+ /// update user-defined meta data and attributes in DOM tree
+ void SAL_CALL updateUserDefinedAndAttributes();
+ /// create empty DOM tree (XDocument)
+ css::uno::Reference<css::xml::dom::XDocument> SAL_CALL createDOM() const;
+ /// extract base URL (necessary for converting relative links)
+ css::uno::Reference<css::beans::XPropertySet> SAL_CALL getURLProperties(
+ const css::uno::Sequence<css::beans::PropertyValue> & i_rMedium) const;
+ // throw (css::uno::RuntimeException);
+ /// get text of standard meta data element
+ ::rtl::OUString SAL_CALL getMetaText(const char* i_name) const;
+ // throw (css::uno::RuntimeException);
+ /// set text of standard meta data element iff not equal to existing text
+ bool SAL_CALL setMetaText(const char* i_name,
+ const ::rtl::OUString & i_rValue);
+ // throw (css::uno::RuntimeException);
+ /// set text of standard meta data element iff not equal to existing text
+ void SAL_CALL setMetaTextAndNotify(const char* i_name,
+ const ::rtl::OUString & i_rValue);
+ // throw (css::uno::RuntimeException);
+ /// get text of standard meta data element's attribute
+ ::rtl::OUString SAL_CALL getMetaAttr(const char* i_name,
+ const char* i_attr) const;
+ // throw (css::uno::RuntimeException);
+ /// get text of a list of standard meta data elements (multiple occ.)
+ css::uno::Sequence< ::rtl::OUString > SAL_CALL getMetaList(
+ const char* i_name) const;
+ // throw (css::uno::RuntimeException);
+ /// set text of a list of standard meta data elements (multiple occ.)
+ bool SAL_CALL setMetaList(const char* i_name,
+ const css::uno::Sequence< ::rtl::OUString > & i_rValue,
+ AttrVector const* = 0);
+ // throw (css::uno::RuntimeException);
+ void createUserDefined();
+};
+
+////////////////////////////////////////////////////////////////////////////
+
+bool operator== (const css::util::DateTime &i_rLeft,
+ const css::util::DateTime &i_rRight)
+{
+ return i_rLeft.Year == i_rRight.Year
+ && i_rLeft.Month == i_rRight.Month
+ && i_rLeft.Day == i_rRight.Day
+ && i_rLeft.Hours == i_rRight.Hours
+ && i_rLeft.Minutes == i_rRight.Minutes
+ && i_rLeft.Seconds == i_rRight.Seconds
+ && i_rLeft.HundredthSeconds == i_rRight.HundredthSeconds;
+}
+
+// NB: keep these two arrays in sync!
+const char* s_stdStatAttrs[] = {
+ "meta:page-count",
+ "meta:table-count",
+ "meta:draw-count",
+ "meta:image-count",
+ "meta:object-count",
+ "meta:ole-object-count",
+ "meta:paragraph-count",
+ "meta:word-count",
+ "meta:character-count",
+ "meta:row-count",
+ "meta:frame-count",
+ "meta:sentence-count",
+ "meta:syllable-count",
+ "meta:non-whitespace-character-count",
+ "meta:cell-count",
+ 0
+};
+
+// NB: keep these two arrays in sync!
+const char* s_stdStats[] = {
+ "PageCount",
+ "TableCount",
+ "DrawCount",
+ "ImageCount",
+ "ObjectCount",
+ "OLEObjectCount",
+ "ParagraphCount",
+ "WordCount",
+ "CharacterCount",
+ "RowCount",
+ "FrameCount",
+ "SentenceCount",
+ "SyllableCount",
+ "NonWhitespaceCharacterCount",
+ "CellCount",
+ 0
+};
+
+const char* s_stdMeta[] = {
+ "meta:generator", // string
+ "dc:title", // string
+ "dc:description", // string
+ "dc:subject", // string
+ "meta:initial-creator", // string
+ "dc:creator", // string
+ "meta:printed-by", // string
+ "meta:creation-date", // dateTime
+ "dc:date", // dateTime
+ "meta:print-date", // dateTime
+ "meta:template", // XLink
+ "meta:auto-reload", // ...
+ "meta:hyperlink-behaviour", // ...
+ "dc:language", // language
+ "meta:editing-cycles", // nonNegativeInteger
+ "meta:editing-duration", // duration
+ "meta:document-statistic", // ... // note: statistic is singular, no s!
+ 0
+};
+
+const char* s_stdMetaList[] = {
+ "meta:keyword", // string*
+ "meta:user-defined", // ...*
+ 0
+};
+
+const char* s_nsXLink = "http://www.w3.org/1999/xlink";
+const char* s_nsDC = "http://purl.org/dc/elements/1.1/";
+const char* s_nsODF = "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
+const char* s_nsODFMeta = "urn:oasis:names:tc:opendocument:xmlns:meta:1.0";
+// const char* s_nsOOo = "http://openoffice.org/2004/office"; // not used (yet?)
+
+const char* s_metaXml = "meta.xml";
+
+
+bool isValidDate(const css::util::Date & i_rDate)
+{
+ return i_rDate.Month > 0;
+}
+
+bool isValidDateTime(const css::util::DateTime & i_rDateTime)
+{
+ return i_rDateTime.Month > 0;
+}
+
+std::pair< ::rtl::OUString, ::rtl::OUString > SAL_CALL
+getQualifier(const char* i_name) {
+ ::rtl::OUString nm = ::rtl::OUString::createFromAscii(i_name);
+ sal_Int32 ix = nm.indexOf(static_cast<sal_Unicode> (':'));
+ if (ix == -1) {
+ return std::make_pair(::rtl::OUString(), nm);
+ } else {
+ return std::make_pair(nm.copy(0,ix), nm.copy(ix+1));
+ }
+}
+
+// get namespace for standard qualified names
+// NB: only call this with statically known strings!
+::rtl::OUString SAL_CALL getNameSpace(const char* i_qname) throw ()
+{
+ DBG_ASSERT(i_qname, "SfxDocumentMetaData: getNameSpace: argument is null");
+ const char * ns = "";
+ ::rtl::OUString n = getQualifier(i_qname).first;
+ if (n.equalsAscii("xlink" )) ns = s_nsXLink;
+ if (n.equalsAscii("dc" )) ns = s_nsDC;
+ if (n.equalsAscii("office")) ns = s_nsODF;
+ if (n.equalsAscii("meta" )) ns = s_nsODFMeta;
+ DBG_ASSERT(*ns, "SfxDocumentMetaData: unknown namespace prefix");
+ return ::rtl::OUString::createFromAscii(ns);
+}
+
+bool SAL_CALL
+textToDateOrDateTime(css::util::Date & io_rd, css::util::DateTime & io_rdt,
+ bool & o_rIsDateTime, ::rtl::OUString i_text) throw ()
+{
+ if (::sax::Converter::convertDateOrDateTime(
+ io_rd, io_rdt, o_rIsDateTime, i_text)) {
+ return true;
+ } else {
+ DBG_WARNING1("SfxDocumentMetaData: invalid date: %s",
+ OUStringToOString(i_text, RTL_TEXTENCODING_UTF8).getStr());
+ return false;
+ }
+}
+
+// convert string to date/time
+bool SAL_CALL
+textToDateTime(css::util::DateTime & io_rdt, ::rtl::OUString i_text) throw ()
+{
+ if (::sax::Converter::convertDateTime(io_rdt, i_text)) {
+ return true;
+ } else {
+ DBG_WARNING1("SfxDocumentMetaData: invalid date: %s",
+ OUStringToOString(i_text, RTL_TEXTENCODING_UTF8).getStr());
+ return false;
+ }
+}
+
+// convert string to date/time with default return value
+css::util::DateTime SAL_CALL
+textToDateTimeDefault(::rtl::OUString i_text) throw ()
+{
+ css::util::DateTime dt;
+ static_cast<void> (textToDateTime(dt, i_text));
+ // on conversion error: return default value (unchanged)
+ return dt;
+}
+
+// convert date to string
+::rtl::OUString SAL_CALL
+dateToText(css::util::Date const& i_rd) throw ()
+{
+ if (isValidDate(i_rd)) {
+ ::rtl::OUStringBuffer buf;
+ ::sax::Converter::convertDate(buf, i_rd);
+ return buf.makeStringAndClear();
+ } else {
+ return ::rtl::OUString();
+ }
+}
+
+
+// convert date/time to string
+::rtl::OUString SAL_CALL
+dateTimeToText(css::util::DateTime const& i_rdt) throw ()
+{
+ if (isValidDateTime(i_rdt)) {
+ ::rtl::OUStringBuffer buf;
+ ::sax::Converter::convertDateTime(buf, i_rdt, true);
+ return buf.makeStringAndClear();
+ } else {
+ return ::rtl::OUString();
+ }
+}
+
+// convert string to duration
+bool
+textToDuration(css::util::Duration& io_rDur, ::rtl::OUString const& i_rText)
+throw ()
+{
+ if (::sax::Converter::convertDuration(io_rDur, i_rText)) {
+ return true;
+ } else {
+ DBG_WARNING1("SfxDocumentMetaData: invalid duration: %s",
+ OUStringToOString(i_rText, RTL_TEXTENCODING_UTF8).getStr());
+ return false;
+ }
+}
+
+sal_Int32 textToDuration(::rtl::OUString const& i_rText) throw ()
+{
+ css::util::Duration d;
+ if (textToDuration(d, i_rText)) {
+ // #i107372#: approximate years/months
+ const sal_Int32 days( (d.Years * 365) + (d.Months * 30) + d.Days );
+ return (days * (24*3600))
+ + (d.Hours * 3600) + (d.Minutes * 60) + d.Seconds;
+ } else {
+ return 0; // default
+ }
+}
+
+// convert duration to string
+::rtl::OUString durationToText(css::util::Duration const& i_rDur) throw ()
+{
+ ::rtl::OUStringBuffer buf;
+ ::sax::Converter::convertDuration(buf, i_rDur);
+ return buf.makeStringAndClear();
+}
+
+// convert duration to string
+::rtl::OUString SAL_CALL durationToText(sal_Int32 i_value) throw ()
+{
+ css::util::Duration ud;
+ ud.Days = static_cast<sal_Int16>(i_value / (24 * 3600));
+ ud.Hours = static_cast<sal_Int16>((i_value % (24 * 3600)) / 3600);
+ ud.Minutes = static_cast<sal_Int16>((i_value % 3600) / 60);
+ ud.Seconds = static_cast<sal_Int16>(i_value % 60);
+ ud.MilliSeconds = 0;
+ return durationToText(ud);
+}
+
+// extract base URL (necessary for converting relative links)
+css::uno::Reference< css::beans::XPropertySet > SAL_CALL
+SfxDocumentMetaData::getURLProperties(
+ const css::uno::Sequence< css::beans::PropertyValue > & i_rMedium) const
+{
+ css::uno::Reference<css::lang::XMultiComponentFactory> xMsf (
+ m_xContext->getServiceManager());
+ css::uno::Reference< css::beans::XPropertyContainer> xPropArg(
+ xMsf->createInstanceWithContext(::rtl::OUString::createFromAscii(
+ "com.sun.star.beans.PropertyBag"), m_xContext),
+ css::uno::UNO_QUERY_THROW);
+ try {
+ ::rtl::OUString dburl =
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentBaseURL"));
+ ::rtl::OUString hdn =
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HierarchicalDocumentName"));
+ for (sal_Int32 i = 0; i < i_rMedium.getLength(); ++i) {
+ if (i_rMedium[i].Name.equals(dburl)) {
+ xPropArg->addProperty(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")),
+ css::beans::PropertyAttribute::MAYBEVOID,
+ i_rMedium[i].Value);
+ } else if (i_rMedium[i].Name.equals(hdn)) {
+ xPropArg->addProperty(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamRelPath")),
+ css::beans::PropertyAttribute::MAYBEVOID,
+ i_rMedium[i].Value);
+ }
+ }
+ xPropArg->addProperty(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")),
+ css::beans::PropertyAttribute::MAYBEVOID,
+ css::uno::makeAny(::rtl::OUString::createFromAscii(s_metaXml)));
+ } catch (css::uno::Exception &) {
+ // ignore
+ }
+ return css::uno::Reference< css::beans::XPropertySet>(xPropArg,
+ css::uno::UNO_QUERY_THROW);
+}
+
+// return the text of the (hopefully unique, i.e., normalize first!) text
+// node _below_ the given node
+::rtl::OUString SAL_CALL
+getNodeText(css::uno::Reference<css::xml::dom::XNode> i_xNode)
+ throw (css::uno::RuntimeException)
+{
+ if (!i_xNode.is()) throw css::uno::RuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::getNodeText: argument is null"), i_xNode);
+ for (css::uno::Reference<css::xml::dom::XNode> c = i_xNode->getFirstChild();
+ c.is();
+ c = c->getNextSibling()) {
+ if (c->getNodeType() == css::xml::dom::NodeType_TEXT_NODE) {
+ try {
+ return c->getNodeValue();
+ } catch (css::xml::dom::DOMException &) { // too big?
+ return ::rtl::OUString();
+ }
+ }
+ }
+ return ::rtl::OUString();
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getMetaText(const char* i_name) const
+// throw (css::uno::RuntimeException)
+{
+ checkInit();
+
+ const ::rtl::OUString name( ::rtl::OUString::createFromAscii(i_name) );
+ DBG_ASSERT(m_meta.find(name) != m_meta.end(),
+ "SfxDocumentMetaData::getMetaText: not found");
+ css::uno::Reference<css::xml::dom::XNode> xNode = m_meta.find(name)->second;
+ return (xNode.is()) ? getNodeText(xNode) : ::rtl::OUString();
+}
+
+bool SAL_CALL
+SfxDocumentMetaData::setMetaText(const char* i_name,
+ const ::rtl::OUString & i_rValue)
+ // throw (css::uno::RuntimeException)
+{
+ checkInit();
+
+ const ::rtl::OUString name( ::rtl::OUString::createFromAscii(i_name) );
+ DBG_ASSERT(m_meta.find(name) != m_meta.end(),
+ "SfxDocumentMetaData::setMetaText: not found");
+ css::uno::Reference<css::xml::dom::XNode> xNode = m_meta.find(name)->second;
+
+ try {
+ if (i_rValue.equalsAscii("")) {
+ if (xNode.is()) { // delete
+ m_xParent->removeChild(xNode);
+ xNode.clear();
+ m_meta[name] = xNode;
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ if (xNode.is()) { // update
+ for (css::uno::Reference<css::xml::dom::XNode> c =
+ xNode->getFirstChild();
+ c.is();
+ c = c->getNextSibling()) {
+ if (c->getNodeType() == css::xml::dom::NodeType_TEXT_NODE) {
+ if (!c->getNodeValue().equals(i_rValue)) {
+ c->setNodeValue(i_rValue);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+ } else { // insert
+ xNode.set(m_xDoc->createElementNS(getNameSpace(i_name), name),
+ css::uno::UNO_QUERY_THROW);
+ m_xParent->appendChild(xNode);
+ m_meta[name] = xNode;
+ }
+ css::uno::Reference<css::xml::dom::XNode> xTextNode(
+ m_xDoc->createTextNode(i_rValue), css::uno::UNO_QUERY_THROW);
+ xNode->appendChild(xTextNode);
+ return true;
+ }
+ } catch (css::xml::dom::DOMException & e) {
+ css::uno::Any a(e);
+ throw css::lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::setMetaText: DOM exception"),
+ css::uno::Reference<css::uno::XInterface>(*this), a);
+ }
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setMetaTextAndNotify(const char* i_name,
+ const ::rtl::OUString & i_rValue)
+ // throw (css::uno::RuntimeException)
+{
+ ::osl::ClearableMutexGuard g(m_aMutex);
+ if (setMetaText(i_name, i_rValue)) {
+ g.clear();
+ setModified(true);
+ }
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getMetaAttr(const char* i_name, const char* i_attr) const
+// throw (css::uno::RuntimeException)
+{
+// checkInit();
+ ::rtl::OUString name = ::rtl::OUString::createFromAscii(i_name);
+ DBG_ASSERT(m_meta.find(name) != m_meta.end(),
+ "SfxDocumentMetaData::getMetaAttr: not found");
+ css::uno::Reference<css::xml::dom::XNode> xNode = m_meta.find(name)->second;
+ if (xNode.is()) {
+ css::uno::Reference<css::xml::dom::XElement> xElem(xNode,
+ css::uno::UNO_QUERY_THROW);
+ return xElem->getAttributeNS(getNameSpace(i_attr),
+ getQualifier(i_attr).second);
+ } else {
+ return ::rtl::OUString();
+ }
+}
+
+css::uno::Sequence< ::rtl::OUString> SAL_CALL
+SfxDocumentMetaData::getMetaList(const char* i_name) const
+// throw (css::uno::RuntimeException)
+{
+ checkInit();
+ ::rtl::OUString name = ::rtl::OUString::createFromAscii(i_name);
+ DBG_ASSERT(m_metaList.find(name) != m_metaList.end(),
+ "SfxDocumentMetaData::getMetaList: not found");
+ std::vector<css::uno::Reference<css::xml::dom::XNode> > const & vec =
+ m_metaList.find(name)->second;
+ css::uno::Sequence< ::rtl::OUString> ret(vec.size());
+ for (size_t i = 0; i < vec.size(); ++i) {
+ ret[i] = getNodeText(vec.at(i));
+ }
+ return ret;
+}
+
+bool SAL_CALL
+SfxDocumentMetaData::setMetaList(const char* i_name,
+ const css::uno::Sequence< ::rtl::OUString> & i_rValue,
+ AttrVector const* i_pAttrs)
+ // throw (css::uno::RuntimeException)
+{
+ checkInit();
+ DBG_ASSERT((i_pAttrs == 0) ||
+ (static_cast<size_t>(i_rValue.getLength()) == i_pAttrs->size()),
+ "SfxDocumentMetaData::setMetaList: invalid args");
+
+ try {
+ ::rtl::OUString name = ::rtl::OUString::createFromAscii(i_name);
+ DBG_ASSERT(m_metaList.find(name) != m_metaList.end(),
+ "SfxDocumentMetaData::setMetaList: not found");
+ std::vector<css::uno::Reference<css::xml::dom::XNode> > & vec =
+ m_metaList[name];
+
+ // if nothing changed, do nothing
+ // alas, this does not check for permutations, or attributes...
+ if ((0 == i_pAttrs)) {
+ if (static_cast<size_t>(i_rValue.getLength()) == vec.size()) {
+ bool isEqual(true);
+ for (sal_Int32 i = 0; i < i_rValue.getLength(); ++i) {
+ css::uno::Reference<css::xml::dom::XNode> xNode(vec.at(i));
+ if (xNode.is()) {
+ ::rtl::OUString val = getNodeText(xNode);
+ if (!val.equals(i_rValue[i])) {
+ isEqual = false;
+ break;
+ }
+ }
+ }
+ if (isEqual) return false;
+ }
+ }
+
+ // remove old meta data nodes
+ {
+ std::vector<css::uno::Reference<css::xml::dom::XNode> >
+ ::reverse_iterator it(vec.rbegin());
+ try {
+ for ( ;it != vec.rend(); ++it)
+ {
+ m_xParent->removeChild(*it);
+ }
+ }
+ catch (...)
+ {
+ // Clean up already removed nodes
+ vec.erase(it.base(), vec.end());
+ throw;
+ }
+ vec.clear();
+ }
+
+ // insert new meta data nodes into DOM tree
+ for (sal_Int32 i = 0; i < i_rValue.getLength(); ++i) {
+ css::uno::Reference<css::xml::dom::XElement> xElem(
+ m_xDoc->createElementNS(getNameSpace(i_name), name),
+ css::uno::UNO_QUERY_THROW);
+ css::uno::Reference<css::xml::dom::XNode> xNode(xElem,
+ css::uno::UNO_QUERY_THROW);
+ css::uno::Reference<css::xml::dom::XNode> xTextNode(
+ m_xDoc->createTextNode(i_rValue[i]), css::uno::UNO_QUERY_THROW);
+ // set attributes
+ if (i_pAttrs != 0) {
+ for (std::vector<std::pair<const char*, ::rtl::OUString> >
+ ::const_iterator it = (*i_pAttrs)[i].begin();
+ it != (*i_pAttrs)[i].end(); ++it) {
+ xElem->setAttributeNS(getNameSpace(it->first),
+ ::rtl::OUString::createFromAscii(it->first),
+ it->second);
+ }
+ }
+ xNode->appendChild(xTextNode);
+ m_xParent->appendChild(xNode);
+ vec.push_back(xNode);
+ }
+
+ return true;
+ } catch (css::xml::dom::DOMException & e) {
+ css::uno::Any a(e);
+ throw css::lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::setMetaList: DOM exception"),
+ css::uno::Reference<css::uno::XInterface>(*this), a);
+ }
+}
+
+// convert property list to string list and attribute list
+std::pair<css::uno::Sequence< ::rtl::OUString>, AttrVector> SAL_CALL
+propsToStrings(css::uno::Reference<css::beans::XPropertySet> const & i_xPropSet)
+{
+ ::comphelper::SequenceAsVector< ::rtl::OUString > values;
+ AttrVector attrs;
+
+ css::uno::Reference<css::beans::XPropertySetInfo> xSetInfo
+ = i_xPropSet->getPropertySetInfo();
+ css::uno::Sequence<css::beans::Property> props = xSetInfo->getProperties();
+
+ for (sal_Int32 i = 0; i < props.getLength(); ++i) {
+ if (props[i].Attributes & css::beans::PropertyAttribute::TRANSIENT) {
+ continue;
+ }
+ const ::rtl::OUString name = props[i].Name;
+ css::uno::Any any;
+ try {
+ any = i_xPropSet->getPropertyValue(name);
+ } catch (css::uno::Exception &) {
+ // ignore
+ }
+ const css::uno::Type & type = any.getValueType();
+ std::vector<std::pair<const char*, ::rtl::OUString> > as;
+ as.push_back(std::make_pair(static_cast<const char*>("meta:name"),
+ name));
+ const char* vt = "meta:value-type";
+
+ // convert according to type
+ if (type == ::cppu::UnoType<bool>::get()) {
+ bool b = false;
+ any >>= b;
+ ::rtl::OUStringBuffer buf;
+ ::sax::Converter::convertBool(buf, b);
+ values.push_back(buf.makeStringAndClear());
+ as.push_back(std::make_pair(vt,
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("boolean"))));
+ } else if (type == ::cppu::UnoType< ::rtl::OUString>::get()) {
+ ::rtl::OUString s;
+ any >>= s;
+ values.push_back(s);
+// #i90847# OOo 2.x does stupid things if value-type="string";
+// fortunately string is default anyway, so we can just omit it
+// #i107502#: however, OOo 2.x only reads 4 user-defined without @value-type
+// => best backward compatibility: first 4 without @value-type, rest with
+ if (4 <= i)
+ {
+ as.push_back(std::make_pair(vt,
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("string"))));
+ }
+ } else if (type == ::cppu::UnoType<css::util::DateTime>::get()) {
+ css::util::DateTime dt;
+ any >>= dt;
+ values.push_back(dateTimeToText(dt));
+ as.push_back(std::make_pair(vt,
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("date"))));
+ } else if (type == ::cppu::UnoType<css::util::Date>::get()) {
+ css::util::Date d;
+ any >>= d;
+ values.push_back(dateToText(d));
+ as.push_back(std::make_pair(vt,
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("date"))));
+ } else if (type == ::cppu::UnoType<css::util::Time>::get()) {
+ // #i97029#: replaced by Duration
+ // Time is supported for backward compatibility with OOo 3.x, x<=2
+ css::util::Time ut;
+ any >>= ut;
+ css::util::Duration ud;
+ ud.Hours = ut.Hours;
+ ud.Minutes = ut.Minutes;
+ ud.Seconds = ut.Seconds;
+ ud.MilliSeconds = 10 * ut.HundredthSeconds;
+ values.push_back(durationToText(ud));
+ as.push_back(std::make_pair(vt,
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("time"))));
+ } else if (type == ::cppu::UnoType<css::util::Duration>::get()) {
+ css::util::Duration ud;
+ any >>= ud;
+ values.push_back(durationToText(ud));
+ as.push_back(std::make_pair(vt,
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("time"))));
+ } else if (::cppu::UnoType<double>::get().isAssignableFrom(type)) {
+ // support not just double, but anything that can be converted
+ double d = 0;
+ any >>= d;
+ ::rtl::OUStringBuffer buf;
+ ::sax::Converter::convertDouble(buf, d);
+ values.push_back(buf.makeStringAndClear());
+ as.push_back(std::make_pair(vt,
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("float"))));
+ } else {
+ DBG_WARNING1("SfxDocumentMetaData: unsupported property type: %s",
+ OUStringToOString(any.getValueTypeName(),
+ RTL_TEXTENCODING_UTF8).getStr());
+ continue;
+ }
+ attrs.push_back(as);
+ }
+
+ return std::make_pair(values.getAsConstList(), attrs);
+}
+
+// remove the given element from the DOM, and iff i_pAttrs != 0 insert new one
+void SAL_CALL
+SfxDocumentMetaData::updateElement(const char *i_name,
+ std::vector<std::pair<const char *, ::rtl::OUString> >* i_pAttrs)
+{
+ ::rtl::OUString name = ::rtl::OUString::createFromAscii(i_name);
+ try {
+ // remove old element
+ css::uno::Reference<css::xml::dom::XNode> xNode =
+ m_meta.find(name)->second;
+ if (xNode.is()) {
+ m_xParent->removeChild(xNode);
+ xNode.clear();
+ }
+ // add new element
+ if (0 != i_pAttrs) {
+ css::uno::Reference<css::xml::dom::XElement> xElem(
+ m_xDoc->createElementNS(getNameSpace(i_name), name),
+ css::uno::UNO_QUERY_THROW);
+ xNode.set(xElem, css::uno::UNO_QUERY_THROW);
+ // set attributes
+ for (std::vector<std::pair<const char *, ::rtl::OUString> >
+ ::const_iterator it = i_pAttrs->begin();
+ it != i_pAttrs->end(); ++it) {
+ xElem->setAttributeNS(getNameSpace(it->first),
+ ::rtl::OUString::createFromAscii(it->first), it->second);
+ }
+ m_xParent->appendChild(xNode);
+ }
+ m_meta[name] = xNode;
+ } catch (css::xml::dom::DOMException & e) {
+ css::uno::Any a(e);
+ throw css::lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::updateElement: DOM exception"),
+ css::uno::Reference<css::uno::XInterface>(*this), a);
+ }
+}
+
+// update user-defined meta data in DOM tree
+void SAL_CALL SfxDocumentMetaData::updateUserDefinedAndAttributes()
+{
+ createUserDefined();
+ const css::uno::Reference<css::beans::XPropertySet> xPSet(m_xUserDefined,
+ css::uno::UNO_QUERY_THROW);
+ const std::pair<css::uno::Sequence< ::rtl::OUString>, AttrVector>
+ udStringsAttrs( propsToStrings(xPSet) );
+ (void) setMetaList("meta:user-defined", udStringsAttrs.first,
+ &udStringsAttrs.second);
+
+ // update elements with attributes
+ std::vector<std::pair<const char *, ::rtl::OUString> > attributes;
+ if (!m_TemplateName.equalsAscii("") || !m_TemplateURL.equalsAscii("")
+ || isValidDateTime(m_TemplateDate)) {
+ attributes.push_back(std::make_pair(
+ static_cast<const char*>("xlink:type"),
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("simple"))));
+ attributes.push_back(std::make_pair(
+ static_cast<const char*>("xlink:actuate"),
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("onRequest"))));
+ attributes.push_back(std::make_pair(
+ static_cast<const char*>("xlink:title"), m_TemplateName));
+ attributes.push_back(std::make_pair(
+ static_cast<const char*>("xlink:href" ), m_TemplateURL ));
+ if (isValidDateTime(m_TemplateDate)) {
+ attributes.push_back(std::make_pair(
+ static_cast<const char*>("meta:date" ),
+ dateTimeToText(m_TemplateDate)));
+ }
+ updateElement("meta:template", &attributes);
+ } else {
+ updateElement("meta:template");
+ }
+ attributes.clear();
+
+ if (!m_AutoloadURL.equalsAscii("") || (0 != m_AutoloadSecs)) {
+ attributes.push_back(std::make_pair(
+ static_cast<const char*>("xlink:href" ), m_AutoloadURL ));
+ attributes.push_back(std::make_pair(
+ static_cast<const char*>("meta:delay" ),
+ durationToText(m_AutoloadSecs)));
+ updateElement("meta:auto-reload", &attributes);
+ } else {
+ updateElement("meta:auto-reload");
+ }
+ attributes.clear();
+
+ if (!m_DefaultTarget.equalsAscii("")) {
+ attributes.push_back(std::make_pair(
+ static_cast<const char*>("office:target-frame-name"),
+ m_DefaultTarget));
+ // xlink:show: _blank -> new, any other value -> replace
+ const sal_Char* show = m_DefaultTarget.equalsAscii("_blank")
+ ? "new" : "replace";
+ attributes.push_back(std::make_pair(
+ static_cast<const char*>("xlink:show"),
+ ::rtl::OUString::createFromAscii(show)));
+ updateElement("meta:hyperlink-behaviour", &attributes);
+ } else {
+ updateElement("meta:hyperlink-behaviour");
+ }
+ attributes.clear();
+}
+
+// create empty DOM tree (XDocument)
+css::uno::Reference<css::xml::dom::XDocument> SAL_CALL
+SfxDocumentMetaData::createDOM() const // throw (css::uno::RuntimeException)
+{
+ css::uno::Reference<css::lang::XMultiComponentFactory> xMsf (
+ m_xContext->getServiceManager());
+ css::uno::Reference<css::xml::dom::XDocumentBuilder> xBuilder(
+ xMsf->createInstanceWithContext(::rtl::OUString::createFromAscii(
+ "com.sun.star.xml.dom.DocumentBuilder"), m_xContext),
+ css::uno::UNO_QUERY_THROW );
+ if (!xBuilder.is()) throw css::uno::RuntimeException(
+ ::rtl::OUString::createFromAscii("SfxDocumentMetaData::createDOM: "
+ "cannot create DocumentBuilder service"),
+ *const_cast<SfxDocumentMetaData*>(this));
+ css::uno::Reference<css::xml::dom::XDocument> xDoc =
+ xBuilder->newDocument();
+ if (!xDoc.is()) throw css::uno::RuntimeException(
+ ::rtl::OUString::createFromAscii("SfxDocumentMetaData::createDOM: "
+ "cannot create new document"),
+ *const_cast<SfxDocumentMetaData*>(this));
+ return xDoc;
+}
+
+void SAL_CALL
+SfxDocumentMetaData::checkInit() const // throw (css::uno::RuntimeException)
+{
+ if (!m_isInitialized) {
+ throw css::uno::RuntimeException(::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::checkInit: not initialized"),
+ *const_cast<SfxDocumentMetaData*>(this));
+ }
+ DBG_ASSERT((m_xDoc.is() && m_xParent.is() ),
+ "SfxDocumentMetaData::checkInit: reference is null");
+}
+
+// initialize state from DOM tree
+void SAL_CALL SfxDocumentMetaData::init(
+ css::uno::Reference<css::xml::dom::XDocument> i_xDoc)
+// throw (css::uno::RuntimeException, css::io::WrongFormatException,
+// css::uno::Exception)
+{
+ if (!i_xDoc.is()) throw css::uno::RuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::init: no DOM tree given"), *this);
+
+ css::uno::Reference<css::lang::XMultiComponentFactory> xMsf (
+ m_xContext->getServiceManager());
+ css::uno::Reference<css::xml::xpath::XXPathAPI> xPath(
+ xMsf->createInstanceWithContext(::rtl::OUString::createFromAscii(
+ "com.sun.star.xml.xpath.XPathAPI"), m_xContext),
+ css::uno::UNO_QUERY_THROW );
+ if (!xPath.is()) throw css::uno::RuntimeException(
+ ::rtl::OUString::createFromAscii("SfxDocumentMetaData::init:"
+ " cannot create XPathAPI service"), *this);
+
+ m_isInitialized = false;
+ m_xDoc = i_xDoc;
+ m_xDoc->normalize();
+
+ // select nodes for standard meta data stuff
+ xPath->registerNS(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xlink")),
+ ::rtl::OUString::createFromAscii(s_nsXLink));
+ xPath->registerNS(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("dc")),
+ ::rtl::OUString::createFromAscii(s_nsDC));
+ xPath->registerNS(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("office")),
+ ::rtl::OUString::createFromAscii(s_nsODF));
+ xPath->registerNS(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("meta")),
+ ::rtl::OUString::createFromAscii(s_nsODFMeta));
+ // NB: we do not handle the single-XML-file ODF variant, which would
+ // have the root element office:document.
+ // The root of such documents must be converted in the importer!
+ ::rtl::OUString prefix = ::rtl::OUString::createFromAscii(
+ "/child::office:document-meta/child::office:meta");
+ css::uno::Reference<css::xml::dom::XNode> xDocNode(
+ m_xDoc, css::uno::UNO_QUERY_THROW);
+ m_xParent.clear();
+ try {
+ m_xParent = xPath->selectSingleNode(xDocNode, prefix);
+ } catch (com::sun::star::uno::Exception &) {
+// DBG_WARNING("SfxDocumentMetaData::init: "
+// "caught RuntimeException from libxml!");
+ }
+
+ if (!m_xParent.is()) {
+ // all this create/append stuff may throw DOMException
+ try {
+ css::uno::Reference<css::xml::dom::XElement> xRElem(
+ i_xDoc->createElementNS(
+ ::rtl::OUString::createFromAscii(s_nsODF),
+ ::rtl::OUString::createFromAscii("office:document-meta")));
+ css::uno::Reference<css::xml::dom::XNode> xRNode(xRElem,
+ css::uno::UNO_QUERY_THROW);
+ // NB: the following is a _bad_idea_ with our DOM implementation
+ // do _not_ create attributes with xmlns prefix!
+// xRElem->setAttribute(::rtl::OUString::createFromAscii("xmlns:office"),
+// ::rtl::OUString::createFromAscii(s_nsODF));
+ xRElem->setAttributeNS(::rtl::OUString::createFromAscii(s_nsODF),
+ ::rtl::OUString::createFromAscii("office:version"),
+ ::rtl::OUString::createFromAscii("1.0"));
+ i_xDoc->appendChild(xRNode);
+ css::uno::Reference<css::xml::dom::XNode> xParent (
+ i_xDoc->createElementNS(
+ ::rtl::OUString::createFromAscii(s_nsODF),
+ ::rtl::OUString::createFromAscii("office:meta")),
+ css::uno::UNO_QUERY_THROW);
+ xRNode->appendChild(xParent);
+ m_xParent = xParent;
+ } catch (css::xml::dom::DOMException & e) {
+ css::uno::Any a(e);
+ throw css::lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::init: DOM exception"),
+ css::uno::Reference<css::uno::XInterface>(*this), a);
+ }
+ }
+
+
+ // select nodes for elements of which we only handle one occurrence
+ for (const char **pName = s_stdMeta; *pName != 0; ++pName) {
+ ::rtl::OUString name = ::rtl::OUString::createFromAscii(*pName);
+ // NB: If a document contains more than one occurrence of a
+ // meta-data element, we arbitrarily pick one of them here.
+ // We do not remove the others, i.e., when we write the
+ // document, it will contain the duplicates unchanged.
+ // The ODF spec says that handling multiple occurrences is
+ // application-specific.
+ css::uno::Reference<css::xml::dom::XNode> xNode =
+ xPath->selectSingleNode(m_xParent,
+ ::rtl::OUString::createFromAscii("child::") + name);
+ // Do not create an empty element if it is missing;
+ // for certain elements, such as dateTime, this would be invalid
+ m_meta[name] = xNode;
+ }
+
+ // select nodes for elements of which we handle all occurrences
+ for (const char **pName = s_stdMetaList; *pName != 0; ++pName) {
+ ::rtl::OUString name = ::rtl::OUString::createFromAscii(*pName);
+ css::uno::Reference<css::xml::dom::XNodeList> nodes =
+ xPath->selectNodeList(m_xParent,
+ ::rtl::OUString::createFromAscii("child::") + name);
+ std::vector<css::uno::Reference<css::xml::dom::XNode> > v;
+ for (sal_Int32 i = 0; i < nodes->getLength(); ++i) {
+ v.push_back(nodes->item(i));
+ }
+ m_metaList[name] = v;
+ }
+
+ // initialize members corresponding to attributes from DOM nodes
+ m_TemplateName = getMetaAttr("meta:template", "xlink:title");
+ m_TemplateURL = getMetaAttr("meta:template", "xlink:href");
+ m_TemplateDate =
+ textToDateTimeDefault(getMetaAttr("meta:template", "meta:date"));
+ m_AutoloadURL = getMetaAttr("meta:auto-reload", "xlink:href");
+ m_AutoloadSecs =
+ textToDuration(getMetaAttr("meta:auto-reload", "meta:delay"));
+ m_DefaultTarget =
+ getMetaAttr("meta:hyperlink-behaviour", "office:target-frame-name");
+
+
+ std::vector<css::uno::Reference<css::xml::dom::XNode> > & vec =
+ m_metaList[::rtl::OUString::createFromAscii("meta:user-defined")];
+ m_xUserDefined.clear(); // #i105826#: reset (may be re-initialization)
+ if ( !vec.empty() )
+ {
+ createUserDefined();
+ }
+
+ // user-defined meta data: initialize PropertySet from DOM nodes
+ for (std::vector<css::uno::Reference<css::xml::dom::XNode> >::iterator
+ it = vec.begin(); it != vec.end(); ++it) {
+ css::uno::Reference<css::xml::dom::XElement> xElem(*it,
+ css::uno::UNO_QUERY_THROW);
+ css::uno::Any any;
+ ::rtl::OUString name = xElem->getAttributeNS(
+ ::rtl::OUString::createFromAscii(s_nsODFMeta),
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("name")));
+ ::rtl::OUString type = xElem->getAttributeNS(
+ ::rtl::OUString::createFromAscii(s_nsODFMeta),
+ ::rtl::OUString::createFromAscii("value-type"));
+ ::rtl::OUString text = getNodeText(*it);
+ if (type.equalsAscii("float")) {
+ double d;
+ if (::sax::Converter::convertDouble(d, text)) {
+ any <<= d;
+ } else {
+ DBG_WARNING1("SfxDocumentMetaData: invalid float: %s",
+ OUStringToOString(text, RTL_TEXTENCODING_UTF8).getStr());
+ continue;
+ }
+ } else if (type.equalsAscii("date")) {
+ bool isDateTime;
+ css::util::Date d;
+ css::util::DateTime dt;
+ if (textToDateOrDateTime(d, dt, isDateTime, text)) {
+ if (isDateTime) {
+ any <<= dt;
+ } else {
+ any <<= d;
+ }
+ } else {
+ DBG_WARNING1("SfxDocumentMetaData: invalid date: %s",
+ OUStringToOString(text, RTL_TEXTENCODING_UTF8).getStr());
+ continue;
+ }
+ } else if (type.equalsAscii("time")) {
+ css::util::Duration ud;
+ if (textToDuration(ud, text)) {
+ any <<= ud;
+ } else {
+ DBG_WARNING1("SfxDocumentMetaData: invalid time: %s",
+ OUStringToOString(text, RTL_TEXTENCODING_UTF8).getStr());
+ continue;
+ }
+ } else if (type.equalsAscii("boolean")) {
+ bool b;
+ if (::sax::Converter::convertBool(b, text)) {
+ any <<= b;
+ } else {
+ DBG_WARNING1("SfxDocumentMetaData: invalid boolean: %s",
+ OUStringToOString(text, RTL_TEXTENCODING_UTF8).getStr());
+ continue;
+ }
+ } else if (type.equalsAscii("string") || true) { // default
+ any <<= text;
+ }
+ try {
+ m_xUserDefined->addProperty(name,
+ css::beans::PropertyAttribute::REMOVEABLE, any);
+ } catch (css::beans::PropertyExistException &) {
+ DBG_WARNING1("SfxDocumentMetaData: duplicate: %s",
+ OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr());
+ // ignore; duplicate
+ } catch (css::beans::IllegalTypeException &) {
+ DBG_ERROR1("SfxDocumentMetaData: illegal type: %s",
+ OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr());
+ } catch (css::lang::IllegalArgumentException &) {
+ DBG_ERROR1("SfxDocumentMetaData: illegal arg: %s",
+ OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr());
+ }
+ }
+
+ m_isModified = false;
+ m_isInitialized = true;
+}
+
+
+////////////////////////////////////////////////////////////////////////////
+
+SfxDocumentMetaData::SfxDocumentMetaData(
+ css::uno::Reference< css::uno::XComponentContext > const & context)
+ : BaseMutex()
+ , SfxDocumentMetaData_Base(m_aMutex)
+ , m_xContext(context)
+ , m_NotifyListeners(m_aMutex)
+ , m_isInitialized(false)
+ , m_isModified(false)
+ , m_AutoloadSecs(0)
+{
+ DBG_ASSERT(context.is(), "SfxDocumentMetaData: context is null");
+ DBG_ASSERT(context->getServiceManager().is(),
+ "SfxDocumentMetaData: context has no service manager");
+ init(createDOM());
+}
+
+// com.sun.star.uno.XServiceInfo:
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getImplementationName() throw (css::uno::RuntimeException)
+{
+ return comp_SfxDocumentMetaData::_getImplementationName();
+}
+
+::sal_Bool SAL_CALL
+SfxDocumentMetaData::supportsService(::rtl::OUString const & serviceName)
+ throw (css::uno::RuntimeException)
+{
+ css::uno::Sequence< ::rtl::OUString > serviceNames =
+ comp_SfxDocumentMetaData::_getSupportedServiceNames();
+ for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
+ if (serviceNames[i] == serviceName)
+ return sal_True;
+ }
+ return sal_False;
+}
+
+css::uno::Sequence< ::rtl::OUString > SAL_CALL
+SfxDocumentMetaData::getSupportedServiceNames()
+ throw (css::uno::RuntimeException)
+{
+ return comp_SfxDocumentMetaData::_getSupportedServiceNames();
+}
+
+
+// ::com::sun::star::lang::XComponent:
+void SAL_CALL SfxDocumentMetaData::dispose() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ if (!m_isInitialized) {
+ return;
+ }
+ WeakComponentImplHelperBase::dispose(); // superclass
+ m_NotifyListeners.disposeAndClear(css::lang::EventObject(
+ static_cast< ::cppu::OWeakObject* >(this)));
+ m_isInitialized = false;
+ m_meta.clear();
+ m_metaList.clear();
+ m_xParent.clear();
+ m_xDoc.clear();
+ m_xUserDefined.clear();
+}
+
+
+// ::com::sun::star::document::XDocumentProperties:
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getAuthor() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return getMetaText("meta:initial-creator");
+}
+
+void SAL_CALL SfxDocumentMetaData::setAuthor(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ setMetaTextAndNotify("meta:initial-creator", the_value);
+}
+
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getGenerator() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return getMetaText("meta:generator");
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setGenerator(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ setMetaTextAndNotify("meta:generator", the_value);
+}
+
+css::util::DateTime SAL_CALL
+SfxDocumentMetaData::getCreationDate() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return textToDateTimeDefault(getMetaText("meta:creation-date"));
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setCreationDate(const css::util::DateTime & the_value)
+ throw (css::uno::RuntimeException)
+{
+ setMetaTextAndNotify("meta:creation-date", dateTimeToText(the_value));
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getTitle() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return getMetaText("dc:title");
+}
+
+void SAL_CALL SfxDocumentMetaData::setTitle(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ setMetaTextAndNotify("dc:title", the_value);
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getSubject() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return getMetaText("dc:subject");
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setSubject(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ setMetaTextAndNotify("dc:subject", the_value);
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getDescription() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return getMetaText("dc:description");
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setDescription(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ setMetaTextAndNotify("dc:description", the_value);
+}
+
+css::uno::Sequence< ::rtl::OUString >
+SAL_CALL SfxDocumentMetaData::getKeywords() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return getMetaList("meta:keyword");
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setKeywords(
+ const css::uno::Sequence< ::rtl::OUString > & the_value)
+ throw (css::uno::RuntimeException)
+{
+ ::osl::ClearableMutexGuard g(m_aMutex);
+ if (setMetaList("meta:keyword", the_value)) {
+ g.clear();
+ setModified(true);
+ }
+}
+
+css::lang::Locale SAL_CALL
+ SfxDocumentMetaData::getLanguage() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ css::lang::Locale loc;
+ ::rtl::OUString text = getMetaText("dc:language");
+ sal_Int32 ix = text.indexOf(static_cast<sal_Unicode> ('-'));
+ if (ix == -1) {
+ loc.Language = text;
+ } else {
+ loc.Language = text.copy(0, ix);
+ loc.Country = text.copy(ix+1);
+ }
+ return loc;
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setLanguage(const css::lang::Locale & the_value)
+ throw (css::uno::RuntimeException)
+{
+ ::rtl::OUString text = the_value.Language;
+ if (the_value.Country.getLength() > 0) {
+ text += ::rtl::OUString::createFromAscii("-").concat(the_value.Country);
+ }
+ setMetaTextAndNotify("dc:language", text);
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getModifiedBy() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return getMetaText("dc:creator");
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setModifiedBy(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ setMetaTextAndNotify("dc:creator", the_value);
+}
+
+css::util::DateTime SAL_CALL
+SfxDocumentMetaData::getModificationDate() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return textToDateTimeDefault(getMetaText("dc:date"));
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setModificationDate(const css::util::DateTime & the_value)
+ throw (css::uno::RuntimeException)
+{
+ setMetaTextAndNotify("dc:date", dateTimeToText(the_value));
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getPrintedBy() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return getMetaText("meta:printed-by");
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setPrintedBy(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ setMetaTextAndNotify("meta:printed-by", the_value);
+}
+
+css::util::DateTime SAL_CALL
+SfxDocumentMetaData::getPrintDate() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return textToDateTimeDefault(getMetaText("meta:print-date"));
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setPrintDate(const css::util::DateTime & the_value)
+ throw (css::uno::RuntimeException)
+{
+ setMetaTextAndNotify("meta:print-date", dateTimeToText(the_value));
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getTemplateName() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ return m_TemplateName;
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setTemplateName(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ ::osl::ClearableMutexGuard g(m_aMutex);
+ checkInit();
+ if (m_TemplateName != the_value) {
+ m_TemplateName = the_value;
+ g.clear();
+ setModified(true);
+ }
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getTemplateURL() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ return m_TemplateURL;
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setTemplateURL(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ ::osl::ClearableMutexGuard g(m_aMutex);
+ checkInit();
+ if (m_TemplateURL != the_value) {
+ m_TemplateURL = the_value;
+ g.clear();
+ setModified(true);
+ }
+}
+
+css::util::DateTime SAL_CALL
+SfxDocumentMetaData::getTemplateDate() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ return m_TemplateDate;
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setTemplateDate(const css::util::DateTime & the_value)
+ throw (css::uno::RuntimeException)
+{
+ ::osl::ClearableMutexGuard g(m_aMutex);
+ checkInit();
+ if (!(m_TemplateDate == the_value)) {
+ m_TemplateDate = the_value;
+ g.clear();
+ setModified(true);
+ }
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getAutoloadURL() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ return m_AutoloadURL;
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setAutoloadURL(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ ::osl::ClearableMutexGuard g(m_aMutex);
+ checkInit();
+ if (m_AutoloadURL != the_value) {
+ m_AutoloadURL = the_value;
+ g.clear();
+ setModified(true);
+ }
+}
+
+::sal_Int32 SAL_CALL
+SfxDocumentMetaData::getAutoloadSecs() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ return m_AutoloadSecs;
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setAutoloadSecs(::sal_Int32 the_value)
+ throw (css::uno::RuntimeException, css::lang::IllegalArgumentException)
+{
+ if (the_value < 0) throw css::lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::setAutoloadSecs: argument is negative"),
+ *this, 0);
+ ::osl::ClearableMutexGuard g(m_aMutex);
+ checkInit();
+ if (m_AutoloadSecs != the_value) {
+ m_AutoloadSecs = the_value;
+ g.clear();
+ setModified(true);
+ }
+}
+
+::rtl::OUString SAL_CALL
+SfxDocumentMetaData::getDefaultTarget() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ return m_DefaultTarget;
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setDefaultTarget(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ ::osl::ClearableMutexGuard g(m_aMutex);
+ checkInit();
+ if (m_DefaultTarget != the_value) {
+ m_DefaultTarget = the_value;
+ g.clear();
+ setModified(true);
+ }
+}
+
+css::uno::Sequence< css::beans::NamedValue > SAL_CALL
+SfxDocumentMetaData::getDocumentStatistics() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ ::comphelper::SequenceAsVector<css::beans::NamedValue> stats;
+ for (size_t i = 0; s_stdStats[i] != 0; ++i) {
+ const char * aName = s_stdStatAttrs[i];
+ ::rtl::OUString text = getMetaAttr("meta:document-statistic", aName);
+ if (text.equalsAscii("")) continue;
+ css::beans::NamedValue stat;
+ stat.Name = ::rtl::OUString::createFromAscii(s_stdStats[i]);
+ sal_Int32 val;
+ css::uno::Any any;
+ if (!::sax::Converter::convertNumber(val, text, 0,
+ std::numeric_limits<sal_Int32>::max()) || (val < 0)) {
+ val = 0;
+ DBG_WARNING1("SfxDocumentMetaData: invalid number: %s",
+ OUStringToOString(text, RTL_TEXTENCODING_UTF8).getStr());
+ }
+ any <<= val;
+ stat.Value = any;
+ stats.push_back(stat);
+ }
+
+ return stats.getAsConstList();
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setDocumentStatistics(
+ const css::uno::Sequence< css::beans::NamedValue > & the_value)
+ throw (css::uno::RuntimeException)
+{
+ ::osl::ClearableMutexGuard g(m_aMutex);
+ checkInit();
+ std::vector<std::pair<const char *, ::rtl::OUString> > attributes;
+ for (sal_Int32 i = 0; i < the_value.getLength(); ++i) {
+ const ::rtl::OUString name = the_value[i].Name;
+ // inefficently search for matching attribute
+ for (size_t j = 0; s_stdStats[j] != 0; ++j) {
+ if (name.equalsAscii(s_stdStats[j])) {
+ const css::uno::Any any = the_value[i].Value;
+ sal_Int32 val = 0;
+ if (any >>= val) {
+ ::rtl::OUStringBuffer buf;
+ ::sax::Converter::convertNumber(buf, val);
+ attributes.push_back(std::make_pair(s_stdStatAttrs[j],
+ buf.makeStringAndClear()));
+ } else {
+ DBG_WARNING1("SfxDocumentMetaData: invalid statistic: %s",
+ OUStringToOString(name, RTL_TEXTENCODING_UTF8)
+ .getStr());
+ }
+ break;
+ }
+ }
+ }
+ updateElement("meta:document-statistic", &attributes);
+ g.clear();
+ setModified(true);
+}
+
+::sal_Int16 SAL_CALL
+SfxDocumentMetaData::getEditingCycles() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ ::rtl::OUString text = getMetaText("meta:editing-cycles");
+ sal_Int32 ret;
+ if (::sax::Converter::convertNumber(ret, text,
+ 0, std::numeric_limits<sal_Int16>::max())) {
+ return static_cast<sal_Int16>(ret);
+ } else {
+ return 0;
+ }
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setEditingCycles(::sal_Int16 the_value)
+ throw (css::uno::RuntimeException, css::lang::IllegalArgumentException)
+{
+ if (the_value < 0) throw css::lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::setEditingCycles: argument is negative"),
+ *this, 0);
+ ::rtl::OUStringBuffer buf;
+ ::sax::Converter::convertNumber(buf, the_value);
+ setMetaTextAndNotify("meta:editing-cycles", buf.makeStringAndClear());
+}
+
+::sal_Int32 SAL_CALL
+SfxDocumentMetaData::getEditingDuration() throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ return textToDuration(getMetaText("meta:editing-duration"));
+}
+
+void SAL_CALL
+SfxDocumentMetaData::setEditingDuration(::sal_Int32 the_value)
+ throw (css::uno::RuntimeException, css::lang::IllegalArgumentException)
+{
+ if (the_value < 0) throw css::lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::setEditingDuration: argument is negative"),
+ *this, 0);
+ setMetaTextAndNotify("meta:editing-duration", durationToText(the_value));
+}
+
+void SAL_CALL
+SfxDocumentMetaData::resetUserData(const ::rtl::OUString & the_value)
+ throw (css::uno::RuntimeException)
+{
+ ::osl::ClearableMutexGuard g(m_aMutex);
+
+ bool bModified( false );
+ bModified |= setMetaText("meta:initial-creator", the_value);
+ ::DateTime now = DateTime();
+ css::util::DateTime uDT(now.Get100Sec(), now.GetSec(), now.GetMin(),
+ now.GetHour(), now.GetDay(), now.GetMonth(), now.GetYear());
+ bModified |= setMetaText("meta:creation-date", dateTimeToText(uDT));
+ bModified |= setMetaText("dc:creator", ::rtl::OUString());
+ bModified |= setMetaText("meta:printed-by", ::rtl::OUString());
+ bModified |= setMetaText("dc:date", dateTimeToText(css::util::DateTime()));
+ bModified |= setMetaText("meta:print-date",
+ dateTimeToText(css::util::DateTime()));
+ bModified |= setMetaText("meta:editing-duration", durationToText(0));
+ bModified |= setMetaText("meta:editing-cycles",
+ ::rtl::OUString::createFromAscii("1"));
+
+ if (bModified) {
+ g.clear();
+ setModified(true);
+ }
+}
+
+
+css::uno::Reference< css::beans::XPropertyContainer > SAL_CALL
+SfxDocumentMetaData::getUserDefinedProperties()
+ throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ createUserDefined();
+ return m_xUserDefined;
+}
+
+
+void SAL_CALL
+SfxDocumentMetaData::loadFromStorage(
+ const css::uno::Reference< css::embed::XStorage > & xStorage,
+ const css::uno::Sequence< css::beans::PropertyValue > & Medium)
+ throw (css::uno::RuntimeException, css::lang::IllegalArgumentException,
+ css::io::WrongFormatException,
+ css::lang::WrappedTargetException, css::io::IOException)
+{
+ if (!xStorage.is()) throw css::lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii("SfxDocumentMetaData::loadFromStorage:"
+ " argument is null"), *this, 0);
+ ::osl::MutexGuard g(m_aMutex);
+
+ // open meta data file
+ css::uno::Reference<css::io::XStream> xStream(
+ xStorage->openStreamElement(
+ ::rtl::OUString::createFromAscii(s_metaXml),
+ css::embed::ElementModes::READ) );
+ if (!xStream.is()) throw css::uno::RuntimeException();
+ css::uno::Reference<css::io::XInputStream> xInStream =
+ xStream->getInputStream();
+ if (!xInStream.is()) throw css::uno::RuntimeException();
+
+ // create DOM parser service
+ css::uno::Reference<css::lang::XMultiComponentFactory> xMsf (
+ m_xContext->getServiceManager());
+ css::uno::Reference<css::xml::sax::XParser> xParser (
+ xMsf->createInstanceWithContext(::rtl::OUString::createFromAscii(
+ "com.sun.star.xml.sax.Parser"), m_xContext),
+ css::uno::UNO_QUERY_THROW);
+ if (!xParser.is()) throw css::uno::RuntimeException(
+ ::rtl::OUString::createFromAscii("SfxDocumentMetaData::loadFromStorage:"
+ " cannot create Parser service"), *this);
+ css::xml::sax::InputSource input;
+ input.aInputStream = xInStream;
+
+ sal_uInt64 version = SotStorage::GetVersion( xStorage );
+ // Oasis is also the default (0)
+ sal_Bool bOasis = ( version > SOFFICE_FILEFORMAT_60 || version == 0 );
+ const sal_Char *pServiceName = bOasis
+ ? "com.sun.star.document.XMLOasisMetaImporter"
+ : "com.sun.star.document.XMLMetaImporter";
+
+ // set base URL
+ css::uno::Reference<css::beans::XPropertySet> xPropArg =
+ getURLProperties(Medium);
+ try {
+ xPropArg->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")))
+ >>= input.sSystemId;
+ input.sSystemId += ::rtl::OUString::createFromAscii("/").concat(
+ ::rtl::OUString::createFromAscii(s_metaXml));
+ } catch (css::uno::Exception &) {
+ input.sSystemId = ::rtl::OUString::createFromAscii(s_metaXml);
+ }
+ css::uno::Sequence< css::uno::Any > args(1);
+ args[0] <<= xPropArg;
+
+ css::uno::Reference<css::xml::sax::XDocumentHandler> xDocHandler (
+ xMsf->createInstanceWithArgumentsAndContext(
+ ::rtl::OUString::createFromAscii(pServiceName), args, m_xContext),
+ css::uno::UNO_QUERY_THROW);
+ if (!xDocHandler.is()) throw css::uno::RuntimeException(
+ ::rtl::OUString::createFromAscii("SfxDocumentMetaData::loadFromStorage:"
+ " cannot create XMLOasisMetaImporter service"), *this);
+ css::uno::Reference<css::document::XImporter> xImp (xDocHandler,
+ css::uno::UNO_QUERY_THROW);
+ xImp->setTargetDocument(css::uno::Reference<css::lang::XComponent>(this));
+ xParser->setDocumentHandler(xDocHandler);
+ try {
+ xParser->parseStream(input);
+ } catch (css::xml::sax::SAXException &) {
+ throw css::io::WrongFormatException(::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::loadFromStorage:"
+ " XML parsing exception"), *this);
+ }
+ // NB: the implementation of XMLOasisMetaImporter calls initialize
+// init(xDocBuilder->getDocument());
+ checkInit();
+}
+
+void SAL_CALL
+SfxDocumentMetaData::storeToStorage(
+ const css::uno::Reference< css::embed::XStorage > & xStorage,
+ const css::uno::Sequence< css::beans::PropertyValue > & Medium)
+ throw (css::uno::RuntimeException, css::lang::IllegalArgumentException,
+ css::lang::WrappedTargetException, css::io::IOException)
+{
+ if (!xStorage.is()) throw css::lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii("SfxDocumentMetaData::storeToStorage:"
+ " argument is null"), *this, 0);
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+
+ // update user-defined meta data in DOM tree
+// updateUserDefinedAndAttributes(); // this will be done in serialize!
+
+ // write into storage
+ css::uno::Reference<css::io::XStream> xStream =
+ xStorage->openStreamElement(::rtl::OUString::createFromAscii(s_metaXml),
+ css::embed::ElementModes::WRITE
+ | css::embed::ElementModes::TRUNCATE);
+ if (!xStream.is()) throw css::uno::RuntimeException();
+ css::uno::Reference< css::beans::XPropertySet > xStreamProps(xStream,
+ css::uno::UNO_QUERY_THROW);
+ xStreamProps->setPropertyValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType")),
+ css::uno::makeAny(::rtl::OUString::createFromAscii("text/xml")));
+ xStreamProps->setPropertyValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Compressed")),
+ css::uno::makeAny(static_cast<sal_Bool> (sal_False)));
+ xStreamProps->setPropertyValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCommonStoragePasswordEncryption")),
+ css::uno::makeAny(static_cast<sal_Bool> (sal_False)));
+ css::uno::Reference<css::io::XOutputStream> xOutStream =
+ xStream->getOutputStream();
+ if (!xOutStream.is()) throw css::uno::RuntimeException();
+ css::uno::Reference<css::lang::XMultiComponentFactory> xMsf (
+ m_xContext->getServiceManager());
+ css::uno::Reference<css::io::XActiveDataSource> xSaxWriter(
+ xMsf->createInstanceWithContext(::rtl::OUString::createFromAscii(
+ "com.sun.star.xml.sax.Writer"), m_xContext),
+ css::uno::UNO_QUERY_THROW);
+ xSaxWriter->setOutputStream(xOutStream);
+ css::uno::Reference<css::xml::sax::XDocumentHandler> xDocHandler (
+ xSaxWriter, css::uno::UNO_QUERY_THROW);
+
+ const sal_uInt64 version = SotStorage::GetVersion( xStorage );
+ // Oasis is also the default (0)
+ const sal_Bool bOasis = ( version > SOFFICE_FILEFORMAT_60 || version == 0 );
+ const sal_Char *pServiceName = bOasis
+ ? "com.sun.star.document.XMLOasisMetaExporter"
+ : "com.sun.star.document.XMLMetaExporter";
+
+ // set base URL
+ css::uno::Reference<css::beans::XPropertySet> xPropArg =
+ getURLProperties(Medium);
+ css::uno::Sequence< css::uno::Any > args(2);
+ args[0] <<= xDocHandler;
+ args[1] <<= xPropArg;
+
+ css::uno::Reference<css::document::XExporter> xExp(
+ xMsf->createInstanceWithArgumentsAndContext(
+ ::rtl::OUString::createFromAscii(pServiceName), args, m_xContext),
+ css::uno::UNO_QUERY_THROW);
+ xExp->setSourceDocument(css::uno::Reference<css::lang::XComponent>(this));
+ css::uno::Reference<css::document::XFilter> xFilter(xExp,
+ css::uno::UNO_QUERY_THROW);
+ if (xFilter->filter(css::uno::Sequence< css::beans::PropertyValue >())) {
+ css::uno::Reference<css::embed::XTransactedObject> xTransaction(
+ xStorage, css::uno::UNO_QUERY);
+ if (xTransaction.is()) {
+ xTransaction->commit();
+ }
+ } else {
+ throw css::io::IOException(::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::storeToStorage: cannot filter"), *this);
+ }
+}
+
+void SAL_CALL
+SfxDocumentMetaData::loadFromMedium(const ::rtl::OUString & URL,
+ const css::uno::Sequence< css::beans::PropertyValue > & Medium)
+ throw (css::uno::RuntimeException, css::io::WrongFormatException,
+ css::lang::WrappedTargetException, css::io::IOException)
+{
+ css::uno::Reference<css::io::XInputStream> xIn;
+ ::comphelper::MediaDescriptor md(Medium);
+ // if we have an URL parameter, it replaces the one in the media descriptor
+ if (!URL.equalsAscii("")) {
+ md[ ::comphelper::MediaDescriptor::PROP_URL() ] <<= URL;
+ }
+ if (sal_True == md.addInputStream()) {
+ md[ ::comphelper::MediaDescriptor::PROP_INPUTSTREAM() ] >>= xIn;
+ }
+ css::uno::Reference<css::embed::XStorage> xStorage;
+ css::uno::Reference<css::lang::XMultiServiceFactory> xMsf (
+ m_xContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
+ try {
+ if (xIn.is()) {
+ xStorage = ::comphelper::OStorageHelper::GetStorageFromInputStream(
+ xIn, xMsf);
+ } else { // fallback to url parameter
+ xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
+ URL, css::embed::ElementModes::READ, xMsf);
+ }
+ } catch (css::uno::RuntimeException &) {
+ throw;
+ } catch (css::io::IOException &) {
+ throw;
+ } catch (css::uno::Exception & e) {
+ throw css::lang::WrappedTargetException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::loadFromMedium: exception"),
+ css::uno::Reference<css::uno::XInterface>(*this),
+ css::uno::makeAny(e));
+ }
+ if (!xStorage.is()) {
+ throw css::uno::RuntimeException(::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::loadFromMedium: cannot get Storage"),
+ *this);
+ }
+ loadFromStorage(xStorage, md.getAsConstPropertyValueList());
+}
+
+void SAL_CALL
+SfxDocumentMetaData::storeToMedium(const ::rtl::OUString & URL,
+ const css::uno::Sequence< css::beans::PropertyValue > & Medium)
+ throw (css::uno::RuntimeException,
+ css::lang::WrappedTargetException, css::io::IOException)
+{
+ ::comphelper::MediaDescriptor md(Medium);
+ if (!URL.equalsAscii("")) {
+ md[ ::comphelper::MediaDescriptor::PROP_URL() ] <<= URL;
+ }
+ SfxMedium aMedium(md.getAsConstPropertyValueList());
+ css::uno::Reference<css::embed::XStorage> xStorage
+ = aMedium.GetOutputStorage();
+
+
+ if (!xStorage.is()) {
+ throw css::uno::RuntimeException(::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::storeToMedium: cannot get Storage"),
+ *this);
+ }
+ // set MIME type of the storage
+ ::comphelper::MediaDescriptor::const_iterator iter
+ = md.find(::comphelper::MediaDescriptor::PROP_MEDIATYPE());
+ if (iter != md.end()) {
+ css::uno::Reference< css::beans::XPropertySet > xProps(xStorage,
+ css::uno::UNO_QUERY_THROW);
+ xProps->setPropertyValue(
+ ::comphelper::MediaDescriptor::PROP_MEDIATYPE(),
+ iter->second);
+ }
+ storeToStorage(xStorage, md.getAsConstPropertyValueList());
+
+
+ const sal_Bool bOk = aMedium.Commit();
+ aMedium.Close();
+ if ( !bOk ) {
+ sal_uInt32 nError = aMedium.GetError();
+ if ( nError == ERRCODE_NONE ) {
+ nError = ERRCODE_IO_GENERAL;
+ }
+
+ throw css::task::ErrorCodeIOException( ::rtl::OUString(),
+ css::uno::Reference< css::uno::XInterface >(), nError);
+
+ }
+}
+
+// ::com::sun::star::lang::XInitialization:
+void SAL_CALL
+SfxDocumentMetaData::initialize(
+ const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments)
+ throw (css::uno::RuntimeException, css::uno::Exception)
+{
+ // possible arguments:
+ // - no argument: default initialization (empty DOM)
+ // - 1 argument, XDocument: initialize with given DOM and empty base URL
+ // NB: links in document must be absolute
+
+ ::osl::MutexGuard g(m_aMutex);
+ css::uno::Reference<css::xml::dom::XDocument> xDoc;
+
+ for (sal_Int32 i = 0; i < aArguments.getLength(); ++i) {
+ const css::uno::Any any = aArguments[i];
+ if (any >>= xDoc) {
+ if (!xDoc.is()) {
+ throw css::lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii("SfxDocumentMetaData::"
+ "initialize: argument is null"),
+ *this, static_cast<sal_Int16>(i));
+ }
+ } else {
+ throw css::lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii("SfxDocumentMetaData::"
+ "initialize: argument must be XDocument"),
+ *this, static_cast<sal_Int16>(i));
+ }
+ }
+
+ if (!xDoc.is()) {
+ // For a new document, we create a new DOM tree here.
+ xDoc = createDOM();
+ }
+
+ init(xDoc);
+}
+
+// ::com::sun::star::util::XCloneable:
+css::uno::Reference<css::util::XCloneable> SAL_CALL
+SfxDocumentMetaData::createClone()
+ throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+
+ SfxDocumentMetaData *pNew = new SfxDocumentMetaData(m_xContext);
+
+ // NB: do not copy the modification listeners, only DOM
+ css::uno::Reference<css::xml::dom::XDocument> xDoc = createDOM();
+ try {
+ updateUserDefinedAndAttributes();
+ // deep copy of root node
+ css::uno::Reference<css::xml::dom::XNode> xRoot(
+ m_xDoc->getDocumentElement(), css::uno::UNO_QUERY_THROW);
+ css::uno::Reference<css::xml::dom::XNode> xRootNew(
+ xDoc->importNode(xRoot, true));
+ xDoc->appendChild(xRootNew);
+ pNew->init(xDoc);
+ } catch (css::uno::RuntimeException &) {
+ throw;
+ } catch (css::uno::Exception & e) {
+ css::uno::Any a(e);
+ throw css::lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentMetaData::createClone: exception"),
+ css::uno::Reference<css::uno::XInterface>(*this), a);
+ }
+// return static_cast< ::cppu::OWeakObject * > (pNew);
+ return css::uno::Reference<css::util::XCloneable> (pNew);
+}
+
+// ::com::sun::star::util::XModifiable:
+::sal_Bool SAL_CALL SfxDocumentMetaData::isModified( )
+ throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ css::uno::Reference<css::util::XModifiable> xMB(m_xUserDefined,
+ css::uno::UNO_QUERY);
+ return m_isModified || (xMB.is() ? xMB->isModified() : sal_False);
+}
+
+void SAL_CALL SfxDocumentMetaData::setModified( ::sal_Bool bModified )
+ throw (css::beans::PropertyVetoException, css::uno::RuntimeException)
+{
+ css::uno::Reference<css::util::XModifiable> xMB;
+ { // do not lock mutex while notifying (#i93514#) to prevent deadlock
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ m_isModified = bModified;
+ if ( !bModified && m_xUserDefined.is() )
+ {
+ xMB.set(m_xUserDefined, css::uno::UNO_QUERY);
+ DBG_ASSERT(xMB.is(),
+ "SfxDocumentMetaData::setModified: PropertyBag not Modifiable?");
+ }
+ }
+ if (bModified) {
+ try {
+ css::uno::Reference<css::uno::XInterface> xThis(*this);
+ css::lang::EventObject event(xThis);
+ m_NotifyListeners.notifyEach(&css::util::XModifyListener::modified,
+ event);
+ } catch (css::uno::RuntimeException &) {
+ throw;
+ } catch (css::uno::Exception & e) {
+ // ignore
+ DBG_WARNING1("SfxDocumentMetaData::setModified: exception:\n%s",
+ OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
+ (void) e;
+ }
+ } else {
+ if (xMB.is()) {
+ xMB->setModified(false);
+ }
+ }
+}
+
+// ::com::sun::star::util::XModifyBroadcaster:
+void SAL_CALL SfxDocumentMetaData::addModifyListener(
+ const css::uno::Reference< css::util::XModifyListener > & xListener)
+ throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ m_NotifyListeners.addInterface(xListener);
+ css::uno::Reference<css::util::XModifyBroadcaster> xMB(m_xUserDefined,
+ css::uno::UNO_QUERY);
+ if (xMB.is()) {
+ xMB->addModifyListener(xListener);
+ }
+}
+
+void SAL_CALL SfxDocumentMetaData::removeModifyListener(
+ const css::uno::Reference< css::util::XModifyListener > & xListener)
+ throw (css::uno::RuntimeException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ m_NotifyListeners.removeInterface(xListener);
+ css::uno::Reference<css::util::XModifyBroadcaster> xMB(m_xUserDefined,
+ css::uno::UNO_QUERY);
+ if (xMB.is()) {
+ xMB->removeModifyListener(xListener);
+ }
+}
+
+// ::com::sun::star::xml::sax::XSAXSerializable
+void SAL_CALL SfxDocumentMetaData::serialize(
+ const css::uno::Reference<css::xml::sax::XDocumentHandler>& i_xHandler,
+ const css::uno::Sequence< css::beans::StringPair >& i_rNamespaces)
+ throw (css::uno::RuntimeException, css::xml::sax::SAXException)
+{
+ ::osl::MutexGuard g(m_aMutex);
+ checkInit();
+ updateUserDefinedAndAttributes();
+ css::uno::Reference<css::xml::sax::XSAXSerializable> xSAXable(m_xDoc,
+ css::uno::UNO_QUERY_THROW);
+ xSAXable->serialize(i_xHandler, i_rNamespaces);
+}
+
+void SfxDocumentMetaData::createUserDefined()
+{
+ // user-defined meta data: create PropertyBag which only accepts property
+ // values of allowed types
+ if ( !m_xUserDefined.is() )
+ {
+ css::uno::Sequence<css::uno::Type> types(11);
+ types[0] = ::cppu::UnoType<bool>::get();
+ types[1] = ::cppu::UnoType< ::rtl::OUString>::get();
+ types[2] = ::cppu::UnoType<css::util::DateTime>::get();
+ types[3] = ::cppu::UnoType<css::util::Date>::get();
+ types[4] = ::cppu::UnoType<css::util::Duration>::get();
+ types[5] = ::cppu::UnoType<float>::get();
+ types[6] = ::cppu::UnoType<double>::get();
+ types[7] = ::cppu::UnoType<sal_Int16>::get();
+ types[8] = ::cppu::UnoType<sal_Int32>::get();
+ types[9] = ::cppu::UnoType<sal_Int64>::get();
+ // Time is supported for backward compatibility with OOo 3.x, x<=2
+ types[10] = ::cppu::UnoType<css::util::Time>::get();
+ css::uno::Sequence<css::uno::Any> args(2);
+ args[0] <<= css::beans::NamedValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowedTypes")),
+ css::uno::makeAny(types));
+ // #i94175#: ODF allows empty user-defined property names!
+ args[1] <<= css::beans::NamedValue( ::rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("AllowEmptyPropertyName")),
+ css::uno::makeAny(sal_True));
+
+ const css::uno::Reference<css::lang::XMultiComponentFactory> xMsf(
+ m_xContext->getServiceManager());
+ m_xUserDefined.set(
+ xMsf->createInstanceWithContext(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.beans.PropertyBag")), m_xContext),
+ css::uno::UNO_QUERY_THROW);
+ const css::uno::Reference<css::lang::XInitialization> xInit(
+ m_xUserDefined, css::uno::UNO_QUERY);
+ if (xInit.is()) {
+ xInit->initialize(args);
+ }
+
+ const css::uno::Reference<css::util::XModifyBroadcaster> xMB(
+ m_xUserDefined, css::uno::UNO_QUERY);
+ if (xMB.is())
+ {
+ const css::uno::Sequence<css::uno::Reference<css::uno::XInterface> >
+ listeners(m_NotifyListeners.getElements());
+ for (css::uno::Reference< css::uno::XInterface > const * iter =
+ ::comphelper::stl_begin(listeners);
+ iter != ::comphelper::stl_end(listeners); ++iter) {
+ xMB->addModifyListener(
+ css::uno::Reference< css::util::XModifyListener >(*iter,
+ css::uno::UNO_QUERY));
+ }
+ }
+ }
+}
+
+} // closing anonymous implementation namespace
+
+
+// component helper namespace
+namespace comp_SfxDocumentMetaData {
+
+::rtl::OUString SAL_CALL _getImplementationName() {
+ return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "SfxDocumentMetaData"));
+}
+
+css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames()
+{
+ css::uno::Sequence< ::rtl::OUString > s(1);
+ s[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.document.DocumentProperties"));
+ return s;
+}
+
+css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
+ const css::uno::Reference< css::uno::XComponentContext > & context)
+ SAL_THROW((css::uno::Exception))
+{
+ return static_cast< ::cppu::OWeakObject * >
+ (new SfxDocumentMetaData(context));
+}
+
+} // closing component helper namespace
+
+static ::cppu::ImplementationEntry const entries[] = {
+ { &comp_SfxDocumentMetaData::_create,
+ &comp_SfxDocumentMetaData::_getImplementationName,
+ &comp_SfxDocumentMetaData::_getSupportedServiceNames,
+ &::cppu::createSingleComponentFactory, 0, 0 },
+ { 0, 0, 0, 0, 0, 0 }
+};
+
+#if 0
+extern "C" void SAL_CALL component_getImplementationEnvironment(
+ const char ** envTypeName, uno_Environment **)
+{
+ *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+
+extern "C" void * SAL_CALL component_getFactory(
+ const char * implName, void * serviceManager, void * registryKey)
+{
+ return ::cppu::component_getFactoryHelper(
+ implName, serviceManager, registryKey, entries);
+}
+#endif
+
diff --git a/sfx2/source/doc/doc.hrc b/sfx2/source/doc/doc.hrc
new file mode 100644
index 000000000000..7e8fd688af52
--- /dev/null
+++ b/sfx2/source/doc/doc.hrc
@@ -0,0 +1,221 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_DOC_HRC
+#define _SFX_DOC_HRC
+
+#include <sfx2/sfx.hrc>
+
+// #defines *****************************************************************
+
+#define RID_SFX_DOC_END (RID_SFX_DIALOG_START-1)
+
+#define STR_NODEFPRINTER (RID_SFX_DOC_START+ 0)
+#define STR_PRINTER_NOTAVAIL_1 (RID_SFX_DOC_START+ 1)
+#define STR_PRINTER_NOTAVAIL_2 (RID_SFX_DOC_START+ 2)
+#define STR_PRINTER_NOTAVAIL_3 (RID_SFX_DOC_START+ 3)
+#define STR_PRINTER_NOTAVAIL_4 (RID_SFX_DOC_START+ 4)
+#define STR_PRINTER_NOTAVAIL_5 (RID_SFX_DOC_START+ 5)
+#define STR_PRINT_OPTIONS (RID_SFX_DOC_START+ 6)
+#define STR_ERROR_PRINTER_BUSY (RID_SFX_DOC_START+ 7)
+#define STR_NOSTARTPRINTER (RID_SFX_DOC_START+ 8)
+#define MSG_CONFIRM_FILTER (RID_SFX_DOC_START+11)
+#define MSG_CONFIRM_OVERWRITE_TEMPLATE (RID_SFX_DOC_START+12)
+
+#define STR_DELETE_REGION (RID_SFX_DOC_START+14)
+#define STR_DELETE_TEMPLATE (RID_SFX_DOC_START+15)
+#define MSG_REGION_NOTEMPTY (RID_SFX_DOC_START+17)
+
+#define DLG_NEW_FILE (RID_SFX_DOC_START+1)
+#define DLG_DOC_TEMPLATE (RID_SFX_DOC_START+2)
+#define DLG_ORGANIZE (RID_SFX_DOC_START+3)
+
+#define BMP_STYLES_CLOSED (RID_SFX_DOC_START+ 0)
+#define BMP_STYLES_OPENED (RID_SFX_DOC_START+ 1)
+
+#define BMP_STYLES_FAMILY1 (RID_SFX_DOC_START+ 2)
+#define BMP_STYLES_FAMILY2 (RID_SFX_DOC_START+ 3)
+#define BMP_STYLES_FAMILY3 (RID_SFX_DOC_START+ 4)
+#define BMP_STYLES_FAMILY4 (RID_SFX_DOC_START+ 5)
+
+#define BMP_STYLES_CLOSED_HC (RID_SFX_DOC_START+ 6)
+#define BMP_STYLES_OPENED_HC (RID_SFX_DOC_START+ 7)
+
+#define BMP_STYLES_FAMILY1_HC (RID_SFX_DOC_START+ 8)
+#define BMP_STYLES_FAMILY2_HC (RID_SFX_DOC_START+ 9)
+#define BMP_STYLES_FAMILY3_HC (RID_SFX_DOC_START+ 10)
+#define BMP_STYLES_FAMILY4_HC (RID_SFX_DOC_START+ 11)
+
+#define STR_STYLES (RID_SFX_DOC_START+ 18)
+#define STR_MACROS (RID_SFX_DOC_START+ 19)
+
+#define STR_PRINT_STYLES (RID_SFX_DOC_START+ 20)
+#define STR_PRINT_STYLES_HEADER (RID_SFX_DOC_START+ 21)
+#define MSG_PRINT_ERROR (RID_SFX_DOC_START+ 22)
+#define STR_BACKUP_COPY (RID_SFX_DOC_START+ 23)
+// #define MSG_WARNING_BACKUP (RID_SFX_DOC_START+ 24)
+#define MSG_CANT_OPEN_TEMPLATE (RID_SFX_DOC_START+ 25)
+#define MSG_VIEW_OPEN_CANT_SAVE (RID_SFX_DOC_START+ 26)
+#define STR_ERROR_SAVE (RID_SFX_DOC_START+ 27)
+#define STR_TEMPLATE_FILTER (RID_SFX_DOC_START+ 28)
+#define STR_ERROR_COPY_TEMPLATE (RID_SFX_DOC_START+ 29)
+
+#define STR_ERROR_DELETE_TEMPLATE (RID_SFX_DOC_START+ 30)
+#define STR_ERROR_MOVE_TEMPLATE (RID_SFX_DOC_START+ 32)
+#define MSG_ERROR_RESCAN (RID_SFX_DOC_START+ 33)
+#define STR_ERROR_SAVE_TEMPLATE (RID_SFX_DOC_START+ 34)
+#define MSG_ERROR_RENAME_TEMPLATE (RID_SFX_DOC_START+ 34)
+#define MSG_ERROR_RENAME_TEMPLATE_REGION (RID_SFX_DOC_START+ 35)
+#define STR_CONFIG (RID_SFX_DOC_START+ 37)
+#define MSG_ERROR_EMPTY_NAME (RID_SFX_DOC_START+ 37)
+#define MSG_ERROR_UNIQ_NAME (RID_SFX_DOC_START+ 38)
+#define STR_QUERY_DEFAULT_TEMPLATE (RID_SFX_DOC_START+ 39)
+#define MSG_QUERY_RESET_DEFAULT_TEMPLATE (RID_SFX_DOC_START+ 39)
+#define MSG_TEMPLATE_DIR_NOT_EXIST (RID_SFX_DOC_START+ 40)
+#define MSG_DOCINFO_CANTREAD (RID_SFX_DOC_START+ 41)
+#define STR_ERROR_NOSTORAGE (RID_SFX_DOC_START+ 42)
+// #define STR_QUERY_SAVEOWNFORMAT (RID_SFX_DOC_START+ 43)
+#define STR_QUERY_MUSTOWNFORMAT (RID_SFX_DOC_START+ 44)
+#define STR_SAVEDOC (RID_SFX_DOC_START+ 45)
+#define STR_UPDATEDOC (RID_SFX_DOC_START+ 46)
+#define STR_SAVEASDOC (RID_SFX_DOC_START+ 47)
+#define STR_SAVECOPYDOC (RID_SFX_DOC_START+ 48)
+#define STR_CLOSEDOC (RID_SFX_DOC_START+ 49)
+#define STR_CLOSEDOC_ANDRETURN (RID_SFX_DOC_START+ 50)
+#define STR_WIZARD (RID_SFX_DOC_START+ 51)
+#define RID_STR_FILTCONFIG (RID_SFX_DOC_START+ 52)
+#define RID_STR_FILTBASIC (RID_SFX_DOC_START+ 53)
+#define RID_STR_WARNSTYLEOVERWRITE (RID_SFX_DOC_START+ 54)
+#define RID_DLSTATUS (RID_SFX_DOC_START+ 55)
+
+#define STR_DOC_LOADING (RID_SFX_DOC_START+ 57)
+#define MSG_OPEN_READONLY (RID_SFX_DOC_START+ 58)
+
+#define RID_OFFICEFILTER (RID_SFX_DOC_START+ 59)
+#define RID_OFFICEFILTER_WILDCARD (RID_SFX_DOC_START+ 60)
+#define RID_OFFICEFILTER_MACTYPE (RID_SFX_DOC_START+ 61)
+#define RID_OFFICEFILTER_OS2TYPE (RID_SFX_DOC_START+ 62)
+#define STR_FRAMEOBJECT_PROPERTIES (RID_SFX_DOC_START+ 63)
+
+#define STR_FSET_FILTERNAME0 (RID_SFX_DOC_START+ 64)
+#define STR_FSET_FILTERNAME1 (RID_SFX_DOC_START+ 65)
+
+#define STR_TEMPL_MOVED (RID_SFX_DOC_START+ 66)
+#define STR_TEMPL_RESET (RID_SFX_DOC_START+ 67)
+#define STR_AUTOMATICVERSION (RID_SFX_DOC_START+ 68)
+
+#define STR_DOCTYPENAME_SW (RID_SFX_DOC_START+ 69)
+#define STR_DOCTYPENAME_SWWEB (RID_SFX_DOC_START+ 70)
+#define STR_DOCTYPENAME_SWGLOB (RID_SFX_DOC_START+ 71)
+#define STR_DOCTYPENAME_SC (RID_SFX_DOC_START+ 72)
+#define STR_DOCTYPENAME_SI (RID_SFX_DOC_START+ 73)
+#define STR_DOCTYPENAME_SD (RID_SFX_DOC_START+ 74)
+#define STR_DOCTYPENAME_MESSAGE (RID_SFX_DOC_START+ 75)
+#define RID_STR_NEW_TASK (RID_SFX_DOC_START+ 76)
+
+#define STR_SAVEANDCLOSE (RID_SFX_DOC_START+ 77)
+#define STR_NOSAVEANDCLOSE (RID_SFX_DOC_START+ 78)
+#define STR_PACKNGO_NOACCESS (RID_SFX_DOC_START+ 79)
+#define STR_PACKNGO_NEWMEDIUM (RID_SFX_DOC_START+ 80)
+
+#define TEMPLATE_LONG_NAMES_ARY (RID_SFX_DOC_START+ 81)
+#define TEMPLATE_SHORT_NAMES_ARY (RID_SFX_DOC_START+ 82)
+#define RID_CNT_STR_WAITING (RID_SFX_DOC_START+ 83)
+
+#define STR_OBJECT (RID_SFX_DOC_START+ 84)
+#define STR_EDITOBJECT (RID_SFX_DOC_START+ 85)
+// --> PB 2004-08-20 #i33095#
+/* obsolete
+#define STR_OPENOBJECT (RID_SFX_DOC_START+ 86)
+*/
+
+#define DLOAD_URL 1
+#define DLOAD_STATUS 2
+#define DLOAD_NAME 3
+#define DLOAD_TEXT 4
+#define DLOAD_CANCEL 1
+
+#define DLG_MACROQUERY (RID_SFX_DOC_START+87)
+#define BTN_OK (RID_SFX_DOC_START+88)
+#define BTN_CANCEL (RID_SFX_DOC_START+89)
+#define FT_OK (RID_SFX_DOC_START+90)
+#define FT_CANCEL (RID_SFX_DOC_START+91)
+
+#define STR_EXPORTASPDF_TITLE (RID_SFX_DOC_START+92)
+#define STR_EXPORTBUTTON (RID_SFX_DOC_START+93)
+#define STR_EXPORTWITHCFGBUTTON (RID_SFX_DOC_START+94)
+
+#define RID_SVXSTR_SECURITY_ADDPATH (RID_SFX_DOC_START+95)
+
+#define STR_LABEL_FILEFORMAT (RID_SFX_DOC_START+96)
+
+// some icons are commented out since they are removed
+#define BMP_SIGNATURE (RID_SFX_DOC_START+97)
+// #define BMP_128X128_BASE_DOC (RID_SFX_DOC_START+98)
+#define BMP_128X128_CALC_DOC (RID_SFX_DOC_START+99)
+// #define BMP_128X128_CALC_TEMP (RID_SFX_DOC_START+100)
+#define BMP_128X128_CHART_DOC (RID_SFX_DOC_START+101)
+#define BMP_128X128_DRAW_DOC (RID_SFX_DOC_START+102)
+// #define BMP_128X128_DRAW_TEMP (RID_SFX_DOC_START+103)
+#define BMP_128X128_IMPRESS_DOC (RID_SFX_DOC_START+104)
+// #define BMP_128X128_IMPRESS_TEMP (RID_SFX_DOC_START+105)
+// #define BMP_128X128_MASTER_DOC (RID_SFX_DOC_START+106)
+#define BMP_128X128_MATH_DOC (RID_SFX_DOC_START+107)
+#define BMP_128X128_WRITER_DOC (RID_SFX_DOC_START+108)
+// #define BMP_128X128_WRITER_TEMP (RID_SFX_DOC_START+109)
+
+#define STR_HIDDENINFO_CONTAINS (RID_SFX_DOC_START+110)
+#define STR_HIDDENINFO_RECORDCHANGES (RID_SFX_DOC_START+111)
+#define STR_HIDDENINFO_NOTES (RID_SFX_DOC_START+112)
+#define STR_HIDDENINFO_DOCVERSIONS (RID_SFX_DOC_START+113)
+#define STR_HIDDENINFO_FIELDS (RID_SFX_DOC_START+114)
+#define STR_HIDDENINFO_LINKDATA (RID_SFX_DOC_START+115)
+#define STR_HIDDENINFO_CONTINUE_SAVING (RID_SFX_DOC_START+116)
+#define STR_HIDDENINFO_CONTINUE_PRINTING (RID_SFX_DOC_START+117)
+#define STR_HIDDENINFO_CONTINUE_SIGNING (RID_SFX_DOC_START+118)
+#define STR_HIDDENINFO_CONTINUE_CREATEPDF (RID_SFX_DOC_START+119)
+
+// #define MSG_WARNING_MACRO_ISDISABLED (RID_SFX_DOC_START+120)
+#define STR_NEW_FILENAME_SAVE (RID_SFX_DOC_START+121)
+// #define STR_MACROS_DISABLED (RID_SFX_DOC_START+122)
+#define STR_ERROR_DELETE_TEMPLATE_DIR (RID_SFX_DOC_START+123)
+#define STR_DOCINFO_INFOFIELD (RID_SFX_DOC_START+124)
+
+#define MSG_XMLSEC_QUERY_SAVESIGNEDBEFORESIGN (RID_SFX_DOC_START+125)
+#define STR_XMLSEC_ODF12_EXPECTED (RID_SFX_DOC_START+126)
+
+#define STR_QRYTEMPL_MESSAGE (RID_SFX_DOC_START+127)
+#define STR_QRYTEMPL_UPDATE_BTN (RID_SFX_DOC_START+128)
+#define STR_QRYTEMPL_KEEP_BTN (RID_SFX_DOC_START+129)
+
+// please update to the last id
+#define ACT_SFX_DOC_END STR_QRYTEMPL_KEEP_BTN
+#if ACT_SFX_DOC_END > RID_SFX_DOC_END
+#error resource overflow in #line, #file
+#endif
+
+#endif
+
diff --git a/sfx2/source/doc/doc.src b/sfx2/source/doc/doc.src
new file mode 100644
index 000000000000..497d4ccd7c97
--- /dev/null
+++ b/sfx2/source/doc/doc.src
@@ -0,0 +1,528 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#include <sfx2/sfx.hrc>
+#include "doc.hrc"
+#define __RSC
+#include <svl/inetdef.hxx>
+//#include <so3/so2defs.hxx>
+
+ // -----------------------------------------------------------------------
+QueryBox MSG_CONFIRM_FILTER
+{
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_YES ;
+ Message [ en-US ] = "Saving in external formats may have caused\n information loss. Do you still want to close?" ;
+};
+QueryBox MSG_CONFIRM_OVERWRITE_TEMPLATE
+{
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_NO ;
+ Message [ en-US ] = "Name already in use.\nDo you want to overwrite document template?" ;
+};
+String STR_DELETE_REGION
+{
+ Text [ en-US ] = "Are you sure you want to delete the region \"$1\"?" ;
+};
+String STR_DELETE_TEMPLATE
+{
+ Text [ en-US ] = "Are you sure you want to delete the entry \"$1\"?" ;
+};
+QueryBox MSG_REGION_NOTEMPTY
+{
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_NO ;
+ Message [ en-US ] = "The category is not empty.\nDelete anyway?" ;
+};
+String STR_QUERY_SAVE_DOCUMENT
+{
+ Text [ en-US ] = "The document \"$(DOC)\" has been modified.\nDo you want to save your changes?" ;
+};
+Bitmap BMP_STYLES_CLOSED { File = "newex.bmp" ; };
+Bitmap BMP_STYLES_OPENED { File = "newex.bmp" ; };
+
+Bitmap BMP_STYLES_CLOSED_HC { File = "newex_h.bmp" ; };
+Bitmap BMP_STYLES_OPENED_HC { File = "newex_h.bmp" ; };
+
+String STR_STYLES
+{
+ Text [ en-US ] = "Styles" ;
+};
+String STR_MACROS
+{
+ Text [ en-US ] = "Macros" ;
+};
+String STR_CONFIG
+{
+ Text [ en-US ] = "Configuration" ;
+};
+String STR_PRINT_STYLES_HEADER
+{
+ Text [ en-US ] = "Styles in " ;
+};
+String STR_PRINT_STYLES
+{
+ Text [ en-US ] = "Printing Styles" ;
+};
+Bitmap BMP_STYLES_FAMILY1 { File = "styfam1.bmp" ; };
+Bitmap BMP_STYLES_FAMILY2 { File = "styfam2.bmp" ; };
+Bitmap BMP_STYLES_FAMILY3 { File = "styfam3.bmp" ; };
+Bitmap BMP_STYLES_FAMILY4 { File = "styfam4.bmp" ; };
+
+Bitmap BMP_STYLES_FAMILY1_HC { File = "styfam1_h.bmp" ; };
+Bitmap BMP_STYLES_FAMILY2_HC { File = "styfam2_h.bmp" ; };
+Bitmap BMP_STYLES_FAMILY3_HC { File = "styfam3_h.bmp" ; };
+Bitmap BMP_STYLES_FAMILY4_HC { File = "styfam4_h.bmp" ; };
+
+ErrorBox MSG_PRINT_ERROR
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "The print job could not be started." ;
+};
+String STR_BACKUP_COPY
+{
+ Text [ en-US ] = "Copy" ;
+};
+InfoBox MSG_CANT_OPEN_TEMPLATE
+{
+ Message [ en-US ] = "The template could not be opened." ;
+};
+InfoBox MSG_VIEW_OPEN_CANT_SAVE
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Document already open for editing." ;
+};
+String STR_ERROR_SAVE
+{
+ Text [ en-US ] = "Error recording document " ;
+};
+String STR_TEMPLATE_FILTER
+{
+ Text [ en-US ] = "Templates" ;
+};
+String STR_ERROR_COPY_TEMPLATE
+{
+ Text [ en-US ] = "Error copying template \"$1\". \nA template with this name may already exist." ;
+};
+String STR_ERROR_DELETE_TEMPLATE
+{
+ Text [ en-US ] = "The template \"$1\" can not be deleted." ;
+};
+String STR_ERROR_MOVE_TEMPLATE
+{
+ Text [ en-US ] = "Error moving template \"$1\"." ;
+};
+ErrorBox MSG_ERROR_RESCAN
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "The update could not be saved." ;
+};
+String STR_ERROR_SAVE_TEMPLATE
+{
+ Text [ en-US ] = "Error saving template " ;
+};
+ErrorBox MSG_ERROR_RENAME_TEMPLATE
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Error renaming template." ;
+};
+ErrorBox MSG_ERROR_RENAME_TEMPLATE_REGION
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Error renaming template category." ;
+};
+ErrorBox MSG_ERROR_EMPTY_NAME
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Please specify a name." ;
+};
+ErrorBox MSG_ERROR_UNIQ_NAME
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "Please specify a unique name.\nEntries must not be case specific." ;
+};
+String STR_QUERY_DEFAULT_TEMPLATE
+{
+ Text [ en-US ] = "Should the template \"$(TEXT)\" become the default template?" ;
+};
+QueryBox MSG_QUERY_RESET_DEFAULT_TEMPLATE
+{
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_NO ;
+ Message [ en-US ] = "Do you want to reset the default template?" ;
+};
+InfoBox MSG_TEMPLATE_DIR_NOT_EXIST
+{
+ Message [ en-US ] = "Template directory\n$(DIR)\ndoes not exist." ;
+};
+InfoBox MSG_DOCINFO_CANTREAD
+{
+ Message [ en-US ] = "Document info cannot be read." ;
+};
+String STR_ERROR_NOSTORAGE
+{
+ /* ### ACHTUNG: Neuer Text in Resource? Die ausgew�hlte Datei besitzt ein falsches Format. : Die ausgew�hlte Datei besitzt ein falsches Format. */
+ /* ### ACHTUNG: Neuer Text in Resource? Die ausgew�hlte Datei besitzt ein falsches Format. : Die ausgew�hlte Datei besitzt ein falsches Format. */
+ Text [ en-US ] = "The selected file has an incorrect format." ;
+};
+String STR_QUERY_MUSTOWNFORMAT
+{
+ Text [ en-US ] = "Documents cannot be saved in $(FORMAT) format. Do you\nwant to save your changes using the $(OWNFORMAT) format?" ;
+};
+String STR_SAVEDOC
+{
+ Text [ en-US ] = "~Save" ;
+};
+String STR_UPDATEDOC
+{
+ Text [ en-US ] = "~Update" ;
+};
+String STR_SAVEASDOC
+{
+ Text [ en-US ] = "Save ~As..." ;
+};
+String STR_SAVECOPYDOC
+{
+ Text [ en-US ] = "Save Copy ~as..." ;
+};
+String STR_CLOSEDOC
+{
+ Text [ en-US ] = "~Close" ;
+};
+String STR_CLOSEDOC_ANDRETURN
+{
+ /* ### ACHTUNG: Neuer Text in Resource? S~chlie�en & zur�ck zu : S~chlie�en & zur�ck zu */
+ /* ### ACHTUNG: Neuer Text in Resource? S~chlie�en & zur�ck zu : S~chlie�en & zur�ck zu */
+ Text [ en-US ] = "~Close & Return to " ;
+};
+String STR_WIZARD
+{
+ Text [ en-US ] = " AutoPilot" ;
+};
+String RID_STR_FILTCONFIG
+{
+ Text [ en-US ] = "Configurations" ;
+};
+String RID_STR_FILTBASIC
+{
+ Text [ en-US ] = "%PRODUCTNAME Basic libraries" ;
+};
+String RID_STR_WARNSTYLEOVERWRITE
+{
+ Text [ en-US ] = "Should the \"$(ARG1)\" Style be replaced?" ;
+};
+String STR_DOC_LOADING
+{
+ Text [ en-US ] = "Loading Document" ;
+};
+Resource RID_DLSTATUS
+{
+ String INET_NAME_RESOLVE_START
+ {
+ Text [ en-US ] = "Connection to: $(HOST). Waiting for response..." ;
+ };
+ String INET_CONNECT_START
+ {
+ Text [ en-US ] = "Opening $(TARGET) at $(HOST)" ;
+ };
+ String INET_READ_STATUS
+ {
+ Text [ en-US ] = "Loading: $(TARGET) from $(HOST). Loaded: $(BYTE)" ;
+ };
+ String INET_CONNECTION_CLOSED
+ {
+ Text [ en-US ] = "Disconnected" ;
+ };
+};
+QueryBox MSG_OPEN_READONLY
+{
+ BUTTONS = WB_YES_NO ;
+ DEFBUTTON = WB_DEF_YES ;
+ Message [ en-US ] = "Document cannot be opened for editing.\nDo you want to open it as read-only?" ;
+};
+String STR_EDIT
+{
+ Text [ en-US ] = "Edit" ;
+};
+String RID_OFFICEFILTER
+{
+ Text [ en-US ] = "%PRODUCTNAME Documents" ;
+};
+String RID_OFFICEFILTER_WILDCARD
+{
+ Text = "*.sdw;*.sdd;*.sda;*.sdc;*.smf;*.sds;*.sd;*.sdm;*.smd" ;
+};
+String RID_OFFICEFILTER_MACTYPE
+{
+ Text = "SVsd0;SW/\2510;SVsc0;SVsm0;SVsh0;SVsd1;SW/\2511;SVsc1;SVsm1;SVsh1;MAIL" ;
+};
+String RID_OFFICEFILTER_OS2TYPE
+{
+ Text = "StarWriter 4.0;StarWriter 3.0;StarDraw 4.0;StarDraw 3.0;StarCalc 4.0;StarCalc 3.0;StarMath 4.0;StarMath 3.0;StarChart 4.0;StarChart 3.0;StarFrameSet;StarMessage" ;
+};
+String STR_FRAMEOBJECT_PROPERTIES
+{
+ Text [ en-US ] = "Propert~ies..." ;
+};
+String STR_FSET_FILTERNAME0
+{
+ Text [ en-US ] = "HTML (FrameSet)" ;
+};
+String STR_FSET_FILTERNAME1
+{
+ // nur 'Dokument' "ubersetzen - only translate 'Document'
+ Text [ en-US ] = "%PRODUCTNAME Frame Document" ;
+};
+String STR_TEMPL_MOVED
+{
+ Text [ en-US ] = "The template \"$(TEMPLATE)\" was not found at the original location. A template with the same name exists at \"$(FOUND)\". Should this template be used in the future when comparing?" ;
+};
+String STR_TEMPL_RESET
+{
+ Text [ en-US ] = "The template \"$(TEMPLATE)\" has not been found. Should the template be looked for the next time the document is opened ?" ;
+};
+String STR_AUTOMATICVERSION
+{
+ Text [ en-US ] = "Automatically saved version" ;
+};
+
+String STR_DOCTYPENAME_SW
+{
+ Text [ en-US ] = "Text Document";
+};
+
+String STR_DOCTYPENAME_SWWEB
+{
+ Text [ en-US ] = "HTML Document";
+};
+
+String STR_DOCTYPENAME_SWGLOB
+{
+ Text [ en-US ] = "Master Document";
+};
+
+String STR_DOCTYPENAME_SC
+{
+ Text [ en-US ] = "Spreadsheet";
+};
+
+String STR_DOCTYPENAME_SI
+{
+ Text [ en-US ] = "Presentation";
+};
+
+String STR_DOCTYPENAME_SD
+{
+ Text [ en-US ] = "Drawing";
+};
+
+String STR_DOCTYPENAME_MESSAGE
+{
+ Text [ en-US ] = "Message";
+};
+
+String STR_NOSAVEANDCLOSE
+{
+ Text [ en-US ] = "~Discard" ;
+};
+
+String STR_PACKNGO_NOACCESS
+{
+ Text [ en-US ] = "Access to the current data medium not possible." ;
+};
+
+String STR_PACKNGO_NEWMEDIUM
+{
+ Text [ en-US ] = "Insert the next data carrier and click OK." ;
+};
+
+String STR_OBJECT
+{
+ Text [ en-US ] = "Object" ;
+};
+
+String STR_EDITOBJECT
+{
+ Text [ en-US ] = "~Edit";
+};
+
+// --> PB 2004-08-20 #i33095#
+/* obsolete
+String STR_OPENOBJECT
+{
+ Text [ en-US ] = "~Open";
+};
+*/
+
+QueryBox DLG_MACROQUERY
+{
+ Buttons = WB_OK_CANCEL;
+ Title [ en-US ] = "Run Macro" ;
+
+ Message [ en-US ] = "This document contains macros. $(TEXT)";
+};
+
+String BTN_OK
+{
+ Text [ en-US ] = "Run" ;
+};
+String BTN_CANCEL
+{
+ Text [ en-US ] = "Do Not Run" ;
+};
+String FT_CANCEL
+{
+ Text [ en-US ] = "According to the security settings, the macros in this document should not be run. Do you want to run them anyway?";
+};
+String FT_OK
+{
+ Text [ en-US ] = "Do you want to allow these macros to be run?";
+};
+
+String STR_EXPORTASPDF_TITLE
+{
+ Text [ en-US ] = "Export as PDF";
+};
+
+String STR_EXPORTWITHCFGBUTTON
+{
+ Text [ en-US ] = "Export...";
+};
+
+String STR_EXPORTBUTTON
+{
+ Text [ en-US ] = "Export" ;
+};
+
+String RID_SVXSTR_SECURITY_ADDPATH
+{
+ Text [ en-US ] = "Add this directory to the list of secure paths: " ;
+};
+
+String STR_LABEL_FILEFORMAT
+{
+ Text [ en-US ] = "File format:" ;
+};
+
+String STR_HIDDENINFO_CONTAINS
+{
+ Text [ en-US ] = "This document contains:\n\n" ;
+};
+String STR_HIDDENINFO_RECORDCHANGES
+{
+ Text [ en-US ] = "Recorded changes" ;
+};
+String STR_HIDDENINFO_NOTES
+{
+ Text [ en-US ] = "Notes" ;
+};
+String STR_HIDDENINFO_DOCVERSIONS
+{
+ Text [ en-US ] = "Document versions" ;
+};
+String STR_HIDDENINFO_FIELDS
+{
+ Text [ en-US ] = "Fields" ;
+};
+String STR_HIDDENINFO_LINKDATA
+{
+ Text [ en-US ] = "Linked data..." ;
+};
+String STR_HIDDENINFO_CONTINUE_SAVING
+{
+ Text [ en-US ] = "Do you want to continue saving the document?" ;
+};
+String STR_HIDDENINFO_CONTINUE_PRINTING
+{
+ Text [ en-US ] = "Do you want to continue printing the document?" ;
+};
+String STR_HIDDENINFO_CONTINUE_SIGNING
+{
+ Text [ en-US ] = "Do you want to continue signing the document?" ;
+};
+String STR_HIDDENINFO_CONTINUE_CREATEPDF
+{
+ Text [ en-US ] = "Do you want to continue creating a PDF file?" ;
+};
+
+String STR_NEW_FILENAME_SAVE
+{
+ Text [ en-US ] = "If you do not want to overwrite the original document, you should save your work under a new filename." ;
+};
+
+String STR_ERROR_DELETE_TEMPLATE_DIR
+{
+ Text [ en-US ] = "Some template files are protected and can not be deleted.";
+};
+
+String STR_DOCINFO_INFOFIELD
+{
+ Text [ en-US ] = "Info %1";
+ Text [ x-comment ] = "pb: %1 == a number [1-4]";
+};
+
+String STR_SHARED
+{
+ Text [ en-US ] = " (shared)";
+ Text [ x-comment ] = "Used in the title of a shared document.";
+};
+
+String STR_XMLSEC_ODF12_EXPECTED
+{
+ Text [ en-US ] = "The document format version is set to ODF 1.1 (OpenOffice.org 2.x) in Tools-Options-Load/Save-General. Signing documents requires ODF 1.2 (OpenOffice.org 3.x).";
+};
+
+QueryBox MSG_XMLSEC_QUERY_SAVESIGNEDBEFORESIGN
+{
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_YES ;
+ Message [ en-US ] = "The document has to be saved before it can be signed. Saving the document removes all present signatures.\nDo you want to save the document?";
+};
+
+String STR_QRYTEMPL_MESSAGE
+{
+ Text [ en-US ] = "The template '$(ARG1)' on which this document is based, has been modified. Do you want to update style based formattings according to the modified template?";
+};
+
+String STR_QRYTEMPL_UPDATE_BTN
+{
+ Text [ en-US ] = "~Update Styles";
+};
+
+String STR_QRYTEMPL_KEEP_BTN
+{
+ Text [ en-US ] = "~Keep Old Styles";
+};
+
+// ******************************************************************* EOF
+
diff --git a/sfx2/source/doc/docfac.cxx b/sfx2/source/doc/docfac.cxx
new file mode 100644
index 000000000000..ff0a15e20088
--- /dev/null
+++ b/sfx2/source/doc/docfac.cxx
@@ -0,0 +1,491 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/registry/MergeConflictException.hpp>
+#include <com/sun/star/registry/XSimpleRegistry.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
+#include <com/sun/star/document/XTypeDetection.hpp>
+#include <com/sun/star/frame/XLoadable.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <comphelper/processfactory.hxx>
+#include <tools/config.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/configurationhelper.hxx>
+
+#include <sfx2/sfx.hrc>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/docfac.hxx>
+#include "sfx2/viewfac.hxx"
+#include "fltfnc.hxx"
+#include "arrdecl.hxx"
+#include <sfx2/app.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/mnumgr.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/sfxuno.hxx>
+#include "syspath.hxx"
+#include <osl/file.hxx>
+#include <osl/security.hxx>
+#include "doc.hrc"
+
+#include <assert.h>
+
+namespace css = ::com::sun::star;
+using namespace ::com::sun::star;
+
+//========================================================================
+
+DECL_PTRARRAY( SfxViewFactoryArr_Impl, SfxViewFactory*, 2, 2 )
+
+//========================================================================
+
+DBG_NAME(SfxObjectFactory)
+
+//static SfxObjectFactoryArr_Impl* pObjFac = 0;
+
+//========================================================================
+
+struct SfxObjectFactory_Impl
+{
+ SfxViewFactoryArr_Impl aViewFactoryArr;// Liste von <SfxViewFactory>s
+ SfxFilterArr_Impl aFilterArr; // Liste von <SFxFilter>n
+ ResId* pNameResId;
+ ::rtl::OUString aServiceName;
+ SfxFilterContainer* pFilterContainer;
+ SfxModule* pModule;
+ sal_uInt16 nImageId;
+ String aStandardTemplate;
+ sal_Bool bTemplateInitialized;
+ SvGlobalName aClassName;
+
+ SfxObjectFactory_Impl() :
+ pNameResId ( NULL ),
+ pFilterContainer ( NULL ),
+ pModule ( NULL ),
+ nImageId ( 0 ),
+ bTemplateInitialized( sal_False )
+ {}
+};
+
+//========================================================================
+
+SfxFilterContainer* SfxObjectFactory::GetFilterContainer( sal_Bool /*bForceLoad*/ ) const
+{
+ return pImpl->pFilterContainer;
+}
+
+//--------------------------------------------------------------------
+
+SfxObjectFactory::SfxObjectFactory
+(
+ const SvGlobalName& rName,
+ SfxObjectShellFlags nFlagsP,
+ const char* pName
+) : pShortName( pName ),
+ pImpl( new SfxObjectFactory_Impl ),
+ nFlags( nFlagsP )
+{
+ DBG_CTOR(SfxObjectFactory, 0);
+ pImpl->pFilterContainer = new SfxFilterContainer( String::CreateFromAscii( pName ) );
+
+ String aShortName( String::CreateFromAscii( pShortName ) );
+ aShortName.ToLowerAscii();
+ pImpl->aClassName = rName;
+ if ( aShortName.EqualsAscii( "swriter" ) )
+ pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SW );
+ else if ( aShortName.EqualsAscii( "swriter/web" ) )
+ pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SWWEB );
+ else if ( aShortName.EqualsAscii( "swriter/globaldocument" ) )
+ pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SWGLOB );
+ else if ( aShortName.EqualsAscii( "scalc" ) )
+ pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SC );
+ else if ( aShortName.EqualsAscii( "simpress" ) )
+ pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SI );
+ else if ( aShortName.EqualsAscii( "sdraw" ) )
+ pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SD );
+ else if ( aShortName.EqualsAscii( "message" ) )
+ pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_MESSAGE );
+}
+
+//--------------------------------------------------------------------
+
+SfxObjectFactory::~SfxObjectFactory()
+{
+ DBG_DTOR(SfxObjectFactory, 0);
+
+ const sal_uInt16 nCount = pImpl->aFilterArr.Count();
+ for ( sal_uInt16 i = 0; i < nCount; ++i )
+ delete pImpl->aFilterArr[i];
+ delete pImpl->pNameResId;
+ delete pImpl;
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectFactory::RegisterViewFactory
+(
+ SfxViewFactory &rFactory
+)
+{
+#if OSL_DEBUG_LEVEL > 0
+ {
+ const String sViewName( rFactory.GetAPIViewName() );
+ for ( sal_uInt16 i = 0; i < pImpl->aViewFactoryArr.Count(); ++i )
+ {
+ if ( !pImpl->aViewFactoryArr[i]->GetAPIViewName().Equals( sViewName ) )
+ continue;
+ ByteString sMessage( "SfxObjectFactory::RegisterViewFactory: duplicate view name '" );
+ sMessage += ByteString( sViewName, RTL_TEXTENCODING_ASCII_US );
+ sMessage += "'!";
+ OSL_ENSURE( false, sMessage.GetBuffer() );
+ break;
+ }
+ }
+#endif
+ sal_uInt16 nPos;
+ for ( nPos = 0;
+ nPos < pImpl->aViewFactoryArr.Count() &&
+ pImpl->aViewFactoryArr[nPos]->GetOrdinal() <= rFactory.GetOrdinal();
+ ++nPos )
+ /* empty loop */;
+ pImpl->aViewFactoryArr.Insert(nPos, &rFactory);
+}
+
+//--------------------------------------------------------------------
+
+sal_uInt16 SfxObjectFactory::GetViewFactoryCount() const
+{
+ return pImpl->aViewFactoryArr.Count();
+}
+
+//--------------------------------------------------------------------
+
+SfxViewFactory& SfxObjectFactory::GetViewFactory(sal_uInt16 i) const
+{
+ return *pImpl->aViewFactoryArr[i];
+}
+
+//--------------------------------------------------------------------
+
+SfxModule* SfxObjectFactory::GetModule() const
+{
+ return pImpl->pModule;
+}
+
+void SfxObjectFactory::SetModule_Impl( SfxModule *pMod )
+{
+ pImpl->pModule = pMod;
+}
+
+void SfxObjectFactory::SetSystemTemplate( const String& rServiceName, const String& rTemplateName )
+{
+ static const int nMaxPathSize = 16000;
+ static ::rtl::OUString SERVICE_FILTER_FACTORY = ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" );
+ static ::rtl::OUString SERVICE_TYPE_DECTECTION = ::rtl::OUString::createFromAscii( "com.sun.star.document.TypeDetection" );
+ static ::rtl::OUString SERVICE_SIMPLE_ACCESS = ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" );
+
+ static ::rtl::OUString CONF_ROOT = ::rtl::OUString::createFromAscii( "/org.openoffice.Setup");
+ static ::rtl::OUString CONF_PATH = ::rtl::OUString::createFromAscii( "Office/Factories/" ) + ::rtl::OUString( rServiceName );
+ static ::rtl::OUString PROP_DEF_TEMPL_CHANGED = ::rtl::OUString::createFromAscii( "ooSetupFactorySystemDefaultTemplateChanged" );
+ static ::rtl::OUString PROP_ACTUAL_FILTER = ::rtl::OUString::createFromAscii( "ooSetupFactoryActualFilter" );
+
+ static ::rtl::OUString DEF_TPL_STR = ::rtl::OUString::createFromAscii("/soffice.");
+
+ String sURL;
+ String sPath;
+ sal_Unicode aPathBuffer[nMaxPathSize];
+ if ( SystemPath::GetUserTemplateLocation( aPathBuffer, nMaxPathSize ))
+ sPath = String( aPathBuffer );
+ ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sPath, sURL );
+
+ ::rtl::OUString aUserTemplateURL( sURL );
+ if ( aUserTemplateURL.getLength() != 0)
+ {
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
+ uno::Reference< uno::XInterface > xConfig = ::comphelper::ConfigurationHelper::openConfig(
+ xFactory, CONF_ROOT, ::comphelper::ConfigurationHelper::E_STANDARD );
+
+ ::rtl::OUString aActualFilter;
+ ::comphelper::ConfigurationHelper::readRelativeKey( xConfig, CONF_PATH, PROP_ACTUAL_FILTER ) >>= aActualFilter;
+ sal_Bool bChanged(sal_False);
+ ::comphelper::ConfigurationHelper::readRelativeKey( xConfig, CONF_PATH, PROP_DEF_TEMPL_CHANGED ) >>= bChanged;
+
+ uno::Reference< container::XNameAccess > xFilterFactory(
+ xFactory->createInstance( SERVICE_FILTER_FACTORY ), uno::UNO_QUERY_THROW );
+ uno::Reference< container::XNameAccess > xTypeDetection(
+ xFactory->createInstance( SERVICE_TYPE_DECTECTION ), uno::UNO_QUERY_THROW );
+
+ ::rtl::OUString aActualFilterTypeName;
+ uno::Sequence< beans::PropertyValue > aActuralFilterData;
+ xFilterFactory->getByName( aActualFilter ) >>= aActuralFilterData;
+ for ( sal_Int32 nInd = 0; nInd < aActuralFilterData.getLength(); nInd++ )
+ if ( aActuralFilterData[nInd].Name.equalsAscii( "Type" ) )
+ aActuralFilterData[nInd].Value >>= aActualFilterTypeName;
+ ::comphelper::SequenceAsHashMap aProps1( xTypeDetection->getByName( aActualFilterTypeName ) );
+ uno::Sequence< ::rtl::OUString > aAllExt =
+ aProps1.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Extensions" ), uno::Sequence< ::rtl::OUString >() );
+ //To-do: check if aAllExt is empty first
+ ::rtl::OUString aExt = aAllExt[0];
+
+ aUserTemplateURL += DEF_TPL_STR;
+ aUserTemplateURL += aExt;
+
+ uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess(
+ xFactory->createInstance( SERVICE_SIMPLE_ACCESS ), uno::UNO_QUERY_THROW );
+
+ ::rtl::OUString aBackupURL;
+ ::osl::Security().getConfigDir(aBackupURL);
+ aBackupURL += ::rtl::OUString::createFromAscii( "/temp" );
+
+ if ( !xSimpleFileAccess->exists( aBackupURL ) )
+ xSimpleFileAccess->createFolder( aBackupURL );
+
+ aBackupURL += DEF_TPL_STR;
+ aBackupURL += aExt;
+
+ if ( rTemplateName.Len() != 0 )
+ {
+ if ( xSimpleFileAccess->exists( aUserTemplateURL ) && !bChanged )
+ xSimpleFileAccess->copy( aUserTemplateURL, aBackupURL );
+
+ uno::Reference< document::XTypeDetection > xTypeDetector( xTypeDetection, uno::UNO_QUERY );
+ ::comphelper::SequenceAsHashMap aProps2( xTypeDetection->getByName( xTypeDetector->queryTypeByURL( rTemplateName ) ) );
+ ::rtl::OUString aFilterName =
+ aProps2.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii("PreferredFilter"), ::rtl::OUString() );
+
+ uno::Sequence< beans::PropertyValue > aArgs( 3 );
+ aArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" );
+ aArgs[0].Value <<= aFilterName;
+ aArgs[1].Name = ::rtl::OUString::createFromAscii( "AsTemplate" );
+ aArgs[1].Value <<= sal_True;
+ aArgs[2].Name = ::rtl::OUString::createFromAscii( "URL" );
+ aArgs[2].Value <<= ::rtl::OUString( rTemplateName );
+
+ uno::Reference< frame::XLoadable > xLoadable( xFactory->createInstance( ::rtl::OUString( rServiceName ) ), uno::UNO_QUERY );
+ xLoadable->load( aArgs );
+
+ aArgs.realloc( 2 );
+ aArgs[1].Name = ::rtl::OUString::createFromAscii( "Overwrite" );
+ aArgs[1].Value <<= sal_True;
+
+ uno::Reference< frame::XStorable > xStorable( xLoadable, uno::UNO_QUERY );
+ xStorable->storeToURL( aUserTemplateURL, aArgs );
+ ::comphelper::ConfigurationHelper::writeRelativeKey( xConfig, CONF_PATH, PROP_DEF_TEMPL_CHANGED, uno::makeAny( sal_True ));
+ ::comphelper::ConfigurationHelper::flush( xConfig );
+ }
+ else
+ {
+ DBG_ASSERT( bChanged, "invalid ooSetupFactorySystemDefaultTemplateChanged value!" );
+
+ xSimpleFileAccess->copy( aBackupURL, aUserTemplateURL );
+ xSimpleFileAccess->kill( aBackupURL );
+ ::comphelper::ConfigurationHelper::writeRelativeKey( xConfig, CONF_PATH, PROP_DEF_TEMPL_CHANGED, uno::makeAny( sal_False ));
+ ::comphelper::ConfigurationHelper::flush( xConfig );
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+}
+
+void SfxObjectFactory::SetStandardTemplate( const String& rServiceName, const String& rTemplate )
+{
+ SvtModuleOptions::EFactory eFac = SvtModuleOptions::ClassifyFactoryByServiceName(rServiceName);
+ if (eFac == SvtModuleOptions::E_UNKNOWN_FACTORY)
+ eFac = SvtModuleOptions::ClassifyFactoryByShortName(rServiceName);
+ if (eFac != SvtModuleOptions::E_UNKNOWN_FACTORY)
+ {
+ SetSystemTemplate( rServiceName, rTemplate );
+ SvtModuleOptions().SetFactoryStandardTemplate(eFac, rTemplate);
+ }
+}
+
+String SfxObjectFactory::GetStandardTemplate( const String& rServiceName )
+{
+ SvtModuleOptions::EFactory eFac = SvtModuleOptions::ClassifyFactoryByServiceName(rServiceName);
+ if (eFac == SvtModuleOptions::E_UNKNOWN_FACTORY)
+ eFac = SvtModuleOptions::ClassifyFactoryByShortName(rServiceName);
+
+ String sTemplate;
+ if (eFac != SvtModuleOptions::E_UNKNOWN_FACTORY)
+ sTemplate = SvtModuleOptions().GetFactoryStandardTemplate(eFac);
+
+ return sTemplate;
+}
+
+/*
+const SfxObjectFactory* SfxObjectFactory::GetFactory( const String& rFactoryURL )
+{
+ const SfxObjectFactory* pFactory = 0;
+ String aFact( rFactoryURL );
+ String aPrefix( DEFINE_CONST_UNICODE( "private:factory/" ) );
+ if ( aPrefix.Len() == aFact.Match( aPrefix ) )
+ // Aufruf m"oglich mit z.B. "swriter" oder "private:factory/swriter"
+ aFact.Erase( 0, aPrefix.Len() );
+ sal_uInt16 nPos = aFact.Search( '?' );
+
+ // Etwaige Parameter abschneiden
+ aFact.Erase( nPos, aFact.Len() );
+
+ SfxApplication *pApp = SFX_APP();
+
+ // "swriter4" durch "swriter" ersetzen, zum Vergleichen uppercase verwenden
+ WildCard aSearchedFac( aFact.EraseAllChars('4').ToUpperAscii() );
+ for( sal_uInt16 n = GetObjectFactoryCount_Impl(); !pFactory && n--; )
+ {
+ pFactory = &GetObjectFactory_Impl( n );
+ String aCompareTo = String::CreateFromAscii( pFactory->GetShortName() );
+ aCompareTo.ToUpperAscii();
+ if( !aSearchedFac.Matches( aCompareTo ) )
+ pFactory = 0;
+ }
+
+ return pFactory;
+}
+*/
+
+const SfxFilter* SfxObjectFactory::GetTemplateFilter() const
+{
+ USHORT nVersion=0;
+ SfxFilterMatcher aMatcher ( String::CreateFromAscii( pShortName ) );
+ SfxFilterMatcherIter aIter( &aMatcher );
+ const SfxFilter *pFilter = 0;
+ const SfxFilter *pTemp = aIter.First();
+ while ( pTemp )
+ {
+ if( pTemp->IsOwnFormat() && pTemp->IsOwnTemplateFormat() && ( pTemp->GetVersion() > nVersion ) )
+ {
+ pFilter = pTemp;
+ nVersion = (USHORT) pTemp->GetVersion();
+ }
+
+ pTemp = aIter.Next();
+ }
+
+ return pFilter;
+}
+
+void SfxObjectFactory::SetDocumentTypeNameResource( const ResId& rId )
+{
+ DBG_ASSERT( !pImpl->pNameResId, "UI-Namensresource mehrfach gesetzt!" );
+ pImpl->pNameResId = new ResId( rId );
+}
+
+String SfxObjectFactory::GetDocumentTypeName() const
+{
+ if ( pImpl->pNameResId )
+ return String( *pImpl->pNameResId );
+ return String();
+}
+
+void SfxObjectFactory::SetDocumentServiceName( const ::rtl::OUString& rServiceName )
+{
+ pImpl->aServiceName = rServiceName;
+}
+
+const ::rtl::OUString& SfxObjectFactory::GetDocumentServiceName() const
+{
+ return pImpl->aServiceName;
+}
+
+const SvGlobalName& SfxObjectFactory::GetClassId() const
+{
+ return pImpl->aClassName;
+}
+
+String SfxObjectFactory::GetFactoryURL() const
+{
+ ::rtl::OUStringBuffer aURLComposer;
+ aURLComposer.appendAscii( "private:factory/" );
+ aURLComposer.appendAscii( GetShortName() );
+ return aURLComposer.makeStringAndClear();
+}
+
+String SfxObjectFactory::GetModuleName() const
+{
+ static ::rtl::OUString SERVICENAME_MODULEMANAGER = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
+ static ::rtl::OUString PROP_MODULEUINAME = ::rtl::OUString::createFromAscii("ooSetupFactoryUIName");
+
+ try
+ {
+ css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
+
+ css::uno::Reference< css::container::XNameAccess > xModuleManager(
+ xSMGR->createInstance(SERVICENAME_MODULEMANAGER),
+ css::uno::UNO_QUERY_THROW);
+
+ ::rtl::OUString sDocService(GetDocumentServiceName());
+ ::comphelper::SequenceAsHashMap aPropSet( xModuleManager->getByName(sDocService) );
+ ::rtl::OUString sModuleName = aPropSet.getUnpackedValueOrDefault(PROP_MODULEUINAME, ::rtl::OUString());
+ return String(sModuleName);
+ }
+ catch(const css::uno::RuntimeException&)
+ { throw; }
+ catch(const css::uno::Exception&)
+ {}
+
+ return String();
+}
+
+
+sal_uInt16 SfxObjectFactory::GetViewNo_Impl( const sal_uInt16 i_nViewId, const sal_uInt16 i_nFallback ) const
+{
+ for ( sal_uInt16 curViewNo = 0; curViewNo < GetViewFactoryCount(); ++curViewNo )
+ {
+ const sal_uInt16 curViewId = GetViewFactory( curViewNo ).GetOrdinal();
+ if ( i_nViewId == curViewId )
+ return curViewNo;
+ }
+ return i_nFallback;
+}
+
+SfxViewFactory* SfxObjectFactory::GetViewFactoryByViewName( const String& i_rViewName ) const
+{
+ for ( USHORT nViewNo = 0;
+ nViewNo < GetViewFactoryCount();
+ ++nViewNo
+ )
+ {
+ SfxViewFactory& rViewFac( GetViewFactory( nViewNo ) );
+ if ( ( rViewFac.GetAPIViewName() == i_rViewName )
+ || ( rViewFac.GetLegacyViewName() == i_rViewName )
+ )
+ return &rViewFac;
+ }
+ return NULL;
+}
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
new file mode 100644
index 000000000000..434553bdb226
--- /dev/null
+++ b/sfx2/source/doc/docfile.cxx
@@ -0,0 +1,3934 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <sfx2/docfile.hxx>
+#include "sfx2/signaturestate.hxx"
+
+#include <uno/mapping.hxx>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/ucb/XContent.hpp>
+#include <com/sun/star/document/XDocumentRevisionListPersistence.hpp>
+#include <com/sun/star/document/LockedDocumentRequest.hpp>
+#include <com/sun/star/document/OwnLockOnDocumentRequest.hpp>
+#include <com/sun/star/document/LockedOnSavingRequest.hpp>
+#include <com/sun/star/document/LockFileIgnoreRequest.hpp>
+#include <com/sun/star/document/ChangedByOthersRequest.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/UseBackupException.hpp>
+#include <com/sun/star/embed/XOptimizedStorage.hpp>
+#include <com/sun/star/ucb/InteractiveIOException.hpp>
+#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
+#include <com/sun/star/ucb/CommandFailedException.hpp>
+#include <com/sun/star/ucb/CommandAbortedException.hpp>
+#include <com/sun/star/ucb/XCommandEnvironment.hpp>
+#include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
+#include <com/sun/star/ucb/XContentProvider.hpp>
+#include <com/sun/star/ucb/XProgressHandler.hpp>
+#include <com/sun/star/ucb/XCommandInfo.hpp>
+#include <com/sun/star/util/XArchiver.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XTruncate.hpp>
+#include <com/sun/star/io/XStreamListener.hpp>
+#include <com/sun/star/io/XSeekable.hpp>
+#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/ucb/InsertCommandArgument.hpp>
+#include <com/sun/star/ucb/NameClash.hpp>
+#include <com/sun/star/ucb/TransferInfo.hpp>
+#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
+#include <com/sun/star/ucb/OpenMode.hpp>
+#include <com/sun/star/ucb/NameClashException.hpp>
+#include <com/sun/star/logging/XSimpleLogRing.hpp>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#ifndef _COM_SUN_STAR_SECURITY_DOCUMENTSIGNATURESINFORMATION_HPP_
+#include <com/sun/star/security/DocumentSignatureInformation.hpp>
+#endif
+#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+#include <tools/zcodec.hxx>
+#include <tools/cachestr.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/tempfile.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/componentcontext.hxx>
+#include <comphelper/interaction.hxx>
+#include <framework/interaction.hxx>
+#include <unotools/streamhelper.hxx>
+#include <unotools/localedatawrapper.hxx>
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#include <svl/stritem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/lckbitem.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svl/itemset.hxx>
+#include <svl/intitem.hxx>
+#include <svtools/svparser.hxx> // SvKeyValue
+#include <cppuhelper/weakref.hxx>
+#include <cppuhelper/implbase1.hxx>
+
+#define _SVSTDARR_ULONGS
+#define _SVSTDARR_STRINGSDTOR
+#include <svl/svstdarr.hxx>
+
+#include <unotools/streamwrap.hxx>
+
+#include <rtl/logfile.hxx>
+#include <osl/file.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::io;
+
+#include <comphelper/storagehelper.hxx>
+#include <comphelper/mediadescriptor.hxx>
+#include <comphelper/configurationhelper.hxx>
+#include <comphelper/docpasswordhelper.hxx>
+#include <tools/urlobj.hxx>
+#include <tools/inetmime.hxx>
+#include <unotools/ucblockbytes.hxx>
+#include <unotools/pathoptions.hxx>
+#include <svtools/asynclink.hxx>
+#include <svl/inettype.hxx>
+#include <ucbhelper/contentbroker.hxx>
+#include <ucbhelper/commandenvironment.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/ucbhelper.hxx>
+#include <unotools/progresshandlerwrap.hxx>
+#include <ucbhelper/content.hxx>
+#include <ucbhelper/interactionrequest.hxx>
+#include <sot/stg.hxx>
+#include <unotools/saveopt.hxx>
+#include <svl/documentlockfile.hxx>
+
+#include "helper.hxx"
+#include <sfx2/request.hxx> // SFX_ITEMSET_SET
+#include <sfx2/app.hxx> // GetFilterMatcher
+#include <sfx2/frame.hxx> // LoadTargetFrame
+#include "fltfnc.hxx" // SfxFilterMatcher
+#include <sfx2/docfilt.hxx> // SfxFilter
+#include <sfx2/objsh.hxx> // CheckOpenMode
+#include <sfx2/docfac.hxx> // GetFilterContainer
+#include "doc.hrc"
+#include "openflag.hxx" // SFX_STREAM_READONLY etc.
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/appuno.hxx>
+
+//#include "xmlversion.hxx"
+
+#define MAX_REDIRECT 5
+
+
+sal_Bool IsReadonlyAccordingACL( const sal_Unicode* pFilePath );
+
+//==========================================================
+namespace {
+
+static const sal_Int8 LOCK_UI_NOLOCK = 0;
+static const sal_Int8 LOCK_UI_SUCCEEDED = 1;
+static const sal_Int8 LOCK_UI_TRY = 2;
+
+//----------------------------------------------------------------
+sal_Bool IsSystemFileLockingUsed()
+{
+ // check whether system file locking has been used, the default value is false
+ sal_Bool bUseSystemLock = sal_False;
+ try
+ {
+
+ uno::Reference< uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig(
+ ::comphelper::getProcessServiceFactory(),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
+ ::comphelper::ConfigurationHelper::E_STANDARD );
+ if ( !xCommonConfig.is() )
+ throw uno::RuntimeException();
+
+ ::comphelper::ConfigurationHelper::readRelativeKey(
+ xCommonConfig,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentSystemFileLocking" ) ) ) >>= bUseSystemLock;
+ }
+ catch( const uno::Exception& )
+ {
+ }
+
+ return bUseSystemLock;
+}
+
+//----------------------------------------------------------------
+sal_Bool IsOOoLockFileUsed()
+{
+ // check whether system file locking has been used, the default value is false
+ sal_Bool bOOoLockFileUsed = sal_False;
+ try
+ {
+
+ uno::Reference< uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig(
+ ::comphelper::getProcessServiceFactory(),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
+ ::comphelper::ConfigurationHelper::E_STANDARD );
+ if ( !xCommonConfig.is() )
+ throw uno::RuntimeException();
+
+ ::comphelper::ConfigurationHelper::readRelativeKey(
+ xCommonConfig,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentOOoLockFile" ) ) ) >>= bOOoLockFileUsed;
+ }
+ catch( const uno::Exception& )
+ {
+ }
+
+ return bOOoLockFileUsed;
+}
+
+} // anonymous namespace
+//==========================================================
+
+
+//----------------------------------------------------------------
+class SfxMediumHandler_Impl : public ::cppu::WeakImplHelper1< com::sun::star::task::XInteractionHandler >
+{
+ com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInter;
+
+public:
+ virtual void SAL_CALL handle( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& xRequest )
+ throw( com::sun::star::uno::RuntimeException );
+
+ SfxMediumHandler_Impl( com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > xInteraction )
+ : m_xInter( xInteraction )
+ {}
+
+ ~SfxMediumHandler_Impl();
+};
+
+//----------------------------------------------------------------
+SfxMediumHandler_Impl::~SfxMediumHandler_Impl()
+{
+}
+
+//----------------------------------------------------------------
+void SAL_CALL SfxMediumHandler_Impl::handle( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& xRequest )
+ throw( com::sun::star::uno::RuntimeException )
+{
+ if( !m_xInter.is() )
+ return;
+
+ com::sun::star::uno::Any aRequest = xRequest->getRequest();
+ com::sun::star::ucb::InteractiveIOException aIoException;
+ com::sun::star::ucb::UnsupportedDataSinkException aSinkException;
+ if ( (aRequest >>= aIoException) && ( aIoException.Code == IOErrorCode_ACCESS_DENIED || aIoException.Code == IOErrorCode_LOCKING_VIOLATION ) )
+ return;
+ else
+ if ( aRequest >>= aSinkException )
+ return;
+ else
+ m_xInter->handle( xRequest );
+}
+
+//----------------------------------------------------------------
+class SfxMedium_Impl : public SvCompatWeakBase
+{
+public:
+ ::ucbhelper::Content aContent;
+ sal_Bool bUpdatePickList : 1;
+ sal_Bool bIsTemp : 1;
+ sal_Bool bForceSynchron : 1;
+ sal_Bool bDownloadDone : 1;
+ sal_Bool bDontCallDoneLinkOnSharingError : 1;
+ sal_Bool bIsStorage: 1;
+ sal_Bool bUseInteractionHandler: 1;
+ sal_Bool bAllowDefaultIntHdl: 1;
+ sal_Bool bIsCharsetInitialized: 1;
+ sal_Bool bDisposeStorage: 1;
+ sal_Bool bStorageBasedOnInStream: 1;
+ sal_Bool m_bSalvageMode: 1;
+ sal_Bool m_bVersionsAlreadyLoaded: 1;
+ sal_Bool m_bLocked: 1;
+ sal_Bool m_bGotDateTime: 1;
+
+ uno::Reference < embed::XStorage > xStorage;
+
+ SfxMedium* pAntiImpl;
+
+ long nFileVersion;
+
+ const SfxFilter* pOrigFilter;
+ String aOrigURL;
+ String aPreRedirectionURL;
+ String aReferer;
+ DateTime aExpireTime;
+ SfxFrameWeak wLoadTargetFrame;
+ SvKeyValueIteratorRef xAttributes;
+
+ svtools::AsynchronLink aDoneLink;
+ svtools::AsynchronLink aAvailableLink;
+
+ uno::Sequence < util::RevisionTag > aVersions;
+
+ ::utl::TempFile* pTempFile;
+
+ uno::Reference < embed::XStorage > m_xZipStorage;
+ Reference < XInputStream > xInputStream;
+ Reference < XStream > xStream;
+
+ uno::Reference< io::XStream > m_xLockingStream;
+
+ sal_uInt32 nLastStorageError;
+ ::rtl::OUString aCharset;
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xInteraction;
+
+ sal_Bool m_bRemoveBackup;
+ ::rtl::OUString m_aBackupURL;
+
+ // the following member is changed and makes sence only during saving
+ // TODO/LATER: in future the signature state should be controlled by the medium not by the document
+ // in this case the member will hold this information
+ sal_uInt16 m_nSignatureState;
+
+ util::DateTime m_aDateTime;
+
+ uno::Reference< logging::XSimpleLogRing > m_xLogRing;
+
+ SfxMedium_Impl( SfxMedium* pAntiImplP );
+ ~SfxMedium_Impl();
+};
+
+void SfxMedium::DataAvailable_Impl()
+{
+ pImp->aAvailableLink.ClearPendingCall();
+ pImp->aAvailableLink.Call( NULL );
+}
+
+void SfxMedium::Cancel_Impl()
+{
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+}
+
+//------------------------------------------------------------------
+SfxMedium_Impl::SfxMedium_Impl( SfxMedium* pAntiImplP )
+ : SvCompatWeakBase( pAntiImplP ),
+ bUpdatePickList(sal_True),
+ bIsTemp( sal_False ),
+ bForceSynchron( sal_False ),
+ bDownloadDone( sal_True ),
+ bDontCallDoneLinkOnSharingError( sal_False ),
+ bIsStorage( sal_False ),
+ bUseInteractionHandler( sal_True ),
+ bAllowDefaultIntHdl( sal_False ),
+ bIsCharsetInitialized( sal_False ),
+ bStorageBasedOnInStream( sal_False ),
+ m_bSalvageMode( sal_False ),
+ m_bVersionsAlreadyLoaded( sal_False ),
+ m_bLocked( sal_False ),
+ m_bGotDateTime( sal_False ),
+ pAntiImpl( pAntiImplP ),
+ nFileVersion( 0 ),
+ pOrigFilter( 0 ),
+ aExpireTime( Date() + 10, Time() ),
+ pTempFile( NULL ),
+ nLastStorageError( 0 ),
+ m_bRemoveBackup( sal_False ),
+ m_nSignatureState( SIGNATURESTATE_NOSIGNATURES )
+{
+ aDoneLink.CreateMutex();
+}
+
+//------------------------------------------------------------------
+SfxMedium_Impl::~SfxMedium_Impl()
+{
+
+ aDoneLink.ClearPendingCall();
+ aAvailableLink.ClearPendingCall();
+
+ if ( pTempFile )
+ delete pTempFile;
+}
+
+//================================================================
+
+#define IMPL_CTOR(rootVal,URLVal) \
+ eError( SVSTREAM_OK ), \
+ \
+ bDirect( sal_False ), \
+ bRoot( rootVal ), \
+ bSetFilter( sal_False ), \
+ bTriedStorage( sal_False ), \
+ \
+ nStorOpenMode( SFX_STREAM_READWRITE ), \
+ pURLObj( URLVal ), \
+ pInStream(0), \
+ pOutStream( 0 )
+
+//------------------------------------------------------------------
+void SfxMedium::ResetError()
+{
+ eError = SVSTREAM_OK;
+ if( pInStream )
+ pInStream->ResetError();
+ if( pOutStream )
+ pOutStream->ResetError();
+}
+
+//------------------------------------------------------------------
+sal_uInt32 SfxMedium::GetLastStorageCreationState()
+{
+ return pImp->nLastStorageError;
+}
+
+//------------------------------------------------------------------
+void SfxMedium::AddLog( const ::rtl::OUString& aMessage )
+{
+ if ( !pImp->m_xLogRing.is() )
+ {
+ try
+ {
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ if ( aContext.is() )
+ pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ if ( pImp->m_xLogRing.is() )
+ pImp->m_xLogRing->logString( aMessage );
+}
+
+//------------------------------------------------------------------
+void SfxMedium::SetError( sal_uInt32 nError, const ::rtl::OUString& aLogMessage )
+{
+ eError = nError;
+ if ( eError != ERRCODE_NONE && aLogMessage.getLength() )
+ AddLog( aLogMessage );
+}
+
+//------------------------------------------------------------------
+sal_uInt32 SfxMedium::GetErrorCode() const
+{
+ sal_uInt32 lError=eError;
+ if(!lError && pInStream)
+ lError=pInStream->GetErrorCode();
+ if(!lError && pOutStream)
+ lError=pOutStream->GetErrorCode();
+ return lError;
+}
+
+//------------------------------------------------------------------
+void SfxMedium::CheckFileDate( const util::DateTime& aInitDate )
+{
+ GetInitFileDate( sal_True );
+ if ( pImp->m_aDateTime.Seconds != aInitDate.Seconds
+ || pImp->m_aDateTime.Minutes != aInitDate.Minutes
+ || pImp->m_aDateTime.Hours != aInitDate.Hours
+ || pImp->m_aDateTime.Day != aInitDate.Day
+ || pImp->m_aDateTime.Month != aInitDate.Month
+ || pImp->m_aDateTime.Year != aInitDate.Year )
+ {
+ uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler();
+
+ if ( xHandler.is() )
+ {
+ try
+ {
+ ::rtl::Reference< ::ucbhelper::InteractionRequest > xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
+ document::ChangedByOthersRequest() ) );
+ uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 3 );
+ aContinuations[0] = new ::ucbhelper::InteractionAbort( xInteractionRequestImpl.get() );
+ aContinuations[1] = new ::ucbhelper::InteractionApprove( xInteractionRequestImpl.get() );
+ xInteractionRequestImpl->setContinuations( aContinuations );
+
+ xHandler->handle( xInteractionRequestImpl.get() );
+
+ ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xInteractionRequestImpl->getSelection();
+ if ( uno::Reference< task::XInteractionAbort >( xSelected.get(), uno::UNO_QUERY ).is() )
+ {
+ SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ }
+ catch ( uno::Exception& )
+ {}
+ }
+ }
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::DocNeedsFileDateCheck()
+{
+ return ( !IsReadOnly() && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) );
+}
+
+//------------------------------------------------------------------
+util::DateTime SfxMedium::GetInitFileDate( sal_Bool bIgnoreOldValue )
+{
+ if ( ( bIgnoreOldValue || !pImp->m_bGotDateTime ) && aLogicName.Len() )
+ {
+ try
+ {
+ uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv;
+ ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
+
+ aContent.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "DateModified" )) ) >>= pImp->m_aDateTime;
+ pImp->m_bGotDateTime = sal_True;
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ }
+ }
+
+ return pImp->m_aDateTime;
+}
+
+//------------------------------------------------------------------
+Reference < XContent > SfxMedium::GetContent() const
+{
+ if ( !pImp->aContent.get().is() )
+ {
+ Reference < ::com::sun::star::ucb::XContent > xContent;
+ Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv;
+
+ SFX_ITEMSET_ARG( pSet, pItem, SfxUnoAnyItem, SID_CONTENT, sal_False);
+ if ( pItem )
+ pItem->GetValue() >>= xContent;
+
+ if ( xContent.is() )
+ {
+ try
+ {
+ pImp->aContent = ::ucbhelper::Content( xContent, xEnv );
+ }
+ catch ( Exception& )
+ {
+ }
+ }
+ else
+ {
+ // TODO: DBG_ERROR("SfxMedium::GetContent()\nCreate Content? This code exists as fallback only. Please clarify, why its used.");
+ String aURL;
+ if ( aName.Len() )
+ ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aURL );
+ else if ( aLogicName.Len() )
+ aURL = GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
+ if ( aURL.Len() )
+ ::ucbhelper::Content::create( aURL, xEnv, pImp->aContent );
+ }
+ }
+
+ return pImp->aContent.get();
+}
+
+//------------------------------------------------------------------
+::rtl::OUString SfxMedium::GetBaseURL( bool bForSaving )
+{
+ ::rtl::OUString aBaseURL;
+ const SfxStringItem* pBaseURLItem = static_cast<const SfxStringItem*>( GetItemSet()->GetItem(SID_DOC_BASEURL) );
+ if ( pBaseURLItem )
+ aBaseURL = pBaseURLItem->GetValue();
+ else if ( GetContent().is() )
+ {
+ try
+ {
+ Any aAny = pImp->aContent.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI" )) );
+ aAny >>= aBaseURL;
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ }
+
+ if ( !aBaseURL.getLength() )
+ aBaseURL = GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
+ }
+
+ if ( bForSaving )
+ {
+ SvtSaveOptions aOpt;
+ sal_Bool bIsRemote = IsRemote();
+ if( (bIsRemote && !aOpt.IsSaveRelINet()) || (!bRemote && !aOpt.IsSaveRelFSys()) )
+ return ::rtl::OUString();
+ }
+
+ return aBaseURL;
+}
+
+//------------------------------------------------------------------
+SvStream* SfxMedium::GetInStream()
+{
+ if ( pInStream )
+ return pInStream;
+
+ if ( pImp->pTempFile )
+ {
+ pInStream = new SvFileStream( aName, nStorOpenMode );
+
+ eError = pInStream->GetError();
+
+ if( !eError && (nStorOpenMode & STREAM_WRITE)
+ && ! pInStream->IsWritable() )
+ {
+ eError = ERRCODE_IO_ACCESSDENIED;
+ delete pInStream;
+ pInStream = NULL;
+ }
+ else
+ return pInStream;
+ }
+
+ GetMedium_Impl();
+
+ if ( GetError() )
+ return NULL;
+
+ return pInStream;
+}
+
+//------------------------------------------------------------------
+void SfxMedium::CloseInStream()
+{
+ CloseInStream_Impl();
+}
+
+void SfxMedium::CloseInStream_Impl()
+{
+ // if there is a storage based on the InStream, we have to
+ // close the storage, too, because otherwise the storage
+ // would use an invalid ( deleted ) stream.
+ if ( pInStream && pImp->xStorage.is() )
+ {
+ if ( pImp->bStorageBasedOnInStream )
+ CloseStorage();
+ }
+
+ if ( pInStream && !GetContent().is() )
+ {
+ CreateTempFile( sal_True );
+ return;
+ }
+
+ DELETEZ( pInStream );
+ if ( pSet )
+ pSet->ClearItem( SID_INPUTSTREAM );
+
+ CloseZipStorage_Impl();
+ pImp->xInputStream = uno::Reference< io::XInputStream >();
+
+ if ( !pOutStream )
+ {
+ // output part of the stream is not used so the whole stream can be closed
+ // TODO/LATER: is it correct?
+ pImp->xStream = uno::Reference< io::XStream >();
+ if ( pSet )
+ pSet->ClearItem( SID_STREAM );
+ }
+}
+
+//------------------------------------------------------------------
+SvStream* SfxMedium::GetOutStream()
+{
+ if ( !pOutStream )
+ {
+ // Create a temp. file if there is none because we always
+ // need one.
+ CreateTempFile( sal_False );
+
+ if ( pImp->pTempFile )
+ {
+ pOutStream = new SvFileStream( aName, STREAM_STD_READWRITE );
+ CloseStorage();
+ }
+ }
+
+ return pOutStream;
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::CloseOutStream()
+{
+ CloseOutStream_Impl();
+ return sal_True;
+}
+
+sal_Bool SfxMedium::CloseOutStream_Impl()
+{
+ if ( pOutStream )
+ {
+ // if there is a storage based on the OutStream, we have to
+ // close the storage, too, because otherwise the storage
+ // would use an invalid ( deleted ) stream.
+ //TODO/MBA: how to deal with this?!
+ //maybe we need a new flag when the storage was created from the outstream
+ if ( pImp->xStorage.is() )
+ {
+ //const SvStream *pStorage = aStorage->GetSvStream();
+ //if ( pStorage == pOutStream )
+ CloseStorage();
+ }
+
+ delete pOutStream;
+ pOutStream = NULL;
+ }
+
+ if ( !pInStream )
+ {
+ // input part of the stream is not used so the whole stream can be closed
+ // TODO/LATER: is it correct?
+ pImp->xStream = uno::Reference< io::XStream >();
+ if ( pSet )
+ pSet->ClearItem( SID_STREAM );
+ }
+
+ return sal_True;
+}
+
+//------------------------------------------------------------------
+const String& SfxMedium::GetPhysicalName() const
+{
+ if ( !aName.Len() && aLogicName.Len() )
+ (( SfxMedium*)this)->CreateFileStream();
+
+ // return the name then
+ return aName;
+}
+
+//------------------------------------------------------------------
+void SfxMedium::CreateFileStream()
+{
+ ForceSynchronStream_Impl( TRUE );
+ GetInStream();
+ if( pInStream )
+ {
+ CreateTempFile( sal_False );
+ pImp->bIsTemp = sal_True;
+ CloseInStream_Impl();
+ }
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::Commit()
+{
+ if( pImp->xStorage.is() )
+ StorageCommit_Impl();
+ else if( pOutStream )
+ pOutStream->Flush();
+ else if( pInStream )
+ pInStream->Flush();
+
+ if ( GetError() == SVSTREAM_OK )
+ {
+ // does something only in case there is a temporary file ( means aName points to different location than aLogicName )
+ Transfer_Impl();
+ }
+
+ sal_Bool bResult = ( GetError() == SVSTREAM_OK );
+
+ if ( bResult && DocNeedsFileDateCheck() )
+ GetInitFileDate( sal_True );
+
+ // remove truncation mode from the flags
+ nStorOpenMode &= (~STREAM_TRUNC);
+ return bResult;
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::IsStorage()
+{
+ if ( pImp->xStorage.is() )
+ return TRUE;
+
+ if ( bTriedStorage )
+ return pImp->bIsStorage;
+
+ if ( pImp->pTempFile )
+ {
+ String aURL;
+ if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aURL ) )
+ {
+ DBG_ERROR("Physical name not convertable!");
+ }
+ pImp->bIsStorage = SotStorage::IsStorageFile( aURL ) && !SotStorage::IsOLEStorage( aURL);
+ if ( !pImp->bIsStorage )
+ bTriedStorage = TRUE;
+ }
+ else if ( GetInStream() )
+ {
+ pImp->bIsStorage = SotStorage::IsStorageFile( pInStream ) && !SotStorage::IsOLEStorage( pInStream );
+ if ( !pInStream->GetError() && !pImp->bIsStorage )
+ bTriedStorage = TRUE;
+ }
+
+ return pImp->bIsStorage;
+}
+
+//------------------------------------------------------------------
+Link SfxMedium::GetDataAvailableLink() const
+{
+ return pImp->aAvailableLink.GetLink();
+}
+
+//------------------------------------------------------------------
+Link SfxMedium::GetDoneLink() const
+{
+ return pImp->aDoneLink.GetLink();
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::IsPreview_Impl()
+{
+ sal_Bool bPreview = sal_False;
+ SFX_ITEMSET_ARG( GetItemSet(), pPreview, SfxBoolItem, SID_PREVIEW, sal_False);
+ if ( pPreview )
+ bPreview = pPreview->GetValue();
+ else
+ {
+ SFX_ITEMSET_ARG( GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False);
+ if ( pFlags )
+ {
+ String aFileFlags = pFlags->GetValue();
+ aFileFlags.ToUpperAscii();
+ if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) )
+ bPreview = sal_True;
+ }
+ }
+
+ return bPreview;
+}
+
+//------------------------------------------------------------------
+void SfxMedium::StorageBackup_Impl()
+{
+ ::ucbhelper::Content aOriginalContent;
+ Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv;
+
+ sal_Bool bBasedOnOriginalFile = ( !pImp->pTempFile && !( aLogicName.Len() && pImp->m_bSalvageMode )
+ && GetURLObject().GetMainURL( INetURLObject::NO_DECODE ).getLength()
+ && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) )
+ && ::utl::UCBContentHelper::IsDocument( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) );
+
+ if ( bBasedOnOriginalFile && !pImp->m_aBackupURL.getLength()
+ && ::ucbhelper::Content::create( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, aOriginalContent ) )
+ {
+ DoInternalBackup_Impl( aOriginalContent );
+ if( !pImp->m_aBackupURL.getLength() )
+ SetError( ERRCODE_SFX_CANTCREATEBACKUP, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+}
+
+//------------------------------------------------------------------
+::rtl::OUString SfxMedium::GetBackup_Impl()
+{
+ if ( !pImp->m_aBackupURL.getLength() )
+ StorageBackup_Impl();
+
+ return pImp->m_aBackupURL;
+}
+
+//------------------------------------------------------------------
+uno::Reference < embed::XStorage > SfxMedium::GetOutputStorage()
+{
+ if ( GetError() )
+ return uno::Reference< embed::XStorage >();
+
+ // if the medium was constructed with a Storage: use this one, not a temp. storage
+ // if a temporary storage already exists: use it
+ if ( pImp->xStorage.is() && ( !aLogicName.Len() || pImp->pTempFile ) )
+ return pImp->xStorage;
+
+ // if necessary close stream that was used for reading
+ if ( pInStream && !pInStream->IsWritable() )
+ CloseInStream();
+
+ DBG_ASSERT( !pOutStream, "OutStream in a readonly Medium?!" );
+
+ // TODO/LATER: The current solution is to store the document temporary and then copy it to the target location;
+ // in future it should be stored directly and then copied to the temporary location, since in this case no
+ // file attributes have to be preserved and system copying mechanics could be used instead of streaming.
+ CreateTempFileNoCopy();
+
+ return GetStorage();
+}
+
+//------------------------------------------------------------------
+void SfxMedium::SetEncryptionDataToStorage_Impl()
+{
+ // in case media-descriptor contains password it should be used on opening
+ if ( pImp->xStorage.is() && pSet )
+ {
+ uno::Sequence< beans::NamedValue > aEncryptionData;
+ if ( GetEncryptionData_Impl( pSet, aEncryptionData ) )
+ {
+ // replace the password with encryption data
+ pSet->ClearItem( SID_PASSWORD );
+ pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) ) );
+
+ try
+ {
+ ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( pImp->xStorage, aEncryptionData );
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "It must be possible to set a common password for the storage" );
+ // TODO/LATER: set the error code in case of problem
+ // SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ }
+ }
+}
+
+//------------------------------------------------------------------
+sal_Int8 SfxMedium::ShowLockedDocumentDialog( const uno::Sequence< ::rtl::OUString >& aData, sal_Bool bIsLoading, sal_Bool bOwnLock )
+{
+ sal_Int8 nResult = LOCK_UI_NOLOCK;
+
+ // show the interaction regarding the document opening
+ uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler();
+
+ if ( ::svt::DocumentLockFile::IsInteractionAllowed() && xHandler.is() && ( bIsLoading || bOwnLock ) )
+ {
+ ::rtl::OUString aDocumentURL = GetURLObject().GetLastName();
+ ::rtl::OUString aInfo;
+ ::rtl::Reference< ::ucbhelper::InteractionRequest > xInteractionRequestImpl;
+
+ if ( bOwnLock )
+ {
+ if ( aData.getLength() > LOCKFILE_EDITTIME_ID )
+ aInfo = aData[LOCKFILE_EDITTIME_ID];
+
+ xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
+ document::OwnLockOnDocumentRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo, !bIsLoading ) ) );
+ }
+ else
+ {
+ if ( aData.getLength() > LOCKFILE_EDITTIME_ID )
+ {
+ if ( aData[LOCKFILE_OOOUSERNAME_ID].getLength() )
+ aInfo = aData[LOCKFILE_OOOUSERNAME_ID];
+ else
+ aInfo = aData[LOCKFILE_SYSUSERNAME_ID];
+
+ if ( aInfo.getLength() && aData[LOCKFILE_EDITTIME_ID].getLength() )
+ {
+ aInfo += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " ( " ) );
+ aInfo += aData[LOCKFILE_EDITTIME_ID];
+ aInfo += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " )" ) );
+ }
+ }
+
+ if ( bIsLoading )
+ {
+ xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
+ document::LockedDocumentRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) );
+ }
+ else
+ {
+ xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
+ document::LockedOnSavingRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) );
+
+ }
+ }
+
+ uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 3 );
+ aContinuations[0] = new ::ucbhelper::InteractionAbort( xInteractionRequestImpl.get() );
+ aContinuations[1] = new ::ucbhelper::InteractionApprove( xInteractionRequestImpl.get() );
+ aContinuations[2] = new ::ucbhelper::InteractionDisapprove( xInteractionRequestImpl.get() );
+ xInteractionRequestImpl->setContinuations( aContinuations );
+
+ xHandler->handle( xInteractionRequestImpl.get() );
+
+ ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xInteractionRequestImpl->getSelection();
+ if ( uno::Reference< task::XInteractionAbort >( xSelected.get(), uno::UNO_QUERY ).is() )
+ {
+ SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ else if ( uno::Reference< task::XInteractionDisapprove >( xSelected.get(), uno::UNO_QUERY ).is() )
+ {
+ // own lock on loading, user has selected to ignore the lock
+ // own lock on saving, user has selected to ignore the lock
+ // alien lock on loading, user has selected to edit a copy of document
+ // TODO/LATER: alien lock on saving, user has selected to do SaveAs to different location
+ if ( bIsLoading && !bOwnLock )
+ {
+ // means that a copy of the document should be opened
+ GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
+ }
+ else if ( bOwnLock )
+ nResult = LOCK_UI_SUCCEEDED;
+ }
+ else // if ( XSelected == aContinuations[1] )
+ {
+ // own lock on loading, user has selected to open readonly
+ // own lock on saving, user has selected to open readonly
+ // alien lock on loading, user has selected to retry saving
+ // TODO/LATER: alien lock on saving, user has selected to retry saving
+
+ if ( bIsLoading )
+ GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
+ else
+ nResult = LOCK_UI_TRY;
+ }
+ }
+ else
+ {
+ if ( bIsLoading )
+ {
+ // if no interaction handler is provided the default answer is open readonly
+ // that usually happens in case the document is loaded per API
+ // so the document must be opened readonly for backward compatibility
+ GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
+ }
+ else
+ SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+
+ }
+
+ return nResult;
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::LockOrigFileOnDemand( sal_Bool bLoading, sal_Bool bNoUI )
+{
+ // returns true if the document can be opened for editing ( even if it should be a copy )
+ // otherwise the document should be opened readonly
+ // if user cancel the loading the ERROR_ABORT is set
+
+ if ( pImp->m_bLocked && bLoading && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) )
+ {
+ // if the document is already locked the system locking might be temporarely off after storing
+ // check whether the system file locking should be taken again
+ GetLockingStream_Impl();
+ }
+
+ sal_Bool bResult = pImp->m_bLocked;
+
+ if ( !bResult )
+ {
+ // no read-write access is necessary on loading if the document is explicitly opened as copy
+ SFX_ITEMSET_ARG( GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
+ bResult = ( bLoading && pTemplateItem && pTemplateItem->GetValue() );
+ }
+
+ if ( !bResult && !IsReadOnly() )
+ {
+ sal_Bool bContentReadonly = sal_False;
+ if ( bLoading && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) )
+ {
+ // let the original document be opened to check the possibility to open it for editing
+ // and to let the writable stream stay open to hold the lock on the document
+ GetLockingStream_Impl();
+ }
+
+ // "IsReadOnly" property does not allow to detect whether the file is readonly always
+ // so we try always to open the file for editing
+ // the file is readonly only in case the read-write stream can not be opened
+ if ( bLoading && !pImp->m_xLockingStream.is() )
+ {
+ try
+ {
+ // MediaDescriptor does this check also, the duplication should be avoided in future
+ Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv;
+ ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
+ aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bContentReadonly;
+ }
+ catch( uno::Exception )
+ {}
+
+ if ( !bContentReadonly )
+ {
+ // the file is not readonly, check the ACL
+
+ String aPhysPath;
+ if ( ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), aPhysPath ) )
+ bContentReadonly = IsReadonlyAccordingACL( aPhysPath.GetBuffer() );
+ }
+ }
+
+ // do further checks only if the file not readonly in fs
+ if ( !bContentReadonly )
+ {
+ // the special file locking should be used only for file URLs
+ if ( ::utl::LocalFileHelper::IsLocalFile( aLogicName ) )
+ {
+
+ // in case of storing the document should request the output before locking
+ if ( bLoading )
+ {
+ // let the stream be opened to check the system file locking
+ GetMedium_Impl();
+ }
+
+ sal_Int8 bUIStatus = LOCK_UI_NOLOCK;
+
+ // check whether system file locking has been used, the default value is false
+ sal_Bool bUseSystemLock = IsSystemFileLockingUsed();
+
+ // TODO/LATER: This implementation does not allow to detect the system lock on saving here, actually this is no big problem
+ // if system lock is used the writeable stream should be available
+ sal_Bool bHandleSysLocked = ( bLoading && bUseSystemLock && !pImp->xStream.is() && !pOutStream );
+
+ do
+ {
+ try
+ {
+ ::svt::DocumentLockFile aLockFile( aLogicName );
+ if ( !bHandleSysLocked )
+ {
+ try
+ {
+ bResult = aLockFile.CreateOwnLockFile();
+ }
+ catch ( ucb::InteractiveIOException& e )
+ {
+ // exception means that the lock file can not be successfuly accessed
+ // in this case it should be ignored if system file locking is anyway active
+ if ( bUseSystemLock || !IsOOoLockFileUsed() )
+ {
+ bResult = sal_True;
+ // take the ownership over the lock file
+ aLockFile.OverwriteOwnLockFile();
+ }
+ else if ( e.Code == IOErrorCode_INVALID_PARAMETER )
+ {
+ // system file locking is not active, ask user whether he wants to open the document without any locking
+ uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler();
+
+ if ( xHandler.is() )
+ {
+ ::rtl::Reference< ::ucbhelper::InteractionRequest > xIgnoreRequestImpl
+ = new ::ucbhelper::InteractionRequest( uno::makeAny( document::LockFileIgnoreRequest() ) );
+
+ uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 2 );
+ aContinuations[0] = new ::ucbhelper::InteractionAbort( xIgnoreRequestImpl.get() );
+ aContinuations[1] = new ::ucbhelper::InteractionApprove( xIgnoreRequestImpl.get() );
+ xIgnoreRequestImpl->setContinuations( aContinuations );
+
+ xHandler->handle( xIgnoreRequestImpl.get() );
+
+ ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xIgnoreRequestImpl->getSelection();
+ bResult = ( uno::Reference< task::XInteractionApprove >( xSelected.get(), uno::UNO_QUERY ).is() );
+ }
+ }
+ }
+ catch ( uno::Exception& )
+ {
+ // exception means that the lock file can not be successfuly accessed
+ // in this case it should be ignored if system file locking is anyway active
+ if ( bUseSystemLock || !IsOOoLockFileUsed() )
+ {
+ bResult = sal_True;
+ // take the ownership over the lock file
+ aLockFile.OverwriteOwnLockFile();
+ }
+ }
+
+ // in case OOo locking is turned off the lock file is still written if possible
+ // but it is ignored while deciding whether the document should be opened for editing or not
+ if ( !bResult && !IsOOoLockFileUsed() )
+ {
+ bResult = sal_True;
+ // take the ownership over the lock file
+ aLockFile.OverwriteOwnLockFile();
+ }
+ }
+
+
+ if ( !bResult )
+ {
+ uno::Sequence< ::rtl::OUString > aData;
+ try
+ {
+ // impossibility to get data is no real problem
+ aData = aLockFile.GetLockData();
+ }
+ catch( uno::Exception ) {}
+
+ sal_Bool bOwnLock = sal_False;
+
+ if ( !bHandleSysLocked )
+ {
+ uno::Sequence< ::rtl::OUString > aOwnData = aLockFile.GenerateOwnEntry();
+ bOwnLock = ( aData.getLength() > LOCKFILE_USERURL_ID
+ && aOwnData.getLength() > LOCKFILE_USERURL_ID
+ && aOwnData[LOCKFILE_SYSUSERNAME_ID].equals( aData[LOCKFILE_SYSUSERNAME_ID] ) );
+
+ if ( bOwnLock
+ && aOwnData[LOCKFILE_LOCALHOST_ID].equals( aData[LOCKFILE_LOCALHOST_ID] )
+ && aOwnData[LOCKFILE_USERURL_ID].equals( aData[LOCKFILE_USERURL_ID] ) )
+ {
+ // this is own lock from the same installation, it could remain because of crash
+ bResult = sal_True;
+ }
+ }
+
+ if ( !bResult && !bNoUI )
+ {
+ bUIStatus = ShowLockedDocumentDialog( aData, bLoading, bOwnLock );
+ if ( bUIStatus == LOCK_UI_SUCCEEDED )
+ {
+ // take the ownership over the lock file
+ bResult = aLockFile.OverwriteOwnLockFile();
+ }
+ }
+
+ bHandleSysLocked = sal_False;
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+ } while( !bResult && bUIStatus == LOCK_UI_TRY );
+
+ pImp->m_bLocked = bResult;
+ }
+ else
+ {
+ // this is no file URL, check whether the file is readonly
+ bResult = !bContentReadonly;
+ }
+ }
+ }
+
+ if ( !bResult && GetError() == ERRCODE_NONE )
+ {
+ // the error should be set in case it is storing process
+ // or the document has been opened for editing explicitly
+
+ SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, FALSE );
+ if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->GetValue()) )
+ SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ else
+ GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
+ }
+
+ // when the file is locked, get the current file date
+ if ( bResult && DocNeedsFileDateCheck() )
+ GetInitFileDate( sal_True );
+
+ return bResult;
+}
+
+//------------------------------------------------------------------
+uno::Reference < embed::XStorage > SfxMedium::GetStorage( sal_Bool bCreateTempIfNo )
+{
+ if ( pImp->xStorage.is() || bTriedStorage )
+ return pImp->xStorage;
+
+ uno::Sequence< uno::Any > aArgs( 2 );
+
+ // the medium should be retrieved before temporary file creation
+ // to let the MediaDescriptor be filled with the streams
+ GetMedium_Impl();
+
+ if ( bCreateTempIfNo )
+ CreateTempFile( sal_False );
+
+ GetMedium_Impl();
+
+ if ( GetError() )
+ return pImp->xStorage;
+
+ SFX_ITEMSET_ARG( GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False);
+ if ( pRepairItem && pRepairItem->GetValue() )
+ {
+ // the storage should be created for repairing mode
+ CreateTempFile( sal_False );
+ GetMedium_Impl();
+
+ Reference< ::com::sun::star::ucb::XProgressHandler > xProgressHandler;
+ Reference< ::com::sun::star::task::XStatusIndicator > xStatusIndicator;
+
+ SFX_ITEMSET_ARG( GetItemSet(), pxProgressItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, sal_False );
+ if( pxProgressItem && ( pxProgressItem->GetValue() >>= xStatusIndicator ) )
+ xProgressHandler = Reference< ::com::sun::star::ucb::XProgressHandler >(
+ new utl::ProgressHandlerWrap( xStatusIndicator ) );
+
+ uno::Sequence< beans::PropertyValue > aAddProps( 2 );
+ aAddProps[0].Name = ::rtl::OUString::createFromAscii( "RepairPackage" );
+ aAddProps[0].Value <<= (sal_Bool)sal_True;
+ aAddProps[1].Name = ::rtl::OUString::createFromAscii( "StatusIndicator" );
+ aAddProps[1].Value <<= xProgressHandler;
+
+ // the first arguments will be filled later
+ aArgs.realloc( 3 );
+ aArgs[2] <<= aAddProps;
+ }
+
+ if ( pImp->xStream.is() )
+ {
+ // since the storage is based on temporary stream we open it always read-write
+ aArgs[0] <<= pImp->xStream;
+ aArgs[1] <<= embed::ElementModes::READWRITE;
+ pImp->bStorageBasedOnInStream = sal_True;
+ }
+ else if ( pImp->xInputStream.is() )
+ {
+ // since the storage is based on temporary stream we open it always read-write
+ aArgs[0] <<= pImp->xInputStream;
+ aArgs[1] <<= embed::ElementModes::READ;
+ pImp->bStorageBasedOnInStream = sal_True;
+ }
+ else
+ {
+ CloseStreams_Impl();
+ aArgs[0] <<= ::rtl::OUString( aName );
+ aArgs[1] <<= embed::ElementModes::READ;
+ pImp->bStorageBasedOnInStream = sal_False;
+ }
+
+ try
+ {
+ pImp->xStorage = uno::Reference< embed::XStorage >(
+ ::comphelper::OStorageHelper::GetStorageFactory()->createInstanceWithArguments( aArgs ),
+ uno::UNO_QUERY );
+ }
+ catch( uno::Exception& )
+ {
+ // impossibility to create the storage is no error
+ }
+
+ if( ( pImp->nLastStorageError = GetError() ) != SVSTREAM_OK )
+ {
+ pImp->xStorage = 0;
+ if ( pInStream )
+ pInStream->Seek(0);
+ return uno::Reference< embed::XStorage >();
+ }
+
+ bTriedStorage = sal_True;
+
+ // TODO/LATER: Get versionlist on demand
+ if ( pImp->xStorage.is() )
+ {
+ SetEncryptionDataToStorage_Impl();
+ GetVersionList();
+ }
+
+ SFX_ITEMSET_ARG( pSet, pVersion, SfxInt16Item, SID_VERSION, sal_False);
+
+ BOOL bResetStorage = FALSE;
+ if ( pVersion && pVersion->GetValue() )
+ {
+ // Alle verf"ugbaren Versionen einlesen
+ if ( pImp->aVersions.getLength() )
+ {
+ // Die zum Kommentar passende Version suchen
+ // Die Versionen sind von 1 an durchnumeriert, mit negativen
+ // Versionsnummern werden die Versionen von der aktuellen aus
+ // r"uckw"arts gez"ahlt
+ short nVersion = pVersion ? pVersion->GetValue() : 0;
+ if ( nVersion<0 )
+ nVersion = ( (short) pImp->aVersions.getLength() ) + nVersion;
+ else if ( nVersion )
+ nVersion--;
+
+ util::RevisionTag& rTag = pImp->aVersions[nVersion];
+ {
+ // SubStorage f"ur alle Versionen "offnen
+ uno::Reference < embed::XStorage > xSub = pImp->xStorage->openStorageElement( DEFINE_CONST_UNICODE( "Versions" ),
+ embed::ElementModes::READ );
+
+ DBG_ASSERT( xSub.is(), "Versionsliste, aber keine Versionen!" );
+
+ // Dort ist die Version als gepackter Stream gespeichert
+ uno::Reference < io::XStream > xStr = xSub->openStreamElement( rTag.Identifier, embed::ElementModes::READ );
+ SvStream* pStream = utl::UcbStreamHelper::CreateStream( xStr );
+ if ( pStream && pStream->GetError() == SVSTREAM_OK )
+ {
+ // Stream ins TempDir auspacken
+ ::utl::TempFile aTempFile;
+ String aTmpName = aTempFile.GetURL();
+ SvFileStream aTmpStream( aTmpName, SFX_STREAM_READWRITE );
+
+ *pStream >> aTmpStream;
+ aTmpStream.Close();
+
+ // Datei als Storage "offnen
+ nStorOpenMode = SFX_STREAM_READONLY;
+ pImp->xStorage = comphelper::OStorageHelper::GetStorageFromURL( aTmpName, embed::ElementModes::READ );
+ pImp->bStorageBasedOnInStream = sal_False;
+ String aTemp;
+ ::utl::LocalFileHelper::ConvertURLToPhysicalName( aTmpName, aTemp );
+ SetPhysicalName_Impl( aTemp );
+
+ pImp->bIsTemp = sal_True;
+ GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
+ // TODO/MBA
+ pImp->aVersions.realloc(0);
+ }
+ else
+ bResetStorage = TRUE;
+ }
+ }
+ else
+ bResetStorage = TRUE;
+ }
+
+ if ( bResetStorage )
+ {
+ pImp->xStorage = 0;
+ if ( pInStream )
+ pInStream->Seek( 0L );
+ }
+
+ pImp->bIsStorage = pImp->xStorage.is();
+ return pImp->xStorage;
+}
+
+//------------------------------------------------------------------
+uno::Reference< embed::XStorage > SfxMedium::GetZipStorageToSign_Impl( sal_Bool bReadOnly )
+{
+ if ( !GetError() && !pImp->m_xZipStorage.is() )
+ {
+ // very careful!!!
+ // if bReadOnly == sal_False and there is no temporary file the original file might be used
+ GetMedium_Impl();
+
+ try
+ {
+ // we can not sign document if there is no stream
+ // should it be possible at all?
+ if ( !bReadOnly && pImp->xStream.is() )
+ {
+ pImp->m_xZipStorage = ::comphelper::OStorageHelper::GetStorageOfFormatFromStream( ZIP_STORAGE_FORMAT_STRING, pImp->xStream, embed::ElementModes::READWRITE );
+ }
+ else if ( pImp->xInputStream.is() )
+ {
+ pImp->m_xZipStorage = ::comphelper::OStorageHelper::GetStorageOfFormatFromInputStream( ZIP_STORAGE_FORMAT_STRING, pImp->xInputStream );
+ }
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "No possibility to get readonly version of storage from medium!\n" );
+ }
+
+ if ( GetError() ) // do not remove warnings
+ ResetError();
+ }
+
+ return pImp->m_xZipStorage;
+}
+
+//------------------------------------------------------------------
+void SfxMedium::CloseZipStorage_Impl()
+{
+ if ( pImp->m_xZipStorage.is() )
+ {
+ try {
+ pImp->m_xZipStorage->dispose();
+ } catch( uno::Exception& )
+ {}
+
+ pImp->m_xZipStorage = uno::Reference< embed::XStorage >();
+ }
+}
+
+//------------------------------------------------------------------
+void SfxMedium::CloseStorage()
+{
+ if ( pImp->xStorage.is() )
+ {
+ uno::Reference < lang::XComponent > xComp( pImp->xStorage, uno::UNO_QUERY );
+ // in the salvage mode the medium does not own the storage
+ if ( pImp->bDisposeStorage && !pImp->m_bSalvageMode )
+ {
+ try {
+ xComp->dispose();
+ } catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Medium's storage is already disposed!\n" );
+ }
+ }
+
+ pImp->xStorage = 0;
+ pImp->bStorageBasedOnInStream = sal_False;
+ }
+
+ bTriedStorage = sal_False;
+ pImp->bIsStorage = sal_False;
+}
+
+void SfxMedium::CanDisposeStorage_Impl( sal_Bool bDisposeStorage )
+{
+ pImp->bDisposeStorage = bDisposeStorage;
+}
+
+sal_Bool SfxMedium::WillDisposeStorageOnClose_Impl()
+{
+ return pImp->bDisposeStorage;
+}
+
+//------------------------------------------------------------------
+void SfxMedium::SetOpenMode( StreamMode nStorOpen,
+ sal_Bool bDirectP,
+ sal_Bool bDontClose )
+{
+ if ( nStorOpenMode != nStorOpen )
+ {
+ nStorOpenMode = nStorOpen;
+
+ if( !bDontClose )
+ {
+ if ( pImp->xStorage.is() )
+ CloseStorage();
+
+ CloseStreams_Impl();
+ }
+ }
+
+ bDirect = bDirectP;
+ bSetFilter = sal_False;
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::UseBackupToRestore_Impl( ::ucbhelper::Content& aOriginalContent,
+ const Reference< ::com::sun::star::ucb::XCommandEnvironment >& xComEnv )
+{
+ try
+ {
+ ::ucbhelper::Content aTransactCont( pImp->m_aBackupURL, xComEnv );
+
+ Reference< XInputStream > aOrigInput = aTransactCont.openStream();
+ aOriginalContent.writeStream( aOrigInput, sal_True );
+ return sal_True;
+ }
+ catch( Exception& )
+ {
+ // in case of failure here the backup file should not be removed
+ // TODO/LATER: a message should be used to let user know about the backup
+ pImp->m_bRemoveBackup = sal_False;
+ // TODO/LATER: needs a specific error code
+ eError = ERRCODE_IO_GENERAL;
+ }
+
+ return sal_False;
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::StorageCommit_Impl()
+{
+ sal_Bool bResult = sal_False;
+ Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv;
+ ::ucbhelper::Content aOriginalContent;
+
+ if ( pImp->xStorage.is() )
+ {
+ if ( !GetError() )
+ {
+ uno::Reference < embed::XTransactedObject > xTrans( pImp->xStorage, uno::UNO_QUERY );
+ if ( xTrans.is() )
+ {
+ try
+ {
+ xTrans->commit();
+ CloseZipStorage_Impl();
+ bResult = sal_True;
+ }
+ catch ( embed::UseBackupException& aBackupExc )
+ {
+ // since the temporary file is created always now, the scenario is close to be impossible
+ if ( !pImp->pTempFile )
+ {
+ OSL_ENSURE( pImp->m_aBackupURL.getLength(), "No backup on storage commit!\n" );
+ if ( pImp->m_aBackupURL.getLength()
+ && ::ucbhelper::Content::create( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ),
+ xDummyEnv,
+ aOriginalContent ) )
+ {
+ // use backup to restore the file
+ // the storage has already disconnected from original location
+ CloseAndReleaseStreams_Impl();
+ if ( !UseBackupToRestore_Impl( aOriginalContent, xDummyEnv ) )
+ {
+ // connect the medium to the temporary file of the storage
+ pImp->aContent = ::ucbhelper::Content();
+ aName = aBackupExc.TemporaryFileURL;
+ OSL_ENSURE( aName.Len(), "The exception _must_ contain the temporary URL!\n" );
+ }
+ }
+
+ if ( !GetError() )
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ }
+ catch ( uno::Exception& )
+ {
+ //TODO/LATER: improve error handling
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ }
+ }
+ }
+
+ return bResult;
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource,
+ const INetURLObject& aDest,
+ const Reference< ::com::sun::star::ucb::XCommandEnvironment >& xComEnv )
+{
+ sal_Bool bResult = sal_False;
+ Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv;
+ Reference< XOutputStream > aDestStream;
+ ::ucbhelper::Content aOriginalContent;
+
+ try
+ {
+ aOriginalContent = ::ucbhelper::Content( aDest.GetMainURL( INetURLObject::NO_DECODE ), xComEnv );
+ }
+ catch ( ::com::sun::star::ucb::CommandAbortedException& )
+ {
+ eError = ERRCODE_ABORT;
+ }
+ catch ( ::com::sun::star::ucb::CommandFailedException& )
+ {
+ eError = ERRCODE_ABORT;
+ }
+ catch (const ::com::sun::star::ucb::ContentCreationException& ex)
+ {
+ eError = ERRCODE_IO_GENERAL;
+ if (
+ (ex.eError == ::com::sun::star::ucb::ContentCreationError_NO_CONTENT_PROVIDER ) ||
+ (ex.eError == ::com::sun::star::ucb::ContentCreationError_CONTENT_CREATION_FAILED)
+ )
+ {
+ eError = ERRCODE_IO_NOTEXISTSPATH;
+ }
+ }
+ catch (const ::com::sun::star::uno::Exception&)
+ {
+ eError = ERRCODE_IO_GENERAL;
+ }
+
+ if( !eError || (eError & ERRCODE_WARNING_MASK) )
+ {
+ if ( pImp->xStorage.is() )
+ CloseStorage();
+
+ CloseStreams_Impl();
+
+ ::ucbhelper::Content aTempCont;
+ if( ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, aTempCont ) )
+ {
+ sal_Bool bTransactStarted = sal_False;
+ SFX_ITEMSET_ARG( GetItemSet(), pOverWrite, SfxBoolItem, SID_OVERWRITE, sal_False );
+ SFX_ITEMSET_ARG( GetItemSet(), pRename, SfxBoolItem, SID_RENAME, sal_False );
+ sal_Bool bRename = pRename ? pRename->GetValue() : FALSE;
+ sal_Bool bOverWrite = pOverWrite ? pOverWrite->GetValue() : !bRename;
+
+ try
+ {
+ if( bOverWrite && ::utl::UCBContentHelper::IsDocument( aDest.GetMainURL( INetURLObject::NO_DECODE ) ) )
+ {
+ if( ! pImp->m_aBackupURL.getLength() )
+ DoInternalBackup_Impl( aOriginalContent );
+
+ if( pImp->m_aBackupURL.getLength() )
+ {
+ Reference< XInputStream > aTempInput = aTempCont.openStream();
+ bTransactStarted = sal_True;
+ aOriginalContent.setPropertyValue( ::rtl::OUString::createFromAscii( "Size" ),
+ uno::makeAny( (sal_Int64)0 ) );
+ aOriginalContent.writeStream( aTempInput, bOverWrite );
+ bResult = sal_True;
+ }
+ else
+ {
+ eError = ERRCODE_SFX_CANTCREATEBACKUP;
+ }
+ }
+ else
+ {
+ Reference< XInputStream > aTempInput = aTempCont.openStream();
+ aOriginalContent.writeStream( aTempInput, bOverWrite );
+ bResult = sal_True;
+ }
+ }
+ catch ( ::com::sun::star::ucb::CommandAbortedException& )
+ {
+ eError = ERRCODE_ABORT;
+ }
+ catch ( ::com::sun::star::ucb::CommandFailedException& )
+ {
+ eError = ERRCODE_ABORT;
+ }
+ catch ( ::com::sun::star::ucb::InteractiveIOException& r )
+ {
+ if ( r.Code == IOErrorCode_ACCESS_DENIED )
+ eError = ERRCODE_IO_ACCESSDENIED;
+ else if ( r.Code == IOErrorCode_NOT_EXISTING )
+ eError = ERRCODE_IO_NOTEXISTS;
+ else if ( r.Code == IOErrorCode_CANT_READ )
+ eError = ERRCODE_IO_CANTREAD;
+ else
+ eError = ERRCODE_IO_GENERAL;
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ eError = ERRCODE_IO_GENERAL;
+ }
+
+ if ( bResult )
+ {
+ if ( pImp->pTempFile )
+ {
+ pImp->pTempFile->EnableKillingFile( sal_True );
+ delete pImp->pTempFile;
+ pImp->pTempFile = NULL;
+ }
+ }
+ else if ( bTransactStarted )
+ {
+ UseBackupToRestore_Impl( aOriginalContent, xDummyEnv );
+ }
+ }
+ else
+ eError = ERRCODE_IO_CANTREAD;
+ }
+
+ return bResult;
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::TryDirectTransfer( const ::rtl::OUString& aURL, SfxItemSet& aTargetSet )
+{
+ if ( GetError() )
+ return sal_False;
+
+ // if the document had no password it should be stored without password
+ // if the document had password it should be stored with the same password
+ // otherwise the stream copying can not be done
+ SFX_ITEMSET_ARG( &aTargetSet, pNewPassItem, SfxStringItem, SID_PASSWORD, sal_False );
+ SFX_ITEMSET_ARG( GetItemSet(), pOldPassItem, SfxStringItem, SID_PASSWORD, sal_False );
+ if ( ( !pNewPassItem && !pOldPassItem )
+ || ( pNewPassItem && pOldPassItem && pNewPassItem->GetValue().Equals( pOldPassItem->GetValue() ) ) )
+ {
+ // the filter must be the same
+ SFX_ITEMSET_ARG( &aTargetSet, pNewFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
+ SFX_ITEMSET_ARG( GetItemSet(), pOldFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
+ if ( pNewFilterItem && pOldFilterItem && pNewFilterItem->GetValue().Equals( pOldFilterItem->GetValue() ) )
+ {
+ // get the input stream and copy it
+ // in case of success return true
+ uno::Reference< io::XInputStream > xInStream = GetInputStream();
+
+ ResetError();
+ if ( xInStream.is() )
+ {
+ try
+ {
+ uno::Reference< io::XSeekable > xSeek( xInStream, uno::UNO_QUERY );
+ sal_Int64 nPos = 0;
+ if ( xSeek.is() )
+ {
+ nPos = xSeek->getPosition();
+ xSeek->seek( 0 );
+ }
+
+ uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv;
+ ::ucbhelper::Content aTargetContent( aURL, xEnv );
+
+ InsertCommandArgument aInsertArg;
+ aInsertArg.Data = xInStream;
+ SFX_ITEMSET_ARG( &aTargetSet, pRename, SfxBoolItem, SID_RENAME, sal_False );
+ SFX_ITEMSET_ARG( &aTargetSet, pOverWrite, SfxBoolItem, SID_OVERWRITE, sal_False );
+ if ( (pOverWrite && !pOverWrite->GetValue()) // argument says: never overwrite
+ || (pRename && pRename->GetValue()) ) // argument says: rename file
+ aInsertArg.ReplaceExisting = sal_False;
+ else
+ aInsertArg.ReplaceExisting = sal_True; // default is overwrite existing files
+
+ Any aCmdArg;
+ aCmdArg <<= aInsertArg;
+ aTargetContent.executeCommand( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
+ aCmdArg );
+
+ if ( xSeek.is() )
+ xSeek->seek( nPos );
+
+ return sal_True;
+ }
+ catch( uno::Exception& )
+ {}
+ }
+ }
+ }
+
+ return sal_False;
+}
+
+//------------------------------------------------------------------
+void SfxMedium::Transfer_Impl()
+{
+ // The transfer is required only in two cases: either if there is a temporary file or if there is a salvage item
+ String aNameURL;
+ if ( pImp->pTempFile )
+ aNameURL = pImp->pTempFile->GetURL();
+ else if ( aLogicName.Len() && pImp->m_bSalvageMode )
+ {
+ // makes sence only in case logic name is set
+ if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aNameURL ) )
+ OSL_ENSURE( sal_False, "The medium name is not convertable!\n" );
+ }
+
+ if ( aNameURL.Len() && ( !eError || (eError & ERRCODE_WARNING_MASK) ) )
+ {
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxMedium::Transfer_Impl, copying to target" );
+
+ Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv;
+ Reference< XOutputStream > rOutStream;
+
+ // in case an output stream is provided from outside and the URL is correct
+ // commit to the stream
+ if( aLogicName.CompareToAscii( "private:stream", 14 ) == COMPARE_EQUAL )
+ {
+ // TODO/LATER: support storing to SID_STREAM
+ SFX_ITEMSET_ARG( pSet, pOutStreamItem, SfxUnoAnyItem, SID_OUTPUTSTREAM, sal_False);
+ if( pOutStreamItem && ( pOutStreamItem->GetValue() >>= rOutStream ) )
+ {
+ if ( pImp->xStorage.is() )
+ CloseStorage();
+
+ CloseStreams_Impl();
+
+ INetURLObject aSource( aNameURL );
+ ::ucbhelper::Content aTempCont;
+ if( ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aTempCont ) )
+ {
+ try
+ {
+ sal_Int32 nRead;
+ sal_Int32 nBufferSize = 32767;
+ Sequence < sal_Int8 > aSequence ( nBufferSize );
+ Reference< XInputStream > aTempInput = aTempCont.openStream();
+
+ do
+ {
+ nRead = aTempInput->readBytes ( aSequence, nBufferSize );
+ if ( nRead < nBufferSize )
+ {
+ Sequence < sal_Int8 > aTempBuf ( aSequence.getConstArray(), nRead );
+ rOutStream->writeBytes ( aTempBuf );
+ }
+ else
+ rOutStream->writeBytes ( aSequence );
+ }
+ while ( nRead == nBufferSize );
+
+ // remove temporary file
+ if ( pImp->pTempFile )
+ {
+ pImp->pTempFile->EnableKillingFile( sal_True );
+ delete pImp->pTempFile;
+ pImp->pTempFile = NULL;
+ }
+ }
+ catch( Exception& )
+ {}
+ }
+ }
+ else
+ {
+ DBG_ERROR( "Illegal Output stream parameter!\n" );
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+
+ // free the reference
+ if ( pSet )
+ pSet->ClearItem( SID_OUTPUTSTREAM );
+
+ return;
+ }
+
+ GetContent();
+ if ( !pImp->aContent.get().is() )
+ {
+ eError = ERRCODE_IO_NOTEXISTS;
+ return;
+ }
+
+ SFX_ITEMSET_ARG( GetItemSet(), pSegmentSize, SfxInt32Item, SID_SEGMENTSIZE, sal_False);
+ if ( pSegmentSize )
+ {
+ // this file must be stored into a disk spanned package
+ try
+ {
+ uno::Reference < embed::XStorage > xStor = comphelper::OStorageHelper::GetStorageFromURL( GetName(),
+ embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
+
+ // set segment size property; package will automatically be divided in pieces fitting
+ // into this size
+ ::com::sun::star::uno::Any aAny;
+ aAny <<= pSegmentSize->GetValue();
+
+ uno::Reference < beans::XPropertySet > xSet( pImp->xStorage, uno::UNO_QUERY );
+ xSet->setPropertyValue( String::CreateFromAscii("SegmentSize"), aAny );
+
+ // copy the temporary storage into the disk spanned package
+ GetStorage()->copyToStorage( xStor );
+ uno::Reference < embed::XTransactedObject > xTrans( pImp->xStorage, uno::UNO_QUERY );
+ if ( xTrans.is() )
+ xTrans->commit();
+
+ }
+ catch ( uno::Exception& )
+ {
+ //TODO/MBA: error handling
+ }
+ return;
+ }
+
+ INetURLObject aDest( GetURLObject() );
+
+ // source is the temp file written so far
+ INetURLObject aSource( aNameURL );
+
+ // a special case, an interaction handler should be used for
+ // authentication in case it is available
+ Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv;
+ Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = GetInteractionHandler();
+ if (xInteractionHandler.is())
+ xComEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler,
+ Reference< ::com::sun::star::ucb::XProgressHandler >() );
+
+ if ( ::utl::LocalFileHelper::IsLocalFile( aDest.GetMainURL( INetURLObject::NO_DECODE ) ) || !aDest.removeSegment() )
+ {
+ TransactedTransferForFS_Impl( aSource, aDest, xComEnv );
+ }
+ else
+ {
+ // create content for the parent folder and call transfer on that content with the source content
+ // and the destination file name as parameters
+ ::ucbhelper::Content aSourceContent;
+ ::ucbhelper::Content aTransferContent;
+
+ String aFileName = GetLongName();
+ if ( !aFileName.Len() )
+ aFileName = GetURLObject().getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+
+ try
+ {
+ aTransferContent = ::ucbhelper::Content( aDest.GetMainURL( INetURLObject::NO_DECODE ), xComEnv );
+ }
+ catch (const ::com::sun::star::ucb::ContentCreationException& ex)
+ {
+ eError = ERRCODE_IO_GENERAL;
+ if (
+ (ex.eError == ::com::sun::star::ucb::ContentCreationError_NO_CONTENT_PROVIDER ) ||
+ (ex.eError == ::com::sun::star::ucb::ContentCreationError_CONTENT_CREATION_FAILED)
+ )
+ {
+ eError = ERRCODE_IO_NOTEXISTSPATH;
+ }
+ }
+ catch (const ::com::sun::star::uno::Exception&)
+ {
+ eError = ERRCODE_IO_GENERAL;
+ }
+
+ if ( !eError || (eError & ERRCODE_WARNING_MASK) )
+ {
+ // free resources, otherwise the transfer may fail
+ if ( pImp->xStorage.is() )
+ CloseStorage();
+
+ CloseStreams_Impl();
+
+ ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aSourceContent );
+
+ // check for external parameters that may customize the handling of NameClash situations
+ SFX_ITEMSET_ARG( GetItemSet(), pRename, SfxBoolItem, SID_RENAME, sal_False );
+ SFX_ITEMSET_ARG( GetItemSet(), pOverWrite, SfxBoolItem, SID_OVERWRITE, sal_False );
+ sal_Int32 nNameClash;
+ if ( pOverWrite && !pOverWrite->GetValue() )
+ // argument says: never overwrite
+ nNameClash = NameClash::ERROR;
+ else if ( pRename && pRename->GetValue() )
+ // argument says: rename file
+ nNameClash = NameClash::RENAME;
+ else
+ // default is overwrite existing files
+ nNameClash = NameClash::OVERWRITE;
+
+ try
+ {
+ if (!aTransferContent.transferContent( aSourceContent, ::ucbhelper::InsertOperation_COPY, aFileName, nNameClash ))
+ eError = ERRCODE_IO_GENERAL;
+ }
+ catch ( ::com::sun::star::ucb::CommandAbortedException& )
+ {
+ eError = ERRCODE_ABORT;
+ }
+ catch ( ::com::sun::star::ucb::CommandFailedException& )
+ {
+ eError = ERRCODE_ABORT;
+ }
+ catch ( ::com::sun::star::ucb::InteractiveIOException& r )
+ {
+ if ( r.Code == IOErrorCode_ACCESS_DENIED )
+ eError = ERRCODE_IO_ACCESSDENIED;
+ else if ( r.Code == IOErrorCode_NOT_EXISTING )
+ eError = ERRCODE_IO_NOTEXISTS;
+ else if ( r.Code == IOErrorCode_CANT_READ )
+ eError = ERRCODE_IO_CANTREAD;
+ else
+ eError = ERRCODE_IO_GENERAL;
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ eError = ERRCODE_IO_GENERAL;
+ }
+
+ // do not switch from temporary file in case of nonfile protocol
+ }
+ }
+
+ if ( ( !eError || (eError & ERRCODE_WARNING_MASK) ) && !pImp->pTempFile )
+ {
+ // without a TempFile the physical and logical name should be the same after successful transfer
+ ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ),
+ aName );
+ pImp->m_bSalvageMode = sal_False;
+ }
+ }
+}
+
+//------------------------------------------------------------------
+void SfxMedium::DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent,
+ const String& aPrefix,
+ const String& aExtension,
+ const String& aDestDir )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxMedium::DoInternalBackup_Impl( with destdir )" );
+
+ if ( pImp->m_aBackupURL.getLength() )
+ return; // the backup was done already
+
+ ::utl::TempFile aTransactTemp( aPrefix, &aExtension, &aDestDir );
+ aTransactTemp.EnableKillingFile( sal_False );
+
+ INetURLObject aBackObj( aTransactTemp.GetURL() );
+ ::rtl::OUString aBackupName = aBackObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+
+ Reference < ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv;
+ ::ucbhelper::Content aBackupCont;
+ if( ::ucbhelper::Content::create( aDestDir, xDummyEnv, aBackupCont ) )
+ {
+ try
+ {
+ if( aBackupCont.transferContent( aOriginalContent,
+ ::ucbhelper::InsertOperation_COPY,
+ aBackupName,
+ NameClash::OVERWRITE ) )
+ {
+ pImp->m_aBackupURL = aBackObj.GetMainURL( INetURLObject::NO_DECODE );
+ pImp->m_bRemoveBackup = sal_True;
+ }
+ }
+ catch( Exception& )
+ {}
+ }
+
+ if ( !pImp->m_aBackupURL.getLength() )
+ aTransactTemp.EnableKillingFile( sal_True );
+}
+
+//------------------------------------------------------------------
+void SfxMedium::DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent )
+{
+ if ( pImp->m_aBackupURL.getLength() )
+ return; // the backup was done already
+
+ ::rtl::OUString aFileName = GetURLObject().getName( INetURLObject::LAST_SEGMENT,
+ true,
+ INetURLObject::NO_DECODE );
+
+ sal_Int32 nPrefixLen = aFileName.lastIndexOf( '.' );
+ String aPrefix = ( nPrefixLen == -1 ) ? aFileName : aFileName.copy( 0, nPrefixLen );
+ String aExtension = ( nPrefixLen == -1 ) ? String() : String(aFileName.copy( nPrefixLen ));
+ String aBakDir = SvtPathOptions().GetBackupPath();
+
+ DoInternalBackup_Impl( aOriginalContent, aPrefix, aExtension, aBakDir );
+
+ if ( !pImp->m_aBackupURL.getLength() )
+ {
+ // the copiing to the backup catalog failed ( for example because
+ // of using an encrypted partition as target catalog )
+ // since the user did not specify to make backup explicitly
+ // office should try to make backup in another place,
+ // target catalog does not look bad for this case ( and looks
+ // to be the only way for encrypted partitions )
+
+ INetURLObject aDest = GetURLObject();
+ if ( aDest.removeSegment() )
+ DoInternalBackup_Impl( aOriginalContent, aPrefix, aExtension, aDest.GetMainURL( INetURLObject::NO_DECODE ) );
+ }
+}
+
+
+//------------------------------------------------------------------
+void SfxMedium::DoBackup_Impl()
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxMedium::DoBackup_Impl" );
+
+ // source file name is the logical name of this medium
+ INetURLObject aSource( GetURLObject() );
+
+ // there is nothing to backup in case source file does not exist
+ if ( !::utl::UCBContentHelper::IsDocument( aSource.GetMainURL( INetURLObject::NO_DECODE ) ) )
+ return;
+
+ sal_Bool bSuccess = sal_False;
+
+ // get path for backups
+ String aBakDir = SvtPathOptions().GetBackupPath();
+ if( aBakDir.Len() )
+ {
+ // create content for the parent folder ( = backup folder )
+ ::ucbhelper::Content aContent;
+ Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv;
+ if( ::ucbhelper::Content::create( aBakDir, xEnv, aContent ) )
+ {
+ // save as ".bak" file
+ INetURLObject aDest( aBakDir );
+ aDest.insertName( aSource.getName() );
+ aDest.setExtension( DEFINE_CONST_UNICODE( "bak" ) );
+ String aFileName = aDest.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+
+ // create a content for the source file
+ ::ucbhelper::Content aSourceContent;
+ if ( ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aSourceContent ) )
+ {
+ try
+ {
+ // do the transfer ( copy source file to backup dir )
+ bSuccess = aContent.transferContent( aSourceContent,
+ ::ucbhelper::InsertOperation_COPY,
+ aFileName,
+ NameClash::OVERWRITE );
+ if( bSuccess )
+ {
+ pImp->m_aBackupURL = aDest.GetMainURL( INetURLObject::NO_DECODE );
+ pImp->m_bRemoveBackup = sal_False;
+ }
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ }
+ }
+ }
+ }
+
+ if ( !bSuccess )
+ {
+ eError = ERRCODE_SFX_CANTCREATEBACKUP;
+ }
+}
+
+//------------------------------------------------------------------
+void SfxMedium::ClearBackup_Impl()
+{
+ if( pImp->m_bRemoveBackup )
+ {
+ // currently a document is always stored in a new medium,
+ // thus if a backup can not be removed the backup URL should not be cleaned
+ if ( pImp->m_aBackupURL.getLength() )
+ {
+ if ( ::utl::UCBContentHelper::Kill( pImp->m_aBackupURL ) )
+ // || !::utl::UCBContentHelper::IsDocument( pImp->m_aBackupURL ) );
+ {
+ pImp->m_bRemoveBackup = sal_False;
+ pImp->m_aBackupURL = ::rtl::OUString();
+ }
+ else
+ {
+
+ DBG_ERROR("Couldn't remove backup file!");
+ }
+ }
+ }
+ else
+ pImp->m_aBackupURL = ::rtl::OUString();
+}
+
+//----------------------------------------------------------------
+void SfxMedium::GetLockingStream_Impl()
+{
+ if ( ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) )
+ && !pImp->m_xLockingStream.is() )
+ {
+ SFX_ITEMSET_ARG( pSet, pWriteStreamItem, SfxUnoAnyItem, SID_STREAM, sal_False);
+ if ( pWriteStreamItem )
+ pWriteStreamItem->GetValue() >>= pImp->m_xLockingStream;
+
+ if ( !pImp->m_xLockingStream.is() )
+ {
+ // open the original document
+ uno::Sequence< beans::PropertyValue > xProps;
+ TransformItems( SID_OPENDOC, *GetItemSet(), xProps );
+ comphelper::MediaDescriptor aMedium( xProps );
+
+ aMedium.addInputStreamOwnLock();
+
+ uno::Reference< io::XInputStream > xInputStream;
+ aMedium[comphelper::MediaDescriptor::PROP_STREAM()] >>= pImp->m_xLockingStream;
+ aMedium[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream;
+
+ if ( !pImp->pTempFile && !aName.Len() )
+ {
+ // the medium is still based on the original file, it makes sence to initialize the streams
+ if ( pImp->m_xLockingStream.is() )
+ pImp->xStream = pImp->m_xLockingStream;
+
+ if ( xInputStream.is() )
+ pImp->xInputStream = xInputStream;
+
+ if ( !pImp->xInputStream.is() && pImp->xStream.is() )
+ pImp->xInputStream = pImp->xStream->getInputStream();
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------
+void SfxMedium::GetMedium_Impl()
+{
+ if ( !pInStream )
+ {
+ pImp->bDownloadDone = sal_False;
+ Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = GetInteractionHandler();
+
+ //TODO/MBA: need support for SID_STREAM
+ SFX_ITEMSET_ARG( pSet, pWriteStreamItem, SfxUnoAnyItem, SID_STREAM, sal_False);
+ SFX_ITEMSET_ARG( pSet, pInStreamItem, SfxUnoAnyItem, SID_INPUTSTREAM, sal_False);
+ if ( pWriteStreamItem )
+ {
+ pWriteStreamItem->GetValue() >>= pImp->xStream;
+
+ if ( pInStreamItem )
+ pInStreamItem->GetValue() >>= pImp->xInputStream;
+
+ if ( !pImp->xInputStream.is() && pImp->xStream.is() )
+ pImp->xInputStream = pImp->xStream->getInputStream();
+ }
+ else if ( pInStreamItem )
+ {
+ pInStreamItem->GetValue() >>= pImp->xInputStream;
+ }
+ else
+ {
+ uno::Sequence < beans::PropertyValue > xProps;
+ String aFileName;
+ if ( aName.Len() )
+ {
+ if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aFileName ) )
+ {
+ DBG_ERROR("Physical name not convertable!");
+ }
+ }
+ else
+ aFileName = GetName();
+
+ // in case the temporary file exists the streams should be initialized from it,
+ // but the original MediaDescriptor should not be changed
+ sal_Bool bFromTempFile = ( pImp->pTempFile != NULL );
+
+ if ( !bFromTempFile )
+ {
+ GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, aFileName ) );
+ if( !(nStorOpenMode & STREAM_WRITE ) )
+ GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, TRUE ) );
+ if (xInteractionHandler.is())
+ GetItemSet()->Put( SfxUnoAnyItem( SID_INTERACTIONHANDLER, makeAny(xInteractionHandler) ) );
+ }
+
+ if ( m_xInputStreamToLoadFrom.is() )
+ {
+ pImp->xInputStream = m_xInputStreamToLoadFrom;
+ pImp->xInputStream->skipBytes(0);
+ if(m_bIsReadOnly)
+ GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
+
+ // m_xInputStreamToLoadFrom = 0;
+ }
+ else
+ {
+ TransformItems( SID_OPENDOC, *GetItemSet(), xProps );
+ comphelper::MediaDescriptor aMedium( xProps );
+
+ if ( pImp->m_xLockingStream.is() && !bFromTempFile )
+ {
+ // the medium is not based on the temporary file, so the original stream can be used
+ pImp->xStream = pImp->m_xLockingStream;
+ }
+ else
+ {
+ if ( bFromTempFile )
+ {
+ aMedium[comphelper::MediaDescriptor::PROP_URL()] <<= ::rtl::OUString( aFileName );
+ aMedium.erase( comphelper::MediaDescriptor::PROP_READONLY() );
+ aMedium.addInputStream();
+ }
+ else if ( ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) )
+ {
+ // use the special locking approach only for file URLs
+ aMedium.addInputStreamOwnLock();
+ }
+ else
+ aMedium.addInputStream();
+
+ // the ReadOnly property set in aMedium is ignored
+ // the check is done in LockOrigFileOnDemand() for file and non-file URLs
+
+ //TODO/MBA: what happens if property is not there?!
+ aMedium[comphelper::MediaDescriptor::PROP_STREAM()] >>= pImp->xStream;
+ aMedium[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= pImp->xInputStream;
+ }
+
+ GetContent();
+ if ( !pImp->xInputStream.is() && pImp->xStream.is() )
+ pImp->xInputStream = pImp->xStream->getInputStream();
+ }
+
+ if ( !bFromTempFile )
+ {
+ //TODO/MBA: need support for SID_STREAM
+ if ( pImp->xStream.is() )
+ GetItemSet()->Put( SfxUsrAnyItem( SID_STREAM, makeAny( pImp->xStream ) ) );
+
+ GetItemSet()->Put( SfxUsrAnyItem( SID_INPUTSTREAM, makeAny( pImp->xInputStream ) ) );
+ }
+ }
+
+ //TODO/MBA: ErrorHandling - how to transport error from MediaDescriptor
+ if ( !GetError() && !pImp->xStream.is() && !pImp->xInputStream.is() )
+ SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+
+ if ( !GetError() )
+ {
+ if ( pImp->xStream.is() )
+ pInStream = utl::UcbStreamHelper::CreateStream( pImp->xStream );
+ else if ( pImp->xInputStream.is() )
+ pInStream = utl::UcbStreamHelper::CreateStream( pImp->xInputStream );
+ }
+
+ pImp->bDownloadDone = sal_True;
+ pImp->aDoneLink.ClearPendingCall();
+ pImp->aDoneLink.Call( (void*) GetError() );
+ }
+}
+
+//----------------------------------------------------------------
+sal_Bool SfxMedium::IsRemote()
+{
+ return bRemote;
+}
+
+//------------------------------------------------------------------
+
+void SfxMedium::SetUpdatePickList(sal_Bool bVal)
+{
+ if(!pImp)
+ pImp = new SfxMedium_Impl( this );
+ pImp->bUpdatePickList = bVal;
+}
+//------------------------------------------------------------------
+
+sal_Bool SfxMedium::IsUpdatePickList() const
+{
+ return pImp? pImp->bUpdatePickList: sal_True;
+}
+//----------------------------------------------------------------
+
+void SfxMedium::SetDoneLink( const Link& rLink )
+{
+ pImp->aDoneLink = rLink;
+}
+
+//----------------------------------------------------------------
+
+void SfxMedium::SetDataAvailableLink( const Link& rLink )
+{
+ pImp->aAvailableLink = rLink;
+}
+
+//----------------------------------------------------------------
+void SfxMedium::StartDownload()
+{
+ GetInStream();
+}
+
+void SfxMedium::DownLoad( const Link& aLink )
+{
+ SetDoneLink( aLink );
+ GetInStream();
+ if ( pInStream && !aLink.IsSet() )
+ {
+ while( !pImp->bDownloadDone )
+ Application::Yield();
+ }
+}
+
+//------------------------------------------------------------------
+void SfxMedium::Init_Impl()
+/* [Beschreibung]
+ Setzt in den Logischen Namen eine gueltige ::com::sun::star::util::URL (Falls zuvor ein Filename
+ drin war) und setzt den physikalschen Namen auf den Filenamen, falls
+ vorhanden.
+ */
+
+{
+ Reference< XOutputStream > rOutStream;
+
+ // TODO/LATER: handle lifetime of storages
+ pImp->bDisposeStorage = FALSE;
+
+ SFX_ITEMSET_ARG( pSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
+ if ( pSalvageItem && !pSalvageItem->GetValue().Len() )
+ {
+ pSalvageItem = NULL;
+ pSet->ClearItem( SID_DOC_SALVAGE );
+ }
+
+ if( aLogicName.Len() )
+ {
+ INetURLObject aUrl( aLogicName );
+ INetProtocol eProt = aUrl.GetProtocol();
+ if ( eProt == INET_PROT_NOT_VALID )
+ {
+ DBG_ERROR ( "Unknown protocol!" );
+ }
+ else
+ {
+ if ( aUrl.HasMark() )
+ {
+ aLogicName = aUrl.GetURLNoMark( INetURLObject::NO_DECODE );
+ GetItemSet()->Put( SfxStringItem( SID_JUMPMARK, aUrl.GetMark() ) );
+ }
+
+ // try to convert the URL into a physical name - but never change a physical name
+ // physical name may be set if the logical name is changed after construction
+ if ( !aName.Len() )
+ ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), aName );
+ else {
+ DBG_ASSERT( pSalvageItem, "Suspicious change of logical name!" );
+ }
+ }
+ }
+
+ if ( pSalvageItem && pSalvageItem->GetValue().Len() )
+ {
+ aLogicName = pSalvageItem->GetValue();
+ DELETEZ( pURLObj );
+ pImp->m_bSalvageMode = sal_True;
+ }
+
+ // in case output stream is by mistake here
+ // clear the reference
+ SFX_ITEMSET_ARG( pSet, pOutStreamItem, SfxUnoAnyItem, SID_OUTPUTSTREAM, sal_False);
+ if( pOutStreamItem
+ && ( !( pOutStreamItem->GetValue() >>= rOutStream )
+ || !aLogicName.CompareToAscii( "private:stream", 14 ) == COMPARE_EQUAL ) )
+ {
+ pSet->ClearItem( SID_OUTPUTSTREAM );
+ DBG_ERROR( "Unexpected Output stream parameter!\n" );
+ }
+
+ if ( aLogicName.Len() )
+ {
+ // if the logic name is set it should be set in MediaDescriptor as well
+ SFX_ITEMSET_ARG( pSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, FALSE );
+ if ( !pFileNameItem )
+ {
+ // let the ItemSet be created if necessary
+ GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, INetURLObject( aLogicName ).GetMainURL( INetURLObject::NO_DECODE ) ) );
+ }
+ }
+
+ SetIsRemote_Impl();
+}
+
+//------------------------------------------------------------------
+SfxMedium::SfxMedium()
+: IMPL_CTOR( sal_False, 0 ), // bRoot, pURLObj
+
+ pFilter(0),
+ pSet(0),
+ pImp(new SfxMedium_Impl( this ))
+{
+ Init_Impl();
+}
+//------------------------------------------------------------------
+
+SfxMedium::SfxMedium( const SfxMedium& rMedium, sal_Bool bTemporary )
+: SvRefBase(),
+ IMPL_CTOR( sal_True, // bRoot, pURLObj
+ rMedium.pURLObj ? new INetURLObject(*rMedium.pURLObj) : 0 ),
+ pImp(new SfxMedium_Impl( this ))
+{
+ bDirect = rMedium.IsDirect();
+ nStorOpenMode = rMedium.GetOpenMode();
+ if ( !bTemporary )
+ aName = rMedium.aName;
+
+ pImp->bIsTemp = bTemporary;
+ DBG_ASSERT( ! rMedium.pImp->bIsTemp, "Temporaeres Medium darf nicht kopiert werden" );
+ aLogicName = rMedium.aLogicName;
+ pSet = rMedium.GetItemSet() ? new SfxItemSet(*rMedium.GetItemSet()) : 0;
+ pFilter = rMedium.pFilter;
+ Init_Impl();
+ if( bTemporary )
+ CreateTempFile( sal_True );
+}
+
+//------------------------------------------------------------------
+
+void SfxMedium::UseInteractionHandler( BOOL bUse )
+{
+ pImp->bAllowDefaultIntHdl = bUse;
+}
+
+//------------------------------------------------------------------
+
+::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >
+SfxMedium::GetInteractionHandler()
+{
+ // if interaction isnt allowed explicitly ... return empty reference!
+ if ( !pImp->bUseInteractionHandler )
+ return ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >();
+
+ // search a possible existing handler inside cached item set
+ if ( pSet )
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xHandler;
+ SFX_ITEMSET_ARG( pSet, pHandler, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False);
+ if ( pHandler && (pHandler->GetValue() >>= xHandler) && xHandler.is() )
+ return xHandler;
+ }
+
+ // if default interaction isnt allowed explicitly ... return empty reference!
+ if ( !pImp->bAllowDefaultIntHdl )
+ return ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >();
+
+ // otherwhise return cached default handler ... if it exist.
+ if ( pImp->xInteraction.is() )
+ return pImp->xInteraction;
+
+ // create default handler and cache it!
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
+ if ( xFactory.is() )
+ {
+ pImp->xInteraction = ::com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler >( xFactory->createInstance( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ), ::com::sun::star::uno::UNO_QUERY );
+ return pImp->xInteraction;
+ }
+
+ return ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >();
+}
+
+//----------------------------------------------------------------
+
+void SfxMedium::SetFilter( const SfxFilter* pFilterP, sal_Bool /*bResetOrig*/ )
+{
+ pFilter = pFilterP;
+ pImp->nFileVersion = 0;
+}
+
+//----------------------------------------------------------------
+
+const SfxFilter* SfxMedium::GetOrigFilter( sal_Bool bNotCurrent ) const
+{
+ return ( pImp->pOrigFilter || bNotCurrent ) ? pImp->pOrigFilter : pFilter;
+}
+
+//----------------------------------------------------------------
+
+void SfxMedium::SetOrigFilter_Impl( const SfxFilter* pOrigFilter )
+{
+ pImp->pOrigFilter = pOrigFilter;
+}
+
+//------------------------------------------------------------------
+
+sal_uInt32 SfxMedium::CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bWriter )
+{
+ sal_uInt32 nHash = 0;
+
+ if ( aPasswd.getLength() )
+ {
+ if ( bWriter )
+ {
+ nHash = ::comphelper::DocPasswordHelper::GetWordHashAsUINT32( aPasswd );
+ }
+ else
+ {
+ rtl_TextEncoding nEncoding = RTL_TEXTENCODING_UTF8;
+
+ // if the MS-filter should be used
+ // use the inconsistent algorithm to find the encoding specified by MS
+ nEncoding = osl_getThreadTextEncoding();
+ switch( nEncoding )
+ {
+ case RTL_TEXTENCODING_ISO_8859_15:
+ case RTL_TEXTENCODING_MS_874:
+ case RTL_TEXTENCODING_MS_1250:
+ case RTL_TEXTENCODING_MS_1251:
+ case RTL_TEXTENCODING_MS_1252:
+ case RTL_TEXTENCODING_MS_1253:
+ case RTL_TEXTENCODING_MS_1254:
+ case RTL_TEXTENCODING_MS_1255:
+ case RTL_TEXTENCODING_MS_1256:
+ case RTL_TEXTENCODING_MS_1257:
+ case RTL_TEXTENCODING_MS_1258:
+ case RTL_TEXTENCODING_SHIFT_JIS:
+ case RTL_TEXTENCODING_GB_2312:
+ case RTL_TEXTENCODING_BIG5:
+ // in case the system uses an encoding from the list above, it should be used
+ break;
+
+ default:
+ // in case other encoding is used, use one of the encodings from the list
+ nEncoding = RTL_TEXTENCODING_MS_1250;
+ break;
+ }
+
+ nHash = ::comphelper::DocPasswordHelper::GetXLHashAsUINT16( aPasswd, nEncoding );
+ }
+ }
+
+ return nHash;
+}
+
+//------------------------------------------------------------------
+
+void SfxMedium::Close()
+{
+ if ( pImp->xStorage.is() )
+ {
+ // don't close the streams if they belong to the
+ // storage
+ //TODO/MBA: how to?! Do we need the flag?!
+ /*
+ const SvStream *pStream = aStorage->GetSvStream();
+ if ( pStream && pStream == pInStream )
+ {
+ CloseZipStorage_Impl();
+ pInStream = NULL;
+ pImp->xInputStream = Reference < XInputStream >();
+ pImp->xLockBytes.Clear();
+ if ( pSet )
+ pSet->ClearItem( SID_INPUTSTREAM );
+ aStorage->SetDeleteStream( TRUE );
+ }
+ else if ( pStream && pStream == pOutStream )
+ {
+ pOutStream = NULL;
+ aStorage->SetDeleteStream( TRUE );
+ } */
+
+ CloseStorage();
+ }
+
+ CloseStreams_Impl();
+
+ UnlockFile( sal_False );
+}
+
+void SfxMedium::CloseAndRelease()
+{
+ if ( pImp->xStorage.is() )
+ {
+ // don't close the streams if they belong to the
+ // storage
+ //TODO/MBA: how to?! Do we need the flag?!
+ /*
+ const SvStream *pStream = aStorage->GetSvStream();
+ if ( pStream && pStream == pInStream )
+ {
+ CloseZipStorage_Impl();
+ pInStream = NULL;
+ pImp->xInputStream = Reference < XInputStream >();
+ pImp->xLockBytes.Clear();
+ if ( pSet )
+ pSet->ClearItem( SID_INPUTSTREAM );
+ aStorage->SetDeleteStream( TRUE );
+ }
+ else if ( pStream && pStream == pOutStream )
+ {
+ pOutStream = NULL;
+ aStorage->SetDeleteStream( TRUE );
+ } */
+
+ CloseStorage();
+ }
+
+ CloseAndReleaseStreams_Impl();
+
+ UnlockFile( sal_True );
+}
+
+void SfxMedium::UnlockFile( sal_Bool bReleaseLockStream )
+{
+ if ( pImp->m_xLockingStream.is() )
+ {
+ if ( bReleaseLockStream )
+ {
+ try
+ {
+ uno::Reference< io::XInputStream > xInStream = pImp->m_xLockingStream->getInputStream();
+ uno::Reference< io::XOutputStream > xOutStream = pImp->m_xLockingStream->getOutputStream();
+ if ( xInStream.is() )
+ xInStream->closeInput();
+ if ( xOutStream.is() )
+ xOutStream->closeOutput();
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ pImp->m_xLockingStream = uno::Reference< io::XStream >();
+ }
+
+ if ( pImp->m_bLocked )
+ {
+ try
+ {
+ pImp->m_bLocked = sal_False;
+ ::svt::DocumentLockFile aLockFile( aLogicName );
+ // TODO/LATER: A warning could be shown in case the file is not the own one
+ aLockFile.RemoveFile();
+ }
+ catch( uno::Exception& )
+ {}
+ }
+}
+
+void SfxMedium::CloseAndReleaseStreams_Impl()
+{
+ CloseZipStorage_Impl();
+
+ uno::Reference< io::XInputStream > xInToClose = pImp->xInputStream;
+ uno::Reference< io::XOutputStream > xOutToClose;
+ if ( pImp->xStream.is() )
+ {
+ xOutToClose = pImp->xStream->getOutputStream();
+
+ // if the locking stream is closed here the related member should be cleaned
+ if ( pImp->xStream == pImp->m_xLockingStream )
+ pImp->m_xLockingStream = uno::Reference< io::XStream >();
+ }
+
+ // The probably exsisting SvStream wrappers should be closed first
+ CloseStreams_Impl();
+
+ // in case of salvage mode the storage is based on the streams
+ if ( !pImp->m_bSalvageMode )
+ {
+ try
+ {
+ if ( xInToClose.is() )
+ xInToClose->closeInput();
+ if ( xOutToClose.is() )
+ xOutToClose->closeOutput();
+ }
+ catch ( uno::Exception& )
+ {
+ }
+ }
+}
+
+//------------------------------------------------------------------
+void SfxMedium::CloseStreams_Impl()
+{
+ CloseInStream_Impl();
+ CloseOutStream_Impl();
+
+ if ( pSet )
+ pSet->ClearItem( SID_CONTENT );
+
+ pImp->aContent = ::ucbhelper::Content();
+}
+
+//------------------------------------------------------------------
+
+void SfxMedium::RefreshName_Impl()
+{
+#if 0 //(dv)
+ if ( pImp->aContent.get().is() )
+ {
+ String aNameP = pImp->xAnchor->GetViewURL();
+ pImp->aOrigURL = aNameP;
+ aLogicName = aNameP;
+ DELETEZ( pURLObj );
+ if (aLogicName.Len())
+ aLogicName = GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
+ SetIsRemote_Impl();
+ }
+#endif //(dv)
+}
+
+void SfxMedium::SetIsRemote_Impl()
+{
+ INetURLObject aObj( GetName() );
+ switch( aObj.GetProtocol() )
+ {
+ case INET_PROT_FTP:
+ case INET_PROT_HTTP:
+ case INET_PROT_HTTPS:
+ case INET_PROT_POP3:
+ case INET_PROT_NEWS:
+ case INET_PROT_IMAP:
+// case INET_PROT_OUT:
+ case INET_PROT_VIM:
+ bRemote = TRUE; break;
+ default:
+ bRemote = ( GetName().CompareToAscii( "private:msgid", 13 ) == COMPARE_EQUAL );
+ break;
+ }
+
+ // Da Dateien, die Remote geschrieben werden zur Uebertragung auch
+ // gelesen werden koennen muessen
+ if( bRemote )
+ nStorOpenMode |= STREAM_READ;
+}
+
+
+
+void SfxMedium::SetName( const String& aNameP, sal_Bool bSetOrigURL )
+{
+ if( !pImp->aOrigURL.Len() )
+ pImp->aOrigURL = aLogicName;
+ if( bSetOrigURL )
+ pImp->aOrigURL = aNameP;
+ aLogicName = aNameP;
+ DELETEZ( pURLObj );
+ pImp->aContent = ::ucbhelper::Content();
+ Init_Impl();
+}
+
+//----------------------------------------------------------------
+const String& SfxMedium::GetOrigURL() const
+{
+ return !pImp->aOrigURL.Len() ? (String &)aLogicName : pImp->aOrigURL;
+}
+
+//----------------------------------------------------------------
+
+void SfxMedium::SetPhysicalName_Impl( const String& rNameP )
+{
+ if ( rNameP != aName )
+ {
+ if( pImp->pTempFile )
+ {
+ delete pImp->pTempFile;
+ pImp->pTempFile = NULL;
+ }
+
+ if ( aName.Len() || rNameP.Len() )
+ pImp->aContent = ::ucbhelper::Content();
+
+ aName = rNameP;
+ bTriedStorage = sal_False;
+ pImp->bIsStorage = sal_False;
+ }
+}
+
+//------------------------------------------------------------------
+void SfxMedium::SetTemporary( sal_Bool bTemp )
+{
+ pImp->bIsTemp = bTemp;
+}
+
+//------------------------------------------------------------------
+sal_Bool SfxMedium::IsTemporary() const
+{
+ return pImp->bIsTemp;
+}
+
+//------------------------------------------------------------------
+
+sal_Bool SfxMedium::Exists( sal_Bool /*bForceSession*/ )
+{
+ DBG_ERROR( "Not implemented!" );
+ return sal_True;
+}
+
+//------------------------------------------------------------------
+
+void SfxMedium::ReOpen()
+{
+ BOOL bUseInteractionHandler = pImp->bUseInteractionHandler;
+ pImp->bUseInteractionHandler = FALSE;
+ GetMedium_Impl();
+ pImp->bUseInteractionHandler = bUseInteractionHandler;
+}
+
+//------------------------------------------------------------------
+
+void SfxMedium::CompleteReOpen()
+{
+ // do not use temporary file for reopen and in case of success throw the temporary file away
+ BOOL bUseInteractionHandler = pImp->bUseInteractionHandler;
+ pImp->bUseInteractionHandler = FALSE;
+
+ ::utl::TempFile* pTmpFile = NULL;
+ if ( pImp->pTempFile )
+ {
+ pTmpFile = pImp->pTempFile;
+ pImp->pTempFile = NULL;
+ aName = String();
+ }
+
+ GetMedium_Impl();
+
+ if ( GetError() )
+ {
+ if ( pImp->pTempFile )
+ {
+ pImp->pTempFile->EnableKillingFile( sal_True );
+ delete pImp->pTempFile;
+ }
+ pImp->pTempFile = pTmpFile;
+ if ( pImp->pTempFile )
+ aName = pImp->pTempFile->GetFileName();
+ }
+ else
+ {
+ pTmpFile->EnableKillingFile( sal_True );
+ delete pTmpFile;
+
+ }
+
+ pImp->bUseInteractionHandler = bUseInteractionHandler;
+}
+
+//------------------------------------------------------------------
+SfxMedium::SfxMedium
+(
+ const String &rName, StreamMode nOpenMode, sal_Bool bDirectP,
+ const SfxFilter *pFlt, SfxItemSet *pInSet
+)
+: IMPL_CTOR( sal_False, 0 ), // bRoot, pURLObj
+ pFilter(pFlt),
+ pSet( pInSet ),
+ pImp(new SfxMedium_Impl( this ))
+{
+ aLogicName = rName;
+ nStorOpenMode = nOpenMode;
+ bDirect = bDirectP;
+ Init_Impl();
+}
+
+
+SfxMedium::SfxMedium( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs )
+ : IMPL_CTOR( sal_False, 0 ), // bRoot, pURLObj
+ pFilter(0),
+ pSet(0),
+ pImp(new SfxMedium_Impl( this ))
+{
+ SfxAllItemSet *pParams = new SfxAllItemSet( SFX_APP()->GetPool() );
+ pSet = pParams;
+ TransformParameters( SID_OPENDOC, aArgs, *pParams );
+
+ String aFilterName;
+ SFX_ITEMSET_ARG( pSet, pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False );
+ if( pFilterNameItem )
+ aFilterName = pFilterNameItem->GetValue();
+ pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName );
+
+ sal_Bool bSalvage = sal_False;
+ SFX_ITEMSET_ARG( pSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
+ if( pSalvageItem )
+ {
+ // QUESTION: there is some treatment of Salvage in Init_Impl; align!
+ bSalvage = sal_True;
+ if ( pSalvageItem->GetValue().Len() )
+ {
+ // if an URL is provided in SalvageItem that means that the FileName refers to a temporary file
+ // that must be copied here
+
+ SFX_ITEMSET_ARG( pSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, FALSE );
+ if (!pFileNameItem) throw uno::RuntimeException();
+ ::rtl::OUString aNewTempFileURL = SfxMedium::CreateTempCopyWithExt( pFileNameItem->GetValue() );
+ if ( aNewTempFileURL.getLength() )
+ {
+ pSet->Put( SfxStringItem( SID_FILE_NAME, aNewTempFileURL ) );
+ pSet->ClearItem( SID_INPUTSTREAM );
+ pSet->ClearItem( SID_STREAM );
+ pSet->ClearItem( SID_CONTENT );
+ }
+ else
+ {
+ OSL_ENSURE( sal_False, "Can not create a new temporary file for crash recovery!\n" );
+ }
+ }
+ }
+
+ BOOL bReadOnly = FALSE;
+ SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, FALSE );
+ if ( pReadOnlyItem && pReadOnlyItem->GetValue() )
+ bReadOnly = TRUE;
+
+ SFX_ITEMSET_ARG( pSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, FALSE );
+ if (!pFileNameItem) throw uno::RuntimeException();
+ aLogicName = pFileNameItem->GetValue();
+ nStorOpenMode = bReadOnly ? SFX_STREAM_READONLY : SFX_STREAM_READWRITE;
+ bDirect = FALSE;
+ Init_Impl();
+}
+
+
+//------------------------------------------------------------------
+
+SfxMedium::SfxMedium( const uno::Reference < embed::XStorage >& rStor, const String& rBaseURL, const SfxItemSet* p, sal_Bool bRootP )
+: IMPL_CTOR( bRootP, 0 ), // bRoot, pURLObj
+ pSet(0),
+ pImp( new SfxMedium_Impl( this ))
+{
+ String aType = SfxFilter::GetTypeFromStorage( rStor );
+ pFilter = SFX_APP()->GetFilterMatcher().GetFilter4EA( aType );
+ DBG_ASSERT( pFilter, "No Filter for storage found!" );
+
+ Init_Impl();
+ pImp->xStorage = rStor;
+ pImp->bDisposeStorage = FALSE;
+
+ // always take BaseURL first, could be overwritten by ItemSet
+ GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, rBaseURL ) );
+ if ( p )
+ GetItemSet()->Put( *p );
+}
+
+//------------------------------------------------------------------
+
+SfxMedium::~SfxMedium()
+{
+ /* Attention
+ Don't enable CancelTransfers() till you know that the writer/web has changed his asynchronous load
+ behaviour. Otherwhise may StyleSheets inside a html file will be loaded at the right time.
+ => further the help will be empty then ... #100490#
+ */
+ //CancelTransfers();
+
+ // if there is a requirement to clean the backup this is the last possibility to do it
+ ClearBackup_Impl();
+
+ Close();
+
+ delete pSet;
+
+ if( pImp->bIsTemp && aName.Len() )
+ {
+ String aTemp;
+ if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aTemp ))
+ {
+ DBG_ERROR("Physical name not convertable!");
+ }
+
+ if ( !::utl::UCBContentHelper::Kill( aTemp ) )
+ {
+ DBG_ERROR("Couldn't remove temporary file!");
+ }
+ }
+
+ pFilter = 0;
+
+ delete pURLObj;
+ delete pImp;
+}
+
+//------------------------------------------------------------------
+void SfxMedium::SetItemSet(SfxItemSet *pNewSet)
+{
+ delete pSet;
+ pSet = pNewSet;
+}
+
+//----------------------------------------------------------------
+const INetURLObject& SfxMedium::GetURLObject() const
+{
+ if( !pURLObj )
+ {
+ SfxMedium* pThis = const_cast < SfxMedium* > (this);
+ pThis->pURLObj = new INetURLObject( aLogicName );
+ if ( pThis->pURLObj->HasMark() )
+ (*pThis->pURLObj) = INetURLObject( aLogicName ).GetURLNoMark();
+ }
+
+ return *pURLObj;
+}
+
+//----------------------------------------------------------------
+
+const String& SfxMedium::GetPreRedirectedURL() const
+{
+ return pImp->aPreRedirectionURL;
+}
+//----------------------------------------------------------------
+
+sal_uInt32 SfxMedium::GetMIMEAndRedirect( String& /*rName*/ )
+{
+/* dv !!!! not needed any longer ?
+ INetProtocol eProt = GetURLObject().GetProtocol();
+ if( eProt == INET_PROT_FTP && SvBinding::ShouldUseFtpProxy( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) )
+ {
+ Any aAny( UCB_Helper::GetProperty( GetContent(), WID_FLAG_IS_FOLDER ) );
+ sal_Bool bIsFolder = FALSE;
+ if ( ( aAny >>= bIsFolder ) && bIsFolder )
+ return ERRCODE_NONE;
+ }
+
+ GetMedium_Impl();
+ if( !eError && pImp->xBinding.Is() )
+ {
+ eError = pImp->xBinding->GetMimeType( rName );
+
+ // Wir koennen keine Parameter wie CharSets usw.
+ rName = rName.GetToken( 0, ';' );
+ if( !eError )
+ {
+ if( !pImp->aPreRedirectionURL.Len() )
+ pImp->aPreRedirectionURL = aLogicName;
+ SetName( pImp->xBinding->GetRedirectedURL() );
+ }
+ pImp->aExpireTime = pImp->xBinding->GetExpireDateTime();
+ }
+ return eError;
+*/
+ return 0;
+}
+
+//----------------------------------------------------------------
+
+void SfxMedium::SetReferer( const String& rRefer )
+{
+ pImp->aReferer = rRefer;
+}
+//----------------------------------------------------------------
+
+const String& SfxMedium::GetReferer( ) const
+{
+ return pImp->aReferer;
+}
+
+//----------------------------------------------------------------
+
+void SfxMedium::SetExpired_Impl( const DateTime& rDateTime )
+{
+ pImp->aExpireTime = rDateTime;
+}
+//----------------------------------------------------------------
+
+sal_Bool SfxMedium::IsExpired() const
+{
+ return pImp->aExpireTime.IsValid() && pImp->aExpireTime < DateTime();
+}
+//----------------------------------------------------------------
+
+void SfxMedium::ForceSynchronStream_Impl( sal_Bool bForce )
+{
+ if( pInStream )
+ {
+ SvLockBytes* pBytes = pInStream->GetLockBytes();
+ if( pBytes )
+ pBytes->SetSynchronMode( bForce );
+ }
+ pImp->bForceSynchron = bForce;
+}
+
+//----------------------------------------------------------------
+SfxFrame* SfxMedium::GetLoadTargetFrame() const
+{
+ return pImp->wLoadTargetFrame;
+}
+//----------------------------------------------------------------
+
+void SfxMedium::SetLoadTargetFrame(SfxFrame* pFrame )
+{
+ pImp->wLoadTargetFrame = pFrame;
+}
+//----------------------------------------------------------------
+
+void SfxMedium::SetStorage_Impl( const uno::Reference < embed::XStorage >& rStor )
+{
+ pImp->xStorage = rStor;
+}
+//----------------------------------------------------------------
+
+SfxItemSet* SfxMedium::GetItemSet() const
+{
+ // this method *must* return an ItemSet, returning NULL can cause crashes
+ if( !pSet )
+ ((SfxMedium*)this)->pSet = new SfxAllItemSet( SFX_APP()->GetPool() );
+ return pSet;
+}
+//----------------------------------------------------------------
+
+SvKeyValueIterator* SfxMedium::GetHeaderAttributes_Impl()
+{
+ if( !pImp->xAttributes.Is() )
+ {
+ pImp->xAttributes = SvKeyValueIteratorRef( new SvKeyValueIterator );
+
+ if ( GetContent().is() )
+ {
+ pImp->bIsCharsetInitialized = sal_True;
+
+ try
+ {
+ Any aAny = pImp->aContent.getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) );
+ ::rtl::OUString aContentType;
+ aAny >>= aContentType;
+
+ pImp->xAttributes->Append( SvKeyValue( ::rtl::OUString::createFromAscii( "content-type" ), aContentType ) );
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ }
+ }
+ }
+
+ return pImp->xAttributes;
+}
+//----------------------------------------------------------------
+
+SvCompatWeakHdl* SfxMedium::GetHdl()
+{
+ return pImp->GetHdl();
+}
+
+sal_Bool SfxMedium::IsDownloadDone_Impl()
+{
+ return pImp->bDownloadDone;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SfxMedium::GetInputStream()
+{
+ if ( !pImp->xInputStream.is() )
+ GetMedium_Impl();
+ return pImp->xInputStream;
+}
+
+const uno::Sequence < util::RevisionTag >& SfxMedium::GetVersionList( bool _bNoReload )
+{
+ // if the medium has no name, then this medium should represent a new document and can have no version info
+ if ( ( !_bNoReload || !pImp->m_bVersionsAlreadyLoaded ) && !pImp->aVersions.getLength() &&
+ ( aName.Len() || aLogicName.Len() ) && GetStorage().is() )
+ {
+ uno::Reference < document::XDocumentRevisionListPersistence > xReader( comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii("com.sun.star.document.DocumentRevisionListPersistence") ), uno::UNO_QUERY );
+ if ( xReader.is() )
+ {
+ try
+ {
+ pImp->aVersions = xReader->load( GetStorage() );
+ }
+ catch ( uno::Exception& )
+ {
+ }
+ }
+ }
+
+ if ( !pImp->m_bVersionsAlreadyLoaded )
+ pImp->m_bVersionsAlreadyLoaded = sal_True;
+
+ return pImp->aVersions;
+}
+
+uno::Sequence < util::RevisionTag > SfxMedium::GetVersionList( const uno::Reference < embed::XStorage >& xStorage )
+{
+ uno::Reference < document::XDocumentRevisionListPersistence > xReader( comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii("com.sun.star.document.DocumentRevisionListPersistence") ), uno::UNO_QUERY );
+ if ( xReader.is() )
+ {
+ try
+ {
+ return xReader->load( xStorage );
+ }
+ catch ( uno::Exception& )
+ {
+ }
+ }
+
+ return uno::Sequence < util::RevisionTag >();
+}
+
+sal_uInt16 SfxMedium::AddVersion_Impl( util::RevisionTag& rRevision )
+{
+ if ( GetStorage().is() )
+ {
+ // Einen eindeutigen Namen f"ur den Stream ermitteln
+ SvULongs aLongs;
+ sal_Int32 nLength = pImp->aVersions.getLength();
+ for ( sal_Int32 m=0; m<nLength; m++ )
+ {
+ sal_uInt32 nVer = (sal_uInt32) String( pImp->aVersions[m].Identifier ).Copy(7).ToInt32();
+ sal_uInt16 n;
+ for ( n=0; n<aLongs.Count(); n++ )
+ if ( nVer<aLongs[n] )
+ break;
+
+ aLongs.Insert( nVer, n );
+ }
+
+ sal_uInt16 nKey;
+ for ( nKey=0; nKey<aLongs.Count(); nKey++ )
+ if ( aLongs[nKey] > ( ULONG ) nKey+1 )
+ break;
+
+ String aRevName = DEFINE_CONST_UNICODE( "Version" );
+ aRevName += String::CreateFromInt32( nKey + 1 );
+ pImp->aVersions.realloc( nLength+1 );
+ rRevision.Identifier = aRevName;
+ pImp->aVersions[nLength] = rRevision;
+ return nKey;
+ }
+
+ return 0;
+}
+
+sal_Bool SfxMedium::RemoveVersion_Impl( const ::rtl::OUString& rName )
+{
+ if ( !pImp->aVersions.getLength() )
+ return sal_False;
+
+ sal_Int32 nLength = pImp->aVersions.getLength();
+ for ( sal_Int32 n=0; n<nLength; n++ )
+ {
+ if ( pImp->aVersions[n].Identifier == rName )
+ {
+ for ( sal_Int32 m=n; m<nLength-1; m++ )
+ pImp->aVersions[m] = pImp->aVersions[m+1];
+ pImp->aVersions.realloc(nLength-1);
+ return sal_True;
+ }
+ }
+
+ return sal_False;
+}
+
+sal_Bool SfxMedium::TransferVersionList_Impl( SfxMedium& rMedium )
+{
+ if ( rMedium.pImp->aVersions.getLength() )
+ {
+ pImp->aVersions = rMedium.pImp->aVersions;
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+sal_Bool SfxMedium::SaveVersionList_Impl( sal_Bool /*bUseXML*/ )
+{
+ if ( GetStorage().is() )
+ {
+ if ( !pImp->aVersions.getLength() )
+ return sal_True;
+
+ uno::Reference < document::XDocumentRevisionListPersistence > xWriter( comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii("com.sun.star.document.DocumentRevisionListPersistence") ), uno::UNO_QUERY );
+ if ( xWriter.is() )
+ {
+ try
+ {
+ xWriter->store( GetStorage(), pImp->aVersions );
+ return sal_True;
+ }
+ catch ( uno::Exception& )
+ {
+ }
+ }
+ }
+
+ return sal_False;
+}
+
+//----------------------------------------------------------------
+sal_Bool SfxMedium::IsReadOnly()
+{
+ sal_Bool bReadOnly = sal_False;
+
+ // a) ReadOnly filter cant produce read/write contents!
+ bReadOnly = (
+ (pFilter ) &&
+ ((pFilter->GetFilterFlags() & SFX_FILTER_OPENREADONLY) == SFX_FILTER_OPENREADONLY)
+ );
+
+ // b) if filter allow read/write contents .. check open mode of the storage
+ if (!bReadOnly)
+ bReadOnly = !( GetOpenMode() & STREAM_WRITE );
+
+ // c) the API can force the readonly state!
+ if (!bReadOnly)
+ {
+ SFX_ITEMSET_ARG( GetItemSet(), pItem, SfxBoolItem, SID_DOC_READONLY, sal_False);
+ if (pItem)
+ bReadOnly = pItem->GetValue();
+ }
+
+ return bReadOnly;
+}
+
+//----------------------------------------------------------------
+sal_Bool SfxMedium::SetWritableForUserOnly( const ::rtl::OUString& aURL )
+{
+ // UCB does not allow to allow write access only for the user,
+ // use osl API
+ sal_Bool bResult = sal_False;
+
+ ::osl::DirectoryItem aDirItem;
+ if ( ::osl::DirectoryItem::get( aURL, aDirItem ) == ::osl::FileBase::E_None )
+ {
+ ::osl::FileStatus aFileStatus( FileStatusMask_Attributes );
+ if ( aDirItem.getFileStatus( aFileStatus ) == osl::FileBase::E_None
+ && aFileStatus.isValid( FileStatusMask_Attributes ) )
+ {
+ sal_uInt64 nAttributes = aFileStatus.getAttributes();
+
+ nAttributes &= ~(Attribute_OwnWrite |
+ Attribute_GrpWrite |
+ Attribute_OthWrite |
+ Attribute_ReadOnly);
+ nAttributes |= Attribute_OwnWrite;
+
+ bResult = ( osl::File::setAttributes( aURL, nAttributes ) == ::osl::FileBase::E_None );
+ }
+ }
+
+ return bResult;
+}
+
+//----------------------------------------------------------------
+void SfxMedium::CreateTempFile( sal_Bool bReplace )
+{
+ if ( pImp->pTempFile )
+ {
+ if ( !bReplace )
+ return;
+
+ DELETEZ( pImp->pTempFile );
+ aName = String();
+ }
+
+ pImp->pTempFile = new ::utl::TempFile();
+ pImp->pTempFile->EnableKillingFile( sal_True );
+ aName = pImp->pTempFile->GetFileName();
+ ::rtl::OUString aTmpURL = pImp->pTempFile->GetURL();
+ if ( !aName.Len() || !aTmpURL.getLength() )
+ {
+ SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ return;
+ }
+
+ if ( !( nStorOpenMode & STREAM_TRUNC ) )
+ {
+ sal_Bool bTransferSuccess = sal_False;
+
+ if ( GetContent().is()
+ && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) )
+ && ::utl::UCBContentHelper::IsDocument( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) )
+ {
+ // if there is already such a document, we should copy it
+ // if it is a file system use OS copy process
+ try
+ {
+ uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv;
+ INetURLObject aTmpURLObj( aTmpURL );
+ ::rtl::OUString aFileName = aTmpURLObj.getName( INetURLObject::LAST_SEGMENT,
+ true,
+ INetURLObject::DECODE_WITH_CHARSET );
+ if ( aFileName.getLength() && aTmpURLObj.removeSegment() )
+ {
+ ::ucbhelper::Content aTargetContent( aTmpURLObj.GetMainURL( INetURLObject::NO_DECODE ), xComEnv );
+ if ( aTargetContent.transferContent( pImp->aContent, ::ucbhelper::InsertOperation_COPY, aFileName, NameClash::OVERWRITE ) )
+ {
+ SetWritableForUserOnly( aTmpURL );
+ bTransferSuccess = sal_True;
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {}
+
+ if ( bTransferSuccess )
+ {
+ CloseOutStream();
+ CloseInStream();
+ }
+ }
+
+ if ( !bTransferSuccess && pInStream )
+ {
+ // the case when there is no URL-access available or this is a remote protocoll
+ // but there is an input stream
+ GetOutStream();
+ if ( pOutStream )
+ {
+ char *pBuf = new char [8192];
+ sal_uInt32 nErr = ERRCODE_NONE;
+
+ pInStream->Seek(0);
+ pOutStream->Seek(0);
+
+ while( !pInStream->IsEof() && nErr == ERRCODE_NONE )
+ {
+ sal_uInt32 nRead = pInStream->Read( pBuf, 8192 );
+ nErr = pInStream->GetError();
+ pOutStream->Write( pBuf, nRead );
+ }
+
+ bTransferSuccess = sal_True;
+ delete[] pBuf;
+ CloseInStream();
+ }
+ CloseOutStream_Impl();
+ }
+ else
+ {
+ // Quite strange design, but currently it is expected that in this case no transfer happens
+ // TODO/LATER: get rid of this inconsistent part of the call design
+ bTransferSuccess = sal_True;
+ CloseInStream();
+ }
+
+ if ( !bTransferSuccess )
+ {
+ SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ return;
+ }
+ }
+
+ CloseStorage();
+}
+
+//----------------------------------------------------------------
+void SfxMedium::CreateTempFileNoCopy()
+{
+ // this call always replaces the existing temporary file
+ if ( pImp->pTempFile )
+ delete pImp->pTempFile;
+
+ pImp->pTempFile = new ::utl::TempFile();
+ pImp->pTempFile->EnableKillingFile( sal_True );
+ aName = pImp->pTempFile->GetFileName();
+ if ( !aName.Len() )
+ {
+ SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ return;
+ }
+
+ CloseOutStream_Impl();
+ CloseStorage();
+}
+
+::rtl::OUString SfxMedium::GetCharset()
+{
+ if( !pImp->bIsCharsetInitialized )
+ {
+ // Set an error in case there is no content?
+ if ( GetContent().is() )
+ {
+ pImp->bIsCharsetInitialized = sal_True;
+
+ try
+ {
+ Any aAny = pImp->aContent.getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) );
+ ::rtl::OUString aField;
+ aAny >>= aField;
+
+ ::rtl::OString sContent = ::rtl::OUStringToOString( aField, RTL_TEXTENCODING_ASCII_US );
+ ByteString sType, sSubType;
+ INetContentTypeParameterList aParameters;
+
+ if( INetContentTypes::parse( sContent, sType, sSubType, &aParameters ) )
+ {
+ const INetContentTypeParameter * pCharset = aParameters.find("charset");
+ if (pCharset != 0)
+ pImp->aCharset = pCharset->m_sValue;
+ }
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ }
+ }
+ }
+
+ return pImp->aCharset;
+}
+
+void SfxMedium::SetCharset( ::rtl::OUString aChs )
+{
+ pImp->bIsCharsetInitialized = sal_True;
+ pImp->aCharset = aChs;
+}
+
+sal_Bool SfxMedium::SignContents_Impl( sal_Bool bScriptingContent, const ::rtl::OUString& aODFVersion, sal_Bool bHasValidDocumentSignature )
+{
+ sal_Bool bChanges = FALSE;
+
+ // the medium should be closed to be able to sign, the caller is responsible to close it
+ if ( !IsOpen() && !GetError() )
+ {
+ // The component should know if there was a valid document signature, since
+ // it should show a warning in this case
+ uno::Sequence< uno::Any > aArgs( 2 );
+ aArgs[0] <<= aODFVersion;
+ aArgs[1] <<= bHasValidDocumentSignature;
+ ::com::sun::star::uno::Reference< ::com::sun::star::security::XDocumentDigitalSignatures > xSigner(
+ comphelper::getProcessServiceFactory()->createInstanceWithArguments(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ),
+ aArgs ),
+ ::com::sun::star::uno::UNO_QUERY );
+
+ if ( xSigner.is() )
+ {
+ uno::Reference< embed::XStorage > xWriteableZipStor;
+ if ( !IsReadOnly() )
+ {
+ // we can reuse the temporary file if there is one already
+ CreateTempFile( sal_False );
+ GetMedium_Impl();
+
+ try
+ {
+ if ( !pImp->xStream.is() )
+ throw uno::RuntimeException();
+
+ xWriteableZipStor = ::comphelper::OStorageHelper::GetStorageOfFormatFromStream( ZIP_STORAGE_FORMAT_STRING, pImp->xStream );
+ if ( !xWriteableZipStor.is() )
+ throw uno::RuntimeException();
+
+ uno::Reference< embed::XStorage > xMetaInf = xWriteableZipStor->openStorageElement(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ),
+ embed::ElementModes::READWRITE );
+ if ( !xMetaInf.is() )
+ throw uno::RuntimeException();
+
+ if ( bScriptingContent )
+ {
+ // If the signature has already the document signature it will be removed
+ // after the scripting signature is inserted.
+ uno::Reference< io::XStream > xStream(
+ xMetaInf->openStreamElement( xSigner->getScriptingContentSignatureDefaultStreamName(),
+ embed::ElementModes::READWRITE ),
+ uno::UNO_SET_THROW );
+
+ if ( xSigner->signScriptingContent( GetZipStorageToSign_Impl(), xStream ) )
+ {
+ // remove the document signature if any
+ ::rtl::OUString aDocSigName = xSigner->getDocumentContentSignatureDefaultStreamName();
+ if ( aDocSigName.getLength() && xMetaInf->hasByName( aDocSigName ) )
+ xMetaInf->removeElement( aDocSigName );
+
+ uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW );
+ xTransact->commit();
+ xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW );
+ xTransact->commit();
+
+ // the temporary file has been written, commit it to the original file
+ Commit();
+ bChanges = TRUE;
+ }
+ }
+ else
+ {
+ uno::Reference< io::XStream > xStream(
+ xMetaInf->openStreamElement( xSigner->getDocumentContentSignatureDefaultStreamName(),
+ embed::ElementModes::READWRITE ),
+ uno::UNO_SET_THROW );
+
+ if ( xSigner->signDocumentContent( GetZipStorageToSign_Impl(), xStream ) )
+ {
+ uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW );
+ xTransact->commit();
+ xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW );
+ xTransact->commit();
+
+ // the temporary file has been written, commit it to the original file
+ Commit();
+ bChanges = TRUE;
+ }
+ }
+ }
+ catch ( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Couldn't use signing functionality!\n" );
+ }
+
+ CloseAndRelease();
+ }
+ else
+ {
+ try
+ {
+ if ( bScriptingContent )
+ xSigner->showScriptingContentSignatures( GetZipStorageToSign_Impl(), uno::Reference< io::XInputStream >() );
+ else
+ xSigner->showDocumentContentSignatures( GetZipStorageToSign_Impl(), uno::Reference< io::XInputStream >() );
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Couldn't use signing functionality!\n" );
+ }
+ }
+ }
+
+ ResetError();
+ }
+
+ return bChanges;
+}
+
+//----------------------------------------------------------------
+sal_uInt16 SfxMedium::GetCachedSignatureState_Impl()
+{
+ return pImp->m_nSignatureState;
+}
+
+//----------------------------------------------------------------
+void SfxMedium::SetCachedSignatureState_Impl( sal_uInt16 nState )
+{
+ pImp->m_nSignatureState = nState;
+}
+
+BOOL SfxMedium::HasStorage_Impl() const
+{
+ return pImp->xStorage.is();
+}
+
+BOOL SfxMedium::IsOpen() const
+{
+ return pInStream || pOutStream || pImp->xStorage.is();
+}
+
+::rtl::OUString SfxMedium::CreateTempCopyWithExt( const ::rtl::OUString& aURL )
+{
+ ::rtl::OUString aResult;
+
+ if ( aURL.getLength() )
+ {
+ sal_Int32 nPrefixLen = aURL.lastIndexOf( '.' );
+ String aExt = ( nPrefixLen == -1 ) ? String() : String( aURL.copy( nPrefixLen ) );
+
+ ::rtl::OUString aNewTempFileURL = ::utl::TempFile( String(), &aExt ).GetURL();
+ if ( aNewTempFileURL.getLength() )
+ {
+ INetURLObject aSource( aURL );
+ INetURLObject aDest( aNewTempFileURL );
+ ::rtl::OUString aFileName = aDest.getName( INetURLObject::LAST_SEGMENT,
+ true,
+ INetURLObject::DECODE_WITH_CHARSET );
+ if ( aFileName.getLength() && aDest.removeSegment() )
+ {
+ try
+ {
+ uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv;
+ ::ucbhelper::Content aTargetContent( aDest.GetMainURL( INetURLObject::NO_DECODE ), xComEnv );
+ ::ucbhelper::Content aSourceContent( aSource.GetMainURL( INetURLObject::NO_DECODE ), xComEnv );
+ if ( aTargetContent.transferContent( aSourceContent,
+ ::ucbhelper::InsertOperation_COPY,
+ aFileName,
+ NameClash::OVERWRITE ) )
+ {
+ // Success
+ aResult = aNewTempFileURL;
+ }
+ }
+ catch( uno::Exception& )
+ {}
+ }
+ }
+ }
+
+ return aResult;
+}
+
+sal_Bool SfxMedium::CallApproveHandler( const uno::Reference< task::XInteractionHandler >& xHandler, uno::Any aRequest, sal_Bool bAllowAbort )
+{
+ sal_Bool bResult = sal_False;
+
+ if ( xHandler.is() )
+ {
+ try
+ {
+ uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( bAllowAbort ? 2 : 1 );
+
+ ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
+ aContinuations[ 0 ] = pApprove.get();
+
+ if ( bAllowAbort )
+ {
+ ::rtl::Reference< ::comphelper::OInteractionAbort > pAbort( new ::comphelper::OInteractionAbort );
+ aContinuations[ 1 ] = pAbort.get();
+ }
+
+ xHandler->handle(::framework::InteractionRequest::CreateRequest (aRequest,aContinuations));
+ bResult = pApprove->wasSelected();
+ }
+ catch( const Exception& )
+ {
+ }
+ }
+
+ return bResult;
+}
+
+::rtl::OUString SfxMedium::SwitchDocumentToTempFile()
+{
+ // the method returns empty string in case of failure
+ ::rtl::OUString aResult;
+ ::rtl::OUString aOrigURL = aLogicName;
+
+ if ( aOrigURL.getLength() )
+ {
+ sal_Int32 nPrefixLen = aOrigURL.lastIndexOf( '.' );
+ String aExt = ( nPrefixLen == -1 ) ? String() : String( aOrigURL.copy( nPrefixLen ) );
+ ::rtl::OUString aNewURL = ::utl::TempFile( String(), &aExt ).GetURL();
+
+ // TODO/LATER: In future the aLogicName should be set to shared folder URL
+ // and a temporary file should be created. Transport_Impl should be impossible then.
+ if ( aNewURL.getLength() )
+ {
+ uno::Reference< embed::XStorage > xStorage = GetStorage();
+ uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY );
+
+ if ( xOptStorage.is() )
+ {
+ // TODO/LATER: reuse the pImp->pTempFile if it already exists
+ CanDisposeStorage_Impl( sal_False );
+ Close();
+ SetPhysicalName_Impl( String() );
+ SetName( aNewURL );
+
+ // remove the readonly state
+ sal_Bool bWasReadonly = sal_False;
+ nStorOpenMode = SFX_STREAM_READWRITE;
+ SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, FALSE );
+ if ( pReadOnlyItem && pReadOnlyItem->GetValue() )
+ bWasReadonly = sal_True;
+ GetItemSet()->ClearItem( SID_DOC_READONLY );
+
+ GetMedium_Impl();
+ LockOrigFileOnDemand( sal_False, sal_False );
+ CreateTempFile( sal_True );
+ GetMedium_Impl();
+
+ if ( pImp->xStream.is() )
+ {
+ try
+ {
+ xOptStorage->writeAndAttachToStream( pImp->xStream );
+ pImp->xStorage = xStorage;
+ aResult = aNewURL;
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ if ( !aResult.getLength() )
+ {
+ Close();
+ SetPhysicalName_Impl( String() );
+ SetName( aOrigURL );
+ if ( bWasReadonly )
+ {
+ // set the readonly state back
+ nStorOpenMode = SFX_STREAM_READONLY;
+ GetItemSet()->Put( SfxBoolItem(SID_DOC_READONLY, sal_True));
+ }
+ GetMedium_Impl();
+ pImp->xStorage = xStorage;
+ }
+ }
+ }
+ }
+
+ return aResult;
+}
+
+sal_Bool SfxMedium::SwitchDocumentToFile( ::rtl::OUString aURL )
+{
+ // the method is only for storage based documents
+ sal_Bool bResult = sal_False;
+ ::rtl::OUString aOrigURL = aLogicName;
+
+ if ( aURL.getLength() && aOrigURL.getLength() )
+ {
+ uno::Reference< embed::XStorage > xStorage = GetStorage();
+ uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY );
+
+ if ( xOptStorage.is() )
+ {
+ // TODO/LATER: reuse the pImp->pTempFile if it already exists
+ CanDisposeStorage_Impl( sal_False );
+ Close();
+ SetPhysicalName_Impl( String() );
+ SetName( aURL );
+
+ // open the temporary file based document
+ GetMedium_Impl();
+ LockOrigFileOnDemand( sal_False, sal_False );
+ CreateTempFile( sal_True );
+ GetMedium_Impl();
+
+ if ( pImp->xStream.is() )
+ {
+ try
+ {
+ uno::Reference< io::XTruncate > xTruncate( pImp->xStream, uno::UNO_QUERY_THROW );
+ if ( xTruncate.is() )
+ xTruncate->truncate();
+
+ xOptStorage->writeAndAttachToStream( pImp->xStream );
+ pImp->xStorage = xStorage;
+ bResult = sal_True;
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ if ( !bResult )
+ {
+ Close();
+ SetPhysicalName_Impl( String() );
+ SetName( aOrigURL );
+ GetMedium_Impl();
+ pImp->xStorage = xStorage;
+ }
+ }
+ }
+
+ return bResult;
+}
+
diff --git a/sfx2/source/doc/docfilt.cxx b/sfx2/source/doc/docfilt.cxx
new file mode 100644
index 000000000000..1219d30d7b27
--- /dev/null
+++ b/sfx2/source/doc/docfilt.cxx
@@ -0,0 +1,251 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+// INCLUDE ---------------------------------------------------------------
+
+#ifdef SOLARIS
+// HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
+#include <ctime>
+#endif
+
+#include <string> // HACK: prevent conflict between STLPORT and Workshop headers
+#include <sot/exchange.hxx>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+
+#include <sfx2/docfac.hxx>
+#include <sfx2/docfilt.hxx>
+#include "fltfnc.hxx"
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/objsh.hxx>
+
+using namespace ::com::sun::star;
+
+// STATIC DATA -----------------------------------------------------------
+
+DBG_NAME(SfxFilter)
+
+SfxFilter::SfxFilter( const String &rName,
+ const String &rWildCard,
+ SfxFilterFlags nType,
+ sal_uInt32 lFmt,
+ const String &rTypNm,
+ sal_uInt16 nIcon,
+ const String &rMimeType,
+ const String &rUsrDat,
+ const String &rServiceName ):
+ aWildCard(rWildCard, ';'),
+ lFormat(lFmt),
+ aTypeName(rTypNm),
+ aUserData(rUsrDat),
+ nFormatType(nType),
+ nDocIcon(nIcon),
+ aServiceName( rServiceName ),
+ aMimeType( rMimeType ),
+ aFilterName( rName )
+{
+ String aExts = GetWildcard()();
+ String aShort, aLong;
+ String aRet;
+ sal_uInt16 nMaxLength = USHRT_MAX;
+ String aTest;
+ sal_uInt16 nPos = 0;
+ while( ( aRet = aExts.GetToken( nPos++, ';' ) ).Len() )
+ {
+ aTest = aRet;
+ aTest.SearchAndReplace( DEFINE_CONST_UNICODE( "*." ), String() );
+ if( aTest.Len() <= nMaxLength )
+ {
+ if( aShort.Len() ) aShort += ';';
+ aShort += aRet;
+ }
+ else
+ {
+ if( aLong.Len() ) aLong += ';';
+ aLong += aRet;
+ }
+ }
+ if( aShort.Len() && aLong.Len() )
+ {
+ aShort += ';';
+ aShort += aLong;
+ }
+ aWildCard = aShort;
+
+ nVersion = SOFFICE_FILEFORMAT_50;
+ aUIName = aFilterName;
+}
+
+SfxFilter::~SfxFilter()
+{
+}
+
+String SfxFilter::GetDefaultExtension() const
+{
+ return GetWildcard()().GetToken( 0, ';' );
+}
+
+String SfxFilter::GetSuffixes() const
+{
+ String aRet = GetWildcard()();
+ while( aRet.SearchAndReplaceAscii( "*.", String() ) != STRING_NOTFOUND ) ;
+ while( aRet.SearchAndReplace( ';', ',' ) != STRING_NOTFOUND ) ;
+ return aRet;
+}
+
+const SfxFilter* SfxFilter::GetDefaultFilter( const String& rName )
+{
+ return SfxFilterContainer::GetDefaultFilter_Impl( rName );
+}
+
+const SfxFilter* SfxFilter::GetDefaultFilterFromFactory( const String& rFact )
+{
+ return GetDefaultFilter( SfxObjectShell::GetServiceNameFromFactory( rFact ) );
+}
+
+const SfxFilter* SfxFilter::GetFilterByName( const String& rName )
+{
+ SfxFilterMatcher aMatch;
+ return aMatch.GetFilter4FilterName( rName, 0, 0 );
+}
+
+String SfxFilter::GetTypeFromStorage( const SotStorage& rStg )
+{
+ const char* pType=0;
+ if ( rStg.IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "WordDocument" ) ) ) )
+ {
+ if ( rStg.IsStream( String::CreateFromAscii("0Table" ) ) || rStg.IsStream( String::CreateFromAscii("1Table" ) ) )
+ pType = "writer_MS_Word_97";
+ else
+ pType = "writer_MS_Word_95";
+ }
+ else if ( rStg.IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Book" ) ) ) )
+ {
+ pType = "calc_MS_Excel_95";
+ }
+ else if ( rStg.IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Workbook" ) ) ) )
+ {
+ pType = "calc_MS_Excel_97";
+ }
+ else if ( rStg.IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "PowerPoint Document" ) ) ) )
+ {
+ pType = "impress_MS_PowerPoint_97";
+ }
+ else if ( rStg.IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Equation Native" ) ) ) )
+ {
+ pType = "math_MathType_3x";
+ }
+ else
+ {
+ sal_Int32 nClipId = ((SotStorage&)rStg).GetFormat();
+ if ( nClipId )
+ {
+ const SfxFilter* pFilter = SfxFilterMatcher().GetFilter4ClipBoardId( nClipId );
+ if ( pFilter )
+ return pFilter->GetTypeName();
+ }
+ }
+
+ return pType ? String::CreateFromAscii(pType) : String();
+}
+
+String SfxFilter::GetTypeFromStorage( const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xStorage, BOOL bTemplate,
+ String* pFilterName )
+ throw ( beans::UnknownPropertyException,
+ lang::WrappedTargetException,
+ uno::RuntimeException )
+{
+ SfxFilterMatcher aMatcher;
+ const char* pType=0;
+ String aName;
+ if ( pFilterName )
+ {
+ aName = *pFilterName;
+ pFilterName->Erase();
+ }
+
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xProps( xStorage, com::sun::star::uno::UNO_QUERY );
+ if ( xProps.is() )
+ {
+ ::rtl::OUString aMediaType;
+ xProps->getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) ) >>= aMediaType;
+ if ( aMediaType.getLength() )
+ {
+ ::com::sun::star::datatransfer::DataFlavor aDataFlavor;
+ aDataFlavor.MimeType = aMediaType;
+ sal_uInt32 nClipId = SotExchange::GetFormat( aDataFlavor );
+ if ( nClipId )
+ {
+ SfxFilterFlags nMust = SFX_FILTER_IMPORT, nDont = SFX_FILTER_NOTINSTALLED;
+ if ( bTemplate )
+ // template filter was preselected, try to verify
+ nMust |= SFX_FILTER_TEMPLATEPATH;
+ else
+ // template filters shouldn't be detected if not explicitly asked for
+ nDont |= SFX_FILTER_TEMPLATEPATH;
+
+ const SfxFilter* pFilter = 0;
+ if ( aName.Len() )
+ // get preselected Filter if it matches the desired filter flags
+ pFilter = aMatcher.GetFilter4FilterName( aName, nMust, nDont );
+
+ if ( !pFilter || pFilter->GetFormat() != nClipId )
+ {
+ // get filter from storage MediaType
+ pFilter = aMatcher.GetFilter4ClipBoardId( nClipId, nMust, nDont );
+ if ( !pFilter )
+ // template filter is asked for , but there isn't one; so at least the "normal" format should be detected
+ // or storage *is* a template, but bTemplate is not set
+ pFilter = aMatcher.GetFilter4ClipBoardId( nClipId );
+ }
+
+ if ( pFilter )
+ {
+ if ( pFilterName )
+ *pFilterName = pFilter->GetName();
+ return pFilter->GetTypeName();
+ }
+ }
+ }
+ }
+
+ //TODO: do it without SfxFilter
+ //TODO/LATER: don't yield FilterName, should be done in FWK!
+ String aRet;
+ if ( pType )
+ {
+ aRet = String::CreateFromAscii(pType);
+ if ( pFilterName )
+ *pFilterName = aMatcher.GetFilter4EA( aRet )->GetName();
+ }
+
+ return aRet;
+}
diff --git a/sfx2/source/doc/docinf.cxx b/sfx2/source/doc/docinf.cxx
new file mode 100644
index 000000000000..d0f6678d8641
--- /dev/null
+++ b/sfx2/source/doc/docinf.cxx
@@ -0,0 +1,309 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sfx2/docinf.hxx>
+
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/uno/Exception.hpp>
+
+#include <rtl/ustring.hxx>
+#include <tools/debug.hxx>
+#include <comphelper/string.hxx>
+#include <sot/storage.hxx>
+#include <vcl/gdimtf.hxx>
+
+#include "oleprops.hxx"
+
+// ============================================================================
+
+// stream names
+#define STREAM_SUMMARYINFO "\005SummaryInformation"
+#define STREAM_DOCSUMMARYINFO "\005DocumentSummaryInformation"
+
+// usings
+using namespace ::com::sun::star;
+
+
+namespace sfx2 {
+
+sal_uInt32 SFX2_DLLPUBLIC LoadOlePropertySet(
+ uno::Reference< document::XDocumentProperties> i_xDocProps,
+ SotStorage* i_pStorage )
+{
+ // *** global properties from stream "005SummaryInformation" ***
+
+ // load the property set
+ SfxOlePropertySet aGlobSet;
+ ErrCode nGlobError = aGlobSet.LoadPropertySet(i_pStorage,
+ String( RTL_CONSTASCII_USTRINGPARAM( STREAM_SUMMARYINFO ) ) );
+
+ // global section
+ SfxOleSectionRef xGlobSect = aGlobSet.GetSection( SECTION_GLOBAL );
+ if( xGlobSect.get() )
+ {
+ // set supported properties
+ String aStrValue;
+ util::DateTime aDateTime;
+
+ if( xGlobSect->GetStringValue( aStrValue, PROPID_TITLE ) )
+ i_xDocProps->setTitle( aStrValue );
+ if( xGlobSect->GetStringValue( aStrValue, PROPID_SUBJECT ) )
+ i_xDocProps->setSubject( aStrValue );
+ if( xGlobSect->GetStringValue( aStrValue, PROPID_KEYWORDS ) ) {
+ i_xDocProps->setKeywords(
+ ::comphelper::string::convertCommaSeparated(aStrValue) );
+ }
+ if( xGlobSect->GetStringValue( aStrValue, PROPID_TEMPLATE ) )
+ i_xDocProps->setTemplateName( aStrValue );
+ if( xGlobSect->GetStringValue( aStrValue, PROPID_COMMENTS ) )
+ i_xDocProps->setDescription( aStrValue );
+
+ util::DateTime aInvalid;
+ if( xGlobSect->GetStringValue( aStrValue, PROPID_AUTHOR) )
+ i_xDocProps->setAuthor( aStrValue );
+ else
+ i_xDocProps->setAuthor( ::rtl::OUString() );
+ if( xGlobSect->GetFileTimeValue( aDateTime, PROPID_CREATED ) )
+ i_xDocProps->setCreationDate( aDateTime );
+ else
+ i_xDocProps->setCreationDate( aInvalid );
+
+ if( xGlobSect->GetStringValue( aStrValue, PROPID_LASTAUTHOR) )
+ i_xDocProps->setModifiedBy( aStrValue );
+ else
+ i_xDocProps->setModifiedBy( ::rtl::OUString() );
+ if( xGlobSect->GetFileTimeValue( aDateTime, PROPID_LASTSAVED ) )
+ i_xDocProps->setModificationDate( aDateTime );
+ else
+ i_xDocProps->setModificationDate( aInvalid );
+
+ i_xDocProps->setPrintedBy( ::rtl::OUString() );
+ if( xGlobSect->GetFileTimeValue( aDateTime, PROPID_LASTPRINTED ) )
+ i_xDocProps->setPrintDate( aDateTime );
+ else
+ i_xDocProps->setPrintDate( aInvalid );
+
+ if( xGlobSect->GetStringValue( aStrValue, PROPID_REVNUMBER ) )
+ {
+ sal_Int16 nRevision = static_cast< sal_Int16 >( aStrValue.ToInt32() );
+ if ( nRevision > 0 )
+ i_xDocProps->setEditingCycles( nRevision );
+ }
+
+ if( xGlobSect->GetFileTimeValue( aDateTime, PROPID_EDITTIME ) )
+ {
+ // subtract offset 1601-01-01
+ aDateTime.Year -= 1601;
+ aDateTime.Month -= 1;
+ aDateTime.Day -= 1;
+ try
+ {
+ i_xDocProps->setEditingDuration(
+ aDateTime.Day * 60*60*24 +
+ aDateTime.Hours * 60*60 +
+ aDateTime.Minutes * 60 +
+ aDateTime.Seconds );
+ }
+ catch (lang::IllegalArgumentException &)
+ {
+ // ignore
+ }
+ }
+ }
+
+ // *** custom properties from stream "005DocumentSummaryInformation" ***
+
+ // load the property set
+ SfxOlePropertySet aDocSet;
+ ErrCode nDocError = aDocSet.LoadPropertySet(i_pStorage,
+ String( RTL_CONSTASCII_USTRINGPARAM( STREAM_DOCSUMMARYINFO ) ) );
+
+ // custom properties
+ SfxOleSectionRef xCustomSect = aDocSet.GetSection( SECTION_CUSTOM );
+ if( xCustomSect.get() )
+ {
+ uno::Reference < beans::XPropertyContainer > xUserDefined(
+ i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+ ::std::vector< sal_Int32 > aPropIds;
+ xCustomSect->GetPropertyIds( aPropIds );
+ for( ::std::vector< sal_Int32 >::const_iterator aIt = aPropIds.begin(),
+ aEnd = aPropIds.end(); aIt != aEnd; ++aIt )
+ {
+ ::rtl::OUString aPropName = xCustomSect->GetPropertyName( *aIt );
+ uno::Any aPropValue = xCustomSect->GetAnyValue( *aIt );
+ if( (aPropName.getLength() > 0) && aPropValue.hasValue() ) {
+ try {
+ xUserDefined->addProperty( aPropName,
+ beans::PropertyAttribute::REMOVEABLE, aPropValue );
+ } catch ( uno::Exception& ) {
+ //ignore
+ }
+ }
+ }
+ }
+
+ // return code
+ return (nGlobError != ERRCODE_NONE) ? nGlobError : nDocError;
+}
+
+bool SFX2_DLLPUBLIC SaveOlePropertySet(
+ uno::Reference< document::XDocumentProperties> i_xDocProps,
+ SotStorage* i_pStorage,
+ const uno::Sequence<sal_uInt8> * i_pThumb,
+ const uno::Sequence<sal_uInt8> * i_pGuid,
+ const uno::Sequence<sal_uInt8> * i_pHyperlinks)
+{
+ // *** global properties into stream "005SummaryInformation" ***
+
+ SfxOlePropertySet aGlobSet;
+
+ // set supported properties
+ SfxOleSection& rGlobSect = aGlobSet.AddSection( SECTION_GLOBAL );
+ rGlobSect.SetStringValue( PROPID_TITLE, i_xDocProps->getTitle() );
+ rGlobSect.SetStringValue( PROPID_SUBJECT, i_xDocProps->getSubject() );
+ String aStr = ::comphelper::string::convertCommaSeparated(
+ i_xDocProps->getKeywords() );
+ rGlobSect.SetStringValue( PROPID_KEYWORDS, aStr );
+ rGlobSect.SetStringValue( PROPID_TEMPLATE, i_xDocProps->getTemplateName() );
+ rGlobSect.SetStringValue( PROPID_COMMENTS, i_xDocProps->getDescription() );
+ rGlobSect.SetStringValue( PROPID_AUTHOR, i_xDocProps->getAuthor() );
+ rGlobSect.SetFileTimeValue(PROPID_CREATED, i_xDocProps->getCreationDate());
+ rGlobSect.SetStringValue( PROPID_LASTAUTHOR, i_xDocProps->getModifiedBy() );
+ rGlobSect.SetFileTimeValue(PROPID_LASTSAVED,
+ i_xDocProps->getModificationDate() );
+ // note: apparently PrintedBy is not supported in file format
+ rGlobSect.SetFileTimeValue(PROPID_LASTPRINTED, i_xDocProps->getPrintDate());
+
+ sal_Int32 dur = i_xDocProps->getEditingDuration();
+ util::DateTime aEditTime;
+ // add offset 1601-01-01
+ aEditTime.Year = 1601;
+ aEditTime.Month = 1;
+ aEditTime.Day = 1;
+ aEditTime.Hours = static_cast<sal_Int16>(dur / 3600);
+ aEditTime.Minutes = static_cast<sal_Int16>((dur % 3600) / 60);
+ aEditTime.Seconds = static_cast<sal_Int16>(dur % 60);
+ rGlobSect.SetFileTimeValue( PROPID_EDITTIME, aEditTime );
+
+ rGlobSect.SetStringValue( PROPID_REVNUMBER,
+ String::CreateFromInt32( i_xDocProps->getEditingCycles() ) );
+ if ( i_pThumb && i_pThumb->getLength() )
+ rGlobSect.SetThumbnailValue( PROPID_THUMBNAIL, *i_pThumb );
+
+ // save the property set
+ ErrCode nGlobError = aGlobSet.SavePropertySet(i_pStorage,
+ String( RTL_CONSTASCII_USTRINGPARAM( STREAM_SUMMARYINFO ) ) );
+
+ // *** custom properties into stream "005DocumentSummaryInformation" ***
+
+ SfxOlePropertySet aDocSet;
+
+ // set builtin properties
+ aDocSet.AddSection( SECTION_BUILTIN );
+
+ // set custom properties
+ SfxOleSection& rCustomSect = aDocSet.AddSection( SECTION_CUSTOM );
+
+ // write GUID
+ if (i_pGuid) {
+ const sal_Int32 nPropId = rCustomSect.GetFreePropertyId();
+ rCustomSect.SetBlobValue( nPropId, *i_pGuid );
+ rCustomSect.SetPropertyName( nPropId,
+ ::rtl::OUString::createFromAscii("_PID_GUID") );
+ }
+
+ // write hyperlinks
+ if (i_pHyperlinks) {
+ const sal_Int32 nPropId = rCustomSect.GetFreePropertyId();
+ rCustomSect.SetBlobValue( nPropId, *i_pHyperlinks );
+ rCustomSect.SetPropertyName( nPropId,
+ ::rtl::OUString::createFromAscii("_PID_HLINKS") );
+ }
+
+ uno::Reference<beans::XPropertySet> xUserDefinedProps(
+ i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+ DBG_ASSERT(xUserDefinedProps.is(), "UserDefinedProperties is null");
+ uno::Reference<beans::XPropertySetInfo> xPropInfo =
+ xUserDefinedProps->getPropertySetInfo();
+ DBG_ASSERT(xPropInfo.is(), "UserDefinedProperties Info is null");
+ uno::Sequence<beans::Property> props = xPropInfo->getProperties();
+ for (sal_Int32 i = 0; i < props.getLength(); ++i) {
+ try {
+ // skip transient properties
+ if (~props[i].Attributes & beans::PropertyAttribute::TRANSIENT)
+ {
+ const ::rtl::OUString name = props[i].Name;
+ const sal_Int32 nPropId = rCustomSect.GetFreePropertyId();
+ if (rCustomSect.SetAnyValue( nPropId,
+ xUserDefinedProps->getPropertyValue(name))) {
+ rCustomSect.SetPropertyName( nPropId, name );
+ }
+ }
+ } catch (uno::Exception &) {
+ // may happen with concurrent modification...
+ DBG_WARNING("SavePropertySet: exception");
+ }
+ }
+
+ // save the property set
+ ErrCode nDocError = aDocSet.SavePropertySet(i_pStorage,
+ String( RTL_CONSTASCII_USTRINGPARAM( STREAM_DOCSUMMARYINFO ) ) );
+
+ // return code
+ return (nGlobError == ERRCODE_NONE) && (nDocError == ERRCODE_NONE);
+}
+
+uno::Sequence<sal_uInt8> SFX2_DLLPUBLIC convertMetaFile(GDIMetaFile* i_pThumb)
+{
+ if (i_pThumb) {
+ BitmapEx aBitmap;
+ SvMemoryStream aStream;
+// magic value 160 taken from GraphicHelper::getThumbnailFormatFromGDI_Impl()
+ if( i_pThumb->CreateThumbnail( 160, aBitmap ) ) {
+ aBitmap.GetBitmap().Write( aStream, FALSE, FALSE );
+// uno::Sequence<sal_uInt8> aSeq(aStream.GetSize()); // WRONG
+ aStream.Seek(STREAM_SEEK_TO_END);
+ uno::Sequence<sal_uInt8> aSeq(aStream.Tell());
+ const sal_uInt8* pBlob(
+ static_cast<const sal_uInt8*>(aStream.GetData()));
+ for (sal_Int32 j = 0; j < aSeq.getLength(); ++j) {
+ aSeq[j] = pBlob[j];
+ }
+ return aSeq;
+ }
+ }
+ return uno::Sequence<sal_uInt8>();
+}
+
+} // namespace sfx2
+
diff --git a/sfx2/source/doc/docinsert.cxx b/sfx2/source/doc/docinsert.cxx
new file mode 100644
index 000000000000..360854dc3dbf
--- /dev/null
+++ b/sfx2/source/doc/docinsert.cxx
@@ -0,0 +1,305 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sfx2/app.hxx>
+#include "sfx2/docinsert.hxx"
+#include <sfx2/docfile.hxx>
+#include <sfx2/fcontnr.hxx>
+#include <sfx2/filedlghelper.hxx>
+#include "openflag.hxx"
+#include <sfx2/passwd.hxx>
+
+#include <sfx2/sfxsids.hrc>
+#include <com/sun/star/ui/dialogs/ControlActions.hpp>
+#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
+#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <tools/urlobj.hxx>
+#include <vcl/msgbox.hxx>
+#include <svl/itemset.hxx>
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/stritem.hxx>
+
+#define _SVSTDARR_STRINGSDTOR
+#include <svl/svstdarr.hxx>
+
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::ui::dialogs;
+using namespace ::com::sun::star::uno;
+
+// implemented in 'sfx2/source/appl/appopen.cxx'
+extern sal_uInt32 CheckPasswd_Impl( SfxObjectShell* pDoc, SfxItemPool &rPool, SfxMedium* pFile );
+
+// =======================================================================
+
+namespace sfx2 {
+
+// =======================================================================
+
+// =======================================================================
+// DocumentInserter
+// =======================================================================
+
+DocumentInserter::DocumentInserter(
+ sal_Int64 _nFlags, const String& _rFactory, bool _bEnableMultiSelection ) :
+
+ m_sDocFactory ( _rFactory )
+ , m_bMultiSelectionEnabled ( _bEnableMultiSelection )
+ , m_nDlgFlags ( _nFlags | SFXWB_INSERT | WB_3DLOOK )
+ , m_nError ( ERRCODE_NONE )
+ , m_pFileDlg ( NULL )
+ , m_pItemSet ( NULL )
+ , m_pURLList ( NULL )
+
+{
+}
+
+DocumentInserter::~DocumentInserter()
+{
+ delete m_pFileDlg;
+}
+
+void DocumentInserter::StartExecuteModal( const Link& _rDialogClosedLink )
+{
+ m_aDialogClosedLink = _rDialogClosedLink;
+ m_nError = ERRCODE_NONE;
+ DELETEZ( m_pURLList );
+ if ( !m_pFileDlg )
+ {
+ sal_Int64 nFlags = m_bMultiSelectionEnabled ? ( m_nDlgFlags | SFXWB_MULTISELECTION )
+ : m_nDlgFlags;
+ m_pFileDlg = new FileDialogHelper( nFlags, m_sDocFactory );
+ }
+ m_pFileDlg->StartExecuteModal( LINK( this, DocumentInserter, DialogClosedHdl ) );
+}
+
+SfxMedium* DocumentInserter::CreateMedium()
+{
+ SfxMedium* pMedium = NULL;
+ if ( !m_nError && m_pItemSet && m_pURLList && m_pURLList->Count() > 0 )
+ {
+ DBG_ASSERT( m_pURLList->Count() == 1, "DocumentInserter::CreateMedium(): invalid URL list count" );
+ String sURL = *( m_pURLList->GetObject(0) );
+ pMedium = new SfxMedium(
+ sURL, SFX_STREAM_READONLY, FALSE,
+ SFX_APP()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), m_pItemSet );
+ pMedium->UseInteractionHandler( TRUE );
+ SfxFilterMatcher* pMatcher = NULL;
+ if ( m_sDocFactory.Len() )
+ pMatcher = new SfxFilterMatcher( m_sDocFactory );
+ else
+ pMatcher = new SfxFilterMatcher();
+
+ const SfxFilter* pFilter = NULL;
+ sal_uInt32 nError = pMatcher->DetectFilter( *pMedium, &pFilter, FALSE );
+ if ( nError == ERRCODE_NONE && pFilter )
+ pMedium->SetFilter( pFilter );
+ else
+ DELETEZ( pMedium );
+
+ if ( pMedium && CheckPasswd_Impl( 0, SFX_APP()->GetPool(), pMedium ) == ERRCODE_ABORT )
+ pMedium = NULL;
+
+ DELETEZ( pMatcher );
+ }
+
+ return pMedium;
+}
+
+SfxMediumList* DocumentInserter::CreateMediumList()
+{
+ SfxMediumList* pMediumList = new SfxMediumList;
+ if ( !m_nError && m_pItemSet && m_pURLList && m_pURLList->Count() > 0 )
+ {
+ sal_Int32 i = 0;
+ sal_Int32 nCount = m_pURLList->Count();
+ for ( ; i < nCount; ++i )
+ {
+ String sURL = *( m_pURLList->GetObject( static_cast< USHORT >(i) ) );
+ SfxMedium* pMedium = new SfxMedium(
+ sURL, SFX_STREAM_READONLY, FALSE,
+ SFX_APP()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), m_pItemSet );
+
+ pMedium->UseInteractionHandler( TRUE );
+
+ SfxFilterMatcher aMatcher( m_sDocFactory );
+ const SfxFilter* pFilter = NULL;
+ sal_uInt32 nError = aMatcher.DetectFilter( *pMedium, &pFilter, FALSE );
+ if ( nError == ERRCODE_NONE && pFilter )
+ pMedium->SetFilter( pFilter );
+ else
+ DELETEZ( pMedium );
+
+ if( pMedium && CheckPasswd_Impl( 0, SFX_APP()->GetPool(), pMedium ) != ERRCODE_ABORT )
+ pMediumList->Insert( pMedium );
+ else
+ delete pMedium;
+ }
+ }
+
+ return pMediumList;
+}
+
+void impl_FillURLList( sfx2::FileDialogHelper* _pFileDlg, SvStringsDtor*& _rpURLList )
+{
+ DBG_ASSERT( _pFileDlg, "DocumentInserter::fillURLList(): invalid file dialog" );
+ DBG_ASSERT( !_rpURLList, "DocumentInserter::fillURLList(): URLList already exists" );
+ Sequence < ::rtl::OUString > aPathSeq = _pFileDlg->GetSelectedFiles();
+
+ if ( aPathSeq.getLength() )
+ {
+ _rpURLList = new SvStringsDtor;
+
+ for ( USHORT i = 0; i < aPathSeq.getLength(); ++i )
+ {
+ INetURLObject aPathObj( aPathSeq[i] );
+ String* pURL = new String( aPathObj.GetMainURL( INetURLObject::NO_DECODE ) );
+ _rpURLList->Insert( pURL, _rpURLList->Count() );
+ }
+ }
+}
+
+IMPL_LINK( DocumentInserter, DialogClosedHdl, sfx2::FileDialogHelper*, EMPTYARG )
+{
+ DBG_ASSERT( m_pFileDlg, "DocumentInserter::DialogClosedHdl(): no file dialog" );
+
+ m_nError = m_pFileDlg->GetError();
+ if ( ERRCODE_NONE == m_nError )
+ impl_FillURLList( m_pFileDlg, m_pURLList );
+
+ Reference < XFilePicker > xFP = m_pFileDlg->GetFilePicker();
+ Reference < XFilePickerControlAccess > xCtrlAccess( xFP, UNO_QUERY );
+ if ( xCtrlAccess.is() )
+ {
+ // always create a new itemset
+ m_pItemSet = new SfxAllItemSet( SFX_APP()->GetPool() );
+
+ short nDlgType = m_pFileDlg->GetDialogType();
+ bool bHasPassword = (
+ TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD == nDlgType
+ || TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS == nDlgType );
+
+ // check, wether or not we have to display a password box
+ if ( bHasPassword && m_pFileDlg->IsPasswordEnabled() )
+ {
+ try
+ {
+ Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
+ sal_Bool bPassWord = sal_False;
+ if ( ( aValue >>= bPassWord ) && bPassWord )
+ {
+ // ask for the password
+ SfxPasswordDialog aPasswordDlg( NULL );
+ aPasswordDlg.ShowExtras( SHOWEXTRAS_CONFIRM );
+ short nRet = aPasswordDlg.Execute();
+ if ( RET_OK == nRet )
+ {
+ String aPasswd = aPasswordDlg.GetPassword();
+ m_pItemSet->Put( SfxStringItem( SID_PASSWORD, aPasswd ) );
+ }
+ else
+ {
+ DELETEZ( m_pItemSet );
+ return 0;
+ }
+ }
+ }
+ catch( IllegalArgumentException ){}
+ }
+
+ if ( SFXWB_EXPORT == ( m_nDlgFlags & SFXWB_EXPORT ) )
+ {
+ try
+ {
+ Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
+ sal_Bool bSelection = sal_False;
+ if ( aValue >>= bSelection )
+ m_pItemSet->Put( SfxBoolItem( SID_SELECTION, bSelection ) );
+ }
+ catch( IllegalArgumentException )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
+ }
+ }
+
+
+ // set the read-only flag. When inserting a file, this flag is always set
+ if ( SFXWB_INSERT == ( m_nDlgFlags & SFXWB_INSERT ) )
+ m_pItemSet->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
+ else
+ {
+ if ( ( TemplateDescription::FILEOPEN_READONLY_VERSION == nDlgType ) )
+ {
+ try
+ {
+ Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 );
+ sal_Bool bReadOnly = sal_False;
+ if ( ( aValue >>= bReadOnly ) && bReadOnly )
+ m_pItemSet->Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
+ }
+ catch( IllegalArgumentException )
+ {
+ DBG_ERROR( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
+ }
+ }
+ }
+
+ if ( TemplateDescription::FILEOPEN_READONLY_VERSION == nDlgType )
+ {
+ try
+ {
+ Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
+ ControlActions::GET_SELECTED_ITEM_INDEX );
+ sal_Int32 nVersion = 0;
+ if ( ( aValue >>= nVersion ) && nVersion > 0 )
+ // open a special version; 0 == current version
+ m_pItemSet->Put( SfxInt16Item( SID_VERSION, (short)nVersion ) );
+ }
+ catch( IllegalArgumentException ){}
+ }
+ }
+
+ m_sFilter = m_pFileDlg->GetRealFilter();
+
+ if ( m_aDialogClosedLink.IsSet() )
+ m_aDialogClosedLink.Call( m_pFileDlg );
+
+ return 0;
+}
+
+// =======================================================================
+
+} // namespace sfx2
+
+// =======================================================================
+
diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx
new file mode 100644
index 000000000000..249ebbaf02ab
--- /dev/null
+++ b/sfx2/source/doc/docmacromode.cxx
@@ -0,0 +1,436 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "sfx2/docmacromode.hxx"
+#include "sfx2/signaturestate.hxx"
+#include "sfx2/docfile.hxx"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/task/ErrorCodeRequest.hpp>
+#include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp>
+#include <com/sun/star/task/InteractionClassification.hpp>
+#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+/** === end UNO includes === **/
+
+#include <comphelper/componentcontext.hxx>
+#include <comphelper/processfactory.hxx>
+#include <framework/interaction.hxx>
+#include <osl/file.hxx>
+#include <rtl/ref.hxx>
+#include <unotools/securityoptions.hxx>
+#include <svtools/sfxecode.hxx>
+#include <tools/diagnose_ex.h>
+#include <tools/urlobj.hxx>
+
+//........................................................................
+namespace sfx2
+{
+//........................................................................
+
+ /** === begin UNO using === **/
+ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::task::XInteractionHandler;
+ using ::com::sun::star::uno::Any;
+ using ::com::sun::star::task::XInteractionHandler;
+ using ::com::sun::star::uno::Sequence;
+ using ::com::sun::star::task::XInteractionContinuation;
+ using ::com::sun::star::task::XInteractionRequest;
+ using ::com::sun::star::task::DocumentMacroConfirmationRequest;
+ using ::com::sun::star::task::ErrorCodeRequest;
+ using ::com::sun::star::uno::Exception;
+ using ::com::sun::star::security::XDocumentDigitalSignatures;
+ using ::com::sun::star::security::DocumentSignatureInformation;
+ using ::com::sun::star::embed::XStorage;
+ using ::com::sun::star::task::InteractionClassification_QUERY;
+ using ::com::sun::star::document::XEmbeddedScripts;
+ using ::com::sun::star::uno::UNO_SET_THROW;
+ using ::com::sun::star::script::XLibraryContainer;
+ using ::com::sun::star::container::XNameAccess;
+ using ::com::sun::star::uno::UNO_QUERY_THROW;
+ /** === end UNO using === **/
+ namespace MacroExecMode = ::com::sun::star::document::MacroExecMode;
+
+ //====================================================================
+ //= DocumentMacroMode_Data
+ //====================================================================
+ struct DocumentMacroMode_Data
+ {
+ IMacroDocumentAccess& m_rDocumentAccess;
+ sal_Bool m_bMacroDisabledMessageShown;
+ sal_Bool m_bDocMacroDisabledMessageShown;
+
+ DocumentMacroMode_Data( IMacroDocumentAccess& rDocumentAccess )
+ :m_rDocumentAccess( rDocumentAccess )
+ ,m_bMacroDisabledMessageShown( sal_False )
+ ,m_bDocMacroDisabledMessageShown( sal_False )
+ {
+ }
+ };
+
+ //====================================================================
+ //= helper
+ //====================================================================
+ namespace
+ {
+ //................................................................
+ void lcl_showGeneralSfxErrorOnce( const Reference< XInteractionHandler >& rxHandler, const sal_Int32 nSfxErrorCode, sal_Bool& rbAlreadyShown )
+ {
+ if ( rbAlreadyShown )
+ return;
+
+ ErrorCodeRequest aErrorCodeRequest;
+ aErrorCodeRequest.ErrCode = nSfxErrorCode;
+
+ SfxMedium::CallApproveHandler( rxHandler, makeAny( aErrorCodeRequest ), sal_False );
+ rbAlreadyShown = sal_True;
+ }
+
+ //................................................................
+ void lcl_showMacrosDisabledError( const Reference< XInteractionHandler >& rxHandler, sal_Bool& rbAlreadyShown )
+ {
+ lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_MACROS_SUPPORT_DISABLED, rbAlreadyShown );
+ }
+
+ //................................................................
+ void lcl_showDocumentMacrosDisabledError( const Reference< XInteractionHandler >& rxHandler, sal_Bool& rbAlreadyShown )
+ {
+ lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_DOCUMENT_MACRO_DISABLED, rbAlreadyShown );
+ }
+
+ //................................................................
+ sal_Bool lcl_showMacroWarning( const Reference< XInteractionHandler >& rxHandler,
+ const ::rtl::OUString& rDocumentLocation )
+ {
+ DocumentMacroConfirmationRequest aRequest;
+ aRequest.DocumentURL = rDocumentLocation;
+ return SfxMedium::CallApproveHandler( rxHandler, makeAny( aRequest ), sal_True );
+ }
+ }
+
+ //====================================================================
+ //= DocumentMacroMode
+ //====================================================================
+ //--------------------------------------------------------------------
+ DocumentMacroMode::DocumentMacroMode( IMacroDocumentAccess& rDocumentAccess )
+ :m_pData( new DocumentMacroMode_Data( rDocumentAccess ) )
+ {
+ }
+
+ //--------------------------------------------------------------------
+ DocumentMacroMode::~DocumentMacroMode()
+ {
+ }
+
+ //--------------------------------------------------------------------
+ sal_Bool DocumentMacroMode::allowMacroExecution()
+ {
+ m_pData->m_rDocumentAccess.setCurrentMacroExecMode( MacroExecMode::ALWAYS_EXECUTE_NO_WARN );
+ return sal_True;
+ }
+
+ //--------------------------------------------------------------------
+ sal_Bool DocumentMacroMode::disallowMacroExecution()
+ {
+ m_pData->m_rDocumentAccess.setCurrentMacroExecMode( MacroExecMode::NEVER_EXECUTE );
+ return sal_False;
+ }
+
+ //--------------------------------------------------------------------
+ sal_Bool DocumentMacroMode::adjustMacroMode( const Reference< XInteractionHandler >& rxInteraction )
+ {
+ sal_uInt16 nMacroExecutionMode = m_pData->m_rDocumentAccess.getCurrentMacroExecMode();
+
+ if ( SvtSecurityOptions().IsMacroDisabled() )
+ {
+ // no macro should be executed at all
+ lcl_showMacrosDisabledError( rxInteraction, m_pData->m_bMacroDisabledMessageShown );
+ return disallowMacroExecution();
+ }
+
+ // get setting from configuration if required
+ enum AutoConfirmation
+ {
+ eNoAutoConfirm,
+ eAutoConfirmApprove,
+ eAutoConfirmReject
+ };
+ AutoConfirmation eAutoConfirm( eNoAutoConfirm );
+
+ if ( ( nMacroExecutionMode == MacroExecMode::USE_CONFIG )
+ || ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_REJECT_CONFIRMATION )
+ || ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_APPROVE_CONFIRMATION )
+ )
+ {
+ SvtSecurityOptions aOpt;
+ switch ( aOpt.GetMacroSecurityLevel() )
+ {
+ case 3:
+ nMacroExecutionMode = MacroExecMode::FROM_LIST_NO_WARN;
+ break;
+ case 2:
+ nMacroExecutionMode = MacroExecMode::FROM_LIST_AND_SIGNED_WARN;
+ break;
+ case 1:
+ nMacroExecutionMode = MacroExecMode::ALWAYS_EXECUTE;
+ break;
+ case 0:
+ nMacroExecutionMode = MacroExecMode::ALWAYS_EXECUTE_NO_WARN;
+ break;
+ default:
+ OSL_ENSURE( sal_False, "DocumentMacroMode::adjustMacroMode: unexpected macro security level!" );
+ nMacroExecutionMode = MacroExecMode::NEVER_EXECUTE;
+ }
+
+ if ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_REJECT_CONFIRMATION )
+ eAutoConfirm = eAutoConfirmReject;
+ else if ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_APPROVE_CONFIRMATION )
+ eAutoConfirm = eAutoConfirmApprove;
+ }
+
+ if ( nMacroExecutionMode == MacroExecMode::NEVER_EXECUTE )
+ return sal_False;
+
+ if ( nMacroExecutionMode == MacroExecMode::ALWAYS_EXECUTE_NO_WARN )
+ return sal_True;
+
+ try
+ {
+ ::rtl::OUString sReferrer( m_pData->m_rDocumentAccess.getDocumentLocation() );
+
+ // get document location from medium name and check whether it is a trusted one
+ // the service is created ohne document version, since it is not of interest here
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ Reference< XDocumentDigitalSignatures > xSignatures;
+ if ( aContext.createComponent( "com.sun.star.security.DocumentDigitalSignatures", xSignatures ) )
+ {
+ INetURLObject aURLReferer( sReferrer );
+
+ ::rtl::OUString aLocation;
+ if ( aURLReferer.removeSegment() )
+ aLocation = aURLReferer.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( aLocation.getLength() && xSignatures->isLocationTrusted( aLocation ) )
+ {
+ return allowMacroExecution();
+ }
+ }
+
+ // at this point it is clear that the document is not in the secure location
+ if ( nMacroExecutionMode == MacroExecMode::FROM_LIST_NO_WARN )
+ {
+ lcl_showDocumentMacrosDisabledError( rxInteraction, m_pData->m_bDocMacroDisabledMessageShown );
+ return disallowMacroExecution();
+ }
+
+ // check whether the document is signed with trusted certificate
+ if ( nMacroExecutionMode != MacroExecMode::FROM_LIST )
+ {
+ // the trusted macro check will also retrieve the signature state ( small optimization )
+ sal_Bool bHasTrustedMacroSignature = m_pData->m_rDocumentAccess.hasTrustedScriptingSignature( nMacroExecutionMode != MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN );
+
+ sal_uInt16 nSignatureState = m_pData->m_rDocumentAccess.getScriptingSignatureState();
+ if ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN )
+ {
+ // the signature is broken, no macro execution
+ if ( nMacroExecutionMode != MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN )
+ m_pData->m_rDocumentAccess.showBrokenSignatureWarning( rxInteraction );
+
+ return disallowMacroExecution();
+ }
+ else if ( bHasTrustedMacroSignature )
+ {
+ // there is trusted macro signature, allow macro execution
+ return allowMacroExecution();
+ }
+ else if ( nSignatureState == SIGNATURESTATE_SIGNATURES_OK
+ || nSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
+ {
+ // there is valid signature, but it is not from the trusted author
+ return disallowMacroExecution();
+ }
+ }
+
+ // at this point it is clear that the document is neither in secure location nor signed with trusted certificate
+ if ( ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN )
+ || ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN )
+ )
+ {
+ if ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN )
+ lcl_showDocumentMacrosDisabledError( rxInteraction, m_pData->m_bDocMacroDisabledMessageShown );
+
+ return disallowMacroExecution();
+ }
+ }
+ catch ( Exception& )
+ {
+ if ( ( nMacroExecutionMode == MacroExecMode::FROM_LIST_NO_WARN )
+ || ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN )
+ || ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN )
+ )
+ {
+ return disallowMacroExecution();
+ }
+ }
+
+ // conformation is required
+ sal_Bool bSecure = sal_False;
+
+ if ( eAutoConfirm == eNoAutoConfirm )
+ {
+ ::rtl::OUString sReferrer( m_pData->m_rDocumentAccess.getDocumentLocation() );
+
+ ::rtl::OUString aSystemFileURL;
+ if ( osl::FileBase::getSystemPathFromFileURL( sReferrer, aSystemFileURL ) == osl::FileBase::E_None )
+ sReferrer = aSystemFileURL;
+
+ bSecure = lcl_showMacroWarning( rxInteraction, sReferrer );
+ }
+ else
+ bSecure = ( eAutoConfirm == eAutoConfirmApprove );
+
+ return ( bSecure ? allowMacroExecution() : disallowMacroExecution() );
+ }
+
+ //--------------------------------------------------------------------
+ sal_Bool DocumentMacroMode::isMacroExecutionDisallowed() const
+ {
+ return m_pData->m_rDocumentAccess.getCurrentMacroExecMode() == MacroExecMode::NEVER_EXECUTE;
+ }
+
+ //--------------------------------------------------------------------
+ sal_Bool DocumentMacroMode::hasMacroLibrary() const
+ {
+ sal_Bool bHasMacroLib = sal_False;
+ try
+ {
+ Reference< XEmbeddedScripts > xScripts( m_pData->m_rDocumentAccess.getEmbeddedDocumentScripts() );
+ Reference< XLibraryContainer > xContainer;
+ if ( xScripts.is() )
+ xContainer.set( xScripts->getBasicLibraries(), UNO_QUERY_THROW );
+
+ if ( xContainer.is() )
+ {
+ // a library container exists; check if it's empty
+
+ // if there are libraries except the "Standard" library
+ // we assume that they are not empty (because they have been created by the user)
+ if ( !xContainer->hasElements() )
+ bHasMacroLib = sal_False;
+ else
+ {
+ ::rtl::OUString aStdLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
+ Sequence< ::rtl::OUString > aElements = xContainer->getElementNames();
+ if ( aElements.getLength() )
+ {
+ if ( aElements.getLength() > 1 || !aElements[0].equals( aStdLibName ) )
+ bHasMacroLib = sal_True;
+ else
+ {
+ // usually a "Standard" library is always present (design)
+ // for this reason we must check if it's empty
+ //
+ // Note: Since #i73229#, this is not true anymore. There's no default
+ // "Standard" lib anymore. Wouldn't it be time to get completely
+ // rid of the "Standard" thingie - this shouldn't be necessary
+ // anymore, should it?
+ // 2007-01-25 / frank.schoenheit@sun.com
+ Reference < XNameAccess > xLib;
+ Any aAny = xContainer->getByName( aStdLibName );
+ aAny >>= xLib;
+ if ( xLib.is() )
+ bHasMacroLib = xLib->hasElements();
+ }
+ }
+ }
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
+ return bHasMacroLib;
+ }
+
+ //--------------------------------------------------------------------
+ sal_Bool DocumentMacroMode::storageHasMacros( const Reference< XStorage >& rxStorage )
+ {
+ sal_Bool bHasMacros = sal_False;
+ if ( rxStorage.is() )
+ {
+ try
+ {
+ static const ::rtl::OUString s_sBasicStorageName( ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "Basic" ) ) );
+ static const ::rtl::OUString s_sScriptsStorageName( ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "Scripts" ) ) );
+
+ bHasMacros =( ( rxStorage->hasByName( s_sBasicStorageName )
+ && rxStorage->isStorageElement( s_sBasicStorageName )
+ )
+ || ( rxStorage->hasByName( s_sScriptsStorageName )
+ && rxStorage->isStorageElement( s_sScriptsStorageName )
+ )
+ );
+ }
+ catch ( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+ return bHasMacros;
+ }
+
+ //--------------------------------------------------------------------
+ sal_Bool DocumentMacroMode::checkMacrosOnLoading( const Reference< XInteractionHandler >& rxInteraction )
+ {
+ sal_Bool bAllow = sal_False;
+ if ( SvtSecurityOptions().IsMacroDisabled() )
+ {
+ // no macro should be executed at all
+ bAllow = disallowMacroExecution();
+ }
+ else
+ {
+ if ( m_pData->m_rDocumentAccess.documentStorageHasMacros() || hasMacroLibrary() )
+ {
+ bAllow = adjustMacroMode( rxInteraction );
+ }
+ else if ( !isMacroExecutionDisallowed() )
+ {
+ // if macros will be added by the user later, the security check is obsolete
+ bAllow = allowMacroExecution();
+ }
+ }
+ return bAllow;
+ }
+
+//........................................................................
+} // namespace sfx2
+//........................................................................
diff --git a/sfx2/source/doc/docstoragemodifylistener.cxx b/sfx2/source/doc/docstoragemodifylistener.cxx
new file mode 100644
index 000000000000..625aff0031fc
--- /dev/null
+++ b/sfx2/source/doc/docstoragemodifylistener.cxx
@@ -0,0 +1,96 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "sfx2/docstoragemodifylistener.hxx"
+#include <vos/mutex.hxx>
+
+/** === begin UNO includes === **/
+/** === end UNO includes === **/
+
+//........................................................................
+namespace sfx2
+{
+//........................................................................
+
+ /** === begin UNO using === **/
+ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::uno::XInterface;
+ using ::com::sun::star::uno::UNO_QUERY;
+ using ::com::sun::star::uno::UNO_QUERY_THROW;
+ using ::com::sun::star::uno::UNO_SET_THROW;
+ using ::com::sun::star::uno::Exception;
+ using ::com::sun::star::uno::RuntimeException;
+ using ::com::sun::star::uno::Any;
+ using ::com::sun::star::uno::makeAny;
+ using ::com::sun::star::lang::EventObject;
+ /** === end UNO using === **/
+
+ //====================================================================
+ //=
+ //====================================================================
+ //--------------------------------------------------------------------
+ DocumentStorageModifyListener::DocumentStorageModifyListener( IModifiableDocument& _rDocument, ::vos::IMutex& _rMutex )
+ :m_pDocument( &_rDocument )
+ ,m_rMutex( _rMutex )
+ {
+ }
+
+ //--------------------------------------------------------------------
+ DocumentStorageModifyListener::~DocumentStorageModifyListener()
+ {
+ }
+
+ //--------------------------------------------------------------------
+ void DocumentStorageModifyListener::dispose()
+ {
+ ::vos::OGuard aGuard( m_rMutex );
+ m_pDocument = NULL;
+ }
+
+ //--------------------------------------------------------------------
+ void SAL_CALL DocumentStorageModifyListener::modified( const EventObject& /*aEvent*/ ) throw (RuntimeException)
+ {
+ ::vos::OGuard aGuard( m_rMutex );
+ // storageIsModified must not contain any locking!
+ if ( m_pDocument )
+ m_pDocument->storageIsModified();
+ }
+
+ //--------------------------------------------------------------------
+ void SAL_CALL DocumentStorageModifyListener::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
+ {
+ // not interested in. In particular, we do *not* dispose ourself when a storage we're
+ // listening at is disposed. The reason here is that this listener instance is *reused*
+ // in case the document is re-based to another storage.
+ }
+
+//........................................................................
+} // namespace sfx2
+//........................................................................
diff --git a/sfx2/source/doc/doctdlg.cxx b/sfx2/source/doc/doctdlg.cxx
new file mode 100644
index 000000000000..e6726e97e96d
--- /dev/null
+++ b/sfx2/source/doc/doctdlg.cxx
@@ -0,0 +1,238 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#include <svl/stritem.hxx>
+#ifndef GCC
+#endif
+
+#include <sfx2/doctdlg.hxx>
+#include "docvor.hxx"
+#include "sfx2/sfxresid.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/dispatch.hxx>
+#include <sfx2/app.hxx>
+
+#include <sfx2/sfx.hrc>
+#include "doc.hrc"
+#include "doctdlg.hrc"
+#include <sfx2/basedlgs.hxx>
+
+//=========================================================================
+
+SfxDocumentTemplateDlg::SfxDocumentTemplateDlg( Window * pParent, SfxDocumentTemplates* pTempl ) :
+
+ ModalDialog( pParent, SfxResId( DLG_DOC_TEMPLATE ) ),
+
+ aEditFL ( this, SfxResId( FL_EDIT ) ),
+ aNameEd ( this, SfxResId( ED_NAME ) ),
+ aTemplateFL ( this, SfxResId( FL_STYLESHEETS ) ),
+ aRegionFt ( this, SfxResId( FT_SECTION ) ),
+ aRegionLb ( this, SfxResId( LB_SECTION ) ),
+ aTemplateFt ( this, SfxResId( FT_STYLESHEETS ) ),
+ aTemplateLb ( this, SfxResId( LB_STYLESHEETS ) ),
+
+ aOkBt ( this, SfxResId( BT_OK ) ),
+ aCancelBt ( this, SfxResId( BT_CANCEL ) ),
+ aHelpBt ( this, SfxResId( BT_HELP ) ),
+ aEditBt ( this, SfxResId( BT_EDIT ) ),
+ aOrganizeBt ( this, SfxResId( BT_ORGANIZE ) ),
+
+ pTemplates ( pTempl ),
+ pHelper ( NULL )
+
+{
+ FreeResource();
+
+ pHelper = new SfxModalDefParentHelper( this );
+ aOrganizeBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, OrganizeHdl));
+ aNameEd.SetModifyHdl(LINK(this, SfxDocumentTemplateDlg, NameModify));
+ aOkBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, OkHdl));
+ aEditBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, EditHdl));
+ Init();
+}
+
+//-------------------------------------------------------------------------
+
+SfxDocumentTemplateDlg::~SfxDocumentTemplateDlg()
+{
+ delete pHelper;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxDocumentTemplateDlg, EditHdl, Button *, pBut )
+{
+ (void)pBut; //unused
+ if ( !aRegionLb.GetSelectEntryCount() ||
+ !aTemplateLb.GetSelectEntryCount())
+ return 0;
+
+ const SfxStringItem aRegion( SID_TEMPLATE_REGIONNAME, aRegionLb.GetSelectEntry() );
+ const SfxStringItem aName( SID_TEMPLATE_NAME, aTemplateLb.GetSelectEntry() );
+ SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_OPENTEMPLATE, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD, &aRegion, &aName, 0L );
+ EndDialog(RET_EDIT_STYLE);
+
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDocumentTemplateDlg::Init()
+{
+ if(!pTemplates->IsConstructed())
+ pTemplates->Construct();
+
+ const USHORT nCount = pTemplates->GetRegionCount();
+ for(USHORT i = 0; i < nCount; ++i)
+ aRegionLb.InsertEntry(pTemplates->GetFullRegionName(i));
+ if(!nCount)
+ aRegionLb.InsertEntry(String(SfxResId(STR_STANDARD)));
+ aRegionLb.SelectEntryPos(0);
+ if(nCount)
+ {
+ aRegionLb.SetSelectHdl(LINK(this, SfxDocumentTemplateDlg, RegionSelect));
+ RegionSelect(&aRegionLb);
+ aTemplateLb.SetSelectHdl(LINK(this, SfxDocumentTemplateDlg, TemplateSelect));
+ aTemplateLb.SetDoubleClickHdl(LINK(this, SfxDocumentTemplateDlg, EditHdl));
+ }
+ else {
+ Link aLink;
+ aTemplateLb.SetSelectHdl(aLink);
+ aTemplateLb.SetDoubleClickHdl(aLink);
+ }
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxDocumentTemplateDlg, OrganizeHdl, Button *, pButton )
+{
+ (void)pButton; //unused
+ SfxTemplateOrganizeDlg *pDlg =
+ new SfxTemplateOrganizeDlg(this, pTemplates);
+ const short nRet = pDlg->Execute();
+ delete pDlg;
+ if(RET_OK == nRet)
+ {
+ // View aktualisieren
+ aRegionLb.SetUpdateMode( FALSE );
+ aRegionLb.Clear();
+ Init();
+ aRegionLb.SetUpdateMode( TRUE );
+ aRegionLb.Invalidate();
+ aRegionLb.Update();
+ aCancelBt.SetText(String(SfxResId(STR_CLOSE)));
+ }
+ else if(RET_EDIT_STYLE == nRet)
+ EndDialog(RET_CANCEL);
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxDocumentTemplateDlg, OkHdl, Control *, pControl )
+{
+ (void)pControl; //unused
+ // pruefen, ob eine Vorlage diesen Namens existiert
+ if(LISTBOX_ENTRY_NOTFOUND != aTemplateLb.GetEntryPos(
+ GetTemplateName())) {
+ QueryBox aQuery(this, SfxResId(MSG_CONFIRM_OVERWRITE_TEMPLATE));
+ if(RET_NO == aQuery.Execute())
+ return 0;
+ }
+ EndDialog(RET_OK);
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxDocumentTemplateDlg, RegionSelect, ListBox *, pBox )
+{
+ const USHORT nRegion = pBox->GetSelectEntryPos();
+ const USHORT nCount = pTemplates->GetCount(nRegion);
+ aTemplateLb.SetUpdateMode(FALSE);
+ aTemplateLb.Clear();
+ for(USHORT i = 0; i < nCount; ++i)
+ aTemplateLb.InsertEntry(pTemplates->GetName(nRegion, i));
+ aTemplateLb.SelectEntryPos(0);
+ aTemplateLb.SetUpdateMode(TRUE);
+ aTemplateLb.Invalidate();
+ aTemplateLb.Update();
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxDocumentTemplateDlg, TemplateSelect, ListBox *, pBox )
+{
+ aNameEd.SetText(pBox->GetSelectEntry());
+ NameModify(&aNameEd);
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxDocumentTemplateDlg, TemplateSelect, ListBox *, pBox )
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxDocumentTemplateDlg, NameModify, Edit *, pBox )
+{
+ const String &rText=pBox->GetText();
+ if(!rText.Len())
+ aEditBt.Enable();
+ else
+ {
+ aTemplateLb.SelectEntry(rText);
+ aEditBt.Enable( aTemplateLb.GetSelectEntry() == rText );
+ }
+
+ aOkBt.Enable( rText.Len() > 0 );
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+String SfxDocumentTemplateDlg::GetTemplatePath()
+{
+ const String& rPath=GetTemplateName();
+ if(pTemplates->GetRegionCount())
+ return pTemplates->GetTemplatePath(
+ aRegionLb.GetSelectEntryPos(), rPath);
+ return pTemplates->GetDefaultTemplatePath(rPath);
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDocumentTemplateDlg::NewTemplate(const String &rPath)
+{
+ pTemplates->NewTemplate(
+ aRegionLb.GetSelectEntryPos(), GetTemplateName(), rPath);
+}
+
diff --git a/sfx2/source/doc/doctdlg.hrc b/sfx2/source/doc/doctdlg.hrc
new file mode 100644
index 000000000000..8deed4699f3b
--- /dev/null
+++ b/sfx2/source/doc/doctdlg.hrc
@@ -0,0 +1,42 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#define FT_SECTION 1
+#define LB_SECTION 2
+#define FT_STYLESHEETS 3
+#define LB_STYLESHEETS 4
+#define BT_ORGANIZE 20
+#define BT_HELP 21
+#define FL_EDIT 5
+#define FT_NAME 6
+#define ED_NAME 7
+#define BT_OK 10
+#define BT_SECTION 11
+#define BT_EDIT 12
+#define BT_NEW 13
+#define BT_DELETE 15
+#define BT_CANCEL 16
+#define FL_STYLESHEETS 17
diff --git a/sfx2/source/doc/doctdlg.src b/sfx2/source/doc/doctdlg.src
new file mode 100644
index 000000000000..1b50fd56c55e
--- /dev/null
+++ b/sfx2/source/doc/doctdlg.src
@@ -0,0 +1,152 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <sfx2/sfx.hrc>
+#include "doc.hrc"
+#include "doctdlg.hrc"
+#include <sfx2/sfxcommands.h>
+
+ModalDialog DLG_DOC_TEMPLATE
+{
+ HelpId = CMD_SID_DOCTEMPLATE ;
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 280 , 128 ) ;
+ Text [ en-US ] = "Templates" ;
+ Moveable = TRUE ;
+ FixedLine FL_EDIT
+ {
+ Pos = MAP_APPFONT ( 6 , 3 ) ;
+ Size = MAP_APPFONT ( 212 , 8 ) ;
+ Text [ en-US ] = "New template" ;
+ };
+ Edit ED_NAME
+ {
+ HelpID = "sfx2:Edit:DLG_DOC_TEMPLATE:ED_NAME";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 12 , 14 ) ;
+ Size = MAP_APPFONT ( 200 , 12 ) ;
+ };
+ FixedLine FL_STYLESHEETS
+ {
+ Pos = MAP_APPFONT ( 6 , 32 ) ;
+ Size = MAP_APPFONT ( 212 , 8 ) ;
+ Text [ en-US ] = "Templates" ;
+ };
+ FixedText FT_SECTION
+ {
+ Pos = MAP_APPFONT ( 12 , 43 ) ;
+ Size = MAP_APPFONT ( 97 , 10 ) ;
+ Text [ en-US ] = "~Categories" ;
+ };
+ ListBox LB_SECTION
+ {
+ HelpID = "sfx2:ListBox:DLG_DOC_TEMPLATE:LB_SECTION";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 12 , 56 ) ;
+ Size = MAP_APPFONT ( 97 , 66 ) ;
+ };
+ FixedText FT_STYLESHEETS
+ {
+ Pos = MAP_APPFONT ( 115 , 43 ) ;
+ Size = MAP_APPFONT ( 97 , 10 ) ;
+ Text [ en-US ] = "~Templates" ;
+ };
+ ListBox LB_STYLESHEETS
+ {
+ HelpID = "sfx2:ListBox:DLG_DOC_TEMPLATE:LB_STYLESHEETS";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 115 , 56 ) ;
+ Size = MAP_APPFONT ( 97 , 66 ) ;
+ };
+ OKButton BT_OK
+ {
+ Pos = MAP_APPFONT ( 224 , 6 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ DefButton = TRUE ;
+ Disable = TRUE ;
+ };
+ CancelButton BT_CANCEL
+ {
+ Pos = MAP_APPFONT ( 224 , 23 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ };
+ HelpButton BT_HELP
+ {
+ Pos = MAP_APPFONT ( 224 , 43 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ };
+ PushButton BT_EDIT
+ {
+ HelpID = "sfx2:PushButton:DLG_DOC_TEMPLATE:BT_EDIT";
+ Pos = MAP_APPFONT ( 224 , 62 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~Edit" ;
+ };
+ PushButton BT_ORGANIZE
+ {
+ HelpID = "sfx2:PushButton:DLG_DOC_TEMPLATE:BT_ORGANIZE";
+ Pos = MAP_APPFONT ( 224 , 79 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~Organizer..." ;
+ };
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx
new file mode 100644
index 000000000000..f5ea04e5e08d
--- /dev/null
+++ b/sfx2/source/doc/doctempl.cxx
@@ -0,0 +1,2735 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <limits.h>
+#include <com/sun/star/uno/Any.h>
+#include <vos/mutex.hxx>
+#include <vos/thread.hxx>
+
+#ifndef _SV_RESARY_HXX
+#include <tools/resary.hxx>
+#endif
+#include <vcl/svapp.hxx>
+#include <vcl/settings.hxx>
+#include <unotools/localedatawrapper.hxx>
+#include <unotools/pathoptions.hxx>
+#include <tools/string.hxx>
+#include <tools/urlobj.hxx>
+#include <svtools/ehdl.hxx>
+#include <svtools/sfxecode.hxx>
+#include <comphelper/processfactory.hxx>
+#include <ucbhelper/content.hxx>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/document/XTypeDetection.hpp>
+#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XDocumentTemplates.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XPersist.hpp>
+#include <com/sun/star/lang/XLocalizable.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/ucb/ContentInfo.hpp>
+#include <com/sun/star/ucb/InsertCommandArgument.hpp>
+#include <com/sun/star/ucb/NameClash.hpp>
+#include <com/sun/star/ucb/TransferInfo.hpp>
+#include <com/sun/star/ucb/XCommandProcessor.hpp>
+#include <com/sun/star/ucb/XContent.hpp>
+#include <com/sun/star/ucb/XContentAccess.hpp>
+#include <com/sun/star/ucb/XAnyCompareFactory.hpp>
+#include <com/sun/star/ucb/XAnyCompare.hpp>
+#include <com/sun/star/ucb/NumberedSortingInfo.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+
+#include "sfxurlrelocator.hxx"
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::document;
+using namespace ::rtl;
+using namespace ::ucbhelper;
+
+
+#include <sfx2/doctempl.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/objsh.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/app.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "doc.hrc"
+#include <sfx2/fcontnr.hxx>
+#include <svtools/templatefoldercache.hxx>
+
+#include <comphelper/storagehelper.hxx>
+#include <unotools/ucbhelper.hxx>
+
+//========================================================================
+
+// #define DONT_USE_HIERARCHY
+
+#define TITLE "Title"
+#define IS_FOLDER "IsFolder"
+#define PROPERTY_TYPE "TypeDescription"
+#define TARGET_URL "TargetURL"
+#define TYPE_FOLDER "application/vnd.sun.star.hier-folder"
+#define TYPE_LINK "application/vnd.sun.star.hier-link"
+#define TYPE_FSYS_FOLDER "application/vnd.sun.staroffice.fsys-folder"
+
+#define TARGET_DIR_URL "TargetDirURL"
+#define COMMAND_DELETE "delete"
+#define COMMAND_TRANSFER "transfer"
+
+#define STANDARD_FOLDER "standard"
+
+#define SERVICENAME_TYPEDETECTION "com.sun.star.document.TypeDetection"
+#define TYPEDETECTION_PARAMETER "FileName"
+//#define SERVICENAME_OLD_TYPEDETECTION "com.sun.star.frame.FrameLoaderFactory"
+//#define PARAMETER_OLD_TYPEDETECTION "DeepDetection"
+#define SERVICENAME_DOCINFO "com.sun.star.document.DocumentProperties"
+#define SERVICENAME_DOCTEMPLATES "com.sun.star.frame.DocumentTemplates"
+#define SERVICENAME_DESKTOP "com.sun.star.frame.Desktop"
+
+//========================================================================
+
+class RegionData_Impl;
+
+namespace DocTempl {
+
+class DocTempl_EntryData_Impl
+{
+ RegionData_Impl* mpParent;
+ SfxObjectShellLock mxObjShell;
+ OUString maTitle;
+ OUString maOwnURL;
+ OUString maTargetURL;
+ sal_Bool mbIsOwner : 1;
+ sal_Bool mbDidConvert: 1;
+
+private:
+ RegionData_Impl* GetParent() const { return mpParent; }
+
+public:
+ DocTempl_EntryData_Impl( RegionData_Impl* pParent,
+ const OUString& rTitle );
+
+ const OUString& GetTitle() const { return maTitle; }
+ const OUString& GetTargetURL();
+ const OUString& GetHierarchyURL();
+
+ void SetTitle( const OUString& rTitle ) { maTitle = rTitle; }
+ void SetTargetURL( const OUString& rURL ) { maTargetURL = rURL; }
+ void SetHierarchyURL( const OUString& rURL) { maOwnURL = rURL; }
+
+ int Compare( const OUString& rTitle ) const;
+
+ SfxObjectShellRef CreateObjectShell();
+ sal_Bool DeleteObjectShell();
+};
+
+}
+
+using namespace ::DocTempl;
+
+// ------------------------------------------------------------------------
+
+class RegionData_Impl
+{
+ DECLARE_LIST( EntryList_Impl, DocTempl_EntryData_Impl* )
+ const SfxDocTemplate_Impl* mpParent;
+ EntryList_Impl maEntries;
+ OUString maTitle;
+ OUString maOwnURL;
+ OUString maTargetURL;
+
+private:
+ long GetEntryPos( const OUString& rTitle,
+ sal_Bool& rFound ) const;
+ const SfxDocTemplate_Impl* GetParent() const { return mpParent; }
+
+public:
+ RegionData_Impl( const SfxDocTemplate_Impl* pParent,
+ const OUString& rTitle );
+ ~RegionData_Impl();
+
+ void SetTargetURL( const OUString& rURL ) { maTargetURL = rURL; }
+ void SetHierarchyURL( const OUString& rURL) { maOwnURL = rURL; }
+
+ DocTempl_EntryData_Impl* GetEntry( ULONG nIndex ) const;
+ DocTempl_EntryData_Impl* GetEntry( const OUString& rName ) const;
+ DocTempl_EntryData_Impl* GetByTargetURL( const OUString& rName ) const;
+
+ const OUString& GetTitle() const { return maTitle; }
+ const OUString& GetTargetURL();
+ const OUString& GetHierarchyURL();
+
+ ULONG GetCount() const;
+
+ void SetTitle( const OUString& rTitle ) { maTitle = rTitle; }
+
+ void AddEntry( const OUString& rTitle,
+ const OUString& rTargetURL,
+ USHORT *pPos = NULL );
+ void DeleteEntry( ULONG nIndex );
+
+ int Compare( const OUString& rTitle ) const
+ { return maTitle.compareTo( rTitle ); }
+ int Compare( RegionData_Impl* pCompareWith ) const;
+};
+
+DECLARE_LIST( RegionList_Impl, RegionData_Impl* )
+
+// ------------------------------------------------------------------------
+
+class SfxDocTemplate_Impl : public SvRefBase
+{
+ uno::Reference< XPersist > mxInfo;
+ uno::Reference< XDocumentTemplates > mxTemplates;
+
+ ::osl::Mutex maMutex;
+ OUString maRootURL;
+ OUString maStandardGroup;
+ RegionList_Impl maRegions;
+ sal_Bool mbConstructed;
+
+ uno::Reference< XAnyCompareFactory > m_rCompareFactory;
+
+ // the following member is intended to prevent clearing of the global data when it is in use
+ // TODO/LATER: it still does not make the implementation complete thread-safe
+ sal_Int32 mnLockCounter;
+
+private:
+ void Clear();
+
+public:
+ SfxDocTemplate_Impl();
+ ~SfxDocTemplate_Impl();
+
+ void IncrementLock();
+ void DecrementLock();
+
+ sal_Bool Construct( );
+ void CreateFromHierarchy( Content &rTemplRoot );
+ void ReInitFromComponent();
+ void AddRegion( const OUString& rTitle,
+ Content& rContent );
+
+ void Rescan();
+
+ void DeleteRegion( ULONG nIndex );
+
+ ULONG GetRegionCount() const
+ { return maRegions.Count(); }
+ RegionData_Impl* GetRegion( const OUString& rName ) const;
+ RegionData_Impl* GetRegion( ULONG nIndex ) const;
+ void GetTemplates( Content& rTargetFolder,
+ Content& rParentFolder,
+ RegionData_Impl* pRegion );
+
+ long GetRegionPos( const OUString& rTitle,
+ sal_Bool& rFound ) const;
+
+ sal_Bool GetTitleFromURL( const OUString& rURL, OUString& aTitle );
+ sal_Bool InsertRegion( RegionData_Impl *pData, ULONG nPos = LIST_APPEND );
+ OUString GetRootURL() const { return maRootURL; }
+
+ uno::Reference< XDocumentTemplates > getDocTemplates() { return mxTemplates; }
+};
+
+// ------------------------------------------------------------------------
+
+class DocTemplLocker_Impl
+{
+ SfxDocTemplate_Impl& m_aDocTempl;
+public:
+ DocTemplLocker_Impl( SfxDocTemplate_Impl& aDocTempl )
+ : m_aDocTempl( aDocTempl )
+ {
+ m_aDocTempl.IncrementLock();
+ }
+
+ ~DocTemplLocker_Impl()
+ {
+ m_aDocTempl.DecrementLock();
+ }
+};
+
+// ------------------------------------------------------------------------
+
+#ifndef SFX_DECL_DOCTEMPLATES_DEFINED
+#define SFX_DECL_DOCTEMPLATES_DEFINED
+SV_DECL_REF(SfxDocTemplate_Impl)
+#endif
+
+SV_IMPL_REF(SfxDocTemplate_Impl)
+
+// ------------------------------------------------------------------------
+
+SfxDocTemplate_Impl *gpTemplateData = 0;
+
+// -----------------------------------------------------------------------
+
+static sal_Bool getTextProperty_Impl( Content& rContent,
+ const OUString& rPropName,
+ OUString& rPropValue );
+
+//========================================================================
+//========================================================================
+//========================================================================
+
+String SfxDocumentTemplates::GetFullRegionName
+(
+ USHORT nIdx // Index des Bereiches
+) const
+
+/* [Beschreibung]
+
+ Liefert den logischen Namen eines Bereiches Plus seinem Pfad
+
+
+ [R"uckgabewert] Referenz auf diesen Namen
+
+*/
+
+{
+ // First: find the RegionData for the index
+ String aName;
+
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( pImp->Construct() )
+ {
+ RegionData_Impl *pData1 = pImp->GetRegion( nIdx );
+
+ if ( pData1 )
+ aName = pData1->GetTitle();
+
+ // --**-- here was some code which appended the path to the
+ // group if there was more than one with the same name.
+ // this should not happen anymore
+ }
+
+ return aName;
+}
+
+//------------------------------------------------------------------------
+
+const String& SfxDocumentTemplates::GetRegionName
+(
+ USHORT nIdx // Index des Bereiches
+) const
+
+/* [Beschreibung]
+
+ Liefert den logischen Namen eines Bereiches
+
+
+ [R"uckgabewert]
+
+ const String& Referenz auf diesen Namen
+
+*/
+{
+ static String maTmpString;
+
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( pImp->Construct() )
+ {
+ RegionData_Impl *pData = pImp->GetRegion( nIdx );
+
+ if ( pData )
+ maTmpString = pData->GetTitle();
+ else
+ maTmpString.Erase();
+ }
+ else
+ maTmpString.Erase();
+
+ return maTmpString;
+}
+
+
+//------------------------------------------------------------------------
+
+USHORT SfxDocumentTemplates::GetRegionNo
+(
+ const String &rRegion // Name der Region
+) const
+
+/* [Beschreibung]
+
+ Liefert den Index f"ur einen logischen Namen eines Bereiches.
+
+
+ [R"uckgabewert]
+
+ USHORT Index von 'rRegion' oder USHRT_MAX falls unbekannt
+
+*/
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( !pImp->Construct() )
+ return USHRT_MAX;
+
+ sal_Bool bFound;
+ ULONG nIndex = pImp->GetRegionPos( rRegion, bFound );
+
+ if ( bFound )
+ return (USHORT) nIndex;
+ else
+ return USHRT_MAX;
+}
+
+
+//------------------------------------------------------------------------
+
+USHORT SfxDocumentTemplates::GetRegionCount() const
+
+/* [Beschreibung]
+
+ Liefert die Anzahl der Bereiche
+
+
+ [R"uckgabewert]
+
+ USHORT Anzahl der Bereiche
+
+*/
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( !pImp->Construct() )
+ return 0;
+
+ ULONG nCount = pImp->GetRegionCount();
+
+ return (USHORT) nCount;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::IsRegionLoaded( USHORT nIdx ) const
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( !pImp->Construct() )
+ return sal_False;
+
+ RegionData_Impl *pData = pImp->GetRegion( nIdx );
+
+ if ( pData )
+ return sal_True;
+ else
+ return sal_False;
+}
+
+//------------------------------------------------------------------------
+
+USHORT SfxDocumentTemplates::GetCount
+(
+ const String& rName /* Name des Bereiches, dessen Eintrags-
+ anzahl ermittelt werden soll */
+
+) const
+
+/* [Beschreibung]
+
+ Liefert die Anzahl der Eintr"age eines Bereiches
+
+
+ [R"uckgabewert]
+
+ USHORT Anzahl der Eintr"age
+
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( !pImp->Construct() )
+ return 0;
+
+ RegionData_Impl *pData = pImp->GetRegion( rName );
+ ULONG nCount = 0;
+
+ if ( pData )
+ nCount = pData->GetCount();
+
+ return (USHORT) nCount;
+}
+
+//------------------------------------------------------------------------
+
+USHORT SfxDocumentTemplates::GetCount
+(
+ USHORT nRegion /* Index des Bereiches, dessen Eintrags-
+ anzahl ermittelt werden soll */
+
+) const
+
+/* [Beschreibung]
+
+ Liefert die Anzahl der Eintr"age eines Bereiches
+
+
+ [R"uckgabewert] Anzahl der Eintr"age
+
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( !pImp->Construct() )
+ return 0;
+
+ RegionData_Impl *pData = pImp->GetRegion( nRegion );
+ ULONG nCount = 0;
+
+ if ( pData )
+ nCount = pData->GetCount();
+
+ return (USHORT) nCount;
+}
+
+//------------------------------------------------------------------------
+
+const String& SfxDocumentTemplates::GetName
+(
+ USHORT nRegion, // Index des Bereiches, in dem der Eintrag liegt
+ USHORT nIdx // Index des Eintrags
+) const
+
+/* [Beschreibung]
+
+ Liefert den logischen Namen eines Eintrags eines Bereiches
+
+
+ [R"uckgabewert]
+
+ const String& Name des Eintrags
+
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ static String maTmpString;
+
+ if ( pImp->Construct() )
+ {
+ DocTempl_EntryData_Impl *pEntry = NULL;
+ RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
+
+ if ( pRegion )
+ pEntry = pRegion->GetEntry( nIdx );
+
+ if ( pEntry )
+ maTmpString = pEntry->GetTitle();
+ else
+ maTmpString.Erase();
+ }
+ else
+ maTmpString.Erase();
+
+ return maTmpString;
+}
+
+//------------------------------------------------------------------------
+
+String SfxDocumentTemplates::GetFileName
+(
+ USHORT nRegion, // Index des Bereiches, in dem der Eintrag liegt
+ USHORT nIdx // Index des Eintrags
+) const
+
+/* [Beschreibung]
+
+ Liefert den Dateinamen eines Eintrags eines Bereiches
+
+ [R"uckgabewert] Dateiname des Eintrags
+
+*/
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( !pImp->Construct() )
+ return String();
+
+ DocTempl_EntryData_Impl *pEntry = NULL;
+ RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
+
+ if ( pRegion )
+ pEntry = pRegion->GetEntry( nIdx );
+
+ if ( pEntry )
+ {
+ INetURLObject aURLObj( pEntry->GetTargetURL() );
+ return aURLObj.getName( INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET );
+ }
+ else
+ return String();
+}
+
+//------------------------------------------------------------------------
+
+String SfxDocumentTemplates::GetPath
+(
+ USHORT nRegion, // Index des Bereiches, in dem der Eintrag liegt
+ USHORT nIdx // Index des Eintrags
+) const
+
+/* [Beschreibung]
+
+ Liefert den Dateinamen mit vollst"andigem Pfad zu der einem
+ Eintrag zugeordneten Datei
+
+
+ [R"uckgabewert]
+
+ String Dateiname mit vollst"andigem Pfad
+
+*/
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( !pImp->Construct() )
+ return String();
+
+ DocTempl_EntryData_Impl *pEntry = NULL;
+ RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
+
+ if ( pRegion )
+ pEntry = pRegion->GetEntry( nIdx );
+
+ if ( pEntry )
+ return pEntry->GetTargetURL();
+ else
+ return String();
+}
+
+//------------------------------------------------------------------------
+
+String SfxDocumentTemplates::GetTemplatePath
+(
+ USHORT nRegion, // Index des Bereiches, in dem der Eintrag liegt
+ const String& rLongName // logischer Name des Eintrags
+) const
+
+/* [Beschreibung]
+
+ Liefert den Dateinamen mit vollst"andigem Pfad zu der einem
+ Eintrag zugeordneten Datei
+
+
+ [R"uckgabewert]
+
+ String Dateiname mit vollst"andigem Pfad
+
+*/
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( !pImp->Construct() )
+ return String();
+
+ DocTempl_EntryData_Impl *pEntry = NULL;
+ RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
+
+ if ( pRegion )
+ pEntry = pRegion->GetEntry( rLongName );
+
+ if ( pEntry )
+ return pEntry->GetTargetURL();
+ else if ( pRegion )
+ {
+ // a new template is going to be inserted, generate a new URL
+ // TODO/LATER: if the title is localized, use minimized URL in future
+
+ // --**-- extension handling will become more complicated, because
+ // every new document type will have it's own extension
+ // e.g.: .stw or .stc instead of .vor
+ INetURLObject aURLObj( pRegion->GetTargetURL() );
+ aURLObj.insertName( rLongName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+
+ OUString aExtension = aURLObj.getExtension();
+
+ if ( ! aExtension.getLength() )
+ aURLObj.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM( "vor" ) ) );
+
+ return aURLObj.GetMainURL( INetURLObject::NO_DECODE );
+ }
+ else
+ return String();
+}
+
+//------------------------------------------------------------------------
+
+String SfxDocumentTemplates::GetDefaultTemplatePath
+(
+ const String& rLongName
+)
+
+/* [Beschreibung]
+
+ Liefert den Standardpfad zu Dokumentvorlagen
+
+
+ [R"uckgabewert]
+
+ String Standardpfad zu Dokumentvorlagen
+
+*/
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( ! pImp->Construct() )
+ return String();
+
+ // the first region in the list should always be the standard
+ // group
+ // --**-- perhaps we have to create it ???
+ RegionData_Impl *pRegion = pImp->GetRegion( 0L );
+ DocTempl_EntryData_Impl *pEntry = NULL;
+
+ if ( pRegion )
+ pEntry = pRegion->GetEntry( rLongName );
+
+ if ( pEntry )
+ return pEntry->GetTargetURL();
+ else if ( pRegion )
+ {
+ // a new template is going to be inserted, generate a new URL
+ // TODO/LATER: if the title is localized, use minimized URL in future
+
+ INetURLObject aURLObj( pRegion->GetTargetURL() );
+ aURLObj.insertName( rLongName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+
+ OUString aExtension = aURLObj.getExtension();
+
+ if ( ! aExtension.getLength() )
+ aURLObj.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM( "vor" ) ) );
+
+ return aURLObj.GetMainURL( INetURLObject::NO_DECODE );
+ }
+ else
+ return String();
+
+/* dv! missing: create the directory, if it doesn't exists
+
+
+ DBG_ASSERT(aDirs.GetTokenCount(cDelim), "Keine Bereiche");
+ DirEntry aPath(aDirs.GetToken(0, cDelim));
+
+ // Verzeichnis anlegen
+ if(!aPath.MakeDir())
+ return String();
+
+ MakeFileName_Impl(aPath, rLongName, sal_True);
+ SfxTemplateDir *pEntry = new SfxTemplateDir;
+ SfxTemplateDirEntryPtr pDirEntry =
+ new SfxTemplateDirEntry( String( '.' ), aPath.GetPath() );
+ pDirEntry->SetContent(new SfxTemplateDir(aPath.GetPath()));
+ pEntry->Insert(pDirEntry, pEntry->Count());
+ pDirs->Insert(pEntry, pDirs->Count());
+ return aPath.GetFull();
+*/
+}
+
+//------------------------------------------------------------------------
+
+::rtl::OUString SfxDocumentTemplates::GetTemplateTargetURLFromComponent( const ::rtl::OUString& aGroupName,
+ const ::rtl::OUString& aTitle )
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ INetURLObject aTemplateObj( pImp->GetRootURL() );
+
+ aTemplateObj.insertName( aGroupName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+
+ aTemplateObj.insertName( aTitle, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+
+
+ ::rtl::OUString aResult;
+ Content aTemplate;
+ uno::Reference< XCommandEnvironment > aCmdEnv;
+ if ( Content::create( aTemplateObj.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv, aTemplate ) )
+ {
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
+ getTextProperty_Impl( aTemplate, aPropName, aResult );
+ aResult = SvtPathOptions().SubstituteVariable( aResult );
+ }
+
+ return aResult;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::SaveDir
+(
+// SfxTemplateDir& rDir // das zu speichernde Directory
+)
+
+/* [Beschreibung]
+
+ Speichert das Directory rDir
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_False,
+ Schreibfehler
+
+ sal_True
+ gespeichert
+
+*/
+
+{
+ return sal_True;
+}
+
+//------------------------------------------------------------------------
+
+void SfxDocumentTemplates::NewTemplate
+(
+ USHORT nRegion, /* Index des Bereiches, in dem die Vorlage
+ angelegt werden soll */
+
+ const String& rLongName, // logischer Name der neuen Vorlage
+ const String& rFileName // Dateiname der neuen Vorlage
+)
+
+/* [Beschreibung]
+
+ Eintragen einer neuen Dokumentvorlage in die Verwaltungsstrukturen
+ Das "Uberschreiben einer Vorlage gleichen Namens wird
+ verhindert (!! Fehlermeldung)
+
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( ! pImp->Construct() )
+ return;
+
+ DocTempl_EntryData_Impl *pEntry;
+ RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
+
+ // do nothing if there is no region with that index
+ if ( !pRegion )
+ return;
+
+ pEntry = pRegion->GetEntry( rLongName );
+
+ // do nothing if there is already an entry with that name
+ if ( pEntry )
+ return;
+
+ uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
+
+ if ( xTemplates->addTemplate( pRegion->GetTitle(), rLongName, rFileName ) )
+ pRegion->AddEntry( rLongName, rFileName );
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::CopyOrMove
+(
+ USHORT nTargetRegion, // Index des Zielbereiches
+ USHORT nTargetIdx, // Index Zielposition
+ USHORT nSourceRegion, // Index des Quellbereiches
+ USHORT nSourceIdx, /* Index der zu kopierenden / zu verschiebenden
+ Dokumentvorlage */
+ sal_Bool bMove // kopieren / verschieben
+)
+
+/* [Beschreibung]
+
+ Kopieren oder Verschieben einer Dokumentvorlage
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef2uhrt werden
+ [Querverweise]
+
+ <SfxDocumentTemplates::Move(USHORT,USHORT,USHORT,USHORT)>
+ <SfxDocumentTemplates::Copy(USHORT,USHORT,USHORT,USHORT)>
+*/
+
+{
+ /* to perform a copy or move, we need to send a transfer command to
+ the destination folder with the URL of the source as parameter.
+ ( If the destination content doesn't support the transfer command,
+ we could try a copy ( and delete ) instead. )
+ We need two transfers ( one for the real template and one for its
+ representation in the hierarchy )
+ ...
+ */
+
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( !pImp->Construct() )
+ return sal_False;
+
+ // Don't copy or move any folders
+ if( nSourceIdx == USHRT_MAX )
+ return sal_False ;
+
+ if ( nSourceRegion == nTargetRegion )
+ {
+ DBG_ERRORFILE( "Don't know, what to do!" );
+ return sal_False;
+#if 0
+ // Verschieben einer Vorlage innerhalb eines Bereiches
+ // --> nur Verwaltungsdaten aktualisieren
+ if ( bMove && nTargetRegion == nSourceRegion )
+ {
+ if(nTargetIdx == USHRT_MAX)
+ nTargetIdx = 0;
+ const SfxTemplateDirEntryPtr pEntry = rTargetDir[nSourceIdx];
+ rTargetDir.Insert(pEntry, nTargetIdx);
+ if(nTargetIdx < nSourceIdx)
+ ++nSourceIdx;
+ rTargetDir.Remove(nSourceIdx);
+ return SaveDir(rTargetDir);
+ }
+#endif
+ }
+
+ RegionData_Impl *pSourceRgn = pImp->GetRegion( nSourceRegion );
+ if ( !pSourceRgn )
+ return sal_False;
+
+ DocTempl_EntryData_Impl *pSource = pSourceRgn->GetEntry( nSourceIdx );
+ if ( !pSource )
+ return sal_False;
+
+ RegionData_Impl *pTargetRgn = pImp->GetRegion( nTargetRegion );
+ if ( !pTargetRgn )
+ return sal_False;
+
+ OUString aTitle = pSource->GetTitle();
+
+ uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
+
+ if ( xTemplates->addTemplate( pTargetRgn->GetTitle(),
+ aTitle,
+ pSource->GetTargetURL() ) )
+ {
+
+ INetURLObject aSourceObj( pSource->GetTargetURL() );
+
+ ::rtl::OUString aNewTargetURL = GetTemplateTargetURLFromComponent( pTargetRgn->GetTitle(), aTitle );
+ if ( !aNewTargetURL.getLength() )
+ return sal_False;
+
+ if ( bMove )
+ {
+ // --**-- delete the original file
+ sal_Bool bDeleted = xTemplates->removeTemplate( pSourceRgn->GetTitle(),
+ pSource->GetTitle() );
+ if ( bDeleted )
+ pSourceRgn->DeleteEntry( nSourceIdx );
+ else
+ {
+ if ( xTemplates->removeTemplate( pTargetRgn->GetTitle(), aTitle ) )
+ return sal_False; // will trigger tetry with copy instead of move
+
+ // if it is not possible to remove just created template ( must be possible! )
+ // it is better to report success here, since at least the copy has succeeded
+ // TODO/LATER: solve it more gracefully in future
+ }
+ }
+
+ pTargetRgn->AddEntry( aTitle, aNewTargetURL, &nTargetIdx );
+
+ return sal_True;
+ }
+
+ // --**-- wenn aktuell das File geoeffnet ist,
+ // muss es hinterher wieder geoeffnet werden
+
+ return sal_False;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::Move
+(
+ USHORT nTargetRegion, // Index des Zielbereiches
+ USHORT nTargetIdx, // Index Zielposition
+ USHORT nSourceRegion, // Index des Quellbereiches
+ USHORT nSourceIdx /* Index der zu kopierenden / zu verschiebenden
+ Dokumentvorlage */
+)
+
+/* [Beschreibung]
+
+ Verschieben einer Dokumentvorlage
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef2uhrt werden
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::CopyOrMove(USHORT,USHORT,USHORT,USHORT,sal_Bool)>
+*/
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ return CopyOrMove( nTargetRegion, nTargetIdx,
+ nSourceRegion, nSourceIdx, sal_True );
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::Copy
+(
+ USHORT nTargetRegion, // Index des Zielbereiches
+ USHORT nTargetIdx, // Index Zielposition
+ USHORT nSourceRegion, // Index des Quellbereiches
+ USHORT nSourceIdx /* Index der zu kopierenden / zu verschiebenden
+ Dokumentvorlage */
+)
+
+/* [Beschreibung]
+
+ Kopieren einer Dokumentvorlage
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef"uhrt werden
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::CopyOrMove(USHORT,USHORT,USHORT,USHORT,sal_Bool)>
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ return CopyOrMove( nTargetRegion, nTargetIdx,
+ nSourceRegion, nSourceIdx, sal_False );
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::CopyTo
+(
+ USHORT nRegion, /* Bereich der Vorlage, die exportiert werden
+ soll */
+ USHORT nIdx, /* Index der Vorlage, die exportiert werden
+ soll */
+ const String& rName /* Dateiname, unter dem die Vorlage angelegt
+ werden soll */
+) const
+
+/* [Beschreibung]
+
+ Exportieren einer Dokumentvorlage in das Dateisystem
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef"uhrt werden
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::CopyFrom(USHORT,USHORT,String&)>
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( ! pImp->Construct() )
+ return sal_False;
+
+ RegionData_Impl *pSourceRgn = pImp->GetRegion( nRegion );
+ if ( !pSourceRgn )
+ return sal_False;
+
+ DocTempl_EntryData_Impl *pSource = pSourceRgn->GetEntry( nIdx );
+ if ( !pSource )
+ return sal_False;
+
+ INetURLObject aTargetURL( rName );
+
+ OUString aTitle( aTargetURL.getName( INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET ) );
+ aTargetURL.removeSegment();
+
+ OUString aParentURL = aTargetURL.GetMainURL( INetURLObject::NO_DECODE );
+
+ uno::Reference< XCommandEnvironment > aCmdEnv;
+ Content aTarget;
+
+ try
+ {
+ aTarget = Content( aParentURL, aCmdEnv );
+
+ TransferInfo aTransferInfo;
+ aTransferInfo.MoveData = sal_False;
+ aTransferInfo.SourceURL = pSource->GetTargetURL();
+ aTransferInfo.NewTitle = aTitle;
+ aTransferInfo.NameClash = NameClash::OVERWRITE;
+
+ Any aArg = makeAny( aTransferInfo );
+ OUString aCmd( RTL_CONSTASCII_USTRINGPARAM( COMMAND_TRANSFER ) );
+
+ aTarget.executeCommand( aCmd, aArg );
+ }
+ catch ( ContentCreationException& )
+ { return sal_False; }
+ catch ( Exception& )
+ { return sal_False; }
+
+ return sal_True;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::CopyFrom
+(
+ USHORT nRegion, /* Bereich, in den die Vorlage importiert
+ werden soll */
+ USHORT nIdx, // Index der neuen Vorlage in diesem Bereich
+ String& rName /* Dateiname der Vorlage, die importiert
+ werden soll, als out-Parameter der (auto-
+ matisch aus dem Dateinamen generierte)
+ logische Name der Vorlage */
+)
+
+/* [Beschreibung]
+
+ Importieren einer Dokumentvorlage aus dem Dateisystem
+
+
+ [R"uckgabewert] Erfolg (sal_True) oder Mi"serfpTargetDirectory->GetContent());
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef"uhrt werden
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::CopyTo(USHORT,USHORT,const String&)>
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( ! pImp->Construct() )
+ return sal_False;
+
+ RegionData_Impl *pTargetRgn = pImp->GetRegion( nRegion );
+
+ if ( !pTargetRgn )
+ return sal_False;
+
+ uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
+ if ( !xTemplates.is() )
+ return sal_False;
+
+ OUString aTitle;
+ sal_Bool bTemplateAdded = sal_False;
+
+ if( pImp->GetTitleFromURL( rName, aTitle ) )
+ {
+ bTemplateAdded = xTemplates->addTemplate( pTargetRgn->GetTitle(), aTitle, rName );
+ }
+ else
+ {
+ OUString aService( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_DESKTOP ) );
+ uno::Reference< XComponentLoader > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance( aService ),
+ UNO_QUERY );
+
+ Sequence< PropertyValue > aArgs( 1 );
+ aArgs[0].Name = ::rtl::OUString::createFromAscii("Hidden");
+ aArgs[0].Value <<= sal_True;
+
+ INetURLObject aTemplURL( rName );
+ uno::Reference< XDocumentPropertiesSupplier > xDocPropsSupplier;
+ uno::Reference< XStorable > xStorable;
+ try
+ {
+ xStorable = uno::Reference< XStorable >(
+ xDesktop->loadComponentFromURL( aTemplURL.GetMainURL(INetURLObject::NO_DECODE),
+ OUString::createFromAscii( "_blank" ),
+ 0,
+ aArgs ),
+ UNO_QUERY );
+
+ xDocPropsSupplier = uno::Reference< XDocumentPropertiesSupplier >(
+ xStorable, UNO_QUERY );
+ }
+ catch( Exception& )
+ {
+ }
+
+ if( xStorable.is() )
+ {
+ // get Title from XDocumentPropertiesSupplier
+ if( xDocPropsSupplier.is() )
+ {
+ uno::Reference< XDocumentProperties > xDocProps
+ = xDocPropsSupplier->getDocumentProperties();
+ if (xDocProps.is() ) {
+ aTitle = xDocProps->getTitle();
+ }
+ }
+
+ if( ! aTitle.getLength() )
+ {
+ INetURLObject aURL( aTemplURL );
+ aURL.CutExtension();
+ aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET );
+ }
+
+ // write a template using XStorable interface
+ bTemplateAdded = xTemplates->storeTemplate( pTargetRgn->GetTitle(), aTitle, xStorable );
+ }
+ }
+
+
+ if( bTemplateAdded )
+ {
+ INetURLObject aTemplObj( pTargetRgn->GetHierarchyURL() );
+ aTemplObj.insertName( aTitle, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ OUString aTemplURL = aTemplObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ uno::Reference< XCommandEnvironment > aCmdEnv;
+ Content aTemplCont;
+
+ if( Content::create( aTemplURL, aCmdEnv, aTemplCont ) )
+ {
+ OUString aTemplName;
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
+
+ if( getTextProperty_Impl( aTemplCont, aPropName, aTemplName ) )
+ {
+ if ( nIdx == USHRT_MAX )
+ nIdx = 0;
+ else
+ nIdx += 1;
+
+ pTargetRgn->AddEntry( aTitle, aTemplName, &nIdx );
+ rName = aTitle;
+ return sal_True;
+ }
+ else
+ {
+ DBG_ASSERT( sal_False, "CopyFrom(): The content should contain target URL!" );
+ }
+ }
+ else
+ {
+ DBG_ASSERT( sal_False, "CopyFrom(): The content just was created!" );
+ }
+ }
+
+ return sal_False;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::Delete
+(
+ USHORT nRegion, // Index des Bereiches
+ USHORT nIdx /* Index des Eintrags oder USHRT_MAX,
+ wenn ein Verzeichnis gemeint ist. */
+)
+
+/* [Beschreibung]
+
+ "oschen eines Eintrags oder eines Verzeichnisses
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef"uhrt werden
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::InsertDir(const String&,USHORT)>
+ <SfxDocumentTemplates::KillDir(SfxTemplateDir&)>
+ <SfxDocumentTemplates::SaveDir(SfxTemplateDir&)>
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ /* delete the template or folder in the hierarchy and in the
+ template folder by sending a delete command to the content.
+ Then remove the data from the lists
+ */
+ if ( ! pImp->Construct() )
+ return sal_False;
+
+ RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
+
+ if ( !pRegion )
+ return sal_False;
+
+ sal_Bool bRet;
+ uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
+
+ if ( nIdx == USHRT_MAX )
+ {
+ bRet = xTemplates->removeGroup( pRegion->GetTitle() );
+ if ( bRet )
+ pImp->DeleteRegion( nRegion );
+ }
+ else
+ {
+ DocTempl_EntryData_Impl *pEntry = pRegion->GetEntry( nIdx );
+
+ if ( !pEntry )
+ return sal_False;
+
+ bRet = xTemplates->removeTemplate( pRegion->GetTitle(),
+ pEntry->GetTitle() );
+ if( bRet )
+ pRegion->DeleteEntry( nIdx );
+ }
+
+ return bRet;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::InsertDir
+(
+ const String& rText, // der logische Name des neuen Bereiches
+ USHORT nRegion // Index des Bereiches
+)
+
+/* [Beschreibung]
+
+ Einf"ugen eines Verzeichnisses
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef"uhrt werden
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::KillDir(SfxTemplateDir&)>
+ <SfxDocumentTemplates::SaveDir(SfxTemplateDir&)>
+*/
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( ! pImp->Construct() )
+ return sal_False;
+
+ RegionData_Impl *pRegion = pImp->GetRegion( rText );
+
+ if ( pRegion )
+ return sal_False;
+
+ uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
+
+ if ( xTemplates->addGroup( rText ) )
+ {
+ RegionData_Impl* pNewRegion = new RegionData_Impl( pImp, rText );
+
+ if ( ! pImp->InsertRegion( pNewRegion, nRegion ) )
+ {
+ delete pNewRegion;
+ return sal_False;
+ }
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::SetName
+(
+ const String& rName, // Der zu setzende Name
+ USHORT nRegion, // Index des Bereiches
+ USHORT nIdx /* Index des Eintrags oder USHRT_MAX,
+ wenn ein Verzeichnis gemeint ist. */
+)
+
+/* [Beschreibung]
+
+ "Andern des Namens eines Eintrags oder eines Verzeichnisses
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef"uhrt werden
+
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( ! pImp->Construct() )
+ return sal_False;
+
+ RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
+ DocTempl_EntryData_Impl *pEntry = NULL;
+
+ if ( !pRegion )
+ return sal_False;
+
+ uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
+ OUString aEmpty;
+
+ if ( nIdx == USHRT_MAX )
+ {
+ if ( pRegion->GetTitle() == OUString( rName ) )
+ return sal_True;
+
+ // we have to rename a region
+ if ( xTemplates->renameGroup( pRegion->GetTitle(), rName ) )
+ {
+ pRegion->SetTitle( rName );
+ pRegion->SetTargetURL( aEmpty );
+ pRegion->SetHierarchyURL( aEmpty );
+ return sal_True;
+ }
+ }
+ else
+ {
+ pEntry = pRegion->GetEntry( nIdx );
+
+ if ( !pEntry )
+ return sal_False;
+
+ if ( pEntry->GetTitle() == OUString( rName ) )
+ return sal_True;
+
+ if ( xTemplates->renameTemplate( pRegion->GetTitle(),
+ pEntry->GetTitle(),
+ rName ) )
+ {
+ pEntry->SetTitle( rName );
+ pEntry->SetTargetURL( aEmpty );
+ pEntry->SetHierarchyURL( aEmpty );
+ return sal_True;
+ }
+ }
+
+ return sal_False;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::Rescan()
+
+/* [Beschreibung]
+
+ Abgleich des Verwaltungsdaten mit dem aktuellen Zustand auf der Platte.
+ Die logischen Namen, zu denen keine Datei mit existiert, werden aus
+ der Verwaltungsstruktur entfernt; Dateien, zu denen kein Eintrag
+ existiert, werden aufgenommen.
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef"uhrt werden
+
+
+ [Querverweise]
+
+ <SfxTemplateDir::Scan(sal_Bool bDirectory, sal_Bool bSave)>
+ <SfxTemplateDir::Freshen(const SfxTemplateDir &rNew)>
+*/
+{
+ if ( !pImp->Construct() )
+ return sal_False;
+
+ pImp->Rescan();
+
+ return sal_True;
+}
+
+//------------------------------------------------------------------------
+
+SfxObjectShellRef SfxDocumentTemplates::CreateObjectShell
+(
+ USHORT nRegion, // Index des Bereiches
+ USHORT nIdx // Index des Eintrags
+)
+
+/* [Beschreibung]
+
+ Zugriff auf die DokumentShell eines Eintrags
+
+
+ [R"uckgabewert]
+
+ SfxObjectShellRef Referenz auf die ObjectShell
+
+
+ [Querverweise]
+
+ <SfxTemplateDirEntry::CreateObjectShell()>
+ <SfxDocumentTemplates::DeleteObjectShell(USHORT, USHORT)>
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( !pImp->Construct() )
+ return NULL;
+
+ RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
+ DocTempl_EntryData_Impl *pEntry = NULL;
+
+ if ( pRegion )
+ pEntry = pRegion->GetEntry( nIdx );
+
+ if ( pEntry )
+ return pEntry->CreateObjectShell();
+ else
+ return NULL;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::DeleteObjectShell
+(
+ USHORT nRegion, // Index des Bereiches
+ USHORT nIdx // Index des Eintrags
+)
+
+/* [Beschreibung]
+
+ Freigeben der ObjectShell eines Eintrags
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef"uhrt werden
+
+ [Querverweise]
+
+ <SfxTemplateDirEntry::DeleteObjectShell()>
+ <SfxDocumentTemplates::CreateObjectShell(USHORT, USHORT)>
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( ! pImp->Construct() )
+ return sal_True;
+
+ RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
+ DocTempl_EntryData_Impl *pEntry = NULL;
+
+ if ( pRegion )
+ pEntry = pRegion->GetEntry( nIdx );
+
+ if ( pEntry )
+ return pEntry->DeleteObjectShell();
+ else
+ return sal_True;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::GetFull
+(
+ const String &rRegion, // Der Name des Bereiches
+ const String &rName, // Der Name der Vorlage
+ String &rPath // Out: Pfad + Dateiname
+)
+
+/* [Beschreibung]
+
+ Liefert Pfad + Dateiname zu der durch rRegion und rName bezeichneten
+ Vorlage
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef"uhrt werden
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::GetLogicNames(const String&,String&,String&)>
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ // We don't search for empty names!
+ if ( ! rName.Len() )
+ return sal_False;
+
+ if ( ! pImp->Construct() )
+ return sal_False;
+
+ DocTempl_EntryData_Impl* pEntry = NULL;
+ const USHORT nCount = GetRegionCount();
+
+ for ( USHORT i = 0; i < nCount; ++i )
+ {
+ RegionData_Impl *pRegion = pImp->GetRegion( i );
+
+ if( pRegion &&
+ ( !rRegion.Len() || ( rRegion == String( pRegion->GetTitle() ) ) ) )
+ {
+ pEntry = pRegion->GetEntry( rName );
+
+ if ( pEntry )
+ {
+ rPath = pEntry->GetTargetURL();
+ break;
+ }
+ }
+ }
+
+ return ( pEntry != NULL );
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxDocumentTemplates::GetLogicNames
+(
+ const String &rPath, // vollst"andiger Pfad zu der Vorlage
+ String &rRegion, // Out: der Bereichsname
+ String &rName // Out: der Vorlagenname
+) const
+
+/* [Beschreibung]
+
+ Liefert Pfad und logischen Namen zu der durch rPath bezeichneten
+ Vorlage
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Aktion konnte ausgef"uhrt werden
+
+ sal_False
+ Aktion konnte nicht ausgef"uhrt werden
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::GetFull(const String&,const String&,DirEntry&)>
+*/
+
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ if ( ! pImp->Construct() )
+ return sal_False;
+
+ INetURLObject aFullPath;
+
+ aFullPath.SetSmartProtocol( INET_PROT_FILE );
+ aFullPath.SetURL( rPath );
+ OUString aPath( aFullPath.GetMainURL( INetURLObject::NO_DECODE ) );
+
+ RegionData_Impl *pData = NULL;
+ DocTempl_EntryData_Impl *pEntry = NULL;
+ sal_Bool bFound = sal_False;
+
+ ULONG nCount = GetRegionCount();
+
+ for ( ULONG i=0; !bFound && (i<nCount); i++ )
+ {
+ pData = pImp->GetRegion( i );
+ if ( pData )
+ {
+ ULONG nChildCount = pData->GetCount();
+
+ for ( ULONG j=0; !bFound && (j<nChildCount); j++ )
+ {
+ pEntry = pData->GetEntry( j );
+ if ( pEntry->GetTargetURL() == aPath )
+ {
+ bFound = sal_True;
+ }
+ }
+ }
+ }
+
+ if ( bFound )
+ {
+ rRegion = pData->GetTitle();
+ rName = pEntry->GetTitle();
+ }
+
+ return bFound;
+}
+
+//------------------------------------------------------------------------
+
+SfxDocumentTemplates::SfxDocumentTemplates()
+
+/* [Beschreibung]
+
+ Konstruktor
+*/
+{
+ if ( !gpTemplateData )
+ gpTemplateData = new SfxDocTemplate_Impl;
+
+ pImp = gpTemplateData;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxDocumentTemplates::Construct()
+
+// verz"ogerter Aufbau der Verwaltungsdaten
+
+{
+// pImp->Construct();
+}
+
+//------------------------------------------------------------------------
+
+SfxDocumentTemplates::~SfxDocumentTemplates()
+
+/* [Beschreibung]
+
+ Destruktor
+ Freigeben der Verwaltungsdaten
+*/
+
+{
+ pImp = NULL;
+}
+
+void SfxDocumentTemplates::Update( sal_Bool _bSmart )
+{
+ if ( !_bSmart // don't be smart
+ || ::svt::TemplateFolderCache( sal_True ).needsUpdate() // update is really necessary
+ )
+ {
+ if ( pImp->Construct() )
+ pImp->Rescan();
+ }
+}
+
+void SfxDocumentTemplates::ReInitFromComponent()
+{
+ pImp->ReInitFromComponent();
+}
+
+
+sal_Bool SfxDocumentTemplates::HasUserContents( sal_uInt16 nRegion, sal_uInt16 nIdx ) const
+{
+ DocTemplLocker_Impl aLocker( *pImp );
+
+ sal_Bool bResult = sal_False;
+
+ RegionData_Impl* pRegion = pImp->GetRegion( nRegion );
+
+ if ( pRegion )
+ {
+ ::rtl::OUString aRegionTargetURL = pRegion->GetTargetURL();
+ if ( aRegionTargetURL.getLength() )
+ {
+ sal_uInt16 nLen = 0;
+ sal_uInt16 nStartInd = 0;
+
+ if( nIdx == USHRT_MAX )
+ {
+ // this is a folder
+ // check whether there is at least one editable template
+ nLen = ( sal_uInt16 )pRegion->GetCount();
+ nStartInd = 0;
+ if ( nLen == 0 )
+ bResult = sal_True; // the writing part of empty folder with writing URL can be removed
+ }
+ else
+ {
+ // this is a template
+ // check whether the template is inserted by user
+ nLen = 1;
+ nStartInd = nIdx;
+ }
+
+ for ( sal_uInt16 nInd = nStartInd; nInd < nStartInd + nLen; nInd++ )
+ {
+ DocTempl_EntryData_Impl* pEntryData = pRegion->GetEntry( nInd );
+ if ( pEntryData )
+ {
+ ::rtl::OUString aEntryTargetURL = pEntryData->GetTargetURL();
+ if ( aEntryTargetURL.getLength()
+ && ::utl::UCBContentHelper::IsSubPath( aRegionTargetURL, aEntryTargetURL ) )
+ {
+ bResult = sal_True;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ return bResult;
+}
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+DocTempl_EntryData_Impl::DocTempl_EntryData_Impl( RegionData_Impl* pParent,
+ const OUString& rTitle )
+{
+ mpParent = pParent;
+ maTitle = rTitle;
+ mbIsOwner = sal_False;
+ mbDidConvert= sal_False;
+}
+
+// -----------------------------------------------------------------------
+int DocTempl_EntryData_Impl::Compare( const OUString& rTitle ) const
+{
+ return maTitle.compareTo( rTitle );
+}
+
+//------------------------------------------------------------------------
+SfxObjectShellRef DocTempl_EntryData_Impl::CreateObjectShell()
+{
+ if( ! mxObjShell.Is() )
+ {
+ mbIsOwner = sal_False;
+ sal_Bool bDum = sal_False;
+ SfxApplication *pSfxApp = SFX_APP();
+ String aTargetURL = GetTargetURL();
+
+ mxObjShell = pSfxApp->DocAlreadyLoaded( aTargetURL, sal_True, bDum );
+
+ if( ! mxObjShell.Is() )
+ {
+ mbIsOwner = sal_True;
+ SfxMedium *pMed=new SfxMedium(
+ aTargetURL,(STREAM_STD_READWRITE | STREAM_SHARE_DENYALL), sal_False, 0 );
+ const SfxFilter* pFilter = NULL;
+ pMed->UseInteractionHandler(TRUE);
+ if( pSfxApp->GetFilterMatcher().GuessFilter(
+ *pMed, &pFilter, SFX_FILTER_TEMPLATE, 0 ) ||
+ (pFilter && !pFilter->IsOwnFormat()) ||
+ (pFilter && !pFilter->UsesStorage()) )
+ {
+ SfxErrorContext aEc( ERRCTX_SFX_LOADTEMPLATE,
+ aTargetURL );
+ delete pMed;
+ mbDidConvert=sal_True;
+ ULONG lErr;
+ if ( mxObjShell.Is() ) {
+ lErr = pSfxApp->LoadTemplate( mxObjShell,aTargetURL);
+ if( lErr != ERRCODE_NONE )
+ ErrorHandler::HandleError(lErr);
+ }
+
+ }
+ else if (pFilter)
+ {
+ mbDidConvert=sal_False;
+ mxObjShell = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_ORGANIZER );
+ if ( mxObjShell.Is() )
+ {
+ mxObjShell->DoInitNew(0);
+ // TODO/LATER: make sure that we don't use binary templates!
+ if( mxObjShell->LoadFrom( *pMed ) )
+ {
+ mxObjShell->DoSaveCompleted( pMed );
+ }
+ else
+ mxObjShell.Clear();
+ }
+ }
+ }
+ }
+
+ return (SfxObjectShellRef)(SfxObjectShell*) mxObjShell;
+}
+
+//------------------------------------------------------------------------
+BOOL DocTempl_EntryData_Impl::DeleteObjectShell()
+{
+ sal_Bool bRet = sal_True;
+
+ if ( mxObjShell.Is() )
+ {
+ if( mxObjShell->IsModified() )
+ {
+ //Hier speichern wir auch, falls die Vorlage in Bearbeitung ist...
+ bRet = sal_False;
+
+ if ( mbIsOwner )
+ {
+ if( mbDidConvert )
+ {
+ bRet=mxObjShell->PreDoSaveAs_Impl(
+ GetTargetURL(),
+ mxObjShell->GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_EXPORT | SFX_FILTER_IMPORT, SFX_FILTER_INTERNAL )->GetFilterName(), 0 );
+ }
+ else
+ {
+ if( mxObjShell->Save() )
+ {
+ uno::Reference< embed::XTransactedObject > xTransacted( mxObjShell->GetStorage(), uno::UNO_QUERY );
+ DBG_ASSERT( xTransacted.is(), "Storage must implement XTransactedObject!\n" );
+ if ( xTransacted.is() )
+ {
+ try
+ {
+ xTransacted->commit();
+ bRet = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if( bRet )
+ {
+ mxObjShell.Clear();
+ }
+ }
+ return bRet;
+}
+
+// -----------------------------------------------------------------------
+const OUString& DocTempl_EntryData_Impl::GetHierarchyURL()
+{
+ if ( !maOwnURL.getLength() )
+ {
+ INetURLObject aTemplateObj( GetParent()->GetHierarchyURL() );
+
+ aTemplateObj.insertName( GetTitle(), false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+
+ maOwnURL = aTemplateObj.GetMainURL( INetURLObject::NO_DECODE );
+ DBG_ASSERT( maOwnURL.getLength(), "GetHierarchyURL(): Could not create URL!" );
+ }
+
+ return maOwnURL;
+}
+
+// -----------------------------------------------------------------------
+const OUString& DocTempl_EntryData_Impl::GetTargetURL()
+{
+ if ( !maTargetURL.getLength() )
+ {
+ uno::Reference< XCommandEnvironment > aCmdEnv;
+ Content aRegion;
+
+ if ( Content::create( GetHierarchyURL(), aCmdEnv, aRegion ) )
+ {
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
+
+ getTextProperty_Impl( aRegion, aPropName, maTargetURL );
+ }
+ else
+ {
+ DBG_ERRORFILE( "GetTargetURL(): Could not create hierarchy content!" );
+ }
+ }
+
+ return maTargetURL;
+}
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+RegionData_Impl::RegionData_Impl( const SfxDocTemplate_Impl* pParent,
+ const OUString& rTitle )
+{
+ maTitle = rTitle;
+ mpParent = pParent;
+}
+
+// -----------------------------------------------------------------------
+RegionData_Impl::~RegionData_Impl()
+{
+ DocTempl_EntryData_Impl *pData = maEntries.First();
+
+ while ( pData )
+ {
+ delete pData;
+ pData = maEntries.Next();
+ }
+}
+
+// -----------------------------------------------------------------------
+long RegionData_Impl::GetEntryPos( const OUString& rTitle,
+ sal_Bool& rFound ) const
+{
+#if 1 // Don't use binary search today
+ ULONG i;
+ ULONG nCount = maEntries.Count();
+
+ for ( i=0; i<nCount; i++ )
+ {
+ DocTempl_EntryData_Impl *pData = maEntries.GetObject( i );
+
+ if ( pData->Compare( rTitle ) == 0 )
+ {
+ rFound = sal_True;
+ return i;
+ }
+ }
+
+ rFound = sal_False;
+ return i;
+
+#else
+ // use binary search to find the correct position
+ // in the maEntries list
+
+ int nCompVal = 1;
+ long nStart = 0;
+ long nEnd = maEntries.Count() - 1;
+ long nMid;
+
+ DocTempl_EntryData_Impl* pMid;
+
+ rFound = sal_False;
+
+ while ( nCompVal && ( nStart <= nEnd ) )
+ {
+ nMid = ( nEnd - nStart ) / 2 + nStart;
+ pMid = maEntries.GetObject( nMid );
+
+ nCompVal = pMid->Compare( rTitle );
+
+ if ( nCompVal < 0 ) // pMid < pData
+ nStart = nMid + 1;
+ else
+ nEnd = nMid - 1;
+ }
+
+ if ( nCompVal == 0 )
+ {
+ rFound = sal_True;
+ }
+ else
+ {
+ if ( nCompVal < 0 ) // pMid < pData
+ nMid++;
+ }
+
+ return nMid;
+#endif
+}
+
+// -----------------------------------------------------------------------
+void RegionData_Impl::AddEntry( const OUString& rTitle,
+ const OUString& rTargetURL,
+ USHORT *pPos )
+{
+ INetURLObject aLinkObj( GetHierarchyURL() );
+ aLinkObj.insertName( rTitle, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ OUString aLinkURL = aLinkObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ DocTempl_EntryData_Impl *pEntry;
+ sal_Bool bFound = sal_False;
+ long nPos = GetEntryPos( rTitle, bFound );
+
+ if ( bFound )
+ {
+ pEntry = maEntries.GetObject( nPos );
+ }
+ else
+ {
+ if ( pPos )
+ nPos = *pPos;
+
+ pEntry = new DocTempl_EntryData_Impl( this, rTitle );
+ pEntry->SetTargetURL( rTargetURL );
+ pEntry->SetHierarchyURL( aLinkURL );
+ maEntries.Insert( pEntry, nPos );
+ }
+}
+
+// -----------------------------------------------------------------------
+ULONG RegionData_Impl::GetCount() const
+{
+ return maEntries.Count();
+}
+
+// -----------------------------------------------------------------------
+const OUString& RegionData_Impl::GetHierarchyURL()
+{
+ if ( !maOwnURL.getLength() )
+ {
+ INetURLObject aRegionObj( GetParent()->GetRootURL() );
+
+ aRegionObj.insertName( GetTitle(), false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+
+ maOwnURL = aRegionObj.GetMainURL( INetURLObject::NO_DECODE );
+ DBG_ASSERT( maOwnURL.getLength(), "GetHierarchyURL(): Could not create URL!" );
+ }
+
+ return maOwnURL;
+}
+
+// -----------------------------------------------------------------------
+const OUString& RegionData_Impl::GetTargetURL()
+{
+ if ( !maTargetURL.getLength() )
+ {
+ uno::Reference< XCommandEnvironment > aCmdEnv;
+ Content aRegion;
+
+ if ( Content::create( GetHierarchyURL(), aCmdEnv, aRegion ) )
+ {
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) );
+
+ getTextProperty_Impl( aRegion, aPropName, maTargetURL );
+ // --> PB 2004-10-27 #i32656# - the targeturl must be substituted: $(baseinsturl)
+ maTargetURL = SvtPathOptions().SubstituteVariable( maTargetURL );
+ // <--
+ }
+ else
+ {
+ DBG_ERRORFILE( "GetTargetURL(): Could not create hierarchy content!" );
+ }
+ }
+
+ return maTargetURL;
+}
+
+// -----------------------------------------------------------------------
+DocTempl_EntryData_Impl* RegionData_Impl::GetEntry( const OUString& rName ) const
+{
+ sal_Bool bFound = sal_False;
+ long nPos = GetEntryPos( rName, bFound );
+
+ if ( bFound )
+ return maEntries.GetObject( nPos );
+ else
+ return NULL;
+}
+
+// -----------------------------------------------------------------------
+DocTempl_EntryData_Impl* RegionData_Impl::GetByTargetURL( const OUString& rName ) const
+{
+ DocTempl_EntryData_Impl *pEntry;
+
+ ULONG nCount = maEntries.Count();
+
+ for ( ULONG i=0; i<nCount; i++ )
+ {
+ pEntry = maEntries.GetObject( i );
+ if ( pEntry && ( pEntry->GetTargetURL() == rName ) )
+ return pEntry;
+ }
+
+ return NULL;
+}
+
+// -----------------------------------------------------------------------
+DocTempl_EntryData_Impl* RegionData_Impl::GetEntry( ULONG nIndex ) const
+{
+ return maEntries.GetObject( nIndex );
+}
+
+// -----------------------------------------------------------------------
+void RegionData_Impl::DeleteEntry( ULONG nIndex )
+{
+ DocTempl_EntryData_Impl *pEntry = maEntries.GetObject( nIndex );
+
+ if ( pEntry )
+ {
+ delete pEntry;
+ maEntries.Remove( (ULONG) nIndex );
+ }
+}
+
+// -----------------------------------------------------------------------
+int RegionData_Impl::Compare( RegionData_Impl* pCompare ) const
+{
+ int nCompare = maTitle.compareTo( pCompare->maTitle );
+
+ return nCompare;
+}
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+
+SfxDocTemplate_Impl::SfxDocTemplate_Impl()
+: mbConstructed( sal_False )
+, mnLockCounter( 0 )
+{
+}
+
+// -----------------------------------------------------------------------
+SfxDocTemplate_Impl::~SfxDocTemplate_Impl()
+{
+ Clear();
+
+ gpTemplateData = NULL;
+}
+
+// -----------------------------------------------------------------------
+void SfxDocTemplate_Impl::IncrementLock()
+{
+ ::osl::MutexGuard aGuard( maMutex );
+ mnLockCounter++;
+}
+
+// -----------------------------------------------------------------------
+void SfxDocTemplate_Impl::DecrementLock()
+{
+ ::osl::MutexGuard aGuard( maMutex );
+ if ( mnLockCounter )
+ mnLockCounter--;
+}
+
+// -----------------------------------------------------------------------
+RegionData_Impl* SfxDocTemplate_Impl::GetRegion( ULONG nIndex ) const
+{
+ return maRegions.GetObject( nIndex );
+}
+
+// -----------------------------------------------------------------------
+RegionData_Impl* SfxDocTemplate_Impl::GetRegion( const OUString& rName )
+ const
+{
+ ULONG nCount = maRegions.Count();
+ RegionData_Impl *pData;
+
+ for ( ULONG i=0; i<nCount; i++ )
+ {
+ pData = maRegions.GetObject( i );
+
+ if ( pData->GetTitle() == rName )
+ return pData;
+ }
+
+ return NULL;
+}
+
+// -----------------------------------------------------------------------
+void SfxDocTemplate_Impl::DeleteRegion( ULONG nIndex )
+{
+ RegionData_Impl* pRegion = maRegions.GetObject( nIndex );
+
+ if ( pRegion )
+ {
+ delete pRegion;
+ maRegions.Remove( (ULONG) nIndex );
+ }
+}
+
+// -----------------------------------------------------------------------
+/* AddRegion adds a Region to the RegionList
+*/
+void SfxDocTemplate_Impl::AddRegion( const OUString& rTitle,
+ Content& rContent )
+{
+ RegionData_Impl* pRegion;
+ pRegion = new RegionData_Impl( this, rTitle );
+
+ if ( ! InsertRegion( pRegion ) )
+ {
+ delete pRegion;
+ return;
+ }
+
+ // now get the content of the region
+ uno::Reference< XResultSet > xResultSet;
+ Sequence< OUString > aProps(2);
+ aProps[0] = OUString::createFromAscii( TITLE );
+ aProps[1] = OUString::createFromAscii( TARGET_URL );
+
+ try
+ {
+ ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
+ Sequence< NumberedSortingInfo > aSortingInfo(1);
+ aSortingInfo.getArray()->ColumnIndex = 1;
+ aSortingInfo.getArray()->Ascending = sal_True;
+ xResultSet = rContent.createSortedCursor( aProps, aSortingInfo, m_rCompareFactory, eInclude );
+ }
+ catch ( Exception& ) {}
+
+ if ( xResultSet.is() )
+ {
+ uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
+ uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
+
+ try
+ {
+ while ( xResultSet->next() )
+ {
+ OUString aTitle( xRow->getString( 1 ) );
+ OUString aTargetDir( xRow->getString( 2 ) );
+
+ pRegion->AddEntry( aTitle, aTargetDir );
+ }
+ }
+ catch ( Exception& ) {}
+ }
+}
+
+// -----------------------------------------------------------------------
+void SfxDocTemplate_Impl::CreateFromHierarchy( Content &rTemplRoot )
+{
+ uno::Reference< XResultSet > xResultSet;
+ Sequence< OUString > aProps(1);
+ aProps[0] = OUString::createFromAscii( TITLE );
+
+ try
+ {
+ ResultSetInclude eInclude = INCLUDE_FOLDERS_ONLY;
+ Sequence< NumberedSortingInfo > aSortingInfo(1);
+ aSortingInfo.getArray()->ColumnIndex = 1;
+ aSortingInfo.getArray()->Ascending = sal_True;
+ xResultSet = rTemplRoot.createSortedCursor( aProps, aSortingInfo, m_rCompareFactory, eInclude );
+ }
+ catch ( Exception& ) {}
+
+ if ( xResultSet.is() )
+ {
+ uno::Reference< XCommandEnvironment > aCmdEnv;
+ uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
+ uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
+
+ try
+ {
+ while ( xResultSet->next() )
+ {
+ OUString aTitle( xRow->getString( 1 ) );
+
+ OUString aId = xContentAccess->queryContentIdentifierString();
+ Content aContent = Content( aId, aCmdEnv );
+
+ AddRegion( aTitle, aContent );
+ }
+ }
+ catch ( Exception& ) {}
+ }
+}
+
+// ------------------------------------------------------------------------
+sal_Bool SfxDocTemplate_Impl::Construct( )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ if ( mbConstructed )
+ return sal_True;
+
+ uno::Reference< XMultiServiceFactory > xFactory;
+ xFactory = ::comphelper::getProcessServiceFactory();
+
+ OUString aService( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_DOCINFO ) );
+ uno::Reference< XPersist > xInfo( xFactory->createInstance( aService ), UNO_QUERY );
+ mxInfo = xInfo;
+
+ aService = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_DOCTEMPLATES ) );
+ uno::Reference< XDocumentTemplates > xTemplates( xFactory->createInstance( aService ), UNO_QUERY );
+
+ if ( xTemplates.is() )
+ mxTemplates = xTemplates;
+ else
+ return sal_False;
+
+ uno::Reference< XLocalizable > xLocalizable( xTemplates, UNO_QUERY );
+
+ Sequence< Any > aCompareArg(1);
+ *(aCompareArg.getArray()) <<= xLocalizable->getLocale();;
+ m_rCompareFactory = uno::Reference< XAnyCompareFactory >(
+ xFactory->createInstanceWithArguments( OUString::createFromAscii( "com.sun.star.ucb.AnyCompareFactory" ),
+ aCompareArg ),
+ UNO_QUERY );
+
+ uno::Reference < XContent > aRootContent = xTemplates->getContent();
+ uno::Reference < XCommandEnvironment > aCmdEnv;
+
+ if ( ! aRootContent.is() )
+ return sal_False;
+
+ mbConstructed = sal_True;
+ maRootURL = aRootContent->getIdentifier()->getContentIdentifier();
+
+ ResStringArray aLongNames( SfxResId( TEMPLATE_LONG_NAMES_ARY ) );
+
+ if ( aLongNames.Count() )
+ maStandardGroup = aLongNames.GetString( 0 );
+
+ Content aTemplRoot( aRootContent, aCmdEnv );
+ CreateFromHierarchy( aTemplRoot );
+
+ return sal_True;
+}
+
+// -----------------------------------------------------------------------
+void SfxDocTemplate_Impl::ReInitFromComponent()
+{
+ uno::Reference< XDocumentTemplates > xTemplates = getDocTemplates();
+ if ( xTemplates.is() )
+ {
+ uno::Reference < XContent > aRootContent = xTemplates->getContent();
+ uno::Reference < XCommandEnvironment > aCmdEnv;
+ Content aTemplRoot( aRootContent, aCmdEnv );
+ Clear();
+ CreateFromHierarchy( aTemplRoot );
+ }
+}
+
+// -----------------------------------------------------------------------
+void SfxDocTemplate_Impl::GetTemplates( Content& rTargetFolder,
+ Content& /*rParentFolder*/,
+ RegionData_Impl* pRegion )
+{
+ uno::Reference< XResultSet > xResultSet;
+ Sequence< OUString > aProps(1);
+
+ aProps[0] = OUString::createFromAscii( TITLE );
+
+ try
+ {
+ ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
+ Sequence< NumberedSortingInfo > aSortingInfo(1);
+ aSortingInfo.getArray()->ColumnIndex = 1;
+ aSortingInfo.getArray()->Ascending = sal_True;
+ xResultSet = rTargetFolder.createSortedCursor( aProps, aSortingInfo, m_rCompareFactory, eInclude );
+ }
+ catch ( Exception& ) {}
+
+ if ( xResultSet.is() )
+ {
+ uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
+ uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
+
+ try
+ {
+ while ( xResultSet->next() )
+ {
+ OUString aTitle( xRow->getString(1) );
+
+ if ( aTitle.compareToAscii( "sfx.tlx" ) == 0 )
+ continue;
+
+ OUString aId = xContentAccess->queryContentIdentifierString();
+
+ DocTempl_EntryData_Impl* pEntry = pRegion->GetByTargetURL( aId );
+
+ if ( ! pEntry )
+ {
+ OUString aFullTitle;
+ if( !GetTitleFromURL( aId, aFullTitle ) )
+ {
+ DBG_ERRORFILE( "GetTemplates(): template of alien format" );
+ continue;
+ }
+
+ if ( aFullTitle.getLength() )
+ aTitle = aFullTitle;
+
+ pRegion->AddEntry( aTitle, aId );
+ }
+ }
+ }
+ catch ( Exception& ) {}
+ }
+}
+
+
+// -----------------------------------------------------------------------
+long SfxDocTemplate_Impl::GetRegionPos( const OUString& rTitle,
+ sal_Bool& rFound ) const
+{
+ int nCompVal = 1;
+ long nStart = 0;
+ long nEnd = maRegions.Count() - 1;
+ long nMid = 0;
+
+ RegionData_Impl* pMid;
+
+ while ( nCompVal && ( nStart <= nEnd ) )
+ {
+ nMid = ( nEnd - nStart ) / 2 + nStart;
+ pMid = maRegions.GetObject( nMid );
+
+ nCompVal = pMid->Compare( rTitle );
+
+ if ( nCompVal < 0 ) // pMid < pData
+ nStart = nMid + 1;
+ else
+ nEnd = nMid - 1;
+ }
+
+ if ( nCompVal == 0 )
+ rFound = sal_True;
+ else
+ {
+ if ( nCompVal < 0 ) // pMid < pData
+ nMid++;
+
+ rFound = sal_False;
+ }
+
+ return nMid;
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTemplate_Impl::InsertRegion( RegionData_Impl *pNew,
+ ULONG nPos )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+ RegionData_Impl *pData = maRegions.First();
+
+ while ( pData && ( pData->Compare( pNew ) != 0 ) )
+ pData = maRegions.Next();
+
+ if ( ! pData )
+ {
+ // compare with the name of the standard group here to insert it
+ // first
+
+ if ( pNew->GetTitle() == maStandardGroup )
+ maRegions.Insert( pNew, (ULONG) 0 );
+ else
+ maRegions.Insert( pNew, nPos );
+ }
+
+ return ( pData == NULL );
+}
+
+// -----------------------------------------------------------------------
+void SfxDocTemplate_Impl::Rescan()
+{
+ Clear();
+
+ try
+ {
+ uno::Reference< XDocumentTemplates > xTemplates = getDocTemplates();
+ DBG_ASSERT( xTemplates.is(), "SfxDocTemplate_Impl::Rescan:invalid template instance!" );
+ if ( xTemplates.is() )
+ {
+ xTemplates->update();
+
+ uno::Reference < XContent > aRootContent = xTemplates->getContent();
+ uno::Reference < XCommandEnvironment > aCmdEnv;
+
+ Content aTemplRoot( aRootContent, aCmdEnv );
+ CreateFromHierarchy( aTemplRoot );
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_ERRORFILE( "SfxDocTemplate_Impl::Rescan: caught an exception while doing the update!" );
+ }
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTemplate_Impl::GetTitleFromURL( const OUString& rURL,
+ OUString& aTitle )
+{
+ if ( mxInfo.is() )
+ {
+ try
+ {
+ mxInfo->read( rURL );
+ }
+ catch ( Exception& )
+ {
+ // the document is not a StarOffice document
+ return sal_False;
+ }
+
+
+ try
+ {
+ uno::Reference< XPropertySet > aPropSet( mxInfo, UNO_QUERY );
+ if ( aPropSet.is() )
+ {
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TITLE ) );
+ Any aValue = aPropSet->getPropertyValue( aPropName );
+ aValue >>= aTitle;
+ }
+ }
+ catch ( IOException& ) {}
+ catch ( UnknownPropertyException& ) {}
+ catch ( Exception& ) {}
+ }
+
+ if ( ! aTitle.getLength() )
+ {
+ INetURLObject aURL( rURL );
+ aURL.CutExtension();
+ aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET );
+ }
+
+ return sal_True;
+}
+
+
+// -----------------------------------------------------------------------
+void SfxDocTemplate_Impl::Clear()
+{
+ ::osl::MutexGuard aGuard( maMutex );
+ if ( mnLockCounter )
+ return;
+
+ RegionData_Impl *pRegData = maRegions.First();
+
+ while ( pRegData )
+ {
+ delete pRegData;
+ pRegData = maRegions.Next();
+ }
+
+ maRegions.Clear();
+}
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+sal_Bool getTextProperty_Impl( Content& rContent,
+ const OUString& rPropName,
+ OUString& rPropValue )
+{
+ sal_Bool bGotProperty = sal_False;
+
+ // Get the property
+ try
+ {
+ uno::Reference< XPropertySetInfo > aPropInfo = rContent.getProperties();
+
+ // check, wether or not the property exists
+ if ( !aPropInfo.is() || !aPropInfo->hasPropertyByName( rPropName ) )
+ {
+ return sal_False;
+ }
+
+ // now get the property
+ Any aAnyValue;
+
+ aAnyValue = rContent.getPropertyValue( rPropName );
+ aAnyValue >>= rPropValue;
+
+ if ( SfxURLRelocator_Impl::propertyCanContainOfficeDir( rPropName ) )
+ {
+ SfxURLRelocator_Impl aRelocImpl( ::comphelper::getProcessServiceFactory() );
+ aRelocImpl.makeAbsoluteURL( rPropValue );
+ }
+
+ bGotProperty = sal_True;
+ }
+ catch ( RuntimeException& ) {}
+ catch ( Exception& ) {}
+
+ return bGotProperty;
+}
+
diff --git a/sfx2/source/doc/doctempl.src b/sfx2/source/doc/doctempl.src
new file mode 100644
index 000000000000..2c91358f845e
--- /dev/null
+++ b/sfx2/source/doc/doctempl.src
@@ -0,0 +1,106 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <sfx2/sfx.hrc>
+
+#include "doc.hrc"
+
+StringArray TEMPLATE_SHORT_NAMES_ARY
+{
+ ItemList =
+ {
+ < "standard" ; > ;
+ < "officorr" ; > ;
+ < "offimisc" ; > ;
+ < "personal" ; > ;
+ < "forms" ; > ;
+ < "finance" ; > ;
+ < "educate" ; > ;
+ < "layout" ; > ;
+ < "presnt" ; > ;
+ < "misc" ; > ;
+ };
+};
+
+StringArray TEMPLATE_LONG_NAMES_ARY
+{
+ ItemList [ en-US ] =
+ {
+ < "My Templates" ; > ;
+ < "Business Correspondence" ; > ;
+ < "Other Business Documents" ; > ;
+ < "Personal Correspondence and Documents" ; > ;
+ < "Forms and Contracts" ; > ;
+ < "Finances" ; > ;
+ < "Education" ; > ;
+ < "Presentation Backgrounds" ; > ;
+ < "Presentations" ; > ;
+ < "Miscellaneous" ; > ;
+ };
+
+ };
+
+String RID_CNT_STR_WAITING
+{
+ Text [ en-US ] = "The templates are being initialized for first-time usage." ;
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx
new file mode 100644
index 000000000000..8644e79f611d
--- /dev/null
+++ b/sfx2/source/doc/doctemplates.cxx
@@ -0,0 +1,2898 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "doctemplates.hxx"
+#include <vos/mutex.hxx>
+#include <tools/debug.hxx>
+#include <tools/urlobj.hxx>
+#include <rtl/ustring.hxx>
+#include <rtl/ustrbuf.hxx>
+#ifndef _SV_RESARY_HXX
+#include <tools/resary.hxx>
+#endif
+#include <vcl/svapp.hxx>
+#include <vcl/wrkwin.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <unotools/pathoptions.hxx>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+#include <com/sun/star/beans/StringPair.hpp>
+#include <com/sun/star/container/XContainerQuery.hpp>
+#include <com/sun/star/document/XTypeDetection.hpp>
+#include <com/sun/star/document/XStandaloneDocumentInfo.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/ucb/NameClash.hpp>
+#include <com/sun/star/ucb/NameClashException.hpp>
+#include <com/sun/star/ucb/TransferInfo.hpp>
+#include <com/sun/star/ucb/XCommandEnvironment.hpp>
+#include <com/sun/star/ucb/XContentAccess.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
+
+#include <svtools/templatefoldercache.hxx>
+#include <unotools/configmgr.hxx>
+#include <unotools/ucbhelper.hxx>
+
+#include "sfx2/sfxresid.hxx"
+#include "sfxurlrelocator.hxx"
+#include "doctemplateslocal.hxx"
+#include <sfx2/docfac.hxx>
+#include <sfx2/docfile.hxx>
+#include "doc.hrc"
+
+//-----------------------------------------------------------------------------
+
+//=============================================================================
+
+#define TEMPLATE_SERVICE_NAME "com.sun.star.frame.DocumentTemplates"
+#define TEMPLATE_IMPLEMENTATION_NAME "com.sun.star.comp.sfx2.DocumentTemplates"
+
+#define SERVICENAME_TYPEDETECTION "com.sun.star.document.TypeDetection"
+#define SERVICENAME_DOCINFO "com.sun.star.document.StandaloneDocumentInfo"
+
+#define TEMPLATE_ROOT_URL "vnd.sun.star.hier:/templates"
+#define TITLE "Title"
+#define IS_FOLDER "IsFolder"
+#define IS_DOCUMENT "IsDocument"
+#define TARGET_URL "TargetURL"
+#define TEMPLATE_VERSION "TemplateComponentVersion"
+#define TEMPLATE_VERSION_VALUE "2"
+#define TYPE_FOLDER "application/vnd.sun.star.hier-folder"
+#define TYPE_LINK "application/vnd.sun.star.hier-link"
+#define TYPE_FSYS_FOLDER "application/vnd.sun.staroffice.fsys-folder"
+#define TYPE_FSYS_FILE "application/vnd.sun.staroffice.fsys-file"
+
+#define PROPERTY_DIRLIST "DirectoryList"
+#define PROPERTY_NEEDSUPDATE "NeedsUpdate"
+#define PROPERTY_TYPE "TypeDescription"
+
+#define TARGET_DIR_URL "TargetDirURL"
+#define COMMAND_DELETE "delete"
+#define COMMAND_TRANSFER "transfer"
+
+#define STANDARD_FOLDER "standard"
+
+#define C_DELIM ';'
+
+//=============================================================================
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::util;
+
+using namespace ::rtl;
+using namespace ::ucbhelper;
+using namespace ::comphelper;
+
+//=============================================================================
+
+class WaitWindow_Impl : public WorkWindow
+{
+ Rectangle _aRect;
+ USHORT _nTextStyle;
+ String _aText;
+
+ public:
+ WaitWindow_Impl();
+ ~WaitWindow_Impl();
+ virtual void Paint( const Rectangle& rRect );
+};
+
+#define X_OFFSET 15
+#define Y_OFFSET 15
+
+//=============================================================================
+
+struct NamePair_Impl
+{
+ OUString maShortName;
+ OUString maLongName;
+};
+
+DECLARE_LIST( NameList_Impl, NamePair_Impl* )
+
+class Updater_Impl;
+class GroupList_Impl;
+class DocTemplates_EntryData_Impl;
+class GroupData_Impl;
+
+//=============================================================================
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/ucb/XProgressHandler.hpp>
+#include <com/sun/star/ucb/XCommandEnvironment.hpp>
+
+class TplTaskEnvironment : public ::cppu::WeakImplHelper1< ucb::XCommandEnvironment >
+{
+ uno::Reference< task::XInteractionHandler > m_xInteractionHandler;
+ uno::Reference< ucb::XProgressHandler > m_xProgressHandler;
+
+public:
+ TplTaskEnvironment( const uno::Reference< task::XInteractionHandler>& rxInteractionHandler )
+ : m_xInteractionHandler( rxInteractionHandler )
+ {}
+
+ virtual uno::Reference<task::XInteractionHandler> SAL_CALL getInteractionHandler() throw (uno::RuntimeException)
+ { return m_xInteractionHandler; }
+
+ virtual uno::Reference<ucb::XProgressHandler> SAL_CALL getProgressHandler() throw (uno::RuntimeException)
+ { return m_xProgressHandler; }
+};
+
+class SfxDocTplService_Impl
+{
+ uno::Reference< XMultiServiceFactory > mxFactory;
+ uno::Reference< XCommandEnvironment > maCmdEnv;
+ uno::Reference< XStandaloneDocumentInfo > mxInfo;
+ uno::Reference< XTypeDetection > mxType;
+
+ ::osl::Mutex maMutex;
+ Sequence< OUString > maTemplateDirs;
+ OUString maRootURL;
+ NameList_Impl maNames;
+ Locale maLocale;
+ Content maRootContent;
+ Updater_Impl* mpUpdater;
+ sal_Bool mbIsInitialized : 1;
+ sal_Bool mbLocaleSet : 1;
+
+ SfxURLRelocator_Impl maRelocator;
+
+ void init_Impl();
+ void getDefaultLocale();
+ void getDirList();
+ void readFolderList();
+ sal_Bool needsUpdate();
+ OUString getLongName( const OUString& rShortName );
+ sal_Bool setTitleForURL( const OUString& rURL, const OUString& aTitle );
+ sal_Bool getTitleFromURL( const OUString& rURL, OUString& aTitle, OUString& aType, sal_Bool& bDocHasTitle );
+
+ sal_Bool addEntry( Content& rParentFolder,
+ const OUString& rTitle,
+ const OUString& rTargetURL,
+ const OUString& rType );
+
+ sal_Bool createFolder( const OUString& rNewFolderURL,
+ sal_Bool bCreateParent,
+ sal_Bool bFsysFolder,
+ Content &rNewFolder );
+
+ sal_Bool CreateNewUniqueFolderWithPrefix( const ::rtl::OUString& aPath,
+ const ::rtl::OUString& aPrefix,
+ ::rtl::OUString& aNewFolderName,
+ ::rtl::OUString& aNewFolderURL,
+ Content& aNewFolder );
+ ::rtl::OUString CreateNewUniqueFileWithPrefix( const ::rtl::OUString& aPath,
+ const ::rtl::OUString& aPrefix,
+ const ::rtl::OUString& aExt );
+
+ uno::Sequence< beans::StringPair > ReadUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath );
+ sal_Bool UpdateUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
+ const ::rtl::OUString& aGroupName,
+ const ::rtl::OUString& aNewFolderName );
+ sal_Bool ReplaceUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
+ const ::rtl::OUString& aFsysGroupName,
+ const ::rtl::OUString& aOldGroupName,
+ const ::rtl::OUString& aNewGroupName );
+ sal_Bool RemoveUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
+ const ::rtl::OUString& aGroupName );
+ sal_Bool WriteUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
+ const uno::Sequence< beans::StringPair >& aUINames );
+
+ ::rtl::OUString CreateNewGroupFsys( const ::rtl::OUString& rGroupName, Content& aGroup );
+
+ sal_Bool removeContent( Content& rContent );
+ sal_Bool removeContent( const OUString& rContentURL );
+
+ sal_Bool setProperty( Content& rContent,
+ const OUString& rPropName,
+ const Any& rPropValue );
+ sal_Bool getProperty( Content& rContent,
+ const OUString& rPropName,
+ Any& rPropValue );
+
+ void createFromContent( GroupList_Impl& rList,
+ Content &rContent,
+ sal_Bool bHierarchy,
+ sal_Bool bWriteableContent = sal_False );
+ void addHierGroup( GroupList_Impl& rList,
+ const OUString& rTitle,
+ const OUString& rOwnURL );
+ void addFsysGroup( GroupList_Impl& rList,
+ const OUString& rTitle,
+ const OUString& rUITitle,
+ const OUString& rOwnURL,
+ sal_Bool bWriteableGroup = sal_False );
+ void removeFromHierarchy( DocTemplates_EntryData_Impl *pData );
+ void addToHierarchy( GroupData_Impl *pGroup,
+ DocTemplates_EntryData_Impl *pData );
+
+ void removeFromHierarchy( GroupData_Impl *pGroup );
+ void addGroupToHierarchy( GroupData_Impl *pGroup );
+
+ void updateData( DocTemplates_EntryData_Impl *pData );
+
+public:
+ SfxDocTplService_Impl( uno::Reference< XMultiServiceFactory > xFactory );
+ ~SfxDocTplService_Impl();
+
+ sal_Bool init() { if ( !mbIsInitialized ) init_Impl(); return mbIsInitialized; }
+ Content getContent() { return maRootContent; }
+
+ void setLocale( const Locale & rLocale );
+ Locale getLocale();
+
+ sal_Bool storeTemplate( const OUString& rGroupName,
+ const OUString& rTemplateName,
+ const uno::Reference< XSTORABLE >& rStorable );
+
+ sal_Bool addTemplate( const OUString& rGroupName,
+ const OUString& rTemplateName,
+ const OUString& rSourceURL );
+ sal_Bool removeTemplate( const OUString& rGroupName,
+ const OUString& rTemplateName );
+ sal_Bool renameTemplate( const OUString& rGroupName,
+ const OUString& rOldName,
+ const OUString& rNewName );
+
+ sal_Bool addGroup( const OUString& rGroupName );
+ sal_Bool removeGroup( const OUString& rGroupName );
+ sal_Bool renameGroup( const OUString& rOldName,
+ const OUString& rNewName );
+
+ void update( sal_Bool bUpdateNow );
+ void doUpdate();
+ void finished() { mpUpdater = NULL; }
+};
+
+//=============================================================================
+
+class Updater_Impl : public ::vos::OThread
+{
+private:
+ SfxDocTplService_Impl *mpDocTemplates;
+
+public:
+ Updater_Impl( SfxDocTplService_Impl* pTemplates );
+ ~Updater_Impl();
+
+ virtual void SAL_CALL run();
+ virtual void SAL_CALL onTerminated();
+};
+
+//=============================================================================
+
+class DocTemplates_EntryData_Impl
+{
+ OUString maTitle;
+ OUString maType;
+ OUString maTargetURL;
+ OUString maHierarchyURL;
+
+ sal_Bool mbInHierarchy : 1;
+ sal_Bool mbInUse : 1;
+ sal_Bool mbUpdateType : 1;
+ sal_Bool mbUpdateLink : 1;
+
+public:
+ DocTemplates_EntryData_Impl( const OUString& rTitle );
+
+ void setInUse() { mbInUse = sal_True; }
+ void setHierarchy( sal_Bool bInHierarchy ) { mbInHierarchy = bInHierarchy; }
+ void setUpdateLink( sal_Bool bUpdateLink ) { mbUpdateLink = bUpdateLink; }
+ void setUpdateType( sal_Bool bUpdateType ) { mbUpdateType = bUpdateType; }
+
+ sal_Bool getInUse() const { return mbInUse; }
+ sal_Bool getInHierarchy() const { return mbInHierarchy; }
+ sal_Bool getUpdateLink() const { return mbUpdateLink; }
+ sal_Bool getUpdateType() const { return mbUpdateType; }
+
+ const OUString& getHierarchyURL() const { return maHierarchyURL; }
+ const OUString& getTargetURL() const { return maTargetURL; }
+ const OUString& getTitle() const { return maTitle; }
+ const OUString& getType() const { return maType; }
+
+ void setHierarchyURL( const OUString& rURL ) { maHierarchyURL = rURL; }
+ void setTargetURL( const OUString& rURL ) { maTargetURL = rURL; }
+ void setType( const OUString& rType ) { maType = rType; }
+};
+
+//=============================================================================
+
+class GroupData_Impl
+{
+ DECLARE_LIST( EntryList_Impl, DocTemplates_EntryData_Impl* )
+ EntryList_Impl maEntries;
+ OUString maTitle;
+ OUString maHierarchyURL;
+ OUString maTargetURL;
+ sal_Bool mbInUse : 1;
+ sal_Bool mbInHierarchy : 1;
+
+public:
+ GroupData_Impl( const OUString& rTitle );
+ ~GroupData_Impl();
+
+ void setInUse() { mbInUse = sal_True; }
+ void setHierarchy( sal_Bool bInHierarchy ) { mbInHierarchy = bInHierarchy; }
+ void setHierarchyURL( const OUString& rURL ) { maHierarchyURL = rURL; }
+ void setTargetURL( const OUString& rURL ) { maTargetURL = rURL; }
+
+ sal_Bool getInUse() { return mbInUse; }
+ sal_Bool getInHierarchy() { return mbInHierarchy; }
+ const OUString& getHierarchyURL() const { return maHierarchyURL; }
+ const OUString& getTargetURL() const { return maTargetURL; }
+ const OUString& getTitle() const { return maTitle; }
+
+ DocTemplates_EntryData_Impl* addEntry( const OUString& rTitle,
+ const OUString& rTargetURL,
+ const OUString& rType,
+ const OUString& rHierURL );
+ ULONG count() { return maEntries.Count(); }
+ DocTemplates_EntryData_Impl* getEntry( ULONG nPos ) { return maEntries.GetObject( nPos ); }
+};
+
+DECLARE_LIST( GroupList_Impl, GroupData_Impl* )
+
+//=============================================================================
+//=============================================================================
+//=============================================================================
+
+//-----------------------------------------------------------------------------
+// private SfxDocTplService_Impl
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::init_Impl()
+{
+ uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
+ if ( xFactory.is() )
+ {
+ uno::Reference < task::XInteractionHandler > xInteractionHandler( xFactory->createInstance( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ), uno::UNO_QUERY );
+ maCmdEnv = new TplTaskEnvironment( xInteractionHandler );
+ }
+
+ ::osl::ClearableMutexGuard aGuard( maMutex );
+ sal_Bool bIsInitialized = sal_False;
+ sal_Bool bNeedsUpdate = sal_False;
+
+ if ( !mbLocaleSet )
+ getDefaultLocale();
+
+ // convert locale to string
+ OUString aLang = maLocale.Language;
+ aLang += String( '-' );
+ aLang += maLocale.Country;
+
+ // set maRootContent to the root of the templates hierarchy. Create the
+ // entry if necessary
+
+ maRootURL = OUString( RTL_CONSTASCII_USTRINGPARAM( TEMPLATE_ROOT_URL ) );
+ maRootURL += String( '/' );
+ maRootURL += aLang;
+
+ ::rtl::OUString aTemplVersPropName( RTL_CONSTASCII_USTRINGPARAM( TEMPLATE_VERSION ) );
+ ::rtl::OUString aTemplVers( RTL_CONSTASCII_USTRINGPARAM( TEMPLATE_VERSION_VALUE ) );
+ if ( Content::create( maRootURL, maCmdEnv, maRootContent ) )
+ {
+ uno::Any aValue;
+ ::rtl::OUString aPropValue;
+ if ( getProperty( maRootContent, aTemplVersPropName, aValue )
+ && ( aValue >>= aPropValue )
+ && aPropValue.equals( aTemplVers ) )
+ {
+ bIsInitialized = sal_True;
+ }
+ else
+ removeContent( maRootContent );
+ }
+
+ if ( !bIsInitialized )
+ {
+ if ( createFolder( maRootURL, sal_True, sal_False, maRootContent )
+ && setProperty( maRootContent, aTemplVersPropName, uno::makeAny( aTemplVers ) ) )
+ bIsInitialized = sal_True;
+
+ bNeedsUpdate = sal_True;
+ }
+
+ if ( bIsInitialized )
+ {
+ OUString aService( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_DOCINFO ) );
+ try {
+ mxInfo = uno::Reference< XStandaloneDocumentInfo > (
+ mxFactory->createInstance( aService ), UNO_QUERY );
+ } catch (uno::RuntimeException &) {
+ OSL_ENSURE(false, "SfxDocTplService_Impl::init_Impl: "
+ "cannot create DocumentProperties service");
+ }
+
+ aService = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_TYPEDETECTION ) );
+ mxType = uno::Reference< XTypeDetection > ( mxFactory->createInstance( aService ), UNO_QUERY );
+
+ getDirList();
+ readFolderList();
+
+ if ( bNeedsUpdate )
+ {
+ aGuard.clear();
+ ::vos::OClearableGuard aSolarGuard( Application::GetSolarMutex() );
+
+ WaitWindow_Impl* pWin = new WaitWindow_Impl();
+
+ aSolarGuard.clear();
+ ::osl::ClearableMutexGuard anotherGuard( maMutex );
+
+ update( sal_True );
+
+ anotherGuard.clear();
+ ::vos::OGuard aSecondSolarGuard( Application::GetSolarMutex() );
+
+ delete pWin;
+ }
+ else if ( needsUpdate() )
+ // the UI should be shown only on the first update
+ update( sal_True );
+ }
+ else
+ {
+ DBG_ERRORFILE( "init_Impl(): Could not create root" );
+ }
+
+ mbIsInitialized = bIsInitialized;
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::getDefaultLocale()
+{
+ if ( !mbLocaleSet )
+ {
+ ::osl::MutexGuard aGuard( maMutex );
+ if ( !mbLocaleSet )
+ {
+ rtl::OUString aLocale;
+ utl::ConfigManager::GetDirectConfigProperty( utl::ConfigManager::LOCALE )
+ >>= aLocale;
+
+ if ( aLocale.getLength() > 0 )
+ {
+ sal_Int32 nPos = aLocale.indexOf( sal_Unicode( '-' ) );
+ if ( nPos != -1 )
+ {
+ maLocale.Language = aLocale.copy( 0, nPos );
+ nPos = aLocale.indexOf( sal_Unicode( '_' ), nPos + 1 );
+ if ( nPos != -1 )
+ {
+ maLocale.Country
+ = aLocale.copy( maLocale.Language.getLength() + 1,
+ nPos - maLocale.Language.getLength() - 1 );
+ maLocale.Variant
+ = aLocale.copy( nPos + 1 );
+ }
+ else
+ {
+ maLocale.Country
+ = aLocale.copy( maLocale.Language.getLength() + 1 );
+ }
+ }
+
+ }
+
+ mbLocaleSet = sal_True;
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+void SfxDocTplService_Impl::readFolderList()
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ ResStringArray aShortNames( SfxResId( TEMPLATE_SHORT_NAMES_ARY ) );
+ ResStringArray aLongNames( SfxResId( TEMPLATE_LONG_NAMES_ARY ) );
+
+ NamePair_Impl* pPair;
+
+ USHORT nCount = (USHORT)( Min( aShortNames.Count(), aLongNames.Count() ) );
+
+ for ( USHORT i=0; i<nCount; i++ )
+ {
+ pPair = new NamePair_Impl;
+ pPair->maShortName = aShortNames.GetString( i );
+ pPair->maLongName = aLongNames.GetString( i );
+
+ maNames.Insert( pPair, LIST_APPEND );
+ }
+}
+
+// -----------------------------------------------------------------------
+OUString SfxDocTplService_Impl::getLongName( const OUString& rShortName )
+{
+ OUString aRet;
+ NamePair_Impl *pPair = maNames.First();
+
+ while ( pPair )
+ {
+ if ( pPair->maShortName == rShortName )
+ {
+ aRet = pPair->maLongName;
+ break;
+ }
+ else
+ pPair = maNames.Next();
+ }
+
+ if ( !aRet.getLength() )
+ aRet = rShortName;
+
+ return aRet;
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::getDirList()
+{
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( PROPERTY_DIRLIST ) );
+ Any aValue;
+
+ // Get the template dir list
+ // TODO/LATER: let use service, register listener
+ INetURLObject aURL;
+ String aDirs = SvtPathOptions().GetTemplatePath();
+ USHORT nCount = aDirs.GetTokenCount( C_DELIM );
+
+ maTemplateDirs = Sequence< OUString >( nCount );
+
+ for ( USHORT i=0; i<nCount; i++ )
+ {
+ aURL.SetSmartProtocol( INET_PROT_FILE );
+ aURL.SetURL( aDirs.GetToken( i, C_DELIM ) );
+ maTemplateDirs[i] = aURL.GetMainURL( INetURLObject::NO_DECODE );
+ }
+
+ aValue <<= maTemplateDirs;
+
+ // Store the template dir list
+ setProperty( maRootContent, aPropName, aValue );
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::needsUpdate()
+{
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( PROPERTY_NEEDSUPDATE ) );
+ sal_Bool bHasProperty = sal_False;
+ sal_Bool bNeedsUpdate = sal_True;
+ Any aValue;
+
+ // Get the template dir list
+ bHasProperty = getProperty( maRootContent, aPropName, aValue );
+
+ if ( bHasProperty )
+ aValue >>= bNeedsUpdate;
+
+ // the old template component also checks this state, but it is initialized from this component
+ // so if this componend was already updated the old component does not need such an update
+ ::svt::TemplateFolderCache aTempCache;
+ if ( !bNeedsUpdate )
+ bNeedsUpdate = aTempCache.needsUpdate();
+
+ if ( bNeedsUpdate )
+ aTempCache.storeState();
+
+ return bNeedsUpdate;
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::setTitleForURL( const OUString& rURL, const OUString& aTitle )
+{
+ sal_Bool bResult = sal_False;
+ if ( mxInfo.is() )
+ {
+ try
+ {
+ mxInfo->loadFromURL( rURL );
+ uno::Reference< XPropertySet > xPropSet( mxInfo, UNO_QUERY_THROW );
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TITLE ) );
+ xPropSet->setPropertyValue( aPropName, uno::makeAny( aTitle ) );
+ mxInfo->storeIntoURL( rURL );
+ bResult = sal_True;
+ }
+ catch ( Exception& )
+ {
+ }
+ }
+
+ return bResult;
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::getTitleFromURL( const OUString& rURL, OUString& aTitle, OUString& aType, sal_Bool& bDocHasTitle )
+{
+ bDocHasTitle = sal_False;
+
+ if ( mxInfo.is() )
+ {
+ try
+ {
+ mxInfo->loadFromURL( rURL );
+ }
+ catch ( Exception& )
+ {
+ // the document is not a StarOffice document
+ return sal_False;
+ }
+
+ try
+ {
+ uno::Reference< XPropertySet > aPropSet( mxInfo, UNO_QUERY );
+ if ( aPropSet.is() )
+ {
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TITLE ) );
+ Any aValue = aPropSet->getPropertyValue( aPropName );
+ aValue >>= aTitle;
+
+ aPropName = OUString( RTL_CONSTASCII_USTRINGPARAM( "MIMEType" ) );
+ aValue = aPropSet->getPropertyValue( aPropName );
+ aValue >>= aType;
+ }
+ }
+ catch ( UnknownPropertyException& ) {}
+ catch ( Exception& ) {}
+ }
+
+ if ( ! aType.getLength() && mxType.is() )
+ {
+ ::rtl::OUString aDocType = mxType->queryTypeByURL( rURL );
+ if ( aDocType.getLength() )
+ try
+ {
+ uno::Reference< container::XNameAccess > xTypeDetection( mxType, uno::UNO_QUERY_THROW );
+ SequenceAsHashMap aTypeProps( xTypeDetection->getByName( aDocType ) );
+ aType = aTypeProps.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "MediaType" ),
+ ::rtl::OUString() );
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ if ( ! aTitle.getLength() )
+ {
+ INetURLObject aURL( rURL );
+ aURL.CutExtension();
+ aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET );
+ }
+ else
+ bDocHasTitle = sal_True;
+
+ return sal_True;
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::addEntry( Content& rParentFolder,
+ const OUString& rTitle,
+ const OUString& rTargetURL,
+ const OUString& rType )
+{
+ sal_Bool bAddedEntry = sal_False;
+
+ INetURLObject aLinkObj( rParentFolder.getURL() );
+ aLinkObj.insertName( rTitle, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ OUString aLinkURL = aLinkObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ Content aLink;
+
+ if ( ! Content::create( aLinkURL, maCmdEnv, aLink ) )
+ {
+ Sequence< OUString > aNames(3);
+ aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( TITLE ) );
+ aNames[1] = OUString( RTL_CONSTASCII_USTRINGPARAM( IS_FOLDER ) );
+ aNames[2] = OUString( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
+
+ Sequence< Any > aValues(3);
+ aValues[0] = makeAny( rTitle );
+ aValues[1] = makeAny( sal_Bool( sal_False ) );
+ aValues[2] = makeAny( rTargetURL );
+
+ OUString aType( RTL_CONSTASCII_USTRINGPARAM( TYPE_LINK ) );
+ OUString aAdditionalProp( RTL_CONSTASCII_USTRINGPARAM( PROPERTY_TYPE ) );
+
+ try
+ {
+ rParentFolder.insertNewContent( aType, aNames, aValues, aLink );
+ setProperty( aLink, aAdditionalProp, makeAny( rType ) );
+ bAddedEntry = sal_True;
+ }
+ catch( Exception& )
+ {}
+ }
+ return bAddedEntry;
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::createFolder( const OUString& rNewFolderURL,
+ sal_Bool bCreateParent,
+ sal_Bool bFsysFolder,
+ Content &rNewFolder )
+{
+ Content aParent;
+ sal_Bool bCreatedFolder = sal_False;
+ INetURLObject aParentURL( rNewFolderURL );
+ OUString aFolderName = aParentURL.getName( INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET );
+
+ // compute the parent folder url from the new folder url
+ // and remove the final slash, because Content::create doesn't
+ // like it
+ aParentURL.removeSegment();
+ if ( aParentURL.getSegmentCount() >= 1 )
+ aParentURL.removeFinalSlash();
+
+ // if the parent exists, we can continue with the creation of the
+ // new folder, we have to create the parent otherwise ( as long as
+ // bCreateParent is set to true )
+ if ( Content::create( aParentURL.GetMainURL( INetURLObject::NO_DECODE ), maCmdEnv, aParent ) )
+ {
+ try
+ {
+ Sequence< OUString > aNames(2);
+ aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( TITLE ) );
+ aNames[1] = OUString( RTL_CONSTASCII_USTRINGPARAM( IS_FOLDER ) );
+
+ Sequence< Any > aValues(2);
+ aValues[0] = makeAny( aFolderName );
+ aValues[1] = makeAny( sal_Bool( sal_True ) );
+
+ OUString aType;
+
+ if ( bFsysFolder )
+ aType = OUString( RTL_CONSTASCII_USTRINGPARAM( TYPE_FSYS_FOLDER ) );
+ else
+ aType = OUString( RTL_CONSTASCII_USTRINGPARAM( TYPE_FOLDER ) );
+
+ aParent.insertNewContent( aType, aNames, aValues, rNewFolder );
+ bCreatedFolder = sal_True;
+ }
+ catch( RuntimeException& )
+ {
+ DBG_ERRORFILE( "createFolder(): got runtime exception" );
+ }
+ catch( Exception& )
+ {
+ DBG_ERRORFILE( "createFolder(): Could not create new folder" );
+ }
+ }
+ else if ( bCreateParent )
+ {
+ // if the parent doesn't exists and bCreateParent is set to true,
+ // we try to create the parent and if this was successful, we
+ // try to create the new folder again ( but this time, we set
+ // bCreateParent to false to avoid endless recusions )
+ if ( ( aParentURL.getSegmentCount() >= 1 ) &&
+ createFolder( aParentURL.GetMainURL( INetURLObject::NO_DECODE ), bCreateParent, bFsysFolder, aParent ) )
+ {
+ bCreatedFolder = createFolder( rNewFolderURL, sal_False, bFsysFolder, rNewFolder );
+ }
+ }
+
+ return bCreatedFolder;
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::CreateNewUniqueFolderWithPrefix( const ::rtl::OUString& aPath,
+ const ::rtl::OUString& aPrefix,
+ ::rtl::OUString& aNewFolderName,
+ ::rtl::OUString& aNewFolderURL,
+ Content& aNewFolder )
+{
+ sal_Bool bCreated = sal_False;
+ INetURLObject aDirPath( aPath );
+
+ Content aParent;
+ if ( Content::create( aDirPath.GetMainURL( INetURLObject::NO_DECODE ), maCmdEnv, aParent ) )
+ {
+ for ( sal_Int32 nInd = 0; nInd < 32000; nInd++ )
+ {
+ ::rtl::OUString aTryName = aPrefix;
+ if ( nInd )
+ aTryName += ::rtl::OUString::valueOf( nInd );
+
+ try
+ {
+ Sequence< OUString > aNames(2);
+ aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( TITLE ) );
+ aNames[1] = OUString( RTL_CONSTASCII_USTRINGPARAM( IS_FOLDER ) );
+
+ Sequence< Any > aValues(2);
+ aValues[0] = makeAny( aTryName );
+ aValues[1] = makeAny( sal_Bool( sal_True ) );
+
+ OUString aType( RTL_CONSTASCII_USTRINGPARAM( TYPE_FSYS_FOLDER ) );
+
+ bCreated = aParent.insertNewContent( aType, aNames, aValues, aNewFolder );
+ }
+ catch( ucb::NameClashException& )
+ {
+ // if there is already an element, retry
+ }
+ catch( Exception& )
+ {
+ INetURLObject aObjPath( aDirPath );
+ aObjPath.insertName( aTryName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ // if there is already an element, retry
+ // if there was another error, do not try any more
+ if ( !::utl::UCBContentHelper::Exists( aObjPath.GetMainURL( INetURLObject::NO_DECODE ) ) )
+ break;
+ }
+
+ if ( bCreated )
+ {
+ aNewFolderName = aTryName;
+ aNewFolderURL = aNewFolder.get()->getIdentifier()->getContentIdentifier();
+ break;
+ }
+ }
+ }
+
+ return bCreated;
+}
+
+// -----------------------------------------------------------------------
+::rtl::OUString SfxDocTplService_Impl::CreateNewUniqueFileWithPrefix( const ::rtl::OUString& aPath,
+ const ::rtl::OUString& aPrefix,
+ const ::rtl::OUString& aExt )
+{
+ ::rtl::OUString aNewFileURL;
+ INetURLObject aDirPath( aPath );
+
+ Content aParent;
+
+ uno::Reference< XCommandEnvironment > aQuietEnv;
+ if ( Content::create( aDirPath.GetMainURL( INetURLObject::NO_DECODE ), aQuietEnv, aParent ) )
+ {
+ for ( sal_Int32 nInd = 0; nInd < 32000; nInd++ )
+ {
+ Content aNewFile;
+ sal_Bool bCreated = sal_False;
+ ::rtl::OUString aTryName = aPrefix;
+ if ( nInd )
+ aTryName += ::rtl::OUString::valueOf( nInd );
+ if ( aExt.toChar() != '.' )
+ aTryName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) );
+ aTryName += aExt;
+
+ try
+ {
+ Sequence< OUString > aNames(2);
+ aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( TITLE ) );
+ aNames[1] = OUString( RTL_CONSTASCII_USTRINGPARAM( IS_DOCUMENT ) );
+
+ Sequence< Any > aValues(2);
+ aValues[0] = makeAny( aTryName );
+ aValues[1] = makeAny( sal_Bool( sal_True ) );
+
+ OUString aType( RTL_CONSTASCII_USTRINGPARAM( TYPE_FSYS_FILE ) );
+
+ bCreated = aParent.insertNewContent( aType, aNames, aValues, aNewFile );
+ }
+ catch( ucb::NameClashException& )
+ {
+ // if there is already an element, retry
+ }
+ catch( Exception& )
+ {
+ INetURLObject aObjPath( aPath );
+ aObjPath.insertName( aTryName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ // if there is already an element, retry
+ // if there was another error, do not try any more
+ if ( !::utl::UCBContentHelper::Exists( aObjPath.GetMainURL( INetURLObject::NO_DECODE ) ) )
+ break;
+ }
+
+ if ( bCreated )
+ {
+ aNewFileURL = aNewFile.get()->getIdentifier()->getContentIdentifier();
+ break;
+ }
+ }
+ }
+
+ return aNewFileURL;
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::removeContent( Content& rContent )
+{
+ sal_Bool bRemoved = sal_False;
+ try
+ {
+ OUString aCmd( RTL_CONSTASCII_USTRINGPARAM( COMMAND_DELETE ) );
+ Any aArg = makeAny( sal_Bool( sal_True ) );
+
+ rContent.executeCommand( aCmd, aArg );
+ bRemoved = sal_True;
+ }
+ catch ( RuntimeException& ) {}
+ catch ( Exception& ) {}
+
+ return bRemoved;
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::removeContent( const OUString& rContentURL )
+{
+ Content aContent;
+
+ if ( Content::create( rContentURL, maCmdEnv, aContent ) )
+ return removeContent( aContent );
+ else
+ return sal_False;
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::setProperty( Content& rContent,
+ const OUString& rPropName,
+ const Any& rPropValue )
+{
+ sal_Bool bPropertySet = sal_False;
+
+ // Store the property
+ try
+ {
+ Any aPropValue( rPropValue );
+ uno::Reference< XPropertySetInfo > aPropInfo = rContent.getProperties();
+
+ // check, wether or not the property exists, create it, when not
+ if ( !aPropInfo.is() || !aPropInfo->hasPropertyByName( rPropName ) )
+ {
+ uno::Reference< XPropertyContainer > xProperties( rContent.get(), UNO_QUERY );
+ if ( xProperties.is() )
+ {
+ try
+ {
+ xProperties->addProperty( rPropName, PropertyAttribute::MAYBEVOID, rPropValue );
+ }
+ catch( PropertyExistException& ) {}
+ catch( IllegalTypeException& ) { DBG_ERRORFILE( "IllegalTypeException" ); }
+ catch( IllegalArgumentException& ) { DBG_ERRORFILE( "IllegalArgumentException" ); }
+ }
+ }
+
+ // To ensure a reloctable office installation, the path to the
+ // office installtion directory must never be stored directly.
+ if ( SfxURLRelocator_Impl::propertyCanContainOfficeDir( rPropName ) )
+ {
+ OUString aValue;
+ if ( rPropValue >>= aValue )
+ {
+ maRelocator.makeRelocatableURL( aValue );
+ aPropValue = makeAny( aValue );
+ }
+ else
+ {
+ Sequence< OUString > aValues;
+ if ( rPropValue >>= aValues )
+ {
+ for ( sal_Int32 n = 0; n < aValues.getLength(); n++ )
+ {
+ maRelocator.makeRelocatableURL( aValues[ n ] );
+ }
+ aPropValue = makeAny( aValues );
+ }
+ else
+ {
+ OSL_ENSURE( false, "Unsupported property value type" );
+ }
+ }
+ }
+
+ // now set the property
+
+ rContent.setPropertyValue( rPropName, aPropValue );
+ bPropertySet = sal_True;
+ }
+ catch ( RuntimeException& ) {}
+ catch ( Exception& ) {}
+
+ return bPropertySet;
+}
+
+// -----------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::getProperty( Content& rContent,
+ const OUString& rPropName,
+ Any& rPropValue )
+{
+ sal_Bool bGotProperty = sal_False;
+
+ // Get the property
+ try
+ {
+ uno::Reference< XPropertySetInfo > aPropInfo = rContent.getProperties();
+
+ // check, wether or not the property exists
+ if ( !aPropInfo.is() || !aPropInfo->hasPropertyByName( rPropName ) )
+ {
+ return sal_False;
+ }
+
+ // now get the property
+
+ rPropValue = rContent.getPropertyValue( rPropName );
+
+ // To ensure a reloctable office installation, the path to the
+ // office installtion directory must never be stored directly.
+ if ( SfxURLRelocator_Impl::propertyCanContainOfficeDir( rPropName ) )
+ {
+ OUString aValue;
+ if ( rPropValue >>= aValue )
+ {
+ maRelocator.makeAbsoluteURL( aValue );
+ rPropValue = makeAny( aValue );
+ }
+ else
+ {
+ Sequence< OUString > aValues;
+ if ( rPropValue >>= aValues )
+ {
+ for ( sal_Int32 n = 0; n < aValues.getLength(); n++ )
+ {
+ maRelocator.makeAbsoluteURL( aValues[ n ] );
+ }
+ rPropValue = makeAny( aValues );
+ }
+ else
+ {
+ OSL_ENSURE( false, "Unsupported property value type" );
+ }
+ }
+ }
+
+ bGotProperty = sal_True;
+ }
+ catch ( RuntimeException& ) {}
+ catch ( Exception& ) {}
+
+ return bGotProperty;
+}
+
+// -----------------------------------------------------------------------
+// static
+bool SfxURLRelocator_Impl::propertyCanContainOfficeDir(
+ const rtl::OUString & rPropName )
+{
+ // Note: TargetURL is handled by UCB itself (because it is a property
+ // with a predefined semantic). Additional Core properties introduced
+ // be a client app must be handled by the client app itself, because
+ // the UCB does not know the semantics of those properties.
+ return ( rPropName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM( TARGET_DIR_URL ) ) ||
+ rPropName.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM( PROPERTY_DIRLIST ) ) );
+}
+
+//-----------------------------------------------------------------------------
+// public SfxDocTplService_Impl
+//-----------------------------------------------------------------------------
+
+SfxDocTplService_Impl::SfxDocTplService_Impl( uno::Reference< XMultiServiceFactory > xFactory )
+: maRelocator( xFactory )
+{
+ mxFactory = xFactory;
+ mpUpdater = NULL;
+ mbIsInitialized = sal_False;
+ mbLocaleSet = sal_False;
+}
+
+//-----------------------------------------------------------------------------
+SfxDocTplService_Impl::~SfxDocTplService_Impl()
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ if ( mpUpdater )
+ {
+ mpUpdater->kill();
+ delete mpUpdater;
+ }
+}
+
+//-----------------------------------------------------------------------------
+Locale SfxDocTplService_Impl::getLocale()
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ if ( !mbLocaleSet )
+ getDefaultLocale();
+
+ return maLocale;
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::setLocale( const Locale &rLocale )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ if ( mbLocaleSet &&
+ ( maLocale.Language != rLocale.Language ) &&
+ ( maLocale.Country != rLocale.Country ) )
+ mbIsInitialized = sal_False;
+
+ maLocale = rLocale;
+ mbLocaleSet = sal_True;
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::update( sal_Bool bUpdateNow )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ if ( bUpdateNow )
+ doUpdate();
+ else
+ {
+ mpUpdater = new Updater_Impl( this );
+ mpUpdater->create();
+ }
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::doUpdate()
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( PROPERTY_NEEDSUPDATE ) );
+ Any aValue;
+
+ aValue <<= sal_True;
+ setProperty( maRootContent, aPropName, aValue );
+
+ GroupList_Impl aGroupList;
+
+ // get the entries from the hierarchy
+ createFromContent( aGroupList, maRootContent, sal_True );
+
+ // get the entries from the template directories
+ sal_Int32 nCountDir = maTemplateDirs.getLength();
+ OUString* pDirs = maTemplateDirs.getArray();
+ Content aDirContent;
+
+ // the last directory in the list must be writable
+ sal_Bool bWriteableDirectory = sal_True;
+
+ // the target folder might not exist, for this reason no interaction handler should be used
+ uno::Reference< XCommandEnvironment > aQuietEnv;
+
+ while ( nCountDir )
+ {
+ nCountDir--;
+ if ( Content::create( pDirs[ nCountDir ], aQuietEnv, aDirContent ) )
+ {
+ createFromContent( aGroupList, aDirContent, sal_False, bWriteableDirectory );
+ }
+
+ bWriteableDirectory = sal_False;
+ }
+
+ // now check the list
+ GroupData_Impl *pGroup = aGroupList.First();
+ while ( pGroup )
+ {
+ if ( pGroup->getInUse() )
+ {
+ if ( pGroup->getInHierarchy() )
+ {
+ Content aGroup;
+ if ( Content::create( pGroup->getHierarchyURL(), maCmdEnv, aGroup ) )
+ setProperty( aGroup,
+ OUString( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) ),
+ makeAny( pGroup->getTargetURL() ) );
+
+ ULONG nCount = pGroup->count();
+ for ( ULONG i=0; i<nCount; i++ )
+ {
+ DocTemplates_EntryData_Impl *pData = pGroup->getEntry( i );
+ if ( ! pData->getInUse() )
+ {
+ if ( pData->getInHierarchy() )
+ removeFromHierarchy( pData ); // delete entry in hierarchy
+ else
+ addToHierarchy( pGroup, pData ); // add entry to hierarchy
+ }
+ else if ( pData->getUpdateType() ||
+ pData->getUpdateLink() )
+ {
+ updateData( pData );
+ }
+ }
+ }
+ else
+ {
+ addGroupToHierarchy( pGroup ); // add group to hierarchy
+ }
+ }
+ else
+ removeFromHierarchy( pGroup ); // delete group from hierarchy
+
+ delete pGroup;
+ pGroup = aGroupList.Next();
+ }
+
+ aValue <<= sal_False;
+ setProperty( maRootContent, aPropName, aValue );
+}
+
+//-----------------------------------------------------------------------------
+uno::Sequence< beans::StringPair > SfxDocTplService_Impl::ReadUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath )
+{
+ INetURLObject aLocObj( aUserPath );
+ aLocObj.insertName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "groupuinames.xml" ) ), false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ Content aLocContent;
+
+ // TODO/LATER: Use hashmap in future
+ uno::Sequence< beans::StringPair > aUINames;
+ if ( Content::create( aLocObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference < ucb::XCommandEnvironment >(), aLocContent ) )
+ {
+ try
+ {
+ uno::Reference< io::XInputStream > xLocStream = aLocContent.openStream();
+ if ( xLocStream.is() )
+ aUINames = DocTemplLocaleHelper::ReadGroupLocalizationSequence( xLocStream, mxFactory );
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ return aUINames;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::UpdateUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
+ const ::rtl::OUString& aGroupName,
+ const ::rtl::OUString& aNewFolderName )
+{
+ uno::Sequence< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath );
+ sal_Int32 nLen = aUINames.getLength();
+
+ // it is possible that the name is used already, but it should be checked before
+ for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
+ if ( aUINames[nInd].First.equals( aNewFolderName ) )
+ return sal_False;
+
+ aUINames.realloc( ++nLen );
+ aUINames[nLen-1].First = aNewFolderName;
+ aUINames[nLen-1].Second = aGroupName;
+
+ return WriteUINamesForTemplateDir_Impl( aUserPath, aUINames );
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::ReplaceUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
+ const ::rtl::OUString& aDefaultFsysGroupName,
+ const ::rtl::OUString& aOldGroupName,
+ const ::rtl::OUString& aNewGroupName )
+{
+ uno::Sequence< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath );
+ sal_Int32 nLen = aUINames.getLength();
+
+ sal_Bool bChanged = sal_False;
+ for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
+ if ( aUINames[nInd].Second.equals( aOldGroupName ) )
+ {
+ aUINames[nInd].Second = aNewGroupName;
+ bChanged = sal_True;
+ }
+
+ if ( !bChanged )
+ {
+ aUINames.realloc( ++nLen );
+ aUINames[nLen-1].First = aDefaultFsysGroupName;
+ aUINames[nLen-1].Second = aNewGroupName;
+ }
+ return WriteUINamesForTemplateDir_Impl( aUserPath, aUINames );
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::RemoveUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
+ const ::rtl::OUString& aGroupName )
+{
+ uno::Sequence< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath );
+ sal_Int32 nLen = aUINames.getLength();
+ uno::Sequence< beans::StringPair > aNewUINames( nLen );
+ sal_Int32 nNewLen = 0;
+
+ sal_Bool bChanged = sal_False;
+ for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
+ if ( aUINames[nInd].Second.equals( aGroupName ) )
+ bChanged = sal_True;
+ else
+ {
+ nNewLen++;
+ aNewUINames[nNewLen-1].First = aUINames[nInd].First;
+ aNewUINames[nNewLen-1].Second = aUINames[nInd].Second;
+ }
+
+ aNewUINames.realloc( nNewLen );
+
+ return bChanged ? WriteUINamesForTemplateDir_Impl( aUserPath, aNewUINames ) : sal_True;
+}
+
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::WriteUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
+ const uno::Sequence< beans::StringPair >& aUINames )
+{
+ sal_Bool bResult = sal_False;
+ try {
+ uno::Reference< beans::XPropertySet > xTempFile(
+ mxFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ),
+ uno::UNO_QUERY_THROW );
+
+ ::rtl::OUString aTempURL;
+ uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) );
+ aUrl >>= aTempURL;
+
+ uno::Reference< io::XStream > xStream( xTempFile, uno::UNO_QUERY_THROW );
+ uno::Reference< io::XOutputStream > xOutStream = xStream->getOutputStream();
+ if ( !xOutStream.is() )
+ throw uno::RuntimeException();
+
+ DocTemplLocaleHelper::WriteGroupLocalizationSequence( xOutStream, aUINames, mxFactory );
+ try {
+ // the SAX writer might close the stream
+ xOutStream->closeOutput();
+ } catch( uno::Exception& )
+ {}
+
+ Content aTargetContent( aUserPath, maCmdEnv );
+ Content aSourceContent( aTempURL, maCmdEnv );
+ aTargetContent.transferContent( aSourceContent,
+ InsertOperation_COPY,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "groupuinames.xml" ) ),
+ ucb::NameClash::OVERWRITE );
+ bResult = sal_True;
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ return bResult;
+}
+
+//-----------------------------------------------------------------------------
+::rtl::OUString SfxDocTplService_Impl::CreateNewGroupFsys( const ::rtl::OUString& rGroupName, Content& aGroup )
+{
+ ::rtl::OUString aResultURL;
+
+ if ( maTemplateDirs.getLength() )
+ {
+ ::rtl::OUString aTargetPath = maTemplateDirs[ maTemplateDirs.getLength() - 1 ];
+
+ // create a new folder with the given name
+ Content aNewFolder;
+ ::rtl::OUString aNewFolderName;
+
+ // the Fsys name instead of GroupName should be used, the groupuinames must be added also
+ if ( !CreateNewUniqueFolderWithPrefix( aTargetPath,
+ rGroupName,
+ aNewFolderName,
+ aResultURL,
+ aNewFolder )
+ && !CreateNewUniqueFolderWithPrefix( aTargetPath,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserGroup" ) ),
+ aNewFolderName,
+ aResultURL,
+ aNewFolder ) )
+
+ return ::rtl::OUString();
+
+ if ( !UpdateUINamesForTemplateDir_Impl( aTargetPath, rGroupName, aNewFolderName ) )
+ {
+ // we could not create the groupuinames for the folder, so we delete the group in the
+ // the folder and return
+ removeContent( aNewFolder );
+ return ::rtl::OUString();
+ }
+
+ // Now set the target url for this group and we are done
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) );
+ Any aValue = makeAny( aResultURL );
+
+ if ( ! setProperty( aGroup, aPropName, aValue ) )
+ {
+ removeContent( aNewFolder );
+ return ::rtl::OUString();
+ }
+ }
+
+ return aResultURL;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::addGroup( const OUString& rGroupName )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // Check, wether or not there is a group with this name
+ Content aNewGroup;
+ OUString aNewGroupURL;
+ INetURLObject aNewGroupObj( maRootURL );
+
+ aNewGroupObj.insertName( rGroupName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+
+ aNewGroupURL = aNewGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( Content::create( aNewGroupURL, maCmdEnv, aNewGroup ) ||
+ ! createFolder( aNewGroupURL, sal_False, sal_False, aNewGroup ) )
+ {
+ // if there already was a group with this name or the new group
+ // could not be created, we return here
+ return sal_False;
+ }
+
+ // Get the user template path entry ( new group will always
+ // be added in the user template path )
+ sal_Int32 nIndex;
+ OUString aUserPath;
+
+ nIndex = maTemplateDirs.getLength();
+ if ( nIndex )
+ nIndex--;
+ else
+ return sal_False; // We don't know where to add the group
+
+ aUserPath = maTemplateDirs[ nIndex ];
+
+ // create a new folder with the given name
+ Content aNewFolder;
+ OUString aNewFolderName;
+ OUString aNewFolderURL;
+
+ // the Fsys name instead of GroupName should be used, the groupuinames must be added also
+ if ( !CreateNewUniqueFolderWithPrefix( aUserPath,
+ rGroupName,
+ aNewFolderName,
+ aNewFolderURL,
+ aNewFolder )
+ && !CreateNewUniqueFolderWithPrefix( aUserPath,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserGroup" ) ),
+ aNewFolderName,
+ aNewFolderURL,
+ aNewFolder ) )
+ {
+ // we could not create the folder, so we delete the group in the
+ // hierarchy and return
+ removeContent( aNewGroup );
+ return sal_False;
+ }
+
+ if ( !UpdateUINamesForTemplateDir_Impl( aUserPath, rGroupName, aNewFolderName ) )
+ {
+ // we could not create the groupuinames for the folder, so we delete the group in the
+ // hierarchy, the folder and return
+ removeContent( aNewGroup );
+ removeContent( aNewFolder );
+ return sal_False;
+ }
+
+ // Now set the target url for this group and we are done
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) );
+ Any aValue = makeAny( aNewFolderURL );
+
+ if ( ! setProperty( aNewGroup, aPropName, aValue ) )
+ {
+ removeContent( aNewGroup );
+ removeContent( aNewFolder );
+ return sal_False;
+ }
+
+ return sal_True;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::removeGroup( const OUString& rGroupName )
+{
+ // remove all the elements that have the prefix aTargetURL
+ // if the group does not have other elements remove it
+
+ ::osl::MutexGuard aGuard( maMutex );
+
+ sal_Bool bResult = sal_False;
+
+ // create the group url
+ INetURLObject aGroupObj( maRootURL );
+ aGroupObj.insertName( rGroupName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+
+ // Get the target url
+ Content aGroup;
+ OUString aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( Content::create( aGroupURL, maCmdEnv, aGroup ) )
+ {
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) );
+ Any aValue;
+
+ OUString aGroupTargetURL;
+ if ( getProperty( aGroup, aPropName, aValue ) )
+ aValue >>= aGroupTargetURL;
+
+ if ( !aGroupTargetURL.getLength() )
+ return sal_False; // nothing is allowed to be removed
+
+ if ( !maTemplateDirs.getLength() )
+ return sal_False;
+ ::rtl::OUString aGeneralTempPath = maTemplateDirs[ maTemplateDirs.getLength() - 1 ];
+
+ // check that the fs location is in writeble folder and this is not a "My templates" folder
+ INetURLObject aGroupParentFolder( aGroupTargetURL );
+ if ( !aGroupParentFolder.removeSegment()
+ || !::utl::UCBContentHelper::IsSubPath( aGeneralTempPath,
+ aGroupParentFolder.GetMainURL( INetURLObject::NO_DECODE ) ) )
+ return sal_False;
+
+ // now get the content of the Group
+ uno::Reference< XResultSet > xResultSet;
+ Sequence< OUString > aProps( 1 );
+
+ aProps[0] = OUString::createFromAscii( TARGET_URL );
+
+ try
+ {
+ sal_Bool bHasNonRemovable = sal_False;
+ sal_Bool bHasShared = sal_False;
+
+ ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
+ xResultSet = aGroup.createCursor( aProps, eInclude );
+
+ if ( xResultSet.is() )
+ {
+ uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
+ uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
+
+ while ( xResultSet->next() )
+ {
+ OUString aTemplTargetURL( xRow->getString( 1 ) );
+ OUString aHierURL = xContentAccess->queryContentIdentifierString();
+
+ if ( ::utl::UCBContentHelper::IsSubPath( aGroupTargetURL, aTemplTargetURL ) )
+ {
+ // this is a user template, and it can be removed
+ if ( removeContent( aTemplTargetURL ) )
+ removeContent( aHierURL );
+ else
+ bHasNonRemovable = sal_True;
+ }
+ else
+ bHasShared = sal_True;
+ }
+
+ if ( !bHasNonRemovable && !bHasShared )
+ {
+ if ( removeContent( aGroupTargetURL )
+ || !::utl::UCBContentHelper::Exists( aGroupTargetURL ) )
+ {
+ removeContent( aGroupURL );
+ RemoveUINamesForTemplateDir_Impl( aGeneralTempPath, rGroupName );
+ bResult = sal_True; // the operation is successful only if the whole group is removed
+ }
+ }
+ else if ( !bHasNonRemovable )
+ {
+ if ( removeContent( aGroupTargetURL )
+ || !::utl::UCBContentHelper::Exists( aGroupTargetURL ) )
+ {
+ RemoveUINamesForTemplateDir_Impl( aGeneralTempPath, rGroupName );
+ setProperty( aGroup, aPropName, uno::makeAny( ::rtl::OUString() ) );
+ }
+ }
+ }
+ }
+ catch ( Exception& ) {}
+ }
+
+ return bResult;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::renameGroup( const OUString& rOldName,
+ const OUString& rNewName )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // create the group url
+ Content aGroup;
+ INetURLObject aGroupObj( maRootURL );
+ aGroupObj.insertName( rNewName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ OUString aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ // Check, if there is a group with the new name, return false
+ // if there is one.
+ if ( Content::create( aGroupURL, maCmdEnv, aGroup ) )
+ return sal_False;
+
+ aGroupObj.removeSegment();
+ aGroupObj.insertName( rOldName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ // When there is no group with the old name, we can't rename it
+ if ( ! Content::create( aGroupURL, maCmdEnv, aGroup ) )
+ return sal_False;
+
+ OUString aGroupTargetURL;
+ // there is no need to check whether target dir url is in target path, since if the target path is changed
+ // the target dir url should be already generated new
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) );
+ Any aValue;
+ if ( getProperty( aGroup, aPropName, aValue ) )
+ aValue >>= aGroupTargetURL;
+
+ if ( !aGroupTargetURL.getLength() )
+ return sal_False;
+
+ if ( !maTemplateDirs.getLength() )
+ return sal_False;
+ ::rtl::OUString aGeneralTempPath = maTemplateDirs[ maTemplateDirs.getLength() - 1 ];
+
+ // check that the fs location is in writeble folder and this is not a "My templates" folder
+ INetURLObject aGroupParentFolder( aGroupTargetURL );
+ if ( !aGroupParentFolder.removeSegment()
+ || !::utl::UCBContentHelper::IsSubPath( aGeneralTempPath,
+ aGroupParentFolder.GetMainURL( INetURLObject::NO_DECODE ) ) )
+ return sal_False;
+
+ // check that the group can be renamed ( all the contents must be in target location )
+ sal_Bool bCanBeRenamed = sal_False;
+ try
+ {
+ uno::Reference< XResultSet > xResultSet;
+ Sequence< OUString > aProps( 1 );
+
+ aProps[0] = OUString::createFromAscii( TARGET_URL );
+ ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
+ xResultSet = aGroup.createCursor( aProps, eInclude );
+
+ if ( xResultSet.is() )
+ {
+ uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
+ uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
+
+ while ( xResultSet->next() )
+ {
+ OUString aTemplTargetURL( xRow->getString( 1 ) );
+
+ if ( !::utl::UCBContentHelper::IsSubPath( aGroupTargetURL, aTemplTargetURL ) )
+ throw uno::Exception();
+ }
+
+ bCanBeRenamed = sal_True;
+ }
+ }
+ catch ( Exception& ) {}
+
+ if ( bCanBeRenamed )
+ {
+ INetURLObject aGroupTargetObj( aGroupTargetURL );
+ ::rtl::OUString aFsysName = aGroupTargetObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+
+ if ( aGroupTargetObj.removeSegment()
+ && ReplaceUINamesForTemplateDir_Impl( aGroupTargetObj.GetMainURL( INetURLObject::NO_DECODE ),
+ aFsysName,
+ rOldName,
+ rNewName ) )
+ {
+ // rename the group in the hierarchy
+ OUString aTitleProp( RTL_CONSTASCII_USTRINGPARAM( TITLE ) );
+ Any aTitleValue;
+ aTitleValue <<= rNewName;
+
+ return setProperty( aGroup, aTitleProp, aTitleValue );
+ }
+ }
+
+ return sal_False;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::storeTemplate( const OUString& rGroupName,
+ const OUString& rTemplateName,
+ const uno::Reference< XSTORABLE >& rStorable )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // Check, wether or not there is a group with this name
+ // Return false, if there is no group with the given name
+ Content aGroup, aTemplate, aTargetGroup, aTemplateToRemove;
+ OUString aGroupURL, aTemplateURL, aTemplateToRemoveTargetURL;
+ INetURLObject aGroupObj( maRootURL );
+ sal_Bool bRemoveOldTemplateContent = sal_False;
+ ::rtl::OUString sDocServiceName;
+
+ aGroupObj.insertName( rGroupName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( ! Content::create( aGroupURL, maCmdEnv, aGroup ) )
+ return sal_False;
+
+ ::rtl::OUString aGroupTargetURL;
+ ::rtl::OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) );
+ Any aValue;
+ if ( getProperty( aGroup, aPropName, aValue ) )
+ aValue >>= aGroupTargetURL;
+
+
+ // Check, if there's a template with the given name in this group
+ // the target template should be overwritten if it is imported by user
+ // in case the template is installed by office installation of by an add-in
+ // it can not be replaced
+ aGroupObj.insertName( rTemplateName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( Content::create( aTemplateURL, maCmdEnv, aTemplateToRemove ) )
+ {
+ OUString aTargetTemplPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
+
+ bRemoveOldTemplateContent = sal_True;
+ if ( getProperty( aTemplateToRemove, aTargetTemplPropName, aValue ) )
+ aValue >>= aTemplateToRemoveTargetURL;
+
+ if ( !aGroupTargetURL.getLength() || !maTemplateDirs.getLength()
+ || (aTemplateToRemoveTargetURL.getLength() && !::utl::UCBContentHelper::IsSubPath( maTemplateDirs[ maTemplateDirs.getLength() - 1 ], aTemplateToRemoveTargetURL )) )
+ return sal_False; // it is not allowed to remove the template
+ }
+
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
+ if ( !xFactory.is() )
+ throw uno::RuntimeException();
+
+ // get document service name
+ uno::Reference< frame::XModuleManager > xModuleManager(
+ xFactory->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.frame.ModuleManager" ) ),
+ uno::UNO_QUERY_THROW );
+ sDocServiceName = xModuleManager->identify( uno::Reference< uno::XInterface >( rStorable, uno::UNO_QUERY ) );
+ if ( !sDocServiceName.getLength() )
+ throw uno::RuntimeException();
+
+ // get the actual filter name
+ ::rtl::OUString aFilterName;
+
+ uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
+ xFactory->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" ) ),
+ uno::UNO_QUERY_THROW );
+
+ uno::Sequence< uno::Any > aArgs( 1 );
+ beans::PropertyValue aPathProp;
+ aPathProp.Name = ::rtl::OUString::createFromAscii( "nodepath" );
+ aPathProp.Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Setup/Office/Factories/" ) );
+ aArgs[0] <<= aPathProp;
+
+ uno::Reference< container::XNameAccess > xSOFConfig(
+ xConfigProvider->createInstanceWithArguments(
+ ::rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" ),
+ aArgs ),
+ uno::UNO_QUERY_THROW );
+
+ uno::Reference< container::XNameAccess > xApplConfig;
+ xSOFConfig->getByName( sDocServiceName ) >>= xApplConfig;
+ if ( !xApplConfig.is() )
+ throw uno::RuntimeException();
+
+ xApplConfig->getByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooSetupFactoryActualTemplateFilter" ) ) ) >>= aFilterName;
+ if ( !aFilterName.getLength() )
+ throw uno::RuntimeException();
+
+ // find the related type name
+ ::rtl::OUString aTypeName;
+ uno::Reference< container::XNameAccess > xFilterFactory(
+ xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ),
+ uno::UNO_QUERY_THROW );
+
+ uno::Sequence< beans::PropertyValue > aFilterData;
+ xFilterFactory->getByName( aFilterName ) >>= aFilterData;
+ for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
+ if ( aFilterData[nInd].Name.equalsAscii( "Type" ) )
+ aFilterData[nInd].Value >>= aTypeName;
+
+ if ( !aTypeName.getLength() )
+ throw uno::RuntimeException();
+
+ // find the mediatype and extension
+ uno::Reference< container::XNameAccess > xTypeDetection =
+ mxType.is() ?
+ uno::Reference< container::XNameAccess >( mxType, uno::UNO_QUERY_THROW ) :
+ uno::Reference< container::XNameAccess >(
+ xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.TypeDetection" ) ),
+ uno::UNO_QUERY_THROW );
+
+ SequenceAsHashMap aTypeProps( xTypeDetection->getByName( aTypeName ) );
+ uno::Sequence< ::rtl::OUString > aAllExt =
+ aTypeProps.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Extensions" ), Sequence< ::rtl::OUString >() );
+ if ( !aAllExt.getLength() )
+ throw uno::RuntimeException();
+
+ ::rtl::OUString aMediaType = aTypeProps.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "MediaType" ), ::rtl::OUString() );
+ ::rtl::OUString aExt = aAllExt[0];
+
+ if ( !aMediaType.getLength() || !aExt.getLength() )
+ throw uno::RuntimeException();
+
+ // construct destination url
+ if ( !aGroupTargetURL.getLength() )
+ {
+ aGroupTargetURL = CreateNewGroupFsys( rGroupName, aGroup );
+
+ if ( !aGroupTargetURL.getLength() )
+ throw uno::RuntimeException();
+ }
+
+ ::rtl::OUString aNewTemplateTargetURL = CreateNewUniqueFileWithPrefix( aGroupTargetURL, rTemplateName, aExt );
+ if ( !aNewTemplateTargetURL.getLength() )
+ {
+ aNewTemplateTargetURL = CreateNewUniqueFileWithPrefix( aGroupTargetURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserTemplate" ) ), aExt );
+
+ if ( !aNewTemplateTargetURL.getLength() )
+ throw uno::RuntimeException();
+ }
+
+ // store template
+ uno::Sequence< PropertyValue > aStoreArgs( 2 );
+ aStoreArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" );
+ aStoreArgs[0].Value <<= aFilterName;
+ aStoreArgs[1].Name = ::rtl::OUString::createFromAscii( "DocumentTitle" );
+ aStoreArgs[1].Value <<= rTemplateName;
+
+ ::rtl::OUString aCurrentDocumentURL = rStorable->getLocation();
+ if( !::utl::UCBContentHelper::EqualURLs( aNewTemplateTargetURL, rStorable->getLocation() ))
+ rStorable->storeToURL( aNewTemplateTargetURL, aStoreArgs );
+ else
+ rStorable->store();
+
+ // the storing was successful, now the old template with the same name can be removed if it existed
+ if ( aTemplateToRemoveTargetURL.getLength() )
+ {
+ removeContent( aTemplateToRemoveTargetURL );
+
+ /*
+ * pb: #i79496#
+ * if the old template was the standard template
+ * it is necessary to change the standard template with the new file name
+ */
+ String sStdTmplFile = SfxObjectFactory::GetStandardTemplate( sDocServiceName );
+ if ( INetURLObject( sStdTmplFile ) == INetURLObject( aTemplateToRemoveTargetURL ) )
+ {
+ SfxObjectFactory::SetStandardTemplate( sDocServiceName, aNewTemplateTargetURL );
+ }
+ }
+
+ if ( bRemoveOldTemplateContent )
+ removeContent( aTemplateToRemove );
+
+ // add the template to hierarchy
+ return addEntry( aGroup, rTemplateName, aNewTemplateTargetURL, aMediaType );
+ }
+ catch( Exception& )
+ {
+ // the template was not stored
+ return sal_False;
+ }
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::addTemplate( const OUString& rGroupName,
+ const OUString& rTemplateName,
+ const OUString& rSourceURL )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // Check, wether or not there is a group with this name
+ // Return false, if there is no group with the given name
+ Content aGroup, aTemplate, aTargetGroup;
+ OUString aGroupURL, aTemplateURL;
+ INetURLObject aGroupObj( maRootURL );
+
+ aGroupObj.insertName( rGroupName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( ! Content::create( aGroupURL, maCmdEnv, aGroup ) )
+ return sal_False;
+
+ // Check, if there's a template with the given name in this group
+ // Return false, if there already is a template
+ aGroupObj.insertName( rTemplateName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( Content::create( aTemplateURL, maCmdEnv, aTemplate ) )
+ return sal_False;
+
+ // get the target url of the group
+ OUString aTargetURL;
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) );
+ Any aValue;
+
+ if ( getProperty( aGroup, aPropName, aValue ) )
+ aValue >>= aTargetURL;
+
+ if ( !aTargetURL.getLength() )
+ {
+ aTargetURL = CreateNewGroupFsys( rGroupName, aGroup );
+
+ if ( !aTargetURL.getLength() )
+ return sal_False;
+ }
+
+ // Get the content type
+ OUString aTitle, aType, aTargetURL2, aFullName;
+
+ // only StarOffice documents are acceptable
+ sal_Bool bDocHasTitle = sal_False;
+ if( !getTitleFromURL( rSourceURL, aTitle, aType, bDocHasTitle ) )
+ return sal_False;
+
+ INetURLObject aSourceObj( rSourceURL );
+ if ( rTemplateName.equals( aTitle ) )
+ {
+ /////////////////////////////////////////////////////
+ // addTemplate will sometimes be called just to add an entry in the
+ // hierarchy; the target URL and the source URL will be the same in
+ // this scenario
+ // TODO/LATER: get rid of this old hack
+
+ INetURLObject aTargetObj( aTargetURL );
+
+ aTargetObj.insertName( rTemplateName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aTargetObj.setExtension( aSourceObj.getExtension() );
+
+ aTargetURL2 = aTargetObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( aTargetURL2 == rSourceURL )
+ return addEntry( aGroup, rTemplateName, aTargetURL2, aType );
+ }
+
+ /////////////////////////////////////////////////////
+ // copy the template into the new group (targeturl)
+
+ INetURLObject aTmpURL( aSourceObj );
+ aTmpURL.CutExtension();
+ ::rtl::OUString aPattern = aTmpURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+
+ ::rtl::OUString aNewTemplateTargetURL = CreateNewUniqueFileWithPrefix( aTargetURL, aPattern, aSourceObj.getExtension() );
+ INetURLObject aNewTemplateTargetObj( aNewTemplateTargetURL );
+ ::rtl::OUString aNewTemplateTargetName = aNewTemplateTargetObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+ if ( !aNewTemplateTargetURL.getLength() || !aNewTemplateTargetName.getLength() )
+ return sal_False;
+
+ // get access to source file
+ Content aSourceContent;
+ uno::Reference < ucb::XCommandEnvironment > xEnv;
+ INetURLObject aSourceURL( rSourceURL );
+ if( ! Content::create( aSourceURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aSourceContent ) )
+ return sal_False;
+
+ if( ! Content::create( aTargetURL, xEnv, aTargetGroup ) )
+ return sal_False;
+
+ // transfer source file
+ try
+ {
+ if( ! aTargetGroup.transferContent( aSourceContent,
+ InsertOperation_COPY,
+ aNewTemplateTargetName,
+ NameClash::OVERWRITE ) )
+ return sal_False;
+
+ // allow to edit the added template
+ Content aResultContent;
+ if ( Content::create( aNewTemplateTargetURL, xEnv, aResultContent ) )
+ {
+ ::rtl::OUString aPropertyName( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) );
+ uno::Any aProperty;
+ sal_Bool bReadOnly = sal_False;
+ if ( getProperty( aResultContent, aPropertyName, aProperty ) && ( aProperty >>= bReadOnly ) && bReadOnly )
+ setProperty( aResultContent, aPropertyName, uno::makeAny( (sal_Bool)sal_False ) );
+ }
+ }
+ catch ( ContentCreationException& )
+ { return sal_False; }
+ catch ( Exception& )
+ { return sal_False; }
+
+
+ // either the document has title and it is the same as requested, or we have to set it
+ sal_Bool bCorrectTitle = ( bDocHasTitle && aTitle.equals( rTemplateName ) );
+ if ( !bCorrectTitle )
+ {
+ if ( !bDocHasTitle )
+ {
+ INetURLObject aNewTmpObj( aNewTemplateTargetObj );
+ aNewTmpObj.CutExtension();
+ bCorrectTitle = ( aNewTmpObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ).equals( rTemplateName ) );
+ }
+
+ if ( !bCorrectTitle )
+ bCorrectTitle = setTitleForURL( aNewTemplateTargetURL, rTemplateName );
+ }
+
+ if ( bCorrectTitle )
+ {
+ // create a new entry in the hierarchy
+ return addEntry( aGroup, rTemplateName, aNewTemplateTargetURL, aType );
+ }
+
+ // TODO/LATER: The user could be notified here that the renaming has failed
+ // create a new entry in the hierarchy
+ addEntry( aGroup, aTitle, aNewTemplateTargetURL, aType );
+ return sal_False;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::removeTemplate( const OUString& rGroupName,
+ const OUString& rTemplateName )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // Check, wether or not there is a group with this name
+ // Return false, if there is no group with the given name
+ Content aGroup, aTemplate;
+ OUString aGroupURL, aTemplateURL;
+ INetURLObject aGroupObj( maRootURL );
+
+ aGroupObj.insertName( rGroupName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( ! Content::create( aGroupURL, maCmdEnv, aGroup ) )
+ return sal_False;
+
+ // Check, if there's a template with the given name in this group
+ // Return false, if there is no template
+ aGroupObj.insertName( rTemplateName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( !Content::create( aTemplateURL, maCmdEnv, aTemplate ) )
+ return sal_False;
+
+ // get the target URL from the template
+ OUString aTargetURL;
+ OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
+ Any aValue;
+
+ if ( getProperty( aTemplate, aPropName, aValue ) )
+ aValue >>= aTargetURL;
+
+ // delete the target template
+ if ( aTargetURL.getLength() )
+ {
+ if ( !maTemplateDirs.getLength()
+ || !::utl::UCBContentHelper::IsSubPath( maTemplateDirs[ maTemplateDirs.getLength() - 1 ], aTargetURL ) )
+ return sal_False;
+
+ removeContent( aTargetURL );
+ }
+
+ // delete the template entry
+ return removeContent( aTemplate );
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SfxDocTplService_Impl::renameTemplate( const OUString& rGroupName,
+ const OUString& rOldName,
+ const OUString& rNewName )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // Check, wether or not there is a group with this name
+ // Return false, if there is no group with the given name
+ Content aGroup, aTemplate;
+ OUString aGroupURL, aTemplateURL;
+ INetURLObject aGroupObj( maRootURL );
+
+ aGroupObj.insertName( rGroupName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( ! Content::create( aGroupURL, maCmdEnv, aGroup ) )
+ return sal_False;
+
+ // Check, if there's a template with the new name in this group
+ // Return false, if there is one
+ aGroupObj.insertName( rNewName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( Content::create( aTemplateURL, maCmdEnv, aTemplate ) )
+ return sal_False;
+
+ // Check, if there's a template with the old name in this group
+ // Return false, if there is no template
+ aGroupObj.removeSegment();
+ aGroupObj.insertName( rOldName, false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+ aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( !Content::create( aTemplateURL, maCmdEnv, aTemplate ) )
+ return sal_False;
+
+ OUString aTemplateTargetURL;
+ OUString aTargetProp( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
+ Any aTargetValue;
+
+ if ( getProperty( aTemplate, aTargetProp, aTargetValue ) )
+ aTargetValue >>= aTemplateTargetURL;
+
+ if ( !setTitleForURL( aTemplateTargetURL, rNewName ) )
+ return sal_False;
+
+ // rename the template entry in the cache
+ OUString aTitleProp( RTL_CONSTASCII_USTRINGPARAM( TITLE ) );
+ Any aTitleValue;
+ aTitleValue <<= rNewName;
+
+ return setProperty( aTemplate, aTitleProp, aTitleValue );
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+SFX_IMPL_XSERVICEINFO( SfxDocTplService, TEMPLATE_SERVICE_NAME, TEMPLATE_IMPLEMENTATION_NAME )
+SFX_IMPL_SINGLEFACTORY( SfxDocTplService )
+
+//-----------------------------------------------------------------------------
+SfxDocTplService::SfxDocTplService( const uno::Reference< XMultiServiceFactory >& xFactory )
+{
+ pImp = new SfxDocTplService_Impl( xFactory );
+}
+
+//-----------------------------------------------------------------------------
+
+SfxDocTplService::~SfxDocTplService()
+{
+ delete pImp;
+}
+
+//-----------------------------------------------------------------------------
+//--- XLocalizable ---
+//-----------------------------------------------------------------------------
+
+Locale SAL_CALL SfxDocTplService::getLocale()
+ throw( RUNTIMEEXCEPTION )
+{
+ return pImp->getLocale();
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocTplService::setLocale( const Locale & rLocale )
+ throw( RUNTIMEEXCEPTION )
+{
+ pImp->setLocale( rLocale );
+}
+
+//-----------------------------------------------------------------------------
+//--- XDocumentTemplates ---
+//-----------------------------------------------------------------------------
+uno::Reference< XCONTENT > SAL_CALL SfxDocTplService::getContent()
+ throw( RUNTIMEEXCEPTION )
+{
+ if ( pImp->init() )
+ return pImp->getContent().get();
+ else
+ return NULL;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxDocTplService::storeTemplate( const OUString& GroupName,
+ const OUString& TemplateName,
+ const uno::Reference< XSTORABLE >& Storable )
+ throw( RUNTIMEEXCEPTION )
+{
+ if ( pImp->init() )
+ return pImp->storeTemplate( GroupName, TemplateName, Storable );
+ else
+ return sal_False;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxDocTplService::addTemplate( const OUString& rGroupName,
+ const OUString& rTemplateName,
+ const OUString& rSourceURL )
+ throw( RUNTIMEEXCEPTION )
+{
+ if ( pImp->init() )
+ return pImp->addTemplate( rGroupName, rTemplateName, rSourceURL );
+ else
+ return sal_False;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxDocTplService::removeTemplate( const OUString& rGroupName,
+ const OUString& rTemplateName )
+ throw( RUNTIMEEXCEPTION )
+{
+ if ( pImp->init() )
+ return pImp->removeTemplate( rGroupName, rTemplateName );
+ else
+ return sal_False;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxDocTplService::renameTemplate( const OUString& rGroupName,
+ const OUString& rOldName,
+ const OUString& rNewName )
+ throw( RUNTIMEEXCEPTION )
+{
+ if ( rOldName == rNewName )
+ return sal_True;
+
+ if ( pImp->init() )
+ return pImp->renameTemplate( rGroupName, rOldName, rNewName );
+ else
+ return sal_False;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxDocTplService::addGroup( const OUString& rGroupName )
+ throw( RUNTIMEEXCEPTION )
+{
+ if ( pImp->init() )
+ return pImp->addGroup( rGroupName );
+ else
+ return sal_False;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxDocTplService::removeGroup( const OUString& rGroupName )
+ throw( RUNTIMEEXCEPTION )
+{
+ if ( pImp->init() )
+ return pImp->removeGroup( rGroupName );
+ else
+ return sal_False;
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxDocTplService::renameGroup( const OUString& rOldName,
+ const OUString& rNewName )
+ throw( RUNTIMEEXCEPTION )
+{
+ if ( rOldName == rNewName )
+ return sal_True;
+
+ if ( pImp->init() )
+ return pImp->renameGroup( rOldName, rNewName );
+ else
+ return sal_False;
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxDocTplService::update()
+ throw( RUNTIMEEXCEPTION )
+{
+ if ( pImp->init() )
+ pImp->update( sal_True );
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//------------------------------------------------------------------------
+
+Updater_Impl::Updater_Impl( SfxDocTplService_Impl* pTemplates )
+{
+ mpDocTemplates = pTemplates;
+}
+
+//------------------------------------------------------------------------
+Updater_Impl::~Updater_Impl()
+{
+}
+
+//------------------------------------------------------------------------
+void SAL_CALL Updater_Impl::run()
+{
+ mpDocTemplates->doUpdate();
+}
+
+//------------------------------------------------------------------------
+void SAL_CALL Updater_Impl::onTerminated()
+{
+ mpDocTemplates->finished();
+ delete this;
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+WaitWindow_Impl::WaitWindow_Impl()
+ : WorkWindow( NULL, WB_BORDER | WB_3DLOOK )
+{
+ Rectangle aRect = Rectangle( 0, 0, 300, 30000 );
+ _nTextStyle = TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER | TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE;
+ _aText = String( SfxResId( RID_CNT_STR_WAITING ) );
+ _aRect = GetTextRect( aRect, _aText, _nTextStyle );
+ aRect = _aRect;
+ aRect.Right() += 2*X_OFFSET;
+ aRect.Bottom() += 2*Y_OFFSET;
+ _aRect.SetPos( Point( X_OFFSET, Y_OFFSET ) );
+ SetOutputSizePixel( aRect.GetSize() );
+ Show();
+ Update();
+ Flush();
+}
+
+//-----------------------------------------------------------------------------
+WaitWindow_Impl::~WaitWindow_Impl()
+{
+ Hide();
+}
+
+//-----------------------------------------------------------------------------
+void WaitWindow_Impl::Paint( const Rectangle& /*rRect*/ )
+{
+ DrawText( _aRect, _aText, _nTextStyle );
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::addHierGroup( GroupList_Impl& rList,
+ const OUString& rTitle,
+ const OUString& rOwnURL )
+{
+ // now get the content of the Group
+ Content aContent;
+ uno::Reference< XResultSet > xResultSet;
+ Sequence< OUString > aProps(3);
+
+ aProps[0] = OUString::createFromAscii( TITLE );
+ aProps[1] = OUString::createFromAscii( TARGET_URL );
+ aProps[2] = OUString::createFromAscii( PROPERTY_TYPE );
+
+ try
+ {
+ aContent = Content( rOwnURL, maCmdEnv );
+ ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
+ xResultSet = aContent.createCursor( aProps, eInclude );
+ }
+ catch ( ContentCreationException& )
+ {
+ DBG_ERRORFILE( "addHierGroup: ContentCreationException" );
+ }
+ catch ( Exception& ) {}
+
+ if ( xResultSet.is() )
+ {
+ GroupData_Impl *pGroup = new GroupData_Impl( rTitle );
+ pGroup->setHierarchy( sal_True );
+ pGroup->setHierarchyURL( rOwnURL );
+ rList.Insert( pGroup );
+
+ uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
+ uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
+
+ try
+ {
+ while ( xResultSet->next() )
+ {
+ BOOL bUpdateType = sal_False;
+ DocTemplates_EntryData_Impl *pData;
+
+ OUString aTitle( xRow->getString( 1 ) );
+ OUString aTargetDir( xRow->getString( 2 ) );
+ OUString aType( xRow->getString( 3 ) );
+ OUString aHierURL = xContentAccess->queryContentIdentifierString();
+
+ if ( !aType.getLength() )
+ {
+ OUString aTmpTitle;
+
+ sal_Bool bDocHasTitle = sal_False;
+ if( !getTitleFromURL( aTargetDir, aTmpTitle, aType, bDocHasTitle ) )
+ {
+ DBG_ERRORFILE( "addHierGroup(): template of alien format" );
+ continue;
+ }
+
+ if ( aType.getLength() )
+ bUpdateType = sal_True;
+ }
+
+ pData = pGroup->addEntry( aTitle, aTargetDir, aType, aHierURL );
+ pData->setUpdateType( bUpdateType );
+ }
+ }
+ catch ( Exception& ) {}
+ }
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::addFsysGroup( GroupList_Impl& rList,
+ const OUString& rTitle,
+ const OUString& rUITitle,
+ const OUString& rOwnURL,
+ sal_Bool bWriteableGroup )
+{
+ ::rtl::OUString aTitle;
+
+ if ( !rUITitle.getLength() )
+ {
+ // reserved FS names that should not be used
+ if ( rTitle.compareToAscii( "wizard" ) == 0 )
+ return;
+ else if ( rTitle.compareToAscii( "internal" ) == 0 )
+ return;
+
+ aTitle = getLongName( rTitle );
+ }
+ else
+ aTitle = rUITitle;
+
+ if ( !aTitle.getLength() )
+ return;
+
+ GroupData_Impl *pGroup = rList.First();
+
+ while ( pGroup && pGroup->getTitle() != aTitle )
+ pGroup = rList.Next();
+
+ if ( !pGroup )
+ {
+ pGroup = new GroupData_Impl( aTitle );
+ rList.Insert( pGroup );
+ }
+
+ if ( bWriteableGroup )
+ pGroup->setTargetURL( rOwnURL );
+
+ pGroup->setInUse();
+
+ // now get the content of the Group
+ Content aContent;
+ uno::Reference< XResultSet > xResultSet;
+ Sequence< OUString > aProps(1);
+ aProps[0] = OUString::createFromAscii( TITLE );
+
+ try
+ {
+ // this method is only used during checking of the available template-folders
+ // that should happen quietly
+ uno::Reference< XCommandEnvironment > aQuietEnv;
+ aContent = Content( rOwnURL, aQuietEnv );
+ ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
+ xResultSet = aContent.createCursor( aProps, eInclude );
+ }
+ catch ( Exception& ) {}
+
+ if ( xResultSet.is() )
+ {
+ uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
+ uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
+
+ try
+ {
+ while ( xResultSet->next() )
+ {
+ OUString aChildTitle( xRow->getString( 1 ) );
+ OUString aTargetURL = xContentAccess->queryContentIdentifierString();
+ OUString aType;
+ OUString aHierURL;
+
+ if ( aChildTitle.compareToAscii( "sfx.tlx" ) == 0
+ || aChildTitle.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "groupuinames.xml" ) ) )
+ continue;
+
+ // only StarOffice templates are accepted
+ sal_Bool bDocHasTitle = sal_False;
+ if( !getTitleFromURL( aTargetURL, aChildTitle, aType, bDocHasTitle ) )
+ continue;
+
+ pGroup->addEntry( aChildTitle, aTargetURL, aType, aHierURL );
+ }
+ }
+ catch ( Exception& ) {}
+ }
+}
+
+// -----------------------------------------------------------------------
+void SfxDocTplService_Impl::createFromContent( GroupList_Impl& rList,
+ Content &rContent,
+ sal_Bool bHierarchy,
+ sal_Bool bWriteableContent )
+{
+ OUString aTargetURL = rContent.get()->getIdentifier()->getContentIdentifier();
+
+ // when scanning the file system, we have to add the 'standard' group, too
+ if ( ! bHierarchy )
+ {
+ OUString aUIStdTitle = getLongName( OUString( RTL_CONSTASCII_USTRINGPARAM( STANDARD_FOLDER ) ) );
+ addFsysGroup( rList, ::rtl::OUString(), aUIStdTitle, aTargetURL, bWriteableContent );
+ }
+
+ // search for predefined UI names
+ INetURLObject aLayerObj( aTargetURL );
+
+ // TODO/LATER: Use hashmap in future
+ uno::Sequence< beans::StringPair > aUINames;
+ if ( !bHierarchy )
+ aUINames = ReadUINamesForTemplateDir_Impl( aLayerObj.GetMainURL( INetURLObject::NO_DECODE ) );
+
+ uno::Reference< XResultSet > xResultSet;
+ Sequence< OUString > aProps(1);
+ aProps[0] = OUString::createFromAscii( TITLE );
+
+ try
+ {
+ ResultSetInclude eInclude = INCLUDE_FOLDERS_ONLY;
+ xResultSet = rContent.createCursor( aProps, eInclude );
+ }
+ catch ( Exception& ) {}
+
+ if ( xResultSet.is() )
+ {
+ uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
+ uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
+
+ try
+ {
+ while ( xResultSet->next() )
+ {
+ // TODO/LATER: clarify the encoding of the Title
+ OUString aTitle( xRow->getString( 1 ) );
+ OUString aTargetSubfolderURL( xContentAccess->queryContentIdentifierString() );
+
+ if ( bHierarchy )
+ addHierGroup( rList, aTitle, aTargetSubfolderURL );
+ else
+ {
+ ::rtl::OUString aUITitle;
+ for ( sal_Int32 nInd = 0; nInd < aUINames.getLength(); nInd++ )
+ if ( aUINames[nInd].First.equals( aTitle ) )
+ {
+ aUITitle = aUINames[nInd].Second;
+ break;
+ }
+
+ addFsysGroup( rList, aTitle, aUITitle, aTargetSubfolderURL, bWriteableContent );
+ }
+ }
+ }
+ catch ( Exception& ) {}
+ }
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::removeFromHierarchy( DocTemplates_EntryData_Impl *pData )
+{
+ Content aTemplate;
+
+ if ( Content::create( pData->getHierarchyURL(), maCmdEnv, aTemplate ) )
+ {
+ removeContent( aTemplate );
+ }
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::addToHierarchy( GroupData_Impl *pGroup,
+ DocTemplates_EntryData_Impl *pData )
+{
+ Content aGroup, aTemplate;
+
+ if ( ! Content::create( pGroup->getHierarchyURL(), maCmdEnv, aGroup ) )
+ return;
+
+ // Check, if there's a template with the given name in this group
+ // Return if there is already a template
+ INetURLObject aGroupObj( pGroup->getHierarchyURL() );
+
+ aGroupObj.insertName( pData->getTitle(), false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+
+ OUString aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( Content::create( aTemplateURL, maCmdEnv, aTemplate ) )
+ return;
+
+ addEntry( aGroup, pData->getTitle(),
+ pData->getTargetURL(),
+ pData->getType() );
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::updateData( DocTemplates_EntryData_Impl *pData )
+{
+ Content aTemplate;
+
+ if ( ! Content::create( pData->getHierarchyURL(), maCmdEnv, aTemplate ) )
+ return;
+
+ OUString aPropName;
+
+ if ( pData->getUpdateType() )
+ {
+ aPropName = OUString( RTL_CONSTASCII_USTRINGPARAM( PROPERTY_TYPE ) );
+ setProperty( aTemplate, aPropName, makeAny( pData->getType() ) );
+ }
+
+ if ( pData->getUpdateLink() )
+ {
+ aPropName = OUString( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
+ setProperty( aTemplate, aPropName, makeAny( pData->getTargetURL() ) );
+ }
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::addGroupToHierarchy( GroupData_Impl *pGroup )
+{
+ OUString aAdditionalProp( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) );
+ Content aGroup;
+
+ INetURLObject aNewGroupObj( maRootURL );
+ aNewGroupObj.insertName( pGroup->getTitle(), false,
+ INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::ENCODE_ALL );
+
+ OUString aNewGroupURL = aNewGroupObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( createFolder( aNewGroupURL, sal_False, sal_False, aGroup ) )
+ {
+ setProperty( aGroup, aAdditionalProp, makeAny( pGroup->getTargetURL() ) );
+ pGroup->setHierarchyURL( aNewGroupURL );
+
+ ULONG nCount = pGroup->count();
+ for ( ULONG i=0; i<nCount; i++ )
+ {
+ DocTemplates_EntryData_Impl *pData = pGroup->getEntry( i );
+ addToHierarchy( pGroup, pData ); // add entry to hierarchy
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+void SfxDocTplService_Impl::removeFromHierarchy( GroupData_Impl *pGroup )
+{
+ Content aGroup;
+
+ if ( Content::create( pGroup->getHierarchyURL(), maCmdEnv, aGroup ) )
+ {
+ removeContent( aGroup );
+ }
+}
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+GroupData_Impl::GroupData_Impl( const OUString& rTitle )
+{
+ maTitle = rTitle;
+ mbInUse = sal_False;
+ mbInHierarchy = sal_False;
+}
+
+// -----------------------------------------------------------------------
+GroupData_Impl::~GroupData_Impl()
+{
+ DocTemplates_EntryData_Impl *pData = maEntries.First();
+ while ( pData )
+ {
+ delete pData;
+ pData = maEntries.Next();
+ }
+}
+
+// -----------------------------------------------------------------------
+DocTemplates_EntryData_Impl* GroupData_Impl::addEntry( const OUString& rTitle,
+ const OUString& rTargetURL,
+ const OUString& rType,
+ const OUString& rHierURL )
+{
+ DocTemplates_EntryData_Impl *pData = maEntries.First();
+
+ while ( pData && pData->getTitle() != rTitle )
+ pData = maEntries.Next();
+
+ if ( !pData )
+ {
+ pData = new DocTemplates_EntryData_Impl( rTitle );
+ pData->setTargetURL( rTargetURL );
+ pData->setType( rType );
+ if ( rHierURL.getLength() )
+ {
+ pData->setHierarchyURL( rHierURL );
+ pData->setHierarchy( sal_True );
+ }
+ maEntries.Insert( pData );
+ }
+ else
+ {
+ if ( rHierURL.getLength() )
+ {
+ pData->setHierarchyURL( rHierURL );
+ pData->setHierarchy( sal_True );
+ }
+
+ if ( pData->getInHierarchy() )
+ pData->setInUse();
+
+ if ( rTargetURL != pData->getTargetURL() )
+ {
+ pData->setTargetURL( rTargetURL );
+ pData->setUpdateLink( sal_True );
+ }
+ }
+
+ return pData;
+}
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+DocTemplates_EntryData_Impl::DocTemplates_EntryData_Impl( const OUString& rTitle )
+{
+ maTitle = rTitle;
+ mbInUse = sal_False;
+ mbInHierarchy = sal_False;
+ mbUpdateType = sal_False;
+ mbUpdateLink = sal_False;
+}
+
+// -----------------------------------------------------------------------
+SfxURLRelocator_Impl::SfxURLRelocator_Impl( uno::Reference< XMultiServiceFactory > xFactory )
+: mxFactory( xFactory )
+{
+}
+
+// -----------------------------------------------------------------------
+SfxURLRelocator_Impl::~SfxURLRelocator_Impl()
+{
+}
+
+// -----------------------------------------------------------------------
+void SfxURLRelocator_Impl::initOfficeInstDirs()
+{
+ if ( !mxOfficeInstDirs.is() )
+ {
+ osl::MutexGuard aGuard( maMutex );
+ if ( !mxOfficeInstDirs.is() )
+ {
+ OSL_ENSURE( mxFactory.is(), "No service manager!" );
+
+ uno::Reference< XComponentContext > xCtx;
+ uno::Reference< XPropertySet > xPropSet( mxFactory, UNO_QUERY );
+ if ( xPropSet.is() )
+ {
+ xPropSet->getPropertyValue(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) )
+ >>= xCtx;
+ }
+
+ OSL_ENSURE( xCtx.is(),
+ "Unable to obtain component context from "
+ "service manager!" );
+
+ if ( xCtx.is() )
+ {
+ xCtx->getValueByName(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "/singletons/"
+ "com.sun.star.util.theOfficeInstallationDirectories" ) ) )
+ >>= mxOfficeInstDirs;
+ }
+
+ OSL_ENSURE( mxOfficeInstDirs.is(),
+ "Unable to obtain office installation directory "
+ "singleton!" );
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+void SfxURLRelocator_Impl::makeRelocatableURL( rtl::OUString & rURL )
+{
+ if ( rURL.getLength() > 0 )
+ {
+ initOfficeInstDirs();
+ rURL = mxOfficeInstDirs->makeRelocatableURL( rURL );
+ }
+}
+
+// -----------------------------------------------------------------------
+void SfxURLRelocator_Impl::makeAbsoluteURL( rtl::OUString & rURL )
+{
+ if ( rURL.getLength() > 0 )
+ {
+ initOfficeInstDirs();
+ rURL = mxOfficeInstDirs->makeAbsoluteURL( rURL );
+ }
+}
+
+
diff --git a/sfx2/source/doc/doctemplateslocal.cxx b/sfx2/source/doc/doctemplateslocal.cxx
new file mode 100644
index 000000000000..277199d30051
--- /dev/null
+++ b/sfx2/source/doc/doctemplateslocal.cxx
@@ -0,0 +1,263 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
+#include <com/sun/star/beans/StringPair.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+#ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP
+#include <com/sun/star/xml/sax/XParser.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#endif
+
+#include <comphelper/attributelist.hxx>
+
+#include "doctemplateslocal.hxx"
+
+using namespace ::com::sun::star;
+
+// -----------------------------------
+uno::Sequence< beans::StringPair > DocTemplLocaleHelper::ReadGroupLocalizationSequence( const uno::Reference< io::XInputStream >& xInStream, const uno::Reference< lang::XMultiServiceFactory > xFactory )
+ throw( uno::Exception )
+{
+ ::rtl::OUString aStringID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "groupuinames.xml" ) );
+ return ReadLocalizationSequence_Impl( xInStream, aStringID, xFactory );
+}
+
+// -----------------------------------
+void SAL_CALL DocTemplLocaleHelper::WriteGroupLocalizationSequence( const uno::Reference< io::XOutputStream >& xOutStream, const uno::Sequence< beans::StringPair >& aSequence, const uno::Reference< lang::XMultiServiceFactory > xFactory )
+ throw( uno::Exception )
+{
+ if ( !xOutStream.is() )
+ throw uno::RuntimeException();
+
+ uno::Reference< io::XActiveDataSource > xWriterSource(
+ xFactory->createInstance(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ),
+ uno::UNO_QUERY_THROW );
+ uno::Reference< xml::sax::XDocumentHandler > xWriterHandler( xWriterSource, uno::UNO_QUERY_THROW );
+
+ xWriterSource->setOutputStream( xOutStream );
+
+ ::rtl::OUString aGroupListElement( RTL_CONSTASCII_USTRINGPARAM( "groupuinames:template-group-list" ) );
+ ::rtl::OUString aGroupElement( RTL_CONSTASCII_USTRINGPARAM( "groupuinames:template-group" ) );
+ ::rtl::OUString aNameAttr( RTL_CONSTASCII_USTRINGPARAM( "groupuinames:name" ) );
+ ::rtl::OUString aUINameAttr( RTL_CONSTASCII_USTRINGPARAM( "groupuinames:default-ui-name" ) );
+ ::rtl::OUString aCDATAString( RTL_CONSTASCII_USTRINGPARAM ( "CDATA" ) );
+ ::rtl::OUString aWhiteSpace( RTL_CONSTASCII_USTRINGPARAM ( " " ) );
+
+ // write the namespace
+ ::comphelper::AttributeList* pRootAttrList = new ::comphelper::AttributeList;
+ uno::Reference< xml::sax::XAttributeList > xRootAttrList( pRootAttrList );
+ pRootAttrList->AddAttribute(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "xmlns" ) ),
+ aCDATAString,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "http://openoffice.org/2006/groupuinames" ) ) );
+
+ xWriterHandler->startDocument();
+ xWriterHandler->startElement( aGroupListElement, xRootAttrList );
+
+ for ( sal_Int32 nInd = 0; nInd < aSequence.getLength(); nInd++ )
+ {
+ ::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList;
+ uno::Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
+ pAttrList->AddAttribute( aNameAttr, aCDATAString, aSequence[nInd].First );
+ pAttrList->AddAttribute( aUINameAttr, aCDATAString, aSequence[nInd].Second );
+
+ xWriterHandler->startElement( aGroupElement, xAttrList );
+ xWriterHandler->ignorableWhitespace( aWhiteSpace );
+ xWriterHandler->endElement( aGroupElement );
+ }
+
+ xWriterHandler->ignorableWhitespace( aWhiteSpace );
+ xWriterHandler->endElement( aGroupListElement );
+ xWriterHandler->endDocument();
+}
+
+// ==================================================================================
+
+// -----------------------------------
+uno::Sequence< beans::StringPair > SAL_CALL DocTemplLocaleHelper::ReadLocalizationSequence_Impl( const uno::Reference< io::XInputStream >& xInStream, const ::rtl::OUString& aStringID, const uno::Reference< lang::XMultiServiceFactory > xFactory )
+ throw( uno::Exception )
+{
+ if ( !xFactory.is() || !xInStream.is() )
+ throw uno::RuntimeException();
+
+ uno::Sequence< beans::StringPair > aResult;
+
+ uno::Reference< xml::sax::XParser > xParser( xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser" ) ) ), uno::UNO_QUERY_THROW );
+
+ DocTemplLocaleHelper* pHelper = new DocTemplLocaleHelper();
+ uno::Reference< xml::sax::XDocumentHandler > xHelper( static_cast< xml::sax::XDocumentHandler* >( pHelper ) );
+ xml::sax::InputSource aParserInput;
+ aParserInput.aInputStream = xInStream;
+ aParserInput.sSystemId = aStringID;
+ xParser->setDocumentHandler( xHelper );
+ xParser->parseStream( aParserInput );
+ xParser->setDocumentHandler( uno::Reference < xml::sax::XDocumentHandler > () );
+
+ return pHelper->GetParsingResult();
+}
+
+// -----------------------------------
+DocTemplLocaleHelper::DocTemplLocaleHelper()
+: m_aGroupListElement( RTL_CONSTASCII_USTRINGPARAM( "groupuinames:template-group-list" ) )
+, m_aGroupElement( RTL_CONSTASCII_USTRINGPARAM( "groupuinames:template-group" ) )
+, m_aNameAttr( RTL_CONSTASCII_USTRINGPARAM( "groupuinames:name" ) )
+, m_aUINameAttr( RTL_CONSTASCII_USTRINGPARAM( "groupuinames:default-ui-name" ) )
+{
+}
+
+// -----------------------------------
+DocTemplLocaleHelper::~DocTemplLocaleHelper()
+{
+}
+
+// -----------------------------------
+uno::Sequence< beans::StringPair > DocTemplLocaleHelper::GetParsingResult()
+{
+ if ( m_aElementsSeq.getLength() )
+ throw uno::RuntimeException(); // the parsing has still not finished!
+
+ return m_aResultSeq;
+}
+
+// -----------------------------------
+void SAL_CALL DocTemplLocaleHelper::startDocument()
+ throw(xml::sax::SAXException, uno::RuntimeException)
+{
+}
+
+// -----------------------------------
+void SAL_CALL DocTemplLocaleHelper::endDocument()
+ throw(xml::sax::SAXException, uno::RuntimeException)
+{
+}
+
+// -----------------------------------
+void SAL_CALL DocTemplLocaleHelper::startElement( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs )
+ throw( xml::sax::SAXException, uno::RuntimeException )
+{
+ if ( aName == m_aGroupListElement )
+ {
+ sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1;
+
+ if ( nNewLength != 1 )
+ throw xml::sax::SAXException(); // TODO: this element must be the first level element
+
+ m_aElementsSeq.realloc( nNewLength );
+ m_aElementsSeq[nNewLength-1] = aName;
+
+ return; // nothing to do
+ }
+ else if ( aName == m_aGroupElement )
+ {
+ sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1;
+ if ( nNewLength != 2 )
+ throw xml::sax::SAXException(); // TODO: this element must be the second level element
+
+ m_aElementsSeq.realloc( nNewLength );
+ m_aElementsSeq[nNewLength-1] = aName;
+
+ sal_Int32 nNewEntryNum = m_aResultSeq.getLength() + 1;
+ m_aResultSeq.realloc( nNewEntryNum );
+
+ ::rtl::OUString aNameValue = xAttribs->getValueByName( m_aNameAttr );
+ if ( !aNameValue.getLength() )
+ throw xml::sax::SAXException(); // TODO: the ID value must present
+
+ ::rtl::OUString aUINameValue = xAttribs->getValueByName( m_aUINameAttr );
+ if ( !aUINameValue.getLength() )
+ throw xml::sax::SAXException(); // TODO: the ID value must present
+
+ m_aResultSeq[nNewEntryNum-1].First = aNameValue;
+ m_aResultSeq[nNewEntryNum-1].Second = aUINameValue;
+ }
+ else
+ {
+ // accept future extensions
+ sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1;
+
+ if ( !nNewLength )
+ throw xml::sax::SAXException(); // TODO: the extension element must not be the first level element
+
+ m_aElementsSeq.realloc( nNewLength );
+ m_aElementsSeq[nNewLength-1] = aName;
+ }
+}
+
+// -----------------------------------
+void SAL_CALL DocTemplLocaleHelper::endElement( const ::rtl::OUString& aName )
+ throw( xml::sax::SAXException, uno::RuntimeException )
+{
+ sal_Int32 nLength = m_aElementsSeq.getLength();
+ if ( nLength <= 0 )
+ throw xml::sax::SAXException(); // TODO: no other end elements expected!
+
+ if ( !m_aElementsSeq[nLength-1].equals( aName ) )
+ throw xml::sax::SAXException(); // TODO: unexpected element ended
+
+ m_aElementsSeq.realloc( nLength - 1 );
+}
+
+// -----------------------------------
+void SAL_CALL DocTemplLocaleHelper::characters( const ::rtl::OUString& /*aChars*/ )
+ throw(xml::sax::SAXException, uno::RuntimeException)
+{
+}
+
+// -----------------------------------
+void SAL_CALL DocTemplLocaleHelper::ignorableWhitespace( const ::rtl::OUString& /*aWhitespaces*/ )
+ throw(xml::sax::SAXException, uno::RuntimeException)
+{
+}
+
+// -----------------------------------
+void SAL_CALL DocTemplLocaleHelper::processingInstruction( const ::rtl::OUString& /*aTarget*/, const ::rtl::OUString& /*aData*/ )
+ throw(xml::sax::SAXException, uno::RuntimeException)
+{
+}
+
+// -----------------------------------
+void SAL_CALL DocTemplLocaleHelper::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ )
+ throw(xml::sax::SAXException, uno::RuntimeException)
+{
+}
+
diff --git a/sfx2/source/doc/doctemplateslocal.hxx b/sfx2/source/doc/doctemplateslocal.hxx
new file mode 100644
index 000000000000..84b1a9cc9611
--- /dev/null
+++ b/sfx2/source/doc/doctemplateslocal.hxx
@@ -0,0 +1,88 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_DOCTEMPLATESLOCAL_HXX
+#define _SFX_DOCTEMPLATESLOCAL_HXX
+
+#ifndef _COM_SUN_STAR_XML_SAX_XDUCUMENTHANDLER_HPP_
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#endif
+#include <com/sun/star/beans/StringPair.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <cppuhelper/implbase1.hxx>
+
+
+class DocTemplLocaleHelper : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler >
+{
+ // Relations info related strings
+ ::rtl::OUString m_aGroupListElement;
+ ::rtl::OUString m_aGroupElement;
+ ::rtl::OUString m_aNameAttr;
+ ::rtl::OUString m_aUINameAttr;
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > m_aResultSeq;
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aElementsSeq; // stack of elements being parsed
+
+ DocTemplLocaleHelper(); // must not be created directly
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > GetParsingResult();
+
+ static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > SAL_CALL ReadLocalizationSequence_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, const ::rtl::OUString& aStringID, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
+ throw( ::com::sun::star::uno::Exception );
+
+public:
+ ~DocTemplLocaleHelper();
+
+ // returns sequence of pairs ( GroupName, GroupUIName )
+ static
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >
+ ReadGroupLocalizationSequence(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
+ throw( ::com::sun::star::uno::Exception );
+
+ // writes sequence of elements ( GroupName, GroupUIName )
+ static
+ void SAL_CALL WriteGroupLocalizationSequence(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aSequence,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
+ throw( ::com::sun::star::uno::Exception );
+
+ // XDocumentHandler
+ virtual void SAL_CALL startDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL endDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
+};
+
+#endif
+
diff --git a/sfx2/source/doc/docvor.cxx b/sfx2/source/doc/docvor.cxx
new file mode 100644
index 000000000000..6367f2a65d76
--- /dev/null
+++ b/sfx2/source/doc/docvor.cxx
@@ -0,0 +1,2466 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
+
+#include <stdio.h>
+
+#ifndef _SV_PRNSETUP_HXX //autogen
+#include <svtools/prnsetup.hxx>
+#endif
+#include <vcl/cmdevt.hxx>
+#include <vcl/menubtn.hxx>
+#include <vcl/msgbox.hxx>
+#include <vcl/print.hxx>
+#include <svl/style.hxx>
+#include <svl/stritem.hxx>
+#include <svl/eitem.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+#include <svtools/imagemgr.hxx>
+#include <vcl/waitobj.hxx>
+#include <tools/urlobj.hxx>
+#include <tools/color.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <sot/exchange.hxx>
+#include <comphelper/storagehelper.hxx>
+
+#include "helpid.hrc"
+#include "docvor.hxx"
+#include <sfx2/docfac.hxx>
+#include "orgmgr.hxx"
+#include <sfx2/doctempl.hxx>
+#include <sfx2/templdlg.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/app.hxx>
+#include <sfx2/dispatch.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "doc.hrc"
+#include <sfx2/sfx.hrc>
+#include "docvor.hrc"
+#include <sfx2/docfilt.hxx>
+#include <sfx2/filedlghelper.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/fcontnr.hxx>
+#include <svtools/localresaccess.hxx>
+#ifndef _SVT_DOC_ADDRESSTEMPLATE_HXX_
+#include <svtools/addresstemplate.hxx>
+#endif
+#include <comphelper/processfactory.hxx>
+#define _SVSTDARR_STRINGSDTOR
+#include <svl/svstdarr.hxx>
+
+static const char cDelim = ':';
+BOOL SfxOrganizeListBox_Impl::bDropMoveOk = TRUE;
+
+using namespace ::com::sun::star;
+
+//=========================================================================
+
+class SuspendAccel
+{
+public:
+ Accelerator* pAccel;
+
+ SuspendAccel( Accelerator* pA )
+ {
+ pAccel=pA;
+ GetpApp()->RemoveAccel( pAccel );
+ }
+ ~SuspendAccel()
+ {
+ GetpApp()->InsertAccel( pAccel );
+ }
+};
+
+//=========================================================================
+
+
+inline void SfxOrganizeListBox_Impl::SetBitmaps(
+ const Image &rOFolder, const Image &rCFolder, const Image &rODoc, const Image &rCDoc,
+ const Image &rOFolderHC, const Image &rCFolderHC, const Image &rODocHC, const Image &rCDocHC )
+{
+ aOpenedFolderBmp = rOFolder;
+ aClosedFolderBmp = rCFolder;
+ aOpenedDocBmp = rODoc;
+ aClosedDocBmp = rCDoc;
+
+ aOpenedFolderBmpHC = rOFolderHC;
+ aClosedFolderBmpHC = rCFolderHC;
+ aOpenedDocBmpHC = rODocHC;
+ aClosedDocBmpHC = rCDocHC;
+
+}
+
+//=========================================================================
+
+#define NO_DROP_ACTION ((sal_Int8)-1)
+
+class SfxOrganizeDlg_Impl
+{
+friend class SfxTemplateOrganizeDlg;
+friend class SfxOrganizeListBox_Impl;
+
+ SuspendAccel* pSuspend;
+ SfxTemplateOrganizeDlg* pDialog;
+
+ SfxOrganizeListBox_Impl* pFocusBox;
+ Printer* pPrt;
+
+ // save pointer for asynchronous D&D
+ SvLBox* pSourceView;
+ SvLBoxEntry* pTargetEntry;
+ SfxOrganizeListBox_Impl* pFinishedBox;
+ sal_Int8 nDropAction;
+ bool bExecDropFinished;
+
+ // save some variables for the asynchronous file dialog
+ USHORT m_nRegion;
+ USHORT m_nIndex;
+ String m_sExtension4Save;
+
+ SfxOrganizeListBox_Impl aLeftLb;
+ ListBox aLeftTypLb;
+
+ SfxOrganizeListBox_Impl aRightLb;
+ ListBox aRightTypLb;
+
+ OKButton aOkBtn;
+ MenuButton aEditBtn;
+ HelpButton aHelpBtn;
+ PushButton aAddressTemplateBtn;
+ PushButton aFilesBtn;
+
+ Accelerator aEditAcc;
+
+ String aLastDir;
+ SfxOrganizeMgr aMgr;
+ sfx2::FileDialogHelper* pFileDlg;
+
+ SvStringsDtor* GetAllFactoryURLs_Impl() const;
+ sal_Bool GetServiceName_Impl( String& rFactoryURL, String& rFileURL ) const;
+ long Dispatch_Impl( USHORT nId, Menu* _pMenu );
+ String GetPath_Impl( BOOL bOpen, const String& rFileName );
+ ::com::sun::star::uno::Sequence< ::rtl::OUString >
+ GetPaths_Impl( const String& rFileName );
+ void InitBitmaps( void );
+
+ DECL_LINK( GetFocus_Impl, SfxOrganizeListBox_Impl * );
+ DECL_LINK( LeftListBoxSelect_Impl, ListBox * );
+ DECL_LINK( RightListBoxSelect_Impl, ListBox * );
+ DECL_LINK( AccelSelect_Impl, Accelerator * );
+ DECL_LINK( MenuSelect_Impl, Menu * );
+ DECL_LINK( MenuActivate_Impl, Menu * );
+ DECL_LINK( AddFiles_Impl, Button * );
+ DECL_LINK( OnAddressTemplateClicked, Button * );
+
+ DECL_LINK( ImportHdl, sfx2::FileDialogHelper* );
+ DECL_LINK( ExportHdl, sfx2::FileDialogHelper* );
+ DECL_LINK( AddFilesHdl, sfx2::FileDialogHelper* );
+
+ BOOL DontDelete_Impl( SvLBoxEntry* pEntry );
+ void OkHdl( Button* );
+
+public:
+ SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent, SfxDocumentTemplates* pTempl );
+ ~SfxOrganizeDlg_Impl();
+};
+
+//-------------------------------------------------------------------------
+
+SfxOrganizeDlg_Impl::SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent,
+ SfxDocumentTemplates* pTempl ) :
+
+ pSuspend ( NULL ),
+ pDialog ( pParent ),
+ pFocusBox ( NULL ),
+ pPrt ( NULL ),
+ pSourceView ( NULL ),
+ pTargetEntry ( NULL ),
+ pFinishedBox ( NULL ),
+ nDropAction ( NO_DROP_ACTION ),
+ bExecDropFinished ( true ),
+
+ aLeftLb ( this, pParent, WB_BORDER | WB_TABSTOP | WB_HSCROLL, SfxOrganizeListBox_Impl::VIEW_TEMPLATES ),
+ aLeftTypLb ( pParent, SfxResId( LB_LEFT_TYP ) ),
+
+ aRightLb ( this, pParent, WB_BORDER | WB_TABSTOP | WB_HSCROLL, SfxOrganizeListBox_Impl::VIEW_FILES ),
+ aRightTypLb ( pParent, SfxResId( LB_RIGHT_TYP ) ),
+
+ aOkBtn ( pParent, SfxResId( BTN_OK ) ),
+ aEditBtn ( pParent, SfxResId( BTN_EDIT ) ),
+ aHelpBtn ( pParent, SfxResId( BTN_HELP ) ),
+ aAddressTemplateBtn ( pParent, SfxResId( BTN_ADDRESSTEMPLATE ) ),
+ aFilesBtn ( pParent, SfxResId( BTN_FILES ) ),
+
+ aEditAcc ( SfxResId( ACC_EDIT ) ),
+ aMgr ( &aLeftLb, &aRightLb, pTempl ),
+ pFileDlg ( NULL )
+
+{
+ // update the SfxDocumentTemplates the manager works with
+ if ( aMgr.GetTemplates() ) // should never fail, but who knows ....
+ {
+ // for this, show a wait cursor (it may take a while)
+ Window* pWaitObjectRange = pDialog ? pDialog->GetParent() : NULL;
+ if ( !pWaitObjectRange )
+ pWaitObjectRange = pDialog;
+
+ WaitObject aWaitCursor( pWaitObjectRange );
+ const_cast< SfxDocumentTemplates* >( aMgr.GetTemplates() )->Update( sal_True /* be smart */ );
+ // this const_cast is a hack - but the alternative would be to
+ // * have a method which returns the templates non-const
+ // * use a new SfxDocumentTemplates instance for the update (knowing that they all share the same
+ // implementation class)
+ // * always work with an own instance, even if we get only NULL in this ctor
+ }
+
+ aLeftLb.SetHelpId( HID_CTL_ORGANIZER_LEFT );
+ aRightLb.SetHelpId( HID_CTL_ORGANIZER_RIGHT );
+
+ String aWorkPath = SvtPathOptions().GetWorkPath();
+ if ( aWorkPath.Len() )
+ {
+ INetURLObject aObj( aWorkPath );
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL !" );
+ aObj.setFinalSlash();
+ aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
+ }
+ else
+ {
+ // fallback
+ String aProgURL = SvtPathOptions().SubstituteVariable( String::CreateFromAscii("$(PROGURL)") );
+ INetURLObject aObj( aProgURL );
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL !" );
+ aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
+ }
+
+ InitBitmaps();
+
+ aEditBtn.GetPopupMenu()->SetSelectHdl( LINK( this, SfxOrganizeDlg_Impl, MenuSelect_Impl ) );
+ aEditBtn.GetPopupMenu()->SetActivateHdl( LINK( this, SfxOrganizeDlg_Impl, MenuActivate_Impl ) );
+ aEditAcc.SetSelectHdl( LINK( this, SfxOrganizeDlg_Impl, AccelSelect_Impl ) );
+ GetpApp()->InsertAccel( &aEditAcc );
+
+ aFilesBtn.SetClickHdl(
+ LINK(this,SfxOrganizeDlg_Impl, AddFiles_Impl));
+ aAddressTemplateBtn.SetClickHdl(
+ LINK(this,SfxOrganizeDlg_Impl, OnAddressTemplateClicked));
+ aLeftTypLb.SetSelectHdl(
+ LINK(this, SfxOrganizeDlg_Impl, LeftListBoxSelect_Impl));
+ aRightTypLb.SetSelectHdl(
+ LINK(this, SfxOrganizeDlg_Impl, RightListBoxSelect_Impl));
+ aLeftLb.SetGetFocusHdl(
+ LINK(this, SfxOrganizeDlg_Impl, GetFocus_Impl));
+ aRightLb.SetGetFocusHdl(
+ LINK(this, SfxOrganizeDlg_Impl, GetFocus_Impl));
+ aLeftLb.SetPosSizePixel(pParent->LogicToPixel(Point(3, 6), MAP_APPFONT),
+ pParent->LogicToPixel(Size(94, 132), MAP_APPFONT));
+ aRightLb.SetPosSizePixel(pParent->LogicToPixel(Point(103, 6), MAP_APPFONT),
+ pParent->LogicToPixel(Size(94, 132), MAP_APPFONT));
+
+ if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE) )
+ aAddressTemplateBtn.Hide();
+ Font aFont(aLeftLb.GetFont());
+ aFont.SetWeight(WEIGHT_NORMAL);
+ aLeftLb.SetFont(aFont);
+ aRightLb.SetFont(aFont);
+ const long nIndent = aLeftLb.GetIndent() / 2;
+ aLeftLb.SetIndent( (short)nIndent );
+ aRightLb.SetIndent( (short)nIndent );
+
+ aLeftLb.SetMgr(&aMgr);
+ aRightLb.SetMgr(&aMgr);
+ aLeftLb.Reset();
+ aRightLb.Reset();//SetModel(aLeftLb.GetModel());
+
+ aLeftLb.Show();
+ aRightLb.Show();
+
+ aLeftLb.SelectAll( FALSE );
+ aRightLb.SelectAll( FALSE );
+ aRightLb.GrabFocus();
+}
+
+//-------------------------------------------------------------------------
+
+SfxOrganizeDlg_Impl::~SfxOrganizeDlg_Impl()
+{
+ delete pFileDlg;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxOrganizeDlg_Impl::InitBitmaps( void )
+{
+ Image aOpenedFolderBmp( SfxResId( IMG_OPENED_FOLDER ) );
+ Image aClosedFolderBmp( SfxResId( IMG_CLOSED_FOLDER ) );
+ Image aOpenedDocBmp( SfxResId( IMG_OPENED_DOC ) );
+ Image aClosedDocBmp( SfxResId( IMG_CLOSED_DOC ) );
+
+ Image aOpenedFolderBmpHC( SfxResId( IMG_OPENED_FOLDER_HC ) );
+ Image aClosedFolderBmpHC( SfxResId( IMG_CLOSED_FOLDER_HC ) );
+ Image aOpenedDocBmpHC( SfxResId( IMG_OPENED_DOC_HC ) );
+ Image aClosedDocBmpHC( SfxResId( IMG_CLOSED_DOC_HC ) );
+
+ aLeftLb.SetBitmaps( aOpenedFolderBmp, aClosedFolderBmp, aOpenedDocBmp, aClosedDocBmp,
+ aOpenedFolderBmpHC, aClosedFolderBmpHC, aOpenedDocBmpHC, aClosedDocBmpHC );
+ aRightLb.SetBitmaps( aOpenedFolderBmp, aClosedFolderBmp, aOpenedDocBmp, aClosedDocBmp,
+ aOpenedFolderBmpHC, aClosedFolderBmpHC, aOpenedDocBmpHC, aClosedDocBmpHC );
+}
+
+//=========================================================================
+
+BOOL QueryDelete_Impl(Window *pParent, // Parent der QueryBox
+ USHORT nId, // Resource Id
+ const String &rTemplateName) // Name der zu l"oschenden Vorlage
+/* [Beschreibung]
+
+ "oschabfrage
+
+*/
+{
+ SfxResId aResId( nId );
+ String aEntryText( aResId );
+ aEntryText.SearchAndReplaceAscii( "$1", rTemplateName );
+ QueryBox aBox( pParent, WB_YES_NO | WB_DEF_NO, aEntryText );
+ return RET_NO != aBox.Execute();
+}
+
+//-------------------------------------------------------------------------
+
+void ErrorDelete_Impl(Window *pParent, const String &rName, sal_Bool bFolder = sal_False )
+
+/* [Beschreibung]
+
+ Benutzerinformation, da"s die Vorlage rName nicht gel"oscht werden konnte
+
+*/
+{
+ if ( bFolder )
+ {
+ String aText( SfxResId( STR_ERROR_DELETE_TEMPLATE_DIR ) );
+ ErrorBox( pParent, WB_OK, aText ).Execute();
+ }
+ else
+ {
+ String aText( SfxResId( STR_ERROR_DELETE_TEMPLATE ) );
+ aText.SearchAndReplaceAscii( "$1", rName );
+ ErrorBox( pParent, WB_OK, aText ).Execute();
+ }
+}
+
+
+//=========================================================================
+
+/* [Beschreibung]
+
+ Implementierungsklasse; Referenzklasse f"ur USHORT-Array
+
+*/
+
+struct ImpPath_Impl
+{
+ SvUShorts aUS;
+ USHORT nRef;
+
+ ImpPath_Impl();
+ ImpPath_Impl( const ImpPath_Impl& rCopy );
+};
+
+//-------------------------------------------------------------------------
+
+ImpPath_Impl::ImpPath_Impl() : aUS(5), nRef(1)
+{
+}
+
+//-------------------------------------------------------------------------
+
+ImpPath_Impl::ImpPath_Impl( const ImpPath_Impl& rCopy ) :
+
+ aUS ( (BYTE)rCopy.aUS.Count() ),
+ nRef( 1 )
+
+{
+ const USHORT nCount = rCopy.aUS.Count();
+
+ for ( USHORT i = 0; i < nCount; ++i )
+ aUS.Insert( rCopy.aUS[i], i );
+}
+
+//==========================================================================
+
+/* [Beschreibung]
+
+ Implementierungsklasse; Darstellung einer Position in der Outline-
+ Listbox als USHORT-Array; dieses beschreibt die Position jeweil
+ als relative Postion zum "ubergeordneten Eintrag
+
+*/
+class Path
+{
+ ImpPath_Impl *pData;
+ void NewImp();
+public:
+ Path(SvLBox *pBox, SvLBoxEntry *pEntry);
+ Path(const Path &rPath):
+ pData(rPath.pData)
+ {
+ ++pData->nRef;
+ }
+ const Path &operator=(const Path &rPath)
+ {
+ if(&rPath != this)
+ {
+ if(!--pData->nRef)
+ delete pData;
+ pData = rPath.pData;
+ pData->nRef++;
+ }
+ return *this;
+ }
+ ~Path()
+ {
+ if(!--pData->nRef)
+ delete pData;
+ }
+ USHORT Count() const { return pData->aUS.Count(); }
+ USHORT operator[]( USHORT i ) const
+ {
+ return i < Count()? pData->aUS[i]: INDEX_IGNORE;
+ }
+};
+
+//-------------------------------------------------------------------------
+
+Path::Path(SvLBox *pBox, SvLBoxEntry *pEntry) :
+ pData(new ImpPath_Impl)
+{
+ DBG_ASSERT(pEntry != 0, "EntryPtr ist NULL");
+ if(!pEntry)
+ return;
+ SvLBoxEntry *pParent = pBox->GetParent(pEntry);
+ do {
+ pData->aUS.Insert((USHORT)pBox->GetModel()->GetRelPos(pEntry), 0);
+ if(0 == pParent)
+ break;
+ pEntry = pParent;
+ pParent = pBox->GetParent(pEntry);
+ } while(1);
+}
+
+//-------------------------------------------------------------------------
+
+void Path::NewImp()
+{
+ if(pData->nRef != 1)
+ {
+ pData->nRef--;
+ pData = new ImpPath_Impl(*pData);
+ }
+}
+
+//-------------------------------------------------------------------------
+
+SvLBoxEntry *GetIndices_Impl(SvLBox *pBox,
+ SvLBoxEntry *pEntry,
+ USHORT &rRegion,
+ USHORT &rOffset)
+/* [Beschreibung]
+
+ Bereich und Position innerhalb eines Bereiches f"ur eine
+ Dokumentvorlage wird ermittelt.
+
+ [Parameter]
+
+ SvLBox *pBox Listbox, an der das Ereignis auftrat
+ SvLBoxEntry *pEntry Eintrag, dessen Position ermittelt werden soll
+ USHORT &rRegion der Bereich innerhalb der Bereiche der
+ Dokumentvorlagen (Out-Parameter)
+ USHORT &rOffset die Position innerhalb des Bereiches
+ Dokumentvorlagen (Out-Parameter)
+
+ [Querverweise]
+
+ <class Path> (unter Umst"anden kann auf diese Funktion zugunsten
+ von Path verzichtet werden.)
+
+*/
+
+{
+ if(!pEntry)
+ {
+ rRegion = rOffset = 0;
+ return pEntry;
+ }
+ if(0 == pBox->GetModel()->GetDepth(pEntry))
+ {
+ rRegion = (USHORT)pBox->GetModel()->GetRelPos(pEntry);
+ rOffset = USHRT_MAX;
+ return pEntry;
+ }
+ SvLBoxEntry *pParent = pBox->GetParent(pEntry);
+ rRegion = (USHORT)pBox->GetModel()->GetRelPos(pParent);
+ rOffset = (USHORT)pBox->GetModel()->GetRelPos(pEntry);
+ return pEntry;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeListBox_Impl::Select( SvLBoxEntry* pEntry, BOOL bSelect )
+{
+ if(!bSelect)
+ return SvTreeListBox::Select(pEntry,bSelect);
+ USHORT nLevel = GetDocLevel();
+ if(GetModel()->GetDepth(pEntry)+nLevel<3)
+ return SvTreeListBox::Select(pEntry,bSelect);
+
+ Path aPath(this, pEntry);
+ GetObjectShell(aPath)->TriggerHelpPI(
+ aPath[nLevel+1], aPath[nLevel+2], aPath[nLevel+3]);
+ return SvTreeListBox::Select(pEntry,bSelect);
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
+ SvLBoxEntry *pSource,
+ SvLBoxEntry* pTarget,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx,
+ BOOL bCopy)
+/* [Beschreibung]
+
+ Verschieben oder Kopieren von Dokumentvorlagen
+
+ [Parameter]
+
+ SvLBox *pSourceBox Quell-Listbox, an der das Ereignis auftrat
+ SvLBoxEntry *pSource Quell-Eintrag, der kopiert / verschoben werden soll
+ SvLBoxEntry* pTarget Ziel-Eintrag, auf den verschoben werden soll
+ SvLBoxEntry *&pNewParent der Parent der an der Zielposition erzeugten
+ Eintrags (Out-Parameter)
+ ULONG &rIdx Index des Zieleintrags
+ BOOL bCopy Flag f"ur Kopieren / Verschieben
+
+
+ [Returnwert] BOOL: Erfolg oder Mi"serfolg
+
+ [Querverweise]
+
+ <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
+ SvLBoxEntry *pSource,
+ SvLBoxEntry* pTarget,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx,
+ BOOL bCopy)>
+ <BOOL SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
+ SvLBoxEntry* pSource,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx)>
+ <BOOL SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
+ SvLBoxEntry* pSource,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx)>
+*/
+
+{
+ BOOL bOk = FALSE;
+
+ if(pSource)
+ {
+ USHORT nTargetRegion = 0, nTargetIndex = 0;
+ GetIndices_Impl(this, pTarget, nTargetRegion, nTargetIndex);
+
+ USHORT nSourceRegion = 0, nSourceIndex = 0;
+ GetIndices_Impl(pSourceBox, pSource, nSourceRegion, nSourceIndex);
+
+ bOk = bCopy ?
+ pMgr->Copy(nTargetRegion, nTargetIndex+1,
+ nSourceRegion, nSourceIndex):
+ pMgr->Move(nTargetRegion, nTargetIndex+1,
+ nSourceRegion, nSourceIndex);
+
+ if(bOk)
+ {
+ if(pSourceBox->GetModel()->GetDepth(pSource) == GetModel()->GetDepth(pTarget))
+ {
+ pNewParent = GetParent(pTarget);
+ rIdx = GetModel()->GetRelPos(pTarget)+1;
+ }
+ else
+ {
+ if(nTargetIndex == USHRT_MAX)
+ {
+ pNewParent = pTarget;
+ rIdx = 0;
+ }
+ else
+ SvLBox::NotifyCopying(
+ pTarget, pSource, pNewParent, rIdx);
+ }
+ }
+ else if ( bCopy )
+ {
+ // the template organizer always tries copy after the move, so no error is required for move case
+ String aText( SfxResId( bCopy ? STR_ERROR_COPY_TEMPLATE : STR_ERROR_MOVE_TEMPLATE ) );
+ aText.SearchAndReplaceAscii( "$1",
+ ( (SvTreeListBox *)pSourceBox )->GetEntryText( pSource ) );
+ ErrorBox( this, WB_OK, aText ).Execute();
+ }
+ }
+ return bOk;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
+ SvLBoxEntry *pSource,
+ SvLBoxEntry* pTarget,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx,
+ BOOL bCopy)
+/* [Beschreibung]
+
+ Verschieben oder Kopieren von Dokumentinhalten
+
+ [Parameter]
+
+ SvLBox *pSourceBox Quell-Listbox, an der das Ereignis auftrat
+ SvLBoxEntry *pSource Quell-Eintrag, der kopiert / verschoben werden soll
+ SvLBoxEntry* pTarget Ziel-Eintrag, auf den verschoben werden soll
+ SvLBoxEntry *&pNewParent der Parent der an der Zielposition erzeugten
+ Eintrags (Out-Parameter)
+ ULONG &rIdx Index des Zieleintrags
+ BOOL bCopy Flag f"ur Kopieren / Verschieben
+
+
+ [Returnwert] BOOL: Erfolg oder Mi"serfolg
+
+ [Querverweise]
+
+ <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
+ SvLBoxEntry *pSource,
+ SvLBoxEntry* pTarget,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx,
+ BOOL bCopy)>
+ <BOOL SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
+ SvLBoxEntry* pSource,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx)>
+ <BOOL SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
+ SvLBoxEntry* pSource,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx)>
+*/
+
+{
+ SfxErrorContext aEc( ERRCTX_SFX_MOVEORCOPYCONTENTS, this);
+ BOOL bOk = FALSE, bKeepExpansion = FALSE;
+ BOOL bRemovedFromSource = FALSE;
+ Path aSource(pSourceBox, pSource);
+ Path aTarget(this, pTarget);
+ SfxObjectShellRef aSourceDoc =
+ ((SfxOrganizeListBox_Impl *)pSourceBox)->GetObjectShell(aSource);
+
+ SfxObjectShellRef aTargetDoc = GetObjectShell(aTarget);
+ const USHORT nSLevel =
+ ((SfxOrganizeListBox_Impl *)pSourceBox)->GetDocLevel();
+ const USHORT nTLevel = GetDocLevel();
+
+ if(aSourceDoc.Is() && aTargetDoc.Is())
+ {
+ if (aSourceDoc->GetStyleSheetPool())
+ aSourceDoc->GetStyleSheetPool()->SetSearchMask(
+ SFX_STYLE_FAMILY_ALL, SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
+
+ if (aTargetDoc->GetStyleSheetPool())
+ aTargetDoc->GetStyleSheetPool()->SetSearchMask(
+ SFX_STYLE_FAMILY_ALL, SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
+ USHORT p[3];
+ USHORT nIdxDeleted = INDEX_IGNORE;
+ p[0]=aTarget[nTLevel+1];
+ p[1]=aTarget[nTLevel+2];
+ if(p[1]!=INDEX_IGNORE)p[1]++;
+ p[2]=aTarget[nTLevel+3];
+
+ bOk = aTargetDoc->Insert(
+ *aSourceDoc, aSource[nSLevel+1],
+ aSource[nSLevel+2], aSource[nSLevel+3],
+ p[0], p[1], p[2], nIdxDeleted);
+ // Positionskorrektur auswerten
+ // a = Dokumentinhalt
+ // b = Position Sub-Inhalt 1
+ // c = Position Sub-Inhalt 2
+ // doppelte Eintraege loeschen
+ if(bOk)
+ {
+ SvLBoxEntry *pParentIter = pTarget;
+ // bis auf die DokumentEbene nach oben als
+ // allgemeiner Bezugspunkt
+ while(GetModel()->GetDepth(pParentIter) != nTLevel)
+ pParentIter = GetParent(pParentIter);
+ if(pParentIter->HasChildsOnDemand() &&
+ !GetModel()->HasChilds(pParentIter))
+ RequestingChilds(pParentIter);
+ SvLBoxEntry *pChildIter = 0;
+
+ USHORT i = 0;
+ while(i < 2 && p[i+1] != INDEX_IGNORE)
+ {
+ pChildIter = FirstChild(pParentIter);
+ // bis zum Index der aktuellen Ebene
+ for(USHORT j = 0; j < p[i]; ++j)
+ pChildIter = NextSibling(pChildIter);
+ // gfs Fuellen bei Items onDemand
+ ++i;
+ if(p[i+1] != INDEX_IGNORE &&
+ pChildIter->HasChildsOnDemand() &&
+ !GetModel()->HasChilds(pChildIter))
+ RequestingChilds(pChildIter);
+ pParentIter = pChildIter;
+ }
+ rIdx = p[i];
+ pNewParent = pParentIter;
+ if(!IsExpanded(pNewParent) &&
+ pNewParent->HasChildsOnDemand() &&
+ !GetModel()->HasChilds(pNewParent))
+ {
+ bOk = FALSE;
+ if(!bCopy)
+ pSourceBox->GetModel()->Remove(pSource);
+ }
+ // Geloeschte Eintraege entfernen
+ // (kann durch Ueberschreiben geschehen)
+ if(nIdxDeleted != INDEX_IGNORE)
+ {
+ pChildIter = FirstChild(pParentIter);
+ for(USHORT j = 0; j < nIdxDeleted; ++j)
+ pChildIter = NextSibling(pChildIter);
+ if( pChildIter && pChildIter != pSource )
+ {
+ bKeepExpansion = IsExpanded(pParentIter);
+ GetModel()->Remove(pChildIter);
+ }
+ else
+ bOk = FALSE;
+ }
+ if(!bCopy && &aSourceDoc != &aTargetDoc)
+ {
+ //#109566# pool styles that are moved produce
+ //an rIdx == INDEX_IGNORE
+ //the method has to return true to keep the box content consistent
+ bRemovedFromSource = aSourceDoc->Remove(aSource[nSLevel+1],
+ aSource[nSLevel+2],
+ aSource[nSLevel+3]);
+ }
+ }
+ }
+// rIdx++;
+ return (((rIdx != INDEX_IGNORE)|| bRemovedFromSource) && bOk )
+ ? bKeepExpansion? (BOOL)2: TRUE: FALSE;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
+ SvLBoxEntry* pSource,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx)
+
+/* [Beschreibung]
+
+ Benachrichtigung, da"s ein Eintrag verschoben werden soll
+ (SV-Handler)
+
+ [Parameter]
+
+ SvLBoxEntry* pTarget Ziel-Eintrag, auf den verschoben werden soll
+ SvLBoxEntry *pSource Quell-Eintrag, der verschoben werden soll
+ SvLBoxEntry *&pNewParent der Parent der an der Zielposition erzeugten
+ Eintrags (Out-Parameter)
+ ULONG &rIdx Index des Zieleintrags
+
+
+ [Returnwert] BOOL: Erfolg oder Mi"serfolg
+
+ [Querverweise]
+
+ <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
+ SvLBoxEntry *pSource,
+ SvLBoxEntry* pTarget,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx,
+ BOOL bCopy)>
+ <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
+ SvLBoxEntry *pSource,
+ SvLBoxEntry* pTarget,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx,
+ BOOL bCopy)>
+ <BOOL SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
+ SvLBoxEntry* pSource,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx)>
+*/
+
+{
+ BOOL bOk = FALSE;
+ SvLBox* pSourceBox = GetSourceView();
+ if ( !pSourceBox )
+ pSourceBox = pDlg->pSourceView;
+ DBG_ASSERT( pSourceBox, "no source view" );
+ if ( !pTarget )
+ pTarget = pDlg->pTargetEntry;
+
+ if ( pSourceBox->GetModel()->GetDepth( pSource ) <= GetDocLevel() &&
+ GetModel()->GetDepth( pTarget ) <= GetDocLevel() )
+ bOk = MoveOrCopyTemplates( pSourceBox, pSource, pTarget, pNewParent, rIdx, FALSE );
+ else
+ bOk = MoveOrCopyContents(pSourceBox, pSource, pTarget, pNewParent, rIdx, FALSE );
+
+ return bOk;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
+ SvLBoxEntry* pSource,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx)
+/* [Beschreibung]
+
+ Benachrichtigung, da"s ein Eintrag kopiert werden soll
+ (SV-Handler)
+
+ [Parameter]
+
+ SvLBoxEntry* pTarget Ziel-Eintrag, auf den kopiert werden soll
+ SvLBoxEntry *pSource Quell-Eintrag, der kopiert werden soll
+ SvLBoxEntry *&pNewParent der Parent der an der Zielposition erzeugten
+ Eintrags (Out-Parameter)
+ ULONG &rIdx Index des Zieleintrags
+
+
+ [Returnwert] BOOL: Erfolg oder Mi"serfolg
+
+ [Querverweise]
+
+ <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
+ SvLBoxEntry *pSource,
+ SvLBoxEntry* pTarget,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx,
+ BOOL bCopy)>
+ <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
+ SvLBoxEntry *pSource,
+ SvLBoxEntry* pTarget,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx,
+ BOOL bCopy)>
+ <BOOL SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
+ SvLBoxEntry* pSource,
+ SvLBoxEntry *&pNewParent,
+ ULONG &rIdx)>
+*/
+{
+ BOOL bOk = FALSE;
+ SvLBox* pSourceBox = GetSourceView();
+ if ( !pSourceBox )
+ pSourceBox = pDlg->pSourceView;
+ DBG_ASSERT( pSourceBox, "no source view" );
+ if ( !pTarget )
+ pTarget = pDlg->pTargetEntry;
+ if ( pSourceBox->GetModel()->GetDepth( pSource ) <= GetDocLevel() &&
+ GetModel()->GetDepth( pTarget ) <= GetDocLevel() )
+ bOk = MoveOrCopyTemplates( pSourceBox, pSource, pTarget, pNewParent, rIdx, TRUE );
+ else
+ bOk = MoveOrCopyContents( pSourceBox, pSource, pTarget, pNewParent, rIdx, TRUE );
+
+ return bOk;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeListBox_Impl::EditingEntry( SvLBoxEntry* pEntry, Selection& )
+
+/* [Beschreibung]
+
+ Nachfrage, ob ein Eintrag editierbar ist
+ (SV-Handler)
+
+ [Querverweise]
+ <SfxOrganizeListBox_Impl::EditedEntry(SvLBoxEntry* pEntry, const String& rText)>
+*/
+
+{
+ if( VIEW_TEMPLATES == eViewType &&
+ GetModel()->GetDepth(pEntry) < 2 )
+ {
+ pDlg->pSuspend = new SuspendAccel( &pDlg->aEditAcc );
+ return TRUE;
+ }
+ return FALSE;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeListBox_Impl::EditedEntry(SvLBoxEntry* pEntry, const String& rText)
+
+/* [Beschreibung]
+
+ Der Name eines Eintrags wurde bearbeitet; ist der eingegebene Name
+ ein g"ultiger Name ("ange > 0), wird das Model aktualisiert.
+ (SV-Handler)
+
+ [Returnwert]
+
+ BOOL TRUE: der Name soll in der Anzeige ge"andert werden
+ FALSE:der Name soll nicht ge"andert werden
+
+ [Querverweise]
+ <SfxOrganizeListBox_Impl::EditingEntry(SvLBoxEntry* pEntry, const String& rText)>
+*/
+
+{
+ DBG_ASSERT(pEntry, "kein Entry selektiert");
+ delete pDlg->pSuspend;
+ pDlg->pSuspend = NULL;
+ SvLBoxEntry* pParent = GetParent(pEntry);
+ if( !rText.Len() )
+ {
+ ErrorBox aBox( this, SfxResId( MSG_ERROR_EMPTY_NAME ) );
+ aBox.GrabFocus();
+ aBox.Execute();
+ return FALSE;
+ }
+ if ( !IsUniqName_Impl( rText, pParent, pEntry ) )
+ {
+ ErrorBox aBox( this, SfxResId( MSG_ERROR_UNIQ_NAME ) );
+ aBox.GrabFocus();
+ aBox.Execute();
+ return FALSE;
+ }
+ USHORT nRegion = 0, nIndex = 0;
+ GetIndices_Impl( this, pEntry, nRegion, nIndex );
+ String aOldName;
+ if ( USHRT_MAX != nIndex )
+ aOldName = pMgr->GetTemplates()->GetName( nRegion, nIndex );
+ else
+ aOldName = pMgr->GetTemplates()->GetRegionName( nRegion );
+
+ if ( !pMgr->SetName( rText, nRegion, nIndex ) )
+ {
+ SfxResId aResId( USHRT_MAX != nIndex ? MSG_ERROR_RENAME_TEMPLATE
+ : MSG_ERROR_RENAME_TEMPLATE_REGION );
+ ErrorBox( this, aResId ).Execute();
+ return FALSE;
+ }
+/*
+ else
+ {
+ SfxTemplateOrganizeDlg* pDlg = (SfxTemplateOrganizeDlg*)Window::GetParent();
+ }
+*/
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+DragDropMode SfxOrganizeListBox_Impl::NotifyStartDrag( TransferDataContainer&, SvLBoxEntry* pEntry )
+{
+ USHORT nSourceLevel = GetModel()->GetDepth( pEntry );
+ if ( VIEW_FILES == GetViewType() )
+ ++nSourceLevel;
+ if ( nSourceLevel >= 2 )
+ bDropMoveOk = FALSE;
+ else
+ bDropMoveOk = TRUE;
+
+ return GetDragDropMode();
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeListBox_Impl::NotifyAcceptDrop( SvLBoxEntry* pEntry )
+{
+ if(!pEntry)
+ return FALSE;
+ SvLBox *pSource = GetSourceView();
+ SvLBoxEntry *pSourceEntry = pSource->FirstSelected();
+ if(pEntry == pSourceEntry)
+ return FALSE;
+ USHORT nSourceLevel = pSource->GetModel()->GetDepth(pSourceEntry);
+ if(VIEW_FILES == ((SfxOrganizeListBox_Impl *)pSource)->GetViewType())
+ ++nSourceLevel;
+ USHORT nTargetLevel = GetModel()->GetDepth(pEntry);
+ if(VIEW_FILES == GetViewType())
+ ++nTargetLevel;
+ Path aSource(pSource, pSourceEntry);
+ Path aTarget(this, pEntry);
+ const USHORT SL = ((SfxOrganizeListBox_Impl *)pSource)->GetDocLevel();
+ const USHORT TL = GetDocLevel();
+
+ return( (nSourceLevel == 1 && nTargetLevel == 0 &&
+ VIEW_TEMPLATES ==
+ ((SfxOrganizeListBox_Impl *)pSource)->GetViewType()) ||
+ (nSourceLevel == 1 && nTargetLevel == 1 &&
+ VIEW_TEMPLATES ==
+ ((SfxOrganizeListBox_Impl *)pSource)->GetViewType() &&
+ VIEW_TEMPLATES == GetViewType()) ||
+ (nSourceLevel == 3 && nTargetLevel == 1) ||
+ (nSourceLevel == 3 && nTargetLevel == 2 &&
+ aSource[1+SL] == aTarget[1+TL]) ||
+ (nSourceLevel == 3 && nTargetLevel == 3 &&
+ aSource[1+SL] == aTarget[1+TL]) ||
+ (nSourceLevel == 4 && nTargetLevel == 3 &&
+ aSource[1+SL] == aTarget[1+TL] &&
+ aSource[2+SL] == aTarget[2+TL]) ||
+ (nSourceLevel == 4 && nTargetLevel == 4 &&
+ aSource[1+SL] == aTarget[1+TL] &&
+ aSource[2+SL] == aTarget[2+TL]));
+}
+
+//-------------------------------------------------------------------------
+
+sal_Int8 SfxOrganizeListBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
+{
+ sal_Bool bAccept = ( eViewType == VIEW_FILES && IsDropFormatSupported( SOT_FORMAT_FILE ) );
+ if ( bAccept )
+ return rEvt.mnAction;
+ else
+ return SvTreeListBox::AcceptDrop( rEvt );
+}
+
+//-------------------------------------------------------------------------
+
+sal_Int8 SfxOrganizeListBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
+{
+ TransferableDataHelper aHelper( rEvt.maDropEvent.Transferable );
+ sal_uInt32 nFormatCount = aHelper.GetFormatCount();
+ BOOL bSuccess = FALSE;
+ for ( sal_uInt32 i = 0; i < nFormatCount; ++i )
+ {
+ String aFileName;
+ SotFormatStringId nId = aHelper.GetFormat(i);
+
+ if ( SOT_FORMAT_FILE == nId && aHelper.GetString( nId, aFileName ) )
+ {
+ INetURLObject aObj( aFileName, INET_PROT_FILE );
+ bSuccess |= pMgr->InsertFile( this, aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
+ }
+ }
+ bDropMoveOk = TRUE;
+ sal_Int8 nRet = rEvt.mnAction;
+ if ( !bSuccess )
+ {
+ // asynchronous, because of MessBoxes
+ pDlg->pSourceView = GetSourceView();
+ pDlg->pTargetEntry = pTargetEntry;
+ pDlg->pFinishedBox = NULL;
+ pDlg->nDropAction = NO_DROP_ACTION;
+ PostUserEvent( LINK( this, SfxOrganizeListBox_Impl, OnAsyncExecuteDrop ),
+ new ExecuteDropEvent( rEvt ) );
+ }
+
+ return nRet;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxOrganizeListBox_Impl::DragFinished( sal_Int8 nDropAction )
+{
+ if ( pDlg->bExecDropFinished )
+ {
+ if ( pDlg->nDropAction != NO_DROP_ACTION )
+ nDropAction = pDlg->nDropAction;
+ SvTreeListBox::DragFinished( nDropAction );
+ pDlg->nDropAction = NO_DROP_ACTION;
+ }
+ else
+ pDlg->pFinishedBox = this;
+}
+
+//-------------------------------------------------------------------------
+
+inline USHORT SfxOrganizeListBox_Impl::GetDocLevel() const
+
+/* [Beschreibung]
+
+ Ermittelt, auf welche Ebene sich Dokumente befinden (unterschiedlich
+ in der Dokumentvorlagensicht und der Dokumentensicht)
+
+ [Returnwert]
+
+ USHORT Die Ebene der Dokumente
+
+*/
+
+{
+ return eViewType == VIEW_FILES? 0: 1;
+}
+
+//-------------------------------------------------------------------------
+
+SfxObjectShellRef SfxOrganizeListBox_Impl::GetObjectShell(const Path &rPath)
+
+/* [Beschreibung]
+
+ Zugriff auf die ObjectShell, die dem aktuellen Eintrag zugeordnet
+ ist.
+
+ [Parameter]
+
+ const Path &rPath Beschreibung des aktuellen Eintrags
+
+ [Returnwert]
+
+ SfxObjectShellRef Referenz auf die ObjectShell
+
+ [Querverweise]
+
+ <class Path>
+
+*/
+
+{
+ SfxObjectShellRef aDoc;
+ if(eViewType == VIEW_FILES)
+ aDoc = pMgr->CreateObjectShell(rPath[0]);
+ else
+ aDoc = pMgr->CreateObjectShell(rPath[0], rPath[1]);
+ return aDoc;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxOrganizeListBox_Impl::RequestingChilds( SvLBoxEntry* pEntry )
+
+/* [Beschreibung]
+
+ Aufforderung, der Childs eines Eintrags einzuf"ugen
+ ist.
+ (SV-Handler)
+
+ [Parameter]
+
+ SvLBoxEntry* pEntry der Eintrag, dessen Childs erfragt werden
+
+
+*/
+
+{
+ // wenn keine Childs vorhanden sind, gfs. Childs
+ // einfuegen
+ BmpColorMode eColorMode = BMP_COLOR_NORMAL;
+
+ if ( GetSettings().GetStyleSettings().GetHighContrastMode() )
+ eColorMode = BMP_COLOR_HIGHCONTRAST;
+
+
+ if ( !GetModel()->HasChilds( pEntry ) )
+ {
+ WaitObject aWaitCursor( this );
+
+ // Choose the correct mask color dependent from eColorMode. This must be adopted if
+ // we change the mask color for normal images, too!
+ Color aMaskColor( COL_LIGHTMAGENTA );
+
+ // hier sind alle initial eingefuegt
+ SfxErrorContext aEc(ERRCTX_SFX_CREATEOBJSH, pDlg->pDialog);
+ if(VIEW_TEMPLATES == GetViewType() && 0 == GetModel()->GetDepth(pEntry))
+ {
+ USHORT i = (USHORT)GetModel()->GetRelPos(pEntry);
+ const USHORT nEntryCount = pMgr->GetTemplates()->GetCount(i);
+ for(USHORT j = 0; j < nEntryCount; ++j)
+ InsertEntryByBmpType( pMgr->GetTemplates()->GetName( i, j ), BMPTYPE_DOC, pEntry, TRUE );
+ }
+ else
+ {
+ const USHORT nDocLevel = GetDocLevel();
+ Path aPath(this, pEntry);
+ SfxObjectShellRef aRef = GetObjectShell(aPath);
+ if(aRef.Is())
+ {
+ const USHORT nCount = aRef->GetContentCount(
+ aPath[nDocLevel+1], aPath[nDocLevel+2]);
+ String aText;
+ Bitmap aClosedBmp, aOpenedBmp;
+ const BOOL bCanHaveChilds =
+ aRef->CanHaveChilds(aPath[nDocLevel+1],
+ aPath[nDocLevel+2]);
+ for(USHORT i = 0; i < nCount; ++i)
+ {
+ BOOL bDeletable;
+ aRef->GetContent(
+ aText, aClosedBmp, aOpenedBmp, eColorMode, bDeletable,
+ i, aPath[nDocLevel+1], aPath[nDocLevel+2]);
+
+ // Create image with the correct mask color
+ Image aClosedImage( aClosedBmp, aMaskColor );
+ Image aOpenedImage( aOpenedBmp, aMaskColor );
+
+ SvLBoxEntry *pNew = SvTreeListBox::InsertEntry(
+ aText, aOpenedImage, aClosedImage,
+ pEntry, bCanHaveChilds);
+ pNew->SetUserData(bDeletable ? &bDeletable : 0);
+ }
+ }
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+long SfxOrganizeListBox_Impl::ExpandingHdl()
+
+/* [Beschreibung]
+
+ SV-Handler, der nach dem und vor dem Aufklappen eines Eintrags
+ gerufen wird.
+ Wird verwendet, um gfs. die ObjectShell wieder zu schlie"sen;
+ die Eintr"age mit den Inhalten dieser Shell werden ebenfalls
+ entfernt.
+
+*/
+
+{
+ if ( !(nImpFlags & SVLBOX_IS_EXPANDING) )
+ {
+ SvLBoxEntry* pEntry = GetHdlEntry();
+ const USHORT nLevel = GetModel()->GetDepth(pEntry);
+ if((eViewType == VIEW_FILES && nLevel == 0) ||
+ (eViewType == VIEW_TEMPLATES && nLevel == 1))
+ {
+ Path aPath(this, pEntry);
+ // Beim Schliessen des Files die ObjectShell freigeben
+ if(eViewType == VIEW_FILES && nLevel == 0)
+ pMgr->DeleteObjectShell(aPath[0]);
+ else
+ pMgr->DeleteObjectShell(aPath[0], aPath[1]);
+ // alle SubEntries loeschen
+ SvLBoxEntry *pToDel = SvLBox::GetEntry(pEntry, 0);
+ while(pToDel)
+ {
+ GetModel()->Remove(pToDel);
+ pToDel = SvLBox::GetEntry(pEntry, 0);
+ }
+ }
+ }
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeListBox_Impl::IsUniqName_Impl(const String &rText,
+ SvLBoxEntry* pParent, SvLBoxEntry *pEntry) const
+
+/* [Beschreibung]
+
+ Pr"uft, ob eine Name auf seiner Ebene eindeutig ist.
+
+ [Parameter]
+
+ const String & Name des zu suchenden Eintrags
+ SvLBoxEntry* pSibling Geschwister (bezeichnet die Ebene)
+
+ [Returnwert]
+
+ BOOL TRUE, wenn der Name eindeutig ist, sonst FALSE
+*/
+
+{
+ SvLBoxEntry* pChild = FirstChild(pParent);
+ while(pChild) {
+ const String aEntryText(GetEntryText(pChild));
+ if(COMPARE_EQUAL == aEntryText.CompareIgnoreCaseToAscii(rText)&&(!pEntry || pEntry!=pChild))
+ return FALSE;
+ pChild = NextSibling(pChild);
+ }
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+USHORT SfxOrganizeListBox_Impl::GetLevelCount_Impl(SvLBoxEntry* pParent) const
+{
+ SvLBoxEntry* pChild = FirstChild(pParent);
+ USHORT nCount = 0;
+ while(pChild) {
+ pChild = NextSibling(pChild);
+ ++nCount;
+ }
+ return nCount;
+}
+
+//-------------------------------------------------------------------------
+
+SvLBoxEntry* SfxOrganizeListBox_Impl::InsertEntryByBmpType( const XubString& rText, BMPTYPE eBmpType,
+ SvLBoxEntry* pParent, BOOL bChildsOnDemand, ULONG nPos, void* pUserData )
+{
+ SvLBoxEntry* pEntry = NULL;
+ const Image* pExp = NULL;
+ const Image* pCol = NULL;
+ const Image* pExpHC = NULL;
+ const Image* pColHC = NULL;
+
+ switch( eBmpType )
+ {
+ case BMPTYPE_FOLDER:
+ pExp = &aOpenedFolderBmp;
+ pCol = &aClosedFolderBmp;
+ pExpHC = &aOpenedFolderBmpHC;
+ pColHC = &aClosedFolderBmpHC;
+ break;
+ default:
+ DBG_ERROR( "SfxOrganizeListBox_Impl::InsertEntryByBmpType(): something forgotten?!" );
+
+ case BMPTYPE_DOC:
+ pExp = &aOpenedDocBmp;
+ pCol = &aClosedDocBmp;
+ pExpHC = &aOpenedDocBmpHC;
+ pColHC = &aClosedDocBmpHC;
+ break;
+ }
+
+ pEntry = SvTreeListBox::InsertEntry( rText, *pExp, *pCol, pParent, bChildsOnDemand, nPos, pUserData );
+
+ SetExpandedEntryBmp( pEntry, *pExpHC, BMP_COLOR_HIGHCONTRAST );
+ SetCollapsedEntryBmp( pEntry, *pColHC, BMP_COLOR_HIGHCONTRAST );
+
+ return pEntry;
+}
+
+//-------------------------------------------------------------------------
+
+SfxOrganizeListBox_Impl::SfxOrganizeListBox_Impl
+(
+ SfxOrganizeDlg_Impl* pArgDlg,
+ Window* pParent,
+ WinBits nBits,
+ DataEnum eType
+) :
+
+ SvTreeListBox( pParent, nBits ),
+
+ pMgr ( NULL ),
+ pDlg ( pArgDlg ),
+ eViewType ( eType )
+
+/* [Beschreibung]
+
+ Konstruktor SfxOrganizeListBox
+
+*/
+
+{
+ SetDragDropMode(
+ SV_DRAGDROP_CTRL_MOVE | SV_DRAGDROP_CTRL_COPY |
+ SV_DRAGDROP_APP_MOVE | SV_DRAGDROP_APP_COPY | SV_DRAGDROP_APP_DROP );
+ SetEntryHeight( 16 );
+ SetSelectionMode( SINGLE_SELECTION );
+ GetModel()->SetSortMode( SortNone );
+
+ EnableContextMenuHandling();
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxOrganizeListBox_Impl, OnAsyncExecuteDrop, ExecuteDropEvent*, pEvent )
+{
+ DBG_ASSERT( pEvent, "invalid DropEvent" );
+ if ( pEvent )
+ {
+ SvLBox* pSourceView = GetSourceView();
+ if ( !pSourceView )
+ pSourceView = pDlg->pSourceView;
+ pDlg->bExecDropFinished = false;
+ // if a template can not be moved it should be copied
+ if ( pEvent->mnAction == DND_ACTION_MOVE )
+ pEvent->mnAction = DND_ACTION_COPYMOVE;
+ pDlg->nDropAction = SvTreeListBox::ExecuteDrop( *pEvent, pSourceView );
+ delete pEvent;
+ pDlg->pSourceView = NULL;
+ pDlg->pTargetEntry = NULL;
+ pDlg->bExecDropFinished = true;
+ if ( pDlg->pFinishedBox )
+ {
+ pDlg->pFinishedBox->DragFinished( pDlg->nDropAction );
+ pDlg->pFinishedBox = NULL;
+ }
+ }
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxOrganizeListBox_Impl::Reset()
+
+/* [Beschreibung]
+
+ Einf"ugen der Elemente in die ListBox
+
+*/
+
+{
+ DBG_ASSERT( pMgr != 0, "kein Manager" );
+ // Inhalte l"oschen
+ SetUpdateMode(FALSE);
+ Clear();
+ if ( VIEW_TEMPLATES == eViewType )
+ {
+ const USHORT nCount = pMgr->GetTemplates()->GetRegionCount();
+ for ( USHORT i = 0; i < nCount; ++i )
+ InsertEntryByBmpType( pMgr->GetTemplates()->GetFullRegionName(i), BMPTYPE_FOLDER, 0, TRUE );
+ }
+ else
+ {
+ const SfxObjectList& rList = pMgr->GetObjectList();
+ const USHORT nCount = rList.Count();
+ for ( USHORT i = 0; i < nCount; ++i )
+ InsertEntryByBmpType( rList.GetBaseName(i), BMPTYPE_DOC, 0, TRUE );
+
+ }
+ SetUpdateMode(TRUE);
+ Invalidate();
+ Update();
+}
+
+//-------------------------------------------------------------------------
+
+const Image &SfxOrganizeListBox_Impl::GetClosedBmp(USHORT nLevel) const
+
+/* [Beschreibung]
+
+ Zugriff auf die Bitmap f"ur einen geschlossenen Eintrag
+ der jeweiligen Ebene
+
+ [Parameter]
+
+ USHORT nLevel Angabe der Ebene, 2 Ebenen sind erlaubt
+
+ [Returnwert]
+
+ const Image & das Image auf der Ebenen nLevel
+
+*/
+
+{
+ BOOL bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
+ const Image* pRet = NULL;
+
+ switch( nLevel )
+ {
+ default: DBG_ERROR( "Bitmaps ueberindiziert" );
+
+ case 0: pRet = bHC? &aClosedFolderBmpHC : &aClosedFolderBmp; break;
+ case 1: pRet = bHC? &aClosedDocBmpHC : &aClosedDocBmp; break;
+ }
+
+ return *pRet;
+}
+
+//-------------------------------------------------------------------------
+
+const Image &SfxOrganizeListBox_Impl::GetOpenedBmp(USHORT nLevel) const
+
+/* [Beschreibung]
+
+ Zugriff auf die Bitmap f"ur einen ge"offneten Eintrag
+ der jeweiligen Ebene
+
+ [Parameter]
+
+ USHORT nLevel Angabe der Ebene, 2 Ebenen sind erlaubt
+
+ [Returnwert]
+
+ const Image & das Image auf der Ebenen nLevel
+
+*/
+
+{
+ BOOL bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
+ const Image* pRet = NULL;
+
+ switch( nLevel )
+ {
+ case 0:
+ pRet = bHC ? &aOpenedFolderBmpHC : &aOpenedFolderBmp; break;
+ case 1:
+ pRet = bHC ? &aOpenedDocBmpHC : &aOpenedDocBmp; break;
+ default:
+ pRet = bHC ? &aClosedFolderBmpHC : &aClosedFolderBmp; break;
+ }
+
+ return *pRet;
+}
+
+//-------------------------------------------------------------------------
+
+PopupMenu* SfxOrganizeListBox_Impl::CreateContextMenu()
+{
+ return new PopupMenu( *( pDlg->aEditBtn.GetPopupMenu() ) );
+}
+
+//-------------------------------------------------------------------------
+
+String SfxOrganizeDlg_Impl::GetPath_Impl( BOOL bOpen, const String& rFileName )
+
+/* [Beschreibung]
+
+ Pfad per FileDialog erfragen, f"ur Import / Export von
+ Dokumentvorlagen
+
+ [Parameter]
+
+ BOOL bOpen Flag: "Offnen / Speichern
+ const String& rFileName aktueller Dateiname als Vorschlag
+
+ [R"uckgabewert] Dateiname mit Pfad oder Leerstring, wenn
+ der Benutzer 'Abbrechen' gedr"uckt hat
+*/
+
+{
+ String aPath;
+ m_sExtension4Save = DEFINE_CONST_UNICODE( "vor" );
+ sal_Int16 nDialogType = bOpen
+ ? com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
+ : com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE;
+ if ( pFileDlg )
+ delete pFileDlg;
+ pFileDlg = new sfx2::FileDialogHelper( nDialogType, 0L );
+
+ // add "All" filter
+ pFileDlg->AddFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL ) ),
+ DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ) );
+ // add template filter
+ String sFilterName( SfxResId( STR_TEMPLATE_FILTER ) );
+ String sFilterExt;
+ // add filters of modules which are installed
+ SvtModuleOptions aModuleOpt;
+ if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
+ sFilterExt += DEFINE_CONST_UNICODE( "*.ott;*.stw;*.oth" );
+ if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
+ {
+ if ( sFilterExt.Len() > 0 )
+ sFilterExt += ';';
+ sFilterExt += DEFINE_CONST_UNICODE( "*.ots;*.stc" );
+ }
+ if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
+ {
+ if ( sFilterExt.Len() > 0 )
+ sFilterExt += ';';
+ sFilterExt += DEFINE_CONST_UNICODE( "*.otp;*.sti" );
+ }
+ if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
+ {
+ if ( sFilterExt.Len() > 0 )
+ sFilterExt += ';';
+ sFilterExt += DEFINE_CONST_UNICODE( "*.otg;*.std" );
+ }
+ if ( sFilterExt.Len() > 0 )
+ sFilterExt += ';';
+ sFilterExt += DEFINE_CONST_UNICODE( "*.vor" );
+
+ sFilterName += DEFINE_CONST_UNICODE( " (" );
+ sFilterName += sFilterExt;
+ sFilterName += ')';
+ pFileDlg->AddFilter( sFilterName, sFilterExt );
+ pFileDlg->SetCurrentFilter( sFilterName );
+
+ if ( aLastDir.Len() || rFileName.Len() )
+ {
+ INetURLObject aObj;
+ if ( aLastDir.Len() )
+ {
+ aObj.SetURL( aLastDir );
+ if ( rFileName.Len() )
+ aObj.insertName( rFileName );
+ }
+ else
+ aObj.SetURL( rFileName );
+
+ if ( aObj.hasExtension() )
+ {
+ m_sExtension4Save = aObj.getExtension(
+ INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+ aObj.removeExtension();
+ }
+
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ pFileDlg->SetDisplayDirectory( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
+ }
+
+ pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, ImportHdl ) );
+
+ return aPath;
+}
+
+//-------------------------------------------------------------------------
+
+::com::sun::star::uno::Sequence< ::rtl::OUString >
+ SfxOrganizeDlg_Impl::GetPaths_Impl( const String& rFileName )
+
+/* [Description]
+
+ Query plural paths by FileDialog, for Import / Export from document
+ templates
+
+ [Parameter]
+
+ const String& rFileName The default file name when dialog executes
+
+ [Return value] Empty sequence when users have clicked
+ 'Cancel', a sequence just containing one
+ file name with path when they have
+ choosed one file or a sequence containing
+ path and file names without path
+*/
+
+{
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > aPaths;
+ m_sExtension4Save = DEFINE_CONST_UNICODE( "vor" );
+ if ( pFileDlg )
+ delete pFileDlg;
+ pFileDlg = new sfx2::FileDialogHelper(
+ com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, SFXWB_MULTISELECTION );
+
+ // add "All" filter
+ pFileDlg->AddFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL ) ),
+ DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ) );
+
+ // add template filter
+ String sFilterName( SfxResId( STR_TEMPLATE_FILTER ) );
+ String sFilterExt;
+ // add filters of modules which are installed
+ SvtModuleOptions aModuleOpt;
+ if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
+ sFilterExt += DEFINE_CONST_UNICODE( "*.ott;*.stw;*.oth" );
+ if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
+ {
+ if ( sFilterExt.Len() > 0 )
+ sFilterExt += ';';
+ sFilterExt += DEFINE_CONST_UNICODE( "*.ots;*.stc" );
+ }
+ if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
+ {
+ if ( sFilterExt.Len() > 0 )
+ sFilterExt += ';';
+ sFilterExt += DEFINE_CONST_UNICODE( "*.otp;*.sti" );
+ }
+ if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
+ {
+ if ( sFilterExt.Len() > 0 )
+ sFilterExt += ';';
+ sFilterExt += DEFINE_CONST_UNICODE( "*.otg;*.std" );
+ }
+ if ( sFilterExt.Len() > 0 )
+ sFilterExt += ';';
+ sFilterExt += DEFINE_CONST_UNICODE( "*.vor" );
+
+ sFilterName += DEFINE_CONST_UNICODE( " (" );
+ sFilterName += sFilterExt;
+ sFilterName += ')';
+ pFileDlg->AddFilter( sFilterName, sFilterExt );
+ pFileDlg->SetCurrentFilter( sFilterName );
+
+ if ( aLastDir.Len() || rFileName.Len() )
+ {
+ INetURLObject aObj;
+ if ( aLastDir.Len() )
+ {
+ aObj.SetURL( aLastDir );
+ if ( rFileName.Len() )
+ aObj.insertName( rFileName );
+ }
+ else
+ aObj.SetURL( rFileName );
+
+ if ( aObj.hasExtension() )
+ {
+ m_sExtension4Save = aObj.getExtension(
+ INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+ aObj.removeExtension();
+ }
+
+ DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
+ pFileDlg->SetDisplayDirectory( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
+ }
+
+ pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, ExportHdl ) );
+
+ return aPaths;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeDlg_Impl::DontDelete_Impl( SvLBoxEntry* pEntry )
+{
+ USHORT nDepth = pFocusBox->GetModel()->GetDepth(pEntry);
+ if(SfxOrganizeListBox_Impl::VIEW_FILES ==
+ pFocusBox->GetViewType())
+ nDepth++;
+ if( (nDepth > 2 && !pEntry->GetUserData()) ||
+ //Delete ueber GetContent verboten
+ nDepth==2 || //Vorlage / Konfigurtionsrubrik nicht loeshcen
+ (nDepth==1 && SfxOrganizeListBox_Impl::VIEW_FILES ==
+ pFocusBox->GetViewType()) || //Files nicht loeschen
+ (0 == nDepth && pFocusBox->GetLevelCount_Impl(0) < 2))
+ //Mindestens eine Vorlage behalten
+ {
+ return TRUE;
+ }
+
+ USHORT nRegion = 0, nIndex = 0;
+ GetIndices_Impl( pFocusBox, pEntry, nRegion, nIndex );
+ const SfxDocumentTemplates* pTemplates = aMgr.GetTemplates();
+ if ( !pTemplates || !pTemplates->HasUserContents( nRegion, nIndex ) )
+ return TRUE;
+
+ return FALSE;
+}
+
+SvStringsDtor* SfxOrganizeDlg_Impl::GetAllFactoryURLs_Impl( ) const
+{
+ SvtModuleOptions aModOpt;
+ const ::com::sun::star::uno::Sequence < ::rtl::OUString >& aServiceNames = aModOpt.GetAllServiceNames() ;
+ SvStringsDtor* pList = new SvStringsDtor;
+ sal_Int32 nCount = aServiceNames.getLength();
+ for( sal_Int32 i=0; i<nCount; ++i )
+ {
+ if ( SfxObjectFactory::GetStandardTemplate( aServiceNames[i] ).Len() > 0 )
+ {
+ SvtModuleOptions::EFactory eFac = SvtModuleOptions::E_WRITER;
+ SvtModuleOptions::ClassifyFactoryByName( aServiceNames[i], eFac );
+ String* pURL = new String( aModOpt.GetFactoryEmptyDocumentURL( eFac ) );
+ pList->Insert( pURL, pList->Count() );
+ }
+ }
+
+ return pList;
+}
+
+sal_Bool SfxOrganizeDlg_Impl::GetServiceName_Impl( String& rName, String& rFileURL ) const
+{
+ sal_Bool bRet = sal_False;
+ const SfxDocumentTemplates* pTemplates = aMgr.GetTemplates();
+ SvLBoxEntry* pEntry = pFocusBox ? pFocusBox->FirstSelected() : NULL;
+ USHORT nRegion = 0, nIndex = 0;
+ GetIndices_Impl( pFocusBox, pEntry, nRegion, nIndex );
+ rFileURL = pTemplates->GetPath( nRegion, nIndex );
+ if ( rFileURL.Len() > 0 )
+ {
+ try
+ {
+ uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
+ rFileURL,
+ embed::ElementModes::READ );
+ ULONG nFormat = SotStorage::GetFormatID( xStorage );
+ const SfxFilter* pFilter =
+ SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( nFormat );
+ if ( pFilter )
+ {
+ rName = pFilter->GetServiceName();
+ bRet = TRUE;
+ }
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ return bRet;
+}
+
+long SfxOrganizeDlg_Impl::Dispatch_Impl( USHORT nId, Menu* _pMenu )
+
+/* [Beschreibung]
+
+ Verarbeiten der Events aus MenuButton oder Accelerator
+
+ [Parameter]
+
+ USHORT nId ID des Events
+
+ [R"uckgabewert] 1: Event wurde verarbeitet,
+ 0: Event wurde nicht verarbeitet (SV-Menu)
+
+*/
+
+{
+ SuspendAccel aTmp(&aEditAcc);
+ SvLBoxEntry *pEntry = pFocusBox? pFocusBox->FirstSelected(): 0;
+ sal_Bool bHandled = sal_True;
+ switch(nId)
+ {
+ case ID_NEW:
+ {
+ if(!pEntry)
+ return 1;
+ if(pFocusBox->GetViewType() == SfxOrganizeListBox_Impl::VIEW_TEMPLATES)
+ {
+ if(0 == pFocusBox->GetModel()->GetDepth(pEntry))
+ {
+ const String aNoName( SfxResId(STR_NONAME) );
+ SvLBoxEntry* pParent = pFocusBox->GetParent(pEntry);
+ String aName(aNoName);
+ USHORT n = 1;
+ while(!pFocusBox->IsUniqName_Impl(aName, pParent))
+ {
+ aName = aNoName;
+ aName += String::CreateFromInt32( n++ );
+ }
+ aMgr.InsertDir( pFocusBox, aName,
+ (USHORT)pFocusBox->GetModel()->GetRelPos(pEntry)+1);
+ }
+ }
+ break;
+ }
+
+ case ID_DELETE:
+ {
+ if(!pEntry || DontDelete_Impl(pEntry))
+ return 1;
+ const USHORT nDepth = pFocusBox->GetModel()->GetDepth(pEntry);
+ if(nDepth < 2)
+ {
+ if(0 == nDepth && pFocusBox->GetLevelCount_Impl(0) < 2) return 1;
+ if(SfxOrganizeListBox_Impl::VIEW_TEMPLATES == pFocusBox->GetViewType())
+ {
+ USHORT nResId = nDepth? STR_DELETE_TEMPLATE :
+ STR_DELETE_REGION;
+ if( !QueryDelete_Impl(
+ pDialog, nResId, pFocusBox->GetEntryText(pEntry)))
+ return 1;
+ if ( STR_DELETE_REGION == nResId &&
+ pFocusBox->GetChildCount(pEntry))
+ {
+ QueryBox aQBox(pDialog, SfxResId(MSG_REGION_NOTEMPTY));
+ if(RET_NO == aQBox.Execute())
+ return 1;
+ }
+ USHORT nRegion = 0, nIndex = 0;
+ GetIndices_Impl(pFocusBox, pEntry, nRegion, nIndex);
+
+ USHORT nDeleteInd = ( STR_DELETE_REGION == nResId? USHRT_MAX: nIndex );
+ if ( !aMgr.Delete( pFocusBox, nRegion, nDeleteInd ) )
+ ErrorDelete_Impl(
+ pDialog,
+ pFocusBox->GetEntryText(pEntry),
+ ( nDeleteInd == USHRT_MAX && pFocusBox->GetChildCount(pEntry) ) );
+ }
+ }
+ // Inhaltsformen
+ else if(nDepth + pFocusBox->GetDocLevel() >= 2)
+ {
+ if(!QueryDelete_Impl(pDialog, STR_DELETE_TEMPLATE, pFocusBox->GetEntryText(pEntry)))
+ return 1;
+ Path aPath(pFocusBox, pEntry);
+ SfxObjectShellRef aRef = pFocusBox->GetObjectShell(aPath);
+ if(aRef.Is() &&
+ aRef->Remove(aPath[1+pFocusBox->GetDocLevel()],
+ aPath[2+pFocusBox->GetDocLevel()],
+ aPath[3+pFocusBox->GetDocLevel()]))
+ pFocusBox->GetModel()->Remove(pEntry);
+ else
+ ErrorDelete_Impl(pDialog, pFocusBox->GetEntryText(pEntry), sal_False );
+ }
+ break;
+ }
+
+ case ID_EDIT:
+ {
+ if(!pEntry)
+ return 1;
+ USHORT nRegion = 0, nIndex = 0;
+ GetIndices_Impl( pFocusBox, pEntry, nRegion, nIndex );
+ const SfxStringItem aName( SID_FILE_NAME, aMgr.GetTemplates()->GetPath( nRegion, nIndex ) );
+ const SfxStringItem aLongName( SID_FILE_LONGNAME, pFocusBox->GetEntryText( pEntry ) );
+ const SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE( "private:user" ) );
+ const SfxStringItem aTargetName( SID_TARGETNAME, DEFINE_CONST_UNICODE( "_default" ) );
+ const SfxBoolItem aTemplateIndicator( SID_TEMPLATE, sal_False );
+
+ SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_OPENTEMPLATE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
+ &aName, &aLongName, &aReferer, &aTargetName, &aTemplateIndicator, 0L );
+ pDialog->EndDialog( RET_EDIT_STYLE );
+ break;
+ }
+
+ case ID_COPY_FROM:
+ {
+ if ( !pEntry )
+ return 1;
+ m_nRegion = 0;
+ m_nIndex = 0;
+ GetIndices_Impl( pFocusBox, pEntry, m_nRegion, m_nIndex );
+ GetPaths_Impl( String() );
+ break;
+ }
+
+ case ID_COPY_TO:
+ {
+ if ( !pEntry )
+ return 1;
+ m_nRegion = 0;
+ m_nIndex = 0;
+ GetIndices_Impl( pFocusBox, pEntry, m_nRegion, m_nIndex );
+ GetPath_Impl( FALSE, aMgr.GetTemplates()->GetFileName( m_nRegion, m_nIndex ) );
+ break;
+ }
+
+ case ID_RESCAN:
+ if ( !aMgr.Rescan() )
+ ErrorBox( pDialog, SfxResId( MSG_ERROR_RESCAN ) ).Execute();
+ if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aLeftLb.GetViewType() )
+ aLeftLb.Reset();
+ if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aRightLb.GetViewType() )
+ aRightLb.Reset();
+ break;
+
+ case ID_PRINT:
+ {
+ if ( !pEntry )
+ return 1;
+ Path aPath( pFocusBox, pEntry );
+ SfxObjectShellRef aRef = pFocusBox->GetObjectShell( aPath );
+ if ( aRef.Is() )
+ {
+ const USHORT nDocLevel = pFocusBox->GetDocLevel();
+ if ( !pPrt )
+ pPrt = new Printer;
+ SvLBoxEntry *pDocEntry = pEntry;
+ while ( pFocusBox->GetModel()->GetDepth( pDocEntry ) > nDocLevel )
+ pDocEntry = pFocusBox->GetParent( pDocEntry );
+ const String aName(pFocusBox->GetEntryText(pDocEntry));
+ if ( !aRef->Print( *pPrt, aPath[1+nDocLevel],
+ aPath[2+nDocLevel], aPath[3+nDocLevel], &aName ) )
+ ErrorBox( pDialog, SfxResId( MSG_PRINT_ERROR ) ).Execute();
+ }
+ break;
+ }
+
+ case ID_PRINTER_SETUP:
+ {
+ PrinterSetupDialog* pDlg = new PrinterSetupDialog( pDialog );
+ if ( !pPrt )
+ pPrt = new Printer;
+ pDlg->SetPrinter( pPrt );
+ pDlg->Execute();
+ delete pDlg;
+ break;
+ }
+
+ case ID_DEFAULT_TEMPLATE:
+ {
+ String aServiceName, aFileURL;
+ if ( GetServiceName_Impl( aServiceName, aFileURL ) )
+ SfxObjectFactory::SetStandardTemplate( aServiceName, aFileURL );
+ break;
+ }
+
+ default:
+ bHandled = sal_False;
+ }
+
+ if ( !bHandled && ( nId > ID_RESET_DEFAULT_TEMPLATE || nId <= ID_RESET_DEFAULT_TEMPLATE_END ) )
+ {
+ Menu* pSubMenu = _pMenu ? _pMenu : aEditBtn.GetPopupMenu()->GetPopupMenu( ID_RESET_DEFAULT_TEMPLATE );
+ if ( pSubMenu )
+ {
+ String aServiceName = SfxObjectShell::GetServiceNameFromFactory( pSubMenu->GetItemCommand( nId ) );
+ SfxObjectFactory::SetStandardTemplate( aServiceName, String() );
+ bHandled = sal_True;
+ }
+ }
+
+ return bHandled ? 1 : 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxOrganizeDlg_Impl, MenuSelect_Impl, Menu *, pMenu )
+
+/* [Beschreibung]
+
+ SelectHandler des Men"us des Men"ubuttons (SV)
+
+ [Parameter]
+
+ MenuButton *pBtn der das Event ausl"osende Button
+
+ [R"uckgabewert] 1: Event wurde verarbeitet,
+ 0: Event wurde nicht verarbeitet (SV-Menu)
+
+*/
+{
+ return Dispatch_Impl( pMenu->GetCurItemId(), pMenu );
+}
+IMPL_LINK_INLINE_END( SfxOrganizeDlg_Impl, MenuSelect_Impl, Menu *, pMenu )
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxOrganizeDlg_Impl, AccelSelect_Impl, Accelerator *, pAccel )
+
+/* [Beschreibung]
+
+ SelectHandler des Accelerators (SV)
+
+ [Parameter]
+
+ Accelerator *pAccel der das Event ausl"osende Accelerator
+
+ [R"uckgabewert] 1: Event wurde verarbeitet,
+ 0: Event wurde nicht verarbeitet (SV)
+
+*/
+
+{
+ SvLBoxEntry* pEntry = pFocusBox && pFocusBox->GetSelectionCount() ?
+ pFocusBox->FirstSelected() : NULL ;
+ return pEntry && ( pAccel->GetCurItemId() == ID_NEW || !DontDelete_Impl( pEntry ) ) ?
+ Dispatch_Impl( pAccel->GetCurItemId(), NULL ) : 0;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxOrganizeDlg_Impl::OkHdl(Button *pButton)
+{
+ if(pFocusBox && pFocusBox->IsEditingActive())
+ pFocusBox->EndEditing(FALSE);
+ pButton->Click();
+}
+
+
+
+IMPL_LINK( SfxOrganizeDlg_Impl, MenuActivate_Impl, Menu *, pMenu )
+
+/* [Beschreibung]
+
+ ActivateHandler des Men"us des Men"ubuttons (SV)
+
+ [Parameter]
+
+ Menu *pMenu das das Event ausl"osende Men"u
+
+ [R"uckgabewert] 1: Event wurde verarbeitet,
+ 0: Event wurde nicht verarbeitet (SV-Menu)
+
+*/
+{
+ if ( pFocusBox && pFocusBox->IsEditingActive() )
+ pFocusBox->EndEditing( FALSE );
+ BOOL bEnable = ( pFocusBox && pFocusBox->GetSelectionCount() );
+ SvLBoxEntry* pEntry = bEnable ? pFocusBox->FirstSelected() : NULL;
+ const USHORT nDepth =
+ ( bEnable && pFocusBox->GetSelectionCount() ) ? pFocusBox->GetModel()->GetDepth( pEntry ) : 0;
+ const USHORT nDocLevel = bEnable ? pFocusBox->GetDocLevel() : 0;
+ int eVT = pFocusBox ? pFocusBox->GetViewType() : 0;
+ // nur Vorlagen anlegen
+ pMenu->EnableItem( ID_NEW, bEnable && 0 == nDepth && SfxOrganizeListBox_Impl::VIEW_TEMPLATES == eVT );
+ // Vorlagen: Loeschen Ebene 0,1,3ff
+ // ein Bereich mu"s mindestens erhalten bleiben
+ // Dateien : Loeschen Ebene > 2
+
+ pMenu->EnableItem( ID_DELETE, bEnable && !DontDelete_Impl( pEntry ) );
+ pMenu->EnableItem( ID_EDIT,
+ bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES && nDepth == nDocLevel
+ && !DontDelete_Impl( pEntry ) );
+ pMenu->EnableItem( ID_COPY_FROM,
+ bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES &&
+ ( nDepth == nDocLevel || nDepth == nDocLevel - 1 ) );
+ pMenu->EnableItem( ID_COPY_TO,
+ bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES &&
+ nDepth == nDocLevel );
+ pMenu->EnableItem( ID_RESCAN,
+ SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aRightLb.GetViewType() ||
+ SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aLeftLb.GetViewType() );
+ BOOL bPrint = bEnable && nDepth > pFocusBox->GetDocLevel();
+ if ( bPrint && pPrt )
+ bPrint = !pPrt->IsPrinting() && !pPrt->IsJobActive();
+ if ( bPrint && bEnable )
+ {
+ // only styles printable
+ Path aPath( pFocusBox, pFocusBox->FirstSelected() );
+ USHORT nIndex = aPath[ nDocLevel + 1 ];
+ bPrint = ( nIndex == CONTENT_STYLE );
+ }
+ pMenu->EnableItem( ID_PRINT, bPrint );
+
+ if ( bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES && nDepth == nDocLevel )
+ {
+ String aFactoryURL, aFileURL;
+ bEnable = GetServiceName_Impl( aFactoryURL, aFileURL );
+ }
+ else if ( bEnable )
+ bEnable = FALSE;
+ pMenu->EnableItem( ID_DEFAULT_TEMPLATE, bEnable );
+
+ bEnable = sal_True;
+ SvStringsDtor* pList = GetAllFactoryURLs_Impl();
+ USHORT nCount = pList->Count();
+ if ( nCount > 0 )
+ {
+ PopupMenu* pSubMenu = new PopupMenu;
+ USHORT nItemId = ID_RESET_DEFAULT_TEMPLATE + 1;
+ for ( USHORT i = 0; i < nCount; ++i )
+ {
+ String aObjFacURL( *pList->GetObject(i) );
+ String aTitle = SvFileInformationManager::GetDescription(
+ INetURLObject(aObjFacURL) );
+ pSubMenu->InsertItem( nItemId, aTitle,
+ SvFileInformationManager::GetImage(INetURLObject(aObjFacURL)) );
+ pSubMenu->SetItemCommand( nItemId++, aObjFacURL );
+ DBG_ASSERT( nItemId <= ID_RESET_DEFAULT_TEMPLATE_END, "menu item id overflow" );
+ }
+ pMenu->SetPopupMenu( ID_RESET_DEFAULT_TEMPLATE, pSubMenu );
+ }
+ else
+ bEnable = sal_False;
+
+ delete pList;
+ pMenu->EnableItem( ID_RESET_DEFAULT_TEMPLATE, bEnable );
+
+ return 1;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxOrganizeDlg_Impl, GetFocus_Impl, SfxOrganizeListBox_Impl *, pBox )
+
+/* [Beschreibung]
+
+ GetFocus-Handler, wird aus den Select-Handler der Listboxen
+ gerufen.
+ Wird verwendet, im die Listbox, die den Focus besitzt sowie
+ deren Zustand zu ermitteln.
+
+ [Parameter]
+
+ SfxOrganizeListBox *pBox die rufende Box
+
+*/
+
+{
+ if(pFocusBox && pFocusBox != pBox)
+ pFocusBox->SelectAll(FALSE);
+ pFocusBox = pBox;
+ aFilesBtn.Enable( SfxOrganizeListBox_Impl::VIEW_FILES ==
+ pFocusBox->GetViewType() );
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxOrganizeDlg_Impl, LeftListBoxSelect_Impl, ListBox *, pBox )
+
+/* [Beschreibung]
+
+ Select-Handler, wird aus den Select-Handler der Listboxen
+ gerufen.
+ Wenn sich der Modus der Boxen (Dokumentsicht, Dokumentvorlagensicht)
+ unterscheiden, werden die Models getrennt; andernfalls zusammengefa"st.
+
+ [Parameter]
+
+ ListBox *pBox die rufende Box
+
+*/
+{
+ const SfxOrganizeListBox_Impl::DataEnum
+ eViewType = pBox->GetSelectEntryPos() == 0 ?
+ SfxOrganizeListBox_Impl::VIEW_TEMPLATES : SfxOrganizeListBox_Impl::VIEW_FILES;
+ if(eViewType!= aLeftLb.GetViewType()) {
+ aLeftLb.SetViewType(eViewType);
+ if(aRightLb.GetViewType() == eViewType)
+ aLeftLb.SetModel(aRightLb.GetModel());
+ else {
+ // Models trennen
+ aLeftLb.DisconnectFromModel();
+ aLeftLb.Reset();
+ }
+ }
+ GetFocus_Impl(&aLeftLb);
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxOrganizeDlg_Impl, RightListBoxSelect_Impl, ListBox *, pBox )
+
+/* [Beschreibung]
+
+ Select-Handler, wird aus den Select-Handler der Listboxen
+ gerufen.
+ Wenn sich der Modus der Boxen (Dokumentsicht, Dokumentvorlagensicht)
+ unterscheiden, werden die Models getrennt; andernfalls zusammengefa"st.
+
+ [Parameter]
+
+ ListBox *pBox die rufende Box
+
+*/
+{
+ const SfxOrganizeListBox_Impl::DataEnum eViewType =
+ pBox->GetSelectEntryPos() == 0 ?
+ SfxOrganizeListBox_Impl::VIEW_TEMPLATES : SfxOrganizeListBox_Impl::VIEW_FILES;
+ if(eViewType!= aRightLb.GetViewType())
+ {
+ aRightLb.SetViewType(eViewType);
+ if(aLeftLb.GetViewType() == eViewType)
+ aRightLb.SetModel(aLeftLb.GetModel());
+ else
+ {
+ // Models trennen
+ aRightLb.DisconnectFromModel();
+ aRightLb.Reset();
+ }
+ }
+ aRightLb.GrabFocus();
+ GetFocus_Impl(&aRightLb);
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxOrganizeDlg_Impl, OnAddressTemplateClicked, Button *, pButton )
+{
+ (void)pButton; //unused
+ svt::AddressBookSourceDialog aDialog(pDialog, ::comphelper::getProcessServiceFactory());
+ aDialog.Execute();
+ return 0L;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxOrganizeDlg_Impl, AddFiles_Impl, Button *, pButton )
+
+/* [Beschreibung]
+
+ Handler des Buttons f"ur das Hinzuf"ugen von Dateien per Dialog.
+
+ [Parameter]
+
+ Button * der Button, der dieses Events ausgel"ost hat.
+
+*/
+{
+ (void)pButton; //unused
+ if ( pFileDlg )
+ delete pFileDlg;
+ pFileDlg = new sfx2::FileDialogHelper( WB_OPEN, String() );
+
+ // add config and basic filter
+ static String sOpenBracket( DEFINE_CONST_UNICODE( " (" ) );
+ static String sCloseBracket( DEFINE_CONST_UNICODE( ")" ) );
+ static String sConfigExt( DEFINE_CONST_UNICODE( "*.cfg" ) );
+ static String sBasicExt( DEFINE_CONST_UNICODE( "*.sbl" ) );
+
+ String sFilterName( SfxResId( RID_STR_FILTCONFIG ) );
+ sFilterName += sOpenBracket;
+ sFilterName += sConfigExt;
+ sFilterName += sCloseBracket;
+ pFileDlg->AddFilter( sFilterName, sConfigExt );
+
+ sFilterName = String( SfxResId( RID_STR_FILTBASIC ) );
+ sFilterName += sOpenBracket;
+ sFilterName += sBasicExt;
+ sFilterName += sCloseBracket;
+ pFileDlg->AddFilter( sFilterName, sBasicExt );
+
+ // set "All" filter as current
+ pFileDlg->SetCurrentFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL ) ) );
+
+ if ( aLastDir.Len() )
+ pFileDlg->SetDisplayDirectory( aLastDir );
+
+ pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, AddFilesHdl ) );
+
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxOrganizeDlg_Impl, ImportHdl, sfx2::FileDialogHelper *, EMPTYARG )
+{
+ DBG_ASSERT( pFileDlg, "SfxOrganizeDlg_Impl::ImportHdl(): no file dialog" );
+
+ if ( ERRCODE_NONE == pFileDlg->GetError() )
+ {
+ String aPath = pFileDlg->GetPath();
+ INetURLObject aObj( aPath );
+
+ // we want to keep the original extension when exporting, the file open dialog
+ // always sets the extension to *.vor
+ if ( pFileDlg->GetDialogType() ==
+ com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE )
+ {
+ if ( aObj.hasExtension() )
+ aObj.removeExtension();
+
+ aObj.setExtension( m_sExtension4Save );
+ aPath = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
+ }
+
+ aObj.removeSegment();
+ aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
+
+ if ( aPath.Len() && !aMgr.CopyTo( m_nRegion, m_nIndex, aPath ) )
+ {
+ String aText( SfxResId( STR_ERROR_COPY_TEMPLATE ) );
+ aText.SearchAndReplaceAscii( "$1", aPath );
+ ErrorBox( pDialog, WB_OK, aText ).Execute();
+ }
+ }
+
+ return 0L;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxOrganizeDlg_Impl, ExportHdl, sfx2::FileDialogHelper *, EMPTYARG )
+{
+ DBG_ASSERT( pFileDlg, "SfxOrganizeDlg_Impl::ImportHdl(): no file dialog" );
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > aPaths;
+
+ if ( ERRCODE_NONE == pFileDlg->GetError() )
+ {
+ aPaths = pFileDlg->GetMPath();
+ sal_Int32 lastCount = aPaths.getLength() - 1;
+ INetURLObject aObj( aPaths.getArray()[ lastCount ] );
+
+ aObj.removeSegment();
+ aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
+ }
+
+ sal_Int32 nCount = aPaths.getLength();
+ if ( 1 == nCount )
+ {
+ String aPath = String( aPaths.getArray()[0] );
+ if ( aPath.Len() && !aMgr.CopyFrom( pFocusBox, m_nRegion, m_nIndex, aPath ) )
+ {
+ String aText( SfxResId( STR_ERROR_COPY_TEMPLATE ) );
+ aText.SearchAndReplaceAscii( "$1", aPath );
+ ErrorBox( pDialog, WB_OK, aText ).Execute();
+ }
+ }
+ else if ( nCount > 1 )
+ {
+ INetURLObject aPathObj( aPaths[0] );
+ aPathObj.setFinalSlash();
+ for ( USHORT i = 1; i < nCount; ++i )
+ {
+ if ( 1 == i )
+ aPathObj.Append( aPaths[i] );
+ else
+ aPathObj.setName( aPaths[i] );
+ String aPath = aPathObj.GetMainURL( INetURLObject::NO_DECODE );
+ if ( aPath.Len() && !aMgr.CopyFrom( pFocusBox, m_nRegion, m_nIndex, aPath ) )
+ {
+ String aText( SfxResId( STR_ERROR_COPY_TEMPLATE ) );
+ aText.SearchAndReplaceAscii( "$1", aPath );
+ ErrorBox( pDialog, WB_OK, aText ).Execute();
+ }
+ }
+ }
+
+ return 0L;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxOrganizeDlg_Impl, AddFilesHdl, sfx2::FileDialogHelper *, EMPTYARG )
+{
+ if ( ERRCODE_NONE == pFileDlg->GetError() )
+ {
+ String aPath = pFileDlg->GetPath();
+ aMgr.InsertFile( pFocusBox, aPath );
+ INetURLObject aObj( aPath );
+ aObj.removeSegment();
+ aObj.setFinalSlash();
+ aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
+ }
+
+ return 0L;
+}
+
+//-------------------------------------------------------------------------
+
+short SfxTemplateOrganizeDlg::Execute()
+
+/* [Beschreibung]
+
+ "Uberladene Execute- Methode; speichert gfs. "Anderungen an den
+ Dokumentvorlagen
+ (SV-Methode)
+
+*/
+
+{
+ const short nRet = ModalDialog::Execute();
+ if(RET_CANCEL != nRet)
+ {
+ pImp->aMgr.SaveAll(this);
+ SfxTemplateDialog* pTemplDlg = SFX_APP()->GetTemplateDialog();
+ if(pTemplDlg)
+ pTemplDlg->Update();
+ }
+ return nRet;
+}
+
+
+//-------------------------------------------------------------------------
+
+SfxTemplateOrganizeDlg::SfxTemplateOrganizeDlg(Window * pParent,
+ SfxDocumentTemplates *pTempl)
+: ModalDialog( pParent, SfxResId(DLG_ORGANIZE)),
+ pImp( new SfxOrganizeDlg_Impl(this, pTempl) )
+
+/* [Beschreibung]
+
+ Konstruktor
+
+*/
+{
+ FreeResource();
+}
+
+//-------------------------------------------------------------------------
+
+SfxTemplateOrganizeDlg::~SfxTemplateOrganizeDlg()
+{
+ GetpApp()->RemoveAccel(&pImp->aEditAcc);
+ delete pImp->pPrt;
+ delete pImp;
+}
+
diff --git a/sfx2/source/doc/docvor.hrc b/sfx2/source/doc/docvor.hrc
new file mode 100644
index 000000000000..842aa73fb8a3
--- /dev/null
+++ b/sfx2/source/doc/docvor.hrc
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#define IMG_OPENED_FOLDER 2
+#define IMG_CLOSED_FOLDER 1
+#define IMG_OPENED_DOC 3
+#define IMG_CLOSED_DOC 4
+#define IMG_OPENED_FOLDER_HC 5
+#define IMG_CLOSED_FOLDER_HC 6
+#define IMG_OPENED_DOC_HC 7
+#define IMG_CLOSED_DOC_HC 8
+
+#define ACC_EDIT 1
+#define ID_COPY 201
+#define ID_MOVE 202
+#define ID_DELETE 203
+#define ID_EDIT 204
+#define ID_COPY_FROM 211
+#define ID_EXPORT 221
+#define ID_RESCAN 220
+#define ID_COPY_TO 210
+#define ID_NEW 200
+#define ID_PRINT 240
+#define ID_PRINTER_SETUP 2341
+
+#define ID_DEFAULT_TEMPLATE 300
+#define ID_RESET_DEFAULT_TEMPLATE 301
+//!!! dont use the ids from 302 to 350, we need them as dynamic ids
+#define ID_RESET_DEFAULT_TEMPLATE_END (ID_RESET_DEFAULT_TEMPLATE+49)
+
+#define LB_RIGHT_TYP 11
+#define LB_RIGHT 10
+#define LB_LEFT_TYP 2
+#define BTN_EDIT 105
+#define BTN_FILES 3
+#define BTN_ADDRESSTEMPLATE 4
+#define LB_LEFT 1
+#define FT_DEFAULT_TEMPLATE_LABEL 20
+#define FT_DEFAULT_TEMPLATE 21
+#define BTN_HELP 100
+
+#ifdef BTN_OK
+#undef BTN_OK
+#endif
+#define BTN_OK 100
+
+#ifdef BTN_CANCEL
+#undef BTN_CANCEL
+#endif
+#define BTN_CANCEL 101
+
diff --git a/sfx2/source/doc/docvor.src b/sfx2/source/doc/docvor.src
new file mode 100644
index 000000000000..80ebed8b1708
--- /dev/null
+++ b/sfx2/source/doc/docvor.src
@@ -0,0 +1,320 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+ // include ---------------------------------------------------------------
+#include <sfx2/sfx.hrc>
+#include "doc.hrc"
+#include "docvor.hrc"
+#include "helpid.hrc"
+// pragma ----------------------------------------------------------------
+
+// DLG_ORGANIZE ----------------------------------------------------------
+
+#define MASKCOLOR MaskColor = Color { Red = 0xFFFF ; Green = 0x0000 ; Blue = 0xFFFF ; }
+
+ModalDialog DLG_ORGANIZE
+{
+ HelpId = CMD_SID_ORGANIZER ;
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 271 , 162 ) ;
+ Text [ en-US ] = "Template Management" ;
+ Moveable = TRUE ;
+ HelpButton BTN_HELP
+ {
+ Pos = MAP_APPFONT ( 205 , 43 ) ;
+ Size = MAP_APPFONT ( 60 , 14 ) ;
+ TabStop = TRUE ;
+ };
+ OKButton BTN_OK
+ {
+ Pos = MAP_APPFONT ( 205 , 6 ) ;
+ Size = MAP_APPFONT ( 60 , 14 ) ;
+ /* ### ACHTUNG: Neuer Text in Resource? Schließen : Schlie˜en */
+ /* ### ACHTUNG: Neuer Text in Resource? Schließen : Schlie˜en */
+ Text [ en-US ] = "Close" ;
+ TabStop = TRUE ;
+ DefButton = TRUE ;
+ };
+ PushButton BTN_FILES
+ {
+ HelpID = "sfx2:PushButton:DLG_ORGANIZE:BTN_FILES";
+ Pos = MAP_APPFONT ( 205 , 143 ) ;
+ Size = MAP_APPFONT ( 60 , 14 ) ;
+ Text [ en-US ] = "~File..." ;
+ TabStop = TRUE ;
+ };
+ PushButton BTN_ADDRESSTEMPLATE
+ {
+ HelpID = "sfx2:PushButton:DLG_ORGANIZE:BTN_ADDRESSTEMPLATE";
+ Pos = MAP_APPFONT ( 205 , 124 ) ;
+ Size = MAP_APPFONT ( 60 , 14 ) ;
+ Text [ en-US ] = "~Address Book..." ;
+ };
+ ListBox LB_LEFT_TYP
+ {
+ HelpID = "sfx2:ListBox:DLG_ORGANIZE:LB_LEFT_TYP";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 3 , 144 ) ;
+ Size = MAP_APPFONT ( 94 , 55 ) ;
+ TabStop = TRUE ;
+ DropDown = TRUE ;
+ CurPos = 0 ;
+ StringList [ en-US ] =
+ {
+ < "Templates" ; Default ; > ;
+ < "Documents" ; Default ; > ;
+ };
+ };
+ ListBox LB_RIGHT_TYP
+ {
+ HelpID = "sfx2:ListBox:DLG_ORGANIZE:LB_RIGHT_TYP";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 103 , 144 ) ;
+ Size = MAP_APPFONT ( 94 , 55 ) ;
+ TabStop = TRUE ;
+ DropDown = TRUE ;
+ CurPos = 1 ;
+ StringList [ en-US ] =
+ {
+ < "Templates" ; Default ; > ;
+ < "Documents" ; Default ; > ;
+ };
+ };
+ Control LB_LEFT
+ {
+ HelpId = HID_CTL_ORGANIZER_LEFT ;
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 3 , 6 ) ;
+ Size = MAP_APPFONT ( 94 , 132 ) ;
+ TabStop = TRUE ;
+ ClipChildren = TRUE ;
+ };
+ Control LB_RIGHT
+ {
+ HelpId = HID_CTL_ORGANIZER_RIGHT ;
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 103 , 6 ) ;
+ Size = MAP_APPFONT ( 94 , 132 ) ;
+ TabStop = TRUE ;
+ ClipChildren = TRUE ;
+ };
+ Accelerator ACC_EDIT
+ {
+ ItemList =
+ {
+ AcceleratorItem
+ {
+ Identifier = ID_NEW ;
+ Key = KeyCode
+ {
+ Code = KEY_INSERT ;
+ };
+ };
+ AcceleratorItem
+ {
+ Identifier = ID_DELETE ;
+ Key = KeyCode
+ {
+ Code = KEY_DELETE ;
+ };
+ };
+ };
+ };
+ MenuButton BTN_EDIT
+ {
+ HelpID = "sfx2:MenuButton:DLG_ORGANIZE:BTN_EDIT";
+ Pos = MAP_APPFONT ( 205 , 23 ) ;
+ Size = MAP_APPFONT ( 60 , 14 ) ;
+ Text [ en-US ] = "Commands" ;
+ TabStop = TRUE ;
+ ButtonMenu = Menu
+ {
+ ItemList =
+ {
+ MenuItem
+ {
+ Identifier = ID_NEW ;
+ HelpId = HID_ORGANIZE_NEW ;
+ Text [ en-US ] = "~New" ;
+ AccelKey = KeyCode
+ {
+ Code = KEY_INSERT ;
+ };
+ };
+ MenuItem
+ {
+ Identifier = ID_DELETE ;
+ HelpId = HID_ORGANIZE_DELETE ;
+ /* ### ACHTUNG: Neuer Text in Resource? ~Löschen : ~L÷schen */
+ /* ### ACHTUNG: Neuer Text in Resource? ~Löschen : ~L÷schen */
+ Text [ en-US ] = "~Delete" ;
+ AccelKey = KeyCode
+ {
+ Code = KEY_DELETE ;
+ };
+ };
+ MenuItem
+ {
+ Identifier = ID_EDIT ;
+ HelpId = HID_ORGANIZE_EDIT ;
+ Text [ en-US ] = "~Edit" ;
+ };
+ MenuItem
+ {
+ Separator = TRUE ;
+ };
+ MenuItem
+ {
+ Identifier = ID_COPY_FROM ;
+ HelpId = HID_ORGANIZE_COPY_FROM ;
+ Text [ en-US ] = "Import Template..." ;
+ };
+ MenuItem
+ {
+ Identifier = ID_COPY_TO ;
+ HelpId = HID_ORGANIZE_COPY_TO ;
+ Text [ en-US ] = "Export Template..." ;
+ };
+ MenuItem
+ {
+ Separator = TRUE ;
+ };
+ MenuItem
+ {
+ Identifier = ID_PRINT ;
+ HelpId = HID_ORGANIZE_PRINT ;
+ Text [ en-US ] = "~Print" ;
+ };
+ MenuItem
+ {
+ Identifier = ID_PRINTER_SETUP ;
+ HelpId = HID_ORGANIZE_PRINTER_SETUP ;
+ Text [ en-US ] = "Printer Settings..." ;
+ };
+ MenuItem
+ {
+ Separator = TRUE ;
+ };
+ MenuItem
+ {
+ Identifier = ID_RESCAN ;
+ HelpId = HID_ORGANIZE_RESCAN ;
+ Text [ en-US ] = "Update" ;
+ };
+ MenuItem
+ {
+ Separator = TRUE ;
+ };
+ MenuItem
+ {
+ Identifier = ID_DEFAULT_TEMPLATE ;
+ HelpId = HID_ORGANIZE_STDTEMPLATE_ADD ;
+ Text [ en-US ] = "Set As Default Template" ;
+ };
+ MenuItem
+ {
+ Identifier = ID_RESET_DEFAULT_TEMPLATE ;
+ HelpId = HID_ORGANIZE_STDTEMPLATE_DEL ;
+ Text [ en-US ] = "Reset Default Template" ;
+ };
+ };
+ };
+ };
+ Image IMG_OPENED_FOLDER
+ {
+ MASKCOLOR ;
+ ImageBitmap = Bitmap { File = "folderop.bmp" ; } ;
+ };
+ Image IMG_CLOSED_FOLDER
+ {
+ MASKCOLOR ;
+ ImageBitmap = Bitmap { File = "foldercl.bmp" ; } ;
+ };
+ Image IMG_OPENED_DOC
+ {
+ MASKCOLOR ;
+ ImageBitmap = Bitmap { File = "doccl.bmp" ; } ;
+ };
+ Image IMG_CLOSED_DOC
+ {
+ MASKCOLOR ;
+ ImageBitmap = Bitmap { File = "doccl.bmp" ; } ;
+ };
+ Image IMG_OPENED_FOLDER_HC
+ {
+ MASKCOLOR ;
+ ImageBitmap = Bitmap { File = "folderop_h.bmp" ; } ;
+ };
+ Image IMG_CLOSED_FOLDER_HC
+ {
+ MASKCOLOR ;
+ ImageBitmap = Bitmap { File = "foldercl_h.bmp" ; } ;
+ };
+ Image IMG_OPENED_DOC_HC
+ {
+ MASKCOLOR ;
+ ImageBitmap = Bitmap { File = "doccl_h.bmp" ; } ;
+ };
+ Image IMG_CLOSED_DOC_HC
+ {
+ MASKCOLOR ;
+ ImageBitmap = Bitmap { File = "doccl_h.bmp" ; } ;
+ };
+ /* FixedText FT_DEFAULT_TEMPLATE_LABEL
+ {
+ Pos = MAP_APPFONT ( 3 , 161 ) ;
+ Size = MAP_APPFONT ( 61 , 10 ) ;
+ Text [ en-US ] = "Default template:" ;
+ };
+ FixedText FT_DEFAULT_TEMPLATE
+ {
+ Pos = MAP_APPFONT ( 66 , 161 ) ;
+ Size = MAP_APPFONT ( 131 , 10 ) ;
+ };*/
+};
+ // ********************************************************************** EOF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/doc/frmdescr.cxx b/sfx2/source/doc/frmdescr.cxx
new file mode 100644
index 000000000000..04c3e78a7e7b
--- /dev/null
+++ b/sfx2/source/doc/frmdescr.cxx
@@ -0,0 +1,329 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sot/object.hxx>
+#include <tools/stream.hxx>
+#include <vcl/splitwin.hxx>
+#include <svl/itemset.hxx>
+#ifndef GCC
+#endif
+
+#include <sfx2/frmdescr.hxx>
+#include <sfx2/app.hxx>
+
+DBG_NAME(SfxFrameDescriptor);
+
+#define VERSION (USHORT) 3
+
+struct SfxFrameDescriptor_Impl
+{
+ Wallpaper* pWallpaper;
+ SfxItemSet* pArgs;
+ BOOL bEditable;
+
+ SfxFrameDescriptor_Impl() : pWallpaper( NULL ), pArgs( NULL ), bEditable( TRUE ) {}
+ ~SfxFrameDescriptor_Impl()
+ {
+ delete pWallpaper;
+ delete pArgs;
+ }
+};
+
+SfxFrameDescriptor::SfxFrameDescriptor() :
+ aMargin( -1, -1 ),
+ nWidth( 0L ),
+ eScroll( ScrollingAuto ),
+ eSizeSelector( SIZE_ABS ),
+ nHasBorder( BORDER_YES ),
+ nItemId( 0 ),
+ bResizeHorizontal( TRUE ),
+ bResizeVertical( TRUE ),
+ bHasUI( TRUE ),
+ bReadOnly( FALSE )
+{
+ DBG_CTOR(SfxFrameDescriptor, 0);
+
+ pImp = new SfxFrameDescriptor_Impl;
+}
+
+SfxFrameDescriptor::~SfxFrameDescriptor()
+{
+ DBG_DTOR(SfxFrameDescriptor, 0);
+ delete pImp;
+}
+
+SfxItemSet* SfxFrameDescriptor::GetArgs()
+{
+ if( !pImp->pArgs )
+ pImp->pArgs = new SfxAllItemSet( SFX_APP()->GetPool() );
+ return pImp->pArgs;
+}
+
+void SfxFrameDescriptor::SetURL( const String& rURL )
+{
+ aURL = INetURLObject(rURL);
+ SetActualURL( aURL );
+}
+
+void SfxFrameDescriptor::SetURL( const INetURLObject& rURL )
+{
+ aURL = rURL.GetMainURL( INetURLObject::DECODE_TO_IURI );
+ SetActualURL( aURL );
+}
+
+void SfxFrameDescriptor::SetActualURL( const String& rURL )
+{
+ aActualURL = INetURLObject(rURL);
+ if ( pImp->pArgs )
+ pImp->pArgs->ClearItem();
+}
+
+void SfxFrameDescriptor::SetActualURL( const INetURLObject& rURL )
+{
+ SetActualURL(String(rURL.GetMainURL( INetURLObject::DECODE_TO_IURI )));
+}
+
+void SfxFrameDescriptor::SetEditable( BOOL bSet )
+{
+ pImp->bEditable = bSet;
+}
+
+BOOL SfxFrameDescriptor::IsEditable() const
+{
+ return pImp->bEditable;
+}
+
+BOOL SfxFrameDescriptor::CompareOriginal( SfxFrameDescriptor& rDescr ) const
+{
+ if( aURL != rDescr.aURL )
+ return FALSE;
+ else
+ return TRUE;
+}
+
+BOOL SfxFrameDescriptor::CheckContent() const
+{
+ BOOL bRet = !( aURL == aActualURL );
+ return bRet;
+}
+
+void SfxFrameDescriptor::UnifyContent( BOOL bTakeActual )
+{
+ if ( bTakeActual )
+ aURL = aActualURL;
+ else
+ aActualURL = aURL;
+}
+
+SfxFrameDescriptor* SfxFrameDescriptor::Clone( BOOL bWithIds ) const
+{
+ SfxFrameDescriptor *pFrame = new SfxFrameDescriptor;
+
+ pFrame->aURL = aURL;
+ pFrame->aActualURL = aActualURL;
+ pFrame->aName = aName;
+ pFrame->aMargin = aMargin;
+ pFrame->nWidth = nWidth;
+ pFrame->eSizeSelector = eSizeSelector;
+ pFrame->eScroll = eScroll;
+ pFrame->bResizeHorizontal = bResizeHorizontal;
+ pFrame->bResizeVertical = bResizeVertical;
+ pFrame->nHasBorder = nHasBorder;
+ pFrame->bHasUI = bHasUI;
+ pFrame->SetReadOnly( IsReadOnly() );
+ pFrame->SetEditable( IsEditable() );
+ if ( pImp->pWallpaper )
+ pFrame->pImp->pWallpaper = new Wallpaper( *pImp->pWallpaper );
+ if( pImp->pArgs )
+ {
+ // Aktuell ist im Clone von SfxAllItemSets noch ein Bug...
+ pFrame->pImp->pArgs = new SfxAllItemSet( SFX_APP()->GetPool() );
+ pFrame->pImp->pArgs->Put(*pImp->pArgs);
+ }
+
+ if ( bWithIds )
+ pFrame->nItemId = nItemId;
+ else
+ pFrame->nItemId = 0;
+
+ return pFrame;
+}
+
+USHORT SfxFrameDescriptor::GetWinBits() const
+{
+ USHORT nBits = 0;
+ if ( eSizeSelector == SIZE_REL )
+ nBits |= SWIB_RELATIVESIZE;
+ if ( eSizeSelector == SIZE_PERCENT )
+ nBits |= SWIB_PERCENTSIZE;
+ if ( !IsResizable() )
+ nBits |= SWIB_FIXED;
+ if ( !nWidth )
+ nBits |= SWIB_INVISIBLE;
+ return nBits;
+}
+
+BOOL SfxFrameDescriptor::HasFrameBorder() const
+{
+ return (nHasBorder & BORDER_YES) != 0;
+}
+
+long SfxFrameDescriptor::GetSize() const
+{
+ return nWidth;
+}
+
+void SfxFrameDescriptor::TakeProperties( const SfxFrameProperties& rProp )
+{
+ aURL = aActualURL = INetURLObject(rProp.aURL);
+ aName = rProp.aName;
+ aMargin.Width() = rProp.lMarginWidth;
+ aMargin.Height() = rProp.lMarginHeight;
+ nWidth = rProp.lSize;
+ eScroll = rProp.eScroll;
+ eSizeSelector = rProp.eSizeSelector;
+ nHasBorder = rProp.bHasBorder ? BORDER_YES : BORDER_NO;
+ if ( rProp.bBorderSet )
+ nHasBorder |= BORDER_SET;
+ bResizeHorizontal = bResizeVertical = rProp.bResizable;
+}
+
+void SfxFrameDescriptor::SetWallpaper( const Wallpaper& rWallpaper )
+{
+ DELETEZ( pImp->pWallpaper );
+
+ if ( rWallpaper.GetStyle() != WALLPAPER_NULL )
+ pImp->pWallpaper = new Wallpaper( rWallpaper );
+}
+
+const Wallpaper* SfxFrameDescriptor::GetWallpaper() const
+{
+ return pImp->pWallpaper;
+}
+
+USHORT SfxFrameDescriptor::GetItemPos() const
+{
+ return USHRT_MAX;
+}
+
+
+SfxFrameProperties::SfxFrameProperties( const SfxFrameDescriptor *pD )
+ : aURL( pD->GetURL().GetMainURL( INetURLObject::DECODE_TO_IURI ) )
+ , aName( pD->GetName() )
+ , lMarginWidth( pD->GetMargin().Width() )
+ , lMarginHeight( pD->GetMargin().Height() )
+ , lSize( pD->GetWidth() )
+ , lSetSize( SIZE_NOT_SET )
+ , lFrameSpacing( SPACING_NOT_SET )
+ , lInheritedFrameSpacing( SPACING_NOT_SET )
+ , eScroll( pD->GetScrollingMode() )
+ , eSizeSelector( pD->GetSizeSelector() )
+ , eSetSizeSelector( SIZE_REL )
+ , bHasBorder( pD->HasFrameBorder() )
+ , bBorderSet( pD->IsFrameBorderSet() )
+ , bResizable( pD->IsResizable() )
+ , bSetResizable( FALSE )
+ , bIsRootSet( FALSE )
+ , bIsInColSet( FALSE )
+ , bHasBorderInherited( FALSE )
+ , pFrame( pD->Clone() )
+{
+ bBorderSet = TRUE;
+}
+
+SfxFrameProperties& SfxFrameProperties::operator =(
+ const SfxFrameProperties &rProp )
+{
+ aURL = rProp.aURL;
+ aName = rProp.aName;
+ lMarginWidth = rProp.lMarginWidth;
+ lMarginHeight = rProp.lMarginHeight;
+ lSize = rProp.lSize;
+ lSetSize = rProp.lSetSize;
+ lFrameSpacing = rProp.lFrameSpacing;
+ lInheritedFrameSpacing = rProp.lInheritedFrameSpacing;
+ eScroll = rProp.eScroll;
+ eSizeSelector = rProp.eSizeSelector;
+ eSetSizeSelector = rProp.eSetSizeSelector;
+ bHasBorder = rProp.bHasBorder;
+ bBorderSet = rProp.bBorderSet;
+ bResizable = rProp.bResizable;
+ bSetResizable = rProp.bSetResizable;
+ bIsRootSet = rProp.bIsRootSet;
+ bIsInColSet = rProp.bIsInColSet;
+ bHasBorderInherited = rProp.bHasBorderInherited;
+ pFrame = rProp.pFrame->Clone();
+ return *this;
+}
+
+int SfxFrameProperties::operator ==( const SfxFrameProperties& rProp ) const
+{
+ return aURL == rProp.aURL && aName == rProp.aName && lMarginWidth == rProp.lMarginWidth && lMarginHeight == rProp.lMarginHeight &&
+ lSize == rProp.lSize && eScroll == rProp.eScroll && eSizeSelector == rProp.eSizeSelector &&
+ lSetSize == rProp.lSetSize && lFrameSpacing == rProp.lFrameSpacing && eSetSizeSelector == rProp.eSetSizeSelector &&
+ bHasBorder == rProp.bHasBorder && bBorderSet == rProp.bBorderSet &&
+ bResizable == rProp.bResizable && bSetResizable == rProp.bSetResizable;
+}
+
+TYPEINIT1(SfxFrameDescriptorItem, SfxPoolItem);
+
+SfxFrameDescriptorItem::~SfxFrameDescriptorItem()
+{}
+
+int SfxFrameDescriptorItem::operator==( const SfxPoolItem& rAttr ) const
+{
+ DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
+
+ return aProperties == ((SfxFrameDescriptorItem&)rAttr).aProperties;
+}
+
+// -----------------------------------------------------------------------
+
+SfxPoolItem* SfxFrameDescriptorItem::Clone( SfxItemPool* ) const
+{
+ return new SfxFrameDescriptorItem( *this );
+}
+
+//------------------------------------------------------------------------
+
+SfxItemPresentation SfxFrameDescriptorItem::GetPresentation
+(
+ SfxItemPresentation /*ePres*/,
+ SfxMapUnit /*eCoreUnit*/,
+ SfxMapUnit /*ePresUnit*/,
+ XubString& rText,
+ const IntlWrapper *
+) const
+{
+ rText.Erase();
+ return SFX_ITEM_PRESENTATION_NONE;
+}
+
+
diff --git a/sfx2/source/doc/graphhelp.cxx b/sfx2/source/doc/graphhelp.cxx
new file mode 100644
index 000000000000..eff1554526ea
--- /dev/null
+++ b/sfx2/source/doc/graphhelp.cxx
@@ -0,0 +1,529 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifdef WNT
+
+#undef WB_LEFT
+#undef WB_RIGHT
+
+#define UINT64 USE_WIN_UINT64
+#define INT64 USE_WIN_INT64
+#define UINT32 USE_WIN_UINT32
+#define INT32 USE_WIN_INT32
+
+#include <tools/presys.h>
+#if defined _MSC_VER
+#pragma warning(push, 1)
+#endif
+#include <windows.h>
+#if defined _MSC_VER
+#pragma warning(pop)
+#endif
+#include <tools/postsys.h>
+
+#undef UINT64
+#undef INT64
+#undef UINT32
+#undef INT32
+
+#endif
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/datatransfer/XTransferable.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/graphic/XGraphicProvider.hpp>
+#include <com/sun/star/graphic/XGraphic.hpp>
+#include <com/sun/star/io/XStream.hpp>
+
+
+#include <osl/thread.h>
+#include <vcl/gdimtf.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/cvtgrf.hxx>
+#include <vcl/outdev.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/bitmapex.hxx>
+#include <vcl/salbtype.hxx>
+
+#include <tools/stream.hxx>
+#include <unotools/tempfile.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/streamwrap.hxx>
+#include <comphelper/processfactory.hxx>
+
+
+#include "sfx2/sfxresid.hxx"
+#include "graphhelp.hxx"
+#include "doc.hrc"
+
+using namespace ::com::sun::star;
+
+#define THUMBNAIL_RESOLUTION 256
+
+//---------------------------------------------------------------
+// static
+SvMemoryStream* GraphicHelper::getFormatStrFromGDI_Impl( const GDIMetaFile* pGDIMeta, sal_uInt32 nFormat )
+{
+ SvMemoryStream* pResult = NULL;
+ if ( pGDIMeta )
+ {
+ SvMemoryStream* pStream = new SvMemoryStream( 65535, 65535 );
+ if ( pStream )
+ {
+ Graphic aGraph( *pGDIMeta );
+ if ( GraphicConverter::Export( *pStream, aGraph, nFormat ) == 0 )
+ pResult = pStream;
+ else
+ delete pStream;
+ }
+ }
+
+ return pResult;
+}
+
+//---------------------------------------------------------------
+// static
+void* GraphicHelper::getEnhMetaFileFromGDI_Impl( const GDIMetaFile* pGDIMeta )
+{
+ (void)pGDIMeta; // unused
+ void* pResult = NULL;
+
+#ifdef WNT
+ if ( pGDIMeta )
+ {
+ String aStr = ::rtl::OUString::createFromAscii( ".emf" );
+ ::utl::TempFile aTempFile( ::rtl::OUString(),
+ &aStr,
+ NULL,
+ sal_False );
+
+ ::rtl::OUString aMetaFile = aTempFile.GetFileName();
+ ::rtl::OUString aMetaURL = aTempFile.GetURL();
+ ::rtl::OString aWinFile = ::rtl::OUStringToOString( aMetaFile, osl_getThreadTextEncoding() );
+
+ SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aMetaURL, STREAM_STD_READWRITE );
+ if ( pStream )
+ {
+ Graphic aGraph( *pGDIMeta );
+ sal_Bool bFailed = (sal_Bool)GraphicConverter::Export( *pStream, aGraph, CVT_EMF );
+ pStream->Flush();
+ delete pStream;
+
+ if ( !bFailed )
+ pResult = GetEnhMetaFileA( aWinFile.getStr() );
+ }
+ }
+#endif
+
+ return pResult;
+}
+
+//---------------------------------------------------------------
+// static
+void* GraphicHelper::getWinMetaFileFromGDI_Impl( const GDIMetaFile* pGDIMeta, const Size& aMetaSize )
+{
+ (void)pGDIMeta; // unused
+ (void)aMetaSize; // unused
+ void* pResult = NULL;
+
+#ifdef WNT
+ if ( pGDIMeta )
+ {
+ SvMemoryStream* pStream = new SvMemoryStream( 65535, 65535 );
+ if ( pStream )
+ {
+ Graphic aGraph( *pGDIMeta );
+ sal_Bool bFailed = (sal_Bool)GraphicConverter::Export( *pStream, aGraph, CVT_WMF );
+ pStream->Flush();
+ if ( !bFailed )
+ {
+ sal_Int32 nLength = pStream->Seek( STREAM_SEEK_TO_END );
+ if ( nLength > 22 )
+ {
+ HMETAFILE hMeta = SetMetaFileBitsEx( nLength - 22,
+ ( reinterpret_cast< const sal_uChar*>( pStream->GetData() ) ) + 22 );
+
+ if ( hMeta )
+ {
+ HGLOBAL hMemory = GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, sizeof( METAFILEPICT ) );
+
+ if ( hMemory )
+ {
+ METAFILEPICT* pMF = (METAFILEPICT*)GlobalLock( hMemory );
+
+ pMF->hMF = hMeta;
+ pMF->mm = MM_ANISOTROPIC;
+
+ MapMode aMetaMode = pGDIMeta->GetPrefMapMode();
+ MapMode aWinMode( MAP_100TH_MM );
+
+ if ( aWinMode == pGDIMeta->GetPrefMapMode() )
+ {
+ pMF->xExt = aMetaSize.Width();
+ pMF->yExt = aMetaSize.Height();
+ }
+ else
+ {
+ Size aWinSize = OutputDevice::LogicToLogic( Size( aMetaSize.Width(), aMetaSize.Height() ),
+ pGDIMeta->GetPrefMapMode(),
+ aWinMode );
+ pMF->xExt = aWinSize.Width();
+ pMF->yExt = aWinSize.Height();
+ }
+
+ GlobalUnlock( hMemory );
+ pResult = (void*)hMemory;
+ }
+ else
+ DeleteMetaFile( hMeta );
+ }
+ }
+ }
+
+ delete pStream;
+ }
+ }
+
+#endif
+
+
+ return pResult;
+}
+
+//---------------------------------------------------------------
+// static
+sal_Bool GraphicHelper::supportsMetaFileHandle_Impl()
+{
+#ifdef WNT
+ return sal_True;
+#else
+ return sal_False;
+#endif
+}
+
+//---------------------------------------------------------------
+// static
+sal_Bool GraphicHelper::mergeBitmaps_Impl( const BitmapEx& rBmpEx, const BitmapEx& rOverlay,
+ const Rectangle& rOverlayRect, BitmapEx& rReturn )
+{
+ // the implementation is provided by KA
+
+ Point aNullPt;
+ Rectangle aBmpRect( aNullPt, rBmpEx.GetSizePixel() );
+ VirtualDevice aVDev;
+
+ if( !rReturn.IsEmpty() )
+ rReturn.SetEmpty();
+
+ if( !rBmpEx.IsEmpty() && aVDev.SetOutputSizePixel( aBmpRect.GetSize() ) )
+ {
+ Rectangle aOverlayRect( rOverlayRect );
+
+ aOverlayRect.Intersection( aBmpRect );
+
+ if( rOverlay.IsEmpty() || rOverlayRect.IsEmpty() )
+ rReturn = rBmpEx;
+ else
+ {
+ aVDev.DrawBitmap( aNullPt, aVDev.GetOutputSizePixel(), rBmpEx.GetBitmap() );
+ aVDev.DrawBitmapEx( aOverlayRect.TopLeft(), aOverlayRect.GetSize(), rOverlay );
+
+ Bitmap aBmp( aVDev.GetBitmap( aNullPt, aVDev.GetOutputSizePixel() ) );
+ aBmp.Convert( BMP_CONVERSION_24BIT );
+
+ if( !rBmpEx.IsTransparent() )
+ rReturn = aBmp;
+ else
+ {
+ aVDev.DrawBitmap( aNullPt, aVDev.GetOutputSizePixel(), rBmpEx.GetMask() );
+ Bitmap aOverlayMergeBmp( aVDev.GetBitmap( aOverlayRect.TopLeft(), aOverlayRect.GetSize() ) );
+
+ if( rOverlay.IsTransparent() )
+ aVDev.DrawBitmap( aOverlayRect.TopLeft(), aOverlayRect.GetSize(), rOverlay.GetMask() );
+ else
+ {
+ aVDev.SetLineColor( COL_BLACK );
+ aVDev.SetFillColor( COL_BLACK );
+ aVDev.DrawRect( aOverlayRect);
+ }
+
+ aOverlayMergeBmp.CombineSimple( aVDev.GetBitmap( aOverlayRect.TopLeft(), aOverlayRect.GetSize() ), BMP_COMBINE_AND );
+ aVDev.DrawBitmap( aOverlayRect.TopLeft(), aOverlayRect.GetSize(), aOverlayMergeBmp );
+ rReturn = BitmapEx( aBmp, aVDev.GetBitmap( aNullPt, aVDev.GetOutputSizePixel() ) );
+ }
+ }
+ }
+
+ return !rReturn.IsEmpty();
+}
+
+
+//---------------------------------------------------------------
+// static
+sal_Bool GraphicHelper::createThumb_Impl( const GDIMetaFile& rMtf,
+ sal_uInt32 nMaximumExtent,
+ BitmapEx& rBmpEx,
+ const BitmapEx* pOverlay,
+ const Rectangle* pOverlayRect )
+{
+ // the implementation is provided by KA
+
+ // initialization seems to be complicated but is used to avoid rounding errors
+ VirtualDevice aVDev;
+ const Point aNullPt;
+ const Point aTLPix( aVDev.LogicToPixel( aNullPt, rMtf.GetPrefMapMode() ) );
+ const Point aBRPix( aVDev.LogicToPixel( Point( rMtf.GetPrefSize().Width() - 1, rMtf.GetPrefSize().Height() - 1 ), rMtf.GetPrefMapMode() ) );
+ Size aDrawSize( aVDev.LogicToPixel( rMtf.GetPrefSize(), rMtf.GetPrefMapMode() ) );
+ Size aSizePix( labs( aBRPix.X() - aTLPix.X() ) + 1, labs( aBRPix.Y() - aTLPix.Y() ) + 1 );
+ Point aPosPix;
+
+ if ( !rBmpEx.IsEmpty() )
+ rBmpEx.SetEmpty();
+
+ // determine size that has the same aspect ratio as image size and
+ // fits into the rectangle determined by nMaximumExtent
+ if ( aSizePix.Width() && aSizePix.Height() &&
+ ( sal::static_int_cast<sal_uInt32>(aSizePix.Width()) > nMaximumExtent ||
+ sal::static_int_cast<sal_uInt32>(aSizePix.Height()) > nMaximumExtent ) )
+ {
+ const Size aOldSizePix( aSizePix );
+ double fWH = static_cast< double >( aSizePix.Width() ) / aSizePix.Height();
+
+ if ( fWH <= 1.0 )
+ {
+ aSizePix.Width() = FRound( nMaximumExtent * fWH );
+ aSizePix.Height() = nMaximumExtent;
+ }
+ else
+ {
+ aSizePix.Width() = nMaximumExtent;
+ aSizePix.Height() = FRound( nMaximumExtent / fWH );
+ }
+
+ aDrawSize.Width() = FRound( ( static_cast< double >( aDrawSize.Width() ) * aSizePix.Width() ) / aOldSizePix.Width() );
+ aDrawSize.Height() = FRound( ( static_cast< double >( aDrawSize.Height() ) * aSizePix.Height() ) / aOldSizePix.Height() );
+ }
+
+ Size aFullSize;
+ Point aBackPosPix;
+ Rectangle aOverlayRect;
+
+ // calculate addigtional positions and sizes if an overlay image is used
+ if ( pOverlay )
+ {
+ aFullSize = Size( nMaximumExtent, nMaximumExtent );
+ aOverlayRect = Rectangle( aNullPt, aFullSize );
+
+ aOverlayRect.Intersection( pOverlayRect ? *pOverlayRect : Rectangle( aNullPt, pOverlay->GetSizePixel() ) );
+
+ if ( !aOverlayRect.IsEmpty() )
+ aBackPosPix = Point( ( nMaximumExtent - aSizePix.Width() ) >> 1, ( nMaximumExtent - aSizePix.Height() ) >> 1 );
+ else
+ pOverlay = NULL;
+ }
+ else
+ {
+ aFullSize = aSizePix;
+ pOverlay = NULL;
+ }
+
+ // draw image(s) into VDev and get resulting image
+ if ( aVDev.SetOutputSizePixel( aFullSize ) )
+ {
+ // draw metafile into VDev
+ const_cast< GDIMetaFile& >( rMtf ).WindStart();
+ const_cast< GDIMetaFile& >( rMtf ).Play( &aVDev, aBackPosPix, aDrawSize );
+
+ // draw overlay if neccessary
+ if ( pOverlay )
+ aVDev.DrawBitmapEx( aOverlayRect.TopLeft(), aOverlayRect.GetSize(), *pOverlay );
+
+ // get paint bitmap
+ Bitmap aBmp( aVDev.GetBitmap( aNullPt, aVDev.GetOutputSizePixel() ) );
+
+ // assure that we have a true color image
+ if ( aBmp.GetBitCount() != 24 )
+ aBmp.Convert( BMP_CONVERSION_24BIT );
+
+ rBmpEx = BitmapEx( aBmp );
+ }
+
+ return !rBmpEx.IsEmpty();
+}
+
+//---------------------------------------------------------------
+// static
+sal_Bool GraphicHelper::getThumbnailFormatFromGDI_Impl( GDIMetaFile* pMetaFile,
+ sal_Bool bSigned,
+ const uno::Reference< io::XStream >& xStream )
+{
+ sal_Bool bResult = sal_False;
+ SvStream* pStream = NULL;
+
+ if ( xStream.is() )
+ pStream = ::utl::UcbStreamHelper::CreateStream( xStream );
+
+ if ( pMetaFile && pStream && !pStream->GetError() )
+ {
+ BitmapEx aResultBitmap;
+ BitmapEx* pSignatureBitmap = NULL;
+
+ if ( bSigned )
+ pSignatureBitmap = new BitmapEx( SfxResId( BMP_SIGNATURE ) );
+
+ bResult = createThumb_Impl( *pMetaFile,
+ THUMBNAIL_RESOLUTION,
+ aResultBitmap,
+ pSignatureBitmap );
+ if ( bResult )
+ bResult = ( !aResultBitmap.IsEmpty()
+ && GraphicConverter::Export( *pStream, aResultBitmap, CVT_PNG ) == 0
+ && ( pStream->Flush(), !pStream->GetError() ) );
+
+ if ( pSignatureBitmap )
+ delete pSignatureBitmap;
+
+ delete pStream;
+ }
+
+ return bResult;
+}
+
+//---------------------------------------------------------------
+// static
+sal_Bool GraphicHelper::getSignedThumbnailFormatFromBitmap_Impl( const BitmapEx& aBitmap,
+ const uno::Reference< io::XStream >& xStream )
+{
+ sal_Bool bResult = sal_False;
+ SvStream* pStream = NULL;
+
+ if ( xStream.is() )
+ pStream = ::utl::UcbStreamHelper::CreateStream( xStream );
+
+ if ( pStream && !pStream->GetError() )
+ {
+ BitmapEx aResultBitmap;
+ BitmapEx aSignatureBitmap( SfxResId( BMP_SIGNATURE ) );
+
+ bResult = mergeBitmaps_Impl( aBitmap,
+ aSignatureBitmap,
+ Rectangle( Point(), aBitmap.GetSizePixel() ),
+ aResultBitmap );
+
+ if ( bResult )
+ {
+ bResult = ( !aResultBitmap.IsEmpty()
+ && GraphicConverter::Export( *pStream, aResultBitmap, CVT_PNG ) == 0
+ && ( pStream->Flush(), !pStream->GetError() ) );
+ }
+
+ delete pStream;
+ }
+
+ return bResult;
+}
+
+//---------------------------------------------------------------
+// static
+sal_Bool GraphicHelper::getThumbnailReplacement_Impl( sal_Int32 nResID, const uno::Reference< io::XStream >& xStream )
+{
+ sal_Bool bResult = sal_False;
+ if ( nResID && xStream.is() )
+ {
+ uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
+ if ( xServiceManager.is() )
+ {
+ try
+ {
+ uno::Reference< graphic::XGraphicProvider > xGraphProvider(
+ xServiceManager->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.graphic.GraphicProvider" ) ),
+ uno::UNO_QUERY );
+ if ( xGraphProvider.is() )
+ {
+ ::rtl::OUString aURL = ::rtl::OUString::createFromAscii( "private:resource/sfx/bitmapex/" );
+ aURL += ::rtl::OUString::valueOf( nResID );
+
+ uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
+ aMediaProps[0].Name = ::rtl::OUString::createFromAscii( "URL" );
+ aMediaProps[0].Value <<= aURL;
+
+ uno::Reference< graphic::XGraphic > xGraphic = xGraphProvider->queryGraphic( aMediaProps );
+ if ( xGraphic.is() )
+ {
+ uno::Sequence< beans::PropertyValue > aStoreProps( 2 );
+ aStoreProps[0].Name = ::rtl::OUString::createFromAscii( "OutputStream" );
+ aStoreProps[0].Value <<= xStream;
+ aStoreProps[1].Name = ::rtl::OUString::createFromAscii( "MimeType" );
+ aStoreProps[1].Value <<= ::rtl::OUString::createFromAscii( "image/png" );
+
+ xGraphProvider->storeGraphic( xGraphic, aStoreProps );
+ bResult = sal_True;
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ }
+
+ return bResult;
+}
+
+//---------------------------------------------------------------
+// static
+sal_uInt16 GraphicHelper::getThumbnailReplacementIDByFactoryName_Impl( const ::rtl::OUString& aFactoryShortName, sal_Bool /*bIsTemplate*/ )
+{
+ sal_uInt16 nResult = 0;
+
+ if ( aFactoryShortName.equalsAscii( "scalc" ) )
+ {
+ nResult = BMP_128X128_CALC_DOC;
+ }
+ else if ( aFactoryShortName.equalsAscii( "sdraw" ) )
+ {
+ nResult = BMP_128X128_DRAW_DOC;
+ }
+ else if ( aFactoryShortName.equalsAscii( "simpress" ) )
+ {
+ nResult = BMP_128X128_IMPRESS_DOC;
+ }
+ else if ( aFactoryShortName.equalsAscii( "smath" ) )
+ {
+ nResult = BMP_128X128_MATH_DOC;
+ }
+ else if ( aFactoryShortName.equalsAscii( "swriter" ) || aFactoryShortName.compareToAscii( "swriter/", 8 ) == 0 )
+ {
+ nResult = BMP_128X128_WRITER_DOC;
+ }
+
+ return nResult;
+}
+
diff --git a/sfx2/source/doc/graphhelp.hxx b/sfx2/source/doc/graphhelp.hxx
new file mode 100644
index 000000000000..22f8ad5a115e
--- /dev/null
+++ b/sfx2/source/doc/graphhelp.hxx
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/io/XStream.hpp>
+
+#include <rtl/ustring.hxx>
+class SvMemoryStream;
+class GDIMetaFile;
+class BitmapEx;
+
+class GraphicHelper
+{
+
+ static sal_Bool mergeBitmaps_Impl( const BitmapEx& rBmpEx, const BitmapEx& rOverlay,
+ const Rectangle& rOverlayRect, BitmapEx& rReturn );
+
+ static sal_Bool createThumb_Impl( const GDIMetaFile& rMtf,
+ sal_uInt32 nMaximumExtent,
+ BitmapEx& rBmpEx,
+ const BitmapEx* pOverlay = NULL,
+ const Rectangle* pOverlayRect = NULL );
+
+public:
+
+ static SvMemoryStream* getFormatStrFromGDI_Impl( const GDIMetaFile* pGDIMeta, sal_uInt32 nFormat );
+
+ static void* getEnhMetaFileFromGDI_Impl( const GDIMetaFile* pGDIMeta );
+
+ static void* getWinMetaFileFromGDI_Impl( const GDIMetaFile* pGDIMeta, const Size& aMetaSize );
+
+ static sal_Bool supportsMetaFileHandle_Impl();
+
+ static sal_Bool getThumbnailFormatFromGDI_Impl(
+ GDIMetaFile* pMetaFile,
+ sal_Bool bSigned,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream );
+
+ static sal_Bool getSignedThumbnailFormatFromBitmap_Impl(
+ const BitmapEx& aBitmap,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream );
+
+ static sal_uInt16 getThumbnailReplacementIDByFactoryName_Impl( const ::rtl::OUString& aFactoryShortName,
+ sal_Bool bIsTemplate );
+
+ static sal_Bool getThumbnailReplacement_Impl(
+ sal_Int32 nResID,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream );
+
+};
+
diff --git a/sfx2/source/doc/graphhelp.src b/sfx2/source/doc/graphhelp.src
new file mode 100644
index 000000000000..1936a8460d25
--- /dev/null
+++ b/sfx2/source/doc/graphhelp.src
@@ -0,0 +1,59 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "doc.hrc"
+
+Bitmap BMP_SIGNATURE
+{
+ File = "signet.png";
+};
+
+Bitmap BMP_128X128_CALC_DOC
+{
+ File = "128x128_calc_doc-p.png";
+};
+
+Bitmap BMP_128X128_DRAW_DOC
+{
+ File = "128x128_draw_doc-p.png";
+};
+
+Bitmap BMP_128X128_IMPRESS_DOC
+{
+ File = "128x128_impress_doc-p.png";
+};
+
+Bitmap BMP_128X128_MATH_DOC
+{
+ File = "128x128_math_doc-p.png";
+};
+
+Bitmap BMP_128X128_WRITER_DOC
+{
+ File = "128x128_writer_doc-p.png";
+};
+
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
new file mode 100644
index 000000000000..bceb7477a61e
--- /dev/null
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -0,0 +1,1802 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
+#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
+#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
+#include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
+#include <com/sun/star/view/XSelectionSupplier.hpp>
+#include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/document/XDocumentInfoSupplier.hpp>
+#include <com/sun/star/document/XDocumentInfo.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/util/DateTime.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/frame/XStorable2.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XTitle.hpp>
+#include <com/sun/star/util/XModifyListener.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/util/XModifyBroadcaster.hpp>
+
+#include <com/sun/star/util/XCloneable.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/io/IOException.hpp>
+
+#include "guisaveas.hxx"
+
+#include <unotools/pathoptions.hxx>
+#include <unotools/pathoptions.hxx>
+#include <svl/itemset.hxx>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <unotools/useroptions.hxx>
+#include <unotools/saveopt.hxx>
+#include <tools/debug.hxx>
+#include <tools/urlobj.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/configurationhelper.hxx>
+#include <comphelper/mimeconfighelper.hxx>
+#include <vcl/msgbox.hxx>
+#include <vcl/window.hxx>
+#include <toolkit/awt/vclxwindow.hxx>
+
+#include <sfx2/sfxsids.hrc>
+#include <doc.hrc>
+#include <sfx2/sfxresid.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/filedlghelper.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/dinfdlg.hxx>
+#include <sfx2/request.hxx>
+#include <sfxtypes.hxx>
+#include "alienwarn.hxx"
+
+#include "../appl/app.hrc"
+
+#define DOCPROPSNUM 17
+
+// flags that specify requested operation
+#define EXPORT_REQUESTED 1
+#define PDFEXPORT_REQUESTED 2
+#define PDFDIRECTEXPORT_REQUESTED 4
+#define WIDEEXPORT_REQUESTED 8
+#define SAVE_REQUESTED 16
+#define SAVEAS_REQUESTED 32
+
+// possible statuses of save operation
+#define STATUS_NO_ACTION 0
+#define STATUS_SAVE 1
+#define STATUS_SAVEAS 2
+#define STATUS_SAVEAS_STANDARDNAME 3
+
+const ::rtl::OUString aFilterNameString = ::rtl::OUString::createFromAscii( "FilterName" );
+const ::rtl::OUString aFilterOptionsString = ::rtl::OUString::createFromAscii( "FilterOptions" );
+const ::rtl::OUString aFilterDataString = ::rtl::OUString::createFromAscii( "FilterData" );
+const ::rtl::OUString aFilterFlagsString = ::rtl::OUString::createFromAscii( "FilterFlags" );
+
+using namespace ::com::sun::star;
+
+namespace {
+//-------------------------------------------------------------------------
+static sal_uInt16 getSlotIDFromMode( sal_Int8 nStoreMode )
+{
+ // This is a temporary hardcoded solution must be removed when
+ // dialogs do not need parameters in SidSet representation any more
+
+ sal_uInt16 nResult = 0;
+ if ( nStoreMode == EXPORT_REQUESTED )
+ nResult = SID_EXPORTDOC;
+ else if ( nStoreMode == ( EXPORT_REQUESTED | PDFEXPORT_REQUESTED ) )
+ nResult = SID_EXPORTDOCASPDF;
+ else if ( nStoreMode == ( EXPORT_REQUESTED | PDFEXPORT_REQUESTED | PDFDIRECTEXPORT_REQUESTED ) )
+ nResult = SID_DIRECTEXPORTDOCASPDF;
+ else if ( nStoreMode == SAVEAS_REQUESTED || nStoreMode == ( EXPORT_REQUESTED | WIDEEXPORT_REQUESTED ) )
+ nResult = SID_SAVEASDOC;
+ else {
+ DBG_ASSERT( sal_False, "Unacceptable slot name is provided!\n" );
+ }
+
+ return nResult;
+}
+
+//-------------------------------------------------------------------------
+static sal_uInt8 getStoreModeFromSlotName( const ::rtl::OUString& aSlotName )
+{
+ sal_uInt8 nResult = 0;
+ if ( aSlotName.equalsAscii( "ExportTo" ) )
+ nResult = EXPORT_REQUESTED;
+ else if ( aSlotName.equalsAscii( "ExportToPDF" ) )
+ nResult = EXPORT_REQUESTED | PDFEXPORT_REQUESTED;
+ else if ( aSlotName.equalsAscii( "ExportDirectToPDF" ) )
+ nResult = EXPORT_REQUESTED | PDFEXPORT_REQUESTED | PDFDIRECTEXPORT_REQUESTED;
+ else if ( aSlotName.equalsAscii( "Save" ) )
+ nResult = SAVE_REQUESTED;
+ else if ( aSlotName.equalsAscii( "SaveAs" ) )
+ nResult = SAVEAS_REQUESTED;
+ else
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ ERRCODE_IO_INVALIDPARAMETER );
+
+ return nResult;
+}
+
+//-------------------------------------------------------------------------
+static sal_Int32 getMustFlags( sal_Int8 nStoreMode )
+{
+ return ( SFX_FILTER_EXPORT
+ | ( ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) ) ? 0 : SFX_FILTER_IMPORT ) );
+}
+
+//-------------------------------------------------------------------------
+static sal_Int32 getDontFlags( sal_Int8 nStoreMode )
+{
+ return ( SFX_FILTER_INTERNAL
+ | SFX_FILTER_NOTINFILEDLG
+ | ( ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) ) ? SFX_FILTER_IMPORT : 0 ) );
+}
+
+//=========================================================================
+// class DocumentSettingsGuard
+//=========================================================================
+
+class DocumentSettingsGuard
+{
+ uno::Reference< beans::XPropertySet > m_xDocumentSettings;
+ sal_Bool m_bPreserveReadOnly;
+ sal_Bool m_bReadOnlySupported;
+
+ sal_Bool m_bRestoreSettings;
+public:
+ DocumentSettingsGuard( const uno::Reference< frame::XModel >& xModel, sal_Bool bReadOnly, sal_Bool bRestore )
+ : m_bPreserveReadOnly( sal_False )
+ , m_bReadOnlySupported( sal_False )
+ , m_bRestoreSettings( bRestore )
+ {
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xDocSettingsSupplier( xModel, uno::UNO_QUERY_THROW );
+ m_xDocumentSettings.set(
+ xDocSettingsSupplier->createInstance(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.Settings" ) ) ),
+ uno::UNO_QUERY_THROW );
+
+ ::rtl::OUString aLoadReadonlyString( RTL_CONSTASCII_USTRINGPARAM( "LoadReadonly" ) );
+
+ try
+ {
+ m_xDocumentSettings->getPropertyValue( aLoadReadonlyString ) >>= m_bPreserveReadOnly;
+ m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( bReadOnly ) );
+ m_bReadOnlySupported = sal_True;
+ }
+ catch( uno::Exception& )
+ {}
+ }
+ catch( uno::Exception& )
+ {}
+
+ if ( ( bReadOnly && !m_bReadOnlySupported ) )
+ throw uno::RuntimeException(); // the user could provide the data, so it must be stored
+ }
+
+ ~DocumentSettingsGuard()
+ {
+ if ( m_bRestoreSettings )
+ {
+ ::rtl::OUString aLoadReadonlyString( RTL_CONSTASCII_USTRINGPARAM( "LoadReadonly" ) );
+
+ try
+ {
+ if ( m_bReadOnlySupported )
+ m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( m_bPreserveReadOnly ) );
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ASSERT( "Unexpected exception!" );
+ }
+ }
+ }
+};
+} // anonymous namespace
+
+//=========================================================================
+// class ModelData_Impl
+//=========================================================================
+class ModelData_Impl
+{
+ SfxStoringHelper* m_pOwner;
+ uno::Reference< frame::XModel > m_xModel;
+ uno::Reference< frame::XStorable > m_xStorable;
+ uno::Reference< frame::XStorable2 > m_xStorable2;
+ uno::Reference< util::XModifiable > m_xModifiable;
+
+ ::rtl::OUString m_aModuleName;
+ ::comphelper::SequenceAsHashMap* m_pDocumentPropsHM;
+ ::comphelper::SequenceAsHashMap* m_pModulePropsHM;
+
+ ::comphelper::SequenceAsHashMap m_aMediaDescrHM;
+
+ sal_Bool m_bRecommendReadOnly;
+
+public:
+ ModelData_Impl( SfxStoringHelper& aOwner,
+ const uno::Reference< frame::XModel >& xModel,
+ const uno::Sequence< beans::PropertyValue >& aMediaDescr );
+
+ ~ModelData_Impl();
+
+ void FreeDocumentProps();
+
+ uno::Reference< frame::XModel > GetModel();
+ uno::Reference< frame::XStorable > GetStorable();
+ uno::Reference< frame::XStorable2 > GetStorable2();
+ uno::Reference< util::XModifiable > GetModifiable();
+
+ ::comphelper::SequenceAsHashMap& GetMediaDescr() { return m_aMediaDescrHM; }
+
+ sal_Bool IsRecommendReadOnly() { return m_bRecommendReadOnly; }
+
+ const ::comphelper::SequenceAsHashMap& GetDocProps();
+
+ ::rtl::OUString GetModuleName();
+ const ::comphelper::SequenceAsHashMap& GetModuleProps();
+
+ void CheckInteractionHandler();
+
+
+ ::rtl::OUString GetDocServiceName();
+ uno::Sequence< beans::PropertyValue > GetDocServiceDefaultFilterCheckFlags( sal_Int32 nMust, sal_Int32 nDont );
+ uno::Sequence< beans::PropertyValue > GetDocServiceAnyFilter( sal_Int32 nMust, sal_Int32 nDont );
+ uno::Sequence< beans::PropertyValue > GetPreselectedFilter_Impl( sal_Int8 nStoreMode );
+ uno::Sequence< beans::PropertyValue > GetDocServiceDefaultFilter();
+
+ sal_Bool ExecuteFilterDialog_Impl( const ::rtl::OUString& aFilterName );
+
+ sal_Int8 CheckSaveAcceptable( sal_Int8 nCurStatus );
+ sal_Int8 CheckStateForSave();
+
+ sal_Int8 CheckFilter( const ::rtl::OUString& );
+
+ sal_Bool CheckFilterOptionsDialogExistence();
+
+ sal_Bool OutputFileDialog( sal_Int8 nStoreMode,
+ const ::comphelper::SequenceAsHashMap& aPreselectedFilterPropsHM,
+ sal_Bool bSetStandardName,
+ ::rtl::OUString& aSuggestedName,
+ sal_Bool bPreselectPassword,
+ const ::rtl::OUString& aSuggestedDir,
+ sal_Int16 nDialog,
+ const ::rtl::OUString& rStandardDir,
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList
+ );
+
+ sal_Bool ShowDocumentInfoDialog();
+
+ ::rtl::OUString GetReccomendedDir( const ::rtl::OUString& aSuggestedDir,
+ const sfx2::FileDialogHelper::Context& aCtxt );
+ ::rtl::OUString GetReccomendedName( const ::rtl::OUString& aSuggestedName,
+ const ::rtl::OUString& aTypeName );
+
+};
+
+//-------------------------------------------------------------------------
+ModelData_Impl::ModelData_Impl( SfxStoringHelper& aOwner,
+ const uno::Reference< frame::XModel >& xModel,
+ const uno::Sequence< beans::PropertyValue >& aMediaDescr )
+: m_pOwner( &aOwner )
+, m_xModel( xModel )
+, m_pDocumentPropsHM( NULL )
+, m_pModulePropsHM( NULL )
+, m_aMediaDescrHM( aMediaDescr )
+, m_bRecommendReadOnly( sal_False )
+{
+ CheckInteractionHandler();
+}
+
+//-------------------------------------------------------------------------
+ModelData_Impl::~ModelData_Impl()
+{
+ FreeDocumentProps();
+ if ( m_pDocumentPropsHM )
+ delete m_pDocumentPropsHM;
+
+ if ( m_pModulePropsHM )
+ delete m_pModulePropsHM;
+}
+
+//-------------------------------------------------------------------------
+void ModelData_Impl::FreeDocumentProps()
+{
+ if ( m_pDocumentPropsHM )
+ {
+ delete m_pDocumentPropsHM;
+ m_pDocumentPropsHM = NULL;
+ }
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< frame::XModel > ModelData_Impl::GetModel()
+{
+ if ( !m_xModel.is() )
+ throw uno::RuntimeException();
+
+ return m_xModel;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< frame::XStorable > ModelData_Impl::GetStorable()
+{
+ if ( !m_xStorable.is() )
+ {
+ m_xStorable = uno::Reference< frame::XStorable >( m_xModel, uno::UNO_QUERY );
+ if ( !m_xStorable.is() )
+ throw uno::RuntimeException();
+ }
+
+ return m_xStorable;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< frame::XStorable2 > ModelData_Impl::GetStorable2()
+{
+ if ( !m_xStorable2.is() )
+ {
+ m_xStorable2 = uno::Reference< frame::XStorable2 >( m_xModel, uno::UNO_QUERY );
+ if ( !m_xStorable2.is() )
+ throw uno::RuntimeException();
+ }
+
+ return m_xStorable2;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< util::XModifiable > ModelData_Impl::GetModifiable()
+{
+ if ( !m_xModifiable.is() )
+ {
+ m_xModifiable = uno::Reference< util::XModifiable >( m_xModel, uno::UNO_QUERY );
+ if ( !m_xModifiable.is() )
+ throw uno::RuntimeException();
+ }
+
+ return m_xModifiable;
+}
+
+//-------------------------------------------------------------------------
+const ::comphelper::SequenceAsHashMap& ModelData_Impl::GetDocProps()
+{
+ if ( !m_pDocumentPropsHM )
+ m_pDocumentPropsHM = new ::comphelper::SequenceAsHashMap( GetModel()->getArgs() );
+
+ return *m_pDocumentPropsHM;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString ModelData_Impl::GetModuleName()
+{
+ if ( !m_aModuleName.getLength() )
+ {
+ m_aModuleName = m_pOwner->GetModuleManager()->identify(
+ uno::Reference< uno::XInterface >( m_xModel, uno::UNO_QUERY ) );
+ if ( !m_aModuleName.getLength() )
+ throw uno::RuntimeException(); // TODO:
+ }
+ return m_aModuleName;
+}
+
+//-------------------------------------------------------------------------
+const ::comphelper::SequenceAsHashMap& ModelData_Impl::GetModuleProps()
+{
+ if ( !m_pModulePropsHM )
+ {
+ uno::Sequence< beans::PropertyValue > aModuleProps;
+ m_pOwner->GetNamedModuleManager()->getByName( GetModuleName() ) >>= aModuleProps;
+ if ( !aModuleProps.getLength() )
+ throw uno::RuntimeException(); // TODO;
+ m_pModulePropsHM = new ::comphelper::SequenceAsHashMap( aModuleProps );
+ }
+
+ return *m_pModulePropsHM;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString ModelData_Impl::GetDocServiceName()
+{
+ return GetModuleProps().getUnpackedValueOrDefault(::rtl::OUString::createFromAscii( "ooSetupFactoryDocumentService" ), ::rtl::OUString());
+}
+
+//-------------------------------------------------------------------------
+void ModelData_Impl::CheckInteractionHandler()
+{
+ ::comphelper::SequenceAsHashMap::const_iterator aInteractIter =
+ m_aMediaDescrHM.find( ::rtl::OUString::createFromAscii( "InteractionHandler" ) );
+
+ if ( aInteractIter == m_aMediaDescrHM.end() )
+ {
+ try {
+ m_aMediaDescrHM[ ::rtl::OUString::createFromAscii( "InteractionHandler" ) ]
+ <<= uno::Reference< task::XInteractionHandler >(
+ m_pOwner->GetServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ),
+ uno::UNO_QUERY );
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ else
+ {
+ uno::Reference< task::XInteractionHandler > xInteract;
+ DBG_ASSERT( ( aInteractIter->second >>= xInteract ) && xInteract.is(), "Broken interaction handler is provided!\n" );
+ }
+}
+
+//-------------------------------------------------------------------------
+uno::Sequence< beans::PropertyValue > ModelData_Impl::GetDocServiceDefaultFilter()
+{
+ uno::Sequence< beans::PropertyValue > aProps;
+
+ ::rtl::OUString aFilterName = GetModuleProps().getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "ooSetupFactoryDefaultFilter" ),
+ ::rtl::OUString() );
+
+ m_pOwner->GetFilterConfiguration()->getByName( aFilterName ) >>= aProps;
+
+ return aProps;
+}
+
+//-------------------------------------------------------------------------
+uno::Sequence< beans::PropertyValue > ModelData_Impl::GetDocServiceDefaultFilterCheckFlags( sal_Int32 nMust,
+ sal_Int32 nDont )
+{
+ uno::Sequence< beans::PropertyValue > aFilterProps;
+ uno::Sequence< beans::PropertyValue > aProps = GetDocServiceDefaultFilter();
+ if ( aProps.getLength() )
+ {
+ ::comphelper::SequenceAsHashMap aFiltHM( aProps );
+ sal_Int32 nFlags = aFiltHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ),
+ (sal_Int32)0 );
+ if ( ( ( nFlags & nMust ) == nMust ) && !( nFlags & nDont ) )
+ aFilterProps = aProps;
+ }
+
+ return aFilterProps;
+}
+
+
+//-------------------------------------------------------------------------
+uno::Sequence< beans::PropertyValue > ModelData_Impl::GetDocServiceAnyFilter( sal_Int32 nMust, sal_Int32 nDont )
+{
+ uno::Sequence< beans::NamedValue > aSearchRequest( 1 );
+ aSearchRequest[0].Name = ::rtl::OUString::createFromAscii( "DocumentService" );
+ aSearchRequest[0].Value <<= GetDocServiceName();
+
+ return ::comphelper::MimeConfigurationHelper::SearchForFilter( m_pOwner->GetFilterQuery(), aSearchRequest, nMust, nDont );
+}
+
+//-------------------------------------------------------------------------
+uno::Sequence< beans::PropertyValue > ModelData_Impl::GetPreselectedFilter_Impl( sal_Int8 nStoreMode )
+{
+ uno::Sequence< beans::PropertyValue > aFilterProps;
+
+ sal_Int32 nMust = getMustFlags( nStoreMode );
+ sal_Int32 nDont = getDontFlags( nStoreMode );
+
+ if ( nStoreMode & PDFEXPORT_REQUESTED )
+ {
+ // Preselect PDF-Filter for EXPORT
+ uno::Sequence< beans::NamedValue > aSearchRequest( 2 );
+ aSearchRequest[0].Name = ::rtl::OUString::createFromAscii( "Type" );
+ aSearchRequest[0].Value <<= ::rtl::OUString::createFromAscii( "pdf_Portable_Document_Format" );
+ aSearchRequest[1].Name = ::rtl::OUString::createFromAscii( "DocumentService" );
+ aSearchRequest[1].Value <<= GetDocServiceName();
+
+ aFilterProps = ::comphelper::MimeConfigurationHelper::SearchForFilter( m_pOwner->GetFilterQuery(), aSearchRequest, nMust, nDont );
+ }
+ else
+ {
+ aFilterProps = GetDocServiceDefaultFilterCheckFlags( nMust, nDont );
+
+ if ( !aFilterProps.getLength() )
+ {
+ // the default filter was not faund, use just the first acceptable one
+ aFilterProps = GetDocServiceAnyFilter( nMust, nDont );
+ }
+ }
+
+ return aFilterProps;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool ModelData_Impl::ExecuteFilterDialog_Impl( const ::rtl::OUString& aFilterName )
+{
+ sal_Bool bDialogUsed = sal_False;
+
+ try {
+ uno::Sequence < beans::PropertyValue > aProps;
+ uno::Any aAny = m_pOwner->GetFilterConfiguration()->getByName( aFilterName );
+ if ( aAny >>= aProps )
+ {
+ sal_Int32 nPropertyCount = aProps.getLength();
+ for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
+ if( aProps[nProperty].Name.equals( ::rtl::OUString::createFromAscii("UIComponent")) )
+ {
+ ::rtl::OUString aServiceName;
+ aProps[nProperty].Value >>= aServiceName;
+ if( aServiceName.getLength() )
+ {
+ uno::Reference< ui::dialogs::XExecutableDialog > xFilterDialog(
+ m_pOwner->GetServiceFactory()->createInstance( aServiceName ), uno::UNO_QUERY );
+ uno::Reference< beans::XPropertyAccess > xFilterProperties( xFilterDialog, uno::UNO_QUERY );
+
+ if( xFilterDialog.is() && xFilterProperties.is() )
+ {
+ bDialogUsed = sal_True;
+
+ uno::Reference< document::XExporter > xExporter( xFilterDialog, uno::UNO_QUERY );
+ if( xExporter.is() )
+ xExporter->setSourceDocument(
+ uno::Reference< lang::XComponent >( GetModel(), uno::UNO_QUERY ) );
+
+ uno::Sequence< beans::PropertyValue > aPropsForDialog;
+ GetMediaDescr() >> aPropsForDialog;
+ xFilterProperties->setPropertyValues( aPropsForDialog );
+
+ if( xFilterDialog->execute() )
+ {
+ uno::Sequence< beans::PropertyValue > aPropsFromDialog =
+ xFilterProperties->getPropertyValues();
+ for ( sal_Int32 nInd = 0; nInd < aPropsFromDialog.getLength(); nInd++ )
+ GetMediaDescr()[aPropsFromDialog[nInd].Name] = aPropsFromDialog[nInd].Value;
+ }
+ else
+ {
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ ERRCODE_IO_ABORT );
+ }
+ }
+ }
+
+ break;
+ }
+ }
+ }
+ catch( container::NoSuchElementException& )
+ {
+ // the filter name is unknown
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ ERRCODE_IO_INVALIDPARAMETER );
+ }
+ catch( task::ErrorCodeIOException& )
+ {
+ throw;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return bDialogUsed;
+}
+
+//-------------------------------------------------------------------------
+sal_Int8 ModelData_Impl::CheckSaveAcceptable( sal_Int8 nCurStatus )
+{
+ sal_Int8 nResult = nCurStatus;
+
+ if ( nResult != STATUS_NO_ACTION && GetStorable()->hasLocation() )
+ {
+ // check whether save is acceptable by the configuration
+ // it is done only for documents that have persistence already
+ uno::Reference< uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig(
+ m_pOwner->GetServiceFactory(),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
+ ::comphelper::ConfigurationHelper::E_STANDARD );
+ if ( !xCommonConfig.is() )
+ throw uno::RuntimeException(); // should the saving proceed as usual instead?
+
+ try
+ {
+ sal_Bool bAlwaysSaveAs = sal_False;
+
+ // the saving is acceptable
+ // in case the configuration entry is not set or set to false
+ // or in case of version creation
+ ::rtl::OUString aVersionCommentString = ::rtl::OUString::createFromAscii( "VersionComment" );
+ if ( ( ::comphelper::ConfigurationHelper::readRelativeKey(
+ xCommonConfig,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Save/Document/" ) ),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AlwaysSaveAs" ) ) ) >>= bAlwaysSaveAs )
+ && bAlwaysSaveAs
+ && GetMediaDescr().find( aVersionCommentString ) == GetMediaDescr().end() )
+ {
+ // notify the user that SaveAs is going to be done
+ String aString( SfxResId( STR_NEW_FILENAME_SAVE ) );
+ Window* pWin = SfxStoringHelper::GetModelWindow( m_xModel );
+ QueryBox aMessageBox( pWin, WB_OK_CANCEL | WB_DEF_OK, aString );
+ if ( aMessageBox.Execute() == RET_OK )
+ nResult = STATUS_SAVEAS;
+ else
+ nResult = STATUS_NO_ACTION;
+ }
+ }
+ catch( uno::Exception& )
+ {
+ // impossibility to get the configuration access means normal saving flow for now
+ }
+ }
+
+ return nResult;
+}
+
+//-------------------------------------------------------------------------
+sal_Int8 ModelData_Impl::CheckStateForSave()
+{
+ // check acceptable entries for media descriptor
+ sal_Bool bVersInfoNeedsStore = sal_False;
+ ::comphelper::SequenceAsHashMap aAcceptedArgs;
+
+ ::rtl::OUString aVersionCommentString = ::rtl::OUString::createFromAscii( "VersionComment" );
+ ::rtl::OUString aAuthorString = ::rtl::OUString::createFromAscii( "Author" );
+ ::rtl::OUString aInteractionHandlerString = ::rtl::OUString::createFromAscii( "InteractionHandler" );
+ ::rtl::OUString aStatusIndicatorString = ::rtl::OUString::createFromAscii( "StatusIndicator" );
+
+ if ( GetMediaDescr().find( aVersionCommentString ) != GetMediaDescr().end() )
+ {
+ bVersInfoNeedsStore = sal_True;
+ aAcceptedArgs[ aVersionCommentString ] = GetMediaDescr()[ aVersionCommentString ];
+ }
+ if ( GetMediaDescr().find( aAuthorString ) != GetMediaDescr().end() )
+ aAcceptedArgs[ aAuthorString ] = GetMediaDescr()[ aAuthorString ];
+ if ( GetMediaDescr().find( aInteractionHandlerString ) != GetMediaDescr().end() )
+ aAcceptedArgs[ aInteractionHandlerString ] = GetMediaDescr()[ aInteractionHandlerString ];
+ if ( GetMediaDescr().find( aStatusIndicatorString ) != GetMediaDescr().end() )
+ aAcceptedArgs[ aStatusIndicatorString ] = GetMediaDescr()[ aStatusIndicatorString ];
+
+ // remove unacceptable entry if there is any
+ DBG_ASSERT( GetMediaDescr().size() == aAcceptedArgs.size(),
+ "Unacceptable parameters are provided in Save request!\n" );
+ if ( GetMediaDescr().size() != aAcceptedArgs.size() )
+ GetMediaDescr() = aAcceptedArgs;
+
+ // the document must be modified
+ if ( !GetModifiable()->isModified() && !bVersInfoNeedsStore )
+ return STATUS_NO_ACTION;
+
+ // if the document is readonly or a new one a SaveAs operation must be used
+ if ( !GetStorable()->hasLocation() || GetStorable()->isReadonly() )
+ return STATUS_SAVEAS;
+
+ // check that the old filter is acceptable
+ ::rtl::OUString aOldFilterName = GetDocProps().getUnpackedValueOrDefault(
+ aFilterNameString,
+ ::rtl::OUString() );
+ sal_Int8 nResult = CheckFilter( aOldFilterName );
+
+ return nResult;
+}
+
+sal_Int8 ModelData_Impl::CheckFilter( const ::rtl::OUString& aFilterName )
+{
+ ::comphelper::SequenceAsHashMap aFiltPropsHM;
+ sal_Int32 nFiltFlags = 0;
+ if ( aFilterName.getLength() )
+ {
+ // get properties of filter
+ uno::Sequence< beans::PropertyValue > aFilterProps;
+ if ( aFilterName.getLength() )
+ m_pOwner->GetFilterConfiguration()->getByName( aFilterName ) >>= aFilterProps;
+
+ aFiltPropsHM = ::comphelper::SequenceAsHashMap( aFilterProps );
+ nFiltFlags = aFiltPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), (sal_Int32)0 );
+ }
+
+ // only a temporary solution until default filter retrieving feature is implemented
+ // then GetDocServiceDefaultFilter() must be used
+ ::comphelper::SequenceAsHashMap aDefFiltPropsHM = GetDocServiceDefaultFilterCheckFlags( 3, 0 );
+ sal_Int32 nDefFiltFlags = aDefFiltPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), (sal_Int32)0 );
+
+ // if the old filter is not acceptable
+ // and there is no default filter or it is not acceptable for requested parameters then proceed with saveAs
+ if ( ( !aFiltPropsHM.size() || !( nFiltFlags & SFX_FILTER_EXPORT ) )
+ && ( !aDefFiltPropsHM.size() || !( nDefFiltFlags & SFX_FILTER_EXPORT ) || nDefFiltFlags & SFX_FILTER_INTERNAL ) )
+ return STATUS_SAVEAS;
+
+ // so at this point there is either an acceptable old filter or default one
+ if ( !aFiltPropsHM.size() || !( nFiltFlags & SFX_FILTER_EXPORT ) )
+ {
+ // so the default filter must be acceptable
+ return STATUS_SAVEAS_STANDARDNAME;
+ }
+ else if ( ( !( nFiltFlags & SFX_FILTER_OWN ) || ( nFiltFlags & SFX_FILTER_ALIEN ) )
+ && !( nFiltFlags & SFX_FILTER_SILENTEXPORT ) && aDefFiltPropsHM.size()
+ && ( nDefFiltFlags & SFX_FILTER_EXPORT ) && !( nDefFiltFlags & SFX_FILTER_INTERNAL ))
+ {
+ // the default filter is acceptable and the old filter is alian one
+ // so ask to make a saveAs operation
+ ::rtl::OUString aUIName = aFiltPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "UIName" ),
+ ::rtl::OUString() );
+ ::rtl::OUString aDefUIName = aDefFiltPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "UIName" ),
+ ::rtl::OUString() );
+ ::rtl::OUString aPreusedFilterName = GetDocProps().getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "PreusedFilterName" ),
+ ::rtl::OUString() );
+ if ( !aPreusedFilterName.equals( aFilterName ) && !aUIName.equals( aDefUIName ) )
+ {
+ if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), aUIName, aDefUIName, sal_True ) )
+ return STATUS_SAVEAS_STANDARDNAME;
+ }
+ }
+
+ return STATUS_SAVE;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool ModelData_Impl::CheckFilterOptionsDialogExistence()
+{
+ uno::Sequence< beans::NamedValue > aSearchRequest( 1 );
+ aSearchRequest[0].Name = ::rtl::OUString::createFromAscii( "DocumentService" );
+ aSearchRequest[0].Value <<= GetDocServiceName();
+
+ uno::Reference< container::XEnumeration > xFilterEnum =
+ m_pOwner->GetFilterQuery()->createSubSetEnumerationByProperties( aSearchRequest );
+
+ while ( xFilterEnum->hasMoreElements() )
+ {
+ uno::Sequence< beans::PropertyValue > pProps;
+ if ( xFilterEnum->nextElement() >>= pProps )
+ {
+ ::comphelper::SequenceAsHashMap aPropsHM( pProps );
+ ::rtl::OUString aUIServName = aPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "UIComponent" ),
+ ::rtl::OUString() );
+ if ( aUIServName.getLength() )
+ return sal_True;
+ }
+ }
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool ModelData_Impl::OutputFileDialog( sal_Int8 nStoreMode,
+ const ::comphelper::SequenceAsHashMap& aPreselectedFilterPropsHM,
+ sal_Bool bSetStandardName,
+ ::rtl::OUString& aSuggestedName,
+ sal_Bool bPreselectPassword,
+ const ::rtl::OUString& aSuggestedDir,
+ sal_Int16 nDialog,
+ const ::rtl::OUString& rStandardDir,
+ const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
+{
+ sal_Bool bUseFilterOptions = sal_False;
+
+ ::comphelper::SequenceAsHashMap::const_iterator aOverwriteIter =
+ GetMediaDescr().find( ::rtl::OUString::createFromAscii( "Overwrite" ) );
+
+ // the file name must be specified if overwrite option is set
+ if ( aOverwriteIter != GetMediaDescr().end() )
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ ERRCODE_IO_INVALIDPARAMETER );
+
+ // no target file name is specified
+ // we need to show the file dialog
+
+ // check if we have a filter which allows for filter options, so we need a corresponding checkbox in the dialog
+ sal_Bool bAllowOptions = sal_False;
+
+ // in case of Export, filter options dialog is used if available
+ if( !( nStoreMode & EXPORT_REQUESTED ) || ( nStoreMode & WIDEEXPORT_REQUESTED ) )
+ bAllowOptions = CheckFilterOptionsDialogExistence();
+
+ // get the filename by dialog ...
+ // create the file dialog
+ sal_Int16 aDialogMode = bAllowOptions
+ ? (com::sun::star::ui::dialogs::TemplateDescription::
+ FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS)
+ : (com::sun::star::ui::dialogs::TemplateDescription::
+ FILESAVE_AUTOEXTENSION_PASSWORD);
+ sal_Int64 aDialogFlags = 0;
+
+ if( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) )
+ {
+ if ( nStoreMode & PDFEXPORT_REQUESTED )
+ aDialogMode = com::sun::star::ui::dialogs::TemplateDescription::
+ FILESAVE_AUTOEXTENSION;
+ else
+ aDialogMode = com::sun::star::ui::dialogs::TemplateDescription::
+ FILESAVE_AUTOEXTENSION_SELECTION;
+ aDialogFlags = SFXWB_EXPORT;
+ }
+
+ sfx2::FileDialogHelper* pFileDlg = NULL;
+
+ ::rtl::OUString aDocServiceName = GetDocServiceName();
+ DBG_ASSERT( aDocServiceName.getLength(), "No document service for this module set!" );
+
+ sal_Int32 nMust = getMustFlags( nStoreMode );
+ sal_Int32 nDont = getDontFlags( nStoreMode );
+ sfx2::FileDialogHelper::Context eCtxt = sfx2::FileDialogHelper::UNKNOWN_CONTEXT;
+
+ if ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) )
+ {
+ if ( ( nStoreMode & PDFEXPORT_REQUESTED ) && aPreselectedFilterPropsHM.size() )
+ {
+ // this is a PDF export
+ // the filter options has been shown already
+ ::rtl::OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "UIName" ),
+ ::rtl::OUString() );
+
+ pFileDlg = new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aFilterUIName, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "pdf" ) ), rStandardDir, rBlackList );
+ pFileDlg->SetCurrentFilter( aFilterUIName );
+ }
+ else
+ {
+ // This is the normal dialog
+ pFileDlg = new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aDocServiceName, nDialog, nMust, nDont, rStandardDir, rBlackList );
+ }
+
+ if( aDocServiceName.equalsAscii( "com.sun.star.drawing.DrawingDocument" ) )
+ eCtxt = sfx2::FileDialogHelper::SD_EXPORT;
+ if( aDocServiceName.equalsAscii( "com.sun.star.presentation.PresentationDocument" ) )
+ eCtxt = sfx2::FileDialogHelper::SI_EXPORT;
+ if( aDocServiceName.equalsAscii( "com.sun.star.text.TextDocument" ) )
+ eCtxt = sfx2::FileDialogHelper::SW_EXPORT;
+
+ if ( eCtxt != sfx2::FileDialogHelper::UNKNOWN_CONTEXT )
+ pFileDlg->SetContext( eCtxt );
+
+ pFileDlg->CreateMatcher( aDocServiceName );
+
+ uno::Reference< ui::dialogs::XFilePicker > xFilePicker = pFileDlg->GetFilePicker();
+ uno::Reference< ui::dialogs::XFilePickerControlAccess > xControlAccess =
+ uno::Reference< ui::dialogs::XFilePickerControlAccess >( xFilePicker, uno::UNO_QUERY );
+
+ if ( xControlAccess.is() )
+ {
+ ::rtl::OUString aCtrlText = String( SfxResId( STR_EXPORTBUTTON ) );
+ xControlAccess->setLabel( ui::dialogs::CommonFilePickerElementIds::PUSHBUTTON_OK, aCtrlText );
+
+ aCtrlText = ::rtl::OUString( String( SfxResId( STR_LABEL_FILEFORMAT ) ) );
+ xControlAccess->setLabel( ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER_LABEL, aCtrlText );
+ }
+ }
+ else
+ {
+ // This is the normal dialog
+ pFileDlg = new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aDocServiceName, nDialog, nMust, nDont, rStandardDir, rBlackList );
+ pFileDlg->CreateMatcher( aDocServiceName );
+ }
+
+ ::rtl::OUString aAdjustToType;
+
+ if ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) )
+ {
+ // it is export, set the preselected filter
+ ::rtl::OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "UIName" ),
+ ::rtl::OUString() );
+ pFileDlg->SetCurrentFilter( aFilterUIName );
+ }
+ // it is no export, bSetStandardName == true means that user agreed to store document in the default (default default ;-)) format
+ else if ( bSetStandardName || GetStorable()->hasLocation() )
+ {
+ uno::Sequence< beans::PropertyValue > aOldFilterProps;
+ ::rtl::OUString aOldFilterName = GetDocProps().getUnpackedValueOrDefault(
+ aFilterNameString,
+ ::rtl::OUString() );
+
+ if ( aOldFilterName.getLength() )
+ m_pOwner->GetFilterConfiguration()->getByName( aOldFilterName ) >>= aOldFilterProps;
+
+ ::comphelper::SequenceAsHashMap aOldFiltPropsHM( aOldFilterProps );
+ sal_Int32 nOldFiltFlags = aOldFiltPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), (sal_Int32)0 );
+
+ if ( bSetStandardName || ( nOldFiltFlags & nMust ) != nMust || nOldFiltFlags & nDont )
+ {
+ // the suggested type will be changed, the extension should be adjusted
+ aAdjustToType = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "Type" ),
+ ::rtl::OUString() );
+
+ ::rtl::OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "UIName" ),
+ ::rtl::OUString() );
+ pFileDlg->SetCurrentFilter( aFilterUIName );
+ }
+ else
+ {
+ pFileDlg->SetCurrentFilter( aOldFiltPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "UIName" ),
+ ::rtl::OUString() ) );
+ }
+ }
+
+ ::rtl::OUString aReccomendedDir = GetReccomendedDir( aSuggestedDir, eCtxt );
+ if ( aReccomendedDir.getLength() )
+ pFileDlg->SetDisplayDirectory( aReccomendedDir );
+ ::rtl::OUString aReccomendedName = GetReccomendedName( aSuggestedName, aAdjustToType );
+ if ( aReccomendedName.getLength() )
+ pFileDlg->SetFileName( aReccomendedName );
+
+ uno::Reference < view::XSelectionSupplier > xSel( GetModel()->getCurrentController(), uno::UNO_QUERY );
+ if ( xSel.is() && xSel->getSelection().hasValue() )
+ GetMediaDescr()[::rtl::OUString::createFromAscii( "SelectionOnly" )] <<= sal_True;
+
+ // This is a temporary hardcoded solution must be removed when
+ // dialogs do not need parameters in SidSet representation any more
+ sal_uInt16 nSlotID = getSlotIDFromMode( nStoreMode );
+ if ( !nSlotID )
+ throw lang::IllegalArgumentException(); // TODO:
+
+ // generate SidSet from MediaDescriptor and provide it into FileDialog
+ // than merge changed SidSet back
+ SfxAllItemSet aDialogParams( SFX_APP()->GetPool() );
+ SfxItemSet* pDialogParams = &aDialogParams;
+ TransformParameters( nSlotID,
+ GetMediaDescr().getAsConstPropertyValueList(),
+ aDialogParams,
+ NULL );
+
+ const SfxPoolItem* pItem = NULL;
+ if ( bPreselectPassword && aDialogParams.GetItemState( SID_ENCRYPTIONDATA, sal_True, &pItem ) != SFX_ITEM_SET )
+ {
+ // the file dialog preselects the password checkbox if the provided mediadescriptor has encryption data entry
+ // after dialog execution the password interaction flag will be either removed or not
+ aDialogParams.Put( SfxBoolItem( SID_PASSWORDINTERACTION, sal_True ) );
+ }
+
+ // aStringTypeFN is a pure output parameter, pDialogParams is an in/out parameter
+ String aStringTypeFN;
+ if ( pFileDlg->Execute( pDialogParams, aStringTypeFN ) != ERRCODE_NONE )
+ {
+ delete pFileDlg;
+ throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT );
+ }
+
+ ::rtl::OUString aFilterName = aStringTypeFN;
+
+ // the following two arguments can not be converted in MediaDescriptor,
+ // so they should be removed from the ItemSet after retrieving
+ SFX_ITEMSET_ARG( pDialogParams, pRecommendReadOnly, SfxBoolItem, SID_RECOMMENDREADONLY, sal_False );
+ m_bRecommendReadOnly = ( pRecommendReadOnly && pRecommendReadOnly->GetValue() );
+ pDialogParams->ClearItem( SID_RECOMMENDREADONLY );
+
+ uno::Sequence< beans::PropertyValue > aPropsFromDialog;
+ TransformItems( nSlotID, *pDialogParams, aPropsFromDialog, NULL );
+ GetMediaDescr() << aPropsFromDialog;
+
+ // get the path from the dialog
+ INetURLObject aURL( pFileDlg->GetPath() );
+ // the path should be provided outside since it might be used for further calls to the dialog
+ aSuggestedName = aURL.GetName( INetURLObject::DECODE_WITH_CHARSET );
+
+ // old filter options should be cleared in case different filter is used
+
+ ::rtl::OUString aFilterFromMediaDescr = GetMediaDescr().getUnpackedValueOrDefault(
+ aFilterNameString,
+ ::rtl::OUString() );
+ ::rtl::OUString aOldFilterName = GetDocProps().getUnpackedValueOrDefault(
+ aFilterNameString,
+ ::rtl::OUString() );
+ if ( aFilterName.equals( aFilterFromMediaDescr ) )
+ {
+ // preserv current settings if any
+ // if there no current settings and the name is the same
+ // as old filter name use old filter settings
+
+ if ( aFilterFromMediaDescr.equals( aOldFilterName ) )
+ {
+ ::comphelper::SequenceAsHashMap::const_iterator aIter =
+ GetDocProps().find( aFilterOptionsString );
+ if ( aIter != GetDocProps().end()
+ && GetMediaDescr().find( aFilterOptionsString ) == GetMediaDescr().end() )
+ GetMediaDescr()[aIter->first] = aIter->second;
+
+ aIter = GetDocProps().find( aFilterDataString );
+ if ( aIter != GetDocProps().end()
+ && GetMediaDescr().find( aFilterDataString ) == GetMediaDescr().end() )
+ GetMediaDescr()[aIter->first] = aIter->second;
+ }
+ }
+ else
+ {
+ GetMediaDescr().erase( aFilterDataString );
+ GetMediaDescr().erase( aFilterOptionsString );
+
+ if ( aFilterName.equals( aOldFilterName ) )
+ {
+ // merge filter option of the document filter
+
+ ::comphelper::SequenceAsHashMap::const_iterator aIter =
+ GetDocProps().find( aFilterOptionsString );
+ if ( aIter != GetDocProps().end() )
+ GetMediaDescr()[aIter->first] = aIter->second;
+
+ aIter = GetDocProps().find( aFilterDataString );
+ if ( aIter != GetDocProps().end() )
+ GetMediaDescr()[aIter->first] = aIter->second;
+ }
+ }
+
+ uno::Reference< ui::dialogs::XFilePickerControlAccess > xExtFileDlg( pFileDlg->GetFilePicker(), uno::UNO_QUERY );
+ if ( xExtFileDlg.is() )
+ {
+ if ( SfxStoringHelper::CheckFilterOptionsAppearence( m_pOwner->GetFilterConfiguration(), aFilterName ) )
+ bUseFilterOptions = sal_True;
+
+ if ( ( !( nStoreMode & EXPORT_REQUESTED ) || ( nStoreMode & WIDEEXPORT_REQUESTED ) ) && bUseFilterOptions )
+ {
+ try
+ {
+ // for exporters: always show dialog if format uses options
+ // for save: show dialog if format uses options and no options given or if forced by user
+ uno::Any aVal =
+ xExtFileDlg->getValue( ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS, 0 );
+
+ aVal >>= bUseFilterOptions;
+ if ( !bUseFilterOptions )
+ bUseFilterOptions =
+ ( GetMediaDescr().find( aFilterDataString ) == GetMediaDescr().end()
+ && GetMediaDescr().find( aFilterOptionsString ) == GetMediaDescr().end() );
+ }
+ catch( lang::IllegalArgumentException& )
+ {}
+ }
+ }
+
+ delete pFileDlg;
+
+ // merge in results of the dialog execution
+ GetMediaDescr()[::rtl::OUString::createFromAscii( "URL" )] <<=
+ ::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ));
+ GetMediaDescr()[aFilterNameString] <<= aFilterName;
+
+ return bUseFilterOptions;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool ModelData_Impl::ShowDocumentInfoDialog()
+{
+ sal_Bool bDialogUsed = sal_False;
+
+ try {
+ uno::Reference< frame::XController > xController = GetModel()->getCurrentController();
+ if ( xController.is() )
+ {
+ uno::Reference< frame::XDispatchProvider > xFrameDispatch( xController->getFrame(), uno::UNO_QUERY );
+ if ( xFrameDispatch.is() )
+ {
+ util::URL aURL;
+ aURL.Complete = ::rtl::OUString::createFromAscii( ".uno:SetDocumentProperties" );
+
+ uno::Reference< util::XURLTransformer > xTransformer(
+ m_pOwner->GetServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.util.URLTransformer") ),
+ uno::UNO_QUERY );
+ if ( xTransformer.is() && xTransformer->parseStrict( aURL ) )
+ {
+ uno::Reference< frame::XDispatch > xDispatch = xFrameDispatch->queryDispatch(
+ aURL,
+ ::rtl::OUString::createFromAscii( "_self" ),
+ 0 );
+ if ( xDispatch.is() )
+ {
+ xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() );
+ bDialogUsed = sal_True;
+ }
+ }
+ }
+ }
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ return bDialogUsed;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString ModelData_Impl::GetReccomendedDir( const ::rtl::OUString& aSuggestedDir, const sfx2::FileDialogHelper::Context& aCtxt )
+{
+ ::rtl::OUString aReccomendedDir;
+
+ if ( ( aSuggestedDir.getLength() || GetStorable()->hasLocation() )
+ && !GetMediaDescr().getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "RepairPackage" ),
+ sal_False ) )
+ {
+ INetURLObject aLocation;
+ if ( aSuggestedDir.getLength() )
+ aLocation = INetURLObject( aSuggestedDir );
+ else
+ {
+ ::rtl::OUString aOldURL = GetStorable()->getLocation();
+ if ( aOldURL.getLength() )
+ {
+ INetURLObject aTmp( aOldURL );
+ if ( aTmp.removeSegment() )
+ aLocation = aTmp;
+ }
+
+ if ( aLocation.HasError() )
+ aLocation = INetURLObject( SvtPathOptions().GetWorkPath() );
+ }
+
+ aLocation.setFinalSlash();
+ if ( !aLocation.HasError() )
+ aReccomendedDir = aLocation.GetMainURL( INetURLObject::NO_DECODE );
+ }
+ else
+ {
+ // pb: set graphic path if context == SD_EXPORT or SI_EXPORT else work path
+ ::rtl::OUString aConfigSuggestion( ( aCtxt != sfx2::FileDialogHelper::UNKNOWN_CONTEXT ) ? SvtPathOptions().GetGraphicPath() : SvtPathOptions().GetWorkPath() );
+ aReccomendedDir = INetURLObject( aConfigSuggestion ).GetMainURL( INetURLObject::NO_DECODE );
+ }
+
+ return aReccomendedDir;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString ModelData_Impl::GetReccomendedName( const ::rtl::OUString& aSuggestedName, const ::rtl::OUString& aTypeName )
+{
+ // the last used name might be provided by aSuggestedName from the old selection, or from the MediaDescriptor
+ ::rtl::OUString aReccomendedName;
+
+ if ( aSuggestedName.getLength() )
+ aReccomendedName = aSuggestedName;
+ else
+ {
+ aReccomendedName = INetURLObject( GetStorable()->getLocation() ).GetName( INetURLObject::DECODE_WITH_CHARSET );
+ if ( !aReccomendedName.getLength() )
+ {
+ try {
+ uno::Reference< frame::XTitle > xTitle( GetModel(), uno::UNO_QUERY_THROW );
+ aReccomendedName = xTitle->getTitle();
+ } catch( uno::Exception& ) {}
+ }
+
+ if ( aReccomendedName.getLength() && aTypeName.getLength() )
+ {
+ // adjust the extension to the type
+ uno::Reference< container::XNameAccess > xTypeDetection = uno::Reference< container::XNameAccess >(
+ m_pOwner->GetServiceFactory()->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.TypeDetection" ) ),
+ uno::UNO_QUERY );
+ if ( xTypeDetection.is() )
+ {
+ INetURLObject aObj( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "file:///c:/" ) ) + aReccomendedName );
+
+ uno::Sequence< beans::PropertyValue > aTypeNameProps;
+ if ( ( xTypeDetection->getByName( aTypeName ) >>= aTypeNameProps ) && aTypeNameProps.getLength() )
+ {
+ ::comphelper::SequenceAsHashMap aTypeNamePropsHM( aTypeNameProps );
+ uno::Sequence< ::rtl::OUString > aExtensions = aTypeNamePropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "Extensions" ),
+ ::uno::Sequence< ::rtl::OUString >() );
+ if ( aExtensions.getLength() )
+ aObj.SetExtension( aExtensions[0] );
+ }
+
+ aReccomendedName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET );
+ }
+ }
+ }
+
+ return aReccomendedName;
+}
+
+
+//=========================================================================
+// class SfxStoringHelper
+//=========================================================================
+//-------------------------------------------------------------------------
+SfxStoringHelper::SfxStoringHelper( const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+: m_xFactory( xFactory )
+{
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< lang::XMultiServiceFactory > SfxStoringHelper::GetServiceFactory()
+{
+ if ( !m_xFactory.is() )
+ {
+ m_xFactory = ::comphelper::getProcessServiceFactory();
+ if( !m_xFactory.is() )
+ throw uno::RuntimeException(); // TODO:
+ }
+
+ return m_xFactory;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< container::XNameAccess > SfxStoringHelper::GetFilterConfiguration()
+{
+ if ( !m_xFilterCFG.is() )
+ {
+ m_xFilterCFG = uno::Reference< container::XNameAccess >(
+ GetServiceFactory()->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ),
+ uno::UNO_QUERY );
+
+ if ( !m_xFilterCFG.is() )
+ throw uno::RuntimeException();
+ }
+
+ return m_xFilterCFG;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< container::XContainerQuery > SfxStoringHelper::GetFilterQuery()
+{
+ if ( !m_xFilterQuery.is() )
+ {
+ m_xFilterQuery = uno::Reference< container::XContainerQuery >( GetFilterConfiguration(), uno::UNO_QUERY );
+ if ( !m_xFilterQuery.is() )
+ throw uno::RuntimeException();
+ }
+
+ return m_xFilterQuery;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< ::com::sun::star::frame::XModuleManager > SfxStoringHelper::GetModuleManager()
+{
+ if ( !m_xModuleManager.is() )
+ {
+ m_xModuleManager = uno::Reference< ::com::sun::star::frame::XModuleManager >(
+ GetServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.frame.ModuleManager" ) ),
+ uno::UNO_QUERY );
+
+ if ( !m_xModuleManager.is() )
+ throw uno::RuntimeException();
+ }
+
+ return m_xModuleManager;
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< container::XNameAccess > SfxStoringHelper::GetNamedModuleManager()
+{
+ if ( !m_xNamedModManager.is() )
+ {
+ m_xNamedModManager = uno::Reference< container::XNameAccess >( GetModuleManager(), uno::UNO_QUERY );
+ if ( !m_xNamedModManager.is() )
+ throw uno::RuntimeException();
+ }
+
+ return m_xNamedModManager;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& xModel,
+ const ::rtl::OUString& aSlotName,
+ uno::Sequence< beans::PropertyValue >& aArgsSequence,
+ sal_Bool bPreselectPassword,
+ ::rtl::OUString aSuggestedName,
+ sal_uInt16 nDocumentSignatureState )
+{
+ ModelData_Impl aModelData( *this, xModel, aArgsSequence );
+
+ sal_Bool bDialogUsed = sal_False;
+
+ INetURLObject aURL;
+
+ sal_Bool bSetStandardName = sal_False; // can be set only for SaveAs
+
+ // parse the slot name
+ sal_Int8 nStoreMode = getStoreModeFromSlotName( aSlotName );
+ sal_Int8 nStatusSave = STATUS_NO_ACTION;
+
+ // handle the special cases
+ if ( nStoreMode & SAVEAS_REQUESTED )
+ {
+ ::comphelper::SequenceAsHashMap::const_iterator aSaveToIter =
+ aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "SaveTo" ) );
+ if ( aSaveToIter != aModelData.GetMediaDescr().end() )
+ {
+ sal_Bool bWideExport = sal_False;
+ aSaveToIter->second >>= bWideExport;
+ if ( bWideExport )
+ nStoreMode = EXPORT_REQUESTED | WIDEEXPORT_REQUESTED;
+ }
+
+ // if saving is not acceptable the warning must be shown even in case of SaveAs operation
+ if ( ( nStoreMode & SAVEAS_REQUESTED ) && aModelData.CheckSaveAcceptable( STATUS_SAVEAS ) == STATUS_NO_ACTION )
+ throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT );
+ }
+ else if ( nStoreMode & SAVE_REQUESTED )
+ {
+ // if saving is not acceptable by the configuration the warning must be shown
+ nStatusSave = aModelData.CheckSaveAcceptable( STATUS_SAVE );
+
+ if ( nStatusSave == STATUS_NO_ACTION )
+ throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT );
+ else if ( nStatusSave == STATUS_SAVE )
+ {
+ // check whether it is possible to use save operation
+ nStatusSave = aModelData.CheckStateForSave();
+ }
+
+ if ( nStatusSave == STATUS_NO_ACTION )
+ {
+ throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT );
+ }
+ else if ( nStatusSave != STATUS_SAVE )
+ {
+ // this should be a usual SaveAs operation
+ nStoreMode = SAVEAS_REQUESTED;
+ if ( nStatusSave == STATUS_SAVEAS_STANDARDNAME )
+ bSetStandardName = sal_True;
+ }
+ }
+
+ if ( !( nStoreMode & EXPORT_REQUESTED ) )
+ {
+ // if it is no export, warn user that the signature will be removed
+ if ( SIGNATURESTATE_SIGNATURES_OK == nDocumentSignatureState
+ || SIGNATURESTATE_SIGNATURES_INVALID == nDocumentSignatureState
+ || SIGNATURESTATE_SIGNATURES_NOTVALIDATED == nDocumentSignatureState
+ || SIGNATURESTATE_SIGNATURES_PARTIAL_OK == nDocumentSignatureState)
+ {
+ if ( QueryBox( NULL, SfxResId( RID_XMLSEC_QUERY_LOSINGSIGNATURE ) ).Execute() != RET_YES )
+ {
+ // the user has decided not to store the document
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ ERRCODE_IO_ABORT );
+ }
+ }
+ }
+
+ if ( nStoreMode & SAVE_REQUESTED && nStatusSave == STATUS_SAVE )
+ {
+ // Document properties can contain streams that should be freed before storing
+ aModelData.FreeDocumentProps();
+
+ if ( aModelData.GetStorable2().is() )
+ {
+ try
+ {
+ aModelData.GetStorable2()->storeSelf( aModelData.GetMediaDescr().getAsConstPropertyValueList() );
+ }
+ catch( lang::IllegalArgumentException& )
+ {
+ OSL_ENSURE( sal_False, "ModelData didn't handle illegal parameters, all the parameters are ignored!\n" );
+ aModelData.GetStorable()->store();
+ }
+ }
+ else
+ {
+ OSL_ENSURE( sal_False, "XStorable2 is not supported by the model!\n" );
+ aModelData.GetStorable()->store();
+ }
+
+ return sal_False;
+ }
+
+ // preselect a filter for the storing process
+ uno::Sequence< beans::PropertyValue > aFilterProps = aModelData.GetPreselectedFilter_Impl( nStoreMode );
+
+ DBG_ASSERT( aFilterProps.getLength(), "No filter for storing!\n" );
+ if ( !aFilterProps.getLength() )
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ ERRCODE_IO_INVALIDPARAMETER );
+
+ ::comphelper::SequenceAsHashMap aFilterPropsHM( aFilterProps );
+ ::rtl::OUString aFilterName = aFilterPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "Name" ),
+ ::rtl::OUString() );
+
+ ::rtl::OUString aFilterFromMediaDescr = aModelData.GetMediaDescr().getUnpackedValueOrDefault(
+ aFilterNameString,
+ ::rtl::OUString() );
+ ::rtl::OUString aOldFilterName = aModelData.GetDocProps().getUnpackedValueOrDefault(
+ aFilterNameString,
+ ::rtl::OUString() );
+
+ sal_Bool bUseFilterOptions = sal_False;
+ ::comphelper::SequenceAsHashMap::const_iterator aFileNameIter = aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "URL" ) );
+
+ if ( ( nStoreMode & EXPORT_REQUESTED ) && ( nStoreMode & PDFEXPORT_REQUESTED ) && !( nStoreMode & PDFDIRECTEXPORT_REQUESTED ) )
+ {
+ // this is PDF export, the filter options dialog should be shown before the export
+ aModelData.GetMediaDescr()[aFilterNameString] <<= aFilterName;
+ if ( aModelData.GetMediaDescr().find( aFilterFlagsString ) == aModelData.GetMediaDescr().end()
+ && aModelData.GetMediaDescr().find( aFilterOptionsString ) == aModelData.GetMediaDescr().end()
+ && aModelData.GetMediaDescr().find( aFilterDataString ) == aModelData.GetMediaDescr().end() )
+ {
+ // execute filter options dialog since no options are set in the media descriptor
+ if ( aModelData.ExecuteFilterDialog_Impl( aFilterName ) )
+ bDialogUsed = sal_True;
+ }
+ }
+
+ if ( aFileNameIter == aModelData.GetMediaDescr().end() )
+ {
+ sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG;
+ ::comphelper::SequenceAsHashMap::const_iterator aDlgIter =
+ aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "UseSystemDialog" ) );
+ if ( aDlgIter != aModelData.GetMediaDescr().end() )
+ {
+ sal_Bool bUseSystemDialog = sal_True;
+ if ( aDlgIter->second >>= bUseSystemDialog )
+ {
+ if ( bUseSystemDialog )
+ nDialog = SFX2_IMPL_DIALOG_SYSTEM;
+ else
+ nDialog = SFX2_IMPL_DIALOG_OOO;
+ }
+ }
+
+ // The Dispatch supports parameter FolderName that overwrites SuggestedSaveAsDir
+ ::rtl::OUString aSuggestedDir = aModelData.GetMediaDescr().getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FolderName" ) ), ::rtl::OUString() );
+ if ( !aSuggestedDir.getLength() )
+ {
+ aSuggestedDir = aModelData.GetMediaDescr().getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SuggestedSaveAsDir" ) ), ::rtl::OUString() );
+ if ( !aSuggestedDir.getLength() )
+ aSuggestedDir = aModelData.GetDocProps().getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SuggestedSaveAsDir" ) ), ::rtl::OUString() );
+ }
+
+ aSuggestedName = aModelData.GetMediaDescr().getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SuggestedSaveAsName" ) ), ::rtl::OUString() );
+ if ( !aSuggestedName.getLength() )
+ aSuggestedName = aModelData.GetDocProps().getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SuggestedSaveAsName" ) ), ::rtl::OUString() );
+
+ ::rtl::OUString sStandardDir;
+ ::comphelper::SequenceAsHashMap::const_iterator aStdDirIter =
+ aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "StandardDir" ) );
+ if ( aStdDirIter != aModelData.GetMediaDescr().end() )
+ aStdDirIter->second >>= sStandardDir;
+
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > aBlackList;
+
+ ::comphelper::SequenceAsHashMap::const_iterator aBlackListIter =
+ aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "BlackList" ) );
+ if ( aBlackListIter != aModelData.GetMediaDescr().end() )
+ aBlackListIter->second >>= aBlackList;
+
+ sal_Bool bExit = sal_False;
+ while ( !bExit )
+ {
+ bUseFilterOptions = aModelData.OutputFileDialog( nStoreMode, aFilterProps, bSetStandardName, aSuggestedName, bPreselectPassword, aSuggestedDir, nDialog, sStandardDir, aBlackList );
+
+ // in case the dialog is opend a second time the folder should be the same as before, not what was handed over by parameters
+ aSuggestedDir = ::rtl::OUString();
+ if ( nStoreMode == SAVEAS_REQUESTED )
+ {
+ // in case of saving check filter for possible alien warning
+ ::rtl::OUString aSelFilterName = aModelData.GetMediaDescr().getUnpackedValueOrDefault(
+ aFilterNameString,
+ ::rtl::OUString() );
+ sal_Int8 nStatusFilterSave = aModelData.CheckFilter( aSelFilterName );
+ if ( nStatusFilterSave == STATUS_SAVEAS_STANDARDNAME )
+ {
+ // switch to best filter
+ bSetStandardName = sal_True;
+ }
+ else if ( nStatusFilterSave == STATUS_SAVE )
+ {
+ // user confirmed alien filter or "good" filter is used
+ bExit = sal_True;
+ }
+ }
+ else
+ bExit = sal_True;
+ }
+
+ bDialogUsed = sal_True;
+ aFileNameIter = aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "URL" ) );
+ }
+ else
+ {
+ // the target file name is provided so check if new filter options
+ // are provided or old options can be used
+ if ( aFilterFromMediaDescr.equals( aOldFilterName ) )
+ {
+ ::comphelper::SequenceAsHashMap::const_iterator aIter =
+ aModelData.GetDocProps().find( aFilterOptionsString );
+ if ( aIter != aModelData.GetDocProps().end()
+ && aModelData.GetMediaDescr().find( aFilterOptionsString ) == aModelData.GetMediaDescr().end() )
+ aModelData.GetMediaDescr()[aIter->first] = aIter->second;
+
+ aIter = aModelData.GetDocProps().find( aFilterDataString );
+ if ( aIter != aModelData.GetDocProps().end()
+ && aModelData.GetMediaDescr().find( aFilterDataString ) == aModelData.GetMediaDescr().end() )
+ aModelData.GetMediaDescr()[aIter->first] = aIter->second;
+ }
+ }
+
+ if ( aFileNameIter != aModelData.GetMediaDescr().end() )
+ {
+ ::rtl::OUString aFileName;
+ aFileNameIter->second >>= aFileName;
+ aURL.SetURL( aFileName );
+ DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL!" );
+
+ ::comphelper::SequenceAsHashMap::const_iterator aIter =
+ aModelData.GetMediaDescr().find( aFilterNameString );
+
+ if ( aIter != aModelData.GetMediaDescr().end() )
+ aIter->second >>= aFilterName;
+ else
+ aModelData.GetMediaDescr()[aFilterNameString] <<= aFilterName;
+
+ DBG_ASSERT( aFilterName.getLength(), "Illegal filter!" );
+ }
+ else
+ {
+ DBG_ASSERT( sal_False, "This code must be unreachable!\n" );
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ ERRCODE_IO_INVALIDPARAMETER );
+ }
+
+ ::comphelper::SequenceAsHashMap::const_iterator aIter =
+ aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "FilterFlags" ) );
+ sal_Bool bFilterFlagsSet = ( aIter != aModelData.GetMediaDescr().end() );
+
+ if( !( nStoreMode & PDFEXPORT_REQUESTED ) && !bFilterFlagsSet
+ && ( ( nStoreMode & EXPORT_REQUESTED ) || bUseFilterOptions ) )
+ {
+ // execute filter options dialog
+ if ( aModelData.ExecuteFilterDialog_Impl( aFilterName ) )
+ bDialogUsed = sal_True;
+ }
+
+ // so the arguments will not change any more and can be stored to the main location
+ aArgsSequence = aModelData.GetMediaDescr().getAsConstPropertyValueList();
+
+ // store the document and handle it's docinfo
+ SvtSaveOptions aOptions;
+
+ DocumentSettingsGuard aSettingsGuard( aModelData.GetModel(), aModelData.IsRecommendReadOnly(), nStoreMode & EXPORT_REQUESTED );
+
+ OSL_ENSURE( aModelData.GetMediaDescr().find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ) ) == aModelData.GetMediaDescr().end(), "The Password property of MediaDescriptor should not be used here!" );
+ if ( aOptions.IsDocInfoSave()
+ && ( !aModelData.GetStorable()->hasLocation()
+ || INetURLObject( aModelData.GetStorable()->getLocation() ) != aURL ) )
+ {
+ // this is defenitly not a Save operation
+ // so the document info can be updated
+
+ // on export document info must be preserved
+ uno::Reference<document::XDocumentInfoSupplier> xDIS(
+ aModelData.GetModel(), uno::UNO_QUERY_THROW);
+ uno::Reference<util::XCloneable> xCloneable(
+ xDIS->getDocumentInfo(), uno::UNO_QUERY_THROW);
+ uno::Reference<document::XDocumentInfo> xOldDocInfo(
+ xCloneable->createClone(), uno::UNO_QUERY_THROW);
+
+ // use dispatch API to show document info dialog
+ if ( aModelData.ShowDocumentInfoDialog() )
+ bDialogUsed = sal_True;
+ else
+ {
+ DBG_ERROR( "Can't execute document info dialog!\n" );
+ }
+
+ try {
+ // Document properties can contain streams that should be freed before storing
+ aModelData.FreeDocumentProps();
+ if ( ( nStoreMode & EXPORT_REQUESTED ) )
+ aModelData.GetStorable()->storeToURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
+ else
+ aModelData.GetStorable()->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
+ }
+ catch( uno::Exception& )
+ {
+ if ( ( nStoreMode & EXPORT_REQUESTED ) )
+ SetDocInfoState( aModelData.GetModel(), xOldDocInfo, sal_True );
+
+ throw;
+ }
+
+ if ( ( nStoreMode & EXPORT_REQUESTED ) )
+ SetDocInfoState( aModelData.GetModel(), xOldDocInfo, sal_True );
+ }
+ else
+ {
+ // Document properties can contain streams that should be freed before storing
+ aModelData.FreeDocumentProps();
+
+ // this is actually a save operation with different parameters
+ // so storeTo or storeAs without DocInfo operations are used
+ if ( ( nStoreMode & EXPORT_REQUESTED ) )
+ aModelData.GetStorable()->storeToURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
+ else
+ aModelData.GetStorable()->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
+ }
+
+ return bDialogUsed;
+}
+
+//-------------------------------------------------------------------------
+// static
+sal_Bool SfxStoringHelper::CheckFilterOptionsAppearence(
+ const uno::Reference< container::XNameAccess >& xFilterCFG,
+ const ::rtl::OUString& aFilterName )
+{
+ sal_Bool bUseFilterOptions = sal_False;
+
+ DBG_ASSERT( xFilterCFG.is(), "No filter configuration!\n" );
+ if( xFilterCFG.is() )
+ {
+ try {
+ uno::Sequence < beans::PropertyValue > aProps;
+ uno::Any aAny = xFilterCFG->getByName( aFilterName );
+ if ( aAny >>= aProps )
+ {
+ ::comphelper::SequenceAsHashMap aPropsHM( aProps );
+ ::rtl::OUString aServiceName = aPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "UIComponent" ),
+ ::rtl::OUString() );
+ if( aServiceName.getLength() )
+ bUseFilterOptions = sal_True;
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+
+ return bUseFilterOptions;
+}
+
+//-------------------------------------------------------------------------
+// static
+void SfxStoringHelper::SetDocInfoState(
+ const uno::Reference< frame::XModel >& xModel,
+ const uno::Reference< document::XDocumentInfo >& i_xOldDocInfo,
+ sal_Bool bNoModify )
+{
+ uno::Reference< document::XDocumentInfoSupplier > xModelDocInfoSupplier( xModel, uno::UNO_QUERY );
+ if ( !xModelDocInfoSupplier.is() )
+ throw uno::RuntimeException(); // TODO:
+
+ uno::Reference< document::XDocumentInfo > xDocInfoToFill = xModelDocInfoSupplier->getDocumentInfo();
+ uno::Reference< beans::XPropertySet > xPropSet( i_xOldDocInfo,
+ uno::UNO_QUERY_THROW );
+
+ uno::Reference< util::XModifiable > xModifiable( xModel, uno::UNO_QUERY );
+ if ( bNoModify && !xModifiable.is() )
+ throw uno::RuntimeException();
+
+ sal_Bool bIsModified = bNoModify && xModifiable->isModified();
+
+ try
+ {
+ uno::Reference< beans::XPropertySet > xSet( xDocInfoToFill, uno::UNO_QUERY );
+ uno::Reference< beans::XPropertyContainer > xContainer( xSet, uno::UNO_QUERY );
+ uno::Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
+ uno::Sequence< beans::Property > lProps = xSetInfo->getProperties();
+ const beans::Property* pProps = lProps.getConstArray();
+ sal_Int32 c = lProps.getLength();
+ sal_Int32 i = 0;
+ for (i=0; i<c; ++i)
+ {
+ uno::Any aValue = xPropSet->getPropertyValue( pProps[i].Name );
+ if ( pProps[i].Attributes & ::com::sun::star::beans::PropertyAttribute::REMOVABLE )
+ // QUESTION: DefaultValue?!
+ xContainer->addProperty( pProps[i].Name, pProps[i].Attributes, aValue );
+ try
+ {
+ // it is possible that the propertysets from XML and binary files differ; we shouldn't break then
+ xSet->setPropertyValue( pProps[i].Name, aValue );
+ }
+ catch ( uno::Exception& ) {}
+ }
+
+ sal_Int16 nCount = i_xOldDocInfo->getUserFieldCount();
+ sal_Int16 nSupportedCount = xDocInfoToFill->getUserFieldCount();
+ for ( sal_Int16 nInd = 0; nInd < nCount && nInd < nSupportedCount; nInd++ )
+ {
+ ::rtl::OUString aPropName = i_xOldDocInfo->getUserFieldName( nInd );
+ xDocInfoToFill->setUserFieldName( nInd, aPropName );
+ ::rtl::OUString aPropVal = i_xOldDocInfo->getUserFieldValue( nInd );
+ xDocInfoToFill->setUserFieldValue( nInd, aPropVal );
+ }
+ }
+ catch ( uno::Exception& ) {}
+
+ // set the modified flag back if required
+ if ( bNoModify && bIsModified != xModifiable->isModified() )
+ xModifiable->setModified( bIsModified );
+}
+
+//-------------------------------------------------------------------------
+// static
+sal_Bool SfxStoringHelper::WarnUnacceptableFormat( const uno::Reference< frame::XModel >& xModel,
+ ::rtl::OUString aOldUIName,
+ ::rtl::OUString /*aDefUIName*/,
+ sal_Bool /*bCanProceedFurther*/ )
+{
+ if ( !SvtSaveOptions().IsWarnAlienFormat() )
+ return sal_True;
+
+ Window* pWin = SfxStoringHelper::GetModelWindow( xModel );
+ SfxAlienWarningDialog aDlg( pWin, aOldUIName );
+
+ return aDlg.Execute() == RET_OK;
+}
+
+// static
+void SfxStoringHelper::ExecuteFilterDialog( SfxStoringHelper& _rStorageHelper
+ ,const ::rtl::OUString& _sFilterName
+ ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _xModel
+ ,/*OUT*/::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgsSequence)
+{
+ ModelData_Impl aModelData( _rStorageHelper, _xModel, _rArgsSequence );
+ if ( aModelData.ExecuteFilterDialog_Impl( _sFilterName ) )
+ _rArgsSequence = aModelData.GetMediaDescr().getAsConstPropertyValueList();
+}
+
+// static
+Window* SfxStoringHelper::GetModelWindow( const uno::Reference< frame::XModel >& xModel )
+{
+ Window* pWin = 0;
+ try {
+ if ( xModel.is() )
+ {
+ uno::Reference< frame::XController > xController = xModel->getCurrentController();
+ if ( xController.is() )
+ {
+ uno::Reference< frame::XFrame > xFrame = xController->getFrame();
+ if ( xFrame.is() )
+ {
+ uno::Reference< awt::XWindow > xWindow = xFrame->getContainerWindow();
+ if ( xWindow.is() )
+ {
+ VCLXWindow* pVCLWindow = VCLXWindow::GetImplementation( xWindow );
+ if ( pVCLWindow )
+ pWin = pVCLWindow->GetWindow();
+ }
+ }
+ }
+ }
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ return pWin;
+}
+
diff --git a/sfx2/source/doc/iframe.cxx b/sfx2/source/doc/iframe.cxx
new file mode 100644
index 000000000000..f7df58ffd397
--- /dev/null
+++ b/sfx2/source/doc/iframe.cxx
@@ -0,0 +1,397 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "iframe.hxx"
+#include <sfx2/sfxdlg.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+
+#include <tools/urlobj.hxx>
+#include <tools/debug.hxx>
+#include <rtl/ustring.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <svtools/miscopt.hxx>
+#include <vcl/window.hxx>
+
+using namespace ::com::sun::star;
+
+namespace sfx2
+{
+
+class IFrameWindow_Impl : public Window
+{
+ uno::Reference < frame::XFrame > mxFrame;
+ sal_Bool bActive;
+ sal_Bool bBorder;
+
+public:
+ IFrameWindow_Impl( Window *pParent,
+ sal_Bool bHasBorder,
+ WinBits nWinBits = 0 );
+
+public:
+ void SetBorder( sal_Bool bNewBorder = sal_True );
+ sal_Bool HasBorder() const { return bBorder; }
+};
+
+IFrameWindow_Impl::IFrameWindow_Impl( Window *pParent, sal_Bool bHasBorder, WinBits nWinBits )
+ : Window( pParent, nWinBits | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_DOCKBORDER )
+ , bActive(sal_False)
+ , bBorder(bHasBorder)
+{
+ if ( !bHasBorder )
+ SetBorderStyle( WINDOW_BORDER_NOBORDER );
+ else
+ SetBorderStyle( WINDOW_BORDER_NORMAL );
+ //SetActivateMode( ACTIVATE_MODE_GRABFOCUS );
+}
+
+void IFrameWindow_Impl::SetBorder( sal_Bool bNewBorder )
+{
+ if ( bBorder != bNewBorder )
+ {
+ Size aSize = GetSizePixel();
+ bBorder = bNewBorder;
+ if ( bBorder )
+ SetBorderStyle( WINDOW_BORDER_NORMAL );
+ else
+ SetBorderStyle( WINDOW_BORDER_NOBORDER );
+ if ( GetSizePixel() != aSize )
+ SetSizePixel( aSize );
+ }
+}
+
+#define PROPERTY_UNBOUND 0
+
+#define WID_FRAME_URL 1
+#define WID_FRAME_NAME 2
+#define WID_FRAME_IS_AUTO_SCROLL 3
+#define WID_FRAME_IS_SCROLLING_MODE 4
+#define WID_FRAME_IS_BORDER 5
+#define WID_FRAME_IS_AUTO_BORDER 6
+#define WID_FRAME_MARGIN_WIDTH 7
+#define WID_FRAME_MARGIN_HEIGHT 8
+
+const SfxItemPropertyMapEntry* lcl_GetIFramePropertyMap_Impl()
+{
+ static SfxItemPropertyMapEntry aIFramePropertyMap_Impl[] =
+ {
+ { MAP_CHAR_LEN("FrameIsAutoBorder"), WID_FRAME_IS_AUTO_BORDER, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
+ { MAP_CHAR_LEN("FrameIsAutoScroll"), WID_FRAME_IS_AUTO_SCROLL, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
+ { MAP_CHAR_LEN("FrameIsBorder"), WID_FRAME_IS_BORDER, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
+ { MAP_CHAR_LEN("FrameIsScrollingMode"), WID_FRAME_IS_SCROLLING_MODE, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
+ { MAP_CHAR_LEN("FrameMarginHeight"), WID_FRAME_MARGIN_HEIGHT, &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 },
+ { MAP_CHAR_LEN("FrameMarginWidth"), WID_FRAME_MARGIN_WIDTH, &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 },
+ { MAP_CHAR_LEN("FrameName"), WID_FRAME_NAME, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { MAP_CHAR_LEN("FrameURL"), WID_FRAME_URL, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ {0,0,0,0,0,0}
+ };
+ return aIFramePropertyMap_Impl;
+}
+
+SFX_IMPL_XSERVICEINFO( IFrameObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.IFrameObject" )
+SFX_IMPL_SINGLEFACTORY( IFrameObject );
+
+IFrameObject::IFrameObject( const uno::Reference < lang::XMultiServiceFactory >& rFact )
+ : mxFact( rFact )
+ , maPropMap( lcl_GetIFramePropertyMap_Impl() )
+{
+}
+
+IFrameObject::~IFrameObject()
+{
+}
+
+
+void SAL_CALL IFrameObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
+{
+ if ( aArguments.getLength() )
+ aArguments[0] >>= mxObj;
+}
+
+sal_Bool SAL_CALL IFrameObject::load(
+ const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
+ const uno::Reference < frame::XFrame >& xFrame )
+throw( uno::RuntimeException )
+{
+ if ( SvtMiscOptions().IsPluginsEnabled() )
+ {
+ DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
+ Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
+ IFrameWindow_Impl* pWin = new IFrameWindow_Impl( pParent, maFrmDescr.IsFrameBorderOn() );
+ pWin->SetSizePixel( pParent->GetOutputSizePixel() );
+ pWin->SetBackground();
+ pWin->Show();
+
+ uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
+ xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
+
+ // we must destroy the IFrame before the parent is destroyed
+ xWindow->addEventListener( this );
+
+ mxFrame = uno::Reference< frame::XFrame >( mxFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Frame" ) ),
+ uno::UNO_QUERY );
+ uno::Reference < awt::XWindow > xWin( pWin->GetComponentInterface(), uno::UNO_QUERY );
+ mxFrame->initialize( xWin );
+ mxFrame->setName( maFrmDescr.GetName() );
+
+ uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, uno::UNO_QUERY );
+ if ( xFramesSupplier.is() )
+ mxFrame->setCreator( xFramesSupplier );
+
+ uno::Reference< frame::XDispatchProvider > xProv( mxFrame, uno::UNO_QUERY );
+
+ util::URL aTargetURL;
+ aTargetURL.Complete = ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
+ uno::Reference < util::XURLTransformer > xTrans( mxFact->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), uno::UNO_QUERY );
+ xTrans->parseStrict( aTargetURL );
+
+ uno::Sequence < beans::PropertyValue > aProps(2);
+ aProps[0].Name = ::rtl::OUString::createFromAscii("PluginMode");
+ aProps[0].Value <<= (sal_Int16) 2;
+ aProps[1].Name = ::rtl::OUString::createFromAscii("ReadOnly");
+ aProps[1].Value <<= (sal_Bool) sal_True;
+ uno::Reference < frame::XDispatch > xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_self"), 0 );
+ if ( xDisp.is() )
+ xDisp->dispatch( aTargetURL, aProps );
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void SAL_CALL IFrameObject::cancel() throw( com::sun::star::uno::RuntimeException )
+{
+ try
+ {
+ uno::Reference < util::XCloseable > xClose( mxFrame, uno::UNO_QUERY );
+ if ( xClose.is() )
+ xClose->close( sal_True );
+ mxFrame = 0;
+ }
+ catch ( uno::Exception& )
+ {}
+}
+
+void SAL_CALL IFrameObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL IFrameObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL IFrameObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL IFrameObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
+{
+ cancel();
+}
+
+uno::Reference< beans::XPropertySetInfo > SAL_CALL IFrameObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
+{
+ static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap );
+ return xInfo;
+}
+
+void SAL_CALL IFrameObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
+ throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
+{
+ const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
+ if( !pEntry )
+ throw beans::UnknownPropertyException();
+ switch( pEntry->nWID )
+ {
+ case WID_FRAME_URL:
+ {
+ ::rtl::OUString aURL;
+ aAny >>= aURL;
+ maFrmDescr.SetURL( String(aURL) );
+ }
+ break;
+ case WID_FRAME_NAME:
+ {
+ ::rtl::OUString aName;
+ if ( aAny >>= aName )
+ maFrmDescr.SetName( aName );
+ }
+ break;
+ case WID_FRAME_IS_AUTO_SCROLL:
+ {
+ sal_Bool bIsAutoScroll = sal_Bool();
+ if ( (aAny >>= bIsAutoScroll) && bIsAutoScroll )
+ maFrmDescr.SetScrollingMode( ScrollingAuto );
+ }
+ break;
+ case WID_FRAME_IS_SCROLLING_MODE:
+ {
+ sal_Bool bIsScroll = sal_Bool();
+ if ( aAny >>= bIsScroll )
+ maFrmDescr.SetScrollingMode( bIsScroll ? ScrollingYes : ScrollingNo );
+ }
+ break;
+ case WID_FRAME_IS_BORDER:
+ {
+ sal_Bool bIsBorder = sal_Bool();
+ if ( aAny >>= bIsBorder )
+ maFrmDescr.SetFrameBorder( bIsBorder );
+ }
+ break;
+ case WID_FRAME_IS_AUTO_BORDER:
+ {
+ sal_Bool bIsAutoBorder = sal_Bool();
+ if ( (aAny >>= bIsAutoBorder) )
+ {
+ BOOL bBorder = maFrmDescr.IsFrameBorderOn();
+ maFrmDescr.ResetBorder();
+ if ( bIsAutoBorder )
+ maFrmDescr.SetFrameBorder( bBorder );
+ }
+ }
+ break;
+ case WID_FRAME_MARGIN_WIDTH:
+ {
+ sal_Int32 nMargin = 0;
+ Size aSize = maFrmDescr.GetMargin();
+ if ( aAny >>= nMargin )
+ {
+ aSize.Width() = nMargin;
+ maFrmDescr.SetMargin( aSize );
+ }
+ }
+ break;
+ case WID_FRAME_MARGIN_HEIGHT:
+ {
+ sal_Int32 nMargin = 0;
+ Size aSize = maFrmDescr.GetMargin();
+ if ( aAny >>= nMargin )
+ {
+ aSize.Height() = nMargin;
+ maFrmDescr.SetMargin( aSize );
+ }
+ }
+ break;
+ default: ;
+ }
+}
+
+uno::Any SAL_CALL IFrameObject::getPropertyValue(const ::rtl::OUString& aPropertyName)
+ throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
+{
+ const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
+ if( !pEntry )
+ throw beans::UnknownPropertyException();
+ uno::Any aAny;
+ switch( pEntry->nWID )
+ {
+ case WID_FRAME_URL:
+ {
+ aAny <<= ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
+ }
+ break;
+ case WID_FRAME_NAME:
+ {
+ aAny <<= ::rtl::OUString( maFrmDescr.GetName() );
+ }
+ break;
+ case WID_FRAME_IS_AUTO_SCROLL:
+ {
+ sal_Bool bIsAutoScroll = ( maFrmDescr.GetScrollingMode() == ScrollingAuto );
+ aAny <<= bIsAutoScroll;
+ }
+ break;
+ case WID_FRAME_IS_SCROLLING_MODE:
+ {
+ sal_Bool bIsScroll = ( maFrmDescr.GetScrollingMode() == ScrollingYes );
+ aAny <<= bIsScroll;
+ }
+ break;
+ case WID_FRAME_IS_BORDER:
+ {
+ sal_Bool bIsBorder = maFrmDescr.IsFrameBorderOn();
+ aAny <<= bIsBorder;
+ }
+ break;
+ case WID_FRAME_IS_AUTO_BORDER:
+ {
+ sal_Bool bIsAutoBorder = !maFrmDescr.IsFrameBorderSet();
+ aAny <<= bIsAutoBorder;
+ }
+ break;
+ case WID_FRAME_MARGIN_WIDTH:
+ {
+ aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Width();
+ }
+ break;
+ case WID_FRAME_MARGIN_HEIGHT:
+ {
+ aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Height();
+ }
+ default: ;
+ }
+ return aAny;
+}
+
+void SAL_CALL IFrameObject::addPropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL IFrameObject::removePropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL IFrameObject::addVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL IFrameObject::removeVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+::sal_Int16 SAL_CALL IFrameObject::execute() throw (::com::sun::star::uno::RuntimeException)
+{
+ SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
+ VclAbstractDialog* pDlg = pFact->CreateEditObjectDialog( NULL, rtl::OUString::createFromAscii(".uno:InsertObjectFloatingFrame"), mxObj );
+ if ( pDlg )
+ pDlg->Execute();
+ return 0;
+}
+
+void SAL_CALL IFrameObject::setTitle( const ::rtl::OUString& ) throw (::com::sun::star::uno::RuntimeException)
+{
+}
+
+}
diff --git a/sfx2/source/doc/new.cxx b/sfx2/source/doc/new.cxx
new file mode 100644
index 000000000000..932f6f10ecb0
--- /dev/null
+++ b/sfx2/source/doc/new.cxx
@@ -0,0 +1,741 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <sfx2/new.hxx>
+#include <vcl/gdimtf.hxx>
+#include <vcl/msgbox.hxx>
+#include <vcl/morebtn.hxx>
+#include <svtools/svmedit.hxx>
+#include <svl/itemset.hxx>
+#include <svl/eitem.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/localfilehelper.hxx>
+
+#include "new.hrc"
+#include "doc.hrc"
+#include <sfx2/sfx.hrc>
+#include "helpid.hrc"
+#include "sfxtypes.hxx"
+#include <sfx2/app.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/objsh.hxx>
+#include "fltfnc.hxx"
+#include <sfx2/viewsh.hxx>
+#include "sfx2/viewfac.hxx"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/docfile.hxx>
+#include "preview.hxx"
+#include <sfx2/printer.hxx>
+#include <vcl/waitobj.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/jobset.hxx>
+#include <svtools/accessibilityoptions.hxx>
+
+// Draw modes
+#define OUTPUT_DRAWMODE_COLOR (DRAWMODE_DEFAULT)
+#define OUTPUT_DRAWMODE_GRAYSCALE (DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_BLACKTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT)
+#define OUTPUT_DRAWMODE_BLACKWHITE (DRAWMODE_BLACKLINE | DRAWMODE_BLACKTEXT | DRAWMODE_WHITEFILL | DRAWMODE_GRAYBITMAP | DRAWMODE_WHITEGRADIENT)
+#define OUTPUT_DRAWMODE_CONTRAST (DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT)
+
+//========================================================================
+
+#define MORE_BTN(x) pMoreBt->x
+
+//========================================================================
+
+void SfxPreviewBase_Impl::SetObjectShell( SfxObjectShell* pObj )
+{
+ ::boost::shared_ptr<GDIMetaFile> pFile = pObj
+ ? pObj->GetPreviewMetaFile()
+ : ::boost::shared_ptr<GDIMetaFile>();
+ pMetaFile = pFile;
+ Invalidate();
+}
+
+SfxPreviewBase_Impl::SfxPreviewBase_Impl(
+ Window* pParent, const ResId& rResId )
+ : Window(pParent, rResId), pMetaFile()
+{
+}
+
+SfxPreviewBase_Impl::SfxPreviewBase_Impl( Window* pParent )
+ : Window(pParent, 0 ), pMetaFile()
+{
+ Resize();
+ Show();
+}
+
+SfxPreviewBase_Impl::~SfxPreviewBase_Impl()
+{
+}
+
+void SfxPreviewBase_Impl::Resize()
+{
+ Invalidate();
+}
+
+void SfxPreviewBase_Impl::SetGDIFile( ::boost::shared_ptr<GDIMetaFile> pFile )
+{
+ pMetaFile = pFile;
+ Invalidate();
+}
+
+SfxFrameWindow* SfxPreviewWin_Impl::PreviewFactory(
+ SfxFrame* pFrame, const String& /*rName*/ )
+{
+ return new SfxFrameWindow( new SfxPreviewWin_Impl(
+ &pFrame->GetCurrentViewFrame()->GetWindow() ) );
+}
+
+void SfxPreviewWin_Impl::ImpPaint(
+ const Rectangle&, GDIMetaFile* pFile, Window* pWindow )
+{
+ Size aTmpSize = pFile ? pFile->GetPrefSize() : Size(1,1 );
+ DBG_ASSERT( aTmpSize.Height()*aTmpSize.Width(),
+ "size of first page is 0, overload GetFirstPageSize or set vis-area!" );
+#define FRAME 4
+ long nWidth = pWindow->GetOutputSize().Width() - 2*FRAME;
+ long nHeight = pWindow->GetOutputSize().Height() - 2*FRAME;
+ if( nWidth < 0 ) nWidth = 0;
+ if( nHeight < 0 ) nHeight = 0;
+
+ double dRatio=((double)aTmpSize.Width())/aTmpSize.Height();
+ double dRatioPreV=((double) nWidth ) / nHeight;
+ Size aSize;
+ Point aPoint;
+ if (dRatio>dRatioPreV)
+ {
+ aSize=Size(nWidth, (USHORT)(nWidth/dRatio));
+ aPoint=Point( 0, (USHORT)((nHeight-aSize.Height())/2));
+ }
+ else
+ {
+ aSize=Size((USHORT)(nHeight*dRatio), nHeight);
+ aPoint=Point((USHORT)((nWidth-aSize.Width())/2),0);
+ }
+ Point bPoint=Point(nWidth,nHeight)-aPoint;
+
+
+ pWindow->SetLineColor();
+ Color aLightGrayCol( COL_LIGHTGRAY );
+ pWindow->SetFillColor( aLightGrayCol );
+ pWindow->DrawRect( Rectangle( Point( 0,0 ), pWindow->GetOutputSize() ) );
+ if ( pFile )
+ {
+ Color aBlackCol( COL_BLACK );
+ Color aWhiteCol( COL_WHITE );
+ pWindow->SetLineColor( aBlackCol );
+ pWindow->SetFillColor( aWhiteCol );
+ pWindow->DrawRect( Rectangle( aPoint + Point( FRAME, FRAME ), bPoint + Point( FRAME, FRAME ) ) );
+//! pFile->Move( Point( FRAME, FRAME ) );
+//! pFile->Scale( Fraction( aTmpSize.Width(), aSize.Width() ),
+//! Fraction( aTmpSize.Height(), aSize.Height() ) );
+ pFile->WindStart();
+ pFile->Play( pWindow, aPoint + Point( FRAME, FRAME ), aSize );
+ }
+}
+
+void SfxPreviewWin_Impl::Paint( const Rectangle& rRect )
+{
+ ImpPaint( rRect, pMetaFile.get(), this );
+}
+
+SfxPreviewWin::SfxPreviewWin(
+ Window* pParent, const ResId& rResId, SfxObjectShellLock &rDocSh )
+ : Window(pParent, rResId), rDocShell( rDocSh )
+{
+ SetHelpId( HID_PREVIEW_FRAME );
+
+ // adjust contrast mode initially
+ bool bUseContrast = UseHighContrastSetting();
+ SetDrawMode( bUseContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
+
+ // #107818# This preview window is for document previews. Therefore
+ // right-to-left mode should be off
+ EnableRTL( FALSE );
+}
+
+void SfxPreviewWin::Paint( const Rectangle& rRect )
+{
+ SfxViewFrame *pFrame = SfxViewFrame::GetFirst( &rDocShell );
+ if ( pFrame && pFrame->GetViewShell() &&
+ pFrame->GetViewShell()->GetPrinter() &&
+ pFrame->GetViewShell()->GetPrinter()->IsPrinting() )
+ {
+ return;
+ }
+
+ Size aTmpSize( rDocShell->GetFirstPageSize() );
+ GDIMetaFile aMtf;
+ VirtualDevice aDevice;
+
+ DBG_ASSERT( aTmpSize.Height() * aTmpSize.Width(), "size of first page is 0, overload GetFirstPageSize or set vis-area!" );
+
+ aMtf.SetPrefSize( aTmpSize );
+ aDevice.EnableOutput( FALSE );
+ aDevice.SetMapMode( rDocShell->GetMapUnit() );
+ aDevice.SetDrawMode( GetDrawMode() );
+ aMtf.Record( &aDevice );
+ rDocShell->DoDraw( &aDevice, Point(0,0), aTmpSize, JobSetup(), ASPECT_THUMBNAIL );
+ aMtf.Stop();
+ aMtf.WindStart();
+ SfxPreviewWin_Impl::ImpPaint( rRect, &aMtf, this );
+}
+
+void SfxPreviewWin::DataChanged( const DataChangedEvent& rDCEvt )
+{
+ Window::DataChanged( rDCEvt );
+
+ if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
+ (rDCEvt.GetFlags() & SETTINGS_STYLE) )
+ {
+ // adjust contrast mode
+ bool bUseContrast = UseHighContrastSetting();
+ SetDrawMode( bUseContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
+ }
+}
+
+bool SfxPreviewWin::UseHighContrastSetting() const
+{
+ return GetSettings().GetStyleSettings().GetHighContrastMode();
+}
+
+
+class SfxNewFileDialog_Impl
+{
+ FixedText aRegionFt;
+ ListBox aRegionLb;
+ FixedText aTemplateFt;
+ ListBox aTemplateLb;
+
+ CheckBox aPreviewBtn;
+ SfxPreviewWin_Impl aPreviewWin;
+
+ FixedText aTitleFt;
+ Edit aTitleEd;
+ FixedText aThemaFt;
+ Edit aThemaEd;
+ FixedText aKeywordsFt;
+ Edit aKeywordsEd;
+ FixedText aDescFt;
+ MultiLineEdit aDescEd;
+ FixedLine aDocinfoGb;
+
+ CheckBox aTextStyleCB;
+ CheckBox aFrameStyleCB;
+ CheckBox aPageStyleCB;
+ CheckBox aNumStyleCB;
+ CheckBox aMergeStyleCB;
+ PushButton aLoadFilePB;
+
+ OKButton aOkBt;
+ CancelButton aCancelBt;
+ HelpButton aHelpBt;
+ MoreButton* pMoreBt;
+ Timer aPrevTimer;
+ String aNone;
+ String sLoadTemplate;
+
+ USHORT nFlags;
+ SfxDocumentTemplates aTemplates;
+ SfxObjectShellLock xDocShell;
+ SfxNewFileDialog* pAntiImpl;
+
+ void ClearInfo();
+ DECL_LINK( Update, void * );
+
+ DECL_LINK( RegionSelect, ListBox * );
+ DECL_LINK( TemplateSelect, ListBox * );
+ DECL_LINK( DoubleClick, ListBox * );
+ void TogglePreview(CheckBox *);
+ DECL_LINK( Expand, MoreButton * );
+ DECL_LINK( PreviewClick, CheckBox * );
+ DECL_LINK( LoadFile, PushButton* );
+ USHORT GetSelectedTemplatePos() const;
+
+public:
+
+ SfxNewFileDialog_Impl( SfxNewFileDialog* pAntiImplP, USHORT nFlags );
+ ~SfxNewFileDialog_Impl();
+
+ // Liefert FALSE, wenn '- Keine -' als Vorlage eingestellt ist
+ // Nur wenn IsTemplate() TRUE liefert, koennen Vorlagennamen
+ // erfragt werden
+ BOOL IsTemplate() const;
+ String GetTemplateRegion() const;
+ String GetTemplateName() const;
+ String GetTemplateFileName() const;
+
+ USHORT GetTemplateFlags()const;
+ void SetTemplateFlags(USHORT nSet);
+};
+
+
+//-------------------------------------------------------------------------
+
+void SfxNewFileDialog_Impl::ClearInfo()
+{
+ const String aNo;
+ aTitleEd.SetText(aNo);
+ aThemaEd.SetText(aNo);
+ aKeywordsEd.SetText(aNo);
+ aDescEd.SetText(aNo);
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxNewFileDialog_Impl, Update, void *, EMPTYARG )
+{
+ if ( xDocShell.Is() )
+ {
+ if ( xDocShell->GetProgress() )
+ return FALSE;
+ xDocShell.Clear();
+ }
+
+ const USHORT nEntry = GetSelectedTemplatePos();
+ if(!nEntry)
+ {
+ ClearInfo();
+ aPreviewWin.Invalidate();
+ aPreviewWin.SetObjectShell( 0);
+ return 0;
+ }
+
+ if ( aPreviewBtn.IsChecked() && (nFlags & SFXWB_PREVIEW) == SFXWB_PREVIEW)
+ {
+
+ String aFileName = aTemplates.GetPath( aRegionLb.GetSelectEntryPos(), nEntry-1);
+ INetURLObject aTestObj( aFileName );
+ if( aTestObj.GetProtocol() == INET_PROT_NOT_VALID )
+ {
+ // temp. fix until Templates are managed by UCB compatible service
+ // does NOT work with locally cached components !
+ String aTemp;
+ utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName, aTemp );
+ aFileName = aTemp;
+ }
+
+ INetURLObject aObj( aFileName );
+ for ( SfxObjectShell* pTmp = SfxObjectShell::GetFirst();
+ pTmp;
+ pTmp = SfxObjectShell::GetNext(*pTmp) )
+ {
+ //! fsys bug op==
+ if ( pTmp->GetMedium())
+ // ??? HasName() MM
+ if( INetURLObject( pTmp->GetMedium()->GetName() ) == aObj )
+ {
+ xDocShell = pTmp;
+ break;
+ }
+ }
+
+ if ( !xDocShell.Is() )
+ {
+ Window *pParent = Application::GetDefDialogParent();
+ Application::SetDefDialogParent( pAntiImpl );
+ SfxErrorContext eEC(ERRCTX_SFX_LOADTEMPLATE,pAntiImpl);
+ SfxApplication *pSfxApp = SFX_APP();
+ ULONG lErr;
+ SfxItemSet* pSet = new SfxAllItemSet( pSfxApp->GetPool() );
+ pSet->Put( SfxBoolItem( SID_TEMPLATE, TRUE ) );
+ pSet->Put( SfxBoolItem( SID_PREVIEW, TRUE ) );
+ lErr = pSfxApp->LoadTemplate( xDocShell, aFileName, TRUE, pSet );
+ if( lErr )
+ ErrorHandler::HandleError(lErr);
+ Application::SetDefDialogParent( pParent );
+ if ( !xDocShell.Is() )
+ {
+ aPreviewWin.SetObjectShell( 0 );
+ return FALSE;
+ }
+ }
+
+ aPreviewWin.SetObjectShell( xDocShell );
+ }
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxNewFileDialog_Impl, RegionSelect, ListBox *, pBox )
+{
+ if ( xDocShell.Is() && xDocShell->GetProgress() )
+ return 0;
+
+ const USHORT nRegion = pBox->GetSelectEntryPos();
+ const USHORT nCount = aTemplates.GetRegionCount()? aTemplates.GetCount(nRegion): 0;
+ aTemplateLb.SetUpdateMode(FALSE);
+ aTemplateLb.Clear();
+ String aSel=aRegionLb.GetSelectEntry();
+ USHORT nc=aSel.Search('(');
+ if (nc-1&&nc!=STRING_NOTFOUND)
+ aSel.Erase(nc-1);
+ if (aSel.CompareIgnoreCaseToAscii( String(SfxResId(STR_STANDARD)) )==COMPARE_EQUAL)
+ aTemplateLb.InsertEntry(aNone);
+ for (USHORT i = 0; i < nCount; ++i)
+ aTemplateLb.InsertEntry(aTemplates.GetName(nRegion, i));
+ aTemplateLb.SelectEntryPos(0);
+ aTemplateLb.SetUpdateMode(TRUE);
+ aTemplateLb.Invalidate();
+ aTemplateLb.Update();
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxNewFileDialog_Impl, Expand, MoreButton *, EMPTYARG )
+{
+ TemplateSelect(&aTemplateLb);
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxNewFileDialog_Impl, Expand, MoreButton *, pMoreButton )
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxNewFileDialog_Impl, PreviewClick, CheckBox *, pBox )
+{
+ if ( xDocShell.Is() && xDocShell->GetProgress() )
+ return 0;
+
+ USHORT nEntry = GetSelectedTemplatePos();
+ if ( nEntry && pBox->IsChecked() )
+ {
+ if(!Update(0))
+ aPreviewWin.Invalidate();
+ }
+ else
+ {
+ if (xDocShell.Is())
+ xDocShell.Clear();
+ aPreviewWin.SetObjectShell( 0 );
+ }
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxNewFileDialog_Impl, TemplateSelect, ListBox *, EMPTYARG )
+{
+ // noch am Laden
+ if ( xDocShell && xDocShell->GetProgress() )
+ return 0;
+
+ if ( !MORE_BTN(GetState()) )
+ // Dialog nicht aufgeklappt
+ return 0;
+
+ aPrevTimer.Start();
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxNewFileDialog_Impl, DoubleClick, ListBox *, pListBox )
+{
+ (void)pListBox;
+ // noch am Laden
+ if ( !xDocShell.Is() || !xDocShell->GetProgress() )
+ pAntiImpl->EndDialog(RET_OK);
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxNewFileDialog_Impl, DoubleClick, ListBox *, pListBox )
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxNewFileDialog_Impl, LoadFile, PushButton *, EMPTYARG )
+{
+ pAntiImpl->EndDialog(RET_TEMPLATE_LOAD);
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxNewFileDialog_Impl, LoadFile, PushButton *, EMPTYARG )
+//-------------------------------------------------------------------------
+
+USHORT SfxNewFileDialog_Impl::GetSelectedTemplatePos() const
+{
+ USHORT nEntry=aTemplateLb.GetSelectEntryPos();
+ String aSel=aRegionLb.GetSelectEntry().Copy();
+ USHORT nc=aSel.Search('(');
+ if (nc-1&&nc!=STRING_NOTFOUND)
+ aSel.Erase(nc-1);
+ if (aSel.CompareIgnoreCaseToAscii(String(SfxResId(STR_STANDARD)))!=COMPARE_EQUAL)
+ nEntry++;
+ if (!aTemplateLb.GetSelectEntryCount())
+ nEntry=0;
+ return nEntry;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxNewFileDialog_Impl::IsTemplate() const
+{
+ return GetSelectedTemplatePos()!=0;
+
+}
+
+//-------------------------------------------------------------------------
+
+String SfxNewFileDialog_Impl::GetTemplateFileName() const
+{
+ if(!IsTemplate() || !aTemplates.GetRegionCount())
+ return String();
+ return aTemplates.GetPath(aRegionLb.GetSelectEntryPos(),
+ GetSelectedTemplatePos()-1);
+}
+
+//-------------------------------------------------------------------------
+
+String SfxNewFileDialog_Impl::GetTemplateRegion() const
+{
+ if(!IsTemplate() || !aTemplates.GetRegionCount())
+ return String();
+ return aRegionLb.GetSelectEntry();
+}
+
+//-------------------------------------------------------------------------
+
+String SfxNewFileDialog_Impl::GetTemplateName() const
+{
+ if(!IsTemplate() || !aTemplates.GetRegionCount())
+ return String();
+ return aTemplateLb.GetSelectEntry();
+}
+
+//-------------------------------------------------------------------------
+
+void AdjustPosSize_Impl(Window *pWin, short nMoveOffset, short nSizeOffset)
+{
+ Point aPos(pWin->GetPosPixel());
+ Size aSize(pWin->GetSizePixel());
+ aPos.X() -= nMoveOffset;
+ aSize.Width() += nSizeOffset;
+ pWin->SetPosSizePixel(aPos, aSize);
+}
+//-------------------------------------------------------------------------
+USHORT SfxNewFileDialog_Impl::GetTemplateFlags()const
+{
+ USHORT nRet = aTextStyleCB.IsChecked() ? SFX_LOAD_TEXT_STYLES : 0;
+ if(aFrameStyleCB.IsChecked())
+ nRet |= SFX_LOAD_FRAME_STYLES;
+ if(aPageStyleCB.IsChecked())
+ nRet |= SFX_LOAD_PAGE_STYLES;
+ if(aNumStyleCB.IsChecked())
+ nRet |= SFX_LOAD_NUM_STYLES;
+ if(aMergeStyleCB.IsChecked())
+ nRet |= SFX_MERGE_STYLES;
+ return nRet;
+}
+//-------------------------------------------------------------------------
+void SfxNewFileDialog_Impl::SetTemplateFlags(USHORT nSet)
+{
+ aTextStyleCB.Check( 0 != (nSet&SFX_LOAD_TEXT_STYLES ));
+ aFrameStyleCB.Check( 0 != (nSet&SFX_LOAD_FRAME_STYLES));
+ aPageStyleCB.Check( 0 != (nSet&SFX_LOAD_PAGE_STYLES ));
+ aNumStyleCB.Check( 0 != (nSet&SFX_LOAD_NUM_STYLES ));
+ aMergeStyleCB.Check( 0 != (nSet&SFX_MERGE_STYLES ));
+}
+
+//-------------------------------------------------------------------------
+
+SfxNewFileDialog_Impl::SfxNewFileDialog_Impl(
+ SfxNewFileDialog* pAntiImplP, USHORT nFl)
+ : aRegionFt( pAntiImplP, SfxResId( FT_REGION ) ),
+ aRegionLb( pAntiImplP, SfxResId( LB_REGION ) ),
+ aTemplateFt( pAntiImplP, SfxResId( FT_TEMPLATE ) ),
+ aTemplateLb( pAntiImplP, SfxResId( LB_TEMPLATE ) ),
+ aPreviewBtn( pAntiImplP, SfxResId( BTN_PREVIEW ) ),
+ aPreviewWin( pAntiImplP, SfxResId( WIN_PREVIEW ) ),
+ aTitleFt( pAntiImplP, SfxResId( FT_TITLE ) ),
+ aTitleEd( pAntiImplP, SfxResId( ED_TITLE ) ),
+ aThemaFt( pAntiImplP, SfxResId( FT_THEMA ) ),
+ aThemaEd( pAntiImplP, SfxResId( ED_THEMA ) ),
+ aKeywordsFt( pAntiImplP, SfxResId( FT_KEYWORDS ) ),
+ aKeywordsEd( pAntiImplP, SfxResId( ED_KEYWORDS ) ),
+ aDescFt( pAntiImplP, SfxResId( FT_DESC ) ),
+ aDescEd( pAntiImplP, SfxResId( ED_DESC ) ),
+ aDocinfoGb( pAntiImplP, SfxResId( GB_DOCINFO ) ),
+ aTextStyleCB( pAntiImplP, SfxResId( CB_TEXT_STYLE )),
+ aFrameStyleCB( pAntiImplP, SfxResId( CB_FRAME_STYLE )),
+ aPageStyleCB( pAntiImplP, SfxResId( CB_PAGE_STYLE )),
+ aNumStyleCB( pAntiImplP, SfxResId( CB_NUM_STYLE )),
+ aMergeStyleCB( pAntiImplP, SfxResId( CB_MERGE_STYLE )),
+ aLoadFilePB( pAntiImplP, SfxResId( PB_LOAD_FILE )),
+ aOkBt( pAntiImplP, SfxResId( BT_OK ) ),
+ aCancelBt( pAntiImplP, SfxResId( BT_CANCEL ) ),
+ aHelpBt( pAntiImplP, SfxResId( BT_HELP ) ),
+ pMoreBt( new MoreButton( pAntiImplP, SfxResId( BT_MORE ) ) ),
+ aNone( SfxResId(STR_NONE) ),
+ sLoadTemplate( SfxResId(STR_LOAD_TEMPLATE)),
+ nFlags(nFl),
+ pAntiImpl( pAntiImplP )
+{
+ short nMoveOffset = *(short *)pAntiImplP->GetClassRes();
+ pAntiImplP->IncrementRes(sizeof(short));
+ short nExpandSize= *(short *)pAntiImplP->GetClassRes();
+ pAntiImplP->IncrementRes(sizeof(short));
+ pAntiImplP->FreeResource();
+
+ if (!nFlags)
+ MORE_BTN(Hide());
+ else if(SFXWB_LOAD_TEMPLATE == nFlags)
+ {
+ aLoadFilePB.SetClickHdl(LINK(this, SfxNewFileDialog_Impl, LoadFile));
+ aLoadFilePB.Show();
+ aTextStyleCB.Show();
+ aFrameStyleCB.Show();
+ aPageStyleCB.Show();
+ aNumStyleCB.Show();
+ aMergeStyleCB.Show();
+ Size aSize(pAntiImplP->GetOutputSizePixel());
+ Size aTmp(pAntiImplP->LogicToPixel(Size(16, 16), MAP_APPFONT));
+ aSize.Height() += aTmp.Height();
+ pAntiImplP->SetOutputSizePixel(aSize);
+ pMoreBt->Hide();
+ aTextStyleCB.Check();
+ pAntiImplP->SetText(sLoadTemplate);
+ }
+ else
+ {
+ MORE_BTN(SetClickHdl(LINK(this, SfxNewFileDialog_Impl, Expand)));
+ if((nFlags & SFXWB_PREVIEW) == SFXWB_PREVIEW)
+ {
+ MORE_BTN(AddWindow(&aPreviewBtn));
+ MORE_BTN(AddWindow(&aPreviewWin));
+ aPreviewBtn.SetClickHdl(LINK(this, SfxNewFileDialog_Impl, PreviewClick));
+ }
+ else
+ {
+ aPreviewBtn.Hide();
+ aPreviewWin.Hide();
+ nMoveOffset = (short)pAntiImplP->LogicToPixel(
+ Size(nMoveOffset, nMoveOffset), MAP_APPFONT).Width();
+ nExpandSize = (short)pAntiImplP->LogicToPixel(
+ Size(nExpandSize, nExpandSize), MAP_APPFONT).Width();
+ AdjustPosSize_Impl(&aTitleFt, nMoveOffset, 0);
+ AdjustPosSize_Impl(&aTitleEd, nMoveOffset, nExpandSize);
+ AdjustPosSize_Impl(&aThemaFt, nMoveOffset, 0);
+ AdjustPosSize_Impl(&aThemaEd, nMoveOffset, nExpandSize);
+ AdjustPosSize_Impl(&aKeywordsFt, nMoveOffset, 0);
+ AdjustPosSize_Impl(&aKeywordsEd, nMoveOffset, nExpandSize);
+ AdjustPosSize_Impl(&aDescFt , nMoveOffset, 0);
+ AdjustPosSize_Impl(&aDescEd , nMoveOffset, nExpandSize);
+ AdjustPosSize_Impl(&aDocinfoGb, nMoveOffset, nExpandSize);
+ }
+ }
+
+ String &rExtra = pAntiImplP->GetExtraData();
+ USHORT nTokCount = rExtra.GetTokenCount( '|' );
+ if( nTokCount > 0 && nFlags )
+ MORE_BTN(SetState( rExtra.GetToken( 0, '|' ) == 'Y' ));
+ if( nTokCount > 1 && nFlags )
+ aPreviewBtn.Check( rExtra.GetToken( 1 ,'|' ) == 'Y' );
+
+ aTemplateLb.SetDoubleClickHdl(LINK(this, SfxNewFileDialog_Impl, DoubleClick));
+
+ // update the template configuration if necessary
+ {
+ WaitObject aWaitCursor( pAntiImplP->GetParent() );
+ aTemplates.Update( sal_True /* be smart */ );
+ }
+ // fill the list boxes
+ const USHORT nCount = aTemplates.GetRegionCount();
+ if (nCount)
+ {
+ for(USHORT i = 0; i < nCount; ++i)
+ aRegionLb.InsertEntry(aTemplates.GetFullRegionName(i));
+ aRegionLb.SetSelectHdl(LINK(this, SfxNewFileDialog_Impl, RegionSelect));
+ }
+
+ aPrevTimer.SetTimeout( 500 );
+ aPrevTimer.SetTimeoutHdl( LINK( this, SfxNewFileDialog_Impl, Update));
+
+// else
+// aRegionLb.InsertEntry(String(SfxResId(STR_STANDARD)));
+ aRegionLb.SelectEntryPos(0);
+ RegionSelect(&aRegionLb);
+}
+
+//-------------------------------------------------------------------------
+
+SfxNewFileDialog_Impl::~SfxNewFileDialog_Impl()
+{
+ String &rExtra = pAntiImpl->GetExtraData();
+ rExtra = MORE_BTN(GetState()) ? 'Y' : 'N';
+ rExtra += '|';
+ rExtra += aPreviewBtn.IsChecked() ? 'Y' : 'N';
+
+ delete pMoreBt;
+}
+//-------------------------------------------------------------------------
+SfxNewFileDialog::SfxNewFileDialog(Window *pParent, USHORT nFlags)
+ : SfxModalDialog( pParent, SfxResId( DLG_NEW_FILE ) )
+{
+ pImpl = new SfxNewFileDialog_Impl( this, nFlags );
+}
+//-------------------------------------------------------------------------
+SfxNewFileDialog::~SfxNewFileDialog()
+{
+ delete pImpl;
+}
+//-------------------------------------------------------------------------
+BOOL SfxNewFileDialog::IsTemplate() const
+{
+ return pImpl->IsTemplate();
+}
+//-------------------------------------------------------------------------
+String SfxNewFileDialog::GetTemplateRegion() const
+{
+ return pImpl->GetTemplateRegion();
+}
+//-------------------------------------------------------------------------
+String SfxNewFileDialog::GetTemplateName() const
+{
+ return pImpl->GetTemplateName();
+}
+//-------------------------------------------------------------------------
+String SfxNewFileDialog::GetTemplateFileName() const
+{
+ return pImpl->GetTemplateFileName();
+}
+//-------------------------------------------------------------------------
+USHORT SfxNewFileDialog::GetTemplateFlags()const
+{
+ return pImpl->GetTemplateFlags();
+
+}
+//-------------------------------------------------------------------------
+void SfxNewFileDialog::SetTemplateFlags(USHORT nSet)
+{
+ pImpl->SetTemplateFlags(nSet);
+}
+
diff --git a/sfx2/source/doc/new.hrc b/sfx2/source/doc/new.hrc
new file mode 100644
index 000000000000..dd8878bf0177
--- /dev/null
+++ b/sfx2/source/doc/new.hrc
@@ -0,0 +1,57 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#define BTN_PREVIEW 51
+#define WIN_PREVIEW 50
+#define GB_DOCCLASS 1
+#define LB_DOCCLASS 2
+#define GB_DESC 10
+#define FT_DESC 11
+#define FT_STYLESHEETS 19
+#define FT_REGION 20
+#define ED_TITLE 56
+#define ED_KEYWORDS 61
+#define FT_KEYWORDS 60
+#define FT_TITLE 55
+#define ED_DESC 71
+#define FT_DOCINFO 70
+#define LB_REGION 21
+#define BT_OK 30
+#define BT_CANCEL 31
+#define BT_HELP 32
+#define GB_DOCINFO 70
+#define ED_THEMA 55
+#define FT_THEMA 54
+#define FT_TEMPLATE 53
+#define LB_TEMPLATE 52
+#define BT_MORE 32
+#define CB_TEXT_STYLE 33
+#define CB_FRAME_STYLE 34
+#define CB_PAGE_STYLE 35
+#define CB_NUM_STYLE 36
+#define CB_MERGE_STYLE 37
+#define PB_LOAD_FILE 38
+#define STR_LOAD_TEMPLATE 39
diff --git a/sfx2/source/doc/new.src b/sfx2/source/doc/new.src
new file mode 100644
index 000000000000..6737128cce43
--- /dev/null
+++ b/sfx2/source/doc/new.src
@@ -0,0 +1,275 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+ // include ---------------------------------------------------------------
+#include <sfx2/sfx.hrc>
+#include "doc.hrc"
+#include "new.hrc"
+#include <sfx2/sfxcommands.h>
+
+ // pragma ----------------------------------------------------------------
+
+ // DLG_NEW_FILE ----------------------------------------------------------
+ModalDialog DLG_NEW_FILE
+{
+ HelpId = CMD_SID_NEWDOC ;
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Size = MAP_APPFONT ( 336 , 96 ) ;
+ Text [ en-US ] = "New" ;
+ Moveable = TRUE ;
+ OKButton BT_OK
+ {
+ Pos = MAP_APPFONT ( 274 , 6 ) ;
+ Size = MAP_APPFONT ( 56 , 14 ) ;
+ DefButton = TRUE ;
+ };
+ CancelButton BT_CANCEL
+ {
+ Pos = MAP_APPFONT ( 274 , 23 ) ;
+ Size = MAP_APPFONT ( 56 , 14 ) ;
+ };
+ HelpButton BT_HELP
+ {
+ Pos = MAP_APPFONT ( 274 , 43 ) ;
+ Size = MAP_APPFONT ( 56 , 14 ) ;
+ };
+ ListBox LB_REGION
+ {
+ HelpID = "sfx2:ListBox:DLG_NEW_FILE:LB_REGION";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 18 ) ;
+ Size = MAP_APPFONT ( 127 , 72 ) ;
+ CurPos = 0 ;
+ };
+ FixedText FT_REGION
+ {
+ Pos = MAP_APPFONT ( 6 , 6 ) ;
+ Size = MAP_APPFONT ( 97 , 10 ) ;
+ Text [ en-US ] = "~Categories" ;
+ Left = TRUE ;
+ };
+ FixedText FT_TEMPLATE
+ {
+ Pos = MAP_APPFONT ( 139 , 6 ) ;
+ Size = MAP_APPFONT ( 97 , 10 ) ;
+ Text [ en-US ] = "T~emplates" ;
+ Left = TRUE ;
+ };
+ ListBox LB_TEMPLATE
+ {
+ HelpID = "sfx2:ListBox:DLG_NEW_FILE:LB_TEMPLATE";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 139 , 18 ) ;
+ Size = MAP_APPFONT ( 127 , 72 ) ;
+ CurPos = 0 ;
+ };
+ MoreButton BT_MORE
+ {
+ HelpID = "sfx2:MoreButton:DLG_NEW_FILE:BT_MORE";
+ Pos = MAP_APPFONT ( 274 , 70 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ Text [ en-US ] = "~More" ;
+ Delta = 148 ;
+ MapUnit = MAP_APPFONT ;
+ };
+ Window WIN_PREVIEW
+ {
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 6 , 110 ) ;
+ Size = MAP_APPFONT ( 127 , 129 ) ;
+ Hide = TRUE ;
+ SVLook = FALSE ;
+ };
+ CheckBox BTN_PREVIEW
+ {
+ HelpID = "sfx2:CheckBox:DLG_NEW_FILE:BTN_PREVIEW";
+ Pos = MAP_APPFONT ( 6 , 96 ) ;
+ Size = MAP_APPFONT ( 97 , 10 ) ;
+ Text [ en-US ] = "Pre~view" ;
+ Hide = TRUE ;
+ };
+ FixedLine GB_DOCINFO
+ {
+ Pos = MAP_APPFONT ( 139 , 97 ) ;
+ Size = MAP_APPFONT ( 186 , 8 ) ;
+ Hide = TRUE ;
+ Text [ en-US ] = "Description" ;
+ };
+ CheckBox CB_TEXT_STYLE
+ {
+ HelpID = "sfx2:CheckBox:DLG_NEW_FILE:CB_TEXT_STYLE";
+ Pos = MAP_APPFONT ( 6 , 94 ) ;
+ Size = MAP_APPFONT ( 50 , 10 ) ;
+ Hide = TRUE;
+ Text [ en-US ] = "Te~xt" ;
+ };
+ CheckBox CB_FRAME_STYLE
+ {
+ HelpID = "sfx2:CheckBox:DLG_NEW_FILE:CB_FRAME_STYLE";
+ Pos = MAP_APPFONT ( 60 , 94 ) ;
+ Size = MAP_APPFONT ( 50 , 10 ) ;
+ Hide = TRUE;
+ Text [ en-US ] = "~Frame" ;
+ };
+ CheckBox CB_PAGE_STYLE
+ {
+ HelpID = "sfx2:CheckBox:DLG_NEW_FILE:CB_PAGE_STYLE";
+ Pos = MAP_APPFONT ( 114 , 94 ) ;
+ Size = MAP_APPFONT ( 50 , 10 ) ;
+ Hide = TRUE;
+ Text [ en-US ] = "~Pages" ;
+ };
+ CheckBox CB_NUM_STYLE
+ {
+ HelpID = "sfx2:CheckBox:DLG_NEW_FILE:CB_NUM_STYLE";
+ Pos = MAP_APPFONT ( 168 , 94 ) ;
+ Size = MAP_APPFONT ( 50 , 10 ) ;
+ Hide = TRUE;
+ Text [ en-US ] = "N~umbering" ;
+ };
+ CheckBox CB_MERGE_STYLE
+ {
+ HelpID = "sfx2:CheckBox:DLG_NEW_FILE:CB_MERGE_STYLE";
+ Pos = MAP_APPFONT ( 222 , 94 ) ;
+ Size = MAP_APPFONT ( 50 , 10 ) ;
+ Hide = TRUE;
+ Text [ en-US ] = "~Overwrite" ;
+ };
+ PushButton PB_LOAD_FILE
+ {
+ HelpID = "sfx2:PushButton:DLG_NEW_FILE:PB_LOAD_FILE";
+ Pos = MAP_APPFONT ( 274 , 92 ) ;
+ Size = MAP_APPFONT ( 56 , 14 ) ;
+ Hide = TRUE;
+ Text [ en-US ] = "From File...";
+ };
+ String STR_LOAD_TEMPLATE
+ {
+ Text [ en-US ] = "Load Styles" ;
+ };
+ FixedText FT_TITLE
+ {
+ Pos = MAP_APPFONT ( 145 , 108 ) ;
+ Size = MAP_APPFONT ( 175 , 10 ) ;
+ Text [ en-US ] = "~Title" ;
+ Hide = TRUE ;
+ };
+ Edit ED_TITLE
+ {
+ HelpID = "sfx2:Edit:DLG_NEW_FILE:ED_TITLE";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 145 , 121 ) ;
+ Size = MAP_APPFONT ( 175 , 12 ) ;
+ ReadOnly = TRUE ;
+ Hide = TRUE ;
+ };
+ FixedText FT_THEMA
+ {
+ Pos = MAP_APPFONT ( 145 , 135 ) ;
+ Size = MAP_APPFONT ( 175 , 10 ) ;
+ Text [ en-US ] = "Subject" ;
+ Hide = TRUE ;
+ };
+ Edit ED_THEMA
+ {
+ HelpID = "sfx2:Edit:DLG_NEW_FILE:ED_THEMA";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 145 , 148 ) ;
+ Size = MAP_APPFONT ( 175 , 12 ) ;
+ ReadOnly = TRUE ;
+ Hide = TRUE ;
+ };
+ FixedText FT_KEYWORDS
+ {
+ Pos = MAP_APPFONT ( 145 , 162 ) ;
+ Size = MAP_APPFONT ( 175 , 10 ) ;
+ Text [ en-US ] = "~Key words" ;
+ Hide = TRUE ;
+ };
+ Edit ED_KEYWORDS
+ {
+ HelpID = "sfx2:Edit:DLG_NEW_FILE:ED_KEYWORDS";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 145 , 175 ) ;
+ Size = MAP_APPFONT ( 175 , 12 ) ;
+ ReadOnly = TRUE ;
+ Hide = TRUE ;
+ };
+ FixedText FT_DESC
+ {
+ Pos = MAP_APPFONT ( 145 , 189 ) ;
+ Size = MAP_APPFONT ( 175 , 10 ) ;
+ Text [ en-US ] = "~Description" ;
+ Hide = TRUE ;
+ };
+ MultiLineEdit ED_DESC
+ {
+ HelpID = "sfx2:MultiLineEdit:DLG_NEW_FILE:ED_DESC";
+ Border = TRUE ;
+ Pos = MAP_APPFONT ( 144 , 202 ) ;
+ Size = MAP_APPFONT ( 175 , 32 ) ;
+ IgnoreTab = TRUE ;
+ ReadOnly = TRUE ;
+ Hide = TRUE ;
+ };
+ ExtraData =
+ {
+ 103;
+ 44;
+ };
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx
new file mode 100644
index 000000000000..91f5842c1fb7
--- /dev/null
+++ b/sfx2/source/doc/objcont.cxx
@@ -0,0 +1,1281 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/document/UpdateDocMode.hpp>
+#include <com/sun/star/frame/XLayoutManager.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/document/XStandaloneDocumentInfo.hpp>
+#include <com/sun/star/beans/XFastPropertySet.hpp>
+#include <tools/cachestr.hxx>
+#include <vcl/msgbox.hxx>
+#include <svl/style.hxx>
+#include <vcl/wrkwin.hxx>
+
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/rectitem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/urihelper.hxx>
+#include <svl/ctloptions.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <comphelper/processfactory.hxx>
+#include <unotools/securityoptions.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+#include <tools/datetime.hxx>
+#include <math.h>
+
+#include <unotools/saveopt.hxx>
+#include <unotools/useroptions.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/oldprintadaptor.hxx>
+
+#include <sfx2/app.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "appdata.hxx"
+#include <sfx2/dinfdlg.hxx>
+#include "fltfnc.hxx"
+#include <sfx2/docfac.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/objsh.hxx>
+#include "objshimp.hxx"
+#include <sfx2/evntconf.hxx>
+#include "sfx2/sfxhelp.hxx"
+#include <sfx2/dispatch.hxx>
+#include <sfx2/printer.hxx>
+#include "sfx2/basmgr.hxx"
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/doctempl.hxx>
+#include "doc.hrc"
+#include <sfx2/sfxbasemodel.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/request.hxx>
+#include "openflag.hxx"
+#include "querytemplate.hxx"
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+
+//====================================================================
+
+//====================================================================
+
+static
+bool operator> (const util::DateTime& i_rLeft, const util::DateTime& i_rRight)
+{
+ if ( i_rLeft.Year != i_rRight.Year )
+ return i_rLeft.Year > i_rRight.Year;
+
+ if ( i_rLeft.Month != i_rRight.Month )
+ return i_rLeft.Month > i_rRight.Month;
+
+ if ( i_rLeft.Day != i_rRight.Day )
+ return i_rLeft.Day > i_rRight.Day;
+
+ if ( i_rLeft.Hours != i_rRight.Hours )
+ return i_rLeft.Hours > i_rRight.Hours;
+
+ if ( i_rLeft.Minutes != i_rRight.Minutes )
+ return i_rLeft.Minutes > i_rRight.Minutes;
+
+ if ( i_rLeft.Seconds != i_rRight.Seconds )
+ return i_rLeft.Seconds > i_rRight.Seconds;
+
+ if ( i_rLeft.HundredthSeconds != i_rRight.HundredthSeconds )
+ return i_rLeft.HundredthSeconds > i_rRight.HundredthSeconds;
+
+ return sal_False;
+}
+
+
+::boost::shared_ptr<GDIMetaFile>
+SfxObjectShell::GetPreviewMetaFile( sal_Bool bFullContent ) const
+{
+ return CreatePreviewMetaFile_Impl( bFullContent, sal_False );
+}
+
+
+::boost::shared_ptr<GDIMetaFile>
+SfxObjectShell::CreatePreviewMetaFile_Impl( sal_Bool bFullContent, sal_Bool bHighContrast ) 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 ::boost::shared_ptr<GDIMetaFile>();
+
+ ::boost::shared_ptr<GDIMetaFile> pFile(new GDIMetaFile);
+
+ VirtualDevice aDevice;
+ aDevice.EnableOutput( FALSE );
+
+ // adjust the output device if HC-metafile is requested
+ if ( bHighContrast )
+ aDevice.SetDrawMode( aDevice.GetDrawMode() | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
+
+ MapMode aMode( ((SfxObjectShell*)this)->GetMapUnit() );
+ aDevice.SetMapMode( aMode );
+ pFile->SetPrefMapMode( aMode );
+
+ Size aTmpSize;
+ sal_Int8 nAspect;
+ if ( bFullContent )
+ {
+ nAspect = ASPECT_CONTENT;
+ aTmpSize = 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 );
+
+ LanguageType eLang;
+ SvtCTLOptions* pCTLOptions = new SvtCTLOptions;
+ if ( SvtCTLOptions::NUMERALS_HINDI == pCTLOptions->GetCTLTextNumerals() )
+ eLang = LANGUAGE_ARABIC_SAUDI_ARABIA;
+ else if ( SvtCTLOptions::NUMERALS_ARABIC == pCTLOptions->GetCTLTextNumerals() )
+ eLang = LANGUAGE_ENGLISH;
+ else
+ eLang = (LanguageType) Application::GetSettings().GetLanguage();
+
+ aDevice.SetDigitLanguage( eLang );
+
+ ((SfxObjectShell*)this)->DoDraw( &aDevice, Point(0,0), aTmpSize, JobSetup(), nAspect );
+ pFile->Stop();
+
+ return pFile;
+}
+
+//====================================================================
+
+void SfxObjectShell::UpdateDocInfoForSave()
+{
+ uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
+
+ // clear user data if recommend (see 'Tools - Options - Open/StarOffice - Security')
+ if ( SvtSecurityOptions().IsOptionSet(
+ SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO ) )
+ {
+ xDocProps->resetUserData( ::rtl::OUString() );
+ }
+ else if ( IsModified() )
+ {
+ String aUserName = SvtUserOptions().GetFullName();
+ if ( !IsUseUserData() )
+ {
+ // remove all data pointing to the current user
+ if (xDocProps->getAuthor().equals(aUserName)) {
+ xDocProps->setAuthor( ::rtl::OUString() );
+ }
+ xDocProps->setModifiedBy( ::rtl::OUString() );
+ if (xDocProps->getPrintedBy().equals(aUserName)) {
+ xDocProps->setPrintedBy( ::rtl::OUString() );
+ }
+ }
+ else
+ {
+ // update ModificationAuthor, revision and editing time
+ ::DateTime now;
+ xDocProps->setModificationDate( util::DateTime(
+ now.Get100Sec(), now.GetSec(), now.GetMin(),
+ now.GetHour(), now.GetDay(), now.GetMonth(),
+ now.GetYear() ) );
+ xDocProps->setModifiedBy( aUserName );
+ if ( !HasName() || pImp->bIsSaving )
+ // QUESTION: not in case of "real" SaveAs as this is meant to create a new document
+ UpdateTime_Impl( xDocProps );
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+static void
+lcl_add(util::Duration & rDur, Time const& rTime)
+{
+ // here we don't care about overflow: rDur is converted back to seconds
+ // anyway, and Time cannot store more than ~4000 hours
+ rDur.Hours += rTime.GetHour();
+ rDur.Minutes += rTime.GetMin();
+ rDur.Seconds += rTime.GetSec();
+}
+
+// Bearbeitungszeit aktualisieren
+void SfxObjectShell::UpdateTime_Impl(
+ const uno::Reference<document::XDocumentProperties> & i_xDocProps)
+{
+ // Get old time from documentinfo
+ const sal_Int32 secs = i_xDocProps->getEditingDuration();
+ util::Duration editDuration(sal_False, 0, 0, 0,
+ secs/3600, (secs%3600)/60, secs%60, 0);
+
+ // 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 ;
+ }
+
+ lcl_add(editDuration, nAddTime);
+ }
+
+ pImp->nTime = aNow;
+ try {
+ const sal_Int32 newSecs( (editDuration.Hours*3600)
+ + (editDuration.Minutes*60) + editDuration.Seconds);
+ i_xDocProps->setEditingDuration(newSecs);
+ i_xDocProps->setEditingCycles(i_xDocProps->getEditingCycles() + 1);
+ }
+ catch (lang::IllegalArgumentException &)
+ {
+ // ignore overflow
+ }
+}
+
+//--------------------------------------------------------------------
+
+SfxDocumentInfoDialog* SfxObjectShell::CreateDocumentInfoDialog
+(
+ Window* pParent,
+ const SfxItemSet& rSet
+)
+{
+ return new SfxDocumentInfoDialog(pParent, rSet);
+}
+
+//--------------------------------------------------------------------
+
+SfxStyleSheetBasePool* SfxObjectShell::GetStyleSheetPool()
+{
+ return 0;
+}
+
+void SfxObjectShell::SetOrganizerSearchMask(
+ SfxStyleSheetBasePool* pStylePool) const
+{
+ pStylePool->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 *pStylePool = GetStyleSheetPool();
+ if(!pStylePool)
+ return 0;
+ SetOrganizerSearchMask(pStylePool);
+ return pStylePool->Count();
+ }
+ case CONTENT_MACRO:
+ break;
+/*
+ case CONTENT_CONFIG:
+ return ( GetConfigManager() ) ?
+ GetConfigManager()->GetItemCount() : 0;
+ break;
+ */
+ }
+ return 0;
+}
+
+
+//--------------------------------------------------------------------
+//TODO/CLEANUP: remove this method (it's virtual)
+void SfxObjectShell::TriggerHelpPI(USHORT nIdx1, USHORT nIdx2, USHORT)
+{
+ if(nIdx1==CONTENT_STYLE && nIdx2 != INDEX_IGNORE) //StyleSheets
+ {
+ SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
+ SetOrganizerSearchMask(pStylePool);
+ }
+}
+
+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 *pStylePool = GetStyleSheetPool();
+ SetOrganizerSearchMask(pStylePool);
+ SfxStyleSheetBase *pStyle = (*pStylePool)[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() )
+ {
+ 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 = NULL;
+
+ if ( pHisPool && pHisPool->Count() > nSourceIdx2 )
+ pHisSheet = (*pHisPool)[nSourceIdx2];
+
+ // Einfuegen ist nur dann noetig, wenn ein StyleSheet
+ // zwischen unterschiedlichen(!) Pools bewegt wird
+
+ if ( pHisSheet && 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() )
+ {
+ 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();
+ pMyPool->Remove(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();
+ }
+
+ SetModified( TRUE );
+ }
+
+ return bRet;
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxObjectShell::Print
+(
+ Printer& rPrt,
+ USHORT nIdx1,
+ USHORT /*nIdx2*/,
+ USHORT /*nIdx3*/,
+ const String* pObjectName
+)
+
+/* [Beschreibung]
+*/
+
+{
+ switch(nIdx1)
+ {
+ case CONTENT_STYLE:
+ {
+ SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
+ SetOrganizerSearchMask(pStylePool);
+ SfxStyleSheetIterator* pIter = pStylePool->CreateIterator(
+ pStylePool->GetSearchFamily(), pStylePool->GetSearchMask() );
+ USHORT nStyles = pIter->Count();
+ SfxStyleSheetBase *pStyle = pIter->First();
+ if ( !pStyle )
+ return TRUE;
+
+ // pepare adaptor for old style StartPage/EndPage printing
+ boost::shared_ptr< Printer > pPrinter( new Printer( rPrt.GetJobSetup() ) );
+ vcl::OldStylePrintAdaptor* pAdaptor = new vcl::OldStylePrintAdaptor( pPrinter );
+ boost::shared_ptr< vcl::PrinterController > pController( pAdaptor );
+
+ pAdaptor->StartPage();
+
+ pPrinter->SetMapMode(MapMode(MAP_10TH_MM));
+ Font aFont( DEFINE_CONST_UNICODE( "Arial" ), Size(0, 64)); // 18pt
+ aFont.SetWeight(WEIGHT_BOLD);
+ pPrinter->SetFont(aFont);
+ const Size aPageSize(pPrinter->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( pPrinter->GetTextHeight() );
+ pPrinter->DrawText(aOutPos, aHeader);
+ aOutPos.Y() += nTextHeight;
+ aOutPos.Y() += nTextHeight/2;
+ aFont.SetSize(Size(0, 35)); // 10pt
+ nStyles = 1;
+ while(pStyle)
+ {
+ // print template name
+ String aStr(pStyle->GetName());
+ aFont.SetWeight(WEIGHT_BOLD);
+ pPrinter->SetFont(aFont);
+ nTextHeight = pPrinter->GetTextHeight();
+ // check for new page
+ if ( aOutPos.Y() + nTextHeight*2 >
+ aPageSize.Height() - (long) nYIndent )
+ {
+ pAdaptor->EndPage();
+ pAdaptor->StartPage();
+ aOutPos.Y() = nYIndent;
+ }
+ pPrinter->DrawText(aOutPos, aStr);
+ aOutPos.Y() += nTextHeight;
+
+ // print template description
+ aFont.SetWeight(WEIGHT_NORMAL);
+ pPrinter->SetFont(aFont);
+ aStr = pStyle->GetDescription();
+ const char cDelim = ' ';
+ USHORT nStart = 0, nIdx = 0;
+
+ nTextHeight = pPrinter->GetTextHeight();
+ // break text into lines
+ while(nIdx < aStr.Len())
+ {
+ USHORT nOld = nIdx;
+ long nTextWidth;
+ nIdx = aStr.Search(cDelim, nStart);
+ nTextWidth = pPrinter->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 = pPrinter->GetTextWidth(aStr, nStart, nIdx-nStart);
+ }
+ String aTmp(aStr, nStart, nIdx == STRING_NOTFOUND?
+ STRING_LEN :
+ nOld-nStart);
+ if ( aTmp.Len() )
+ {
+ nStart = nOld+1; // trailing space
+ }
+ else
+ {
+ USHORT nChar = 1;
+ while(
+ nStart + nChar < aStr.Len() &&
+ aOutPos.X() + pPrinter->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 )
+ {
+ pAdaptor->EndPage();
+ pAdaptor->StartPage();
+ aOutPos.Y() = nYIndent;
+ }
+ pPrinter->DrawText(aOutPos, aTmp);
+ aOutPos.Y() += pPrinter->GetTextHeight();
+ }
+ pStyle = pIter->Next();
+ }
+ pAdaptor->EndPage();
+
+ Printer::PrintJob( pController, rPrt.GetJobSetup() );
+
+ 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 ( !pFile )
+ return;
+
+ if ( !::utl::LocalFileHelper::IsLocalFile( pFile->GetName() ) )
+ // update only for documents loaded from the local file system
+ return;
+
+ // only for own storage formats
+ uno::Reference< embed::XStorage > xDocStor = pFile->GetStorage();
+ if ( !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?
+ uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
+ ::rtl::OUString aTemplName( xDocProps->getTemplateName() );
+ ::rtl::OUString aTemplURL( xDocProps->getTemplateURL() );
+ String aFoundName;
+
+ if ( aTemplName.getLength() || (aTemplURL.getLength() && !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 ( aTemplURL.getLength() )
+ {
+ String aURL;
+ if( ::utl::LocalFileHelper::ConvertSystemPathToURL( aTemplURL, GetMedium()->GetName(), aURL ) )
+ aFoundName = aURL;
+ }
+
+ if( !aFoundName.Len() && aTemplName.getLength() )
+ // 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
+ aTemplURL = aFoundName;
+ BOOL bLoad = FALSE;
+
+ // should the document checked against changes in the template ?
+ if ( IsQueryLoadTemplate() )
+ {
+ // load document info of template
+ BOOL bOK = FALSE;
+ util::DateTime aTemplDate;
+ try
+ {
+ Reference < document::XStandaloneDocumentInfo > xDocInfo (
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.document.StandaloneDocumentInfo") ) ),
+ UNO_QUERY_THROW );
+ Reference < beans::XFastPropertySet > xSet( xDocInfo,
+ UNO_QUERY_THROW );
+ xDocInfo->loadFromURL( aTemplURL );
+ Any aAny = xSet->getFastPropertyValue( WID_DATE_MODIFIED );
+ ::com::sun::star::util::DateTime aTmp;
+ if ( aAny >>= aTemplDate )
+ {
+ // get modify date from document info
+ 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 util::DateTime aInfoDate( xDocProps->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 )
+ {
+ String sMessage( SfxResId( STR_QRYTEMPL_MESSAGE ) );
+ sMessage.SearchAndReplace( String::CreateFromAscii("$(ARG1)"), aTemplName );
+ sfx2::QueryTemplateBox aBox( GetDialogParent(), sMessage );
+ if ( RET_YES == aBox.Execute() )
+ bLoad = TRUE;
+ }
+
+ if( !bLoad )
+ {
+ // user refuses, so don't ask again for this document
+ SetQueryLoadTemplate(FALSE);
+ SetModified( TRUE );
+ }
+ }
+ }
+
+ if ( bLoad )
+ {
+ // styles should be updated, create document in organizer mode to read in the styles
+ //TODO: testen!
+ SfxObjectShellLock xTemplDoc = CreateObjectByFactoryName( GetFactory().GetFactoryName(), SFX_CREATE_MODE_ORGANIZER );
+ xTemplDoc->DoInitNew(0);
+
+ // TODO/MBA: do we need a BaseURL? Then LoadFrom must be extended!
+ //xTemplDoc->SetBaseURL( aFoundName );
+
+ // TODO/LATER: make sure that we don't use binary templates!
+ SfxMedium aMedium( aFoundName, STREAM_STD_READ );
+ if ( xTemplDoc->LoadFrom( aMedium ) )
+ {
+ // transfer styles from xTemplDoc to this document
+ // TODO/MBA: make sure that no BaseURL is needed in *this* document
+ LoadStyles(*xTemplDoc);
+
+ // remember date/time of check
+ xDocProps->setTemplateDate(aTemplDate);
+ // TODO/LATER: new functionality to store document info is required ( didn't work for SO7 XML format )
+//REPLACE pInfo->Save(xDocStor);
+ }
+ }
+/*
+ SfxConfigManager *pCfgMgr = SFX_CFGMANAGER();
+ {
+ 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;
+ }
+ }
+}
+
+SfxObjectShellRef MakeObjectShellForOrganizer_Impl( const String& aTargetURL, BOOL bForWriting )
+{
+ // check for own format
+ SfxObjectShellRef xDoc;
+ StreamMode nMode = bForWriting ? SFX_STREAM_READWRITE : SFX_STREAM_READONLY;
+ SfxMedium *pMed = new SfxMedium( aTargetURL, nMode, FALSE, 0 );
+ const SfxFilter* pFilter = NULL;
+ pMed->UseInteractionHandler(TRUE);
+ if( SFX_APP()->GetFilterMatcher().GuessFilter( *pMed, &pFilter ) == ERRCODE_NONE && pFilter && pFilter->IsOwnFormat() )
+ {
+ // create document
+ xDoc = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_ORGANIZER );
+ if ( xDoc.Is() )
+ {
+ // partially load, so don't use DoLoad!
+ xDoc->DoInitNew(0);
+ // TODO/LATER: make sure that we don't use binary templates!
+ if( xDoc->LoadFrom( *pMed ) )
+ {
+ // connect to storage, abandon temp. storage
+ xDoc->DoSaveCompleted( pMed );
+ }
+ else
+ xDoc.Clear();
+ }
+ }
+ else
+ delete pMed;
+
+ return xDoc;
+}
+
+sal_Bool SfxObjectShell::IsHelpDocument() const
+{
+ const SfxFilter* pFilter = GetMedium()->GetFilter();
+ return ( pFilter && pFilter->GetFilterName().CompareToAscii("writer_web_HTML_help") == COMPARE_EQUAL );
+}
+
+void SfxObjectShell::ResetFromTemplate( const String& rTemplateName, const String& rFileName )
+{
+ // only care about reseting this data for openoffice formats otherwise
+ if ( IsOwnStorageFormat_Impl( *GetMedium()) )
+ {
+ uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
+ xDocProps->setTemplateURL( ::rtl::OUString() );
+ xDocProps->setTemplateName( ::rtl::OUString() );
+ xDocProps->setTemplateDate( util::DateTime() );
+ xDocProps->resetUserData( ::rtl::OUString() );
+
+ // TODO/REFACTOR:
+ // Title?
+
+ if( ::utl::LocalFileHelper::IsLocalFile( rFileName ) )
+ {
+ String aFoundName;
+ if( SFX_APP()->Get_Impl()->GetDocumentTemplates()->GetFull( String(), rTemplateName, aFoundName ) )
+ {
+ INetURLObject aObj( rFileName );
+ xDocProps->setTemplateURL( aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
+ xDocProps->setTemplateName( rTemplateName );
+
+ ::DateTime now;
+ xDocProps->setTemplateDate( util::DateTime(
+ now.Get100Sec(), now.GetSec(), now.GetMin(),
+ now.GetHour(), now.GetDay(), now.GetMonth(),
+ now.GetYear() ) );
+
+ SetQueryLoadTemplate( sal_True );
+ }
+ }
+ }
+}
+
+sal_Bool SfxObjectShell::IsQueryLoadTemplate() const
+{
+ return pImp->bQueryLoadTemplate;
+}
+
+sal_Bool SfxObjectShell::IsUseUserData() const
+{
+ return pImp->bUseUserData;
+}
+
+void SfxObjectShell::SetQueryLoadTemplate( sal_Bool bNew )
+{
+ if ( pImp->bQueryLoadTemplate != bNew )
+ SetModified( TRUE );
+ pImp->bQueryLoadTemplate = bNew;
+}
+
+void SfxObjectShell::SetUseUserData( sal_Bool bNew )
+{
+ if ( pImp->bUseUserData != bNew )
+ SetModified( TRUE );
+ pImp->bUseUserData = bNew;
+}
+
+sal_Bool SfxObjectShell::IsLoadReadonly() const
+{
+ return pImp->bLoadReadonly;
+}
+
+sal_Bool SfxObjectShell::IsSaveVersionOnClose() const
+{
+ return pImp->bSaveVersionOnClose;
+}
+
+void SfxObjectShell::SetLoadReadonly( sal_Bool bNew )
+{
+ if ( pImp->bLoadReadonly != bNew )
+ SetModified( TRUE );
+ pImp->bLoadReadonly = bNew;
+}
+
+void SfxObjectShell::SetSaveVersionOnClose( sal_Bool bNew )
+{
+ if ( pImp->bSaveVersionOnClose != bNew )
+ SetModified( TRUE );
+ pImp->bSaveVersionOnClose = bNew;
+}
+
+sal_uInt32 SfxObjectShell::GetModifyPasswordHash() const
+{
+ return pImp->m_nModifyPasswordHash;
+}
+
+sal_Bool SfxObjectShell::SetModifyPasswordHash( sal_uInt32 nHash )
+{
+ if ( ( !IsReadOnly() && !IsReadOnlyUI() )
+ || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) )
+ {
+ // the hash can be changed only in editable documents,
+ // or during loading of document
+ pImp->m_nModifyPasswordHash = nHash;
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+uno::Sequence< beans::PropertyValue > SfxObjectShell::GetModifyPasswordInfo() const
+{
+ return pImp->m_aModifyPasswordInfo;
+}
+
+sal_Bool SfxObjectShell::SetModifyPasswordInfo( const uno::Sequence< beans::PropertyValue >& aInfo )
+{
+ if ( ( !IsReadOnly() && !IsReadOnlyUI() )
+ || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) )
+ {
+ // the hash can be changed only in editable documents,
+ // or during loading of document
+ pImp->m_aModifyPasswordInfo = aInfo;
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+void SfxObjectShell::SetModifyPasswordEntered( sal_Bool bEntered )
+{
+ pImp->m_bModifyPasswordEntered = bEntered;
+}
+
+sal_Bool SfxObjectShell::IsModifyPasswordEntered()
+{
+ return pImp->m_bModifyPasswordEntered;
+}
+
diff --git a/sfx2/source/doc/objembed.cxx b/sfx2/source/doc/objembed.cxx
new file mode 100644
index 000000000000..1c2105c210b9
--- /dev/null
+++ b/sfx2/source/doc/objembed.cxx
@@ -0,0 +1,317 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/container/XChild.hpp>
+#include <com/sun/star/embed/XEmbedObjectCreator.hpp>
+#include <com/sun/star/embed/XComponentSupplier.hpp>
+#include <com/sun/star/embed/XEmbedPersist.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/embed/EmbedStates.hpp>
+
+#include <sfx2/objsh.hxx>
+#include <sfx2/app.hxx>
+#include "objshimp.hxx"
+#include <sfx2/sfx.hrc>
+#include <sfx2/event.hxx>
+
+#include <comphelper/seqstream.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <svtools/embedtransfer.hxx>
+#include <vcl/outdev.hxx>
+#include <vcl/gdimtf.hxx>
+
+using namespace ::com::sun::star;
+
+// -----------------------------------------------------------------------
+// TODO/LATER: this workaround must be replaced by API in future if possible
+SfxObjectShell* SfxObjectShell::GetParentShellByModel_Impl()
+{
+ SfxObjectShell* pResult = NULL;
+
+ try {
+ uno::Reference< container::XChild > xChildModel( GetModel(), uno::UNO_QUERY );
+ if ( xChildModel.is() )
+ {
+ uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
+ if ( xParentTunnel.is() )
+ {
+ SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
+ pResult = reinterpret_cast<SfxObjectShell*>(xParentTunnel->getSomething(
+ uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ // TODO: error handling
+ }
+
+ return pResult;
+}
+
+// -----------------------------------------------------------------------
+Printer* SfxObjectShell::GetDocumentPrinter()
+{
+ SfxObjectShell* pParent = GetParentShellByModel_Impl();
+ if ( pParent )
+ return pParent->GetDocumentPrinter();
+ return NULL;
+}
+
+// -----------------------------------------------------------------------
+OutputDevice* SfxObjectShell::GetDocumentRefDev()
+{
+ SfxObjectShell* pParent = GetParentShellByModel_Impl();
+ if ( pParent )
+ return pParent->GetDocumentRefDev();
+ return NULL;
+}
+
+// -----------------------------------------------------------------------
+void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ )
+{
+ // virtual method
+}
+
+// -----------------------------------------------------------------------
+Rectangle SfxObjectShell::GetVisArea( USHORT nAspect ) const
+{
+ if( nAspect == ASPECT_CONTENT )
+ return pImp->m_aVisArea;
+ else if( nAspect == ASPECT_THUMBNAIL )
+ {
+ Rectangle aRect;
+ aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
+ MAP_100TH_MM, GetMapUnit() ) );
+ return aRect;
+ }
+ return Rectangle();
+}
+
+// -----------------------------------------------------------------------
+const Rectangle& SfxObjectShell::GetVisArea() const
+{
+ pImp->m_aVisArea = GetVisArea( ASPECT_CONTENT );
+ return pImp->m_aVisArea;
+}
+
+// -----------------------------------------------------------------------
+void SfxObjectShell::SetVisArea( const Rectangle & rVisArea )
+{
+ if( pImp->m_aVisArea != rVisArea )
+ {
+ pImp->m_aVisArea = rVisArea;
+ if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
+ {
+ if ( IsEnableSetModified() )
+ SetModified( TRUE );
+
+ SFX_APP()->NotifyEvent(SfxEventHint( SFX_EVENT_VISAREACHANGED, GlobalEventConfig::GetEventName(STR_EVENT_VISAREACHANGED), this));
+
+ /*
+ Size aSize (GetVisArea().GetSize());
+ if ( GetIPEnv() && GetIPEnv()->GetEditWin() )
+ ViewChanged( ASPECT_CONTENT );
+ */
+
+
+ // OutPlace die Gr"o\se des MDI-Fensters anpassen
+ // Unbedingt den Gr"o\senvergleich machen, spart nicht nur Zeit, sondern
+ // vermeidet auch Rundungsfehler !
+ /*
+ // in case of ole outplace editing the frame should be found
+ SfxViewFrame* pFrameToResize = pFrame ? pFrame : SfxViewFrame::GetFirst( GetObjectShell() );
+
+ if ( pFrameToResize && !pIPF && rRect.GetSize() != aSize &&
+ !pFrameToResize->IsAdjustPosSizePixelLocked_Impl() )
+
+ {
+ // Zuerst die logischen Koordinaten von IP-Objekt und EditWindow
+ // ber"ucksichtigen
+ SfxViewShell *pShell = pFrameToResize->GetViewShell();
+ Window *pWindow = pShell->GetWindow();
+
+ // Da in den Applikationen bei der R"ucktransformation immer die
+ // Eckpunkte tranformiert werden und nicht die Size (um die Ecken
+ // alignen zu k"onnen), transformieren wir hier auch die Punkte, um
+ // m"oglichst wenig Rundungsfehler zu erhalten.
+ Rectangle aRect = pWindow->LogicToPixel( rRect );
+ Size aSize = aRect.GetSize();
+ pShell->GetWindow()->SetSizePixel( aSize );
+ pFrameToResize->DoAdjustPosSizePixel( pShell, Point(), aSize );
+ }
+
+ // bei InPlace die View skalieren
+ if ( GetIPEnv() && GetIPEnv()->GetEditWin() && !bDisableViewScaling && pIPF )
+ pIPF->GetEnv_Impl()->MakeScale( rRect.GetSize(), GetMapUnit(),
+ pIPF->GetViewShell()->GetWindow()->GetOutputSizePixel() );
+ */
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
+{
+ SetVisArea( Rectangle( GetVisArea().TopLeft(), rVisSize ) );
+}
+
+// -----------------------------------------------------------------------
+ULONG SfxObjectShell::GetMiscStatus() const
+{
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+MapUnit SfxObjectShell::GetMapUnit() const
+{
+ return pImp->m_nMapUnit;
+}
+
+// -----------------------------------------------------------------------
+void SfxObjectShell::SetMapUnit( MapUnit nMapUnit )
+{
+ pImp->m_nMapUnit = nMapUnit;
+}
+
+// -----------------------------------------------------------------------
+void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const
+{
+ sal_uInt32 nClipFormat;
+ String aAppName, aShortName;
+ FillClass( &rDesc.maClassName, &nClipFormat, &aAppName, &rDesc.maTypeName, &aShortName, SOFFICE_FILEFORMAT_CURRENT );
+
+ rDesc.mnViewAspect = ASPECT_CONTENT;
+ rDesc.mnOle2Misc = GetMiscStatus();
+ rDesc.maSize = OutputDevice::LogicToLogic( GetVisArea().GetSize(), GetMapUnit(), MAP_100TH_MM );
+ rDesc.maDragStartPos = Point();
+ rDesc.maDisplayName = String();
+ rDesc.mbCanLink = FALSE;
+}
+
+// -----------------------------------------------------------------------
+void SfxObjectShell::DoDraw( OutputDevice* pDev,
+ const Point & rObjPos,
+ const Size & rSize,
+ const JobSetup & rSetup,
+ USHORT nAspect )
+{
+ MapMode aMod = pDev->GetMapMode();
+ Size aSize = GetVisArea( nAspect ).GetSize();
+ MapMode aWilliMode( GetMapUnit() );
+ aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
+ if( aSize.Width() && aSize.Height() )
+ {
+ Fraction aXF( rSize.Width(), aSize.Width() );
+ Fraction aYF( rSize.Height(), aSize.Height() );
+
+//REMOVE Point aOrg = rObjPos;
+//REMOVE aMod.SetMapUnit( MAP_100TH_MM );
+//REMOVE aSize = pDev->LogicToLogic( GetVisArea( nAspect ).GetSize(), &aMod, &aWilliMode );
+ DoDraw_Impl( pDev, rObjPos, aXF, aYF, rSetup, nAspect );
+ }
+}
+
+// -----------------------------------------------------------------------
+void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev,
+ const Point & rViewPos,
+ const Fraction & rScaleX,
+ const Fraction & rScaleY,
+ const JobSetup & rSetup,
+ USHORT nAspect )
+{
+ Rectangle aVisArea = GetVisArea( nAspect );
+ // MapUnit des Ziels
+ MapMode aMapMode( GetMapUnit() );
+ aMapMode.SetScaleX( rScaleX );
+ aMapMode.SetScaleY( rScaleY );
+
+ // Ziel in Pixel
+ Point aOrg = pDev->LogicToLogic( rViewPos, NULL, &aMapMode );
+ Point aDelta = aOrg - aVisArea.TopLeft();
+
+ // Origin entsprechend zum sichtbaren Bereich verschieben
+ // Origin mit Scale setzen
+ aMapMode.SetOrigin( aDelta );
+
+ // Deviceeinstellungen sichern
+ pDev->Push();
+
+ Region aRegion;
+ if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
+ {
+ aRegion = pDev->GetClipRegion();
+ aRegion = pDev->LogicToPixel( aRegion );
+ }
+ pDev->SetRelativeMapMode( aMapMode );
+
+ GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
+ if( pMtf )
+ {
+ if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
+ pMtf->Stop();
+ else
+ pMtf = NULL;
+ }
+// #ifndef UNX
+ if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
+// #endif
+ {
+ aRegion = pDev->PixelToLogic( aRegion );
+ pDev->SetClipRegion( aRegion );
+ }
+ if( pMtf )
+ pMtf->Record( pDev );
+
+//REMOVE SvOutPlaceObjectRef xOutRef( this );
+//REMOVE if ( xOutRef.Is() )
+//REMOVE xOutRef->DrawObject( pDev, rSetup, rSize, nAspect );
+//REMOVE else
+ Draw( pDev, rSetup, nAspect );
+//REMOVE DrawHatch( pDev, aVisArea.TopLeft(), aVisArea.GetSize() );
+
+ // Deviceeinstellungen wieder herstellen
+ pDev->Pop();
+
+}
+
+comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const
+{
+ if ( !pImp->mpObjectContainer )
+ pImp->mpObjectContainer = new comphelper::EmbeddedObjectContainer( ((SfxObjectShell*)this)->GetStorage(), GetModel() );
+ return *pImp->mpObjectContainer;
+}
+
+void SfxObjectShell::ClearEmbeddedObjects()
+{
+ // frees alle space taken by embedded objects
+ DELETEZ( pImp->mpObjectContainer );
+}
+
diff --git a/sfx2/source/doc/objitem.cxx b/sfx2/source/doc/objitem.cxx
new file mode 100644
index 000000000000..2980d984fd78
--- /dev/null
+++ b/sfx2/source/doc/objitem.cxx
@@ -0,0 +1,135 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+
+#include <sfx2/objsh.hxx>
+//#include "objshimp.hxx"
+#include <sfx2/objitem.hxx>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+
+//====================================================================
+
+TYPEINIT1_AUTOFACTORY(SfxObjectShellItem,SfxPoolItem)
+TYPEINIT1_AUTOFACTORY(SfxObjectItem,SfxPoolItem)
+
+//=========================================================================
+
+int SfxObjectShellItem::operator==( const SfxPoolItem &rItem ) const
+{
+ return PTR_CAST(SfxObjectShellItem, &rItem)->pObjSh == pObjSh;
+}
+
+//--------------------------------------------------------------------
+
+String SfxObjectShellItem::GetValueText() const
+{
+ return String();
+}
+
+//--------------------------------------------------------------------
+
+SfxPoolItem* SfxObjectShellItem::Clone( SfxItemPool *) const
+{
+ return new SfxObjectShellItem( Which(), pObjSh );
+}
+
+//--------------------------------------------------------------------
+
+sal_Bool SfxObjectShellItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ ) const
+{
+ if ( pObjSh )
+ {
+ // This item MUST provide a model. Please don't change this, there are UNO-based
+ // implementations which need it!!
+ rVal <<= pObjSh->GetModel();
+ }
+ else
+ {
+ rVal <<= ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >();
+ }
+ return TRUE;
+}
+
+//--------------------------------------------------------------------
+
+sal_Bool SfxObjectShellItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ )
+{
+ // This item MUST have a model. Please don't change this, there are UNO-based
+ // implementations which need it!!
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > xModel;
+
+ if ( rVal >>= xModel )
+ {
+ if ( xModel.is() )
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xTunnel(
+ xModel, ::com::sun::star::uno::UNO_QUERY );
+ if ( xTunnel.is() )
+ {
+ ::com::sun::star::uno::Sequence < sal_Int8 > aSeq( (sal_Int8*) SvGlobalName( SFX_GLOBAL_CLASSID ).GetBytes(), 16 );
+ sal_Int64 nHandle = xTunnel->getSomething( aSeq );
+ if ( nHandle )
+ {
+ pObjSh = reinterpret_cast< SfxObjectShell* >(sal::static_int_cast<sal_IntPtr>( nHandle ));
+ return TRUE;
+ }
+ }
+ }
+
+ pObjSh = 0;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+//=========================================================================
+
+SfxObjectItem::SfxObjectItem( USHORT nWhichId, SfxShell *pSh )
+: SfxPoolItem( nWhichId ),
+ _pSh( pSh )
+{}
+
+//--------------------------------------------------------------------
+
+int SfxObjectItem::operator==( const SfxPoolItem &rItem ) const
+{
+ SfxObjectItem *pOther = PTR_CAST(SfxObjectItem, &rItem);
+ return pOther->_pSh == _pSh;
+}
+
+//--------------------------------------------------------------------
+
+SfxPoolItem* SfxObjectItem::Clone( SfxItemPool *) const
+{
+ return new SfxObjectItem( Which(), _pSh );
+}
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
new file mode 100644
index 000000000000..71c7e0e78383
--- /dev/null
+++ b/sfx2/source/doc/objmisc.cxx
@@ -0,0 +1,2585 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef _INETMSG_HXX //autogen
+#include <svl/inetmsg.hxx>
+#endif
+#include <tools/diagnose_ex.h>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <svtools/svparser.hxx> // SvKeyValue
+#include <vos/mutex.hxx>
+#include <cppuhelper/exc_hlp.hxx>
+
+#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/document/UpdateDocMode.hpp>
+#include <com/sun/star/script/XTypeConverter.hpp>
+#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
+#include <com/sun/star/script/FinishEngineEvent.hpp>
+#include <com/sun/star/script/InterruptReason.hpp>
+#include <com/sun/star/script/XEngineListener.hpp>
+#include <com/sun/star/script/XDebugging.hpp>
+#ifndef _COM_SUN_STAR_SCRIPT_XINVOKATION_HPP_
+#include <com/sun/star/script/XInvocation.hpp>
+#endif
+#include <com/sun/star/script/ContextInformation.hpp>
+#include <com/sun/star/script/FinishReason.hpp>
+#include <com/sun/star/script/XEngine.hpp>
+#include <com/sun/star/script/InterruptEngineEvent.hpp>
+#include <com/sun/star/script/XLibraryAccess.hpp>
+#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/document/XScriptInvocationContext.hpp>
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/XEmbedPersist.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/container/XChild.hpp>
+#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
+
+
+#include <com/sun/star/script/provider/XScript.hpp>
+#include <com/sun/star/script/provider/XScriptProvider.hpp>
+#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
+
+#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
+#include <toolkit/unohlp.hxx>
+#endif
+
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Any.h>
+#include <com/sun/star/ucb/XContent.hpp>
+#include <com/sun/star/task/ErrorCodeRequest.hpp>
+#include <unotools/securityoptions.hxx>
+
+#include <comphelper/processfactory.hxx>
+#include <comphelper/componentcontext.hxx>
+#include <comphelper/configurationhelper.hxx>
+
+#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+#include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp>
+#include <com/sun/star/task/InteractionClassification.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::script;
+using namespace ::com::sun::star::script::provider;
+using namespace ::com::sun::star::container;
+#include <basic/sbuno.hxx>
+#include <basic/sbstar.hxx>
+#ifndef _SB_BASMGR_HXX
+#include <basic/basmgr.hxx>
+#endif
+#ifndef _VCL_MSGBOX_HXX
+#include <vcl/msgbox.hxx>
+#endif
+#include <basic/sbx.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+
+#include <unotools/pathoptions.hxx>
+#include <unotools/ucbhelper.hxx>
+#include <tools/inetmime.hxx>
+#include <tools/urlobj.hxx>
+#include <svl/inettype.hxx>
+#include <svl/sharecontrolfile.hxx>
+#include <osl/file.hxx>
+#include <rtl/bootstrap.hxx>
+#include <vcl/svapp.hxx>
+#include <framework/interaction.hxx>
+#include <comphelper/interaction.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <comphelper/documentconstants.hxx>
+
+#include <sfx2/signaturestate.hxx>
+#include <sfx2/app.hxx>
+#include "appdata.hxx"
+#include <sfx2/request.hxx>
+#include <sfx2/bindings.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/objsh.hxx>
+#include "objshimp.hxx"
+#include <sfx2/event.hxx>
+#include "fltfnc.hxx"
+#include <sfx2/sfx.hrc>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/ctrlitem.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/module.hxx>
+#include <sfx2/macrconf.hxx>
+#include <sfx2/docfac.hxx>
+#include "helper.hxx"
+#include "doc.hrc"
+#include "workwin.hxx"
+#include "helpid.hrc"
+#include "../appl/app.hrc"
+#include <sfx2/sfxdlg.hxx>
+#include "appbaslib.hxx"
+#include <openflag.hxx> // SFX_STREAM_READWRITE
+
+using namespace ::com::sun::star;
+
+// class SfxHeaderAttributes_Impl ----------------------------------------
+
+class SfxHeaderAttributes_Impl : public SvKeyValueIterator
+{
+private:
+ SfxObjectShell* pDoc;
+ SvKeyValueIteratorRef xIter;
+ sal_Bool bAlert;
+
+public:
+ SfxHeaderAttributes_Impl( SfxObjectShell* pSh ) :
+ SvKeyValueIterator(), pDoc( pSh ),
+ xIter( pSh->GetMedium()->GetHeaderAttributes_Impl() ),
+ bAlert( sal_False ) {}
+
+ virtual sal_Bool GetFirst( SvKeyValue& rKV ) { return xIter->GetFirst( rKV ); }
+ virtual sal_Bool GetNext( SvKeyValue& rKV ) { return xIter->GetNext( rKV ); }
+ virtual void Append( const SvKeyValue& rKV );
+
+ void ClearForSourceView() { xIter = new SvKeyValueIterator; bAlert = sal_False; }
+ void SetAttributes();
+ void SetAttribute( const SvKeyValue& rKV );
+};
+
+//=========================================================================
+
+sal_uInt16 __READONLY_DATA aTitleMap_Impl[3][2] =
+{
+ // local remote
+ /* SFX_TITLE_CAPTION */ { SFX_TITLE_FILENAME, SFX_TITLE_TITLE },
+ /* SFX_TITLE_PICKLIST */ { 32, SFX_TITLE_FULLNAME },
+ /* SFX_TITLE_HISTORY */ { 32, SFX_TITLE_FULLNAME }
+};
+
+//=========================================================================
+
+void SfxObjectShell::AbortImport()
+{
+ pImp->bIsAbortingImport = sal_True;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsAbortingImport() const
+{
+ return pImp->bIsAbortingImport;
+}
+
+//-------------------------------------------------------------------------
+
+uno::Reference<document::XDocumentProperties>
+SfxObjectShell::getDocProperties()
+{
+ uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
+ GetModel(), uno::UNO_QUERY_THROW);
+ uno::Reference<document::XDocumentProperties> xDocProps(
+ xDPS->getDocumentProperties());
+ DBG_ASSERT(xDocProps.is(),
+ "SfxObjectShell: model has no DocumentProperties");
+ return xDocProps;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::DoFlushDocInfo()
+{
+}
+
+//-------------------------------------------------------------------------
+
+// Note: the only thing that calls this is the modification event handler
+// that is installed at the XDocumentProperties
+void SfxObjectShell::FlushDocInfo()
+{
+ if ( IsLoading() )
+ return;
+
+ SetModified(sal_True);
+ uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
+ DoFlushDocInfo(); // call template method
+ ::rtl::OUString url(xDocProps->getAutoloadURL());
+ sal_Int32 delay(xDocProps->getAutoloadSecs());
+ SetAutoLoad( INetURLObject(url), delay * 1000,
+ (delay > 0) || url.getLength() );
+/*
+ // bitte beachten:
+ // 1. Titel in DocInfo aber nicht am Doc (nach HTML-Import)
+ // => auch am Doc setzen
+ // 2. Titel in DocInfo leer (Briefumschlagsdruck)
+ // => nicht am Doc setzen, da sonst "unbenanntX" daraus wird
+ String aDocInfoTitle = GetDocInfo().GetTitle();
+ if ( aDocInfoTitle.Len() )
+ SetTitle( aDocInfoTitle );
+ else
+ {
+ pImp->aTitle.Erase();
+ SetNamedVisibility_Impl();
+ if ( GetMedium() )
+ {
+ SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
+ Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
+ }
+ }*/
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::SetError( sal_uInt32 lErr, const ::rtl::OUString& aLogMessage )
+{
+ if(pImp->lErr==ERRCODE_NONE)
+ {
+ pImp->lErr=lErr;
+
+ if( lErr != ERRCODE_NONE && aLogMessage.getLength() )
+ AddLog( aLogMessage );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+sal_uInt32 SfxObjectShell::GetError() const
+{
+ return ERRCODE_TOERROR(GetErrorCode());
+}
+
+//-------------------------------------------------------------------------
+
+sal_uInt32 SfxObjectShell::GetErrorCode() const
+{
+ sal_uInt32 lError=pImp->lErr;
+ if(!lError && GetMedium())
+ lError=GetMedium()->GetErrorCode();
+ return lError;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::ResetError()
+{
+ if( pImp->lErr != ERRCODE_NONE )
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Resetting Error." ) ) );
+
+ pImp->lErr=0;
+ SfxMedium * pMed = GetMedium();
+ if( pMed )
+ pMed->ResetError();
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsTemplate() const
+{
+ return pImp->bIsTemplate;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::SetTemplate(sal_Bool bIs)
+{
+ pImp->bIsTemplate=bIs;
+ SfxFilterMatcher aMatcher( GetFactory().GetFactoryName() );
+ SfxFilterMatcherIter aIter( &aMatcher, SFX_FILTER_TEMPLATEPATH );
+ SfxMedium* pMed = GetMedium();
+ if( pMed ) pMed->SetFilter( aIter.First() );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::EnableSetModified( sal_Bool bEnable )
+{
+#ifdef DBG_UTIL
+ if ( bEnable == pImp->m_bEnableSetModified )
+ DBG_WARNING( "SFX_PERSIST: EnableSetModified 2x mit dem gleichen Wert gerufen" );
+#endif
+ pImp->m_bEnableSetModified = bEnable;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsEnableSetModified() const
+{
+ return pImp->m_bEnableSetModified && !IsReadOnly();
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsModified()
+{
+ if ( pImp->m_bIsModified )
+ return sal_True;
+
+ if ( !pImp->m_xDocStorage.is() || IsReadOnly() )
+ {
+ // if the document still has no storage and is not set to be modified explicitly it is not modified
+ // a readonly document is also not modified
+
+ return sal_False;
+ }
+
+ uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
+ for ( sal_Int32 n=0; n<aNames.getLength(); n++ )
+ {
+ uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] );
+ OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
+ if ( xObj.is() )
+ {
+ try
+ {
+ sal_Int32 nState = xObj->getCurrentState();
+ if ( nState != embed::EmbedStates::LOADED )
+ {
+ uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
+ if ( xModifiable.is() && xModifiable->isModified() )
+ return sal_True;
+ }
+ }
+ catch( uno::Exception& )
+ {}
+ }
+ }
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::SetModified( sal_Bool bModifiedP )
+{
+#ifdef DBG_UTIL
+ if ( !bModifiedP && !IsEnableSetModified() )
+ DBG_WARNING( "SFX_PERSIST: SetModified( sal_False ), obwohl IsEnableSetModified() == sal_False" );
+#endif
+
+ if( !IsEnableSetModified() )
+ return;
+
+ if( pImp->m_bIsModified != bModifiedP )
+ {
+ pImp->m_bIsModified = bModifiedP;
+ ModifyChanged();
+ }
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::ModifyChanged()
+{
+ if ( pImp->bClosing )
+ // SetModified aus dem dispose des Models!
+ return;
+
+ {DBG_CHKTHIS(SfxObjectShell, 0);}
+
+ SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+ if ( pViewFrame )
+ pViewFrame->GetBindings().Invalidate( SID_SAVEDOCS );
+
+ Invalidate( SID_SIGNATURE );
+ Invalidate( SID_MACRO_SIGNATURE );
+ Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) ); // xmlsec05, signed state might change in title...
+
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_MODIFYCHANGED, GlobalEventConfig::GetEventName(STR_EVENT_MODIFYCHANGED), this ) );
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsReadOnlyUI() const
+
+/* [Beschreibung]
+
+ Liefert sal_True, wenn das Dokument fuer die UI wie r/o behandelt werden
+ soll. Dieses ist unabhaengig vom tatsaechlichen r/o, welches per
+ <IsReadOnly()> erfragbar ist.
+*/
+
+{
+ return pImp->bReadOnlyUI;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsReadOnlyMedium() const
+
+/* [Beschreibung]
+
+ Liefert sal_True, wenn das Medium r/o ist bzw. r/o geoeffnet wurde.
+*/
+
+{
+ if ( !pMedium )
+ return sal_True;
+ return pMedium->IsReadOnly();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly )
+
+/* [Beschreibung]
+
+ Schaltet das Dokument in einen r/o bzw. r/w Zustand ohne es neu
+ zu laden und ohne die Open-Modi des Mediums zu aendern.
+*/
+
+{
+ sal_Bool bWasRO = IsReadOnly();
+ pImp->bReadOnlyUI = bReadOnly;
+ if ( bWasRO != IsReadOnly() )
+ {
+ Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
+ //if ( pImp->pDocInfo )
+ // pImp->pDocInfo->SetReadOnly( IsReadOnly() );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::SetReadOnly()
+{
+ // Let the document be completely readonly, means that the
+ // medium open mode is adjusted accordingly, and the write lock
+ // on the file is removed.
+
+ if ( pMedium && !IsReadOnlyMedium() )
+ {
+ sal_Bool bWasROUI = IsReadOnly();
+
+ pMedium->UnlockFile( sal_False );
+
+ // the storage-based mediums are already based on the temporary file
+ // so UnlockFile has already closed the locking stream
+ if ( !pMedium->HasStorage_Impl() && IsLoadingFinished() )
+ pMedium->CloseInStream();
+
+ pMedium->SetOpenMode( SFX_STREAM_READONLY, pMedium->IsDirect(), sal_True );
+ pMedium->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
+
+ if ( !bWasROUI )
+ Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
+ }
+}
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsReadOnly() const
+{
+ return pImp->bReadOnlyUI || IsReadOnlyMedium();
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsInModalMode() const
+{
+ return pImp->bModalMode || pImp->bRunningMacro;
+}
+
+//<!--Added by PengYunQuan for Validity Cell Range Picker
+sal_Bool SfxObjectShell::AcceptStateUpdate() const
+{
+ return !IsInModalMode();
+}
+//-->Added by PengYunQuan for Validity Cell Range Picker
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::HasModalViews() const
+{
+ SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
+ while( pFrame )
+ {
+ if ( pFrame->IsInModalMode() )
+ return sal_True;
+
+ pFrame = SfxViewFrame::GetNext( *pFrame, this );
+ }
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::SetMacroMode_Impl( sal_Bool bModal )
+{
+ if ( !pImp->bRunningMacro != !bModal )
+ {
+ pImp->bRunningMacro = bModal;
+ Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal )
+{
+ // nur Broadcasten wenn modifiziert, sonst ggf. Endlosrekursion
+ if ( !pImp->bModalMode != !bModal )
+ {
+ // zentral mitz"ahlen
+ sal_uInt16 &rDocModalCount = SFX_APP()->Get_Impl()->nDocModalMode;
+ if ( bModal )
+ ++rDocModalCount;
+ else
+ --rDocModalCount;
+
+ // umschalten
+ pImp->bModalMode = bModal;
+ Broadcast( SfxSimpleHint( SFX_HINT_MODECHANGED ) );
+ }
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxObjectShell::SwitchToShared( sal_Bool bShared, sal_Bool bSave )
+{
+ sal_Bool bResult = sal_True;
+
+ if ( bShared != IsDocShared() )
+ {
+ ::rtl::OUString aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( !aOrigURL.getLength() && bSave )
+ {
+ // this is a new document, let it be stored before switching to the shared mode;
+ // the storing should be done without shared flag, since it is possible that the
+ // target location does not allow to create sharing control file;
+ // the shared flag will be set later after creation of sharing control file
+ SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
+
+ if ( pViewFrame )
+ {
+ // TODO/LATER: currently the application guards against the reentrance problem
+ const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
+ SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
+ bResult = ( pResult && pResult->GetValue() );
+ if ( bResult )
+ aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
+ }
+ }
+
+ sal_Bool bOldValue = HasSharedXMLFlagSet();
+ SetSharedXMLFlag( bShared );
+
+ sal_Bool bRemoveEntryOnError = sal_False;
+ if ( bResult && bShared )
+ {
+ try
+ {
+ ::svt::ShareControlFile aControlFile( aOrigURL );
+ aControlFile.InsertOwnEntry();
+ bRemoveEntryOnError = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ bResult = sal_False;
+ }
+ }
+
+ if ( bResult && bSave )
+ {
+ SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
+
+ if ( pViewFrame )
+ {
+ // TODO/LATER: currently the application guards against the reentrance problem
+ SetModified( sal_True ); // the modified flag has to be set to let the document be stored with the shared flag
+ const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
+ SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
+ bResult = ( pResult && pResult->GetValue() );
+ }
+ }
+
+ if ( bResult )
+ {
+ // TODO/LATER: Is it possible that the following calls fail?
+ if ( bShared )
+ {
+ pImp->m_aSharedFileURL = aOrigURL;
+ GetMedium()->SwitchDocumentToTempFile();
+ }
+ else
+ {
+ ::rtl::OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
+ GetMedium()->SwitchDocumentToFile( GetSharedFileURL() );
+ pImp->m_aSharedFileURL = ::rtl::OUString();
+
+ // now remove the temporary file the document was based on
+ ::utl::UCBContentHelper::Kill( aTempFileURL );
+
+ try
+ {
+ // aOrigURL can not be used since it contains an old value
+ ::svt::ShareControlFile aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
+ aControlFile.RemoveFile();
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ }
+ else
+ {
+ // the saving has failed!
+ if ( bRemoveEntryOnError )
+ {
+ try
+ {
+ ::svt::ShareControlFile aControlFile( aOrigURL );
+ aControlFile.RemoveEntry();
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ SetSharedXMLFlag( bOldValue );
+ }
+ }
+ else
+ bResult = sal_False; // the second switch to the same mode
+
+ if ( bResult )
+ SetTitle( String() );
+
+ return bResult;
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::DisconnectFromShared()
+{
+ if ( IsDocShared() )
+ {
+ if ( pMedium && pMedium->GetStorage().is() )
+ {
+ // set medium to noname
+ pMedium->SetName( String(), sal_True );
+ pMedium->Init_Impl();
+
+ // drop resource
+ SetNoName();
+ InvalidateName();
+
+ // untitled document must be based on temporary storage
+ // the medium should not dispose the storage in this case
+ if ( pMedium->GetStorage() == GetStorage() )
+ ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium );
+
+ pMedium->Close();
+ FreeSharedFile();
+
+ SfxMedium* pTmpMedium = pMedium;
+ ForgetMedium();
+ if( !DoSaveCompleted( pTmpMedium ) )
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ else
+ {
+ // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
+ pMedium->CanDisposeStorage_Impl( sal_False );
+ }
+
+ pMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
+ pMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True );
+
+ SetTitle( String() );
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::FreeSharedFile()
+{
+ if ( pMedium )
+ FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
+}
+
+//--------------------------------------------------------------------
+void SfxObjectShell::FreeSharedFile( const ::rtl::OUString& aTempFileURL )
+{
+ SetSharedXMLFlag( sal_False );
+
+ if ( IsDocShared() && aTempFileURL.getLength()
+ && !::utl::UCBContentHelper::EqualURLs( aTempFileURL, GetSharedFileURL() ) )
+ {
+ if ( pImp->m_bAllowShareControlFileClean )
+ {
+ try
+ {
+ ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
+ aControlFile.RemoveEntry();
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+
+ // the cleaning is forbidden only once
+ pImp->m_bAllowShareControlFileClean = sal_True;
+
+ // now remove the temporary file the document is based currently on
+ ::utl::UCBContentHelper::Kill( aTempFileURL );
+
+ pImp->m_aSharedFileURL = ::rtl::OUString();
+ }
+}
+
+//--------------------------------------------------------------------
+void SfxObjectShell::DoNotCleanShareControlFile()
+{
+ pImp->m_bAllowShareControlFileClean = sal_False;
+}
+
+//--------------------------------------------------------------------
+void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag ) const
+{
+ pImp->m_bSharedXMLFlag = bFlag;
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxObjectShell::HasSharedXMLFlagSet() const
+{
+ return pImp->m_bSharedXMLFlag;
+}
+
+//--------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsDocShared() const
+{
+ return ( pImp->m_aSharedFileURL.getLength() > 0 );
+}
+
+//--------------------------------------------------------------------
+
+::rtl::OUString SfxObjectShell::GetSharedFileURL() const
+{
+ return pImp->m_aSharedFileURL;
+}
+
+//--------------------------------------------------------------------
+
+Size SfxObjectShell::GetFirstPageSize()
+{
+ return GetVisArea(ASPECT_THUMBNAIL).GetSize();
+}
+
+
+//--------------------------------------------------------------------
+
+IndexBitSet& SfxObjectShell::GetNoSet_Impl()
+{
+ return pImp->aBitSet;
+}
+
+//--------------------------------------------------------------------
+// changes the title of the document
+
+void SfxObjectShell::SetTitle
+(
+ const String& rTitle // der neue Titel des Dokuments
+)
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann der Titel des Dokuments gesetzt werden.
+ Dieser entspricht initial dem kompletten Dateinamen. Ein Setzen
+ des Titels wirkt jedoch nicht zu"uck auf den Dateinamen; er wird
+ jedoch in den Caption-Bars der MDI-Fenster angezeigt.
+*/
+
+{
+ DBG_CHKTHIS(SfxObjectShell, 0);
+
+ // nix zu tun?
+ if ( ( ( HasName() && pImp->aTitle == rTitle )
+ || ( !HasName() && GetTitle() == rTitle ) )
+ && !IsDocShared() )
+ return;
+
+ SfxApplication *pSfxApp = SFX_APP();
+#if 0
+ // wird 'unbenannt#' als Titel gesetzt
+ String aNoName(SfxResId(STR_NONAME));
+ if ( rTitle.Match(aNoName) <= aNoName.Len() )
+ {
+ // er ist es selbst => ignorieren
+ pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
+ pImp->bIsNamedVisible=0;
+ }
+#endif
+
+ // ggf. die unbenannt-Nummer freigeben
+ if ( pImp->bIsNamedVisible && USHRT_MAX != pImp->nVisualDocumentNumber )
+ {
+ pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
+ pImp->bIsNamedVisible = 0;
+ }
+
+ // Title setzen
+ pImp->aTitle = rTitle;
+// Wieso denn in der DocInfo?
+// GetDocInfo().SetTitle( rTitle );
+// FlushDocInfo();
+
+ // Benachrichtigungen
+ if ( GetMedium() )
+ {
+ SfxShell::SetName( GetTitle(SFX_TITLE_APINAME) );
+ Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
+ }
+}
+
+//--------------------------------------------------------------------
+
+#if OSL_DEBUG_LEVEL > 1
+String X(const String &rRet)
+{
+ if ( !rRet.Len() )
+ return DEFINE_CONST_UNICODE( "-empty-" );
+ return rRet;
+}
+#else
+#define X(ret) ret
+#endif
+
+//--------------------------------------------------------------------
+//--------------------------------------------------------------------
+String SfxObjectShell::GetTitle
+(
+ sal_uInt16 nMaxLength /* 0 (default)
+ der Titel selbst, so wie er ist
+
+ 1 (==SFX_TITLE_FILENAME)
+ liefert den logischen Dateinamen ohne Pfad
+ (unter WNT je nach Systemeinstellung ohne
+ Extension)
+
+ 2 (==SFX_TITLE_FULLNAME)
+ liefert den mit komplettem logischen Dateinamen
+ mit Pfad (remote => ::com::sun::star::util::URL)
+
+ 3 (==SFX_TITLE_APINAME)
+ liefert den logischen Dateinamen ohne Pfad
+ und Extension
+
+ 4 (==SFX_TITLE_DETECT)
+ liefert den kompletten Titel, falls noch
+ nicht gesetzt wird aber aus DocInfo oder
+ dem Namen des Medium erzeugt
+
+ 5 (==SFX_TITLE_CAPTION)
+ liefert den Titel so, wie MB ihn heute in
+ der CaptionBar anzeigen m"ochte
+
+ 6 (==SFX_TITLE_PICKLIST)
+ liefert den Titel so, wie MB ihn heute in
+ der PickList anzeigen m"ochte
+
+ 7 (==SFX_TITLE_HISTORY)
+ liefert den Titel so, wie MB ihn heute in
+ der History anzeigen m"ochte
+
+ 10 bis USHRT_MAX
+ liefert maximal 'nMaxLength' Zeichen vom logischen
+ Dateinamen inkl. Pfad (remote => ::com::sun::star::util::URL)
+ */
+) const
+
+/* [Beschreibung]
+
+ Liefert den Titel bzw. logischen Dateinamen des Dokuments, je nach
+ 'nMaxLength'.
+
+ Falls der Dateiname mit Pfad verwendet wird, wird die Namensk"urzung durch
+ Ersetzung eines oder mehrerer Directory-Namen durch "..." durchgef"uhrt,
+ URLs werden z.Zt. immer komplett geliefert.
+*/
+
+{
+// if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
+// return String();
+ SfxMedium *pMed = GetMedium();
+ if ( IsLoading() )
+ return String();
+
+/* if ( !nMaxLength && pImp->pDocInfo )
+ {
+ String aTitle = pImp->pDocInfo->GetTitle();
+ if ( aTitle.Len() )
+ return aTitle;
+ } */
+
+ // Titel erzeugen?
+ if ( SFX_TITLE_DETECT == nMaxLength && !pImp->aTitle.Len() )
+ {
+ static sal_Bool bRecur = sal_False;
+ if ( bRecur )
+ return DEFINE_CONST_UNICODE( "-not available-" );
+ bRecur = sal_True;
+
+ String aTitle;
+ SfxObjectShell *pThis = (SfxObjectShell*) this;
+
+ if ( pMed )
+ {
+ SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
+ if ( pNameItem )
+ aTitle = pNameItem->GetValue();
+ }
+
+ if ( !aTitle.Len() )
+ aTitle = GetTitle( SFX_TITLE_FILENAME );
+
+ if ( IsTemplate() )
+ pThis->SetTitle( aTitle );
+ bRecur = sal_False;
+ return X(aTitle);
+ }
+ else if (SFX_TITLE_APINAME == nMaxLength )
+ return X(GetAPIName());
+
+ // Sonderfall Vorlagen:
+ if( IsTemplate() && pImp->aTitle.Len() &&
+ ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
+ return X(pImp->aTitle);
+
+ // Picklist/Caption wird gemappt
+ if ( pMed && ( nMaxLength == SFX_TITLE_CAPTION || nMaxLength == SFX_TITLE_PICKLIST ) )
+ {
+ // Wenn ein spezieller Titel beim "Offnen mitgegeben wurde;
+ // wichtig bei URLs, die INET_PROT_FILE verwenden, denn bei denen
+ // wird der gesetzte Titel nicht beachtet.
+ // (s.u., Auswertung von aTitleMap_Impl)
+ SFX_ITEMSET_ARG( pMed->GetItemSet(), pNameItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
+ if ( pNameItem )
+ return X( pNameItem->GetValue() );
+ }
+
+ // noch unbenannt?
+ DBG_ASSERT( !HasName() || pMed, "HasName() aber kein Medium?!?" );
+ if ( !HasName() || !pMed )
+ {
+ // schon Titel gesezt?
+ if ( pImp->aTitle.Len() )
+ return X(pImp->aTitle);
+
+ // mu\s es durchnumeriert werden?
+ String aNoName( SfxResId( STR_NONAME ) );
+ if ( pImp->bIsNamedVisible )
+ // Nummer hintenanh"angen
+ aNoName += String::CreateFromInt32( pImp->nVisualDocumentNumber );
+
+ // Dokument hei\st vorerst 'unbenannt#'
+ return X(aNoName);
+ }
+
+ const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
+ if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY )
+ {
+ sal_uInt16 nRemote;
+ if( !pMed || aURL.GetProtocol() == INET_PROT_FILE )
+ nRemote = 0;
+ else
+ nRemote = 1;
+ nMaxLength = aTitleMap_Impl[nMaxLength-SFX_TITLE_CAPTION][nRemote];
+ }
+
+ // lokale Datei?
+ if ( aURL.GetProtocol() == INET_PROT_FILE )
+ {
+ String aName( aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() ).PathToFileName() : aURL.PathToFileName() );
+ if ( nMaxLength == SFX_TITLE_FULLNAME )
+ return X( aName );
+ else if ( nMaxLength == SFX_TITLE_FILENAME )
+ return X( aURL.getName( INetURLObject::LAST_SEGMENT,
+ true, INetURLObject::DECODE_WITH_CHARSET ) );
+ else if ( !pImp->aTitle.Len() )
+ pImp->aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT,
+ true, INetURLObject::DECODE_WITH_CHARSET );
+ }
+ else
+ {
+ // ::com::sun::star::util::URL-Versionen
+ if ( nMaxLength >= SFX_TITLE_MAXLEN )
+ {
+ String aComplete( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
+ if( aComplete.Len() > nMaxLength )
+ {
+ String aRet( DEFINE_CONST_UNICODE( "..." ) );
+ aRet += aComplete.Copy( aComplete.Len() - nMaxLength + 3, nMaxLength - 3 );
+ return X( aRet );
+ }
+ else
+ return X( aComplete );
+ }
+ else if ( nMaxLength == SFX_TITLE_FILENAME )
+ {
+ String aName( aURL.GetBase() );
+ aName = INetURLObject::decode( aName, INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET );
+ if( !aName.Len() )
+ aName = aURL.GetURLNoPass();
+ return X(aName);
+ }
+ else if ( nMaxLength == SFX_TITLE_FULLNAME )
+ return X(aURL.GetMainURL( INetURLObject::DECODE_TO_IURI ));
+
+ // ggf. Titel aus Dateiname generieren
+ if ( !pImp->aTitle.Len() )
+ pImp->aTitle = aURL.GetBase();
+
+ // workaround for the case when the name can not be retrieved from URL by INetURLObject
+ if ( !pImp->aTitle.Len() )
+ pImp->aTitle = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
+ }
+
+ // ganzer Titel
+ return X(pImp->aTitle);
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::InvalidateName()
+
+/* [Beschreibung]
+
+ Ermittelt den Titel des Dokuments neu aus 'unbenannt', DocInfo-Titel
+ bzw. Dateinamen. Wird nach Laden aus Template oder SaveAs ben"otigt.
+*/
+
+{
+ // Title neu erzeugen
+ pImp->aTitle.Erase();
+// pImp->nVisualDocumentNumber = USHRT_MAX;
+ //GetTitle( SFX_TITLE_DETECT );
+ SetName( GetTitle( SFX_TITLE_APINAME ) );
+
+ // Benachrichtigungen
+ Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::SetNamedVisibility_Impl()
+{
+ if ( !pImp->bIsNamedVisible )
+ {
+ // Nummer verpassen
+ pImp->bIsNamedVisible = sal_True;
+ // ggf. neue Nummer verpassen
+ if ( !HasName() && USHRT_MAX == pImp->nVisualDocumentNumber && !pImp->aTitle.Len() )
+ {
+ pImp->nVisualDocumentNumber = SFX_APP()->GetFreeIndex();
+ Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
+ }
+ }
+
+ SetName( GetTitle(SFX_TITLE_APINAME) );
+}
+
+void SfxObjectShell::SetNoName()
+{
+ bHasName = 0;
+ bIsTmp = sal_True;
+ GetModel()->attachResource( ::rtl::OUString(), GetModel()->getArgs() );
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::MemoryError()
+{
+}
+
+//--------------------------------------------------------------------
+
+SfxProgress* SfxObjectShell::GetProgress() const
+{
+ return pImp->pProgress;
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::SetProgress_Impl
+(
+ SfxProgress *pProgress /* zu startender <SfxProgress> oder 0, falls
+ der Progress zur"uckgesetzt werden soll */
+)
+
+/* [Beschreibung]
+
+ Interne Methode zum setzen oder zur"ucksetzen des Progress-Modes
+ f"ur diese SfxObjectShell.
+*/
+
+{
+ DBG_ASSERT( ( !pImp->pProgress && pProgress ) ||
+ ( pImp->pProgress && !pProgress ),
+ "Progress activation/deacitivation mismatch" );
+ pImp->pProgress = pProgress;
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame* pFrame )
+{
+ SfxApplication* pSfxApp = SFX_APP();
+ if ( !pSfxApp->IsDowning() && !IsLoading() && pFrame && !pFrame->GetFrame().IsClosing_Impl() )
+ {
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
+ if ( !pHiddenItem || !pHiddenItem->GetValue() )
+ {
+ sal_uInt16 nId = pImp->nEventId;
+ pImp->nEventId = 0;
+ if ( nId == SFX_EVENT_OPENDOC )
+ pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_OPENDOC), this, pFrame->GetFrame().GetController() ), sal_False);
+ else if (nId == SFX_EVENT_CREATEDOC )
+ pSfxApp->NotifyEvent(SfxViewEventHint( nId, GlobalEventConfig::GetEventName(STR_EVENT_CREATEDOC), this, pFrame->GetFrame().GetController() ), sal_False);
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::SetActivateEvent_Impl(sal_uInt16 nId )
+{
+ if ( GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC )
+ pImp->nEventId = nId;
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::RegisterTransfer( SfxMedium& rMedium )
+/* [Beschreibung ]
+ Alle Medien, die aufgesetzt werden, um Teile eines Dokumentes zu
+ laden, muessen an der zugehoerigen SfxObjectShell angemeldet
+ werden. So kann dokumentweise abgebrochen werden. */
+{
+ rMedium.SetReferer( GetMedium()->GetName() );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::PrepareReload( )
+/* [Beschreibung ]
+ Wird vor dem Reload gerufen und gibt die Moeglichkeit,
+ etwaige Caches zu leeren. */
+{
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::LockAutoLoad( sal_Bool bLock )
+
+/* Verhindert ein evtl. eintreffendes AutoLoad. Wird auch vor AutoLoad
+ eines umgebenden FrameSet beruecksichtigt.
+*/
+
+{
+ if ( bLock )
+ ++pImp->nAutoLoadLocks;
+ else
+ --pImp->nAutoLoadLocks;
+}
+
+//-------------------------------------------------------------------------
+
+// kann nach frame.cxx gemoved werden, wenn 358+36x-Stand gemerged sind
+
+sal_Bool SfxFrame::IsAutoLoadLocked_Impl() const
+{
+ // sein einges Doc gelockt?
+ const SfxObjectShell* pObjSh = GetCurrentDocument();
+ if ( !pObjSh || !pObjSh->IsAutoLoadLocked() )
+ return sal_False;
+
+ // seine Childs gelockt?
+ for ( sal_uInt16 n = GetChildFrameCount(); n--; )
+ if ( !GetChildFrame(n)->IsAutoLoadLocked_Impl() )
+ return sal_False;
+
+ // sonst ist AutoLoad erlaubt
+ return sal_True;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsAutoLoadLocked() const
+
+/* Liefert, ob ein eintreffendes AutoLoad ausgefuehrt werden darf. Wird auch
+ vor AutoLoad eines umgebenden FrameSet beruecksichtigt.
+*/
+
+{
+ return !IsReadOnly() || pImp->nAutoLoadLocks > 0;
+}
+
+//-------------------------------------------------------------------------
+void SfxObjectShell::BreakMacroSign_Impl( sal_Bool bBreakMacroSign )
+{
+ pImp->m_bMacroSignBroken = bBreakMacroSign;
+}
+
+//-------------------------------------------------------------------------
+void SfxObjectShell::CheckSecurityOnLoading_Impl()
+{
+ uno::Reference< task::XInteractionHandler > xInteraction;
+ if ( GetMedium() )
+ xInteraction = GetMedium()->GetInteractionHandler();
+
+ // check if there is a broken signature...
+ CheckForBrokenDocSignatures_Impl( xInteraction );
+
+ CheckEncryption_Impl( xInteraction );
+
+ // check macro security
+ pImp->aMacroMode.checkMacrosOnLoading( xInteraction );
+}
+
+//-------------------------------------------------------------------------
+void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
+{
+ ::rtl::OUString aVersion;
+ sal_Bool bIsEncrypted = sal_False;
+ sal_Bool bHasNonEncrypted = sal_False;
+
+ try
+ {
+ uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion;
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasEncryptedEntries" ) ) ) >>= bIsEncrypted;
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasNonEncryptedEntries" ) ) ) >>= bHasNonEncrypted;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ if ( aVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
+ {
+ // this is ODF1.2 or later
+ if ( bIsEncrypted && bHasNonEncrypted )
+ {
+ if ( !pImp->m_bIncomplEncrWarnShown )
+ {
+ // this is an encrypted document with nonencrypted streams inside, show the warning
+ ::com::sun::star::task::ErrorCodeRequest aErrorCode;
+ aErrorCode.ErrCode = ERRCODE_SFX_INCOMPLETE_ENCRYPTION;
+
+ SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
+ pImp->m_bIncomplEncrWarnShown = sal_True;
+ }
+
+ // broken signatures imply no macro execution at all
+ pImp->aMacroMode.disallowMacroExecution();
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+void SfxObjectShell::CheckForBrokenDocSignatures_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
+{
+ sal_Int16 nSignatureState = GetDocumentSignatureState();
+ bool bSignatureBroken = ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN );
+ if ( !bSignatureBroken )
+ return;
+
+ pImp->showBrokenSignatureWarning( xHandler );
+
+ // broken signatures imply no macro execution at all
+ pImp->aMacroMode.disallowMacroExecution();
+}
+
+//-------------------------------------------------------------------------
+void SfxObjectShell::SetAutoLoad(
+ const INetURLObject& rUrl, sal_uInt32 nTime, sal_Bool bReload )
+{
+ if ( pImp->pReloadTimer )
+ DELETEZ(pImp->pReloadTimer);
+ if ( bReload )
+ {
+ pImp->pReloadTimer = new AutoReloadTimer_Impl(
+ rUrl.GetMainURL( INetURLObject::DECODE_TO_IURI ),
+ nTime, bReload, this );
+ pImp->pReloadTimer->Start();
+ }
+}
+
+sal_Bool SfxObjectShell::IsLoadingFinished() const
+{
+ return ( pImp->nLoadedFlags == SFX_LOADED_ALL );
+}
+
+void impl_addToModelCollection(const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& xModel);
+void SfxObjectShell::InitOwnModel_Impl()
+{
+ if ( !pImp->bModelInitialized )
+ {
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
+ if ( pSalvageItem )
+ {
+ pImp->aTempName = pMedium->GetPhysicalName();
+ pMedium->GetItemSet()->ClearItem( SID_DOC_SALVAGE );
+ pMedium->GetItemSet()->ClearItem( SID_FILE_NAME );
+ pMedium->GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, pMedium->GetOrigURL() ) );
+ }
+ else
+ {
+ pMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
+ pMedium->GetItemSet()->ClearItem( SID_DOCUMENT );
+ }
+
+ pMedium->GetItemSet()->ClearItem( SID_REFERER );
+ uno::Reference< frame::XModel > xModel ( GetModel(), uno::UNO_QUERY );
+ if ( xModel.is() )
+ {
+ ::rtl::OUString aURL = GetMedium()->GetOrigURL();
+ SfxItemSet *pSet = GetMedium()->GetItemSet();
+ if ( !GetMedium()->IsReadOnly() )
+ pSet->ClearItem( SID_INPUTSTREAM );
+ uno::Sequence< beans::PropertyValue > aArgs;
+ TransformItems( SID_OPENDOC, *pSet, aArgs );
+ xModel->attachResource( aURL, aArgs );
+ impl_addToModelCollection(xModel);
+ }
+
+ pImp->bModelInitialized = sal_True;
+ }
+}
+
+void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags )
+{
+ sal_Bool bSetModifiedTRUE = sal_False;
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
+ if( ( nFlags & SFX_LOADED_MAINDOCUMENT ) && !(pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
+ && !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ))
+ {
+ pImp->nFlagsInProgress |= SFX_LOADED_MAINDOCUMENT;
+ ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())->SetAttributes();
+ pImp->bImportDone = sal_True;
+ if( !IsAbortingImport() )
+ PositionView_Impl();
+
+ if ( ( GetModifyPasswordHash() || GetModifyPasswordInfo().getLength() ) && !IsModifyPasswordEntered() )
+ SetReadOnly();
+
+ // Salvage
+ if ( pSalvageItem )
+ bSetModifiedTRUE = sal_True;
+
+ if ( !IsEnableSetModified() )
+ EnableSetModified( sal_True );
+
+ if( !bSetModifiedTRUE && IsEnableSetModified() )
+ SetModified( sal_False );
+
+ CheckSecurityOnLoading_Impl();
+
+ bHasName = sal_True; // the document is loaded, so the name should already available
+ GetTitle( SFX_TITLE_DETECT );
+ InitOwnModel_Impl();
+ pImp->nFlagsInProgress &= ~SFX_LOADED_MAINDOCUMENT;
+ }
+
+ if( ( nFlags & SFX_LOADED_IMAGES ) && !(pImp->nLoadedFlags & SFX_LOADED_IMAGES )
+ && !(pImp->nFlagsInProgress & SFX_LOADED_IMAGES ))
+ {
+ pImp->nFlagsInProgress |= SFX_LOADED_IMAGES;
+ uno::Reference<document::XDocumentProperties> xDocProps(
+ getDocProperties());
+ ::rtl::OUString url(xDocProps->getAutoloadURL());
+ sal_Int32 delay(xDocProps->getAutoloadSecs());
+ SetAutoLoad( INetURLObject(url), delay * 1000,
+ (delay > 0) || url.getLength() );
+ if( !bSetModifiedTRUE && IsEnableSetModified() )
+ SetModified( sal_False );
+ Invalidate( SID_SAVEASDOC );
+ pImp->nFlagsInProgress &= ~SFX_LOADED_IMAGES;
+ }
+
+ pImp->nLoadedFlags |= nFlags;
+
+ if ( !pImp->nFlagsInProgress )
+ {
+ // in case of reentrance calls the first called FinishedLoading() call on the stack
+ // should do the notification, in result the notification is done when all the FinishedLoading() calls are finished
+
+ if ( bSetModifiedTRUE )
+ SetModified( sal_True );
+ else
+ SetModified( sal_False );
+
+ if ( (pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) && (pImp->nLoadedFlags & SFX_LOADED_IMAGES ) )
+ {
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
+ sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
+
+ // closing the streams on loading should be under control of SFX!
+ DBG_ASSERT( pMedium->IsOpen(), "Don't close the medium when loading documents!" );
+
+ if ( bTemplate )
+ {
+ TemplateDisconnectionAfterLoad();
+ }
+ else
+ {
+ // if a readonly medium has storage then it's stream is already based on temporary file
+ if( !(pMedium->GetOpenMode() & STREAM_WRITE) && !pMedium->HasStorage_Impl() )
+ // don't lock file opened read only
+ pMedium->CloseInStream();
+ }
+ }
+
+ SetInitialized_Impl( false );
+
+ // Title is not available until loading has finished
+ Broadcast( SfxSimpleHint( SFX_HINT_TITLECHANGED ) );
+ if ( pImp->nEventId )
+ PostActivateEvent_Impl(SfxViewFrame::GetFirst(this));
+ }
+}
+
+//-------------------------------------------------------------------------
+extern void SetTemplate_Impl( const String&, const String&, SfxObjectShell* );
+
+void SfxObjectShell::TemplateDisconnectionAfterLoad()
+{
+ // document is created from a template
+ //TODO/LATER: should the templates always be XML docs!
+
+ SfxMedium* pTmpMedium = pMedium;
+ if ( pTmpMedium )
+ {
+ String aName( pTmpMedium->GetName() );
+ SFX_ITEMSET_ARG( pTmpMedium->GetItemSet(), pTemplNamItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False);
+ String aTemplateName;
+ if ( pTemplNamItem )
+ aTemplateName = pTemplNamItem->GetValue();
+ else
+ {
+ // !TODO/LATER: what's this?!
+ // Interaktiv ( DClick, Contextmenu ) kommt kein Langname mit
+ aTemplateName = getDocProperties()->getTitle();
+ if ( !aTemplateName.Len() )
+ {
+ INetURLObject aURL( aName );
+ aURL.CutExtension();
+ aTemplateName = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+ }
+ }
+
+ // set medium to noname
+ pTmpMedium->SetName( String(), sal_True );
+ pTmpMedium->Init_Impl();
+
+ // drop resource
+ SetNoName();
+ InvalidateName();
+
+ if( IsPackageStorageFormat_Impl( *pTmpMedium ) )
+ {
+ // untitled document must be based on temporary storage
+ // the medium should not dispose the storage in this case
+ uno::Reference < embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
+ GetStorage()->copyToStorage( xTmpStor );
+
+ // the medium should disconnect from the original location
+ // the storage should not be disposed since the document is still
+ // based on it, but in DoSaveCompleted it will be disposed
+ pTmpMedium->CanDisposeStorage_Impl( sal_False );
+ pTmpMedium->Close();
+
+ // setting the new storage the medium will be based on
+ pTmpMedium->SetStorage_Impl( xTmpStor );
+
+ ForgetMedium();
+ if( !DoSaveCompleted( pTmpMedium ) )
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ else
+ {
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
+ sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
+
+ if ( !bSalvage )
+ {
+ // some further initializations for templates
+ SetTemplate_Impl( aName, aTemplateName, this );
+ }
+
+ // the medium should not dispose the storage, DoSaveCompleted() has let it to do so
+ pTmpMedium->CanDisposeStorage_Impl( sal_False );
+ }
+ }
+ else
+ {
+ // some further initializations for templates
+ SetTemplate_Impl( aName, aTemplateName, this );
+ pTmpMedium->CreateTempFile( sal_True );
+ }
+
+ // templates are never readonly
+ pTmpMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
+ pTmpMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True );
+
+ // notifications about possible changes in readonly state and document info
+ Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
+
+ // created untitled document can't be modified
+ SetModified( sal_False );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::PositionView_Impl()
+{
+ MarkData_Impl *pMark = Get_Impl()->pMarkData;
+ if( pMark )
+ {
+ SfxViewShell* pSh = pMark->pFrame->GetViewShell();
+ if( pMark->aUserData.Len() )
+ pSh->ReadUserData( pMark->aUserData, sal_True );
+ else if( pMark->aMark.Len() )
+ pSh->JumpToMark( pMark->aMark );
+ DELETEZ( Get_Impl()->pMarkData );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsLoading() const
+/* [Beschreibung ]
+ Has FinishedLoading been called? */
+{
+ return !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::CancelTransfers()
+/* [Beschreibung ]
+ Hier koennen Transfers gecanceled werden, die nicht mit
+ RegisterTransfer registiert wurden */
+{
+ if( ( pImp->nLoadedFlags & SFX_LOADED_ALL ) != SFX_LOADED_ALL )
+ {
+ AbortImport();
+ if( IsLoading() )
+ FinishedLoading( SFX_LOADED_ALL );
+
+/*
+ SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
+ while( pFrame )
+ {
+ pFrame->CancelTransfers();
+ pFrame = SfxViewFrame::GetNext( *pFrame, this );
+ }*/
+ }
+}
+
+//-------------------------------------------------------------------------
+
+AutoReloadTimer_Impl::AutoReloadTimer_Impl(
+ const String& rURL, sal_uInt32 nTime, sal_Bool bReloadP, SfxObjectShell* pSh )
+ : aUrl( rURL ), bReload( bReloadP ), pObjSh( pSh )
+{
+ SetTimeout( nTime );
+}
+
+//-------------------------------------------------------------------------
+
+void AutoReloadTimer_Impl::Timeout()
+{
+ SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjSh );
+
+ if ( pFrame )
+ {
+ // momentan nicht m"oglich/sinnvoll?
+ if ( !pObjSh->CanReload_Impl() || pObjSh->IsAutoLoadLocked() || Application::IsUICaptured() )
+ {
+ // erneuten Versuch erlauben
+ Start();
+ return;
+ }
+
+ SfxAllItemSet aSet( SFX_APP()->GetPool() );
+ aSet.Put( SfxBoolItem( SID_AUTOLOAD, sal_True ) );
+ if ( aUrl.Len() )
+ aSet.Put( SfxStringItem( SID_FILE_NAME, aUrl ) );
+ SfxRequest aReq( SID_RELOAD, 0, aSet );
+ pObjSh->Get_Impl()->pReloadTimer = 0;
+ delete this;
+ pFrame->ExecReload_Impl( aReq );
+ return;
+ }
+
+ pObjSh->Get_Impl()->pReloadTimer = 0;
+ delete this;
+}
+
+SfxModule* SfxObjectShell::GetModule() const
+{
+ return GetFactory().GetModule();
+}
+
+sal_Bool SfxObjectShell::IsBasic(
+ const String & rCode, SbxObject * pVCtrl )
+{
+ if( !rCode.Len() ) return sal_False;
+ return SfxMacroConfig::IsBasic( pVCtrl, rCode, GetBasicManager() );
+}
+
+ErrCode SfxObjectShell::CallBasic( const String& rMacro,
+ const String& rBasic, SbxObject* pVCtrl, SbxArray* pArgs,
+ SbxValue* pRet )
+{
+ SfxApplication* pApp = SFX_APP();
+ if( pApp->GetName() != rBasic )
+ {
+ if ( !AdjustMacroMode( String() ) )
+ return ERRCODE_IO_ACCESSDENIED;
+ }
+
+ pApp->EnterBasicCall();
+ BasicManager *pMgr = GetBasicManager();
+ if( pApp->GetName() == rBasic )
+ pMgr = pApp->GetBasicManager();
+ ErrCode nRet = SfxMacroConfig::Call( pVCtrl, rMacro, pMgr, pArgs, pRet );
+ pApp->LeaveBasicCall();
+ return nRet;
+}
+
+ErrCode SfxObjectShell::Call( const String & rCode, sal_Bool bIsBasicReturn, SbxObject * pVCtrl )
+{
+ ErrCode nErr = ERRCODE_NONE;
+ if ( bIsBasicReturn )
+ CallBasic( rCode, String(), pVCtrl );
+ return nErr;
+}
+
+namespace
+{
+ static bool lcl_isScriptAccessAllowed_nothrow( const Reference< XInterface >& _rxScriptContext )
+ {
+ try
+ {
+ Reference< XEmbeddedScripts > xScripts( _rxScriptContext, UNO_QUERY );
+ if ( !xScripts.is() )
+ {
+ Reference< XScriptInvocationContext > xContext( _rxScriptContext, UNO_QUERY_THROW );
+ xScripts.set( xContext->getScriptContainer(), UNO_SET_THROW );
+ }
+
+ return xScripts->getAllowMacroExecution();
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return false;
+ }
+}
+
+ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptContext, const ::rtl::OUString& _rScriptURL,
+ const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam, bool bRaiseError )
+{
+ OSL_TRACE( "in CallXScript" );
+ ErrCode nErr = ERRCODE_NONE;
+
+ bool bIsDocumentScript = ( _rScriptURL.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "location=document" ) ) >= 0 );
+ // TODO: we should parse the URL, and check whether there is a parameter with this name.
+ // Otherwise, we might find too much.
+ if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
+ return ERRCODE_IO_ACCESSDENIED;
+
+ bool bCaughtException = false;
+ Any aException;
+ try
+ {
+ // obtain/create a script provider
+ Reference< provider::XScriptProvider > xScriptProvider;
+ Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY );
+ if ( xSPS.is() )
+ xScriptProvider.set( xSPS->getScriptProvider() );
+
+ if ( !xScriptProvider.is() )
+ {
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ Reference< provider::XScriptProviderFactory > xScriptProviderFactory(
+ aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
+ xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( _rxScriptContext ) ), UNO_SET_THROW );
+ }
+
+ // obtain the script, and execute it
+ Reference< provider::XScript > xScript( xScriptProvider->getScript( _rScriptURL ), UNO_QUERY_THROW );
+
+ aRet = xScript->invoke( aParams, aOutParamIndex, aOutParam );
+ }
+ catch ( const uno::Exception& )
+ {
+ aException = ::cppu::getCaughtException();
+ bCaughtException = TRUE;
+ nErr = ERRCODE_BASIC_INTERNAL_ERROR;
+ }
+
+ if ( bCaughtException && bRaiseError )
+ {
+ ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg;
+ SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
+ if ( pFact )
+ pScriptErrDlg.reset( pFact->CreateScriptErrorDialog( NULL, aException ) );
+ OSL_ENSURE( pScriptErrDlg.get(), "SfxObjectShell::CallXScript: no script error dialog!" );
+
+ if ( pScriptErrDlg.get() )
+ pScriptErrDlg->Execute();
+ }
+
+ OSL_TRACE( "leaving CallXScript" );
+ return nErr;
+}
+
+// perhaps rename to CallScript once we get rid of the existing CallScript
+// and Call, CallBasic, CallStarBasic methods
+ErrCode SfxObjectShell::CallXScript( const String& rScriptURL,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&
+ aParams,
+ ::com::sun::star::uno::Any& aRet,
+ ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex,
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam
+ , bool bRaiseError )
+{
+ return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError );
+}
+
+//-------------------------------------------------------------------------
+namespace {
+ using namespace ::com::sun::star::uno;
+
+ //.....................................................................
+ static SbxArrayRef lcl_translateUno2Basic( const void* _pAnySequence )
+ {
+ SbxArrayRef xReturn;
+ if ( _pAnySequence )
+ {
+ // in real it's a sequence of Any (by convention)
+ const Sequence< Any >* pArguments = static_cast< const Sequence< Any >* >( _pAnySequence );
+
+ // do we have arguments ?
+ if ( pArguments->getLength() )
+ {
+ // yep
+ xReturn = new SbxArray;
+ String sEmptyName;
+
+ // loop through the sequence
+ const Any* pArg = pArguments->getConstArray();
+ const Any* pArgEnd = pArg + pArguments->getLength();
+
+ for ( sal_uInt16 nArgPos=1; pArg != pArgEnd; ++pArg, ++nArgPos )
+ // and create a Sb object for every Any
+ xReturn->Put( GetSbUnoObject( sEmptyName, *pArg ), nArgPos );
+ }
+ }
+ return xReturn;
+ }
+ //.....................................................................
+ void lcl_translateBasic2Uno( const SbxVariableRef& _rBasicValue, void* _pAny )
+ {
+ if ( _pAny )
+ *static_cast< Any* >( _pAny ) = sbxToUnoValue( _rBasicValue );
+ }
+}
+//-------------------------------------------------------------------------
+ErrCode SfxObjectShell::CallStarBasicScript( const String& _rMacroName, const String& _rLocation,
+ const void* _pArguments, void* _pReturn )
+{
+ OSL_TRACE("in CallSBS");
+ ::vos::OClearableGuard aGuard( Application::GetSolarMutex() );
+
+ // the arguments for the call
+ SbxArrayRef xMacroArguments = lcl_translateUno2Basic( _pArguments );
+
+ // the return value
+ SbxVariableRef xReturn = _pReturn ? new SbxVariable : NULL;
+
+ // the location (document or application)
+ String sMacroLocation;
+ if ( _rLocation.EqualsAscii( "application" ) )
+ sMacroLocation = SFX_APP()->GetName();
+#ifdef DBG_UTIL
+ else
+ DBG_ASSERT( _rLocation.EqualsAscii( "document" ),
+ "SfxObjectShell::CallStarBasicScript: invalid (unknown) location!" );
+#endif
+
+ // call the script
+ ErrCode eError = CallBasic( _rMacroName, sMacroLocation, NULL, xMacroArguments, xReturn );
+
+ // translate the return value
+ lcl_translateBasic2Uno( xReturn, _pReturn );
+
+ // outta here
+ return eError;
+}
+
+//-------------------------------------------------------------------------
+ErrCode SfxObjectShell::CallScript(
+ const String & rScriptType,
+ const String & rCode,
+ const void *pArgs,
+ void *pRet
+)
+{
+ ::vos::OClearableGuard aGuard( Application::GetSolarMutex() );
+ ErrCode nErr = ERRCODE_NONE;
+ if( rScriptType.EqualsAscii( "StarBasic" ) )
+ {
+ // the arguments for the call
+ SbxArrayRef xMacroArguments = lcl_translateUno2Basic( pArgs );
+
+ // the return value
+ SbxVariableRef xReturn = pRet ? new SbxVariable : NULL;
+
+ // call the script
+ nErr = CallBasic( rCode, String(), NULL, xMacroArguments, xReturn );
+
+ // translate the return value
+ lcl_translateBasic2Uno( xReturn, pRet );
+
+ // did this fail because the method was not found?
+ if ( nErr == ERRCODE_BASIC_PROC_UNDEFINED )
+ { // yep-> look in the application BASIC module
+ nErr = CallBasic( rCode, SFX_APP()->GetName(), NULL, xMacroArguments, xReturn );
+ }
+ }
+ else if( rScriptType.EqualsAscii( "JavaScript" ) )
+ {
+ DBG_ERROR( "JavaScript not allowed" );
+ return 0;
+ }
+ else
+ {
+ DBG_ERROR( "StarScript not allowed" );
+ }
+ return nErr;
+}
+
+SfxFrame* SfxObjectShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ )
+{
+ return pSelf;
+}
+
+SfxObjectShellFlags SfxObjectShell::GetFlags() const
+{
+ if( pImp->eFlags == SFXOBJECTSHELL_UNDEFINED )
+ pImp->eFlags = GetFactory().GetFlags();
+ return pImp->eFlags;
+}
+
+void SfxObjectShell::SetFlags( SfxObjectShellFlags eFlags )
+{
+ pImp->eFlags = eFlags;
+}
+
+/*
+void SfxObjectShell::SetBaseURL( const String& rURL )
+{
+ pImp->aBaseURL = rURL;
+ pImp->bNoBaseURL = FALSE;
+}
+
+const String& SfxObjectShell::GetBaseURLForSaving() const
+{
+ if ( pImp->bNoBaseURL )
+ return String();
+ return GetBaseURL();
+}
+
+const String& SfxObjectShell::GetBaseURL() const
+{
+ if ( pImp->aBaseURL.Len() )
+ return pImp->aBaseURL;
+ return pMedium->GetBaseURL();
+}
+
+void SfxObjectShell::SetEmptyBaseURL()
+{
+ pImp->bNoBaseURL = TRUE;
+}
+*/
+String SfxObjectShell::QueryTitle( SfxTitleQuery eType ) const
+{
+ String aRet;
+
+ switch( eType )
+ {
+ case SFX_TITLE_QUERY_SAVE_NAME_PROPOSAL:
+ {
+ SfxMedium* pMed = GetMedium();
+ const INetURLObject aObj( pMed->GetName() );
+ aRet = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
+ if ( !aRet.Len() )
+ aRet = GetTitle( SFX_TITLE_CAPTION );
+ break;
+ }
+ }
+ return aRet;
+}
+
+void SfxHeaderAttributes_Impl::SetAttributes()
+{
+ bAlert = sal_True;
+ SvKeyValue aPair;
+ for( sal_Bool bCont = xIter->GetFirst( aPair ); bCont;
+ bCont = xIter->GetNext( aPair ) )
+ SetAttribute( aPair );
+}
+
+void SfxHeaderAttributes_Impl::SetAttribute( const SvKeyValue& rKV )
+{
+ String aValue = rKV.GetValue();
+ if( rKV.GetKey().CompareIgnoreCaseToAscii( "refresh" ) == COMPARE_EQUAL && rKV.GetValue().Len() )
+ {
+ sal_uInt32 nTime = aValue.GetToken( 0, ';' ).ToInt32() ;
+ String aURL = aValue.GetToken( 1, ';' );
+ aURL.EraseTrailingChars().EraseLeadingChars();
+ uno::Reference<document::XDocumentProperties> xDocProps(
+ pDoc->getDocProperties());
+ if( aURL.Copy(0, 4).CompareIgnoreCaseToAscii( "url=" ) == COMPARE_EQUAL )
+ {
+ INetURLObject aObj;
+ INetURLObject( pDoc->GetMedium()->GetName() ).GetNewAbsURL( aURL.Copy( 4 ), &aObj );
+ xDocProps->setAutoloadURL(
+ aObj.GetMainURL( INetURLObject::NO_DECODE ) );
+ }
+ try
+ {
+ xDocProps->setAutoloadSecs( nTime );
+ }
+ catch (lang::IllegalArgumentException &)
+ {
+ // ignore
+ }
+ }
+ else if( rKV.GetKey().CompareIgnoreCaseToAscii( "expires" ) == COMPARE_EQUAL )
+ {
+ DateTime aDateTime;
+ if( INetRFC822Message::ParseDateField( rKV.GetValue(), aDateTime ) )
+ {
+ aDateTime.ConvertToLocalTime();
+ pDoc->GetMedium()->SetExpired_Impl( aDateTime );
+ }
+ else
+ {
+// DBG_ERROR( "Schlechtes ::com::sun::star::util::DateTime fuer Expired" );
+ pDoc->GetMedium()->SetExpired_Impl( Date( 1, 1, 1970 ) );
+ }
+ }
+ else if( rKV.GetKey().CompareIgnoreCaseToAscii( "content-type" ) == COMPARE_EQUAL )
+ {
+ ::rtl::OString sContent = ::rtl::OUStringToOString( aValue, RTL_TEXTENCODING_ASCII_US );
+ ByteString sType, sSubType;
+ INetContentTypeParameterList aParameters;
+
+ if( INetContentTypes::parse( sContent, sType, sSubType, &aParameters ) )
+ {
+ const INetContentTypeParameter * pCharset = aParameters.find("charset");
+ if (pCharset != 0)
+ pDoc->GetMedium()->SetCharset( pCharset->m_sValue );
+ }
+ }
+}
+
+void SfxHeaderAttributes_Impl::Append( const SvKeyValue& rKV )
+{
+ xIter->Append( rKV );
+ if( bAlert ) SetAttribute( rKV );
+}
+
+SvKeyValueIterator* SfxObjectShell::GetHeaderAttributes()
+{
+ if( !pImp->xHeaderAttributes.Is() )
+ {
+ DBG_ASSERT( pMedium, "Kein Medium" );
+ pImp->xHeaderAttributes = new SfxHeaderAttributes_Impl( this );
+ }
+ return ( SvKeyValueIterator*) &pImp->xHeaderAttributes;
+}
+
+void SfxObjectShell::ClearHeaderAttributesForSourceViewHack()
+{
+ ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
+ ->ClearForSourceView();
+}
+
+
+void SfxObjectShell::SetHeaderAttributesForSourceViewHack()
+{
+ ((SfxHeaderAttributes_Impl*)GetHeaderAttributes())
+ ->SetAttributes();
+}
+
+sal_Bool SfxObjectShell::IsPreview() const
+{
+ if ( !pMedium )
+ return sal_False;
+
+ sal_Bool bPreview = sal_False;
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False);
+ if ( pFlags )
+ {
+ // Werte auf einzelne Items verteilen
+ String aFileFlags = pFlags->GetValue();
+ aFileFlags.ToUpperAscii();
+ if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) )
+ bPreview = sal_True;
+ }
+
+ if ( !bPreview )
+ {
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pItem, SfxBoolItem, SID_PREVIEW, sal_False);
+ if ( pItem )
+ bPreview = pItem->GetValue();
+ }
+
+ return bPreview;
+}
+
+sal_Bool SfxObjectShell::IsSecure()
+{
+ // Wenn globale Warnung an ist, nach Secure-Referer-Liste gehen
+ String aReferer = GetMedium()->GetName();
+ if ( !aReferer.Len() )
+ {
+ // bei neuen Dokumenten das Template als Referer nehmen
+ ::rtl::OUString aTempl( getDocProperties()->getTemplateURL() );
+ if ( aTempl.getLength() )
+ aReferer = INetURLObject( aTempl ).GetMainURL( INetURLObject::NO_DECODE );
+ }
+
+ INetURLObject aURL( "macro:" );
+ if ( !aReferer.Len() )
+ // empty new or embedded document
+ return sal_True;
+
+ SvtSecurityOptions aOpt;
+
+ if( aOpt.GetBasicMode() == eALWAYS_EXECUTE )
+ return sal_True;
+
+ if( aOpt.GetBasicMode() == eNEVER_EXECUTE )
+ return sal_False;
+
+ if ( aOpt.IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) )
+ //if ( SvtSecurityOptions().IsSecureURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aReferer ) )
+ {
+ if ( GetMedium()->GetContent().is() )
+ {
+ Any aAny( ::utl::UCBContentHelper::GetProperty( aURL.GetMainURL( INetURLObject::NO_DECODE ), String( RTL_CONSTASCII_USTRINGPARAM("IsProtected")) ) );
+ sal_Bool bIsProtected = FALSE;
+ if ( ( aAny >>= bIsProtected ) && bIsProtected )
+ return sal_False;
+ else
+ return sal_True;
+ }
+ else
+ return sal_True;
+ }
+ else
+ return sal_False;
+}
+
+void SfxObjectShell::SetWaitCursor( BOOL bSet ) const
+{
+ for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
+ {
+ if ( bSet )
+ pFrame->GetFrame().GetWindow().EnterWait();
+ else
+ pFrame->GetFrame().GetWindow().LeaveWait();
+ }
+}
+
+String SfxObjectShell::GetAPIName() const
+{
+ INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
+ String aName( aURL.GetBase() );
+ if( !aName.Len() )
+ aName = aURL.GetURLNoPass();
+ if ( !aName.Len() )
+ aName = GetTitle( SFX_TITLE_DETECT );
+ return aName;
+}
+
+void SfxObjectShell::Invalidate( USHORT nId )
+{
+ for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this ); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, this ) )
+ Invalidate_Impl( pFrame->GetBindings(), nId );
+}
+
+bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool bSuppressUI )
+{
+ uno::Reference< task::XInteractionHandler > xInteraction;
+ if ( pMedium && !bSuppressUI )
+ xInteraction = pMedium->GetInteractionHandler();
+
+ CheckForBrokenDocSignatures_Impl( xInteraction );
+
+ CheckEncryption_Impl( xInteraction );
+
+ return pImp->aMacroMode.adjustMacroMode( xInteraction );
+}
+
+Window* SfxObjectShell::GetDialogParent( SfxMedium* pLoadingMedium )
+{
+ Window* pWindow = 0;
+ SfxItemSet* pSet = pLoadingMedium ? pLoadingMedium->GetItemSet() : GetMedium()->GetItemSet();
+ SFX_ITEMSET_ARG( pSet, pUnoItem, SfxUnoFrameItem, SID_FILLFRAME, FALSE );
+ if ( pUnoItem )
+ {
+ uno::Reference < frame::XFrame > xFrame( pUnoItem->GetFrame() );
+ pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
+ }
+
+ if ( !pWindow )
+ {
+ SfxFrame* pFrame = 0;
+ SFX_ITEMSET_ARG( pSet, pFrameItem, SfxFrameItem, SID_DOCFRAME, FALSE );
+ if( pFrameItem && pFrameItem->GetFrame() )
+ // get target frame from ItemSet
+ pFrame = pFrameItem->GetFrame();
+ else
+ {
+ // try the current frame
+ SfxViewFrame* pView = SfxViewFrame::Current();
+ if ( !pView || pView->GetObjectShell() != this )
+ // get any visible frame
+ pView = SfxViewFrame::GetFirst(this);
+ if ( pView )
+ pFrame = &pView->GetFrame();
+ }
+
+ if ( pFrame )
+ // get topmost window
+ pWindow = VCLUnoHelper::GetWindow( pFrame->GetFrameInterface()->getContainerWindow() );
+ }
+
+ if ( pWindow )
+ {
+ // this frame may be invisible, show it if it is allowed
+ SFX_ITEMSET_ARG( pSet, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
+ if ( !pHiddenItem || !pHiddenItem->GetValue() )
+ {
+ pWindow->Show();
+ pWindow->ToTop();
+ }
+ }
+
+ return pWindow;
+}
+
+String SfxObjectShell::UpdateTitle( SfxMedium* pMed, USHORT nDocViewNumber )
+{
+ // Titel des Fensters
+ String aTitle;
+ if ( pMed )
+ {
+ INetURLObject aTmp( pMed->GetName() );
+ aTitle = aTmp.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+ }
+ else
+ {
+ pMed = GetMedium();
+ aTitle = GetTitle(SFX_TITLE_CAPTION);
+ String aName(aTitle);
+ if ( nDocViewNumber )
+ {
+ aName += ':';
+ aName += String::CreateFromInt32( nDocViewNumber );
+ }
+ }
+
+ if ( pMed )
+ {
+ SFX_ITEMSET_ARG( pMed->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
+ if ( pRepairedDocItem && pRepairedDocItem->GetValue() )
+ aTitle += String( SfxResId(STR_REPAIREDDOCUMENT) );
+ }
+
+ if ( IsReadOnlyUI() || (pMed && pMed->IsReadOnly()) )
+ aTitle += String( SfxResId(STR_READONLY) );
+ else if ( IsDocShared() )
+ aTitle += String( SfxResId(STR_SHARED) );
+
+ return aTitle;
+}
+
+void SfxObjectShell::SetCreateMode_Impl( SfxObjectCreateMode nMode )
+{
+ eCreateMode = nMode;
+}
+
+BOOL SfxObjectShell::IsInPlaceActive()
+{
+ if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
+ return FALSE;
+
+ SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
+ return pFrame && pFrame->GetFrame().IsInPlace();
+}
+
+BOOL SfxObjectShell::IsUIActive()
+{
+ if ( eCreateMode != SFX_CREATE_MODE_EMBEDDED )
+ return FALSE;
+
+ SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
+ return pFrame && pFrame->GetFrame().IsInPlace() && pFrame->GetFrame().GetWorkWindow_Impl()->IsVisible_Impl();
+}
+
+void SfxObjectShell::UIActivate( BOOL )
+{
+}
+
+void SfxObjectShell::InPlaceActivate( BOOL )
+{
+}
+
+sal_Bool SfxObjectShell::UseInteractionToHandleError(
+ const uno::Reference< task::XInteractionHandler >& xHandler,
+ sal_uInt32 nError )
+{
+ sal_Bool bResult = sal_False;
+
+ if ( xHandler.is() )
+ {
+ try
+ {
+ uno::Any aInteraction;
+ uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations(2);
+ ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort();
+ ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove();
+ lContinuations[0] = uno::Reference< task::XInteractionContinuation >(
+ static_cast< task::XInteractionContinuation* >( pAbort ), uno::UNO_QUERY );
+ lContinuations[1] = uno::Reference< task::XInteractionContinuation >(
+ static_cast< task::XInteractionContinuation* >( pApprove ), uno::UNO_QUERY );
+
+ task::ErrorCodeRequest aErrorCode;
+ aErrorCode.ErrCode = nError;
+ aInteraction <<= aErrorCode;
+ xHandler->handle(::framework::InteractionRequest::CreateRequest (aInteraction,lContinuations));
+ bResult = pAbort->wasSelected();
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ return bResult;
+}
+
+sal_Bool SfxObjectShell_Impl::NeedsOfficeUpdateDialog()
+{
+ // if the configuration is not available for any reason, the default behavior is to show the message
+ sal_Bool bResult = sal_True;
+
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
+ uno::Reference< uno::XInterface > xCommonConfig(
+ ::comphelper::ConfigurationHelper::openConfig(
+ xServiceManager,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
+ ::comphelper::ConfigurationHelper::E_STANDARD ),
+ uno::UNO_SET_THROW );
+
+ ::comphelper::ConfigurationHelper::readRelativeKey(
+ xCommonConfig,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Load/" ) ),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShowOfficeUpdateDialog" ) ) ) >>= bResult;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return bResult;
+}
+
+sal_Int16 SfxObjectShell_Impl::getCurrentMacroExecMode() const
+{
+ sal_Int16 nImposedExecMode( MacroExecMode::NEVER_EXECUTE );
+
+ const SfxMedium* pMedium( rDocShell.GetMedium() );
+ OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
+ if ( pMedium )
+ {
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pMacroModeItem, SfxUInt16Item, SID_MACROEXECMODE, sal_False);
+ if ( pMacroModeItem )
+ nImposedExecMode = pMacroModeItem->GetValue();
+ }
+ return nImposedExecMode;
+}
+
+sal_Bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
+{
+ const SfxMedium* pMedium( rDocShell.GetMedium() );
+ OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getCurrentMacroExecMode: no medium!" );
+ if ( pMedium )
+ {
+ pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, nMacroMode ) );
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+::rtl::OUString SfxObjectShell_Impl::getDocumentLocation() const
+{
+ ::rtl::OUString sLocation;
+
+ const SfxMedium* pMedium( rDocShell.GetMedium() );
+ OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getDocumentLocation: no medium!" );
+ if ( pMedium )
+ {
+ sLocation = pMedium->GetName();
+ if ( !sLocation.getLength() )
+ {
+ // for documents made from a template: get the name of the template
+ sLocation = rDocShell.getDocProperties()->getTemplateURL();
+ }
+ }
+ return sLocation;
+}
+
+uno::Reference< embed::XStorage > SfxObjectShell_Impl::getZipStorageToSign()
+{
+ Reference < embed::XStorage > xStore;
+
+ SfxMedium* pMedium( rDocShell.GetMedium() );
+ OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" );
+ if ( pMedium )
+ xStore = pMedium->GetZipStorageToSign_Impl();
+
+ return xStore;
+}
+
+sal_Bool SfxObjectShell_Impl::documentStorageHasMacros() const
+{
+ return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage );
+}
+
+Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const
+{
+ return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY );
+}
+
+sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState()
+{
+ sal_Int16 nSignatureState( rDocShell.GetScriptingSignatureState() );
+
+ if ( nSignatureState != SIGNATURESTATE_NOSIGNATURES && m_bMacroSignBroken )
+ {
+ // if there is a macro signature it must be handled as broken
+ nSignatureState = SIGNATURESTATE_SIGNATURES_BROKEN;
+ }
+
+ return nSignatureState;
+}
+
+sal_Bool SfxObjectShell_Impl::hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor )
+{
+ sal_Bool bResult = sal_False;
+
+ try
+ {
+ ::rtl::OUString aVersion;
+ try
+ {
+ uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW );
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion;
+ }
+ catch( uno::Exception& )
+ {
+ }
+ uno::Sequence< uno::Any > aArgs( 1 );
+ aArgs[0] <<= aVersion;
+
+ uno::Reference< security::XDocumentDigitalSignatures > xSigner( comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), aArgs ), uno::UNO_QUERY_THROW );
+
+ if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN
+ || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
+ || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
+ {
+ uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.ImplAnalyzeSignature( sal_True, xSigner );
+
+ if ( aInfo.getLength() )
+ {
+ if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN )
+ nScriptingSignatureState = rDocShell.ImplCheckSignaturesInformation( aInfo );
+
+ if ( nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
+ || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
+ {
+ for ( sal_Int32 nInd = 0; !bResult && nInd < aInfo.getLength(); nInd++ )
+ {
+ bResult = xSigner->isAuthorTrusted( aInfo[nInd].Signer );
+ }
+
+ if ( !bResult && bAllowUIToAddAuthor )
+ {
+ uno::Reference< task::XInteractionHandler > xInteraction;
+ if ( rDocShell.GetMedium() )
+ xInteraction = rDocShell.GetMedium()->GetInteractionHandler();
+
+ if ( xInteraction.is() )
+ {
+ task::DocumentMacroConfirmationRequest aRequest;
+ aRequest.DocumentURL = getDocumentLocation();
+ aRequest.DocumentStorage = rDocShell.GetMedium()->GetZipStorageToSign_Impl();
+ aRequest.DocumentSignatureInformation = aInfo;
+ aRequest.DocumentVersion = aVersion;
+ aRequest.Classification = task::InteractionClassification_QUERY;
+ bResult = SfxMedium::CallApproveHandler( xInteraction, uno::makeAny( aRequest ), sal_True );
+ }
+ }
+ }
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {}
+
+ return bResult;
+}
+
+void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference< task::XInteractionHandler >& _rxInteraction ) const
+{
+ if ( !bSignatureErrorIsShown )
+ {
+ SfxObjectShell::UseInteractionToHandleError( _rxInteraction, ERRCODE_SFX_BROKENSIGNATURE );
+ const_cast< SfxObjectShell_Impl* >( this )->bSignatureErrorIsShown = sal_True;
+ }
+}
+
+void SfxObjectShell::AddLog( const ::rtl::OUString& aMessage )
+{
+ if ( !pImp->m_xLogRing.is() )
+ {
+ try
+ {
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ if ( aContext.is() )
+ pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ if ( pImp->m_xLogRing.is() )
+ pImp->m_xLogRing->logString( aMessage );
+}
+
+namespace {
+
+void WriteStringInStream( const uno::Reference< io::XOutputStream >& xOutStream, const ::rtl::OUString& aString )
+{
+ if ( xOutStream.is() )
+ {
+ ::rtl::OString aStrLog = ::rtl::OUStringToOString( aString, RTL_TEXTENCODING_UTF8 );
+ uno::Sequence< sal_Int8 > aLogData( (const sal_Int8*)aStrLog.getStr(), aStrLog.getLength() );
+ xOutStream->writeBytes( aLogData );
+
+ aLogData.realloc( 1 );
+ aLogData[0] = '\n';
+ xOutStream->writeBytes( aLogData );
+ }
+}
+
+}
+
+void SfxObjectShell::StoreLog()
+{
+ if ( !pImp->m_xLogRing.is() )
+ {
+ try
+ {
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ if ( aContext.is() )
+ pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW );
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ if ( pImp->m_xLogRing.is() )
+ {
+#ifdef WNT
+ ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$BRAND_BASE_DIR/program/bootstrap.ini:UserInstallation}" ) );
+#else
+ ::rtl::OUString aFileURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}" ) );
+#endif
+
+ ::rtl::Bootstrap::expandMacros( aFileURL );
+
+#ifdef WNT
+ ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$BRAND_BASE_DIR/program/setup.ini:buildid}" ) );
+#else
+ ::rtl::OUString aBuildID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "${$BRAND_BASE_DIR/program/setuprc:buildid}" ) );
+#endif
+
+ ::rtl::Bootstrap::expandMacros( aBuildID );
+
+ if ( aFileURL.getLength() )
+ {
+ aFileURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/temp/document_io_logring.txt" ) );
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
+ uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( xFactory->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY_THROW );
+ uno::Reference< io::XStream > xStream( xSimpleFileAccess->openFileReadWrite( aFileURL ), uno::UNO_SET_THROW );
+ uno::Reference< io::XOutputStream > xOutStream( xStream->getOutputStream(), uno::UNO_SET_THROW );
+ uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY_THROW );
+ xTruncate->truncate();
+
+ if ( aBuildID.getLength() )
+ WriteStringInStream( xOutStream, aBuildID );
+
+ uno::Sequence< ::rtl::OUString > aLogSeq = pImp->m_xLogRing->getCollectedLog();
+ for ( sal_Int32 nInd = 0; nInd < aLogSeq.getLength(); nInd++ )
+ WriteStringInStream( xOutStream, aLogSeq[nInd] );
+ }
+ catch( uno::Exception& )
+ {}
+ }
+ }
+}
+
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
new file mode 100644
index 000000000000..c9b5e6f37293
--- /dev/null
+++ b/sfx2/source/doc/objserv.cxx
@@ -0,0 +1,1515 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sot/storage.hxx>
+#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
+#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
+#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/XControlAccess.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/task/XStatusIndicator.hpp>
+#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
+#include <com/sun/star/frame/XDocumentTemplates.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/security/CertificateValidity.hpp>
+
+#include <com/sun/star/security/DocumentSignatureInformation.hpp>
+#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+#include <tools/urlobj.hxx>
+#include <svl/whiter.hxx>
+#include <vcl/msgbox.hxx>
+#include <svl/intitem.hxx>
+#include <svl/eitem.hxx>
+#include <vcl/wrkwin.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+
+#include <comphelper/string.hxx>
+#include <basic/sbx.hxx>
+#include <unotools/pathoptions.hxx>
+#include <unotools/useroptions.hxx>
+#include <svtools/asynclink.hxx>
+#include <unotools/saveopt.hxx>
+#include <comphelper/documentconstants.hxx>
+
+#include <sfx2/app.hxx>
+#include <sfx2/signaturestate.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/event.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/printer.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/doctdlg.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/dinfdlg.hxx>
+#include <sfx2/objitem.hxx>
+#include <sfx2/objsh.hxx>
+#include "objshimp.hxx"
+#include "sfxtypes.hxx"
+//#include "interno.hxx"
+#include <sfx2/module.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "versdlg.hxx"
+#include "doc.hrc"
+#include <sfx2/docfac.hxx>
+#include <sfx2/fcontnr.hxx>
+#include <sfx2/filedlghelper.hxx>
+#include "sfx2/sfxhelp.hxx"
+#include <sfx2/msgpool.hxx>
+#include <sfx2/objface.hxx>
+
+#include "../appl/app.hrc"
+#include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/util/XCloneable.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+
+#include "helpid.hrc"
+
+#include "guisaveas.hxx"
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::ui::dialogs;
+using namespace ::com::sun::star::awt;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::task;
+
+//====================================================================
+
+class SfxSaveAsContext_Impl
+{
+ String& _rNewNameVar;
+ String _aNewName;
+
+public:
+ SfxSaveAsContext_Impl( String &rNewNameVar,
+ const String &rNewName )
+ : _rNewNameVar( rNewNameVar ),
+ _aNewName( rNewName )
+ { rNewNameVar = rNewName; }
+ ~SfxSaveAsContext_Impl()
+ { _rNewNameVar.Erase(); }
+};
+
+//====================================================================
+
+#define SfxObjectShell
+#include "sfxslots.hxx"
+
+//=========================================================================
+
+
+
+SFX_IMPL_INTERFACE(SfxObjectShell,SfxShell,SfxResId(0))
+{
+}
+
+//=========================================================================
+
+class SfxClosePreventer_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
+{
+ sal_Bool m_bGotOwnership;
+ sal_Bool m_bPreventClose;
+
+public:
+ SfxClosePreventer_Impl();
+
+ sal_Bool HasOwnership() { return m_bGotOwnership; }
+
+ void SetPreventClose( sal_Bool bPrevent ) { m_bPreventClose = bPrevent; }
+
+ virtual void SAL_CALL queryClosing( const lang::EventObject& aEvent, sal_Bool bDeliverOwnership )
+ throw ( uno::RuntimeException, util::CloseVetoException );
+
+ virtual void SAL_CALL notifyClosing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ;
+
+ virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ;
+
+} ;
+
+SfxClosePreventer_Impl::SfxClosePreventer_Impl()
+: m_bGotOwnership( sal_False )
+, m_bPreventClose( sal_True )
+{
+}
+
+void SAL_CALL SfxClosePreventer_Impl::queryClosing( const lang::EventObject&, sal_Bool bDeliverOwnership )
+ throw ( uno::RuntimeException, util::CloseVetoException )
+{
+ if ( m_bPreventClose )
+ {
+ if ( !m_bGotOwnership )
+ m_bGotOwnership = bDeliverOwnership;
+
+ throw util::CloseVetoException();
+ }
+}
+
+void SAL_CALL SfxClosePreventer_Impl::notifyClosing( const lang::EventObject& ) throw ( uno::RuntimeException )
+{}
+
+void SAL_CALL SfxClosePreventer_Impl::disposing( const lang::EventObject& ) throw ( uno::RuntimeException )
+{}
+
+//=========================================================================
+class SfxInstanceCloseGuard_Impl
+{
+ SfxClosePreventer_Impl* m_pPreventer;
+ uno::Reference< util::XCloseListener > m_xPreventer;
+ uno::Reference< util::XCloseable > m_xCloseable;
+
+public:
+ SfxInstanceCloseGuard_Impl()
+ : m_pPreventer( NULL )
+ {}
+
+ ~SfxInstanceCloseGuard_Impl();
+
+ sal_Bool Init_Impl( const uno::Reference< util::XCloseable >& xCloseable );
+};
+
+sal_Bool SfxInstanceCloseGuard_Impl::Init_Impl( const uno::Reference< util::XCloseable >& xCloseable )
+{
+ sal_Bool bResult = sal_False;
+
+ // do not allow reinit after the successful init
+ if ( xCloseable.is() && !m_xCloseable.is() )
+ {
+ try
+ {
+ m_pPreventer = new SfxClosePreventer_Impl();
+ m_xPreventer = uno::Reference< util::XCloseListener >( m_pPreventer );
+ xCloseable->addCloseListener( m_xPreventer );
+ m_xCloseable = xCloseable;
+ bResult = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Could not register close listener!\n" );
+ }
+ }
+
+ return bResult;
+}
+
+SfxInstanceCloseGuard_Impl::~SfxInstanceCloseGuard_Impl()
+{
+ if ( m_xCloseable.is() && m_xPreventer.is() )
+ {
+ try
+ {
+ m_xCloseable->removeCloseListener( m_xPreventer );
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ try
+ {
+ if ( m_pPreventer )
+ {
+ m_pPreventer->SetPreventClose( sal_False );
+
+ if ( m_pPreventer->HasOwnership() )
+ m_xCloseable->close( sal_True ); // TODO: do it asynchronously
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+}
+
+//=========================================================================
+
+void SfxObjectShell::PrintExec_Impl(SfxRequest &rReq)
+{
+ SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this);
+ if ( pFrame )
+ {
+ rReq.SetSlot( SID_PRINTDOC );
+ pFrame->GetViewShell()->ExecuteSlot(rReq);
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::PrintState_Impl(SfxItemSet &rSet)
+{
+ bool bPrinting = false;
+ SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this );
+ if ( pFrame )
+ {
+ SfxPrinter *pPrinter = pFrame->GetViewShell()->GetPrinter();
+ bPrinting = pPrinter && pPrinter->IsPrinting();
+ }
+ rSet.Put( SfxBoolItem( SID_PRINTOUT, bPrinting ) );
+}
+
+//--------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::APISaveAs_Impl
+(
+ const String& aFileName,
+ SfxItemSet* aParams
+)
+{
+ BOOL bOk = sal_False;
+
+ {DBG_CHKTHIS(SfxObjectShell, 0);}
+
+ if ( GetMedium() )
+ {
+ String aFilterName;
+ SFX_ITEMSET_ARG( aParams, pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False );
+ if( pFilterNameItem )
+ {
+ aFilterName = pFilterNameItem->GetValue();
+ }
+ else
+ {
+ SFX_ITEMSET_ARG( aParams, pContentTypeItem, SfxStringItem, SID_CONTENTTYPE, sal_False );
+ if ( pContentTypeItem )
+ {
+ const SfxFilter* pFilter = SfxFilterMatcher( String::CreateFromAscii(GetFactory().GetShortName()) ).GetFilter4Mime( pContentTypeItem->GetValue(), SFX_FILTER_EXPORT );
+ if ( pFilter )
+ aFilterName = pFilter->GetName();
+ }
+ }
+
+ // in case no filter defined use default one
+ if( !aFilterName.Len() )
+ {
+ const SfxFilter* pFilt = SfxFilter::GetDefaultFilterFromFactory(GetFactory().GetFactoryName());
+
+ DBG_ASSERT( pFilt, "No default filter!\n" );
+ if( pFilt )
+ aFilterName = pFilt->GetFilterName();
+
+ aParams->Put(SfxStringItem( SID_FILTER_NAME, aFilterName));
+ }
+
+
+ {
+ SfxObjectShellRef xLock( this ); // ???
+
+ // use the title that is provided in the media descriptor
+ SFX_ITEMSET_ARG( aParams, pDocTitleItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
+ if ( pDocTitleItem )
+ getDocProperties()->setTitle( pDocTitleItem->GetValue() );
+
+ bOk = CommonSaveAs_Impl( INetURLObject(aFileName), aFilterName,
+ aParams );
+
+ }
+
+ // prevent picklist-entry
+ GetMedium()->SetUpdatePickList( FALSE );
+ }
+
+ return bOk;
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
+{
+ {DBG_CHKTHIS(SfxObjectShell, 0);}
+
+ USHORT nId = rReq.GetSlot();
+
+ if( SID_SIGNATURE == nId || SID_MACRO_SIGNATURE == nId )
+ {
+ if ( QueryHiddenInformation( WhenSigning, NULL ) == RET_YES )
+ ( SID_SIGNATURE == nId ) ? SignDocumentContent() : SignScriptingContent();
+ return;
+ }
+
+ if ( !GetMedium() && nId != SID_CLOSEDOC )
+ {
+ rReq.Ignore();
+ return;
+ }
+
+ // this guard is created here to have it destruction at the end of the method
+ SfxInstanceCloseGuard_Impl aModelGuard;
+
+ sal_Bool bIsPDFExport = sal_False;
+ switch(nId)
+ {
+ case SID_VERSION:
+ {
+ SfxViewFrame* pFrame = GetFrame();
+ if ( !pFrame )
+ pFrame = SfxViewFrame::GetFirst( this );
+ if ( !pFrame )
+ return;
+
+ if ( pFrame->GetFrame().GetParentFrame() )
+ {
+ pFrame->GetTopViewFrame()->GetObjectShell()->ExecuteSlot( rReq );
+ return;
+ }
+
+ if ( !IsOwnStorageFormat_Impl( *GetMedium() ) )
+ return;
+
+ SfxVersionDialog *pDlg = new SfxVersionDialog( pFrame, IsSaveVersionOnClose() );
+ pDlg->Execute();
+ SetSaveVersionOnClose( pDlg->IsSaveVersionOnClose() );
+ delete pDlg;
+ rReq.Done();
+ return;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_DOCINFO:
+ {
+ SFX_REQUEST_ARG(rReq, pDocInfItem, SfxDocumentInfoItem, SID_DOCINFO, FALSE);
+ if ( pDocInfItem )
+ {
+ // parameter, e.g. from replayed macro
+ pDocInfItem->UpdateDocumentInfo(getDocProperties(), true);
+ SetUseUserData( pDocInfItem->IsUseUserData() );
+ }
+ else
+ {
+ // no argument containing DocInfo; check optional arguments
+ BOOL bReadOnly = IsReadOnly();
+ SFX_REQUEST_ARG(rReq, pROItem, SfxBoolItem, SID_DOC_READONLY, FALSE);
+ if ( pROItem )
+ // override readonly attribute of document
+ // e.g. if a readonly document is saved elsewhere and user asks for editing DocInfo before
+ bReadOnly = pROItem->GetValue();
+
+ // collect data for dialog
+ String aURL, aTitle;
+ if ( HasName() )
+ {
+ aURL = GetMedium()->GetName();
+ aTitle = GetTitle();
+ }
+ else
+ {
+ aURL = DEFINE_CONST_UNICODE( "private:factory/" );
+ aURL += String::CreateFromAscii( GetFactory().GetShortName() );
+
+ aTitle = GetTitle();
+ }
+
+ SfxDocumentInfoItem aDocInfoItem( aURL, getDocProperties(),
+ IsUseUserData() );
+ if ( !GetSlotState( SID_DOCTEMPLATE ) )
+ // templates not supported
+ aDocInfoItem.SetTemplate(FALSE);
+
+ SfxItemSet aSet(GetPool(), SID_DOCINFO, SID_DOCINFO, SID_DOC_READONLY, SID_DOC_READONLY,
+ SID_EXPLORER_PROPS_START, SID_EXPLORER_PROPS_START, SID_BASEURL, SID_BASEURL,
+ 0L );
+ aSet.Put( aDocInfoItem );
+ aSet.Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
+ aSet.Put( SfxStringItem( SID_EXPLORER_PROPS_START, aTitle ) );
+ aSet.Put( SfxStringItem( SID_BASEURL, GetMedium()->GetBaseURL() ) );
+
+ // creating dialog is done via virtual method; application will add its own statistics page
+ SfxDocumentInfoDialog *pDlg = CreateDocumentInfoDialog(0, aSet);
+ if ( RET_OK == pDlg->Execute() )
+ {
+ SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pDocInfoItem, SfxDocumentInfoItem, SID_DOCINFO, FALSE);
+ if ( pDocInfoItem )
+ {
+ // user has done some changes to DocumentInfo
+ pDocInfoItem->UpdateDocumentInfo(getDocProperties());
+ SetUseUserData( ((const SfxDocumentInfoItem *)pDocInfoItem)->IsUseUserData() );
+
+ // add data from dialog for possible recording purposes
+ rReq.AppendItem( SfxDocumentInfoItem( GetTitle(),
+ getDocProperties(), IsUseUserData() ) );
+ }
+
+ rReq.Done();
+ }
+ else
+ // nothing done; no recording
+ rReq.Ignore();
+
+ delete pDlg;
+ }
+
+ return;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ case SID_EXPORTDOCASPDF:
+ case SID_DIRECTEXPORTDOCASPDF:
+ bIsPDFExport = sal_True;
+ case SID_EXPORTDOC:
+ case SID_SAVEASDOC:
+ case SID_SAVEDOC:
+ {
+ // derived class may decide to abort this
+ if( !QuerySlotExecutable( nId ) )
+ {
+ rReq.SetReturnValue( SfxBoolItem( 0, FALSE ) );
+ return;
+ }
+
+ //!! detaillierte Auswertung eines Fehlercodes
+ SfxObjectShellRef xLock( this );
+
+ // the model can not be closed till the end of this method
+ // if somebody tries to close it during this time the model will be closed
+ // at the end of the method
+ aModelGuard.Init_Impl( uno::Reference< util::XCloseable >( GetModel(), uno::UNO_QUERY ) );
+
+ sal_Bool bDialogUsed = sal_False;
+ sal_uInt32 nErrorCode = ERRCODE_NONE;
+
+ // by default versions should be preserved always except in case of an explicit
+ // SaveAs via GUI, so the flag must be set accordingly
+ pImp->bPreserveVersions = (nId == SID_SAVEDOC);
+ try
+ {
+ SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, GetTitle() ); // ???
+
+ if ( nId == SID_SAVEASDOC )
+ {
+ // in case of plugin mode the SaveAs operation means SaveTo
+ SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pViewOnlyItem, SfxBoolItem, SID_VIEWONLY, FALSE );
+ if ( pViewOnlyItem && pViewOnlyItem->GetValue() )
+ rReq.AppendItem( SfxBoolItem( SID_SAVETO, sal_True ) );
+ }
+
+ // TODO/LATER: do the following GUI related actions in standalown method
+ // ========================================================================================================
+ // Introduce a status indicator for GUI operation
+ SFX_REQUEST_ARG( rReq, pStatusIndicatorItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, FALSE );
+ if ( !pStatusIndicatorItem )
+ {
+ // get statusindicator
+ uno::Reference< task::XStatusIndicator > xStatusIndicator;
+ SfxViewFrame *pFrame = GetFrame();
+ if ( pFrame )
+ {
+ uno::Reference< task::XStatusIndicatorFactory > xStatFactory(
+ pFrame->GetFrame().GetFrameInterface(),
+ uno::UNO_QUERY );
+ if( xStatFactory.is() )
+ xStatusIndicator = xStatFactory->createStatusIndicator();
+ }
+
+
+ OSL_ENSURE( xStatusIndicator.is(), "Can not retrieve default status indicator!\n" );
+ if ( xStatusIndicator.is() )
+ {
+ SfxUnoAnyItem aStatIndItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::makeAny( xStatusIndicator ) );
+
+ if ( nId == SID_SAVEDOC )
+ {
+ // in case of saving it is not possible to transport the parameters from here
+ // but it is not clear here whether the saving will be done or saveAs operation
+ GetMedium()->GetItemSet()->Put( aStatIndItem );
+ }
+
+ rReq.AppendItem( aStatIndItem );
+ }
+ }
+ else if ( nId == SID_SAVEDOC )
+ {
+ // in case of saving it is not possible to transport the parameters from here
+ // but it is not clear here whether the saving will be done or saveAs operation
+ GetMedium()->GetItemSet()->Put( *pStatusIndicatorItem );
+ }
+
+ // Introduce an interaction handler for GUI operation
+ SFX_REQUEST_ARG( rReq, pInteractionHandlerItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, FALSE );
+ if ( !pInteractionHandlerItem )
+ {
+ uno::Reference< task::XInteractionHandler > xInteract;
+ uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
+ if( xServiceManager.is() )
+ {
+ xInteract = Reference< XInteractionHandler >(
+ xServiceManager->createInstance( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ),
+ UNO_QUERY );
+ }
+
+ OSL_ENSURE( xInteract.is(), "Can not retrieve default status indicator!\n" );
+ if ( xInteract.is() )
+ {
+ SfxUnoAnyItem aInteractionItem( SID_INTERACTIONHANDLER, uno::makeAny( xInteract ) );
+ if ( nId == SID_SAVEDOC )
+ {
+ // in case of saving it is not possible to transport the parameters from here
+ // but it is not clear here whether the saving will be done or saveAs operation
+ GetMedium()->GetItemSet()->Put( aInteractionItem );
+ }
+
+ rReq.AppendItem( aInteractionItem );
+ }
+ }
+ else if ( nId == SID_SAVEDOC )
+ {
+ // in case of saving it is not possible to transport the parameters from here
+ // but it is not clear here whether the saving will be done or saveAs operation
+ GetMedium()->GetItemSet()->Put( *pInteractionHandlerItem );
+ }
+ // ========================================================================================================
+
+ sal_Bool bPreselectPassword = sal_False;
+ SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pOldEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, FALSE );
+ SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pOldPasswordItem, SfxStringItem, SID_PASSWORD, FALSE );
+ if ( pOldEncryptionDataItem || pOldPasswordItem )
+ bPreselectPassword = sal_True;
+
+ uno::Sequence< beans::PropertyValue > aDispatchArgs;
+ if ( rReq.GetArgs() )
+ TransformItems( nId,
+ *rReq.GetArgs(),
+ aDispatchArgs,
+ NULL );
+
+ const SfxSlot* pSlot = GetModule()->GetSlotPool()->GetSlot( nId );
+ if ( !pSlot )
+ throw uno::Exception();
+
+ uno::Reference< lang::XMultiServiceFactory > xEmptyFactory;
+ SfxStoringHelper aHelper( xEmptyFactory );
+
+ if ( QueryHiddenInformation( bIsPDFExport ? WhenCreatingPDF : WhenSaving, NULL ) == RET_YES )
+ {
+ bDialogUsed = aHelper.GUIStoreModel( GetModel(),
+ ::rtl::OUString::createFromAscii( pSlot->GetUnoName() ),
+ aDispatchArgs,
+ bPreselectPassword,
+ GetSharedFileURL(),
+ GetDocumentSignatureState() );
+ }
+ else
+ {
+ // the user has decided not to store the document
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ ERRCODE_IO_ABORT );
+ }
+
+ // merge aDispatchArgs to the request
+ SfxAllItemSet aResultParams( GetPool() );
+ TransformParameters( nId,
+ aDispatchArgs,
+ aResultParams,
+ NULL );
+ rReq.SetArgs( aResultParams );
+
+ SFX_REQUEST_ARG( rReq, pFilterNameItem, SfxStringItem, SID_FILTER_NAME, FALSE );
+ ::rtl::OUString aFilterName = pFilterNameItem ? ::rtl::OUString( pFilterNameItem->GetValue() )
+ : ::rtl::OUString();
+ const SfxFilter* pFilt = GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
+
+ OSL_ENSURE( nId == SID_SAVEDOC || pFilt, "The filter can not be zero since it was used for storing!\n" );
+ if ( bDialogUsed && pFilt
+ && pFilt->IsOwnFormat()
+ && pFilt->UsesStorage()
+ && pFilt->GetVersion() >= SOFFICE_FILEFORMAT_60 )
+ {
+ SfxViewFrame* pDocViewFrame = SfxViewFrame::GetFirst( this );
+ if ( pDocViewFrame )
+ SfxHelp::OpenHelpAgent( &pDocViewFrame->GetFrame(), HID_DID_SAVE_PACKED_XML );
+ }
+
+ // the StoreAsURL/StoreToURL method have called this method with false
+ // so it has to be restored to true here since it is a call from GUI
+ GetMedium()->SetUpdatePickList( sal_True );
+
+ // TODO: in future it must be done in followind way
+ // if document is opened from GUI it is immediatelly appeares in the picklist
+ // if the document is a new one then it appeares in the picklist immediatelly
+ // after SaveAs operation triggered from GUI
+ }
+ catch( task::ErrorCodeIOException& aErrorEx )
+ {
+ nErrorCode = (sal_uInt32)aErrorEx.ErrCode;
+ }
+ catch( Exception& )
+ {
+ nErrorCode = ERRCODE_IO_GENERAL;
+ }
+
+ // by default versions should be preserved always except in case of an explicit
+ // SaveAs via GUI, so the flag must be reset to guarantee this
+ pImp->bPreserveVersions = sal_True;
+ ULONG lErr=GetErrorCode();
+
+ if ( !lErr && nErrorCode )
+ lErr = nErrorCode;
+
+ if ( lErr && nErrorCode == ERRCODE_NONE )
+ {
+ SFX_REQUEST_ARG( rReq, pWarnItem, SfxBoolItem, SID_FAIL_ON_WARNING, FALSE );
+ if ( pWarnItem && pWarnItem->GetValue() )
+ nErrorCode = lErr;
+ }
+
+ // may be nErrorCode should be shown in future
+ if ( lErr != ERRCODE_IO_ABORT )
+ {
+ SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC,GetTitle());
+ ErrorHandler::HandleError( lErr );
+ }
+
+ if ( nId == SID_EXPORTDOCASPDF )
+ {
+ // This function is used by the SendMail function that needs information if a export
+ // file was written or not. This could be due to cancellation of the export
+ // or due to an error. So IO abort must be handled like an error!
+ nErrorCode = ( lErr != ERRCODE_IO_ABORT ) && ( nErrorCode == ERRCODE_NONE ) ? nErrorCode : lErr;
+ }
+
+ rReq.SetReturnValue( SfxBoolItem(0, nErrorCode == ERRCODE_NONE ) );
+
+ ResetError();
+
+ Invalidate();
+ break;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ case SID_CLOSEDOC:
+ {
+ SfxViewFrame *pFrame = GetFrame();
+ if ( pFrame && pFrame->GetFrame().GetParentFrame() )
+ {
+ // Wenn SID_CLOSEDOC "uber Menue etc. ausgef"uhrt wird, das
+ // aktuelle Dokument aber in einem Frame liegt, soll eigentlich
+ // das FrameSetDocument geclosed werden
+ pFrame->GetTopViewFrame()->GetObjectShell()->ExecuteSlot( rReq );
+ rReq.Done();
+ return;
+ }
+
+ BOOL bInFrameSet = FALSE;
+ USHORT nFrames=0;
+ pFrame = SfxViewFrame::GetFirst( this );
+ while ( pFrame )
+ {
+ if ( pFrame->GetFrame().GetParentFrame() )
+ {
+ // Auf dieses Dokument existiert noch eine Sicht, die
+ // in einem FrameSet liegt; diese darf nat"urlich nicht
+ // geclosed werden
+ bInFrameSet = TRUE;
+ }
+ else
+ nFrames++;
+
+ pFrame = SfxViewFrame::GetNext( *pFrame, this );
+ }
+
+ if ( bInFrameSet )
+ {
+ // Alle Sichten, die nicht in einem FrameSet liegen, closen
+ pFrame = SfxViewFrame::GetFirst( this );
+ while ( pFrame )
+ {
+ if ( !pFrame->GetFrame().GetParentFrame() )
+ pFrame->GetFrame().DoClose();
+ pFrame = SfxViewFrame::GetNext( *pFrame, this );
+ }
+ }
+
+ // Parameter auswerten
+ SFX_REQUEST_ARG(rReq, pSaveItem, SfxBoolItem, SID_CLOSEDOC_SAVE, FALSE);
+ SFX_REQUEST_ARG(rReq, pNameItem, SfxStringItem, SID_CLOSEDOC_FILENAME, FALSE);
+ if ( pSaveItem )
+ {
+ if ( pSaveItem->GetValue() )
+ {
+ if ( !pNameItem )
+ {
+ SbxBase::SetError( SbxERR_WRONG_ARGS );
+ rReq.Ignore();
+ return;
+ }
+ SfxAllItemSet aArgs( GetPool() );
+ SfxStringItem aTmpItem( SID_FILE_NAME, pNameItem->GetValue() );
+ aArgs.Put( aTmpItem, aTmpItem.Which() );
+ SfxRequest aSaveAsReq( SID_SAVEASDOC, SFX_CALLMODE_API, aArgs );
+ ExecFile_Impl( aSaveAsReq );
+ if ( !aSaveAsReq.IsDone() )
+ {
+ rReq.Ignore();
+ return;
+ }
+ }
+ else
+ SetModified(FALSE);
+ }
+
+ // Benutzer bricht ab?
+ if ( !PrepareClose( 2 ) )
+ {
+ rReq.SetReturnValue( SfxBoolItem(0, FALSE) );
+ rReq.Done();
+ return;
+ }
+
+ SetModified( FALSE );
+ ULONG lErr = GetErrorCode();
+ ErrorHandler::HandleError(lErr);
+
+ rReq.SetReturnValue( SfxBoolItem(0, TRUE) );
+ rReq.Done();
+ rReq.ReleaseArgs(); // da der Pool in Close zerst"ort wird
+ DoClose();
+ return;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_DOCTEMPLATE:
+ {
+ // speichern als Dokumentvorlagen
+ SfxDocumentTemplateDlg *pDlg = 0;
+ SfxErrorContext aEc(ERRCTX_SFX_DOCTEMPLATE,GetTitle());
+ SfxDocumentTemplates *pTemplates = new SfxDocumentTemplates;
+
+ if ( !rReq.GetArgs() )
+ {
+ pDlg = new SfxDocumentTemplateDlg(0, pTemplates);
+ if ( RET_OK == pDlg->Execute() && pDlg->GetTemplateName().Len())
+ {
+ rReq.AppendItem(SfxStringItem(
+ SID_TEMPLATE_NAME, pDlg->GetTemplateName()));
+ rReq.AppendItem(SfxStringItem(
+ SID_TEMPLATE_REGIONNAME, pDlg->GetRegionName()));
+ }
+ else
+ {
+ delete pDlg;
+ rReq.Ignore();
+ return;
+ }
+ }
+
+ SFX_REQUEST_ARG(rReq, pRegionItem, SfxStringItem, SID_TEMPLATE_REGIONNAME, FALSE);
+ SFX_REQUEST_ARG(rReq, pNameItem, SfxStringItem, SID_TEMPLATE_NAME, FALSE);
+ SFX_REQUEST_ARG(rReq, pRegionNrItem, SfxUInt16Item, SID_TEMPLATE_REGION, FALSE);
+ if ( (!pRegionItem && !pRegionNrItem ) || !pNameItem )
+ {
+ DBG_ASSERT( rReq.IsAPI(), "non-API call without Arguments" );
+ SbxBase::SetError( SbxERR_WRONG_ARGS );
+ rReq.Ignore();
+ return;
+ }
+
+ ::rtl::OUString aTemplateName = pNameItem->GetValue();
+ ::rtl::OUString aTemplateGroup;
+ if ( pRegionItem )
+ aTemplateGroup = pRegionItem->GetValue();
+ else
+ // pRegionNrItem must not be NULL, it was just checked
+ aTemplateGroup = pTemplates->GetFullRegionName( pRegionNrItem->GetValue() );
+ // check Group and Name
+ delete pTemplates;
+
+ sal_Bool bOk = sal_False;
+ try
+ {
+ uno::Reference< frame::XStorable > xStorable( GetModel(), uno::UNO_QUERY_THROW );
+ ::rtl::OUString aService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.DocumentTemplates" ) );
+ uno::Reference< frame::XDocumentTemplates > xTemplates(
+ comphelper::getProcessServiceFactory()->createInstance( aService ),
+ uno::UNO_QUERY_THROW );
+
+ bOk = xTemplates->storeTemplate( aTemplateGroup, aTemplateName, xStorable );
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ DELETEX(pDlg);
+
+ rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
+ if ( bOk )
+ {
+ // update the Organizer runtime cache from the template component if the cache has already been created
+ // TODO/LATER: get rid of this cache duplication
+ SfxDocumentTemplates aTemplates;
+ aTemplates.ReInitFromComponent();
+ }
+ else
+ {
+ ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
+ return;
+ }
+
+ break;
+ }
+ }
+
+ // Picklisten-Eintrag verhindern
+ if ( rReq.IsAPI() )
+ GetMedium()->SetUpdatePickList( FALSE );
+ else if ( rReq.GetArgs() )
+ {
+ SFX_ITEMSET_GET( *rReq.GetArgs(), pPicklistItem, SfxBoolItem, SID_PICKLIST, FALSE );
+ if ( pPicklistItem )
+ GetMedium()->SetUpdatePickList( pPicklistItem->GetValue() );
+ }
+
+ // Ignore()-Zweige haben schon returnt
+ rReq.Done();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxObjectShell::GetState_Impl(SfxItemSet &rSet)
+{
+ DBG_CHKTHIS(SfxObjectShell, 0);
+ SfxWhichIter aIter( rSet );
+
+ for ( USHORT nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() )
+ {
+ switch ( nWhich )
+ {
+ case SID_DOCTEMPLATE :
+ {
+ if ( !GetFactory().GetTemplateFilter() )
+ rSet.DisableItem( nWhich );
+ break;
+ }
+
+ case SID_VERSION:
+ {
+ SfxObjectShell *pDoc = this;
+ SfxViewFrame* pFrame = GetFrame();
+ if ( !pFrame )
+ pFrame = SfxViewFrame::GetFirst( this );
+ if ( pFrame )
+ {
+ if ( pFrame->GetFrame().GetParentFrame() )
+ {
+ pFrame = pFrame->GetTopViewFrame();
+ pDoc = pFrame->GetObjectShell();
+ }
+ }
+
+ if ( !pFrame || !pDoc->HasName() ||
+ !IsOwnStorageFormat_Impl( *pDoc->GetMedium() ) )
+//REMOVE || pDoc->GetMedium()->GetStorage()->GetVersion() < SOFFICE_FILEFORMAT_50 )
+ rSet.DisableItem( nWhich );
+ break;
+ }
+ case SID_SAVEDOC:
+ {
+ BOOL bMediumRO = IsReadOnlyMedium();
+ if ( !bMediumRO && GetMedium() && IsModified() )
+ rSet.Put(SfxStringItem(
+ nWhich, String(SfxResId(STR_SAVEDOC))));
+ else
+ rSet.DisableItem(nWhich);
+ }
+ break;
+
+ case SID_DOCINFO:
+ if ( 0 != ( pImp->eFlags & SFXOBJECTSHELL_NODOCINFO ) )
+ rSet.DisableItem( nWhich );
+ break;
+
+ case SID_CLOSEDOC:
+ {
+ SfxObjectShell *pDoc = this;
+ SfxViewFrame *pFrame = GetFrame();
+ if ( pFrame && pFrame->GetFrame().GetParentFrame() )
+ {
+ // Wenn SID_CLOSEDOC "uber Menue etc. ausgef"uhrt wird, das
+ // aktuelle Dokument aber in einem Frame liegt, soll eigentlich
+ // das FrameSetDocument geclosed werden
+ pDoc = pFrame->GetTopViewFrame()->GetObjectShell();
+ }
+
+ if ( pDoc->GetFlags() & SFXOBJECTSHELL_DONTCLOSE )
+ rSet.DisableItem(nWhich);
+ else
+ rSet.Put(SfxStringItem(nWhich, String(SfxResId(STR_CLOSEDOC))));
+ break;
+ }
+
+ case SID_SAVEASDOC:
+ {
+ if( ( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) != SFX_LOADED_MAINDOCUMENT )
+ {
+ rSet.DisableItem( nWhich );
+ break;
+ }
+/*
+ const SfxFilter* pCombinedFilters = NULL;
+ SfxFilterContainer* pFilterContainer = GetFactory().GetFilterContainer();
+
+ if ( pFilterContainer )
+ {
+ SfxFilterFlags nMust = SFX_FILTER_IMPORT | SFX_FILTER_EXPORT;
+ SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED | SFX_FILTER_INTERNAL;
+
+ pCombinedFilters = pFilterContainer->GetAnyFilter( nMust, nDont );
+ }
+*/
+ if ( /*!pCombinedFilters ||*/ !GetMedium() )
+ rSet.DisableItem( nWhich );
+ else
+ rSet.Put( SfxStringItem( nWhich, String( SfxResId( STR_SAVEASDOC ) ) ) );
+ break;
+ }
+
+ case SID_EXPORTDOCASPDF:
+ case SID_DIRECTEXPORTDOCASPDF:
+ {
+ /*
+
+ search for filter cant work correctly ...
+ Because it's not clear, which export filter for which office module
+ must be searched. On the other side it can be very expensive doing so.
+ The best solution would be: on installation time we should know if pdf feature
+ was installed or not!!! (e.g. by writing a bool inside cfg)
+
+ SfxFilterContainer* pFilterContainer = GetFactory().GetFilterContainer();
+ if ( pFilterContainer )
+ {
+ String aPDFExtension = String::CreateFromAscii( "pdf" );
+ const SfxFilter* pFilter = pFilterContainer->GetFilter4Extension( aPDFExtension, SFX_FILTER_EXPORT );
+ if ( pFilter != NULL )
+ break;
+ }
+
+ rSet.DisableItem( nWhich );
+ */
+ break;
+ }
+
+ case SID_DOC_MODIFIED:
+ {
+ rSet.Put( SfxStringItem( SID_DOC_MODIFIED, IsModified() ? '*' : ' ' ) );
+ break;
+ }
+
+ case SID_MODIFIED:
+ {
+ rSet.Put( SfxBoolItem( SID_MODIFIED, IsModified() ) );
+ break;
+ }
+
+ case SID_DOCINFO_TITLE:
+ {
+ rSet.Put( SfxStringItem(
+ SID_DOCINFO_TITLE, getDocProperties()->getTitle() ) );
+ break;
+ }
+ case SID_FILE_NAME:
+ {
+ if( GetMedium() && HasName() )
+ rSet.Put( SfxStringItem(
+ SID_FILE_NAME, GetMedium()->GetName() ) );
+ break;
+ }
+ case SID_SIGNATURE:
+ {
+ rSet.Put( SfxUInt16Item( SID_SIGNATURE, GetDocumentSignatureState() ) );
+ break;
+ }
+ case SID_MACRO_SIGNATURE:
+ {
+ // the slot makes sense only if there is a macro in the document
+ if ( pImp->documentStorageHasMacros() || pImp->aMacroMode.hasMacroLibrary() )
+ rSet.Put( SfxUInt16Item( SID_MACRO_SIGNATURE, GetScriptingSignatureState() ) );
+ else
+ rSet.DisableItem( nWhich );
+ break;
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::ExecProps_Impl(SfxRequest &rReq)
+{
+ switch ( rReq.GetSlot() )
+ {
+ case SID_MODIFIED:
+ {
+ SetModified( ( (SfxBoolItem&) rReq.GetArgs()->Get(SID_MODIFIED)).GetValue() );
+ rReq.Done();
+ break;
+ }
+
+ case SID_DOCTITLE:
+ SetTitle( ( (SfxStringItem&) rReq.GetArgs()->Get(SID_DOCTITLE)).GetValue() );
+ rReq.Done();
+ break;
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_PLAYMACRO:
+ {
+ SFX_APP()->PlayMacro_Impl( rReq, GetBasic() );
+ break;
+ }
+
+ case SID_DOCINFO_AUTHOR :
+ {
+ ::rtl::OUString aStr = ( (SfxStringItem&)rReq.GetArgs()->Get(rReq.GetSlot())).GetValue();
+ getDocProperties()->setAuthor( aStr );
+ break;
+ }
+
+ case SID_DOCINFO_COMMENTS :
+ {
+ ::rtl::OUString aStr = ( (SfxStringItem&)rReq.GetArgs()->Get(rReq.GetSlot())).GetValue();
+ getDocProperties()->setDescription( aStr );
+ break;
+ }
+
+ case SID_DOCINFO_KEYWORDS :
+ {
+ ::rtl::OUString aStr = ( (SfxStringItem&)rReq.GetArgs()->Get(rReq.GetSlot())).GetValue();
+ getDocProperties()->setKeywords(
+ ::comphelper::string::convertCommaSeparated(aStr) );
+ break;
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::StateProps_Impl(SfxItemSet &rSet)
+{
+ SfxWhichIter aIter(rSet);
+ for ( USHORT nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
+ {
+ switch ( nSID )
+ {
+ case SID_DOCINFO_AUTHOR :
+ {
+ rSet.Put( SfxStringItem( nSID,
+ getDocProperties()->getAuthor() ) );
+ break;
+ }
+
+ case SID_DOCINFO_COMMENTS :
+ {
+ rSet.Put( SfxStringItem( nSID,
+ getDocProperties()->getDescription()) );
+ break;
+ }
+
+ case SID_DOCINFO_KEYWORDS :
+ {
+ rSet.Put( SfxStringItem( nSID, ::comphelper::string::
+ convertCommaSeparated(getDocProperties()->getKeywords())) );
+ break;
+ }
+
+ case SID_DOCPATH:
+ {
+ DBG_ERROR( "Not supported anymore!" );
+ break;
+ }
+
+ case SID_DOCFULLNAME:
+ {
+ rSet.Put( SfxStringItem( SID_DOCFULLNAME, GetTitle(SFX_TITLE_FULLNAME) ) );
+ break;
+ }
+
+ case SID_DOCTITLE:
+ {
+ rSet.Put( SfxStringItem( SID_DOCTITLE, GetTitle() ) );
+ break;
+ }
+
+ case SID_DOC_READONLY:
+ {
+ rSet.Put( SfxBoolItem( SID_DOC_READONLY, IsReadOnly() ) );
+ break;
+ }
+
+ case SID_DOC_SAVED:
+ {
+ rSet.Put( SfxBoolItem( SID_DOC_SAVED, !IsModified() ) );
+ break;
+ }
+
+ case SID_CLOSING:
+ {
+ rSet.Put( SfxBoolItem( SID_CLOSING, false ) );
+ break;
+ }
+
+ case SID_DOC_LOADING:
+ rSet.Put( SfxBoolItem( nSID, SFX_LOADED_MAINDOCUMENT !=
+ ( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) ) );
+ break;
+
+ case SID_IMG_LOADING:
+ rSet.Put( SfxBoolItem( nSID, SFX_LOADED_IMAGES !=
+ ( pImp->nLoadedFlags & SFX_LOADED_IMAGES ) ) );
+ break;
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::ExecView_Impl(SfxRequest &rReq)
+{
+ switch ( rReq.GetSlot() )
+ {
+ case SID_ACTIVATE:
+ {
+ SfxViewFrame *pFrame = SfxViewFrame::GetFirst( this, TRUE );
+ if ( pFrame )
+ pFrame->GetFrame().Appear();
+ rReq.SetReturnValue( SfxObjectItem( 0, pFrame ) );
+ rReq.Done();
+ break;
+ }
+ case SID_NEWWINDOWFOREDIT:
+ {
+ SfxViewFrame* pFrame = SfxViewFrame::Current();
+ if( pFrame->GetObjectShell() == this &&
+ ( pFrame->GetFrameType() & SFXFRAME_HASTITLE ) )
+ pFrame->ExecuteSlot( rReq );
+ else
+ {
+ String aFileName( GetObjectShell()->GetMedium()->GetName() );
+ if ( aFileName.Len() )
+ {
+ SfxStringItem aName( SID_FILE_NAME, aFileName );
+ SfxBoolItem aCreateView( SID_OPEN_NEW_VIEW, TRUE );
+ SFX_APP()->GetAppDispatcher_Impl()->Execute(
+ SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aName,
+ &aCreateView, 0L);
+ }
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::StateView_Impl(SfxItemSet& /*rSet*/)
+{
+}
+
+sal_uInt16 SfxObjectShell::ImplCheckSignaturesInformation( const uno::Sequence< security::DocumentSignatureInformation >& aInfos )
+{
+ sal_Bool bCertValid = sal_True;
+ sal_uInt16 nResult = SIGNATURESTATE_NOSIGNATURES;
+ int nInfos = aInfos.getLength();
+ bool bCompleteSignature = true;
+ if( nInfos )
+ {
+ nResult = SIGNATURESTATE_SIGNATURES_OK;
+ for ( int n = 0; n < nInfos; n++ )
+ {
+ if ( bCertValid )
+ {
+ sal_Int32 nCertStat = aInfos[n].CertificateStatus;
+ bCertValid = nCertStat == security::CertificateValidity::VALID ? sal_True : sal_False;
+ }
+
+ if ( !aInfos[n].SignatureIsValid )
+ {
+ nResult = SIGNATURESTATE_SIGNATURES_BROKEN;
+ break; // we know enough
+ }
+ bCompleteSignature &= !aInfos[n].PartialDocumentSignature;
+ }
+ }
+
+ if ( nResult == SIGNATURESTATE_SIGNATURES_OK && !bCertValid )
+ nResult = SIGNATURESTATE_SIGNATURES_NOTVALIDATED;
+ else if ( nResult == SIGNATURESTATE_SIGNATURES_OK && bCertValid && !bCompleteSignature)
+ nResult = SIGNATURESTATE_SIGNATURES_PARTIAL_OK;
+
+ // this code must not check whether the document is modified
+ // it should only check the provided info
+
+ return nResult;
+}
+
+uno::Sequence< security::DocumentSignatureInformation > SfxObjectShell::ImplAnalyzeSignature( sal_Bool bScriptingContent, const uno::Reference< security::XDocumentDigitalSignatures >& xSigner )
+{
+ uno::Sequence< security::DocumentSignatureInformation > aResult;
+ uno::Reference< security::XDocumentDigitalSignatures > xLocSigner = xSigner;
+
+ if ( GetMedium() && GetMedium()->GetName().Len() && IsOwnStorageFormat_Impl( *GetMedium()) && GetMedium()->GetStorage().is() )
+ {
+ try
+ {
+ if ( !xLocSigner.is() )
+ {
+ uno::Sequence< uno::Any > aArgs( 1 );
+ aArgs[0] <<= ::rtl::OUString();
+ try
+ {
+ uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
+ aArgs[0] = xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) );
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ xLocSigner.set( comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), aArgs ), uno::UNO_QUERY_THROW );
+
+ }
+
+ if ( bScriptingContent )
+ aResult = xLocSigner->verifyScriptingContentSignatures( GetMedium()->GetZipStorageToSign_Impl(),
+ uno::Reference< io::XInputStream >() );
+ else
+ aResult = xLocSigner->verifyDocumentContentSignatures( GetMedium()->GetZipStorageToSign_Impl(),
+ uno::Reference< io::XInputStream >() );
+ }
+ catch( com::sun::star::uno::Exception& )
+ {
+ }
+ }
+
+ return aResult;
+}
+
+sal_uInt16 SfxObjectShell::ImplGetSignatureState( sal_Bool bScriptingContent )
+{
+ sal_Int16* pState = bScriptingContent ? &pImp->nScriptingSignatureState : &pImp->nDocumentSignatureState;
+
+ if ( *pState == SIGNATURESTATE_UNKNOWN )
+ {
+ *pState = SIGNATURESTATE_NOSIGNATURES;
+
+ uno::Sequence< security::DocumentSignatureInformation > aInfos = ImplAnalyzeSignature( bScriptingContent );
+ *pState = ImplCheckSignaturesInformation( aInfos );
+ }
+
+ if ( *pState == SIGNATURESTATE_SIGNATURES_OK || *pState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
+ || *pState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK)
+ {
+ if ( IsModified() )
+ *pState = SIGNATURESTATE_SIGNATURES_INVALID;
+ }
+
+ return (sal_uInt16)*pState;
+}
+
+void SfxObjectShell::ImplSign( sal_Bool bScriptingContent )
+{
+ // Check if it is stored in OASIS format...
+ if ( GetMedium()
+ && GetMedium()->GetFilter()
+ && GetMedium()->GetName().Len()
+ && ( !GetMedium()->GetFilter()->IsOwnFormat()
+ || !GetMedium()->HasStorage_Impl()
+ )
+ )
+ {
+ // Only OASIS and OOo6.x formats will be handled further
+ InfoBox( NULL, SfxResId( RID_XMLSEC_INFO_WRONGDOCFORMAT ) ).Execute();
+ return;
+ }
+
+ // check whether the document is signed
+ ImplGetSignatureState( sal_False ); // document signature
+ ImplGetSignatureState( sal_True ); // script signature
+ sal_Bool bHasSign = ( pImp->nScriptingSignatureState != SIGNATURESTATE_NOSIGNATURES || pImp->nDocumentSignatureState != SIGNATURESTATE_NOSIGNATURES );
+
+ // the target ODF version on saving
+ SvtSaveOptions aSaveOpt;
+ SvtSaveOptions::ODFDefaultVersion nVersion = aSaveOpt.GetODFDefaultVersion();
+
+ // the document is not new and is not modified
+ ::rtl::OUString aODFVersion;
+ try
+ {
+ // check the version of the document
+ uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aODFVersion;
+ }
+ catch( uno::Exception& )
+ {}
+
+ bool bNoSig = false;
+
+ if ( IsModified() || !GetMedium() || !GetMedium()->GetName().Len()
+ || (!aODFVersion.equals( ODFVER_012_TEXT ) && !bHasSign) )
+ {
+ // the document might need saving ( new, modified or in ODF1.1 format without signature )
+
+ if ( nVersion >= SvtSaveOptions::ODFVER_012 )
+ {
+
+ if ( (bHasSign && QueryBox( NULL, SfxResId( MSG_XMLSEC_QUERY_SAVESIGNEDBEFORESIGN ) ).Execute() == RET_YES)
+ || (!bHasSign && QueryBox( NULL, SfxResId( RID_XMLSEC_QUERY_SAVEBEFORESIGN ) ).Execute() == RET_YES) )
+ {
+ USHORT nId = SID_SAVEDOC;
+ if ( !GetMedium() || !GetMedium()->GetName().Len() )
+ nId = SID_SAVEASDOC;
+ SfxRequest aSaveRequest( nId, 0, GetPool() );
+ //ToDo: Review. We needed to call SetModified, otherwise the document would not be saved.
+ SetModified(sal_True);
+ ExecFile_Impl( aSaveRequest );
+
+ // Check if it is stored in OASIS format...
+ if ( GetMedium() && GetMedium()->GetFilter()
+ && ( !GetMedium()->GetFilter()->IsOwnFormat() || !GetMedium()->HasStorage_Impl()
+ || SotStorage::GetVersion( GetMedium()->GetStorage() ) <= SOFFICE_FILEFORMAT_60 ) )
+ {
+ // Only OASIS format will be handled further
+ InfoBox( NULL, SfxResId( RID_XMLSEC_INFO_WRONGDOCFORMAT ) ).Execute();
+ return;
+ }
+ }
+ else
+ {
+ //When the document is modified then we must not show the digital signatures dialog
+ //If we have come here then the user denied to save.
+ if (!bHasSign)
+ bNoSig = true;
+ }
+ }
+ else
+ {
+ ErrorBox( NULL, WB_OK, SfxResId( STR_XMLSEC_ODF12_EXPECTED ) ).Execute();
+ return;
+ }
+
+ if ( IsModified() || !GetMedium() || !GetMedium()->GetName().Len() )
+ return;
+ }
+
+ // the document is not modified currently, so it can not become modified after signing
+ sal_Bool bAllowModifiedBack = sal_False;
+ if ( IsEnableSetModified() )
+ {
+ EnableSetModified( sal_False );
+ bAllowModifiedBack = sal_True;
+ }
+
+ // we have to store to the original document, the original medium should be closed for this time
+ if ( !bNoSig
+ && ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
+ {
+ GetMedium()->CloseAndRelease();
+
+ // We sign only ODF1.2, that means that if this point has been reached,
+ // the ODF1.2 signing process should be used.
+ // This code still might be called to show the signature of ODF1.1 document.
+ sal_Bool bSigned = GetMedium()->SignContents_Impl(
+ bScriptingContent,
+ aODFVersion,
+ pImp->nDocumentSignatureState == SIGNATURESTATE_SIGNATURES_OK
+ || pImp->nDocumentSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
+ || pImp->nDocumentSignatureState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK);
+
+ DoSaveCompleted( GetMedium() );
+
+ if ( bSigned )
+ {
+ if ( bScriptingContent )
+ {
+ pImp->nScriptingSignatureState = SIGNATURESTATE_UNKNOWN;// Re-Check
+
+ // adding of scripting signature removes existing document signature
+ pImp->nDocumentSignatureState = SIGNATURESTATE_UNKNOWN;// Re-Check
+ }
+ else
+ pImp->nDocumentSignatureState = SIGNATURESTATE_UNKNOWN;// Re-Check
+
+ pImp->bSignatureErrorIsShown = sal_False;
+
+ Invalidate( SID_SIGNATURE );
+ Invalidate( SID_MACRO_SIGNATURE );
+ Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
+ }
+ }
+
+ if ( bAllowModifiedBack )
+ EnableSetModified( sal_True );
+}
+
+sal_uInt16 SfxObjectShell::GetDocumentSignatureState()
+{
+ return ImplGetSignatureState( FALSE );
+}
+
+void SfxObjectShell::SignDocumentContent()
+{
+ ImplSign( FALSE );
+}
+
+sal_uInt16 SfxObjectShell::GetScriptingSignatureState()
+{
+ return ImplGetSignatureState( TRUE );
+}
+
+void SfxObjectShell::SignScriptingContent()
+{
+ ImplSign( TRUE );
+}
+
+// static
+const uno::Sequence<sal_Int8>& SfxObjectShell::getUnoTunnelId()
+{
+ static uno::Sequence<sal_Int8> * pSeq = 0;
+ if( !pSeq )
+ {
+ osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
+ if( !pSeq )
+ {
+ static uno::Sequence< sal_Int8 > aSeq( 16 );
+ rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
+ pSeq = &aSeq;
+ }
+ }
+ return *pSeq;
+}
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
new file mode 100644
index 000000000000..0575660877a3
--- /dev/null
+++ b/sfx2/source/doc/objstor.cxx
@@ -0,0 +1,3757 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <tools/zcodec.hxx>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/document/XImporter.hpp>
+#include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/document/FilterOptionsRequest.hpp>
+#include <com/sun/star/document/XInteractionFilterOptions.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/task/XInteractionAskLater.hpp>
+#include <com/sun/star/task/FutureDocumentVersionProductUpdateRequest.hpp>
+#include <com/sun/star/task/InteractionClassification.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
+#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/container/XSet.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/Aspects.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/embed/XEmbedPersist.hpp>
+#include <com/sun/star/embed/XLinkageSupport.hpp>
+#include <com/sun/star/embed/EntryInitModes.hpp>
+#include <com/sun/star/embed/XOptimizedStorage.hpp>
+#include <com/sun/star/io/XTruncate.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+
+#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/configurationhelper.hxx>
+#include <comphelper/interaction.hxx>
+#include <svtools/sfxecode.hxx>
+#include <unotools/securityoptions.hxx>
+#include <cppuhelper/weak.hxx>
+#include <comphelper/processfactory.hxx>
+#include <tools/cachestr.hxx>
+#include <unotools/streamwrap.hxx>
+
+#include <unotools/saveopt.hxx>
+#include <unotools/useroptions.hxx>
+#include <unotools/pathoptions.hxx>
+#include <tools/urlobj.hxx>
+#include <tools/diagnose_ex.h>
+#include <unotools/localfilehelper.hxx>
+#include <unotools/ucbhelper.hxx>
+#include <unotools/tempfile.hxx>
+#include <unotools/docinfohelper.hxx>
+#include <ucbhelper/content.hxx>
+#include <sot/storinfo.hxx>
+#include <sot/exchange.hxx>
+#include <sot/formats.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <comphelper/seqstream.hxx>
+#include <comphelper/documentconstants.hxx>
+#include <comphelper/string.hxx>
+#include <vcl/bitmapex.hxx>
+#include <svtools/embedhlp.hxx>
+#include <rtl/logfile.hxx>
+#include <basic/modsizeexceeded.hxx>
+#include <osl/file.hxx>
+
+#include <sfx2/signaturestate.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/childwin.hxx>
+#include <sfx2/request.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/docfile.hxx>
+#include "fltfnc.hxx"
+#include <sfx2/docfilt.hxx>
+#include <sfx2/docfac.hxx>
+#include "objshimp.hxx"
+#include "sfxtypes.hxx"
+#include "doc.hrc"
+#include <sfx2/sfxsids.hrc>
+#include <sfx2/module.hxx>
+#include <sfx2/dispatch.hxx>
+#include "openflag.hxx"
+#include "helper.hxx"
+#include <sfx2/filedlghelper.hxx>
+#include <sfx2/event.hxx>
+#include "fltoptint.hxx"
+#include <sfx2/viewfrm.hxx>
+#include "graphhelp.hxx"
+#include "appbaslib.hxx"
+#include "appdata.hxx"
+
+#ifdef OS2
+#include <osl/file.hxx>
+#include <stdio.h>
+#include <sys/ea.h>
+#endif
+
+#include "../appl/app.hrc"
+
+extern sal_uInt32 CheckPasswd_Impl( SfxObjectShell*, SfxItemPool&, SfxMedium* );
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::ui::dialogs;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::task;
+using namespace ::com::sun::star::document;
+using namespace ::rtl;
+using namespace ::cppu;
+
+namespace css = ::com::sun::star;
+
+//=========================================================================
+void impl_addToModelCollection(const css::uno::Reference< css::frame::XModel >& xModel)
+{
+ if (!xModel.is())
+ return;
+
+ css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
+ css::uno::Reference< css::container::XSet > xModelCollection(
+ xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.GlobalEventBroadcaster")),
+ css::uno::UNO_QUERY);
+ if (xModelCollection.is())
+ {
+ try
+ {
+ xModelCollection->insert(css::uno::makeAny(xModel));
+ }
+ catch ( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "The document seems to be in the collection already!\n" );
+ }
+ }
+}
+
+//=========================================================================
+
+sal_Bool SfxObjectShell::Save()
+{
+ return SaveChildren();
+}
+
+//--------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::SaveAs( SfxMedium& rMedium )
+{
+ return SaveAsChildren( rMedium );
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::QuerySlotExecutable( USHORT /*nSlotId*/ )
+{
+ return sal_True;
+}
+
+//-------------------------------------------------------------------------
+
+bool GetEncryptionData_Impl( const SfxItemSet* pSet, uno::Sequence< beans::NamedValue >& o_rEncryptionData )
+{
+ bool bResult = false;
+ if ( pSet )
+ {
+ SFX_ITEMSET_ARG( pSet, pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, sal_False);
+ if ( pEncryptionDataItem )
+ {
+ pEncryptionDataItem->GetValue() >>= o_rEncryptionData;
+ bResult = true;
+ }
+ else
+ {
+ SFX_ITEMSET_ARG( pSet, pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False);
+ if ( pPasswordItem )
+ {
+ ::rtl::OUString aPassword = pPasswordItem->GetValue();
+ o_rEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPassword );
+ bResult = true;
+ }
+ }
+ }
+
+ return bResult;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SfxObjectShell::PutURLContentsToVersionStream_Impl(
+ ::rtl::OUString aURL,
+ const uno::Reference< embed::XStorage >& xDocStorage,
+ ::rtl::OUString aStreamName )
+{
+ sal_Bool bResult = sal_False;
+ try
+ {
+ uno::Reference< embed::XStorage > xVersion = xDocStorage->openStorageElement(
+ ::rtl::OUString::createFromAscii( "Versions" ),
+ embed::ElementModes::READWRITE );
+
+ DBG_ASSERT( xVersion.is(),
+ "The method must throw an exception if the storage can not be opened!\n" );
+ if ( !xVersion.is() )
+ throw uno::RuntimeException();
+
+ uno::Reference< io::XStream > xVerStream = xVersion->openStreamElement(
+ aStreamName,
+ embed::ElementModes::READWRITE );
+ DBG_ASSERT( xVerStream.is(), "The method must throw an exception if the storage can not be opened!\n" );
+ if ( !xVerStream.is() )
+ throw uno::RuntimeException();
+
+ uno::Reference< io::XOutputStream > xOutStream = xVerStream->getOutputStream();
+ uno::Reference< io::XTruncate > xTrunc( xOutStream, uno::UNO_QUERY );
+
+ DBG_ASSERT( xTrunc.is(), "The output stream must exist and implement XTruncate interface!\n" );
+ if ( !xTrunc.is() )
+ throw RuntimeException();
+
+ uno::Reference< io::XInputStream > xTmpInStream =
+ ::comphelper::OStorageHelper::GetInputStreamFromURL( aURL );
+ DBG_ASSERT( xTmpInStream.is(), "The method must create the stream or throw an exception!\n" );
+ if ( !xTmpInStream.is() )
+ throw uno::RuntimeException();
+
+ xTrunc->truncate();
+ ::comphelper::OStorageHelper::CopyInputToOutput( xTmpInStream, xOutStream );
+ xOutStream->closeOutput();
+
+ uno::Reference< embed::XTransactedObject > xTransact( xVersion, uno::UNO_QUERY );
+ DBG_ASSERT( xTransact.is(), "The storage must implement XTransacted interface!\n" );
+ if ( xTransact.is() )
+ xTransact->commit();
+
+ bResult = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ // TODO/LATER: handle the error depending on exception
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+
+ return bResult;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString SfxObjectShell::CreateTempCopyOfStorage_Impl( const uno::Reference< embed::XStorage >& xStorage )
+{
+ ::rtl::OUString aTempURL = ::utl::TempFile().GetURL();
+
+ DBG_ASSERT( aTempURL.getLength(), "Can't create a temporary file!\n" );
+ if ( aTempURL.getLength() )
+ {
+ try
+ {
+ uno::Reference< embed::XStorage > xTempStorage =
+ ::comphelper::OStorageHelper::GetStorageFromURL( aTempURL, embed::ElementModes::READWRITE );
+
+ // the password will be transfered from the xStorage to xTempStorage by storage implemetation
+ xStorage->copyToStorage( xTempStorage );
+
+ // the temporary storage was commited by the previous method and it will die by refcount
+ }
+ catch ( uno::Exception& )
+ {
+ DBG_ERROR( "Creation of a storage copy is failed!" );
+ ::utl::UCBContentHelper::Kill( aTempURL );
+
+ aTempURL = ::rtl::OUString();
+
+ // TODO/LATER: may need error code setting based on exception
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ }
+
+ return aTempURL;
+}
+
+//-------------------------------------------------------------------------
+SvGlobalName SfxObjectShell::GetClassName() const
+{
+ return GetFactory().GetClassId();
+}
+
+//-------------------------------------------------------------------------
+void SfxObjectShell::SetupStorage( const uno::Reference< embed::XStorage >& xStorage,
+ sal_Int32 nVersion,
+ sal_Bool bTemplate ) const
+{
+ uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY );
+
+ if ( xProps.is() )
+ {
+ SvGlobalName aName;
+ String aFullTypeName, aShortTypeName, aAppName;
+ sal_uInt32 nClipFormat=0;
+
+ FillClass( &aName, &nClipFormat, &aAppName, &aFullTypeName, &aShortTypeName, nVersion, bTemplate );
+ if ( nClipFormat )
+ {
+ // basic doesn't have a ClipFormat
+ // without MediaType the storage is not really usable, but currently the BasicIDE still
+ // is an SfxObjectShell and so we can't take this as an error
+ datatransfer::DataFlavor aDataFlavor;
+ SotExchange::GetFormatDataFlavor( nClipFormat, aDataFlavor );
+ if ( aDataFlavor.MimeType.getLength() )
+ {
+ try
+ {
+ xProps->setPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ), uno::makeAny( aDataFlavor.MimeType ) );
+ }
+ catch( uno::Exception& )
+ {
+ const_cast<SfxObjectShell*>( this )->SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+
+ ::rtl::OUString aVersion;
+ SvtSaveOptions aSaveOpt;
+ SvtSaveOptions::ODFDefaultVersion nDefVersion = aSaveOpt.GetODFDefaultVersion();
+
+ // older versions can not have this property set, it exists only starting from ODF1.2
+ if ( nDefVersion >= SvtSaveOptions::ODFVER_012 )
+ aVersion = ODFVER_012_TEXT;
+
+ if ( aVersion.getLength() )
+ {
+ try
+ {
+ xProps->setPropertyValue( ::rtl::OUString::createFromAscii( "Version" ), uno::makeAny( aVersion ) );
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ }
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+void SfxObjectShell::PrepareSecondTryLoad_Impl()
+{
+ // only for internal use
+ pImp->m_xDocStorage = uno::Reference< embed::XStorage >();
+ pImp->m_bIsInit = sal_False;
+ ResetError();
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SfxObjectShell::GeneralInit_Impl( const uno::Reference< embed::XStorage >& xStorage,
+ sal_Bool bTypeMustBeSetAlready )
+{
+ if ( pImp->m_bIsInit )
+ return sal_False;
+
+ pImp->m_bIsInit = sal_True;
+ if ( xStorage.is() )
+ {
+ // no notification is required the storage is set the first time
+ pImp->m_xDocStorage = xStorage;
+
+ try {
+ uno::Reference < beans::XPropertySet > xPropSet( xStorage, uno::UNO_QUERY_THROW );
+ Any a = xPropSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) );
+ ::rtl::OUString aMediaType;
+ if ( !(a>>=aMediaType) || !aMediaType.getLength() )
+ {
+ if ( bTypeMustBeSetAlready )
+ {
+ SetError( ERRCODE_IO_BROKENPACKAGE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ return sal_False;
+ }
+
+ SetupStorage( xStorage, SOFFICE_FILEFORMAT_CURRENT, sal_False );
+ }
+ }
+ catch ( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Can't check storage's mediatype!\n" );
+ }
+ }
+ else
+ pImp->m_bCreateTempStor = sal_True;
+
+ return sal_True;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SfxObjectShell::InitNew( const uno::Reference< embed::XStorage >& xStorage )
+{
+ return GeneralInit_Impl( xStorage, sal_False );
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SfxObjectShell::Load( SfxMedium& rMedium )
+{
+ return GeneralInit_Impl( rMedium.GetStorage(), sal_True );
+}
+
+sal_Bool SfxObjectShell::DoInitNew( SfxMedium* pMed )
+/* [Beschreibung]
+
+ Diese von SvPersist geerbte virtuelle Methode wird gerufen, um
+ die SfxObjectShell-Instanz aus einem Storage (pStor != 0) bzw.
+ (pStor == 0) ganz neu zu initialisieren.
+
+ Wie alle Do...-Methoden liegt hier eine Steuerung vor, die eigentliche
+ Implementierung erfolgt, indem die ebenfalls virtuellen Methode
+ InitNew(SvStorate*) von der SfxObjectShell-Subclass implementiert wird.
+
+ F"ur pStor == 0 wird ein die SfxObjectShell-Instanz mit einem leeren
+ SfxMedium verbunden, sonst mit einem SfxMedium, welches auf den
+ als Parameter "ubergeben SvStorage verweist.
+
+ Erst nach InitNew() oder Load() ist das Objekt korrekt initialisiert.
+
+ [R"uckgabewert]
+ sal_True Das Objekt wurde initialisiert.
+ sal_False Das Objekt konnte nicht initialisiert werden
+*/
+
+{
+ ModifyBlocker_Impl aBlock( this );
+ pMedium = pMed;
+ if ( !pMedium )
+ {
+ bIsTmp = sal_True;
+ pMedium = new SfxMedium;
+ }
+
+ pMedium->CanDisposeStorage_Impl( sal_True );
+
+ if ( InitNew( pMed ? pMed->GetStorage() : uno::Reference < embed::XStorage >() ) )
+ {
+ // empty documents always get their macros from the user, so there is no reason to restrict access
+ pImp->aMacroMode.allowMacroExecution();
+ if ( SFX_CREATE_MODE_EMBEDDED == eCreateMode )
+ SetTitle( String( SfxResId( STR_NONAME ) ));
+
+ uno::Reference< frame::XModel > xModel ( GetModel(), uno::UNO_QUERY );
+ if ( xModel.is() )
+ {
+ SfxItemSet *pSet = GetMedium()->GetItemSet();
+ uno::Sequence< beans::PropertyValue > aArgs;
+ TransformItems( SID_OPENDOC, *pSet, aArgs );
+ sal_Int32 nLength = aArgs.getLength();
+ aArgs.realloc( nLength + 1 );
+ aArgs[nLength].Name = DEFINE_CONST_UNICODE("Title");
+ aArgs[nLength].Value <<= ::rtl::OUString( GetTitle( SFX_TITLE_DETECT ) );
+ xModel->attachResource( ::rtl::OUString(), aArgs );
+ impl_addToModelCollection(xModel);
+ }
+
+ SetInitialized_Impl( true );
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::ImportFromGeneratedStream_Impl(
+ const uno::Reference< io::XStream >& xStream,
+ const uno::Sequence< beans::PropertyValue >& aMediaDescr )
+{
+ if ( !xStream.is() )
+ return sal_False;
+
+ if ( pMedium && pMedium->HasStorage_Impl() )
+ pMedium->CloseStorage();
+
+ sal_Bool bResult = sal_False;
+
+ try
+ {
+ uno::Reference< embed::XStorage > xStorage =
+ ::comphelper::OStorageHelper::GetStorageFromStream( xStream, embed::ElementModes::READWRITE );
+
+ if ( !xStorage.is() )
+ throw uno::RuntimeException();
+
+ if ( !pMedium )
+ pMedium = new SfxMedium( xStorage, String() );
+ else
+ pMedium->SetStorage_Impl( xStorage );
+
+ SfxAllItemSet aSet( SFX_APP()->GetPool() );
+ TransformParameters( SID_OPENDOC, aMediaDescr, aSet );
+ pMedium->GetItemSet()->Put( aSet );
+ pMedium->CanDisposeStorage_Impl( sal_False );
+
+ // allow the subfilter to reinit the model
+ if ( pImp->m_bIsInit )
+ pImp->m_bIsInit = sal_False;
+
+ if ( LoadOwnFormat( *pMedium ) )
+ {
+ bHasName = sal_True;
+ if ( !IsReadOnly() && IsLoadReadonly() )
+ SetReadOnlyUI();
+
+ bResult = sal_True;
+ OSL_ENSURE( pImp->m_xDocStorage == xStorage, "Wrong storage is used!\n" );
+ }
+
+ // now the medium can be disconnected from the storage
+ // the medium is not allowed to dispose the storage so CloseStorage() can be used
+ pMedium->CloseStorage();
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return bResult;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::DoLoad( SfxMedium *pMed )
+{
+ ModifyBlocker_Impl aBlock( this );
+
+ if ( SFX_CREATE_MODE_EMBEDDED != eCreateMode )
+ GetpApp()->ShowStatusText( SfxResId(STR_DOC_LOADING) );
+
+ pMedium = pMed;
+ pMedium->CanDisposeStorage_Impl( sal_True );
+
+ sal_Bool bOk = sal_False;
+ const SfxFilter* pFilter = pMed->GetFilter();
+ SfxItemSet* pSet = pMedium->GetItemSet();
+ if( !pImp->nEventId )
+ {
+ SFX_ITEMSET_ARG(
+ pSet, pTemplateItem, SfxBoolItem,
+ SID_TEMPLATE, sal_False);
+ SetActivateEvent_Impl(
+ ( pTemplateItem && pTemplateItem->GetValue() )
+ ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
+ }
+
+
+ SFX_ITEMSET_ARG( pSet, pBaseItem, SfxStringItem,
+ SID_BASEURL, sal_False);
+ String aBaseURL;
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
+ if( pBaseItem )
+ aBaseURL = pBaseItem->GetValue();
+ else
+ {
+ if ( pSalvageItem )
+ {
+ String aName( pMed->GetPhysicalName() );
+ ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aBaseURL );
+ }
+ else
+ aBaseURL = pMed->GetBaseURL();
+ }
+ pMed->GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, aBaseURL ) );
+
+ pImp->nLoadedFlags = 0;
+ pImp->bModelInitialized = sal_False;
+
+ //TODO/LATER: make a clear strategy how to handle "UsesStorage" etc.
+ sal_Bool bOwnStorageFormat = IsOwnStorageFormat_Impl( *pMedium );
+ sal_Bool bHasStorage = IsPackageStorageFormat_Impl( *pMedium );
+ if ( pMedium->GetFilter() )
+ {
+ sal_uInt32 nError = HandleFilter( pMedium, this );
+ if ( nError != ERRCODE_NONE )
+ SetError( nError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+
+ EnableSetModified( sal_False );
+
+ pMedium->LockOrigFileOnDemand( sal_True, sal_False );
+ if ( GetError() == ERRCODE_NONE && bOwnStorageFormat && ( !pFilter || !( pFilter->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) ) )
+ {
+ uno::Reference< embed::XStorage > xStorage;
+ if ( pMedium->GetError() == ERRCODE_NONE )
+ xStorage = pMedium->GetStorage();
+
+ if( xStorage.is() && pMedium->GetLastStorageCreationState() == ERRCODE_NONE )
+ {
+ DBG_ASSERT( pFilter, "No filter for storage found!" );
+
+ try
+ {
+ sal_Bool bWarnMediaTypeFallback = sal_False;
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairPackageItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False);
+
+ // treat the package as broken if the mediatype was retrieved as a fallback
+ uno::Reference< beans::XPropertySet > xStorProps( xStorage, uno::UNO_QUERY_THROW );
+ xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaTypeFallbackUsed" ) ) )
+ >>= bWarnMediaTypeFallback;
+
+ if ( pRepairPackageItem && pRepairPackageItem->GetValue() )
+ {
+ // the macros in repaired documents should be disabled
+ pMedium->GetItemSet()->Put( SfxUInt16Item( SID_MACROEXECMODE, document::MacroExecMode::NEVER_EXECUTE ) );
+
+ // the mediatype was retrieved by using fallback solution but this is a repairing mode
+ // so it is acceptable to open the document if there is no contents that required manifest.xml
+ bWarnMediaTypeFallback = sal_False;
+ }
+
+ if ( bWarnMediaTypeFallback || !xStorage->getElementNames().getLength() )
+ SetError( ERRCODE_IO_BROKENPACKAGE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ catch( uno::Exception& )
+ {
+ // TODO/LATER: may need error code setting based on exception
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+
+ // Load
+ if ( !GetError() )
+ {
+ pImp->nLoadedFlags = 0;
+ pImp->bModelInitialized = sal_False;
+ bOk = xStorage.is() && LoadOwnFormat( *pMed );
+ if ( bOk )
+ {
+ // the document loaded from template has no name
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
+ if ( !pTemplateItem || !pTemplateItem->GetValue() )
+ bHasName = sal_True;
+
+ if ( !IsReadOnly() && IsLoadReadonly() )
+ SetReadOnlyUI();
+ }
+ else
+ SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ }
+ else
+ SetError( pMed->GetLastStorageCreationState(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ else if ( GetError() == ERRCODE_NONE && InitNew(0) )
+ {
+ // Name vor ConvertFrom setzen, damit GetSbxObject() schon funktioniert
+ bHasName = sal_True;
+ SetName( SfxResId( STR_NONAME ) );
+
+ if( !bHasStorage )
+ pMedium->GetInStream();
+ else
+ pMedium->GetStorage();
+
+ if ( GetError() == ERRCODE_NONE )
+ {
+ pImp->nLoadedFlags = 0;
+ pImp->bModelInitialized = sal_False;
+ if ( pMedium->GetFilter() && ( pMedium->GetFilter()->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) )
+ {
+ uno::Reference < beans::XPropertySet > xSet( GetModel(), uno::UNO_QUERY );
+ ::rtl::OUString sLockUpdates(::rtl::OUString::createFromAscii("LockUpdates"));
+ bool bSetProperty = true;
+ try
+ {
+ xSet->setPropertyValue( sLockUpdates, makeAny( (sal_Bool) sal_True ) );
+ }
+ catch(const beans::UnknownPropertyException& )
+ {
+ bSetProperty = false;
+ }
+ bOk = ImportFrom(*pMedium);
+ if(bSetProperty)
+ {
+ try
+ {
+ xSet->setPropertyValue( sLockUpdates, makeAny( (sal_Bool) sal_False ) );
+ }
+ catch(const beans::UnknownPropertyException& )
+ {}
+ }
+ UpdateLinks();
+ FinishedLoading( SFX_LOADED_ALL );
+ }
+ else
+ {
+ bOk = ConvertFrom(*pMedium);
+ InitOwnModel_Impl();
+ }
+ }
+ }
+
+ if ( bOk )
+ {
+ try
+ {
+ ::ucbhelper::Content aContent( pMedium->GetName(), com::sun::star::uno::Reference < XCommandEnvironment >() );
+ com::sun::star::uno::Reference < XPropertySetInfo > xProps = aContent.getProperties();
+ if ( xProps.is() )
+ {
+ ::rtl::OUString aAuthor( RTL_CONSTASCII_USTRINGPARAM("Author") );
+ ::rtl::OUString aKeywords( RTL_CONSTASCII_USTRINGPARAM("Keywords") );
+ ::rtl::OUString aSubject( RTL_CONSTASCII_USTRINGPARAM("Subject") );
+ Any aAny;
+ ::rtl::OUString aValue;
+ uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
+ GetModel(), uno::UNO_QUERY_THROW);
+ uno::Reference<document::XDocumentProperties> xDocProps
+ = xDPS->getDocumentProperties();
+ if ( xProps->hasPropertyByName( aAuthor ) )
+ {
+ aAny = aContent.getPropertyValue( aAuthor );
+ if ( ( aAny >>= aValue ) )
+ xDocProps->setAuthor(aValue);
+ }
+ if ( xProps->hasPropertyByName( aKeywords ) )
+ {
+ aAny = aContent.getPropertyValue( aKeywords );
+ if ( ( aAny >>= aValue ) )
+ xDocProps->setKeywords(
+ ::comphelper::string::convertCommaSeparated(aValue));
+;
+ }
+ if ( xProps->hasPropertyByName( aSubject ) )
+ {
+ aAny = aContent.getPropertyValue( aSubject );
+ if ( ( aAny >>= aValue ) ) {
+ xDocProps->setSubject(aValue);
+ }
+ }
+ }
+ }
+ catch( Exception& )
+ {
+ }
+
+ // Falls nicht asynchron geladen wird selbst FinishedLoading aufrufen
+ if ( !( pImp->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) &&
+ ( !pMedium->GetFilter() || pMedium->GetFilter()->UsesStorage() )
+ )
+ FinishedLoading( SFX_LOADED_MAINDOCUMENT );
+
+ if( IsOwnStorageFormat_Impl(*pMed) && pMed->GetFilter() )
+ {
+//???? dv DirEntry aDirEntry( pMed->GetPhysicalName() );
+//???? dv SetFileName( aDirEntry.GetFull() );
+ }
+ Broadcast( SfxSimpleHint(SFX_HINT_NAMECHANGED) );
+
+ if ( SFX_CREATE_MODE_EMBEDDED != eCreateMode )
+ {
+ GetpApp()->HideStatusText();
+
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pAsTempItem, SfxBoolItem, SID_TEMPLATE, sal_False);
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPreviewItem, SfxBoolItem, SID_PREVIEW, sal_False);
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False);
+ if( bOk && pMedium->GetOrigURL().Len()
+ && !( pAsTempItem && pAsTempItem->GetValue() )
+ && !( pPreviewItem && pPreviewItem->GetValue() )
+ && !( pHiddenItem && pHiddenItem->GetValue() ) )
+ {
+ INetURLObject aUrl( pMedium->GetOrigURL() );
+
+ if ( aUrl.GetProtocol() == INET_PROT_FILE )
+ {
+ const SfxFilter* pOrgFilter = pMedium->GetOrigFilter();
+ Application::AddToRecentDocumentList(
+ aUrl.GetURLNoPass( INetURLObject::NO_DECODE ),
+ (pOrgFilter) ? pOrgFilter->GetMimeType() : String() );
+ }
+ }
+ }
+
+ if ( pMedium->HasStorage_Impl() )
+ {
+ uno::Reference< XInteractionHandler > xHandler( pMedium->GetInteractionHandler() );
+ if ( xHandler.is() && !SFX_APP()->Get_Impl()->bODFVersionWarningLater )
+ {
+ uno::Reference<beans::XPropertySet> xStorageProps( pMedium->GetStorage(), uno::UNO_QUERY_THROW );
+ ::rtl::OUString sVersion;
+ try
+ {
+ xStorageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= sVersion;
+ }
+ catch( const uno::Exception& )
+ {
+ // Custom Property "ODFVersion" does not exist
+ }
+
+ if ( sVersion.getLength() )
+ {
+ double nVersion = sVersion.toDouble();
+ if ( nVersion > 1.20001 && SfxObjectShell_Impl::NeedsOfficeUpdateDialog() )
+ // ODF version greater than 1.2 - added some decimal places to be safe against floating point conversion errors (hack)
+ {
+ ::rtl::OUString sDocumentURL( pMedium->GetOrigURL() );
+ ::rtl::OUString aSystemFileURL;
+ if ( osl::FileBase::getSystemPathFromFileURL( sDocumentURL, aSystemFileURL ) == osl::FileBase::E_None )
+ sDocumentURL = aSystemFileURL;
+
+ FutureDocumentVersionProductUpdateRequest aUpdateRequest;
+ aUpdateRequest.Classification = InteractionClassification_QUERY;
+ aUpdateRequest.DocumentURL = sDocumentURL;
+
+ ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest = new ::comphelper::OInteractionRequest( makeAny( aUpdateRequest ) );
+ pRequest->addContinuation( new ::comphelper::OInteractionApprove );
+ pRequest->addContinuation( new ::comphelper::OInteractionAbort );
+
+ typedef ::comphelper::OInteraction< XInteractionAskLater > OInteractionAskLater;
+ OInteractionAskLater* pLater = new OInteractionAskLater;
+ pRequest->addContinuation( pLater );
+
+ try
+ {
+ xHandler->handle( pRequest.get() );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ if ( pLater->wasSelected() )
+ SFX_APP()->Get_Impl()->bODFVersionWarningLater = true;
+ }
+ }
+ }
+ }
+ }
+ else
+ GetpApp()->HideStatusText();
+
+ return bOk;
+}
+
+sal_uInt32 SfxObjectShell::HandleFilter( SfxMedium* pMedium, SfxObjectShell* pDoc )
+{
+ sal_uInt32 nError = ERRCODE_NONE;
+ SfxItemSet* pSet = pMedium->GetItemSet();
+ SFX_ITEMSET_ARG( pSet, pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
+ SFX_ITEMSET_ARG( pSet, pData, SfxUnoAnyItem, SID_FILTER_DATA, sal_False );
+ if ( !pData && !pOptions )
+ {
+ com::sun::star::uno::Reference< XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
+ com::sun::star::uno::Reference< XNameAccess > xFilterCFG;
+ if( xServiceManager.is() )
+ {
+ xFilterCFG = com::sun::star::uno::Reference< XNameAccess >(
+ xServiceManager->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ),
+ UNO_QUERY );
+ }
+
+ if( xFilterCFG.is() )
+ {
+ BOOL bAbort = FALSE;
+ try {
+ const SfxFilter* pFilter = pMedium->GetFilter();
+ Sequence < PropertyValue > aProps;
+ Any aAny = xFilterCFG->getByName( pFilter->GetName() );
+ if ( aAny >>= aProps )
+ {
+ sal_Int32 nPropertyCount = aProps.getLength();
+ for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
+ if( aProps[nProperty].Name.equals( ::rtl::OUString::createFromAscii("UIComponent")) )
+ {
+ ::rtl::OUString aServiceName;
+ aProps[nProperty].Value >>= aServiceName;
+ if( aServiceName.getLength() )
+ {
+ com::sun::star::uno::Reference< XInteractionHandler > rHandler = pMedium->GetInteractionHandler();
+ if( rHandler.is() )
+ {
+ // we need some properties in the media descriptor, so we have to make sure that they are in
+ Any aStreamAny;
+ aStreamAny <<= pMedium->GetInputStream();
+ if ( pSet->GetItemState( SID_INPUTSTREAM ) < SFX_ITEM_SET )
+ pSet->Put( SfxUnoAnyItem( SID_INPUTSTREAM, aStreamAny ) );
+ if ( pSet->GetItemState( SID_FILE_NAME ) < SFX_ITEM_SET )
+ pSet->Put( SfxStringItem( SID_FILE_NAME, pMedium->GetName() ) );
+ if ( pSet->GetItemState( SID_FILTER_NAME ) < SFX_ITEM_SET )
+ pSet->Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
+
+ Sequence< PropertyValue > rProperties;
+ TransformItems( SID_OPENDOC, *pSet, rProperties, NULL );
+ RequestFilterOptions* pFORequest = new RequestFilterOptions( pDoc->GetModel(), rProperties );
+
+ com::sun::star::uno::Reference< XInteractionRequest > rRequest( pFORequest );
+ rHandler->handle( rRequest );
+
+ if ( !pFORequest->isAbort() )
+ {
+ SfxAllItemSet aNewParams( pDoc->GetPool() );
+ TransformParameters( SID_OPENDOC,
+ pFORequest->getFilterOptions(),
+ aNewParams,
+ NULL );
+
+ SFX_ITEMSET_ARG( &aNewParams,
+ pFilterOptions,
+ SfxStringItem,
+ SID_FILE_FILTEROPTIONS,
+ sal_False );
+ if ( pFilterOptions )
+ pSet->Put( *pFilterOptions );
+
+ SFX_ITEMSET_ARG( &aNewParams,
+ pFilterData,
+ SfxUnoAnyItem,
+ SID_FILTER_DATA,
+ sal_False );
+ if ( pFilterData )
+ pSet->Put( *pFilterData );
+ }
+ else
+ bAbort = TRUE;
+ }
+ }
+
+ break;
+ }
+ }
+
+ if( bAbort )
+ {
+ // filter options were not entered
+ nError = ERRCODE_ABORT;
+ }
+ }
+ catch( NoSuchElementException& )
+ {
+ // the filter name is unknown
+ nError = ERRCODE_IO_INVALIDPARAMETER;
+ }
+ catch( Exception& )
+ {
+ nError = ERRCODE_ABORT;
+ }
+ }
+ }
+
+ return nError;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsOwnStorageFormat_Impl(const SfxMedium &rMedium) const
+{
+ return !rMedium.GetFilter() || // Embedded
+ ( rMedium.GetFilter()->IsOwnFormat() &&
+ rMedium.GetFilter()->UsesStorage() &&
+ rMedium.GetFilter()->GetVersion() >= SOFFICE_FILEFORMAT_60 );
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsPackageStorageFormat_Impl(const SfxMedium &rMedium) const
+{
+ return !rMedium.GetFilter() || // Embedded
+ ( rMedium.GetFilter()->UsesStorage() &&
+ rMedium.GetFilter()->GetVersion() >= SOFFICE_FILEFORMAT_60 );
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::DoSave()
+// DoSave wird nur noch ueber OLE aufgerufen. Sichern eigener Dokumente im SFX
+// laeuft uber DoSave_Impl, um das Anlegen von Backups zu ermoeglichen.
+// Save in eigenes Format jetzt auch wieder Hierueber
+{
+ sal_Bool bOk = sal_False ;
+ {
+ ModifyBlocker_Impl aBlock( this );
+
+ pImp->bIsSaving = sal_True;
+
+ uno::Sequence< beans::NamedValue > aEncryptionData;
+ if ( IsPackageStorageFormat_Impl( *GetMedium() ) )
+ {
+ if ( GetEncryptionData_Impl( GetMedium()->GetItemSet(), aEncryptionData ) )
+ {
+ try
+ {
+ //TODO/MBA: GetOutputStorage?! Special mode, because it's "Save"?!
+ ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( GetMedium()->GetStorage(), aEncryptionData );
+ bOk = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+
+ DBG_ASSERT( bOk, "The root storage must allow to set common password!\n" );
+ }
+ else
+ bOk = sal_True;
+
+ if ( HasBasic() )
+ {
+ try
+ {
+ // The basic and dialogs related contents are still not able to proceed with save operation ( saveTo only )
+ // so since the document storage is locked a workaround has to be used
+
+ uno::Reference< embed::XStorage > xTmpStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
+ DBG_ASSERT( xTmpStorage.is(), "If a storage can not be created an exception must be thrown!\n" );
+ if ( !xTmpStorage.is() )
+ throw uno::RuntimeException();
+
+ ::rtl::OUString aBasicStorageName( RTL_CONSTASCII_USTRINGPARAM( "Basic" ) );
+ ::rtl::OUString aDialogsStorageName( RTL_CONSTASCII_USTRINGPARAM( "Dialogs" ) );
+ if ( GetMedium()->GetStorage()->hasByName( aBasicStorageName ) )
+ GetMedium()->GetStorage()->copyElementTo( aBasicStorageName, xTmpStorage, aBasicStorageName );
+ if ( GetMedium()->GetStorage()->hasByName( aDialogsStorageName ) )
+ GetMedium()->GetStorage()->copyElementTo( aDialogsStorageName, xTmpStorage, aDialogsStorageName );
+
+ GetBasicManager();
+
+ // disconnect from the current storage
+ pImp->pBasicManager->setStorage( xTmpStorage );
+
+ // store to the current storage
+ pImp->pBasicManager->storeLibrariesToStorage( GetMedium()->GetStorage() );
+
+ // connect to the current storage back
+ pImp->pBasicManager->setStorage( GetMedium()->GetStorage() );
+ }
+ catch( uno::Exception& )
+ {
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ bOk = sal_False;
+ }
+ }
+ }
+
+ if ( bOk )
+ bOk = Save();
+
+ bOk = pMedium->Commit();
+ }
+
+//#88046
+// if ( bOk )
+// SetModified( sal_False );
+ return bOk;
+}
+
+void Lock_Impl( SfxObjectShell* pDoc, BOOL bLock )
+{
+ SfxViewFrame *pFrame= SfxViewFrame::GetFirst( pDoc );
+ while ( pFrame )
+ {
+ pFrame->GetDispatcher()->Lock( bLock );
+ pFrame->Enable( !bLock );
+ pFrame = SfxViewFrame::GetNext( *pFrame, pDoc );
+ }
+
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::SaveTo_Impl
+(
+ SfxMedium &rMedium, // Medium, in das gespeichert werden soll
+ const SfxItemSet* pSet
+)
+
+/* [Beschreibung]
+
+ Schreibt den aktuellen Inhalt in das Medium rMedium.
+ Ist das Zielmedium kein Storage, so wird ueber ein temporaeres
+ Medium gespeichert, sonst direkt, da das Medium transacted
+ geschaltet ist, wenn wir es selbst geoeffnet haben und falls wir
+ Server sind entweder der Container einen transacted Storage zur
+ Verfuegung stellt oder selbst einen temporaeren Storage erzeugt hat.
+*/
+
+{
+ RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "PERFORMANCE SfxObjectShell::SaveTo_Impl" );
+ if( RTL_LOGFILE_HASLOGFILE() )
+ {
+ ByteString aString( rMedium.GetName(), RTL_TEXTENCODING_ASCII_US );
+ RTL_LOGFILE_PRODUCT_CONTEXT_TRACE1( aLog, "saving \"%s\"", aString.GetBuffer() );
+ }
+
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Begin" ) ) );
+
+ ModifyBlocker_Impl aMod(this);
+
+ const SfxFilter *pFilter = rMedium.GetFilter();
+ if ( !pFilter )
+ {
+ // if no filter was set, use the default filter
+ // this should be changed in the feature, it should be an error!
+ DBG_ERROR("No filter set!");
+ pFilter = GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT );
+ rMedium.SetFilter(pFilter);
+ }
+
+ sal_Bool bStorageBasedSource = IsPackageStorageFormat_Impl( *pMedium );
+ sal_Bool bStorageBasedTarget = IsPackageStorageFormat_Impl( rMedium );
+ sal_Bool bOwnSource = IsOwnStorageFormat_Impl( *pMedium );
+ sal_Bool bOwnTarget = IsOwnStorageFormat_Impl( rMedium );
+
+ // Examine target format to determine whether to query if any password
+ // protected libraries exceed the size we can handler
+ if ( bOwnTarget && !QuerySaveSizeExceededModules_Impl( rMedium.GetInteractionHandler() ) )
+ {
+ SetError( ERRCODE_IO_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ return sal_False;
+ }
+
+ sal_Bool bNeedsDisconnectionOnFail = sal_False;
+
+ sal_Bool bStoreToSameLocation = sal_False;
+
+ // the detection whether the script is changed should be done before saving
+ sal_Bool bTryToPreserveScriptSignature = sal_False;
+ // no way to detect whether a filter is oasis format, have to wait for saving process
+ sal_Bool bNoPreserveForOasis = sal_False;
+ if ( bOwnSource && bOwnTarget
+ && ( pImp->nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
+ || pImp->nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
+ || pImp->nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_INVALID ) )
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "MacroSignaturePreserving" ) ) );
+
+ // the checking of the library modified state iterates over the libraries, should be done only when required
+ // currently the check is commented out since it is broken, we have to check the signature every time we save
+ // TODO/LATER: let isAnyContainerModified() work!
+ bTryToPreserveScriptSignature = sal_True; // !pImp->pBasicManager->isAnyContainerModified();
+ if ( bTryToPreserveScriptSignature )
+ {
+ // check that the storage format stays the same
+ SvtSaveOptions aSaveOpt;
+ SvtSaveOptions::ODFDefaultVersion nVersion = aSaveOpt.GetODFDefaultVersion();
+
+ ::rtl::OUString aODFVersion;
+ try
+ {
+ uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aODFVersion;
+ }
+ catch( uno::Exception& )
+ {}
+
+ // preserve only if the same filter has been used
+ bTryToPreserveScriptSignature = pMedium->GetFilter() && pFilter && pMedium->GetFilter()->GetFilterName() == pFilter->GetFilterName();
+
+ bNoPreserveForOasis = (
+ (aODFVersion.equals( ODFVER_012_TEXT ) && nVersion == SvtSaveOptions::ODFVER_011) ||
+ (!aODFVersion.getLength() && nVersion >= SvtSaveOptions::ODFVER_012)
+ );
+ }
+ }
+
+ sal_Bool bCopyTo = sal_False;
+ SfxItemSet *pMedSet = rMedium.GetItemSet();
+ if( pMedSet )
+ {
+ SFX_ITEMSET_ARG( pMedSet, pSaveToItem, SfxBoolItem, SID_SAVETO, sal_False );
+ bCopyTo = GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ||
+ (pSaveToItem && pSaveToItem->GetValue());
+ }
+
+ // use UCB for case sensitive/insensitive file name comparison
+ if ( pMedium
+ && pMedium->GetName().CompareIgnoreCaseToAscii( "private:stream", 14 ) != COMPARE_EQUAL
+ && rMedium.GetName().CompareIgnoreCaseToAscii( "private:stream", 14 ) != COMPARE_EQUAL
+ && ::utl::UCBContentHelper::EqualURLs( pMedium->GetName(), rMedium.GetName() ) )
+ {
+ bStoreToSameLocation = sal_True;
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save" ) ) );
+
+ if ( pMedium->DocNeedsFileDateCheck() )
+ rMedium.CheckFileDate( pMedium->GetInitFileDate( sal_False ) );
+
+ if ( bCopyTo && GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
+ {
+ // export to the same location is vorbidden
+ SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ else
+ {
+ // before we overwrite the original file, we will make a backup if there is a demand for that
+ // if the backup is not created here it will be created internally and will be removed in case of successful saving
+ const sal_Bool bDoBackup = SvtSaveOptions().IsBackup();
+ if ( bDoBackup )
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "DoBackup" ) ) );
+ rMedium.DoBackup_Impl();
+ if ( rMedium.GetError() )
+ {
+ SetError( rMedium.GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ rMedium.ResetError();
+ }
+ }
+
+ if ( bStorageBasedSource && bStorageBasedTarget )
+ {
+ // The active storage must be switched. The simple saving is not enough.
+ // The problem is that the target medium contains target MediaDescriptor.
+
+ // In future the switch of the persistance could be done on stream level:
+ // a new wrapper service will be implemented that allows to exchange
+ // persistance on the fly. So the real persistance will be set
+ // to that stream only after successful commit of the storage.
+ // TODO/LATER:
+ // create wrapper stream based on the URL
+ // create a new storage based on this stream
+ // store to this new storage
+ // commit the new storage
+ // call saveCompleted based with this new storage ( get rid of old storage and "frees" URL )
+ // commit the wrapper stream ( the stream will connect the URL only on commit, after that it will hold it )
+ // if the last step is failed the stream should stay to be transacted and should be commited on any flush
+ // so we can forget the stream in any way and the next storage commit will flush it
+
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save: Own to Own" ) ) );
+
+ bNeedsDisconnectionOnFail = DisconnectStorage_Impl(
+ *pMedium, rMedium );
+ if ( bNeedsDisconnectionOnFail
+ || ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
+ {
+ pMedium->CloseAndRelease();
+
+ // TODO/LATER: for now the medium must be closed since it can already contain streams from old medium
+ // in future those streams should not be copied in case a valid target url is provided,
+ // if the url is not provided ( means the document is based on a stream ) this code is not
+ // reachable.
+ rMedium.CloseAndRelease();
+ rMedium.GetOutputStorage();
+ }
+ }
+ else if ( !bStorageBasedSource && !bStorageBasedTarget )
+ {
+ // the source and the target formats are alien
+ // just disconnect the stream from the source format
+ // so that the target medium can use it
+
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save: Alien to Alien" ) ) );
+
+ pMedium->CloseAndRelease();
+ rMedium.CloseAndRelease();
+ rMedium.CreateTempFileNoCopy();
+ rMedium.GetOutStream();
+ }
+ else if ( !bStorageBasedSource && bStorageBasedTarget )
+ {
+ // the source format is an alien one but the target
+ // format is an own one so just disconnect the source
+ // medium
+
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save: Alien to Own" ) ) );
+
+ pMedium->CloseAndRelease();
+ rMedium.CloseAndRelease();
+ rMedium.GetOutputStorage();
+ }
+ else // means if ( bStorageBasedSource && !bStorageBasedTarget )
+ {
+ // the source format is an own one but the target is
+ // an alien format, just connect the source to temporary
+ // storage
+
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save: Own to Alien" ) ) );
+
+ bNeedsDisconnectionOnFail = DisconnectStorage_Impl(
+ *pMedium, rMedium );
+ if ( bNeedsDisconnectionOnFail
+ || ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
+ {
+ pMedium->CloseAndRelease();
+ rMedium.CloseAndRelease();
+ rMedium.CreateTempFileNoCopy();
+ rMedium.GetOutStream();
+ }
+ }
+ }
+ }
+ else
+ {
+ // This is SaveAs or export action, prepare the target medium
+ // the alien filters still might write directly to the file, that is of course a bug,
+ // but for now the framework has to be ready for it
+ // TODO/LATER: let the medium be prepared for alien formats as well
+
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "SaveAs/Export" ) ) );
+
+ rMedium.CloseAndRelease();
+ if ( bStorageBasedTarget )
+ {
+ rMedium.GetOutputStorage();
+ }
+ }
+
+ // TODO/LATER: error handling
+ if( rMedium.GetErrorCode() || pMedium->GetErrorCode() || GetErrorCode() )
+ return sal_False;
+
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Locking" ) ) );
+
+ rMedium.LockOrigFileOnDemand( sal_False, sal_False );
+
+ if ( bStorageBasedTarget )
+ {
+ if ( rMedium.GetErrorCode() )
+ return sal_False;
+
+ // If the filter is a "cross export" filter ( f.e. a filter for exporting an impress document from
+ // a draw document ), the ClassId of the destination storage is different from the ClassId of this
+ // document. It can be retrieved from the default filter for the desired target format
+ long nFormat = rMedium.GetFilter()->GetFormat();
+ SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
+ const SfxFilter *pFilt = rMatcher.GetFilter4ClipBoardId( nFormat );
+ if ( pFilt )
+ {
+ if ( pFilt->GetServiceName() != rMedium.GetFilter()->GetServiceName() )
+ {
+ datatransfer::DataFlavor aDataFlavor;
+ SotExchange::GetFormatDataFlavor( nFormat, aDataFlavor );
+
+ try
+ {
+ uno::Reference< beans::XPropertySet > xProps( rMedium.GetStorage(), uno::UNO_QUERY );
+ DBG_ASSERT( xProps.is(), "The storage implementation must implement XPropertySet!" );
+ if ( !xProps.is() )
+ throw uno::RuntimeException();
+
+ xProps->setPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ),
+ uno::makeAny( aDataFlavor.MimeType ) );
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ }
+ }
+
+ // TODO/LATER: error handling
+ if( rMedium.GetErrorCode() || pMedium->GetErrorCode() || GetErrorCode() )
+ return sal_False;
+
+ sal_Bool bOldStat = pImp->bForbidReload;
+ pImp->bForbidReload = sal_True;
+
+ // lock user interface while saving the document
+ Lock_Impl( this, sal_True );
+
+ sal_Bool bOk = sal_False;
+ // TODO/LATER: get rid of bOk
+
+ if( bOwnTarget && !( pFilter->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) )
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing in own format." ) ) );
+ uno::Reference< embed::XStorage > xMedStorage = rMedium.GetStorage();
+ if ( !xMedStorage.is() )
+ {
+ // no saving without storage, unlock UI and return
+ Lock_Impl( this, sal_False );
+ pImp->bForbidReload = bOldStat;
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed, still no error set." ) ) );
+ return sal_False;
+ }
+
+ // transfer password from the parameters to the storage
+ uno::Sequence< beans::NamedValue > aEncryptionData;
+ sal_Bool bPasswdProvided = sal_False;
+ if ( GetEncryptionData_Impl( rMedium.GetItemSet(), aEncryptionData ) )
+ {
+ bPasswdProvided = sal_True;
+ try {
+ ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( xMedStorage, aEncryptionData );
+ bOk = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERROR( "Setting of common encryption key failed!" );
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ }
+ else
+ bOk = sal_True;
+
+ pFilter = rMedium.GetFilter();
+
+ const SfxStringItem *pVersionItem = pSet ? (const SfxStringItem*)
+ SfxRequest::GetItem( pSet, SID_DOCINFO_COMMENTS, sal_False, TYPE(SfxStringItem) ) : NULL;
+ ::rtl::OUString aTmpVersionURL;
+
+ if ( bOk )
+ {
+ bOk = sal_False;
+ // currently the case that the storage is the same should be impossible
+ if ( xMedStorage == GetStorage() )
+ {
+ OSL_ENSURE( !pVersionItem, "This scenario is impossible currently!\n" );
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Should be impossible." ) ) );
+ // usual save procedure
+ bOk = Save();
+ }
+ else
+ {
+ // save to target
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Save as own format." ) ) );
+ bOk = SaveAsOwnFormat( rMedium );
+ if ( bOk && pVersionItem )
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "pVersionItem != NULL" ) ) );
+ aTmpVersionURL = CreateTempCopyOfStorage_Impl( xMedStorage );
+ bOk = ( aTmpVersionURL.getLength() > 0 );
+ }
+ }
+ }
+
+
+ if ( bOk && GetCreateMode() != SFX_CREATE_MODE_EMBEDDED && !bPasswdProvided )
+ {
+ // store the thumbnail representation image
+ // the thumbnail is not stored in case of encrypted document
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Thumbnail creation." ) ) );
+ if ( !GenerateAndStoreThumbnail( bPasswdProvided,
+ sal_False,
+ pFilter->IsOwnTemplateFormat(),
+ xMedStorage ) )
+ {
+ // TODO: error handling
+ OSL_ENSURE( sal_False, "Couldn't store thumbnail representation!" );
+ }
+ }
+
+ if ( bOk )
+ {
+ if ( pImp->bIsSaving || pImp->bPreserveVersions )
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Preserve versions." ) ) );
+ try
+ {
+ Sequence < util::RevisionTag > aVersions = rMedium.GetVersionList();
+ if ( aVersions.getLength() )
+ {
+ // copy the version streams
+ ::rtl::OUString aVersionsName( RTL_CONSTASCII_USTRINGPARAM( "Versions" ) );
+ uno::Reference< embed::XStorage > xNewVerStor = xMedStorage->openStorageElement(
+ aVersionsName,
+ embed::ElementModes::READWRITE );
+ uno::Reference< embed::XStorage > xOldVerStor = GetStorage()->openStorageElement(
+ aVersionsName,
+ embed::ElementModes::READ );
+ if ( !xNewVerStor.is() || !xOldVerStor.is() )
+ throw uno::RuntimeException();
+
+ for ( sal_Int32 n=0; n<aVersions.getLength(); n++ )
+ {
+ if ( xOldVerStor->hasByName( aVersions[n].Identifier ) )
+ xOldVerStor->copyElementTo( aVersions[n].Identifier, xNewVerStor, aVersions[n].Identifier );
+ }
+
+ uno::Reference< embed::XTransactedObject > xTransact( xNewVerStor, uno::UNO_QUERY );
+ if ( xTransact.is() )
+ xTransact->commit();
+ }
+ }
+ catch( uno::Exception& )
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Preserve versions has failed." ) ) );
+ DBG_ERROR( "Couldn't copy versions!\n" );
+ bOk = sal_False;
+ // TODO/LATER: a specific error could be set
+ }
+ }
+
+ if ( bOk && pVersionItem )
+ {
+ // store a version also
+ const SfxStringItem *pAuthorItem = pSet ? (const SfxStringItem*)
+ SfxRequest::GetItem( pSet, SID_DOCINFO_AUTHOR, sal_False, TYPE(SfxStringItem) ) : NULL;
+
+ // version comment
+ util::RevisionTag aInfo;
+ aInfo.Comment = pVersionItem->GetValue();
+
+ // version author
+ String aAuthor;
+ if ( pAuthorItem )
+ aInfo.Author = pAuthorItem->GetValue();
+ else
+ // if not transferred as a parameter, get it from user settings
+ aInfo.Author = SvtUserOptions().GetFullName();
+
+ DateTime aTime;
+ aInfo.TimeStamp.Day = aTime.GetDay();
+ aInfo.TimeStamp.Month = aTime.GetMonth();
+ aInfo.TimeStamp.Year = aTime.GetYear();
+ aInfo.TimeStamp.Hours = aTime.GetHour();
+ aInfo.TimeStamp.Minutes = aTime.GetMin();
+ aInfo.TimeStamp.Seconds = aTime.GetSec();
+
+ if ( bOk )
+ {
+ // add new version information into the versionlist and save the versionlist
+ // the version list must have been transferred from the "old" medium before
+ rMedium.AddVersion_Impl( aInfo );
+ rMedium.SaveVersionList_Impl( sal_True );
+ bOk = PutURLContentsToVersionStream_Impl( aTmpVersionURL, xMedStorage, aInfo.Identifier );
+ }
+ }
+ else if ( bOk && ( pImp->bIsSaving || pImp->bPreserveVersions ) )
+ {
+ rMedium.SaveVersionList_Impl( sal_True );
+ }
+ }
+
+ if ( aTmpVersionURL.getLength() )
+ ::utl::UCBContentHelper::Kill( aTmpVersionURL );
+ }
+ else
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing in alien format." ) ) );
+ // it's a "SaveAs" in an alien format
+ if ( rMedium.GetFilter() && ( rMedium.GetFilter()->GetFilterFlags() & SFX_FILTER_STARONEFILTER ) )
+ bOk = ExportTo( rMedium );
+ else
+ bOk = ConvertTo( rMedium );
+
+ // after saving the document, the temporary object storage must be updated
+ // if the old object storage was not a temporary one, it will be updated also, because it will be used
+ // as a source for copying the objects into the new temporary storage that will be created below
+ // updating means: all child objects must be stored into it
+ // ( same as on loading, where these objects are copied to the temporary storage )
+ // but don't commit these changes, because in the case when the old object storage is not a temporary one,
+ // all changes will be written into the original file !
+
+ if( bOk && !bCopyTo )
+ // we also don't touch any graphical replacements here
+ bOk = SaveChildren( TRUE );
+ }
+
+ if ( bOk )
+ {
+ // if ODF version of oasis format changes on saving the signature should not be preserved
+ if ( bOk && bTryToPreserveScriptSignature && bNoPreserveForOasis )
+ bTryToPreserveScriptSignature = ( SotStorage::GetVersion( rMedium.GetStorage() ) == SOFFICE_FILEFORMAT_60 );
+
+ uno::Reference< security::XDocumentDigitalSignatures > xDDSigns;
+ if ( bOk && bTryToPreserveScriptSignature )
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Copying scripting signature." ) ) );
+
+ // if the scripting code was not changed and it is signed the signature should be preserved
+ // unfortunately at this point we have only information whether the basic code has changed or not
+ // so the only way is to check the signature if the basic was not changed
+ try
+ {
+ // get the ODF version of the new medium
+ uno::Sequence< uno::Any > aArgs( 1 );
+ aArgs[0] <<= ::rtl::OUString();
+ try
+ {
+ uno::Reference < beans::XPropertySet > xPropSet( rMedium.GetStorage(), uno::UNO_QUERY_THROW );
+ aArgs[0] = xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) );
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ xDDSigns = uno::Reference< security::XDocumentDigitalSignatures >(
+ comphelper::getProcessServiceFactory()->createInstanceWithArguments(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ),
+ aArgs ),
+ uno::UNO_QUERY_THROW );
+
+ ::rtl::OUString aScriptSignName = xDDSigns->getScriptingContentSignatureDefaultStreamName();
+
+ if ( aScriptSignName.getLength() )
+ {
+ pMedium->Close();
+
+ // target medium is still not commited, it should not be closed
+ // commit the package storage and close it, but leave the streams open
+ rMedium.StorageCommit_Impl();
+ rMedium.CloseStorage();
+
+ uno::Reference< embed::XStorage > xReadOrig = pMedium->GetZipStorageToSign_Impl();
+ if ( !xReadOrig.is() )
+ throw uno::RuntimeException();
+ uno::Reference< embed::XStorage > xMetaInf = xReadOrig->openStorageElement(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ),
+ embed::ElementModes::READ );
+
+ uno::Reference< embed::XStorage > xTarget = rMedium.GetZipStorageToSign_Impl( sal_False );
+ if ( !xTarget.is() )
+ throw uno::RuntimeException();
+ uno::Reference< embed::XStorage > xTargetMetaInf = xTarget->openStorageElement(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ),
+ embed::ElementModes::READWRITE );
+
+ if ( xMetaInf.is() && xTargetMetaInf.is() )
+ {
+ xMetaInf->copyElementTo( aScriptSignName, xTargetMetaInf, aScriptSignName );
+
+ uno::Reference< embed::XTransactedObject > xTransact( xTargetMetaInf, uno::UNO_QUERY );
+ if ( xTransact.is() )
+ xTransact->commit();
+
+ xTargetMetaInf->dispose();
+
+ // now check the copied signature
+ uno::Sequence< security::DocumentSignatureInformation > aInfos =
+ xDDSigns->verifyScriptingContentSignatures( xTarget,
+ uno::Reference< io::XInputStream >() );
+ sal_uInt16 nState = ImplCheckSignaturesInformation( aInfos );
+ if ( nState == SIGNATURESTATE_SIGNATURES_OK || nState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED
+ || nState == SIGNATURESTATE_SIGNATURES_PARTIAL_OK)
+ {
+ rMedium.SetCachedSignatureState_Impl( nState );
+
+ // commit the ZipStorage from target medium
+ xTransact.set( xTarget, uno::UNO_QUERY );
+ if ( xTransact.is() )
+ xTransact->commit();
+ }
+ else
+ {
+ // it should not happen, the copies signature is invalid!
+ // throw the changes away
+ OSL_ASSERT( "An invalid signature was copied!" );
+ }
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ pMedium->Close();
+ rMedium.CloseZipStorage_Impl();
+ }
+
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Medium commit." ) ) );
+
+ // transfer data to its destinated location
+ // the medium commits the storage or the stream it is based on
+ RegisterTransfer( rMedium );
+ bOk = rMedium.Commit();
+
+ if ( bOk )
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing is successful." ) ) );
+
+ // if the target medium is an alien format and the "old" medium was an own format and the "old" medium
+ // has a name, the object storage must be exchanged, because now we need a new temporary storage
+ // as object storage
+ if ( !bCopyTo && bStorageBasedSource && !bStorageBasedTarget )
+ {
+ if ( bStoreToSameLocation )
+ {
+ // if the old medium already disconnected from document storage, the storage still must
+ // be switched if backup file is used
+ if ( bNeedsDisconnectionOnFail )
+ ConnectTmpStorage_Impl( pImp->m_xDocStorage, NULL );
+ }
+ else if ( pMedium->GetName().Len()
+ || ( pMedium->HasStorage_Impl() && pMedium->WillDisposeStorageOnClose_Impl() ) )
+ {
+ OSL_ENSURE( pMedium->GetName().Len(), "Fallback is used, the medium without name should not dispose the storage!\n" );
+ // copy storage of old medium to new temporary storage and take this over
+ if( !ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Process after storing has failed." ) ) );
+ bOk = sal_False;
+ }
+ }
+ }
+ }
+ else
+ {
+ AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing has failed." ) ) );
+
+ // in case the document storage was connected to backup temporarely it must be disconnected now
+ if ( bNeedsDisconnectionOnFail )
+ ConnectTmpStorage_Impl( pImp->m_xDocStorage, NULL );
+ }
+ }
+
+ // unlock user interface
+ Lock_Impl( this, sal_False );
+ pImp->bForbidReload = bOldStat;
+
+ if ( bOk )
+ {
+ try
+ {
+ ::ucbhelper::Content aContent( rMedium.GetName(), com::sun::star::uno::Reference < XCommandEnvironment >() );
+ com::sun::star::uno::Reference < XPropertySetInfo > xProps = aContent.getProperties();
+ if ( xProps.is() )
+ {
+ ::rtl::OUString aAuthor( RTL_CONSTASCII_USTRINGPARAM("Author") );
+ ::rtl::OUString aKeywords( RTL_CONSTASCII_USTRINGPARAM("Keywords") );
+ ::rtl::OUString aSubject( RTL_CONSTASCII_USTRINGPARAM("Subject") );
+ Any aAny;
+
+ uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
+ GetModel(), uno::UNO_QUERY_THROW);
+ uno::Reference<document::XDocumentProperties> xDocProps
+ = xDPS->getDocumentProperties();
+
+ if ( xProps->hasPropertyByName( aAuthor ) )
+ {
+ aAny <<= xDocProps->getAuthor();
+ aContent.setPropertyValue( aAuthor, aAny );
+ }
+ if ( xProps->hasPropertyByName( aKeywords ) )
+ {
+ aAny <<= ::comphelper::string::convertCommaSeparated(
+ xDocProps->getKeywords());
+ aContent.setPropertyValue( aKeywords, aAny );
+ }
+ if ( xProps->hasPropertyByName( aSubject ) )
+ {
+ aAny <<= xDocProps->getSubject();
+ aContent.setPropertyValue( aSubject, aAny );
+ }
+ }
+ }
+ catch( Exception& )
+ {
+ }
+
+#ifdef OS2
+ {
+#define CHAR_POINTER(THE_OUSTRING) ::rtl::OUStringToOString (THE_OUSTRING, RTL_TEXTENCODING_UTF8).pData->buffer
+ // Header for a single-valued ASCII EA data item
+ typedef struct _EA_ASCII_header {
+ USHORT usAttr; /* value: EAT_ASCII */
+ USHORT usLen; /* length of data */
+ CHAR szType[_MAX_PATH]; /* ASCII data fits in here ... */
+ } EA_ASCII_HEADER;
+ char filePath[_MAX_PATH];
+ char fileExt[_MAX_PATH];
+ char docType[_MAX_PATH];
+ int rc;
+ oslFileError eRet;
+ ::rtl::OUString aSystemFileURL;
+ const ::rtl::OUString aFileURL = rMedium.GetName();
+ // close medium
+ rMedium.Close();
+
+ // convert file URL to system path
+ if (osl::FileBase::getSystemPathFromFileURL( aFileURL, aSystemFileURL) == osl::FileBase::E_None) {
+ EA_ASCII_HEADER eaAscii;
+ struct _ea eaType;
+ strcpy( filePath, CHAR_POINTER( aSystemFileURL));
+ strcpy( docType, CHAR_POINTER( rMedium.GetFilter()->GetServiceName()));
+#if OSL_DEBUG_LEVEL>1
+ printf( "file name: %s\n", filePath);
+ printf( "filter name: %s\n", CHAR_POINTER(rMedium.GetFilter()->GetFilterName()));
+ printf( "service name: %s\n", docType);
+#endif
+ // initialize OS/2 EA data structure
+ eaAscii.usAttr = EAT_ASCII;
+ _splitpath ( filePath, NULL, NULL, NULL, fileExt);
+ if (!stricmp( fileExt, ".pdf"))
+ strcpy( eaAscii.szType, "Acrobat Document");
+ else if (!strcmp( docType, "com.sun.star.text.TextDocument"))
+ strcpy( eaAscii.szType, "OpenOfficeOrg Writer Document");
+ else if (!strcmp( docType, "com.sun.star.sheet.SpreadsheetDocument"))
+ strcpy( eaAscii.szType, "OpenOfficeOrg Calc Document");
+ else if (!strcmp( docType, "com.sun.star.presentation.PresentationDocument"))
+ strcpy( eaAscii.szType, "OpenOfficeOrg Impress Document");
+ else if (!strcmp( docType, "com.sun.star.drawing.DrawingDocument"))
+ strcpy( eaAscii.szType, "OpenOfficeOrg Draw Document");
+ else
+ strcpy( eaAscii.szType, "OpenOfficeOrg Document");
+ eaAscii.usLen = strlen( eaAscii.szType);
+ // fill libc EA data structure
+ eaType.flags = 0;
+ eaType.size = sizeof(USHORT)*2 + eaAscii.usLen;
+ eaType.value = &eaAscii;
+ // put EA to file
+ rc = _ea_put( &eaType, filePath, 0, ".TYPE");
+#if OSL_DEBUG_LEVEL>1
+ printf( "ea name: %s, rc %d, errno %d\n", eaAscii.szType, rc, errno);
+#endif
+ }
+ }
+#endif
+
+ }
+
+ return bOk;
+}
+
+//------------------------------------------------------------------------
+sal_Bool SfxObjectShell::DisconnectStorage_Impl( SfxMedium& rSrcMedium, SfxMedium& rTargetMedium )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::DisconnectStorage_Impl" );
+
+ // this method disconnects the storage from source medium, and attaches it to the backup created by the target medium
+
+ uno::Reference< embed::XStorage > xStorage = rSrcMedium.GetStorage();
+
+ sal_Bool bResult = sal_False;
+ if ( xStorage == pImp->m_xDocStorage )
+ {
+ try
+ {
+ uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY_THROW );
+ ::rtl::OUString aBackupURL = rTargetMedium.GetBackup_Impl();
+ if ( !aBackupURL.getLength() )
+ {
+ // the backup could not be created, try to disconnect the storage and close the source SfxMedium
+ // in this case the optimization is not possible, connect storage to a temporary file
+ rTargetMedium.ResetError();
+ xOptStorage->writeAndAttachToStream( uno::Reference< io::XStream >() );
+ rSrcMedium.CanDisposeStorage_Impl( sal_False );
+ rSrcMedium.Close();
+
+ // now try to create the backup
+ rTargetMedium.GetBackup_Impl();
+ }
+ else
+ {
+ // the following call will only compare stream sizes
+ // TODO/LATER: this is a very risky part, since if the URL contents are different from the storage
+ // contents, the storag will be broken
+ xOptStorage->attachToURL( aBackupURL, sal_True );
+
+ // the storage is successfuly attached to backup, thus it it owned by the document not by the medium
+ rSrcMedium.CanDisposeStorage_Impl( sal_False );
+ bResult = sal_True;
+ }
+ }
+ catch ( uno::Exception& )
+ {}
+ }
+
+ OSL_ENSURE( bResult, "Storage disconnecting has failed - affects performance!" );
+
+ return bResult;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::ConnectTmpStorage_Impl(
+ const uno::Reference< embed::XStorage >& xStorage,
+ SfxMedium* pMediumArg )
+
+/* [Beschreibung]
+
+ Arbeitet die Applikation auf einem temporaeren Storage,
+ so darf der temporaere Storage nicht aus dem SaveCompleted
+ genommen werden. Daher wird in diesem Fall schon hier an
+ den neuen Storage connected. SaveCompleted tut dann nichts.
+
+ */
+
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::ConnectTmpStorage_Impl" );
+
+ sal_Bool bResult = sal_False;
+
+ if ( xStorage.is() )
+ {
+ try
+ {
+ // the empty argument means that the storage will create temporary stream itself
+ uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY_THROW );
+ xOptStorage->writeAndAttachToStream( uno::Reference< io::XStream >() );
+
+ // the storage is successfuly disconnected from the original sources, thus the medium must not dispose it
+ if ( pMediumArg )
+ pMediumArg->CanDisposeStorage_Impl( sal_False );
+
+ bResult = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ // if switching of the storage does not work for any reason ( nonroot storage for example ) use the old method
+ if ( !bResult ) try
+ {
+ uno::Reference< embed::XStorage > xTmpStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
+
+ DBG_ASSERT( xTmpStorage.is(), "If a storage can not be created an exception must be thrown!\n" );
+ if ( !xTmpStorage.is() )
+ throw uno::RuntimeException();
+
+ // TODO/LATER: may be it should be done in SwitchPersistence also
+ // TODO/LATER: find faster way to copy storage; perhaps sharing with backup?!
+ xStorage->copyToStorage( xTmpStorage );
+ //CopyStoragesOfUnknownMediaType( xStorage, xTmpStorage );
+ bResult = SaveCompleted( xTmpStorage );
+
+ if ( bResult )
+ {
+ pImp->pBasicManager->setStorage( xTmpStorage );
+
+ // Get rid of this workaround after issue i113914 is fixed
+ try
+ {
+ uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImp->xBasicLibraries, uno::UNO_QUERY_THROW );
+ xBasicLibraries->setRootStorage( xTmpStorage );
+ }
+ catch( uno::Exception& )
+ {}
+ try
+ {
+ uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImp->xDialogLibraries, uno::UNO_QUERY_THROW );
+ xDialogLibraries->setRootStorage( xTmpStorage );
+ }
+ catch( uno::Exception& )
+ {}
+ }
+ }
+ catch( uno::Exception& )
+ {}
+
+ if ( !bResult )
+ {
+ // TODO/LATER: may need error code setting based on exception
+ SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+ }
+
+ return bResult;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::DoSaveObjectAs( SfxMedium& rMedium, BOOL bCommit )
+{
+ sal_Bool bOk = sal_False;
+ {
+ ModifyBlocker_Impl aBlock( this );
+
+ uno::Reference < embed::XStorage > xNewStor = rMedium.GetStorage();
+ if ( !xNewStor.is() )
+ return sal_False;
+
+ uno::Reference < beans::XPropertySet > xPropSet( xNewStor, uno::UNO_QUERY );
+ if ( xPropSet.is() )
+ {
+ Any a = xPropSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) );
+ ::rtl::OUString aMediaType;
+ if ( !(a>>=aMediaType) || !aMediaType.getLength() )
+ {
+ OSL_ENSURE( sal_False, "The mediatype must be set already!\n" );
+ SetupStorage( xNewStor, SOFFICE_FILEFORMAT_CURRENT, sal_False );
+ }
+
+ pImp->bIsSaving = sal_False;
+ bOk = SaveAsOwnFormat( rMedium );
+
+ if ( bCommit )
+ {
+ try {
+ uno::Reference< embed::XTransactedObject > xTransact( xNewStor, uno::UNO_QUERY_THROW );
+ xTransact->commit();
+ }
+ catch( uno::Exception& )
+ {
+ DBG_ERROR( "The strotage was not commited on DoSaveAs!\n" );
+ }
+ }
+ }
+ }
+
+ return bOk;
+}
+
+//-------------------------------------------------------------------------
+// TODO/LATER: may be the call must be removed completelly
+sal_Bool SfxObjectShell::DoSaveAs( SfxMedium& rMedium )
+{
+ // hier kommen nur Root-Storages rein, die via Temp-File gespeichert werden
+ rMedium.CreateTempFileNoCopy();
+ SetError(rMedium.GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ if ( GetError() )
+ return sal_False;
+
+ // copy version list from "old" medium to target medium, so it can be used on saving
+ if ( pImp->bPreserveVersions )
+ rMedium.TransferVersionList_Impl( *pMedium );
+
+ sal_Bool bRet = SaveTo_Impl( rMedium, NULL );
+ if ( !bRet )
+ SetError(rMedium.GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ return bRet;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::DoSaveCompleted( SfxMedium* pNewMed )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::DoSaveCompleted" );
+
+ sal_Bool bOk = sal_True;
+ sal_Bool bMedChanged = pNewMed && pNewMed!=pMedium;
+/* sal_Bool bCreatedTempStor = pNewMed && pMedium &&
+ IsPackageStorageFormat_Impl(*pMedium) &&
+ !IsPackageStorageFormat_Impl(*pNewMed) &&
+ pMedium->GetName().Len();
+*/
+ DBG_ASSERT( !pNewMed || pNewMed->GetError() == ERRCODE_NONE, "DoSaveCompleted: Medium has error!" );
+
+ // delete Medium (and Storage!) after all notifications
+ SfxMedium* pOld = pMedium;
+ if ( bMedChanged )
+ {
+ pMedium = pNewMed;
+ pMedium->CanDisposeStorage_Impl( sal_True );
+ }
+
+ const SfxFilter *pFilter = pMedium ? pMedium->GetFilter() : 0;
+ if ( pNewMed )
+ {
+ if( bMedChanged )
+ {
+ if( pNewMed->GetName().Len() )
+ bHasName = sal_True;
+ Broadcast( SfxSimpleHint(SFX_HINT_NAMECHANGED) );
+ getDocProperties()->setGenerator(
+ ::utl::DocInfoHelper::GetGeneratorString() );
+ }
+
+ uno::Reference< embed::XStorage > xStorage;
+ if ( !pFilter || IsPackageStorageFormat_Impl( *pMedium ) )
+ {
+ uno::Reference < embed::XStorage > xOld = GetStorage();
+
+ // when the package based medium is broken and has no storage or if the storage
+ // is the same as the document storage the current document storage should be preserved
+ xStorage = pMedium->GetStorage();
+ bOk = SaveCompleted( xStorage );
+ if ( bOk && xStorage.is() && xOld != xStorage
+ && (!pOld || !pOld->HasStorage_Impl() || xOld != pOld->GetStorage() ) )
+ {
+ // old own storage was not controlled by old Medium -> dispose it
+ try {
+ xOld->dispose();
+ } catch( uno::Exception& )
+ {
+ // the storage is disposed already
+ // can happen during reload scenario when the medium has disposed it during the closing
+ // will be fixed in one of the next milestones
+ }
+ }
+ }
+ else
+ {
+ if( pMedium->GetOpenMode() & STREAM_WRITE )
+ pMedium->GetInStream();
+ xStorage = GetStorage();
+ }
+
+ // TODO/LATER: may be this code will be replaced, but not sure
+ // Set storage in document library containers
+ pImp->pBasicManager->setStorage( xStorage );
+
+ // Get rid of this workaround after issue i113914 is fixed
+ try
+ {
+ uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImp->xBasicLibraries, uno::UNO_QUERY_THROW );
+ xBasicLibraries->setRootStorage( xStorage );
+ }
+ catch( uno::Exception& )
+ {}
+ try
+ {
+ uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImp->xDialogLibraries, uno::UNO_QUERY_THROW );
+ xDialogLibraries->setRootStorage( xStorage );
+ }
+ catch( uno::Exception& )
+ {}
+ }
+ else
+ {
+ if( pMedium )
+ {
+ if( pFilter && !IsPackageStorageFormat_Impl( *pMedium ) && (pMedium->GetOpenMode() & STREAM_WRITE ))
+ {
+ pMedium->ReOpen();
+ bOk = SaveCompletedChildren( sal_False );
+ }
+ else
+ bOk = SaveCompleted( NULL );
+ }
+ // entweder Save oder ConvertTo
+ else
+ bOk = SaveCompleted( NULL );
+ }
+
+ if ( bOk && pNewMed )
+ {
+ if( bMedChanged )
+ {
+ delete pOld;
+
+ uno::Reference< frame::XModel > xModel = GetModel();
+ if ( xModel.is() )
+ {
+ ::rtl::OUString aURL = pNewMed->GetOrigURL();
+ uno::Sequence< beans::PropertyValue > aMediaDescr;
+ TransformItems( SID_OPENDOC, *pNewMed->GetItemSet(), aMediaDescr );
+ try
+ {
+ xModel->attachResource( aURL, aMediaDescr );
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ // before the title regenerated the document must loose the signatures
+ pImp->nDocumentSignatureState = SIGNATURESTATE_NOSIGNATURES;
+ pImp->nScriptingSignatureState = pNewMed->GetCachedSignatureState_Impl();
+ OSL_ENSURE( pImp->nScriptingSignatureState != SIGNATURESTATE_SIGNATURES_BROKEN, "The signature must not be broken at this place" );
+ pImp->bSignatureErrorIsShown = sal_False;
+
+ // TODO/LATER: in future the medium must control own signature state, not the document
+ pNewMed->SetCachedSignatureState_Impl( SIGNATURESTATE_NOSIGNATURES ); // set the default value back
+
+ // Titel neu setzen
+ if ( pNewMed->GetName().Len() && SFX_CREATE_MODE_EMBEDDED != eCreateMode )
+ InvalidateName();
+ SetModified(sal_False); // nur bei gesetztem Medium zur"ucksetzen
+ Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
+
+ // this is the end of the saving process, it is possible that the file was changed
+ // between medium commit and this step ( attributes change and so on )
+ // so get the file date again
+ if ( pNewMed->DocNeedsFileDateCheck() )
+ pNewMed->GetInitFileDate( sal_True );
+ }
+ }
+
+ pMedium->ClearBackup_Impl();
+ pMedium->LockOrigFileOnDemand( sal_True, sal_False );
+
+ return bOk;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::ConvertFrom
+(
+ SfxMedium& /*rMedium*/ /* <SfxMedium>, welches die Quell-Datei beschreibt
+ (z.B. Dateiname, <SfxFilter>, Open-Modi etc.) */
+)
+
+/* [Beschreibung]
+
+ Diese Methode wird zum Laden von Dokumenten "uber alle Filter gerufen,
+ die nicht SFX_FILTER_OWN sind oder f"ur die kein Clipboard-Format
+ registriert wurde (also kein Storage-Format benutzen). Mit anderen Worten:
+ mit dieser Methode wird importiert.
+
+ Das hier zu "offende File sollte "uber 'rMedium' ge"offnet werden,
+ um die richtigen Open-Modi zu gew"ahrleisten. Insbesondere wenn das
+ Format beibehalten wird (nur m"oglich bei SFX_FILTER_SIMULATE oder
+ SFX_FILTER_ONW) mu\s die Datei STREAM_SHARE_DENYWRITE ge"offnet werden.
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Das Dokument konnte geladen werden.
+
+ sal_False
+ Das Dokument konnte nicht geladen werden, ein
+ Fehlercode ist mit <SvMedium::GetError()const> zu
+ erhalten.
+
+
+ [Beispiel]
+
+ sal_Bool DocSh::ConvertFrom( SfxMedium &rMedium )
+ {
+ SvStreamRef xStream = rMedium.GetInStream();
+ if( xStream.is() )
+ {
+ xStream->SetBufferSize(4096);
+ *xStream >> ...;
+
+ // NICHT 'rMedium.CloseInStream()' rufen! File gelockt halten!
+ return SVSTREAM_OK == rMedium.GetError();
+ }
+
+ return sal_False;
+ }
+
+
+ [Querverweise]
+
+ <SfxObjectShell::ConvertTo(SfxMedium&)>
+ <SFX_FILTER_REGISTRATION>
+*/
+{
+ return sal_False;
+}
+
+sal_Bool SfxObjectShell::InsertFrom( SfxMedium& rMedium )
+{
+ ::rtl::OUString aTypeName( rMedium.GetFilter()->GetTypeName() );
+ ::rtl::OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
+
+ uno::Reference< lang::XMultiServiceFactory > xMan = ::comphelper::getProcessServiceFactory();
+ uno::Reference < lang::XMultiServiceFactory > xFilterFact (
+ xMan->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), uno::UNO_QUERY );
+
+ uno::Sequence < beans::PropertyValue > aProps;
+ uno::Reference < container::XNameAccess > xFilters ( xFilterFact, uno::UNO_QUERY );
+ if ( xFilters->hasByName( aFilterName ) )
+ {
+ xFilters->getByName( aFilterName ) >>= aProps;
+ rMedium.GetItemSet()->Put( SfxStringItem( SID_FILTER_NAME, aFilterName ) );
+ }
+
+ ::rtl::OUString aFilterImplName;
+ sal_Int32 nFilterProps = aProps.getLength();
+ for ( sal_Int32 nFilterProp = 0; nFilterProp<nFilterProps; nFilterProp++ )
+ {
+ const beans::PropertyValue& rFilterProp = aProps[nFilterProp];
+ if ( rFilterProp.Name.compareToAscii("FilterService") == COMPARE_EQUAL )
+ {
+ rFilterProp.Value >>= aFilterImplName;
+ break;
+ }
+ }
+
+ uno::Reference< document::XFilter > xLoader;
+ if ( aFilterImplName.getLength() )
+ {
+ try{
+ xLoader = uno::Reference< document::XFilter >
+ ( xFilterFact->createInstanceWithArguments( aFilterName, uno::Sequence < uno::Any >() ), uno::UNO_QUERY );
+ }catch(const uno::Exception&)
+ { xLoader.clear(); }
+ }
+ if ( xLoader.is() )
+ {
+ // #131744#: it happens that xLoader does not support xImporter!
+ try{
+ uno::Reference< lang::XComponent > xComp( GetModel(), uno::UNO_QUERY_THROW );
+ uno::Reference< document::XImporter > xImporter( xLoader, uno::UNO_QUERY_THROW );
+ xImporter->setTargetDocument( xComp );
+
+ uno::Sequence < beans::PropertyValue > lDescriptor;
+ rMedium.GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, rMedium.GetName() ) );
+ TransformItems( SID_OPENDOC, *rMedium.GetItemSet(), lDescriptor );
+
+ com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aArgs ( lDescriptor.getLength() );
+ com::sun::star::beans::PropertyValue * pNewValue = aArgs.getArray();
+ const com::sun::star::beans::PropertyValue * pOldValue = lDescriptor.getConstArray();
+ const OUString sInputStream ( RTL_CONSTASCII_USTRINGPARAM ( "InputStream" ) );
+
+ sal_Bool bHasInputStream = sal_False;
+ BOOL bHasBaseURL = FALSE;
+ sal_Int32 i;
+ sal_Int32 nEnd = lDescriptor.getLength();
+
+ for ( i = 0; i < nEnd; i++ )
+ {
+ pNewValue[i] = pOldValue[i];
+ if ( pOldValue [i].Name == sInputStream )
+ bHasInputStream = sal_True;
+ else if ( pOldValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "DocumentBaseURL" ) ) )
+ bHasBaseURL = sal_True;
+ }
+
+ if ( !bHasInputStream )
+ {
+ aArgs.realloc ( ++nEnd );
+ aArgs[nEnd-1].Name = sInputStream;
+ aArgs[nEnd-1].Value <<= com::sun::star::uno::Reference < com::sun::star::io::XInputStream > ( new utl::OSeekableInputStreamWrapper ( *rMedium.GetInStream() ) );
+ }
+
+ if ( !bHasBaseURL )
+ {
+ aArgs.realloc ( ++nEnd );
+ aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DocumentBaseURL" ) );
+ aArgs[nEnd-1].Value <<= rMedium.GetBaseURL();
+ }
+
+ aArgs.realloc( ++nEnd );
+ aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "InsertMode" ) );
+ aArgs[nEnd-1].Value <<= (sal_Bool) sal_True;
+
+ return xLoader->filter( aArgs );
+ }catch(const uno::Exception&)
+ {}
+ }
+
+ return sal_False;
+}
+
+sal_Bool SfxObjectShell::ImportFrom( SfxMedium& rMedium )
+{
+ ::rtl::OUString aTypeName( rMedium.GetFilter()->GetTypeName() );
+ ::rtl::OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
+
+ uno::Reference< lang::XMultiServiceFactory > xMan = ::comphelper::getProcessServiceFactory();
+ uno::Reference < lang::XMultiServiceFactory > xFilterFact (
+ xMan->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), uno::UNO_QUERY );
+
+ uno::Sequence < beans::PropertyValue > aProps;
+ uno::Reference < container::XNameAccess > xFilters ( xFilterFact, uno::UNO_QUERY );
+ if ( xFilters->hasByName( aFilterName ) )
+ {
+ xFilters->getByName( aFilterName ) >>= aProps;
+ rMedium.GetItemSet()->Put( SfxStringItem( SID_FILTER_NAME, aFilterName ) );
+ }
+
+ ::rtl::OUString aFilterImplName;
+ sal_Int32 nFilterProps = aProps.getLength();
+ for ( sal_Int32 nFilterProp = 0; nFilterProp<nFilterProps; nFilterProp++ )
+ {
+ const beans::PropertyValue& rFilterProp = aProps[nFilterProp];
+ if ( rFilterProp.Name.compareToAscii("FilterService") == COMPARE_EQUAL )
+ {
+ rFilterProp.Value >>= aFilterImplName;
+ break;
+ }
+ }
+
+ uno::Reference< document::XFilter > xLoader;
+ if ( aFilterImplName.getLength() )
+ {
+ try{
+ xLoader = uno::Reference< document::XFilter >
+ ( xFilterFact->createInstanceWithArguments( aFilterName, uno::Sequence < uno::Any >() ), uno::UNO_QUERY );
+ }catch(const uno::Exception&)
+ { xLoader.clear(); }
+ }
+ if ( xLoader.is() )
+ {
+ // #131744#: it happens that xLoader does not support xImporter!
+ try{
+ uno::Reference< lang::XComponent > xComp( GetModel(), uno::UNO_QUERY_THROW );
+ uno::Reference< document::XImporter > xImporter( xLoader, uno::UNO_QUERY_THROW );
+ xImporter->setTargetDocument( xComp );
+
+ uno::Sequence < beans::PropertyValue > lDescriptor;
+ rMedium.GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, rMedium.GetName() ) );
+ TransformItems( SID_OPENDOC, *rMedium.GetItemSet(), lDescriptor );
+
+ com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aArgs ( lDescriptor.getLength() );
+ com::sun::star::beans::PropertyValue * pNewValue = aArgs.getArray();
+ const com::sun::star::beans::PropertyValue * pOldValue = lDescriptor.getConstArray();
+ const OUString sInputStream ( RTL_CONSTASCII_USTRINGPARAM ( "InputStream" ) );
+
+ sal_Bool bHasInputStream = sal_False;
+ BOOL bHasBaseURL = FALSE;
+ sal_Int32 i;
+ sal_Int32 nEnd = lDescriptor.getLength();
+
+ for ( i = 0; i < nEnd; i++ )
+ {
+ pNewValue[i] = pOldValue[i];
+ if ( pOldValue [i].Name == sInputStream )
+ bHasInputStream = sal_True;
+ else if ( pOldValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "DocumentBaseURL" ) ) )
+ bHasBaseURL = sal_True;
+ }
+
+ if ( !bHasInputStream )
+ {
+ aArgs.realloc ( ++nEnd );
+ aArgs[nEnd-1].Name = sInputStream;
+ aArgs[nEnd-1].Value <<= com::sun::star::uno::Reference < com::sun::star::io::XInputStream > ( new utl::OSeekableInputStreamWrapper ( *rMedium.GetInStream() ) );
+ }
+
+ if ( !bHasBaseURL )
+ {
+ aArgs.realloc ( ++nEnd );
+ aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DocumentBaseURL" ) );
+ aArgs[nEnd-1].Value <<= rMedium.GetBaseURL();
+ }
+
+ return xLoader->filter( aArgs );
+ }catch(const uno::Exception&)
+ {}
+ }
+
+ return sal_False;
+}
+
+sal_Bool SfxObjectShell::ExportTo( SfxMedium& rMedium )
+{
+ ::rtl::OUString aTypeName( rMedium.GetFilter()->GetTypeName() );
+ ::rtl::OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
+ uno::Reference< document::XExporter > xExporter;
+
+ {
+ uno::Reference< lang::XMultiServiceFactory > xMan = ::comphelper::getProcessServiceFactory();
+ uno::Reference < lang::XMultiServiceFactory > xFilterFact (
+ xMan->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), uno::UNO_QUERY );
+
+ uno::Sequence < beans::PropertyValue > aProps;
+ uno::Reference < container::XNameAccess > xFilters ( xFilterFact, uno::UNO_QUERY );
+ if ( xFilters->hasByName( aFilterName ) )
+ xFilters->getByName( aFilterName ) >>= aProps;
+
+ ::rtl::OUString aFilterImplName;
+ sal_Int32 nFilterProps = aProps.getLength();
+ for ( sal_Int32 nFilterProp = 0; nFilterProp<nFilterProps; nFilterProp++ )
+ {
+ const beans::PropertyValue& rFilterProp = aProps[nFilterProp];
+ if ( rFilterProp.Name.compareToAscii("FilterService") == COMPARE_EQUAL )
+ {
+ rFilterProp.Value >>= aFilterImplName;
+ break;
+ }
+ }
+
+ if ( aFilterImplName.getLength() )
+ {
+ try{
+ xExporter = uno::Reference< document::XExporter >
+ ( xFilterFact->createInstanceWithArguments( aFilterName, uno::Sequence < uno::Any >() ), uno::UNO_QUERY );
+ }catch(const uno::Exception&)
+ { xExporter.clear(); }
+ }
+ }
+
+ if ( xExporter.is() )
+ {
+ try{
+ uno::Reference< lang::XComponent > xComp( GetModel(), uno::UNO_QUERY_THROW );
+ uno::Reference< document::XFilter > xFilter( xExporter, uno::UNO_QUERY_THROW );
+ xExporter->setSourceDocument( xComp );
+
+ com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aOldArgs;
+ SfxItemSet* pItems = rMedium.GetItemSet();
+ TransformItems( SID_SAVEASDOC, *pItems, aOldArgs );
+
+ const com::sun::star::beans::PropertyValue * pOldValue = aOldArgs.getConstArray();
+ com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aArgs ( aOldArgs.getLength() );
+ com::sun::star::beans::PropertyValue * pNewValue = aArgs.getArray();
+
+ // put in the REAL file name, and copy all PropertyValues
+ const OUString sOutputStream ( RTL_CONSTASCII_USTRINGPARAM ( "OutputStream" ) );
+ const OUString sStream ( RTL_CONSTASCII_USTRINGPARAM ( "StreamForOutput" ) );
+ BOOL bHasOutputStream = FALSE;
+ BOOL bHasStream = FALSE;
+ BOOL bHasBaseURL = FALSE;
+ sal_Int32 i;
+ sal_Int32 nEnd = aOldArgs.getLength();
+
+ for ( i = 0; i < nEnd; i++ )
+ {
+ pNewValue[i] = pOldValue[i];
+ if ( pOldValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "FileName" ) ) )
+ pNewValue[i].Value <<= OUString ( rMedium.GetName() );
+ else if ( pOldValue[i].Name == sOutputStream )
+ bHasOutputStream = sal_True;
+ else if ( pOldValue[i].Name == sStream )
+ bHasStream = sal_True;
+ else if ( pOldValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "DocumentBaseURL" ) ) )
+ bHasBaseURL = sal_True;
+ }
+
+ if ( !bHasOutputStream )
+ {
+ aArgs.realloc ( ++nEnd );
+ aArgs[nEnd-1].Name = sOutputStream;
+ aArgs[nEnd-1].Value <<= com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > ( new utl::OOutputStreamWrapper ( *rMedium.GetOutStream() ) );
+ }
+
+ // add stream as well, for OOX export and maybe others
+ if ( !bHasStream )
+ {
+ aArgs.realloc ( ++nEnd );
+ aArgs[nEnd-1].Name = sStream;
+ aArgs[nEnd-1].Value <<= com::sun::star::uno::Reference < com::sun::star::io::XStream > ( new utl::OStreamWrapper ( *rMedium.GetOutStream() ) );
+ }
+
+ if ( !bHasBaseURL )
+ {
+ aArgs.realloc ( ++nEnd );
+ aArgs[nEnd-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DocumentBaseURL" ) );
+ aArgs[nEnd-1].Value <<= rMedium.GetBaseURL( sal_True );
+ }
+
+ return xFilter->filter( aArgs );
+ }catch(const uno::Exception&)
+ {}
+ }
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::ConvertTo
+(
+ SfxMedium& /*rMedium*/ /* <SfxMedium>, welches die Ziel-Datei beschreibt
+ (z.B. Dateiname, <SfxFilter>, Open-Modi etc.) */
+)
+
+/* [Beschreibung]
+
+ Diese Methode wird zum Speichern von Dokumenten "uber alle Filter gerufen,
+ die nicht SFX_FILTER_OWN sind oder f"ur die kein Clipboard-Format
+ registriert wurde (also kein Storage-Format benutzen). Mit anderen Worten:
+ mit dieser Methode wird exportiert.
+
+ Das hier zu "offende File sollte "uber 'rMedium' ge"offnet werden,
+ um die richtigen Open-Modi zu gew"ahrleisten. Insbesondere wenn das
+ Format beibehalten wird (nur m"oglich bei SFX_FILTER_SIMULATE oder
+ SFX_FILTER_ONW) mu\s die Datei auch nach dem Speichern im Modus
+ STREAM_SHARE_DENYWRITE ge"offnet bleiben.
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ Das Dokument konnte gespeichert werden.
+
+ sal_False
+ Das Dokument konnte nicht gespeichert werden, ein
+ Fehlercode ist mit <SvMedium::GetError()const> zu
+ erhalten.
+
+
+ [Beispiel]
+
+ sal_Bool DocSh::ConvertTo( SfxMedium &rMedium )
+ {
+ SvStreamRef xStream = rMedium.GetOutStream();
+ if ( xStream.is() )
+ {
+ xStream->SetBufferSize(4096);
+ *xStream << ...;
+
+ rMedium.CloseOutStream(); // "offnet automatisch wieder den InStream
+ return SVSTREAM_OK == rMedium.GetError();
+ }
+ return sal_False ;
+ }
+
+
+ [Querverweise]
+
+ <SfxObjectShell::ConvertFrom(SfxMedium&)>
+ <SFX_FILTER_REGISTRATION>
+*/
+
+{
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs )
+{
+ SfxMedium* pRetrMedium = GetMedium();
+ const SfxFilter* pFilter = pRetrMedium->GetFilter();
+
+ // copy the original itemset, but remove the "version" item, because pMediumTmp
+ // is a new medium "from scratch", so no version should be stored into it
+ SfxItemSet* pSet = new SfxAllItemSet(*pRetrMedium->GetItemSet());
+ pSet->ClearItem( SID_VERSION );
+ pSet->ClearItem( SID_DOC_BASEURL );
+
+ // create a medium as a copy; this medium is only for writingm, because it uses the same name as the original one
+ // writing is done through a copy, that will be transferred to the target ( of course after calling HandsOff )
+ SfxMedium* pMediumTmp = new SfxMedium( pRetrMedium->GetName(), pRetrMedium->GetOpenMode(), pRetrMedium->IsDirect(), pFilter, pSet );
+ pMediumTmp->SetLongName( pRetrMedium->GetLongName() );
+// pMediumTmp->CreateTempFileNoCopy();
+ if ( pMediumTmp->GetErrorCode() != ERRCODE_NONE )
+ {
+ SetError( pMediumTmp->GetError(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ delete pMediumTmp;
+ return sal_False;
+ }
+
+ // copy version list from "old" medium to target medium, so it can be used on saving
+ pMediumTmp->TransferVersionList_Impl( *pRetrMedium );
+/*
+ if ( pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PACKED ) )
+ SetError( GetMedium()->Unpack_Impl( pRetrMedium->GetPhysicalName() ), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+*/
+
+ // an interaction handler here can aquire only in case of GUI Saving
+ // and should be removed after the saving is done
+ com::sun::star::uno::Reference< XInteractionHandler > xInteract;
+ SFX_ITEMSET_ARG( pArgs, pxInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False );
+ if ( pxInteractionItem && ( pxInteractionItem->GetValue() >>= xInteract ) && xInteract.is() )
+ pMediumTmp->GetItemSet()->Put( SfxUnoAnyItem( SID_INTERACTIONHANDLER, makeAny( xInteract ) ) );
+
+ sal_Bool bSaved = sal_False;
+ if( !GetError() && SaveTo_Impl( *pMediumTmp, pArgs ) )
+ {
+ bSaved = sal_True;
+
+ if( pMediumTmp->GetItemSet() )
+ {
+ pMediumTmp->GetItemSet()->ClearItem( SID_INTERACTIONHANDLER );
+ pMediumTmp->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
+ }
+
+ SetError(pMediumTmp->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+
+ sal_Bool bOpen( sal_False );
+ bOpen = DoSaveCompleted( pMediumTmp );
+ DBG_ASSERT(bOpen,"Fehlerbehandlung fuer DoSaveCompleted nicht implementiert");
+ }
+ else
+ {
+ // transfer error code from medium to objectshell
+ SetError( pMediumTmp->GetError(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+
+ // reconnect to object storage
+ DoSaveCompleted( 0 );
+
+ if( pRetrMedium->GetItemSet() )
+ {
+ pRetrMedium->GetItemSet()->ClearItem( SID_INTERACTIONHANDLER );
+ pRetrMedium->GetItemSet()->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
+ }
+
+ delete pMediumTmp;
+ }
+
+ SetModified( !bSaved );
+ return bSaved;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::Save_Impl( const SfxItemSet* pSet )
+{
+ if ( IsReadOnly() )
+ {
+ SetError( ERRCODE_SFX_DOCUMENTREADONLY, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ return sal_False;
+ }
+
+ DBG_CHKTHIS(SfxObjectShell, 0);
+
+ pImp->bIsSaving = sal_True;
+ sal_Bool bSaved = FALSE;
+ SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
+ if ( pSalvageItem )
+ {
+ SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False);
+ String aFilterName;
+ const SfxFilter *pFilter = NULL;
+ if ( pFilterItem )
+ pFilter = SfxFilterMatcher( String::CreateFromAscii( GetFactory().GetShortName()) ).GetFilter4FilterName( aFilterName );
+
+ SfxMedium *pMed = new SfxMedium(
+ pSalvageItem->GetValue(), STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC, sal_False, pFilter );
+
+ SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False );
+ if ( pPasswordItem )
+ pMed->GetItemSet()->Put( *pPasswordItem );
+
+ bSaved = DoSaveAs( *pMed );
+ if ( bSaved )
+ bSaved = DoSaveCompleted( pMed );
+ else
+ delete pMed;
+ }
+ else
+ bSaved = DoSave_Impl( pSet );
+ return bSaved;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::CommonSaveAs_Impl
+(
+ const INetURLObject& aURL,
+ const String& aFilterName,
+ SfxItemSet* aParams
+)
+{
+ if( aURL.HasError() )
+ {
+ SetError( ERRCODE_IO_INVALIDPARAMETER, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ return sal_False;
+ }
+
+ if ( aURL != INetURLObject( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:stream" ) ) ) )
+ {
+ // gibt es schon ein Doc mit dem Namen?
+ SfxObjectShell* pDoc = 0;
+ for ( SfxObjectShell* pTmp = SfxObjectShell::GetFirst();
+ pTmp && !pDoc;
+ pTmp = SfxObjectShell::GetNext(*pTmp) )
+ {
+ if( ( pTmp != this ) && pTmp->GetMedium() )
+ {
+ INetURLObject aCompare( pTmp->GetMedium()->GetName() );
+ if ( aCompare == aURL )
+ pDoc = pTmp;
+ }
+ }
+ if ( pDoc )
+ {
+ // dann Fehlermeldeung: "schon offen"
+ SetError(ERRCODE_SFX_ALREADYOPEN, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
+ return sal_False;
+ }
+ }
+
+ DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL!" );
+ DBG_ASSERT( aParams->Count() != 0, "fehlerhafte Parameter");
+
+ SFX_ITEMSET_ARG( aParams, pSaveToItem, SfxBoolItem, SID_SAVETO, sal_False );
+ sal_Bool bSaveTo = pSaveToItem ? pSaveToItem->GetValue() : sal_False;
+
+ const SfxFilter* pFilter = GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
+ if ( !pFilter
+ || !pFilter->CanExport()
+ || (!bSaveTo && !pFilter->CanImport()) )
+ {
+ SetError( ERRCODE_IO_INVALIDPARAMETER, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ return sal_False;
+ }
+
+ SFX_ITEMSET_ARG( aParams, pCopyStreamItem, SfxBoolItem, SID_COPY_STREAM_IF_POSSIBLE, sal_False );
+ if ( bSaveTo && pCopyStreamItem && pCopyStreamItem->GetValue() && !IsModified() )
+ {
+ if ( pMedium->TryDirectTransfer( aURL.GetMainURL( INetURLObject::NO_DECODE ), *aParams ) )
+ return sal_True;
+ }
+ aParams->ClearItem( SID_COPY_STREAM_IF_POSSIBLE );
+
+ pImp->bPasswd = aParams && SFX_ITEM_SET == aParams->GetItemState(SID_PASSWORD);
+
+ SfxMedium *pActMed = GetMedium();
+ const INetURLObject aActName(pActMed->GetName());
+
+ BOOL bWasReadonly = IsReadOnly();
+
+ if ( aURL == aActName && aURL != INetURLObject( OUString::createFromAscii( "private:stream" ) )
+ && IsReadOnly() )
+ {
+ SetError(ERRCODE_SFX_DOCUMENTREADONLY, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ));
+ return sal_False;
+ }
+
+ // this notification should be already sent by caller in sfxbasemodel
+ // SFX_APP()->NotifyEvent(SfxEventHint( bSaveTo? SFX_EVENT_SAVETODOC : SFX_EVENT_SAVEASDOC,this));
+
+ if( SFX_ITEM_SET != aParams->GetItemState(SID_UNPACK) && SvtSaveOptions().IsSaveUnpacked() )
+ aParams->Put( SfxBoolItem( SID_UNPACK, sal_False ) );
+
+ ::rtl::OUString aTempFileURL;
+ if ( IsDocShared() )
+ aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
+
+ if ( PreDoSaveAs_Impl(aURL.GetMainURL( INetURLObject::NO_DECODE ),aFilterName,aParams))
+ {
+ pImp->bWaitingForPicklist = sal_True;
+
+ // Daten am Medium updaten
+ SfxItemSet *pSet = GetMedium()->GetItemSet();
+ pSet->ClearItem( SID_INTERACTIONHANDLER );
+ pSet->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
+ pSet->ClearItem( SID_STANDARD_DIR );
+ pSet->ClearItem( SID_PATH );
+
+ if ( !bSaveTo )
+ {
+ pSet->ClearItem( SID_REFERER );
+ pSet->ClearItem( SID_POSTDATA );
+ pSet->ClearItem( SID_TEMPLATE );
+ pSet->ClearItem( SID_DOC_READONLY );
+ pSet->ClearItem( SID_CONTENTTYPE );
+ pSet->ClearItem( SID_CHARSET );
+ pSet->ClearItem( SID_FILTER_NAME );
+ pSet->ClearItem( SID_OPTIONS );
+ //pSet->ClearItem( SID_FILE_FILTEROPTIONS );
+ pSet->ClearItem( SID_VERSION );
+ pSet->ClearItem( SID_EDITDOC );
+ pSet->ClearItem( SID_OVERWRITE );
+ pSet->ClearItem( SID_DEFAULTFILEPATH );
+ pSet->ClearItem( SID_DEFAULTFILENAME );
+
+ SFX_ITEMSET_GET( (*aParams), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
+ if ( pFilterItem )
+ pSet->Put( *pFilterItem );
+
+ SFX_ITEMSET_GET( (*aParams), pOptionsItem, SfxStringItem, SID_OPTIONS, sal_False );
+ if ( pOptionsItem )
+ pSet->Put( *pOptionsItem );
+
+ SFX_ITEMSET_GET( (*aParams), pFilterOptItem, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
+ if ( pFilterOptItem )
+ pSet->Put( *pFilterOptItem );
+
+ if ( IsDocShared() && aTempFileURL.getLength() )
+ {
+ // this is a shared document that has to be disconnected from the old location
+ FreeSharedFile( aTempFileURL );
+
+ if ( pFilter->IsOwnFormat()
+ && pFilter->UsesStorage()
+ && pFilter->GetVersion() >= SOFFICE_FILEFORMAT_60 )
+ {
+ // the target format is the own format
+ // the target document must be shared
+ SwitchToShared( sal_True, sal_False );
+ }
+ }
+ }
+
+ if ( bWasReadonly && !bSaveTo )
+ Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
+
+ return sal_True;
+ }
+ else
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::PreDoSaveAs_Impl
+(
+ const String& rFileName,
+ const String& aFilterName,
+ SfxItemSet* pParams
+)
+{
+ // copy all items stored in the itemset of the current medium
+ SfxAllItemSet* pMergedParams = new SfxAllItemSet( *pMedium->GetItemSet() );
+
+ // in "SaveAs" title and password will be cleared ( maybe the new itemset contains new values, otherwise they will be empty )
+ pMergedParams->ClearItem( SID_PASSWORD );
+ pMergedParams->ClearItem( SID_DOCINFO_TITLE );
+
+ pMergedParams->ClearItem( SID_INPUTSTREAM );
+ pMergedParams->ClearItem( SID_STREAM );
+ pMergedParams->ClearItem( SID_CONTENT );
+ pMergedParams->ClearItem( SID_DOC_READONLY );
+ pMergedParams->ClearItem( SID_DOC_BASEURL );
+
+ pMergedParams->ClearItem( SID_REPAIRPACKAGE );
+
+ // "SaveAs" will never store any version information - it's a complete new file !
+ pMergedParams->ClearItem( SID_VERSION );
+
+ // merge the new parameters into the copy
+ // all values present in both itemsets will be overwritten by the new parameters
+ if( pParams )
+ pMergedParams->Put( *pParams );
+ //DELETEZ( pParams );
+
+#ifdef DBG_UTIL
+ if ( pMergedParams->GetItemState( SID_DOC_SALVAGE) >= SFX_ITEM_SET )
+ DBG_ERROR("Salvage item present in Itemset, check the parameters!");
+#endif
+
+ // should be unneccessary - too hot to handle!
+ pMergedParams->ClearItem( SID_DOC_SALVAGE );
+
+ // take over the new merged itemset
+ pParams = pMergedParams;
+
+ // create a medium for the target URL
+ SfxMedium *pNewFile = new SfxMedium( rFileName, STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC, sal_False, 0, pParams );
+
+ // set filter; if no filter is given, take the default filter of the factory
+ if ( aFilterName.Len() )
+ pNewFile->SetFilter( GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName ) );
+ else
+ pNewFile->SetFilter( GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT ) );
+
+ if ( pNewFile->GetErrorCode() != ERRCODE_NONE )
+ {
+ // creating temporary file failed ( f.e. floppy disk not inserted! )
+ SetError( pNewFile->GetError(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ delete pNewFile;
+ return sal_False;
+ }
+
+ // check if a "SaveTo" is wanted, no "SaveAs"
+ SFX_ITEMSET_ARG( pParams, pSaveToItem, SfxBoolItem, SID_SAVETO, sal_False );
+ sal_Bool bCopyTo = GetCreateMode() == SFX_CREATE_MODE_EMBEDDED || (pSaveToItem && pSaveToItem->GetValue());
+
+ // distinguish between "Save" and "SaveAs"
+ pImp->bIsSaving = sal_False;
+
+ // copy version list from "old" medium to target medium, so it can be used on saving
+ if ( pImp->bPreserveVersions )
+ pNewFile->TransferVersionList_Impl( *pMedium );
+
+/*
+ if ( GetMedium()->GetFilter() && ( GetMedium()->GetFilter()->GetFilterFlags() & SFX_FILTER_PACKED ) )
+ {
+ SfxMedium *pMed = bCopyTo ? pMedium : pNewFile;
+ pNewFile->SetError( GetMedium()->Unpack_Impl( pMed->GetPhysicalName() ) , ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+ }
+*/
+ // Save the document ( first as temporary file, then transfer to the target URL by committing the medium )
+ sal_Bool bOk = sal_False;
+ if ( !pNewFile->GetErrorCode() && SaveTo_Impl( *pNewFile, NULL ) )
+ {
+ bOk = sal_True;
+
+ // transfer a possible error from the medium to the document
+ SetError( pNewFile->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+
+ // notify the document that saving was done successfully
+ if ( !bCopyTo )
+ {
+ bOk = DoSaveCompleted( pNewFile );
+ }
+ else
+ bOk = DoSaveCompleted(0);
+
+ if( bOk )
+ {
+ if( !bCopyTo )
+ SetModified( sal_False );
+ }
+ else
+ {
+ // TODO/LATER: the code below must be dead since the storage commit makes all the stuff
+ // and the DoSaveCompleted call should not be able to fail in general
+
+ DBG_ASSERT( !bCopyTo, "Error while reconnecting to medium, can't be handled!");
+ SetError( pNewFile->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+
+ if ( !bCopyTo )
+ {
+ // reconnect to the old medium
+ BOOL bRet( FALSE );
+ bRet = DoSaveCompleted( pMedium );
+ DBG_ASSERT( bRet, "Error in DoSaveCompleted, can't be handled!");
+ }
+
+ // TODO/LATER: disconnect the new file from the storage for the case when pure saving is done
+ // if storing has corrupted the file, probably it must be restored either here or
+ // by the storage
+ DELETEZ( pNewFile );
+ }
+ }
+ else
+ {
+ SetError( pNewFile->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+
+ // reconnect to the old storage
+ DoSaveCompleted( 0 );
+
+ DELETEZ( pNewFile );
+ }
+
+ if ( bCopyTo )
+ DELETEZ( pNewFile );
+ else if( !bOk )
+ SetModified( sal_True );
+
+ return bOk;
+}
+
+//------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::LoadFrom( SfxMedium& /*rMedium*/ )
+{
+ DBG_ERROR( "Base implementation, must not be called in general!" );
+ return sal_True;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SfxObjectShell::IsInformationLost()
+{
+ Sequence< PropertyValue > aProps = GetModel()->getArgs();
+ ::rtl::OUString aFilterName;
+ ::rtl::OUString aPreusedFilterName;
+ for ( sal_Int32 nInd = 0; nInd < aProps.getLength(); nInd++ )
+ {
+ if ( aProps[nInd].Name.equalsAscii( "FilterName" ) )
+ aProps[nInd].Value >>= aFilterName;
+ else if ( aProps[nInd].Name.equalsAscii( "PreusedFilterName" ) )
+ aProps[nInd].Value >>= aPreusedFilterName;
+ }
+
+ // if current filter can lead to information loss and it was used
+ // for the latest store then the user should be asked to store in own format
+ if ( aFilterName.getLength() && aFilterName.equals( aPreusedFilterName ) )
+ {
+ const SfxFilter *pFilt = GetMedium()->GetFilter();
+ DBG_ASSERT( pFilt && aFilterName.equals( pFilt->GetName() ), "MediaDescriptor contains wrong filter!\n" );
+ return ( pFilt && pFilt->IsAlienFormat() && !(pFilt->GetFilterFlags() & SFX_FILTER_SILENTEXPORT ) );
+ }
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SfxObjectShell::CanReload_Impl()
+
+/* [Beschreibung]
+
+ Interne Methode zum Feststellen, ob eine erneutes Laden des
+ Dokuments (auch als RevertToSaved oder LastVersion bekannt)
+ m"oglich ist.
+*/
+
+{
+ return pMedium && HasName() && !IsInModalMode() && !pImp->bForbidReload;
+}
+
+//-------------------------------------------------------------------------
+
+sal_uInt16 SfxObjectShell::GetHiddenInformationState( sal_uInt16 nStates )
+{
+ sal_uInt16 nState = 0;
+ if ( nStates & HIDDENINFORMATION_DOCUMENTVERSIONS )
+ {
+ if ( GetMedium()->GetVersionList().getLength() )
+ nState |= HIDDENINFORMATION_DOCUMENTVERSIONS;
+ }
+
+ return nState;
+}
+
+sal_Int16 SfxObjectShell::QueryHiddenInformation( HiddenWarningFact eFact, Window* pParent )
+{
+ sal_Int16 nRet = RET_YES;
+ USHORT nResId = 0;
+ SvtSecurityOptions::EOption eOption = static_cast< SvtSecurityOptions::EOption >( -1 );
+
+ switch ( eFact )
+ {
+ case WhenSaving :
+ {
+ nResId = STR_HIDDENINFO_CONTINUE_SAVING;
+ eOption = SvtSecurityOptions::E_DOCWARN_SAVEORSEND;
+ break;
+ }
+ case WhenPrinting :
+ {
+ nResId = STR_HIDDENINFO_CONTINUE_PRINTING;
+ eOption = SvtSecurityOptions::E_DOCWARN_PRINT;
+ break;
+ }
+ case WhenSigning :
+ {
+ nResId = STR_HIDDENINFO_CONTINUE_SIGNING;
+ eOption = SvtSecurityOptions::E_DOCWARN_SIGNING;
+ break;
+ }
+ case WhenCreatingPDF :
+ {
+ nResId = STR_HIDDENINFO_CONTINUE_CREATEPDF;
+ eOption = SvtSecurityOptions::E_DOCWARN_CREATEPDF;
+ break;
+ }
+ default:
+ {
+ DBG_ERRORFILE( "SfxObjectShell::DetectHiddenInformation(): what fact?" );
+ }
+ }
+
+ if ( eOption != -1 && SvtSecurityOptions().IsOptionSet( eOption ) )
+ {
+ String sMessage( SfxResId( STR_HIDDENINFO_CONTAINS ) );
+ sal_uInt16 nWantedStates = HIDDENINFORMATION_RECORDEDCHANGES | HIDDENINFORMATION_NOTES;
+ if ( eFact != WhenPrinting )
+ nWantedStates |= HIDDENINFORMATION_DOCUMENTVERSIONS;
+ sal_uInt16 nStates = GetHiddenInformationState( nWantedStates );
+ bool bWarning = false;
+
+ if ( ( nStates & HIDDENINFORMATION_RECORDEDCHANGES ) == HIDDENINFORMATION_RECORDEDCHANGES )
+ {
+ sMessage += String( SfxResId( STR_HIDDENINFO_RECORDCHANGES ) );
+ sMessage += '\n';
+ bWarning = true;
+ }
+ if ( ( nStates & HIDDENINFORMATION_NOTES ) == HIDDENINFORMATION_NOTES )
+ {
+ sMessage += String( SfxResId( STR_HIDDENINFO_NOTES ) );
+ sMessage += '\n';
+ bWarning = true;
+ }
+ if ( ( nStates & HIDDENINFORMATION_DOCUMENTVERSIONS ) == HIDDENINFORMATION_DOCUMENTVERSIONS )
+ {
+ sMessage += String( SfxResId( STR_HIDDENINFO_DOCVERSIONS ) );
+ sMessage += '\n';
+ bWarning = true;
+ }
+
+ if ( bWarning )
+ {
+ sMessage += '\n';
+ sMessage += String( SfxResId( nResId ) );
+ WarningBox aWBox( pParent, WB_YES_NO | WB_DEF_NO, sMessage );
+ nRet = aWBox.Execute();
+ }
+ }
+
+ return nRet;
+}
+
+sal_Bool SfxObjectShell::HasSecurityOptOpenReadOnly() const
+{
+ return sal_True;
+}
+
+sal_Bool SfxObjectShell::IsSecurityOptOpenReadOnly() const
+{
+ return IsLoadReadonly();
+}
+
+void SfxObjectShell::SetSecurityOptOpenReadOnly( sal_Bool _b )
+{
+ SetLoadReadonly( _b );
+}
+
+sal_Bool SfxObjectShell::LoadOwnFormat( SfxMedium& rMedium )
+{
+ RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "PERFORMANCE SfxObjectShell::LoadOwnFormat" );
+ if( RTL_LOGFILE_HASLOGFILE() )
+ {
+ ByteString aString( rMedium.GetName(), RTL_TEXTENCODING_ASCII_US );
+ RTL_LOGFILE_PRODUCT_CONTEXT_TRACE1( aLog, "loading \"%s\"", aString.GetBuffer() );
+ }
+
+ uno::Reference< embed::XStorage > xStorage = rMedium.GetStorage();
+ if ( xStorage.is() )
+ {
+ // Password
+ SFX_ITEMSET_ARG( rMedium.GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False );
+ if ( pPasswdItem || ERRCODE_IO_ABORT != CheckPasswd_Impl( this, SFX_APP()->GetPool(), pMedium ) )
+ {
+ uno::Sequence< beans::NamedValue > aEncryptionData;
+ if ( GetEncryptionData_Impl(pMedium->GetItemSet(), aEncryptionData) )
+ {
+ try
+ {
+ // the following code must throw an exception in case of failure
+ ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( xStorage, aEncryptionData );
+ }
+ catch( uno::Exception& )
+ {
+ // TODO/LATER: handle the error code
+ }
+ }
+
+ // load document
+ return Load( rMedium );
+ }
+ return sal_False;
+ }
+ else
+ return sal_False;
+}
+
+sal_Bool SfxObjectShell::SaveAsOwnFormat( SfxMedium& rMedium )
+{
+ uno::Reference< embed::XStorage > xStorage = rMedium.GetStorage();
+ if( xStorage.is() )
+ {
+ sal_Int32 nVersion = rMedium.GetFilter()->GetVersion();
+
+ // OASIS templates have own mediatypes ( SO7 also actually, but it is to late to use them here )
+ sal_Bool bTemplate = ( rMedium.GetFilter()->IsOwnTemplateFormat() && nVersion > SOFFICE_FILEFORMAT_60 );
+
+ SetupStorage( xStorage, nVersion, bTemplate );
+
+ if ( HasBasic() )
+ {
+ // Initialize Basic
+ GetBasicManager();
+
+ // Save dialog/script container
+ pImp->pBasicManager->storeLibrariesToStorage( xStorage );
+ }
+
+ return SaveAs( rMedium );
+ }
+ else return sal_False;
+}
+
+uno::Reference< embed::XStorage > SfxObjectShell::GetStorage()
+{
+ if ( !pImp->m_xDocStorage.is() )
+ {
+ OSL_ENSURE( pImp->m_bCreateTempStor, "The storage must exist already!\n" );
+ try {
+ // no notification is required the storage is set the first time
+ pImp->m_xDocStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
+ OSL_ENSURE( pImp->m_xDocStorage.is(), "The method must either return storage or throw an exception!" );
+
+ SetupStorage( pImp->m_xDocStorage, SOFFICE_FILEFORMAT_CURRENT, sal_False );
+ pImp->m_bCreateTempStor = sal_False;
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_STORAGECHANGED, GlobalEventConfig::GetEventName(STR_EVENT_STORAGECHANGED), this ) );
+ }
+ catch( uno::Exception& )
+ {
+ // TODO/LATER: error handling?
+ }
+ }
+
+ OSL_ENSURE( pImp->m_xDocStorage.is(), "The document storage must be created!" );
+ return pImp->m_xDocStorage;
+}
+
+
+sal_Bool SfxObjectShell::SaveChildren( BOOL bObjectsOnly )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SaveChildren" );
+
+ sal_Bool bResult = sal_True;
+ if ( pImp->mpObjectContainer )
+ {
+ sal_Bool bOasis = ( SotStorage::GetVersion( GetStorage() ) > SOFFICE_FILEFORMAT_60 );
+ GetEmbeddedObjectContainer().StoreChildren(bOasis,bObjectsOnly);
+ }
+
+ return bResult;
+}
+
+sal_Bool SfxObjectShell::SaveAsChildren( SfxMedium& rMedium )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SaveAsChildren" );
+
+ sal_Bool bResult = sal_True;
+
+ uno::Reference < embed::XStorage > xStorage = rMedium.GetStorage();
+ if ( !xStorage.is() )
+ return sal_False;
+
+ if ( xStorage == GetStorage() )
+ return SaveChildren();
+
+ sal_Bool bOasis = sal_True;
+ if ( pImp->mpObjectContainer )
+ {
+ bOasis = ( SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60 );
+ GetEmbeddedObjectContainer().StoreAsChildren(bOasis,SFX_CREATE_MODE_EMBEDDED == eCreateMode,xStorage);
+ }
+
+ if ( bResult )
+ bResult = CopyStoragesOfUnknownMediaType( GetStorage(), xStorage );
+
+ return bResult;
+}
+
+sal_Bool SfxObjectShell::SaveCompletedChildren( sal_Bool bSuccess )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SaveCompletedChildren" );
+
+ sal_Bool bResult = sal_True;
+
+ if ( pImp->mpObjectContainer )
+ {
+ uno::Sequence < ::rtl::OUString > aNames = GetEmbeddedObjectContainer().GetObjectNames();
+ for ( sal_Int32 n=0; n<aNames.getLength(); n++ )
+ {
+ uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObjectContainer().GetEmbeddedObject( aNames[n] );
+ OSL_ENSURE( xObj.is(), "An empty entry in the embedded objects list!\n" );
+ if ( xObj.is() )
+ {
+ uno::Reference< embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
+ if ( xPersist.is() )
+ {
+ try
+ {
+ xPersist->saveCompleted( bSuccess );
+ }
+ catch( uno::Exception& )
+ {
+ // TODO/LATER: error handling
+ bResult = sal_False;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ return bResult;
+}
+
+sal_Bool SfxObjectShell::SwitchChildrenPersistance( const uno::Reference< embed::XStorage >& xStorage,
+ sal_Bool bForceNonModified )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SwitchChildrenPersistence" );
+
+ if ( !xStorage.is() )
+ {
+ // TODO/LATER: error handling
+ return sal_False;
+ }
+
+ sal_Bool bResult = sal_True;
+
+ if ( pImp->mpObjectContainer )
+ pImp->mpObjectContainer->SetPersistentEntries(xStorage,bForceNonModified);
+
+ return bResult;
+}
+
+// Never call this method directly, always use the DoSaveCompleted call
+sal_Bool SfxObjectShell::SaveCompleted( const uno::Reference< embed::XStorage >& xStorage )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SaveCompleted" );
+
+ sal_Bool bResult = sal_False;
+ sal_Bool bSendNotification = sal_False;
+ uno::Reference< embed::XStorage > xOldStorageHolder;
+
+#ifdef DBG_UTIL
+ // check for wrong creation of object container
+ BOOL bHasContainer = ( pImp->mpObjectContainer != 0 );
+#endif
+
+ if ( !xStorage.is() || xStorage == GetStorage() )
+ {
+ // no persistence change
+ bResult = SaveCompletedChildren( sal_False );
+ }
+ else
+ {
+ if ( pImp->mpObjectContainer )
+ GetEmbeddedObjectContainer().SwitchPersistence( xStorage );
+
+ bResult = SwitchChildrenPersistance( xStorage, sal_True );
+ }
+
+ if ( bResult )
+ {
+ if ( xStorage.is() && pImp->m_xDocStorage != xStorage )
+ {
+ // make sure that until the storage is assigned the object container is not created by accident!
+ DBG_ASSERT( bHasContainer == (pImp->mpObjectContainer != 0), "Wrong storage in object container!" );
+ xOldStorageHolder = pImp->m_xDocStorage;
+ pImp->m_xDocStorage = xStorage;
+ bSendNotification = sal_True;
+
+ if ( IsEnableSetModified() )
+ SetModified( sal_False );
+ }
+ }
+ else
+ {
+ if ( pImp->mpObjectContainer )
+ GetEmbeddedObjectContainer().SwitchPersistence( pImp->m_xDocStorage );
+
+ // let already successfully connected objects be switched back
+ SwitchChildrenPersistance( pImp->m_xDocStorage, sal_True );
+ }
+
+ if ( bSendNotification )
+ {
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_STORAGECHANGED, GlobalEventConfig::GetEventName(STR_EVENT_STORAGECHANGED), this ) );
+ }
+
+ return bResult;
+}
+
+
+sal_Bool StoragesOfUnknownMediaTypeAreCopied_Impl( const uno::Reference< embed::XStorage >& xSource,
+ const uno::Reference< embed::XStorage >& xTarget )
+{
+ OSL_ENSURE( xSource.is() && xTarget.is(), "Source and/or target storages are not available!\n" );
+ if ( !xSource.is() || !xTarget.is() || xSource == xTarget )
+ return sal_True;
+
+ try
+ {
+ uno::Sequence< ::rtl::OUString > aSubElements = xSource->getElementNames();
+ for ( sal_Int32 nInd = 0; nInd < aSubElements.getLength(); nInd++ )
+ {
+ if ( xSource->isStorageElement( aSubElements[nInd] ) )
+ {
+ ::rtl::OUString aMediaType;
+ ::rtl::OUString aMediaTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
+ sal_Bool bGotMediaType = sal_False;
+
+ try
+ {
+ uno::Reference< embed::XOptimizedStorage > xOptStorage( xSource, uno::UNO_QUERY_THROW );
+ bGotMediaType =
+ ( xOptStorage->getElementPropertyValue( aSubElements[nInd], aMediaTypePropName ) >>= aMediaType );
+ }
+ catch( uno::Exception& )
+ {}
+
+ if ( !bGotMediaType )
+ {
+ uno::Reference< embed::XStorage > xSubStorage;
+ try {
+ xSubStorage = xSource->openStorageElement( aSubElements[nInd], embed::ElementModes::READ );
+ } catch( uno::Exception& )
+ {}
+
+ if ( !xSubStorage.is() )
+ {
+ xSubStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
+ xSource->copyStorageElementLastCommitTo( aSubElements[nInd], xSubStorage );
+ }
+
+ uno::Reference< beans::XPropertySet > xProps( xSubStorage, uno::UNO_QUERY_THROW );
+ bGotMediaType = ( xProps->getPropertyValue( aMediaTypePropName ) >>= aMediaType );
+ }
+
+ // TODO/LATER: there should be a way to detect whether an object with such a MediaType can exist
+ // probably it should be placed in the MimeType-ClassID table or in standalone table
+ if ( aMediaType.getLength()
+ && aMediaType.compareToAscii( "application/vnd.sun.star.oleobject" ) != COMPARE_EQUAL )
+ {
+ ::com::sun::star::datatransfer::DataFlavor aDataFlavor;
+ aDataFlavor.MimeType = aMediaType;
+ sal_uInt32 nFormat = SotExchange::GetFormat( aDataFlavor );
+
+ switch ( nFormat )
+ {
+ case SOT_FORMATSTR_ID_STARWRITER_60 :
+ case SOT_FORMATSTR_ID_STARWRITERWEB_60 :
+ case SOT_FORMATSTR_ID_STARWRITERGLOB_60 :
+ case SOT_FORMATSTR_ID_STARDRAW_60 :
+ case SOT_FORMATSTR_ID_STARIMPRESS_60 :
+ case SOT_FORMATSTR_ID_STARCALC_60 :
+ case SOT_FORMATSTR_ID_STARCHART_60 :
+ case SOT_FORMATSTR_ID_STARMATH_60 :
+ case SOT_FORMATSTR_ID_STARWRITER_8:
+ case SOT_FORMATSTR_ID_STARWRITERWEB_8:
+ case SOT_FORMATSTR_ID_STARWRITERGLOB_8:
+ case SOT_FORMATSTR_ID_STARDRAW_8:
+ case SOT_FORMATSTR_ID_STARIMPRESS_8:
+ case SOT_FORMATSTR_ID_STARCALC_8:
+ case SOT_FORMATSTR_ID_STARCHART_8:
+ case SOT_FORMATSTR_ID_STARMATH_8:
+ break;
+
+ default:
+ {
+ if ( !xTarget->hasByName( aSubElements[nInd] ) )
+ return sal_False;
+ }
+ }
+ }
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Cant check storage consistency!\n" );
+ }
+
+ return sal_True;
+}
+
+
+sal_Bool SfxObjectShell::SwitchPersistance( const uno::Reference< embed::XStorage >& xStorage )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::SwitchPersistance" );
+
+ sal_Bool bResult = sal_False;
+#ifdef DBG_UTIL
+ // check for wrong creation of object container
+ BOOL bHasContainer = ( pImp->mpObjectContainer != 0 );
+#endif
+ if ( xStorage.is() )
+ {
+ if ( pImp->mpObjectContainer )
+ GetEmbeddedObjectContainer().SwitchPersistence( xStorage );
+ bResult = SwitchChildrenPersistance( xStorage );
+
+ // TODO/LATER: substorages that have unknown mimetypes probably should be copied to the target storage here
+ OSL_ENSURE( StoragesOfUnknownMediaTypeAreCopied_Impl( pImp->m_xDocStorage, xStorage ),
+ "Some of substorages with unknown mimetypes is lost!" );
+ }
+
+ if ( bResult )
+ {
+ // make sure that until the storage is assigned the object container is not created by accident!
+ DBG_ASSERT( bHasContainer == (pImp->mpObjectContainer != 0), "Wrong storage in object container!" );
+ if ( pImp->m_xDocStorage != xStorage )
+ DoSaveCompleted( new SfxMedium( xStorage, GetMedium()->GetBaseURL() ) );
+
+ if ( IsEnableSetModified() )
+ SetModified( sal_True ); // ???
+ }
+
+ return bResult;
+}
+
+sal_Bool SfxObjectShell::CopyStoragesOfUnknownMediaType( const uno::Reference< embed::XStorage >& xSource,
+ const uno::Reference< embed::XStorage >& xTarget )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::CopyStoragesOfUnknownMediaType" );
+
+ // This method does not commit the target storage and should not do it
+ sal_Bool bResult = sal_True;
+
+ try
+ {
+ uno::Sequence< ::rtl::OUString > aSubElements = xSource->getElementNames();
+ for ( sal_Int32 nInd = 0; nInd < aSubElements.getLength(); nInd++ )
+ {
+ if ( aSubElements[nInd].equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Configurations" ) ) ) )
+ {
+ // The workaround for compatibility with SO7, "Configurations" substorage must be preserved
+ if ( xSource->isStorageElement( aSubElements[nInd] ) )
+ {
+ OSL_ENSURE( !xTarget->hasByName( aSubElements[nInd] ),
+ "The target storage is an output storage, the element should not exist in the target!\n" );
+
+ xSource->copyElementTo( aSubElements[nInd], xTarget, aSubElements[nInd] );
+ }
+ }
+ else if ( xSource->isStorageElement( aSubElements[nInd] ) )
+ {
+ ::rtl::OUString aMediaType;
+ ::rtl::OUString aMediaTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
+ sal_Bool bGotMediaType = sal_False;
+
+ try
+ {
+ uno::Reference< embed::XOptimizedStorage > xOptStorage( xSource, uno::UNO_QUERY_THROW );
+ bGotMediaType =
+ ( xOptStorage->getElementPropertyValue( aSubElements[nInd], aMediaTypePropName ) >>= aMediaType );
+ }
+ catch( uno::Exception& )
+ {}
+
+ if ( !bGotMediaType )
+ {
+ uno::Reference< embed::XStorage > xSubStorage;
+ try {
+ xSubStorage = xSource->openStorageElement( aSubElements[nInd], embed::ElementModes::READ );
+ } catch( uno::Exception& )
+ {}
+
+ if ( !xSubStorage.is() )
+ {
+ // TODO/LATER: as optimization in future a substorage of target storage could be used
+ // instead of the temporary storage; this substorage should be removed later
+ // if the MimeType is wrong
+ xSubStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
+ xSource->copyStorageElementLastCommitTo( aSubElements[nInd], xSubStorage );
+ }
+
+ uno::Reference< beans::XPropertySet > xProps( xSubStorage, uno::UNO_QUERY_THROW );
+ bGotMediaType = ( xProps->getPropertyValue( aMediaTypePropName ) >>= aMediaType );
+ }
+
+ // TODO/LATER: there should be a way to detect whether an object with such a MediaType can exist
+ // probably it should be placed in the MimeType-ClassID table or in standalone table
+ if ( aMediaType.getLength()
+ && aMediaType.compareToAscii( "application/vnd.sun.star.oleobject" ) != COMPARE_EQUAL )
+ {
+ ::com::sun::star::datatransfer::DataFlavor aDataFlavor;
+ aDataFlavor.MimeType = aMediaType;
+ sal_uInt32 nFormat = SotExchange::GetFormat( aDataFlavor );
+
+ switch ( nFormat )
+ {
+ case SOT_FORMATSTR_ID_STARWRITER_60 :
+ case SOT_FORMATSTR_ID_STARWRITERWEB_60 :
+ case SOT_FORMATSTR_ID_STARWRITERGLOB_60 :
+ case SOT_FORMATSTR_ID_STARDRAW_60 :
+ case SOT_FORMATSTR_ID_STARIMPRESS_60 :
+ case SOT_FORMATSTR_ID_STARCALC_60 :
+ case SOT_FORMATSTR_ID_STARCHART_60 :
+ case SOT_FORMATSTR_ID_STARMATH_60 :
+ case SOT_FORMATSTR_ID_STARWRITER_8:
+ case SOT_FORMATSTR_ID_STARWRITERWEB_8:
+ case SOT_FORMATSTR_ID_STARWRITERGLOB_8:
+ case SOT_FORMATSTR_ID_STARDRAW_8:
+ case SOT_FORMATSTR_ID_STARIMPRESS_8:
+ case SOT_FORMATSTR_ID_STARCALC_8:
+ case SOT_FORMATSTR_ID_STARCHART_8:
+ case SOT_FORMATSTR_ID_STARMATH_8:
+ break;
+
+ default:
+ {
+ OSL_ENSURE(
+ aSubElements[nInd].equalsAscii( "Configurations2" ) || !xTarget->hasByName( aSubElements[nInd] ),
+ "The target storage is an output storage, the element should not exist in the target!\n" );
+
+ if ( !xTarget->hasByName( aSubElements[nInd] ) )
+ {
+ xSource->copyElementTo( aSubElements[nInd], xTarget, aSubElements[nInd] );
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ bResult = sal_False;
+ // TODO/LATER: a specific error could be provided
+ }
+
+ return bResult;
+}
+
+sal_Bool SfxObjectShell::GenerateAndStoreThumbnail( sal_Bool bEncrypted,
+ sal_Bool bSigned,
+ sal_Bool bIsTemplate,
+ const uno::Reference< embed::XStorage >& xStor )
+{
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::GenerateAndStoreThumbnail" );
+
+ sal_Bool bResult = sal_False;
+
+ try {
+ uno::Reference< embed::XStorage > xThumbnailStor =
+ xStor->openStorageElement( ::rtl::OUString::createFromAscii( "Thumbnails" ),
+ embed::ElementModes::READWRITE );
+ if ( xThumbnailStor.is() )
+ {
+ uno::Reference< io::XStream > xStream = xThumbnailStor->openStreamElement(
+ ::rtl::OUString::createFromAscii( "thumbnail.png" ),
+ embed::ElementModes::READWRITE );
+
+ if ( xStream.is() && WriteThumbnail( bEncrypted, bSigned, bIsTemplate, xStream ) )
+ {
+ uno::Reference< embed::XTransactedObject > xTransact( xThumbnailStor, uno::UNO_QUERY_THROW );
+ xTransact->commit();
+ bResult = sal_True;
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return bResult;
+}
+
+sal_Bool SfxObjectShell::WriteThumbnail( sal_Bool bEncrypted,
+ sal_Bool bSigned,
+ sal_Bool bIsTemplate,
+ const uno::Reference< io::XStream >& xStream )
+{
+ sal_Bool bResult = sal_False;
+
+ if ( xStream.is() )
+ {
+ try {
+ uno::Reference< io::XTruncate > xTruncate( xStream->getOutputStream(), uno::UNO_QUERY_THROW );
+ xTruncate->truncate();
+
+ if ( bEncrypted )
+ {
+ sal_uInt16 nResID = GraphicHelper::getThumbnailReplacementIDByFactoryName_Impl(
+ ::rtl::OUString::createFromAscii( GetFactory().GetShortName() ),
+ bIsTemplate );
+ if ( nResID )
+ {
+ if ( !bSigned )
+ {
+ bResult = GraphicHelper::getThumbnailReplacement_Impl( nResID, xStream );
+ }
+ else
+ {
+ // retrieve the bitmap and write a signature bitmap over it
+ SfxResId aResId( nResID );
+ BitmapEx aThumbBitmap( aResId );
+ bResult = GraphicHelper::getSignedThumbnailFormatFromBitmap_Impl( aThumbBitmap, xStream );
+ }
+ }
+ }
+ else
+ {
+ ::boost::shared_ptr<GDIMetaFile> pMetaFile =
+ GetPreviewMetaFile( sal_False );
+ if ( pMetaFile )
+ {
+ bResult = GraphicHelper::getThumbnailFormatFromGDI_Impl(
+ pMetaFile.get(), bSigned, xStream );
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ return bResult;
+}
+
+void SfxObjectShell::UpdateLinks()
+{
+}
+
+sal_Bool SfxObjectShell::QuerySaveSizeExceededModules_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
+{
+ if ( !HasBasic() )
+ return sal_True;
+
+ if ( !pImp->pBasicManager->isValid() )
+ GetBasicManager();
+ uno::Sequence< rtl::OUString > sModules;
+ if ( xHandler.is() )
+ {
+ if( pImp->pBasicManager->LegacyPsswdBinaryLimitExceeded( sModules ) )
+ {
+ ModuleSizeExceeded* pReq = new ModuleSizeExceeded( sModules );
+ uno::Reference< task::XInteractionRequest > xReq( pReq );
+ xHandler->handle( xReq );
+ return pReq->isApprove();
+ }
+ }
+ // No interaction handler, default is to continue to save
+ return sal_True;
+}
+// -----------------------------------------------------------------------------
+uno::Reference< task::XInteractionHandler > SfxObjectShell::getInteractionHandler() const
+{
+ uno::Reference< task::XInteractionHandler > xRet;
+ if ( GetMedium() )
+ xRet = GetMedium()->GetInteractionHandler();
+ return xRet;
+}
diff --git a/sfx2/source/doc/objuno.cxx b/sfx2/source/doc/objuno.cxx
new file mode 100644
index 000000000000..32d50de40d51
--- /dev/null
+++ b/sfx2/source/doc/objuno.cxx
@@ -0,0 +1,1350 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/util/DateTime.hpp>
+#include <com/sun/star/util/Date.hpp>
+#include <com/sun/star/util/Time.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/beans/StringPair.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/document/XImporter.hpp>
+#include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/lang/Locale.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+
+#include <unotools/configmgr.hxx>
+#include <tools/inetdef.hxx>
+#include <unotools/bootstrap.hxx>
+#include <cppuhelper/interfacecontainer.hxx>
+#include <osl/mutex.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <vcl/svapp.hxx>
+#include <vos/mutex.hxx>
+
+#include <tools/errcode.hxx>
+#include <svl/cntwids.hrc>
+#include <comphelper/string.hxx>
+#include <comphelper/sequenceasvector.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <sot/storage.hxx>
+
+#include <sfx2/objuno.hxx>
+#include <sfx2/sfx.hrc>
+
+#include <vector>
+#include <algorithm>
+
+#include "sfx2/sfxresid.hxx"
+#include "doc.hrc"
+
+using namespace ::com::sun::star;
+
+// TODO/REFACTOR: provide service for MS formats
+// TODO/REFACTOR: IsEncrypted is never set nor read
+// Generator is not saved ATM; which value?!
+// Generator handling must be implemented
+// Deprecate "Theme", rework IDL
+// AutoLoadEnabled is deprecated?!
+// Reasonable defaults for DateTime
+// MIMEType readonly?!
+// Announce changes about Theme, Language, Generator, removed entries etc.
+// IsEncrypted is necessary for binary formats!
+// Open: When to call PrepareDocInfoForSave? Currently only called for own formats and HTML/Writer
+// Open: How to load and save EditingTime to MS formats
+// PPT-Export should use SavePropertySet
+
+//=============================================================================
+
+// The number of user defined fields handled by the evil XDocumentInfo
+// interface. There are exactly 4. No more, no less.
+#define FOUR 4
+
+#define PROPERTY_UNBOUND 0
+#define PROPERTY_MAYBEVOID ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
+
+const SfxItemPropertyMapEntry* lcl_GetDocInfoPropertyMap()
+{
+ static SfxItemPropertyMapEntry aDocInfoPropertyMap_Impl[] =
+ {
+ { "Author" , 6 , WID_FROM, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "AutoloadEnabled" , 15, MID_DOCINFO_AUTOLOADENABLED, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
+ { "AutoloadSecs" , 12, MID_DOCINFO_AUTOLOADSECS, &::getCppuType((const sal_Int32*)0), PROPERTY_UNBOUND, 0 },
+ { "AutoloadURL" , 11, MID_DOCINFO_AUTOLOADURL, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "CreationDate" , 12, WID_DATE_CREATED, &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 },
+ { "DefaultTarget" , 13, MID_DOCINFO_DEFAULTTARGET, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "Description" , 11, MID_DOCINFO_DESCRIPTION, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "DocumentStatistic", 17 , MID_DOCINFO_STATISTIC, &::getCppuType((const uno::Sequence< beans::NamedValue >*)0), PROPERTY_UNBOUND, 0 },
+ { "EditingCycles" , 13, MID_DOCINFO_REVISION, &::getCppuType((const sal_Int16*)0), PROPERTY_UNBOUND, 0 },
+ { "EditingDuration" , 15, MID_DOCINFO_EDITTIME, &::getCppuType((const sal_Int32*)0), PROPERTY_UNBOUND, 0 },
+ { "Generator" , 9, SID_APPLICATION, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "Keywords" , 8 , WID_KEYWORDS, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "Language" , 8, MID_DOCINFO_CHARLOCALE, &::getCppuType((const lang::Locale*)0), PROPERTY_UNBOUND, 0 },
+ { "MIMEType" , 8 , WID_CONTENT_TYPE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND | ::com::sun::star::beans::PropertyAttribute::READONLY, 0 },
+ { "ModifiedBy" , 10, MID_DOCINFO_MODIFICATIONAUTHOR, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "ModifyDate" , 10, WID_DATE_MODIFIED, &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 },
+ { "PrintDate" , 9 , MID_DOCINFO_PRINTDATE, &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 },
+ { "PrintedBy" , 9 , MID_DOCINFO_PRINTEDBY, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "Subject" , 7 , MID_DOCINFO_SUBJECT, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "Template" , 8 , MID_DOCINFO_TEMPLATE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "TemplateFileName", 16, SID_TEMPLATE_NAME, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { "TemplateDate" , 12, MID_DOCINFO_TEMPLATEDATE, &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 },
+ { "Title" , 5 , WID_TITLE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ {0,0,0,0,0,0}
+ };
+ return aDocInfoPropertyMap_Impl;
+}
+
+static USHORT aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,
+ 31, 31, 30, 31, 30, 31 };
+
+inline USHORT DaysInMonth( USHORT nMonth, USHORT nYear )
+{
+ if ( nMonth != 2 )
+ return aDaysInMonth[nMonth-1];
+ else
+ {
+ if ( (((nYear % 4) == 0) && ((nYear % 100) != 0)) ||
+ ((nYear % 400) == 0) )
+ return aDaysInMonth[nMonth-1] + 1;
+ else
+ return aDaysInMonth[nMonth-1];
+ }
+}
+
+bool IsValidDateTime( const util::DateTime& rDT )
+{
+ if ( !rDT.Month || (rDT.Month > 12) )
+ return false;
+ if ( !rDT.Day || (rDT.Day > DaysInMonth( rDT.Month, rDT.Year )) )
+ return false;
+ else if ( rDT.Year <= 1582 )
+ {
+ if ( rDT.Year < 1582 )
+ return false;
+ else if ( rDT.Month < 10 )
+ return false;
+ else if ( (rDT.Month == 10) && (rDT.Day < 15) )
+ return false;
+ }
+
+ return true;
+}
+
+struct OUStringHashCode
+{
+ size_t operator()( const ::rtl::OUString& sString ) const
+ {
+ return sString.hashCode();
+ }
+};
+
+struct SfxExtendedItemPropertyMap : public SfxItemPropertyMapEntry
+{
+ ::com::sun::star::uno::Any aValue;
+};
+
+void Copy( const uno::Reference < document::XStandaloneDocumentInfo >& rSource, const uno::Reference < document::XStandaloneDocumentInfo >& rTarget )
+{
+ try
+ {
+ uno::Reference< beans::XPropertySet > xSet( rSource, uno::UNO_QUERY );
+ uno::Reference< beans::XPropertySet > xTarget( rTarget, uno::UNO_QUERY );
+ uno::Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
+ uno::Reference< beans::XPropertyContainer > xContainer( rTarget, uno::UNO_QUERY );
+ uno::Sequence< beans::Property > lProps = xSetInfo->getProperties();
+ const beans::Property* pProps = lProps.getConstArray();
+ sal_Int32 c = lProps.getLength();
+ sal_Int32 i = 0;
+ for (i=0; i<c; ++i)
+ {
+ uno::Any aValue = xSet->getPropertyValue( pProps[i].Name );
+ if ( pProps[i].Attributes & ::com::sun::star::beans::PropertyAttribute::REMOVABLE )
+ // QUESTION: DefaultValue?!
+ xContainer->addProperty( pProps[i].Name, pProps[i].Attributes, aValue );
+ try
+ {
+ // it is possible that the propertysets from XML and binary files differ; we shouldn't break then
+ xTarget->setPropertyValue( pProps[i].Name, aValue );
+ }
+ catch ( uno::Exception& ) {}
+ }
+
+ sal_Int16 nCount = rSource->getUserFieldCount();
+ sal_Int16 nSupportedCount = rTarget->getUserFieldCount();
+ for ( sal_Int16 nInd = 0; nInd < nCount && nInd < nSupportedCount; nInd++ )
+ {
+ ::rtl::OUString aPropName = rSource->getUserFieldName( nInd );
+ rTarget->setUserFieldName( nInd, aPropName );
+ ::rtl::OUString aPropVal = rSource->getUserFieldValue( nInd );
+ rTarget->setUserFieldValue( nInd, aPropVal );
+ }
+ }
+ catch ( uno::Exception& ) {}
+}
+
+class MixedPropertySetInfo : public ::cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertySetInfo >
+{
+ private:
+
+ SfxItemPropertyMap _aPropertyMap;
+ ::rtl::OUString* _pUserKeys;
+ uno::Reference<beans::XPropertySet> _xUDProps;
+
+ public:
+
+ MixedPropertySetInfo( const SfxItemPropertyMapEntry* pFixProps,
+ ::rtl::OUString* pUserKeys,
+ uno::Reference<beans::XPropertySet> xUDProps);
+
+ virtual ~MixedPropertySetInfo();
+
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL getProperties( ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::beans::Property SAL_CALL getPropertyByName( const ::rtl::OUString& aName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
+ virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name ) throw (::com::sun::star::uno::RuntimeException);
+};
+
+//-----------------------------------------------------------------------------
+
+MixedPropertySetInfo::MixedPropertySetInfo(const SfxItemPropertyMapEntry* pFixProps,
+ ::rtl::OUString* pUserKeys,
+ uno::Reference<beans::XPropertySet> xUDProps)
+ : _aPropertyMap( pFixProps )
+ , _pUserKeys(pUserKeys)
+ , _xUDProps(xUDProps)
+{
+}
+
+//-----------------------------------------------------------------------------
+
+MixedPropertySetInfo::~MixedPropertySetInfo()
+{
+}
+
+//-----------------------------------------------------------------------------
+
+::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL MixedPropertySetInfo::getProperties()
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ ::comphelper::SequenceAsVector< ::com::sun::star::beans::Property > lProps;
+
+ // copy "fix" props
+ //todo: os: this ugly thing should be replaced
+ const SfxItemPropertyMapEntry* pFixProp = lcl_GetDocInfoPropertyMap();
+
+ while(pFixProp && pFixProp->pName)
+ {
+ ::com::sun::star::beans::Property aProp;
+
+ aProp.Name = ::rtl::OUString::createFromAscii(pFixProp->pName);
+ aProp.Handle = pFixProp->nWID;
+ aProp.Type = *(pFixProp->pType);
+ aProp.Attributes = (sal_Int16)(pFixProp->nFlags);
+
+ lProps.push_back(aProp);
+ ++pFixProp;
+ }
+
+ // copy "dynamic" props
+
+ // NB: this is really ugly:
+ // The returned properties must _not_ include the 4 user-defined fields!
+ // These are _not_ properties of the XDocumentInfo interface.
+ // Some things rely on this, e.g. Copy would break otherwise.
+ // This will have interesting consequences if someone expects to insert
+ // a property with the same name as an user-defined key, but nobody
+ // sane does that.
+ uno::Sequence<beans::Property> udProps =
+ _xUDProps->getPropertySetInfo()->getProperties();
+ for (sal_Int32 i = 0; i < udProps.getLength(); ++i) {
+ if (std::find(_pUserKeys, _pUserKeys+FOUR, udProps[i].Name)
+ == _pUserKeys+FOUR) {
+ // #i100027#: handles from udProps are not valid here
+ udProps[i].Handle = -1;
+ lProps.push_back(udProps[i]);
+ }
+ }
+
+ return lProps.getAsConstList();
+}
+
+//-----------------------------------------------------------------------------
+
+::com::sun::star::beans::Property SAL_CALL MixedPropertySetInfo::getPropertyByName(
+ const ::rtl::OUString& sName )
+ throw(::com::sun::star::beans::UnknownPropertyException,
+ ::com::sun::star::uno::RuntimeException )
+{
+ ::com::sun::star::beans::Property aProp;
+
+ // search it as "fix" prop
+ if( _aPropertyMap.hasPropertyByName( sName ) )
+ return _aPropertyMap.getPropertyByName( sName );
+ else
+ // search it as "dynamic" prop
+ return _xUDProps->getPropertySetInfo()->getPropertyByName(sName);
+}
+
+//-----------------------------------------------------------------------------
+
+::sal_Bool SAL_CALL MixedPropertySetInfo::hasPropertyByName(const ::rtl::OUString& sName)
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ return _aPropertyMap.hasPropertyByName( sName ) ? // "fix" prop?
+ sal_True :
+ _xUDProps->getPropertySetInfo()->hasPropertyByName(sName); // "dynamic" prop?
+}
+
+//-----------------------------------------------------------------------------
+
+struct SfxDocumentInfoObject_Impl
+{
+ ::osl::Mutex _aMutex;
+ ::cppu::OInterfaceContainerHelper _aDisposeContainer;
+
+ sal_Bool bDisposed;
+
+ // this contains the names of the 4 user defined properties
+ // which are accessible via the evil XDocumentInfo interface
+ ::rtl::OUString m_UserDefined[FOUR];
+
+ // the actual contents
+ uno::Reference<document::XDocumentProperties> m_xDocProps;
+ SfxItemPropertyMap m_aPropertyMap;
+
+ SfxDocumentInfoObject_Impl()
+ : _aDisposeContainer( _aMutex )
+ , bDisposed(sal_False)
+ , m_xDocProps()
+ , m_aPropertyMap( lcl_GetDocInfoPropertyMap() )
+ {
+ // the number of user fields is not changeable from the outside
+ // we can't set it too high because every name/value pair will be written to the file (even if empty)
+ // currently our dialog has only 4 user keys so 4 is still a reasonable number
+ }
+
+ /// the initialization function
+ void Reset(uno::Reference<document::XDocumentProperties> xDocProps, ::rtl::OUString* pUserDefined = 0);
+};
+
+void SfxDocumentInfoObject_Impl::Reset(uno::Reference<document::XDocumentProperties> xDocProps, ::rtl::OUString* pUserDefined)
+{
+ if (pUserDefined == 0) {
+ // NB: this is an ugly hack; the "Properties" ui dialog displays
+ // exactly 4 user-defined fields and expects these to be available
+ // (should be redesigned), but I do not want to do this in
+ // DocumentProperties; do it here instead
+ uno::Reference<beans::XPropertyAccess> xPropAccess(
+ xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+ uno::Reference<beans::XPropertyContainer> xPropContainer(
+ xPropAccess, uno::UNO_QUERY_THROW);
+ uno::Sequence< beans::PropertyValue >
+ props = xPropAccess->getPropertyValues();
+ sal_Int32 oldLength = props.getLength();
+ if (oldLength < FOUR) {
+ std::vector< ::rtl::OUString > names;
+ for (sal_Int32 i = 0; i < oldLength; ++i) {
+ names.push_back(props[i].Name);
+ }
+ const ::rtl::OUString sInfo(
+ String( SfxResId( STR_DOCINFO_INFOFIELD ) ));
+ for (sal_Int32 i = oldLength; i < FOUR; ++i) {
+ ::rtl::OUString sName(sInfo);
+ sal_Int32 idx = sName.indexOfAsciiL("%1", 2);
+ ::rtl::OUString name = (idx > 0)
+ ? sName.replaceAt(idx, 2, ::rtl::OUString::valueOf(i+1))
+ : sName + ::rtl::OUString::valueOf(i+1);
+ while (std::find(names.begin(), names.end(), name)
+ != names.end()) {
+ name += ::rtl::OUString::createFromAscii("'");
+ }
+ // FIXME there is a race condition here
+ try {
+ xPropContainer->addProperty(name,
+ beans::PropertyAttribute::REMOVEABLE,
+ uno::makeAny(::rtl::OUString::createFromAscii("")));
+ } catch (uno::RuntimeException) {
+ throw;
+ } catch (uno::Exception) {
+ // ignore
+ }
+ }
+ }
+ props = xPropAccess->getPropertyValues();
+ for (sal_Int32 i = 0; i < FOUR; ++i) {
+ m_UserDefined[i] = props[i].Name;
+ }
+ } else {
+ std::copy(pUserDefined, pUserDefined+FOUR, m_UserDefined);
+ }
+ m_xDocProps = xDocProps;
+}
+
+//-----------------------------------------------------------------------------
+
+SfxDocumentInfoObject::SfxDocumentInfoObject()
+ : _pImp( new SfxDocumentInfoObject_Impl() )
+{
+}
+
+//-----------------------------------------------------------------------------
+
+SfxDocumentInfoObject::~SfxDocumentInfoObject()
+{
+ delete _pImp;
+}
+
+//-----------------------------------------------------------------------------
+
+// ::com::sun::star::lang::XInitialization:
+void SAL_CALL
+SfxDocumentInfoObject::initialize(const uno::Sequence< uno::Any > & aArguments)
+ throw (uno::RuntimeException, uno::Exception)
+{
+ if (aArguments.getLength() >= 1) {
+ uno::Any any = aArguments[0];
+ uno::Reference<document::XDocumentProperties> xDoc;
+ if (!(any >>= xDoc) || !xDoc.is()) throw lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentInfoObject::initialize: no XDocumentProperties given"),
+ *this, 0);
+ _pImp->Reset(xDoc);
+ } else {
+ throw lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii(
+ "SfxDocumentInfoObject::initialize: no argument given"),
+ *this, 0);
+ }
+}
+
+// ::com::sun::star::util::XCloneable:
+uno::Reference<util::XCloneable> SAL_CALL
+SfxDocumentInfoObject::createClone() throw (uno::RuntimeException)
+{
+ SfxDocumentInfoObject *pNew = new SfxDocumentInfoObject;
+ uno::Reference< util::XCloneable >
+ xCloneable(_pImp->m_xDocProps, uno::UNO_QUERY_THROW);
+ uno::Reference<document::XDocumentProperties> xDocProps(
+ xCloneable->createClone(), uno::UNO_QUERY_THROW);
+ pNew->_pImp->Reset(xDocProps, _pImp->m_UserDefined);
+ return pNew;
+}
+
+// ::com::sun::star::document::XDocumentProperties:
+uno::Reference< document::XDocumentProperties > SAL_CALL
+SfxDocumentInfoObject::getDocumentProperties()
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ return _pImp->m_xDocProps;
+}
+
+//-----------------------------------------------------------------------------
+
+const SfxDocumentInfoObject& SfxDocumentInfoObject::operator=( const SfxDocumentInfoObject & rOther)
+{
+ uno::Reference< util::XCloneable >
+ xCloneable(rOther._pImp->m_xDocProps, uno::UNO_QUERY_THROW);
+ uno::Reference<document::XDocumentProperties> xDocProps(
+ xCloneable->createClone(), uno::UNO_QUERY_THROW);
+ _pImp->Reset(xDocProps, rOther._pImp->m_UserDefined);
+ return *this;
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocumentInfoObject::dispose() throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::com::sun::star::lang::EventObject aEvent( (::cppu::OWeakObject *)this );
+ _pImp->_aDisposeContainer.disposeAndClear( aEvent );
+ ::osl::MutexGuard aGuard( _pImp->_aMutex );
+ _pImp->m_xDocProps = 0;
+ // NB: do not call m_xDocProps->dispose(), there could be other refs
+ _pImp->bDisposed = sal_True;
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocumentInfoObject::addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException )
+{
+ _pImp->_aDisposeContainer.addInterface( aListener );
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocumentInfoObject::removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException )
+{
+ _pImp->_aDisposeContainer.removeInterface( aListener );
+}
+//-----------------------------------------------------------------------------
+
+::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL SfxDocumentInfoObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( _pImp->_aMutex );
+
+ uno::Reference<beans::XPropertySet> xPropSet(
+ _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+ MixedPropertySetInfo* pInfo = new MixedPropertySetInfo( lcl_GetDocInfoPropertyMap(), _pImp->m_UserDefined, xPropSet);
+ uno::Reference< beans::XPropertySetInfo > xInfo(
+ static_cast< beans::XPropertySetInfo* >(pInfo), uno::UNO_QUERY_THROW);
+ return xInfo;
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocumentInfoObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aValue) throw (
+ uno::RuntimeException, beans::UnknownPropertyException,
+ beans::PropertyVetoException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ const SfxItemPropertySimpleEntry* pEntry = _pImp->m_aPropertyMap.getByName( aPropertyName );
+ // fix prop!
+ if ( pEntry )
+ setFastPropertyValue( pEntry->nWID, aValue );
+ else
+ // dynamic prop!
+ {
+ uno::Reference<beans::XPropertySet> xPropSet(
+ _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+ return xPropSet->setPropertyValue(aPropertyName, aValue);
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+uno::Any SAL_CALL SfxDocumentInfoObject::getPropertyValue(const ::rtl::OUString& aPropertyName) throw(
+ uno::RuntimeException, beans::UnknownPropertyException,
+ lang::WrappedTargetException)
+{
+ const SfxItemPropertySimpleEntry* pEntry = _pImp->m_aPropertyMap.getByName( aPropertyName );
+ // fix prop!
+ if ( pEntry )
+ return getFastPropertyValue( pEntry->nWID );
+ else
+ // dynamic prop!
+ {
+ uno::Reference<beans::XPropertySet> xPropSet(
+ _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+ return xPropSet->getPropertyValue(aPropertyName);
+ }
+}
+
+sal_Bool SAL_CALL SfxDocumentInfoObject::isModified() throw(::com::sun::star::uno::RuntimeException)
+{
+ uno::Reference<util::XModifiable> xModif(
+ _pImp->m_xDocProps, uno::UNO_QUERY_THROW);
+ return xModif->isModified();
+}
+
+void SAL_CALL SfxDocumentInfoObject::setModified( sal_Bool bModified )
+ throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException)
+{
+ uno::Reference<util::XModifiable> xModif(
+ _pImp->m_xDocProps, uno::UNO_QUERY_THROW);
+ return xModif->setModified(bModified);
+}
+
+void SAL_CALL SfxDocumentInfoObject::addModifyListener( const uno::Reference< util::XModifyListener >& xListener) throw( uno::RuntimeException )
+{
+ uno::Reference<util::XModifiable> xModif(
+ _pImp->m_xDocProps, uno::UNO_QUERY_THROW);
+ return xModif->addModifyListener(xListener);
+}
+
+void SAL_CALL SfxDocumentInfoObject::removeModifyListener( const uno::Reference< util::XModifyListener >& xListener) throw( uno::RuntimeException )
+{
+ uno::Reference<util::XModifiable> xModif(
+ _pImp->m_xDocProps, uno::UNO_QUERY_THROW);
+ return xModif->removeModifyListener(xListener);
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocumentInfoObject::addPropertyChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener > & ) throw(
+ uno::RuntimeException, beans::UnknownPropertyException,
+ lang::WrappedTargetException)
+{}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocumentInfoObject::removePropertyChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener > & ) throw(
+ uno::RuntimeException, beans::UnknownPropertyException,
+ lang::WrappedTargetException)
+{}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocumentInfoObject::addVetoableChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener > & ) throw(
+ uno::RuntimeException, beans::UnknownPropertyException,
+ lang::WrappedTargetException)
+{}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocumentInfoObject::removeVetoableChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener > & ) throw(
+ uno::RuntimeException, beans::UnknownPropertyException,
+ lang::WrappedTargetException)
+{}
+
+uno::Sequence< beans::PropertyValue > SAL_CALL SfxDocumentInfoObject::getPropertyValues( void ) throw( uno::RuntimeException )
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = getPropertySetInfo();
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps = xInfo->getProperties();
+
+ const ::com::sun::star::beans::Property* pProps = aProps.getConstArray();
+ sal_uInt32 nCount = aProps.getLength();
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >aSeq( nCount );
+ ::com::sun::star::beans::PropertyValue* pValues = aSeq.getArray();
+
+ for ( sal_uInt32 n = 0; n < nCount; ++n )
+ {
+ ::com::sun::star::beans::PropertyValue& rCurrValue = pValues[n];
+ const ::com::sun::star::beans::Property& rCurrProp = pProps[n];
+
+ rCurrValue.Name = rCurrProp.Name;
+ rCurrValue.Handle = rCurrProp.Handle;
+ rCurrValue.Value = getPropertyValue( rCurrProp.Name );
+ }
+
+ return aSeq;
+}
+
+void SAL_CALL SfxDocumentInfoObject::setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps )
+ throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException )
+{
+ const ::com::sun::star::beans::PropertyValue* pProps = aProps.getConstArray();
+ sal_uInt32 nCount = aProps.getLength();
+
+ for ( sal_uInt32 n = 0; n < nCount; ++n )
+ {
+ const ::com::sun::star::beans::PropertyValue& rProp = pProps[n];
+ setPropertyValue( rProp.Name, rProp.Value );
+ }
+}
+
+void SAL_CALL SfxDocumentInfoObject::addProperty(const ::rtl::OUString& sName ,
+ sal_Int16 nAttributes ,
+ const ::com::sun::star::uno::Any& aDefaultValue)
+ throw(::com::sun::star::beans::PropertyExistException ,
+ ::com::sun::star::beans::IllegalTypeException ,
+ ::com::sun::star::lang::IllegalArgumentException,
+ ::com::sun::star::uno::RuntimeException )
+{
+ // clash with "fix" properties ?
+ sal_Bool bFixProp = _pImp->m_aPropertyMap.getByName( sName ) != 0;
+ if ( bFixProp )
+ {
+ ::rtl::OUStringBuffer sMsg(256);
+ sMsg.appendAscii("The property \"" );
+ sMsg.append (sName );
+ sMsg.appendAscii("\" " );
+ if ( bFixProp )
+ sMsg.appendAscii(" already exists as a fix property. Please have a look into the IDL documentation of the DocumentInfo service.");
+
+ throw ::com::sun::star::beans::PropertyExistException(
+ sMsg.makeStringAndClear(),
+ static_cast< ::cppu::OWeakObject* >(this));
+ }
+
+ uno::Reference<beans::XPropertyContainer> xPropSet(
+ _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+ return xPropSet->addProperty(sName, nAttributes, aDefaultValue);
+}
+
+void SAL_CALL SfxDocumentInfoObject::removeProperty(const ::rtl::OUString& sName)
+ throw(::com::sun::star::beans::UnknownPropertyException,
+ ::com::sun::star::beans::NotRemoveableException ,
+ ::com::sun::star::uno::RuntimeException )
+{
+ // clash with "fix" properties ?
+ sal_Bool bFixProp = _pImp->m_aPropertyMap.getByName( sName ) != 0;
+ if ( bFixProp )
+ {
+ ::rtl::OUStringBuffer sMsg(256);
+ sMsg.appendAscii("The property \"" );
+ sMsg.append (sName );
+ sMsg.appendAscii("\" cant be removed. Its a fix property of the DocumentInfo service.");
+
+ throw ::com::sun::star::beans::NotRemoveableException(
+ sMsg.makeStringAndClear(),
+ static_cast< ::cppu::OWeakObject* >(this));
+ }
+
+ uno::Reference<beans::XPropertyContainer> xPropSet(
+ _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+ return xPropSet->removeProperty(sName);
+}
+
+BOOL equalsDateTime( const util::DateTime& D1, const util::DateTime& D2 )
+{
+ return D1.HundredthSeconds == D2.HundredthSeconds &&
+ D1.Seconds == D2.Seconds &&
+ D1.Minutes == D2.Minutes &&
+ D1.Hours == D2.Hours &&
+ D1.Day == D2.Day &&
+ D1.Month == D2.Month &&
+ D1.Year == D2.Year;
+}
+
+void SAL_CALL SfxDocumentInfoObject::setFastPropertyValue(sal_Int32 nHandle, const ::com::sun::star::uno::Any& aValue) throw(
+ uno::RuntimeException, beans::UnknownPropertyException,
+ beans::PropertyVetoException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ // Attention: Only fix properties should be provided by this method.
+ // Dynamic properties has no handle in real ... because it cant be used inside multithreaded environments :-)
+
+ ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex );
+
+ if ( aValue.getValueType() == ::getCppuType((const ::rtl::OUString*)0) )
+ {
+ ::rtl::OUString sTemp ;
+ aValue >>= sTemp ;
+ switch ( nHandle )
+ {
+ case SID_APPLICATION :
+ _pImp->m_xDocProps->setGenerator(sTemp);
+ break;
+ case WID_FROM :
+ {
+ // QUESTION: do we still need this?
+ /*
+ // String aStrVal( sTemp );
+ if ( aStrVal.Len() > TIMESTAMP_MAXLENGTH )
+ {
+ SvAddressParser aParser( aStrVal );
+ if ( aParser.Count() > 0 )
+ {
+ String aEmail = aParser.GetEmailAddress(0);
+ String aRealname = aParser.GetRealName(0);
+
+ if ( aRealname.Len() <= TIMESTAMP_MAXLENGTH )
+ aStrVal = aRealname;
+ else if ( aEmail.Len() <= TIMESTAMP_MAXLENGTH )
+ aStrVal = aEmail;
+ }
+ } */
+
+ if ( _pImp->m_xDocProps->getAuthor() != sTemp )
+ _pImp->m_xDocProps->setAuthor(sTemp);
+ break;
+ }
+ case MID_DOCINFO_PRINTEDBY:
+ if ( _pImp->m_xDocProps->getPrintedBy() != sTemp )
+ _pImp->m_xDocProps->setPrintedBy(sTemp);
+ break;
+ case MID_DOCINFO_MODIFICATIONAUTHOR:
+ if ( _pImp->m_xDocProps->getModifiedBy() != sTemp )
+ _pImp->m_xDocProps->setModifiedBy(sTemp);
+ break;
+ case WID_TITLE :
+ {
+ if ( _pImp->m_xDocProps->getTitle() != sTemp )
+ _pImp->m_xDocProps->setTitle(sTemp);
+ break;
+ }
+ case MID_DOCINFO_SUBJECT :
+ if ( _pImp->m_xDocProps->getSubject() != sTemp )
+ _pImp->m_xDocProps->setSubject(sTemp);
+ break;
+ case WID_KEYWORDS :
+ {
+ _pImp->m_xDocProps->setKeywords(
+ ::comphelper::string::convertCommaSeparated(sTemp));
+ }
+ break;
+ case MID_DOCINFO_TEMPLATE:
+ if ( _pImp->m_xDocProps->getTemplateName() != sTemp )
+ _pImp->m_xDocProps->setTemplateName(sTemp);
+ break;
+ case SID_TEMPLATE_NAME:
+ if ( _pImp->m_xDocProps->getTemplateURL() != sTemp )
+ _pImp->m_xDocProps->setTemplateURL(sTemp);
+ break;
+ case MID_DOCINFO_DESCRIPTION:
+ if ( _pImp->m_xDocProps->getDescription() != sTemp )
+ _pImp->m_xDocProps->setDescription(sTemp);
+ break;
+ case MID_DOCINFO_AUTOLOADURL:
+ if ( _pImp->m_xDocProps->getAutoloadURL() != sTemp )
+ _pImp->m_xDocProps->setAutoloadURL(sTemp);
+ break;
+ case MID_DOCINFO_DEFAULTTARGET:
+ if ( _pImp->m_xDocProps->getDefaultTarget() != sTemp )
+ _pImp->m_xDocProps->setDefaultTarget(sTemp);
+ break;
+// case WID_CONTENT_TYPE : // this is readonly!
+ default:
+ break;
+ }
+ }
+ else if ( aValue.getValueType() == ::getCppuType((const ::com::sun::star::util::DateTime*)0) )
+ {
+ com::sun::star::util::DateTime aTemp;
+ aValue >>= aTemp ;
+ switch ( nHandle )
+ {
+ case WID_DATE_CREATED :
+ {
+ if ( !equalsDateTime(_pImp->m_xDocProps->getCreationDate(), aTemp ) )
+ {
+ _pImp->m_xDocProps->setCreationDate(aTemp);
+ }
+ break;
+ }
+ case WID_DATE_MODIFIED :
+ {
+ if ( !equalsDateTime(_pImp->m_xDocProps->getModificationDate(), aTemp ) )
+ {
+ _pImp->m_xDocProps->setModificationDate(aTemp);
+ }
+ break;
+ }
+ case MID_DOCINFO_PRINTDATE :
+ {
+ if ( !equalsDateTime(_pImp->m_xDocProps->getPrintDate(), aTemp ) )
+ {
+ _pImp->m_xDocProps->setPrintDate(aTemp);
+ }
+ break;
+ }
+ case MID_DOCINFO_TEMPLATEDATE :
+ {
+ if ( !equalsDateTime(_pImp->m_xDocProps->getTemplateDate(), aTemp ) )
+ {
+ _pImp->m_xDocProps->setTemplateDate(aTemp);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ else if ( aValue.getValueType() == ::getBooleanCppuType() )
+ {
+ sal_Bool bBoolVal = false;
+ aValue >>= bBoolVal ;
+ switch ( nHandle )
+ {
+ case MID_DOCINFO_AUTOLOADENABLED:
+ // NB: this property does not exist any more
+ // it is emulated as enabled iff delay > 0
+ if ( bBoolVal && (0 == _pImp->m_xDocProps->getAutoloadSecs()) ) {
+ _pImp->m_xDocProps->setAutoloadSecs(60); // default
+ } else if ( !bBoolVal && (0 != _pImp->m_xDocProps->getAutoloadSecs()) ) {
+ _pImp->m_xDocProps->setAutoloadSecs(0);
+ _pImp->m_xDocProps->setAutoloadURL(::rtl::OUString::createFromAscii(""));
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ else if ( aValue.getValueType() == ::getCppuType((const sal_Int32*)0) )
+ {
+ sal_Int32 nIntVal = 0;
+ aValue >>= nIntVal ;
+ switch ( nHandle )
+ {
+ case MID_DOCINFO_AUTOLOADSECS:
+ if ( nIntVal != _pImp->m_xDocProps->getAutoloadSecs())
+ _pImp->m_xDocProps->setAutoloadSecs(nIntVal);
+ break;
+ case MID_DOCINFO_EDITTIME:
+ if ( nIntVal != _pImp->m_xDocProps->getEditingDuration())
+ _pImp->m_xDocProps->setEditingDuration(nIntVal);
+ break;
+ default:
+ break;
+ }
+ }
+ else if ( aValue.getValueType() == ::getCppuType((const sal_Int16*)0) )
+ {
+ short nIntVal = 0;
+ aValue >>= nIntVal ;
+ switch ( nHandle )
+ {
+ case MID_DOCINFO_REVISION:
+ if ( nIntVal != _pImp->m_xDocProps->getEditingCycles())
+ _pImp->m_xDocProps->setEditingCycles(nIntVal);
+ break;
+ default:
+ break;
+ }
+ }
+ else if ( aValue.getValueType() == ::getCppuType((const uno::Sequence< beans::NamedValue >*)0) )
+ {
+ if ( nHandle == MID_DOCINFO_STATISTIC )
+ {
+ uno::Sequence < beans::NamedValue > aData;
+ aValue >>= aData;
+ {
+ _pImp->m_xDocProps->setDocumentStatistics(aData);
+ }
+ }
+ }
+ else if ( aValue.getValueType() == ::getCppuType((const lang::Locale*)0) )
+ {
+ if ( nHandle == MID_DOCINFO_CHARLOCALE )
+ {
+ lang::Locale aLocale;
+ aValue >>= aLocale;
+ lang::Locale oldLocale = _pImp->m_xDocProps->getLanguage();
+ if ( aLocale.Language != oldLocale.Language ||
+ aLocale.Country != oldLocale.Country ||
+ aLocale.Variant != oldLocale.Variant )
+ {
+ _pImp->m_xDocProps->setLanguage(aLocale);
+ }
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+::com::sun::star::uno::Any SAL_CALL SfxDocumentInfoObject::getFastPropertyValue(sal_Int32 nHandle) throw(
+ uno::RuntimeException, beans::UnknownPropertyException,
+ lang::WrappedTargetException)
+{
+ // Attention: Only fix properties should be provided by this method.
+ // Dynamic properties has no handle in real ... because it cant be used inside multithreaded environments :-)
+
+ ::osl::MutexGuard aGuard( _pImp->_aMutex );
+ ::com::sun::star::uno::Any aValue;
+ switch ( nHandle )
+ {
+ case SID_APPLICATION :
+ aValue <<= _pImp->m_xDocProps->getGenerator();
+ break;
+ case WID_CONTENT_TYPE :
+// FIXME this is not available anymore
+ aValue <<= ::rtl::OUString();
+ break;
+ case MID_DOCINFO_REVISION :
+ aValue <<= _pImp->m_xDocProps->getEditingCycles();
+ break;
+ case MID_DOCINFO_EDITTIME :
+ aValue <<= _pImp->m_xDocProps->getEditingDuration();
+ break;
+ case WID_FROM :
+ aValue <<= _pImp->m_xDocProps->getAuthor();
+ break;
+ case WID_DATE_CREATED :
+ if ( IsValidDateTime( _pImp->m_xDocProps->getCreationDate() ) )
+ aValue <<= _pImp->m_xDocProps->getCreationDate();
+ break;
+ case WID_TITLE :
+ aValue <<= _pImp->m_xDocProps->getTitle();
+ break;
+ case MID_DOCINFO_SUBJECT:
+ aValue <<= _pImp->m_xDocProps->getSubject();
+ break;
+ case MID_DOCINFO_MODIFICATIONAUTHOR:
+ aValue <<= _pImp->m_xDocProps->getModifiedBy();
+ break;
+ case WID_DATE_MODIFIED :
+ if ( IsValidDateTime( _pImp->m_xDocProps->getModificationDate() ) )
+ aValue <<= _pImp->m_xDocProps->getModificationDate();
+ break;
+ case MID_DOCINFO_PRINTEDBY:
+ aValue <<= _pImp->m_xDocProps->getPrintedBy();
+ break;
+ case MID_DOCINFO_PRINTDATE:
+ if ( IsValidDateTime( _pImp->m_xDocProps->getPrintDate() ) )
+ aValue <<= _pImp->m_xDocProps->getPrintDate();
+ break;
+ case WID_KEYWORDS :
+ aValue <<= ::comphelper::string::convertCommaSeparated(
+ _pImp->m_xDocProps->getKeywords());
+ break;
+ case MID_DOCINFO_DESCRIPTION:
+ aValue <<= _pImp->m_xDocProps->getDescription();
+ break;
+ case MID_DOCINFO_TEMPLATE:
+ aValue <<= _pImp->m_xDocProps->getTemplateName();
+ break;
+ case SID_TEMPLATE_NAME:
+ aValue <<= _pImp->m_xDocProps->getTemplateURL();
+ break;
+ case MID_DOCINFO_TEMPLATEDATE:
+ if ( IsValidDateTime( _pImp->m_xDocProps->getTemplateDate() ) )
+ aValue <<= _pImp->m_xDocProps->getTemplateDate();
+ break;
+ case MID_DOCINFO_AUTOLOADENABLED:
+ aValue <<= static_cast<sal_Bool>
+ ( (_pImp->m_xDocProps->getAutoloadSecs() != 0)
+ || !(_pImp->m_xDocProps->getAutoloadURL().equalsAscii("")));
+ break;
+ case MID_DOCINFO_AUTOLOADURL:
+ aValue <<= _pImp->m_xDocProps->getAutoloadURL();
+ break;
+ case MID_DOCINFO_AUTOLOADSECS:
+ aValue <<= _pImp->m_xDocProps->getAutoloadSecs();
+ break;
+ case MID_DOCINFO_DEFAULTTARGET:
+ aValue <<= _pImp->m_xDocProps->getDefaultTarget();
+ break;
+ case MID_DOCINFO_STATISTIC:
+ aValue <<= _pImp->m_xDocProps->getDocumentStatistics();
+ break;
+ case MID_DOCINFO_CHARLOCALE:
+ aValue <<= _pImp->m_xDocProps->getLanguage();
+ break;
+ default:
+ aValue <<= ::rtl::OUString();
+ break;
+ }
+
+ return aValue;
+}
+
+//-----------------------------------------------------------------------------
+
+sal_Int16 SAL_CALL SfxDocumentInfoObject::getUserFieldCount() throw( ::com::sun::star::uno::RuntimeException )
+{
+// uno::Reference<beans::XPropertyAccess> xPropSet(
+// _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+// return xPropSet->getPropertyValues().getLength();
+ return FOUR;
+}
+
+//-----------------------------------------------------------------------------
+
+::rtl::OUString SAL_CALL SfxDocumentInfoObject::getUserFieldName(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( _pImp->_aMutex );
+ if (nIndex < FOUR)
+ return _pImp->m_UserDefined[nIndex];
+ else
+ return ::rtl::OUString();
+}
+
+//-----------------------------------------------------------------------------
+
+::rtl::OUString SAL_CALL SfxDocumentInfoObject::getUserFieldValue(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( _pImp->_aMutex );
+ if (nIndex < FOUR) {
+ ::rtl::OUString name = _pImp->m_UserDefined[nIndex];
+ uno::Reference<beans::XPropertySet> xPropSet(
+ _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+ ::rtl::OUString val;
+ try {
+ xPropSet->getPropertyValue(name) >>= val;
+ return val;
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception &) {
+ return ::rtl::OUString(); // ignore
+ }
+ } else
+ return ::rtl::OUString();
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocumentInfoObject::setUserFieldName(sal_Int16 nIndex, const ::rtl::OUString& aName ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex );
+ if (nIndex < FOUR) // yes, four!
+ {
+ // FIXME this is full of race conditions because the PropertyBag
+ // can be accessed from clients of the DocumentProperties!
+ ::rtl::OUString name = _pImp->m_UserDefined[nIndex];
+ if (name != aName) {
+ uno::Reference<beans::XPropertySet> xPropSet(
+ _pImp->m_xDocProps->getUserDefinedProperties(),
+ uno::UNO_QUERY_THROW);
+ uno::Reference<beans::XPropertyContainer> xPropContainer(
+ _pImp->m_xDocProps->getUserDefinedProperties(),
+ uno::UNO_QUERY_THROW);
+ uno::Any value;
+ try {
+ value = xPropSet->getPropertyValue(name);
+ xPropContainer->removeProperty(name);
+ xPropContainer->addProperty(aName,
+ beans::PropertyAttribute::REMOVEABLE, value);
+ _pImp->m_UserDefined[nIndex] = aName;
+ } catch (beans::UnknownPropertyException) {
+ try {
+ xPropContainer->addProperty(aName,
+ beans::PropertyAttribute::REMOVEABLE,
+ uno::makeAny(::rtl::OUString::createFromAscii("")));
+ _pImp->m_UserDefined[nIndex] = aName;
+ } catch (beans::PropertyExistException) {
+ _pImp->m_UserDefined[nIndex] = aName;
+ // ignore
+ }
+ } catch (beans::PropertyExistException) {
+ try {
+ xPropContainer->addProperty(name,
+ beans::PropertyAttribute::REMOVEABLE, value);
+ } catch (beans::PropertyExistException) {
+ // bugger...
+ }
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception &) {
+ // ignore everything else; xPropSet _may_ be corrupted
+ }
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxDocumentInfoObject::setUserFieldValue( sal_Int16 nIndex, const ::rtl::OUString& aValue ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex );
+ if (nIndex < FOUR) // yes, four!
+ {
+ ::rtl::OUString name = _pImp->m_UserDefined[nIndex];
+ uno::Reference<beans::XPropertySet> xPropSet(
+ _pImp->m_xDocProps->getUserDefinedProperties(),
+ uno::UNO_QUERY_THROW);
+ uno::Reference<beans::XPropertyContainer> xPropContainer(
+ _pImp->m_xDocProps->getUserDefinedProperties(),
+ uno::UNO_QUERY_THROW);
+ uno::Any aAny;
+ aAny <<= aValue;
+ try {
+ uno::Any value = xPropSet->getPropertyValue(name);
+ if (value != aAny) {
+ xPropSet->setPropertyValue(name, aAny);
+ }
+ } catch (beans::UnknownPropertyException) {
+ try {
+ // someone removed it, add it back again
+ xPropContainer->addProperty(name,
+ beans::PropertyAttribute::REMOVEABLE, aAny);
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception &) {
+ // ignore everything else
+ }
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception &) {
+ // ignore everything else
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+SFX_IMPL_XINTERFACE_2( SfxStandaloneDocumentInfoObject, SfxDocumentInfoObject, ::com::sun::star::lang::XServiceInfo, ::com::sun::star::document::XStandaloneDocumentInfo )
+SFX_IMPL_XTYPEPROVIDER_10( SfxStandaloneDocumentInfoObject, ::com::sun::star::document::XDocumentInfo, ::com::sun::star::lang::XComponent,
+ ::com::sun::star::beans::XPropertySet, ::com::sun::star::beans::XFastPropertySet, ::com::sun::star::beans::XPropertyAccess,
+ ::com::sun::star::beans::XPropertyContainer, ::com::sun::star::util::XModifiable, ::com::sun::star::util::XModifyBroadcaster,
+ ::com::sun::star::document::XStandaloneDocumentInfo, ::com::sun::star::lang::XServiceInfo )
+
+SFX_IMPL_XSERVICEINFO( SfxStandaloneDocumentInfoObject, "com.sun.star.document.StandaloneDocumentInfo", "com.sun.star.comp.sfx2.StandaloneDocumentInfo" )
+SFX_IMPL_SINGLEFACTORY( SfxStandaloneDocumentInfoObject )
+
+SfxStandaloneDocumentInfoObject::SfxStandaloneDocumentInfoObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory )
+ : SfxDocumentInfoObject()
+ , _xFactory( xFactory )
+{
+ uno::Reference< lang::XInitialization > xDocProps(
+ _xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.document.DocumentProperties"))), uno::UNO_QUERY_THROW);
+// xDocProps->initialize(uno::Sequence<uno::Any>());
+ uno::Any a;
+ a <<= xDocProps;
+ uno::Sequence<uno::Any> args(1);
+ args[0] = a;
+ initialize(args);
+}
+
+//-----------------------------------------------------------------------------
+
+SfxStandaloneDocumentInfoObject::~SfxStandaloneDocumentInfoObject()
+{
+}
+
+//-----------------------------------------------------------------------------
+
+uno::Reference< embed::XStorage > GetStorage_Impl( const ::rtl::OUString& rName, sal_Bool bWrite, uno::Reference < lang::XMultiServiceFactory >& xFactory )
+{
+ // catch unexpected exceptions under solaris
+ // Client code checks the returned reference but is not interested on error details.
+ try
+ {
+ ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
+ return ::comphelper::OStorageHelper::GetStorageFromURL(
+ rName,
+ bWrite ? embed::ElementModes::READWRITE : embed::ElementModes::READ,
+ xFactory );
+ }
+ catch(const uno::Exception&)
+ {}
+
+ return uno::Reference< embed::XStorage >();
+}
+
+//-----------------------------------------------------------------------------
+
+sal_Int16 SAL_CALL SfxStandaloneDocumentInfoObject::getUserFieldCount() throw( ::com::sun::star::uno::RuntimeException )
+{
+ return SfxDocumentInfoObject::getUserFieldCount();
+}
+
+//-----------------------------------------------------------------------------
+
+::rtl::OUString SAL_CALL SfxStandaloneDocumentInfoObject::getUserFieldName(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException )
+{
+ return SfxDocumentInfoObject::getUserFieldName(nIndex);
+}
+
+//-----------------------------------------------------------------------------
+
+::rtl::OUString SAL_CALL SfxStandaloneDocumentInfoObject::getUserFieldValue(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException )
+{
+ return SfxDocumentInfoObject::getUserFieldValue(nIndex);
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxStandaloneDocumentInfoObject::setUserFieldName(sal_Int16 nIndex, const ::rtl::OUString& aName ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ SfxDocumentInfoObject::setUserFieldName( nIndex, aName );
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxStandaloneDocumentInfoObject::setUserFieldValue( sal_Int16 nIndex, const ::rtl::OUString& aValue ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ SfxDocumentInfoObject::setUserFieldValue( nIndex, aValue );
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxStandaloneDocumentInfoObject::loadFromURL(const ::rtl::OUString& aURL)
+ throw( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException )
+{
+ sal_Bool bOK = sal_False;
+
+ ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex );
+ uno::Reference< document::XDocumentProperties > xDocProps(
+ _xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.document.DocumentProperties"))), uno::UNO_QUERY_THROW);
+// uno::Reference< lang::XInitialization > xInit(xDocProps, uno::UNO_QUERY_THROW);
+// xInit->initialize(uno::Sequence<uno::Any>());
+ _pImp->Reset(xDocProps);
+ aGuard.clear();
+
+ uno::Reference< embed::XStorage > xStorage = GetStorage_Impl( aURL, sal_False, _xFactory );
+ if ( xStorage.is() )
+ {
+ try
+ {
+ uno::Sequence<beans::PropertyValue> medium(2);
+ medium[0].Name = ::rtl::OUString::createFromAscii("DocumentBaseURL");
+ medium[0].Value <<= aURL;
+ medium[1].Name = ::rtl::OUString::createFromAscii("URL");
+ medium[1].Value <<= aURL;
+ _pImp->m_xDocProps->loadFromStorage(xStorage, medium);
+ _pImp->Reset(_pImp->m_xDocProps);
+ bOK = sal_True;
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ else
+ {
+ uno::Reference < document::XStandaloneDocumentInfo > xBinary( _xFactory->createInstance(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.BinaryStandaloneDocumentInfo" ) ) ), uno::UNO_QUERY );
+ if ( xBinary.is() )
+ {
+ xBinary->loadFromURL( aURL );
+ bOK = sal_True;
+ uno::Reference < document::XStandaloneDocumentInfo > xTarget( static_cast < document::XStandaloneDocumentInfo*> (this), uno::UNO_QUERY );
+ Copy( xBinary, xTarget );
+ }
+ }
+
+ if ( !bOK )
+ throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_CANTREAD );
+}
+
+//-----------------------------------------------------------------------------
+
+void SAL_CALL SfxStandaloneDocumentInfoObject::storeIntoURL(const ::rtl::OUString& aURL) throw( ::com::sun::star::io::IOException )
+{
+ sal_Bool bOK = sal_False;
+ uno::Reference< embed::XStorage > xStorage = GetStorage_Impl( aURL, sal_True, _xFactory );
+ if ( xStorage.is() )
+ {
+ try
+ {
+ uno::Sequence<beans::PropertyValue> medium(2);
+ medium[0].Name = ::rtl::OUString::createFromAscii("DocumentBaseURL");
+ medium[0].Value <<= aURL;
+ medium[1].Name = ::rtl::OUString::createFromAscii("URL");
+ medium[1].Value <<= aURL;
+
+ _pImp->m_xDocProps->storeToStorage(xStorage, medium);
+ bOK = sal_True;
+ }
+ catch( io::IOException & )
+ {
+ throw;
+ }
+ catch( uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+ else
+ {
+ uno::Reference < document::XStandaloneDocumentInfo > xBinary( _xFactory->createInstance(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.BinaryStandaloneDocumentInfo" ) ) ), uno::UNO_QUERY );
+ if ( xBinary.is() )
+ {
+ Copy( this, xBinary );
+ xBinary->storeIntoURL( aURL );
+ bOK = sal_True;
+ }
+ }
+
+ if ( !bOK )
+ throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_CANTWRITE );
+}
+
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
new file mode 100644
index 000000000000..693911f0404c
--- /dev/null
+++ b/sfx2/source/doc/objxtor.cxx
@@ -0,0 +1,1147 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "arrdecl.hxx"
+
+#include <cppuhelper/implbase1.hxx>
+
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/util/XCloseBroadcaster.hpp>
+#include <com/sun/star/util/XCloseListener.hpp>
+#include <com/sun/star/util/XModifyBroadcaster.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/XTitle.hpp>
+#include <vos/mutex.hxx>
+
+#ifndef _SV_RESARY_HXX
+#include <tools/resary.hxx>
+#endif
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#ifndef _WRKWIN_HXX //autogen
+#include <vcl/wrkwin.hxx>
+#endif
+#include <vcl/svapp.hxx>
+#include <svl/eitem.hxx>
+#include <tools/rtti.hxx>
+#include <svl/lstner.hxx>
+#include <sfx2/sfxhelp.hxx>
+#include <basic/sbstar.hxx>
+#include <svl/stritem.hxx>
+#include <basic/sbx.hxx>
+#include <unotools/eventcfg.hxx>
+
+#include <sfx2/objsh.hxx>
+#include <sfx2/signaturestate.hxx>
+#include <sfx2/sfxmodelfactory.hxx>
+
+#ifndef _BASIC_SBUNO_HXX
+#include <basic/sbuno.hxx>
+#endif
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+#include <unotools/printwarningoptions.hxx>
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+
+#include <com/sun/star/document/XStorageBasedDocument.hpp>
+#include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
+#include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
+#include <com/sun/star/document/XEmbeddedScripts.hpp>
+#include <com/sun/star/document/XScriptInvocationContext.hpp>
+
+#include <svl/urihelper.hxx>
+#include <unotools/pathoptions.hxx>
+#include <svl/sharecontrolfile.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <unotools/ucbhelper.hxx>
+#include <svtools/asynclink.hxx>
+#include <tools/diagnose_ex.h>
+#include <sot/clsids.hxx>
+
+#include <sfx2/app.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/event.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "objshimp.hxx"
+#include "appbas.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/evntconf.hxx>
+#include <sfx2/request.hxx>
+#include "doc.hrc"
+#include "sfxlocal.hrc"
+#include "appdata.hxx"
+#include <sfx2/appuno.hxx>
+#include <sfx2/sfxsids.hrc>
+#include "sfx2/basmgr.hxx"
+#include "sfx2/QuerySaveDocument.hxx"
+#include "helpid.hrc"
+#include <sfx2/msg.hxx>
+#include "appbaslib.hxx"
+#include <sfx2/sfxbasemodel.hxx>
+
+#include <basic/basicmanagerrepository.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::script;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::document;
+
+using ::basic::BasicManagerRepository;
+#include <uno/mapping.hxx>
+
+//====================================================================
+
+DBG_NAME(SfxObjectShell)
+
+#define DocumentInfo
+#include "sfxslots.hxx"
+
+static WeakReference< XInterface > s_xCurrentComponent;
+
+//=========================================================================
+
+
+//=========================================================================
+
+class SfxModelListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
+{
+ SfxObjectShell* mpDoc;
+public:
+ SfxModelListener_Impl( SfxObjectShell* pDoc ) : mpDoc(pDoc) {};
+ virtual void SAL_CALL queryClosing( const com::sun::star::lang::EventObject& aEvent, sal_Bool bDeliverOwnership )
+ throw ( com::sun::star::uno::RuntimeException, com::sun::star::util::CloseVetoException) ;
+ virtual void SAL_CALL notifyClosing( const com::sun::star::lang::EventObject& aEvent ) throw ( com::sun::star::uno::RuntimeException ) ;
+ virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& aEvent ) throw ( com::sun::star::uno::RuntimeException ) ;
+
+};
+
+void SAL_CALL SfxModelListener_Impl::queryClosing( const com::sun::star::lang::EventObject& , sal_Bool )
+ throw ( com::sun::star::uno::RuntimeException, com::sun::star::util::CloseVetoException)
+{
+}
+
+void SAL_CALL SfxModelListener_Impl::notifyClosing( const com::sun::star::lang::EventObject& ) throw ( com::sun::star::uno::RuntimeException )
+{
+ ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
+ mpDoc->Broadcast( SfxSimpleHint(SFX_HINT_DEINITIALIZING) );
+}
+
+void SAL_CALL SfxModelListener_Impl::disposing( const com::sun::star::lang::EventObject& _rEvent ) throw ( com::sun::star::uno::RuntimeException )
+{
+ // am I ThisComponent in AppBasic?
+ ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
+ if ( SfxObjectShell::GetCurrentComponent() == _rEvent.Source )
+ {
+ // remove ThisComponent reference from AppBasic
+ SfxObjectShell::SetCurrentComponent( Reference< XInterface >() );
+ }
+
+ if ( mpDoc->Get_Impl()->bHiddenLockedByAPI )
+ {
+ mpDoc->Get_Impl()->bHiddenLockedByAPI = FALSE;
+ mpDoc->OwnerLock(FALSE);
+ }
+ else if ( !mpDoc->Get_Impl()->bClosing )
+ // GCC stuerzt ab, wenn schon im dtor, also vorher Flag abfragen
+ mpDoc->DoClose();
+}
+
+TYPEINIT1(SfxObjectShell, SfxShell);
+
+//--------------------------------------------------------------------
+SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell )
+ :mpObjectContainer(0)
+ ,pBasicManager( new SfxBasicManagerHolder )
+ ,rDocShell( _rDocShell )
+ ,aMacroMode( *this )
+ ,pProgress( 0)
+ ,nTime()
+ ,nVisualDocumentNumber( USHRT_MAX)
+ ,nDocumentSignatureState( SIGNATURESTATE_UNKNOWN )
+ ,nScriptingSignatureState( SIGNATURESTATE_UNKNOWN )
+ ,bInList( sal_False)
+ ,bClosing( sal_False)
+ ,bIsSaving( sal_False)
+ ,bPasswd( sal_False)
+ ,bIsTmp( sal_False)
+ ,bIsNamedVisible( sal_False)
+ ,bIsTemplate(sal_False)
+ ,bIsAbortingImport ( sal_False)
+ ,bImportDone ( sal_False)
+ ,bInPrepareClose( sal_False )
+ ,bPreparedForClose( sal_False )
+ ,bWaitingForPicklist( sal_True )
+ ,bForbidReload( sal_False )
+ ,bBasicInitialized( sal_False )
+ ,bIsPrintJobCancelable( sal_True )
+ ,bOwnsStorage( sal_True )
+ ,bNoBaseURL( sal_False )
+ ,bInitialized( sal_False )
+ ,bSignatureErrorIsShown( sal_False )
+ ,bModelInitialized( sal_False )
+ ,bPreserveVersions( sal_True )
+ ,m_bMacroSignBroken( sal_False )
+ ,m_bNoBasicCapabilities( sal_False )
+ ,m_bDocRecoverySupport( sal_True )
+ ,bQueryLoadTemplate( sal_True )
+ ,bLoadReadonly( sal_False )
+ ,bUseUserData( sal_True )
+ ,bSaveVersionOnClose( sal_False )
+ ,m_bSharedXMLFlag( sal_False )
+ ,m_bAllowShareControlFileClean( sal_True )
+ ,lErr(ERRCODE_NONE)
+ ,nEventId ( 0)
+ ,pReloadTimer ( 0)
+ ,pMarkData( 0 )
+ ,nLoadedFlags ( SFX_LOADED_ALL )
+ ,nFlagsInProgress( 0 )
+ ,bModalMode( sal_False )
+ ,bRunningMacro( sal_False )
+ ,bReloadAvailable( sal_False )
+ ,nAutoLoadLocks( 0 )
+ ,pModule( 0 )
+ ,eFlags( SFXOBJECTSHELL_UNDEFINED )
+ ,bReadOnlyUI( sal_False )
+ ,bHiddenLockedByAPI( sal_False )
+ ,nStyleFilter( 0 )
+ ,bDisposing( sal_False )
+ ,m_bEnableSetModified( sal_True )
+ ,m_bIsModified( sal_False )
+ ,m_nMapUnit( MAP_100TH_MM )
+ ,m_bCreateTempStor( sal_False )
+ ,m_bIsInit( sal_False )
+ ,m_bIncomplEncrWarnShown( sal_False )
+ ,m_nModifyPasswordHash( 0 )
+ ,m_bModifyPasswordEntered( sal_False )
+{
+ SfxObjectShell* pDoc = &_rDocShell;
+ SfxObjectShellArr_Impl &rArr = SFX_APP()->GetObjectShells_Impl();
+ rArr.C40_INSERT( SfxObjectShell, pDoc, rArr.Count() );
+ bInList = sal_True;
+}
+
+//--------------------------------------------------------------------
+
+SfxObjectShell_Impl::~SfxObjectShell_Impl()
+{
+ delete pBasicManager;
+}
+
+//--------------------------------------------------------------------
+
+SfxObjectShell::SfxObjectShell( const sal_uInt64 i_nCreationFlags )
+ : pImp( new SfxObjectShell_Impl( *this ) )
+ , pMedium(0)
+ , pStyleSheetPool(0)
+ , eCreateMode( ( i_nCreationFlags & SFXMODEL_EMBEDDED_OBJECT ) ? SFX_CREATE_MODE_EMBEDDED : SFX_CREATE_MODE_STANDARD )
+ , bHasName( sal_False )
+{
+ DBG_CTOR(SfxObjectShell, 0);
+
+ const bool bScriptSupport = ( i_nCreationFlags & SFXMODEL_DISABLE_EMBEDDED_SCRIPTS ) == 0;
+ if ( !bScriptSupport )
+ SetHasNoBasic();
+
+ const bool bDocRecovery = ( i_nCreationFlags & SFXMODEL_DISABLE_DOCUMENT_RECOVERY ) == 0;
+ if ( !bDocRecovery )
+ pImp->m_bDocRecoverySupport = sal_False;
+}
+
+//--------------------------------------------------------------------
+
+// initializes a document from a file-description
+
+SfxObjectShell::SfxObjectShell
+(
+ SfxObjectCreateMode eMode /* Zweck, zu dem die SfxObjectShell
+ erzeugt wird:
+
+ SFX_CREATE_MODE_EMBEDDED (default)
+ als SO-Server aus einem anderen
+ Dokument heraus
+
+ SFX_CREATE_MODE_STANDARD,
+ als normales, selbst"aendig ge"offnetes
+ Dokument
+
+ SFX_CREATE_MODE_PREVIEW
+ um ein Preview durchzuf"uhren,
+ ggf. werden weniger Daten ben"otigt
+
+ SFX_CREATE_MODE_ORGANIZER
+ um im Organizer dargestellt zu
+ werden, hier werden keine Inhalte
+ ben"otigt */
+)
+
+/* [Beschreibung]
+
+ Konstruktor der Klasse SfxObjectShell.
+*/
+
+: pImp( new SfxObjectShell_Impl( *this ) ),
+ pMedium(0),
+ pStyleSheetPool(0),
+ eCreateMode(eMode),
+ bHasName( sal_False )
+{
+ DBG_CTOR(SfxObjectShell, 0);
+}
+
+//--------------------------------------------------------------------
+
+// virtual dtor of typical base-class SfxObjectShell
+
+SfxObjectShell::~SfxObjectShell()
+{
+ DBG_DTOR(SfxObjectShell, 0);
+
+ if ( IsEnableSetModified() )
+ EnableSetModified( sal_False );
+
+ // Niemals GetInPlaceObject() aufrufen, der Zugriff auf den
+ // Ableitungszweig SfxInternObject ist wegen eines Compiler Bugs nicht
+ // erlaubt
+ SfxObjectShell::Close();
+ pImp->pBaseModel.set( NULL );
+
+ DELETEX(pImp->pReloadTimer );
+
+ SfxApplication *pSfxApp = SFX_APP();
+ if ( USHRT_MAX != pImp->nVisualDocumentNumber )
+ pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
+
+ // Basic-Manager zerst"oren
+ pImp->pBasicManager->reset( NULL );
+
+ if ( pSfxApp->GetDdeService() )
+ pSfxApp->RemoveDdeTopic( this );
+
+ pImp->pBaseModel.set( NULL );
+
+ // don't call GetStorage() here, in case of Load Failure it's possible that a storage was never assigned!
+ if ( pMedium && pMedium->HasStorage_Impl() && pMedium->GetStorage( sal_False ) == pImp->m_xDocStorage )
+ pMedium->CanDisposeStorage_Impl( sal_False );
+
+ if ( pImp->mpObjectContainer )
+ {
+ pImp->mpObjectContainer->CloseEmbeddedObjects();
+ delete pImp->mpObjectContainer;
+ }
+
+ if ( pImp->bOwnsStorage && pImp->m_xDocStorage.is() )
+ pImp->m_xDocStorage->dispose();
+
+ if ( pMedium )
+ {
+ pMedium->CloseAndReleaseStreams_Impl();
+
+ if ( IsDocShared() )
+ FreeSharedFile();
+
+ DELETEX( pMedium );
+ }
+
+ // The removing of the temporary file must be done as the latest step in the document destruction
+ if ( pImp->aTempName.Len() )
+ {
+ String aTmp;
+ ::utl::LocalFileHelper::ConvertPhysicalNameToURL( pImp->aTempName, aTmp );
+ ::utl::UCBContentHelper::Kill( aTmp );
+ }
+
+ delete pImp;
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::Stamp_SetPrintCancelState(sal_Bool bState)
+{
+ pImp->bIsPrintJobCancelable = bState;
+}
+
+//--------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::Stamp_GetPrintCancelState() const
+{
+ return pImp->bIsPrintJobCancelable;
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::ViewAssigned()
+
+/* [Beschreibung]
+
+ Diese Methode wird gerufen, wenn eine View zugewiesen wird.
+*/
+
+{
+}
+
+//--------------------------------------------------------------------
+// closes the Object and all its views
+
+sal_Bool SfxObjectShell::Close()
+{
+ {DBG_CHKTHIS(SfxObjectShell, 0);}
+ SfxObjectShellRef aRef(this);
+ if ( !pImp->bClosing )
+ {
+ // falls noch ein Progress l"auft, nicht schlie\sen
+ if ( !pImp->bDisposing && GetProgress() )
+ return sal_False;
+
+ pImp->bClosing = sal_True;
+ Reference< util::XCloseable > xCloseable( GetBaseModel(), UNO_QUERY );
+
+ if ( xCloseable.is() )
+ {
+ try
+ {
+ xCloseable->close( sal_True );
+ }
+ catch( Exception& )
+ {
+ pImp->bClosing = sal_False;
+ }
+ }
+
+ if ( pImp->bClosing )
+ {
+ // aus Document-Liste austragen
+ SfxApplication *pSfxApp = SFX_APP();
+ SfxObjectShellArr_Impl &rDocs = pSfxApp->GetObjectShells_Impl();
+ const SfxObjectShell *pThis = this;
+ sal_uInt16 nPos = rDocs.GetPos(pThis);
+ if ( nPos < rDocs.Count() )
+ rDocs.Remove( nPos );
+ pImp->bInList = sal_False;
+ }
+ }
+
+ return sal_True;
+}
+
+//--------------------------------------------------------------------
+
+// returns a pointer the first SfxDocument of specified type
+
+SfxObjectShell* SfxObjectShell::GetFirst
+(
+ const TypeId* pType ,
+ sal_Bool bOnlyVisible
+)
+{
+ SfxObjectShellArr_Impl &rDocs = SFX_APP()->GetObjectShells_Impl();
+
+ // seach for a SfxDocument of the specified type
+ for ( sal_uInt16 nPos = 0; nPos < rDocs.Count(); ++nPos )
+ {
+ SfxObjectShell* pSh = rDocs.GetObject( nPos );
+ if ( bOnlyVisible && pSh->IsPreview() && pSh->IsReadOnly() )
+ continue;
+
+ if ( ( !pType || pSh->IsA(*pType) ) &&
+ ( !bOnlyVisible || SfxViewFrame::GetFirst( pSh, sal_True )))
+ return pSh;
+ }
+
+ return 0;
+}
+//--------------------------------------------------------------------
+
+// returns a pointer to the next SfxDocument of specified type behind *pDoc
+
+SfxObjectShell* SfxObjectShell::GetNext
+(
+ const SfxObjectShell& rPrev,
+ const TypeId* pType,
+ sal_Bool bOnlyVisible
+)
+{
+ SfxObjectShellArr_Impl &rDocs = SFX_APP()->GetObjectShells_Impl();
+
+ // refind the specified predecessor
+ sal_uInt16 nPos;
+ for ( nPos = 0; nPos < rDocs.Count(); ++nPos )
+ if ( rDocs.GetObject(nPos) == &rPrev )
+ break;
+
+ // search for the next SfxDocument of the specified type
+ for ( ++nPos; nPos < rDocs.Count(); ++nPos )
+ {
+ SfxObjectShell* pSh = rDocs.GetObject( nPos );
+ if ( bOnlyVisible && pSh->IsPreview() && pSh->IsReadOnly() )
+ continue;
+
+ if ( ( !pType || pSh->IsA(*pType) ) &&
+ ( !bOnlyVisible || SfxViewFrame::GetFirst( pSh, sal_True )))
+ return pSh;
+ }
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+SfxObjectShell* SfxObjectShell::Current()
+{
+ SfxViewFrame *pFrame = SfxViewFrame::Current();
+ return pFrame ? pFrame->GetObjectShell() : 0;
+}
+
+//-------------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::IsInPrepareClose() const
+{
+ return pImp->bInPrepareClose;
+}
+
+//------------------------------------------------------------------------
+
+struct BoolEnv_Impl
+{
+ SfxObjectShell_Impl* pImp;
+ BoolEnv_Impl( SfxObjectShell_Impl* pImpP) : pImp( pImpP )
+ { pImpP->bInPrepareClose = sal_True; }
+ ~BoolEnv_Impl() { pImp->bInPrepareClose = sal_False; }
+};
+
+
+sal_uInt16 SfxObjectShell::PrepareClose
+(
+ sal_Bool bUI, // sal_True: Dialoge etc. erlaubt, sal_False: silent-mode
+ sal_Bool bForBrowsing
+)
+{
+ if( pImp->bInPrepareClose || pImp->bPreparedForClose )
+ return sal_True;
+ BoolEnv_Impl aBoolEnv( pImp );
+
+ // DocModalDialog?
+ if ( IsInModalMode() )
+ return sal_False;
+
+ SfxViewFrame* pFirst = SfxViewFrame::GetFirst( this );
+ if( pFirst && !pFirst->GetFrame().PrepareClose_Impl( bUI, bForBrowsing ) )
+ return sal_False;
+
+ // prepare views for closing
+ for ( SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this );
+ pFrm; pFrm = SfxViewFrame::GetNext( *pFrm, this ) )
+ {
+ DBG_ASSERT(pFrm->GetViewShell(),"KeineShell");
+ if ( pFrm->GetViewShell() )
+ {
+ sal_uInt16 nRet = pFrm->GetViewShell()->PrepareClose( bUI, bForBrowsing );
+ if ( nRet != sal_True )
+ return nRet;
+ }
+ }
+
+ SfxApplication *pSfxApp = SFX_APP();
+ pSfxApp->NotifyEvent( SfxEventHint(SFX_EVENT_PREPARECLOSEDOC, GlobalEventConfig::GetEventName(STR_EVENT_PREPARECLOSEDOC), this) );
+
+ if( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
+ {
+ pImp->bPreparedForClose = sal_True;
+ return sal_True;
+ }
+
+ // ggf. nachfragen, ob gespeichert werden soll
+ // nur fuer in sichtbaren Fenstern dargestellte Dokumente fragen
+ SfxViewFrame *pFrame = SfxObjectShell::Current() == this
+ ? SfxViewFrame::Current() : SfxViewFrame::GetFirst( this );
+
+ sal_Bool bClose = sal_False;
+ if ( bUI && IsModified() && pFrame )
+ {
+ // minimierte restoren
+ SfxFrame& rTop = pFrame->GetTopFrame();
+ SfxViewFrame::SetViewFrame( rTop.GetCurrentViewFrame() );
+ pFrame->GetFrame().Appear();
+
+ // fragen, ob gespeichert werden soll
+ short nRet = RET_YES;
+ //TODO/CLEANUP
+ //brauchen wir UI=2 noch?
+ //if( SfxApplication::IsPlugin() == sal_False || bUI == 2 )
+ {
+ //initiate help agent to inform about "print modifies the document"
+ SvtPrintWarningOptions aPrintOptions;
+ if (aPrintOptions.IsModifyDocumentOnPrintingAllowed() &&
+ HasName() && getDocProperties()->getPrintDate().Month > 0)
+ {
+ SfxHelp::OpenHelpAgent( &pFirst->GetFrame(), HID_CLOSE_WARNING );
+ }
+ const Reference< XTitle > xTitle( *pImp->pBaseModel.get(), UNO_QUERY_THROW );
+ const ::rtl::OUString sTitle = xTitle->getTitle ();
+ nRet = ExecuteQuerySaveDocument(&pFrame->GetWindow(),sTitle);
+ }
+ /*HACK for plugin::destroy()*/
+
+ if ( RET_YES == nRet )
+ {
+ // per Dispatcher speichern
+ const SfxPoolItem *pPoolItem;
+ if ( IsSaveVersionOnClose() )
+ {
+ SfxStringItem aItem( SID_DOCINFO_COMMENTS, String( SfxResId( STR_AUTOMATICVERSION ) ) );
+ SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI );
+ const SfxPoolItem* ppArgs[] = { &aItem, &aWarnItem, 0 };
+ pPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs );
+ }
+ else
+ {
+ SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI );
+ const SfxPoolItem* ppArgs[] = { &aWarnItem, 0 };
+ pPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs );
+ }
+
+ if ( !pPoolItem || pPoolItem->ISA(SfxVoidItem) || ( pPoolItem->ISA(SfxBoolItem) && !( (const SfxBoolItem*) pPoolItem )->GetValue() ) )
+ return sal_False;
+ else
+ bClose = sal_True;
+ }
+ else if ( RET_CANCEL == nRet )
+ // abgebrochen
+ return sal_False;
+ else if ( RET_NEWTASK == nRet )
+ {
+ return RET_NEWTASK;
+ }
+ else
+ {
+ // Bei Nein nicht noch Informationlost
+ bClose = sal_True;
+ }
+ }
+
+ pImp->bPreparedForClose = sal_True;
+ return sal_True;
+}
+
+//--------------------------------------------------------------------
+namespace
+{
+ static BasicManager* lcl_getBasicManagerForDocument( const SfxObjectShell& _rDocument )
+ {
+ if ( !_rDocument.Get_Impl()->m_bNoBasicCapabilities )
+ {
+ if ( !_rDocument.Get_Impl()->bBasicInitialized )
+ const_cast< SfxObjectShell& >( _rDocument ).InitBasicManager_Impl();
+ return _rDocument.Get_Impl()->pBasicManager->get();
+ }
+
+ // assume we do not have Basic ourself, but we can refer to another
+ // document which does (by our model's XScriptInvocationContext::getScriptContainer).
+ // In this case, we return the BasicManager of this other document.
+
+ OSL_ENSURE( !Reference< XEmbeddedScripts >( _rDocument.GetModel(), UNO_QUERY ).is(),
+ "lcl_getBasicManagerForDocument: inconsistency: no Basic, but an XEmbeddedScripts?" );
+ Reference< XModel > xForeignDocument;
+ Reference< XScriptInvocationContext > xContext( _rDocument.GetModel(), UNO_QUERY );
+ if ( xContext.is() )
+ {
+ xForeignDocument.set( xContext->getScriptContainer(), UNO_QUERY );
+ OSL_ENSURE( xForeignDocument.is() && xForeignDocument != _rDocument.GetModel(),
+ "lcl_getBasicManagerForDocument: no Basic, but providing ourself as script container?" );
+ }
+
+ BasicManager* pBasMgr = NULL;
+ if ( xForeignDocument.is() )
+ pBasMgr = ::basic::BasicManagerRepository::getDocumentBasicManager( xForeignDocument );
+
+ return pBasMgr;
+ }
+}
+
+//--------------------------------------------------------------------
+
+BasicManager* SfxObjectShell::GetBasicManager() const
+{
+ BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
+ if ( !pBasMgr )
+ pBasMgr = SFX_APP()->GetBasicManager();
+ return pBasMgr;
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::SetHasNoBasic()
+{
+ pImp->m_bNoBasicCapabilities = sal_True;
+}
+
+//--------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::HasBasic() const
+{
+ if ( pImp->m_bNoBasicCapabilities )
+ return sal_False;
+
+ if ( !pImp->bBasicInitialized )
+ const_cast< SfxObjectShell* >( this )->InitBasicManager_Impl();
+
+ return pImp->pBasicManager->isValid();
+}
+
+//--------------------------------------------------------------------
+namespace
+{
+ const Reference< XLibraryContainer >&
+ lcl_getOrCreateLibraryContainer( bool _bScript, Reference< XLibraryContainer >& _rxContainer,
+ const Reference< XModel >& _rxDocument )
+ {
+ if ( !_rxContainer.is() )
+ {
+ try
+ {
+ Reference< XStorageBasedDocument > xStorageDoc( _rxDocument, UNO_QUERY );
+ const Reference< XComponentContext > xContext(
+ ::comphelper::getProcessComponentContext() );
+ _rxContainer.set ( _bScript
+ ? DocumentScriptLibraryContainer::create(
+ xContext, xStorageDoc )
+ : DocumentDialogLibraryContainer::create(
+ xContext, xStorageDoc )
+ , UNO_QUERY_THROW );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+ return _rxContainer;
+ }
+}
+
+//--------------------------------------------------------------------
+
+Reference< XLibraryContainer > SfxObjectShell::GetDialogContainer()
+{
+ if ( !pImp->m_bNoBasicCapabilities )
+ return lcl_getOrCreateLibraryContainer( false, pImp->xDialogLibraries, GetModel() );
+
+ BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
+ if ( pBasMgr )
+ return pBasMgr->GetDialogLibraryContainer().get();
+
+ OSL_ENSURE( false, "SfxObjectShell::GetDialogContainer: falling back to the application - is this really expected here?" );
+ return SFX_APP()->GetDialogContainer();
+}
+
+//--------------------------------------------------------------------
+
+Reference< XLibraryContainer > SfxObjectShell::GetBasicContainer()
+{
+ if ( !pImp->m_bNoBasicCapabilities )
+ return lcl_getOrCreateLibraryContainer( true, pImp->xBasicLibraries, GetModel() );
+
+ BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
+ if ( pBasMgr )
+ return pBasMgr->GetScriptLibraryContainer().get();
+
+ OSL_ENSURE( false, "SfxObjectShell::GetBasicContainer: falling back to the application - is this really expected here?" );
+ return SFX_APP()->GetBasicContainer();
+}
+
+//--------------------------------------------------------------------
+
+StarBASIC* SfxObjectShell::GetBasic() const
+{
+ return GetBasicManager()->GetLib(0);
+}
+
+//--------------------------------------------------------------------
+
+void SfxObjectShell::InitBasicManager_Impl()
+/* [Beschreibung]
+
+ creates a document's BasicManager and loads it, if we are already based on
+ a storage.
+
+ [Anmerkung]
+
+ Diese Methode mu"s aus den "Uberladungen von <SvPersist::Load()> (mit
+ dem pStor aus dem Parameter von Load()) sowie aus der "Uberladung
+ von <SvPersist::InitNew()> (mit pStor = 0) gerufen werden.
+*/
+
+{
+ /* #163556# (DR) - Handling of recursive calls while creating the Bacic
+ manager.
+
+ It is possible that (while creating the Basic manager) the code that
+ imports the Basic storage wants to access the Basic manager again.
+ Especially in VBA compatibility mode, there is code that wants to
+ access the "VBA Globals" object which is stored as global UNO constant
+ in the Basic manager.
+
+ To achieve correct handling of the recursive calls of this function
+ from lcl_getBasicManagerForDocument(), the implementation of the
+ function BasicManagerRepository::getDocumentBasicManager() has been
+ changed to return the Basic manager currently under construction, when
+ called repeatedly.
+
+ The variable pImp->bBasicInitialized will be set to TRUE after
+ construction now, to ensure that the recursive call of the function
+ lcl_getBasicManagerForDocument() will be routed into this function too.
+
+ Calling BasicManagerHolder::reset() twice is not a big problem, as it
+ does not take ownership but stores only the raw pointer. Owner of all
+ Basic managers is the global BasicManagerRepository instance.
+ */
+ DBG_ASSERT( !pImp->bBasicInitialized && !pImp->pBasicManager->isValid(), "Lokaler BasicManager bereits vorhanden");
+ pImp->pBasicManager->reset( BasicManagerRepository::getDocumentBasicManager( GetModel() ) );
+ DBG_ASSERT( pImp->pBasicManager->isValid(), "SfxObjectShell::InitBasicManager_Impl: did not get a BasicManager!" );
+ pImp->bBasicInitialized = TRUE;
+}
+
+//--------------------------------------------------------------------
+#if 0 //(mba)
+SotObjectRef SfxObjectShell::CreateAggObj( const SotFactory* pFact )
+{
+ // SvDispatch?
+ SotFactory* pDispFact = SvDispatch::ClassFactory();
+ if( pFact == pDispFact )
+ return( (SfxShellObject*)GetSbxObject() );
+
+ // sonst unbekannte Aggregation
+ DBG_ERROR("unkekannte Factory");
+ SotObjectRef aSvObjectRef;
+ return aSvObjectRef;
+}
+#endif
+
+//--------------------------------------------------------------------
+
+sal_uInt16 SfxObjectShell::Count()
+{
+ return SFX_APP()->GetObjectShells_Impl().Count();
+}
+
+//--------------------------------------------------------------------
+
+sal_Bool SfxObjectShell::DoClose()
+{
+ return Close();
+}
+
+//--------------------------------------------------------------------
+
+SfxObjectShell* SfxObjectShell::GetObjectShell()
+{
+ return this;
+}
+
+//--------------------------------------------------------------------
+
+SEQUENCE< OUSTRING > SfxObjectShell::GetEventNames()
+{
+ static uno::Sequence< ::rtl::OUString >* pEventNameContainer = NULL;
+
+ if ( !pEventNameContainer )
+ {
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( !pEventNameContainer )
+ {
+ static uno::Sequence< ::rtl::OUString > aEventNameContainer = GlobalEventConfig().getElementNames();
+ pEventNameContainer = &aEventNameContainer;
+ }
+ }
+
+ return *pEventNameContainer;
+}
+
+//--------------------------------------------------------------------
+
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SfxObjectShell::GetModel() const
+{
+ return GetBaseModel();
+}
+
+void SfxObjectShell::SetBaseModel( SfxBaseModel* pModel )
+{
+ OSL_ENSURE( !pImp->pBaseModel.is() || pModel == NULL, "Model already set!" );
+ pImp->pBaseModel.set( pModel );
+ if ( pImp->pBaseModel.is() )
+ {
+ pImp->pBaseModel->addCloseListener( new SfxModelListener_Impl(this) );
+ }
+}
+
+//--------------------------------------------------------------------
+
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SfxObjectShell::GetBaseModel() const
+{
+ return pImp->pBaseModel.get();
+}
+/* -----------------------------10.09.2001 15:56------------------------------
+
+ ---------------------------------------------------------------------------*/
+void SfxObjectShell::SetAutoStyleFilterIndex(sal_uInt16 nSet)
+{
+ pImp->nStyleFilter = nSet;
+}
+
+sal_uInt16 SfxObjectShell::GetAutoStyleFilterIndex()
+{
+ return pImp->nStyleFilter;
+}
+
+
+void SfxObjectShell::SetCurrentComponent( const Reference< XInterface >& _rxComponent )
+{
+ Reference< XInterface > xTest(s_xCurrentComponent);
+ if ( _rxComponent == xTest )
+ // nothing to do
+ return;
+ // note that "_rxComponent.get() == s_xCurrentComponent.get().get()" is /sufficient/, but not
+ // /required/ for "_rxComponent == s_xCurrentComponent.get()".
+ // In other words, it's still possible that we here do something which is not necessary,
+ // but we should have filtered quite some unnecessary calls already.
+
+ BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
+ s_xCurrentComponent = _rxComponent;
+ if ( pAppMgr )
+ pAppMgr->SetGlobalUNOConstant( "ThisComponent", makeAny( _rxComponent ) );
+
+#if OSL_DEBUG_LEVEL > 0
+ const char* pComponentImplName = _rxComponent.get() ? typeid( *_rxComponent.get() ).name() : "void";
+ OSL_TRACE( "current component is a %s\n", pComponentImplName );
+#endif
+}
+
+Reference< XInterface > SfxObjectShell::GetCurrentComponent()
+{
+ return s_xCurrentComponent;
+}
+
+
+String SfxObjectShell::GetServiceNameFromFactory( const String& rFact )
+{
+ //! Remove everything behind name!
+ String aFact( rFact );
+ String aPrefix = String::CreateFromAscii( "private:factory/" );
+ if ( aPrefix.Len() == aFact.Match( aPrefix ) )
+ aFact.Erase( 0, aPrefix.Len() );
+ USHORT nPos = aFact.Search( '?' );
+ String aParam;
+ if ( nPos != STRING_NOTFOUND )
+ {
+ aParam = aFact.Copy( nPos, aFact.Len() );
+ aFact.Erase( nPos, aFact.Len() );
+ aParam.Erase(0,1);
+ }
+ aFact.EraseAllChars('4').ToLowerAscii();
+
+ // HACK: sometimes a real document service name is given here instead of
+ // a factory short name. Set return value directly to this service name as fallback
+ // in case next lines of code does nothing ...
+ // use rFact instead of normed aFact value !
+ ::rtl::OUString aServiceName = rFact;
+
+ if ( aFact.EqualsAscii("swriter") )
+ {
+ aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.text.TextDocument");
+ }
+ else if ( aFact.EqualsAscii("sweb") || aFact.EqualsAscii("swriter/web") )
+ {
+ aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.text.WebDocument");
+ }
+ else if ( aFact.EqualsAscii("sglobal") || aFact.EqualsAscii("swriter/globaldocument") )
+ {
+ aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.text.GlobalDocument");
+ }
+ else if ( aFact.EqualsAscii("scalc") )
+ {
+ aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.sheet.SpreadsheetDocument");
+ }
+ else if ( aFact.EqualsAscii("sdraw") )
+ {
+ aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.drawing.DrawingDocument");
+ }
+ else if ( aFact.EqualsAscii("simpress") )
+ {
+ aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.presentation.PresentationDocument");
+ }
+ else if ( aFact.EqualsAscii("schart") )
+ {
+ aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.chart.ChartDocument");
+ }
+ else if ( aFact.EqualsAscii("smath") )
+ {
+ aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.formula.FormulaProperties");
+ }
+ else if ( aFact.EqualsAscii("sbasic") )
+ {
+ aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.script.BasicIDE");
+ }
+ else if ( aFact.EqualsAscii("sdatabase") )
+ {
+ aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.sdb.OfficeDatabaseDocument");
+ }
+
+ return aServiceName;
+}
+
+SfxObjectShell* SfxObjectShell::CreateObjectByFactoryName( const String& rFact, SfxObjectCreateMode eMode )
+{
+ return CreateObject( GetServiceNameFromFactory( rFact ), eMode );
+}
+
+
+SfxObjectShell* SfxObjectShell::CreateObject( const String& rServiceName, SfxObjectCreateMode eCreateMode )
+{
+ if ( rServiceName.Len() )
+ {
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XModel > xDoc(
+ ::comphelper::getProcessServiceFactory()->createInstance( rServiceName ), UNO_QUERY );
+ if ( xDoc.is() )
+ {
+ ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( xDoc, UNO_QUERY );
+ ::com::sun::star::uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
+ sal_Int64 nHandle = xObj->getSomething( aSeq );
+ if ( nHandle )
+ {
+ SfxObjectShell* pRet = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
+ pRet->SetCreateMode_Impl( eCreateMode );
+ return pRet;
+ }
+ }
+ }
+
+ return 0;
+}
+
+SfxObjectShell* SfxObjectShell::CreateAndLoadObject( const SfxItemSet& rSet, SfxFrame* pFrame )
+{
+ uno::Sequence < beans::PropertyValue > aProps;
+ TransformItems( SID_OPENDOC, rSet, aProps );
+ SFX_ITEMSET_ARG(&rSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, FALSE);
+ SFX_ITEMSET_ARG(&rSet, pTargetItem, SfxStringItem, SID_TARGETNAME, FALSE);
+ ::rtl::OUString aURL;
+ ::rtl::OUString aTarget = rtl::OUString::createFromAscii("_blank");
+ if ( pFileNameItem )
+ aURL = pFileNameItem->GetValue();
+ if ( pTargetItem )
+ aTarget = pTargetItem->GetValue();
+
+ uno::Reference < frame::XComponentLoader > xLoader;
+ if ( pFrame )
+ {
+ xLoader = uno::Reference < frame::XComponentLoader >( pFrame->GetFrameInterface(), uno::UNO_QUERY );
+ }
+ else
+ xLoader = uno::Reference < frame::XComponentLoader >( comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop") ), uno::UNO_QUERY );
+
+ uno::Reference < lang::XUnoTunnel > xObj;
+ try
+ {
+ xObj = uno::Reference< lang::XUnoTunnel >( xLoader->loadComponentFromURL( aURL, aTarget, 0, aProps ), uno::UNO_QUERY );
+ }
+ catch( uno::Exception& )
+ {}
+
+ if ( xObj.is() )
+ {
+ ::com::sun::star::uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
+ sal_Int64 nHandle = xObj->getSomething( aSeq );
+ if ( nHandle )
+ return reinterpret_cast< SfxObjectShell* >(sal::static_int_cast< sal_IntPtr >( nHandle ));
+ }
+
+ return NULL;
+}
+
+void SfxObjectShell::SetInitialized_Impl( const bool i_fromInitNew )
+{
+ pImp->bInitialized = sal_True;
+ if ( i_fromInitNew )
+ {
+ SetActivateEvent_Impl( SFX_EVENT_CREATEDOC );
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_DOCCREATED, GlobalEventConfig::GetEventName(STR_EVENT_DOCCREATED), this ) );
+ }
+ else
+ {
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_LOADFINISHED, GlobalEventConfig::GetEventName(STR_EVENT_LOADFINISHED), this ) );
+ }
+}
+
+
+bool SfxObjectShell::IsChangeRecording() const
+{
+ // currently this function needs to be overwritten by Writer and Calc only
+ DBG_ASSERT( 0, "function not implemented" );
+ return false;
+}
+
+
+bool SfxObjectShell::HasChangeRecordProtection() const
+{
+ // currently this function needs to be overwritten by Writer and Calc only
+ DBG_ASSERT( 0, "function not implemented" );
+ return false;
+}
+
+
+void SfxObjectShell::SetChangeRecording( bool /*bActivate*/ )
+{
+ // currently this function needs to be overwritten by Writer and Calc only
+ DBG_ASSERT( 0, "function not implemented" );
+}
+
+
+bool SfxObjectShell::SetProtectionPassword( const String & /*rPassword*/ )
+{
+ // currently this function needs to be overwritten by Writer and Calc only
+ DBG_ASSERT( 0, "function not implemented" );
+ return false;
+}
+
+
+bool SfxObjectShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > & /*rPasswordHash*/ )
+{
+ // currently this function needs to be overwritten by Writer and Calc only
+ DBG_ASSERT( 0, "function not implemented" );
+ return false;
+}
+
diff --git a/sfx2/source/doc/oleprops.cxx b/sfx2/source/doc/oleprops.cxx
new file mode 100755
index 000000000000..d6192542d1a1
--- /dev/null
+++ b/sfx2/source/doc/oleprops.cxx
@@ -0,0 +1,1227 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "oleprops.hxx"
+
+#include <comphelper/types.hxx>
+#include <tools/debug.hxx>
+#include <tools/datetime.hxx>
+#include <rtl/tencinfo.h>
+
+// ============================================================================
+
+
+// ============================================================================
+
+#define VERSION 11
+#define STREAM_BUFFER_SIZE 2048
+
+// usings
+using ::rtl::OUString;
+using ::com::sun::star::uno::Any;
+using ::com::sun::star::uno::makeAny;
+
+using namespace ::com::sun::star;
+
+#define TIMESTAMP_INVALID_DATETIME ( DateTime ( Date ( 1, 1, 1601 ), Time ( 0, 0, 0 ) ) ) /// Invalid value for date and time to create invalid instance of TimeStamp.
+#define TIMESTAMP_INVALID_UTILDATETIME ( util::DateTime ( 0, 0, 0, 0, 1, 1, 1601 ) ) /// Invalid value for date and time to create invalid instance of TimeStamp.
+
+static
+bool operator==(const util::DateTime &i_rLeft, const util::DateTime &i_rRight)
+{
+ return i_rLeft.Year == i_rRight.Year
+ && i_rLeft.Month == i_rRight.Month
+ && i_rLeft.Day == i_rRight.Day
+ && i_rLeft.Hours == i_rRight.Hours
+ && i_rLeft.Minutes == i_rRight.Minutes
+ && i_rLeft.Seconds == i_rRight.Seconds
+ && i_rLeft.HundredthSeconds == i_rRight.HundredthSeconds;
+}
+
+// ============================================================================
+
+/** Property representing a signed 32-bit integer value. */
+class SfxOleInt32Property : public SfxOlePropertyBase
+{
+public:
+ explicit SfxOleInt32Property( sal_Int32 nPropId, sal_Int32 nValue = 0 );
+
+ inline sal_Int32 GetValue() const { return mnValue; }
+ inline void SetValue( sal_Int32 nValue ) { mnValue = nValue; }
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+
+private:
+ sal_Int32 mnValue;
+};
+
+// ============================================================================
+
+/** Property representing a floating-point value. */
+class SfxOleDoubleProperty : public SfxOlePropertyBase
+{
+public:
+ explicit SfxOleDoubleProperty( sal_Int32 nPropId, double fValue = 0.0 );
+
+ inline double GetValue() const { return mfValue; }
+ inline void SetValue( double fValue ) { mfValue = fValue; }
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+
+private:
+ double mfValue;
+};
+
+// ============================================================================
+
+/** Property representing a boolean value. */
+class SfxOleBoolProperty : public SfxOlePropertyBase
+{
+public:
+ explicit SfxOleBoolProperty( sal_Int32 nPropId, bool bValue = false );
+
+ inline bool GetValue() const { return mbValue; }
+ inline void SetValue( bool bValue ) { mbValue = bValue; }
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+
+private:
+ bool mbValue;
+};
+
+// ============================================================================
+
+/** Base class for properties that contain a single string value. */
+class SfxOleStringPropertyBase : public SfxOlePropertyBase, public SfxOleStringHelper
+{
+public:
+ explicit SfxOleStringPropertyBase(
+ sal_Int32 nPropId, sal_Int32 nPropType,
+ const SfxOleTextEncoding& rTextEnc );
+ explicit SfxOleStringPropertyBase(
+ sal_Int32 nPropId, sal_Int32 nPropType,
+ const SfxOleTextEncoding& rTextEnc, const String& rValue );
+ explicit SfxOleStringPropertyBase(
+ sal_Int32 nPropId, sal_Int32 nPropType,
+ rtl_TextEncoding eTextEnc );
+ explicit SfxOleStringPropertyBase(
+ sal_Int32 nPropId, sal_Int32 nPropType,
+ rtl_TextEncoding eTextEnc, const String& rValue );
+
+ inline const String& GetValue() const { return maValue; }
+ inline void SetValue( const String& rValue ) { maValue = rValue; }
+
+private:
+ String maValue;
+};
+
+// ============================================================================
+
+/** Property representing a bytestring value. */
+class SfxOleString8Property : public SfxOleStringPropertyBase
+{
+public:
+ explicit SfxOleString8Property(
+ sal_Int32 nPropId, const SfxOleTextEncoding& rTextEnc );
+ explicit SfxOleString8Property(
+ sal_Int32 nPropId, const SfxOleTextEncoding& rTextEnc,
+ const String& rValue );
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+};
+
+// ============================================================================
+
+/** Property representing a Unicode string value. */
+class SfxOleString16Property : public SfxOleStringPropertyBase
+{
+public:
+ explicit SfxOleString16Property( sal_Int32 nPropId );
+ explicit SfxOleString16Property( sal_Int32 nPropId, const String& rValue );
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+};
+
+// ============================================================================
+
+/** Property representing a filetime value as defined by the Windows API. */
+class SfxOleFileTimeProperty : public SfxOlePropertyBase
+{
+public:
+ explicit SfxOleFileTimeProperty( sal_Int32 nPropId );
+ /** @param rDateTime Date and time as LOCAL time. */
+ explicit SfxOleFileTimeProperty( sal_Int32 nPropId, const util::DateTime& rDateTime );
+
+ /** Returns the time value as LOCAL time. */
+ inline const util::DateTime& GetValue() const { return maDateTime; }
+ /** @param rDateTime Date and time as LOCAL time. */
+ inline void SetValue( const util::DateTime& rDateTime ) { maDateTime = rDateTime; }
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+
+private:
+ util::DateTime maDateTime;
+};
+
+// ============================================================================
+
+/** Property representing a thumbnail picture.
+
+ Currently, only saving this property is implemented.
+ */
+class SfxOleThumbnailProperty : public SfxOlePropertyBase
+{
+public:
+ explicit SfxOleThumbnailProperty( sal_Int32 nPropId,
+ const uno::Sequence<sal_uInt8> & i_rData);
+
+ inline bool IsValid() const { return mData.getLength() > 0; }
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+
+private:
+ uno::Sequence<sal_uInt8> mData;
+};
+
+// ============================================================================
+
+/** Property representing a BLOB (which presumably stands for binary large
+ object).
+
+ Currently, only saving this property is implemented.
+ */
+class SfxOleBlobProperty : public SfxOlePropertyBase
+{
+public:
+ explicit SfxOleBlobProperty( sal_Int32 nPropId,
+ const uno::Sequence<sal_uInt8> & i_rData);
+ inline bool IsValid() const { return mData.getLength() > 0; }
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+
+private:
+ uno::Sequence<sal_uInt8> mData;
+};
+
+// ============================================================================
+
+sal_uInt16 SfxOleTextEncoding::GetCodePage() const
+{
+ sal_uInt16 nCodePage = IsUnicode() ? CODEPAGE_UNICODE :
+ static_cast< sal_uInt16 >( rtl_getWindowsCodePageFromTextEncoding( *mxTextEnc ) );
+ return (nCodePage == CODEPAGE_UNKNOWN) ? CODEPAGE_UTF8 : nCodePage;
+}
+
+void SfxOleTextEncoding::SetCodePage( sal_uInt16 nCodePage )
+{
+ if( nCodePage == CODEPAGE_UNICODE )
+ SetUnicode();
+ else
+ {
+ rtl_TextEncoding eTextEnc = rtl_getTextEncodingFromWindowsCodePage( nCodePage );
+ if( eTextEnc != RTL_TEXTENCODING_DONTKNOW )
+ *mxTextEnc = eTextEnc;
+ }
+}
+
+// ----------------------------------------------------------------------------
+
+String SfxOleStringHelper::LoadString8( SvStream& rStrm ) const
+{
+ return IsUnicode() ? ImplLoadString16( rStrm ) : ImplLoadString8( rStrm );
+}
+
+void SfxOleStringHelper::SaveString8( SvStream& rStrm, const String& rValue ) const
+{
+ if( IsUnicode() )
+ ImplSaveString16( rStrm, rValue );
+ else
+ ImplSaveString8( rStrm, rValue );
+}
+
+String SfxOleStringHelper::LoadString16( SvStream& rStrm ) const
+{
+ return ImplLoadString16( rStrm );
+}
+
+void SfxOleStringHelper::SaveString16( SvStream& rStrm, const String& rValue ) const
+{
+ ImplSaveString16( rStrm, rValue );
+}
+
+String SfxOleStringHelper::ImplLoadString8( SvStream& rStrm ) const
+{
+ String aValue;
+ // read size field (signed 32-bit)
+ sal_Int32 nSize;
+ rStrm >> nSize;
+ // size field includes trailing NUL character
+ DBG_ASSERT( (0 < nSize) && (nSize <= 0xFFFF), "SfxOleStringHelper::ImplLoadString8 - invalid string" );
+ if( (0 < nSize) && (nSize <= 0xFFFF) )
+ {
+ // load character buffer
+ ::std::vector< sal_Char > aBuffer( static_cast< size_t >( nSize + 1 ), 0 );
+ rStrm.Read( &aBuffer.front(), static_cast< sal_Size >( nSize ) );
+ // create string from encoded character array
+ aValue = String( &aBuffer.front(), GetTextEncoding() );
+ }
+ return aValue;
+}
+
+String SfxOleStringHelper::ImplLoadString16( SvStream& rStrm ) const
+{
+ String aValue;
+ // read size field (signed 32-bit), may be buffer size or character count
+ sal_Int32 nSize;
+ rStrm >> nSize;
+ DBG_ASSERT( (0 < nSize) && (nSize <= 0xFFFF), "SfxOleStringHelper::ImplLoadString16 - invalid string" );
+ // size field includes trailing NUL character
+ if( (0 < nSize) && (nSize <= 0xFFFF) )
+ {
+ // load character buffer
+ ::std::vector< sal_Unicode > aBuffer;
+ aBuffer.reserve( static_cast< size_t >( nSize + 1 ) );
+ sal_uInt16 cChar;
+ for( sal_Int32 nIdx = 0; nIdx < nSize; ++nIdx )
+ {
+ rStrm >> cChar;
+ aBuffer.push_back( static_cast< sal_Unicode >( cChar ) );
+ }
+ // stream is always padded to 32-bit boundary, skip 2 bytes on odd character count
+ if( (nSize & 1) == 1 )
+ rStrm.SeekRel( 2 );
+ // create string from character array
+ aBuffer.push_back( 0 );
+ aValue = String( &aBuffer.front() );
+ }
+ return aValue;
+}
+
+void SfxOleStringHelper::ImplSaveString8( SvStream& rStrm, const String& rValue ) const
+{
+ // encode to byte string
+ ByteString aEncoded( rValue, GetTextEncoding() );
+ // write size field (including trailing NUL character)
+ sal_Int32 nSize = static_cast< sal_Int32 >( aEncoded.Len() + 1 );
+ rStrm << nSize;
+ // write character array with trailing NUL character
+ rStrm.Write( aEncoded.GetBuffer(), aEncoded.Len() );
+ rStrm << sal_uInt8( 0 );
+}
+
+void SfxOleStringHelper::ImplSaveString16( SvStream& rStrm, const String& rValue ) const
+{
+ // write size field (including trailing NUL character)
+ sal_Int32 nSize = static_cast< sal_Int32 >( rValue.Len() + 1 );
+ rStrm << nSize;
+ // write character array with trailing NUL character
+ for( xub_StrLen nIdx = 0; nIdx < rValue.Len(); ++nIdx )
+ rStrm << static_cast< sal_uInt16 >( rValue.GetChar( nIdx ) );
+ rStrm << sal_uInt16( 0 );
+ // stream is always padded to 32-bit boundary, add 2 bytes on odd character count
+ if( (nSize & 1) == 1 )
+ rStrm << sal_uInt16( 0 );
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleObjectBase::~SfxOleObjectBase()
+{
+}
+
+ErrCode SfxOleObjectBase::Load( SvStream& rStrm )
+{
+ mnErrCode = ERRCODE_NONE;
+ ImplLoad( rStrm );
+ SetError( rStrm.GetErrorCode() );
+ return GetError();
+}
+
+ErrCode SfxOleObjectBase::Save( SvStream& rStrm )
+{
+ mnErrCode = ERRCODE_NONE;
+ ImplSave( rStrm );
+ SetError( rStrm.GetErrorCode() );
+ return GetError();
+}
+
+void SfxOleObjectBase::LoadObject( SvStream& rStrm, SfxOleObjectBase& rObj )
+{
+ SetError( rObj.Load( rStrm ) );
+}
+
+void SfxOleObjectBase::SaveObject( SvStream& rStrm, SfxOleObjectBase& rObj )
+{
+ SetError( rObj.Save( rStrm ) );
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleCodePageProperty::SfxOleCodePageProperty() :
+ SfxOlePropertyBase( PROPID_CODEPAGE, PROPTYPE_INT16 )
+{
+}
+
+void SfxOleCodePageProperty::ImplLoad( SvStream& rStrm )
+{
+ // property type is signed int16, but we use always unsigned int16 for codepages
+ sal_uInt16 nCodePage;
+ rStrm >> nCodePage;
+ SetCodePage( nCodePage );
+}
+
+void SfxOleCodePageProperty::ImplSave( SvStream& rStrm )
+{
+ // property type is signed int16, but we use always unsigned int16 for codepages
+ rStrm << GetCodePage();
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleInt32Property::SfxOleInt32Property( sal_Int32 nPropId, sal_Int32 nValue ) :
+ SfxOlePropertyBase( nPropId, PROPTYPE_INT32 ),
+ mnValue( nValue )
+{
+}
+
+void SfxOleInt32Property::ImplLoad( SvStream& rStrm )
+{
+ rStrm >> mnValue;
+}
+
+void SfxOleInt32Property::ImplSave( SvStream& rStrm )
+{
+ rStrm << mnValue;
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleDoubleProperty::SfxOleDoubleProperty( sal_Int32 nPropId, double fValue ) :
+ SfxOlePropertyBase( nPropId, PROPTYPE_DOUBLE ),
+ mfValue( fValue )
+{
+}
+
+void SfxOleDoubleProperty::ImplLoad( SvStream& rStrm )
+{
+ rStrm >> mfValue;
+}
+
+void SfxOleDoubleProperty::ImplSave( SvStream& rStrm )
+{
+ rStrm << mfValue;
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleBoolProperty::SfxOleBoolProperty( sal_Int32 nPropId, bool bValue ) :
+ SfxOlePropertyBase( nPropId, PROPTYPE_BOOL ),
+ mbValue( bValue )
+{
+}
+
+void SfxOleBoolProperty::ImplLoad( SvStream& rStrm )
+{
+ sal_Int16 nValue;
+ rStrm >> nValue;
+ mbValue = nValue != 0;
+}
+
+void SfxOleBoolProperty::ImplSave( SvStream& rStrm )
+{
+ rStrm << static_cast< sal_Int16 >( mbValue ? -1 : 0 );
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleStringPropertyBase::SfxOleStringPropertyBase(
+ sal_Int32 nPropId, sal_Int32 nPropType, const SfxOleTextEncoding& rTextEnc ) :
+ SfxOlePropertyBase( nPropId, nPropType ),
+ SfxOleStringHelper( rTextEnc )
+{
+}
+
+SfxOleStringPropertyBase::SfxOleStringPropertyBase(
+ sal_Int32 nPropId, sal_Int32 nPropType, const SfxOleTextEncoding& rTextEnc, const String& rValue ) :
+ SfxOlePropertyBase( nPropId, nPropType ),
+ SfxOleStringHelper( rTextEnc ),
+ maValue( rValue )
+{
+}
+
+SfxOleStringPropertyBase::SfxOleStringPropertyBase(
+ sal_Int32 nPropId, sal_Int32 nPropType, rtl_TextEncoding eTextEnc ) :
+ SfxOlePropertyBase( nPropId, nPropType ),
+ SfxOleStringHelper( eTextEnc )
+{
+}
+
+SfxOleStringPropertyBase::SfxOleStringPropertyBase(
+ sal_Int32 nPropId, sal_Int32 nPropType, rtl_TextEncoding eTextEnc, const String& rValue ) :
+ SfxOlePropertyBase( nPropId, nPropType ),
+ SfxOleStringHelper( eTextEnc ),
+ maValue( rValue )
+{
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleString8Property::SfxOleString8Property(
+ sal_Int32 nPropId, const SfxOleTextEncoding& rTextEnc ) :
+ SfxOleStringPropertyBase( nPropId, PROPTYPE_STRING8, rTextEnc )
+{
+}
+
+SfxOleString8Property::SfxOleString8Property(
+ sal_Int32 nPropId, const SfxOleTextEncoding& rTextEnc, const String& rValue ) :
+ SfxOleStringPropertyBase( nPropId, PROPTYPE_STRING8, rTextEnc, rValue )
+{
+}
+
+void SfxOleString8Property::ImplLoad( SvStream& rStrm )
+{
+ SetValue( LoadString8( rStrm ) );
+}
+
+void SfxOleString8Property::ImplSave( SvStream& rStrm )
+{
+ SaveString8( rStrm, GetValue() );
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleString16Property::SfxOleString16Property( sal_Int32 nPropId ) :
+ SfxOleStringPropertyBase( nPropId, PROPTYPE_STRING16, RTL_TEXTENCODING_UCS2 )
+{
+}
+
+SfxOleString16Property::SfxOleString16Property( sal_Int32 nPropId, const String& rValue ) :
+ SfxOleStringPropertyBase( nPropId, PROPTYPE_STRING16, RTL_TEXTENCODING_UCS2, rValue )
+{
+}
+
+void SfxOleString16Property::ImplLoad( SvStream& rStrm )
+{
+ SetValue( LoadString16( rStrm ) );
+}
+
+void SfxOleString16Property::ImplSave( SvStream& rStrm )
+{
+ SaveString16( rStrm, GetValue() );
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleFileTimeProperty::SfxOleFileTimeProperty( sal_Int32 nPropId ) :
+ SfxOlePropertyBase( nPropId, PROPTYPE_FILETIME )
+{
+}
+
+SfxOleFileTimeProperty::SfxOleFileTimeProperty( sal_Int32 nPropId, const util::DateTime& rDateTime ) :
+ SfxOlePropertyBase( nPropId, PROPTYPE_FILETIME ),
+ maDateTime( rDateTime )
+{
+}
+
+void SfxOleFileTimeProperty::ImplLoad( SvStream& rStrm )
+{
+ sal_uInt32 nLower, nUpper;
+ rStrm >> nLower >> nUpper;
+ ::DateTime aDateTime = DateTime::CreateFromWin32FileDateTime( nLower, nUpper );
+ // note: editing duration is stored as offset to TIMESTAMP_INVALID_DATETIME
+ // of course we should not convert the time zone of a duration!
+ // heuristic to detect editing durations (which we assume to be < 1 year):
+ // check only the year, not the entire date
+ if ( aDateTime.GetYear() != TIMESTAMP_INVALID_DATETIME.GetYear() )
+ aDateTime.ConvertToLocalTime();
+ maDateTime.Year = aDateTime.GetYear();
+ maDateTime.Month = aDateTime.GetMonth();
+ maDateTime.Day = aDateTime.GetDay();
+ maDateTime.Hours = aDateTime.GetHour();
+ maDateTime.Minutes = aDateTime.GetMin();
+ maDateTime.Seconds = aDateTime.GetSec();
+ maDateTime.HundredthSeconds = aDateTime.Get100Sec();
+}
+
+void SfxOleFileTimeProperty::ImplSave( SvStream& rStrm )
+{
+ DateTime aDateTimeUtc(
+ Date(
+ static_cast< USHORT >( maDateTime.Day ),
+ static_cast< USHORT >( maDateTime.Month ),
+ static_cast< USHORT >( maDateTime.Year ) ),
+ Time(
+ static_cast< ULONG >( maDateTime.Hours ),
+ static_cast< ULONG >( maDateTime.Minutes ),
+ static_cast< ULONG >( maDateTime.Seconds ),
+ static_cast< ULONG >( maDateTime.HundredthSeconds ) ) );
+ // invalid time stamp is not converted to UTC
+ // heuristic to detect editing durations (which we assume to be < 1 year):
+ // check only the year, not the entire date
+ if( aDateTimeUtc.IsValid()
+ && aDateTimeUtc.GetYear() != TIMESTAMP_INVALID_DATETIME.GetYear() ) {
+ aDateTimeUtc.ConvertToUTC();
+ }
+ sal_uInt32 nLower, nUpper;
+ aDateTimeUtc.GetWin32FileDateTime( nLower, nUpper );
+ rStrm << nLower << nUpper;
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleThumbnailProperty::SfxOleThumbnailProperty(
+ sal_Int32 nPropId, const uno::Sequence<sal_uInt8> & i_rData) :
+ SfxOlePropertyBase( nPropId, PROPTYPE_CLIPFMT ),
+ mData(i_rData)
+{
+}
+
+void SfxOleThumbnailProperty::ImplLoad( SvStream& )
+{
+ DBG_ERRORFILE( "SfxOleThumbnailProperty::ImplLoad - not implemented" );
+ SetError( SVSTREAM_INVALID_ACCESS );
+}
+
+void SfxOleThumbnailProperty::ImplSave( SvStream& rStrm )
+{
+ /* Type Contents
+ -----------------------------------------------------------------------
+ int32 size of following data
+ int32 clipboard format tag (see below)
+ byte[] clipboard data (see below)
+
+ Clipboard format tag:
+ -1 = Windows clipboard format
+ -2 = Macintosh clipboard format
+ -3 = GUID that contains a format identifier (FMTID)
+ >0 = custom clipboard format name plus data (see msdn site below)
+ 0 = no data
+
+ References:
+ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/stg/stg/propvariant.asp
+ http://jakarta.apache.org/poi/hpsf/thumbnails.html
+ http://linux.com.hk/docs/poi/org/apache/poi/hpsf/Thumbnail.html
+ http://sparks.discreet.com/knowledgebase/public/solutions/ExtractThumbnailImg.htm
+ */
+ if( IsValid() )
+ {
+ // clipboard size: clip_format_tag + data_format_tag + bitmap_len
+ sal_Int32 nClipSize = static_cast< sal_Int32 >( 4 + 4 + mData.getLength() );
+ rStrm << nClipSize << CLIPFMT_WIN << CLIPDATAFMT_DIB;
+ rStrm.Write( mData.getConstArray(), mData.getLength() );
+ }
+ else
+ {
+ DBG_ERRORFILE( "SfxOleThumbnailProperty::ImplSave - invalid thumbnail property" );
+ SetError( SVSTREAM_INVALID_ACCESS );
+ }
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleBlobProperty::SfxOleBlobProperty( sal_Int32 nPropId,
+ const uno::Sequence<sal_uInt8> & i_rData) :
+ SfxOlePropertyBase( nPropId, PROPTYPE_BLOB ),
+ mData(i_rData)
+{
+}
+
+void SfxOleBlobProperty::ImplLoad( SvStream& )
+{
+ DBG_ERRORFILE( "SfxOleBlobProperty::ImplLoad - not implemented" );
+ SetError( SVSTREAM_INVALID_ACCESS );
+}
+
+void SfxOleBlobProperty::ImplSave( SvStream& rStrm )
+{
+ if (IsValid()) {
+ rStrm.Write( mData.getConstArray(), mData.getLength() );
+ } else {
+ DBG_ERRORFILE( "SfxOleBlobProperty::ImplSave - invalid BLOB property" );
+ SetError( SVSTREAM_INVALID_ACCESS );
+ }
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleDictionaryProperty::SfxOleDictionaryProperty( const SfxOleTextEncoding& rTextEnc ) :
+ SfxOlePropertyBase( PROPID_DICTIONARY, 0 ),
+ SfxOleStringHelper( rTextEnc )
+{
+}
+
+const String& SfxOleDictionaryProperty::GetPropertyName( sal_Int32 nPropId ) const
+{
+ SfxOlePropNameMap::const_iterator aIt = maPropNameMap.find( nPropId );
+ return (aIt == maPropNameMap.end()) ? String::EmptyString() : aIt->second;
+}
+
+void SfxOleDictionaryProperty::SetPropertyName( sal_Int32 nPropId, const String& rPropName )
+{
+ maPropNameMap[ nPropId ] = rPropName;
+ // dictionary property contains number of pairs in property type field
+ SetPropType( static_cast< sal_Int32 >( maPropNameMap.size() ) );
+}
+
+void SfxOleDictionaryProperty::ImplLoad( SvStream& rStrm )
+{
+ // dictionary property contains number of pairs in property type field
+ sal_Int32 nNameCount = GetPropType();
+ // read property ID/name pairs
+ maPropNameMap.clear();
+ for( sal_Int32 nIdx = 0; (nIdx < nNameCount) && (rStrm.GetErrorCode() == SVSTREAM_OK) && !rStrm.IsEof(); ++nIdx )
+ {
+ sal_Int32 nPropId;
+ rStrm >> nPropId;
+ // name always stored as byte string
+ maPropNameMap[ nPropId ] = LoadString8( rStrm );
+ }
+}
+
+void SfxOleDictionaryProperty::ImplSave( SvStream& rStrm )
+{
+ // write property ID/name pairs
+ for( SfxOlePropNameMap::const_iterator aIt = maPropNameMap.begin(), aEnd = maPropNameMap.end(); aIt != aEnd; ++aIt )
+ {
+ rStrm << aIt->first;
+ // name always stored as byte string
+ SaveString8( rStrm, aIt->second );
+ }
+}
+
+// ----------------------------------------------------------------------------
+
+SfxOleSection::SfxOleSection( bool bSupportsDict ) :
+ maDictProp( maCodePageProp ),
+ mnStartPos( 0 ),
+ mbSupportsDict( bSupportsDict )
+{
+}
+
+SfxOlePropertyRef SfxOleSection::GetProperty( sal_Int32 nPropId ) const
+{
+ SfxOlePropertyRef xProp;
+ SfxOlePropMap::const_iterator aIt = maPropMap.find( nPropId );
+ if( aIt != maPropMap.end() )
+ xProp = aIt->second;
+ return xProp;
+}
+
+bool SfxOleSection::GetInt32Value( sal_Int32& rnValue, sal_Int32 nPropId ) const
+{
+ SfxOlePropertyRef xProp = GetProperty( nPropId );
+ const SfxOleInt32Property* pProp =
+ dynamic_cast< const SfxOleInt32Property* >( xProp.get() );
+ if( pProp )
+ rnValue = pProp->GetValue();
+ return pProp != 0;
+}
+
+bool SfxOleSection::GetDoubleValue( double& rfValue, sal_Int32 nPropId ) const
+{
+ SfxOlePropertyRef xProp = GetProperty( nPropId );
+ const SfxOleDoubleProperty* pProp =
+ dynamic_cast< const SfxOleDoubleProperty* >( xProp.get() );
+ if( pProp )
+ rfValue = pProp->GetValue();
+ return pProp != 0;
+}
+
+bool SfxOleSection::GetBoolValue( bool& rbValue, sal_Int32 nPropId ) const
+{
+ SfxOlePropertyRef xProp = GetProperty( nPropId );
+ const SfxOleBoolProperty* pProp =
+ dynamic_cast< const SfxOleBoolProperty* >( xProp.get() );
+ if( pProp )
+ rbValue = pProp->GetValue();
+ return pProp != 0;
+}
+
+bool SfxOleSection::GetStringValue( String& rValue, sal_Int32 nPropId ) const
+{
+ SfxOlePropertyRef xProp = GetProperty( nPropId );
+ const SfxOleStringPropertyBase* pProp =
+ dynamic_cast< const SfxOleStringPropertyBase* >( xProp.get() );
+ if( pProp )
+ rValue = pProp->GetValue();
+ return pProp != 0;
+}
+
+bool SfxOleSection::GetFileTimeValue( util::DateTime& rValue, sal_Int32 nPropId ) const
+{
+ SfxOlePropertyRef xProp = GetProperty( nPropId );
+ const SfxOleFileTimeProperty* pProp =
+ dynamic_cast< const SfxOleFileTimeProperty* >( xProp.get() );
+ if( pProp )
+ {
+ if ( pProp->GetValue() == TIMESTAMP_INVALID_UTILDATETIME )
+ rValue = util::DateTime();
+ else
+ rValue = pProp->GetValue();
+ }
+ return pProp != 0;
+}
+
+void SfxOleSection::SetProperty( SfxOlePropertyRef xProp )
+{
+ if( xProp.get() )
+ maPropMap[ xProp->GetPropId() ] = xProp;
+}
+
+void SfxOleSection::SetInt32Value( sal_Int32 nPropId, sal_Int32 nValue )
+{
+ SetProperty( SfxOlePropertyRef( new SfxOleInt32Property( nPropId, nValue ) ) );
+}
+
+void SfxOleSection::SetDoubleValue( sal_Int32 nPropId, double fValue )
+{
+ SetProperty( SfxOlePropertyRef( new SfxOleDoubleProperty( nPropId, fValue ) ) );
+}
+
+void SfxOleSection::SetBoolValue( sal_Int32 nPropId, bool bValue )
+{
+ SetProperty( SfxOlePropertyRef( new SfxOleBoolProperty( nPropId, bValue ) ) );
+}
+
+bool SfxOleSection::SetStringValue( sal_Int32 nPropId, const String& rValue, bool bSkipEmpty )
+{
+ bool bInserted = !bSkipEmpty || (rValue.Len() > 0);
+ if( bInserted )
+ SetProperty( SfxOlePropertyRef( new SfxOleString8Property( nPropId, maCodePageProp, rValue ) ) );
+ return bInserted;
+}
+
+void SfxOleSection::SetFileTimeValue( sal_Int32 nPropId, const util::DateTime& rValue )
+{
+ if ( rValue.Year == 0 || rValue.Month == 0 || rValue.Day == 0 )
+ SetProperty( SfxOlePropertyRef( new SfxOleFileTimeProperty( nPropId, TIMESTAMP_INVALID_UTILDATETIME ) ) );
+ else
+ SetProperty( SfxOlePropertyRef( new SfxOleFileTimeProperty( nPropId, rValue ) ) );
+}
+
+void SfxOleSection::SetThumbnailValue( sal_Int32 nPropId,
+ const uno::Sequence<sal_uInt8> & i_rData)
+{
+ SfxOleThumbnailProperty* pThumbnail = new SfxOleThumbnailProperty( nPropId, i_rData );
+ SfxOlePropertyRef xProp( pThumbnail ); // take ownership
+ if( pThumbnail->IsValid() )
+ SetProperty( xProp );
+}
+
+void SfxOleSection::SetBlobValue( sal_Int32 nPropId,
+ const uno::Sequence<sal_uInt8> & i_rData)
+{
+ SfxOleBlobProperty* pBlob( new SfxOleBlobProperty( nPropId, i_rData ) );
+ SfxOlePropertyRef xProp( pBlob );
+ if( pBlob->IsValid() ) {
+ SetProperty( xProp );
+ }
+}
+
+Any SfxOleSection::GetAnyValue( sal_Int32 nPropId ) const
+{
+ Any aValue;
+ sal_Int32 nInt32 = 0;
+ double fDouble = 0.0;
+ bool bBool = false;
+ String aString;
+ ::com::sun::star::util::DateTime aApiDateTime;
+
+ if( GetInt32Value( nInt32, nPropId ) )
+ aValue <<= nInt32;
+ else if( GetDoubleValue( fDouble, nPropId ) )
+ aValue <<= fDouble;
+ else if( GetBoolValue( bBool, nPropId ) )
+ ::comphelper::setBOOL( aValue, bBool ? sal_True : sal_False );
+ else if( GetStringValue( aString, nPropId ) )
+ aValue <<= OUString( aString );
+ else if( GetFileTimeValue( aApiDateTime, nPropId ) )
+ {
+ aValue <<= aApiDateTime;
+ }
+ return aValue;
+}
+
+bool SfxOleSection::SetAnyValue( sal_Int32 nPropId, const Any& rValue )
+{
+ bool bInserted = true;
+ sal_Int32 nInt32 = 0;
+ double fDouble = 0.0;
+ OUString aString;
+ ::com::sun::star::util::DateTime aApiDateTime;
+
+ if( rValue.getValueType() == ::getBooleanCppuType() )
+ SetBoolValue( nPropId, ::comphelper::getBOOL( rValue ) == sal_True );
+ else if( rValue >>= nInt32 )
+ SetInt32Value( nPropId, nInt32 );
+ else if( rValue >>= fDouble )
+ SetDoubleValue( nPropId, fDouble );
+ else if( rValue >>= aString )
+ bInserted = SetStringValue( nPropId, aString );
+ else if( rValue >>= aApiDateTime )
+ {
+ SetFileTimeValue( nPropId, aApiDateTime );
+ }
+ else
+ bInserted = false;
+ return bInserted;
+}
+
+const String& SfxOleSection::GetPropertyName( sal_Int32 nPropId ) const
+{
+ return maDictProp.GetPropertyName( nPropId );
+}
+
+void SfxOleSection::SetPropertyName( sal_Int32 nPropId, const String& rPropName )
+{
+ maDictProp.SetPropertyName( nPropId, rPropName );
+}
+
+void SfxOleSection::GetPropertyIds( ::std::vector< sal_Int32 >& rPropIds ) const
+{
+ rPropIds.clear();
+ for( SfxOlePropMap::const_iterator aIt = maPropMap.begin(), aEnd = maPropMap.end(); aIt != aEnd; ++aIt )
+ rPropIds.push_back( aIt->first );
+}
+
+sal_Int32 SfxOleSection::GetFreePropertyId() const
+{
+ return maPropMap.empty() ? PROPID_FIRSTCUSTOM : (maPropMap.rbegin()->first + 1);
+}
+
+void SfxOleSection::ImplLoad( SvStream& rStrm )
+{
+ // read section header
+ mnStartPos = rStrm.Tell();
+ sal_uInt32 nSize;
+ sal_Int32 nPropCount;
+ rStrm >> nSize >> nPropCount;
+
+ // read property ID/position pairs
+ typedef ::std::map< sal_Int32, sal_uInt32 > SfxOlePropPosMap;
+ SfxOlePropPosMap aPropPosMap;
+ for( sal_Int32 nPropIdx = 0; (nPropIdx < nPropCount) && (rStrm.GetErrorCode() == SVSTREAM_OK) && !rStrm.IsEof(); ++nPropIdx )
+ {
+ sal_Int32 nPropId;
+ sal_uInt32 nPropPos;
+ rStrm >> nPropId >> nPropPos;
+ aPropPosMap[ nPropId ] = nPropPos;
+ }
+
+ // read codepage property
+ SfxOlePropPosMap::iterator aCodePageIt = aPropPosMap.find( PROPID_CODEPAGE );
+ if( (aCodePageIt != aPropPosMap.end()) && SeekToPropertyPos( rStrm, aCodePageIt->second ) )
+ {
+ // codepage property must be of type signed int-16
+ sal_Int32 nPropType;
+ rStrm >> nPropType;
+ if( nPropType == PROPTYPE_INT16 )
+ LoadObject( rStrm, maCodePageProp );
+ // remove property position
+ aPropPosMap.erase( aCodePageIt );
+ }
+
+ // read dictionary property
+ SfxOlePropPosMap::iterator aDictIt = aPropPosMap.find( PROPID_DICTIONARY );
+ if( (aDictIt != aPropPosMap.end()) && SeekToPropertyPos( rStrm, aDictIt->second ) )
+ {
+ // #i66214# #i66428# applications may write broken dictionary properties in wrong sections
+ if( mbSupportsDict )
+ {
+ // dictionary property contains number of pairs in property type field
+ sal_Int32 nNameCount;
+ rStrm >> nNameCount;
+ maDictProp.SetNameCount( nNameCount );
+ LoadObject( rStrm, maDictProp );
+ }
+ // always remove position of dictionary property (do not try to read it again below)
+ aPropPosMap.erase( aDictIt );
+ }
+
+ // read other properties
+ maPropMap.clear();
+ for( SfxOlePropPosMap::const_iterator aIt = aPropPosMap.begin(), aEnd = aPropPosMap.end(); aIt != aEnd; ++aIt )
+ if( SeekToPropertyPos( rStrm, aIt->second ) )
+ LoadProperty( rStrm, aIt->first );
+}
+
+void SfxOleSection::ImplSave( SvStream& rStrm )
+{
+ /* Always export with UTF-8 encoding. All dependent properties (bytestring
+ and dictionary) will be updated automatically. */
+ maCodePageProp.SetTextEncoding( RTL_TEXTENCODING_UTF8 );
+
+ // write section header
+ mnStartPos = rStrm.Tell();
+ sal_Int32 nPropCount = static_cast< sal_Int32 >( maPropMap.size() + 1 );
+ if( maDictProp.HasPropertyNames() )
+ ++nPropCount;
+ rStrm << sal_uInt32( 0 ) << nPropCount;
+
+ // write placeholders for property ID/position pairs
+ sal_Size nPropPosPos = rStrm.Tell();
+ rStrm.SeekRel( static_cast< sal_sSize >( 8 * nPropCount ) );
+
+ // write dictionary property
+ if( maDictProp.HasPropertyNames() )
+ SaveProperty( rStrm, maDictProp, nPropPosPos );
+ // write codepage property
+ SaveProperty( rStrm, maCodePageProp, nPropPosPos );
+ // write other properties
+ for( SfxOlePropMap::const_iterator aIt = maPropMap.begin(), aEnd = maPropMap.end(); aIt != aEnd; ++aIt )
+ SaveProperty( rStrm, *aIt->second, nPropPosPos );
+
+ // write section size (first field in section header)
+ rStrm.Seek( STREAM_SEEK_TO_END );
+ sal_uInt32 nSectSize = static_cast< sal_uInt32 >( rStrm.Tell() - mnStartPos );
+ rStrm.Seek( mnStartPos );
+ rStrm << nSectSize;
+}
+
+bool SfxOleSection::SeekToPropertyPos( SvStream& rStrm, sal_uInt32 nPropPos ) const
+{
+ rStrm.Seek( static_cast< sal_Size >( mnStartPos + nPropPos ) );
+ return rStrm.GetErrorCode() == SVSTREAM_OK;
+}
+
+void SfxOleSection::LoadProperty( SvStream& rStrm, sal_Int32 nPropId )
+{
+ // property data type
+ sal_Int32 nPropType;
+ rStrm >> nPropType;
+ // create empty property object
+ SfxOlePropertyRef xProp;
+ switch( nPropType )
+ {
+ case PROPTYPE_INT32:
+ xProp.reset( new SfxOleInt32Property( nPropId ) );
+ break;
+ case PROPTYPE_DOUBLE:
+ xProp.reset( new SfxOleDoubleProperty( nPropId ) );
+ break;
+ case PROPTYPE_BOOL:
+ xProp.reset( new SfxOleBoolProperty( nPropId ) );
+ break;
+ case PROPTYPE_STRING8:
+ xProp.reset( new SfxOleString8Property( nPropId, maCodePageProp ) );
+ break;
+ case PROPTYPE_STRING16:
+ xProp.reset( new SfxOleString16Property( nPropId ) );
+ break;
+ case PROPTYPE_FILETIME:
+ xProp.reset( new SfxOleFileTimeProperty( nPropId ) );
+ break;
+ }
+ // load property contents
+ if( xProp.get() )
+ {
+ SetError( xProp->Load( rStrm ) );
+ maPropMap[ nPropId ] = xProp;
+ }
+}
+
+void SfxOleSection::SaveProperty( SvStream& rStrm, SfxOlePropertyBase& rProp, sal_Size& rnPropPosPos )
+{
+ rStrm.Seek( STREAM_SEEK_TO_END );
+ sal_uInt32 nPropPos = static_cast< sal_uInt32 >( rStrm.Tell() - mnStartPos );
+ // property data type
+ rStrm << rProp.GetPropType();
+ // write property contents
+ SaveObject( rStrm, rProp );
+ // align to 32-bit
+ while( (rStrm.Tell() & 3) != 0 )
+ rStrm << sal_uInt8( 0 );
+ // write property ID/position pair
+ rStrm.Seek( rnPropPosPos );
+ rStrm << rProp.GetPropId() << nPropPos;
+ rnPropPosPos = rStrm.Tell();
+}
+
+// ----------------------------------------------------------------------------
+
+ErrCode SfxOlePropertySet::LoadPropertySet( SotStorage* pStrg, const String& rStrmName )
+{
+ if( pStrg )
+ {
+ SotStorageStreamRef xStrm = pStrg->OpenSotStream( rStrmName, STREAM_STD_READ );
+ if( xStrm.Is() && (xStrm->GetError() == SVSTREAM_OK) )
+ {
+ xStrm->SetBufferSize( STREAM_BUFFER_SIZE );
+ Load( *xStrm );
+ }
+ else
+ SetError( ERRCODE_IO_ACCESSDENIED );
+ }
+ else
+ SetError( ERRCODE_IO_ACCESSDENIED );
+ return GetError();
+}
+
+ErrCode SfxOlePropertySet::SavePropertySet( SotStorage* pStrg, const String& rStrmName )
+{
+ if( pStrg )
+ {
+ SotStorageStreamRef xStrm = pStrg->OpenSotStream( rStrmName, STREAM_TRUNC | STREAM_STD_WRITE );
+ if( xStrm.Is() )
+ Save( *xStrm );
+ else
+ SetError( ERRCODE_IO_ACCESSDENIED );
+ }
+ else
+ SetError( ERRCODE_IO_ACCESSDENIED );
+ return GetError();
+}
+
+SfxOleSectionRef SfxOlePropertySet::GetSection( SfxOleSectionType eSection ) const
+{
+ return GetSection( GetSectionGuid( eSection ) );
+}
+
+SfxOleSectionRef SfxOlePropertySet::GetSection( const SvGlobalName& rSectionGuid ) const
+{
+ SfxOleSectionRef xSection;
+ SfxOleSectionMap::const_iterator aIt = maSectionMap.find( rSectionGuid );
+ if( aIt != maSectionMap.end() )
+ xSection = aIt->second;
+ return xSection;
+}
+
+SfxOleSection& SfxOlePropertySet::AddSection( SfxOleSectionType eSection )
+{
+ return AddSection( GetSectionGuid( eSection ) );
+}
+
+SfxOleSection& SfxOlePropertySet::AddSection( const SvGlobalName& rSectionGuid )
+{
+ SfxOleSectionRef xSection = GetSection( rSectionGuid );
+ if( !xSection )
+ {
+ // #i66214# #i66428# applications may write broken dictionary properties in wrong sections
+ bool bSupportsDict = rSectionGuid == GetSectionGuid( SECTION_CUSTOM );
+ xSection.reset( new SfxOleSection( bSupportsDict ) );
+ maSectionMap[ rSectionGuid ] = xSection;
+ }
+ return *xSection;
+}
+
+void SfxOlePropertySet::ImplLoad( SvStream& rStrm )
+{
+ // read property set header
+ sal_uInt16 nByteOrder;
+ sal_uInt16 nVersion;
+ sal_uInt16 nOsMinor;
+ sal_uInt16 nOsType;
+ SvGlobalName aGuid;
+ sal_Int32 nSectCount;
+ rStrm >> nByteOrder >> nVersion >> nOsMinor >> nOsType >> aGuid >> nSectCount;
+
+ // read sections
+ sal_Size nSectPosPos = rStrm.Tell();
+ for( sal_Int32 nSectIdx = 0; (nSectIdx < nSectCount) && (rStrm.GetErrorCode() == SVSTREAM_OK) && !rStrm.IsEof(); ++nSectIdx )
+ {
+ // read section guid/position pair
+ rStrm.Seek( nSectPosPos );
+ SvGlobalName aSectGuid;
+ sal_uInt32 nSectPos;
+ rStrm >> aSectGuid >> nSectPos;
+ nSectPosPos = rStrm.Tell();
+ // read section
+ rStrm.Seek( static_cast< sal_Size >( nSectPos ) );
+ if( rStrm.GetErrorCode() == SVSTREAM_OK )
+ LoadObject( rStrm, AddSection( aSectGuid ) );
+ }
+}
+
+void SfxOlePropertySet::ImplSave( SvStream& rStrm )
+{
+ // write property set header
+ SvGlobalName aGuid;
+ sal_Int32 nSectCount = static_cast< sal_Int32 >( maSectionMap.size() );
+ rStrm << sal_uInt16( 0xFFFE ) // byte order
+ << sal_uInt16( 0 ) // version
+ << sal_uInt16( 1 ) // OS minor version
+ << sal_uInt16( 2 ) // OS type always windows for text encoding
+ << aGuid // unused guid
+ << nSectCount; // number of sections
+
+ // write placeholders for section guid/position pairs
+ sal_Size nSectPosPos = rStrm.Tell();
+ rStrm.SeekRel( static_cast< sal_sSize >( 20 * nSectCount ) );
+
+ // write sections
+ for( SfxOleSectionMap::const_iterator aIt = maSectionMap.begin(), aEnd = maSectionMap.end(); aIt != aEnd; ++aIt )
+ {
+ SfxOleSection& rSection = *aIt->second;
+ rStrm.Seek( STREAM_SEEK_TO_END );
+ sal_uInt32 nSectPos = static_cast< sal_uInt32 >( rStrm.Tell() );
+ // write the section
+ SaveObject( rStrm, rSection );
+ // write section guid/position pair
+ rStrm.Seek( nSectPosPos );
+ rStrm << aIt->first << nSectPos;
+ nSectPosPos = rStrm.Tell();
+ }
+}
+
+const SvGlobalName& SfxOlePropertySet::GetSectionGuid( SfxOleSectionType eSection )
+{
+ static const SvGlobalName saGlobalGuid( 0xF29F85E0, 0x4FF9, 0x1068, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 );
+ static const SvGlobalName saBuiltInGuid( 0xD5CDD502, 0x2E9C, 0x101B, 0x93, 0x97, 0x08, 0x00, 0x2B, 0x2C, 0xF9, 0xAE );
+ static const SvGlobalName saCustomGuid( 0xD5CDD505, 0x2E9C, 0x101B, 0x93, 0x97, 0x08, 0x00, 0x2B, 0x2C, 0xF9, 0xAE );
+ static const SvGlobalName saEmptyGuid;
+ switch( eSection )
+ {
+ case SECTION_GLOBAL: return saGlobalGuid;
+ case SECTION_BUILTIN: return saBuiltInGuid;
+ case SECTION_CUSTOM: return saCustomGuid;
+ default: DBG_ERRORFILE( "SfxOlePropertySet::GetSectionGuid - unknown section type" );
+ }
+ return saEmptyGuid;
+}
+
+// ============================================================================
+
+//} // namespace
diff --git a/sfx2/source/doc/oleprops.hxx b/sfx2/source/doc/oleprops.hxx
new file mode 100755
index 000000000000..5bd586576ac8
--- /dev/null
+++ b/sfx2/source/doc/oleprops.hxx
@@ -0,0 +1,404 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <map>
+#include <boost/shared_ptr.hpp>
+#include <sot/storage.hxx>
+#include <vcl/bitmapex.hxx>
+
+#include <com/sun/star/util/DateTime.hpp>
+
+
+// ============================================================================
+
+//namespace {
+
+// ============================================================================
+// property type IDs
+const sal_Int32 PROPTYPE_INT16 = 2;
+const sal_Int32 PROPTYPE_INT32 = 3;
+const sal_Int32 PROPTYPE_FLOAT = 4;
+const sal_Int32 PROPTYPE_DOUBLE = 5;
+const sal_Int32 PROPTYPE_DATE = 7;
+const sal_Int32 PROPTYPE_STRING = 8;
+const sal_Int32 PROPTYPE_STATUS = 10;
+const sal_Int32 PROPTYPE_BOOL = 11;
+const sal_Int32 PROPTYPE_VARIANT = 12;
+const sal_Int32 PROPTYPE_INT8 = 16;
+const sal_Int32 PROPTYPE_UINT8 = 17;
+const sal_Int32 PROPTYPE_UINT16 = 18;
+const sal_Int32 PROPTYPE_UINT32 = 19;
+const sal_Int32 PROPTYPE_INT64 = 20;
+const sal_Int32 PROPTYPE_UINT64 = 21;
+const sal_Int32 PROPTYPE_STRING8 = 30;
+const sal_Int32 PROPTYPE_STRING16 = 31;
+const sal_Int32 PROPTYPE_FILETIME = 64;
+const sal_Int32 PROPTYPE_BLOB = 65;
+const sal_Int32 PROPTYPE_CLIPFMT = 71;
+
+// static property IDs
+const sal_Int32 PROPID_DICTIONARY = 0;
+const sal_Int32 PROPID_CODEPAGE = 1;
+const sal_Int32 PROPID_FIRSTCUSTOM = 2;
+
+// property IDs for GlobalDocPropertySet
+const sal_Int32 PROPID_TITLE = 2;
+const sal_Int32 PROPID_SUBJECT = 3;
+const sal_Int32 PROPID_AUTHOR = 4;
+const sal_Int32 PROPID_KEYWORDS = 5;
+const sal_Int32 PROPID_COMMENTS = 6;
+const sal_Int32 PROPID_TEMPLATE = 7;
+const sal_Int32 PROPID_LASTAUTHOR = 8;
+const sal_Int32 PROPID_REVNUMBER = 9;
+const sal_Int32 PROPID_EDITTIME = 10;
+const sal_Int32 PROPID_LASTPRINTED = 11;
+const sal_Int32 PROPID_CREATED = 12;
+const sal_Int32 PROPID_LASTSAVED = 13;
+const sal_Int32 PROPID_THUMBNAIL = 17;
+
+// predefined codepages
+const sal_uInt16 CODEPAGE_UNKNOWN = 0;
+const sal_uInt16 CODEPAGE_UNICODE = 1200;
+const sal_uInt16 CODEPAGE_UTF8 = 65001;
+
+// predefined clipboard format IDs
+const sal_Int32 CLIPFMT_WIN = -1;
+
+// predefined clipboard data format IDs
+const sal_Int32 CLIPDATAFMT_DIB = 8;
+
+// ============================================================================
+// ============================================================================
+
+/** Helper for classes that need text encoding settings.
+
+ Classes derived from this class will include functions to store and use
+ text encoding settings and to convert Windows codepage constants.
+ */
+class SfxOleTextEncoding
+{
+public:
+ inline explicit SfxOleTextEncoding() :
+ mxTextEnc( new rtl_TextEncoding( gsl_getSystemTextEncoding() ) ) {}
+ inline explicit SfxOleTextEncoding( rtl_TextEncoding eTextEnc ) :
+ mxTextEnc( new rtl_TextEncoding( eTextEnc ) ) {}
+ inline explicit SfxOleTextEncoding( sal_Int16 nCodePage ) :
+ mxTextEnc( new rtl_TextEncoding ) { SetCodePage( nCodePage ); }
+
+ /** Returns the current text encoding identifier. */
+ inline rtl_TextEncoding GetTextEncoding() const { return *mxTextEnc; }
+ /** Sets the passed text encoding. */
+ inline void SetTextEncoding( rtl_TextEncoding eTextEnc ) { *mxTextEnc = eTextEnc; }
+
+ /** Returns true, if this object contains Unicode text encoding. */
+ inline bool IsUnicode() const { return GetTextEncoding() == RTL_TEXTENCODING_UCS2; }
+ /** Sets Unicode text encoding to this object. */
+ inline void SetUnicode() { SetTextEncoding( RTL_TEXTENCODING_UCS2 ); }
+
+ /** Converts the current settings to a Windows codepage identifier. */
+ sal_uInt16 GetCodePage() const;
+ /** Sets the current text encoding from a Windows codepage identifier. */
+ void SetCodePage( sal_uInt16 nCodePage );
+
+private:
+ typedef ::boost::shared_ptr< rtl_TextEncoding > TextEncRef;
+ TextEncRef mxTextEnc;
+};
+
+// ============================================================================
+
+/** Helper for classes that need to load or save string values.
+
+ Classes derived from this class contain functions to load and save string
+ values with the text encoding passed in the constructor.
+ */
+class SfxOleStringHelper : public SfxOleTextEncoding
+{
+public:
+ /** Creates a string helper object depending on an external text encoding. */
+ inline explicit SfxOleStringHelper( const SfxOleTextEncoding& rTextEnc ) :
+ SfxOleTextEncoding( rTextEnc ) {}
+ /** Creates a string helper object with own text encoding. */
+ inline explicit SfxOleStringHelper( rtl_TextEncoding eTextEnc ) :
+ SfxOleTextEncoding( eTextEnc ) {}
+
+ /** Loads a string from the passed stream with current encoding (maybe Unicode). */
+ String LoadString8( SvStream& rStrm ) const;
+ /** Saves a string to the passed stream with current encoding (maybe Unicode). */
+ void SaveString8( SvStream& rStrm, const String& rValue ) const;
+
+ /** Loads a Unicode string from the passed stream, ignores own encoding. */
+ String LoadString16( SvStream& rStrm ) const;
+ /** Saves a Unicode string to the passed stream, ignores own encoding. */
+ void SaveString16( SvStream& rStrm, const String& rValue ) const;
+
+private:
+ String ImplLoadString8( SvStream& rStrm ) const;
+ String ImplLoadString16( SvStream& rStrm ) const;
+ void ImplSaveString8( SvStream& rStrm, const String& rValue ) const;
+ void ImplSaveString16( SvStream& rStrm, const String& rValue ) const;
+};
+
+
+// ============================================================================
+// ============================================================================
+
+/** Base class for all classes related to OLE property sets.
+
+ Derived calsses have to implement the pure virtual functions ImplLoad() and
+ ImplSave().
+ */
+class SfxOleObjectBase
+{
+public:
+ inline explicit SfxOleObjectBase() : mnErrCode( ERRCODE_NONE ) {}
+ virtual ~SfxOleObjectBase();
+
+ /** Returns true, if an error code (other than ERRCODE_NONE) is set. */
+ inline bool HasError() const { return mnErrCode != ERRCODE_NONE; }
+ /** Returns the current error code. */
+ inline ErrCode GetError() const { return mnErrCode; }
+
+ /** Loads this object from the passed stream. Calls virtual ImplLoad(). */
+ ErrCode Load( SvStream& rStrm );
+ /** Saves this object to the passed stream. Calls virtual ImplSave(). */
+ ErrCode Save( SvStream& rStrm );
+
+protected:
+ /** Sets the passed error code. Will be returned by Load() and Save() functions.
+ Always the first error code is stored. Multiple calls have no effect. */
+ inline void SetError( ErrCode nErrCode ) { if( !HasError() ) mnErrCode = nErrCode; }
+ /** Loads the passed object from the stream. Sets returned error code as own error. */
+ void LoadObject( SvStream& rStrm, SfxOleObjectBase& rObj );
+ /** Saves the passed object to the stream. Sets returned error code as own error. */
+ void SaveObject( SvStream& rStrm, SfxOleObjectBase& rObj );
+
+private:
+ /** Derived classes implement loading the object from the passed steam. */
+ virtual void ImplLoad( SvStream& rStrm ) = 0;
+ /** Derived classes implement saving the object to the passed steam. */
+ virtual void ImplSave( SvStream& rStrm ) = 0;
+
+private:
+ ErrCode mnErrCode; /// Current error code.
+};
+
+// ============================================================================
+// ============================================================================
+
+/** Base class for all OLE property objects. */
+class SfxOlePropertyBase : public SfxOleObjectBase
+{
+public:
+ inline explicit SfxOlePropertyBase( sal_Int32 nPropId, sal_Int32 nPropType ) :
+ mnPropId( nPropId ), mnPropType( nPropType ) {}
+
+ inline sal_Int32 GetPropId() const { return mnPropId; }
+ inline sal_Int32 GetPropType() const { return mnPropType; }
+
+protected:
+ inline void SetPropId( sal_Int32 nPropId ) { mnPropId = nPropId; }
+ inline void SetPropType( sal_Int32 nPropType ) { mnPropType = nPropType; }
+
+private:
+ sal_Int32 mnPropId;
+ sal_Int32 mnPropType;
+};
+
+typedef ::boost::shared_ptr< SfxOlePropertyBase > SfxOlePropertyRef;
+
+// ============================================================================
+/** Property representing the codepage used to encode bytestrings in the entire property set. */
+class SfxOleCodePageProperty : public SfxOlePropertyBase, public SfxOleTextEncoding
+{
+public:
+ explicit SfxOleCodePageProperty();
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+};
+
+// ============================================================================
+// ============================================================================
+
+/** Property containing custom names for other properties in the property set. */
+class SfxOleDictionaryProperty : public SfxOlePropertyBase, public SfxOleStringHelper
+{
+public:
+ explicit SfxOleDictionaryProperty( const SfxOleTextEncoding& rTextEnc );
+
+ /** Returns true, if the property contains at least one custom property name. */
+ inline bool HasPropertyNames() const { return !maPropNameMap.empty(); }
+ /** Prepares the property for loading. Does not affect contained names for its own. */
+ inline void SetNameCount( sal_Int32 nNameCount ) { SetPropType( nNameCount ); }
+
+ /** Returns the custom name for the passed property ID, or an empty string, if name not found. */
+ const String& GetPropertyName( sal_Int32 nPropId ) const;
+ /** Sets a custom name for the passed property ID. */
+ void SetPropertyName( sal_Int32 nPropId, const String& rPropName );
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+
+private:
+ typedef ::std::map< sal_Int32, String > SfxOlePropNameMap;
+ SfxOlePropNameMap maPropNameMap;
+};
+
+// ============================================================================
+// ============================================================================
+
+/** A section in a property set. Contains properties with unique identifiers. */
+class SfxOleSection : public SfxOleObjectBase
+{
+private:
+ typedef ::std::map< sal_Int32, SfxOlePropertyRef > SfxOlePropMap;
+
+public:
+ explicit SfxOleSection( bool bSupportsDict );
+
+ /** Returns the property with the passed ID, or an empty reference, if nothing found. */
+ SfxOlePropertyRef GetProperty( sal_Int32 nPropId ) const;
+ /** Returns the value of a signed int32 property with the passed ID in rnValue.
+ @return true = Property found, rnValue is valid; false = Property not found. */
+ bool GetInt32Value( sal_Int32& rnValue, sal_Int32 nPropId ) const;
+ /** Returns the value of a floating-point property with the passed ID in rfValue.
+ @return true = Property found, rfValue is valid; false = Property not found. */
+ bool GetDoubleValue( double& rfValue, sal_Int32 nPropId ) const;
+ /** Returns the value of a boolean property with the passed ID in rbValue.
+ @return true = Property found, rbValue is valid; false = Property not found. */
+ bool GetBoolValue( bool& rbValue, sal_Int32 nPropId ) const;
+ /** Returns the value of a string property with the passed ID in rValue.
+ @return true = Property found, rValue is valid; false = Property not found. */
+ bool GetStringValue( String& rValue, sal_Int32 nPropId ) const;
+ /** Returns the value of a time stamp property with the passed ID in rValue.
+ @return true = Property found, rValue is valid; false = Property not found. */
+ bool GetFileTimeValue( ::com::sun::star::util::DateTime& rValue, sal_Int32 nPropId ) const;
+
+ /** Adds the passed property to the property set. Drops an existing old property. */
+ void SetProperty( SfxOlePropertyRef xProp );
+ /** Inserts a signed int32 property with the passed value. */
+ void SetInt32Value( sal_Int32 nPropId, sal_Int32 nValue );
+ /** Inserts a foating-point property with the passed value. */
+ void SetDoubleValue( sal_Int32 nPropId, double fValue );
+ /** Inserts a boolean property with the passed value. */
+ void SetBoolValue( sal_Int32 nPropId, bool bValue );
+ /** Inserts a string property with the passed value.
+ @return true = Property inserted; false = String was empty, property not inserted. */
+ bool SetStringValue( sal_Int32 nPropId, const String& rValue, bool bSkipEmpty = true );
+ /** Inserts a time stamp property with the passed value. */
+ void SetFileTimeValue( sal_Int32 nPropId, const ::com::sun::star::util::DateTime& rValue );
+ /** Inserts a thumbnail property from the passed meta file. */
+ void SetThumbnailValue( sal_Int32 nPropId,
+ const ::com::sun::star::uno::Sequence<sal_uInt8> & i_rData);
+ /** Inserts a BLOB property with the passed data. */
+ void SetBlobValue( sal_Int32 nPropId,
+ const ::com::sun::star::uno::Sequence<sal_uInt8> & i_rData);
+
+ /** Returns the value of the property with the passed ID in a UNO any. */
+ com::sun::star::uno::Any GetAnyValue( sal_Int32 nPropId ) const;
+ /** Inserts a property created from the passed any.
+ @return true = Property converted and inserted; false = Property type not supported. */
+ bool SetAnyValue( sal_Int32 nPropId, const com::sun::star::uno::Any& rValue );
+
+ /** Returns the custom name for the passed property ID, or an empty string, if name not found. */
+ const String& GetPropertyName( sal_Int32 nPropId ) const;
+ /** Sets a custom name for the passed property ID. */
+ void SetPropertyName( sal_Int32 nPropId, const String& rPropName );
+
+ /** Returns the identifiers of all existing properties in the passed vector. */
+ void GetPropertyIds( ::std::vector< sal_Int32 >& rPropIds ) const;
+ /** Returns a property identifier not used in this section. */
+ sal_Int32 GetFreePropertyId() const;
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+
+ bool SeekToPropertyPos( SvStream& rStrm, sal_uInt32 nPropPos ) const;
+ void LoadProperty( SvStream& rStrm, sal_Int32 nPropId );
+ void SaveProperty( SvStream& rStrm, SfxOlePropertyBase& rProp, sal_Size& rnPropPosPos );
+
+private:
+ SfxOlePropMap maPropMap; /// All properties in this section, by identifier.
+ SfxOleCodePageProperty maCodePageProp; /// The codepage property.
+ SfxOleDictionaryProperty maDictProp; /// The dictionary property.
+ sal_Size mnStartPos; /// Start stream position of the section.
+ bool mbSupportsDict; /// true = section supports dictionary.
+};
+
+typedef ::boost::shared_ptr< SfxOleSection > SfxOleSectionRef;
+
+// ============================================================================
+// ============================================================================
+
+/** Enumerates different section types in OLE property sets. */
+enum SfxOleSectionType
+{
+ SECTION_GLOBAL, /// Globally defined properties.
+ SECTION_BUILTIN, /// Properties built into MS Office.
+ SECTION_CUSTOM /// Custom properties.
+};
+
+// ============================================================================
+
+/** Represents a complete property set, may consist of several property sections. */
+class SfxOlePropertySet : public SfxOleObjectBase
+{
+public:
+ inline explicit SfxOlePropertySet() {}
+
+ /** Loads this object from the passed storage. */
+ ErrCode LoadPropertySet( SotStorage* pStrg, const String& rStrmName );
+ /** Saves this object to the passed storage. */
+ ErrCode SavePropertySet( SotStorage* pStrg, const String& rStrmName );
+
+ /** Returns the specified section, or an empty reference, if nothing found. */
+ SfxOleSectionRef GetSection( SfxOleSectionType eSection ) const;
+ /** Returns the specified section, or an empty reference, if nothing found. */
+ SfxOleSectionRef GetSection( const SvGlobalName& rSectionGuid ) const;
+
+ /** Creates and returns the specified section, or just returns it if it already exists. */
+ SfxOleSection& AddSection( SfxOleSectionType eSection );
+ /** Creates and returns the specified section, or just returns it if it already exists. */
+ SfxOleSection& AddSection( const SvGlobalName& rSectionGuid );
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+
+ /** Returns the GUID for the specified section. */
+ static const SvGlobalName& GetSectionGuid( SfxOleSectionType eSection );
+
+private:
+ typedef ::std::map< SvGlobalName, SfxOleSectionRef > SfxOleSectionMap;
+ SfxOleSectionMap maSectionMap;
+};
+
+//};
diff --git a/sfx2/source/doc/ownsubfilterservice.cxx b/sfx2/source/doc/ownsubfilterservice.cxx
new file mode 100644
index 000000000000..9cab42889b6e
--- /dev/null
+++ b/sfx2/source/doc/ownsubfilterservice.cxx
@@ -0,0 +1,165 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/frame/DoubleInitializationException.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+
+#include <ownsubfilterservice.hxx>
+#include <sfx2/objsh.hxx>
+
+using namespace ::com::sun::star;
+
+namespace sfx2 {
+
+//-------------------------------------------------------------------------
+OwnSubFilterService::OwnSubFilterService( const uno::Reference < lang::XMultiServiceFactory >& xFactory )
+: m_xFactory( xFactory )
+, m_pObjectShell( NULL )
+{
+}
+
+//-------------------------------------------------------------------------
+OwnSubFilterService::~OwnSubFilterService()
+{
+}
+
+//-------------------------------------------------------------------------
+uno::Sequence< ::rtl::OUString > SAL_CALL OwnSubFilterService::impl_getStaticSupportedServiceNames()
+{
+ uno::Sequence< ::rtl::OUString > aRet(2);
+ aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.document.OwnSubFilter");
+ aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.document.OwnSubFilter");
+ return aRet;
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString SAL_CALL OwnSubFilterService::impl_getStaticImplementationName()
+{
+ return ::rtl::OUString::createFromAscii("com.sun.star.comp.document.OwnSubFilter");
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< uno::XInterface > SAL_CALL OwnSubFilterService::impl_staticCreateSelfInstance(
+ const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
+{
+ return uno::Reference< uno::XInterface >( *new OwnSubFilterService( xServiceManager ) );
+}
+
+//-------------------------------------------------------------------------
+uno::Reference< lang::XSingleServiceFactory > SAL_CALL OwnSubFilterService::impl_createFactory(
+ const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
+{
+ return ::cppu::createSingleFactory( xServiceManager,
+ OwnSubFilterService::impl_getStaticImplementationName(),
+ OwnSubFilterService::impl_staticCreateSelfInstance,
+ OwnSubFilterService::impl_getStaticSupportedServiceNames() );
+}
+
+
+// XFilter
+
+//-------------------------------------------------------------------------
+sal_Bool SAL_CALL OwnSubFilterService::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
+ throw (uno::RuntimeException)
+{
+ if ( !m_pObjectShell )
+ throw uno::RuntimeException();
+
+ return m_pObjectShell->ImportFromGeneratedStream_Impl( m_xStream, aDescriptor );
+}
+
+//-------------------------------------------------------------------------
+void SAL_CALL OwnSubFilterService::cancel()
+ throw (uno::RuntimeException)
+{
+ // not implemented
+}
+
+
+// XInitialization
+
+//-------------------------------------------------------------------------
+void SAL_CALL OwnSubFilterService::initialize( const uno::Sequence< uno::Any >& aArguments )
+ throw (uno::Exception, uno::RuntimeException)
+{
+ if ( !m_xFactory.is() )
+ throw uno::RuntimeException();
+
+ if ( aArguments.getLength() != 2 )
+ throw lang::IllegalArgumentException();
+
+ if ( m_pObjectShell )
+ throw frame::DoubleInitializationException();
+
+ if ( ( aArguments[1] >>= m_xStream ) && m_xStream.is()
+ && ( aArguments[0] >>= m_xModel ) && m_xModel.is() )
+ {
+ ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( m_xModel, uno::UNO_QUERY_THROW );
+ ::com::sun::star::uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
+ sal_Int64 nHandle = xObj->getSomething( aSeq );
+ if ( nHandle )
+ m_pObjectShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
+ }
+
+ if ( !m_pObjectShell )
+ throw lang::IllegalArgumentException();
+}
+
+
+// XServiceInfo
+
+//-------------------------------------------------------------------------
+::rtl::OUString SAL_CALL OwnSubFilterService::getImplementationName()
+ throw ( uno::RuntimeException )
+{
+ return impl_getStaticImplementationName();
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SAL_CALL OwnSubFilterService::supportsService( const ::rtl::OUString& ServiceName )
+ throw ( uno::RuntimeException )
+{
+ uno::Sequence< ::rtl::OUString > aSeq = impl_getStaticSupportedServiceNames();
+
+ for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
+ if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
+ return sal_True;
+
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+uno::Sequence< ::rtl::OUString > SAL_CALL OwnSubFilterService::getSupportedServiceNames()
+ throw ( uno::RuntimeException )
+{
+ return impl_getStaticSupportedServiceNames();
+}
+
+} // namespace sfx2
+
diff --git a/sfx2/source/doc/plugin.cxx b/sfx2/source/doc/plugin.cxx
new file mode 100644
index 000000000000..9ff8c73acbf6
--- /dev/null
+++ b/sfx2/source/doc/plugin.cxx
@@ -0,0 +1,266 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "plugin.hxx"
+#include <com/sun/star/plugin/XPluginManager.hpp>
+#include <com/sun/star/plugin/PluginMode.hpp>
+#include <com/sun/star/awt/XControl.hpp>
+
+#include <tools/debug.hxx>
+#include <rtl/ustring.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <svtools/miscopt.hxx>
+#include <vcl/window.hxx>
+
+using namespace ::com::sun::star;
+
+namespace sfx2
+{
+
+class PluginWindow_Impl : public Window
+{
+public:
+ uno::Reference < awt::XWindow > xWindow;
+ PluginWindow_Impl( Window* pParent )
+ : Window( pParent, WB_CLIPCHILDREN )
+ {}
+
+ virtual void Resize();
+};
+
+void PluginWindow_Impl::Resize()
+{
+ Size aSize( GetOutputSizePixel() );
+ if ( xWindow.is() )
+ xWindow->setPosSize( 0, 0, aSize.Width(), aSize.Height(), WINDOW_POSSIZE_SIZE );
+}
+
+#define PROPERTY_UNBOUND 0
+
+#define WID_COMMANDS 1
+#define WID_MIMETYPE 2
+#define WID_URL 3
+const SfxItemPropertyMapEntry* lcl_GetPluginPropertyMap_Impl()
+{
+ static SfxItemPropertyMapEntry aPluginPropertyMap_Impl[] =
+ {
+ { MAP_CHAR_LEN("PluginCommands"), WID_COMMANDS, &::getCppuType((::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >*)0), PROPERTY_UNBOUND, 0},
+ { MAP_CHAR_LEN("PluginMimeType"), WID_MIMETYPE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ { MAP_CHAR_LEN("PluginURL"), WID_URL , &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
+ {0,0,0,0,0,0}
+ };
+ return aPluginPropertyMap_Impl;
+}
+
+SFX_IMPL_XSERVICEINFO( PluginObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.PluginObject" )
+SFX_IMPL_SINGLEFACTORY( PluginObject );
+
+PluginObject::PluginObject( const uno::Reference < lang::XMultiServiceFactory >& rFact )
+ : mxFact( rFact )
+ , maPropMap( lcl_GetPluginPropertyMap_Impl() )
+{
+}
+
+PluginObject::~PluginObject()
+{
+}
+
+void SAL_CALL PluginObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
+{
+ if ( aArguments.getLength() )
+ aArguments[0] >>= mxObj;
+}
+
+sal_Bool SAL_CALL PluginObject::load(
+ const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
+ const uno::Reference < frame::XFrame >& xFrame )
+throw( uno::RuntimeException )
+{
+ uno::Reference< plugin::XPluginManager > xPMgr( mxFact->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.plugin.PluginManager") ), uno::UNO_QUERY );
+ if (!xPMgr.is() )
+ return FALSE;
+
+ if ( SvtMiscOptions().IsPluginsEnabled() )
+ {
+ Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
+ PluginWindow_Impl* pWin = new PluginWindow_Impl( pParent );
+ pWin->SetSizePixel( pParent->GetOutputSizePixel() );
+ pWin->SetBackground();
+ pWin->Show();
+
+ ULONG nCount = maCmdList.Count();
+ uno::Sequence < ::rtl::OUString > aCmds( nCount ), aArgs( nCount );
+ ::rtl::OUString *pCmds = aCmds.getArray(), *pArgs = aArgs.getArray();
+ for( ULONG i = 0; i < nCount; i++ )
+ {
+ SvCommand & rCmd = maCmdList.GetObject( i );
+ pCmds[i] = rCmd.GetCommand();
+ pArgs[i] = rCmd.GetArgument();
+ }
+
+ mxPlugin = xPMgr->createPluginFromURL(
+ xPMgr->createPluginContext(), plugin::PluginMode::EMBED, aCmds, aArgs, uno::Reference< awt::XToolkit >(),
+ uno::Reference< awt::XWindowPeer >( pWin->GetComponentInterface() ), maURL );
+
+ if ( mxPlugin.is() )
+ {
+ uno::Reference< awt::XWindow > xWindow( mxPlugin, uno::UNO_QUERY );
+ if ( xWindow.is() )
+ {
+ pWin->xWindow = xWindow;
+ pWin->Resize();
+ xWindow->setVisible( TRUE );
+ }
+
+ try
+ {
+ uno::Reference< awt::XControl > xControl( mxPlugin, uno::UNO_QUERY );
+ if( xControl.is() )
+ {
+ uno::Reference< awt::XControlModel > xModel = xControl->getModel();
+ uno::Reference< beans::XPropertySet > xProp( xModel, ::uno::UNO_QUERY );
+ if( xProp.is() )
+ {
+ uno::Any aValue = xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
+ aValue >>= maURL;
+ aValue = xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TYPE" ) ) );
+ aValue >>= maMimeType;
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+
+ uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
+
+ // we must destroy the plugin before the parent is destroyed
+ xWindow->addEventListener( this );
+ xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
+ return mxPlugin.is() ? TRUE : FALSE;
+ }
+
+ return FALSE;
+}
+
+void SAL_CALL PluginObject::cancel() throw( com::sun::star::uno::RuntimeException )
+{
+ uno::Reference< lang::XComponent > xComp( mxPlugin, uno::UNO_QUERY );
+ if (xComp.is())
+ xComp->dispose();
+ mxPlugin = 0;
+}
+
+void SAL_CALL PluginObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL PluginObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL PluginObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL PluginObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
+{
+ cancel();
+}
+
+uno::Reference< beans::XPropertySetInfo > SAL_CALL PluginObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
+{
+ static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap );
+ return xInfo;
+}
+
+void SAL_CALL PluginObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
+ throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
+{
+ if ( aPropertyName.equalsAscii("PluginURL") )
+ {
+ aAny >>= maURL;
+ }
+ else if ( aPropertyName.equalsAscii("PluginMimeType") )
+ {
+ aAny >>= maMimeType;
+ }
+ else if ( aPropertyName.equalsAscii("PluginCommands") )
+ {
+ maCmdList.Clear();
+ uno::Sequence < beans::PropertyValue > aCommandSequence;
+ if( aAny >>= aCommandSequence )
+ maCmdList.FillFromSequence( aCommandSequence );
+ }
+ else
+ throw beans::UnknownPropertyException();
+}
+
+uno::Any SAL_CALL PluginObject::getPropertyValue(const ::rtl::OUString& aPropertyName)
+ throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
+{
+ uno::Any aAny;
+ if ( aPropertyName.equalsAscii("PluginURL") )
+ {
+ aAny <<= maURL;
+ }
+ else if ( aPropertyName.equalsAscii("PluginMimeType") )
+ {
+ aAny <<= maMimeType;
+ }
+ else if ( aPropertyName.equalsAscii("PluginCommands") )
+ {
+ uno::Sequence< beans::PropertyValue > aCommandSequence;
+ maCmdList.FillSequence( aCommandSequence );
+ aAny <<= aCommandSequence;
+ }
+ else
+ throw beans::UnknownPropertyException();
+ return aAny;
+}
+
+void SAL_CALL PluginObject::addPropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL PluginObject::removePropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL PluginObject::addVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL PluginObject::removeVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+}
diff --git a/sfx2/source/doc/printhelper.cxx b/sfx2/source/doc/printhelper.cxx
new file mode 100755
index 000000000000..1dc2423bcdaf
--- /dev/null
+++ b/sfx2/source/doc/printhelper.cxx
@@ -0,0 +1,832 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "printhelper.hxx"
+
+#include <com/sun/star/view/XPrintJob.hpp>
+#include <com/sun/star/awt/Size.hpp>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/view/PaperFormat.hpp>
+#include <com/sun/star/view/PaperOrientation.hpp>
+#include <com/sun/star/ucb/NameClash.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/lang/EventObject.hpp>
+#include <com/sun/star/view/DuplexMode.hpp>
+
+#include <svl/lstner.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/eitem.hxx>
+#include <unotools/tempfile.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <osl/file.hxx>
+#include <osl/thread.hxx>
+#include <tools/urlobj.hxx>
+#include <ucbhelper/content.hxx>
+#include <cppuhelper/interfacecontainer.hxx>
+#include <vos/mutex.hxx>
+#include <cppuhelper/implbase1.hxx>
+
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/printer.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/event.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+
+struct IMPL_PrintListener_DataContainer : public SfxListener
+{
+ SfxObjectShellRef m_pObjectShell;
+ ::cppu::OMultiTypeInterfaceContainerHelper m_aInterfaceContainer;
+ uno::Reference< com::sun::star::view::XPrintJob> m_xPrintJob;
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aPrintOptions;
+
+ IMPL_PrintListener_DataContainer( ::osl::Mutex& aMutex)
+ : m_pObjectShell ( 0 )
+ , m_aInterfaceContainer ( aMutex )
+ {
+ }
+
+
+ void Notify( SfxBroadcaster& aBC ,
+ const SfxHint& aHint ) ;
+};
+
+awt::Size impl_Size_Object2Struct( const Size& aSize )
+{
+ awt::Size aReturnValue;
+ aReturnValue.Width = aSize.Width() ;
+ aReturnValue.Height = aSize.Height() ;
+ return aReturnValue ;
+}
+
+Size impl_Size_Struct2Object( const awt::Size& aSize )
+{
+ Size aReturnValue;
+ aReturnValue.Width() = aSize.Width ;
+ aReturnValue.Height() = aSize.Height ;
+ return aReturnValue ;
+}
+
+class SfxPrintJob_Impl : public cppu::WeakImplHelper1
+<
+ com::sun::star::view::XPrintJob
+>
+{
+ IMPL_PrintListener_DataContainer* m_pData;
+
+public:
+ SfxPrintJob_Impl( IMPL_PrintListener_DataContainer* pData );
+ virtual Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPrintOptions( ) throw (RuntimeException);
+ virtual Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPrinter( ) throw (RuntimeException);
+ virtual Reference< ::com::sun::star::view::XPrintable > SAL_CALL getPrintable( ) throw (RuntimeException);
+ virtual void SAL_CALL cancelJob() throw (RuntimeException);
+};
+
+SfxPrintJob_Impl::SfxPrintJob_Impl( IMPL_PrintListener_DataContainer* pData )
+ : m_pData( pData )
+{
+}
+
+Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL SfxPrintJob_Impl::getPrintOptions() throw (RuntimeException)
+{
+ return m_pData->m_aPrintOptions;
+}
+
+Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL SfxPrintJob_Impl::getPrinter() throw (RuntimeException)
+{
+ if( m_pData->m_pObjectShell.Is() )
+ {
+ Reference < view::XPrintable > xPrintable( m_pData->m_pObjectShell->GetModel(), UNO_QUERY );
+ if ( xPrintable.is() )
+ return xPrintable->getPrinter();
+ }
+ return Sequence< ::com::sun::star::beans::PropertyValue >();
+}
+
+Reference< ::com::sun::star::view::XPrintable > SAL_CALL SfxPrintJob_Impl::getPrintable() throw (RuntimeException)
+{
+ Reference < view::XPrintable > xPrintable( m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->GetModel() : NULL, UNO_QUERY );
+ return xPrintable;
+}
+
+void SAL_CALL SfxPrintJob_Impl::cancelJob() throw (RuntimeException)
+{
+ // FIXME: how to cancel PrintJob via API?!
+ if( m_pData->m_pObjectShell.Is() )
+ m_pData->m_pObjectShell->Broadcast( SfxPrintingHint( -2 ) );
+}
+
+SfxPrintHelper::SfxPrintHelper()
+{
+ m_pData = new IMPL_PrintListener_DataContainer(m_aMutex);
+}
+
+void SAL_CALL SfxPrintHelper::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
+{
+ if ( aArguments.getLength() )
+ {
+ com::sun::star::uno::Reference < com::sun::star::frame::XModel > xModel;
+ aArguments[0] >>= xModel;
+ uno::Reference < lang::XUnoTunnel > xObj( xModel, uno::UNO_QUERY );
+ uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
+ sal_Int64 nHandle = xObj->getSomething( aSeq );
+ if ( nHandle )
+ {
+ m_pData->m_pObjectShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
+ m_pData->StartListening(*m_pData->m_pObjectShell);
+ }
+ }
+}
+
+SfxPrintHelper::~SfxPrintHelper()
+{
+ delete m_pData;
+}
+
+namespace
+{
+ view::PaperFormat convertToPaperFormat(Paper eFormat)
+ {
+ view::PaperFormat eRet;
+ switch (eFormat)
+ {
+ case PAPER_A3:
+ eRet = view::PaperFormat_A3;
+ break;
+ case PAPER_A4:
+ eRet = view::PaperFormat_A4;
+ break;
+ case PAPER_A5:
+ eRet = view::PaperFormat_A5;
+ break;
+ case PAPER_B4_ISO:
+ eRet = view::PaperFormat_B4;
+ break;
+ case PAPER_B5_ISO:
+ eRet = view::PaperFormat_B5;
+ break;
+ case PAPER_LETTER:
+ eRet = view::PaperFormat_LETTER;
+ break;
+ case PAPER_LEGAL:
+ eRet = view::PaperFormat_LEGAL;
+ break;
+ case PAPER_TABLOID:
+ eRet = view::PaperFormat_TABLOID;
+ break;
+ case PAPER_USER:
+ default:
+ eRet = view::PaperFormat_USER;
+ break;
+ }
+ return eRet;
+ }
+
+ Paper convertToPaper(view::PaperFormat eFormat)
+ {
+ Paper eRet(PAPER_USER);
+ switch (eFormat)
+ {
+ case view::PaperFormat_A3:
+ eRet = PAPER_A3;
+ break;
+ case view::PaperFormat_A4:
+ eRet = PAPER_A4;
+ break;
+ case view::PaperFormat_A5:
+ eRet = PAPER_A5;
+ break;
+ case view::PaperFormat_B4:
+ eRet = PAPER_B4_ISO;
+ break;
+ case view::PaperFormat_B5:
+ eRet = PAPER_B5_ISO;
+ break;
+ case view::PaperFormat_LETTER:
+ eRet = PAPER_LETTER;
+ break;
+ case view::PaperFormat_LEGAL:
+ eRet = PAPER_LEGAL;
+ break;
+ case view::PaperFormat_TABLOID:
+ eRet = PAPER_TABLOID;
+ break;
+ case view::PaperFormat_USER:
+ eRet = PAPER_USER;
+ break;
+ case view::PaperFormat_MAKE_FIXED_SIZE:
+ break;
+ //deliberate no default to force warn on a new papersize
+ }
+ return eRet;
+ }
+}
+
+//________________________________________________________________________________________________________
+// XPrintable
+//________________________________________________________________________________________________________
+
+uno::Sequence< beans::PropertyValue > SAL_CALL SfxPrintHelper::getPrinter() throw(::com::sun::star::uno::RuntimeException)
+{
+ // object already disposed?
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ // search for any view of this document that is currently printing
+ const Printer *pPrinter = NULL;
+ SfxViewFrame *pViewFrm = m_pData->m_pObjectShell.Is() ? SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False ) : 0;
+ SfxViewFrame* pFirst = pViewFrm;
+ while ( pViewFrm && !pPrinter )
+ {
+ pPrinter = pViewFrm->GetViewShell()->GetActivePrinter();
+ pViewFrm = SfxViewFrame::GetNext( *pViewFrm, m_pData->m_pObjectShell, sal_False );
+ }
+
+ // if no view is printing currently, use the permanent SfxPrinter instance
+ if ( !pPrinter && pFirst )
+ pPrinter = pFirst->GetViewShell()->GetPrinter(sal_True);
+
+ if ( !pPrinter )
+ return uno::Sequence< beans::PropertyValue >();
+
+ uno::Sequence< beans::PropertyValue > aPrinter(8);
+
+ aPrinter.getArray()[7].Name = DEFINE_CONST_UNICODE( "CanSetPaperSize" );
+ aPrinter.getArray()[7].Value <<= ( pPrinter->HasSupport( SUPPORT_SET_PAPERSIZE ) );
+
+ aPrinter.getArray()[6].Name = DEFINE_CONST_UNICODE( "CanSetPaperFormat" );
+ aPrinter.getArray()[6].Value <<= ( pPrinter->HasSupport( SUPPORT_SET_PAPER ) );
+
+ aPrinter.getArray()[5].Name = DEFINE_CONST_UNICODE( "CanSetPaperOrientation" );
+ aPrinter.getArray()[5].Value <<= ( pPrinter->HasSupport( SUPPORT_SET_ORIENTATION ) );
+
+ aPrinter.getArray()[4].Name = DEFINE_CONST_UNICODE( "IsBusy" );
+ aPrinter.getArray()[4].Value <<= ( pPrinter->IsPrinting() );
+
+ aPrinter.getArray()[3].Name = DEFINE_CONST_UNICODE( "PaperSize" );
+ awt::Size aSize = impl_Size_Object2Struct(pPrinter->GetPaperSize() );
+ aPrinter.getArray()[3].Value <<= aSize;
+
+ aPrinter.getArray()[2].Name = DEFINE_CONST_UNICODE( "PaperFormat" );
+ view::PaperFormat eFormat = convertToPaperFormat(pPrinter->GetPaper());
+ aPrinter.getArray()[2].Value <<= eFormat;
+
+ aPrinter.getArray()[1].Name = DEFINE_CONST_UNICODE( "PaperOrientation" );
+ view::PaperOrientation eOrient = (view::PaperOrientation)pPrinter->GetOrientation();
+ aPrinter.getArray()[1].Value <<= eOrient;
+
+ aPrinter.getArray()[0].Name = DEFINE_CONST_UNICODE( "Name" );
+ String sStringTemp = pPrinter->GetName() ;
+ aPrinter.getArray()[0].Value <<= ::rtl::OUString( sStringTemp );
+
+ return aPrinter;
+}
+
+//________________________________________________________________________________________________________
+// XPrintable
+//________________________________________________________________________________________________________
+
+void SfxPrintHelper::impl_setPrinter(const uno::Sequence< beans::PropertyValue >& rPrinter,SfxPrinter*& pPrinter,sal_uInt16& nChangeFlags,SfxViewShell*& pViewSh)
+
+{
+ // alten Printer beschaffen
+ SfxViewFrame *pViewFrm = m_pData->m_pObjectShell.Is() ?
+ SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False ) : 0;
+ if ( !pViewFrm )
+ return;
+
+ pViewSh = pViewFrm->GetViewShell();
+ pPrinter = pViewSh->GetPrinter(sal_True);
+ if ( !pPrinter )
+ return;
+
+ // new Printer-Name available?
+ nChangeFlags = 0;
+ sal_Int32 lDummy = 0;
+ for ( int n = 0; n < rPrinter.getLength(); ++n )
+ {
+ // get Property-Value from printer description
+ const beans::PropertyValue &rProp = rPrinter.getConstArray()[n];
+
+ // Name-Property?
+ if ( rProp.Name.compareToAscii( "Name" ) == 0 )
+ {
+ OUSTRING sTemp;
+ if ( ( rProp.Value >>= sTemp ) == sal_False )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+
+ String aPrinterName( sTemp ) ;
+ if ( aPrinterName != pPrinter->GetName() )
+ {
+ pPrinter = new SfxPrinter( pPrinter->GetOptions().Clone(), aPrinterName );
+ nChangeFlags = SFX_PRINTER_PRINTER;
+ }
+ break;
+ }
+ }
+
+ Size aSetPaperSize( 0, 0);
+ view::PaperFormat nPaperFormat = view::PaperFormat_USER;
+
+ // other properties
+ for ( int i = 0; i < rPrinter.getLength(); ++i )
+ {
+ // get Property-Value from printer description
+ const beans::PropertyValue &rProp = rPrinter.getConstArray()[i];
+
+ // PaperOrientation-Property?
+ if ( rProp.Name.compareToAscii( "PaperOrientation" ) == 0 )
+ {
+ view::PaperOrientation eOrient;
+ if ( ( rProp.Value >>= eOrient ) == sal_False )
+ {
+ if ( ( rProp.Value >>= lDummy ) == sal_False )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ eOrient = ( view::PaperOrientation) lDummy;
+ }
+
+ if ( (Orientation) eOrient != pPrinter->GetOrientation() )
+ {
+ pPrinter->SetOrientation( (Orientation) eOrient );
+ nChangeFlags |= SFX_PRINTER_CHG_ORIENTATION;
+ }
+ }
+
+ // PaperFormat-Property?
+ else if ( rProp.Name.compareToAscii( "PaperFormat" ) == 0 )
+ {
+ if ( ( rProp.Value >>= nPaperFormat ) == sal_False )
+ {
+ if ( ( rProp.Value >>= lDummy ) == sal_False )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ nPaperFormat = ( view::PaperFormat ) lDummy;
+ }
+
+ if ( convertToPaper(nPaperFormat) != pPrinter->GetPaper() )
+ {
+ pPrinter->SetPaper( convertToPaper(nPaperFormat) );
+ nChangeFlags |= SFX_PRINTER_CHG_SIZE;
+ }
+ }
+
+ // PaperSize-Property?
+ else if ( rProp.Name.compareToAscii( "PaperSize" ) == 0 )
+ {
+ awt::Size aTempSize ;
+ if ( ( rProp.Value >>= aTempSize ) == sal_False )
+ {
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ }
+ else
+ {
+ aSetPaperSize = impl_Size_Struct2Object(aTempSize);
+ }
+ }
+
+ // PrinterTray-Property
+ else if ( rProp.Name.compareToAscii( "PrinterPaperTray" ) == 0 )
+ {
+ rtl::OUString aTmp;
+ if ( ( rProp.Value >>= aTmp ) == sal_False )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ USHORT nCount = pPrinter->GetPaperBinCount();
+ for (USHORT nBin=0; nBin<nCount; nBin++)
+ {
+ ::rtl::OUString aName( pPrinter->GetPaperBinName(nBin) );
+ if ( aName == aTmp )
+ {
+ pPrinter->SetPaperBin(nBin);
+ break;
+ }
+ }
+ }
+ }
+
+ //os 12.11.98: die PaperSize darf nur gesetzt werden, wenn tatsaechlich
+ //PAPER_USER gilt, sonst koennte vom Treiber ein falsches Format gewaehlt werden
+ if(nPaperFormat == view::PaperFormat_USER && aSetPaperSize.Width())
+ {
+ //JP 23.09.98 - Bug 56929 - MapMode von 100mm in die am
+ // Device gesetzten umrechnen. Zusaetzlich nur dann
+ // setzen, wenn sie wirklich veraendert wurden.
+ aSetPaperSize = pPrinter->LogicToPixel( aSetPaperSize, MAP_100TH_MM );
+ if( aSetPaperSize != pPrinter->GetPaperSizePixel() )
+ {
+ pPrinter->SetPaperSizeUser( pPrinter->PixelToLogic( aSetPaperSize ) );
+ nChangeFlags |= SFX_PRINTER_CHG_SIZE;
+ }
+ }
+
+ // #96772#: wait until printing is done
+ SfxPrinter* pDocPrinter = pViewSh->GetPrinter();
+ while ( pDocPrinter->IsPrinting() )
+ Application::Yield();
+}
+
+void SAL_CALL SfxPrintHelper::setPrinter(const uno::Sequence< beans::PropertyValue >& rPrinter)
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
+{
+ // object already disposed?
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ SfxViewShell* pViewSh = NULL;
+ SfxPrinter* pPrinter = NULL;
+ sal_uInt16 nChangeFlags = 0;
+ impl_setPrinter(rPrinter,pPrinter,nChangeFlags,pViewSh);
+ // set new printer
+ if ( pViewSh && pPrinter )
+ pViewSh->SetPrinter( pPrinter, nChangeFlags, false );
+}
+
+//________________________________________________________________________________________________________
+// ImplPrintWatch thread for asynchronous printing with moving temp. file to ucb location
+//________________________________________________________________________________________________________
+
+/* This implements a thread which will be started to wait for asynchronous
+ print jobs to temp. localy files. If they finish we move the temp. files
+ to her right locations by using the ucb.
+ */
+class ImplUCBPrintWatcher : public ::osl::Thread
+{
+ private:
+ /// of course we must know the printer which execute the job
+ SfxPrinter* m_pPrinter;
+ /// this describes the target location for the printed temp file
+ String m_sTargetURL;
+ /// it holds the temp file alive, till the print job will finish and remove it from disk automaticly if the object die
+ ::utl::TempFile* m_pTempFile;
+
+ public:
+ /* initialize this watcher but don't start it */
+ ImplUCBPrintWatcher( SfxPrinter* pPrinter, ::utl::TempFile* pTempFile, const String& sTargetURL )
+ : m_pPrinter ( pPrinter )
+ , m_sTargetURL( sTargetURL )
+ , m_pTempFile ( pTempFile )
+ {}
+
+ /* waits for finishing of the print job and moves the temp file afterwards
+ Note: Starting of the job is done outside this thread!
+ But we have to free some of the given ressources on heap!
+ */
+ void SAL_CALL run()
+ {
+ /* SAFE { */
+ {
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ while( m_pPrinter->IsPrinting() )
+ Application::Yield();
+ m_pPrinter = NULL; // don't delete it! It's borrowed only :-)
+ }
+ /* } SAFE */
+
+ // lock for further using of our member isn't neccessary - because
+ // we truns alone by defenition. Nobody join for us nor use us ...
+ ImplUCBPrintWatcher::moveAndDeleteTemp(&m_pTempFile,m_sTargetURL);
+
+ // finishing of this run() method will call onTerminate() automaticly
+ // kill this thread there!
+ }
+
+ /* nobody wait for this thread. We must kill ourself ...
+ */
+ void SAL_CALL onTerminated()
+ {
+ delete this;
+ }
+
+ /* static helper to move the temp. file to the target location by using the ucb
+ It's static to be useable from outside too. So it's not realy neccessary to start
+ the thread, if finishing of the job was detected outside this thread.
+ But it must be called without using a corresponding thread for the given parameter!
+ */
+ static void moveAndDeleteTemp( ::utl::TempFile** ppTempFile, const String& sTargetURL )
+ {
+ // move the file
+ try
+ {
+ INetURLObject aSplitter(sTargetURL);
+ String sFileName = aSplitter.getName(
+ INetURLObject::LAST_SEGMENT,
+ true,
+ INetURLObject::DECODE_WITH_CHARSET);
+ if (aSplitter.removeSegment() && sFileName.Len()>0)
+ {
+ ::ucbhelper::Content aSource(
+ ::rtl::OUString((*ppTempFile)->GetURL()),
+ ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >());
+
+ ::ucbhelper::Content aTarget(
+ ::rtl::OUString(aSplitter.GetMainURL(INetURLObject::NO_DECODE)),
+ ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >());
+
+ aTarget.transferContent(
+ aSource,
+ ::ucbhelper::InsertOperation_COPY,
+ ::rtl::OUString(sFileName),
+ ::com::sun::star::ucb::NameClash::OVERWRITE);
+ }
+ }
+ catch( ::com::sun::star::ucb::ContentCreationException& ) { DBG_ERROR("content create exception"); }
+ catch( ::com::sun::star::ucb::CommandAbortedException& ) { DBG_ERROR("command abort exception"); }
+ catch( ::com::sun::star::uno::RuntimeException& ) { DBG_ERROR("runtime exception"); }
+ catch( ::com::sun::star::uno::Exception& ) { DBG_ERROR("unknown exception"); }
+
+ // kill the temp file!
+ delete *ppTempFile;
+ *ppTempFile = NULL;
+ }
+};
+
+//------------------------------------------------
+
+//________________________________________________________________________________________________________
+// XPrintable
+//________________________________________________________________________________________________________
+void SAL_CALL SfxPrintHelper::print(const uno::Sequence< beans::PropertyValue >& rOptions)
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
+{
+ if( Application::GetSettings().GetMiscSettings().GetDisablePrinting() )
+ return;
+
+ // object already disposed?
+ // object already disposed?
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ // get view for sfx printing capabilities
+ SfxViewFrame *pViewFrm = m_pData->m_pObjectShell.Is() ?
+ SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False ) : 0;
+ if ( !pViewFrm )
+ return;
+ SfxViewShell* pView = pViewFrm->GetViewShell();
+ if ( !pView )
+ return;
+
+// SfxAllItemSet aArgs( pView->GetPool() );
+ sal_Bool bMonitor = sal_False;
+ // We need this information at the end of this method, if we start the vcl printer
+ // by executing the slot. Because if it is a ucb relevant URL we must wait for
+ // finishing the print job and move the temporary local file by using the ucb
+ // to the right location. But in case of no file name is given or it is already
+ // a local one we can supress this special handling. Because then vcl makes all
+ // right for us.
+ String sUcbUrl;
+ ::utl::TempFile* pUCBPrintTempFile = NULL;
+
+ uno::Sequence < beans::PropertyValue > aCheckedArgs( rOptions.getLength() );
+ sal_Int32 nProps = 0;
+ sal_Bool bWaitUntilEnd = sal_False;
+ sal_Int16 nDuplexMode = ::com::sun::star::view::DuplexMode::UNKNOWN;
+ for ( int n = 0; n < rOptions.getLength(); ++n )
+ {
+ // get Property-Value from options
+ const beans::PropertyValue &rProp = rOptions.getConstArray()[n];
+
+ // FileName-Property?
+ if ( rProp.Name.compareToAscii( "FileName" ) == 0 )
+ {
+ // unpack th URL and check for a valid and well known protocol
+ OUSTRING sTemp;
+ if (
+ ( rProp.Value.getValueType()!=::getCppuType((const OUSTRING*)0)) ||
+ (!(rProp.Value>>=sTemp))
+ )
+ {
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ }
+
+ String sPath ;
+ String sURL (sTemp);
+ INetURLObject aCheck(sURL );
+ if (aCheck.GetProtocol()==INET_PROT_NOT_VALID)
+ {
+ // OK - it's not a valid URL. But may it's a simple
+ // system path directly. It will be supported for historical
+ // reasons. Otherwhise we break to much external code ...
+ // We try to convert it to a file URL. If its possible
+ // we put the system path to the item set and let vcl work with it.
+ // No ucb or thread will be neccessary then. In case it couldnt be
+ // converted its not an URL nor a system path. Then we can't accept
+ // this parameter and have to throw an exception.
+ ::rtl::OUString sSystemPath(sTemp);
+ ::rtl::OUString sFileURL;
+ if (::osl::FileBase::getFileURLFromSystemPath(sSystemPath,sFileURL)!=::osl::FileBase::E_None)
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ aCheckedArgs[nProps].Name = rProp.Name;
+ aCheckedArgs[nProps++].Value <<= sFileURL;
+ // and append the local filename
+ aCheckedArgs.realloc( aCheckedArgs.getLength()+1 );
+ aCheckedArgs[nProps].Name = rtl::OUString::createFromAscii("LocalFileName");
+ aCheckedArgs[nProps++].Value <<= ::rtl::OUString( sTemp );
+ }
+ else
+ // It's a valid URL. but now we must know, if it is a local one or not.
+ // It's a question of using ucb or not!
+ if (::utl::LocalFileHelper::ConvertURLToSystemPath(sURL,sPath))
+ {
+ // it's a local file, we can use vcl without special handling
+ // And we have to use the system notation of the incoming URL.
+ // But it into the descriptor and let the slot be executed at
+ // the end of this method.
+ aCheckedArgs[nProps].Name = rProp.Name;
+ aCheckedArgs[nProps++].Value <<= sTemp;
+ // and append the local filename
+ aCheckedArgs.realloc( aCheckedArgs.getLength()+1 );
+ aCheckedArgs[nProps].Name = rtl::OUString::createFromAscii("LocalFileName");
+ aCheckedArgs[nProps++].Value <<= ::rtl::OUString( sPath );
+ }
+ else
+ {
+ // it's an ucb target. So we must use a temp. file for vcl
+ // and move it after printing by using the ucb.
+ // Create a temp file on the heap (because it must delete the
+ // real file on disk automaticly if it die - bt we have to share it with
+ // some other sources ... e.g. the ImplUCBPrintWatcher).
+ // And we put the name of this temp file to the descriptor instead
+ // of the URL. The URL we save for later using seperatly.
+ // Execution of the print job will be done later by executing
+ // a slot ...
+ pUCBPrintTempFile = new ::utl::TempFile();
+ pUCBPrintTempFile->EnableKillingFile();
+
+ //FIXME: does it work?
+ aCheckedArgs[nProps].Name = rtl::OUString::createFromAscii("LocalFileName");
+ aCheckedArgs[nProps++].Value <<= ::rtl::OUString( pUCBPrintTempFile->GetFileName() );
+ sUcbUrl = sURL;
+ }
+ }
+
+ // CopyCount-Property
+ else if ( rProp.Name.compareToAscii( "CopyCount" ) == 0 )
+ {
+ sal_Int32 nCopies = 0;
+ if ( ( rProp.Value >>= nCopies ) == sal_False )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+
+ aCheckedArgs[nProps].Name = rProp.Name;
+ aCheckedArgs[nProps++].Value <<= nCopies;
+ }
+
+ // Collate-Property
+ // Sort-Property (deprecated)
+ else if ( rProp.Name.compareToAscii( "Collate" ) == 0 ||
+ ( rProp.Name.compareToAscii( "Sort" ) == 0 ) )
+ {
+ sal_Bool bTemp = sal_Bool();
+ if ( rProp.Value >>= bTemp )
+ {
+ aCheckedArgs[nProps].Name = rtl::OUString::createFromAscii("Collate");
+ aCheckedArgs[nProps++].Value <<= bTemp;
+ }
+ else
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ }
+
+ // Pages-Property
+ else if ( rProp.Name.compareToAscii( "Pages" ) == 0 )
+ {
+ OUSTRING sTemp;
+ if( rProp.Value >>= sTemp )
+ {
+ aCheckedArgs[nProps].Name = rProp.Name;
+ aCheckedArgs[nProps++].Value <<= sTemp;
+ }
+ else
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ }
+
+ // MonitorVisible
+ else if ( rProp.Name.compareToAscii( "MonitorVisible" ) == 0 )
+ {
+ if( !(rProp.Value >>= bMonitor) )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ aCheckedArgs[nProps].Name = rProp.Name;
+ aCheckedArgs[nProps++].Value <<= bMonitor;
+ }
+
+ // Wait
+ else if ( rProp.Name.compareToAscii( "Wait" ) == 0 )
+ {
+ if ( !(rProp.Value >>= bWaitUntilEnd) )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ aCheckedArgs[nProps].Name = rProp.Name;
+ aCheckedArgs[nProps++].Value <<= bWaitUntilEnd;
+ }
+
+ else if ( rProp.Name.compareToAscii( "DuplexMode" ) == 0 )
+ {
+ if ( !(rProp.Value >>= nDuplexMode ) )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ aCheckedArgs[nProps].Name = rProp.Name;
+ aCheckedArgs[nProps++].Value <<= nDuplexMode;
+ }
+ }
+
+ if ( nProps != aCheckedArgs.getLength() )
+ aCheckedArgs.realloc(nProps);
+
+ // Execute the print request every time.
+ // It doesn'tmatter if it is a real printer used or we print to a local file
+ // nor if we print to a temp file and move it afterwards by using the ucb.
+ // That will be handled later. see pUCBPrintFile below!
+ pView->ExecPrint( aCheckedArgs, sal_True, sal_False );
+
+ // Ok - may be execution before has finished (or started!) printing.
+ // And may it was a printing to a file.
+ // Now we have to check if we can move the file (if neccessary) via ucb to his right location.
+ // Cases:
+ // a) printing finished => move the file directly and forget the watcher thread
+ // b) printing is asynchron and runs currently => start watcher thread and exit this method
+ // This thread make all neccessary things by itself.
+ if (pUCBPrintTempFile!=NULL)
+ {
+ // a)
+ SfxPrinter* pPrinter = pView->GetPrinter();
+ if ( ! pPrinter->IsPrinting() )
+ ImplUCBPrintWatcher::moveAndDeleteTemp(&pUCBPrintTempFile,sUcbUrl);
+ // b)
+ else
+ {
+ // Note: we create(d) some ressource on the heap. (thread and tep file)
+ // They will be delected by the thread automaticly if he finish his run() method.
+ ImplUCBPrintWatcher* pWatcher = new ImplUCBPrintWatcher( pPrinter, pUCBPrintTempFile, sUcbUrl );
+ pWatcher->create();
+ }
+ }
+}
+
+void IMPL_PrintListener_DataContainer::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
+{
+ if ( &rBC == m_pObjectShell )
+ {
+ SfxPrintingHint* pPrintHint = PTR_CAST( SfxPrintingHint, &rHint );
+ if ( pPrintHint )
+ {
+ if ( pPrintHint->GetWhich() == com::sun::star::view::PrintableState_JOB_STARTED )
+ {
+ if ( !m_xPrintJob.is() )
+ m_xPrintJob = new SfxPrintJob_Impl( this );
+ m_aPrintOptions = pPrintHint->GetOptions();
+ }
+ else if ( pPrintHint->GetWhich() != -2 ) // -2 : CancelPrintJob
+ {
+ view::PrintJobEvent aEvent;
+ aEvent.Source = m_xPrintJob;
+ aEvent.State = (com::sun::star::view::PrintableState) pPrintHint->GetWhich();
+ ::cppu::OInterfaceContainerHelper* pContainer = m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< view::XPrintJobListener >*) NULL ) );
+ if ( pContainer!=NULL )
+ {
+ ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
+ while (pIterator.hasMoreElements())
+ ((view::XPrintJobListener*)pIterator.next())->printJobEvent( aEvent );
+ }
+ }
+ }
+ }
+}
+
+void SAL_CALL SfxPrintHelper::addPrintJobListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XPrintJobListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference < view::XPrintJobListener>*)0), xListener );
+}
+
+void SAL_CALL SfxPrintHelper::removePrintJobListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XPrintJobListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference < view::XPrintJobListener>*)0), xListener );
+}
+
+
diff --git a/sfx2/source/doc/printhelper.hxx b/sfx2/source/doc/printhelper.hxx
new file mode 100755
index 000000000000..9ba05fc20cee
--- /dev/null
+++ b/sfx2/source/doc/printhelper.hxx
@@ -0,0 +1,69 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "sal/config.h"
+#include "sfx2/dllapi.h"
+#include "sal/types.h"
+
+#include <com/sun/star/view/XPrintable.hpp>
+#include <com/sun/star/view/XPrintJobBroadcaster.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <osl/mutex.hxx>
+#include <cppuhelper/implbase3.hxx>
+
+struct IMPL_PrintListener_DataContainer;
+class SfxViewShell;
+class SfxPrinter;
+
+class SfxPrintHelper : public cppu::WeakImplHelper3
+ < com::sun::star::view::XPrintable
+ , com::sun::star::view::XPrintJobBroadcaster
+ , com::sun::star::lang::XInitialization >
+{
+public:
+
+ SfxPrintHelper() ;
+ virtual ~SfxPrintHelper() ;
+
+ void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL addPrintJobListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XPrintJobListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removePrintJobListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XPrintJobListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
+ virtual com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > SAL_CALL getPrinter() throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setPrinter( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& seqPrinter )
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL print( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& seqOptions )
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
+
+private:
+
+ osl::Mutex m_aMutex;
+ IMPL_PrintListener_DataContainer* m_pData ;
+ virtual void impl_setPrinter(const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rPrinter,SfxPrinter*& pPrinter,sal_uInt16& nChangeFlags,SfxViewShell*& pViewSh);
+} ;
diff --git a/sfx2/source/doc/querytemplate.cxx b/sfx2/source/doc/querytemplate.cxx
new file mode 100644
index 000000000000..a2adce45d239
--- /dev/null
+++ b/sfx2/source/doc/querytemplate.cxx
@@ -0,0 +1,52 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "querytemplate.hxx"
+#include "sfx2/sfxresid.hxx"
+#include "doc.hrc"
+#include "helpid.hrc"
+#include <vcl/svapp.hxx>
+
+namespace sfx2
+{
+
+QueryTemplateBox::QueryTemplateBox( Window* pParent, const String& rMessage ) :
+ MessBox ( pParent, 0, Application::GetDisplayName(), rMessage )
+{
+ SetImage( QueryBox::GetStandardImage() );
+ SetHelpId( HID_QUERY_LOAD_TEMPLATE );
+
+ AddButton( String( SfxResId( STR_QRYTEMPL_UPDATE_BTN ) ), RET_YES,
+ BUTTONDIALOG_DEFBUTTON | BUTTONDIALOG_OKBUTTON | BUTTONDIALOG_FOCUSBUTTON );
+ AddButton( String( SfxResId( STR_QRYTEMPL_KEEP_BTN ) ), RET_NO, BUTTONDIALOG_CANCELBUTTON );
+}
+
+} // end of namespace sfx2
+
diff --git a/sfx2/source/doc/querytemplate.hxx b/sfx2/source/doc/querytemplate.hxx
new file mode 100644
index 000000000000..92e9f26da0a7
--- /dev/null
+++ b/sfx2/source/doc/querytemplate.hxx
@@ -0,0 +1,44 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX2_QUERYTEMPLATE_HXX
+#define _SFX2_QUERYTEMPLATE_HXX
+
+#include <vcl/msgbox.hxx>
+
+namespace sfx2
+{
+
+ class QueryTemplateBox : public MessBox
+ {
+ public:
+ QueryTemplateBox( Window* pParent, const String& rMessage );
+ };
+
+} // end of namespace sfx2
+
+#endif
+
diff --git a/sfx2/source/doc/sfxacldetect.cxx b/sfx2/source/doc/sfxacldetect.cxx
new file mode 100644
index 000000000000..ded9d3000fc8
--- /dev/null
+++ b/sfx2/source/doc/sfxacldetect.cxx
@@ -0,0 +1,109 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+
+#ifdef WNT
+
+// necessary to include system headers without warnings
+#ifdef _MSC_VER
+#pragma warning(disable:4668 4917)
+#endif
+
+#include <windows.h>
+#include <lmaccess.h>
+#include <sal/types.h>
+
+sal_Bool IsReadonlyAccordingACL( const sal_Unicode* pFilePath )
+{
+ sal_Bool bResult = sal_False;
+
+ sal_uInt32 nFDSize = 0;
+ GetFileSecurityW( reinterpret_cast< LPCWSTR >(pFilePath), DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION, NULL, 0, &nFDSize );
+ if ( nFDSize )
+ {
+ PSECURITY_DESCRIPTOR pFileDescr = reinterpret_cast< PSECURITY_DESCRIPTOR >( malloc( nFDSize ) );
+ if ( GetFileSecurityW( reinterpret_cast< LPCWSTR >(pFilePath), DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION, pFileDescr, nFDSize, &nFDSize ) )
+ {
+ HANDLE hToken = NULL;
+ if ( OpenThreadToken( GetCurrentThread(), TOKEN_DUPLICATE|TOKEN_QUERY, TRUE, &hToken )
+ || OpenProcessToken( GetCurrentProcess(), TOKEN_DUPLICATE|TOKEN_QUERY, &hToken) )
+ {
+ HANDLE hImpersonationToken = NULL;
+ if ( DuplicateToken( hToken, SecurityImpersonation, &hImpersonationToken) )
+ {
+ sal_uInt32 nDesiredAccess = ACCESS_WRITE;
+ GENERIC_MAPPING aGenericMapping = { ACCESS_READ, ACCESS_WRITE, 0, ACCESS_READ | ACCESS_WRITE };
+ MapGenericMask( &nDesiredAccess, &aGenericMapping );
+
+ PRIVILEGE_SET aPrivilegeSet;
+ sal_uInt32 nPrivilegeSetSize = sizeof( PRIVILEGE_SET );
+
+ sal_uInt32 nGrantedAccess;
+ BOOL bAccessible = TRUE;
+ if ( AccessCheck( pFileDescr,
+ hImpersonationToken,
+ nDesiredAccess,
+ &aGenericMapping,
+ &aPrivilegeSet,
+ &nPrivilegeSetSize,
+ &nGrantedAccess,
+ &bAccessible ) )
+ {
+ bResult = !bAccessible;
+ }
+
+ CloseHandle( hImpersonationToken );
+ }
+
+ CloseHandle( hToken );
+ }
+ }
+
+ free( pFileDescr );
+ }
+
+ return bResult;
+}
+
+#else // this is UNX
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+
+#include <sal/types.h>
+
+sal_Bool IsReadonlyAccordingACL( const sal_Unicode* )
+{
+ // to be implemented
+ return sal_False;
+}
+
+#endif
+
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
new file mode 100644
index 000000000000..d24a95332b58
--- /dev/null
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -0,0 +1,4373 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+//________________________________________________________________________________________________________
+// my own includes
+//________________________________________________________________________________________________________
+
+#include <sfx2/sfxbasemodel.hxx>
+
+//________________________________________________________________________________________________________
+// include of other projects
+//________________________________________________________________________________________________________
+
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/task/ErrorCodeRequest.hpp>
+#include <com/sun/star/view/XSelectionSupplier.hpp>
+#include <com/sun/star/view/XPrintJobListener.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
+#include <com/sun/star/frame/IllegalArgumentIOException.hpp>
+#include <com/sun/star/frame/XUntitledNumbers.hpp>
+#include <com/sun/star/frame/UntitledNumbersConst.hpp>
+#include <com/sun/star/embed/XTransactionBroadcaster.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/EmbedMapUnits.hpp>
+#include <com/sun/star/document/XStorageChangeListener.hpp>
+#include <com/sun/star/document/XActionLockable.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/container/XIndexContainer.hpp>
+#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
+#include <com/sun/star/script/provider/XScriptProvider.hpp>
+#include <com/sun/star/ui/XUIConfigurationStorage.hpp>
+#include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/Aspects.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp>
+#include <comphelper/enumhelper.hxx> // can be removed when this is a "real" service
+
+#include <cppuhelper/interfacecontainer.hxx>
+#include <cppuhelper/exc_hlp.hxx>
+#include <comphelper/processfactory.hxx> // can be removed when this is a "real" service
+#include <comphelper/componentcontext.hxx>
+#include <comphelper/namedvaluecollection.hxx>
+#include <svl/itemset.hxx>
+#include <svl/stritem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <basic/sbx.hxx>
+#include <basic/sbuno.hxx>
+#include <tools/urlobj.hxx>
+#include <tools/diagnose_ex.h>
+#include <unotools/tempfile.hxx>
+#include <vos/mutex.hxx>
+#include <vcl/salctype.hxx>
+#include <sot/clsids.hxx>
+#include <sot/storinfo.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <svtools/transfer.hxx>
+#include <svtools/ehdl.hxx>
+#include <svtools/sfxecode.hxx>
+#include <rtl/logfile.hxx>
+#include <framework/configimporter.hxx>
+#include <framework/interaction.hxx>
+#include <framework/titlehelper.hxx>
+#include <comphelper/numberedcollection.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/ucbhelper.hxx>
+
+//________________________________________________________________________________________________________
+// includes of my own project
+//________________________________________________________________________________________________________
+
+#include <sfx2/sfxbasecontroller.hxx>
+#include "sfx2/viewfac.hxx"
+#include "workwin.hxx"
+#include <sfx2/signaturestate.hxx>
+#include <sfx2/sfxuno.hxx>
+#include <objshimp.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/objuno.hxx>
+#include <sfx2/printer.hxx>
+#include <sfx2/basmgr.hxx>
+#include <sfx2/event.hxx>
+#include <eventsupplier.hxx>
+#include <sfx2/evntconf.hxx>
+#include <sfx2/sfx.hrc>
+#include <sfx2/app.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "appdata.hxx"
+#include <sfx2/docfac.hxx>
+#include <sfx2/fcontnr.hxx>
+#include "sfx2/docstoragemodifylistener.hxx"
+#include "sfx2/brokenpackageint.hxx"
+#include "graphhelp.hxx"
+#include <sfx2/msgpool.hxx>
+#include <sfx2/DocumentMetadataAccess.hxx>
+
+#include <sfx2/sfxresid.hxx>
+
+//________________________________________________________________________________________________________
+// const
+static const ::rtl::OUString SERVICENAME_DESKTOP = ::rtl::OUString::createFromAscii ("com.sun.star.frame.Desktop");
+
+//________________________________________________________________________________________________________
+// namespaces
+//________________________________________________________________________________________________________
+
+namespace css = ::com::sun::star;
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using ::com::sun::star::beans::PropertyValue;
+using ::com::sun::star::frame::XFrame;
+using ::com::sun::star::frame::XController;
+using ::com::sun::star::frame::XController2;
+using ::com::sun::star::lang::IllegalArgumentException;
+using ::com::sun::star::io::IOException;
+using ::com::sun::star::lang::WrappedTargetException;
+using ::com::sun::star::uno::Type;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::document::XDocumentRecovery;
+
+/** This Listener is used to get notified when the XDocumentProperties of the
+ XModel change.
+ */
+class SfxDocInfoListener_Impl : public ::cppu::WeakImplHelper1<
+ ::com::sun::star::util::XModifyListener >
+{
+
+public:
+ SfxObjectShell& m_rShell;
+
+ SfxDocInfoListener_Impl( SfxObjectShell& i_rDoc )
+ : m_rShell(i_rDoc)
+ { };
+
+ ~SfxDocInfoListener_Impl();
+
+ virtual void SAL_CALL disposing( const lang::EventObject& )
+ throw ( uno::RuntimeException );
+ virtual void SAL_CALL modified( const lang::EventObject& )
+ throw ( uno::RuntimeException );
+};
+SfxDocInfoListener_Impl::~SfxDocInfoListener_Impl()
+{
+}
+void SAL_CALL SfxDocInfoListener_Impl::modified( const lang::EventObject& )
+ throw ( uno::RuntimeException )
+{
+ ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
+
+ // notify changes to the SfxObjectShell
+ m_rShell.FlushDocInfo();
+}
+
+void SAL_CALL SfxDocInfoListener_Impl::disposing( const lang::EventObject& )
+ throw ( uno::RuntimeException )
+{
+}
+
+//________________________________________________________________________________________________________
+// impl. declarations
+//________________________________________________________________________________________________________
+
+
+struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument
+{
+ // counter for SfxBaseModel instances created.
+ static sal_Int64 g_nInstanceCounter ;
+ SfxObjectShellRef m_pObjectShell ;
+ ::rtl::OUString m_sURL ;
+ ::rtl::OUString m_sRuntimeUID ;
+ ::rtl::OUString m_aPreusedFilterName;
+ ::cppu::OMultiTypeInterfaceContainerHelper m_aInterfaceContainer ;
+ uno::Reference< uno::XInterface > m_xParent ;
+ uno::Reference< frame::XController > m_xCurrent ;
+ uno::Reference< document::XDocumentInfo > m_xDocumentInfo ;
+ uno::Reference< document::XDocumentProperties > m_xDocumentProperties;
+ uno::Reference< script::XStarBasicAccess > m_xStarBasicAccess ;
+ uno::Reference< container::XNameReplace > m_xEvents ;
+ uno::Sequence< beans::PropertyValue> m_seqArguments ;
+ uno::Sequence< uno::Reference< frame::XController > > m_seqControllers ;
+ uno::Reference< container::XIndexAccess > m_contViewData ;
+ sal_uInt16 m_nControllerLockCount ;
+ sal_Bool m_bClosed ;
+ sal_Bool m_bClosing ;
+ sal_Bool m_bSaving ;
+ sal_Bool m_bSuicide ;
+ sal_Bool m_bInitialized ;
+ sal_Bool m_bModifiedSinceLastSave;
+ uno::Reference< com::sun::star::view::XPrintable> m_xPrintable ;
+ uno::Reference< script::provider::XScriptProvider > m_xScriptProvider;
+ uno::Reference< ui::XUIConfigurationManager > m_xUIConfigurationManager;
+ ::rtl::Reference< ::sfx2::DocumentStorageModifyListener > m_pStorageModifyListen;
+ ::rtl::OUString m_sModuleIdentifier;
+ css::uno::Reference< css::frame::XTitle > m_xTitleHelper;
+ css::uno::Reference< css::frame::XUntitledNumbers > m_xNumberedControllers;
+ uno::Reference< rdf::XDocumentMetadataAccess> m_xDocumentMetadata;
+
+
+ IMPL_SfxBaseModel_DataContainer( ::osl::Mutex& rMutex, SfxObjectShell* pObjectShell )
+ : m_pObjectShell ( pObjectShell )
+ , m_aInterfaceContainer ( rMutex )
+ , m_nControllerLockCount ( 0 )
+ , m_bClosed ( sal_False )
+ , m_bClosing ( sal_False )
+ , m_bSaving ( sal_False )
+ , m_bSuicide ( sal_False )
+ , m_bInitialized ( sal_False )
+ , m_bModifiedSinceLastSave( sal_False )
+ , m_pStorageModifyListen ( NULL )
+ , m_xTitleHelper ()
+ , m_xNumberedControllers ()
+ , m_xDocumentMetadata () // lazy
+ {
+ // increase global instance counter.
+ ++g_nInstanceCounter;
+ // set own Runtime UID
+ m_sRuntimeUID = rtl::OUString::valueOf( g_nInstanceCounter );
+ }
+
+ virtual ~IMPL_SfxBaseModel_DataContainer()
+ {
+ }
+
+ // ::sfx2::IModifiableDocument
+ virtual void storageIsModified()
+ {
+ if ( m_pObjectShell.Is() && !m_pObjectShell->IsModified() )
+ m_pObjectShell->SetModified( sal_True );
+ }
+
+ uno::Reference<rdf::XDocumentMetadataAccess> GetDMA()
+ {
+ if (!m_xDocumentMetadata.is())
+ {
+ OSL_ENSURE(m_pObjectShell, "GetDMA: no object shell?");
+ if (!m_pObjectShell)
+ {
+ return 0;
+ }
+
+ const uno::Reference<uno::XComponentContext> xContext(
+ ::comphelper::getProcessComponentContext());
+ ::rtl::OUString uri;
+ const uno::Reference<frame::XModel> xModel(
+ m_pObjectShell->GetModel());
+ const uno::Reference<lang::XMultiComponentFactory> xMsf(
+ xContext->getServiceManager());
+ const uno::Reference<frame::
+ XTransientDocumentsDocumentContentFactory> xTDDCF(
+ xMsf->createInstanceWithContext(
+ ::rtl::OUString::createFromAscii( "com.sun.star.frame."
+ "TransientDocumentsDocumentContentFactory"),
+ xContext),
+ uno::UNO_QUERY_THROW);
+ const uno::Reference<ucb::XContent> xContent(
+ xTDDCF->createDocumentContent(xModel) );
+ OSL_ENSURE(xContent.is(), "GetDMA: cannot create DocumentContent");
+ if (!xContent.is())
+ {
+ return 0;
+ }
+ uri = xContent->getIdentifier()->getContentIdentifier();
+ OSL_ENSURE(uri.getLength(), "GetDMA: empty uri?");
+ if (uri.getLength() && !uri.endsWithAsciiL("/", 1))
+ {
+ uri = uri + ::rtl::OUString::createFromAscii("/");
+ }
+
+ m_xDocumentMetadata = new ::sfx2::DocumentMetadataAccess(
+ xContext, *m_pObjectShell, uri);
+ }
+ return m_xDocumentMetadata;
+ }
+
+ uno::Reference<rdf::XDocumentMetadataAccess> CreateDMAUninitialized()
+ {
+ return (m_pObjectShell)
+ ? new ::sfx2::DocumentMetadataAccess(
+ ::comphelper::getProcessComponentContext(), *m_pObjectShell)
+ : 0;
+ }
+};
+
+// static member initialization.
+sal_Int64 IMPL_SfxBaseModel_DataContainer::g_nInstanceCounter = 0;
+
+// =======================================================================================================
+
+// Listener that forwards notifications from the PrintHelper to the "real" listeners
+class SfxPrintHelperListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::view::XPrintJobListener >
+{
+public:
+ IMPL_SfxBaseModel_DataContainer* m_pData;
+ SfxPrintHelperListener_Impl( IMPL_SfxBaseModel_DataContainer* pData )
+ : m_pData( pData )
+ {}
+
+ virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ;
+ virtual void SAL_CALL printJobEvent( const view::PrintJobEvent& rEvent ) throw ( uno::RuntimeException);
+};
+
+void SAL_CALL SfxPrintHelperListener_Impl::disposing( const lang::EventObject& ) throw ( uno::RuntimeException )
+{
+ m_pData->m_xPrintable = 0;
+}
+
+void SAL_CALL SfxPrintHelperListener_Impl::printJobEvent( const view::PrintJobEvent& rEvent ) throw (uno::RuntimeException)
+{
+ ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< view::XPrintJobListener >*) NULL ) );
+ if ( pContainer!=NULL )
+ {
+ ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
+ while (pIterator.hasMoreElements())
+ ((view::XPrintJobListener*)pIterator.next())->printJobEvent( rEvent );
+ }
+}
+
+// SfxOwnFramesLocker ====================================================================================
+// allows to lock all the frames related to the provided SfxObjectShell
+class SfxOwnFramesLocker
+{
+ uno::Sequence< uno::Reference< frame::XFrame > > m_aLockedFrames;
+
+ Window* GetVCLWindow( const uno::Reference< frame::XFrame >& xFrame );
+public:
+ SfxOwnFramesLocker( SfxObjectShell* ObjechShell );
+ ~SfxOwnFramesLocker();
+ void UnlockFrames();
+};
+
+SfxOwnFramesLocker::SfxOwnFramesLocker( SfxObjectShell* pObjectShell )
+{
+ if ( !pObjectShell )
+ return;
+
+ for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjectShell );
+ pFrame;
+ pFrame = SfxViewFrame::GetNext( *pFrame, pObjectShell )
+ )
+ {
+ SfxFrame& rSfxFrame = pFrame->GetFrame();
+ try
+ {
+ // get vcl window related to the frame and lock it if it is still not locked
+ uno::Reference< frame::XFrame > xFrame = rSfxFrame.GetFrameInterface();
+ Window* pWindow = GetVCLWindow( xFrame );
+ if ( !pWindow )
+ throw uno::RuntimeException();
+
+ if ( pWindow->IsEnabled() )
+ {
+ pWindow->Disable();
+
+ try
+ {
+ sal_Int32 nLen = m_aLockedFrames.getLength();
+ m_aLockedFrames.realloc( nLen + 1 );
+ m_aLockedFrames[nLen] = xFrame;
+ }
+ catch( uno::Exception& )
+ {
+ pWindow->Enable();
+ throw;
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Not possible to lock the frame window!\n" );
+ }
+ }
+}
+
+SfxOwnFramesLocker::~SfxOwnFramesLocker()
+{
+ UnlockFrames();
+}
+
+Window* SfxOwnFramesLocker::GetVCLWindow( const uno::Reference< frame::XFrame >& xFrame )
+{
+ Window* pWindow = NULL;
+
+ if ( xFrame.is() )
+ {
+ uno::Reference< awt::XWindow > xWindow = xFrame->getContainerWindow();
+ if ( xWindow.is() )
+ pWindow = VCLUnoHelper::GetWindow( xWindow );
+ }
+
+ return pWindow;
+}
+
+void SfxOwnFramesLocker::UnlockFrames()
+{
+ for ( sal_Int32 nInd = 0; nInd < m_aLockedFrames.getLength(); nInd++ )
+ {
+ try
+ {
+ if ( m_aLockedFrames[nInd].is() )
+ {
+ // get vcl window related to the frame and unlock it
+ Window* pWindow = GetVCLWindow( m_aLockedFrames[nInd] );
+ if ( !pWindow )
+ throw uno::RuntimeException();
+
+ pWindow->Enable();
+
+ m_aLockedFrames[nInd] = uno::Reference< frame::XFrame >();
+ }
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Can't unlock the frame window!\n" );
+ }
+ }
+}
+
+// SfxSaveGuard ====================================================================================
+class SfxSaveGuard
+{
+ private:
+ uno::Reference< frame::XModel > m_xModel;
+ IMPL_SfxBaseModel_DataContainer* m_pData;
+ SfxOwnFramesLocker* m_pFramesLock;
+
+ public:
+ SfxSaveGuard(const uno::Reference< frame::XModel >& xModel ,
+ IMPL_SfxBaseModel_DataContainer* pData ,
+ sal_Bool bRejectConcurrentSaveRequest);
+ ~SfxSaveGuard();
+};
+
+SfxSaveGuard::SfxSaveGuard(const uno::Reference< frame::XModel >& xModel ,
+ IMPL_SfxBaseModel_DataContainer* pData ,
+ sal_Bool bRejectConcurrentSaveRequest)
+ : m_xModel (xModel)
+ , m_pData (pData )
+ , m_pFramesLock(0 )
+{
+ static ::rtl::OUString MSG_1 = ::rtl::OUString::createFromAscii("Object already disposed." );
+ static ::rtl::OUString MSG_2 = ::rtl::OUString::createFromAscii("Concurrent save requests on the same document are not possible.");
+
+ if ( m_pData->m_bClosed )
+ throw ::com::sun::star::lang::DisposedException(
+ MSG_1,
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >());
+
+ if (
+ bRejectConcurrentSaveRequest &&
+ m_pData->m_bSaving
+ )
+ throw ::com::sun::star::io::IOException(
+ MSG_2,
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >());
+
+ m_pData->m_bSaving = sal_True;
+ m_pFramesLock = new SfxOwnFramesLocker(m_pData->m_pObjectShell);
+}
+
+SfxSaveGuard::~SfxSaveGuard()
+{
+ SfxOwnFramesLocker* pFramesLock = m_pFramesLock;
+ m_pFramesLock = 0;
+ delete pFramesLock;
+
+ m_pData->m_bSaving = sal_False;
+
+ // m_bSuicide was set e.g. in case somewhere tried to close a document, while it was used for
+ // storing at the same time. Further m_bSuicide was set to TRUE only if close(TRUE) was called.
+ // So the owner ship was delegated to the place where a veto exception was thrown.
+ // Now we have to call close() again and delegate the owner ship to the next one, which
+ // cant accept that. Close(FALSE) cant work in this case. Because then the document will may be never closed ...
+
+ if ( m_pData->m_bSuicide )
+ {
+ // Reset this state. In case the new close() request is not accepted by somehwere else ...
+ // it's not a good idea to have two "owners" for close .-)
+ m_pData->m_bSuicide = sal_False;
+ try
+ {
+ uno::Reference< util::XCloseable > xClose(m_xModel, uno::UNO_QUERY);
+ if (xClose.is())
+ xClose->close(sal_True);
+ }
+ catch(const util::CloseVetoException&)
+ {}
+ }
+}
+
+// =======================================================================================================
+
+//________________________________________________________________________________________________________
+// constructor
+//________________________________________________________________________________________________________
+DBG_NAME(sfx2_SfxBaseModel)
+SfxBaseModel::SfxBaseModel( SfxObjectShell *pObjectShell )
+: BaseMutex()
+, m_pData( new IMPL_SfxBaseModel_DataContainer( m_aMutex, pObjectShell ) )
+, m_bSupportEmbeddedScripts( pObjectShell && pObjectShell->Get_Impl() ? !pObjectShell->Get_Impl()->m_bNoBasicCapabilities : false )
+, m_bSupportDocRecovery( pObjectShell && pObjectShell->Get_Impl() ? pObjectShell->Get_Impl()->m_bDocRecoverySupport : false )
+{
+ DBG_CTOR(sfx2_SfxBaseModel,NULL);
+ if ( pObjectShell != NULL )
+ {
+ StartListening( *pObjectShell ) ;
+ }
+}
+
+//________________________________________________________________________________________________________
+// destructor
+//________________________________________________________________________________________________________
+
+SfxBaseModel::~SfxBaseModel()
+{
+ DBG_DTOR(sfx2_SfxBaseModel,NULL);
+}
+
+//________________________________________________________________________________________________________
+// XInterface
+//________________________________________________________________________________________________________
+
+uno::Any SAL_CALL SfxBaseModel::queryInterface( const UNOTYPE& rType ) throw( uno::RuntimeException )
+{
+ if ( ( !m_bSupportEmbeddedScripts && rType.equals( XEMBEDDEDSCRIPTS::static_type() ) )
+ || ( !m_bSupportDocRecovery && rType.equals( XDocumentRecovery::static_type() ) )
+ )
+ return Any();
+
+ return SfxBaseModel_Base::queryInterface( rType );
+}
+
+//________________________________________________________________________________________________________
+// XInterface
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::acquire() throw( )
+{
+ // Attention:
+ // Don't use mutex or guard in this method!!! Is a method of XInterface.
+
+ // Forward to baseclass
+ OWeakObject::acquire() ;
+}
+
+//________________________________________________________________________________________________________
+// XInterface
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::release() throw( )
+{
+ // Attention:
+ // Don't use mutex or guard in this method!!! Is a method of XInterface.
+
+ // Forward to baseclass
+ OWeakObject::release() ;
+}
+
+//________________________________________________________________________________________________________
+// XTypeProvider
+//________________________________________________________________________________________________________
+
+namespace
+{
+ void lcl_stripType( Sequence< Type >& io_rTypes, const Type& i_rTypeToStrip )
+ {
+ Sequence< UNOTYPE > aStrippedTypes( io_rTypes.getLength() - 1 );
+ ::std::remove_copy_if(
+ io_rTypes.getConstArray(),
+ io_rTypes.getConstArray() + io_rTypes.getLength(),
+ aStrippedTypes.getArray(),
+ ::std::bind2nd( ::std::equal_to< Type >(), i_rTypeToStrip )
+ );
+ io_rTypes = aStrippedTypes;
+ }
+}
+
+uno::Sequence< UNOTYPE > SAL_CALL SfxBaseModel::getTypes() throw( uno::RuntimeException )
+{
+ uno::Sequence< UNOTYPE > aTypes( SfxBaseModel_Base::getTypes() );
+
+ if ( !m_bSupportEmbeddedScripts )
+ lcl_stripType( aTypes, XEMBEDDEDSCRIPTS::static_type() );
+
+ if ( !m_bSupportDocRecovery )
+ lcl_stripType( aTypes, XDocumentRecovery::static_type() );
+
+ return aTypes;
+}
+
+//________________________________________________________________________________________________________
+// XTypeProvider
+//________________________________________________________________________________________________________
+
+uno::Sequence< sal_Int8 > SAL_CALL SfxBaseModel::getImplementationId() throw( uno::RuntimeException )
+{
+ // Create one Id for all instances of this class.
+ // Use ethernet address to do this! (sal_True)
+
+ // Optimize this method
+ // We initialize a static variable only one time. And we don't must use a mutex at every call!
+ // For the first call; pID is NULL - for the second call pID is different from NULL!
+ static ::cppu::OImplementationId* pID = NULL ;
+
+ if ( pID == NULL )
+ {
+ // Ready for multithreading; get global mutex for first call of this method only! see before
+ ::osl::MutexGuard aGuard( MUTEX::getGlobalMutex() ) ;
+
+ // Control these pointer again ... it can be, that another instance will be faster then these!
+ if ( pID == NULL )
+ {
+ // Create a new static ID ...
+ static ::cppu::OImplementationId aID( sal_False ) ;
+ // ... and set his address to static pointer!
+ pID = &aID ;
+ }
+ }
+
+ return pID->getImplementationId() ;
+}
+
+//________________________________________________________________________________________________________
+// XStarBasicAccess
+//________________________________________________________________________________________________________
+
+uno::Reference< script::XStarBasicAccess > implGetStarBasicAccess( SfxObjectShell* pObjectShell )
+{
+ uno::Reference< script::XStarBasicAccess > xRet;
+ if( pObjectShell )
+ {
+ BasicManager* pMgr = pObjectShell->GetBasicManager();
+ xRet = getStarBasicAccess( pMgr );
+ }
+ return xRet;
+}
+
+uno::Reference< XNAMECONTAINER > SAL_CALL SfxBaseModel::getLibraryContainer() throw( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
+ if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
+ rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
+
+ uno::Reference< XNAMECONTAINER > xRet;
+ if( rxAccess.is() )
+ xRet = rxAccess->getLibraryContainer();
+ return xRet;
+}
+
+/**___________________________________________________________________________________________________
+ @seealso XStarBasicAccess
+*/
+void SAL_CALL SfxBaseModel::createLibrary( const ::rtl::OUString& LibName, const ::rtl::OUString& Password,
+ const ::rtl::OUString& ExternalSourceURL, const ::rtl::OUString& LinkTargetURL )
+ throw(ELEMENTEXISTEXCEPTION, uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
+ if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
+ rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
+
+ if( rxAccess.is() )
+ rxAccess->createLibrary( LibName, Password, ExternalSourceURL, LinkTargetURL );
+}
+
+/**___________________________________________________________________________________________________
+ @seealso XStarBasicAccess
+*/
+void SAL_CALL SfxBaseModel::addModule( const ::rtl::OUString& LibraryName, const ::rtl::OUString& ModuleName,
+ const ::rtl::OUString& Language, const ::rtl::OUString& Source )
+ throw( NOSUCHELEMENTEXCEPTION, uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
+ if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
+ rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
+
+ if( rxAccess.is() )
+ rxAccess->addModule( LibraryName, ModuleName, Language, Source );
+}
+
+/**___________________________________________________________________________________________________
+ @seealso XStarBasicAccess
+*/
+void SAL_CALL SfxBaseModel::addDialog( const ::rtl::OUString& LibraryName, const ::rtl::OUString& DialogName,
+ const ::com::sun::star::uno::Sequence< sal_Int8 >& Data )
+ throw(NOSUCHELEMENTEXCEPTION, uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess;
+ if( !rxAccess.is() && m_pData->m_pObjectShell.Is() )
+ rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell );
+
+ if( rxAccess.is() )
+ rxAccess->addDialog( LibraryName, DialogName, Data );
+}
+
+
+//________________________________________________________________________________________________________
+// XChild
+//________________________________________________________________________________________________________
+
+uno::Reference< uno::XInterface > SAL_CALL SfxBaseModel::getParent() throw( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ return m_pData->m_xParent;
+}
+
+//________________________________________________________________________________________________________
+// XChild
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::setParent(const uno::Reference< uno::XInterface >& Parent) throw(NOSUPPORTEXCEPTION, uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+ m_pData->m_xParent = Parent;
+}
+
+//________________________________________________________________________________________________________
+// XChild
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::dispose() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+
+ if ( !m_pData->m_bClosed )
+ {
+ // gracefully accept wrong dispose calls instead of close call
+ // and try to make it work (may be really disposed later!)
+ try
+ {
+ close( sal_True );
+ }
+ catch ( com::sun::star::util::CloseVetoException& )
+ {
+ }
+
+ return;
+ }
+
+ if ( m_pData->m_pStorageModifyListen.is() )
+ {
+ m_pData->m_pStorageModifyListen->dispose();
+ m_pData->m_pStorageModifyListen = NULL;
+ }
+
+ lang::EventObject aEvent( (frame::XModel *)this );
+ m_pData->m_aInterfaceContainer.disposeAndClear( aEvent );
+
+ if ( m_pData->m_xDocumentInfo.is() )
+ {
+ // as long as an SfxObjectShell is assigned to an SfxBaseModel it is still existing here
+ // so we can't dispose the shared DocumentInfoObject here
+ // uno::Reference < lang::XComponent > xComp( m_pData->m_xDocumentInfo, uno::UNO_QUERY );
+ // xComp->dispose();
+ m_pData->m_xDocumentInfo = 0;
+ }
+
+ m_pData->m_xDocumentProperties.clear();
+
+ m_pData->m_xDocumentMetadata.clear();
+
+ EndListening( *m_pData->m_pObjectShell );
+
+ m_pData->m_xCurrent = uno::Reference< frame::XController > ();
+ m_pData->m_seqControllers = uno::Sequence< uno::Reference< frame::XController > > () ;
+
+ // m_pData member must be set to zero before 0delete is called to
+ // force disposed exception whenever someone tries to access our
+ // instance while in the dtor.
+ IMPL_SfxBaseModel_DataContainer* pData = m_pData;
+ m_pData = 0;
+ delete pData;
+}
+
+//________________________________________________________________________________________________________
+// XChild
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XEVENTLISTENER >& aListener )
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+ m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener );
+}
+
+//________________________________________________________________________________________________________
+// XChild
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XEVENTLISTENER >& aListener )
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+ m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener );
+}
+
+//________________________________________________________________________________________________________
+// document::XDocumentInfoSupplier
+//________________________________________________________________________________________________________
+
+uno::Reference< document::XDocumentInfo > SAL_CALL SfxBaseModel::getDocumentInfo() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+ if ( !m_pData->m_xDocumentInfo.is() )
+ {
+ // WARNING: this will only work if (when loading a document) the
+ // document meta-data has already been read and completely written
+ // into the XDocumentProperties at this point
+ // ==> DO NOT call getDocumentInfo before document info has been read!
+ uno::Reference< document::XDocumentInfo > xDocInfo =
+ new SfxDocumentInfoObject;
+ uno::Reference< document::XDocumentProperties > xDocProps =
+ getDocumentProperties();
+ uno::Sequence< uno::Any > args(1);
+ args[0] <<= xDocProps;
+ uno::Reference< lang::XInitialization > xInit(
+ xDocInfo, uno::UNO_QUERY_THROW);
+ try {
+ xInit->initialize(args);
+ ((SfxBaseModel*)this)->m_pData->m_xDocumentInfo = xDocInfo;
+ } catch (uno::RuntimeException &) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(::rtl::OUString::createFromAscii(
+ "SfxBaseModel::getDocumentInfo: cannot initialize"), *this,
+ uno::makeAny(e));
+ }
+ try {
+ rtl::OUString aName = rtl::OUString::createFromAscii("MediaType");
+ uno::Reference < beans::XPropertySet > xSet(
+ getDocumentStorage(), uno::UNO_QUERY );
+ uno::Any aMediaType = xSet->getPropertyValue( aName );
+ uno::Reference < beans::XPropertySet > xDocSet(
+ m_pData->m_xDocumentInfo, uno::UNO_QUERY );
+ xDocSet->setPropertyValue( aName, aMediaType );
+ } catch (uno::Exception &) {
+ //ignore
+ }
+ }
+
+ return m_pData->m_xDocumentInfo;
+}
+
+// document::XDocumentPropertiesSupplier:
+uno::Reference< document::XDocumentProperties > SAL_CALL
+SfxBaseModel::getDocumentProperties()
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+ if ( !m_pData->m_xDocumentProperties.is() )
+ {
+ uno::Reference< lang::XInitialization > xDocProps(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.document.DocumentProperties") ),
+ uno::UNO_QUERY_THROW);
+// xDocProps->initialize(uno::Sequence<uno::Any>());
+ m_pData->m_xDocumentProperties.set(xDocProps, uno::UNO_QUERY_THROW);
+ uno::Reference<util::XModifyBroadcaster> xMB(m_pData->m_xDocumentProperties, uno::UNO_QUERY_THROW);
+ xMB->addModifyListener(new SfxDocInfoListener_Impl(*m_pData->m_pObjectShell));
+ }
+
+ return m_pData->m_xDocumentProperties;
+}
+
+
+//________________________________________________________________________________________________________
+// XEVENTLISTENER
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::disposing( const lang::EventObject& aObject )
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ return;
+
+ uno::Reference< XMODIFYLISTENER > xMod( aObject.Source, uno::UNO_QUERY );
+ uno::Reference< XEVENTLISTENER > xListener( aObject.Source, uno::UNO_QUERY );
+ uno::Reference< XDOCEVENTLISTENER > xDocListener( aObject.Source, uno::UNO_QUERY );
+
+ if ( xMod.is() )
+ m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0), xMod );
+ else if ( xListener.is() )
+ m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), xListener );
+ else if ( xDocListener.is() )
+ m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), xListener );
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+sal_Bool SAL_CALL SfxBaseModel::attachResource( const ::rtl::OUString& rURL ,
+ const uno::Sequence< beans::PropertyValue >& rArgs )
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+ if ( rURL.getLength() == 0 && rArgs.getLength() == 1 && rArgs[0].Name.equalsAscii( "SetEmbedded" ) )
+ {
+ // allows to set a windowless document to EMBEDDED state
+ // but _only_ before load() or initNew() methods
+ if ( m_pData->m_pObjectShell.Is() && !m_pData->m_pObjectShell->GetMedium() )
+ {
+ sal_Bool bEmb = sal_Bool();
+ if ( ( rArgs[0].Value >>= bEmb ) && bEmb )
+ m_pData->m_pObjectShell->SetCreateMode_Impl( SFX_CREATE_MODE_EMBEDDED );
+ }
+
+ return sal_True;
+ }
+
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ m_pData->m_sURL = rURL;
+
+ SfxObjectShell* pObjectShell = m_pData->m_pObjectShell;
+
+ ::comphelper::NamedValueCollection aArgs( rArgs );
+
+ Sequence< sal_Int32 > aWinExtent;
+ if ( ( aArgs.get( "WinExtent" ) >>= aWinExtent )&& ( aWinExtent.getLength() == 4 ) )
+ {
+ Rectangle aVisArea( aWinExtent[0], aWinExtent[1], aWinExtent[2], aWinExtent[3] );
+ aVisArea = OutputDevice::LogicToLogic( aVisArea, MAP_100TH_MM, pObjectShell->GetMapUnit() );
+ pObjectShell->SetVisArea( aVisArea );
+ }
+
+ sal_Bool bBreakMacroSign = sal_False;
+ if ( aArgs.get( "BreakMacroSignature" ) >>= bBreakMacroSign )
+ {
+ pObjectShell->BreakMacroSign_Impl( bBreakMacroSign );
+ }
+
+ aArgs.remove( "WinExtent" );
+ aArgs.remove( "BreakMacroSignature" );
+ aArgs.remove( "Stream" );
+ aArgs.remove( "InputStream" );
+ aArgs.remove( "URL" );
+ aArgs.remove( "Frame" );
+ aArgs.remove( "Password" );
+ aArgs.remove( "EncryptionData" );
+
+ // TODO/LATER: all the parameters that are accepted by ItemSet of the DocShell must be removed here
+
+ m_pData->m_seqArguments = aArgs.getPropertyValues();
+
+ SfxMedium* pMedium = pObjectShell->GetMedium();
+ if ( pMedium )
+ {
+ SfxAllItemSet aSet( pObjectShell->GetPool() );
+ TransformParameters( SID_OPENDOC, rArgs, aSet );
+
+ // the arguments are not allowed to reach the medium
+ aSet.ClearItem( SID_FILE_NAME );
+ aSet.ClearItem( SID_FILLFRAME );
+
+ pMedium->GetItemSet()->Put( aSet );
+ SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False );
+ if ( pItem )
+ pMedium->SetFilter(
+ pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( pItem->GetValue() ) );
+
+ SFX_ITEMSET_ARG( &aSet, pTitleItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False );
+ if ( pTitleItem )
+ {
+ SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjectShell );
+ if ( pFrame )
+ pFrame->UpdateTitle();
+ }
+ }
+ }
+
+ return sal_True ;
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+::rtl::OUString SAL_CALL SfxBaseModel::getURL() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+ return m_pData->m_sURL ;
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+uno::Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getArgs() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ uno::Sequence< beans::PropertyValue > seqArgsNew;
+ uno::Sequence< beans::PropertyValue > seqArgsOld;
+ SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
+
+ // we need to know which properties are supported by the transformer
+ // hopefully it is a temporary solution, I guess nonconvertable properties
+ // should not be supported so then there will be only ItemSet from medium
+
+ TransformItems( SID_OPENDOC, *(m_pData->m_pObjectShell->GetMedium()->GetItemSet()), seqArgsNew );
+ TransformParameters( SID_OPENDOC, m_pData->m_seqArguments, aSet );
+ TransformItems( SID_OPENDOC, aSet, seqArgsOld );
+
+ sal_Int32 nOrgLength = m_pData->m_seqArguments.getLength();
+ sal_Int32 nOldLength = seqArgsOld.getLength();
+ sal_Int32 nNewLength = seqArgsNew.getLength();
+
+ // "WinExtent" property should be updated always.
+ // We can store it now to overwrite an old value
+ // since it is not from ItemSet
+ Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
+ aTmpRect = OutputDevice::LogicToLogic( aTmpRect, m_pData->m_pObjectShell->GetMapUnit(), MAP_100TH_MM );
+
+ Sequence< sal_Int32 > aRectSeq(4);
+ aRectSeq[0] = aTmpRect.Left();
+ aRectSeq[1] = aTmpRect.Top();
+ aRectSeq[2] = aTmpRect.Right();
+ aRectSeq[3] = aTmpRect.Bottom();
+
+ seqArgsNew.realloc( ++nNewLength );
+ seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "WinExtent" );
+ seqArgsNew[ nNewLength - 1 ].Value <<= aRectSeq;
+
+ if ( m_pData->m_aPreusedFilterName.getLength() )
+ {
+ seqArgsNew.realloc( ++nNewLength );
+ seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "PreusedFilterName" );
+ seqArgsNew[ nNewLength - 1 ].Value <<= m_pData->m_aPreusedFilterName;
+ }
+
+ SfxViewFrame* pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell );
+ if ( pFrame )
+ {
+ SvBorder aBorder = pFrame->GetBorderPixelImpl( pFrame->GetViewShell() );
+
+ Sequence< sal_Int32 > aBorderSeq(4);
+ aBorderSeq[0] = aBorder.Left();
+ aBorderSeq[1] = aBorder.Top();
+ aBorderSeq[2] = aBorder.Right();
+ aBorderSeq[3] = aBorder.Bottom();
+
+ seqArgsNew.realloc( ++nNewLength );
+ seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "DocumentBorder" );
+ seqArgsNew[ nNewLength - 1 ].Value <<= aBorderSeq;
+ }
+
+ // only the values that are not supported by the ItemSet must be cached here
+ uno::Sequence< beans::PropertyValue > aFinalCache;
+ sal_Int32 nFinalLength = 0;
+
+ for ( sal_Int32 nOrg = 0; nOrg < nOrgLength; nOrg++ )
+ {
+ sal_Int32 nOldInd = 0;
+ while ( nOldInd < nOldLength )
+ {
+ if ( m_pData->m_seqArguments[nOrg].Name.equals( seqArgsOld[nOldInd].Name ) )
+ break;
+ nOldInd++;
+ }
+
+ if ( nOldInd == nOldLength )
+ {
+ // the entity with this name should be new for seqArgsNew
+ // since it is not supported by transformer
+
+ seqArgsNew.realloc( ++nNewLength );
+ seqArgsNew[ nNewLength - 1 ] = m_pData->m_seqArguments[nOrg];
+
+ aFinalCache.realloc( ++nFinalLength );
+ aFinalCache[ nFinalLength - 1 ] = m_pData->m_seqArguments[nOrg];
+ }
+ }
+
+ m_pData->m_seqArguments = aFinalCache;
+
+ return seqArgsNew;
+ }
+
+ return m_pData->m_seqArguments;
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::connectController( const uno::Reference< frame::XController >& xController )
+ throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+ OSL_PRECOND( xController.is(), "SfxBaseModel::connectController: invalid controller!" );
+ if ( !xController.is() )
+ return;
+
+ sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength();
+ uno::Sequence< uno::Reference< frame::XController > > aNewSeq( nOldCount + 1 );
+ for ( sal_uInt32 n = 0; n < nOldCount; n++ )
+ aNewSeq.getArray()[n] = m_pData->m_seqControllers.getConstArray()[n];
+ aNewSeq.getArray()[nOldCount] = xController;
+ m_pData->m_seqControllers = aNewSeq;
+
+ if ( m_pData->m_seqControllers.getLength() == 1 )
+ {
+ SfxViewFrame* pViewFrame = SfxViewFrame::Get( xController, GetObjectShell() );
+ ENSURE_OR_THROW( pViewFrame, "SFX document without SFX view!?" );
+ pViewFrame->UpdateDocument_Impl();
+ const String sDocumentURL = GetObjectShell()->GetMedium()->GetName();
+ if ( sDocumentURL.Len() )
+ SFX_APP()->Broadcast( SfxStringHint( SID_OPENURL, sDocumentURL ) );
+ }
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::disconnectController( const uno::Reference< frame::XController >& xController ) throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength();
+ if ( !nOldCount )
+ return;
+
+ uno::Sequence< uno::Reference< frame::XController > > aNewSeq( nOldCount - 1 );
+ for ( sal_uInt32 nOld = 0, nNew = 0; nOld < nOldCount; ++nOld )
+ {
+ if ( xController != m_pData->m_seqControllers.getConstArray()[nOld] )
+ {
+ aNewSeq.getArray()[nNew] = m_pData->m_seqControllers.getConstArray()[nOld];
+ ++nNew;
+ }
+ }
+
+ m_pData->m_seqControllers = aNewSeq;
+
+ if ( xController == m_pData->m_xCurrent )
+ m_pData->m_xCurrent = uno::Reference< frame::XController > ();
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::lockControllers() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ ++m_pData->m_nControllerLockCount ;
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::unlockControllers() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ --m_pData->m_nControllerLockCount ;
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+sal_Bool SAL_CALL SfxBaseModel::hasControllersLocked() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+ return ( m_pData->m_nControllerLockCount != 0 ) ;
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+uno::Reference< frame::XController > SAL_CALL SfxBaseModel::getCurrentController() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ // get the last active controller of this model
+ if ( m_pData->m_xCurrent.is() )
+ return m_pData->m_xCurrent;
+
+ // get the first controller of this model
+ return m_pData->m_seqControllers.getLength() ? m_pData->m_seqControllers.getConstArray()[0] : m_pData->m_xCurrent;
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::setCurrentController( const uno::Reference< frame::XController >& xCurrentController )
+ throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ m_pData->m_xCurrent = xCurrentController;
+}
+
+//________________________________________________________________________________________________________
+// frame::XModel
+//________________________________________________________________________________________________________
+
+uno::Reference< uno::XInterface > SAL_CALL SfxBaseModel::getCurrentSelection() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< uno::XInterface > xReturn;
+ uno::Reference< frame::XController > xController = getCurrentController() ;
+
+ if ( xController.is() )
+ {
+ uno::Reference< view::XSelectionSupplier > xDocView( xController, uno::UNO_QUERY );
+ if ( xDocView.is() )
+ {
+ uno::Any xSel = xDocView->getSelection();
+ xSel >>= xReturn ;
+ }
+ }
+
+ return xReturn ;
+}
+
+//________________________________________________________________________________________________________
+// XModifiable2
+//________________________________________________________________________________________________________
+
+sal_Bool SAL_CALL SfxBaseModel::disableSetModified() throw (::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( !m_pData->m_pObjectShell.Is() )
+ throw uno::RuntimeException();
+
+ sal_Bool bResult = m_pData->m_pObjectShell->IsEnableSetModified();
+ m_pData->m_pObjectShell->EnableSetModified( sal_False );
+
+ return bResult;
+}
+
+sal_Bool SAL_CALL SfxBaseModel::enableSetModified() throw (::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( !m_pData->m_pObjectShell.Is() )
+ throw uno::RuntimeException();
+
+ sal_Bool bResult = m_pData->m_pObjectShell->IsEnableSetModified();
+ m_pData->m_pObjectShell->EnableSetModified( sal_True );
+
+ return bResult;
+}
+
+sal_Bool SAL_CALL SfxBaseModel::isSetModifiedEnabled() throw (::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( !m_pData->m_pObjectShell.Is() )
+ throw uno::RuntimeException();
+
+ return m_pData->m_pObjectShell->IsEnableSetModified();
+}
+
+//________________________________________________________________________________________________________
+// XModifiable
+//________________________________________________________________________________________________________
+
+sal_Bool SAL_CALL SfxBaseModel::isModified() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->IsModified() : sal_False;
+}
+
+//________________________________________________________________________________________________________
+// XModifiable
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::setModified( sal_Bool bModified )
+ throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( m_pData->m_pObjectShell.Is() )
+ m_pData->m_pObjectShell->SetModified(bModified);
+}
+
+//________________________________________________________________________________________________________
+// XModifiable
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::addModifyListener(const uno::Reference< XMODIFYLISTENER >& xListener) throw( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+
+ m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0),xListener );
+}
+
+//________________________________________________________________________________________________________
+// XModifiable
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::removeModifyListener(const uno::Reference< XMODIFYLISTENER >& xListener) throw( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0), xListener );
+}
+
+//____________________________________________________________________________________________________
+// XCloseable
+//____________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::close( sal_Bool bDeliverOwnership ) throw (util::CloseVetoException, uno::RuntimeException)
+{
+ static ::rtl::OUString MSG_1 = ::rtl::OUString::createFromAscii("Cant close while saving.");
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() || m_pData->m_bClosed || m_pData->m_bClosing )
+ return;
+
+ uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
+ lang::EventObject aSource (static_cast< ::cppu::OWeakObject*>(this));
+ ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
+ if (pContainer!=NULL)
+ {
+ ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
+ while (pIterator.hasMoreElements())
+ {
+ try
+ {
+ ((util::XCloseListener*)pIterator.next())->queryClosing( aSource, bDeliverOwnership );
+ }
+ catch( uno::RuntimeException& )
+ {
+ pIterator.remove();
+ }
+ }
+ }
+
+ if ( m_pData->m_bSaving )
+ {
+ if (bDeliverOwnership)
+ m_pData->m_bSuicide = sal_True;
+ throw util::CloseVetoException(
+ MSG_1,
+ static_cast< ::com::sun::star::util::XCloseable* >(this));
+ }
+
+ // no own objections against closing!
+ m_pData->m_bClosing = sal_True;
+ pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
+ if (pContainer!=NULL)
+ {
+ ::cppu::OInterfaceIteratorHelper pCloseIterator(*pContainer);
+ while (pCloseIterator.hasMoreElements())
+ {
+ try
+ {
+ ((util::XCloseListener*)pCloseIterator.next())->notifyClosing( aSource );
+ }
+ catch( uno::RuntimeException& )
+ {
+ pCloseIterator.remove();
+ }
+ }
+ }
+
+ m_pData->m_bClosed = sal_True;
+ m_pData->m_bClosing = sal_False;
+
+ dispose();
+}
+
+//____________________________________________________________________________________________________
+// XCloseBroadcaster
+//____________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::addCloseListener( const uno::Reference< XCLOSELISTENER >& xListener ) throw (uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+
+ m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XCLOSELISTENER >*)0), xListener );
+}
+
+//____________________________________________________________________________________________________
+// XCloseBroadcaster
+//____________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::removeCloseListener( const uno::Reference< XCLOSELISTENER >& xListener ) throw (uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XCLOSELISTENER >*)0), xListener );
+}
+
+//________________________________________________________________________________________________________
+// XPrintable
+//________________________________________________________________________________________________________
+
+uno::Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getPrinter() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( impl_getPrintHelper() )
+ return m_pData->m_xPrintable->getPrinter();
+ else
+ return uno::Sequence< beans::PropertyValue >();
+}
+
+void SAL_CALL SfxBaseModel::setPrinter(const uno::Sequence< beans::PropertyValue >& rPrinter)
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( impl_getPrintHelper() )
+ m_pData->m_xPrintable->setPrinter( rPrinter );
+}
+
+void SAL_CALL SfxBaseModel::print(const uno::Sequence< beans::PropertyValue >& rOptions)
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( impl_getPrintHelper() )
+ m_pData->m_xPrintable->print( rOptions );
+}
+
+//________________________________________________________________________________________________________
+// XStorable
+//________________________________________________________________________________________________________
+
+sal_Bool SAL_CALL SfxBaseModel::hasLocation() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->HasName() : sal_False;
+}
+
+//________________________________________________________________________________________________________
+// XStorable
+//________________________________________________________________________________________________________
+
+::rtl::OUString SAL_CALL SfxBaseModel::getLocation() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ // TODO/LATER: is it correct that the shared document returns shared file location?
+ if ( m_pData->m_pObjectShell->IsDocShared() )
+ return m_pData->m_pObjectShell->GetSharedFileURL();
+ else
+ return ::rtl::OUString(m_pData->m_pObjectShell->GetMedium()->GetName());
+ }
+
+ return m_pData->m_sURL;
+}
+
+//________________________________________________________________________________________________________
+// XStorable
+//________________________________________________________________________________________________________
+
+sal_Bool SAL_CALL SfxBaseModel::isReadonly() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->IsReadOnly() : sal_True;
+}
+
+//________________________________________________________________________________________________________
+// XStorable2
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::storeSelf( const uno::Sequence< beans::PropertyValue >& aSeqArgs )
+ throw ( ::com::sun::star::lang::IllegalArgumentException,
+ ::com::sun::star::io::IOException,
+ ::com::sun::star::uno::RuntimeException )
+{
+ RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeSelf" );
+
+ SfxModelGuard aGuard( *this );
+
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeSelf" ) ) );
+ SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
+
+ for ( sal_Int32 nInd = 0; nInd < aSeqArgs.getLength(); nInd++ )
+ {
+ // check that only acceptable parameters are provided here
+ if ( !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VersionComment" ) ) )
+ && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Author" ) ) )
+ && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) ) )
+ && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) ) ) )
+ {
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected parameter for storeSelf, might be no problem if SaveAs is executed." ) ) );
+ m_pData->m_pObjectShell->StoreLog();
+
+ ::rtl::OUString aMessage( RTL_CONSTASCII_USTRINGPARAM( "Unexpected MediaDescriptor parameter: " ) );
+ aMessage += aSeqArgs[nInd].Name;
+ throw lang::IllegalArgumentException( aMessage, uno::Reference< uno::XInterface >(), 1 );
+ }
+ }
+
+ SfxAllItemSet *pParams = new SfxAllItemSet( SFX_APP()->GetPool() );
+ TransformParameters( SID_SAVEDOC, aSeqArgs, *pParams );
+
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOC, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOC), m_pData->m_pObjectShell ) );
+
+ sal_Bool bRet = sal_False;
+
+ // TODO/LATER: let the embedded case of saving be handled more careful
+ if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
+ {
+ // If this is an embedded object that has no URL based location it should be stored to own storage.
+ // An embedded object can have a location based on URL in case it is a link, then it should be
+ // stored in normal way.
+ if ( !hasLocation() || getLocation().compareToAscii( "private:", 8 ) == 0 )
+ {
+ // actually in this very rare case only UI parameters have sence
+ // TODO/LATER: should be done later, after integration of sb19
+ bRet = m_pData->m_pObjectShell->DoSave()
+ && m_pData->m_pObjectShell->DoSaveCompleted();
+ }
+ else
+ {
+ bRet = m_pData->m_pObjectShell->Save_Impl( pParams );
+ }
+ }
+ else
+ bRet = m_pData->m_pObjectShell->Save_Impl( pParams );
+
+ DELETEZ( pParams );
+
+ sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ? m_pData->m_pObjectShell->GetError()
+ : ERRCODE_IO_CANTWRITE;
+ m_pData->m_pObjectShell->ResetError();
+
+ if ( bRet )
+ {
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "successful saving." ) ) );
+ m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
+
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCDONE), m_pData->m_pObjectShell ) );
+ }
+ else
+ {
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) );
+ m_pData->m_pObjectShell->StoreLog();
+
+ // write the contents of the logger to the file
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCFAILED, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCFAILED), m_pData->m_pObjectShell ) );
+
+ throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
+ }
+ }
+
+}
+
+//________________________________________________________________________________________________________
+// XStorable
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::store() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
+{
+ storeSelf( uno::Sequence< beans::PropertyValue >() );
+}
+
+//________________________________________________________________________________________________________
+// XStorable
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::storeAsURL( const ::rtl::OUString& rURL ,
+ const uno::Sequence< beans::PropertyValue >& rArgs )
+ throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
+{
+ RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeAsURL" );
+
+ SfxModelGuard aGuard( *this );
+
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeAsURL" ) ) );
+ SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
+
+ impl_store( rURL, rArgs, sal_False );
+
+ uno::Sequence< beans::PropertyValue > aSequence ;
+ TransformItems( SID_OPENDOC, *m_pData->m_pObjectShell->GetMedium()->GetItemSet(), aSequence );
+ attachResource( rURL, aSequence );
+
+#if OSL_DEBUG_LEVEL > 0
+ SFX_ITEMSET_ARG( m_pData->m_pObjectShell->GetMedium()->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False);
+ OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" );
+#endif
+ }
+}
+
+//________________________________________________________________________________________________________
+// XStorable
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::storeToURL( const ::rtl::OUString& rURL ,
+ const uno::Sequence< beans::PropertyValue >& rArgs )
+ throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeToURL" ) ) );
+ SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
+ impl_store( rURL, rArgs, sal_True );
+ }
+}
+
+::sal_Bool SAL_CALL SfxBaseModel::wasModifiedSinceLastSave() throw ( RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+ return m_pData->m_bModifiedSinceLastSave;
+}
+
+void SAL_CALL SfxBaseModel::storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
+{
+ SfxModelGuard aGuard( *this );
+
+ // delegate
+ SfxSaveGuard aSaveGuard( this, m_pData, sal_False );
+ impl_store( i_TargetLocation, i_MediaDescriptor, sal_True );
+
+ // no need for subsequent calls to storeToRecoveryFile, unless we're modified, again
+ m_pData->m_bModifiedSinceLastSave = sal_False;
+}
+
+void SAL_CALL SfxBaseModel::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+
+ // delegate to our "load" method
+ ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor );
+
+ // our load implementation expects the SalvagedFile to be in the media descriptor
+ OSL_ENSURE( !aMediaDescriptor.has( "SalvagedFile" ) || ( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) == i_SalvagedFile ),
+ "SfxBaseModel::recoverFromFile: inconsistent information!" );
+ aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile );
+
+ // similar for the to-be-loaded file
+ OSL_ENSURE( !aMediaDescriptor.has( "URL" ) || ( aMediaDescriptor.getOrDefault( "URL", ::rtl::OUString() ) == i_SourceLocation ),
+ "SfxBaseModel::recoverFromFile: inconsistent information!" );
+ aMediaDescriptor.put( "URL", i_SourceLocation );
+
+ load( aMediaDescriptor.getPropertyValues() );
+
+ // Note: The XDocumentRecovery interface specification requires us to do an attachResource after loading.
+ // However, we will not do this here, as we know that our load implementation (respectively some method
+ // called from there) already did so.
+ // In particular, the load process might already have modified some elements of the media
+ // descriptor, for instance the MacroExecMode (in case the user was involved to decide about it), and we do
+ // not want to overwrite it with the "old" elements passed to this method here.
+}
+
+//________________________________________________________________________________________________________
+// XLoadable
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::initNew()
+ throw (::com::sun::star::frame::DoubleInitializationException,
+ ::com::sun::star::io::IOException,
+ ::com::sun::star::uno::RuntimeException,
+ ::com::sun::star::uno::Exception)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+ if ( IsInitialized() )
+ throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
+
+ // the object shell should exist always
+ DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" );
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ if( m_pData->m_pObjectShell->GetMedium() )
+ throw DOUBLEINITIALIZATIONEXCEPTION();
+
+ sal_Bool bRes = m_pData->m_pObjectShell->DoInitNew( NULL );
+ sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ?
+ m_pData->m_pObjectShell->GetError() : ERRCODE_IO_CANTCREATE;
+ m_pData->m_pObjectShell->ResetError();
+
+ if ( !bRes )
+ throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
+ }
+}
+
+//________________________________________________________________________________________________________
+// XLoadable
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::load( const uno::Sequence< beans::PropertyValue >& seqArguments )
+ throw (::com::sun::star::frame::DoubleInitializationException,
+ ::com::sun::star::io::IOException,
+ ::com::sun::star::uno::RuntimeException,
+ ::com::sun::star::uno::Exception)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+ if ( IsInitialized() )
+ throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
+
+ // the object shell should exist always
+ DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" );
+
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ if( m_pData->m_pObjectShell->GetMedium() )
+ // if a Medium is present, the document is already initialized
+ throw DOUBLEINITIALIZATIONEXCEPTION();
+
+ SfxMedium* pMedium = new SfxMedium( seqArguments );
+ String aFilterName;
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False );
+ if( pFilterNameItem )
+ aFilterName = pFilterNameItem->GetValue();
+ if( !m_pData->m_pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName ) )
+ {
+ // filtername is not valid
+ delete pMedium;
+ throw frame::IllegalArgumentIOException();
+ }
+
+ // !TODO: currently not working
+ //SFX_ITEMSET_ARG( pParams, pFrameItem, SfxFrameItem, SID_DOCFRAME, FALSE );
+ //if( pFrameItem && pFrameItem->GetFrame() )
+ //{
+ // SfxFrame* pFrame = pFrameItem->GetFrame();
+ // pMedium->SetLoadTargetFrame( pFrame );
+ //}
+
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False );
+ sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False;
+
+ // SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
+ // sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
+ //
+ // does already happen in DoLoad call
+ //m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
+
+ // load document
+ sal_uInt32 nError = ERRCODE_NONE;
+ if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
+ nError=ERRCODE_IO_GENERAL;
+
+ // QUESTION: if the following happens outside of DoLoad, something important is missing there!
+ ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xHandler = pMedium->GetInteractionHandler();
+ if( m_pData->m_pObjectShell->GetErrorCode() )
+ {
+ nError = m_pData->m_pObjectShell->GetErrorCode();
+ if ( nError == ERRCODE_IO_BROKENPACKAGE && xHandler.is() )
+ {
+ ::rtl::OUString aDocName = pMedium->GetURLObject().getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, FALSE );
+ if ( !pRepairItem || !pRepairItem->GetValue() )
+ {
+ RequestPackageReparation aRequest( aDocName );
+ xHandler->handle( aRequest.GetRequest() );
+ if( aRequest.isApproved() )
+ {
+ // broken package: try second loading and allow repair
+ pMedium->GetItemSet()->Put( SfxBoolItem( SID_REPAIRPACKAGE, sal_True ) );
+ pMedium->GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
+ pMedium->GetItemSet()->Put( SfxStringItem( SID_DOCINFO_TITLE, aDocName ) );
+
+ // the error must be reset and the storage must be reopened in new mode
+ pMedium->ResetError();
+ pMedium->CloseStorage();
+ m_pData->m_pObjectShell->PrepareSecondTryLoad_Impl();
+ if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
+ nError=ERRCODE_IO_GENERAL;
+ nError = m_pData->m_pObjectShell->GetErrorCode();
+ }
+ }
+
+ if ( nError == ERRCODE_IO_BROKENPACKAGE )
+ {
+ // repair either not allowed or not successful
+ NotifyBrokenPackage aRequest( aDocName );
+ xHandler->handle( aRequest.GetRequest() );
+ }
+ }
+ }
+
+ if( m_pData->m_pObjectShell->IsAbortingImport() )
+ nError = ERRCODE_ABORT;
+
+ if( bSalvage )
+ {
+ // file recovery: restore original filter
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
+ SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
+ const SfxFilter* pSetFilter = rMatcher.GetFilter4FilterName( pFilterItem->GetValue() );
+ pMedium->SetFilter( pSetFilter );
+ m_pData->m_pObjectShell->SetModified(sal_True);
+ }
+
+ // TODO/LATER: may be the mode should be retrieved from outside and the preused filter should not be set
+ if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
+ {
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
+ if ( pFilterItem )
+ m_pData->m_aPreusedFilterName = pFilterItem->GetValue();
+ }
+
+ if ( !nError )
+ nError = pMedium->GetError();
+
+ m_pData->m_pObjectShell->ResetError();
+
+ if ( nError )
+ {
+ BOOL bSilent = FALSE;
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
+ if( pSilentItem )
+ bSilent = pSilentItem->GetValue();
+
+ BOOL bWarning = ((nError & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK);
+ if ( nError != ERRCODE_IO_BROKENPACKAGE && !bSilent )
+ {
+ // broken package was handled already
+ if ( SfxObjectShell::UseInteractionToHandleError( xHandler, nError ) && !bWarning )
+ {
+ // abort loading (except for warnings)
+ nError = ERRCODE_IO_ABORT;
+ }
+ }
+
+ if ( m_pData->m_pObjectShell->GetMedium() != pMedium )
+ {
+ // for whatever reason document now has another medium
+ DBG_ERROR("Document has rejected the medium?!");
+ delete pMedium;
+ }
+
+ if ( !bWarning ) // #i30711# don't abort loading if it's only a warning
+ {
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ nError ? nError : ERRCODE_IO_CANTREAD );
+ }
+ }
+
+ BOOL bHidden = FALSE;
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHidItem, SfxBoolItem, SID_HIDDEN, sal_False);
+ if ( pHidItem )
+ bHidden = pHidItem->GetValue();
+
+#if OSL_DEBUG_LEVEL > 0
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False);
+ OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" );
+#endif
+ // !TODO: will be done by Framework!
+ pMedium->SetUpdatePickList( !bHidden );
+ }
+}
+
+//________________________________________________________________________________________________________
+// XTransferable
+//________________________________________________________________________________________________________
+
+uno::Any SAL_CALL SfxBaseModel::getTransferData( const DATAFLAVOR& aFlavor )
+ throw (::com::sun::star::datatransfer::UnsupportedFlavorException,
+ ::com::sun::star::io::IOException,
+ ::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Any aAny;
+
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ {
+ TransferableObjectDescriptor aDesc;
+
+ aDesc.maClassName = m_pData->m_pObjectShell->GetClassName();
+ aDesc.maTypeName = aFlavor.HumanPresentableName;
+
+ // TODO/LATER: ViewAspect needs to be sal_Int64
+ aDesc.mnViewAspect = sal::static_int_cast< sal_uInt16 >( embed::Aspects::MSOLE_CONTENT );
+
+ //TODO/LATER: status needs to become sal_Int64
+ aDesc.mnOle2Misc = m_pData->m_pObjectShell->GetMiscStatus();
+ Size aSize = m_pData->m_pObjectShell->GetVisArea().GetSize();
+
+ MapUnit aMapUnit = m_pData->m_pObjectShell->GetMapUnit();
+ aDesc.maSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
+ aDesc.maDragStartPos = Point();
+ aDesc.maDisplayName = String();
+ aDesc.mbCanLink = FALSE;
+
+ SvMemoryStream aMemStm( 1024, 1024 );
+ aMemStm << aDesc;
+ aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() );
+ }
+ else
+ throw datatransfer::UnsupportedFlavorException();
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ {
+ try
+ {
+ utl::TempFile aTmp;
+ aTmp.EnableKillingFile( TRUE );
+ storeToURL( aTmp.GetURL(), uno::Sequence < beans::PropertyValue >() );
+ SvStream* pStream = aTmp.GetStream( STREAM_READ );
+ const sal_uInt32 nLen = pStream->Seek( STREAM_SEEK_TO_END );
+ ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
+ pStream->Seek( STREAM_SEEK_TO_BEGIN );
+ pStream->Read( aSeq.getArray(), nLen );
+ delete pStream;
+ if( aSeq.getLength() )
+ aAny <<= aSeq;
+ }
+ catch ( uno::Exception& )
+ {
+ }
+ }
+ else
+ throw datatransfer::UnsupportedFlavorException();
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ {
+
+ ::boost::shared_ptr<GDIMetaFile> pMetaFile =
+ m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
+
+ if ( pMetaFile )
+ {
+ SvMemoryStream aMemStm( 65535, 65535 );
+ aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
+
+ pMetaFile->Write( aMemStm );
+ aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
+ aMemStm.Seek( STREAM_SEEK_TO_END ) );
+ }
+ }
+ else
+ throw datatransfer::UnsupportedFlavorException();
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ {
+ ::boost::shared_ptr<GDIMetaFile> pMetaFile =
+ m_pData->m_pObjectShell->CreatePreviewMetaFile_Impl( sal_True, sal_True );
+
+ if ( pMetaFile )
+ {
+ SvMemoryStream aMemStm( 65535, 65535 );
+ aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
+
+ pMetaFile->Write( aMemStm );
+ aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
+ aMemStm.Seek( STREAM_SEEK_TO_END ) );
+ }
+ }
+ else
+ throw datatransfer::UnsupportedFlavorException();
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ {
+ ::boost::shared_ptr<GDIMetaFile> pMetaFile =
+ m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
+
+ if ( pMetaFile )
+ {
+ ::boost::shared_ptr<SvMemoryStream> pStream(
+ GraphicHelper::getFormatStrFromGDI_Impl(
+ pMetaFile.get(), CVT_EMF ) );
+ if ( pStream )
+ {
+ pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
+ aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
+ pStream->Seek( STREAM_SEEK_TO_END ) );
+ }
+ }
+ }
+ else if ( GraphicHelper::supportsMetaFileHandle_Impl()
+ && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
+ {
+ ::boost::shared_ptr<GDIMetaFile> pMetaFile =
+ m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
+
+ if ( pMetaFile )
+ {
+ aAny <<= reinterpret_cast< const sal_uInt64 >(
+ GraphicHelper::getEnhMetaFileFromGDI_Impl( pMetaFile.get() ) );
+ }
+ }
+ else
+ throw datatransfer::UnsupportedFlavorException();
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ {
+ ::boost::shared_ptr<GDIMetaFile> pMetaFile =
+ m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
+
+ if ( pMetaFile )
+ {
+ ::boost::shared_ptr<SvMemoryStream> pStream(
+ GraphicHelper::getFormatStrFromGDI_Impl(
+ pMetaFile.get(), CVT_WMF ) );
+
+ if ( pStream )
+ {
+ pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
+ aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
+ pStream->Seek( STREAM_SEEK_TO_END ) );
+ }
+ }
+ }
+ else if ( GraphicHelper::supportsMetaFileHandle_Impl()
+ && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
+ {
+ // means HGLOBAL handler to memory storage containing METAFILEPICT structure
+
+ ::boost::shared_ptr<GDIMetaFile> pMetaFile =
+ m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
+
+ if ( pMetaFile )
+ {
+ Size aMetaSize = pMetaFile->GetPrefSize();
+ aAny <<= reinterpret_cast< const sal_uInt64 >(
+ GraphicHelper::getWinMetaFileFromGDI_Impl(
+ pMetaFile.get(), aMetaSize ) );
+ }
+ }
+ else
+ throw datatransfer::UnsupportedFlavorException();
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ {
+ ::boost::shared_ptr<GDIMetaFile> pMetaFile =
+ m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
+
+ if ( pMetaFile )
+ {
+ ::boost::shared_ptr<SvMemoryStream> pStream(
+ GraphicHelper::getFormatStrFromGDI_Impl(
+ pMetaFile.get(), CVT_BMP ) );
+
+ if ( pStream )
+ {
+ pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
+ aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
+ pStream->Seek( STREAM_SEEK_TO_END ) );
+ }
+ }
+ }
+ else
+ throw datatransfer::UnsupportedFlavorException();
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "image/png" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ {
+ ::boost::shared_ptr<GDIMetaFile> pMetaFile =
+ m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True );
+
+ if ( pMetaFile )
+ {
+ ::boost::shared_ptr<SvMemoryStream> pStream(
+ GraphicHelper::getFormatStrFromGDI_Impl(
+ pMetaFile.get(), CVT_PNG ) );
+
+ if ( pStream )
+ {
+ pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
+ aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ),
+ pStream->Seek( STREAM_SEEK_TO_END ) );
+ }
+ }
+ }
+ else
+ throw datatransfer::UnsupportedFlavorException();
+ }
+ else
+ throw datatransfer::UnsupportedFlavorException();
+ }
+
+ return aAny;
+}
+
+//________________________________________________________________________________________________________
+// XTransferable
+//________________________________________________________________________________________________________
+
+
+uno::Sequence< DATAFLAVOR > SAL_CALL SfxBaseModel::getTransferDataFlavors()
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ sal_Int32 nSuppFlavors = GraphicHelper::supportsMetaFileHandle_Impl() ? 10 : 8;
+ uno::Sequence< DATAFLAVOR > aFlavorSeq( nSuppFlavors );
+
+ aFlavorSeq[0].MimeType =
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
+ aFlavorSeq[0].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
+ aFlavorSeq[0].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
+
+ aFlavorSeq[1].MimeType =
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) );
+ aFlavorSeq[1].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) );
+ aFlavorSeq[1].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
+
+ aFlavorSeq[2].MimeType =
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
+ aFlavorSeq[2].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
+ aFlavorSeq[2].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
+
+ aFlavorSeq[3].MimeType =
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
+ aFlavorSeq[3].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
+ aFlavorSeq[3].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
+
+ aFlavorSeq[4].MimeType =
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) );
+ aFlavorSeq[4].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Object Descriptor (XML)" ) );
+ aFlavorSeq[4].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
+
+ aFlavorSeq[5].MimeType =
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"" ) );
+ aFlavorSeq[5].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Embed Source (XML)" ) );
+ aFlavorSeq[5].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
+
+ aFlavorSeq[6].MimeType =
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) );
+ aFlavorSeq[6].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Bitmap" ) );
+ aFlavorSeq[6].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
+
+ aFlavorSeq[7].MimeType =
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) );
+ aFlavorSeq[7].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PNG" ) );
+ aFlavorSeq[7].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 );
+
+ if ( nSuppFlavors == 10 )
+ {
+ aFlavorSeq[8].MimeType =
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
+ aFlavorSeq[8].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
+ aFlavorSeq[8].DataType = getCppuType( (const sal_uInt64*) 0 );
+
+ aFlavorSeq[9].MimeType =
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
+ aFlavorSeq[9].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) );
+ aFlavorSeq[9].DataType = getCppuType( (const sal_uInt64*) 0 );
+ }
+
+ return aFlavorSeq;
+}
+
+//________________________________________________________________________________________________________
+// XTransferable
+//________________________________________________________________________________________________________
+
+
+sal_Bool SAL_CALL SfxBaseModel::isDataFlavorSupported( const DATAFLAVOR& aFlavor )
+ throw (::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ return sal_True;
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ return sal_True;
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ return sal_True;
+ else if ( GraphicHelper::supportsMetaFileHandle_Impl()
+ && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
+ return sal_True;
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ return sal_True;
+ else if ( GraphicHelper::supportsMetaFileHandle_Impl()
+ && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) )
+ return sal_True;
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ return sal_True;
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ return sal_True;
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ return sal_True;
+ }
+ else if ( aFlavor.MimeType.equalsAscii( "image/png" ) )
+ {
+ if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) )
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+
+//--------------------------------------------------------------------------------------------------------
+// XEventsSupplier
+//--------------------------------------------------------------------------------------------------------
+
+uno::Reference< container::XNameReplace > SAL_CALL SfxBaseModel::getEvents() throw( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( ! m_pData->m_xEvents.is() )
+ {
+ m_pData->m_xEvents = new SfxEvents_Impl( m_pData->m_pObjectShell, this );
+ }
+
+ return m_pData->m_xEvents;
+}
+
+//--------------------------------------------------------------------------------------------------------
+// XEmbeddedScripts
+//--------------------------------------------------------------------------------------------------------
+
+uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getBasicLibraries() throw (RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries;
+ if ( m_pData->m_pObjectShell )
+ xBasicLibraries.set( m_pData->m_pObjectShell->GetBasicContainer(), UNO_QUERY_THROW );
+ return xBasicLibraries;
+}
+
+uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getDialogLibraries() throw (RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries;
+ if ( m_pData->m_pObjectShell )
+ xDialogLibraries.set( m_pData->m_pObjectShell->GetDialogContainer(), UNO_QUERY_THROW );
+ return xDialogLibraries;
+}
+
+::sal_Bool SAL_CALL SfxBaseModel::getAllowMacroExecution() throw (RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( m_pData->m_pObjectShell )
+ return m_pData->m_pObjectShell->AdjustMacroMode( String(), false );
+ return sal_False;
+}
+
+//--------------------------------------------------------------------------------------------------------
+// XScriptInvocationContext
+//--------------------------------------------------------------------------------------------------------
+
+Reference< document::XEmbeddedScripts > SAL_CALL SfxBaseModel::getScriptContainer() throw (RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ Reference< document::XEmbeddedScripts > xDocumentScripts;
+
+ try
+ {
+ Reference< frame::XModel > xDocument( this );
+ xDocumentScripts.set( xDocument, uno::UNO_QUERY );
+ while ( !xDocumentScripts.is() && xDocument.is() )
+ {
+ Reference< container::XChild > xDocAsChild( xDocument, uno::UNO_QUERY );
+ if ( !xDocAsChild.is() )
+ {
+ xDocument = NULL;
+ break;
+ }
+
+ xDocument.set( xDocAsChild->getParent(), uno::UNO_QUERY );
+ xDocumentScripts.set( xDocument, uno::UNO_QUERY );
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ xDocumentScripts = NULL;
+ }
+
+ return xDocumentScripts;
+}
+
+//--------------------------------------------------------------------------------------------------------
+// XEventBroadcaster
+//--------------------------------------------------------------------------------------------------------
+
+void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+
+ m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
+}
+
+//--------------------------------------------------------------------------------------------------------
+// XEventBroadcaster
+//--------------------------------------------------------------------------------------------------------
+
+void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener );
+}
+
+//--------------------------------------------------------------------------------------------------------
+// XDocumentEventBroadcaster
+//--------------------------------------------------------------------------------------------------------
+// ---------------------------------
+void SAL_CALL SfxBaseModel::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
+ throw ( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+ m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
+}
+
+// ---------------------------------
+void SAL_CALL SfxBaseModel::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener )
+ throw ( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+ m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener );
+}
+
+// ---------------------------------
+void SAL_CALL SfxBaseModel::notifyDocumentEvent( const ::rtl::OUString&, const uno::Reference< frame::XController2 >&, const uno::Any& )
+ throw ( lang::IllegalArgumentException, lang::NoSupportException, uno::RuntimeException )
+{
+ throw lang::NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SfxBaseModel controlls all the sent notifications itself!" ) ), uno::Reference< uno::XInterface >() );
+}
+
+//________________________________________________________________________________________________________
+// SfxListener
+//________________________________________________________________________________________________________
+
+void addTitle_Impl( Sequence < ::com::sun::star::beans::PropertyValue >& rSeq, const ::rtl::OUString& rTitle )
+{
+ sal_Int32 nCount = rSeq.getLength();
+ sal_Int32 nArg;
+
+ for ( nArg = 0; nArg < nCount; nArg++ )
+ {
+ ::com::sun::star::beans::PropertyValue& rProp = rSeq[nArg];
+ if ( rProp.Name.equalsAscii("Title") )
+ {
+ rProp.Value <<= rTitle;
+ break;
+ }
+ }
+
+ if ( nArg == nCount )
+ {
+ rSeq.realloc( nCount+1 );
+ rSeq[nCount].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") );
+ rSeq[nCount].Value <<= rTitle;
+ }
+}
+
+void SfxBaseModel::NotifyStorageListeners_Impl()
+{
+ uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
+
+ if ( m_pData->m_pObjectShell )
+ {
+ ::cppu::OInterfaceContainerHelper* pContainer =
+ m_pData->m_aInterfaceContainer.getContainer(
+ ::getCppuType( ( const uno::Reference< document::XStorageChangeListener >*) NULL ) );
+ if ( pContainer != NULL )
+ {
+ uno::Reference< embed::XStorage > xNewStorage = m_pData->m_pObjectShell->GetStorage();
+ ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
+ while ( pIterator.hasMoreElements() )
+ {
+ try
+ {
+ ((document::XStorageChangeListener*)pIterator.next())->notifyStorageChange(
+ xSelfHold,
+ xNewStorage );
+ }
+ catch( uno::RuntimeException& )
+ {
+ pIterator.remove();
+ }
+ }
+ }
+ }
+}
+
+void SfxBaseModel::Notify( SfxBroadcaster& rBC ,
+ const SfxHint& rHint )
+{
+ if ( !m_pData )
+ return;
+
+ if ( &rBC == m_pData->m_pObjectShell )
+ {
+ SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
+ if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DOCCHANGED )
+ changing();
+
+ SfxEventHint* pNamedHint = PTR_CAST( SfxEventHint, &rHint );
+ if ( pNamedHint )
+ {
+
+ switch ( pNamedHint->GetEventId() )
+ {
+ case SFX_EVENT_STORAGECHANGED:
+ {
+ // for now this event is sent only on creation of a new storage for new document
+ // and in case of reload of medium without document reload
+ // other events are used to detect storage change
+ // NotifyStorageListeners_Impl();
+
+ if ( m_pData->m_xUIConfigurationManager.is()
+ && m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
+ {
+ uno::Reference< XSTORAGE > xConfigStorage;
+ rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
+
+ xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READWRITE );
+ if ( !xConfigStorage.is() )
+ xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READ );
+
+ if ( xConfigStorage.is() || !m_pData->m_pObjectShell->GetStorage()->hasByName( aUIConfigFolderName ) )
+ {
+ // the storage is different, since otherwise it could not be opened, so it must be exchanged
+ Reference< ui::XUIConfigurationStorage > xUIConfigStorage( m_pData->m_xUIConfigurationManager, uno::UNO_QUERY );
+ xUIConfigStorage->setStorage( xConfigStorage );
+ }
+ else
+ {
+ OSL_ENSURE( sal_False, "Unexpected scenario!\n" );
+ }
+ }
+
+ ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
+ }
+ break;
+
+ case SFX_EVENT_LOADFINISHED:
+ {
+ impl_getPrintHelper();
+ ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() );
+ m_pData->m_bModifiedSinceLastSave = sal_False;
+ }
+ break;
+
+ case SFX_EVENT_SAVEASDOCDONE:
+ {
+ m_pData->m_sURL = m_pData->m_pObjectShell->GetMedium()->GetName();
+
+ SfxItemSet *pSet = m_pData->m_pObjectShell->GetMedium()->GetItemSet();
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
+ ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
+ TransformItems( SID_SAVEASDOC, *pSet, aArgs );
+ addTitle_Impl( aArgs, aTitle );
+ attachResource( m_pData->m_pObjectShell->GetMedium()->GetName(), aArgs );
+ }
+ break;
+
+ case SFX_EVENT_DOCCREATED:
+ {
+ impl_getPrintHelper();
+ m_pData->m_bModifiedSinceLastSave = sal_False;
+ }
+ break;
+
+ case SFX_EVENT_MODIFYCHANGED:
+ {
+ m_pData->m_bModifiedSinceLastSave = isModified();
+ }
+ break;
+ }
+
+
+ SfxViewEventHint* pViewHint = PTR_CAST( SfxViewEventHint, &rHint );
+ postEvent_Impl( pNamedHint->GetEventName(), pViewHint ? pViewHint->GetController() : uno::Reference< frame::XController2 >() );
+ }
+
+ if ( pSimpleHint )
+ {
+ if ( pSimpleHint->GetId() == SFX_HINT_TITLECHANGED )
+ {
+ ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle();
+ addTitle_Impl( m_pData->m_seqArguments, aTitle );
+ postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_TITLECHANGED ) );
+ }
+ if ( pSimpleHint->GetId() == SFX_HINT_MODECHANGED )
+ {
+ postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_MODECHANGED ) );
+ }
+/*
+ else if ( pSimpleHint->GetId() == SFX_HINT_DYING
+ || pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING )
+ {
+ SfxObjectShellLock pShellLock = m_pData->m_pObjectShellLock;
+ m_pData->m_pObjectShellLock = SfxObjectShellLock();
+ }
+*/
+ }
+ }
+}
+
+//________________________________________________________________________________________________________
+// public impl.
+//________________________________________________________________________________________________________
+
+void SfxBaseModel::NotifyModifyListeners_Impl() const
+{
+ ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0) );
+ if ( pIC )
+ {
+ lang::EventObject aEvent( (frame::XModel *)this );
+ pIC->notifyEach( &util::XModifyListener::modified, aEvent );
+ }
+
+ // this notification here is done too generously, we cannot simply assume that we're really modified
+ // now, but we need to check it ...
+ m_pData->m_bModifiedSinceLastSave = const_cast< SfxBaseModel* >( this )->isModified();
+}
+
+void SfxBaseModel::changing()
+{
+ SfxModelGuard aGuard( *this );
+
+ // the notification should not be sent if the document can not be modified
+ if ( !m_pData->m_pObjectShell.Is() || !m_pData->m_pObjectShell->IsEnableSetModified() )
+ return;
+
+ NotifyModifyListeners_Impl();
+}
+
+void SfxBaseModel::impl_change()
+{
+ // object already disposed?
+ if ( impl_isDisposed() )
+ return;
+
+ NotifyModifyListeners_Impl();
+}
+
+//________________________________________________________________________________________________________
+// public impl.
+//________________________________________________________________________________________________________
+
+SfxObjectShell* SfxBaseModel::GetObjectShell() const
+{
+ return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
+}
+
+SfxObjectShell* SfxBaseModel::impl_getObjectShell() const
+{
+ return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0;
+}
+
+//________________________________________________________________________________________________________
+// public impl.
+//________________________________________________________________________________________________________
+
+sal_Bool SfxBaseModel::IsInitialized() const
+{
+ if ( !m_pData || !m_pData->m_pObjectShell )
+ {
+ OSL_ENSURE( false, "SfxBaseModel::IsInitialized: this should have been caught earlier!" );
+ return sal_False;
+ }
+
+ return m_pData->m_pObjectShell->GetMedium() != NULL;
+}
+
+void SfxBaseModel::MethodEntryCheck( const bool i_mustBeInitialized ) const
+{
+ if ( impl_isDisposed() )
+ throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
+ if ( i_mustBeInitialized && !IsInitialized() )
+ throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) );
+}
+
+sal_Bool SfxBaseModel::impl_isDisposed() const
+{
+ return ( m_pData == NULL ) ;
+}
+
+//________________________________________________________________________________________________________
+// private impl.
+//________________________________________________________________________________________________________
+
+::rtl::OUString SfxBaseModel::GetMediumFilterName_Impl()
+{
+ const SfxFilter* pFilter = NULL;
+ SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
+ if ( pMedium )
+ pFilter = pMedium->GetFilter();
+
+ if ( pFilter )
+ return pFilter->GetName();
+
+ return ::rtl::OUString();
+}
+
+void SfxBaseModel::impl_store( const ::rtl::OUString& sURL ,
+ const uno::Sequence< beans::PropertyValue >& seqArguments ,
+ sal_Bool bSaveTo )
+{
+ if( !sURL.getLength() )
+ throw frame::IllegalArgumentIOException();
+
+ //sal_Bool aSaveAsTemplate = sal_False;
+
+ sal_Bool bSaved = sal_False;
+ if ( !bSaveTo && m_pData->m_pObjectShell && sURL.getLength()
+ && sURL.compareToAscii( "private:stream", 14 ) != COMPARE_EQUAL
+ && ::utl::UCBContentHelper::EqualURLs( getLocation(), sURL ) )
+ {
+ // this is the same file URL as the current document location, try to use storeOwn if possible
+
+ ::comphelper::SequenceAsHashMap aArgHash( seqArguments );
+ ::rtl::OUString aFilterString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
+ ::rtl::OUString aFilterName = aArgHash.getUnpackedValueOrDefault( aFilterString, ::rtl::OUString() );
+ if ( aFilterName.getLength() )
+ {
+ SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
+ if ( pMedium )
+ {
+ const SfxFilter* pFilter = pMedium->GetFilter();
+ if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) )
+ {
+ aArgHash.erase( aFilterString );
+ aArgHash.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
+
+ try
+ {
+ storeSelf( aArgHash.getAsConstPropertyValueList() );
+ bSaved = sal_True;
+ }
+ catch( const lang::IllegalArgumentException& )
+ {
+ // some additional arguments do not allow to use saving, SaveAs should be done
+ // but only for normal documents, the shared documents would be overwritten in this case
+ // that would mean an information loss
+ // TODO/LATER: need a new interaction for this case
+ if ( m_pData->m_pObjectShell->IsDocShared() )
+ {
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) );
+ m_pData->m_pObjectShell->StoreLog();
+
+ uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) ), uno::Sequence< beans::NamedValue >() );
+ if ( !aNewEncryptionData.getLength() )
+ {
+ ::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), ::rtl::OUString() );
+ aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword );
+ }
+
+ uno::Sequence< beans::NamedValue > aOldEncryptionData;
+ GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData );
+
+ if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() )
+ throw;
+ else
+ {
+ // if the password is changed a special error should be used in case of shared document
+ throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE );
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if ( !bSaved && m_pData->m_pObjectShell )
+ {
+ SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOC : SFX_EVENT_SAVEASDOC, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOC : STR_EVENT_SAVEASDOC ),
+ m_pData->m_pObjectShell ) );
+
+ SfxAllItemSet *aParams = new SfxAllItemSet( SFX_APP()->GetPool() );
+ aParams->Put( SfxStringItem( SID_FILE_NAME, String(sURL) ) );
+ if ( bSaveTo )
+ aParams->Put( SfxBoolItem( SID_SAVETO, sal_True ) );
+
+ TransformParameters( SID_SAVEASDOC, seqArguments, *aParams );
+
+ SFX_ITEMSET_ARG( aParams, pCopyStreamItem, SfxBoolItem, SID_COPY_STREAM_IF_POSSIBLE, sal_False );
+
+ if ( pCopyStreamItem && pCopyStreamItem->GetValue() && !bSaveTo )
+ {
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Misuse of CopyStreamIfPossible!" ) ) );
+ m_pData->m_pObjectShell->StoreLog();
+
+ throw frame::IllegalArgumentIOException(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CopyStreamIfPossible parameter is not acceptable for storeAsURL() call!") ),
+ uno::Reference< uno::XInterface >() );
+ }
+
+ sal_uInt32 nModifyPasswordHash = 0;
+ uno::Sequence< beans::PropertyValue > aModifyPasswordInfo;
+ SFX_ITEMSET_ARG( aParams, pModifyPasswordInfoItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False );
+ if ( pModifyPasswordInfoItem )
+ {
+ // it contains either a simple hash or a set of PropertyValues
+ // TODO/LATER: the sequence of PropertyValue should replace the hash completely in future
+ sal_Int32 nMPHTmp = 0;
+ pModifyPasswordInfoItem->GetValue() >>= nMPHTmp;
+ nModifyPasswordHash = (sal_uInt32)nMPHTmp;
+ pModifyPasswordInfoItem->GetValue() >>= aModifyPasswordInfo;
+ }
+ aParams->ClearItem( SID_MODIFYPASSWORDINFO );
+ sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash();
+ m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash );
+ uno::Sequence< beans::PropertyValue > aOldModifyPasswordInfo = m_pData->m_pObjectShell->GetModifyPasswordInfo();
+ m_pData->m_pObjectShell->SetModifyPasswordInfo( aModifyPasswordInfo );
+
+ // since saving a document modifies its DocumentInfo, the current
+ // DocumentInfo must be saved on "SaveTo", so it can be restored
+ // after saving
+ sal_Bool bCopyTo = bSaveTo ||
+ m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED;
+ uno::Reference<document::XDocumentProperties> xOldDocProps;
+ uno::Reference<document::XDocumentInfo> xOldDocInfo;
+ if ( bCopyTo )
+ {
+ xOldDocProps = getDocumentProperties();
+ if (m_pData->m_xDocumentInfo.is())
+ {
+ xOldDocInfo = getDocumentInfo();
+ const Reference<util::XCloneable> xCloneable(xOldDocInfo,
+ UNO_QUERY_THROW);
+ const Reference<document::XDocumentInfo> xNewDocInfo(
+ xCloneable->createClone(), UNO_QUERY_THROW);
+ const Reference<document::XDocumentPropertiesSupplier> xDPS(
+ xNewDocInfo, UNO_QUERY_THROW);
+ const Reference<document::XDocumentProperties> xNewDocProps(
+ xDPS->getDocumentProperties());
+ m_pData->m_xDocumentProperties = xNewDocProps;
+ m_pData->m_xDocumentInfo = xNewDocInfo;
+ }
+ else // try not to create DocumentInfo if it does not exist...
+ {
+ const Reference<util::XCloneable> xCloneable(xOldDocProps,
+ UNO_QUERY_THROW);
+ const Reference<document::XDocumentProperties> xNewDocProps(
+ xCloneable->createClone(), UNO_QUERY_THROW);
+ m_pData->m_xDocumentProperties = xNewDocProps;
+ }
+ }
+
+ sal_Bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl( sURL, aParams );
+
+ if ( bCopyTo )
+ {
+ // restore DocumentInfo if a copy was created
+ m_pData->m_xDocumentProperties = xOldDocProps;
+ m_pData->m_xDocumentInfo = xOldDocInfo;
+ }
+
+ uno::Reference < task::XInteractionHandler > xHandler;
+ SFX_ITEMSET_ARG( aParams, pItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False);
+ if ( pItem )
+ pItem->GetValue() >>= xHandler;
+
+ DELETEZ( aParams );
+
+ sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetErrorCode();
+ if ( !bRet && !nErrCode )
+ {
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing has failed, no error is set!" ) ) );
+ nErrCode = ERRCODE_IO_CANTWRITE;
+ }
+ m_pData->m_pObjectShell->ResetError();
+
+ if ( bRet )
+ {
+ if ( nErrCode )
+ {
+ // must be a warning - use Interactionhandler if possible or abandone
+ if ( xHandler.is() )
+ {
+ // TODO/LATER: a general way to set the error context should be available
+ SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, m_pData->m_pObjectShell->GetTitle() );
+
+ ::com::sun::star::task::ErrorCodeRequest aErrorCode;
+ aErrorCode.ErrCode = nErrCode;
+ SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
+ }
+ }
+
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing succeeded!" ) ) );
+ if ( !bSaveTo )
+ {
+ m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
+ m_pData->m_pObjectShell->SetModifyPasswordEntered();
+
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEASDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEASDOCDONE), m_pData->m_pObjectShell ) );
+ }
+ else
+ {
+ m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
+ m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
+
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE), m_pData->m_pObjectShell ) );
+ }
+ }
+ else
+ {
+ // let the logring be stored to the related file
+ m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) );
+ m_pData->m_pObjectShell->StoreLog();
+
+ m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
+ m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo );
+
+
+ SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOCFAILED : SFX_EVENT_SAVEASDOCFAILED, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOCFAILED : STR_EVENT_SAVEASDOCFAILED),
+ m_pData->m_pObjectShell ) );
+
+ throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode );
+ }
+ }
+}
+
+//********************************************************************************************************
+namespace {
+template< typename ListenerT, typename EventT >
+class NotifySingleListenerIgnoreRE
+{
+private:
+ typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& );
+ NotificationMethod m_pMethod;
+ const EventT& m_rEvent;
+public:
+ NotifySingleListenerIgnoreRE( NotificationMethod method, const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
+
+ void operator()( const uno::Reference<ListenerT>& listener ) const
+ {
+ try
+ {
+ (listener.get()->*m_pMethod)( m_rEvent );
+ }
+ catch( uno::RuntimeException& )
+ {
+ // this exception is ignored to avoid problems with invalid listeners, the listener should be probably thrown away in future
+ }
+ }
+};
+} // anonymous namespace
+
+void SfxBaseModel::postEvent_Impl( const ::rtl::OUString& aName, const uno::Reference< frame::XController2 >& xController )
+{
+ // object already disposed?
+ if ( impl_isDisposed() )
+ return;
+
+ DBG_ASSERT( aName.getLength(), "Empty event name!" );
+ if (!aName.getLength())
+ return;
+
+ ::cppu::OInterfaceContainerHelper* pIC =
+ m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XDocumentEventListener >*)0 ) );
+ if ( pIC )
+ {
+#ifdef DBG_UTIL
+ ByteString aTmp( "SfxDocumentEvent: " );
+ aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
+ DBG_TRACE( aTmp.GetBuffer() );
+#endif
+
+ document::DocumentEvent aDocumentEvent( (frame::XModel*)this, aName, xController, uno::Any() );
+
+ pIC->forEach< document::XDocumentEventListener, NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent > >(
+ NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent >(
+ &document::XDocumentEventListener::documentEventOccured,
+ aDocumentEvent ) );
+ }
+
+ pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ) );
+ if ( pIC )
+ {
+#ifdef DBG_UTIL
+ ByteString aTmp( "SfxEvent: " );
+ aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 );
+ DBG_TRACE( aTmp.GetBuffer() );
+#endif
+
+ document::EventObject aEvent( (frame::XModel*)this, aName );
+
+ pIC->forEach< document::XEventListener, NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject > >(
+ NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject >(
+ &document::XEventListener::notifyEvent,
+ aEvent ) );
+ }
+
+}
+
+uno::Reference < container::XIndexAccess > SAL_CALL SfxBaseModel::getViewData() throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( m_pData->m_pObjectShell.Is() && !m_pData->m_contViewData.is() )
+ {
+ SfxViewFrame *pActFrame = SfxViewFrame::Current();
+ if ( !pActFrame || pActFrame->GetObjectShell() != m_pData->m_pObjectShell )
+ pActFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell );
+
+ if ( !pActFrame || !pActFrame->GetViewShell() )
+ // currently no frame for this document at all or View is under construction
+ return uno::Reference < container::XIndexAccess >();
+
+ m_pData->m_contViewData = Reference < container::XIndexAccess >(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.document.IndexedPropertyValues") ),
+ uno::UNO_QUERY );
+
+ if ( !m_pData->m_contViewData.is() )
+ {
+ // error: no container class available!
+ return uno::Reference < container::XIndexAccess >();
+ }
+
+ uno::Reference < container::XIndexContainer > xCont( m_pData->m_contViewData, uno::UNO_QUERY );
+ sal_Int32 nCount = 0;
+ uno::Sequence < beans::PropertyValue > aSeq;
+ ::com::sun::star::uno::Any aAny;
+ for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell ); pFrame;
+ pFrame = SfxViewFrame::GetNext( *pFrame, m_pData->m_pObjectShell ) )
+ {
+ BOOL bIsActive = ( pFrame == pActFrame );
+ pFrame->GetViewShell()->WriteUserDataSequence( aSeq );
+ aAny <<= aSeq;
+ xCont->insertByIndex( bIsActive ? 0 : nCount, aAny );
+ nCount++;
+ }
+ }
+
+ return m_pData->m_contViewData;
+}
+
+void SAL_CALL SfxBaseModel::setViewData( const uno::Reference < container::XIndexAccess >& aData ) throw(::com::sun::star::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ m_pData->m_contViewData = aData;
+}
+
+/** calls all XEventListeners */
+void SfxBaseModel::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) const
+{
+ // object already disposed?
+ if ( impl_isDisposed() )
+ return;
+
+ ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer(
+ ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) );
+ if( pIC )
+
+ {
+ ::cppu::OInterfaceIteratorHelper aIt( *pIC );
+ while( aIt.hasMoreElements() )
+ {
+ try
+ {
+ ((XDOCEVENTLISTENER *)aIt.next())->notifyEvent( aEvent );
+ }
+ catch( uno::RuntimeException& )
+ {
+ aIt.remove();
+ }
+ }
+ }
+}
+
+/** returns true if someone added a XEventListener to this XEventBroadcaster */
+sal_Bool SfxBaseModel::hasEventListeners() const
+{
+ return !impl_isDisposed() && (NULL != m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) ) );
+}
+
+void SAL_CALL SfxBaseModel::addPrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+
+ if ( impl_getPrintHelper() )
+ {
+ uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
+ if ( xPJB.is() )
+ xPJB->addPrintJobListener( xListener );
+ }
+// else
+// m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
+}
+
+void SAL_CALL SfxBaseModel::removePrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( impl_getPrintHelper() )
+ {
+ uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY );
+ if ( xPJB.is() )
+ xPJB->removePrintJobListener( xListener );
+ }
+// else
+// m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener );
+}
+
+// simple declaration of class SvObject is enough
+// the corresponding <so3/iface.hxx> cannon be included because it provides
+// declaration of class SvBorder that conflicts with ../../inc/viewfrm.hxx
+class SvObject;
+sal_Int64 SAL_CALL SfxBaseModel::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( GetObjectShell() )
+ {
+ SvGlobalName aName( aIdentifier );
+ if ( aName == SvGlobalName( SO3_GLOBAL_CLASSID ) )
+ return (sal_Int64)(sal_IntPtr)(SvObject*)GetObjectShell();
+ else if ( aName == SvGlobalName( SFX_GLOBAL_CLASSID ) )
+ return (sal_Int64)(sal_IntPtr)(SfxObjectShell*)GetObjectShell();
+ }
+
+ return 0;
+}
+
+//____________________________________________________________________________________________________
+// XDocumentSubStorageSupplier
+//____________________________________________________________________________________________________
+
+void SfxBaseModel::ListenForStorage_Impl( const uno::Reference< embed::XStorage >& xStorage )
+{
+ uno::Reference< util::XModifiable > xModifiable( xStorage, uno::UNO_QUERY );
+ if ( xModifiable.is() )
+ {
+ if ( !m_pData->m_pStorageModifyListen.is() )
+ {
+ m_pData->m_pStorageModifyListen = new ::sfx2::DocumentStorageModifyListener( *m_pData, Application::GetSolarMutex() );
+ }
+
+ // no need to deregister the listening for old storage since it should be disposed automatically
+ xModifiable->addModifyListener( m_pData->m_pStorageModifyListen.get() );
+ }
+}
+
+uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode )
+ throw ( uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< XSTORAGE > xResult;
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ uno::Reference< embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
+ if ( xStorage.is() )
+ {
+ try
+ {
+ xResult = xStorage->openStorageElement( aStorageName, nMode );
+ }
+ catch ( uno::Exception& )
+ {
+ }
+ }
+ }
+
+ return xResult;
+}
+
+Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getDocumentSubStoragesNames()
+ throw ( io::IOException,
+ RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ Sequence< ::rtl::OUString > aResult;
+ sal_Int32 nResultSize = 0;
+ sal_Bool bSuccess = sal_False;
+ if ( m_pData->m_pObjectShell.Is() )
+ {
+ uno::Reference < embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage();
+ uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
+ if ( xAccess.is() )
+ {
+ Sequence< ::rtl::OUString > aTemp = xAccess->getElementNames();
+ for ( sal_Int32 n = 0; n < aTemp.getLength(); n++ )
+ {
+ if ( xStorage->isStorageElement( aTemp[n] ) )
+ {
+ aResult.realloc( ++nResultSize );
+ aResult[ nResultSize - 1 ] = aTemp[n];
+ }
+ }
+
+ bSuccess = sal_True;
+ }
+ }
+
+ if ( !bSuccess )
+ throw io::IOException();
+
+ return aResult;
+}
+
+//____________________________________________________________________________________________________
+// XScriptProviderSupplier
+//____________________________________________________________________________________________________
+
+
+uno::Reference< script::provider::XScriptProvider > SAL_CALL SfxBaseModel::getScriptProvider()
+ throw ( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< script::provider::XScriptProvider > xScriptProvider;
+
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ Reference< script::provider::XScriptProviderFactory > xScriptProviderFactory(
+ aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), uno::UNO_QUERY_THROW );
+
+ try
+ {
+ Reference< XScriptInvocationContext > xScriptContext( this );
+ xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( xScriptContext ) ), uno::UNO_SET_THROW );
+ }
+ catch( const uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch( const lang::IllegalArgumentException& )
+ {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString(),
+ *this,
+ ::cppu::getCaughtException()
+ );
+ }
+
+ return xScriptProvider;
+}
+
+//____________________________________________________________________________________________________
+// XUIConfigurationManagerSupplier
+//____________________________________________________________________________________________________
+
+rtl::OUString SfxBaseModel::getRuntimeUID() const
+{
+ OSL_ENSURE( m_pData->m_sRuntimeUID.getLength() > 0,
+ "SfxBaseModel::getRuntimeUID - ID is empty!" );
+ return m_pData->m_sRuntimeUID;
+}
+
+sal_Bool SfxBaseModel::hasValidSignatures() const
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pData->m_pObjectShell.Is() )
+ return ( m_pData->m_pObjectShell->ImplGetSignatureState( sal_False ) == SIGNATURESTATE_SIGNATURES_OK );
+ return sal_False;
+}
+
+static void GetCommandFromSequence( rtl::OUString& rCommand, sal_Int32& nIndex, const uno::Sequence< beans::PropertyValue >& rSeqPropValue )
+{
+ rtl::OUString aCommand;
+ nIndex = -1;
+
+ for ( sal_Int32 i = 0; i < rSeqPropValue.getLength(); i++ )
+ {
+ if ( rSeqPropValue[i].Name.equalsAsciiL( "Command", 7 ))
+ {
+ rSeqPropValue[i].Value >>= rCommand;
+ nIndex = i;
+ return;
+ }
+ }
+}
+
+static void ConvertSlotsToCommands( SfxObjectShell* pDoc, uno::Reference< container::XIndexContainer >& rToolbarDefinition )
+{
+ if ( pDoc )
+ {
+ Any aAny;
+ SfxModule* pModule( pDoc->GetFactory().GetModule() );
+ rtl::OUString aSlotCmd( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
+ rtl::OUString aUnoCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
+ uno::Sequence< beans::PropertyValue > aSeqPropValue;
+
+ for ( sal_Int32 i = 0; i < rToolbarDefinition->getCount(); i++ )
+ {
+ sal_Int32 nIndex( -1 );
+ rtl::OUString aCommand;
+
+ if ( rToolbarDefinition->getByIndex( i ) >>= aSeqPropValue )
+ {
+ GetCommandFromSequence( aCommand, nIndex, aSeqPropValue );
+ if ( nIndex >= 0 && ( aCommand.indexOf( aSlotCmd ) == 0 ))
+ {
+ rtl::OUString aSlot( aCommand.copy( 5 ));
+
+ // We have to replace the old "slot-Command" with our new ".uno:-Command"
+ const SfxSlot* pSlot = pModule->GetSlotPool()->GetSlot( USHORT( aSlot.toInt32() ));
+ if ( pSlot )
+ {
+ rtl::OUStringBuffer aStrBuf( aUnoCmd );
+ aStrBuf.appendAscii( pSlot->GetUnoName() );
+
+ aCommand = aStrBuf.makeStringAndClear();
+ aSeqPropValue[nIndex].Value <<= aCommand;
+ rToolbarDefinition->replaceByIndex( i, Any( aSeqPropValue ));
+ }
+ }
+ }
+ }
+ }
+}
+
+uno::Reference< ui::XUIConfigurationManager > SAL_CALL SfxBaseModel::getUIConfigurationManager()
+ throw ( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( !m_pData->m_xUIConfigurationManager.is() )
+ {
+ uno::Reference< ui::XUIConfigurationManager > xNewUIConfMan(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.ui.UIConfigurationManager" )),
+ uno::UNO_QUERY );
+
+ Reference< ui::XUIConfigurationStorage > xUIConfigStorage( xNewUIConfMan, uno::UNO_QUERY );
+ if ( xUIConfigStorage.is() )
+ {
+ uno::Reference< XSTORAGE > xConfigStorage;
+
+ rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
+ // First try to open with READWRITE and then READ
+ xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READWRITE );
+ if ( xConfigStorage.is() )
+ {
+ rtl::OUString aMediaTypeProp( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ));
+ rtl::OUString aUIConfigMediaType(
+ RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.xml.ui.configuration" ) );
+ rtl::OUString aMediaType;
+ uno::Reference< beans::XPropertySet > xPropSet( xConfigStorage, uno::UNO_QUERY );
+ Any a = xPropSet->getPropertyValue( aMediaTypeProp );
+ if ( !( a >>= aMediaType ) || ( aMediaType.getLength() == 0 ))
+ {
+ a <<= aUIConfigMediaType;
+ xPropSet->setPropertyValue( aMediaTypeProp, a );
+ }
+ }
+ else
+ xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READ );
+
+ // initialize ui configuration manager with document substorage
+ xUIConfigStorage->setStorage( xConfigStorage );
+
+ // embedded objects did not support local configuration data until OOo 3.0, so there's nothing to
+ // migrate
+ if ( m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
+ {
+ // Import old UI configuration from OOo 1.x
+ uno::Reference< XSTORAGE > xOOo1ConfigStorage;
+ rtl::OUString aOOo1UIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations" ));
+
+ // Try to open with READ
+ xOOo1ConfigStorage = getDocumentSubStorage( aOOo1UIConfigFolderName, embed::ElementModes::READ );
+ if ( xOOo1ConfigStorage.is() )
+ {
+ uno::Reference< lang::XMultiServiceFactory > xServiceMgr( ::comphelper::getProcessServiceFactory() );
+ uno::Sequence< uno::Reference< container::XIndexContainer > > rToolbars;
+
+ sal_Bool bImported = framework::UIConfigurationImporterOOo1x::ImportCustomToolbars(
+ xNewUIConfMan, rToolbars, xServiceMgr, xOOo1ConfigStorage );
+ if ( bImported )
+ {
+ SfxObjectShell* pObjShell = SfxBaseModel::GetObjectShell();
+
+ char aNum[] = "private:resource/toolbar/custom_OOo1x_0";
+ char aTitle[] = "Toolbar 0";
+ sal_Int32 nNumIndex = strlen( aNum )-1;
+ sal_Int32 nTitleIndex = strlen( aTitle )-1;
+ for ( sal_Int32 i = 0; i < rToolbars.getLength(); i++ )
+ {
+ aNum[nNumIndex]++;
+ aTitle[nTitleIndex]++;
+
+ rtl::OUString aCustomTbxName( RTL_CONSTASCII_USTRINGPARAM( aNum ));
+ rtl::OUString aCustomTbxTitle( RTL_CONSTASCII_USTRINGPARAM( aTitle ));
+
+ uno::Reference< container::XIndexContainer > xToolbar = rToolbars[i];
+ ConvertSlotsToCommands( pObjShell, xToolbar );
+ if ( !xNewUIConfMan->hasSettings( aCustomTbxName ))
+ {
+ // Set UIName for the toolbar with container property
+ uno::Reference< beans::XPropertySet > xPropSet( xToolbar, UNO_QUERY );
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ rtl::OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( "UIName" ));
+ Any aAny( aCustomTbxTitle );
+ xPropSet->setPropertyValue( aPropName, aAny );
+ }
+ catch ( beans::UnknownPropertyException& )
+ {
+ }
+ }
+
+ uno::Reference< container::XIndexAccess > xToolbarData( xToolbar, uno::UNO_QUERY );
+ xNewUIConfMan->insertSettings( aCustomTbxName, xToolbarData );
+ uno::Reference< ui::XUIConfigurationPersistence > xPersist( xNewUIConfMan, uno::UNO_QUERY );
+ xPersist->store();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ m_pData->m_xUIConfigurationManager = xNewUIConfMan;
+ }
+
+ return m_pData->m_xUIConfigurationManager;
+}
+
+//____________________________________________________________________________________________________
+// XVisualObject
+//____________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( !m_pData->m_pObjectShell.Is() )
+ throw uno::Exception(); // TODO: error handling
+
+ SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False );
+ if ( pViewFrm && m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !pViewFrm->GetFrame().IsInPlace() )
+ {
+ Window* pWindow = VCLUnoHelper::GetWindow( pViewFrm->GetFrame().GetFrameInterface()->getContainerWindow() );
+ Size aWinSize = pWindow->GetSizePixel();
+ awt::Size aCurrent = getVisualAreaSize( nAspect );
+ Size aDiff( aSize.Width-aCurrent.Width, aSize.Height-aCurrent.Height );
+ Size aWrongDiff = OutputDevice::LogicToLogic( aDiff , m_pData->m_pObjectShell->GetMapUnit(), pWindow->GetMapMode() );
+ aDiff = pViewFrm->GetViewShell()->GetWindow()->LogicToPixel( aDiff );
+ aWinSize.Width() += aDiff.Width();
+ aWinSize.Height() += aDiff.Height();
+ pWindow->SetSizePixel( aWinSize );
+ }
+ else
+ {
+ Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
+ aTmpRect.SetSize( Size( aSize.Width, aSize.Height ) );
+ m_pData->m_pObjectShell->SetVisArea( aTmpRect );
+ }
+}
+
+awt::Size SAL_CALL SfxBaseModel::getVisualAreaSize( sal_Int64 /*nAspect*/ )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( !m_pData->m_pObjectShell.Is() )
+ throw uno::Exception(); // TODO: error handling
+
+ Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT );
+
+#if 0
+ Window* pWindow = NULL;
+ SfxViewFrame* pViewFrm = m_pData->m_pObjectShell.Is() ?
+ SfxViewFrame::GetFirst( m_pData->m_pObjectShell, 0, sal_False ) : 0;
+
+ if ( pWindow )
+ {
+ MapMode aInternalMapMode( pViewFrm->GetWindow().GetMapMode() );
+ MapMode aExternalMapMode( m_pData->m_pObjectShell->GetMapUnit() );
+
+ aTmpRect = OutputDevice::LogicToLogic( aTmpRect, aInternalMapMode, aExternalMapMode );
+ }
+#endif
+
+ return awt::Size( aTmpRect.GetWidth(), aTmpRect.GetHeight() );
+}
+
+
+sal_Int32 SAL_CALL SfxBaseModel::getMapUnit( sal_Int64 /*nAspect*/ )
+ throw ( uno::Exception,
+ uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( !m_pData->m_pObjectShell.Is() )
+ throw uno::Exception(); // TODO: error handling
+
+ return VCLUnoHelper::VCL2UnoEmbedMapUnit( m_pData->m_pObjectShell->GetMapUnit() );
+}
+
+embed::VisualRepresentation SAL_CALL SfxBaseModel::getPreferredVisualRepresentation( ::sal_Int64 /*nAspect*/ )
+ throw ( lang::IllegalArgumentException,
+ embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ datatransfer::DataFlavor aDataFlavor(
+ ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
+ ::rtl::OUString::createFromAscii( "GDIMetaFile" ),
+ ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
+
+ embed::VisualRepresentation aVisualRepresentation;
+ aVisualRepresentation.Data = getTransferData( aDataFlavor );
+ aVisualRepresentation.Flavor = aDataFlavor;
+
+ return aVisualRepresentation;
+}
+
+//____________________________________________________________________________________________________
+// XStorageBasedDocument
+//____________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseModel::loadFromStorage( const uno::Reference< XSTORAGE >& xStorage,
+ const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
+ throw ( lang::IllegalArgumentException,
+ DOUBLEINITIALIZATIONEXCEPTION,
+ IOEXCEPTION,
+ EXCEPTION,
+ uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+ if ( IsInitialized() )
+ throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this );
+
+ // after i36090 is fixed the pool from object shell can be used
+ // SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
+ SfxAllItemSet aSet( SFX_APP()->GetPool() );
+
+ // the BaseURL is part of the ItemSet
+ SfxMedium* pMedium = new SfxMedium( xStorage, String() );
+ TransformParameters( SID_OPENDOC, aMediaDescriptor, aSet );
+ pMedium->GetItemSet()->Put( aSet );
+
+ // allow to use an interactionhandler (if there is one)
+ pMedium->UseInteractionHandler( TRUE );
+
+ SFX_ITEMSET_ARG( &aSet, pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
+ BOOL bTemplate = pTemplateItem && pTemplateItem->GetValue();
+ m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC );
+ m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = FALSE;
+
+ // load document
+ if ( !m_pData->m_pObjectShell->DoLoad(pMedium) )
+ {
+ sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ nError ? nError : ERRCODE_IO_CANTREAD );
+ }
+}
+
+void SAL_CALL SfxBaseModel::storeToStorage( const uno::Reference< XSTORAGE >& xStorage,
+ const uno::Sequence< beans::PropertyValue >& aMediaDescriptor )
+ throw ( lang::IllegalArgumentException,
+ IOEXCEPTION,
+ EXCEPTION,
+ uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< XSTORAGE > xResult;
+ if ( !m_pData->m_pObjectShell.Is() )
+ throw IOEXCEPTION(); // TODO:
+
+ SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() );
+ TransformParameters( SID_SAVEASDOC, aMediaDescriptor, aSet );
+
+ // TODO/LATER: may be a special URL "private:storage" should be used
+ SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False );
+ sal_Int32 nVersion = SOFFICE_FILEFORMAT_CURRENT;
+ if( pItem )
+ {
+ String aFilterName = pItem->GetValue();
+ const SfxFilter* pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName );
+ if ( pFilter && pFilter->UsesStorage() )
+ nVersion = pFilter->GetVersion();
+ }
+
+ sal_Bool bSuccess = sal_False;
+ if ( xStorage == m_pData->m_pObjectShell->GetStorage() )
+ {
+ // storing to the own storage
+ bSuccess = m_pData->m_pObjectShell->DoSave();
+ }
+ else
+ {
+ // TODO/LATER: if the provided storage has some data inside the storing might fail, probably the storage must be truncated
+ // TODO/LATER: is it possible to have a template here?
+ m_pData->m_pObjectShell->SetupStorage( xStorage, nVersion, sal_False );
+
+ // BaseURL is part of the ItemSet
+ SfxMedium aMedium( xStorage, String(), &aSet );
+ aMedium.CanDisposeStorage_Impl( FALSE );
+ if ( aMedium.GetFilter() )
+ {
+ // storing without a valid filter will often crash
+ bSuccess = m_pData->m_pObjectShell->DoSaveObjectAs( aMedium, TRUE );
+ m_pData->m_pObjectShell->DoSaveCompleted( NULL );
+ }
+ }
+
+ sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
+ m_pData->m_pObjectShell->ResetError();
+
+ // the warnings are currently not transported
+ if ( !bSuccess )
+ {
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ nError ? nError : ERRCODE_IO_GENERAL );
+ }
+}
+
+void SAL_CALL SfxBaseModel::switchToStorage( const uno::Reference< XSTORAGE >& xStorage )
+ throw ( lang::IllegalArgumentException,
+ IOEXCEPTION,
+ EXCEPTION,
+ uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< XSTORAGE > xResult;
+ if ( !m_pData->m_pObjectShell.Is() )
+ throw IOEXCEPTION(); // TODO:
+
+ // the persistence should be switched only if the storage is different
+ if ( xStorage != m_pData->m_pObjectShell->GetStorage()
+ && !m_pData->m_pObjectShell->SwitchPersistance( xStorage ) )
+ {
+ sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode();
+ throw task::ErrorCodeIOException( ::rtl::OUString(),
+ uno::Reference< uno::XInterface >(),
+ nError ? nError : ERRCODE_IO_GENERAL );
+ }
+
+ m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = FALSE;
+}
+
+uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentStorage()
+ throw ( IOEXCEPTION,
+ EXCEPTION,
+ uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ uno::Reference< XSTORAGE > xResult;
+ if ( !m_pData->m_pObjectShell.Is() )
+ throw IOEXCEPTION(); // TODO
+
+ return m_pData->m_pObjectShell->GetStorage();
+}
+
+void SAL_CALL SfxBaseModel::addStorageChangeListener(
+ const uno::Reference< document::XStorageChangeListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+
+ m_pData->m_aInterfaceContainer.addInterface(
+ ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
+}
+
+void SAL_CALL SfxBaseModel::removeStorageChangeListener(
+ const uno::Reference< document::XStorageChangeListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ m_pData->m_aInterfaceContainer.removeInterface(
+ ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener );
+}
+
+#include "printhelper.hxx"
+bool SfxBaseModel::impl_getPrintHelper()
+{
+ if ( m_pData->m_xPrintable.is() )
+ return true;
+ m_pData->m_xPrintable = new SfxPrintHelper();
+ uno::Reference < lang::XInitialization > xInit( m_pData->m_xPrintable, uno::UNO_QUERY );
+ uno::Sequence < uno::Any > aValues(1);
+ aValues[0] <<= uno::Reference < frame::XModel > (static_cast< frame::XModel* >(this), uno::UNO_QUERY );
+ xInit->initialize( aValues );
+ uno::Reference < view::XPrintJobBroadcaster > xBrd( m_pData->m_xPrintable, uno::UNO_QUERY );
+ xBrd->addPrintJobListener( new SfxPrintHelperListener_Impl( m_pData ) );
+ return true;
+}
+
+//=============================================================================
+// css.frame.XModule
+ void SAL_CALL SfxBaseModel::setIdentifier(const ::rtl::OUString& Identifier)
+ throw (css::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+ m_pData->m_sModuleIdentifier = Identifier;
+}
+
+//=============================================================================
+// css.frame.XModule
+ ::rtl::OUString SAL_CALL SfxBaseModel::getIdentifier()
+ throw (css::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+ if (m_pData->m_sModuleIdentifier.getLength() > 0)
+ return m_pData->m_sModuleIdentifier;
+ if (m_pData->m_pObjectShell)
+ return m_pData->m_pObjectShell->GetFactory().GetDocumentServiceName();
+ return ::rtl::OUString();
+}
+
+//=============================================================================
+css::uno::Reference< css::frame::XTitle > SfxBaseModel::impl_getTitleHelper ()
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( ! m_pData->m_xTitleHelper.is ())
+ {
+ css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory ();
+ css::uno::Reference< css::frame::XUntitledNumbers > xDesktop(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
+ css::uno::Reference< css::frame::XModel > xThis (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
+
+ ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(xSMGR);
+ m_pData->m_xTitleHelper = css::uno::Reference< css::frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
+ pHelper->setOwner (xThis );
+ pHelper->connectWithUntitledNumbers (xDesktop);
+ }
+
+ return m_pData->m_xTitleHelper;
+}
+
+//=============================================================================
+css::uno::Reference< css::frame::XUntitledNumbers > SfxBaseModel::impl_getUntitledHelper ()
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( ! m_pData->m_xNumberedControllers.is ())
+ {
+ css::uno::Reference< css::frame::XModel > xThis (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW);
+ ::comphelper::NumberedCollection* pHelper = new ::comphelper::NumberedCollection();
+
+ m_pData->m_xNumberedControllers = css::uno::Reference< css::frame::XUntitledNumbers >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
+
+ pHelper->setOwner (xThis);
+ pHelper->setUntitledPrefix (::rtl::OUString::createFromAscii(" : "));
+ }
+
+ return m_pData->m_xNumberedControllers;
+}
+
+//=============================================================================
+// css.frame.XTitle
+::rtl::OUString SAL_CALL SfxBaseModel::getTitle()
+ throw (css::uno::RuntimeException)
+{
+ // SYNCHRONIZED ->
+ SfxModelGuard aGuard( *this );
+
+ ::rtl::OUString aResult = impl_getTitleHelper()->getTitle ();
+ if ( m_pData->m_pObjectShell )
+ {
+ SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
+ if ( pMedium )
+ {
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False );
+ if ( pRepairedDocItem && pRepairedDocItem->GetValue() )
+ aResult += String( SfxResId(STR_REPAIREDDOCUMENT) );
+ }
+
+ if ( m_pData->m_pObjectShell->IsReadOnlyUI() || (m_pData->m_pObjectShell->GetMedium() && m_pData->m_pObjectShell->GetMedium()->IsReadOnly()) )
+ aResult += ::rtl::OUString( String( SfxResId(STR_READONLY) ) );
+ else if ( m_pData->m_pObjectShell->IsDocShared() )
+ aResult += ::rtl::OUString( String( SfxResId(STR_SHARED) ) );
+
+ if ( m_pData->m_pObjectShell->GetDocumentSignatureState() == SIGNATURESTATE_SIGNATURES_OK )
+ aResult += String( SfxResId( RID_XMLSEC_DOCUMENTSIGNED ) );
+ }
+
+ return aResult;
+}
+
+//=============================================================================
+// css.frame.XTitle
+void SAL_CALL SfxBaseModel::setTitle( const ::rtl::OUString& sTitle )
+ throw (css::uno::RuntimeException)
+{
+ // SYNCHRONIZED ->
+ SfxModelGuard aGuard( *this );
+
+ impl_getTitleHelper()->setTitle (sTitle);
+}
+
+//=============================================================================
+// css.frame.XTitleChangeBroadcaster
+void SAL_CALL SfxBaseModel::addTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
+ throw (css::uno::RuntimeException)
+{
+ // SYNCHRONIZED ->
+ SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING );
+
+ css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
+ if (xBroadcaster.is ())
+ xBroadcaster->addTitleChangeListener (xListener);
+}
+
+//=============================================================================
+// css.frame.XTitleChangeBroadcaster
+void SAL_CALL SfxBaseModel::removeTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
+ throw (css::uno::RuntimeException)
+{
+ // SYNCHRONIZED ->
+ SfxModelGuard aGuard( *this );
+
+ css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
+ if (xBroadcaster.is ())
+ xBroadcaster->removeTitleChangeListener (xListener);
+}
+
+//=============================================================================
+// css.frame.XUntitledNumbers
+::sal_Int32 SAL_CALL SfxBaseModel::leaseNumber( const css::uno::Reference< css::uno::XInterface >& xComponent )
+ throw (css::lang::IllegalArgumentException,
+ css::uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+
+ return impl_getUntitledHelper ()->leaseNumber (xComponent);
+}
+
+//=============================================================================
+// css.frame.XUntitledNumbers
+void SAL_CALL SfxBaseModel::releaseNumber( ::sal_Int32 nNumber )
+ throw (css::lang::IllegalArgumentException,
+ css::uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+ impl_getUntitledHelper ()->releaseNumber (nNumber);
+}
+
+//=============================================================================
+// css.frame.XUntitledNumbers
+void SAL_CALL SfxBaseModel::releaseNumberForComponent( const css::uno::Reference< css::uno::XInterface >& xComponent )
+ throw (css::lang::IllegalArgumentException,
+ css::uno::RuntimeException )
+{
+ SfxModelGuard aGuard( *this );
+ impl_getUntitledHelper ()->releaseNumberForComponent (xComponent);
+}
+
+//=============================================================================
+// css.frame.XUntitledNumbers
+::rtl::OUString SAL_CALL SfxBaseModel::getUntitledPrefix()
+ throw (css::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+ return impl_getUntitledHelper ()->getUntitledPrefix ();
+}
+
+//=============================================================================
+// css::frame::XModel2
+css::uno::Reference< css::container::XEnumeration > SAL_CALL SfxBaseModel::getControllers()
+ throw (css::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ sal_Int32 c = m_pData->m_seqControllers.getLength();
+ sal_Int32 i = 0;
+ css::uno::Sequence< css::uno::Any > lEnum(c);
+ for (i=0; i<c; ++i)
+ lEnum[i] <<= m_pData->m_seqControllers[i];
+
+ ::comphelper::OAnyEnumeration* pEnum = new ::comphelper::OAnyEnumeration(lEnum);
+ css::uno::Reference< css::container::XEnumeration > xEnum(static_cast< css::container::XEnumeration* >(pEnum), css::uno::UNO_QUERY_THROW);
+ return xEnum;
+}
+
+//=============================================================================
+// css::frame::XModel2
+css::uno::Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getAvailableViewControllerNames()
+ throw (css::uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
+ const sal_Int32 nViewFactoryCount = rDocumentFactory.GetViewFactoryCount();
+
+ Sequence< ::rtl::OUString > aViewNames( nViewFactoryCount );
+ for ( sal_Int32 nViewNo = 0; nViewNo < nViewFactoryCount; ++nViewNo )
+ aViewNames[nViewNo] = rDocumentFactory.GetViewFactory( nViewNo ).GetAPIViewName();
+ return aViewNames;
+}
+
+//=============================================================================
+// css::frame::XModel2
+css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createDefaultViewController( const css::uno::Reference< css::frame::XFrame >& i_rFrame )
+ throw (css::uno::RuntimeException ,
+ css::lang::IllegalArgumentException,
+ css::uno::Exception )
+{
+ SfxModelGuard aGuard( *this );
+
+ const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory();
+ const ::rtl::OUString sDefaultViewName = rDocumentFactory.GetViewFactory( 0 ).GetAPIViewName();
+
+ aGuard.clear();
+
+ return createViewController( sDefaultViewName, Sequence< PropertyValue >(), i_rFrame );
+}
+
+//=============================================================================
+namespace sfx { namespace intern {
+
+ /** a class which, in its dtor, cleans up variuos objects (well, at the moment only the frame) collected during
+ the creation of a document view, unless the creation was successful.
+ */
+ class SAL_DLLPRIVATE ViewCreationGuard
+ {
+ public:
+ ViewCreationGuard()
+ :m_bSuccess( false )
+ {
+ }
+
+ ~ViewCreationGuard()
+ {
+ if ( !m_bSuccess )
+ impl_closeAll();
+ }
+
+ void takeFrameOwnership( SfxFrame* i_pFrame )
+ {
+ OSL_PRECOND( !m_aWeakFrame, "ViewCreationGuard::takeFrameOwnership: already have a frame!" );
+ OSL_PRECOND( i_pFrame != NULL, "ViewCreationGuard::takeFrameOwnership: invalid frame!" );
+ m_aWeakFrame = i_pFrame;
+ }
+
+ void releaseAll()
+ {
+ m_bSuccess = true;
+ }
+
+ private:
+ void impl_closeAll()
+ {
+ if ( m_aWeakFrame && !m_aWeakFrame->GetCurrentDocument() )
+ {
+ m_aWeakFrame->SetFrameInterface_Impl( NULL );
+ m_aWeakFrame->DoClose();
+ }
+ }
+
+ private:
+ bool m_bSuccess;
+ SfxFrameWeak m_aWeakFrame;
+ };
+} }
+
+//=============================================================================
+SfxViewFrame* SfxBaseModel::FindOrCreateViewFrame_Impl( const Reference< XFrame >& i_rFrame, ::sfx::intern::ViewCreationGuard& i_rGuard ) const
+{
+ SfxViewFrame* pViewFrame = NULL;
+ for ( pViewFrame = SfxViewFrame::GetFirst( GetObjectShell(), FALSE );
+ pViewFrame;
+ pViewFrame= SfxViewFrame::GetNext( *pViewFrame, GetObjectShell(), FALSE )
+ )
+ {
+ if ( pViewFrame->GetFrame().GetFrameInterface() == i_rFrame )
+ break;
+ }
+ if ( !pViewFrame )
+ {
+ #if OSL_DEBUG_LEVEL > 0
+ for ( SfxFrame* pCheckFrame = SfxFrame::GetFirst();
+ pCheckFrame;
+ pCheckFrame = SfxFrame::GetNext( *pCheckFrame )
+ )
+ {
+ if ( pCheckFrame->GetFrameInterface() == i_rFrame )
+ {
+ if ( ( pCheckFrame->GetCurrentViewFrame() != NULL )
+ || ( pCheckFrame->GetCurrentDocument() != NULL )
+ )
+ // Note that it is perfectly letgitimate that during loading into an XFrame which already contains
+ // a document, there exist two SfxFrame instances bound to this XFrame - the old one, which will be
+ // destroyed later, and the new one, which we're going to create
+ continue;
+
+ OSL_ENSURE( false, "SfxBaseModel::FindOrCreateViewFrame_Impl: there already is an SfxFrame for the given XFrame, but no view in it!" );
+ // nowadays, we're the only instance allowed to create an SfxFrame for an XFrame, so this case here should not happen
+ break;
+ }
+ }
+ #endif
+
+ SfxFrame* pTargetFrame = SfxFrame::Create( i_rFrame );
+ ENSURE_OR_THROW( pTargetFrame, "could not create an SfxFrame" );
+ i_rGuard.takeFrameOwnership( pTargetFrame );
+
+ // prepare it
+ pTargetFrame->PrepareForDoc_Impl( *GetObjectShell() );
+
+ // create view frame
+ pViewFrame = new SfxViewFrame( *pTargetFrame, GetObjectShell() );
+ }
+ return pViewFrame;
+}
+
+//=============================================================================
+// css::frame::XModel2
+css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createViewController(
+ const ::rtl::OUString& i_rViewName, const Sequence< PropertyValue >& i_rArguments, const Reference< XFrame >& i_rFrame )
+ throw (css::uno::RuntimeException ,
+ css::lang::IllegalArgumentException,
+ css::uno::Exception )
+{
+ SfxModelGuard aGuard( *this );
+
+ if ( !i_rFrame.is() )
+ throw css::lang::IllegalArgumentException( ::rtl::OUString(), *this, 3 );
+
+ // find the proper SFX view factory
+ SfxViewFactory* pViewFactory = GetObjectShell()->GetFactory().GetViewFactoryByViewName( i_rViewName );
+ if ( !pViewFactory )
+ throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
+
+ // determine previous shell (used in some special cases)
+ Reference< XController > xPreviousController( i_rFrame->getController() );
+ const Reference< XModel > xMe( this );
+ if ( ( xPreviousController.is() )
+ && ( xMe != xPreviousController->getModel() )
+ )
+ {
+ xPreviousController.clear();
+ }
+ SfxViewShell* pOldViewShell = SfxViewShell::Get( xPreviousController );
+ OSL_ENSURE( !xPreviousController.is() || ( pOldViewShell != NULL ),
+ "SfxBaseModel::createViewController: invalid old controller!" );
+
+ // a guard which will clean up in case of failure
+ ::sfx::intern::ViewCreationGuard aViewCreationGuard;
+
+ // determine the ViewFrame belonging to the given XFrame
+ SfxViewFrame* pViewFrame = FindOrCreateViewFrame_Impl( i_rFrame, aViewCreationGuard );
+ OSL_POSTCOND( pViewFrame, "SfxBaseModel::createViewController: no frame?" );
+
+ // delegate to SFX' view factory
+ pViewFrame->GetBindings().ENTERREGISTRATIONS();
+ SfxViewShell* pViewShell = pViewFactory->CreateInstance( pViewFrame, pOldViewShell );
+ pViewFrame->GetBindings().LEAVEREGISTRATIONS();
+ ENSURE_OR_THROW( pViewShell, "invalid view shell provided by factory" );
+
+ // by setting the ViewShell it is prevented that disposing the Controller will destroy this ViewFrame also
+ pViewFrame->GetDispatcher()->SetDisableFlags( 0 );
+ pViewFrame->SetViewShell_Impl( pViewShell );
+
+ // remember ViewID
+ pViewFrame->SetCurViewId_Impl( pViewFactory->GetOrdinal() );
+
+ // ensure a default controller, if the view shell did not provide an own implementation
+ if ( !pViewShell->GetController().is() )
+ pViewShell->SetController( new SfxBaseController( pViewShell ) );
+
+ // pass the creation arguments to the controller
+ SfxBaseController* pBaseController = pViewShell->GetBaseController_Impl();
+ ENSURE_OR_THROW( pBaseController, "invalid controller implementation!" );
+ pBaseController->SetCreationArguments_Impl( i_rArguments );
+
+ // some initial view settings, coming from our most recent attachResource call
+ ::comphelper::NamedValueCollection aDocumentLoadArgs( getArgs() );
+ if ( aDocumentLoadArgs.getOrDefault( "ViewOnly", false ) )
+ pViewFrame->GetFrame().SetMenuBarOn_Impl( FALSE );
+
+ const sal_Int16 nPluginMode = aDocumentLoadArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
+ if ( nPluginMode == 1 )
+ {
+ pViewFrame->ForceOuterResize_Impl( FALSE );
+ pViewFrame->GetBindings().HidePopups( TRUE );
+
+ SfxFrame& rFrame = pViewFrame->GetFrame();
+ // MBA: layoutmanager of inplace frame starts locked and invisible
+ rFrame.GetWorkWindow_Impl()->MakeVisible_Impl( FALSE );
+ rFrame.GetWorkWindow_Impl()->Lock_Impl( TRUE );
+
+ rFrame.GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
+ pViewFrame->GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
+ }
+
+ // tell the guard we were successful
+ aViewCreationGuard.releaseAll();
+
+ // outta gere
+ return pBaseController;
+}
+
+//=============================================================================
+// RDF DocumentMetadataAccess
+
+// ::com::sun::star::rdf::XRepositorySupplier:
+uno::Reference< rdf::XRepository > SAL_CALL
+SfxBaseModel::getRDFRepository() throw (uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getRDFRepository();
+}
+
+// ::com::sun::star::rdf::XNode:
+::rtl::OUString SAL_CALL
+SfxBaseModel::getStringValue() throw (uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getStringValue();
+}
+
+// ::com::sun::star::rdf::XURI:
+::rtl::OUString SAL_CALL
+SfxBaseModel::getNamespace() throw (uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getNamespace();
+}
+
+::rtl::OUString SAL_CALL
+SfxBaseModel::getLocalName() throw (uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getLocalName();
+}
+
+// ::com::sun::star::rdf::XDocumentMetadataAccess:
+uno::Reference< rdf::XMetadatable > SAL_CALL
+SfxBaseModel::getElementByMetadataReference(
+ const ::com::sun::star::beans::StringPair & i_rReference)
+throw (uno::RuntimeException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getElementByMetadataReference(i_rReference);
+}
+
+uno::Reference< rdf::XMetadatable > SAL_CALL
+SfxBaseModel::getElementByURI(const uno::Reference< rdf::XURI > & i_xURI)
+throw (uno::RuntimeException, lang::IllegalArgumentException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getElementByURI(i_xURI);
+}
+
+uno::Sequence< uno::Reference< rdf::XURI > > SAL_CALL
+SfxBaseModel::getMetadataGraphsWithType(
+ const uno::Reference<rdf::XURI> & i_xType)
+throw (uno::RuntimeException, lang::IllegalArgumentException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getMetadataGraphsWithType(i_xType);
+}
+
+uno::Reference<rdf::XURI> SAL_CALL
+SfxBaseModel::addMetadataFile(const ::rtl::OUString & i_rFileName,
+ const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::ElementExistException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->addMetadataFile(i_rFileName, i_rTypes);
+}
+
+uno::Reference<rdf::XURI> SAL_CALL
+SfxBaseModel::importMetadataFile(::sal_Int16 i_Format,
+ const uno::Reference< io::XInputStream > & i_xInStream,
+ const ::rtl::OUString & i_rFileName,
+ const uno::Reference< rdf::XURI > & i_xBaseURI,
+ const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ datatransfer::UnsupportedFlavorException,
+ container::ElementExistException, rdf::ParseException, io::IOException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->importMetadataFile(i_Format,
+ i_xInStream, i_rFileName, i_xBaseURI, i_rTypes);
+}
+
+void SAL_CALL
+SfxBaseModel::removeMetadataFile(
+ const uno::Reference< rdf::XURI > & i_xGraphName)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::NoSuchElementException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->removeMetadataFile(i_xGraphName);
+}
+
+void SAL_CALL
+SfxBaseModel::addContentOrStylesFile(const ::rtl::OUString & i_rFileName)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::ElementExistException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->addContentOrStylesFile(i_rFileName);
+}
+
+void SAL_CALL
+SfxBaseModel::removeContentOrStylesFile(const ::rtl::OUString & i_rFileName)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::NoSuchElementException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->removeContentOrStylesFile(i_rFileName);
+}
+
+void SAL_CALL
+SfxBaseModel::loadMetadataFromStorage(
+ uno::Reference< embed::XStorage > const & i_xStorage,
+ uno::Reference<rdf::XURI> const & i_xBaseURI,
+ uno::Reference<task::XInteractionHandler> const & i_xHandler)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
+ m_pData->CreateDMAUninitialized());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ try {
+ xDMA->loadMetadataFromStorage(i_xStorage, i_xBaseURI, i_xHandler);
+ } catch (lang::IllegalArgumentException &) {
+ throw; // not initialized
+ } catch (uno::Exception &) {
+ // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
+ m_pData->m_xDocumentMetadata = xDMA;
+ throw;
+ }
+ m_pData->m_xDocumentMetadata = xDMA;
+
+}
+
+void SAL_CALL
+SfxBaseModel::storeMetadataToStorage(
+ uno::Reference< embed::XStorage > const & i_xStorage)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->storeMetadataToStorage(i_xStorage);
+}
+
+void SAL_CALL
+SfxBaseModel::loadMetadataFromMedium(
+ const uno::Sequence< beans::PropertyValue > & i_rMedium)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
+ m_pData->CreateDMAUninitialized());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ try {
+ xDMA->loadMetadataFromMedium(i_rMedium);
+ } catch (lang::IllegalArgumentException &) {
+ throw; // not initialized
+ } catch (uno::Exception &) {
+ // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
+ m_pData->m_xDocumentMetadata = xDMA;
+ throw;
+ }
+ m_pData->m_xDocumentMetadata = xDMA;
+}
+
+void SAL_CALL
+SfxBaseModel::storeMetadataToMedium(
+ const uno::Sequence< beans::PropertyValue > & i_rMedium)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ SfxModelGuard aGuard( *this );
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->storeMetadataToMedium(i_rMedium);
+}
+
diff --git a/sfx2/source/doc/sfxmodelfactory.cxx b/sfx2/source/doc/sfxmodelfactory.cxx
new file mode 100644
index 000000000000..714dfc2ea824
--- /dev/null
+++ b/sfx2/source/doc/sfxmodelfactory.cxx
@@ -0,0 +1,239 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include "sfx2/sfxmodelfactory.hxx"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+/** === end UNO includes === **/
+
+#include <comphelper/namedvaluecollection.hxx>
+#include <cppuhelper/implbase2.hxx>
+
+#include <algorithm>
+#include <functional>
+
+//........................................................................
+namespace sfx2
+{
+//........................................................................
+
+ /** === begin UNO using === **/
+ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::uno::XInterface;
+ using ::com::sun::star::uno::UNO_QUERY;
+ using ::com::sun::star::uno::UNO_QUERY_THROW;
+ using ::com::sun::star::uno::UNO_SET_THROW;
+ using ::com::sun::star::uno::Exception;
+ using ::com::sun::star::uno::RuntimeException;
+ using ::com::sun::star::uno::Any;
+ using ::com::sun::star::uno::makeAny;
+ using ::com::sun::star::lang::XMultiServiceFactory;
+ using ::com::sun::star::uno::Sequence;
+ using ::com::sun::star::lang::XSingleServiceFactory;
+ using ::com::sun::star::lang::XServiceInfo;
+ using ::com::sun::star::beans::NamedValue;
+ using ::com::sun::star::beans::PropertyValue;
+ using ::com::sun::star::lang::XInitialization;
+ /** === end UNO using === **/
+
+ //====================================================================
+ //= SfxModelFactory - declaration
+ //====================================================================
+ typedef ::cppu::WeakImplHelper2 < XSingleServiceFactory
+ , XServiceInfo
+ > SfxModelFactory_Base;
+ /** implements a XSingleServiceFactory which can be used to created instances
+ of classes derived from SfxBaseModel
+
+ In opposite to the default implementations from module cppuhelper, this
+ factory evaluates certain creation arguments (passed to createInstanceWithArguments)
+ and passes them to the factory function of the derived class.
+ */
+ class SfxModelFactory : public SfxModelFactory_Base
+ {
+ public:
+ SfxModelFactory(
+ const Reference< XMultiServiceFactory >& _rxServiceFactory,
+ const ::rtl::OUString& _rImplementationName,
+ const SfxModelFactoryFunc _pComponentFactoryFunc,
+ const Sequence< ::rtl::OUString >& _rServiceNames
+ );
+
+ // XSingleServiceFactory
+ virtual Reference< XInterface > SAL_CALL createInstance( ) throw (Exception, RuntimeException);
+ virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException);
+
+ // XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (RuntimeException);
+ virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException);
+ virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException);
+
+ protected:
+ virtual ~SfxModelFactory();
+
+ private:
+ Reference< XInterface > impl_createInstance( const sal_uInt64 _nCreationFlags ) const;
+
+ private:
+ const Reference< XMultiServiceFactory > m_xServiceFactory;
+ const ::rtl::OUString m_sImplementationName;
+ const Sequence< ::rtl::OUString > m_aServiceNames;
+ const SfxModelFactoryFunc m_pComponentFactoryFunc;
+ };
+
+ //====================================================================
+ //= SfxModelFactory - implementation
+ //====================================================================
+ //--------------------------------------------------------------------
+ SfxModelFactory::SfxModelFactory( const Reference< XMultiServiceFactory >& _rxServiceFactory,
+ const ::rtl::OUString& _rImplementationName, const SfxModelFactoryFunc _pComponentFactoryFunc,
+ const Sequence< ::rtl::OUString >& _rServiceNames )
+ :m_xServiceFactory( _rxServiceFactory )
+ ,m_sImplementationName( _rImplementationName )
+ ,m_aServiceNames( _rServiceNames )
+ ,m_pComponentFactoryFunc( _pComponentFactoryFunc )
+ {
+ }
+
+ //--------------------------------------------------------------------
+ SfxModelFactory::~SfxModelFactory()
+ {
+ }
+
+ //--------------------------------------------------------------------
+ Reference< XInterface > SfxModelFactory::impl_createInstance( const sal_uInt64 _nCreationFlags ) const
+ {
+ return (*m_pComponentFactoryFunc)( m_xServiceFactory, _nCreationFlags );
+ }
+
+ //--------------------------------------------------------------------
+ Reference< XInterface > SAL_CALL SfxModelFactory::createInstance( ) throw (Exception, RuntimeException)
+ {
+ return createInstanceWithArguments( Sequence< Any >() );
+ }
+
+ //--------------------------------------------------------------------
+ namespace
+ {
+ struct IsSpecialArgument : public ::std::unary_function< Any, bool >
+ {
+ static bool isSpecialArgumentName( const ::rtl::OUString& _rValueName )
+ {
+ return _rValueName.equalsAscii( "EmbeddedObject" )
+ || _rValueName.equalsAscii( "EmbeddedScriptSupport" )
+ || _rValueName.equalsAscii( "DocumentRecoverySupport" );
+ }
+
+ bool operator()( const Any& _rArgument ) const
+ {
+ NamedValue aNamedValue;
+ if ( ( _rArgument >>= aNamedValue ) && isSpecialArgumentName( aNamedValue.Name ) )
+ return true;
+ PropertyValue aPropertyValue;
+ if ( ( _rArgument >>= aPropertyValue ) && isSpecialArgumentName( aPropertyValue.Name ) )
+ return true;
+ return false;
+ }
+ };
+ }
+
+ //--------------------------------------------------------------------
+ Reference< XInterface > SAL_CALL SfxModelFactory::createInstanceWithArguments( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
+ {
+ ::comphelper::NamedValueCollection aArgs( _rArguments );
+ const sal_Bool bEmbeddedObject = aArgs.getOrDefault( "EmbeddedObject", sal_False );
+ const sal_Bool bScriptSupport = aArgs.getOrDefault( "EmbeddedScriptSupport", sal_True );
+ const sal_Bool bDocRecoverySupport = aArgs.getOrDefault( "DocumentRecoverySupport", sal_True );
+
+ sal_uInt64 nCreationFlags =
+ ( bEmbeddedObject ? SFXMODEL_EMBEDDED_OBJECT : 0 )
+ | ( bScriptSupport ? 0 : SFXMODEL_DISABLE_EMBEDDED_SCRIPTS )
+ | ( bDocRecoverySupport ? 0 : SFXMODEL_DISABLE_DOCUMENT_RECOVERY );
+
+ Reference< XInterface > xInstance( impl_createInstance( nCreationFlags ) );
+
+ // to mimic the bahaviour of the default factory's createInstanceWithArguments, we initialize
+ // the object with the given arguments, stripped by the three special ones
+ Sequence< Any > aStrippedArguments( _rArguments.getLength() );
+ Any* pStrippedArgs = aStrippedArguments.getArray();
+ Any* pStrippedArgsEnd = ::std::remove_copy_if(
+ _rArguments.getConstArray(),
+ _rArguments.getConstArray() + _rArguments.getLength(),
+ pStrippedArgs,
+ IsSpecialArgument()
+ );
+ aStrippedArguments.realloc( pStrippedArgsEnd - pStrippedArgs );
+
+ if ( aStrippedArguments.getLength() )
+ {
+ Reference< XInitialization > xModelInit( xInstance, UNO_QUERY );
+ OSL_ENSURE( xModelInit.is(), "SfxModelFactory::createInstanceWithArguments: no XInitialization!" );
+ if ( xModelInit.is() )
+ xModelInit->initialize( aStrippedArguments );
+ }
+
+ return xInstance;
+ }
+
+ //--------------------------------------------------------------------
+ ::rtl::OUString SAL_CALL SfxModelFactory::getImplementationName( ) throw (RuntimeException)
+ {
+ return m_sImplementationName;
+ }
+
+ //--------------------------------------------------------------------
+ ::sal_Bool SAL_CALL SfxModelFactory::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
+ {
+ return ::std::find(
+ m_aServiceNames.getConstArray(),
+ m_aServiceNames.getConstArray() + m_aServiceNames.getLength(),
+ _rServiceName
+ ) != m_aServiceNames.getConstArray() + m_aServiceNames.getLength();
+ }
+
+ //--------------------------------------------------------------------
+ Sequence< ::rtl::OUString > SAL_CALL SfxModelFactory::getSupportedServiceNames( ) throw (RuntimeException)
+ {
+ return m_aServiceNames;
+ }
+
+ //--------------------------------------------------------------------
+ Reference< XSingleServiceFactory > createSfxModelFactory( const Reference< XMultiServiceFactory >& _rxServiceFactory,
+ const ::rtl::OUString& _rImplementationName, const SfxModelFactoryFunc _pComponentFactoryFunc,
+ const Sequence< ::rtl::OUString >& _rServiceNames )
+ {
+ return new SfxModelFactory( _rxServiceFactory, _rImplementationName, _pComponentFactoryFunc, _rServiceNames );
+ }
+
+//........................................................................
+} // namespace sfx2
+//........................................................................
diff --git a/sfx2/source/doc/syspath.cxx b/sfx2/source/doc/syspath.cxx
new file mode 100755
index 000000000000..a1025370ed24
--- /dev/null
+++ b/sfx2/source/doc/syspath.cxx
@@ -0,0 +1,48 @@
+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2008 by Sun Microsystems, Inc.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: shutdowniconw32.cxx,v $
+* $Revision: 1.48 $
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+// Comment out precompiled statement due to redefinition errors
+#include "precompiled_sfx2.hxx"
+
+#include "syspath.hxx"
+
+extern "C" bool GetUserTemplateLocation(sal_Unicode*, int nSize);
+
+bool SystemPath::GetUserTemplateLocation(sal_Unicode* pFolder, int nSize )
+{
+#ifdef WNT
+ return ::GetUserTemplateLocation( pFolder, nSize );
+#else
+ (void)pFolder;
+ (void)nSize;
+ return false;
+#endif
+}
diff --git a/sfx2/source/doc/syspath.hxx b/sfx2/source/doc/syspath.hxx
new file mode 100644
index 000000000000..015c16f18d26
--- /dev/null
+++ b/sfx2/source/doc/syspath.hxx
@@ -0,0 +1,44 @@
+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2008 by Sun Microsystems, Inc.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: shutdowniconw32.cxx,v $
+* $Revision: 1.48 $
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+#ifndef __SYSPATH_HXX__
+#define __SYSPATH_HXX__
+//#pragma warning(disable:4917)
+
+#include <sfx2/dllapi.h>
+
+class SFX2_DLLPUBLIC SystemPath
+{
+public:
+ static bool GetUserTemplateLocation(sal_Unicode*, int nSize);
+};
+
+#endif
+
diff --git a/sfx2/source/doc/syspathw32.cxx b/sfx2/source/doc/syspathw32.cxx
new file mode 100755
index 000000000000..167dadea2e38
--- /dev/null
+++ b/sfx2/source/doc/syspathw32.cxx
@@ -0,0 +1,87 @@
+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2008 by Sun Microsystems, Inc.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: shutdowniconw32.cxx,v $
+* $Revision: 1.48 $
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+
+#ifdef WNT
+#ifdef _MSC_VER
+#pragma warning(disable:4917)
+#endif
+#include <shlobj.h>
+
+static bool _SHGetSpecialFolderW32( int nFolderID, WCHAR* pszFolder, int nSize )
+{
+ LPITEMIDLIST pidl;
+ HRESULT hHdl = SHGetSpecialFolderLocation( NULL, nFolderID, &pidl );
+
+ if( hHdl == NOERROR )
+ {
+ WCHAR *lpFolder = static_cast< WCHAR* >( HeapAlloc( GetProcessHeap(), 0, 16000 ));
+
+ SHGetPathFromIDListW( pidl, lpFolder );
+ wcsncpy( pszFolder, lpFolder, nSize );
+
+ HeapFree( GetProcessHeap(), 0, lpFolder );
+ IMalloc *pMalloc;
+ if( NOERROR == SHGetMalloc(&pMalloc) )
+ {
+ pMalloc->Free( pidl );
+ pMalloc->Release();
+ }
+ }
+ return true;
+}
+
+#endif
+
+// Copied from sal/types.h to circumvent problems with precompiled headers
+// and redefinitions of BOOL, INT32 and other types. Unfortunately tools
+// also define these type incompatible with Win32 types which leads from
+// time to time to very nasty compilation errors. If someone finds a better
+// way to solve these probs please remove this copied part!
+typedef unsigned short sal_uInt16;
+#if ( defined(WIN32) && !defined(__MINGW32__) )
+ typedef wchar_t sal_Unicode;
+#else
+ typedef sal_uInt16 sal_Unicode;
+#endif
+
+extern "C" bool GetUserTemplateLocation(sal_Unicode* pFolder, int nSize)
+{
+#ifdef WNT
+ return _SHGetSpecialFolderW32( CSIDL_TEMPLATES, reinterpret_cast<LPWSTR>(pFolder), nSize );
+#else
+ (void)pFolder;
+ (void)nSize;
+ return false;
+#endif
+}
diff --git a/sfx2/source/explorer/nochaos.cxx b/sfx2/source/explorer/nochaos.cxx
new file mode 100644
index 000000000000..63c165bea7eb
--- /dev/null
+++ b/sfx2/source/explorer/nochaos.cxx
@@ -0,0 +1,215 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <svl/itempool.hxx>
+#include <svl/poolitem.hxx>
+#include <svl/stritem.hxx>
+#include <nochaos.hxx>
+#include <sfx2/sfxuno.hxx>
+
+
+#define WID_CHAOS_START 500
+//=========================================================================
+//
+// class CntStaticPoolDefaults_Impl
+//
+//=========================================================================
+
+class CntItemPool;
+
+class CntStaticPoolDefaults_Impl
+{
+ sal_uInt32 m_nItems;
+ SfxPoolItem** m_ppDefaults;
+ SfxItemInfo* m_pItemInfos;
+
+private:
+ // Forbidden and not implemented...
+ CntStaticPoolDefaults_Impl( const CntStaticPoolDefaults_Impl& );
+ CntStaticPoolDefaults_Impl& operator=( const CntStaticPoolDefaults_Impl& );
+
+ inline void Insert( SfxPoolItem* pItem, sal_uInt16 nSID, sal_uInt16 nFlags );
+
+public:
+ CntStaticPoolDefaults_Impl( CntItemPool* pPool );
+ ~CntStaticPoolDefaults_Impl();
+
+ SfxPoolItem** GetDefaults() const { return m_ppDefaults; }
+ const SfxItemInfo* GetItemInfos() const { return m_pItemInfos; }
+};
+
+//----------------------------------------------------------------------------
+
+//=========================================================================
+
+class CntItemPool: public SfxItemPool
+{
+ static CntItemPool* _pThePool;
+ USHORT _nRefs;
+
+protected:
+ CntItemPool();
+ virtual ~CntItemPool();
+
+public:
+ static CntItemPool* Acquire();
+ static USHORT Release();
+};
+
+//----------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------
+// static
+SfxItemPool* NoChaos::GetItemPool()
+{
+ // Get and hold CHAOS item pool.
+ return CntItemPool::Acquire();
+}
+
+//----------------------------------------------------------------------------
+// static
+USHORT NoChaos::ReleaseItemPool()
+{
+ // Release CHAOS item pool.
+ return CntItemPool::Release();
+}
+
+//=========================================================================
+//
+// CntItemPool implementation
+//
+//=========================================================================
+
+static CntStaticPoolDefaults_Impl* pPoolDefs_Impl = NULL;
+
+// static member!
+CntItemPool* CntItemPool::_pThePool = NULL;
+
+//-------------------------------------------------------------------------
+CntItemPool::CntItemPool()
+: SfxItemPool( DEFINE_CONST_UNICODE("chaos"), WID_CHAOS_START, WID_CHAOS_START, NULL ),
+ _nRefs( 0 )
+{
+ SetFileFormatVersion( SOFFICE_FILEFORMAT_50 );
+
+ FreezeIdRanges();
+
+ // Create static defaults.
+ pPoolDefs_Impl = new CntStaticPoolDefaults_Impl( this );
+
+ // Set item infos.
+ SetItemInfos( pPoolDefs_Impl->GetItemInfos() );
+
+ // Set static pool default items.
+ SetDefaults( pPoolDefs_Impl->GetDefaults() );
+}
+
+//-------------------------------------------------------------------------
+//virtual
+CntItemPool::~CntItemPool()
+{
+ // Release static pool default items.
+ ReleaseDefaults( sal_False );
+}
+
+//-------------------------------------------------------------------------
+// static
+CntItemPool* CntItemPool::Acquire()
+{
+ if ( !_pThePool )
+ _pThePool = new CntItemPool;
+
+ _pThePool->_nRefs++;
+
+ return _pThePool;
+}
+
+//-------------------------------------------------------------------------
+// static
+sal_uInt16 CntItemPool::Release()
+{
+ if ( !_pThePool )
+ return 0;
+
+ sal_uInt16& nRefs = _pThePool->_nRefs;
+
+ if ( nRefs )
+ --nRefs;
+
+ if ( !nRefs )
+ {
+ DELETEZ( _pThePool );
+ DELETEZ( pPoolDefs_Impl );
+ return 0;
+ }
+
+ return nRefs;
+}
+
+//=========================================================================
+//
+// CntStaticPoolDefaults_Impl implementation.
+//
+//=========================================================================
+
+inline void CntStaticPoolDefaults_Impl::Insert(
+ SfxPoolItem* pItem, /* Static Pool Default Item */
+ sal_uInt16 nSID, sal_uInt16 nFlags /* Item Info */ )
+{
+ sal_uInt16 nPos = pItem->Which() - WID_CHAOS_START;
+
+ m_ppDefaults[ nPos ] = pItem;
+ m_pItemInfos[ nPos ]._nSID = nSID;
+ m_pItemInfos[ nPos ]._nFlags = nFlags;
+}
+
+//-------------------------------------------------------------------------
+CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl()
+{
+ for ( sal_uInt32 n = 0; n < m_nItems; ++n )
+ delete m_ppDefaults[ n ];
+
+ delete [] m_ppDefaults;
+ delete [] m_pItemInfos;
+}
+
+//-------------------------------------------------------------------------
+CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl( CntItemPool* /*pPool*/ )
+: m_nItems( 1 ),
+ m_ppDefaults( new SfxPoolItem* [ m_nItems ] ),
+ m_pItemInfos( new SfxItemInfo [ m_nItems ] )
+{
+ rtl_zeroMemory( m_ppDefaults, sizeof( SfxPoolItem* ) * m_nItems );
+ rtl_zeroMemory( m_pItemInfos, sizeof( SfxItemInfo ) * m_nItems );
+ Insert(
+ new SfxStringItem( WID_CHAOS_START, String() ),
+ 0,
+ SFX_ITEM_POOLABLE );
+}
diff --git a/sfx2/source/inc/SfxDocumentMetaData.hxx b/sfx2/source/inc/SfxDocumentMetaData.hxx
new file mode 100644
index 000000000000..ec573cf007a7
--- /dev/null
+++ b/sfx2/source/inc/SfxDocumentMetaData.hxx
@@ -0,0 +1,49 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFXDOCUMENTMETADATA_HXX
+#define _SFXDOCUMENTMETADATA_HXX
+
+#include "sal/config.h"
+#include "cppuhelper/factory.hxx"
+
+
+// component helper namespace
+namespace comp_SfxDocumentMetaData {
+
+namespace css = ::com::sun::star;
+
+// component and service helper functions:
+::rtl::OUString SAL_CALL _getImplementationName();
+css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames();
+css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
+ css::uno::Reference< css::uno::XComponentContext > const & context );
+
+} // closing component helper namespace
+
+#endif
+
diff --git a/sfx2/source/inc/alienwarn.hxx b/sfx2/source/inc/alienwarn.hxx
new file mode 100644
index 000000000000..f7c38173fceb
--- /dev/null
+++ b/sfx2/source/inc/alienwarn.hxx
@@ -0,0 +1,56 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_ALIENWARN_HXX
+#define _SFX_ALIENWARN_HXX
+
+#ifndef _SV_BUTTON_HXX
+#include <vcl/button.hxx>
+#endif
+#include <vcl/fixed.hxx>
+
+#include <sfx2/basedlgs.hxx>
+
+class SfxAlienWarningDialog : public SfxModalDialog
+{
+private:
+ OKButton m_aKeepCurrentBtn;
+ CancelButton m_aSaveODFBtn;
+ HelpButton m_aMoreInfoBtn;
+ FixedLine m_aOptionLine;
+ CheckBox m_aWarningOnBox;
+ FixedImage m_aQueryImage;
+ FixedText m_aInfoText;
+
+ void InitSize();
+
+public:
+ SfxAlienWarningDialog( Window* pParent, const String& _rFormatName );
+ virtual ~SfxAlienWarningDialog();
+};
+
+#endif // #ifndef _SFX_ALIENWARN_HXX
+
diff --git a/sfx2/source/inc/appbas.hxx b/sfx2/source/inc/appbas.hxx
new file mode 100644
index 000000000000..8b10fcb843de
--- /dev/null
+++ b/sfx2/source/inc/appbas.hxx
@@ -0,0 +1,44 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_APPBAS_HXX
+#define _SFX_APPBAS_HXX
+
+
+#include <basic/sbxdef.hxx>
+
+class StarBASIC;
+class SbxObject;
+
+//=========================================================================
+
+SbxVariable* MakeVariable( StarBASIC *pBas, SbxObject *pObject,
+ const char *pName, ULONG nSID, SbxDataType eType=SbxOBJECT,
+ SbxClassType = SbxCLASS_PROPERTY );
+
+
+#endif
+
diff --git a/sfx2/source/inc/appbaslib.hxx b/sfx2/source/inc/appbaslib.hxx
new file mode 100644
index 000000000000..5bc7662e8f9b
--- /dev/null
+++ b/sfx2/source/inc/appbaslib.hxx
@@ -0,0 +1,140 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef APPBASLIB_HXX
+#define APPBASLIB_HXX
+
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/script/XStorageBasedLibraryContainer.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+
+class BasicManager;
+
+/** helper class which holds and manipulates a BasicManager
+*/
+class SfxBasicManagerHolder
+{
+private:
+ BasicManager* mpBasicManager;
+ ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer >
+ mxBasicContainer;
+ ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer >
+ mxDialogContainer;
+
+public:
+ SfxBasicManagerHolder();
+
+ enum ContainerType
+ {
+ SCRIPTS, DIALOGS
+ };
+
+ /** returns <TRUE/> if and only if the instance is currently bound to a non-<NULL/>
+ BasicManager.
+ */
+ bool isValid() const { return mpBasicManager != NULL; }
+
+ /** returns the BasicManager which this instance is currently bound to
+ */
+ BasicManager*
+ get() const { return mpBasicManager; }
+
+ /** binds the instance to the given BasicManager
+ */
+ void reset( BasicManager* _pBasicManager );
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >
+ getLibraryContainer( ContainerType _eType );
+
+ /** determines whether any of our library containers is modified, i.e. returns <TRUE/>
+ in its isContainerModified call.
+ */
+ bool isAnyContainerModified() const;
+
+ /** calls the storeLibraries at both our script and basic library container
+ */
+ void storeAllLibraries();
+
+ /** calls the setStorage at all our XStorageBasedLibraryContainer.
+ */
+ void setStorage(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage
+ );
+
+ /** calls the storeLibrariesToStorage at all our XStorageBasedLibraryContainer.
+ */
+ void storeLibrariesToStorage(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage
+ );
+
+
+ /** checks if any modules in the SfxLibraryContainer exceed the binary
+ limits.
+ */
+ sal_Bool LegacyPsswdBinaryLimitExceeded( ::com::sun::star::uno::Sequence< rtl::OUString >& sModules );
+
+
+private:
+ void impl_releaseContainers();
+
+ bool impl_getContainer(
+ ContainerType _eType,
+ ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer >& _out_rxContainer );
+};
+
+class SfxApplicationScriptLibraryContainer
+{
+public:
+ // Service
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getStaticSupportedServiceNames();
+ static ::rtl::OUString impl_getStaticImplementationName();
+ static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL impl_createInstance
+ ( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager )
+ throw( ::com::sun::star::uno::Exception );
+ static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > impl_createFactory
+ ( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
+
+};
+
+class SfxApplicationDialogLibraryContainer
+{
+public:
+ // Service
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getStaticSupportedServiceNames();
+ static ::rtl::OUString impl_getStaticImplementationName();
+ static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL impl_createInstance
+ ( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager )
+ throw( ::com::sun::star::uno::Exception );
+ static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > impl_createFactory
+ ( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
+
+};
+
+#endif // APPBASLIB_HXX
+
diff --git a/sfx2/source/inc/appdata.hxx b/sfx2/source/inc/appdata.hxx
new file mode 100644
index 000000000000..bd12f3db80dc
--- /dev/null
+++ b/sfx2/source/inc/appdata.hxx
@@ -0,0 +1,182 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_APPDATA_HXX
+#define _SFX_APPDATA_HXX
+
+#include <tools/link.hxx>
+#include <tools/list.hxx>
+#include <svl/lstner.hxx>
+#include <vcl/timer.hxx>
+#include <tools/string.hxx>
+#include "rtl/ref.hxx"
+
+#include <com/sun/star/frame/XModel.hpp>
+
+#include "bitset.hxx"
+
+class SfxApplication;
+class SvStrings;
+class SfxProgress;
+class SfxChildWinFactArr_Impl;
+class SfxDdeDocTopics_Impl;
+class DdeService;
+class SfxEventConfiguration;
+class SfxMacroConfig;
+class SfxItemPool;
+class SfxInitLinkList;
+class SfxFilterMatcher;
+class SvUShorts;
+class ISfxTemplateCommon;
+class SfxFilterMatcher;
+class SfxStatusDispatcher;
+class SfxDdeTriggerTopic_Impl;
+class SfxDocumentTemplates;
+class SfxFrameArr_Impl;
+class SvtSaveOptions;
+class SvtUndoOptions;
+class SvtHelpOptions;
+class SfxObjectFactory;
+class SfxObjectShell;
+class ResMgr;
+class Window;
+class SfxTbxCtrlFactArr_Impl;
+class SfxStbCtrlFactArr_Impl;
+class SfxMenuCtrlFactArr_Impl;
+class SfxViewFrameArr_Impl;
+class SfxViewShellArr_Impl;
+class SfxObjectShellArr_Impl;
+class ResMgr;
+class SimpleResMgr;
+class SfxViewFrame;
+class SfxSlotPool;
+class SfxResourceManager;
+class SfxDispatcher;
+class SfxInterface;
+class BasicManager;
+class SfxBasicManagerHolder;
+class SfxBasicManagerCreationListener;
+
+namespace sfx2 { namespace appl { class ImeStatusWindow; } }
+
+typedef Link* LinkPtr;
+SV_DECL_PTRARR(SfxInitLinkList, LinkPtr, 4, 4)
+
+//=========================================================================
+// SfxAppData_Impl
+//=========================================================================
+
+class SfxAppData_Impl
+{
+public:
+ IndexBitSet aIndexBitSet; // for counting noname documents
+ String aLastDir; // for IO dialog
+
+ // DDE stuff
+ DdeService* pDdeService;
+ SfxDdeDocTopics_Impl* pDocTopics;
+ SfxDdeTriggerTopic_Impl* pTriggerTopic;
+ DdeService* pDdeService2;
+
+ // single instance classes
+ SfxChildWinFactArr_Impl* pFactArr;
+ SfxFrameArr_Impl* pTopFrames;
+
+ // special members
+ SfxInitLinkList* pInitLinkList;
+
+ // application members
+ SfxFilterMatcher* pMatcher;
+ ResMgr* pLabelResMgr;
+ SfxStatusDispatcher* pAppDispatch;
+ SfxDocumentTemplates* pTemplates;
+
+ // global pointers
+ SfxItemPool* pPool;
+ SfxEventConfiguration* pEventConfig;
+ SvUShorts* pDisabledSlotList;
+ SvStrings* pSecureURLs;
+ SvtSaveOptions* pSaveOptions;
+ SvtUndoOptions* pUndoOptions;
+ SvtHelpOptions* pHelpOptions;
+
+ // "current" functionality
+ SfxProgress* pProgress;
+ ISfxTemplateCommon* pTemplateCommon;
+
+ USHORT nDocModalMode; // counts documents in modal mode
+ USHORT nAutoTabPageId;
+ USHORT nBasicCallLevel;
+ USHORT nRescheduleLocks;
+ USHORT nInReschedule;
+ USHORT nAsynchronCalls;
+
+ rtl::Reference< sfx2::appl::ImeStatusWindow > m_xImeStatusWindow;
+
+ SfxTbxCtrlFactArr_Impl* pTbxCtrlFac;
+ SfxStbCtrlFactArr_Impl* pStbCtrlFac;
+ SfxMenuCtrlFactArr_Impl* pMenuCtrlFac;
+ SfxViewFrameArr_Impl* pViewFrames;
+ SfxViewShellArr_Impl* pViewShells;
+ SfxObjectShellArr_Impl* pObjShells;
+ ResMgr* pSfxResManager;
+ ResMgr* pOfaResMgr;
+ SimpleResMgr* pSimpleResManager;
+ SfxBasicManagerHolder* pBasicManager;
+ SfxBasicManagerCreationListener*
+ pBasMgrListener;
+ SfxViewFrame* pViewFrame;
+ SfxSlotPool* pSlotPool;
+ SfxResourceManager* pResMgr;
+ SfxDispatcher* pAppDispat; // Dispatcher falls kein Doc
+ SfxInterface** pInterfaces;
+
+ USHORT nDocNo; // Laufende Doc-Nummer (AutoName)
+ USHORT nInterfaces;
+
+ BOOL bDispatcherLocked:1; // nichts ausf"uhren
+ BOOL bDowning:1; // TRUE ab Exit und danach
+ BOOL bInQuit : 1;
+ BOOL bInvalidateOnUnlock : 1;
+ BOOL bODFVersionWarningLater : 1;
+
+ SfxAppData_Impl( SfxApplication* );
+ ~SfxAppData_Impl();
+
+ void UpdateApplicationSettings( BOOL bDontHide );
+ SfxDocumentTemplates* GetDocumentTemplates();
+ void DeInitDDE();
+
+ /** called when the Application's BasicManager has been created. This can happen
+ explicitly in SfxApplication::GetBasicManager, or implicitly if a document's
+ BasicManager is created before the application's BasicManager exists.
+ */
+ void OnApplicationBasicManagerCreated( BasicManager& _rManager );
+};
+
+#endif // #ifndef _SFX_APPDATA_HXX
+
+
diff --git a/sfx2/source/inc/doctemplates.hxx b/sfx2/source/inc/doctemplates.hxx
new file mode 100644
index 000000000000..5e962b93a117
--- /dev/null
+++ b/sfx2/source/inc/doctemplates.hxx
@@ -0,0 +1,102 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_DOCTEMPLATES_HXX_
+#define _SFX_DOCTEMPLATES_HXX_
+
+#include <cppuhelper/weak.hxx>
+#include <cppuhelper/implbase3.hxx>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/frame/XDocumentTemplates.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/lang/Locale.hpp>
+#include <com/sun/star/lang/XLocalizable.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/ucb/XContent.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/uno/RuntimeException.hpp>
+#include <com/sun/star/uno/XInterface.hpp>
+#include <ucbhelper/content.hxx>
+#include <sfx2/sfxuno.hxx>
+
+//--------------------------------------------------------------------------------------------------------
+
+#define UNOLOCALE ::com::sun::star::lang::Locale
+#define REFERENCE ::com::sun::star::uno::Reference
+#define RUNTIMEEXCEPTION ::com::sun::star::uno::RuntimeException
+#define PROPERTYVALUE ::com::sun::star::beans::PropertyValue
+#define XCONTENT ::com::sun::star::ucb::XContent
+#define XDOCUMENTTEMPLATES ::com::sun::star::frame::XDocumentTemplates
+#define XINTERFACE ::com::sun::star::uno::XInterface
+#define XLOCALIZABLE ::com::sun::star::lang::XLocalizable
+#define XMODEL ::com::sun::star::frame::XModel
+#define XMULTISERVICEFACTORY ::com::sun::star::lang::XMultiServiceFactory
+#define XNAMEACCESS ::com::sun::star::container::XNameAccess
+#define XSERVICEINFO ::com::sun::star::lang::XServiceInfo
+#define XSTORABLE ::com::sun::star::frame::XStorable
+
+//--------------------------------------------------------------------------------------------------------
+
+class SfxDocTplService_Impl;
+
+class SfxDocTplService: public ::cppu::WeakImplHelper3< XLOCALIZABLE, XDOCUMENTTEMPLATES, XSERVICEINFO >
+{
+ SfxDocTplService_Impl *pImp;
+
+public:
+ SFX_DECL_XSERVICEINFO
+
+ SfxDocTplService( const REFERENCE < ::com::sun::star::lang::XMultiServiceFactory >& xFactory );
+ ~SfxDocTplService();
+
+ // --- XLocalizable ---
+ void SAL_CALL setLocale( const UNOLOCALE & eLocale ) throw( RUNTIMEEXCEPTION );
+ UNOLOCALE SAL_CALL getLocale() throw( RUNTIMEEXCEPTION );
+
+ // --- XDocumentTemplates ---
+ REFERENCE< XCONTENT > SAL_CALL getContent() throw( RUNTIMEEXCEPTION );
+ sal_Bool SAL_CALL storeTemplate( const ::rtl::OUString& GroupName,
+ const ::rtl::OUString& TemplateName,
+ const REFERENCE< XSTORABLE >& Storable ) throw( RUNTIMEEXCEPTION );
+ sal_Bool SAL_CALL addTemplate( const ::rtl::OUString& GroupName,
+ const ::rtl::OUString& TemplateName,
+ const ::rtl::OUString& SourceURL ) throw( RUNTIMEEXCEPTION );
+ sal_Bool SAL_CALL removeTemplate( const ::rtl::OUString& GroupName,
+ const ::rtl::OUString& TemplateName ) throw( RUNTIMEEXCEPTION );
+ sal_Bool SAL_CALL renameTemplate( const ::rtl::OUString& GroupName,
+ const ::rtl::OUString& OldTemplateName,
+ const ::rtl::OUString& NewTemplateName ) throw( RUNTIMEEXCEPTION );
+ sal_Bool SAL_CALL addGroup( const ::rtl::OUString& GroupName ) throw( RUNTIMEEXCEPTION );
+ sal_Bool SAL_CALL removeGroup( const ::rtl::OUString& GroupName ) throw( RUNTIMEEXCEPTION );
+ sal_Bool SAL_CALL renameGroup( const ::rtl::OUString& OldGroupName,
+ const ::rtl::OUString& NewGroupName ) throw( RUNTIMEEXCEPTION );
+ void SAL_CALL update() throw( RUNTIMEEXCEPTION );
+};
+
+#endif
diff --git a/sfx2/source/inc/eventsupplier.hxx b/sfx2/source/inc/eventsupplier.hxx
new file mode 100644
index 000000000000..e012eea39c2d
--- /dev/null
+++ b/sfx2/source/inc/eventsupplier.hxx
@@ -0,0 +1,264 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_EVENTSUPPLIER_HXX_
+#define _SFX_EVENTSUPPLIER_HXX_
+
+#include <com/sun/star/lang/XTypeProvider.hpp>
+#include <com/sun/star/container/XNameReplace.hpp>
+#include <com/sun/star/container/XSet.hpp>
+#include <com/sun/star/document/XEventListener.hpp>
+#include <com/sun/star/document/XEventBroadcaster.hpp>
+#include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
+#include <com/sun/star/document/XDocumentEventListener.hpp>
+#include <com/sun/star/document/XEventsSupplier.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/task/XJobExecutor.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/Type.hxx>
+#include <sal/types.h>
+#include <osl/mutex.hxx>
+#include <cppuhelper/weak.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/implbase3.hxx>
+#include <cppuhelper/implbase4.hxx>
+#include <cppuhelper/implbase7.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/sequenceasvector.hxx>
+#include <sfx2/sfxuno.hxx>
+
+#include <vos/mutex.hxx>
+#include <cppuhelper/interfacecontainer.hxx>
+#include <svl/lstner.hxx>
+#include <unotools/eventcfg.hxx>
+
+//--------------------------------------------------------------------------------------------------------
+
+#define NOSUCHELEMENTEXCEPTION ::com::sun::star::container::NoSuchElementException
+#define XNAMEREPLACE ::com::sun::star::container::XNameReplace
+#define DOCEVENTOBJECT ::com::sun::star::document::EventObject
+#define XEVENTBROADCASTER ::com::sun::star::document::XEventBroadcaster
+#define XDOCEVENTLISTENER ::com::sun::star::document::XEventListener
+#define XEVENTSSUPPLIER ::com::sun::star::document::XEventsSupplier
+#define XJOBEXECUTOR ::com::sun::star::task::XJobExecutor
+#define EVENTOBJECT ::com::sun::star::lang::EventObject
+#define ILLEGALARGUMENTEXCEPTION ::com::sun::star::lang::IllegalArgumentException
+#define WRAPPEDTARGETEXCEPTION ::com::sun::star::lang::WrappedTargetException
+#define ANY ::com::sun::star::uno::Any
+#define REFERENCE ::com::sun::star::uno::Reference
+#define WEAKREFERENCE ::com::sun::star::uno::WeakReference
+#define RUNTIMEEXCEPTION ::com::sun::star::uno::RuntimeException
+#define SEQUENCE ::com::sun::star::uno::Sequence
+#define UNOTYPE ::com::sun::star::uno::Type
+#define OUSTRING ::rtl::OUString
+#define OINTERFACECONTAINERHELPER ::cppu::OInterfaceContainerHelper
+
+//--------------------------------------------------------------------------------------------------------
+
+class SfxObjectShell;
+class SfxBaseModel;
+class SvxMacro;
+
+//--------------------------------------------------------------------------------------------------------
+
+class SfxEvents_Impl : public ::cppu::WeakImplHelper2< ::com::sun::star::container::XNameReplace, ::com::sun::star::document::XEventListener >
+{
+ SEQUENCE< OUSTRING > maEventNames;
+ SEQUENCE< ANY > maEventData;
+ REFERENCE< XEVENTBROADCASTER > mxBroadcaster;
+ ::osl::Mutex maMutex;
+ SfxObjectShell *mpObjShell;
+
+ sal_Bool Warn_Impl( const String& );
+
+public:
+ SfxEvents_Impl( SfxObjectShell* pShell,
+ REFERENCE< XEVENTBROADCASTER > xBroadcaster );
+ ~SfxEvents_Impl();
+
+ // --- XNameReplace ---
+ virtual void SAL_CALL replaceByName( const OUSTRING & aName, const ANY & aElement )
+ throw( ILLEGALARGUMENTEXCEPTION, NOSUCHELEMENTEXCEPTION,
+ WRAPPEDTARGETEXCEPTION, RUNTIMEEXCEPTION );
+
+ // --- XNameAccess ( parent of XNameReplace ) ---
+ virtual ANY SAL_CALL getByName( const OUSTRING& aName )
+ throw( NOSUCHELEMENTEXCEPTION, WRAPPEDTARGETEXCEPTION,
+ RUNTIMEEXCEPTION );
+ virtual SEQUENCE< OUSTRING > SAL_CALL getElementNames() throw ( RUNTIMEEXCEPTION );
+ virtual sal_Bool SAL_CALL hasByName( const OUSTRING& aName ) throw ( RUNTIMEEXCEPTION );
+
+ // --- XElementAccess ( parent of XNameAccess ) ---
+ virtual UNOTYPE SAL_CALL getElementType() throw ( RUNTIMEEXCEPTION );
+ virtual sal_Bool SAL_CALL hasElements() throw ( RUNTIMEEXCEPTION );
+
+ // --- ::document::XEventListener ---
+ virtual void SAL_CALL notifyEvent( const DOCEVENTOBJECT& aEvent )
+ throw( RUNTIMEEXCEPTION );
+
+ // --- ::lang::XEventListener ---
+ virtual void SAL_CALL disposing( const EVENTOBJECT& Source )
+ throw( RUNTIMEEXCEPTION );
+
+ static SvxMacro* ConvertToMacro( const ANY& rElement, SfxObjectShell* pDoc, BOOL bBlowUp );
+ static void BlowUpMacro( const ANY& rIn, ANY& rOut, SfxObjectShell* pDoc );
+};
+
+//=============================================================================
+struct ModelCollectionMutexBase
+{
+ public:
+ ::osl::Mutex m_aLock;
+};
+
+//=============================================================================
+typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > > TModelList;
+
+//=============================================================================
+class ModelCollectionEnumeration : public ModelCollectionMutexBase
+ , public ::cppu::WeakImplHelper1< ::com::sun::star::container::XEnumeration >
+{
+
+ //-------------------------------------------------------------------------
+ // member
+ //-------------------------------------------------------------------------
+ private:
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xSMGR;
+ TModelList m_lModels;
+ TModelList::iterator m_pEnumerationIt;
+
+ //-------------------------------------------------------------------------
+ // native interface
+ //-------------------------------------------------------------------------
+ public:
+ ModelCollectionEnumeration(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMGR);
+ virtual ~ModelCollectionEnumeration();
+ void setModelList(const TModelList& rList);
+
+ //-------------------------------------------------------------------------
+ // uno interface
+ //-------------------------------------------------------------------------
+ public:
+
+ // css.container.XEnumeration
+ virtual sal_Bool SAL_CALL hasMoreElements()
+ throw(::com::sun::star::uno::RuntimeException);
+
+ virtual ::com::sun::star::uno::Any SAL_CALL nextElement()
+ throw(::com::sun::star::container::NoSuchElementException,
+ ::com::sun::star::lang::WrappedTargetException ,
+ ::com::sun::star::uno::RuntimeException );
+};
+
+//=============================================================================
+class SfxGlobalEvents_Impl : public ModelCollectionMutexBase
+ , public ::cppu::WeakImplHelper7< ::com::sun::star::lang::XServiceInfo
+ , ::com::sun::star::document::XEventsSupplier
+ , ::com::sun::star::document::XEventBroadcaster
+ , ::com::sun::star::document::XDocumentEventBroadcaster
+ , ::com::sun::star::document::XEventListener
+ , ::com::sun::star::document::XDocumentEventListener
+ , ::com::sun::star::container::XSet >
+{
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xSMGR;
+ ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > m_xEvents;
+ ::com::sun::star::uno::WeakReference< ::com::sun::star::document::XEventListener > m_xJobExecutorListener;
+ OINTERFACECONTAINERHELPER m_aLegacyListeners;
+ OINTERFACECONTAINERHELPER m_aDocumentListeners;
+ TModelList m_lModels;
+ GlobalEventConfig* pImp;
+
+public:
+ SfxGlobalEvents_Impl(const com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& xSMGR);
+ virtual ~SfxGlobalEvents_Impl();
+
+ SFX_DECL_XSERVICEINFO
+
+ // css.document.XEventBroadcaster
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents()
+ throw(::com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& xListener)
+ throw(::com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& xListener)
+ throw(::com::sun::star::uno::RuntimeException);
+
+ // css.document.XDocumentEventBroadcaster
+ virtual void SAL_CALL addDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL notifyDocumentEvent( const ::rtl::OUString& _EventName, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 >& _ViewController, const ::com::sun::star::uno::Any& _Supplement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
+
+ // css.document.XEventListener
+ virtual void SAL_CALL notifyEvent(const ::com::sun::star::document::EventObject& aEvent)
+ throw(::com::sun::star::uno::RuntimeException);
+
+ // css.document.XDocumentEventListener
+ virtual void SAL_CALL documentEventOccured( const ::com::sun::star::document::DocumentEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
+
+ // css.container.XSet
+ virtual sal_Bool SAL_CALL has(const ::com::sun::star::uno::Any& aElement)
+ throw(::com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL insert(const ::com::sun::star::uno::Any& aElement)
+ throw(::com::sun::star::lang::IllegalArgumentException ,
+ ::com::sun::star::container::ElementExistException,
+ ::com::sun::star::uno::RuntimeException );
+
+ virtual void SAL_CALL remove(const ::com::sun::star::uno::Any& aElement)
+ throw(::com::sun::star::lang::IllegalArgumentException ,
+ ::com::sun::star::container::NoSuchElementException,
+ ::com::sun::star::uno::RuntimeException );
+
+ // css.container.XEnumerationAccess
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration()
+ throw(::com::sun::star::uno::RuntimeException);
+
+ // css.container.XElementAccess
+ virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
+ throw(::com::sun::star::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL hasElements()
+ throw(::com::sun::star::uno::RuntimeException);
+
+ // css.lang.XEventListener
+ virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& aEvent)
+ throw(::com::sun::star::uno::RuntimeException);
+
+private:
+
+ // threadsafe
+ void implts_notifyJobExecution(const ::com::sun::star::document::EventObject& aEvent);
+ void implts_checkAndExecuteEventBindings(const ::com::sun::star::document::DocumentEvent& aEvent);
+ void implts_notifyListener(const ::com::sun::star::document::DocumentEvent& aEvent);
+
+ // not threadsafe
+ TModelList::iterator impl_searchDoc(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel);
+};
+
+#endif
diff --git a/sfx2/source/inc/fltfnc.hxx b/sfx2/source/inc/fltfnc.hxx
new file mode 100644
index 000000000000..0a078a33c5be
--- /dev/null
+++ b/sfx2/source/inc/fltfnc.hxx
@@ -0,0 +1,35 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFXFLTFNC_HXX
+#define _SFXFLTFNC_HXX
+
+#include <sfx2/fcontnr.hxx>
+
+BOOL SfxIsHelpEntryURL( const String &rURL, const String &rExtMask );
+
+#endif
+
diff --git a/sfx2/source/inc/fltoptint.hxx b/sfx2/source/inc/fltoptint.hxx
new file mode 100644
index 000000000000..d674c7620d54
--- /dev/null
+++ b/sfx2/source/inc/fltoptint.hxx
@@ -0,0 +1,78 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef SFX2_FLTOPTINT_HXX
+#define SFX2_FLTOPTINT_HXX
+
+#include <com/sun/star/document/FilterOptionsRequest.hpp>
+#include <com/sun/star/document/XInteractionFilterOptions.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <comphelper/interaction.hxx>
+
+//using namespace ::framework;
+
+class FilterOptionsContinuation : public comphelper::OInteraction< ::com::sun::star::document::XInteractionFilterOptions >
+{
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > rProperties;
+
+public:
+ virtual void SAL_CALL setFilterOptions( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rProp ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getFilterOptions( ) throw (::com::sun::star::uno::RuntimeException);
+};
+
+class RequestFilterOptions : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest >
+{
+ ::com::sun::star::uno::Any m_aRequest;
+
+ ::com::sun::star::uno::Sequence<
+ ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >
+ > m_lContinuations;
+
+ comphelper::OInteractionAbort* m_pAbort;
+
+ FilterOptionsContinuation* m_pOptions;
+
+public:
+ RequestFilterOptions( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > rModel,
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > rProperties );
+
+ sal_Bool isAbort() { return m_pAbort->wasSelected(); }
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > getFilterOptions()
+ {
+ return m_pOptions->getFilterOptions();
+ }
+
+ virtual ::com::sun::star::uno::Any SAL_CALL getRequest()
+ throw( ::com::sun::star::uno::RuntimeException );
+
+ virtual ::com::sun::star::uno::Sequence<
+ ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >
+ > SAL_CALL getContinuations()
+ throw( ::com::sun::star::uno::RuntimeException );
+};
+
+#endif
diff --git a/sfx2/source/inc/helper.hxx b/sfx2/source/inc/helper.hxx
new file mode 100644
index 000000000000..45aed74b154a
--- /dev/null
+++ b/sfx2/source/inc/helper.hxx
@@ -0,0 +1,78 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_HELPER_HXX
+#define _SFX_HELPER_HXX
+
+// include ---------------------------------------------------------------
+
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/ucb/NameClash.hpp>
+
+#include <tools/string.hxx>
+#include <tools/errcode.hxx>
+#include <tools/bigint.hxx>
+
+// class SfxContentHelper ------------------------------------------------
+
+class SfxContentHelper
+{
+private:
+ static sal_Bool Transfer_Impl( const String& rSource, const String& rDest, sal_Bool bMoveData,
+ sal_Int32 nNameClash );
+
+public:
+ static sal_Bool IsDocument( const String& rContent );
+ static sal_Bool IsFolder( const String& rContent );
+ static sal_Bool GetTitle( const String& rContent, String& rTitle );
+ static sal_Bool Kill( const String& rContent );
+
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString >
+ GetFolderContents( const String& rFolder, sal_Bool bFolder, sal_Bool bSorted = sal_False );
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString >
+ GetFolderContentProperties( const String& rFolder, sal_Bool bFolder );
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString >
+ GetResultSet( const String& rURL );
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString >
+ GetHelpTreeViewContents( const String& rURL );
+ static String GetActiveHelpString( const String& rURL );
+ static sal_Bool IsHelpErrorDocument( const String& rURL );
+
+ static sal_Bool CopyTo( const String& rSource, const String& rDest );
+ static sal_Bool MoveTo( const String& rSource, const String& rDest, sal_Int32 nNameClash = com::sun::star::ucb::NameClash::ERROR );
+
+ static sal_Bool MakeFolder( const String& rFolder );
+ static ErrCode QueryDiskSpace( const String& rPath, sal_Int64& rFreeBytes );
+ static ULONG GetSize( const String& rContent );
+
+ // please don't use this!
+ static sal_Bool Exists( const String& rContent );
+ static sal_Bool Find( const String& rFolder, const String& rName, String& rFile );
+};
+
+#endif // #ifndef _SFX_HELPER_HXX
+
+
diff --git a/sfx2/source/inc/helpid.hrc b/sfx2/source/inc/helpid.hrc
new file mode 100644
index 000000000000..ef5c168c36f0
--- /dev/null
+++ b/sfx2/source/inc/helpid.hrc
@@ -0,0 +1,342 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_HELPID_HRC
+#define _SFX_HELPID_HRC
+
+// include ------------------------------------------------------------------
+
+#include <sfx2/sfxcommands.h>
+
+// Help-Ids -----------------------------------------------------------------
+
+#define HID_FILTER_SELECT "SFX2_HID_FILTER_SELECT"
+#define HID_USERDEFBMP "SFX2_HID_USERDEFBMP"
+#define HID_DOCINFO_EDT "SFX2_HID_DOCINFO_EDT"
+#define HID_PASSWD "SFX2_HID_PASSWD"
+#define HID_PRINTMONITOR "SFX2_HID_PRINTMONITOR"
+#define HID_CONFIG_OBJECTBAR "SFX2_HID_CONFIG_OBJECTBAR"
+#define HID_MANAGE_STYLES "SFX2_HID_MANAGE_STYLES"
+#define HID_CONFIG_EVENT "SFX2_HID_CONFIG_EVENT"
+#define HID_DOCINFODESC "SFX2_HID_DOCINFODESC"
+#define HID_DOCINFODOC "SFX2_HID_DOCINFODOC"
+#define HID_DOCINFOUSER "SFX2_HID_DOCINFOUSER"
+#define HID_BOOKMARKPROPS "SFX2_HID_BOOKMARKPROPS"
+#define HID_BOOKGROUPPROPS "SFX2_HID_BOOKGROUPPROPS"
+#define HID_BOOKFILEPROPS "SFX2_HID_BOOKFILEPROPS"
+#define HID_NEWS_SERVERPROPS "SFX2_HID_NEWS_SERVERPROPS"
+#define HID_NEWS_RULEPAGE "SFX2_HID_NEWS_RULEPAGE"
+#define HID_MAILINTRAYPROPS "SFX2_HID_MAILINTRAYPROPS"
+#define HID_DOCINFORELOAD "SFX2_HID_DOCINFORELOAD"
+#define HID_NEWS_GROUPPAGE "SFX2_HID_NEWS_GROUPPAGE"
+#define HID_NEWS_SERVERPAGE "SFX2_HID_NEWS_SERVERPAGE"
+#define HID_EXPLORERCONTROL "SFX2_HID_EXPLORERCONTROL"
+#define HID_BROWSERCONTROL "SFX2_HID_BROWSERCONTROL"
+#define HID_CTL_ORGANIZER_LEFT "SFX2_HID_CTL_ORGANIZER_LEFT"
+#define HID_CTL_ORGANIZER_RIGHT "SFX2_HID_CTL_ORGANIZER_RIGHT"
+#define HID_EXPLMAILSRV_GENERAL_PAGE "SFX2_HID_EXPLMAILSRV_GENERAL_PAGE"
+#define HID_EXPLMAILSRV_PROTOCOL_PAGE "SFX2_HID_EXPLMAILSRV_PROTOCOL_PAGE"
+#define HID_EXPLMAILSRV_DATAMATCH_PAGE "SFX2_HID_EXPLMAILSRV_DATAMATCH_PAGE"
+#define HID_EXPLMAILSRV_SENDJOURNAL_PAGE "SFX2_HID_EXPLMAILSRV_SENDJOURNAL_PAGE"
+#define HID_EXPLMAIL_GENERAL_PAGE "SFX2_HID_EXPLMAIL_GENERAL_PAGE"
+#define HID_NEWS_CTL_RULES "SFX2_HID_NEWS_CTL_RULES"
+#define HID_NEWS_CTL_GROUPS "SFX2_HID_NEWS_CTL_GROUPS"
+#define HID_CONFIG_OBJECTBAR_CTL "SFX2_HID_CONFIG_OBJECTBAR_CTL"
+#define HID_NEWS_QUICKSEARCH "SFX2_HID_NEWS_QUICKSEARCH"
+#define HID_NEWS_SERVERVIEWPROPS "SFX2_HID_NEWS_SERVERVIEWPROPS"
+#define HID_NEWS_SHOWARTICLEPROPS "SFX2_HID_NEWS_SHOWARTICLEPROPS"
+#define HID_NEWS_SHOWGROUPPROPS "SFX2_HID_NEWS_SHOWGROUPPROPS"
+#define HID_NEWS_USER "SFX2_HID_NEWS_USER"
+#define HID_MULTISELECTION_GENERAL_PAGE "SFX2_HID_MULTISELECTION_GENERAL_PAGE"
+#define HID_LINK_GENERAL_PAGE "SFX2_HID_LINK_GENERAL_PAGE"
+#define HID_LINK_ADDRESS_PAGE "SFX2_HID_LINK_ADDRESS_PAGE"
+#define HID_FOLDER_GENERAL_PAGE "SFX2_HID_FOLDER_GENERAL_PAGE"
+#define HID_FILE_GENERAL_PAGE "SFX2_HID_FILE_GENERAL_PAGE"
+#define HID_FTP_GENERAL_PAGE "SFX2_HID_FTP_GENERAL_PAGE"
+#define HID_PRINT_OPTIONS "SFX2_HID_PRINT_OPTIONS"
+#define HID_PREVIEW_FRAME "SFX2_HID_PREVIEW_FRAME"
+#define HID_DOCINFO_FRAME "SFX2_HID_DOCINFO_FRAME"
+#define HID_EXPLORER_FRAME "SFX2_HID_EXPLORER_FRAME"
+#define HID_APP_WIN "SFX2_HID_APP_WIN"
+#define HID_TEMPLATE_FMT "SFX2_HID_TEMPLATE_FMT"
+#define HID_TEMPLATE_FILTER "SFX2_HID_TEMPLATE_FILTER"
+#define HID_FTPSERVER_PAGE "SFX2_HID_FTPSERVER_PAGE"
+#define HID_DLG_SFX_EXP_SEARCH "SFX2_HID_DLG_SFX_EXP_SEARCH"
+#define HID_TP_SFX_EXP_SEARCH_CRITERIA "SFX2_HID_TP_SFX_EXP_SEARCH_CRITERIA"
+#define HID_TP_SFX_EXP_SEARCH_PLACE "SFX2_HID_TP_SFX_EXP_SEARCH_PLACE"
+#define HID_SEARCH_DLG_TABLB "SFX2_HID_SEARCH_DLG_TABLB"
+#define HID_TEMPLDLG_NEWBYEXAMPLE "SFX2_HID_TEMPLDLG_NEWBYEXAMPLE"
+#define HID_TEMPLDLG_UPDATEBYEXAMPLE "SFX2_HID_TEMPLDLG_UPDATEBYEXAMPLE"
+#define HID_TEMPLDLG_WATERCAN "SFX2_HID_TEMPLDLG_WATERCAN"
+#define HID_DESKTOP "SFX2_HID_DESKTOP"
+#define HID_EXPLORERTOOLSTOOLBOX "SFX2_HID_EXPLORERTOOLSTOOLBOX"
+#define HID_EXPLOREROBJECTTOOLBOX "SFX2_HID_EXPLOREROBJECTTOOLBOX"
+#define HID_RECORDINGTOOLBOX "SFX2_HID_RECORDINGTOOLBOX"
+#define HID_FULLSCREENTOOLBOX "SFX2_HID_FULLSCREENTOOLBOX"
+#define HID_HELPBAR "SFX2_HID_HELPBAR"
+#define HID_ENVTOOLBOX "SFX2_HID_ENVTOOLBOX"
+#define HID_FRAMESETEDIT_TOOLBOX "SFX2_HID_FRAMESETEDIT_TOOLBOX"
+#define HID_NAVIGATOR_WINDOW "SFX2_HID_NAVIGATOR_WINDOW"
+#define HID_TABDLG_RESET_BTN "SFX2_HID_TABDLG_RESET_BTN"
+#define HID_TABDLG_STANDARD_BTN "SFX2_HID_TABDLG_STANDARD_BTN"
+#define HID_HELPAGENT_TIP_BOX "SFX2_HID_HELPAGENT_TIP_BOX"
+#define HID_TEMPLDLG_TOOLBOX_LEFT "SFX2_HID_TEMPLDLG_TOOLBOX_LEFT"
+#define HID_TEMPLDLG_TOOLBOX_RIGHT "SFX2_HID_TEMPLDLG_TOOLBOX_RIGHT"
+#define HID_EXPLORER_SRCH_COUNT "SFX2_HID_EXPLORER_SRCH_COUNT"
+#define HID_BEAMER_SORT_ASCENDING "SFX2_HID_BEAMER_SORT_ASCENDING"
+#define HID_BEAMER_SORT_DESCENDING "SFX2_HID_BEAMER_SORT_DESCENDING"
+#define HID_EXPLORER_SRCH_LATEST_COUNT "SFX2_HID_EXPLORER_SRCH_LATEST_COUNT"
+#define HID_CONFIG_EVENT_OFFICE_BASED "SFX2_HID_CONFIG_EVENT_OFFICE_BASED"
+#define HID_CONFIG_EVENT_DOCUMENT_BASED "SFX2_HID_CONFIG_EVENT_DOCUMENT_BASED"
+#define HID_ORGANIZE_NEW "SFX2_HID_ORGANIZE_NEW"
+#define HID_ORGANIZE_DELETE "SFX2_HID_ORGANIZE_DELETE"
+#define HID_ORGANIZE_EDIT "SFX2_HID_ORGANIZE_EDIT"
+#define HID_ORGANIZE_COPY_FROM "SFX2_HID_ORGANIZE_COPY_FROM"
+#define HID_ORGANIZE_COPY_TO "SFX2_HID_ORGANIZE_COPY_TO"
+#define HID_ORGANIZE_PRINT "SFX2_HID_ORGANIZE_PRINT"
+#define HID_ORGANIZE_PRINTER_SETUP "SFX2_HID_ORGANIZE_PRINTER_SETUP"
+#define HID_ORGANIZE_RESCAN "SFX2_HID_ORGANIZE_RESCAN"
+#define HID_STYLIST_NEW "SFX2_HID_STYLIST_NEW"
+#define HID_STYLIST_EDIT "SFX2_HID_STYLIST_EDIT"
+#define HID_STYLIST_DELETE "SFX2_HID_STYLIST_DELETE"
+#define HID_EXPLORERMENU_ARRANGEICONS "SFX2_HID_EXPLORERMENU_ARRANGEICONS"
+#define HID_EXPLORERMENU_ARRANGEICONS_ONGRID "SFX2_HID_EXPLORERMENU_ARRANGEICONS_ONGRID"
+#define HID_EXPLORERMENU_FIXEDICONPOS "SFX2_HID_EXPLORERMENU_FIXEDICONPOS"
+#define HID_EXPLORERMENU_OPEN "SFX2_HID_EXPLORERMENU_OPEN"
+#define HID_EXPLORERMENU_PRINT "SFX2_HID_EXPLORERMENU_PRINT"
+#define HID_EXPLORERMENU_SEARCH "SFX2_HID_EXPLORERMENU_SEARCH"
+#define HID_EXPLORERMENU_COPY "SFX2_HID_EXPLORERMENU_COPY"
+#define HID_EXPLORERMENU_DELETE "SFX2_HID_EXPLORERMENU_DELETE"
+#define HID_EXPLORERMENU_CREATELINK "SFX2_HID_EXPLORERMENU_CREATELINK"
+#define HID_EXPLORERMENU_EDITPROPERTIES "SFX2_HID_EXPLORERMENU_EDITPROPERTIES"
+#define HID_EXPLORERMENU_DOWNLOAD "SFX2_HID_EXPLORERMENU_DOWNLOAD"
+#define HID_EXPLORERMENU_STDTEMPLATE "SFX2_HID_EXPLORERMENU_STDTEMPLATE"
+#define HID_EXPLORERDLG_FILELIST "SFX2_HID_EXPLORERDLG_FILELIST"
+#define HID_PDFOLDERS_WORKPLACE "SFX2_HID_PDFOLDERS_WORKPLACE"
+#define HID_PDFOLDERS_EXPLORER "SFX2_HID_PDFOLDERS_EXPLORER"
+#define HID_PDFOLDERS_STANDARD "SFX2_HID_PDFOLDERS_STANDARD"
+#define HID_PDFOLDERS_ROOT "SFX2_HID_PDFOLDERS_ROOT"
+#define HID_PDFOLDERS_DESKTOP "SFX2_HID_PDFOLDERS_DESKTOP"
+#define HID_CNTMENU_REMOVE_GROUP "SFX2_HID_CNTMENU_REMOVE_GROUP"
+#define HID_CNTMENU_CLEAR_CACHE "SFX2_HID_CNTMENU_CLEAR_CACHE"
+#define HID_CNT_SYNC_INFO_DLG "SFX2_HID_CNT_SYNC_INFO_DLG"
+#define HID_CNT_REMOVE_REMOVEDLIST "SFX2_HID_CNT_REMOVE_REMOVEDLIST"
+#define HID_CNT_ABORT_DIALOG "SFX2_HID_CNT_ABORT_DIALOG"
+#define HID_CNT_PAGE_PRJ_DATAEXCHANGE "SFX2_HID_CNT_PAGE_PRJ_DATAEXCHANGE"
+#define HID_CHAOSDOC_OBJECTBAR_FILE "SFX2_HID_CHAOSDOC_OBJECTBAR_FILE"
+#define HID_CHAOSDOC_OBJECTBAR_MESSAGE "SFX2_HID_CHAOSDOC_OBJECTBAR_MESSAGE"
+#define HID_CHAOSDOC_MN_PART_OPEN "SFX2_HID_CHAOSDOC_MN_PART_OPEN"
+#define HID_CHAOSDOC_MN_PART_DELETE "SFX2_HID_CHAOSDOC_MN_PART_DELETE"
+#define HID_CHAOSDOC_MN_PART_RENAME "SFX2_HID_CHAOSDOC_MN_PART_RENAME"
+#define HID_CHAOSDOC_MN_PART_SAVEAS "SFX2_HID_CHAOSDOC_MN_PART_SAVEAS"
+#define HID_EXPLORER_DOCVIEW_ICON "SFX2_HID_EXPLORER_DOCVIEW_ICON"
+#define HID_EXPLORER_DOCVIEW_DETAILS "SFX2_HID_EXPLORER_DOCVIEW_DETAILS"
+#define HID_CHAOSDOC_WIN "SFX2_HID_CHAOSDOC_WIN"
+#define HID_CHAOSDOC_WIN_HEADER "SFX2_HID_CHAOSDOC_WIN_HEADER"
+#define HID_CHAOSDOC_WIN_PARTS "SFX2_HID_CHAOSDOC_WIN_PARTS"
+#define HID_CHAOSDOC_WIN_BODY "SFX2_HID_CHAOSDOC_WIN_BODY"
+#define HID_CNT_INSERT_COLUMN "SFX2_HID_CNT_INSERT_COLUMN"
+#define HID_CNT_REMOVE_COLUMN "SFX2_HID_CNT_REMOVE_COLUMN"
+#define HID_CNT_OPT_WIDTH "SFX2_HID_CNT_OPT_WIDTH"
+#define HID_CNT_SORT_ASC "SFX2_HID_CNT_SORT_ASC"
+#define HID_CNT_SORT_DESC "SFX2_HID_CNT_SORT_DESC"
+#define HID_CNT_RULEPG_OPEN_DIR "SFX2_HID_CNT_RULEPG_OPEN_DIR"
+#define HID_CHAOSDOC_MN_HEADER_ADDRESSBOOK "SFX2_HID_CHAOSDOC_MN_HEADER_ADDRESSBOOK"
+#define HID_CHAOSDOC_MN_HEADER_COPYLINK "SFX2_HID_CHAOSDOC_MN_HEADER_COPYLINK"
+#define HID_CLEAN_CACHE "SFX2_HID_CLEAN_CACHE"
+#define HID_SBOX_LOCATION "SFX2_HID_SBOX_LOCATION"
+#define HID_SBOX_SUBSCRIBTION "SFX2_HID_SBOX_SUBSCRIBTION"
+#define HID_SBOX_CDF_SUBSCRIBTION "SFX2_HID_SBOX_CDF_SUBSCRIBTION"
+#define HID_SBOX_SCHEDULE "SFX2_HID_SBOX_SCHEDULE"
+#define HID_SBOX_NOTIFICATION "SFX2_HID_SBOX_NOTIFICATION"
+#define HID_SBOX_SDC_GENERAL "SFX2_HID_SBOX_SDC_GENERAL"
+#define HID_BRWBOX_HEADERBAR "SFX2_HID_BRWBOX_HEADERBAR"
+#define HID_CANNOT_CREATE_BMK_HERE "SFX2_HID_CANNOT_CREATE_BMK_HERE"
+#define HID_CREATE_BOOKMARK "SFX2_HID_CREATE_BOOKMARK"
+#define HID_TASKBAR "SFX2_HID_TASKBAR"
+#define HID_TASKBUTTONBAR "SFX2_HID_TASKBUTTONBAR"
+#define HID_TASKTOOLBAR "SFX2_HID_TASKTOOLBAR"
+#define HID_CHAOSDOC_SHOW_FSYS_EXTENSION "SFX2_HID_CHAOSDOC_SHOW_FSYS_EXTENSION"
+#define HID_CNT_FILE "SFX2_HID_CNT_FILE"
+#define HID_CHAOSDOC_MN_BODY_OPENLINK "SFX2_HID_CHAOSDOC_MN_BODY_OPENLINK"
+#define HID_CHAOSDOC_MN_BODY_OPENLINK_BLANK "SFX2_HID_CHAOSDOC_MN_BODY_OPENLINK_BLANK"
+#define HID_CHAOSDOC_MN_BODY_DOWNLOAD "SFX2_HID_CHAOSDOC_MN_BODY_DOWNLOAD"
+#define HID_CHAOSDOC_MN_BODY_ADDBOOKMARK "SFX2_HID_CHAOSDOC_MN_BODY_ADDBOOKMARK"
+#define HID_OPEN_MENU_CNT "SFX2_HID_OPEN_MENU_CNT"
+#define HID_CNT_OPEN_AS_TEMPLATE "SFX2_HID_CNT_OPEN_AS_TEMPLATE"
+#define HID_CNT_OPEN_AS_DOC "SFX2_HID_CNT_OPEN_AS_DOC"
+#define HID_PDFOLDERS_TEMPLATE "SFX2_HID_PDFOLDERS_TEMPLATE"
+#define HID_EXPLORER_ROOT "SFX2_HID_EXPLORER_ROOT"
+#define HID_RESET_URL "SFX2_HID_RESET_URL"
+#define HID_PHONE_DIALOG "SFX2_HID_PHONE_DIALOG"
+#define HID_QB_RESOLVE_LINK "SFX2_HID_QB_RESOLVE_LINK"
+#define HID_CHAOSDOC_MN_HEADER_FLAG_BOLD "SFX2_HID_CHAOSDOC_MN_HEADER_FLAG_BOLD"
+#define HID_CHAOSDOC_MN_HEADER_FLAG_ITALIC "SFX2_HID_CHAOSDOC_MN_HEADER_FLAG_ITALIC"
+#define HID_CHAOSDOC_MN_HEADER_BIG_HEADER "SFX2_HID_CHAOSDOC_MN_HEADER_BIG_HEADER"
+#define HID_CHAOSDOC_MN_HEADER_TEMPLATE_HEADER "SFX2_HID_CHAOSDOC_MN_HEADER_TEMPLATE_HEADER"
+#define HID_CNT_MARK_THREAD_MARKED "SFX2_HID_CNT_MARK_THREAD_MARKED"
+#define HID_CNT_MARK_THREAD_UNMARKED "SFX2_HID_CNT_MARK_THREAD_UNMARKED"
+#define HID_CNT_DLG_SEARCH_BT_SHOW "SFX2_HID_CNT_DLG_SEARCH_BT_SHOW"
+#define HID_CNT_DLG_SEARCH_BT_UPDATE "SFX2_HID_CNT_DLG_SEARCH_BT_UPDATE"
+#define HID_CNT_DLG_SEARCH_BT_SYNCHRONIZE "SFX2_HID_CNT_DLG_SEARCH_BT_SYNCHRONIZE"
+#define HID_CNT_DLG_SEARCH_BT_STOP "SFX2_HID_CNT_DLG_SEARCH_BT_STOP"
+#define HID_CNT_PAGE_HEADER "SFX2_HID_CNT_PAGE_HEADER"
+#define HID_CNT_DLG_ADDRESS "SFX2_HID_CNT_DLG_ADDRESS"
+#define HID_EXPLORERMENU_AUTO_ARRANGEICONS "SFX2_HID_EXPLORERMENU_AUTO_ARRANGEICONS"
+#define HID_EXPLORERMENU_AUTO_ADJUSTICONS "SFX2_HID_EXPLORERMENU_AUTO_ADJUSTICONS"
+#define HID_EXPLORERMENU_FREE_POSITIONING "SFX2_HID_EXPLORERMENU_FREE_POSITIONING"
+#define HID_CNT_TARGET_MENU "SFX2_HID_CNT_TARGET_MENU"
+#define HID_CNT_PAGE_DESCRIPTION "SFX2_HID_CNT_PAGE_DESCRIPTION"
+#define HID_CNT_LB_HEADER "SFX2_HID_CNT_LB_HEADER"
+#define HID_CNT_LB_DESCRIPTION "SFX2_HID_CNT_LB_DESCRIPTION"
+#define HID_GROUPVIEW_BIG_SYMBOLS "SFX2_HID_GROUPVIEW_BIG_SYMBOLS"
+#define HID_GROUPVIEW_SMALL_SYMBOLS "SFX2_HID_GROUPVIEW_SMALL_SYMBOLS"
+#define HID_GROUPVIEW_ADD_GROUP "SFX2_HID_GROUPVIEW_ADD_GROUP"
+#define HID_GROUPVIEW_REMOVE_GROUP "SFX2_HID_GROUPVIEW_REMOVE_GROUP"
+#define HID_GROUPVIEW_RENAME_GROUP "SFX2_HID_GROUPVIEW_RENAME_GROUP"
+#define HID_GROUPVIEW_ADD_BOOKMARK "SFX2_HID_GROUPVIEW_ADD_BOOKMARK"
+#define HID_GROUPVIEW_TREE "SFX2_HID_GROUPVIEW_TREE"
+#define HID_GROUPVIEW_ADD_AS_FOLDER "SFX2_HID_GROUPVIEW_ADD_AS_FOLDER"
+#define HID_GROUPVIEW_ADD_AS_BMK "SFX2_HID_GROUPVIEW_ADD_AS_BMK"
+#define HID_GROUPVIEW_REMOVE_BMK "SFX2_HID_GROUPVIEW_REMOVE_BMK"
+#define HID_GROUPVIEW_CONTENT_BIG "SFX2_HID_GROUPVIEW_CONTENT_BIG"
+#define HID_GROUPVIEW_CONTENT_SMALL "SFX2_HID_GROUPVIEW_CONTENT_SMALL"
+#define HID_GROUPVIEW_CONTENT_TREE "SFX2_HID_GROUPVIEW_CONTENT_TREE"
+#define HID_GROUPVIEW_SHOW_DOCS "SFX2_HID_GROUPVIEW_SHOW_DOCS"
+#define HID_EDIT_TEMPLATE "SFX2_HID_EDIT_TEMPLATE"
+#define HID_PDFOLDERS_GRAPHICS "SFX2_HID_PDFOLDERS_GRAPHICS"
+#define HID_PDFOLDERS_GROUPS "SFX2_HID_PDFOLDERS_GROUPS"
+#define HID_OPEN_CHOOSE_FILTER "SFX2_HID_OPEN_CHOOSE_FILTER"
+#define HID_PDFOLDERS_BOOKMARKS "SFX2_HID_PDFOLDERS_BOOKMARKS"
+#define HID_PDFOLDERS_FAVORITES_ADD "SFX2_HID_PDFOLDERS_FAVORITES_ADD"
+#define HID_PDFOLDERS_FAVORITES_REMOVE "SFX2_HID_PDFOLDERS_FAVORITES_REMOVE"
+#define HID_PDFOLDERS_HISTORY "SFX2_HID_PDFOLDERS_HISTORY"
+#define HID_CNT_CB_FORCE_BODY_EXPORT "SFX2_HID_CNT_CB_FORCE_BODY_EXPORT"
+#define HID_CNT_PAGE_REPSTATE_CONTROL "SFX2_HID_CNT_PAGE_REPSTATE_CONTROL"
+#define HID_TASKSTATUSBAR "SFX2_HID_TASKSTATUSBAR"
+#define HID_CNT_PAGE_HEADER_TABBAR "SFX2_HID_CNT_PAGE_HEADER_TABBAR"
+#define HID_CNT_PAGE_SUBSCR_TABBAR "SFX2_HID_CNT_PAGE_SUBSCR_TABBAR"
+#define HID_CHAOSDOC_MN_PART_PRINT "SFX2_HID_CHAOSDOC_MN_PART_PRINT"
+#define HID_STATUSINDICATOR_TEXT "SFX2_HID_STATUSINDICATOR_TEXT"
+#define HID_STATUSINDICATOR_PROGRESS "SFX2_HID_STATUSINDICATOR_PROGRESS"
+#define HID_CNT_VALUE_ADDED_NONE "SFX2_HID_CNT_VALUE_ADDED_NONE"
+#define HID_CNT_VALUE_ADDED_DOCINFO "SFX2_HID_CNT_VALUE_ADDED_DOCINFO"
+#define HID_CNT_VALUE_ADDED_FULL "SFX2_HID_CNT_VALUE_ADDED_FULL"
+#define HID_CNT_MESSAGE_STOREMODE_REMOTE "SFX2_HID_CNT_MESSAGE_STOREMODE_REMOTE"
+#define HID_CNT_MESSAGE_STOREMODE_LOCAL "SFX2_HID_CNT_MESSAGE_STOREMODE_LOCAL"
+#define HID_CNT_VIEW_ALL_ARTICLES "SFX2_HID_CNT_VIEW_ALL_ARTICLES"
+#define HID_CNT_VIEW_UNREAD_ARTICLES "SFX2_HID_CNT_VIEW_UNREAD_ARTICLES"
+#define HID_CNT_VIEW_READ_ARTICLES "SFX2_HID_CNT_VIEW_READ_ARTICLES"
+#define HID_CNT_VIEW_MARKED_ARTICLES "SFX2_HID_CNT_VIEW_MARKED_ARTICLES"
+#define HID_CNT_VIEW_MARKED_AND_UNREAD_ARTICLES "SFX2_HID_CNT_VIEW_MARKED_AND_UNREAD_ARTICLES"
+#define HID_CNT_VIEW_ALL_FOLDERS "SFX2_HID_CNT_VIEW_ALL_FOLDERS"
+#define HID_CNT_VIEW_SUBSCRIBED_FOLDERS "SFX2_HID_CNT_VIEW_SUBSCRIBED_FOLDERS"
+#define HID_CNT_VIEW_ACTIVE_FOLDERS "SFX2_HID_CNT_VIEW_ACTIVE_FOLDERS"
+#define HID_CNT_SENT_VIEW_ALL_ARTICLES "SFX2_HID_CNT_SENT_VIEW_ALL_ARTICLES"
+#define HID_CNT_SENT_VIEW_SENT_ARTICLES "SFX2_HID_CNT_SENT_VIEW_SENT_ARTICLES"
+#define HID_CNT_SENT_VIEW_UNSENT_ARTICLES "SFX2_HID_CNT_SENT_VIEW_UNSENT_ARTICLES"
+#define HID_CNT_SENT_VIEW_MARKED_ARTICLES "SFX2_HID_CNT_SENT_VIEW_MARKED_ARTICLES"
+#define HID_MAILWIN_SEND_BUTTON "SFX2_HID_MAILWIN_SEND_BUTTON"
+#define HID_MAILWIN_CLOSE_BUTTON "SFX2_HID_MAILWIN_CLOSE_BUTTON"
+#define HID_MAILWIN_ROLE_BOX "SFX2_HID_MAILWIN_ROLE_BOX"
+#define HID_MAILWIN_ADDRESS_EDIT "SFX2_HID_MAILWIN_ADDRESS_EDIT"
+#define HID_MAILWIN_ADDRESS_BOX "SFX2_HID_MAILWIN_ADDRESS_BOX"
+#define HID_MAILWIN_SUBJECT_EDIT "SFX2_HID_MAILWIN_SUBJECT_EDIT"
+#define HID_MAILWIN_FROM_EDIT "SFX2_HID_MAILWIN_FROM_EDIT"
+#define HID_MAILWIN_PRIO_BOX "SFX2_HID_MAILWIN_PRIO_BOX"
+#define HID_TABDLG_APPLY_BTN "SFX2_HID_TABDLG_APPLY_BTN"
+#define HID_TP_COMMONPRINTOPTIONS "SFX2_HID_TP_COMMONPRINTOPTIONS"
+#define HID_HELP_WINDOW "SFX2_HID_HELP_WINDOW"
+#define HID_HELP_LISTBOX "SFX2_HID_HELP_LISTBOX"
+#define HID_HELP_TABCONTROL "SFX2_HID_HELP_TABCONTROL"
+#define HID_HELP_TOOLBOX "SFX2_HID_HELP_TOOLBOX"
+#define HID_HELP_TOOLBOXITEM_INDEX "SFX2_HID_HELP_TOOLBOXITEM_INDEX"
+#define HID_HELP_TOOLBOXITEM_START "SFX2_HID_HELP_TOOLBOXITEM_START"
+#define HID_HELP_TOOLBOXITEM_BACKWARD "SFX2_HID_HELP_TOOLBOXITEM_BACKWARD"
+#define HID_HELP_TOOLBOXITEM_FORWARD "SFX2_HID_HELP_TOOLBOXITEM_FORWARD"
+#define HID_HELP_TOOLBOXITEM_PRINT "SFX2_HID_HELP_TOOLBOXITEM_PRINT"
+#define HID_HELP_TOOLBOXITEM_BOOKMARKS "SFX2_HID_HELP_TOOLBOXITEM_BOOKMARKS"
+#define HID_HELP_TABPAGE_CONTENTS "SFX2_HID_HELP_TABPAGE_CONTENTS"
+#define HID_HELP_TABPAGE_INDEX "SFX2_HID_HELP_TABPAGE_INDEX"
+#define HID_HELP_TABPAGE_SEARCH "SFX2_HID_HELP_TABPAGE_SEARCH"
+#define HID_HELP_TABPAGE_BOOKMARKS "SFX2_HID_HELP_TABPAGE_BOOKMARKS"
+#define HID_TBXCONTROL_FILENEW "SFX2_HID_TBXCONTROL_FILENEW"
+#define HID_ORGANIZE_STDTEMPLATE_ADD "SFX2_HID_ORGANIZE_STDTEMPLATE_ADD"
+#define HID_ORGANIZE_STDTEMPLATE_DEL "SFX2_HID_ORGANIZE_STDTEMPLATE_DEL"
+#define HID_HELP_TOOLBOXITEM_SEARCHDIALOG "SFX2_HID_HELP_TOOLBOXITEM_SEARCHDIALOG"
+#define HID_HELP_BOOKMARKS_OPEN "SFX2_HID_HELP_BOOKMARKS_OPEN"
+#define HID_HELP_BOOKMARKS_RENAME "SFX2_HID_HELP_BOOKMARKS_RENAME"
+#define HID_HELP_BOOKMARKS_DELETE "SFX2_HID_HELP_BOOKMARKS_DELETE"
+#define HID_CLOSE_WARNING "SFX2_HID_CLOSE_WARNING"
+#define HID_DID_SAVE_PACKED_XML "SFX2_HID_DID_SAVE_PACKED_XML"
+#define HID_HELP_TREELISTBOX_CONTENTS "SFX2_HID_HELP_TREELISTBOX_CONTENTS"
+#define HID_CUSTOMIZETOOLBOX "SFX2_HID_CUSTOMIZETOOLBOX"
+#define HID_CUSTOMIZETOOLBOX_FUNCTIONS "SFX2_HID_CUSTOMIZETOOLBOX_FUNCTIONS"
+#define HID_CUSTOMIZETOOLBOX_TOOLBOX "SFX2_HID_CUSTOMIZETOOLBOX_TOOLBOX"
+#define HID_HELP_TEXT_SELECTION_MODE "SFX2_HID_HELP_TEXT_SELECTION_MODE"
+
+#define HID_WARNING_SECURITY_HYPERLINK "SFX2_HID_WARNING_SECURITY_HYPERLINK"
+#define HID_USERDEFBMP_TOOLBOX "SFX2_HID_USERDEFBMP_TOOLBOX"
+
+#define HID_CONFIG_LOAD "SFX2_HID_CONFIG_LOAD"
+#define HID_CONFIG_SAVE "SFX2_HID_CONFIG_SAVE"
+
+#define HID_SEARCHDIALOG "SFX2_HID_SEARCHDIALOG"
+
+#define HID_XMLSEC_WARNING_BROKENSIGNATURE "SFX2_HID_XMLSEC_WARNING_BROKENSIGNATURE"
+#define HID_XMLSEC_QUERY_LOSINGSIGNATURE "SFX2_HID_XMLSEC_QUERY_LOSINGSIGNATURE"
+#define HID_XMLSEC_QUERY_SAVEBEFORESIGN "SFX2_HID_XMLSEC_QUERY_SAVEBEFORESIGN"
+#define HID_XMLSECDLG_MACROWARN "SFX2_HID_XMLSECDLG_MACROWARN"
+#define HID_XMLSEC_INFO_WRONGDOCFORMAT "SFX2_HID_XMLSEC_INFO_WRONGDOCFORMAT"
+#define HID_WARNING_MACROSDISABLED "SFX2_HID_WARNING_MACROSDISABLED"
+#define HID_WARNING_ALIENFORMAT "SFX2_HID_WARNING_ALIENFORMAT"
+#define HID_HELP_ONSTARTUP_BOX "SFX2_HID_HELP_ONSTARTUP_BOX"
+#define HID_DLG_CHECKFORONLINEUPDATE "SFX2_HID_DLG_CHECKFORONLINEUPDATE"
+#define HID_TP_CUSTOMPROPERTIES "SFX2_HID_TP_CUSTOMPROPERTIES"
+#define HID_CTRL_CUSTOMPROPERTIES "SFX2_HID_CTRL_CUSTOMPROPERTIES"
+#define HID_CTRL_CUSTOMPROPS_YES_NO "SFX2_HID_CTRL_CUSTOMPROPS_YES_NO"
+#define HID_DLG_CUSTOMPROPS_DURATION "SFX2_HID_DLG_CUSTOMPROPS_DURATION"
+
+#define HID_HELP_ONHELP "SFX2_HID_HELP_ONHELP"
+
+#define HID_QUERY_LOAD_TEMPLATE "SFX2_HID_QUERY_LOAD_TEMPLATE"
+
+#define HID_SECURITYTAB_PASSWORD_TO_OPEN "SFX2_HID_SECURITYTAB_PASSWORD_TO_OPEN"
+#define HID_SECURITYTAB_CONFIRM_PASSWORD_TO_OPEN "SFX2_HID_SECURITYTAB_CONFIRM_PASSWORD_TO_OPEN"
+#define HID_SECURITYTAB_PASSWORD_TO_MODIFY "SFX2_HID_SECURITYTAB_PASSWORD_TO_MODIFY"
+#define HID_SECURITYTAB_CONFIRM_PASSWORD_TO_MODIFY "SFX2_HID_SECURITYTAB_CONFIRM_PASSWORD_TO_MODIFY"
+#define HID_SECURITYTAB_OPEN_FILE_READONLY "SFX2_HID_SECURITYTAB_OPEN_FILE_READONLY"
+#define HID_SECURITYTAB_RECORD_CHANGES "SFX2_HID_SECURITYTAB_RECORD_CHANGES"
+#define HID_SECURITYTAB_PROTECTION "SFX2_HID_SECURITYTAB_PROTECTION"
+
+#define HID_TASKPANE_WINDOW "SFX2_HID_TASKPANE_WINDOW"
+#define HID_TASKPANE_VIEW_MENU "SFX2_HID_TASKPANE_VIEW_MENU"
+#define HID_DOCINFOSECURITY "SFX2_HID_DOCINFOSECURITY"
+
+#endif // #ifndef _SFX_HELPID_HRC
+
+// ******************************************************************* EOF
+
diff --git a/sfx2/source/inc/hexplwnd.hxx b/sfx2/source/inc/hexplwnd.hxx
new file mode 100644
index 000000000000..228ce78949b9
--- /dev/null
+++ b/sfx2/source/inc/hexplwnd.hxx
@@ -0,0 +1,101 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _HEXPLWND_HXX
+#define _HEXPLWND_HXX
+
+// includes --------------------------------------------------------------
+
+#include <com/sun/star/beans/PropertyValues.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/PropertyState.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/beans/XMultiPropertySet.hpp>
+#include <com/sun/star/beans/XFastPropertySet.hpp>
+#include <com/sun/star/beans/XVetoableChangeListener.hpp>
+#include <com/sun/star/beans/XPropertyState.hpp>
+#include <com/sun/star/beans/XPropertyStateChangeListener.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/beans/XPropertiesChangeListener.hpp>
+#include <com/sun/star/beans/XPropertyChangeListener.hpp>
+#include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+#include <com/sun/star/beans/PropertyStateChangeEvent.hpp>
+#include <com/sun/star/beans/PropertyChangeEvent.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <sfx2/childwin.hxx>
+#include <sfx2/dockwin.hxx>
+
+// forward ---------------------------------------------------------------
+
+class SfxBeamerUnoFrame_Impl;
+
+// class SfxExplorerHorizChildWnd_Impl -----------------------------------
+
+class SfxExplorerHorizChildWnd_Impl : public SfxChildWindow
+{
+public:
+ SfxExplorerHorizChildWnd_Impl( Window* pParent, sal_uInt16 nId,
+ SfxBindings* pBindings,
+ SfxChildWinInfo* pInfo );
+
+ SFX_DECL_CHILDWINDOW(SfxExplorerHorizChildWnd_Impl);
+
+
+ virtual sal_Bool QueryClose();
+};
+
+// class SfxExplorerDockWnd_Impl -----------------------------------------
+
+class SfxExplorerHorizDockWnd_Impl : public SfxDockingWindow
+{
+private:
+ SfxBeamerUnoFrame_Impl* _pFrame;
+
+protected:
+ virtual void GetFocus();
+ virtual long Notify( NotifyEvent& rNEvt );
+
+public:
+ SfxExplorerHorizDockWnd_Impl( SfxBindings* pBindings,
+ SfxChildWindow* pChildWin,
+ Window* pParent, const ResId& rResId );
+ ~SfxExplorerHorizDockWnd_Impl();
+
+ virtual void FillInfo( SfxChildWinInfo& ) const;
+ virtual void FadeIn( sal_Bool );
+ sal_Bool QueryClose();
+ void SetURL( const ::com::sun::star::util::URL& rURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs );
+ const ::com::sun::star::util::URL& GetURL() const;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > GetFrameInterface();
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& GetArgs() const;
+};
+
+
+#endif
+
diff --git a/sfx2/source/inc/iframe.hxx b/sfx2/source/inc/iframe.hxx
new file mode 100644
index 000000000000..041ffac822b7
--- /dev/null
+++ b/sfx2/source/inc/iframe.hxx
@@ -0,0 +1,93 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_IFRAME_HXX
+#define _SFX_IFRAME_HXX
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/lang/XEventListener.hpp>
+#include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/embed/XEmbeddedObject.hpp>
+#include <cppuhelper/implbase6.hxx>
+
+#include <rtl/ustring.hxx>
+#include <svl/ownlist.hxx>
+#include <svl/itemprop.hxx>
+
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/frmdescr.hxx>
+
+namespace sfx2
+{
+
+class IFrameObject : public ::cppu::WeakImplHelper6 <
+ com::sun::star::util::XCloseable,
+ com::sun::star::lang::XEventListener,
+ com::sun::star::frame::XSynchronousFrameLoader,
+ com::sun::star::ui::dialogs::XExecutableDialog,
+ com::sun::star::lang::XInitialization,
+ com::sun::star::beans::XPropertySet >
+{
+ com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > mxFact;
+ com::sun::star::uno::Reference < com::sun::star::frame::XFrame > mxFrame;
+ com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject > mxObj;
+ SfxItemPropertyMap maPropMap;
+ SfxFrameDescriptor maFrmDescr;
+
+ IFrameObject( const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rFact );
+ ~IFrameObject();
+
+ virtual sal_Bool SAL_CALL load( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& lDescriptor,
+ const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame ) throw( com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL cancel() throw( com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL close( sal_Bool bDeliverOwnership ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& xListener ) throw( com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& xListener ) throw( com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& aEvent ) throw (com::sun::star::uno::RuntimeException) ;
+ virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::sal_Int16 SAL_CALL execute( ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL addPropertyChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL removePropertyChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL addVetoableChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL removeVetoableChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+public:
+ SFX_DECL_XSERVICEINFO
+};
+
+}
+#endif
diff --git a/sfx2/source/inc/intro.hxx b/sfx2/source/inc/intro.hxx
new file mode 100644
index 000000000000..1b09008c0778
--- /dev/null
+++ b/sfx2/source/inc/intro.hxx
@@ -0,0 +1,55 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_INTRO_HXX
+#define _SFX_INTRO_HXX
+
+// include ---------------------------------------------------------------
+
+#include <vcl/wrkwin.hxx>
+#include <vcl/bitmap.hxx>
+
+// class IntroWindow_Impl ------------------------------------------------
+
+class IntroWindow_Impl : public WorkWindow
+{
+private:
+ Bitmap aIntroBmp;
+
+ void Init();
+
+public:
+ IntroWindow_Impl( const Bitmap& rBmp );
+ ~IntroWindow_Impl();
+
+ virtual void Paint( const Rectangle& );
+
+ void Slide();
+};
+
+#endif // #ifndef _SFX_INTRO_HXX
+
+
diff --git a/sfx2/source/inc/mailmodel.hxx b/sfx2/source/inc/mailmodel.hxx
new file mode 100644
index 000000000000..43e938d46800
--- /dev/null
+++ b/sfx2/source/inc/mailmodel.hxx
@@ -0,0 +1,105 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef INCLUDED_SFX_MAILMODEL_HXX
+#define INCLUDED_SFX_MAILMODEL_HXX
+
+#include <com/sun/star/frame/XFrame.hpp>
+
+// class SfxMailModel_Impl -----------------------------------------------
+
+class AddressList_Impl;
+
+class SfxMailModel_Impl
+{
+public:
+ enum MailPriority
+ {
+ PRIO_HIGHEST,
+ PRIO_HIGH,
+ PRIO_NORMAL,
+ PRIO_LOW,
+ PRIO_LOWEST
+ };
+
+ enum AddressRole
+ {
+ ROLE_TO,
+ ROLE_CC,
+ ROLE_BCC
+ };
+
+ enum MailDocType
+ {
+ TYPE_SELF,
+ TYPE_ASPDF
+ };
+
+private:
+ enum SaveResult
+ {
+ SAVE_SUCCESSFULL,
+ SAVE_CANCELLED,
+ SAVE_ERROR
+ };
+
+ AddressList_Impl* mpToList;
+ AddressList_Impl* mpCcList;
+ AddressList_Impl* mpBccList;
+ String maFromAddress;
+ String maSubject;
+ MailPriority mePriority;
+
+ sal_Bool mbLoadDone;
+
+ void ClearList( AddressList_Impl* pList );
+ void MakeValueList( AddressList_Impl* pList, String& rValueList );
+ SaveResult SaveDocumentAsFormat( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const rtl::OUString& rType, rtl::OUString& rFileNamePath );
+
+ DECL_LINK( DoneHdl, void* );
+
+public:
+ enum SendMailResult
+ {
+ SEND_MAIL_OK,
+ SEND_MAIL_CANCELLED,
+ SEND_MAIL_ERROR
+ };
+
+ SfxMailModel_Impl();
+ ~SfxMailModel_Impl();
+
+ void AddAddress( const String& rAddress, AddressRole eRole );
+ void SetFromAddress( const String& rAddress ) { maFromAddress = rAddress; }
+ void SetSubject( const String& rSubject ) { maSubject = rSubject; }
+ void SetPriority( MailPriority ePrio ) { mePriority = ePrio; }
+
+ SendMailResult Send( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const rtl::OUString& rType );
+};
+
+BOOL CreateFromAddress_Impl( String& rFrom );
+
+#endif // INCLUDED_SFX_MAILMODEL_HXX
diff --git a/sfx2/source/inc/mnucfga.hxx b/sfx2/source/inc/mnucfga.hxx
new file mode 100644
index 000000000000..bbc3c1cd63ac
--- /dev/null
+++ b/sfx2/source/inc/mnucfga.hxx
@@ -0,0 +1,52 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFXMNUCFGA_HXX
+#define _SFXMNUCFGA_HXX
+
+#include <tools/string.hxx>
+#ifndef _SFXMINARRAY_HXX
+#include <sfx2/minarray.hxx>
+#endif
+
+//==================================================================
+
+class SfxMenuCfgItemArr;
+
+struct SfxMenuCfgItem
+{
+ USHORT nId; // id of the binding or 0 if none
+ String aTitle; // title of the item
+ String aHelpText; // Hilfetext
+ String aCommand;
+ SfxMenuCfgItemArr* pPopup; // pointer to a popup menu (if any)
+};
+
+DECL_PTRARRAY(SfxMenuCfgItemArr, SfxMenuCfgItem*, 4, 4 )
+
+
+#endif
+
diff --git a/sfx2/source/inc/nfltdlg.hxx b/sfx2/source/inc/nfltdlg.hxx
new file mode 100644
index 000000000000..371fa96c57a2
--- /dev/null
+++ b/sfx2/source/inc/nfltdlg.hxx
@@ -0,0 +1,66 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFXNFLTDLG_HXX
+#define _SFXNFLTDLG_HXX
+
+
+#include <vcl/dialog.hxx>
+#include <vcl/lstbox.hxx>
+#ifndef _SV_BUTTON_HXX //autogen
+#include <vcl/button.hxx>
+#endif
+#include <vcl/fixed.hxx>
+class SfxFilterMatcher;
+
+class SfxMedium;
+class SfxFilterDialog : public ModalDialog
+{
+private:
+ FixedLine aMimeTypeFL;
+ FixedText aMIMEType;
+ FixedText aExtension;
+ FixedLine aFilterFL;
+ ListBox aListbox;
+ OKButton aOkBtn;
+ CancelButton aCancelBtn;
+ HelpButton aHelpBtn;
+
+ const SfxFilterMatcher& rMatcher;
+
+ DECL_LINK( OkHdl, Control * );
+
+public:
+ SfxFilterDialog( Window * pParent,
+ SfxMedium* pMed,
+ const SfxFilterMatcher &rMatcher,
+ const String *pDefFilter, BOOL bShowConvert = TRUE );
+
+ String GetSelectEntry() const;
+};
+
+#endif
+
diff --git a/sfx2/source/inc/nochaos.hxx b/sfx2/source/inc/nochaos.hxx
new file mode 100644
index 000000000000..4b5d7fb1f40e
--- /dev/null
+++ b/sfx2/source/inc/nochaos.hxx
@@ -0,0 +1,40 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_NOCHAOS_HXX
+#define _SFX_NOCHAOS_HXX
+
+class SfxItemPool;
+
+class NoChaos
+{
+public:
+ static SfxItemPool* GetItemPool();
+ static USHORT ReleaseItemPool();
+};
+
+#endif
+
diff --git a/sfx2/source/inc/objmnctl.hxx b/sfx2/source/inc/objmnctl.hxx
new file mode 100644
index 000000000000..e58c6cd5592d
--- /dev/null
+++ b/sfx2/source/inc/objmnctl.hxx
@@ -0,0 +1,56 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_OBJMNCTL_HXX
+#define _SFX_OBJMNCTL_HXX
+
+
+#ifndef _SFX_HXX
+#include <sfx2/mnuitem.hxx>
+#endif
+
+class SfxBindings;
+class PopupMenu;
+class Menu;
+
+class SfxObjectVerbsControl: public SfxMenuControl
+{
+ PopupMenu* pMenu;
+ Menu& rParent;
+
+private:
+ void FillMenu();
+ DECL_LINK( MenuSelect, Menu * );
+ virtual void StateChanged( USHORT, SfxItemState, const SfxPoolItem* pState );
+
+public:
+ SfxObjectVerbsControl(USHORT, Menu&, SfxBindings&);
+ ~SfxObjectVerbsControl();
+ virtual PopupMenu* GetPopup() const;
+ SFX_DECL_MENU_CONTROL();
+};
+
+#endif
diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx
new file mode 100644
index 000000000000..b5087fb46294
--- /dev/null
+++ b/sfx2/source/inc/objshimp.hxx
@@ -0,0 +1,176 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_OBJSHIMP_HXX
+#define _SFX_OBJSHIMP_HXX
+
+//#include <hash_map>
+
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <rtl/ustring.hxx>
+#include <rtl/ref.hxx>
+#include <com/sun/star/logging/XSimpleLogRing.hpp>
+#include <tools/datetime.hxx>
+
+#include <unotools/securityoptions.hxx>
+#include <sfx2/objsh.hxx>
+#include "sfx2/docmacromode.hxx"
+#include "bitset.hxx"
+
+namespace svtools { class AsynchronLink; }
+
+//====================================================================
+
+DBG_NAMEEX(SfxObjectShell)
+
+class SfxViewFrame;
+struct MarkData_Impl
+{
+ String aMark;
+ String aUserData;
+ SfxViewFrame* pFrame;
+};
+
+class SfxFrame;
+class SfxToolBoxConfig;
+class SfxBasicManagerHolder;
+
+struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess
+{
+ ::comphelper::EmbeddedObjectContainer* mpObjectContainer;
+ SfxBasicManagerHolder*
+ pBasicManager;
+ SfxObjectShell& rDocShell;
+ ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >
+ xBasicLibraries;
+ ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >
+ xDialogLibraries;
+ com::sun::star::uno::Sequence < rtl::OUString > xEventNames;
+ ::sfx2::DocumentMacroMode
+ aMacroMode;
+ SfxProgress* pProgress;
+ String aTitle;
+ String aTempName;
+ DateTime nTime;
+ sal_uInt16 nVisualDocumentNumber;
+ sal_Int16 nDocumentSignatureState;
+ sal_Int16 nScriptingSignatureState;
+ sal_Bool bInList:1, // ob per First/Next erreichbar
+ bClosing:1, // sal_True w"aehrend Close(), um Benachrichtigungs-Rekursionen zu verhindern
+ bIsSaving:1,
+ bPasswd:1,
+ bIsTmp:1,
+ bIsNamedVisible:1,
+ bIsTemplate:1,
+ bIsAbortingImport:1, // Importvorgang soll abgebrochen werden.
+ bImportDone : 1, //Import schon fertig? Fuer AutoReload von Docs.
+ bInPrepareClose : 1,
+ bPreparedForClose : 1,
+ bWaitingForPicklist : 1,// Muss noch in die Pickliste
+ bForbidReload : 1,
+ bBasicInitialized :1,
+ bIsPrintJobCancelable :1, // Stampit disable/enable cancel button for print jobs ... default = true = enable!
+ bOwnsStorage:1,
+ bNoBaseURL:1,
+ bInitialized:1,
+ bSignatureErrorIsShown:1,
+ bModelInitialized:1, // whether the related model is initialized
+ bPreserveVersions:1,
+ m_bMacroSignBroken:1, // whether the macro signature was explicitly broken
+ m_bNoBasicCapabilities:1,
+ m_bDocRecoverySupport:1,
+ bQueryLoadTemplate:1,
+ bLoadReadonly:1,
+ bUseUserData:1,
+ bSaveVersionOnClose:1,
+ m_bSharedXMLFlag:1, // whether the flag should be stored in xml file
+ m_bAllowShareControlFileClean:1; // whether the flag should be stored in xml file
+
+ IndexBitSet aBitSet;
+ sal_uInt32 lErr;
+ sal_uInt16 nEventId; // falls vor Activate noch ein
+ // Open/Create gesendet werden mu/s
+ AutoReloadTimer_Impl *pReloadTimer;
+ MarkData_Impl* pMarkData;
+ sal_uInt16 nLoadedFlags;
+ sal_uInt16 nFlagsInProgress;
+ sal_Bool bModalMode;
+ sal_Bool bRunningMacro;
+ sal_Bool bReloadAvailable;
+ sal_uInt16 nAutoLoadLocks;
+ SfxModule* pModule;
+ SfxObjectShellFlags eFlags;
+ sal_Bool bReadOnlyUI;
+ SvRefBaseRef xHeaderAttributes;
+ sal_Bool bHiddenLockedByAPI;
+ ::rtl::Reference< SfxBaseModel >
+ pBaseModel;
+ sal_uInt16 nStyleFilter;
+ sal_Bool bDisposing;
+
+ sal_Bool m_bEnableSetModified;
+ sal_Bool m_bIsModified;
+
+ Rectangle m_aVisArea;
+ MapUnit m_nMapUnit;
+
+ sal_Bool m_bCreateTempStor;
+ ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xDocStorage;
+
+ sal_Bool m_bIsInit;
+
+ ::rtl::OUString m_aSharedFileURL;
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::logging::XSimpleLogRing > m_xLogRing;
+
+ sal_Bool m_bIncomplEncrWarnShown;
+
+ // TODO/LATER: m_aModifyPasswordInfo should completely replace m_nModifyPasswordHash in future
+ sal_uInt32 m_nModifyPasswordHash;
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aModifyPasswordInfo;
+ sal_Bool m_bModifyPasswordEntered;
+
+ SfxObjectShell_Impl( SfxObjectShell& _rDocShell );
+ virtual ~SfxObjectShell_Impl();
+
+ static sal_Bool NeedsOfficeUpdateDialog();
+
+ // IMacroDocumentAccess overridables
+ virtual sal_Int16 getCurrentMacroExecMode() const;
+ virtual sal_Bool setCurrentMacroExecMode( sal_uInt16 nMacroMode );
+ virtual ::rtl::OUString getDocumentLocation() const;
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getZipStorageToSign();
+ virtual sal_Bool documentStorageHasMacros() const;
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > getEmbeddedDocumentScripts() const;
+ virtual sal_Int16 getScriptingSignatureState();
+
+ virtual sal_Bool hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor );
+ virtual void showBrokenSignatureWarning( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction ) const;
+};
+
+#endif
+
diff --git a/sfx2/source/inc/openflag.hxx b/sfx2/source/inc/openflag.hxx
new file mode 100644
index 000000000000..5b719095eae8
--- /dev/null
+++ b/sfx2/source/inc/openflag.hxx
@@ -0,0 +1,41 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_OPENFLAG_HXX
+#define _SFX_OPENFLAG_HXX
+
+// Datei zum Bearbeiten "offnen, anschliessend funktioniert nur noch
+// die dritte Variante (Lesen einer Kopie)
+#define SFX_STREAM_READWRITE (STREAM_READWRITE | STREAM_SHARE_DENYWRITE)
+// Ich arbeite roh auf dem Original, keine Kopie
+// -> Datei kann anschliessend nicht zum Bearbeiten ge"offnet werden
+#define SFX_STREAM_READONLY (STREAM_READ | STREAM_SHARE_DENYWRITE) // + !bDirect
+// Jemand anders bearbeitet das File, es wird eine Kopie erstellt
+// -> Datei kann anschliessend zum Bearbeiten ge"offnet werden
+#define SFX_STREAM_READONLY_MAKECOPY (STREAM_READ | STREAM_SHARE_DENYNONE)
+
+
+#endif
diff --git a/sfx2/source/inc/ownsubfilterservice.hxx b/sfx2/source/inc/ownsubfilterservice.hxx
new file mode 100644
index 000000000000..f800e1e253ae
--- /dev/null
+++ b/sfx2/source/inc/ownsubfilterservice.hxx
@@ -0,0 +1,90 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _OWNSUBFILTERSERVICE_HXX_
+#define _OWNSUBFILTERSERVICE_HXX_
+
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#ifndef _COM_SUN_STAR_LANG_XPSERVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/io/XStream.hpp>
+#include <cppuhelper/implbase3.hxx>
+
+class SfxObjectShell;
+
+namespace sfx2 {
+
+class OwnSubFilterService : public cppu::WeakImplHelper3 < ::com::sun::star::document::XFilter
+ ,::com::sun::star::lang::XInitialization
+ ,::com::sun::star::lang::XServiceInfo >
+{
+ ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel;
+ ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream;
+ SfxObjectShell* m_pObjectShell;
+
+public:
+
+ OwnSubFilterService(const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory);
+ virtual ~OwnSubFilterService();
+
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
+ impl_getStaticSupportedServiceNames();
+
+ static ::rtl::OUString SAL_CALL impl_getStaticImplementationName();
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
+ impl_staticCreateSelfInstance(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > SAL_CALL
+ impl_createFactory(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
+
+
+ // XFilter
+ virtual ::sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL cancel() throw (::com::sun::star::uno::RuntimeException);
+
+ // XInitialization
+ virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ // XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
+
+};
+
+} // namespace sfx2
+
+#endif
+
diff --git a/sfx2/source/inc/partwnd.hxx b/sfx2/source/inc/partwnd.hxx
new file mode 100644
index 000000000000..4a485e3cc91f
--- /dev/null
+++ b/sfx2/source/inc/partwnd.hxx
@@ -0,0 +1,90 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _PARTWND_HXX
+#define _PARTWND_HXX
+
+#include <com/sun/star/uno/Reference.h>
+
+namespace com
+{
+ namespace sun
+ {
+ namespace star
+ {
+ namespace frame
+ {
+ class XFrame;
+ }
+ }
+ }
+}
+
+#include <sfx2/childwin.hxx>
+#include <sfx2/dockwin.hxx>
+
+// forward ---------------------------------------------------------------
+
+// class SfxPartChildWnd_Impl -----------------------------------
+
+class SfxPartChildWnd_Impl : public SfxChildWindow
+{
+public:
+ SfxPartChildWnd_Impl( Window* pParent, sal_uInt16 nId,
+ SfxBindings* pBindings,
+ SfxChildWinInfo* pInfo );
+
+ SFX_DECL_CHILDWINDOW(SfxPartChildWnd_Impl);
+ ~SfxPartChildWnd_Impl();
+
+ virtual sal_Bool QueryClose();
+};
+
+// class SfxExplorerDockWnd_Impl -----------------------------------------
+
+class SfxPartDockWnd_Impl : public SfxDockingWindow
+{
+private:
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > m_xFrame;
+
+protected:
+ virtual void Resize();
+ virtual long Notify( NotifyEvent& rNEvt );
+
+public:
+ SfxPartDockWnd_Impl( SfxBindings* pBindings,
+ SfxChildWindow* pChildWin,
+ Window* pParent,
+ WinBits nBits );
+
+ ~SfxPartDockWnd_Impl();
+ sal_Bool QueryClose();
+ virtual void FillInfo(SfxChildWinInfo&) const;
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > ForgetFrame();
+};
+
+#endif
+
diff --git a/sfx2/source/inc/plugin.hxx b/sfx2/source/inc/plugin.hxx
new file mode 100644
index 000000000000..a9d3ce2f1e72
--- /dev/null
+++ b/sfx2/source/inc/plugin.hxx
@@ -0,0 +1,91 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_PLUGIN_HXX
+#define _SFX_PLUGIN_HXX
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/lang/XEventListener.hpp>
+#include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
+#include <com/sun/star/plugin/XPlugin.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/embed/XEmbeddedObject.hpp>
+#include <cppuhelper/implbase5.hxx>
+
+#include <rtl/ustring.hxx>
+#include <svl/ownlist.hxx>
+#include <svl/itemprop.hxx>
+
+#include <sfx2/sfxuno.hxx>
+
+namespace sfx2
+{
+
+class PluginObject : public ::cppu::WeakImplHelper5 <
+ com::sun::star::util::XCloseable,
+ com::sun::star::lang::XEventListener,
+ com::sun::star::frame::XSynchronousFrameLoader,
+ com::sun::star::lang::XInitialization,
+ com::sun::star::beans::XPropertySet >
+{
+ com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > mxFact;
+ com::sun::star::uno::Reference< com::sun::star::plugin::XPlugin > mxPlugin;
+ com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject > mxObj;
+ SfxItemPropertyMap maPropMap;
+ SvCommandList maCmdList;
+ ::rtl::OUString maURL;
+ ::rtl::OUString maMimeType;
+
+ PluginObject( const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rFact );
+ ~PluginObject();
+
+ virtual sal_Bool SAL_CALL load( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& lDescriptor,
+ const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame ) throw( com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL cancel() throw( com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL close( sal_Bool bDeliverOwnership ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& xListener ) throw( com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& xListener ) throw( com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& aEvent ) throw (com::sun::star::uno::RuntimeException) ;
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL addPropertyChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL removePropertyChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL addVetoableChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL removeVetoableChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & aListener) throw( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+public:
+ SFX_DECL_XSERVICEINFO
+};
+
+}
+#endif
diff --git a/sfx2/source/inc/preview.hxx b/sfx2/source/inc/preview.hxx
new file mode 100644
index 000000000000..f247a2570cf9
--- /dev/null
+++ b/sfx2/source/inc/preview.hxx
@@ -0,0 +1,73 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFXPREVIEW_HXX
+#define _SFXPREVIEW_HXX
+
+
+#include <sfx2/doctempl.hxx>
+#include <sfx2/basedlgs.hxx>
+
+class SfxObjectShell;
+//REMOVE class SvStorageRef;
+class SfxFrameWindow;
+
+class SfxFrame;
+class GDIMetaFile;
+
+class SfxPreviewBase_Impl : public Window
+{
+protected:
+ ::boost::shared_ptr<GDIMetaFile> pMetaFile;
+public:
+ SfxPreviewBase_Impl( Window* pParent,
+ const ResId& rResId );
+ SfxPreviewBase_Impl( Window* pParent );
+ ~SfxPreviewBase_Impl( );
+ void SetObjectShell( SfxObjectShell* pObj );
+ void SetGDIFile( ::boost::shared_ptr<GDIMetaFile> pFile );
+ virtual void Resize();
+};
+
+
+
+class SfxPreviewWin_Impl: public SfxPreviewBase_Impl
+{
+protected:
+ virtual void Paint( const Rectangle& rRect );
+public:
+ SfxPreviewWin_Impl( Window* pParent,
+ const ResId& rResId )
+ : SfxPreviewBase_Impl( pParent, rResId ){};
+ SfxPreviewWin_Impl( Window* pParent )
+ : SfxPreviewBase_Impl( pParent ){};
+ static void ImpPaint(
+ const Rectangle& rRect, GDIMetaFile* pFile, Window* pWindow );
+ static SfxFrameWindow*
+ PreviewFactory( SfxFrame* pFrame, const String& rName );
+};
+
+#endif
diff --git a/sfx2/source/inc/recfloat.hxx b/sfx2/source/inc/recfloat.hxx
new file mode 100644
index 000000000000..5667a6c1e67a
--- /dev/null
+++ b/sfx2/source/inc/recfloat.hxx
@@ -0,0 +1,69 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _RECFLOAT_HXX
+#define _RECFLOAT_HXX
+
+// includes *******************************************************************
+
+#include <sfx2/childwin.hxx>
+#include <sfx2/basedlgs.hxx>
+
+class SfxRecordingFloatWrapper_Impl : public SfxChildWindow
+{
+ SfxBindings* pBindings;
+public:
+ SfxRecordingFloatWrapper_Impl( Window* pParent ,
+ USHORT nId ,
+ SfxBindings* pBindings ,
+ SfxChildWinInfo* pInfo );
+ ~SfxRecordingFloatWrapper_Impl();
+
+ SFX_DECL_CHILDWINDOW(SfxRecordingFloatWrapper_Impl);
+ virtual sal_Bool QueryClose();
+};
+
+class SfxRecordingFloat_Impl : public SfxFloatingWindow
+{
+ SfxChildWindow* pWrapper;
+ ToolBox aTbx;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XToolbarController > xStopRecTbxCtrl;
+public:
+ SfxRecordingFloat_Impl( SfxBindings* pBindings ,
+ SfxChildWindow* pChildWin ,
+ Window* pParent );
+ virtual ~SfxRecordingFloat_Impl();
+ virtual BOOL Close();
+ virtual void FillInfo( SfxChildWinInfo& rInfo ) const;
+ virtual void StateChanged( StateChangedType nStateChange );
+
+ DECL_LINK( Select, ToolBox * );
+};
+
+#endif
+
+
diff --git a/sfx2/source/inc/referers.hxx b/sfx2/source/inc/referers.hxx
new file mode 100644
index 000000000000..6c938861d013
--- /dev/null
+++ b/sfx2/source/inc/referers.hxx
@@ -0,0 +1,36 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_REFERERS_HXX
+#define _SFX_REFERERS_HXX
+
+#define SFX_REFERER_USER "private:user"
+#define SFX_REFERER_APPEVENT "private:appevent"
+#define SFX_REFERER_EXPLORER "private:explorer"
+#define SFX_REFERER_NEWMENU "private:newmenu"
+
+
+#endif
diff --git a/sfx2/source/inc/sfxlocal.hrc b/sfx2/source/inc/sfxlocal.hrc
new file mode 100644
index 000000000000..202ed6f6f00f
--- /dev/null
+++ b/sfx2/source/inc/sfxlocal.hrc
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+//============================================================================
+// Lokale Resourcen
+//
+// (C) 1996 - 2000 Star Division GmbH, Hamburg, Germany
+// $Author: rt $ $Date: 2008-07-30 09:24:39 $ $Revision: 1.8 $
+// $Logfile: T:/sfx2/source/inc/sfxlocal.hrv $ $Workfile: SFXLOCAL.HRC $
+//----------------------------------------------------------------------------
+#ifndef _SFXLOCAL_HRC
+#define _SFXLOCAL_HRC
+
+#include <sfx2/sfx.hrc>
+
+// Strings ---------------------------------------------------------------
+
+#define STR_SFX_NEWOFFICEDOC (RID_SFX_SFXLOCAL_START + 0)
+#define STR_SFX_FILEDLG_ACTUALVERSION (RID_SFX_SFXLOCAL_START + 2)
+#define STR_SFX_EXPLORERFILE_INSERT (RID_SFX_SFXLOCAL_START + 3)
+#define STR_SFX_EXPLORERFILE_BUTTONINSERT (RID_SFX_SFXLOCAL_START + 4)
+#define STR_SFX_IMPORT_ALL (RID_SFX_SFXLOCAL_START + 5)
+#define STR_SFX_EXPLORERFILE_EXPORT (RID_SFX_SFXLOCAL_START + 6)
+#define STR_SFX_DOCK (RID_SFX_SFXLOCAL_START + 7)
+#define STR_SFX_UNDOCK (RID_SFX_SFXLOCAL_START + 8)
+#define STR_SFX_TASK_PANE_VIEW (RID_SFX_SFXLOCAL_START + 9)
+#define STR_SFX_TASKS (RID_SFX_SFXLOCAL_START + 10)
+
+// Controls --------------------------------------------------------------
+
+#define SFX_CB_PROPERTY_NAME (RID_SFX_SFXLOCAL_START + 0)
+#define SFX_ED_PROPERTY_VALUE (RID_SFX_SFXLOCAL_START + 1)
+#define SFX_RB_PROPERTY_YES (RID_SFX_SFXLOCAL_START + 2)
+#define SFX_RB_PROPERTY_NO (RID_SFX_SFXLOCAL_START + 3)
+#define SFX_LB_PROPERTY_TYPE (RID_SFX_SFXLOCAL_START + 4)
+#define SFX_PB_PROPERTY_REMOVE (RID_SFX_SFXLOCAL_START + 5)
+#define SFX_WIN_PROPERTY_YESNO (RID_SFX_SFXLOCAL_START + 6)
+#define SFX_QB_WRONG_TYPE (RID_SFX_SFXLOCAL_START + 7)
+#define SFX_FLD_DATE (RID_SFX_SFXLOCAL_START + 10)
+#define SFX_FLD_TIME (RID_SFX_SFXLOCAL_START + 11)
+#define SFX_FLD_DURATION (RID_SFX_SFXLOCAL_START + 12)
+#define SFX_ST_DURATION_FORMAT (RID_SFX_SFXLOCAL_START + 13)
+
+// Images ----------------------------------------------------------------
+
+#define SFX_IMG_PROPERTY_REMOVE (RID_SFX_SFXLOCAL_START + 0)
+#define SFX_IMG_PROPERTY_REMOVE_HC (RID_SFX_SFXLOCAL_START + 1)
+#define SFX_IMG_CLOSE_DOC (RID_SFX_SFXLOCAL_START + 2)
+#define SFX_IMG_CLOSE_DOC_HC (RID_SFX_SFXLOCAL_START + 3)
+
+#endif
+
diff --git a/sfx2/source/inc/sfxpicklist.hxx b/sfx2/source/inc/sfxpicklist.hxx
new file mode 100644
index 000000000000..8b5069f20296
--- /dev/null
+++ b/sfx2/source/inc/sfxpicklist.hxx
@@ -0,0 +1,86 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_PICKLIST_HXX_
+#define _SFX_PICKLIST_HXX_
+
+#include <osl/mutex.hxx>
+#include <tools/string.hxx>
+#include <vcl/menu.hxx>
+#include <svl/lstner.hxx>
+#include <com/sun/star/util/XStringWidth.hpp>
+
+#include <vector>
+
+#define PICKLIST_MAXSIZE 100
+
+class SfxPickList : public SfxListener
+{
+ struct PickListEntry
+ {
+ PickListEntry( const String& _aName, const String& _aFilter, const String& _aTitle ) :
+ aName( _aName ), aFilter( _aFilter ), aTitle( _aTitle ) {}
+
+ String aName;
+ String aFilter;
+ String aTitle;
+ String aOptions;
+ };
+
+ static SfxPickList* pUniqueInstance;
+ static osl::Mutex* pMutex;
+
+ std::vector< PickListEntry* > m_aPicklistVector;
+ sal_uInt32 m_nAllowedMenuSize;
+ ::com::sun::star::uno::Reference< ::com::sun::star::util::XStringWidth > m_xStringLength;
+
+ SfxPickList( sal_uInt32 nMenuSize );
+ ~SfxPickList();
+
+ static osl::Mutex* GetOrCreateMutex();
+
+ void CreatePicklistMenuTitle( Menu* pMenu, USHORT nItemId, const String& aURL, sal_uInt32 nNo );
+ PickListEntry* GetPickListEntry( sal_uInt32 nIndex );
+ void CreatePickListEntries();
+ void RemovePickListEntries();
+
+ public:
+ static SfxPickList* GetOrCreate( const sal_uInt32 nMenuSize );
+ static SfxPickList* Get();
+ static void Delete();
+
+ sal_uInt32 GetAllowedMenuSize() { return m_nAllowedMenuSize; }
+ sal_uInt32 GetNumOfEntries() const { return m_aPicklistVector.size(); }
+ void CreateMenuEntries( Menu* pMenu );
+ void ExecuteMenuEntry( USHORT nId );
+ void ExecuteEntry( sal_uInt32 nIndex );
+ String GetMenuEntryTitle( sal_uInt32 nIndex );
+
+ virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
+};
+
+#endif // _SFX_PICKLIST_HXX_
diff --git a/sfx2/source/inc/sfxtypes.hxx b/sfx2/source/inc/sfxtypes.hxx
new file mode 100644
index 000000000000..73014121541e
--- /dev/null
+++ b/sfx2/source/inc/sfxtypes.hxx
@@ -0,0 +1,199 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_SFXTYPES_HXX
+#define _SFX_SFXTYPES_HXX
+
+#include <tools/debug.hxx>
+#ifndef _RC_HXX //autogen
+#include <tools/rc.hxx>
+#endif
+#ifndef _RCID_H //autogen
+#include <tools/rcid.h>
+#endif
+#ifndef _RESID_HXX //autogen
+#include <tools/resid.hxx>
+#endif
+#include <tools/link.hxx>
+#ifndef _APP_HXX //autogen
+#include <vcl/svapp.hxx>
+#endif
+#include <vcl/wrkwin.hxx>
+
+#ifndef _VOS_MUTEX_HXX //autogen
+#include <vos/mutex.hxx>
+#endif
+
+#ifndef DELETEZ
+#define DELETEZ(pPtr) ( delete pPtr, pPtr = 0 )
+#endif
+
+#ifndef DELETEX
+#ifdef DBG_UTIL
+#define DELETEX(pPtr) ( delete pPtr, (void*&) pPtr = (void*) 0xFFFFFFFF )
+#else
+#define DELETEX(pPtr) delete pPtr
+#endif
+#endif
+
+class SfxShell;
+class Timer;
+
+#if !defined(_SFX_APPCTOR_CXX) && defined(WNT)
+#ifndef _DLL_
+#error _DLL_ mal wieder nicht defined => GetpApp() == 0
+#endif
+#endif
+
+//------------------------------------------------------------------------
+
+// Macro fuer den Call-Profiler unter WinNT
+// mit S_CAP kann eine Messung gestarted, mit E_CAP wieder gestoppt werden
+#if defined( WNT ) && defined( PROFILE )
+
+extern "C" {
+ void StartCAP();
+ void StopCAP();
+ void DumpCAP();
+};
+
+#define S_CAP() StartCAP();
+#define E_CAP() StopCAP(); DumpCAP();
+
+struct _Capper
+{
+ _Capper() { S_CAP(); }
+ ~_Capper() { E_CAP(); }
+};
+
+#define CAP _Capper _aCap_
+
+#else
+
+#define S_CAP()
+#define E_CAP()
+#define CAP
+
+#endif
+
+#ifdef DBG_UTIL
+#ifndef DBG
+#define DBG(statement) statement
+#endif
+#define DBG_OUTF(x) DbgOutf x
+#else
+#ifndef DBG
+#define DBG(statement)
+#endif
+#define DBG_OUTF(x)
+#endif
+
+#define TRIM(s) s.EraseLeadingChars().EraseTrailingChars()
+
+//------------------------------------------------------------------------
+
+String SfxShellIdent_Impl( const SfxShell *pSh );
+
+//------------------------------------------------------------------------
+
+#if defined(DBG_UTIL) && ( defined(WNT) || defined(OS2) )
+
+class SfxStack
+{
+ static unsigned nLevel;
+
+public:
+ SfxStack( const char *pName )
+ {
+ ++nLevel;
+ DbgOutf( "STACK: enter %3d %s", nLevel, pName );
+ }
+ ~SfxStack()
+ {
+ DbgOutf( "STACK: leave %3d", nLevel );
+ --nLevel;
+ }
+};
+
+#define SFX_STACK(s) SfxStack aSfxStack_( #s )
+#else
+#define SFX_STACK(s)
+#endif
+
+//------------------------------------------------------------------------
+
+String SearchAndReplace( const String &rSource,
+ const String &rToReplace,
+ const String &rReplacement );
+
+#define SFX_PASSWORD_CODE "_:;*\x9A?()/&[&"
+String SfxStringEncode( const String &rSource,
+ const char *pKey = SFX_PASSWORD_CODE );
+String SfxStringDecode( const String &rSource,
+ const char *pKey = SFX_PASSWORD_CODE );
+
+
+struct StringList_Impl : private Resource
+{
+
+ ResId aResId;
+
+ StringList_Impl( const ResId& rErrIdP, USHORT nId)
+ : Resource( rErrIdP ),aResId(nId, *rErrIdP.GetResMgr()){}
+ ~StringList_Impl() { FreeResource(); }
+
+ String GetString(){ return String( aResId ); }
+ operator BOOL(){return IsAvailableRes(aResId.SetRT(RSC_STRING));}
+
+};
+
+#define SFX_DEL_PTRARR(pArr) \
+ { \
+ for ( USHORT n = (pArr)->Count(); n--; ) \
+ delete (pArr)->GetObject(n); \
+ DELETEX(pArr); \
+ }
+
+class SfxBoolResetter
+{
+ BOOL& _rVar;
+ BOOL _bOld;
+
+public:
+ SfxBoolResetter( BOOL &rVar )
+ : _rVar( rVar ),
+ _bOld( rVar )
+ {}
+
+ ~SfxBoolResetter()
+ { _rVar = _bOld; }
+};
+
+#define GPF() *(int*)0 = 0
+
+#endif // #ifndef _SFX_SFXTYPES_HXX
+
+
diff --git a/sfx2/source/inc/sfxurlrelocator.hxx b/sfx2/source/inc/sfxurlrelocator.hxx
new file mode 100644
index 000000000000..8acc674b3568
--- /dev/null
+++ b/sfx2/source/inc/sfxurlrelocator.hxx
@@ -0,0 +1,54 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_SFXURLRELOCATOR_HXX_
+#define _SFX_SFXURLRELOCATOR_HXX_
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
+
+#include <rtl/ustring.hxx>
+#include <osl/mutex.hxx>
+
+class SfxURLRelocator_Impl
+{
+ ::osl::Mutex maMutex;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxFactory;
+ ::com::sun::star::uno::Reference< ::com::sun::star::util::XOfficeInstallationDirectories > mxOfficeInstDirs;
+
+public:
+ static bool propertyCanContainOfficeDir( const rtl::OUString & rPropName );
+ void initOfficeInstDirs();
+ void makeRelocatableURL( rtl::OUString & rURL );
+ void makeAbsoluteURL( rtl::OUString & rURL );
+
+ SfxURLRelocator_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory );
+ ~SfxURLRelocator_Impl();
+};
+
+#endif
+
diff --git a/sfx2/source/inc/slotserv.hxx b/sfx2/source/inc/slotserv.hxx
new file mode 100644
index 000000000000..9b0a8e94733c
--- /dev/null
+++ b/sfx2/source/inc/slotserv.hxx
@@ -0,0 +1,84 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFXSLOTSERV_HXX
+#define _SFXSLOTSERV_HXX
+
+#include <tools/solar.h>
+
+class SfxSlot;
+
+class SfxSlotServer
+{
+private:
+ const SfxSlot* _pSlot;
+ USHORT _nShellLevel;
+
+public:
+ SfxSlotServer( const SfxSlot &rSlot, USHORT nShell );
+ SfxSlotServer();
+
+ USHORT GetShellLevel() const;
+ void SetShellLevel(USHORT nLevel) { _nShellLevel = nLevel; }
+ void SetSlot(const SfxSlot* pSlot) {
+ _pSlot = pSlot;
+ }
+ const SfxSlot* GetSlot() const;
+ void Invalidate() { _pSlot = 0; }
+};
+
+//--------------------------------------------------------------------
+
+inline SfxSlotServer::SfxSlotServer( const SfxSlot &rSlot, USHORT nShell ):
+ _pSlot( &rSlot),
+ _nShellLevel( nShell )
+{
+}
+
+//--------------------------------------------------------------------
+
+inline SfxSlotServer::SfxSlotServer():
+ _pSlot(0),
+ _nShellLevel(0)
+{
+}
+
+//--------------------------------------------------------------------
+
+inline USHORT SfxSlotServer::GetShellLevel() const
+{
+ return _nShellLevel;
+}
+
+//--------------------------------------------------------------------
+
+inline const SfxSlot* SfxSlotServer::GetSlot() const
+{
+ return _pSlot;
+}
+
+
+#endif
diff --git a/sfx2/source/inc/splitwin.hxx b/sfx2/source/inc/splitwin.hxx
new file mode 100644
index 000000000000..5105d27dd536
--- /dev/null
+++ b/sfx2/source/inc/splitwin.hxx
@@ -0,0 +1,133 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFXSPLITWIN_HXX
+#define _SFXSPLITWIN_HXX
+
+#ifndef _SPLITWIN_HXX //autogen
+#include <vcl/splitwin.hxx>
+#endif
+#include <sfx2/childwin.hxx>
+
+class SfxWorkWindow;
+class SfxDockingWindow;
+class SfxDockArr_Impl;
+class SfxEmptySplitWin_Impl;
+struct SfxDock_Impl;
+
+class SfxSplitWindow : public SplitWindow
+{
+friend class SfxEmptySplitWin_Impl;
+
+private:
+ SfxChildAlignment eAlign;
+ SfxWorkWindow* pWorkWin;
+ SfxDockArr_Impl* pDockArr;
+ BOOL bLocked;
+ BOOL bPinned;
+ SfxEmptySplitWin_Impl* pEmptyWin;
+ SfxDockingWindow* pActive;
+
+ void InsertWindow_Impl( SfxDock_Impl* pDockWin,
+ const Size& rSize,
+ USHORT nLine,
+ USHORT nPos,
+ BOOL bNewLine=FALSE );
+
+ DECL_LINK( TimerHdl, Timer* );
+ BOOL CursorIsOverRect( BOOL bForceAdding = FALSE ) const;
+ void SetPinned_Impl( BOOL );
+ void SetFadeIn_Impl( BOOL );
+ void SaveConfig_Impl();
+ void FadeOut_Impl();
+
+protected:
+
+ virtual void StartSplit();
+ virtual void SplitResize();
+ virtual void Split();
+ virtual void Command ( const CommandEvent& rCEvt );
+ virtual void MouseButtonDown ( const MouseEvent& );
+
+public:
+ SfxSplitWindow( Window* pParent, SfxChildAlignment eAl,
+ SfxWorkWindow *pW, BOOL bWithButtons,
+ WinBits nBits = WB_BORDER | WB_SIZEABLE | WB_3DLOOK );
+
+ ~SfxSplitWindow();
+
+ void ReleaseWindow_Impl(SfxDockingWindow *pWin, BOOL bSaveConfig=TRUE);
+
+ void InsertWindow( SfxDockingWindow* pDockWin,
+ const Size& rSize);
+
+ void InsertWindow( SfxDockingWindow* pDockWin,
+ const Size& rSize,
+ USHORT nLine,
+ USHORT nPos,
+ BOOL bNewLine=FALSE );
+
+ void MoveWindow( SfxDockingWindow* pDockWin,
+ const Size& rSize,
+ USHORT nLine,
+ USHORT nPos,
+ BOOL bNewLine=FALSE );
+
+ void RemoveWindow( SfxDockingWindow* pDockWin, BOOL bHide=TRUE);
+
+ void Lock( BOOL bLock=TRUE )
+ {
+ bLocked = bLock;
+ SetUpdateMode( !bLock );
+ }
+ using Window::IsLocked;
+ BOOL IsLocked() const { return bLocked; }
+ BOOL GetWindowPos( const SfxDockingWindow* pWindow,
+ USHORT& rLine, USHORT& rPos ) const;
+ BOOL GetWindowPos( const Point& rTestPos,
+ USHORT& rLine, USHORT& rPos ) const;
+ USHORT GetLineCount() const;
+ long GetLineSize( USHORT ) const;
+ USHORT GetWindowCount(USHORT nLine) const;
+ USHORT GetWindowCount() const;
+
+ BOOL IsPinned() const { return bPinned; }
+ BOOL IsFadeIn() const;
+ BOOL IsAutoHide( BOOL bSelf = FALSE ) const;
+ SplitWindow* GetSplitWindow();
+
+ virtual void AutoHide();
+ virtual void FadeOut();
+ virtual void FadeIn();
+ void Show_Impl();
+ void Pin_Impl( BOOL bPinned );
+ BOOL ActivateNextChild_Impl( BOOL bForward = TRUE );
+ void SetActiveWindow_Impl( SfxDockingWindow* pWin );
+};
+
+#endif // #ifndef _SFXSPLITWIN_HXX
+
+
diff --git a/sfx2/source/inc/statcach.hxx b/sfx2/source/inc/statcach.hxx
new file mode 100644
index 000000000000..03b0d72dac61
--- /dev/null
+++ b/sfx2/source/inc/statcach.hxx
@@ -0,0 +1,182 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFXSTATCACH_HXX
+#define _SFXSTATCACH_HXX
+
+#include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XStatusListener.hpp>
+#include <com/sun/star/frame/FrameSearchFlag.hpp>
+#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
+#include <com/sun/star/frame/FeatureStateEvent.hpp>
+#include <com/sun/star/frame/DispatchDescriptor.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <cppuhelper/weak.hxx>
+
+#ifndef _SFXBINDINGS_HXX
+#include <sfx2/bindings.hxx>
+#endif
+
+#ifndef _SFXMSGSERV_HXX
+#include "slotserv.hxx"
+#endif
+
+#include <sfx2/sfxuno.hxx>
+
+class SfxControllerItem;
+class SfxDispatcher;
+class BindDispatch_Impl : public ::com::sun::star::frame::XStatusListener ,
+ public ::com::sun::star::lang::XTypeProvider ,
+ public ::cppu::OWeakObject
+{
+friend class SfxStateCache;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp;
+ ::com::sun::star::util::URL aURL;
+ ::com::sun::star::frame::FeatureStateEvent aStatus;
+ SfxStateCache* pCache;
+ const SfxSlot* pSlot;
+
+public:
+ BindDispatch_Impl(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > & rDisp,
+ const ::com::sun::star::util::URL& rURL,
+ SfxStateCache* pStateCache, const SfxSlot* pSlot );
+
+ SFX_DECL_XINTERFACE_XTYPEPROVIDER
+
+ virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
+
+ void Release();
+ const ::com::sun::star::frame::FeatureStateEvent& GetStatus() const;
+ void Dispatch( com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aProps, sal_Bool bForceSynchron = sal_False );
+};
+
+class SfxStateCache
+{
+friend class BindDispatch_Impl;
+ BindDispatch_Impl* pDispatch;
+ sal_uInt16 nId; // Slot-Id
+ SfxControllerItem* pInternalController;
+ com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > xMyDispatch;
+ SfxControllerItem* pController; // Ptr auf 1. gebundenen Controller (untereinander verkettet)
+ SfxSlotServer aSlotServ; // SlotServer, SlotPtr = 0 -> Nicht auf Stack
+ SfxPoolItem* pLastItem; // zuletzt verschicktes Item, nie -1
+ SfxItemState eLastState; // zuletzt verschickter State
+ sal_Bool bCtrlDirty:1; // Controller aktualisiert?
+ sal_Bool bSlotDirty:1; // Funktion gfs. vorhanden, muss aktualisiert werden
+ sal_Bool bItemVisible:1;// item visibility
+ sal_Bool bItemDirty; // G"ultigkeit von pLastItem
+
+private:
+ SfxStateCache( const SfxStateCache& rOrig ); // n.i.
+ void SetState_Impl( SfxItemState, const SfxPoolItem*, BOOL bMaybeDirty=FALSE );
+
+public:
+ SfxStateCache( sal_uInt16 nFuncId );
+ ~SfxStateCache();
+
+ sal_uInt16 GetId() const;
+
+ const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & xProv );
+ const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat )
+ { return GetSlotServer( rDispat, ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > () ); }
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > GetDispatch() const;
+ void Dispatch( const SfxItemSet* pSet, sal_Bool bForceSynchron = sal_False );
+ sal_Bool IsControllerDirty() const
+ { return bCtrlDirty ? sal_True : sal_False; }
+ SfxPoolItem* GetItem() const { return pLastItem; }
+ void ClearCache();
+
+ void SetState( SfxItemState, const SfxPoolItem*, BOOL bMaybeDirty=FALSE );
+ void SetCachedState(BOOL bAlways = FALSE);
+ void DeleteFloatingWindows();
+ void Invalidate( sal_Bool bWithSlot );
+ void SetVisibleState( BOOL bShow=TRUE );
+
+ SfxControllerItem* ChangeItemLink( SfxControllerItem* pNewBinding );
+ SfxControllerItem* GetItemLink() const;
+ void SetInternalController( SfxControllerItem* pCtrl )
+ { DBG_ASSERT( !pInternalController, "Only one internal controller allowed!" ); pInternalController = pCtrl; }
+ void ReleaseInternalController() { pInternalController = 0; }
+ SfxControllerItem* GetInternalController() const { return pInternalController; }
+ com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >
+ GetInternalDispatch() const
+ { return xMyDispatch; }
+ void SetInternalDispatch( const com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >& rDisp )
+ { xMyDispatch = rDisp; }
+};
+
+//--------------------------------------------------------------------
+
+// checks wheather this function is in the stack of active SfxObjectInterface
+
+//inline sal_Bool SfxStateCache::IsCallable( SfxDispatcher &rDispat )
+//{
+// return GetSlotServer(rDispat) != 0;
+//}
+//--------------------------------------------------------------------
+
+// clears Cached-Item
+
+inline void SfxStateCache::ClearCache()
+{
+ bItemDirty = sal_True;
+}
+
+//--------------------------------------------------------------------
+
+// registeres a item representing this function
+
+inline SfxControllerItem* SfxStateCache::ChangeItemLink( SfxControllerItem* pNewBinding )
+{
+ SfxControllerItem* pOldBinding = pController;
+ pController = pNewBinding;
+ if ( pNewBinding )
+ {
+ bCtrlDirty = sal_True;
+ bItemDirty = sal_True;
+ }
+ return pOldBinding;
+}
+//--------------------------------------------------------------------
+
+// returns the func binding which becomes called on spreading states
+
+inline SfxControllerItem* SfxStateCache::GetItemLink() const
+{
+ return pController;
+}
+//--------------------------------------------------------------------
+
+inline sal_uInt16 SfxStateCache::GetId() const
+{
+ return nId;
+}
+
+#endif
diff --git a/sfx2/source/inc/templdgi.hxx b/sfx2/source/inc/templdgi.hxx
new file mode 100644
index 000000000000..116f56163681
--- /dev/null
+++ b/sfx2/source/inc/templdgi.hxx
@@ -0,0 +1,394 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_TEMPDLGI_HXX
+#define _SFX_TEMPDLGI_HXX
+
+class SfxTemplateControllerItem;
+
+#ifndef _BUTTON_HXX //autogen
+#include <vcl/button.hxx>
+#endif
+#ifndef _TOOLBOX_HXX //autogen
+#include <vcl/toolbox.hxx>
+#endif
+#ifndef _LSTBOX_HXX //autogen
+#include <vcl/lstbox.hxx>
+#endif
+#include <svl/lstner.hxx>
+#include <svtools/svtreebx.hxx>
+#include <svl/eitem.hxx>
+
+#define _SVSTDARR_USHORTS
+#include <svl/svstdarr.hxx> // SvUShorts
+
+#include <rsc/rscsfx.hxx>
+#include <tools/rtti.hxx>
+
+#include <sfx2/childwin.hxx>
+#include <sfx2/templdlg.hxx>
+
+class SfxStyleFamilies;
+class SfxStyleFamilyItem;
+class SfxTemplateItem;
+class SfxBindings;
+class SfxStyleSheetBasePool;
+class SvTreeListBox ;
+class StyleTreeListBox_Impl;
+class SfxTemplateDialog_Impl;
+class SfxCommonTemplateDialog_Impl;
+class SfxTemplateDialogWrapper;
+class SfxDockingWindow;
+
+namespace com { namespace sun { namespace star { namespace frame { class XModuleManager; } } } }
+
+// class DropListBox_Impl ------------------------------------------------
+
+class DropListBox_Impl : public SvTreeListBox
+{
+private:
+ DECL_LINK( OnAsyncExecuteDrop, SvLBoxEntry* );
+ DECL_LINK( OnAsyncExecuteError, void* );
+
+protected:
+ SfxCommonTemplateDialog_Impl* pDialog;
+ USHORT nModifier;
+
+public:
+ DropListBox_Impl( Window* pParent, const ResId& rId, SfxCommonTemplateDialog_Impl* pD ) :
+ SvTreeListBox( pParent, rId ), pDialog( pD ) {}
+ DropListBox_Impl( Window* pParent, WinBits nWinBits, SfxCommonTemplateDialog_Impl* pD ) :
+ SvTreeListBox( pParent, nWinBits ), pDialog( pD ) {}
+
+ virtual void MouseButtonDown( const MouseEvent& rMEvt );
+ virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
+ using SvLBox::ExecuteDrop;
+ virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );
+
+ USHORT GetModifier() const { return nModifier; }
+
+ virtual long Notify( NotifyEvent& rNEvt );
+};
+
+// class SfxActionListBox ------------------------------------------------
+
+class SfxActionListBox : public DropListBox_Impl
+{
+protected:
+public:
+ SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinBits );
+ SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent, const ResId &rResId );
+
+ virtual PopupMenu* CreateContextMenu( void );
+};
+
+// class SfxCommonTemplateDialog_Impl ------------------------------------
+
+struct Deleted
+{
+ bool bDead;
+
+ Deleted() : bDead(false) {}
+
+ inline bool operator()() { return bDead; }
+};
+
+class SfxCommonTemplateDialog_Impl : public SfxListener
+{
+private:
+ class ISfxTemplateCommon_Impl : public ISfxTemplateCommon
+ {
+ private:
+ SfxCommonTemplateDialog_Impl* pDialog;
+ public:
+ ISfxTemplateCommon_Impl( SfxCommonTemplateDialog_Impl* pDialogP ) : pDialog( pDialogP ) {}
+ virtual SfxStyleFamily GetActualFamily() const { return pDialog->GetActualFamily(); }
+ virtual String GetSelectedEntry() const { return pDialog->GetSelectedEntry(); }
+ };
+
+ ISfxTemplateCommon_Impl aISfxTemplateCommon;
+
+ void ReadResource();
+ void ClearResource();
+
+protected:
+#define MAX_FAMILIES 5
+#define COUNT_BOUND_FUNC 13
+
+#define UPDATE_FAMILY_LIST 0x0001
+#define UPDATE_FAMILY 0x0002
+
+ friend class DropListBox_Impl;
+ friend class SfxTemplateControllerItem;
+ friend class SfxTemplateDialogWrapper;
+
+ SfxBindings* pBindings;
+ SfxTemplateControllerItem* pBoundItems[COUNT_BOUND_FUNC];
+
+ Window* pWindow;
+ SfxModule* pModule;
+ Timer* pTimer;
+
+ ResId* m_pStyleFamiliesId;
+ SfxStyleFamilies* pStyleFamilies;
+ SfxTemplateItem* pFamilyState[MAX_FAMILIES];
+ SfxStyleSheetBasePool* pStyleSheetPool;
+ SvTreeListBox* pTreeBox;
+ SfxObjectShell* pCurObjShell;
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager >
+ xModuleManager;
+ Deleted* pbDeleted;
+
+ SfxActionListBox aFmtLb;
+ ListBox aFilterLb;
+ Size aSize;
+
+ USHORT nActFamily; // Id in der ToolBox = Position - 1
+ USHORT nActFilter; // FilterIdx
+ USHORT nAppFilter; // Filter, den die Applikation gesetzt hat (fuer automatisch)
+
+ BOOL bDontUpdate :1,
+ bIsWater :1,
+ bEnabled :1,
+ bUpdate :1,
+ bUpdateFamily :1,
+ bCanEdit :1,
+ bCanDel :1,
+ bCanNew :1,
+ bWaterDisabled :1,
+ bNewByExampleDisabled :1,
+ bUpdateByExampleDisabled:1,
+ bTreeDrag :1,
+ bHierarchical :1,
+ bBindingUpdate :1;
+
+ DECL_LINK( FilterSelectHdl, ListBox * );
+ DECL_LINK( FmtSelectHdl, SvTreeListBox * );
+ DECL_LINK( ApplyHdl, Control * );
+ DECL_LINK( DropHdl, StyleTreeListBox_Impl * );
+ DECL_LINK( TimeOut, Timer * );
+
+
+ virtual void EnableItem( USHORT /*nMesId*/, BOOL /*bCheck*/ = TRUE ) {}
+ virtual void CheckItem( USHORT /*nMesId*/, BOOL /*bCheck*/ = TRUE ) {}
+ virtual BOOL IsCheckedItem( USHORT /*nMesId*/ ) { return TRUE; }
+ virtual void LoadedFamilies() {}
+ virtual void Update() { UpdateStyles_Impl(UPDATE_FAMILY_LIST); }
+ virtual void InvalidateBindings();
+ virtual void InsertFamilyItem( USHORT nId, const SfxStyleFamilyItem* pIten ) = 0;
+ virtual void EnableFamilyItem( USHORT nId, BOOL bEnabled = TRUE ) = 0;
+ virtual void ClearFamilyList() = 0;
+ virtual void ReplaceUpdateButtonByMenu();
+
+ void NewHdl( void* );
+ void EditHdl( void* );
+ void DeleteHdl( void* );
+
+ BOOL Execute_Impl( USHORT nId, const String& rStr, const String& rRefStr,
+ USHORT nFamily, USHORT nMask = 0,
+ USHORT* pIdx = NULL, const USHORT* pModifier = NULL );
+
+ void UpdateStyles_Impl(USHORT nFlags);
+ const SfxStyleFamilyItem* GetFamilyItem_Impl() const;
+ BOOL IsInitialized() { return nActFamily != 0xffff; }
+ void ResetFocus();
+ void EnableDelete();
+ void Initialize();
+
+ void FilterSelect( USHORT nFilterIdx, BOOL bForce = FALSE );
+ void SetFamilyState( USHORT nSlotId, const SfxTemplateItem* );
+ void SetWaterCanState( const SfxBoolItem* pItem );
+
+ void SelectStyle( const String& rStyle );
+ BOOL HasSelectedStyle() const;
+ void FillTreeBox();
+ void Update_Impl();
+ void UpdateFamily_Impl();
+
+ // In welchem FamilyState muss ich nachsehen, um die Info der i-ten
+ // Family in der pStyleFamilies zu bekommen.
+ USHORT StyleNrToInfoOffset( USHORT i );
+ USHORT InfoOffsetToStyleNr( USHORT i );
+
+ void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
+
+ void FamilySelect( USHORT nId );
+ void SetFamily( USHORT nId );
+ void ActionSelect( USHORT nId );
+
+ sal_Int32 LoadFactoryStyleFilter( SfxObjectShell* i_pObjSh );
+ void SaveFactoryStyleFilter( SfxObjectShell* i_pObjSh, sal_Int32 i_nFilter );
+
+public:
+ TYPEINFO();
+
+ SfxCommonTemplateDialog_Impl( SfxBindings* pB, SfxDockingWindow* );
+ SfxCommonTemplateDialog_Impl( SfxBindings* pB, ModalDialog* );
+ ~SfxCommonTemplateDialog_Impl();
+
+ DECL_LINK( MenuSelectHdl, Menu * );
+
+ virtual void EnableEdit( BOOL b = TRUE ) { bCanEdit = b; }
+ virtual void EnableDel( BOOL b = TRUE ) { bCanDel = b; }
+ virtual void EnableNew( BOOL b = TRUE ) { bCanNew = b; }
+
+ ISfxTemplateCommon* GetISfxTemplateCommon() { return &aISfxTemplateCommon; }
+ Window* GetWindow() { return pWindow; }
+
+ void EnableTreeDrag( BOOL b = TRUE );
+ void ExecuteContextMenu_Impl( const Point& rPos, Window* pWin );
+ void EnableExample_Impl( USHORT nId, BOOL bEnable );
+ SfxStyleFamily GetActualFamily() const;
+ String GetSelectedEntry() const;
+ SfxObjectShell* GetObjectShell() const { return pCurObjShell; }
+
+ virtual void PrepareDeleteAction(); // disable buttons, change button text, etc. when del is going to happen
+
+ inline BOOL CanEdit( void ) const { return bCanEdit; }
+ inline BOOL CanDel( void ) const { return bCanDel; }
+ inline BOOL CanNew( void ) const { return bCanNew; }
+
+ // normaly for derivates from SvTreeListBoxes, but in this case the dialog handles context menus
+ virtual PopupMenu* CreateContextMenu( void );
+
+ // Rechnet von den SFX_STYLE_FAMILY Ids auf 1-5 um
+ static USHORT SfxFamilyIdToNId( SfxStyleFamily nFamily );
+
+ void SetAutomaticFilter();
+};
+/* -----------------10.12.2003 11:42-----------------
+
+ --------------------------------------------------*/
+
+class DropToolBox_Impl : public ToolBox, public DropTargetHelper
+{
+ SfxTemplateDialog_Impl& rParent;
+protected:
+ virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
+ virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );
+public:
+ DropToolBox_Impl(Window* pParent, SfxTemplateDialog_Impl* pTemplateDialog);
+ ~DropToolBox_Impl();
+};
+// class SfxTemplateDialog_Impl ------------------------------------------
+
+class SfxTemplateDialog_Impl : public SfxCommonTemplateDialog_Impl
+{
+private:
+ friend class SfxTemplateControllerItem;
+ friend class SfxTemplateDialogWrapper;
+ friend class DropToolBox_Impl;
+
+ SfxTemplateDialog* m_pFloat;
+ BOOL m_bZoomIn;
+ DropToolBox_Impl m_aActionTbL;
+ ToolBox m_aActionTbR;
+
+ DECL_LINK( ToolBoxLSelect, ToolBox * );
+ DECL_LINK( ToolBoxRSelect, ToolBox * );
+ DECL_LINK( ToolBoxRClick, ToolBox * );
+ DECL_LINK( MenuSelectHdl, Menu* );
+
+protected:
+ virtual void Command( const CommandEvent& rMEvt );
+ virtual void EnableEdit( BOOL = TRUE );
+ virtual void EnableItem( USHORT nMesId, BOOL bCheck = TRUE );
+ virtual void CheckItem( USHORT nMesId, BOOL bCheck = TRUE );
+ virtual BOOL IsCheckedItem( USHORT nMesId );
+ virtual void LoadedFamilies();
+ virtual void InsertFamilyItem( USHORT nId, const SfxStyleFamilyItem* pIten );
+ virtual void EnableFamilyItem( USHORT nId, BOOL bEnabled = TRUE );
+ virtual void ClearFamilyList();
+ virtual void ReplaceUpdateButtonByMenu();
+
+ void Resize();
+ Size GetMinOutputSizePixel();
+
+ void updateFamilyImages();
+ void updateNonFamilyImages();
+
+public:
+ friend class SfxTemplateDialog;
+ TYPEINFO();
+
+ SfxTemplateDialog_Impl( Window* pParent, SfxBindings*, SfxTemplateDialog* pWindow );
+ ~SfxTemplateDialog_Impl();
+};
+
+// class SfxTemplateCatalog_Impl -----------------------------------------
+
+class SfxTemplateCatalog_Impl : public SfxCommonTemplateDialog_Impl
+{
+private:
+ friend class SfxTemplateControllerItem;
+ friend class SfxCommonTemplateDialog_Impl;
+
+ ListBox aFamList;
+ OKButton aOkBtn;
+ CancelButton aCancelBtn;
+ PushButton aNewBtn;
+ PushButton aChangeBtn;
+ PushButton aDelBtn;
+ PushButton aOrgBtn;
+ HelpButton aHelpBtn;
+
+ SfxTemplateCatalog* pReal;
+ SvUShorts aFamIds;
+ SfxModalDefParentHelper aHelper;
+
+protected:
+ virtual void EnableItem( USHORT nMesId, BOOL bCheck = TRUE );
+ virtual void CheckItem( USHORT nMesId, BOOL bCheck = TRUE );
+ virtual BOOL IsCheckedItem( USHORT nMesId );
+ virtual void InsertFamilyItem( USHORT nId, const SfxStyleFamilyItem* pIten );
+ virtual void EnableFamilyItem( USHORT nId, BOOL bEnabled = TRUE );
+ virtual void ClearFamilyList();
+ virtual void EnableEdit( BOOL = TRUE );
+ virtual void EnableDel( BOOL = TRUE );
+ virtual void EnableNew( BOOL = TRUE );
+
+ using SfxCommonTemplateDialog_Impl::NewHdl;
+ DECL_LINK( FamListSelect, ListBox * );
+ DECL_LINK( OkHdl, Button * );
+ DECL_LINK( CancelHdl, Button * );
+ DECL_LINK( NewHdl, Button * );
+ DECL_LINK( ChangeHdl, Button * );
+ DECL_LINK( DelHdl, Button * );
+ DECL_LINK( OrgHdl, Button * );
+
+public:
+ TYPEINFO();
+ SfxTemplateCatalog_Impl( Window* pParent, SfxBindings*, SfxTemplateCatalog* pWindow );
+ ~SfxTemplateCatalog_Impl();
+
+friend class SfxTemplateCatalog;
+
+ virtual void PrepareDeleteAction();
+};
+
+#endif // #ifndef _SFX_TEMPDLGI_HXX
+
+
diff --git a/sfx2/source/inc/tplcitem.hxx b/sfx2/source/inc/tplcitem.hxx
new file mode 100644
index 000000000000..f97d7f89868c
--- /dev/null
+++ b/sfx2/source/inc/tplcitem.hxx
@@ -0,0 +1,52 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _TPLCITEM_HXX
+#define _TPLCITEM_HXX
+
+#include <sfx2/ctrlitem.hxx>
+#include <tools/link.hxx>
+
+class SfxCommonTemplateDialog_Impl;
+
+class SfxTemplateControllerItem: public SfxControllerItem {
+ SfxCommonTemplateDialog_Impl &rTemplateDlg;
+ BYTE nWaterCanState;
+ long nUserEventId;
+
+ DECL_STATIC_LINK(SfxTemplateControllerItem, SetWaterCanStateHdl_Impl,
+ SfxTemplateControllerItem*);
+
+protected:
+ virtual void StateChanged( USHORT, SfxItemState, const SfxPoolItem* pState );
+
+public:
+ SfxTemplateControllerItem( USHORT nId, SfxCommonTemplateDialog_Impl &rDlg, SfxBindings &);
+ ~SfxTemplateControllerItem();
+};
+
+
+#endif
diff --git a/sfx2/source/inc/tplcomp.hxx b/sfx2/source/inc/tplcomp.hxx
new file mode 100644
index 000000000000..c172efb15d87
--- /dev/null
+++ b/sfx2/source/inc/tplcomp.hxx
@@ -0,0 +1,224 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _TPLCOMP_HXX
+#define _TPLCOMP_HXX
+
+#include <osl/mutex.hxx>
+//ASDBG #ifndef _USR_UNO_HXX
+//ASDBG #include <usr/uno.hxx>
+//ASDBG #endif
+//ASDBG #ifndef _USR_LSTCOMP_HXX
+//ASDBG #include <usr/iterhlp.hxx>
+//ASDBG #endif
+//ASDBG #ifndef _USR_SERVICES_HXX
+//ASDBG #include <usr/services.hxx>
+//ASDBG #endif
+#include <com/sun/star/chaos/XCommandExecutor.hpp>
+#include <com/sun/star/chaos/XStatusCallback.hpp>
+#include <com/sun/star/chaos/UnknownCommandException.hpp>
+#include <com/sun/star/chaos/StatusCallbackEvent.hpp>
+#include <com/sun/star/chaos/XURLContent.hpp>
+#include <com/sun/star/chaos/XExplorerExchange.hpp>
+#include <com/sun/star/beans/PropertyValues.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/PropertyState.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/beans/XMultiPropertySet.hpp>
+#include <com/sun/star/beans/XFastPropertySet.hpp>
+#include <com/sun/star/beans/XVetoableChangeListener.hpp>
+#include <com/sun/star/beans/XPropertyState.hpp>
+#include <com/sun/star/beans/XPropertyStateChangeListener.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/beans/XPropertiesChangeListener.hpp>
+#include <com/sun/star/beans/XPropertyChangeListener.hpp>
+#include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+#include <com/sun/star/beans/PropertyStateChangeEvent.hpp>
+#include <com/sun/star/beans/PropertyChangeEvent.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <cppuhelper/weak.hxx>
+#include <cppuhelper/interfacecontainer.hxx>
+
+class CntAnchor;
+
+class TplAnchorListener;
+
+// -----------------
+// - TplComponent -
+// -----------------
+
+class TplComponent : public ::com::sun::star::chaos::XURLContent, public ::com::sun::star::chaos::XCommandExecutor,
+ public ::com::sun::star::beans::XPropertySet, public ::com::sun::star::chaos::XExplorerExchange,
+ public ::cppu::OWeakObject, public ::com::sun::star::lang::XServiceInfo
+{
+private:
+
+ void HandleNewEvt( const ::rtl::OUString& rCommand,
+ const ::com::sun::star::uno::Any& rAny );
+ void CreatePopupMenu( ::com::sun::star::uno::Any& rAny ) const;
+
+protected:
+
+ ::rtl::OUString maURL;
+ ::rtl::OUString maName;
+ ::osl::Mutex aMutex;
+ ::cppu::OInterfaceContainerHelper maListeners;
+ TplAnchorListener* mpListener;
+ short mnOpenMode;
+
+public:
+
+ SFX_DECL_XINTERFACE_XTYPEPROVIDER_XSERVICEINFO
+
+ TplComponent();
+ ~TplComponent();
+
+ // interface ::com::sun::star::ucb::XContent
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent() throw ( ::com::sun::star::uno::RuntimeException )
+ { ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > aRef; return aRef; }
+ virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & Parent ) throw ( ::com::sun::star::uno::RuntimeException )
+ {}
+
+ // interface ::com::sun::star::chaos::XURLContent
+ virtual ::rtl::OUString SAL_CALL getURL() throw ( ::com::sun::star::uno::RuntimeException )
+ { return maURL; }
+ virtual sal_Bool SAL_CALL initialize( const ::com::sun::star::uno::Reference< ::com::sun::star::chaos::XURLContent > & aParent, const ::rtl::OUString& aURL ) throw ( ::com::sun::star::uno::RuntimeException );
+
+ // interface ::com::sun::star::chaos::XCommandExecutor
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL queryCommands() throw ( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL cancel( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rCommandId ) throw ( ::com::sun::star::uno::RuntimeException )
+ {}
+ virtual void SAL_CALL execute( const ::rtl::OUString& rCommand, const ::com::sun::star::uno::Any& rArgs,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::chaos::XStatusCallback > & rCallback ) throw ( ::com::sun::star::uno::RuntimeException );
+
+ // interface ::com::sun::star::beans::XPropertySet
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw ( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& aPropertyName ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & aListener ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & aListener ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& aPropertyName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & aListener ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& aPropertyName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & aListener ) throw ( ::com::sun::star::uno::RuntimeException );
+ // interface ::com::sun::star::chaos::XExplorerExchange
+ virtual ::com::sun::star::uno::Any SAL_CALL createDataObject( sal_uInt16& nSourceOptions ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual sal_uInt16 SAL_CALL insertDataObject( const ::com::sun::star::uno::Any& pSotDataObjectPtr,
+ sal_uInt16 nUserAction,
+ sal_uInt16 nSourceOptions ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual sal_Bool SAL_CALL queryInsertDataObject( const ::com::sun::star::uno::Any& pSotDataObjectPtr,
+ sal_uInt16 nUserAction,
+ sal_uInt16 nSourceOptions,
+ sal_uInt16& nResultingAction,
+ sal_uInt16& nDefaultAction ) throw ( ::com::sun::star::uno::RuntimeException );
+
+
+ // -------------------------------------------------------------
+
+ void CreateNewChild( CntAnchor* pAnchor,
+ const String& rTitle );
+ void RemoveChild( CntAnchor* pAnchor );
+ void StopListening( CntAnchor* pAnchor );
+ void HandleOpenEvt();
+};
+
+// ------------------------
+// - TplContentsComponent -
+// ------------------------
+
+class TplContentsListener;
+
+class TplContentsComponent : public TplComponent
+{
+private:
+ ::com::sun::star::uno::Reference< ::com::sun::star::chaos::XURLContent > _xParent;
+ TplContentsListener* _pListener;
+ SvDataObjectRef _xObject;
+ sal_uInt16 _nLayout;
+
+ void HandleOpenEvt( const ::com::sun::star::uno::Reference< ::com::sun::star::chaos::XStatusCallback > & rJob,
+ const ::com::sun::star::chaos::StatusCallbackEvent& rEvt );
+ void HandleNewEvt( const ::rtl::OUString& rCommand,
+ const ::com::sun::star::uno::Any& rAny );
+ void HandleInitEvt();
+
+ void CreateFileName( String& rName,
+ String& rDirURL );
+ void CreateNewTpl( const String& rFilter,
+ const String& rParentDir,
+ const String& rFileName,
+ const String& rDocName );
+protected:
+
+ void CreatePopupMenu( ::com::sun::star::uno::Any& rAny ) const;
+
+public:
+
+ SFX_DECL_XINTERFACE_XTYPEPROVIDER_XSERVICEINFO
+
+ TplContentsComponent();
+ ~TplContentsComponent();
+
+ virtual sal_Bool SAL_CALL initialize( const ::com::sun::star::uno::Reference< ::com::sun::star::chaos::XURLContent > & aParent, const ::rtl::OUString& aURL ) throw ( ::com::sun::star::uno::RuntimeException );
+
+
+ // interface ::com::sun::star::chaos::XCommandExecutor
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL queryCommands() throw ( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL execute( const ::rtl::OUString& rCommand, const ::com::sun::star::uno::Any& rArgs,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::chaos::XStatusCallback > & rCallback ) throw ( ::com::sun::star::uno::RuntimeException );
+
+ // interface ::com::sun::star::beans::XPropertySet
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw ( ::com::sun::star::uno::RuntimeException );
+ virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& aPropertyName ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw ( ::com::sun::star::uno::RuntimeException );
+
+ // interface ::com::sun::star::chaos::XExplorerExchange
+ virtual ::com::sun::star::uno::Any SAL_CALL createDataObject( sal_uInt16& nSourceOptions ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual sal_uInt16 SAL_CALL insertDataObject( const ::com::sun::star::uno::Any& pSotDataObjectPtr,
+ sal_uInt16 nUserAction,
+ sal_uInt16 nSourceOptions ) throw ( ::com::sun::star::uno::RuntimeException );
+ virtual sal_Bool SAL_CALL queryInsertDataObject( const ::com::sun::star::uno::Any& pSotDataObjectPtr,
+ sal_uInt16 nUserAction,
+ sal_uInt16 nSourceOptions,
+ sal_uInt16& nResultingAction,
+ sal_uInt16& nDefaultAction ) throw ( ::com::sun::star::uno::RuntimeException );
+
+ // -------------------------------------------------------------
+
+ void CreateNewChild( CntAnchor* pAnchor );
+ void HandleDeleteEvt();
+ void SetURL( const ::rtl::OUString& rURL);
+ void SetName( const ::rtl::OUString& rNewName );
+};
+
+
+#endif
+
diff --git a/sfx2/source/inc/versdlg.hxx b/sfx2/source/inc/versdlg.hxx
new file mode 100644
index 000000000000..73b686d91252
--- /dev/null
+++ b/sfx2/source/inc/versdlg.hxx
@@ -0,0 +1,109 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _VERSDLG_HXX
+#define _VERSDLG_HXX
+
+// #include *****************************************************************
+
+#ifndef _SV_BUTTON_HXX //autogen
+#include <vcl/button.hxx>
+#endif
+#include <vcl/fixed.hxx>
+#ifndef _SVTREEBOX_HXX //autogen
+#include <svtools/svtabbx.hxx>
+#endif
+#include <svtools/svmedit.hxx>
+#include <sfx2/basedlgs.hxx>
+
+class SfxObjectShell;
+class SfxViewFrame;
+struct SfxVersionInfo;
+
+class SfxVersionsTabListBox_Impl : public SvTabListBox
+{
+ virtual void KeyInput( const KeyEvent& rKeyEvent );
+
+public:
+ SfxVersionsTabListBox_Impl(
+ Window* pParent, const ResId& );
+};
+
+class SfxVersionTableDtor;
+class SfxVersionDialog : public SfxModalDialog
+{
+ FixedLine aNewGroup;
+ PushButton aSaveButton;
+ CheckBox aSaveCheckBox;
+ FixedLine aExistingGroup;
+ FixedText aDateTimeText;
+ FixedText aSavedByText;
+ FixedText aCommentText;
+ SfxVersionsTabListBox_Impl aVersionBox;
+ CancelButton aCloseButton;
+ PushButton aOpenButton;
+ PushButton aViewButton;
+ PushButton aDeleteButton;
+ PushButton aCompareButton;
+ HelpButton aHelpButton;
+ SfxViewFrame* pViewFrame;
+ SfxVersionTableDtor* mpTable;
+ LocaleDataWrapper* mpLocaleWrapper;
+ sal_Bool mbIsSaveVersionOnClose;
+
+ DECL_LINK( DClickHdl_Impl, Control* );
+ DECL_LINK( SelectHdl_Impl, Control* );
+ DECL_LINK( ButtonHdl_Impl, Button* );
+ void Init_Impl();
+ void Open_Impl();
+ void RecalcDateColumn();
+
+public:
+ SfxVersionDialog ( SfxViewFrame* pFrame, sal_Bool );
+ virtual ~SfxVersionDialog ();
+ sal_Bool IsSaveVersionOnClose() const { return mbIsSaveVersionOnClose; }
+};
+
+class SfxViewVersionDialog_Impl : public SfxModalDialog
+{
+ FixedText aDateTimeText;
+ FixedText aSavedByText;
+ MultiLineEdit aEdit;
+ OKButton aOKButton;
+ CancelButton aCancelButton;
+ PushButton aCloseButton;
+ HelpButton aHelpButton;
+ SfxVersionInfo* pInfo;
+
+ DECL_LINK( ButtonHdl, Button* );
+
+public:
+ SfxViewVersionDialog_Impl( Window *pParent,
+ SfxVersionInfo& rInfo, BOOL bEdit );
+ };
+
+#endif
diff --git a/sfx2/source/inc/virtmenu.hxx b/sfx2/source/inc/virtmenu.hxx
new file mode 100644
index 000000000000..4b000133d11c
--- /dev/null
+++ b/sfx2/source/inc/virtmenu.hxx
@@ -0,0 +1,159 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFXVIRTMENU_HXX
+#define _SFXVIRTMENU_HXX
+
+
+#include <svl/svarray.hxx>
+#include <sfx2/mnuitem.hxx>
+#include "mnucfga.hxx"
+
+class SfxBindings;
+class Timer;
+class SfxMenuImageControl_Impl;
+
+SV_DECL_PTRARR_DEL( SfxMenuCtrlArr_Impl, SfxMenuControl*, 2, 2 )
+
+class SAL_DLLPUBLIC_EXPORT SfxVirtualMenu
+{
+friend class SfxMenuControl;
+
+private:
+ Menu* pSVMenu;
+ SfxVirtualMenu* pParent;
+ SfxMenuCtrlArr_Impl* pAppCtrl;
+ SfxMenuControl* pItems;
+ SfxMenuImageControl_Impl* pImageControl;
+ SfxBindings* pBindings;
+ ResMgr* pResMgr;
+ PopupMenu* pWindowMenu;
+ PopupMenu* pPickMenu;
+ PopupMenu* pAddonsMenu;
+ Timer* pAutoDeactivate; // Hack fuer QAP-Bug
+ USHORT nVisibleItems;
+ USHORT nId;
+ USHORT nCount;
+ USHORT nLocks;
+ BOOL bResCtor : 1; // SV Menu created from resource
+ BOOL bOLE : 1; // InPlaceMenu
+ BOOL bHelpInitialized : 1;
+ BOOL bIsActive : 1;
+ BOOL bControllersUnBound : 1;
+ BOOL bWasHighContrast : 1;
+ BOOL bIsAddonPopupMenu : 1;
+
+private:
+ void Construct_Impl();
+ FASTBOOL Bind_Impl( Menu *pMenu );
+ inline SfxMenuCtrlArr_Impl& GetAppCtrl_Impl()
+ {
+ return pAppCtrl? *pAppCtrl: *(pAppCtrl = new SfxMenuCtrlArr_Impl) ;
+ }
+ void UnbindControllers();
+ void BindControllers();
+
+protected:
+ SfxVirtualMenu( USHORT nOwnId, SfxVirtualMenu* pParent, Menu& rMenu, BOOL bWithHelp,
+ SfxBindings &rBind, BOOL bOLEServer=FALSE, BOOL bRes=FALSE, BOOL bIsAddonMenu=FALSE );
+
+ void CreateFromSVMenu();
+ DECL_LINK( Highlight, Menu * );
+ DECL_LINK( Activate, Menu * );
+ DECL_LINK( Deactivate, Menu * );
+ DECL_LINK( SettingsChanged, void* );
+
+ // Used for runtime popup menus
+ void UpdateImages( Menu* pMenu );
+ void RemoveMenuImages( Menu* pMenu );
+ void InsertAddOnsMenuItem( Menu* pMenu );
+
+public:
+ ~SfxVirtualMenu();
+ SfxVirtualMenu( Menu *pStarViewMenu, BOOL bWithHelp,
+ SfxBindings &rBind, BOOL bOLEServer=FALSE, BOOL bRes=FALSE, BOOL bIsAddonMenu=FALSE );
+ void CheckItem( USHORT nItemId, BOOL bCheck );
+ void EnableItem( USHORT nItemId, BOOL bEnable );
+ void SetItemText( USHORT nItemId, const String& rText );
+
+ USHORT GetItemPos( USHORT nItemId ) const;
+
+ USHORT GetItemCount() const;
+ Menu* GetSVMenu() const;
+ SfxMenuControl& operator[]( USHORT nPos ) const;
+
+ USHORT GetItemId( USHORT nPos ) const;
+ SfxVirtualMenu* GetPopupMenu( USHORT nId ) const;
+ String GetItemText( USHORT nId ) const;
+ String GetItemHelpText( USHORT nId ) const;
+
+ //void InvalidateKeyCodes();
+
+ SfxVirtualMenu* GetParentMenu() const { return pParent; }
+ void SetParentMenu( SfxVirtualMenu* pNewParent )
+ { pParent = pNewParent; }
+
+ void SetPopupMenu( USHORT nId, PopupMenu *pMenu );
+ BOOL IsFromResource() const
+ { return bResCtor; }
+ void InitPopup(USHORT nPos, BOOL bOLE = TRUE);
+ void InitializeHelp();
+ void SetResMgr(ResMgr* pMgr) {pResMgr = pMgr; }
+ ResMgr* GetResMgr() { return pResMgr; }
+ void SetHelpIds( ResMgr* );
+ BOOL IsHiContrastMode() const;
+ void UpdateImages();
+
+ DECL_LINK( Select, Menu * );
+};
+
+//--------------------------------------------------------------------
+
+// return the number of virtual items in this menu
+
+inline USHORT SfxVirtualMenu::GetItemCount() const
+{
+ return nCount;
+}
+//--------------------------------------------------------------------
+
+//
+
+inline SfxMenuControl& SfxVirtualMenu::operator[]( USHORT nPos ) const
+{
+ return *(pItems+nPos);
+}
+//--------------------------------------------------------------------
+
+// returns the item id at position nPos in the menu (or 0 if sep.)
+
+inline USHORT SfxVirtualMenu::GetItemId( USHORT nPos ) const
+{
+ return pItems ? pItems[nPos].GetId() : 0;
+}
+
+
+#endif
diff --git a/sfx2/source/inc/workwin.hxx b/sfx2/source/inc/workwin.hxx
new file mode 100644
index 000000000000..0e263a58b90e
--- /dev/null
+++ b/sfx2/source/inc/workwin.hxx
@@ -0,0 +1,391 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFXWORKWIN_HXX
+#define _SFXWORKWIN_HXX
+
+#include <vector>
+#include <deque>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#ifndef _COM_SUN_STAR_UI_XUILEMENT_HPP_
+#include <com/sun/star/ui/XUIElement.hpp>
+#endif
+#include <com/sun/star/task/XStatusIndicator.hpp>
+#include <com/sun/star/frame/XLayoutManagerListener.hpp>
+#include <cppuhelper/weak.hxx>
+#include <cppuhelper/propshlp.hxx>
+
+#define _SVSTDARR_USHORTS
+#include <svl/svstdarr.hxx> // SvUShorts
+#include <rtl/ustring.hxx>
+#include <vos/mutex.hxx>
+
+#include <sfx2/sfx.hrc>
+#include <sfx2/childwin.hxx>
+#include <sfx2/shell.hxx>
+#include <sfx2/minarray.hxx>
+#include <sfx2/ctrlitem.hxx>
+#include <sfx2/viewfrm.hxx>
+
+class SfxInPlaceEnv_Impl;
+class SfxPlugInEnv_Impl;
+class SfxSplitWindow;
+class SfxWorkWindow;
+
+//====================================================================
+// Dieser struct h"alt alle relevanten Informationen "uber Toolboxen bereit.
+
+struct SfxObjectBar_Impl
+{
+ USHORT nId; // Resource - und ConfigId der Toolbox
+ USHORT nMode; // spezielle Sichtbarkeitsflags
+ USHORT nPos;
+ USHORT nIndex;
+ sal_Bool bDestroy;
+ String aName;
+ SfxInterface* pIFace;
+
+ SfxObjectBar_Impl() :
+ nId(0),
+ nMode(0),
+ bDestroy(sal_False),
+ pIFace(0)
+ {}
+};
+
+//------------------------------------------------------------------------------
+// Dieser struct h"alt alle relevanten Informationen "uber die Statuszeile bereit.
+struct SfxStatBar_Impl
+{
+ USHORT nId;
+ BOOL bOn;
+ BOOL bTemp;
+
+ SfxStatBar_Impl() :
+ nId(0),
+ bOn(TRUE),
+ bTemp(FALSE)
+ {}
+};
+
+//------------------------------------------------------------------------------
+
+#define CHILD_NOT_VISIBLE 0
+#define CHILD_ACTIVE 1 // nicht durch HidePopups ausgeschaltet
+#define CHILD_NOT_HIDDEN 2 // nicht durch HideChildWindow ausgeschaltet
+#define CHILD_FITS_IN 4 // nicht zu gro\s f"ur OutputSize des parent
+#define CHILD_VISIBLE (CHILD_NOT_HIDDEN | CHILD_ACTIVE | CHILD_FITS_IN)
+#define CHILD_ISVISIBLE (CHILD_NOT_HIDDEN | CHILD_ACTIVE)
+
+struct SfxChild_Impl
+{
+ Window* pWin;
+ Size aSize;
+ SfxChildAlignment eAlign;
+ USHORT nVisible;
+ BOOL bResize;
+ BOOL bCanGetFocus;
+ BOOL bSetFocus;
+
+ SfxChild_Impl( Window& rChild, const Size& rSize,
+ SfxChildAlignment eAlignment, BOOL bIsVisible ):
+ pWin(&rChild), aSize(rSize), eAlign(eAlignment), bResize(FALSE),
+ bCanGetFocus( FALSE ), bSetFocus( FALSE )
+ {
+ nVisible = bIsVisible ? CHILD_VISIBLE : CHILD_NOT_VISIBLE;
+ }
+};
+
+//--------------------------------------------------------------------
+class SfxChildWinController_Impl : public SfxControllerItem
+{
+ SfxWorkWindow* pWorkwin;
+
+ public:
+ SfxChildWinController_Impl( USHORT nId, SfxWorkWindow *pWin );
+ virtual void StateChanged( USHORT nSID, SfxItemState eState,
+ const SfxPoolItem* pState );
+};
+
+struct SfxChildWin_Impl
+{
+ USHORT nSaveId; // die ChildWindow-Id
+ USHORT nInterfaceId; // der aktuelle Context
+ USHORT nId; // aktuelle Id
+ SfxChildWindow* pWin;
+ BOOL bCreate;
+ SfxChildWinInfo aInfo;
+ SfxChild_Impl* pCli; // != 0 bei direkten Children
+ USHORT nVisibility;
+ BOOL bEnable;
+ BOOL bDisabled;
+
+ SfxChildWin_Impl( sal_uInt32 nID ) :
+ nSaveId((USHORT) (nID & 0xFFFF) ),
+ nInterfaceId((USHORT) (nID >> 16)),
+ nId(nSaveId),
+ pWin(0),
+ bCreate(FALSE),
+ pCli(0),
+ nVisibility( FALSE ),
+ bEnable( TRUE ),
+ bDisabled( FALSE )
+ {}
+};
+
+enum SfxChildIdentifier
+{
+ SFX_CHILDWIN_STATBAR,
+ SFX_CHILDWIN_OBJECTBAR,
+ SFX_CHILDWIN_DOCKINGWINDOW,
+ SFX_CHILDWIN_SPLITWINDOW
+};
+
+enum SfxDockingConfig
+{
+ SFX_SETDOCKINGRECTS,
+ SFX_ALIGNDOCKINGWINDOW,
+ SFX_TOGGLEFLOATMODE,
+ SFX_MOVEDOCKINGWINDOW
+};
+
+DECL_PTRARRAY( SfxChildList_Impl, SfxChild_Impl*, 2, 2 )
+DECL_PTRARRAY( SfxChildWindows_Impl, SfxChildWin_Impl*, 2, 2 )
+
+
+struct SfxObjectBarList_Impl
+{
+ std::deque<SfxObjectBar_Impl> aArr;
+ USHORT nAct;
+
+ SfxObjectBar_Impl operator[] ( USHORT n )
+ { return aArr[n]; }
+ SfxObjectBar_Impl Actual()
+ { return aArr[nAct]; }
+};
+
+struct SfxSplitWin_Impl
+{
+ SfxSplitWindow* pSplitWin;
+ SfxChildWindows_Impl* pChildWins;
+};
+
+#define SFX_SPLITWINDOWS_LEFT 0
+#define SFX_SPLITWINDOWS_TOP 2
+#define SFX_SPLITWINDOWS_RIGHT 1
+#define SFX_SPLITWINDOWS_BOTTOM 3
+#define SFX_SPLITWINDOWS_MAX 4
+
+//--------------------------------------------------------------------
+
+class LayoutManagerListener : public ::com::sun::star::frame::XLayoutManagerListener,
+ public ::com::sun::star::lang::XTypeProvider,
+ public ::com::sun::star::lang::XComponent,
+ public ::cppu::OWeakObject
+{
+ public:
+ LayoutManagerListener( SfxWorkWindow* pWrkWin );
+ virtual ~LayoutManagerListener();
+
+ SFX_DECL_XINTERFACE_XTYPEPROVIDER
+
+ void setFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame );
+
+ //---------------------------------------------------------------------------------------------------------
+ // XComponent
+ //---------------------------------------------------------------------------------------------------------
+ virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException );
+
+ //---------------------------------------------------------------------------------------------------------
+ // XEventListener
+ //---------------------------------------------------------------------------------------------------------
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
+
+ //---------------------------------------------------------------------------------------------------------
+ // XLayoutManagerEventListener
+ //---------------------------------------------------------------------------------------------------------
+ virtual void SAL_CALL layoutEvent( const ::com::sun::star::lang::EventObject& aSource, ::sal_Int16 eLayoutEvent, const ::com::sun::star::uno::Any& aInfo ) throw (::com::sun::star::uno::RuntimeException);
+
+ private:
+ sal_Bool m_bHasFrame;
+ SfxWorkWindow* m_pWrkWin;
+ ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > m_xFrame;
+ rtl::OUString m_aLayoutManagerPropName;
+};
+
+class SfxWorkWindow
+{
+ friend class UIElementWrapper;
+ friend class LayoutManagerListener;
+
+protected:
+ SvUShorts aSortedList;
+ SfxStatBar_Impl aStatBar;
+ std::vector< SfxObjectBar_Impl > aObjBarList;
+ Rectangle aClientArea;
+ Rectangle aUpperClientArea;
+ SfxWorkWindow* pParent;
+ SfxSplitWindow* pSplit[SFX_SPLITWINDOWS_MAX];
+ SfxChildList_Impl* pChilds;
+ SfxChildWindows_Impl* pChildWins;
+ SfxBindings* pBindings;
+ Window* pWorkWin;
+ SfxShell* pConfigShell;
+ Window* pActiveChild;
+ USHORT nUpdateMode;
+ USHORT nChilds;
+ USHORT nOrigMode;
+ BOOL bSorted : 1;
+ BOOL bDockingAllowed : 1;
+ BOOL bInternalDockingAllowed : 1;
+ BOOL bAllChildsVisible : 1;
+ BOOL bIsFullScreen : 1;
+ BOOL bShowStatusBar : 1;
+ sal_Int32 m_nLock;
+ rtl::OUString m_aStatusBarResName;
+ rtl::OUString m_aLayoutManagerPropName;
+ rtl::OUString m_aTbxTypeName;
+ rtl::OUString m_aProgressBarResName;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > m_xLayoutManagerListener;
+
+protected:
+ void CreateChildWin_Impl(SfxChildWin_Impl*,BOOL);
+ void RemoveChildWin_Impl(SfxChildWin_Impl*);
+ void Sort_Impl();
+ void AlignChild_Impl( Window& rWindow, const Size& rNewSize,
+ SfxChildAlignment eAlign );
+ SfxChild_Impl* FindChild_Impl( const Window& rWindow ) const;
+ virtual BOOL RequestTopToolSpacePixel_Impl( SvBorder aBorder );
+ virtual Rectangle GetTopRect_Impl();
+ SvBorder Arrange_Impl();
+ virtual void SaveStatus_Impl(SfxChildWindow*, const SfxChildWinInfo&);
+ static sal_Bool IsPluginMode( SfxObjectShell* pObjShell );
+
+public:
+ SfxWorkWindow( Window *pWin, SfxBindings& rBindings, SfxWorkWindow* pParent = NULL);
+ virtual ~SfxWorkWindow();
+ SystemWindow* GetTopWindow() const;
+ SfxBindings& GetBindings()
+ { return *pBindings; }
+ Window* GetWindow() const
+ { return pWorkWin; }
+ Rectangle GetFreeArea( BOOL bAutoHide ) const;
+ void SetDockingAllowed(BOOL bSet)
+ { bDockingAllowed = bSet; }
+ void SetInternalDockingAllowed(BOOL bSet)
+ { bInternalDockingAllowed = bSet; }
+ BOOL IsDockingAllowed() const
+ { return bDockingAllowed; }
+ BOOL IsInternalDockingAllowed() const
+ { return bInternalDockingAllowed; }
+ SfxWorkWindow* GetParent_Impl() const
+ { return pParent; }
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > CreateDispatch( const String& );
+
+ // Methoden f"ur alle Child-Fenster
+ void DataChanged_Impl( const DataChangedEvent& rDCEvt );
+ void ReleaseChild_Impl( Window& rWindow );
+ SfxChild_Impl* RegisterChild_Impl( Window& rWindow, SfxChildAlignment eAlign, BOOL bCanGetFocus=FALSE );
+ void ShowChilds_Impl();
+ void HideChilds_Impl();
+ void Close_Impl();
+ BOOL PrepareClose_Impl();
+ virtual void ArrangeChilds_Impl( BOOL bForce = TRUE );
+ void DeleteControllers_Impl();
+ void SaveStatus_Impl();
+ void HidePopups_Impl(BOOL bHide, BOOL bParent=FALSE, USHORT nId=0);
+ void ConfigChild_Impl(SfxChildIdentifier,
+ SfxDockingConfig, USHORT);
+ void MakeChildsVisible_Impl( BOOL bVis );
+ void ArrangeAutoHideWindows( SfxSplitWindow *pSplit );
+ BOOL IsAutoHideMode( const SfxSplitWindow *pSplit );
+ void EndAutoShow_Impl( Point aPos );
+ void SetFullScreen_Impl( BOOL bSet ) { bIsFullScreen = bSet; }
+ BOOL IsFullScreen_Impl() const { return bIsFullScreen; }
+
+ // Methoden f"ur Objectbars
+ virtual void UpdateObjectBars_Impl();
+ void ResetObjectBars_Impl();
+ void SetObjectBar_Impl( USHORT nPos, sal_uInt32 nResId,
+ SfxInterface *pIFace, const String* pName=0 );
+ Window* GetObjectBar_Impl( USHORT nPos, sal_uInt32 nResId );
+ FASTBOOL KnowsObjectBar_Impl( USHORT nPos ) const;
+ BOOL IsVisible_Impl();
+ void MakeVisible_Impl( BOOL );
+ void SetObjectBarVisibility_Impl( USHORT nVis );
+ BOOL IsContainer_Impl() const;
+ void Lock_Impl( BOOL );
+ void NextObjectBar_Impl( USHORT nPos );
+ USHORT HasNextObjectBar_Impl( USHORT nPos, String* pStr=0 );
+ void SetObjectBarCustomizeMode_Impl( BOOL );
+
+ // Methoden f"ur ChildWindows
+ void UpdateChildWindows_Impl();
+ void ResetChildWindows_Impl();
+ void SetChildWindowVisible_Impl( sal_uInt32, BOOL, USHORT );
+ void ToggleChildWindow_Impl(USHORT,BOOL);
+ BOOL HasChildWindow_Impl(USHORT);
+ BOOL KnowsChildWindow_Impl(USHORT);
+ void ShowChildWindow_Impl(USHORT, BOOL bVisible, BOOL bSetFocus);
+ void SetChildWindow_Impl(USHORT, BOOL bOn, BOOL bSetFocus);
+ SfxChildWindow* GetChildWindow_Impl(USHORT);
+ virtual void InitializeChild_Impl(SfxChildWin_Impl*);
+ SfxSplitWindow* GetSplitWindow_Impl(SfxChildAlignment);
+
+ BOOL IsVisible_Impl( USHORT nMode ) const;
+ void DisableChildWindow_Impl( USHORT nId, BOOL bDisable );
+ BOOL IsFloating( USHORT nId );
+ void ChangeWindow_Impl( Window *pNew );
+ void SetActiveChild_Impl( Window *pChild );
+ Window* GetActiveChild_Impl();
+ virtual BOOL ActivateNextChild_Impl( BOOL bForward = TRUE );
+ bool AllowChildWindowCreation_Impl( const SfxChildWin_Impl& i_rCW ) const;
+
+ // Methoden f"ur StatusBar
+ void SetTempStatusBar_Impl( BOOL bSet );
+ void ResetStatusBar_Impl();
+ void SetStatusBar_Impl(sal_uInt32 nResId, SfxShell *pShell, SfxBindings& );
+ void UpdateStatusBar_Impl();
+ ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator > GetStatusIndicator();
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > GetFrameInterface();
+};
+
+class SfxFrameWorkWin_Impl : public SfxWorkWindow
+{
+ SfxFrame* pMasterFrame;
+ SfxFrame* pFrame;
+public:
+ SfxFrameWorkWin_Impl( Window* pWin, SfxFrame* pFrm, SfxFrame* pMaster );
+ virtual void ArrangeChilds_Impl( BOOL bForce = TRUE );
+ virtual void UpdateObjectBars_Impl();
+ virtual Rectangle GetTopRect_Impl();
+};
+
+
+#endif
diff --git a/sfx2/source/inet/inettbc.cxx b/sfx2/source/inet/inettbc.cxx
new file mode 100644
index 000000000000..4ac85a7c98fe
--- /dev/null
+++ b/sfx2/source/inet/inettbc.cxx
@@ -0,0 +1,303 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "inettbc.hxx"
+
+#ifndef GCC
+#endif
+#include <com/sun/star/uno/Any.h>
+#ifndef _COM_SUN_STAR_FRAME_XFRAMESSUPLLIER_HPP_
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#endif
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <unotools/historyoptions.hxx>
+#include <svl/folderrestriction.hxx>
+#include <vcl/toolbox.hxx>
+#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
+#include <toolkit/unohlp.hxx>
+#endif
+#ifndef _VOS_THREAD_HXX //autogen
+#include <vos/thread.hxx>
+#endif
+#ifndef _VOS_MUTEX_HXX //autogen
+#include <vos/mutex.hxx>
+#endif
+#include <rtl/ustring.hxx>
+
+#include <svl/itemset.hxx>
+#include <svl/urihelper.hxx>
+#include <unotools/pathoptions.hxx>
+#include <svtools/asynclink.hxx>
+#include <svtools/inettbc.hxx>
+
+#include <unotools/localfilehelper.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include <sfx2/sfx.hrc>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/objsh.hxx>
+#include "referers.hxx"
+#include "sfxtypes.hxx"
+#include "helper.hxx"
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::task;
+
+//***************************************************************************
+// SfxURLToolBoxControl_Impl
+//***************************************************************************
+
+SFX_IMPL_TOOLBOX_CONTROL(SfxURLToolBoxControl_Impl,SfxStringItem)
+
+SfxURLToolBoxControl_Impl::SfxURLToolBoxControl_Impl( USHORT nSlotId, USHORT nId, ToolBox& rBox )
+ : SfxToolBoxControl( nSlotId, nId, rBox ),
+ pAccExec( 0 )
+{
+ addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CurrentURL" )));
+}
+
+SfxURLToolBoxControl_Impl::~SfxURLToolBoxControl_Impl()
+{
+ delete pAccExec;
+}
+
+SvtURLBox* SfxURLToolBoxControl_Impl::GetURLBox() const
+{
+ return (SvtURLBox*)GetToolBox().GetItemWindow( GetId() );
+}
+
+//***************************************************************************
+
+void SfxURLToolBoxControl_Impl::OpenURL( const String& rName, BOOL /*bNew*/ ) const
+{
+ String aName;
+ String aFilter;
+ String aOptions;
+
+ INetURLObject aObj( rName );
+ if ( aObj.GetProtocol() == INET_PROT_NOT_VALID )
+ {
+ String aBaseURL = GetURLBox()->GetBaseURL();
+ aName = SvtURLBox::ParseSmart( rName, aBaseURL, SvtPathOptions().GetWorkPath() );
+ }
+ else
+ aName = rName;
+
+ if ( !aName.Len() )
+ return;
+
+ Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY );
+ if ( xDispatchProvider.is() && m_xServiceManager.is() )
+ {
+ URL aTargetURL;
+ ::rtl::OUString aTarget( ::rtl::OUString::createFromAscii( "_default" ));
+
+ aTargetURL.Complete = aName;
+
+ getURLTransformer()->parseStrict( aTargetURL );
+ Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 );
+ if ( xDispatch.is() )
+ {
+ Sequence< PropertyValue > aArgs( 2 );
+ aArgs[0].Name = ::rtl::OUString::createFromAscii( "Referer" );
+ aArgs[0].Value = makeAny( ::rtl::OUString::createFromAscii( SFX_REFERER_USER ));
+ aArgs[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" ));
+ aArgs[1].Value = makeAny( ::rtl::OUString( aName ));
+
+ if ( aFilter.Len() )
+ {
+ aArgs.realloc( 4 );
+ aArgs[2].Name = ::rtl::OUString::createFromAscii( "FilterOptions" );
+ aArgs[2].Value = makeAny( ::rtl::OUString( aOptions ));
+ aArgs[3].Name = ::rtl::OUString::createFromAscii( "FilterName" );
+ aArgs[3].Value = makeAny( ::rtl::OUString( aFilter ));
+ }
+
+ SfxURLToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxURLToolBoxControl_Impl::ExecuteInfo;
+ pExecuteInfo->xDispatch = xDispatch;
+ pExecuteInfo->aTargetURL = aTargetURL;
+ pExecuteInfo->aArgs = aArgs;
+ Application::PostUserEvent( STATIC_LINK( 0, SfxURLToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+IMPL_STATIC_LINK_NOINSTANCE( SfxURLToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
+{
+ try
+ {
+ // Asynchronous execution as this can lead to our own destruction!
+ // Framework can recycle our current frame and the layout manager disposes all user interface
+ // elements if a component gets detached from its frame!
+ pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
+ }
+ catch ( Exception& )
+ {
+ }
+
+ delete pExecuteInfo;
+ return 0;
+}
+
+
+Window* SfxURLToolBoxControl_Impl::CreateItemWindow( Window* pParent )
+{
+ SvtURLBox* pURLBox = new SvtURLBox( pParent );
+ pURLBox->SetOpenHdl( LINK( this, SfxURLToolBoxControl_Impl, OpenHdl ) );
+ pURLBox->SetSelectHdl( LINK( this, SfxURLToolBoxControl_Impl, SelectHdl ) );
+
+ return pURLBox;
+}
+
+IMPL_LINK( SfxURLToolBoxControl_Impl, SelectHdl, void*, EMPTYARG )
+{
+ SvtURLBox* pURLBox = GetURLBox();
+ String aName( pURLBox->GetURL() );
+
+ if ( !pURLBox->IsTravelSelect() && aName.Len() )
+ OpenURL( aName, FALSE );
+
+ return 1L;
+}
+
+IMPL_LINK( SfxURLToolBoxControl_Impl, OpenHdl, void*, EMPTYARG )
+{
+ SvtURLBox* pURLBox = GetURLBox();
+ OpenURL( pURLBox->GetURL(), pURLBox->IsCtrlOpen() );
+
+ if ( m_xServiceManager.is() )
+ {
+ Reference< XFramesSupplier > xDesktop( m_xServiceManager->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" )),
+ UNO_QUERY );
+ Reference< XFrame > xFrame( xDesktop->getActiveFrame(), UNO_QUERY );
+ if ( xFrame.is() )
+ {
+ Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
+ if ( pWin )
+ {
+ pWin->GrabFocus();
+ pWin->ToTop( TOTOP_RESTOREWHENMIN );
+ }
+ }
+ }
+
+ return 1L;
+}
+
+IMPL_LINK( SfxURLToolBoxControl_Impl, WindowEventListener, VclSimpleEvent*, pEvent )
+{
+ if ( pAccExec &&
+ pEvent &&
+ pEvent->ISA( VclWindowEvent ) &&
+ ( pEvent->GetId() == VCLEVENT_WINDOW_KEYINPUT ))
+ {
+ VclWindowEvent* pWinEvent = static_cast< VclWindowEvent* >( pEvent );
+ KeyEvent* pKeyEvent = static_cast< KeyEvent* >( pWinEvent->GetData() );
+
+ pAccExec->execute( pKeyEvent->GetKeyCode() );
+ }
+
+ return 1;
+}
+
+//***************************************************************************
+
+void SfxURLToolBoxControl_Impl::StateChanged
+(
+ USHORT nSID,
+ SfxItemState eState,
+ const SfxPoolItem* pState
+)
+{
+ if ( nSID == SID_OPENURL )
+ {
+ // Disable URL box if command is disabled #111014#
+ GetURLBox()->Enable( SFX_ITEM_DISABLED != eState );
+ }
+
+ if ( GetURLBox()->IsEnabled() )
+ {
+ if( nSID == SID_FOCUSURLBOX )
+ {
+ if ( GetURLBox()->IsVisible() )
+ GetURLBox()->GrabFocus();
+ }
+ else if ( !GetURLBox()->IsModified() && SFX_ITEM_AVAILABLE == eState )
+ {
+ SvtURLBox* pURLBox = GetURLBox();
+ pURLBox->Clear();
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > lList = SvtHistoryOptions().GetList(eHISTORY);
+ for (sal_Int32 i=0; i<lList.getLength(); ++i)
+ {
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lProps = lList[i];
+ for (sal_Int32 p=0; p<lProps.getLength(); ++p)
+ {
+ if (lProps[p].Name != HISTORY_PROPERTYNAME_URL)
+ continue;
+
+ ::rtl::OUString sURL;
+ if (!(lProps[p].Value>>=sURL) || !sURL.getLength())
+ continue;
+
+ INetURLObject aURL ( sURL );
+ String sMainURL( aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET ) );
+ String sFile;
+
+ if (::utl::LocalFileHelper::ConvertURLToSystemPath(sMainURL,sFile))
+ pURLBox->InsertEntry(sFile);
+ else
+ pURLBox->InsertEntry(sMainURL);
+ }
+ }
+
+ const SfxStringItem *pURL = PTR_CAST(SfxStringItem,pState);
+ String aRep( pURL->GetValue() );
+ INetURLObject aURL( aRep );
+ INetProtocol eProt = aURL.GetProtocol();
+ if ( eProt == INET_PROT_FILE )
+ {
+ pURLBox->SetText( aURL.PathToFileName() );
+ }
+ else
+ pURLBox->SetText( aURL.GetURLNoPass() );
+ }
+ }
+}
+
diff --git a/sfx2/source/layout/factory.cxx b/sfx2/source/layout/factory.cxx
new file mode 100644
index 000000000000..e572ffb2b76e
--- /dev/null
+++ b/sfx2/source/layout/factory.cxx
@@ -0,0 +1,68 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <com/sun/star/awt/WindowAttribute.hpp>
+#include <sal/types.h>
+#include <sfx2/basedlgs.hxx>
+#include <toolkit/awt/vclxtoolkit.hxx>
+#include <toolkit/awt/vclxdialog.hxx>
+
+using rtl::OUString;
+
+class SfxModelessDialog_unprotect : public SfxModelessDialog
+{
+public:
+ SfxModelessDialog_unprotect (Window *parent, WinBits attributes);
+};
+
+SFX2_DLLPUBLIC SfxBindings* sfx2_global_bindings;
+SFX2_DLLPUBLIC SfxChildWindow* sfx2_global_child;
+
+SfxModelessDialog_unprotect::SfxModelessDialog_unprotect (Window *parent, WinBits bits)
+ : SfxModelessDialog (sfx2_global_bindings, sfx2_global_child, parent, bits)
+{
+}
+
+extern "C"
+{
+
+SAL_DLLPUBLIC_EXPORT Window* CreateWindow (VCLXWindow** vcl, OUString const& name, Window* parent, long& attributes)
+{
+ Window* window = 0;
+ if (0)
+ {
+ ;
+ }
+ else if (name.equalsAscii ("sfxmodelessdialog"))
+ {
+ window = new SfxModelessDialog_unprotect (parent, ImplGetWinBits (attributes, 0));
+ *vcl = new layoutimpl::VCLXDialog ();
+ }
+ return window;
+}
+
+}
diff --git a/sfx2/source/layout/sfxdialog.cxx b/sfx2/source/layout/sfxdialog.cxx
new file mode 100644
index 000000000000..f3a76c489b7e
--- /dev/null
+++ b/sfx2/source/layout/sfxdialog.cxx
@@ -0,0 +1,38 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#include "precompiled_sfx2.hxx"
+#include <sfx2/layout.hxx>
+
+namespace layout
+{
+
+SfxDialog::SfxDialog(::Window* parent, char const* xml_file, char const* id, SfxBindings*, SfxChildWindow*)
+ : Dialog (parent, xml_file, id)
+{
+}
+
+} // end namespace layout
diff --git a/sfx2/source/layout/sfxtabdialog.cxx b/sfx2/source/layout/sfxtabdialog.cxx
new file mode 100644
index 000000000000..7909d404b524
--- /dev/null
+++ b/sfx2/source/layout/sfxtabdialog.cxx
@@ -0,0 +1,72 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <limits.h>
+#include <stdlib.h>
+#include <vcl/msgbox.hxx>
+#include <unotools/viewoptions.hxx>
+
+#define _SVSTDARR_USHORTS
+#include <svl/svstdarr.hxx>
+
+#include "appdata.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/minarray.hxx>
+#include <sfx2/tabdlg.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/app.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "sfx2/sfxhelp.hxx"
+#include <sfx2/ctrlitem.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/sfxdlg.hxx>
+#include <sfx2/itemconnect.hxx>
+#include <layout/layout.hxx>
+
+//FIXME
+#include <toolkit/awt/vclxwindow.hxx>
+#include <com/sun/star/awt/PosSize.hpp>
+
+using namespace ::com::sun::star;
+namespace layout
+{
+using namespace ::com::sun::star;
+}
+
+#include <sfx2/layout.hxx>
+#include <layout/layout-pre.hxx>
+
+#undef TabPage
+#undef SfxTabPage
+#undef SfxTabDialog
+
+#define TabDlgCmpUS_Impl layout__TabDlgCmpUS_Impl
+
+#include "../dialog/tabdlg.cxx"
diff --git a/sfx2/source/layout/sfxtabpage.cxx b/sfx2/source/layout/sfxtabpage.cxx
new file mode 100644
index 000000000000..7df739a38bb3
--- /dev/null
+++ b/sfx2/source/layout/sfxtabpage.cxx
@@ -0,0 +1,89 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ***********************************************************************/
+
+#include <sfx2/layout.hxx>
+
+#include <com/sun/star/awt/PosSize.hpp>
+#include <toolkit/awt/vclxwindow.hxx>
+
+namespace layout
+{
+
+using namespace ::com::sun::star;
+
+#if 0
+SfxTabDialog::SfxTabDialog (::Window *parent, char const* xml_file, char const* id, ResId const& res_id, SfxItemSet const* set)
+ : ::SfxTabDialog (parent, res_id, set)
+ , InPlug (parent, xml_file, id)
+{
+}
+
+::Window* SfxTabDialog::GetParent () const
+{
+ return Window::GetParent ();
+}
+
+::Window* SfxTabDialog::GetWindow () const
+{
+ return Window::GetParent ();
+}
+
+void SfxTabDialog::FreeResource ()
+{
+ //::Window::FreeResource ();
+}
+#endif
+
+SfxTabPage::SfxTabPage (::Window *parent, char const* xml_file, char const* id, SfxItemSet const* set)
+ : ::SfxTabPage (parent, 0, *set)
+ , InPlug (parent, xml_file, id)
+{
+ dynamic_cast< ::Window* > (this)->SetComponentInterface (GetVCLXWindow ());
+}
+
+::Window* SfxTabPage::GetParent () const
+{
+ return Window::GetParent ();
+}
+
+::Window* SfxTabPage::GetWindow () const
+{
+ return ::layout::Window::GetWindow();
+}
+
+void SfxTabPage::FreeResource ()
+{
+ //::Window::FreeResource ();
+}
+
+Size SfxTabPage::GetOptimalSize (WindowSizeType) const
+{
+ awt::Size s = GetVCLXWindow()->getMinimumSize ();
+ return Size (s.Width, s.Height);
+}
+
+} // end namespace layout
diff --git a/sfx2/source/menu/menu.hrc b/sfx2/source/menu/menu.hrc
new file mode 100644
index 000000000000..b437f797c26e
--- /dev/null
+++ b/sfx2/source/menu/menu.hrc
@@ -0,0 +1,73 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _MNUCFG_HRC
+#define _MNUCFG_HRC
+
+#include <sfx2/sfx.hrc>
+
+// #defines *****************************************************************
+
+#define DLG_MENUCONFIG (RID_SFX_MENU_START+1)
+#define IBX_MNUCFG_ALREADY_INCLUDED (RID_SFX_MENU_START+2)
+#define QBX_MNUCFG_UNDEFINED_FUNCTIONS (RID_SFX_MENU_START+3)
+#define QBX_MNUCFG_POPUP_FUNCTIONS (RID_SFX_MENU_START+4)
+
+#define BTN_OK 1
+#define BTN_CANCEL 2
+#define BTN_UP 3
+#define BTN_LEFT 4
+#define BTN_RIGHT 5
+#define BTN_DOWN 6
+#define BTN_NEW 7
+#define BTN_CHANGE 8
+#define BTN_REMOVE 9
+#define BOX_ENTRIES 10
+#define TXT_TEXT 11
+#define EDT_TEXT 12
+#define TXT_FUNCTIONTEXT 13
+#define TXT_FUNCTIONINFO 14
+#define TXT_DESCRIPTIONTEXT 15
+#define TXT_DESCRIPTIONINFO 16
+#define GRP_MENU 17
+#define TXT_GROUP 18
+#define BOX_GROUP 19
+#define TXT_FUNCTION 20
+#define BOX_FUNCTION 21
+#define GRP_FUNCTIONS 22
+
+#define STR_MENU_CFGITEM RID_SFX_MENU_START+1
+#define STR_MENU_ADDONS RID_SFX_MENU_START+2
+#define STR_MENU_ADDONHELP RID_SFX_MENU_START+3
+
+#define STR_MENU_SYNONYMS (RID_SFX_MENU_START+11)
+#define STR_MENU_NO_SYNONYM_FOUND (RID_SFX_MENU_START+12)
+#define STR_MENU_THESAURUS (RID_SFX_MENU_START+13)
+
+#define MN_CLIPBOARDFUNCS RID_SFX_MENU_START+1
+#endif
+
diff --git a/sfx2/source/menu/menu.src b/sfx2/source/menu/menu.src
new file mode 100644
index 000000000000..5e3d8296bb59
--- /dev/null
+++ b/sfx2/source/menu/menu.src
@@ -0,0 +1,98 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "menu.hrc"
+#include <sfx2/sfxcommands.h>
+
+String STR_MENU_CFGITEM
+{
+ Text [ en-US ] = "Configuration Menu" ;
+};
+
+String STR_MENU_ADDONS
+{
+ Text [ en-US ] = "~Add-Ons" ;
+};
+
+Menu MN_CLIPBOARDFUNCS
+{
+ ItemList =
+ {
+ MenuItem
+ {
+ Identifier = SID_CUT ;
+ HelpID = CMD_SID_CUT ;
+ Text [ en-US ] = "Cu~t" ;
+ };
+ MenuItem
+ {
+ Identifier = SID_COPY ;
+ HelpID = CMD_SID_COPY ;
+ Text [ en-US ] = "~Copy" ;
+ };
+ MenuItem
+ {
+ Identifier = SID_PASTE ;
+ HelpID = CMD_SID_PASTE ;
+ Text [ en-US ] = "~Paste" ;
+ };
+ };
+};
+
+String SID_WIN_FULLSCREEN
+{
+ Text [ en-US ] = "Leave Full-Screen Mode";
+};
+
+String STR_MENU_ADDONHELP
+{
+ Text [ en-US ] = "Add-~On Help" ;
+};
+
+String STR_MENU_SYNONYMS
+{
+ Text [ en-US ] = "Synonyms" ;
+};
+
+String STR_MENU_NO_SYNONYM_FOUND
+{
+ Text [ en-US ] = "(none)" ;
+};
+
+String STR_MENU_THESAURUS
+{
+ Text [ en-US ] = "~Thesaurus..." ;
+};
+
+// ******************************************************************* EOF
+
+
+
+
+
+
+
diff --git a/sfx2/source/menu/mnuitem.cxx b/sfx2/source/menu/mnuitem.cxx
new file mode 100644
index 000000000000..f101b0d426b9
--- /dev/null
+++ b/sfx2/source/menu/mnuitem.cxx
@@ -0,0 +1,583 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifdef SOLARIS
+// HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
+#include <ctime>
+#endif
+
+#include <string> // HACK: prevent conflict between STLPORT and Workshop includes
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+#include <com/sun/star/util/XURLTransformer.hpp>
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+#include <tools/urlobj.hxx>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <svtools/imagemgr.hxx>
+#include <svtools/menuoptions.hxx>
+#include <framework/menuconfiguration.hxx>
+#ifndef GCC
+#endif
+
+#include <sfx2/app.hxx>
+#include <sfx2/sfx.hrc>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/msg.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include "idpool.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/macrconf.hxx>
+#include "virtmenu.hxx"
+#include <sfx2/mnuitem.hxx>
+#include <sfx2/tbxctrl.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/module.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "sfx2/imgmgr.hxx"
+#include "sfx2/imagemgr.hxx"
+#include "sfx2/sfxresid.hxx"
+#include "../doc/doc.hrc"
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::util;
+
+//====================================================================
+
+class SfxEnumMenu: public PopupMenu
+{
+ USHORT nSlot;
+ SfxEnumItem *pItem;
+ SfxBindings* pBindings;
+
+protected:
+ virtual void Select();
+
+public:
+ SfxEnumMenu( USHORT nSlot, SfxBindings* pBind, const SfxEnumItem &rItem );
+ ~SfxEnumMenu();
+};
+
+//=========================================================================
+
+SfxEnumMenu::SfxEnumMenu( USHORT nSlotId, SfxBindings* pBind, const SfxEnumItem &rItem ):
+ nSlot( nSlotId ),
+ pItem( (SfxEnumItem*) rItem.Clone() ),
+ pBindings( pBind )
+{
+ for ( USHORT nVal = 0; nVal < pItem->GetValueCount(); ++nVal )
+ InsertItem( nVal+1, pItem->GetValueTextByPos(nVal) );
+ CheckItem( pItem->GetValue() + 1, TRUE );
+}
+
+//-------------------------------------------------------------------------
+
+SfxEnumMenu::~SfxEnumMenu()
+{
+ delete pItem;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxEnumMenu::Select()
+{
+ pItem->SetValue( GetCurItemId()-1 );
+ pBindings->GetDispatcher()->Execute( nSlot,
+ SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD,
+ pItem, 0L, 0L );
+}
+
+//--------------------------------------------------------------------
+
+void SfxMenuControl::SetOwnMenu( SfxVirtualMenu* pMenu )
+{
+ pOwnMenu = pMenu;
+ if ( pSubMenu )
+ pSubMenu->SetParentMenu( pMenu );
+}
+
+
+//--------------------------------------------------------------------
+
+// binds the instance to the specified id and assignes the title
+
+void SfxMenuControl::Bind(
+ SfxVirtualMenu* pOwn,
+ USHORT nSlotId,
+ const String& rTitle,
+ const String &rHelpText,
+ SfxBindings &rBindings )
+{
+ DBG_MEMTEST();
+
+ aTitle = rTitle;
+ aHelpText = rHelpText;
+ pOwnMenu = pOwn;
+ pSubMenu = 0;
+ if ( pOwn )
+ SfxControllerItem::Bind(nSlotId, &rBindings);
+ else
+ SetId( nSlotId );
+
+ DBG( CheckConfigure_Impl(SFX_SLOT_MENUCONFIG) );
+}
+
+
+//--------------------------------------------------------------------
+
+// binds the item to the specified menu and assignes the title
+
+void SfxMenuControl::Bind(
+ SfxVirtualMenu* pOwn,
+ USHORT nSlotId,
+ SfxVirtualMenu& rMenu,
+ const String& rTitle,
+ const String &rHelpText,
+ SfxBindings &rBindings )
+{
+ DBG_MEMTEST();
+ SetId( nSlotId );
+ SetBindings(rBindings);
+ pOwnMenu = pOwn;
+ pSubMenu = &rMenu;
+ aTitle = rTitle;
+ aHelpText = rHelpText;
+}
+
+//--------------------------------------------------------------------
+
+// ctor for explicit registration
+
+SfxMenuControl::SfxMenuControl( BOOL bShowStrings )
+: pOwnMenu(0),
+ pSubMenu(0),
+ b_ShowStrings(bShowStrings)
+{
+ DBG_MEMTEST();
+}
+
+//--------------------------------------------------------------------
+
+// ctor for array
+
+SfxMenuControl::SfxMenuControl():
+ pOwnMenu(0),
+ pSubMenu(0),
+ b_ShowStrings(FALSE)
+{
+ DBG_MEMTEST();
+}
+
+//--------------------------------------------------------------------
+
+SfxMenuControl::SfxMenuControl(USHORT nSlotId, SfxBindings& rBindings):
+ SfxControllerItem(nSlotId, rBindings),
+ pOwnMenu(0),
+ pSubMenu(0),
+ b_ShowStrings(FALSE)
+{
+ DBG_MEMTEST();
+
+ // Dieser Ctor soll es erm"oglichen, w"ahrend der Konstruktion schon
+ // auf die Bindings zur"uckgreifen zu k"onnen, aber gebunden wird
+ // wie immer erst sp"ater. Anwendung z.B. wenn im ctor der abgeleiteten
+ // Klasse z.B. ein StatusForwarder erzeugt werden soll.
+ UnBind();
+}
+
+
+//--------------------------------------------------------------------
+
+// dtor
+
+SfxMenuControl::~SfxMenuControl()
+{
+ if ( SfxMacroConfig::IsMacroSlot( GetId() ) )
+ SFX_APP()->GetMacroConfig()->ReleaseSlotId(GetId());
+ delete pSubMenu;
+}
+
+void SfxMenuControl::RemovePopup()
+{
+ DELETEZ( pSubMenu );
+}
+
+//--------------------------------------------------------------------
+
+// changes the state in the virtual menu
+
+void SfxMenuControl::StateChanged
+(
+ USHORT nSID,
+ SfxItemState eState,
+ const SfxPoolItem* pState
+)
+{
+ (void)nSID; //unused
+ DBG_MEMTEST();
+ DBG_ASSERT( nSID == GetId(), "strange SID" );
+ DBG_ASSERT( pOwnMenu != 0, "setting state to dangling SfxMenuControl" );
+
+ FASTBOOL bIsObjMenu =
+ GetId() >= SID_OBJECTMENU0 && GetId() < SID_OBJECTMENU_LAST;
+
+ // enabled/disabled-Flag pauschal korrigieren
+
+#ifdef UNIX
+ if (nSID == SID_PASTE)
+ pOwnMenu->EnableItem( GetId(), TRUE );
+ else
+#endif
+ pOwnMenu->EnableItem( GetId(), bIsObjMenu
+ ? 0 != pOwnMenu->GetSVMenu()->GetPopupMenu( GetId() )
+ : eState != SFX_ITEM_DISABLED );
+
+ if ( eState != SFX_ITEM_AVAILABLE )
+ {
+ // checken nur bei nicht-Object-Menus
+ if ( !bIsObjMenu )
+ pOwnMenu->CheckItem( GetId(), FALSE );
+
+ // SetItemText flackert in MenuBar insbes. unter OS/2 (Bug #20658)
+ if ( // !bIsObjMenu && nicht wegen "Format/Datenbank"
+ pOwnMenu->GetSVMenu()->GetItemText( GetId() ) != GetTitle() )
+ {
+ DBG_WARNING("Title of menu item changed - please check if this needs correction!");
+ // pOwnMenu->SetItemText( GetId(), GetTitle() );
+ }
+ return;
+ }
+
+ // ggf. das alte Enum-Menu entfernen/loeschen
+ //! delete pOwnMenu->GetMenu().ChangePopupMenu( GetId(), 0 );
+
+ bool bCheck = false;
+ if ( pState->ISA(SfxBoolItem) )
+ {
+ // BoolItem fuer checken
+ DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
+ "SfxBoolItem not allowed for SID_OBJECTMENUx" );
+ bCheck = ((const SfxBoolItem*)pState)->GetValue();
+ }
+ else if ( pState->ISA(SfxEnumItemInterface) &&
+ ((SfxEnumItemInterface *)pState)->HasBoolValue() )
+ {
+ // EnumItem wie Bool behandeln
+ DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
+ "SfxEnumItem not allowed for SID_OBJECTMENUx" );
+ bCheck = ((SfxEnumItemInterface *)pState)->GetBoolValue();
+ }
+ else if ( ( b_ShowStrings || bIsObjMenu ) && pState->ISA(SfxStringItem) )
+ {
+ // MenuText aus SfxStringItem holen
+ String aStr( ((const SfxStringItem*)pState)->GetValue() );
+ if ( aStr.CompareToAscii("($1)",4) == COMPARE_EQUAL )
+ {
+ String aEntry(SfxResId(STR_UPDATEDOC));
+ aEntry += ' ';
+ aEntry += aStr.Copy(4);
+ aStr = aEntry;
+ }
+ else if ( aStr.CompareToAscii("($2)",4) == COMPARE_EQUAL )
+ {
+ String aEntry(SfxResId(STR_CLOSEDOC_ANDRETURN));
+ aEntry += aStr.Copy(4);
+ aStr = aEntry;
+ }
+
+ pOwnMenu->SetItemText( GetId(), aStr );
+ }
+
+#ifdef enum_item_menu_ok
+ else if ( aType == TYPE(SfxEnumItem) )
+ {
+ DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
+ "SfxEnumItem not allowed for SID_OBJECTMENUx" );
+ pOwnMenu->GetMenu().ChangePopupMenu( GetId(), &GetBindings(),
+ new SfxEnumMenu( GetId(), *(const SfxEnumItem*)pState ) );
+ }
+#endif
+
+ pOwnMenu->CheckItem( GetId(), bCheck );
+}
+
+//--------------------------------------------------------------------
+
+SfxMenuControl* SfxMenuControl::CreateImpl( USHORT /*nId*/, Menu& /*rMenu*/, SfxBindings& /*rBindings*/ )
+{
+ return new SfxMenuControl( TRUE );
+}
+
+//--------------------------------------------------------------------
+
+void SfxMenuControl::RegisterControl( USHORT nSlotId, SfxModule *pMod )
+{
+ RegisterMenuControl( pMod, new SfxMenuCtrlFactory(
+ SfxMenuControl::CreateImpl, TYPE(SfxStringItem), nSlotId ) );
+}
+
+//--------------------------------------------------------------------
+void SfxMenuControl::RegisterMenuControl(SfxModule* pMod, SfxMenuCtrlFactory* pFact)
+{
+ SFX_APP()->RegisterMenuControl_Impl( pMod, pFact );
+}
+
+SfxMenuControl* SfxMenuControl::CreateControl( USHORT nId, Menu &rMenu, SfxBindings &rBindings )
+{
+ TypeId aSlotType = SFX_SLOTPOOL().GetSlotType(nId);
+ if ( aSlotType )
+ {
+ SfxApplication *pApp = SFX_APP();
+ SfxDispatcher *pDisp = rBindings.GetDispatcher_Impl();
+ SfxModule *pMod = pDisp ? SfxModule::GetActiveModule( pDisp->GetFrame() ) :0;
+ if ( pMod )
+ {
+ SfxMenuCtrlFactArr_Impl *pFactories = pMod->GetMenuCtrlFactories_Impl();
+ if ( pFactories )
+ {
+ SfxMenuCtrlFactArr_Impl &rFactories = *pFactories;
+ for ( USHORT nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ if ( rFactories[nFactory]->nTypeId == aSlotType &&
+ ( ( rFactories[nFactory]->nSlotId == 0 ) ||
+ ( rFactories[nFactory]->nSlotId == nId) ) )
+ return rFactories[nFactory]->pCtor( nId, rMenu, rBindings );
+ }
+ }
+
+ SfxMenuCtrlFactArr_Impl &rFactories = pApp->GetMenuCtrlFactories_Impl();
+
+ for ( USHORT nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ if ( rFactories[nFactory]->nTypeId == aSlotType &&
+ ( ( rFactories[nFactory]->nSlotId == 0 ) ||
+ ( rFactories[nFactory]->nSlotId == nId) ) )
+ return rFactories[nFactory]->pCtor( nId, rMenu, rBindings );
+ }
+ return 0;
+}
+
+BOOL SfxMenuControl::IsSpecialControl( USHORT nId, SfxModule* pMod )
+{
+ TypeId aSlotType = SFX_SLOTPOOL().GetSlotType( nId );
+ if ( aSlotType )
+ {
+ if ( pMod )
+ {
+ SfxMenuCtrlFactArr_Impl *pFactories = pMod->GetMenuCtrlFactories_Impl();
+ if ( pFactories )
+ {
+ SfxMenuCtrlFactArr_Impl &rFactories = *pFactories;
+ for ( USHORT nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ if ( rFactories[nFactory]->nTypeId == aSlotType &&
+ ( ( rFactories[nFactory]->nSlotId == 0 ) ||
+ ( rFactories[nFactory]->nSlotId == nId) ) )
+ return TRUE;
+ }
+ }
+
+ SfxMenuCtrlFactArr_Impl &rFactories = SFX_APP()->GetMenuCtrlFactories_Impl();
+
+ for ( USHORT nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ if ( rFactories[nFactory]->nTypeId == aSlotType &&
+ ( ( rFactories[nFactory]->nSlotId == 0 ) ||
+ ( rFactories[nFactory]->nSlotId == nId) ) )
+ return TRUE;
+ }
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+PopupMenu* SfxMenuControl::GetPopup () const
+{
+ if (GetPopupMenu())
+ return (PopupMenu*)GetPopupMenu()->GetSVMenu();
+ else
+ return 0;
+}
+
+long Select_Impl( void* pHdl, void* pVoid );
+
+SFX_IMPL_MENU_CONTROL( SfxAppMenuControl_Impl, SfxStringItem );
+
+SfxAppMenuControl_Impl::SfxAppMenuControl_Impl(
+ USHORT nPos, Menu& rMenu, SfxBindings& rBindings )
+ : SfxMenuControl( nPos, rBindings ), pMenu(0)
+{
+ String aText = rMenu.GetItemText( nPos );
+
+ // Determine the current background color setting for menus
+ const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
+ m_nSymbolsStyle = rSettings.GetSymbolsStyle();
+ m_bWasHiContrastMode = rSettings.GetHighContrastMode();
+ m_bShowMenuImages = rSettings.GetUseImagesInMenus();
+
+ Reference<com::sun::star::lang::XMultiServiceFactory> aXMultiServiceFactory(::comphelper::getProcessServiceFactory());
+ ::framework::MenuConfiguration aConf( aXMultiServiceFactory );
+ Reference<com::sun::star::frame::XFrame> aXFrame( GetBindings().GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() );
+ pMenu = aConf.CreateBookmarkMenu( aXFrame, GetId() == SID_NEWDOCDIRECT ? BOOKMARK_NEWMENU : BOOKMARK_WIZARDMENU );
+ if( pMenu )
+ {
+ pMenu->SetSelectHdl( Link( &(this->GetBindings()), Select_Impl ) );
+ pMenu->SetActivateHdl( LINK(this, SfxAppMenuControl_Impl, Activate) );
+ rMenu.SetPopupMenu( nPos, pMenu );
+ }
+}
+
+SfxAppMenuControl_Impl::~SfxAppMenuControl_Impl()
+{
+ delete pMenu;
+}
+
+IMPL_LINK( SfxAppMenuControl_Impl, Activate, Menu *, pActMenu )
+{
+ if ( pActMenu )
+ {
+ const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
+ ULONG nSymbolsStyle = rSettings.GetSymbolsStyle();
+ BOOL bIsHiContrastMode = rSettings.GetHighContrastMode();
+ BOOL bShowMenuImages = rSettings.GetUseImagesInMenus();
+
+ if (( nSymbolsStyle != m_nSymbolsStyle ) ||
+ ( bIsHiContrastMode != m_bWasHiContrastMode ) ||
+ ( bShowMenuImages != m_bShowMenuImages ))
+ {
+ m_nSymbolsStyle = nSymbolsStyle;
+ m_bWasHiContrastMode = bIsHiContrastMode;
+ m_bShowMenuImages = bShowMenuImages;
+
+ USHORT nCount = pActMenu->GetItemCount();
+ for ( USHORT nSVPos = 0; nSVPos < nCount; nSVPos++ )
+ {
+ USHORT nItemId = pActMenu->GetItemId( nSVPos );
+ if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR )
+ {
+ if ( bShowMenuImages )
+ {
+ sal_Bool bImageSet = sal_False;
+ ::rtl::OUString aImageId;
+ ::framework::MenuConfiguration::Attributes* pMenuAttributes =
+ (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nItemId );
+
+ if ( pMenuAttributes )
+ aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
+
+ if ( aImageId.getLength() > 0 )
+ {
+ Reference< ::com::sun::star::frame::XFrame > xFrame;
+ Image aImage = GetImage( xFrame, aImageId, FALSE, bIsHiContrastMode );
+ if ( !!aImage )
+ {
+ bImageSet = sal_True;
+ pActMenu->SetItemImage( nItemId, aImage );
+ }
+ }
+
+ String aCmd( pActMenu->GetItemCommand( nItemId ) );
+ if ( !bImageSet && aCmd.Len() )
+ {
+ Image aImage = SvFileInformationManager::GetImage(
+ INetURLObject(aCmd), FALSE, bIsHiContrastMode );
+ if ( !!aImage )
+ pActMenu->SetItemImage( nItemId, aImage );
+ }
+ }
+ else
+ pActMenu->SetItemImage( nItemId, Image() );
+ }
+ }
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+SfxUnoMenuControl* SfxMenuControl::CreateControl( const String& rCmd,
+ USHORT nId, Menu& rMenu, SfxBindings &rBindings, SfxVirtualMenu* pVirt )
+{
+ return new SfxUnoMenuControl( rCmd, nId, rMenu, rBindings, pVirt );
+}
+
+SfxUnoMenuControl* SfxMenuControl::CreateControl( const String& rCmd,
+ USHORT nId, Menu& rMenu, const String& sItemText, const String& sHelpText,
+ SfxBindings& rBindings, SfxVirtualMenu* pVirt)
+{
+ return new SfxUnoMenuControl( rCmd, nId, rMenu, sItemText, sHelpText, rBindings, pVirt);
+}
+
+SfxUnoMenuControl::SfxUnoMenuControl( const String& rCmd, USHORT nSlotId,
+ Menu& rMenu, SfxBindings& rBindings, SfxVirtualMenu* pVirt )
+ : SfxMenuControl( nSlotId, rBindings )
+{
+ Bind( pVirt, nSlotId, rMenu.GetItemText(nSlotId),
+ rMenu.GetHelpText(nSlotId), rBindings);
+ UnBind();
+ pUnoCtrl = new SfxUnoControllerItem( this, rBindings, rCmd );
+ pUnoCtrl->acquire();
+ pUnoCtrl->GetNewDispatch();
+}
+
+SfxUnoMenuControl::SfxUnoMenuControl(
+ const String& rCmd, USHORT nSlotId, Menu& /*rMenu*/,
+ const String& rItemText, const String& rHelpText,
+ SfxBindings& rBindings, SfxVirtualMenu* pVirt)
+ : SfxMenuControl( nSlotId, rBindings )
+{
+ Bind( pVirt, nSlotId, rItemText, rHelpText, rBindings);
+ UnBind();
+ pUnoCtrl = new SfxUnoControllerItem( this, rBindings, rCmd );
+ pUnoCtrl->acquire();
+ pUnoCtrl->GetNewDispatch();
+}
+
+SfxUnoMenuControl::~SfxUnoMenuControl()
+{
+ pUnoCtrl->UnBind();
+ pUnoCtrl->release();
+}
+
+void SfxUnoMenuControl::Select()
+{
+ pUnoCtrl->Execute();
+}
diff --git a/sfx2/source/menu/mnumgr.cxx b/sfx2/source/menu/mnumgr.cxx
new file mode 100755
index 000000000000..77dbd0dcb885
--- /dev/null
+++ b/sfx2/source/menu/mnumgr.cxx
@@ -0,0 +1,641 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <com/sun/star/embed/VerbDescriptor.hpp>
+#include <com/sun/star/embed/VerbAttributes.hpp>
+#include <com/sun/star/container/XNamed.hpp>
+
+#ifdef SOLARIS
+// HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
+#include <ctime>
+#endif
+
+#include <string> // HACK: prevent conflict between STLPORT and Workshop headers
+#include <cstdarg> // std::va_list
+
+#ifndef _POINTR_HXX //autogen
+#include <vcl/pointr.hxx>
+#endif
+#ifndef GCC
+#endif
+
+#include <unotools/streamwrap.hxx>
+#include <sfx2/objsh.hxx>
+#include <framework/menuconfiguration.hxx>
+#include <framework/addonmenu.hxx>
+#include <comphelper/processfactory.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/lingucfg.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/pathoptions.hxx>
+#include <svl/stritem.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <osl/file.hxx>
+#include <vcl/graph.hxx>
+#include <svtools/filter.hxx>
+#include <svl/lngmisc.hxx>
+
+#include <sfx2/mnumgr.hxx>
+
+#define _SVSTDARR_USHORTS
+#include <svl/svstdarr.hxx>
+#include <svtools/menuoptions.hxx>
+
+#include "virtmenu.hxx"
+#include <sfx2/msg.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/minstack.hxx>
+#include <sfx2/app.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/bindings.hxx>
+#include "mnucfga.hxx"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/macrconf.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/sfx.hrc>
+#include "menu.hrc"
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/objface.hxx>
+#include "thessubmenu.hxx"
+
+
+static const USHORT nCompatVersion = 4;
+static const USHORT nVersion = 5;
+
+// static member initialization
+PopupMenu * SfxPopupMenuManager::pStaticThesSubMenu = NULL;
+
+using namespace com::sun::star;
+
+//=========================================================================
+
+DECL_PTRSTACK(SfxMenuCfgItemArrStack, SfxMenuCfgItemArr*, 4, 4 );
+
+//-------------------------------------------------------------------------
+
+void TryToHideDisabledEntries_Impl( Menu* pMenu )
+{
+ DBG_ASSERT( pMenu, "invalid menu" );
+ if( SvtMenuOptions().IsEntryHidingEnabled() == sal_False )
+ {
+ pMenu->SetMenuFlags( pMenu->GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+SfxMenuManager::SfxMenuManager( const ResId& rResId, SfxBindings &rBindings )
+: pMenu(0),
+ pOldMenu(0),
+ pBindings(&rBindings),
+ pResMgr(rResId.GetResMgr()),
+ nType( rResId.GetId() )
+{
+ bAddClipboardFuncs = FALSE;
+ DBG_MEMTEST();
+}
+
+//--------------------------------------------------------------------
+
+SfxMenuManager::~SfxMenuManager()
+{
+ DBG_MEMTEST();
+ pBindings->ENTERREGISTRATIONS();
+ delete pMenu;
+ pBindings->LEAVEREGISTRATIONS();
+}
+
+//--------------------------------------------------------------------
+
+void SfxMenuManager::Construct( SfxVirtualMenu& rMenu )
+{
+ DBG_MEMTEST();
+ pMenu = &rMenu;
+
+ // set the handlers
+ Menu *pSvMenu = pMenu->GetSVMenu();
+ pSvMenu->SetSelectHdl( LINK(this, SfxMenuManager, Select) );
+ TryToHideDisabledEntries_Impl( pSvMenu );
+}
+
+//-------------------------------------------------------------------------
+void InsertVerbs_Impl( SfxBindings* pBindings, const com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor >& aVerbs, Menu* pMenu )
+{
+ SfxViewShell *pView = pBindings->GetDispatcher()->GetFrame()->GetViewShell();
+ if ( pView && aVerbs.getLength() )
+ {
+ SfxObjectShell* pDoc = pView->GetObjectShell();
+ pMenu->InsertSeparator();
+ USHORT nr=0;
+ for ( USHORT n = 0; n < aVerbs.getLength(); ++n )
+ {
+ // check for ReadOnly verbs
+ if ( pDoc->IsReadOnly() && !(aVerbs[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_NEVERDIRTIES) )
+ continue;
+
+ // check for verbs that shouldn't appear in the menu
+ if ( !(aVerbs[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU) )
+ continue;
+
+ // neue Id vergeben
+ USHORT nId = SID_VERB_START + nr++;
+ DBG_ASSERT(nId <= SID_VERB_END, "Zuviele Verben!");
+ if ( nId > SID_VERB_END )
+ break;
+
+ // einf"ugen
+ pMenu->InsertItem( nId, aVerbs[n].VerbName );
+ }
+ }
+}
+
+
+//--------------------------------------------------------------------
+
+
+static Image lcl_GetImageFromPngUrl( const ::rtl::OUString &rFileUrl )
+{
+ Image aRes;
+
+ ::rtl::OUString aTmp;
+ osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
+
+ Graphic aGraphic;
+ const String aFilterName( RTL_CONSTASCII_USTRINGPARAM( IMP_PNG ) );
+ if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) )
+ {
+ aRes = Image( aGraphic.GetBitmapEx() );
+ }
+ return aRes;
+}
+
+
+PopupMenu* InsertThesaurusSubmenu_Impl( SfxBindings* pBindings, Menu* pSVMenu )
+{
+ //
+ // build thesaurus sub menu if look-up string is available
+ //
+ PopupMenu* pThesSubMenu = 0;
+ SfxPoolItem *pItem = 0;
+ pBindings->QueryState( SID_THES, pItem );
+ String aThesLookUpStr;
+ SfxStringItem *pStrItem = dynamic_cast< SfxStringItem * >(pItem);
+ xub_StrLen nDelimPos = STRING_LEN;
+ if (pStrItem)
+ {
+ aThesLookUpStr = pStrItem->GetValue();
+ nDelimPos = aThesLookUpStr.SearchBackward( '#' );
+ }
+ if (aThesLookUpStr.Len() > 0 && nDelimPos != STRING_NOTFOUND)
+ {
+ // get synonym list for sub menu
+ std::vector< ::rtl::OUString > aSynonyms;
+ SfxThesSubMenuHelper aHelper;
+ ::rtl::OUString aText( aHelper.GetText( aThesLookUpStr, nDelimPos ) );
+ lang::Locale aLocale;
+ aHelper.GetLocale( aLocale, aThesLookUpStr, nDelimPos );
+ const bool bHasMoreSynonyms = aHelper.GetMeanings( aSynonyms, aText, aLocale, 7 /*max number of synonyms to retrieve*/ );
+ (void) bHasMoreSynonyms;
+
+ pThesSubMenu = new PopupMenu;
+ pThesSubMenu->SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
+ const size_t nNumSynonyms = aSynonyms.size();
+ if (nNumSynonyms > 0)
+ {
+ SvtLinguConfig aCfg;
+ const bool bHC = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
+
+ Image aImage;
+ String sThesImplName( aHelper.GetThesImplName( aLocale ) );
+ ::rtl::OUString aSynonymsImageUrl( aCfg.GetSynonymsContextImage( sThesImplName, bHC ) );
+ if (sThesImplName.Len() > 0 && aSynonymsImageUrl.getLength() > 0)
+ aImage = Image( lcl_GetImageFromPngUrl( aSynonymsImageUrl ) );
+
+ for (USHORT i = 0; (size_t)i < nNumSynonyms; ++i)
+ {
+ //! item ids should start with values > 0, since 0 has special meaning
+ const USHORT nId = i + 1;
+
+ String aItemText( linguistic::GetThesaurusReplaceText( aSynonyms[i] ) );
+ pThesSubMenu->InsertItem( nId, aItemText );
+ ::rtl::OUString aCmd( ::rtl::OUString::createFromAscii( ".uno:ThesaurusFromContext?WordReplace:string=" ) );
+ aCmd += aItemText;
+ pThesSubMenu->SetItemCommand( nId, aCmd );
+
+ if (aSynonymsImageUrl.getLength() > 0)
+ pThesSubMenu->SetItemImage( nId, aImage );
+ }
+ }
+ else // nNumSynonyms == 0
+ {
+ const String aItemText( SfxResId( STR_MENU_NO_SYNONYM_FOUND ) );
+ pThesSubMenu->InsertItem( 1, aItemText, MIB_NOSELECT );
+ }
+ pThesSubMenu->InsertSeparator();
+ const String sThesaurus( SfxResId( STR_MENU_THESAURUS ) );
+ pThesSubMenu->InsertItem( 100, sThesaurus );
+ pThesSubMenu->SetItemCommand( 100, ::rtl::OUString::createFromAscii( ".uno:ThesaurusDialog" ) );
+
+ pSVMenu->InsertSeparator();
+ const String sSynonyms( SfxResId( STR_MENU_SYNONYMS ) );
+ pSVMenu->InsertItem( SID_THES, sSynonyms );
+ pSVMenu->SetPopupMenu( SID_THES, pThesSubMenu );
+ }
+
+ return pThesSubMenu;
+}
+
+
+//--------------------------------------------------------------------
+
+void SfxMenuManager::UseDefault()
+{
+ DBG_MEMTEST();
+
+ SFX_APP();
+ SfxVirtualMenu *pOldVirtMenu=0;
+ if (pMenu)
+ {
+ pOldVirtMenu = pMenu;
+ pBindings->ENTERREGISTRATIONS();
+ }
+
+ SfxVirtualMenu *pVMenu = 0;
+ {
+ ResId aResId(GetType(),*pResMgr);
+ aResId.SetRT(RSC_MENU);
+ Menu *pSVMenu = new PopupMenu( aResId );
+ //SfxMenuManager::EraseItemCmds( pSVMenu ); // Remove .uno cmds to be compatible with 6.0/src641
+
+ if ( bAddClipboardFuncs )
+ {
+ USHORT n, nCount = pSVMenu->GetItemCount();
+ for ( n=0; n<nCount; n++ )
+ {
+ USHORT nId = pSVMenu->GetItemId( n );
+ if ( nId == SID_COPY || nId == SID_CUT || nId == SID_PASTE )
+ break;
+ }
+
+ if ( n == nCount )
+ {
+ PopupMenu aPop( SfxResId( MN_CLIPBOARDFUNCS ) );
+ nCount = aPop.GetItemCount();
+ pSVMenu->InsertSeparator();
+ for ( n=0; n<nCount; n++ )
+ {
+ USHORT nId = aPop.GetItemId( n );
+ pSVMenu->InsertItem( nId, aPop.GetItemText( nId ), aPop.GetItemBits( nId ) );
+ }
+ }
+ }
+
+ pVMenu = new SfxVirtualMenu( pSVMenu, FALSE, *pBindings, TRUE, TRUE );
+ }
+
+ Construct(*pVMenu);
+ if (pOldVirtMenu)
+ {
+ delete pOldVirtMenu;
+ pBindings->LEAVEREGISTRATIONS();
+ }
+}
+
+// ------------------------------------------------------------------------
+
+// executes the function for the selected item
+IMPL_LINK( SfxMenuManager, Select, Menu *, pSelMenu )
+{
+ DBG_MEMTEST();
+
+ USHORT nId = (USHORT) pSelMenu->GetCurItemId();
+ String aCommand = pSelMenu->GetItemCommand( nId );
+ if ( !aCommand.Len() && pBindings )
+ {
+ const SfxSlot* pSlot = SfxSlotPool::GetSlotPool( pBindings->GetDispatcher()->GetFrame() ).GetSlot( nId );
+ if ( pSlot && pSlot->pUnoName )
+ {
+ aCommand = DEFINE_CONST_UNICODE(".uno:");
+ aCommand += String::CreateFromAscii( pSlot->GetUnoName() );
+ }
+ }
+
+ if ( aCommand.Len() )
+ {
+ pBindings->ExecuteCommand_Impl( aCommand );
+ }
+ else if ( pBindings->IsBound(nId) )
+ // normal function
+ pBindings->Execute( nId );
+ else
+ // special menu function
+ pBindings->GetDispatcher_Impl()->Execute( nId );
+
+ return TRUE;
+}
+
+//--------------------------------------------------------------------
+
+void SfxMenuManager::Construct_Impl( Menu* pSVMenu, BOOL bWithHelp )
+{
+ SfxVirtualMenu *pOldVirtMenu=0;
+ if ( pMenu )
+ {
+ // Es wird umkonfiguriert
+ pOldVirtMenu = pMenu;
+ pBindings->ENTERREGISTRATIONS();
+ }
+
+ TryToHideDisabledEntries_Impl( pSVMenu );
+ SfxVirtualMenu *pVMenu = new SfxVirtualMenu( pSVMenu, bWithHelp, *pBindings, TRUE );
+ Construct(*pVMenu);
+
+ if ( pOldVirtMenu )
+ {
+ delete pOldVirtMenu;
+ pBindings->LEAVEREGISTRATIONS();
+ }
+}
+
+//--------------------------------------------------------------------
+
+// don't insert Popups into ConfigManager, they are not configurable at the moment !
+SfxPopupMenuManager::SfxPopupMenuManager(const ResId& rResId, SfxBindings &rBindings )
+ : SfxMenuManager( rResId, rBindings )
+ , pSVMenu( NULL )
+{
+ DBG_MEMTEST();
+}
+
+SfxPopupMenuManager::~SfxPopupMenuManager()
+{
+}
+
+//-------------------------------------------------------------------------
+
+void SfxPopupMenuManager::RemoveDisabledEntries()
+{
+ if ( pSVMenu )
+ TryToHideDisabledEntries_Impl( pSVMenu );
+}
+
+//--------------------------------------------------------------------
+
+USHORT SfxPopupMenuManager::Execute( const Point& rPos, Window* pWindow )
+{
+ DBG_MEMTEST();
+ USHORT nVal = ( (PopupMenu*) GetMenu()->GetSVMenu() )->Execute( pWindow, rPos );
+ delete pStaticThesSubMenu; pStaticThesSubMenu = NULL;
+ return nVal;
+}
+
+//--------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxPopupMenuManager, SelectHdl, void *, EMPTYARG )
+{
+ return 1;
+}
+IMPL_LINK_INLINE_END( SfxPopupMenuManager, SelectHdl, void *, EMPTYARG )
+
+
+//--------------------------------------------------------------------
+
+USHORT SfxPopupMenuManager::Execute( const Point& rPoint, Window* pWindow, va_list pArgs, const SfxPoolItem *pArg1 )
+{
+ DBG_MEMTEST();
+
+ PopupMenu* pPopMenu = ( (PopupMenu*)GetMenu()->GetSVMenu() );
+ pPopMenu->SetSelectHdl( LINK( this, SfxPopupMenuManager, SelectHdl ) );
+ USHORT nId = pPopMenu->Execute( pWindow, rPoint );
+ pPopMenu->SetSelectHdl( Link() );
+
+ if ( nId )
+ GetBindings().GetDispatcher()->_Execute( nId, SFX_CALLMODE_RECORD, pArgs, pArg1 );
+
+ return nId;
+}
+
+//--------------------------------------------------------------------
+
+USHORT SfxPopupMenuManager::Execute( const Point& rPoint, Window* pWindow, const SfxPoolItem *pArg1, ... )
+{
+ DBG_MEMTEST();
+
+ va_list pArgs;
+ va_start(pArgs, pArg1);
+
+ return (Execute( rPoint, pWindow, pArgs, pArg1 ));
+}
+
+//-------------------------------------------------------------------------
+
+void SfxPopupMenuManager::StartInsert()
+{
+ ResId aResId(GetType(),*pResMgr);
+ aResId.SetRT(RSC_MENU);
+ pSVMenu = new PopupMenu( aResId );
+ TryToHideDisabledEntries_Impl( pSVMenu );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxPopupMenuManager::EndInsert()
+{
+ pBindings->ENTERREGISTRATIONS();
+ pMenu = new SfxVirtualMenu( pSVMenu, FALSE, *pBindings, TRUE, TRUE );
+ Construct( *pMenu );
+ pBindings->LEAVEREGISTRATIONS();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxPopupMenuManager::InsertSeparator( USHORT nPos )
+{
+ pSVMenu->InsertSeparator( nPos );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxPopupMenuManager::InsertItem( USHORT nId, const String& rName, MenuItemBits nBits, const rtl::OString& rHelpId, USHORT nPos )
+{
+ pSVMenu->InsertItem( nId, rName, nBits,nPos );
+ pSVMenu->SetHelpId( nId, rHelpId );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxPopupMenuManager::RemoveItem( USHORT nId )
+{
+ pSVMenu->RemoveItem( nId );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxPopupMenuManager::CheckItem( USHORT nId, BOOL bCheck )
+{
+ pSVMenu->CheckItem( nId, bCheck );
+}
+
+void SfxPopupMenuManager::AddClipboardFunctions()
+{
+ bAddClipboardFuncs = TRUE;
+}
+
+SfxMenuManager::SfxMenuManager( Menu* pMenuArg, SfxBindings &rBindings )
+: pMenu(0),
+ pOldMenu(0),
+ pBindings(&rBindings),
+ pResMgr(NULL),
+ nType(0)
+{
+ bAddClipboardFuncs = FALSE;
+ SfxVirtualMenu* pVMenu = new SfxVirtualMenu( pMenuArg, FALSE, rBindings, TRUE, TRUE );
+ Construct(*pVMenu);
+}
+
+SfxPopupMenuManager::SfxPopupMenuManager( PopupMenu* pMenuArg, SfxBindings& rBindings )
+ : SfxMenuManager( pMenuArg, rBindings )
+ , pSVMenu( pMenuArg )
+{
+}
+
+SfxPopupMenuManager* SfxPopupMenuManager::Popup( const ResId& rResId, SfxViewFrame* pFrame,const Point& rPoint, Window* pWindow )
+{
+ PopupMenu *pSVMenu = new PopupMenu( rResId );
+ USHORT n, nCount = pSVMenu->GetItemCount();
+ for ( n=0; n<nCount; n++ )
+ {
+ USHORT nId = pSVMenu->GetItemId( n );
+ if ( nId == SID_COPY || nId == SID_CUT || nId == SID_PASTE )
+ break;
+ }
+
+ PopupMenu* pThesSubMenu = InsertThesaurusSubmenu_Impl( &pFrame->GetBindings(), pSVMenu );
+ // #i107205# (see comment in header file)
+ pStaticThesSubMenu = pThesSubMenu;
+
+ if ( n == nCount )
+ {
+ PopupMenu aPop( SfxResId( MN_CLIPBOARDFUNCS ) );
+ nCount = aPop.GetItemCount();
+ pSVMenu->InsertSeparator();
+ for ( n=0; n<nCount; n++ )
+ {
+ USHORT nId = aPop.GetItemId( n );
+ pSVMenu->InsertItem( nId, aPop.GetItemText( nId ), aPop.GetItemBits( nId ) );
+ pSVMenu->SetHelpId( nId, aPop.GetHelpId( nId ));
+ }
+ }
+
+ InsertVerbs_Impl( &pFrame->GetBindings(), pFrame->GetViewShell()->GetVerbs(), pSVMenu );
+ Menu* pMenu = NULL;
+ ::com::sun::star::ui::ContextMenuExecuteEvent aEvent;
+ aEvent.SourceWindow = VCLUnoHelper::GetInterface( pWindow );
+ aEvent.ExecutePosition.X = rPoint.X();
+ aEvent.ExecutePosition.Y = rPoint.Y();
+ ::rtl::OUString sDummyMenuName;
+ if ( pFrame->GetViewShell()->TryContextMenuInterception( *pSVMenu, sDummyMenuName, pMenu, aEvent ) )
+ {
+ if ( pMenu )
+ {
+ delete pSVMenu;
+ pSVMenu = (PopupMenu*) pMenu;
+ }
+
+ SfxPopupMenuManager* aMgr = new SfxPopupMenuManager( pSVMenu, pFrame->GetBindings());
+ aMgr->RemoveDisabledEntries();
+ return aMgr;
+ }
+
+ return 0;
+}
+
+
+void SfxPopupMenuManager::ExecutePopup( const ResId& rResId, SfxViewFrame* pFrame, const Point& rPoint, Window* pWindow )
+{
+ PopupMenu *pSVMenu = new PopupMenu( rResId );
+ USHORT n, nCount = pSVMenu->GetItemCount();
+ for ( n=0; n<nCount; n++ )
+ {
+ USHORT nId = pSVMenu->GetItemId( n );
+ if ( nId == SID_COPY || nId == SID_CUT || nId == SID_PASTE )
+ break;
+ }
+
+ PopupMenu* pThesSubMenu = InsertThesaurusSubmenu_Impl( &pFrame->GetBindings(), pSVMenu );
+
+ if ( n == nCount )
+ {
+ PopupMenu aPop( SfxResId( MN_CLIPBOARDFUNCS ) );
+ nCount = aPop.GetItemCount();
+ pSVMenu->InsertSeparator();
+ for ( n=0; n<nCount; n++ )
+ {
+ USHORT nId = aPop.GetItemId( n );
+ pSVMenu->InsertItem( nId, aPop.GetItemText( nId ), aPop.GetItemBits( nId ) );
+ pSVMenu->SetHelpId( nId, aPop.GetHelpId( nId ));
+ }
+ }
+
+ InsertVerbs_Impl( &pFrame->GetBindings(), pFrame->GetViewShell()->GetVerbs(), pSVMenu );
+ Menu* pMenu = NULL;
+ ::com::sun::star::ui::ContextMenuExecuteEvent aEvent;
+ aEvent.SourceWindow = VCLUnoHelper::GetInterface( pWindow );
+ aEvent.ExecutePosition.X = rPoint.X();
+ aEvent.ExecutePosition.Y = rPoint.Y();
+ ::rtl::OUString sDummyMenuName;
+ if ( pFrame->GetViewShell()->TryContextMenuInterception( *pSVMenu, sDummyMenuName, pMenu, aEvent ) )
+ {
+ if ( pMenu )
+ {
+ delete pSVMenu;
+ pSVMenu = (PopupMenu*) pMenu;
+ }
+
+ SfxPopupMenuManager aPop( pSVMenu, pFrame->GetBindings() );
+ aPop.RemoveDisabledEntries();
+ aPop.Execute( rPoint, pWindow );
+
+ // #i112646 avoid crash when context menu is closed.
+ // the (manually inserted) sub-menu needs to be destroyed before
+ // aPop gets destroyed.
+ delete pThesSubMenu;
+ pThesSubMenu = 0;
+ }
+
+ delete pThesSubMenu;
+}
+
+Menu* SfxPopupMenuManager::GetSVMenu()
+{
+ return (Menu*) GetMenu()->GetSVMenu();
+}
+
diff --git a/sfx2/source/menu/objmnctl.cxx b/sfx2/source/menu/objmnctl.cxx
new file mode 100644
index 000000000000..e9d609151504
--- /dev/null
+++ b/sfx2/source/menu/objmnctl.cxx
@@ -0,0 +1,165 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/embed/VerbDescriptor.hpp>
+#include <com/sun/star/embed/VerbAttributes.hpp>
+
+#include <tools/list.hxx>
+#ifndef _MENU_HXX //autogen
+#include <vcl/menu.hxx>
+#endif
+#ifndef _SXSTRITEM_HXX //autogen
+#include <svl/stritem.hxx>
+#endif
+#ifndef GCC
+#endif
+
+#include <sfx2/sfxsids.hrc>
+#include "objmnctl.hxx"
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/objsh.hxx>
+
+// STATIC DATA -----------------------------------------------------------
+
+SFX_IMPL_MENU_CONTROL(SfxObjectVerbsControl, SfxStringItem);
+
+using namespace com::sun::star;
+//--------------------------------------------------------------------
+
+/*
+ Ctor; setzt Select-Handler am Menu und traegt Menu
+ in seinen Parent ein.
+ */
+
+SfxObjectVerbsControl::SfxObjectVerbsControl(USHORT nSlotId, Menu &rMenu, SfxBindings &rBindings)
+ : SfxMenuControl( nSlotId, rBindings )
+ , pMenu(new PopupMenu)
+ , rParent(rMenu)
+{
+ rMenu.SetPopupMenu(nSlotId, pMenu);
+ pMenu->SetSelectHdl(LINK(this, SfxObjectVerbsControl, MenuSelect));
+ FillMenu();
+}
+
+//--------------------------------------------------------------------
+
+/*
+ Fuellt das Menu mit den aktuellen Verben aus der ViewShell.
+ */
+
+void SfxObjectVerbsControl::FillMenu()
+{
+ pMenu->Clear();
+ SfxViewShell *pView = GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
+ if (pView)
+ {
+ SfxObjectShell* pDoc = pView->GetObjectShell();
+ const com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor >& aVerbs = pView->GetVerbs();
+ if ( aVerbs.getLength() )
+ {
+ USHORT nSlotId = SID_VERB_START;
+ for (USHORT n=0; n<aVerbs.getLength(); n++)
+ {
+ // check for ReadOnly verbs
+ if ( pDoc->IsReadOnly() && !(aVerbs[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_NEVERDIRTIES) )
+ continue;
+
+ // check for verbs that shouldn't appear in the menu
+ if ( !(aVerbs[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU) )
+ continue;
+
+ DBG_ASSERT(nSlotId <= SID_VERB_END, "Zuviele Verben!");
+ if (nSlotId > SID_VERB_END)
+ break;
+
+ pMenu->InsertItem(nSlotId++, aVerbs[n].VerbName);
+ }
+ }
+ }
+
+ rParent.EnableItem( GetId(), (BOOL)pMenu->GetItemCount() );
+}
+
+//--------------------------------------------------------------------
+
+/*
+ Statusbenachrichtigung;
+ fuellt gfs. das Menu mit den aktuellen Verben aus der ViewShell.
+ der DocumentShell.
+ Ist die Funktionalit"at disabled, wird der entsprechende
+ Menueeintrag im Parentmenu disabled, andernfalls wird er enabled.
+ */
+
+void SfxObjectVerbsControl::StateChanged(
+ USHORT /*nSID*/,
+ SfxItemState eState,
+ const SfxPoolItem* /*pState*/ )
+{
+ rParent.EnableItem(GetId(), SFX_ITEM_AVAILABLE == eState );
+ if ( SFX_ITEM_AVAILABLE == eState )
+ FillMenu();
+}
+
+//--------------------------------------------------------------------
+
+/*
+ Select-Handler des Menus;
+ das selektierte Verb mit ausgef"uhrt,
+ */
+
+IMPL_LINK_INLINE_START( SfxObjectVerbsControl, MenuSelect, Menu *, pSelMenu )
+{
+ const USHORT nSlotId = pSelMenu->GetCurItemId();
+ if( nSlotId )
+ GetBindings().Execute(nSlotId);
+ return 1;
+}
+IMPL_LINK_INLINE_END( SfxObjectVerbsControl, MenuSelect, Menu *, pSelMenu )
+
+//--------------------------------------------------------------------
+
+/*
+ Dtor; gibt das Menu frei.
+ */
+
+SfxObjectVerbsControl::~SfxObjectVerbsControl()
+{
+ delete pMenu;
+}
+
+//--------------------------------------------------------------------
+
+PopupMenu* SfxObjectVerbsControl::GetPopup() const
+{
+ return pMenu;
+}
+
+
diff --git a/sfx2/source/menu/thessubmenu.cxx b/sfx2/source/menu/thessubmenu.cxx
new file mode 100755
index 000000000000..d82c0a6dbdf3
--- /dev/null
+++ b/sfx2/source/menu/thessubmenu.cxx
@@ -0,0 +1,241 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: thessubmenu.cxx,v $
+ * $Revision: 1.0 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/linguistic2/XThesaurus.hpp>
+#include <com/sun/star/linguistic2/XMeaning.hpp>
+#include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
+
+#include <comphelper/processfactory.hxx>
+#include <svl/stritem.hxx>
+#include <tools/debug.hxx>
+#include <vcl/graph.hxx>
+#include <svtools/filter.hxx>
+
+
+#include <vector>
+
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewsh.hxx>
+#include "thessubmenu.hxx"
+
+
+using namespace ::com::sun::star;
+using ::rtl::OUString;
+
+
+// STATIC DATA -----------------------------------------------------------
+
+SFX_IMPL_MENU_CONTROL(SfxThesSubMenuControl, SfxStringItem);
+
+////////////////////////////////////////////////////////////
+
+
+/*
+ Ctor; setzt Select-Handler am Menu und traegt Menu
+ in seinen Parent ein.
+ */
+SfxThesSubMenuControl::SfxThesSubMenuControl( USHORT nSlotId, Menu &rMenu, SfxBindings &rBindings )
+ : SfxMenuControl( nSlotId, rBindings ),
+ pMenu(new PopupMenu),
+ rParent(rMenu)
+{
+ rMenu.SetPopupMenu(nSlotId, pMenu);
+ pMenu->SetSelectHdl(LINK(this, SfxThesSubMenuControl, MenuSelect));
+ pMenu->Clear();
+ rParent.EnableItem( GetId(), FALSE );
+}
+
+
+SfxThesSubMenuControl::~SfxThesSubMenuControl()
+{
+ delete pMenu;
+}
+
+
+/*
+ Statusbenachrichtigung;
+ Ist die Funktionalit"at disabled, wird der entsprechende
+ Menueeintrag im Parentmenu disabled, andernfalls wird er enabled.
+ */
+void SfxThesSubMenuControl::StateChanged(
+ USHORT /*nSID*/,
+ SfxItemState eState,
+ const SfxPoolItem* /*pState*/ )
+{
+ rParent.EnableItem(GetId(), SFX_ITEM_AVAILABLE == eState );
+}
+
+
+/*
+ Select-Handler des Menus;
+ das selektierte Verb mit ausgef"uhrt,
+ */
+IMPL_LINK_INLINE_START( SfxThesSubMenuControl, MenuSelect, Menu *, pSelMenu )
+{
+ const USHORT nSlotId = pSelMenu->GetCurItemId();
+ if( nSlotId )
+ GetBindings().Execute(nSlotId);
+ return 1;
+}
+IMPL_LINK_INLINE_END( SfxThesSubMenuControl, MenuSelect, Menu *, pSelMenu )
+
+
+PopupMenu* SfxThesSubMenuControl::GetPopup() const
+{
+ return pMenu;
+}
+
+
+////////////////////////////////////////////////////////////
+
+OUString SfxThesSubMenuHelper::GetText(
+ const String &rLookUpString,
+ xub_StrLen nDelimPos )
+{
+ return OUString( rLookUpString.Copy( 0, nDelimPos ) );
+}
+
+
+void SfxThesSubMenuHelper::GetLocale(
+ lang::Locale /*out */ &rLocale,
+ const String &rLookUpString,
+ xub_StrLen nDelimPos )
+{
+ String aIsoLang( rLookUpString.Copy( nDelimPos + 1) );
+ const xub_StrLen nPos = aIsoLang.Search( '-' );
+ if (nPos != STRING_NOTFOUND)
+ {
+ rLocale.Language = aIsoLang.Copy( 0, nPos );
+ rLocale.Country = aIsoLang.Copy( nPos + 1 );
+ rLocale.Variant = String::EmptyString();
+ }
+}
+
+
+SfxThesSubMenuHelper::SfxThesSubMenuHelper()
+{
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
+ m_xLngMgr = uno::Reference< linguistic2::XLinguServiceManager >( xMSF->createInstance(
+ OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.linguistic2.LinguServiceManager" ))), uno::UNO_QUERY_THROW );
+ m_xThesarus = m_xLngMgr->getThesaurus();
+ }
+ catch (uno::Exception &e)
+ {
+ (void) e;
+ DBG_ASSERT( 0, "failed to get thesaurus" );
+ }
+}
+
+
+SfxThesSubMenuHelper::~SfxThesSubMenuHelper()
+{
+}
+
+
+bool SfxThesSubMenuHelper::IsSupportedLocale( const lang::Locale & rLocale ) const
+{
+ return m_xThesarus.is() && m_xThesarus->hasLocale( rLocale );
+}
+
+
+bool SfxThesSubMenuHelper::GetMeanings(
+ std::vector< OUString > & rSynonyms,
+ const OUString & rWord,
+ const lang::Locale & rLocale,
+ sal_Int16 nMaxSynonms )
+{
+ bool bHasMoreSynonyms = false;
+ rSynonyms.clear();
+ if (IsSupportedLocale( rLocale ) && rWord.getLength() && nMaxSynonms > 0)
+ {
+ try
+ {
+ // get all meannings
+ const uno::Sequence< uno::Reference< linguistic2::XMeaning > > aMeaningSeq(
+ m_xThesarus->queryMeanings( rWord, rLocale, uno::Sequence< beans::PropertyValue >() ));
+ const uno::Reference< linguistic2::XMeaning > *pxMeaning = aMeaningSeq.getConstArray();
+ const sal_Int32 nMeanings = aMeaningSeq.getLength();
+
+ // iterate over all meanings until nMaxSynonms are found or all meanings are processed
+ sal_Int32 nCount = 0;
+ sal_Int32 i = 0;
+ for ( ; i < nMeanings && nCount < nMaxSynonms; ++i)
+ {
+ const uno::Sequence< OUString > aSynonymSeq( pxMeaning[i]->querySynonyms() );
+ const OUString *pSynonyms = aSynonymSeq.getConstArray();
+ const sal_Int32 nSynonyms = aSynonymSeq.getLength();
+ sal_Int32 k = 0;
+ for ( ; k < nSynonyms && nCount < nMaxSynonms; ++k)
+ {
+ rSynonyms.push_back( pSynonyms[k] );
+ ++nCount;
+ }
+ bHasMoreSynonyms = k < nSynonyms; // any synonym from this meaning skipped?
+ }
+
+ bHasMoreSynonyms |= i < nMeanings; // any meaning skipped?
+ }
+ catch (uno::Exception &e)
+ {
+ (void) e;
+ DBG_ASSERT( 0, "failed to get synonyms" );
+ }
+ }
+ return bHasMoreSynonyms;
+}
+
+
+String SfxThesSubMenuHelper::GetThesImplName( const lang::Locale &rLocale ) const
+{
+ String aRes;
+ DBG_ASSERT( m_xLngMgr.is(), "LinguServiceManager missing" );
+ if (m_xLngMgr.is())
+ {
+ uno::Sequence< OUString > aServiceNames = m_xLngMgr->getConfiguredServices(
+ OUString::createFromAscii("com.sun.star.linguistic2.Thesaurus"), rLocale );
+ // there should be at most one thesaurus configured for each language
+ DBG_ASSERT( aServiceNames.getLength() <= 1, "more than one thesaurus found. Should not be possible" );
+ if (aServiceNames.getLength() == 1)
+ aRes = aServiceNames[0];
+ }
+ return aRes;
+}
+
+////////////////////////////////////////////////////////////
+
+
diff --git a/sfx2/source/menu/thessubmenu.hxx b/sfx2/source/menu/thessubmenu.hxx
new file mode 100644
index 000000000000..0b86a534de52
--- /dev/null
+++ b/sfx2/source/menu/thessubmenu.hxx
@@ -0,0 +1,103 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: thessubmenu.hxx,v $
+ * $Revision: 1.0 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+
+#ifndef _THESSUBMENU_HXX_
+#define _THESSUBMENU_HXX_
+
+#include <com/sun/star/linguistic2/XThesaurus.hpp>
+#include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
+
+#include <vcl/menu.hxx>
+#include <sfx2/mnuitem.hxx>
+
+class SfxBindings;
+class PopupMenu;
+class Menu;
+
+namespace css = ::com::sun::star;
+
+////////////////////////////////////////////////////////////
+
+class SfxThesSubMenuControl : public SfxMenuControl
+{
+ PopupMenu* pMenu;
+ Menu& rParent;
+
+private:
+ virtual void StateChanged( USHORT, SfxItemState, const SfxPoolItem* pState );
+ DECL_LINK( MenuSelect, Menu * );
+
+public:
+ SfxThesSubMenuControl(USHORT, Menu&, SfxBindings&);
+ ~SfxThesSubMenuControl();
+
+ virtual PopupMenu* GetPopup() const;
+
+ SFX_DECL_MENU_CONTROL();
+};
+
+////////////////////////////////////////////////////////////
+
+class SfxThesSubMenuHelper
+{
+ css::uno::Reference< css::linguistic2::XLinguServiceManager > m_xLngMgr;
+ css::uno::Reference< css::linguistic2::XThesaurus > m_xThesarus;
+
+private:
+
+ // don't use copy c-tor and assignment operator
+ SfxThesSubMenuHelper( const SfxThesSubMenuHelper & );
+ SfxThesSubMenuHelper & operator = ( const SfxThesSubMenuHelper & );
+
+public:
+ SfxThesSubMenuHelper();
+ ~SfxThesSubMenuHelper();
+
+ static ::rtl::OUString GetText( const String &rLookUpString, xub_StrLen nDelimPos );
+
+ // returns the Locale to be used for the selected text when the thesaurus is to be called
+ static void GetLocale( css::lang::Locale /*out */ &rLocale, const String &rLookUpString, xub_StrLen nDelimPos );
+
+ // returns true if the locale is upported by the theasaurus
+ bool IsSupportedLocale( const css::lang::Locale & rLocale ) const;
+
+ // get the first nMax Synonym entries, even if different meanings need to be evaluated
+ bool GetMeanings( std::vector< ::rtl::OUString > & rSynonyms, const ::rtl::OUString & rWord, const css::lang::Locale & rLocale, sal_Int16 nMaxSynonms );
+
+ String GetThesImplName( const css::lang::Locale &rLocale ) const;
+};
+
+////////////////////////////////////////////////////////////
+
+
+#endif
+
+
diff --git a/sfx2/source/menu/virtmenu.cxx b/sfx2/source/menu/virtmenu.cxx
new file mode 100644
index 000000000000..f0408a66a408
--- /dev/null
+++ b/sfx2/source/menu/virtmenu.cxx
@@ -0,0 +1,1361 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <sot/factory.hxx>
+#include <svtools/menuoptions.hxx>
+#include <svtools/imagemgr.hxx>
+#include <svl/imageitm.hxx>
+#include <com/sun/star/container/XEnumeration.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <comphelper/processfactory.hxx>
+#include <toolkit/unohlp.hxx>
+#include <tools/urlobj.hxx>
+
+#include "virtmenu.hxx"
+#include <sfx2/msgpool.hxx>
+#include "statcach.hxx"
+#include <sfx2/msg.hxx>
+#include "idpool.hxx"
+#include <sfx2/mnuitem.hxx>
+#include <sfx2/mnumgr.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/app.hxx>
+#include "sfxtypes.hxx"
+#include "arrdecl.hxx"
+#include <sfx2/sfx.hrc>
+#include <sfx2/viewsh.hxx>
+#include "sfxpicklist.hxx"
+#include <sfx2/macrconf.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "menu.hrc"
+#include "sfx2/imagemgr.hxx"
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/objsh.hxx>
+#include <framework/addonsoptions.hxx>
+
+#ifndef __FRAMEWORK_CLASSES_ADDONMENUS_HXX_
+#include <framework/addonmenu.hxx>
+#endif
+#include <framework/menuconfiguration.hxx>
+
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::uno;
+
+//=========================================================================
+
+DBG_NAME(SfxVirtualMenu)
+
+//=========================================================================
+
+typedef SfxMenuControl* SfxMenuControlPtr;
+SV_IMPL_PTRARR(SfxMenuCtrlArr_Impl, SfxMenuControlPtr);
+
+class SfxMenuImageControl_Impl : public SfxControllerItem
+{
+ SfxVirtualMenu* pMenu;
+ long lRotation;
+ BOOL bIsMirrored;
+
+protected:
+ virtual void StateChanged( USHORT nSID, SfxItemState eState, const SfxPoolItem* pState );
+public:
+ SfxMenuImageControl_Impl( USHORT nSlotId, SfxBindings& rBindings, SfxVirtualMenu* pVMenu )
+ : SfxControllerItem( nSlotId, rBindings )
+ , pMenu( pVMenu )
+ , lRotation( 0 )
+ , bIsMirrored( FALSE )
+ {}
+ void Update();
+};
+
+void SfxMenuImageControl_Impl::StateChanged( USHORT /*nSID*/, SfxItemState /*eState*/, const SfxPoolItem* pState )
+{
+ const SfxImageItem* pItem = PTR_CAST( SfxImageItem, pState );
+ if ( pItem )
+ {
+ lRotation = pItem->GetRotation();
+ bIsMirrored = pItem->IsMirrored();
+ Update();
+ }
+}
+
+void SfxMenuImageControl_Impl::Update()
+{
+ SfxViewFrame* pViewFrame = GetBindings().GetDispatcher_Impl()->GetFrame();
+ SfxModule* pModule = pViewFrame->GetObjectShell()->GetModule();
+ SfxSlotPool* pPool = pModule->GetSlotPool();
+ Menu* pSVMenu = pMenu->GetSVMenu();
+ for (USHORT nPos = 0; nPos<pSVMenu->GetItemCount(); nPos++)
+ {
+ USHORT nslotId = pSVMenu->GetItemId( nPos );
+ const SfxSlot* pSlot = pPool->GetSlot( nslotId );
+ if ( pSlot && pSlot->IsMode( SFX_SLOT_IMAGEROTATION ) )
+ {
+ pSVMenu->SetItemImageMirrorMode( nslotId, FALSE );
+ pSVMenu->SetItemImageAngle( nslotId, lRotation );
+ }
+
+ if ( pSlot && pSlot->IsMode( SFX_SLOT_IMAGEREFLECTION ) )
+ pSVMenu->SetItemImageMirrorMode( nslotId, bIsMirrored );
+ }
+}
+
+//=========================================================================
+
+static Image RetrieveAddOnImage( Reference< com::sun::star::frame::XFrame >& rFrame,
+ const rtl::OUString& aImageId,
+ const rtl::OUString& aURL,
+ BOOL bBigImage,
+ BOOL bHiContrast )
+{
+ Image aImage;
+
+ if ( aImageId.getLength() > 0 )
+ {
+ aImage = GetImage( rFrame, aImageId, bBigImage, bHiContrast );
+ if ( !!aImage )
+ return aImage;
+ }
+
+ aImage = GetImage( rFrame, aURL, bBigImage, bHiContrast );
+ if ( !aImage )
+ aImage = framework::AddonsOptions().GetImageFromURL( aURL, bBigImage, bHiContrast );
+
+ return aImage;
+}
+
+//=========================================================================
+
+/* Diese Hilfsfunktion pr"uft, ob eine Slot-Id im aktuellen Applikations-
+ Status sichtbar ist oder nicht. Dabei bezieht sich der Applikations-Status
+ darauf, ob die Applikation OLE-Server ist oder nicht.
+*/
+
+BOOL IsItemHidden_Impl( USHORT nItemId, int bOleServer, int bMac )
+{
+ return ( bMac &&
+ ( nItemId == SID_MINIMIZED ) ) ||
+ ( bOleServer &&
+ ( nItemId == SID_QUITAPP || nItemId == SID_SAVEDOC ||
+ nItemId == SID_OPENDOC || nItemId == SID_SAVEASDOC ||
+ nItemId == SID_NEWDOC ) ) ||
+ ( !bOleServer &&
+ ( nItemId == SID_EXITANDRETURN || nItemId == SID_UPDATEDOC ) );
+}
+
+//====================================================================
+
+void SfxVirtualMenu::Construct_Impl()
+{
+ pSVMenu->SetHighlightHdl( LINK(this, SfxVirtualMenu, Highlight) );
+ pSVMenu->SetActivateHdl( LINK(this, SfxVirtualMenu, Activate) );
+ pSVMenu->SetDeactivateHdl( LINK(this, SfxVirtualMenu, Deactivate) );
+ pSVMenu->SetSelectHdl( LINK(this, SfxVirtualMenu, Select) );
+
+ // #107258# accelerator keys are needed for accessibility
+ //if ( bOLE )
+ // InvalidateKeyCodes();
+
+ if ( !pResMgr && pParent )
+ pResMgr = pParent->pResMgr;
+}
+
+//--------------------------------------------------------------------
+
+SfxVirtualMenu::SfxVirtualMenu( USHORT nOwnId,
+ SfxVirtualMenu* pOwnParent, Menu& rMenu, BOOL bWithHelp,
+ SfxBindings &rBindings, BOOL bOLEServer, BOOL bRes, BOOL bIsAddonMenu ):
+ pItems(0),
+ pImageControl(0),
+ pBindings(&rBindings),
+ pResMgr(0),
+ pAutoDeactivate(0),
+ nLocks(0),
+ bHelpInitialized( bWithHelp ),
+ bWasHighContrast( FALSE ),
+ bIsAddonPopupMenu( bIsAddonMenu )
+{
+ DBG_MEMTEST();
+ DBG_CTOR(SfxVirtualMenu, 0);
+ pSVMenu = &rMenu;
+
+ bResCtor = bRes;
+ bOLE = bOLEServer;
+ nId = nOwnId;
+ pParent = pOwnParent;
+ nVisibleItems = 0;
+ pAppCtrl = 0;
+ pWindowMenu = NULL;
+ pPickMenu = NULL;
+ pAddonsMenu = NULL;
+ bIsActive = FALSE;
+ bControllersUnBound = FALSE;
+ CreateFromSVMenu();
+ Construct_Impl();
+ bHelpInitialized = FALSE;
+}
+
+//--------------------------------------------------------------------
+
+// creates a virtual menu from a StarView MenuBar or PopupMenu
+
+SfxVirtualMenu::SfxVirtualMenu( Menu *pStarViewMenu, BOOL bWithHelp,
+ SfxBindings &rBindings, BOOL bOLEServer, BOOL bRes, BOOL bIsAddonMenu ):
+ pItems(0),
+ pImageControl(0),
+ pBindings(&rBindings),
+ pResMgr(0),
+ pAutoDeactivate(0),
+ nLocks(0),
+ bHelpInitialized( bWithHelp ),
+ bWasHighContrast( FALSE ),
+ bIsAddonPopupMenu( bIsAddonMenu )
+{
+ DBG_MEMTEST();
+ DBG_CTOR(SfxVirtualMenu, 0);
+
+ pSVMenu = pStarViewMenu;
+
+ bResCtor = bRes;
+ bOLE = bOLEServer;
+ nId = 0;
+ pParent = 0;
+ pAppCtrl = 0;
+ nVisibleItems = 0;
+ pWindowMenu = NULL;
+ pPickMenu = NULL;
+ pAddonsMenu = NULL;
+ bIsActive = FALSE;
+ bControllersUnBound = FALSE;
+ CreateFromSVMenu();
+ Construct_Impl();
+ bHelpInitialized = FALSE;
+}
+
+//--------------------------------------------------------------------
+
+/* Der Destruktor der Klasse SfxVirtualMenu gib die gebundenen Items frei
+ und klinkt das zugeh"orige StarView-PopupMenu aus seinem Parent aus.
+ Falls es sich um das Pickmenu oder das MDI-Menu handelt, wird es
+ dort abgemeldet.
+*/
+
+SfxVirtualMenu::~SfxVirtualMenu()
+{
+ DBG_MEMTEST();
+ DBG_DTOR(SfxVirtualMenu, 0);
+
+ DELETEZ( pImageControl );
+ SvtMenuOptions().RemoveListenerLink( LINK( this, SfxVirtualMenu, SettingsChanged ) );
+
+ if ( bIsActive )
+ {
+ pBindings->LEAVEREGISTRATIONS(); --nLocks; bIsActive = FALSE;
+ }
+
+ // QAP-Hack
+ if ( pAutoDeactivate )
+ {
+ if ( pAutoDeactivate->IsActive() )
+ Deactivate(0);
+ DELETEX(pAutoDeactivate);
+ }
+
+ if (pItems)
+ {
+ delete [] pItems;
+ }
+
+ delete pAppCtrl;
+ pBindings = 0;
+
+ // Alle Menues, die von SV erzeugt wurden, werden auch dort wieder
+ // gel"oscht (also die beim Laden aus der Resource erzeugten).
+ // Das Top-Level-Menu wird nie von SV gel"oscht, da die Allocierung
+ // im SFX erfolgt
+ if ( !bResCtor || !pParent)
+ {
+ if ( pParent )
+ {
+ if( pParent->pSVMenu->GetItemPos( nId ) != MENU_ITEM_NOTFOUND )
+ pParent->pSVMenu->SetPopupMenu( nId, 0 );
+ if ( pParent->pPickMenu == pSVMenu )
+ pParent->pPickMenu = 0;
+ if ( pParent->pWindowMenu == pSVMenu)
+ pParent->pWindowMenu = 0;
+ if ( pParent->pAddonsMenu == pSVMenu )
+ pParent->pAddonsMenu = 0;
+ }
+
+ delete pSVMenu;
+ }
+
+ DBG_OUTF( ("SfxVirtualMenu %lx destroyed", this) );
+ DBG_ASSERT( !nLocks, "destroying active menu" );
+}
+//--------------------------------------------------------------------
+
+BOOL SfxVirtualMenu::IsHiContrastMode() const
+{
+ const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
+ return rSettings.GetHighContrastMode();
+}
+
+//--------------------------------------------------------------------
+// internal: creates the virtual menu from the pSVMenu
+
+void SfxVirtualMenu::CreateFromSVMenu()
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+
+ // Merge Addon popup menus into the SV Menu
+ SfxViewFrame* pViewFrame = pBindings->GetDispatcher()->GetFrame();
+ SfxSlotPool* pSlotPool = pViewFrame->GetObjectShell()->GetModule()->GetSlotPool();
+ Reference< com::sun::star::frame::XFrame > xFrame( pViewFrame->GetFrame().GetFrameInterface() );
+
+ if ( pSVMenu->IsMenuBar() )
+ {
+ USHORT nPos = pSVMenu->GetItemPos( SID_MDIWINDOWLIST );
+ if ( nPos != MENU_ITEM_NOTFOUND && xFrame.is() )
+ {
+ // Retrieve addon popup menus and add them to our menu bar
+ Reference< com::sun::star::frame::XModel > xModel;
+ Reference< com::sun::star::frame::XController > xController( xFrame->getController(), UNO_QUERY );
+ if ( xController.is() )
+ xModel = Reference< com::sun::star::frame::XModel >( xController->getModel(), UNO_QUERY );
+ framework::AddonMenuManager::MergeAddonPopupMenus( xFrame, xModel, nPos, (MenuBar *)pSVMenu );
+ }
+
+ // Merge the Add-Ons help menu items into the Office help menu
+ if ( xFrame.is() )
+ framework::AddonMenuManager::MergeAddonHelpMenu( xFrame, (MenuBar *)pSVMenu );
+
+ // Set addon menu pointer here to avoid problems. When accessibility is enabled, the whole menu
+ // is created immediately!
+ pAddonsMenu = pSVMenu->GetPopupMenu( SID_ADDONLIST );
+ }
+ else if ( pParent )
+ {
+ if ( pSVMenu == pParent->pAddonsMenu &&
+ framework::AddonsOptions().HasAddonsMenu() &&
+ !pSVMenu->GetPopupMenu( SID_ADDONS ) )
+ {
+ // Create menu item at the end of the tools popup menu for the addons popup menu
+ InsertAddOnsMenuItem( pSVMenu );
+ }
+ }
+
+ // get and store the number of items
+ nCount = pSVMenu->GetItemCount();
+
+ // Achtung: nur zu diesem Zeitpunkt ist garantiert, da\s nCount und
+ // der ItemCount des SV-Menues "ubereinstimmen; sp"ater kann das SvMenue
+ // auch mehr Eintr"age haben (Pickliste!)
+ if (nCount)
+ pItems = new SfxMenuControl[nCount];
+
+ // remember some values
+ SFX_APP();
+ const int bOleServer = FALSE;
+ const int bMac = FALSE;
+ SvtMenuOptions aOptions;
+ aOptions.AddListenerLink( LINK( this, SfxVirtualMenu, SettingsChanged ) );
+
+ // iterate through the items
+ pBindings->ENTERREGISTRATIONS(); ++nLocks;
+ pImageControl = new SfxMenuImageControl_Impl( SID_IMAGE_ORIENTATION, *pBindings, this );
+
+ // Update high contrast state
+ bWasHighContrast = IsHiContrastMode();
+
+ USHORT nSVPos = 0;
+ for ( USHORT nPos=0; nPos<nCount; ++nPos, ++nSVPos )
+ {
+ USHORT nSlotId = pSVMenu->GetItemId(nSVPos);
+ PopupMenu* pPopup = pSVMenu->GetPopupMenu(nSlotId);
+ if( pPopup && nSlotId >= SID_OBJECTMENU0 && nSlotId <= SID_OBJECTMENU_LAST )
+ {
+ // artefact in XML menuconfig: every entry in root menu must have a popup!
+ pSVMenu->SetPopupMenu( nSlotId, NULL );
+ DELETEZ( pPopup );
+ }
+
+ const String sItemText = pSVMenu->GetItemText(nSlotId);
+ const String sHelpText = pSVMenu->GetHelpText(nSlotId);
+
+ if ( pPopup )
+ {
+
+ SfxMenuControl *pMnuCtrl =
+ SfxMenuControl::CreateControl(nSlotId, *pPopup, *pBindings);
+
+ if ( pMnuCtrl )
+ {
+ // Das Popup war offensichtlich kein "echtes"; solche werden
+ // niemals aus der Resource geladen und m"ussen daher explizit
+ // gel"oscht werden
+ if ( pSVMenu->GetPopupMenu( nSlotId ) == pPopup )
+ pSVMenu->SetPopupMenu( nSlotId, NULL );
+ delete pPopup;
+ pPopup = 0;
+
+ SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl();
+ rCtrlArr.C40_INSERT( SfxMenuControl, pMnuCtrl, rCtrlArr.Count() );
+ (pItems+nPos)->Bind( 0, nSlotId, sItemText, sHelpText, *pBindings);
+ pMnuCtrl->Bind( this, nSlotId, sItemText, sHelpText, *pBindings);
+
+ if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() )
+ {
+ rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
+ aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId ));
+ Image aImage = GetImage( xFrame, aSlotURL, FALSE, bWasHighContrast );
+ pSVMenu->SetItemImage( nSlotId, aImage );
+ }
+ }
+ else
+ {
+ const SfxSlot* pSlot = pSlotPool->GetSlot( nSlotId );
+ if ( pSlot )
+ {
+ rtl::OString aCmd(".uno:");
+ aCmd += pSlot->GetUnoName();
+ pSVMenu->SetHelpId( nSlotId, pSlot->GetUnoName() );
+ }
+
+ pMnuCtrl = pItems+nPos;
+
+ // normalerweise jetzt erst im Activate-Handler
+ if ( bOLE )
+ {
+ pMnuCtrl->Bind( this, nSlotId,
+ *new SfxVirtualMenu(nSlotId, this, *pPopup, bHelpInitialized, *pBindings, bOLE, bResCtor),
+ sItemText, sHelpText,
+ *pBindings );
+ }
+ }
+
+ ++nVisibleItems;
+ }
+ else
+ {
+ switch ( pSVMenu->GetItemType(nSVPos) )
+ {
+ case MENUITEM_STRING:
+ case MENUITEM_STRINGIMAGE:
+ {
+ SfxMenuControl *pMnuCtrl=0;
+ String aCmd( pSVMenu->GetItemCommand( nSlotId ) );
+ if ( aCmd.CompareToAscii("slot:", 5) == 0 )
+ {
+ SfxMacroConfig* pCfg = SFX_APP()->GetMacroConfig();
+ if ( pCfg->IsMacroSlot( nSlotId ) )
+ {
+ if ( pCfg->GetMacroInfo( nSlotId ) )
+ {
+ pCfg->RegisterSlotId( nSlotId );
+ pSVMenu->SetItemCommand( nSlotId, String() );
+ aCmd.Erase();
+ }
+ else
+ {
+ pSVMenu->SetItemCommand( nSlotId, String::CreateFromAscii("macro:///macro.not.founc") );
+ }
+ }
+ }
+
+ if ( aCmd.Len() && (( nSlotId < SID_SFX_START ) || ( nSlotId > SHRT_MAX )) )
+ {
+ // try to create control via comand name
+ pMnuCtrl = SfxMenuControl::CreateControl( aCmd, nSlotId, *pSVMenu, sItemText, sHelpText, *pBindings, this );
+ if ( pMnuCtrl )
+ {
+ SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl();
+ rCtrlArr.C40_INSERT( SfxMenuControl, pMnuCtrl, rCtrlArr.Count());
+ (pItems+nPos)->Bind( 0, nSlotId, sItemText, sHelpText, *pBindings);
+ }
+ }
+
+ if ( !pMnuCtrl )
+ {
+ // try to create control via Id
+ pMnuCtrl = SfxMenuControl::CreateControl(nSlotId, *pSVMenu, *pBindings);
+ if ( pMnuCtrl )
+ {
+ SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl();
+ rCtrlArr.C40_INSERT( SfxMenuControl, pMnuCtrl, rCtrlArr.Count());
+ (pItems+nPos)->Bind( 0, nSlotId, sItemText, sHelpText, *pBindings);
+ }
+ else
+ // take default control
+ pMnuCtrl = (pItems+nPos);
+
+ pMnuCtrl->Bind( this, nSlotId, sItemText, sHelpText, *pBindings);
+ }
+
+ if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() )
+ {
+ Image aImage;
+ if ( bIsAddonPopupMenu || framework::AddonMenuManager::IsAddonMenuId( nSlotId ))
+ {
+ rtl::OUString aImageId;
+
+ ::framework::MenuConfiguration::Attributes* pMenuAttributes =
+ (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId );
+
+ if ( pMenuAttributes )
+ aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
+
+ aImage = RetrieveAddOnImage( xFrame, aImageId, aCmd, FALSE, bWasHighContrast );
+ }
+ else
+ {
+ rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
+ aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId ));
+ aImage = GetImage( xFrame, aSlotURL, FALSE, bWasHighContrast );
+ }
+
+ if ( !!aImage )
+ pSVMenu->SetItemImage( nSlotId, aImage );
+ }
+
+ if ( !IsItemHidden_Impl(nSlotId, bOleServer, bMac) )
+ ++nVisibleItems;
+ else
+ pSVMenu->RemoveItem( nSVPos-- );
+ break;
+ }
+
+ case MENUITEM_IMAGE:
+ //! not implemented
+ break;
+
+ case MENUITEM_SEPARATOR:
+ //! not implemented
+ break;
+ default:
+ break; // DONTKNOW and STRINGIMAGE not handled.
+ }
+ }
+ }
+ pBindings->LEAVEREGISTRATIONS(); --nLocks;
+}
+
+//--------------------------------------------------------------------
+
+// called on activation of the SV-Menu
+
+IMPL_LINK( SfxVirtualMenu, Highlight, Menu *, pMenu )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+
+ // eigenes StarView-Menu
+ if ( pMenu == pSVMenu )
+ {
+ // AutoDeactivate ist jetzt nicht mehr n"otig
+ //USHORT nSlotId = pMenu->GetCurItemId();
+ if ( pAutoDeactivate )
+ pAutoDeactivate->Stop();
+ }
+
+ return TRUE;
+}
+
+IMPL_LINK( SfxVirtualMenu, SettingsChanged, void*, EMPTYARG )
+{
+ USHORT nItemCount = pSVMenu->GetItemCount();
+ SfxViewFrame *pViewFrame = pBindings->GetDispatcher()->GetFrame();
+ BOOL bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
+ BOOL bIsHiContrastMode = IsHiContrastMode();
+ Reference<com::sun::star::frame::XFrame> xFrame( pViewFrame->GetFrame().GetFrameInterface() );
+
+ if ( !bIsAddonPopupMenu )
+ {
+ for ( USHORT nSVPos=0; nSVPos<nItemCount; ++nSVPos )
+ {
+ USHORT nSlotId = pSVMenu->GetItemId( nSVPos );
+ MenuItemType nType = pSVMenu->GetItemType( nSVPos );
+ if ( nType == MENUITEM_STRING && bIcons )
+ {
+ if ( framework::AddonMenuManager::IsAddonMenuId( nSlotId ))
+ {
+ // Special code for Add-On menu items. They can appear inside the help menu.
+ rtl::OUString aCmd( pSVMenu->GetItemCommand( nSlotId ) );
+ rtl::OUString aImageId;
+
+ ::framework::MenuConfiguration::Attributes* pMenuAttributes =
+ (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId );
+
+ if ( pMenuAttributes )
+ aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
+
+ pSVMenu->SetItemImage( nSlotId, RetrieveAddOnImage( xFrame, aImageId, aCmd, FALSE, bIsHiContrastMode ));
+ }
+ else
+ {
+ rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
+ aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId ));
+ pSVMenu->SetItemImage( nSlotId, GetImage( xFrame, aSlotURL, FALSE, bWasHighContrast ));
+ }
+ }
+ else if( nType == MENUITEM_STRINGIMAGE && !bIcons )
+ {
+ pSVMenu->SetItemImage( nSlotId, Image() );
+ }
+ }
+ }
+ else
+ {
+ // Remove/update images from Add-Ons top-level popup menus when settings have changed
+ if ( !bIcons )
+ RemoveMenuImages( pSVMenu );
+ else
+ UpdateImages( pSVMenu );
+ }
+
+ // Special code to remove menu images from runtime popup menus when settings have changed
+ if ( pParent && pSVMenu == pParent->pAddonsMenu )
+ {
+ if ( !bIcons )
+ RemoveMenuImages( pParent->pAddonsMenu->GetPopupMenu( SID_ADDONS ));
+ else
+ UpdateImages( pParent->pAddonsMenu->GetPopupMenu( SID_ADDONS ));
+ }
+
+ if ( pImageControl )
+ pImageControl->Update();
+
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxVirtualMenu::UpdateImages()
+{
+ BOOL bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
+
+ if ( bIcons )
+ {
+ BOOL bIsHiContrastMode = IsHiContrastMode();
+ USHORT nItemCount = pSVMenu->GetItemCount();
+ SfxViewFrame * pViewFrame = pBindings->GetDispatcher()->GetFrame();
+ Reference<com::sun::star::frame::XFrame> xFrame( pViewFrame->GetFrame().GetFrameInterface() );
+
+ for ( USHORT nSVPos=0; nSVPos < nItemCount; ++nSVPos )
+ {
+ USHORT nSlotId = pSVMenu->GetItemId( nSVPos );
+ if ( pSVMenu->GetItemType( nSVPos ) == MENUITEM_STRINGIMAGE )
+ {
+ if ( framework::AddonMenuManager::IsAddonMenuId( nSlotId ))
+ {
+ // Special code for Add-On menu items. They can appear inside the help menu.
+ rtl::OUString aCmd( pSVMenu->GetItemCommand( nSlotId ) );
+ rtl::OUString aImageId;
+
+ ::framework::MenuConfiguration::Attributes* pMenuAttributes =
+ (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId );
+
+ if ( pMenuAttributes )
+ aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
+
+ pSVMenu->SetItemImage( nSlotId, RetrieveAddOnImage( xFrame, aImageId, aCmd, FALSE, bIsHiContrastMode ));
+ }
+ else
+ {
+ rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
+ aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId ));
+ pSVMenu->SetItemImage( nSlotId, GetImage( xFrame, aSlotURL, FALSE, bWasHighContrast ));
+ }
+ }
+ }
+
+ if ( pImageControl )
+ pImageControl->Update();
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxVirtualMenu::UpdateImages( Menu* pMenu )
+{
+ if ( !pMenu )
+ return;
+
+ framework::AddonsOptions aAddonOptions;
+
+ BOOL bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
+ if ( bIcons )
+ {
+ BOOL bIsHiContrastMode = IsHiContrastMode();
+ USHORT nItemCount = pMenu->GetItemCount();
+ Reference<com::sun::star::frame::XFrame> aXFrame( pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() );
+
+ for ( USHORT nPos=0; nPos < nItemCount; ++nPos )
+ {
+ USHORT nSlotId = pMenu->GetItemId( nPos );
+ PopupMenu* pPopup = pMenu->GetPopupMenu( nSlotId );
+ if ( pMenu->GetItemType( nPos ) != MENUITEM_SEPARATOR )
+ {
+ rtl::OUString aImageId;
+
+ ::framework::MenuConfiguration::Attributes* pMenuAttributes =
+ (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nSlotId );
+
+ if ( pMenuAttributes )
+ aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
+
+ pMenu->SetItemImage( nSlotId, RetrieveAddOnImage( aXFrame, aImageId, pMenu->GetItemCommand( nSlotId ), FALSE, bIsHiContrastMode ));
+ }
+
+ if ( pPopup )
+ UpdateImages( pPopup );
+ }
+
+ if ( pImageControl )
+ pImageControl->Update();
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxVirtualMenu::RemoveMenuImages( Menu* pMenu )
+{
+ if ( !pMenu )
+ return;
+
+ USHORT nItemCount = pMenu->GetItemCount();
+ for ( USHORT nPos=0; nPos < nItemCount; ++nPos )
+ {
+ USHORT nSlotId = pMenu->GetItemId( nPos );
+ PopupMenu* pPopup = pMenu->GetPopupMenu( nSlotId );
+ if ( pMenu->GetItemType( nPos ) == MENUITEM_STRINGIMAGE )
+ pMenu->SetItemImage( nSlotId, Image() );
+ if ( pPopup )
+ RemoveMenuImages( pPopup );
+ }
+}
+
+//--------------------------------------------------------------------
+
+FASTBOOL SfxVirtualMenu::Bind_Impl( Menu *pMenu )
+{
+ // Selber suchen, da SV mit 'USHORT nSID = pSVMenu->GetCurItemId();' immer
+ // 0 liefert. Das ist so, weil die Event-Weiterleitung lt. TH nichts mit
+ // CurItem des Parent-Menus zu tun hat.
+ sal_uInt32 nAddonsPopupPrefixLen = ADDONSPOPUPMENU_URL_PREFIX.getLength();
+
+ for ( USHORT nPos = 0; nPos < nCount; ++nPos )
+ {
+ // angesprochenes Sub-Menu gefunden?
+ FASTBOOL bFound = FALSE;
+ USHORT nSID = pSVMenu->GetItemId(nPos);
+ SfxMenuControl &rCtrl = pItems[nPos];
+ bFound = pSVMenu->GetPopupMenu(nSID) == pMenu;
+ SfxVirtualMenu *pSubMenu = rCtrl.GetPopupMenu();
+
+ if ( bFound )
+ {
+ // Nur ein gebundener Menu-Controller hat schon seine Id!
+ if ( !rCtrl.GetId() )
+ {
+ bIsAddonPopupMenu = FALSE;
+ DBG_ASSERT( !pSubMenu, "Popup schon vorhanden!");
+
+ // Check if the popup is an Add-On popup menu
+ // Either the popup menu has a special ID or a special command URL prefix!
+ rtl::OUString aCommand = pSVMenu->GetItemCommand( nSID );
+ if ( ( nSID == SID_ADDONS ) ||
+ ( nSID == SID_ADDONHELP ) ||
+ (( (sal_uInt32)aCommand.getLength() > nAddonsPopupPrefixLen ) &&
+ ( aCommand.indexOf( ADDONSPOPUPMENU_URL_PREFIX ) == 0 )) )
+ bIsAddonPopupMenu = TRUE;
+
+ // VirtualMenu f"ur Sub-Menu erzeugen
+ BOOL bRes = bResCtor;
+ pSubMenu = new SfxVirtualMenu( nSID, this,
+ *pMenu, FALSE, *pBindings, bOLE, bRes, bIsAddonPopupMenu );
+
+ DBG_OUTF( ("Neues VirtualMenu %lx erzeugt", pSubMenu) );
+
+ rCtrl.Bind( this, nSID, *pSubMenu,
+ pSVMenu->GetItemText(nSID), pSVMenu->GetHelpText(nSID),
+ *pBindings );
+
+ // Activate weiterleiten
+ pSubMenu->Bind_Impl( pMenu );
+ pSubMenu->Activate( pMenu );
+ }
+ }
+
+ // rekursiv weitersuchen (SV Activate nur am Menu selbst und Top-Menu)
+ if ( !bFound && pSubMenu )
+ bFound = pSubMenu->Bind_Impl( pMenu );
+
+ // gefunden, dann abbrechen
+ if ( bFound )
+ return TRUE;
+ }
+
+ // nicht in diesem Untermenu gefunden
+ return FALSE;
+}
+
+void SfxVirtualMenu::BindControllers()
+{
+ pBindings->ENTERREGISTRATIONS();
+
+ USHORT nPos;
+ for ( nPos = 0; nPos < nCount; ++nPos )
+ {
+ SfxMenuControl& rCtrl = pItems[nPos];
+ if ( rCtrl.IsBindable_Impl() && !rCtrl.GetPopupMenu() )
+ rCtrl.ReBind();
+ }
+
+ SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl();
+ for ( nPos=0; nPos<rCtrlArr.Count(); nPos++ )
+ {
+ SfxMenuControl* pCtrl = rCtrlArr[nPos];
+ USHORT nSlotId = pCtrl->GetId();
+ if ( !pSVMenu->GetItemCommand(nSlotId).Len() )
+ pCtrl->ReBind();
+ }
+
+ pBindings->LEAVEREGISTRATIONS();
+ bControllersUnBound = FALSE;
+}
+
+void SfxVirtualMenu::UnbindControllers()
+{
+ pBindings->ENTERREGISTRATIONS();
+
+ USHORT nPos;
+ for ( nPos = 0; nPos < nCount; ++nPos )
+ {
+ SfxMenuControl &rCtrl = pItems[nPos];
+ if ( rCtrl.IsBound() )
+ rCtrl.UnBind();
+ }
+
+ SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl();
+ for ( nPos=0; nPos<rCtrlArr.Count(); nPos++ )
+ {
+ SfxMenuControl* pCtrl = rCtrlArr[nPos];
+ if ( pCtrl->IsBound() )
+ // UnoController sind nicht gebunden!
+ pCtrl->UnBind();
+ }
+
+ pBindings->LEAVEREGISTRATIONS();
+ bControllersUnBound = TRUE;
+}
+
+
+//--------------------------------------------------------------------
+void SfxVirtualMenu::InsertAddOnsMenuItem( Menu* pMenu )
+{
+ // Create special popup menu that is filled with the 3rd party components popup menu items
+ Reference<com::sun::star::lang::XMultiServiceFactory> aXMultiServiceFactory(::comphelper::getProcessServiceFactory());
+ ::framework::MenuConfiguration aConf( aXMultiServiceFactory );
+ Reference<com::sun::star::frame::XFrame> xFrame( pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() );
+
+ PopupMenu* pAddonMenu = NULL;
+ try
+ {
+ pAddonMenu = framework::AddonMenuManager::CreateAddonMenu( xFrame );
+ }
+ catch ( ::com::sun::star::lang::WrappedTargetException )
+ {
+ }
+
+ // Create menu item at the end of the tools popup menu for the addons popup menu
+ if ( pAddonMenu && pAddonMenu->GetItemCount() > 0 )
+ {
+ USHORT nItemCount = pMenu->GetItemCount();
+ String aAddonsTitle( SfxResId( STR_MENU_ADDONS ));
+ if ( nItemCount > 0 && pMenu->GetItemType( nItemCount-1 ) != MENUITEM_SEPARATOR )
+ pMenu->InsertSeparator();
+ pMenu->InsertItem( SID_ADDONS, aAddonsTitle );
+ pMenu->SetPopupMenu( SID_ADDONS, pAddonMenu );
+
+ if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() )
+ {
+ rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
+ aSlotURL += rtl::OUString::valueOf( sal_Int32( SID_ADDONS ));
+ pMenu->SetItemImage( SID_ADDONS, GetImage( xFrame, aSlotURL, FALSE, bWasHighContrast ));
+ }
+ }
+ else
+ delete pAddonMenu;
+}
+
+//--------------------------------------------------------------------
+
+// called on activation of the SV-Menu
+
+IMPL_LINK( SfxVirtualMenu, Activate, Menu *, pMenu )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+ DBG_OUTF( ("SfxVirtualMenu %lx activated %lx, own %lx", this, pMenu, pSVMenu));
+
+ // MI: wozu war der noch gut?
+ // MBA: scheint ein alter QAP-Hack gewesen zu sein ( in rev.1.41 eingecheckt ! )
+// if ( Application::IsInModalMode() )
+// return TRUE; // abw"urgen
+
+ if ( pMenu )
+ {
+ sal_Bool bDontHide = SvtMenuOptions().IsEntryHidingEnabled();
+ sal_uInt16 nFlag = pMenu->GetMenuFlags();
+ if ( bDontHide )
+ nFlag &= ~MENU_FLAG_HIDEDISABLEDENTRIES;
+ else
+ nFlag |= MENU_FLAG_HIDEDISABLEDENTRIES;
+ pMenu->SetMenuFlags( nFlag );
+ }
+
+ // eigenes StarView-Menu
+ if ( pMenu == pSVMenu )
+ {
+ // doppelt-Activate verhindern
+ if ( bIsActive )
+ return TRUE;
+
+ // ggf. Pick-Menu erzeugen
+ if ( pParent && pSVMenu == pParent->pPickMenu )
+ {
+ SfxPickList::Get()->CreateMenuEntries( pParent->pPickMenu );
+ }
+ else
+ pPickMenu = pSVMenu->GetPopupMenu(SID_PICKLIST);
+
+ if ( pParent && pSVMenu == pParent->pWindowMenu )
+ {
+ // update window list
+ ::std::vector< ::rtl::OUString > aNewWindowListVector;
+ Reference< XDesktop > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_OUSTRING( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
+
+ USHORT nActiveItemId = 0;
+ USHORT nItemId = START_ITEMID_WINDOWLIST;
+
+ if ( xDesktop.is() )
+ {
+ Reference< XFramesSupplier > xTasksSupplier( xDesktop, UNO_QUERY );
+ Reference< XFrame > xCurrentFrame = xDesktop->getCurrentFrame();
+ Reference< XIndexAccess > xList ( xTasksSupplier->getFrames(), UNO_QUERY );
+ sal_Int32 nFrameCount = xList->getCount();
+ for( sal_Int32 i=0; i<nFrameCount; ++i )
+ {
+ Reference< XFrame > xFrame;
+ Any aVal = xList->getByIndex(i);
+ if (!(aVal>>=xFrame) || !xFrame.is() )
+ continue;
+
+ if ( xFrame == xCurrentFrame )
+ nActiveItemId = nItemId;
+
+ Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
+ if ( pWin && pWin->IsVisible() )
+ {
+ aNewWindowListVector.push_back( pWin->GetText() );
+ ++nItemId;
+ }
+ }
+ }
+
+ int nItemCount = pMenu->GetItemCount();
+
+ if ( nItemCount > 0 )
+ {
+ // remove all old window list entries from menu
+ sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_WINDOWLIST );
+ for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); )
+ pMenu->RemoveItem( n );
+
+ if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR )
+ pMenu->RemoveItem( pMenu->GetItemCount()-1 );
+ }
+
+ if ( aNewWindowListVector.size() > 0 )
+ {
+ // append new window list entries to menu
+ pMenu->InsertSeparator();
+ nItemId = START_ITEMID_WINDOWLIST;
+ for ( sal_uInt32 i = 0; i < aNewWindowListVector.size(); i++ )
+ {
+ pMenu->InsertItem( nItemId, aNewWindowListVector.at( i ), MIB_RADIOCHECK );
+ if ( nItemId == nActiveItemId )
+ pMenu->CheckItem( nItemId );
+ ++nItemId;
+ }
+ }
+ }
+ else
+ pWindowMenu = pSVMenu->GetPopupMenu(SID_MDIWINDOWLIST);
+
+ if ( !pParent && pSVMenu->IsMenuBar() && !pAddonsMenu )
+ {
+ // Store Add-Ons parents of our runtime menu items
+ pAddonsMenu = pSVMenu->GetPopupMenu( SID_ADDONLIST );
+ }
+
+ // f"ur konstistenten Status sorgen
+ if ( bControllersUnBound )
+ BindControllers();
+
+ //InvalidateKeyCodes();
+ pBindings->GetDispatcher_Impl()->Flush();
+ for ( USHORT nPos = 0; nPos < nCount; ++nPos )
+ {
+ USHORT nSlotId = (pItems+nPos)->GetId();
+ if ( nSlotId && nSlotId > END_ITEMID_WINDOWLIST )
+ pBindings->Update(nSlotId);
+ }
+
+ pBindings->Update( SID_IMAGE_ORIENTATION );
+
+ // HelpText on-demand
+ if ( !bHelpInitialized )
+ {
+ // TODO/CLEANUP: do we need help texts in context menus?
+ // old way with SlotInfo doesn't work anymore
+ }
+
+ // bis zum Deactivate die Statusupdates unterdr"ucken
+ pBindings->ENTERREGISTRATIONS(); ++nLocks; bIsActive = TRUE;
+
+ if ( pAutoDeactivate ) // QAP-Hack
+ pAutoDeactivate->Start();
+
+ if ( IsHiContrastMode() != bWasHighContrast )
+ {
+ // Refresh images as our background color changed and remember it!!
+ bWasHighContrast = IsHiContrastMode();
+ if ( bIsAddonPopupMenu )
+ UpdateImages( pSVMenu );
+ else
+ UpdateImages();
+ }
+
+ // erledigt
+ return TRUE;
+ }
+ else
+ {
+ // VirtualMenu fuer SubMenu finden und ggf. an VirtualMenu binden
+ bool bRet = Bind_Impl( pMenu );
+#ifdef DBG_UTIL
+ if ( !bRet)
+ DBG_WARNING( "W1: Virtual menu konnte nicht erzeugt werden!" );
+#endif
+ return bRet;
+ }
+}
+
+//--------------------------------------------------------------------
+
+IMPL_LINK( SfxVirtualMenu, Deactivate, Menu *, pMenu )
+{
+ DBG_MEMTEST();
+ DBG_OUTF( ("SfxVirtualMenu %lx deactivated %lx, own %lx", this, pMenu, pSVMenu) );
+ if ( bIsActive && ( 0 == pMenu || pMenu == pSVMenu ) )
+ {
+ if ( pAutoDeactivate )
+ pAutoDeactivate->Stop();
+
+ // Bis auf die Menubar k"onnen alle Controller unbinded werden, wenn
+ // das Menue deaktiviert ( = zugeklappt ) wird
+ if ( pParent )
+ UnbindControllers();
+ pBindings->LEAVEREGISTRATIONS(); --nLocks; bIsActive = FALSE;
+ }
+ return TRUE;
+}
+//--------------------------------------------------------------------
+
+// called on activation of the SV-Menu
+
+IMPL_LINK( SfxVirtualMenu, Select, Menu *, pMenu )
+{
+ USHORT nSlotId = (USHORT) pMenu->GetCurItemId();
+ DBG_OUTF( ("SfxVirtualMenu %lx selected %u from %lx", this, nSlotId, pMenu) );
+/*
+ if ( pSVMenu->GetItemCommand( nSlotId ).Len() )
+ {
+ SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl();
+ for ( USHORT nPos=0; nPos<rCtrlArr.Count(); nPos++ )
+ {
+ SfxMenuControl* pCtrl = rCtrlArr[nPos];
+ if ( pCtrl->GetId() == nSlotId )
+ {
+ SfxUnoMenuControl *pUnoCtrl = (SfxUnoMenuControl*) pCtrl;
+ pUnoCtrl->Select();
+ return TRUE;
+ }
+ }
+ }
+*/
+ if ( nSlotId >= START_ITEMID_WINDOWLIST && nSlotId <= END_ITEMID_WINDOWLIST )
+ {
+ // window list menu item selected
+ Reference< XFramesSupplier > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_OUSTRING( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
+ if ( xDesktop.is() )
+ {
+ USHORT nTaskId = START_ITEMID_WINDOWLIST;
+ Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY );
+ sal_Int32 nFrameCount = xList->getCount();
+ for ( sal_Int32 i=0; i<nFrameCount; ++i )
+ {
+ Any aItem = xList->getByIndex(i);
+ Reference< XFrame > xFrame;
+ if (( aItem >>= xFrame ) && xFrame.is() && nTaskId == nSlotId )
+ {
+ Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
+ pWin->GrabFocus();
+ pWin->ToTop( TOTOP_RESTOREWHENMIN );
+ break;
+ }
+
+ nTaskId++;
+ }
+ }
+
+ return TRUE;
+ }
+ else if ( nSlotId >= START_ITEMID_PICKLIST && nSlotId <= END_ITEMID_PICKLIST )
+ {
+ SfxPickList::Get()->ExecuteMenuEntry( nSlotId );
+ return sal_True;
+ }
+
+ if ( pMenu->GetItemCommand( nSlotId ).Len() )
+ pBindings->ExecuteCommand_Impl( pMenu->GetItemCommand( nSlotId ) );
+ else
+ pBindings->Execute( nSlotId );
+
+ return TRUE;
+}
+
+//--------------------------------------------------------------------
+
+// returns the associated StarView-menu
+
+Menu* SfxVirtualMenu::GetSVMenu() const
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+
+ return pSVMenu;
+}
+
+//--------------------------------------------------------------------
+
+// return the position of the specified item
+
+USHORT SfxVirtualMenu::GetItemPos( USHORT nItemId ) const
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+
+ for ( USHORT nPos = 0; nPos < nCount; ++nPos )
+ if ( (pItems+nPos)->GetId() == nItemId )
+ return nPos;
+ return MENU_ITEM_NOTFOUND;
+}
+
+//--------------------------------------------------------------------
+
+// returns the popup-menu assigned to the item or 0 if none
+
+SfxVirtualMenu* SfxVirtualMenu::GetPopupMenu( USHORT nItemId ) const
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+
+ USHORT nPos = GetItemPos(nItemId);
+ if ( nPos != MENU_ITEM_NOTFOUND )
+ return (pItems+nPos)->GetPopupMenu();
+ return 0;
+}
+//--------------------------------------------------------------------
+
+// returns the text of the item as currently shown in the menu
+
+String SfxVirtualMenu::GetItemText( USHORT nSlotId ) const
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+
+ USHORT nPos = GetItemPos(nSlotId);
+ if ( nPos != MENU_ITEM_NOTFOUND )
+ return (pItems+nPos)->GetTitle();
+ return String();
+}
+//--------------------------------------------------------------------
+
+// returns the text of the item as currently shown in the menu
+
+String SfxVirtualMenu::GetItemHelpText( USHORT nSlotId ) const
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+
+ USHORT nPos = GetItemPos(nSlotId);
+ if ( nPos != MENU_ITEM_NOTFOUND )
+ return (pItems+nPos)->GetHelpText();
+ return String();
+}
+
+//--------------------------------------------------------------------
+
+// set the checkmark of the specified item
+
+void SfxVirtualMenu::CheckItem( USHORT nItemId, BOOL bCheck )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+ DBG_ASSERT( this != 0, "");
+ DBG_ASSERT( pSVMenu != 0, "" );
+ if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
+ pSVMenu->CheckItem( nItemId, bCheck );
+}
+//--------------------------------------------------------------------
+
+// set the enabled-state of the specified item
+
+void SfxVirtualMenu::EnableItem( USHORT nItemId, BOOL bEnable )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+ DBG_ASSERT( this != 0, "");
+ DBG_ASSERT( pSVMenu != 0, "" );
+
+ if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
+ pSVMenu->EnableItem( nItemId, bEnable );
+}
+//--------------------------------------------------------------------
+
+// set the text of the specified item
+
+void SfxVirtualMenu::SetItemText( USHORT nItemId, const String& rText )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+ DBG_ASSERT( this != 0, "");
+ DBG_ASSERT( pSVMenu != 0, "" );
+ if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
+ pSVMenu->SetItemText( nItemId, rText );
+}
+
+//--------------------------------------------------------------------
+
+//
+
+void SfxVirtualMenu::SetPopupMenu( USHORT nItemId, PopupMenu *pMenu )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+
+ if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
+ GetSVMenu()->SetPopupMenu( nItemId, pMenu );
+ for ( USHORT n = 0; n < nCount; ++n )
+ {
+ SfxVirtualMenu *pSubMenu = (pItems+n)->GetPopupMenu();
+ if ( pSubMenu )
+ pSubMenu->SetPopupMenu( nItemId, pMenu );
+ }
+}
+
+//--------------------------------------------------------------------
+
+// Erzwingt die Initialisierung, die sonst nur im Activate kommt
+
+void SfxVirtualMenu::InitPopup( USHORT nPos, BOOL /*bOLE*/ )
+{
+ DBG_MEMTEST();
+ DBG_CHKTHIS(SfxVirtualMenu, 0);
+
+ USHORT nSID = pSVMenu->GetItemId(nPos);
+ PopupMenu *pMenu = pSVMenu->GetPopupMenu( nSID );
+
+ DBG_ASSERT( pMenu, "Hier gibt es kein Popup!");
+
+ SfxMenuControl &rCtrl = pItems[nPos];
+ if ( !rCtrl.GetId() )
+ {
+ // VirtualMenu f"ur Sub-Menu erzeugen
+ BOOL bRes = bResCtor;
+ SfxVirtualMenu *pSubMenu =
+ new SfxVirtualMenu(nSID, this, *pMenu, FALSE, *pBindings, bOLE, bRes);
+
+ DBG_OUTF( ("Neues VirtualMenu %lx erzeugt", pSubMenu) );
+
+ rCtrl.Bind( this, nSID, *pSubMenu,
+ pSVMenu->GetItemText(nSID), pSVMenu->GetHelpText(nSID),
+ *pBindings );
+ }
+}
+
+void SfxVirtualMenu::InitializeHelp()
+{
+ for ( USHORT nPos = 0; nPos<pSVMenu->GetItemCount(); ++nPos )
+ {
+ USHORT nSlotId = pSVMenu->GetItemId(nPos);
+ // TODO/CLEANUP: this code does nothing!
+// if ( !bHelpInitialized )
+// pSVMenu->SetHelpText( nId, rSlotPool.GetSlotHelpText_Impl( nId ) );
+ SfxMenuControl &rCtrl = pItems[nPos];
+ if ( nSlotId && !rCtrl.GetId() )
+ {
+ InitPopup( nPos, TRUE );
+ }
+
+ SfxVirtualMenu *pSubMenu = rCtrl.GetPopupMenu();
+ if ( pSubMenu )
+ pSubMenu->InitializeHelp();
+ }
+
+ bHelpInitialized = TRUE;
+}
+
+typedef ULONG (__LOADONCALLAPI *HelpIdFunc) ( const String& );
+
+void SfxVirtualMenu::SetHelpIds( ResMgr *pRes )
+{
+ pResMgr = pRes;
+}
+
diff --git a/sfx2/source/notify/eventsupplier.cxx b/sfx2/source/notify/eventsupplier.cxx
new file mode 100644
index 000000000000..1ca10c6d9390
--- /dev/null
+++ b/sfx2/source/notify/eventsupplier.cxx
@@ -0,0 +1,920 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+//--------------------------------------------------------------------------------------------------------
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+#ifndef _COM_SUN_STAR_UTL_URL_HPP_
+#include <com/sun/star/util/URL.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_UTL_XURLTRANSFORMER_HPP_
+#include <com/sun/star/util/XURLTransformer.hpp>
+#endif
+#include <tools/urlobj.hxx>
+#include <svl/macitem.hxx>
+#include <sfx2/appuno.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/sfxbasemodel.hxx>
+#include <sfx2/evntconf.hxx>
+#include <unotools/eventcfg.hxx>
+
+#include <unotools/securityoptions.hxx>
+#include <comphelper/processfactory.hxx>
+#include "eventsupplier.hxx"
+
+#include <sfx2/app.hxx>
+#include "sfx2/sfxresid.hxx"
+
+#include <sfx2/sfxsids.hrc>
+#include "sfxlocal.hrc"
+#include <sfx2/docfile.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/frame.hxx>
+
+//--------------------------------------------------------------------------------------------------------
+
+#define MACRO_PRFIX "macro://"
+#define MACRO_POSTFIX "()"
+
+//--------------------------------------------------------------------------------------------------------
+
+#define PROPERTYVALUE ::com::sun::star::beans::PropertyValue
+#define UNO_QUERY ::com::sun::star::uno::UNO_QUERY
+
+namespace css = ::com::sun::star;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::beans::PropertyValue;
+
+//--------------------------------------------------------------------------------------------------------
+ // --- XNameReplace ---
+//--------------------------------------------------------------------------------------------------------
+void SAL_CALL SfxEvents_Impl::replaceByName( const OUSTRING & aName, const ANY & rElement )
+ throw( ILLEGALARGUMENTEXCEPTION, NOSUCHELEMENTEXCEPTION,
+ WRAPPEDTARGETEXCEPTION, RUNTIMEEXCEPTION )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // find the event in the list and replace the data
+ long nCount = maEventNames.getLength();
+ for ( long i=0; i<nCount; i++ )
+ {
+ if ( maEventNames[i] == aName )
+ {
+ Sequence< PropertyValue > aProperties;
+ // check for correct type of the element
+ if ( rElement.hasValue() && !( rElement >>= aProperties ) )
+ throw ILLEGALARGUMENTEXCEPTION();
+
+ // create Configuration at first, creation might call this method also and that would overwrite everything
+ // we might have stored before!
+ if ( mpObjShell && !mpObjShell->IsLoading() )
+ mpObjShell->SetModified( TRUE );
+
+ if ( aProperties.getLength() )
+ {
+ // "normalize" the macro descriptor
+ ANY aValue;
+ BlowUpMacro( rElement, aValue, mpObjShell );
+ aValue >>= aProperties;
+
+ ::rtl::OUString sType;
+ if ( ( aProperties.getLength() == 1 )
+ && ( aProperties[0].Name.compareToAscii( PROP_EVENT_TYPE ) == 0 )
+ && ( aProperties[0].Value >>= sType )
+ && ( sType.getLength() == 0 )
+ )
+ {
+ // An empty event type means no binding. Therefore reset data
+ // to reflect that state.
+ // (that's for compatibility only. Nowadays, the Tools/Customize dialog should
+ // set an empty sequence to indicate the request for resetting the assignment.)
+ aProperties.realloc( 0 );
+ }
+ }
+
+ if ( aProperties.getLength() )
+ {
+ maEventData[i] = makeAny( aProperties );
+ }
+ else
+ {
+ maEventData[i].clear();
+ }
+ return;
+ }
+ }
+
+ throw NOSUCHELEMENTEXCEPTION();
+}
+
+//--------------------------------------------------------------------------------------------------------
+// --- XNameAccess ---
+//--------------------------------------------------------------------------------------------------------
+ANY SAL_CALL SfxEvents_Impl::getByName( const OUSTRING& aName )
+ throw( NOSUCHELEMENTEXCEPTION, WRAPPEDTARGETEXCEPTION,
+ RUNTIMEEXCEPTION )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // find the event in the list and return the data
+
+ long nCount = maEventNames.getLength();
+
+ for ( long i=0; i<nCount; i++ )
+ {
+ if ( maEventNames[i] == aName )
+ return maEventData[i];
+ }
+
+ throw NOSUCHELEMENTEXCEPTION();
+}
+
+//--------------------------------------------------------------------------------------------------------
+SEQUENCE< OUSTRING > SAL_CALL SfxEvents_Impl::getElementNames() throw ( RUNTIMEEXCEPTION )
+{
+ return maEventNames;
+}
+
+//--------------------------------------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxEvents_Impl::hasByName( const OUSTRING& aName ) throw ( RUNTIMEEXCEPTION )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // find the event in the list and return the data
+
+ long nCount = maEventNames.getLength();
+
+ for ( long i=0; i<nCount; i++ )
+ {
+ if ( maEventNames[i] == aName )
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+//--------------------------------------------------------------------------------------------------------
+// --- XElementAccess ( parent of XNameAccess ) ---
+//--------------------------------------------------------------------------------------------------------
+UNOTYPE SAL_CALL SfxEvents_Impl::getElementType() throw ( RUNTIMEEXCEPTION )
+{
+ UNOTYPE aElementType = ::getCppuType( (const SEQUENCE < PROPERTYVALUE > *)0 );
+ return aElementType;
+}
+
+//--------------------------------------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxEvents_Impl::hasElements() throw ( RUNTIMEEXCEPTION )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ if ( maEventNames.getLength() )
+ return sal_True;
+ else
+ return sal_False;
+}
+
+static void Execute( ANY& aEventData, const css::document::DocumentEvent& aTrigger, SfxObjectShell* pDoc )
+{
+ SEQUENCE < PROPERTYVALUE > aProperties;
+ if ( aEventData >>= aProperties )
+ {
+ OUSTRING aPrefix = OUSTRING( RTL_CONSTASCII_USTRINGPARAM( MACRO_PRFIX ) );
+ OUSTRING aType;
+ OUSTRING aScript;
+ OUSTRING aLibrary;
+ OUSTRING aMacroName;
+
+ sal_Int32 nCount = aProperties.getLength();
+
+ if ( !nCount )
+ return;
+
+ sal_Int32 nIndex = 0;
+ while ( nIndex < nCount )
+ {
+ if ( aProperties[ nIndex ].Name.compareToAscii( PROP_EVENT_TYPE ) == 0 )
+ aProperties[ nIndex ].Value >>= aType;
+ else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_SCRIPT ) == 0 )
+ aProperties[ nIndex ].Value >>= aScript;
+ else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_LIBRARY ) == 0 )
+ aProperties[ nIndex ].Value >>= aLibrary;
+ else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_MACRO_NAME ) == 0 )
+ aProperties[ nIndex ].Value >>= aMacroName;
+ else {
+ DBG_ERROR("Unknown property value!");
+ }
+ nIndex += 1;
+ }
+
+ if ( aType.compareToAscii( STAR_BASIC ) == 0 && aScript.getLength() )
+ {
+ com::sun::star::uno::Any aAny;
+ SfxMacroLoader::loadMacro( aScript, aAny, pDoc );
+ }
+ else if ( aType.compareToAscii( "Service" ) == 0 ||
+ aType.compareToAscii( "Script" ) == 0 )
+ {
+ if ( aScript.getLength() )
+ {
+ SfxViewFrame* pView = pDoc ?
+ SfxViewFrame::GetFirst( pDoc ) :
+ SfxViewFrame::Current();
+
+ ::com::sun::star::uno::Reference
+ < ::com::sun::star::util::XURLTransformer > xTrans(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString::createFromAscii(
+ "com.sun.star.util.URLTransformer" ) ),
+ UNO_QUERY );
+
+ ::com::sun::star::util::URL aURL;
+ aURL.Complete = aScript;
+ xTrans->parseStrict( aURL );
+
+ ::com::sun::star::uno::Reference
+ < ::com::sun::star::frame::XDispatchProvider > xProv;
+
+ if ( pView != NULL )
+ {
+ xProv = ::com::sun::star::uno::Reference
+ < ::com::sun::star::frame::XDispatchProvider > (
+ pView->GetFrame().GetFrameInterface(), UNO_QUERY );
+ }
+ else
+ {
+ xProv = ::com::sun::star::uno::Reference
+ < ::com::sun::star::frame::XDispatchProvider > (
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString::createFromAscii(
+ "com.sun.star.frame.Desktop" ) ),
+ UNO_QUERY );
+ }
+
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatch > xDisp;
+ if ( xProv.is() )
+ xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 );
+
+ if ( xDisp.is() )
+ {
+ //::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > aArgs(1);
+ //aArgs[0].Name = rtl::OUString::createFromAscii("Referer");
+ //aArs[0].Value <<= ::rtl::OUString( pDoc->GetMedium()->GetName() );
+ //xDisp->dispatch( aURL, aArgs );
+
+ css::beans::PropertyValue aEventParam;
+ aEventParam.Value <<= aTrigger;
+ css::uno::Sequence< css::beans::PropertyValue > aDispatchArgs( &aEventParam, 1 );
+ xDisp->dispatch( aURL, aDispatchArgs );
+ }
+ }
+ }
+ else if ( aType.getLength() == 0 )
+ {
+ // Empty type means no active binding for the event. Just ignore do nothing.
+ }
+ else
+ {
+ DBG_ERRORFILE( "notifyEvent(): Unsupported event type" );
+ }
+ }
+}
+
+//--------------------------------------------------------------------------------------------------------
+// --- ::document::XEventListener ---
+//--------------------------------------------------------------------------------------------------------
+void SAL_CALL SfxEvents_Impl::notifyEvent( const DOCEVENTOBJECT& aEvent ) throw( RUNTIMEEXCEPTION )
+{
+ ::osl::ClearableMutexGuard aGuard( maMutex );
+
+ // get the event name, find the coresponding data, execute the data
+
+ OUSTRING aName = aEvent.EventName;
+ long nCount = maEventNames.getLength();
+ long nIndex = 0;
+ sal_Bool bFound = sal_False;
+
+ while ( !bFound && ( nIndex < nCount ) )
+ {
+ if ( maEventNames[nIndex] == aName )
+ bFound = sal_True;
+ else
+ nIndex += 1;
+ }
+
+ if ( !bFound )
+ return;
+
+ ANY aEventData = maEventData[ nIndex ];
+ aGuard.clear();
+ Execute( aEventData, css::document::DocumentEvent(aEvent.Source, aEvent.EventName, NULL, css::uno::Any()), mpObjShell );
+}
+
+//--------------------------------------------------------------------------------------------------------
+// --- ::lang::XEventListener ---
+//--------------------------------------------------------------------------------------------------------
+void SAL_CALL SfxEvents_Impl::disposing( const EVENTOBJECT& /*Source*/ ) throw( RUNTIMEEXCEPTION )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ if ( mxBroadcaster.is() )
+ {
+ mxBroadcaster->removeEventListener( this );
+ mxBroadcaster = NULL;
+ }
+}
+
+//--------------------------------------------------------------------------------------------------------
+//
+//--------------------------------------------------------------------------------------------------------
+SfxEvents_Impl::SfxEvents_Impl( SfxObjectShell* pShell,
+ REFERENCE< XEVENTBROADCASTER > xBroadcaster )
+{
+ // get the list of supported events and store it
+ if ( pShell )
+ maEventNames = pShell->GetEventNames();
+ else
+ maEventNames = GlobalEventConfig().getElementNames();
+
+ maEventData = SEQUENCE < ANY > ( maEventNames.getLength() );
+
+ mpObjShell = pShell;
+ mxBroadcaster = xBroadcaster;
+
+ if ( mxBroadcaster.is() )
+ mxBroadcaster->addEventListener( this );
+}
+
+//--------------------------------------------------------------------------------------------------------
+SfxEvents_Impl::~SfxEvents_Impl()
+{
+}
+
+//--------------------------------------------------------------------------------------------------------
+SvxMacro* SfxEvents_Impl::ConvertToMacro( const ANY& rElement, SfxObjectShell* pObjShell, BOOL bBlowUp )
+{
+ SvxMacro* pMacro = NULL;
+ SEQUENCE < PROPERTYVALUE > aProperties;
+ ANY aAny;
+ if ( bBlowUp )
+ BlowUpMacro( rElement, aAny, pObjShell );
+ else
+ aAny = rElement;
+
+ if ( aAny >>= aProperties )
+ {
+ OUSTRING aType;
+ OUSTRING aScriptURL;
+ OUSTRING aLibrary;
+ OUSTRING aMacroName;
+
+ long nCount = aProperties.getLength();
+ long nIndex = 0;
+
+ if ( !nCount )
+ return pMacro;
+
+ while ( nIndex < nCount )
+ {
+ if ( aProperties[ nIndex ].Name.compareToAscii( PROP_EVENT_TYPE ) == 0 )
+ aProperties[ nIndex ].Value >>= aType;
+ else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_SCRIPT ) == 0 )
+ aProperties[ nIndex ].Value >>= aScriptURL;
+ else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_LIBRARY ) == 0 )
+ aProperties[ nIndex ].Value >>= aLibrary;
+ else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_MACRO_NAME ) == 0 )
+ aProperties[ nIndex ].Value >>= aMacroName;
+ else {
+ DBG_ERROR("Unknown propery value!");
+ }
+ nIndex += 1;
+ }
+
+ // Get the type
+ ScriptType eType( STARBASIC );
+ if ( aType.compareToAscii( STAR_BASIC ) == COMPARE_EQUAL )
+ eType = STARBASIC;
+ else if ( aType.compareToAscii( "Script" ) == COMPARE_EQUAL && aScriptURL.getLength() )
+ eType = EXTENDED_STYPE;
+ else if ( aType.compareToAscii( SVX_MACRO_LANGUAGE_JAVASCRIPT ) == COMPARE_EQUAL )
+ eType = JAVASCRIPT;
+ else {
+ DBG_ERRORFILE( "ConvertToMacro: Unknown macro type" );
+ }
+
+ if ( aMacroName.getLength() )
+ {
+ if ( aLibrary.compareToAscii("application") == 0 )
+ aLibrary = SFX_APP()->GetName();
+ else
+ aLibrary = ::rtl::OUString();
+ pMacro = new SvxMacro( aMacroName, aLibrary, eType );
+ }
+ else if ( eType == EXTENDED_STYPE )
+ pMacro = new SvxMacro( aScriptURL, aType );
+ }
+
+ return pMacro;
+}
+
+void SfxEvents_Impl::BlowUpMacro( const ANY& rEvent, ANY& rRet, SfxObjectShell* pDoc )
+{
+ if ( !pDoc )
+ pDoc = SfxObjectShell::Current();
+
+ SEQUENCE < PROPERTYVALUE > aInProps;
+ SEQUENCE < PROPERTYVALUE > aOutProps(2);
+
+ if ( !( rEvent >>= aInProps ) )
+ return;
+
+ sal_Int32 nCount = aInProps.getLength();
+
+ if ( !nCount )
+ return;
+
+ OUSTRING aType;
+ OUSTRING aScript;
+ OUSTRING aLibrary;
+ OUSTRING aMacroName;
+
+ sal_Int32 nIndex = 0;
+
+ while ( nIndex < nCount )
+ {
+ if ( aInProps[ nIndex ].Name.compareToAscii( PROP_EVENT_TYPE ) == 0 )
+ {
+ aInProps[nIndex].Value >>= aType;
+ aOutProps[0] = aInProps[nIndex];
+ }
+ else if ( aInProps[ nIndex ].Name.compareToAscii( PROP_SCRIPT ) == 0 )
+ {
+ aInProps[nIndex].Value >>= aScript;
+ aOutProps[1] = aInProps[nIndex];
+ }
+ else if ( aInProps[ nIndex ].Name.compareToAscii( PROP_LIBRARY ) == 0 )
+ {
+ aInProps[ nIndex ].Value >>= aLibrary;
+ }
+ else if ( aInProps[ nIndex ].Name.compareToAscii( PROP_MACRO_NAME ) == 0 )
+ {
+ aInProps[ nIndex ].Value >>= aMacroName;
+ }
+ nIndex += 1;
+ }
+
+ if ( aType.compareToAscii( STAR_BASIC ) == 0 )
+ {
+ aOutProps.realloc(4);
+ if ( aScript.getLength() )
+ {
+ if( ! aMacroName.getLength() || ! aLibrary.getLength() )
+ {
+ sal_Int32 nHashPos = aScript.indexOf( '/', 8 );
+ sal_Int32 nArgsPos = aScript.indexOf( '(' );
+ if ( ( nHashPos != STRING_NOTFOUND ) && ( nHashPos < nArgsPos ) )
+ {
+ OUSTRING aBasMgrName( INetURLObject::decode( aScript.copy( 8, nHashPos-8 ), INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET ) );
+ if ( aBasMgrName.compareToAscii(".") == 0 )
+ aLibrary = pDoc->GetTitle();
+/*
+ else if ( aBasMgrName.getLength() )
+ aLibrary = aBasMgrName;
+ */
+ else
+ aLibrary = SFX_APP()->GetName();
+
+ // Get the macro name
+ aMacroName = aScript.copy( nHashPos+1, nArgsPos - nHashPos - 1 );
+ }
+ else
+ {
+ DBG_ERRORFILE( "ConvertToMacro: Unknown macro url format" );
+ }
+ }
+ }
+ else if ( aMacroName.getLength() )
+ {
+ aScript = OUSTRING( RTL_CONSTASCII_USTRINGPARAM( MACRO_PRFIX ) );
+ if ( aLibrary.compareTo( SFX_APP()->GetName() ) != 0 && aLibrary.compareToAscii("StarDesktop") != 0 && aLibrary.compareToAscii("application") != 0 )
+ aScript += String('.');
+
+ aScript += String('/');
+ aScript += aMacroName;
+ aScript += OUSTRING( RTL_CONSTASCII_USTRINGPARAM( MACRO_POSTFIX ) );
+ }
+ else
+ // wrong properties
+ return;
+
+ if ( aLibrary.compareToAscii("document") != 0 )
+ {
+ if ( !aLibrary.getLength() || (pDoc && ( String(aLibrary) == pDoc->GetTitle( SFX_TITLE_APINAME ) || String(aLibrary) == pDoc->GetTitle() )) )
+ aLibrary = String::CreateFromAscii("document");
+ else
+ aLibrary = String::CreateFromAscii("application");
+ }
+
+ aOutProps[1].Name = OUSTRING::createFromAscii( PROP_SCRIPT );
+ aOutProps[1].Value <<= aScript;
+ aOutProps[2].Name = OUSTRING::createFromAscii( PROP_LIBRARY );
+ aOutProps[2].Value <<= aLibrary;
+ aOutProps[3].Name = OUSTRING::createFromAscii( PROP_MACRO_NAME );
+ aOutProps[3].Value <<= aMacroName;
+ rRet <<= aOutProps;
+ }
+ else if ( aType.compareToAscii( SVX_MACRO_LANGUAGE_JAVASCRIPT ) == 0 )
+ {
+ aOutProps[1] = aInProps[1];
+ rRet <<= aOutProps;
+ }
+ else
+ {
+ rRet <<= aOutProps;
+ }
+}
+
+ModelCollectionEnumeration::ModelCollectionEnumeration(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
+ : ModelCollectionMutexBase( )
+ , m_xSMGR (xSMGR )
+ , m_pEnumerationIt (m_lModels.begin())
+{
+}
+
+ModelCollectionEnumeration::~ModelCollectionEnumeration()
+{
+}
+
+void ModelCollectionEnumeration::setModelList(const TModelList& rList)
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ m_lModels = rList;
+ m_pEnumerationIt = m_lModels.begin();
+ aLock.clear();
+ // <- SAFE
+}
+
+sal_Bool SAL_CALL ModelCollectionEnumeration::hasMoreElements()
+ throw(css::uno::RuntimeException)
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ return (m_pEnumerationIt != m_lModels.end());
+ // <- SAFE
+}
+
+css::uno::Any SAL_CALL ModelCollectionEnumeration::nextElement()
+ throw(css::container::NoSuchElementException,
+ css::lang::WrappedTargetException ,
+ css::uno::RuntimeException )
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ if (m_pEnumerationIt == m_lModels.end())
+ throw css::container::NoSuchElementException(
+ ::rtl::OUString::createFromAscii("End of model enumeration reached."),
+ static_cast< css::container::XEnumeration* >(this));
+ css::uno::Reference< css::frame::XModel > xModel(*m_pEnumerationIt, UNO_QUERY);
+ ++m_pEnumerationIt;
+ aLock.clear();
+ // <- SAFE
+
+ return css::uno::makeAny(xModel);
+}
+
+SFX_IMPL_XSERVICEINFO( SfxGlobalEvents_Impl, "com.sun.star.frame.GlobalEventBroadcaster", "com.sun.star.comp.sfx2.GlobalEventBroadcaster" )
+SFX_IMPL_ONEINSTANCEFACTORY( SfxGlobalEvents_Impl );
+
+//-----------------------------------------------------------------------------
+SfxGlobalEvents_Impl::SfxGlobalEvents_Impl( const com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& xSMGR)
+ : ModelCollectionMutexBase( )
+ , m_xSMGR (xSMGR )
+ , m_aLegacyListeners (m_aLock)
+ , m_aDocumentListeners (m_aLock)
+ , pImp (0 )
+{
+ m_refCount++;
+ SFX_APP();
+ pImp = new GlobalEventConfig();
+ m_xEvents = pImp;
+ m_xJobExecutorListener = css::uno::Reference< css::document::XEventListener >(
+ xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.task.JobExecutor")),
+ UNO_QUERY);
+ m_refCount--;
+}
+
+//-----------------------------------------------------------------------------
+SfxGlobalEvents_Impl::~SfxGlobalEvents_Impl()
+{
+}
+
+//-----------------------------------------------------------------------------
+css::uno::Reference< css::container::XNameReplace > SAL_CALL SfxGlobalEvents_Impl::getEvents()
+ throw(css::uno::RuntimeException)
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ return m_xEvents;
+ // <- SAFE
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::addEventListener(const css::uno::Reference< css::document::XEventListener >& xListener)
+ throw(css::uno::RuntimeException)
+{
+ // container is threadsafe
+ m_aLegacyListeners.addInterface(xListener);
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::removeEventListener(const css::uno::Reference< css::document::XEventListener >& xListener)
+ throw(css::uno::RuntimeException)
+{
+ // container is threadsafe
+ m_aLegacyListeners.removeInterface(xListener);
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::addDocumentEventListener( const css::uno::Reference< css::document::XDocumentEventListener >& _Listener )
+ throw(css::uno::RuntimeException)
+{
+ m_aDocumentListeners.addInterface( _Listener );
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::removeDocumentEventListener( const css::uno::Reference< css::document::XDocumentEventListener >& _Listener )
+ throw(css::uno::RuntimeException)
+{
+ m_aDocumentListeners.removeInterface( _Listener );
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::notifyDocumentEvent( const ::rtl::OUString& /*_EventName*/,
+ const css::uno::Reference< css::frame::XController2 >& /*_ViewController*/, const css::uno::Any& /*_Supplement*/ )
+ throw (css::lang::IllegalArgumentException, css::lang::NoSupportException, css::uno::RuntimeException)
+{
+ // we're a multiplexer only, no chance to generate artifical events here
+ throw css::lang::NoSupportException(::rtl::OUString(), *this);
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::notifyEvent(const css::document::EventObject& aEvent)
+ throw(css::uno::RuntimeException)
+{
+ css::document::DocumentEvent aDocEvent(aEvent.Source, aEvent.EventName, NULL, css::uno::Any());
+ implts_notifyJobExecution(aEvent);
+ implts_checkAndExecuteEventBindings(aDocEvent);
+ implts_notifyListener(aDocEvent);
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::documentEventOccured( const ::css::document::DocumentEvent& _Event )
+ throw (::css::uno::RuntimeException)
+{
+ implts_notifyJobExecution(css::document::EventObject(_Event.Source, _Event.EventName));
+ implts_checkAndExecuteEventBindings(_Event);
+ implts_notifyListener(_Event);
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::disposing(const css::lang::EventObject& aEvent)
+ throw(css::uno::RuntimeException)
+{
+ css::uno::Reference< css::frame::XModel > xDoc(aEvent.Source, UNO_QUERY);
+
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt != m_lModels.end())
+ m_lModels.erase(pIt);
+ aLock.clear();
+ // <- SAFE
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxGlobalEvents_Impl::has(const css::uno::Any& aElement)
+ throw (css::uno::RuntimeException)
+{
+ css::uno::Reference< css::frame::XModel > xDoc;
+ aElement >>= xDoc;
+
+ sal_Bool bHas = sal_False;
+
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt != m_lModels.end())
+ bHas = sal_True;
+ aLock.clear();
+ // <- SAFE
+
+ return bHas;
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::insert( const css::uno::Any& aElement )
+ throw (css::lang::IllegalArgumentException ,
+ css::container::ElementExistException,
+ css::uno::RuntimeException )
+{
+ css::uno::Reference< css::frame::XModel > xDoc;
+ aElement >>= xDoc;
+ if (!xDoc.is())
+ throw css::lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii("Cant locate at least the model parameter."),
+ static_cast< css::container::XSet* >(this),
+ 0);
+
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt != m_lModels.end())
+ throw css::container::ElementExistException(
+ ::rtl::OUString(),
+ static_cast< css::container::XSet* >(this));
+ m_lModels.push_back(xDoc);
+ aLock.clear();
+ // <- SAFE
+
+ css::uno::Reference< css::document::XDocumentEventBroadcaster > xDocBroadcaster(xDoc, UNO_QUERY );
+ if (xDocBroadcaster.is())
+ xDocBroadcaster->addDocumentEventListener(this);
+ else
+ {
+ // try the "legacy version" of XDocumentEventBroadcaster, which is XEventBroadcaster
+ css::uno::Reference< css::document::XEventBroadcaster > xBroadcaster(xDoc, UNO_QUERY);
+ if (xBroadcaster.is())
+ xBroadcaster->addEventListener(static_cast< css::document::XEventListener* >(this));
+ }
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::remove( const css::uno::Any& aElement )
+ throw (css::lang::IllegalArgumentException ,
+ css::container::NoSuchElementException,
+ css::uno::RuntimeException )
+{
+ css::uno::Reference< css::frame::XModel > xDoc;
+ aElement >>= xDoc;
+ if (!xDoc.is())
+ throw css::lang::IllegalArgumentException(
+ ::rtl::OUString::createFromAscii("Cant locate at least the model parameter."),
+ static_cast< css::container::XSet* >(this),
+ 0);
+
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt == m_lModels.end())
+ throw css::container::NoSuchElementException(
+ ::rtl::OUString(),
+ static_cast< css::container::XSet* >(this));
+ m_lModels.erase(pIt);
+ aLock.clear();
+ // <- SAFE
+
+ css::uno::Reference< css::document::XDocumentEventBroadcaster > xDocBroadcaster(xDoc, UNO_QUERY );
+ if (xDocBroadcaster.is())
+ xDocBroadcaster->removeDocumentEventListener(this);
+ else
+ {
+ // try the "legacy version" of XDocumentEventBroadcaster, which is XEventBroadcaster
+ css::uno::Reference< css::document::XEventBroadcaster > xBroadcaster(xDoc, UNO_QUERY);
+ if (xBroadcaster.is())
+ xBroadcaster->removeEventListener(static_cast< css::document::XEventListener* >(this));
+ }
+}
+
+//-----------------------------------------------------------------------------
+css::uno::Reference< css::container::XEnumeration > SAL_CALL SfxGlobalEvents_Impl::createEnumeration()
+ throw (css::uno::RuntimeException)
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ ModelCollectionEnumeration* pEnum = new ModelCollectionEnumeration(m_xSMGR);
+ pEnum->setModelList(m_lModels);
+ css::uno::Reference< css::container::XEnumeration > xEnum(
+ static_cast< css::container::XEnumeration* >(pEnum),
+ UNO_QUERY);
+ aLock.clear();
+ // <- SAFE
+
+ return xEnum;
+}
+
+//-----------------------------------------------------------------------------
+css::uno::Type SAL_CALL SfxGlobalEvents_Impl::getElementType()
+ throw (css::uno::RuntimeException)
+{
+ return ::getCppuType(static_cast< css::uno::Reference< css::frame::XModel >* >(NULL));
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxGlobalEvents_Impl::hasElements()
+ throw (css::uno::RuntimeException)
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ return (m_lModels.size()>0);
+ // <- SAFE
+}
+
+//-----------------------------------------------------------------------------
+void SfxGlobalEvents_Impl::implts_notifyJobExecution(const css::document::EventObject& aEvent)
+{
+ try
+ {
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ css::uno::Reference< css::document::XEventListener > xJobExecutor(m_xJobExecutorListener);
+ aLock.clear();
+ // <- SAFE
+ if (xJobExecutor.is())
+ xJobExecutor->notifyEvent(aEvent);
+ }
+ catch(const css::uno::RuntimeException& exRun)
+ { throw exRun; }
+ catch(const css::uno::Exception&)
+ {}
+}
+
+//-----------------------------------------------------------------------------
+void SfxGlobalEvents_Impl::implts_checkAndExecuteEventBindings(const css::document::DocumentEvent& aEvent)
+{
+ try
+ {
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ css::uno::Reference< css::container::XNameReplace > xEvents = m_xEvents;
+ aLock.clear();
+ // <- SAFE
+
+ css::uno::Any aAny;
+ if (xEvents.is())
+ aAny = xEvents->getByName(aEvent.EventName);
+ Execute(aAny, aEvent, 0);
+ }
+ catch(const css::uno::RuntimeException& exRun)
+ { throw exRun; }
+ catch(const css::uno::Exception&)
+ {}
+}
+
+//-----------------------------------------------------------------------------
+void SfxGlobalEvents_Impl::implts_notifyListener(const css::document::DocumentEvent& aEvent)
+{
+ // containers are threadsafe
+ css::document::EventObject aLegacyEvent(aEvent.Source, aEvent.EventName);
+ m_aLegacyListeners.notifyEach( &css::document::XEventListener::notifyEvent, aLegacyEvent );
+
+ m_aDocumentListeners.notifyEach( &css::document::XDocumentEventListener::documentEventOccured, aEvent );
+}
+
+//-----------------------------------------------------------------------------
+// not threadsafe ... must be locked from outside!
+TModelList::iterator SfxGlobalEvents_Impl::impl_searchDoc(const css::uno::Reference< css::frame::XModel >& xModel)
+{
+ if (!xModel.is())
+ return m_lModels.end();
+
+ TModelList::iterator pIt;
+ for ( pIt = m_lModels.begin();
+ pIt != m_lModels.end() ;
+ ++pIt )
+ {
+ css::uno::Reference< css::frame::XModel > xContainerDoc(*pIt, UNO_QUERY);
+ if (xContainerDoc == xModel)
+ break;
+ }
+
+ return pIt;
+}
+
diff --git a/sfx2/source/notify/hintpost.cxx b/sfx2/source/notify/hintpost.cxx
new file mode 100644
index 000000000000..d541f5542e3e
--- /dev/null
+++ b/sfx2/source/notify/hintpost.cxx
@@ -0,0 +1,110 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifndef GCC
+#endif
+
+#include "arrdecl.hxx"
+#include <sfx2/hintpost.hxx>
+#include <sfx2/app.hxx>
+#include "sfxtypes.hxx"
+
+//====================================================================
+
+void SfxHintPoster::RegisterEvent()
+{
+ DBG_MEMTEST();
+}
+
+//--------------------------------------------------------------------
+
+SfxHintPoster::SfxHintPoster()
+{
+ RegisterEvent();
+}
+
+//--------------------------------------------------------------------
+
+SfxHintPoster::SfxHintPoster( const GenLink& rLink ):
+ aLink(rLink)
+{
+}
+
+
+//--------------------------------------------------------------------
+
+SfxHintPoster::~SfxHintPoster()
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxHintPoster::Post( SfxHint* pHintToPost )
+{
+ GetpApp()->PostUserEvent( ( LINK(this, SfxHintPoster, DoEvent_Impl) ), pHintToPost );
+ AddRef();
+}
+
+//--------------------------------------------------------------------
+
+IMPL_LINK_INLINE_START( SfxHintPoster, DoEvent_Impl, SfxHint *, pPostedHint )
+{
+ DBG_MEMTEST();
+ Event( pPostedHint );
+ ReleaseRef();
+ return 0;
+}
+IMPL_LINK_INLINE_END( SfxHintPoster, DoEvent_Impl, SfxHint *, pPostedHint )
+
+//--------------------------------------------------------------------
+
+void SfxHintPoster::Event( SfxHint* pPostedHint )
+{
+ aLink.Call( pPostedHint );
+}
+
+//--------------------------------------------------------------------
+
+void SfxHintPoster::SetEventHdl( const GenLink& rLink )
+{
+ DBG_MEMTEST();
+ aLink = rLink;
+}
+
+
+#define LOG( x )
+#if 0
+#define LOG( x ) \
+{ \
+ SvFileStream aStrm( "f:\\temp\\log", STREAM_READWRITE ); \
+ aStrm.Seek( STREAM_SEEK_TO_END ); \
+ aStrm << x.GetStr() << '\n'; \
+}
+#endif
diff --git a/sfx2/source/statbar/stbitem.cxx b/sfx2/source/statbar/stbitem.cxx
new file mode 100644
index 000000000000..68d855cbf6c6
--- /dev/null
+++ b/sfx2/source/statbar/stbitem.cxx
@@ -0,0 +1,692 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <svl/stritem.hxx>
+#ifndef GCC
+#endif
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#include <com/sun/star/frame/status/ItemStatus.hpp>
+#include <com/sun/star/frame/status/ItemState.hpp>
+#include <com/sun/star/awt/MouseButton.hpp>
+
+#include <vcl/status.hxx>
+
+#include <sfx2/app.hxx>
+#include "sfx2/stbitem.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/msg.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/bindings.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/sfx.hrc>
+
+#include <comphelper/processfactory.hxx>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
+#include <toolkit/unohlp.hxx>
+#endif
+#include <toolkit/helper/convert.hxx>
+
+using namespace ::com::sun::star;
+
+//--------------------------------------------------------------------
+
+USHORT SfxStatusBarControl::convertAwtToVCLMouseButtons( sal_Int16 nAwtMouseButtons )
+{
+ USHORT nVCLMouseButtons( 0 );
+
+ if ( nAwtMouseButtons & awt::MouseButton::LEFT )
+ nVCLMouseButtons |= MOUSE_LEFT;
+ if ( nAwtMouseButtons & awt::MouseButton::RIGHT )
+ nVCLMouseButtons |= MOUSE_RIGHT;
+ if ( nAwtMouseButtons & awt::MouseButton::MIDDLE )
+ nVCLMouseButtons |= MOUSE_MIDDLE;
+
+ return nVCLMouseButtons;
+}
+
+//--------------------------------------------------------------------
+
+svt::StatusbarController* SAL_CALL SfxStatusBarControllerFactory(
+ const uno::Reference< frame::XFrame >& rFrame,
+ StatusBar* pStatusBar,
+ unsigned short nID,
+ const ::rtl::OUString& aCommandURL )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ util::URL aTargetURL;
+ aTargetURL.Complete = aCommandURL;
+ uno::Reference < util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString::createFromAscii( "com.sun.star.util.URLTransformer" )), uno::UNO_QUERY );
+ xTrans->parseStrict( aTargetURL );
+
+ SfxObjectShell* pObjShell = NULL;
+ uno::Reference < frame::XController > xController;
+ uno::Reference < frame::XModel > xModel;
+ if ( rFrame.is() )
+ {
+ xController = rFrame->getController();
+ if ( xController.is() )
+ xModel = xController->getModel();
+ }
+
+ if ( xModel.is() )
+ {
+ // Get tunnel from model to retrieve the SfxObjectShell pointer from it
+ ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( xModel, uno::UNO_QUERY );
+ ::com::sun::star::uno::Sequence < sal_Int8 > aSeq = SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence();
+ if ( xObj.is() )
+ {
+ sal_Int64 nHandle = xObj->getSomething( aSeq );
+ if ( nHandle )
+ pObjShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
+ }
+ }
+
+ SfxModule* pModule = pObjShell ? pObjShell->GetModule() : NULL;
+ SfxSlotPool* pSlotPool = 0;
+
+ if ( pModule )
+ pSlotPool = pModule->GetSlotPool();
+ else
+ pSlotPool = &(SfxSlotPool::GetSlotPool( NULL ));
+
+ const SfxSlot* pSlot = pSlotPool->GetUnoSlot( aTargetURL.Path );
+ if ( pSlot )
+ {
+ USHORT nSlotId = pSlot->GetSlotId();
+ if ( nSlotId > 0 )
+ {
+ rtl::OString aCmd(".uno:");
+ aCmd += pSlot->GetUnoName();
+ pStatusBar->SetHelpId( nSlotId, aCmd );
+ return SfxStatusBarControl::CreateControl( nSlotId, nID, pStatusBar, pModule );
+ }
+ }
+
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+
+SfxStatusBarControl::SfxStatusBarControl
+(
+ USHORT nSlotID, /* Slot-Id, mit der diese Instanz
+ verbunden wird. Wurde bei der
+ Registrierung eine Slot-Id != 0
+ angegeben, ist dies immer die dort
+ angegebene. */
+ USHORT nCtrlID, /* ID of this controller in the status bar */
+
+ StatusBar& rBar /* Referenz auf die StatusBar, f"ur die
+ dieses Control erzeugt wurde. */
+)
+
+/* [Beschreibung]
+
+ Konstruktor der Klasse SfxStatusBarControl. Die Subclasses werden
+ bei Bedarf per Factory vom SFx erzeugt.
+
+ Instanzen dieser Basisklasse werden f"ur alle StatusBar-Felder
+ erzeugt, f"ur die keine speziellen registriert wurden.
+*/
+
+: svt::StatusbarController(),
+ nSlotId( nSlotID ),
+ nId( nCtrlID ),
+ pBar( &rBar )
+{
+}
+
+//--------------------------------------------------------------------
+
+SfxStatusBarControl::~SfxStatusBarControl()
+
+/* [Beschreibung]
+
+ Destruktor der Klasse SfxStatusBarControl. Die Instanzen dieser
+ Klasse und deren Subklassen werden vom SFx zerst"ort.
+*/
+
+{}
+
+//--------------------------------------------------------------------
+// XInterface
+uno::Any SAL_CALL SfxStatusBarControl::queryInterface( const uno::Type & rType )
+throw( uno::RuntimeException)
+{
+ return svt::StatusbarController::queryInterface( rType );
+}
+
+void SAL_CALL SfxStatusBarControl::acquire() throw()
+{
+ OWeakObject::acquire();
+}
+
+void SAL_CALL SfxStatusBarControl::release() throw()
+{
+ OWeakObject::release();
+}
+
+//--------------------------------------------------------------------
+// XEventListener
+void SAL_CALL SfxStatusBarControl::disposing( const lang::EventObject& aEvent )
+throw( uno::RuntimeException )
+{
+ svt::StatusbarController::disposing( aEvent );
+}
+
+//--------------------------------------------------------------------
+// XComponent
+void SAL_CALL SfxStatusBarControl::dispose()
+throw (uno::RuntimeException)
+{
+ svt::StatusbarController::dispose();
+}
+
+//--------------------------------------------------------------------
+// XStatusListener
+void SAL_CALL SfxStatusBarControl::statusChanged( const frame::FeatureStateEvent& rEvent )
+throw ( ::com::sun::star::uno::RuntimeException )
+{
+ SfxViewFrame* pViewFrame = NULL;
+ uno::Reference < frame::XController > xController;
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_xFrame.is() )
+ xController = m_xFrame->getController();
+
+ uno::Reference < frame::XDispatchProvider > xProvider( xController, uno::UNO_QUERY );
+ if ( xProvider.is() )
+ {
+ uno::Reference < frame::XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, ::rtl::OUString(), 0 );
+ if ( xDisp.is() )
+ {
+ uno::Reference< lang::XUnoTunnel > xTunnel( xDisp, uno::UNO_QUERY );
+ SfxOfficeDispatch* pDisp = NULL;
+ if ( xTunnel.is() )
+ {
+ sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
+ pDisp = reinterpret_cast< SfxOfficeDispatch* >(sal::static_int_cast< sal_IntPtr >( nImplementation ));
+ }
+
+ if ( pDisp )
+ pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
+ }
+ }
+
+ USHORT nSlotID = 0;
+ SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
+ const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
+ if ( pSlot )
+ nSlotID = pSlot->GetSlotId();
+
+ if ( nSlotID > 0 )
+ {
+ if ( rEvent.Requery )
+ svt::StatusbarController::statusChanged( rEvent );
+ else
+ {
+ SfxItemState eState = SFX_ITEM_DISABLED;
+ SfxPoolItem* pItem = NULL;
+ if ( rEvent.IsEnabled )
+ {
+ eState = SFX_ITEM_AVAILABLE;
+ uno::Type pType = rEvent.State.getValueType();
+
+ if ( pType == ::getVoidCppuType() )
+ {
+ pItem = new SfxVoidItem( nSlotID );
+ eState = SFX_ITEM_UNKNOWN;
+ }
+ else if ( pType == ::getBooleanCppuType() )
+ {
+ sal_Bool bTemp = 0;
+ rEvent.State >>= bTemp ;
+ pItem = new SfxBoolItem( nSlotID, bTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt16*)0) )
+ {
+ sal_uInt16 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ pItem = new SfxUInt16Item( nSlotID, nTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt32*)0) )
+ {
+ sal_uInt32 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ pItem = new SfxUInt32Item( nSlotID, nTemp );
+ }
+ else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
+ {
+ ::rtl::OUString sTemp ;
+ rEvent.State >>= sTemp ;
+ pItem = new SfxStringItem( nSlotID, sTemp );
+ }
+ else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
+ {
+ frame::status::ItemStatus aItemStatus;
+ rEvent.State >>= aItemStatus;
+ eState = aItemStatus.State;
+ pItem = new SfxVoidItem( nSlotID );
+ }
+ else
+ {
+ if ( pSlot )
+ pItem = pSlot->GetType()->CreateItem();
+ if ( pItem )
+ {
+ pItem->SetWhich( nSlotID );
+ pItem->PutValue( rEvent.State );
+ }
+ else
+ pItem = new SfxVoidItem( nSlotID );
+ }
+ }
+
+ StateChanged( nSlotID, eState, pItem );
+ delete pItem;
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+// XStatusbarController
+
+::sal_Bool SAL_CALL SfxStatusBarControl::mouseButtonDown(
+ const awt::MouseEvent& rMouseEvent )
+throw ( uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ ::Point aPos( rMouseEvent.X, rMouseEvent.Y );
+
+ ::MouseEvent aMouseEvent( aPos,
+ (USHORT)rMouseEvent.ClickCount,
+ 0,
+ convertAwtToVCLMouseButtons( rMouseEvent.Buttons ),
+ 0 );
+
+ return MouseButtonDown( aMouseEvent );
+}
+
+//--------------------------------------------------------------------
+
+::sal_Bool SAL_CALL SfxStatusBarControl::mouseMove(
+ const awt::MouseEvent& rMouseEvent )
+throw (uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ ::Point aPos( rMouseEvent.X, rMouseEvent.Y );
+
+ ::MouseEvent aMouseEvent( aPos,
+ (USHORT)rMouseEvent.ClickCount,
+ 0,
+ convertAwtToVCLMouseButtons( rMouseEvent.Buttons ),
+ 0 );
+ return MouseMove( aMouseEvent );
+}
+
+//--------------------------------------------------------------------
+
+::sal_Bool SAL_CALL SfxStatusBarControl::mouseButtonUp(
+ const ::awt::MouseEvent& rMouseEvent )
+throw ( uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ ::Point aPos( rMouseEvent.X, rMouseEvent.Y );
+
+ ::MouseEvent aMouseEvent( aPos,
+ (USHORT)rMouseEvent.ClickCount,
+ 0,
+ convertAwtToVCLMouseButtons( rMouseEvent.Buttons ),
+ 0 );
+ return MouseButtonUp( aMouseEvent );
+}
+
+//--------------------------------------------------------------------
+
+void SAL_CALL SfxStatusBarControl::command(
+ const awt::Point& rPos,
+ ::sal_Int32 nCommand,
+ ::sal_Bool /*bMouseEvent*/,
+ const ::com::sun::star::uno::Any& /*aData*/ )
+throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ ::Point aPos( rPos.X, rPos.Y );
+ CommandEvent aCmdEvent( aPos, (USHORT)nCommand, TRUE, NULL );
+
+ Command( aCmdEvent );
+}
+
+//--------------------------------------------------------------------
+
+void SAL_CALL SfxStatusBarControl::paint(
+ const uno::Reference< awt::XGraphics >& xGraphics,
+ const awt::Rectangle& rOutputRectangle,
+ ::sal_Int32 nItemId,
+ ::sal_Int32 nStyle )
+throw ( ::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( xGraphics );;
+ if ( pOutDev )
+ {
+ ::Rectangle aRect = VCLRectangle( rOutputRectangle );
+ UserDrawEvent aUserDrawEvent( pOutDev, aRect, (USHORT)nItemId, (USHORT)nStyle );
+ Paint( aUserDrawEvent );
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SAL_CALL SfxStatusBarControl::click()
+throw ( uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ Click();
+}
+
+//--------------------------------------------------------------------
+
+void SAL_CALL SfxStatusBarControl::doubleClick()
+throw ( uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ DoubleClick();
+}
+
+//--------------------------------------------------------------------
+// old sfx2 interface
+//--------------------------------------------------------------------
+
+void SfxStatusBarControl::StateChanged
+(
+ USHORT nSID,
+ SfxItemState eState,
+ const SfxPoolItem* pState /* Zeiger auf ein SfxPoolItem, welches nur
+ innerhalb dieses Methodenaufrufs g"ultig
+ ist. Es kann ein 0-Pointer, ein Pointer
+ auf ein SfxVoidItem oder auf den Typ, f"ur
+ den die Subclass von SfxStatusBarControl
+ registriert ist vorkommen. */
+)
+
+/* [Beschreibung]
+
+ Die Basisimplementation versteht Items vom Type SfxStringItem, bei
+ denen der Text in das Status-Zeilen-Feld eingetragen wird und
+ SfxVoidItem, bei denen das Feld geleert wird. Die Basisimplementierng
+ sollte in "uberladenen Methoden nicht gerufen werden.
+*/
+
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pBar != 0, "setting state to dangling StatusBar" );
+
+ const SfxStringItem* pStr = PTR_CAST( SfxStringItem, pState );
+ if ( eState == SFX_ITEM_AVAILABLE && pStr )
+ pBar->SetItemText( nSID, pStr->GetValue() );
+ else
+ {
+ DBG_ASSERT( eState != SFX_ITEM_AVAILABLE || pState->ISA(SfxVoidItem),
+ "wrong SfxPoolItem subclass in SfxStatusBarControl" );
+ pBar->SetItemText( nSID, String() );
+ }
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxStatusBarControl::MouseButtonDown( const MouseEvent & )
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode ist eine Weiterleitung des Events
+ MouseButtonDown() der StatusBar, falls die Maus-Position innerhalb
+ des Bereichs des betreffenden Items ist, oder die Maus von diesem
+ Control mit <SfxStatusBarControl::CaptureMouse()> gecaptured wurde.
+
+ Die Defaultimplementierung ist leer und gibt FALSE zur"uck.
+
+
+ [Rueckgabewert]
+
+ BOOL TRUE
+ das Event wurde bearbeitet und soll nicht an
+ die StatusBar weitergeleitet werden
+
+ FALSE
+ das Event wurde nicht bearbeitet und soll an
+ die StatusBar weitergeleitet werden
+*/
+
+{
+ return FALSE;
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxStatusBarControl::MouseMove( const MouseEvent & )
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode ist eine Weiterleitung des Events
+ MouseMove() der StatusBar, falls die Maus-Position innerhalb
+ des Bereichs des betreffenden Items ist, oder die Maus von diesem
+ Control mit <SfxStatusBarControl::CaptureMouse()> gecaptured wurde.
+
+ Die Defaultimplementierung ist leer und gibt FALSE zur"uck.
+
+
+ [Rueckgabewert]
+
+ BOOL TRUE
+ das Event wurde bearbeitet und soll nicht an
+ die StatusBar weitergeleitet werden
+
+ FALSE
+ das Event wurde nicht bearbeitet und soll an
+ die StatusBar weitergeleitet werden
+*/
+
+{
+ return FALSE;
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxStatusBarControl::MouseButtonUp( const MouseEvent & )
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode ist eine Weiterleitung des Events
+ MouseButtonUp() der StatusBar, falls die Maus-Position innerhalb
+ des Bereichs des betreffenden Items ist, oder die Maus von diesem
+ Control mit <SfxStatusBarControl::CaptureMouse()> gecaptured wurde.
+
+ Die Defaultimplementierung ist leer und gibt FALSE zur"uck.
+
+
+ [Rueckgabewert]
+
+ BOOL TRUE
+ das Event wurde bearbeitet und soll nicht an
+ die StatusBar weitergeleitet werden
+
+ FALSE
+ das Event wurde nicht bearbeitet und soll an
+ die StatusBar weitergeleitet werden
+*/
+
+{
+ return FALSE;
+}
+
+//--------------------------------------------------------------------
+
+void SfxStatusBarControl::Command( const CommandEvent& )
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode wird gerufen, wenn f"ur dieses SfxStatusBarControl
+ ein CommandEvent f"ur erkannt wurde.
+
+ Die Defaultimplementierung ist leer.
+*/
+
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxStatusBarControl::Click()
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode wird gerufen, wenn der Anwender mit der Maus
+ in das zu diesem Control geh"orige Feld der Statuszeile klickt.
+
+ Die Defaultimplementierung ist leer.
+*/
+
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxStatusBarControl::DoubleClick()
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode wird gerufen, wenn der Anwender mit der Maus
+ in das zu diesem Control geh"orige Feld der Statuszeile doppel-klickt.
+*/
+
+{
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
+ execute( aArgs );
+}
+
+//--------------------------------------------------------------------
+
+void SfxStatusBarControl::Paint
+(
+ const UserDrawEvent& /* Referenz auf einen UserDrawEvent */
+)
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode wird gerufen, falls das betreffende Feld
+ mit SIB_USERDRAW gekennzeichnet ist, um den Inhalt zu zeichnen.
+ Die Ausgabe mu"s auf dem in durch rUDEvt.GetDevice() erh"altlichen
+ OutputDevice innerhalb des durch rUDEvt.GetRect() angegebenenen
+ Rechtecks erfolgen.
+
+ Die Defaultimplementierung ist leer.
+*/
+
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxStatusBarControl::CaptureMouse()
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxStatusBarControl::ReleaseMouse()
+{
+}
+
+//--------------------------------------------------------------------
+
+SfxStatusBarControl* SfxStatusBarControl::CreateControl
+(
+ USHORT nSlotID,
+ USHORT nStbId,
+ StatusBar* pBar,
+ SfxModule* pMod
+)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ SfxApplication *pApp = SFX_APP();
+
+ SfxSlotPool *pSlotPool;
+ if ( pMod )
+ pSlotPool = pMod->GetSlotPool();
+ else
+ pSlotPool = &SfxSlotPool::GetSlotPool();
+
+ TypeId aSlotType = pSlotPool->GetSlotType(nSlotID);
+ if ( aSlotType )
+ {
+ if ( pMod )
+ {
+ SfxStbCtrlFactArr_Impl *pFactories = pMod->GetStbCtrlFactories_Impl();
+ if ( pFactories )
+ {
+ SfxStbCtrlFactArr_Impl &rFactories = *pFactories;
+ for ( USHORT nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ if ( rFactories[nFactory]->nTypeId == aSlotType &&
+ ( ( rFactories[nFactory]->nSlotId == 0 ) ||
+ ( rFactories[nFactory]->nSlotId == nSlotID) ) )
+ return rFactories[nFactory]->pCtor( nSlotID, nStbId, *pBar );
+ }
+ }
+
+ SfxStbCtrlFactArr_Impl &rFactories = pApp->GetStbCtrlFactories_Impl();
+ for ( USHORT nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
+ if ( rFactories[nFactory]->nTypeId == aSlotType &&
+ ( ( rFactories[nFactory]->nSlotId == 0 ) ||
+ ( rFactories[nFactory]->nSlotId == nSlotID) ) )
+ return rFactories[nFactory]->pCtor( nSlotID, nStbId, *pBar );
+ }
+
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+void SfxStatusBarControl::RegisterStatusBarControl(SfxModule* pMod, SfxStbCtrlFactory* pFact)
+{
+ SFX_APP()->RegisterStatusBarControl_Impl( pMod, pFact );
+}
+//--------------------------------------------------------------------
diff --git a/sfx2/source/toolbox/imgmgr.cxx b/sfx2/source/toolbox/imgmgr.cxx
new file mode 100644
index 000000000000..231baa76fc76
--- /dev/null
+++ b/sfx2/source/toolbox/imgmgr.cxx
@@ -0,0 +1,426 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <stdio.h>
+#include <hash_map>
+
+#include "sfx2/imgmgr.hxx"
+#include <sfx2/sfx.hrc>
+#include <sfx2/app.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/bindings.hxx>
+#include "statcach.hxx"
+#include <sfx2/module.hxx>
+#include <vcl/bitmap.hxx>
+#include <vcl/toolbox.hxx>
+
+#include <tools/rcid.h>
+#include <tools/link.hxx>
+#include <svtools/miscopt.hxx>
+#include <vos/mutex.hxx>
+
+#ifndef GCC
+#endif
+
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+
+const sal_uInt32 IMAGELIST_COUNT = 4; // small, small-hi, large, large-hi
+
+struct ToolBoxInf_Impl
+{
+ ToolBox* pToolBox;
+ USHORT nFlags;
+};
+
+class SfxImageManager_Impl
+{
+public:
+ sal_Int16 m_nSymbolsSize;
+ SvtMiscOptions m_aOpt;
+ std::vector< ToolBoxInf_Impl* > m_aToolBoxes;
+ ImageList* m_pImageList[IMAGELIST_COUNT];
+ SfxModule* m_pModule;
+
+ ImageList* GetImageList( BOOL bBig, BOOL bHiContrast );
+ Image GetImage( USHORT nId, BOOL bBig, BOOL bHiContrast );
+ void SetSymbolsSize_Impl( sal_Int16 );
+
+ DECL_LINK( OptionsChanged_Impl, void* );
+ DECL_LINK( SettingsChanged_Impl, void* );
+
+
+ SfxImageManager_Impl( SfxModule* pModule );
+ ~SfxImageManager_Impl();
+};
+
+typedef std::hash_map< sal_Int64, sal_Int64 > SfxImageManagerMap;
+
+// global image lists
+static SfxImageManager_Impl* pGlobalImageManager = 0;
+static SfxImageManagerMap m_ImageManager_ImplMap;
+static SfxImageManagerMap m_ImageManagerMap;
+static ImageList* pImageListSmall=0;
+static ImageList* pImageListBig=0;
+static ImageList* pImageListHiSmall=0;
+static ImageList* pImageListHiBig=0;
+
+static SfxImageManager_Impl* GetImageManager( SfxModule* pModule )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ if ( pModule == 0 )
+ {
+ if ( !pGlobalImageManager )
+ pGlobalImageManager = new SfxImageManager_Impl( 0 );
+ return pGlobalImageManager;
+ }
+ else
+ {
+ SfxImageManager_Impl* pImpl( 0 );
+ SfxImageManagerMap::const_iterator pIter = m_ImageManager_ImplMap.find( sal::static_int_cast< sal_Int64>( reinterpret_cast< sal_IntPtr >( pModule )));
+ if ( pIter != m_ImageManager_ImplMap.end() )
+ pImpl = reinterpret_cast< SfxImageManager_Impl* >( sal::static_int_cast< sal_IntPtr >( pIter->second ));
+ else
+ {
+ pImpl = new SfxImageManager_Impl( pModule );
+ m_ImageManager_ImplMap.insert(
+ SfxImageManagerMap::value_type(
+ sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( pModule )),
+ sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( pImpl )) ));
+ }
+ return pImpl;
+ }
+}
+
+// Global image list
+static ImageList* GetImageList( BOOL bBig, BOOL bHiContrast )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ // Has to be changed if we know how the IDs are named!!!
+ ImageList*& rpList = bBig ? ( bHiContrast ? pImageListHiBig : pImageListBig ) :
+ ( bHiContrast ? pImageListHiSmall : pImageListSmall );
+ if ( !rpList )
+ {
+ ResMgr *pResMgr = SfxApplication::GetOrCreate()->GetOffResManager_Impl();
+
+ ResId aResId( bBig ? ( bHiContrast ? RID_DEFAULTIMAGELIST_LCH : RID_DEFAULTIMAGELIST_LC ) :
+ ( bHiContrast ? RID_DEFAULTIMAGELIST_SCH : RID_DEFAULTIMAGELIST_SC ), *pResMgr);
+
+ aResId.SetRT( RSC_IMAGELIST );
+
+ DBG_ASSERT( pResMgr->IsAvailable(aResId), "No default ImageList!" );
+
+ if ( pResMgr->IsAvailable(aResId) )
+ rpList = new ImageList( aResId );
+ else
+ rpList = new ImageList();
+ }
+
+ return rpList;
+}
+
+static sal_Int16 impl_convertBools( sal_Bool bLarge, sal_Bool bHiContrast )
+{
+ sal_Int16 nIndex( 0 );
+ if ( bLarge )
+ nIndex += 1;
+ if ( bHiContrast )
+ nIndex += 2;
+ return nIndex;
+}
+
+//=========================================================================
+
+SfxImageManager_Impl::SfxImageManager_Impl( SfxModule* pModule ) :
+ m_nSymbolsSize( SvtMiscOptions().GetCurrentSymbolsSize() ),
+ m_pModule( pModule )
+{
+ for ( sal_uInt32 i = 0; i < IMAGELIST_COUNT; i++ )
+ m_pImageList[i] = 0;
+
+ m_aOpt.AddListenerLink( LINK( this, SfxImageManager_Impl, OptionsChanged_Impl ) );
+ Application::AddEventListener( LINK( this, SfxImageManager_Impl, SettingsChanged_Impl ) );
+}
+
+//-------------------------------------------------------------------------
+
+SfxImageManager_Impl::~SfxImageManager_Impl()
+{
+ m_aOpt.RemoveListenerLink( LINK( this, SfxImageManager_Impl, OptionsChanged_Impl ) );
+ Application::RemoveEventListener( LINK( this, SfxImageManager_Impl, SettingsChanged_Impl ) );
+
+ for ( sal_uInt32 i = 0; i < m_aToolBoxes.size(); i++ )
+ delete m_aToolBoxes[i];
+}
+
+//-------------------------------------------------------------------------
+
+ImageList* SfxImageManager_Impl::GetImageList( BOOL bBig, BOOL bHiContrast )
+{
+ sal_Int32 nIndex = impl_convertBools( bBig, bHiContrast );
+ if ( !m_pImageList[nIndex] )
+ {
+ if ( !m_pModule )
+ m_pImageList[nIndex] = ::GetImageList( bBig, bHiContrast );
+ else
+ m_pImageList[nIndex] = m_pModule->GetImageList_Impl( bBig, bHiContrast );
+ }
+
+ return m_pImageList[nIndex];
+}
+
+//-------------------------------------------------------------------------
+
+Image SfxImageManager_Impl::GetImage( USHORT nId, BOOL bBig, BOOL bHiContrast )
+{
+ ImageList* pImageList = GetImageList( bBig, bHiContrast );
+ if ( pImageList )
+ return pImageList->GetImage( nId );
+ return Image();
+}
+
+//-------------------------------------------------------------------------
+
+void SfxImageManager_Impl::SetSymbolsSize_Impl( sal_Int16 nNewSymbolsSize )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ if ( nNewSymbolsSize != m_nSymbolsSize )
+ {
+ m_nSymbolsSize = nNewSymbolsSize;
+ BOOL bLarge( m_nSymbolsSize == SFX_SYMBOLS_SIZE_LARGE );
+
+ for ( sal_uInt32 n=0; n < m_aToolBoxes.size(); n++ )
+ {
+ ToolBoxInf_Impl *pInf = m_aToolBoxes[n];
+ if ( pInf->nFlags & SFX_TOOLBOX_CHANGESYMBOLSET )
+ {
+ ToolBox *pBox = pInf->pToolBox;
+ BOOL bHiContrast = pBox->GetSettings().GetStyleSettings().GetHighContrastMode();
+ USHORT nCount = pBox->GetItemCount();
+ for ( USHORT nPos=0; nPos<nCount; nPos++ )
+ {
+ USHORT nId = pBox->GetItemId( nPos );
+ if ( pBox->GetItemType(nPos) == TOOLBOXITEM_BUTTON )
+ {
+ pBox->SetItemImage( nId, GetImage( nId, bLarge, bHiContrast ) );
+ SfxStateCache *pCache = SfxViewFrame::Current()->GetBindings().GetStateCache( nId );
+ if ( pCache )
+ pCache->SetCachedState();
+ }
+ }
+
+ if ( !pBox->IsFloatingMode() )
+ {
+ Size aActSize( pBox->GetSizePixel() );
+ Size aSize( pBox->CalcWindowSizePixel() );
+ if ( pBox->IsHorizontal() )
+ aSize.Width() = aActSize.Width();
+ else
+ aSize.Height() = aActSize.Height();
+
+ pBox->SetSizePixel( aSize );
+ }
+ }
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxImageManager_Impl, OptionsChanged_Impl, void*, EMPTYARG )
+{
+ SetSymbolsSize_Impl( SvtMiscOptions().GetCurrentSymbolsSize() );
+ return 0L;
+}
+
+//-------------------------------------------------------------------------
+
+IMPL_LINK( SfxImageManager_Impl, SettingsChanged_Impl, void*, EMPTYARG )
+{
+ // Check if toolbar button size have changed and we have to use system settings
+ sal_Int16 nSymbolsSize = SvtMiscOptions().GetCurrentSymbolsSize();
+ if ( m_nSymbolsSize != nSymbolsSize )
+ SetSymbolsSize_Impl( nSymbolsSize );
+ return 0L;
+}
+
+//-------------------------------------------------------------------------
+
+//=========================================================================
+
+SfxImageManager::SfxImageManager( SfxModule* pModule )
+{
+ pImp = ::GetImageManager( pModule );
+}
+
+//-------------------------------------------------------------------------
+
+SfxImageManager::~SfxImageManager()
+{
+}
+
+//-------------------------------------------------------------------------
+
+SfxImageManager* SfxImageManager::GetImageManager( SfxModule* pModule )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ SfxImageManagerMap::const_iterator pIter =
+ m_ImageManagerMap.find( sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( pModule )));
+ if ( pIter != m_ImageManagerMap.end() )
+ return reinterpret_cast< SfxImageManager* >( sal::static_int_cast< sal_IntPtr >( pIter->second ));
+ else
+ {
+ SfxImageManager* pSfxImageManager = new SfxImageManager( pModule );
+ m_ImageManagerMap.insert( SfxImageManagerMap::value_type(
+ sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( pModule )),
+ sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( pSfxImageManager )) ));
+ return pSfxImageManager;
+ }
+}
+
+//-------------------------------------------------------------------------
+
+Image SfxImageManager::GetImage( USHORT nId, BOOL bBig, BOOL bHiContrast ) const
+{
+ ImageList* pImageList = pImp->GetImageList( bBig, bHiContrast );
+ if ( pImageList && pImageList->HasImageAtPos( nId ) )
+ return pImageList->GetImage( nId );
+ return Image();
+}
+
+//-------------------------------------------------------------------------
+
+Image SfxImageManager::GetImage( USHORT nId, BOOL bHiContrast ) const
+{
+ BOOL bLarge = SvtMiscOptions().AreCurrentSymbolsLarge();
+ return GetImage( nId, bLarge, bHiContrast );
+}
+
+//-------------------------------------------------------------------------
+
+Image SfxImageManager::SeekImage( USHORT nId, BOOL bBig, BOOL bHiContrast ) const
+{
+ sal_Bool bGlobal = ( pImp->m_pModule == 0 );
+ ImageList* pImageList = pImp->GetImageList( bBig, bHiContrast );
+ if ( pImageList && pImageList->HasImageAtPos( nId ) )
+ return pImageList->GetImage( nId );
+ else if ( !bGlobal )
+ {
+ pImageList = ::GetImageManager( 0 )->GetImageList( bBig, bHiContrast );
+ if ( pImageList )
+ return pImageList->GetImage( nId );
+ }
+ return Image();
+}
+
+//-------------------------------------------------------------------------
+
+Image SfxImageManager::SeekImage( USHORT nId, BOOL bHiContrast ) const
+{
+ BOOL bLarge = SvtMiscOptions().AreCurrentSymbolsLarge();
+ return SeekImage( nId, bLarge, bHiContrast );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxImageManager::RegisterToolBox( ToolBox *pBox, USHORT nFlags )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ ToolBoxInf_Impl* pInf = new ToolBoxInf_Impl;
+ pInf->pToolBox = pBox;
+ pInf->nFlags = nFlags;
+ pImp->m_aToolBoxes.push_back( pInf );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxImageManager::ReleaseToolBox( ToolBox *pBox )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ for ( sal_uInt32 n=0; n < pImp->m_aToolBoxes.size(); n++ )
+ {
+ if ((pImp->m_aToolBoxes[n])->pToolBox == pBox )
+ {
+ delete pImp->m_aToolBoxes[n];
+ pImp->m_aToolBoxes.erase( pImp->m_aToolBoxes.begin() + n );
+ return;
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+void SfxImageManager::SetImages( ToolBox& rToolBox, BOOL bHiContrast, BOOL bLarge )
+{
+ SetImagesForceSize( rToolBox, bLarge, bHiContrast );
+}
+
+//-------------------------------------------------------------------------
+
+void SfxImageManager::SetImagesForceSize( ToolBox& rToolBox, BOOL bHiContrast, BOOL bLarge )
+{
+ ImageList* pImageList = pImp->GetImageList( bLarge, bHiContrast );
+
+ USHORT nCount = rToolBox.GetItemCount();
+ for (USHORT n=0; n<nCount; n++)
+ {
+ USHORT nId = rToolBox.GetItemId(n);
+ switch ( rToolBox.GetItemType(n) )
+ {
+ case TOOLBOXITEM_BUTTON:
+ {
+ if ( pImageList && pImageList->HasImageAtPos( nId ) )
+ rToolBox.SetItemImage( nId, pImageList->GetImage( nId ));
+ else
+ rToolBox.SetItemImage( nId, Image() );
+ }
+
+ case TOOLBOXITEM_SEPARATOR:
+ case TOOLBOXITEM_SPACE:
+ case TOOLBOXITEM_BREAK:
+ default:
+ break;
+ }
+ }
+}
+
+void SfxImageManager::SetImages( ToolBox& rToolBox )
+{
+ BOOL bLarge = ( pImp->m_nSymbolsSize == SFX_SYMBOLS_SIZE_LARGE );
+ BOOL bHiContrast = rToolBox.GetSettings().GetStyleSettings().GetHighContrastMode();
+ SetImagesForceSize( rToolBox, bHiContrast, bLarge );
+}
diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx
new file mode 100644
index 000000000000..7cc25c872eb1
--- /dev/null
+++ b/sfx2/source/toolbox/tbxitem.cxx
@@ -0,0 +1,1895 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#ifdef SOLARIS
+// HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
+#include <ctime>
+#endif
+
+#include <string> // prevent conflict with STL includes
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/document/UpdateDocMode.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/XLayoutManager.hpp>
+#include <com/sun/star/frame/status/ItemStatus.hpp>
+#include <com/sun/star/frame/status/ItemState.hpp>
+#include <com/sun/star/ui/XUIElementFactory.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/ui/XUIFunctionListener.hpp>
+#include <com/sun/star/frame/status/Visibility.hpp>
+#include <com/sun/star/document/CorruptedFilterConfigurationException.hpp>
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/imageitm.hxx>
+#include <svl/visitem.hxx>
+#include <svl/urlbmk.hxx>
+#include <vcl/toolbox.hxx>
+#include <unotools/moduleoptions.hxx>
+
+#include <svtools/imagemgr.hxx>
+#include <comphelper/processfactory.hxx>
+#include <framework/addonmenu.hxx>
+#include <framework/addonsoptions.hxx>
+#include <framework/menuconfiguration.hxx>
+#include <framework/sfxhelperfunctions.hxx>
+#include <vcl/taskpanelist.hxx>
+#ifndef _TOOLKIT_UNOHLP_HXX
+#include <toolkit/helper/vclunohelper.hxx>
+#endif
+#include <svtools/menuoptions.hxx>
+#include <svtools/miscopt.hxx>
+
+#ifndef GCC
+#endif
+
+#include <sfx2/tbxctrl.hxx>
+#include <sfx2/mnumgr.hxx>
+#include <sfx2/dispatch.hxx>
+#include "fltfnc.hxx"
+#include <sfx2/msg.hxx>
+#include <sfx2/msgpool.hxx>
+#include "statcach.hxx"
+#include <sfx2/viewfrm.hxx>
+#include "arrdecl.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/macrconf.hxx>
+#include <sfx2/genlink.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/sfx.hrc>
+#include <sfx2/module.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfac.hxx>
+#include "referers.hxx"
+#include <sfx2/frmhtmlw.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/unoctitm.hxx>
+#include "helpid.hrc"
+#include "workwin.hxx"
+#include "sfx2/imgmgr.hxx"
+#include "virtmenu.hxx"
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/module.hxx>
+#include "sfx2/imagemgr.hxx"
+
+#include <comphelper/uieventslogger.hxx>
+#include <com/sun/star/frame/XModuleManager.hpp>
+
+//using namespace ::com::sun::star::awt;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::frame::status;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::ui;
+
+//====================================================================
+
+SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, TRUE);
+SFX_IMPL_TOOLBOX_CONTROL(SfxAppToolBoxControl_Impl, SfxStringItem);
+
+static Window* GetTopMostParentSystemWindow( Window* pWindow )
+{
+ OSL_ASSERT( pWindow );
+ if ( pWindow )
+ {
+ // ->manually search topmost system window
+ // required because their might be another system window between this and the top window
+ pWindow = pWindow->GetParent();
+ SystemWindow* pTopMostSysWin = NULL;
+ while ( pWindow )
+ {
+ if ( pWindow->IsSystemWindow() )
+ pTopMostSysWin = (SystemWindow*)pWindow;
+ pWindow = pWindow->GetParent();
+ }
+ pWindow = pTopMostSysWin;
+ OSL_ASSERT( pWindow );
+ return pWindow;
+ }
+
+ return NULL;
+}
+
+svt::ToolboxController* SAL_CALL SfxToolBoxControllerFactory( const Reference< XFrame >& rFrame, ToolBox* pToolbox, unsigned short nID, const ::rtl::OUString& aCommandURL )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ URL aTargetURL;
+ aTargetURL.Complete = aCommandURL;
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( aTargetURL );
+ if ( aTargetURL.Arguments.getLength() )
+ return NULL;
+
+ SfxObjectShell* pObjShell = NULL;
+ Reference < XController > xController;
+ Reference < XModel > xModel;
+ if ( rFrame.is() )
+ {
+ xController = rFrame->getController();
+ if ( xController.is() )
+ xModel = xController->getModel();
+ }
+
+ if ( xModel.is() )
+ {
+ // Get tunnel from model to retrieve the SfxObjectShell pointer from it
+ ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( xModel, UNO_QUERY );
+ if ( xObj.is() )
+ {
+ ::com::sun::star::uno::Sequence < sal_Int8 > aSeq = SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence();
+ sal_Int64 nHandle = xObj->getSomething( aSeq );
+ if ( nHandle )
+ pObjShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
+ }
+ }
+
+ SfxModule* pModule = pObjShell ? pObjShell->GetModule() : NULL;
+ SfxSlotPool* pSlotPool = 0;
+
+ if ( pModule )
+ pSlotPool = pModule->GetSlotPool();
+ else
+ pSlotPool = &(SfxSlotPool::GetSlotPool( NULL ));
+
+ const SfxSlot* pSlot = pSlotPool->GetUnoSlot( aTargetURL.Path );
+ if ( pSlot )
+ {
+ USHORT nSlotId = pSlot->GetSlotId();
+ if ( nSlotId > 0 )
+ return SfxToolBoxControl::CreateControl( nSlotId, nID, pToolbox, pModule );
+ }
+
+ return NULL;
+}
+
+struct SfxToolBoxControl_Impl
+{
+ ToolBox* pBox;
+ BOOL bShowString;
+ USHORT nSelectModifier;
+ SfxTbxCtrlFactory* pFact;
+ USHORT nTbxId;
+ USHORT nSlotId;
+ SfxPopupWindow* mpFloatingWindow;
+ SfxPopupWindow* mpPopupWindow;
+ Reference< XUIElement > mxUIElement;
+
+ DECL_LINK( WindowEventListener, VclSimpleEvent* );
+};
+
+IMPL_LINK( SfxToolBoxControl_Impl, WindowEventListener, VclSimpleEvent*, pEvent )
+{
+ if ( pEvent &&
+ pEvent->ISA( VclWindowEvent ) &&
+ (( pEvent->GetId() == VCLEVENT_WINDOW_MOVE ) ||
+ ( pEvent->GetId() == VCLEVENT_WINDOW_ACTIVATE )))
+ {
+ Window* pWindow( ((VclWindowEvent*)pEvent)->GetWindow() );
+ if (( pWindow == mpFloatingWindow ) &&
+ ( mpPopupWindow != 0 ))
+ {
+ delete mpPopupWindow;
+ mpPopupWindow = 0;
+ }
+ }
+
+ return 1;
+}
+
+//--------------------------------------------------------------------
+
+SfxToolBoxControl::SfxToolBoxControl(
+ USHORT nSlotID,
+ USHORT nID,
+ ToolBox& rBox,
+ BOOL bShowStringItems )
+: svt::ToolboxController()
+{
+ pImpl = new SfxToolBoxControl_Impl;
+
+ pImpl->pBox = &rBox;
+ pImpl->bShowString = bShowStringItems;
+ pImpl->nSelectModifier = 0;
+ pImpl->pFact = 0;
+ pImpl->nTbxId = nID;
+ pImpl->nSlotId = nSlotID;
+ pImpl->mpFloatingWindow = 0;
+ pImpl->mpPopupWindow = 0;
+}
+
+//--------------------------------------------------------------------
+
+SfxToolBoxControl::~SfxToolBoxControl()
+{
+ if ( pImpl->mxUIElement.is() )
+ {
+ Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
+ xComponent->dispose();
+ }
+ pImpl->mxUIElement = 0;
+ delete pImpl;
+}
+
+//--------------------------------------------------------------------
+
+ToolBox& SfxToolBoxControl::GetToolBox() const
+{
+ return *pImpl->pBox;
+}
+unsigned short SfxToolBoxControl::GetId() const
+{
+ return pImpl->nTbxId;
+}
+unsigned short SfxToolBoxControl::GetSlotId() const
+{
+ return pImpl->nSlotId;
+}
+
+//--------------------------------------------------------------------
+
+void SAL_CALL SfxToolBoxControl::dispose() throw (::com::sun::star::uno::RuntimeException)
+{
+ if ( m_bDisposed )
+ return;
+
+ svt::ToolboxController::dispose();
+
+ // Remove and destroy our item window at our toolbox
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ Window* pWindow = pImpl->pBox->GetItemWindow( pImpl->nTbxId );
+ pImpl->pBox->SetItemWindow( pImpl->nTbxId, 0 );
+ delete pWindow;
+
+ // Dispose an open sub toolbar. It's possible that we have an open
+ // sub toolbar while we get disposed. Therefore we have to dispose
+ // it now! Not doing so would result in a crash. The sub toolbar
+ // gets destroyed asynchronously and would access a non-existing
+ // parent toolbar! See #126569#
+ if ( pImpl->mxUIElement.is() )
+ {
+ Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
+ xComponent->dispose();
+ }
+ pImpl->mxUIElement = 0;
+
+ // Delete my popup windows
+ delete pImpl->mpFloatingWindow;
+ delete pImpl->mpPopupWindow;
+
+ pImpl->mpFloatingWindow = 0;
+ pImpl->mpPopupWindow = 0;
+}
+
+//--------------------------------------------------------------------
+void SfxToolBoxControl::RegisterToolBoxControl( SfxModule* pMod, SfxTbxCtrlFactory* pFact)
+{
+ SFX_APP()->RegisterToolBoxControl_Impl( pMod, pFact );
+}
+
+SfxToolBoxControl* SfxToolBoxControl::CreateControl( USHORT nSlotId, USHORT nTbxId, ToolBox *pBox, SfxModule* pMod )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ SfxToolBoxControl *pCtrl;
+ SfxApplication *pApp = SFX_APP();
+
+ SfxSlotPool *pSlotPool;
+ if ( pMod )
+ pSlotPool = pMod->GetSlotPool();
+ else
+ pSlotPool = &SfxSlotPool::GetSlotPool();
+ TypeId aSlotType = pSlotPool->GetSlotType( nSlotId );
+ if ( aSlotType )
+ {
+ if ( pMod )
+ {
+ SfxTbxCtrlFactArr_Impl *pFactories = pMod->GetTbxCtrlFactories_Impl();
+ if ( pFactories )
+ {
+ SfxTbxCtrlFactArr_Impl &rFactories = *pFactories;
+ USHORT nFactory;
+ const USHORT nCount = rFactories.Count();
+
+ // search for a factory with the given slot id
+ for( nFactory = 0; nFactory < nCount; ++nFactory )
+ if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
+ break;
+
+ if( nFactory == nCount )
+ {
+ // if no factory exists for the given slot id, see if we
+ // have a generic factory with the correct slot type and slot id == 0
+ for ( nFactory = 0; nFactory < nCount; ++nFactory )
+ if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
+ break;
+ }
+
+ if( nFactory < nCount )
+ {
+ pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
+ pCtrl->pImpl->pFact = rFactories[nFactory];
+ return pCtrl;
+ }
+ }
+ }
+
+ SfxTbxCtrlFactArr_Impl &rFactories = pApp->GetTbxCtrlFactories_Impl();
+ USHORT nFactory;
+ const USHORT nCount = rFactories.Count();
+
+ for( nFactory = 0; nFactory < nCount; ++nFactory )
+ if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
+ break;
+
+ if( nFactory == nCount )
+ {
+ // if no factory exists for the given slot id, see if we
+ // have a generic factory with the correct slot type and slot id == 0
+ for( nFactory = 0; nFactory < nCount; ++nFactory )
+ if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
+ break;
+ }
+
+ if( nFactory < nCount )
+ {
+ pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
+ pCtrl->pImpl->pFact = rFactories[nFactory];
+ return pCtrl;
+ }
+ }
+
+ return NULL;
+}
+
+SfxItemState SfxToolBoxControl::GetItemState(
+ const SfxPoolItem* pState )
+/* [Beschreibung]
+
+ Statische Methode zum Ermitteln des Status des SfxPoolItem-Pointers,
+ in der Methode <SfxControllerItem::StateChanged(const SfxPoolItem*)>
+ zu verwenden.
+
+ [R"uckgabewert]
+
+ SfxItemState SFX_ITEM_UNKNOWN
+ Enabled, aber keine weitere Statusinformation
+ verf"ugbar. Typisch f"ur <Slot>s, die allenfalls
+ zeitweise disabled sind, aber ihre Darstellung sonst
+ nicht "andern.
+
+ SFX_ITEM_DISABLED
+ Disabled und keine weiter Statusinformation
+ verf"ugbar. Alle anderen ggf. angezeigten Werte sollten
+ auf den Default zur"uckgesetzt werden.
+
+ SFX_ITEM_DONTCARE
+ Enabled aber es waren nur uneindeutige Werte
+ verf"ugbar (also keine, die abgefragt werden k"onnen).
+
+ SFX_ITEM_AVAILABLE
+ Enabled und mit verf"ugbarem Wert, der von 'pState'
+ erfragbar ist. Der Typ ist dabei im gesamten
+ Programm eindeutig und durch den Slot festgelegt.
+*/
+
+{
+ return !pState
+ ? SFX_ITEM_DISABLED
+ : IsInvalidItem(pState)
+ ? SFX_ITEM_DONTCARE
+ : pState->ISA(SfxVoidItem) && !pState->Which()
+ ? SFX_ITEM_UNKNOWN
+ : SFX_ITEM_AVAILABLE;
+}
+
+void SfxToolBoxControl::Dispatch(
+ const Reference< XDispatchProvider >& rProvider,
+ const rtl::OUString& rCommand,
+ Sequence< ::PropertyValue >& aArgs )
+{
+ if ( rProvider.is() )
+ {
+ ::com::sun::star::util::URL aTargetURL;
+ aTargetURL.Complete = rCommand;
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
+ UNO_QUERY );
+ xTrans->parseStrict( aTargetURL );
+
+ Reference < XDispatch > xDispatch = rProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
+ if ( xDispatch.is() )
+ xDispatch->dispatch( aTargetURL, aArgs );
+ }
+}
+
+void SfxToolBoxControl::Dispatch( const ::rtl::OUString& aCommand, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs )
+{
+ Reference < XController > xController;
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( getFrameInterface().is() )
+ xController = getFrameInterface()->getController();
+
+ Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
+ if ( xProvider.is() )
+ {
+ ::com::sun::star::util::URL aTargetURL;
+ aTargetURL.Complete = aCommand;
+ getURLTransformer()->parseStrict( aTargetURL );
+
+ Reference < XDispatch > xDispatch = xProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
+ if ( xDispatch.is() )
+ {
+ if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
+ {
+ ::rtl::OUString sAppName;
+ try
+ {
+ static ::rtl::OUString our_aModuleManagerName = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager =
+ ::comphelper::getProcessServiceFactory();
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager(
+ xServiceManager->createInstance(our_aModuleManagerName)
+ , ::com::sun::star::uno::UNO_QUERY_THROW);
+ ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame(
+ getFrameInterface(), UNO_QUERY_THROW);
+ sAppName = xModuleManager->identify(xFrame);
+ } catch(::com::sun::star::uno::Exception&) {}
+ Sequence<PropertyValue> source;
+ ::comphelper::UiEventsLogger::appendDispatchOrigin(source, sAppName, ::rtl::OUString::createFromAscii("SfxToolBoxControl"));
+ ::comphelper::UiEventsLogger::logDispatch(aTargetURL, source);
+ }
+ xDispatch->dispatch( aTargetURL, aArgs );
+ }
+ }
+}
+
+// XInterface
+Any SAL_CALL SfxToolBoxControl::queryInterface( const Type & rType )
+throw(::com::sun::star::uno::RuntimeException)
+{
+ ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
+ SAL_STATIC_CAST( ::com::sun::star::awt::XDockableWindowListener*, this ),
+ SAL_STATIC_CAST( ::com::sun::star::frame::XSubToolbarController*, this ));
+ return (aRet.hasValue() ? aRet : svt::ToolboxController::queryInterface( rType ));
+}
+
+void SAL_CALL SfxToolBoxControl::acquire() throw()
+{
+ OWeakObject::acquire();
+}
+
+void SAL_CALL SfxToolBoxControl::release() throw()
+{
+ OWeakObject::release();
+}
+
+void SAL_CALL SfxToolBoxControl::disposing( const ::com::sun::star::lang::EventObject& aEvent )
+throw( ::com::sun::star::uno::RuntimeException )
+{
+ svt::ToolboxController::disposing( aEvent );
+}
+
+// XStatusListener
+void SAL_CALL SfxToolBoxControl::statusChanged( const FeatureStateEvent& rEvent )
+throw ( ::com::sun::star::uno::RuntimeException )
+{
+ SfxViewFrame* pViewFrame = NULL;
+ Reference < XController > xController;
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( getFrameInterface().is() )
+ xController = getFrameInterface()->getController();
+
+ Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
+ if ( xProvider.is() )
+ {
+ Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, ::rtl::OUString(), 0 );
+ if ( xDisp.is() )
+ {
+ Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
+ SfxOfficeDispatch* pDisp = NULL;
+ if ( xTunnel.is() )
+ {
+ sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
+ pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
+ }
+
+ if ( pDisp )
+ pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
+ }
+ }
+
+ USHORT nSlotId = 0;
+ SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
+ const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
+ if ( pSlot )
+ nSlotId = pSlot->GetSlotId();
+ else if ( m_aCommandURL == rEvent.FeatureURL.Path )
+ nSlotId = GetSlotId();
+
+ if ( nSlotId > 0 )
+ {
+ if ( rEvent.Requery )
+ svt::ToolboxController::statusChanged( rEvent );
+ else
+ {
+ SfxItemState eState = SFX_ITEM_DISABLED;
+ SfxPoolItem* pItem = NULL;
+ if ( rEvent.IsEnabled )
+ {
+ eState = SFX_ITEM_AVAILABLE;
+ ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
+
+ if ( pType == ::getVoidCppuType() )
+ {
+ pItem = new SfxVoidItem( nSlotId );
+ eState = SFX_ITEM_UNKNOWN;
+ }
+ else if ( pType == ::getBooleanCppuType() )
+ {
+ sal_Bool bTemp = false;
+ rEvent.State >>= bTemp ;
+ pItem = new SfxBoolItem( nSlotId, bTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt16*)0) )
+ {
+ sal_uInt16 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ pItem = new SfxUInt16Item( nSlotId, nTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt32*)0) )
+ {
+ sal_uInt32 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ pItem = new SfxUInt32Item( nSlotId, nTemp );
+ }
+ else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
+ {
+ ::rtl::OUString sTemp ;
+ rEvent.State >>= sTemp ;
+ pItem = new SfxStringItem( nSlotId, sTemp );
+ }
+ else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
+ {
+ ItemStatus aItemStatus;
+ rEvent.State >>= aItemStatus;
+ eState = aItemStatus.State;
+ pItem = new SfxVoidItem( nSlotId );
+ }
+ else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
+ {
+ Visibility aVisibilityStatus;
+ rEvent.State >>= aVisibilityStatus;
+ pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
+ }
+ else
+ {
+ if ( pSlot )
+ pItem = pSlot->GetType()->CreateItem();
+ if ( pItem )
+ {
+ pItem->SetWhich( nSlotId );
+ pItem->PutValue( rEvent.State );
+ }
+ else
+ pItem = new SfxVoidItem( nSlotId );
+ }
+ }
+
+ StateChanged( nSlotId, eState, pItem );
+ delete pItem;
+ }
+ }
+}
+
+// XSubToolbarController
+::sal_Bool SAL_CALL SfxToolBoxControl::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException)
+{
+ return sal_False;
+}
+
+::rtl::OUString SAL_CALL SfxToolBoxControl::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException)
+{
+ return rtl::OUString();
+}
+
+void SAL_CALL SfxToolBoxControl::functionSelected( const ::rtl::OUString& /*aCommand*/ ) throw (::com::sun::star::uno::RuntimeException)
+{
+ // must be implemented by sub-class
+}
+
+void SAL_CALL SfxToolBoxControl::updateImage() throw (::com::sun::star::uno::RuntimeException)
+{
+ // must be implemented by sub-class
+}
+
+// XToolbarController
+void SAL_CALL SfxToolBoxControl::execute( sal_Int16 KeyModifier ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ Select( (USHORT)KeyModifier );
+}
+void SAL_CALL SfxToolBoxControl::click() throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ Click();
+}
+
+void SAL_CALL SfxToolBoxControl::doubleClick() throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ DoubleClick();
+}
+
+Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createPopupWindow() throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ Window* pWindow = CreatePopupWindow();
+ if ( pWindow )
+ return VCLUnoHelper::GetInterface( pWindow );
+ else
+ return Reference< ::com::sun::star::awt::XWindow >();
+}
+
+Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createItemWindow( const Reference< ::com::sun::star::awt::XWindow >& rParent ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ return VCLUnoHelper::GetInterface( CreateItemWindow( VCLUnoHelper::GetWindow( rParent )));
+}
+
+// XDockableWindowListener
+void SAL_CALL SfxToolBoxControl::startDocking( const ::com::sun::star::awt::DockingEvent& )
+throw (::com::sun::star::uno::RuntimeException)
+{
+}
+::com::sun::star::awt::DockingData SAL_CALL SfxToolBoxControl::docking( const ::com::sun::star::awt::DockingEvent& )
+throw (::com::sun::star::uno::RuntimeException)
+{
+ return ::com::sun::star::awt::DockingData();
+}
+
+void SAL_CALL SfxToolBoxControl::endDocking( const ::com::sun::star::awt::EndDockingEvent& )
+throw (::com::sun::star::uno::RuntimeException)
+{
+}
+
+sal_Bool SAL_CALL SfxToolBoxControl::prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& )
+throw (::com::sun::star::uno::RuntimeException)
+{
+ return sal_False;
+}
+
+void SAL_CALL SfxToolBoxControl::toggleFloatingMode( const ::com::sun::star::lang::EventObject& )
+throw (::com::sun::star::uno::RuntimeException)
+{
+}
+
+void SAL_CALL SfxToolBoxControl::closed( const ::com::sun::star::lang::EventObject& )
+throw (::com::sun::star::uno::RuntimeException)
+{
+}
+
+void SAL_CALL SfxToolBoxControl::endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& aEvent )
+throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ ::rtl::OUString aSubToolBarResName;
+ if ( pImpl->mxUIElement.is() )
+ {
+ Reference< XPropertySet > xPropSet( pImpl->mxUIElement, UNO_QUERY );
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ))) >>= aSubToolBarResName;
+ }
+ catch ( com::sun::star::beans::UnknownPropertyException& )
+ {
+ }
+ catch ( com::sun::star::lang::WrappedTargetException& )
+ {
+ }
+ }
+
+ Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
+ xComponent->dispose();
+ }
+ pImpl->mxUIElement = 0;
+
+ // if the toolbar was teared-off recreate it and place it at the given position
+ if( aEvent.bTearoff )
+ {
+ Reference< XUIElement > xUIElement;
+ Reference< XLayoutManager > xLayoutManager = getLayoutManager();
+
+ if ( !xLayoutManager.is() )
+ return;
+
+ xLayoutManager->createElement( aSubToolBarResName );
+ xUIElement = xLayoutManager->getElement( aSubToolBarResName );
+ if ( xUIElement.is() )
+ {
+ Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
+
+ Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
+ Reference< ::com::sun::star::beans::XPropertySet > xProp( xUIElement, UNO_QUERY );
+ if ( xSubToolBar.is() && xProp.is() )
+ {
+ rtl::OUString aPersistentString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
+ try
+ {
+ Window* pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
+ ToolBox* pToolBar( 0 );
+ if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
+ {
+ pToolBar = (ToolBox *)pTbxWindow;
+
+ Any a;
+ a = xProp->getPropertyValue( aPersistentString );
+ xProp->setPropertyValue( aPersistentString, makeAny( sal_False ));
+
+ xLayoutManager->hideElement( aSubToolBarResName );
+ xLayoutManager->floatWindow( aSubToolBarResName );
+
+ xLayoutManager->setElementPos( aSubToolBarResName, aEvent.FloatingPosition );
+ xLayoutManager->showElement( aSubToolBarResName );
+
+ xProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" )), a );
+ }
+ }
+ catch ( ::com::sun::star::uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch ( ::com::sun::star::uno::Exception& )
+ {
+ }
+ }
+ }
+ }
+}
+
+::Size SfxToolBoxControl::getPersistentFloatingSize( const Reference< XFrame >& /*xFrame*/, const ::rtl::OUString& /*rSubToolBarResName*/ )
+{
+ ::Size aToolboxSize;
+ return aToolboxSize;
+}
+
+void SfxToolBoxControl::createAndPositionSubToolBar( const ::rtl::OUString& rSubToolBarResName )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ if ( pImpl->pBox )
+ {
+ static WeakReference< XUIElementFactory > xWeakUIElementFactory;
+
+ USHORT nItemId = pImpl->pBox->GetDownItemId();
+
+ if ( !nItemId )
+ return;
+
+ // create element with factory
+ Reference< XMultiServiceFactory > xServiceManager = getServiceManager();
+ Reference< XFrame > xFrame = getFrameInterface();
+ Reference< XUIElement > xUIElement;
+ Reference< XUIElementFactory > xUIEementFactory;
+
+ xUIEementFactory = xWeakUIElementFactory;
+ if ( !xUIEementFactory.is() )
+ {
+ xUIEementFactory = Reference< XUIElementFactory >(
+ xServiceManager->createInstance(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.ui.UIElementFactoryManager" ))),
+ UNO_QUERY );
+ xWeakUIElementFactory = xUIEementFactory;
+ }
+
+ Sequence< PropertyValue > aPropSeq( 3 );
+ aPropSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
+ aPropSeq[0].Value <<= xFrame;
+ aPropSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
+ aPropSeq[1].Value <<= sal_False;
+ aPropSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PopupMode" ));
+ aPropSeq[2].Value <<= sal_True;
+
+ try
+ {
+ xUIElement = xUIEementFactory->createUIElement( rSubToolBarResName, aPropSeq );
+ }
+ catch ( ::com::sun::star::container::NoSuchElementException& )
+ {
+ }
+ catch ( IllegalArgumentException& )
+ {
+ }
+
+ if ( xUIElement.is() )
+ {
+ Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
+
+ Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
+ if ( xSubToolBar.is() )
+ {
+ Reference< ::com::sun::star::awt::XDockableWindow > xDockWindow( xSubToolBar, UNO_QUERY );
+ xDockWindow->addDockableWindowListener( Reference< ::com::sun::star::awt::XDockableWindowListener >(
+ static_cast< OWeakObject * >( this ), UNO_QUERY ));
+ xDockWindow->enableDocking( sal_True );
+
+ // keep refererence to UIElement to avoid its destruction
+ if ( pImpl->mxUIElement.is() )
+ {
+ Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
+ xComponent->dispose();
+ }
+ pImpl->mxUIElement = xUIElement;
+
+ Window* pParentTbxWindow( pImpl->pBox );
+ Window* pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
+ ToolBox* pToolBar( 0 );
+ if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
+ pToolBar = (ToolBox *)pTbxWindow;
+
+ if ( pToolBar )
+ {
+ pToolBar->SetParent( pParentTbxWindow );
+ ::Size aSize = getPersistentFloatingSize( xFrame, rSubToolBarResName );
+ if ( aSize.Width() == 0 || aSize.Height() == 0 )
+ {
+ // calc and set size for popup mode
+ aSize = pToolBar->CalcPopupWindowSizePixel();
+ }
+ pToolBar->SetSizePixel( aSize );
+
+ // open subtoolbox in popup mode
+ Window::GetDockingManager()->StartPopupMode( pImpl->pBox, pToolBar );
+ }
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxToolBoxControl::SetPopupWindow( SfxPopupWindow* pWindow )
+{
+ pImpl->mpPopupWindow = pWindow;
+ pImpl->mpPopupWindow->SetPopupModeEndHdl( LINK( this, SfxToolBoxControl, PopupModeEndHdl ));
+ pImpl->mpPopupWindow->SetDeleteLink_Impl( LINK( this, SfxToolBoxControl, ClosePopupWindow ));
+}
+
+//--------------------------------------------------------------------
+
+IMPL_LINK( SfxToolBoxControl, PopupModeEndHdl, void *, EMPTYARG )
+{
+ if ( pImpl->mpPopupWindow->IsVisible() )
+ {
+ // Replace floating window with popup window and destroy
+ // floating window instance.
+ delete pImpl->mpFloatingWindow;
+ pImpl->mpFloatingWindow = pImpl->mpPopupWindow;
+ pImpl->mpPopupWindow = 0;
+ // We also need to know when the user tries to use the
+ // floating window.
+ pImpl->mpFloatingWindow->AddEventListener( LINK( pImpl, SfxToolBoxControl_Impl, WindowEventListener ));
+ }
+ else
+ {
+ // Popup window has been closed by the user. No replacement, instance
+ // will destroy itself.
+ pImpl->mpPopupWindow = 0;
+ }
+
+ return 1;
+}
+
+//--------------------------------------------------------------------
+IMPL_LINK( SfxToolBoxControl, ClosePopupWindow, SfxPopupWindow *, pWindow )
+{
+ if ( pWindow == pImpl->mpFloatingWindow )
+ pImpl->mpFloatingWindow = 0;
+ else
+ pImpl->mpPopupWindow = 0;
+
+ return 1;
+}
+
+//--------------------------------------------------------------------
+
+void SfxToolBoxControl::StateChanged
+(
+ USHORT nId,
+ SfxItemState eState,
+ const SfxPoolItem* pState
+)
+{
+ DBG_MEMTEST();
+ DBG_ASSERT( pImpl->pBox != 0, "setting state to dangling ToolBox" );
+
+ if ( GetId() >= SID_OBJECTMENU0 && GetId() <= SID_OBJECTMENU_LAST )
+ return;
+
+ // enabled/disabled-Flag pauschal korrigieren
+ pImpl->pBox->EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
+
+ USHORT nItemBits = pImpl->pBox->GetItemBits( GetId() );
+ nItemBits &= ~TIB_CHECKABLE;
+ TriState eTri = STATE_NOCHECK;
+ switch ( eState )
+ {
+ case SFX_ITEM_AVAILABLE:
+ {
+ if ( pState->ISA(SfxBoolItem) )
+ {
+ // BoolItem fuer checken
+ if ( ((const SfxBoolItem*)pState)->GetValue() )
+ eTri = STATE_CHECK;
+ nItemBits |= TIB_CHECKABLE;
+ }
+ else if ( pState->ISA(SfxEnumItemInterface) &&
+ ((SfxEnumItemInterface *)pState)->HasBoolValue())
+ {
+ // EnumItem wie Bool behandeln
+ if ( ((const SfxEnumItemInterface *)pState)->GetBoolValue() )
+ eTri = STATE_CHECK;
+ nItemBits |= TIB_CHECKABLE;
+ }
+ else if ( pImpl->bShowString && pState->ISA(SfxStringItem) )
+ pImpl->pBox->SetItemText(nId, ((const SfxStringItem*)pState)->GetValue() );
+ break;
+ }
+
+ case SFX_ITEM_DONTCARE:
+ {
+ eTri = STATE_DONTKNOW;
+ nItemBits |= TIB_CHECKABLE;
+ }
+ }
+
+ pImpl->pBox->SetItemState( GetId(), eTri );
+ pImpl->pBox->SetItemBits( GetId(), nItemBits );
+}
+
+//--------------------------------------------------------------------
+
+void SfxToolBoxControl::Select( USHORT nModifier )
+{
+ pImpl->nSelectModifier = nModifier;
+ Select( BOOL((nModifier & KEY_MOD1)!=0) );
+}
+
+//--------------------------------------------------------------------
+
+void SfxToolBoxControl::Select( BOOL /*bMod1*/ )
+{
+ if(::comphelper::UiEventsLogger::isEnabled()) //#i88653# #i102805#
+ {
+ ::rtl::OUString sAppName;
+ try
+ {
+ static ::rtl::OUString our_aModuleManagerName = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager =
+ ::comphelper::getProcessServiceFactory();
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager(
+ xServiceManager->createInstance(our_aModuleManagerName)
+ , ::com::sun::star::uno::UNO_QUERY_THROW);
+ sAppName = xModuleManager->identify(m_xFrame);
+ } catch(::com::sun::star::uno::Exception&) {}
+ Sequence<PropertyValue> vSource;
+ ::comphelper::UiEventsLogger::appendDispatchOrigin(vSource, sAppName, ::rtl::OUString::createFromAscii("SfxToolBoxControl"));
+ URL aURL;
+ aURL.Complete = m_aCommandURL;
+ ::comphelper::UiEventsLogger::logDispatch(aURL, vSource);
+ }
+ svt::ToolboxController::execute( pImpl->nSelectModifier );
+}
+
+//--------------------------------------------------------------------
+
+void SfxToolBoxControl::DoubleClick()
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxToolBoxControl::Click()
+{
+}
+
+//--------------------------------------------------------------------
+
+SfxPopupWindowType SfxToolBoxControl::GetPopupWindowType() const
+{
+ return SFX_POPUPWINDOW_NONE;
+}
+
+//--------------------------------------------------------------------
+
+SfxPopupWindow* SfxToolBoxControl::CreatePopupWindow()
+{
+ return 0;
+}
+
+SfxPopupWindow* SfxToolBoxControl::CreatePopupWindowCascading()
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+Window* SfxToolBoxControl::CreateItemWindow( Window * )
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+SfxFrameStatusListener::SfxFrameStatusListener(
+ const Reference< XMultiServiceFactory >& rServiceManager,
+ const Reference< XFrame >& xFrame,
+ SfxStatusListenerInterface* pCallee ) :
+ svt::FrameStatusListener( rServiceManager, xFrame ),
+ m_pCallee( pCallee )
+{
+}
+
+//--------------------------------------------------------------------
+
+SfxFrameStatusListener::~SfxFrameStatusListener()
+{
+}
+
+//--------------------------------------------------------------------
+
+// XStatusListener
+void SAL_CALL SfxFrameStatusListener::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& rEvent )
+throw ( ::com::sun::star::uno::RuntimeException )
+{
+ SfxViewFrame* pViewFrame = NULL;
+ Reference < XController > xController;
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_xFrame.is() )
+ xController = m_xFrame->getController();
+
+ Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
+ if ( xProvider.is() )
+ {
+ Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, ::rtl::OUString(), 0 );
+ if ( xDisp.is() )
+ {
+ Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
+ SfxOfficeDispatch* pDisp = NULL;
+ if ( xTunnel.is() )
+ {
+ sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
+ pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
+ }
+
+ if ( pDisp )
+ pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
+ }
+ }
+
+ USHORT nSlotId = 0;
+ SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
+ const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
+ if ( pSlot )
+ nSlotId = pSlot->GetSlotId();
+
+ if ( nSlotId > 0 )
+ {
+ if ( rEvent.Requery )
+ {
+ // requery for the notified state
+ addStatusListener( rEvent.FeatureURL.Complete );
+ }
+ else
+ {
+ SfxItemState eState = SFX_ITEM_DISABLED;
+ SfxPoolItem* pItem = NULL;
+ if ( rEvent.IsEnabled )
+ {
+ eState = SFX_ITEM_AVAILABLE;
+ ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
+
+ if ( pType == ::getVoidCppuType() )
+ {
+ pItem = new SfxVoidItem( nSlotId );
+ eState = SFX_ITEM_UNKNOWN;
+ }
+ else if ( pType == ::getBooleanCppuType() )
+ {
+ sal_Bool bTemp = false;
+ rEvent.State >>= bTemp ;
+ pItem = new SfxBoolItem( nSlotId, bTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt16*)0) )
+ {
+ sal_uInt16 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ pItem = new SfxUInt16Item( nSlotId, nTemp );
+ }
+ else if ( pType == ::getCppuType((const sal_uInt32*)0) )
+ {
+ sal_uInt32 nTemp = 0;
+ rEvent.State >>= nTemp ;
+ pItem = new SfxUInt32Item( nSlotId, nTemp );
+ }
+ else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
+ {
+ ::rtl::OUString sTemp ;
+ rEvent.State >>= sTemp ;
+ pItem = new SfxStringItem( nSlotId, sTemp );
+ }
+ else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
+ {
+ ItemStatus aItemStatus;
+ rEvent.State >>= aItemStatus;
+ eState = aItemStatus.State;
+ pItem = new SfxVoidItem( nSlotId );
+ }
+ else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
+ {
+ Visibility aVisibilityStatus;
+ rEvent.State >>= aVisibilityStatus;
+ pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
+ }
+ else
+ {
+ if ( pSlot )
+ pItem = pSlot->GetType()->CreateItem();
+ if ( pItem )
+ {
+ pItem->SetWhich( nSlotId );
+ pItem->PutValue( rEvent.State );
+ }
+ else
+ pItem = new SfxVoidItem( nSlotId );
+ }
+ }
+
+ if ( m_pCallee )
+ m_pCallee->StateChanged( nSlotId, eState, pItem );
+ delete pItem;
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+SfxPopupWindow::SfxPopupWindow(
+ USHORT nId,
+ const Reference< XFrame >& rFrame,
+ WinBits nBits ) :
+ FloatingWindow( SFX_APP()->GetTopWindow(), nBits )
+ , m_bFloating(FALSE)
+ , m_bCascading( FALSE )
+ , m_nId( nId )
+ , m_xFrame( rFrame )
+ , m_pStatusListener( 0 )
+{
+ m_xServiceManager = ::comphelper::getProcessServiceFactory();
+
+ Window* pWindow = GetTopMostParentSystemWindow( this );
+ if ( pWindow )
+ ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
+}
+
+//--------------------------------------------------------------------
+
+SfxPopupWindow::SfxPopupWindow(
+ USHORT nId,
+ const Reference< XFrame >& rFrame,
+ const ResId &rId ) :
+ FloatingWindow( SFX_APP()->GetTopWindow(), rId )
+ , m_bFloating(FALSE)
+ , m_bCascading( FALSE )
+ , m_nId( nId )
+ , m_xFrame( rFrame )
+ , m_pStatusListener( 0 )
+{
+ m_xServiceManager = ::comphelper::getProcessServiceFactory();
+
+ Window* pWindow = GetTopMostParentSystemWindow( this );
+ if ( pWindow )
+ ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
+}
+
+//--------------------------------------------------------------------
+
+SfxPopupWindow::SfxPopupWindow(
+ USHORT nId,
+ const Reference< XFrame >& rFrame,
+ Window* pParentWindow,
+ WinBits nBits ) :
+ FloatingWindow( pParentWindow, nBits )
+ , m_bFloating(FALSE)
+ , m_bCascading( FALSE )
+ , m_nId( nId )
+ , m_xFrame( rFrame )
+ , m_pStatusListener( 0 )
+{
+ m_xServiceManager = ::comphelper::getProcessServiceFactory();
+
+ Window* pWindow = GetTopMostParentSystemWindow( this );
+ if ( pWindow )
+ ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
+}
+
+//--------------------------------------------------------------------
+
+SfxPopupWindow::SfxPopupWindow(
+ USHORT nId,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
+ Window* pParentWindow,
+ const ResId &rId ) :
+ FloatingWindow( pParentWindow, rId )
+ , m_bFloating(FALSE)
+ , m_bCascading( FALSE )
+ , m_nId( nId )
+ , m_xFrame( rFrame )
+ , m_pStatusListener( 0 )
+{
+ m_xServiceManager = ::comphelper::getProcessServiceFactory();
+
+ Window* pWindow = GetTopMostParentSystemWindow( this );
+ if ( pWindow )
+ ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
+}
+
+//--------------------------------------------------------------------
+
+SfxPopupWindow::~SfxPopupWindow()
+{
+ if ( m_xStatusListener.is() )
+ {
+ m_xStatusListener->dispose();
+ m_xStatusListener.clear();
+ }
+
+ Window* pWindow = GetTopMostParentSystemWindow( this );
+ if ( pWindow )
+ ((SystemWindow *)pWindow)->GetTaskPaneList()->RemoveWindow( this );
+}
+
+//--------------------------------------------------------------------
+
+SfxFrameStatusListener* SfxPopupWindow::GetOrCreateStatusListener()
+{
+ if ( !m_xStatusListener.is() )
+ {
+ m_pStatusListener = new SfxFrameStatusListener(
+ m_xServiceManager,
+ m_xFrame,
+ this );
+ m_xStatusListener = Reference< XComponent >( static_cast< cppu::OWeakObject* >(
+ m_pStatusListener ), UNO_QUERY );
+ }
+
+ return m_pStatusListener;
+}
+
+//--------------------------------------------------------------------
+
+void SfxPopupWindow::BindListener()
+{
+ GetOrCreateStatusListener();
+ if ( m_xStatusListener.is() )
+ m_pStatusListener->bindListener();
+}
+
+//--------------------------------------------------------------------
+
+void SfxPopupWindow::UnbindListener()
+{
+ GetOrCreateStatusListener();
+ if ( m_xStatusListener.is() )
+ m_pStatusListener->unbindListener();
+}
+
+//--------------------------------------------------------------------
+
+void SfxPopupWindow::AddStatusListener( const rtl::OUString& rCommandURL )
+{
+ GetOrCreateStatusListener();
+ if ( m_xStatusListener.is() )
+ m_pStatusListener->addStatusListener( rCommandURL );
+}
+
+//--------------------------------------------------------------------
+
+void SfxPopupWindow::RemoveStatusListener( const rtl::OUString& rCommandURL )
+{
+ GetOrCreateStatusListener();
+ if ( m_xStatusListener.is() )
+ m_pStatusListener->removeStatusListener( rCommandURL );
+}
+
+//--------------------------------------------------------------------
+
+void SfxPopupWindow::UpdateStatus( const rtl::OUString& rCommandURL )
+{
+ GetOrCreateStatusListener();
+ if ( m_xStatusListener.is() )
+ m_pStatusListener->updateStatus( rCommandURL );
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxPopupWindow::Close()
+{
+ m_bFloating = FALSE;
+ FloatingWindow::Close();
+
+ Delete(0);
+ return TRUE;
+}
+
+//--------------------------------------------------------------------
+
+void SfxPopupWindow::PopupModeEnd()
+{
+ //! to allow PopupModeEndHdl to be called
+ FloatingWindow::PopupModeEnd();
+
+ if ( IsVisible() )
+ {
+ // wurde abgerissen
+ DeleteFloatingWindow();
+ m_bFloating = TRUE;
+ }
+ else
+ Close();
+}
+
+//--------------------------------------------------------------------
+
+void SfxPopupWindow::DeleteFloatingWindow()
+{
+ if ( m_bFloating )
+ {
+ Hide();
+ Delete(0);
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxPopupWindow::MouseMove( const ::MouseEvent& rMEvt )
+{
+ if ( m_bCascading == FALSE )
+ FloatingWindow::MouseMove( rMEvt );
+ else
+ {
+ // MouseMove-Event an die Children forwarden
+ ::Point aPos = rMEvt.GetPosPixel();
+ ::Point aScrPos = OutputToScreenPixel( aPos );
+ USHORT i = 0;
+ Window* pWindow = GetChild( i );
+ while ( pWindow )
+ {
+ ::MouseEvent aMEvt( pWindow->ScreenToOutputPixel( aScrPos ),
+ rMEvt.GetClicks(), rMEvt.GetMode(),
+ rMEvt.GetButtons(), rMEvt.GetModifier() );
+ pWindow->MouseMove( rMEvt );
+ pWindow->Update();
+ i++;
+ pWindow = GetChild( i );
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxPopupWindow::StartCascading()
+{
+ m_bCascading= TRUE;
+}
+
+void SfxPopupWindow::EndCascading()
+{
+ m_bCascading = FALSE;
+}
+
+//--------------------------------------------------------------------
+
+SfxPopupWindow* SfxPopupWindow::Clone() const
+
+/* [Beschreibung]
+
+ Diese Methode mu\s "uberladen werden, um dieses Popup auch im
+ Presentations-Modus anzuzeigen. Sie wird gerufen, wenn ein Show()
+ sinnlos w"are, da der Parent nicht das Presentations-Window ist.
+ Beim neu erzeugen wird automatisch das neue Top-Window verwendet, so
+ da\s der Parent das Presentations-Window ist und das neue Popup somit
+ sichtbar ist.
+*/
+
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxPopupWindow::StateChanged(
+ USHORT /*nSID*/,
+ SfxItemState eState,
+ const SfxPoolItem* /*pState*/ )
+/* [Bescheibung]
+
+ Siehe auch <SfxControllerItem::StateChanged()>. Au\serdem wird
+ bei eState==SFX_ITEM_DISABLED das Popup gehided und in allen anderen
+ F"allen, falls es floating ist, wieder angezeigt. Daher mu\s die
+ Basisklasse i.d.R. gerufen werden.
+
+ Es findet wegen des Parents eine Sonderbehandlung f"ur den
+ Presentationsmodus statt.
+
+*/
+
+{
+ if ( SFX_ITEM_DISABLED == eState )
+ {
+ Hide();
+ }
+ else if ( m_bFloating )
+ {
+ Show( TRUE, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
+ }
+}
+
+//--------------------------------------------------------------------
+
+IMPL_LINK( SfxPopupWindow, Delete, void *, EMPTYARG )
+{
+ if ( m_aDeleteLink.IsSet() )
+ m_aDeleteLink.Call( this );
+ delete this;
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+SfxAppToolBoxControl_Impl::SfxAppToolBoxControl_Impl( USHORT nSlotId, USHORT nId, ToolBox& rBox )
+ : SfxToolBoxControl( nSlotId, nId, rBox )
+ , bBigImages( FALSE )
+ , pMenu( 0 )
+{
+ rBox.SetHelpId( nId, HID_TBXCONTROL_FILENEW );
+ rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | TIB_DROPDOWN);
+
+ // Determine the current background color of the menus
+ const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
+ m_nSymbolsStyle = rSettings.GetSymbolsStyle();
+ m_bWasHiContrastMode = rSettings.GetHighContrastMode();
+ m_bShowMenuImages = rSettings.GetUseImagesInMenus();
+
+ SetImage( String() );
+}
+
+SfxAppToolBoxControl_Impl::~SfxAppToolBoxControl_Impl()
+{
+ delete pMenu;
+}
+
+//_____________________________________________________
+/*
+ it return the existing state of the given URL in the popupmenu of this toolbox control.
+
+ If the given URL can be located as an action command of one menu item of the
+ popup menu of this control, we return TRUE. Otherwhise we return FALSE.
+ Further we return a fallback URL, in case we have to return FALSE. Because
+ the outside code must select a valid item of the popup menu everytime ...
+ and we define it here. By the way this m ethod was written to handle
+ error situations gracefully. E.g. it can be called during creation time
+ but then we have no valid menu. For this case we know another fallback URL.
+ Then we return the private:factory/ URL of the default factory.
+
+ @param *pMenu
+ pounts to the popup menu, on which item we try to locate the given URL
+ Can be NULL! Search will be supressed then.
+
+ @param sURL
+ the URL for searching
+
+ @param pFallback
+ contains the fallback URL in case we return FALSE
+ Must point to valid memory!
+
+ @param pImage
+ contains the image of the menu for the URL.
+
+ @return TRUE - if URL could be located as an item of the popup menu.
+ FALSE - otherwhise.
+*/
+BOOL Impl_ExistURLInMenu( const PopupMenu *pMenu ,
+ String &sURL ,
+ String *pFallback ,
+ Image *pImage )
+{
+ BOOL bValidFallback = FALSE;
+ if (pMenu && sURL.Len())
+ {
+ USHORT c = pMenu->GetItemCount();
+ for (USHORT p=0; p<c; ++p)
+ {
+ USHORT nId = pMenu->GetItemId(p);
+ String aCmd( pMenu->GetItemCommand(nId) );
+
+ if (!bValidFallback && aCmd.Len())
+ {
+ *pFallback = aCmd;
+ bValidFallback = TRUE;
+ }
+
+ if (aCmd.Search(sURL)==0)//match even if the menu command is more detailed (maybe an additional query) #i28667#
+ {
+ sURL = aCmd;
+ *pImage = pMenu->GetItemImage( nId );
+ return TRUE;
+ }
+ }
+ }
+
+ if (!bValidFallback)
+ {
+ *pFallback = DEFINE_CONST_UNICODE("private:factory/");
+ *pFallback += String(SvtModuleOptions().GetDefaultModuleName());
+ }
+
+ return FALSE;
+}
+
+long Select_Impl( void* pHdl, void* pVoid );
+
+SfxPopupWindow* SfxAppToolBoxControl_Impl::CreatePopupWindow()
+{
+ ToolBox& rBox = GetToolBox();
+ ::Rectangle aRect( rBox.GetItemRect( GetId() ) );
+
+ if ( !pMenu )
+ {
+ ::framework::MenuConfiguration aConf( m_xServiceManager );
+ if ( m_aCommandURL.equalsAscii( ".uno:AddDirect" ))
+ pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
+ else
+ pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
+ }
+
+ if ( pMenu )
+ {
+ pMenu->SetSelectHdl( Link( NULL, Select_Impl ) );
+ pMenu->SetActivateHdl( LINK( this, SfxAppToolBoxControl_Impl, Activate ));
+ rBox.SetItemDown( GetId(), TRUE );
+ USHORT nSelected = pMenu->Execute( &rBox, aRect, POPUPMENU_EXECUTE_DOWN );
+ if ( nSelected )
+ {
+ aLastURL = pMenu->GetItemCommand( nSelected );
+ SetImage( pMenu->GetItemCommand( nSelected ) );
+ }
+
+ rBox.SetItemDown( GetId(), FALSE );
+ }
+
+ return 0;
+}
+
+void SfxAppToolBoxControl_Impl::SetImage( const String &rURL )
+{
+ /* We accept URL's here only, which exist as items of our internal popup menu.
+ All other ones will be ignored and a fallback is used ... */
+ String aURL = rURL;
+ String sFallback;
+ Image aMenuImage;
+ BOOL bValid = Impl_ExistURLInMenu(pMenu,aURL,&sFallback,&aMenuImage);
+ if (!bValid)
+ aURL = sFallback;
+
+ BOOL bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
+ BOOL bHC = GetToolBox().GetSettings().GetStyleSettings().GetHighContrastMode();
+ Image aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( aURL ), bBig, bHC );
+ if ( !aImage )
+ aImage = !!aMenuImage ? aMenuImage :
+ SvFileInformationManager::GetImage( INetURLObject( aURL ), bBig, bHC );
+ Size aBigSize( GetToolBox().GetDefaultImageSize() );
+ if ( bBig && aImage.GetSizePixel() != aBigSize )
+ {
+ BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
+ aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE );
+ GetToolBox().SetItemImage( GetId(), Image( aScaleBmpEx ) );
+ }
+ else
+ GetToolBox().SetItemImage( GetId(), aImage );
+ aLastURL = aURL;
+}
+
+void SfxAppToolBoxControl_Impl::StateChanged
+(
+ USHORT nSlotId,
+ SfxItemState eState,
+ const SfxPoolItem* pState
+)
+{
+ if ( pState && pState->ISA(SfxStringItem) )
+ {
+ // Important step for following SetImage() call!
+ // It needs the valid pMenu item to fullfill it's specification
+ // to check for supported URLs ...
+ if ( !pMenu )
+ {
+ ::framework::MenuConfiguration aConf( m_xServiceManager );
+ // This toolbox controller is used for two popup menus (new documents and wizards!). Create the correct
+ // popup menu according to the slot ID our controller has been initialized with.
+ if ( nSlotId == SID_NEWDOCDIRECT )
+ pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
+ else
+ pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
+ }
+
+ GetToolBox().EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
+ SetImage(((const SfxStringItem*)pState)->GetValue());
+ }
+ else
+ SfxToolBoxControl::StateChanged( nSlotId, eState, pState );
+}
+
+//--------------------------------------------------------------------
+
+void SfxAppToolBoxControl_Impl::Select( BOOL bMod1 )
+{
+ if( aLastURL.Len() )
+ {
+ URL aTargetURL;
+ Reference< XDispatch > xDispatch;
+ Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY );
+
+ if ( xDispatchProvider.is() )
+ {
+ aTargetURL.Complete = aLastURL;
+ getURLTransformer()->parseStrict( aTargetURL );
+
+ ::rtl::OUString aTarget( ::rtl::OUString::createFromAscii( "_default" ));
+ if ( pMenu )
+ {
+ ::framework::MenuConfiguration::Attributes* pMenuAttributes =
+ (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
+
+ if ( pMenuAttributes )
+ aTarget = pMenuAttributes->aTargetFrame;
+ }
+
+ xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 );
+
+ if ( xDispatch.is() )
+ {
+ Sequence< PropertyValue > aArgs( 1 );
+
+ aArgs[0].Name = ::rtl::OUString::createFromAscii( "Referer" );
+ aArgs[0].Value = makeAny( ::rtl::OUString::createFromAscii( SFX_REFERER_USER ));
+
+ ExecuteInfo* pExecuteInfo = new ExecuteInfo;
+ pExecuteInfo->xDispatch = xDispatch;
+ pExecuteInfo->aTargetURL = aTargetURL;
+ pExecuteInfo->aArgs = aArgs;
+ Application::PostUserEvent( STATIC_LINK(0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
+ }
+ }
+ }
+ else
+ SfxToolBoxControl::Select( bMod1 );
+}
+
+//--------------------------------------------------------------------
+long Select_Impl( void* /*pHdl*/, void* pVoid )
+{
+ Menu* pMenu = (Menu*)pVoid;
+ String aURL( pMenu->GetItemCommand( pMenu->GetCurItemId() ) );
+
+ if( !aURL.Len() )
+ return 0;
+
+ Reference < ::com::sun::star::frame::XFramesSupplier > xDesktop =
+ Reference < ::com::sun::star::frame::XFramesSupplier >( ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
+ Reference < ::com::sun::star::frame::XFrame > xFrame( xDesktop, UNO_QUERY );
+
+ URL aTargetURL;
+ aTargetURL.Complete = aURL;
+ Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
+ UNO_QUERY );
+ xTrans->parseStrict( aTargetURL );
+
+ Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
+ Reference < XDispatch > xDisp;
+ if ( xProv.is() )
+ {
+ if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL )
+ xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
+ else
+ {
+ ::rtl::OUString aTargetFrame( ::rtl::OUString::createFromAscii( "_blank" ) );
+ ::framework::MenuConfiguration::Attributes* pMenuAttributes =
+ (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
+
+ if ( pMenuAttributes )
+ aTargetFrame = pMenuAttributes->aTargetFrame;
+
+ xDisp = xProv->queryDispatch( aTargetURL, aTargetFrame , 0 );
+ }
+ }
+
+ if ( xDisp.is() )
+ {
+ SfxAppToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxAppToolBoxControl_Impl::ExecuteInfo;
+ pExecuteInfo->xDispatch = xDisp;
+ pExecuteInfo->aTargetURL = aTargetURL;
+ pExecuteInfo->aArgs = Sequence< PropertyValue >();
+ Application::PostUserEvent( STATIC_LINK( 0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
+ }
+
+ return TRUE;
+}
+
+IMPL_LINK( SfxAppToolBoxControl_Impl, Activate, Menu *, pActMenu )
+{
+ if ( pActMenu )
+ {
+ const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
+ ULONG nSymbolsStyle = rSettings.GetSymbolsStyle();
+ BOOL bIsHiContrastMode = rSettings.GetHighContrastMode();
+ BOOL bShowMenuImages = rSettings.GetUseImagesInMenus();
+
+ if (( nSymbolsStyle != m_nSymbolsStyle ) ||
+ ( bIsHiContrastMode != m_bWasHiContrastMode ) ||
+ ( bShowMenuImages != m_bShowMenuImages ))
+ {
+ m_nSymbolsStyle = nSymbolsStyle;
+ m_bWasHiContrastMode = bIsHiContrastMode;
+ m_bShowMenuImages = bShowMenuImages;
+
+ USHORT nCount = pActMenu->GetItemCount();
+ for ( USHORT nSVPos = 0; nSVPos < nCount; nSVPos++ )
+ {
+ USHORT nId = pActMenu->GetItemId( nSVPos );
+ if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR )
+ {
+ if ( bShowMenuImages )
+ {
+ sal_Bool bImageSet = sal_False;
+ ::rtl::OUString aImageId;
+ ::framework::MenuConfiguration::Attributes* pMenuAttributes =
+ (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nId );
+
+ if ( pMenuAttributes )
+ aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
+
+ if ( aImageId.getLength() > 0 )
+ {
+ Reference< ::com::sun::star::frame::XFrame > xFrame;
+ Image aImage = GetImage( xFrame, aImageId, FALSE, bIsHiContrastMode );
+ if ( !!aImage )
+ {
+ bImageSet = sal_True;
+ pActMenu->SetItemImage( nId, aImage );
+ }
+ }
+
+ String aCmd( pActMenu->GetItemCommand( nId ) );
+ if ( !bImageSet && aCmd.Len() )
+ {
+ Image aImage = SvFileInformationManager::GetImage(
+ INetURLObject(aCmd), FALSE, bIsHiContrastMode );
+ if ( !!aImage )
+ pActMenu->SetItemImage( nId, aImage );
+ }
+ }
+ else
+ pActMenu->SetItemImage( nId, Image() );
+ }
+ }
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+//--------------------------------------------------------------------
+
+IMPL_STATIC_LINK_NOINSTANCE( SfxAppToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
+{
+/* i62706: Don't catch all exceptions. We hide all problems here and are not able
+ to handle them on higher levels.
+ try
+ {
+*/
+ // Asynchronous execution as this can lead to our own destruction!
+ // Framework can recycle our current frame and the layout manager disposes all user interface
+ // elements if a component gets detached from its frame!
+ pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
+/*
+}
+ catch (const ::com::sun::star::document::CorruptedFilterConfigurationException& exFilters)
+ {
+ throw exFilters;
+ }
+ catch (const Exception& )
+ {
+ }
+*/
+ delete pExecuteInfo;
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxAppToolBoxControl_Impl::Click( )
+{
+}
diff --git a/sfx2/source/view/frame.cxx b/sfx2/source/view/frame.cxx
new file mode 100644
index 000000000000..49deab951843
--- /dev/null
+++ b/sfx2/source/view/frame.cxx
@@ -0,0 +1,994 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/util/CloseVetoException.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/container/XChild.hpp>
+
+#ifndef _MENU_HXX //autogen
+#include <vcl/menu.hxx>
+#endif
+#include <svl/intitem.hxx>
+#ifndef _SPLITWIN_HXX //autogen
+#include <vcl/splitwin.hxx>
+#endif
+#include <svl/eitem.hxx>
+#include <svl/stritem.hxx>
+#ifndef _TOOLKIT_UNOHLP_HXX
+#include <toolkit/helper/vclunohelper.hxx>
+#endif
+#include <com/sun/star/awt/PosSize.hpp>
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+#include <vcl/msgbox.hxx>
+
+#ifndef GCC
+#endif
+
+// wg. pTopFrames
+#include "appdata.hxx"
+#include <sfx2/app.hxx>
+#include <sfx2/event.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/frame.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/objsh.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/frmdescr.hxx>
+#include "openflag.hxx"
+#include <sfx2/viewsh.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/fcontnr.hxx>
+#include "impframe.hxx"
+#include <sfx2/appuno.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "workwin.hxx"
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/msgpool.hxx>
+#include "objshimp.hxx"
+#include <sfx2/ipclient.hxx>
+
+#ifdef DBG_UTIL
+#include <sfx2/frmhtmlw.hxx>
+#endif
+
+using namespace com::sun::star;
+
+static SfxFrameArr_Impl* pFramesArr_Impl=0;
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::container;
+
+TYPEINIT1(SfxFrame, SfxListener);
+TYPEINIT1_AUTOFACTORY(SfxFrameItem, SfxPoolItem);
+TYPEINIT1(SfxUsrAnyItem, SfxPoolItem);
+TYPEINIT1_AUTOFACTORY(SfxUnoFrameItem, SfxPoolItem);
+
+SvCompatWeakHdl* SfxFrame::GetHdl()
+{
+ return pImp->GetHdl();
+}
+
+//--------------------------------------------------------------------
+void SfxFrame::Construct_Impl()
+{
+ pImp = new SfxFrame_Impl( this );
+ if ( !pFramesArr_Impl )
+ pFramesArr_Impl = new SfxFrameArr_Impl;
+ pFramesArr_Impl->Insert( this, pFramesArr_Impl->Count() );
+}
+
+//--------------------------------------------------------------------
+
+SfxFrame::~SfxFrame()
+{
+ RemoveTopFrame_Impl( this );
+ DELETEZ( pWindow );
+
+ pFramesArr_Impl->Remove( pFramesArr_Impl->GetPos( this ) );
+
+ if ( pParentFrame )
+ {
+ pParentFrame->RemoveChildFrame_Impl( this );
+ pParentFrame = 0;
+ }
+
+ delete pImp->pDescr;
+
+ if ( pChildArr )
+ {
+ DBG_ASSERT( !pChildArr->Count(), "Childs nicht entfernt!" );
+ delete pChildArr;
+ }
+
+ delete pImp;
+}
+
+sal_Bool SfxFrame::DoClose()
+{
+ // Eigentlich wird noch ein PrepareClose gebraucht !!!
+ BOOL bRet = FALSE;
+ if ( !pImp->bClosing )
+ {
+ pImp->bClosing = sal_True;
+ CancelTransfers();
+
+ // now close frame; it will be deleted if this call is successful, so don't use any members after that!
+ bRet = TRUE;
+ try
+ {
+ Reference< XCloseable > xCloseable ( pImp->xFrame, UNO_QUERY );
+ if ( (!GetCurrentDocument() || !GetCurrentDocument()->Get_Impl()->bDisposing ) && xCloseable.is())
+ xCloseable->close(sal_True);
+ else if ( pImp->xFrame.is() )
+ {
+ Reference < XFrame > xFrame = pImp->xFrame;
+ xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
+ xFrame->dispose();
+ }
+ else
+ bRet = DoClose_Impl();
+ }
+ catch( ::com::sun::star::util::CloseVetoException& )
+ {
+ pImp->bClosing = sal_False;
+ bRet = FALSE;
+ }
+ catch( ::com::sun::star::lang::DisposedException& )
+ {
+ }
+ }
+
+ return bRet;
+}
+
+sal_Bool SfxFrame::DoClose_Impl()
+{
+ sal_Bool bRet = sal_True;
+ SfxBindings* pBindings = NULL;
+ if ( pImp->pCurrentViewFrame )
+ pBindings = &pImp->pCurrentViewFrame->GetBindings();
+
+ // Bei internen Tasks m"ussen Controller und Tools abger"aumt werden
+ if ( pImp->pWorkWin )
+ pImp->pWorkWin->DeleteControllers_Impl();
+
+ if ( pImp->pCurrentViewFrame )
+ bRet = pImp->pCurrentViewFrame->Close();
+
+ if ( pImp->bOwnsBindings )
+ DELETEZ( pBindings );
+
+ bRet = Close();
+ DBG_ASSERT( bRet, "Impossible state: frame closes, but controller refuses!");
+ return bRet;
+}
+
+sal_Bool SfxFrame::DocIsModified_Impl()
+{
+ if ( pImp->pCurrentViewFrame && pImp->pCurrentViewFrame->GetObjectShell() &&
+ pImp->pCurrentViewFrame->GetObjectShell()->IsModified() )
+ return sal_True;
+ for( sal_uInt16 nPos = GetChildFrameCount(); nPos--; )
+ if( pChildArr->GetObject( nPos )->DocIsModified_Impl() )
+ return sal_True;
+ return sal_False;
+}
+
+sal_uInt16 SfxFrame::PrepareClose_Impl( sal_Bool bUI, sal_Bool bForBrowsing )
+{
+ sal_uInt16 nRet = RET_OK;
+
+ // prevent recursive calls
+ if( !pImp->bPrepClosing )
+ {
+ pImp->bPrepClosing = sal_True;
+
+ SfxObjectShell* pCur = GetCurrentDocument() ;
+ if( pCur )
+ {
+ // SFX components have a known behaviour
+ // First check if this frame is the only view to its current document
+ int bOther = sal_False;
+ for ( const SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pCur );
+ !bOther && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pCur ) )
+ {
+ bOther = ( &pFrame->GetFrame() != this );
+ }
+
+ SFX_APP()->NotifyEvent( SfxViewEventHint(SFX_EVENT_PREPARECLOSEVIEW, GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEVIEW ), pCur, GetController() ) );
+
+ if ( bOther )
+ // if there are other views only the current view of this frame must be asked
+ nRet = GetCurrentViewFrame()->GetViewShell()->PrepareClose( bUI, bForBrowsing );
+ else
+ // otherwise ask the document
+ nRet = pCur->PrepareClose( bUI, bForBrowsing );
+ }
+
+ if ( nRet == RET_OK )
+ {
+ // if this frame has child frames, ask them too
+ for( USHORT nPos = GetChildFrameCount(); nRet == RET_OK && nPos--; )
+ nRet = pChildArr->GetObject( nPos )->PrepareClose_Impl( bUI, bForBrowsing );
+ }
+
+ pImp->bPrepClosing = sal_False;
+ }
+
+ if ( nRet == RET_OK && pImp->pWorkWin )
+ // if closing was accepted by the component the UI subframes must be asked also
+ nRet = pImp->pWorkWin->PrepareClose_Impl();
+
+ return nRet;
+}
+
+//--------------------------------------------------------------------
+
+SfxFrame* SfxFrame::GetChildFrame( sal_uInt16 nPos ) const
+{
+ if ( pChildArr && pChildArr->Count() > nPos )
+ {
+ DBG_ASSERT( nPos < pChildArr->Count(), "Falscher Index!");
+ return (*pChildArr)[nPos];
+ }
+
+ return 0L;
+}
+
+void SfxFrame::RemoveChildFrame_Impl( SfxFrame* pFrame )
+{
+ DBG_ASSERT( pChildArr, "Unbekannter Frame!");
+ sal_uInt16 nPos = pChildArr->GetPos(pFrame);
+ pChildArr->Remove( nPos );
+};
+
+SfxFrame& SfxFrame::GetTopFrame() const
+{
+ const SfxFrame* pParent = this;
+ while ( pParent->pParentFrame )
+ pParent = pParent->pParentFrame;
+ return *const_cast< SfxFrame* >( pParent );
+}
+
+sal_Bool SfxFrame::IsClosing_Impl() const
+{
+ return pImp->bClosing;
+}
+
+void SfxFrame::SetIsClosing_Impl()
+{
+ pImp->bClosing = TRUE;
+}
+
+sal_uInt16 SfxFrame::GetChildFrameCount() const
+{
+ return pChildArr ? pChildArr->Count() : 0;
+}
+
+void SfxFrame::CancelTransfers( sal_Bool /*bCancelLoadEnv*/ )
+{
+ if( !pImp->bInCancelTransfers )
+ {
+ pImp->bInCancelTransfers = sal_True;
+ SfxObjectShell* pObj = GetCurrentDocument();
+ if( pObj ) //&& !( pObj->Get_Impl()->nLoadedFlags & SFX_LOADED_ALL ))
+ {
+ SfxViewFrame* pFrm;
+ for( pFrm = SfxViewFrame::GetFirst( pObj );
+ pFrm && &pFrm->GetFrame() == this;
+ pFrm = SfxViewFrame::GetNext( *pFrm, pObj ) ) ;
+ // Keine anderer Frame mehr auf Doc -> Cancel
+ if( !pFrm )
+ {
+ pObj->CancelTransfers();
+ GetCurrentDocument()->Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
+ }
+ }
+
+ // zuerst Nachladende Frames stoppen
+ sal_uInt16 nCount = GetChildFrameCount();
+ for( sal_uInt16 n = 0; n<nCount; n++ )
+ GetChildFrame( n )->CancelTransfers();
+
+ // ggf. StarOne-Loader canceln
+ SfxFrameWeak wFrame( this );
+ if (wFrame.Is())
+ pImp->bInCancelTransfers = sal_False;
+ }
+}
+
+SfxViewFrame* SfxFrame::GetCurrentViewFrame() const
+{
+ return pImp->pCurrentViewFrame;
+}
+
+SfxDispatcher* SfxFrame::GetDispatcher_Impl() const
+{
+ if ( pImp->pCurrentViewFrame )
+ return pImp->pCurrentViewFrame->GetDispatcher();
+ return GetParentFrame()->GetDispatcher_Impl();
+}
+
+SfxObjectShell* SfxFrame::GetCurrentDocument() const
+{
+ return pImp->pCurrentViewFrame ?
+ pImp->pCurrentViewFrame->GetObjectShell() :
+ NULL;
+}
+
+void SfxFrame::SetCurrentViewFrame_Impl( SfxViewFrame *pFrame )
+{
+ pImp->pCurrentViewFrame = pFrame;
+}
+
+sal_uInt32 SfxFrame::GetFrameType() const
+{
+ return pImp->nType;
+}
+
+void SfxFrame::SetFrameType_Impl( sal_uInt32 n )
+{
+ pImp->nType = n;
+}
+
+void SfxFrame::GetViewData_Impl()
+{
+ // Alle zwischen Laden und Entfernen "anderbaren Daten aktualisieren; die
+ // festen Daten werden nur einmal ( nach PrepareForDoc_Impl in UpdateDescriptor )
+ // geholt, um Zeit zu sparen.
+ SfxViewFrame* pViewFrame = GetCurrentViewFrame();
+ if( pViewFrame && pViewFrame->GetViewShell() )
+ {
+ const SfxMedium *pMed = GetCurrentDocument()->GetMedium();
+ sal_Bool bReadOnly = pMed->GetOpenMode() == SFX_STREAM_READONLY;
+ GetDescriptor()->SetReadOnly( bReadOnly );
+
+ SfxItemSet *pSet = GetDescriptor()->GetArgs();
+ sal_Bool bGetViewData = sal_False;
+ if ( GetController().is() && pSet->GetItemState( SID_VIEW_DATA ) != SFX_ITEM_SET )
+ {
+ ::com::sun::star::uno::Any aData = GetController()->getViewData();
+ pSet->Put( SfxUsrAnyItem( SID_VIEW_DATA, aData ) );
+ bGetViewData = sal_True;
+ }
+
+ if ( pViewFrame->GetCurViewId() )
+ pSet->Put( SfxUInt16Item( SID_VIEW_ID, pViewFrame->GetCurViewId() ) );
+ if ( pChildArr )
+ {
+ // Bei Framesets m"ussen auch die Daten der ChildViews geholt werden
+ sal_uInt16 nCount = pChildArr->Count();
+ for ( sal_uInt16 n=nCount; n>0; n--)
+ {
+ SfxFrame* pFrame = (*pChildArr)[n-1];
+ if ( bGetViewData )
+ pFrame->GetDescriptor()->GetArgs()->ClearItem( SID_VIEW_DATA );
+ pFrame->GetViewData_Impl();
+ }
+ }
+ }
+}
+
+void SfxFrame::UpdateDescriptor( SfxObjectShell *pDoc )
+{
+ // Beim PrepareForDoc_Impl wird der Descriptor des Frames aktualisiert
+ // und sein ItemSet neu initialisiert. Alle Daten, die f"ur ein sp"ateres
+ // Restaurieren der View n"otig sind, sind damit festgehalten.
+ // Soll das Dokument ersetzt werden, wird durch GetViewData_Impl (s.o.)
+ // die neueste Information hinzugef"ugt. Alles zusammen wird dann in der
+ // Browse-History gesichert. Beim Aktivieren eines solchen FramePickEntry
+ // wird das komplette ItemSet und der Descriptor im OpenDoc mitgeschickt.
+ // Hier werden nur die festen Eigenschaften gesichert; die "anderbaren werden
+ // durch GetViewData geholt ( spart Zeit ).
+ DBG_ASSERT( pDoc, "NULL-Document inserted ?!" );
+
+ GetParentFrame();
+ const SfxMedium *pMed = pDoc->GetMedium();
+ GetDescriptor()->SetActualURL( pMed->GetOrigURL() );
+
+ SFX_ITEMSET_ARG( pMed->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, sal_False );
+ sal_Bool bEditable = ( !pItem || pItem->GetValue() );
+
+ GetDescriptor()->SetEditable( bEditable );
+
+ // FileOpen-Parameter merken
+ SfxItemSet* pItemSet = pMed->GetItemSet();
+ String aMedName( pMed->GetName() );
+
+ const SfxFilter* pFilter = pMed->GetOrigFilter();
+ String aFilter;
+ if ( pFilter )
+ aFilter = pFilter->GetFilterName();
+
+ SFX_ITEMSET_ARG( pItemSet, pRefererItem, SfxStringItem, SID_REFERER, sal_False);
+ SFX_ITEMSET_ARG( pItemSet, pOptionsItem, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False);
+ SFX_ITEMSET_ARG( pItemSet, pTitle1Item, SfxStringItem, SID_DOCINFO_TITLE, sal_False);
+
+ SfxItemSet *pSet = GetDescriptor()->GetArgs();
+
+ // Alle alten Items l"oschen
+ pSet->ClearItem();
+
+ if ( pRefererItem )
+ pSet->Put( *pRefererItem );
+ else
+ pSet->Put( SfxStringItem( SID_REFERER, String() ) );
+
+ if ( pOptionsItem )
+ pSet->Put( *pOptionsItem );
+
+ if ( pTitle1Item )
+ pSet->Put( *pTitle1Item );
+
+ pSet->Put( SfxStringItem( SID_FILTER_NAME, aFilter ));
+}
+
+//-------------------------------------------------------------------------
+
+void SfxFrame::SetDescriptor( SfxFrameDescriptor *pD )
+{
+ DBG_ASSERT( pD, "Kein Descriptor!" );
+ DBG_ASSERT( pD != pImp->pDescr, "Descriptor ist schon gesetzt!" );
+
+ if ( pImp->pDescr )
+ {
+ // Nur TopLevel-Frames verwalten ihren Descriptor selbst, bei den
+ // anderen tut es das Frameset
+ if ( !pParentFrame )
+ delete pImp->pDescr;
+ }
+ pImp->pDescr = pD;
+}
+
+//-------------------------------------------------------------------------
+
+SfxFrameDescriptor* SfxFrame::GetDescriptor() const
+{
+ // On Demand einen FrameDescriptor anlegen; wenn es kein TopLevel-Frame
+ // ist, f"uhrt es zu Fehlern, da keine g"ulige Verkettung hergestellt wird
+
+ if ( !pImp->pDescr )
+ {
+ DBG_ASSERT( !GetParentFrame(), "Kein TopLevel-Frame, aber kein Descriptor!" );
+ pImp->pDescr = new SfxFrameDescriptor;
+ if ( GetCurrentDocument() )
+ pImp->pDescr->SetURL( GetCurrentDocument()->GetMedium()->GetOrigURL() );
+ }
+ return pImp->pDescr;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxFrame::GetTargetList( TargetList& rList ) const
+{
+ if ( !GetParentFrame() )
+ {
+ // Einen Leerstring f"ur 'Kein Target'
+ rList.Insert( new String() );
+ rList.Insert( new String( DEFINE_CONST_UNICODE( "_top" ) ) );
+ rList.Insert( new String( DEFINE_CONST_UNICODE( "_parent" ) ) );
+ rList.Insert( new String( DEFINE_CONST_UNICODE( "_blank" ) ) );
+ rList.Insert( new String( DEFINE_CONST_UNICODE( "_self" ) ) );
+ }
+
+ SfxViewFrame* pView = GetCurrentViewFrame();
+ if( pView && pView->GetViewShell() && pChildArr )
+ {
+ sal_uInt16 nCount = pChildArr->Count();
+ for ( sal_uInt16 n=0; n<nCount; n++)
+ {
+ SfxFrame* pFrame = (*pChildArr)[n];
+ pFrame->GetTargetList( rList );
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+SfxBroadcaster& SfxFrame::GetBroadcaster() const
+{
+ return *pImp;
+}
+
+sal_Bool SfxFrame::IsParent( SfxFrame *pFrame ) const
+{
+ SfxFrame *pParent = pParentFrame;
+ while ( pParent )
+ {
+ if ( pParent == pFrame )
+ return sal_True;
+ pParent = pParent->pParentFrame;
+ }
+
+ return sal_False;
+}
+
+void SfxFrame::InsertTopFrame_Impl( SfxFrame* pFrame )
+{
+ SfxFrameArr_Impl& rArr = *SFX_APP()->Get_Impl()->pTopFrames;
+ rArr.Insert( pFrame, rArr.Count() );
+}
+
+void SfxFrame::RemoveTopFrame_Impl( SfxFrame* pFrame )
+{
+ SfxFrameArr_Impl& rArr = *SFX_APP()->Get_Impl()->pTopFrames;
+ rArr.Remove( rArr.GetPos( pFrame ) );
+}
+
+SfxFrameItem::SfxFrameItem( sal_uInt16 nWhichId, SfxViewFrame *p )
+ : SfxPoolItem( nWhichId ), pFrame( p ? &p->GetFrame() : NULL )
+{
+ wFrame = pFrame;
+}
+
+SfxFrameItem::SfxFrameItem( sal_uInt16 nWhichId, SfxFrame *p ):
+ SfxPoolItem( nWhichId ),
+ pFrame( p ), wFrame( p )
+{
+}
+
+SfxFrameItem::SfxFrameItem( SfxFrame *p ):
+ SfxPoolItem( 0 ),
+ pFrame( p ), wFrame( p )
+{
+}
+
+int SfxFrameItem::operator==( const SfxPoolItem &rItem ) const
+{
+ return ((SfxFrameItem&)rItem).pFrame == pFrame &&
+ ((SfxFrameItem&)rItem).wFrame == wFrame;
+}
+
+//--------------------------------------------------------------------
+
+String SfxFrameItem::GetValueText() const
+{
+ return String();
+}
+
+SfxPoolItem* SfxFrameItem::Clone( SfxItemPool *) const
+{
+ SfxFrameItem* pNew = new SfxFrameItem( wFrame);
+ pNew->SetFramePtr_Impl( pFrame );
+ return pNew;
+}
+
+sal_Bool SfxFrameItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE ) const
+{
+ if ( wFrame )
+ {
+ rVal <<= wFrame->GetFrameInterface();
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+sal_Bool SfxFrameItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE )
+{
+ Reference < XFrame > xFrame;
+ if ( (rVal >>= xFrame) && xFrame.is() )
+ {
+ SfxFrame* pFr = SfxFrame::GetFirst();
+ while ( pFr )
+ {
+ if ( pFr->GetFrameInterface() == xFrame )
+ {
+ wFrame = pFrame = pFr;
+ return TRUE;
+ }
+
+ pFr = SfxFrame::GetNext( *pFr );
+ }
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+SfxUsrAnyItem::SfxUsrAnyItem( sal_uInt16 nWhichId, const ::com::sun::star::uno::Any& rAny )
+ : SfxPoolItem( nWhichId )
+{
+ aValue = rAny;
+}
+
+int SfxUsrAnyItem::operator==( const SfxPoolItem& /*rItem*/ ) const
+{
+// return rItem.ISA( SfxUsrAnyItem ) && ((SfxUsrAnyItem&)rItem).aValue == aValue;
+ return sal_False;
+}
+
+SfxPoolItem* SfxUsrAnyItem::Clone( SfxItemPool *) const
+{
+ return new SfxUsrAnyItem( Which(), aValue );
+}
+
+sal_Bool SfxUsrAnyItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ ) const
+{
+ rVal = aValue;
+ return sal_True;
+}
+
+sal_Bool SfxUsrAnyItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ )
+{
+ aValue = rVal;
+ return sal_True;
+}
+
+SfxUnoFrameItem::SfxUnoFrameItem()
+ : SfxPoolItem()
+ , m_xFrame()
+{
+}
+
+SfxUnoFrameItem::SfxUnoFrameItem( sal_uInt16 nWhichId, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame )
+ : SfxPoolItem( nWhichId )
+ , m_xFrame( i_rFrame )
+{
+}
+
+int SfxUnoFrameItem::operator==( const SfxPoolItem& i_rItem ) const
+{
+ return i_rItem.ISA( SfxUnoFrameItem ) && static_cast< const SfxUnoFrameItem& >( i_rItem ).m_xFrame == m_xFrame;
+}
+
+SfxPoolItem* SfxUnoFrameItem::Clone( SfxItemPool* ) const
+{
+ return new SfxUnoFrameItem( Which(), m_xFrame );
+}
+
+sal_Bool SfxUnoFrameItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ ) const
+{
+ rVal <<= m_xFrame;
+ return sal_True;
+}
+
+sal_Bool SfxUnoFrameItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ )
+{
+ return ( rVal >>= m_xFrame );
+}
+
+SfxFrameIterator::SfxFrameIterator( const SfxFrame& rFrame, sal_Bool bRecur )
+ : pFrame( &rFrame )
+ , bRecursive( bRecur )
+{}
+
+SfxFrame* SfxFrameIterator::FirstFrame()
+{
+ // GetFirst beginnt die Iteration beim ersten ChildFrame
+ return pFrame->GetChildFrame( 0 );
+}
+
+SfxFrame* SfxFrameIterator::NextFrame( SfxFrame& rPrev )
+{
+ // Zuerst auf Kinder testen, wenn Rekursion erw"unscht
+ SfxFrame *pRet = NULL;
+ if ( bRecursive )
+ pRet = rPrev.GetChildFrame( 0 );
+ if ( !pRet )
+ {
+ // Anderenfalls mit den Geschwistern von rPrev weitermachen
+ pRet = NextSibling_Impl( rPrev );
+ }
+
+ return pRet;
+}
+
+
+SfxFrame* SfxFrameIterator::NextSibling_Impl( SfxFrame& rPrev )
+{
+ SfxFrame *pRet = NULL;
+ if ( &rPrev != pFrame )
+ {
+ SfxFrameArr_Impl& rArr = *rPrev.pParentFrame->pChildArr;
+ sal_uInt16 nPos = rArr.GetPos( &rPrev );
+ if ( nPos+1 < rArr.Count() )
+ pRet = rArr[nPos+1];
+
+ if ( !pRet && rPrev.pParentFrame->pParentFrame )
+ pRet = NextSibling_Impl( *rPrev.pParentFrame );
+ }
+
+ return pRet;
+}
+
+sal_Bool SfxFrame::IsTop() const
+{
+ return GetFrameInterface().is() ? GetFrameInterface()->isTop() : sal_False;
+}
+
+sal_Bool SfxFrame::HasComponent() const
+{
+ return sal_False;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SfxFrame::GetController() const
+{
+ if ( pImp->pCurrentViewFrame && pImp->pCurrentViewFrame->GetViewShell() )
+ return pImp->pCurrentViewFrame->GetViewShell()->GetController();
+ else
+ return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > ();
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SfxFrame::GetFrameInterface() const
+{
+ return pImp->xFrame;
+}
+
+void SfxFrame::SetFrameInterface_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame )
+{
+ pImp->xFrame = rFrame;
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
+ if ( !rFrame.is() && GetCurrentViewFrame() )
+ GetCurrentViewFrame()->GetBindings().SetRecorder_Impl( xRecorder );
+}
+
+void SfxFrame::Appear()
+{
+ if ( GetCurrentViewFrame() )
+ {
+ GetCurrentViewFrame()->Show();
+ GetWindow().Show();
+ pImp->xFrame->getContainerWindow()->setVisible( sal_True );
+ if ( pParentFrame )
+ pParentFrame->Appear();
+ Reference < ::com::sun::star::awt::XTopWindow > xTopWindow( pImp->xFrame->getContainerWindow(), UNO_QUERY );
+ if ( xTopWindow.is() )
+ xTopWindow->toFront();
+ }
+}
+
+void SfxFrame::AppearWithUpdate()
+{
+ Appear();
+ if ( GetCurrentViewFrame() )
+ GetCurrentViewFrame()->GetDispatcher()->Update_Impl( sal_True );
+}
+
+void SfxFrame::SetOwnsBindings_Impl( sal_Bool bSet )
+{
+ pImp->bOwnsBindings = bSet;
+}
+
+sal_Bool SfxFrame::OwnsBindings_Impl() const
+{
+ return pImp->bOwnsBindings;
+}
+
+void SfxFrame::SetToolSpaceBorderPixel_Impl( const SvBorder& rBorder )
+{
+ pImp->aBorder = rBorder;
+ SfxViewFrame *pF = GetCurrentViewFrame();
+ if ( pF )
+ {
+ Point aPos ( rBorder.Left(), rBorder.Top() );
+ Size aSize( GetWindow().GetOutputSizePixel() );
+ long nDeltaX = rBorder.Left() + rBorder.Right();
+ if ( aSize.Width() > nDeltaX )
+ aSize.Width() -= nDeltaX;
+ else
+ aSize.Width() = 0;
+
+ long nDeltaY = rBorder.Top() + rBorder.Bottom();
+ if ( aSize.Height() > nDeltaY )
+ aSize.Height() -= nDeltaY;
+ else
+ aSize.Height() = 0;
+
+ if ( GetParentFrame() )
+ {
+ sal_Bool bHasTools = rBorder.Left() != rBorder.Right() || rBorder.Top() != rBorder.Bottom();
+ pF->GetWindow().SetBorderStyle( bHasTools ? WINDOW_BORDER_NORMAL : WINDOW_BORDER_NOBORDER );
+ }
+
+ pF->GetWindow().SetPosSizePixel( aPos, aSize );
+ }
+}
+
+Rectangle SfxFrame::GetTopOuterRectPixel_Impl() const
+{
+ Size aSize( GetWindow().GetOutputSizePixel() );
+ Point aPoint;
+ return ( Rectangle ( aPoint, aSize ) );
+}
+
+SfxWorkWindow* SfxFrame::GetWorkWindow_Impl() const
+{
+ if ( pImp->pWorkWin )
+ return pImp->pWorkWin;
+ else if ( pParentFrame )
+ return pParentFrame->GetWorkWindow_Impl();
+ else
+ return NULL;
+}
+
+void SfxFrame::SetWorkWindow_Impl( SfxWorkWindow* pWorkwin )
+{
+ pImp->pWorkWin = pWorkwin;
+}
+
+void SfxFrame::CreateWorkWindow_Impl()
+{
+ SfxFrame* pFrame = this;
+
+ if ( IsInPlace() )
+ {
+ // this makes sence only for inplace activated objects
+ try
+ {
+ Reference < XChild > xChild( GetCurrentDocument()->GetModel(), UNO_QUERY );
+ if ( xChild.is() )
+ {
+ Reference < XModel > xParent( xChild->getParent(), UNO_QUERY );
+ if ( xParent.is() )
+ {
+ Reference< XController > xParentCtrler = xParent->getCurrentController();
+ if ( xParentCtrler.is() )
+ {
+ Reference < XFrame > xFrame( xParentCtrler->getFrame() );
+ SfxFrame* pFr = SfxFrame::GetFirst();
+ while ( pFr )
+ {
+ if ( pFr->GetFrameInterface() == xFrame )
+ {
+ pFrame = pFr;
+ break;
+ }
+
+ pFr = SfxFrame::GetNext( *pFr );
+ }
+ }
+ }
+ }
+ }
+ catch(Exception&)
+ {
+ OSL_ENSURE(0,"SfxFrame::CreateWorkWindow_Impl: Exception cachted. Please try to submit a repoducable bug !");
+ }
+ }
+
+ pImp->pWorkWin = new SfxFrameWorkWin_Impl( &pFrame->GetWindow(), this, pFrame );
+}
+
+void SfxFrame::GrabFocusOnComponent_Impl()
+{
+ if ( pImp->bReleasingComponent )
+ {
+ GetWindow().GrabFocus();
+ return;
+ }
+
+ Window* pFocusWindow = &GetWindow();
+ if ( GetCurrentViewFrame() && GetCurrentViewFrame()->GetViewShell() && GetCurrentViewFrame()->GetViewShell()->GetWindow() )
+ pFocusWindow = GetCurrentViewFrame()->GetViewShell()->GetWindow();
+
+ if( !pFocusWindow->HasChildPathFocus() )
+ pFocusWindow->GrabFocus();
+}
+
+void SfxFrame::ReleasingComponent_Impl( sal_Bool bSet )
+{
+ pImp->bReleasingComponent = bSet;
+}
+
+sal_Bool SfxFrame::IsInPlace() const
+{
+ return pImp->bInPlace;
+}
+
+void SfxFrame::SetInPlace_Impl( sal_Bool bSet )
+{
+ pImp->bInPlace = bSet;
+}
+
+void SfxFrame::Resize()
+{
+ if ( IsClosing_Impl() )
+ return;
+
+ if ( OwnsBindings_Impl() )
+ {
+ if ( IsInPlace() )
+ {
+ SetToolSpaceBorderPixel_Impl( SvBorder() );
+ }
+ else
+ {
+ // check for IPClient that contains UIactive object or object that is currently UI activating
+ SfxWorkWindow *pWork = GetWorkWindow_Impl();
+ SfxInPlaceClient* pClient = GetCurrentViewFrame()->GetViewShell() ? GetCurrentViewFrame()->GetViewShell()->GetUIActiveIPClient_Impl() : 0;
+ if ( pClient )
+ {
+ uno::Reference < lang::XUnoTunnel > xObj( pClient->GetObject()->getComponent(), uno::UNO_QUERY );
+ uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
+ sal_Int64 nHandle = (xObj.is()? xObj->getSomething( aSeq ): 0);
+ if ( nHandle )
+ {
+ SfxObjectShell* pDoc = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
+ pWork = SfxViewFrame::GetFirst( pDoc )->GetFrame().GetWorkWindow_Impl();
+ }
+ }
+
+ if ( pWork )
+ {
+ pWork->ArrangeChilds_Impl();
+ pWork->ShowChilds_Impl();
+ }
+
+ // problem in presence of UIActive object: when the window is resized, but the toolspace border
+ // remains the same, setting the toolspace border at the ContainerEnvironment doesn't force a
+ // resize on the IPEnvironment; without that no resize is called for the SfxViewFrame. So always
+ // set the window size of the SfxViewFrame explicit.
+ SetToolSpaceBorderPixel_Impl( pImp->aBorder );
+ }
+ }
+ else if ( pImp->pCurrentViewFrame )
+ {
+ pImp->pCurrentViewFrame->GetWindow().SetSizePixel( GetWindow().GetOutputSizePixel() );
+ }
+
+}
+
+SfxFrame* SfxFrame::GetFirst()
+{
+ if ( !pFramesArr_Impl )
+ return 0;
+ return pFramesArr_Impl->Count() ? pFramesArr_Impl->GetObject(0) : 0;
+}
+
+SfxFrame* SfxFrame::GetNext( SfxFrame& rFrame )
+{
+ USHORT nPos = pFramesArr_Impl->GetPos( &rFrame );
+ if ( nPos+1 < pFramesArr_Impl->Count() )
+ return pFramesArr_Impl->GetObject(nPos+1);
+ else
+ return NULL;
+}
+
+const SfxPoolItem* SfxFrame::OpenDocumentSynchron( SfxItemSet& i_rSet, const Reference< XFrame >& i_rTargetFrame )
+{
+ i_rSet.Put( SfxUnoFrameItem( SID_FILLFRAME, i_rTargetFrame ) );
+ i_rSet.ClearItem( SID_TARGETNAME );
+ return SFX_APP()->GetDispatcher_Impl()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, i_rSet );
+}
+
diff --git a/sfx2/source/view/frame2.cxx b/sfx2/source/view/frame2.cxx
new file mode 100644
index 000000000000..ef963b36d7bb
--- /dev/null
+++ b/sfx2/source/view/frame2.cxx
@@ -0,0 +1,481 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "impframe.hxx"
+#include "objshimp.hxx"
+#include "sfx2/sfxhelp.hxx"
+#include "workwin.hxx"
+
+#include "sfx2/app.hxx"
+#include "sfx2/bindings.hxx"
+#include "sfx2/dispatch.hxx"
+#include "sfx2/docfac.hxx"
+#include "sfx2/docfile.hxx"
+#include "sfx2/event.hxx"
+#include "sfx2/objface.hxx"
+#include "sfx2/request.hxx"
+
+#include <com/sun/star/awt/XWindow2.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <com/sun/star/frame/XLayoutManager.hpp>
+
+#include <comphelper/componentcontext.hxx>
+#include <comphelper/namedvaluecollection.hxx>
+#include <comphelper/processfactory.hxx>
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/itemset.hxx>
+#include <svl/rectitem.hxx>
+#include <svl/stritem.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <tools/diagnose_ex.h>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::beans;
+using ::com::sun::star::lang::XMultiServiceFactory;
+using ::com::sun::star::lang::XComponent;
+using ::com::sun::star::frame::XComponentLoader;
+
+//------------------------------------------------------------------------
+
+class SfxFrameWindow_Impl : public Window
+{
+public:
+ SfxFrame* pFrame;
+
+ SfxFrameWindow_Impl( SfxFrame* pF, Window& i_rContainerWindow );
+ ~SfxFrameWindow_Impl( );
+
+ virtual void DataChanged( const DataChangedEvent& rDCEvt );
+ virtual void StateChanged( StateChangedType nStateChange );
+ virtual long PreNotify( NotifyEvent& rNEvt );
+ virtual long Notify( NotifyEvent& rEvt );
+ virtual void Resize();
+ virtual void GetFocus();
+ void DoResize();
+ DECL_LINK( CloserHdl, void* );
+};
+
+SfxFrameWindow_Impl::SfxFrameWindow_Impl( SfxFrame* pF, Window& i_rContainerWindow )
+ : Window( &i_rContainerWindow, WB_BORDER | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_3DLOOK )
+ , pFrame( pF )
+{
+}
+
+SfxFrameWindow_Impl::~SfxFrameWindow_Impl( )
+{
+}
+
+void SfxFrameWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
+{
+ Window::DataChanged( rDCEvt );
+ SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
+ if ( pWorkWin )
+ pWorkWin->DataChanged_Impl( rDCEvt );
+}
+
+long SfxFrameWindow_Impl::Notify( NotifyEvent& rNEvt )
+{
+ if ( pFrame->IsClosing_Impl() || !pFrame->GetFrameInterface().is() )
+ return sal_False;
+
+ SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
+ if ( !pView || !pView->GetObjectShell() )
+ return Window::Notify( rNEvt );
+
+ if ( rNEvt.GetType() == EVENT_GETFOCUS )
+ {
+ if ( pView->GetViewShell() && !pView->GetViewShell()->GetUIActiveIPClient_Impl() && !pFrame->IsInPlace() )
+ {
+ DBG_TRACE("SfxFrame: GotFocus");
+ pView->MakeActive_Impl( FALSE );
+ }
+
+ // TODO/LATER: do we still need this code?
+ Window* pWindow = rNEvt.GetWindow();
+ rtl::OString sHelpId;
+ while ( !sHelpId.getLength() && pWindow )
+ {
+ sHelpId = pWindow->GetHelpId();
+ pWindow = pWindow->GetParent();
+ }
+
+ if ( sHelpId.getLength() )
+ SfxHelp::OpenHelpAgent( pFrame, sHelpId );
+
+ // if focus was on an external window, the clipboard content might have been changed
+ pView->GetBindings().Invalidate( SID_PASTE );
+ pView->GetBindings().Invalidate( SID_PASTE_SPECIAL );
+ return sal_True;
+ }
+ else if( rNEvt.GetType() == EVENT_KEYINPUT )
+ {
+ if ( pView->GetViewShell()->KeyInput( *rNEvt.GetKeyEvent() ) )
+ return TRUE;
+ }
+ else if ( rNEvt.GetType() == EVENT_EXECUTEDIALOG /*|| rNEvt.GetType() == EVENT_INPUTDISABLE*/ )
+ {
+ pView->SetModalMode( sal_True );
+ return sal_True;
+ }
+ else if ( rNEvt.GetType() == EVENT_ENDEXECUTEDIALOG /*|| rNEvt.GetType() == EVENT_INPUTENABLE*/ )
+ {
+ //EnableInput( sal_True, sal_True );
+ pView->SetModalMode( sal_False );
+ return sal_True;
+ }
+
+ return Window::Notify( rNEvt );
+}
+
+long SfxFrameWindow_Impl::PreNotify( NotifyEvent& rNEvt )
+{
+ USHORT nType = rNEvt.GetType();
+ if ( nType == EVENT_KEYINPUT || nType == EVENT_KEYUP )
+ {
+ SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
+ SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
+ if ( pShell && pShell->HasKeyListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
+ return sal_True;
+ }
+ else if ( nType == EVENT_MOUSEBUTTONUP || nType == EVENT_MOUSEBUTTONDOWN )
+ {
+ Window* pWindow = rNEvt.GetWindow();
+ SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
+ SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
+ if ( pShell )
+ if ( pWindow == pShell->GetWindow() || pShell->GetWindow()->IsChild( pWindow ) )
+ if ( pShell->HasMouseClickListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
+ return sal_True;
+ }
+
+ if ( nType == EVENT_MOUSEBUTTONDOWN )
+ {
+ Window* pWindow = rNEvt.GetWindow();
+ const MouseEvent* pMEvent = rNEvt.GetMouseEvent();
+ Point aPos = pWindow->OutputToScreenPixel( pMEvent->GetPosPixel() );
+ SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
+ if ( pWorkWin )
+ pWorkWin->EndAutoShow_Impl( aPos );
+ }
+
+ return Window::PreNotify( rNEvt );
+}
+
+void SfxFrameWindow_Impl::GetFocus()
+{
+ if ( pFrame && !pFrame->IsClosing_Impl() && pFrame->GetCurrentViewFrame() && pFrame->GetFrameInterface().is() )
+ pFrame->GetCurrentViewFrame()->MakeActive_Impl( TRUE );
+}
+
+void SfxFrameWindow_Impl::Resize()
+{
+ if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
+ DoResize();
+}
+
+void SfxFrameWindow_Impl::StateChanged( StateChangedType nStateChange )
+{
+ if ( nStateChange == STATE_CHANGE_INITSHOW )
+ {
+ pFrame->pImp->bHidden = FALSE;
+ if ( pFrame->IsInPlace() )
+ // TODO/MBA: workaround for bug in LayoutManager: the final resize does not get through because the
+ // LayoutManager works asynchronously and between resize and time execution the DockingAcceptor was exchanged so that
+ // the resize event never is sent to the component
+ SetSizePixel( GetParent()->GetOutputSizePixel() );
+
+ DoResize();
+ SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
+ if ( pView )
+ pView->GetBindings().GetWorkWindow_Impl()->ShowChilds_Impl();
+ }
+
+ Window::StateChanged( nStateChange );
+}
+
+void SfxFrameWindow_Impl::DoResize()
+{
+ if ( !pFrame->pImp->bLockResize )
+ pFrame->Resize();
+}
+
+Reference < XFrame > SfxFrame::CreateBlankFrame()
+{
+ Reference < XFrame > xFrame;
+ try
+ {
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ Reference < XFrame > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
+ xFrame.set( xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 ), UNO_SET_THROW );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return xFrame;
+}
+
+SfxFrame* SfxFrame::Create( SfxObjectShell& rDoc, Window& rWindow, USHORT nViewId, bool bHidden )
+{
+ SfxFrame* pFrame = NULL;
+ try
+ {
+ // create and initialize new top level frame for this window
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ Reference < XFramesSupplier > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
+ Reference < XFrame > xFrame( aContext.createComponent( "com.sun.star.frame.Frame"), UNO_QUERY_THROW );
+
+ Reference< awt::XWindow2 > xWin( VCLUnoHelper::GetInterface ( &rWindow ), uno::UNO_QUERY_THROW );
+ xFrame->initialize( xWin.get() );
+ xDesktop->getFrames()->append( xFrame );
+
+ if ( xWin->isActive() )
+ xFrame->activate();
+
+ // create load arguments
+ Sequence< PropertyValue > aLoadArgs;
+ TransformItems( SID_OPENDOC, *rDoc.GetMedium()->GetItemSet(), aLoadArgs );
+
+ ::comphelper::NamedValueCollection aArgs( aLoadArgs );
+ aArgs.put( "Model", rDoc.GetModel() );
+ aArgs.put( "Hidden", bHidden );
+ if ( nViewId )
+ aArgs.put( "ViewId", nViewId );
+
+ aLoadArgs = aArgs.getPropertyValues();
+
+ // load the doc into that frame
+ ::rtl::OUString sLoaderURL( RTL_CONSTASCII_USTRINGPARAM( "private:object" ) );
+ Reference< XComponentLoader > xLoader( xFrame, UNO_QUERY_THROW );
+ xLoader->loadComponentFromURL(
+ sLoaderURL,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ),
+ 0,
+ aLoadArgs
+ );
+
+ for ( pFrame = SfxFrame::GetFirst();
+ pFrame;
+ pFrame = SfxFrame::GetNext( *pFrame )
+ )
+ {
+ if ( pFrame->GetFrameInterface() == xFrame )
+ break;
+ }
+
+ OSL_ENSURE( pFrame, "SfxFrame::Create: load succeeded, but no SfxFrame was created during this!" );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
+ return pFrame;
+}
+
+SfxFrame* SfxFrame::Create( const Reference < XFrame >& i_rFrame )
+{
+ // create a new TopFrame to an external XFrame object ( wrap controller )
+ ENSURE_OR_THROW( i_rFrame.is(), "NULL frame not allowed" );
+ Window* pWindow = VCLUnoHelper::GetWindow( i_rFrame->getContainerWindow() );
+ ENSURE_OR_THROW( pWindow, "frame without container window not allowed" );
+
+ SfxFrame* pFrame = new SfxFrame( *pWindow, false );
+ pFrame->SetFrameInterface_Impl( i_rFrame );
+ return pFrame;
+}
+
+SfxFrame::SfxFrame( Window& i_rContainerWindow, bool i_bHidden )
+ :pParentFrame( NULL )
+ ,pChildArr( NULL )
+ ,pImp( NULL )
+ ,pWindow( NULL )
+{
+ Construct_Impl();
+
+ pImp->bHidden = i_bHidden;
+ InsertTopFrame_Impl( this );
+ pImp->pExternalContainerWindow = &i_rContainerWindow;
+
+ pWindow = new SfxFrameWindow_Impl( this, i_rContainerWindow );
+
+ // always show pWindow, which is the ComponentWindow of the XFrame we live in
+ // nowadays, since SfxFrames can be created with an XFrame only, hiding or showing the complete XFrame
+ // is not done at level of the container window, not at SFX level. Thus, the component window can
+ // always be visible.
+ pWindow->Show();
+}
+
+void SfxFrame::SetPresentationMode( BOOL bSet )
+{
+ if ( GetCurrentViewFrame() )
+ GetCurrentViewFrame()->GetWindow().SetBorderStyle( bSet ? WINDOW_BORDER_NOBORDER : WINDOW_BORDER_NORMAL );
+
+ Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
+ Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+
+ if ( xPropSet.is() )
+ {
+ Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
+ aValue >>= xLayoutManager;
+ }
+
+ if ( xLayoutManager.is() )
+ xLayoutManager->setVisible( !bSet ); // we don't want to have ui in presentation mode
+
+ SetMenuBarOn_Impl( !bSet );
+ if ( GetWorkWindow_Impl() )
+ GetWorkWindow_Impl()->SetDockingAllowed( !bSet );
+ if ( GetCurrentViewFrame() )
+ GetCurrentViewFrame()->GetDispatcher()->Update_Impl( TRUE );
+}
+
+SystemWindow* SfxFrame::GetSystemWindow() const
+{
+ return GetTopWindow_Impl();
+}
+
+SystemWindow* SfxFrame::GetTopWindow_Impl() const
+{
+ if ( pImp->pExternalContainerWindow->IsSystemWindow() )
+ return (SystemWindow*) pImp->pExternalContainerWindow;
+ else
+ return NULL;
+}
+
+Window& SfxFrame::GetWindow() const
+{
+ return *pWindow;
+}
+
+sal_Bool SfxFrame::Close()
+{
+ delete this;
+ return sal_True;
+}
+
+void SfxFrame::LockResize_Impl( BOOL bLock )
+{
+ pImp->bLockResize = bLock;
+}
+
+IMPL_LINK( SfxFrameWindow_Impl, CloserHdl, void*, EMPTYARG )
+{
+ if ( pFrame && !pFrame->PrepareClose_Impl( TRUE ) )
+ return 0L;
+
+ if ( pFrame )
+ pFrame->GetCurrentViewFrame()->GetBindings().Execute( SID_CLOSEWIN, 0, 0, SFX_CALLMODE_ASYNCHRON );
+ return 0L;
+}
+
+void SfxFrame::SetMenuBarOn_Impl( BOOL bOn )
+{
+ pImp->bMenuBarOn = bOn;
+
+ Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
+ Reference< ::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" ));
+
+ if ( bOn )
+ xLayoutManager->showElement( aMenuBarURL );
+ else
+ xLayoutManager->hideElement( aMenuBarURL );
+ }
+}
+
+BOOL SfxFrame::IsMenuBarOn_Impl() const
+{
+ return pImp->bMenuBarOn;
+}
+
+void SfxFrame::PositionWindow_Impl( const Rectangle& rWinArea ) const
+{
+ Window *pWin = pImp->pExternalContainerWindow;
+
+ // Groesse setzen
+ const Size aAppWindow( pImp->pExternalContainerWindow->GetDesktopRectPixel().GetSize() );
+ Point aPos( rWinArea.TopLeft() );
+ Size aSz( rWinArea.GetSize() );
+ if ( aSz.Width() && aSz.Height() )
+ {
+ aPos.X() = Min(aPos.X(),
+ long(aAppWindow.Width() - aSz.Width() + aSz.Width() / 2) );
+ aPos.Y() = Min(aPos.Y(),
+ long( aAppWindow.Height() - aSz.Height() + aSz.Height() / 2) );
+ if ( aPos.X() + aSz.Width() <
+ aAppWindow.Width() + aSz.Width() / 2 &&
+ aPos.Y() + aSz.Height() <
+ aAppWindow.Height() + aSz.Height() / 2 )
+ {
+ pWin->SetPosPixel( aPos );
+ pWin->SetOutputSizePixel( aSz );
+ }
+ }
+}
+
+void SfxFrame::PrepareForDoc_Impl( SfxObjectShell& i_rDoc )
+{
+ const ::comphelper::NamedValueCollection aDocumentArgs( i_rDoc.GetModel()->getArgs() );
+
+ // hidden?
+ OSL_ENSURE( !pImp->bHidden, "when does this happen?" );
+ pImp->bHidden = aDocumentArgs.getOrDefault( "Hidden", pImp->bHidden );
+
+ // update our descriptor
+ UpdateDescriptor( &i_rDoc );
+
+ // plugin mode
+ sal_Int16 nPluginMode = aDocumentArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
+ if ( nPluginMode && ( nPluginMode != 2 ) )
+ SetInPlace_Impl( TRUE );
+}
+
+bool SfxFrame::IsMarkedHidden_Impl() const
+{
+ return pImp->bHidden;
+}
diff --git a/sfx2/source/view/frmload.cxx b/sfx2/source/view/frmload.cxx
new file mode 100644
index 000000000000..a4707f03d364
--- /dev/null
+++ b/sfx2/source/view/frmload.cxx
@@ -0,0 +1,745 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "frmload.hxx"
+#include "objshimp.hxx"
+#include "sfx2/app.hxx"
+#include "sfx2/dispatch.hxx"
+#include "sfx2/docfac.hxx"
+#include "sfx2/docfile.hxx"
+#include "sfx2/docfilt.hxx"
+#include "sfx2/doctempl.hxx"
+#include "sfx2/fcontnr.hxx"
+#include "sfx2/frame.hxx"
+#include "sfx2/request.hxx"
+#include "sfx2/sfx.hrc"
+#include "sfx2/sfxsids.hrc"
+#include "sfx2/sfxuno.hxx"
+#include "sfx2/viewfrm.hxx"
+#include "sfx2/viewsh.hxx"
+#include "sfx2/viewfac.hxx"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/container/XContainerQuery.hpp>
+#include <com/sun/star/document/XTypeDetection.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XLoadable.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/task/XInteractionHandler2.hpp>
+#include <com/sun/star/document/XViewDataSupplier.hpp>
+#include <com/sun/star/container/XIndexAccess.hpp>
+/** === end UNO includes === **/
+
+#include <comphelper/interaction.hxx>
+#include <comphelper/namedvaluecollection.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <cppuhelper/exc_hlp.hxx>
+#include <framework/interaction.hxx>
+#include <rtl/logfile.hxx>
+#include <rtl/ustring.h>
+#include <sot/storinfo.hxx>
+#include <svtools/ehdl.hxx>
+#include <svl/eitem.hxx>
+#include <svl/itemset.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svl/stritem.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <tools/diagnose_ex.h>
+#include <ucbhelper/simpleinteractionrequest.hxx>
+#include <vos/mutex.hxx>
+
+/** === begin UNO using === **/
+using ::com::sun::star::beans::PropertyValue;
+using ::com::sun::star::container::XContainerQuery;
+using ::com::sun::star::container::XEnumeration;
+using ::com::sun::star::document::XTypeDetection;
+using ::com::sun::star::frame::XFrame;
+using ::com::sun::star::frame::XLoadable;
+using ::com::sun::star::frame::XModel;
+using ::com::sun::star::lang::XMultiServiceFactory;
+using ::com::sun::star::task::XInteractionHandler;
+using ::com::sun::star::task::XInteractionHandler2;
+using ::com::sun::star::task::XInteractionRequest;
+using ::com::sun::star::task::XStatusIndicator;
+using ::com::sun::star::uno::Any;
+using ::com::sun::star::uno::Exception;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::RuntimeException;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::uno::UNO_QUERY;
+using ::com::sun::star::uno::UNO_QUERY_THROW;
+using ::com::sun::star::uno::UNO_SET_THROW;
+using ::com::sun::star::uno::makeAny;
+using ::com::sun::star::util::XCloseable;
+using ::com::sun::star::document::XViewDataSupplier;
+using ::com::sun::star::container::XIndexAccess;
+using ::com::sun::star::frame::XController2;
+using ::com::sun::star::frame::XController;
+using ::com::sun::star::frame::XModel2;
+/** === end UNO using === **/
+
+SfxFrameLoader_Impl::SfxFrameLoader_Impl( const Reference< XMultiServiceFactory >& _rxFactory )
+ :m_aContext( _rxFactory )
+{
+}
+
+SfxFrameLoader_Impl::~SfxFrameLoader_Impl()
+{
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+const SfxFilter* SfxFrameLoader_Impl::impl_detectFilterForURL( const ::rtl::OUString& sURL,
+ const ::comphelper::NamedValueCollection& i_rDescriptor, const SfxFilterMatcher& rMatcher ) const
+{
+ ::rtl::OUString sFilter;
+ try
+ {
+ if ( !sURL.getLength() )
+ return 0;
+
+ Reference< XTypeDetection > xDetect(
+ m_aContext.createComponent( "com.sun.star.document.TypeDetection" ),
+ UNO_QUERY_THROW);
+
+ ::comphelper::NamedValueCollection aNewArgs;
+ aNewArgs.put( "URL", sURL );
+
+ if ( i_rDescriptor.has( "InteractionHandler" ) )
+ aNewArgs.put( "InteractionHandler", i_rDescriptor.get( "InteractionHandler" ) );
+ if ( i_rDescriptor.has( "StatusIndicator" ) )
+ aNewArgs.put( "StatusIndicator", i_rDescriptor.get( "StatusIndicator" ) );
+
+ Sequence< PropertyValue > aQueryArgs( aNewArgs.getPropertyValues() );
+ ::rtl::OUString sType = xDetect->queryTypeByDescriptor( aQueryArgs, sal_True );
+ if ( sType.getLength() )
+ {
+ const SfxFilter* pFilter = rMatcher.GetFilter4EA( sType );
+ if ( pFilter )
+ sFilter = pFilter->GetName();
+ }
+ }
+ catch ( const RuntimeException& )
+ {
+ throw;
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ sFilter = ::rtl::OUString();
+ }
+
+ const SfxFilter* pFilter = 0;
+ if (sFilter.getLength())
+ pFilter = rMatcher.GetFilter4FilterName(sFilter);
+ return pFilter;
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+const SfxFilter* SfxFrameLoader_Impl::impl_getFilterFromServiceName_nothrow( const ::rtl::OUString& i_rServiceName ) const
+{
+ try
+ {
+ ::comphelper::NamedValueCollection aQuery;
+ aQuery.put( "DocumentService", i_rServiceName );
+
+ const Reference< XContainerQuery > xQuery(
+ m_aContext.createComponent( "com.sun.star.document.FilterFactory" ),
+ UNO_QUERY_THROW );
+
+ const SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
+ const SfxFilterFlags nMust = SFX_FILTER_IMPORT;
+ const SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED;
+
+ Reference < XEnumeration > xEnum( xQuery->createSubSetEnumerationByProperties(
+ aQuery.getNamedValues() ), UNO_SET_THROW );
+ while ( xEnum->hasMoreElements() )
+ {
+ ::comphelper::NamedValueCollection aType( xEnum->nextElement() );
+ ::rtl::OUString sFilterName = aType.getOrDefault( "Name", ::rtl::OUString() );
+ if ( !sFilterName.getLength() )
+ continue;
+
+ const SfxFilter* pFilter = rMatcher.GetFilter4FilterName( sFilterName );
+ if ( !pFilter )
+ continue;
+
+ SfxFilterFlags nFlags = pFilter->GetFilterFlags();
+ if ( ( ( nFlags & nMust ) == nMust )
+ && ( ( nFlags & nDont ) == 0 )
+ )
+ {
+ return pFilter;
+ }
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return NULL;
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+::rtl::OUString SfxFrameLoader_Impl::impl_askForFilter_nothrow( const Reference< XInteractionHandler >& i_rxHandler,
+ const ::rtl::OUString& i_rDocumentURL ) const
+{
+ ENSURE_OR_THROW( i_rxHandler.is(), "invalid interaction handler" );
+
+ ::rtl::OUString sFilterName;
+ try
+ {
+ ::framework::RequestFilterSelect aRequest( i_rDocumentURL );
+ i_rxHandler->handle( aRequest.GetRequest() );
+ if( !aRequest.isAbort() )
+ sFilterName = aRequest.getFilter();
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
+ return sFilterName;
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+namespace
+{
+ sal_Bool lcl_getDispatchResult( const SfxPoolItem* _pResult )
+ {
+ if ( !_pResult )
+ return sal_False;
+
+ // default must be set to true, because some return values
+ // cant be checked, but nonetheless indicate "success"!
+ sal_Bool bSuccess = sal_True;
+
+ // On the other side some special slots return a boolean state,
+ // which can be set to FALSE.
+ SfxBoolItem *pItem = PTR_CAST( SfxBoolItem, _pResult );
+ if ( pItem )
+ bSuccess = pItem->GetValue();
+
+ return bSuccess;
+ }
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+sal_Bool SfxFrameLoader_Impl::impl_createNewDocWithSlotParam( const USHORT _nSlotID, const Reference< XFrame >& i_rxFrame,
+ const bool i_bHidden )
+{
+ SfxRequest aRequest( _nSlotID, SFX_CALLMODE_SYNCHRON, SFX_APP()->GetPool() );
+ aRequest.AppendItem( SfxUnoFrameItem( SID_FILLFRAME, i_rxFrame ) );
+ if ( i_bHidden )
+ aRequest.AppendItem( SfxBoolItem( SID_HIDDEN, TRUE ) );
+ return lcl_getDispatchResult( SFX_APP()->ExecuteSlot( aRequest ) );
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+void SfxFrameLoader_Impl::impl_lockHiddenDocument( SfxObjectShell& i_rDocument, const ::comphelper::NamedValueCollection& i_rDescriptor ) const
+{
+ const sal_Bool bHidden = i_rDescriptor.getOrDefault( "Hidden", sal_False );
+ if ( !bHidden )
+ return;
+
+ const SfxViewFrame* pExistingViewFrame = SfxViewFrame::GetFirst( &i_rDocument );
+ if ( pExistingViewFrame )
+ return;
+
+ // the document is to be loaded hidden, and it is not yet displayed in any other frame
+ // To prevent it from being closed when the loader returns, increase its OwnerLock
+ // (the OwnerLock is normally increased by every frame in which the document is displayed, and by this loader)
+ i_rDocument.RestoreNoDelete();
+ i_rDocument.OwnerLock( TRUE );
+ i_rDocument.Get_Impl()->bHiddenLockedByAPI = TRUE;
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+void SfxFrameLoader_Impl::impl_determineFilter( ::comphelper::NamedValueCollection& io_rDescriptor ) const
+{
+ const ::rtl::OUString sURL = io_rDescriptor.getOrDefault( "URL", ::rtl::OUString() );
+ const ::rtl::OUString sTypeName = io_rDescriptor.getOrDefault( "TypeName", ::rtl::OUString() );
+ const ::rtl::OUString sFilterName = io_rDescriptor.getOrDefault( "FilterName", ::rtl::OUString() );
+ const ::rtl::OUString sServiceName = io_rDescriptor.getOrDefault( "DocumentService", ::rtl::OUString() );
+ const Reference< XInteractionHandler >
+ xInteraction = io_rDescriptor.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() );
+
+ const SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
+ const SfxFilter* pFilter = NULL;
+
+ // get filter by its name directly ...
+ if ( sFilterName.getLength() )
+ pFilter = rMatcher.GetFilter4FilterName( sFilterName );
+
+ // or search the preferred filter for the detected type ...
+ if ( !pFilter && sTypeName.getLength() )
+ pFilter = rMatcher.GetFilter4EA( sTypeName );
+
+ // or use given document service for detection, too
+ if ( !pFilter && sServiceName.getLength() )
+ pFilter = impl_getFilterFromServiceName_nothrow( sServiceName );
+
+ // or use interaction to ask user for right filter.
+ if ( !pFilter && xInteraction.is() && sURL.getLength() )
+ {
+ ::rtl::OUString sSelectedFilter = impl_askForFilter_nothrow( xInteraction, sURL );
+ if ( sSelectedFilter.getLength() )
+ pFilter = rMatcher.GetFilter4FilterName( sSelectedFilter );
+ }
+
+ if ( pFilter )
+ {
+ io_rDescriptor.put( "FilterName", ::rtl::OUString( pFilter->GetFilterName() ) );
+
+ // If detected filter indicates using of an own template format
+ // add property "AsTemplate" to descriptor. But suppress this step
+ // if such property already exists.
+ if ( pFilter->IsOwnTemplateFormat() && !io_rDescriptor.has( "AsTemplate" ) )
+ io_rDescriptor.put( "AsTemplate", sal_Bool( sal_True ) );
+
+ // The DocumentService property will finally be used to determine the document type to create, so
+ // override it with the service name as indicated by the found filter.
+ io_rDescriptor.put( "DocumentService", ::rtl::OUString( pFilter->GetServiceName() ) );
+ }
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+SfxObjectShellLock SfxFrameLoader_Impl::impl_findObjectShell( const Reference< XModel2 >& i_rxDocument ) const
+{
+ for ( SfxObjectShell* pDoc = SfxObjectShell::GetFirst( NULL, FALSE ); pDoc; pDoc = SfxObjectShell::GetNext( *pDoc, NULL, FALSE ) )
+ {
+ if ( i_rxDocument == pDoc->GetModel() )
+ {
+ return pDoc;
+ }
+ }
+
+ DBG_ERROR( "SfxFrameLoader_Impl::impl_findObjectShell: model is not based on SfxObjectShell - wrong frame loader usage!" );
+ return NULL;
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+bool SfxFrameLoader_Impl::impl_determineTemplateDocument( ::comphelper::NamedValueCollection& io_rDescriptor ) const
+{
+ const ::rtl::OUString sTemplateRegioName = io_rDescriptor.getOrDefault( "TemplateRegionName", ::rtl::OUString() );
+ const ::rtl::OUString sTemplateName = io_rDescriptor.getOrDefault( "TemplateName", ::rtl::OUString() );
+ const ::rtl::OUString sServiceName = io_rDescriptor.getOrDefault( "DocumentService", ::rtl::OUString() );
+ const ::rtl::OUString sURL = io_rDescriptor.getOrDefault( "URL", ::rtl::OUString() );
+
+ // determine the full URL of the template to use, if any
+ String sTemplateURL;
+ if ( sTemplateRegioName.getLength() && sTemplateName.getLength() )
+ {
+ SfxDocumentTemplates aTmpFac;
+ aTmpFac.GetFull( sTemplateRegioName, sTemplateName, sTemplateURL );
+ }
+ else
+ {
+ if ( sServiceName.getLength() )
+ sTemplateURL = SfxObjectFactory::GetStandardTemplate( sServiceName );
+ else
+ sTemplateURL = SfxObjectFactory::GetStandardTemplate( SfxObjectShell::GetServiceNameFromFactory( sURL ) );
+ }
+
+ if ( sTemplateURL.Len() > 0 )
+ {
+ // detect the filter for the template. Might still be NULL (if the template is broken, or does not
+ // exist, or some such), but this is handled by our caller the same way as if no template/URL was present.
+ const SfxFilter* pTemplateFilter = impl_detectFilterForURL( sTemplateURL, io_rDescriptor, SFX_APP()->GetFilterMatcher() );
+ if ( pTemplateFilter )
+ {
+ // load the template document, but, well, "as template"
+ io_rDescriptor.put( "FilterName", ::rtl::OUString( pTemplateFilter->GetName() ) );
+ io_rDescriptor.put( "FileName", ::rtl::OUString( sTemplateURL ) );
+ io_rDescriptor.put( "AsTemplate", sal_True );
+
+ // #i21583#
+ // the DocumentService property will finally be used to create the document. Thus, override any possibly
+ // present value with the document service of the template.
+ io_rDescriptor.put( "DocumentService", ::rtl::OUString( pTemplateFilter->GetServiceName() ) );
+ return true;
+ }
+ }
+ return false;
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+USHORT SfxFrameLoader_Impl::impl_findSlotParam( const ::rtl::OUString& i_rFactoryURL ) const
+{
+ ::rtl::OUString sSlotParam;
+ const sal_Int32 nParamPos = i_rFactoryURL.indexOf( '?' );
+ if ( nParamPos >= 0 )
+ {
+ // currently only the "slot" parameter is supported
+ const sal_Int32 nSlotPos = i_rFactoryURL.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "slot=" ), nParamPos );
+ if ( nSlotPos > 0 )
+ sSlotParam = i_rFactoryURL.copy( nSlotPos + 5 );
+ }
+
+ if ( sSlotParam.getLength() )
+ return USHORT( sSlotParam.toInt32() );
+
+ return 0;
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+void SfxFrameLoader_Impl::impl_handleCaughtError_nothrow( const Any& i_rCaughtError, const ::comphelper::NamedValueCollection& i_rDescriptor ) const
+{
+ try
+ {
+ const Reference< XInteractionHandler > xInteraction =
+ i_rDescriptor.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() );
+ if ( !xInteraction.is() )
+ return;
+ ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( i_rCaughtError ) );
+ ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
+ pRequest->addContinuation( pApprove.get() );
+
+ const Reference< XInteractionHandler2 > xHandler( xInteraction, UNO_QUERY );
+ #if OSL_DEBUG_LEVEL > 0
+ const sal_Bool bHandled =
+ #endif
+ xHandler.is() && xHandler->handleInteractionRequest( pRequest.get() );
+
+ #if OSL_DEBUG_LEVEL > 0
+ if ( !bHandled )
+ // the interaction handler couldn't deal with this error
+ // => report it as assertion, at least (done in the DBG_UNHANDLED_EXCEPTION below)
+ ::cppu::throwException( i_rCaughtError );
+ #endif
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+void SfxFrameLoader_Impl::impl_removeLoaderArguments( ::comphelper::NamedValueCollection& io_rDescriptor )
+{
+ // remove the arguments which are for the loader only, and not for a call to attachResource
+ io_rDescriptor.remove( "StatusIndicator" );
+ io_rDescriptor.remove( "Model" );
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+::comphelper::NamedValueCollection SfxFrameLoader_Impl::impl_extractViewCreationArgs( ::comphelper::NamedValueCollection& io_rDescriptor )
+{
+ const sal_Char* pKnownViewArgs[] = {
+ "JumpMark"
+ };
+
+ ::comphelper::NamedValueCollection aViewArgs;
+ for ( size_t i=0; i < sizeof( pKnownViewArgs ) / sizeof( pKnownViewArgs[0] ); ++i )
+ {
+ if ( io_rDescriptor.has( pKnownViewArgs[i] ) )
+ {
+ aViewArgs.put( pKnownViewArgs[i], io_rDescriptor.get( pKnownViewArgs[i] ) );
+ io_rDescriptor.remove( pKnownViewArgs[i] );
+ }
+ }
+ return aViewArgs;
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+sal_Int16 SfxFrameLoader_Impl::impl_determineEffectiveViewId_nothrow( const SfxObjectShell& i_rDocument, const ::comphelper::NamedValueCollection& i_rDescriptor )
+{
+ sal_Int16 nViewId = i_rDescriptor.getOrDefault( "ViewId", sal_Int16( 0 ) );
+ try
+ {
+ if ( nViewId == 0 ) do
+ {
+ Reference< XViewDataSupplier > xViewDataSupplier( i_rDocument.GetModel(), UNO_QUERY );
+ Reference< XIndexAccess > xViewData;
+ if ( xViewDataSupplier.is() )
+ xViewData.set( xViewDataSupplier->getViewData() );
+
+ if ( !xViewData.is() || ( xViewData->getCount() == 0 ) )
+ // no view data stored together with the model
+ break;
+
+ // obtain the ViewID from the view data
+ Sequence< PropertyValue > aViewData;
+ if ( !( xViewData->getByIndex( 0 ) >>= aViewData ) )
+ break;
+
+ ::comphelper::NamedValueCollection aNamedViewData( aViewData );
+ ::rtl::OUString sViewId = aNamedViewData.getOrDefault( "ViewId", ::rtl::OUString() );
+ if ( !sViewId.getLength() )
+ break;
+
+ // somewhat weird convention here ... in the view data, the ViewId is a string, effectively describing
+ // a view name. In the document load descriptor, the ViewId is in fact the numeric ID.
+
+ SfxViewFactory* pViewFactory = i_rDocument.GetFactory().GetViewFactoryByViewName( sViewId );
+ if ( pViewFactory )
+ nViewId = sal_Int16( pViewFactory->GetOrdinal() );
+ }
+ while ( false );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
+ if ( nViewId == 0 )
+ nViewId = i_rDocument.GetFactory().GetViewFactory( 0 ).GetOrdinal();
+ return nViewId;
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+Reference< XController2 > SfxFrameLoader_Impl::impl_createDocumentView( const Reference< XModel2 >& i_rModel,
+ const Reference< XFrame >& i_rFrame, const ::comphelper::NamedValueCollection& i_rViewFactoryArgs,
+ const ::rtl::OUString& i_rViewName )
+{
+ // let the model create a new controller
+ const Reference< XController2 > xController( i_rModel->createViewController(
+ i_rViewName,
+ i_rViewFactoryArgs.getPropertyValues(),
+ i_rFrame
+ ), UNO_SET_THROW );
+
+ // introduce model/view/controller to each other
+ xController->attachModel( i_rModel.get() );
+ i_rModel->connectController( xController.get() );
+ i_rFrame->setComponent( xController->getComponentWindow(), xController.get() );
+ xController->attachFrame( i_rFrame );
+ i_rModel->setCurrentController( xController.get() );
+
+ return xController;
+}
+
+// --------------------------------------------------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const Sequence< PropertyValue >& rArgs,
+ const Reference< XFrame >& _rTargetFrame )
+ throw( RuntimeException )
+{
+ ENSURE_OR_THROW( _rTargetFrame.is(), "illegal NULL frame" );
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxFrameLoader::load" );
+
+ ::comphelper::NamedValueCollection aDescriptor( rArgs );
+
+ // ensure the descriptor contains a referrer
+ if ( !aDescriptor.has( "Referer" ) )
+ aDescriptor.put( "Referer", ::rtl::OUString() );
+
+ // TODO: is this needed? finally, when loading is successfull, then there should be no need for this item,
+ // as the document can always obtain its frame. In particular, there might be situations where this frame
+ // is accessed, but already disposed: Imagine the user loading a document, opening a second view on it, and
+ // then closing the first view/frame.
+ aDescriptor.put( "Frame", _rTargetFrame );
+
+ // did the caller already pass a model?
+ Reference< XModel2 > xModel = aDescriptor.getOrDefault( "Model", Reference< XModel2 >() );
+ const bool bExternalModel = xModel.is();
+
+ // check for factory URLs to create a new doc, instead of loading one
+ const ::rtl::OUString sURL = aDescriptor.getOrDefault( "URL", ::rtl::OUString() );
+ const bool bIsFactoryURL = ( sURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "private:factory/" ) ) == 0 );
+ bool bInitNewModel = bIsFactoryURL;
+ if ( bIsFactoryURL && !bExternalModel )
+ {
+ const ::rtl::OUString sFactory = sURL.copy( sizeof( "private:factory/" ) -1 );
+ // special handling for some weird factory URLs a la private:factory/swriter?slot=21053
+ const USHORT nSlotParam = impl_findSlotParam( sFactory );
+ if ( nSlotParam != 0 )
+ {
+ return impl_createNewDocWithSlotParam( nSlotParam, _rTargetFrame, aDescriptor.getOrDefault( "Hidden", false ) );
+ }
+
+ const bool bDescribesValidTemplate = impl_determineTemplateDocument( aDescriptor );
+ if ( bDescribesValidTemplate )
+ {
+ // if the media descriptor allowed us to determine a template document to create the new document
+ // from, then do not init a new document model from scratch (below), but instead load the
+ // template document
+ bInitNewModel = false;
+ }
+ else
+ {
+ const ::rtl::OUString sServiceName = SfxObjectShell::GetServiceNameFromFactory( sFactory );
+ aDescriptor.put( "DocumentService", sServiceName );
+ }
+ }
+ else
+ {
+ // compatibility
+ aDescriptor.put( "FileName", aDescriptor.get( "URL" ) );
+ }
+
+ sal_Bool bLoadSuccess = sal_False;
+ try
+ {
+ // extract view releant arguments from the loader args
+ ::comphelper::NamedValueCollection aViewCreationArgs( impl_extractViewCreationArgs( aDescriptor ) );
+
+ // no model passed from outside? => create one from scratch
+ if ( !xModel.is() )
+ {
+ // beforehand, determine the filter to use, and update the descriptor with its information
+ if ( !bInitNewModel )
+ {
+ impl_determineFilter( aDescriptor );
+ }
+
+ // create the new doc
+ const ::rtl::OUString sServiceName = aDescriptor.getOrDefault( "DocumentService", ::rtl::OUString() );
+ xModel.set( m_aContext.createComponent( sServiceName ), UNO_QUERY_THROW );
+
+ // load resp. init it
+ const Reference< XLoadable > xLoadable( xModel, UNO_QUERY_THROW );
+ if ( bInitNewModel )
+ {
+ xLoadable->initNew();
+
+ impl_removeLoaderArguments( aDescriptor );
+ xModel->attachResource( ::rtl::OUString(), aDescriptor.getPropertyValues() );
+ }
+ else
+ {
+ xLoadable->load( aDescriptor.getPropertyValues() );
+ }
+ }
+ else
+ {
+ // tell the doc its (current) load args.
+ impl_removeLoaderArguments( aDescriptor );
+ xModel->attachResource( xModel->getURL(), aDescriptor.getPropertyValues() );
+ // TODO: not sure this is correct. The original, pre-refactoring code did it this way. However, I could
+ // imagine scenarios where it is *not* correct to overrule the *existing* model args (XModel::getArgs)
+ // with the ones passed to the loader here. For instance, what about the MacroExecutionMode? The document
+ // might have a mode other than the one passed to the loader, and we always overwrite the former with
+ // the latter.
+ }
+
+ // get the SfxObjectShell (still needed at the moment)
+ const SfxObjectShellLock xDoc = impl_findObjectShell( xModel );
+ ENSURE_OR_THROW( xDoc.Is(), "no SfxObjectShell for the given model" );
+
+ // ensure the ID of the to-be-created view is in the descriptor, if possible
+ const sal_Int16 nViewId = impl_determineEffectiveViewId_nothrow( *xDoc, aDescriptor );
+ const sal_Int16 nViewNo = xDoc->GetFactory().GetViewNo_Impl( nViewId, 0 );
+ const ::rtl::OUString sViewName( xDoc->GetFactory().GetViewFactory( nViewNo ).GetAPIViewName() );
+
+ // if the document is created hidden, prevent it from being deleted until it is shown or disposed
+ impl_lockHiddenDocument( *xDoc, aDescriptor );
+ // TODO; if we wouldn't use a SfxObjectShellLock instance for xDoc, but a simple SfxObjectShellRef,
+ // then this would not be necessary, /me thinks. That is, the *Lock classes inc/dec a "Lock" counter
+ // (additional to the ref counter) in their ctor/dtor, and if the lock counter goes to 0, the
+ // object is closed (DoClose). The impl_lockHiddenDocument is to prevent exactly that premature
+ // closing. However, a *Ref object wouldn't close, anyway. And in case of unsuccessfull loading, the
+ // code at the very end of this method cares for closing the XModel, which should also close the
+ // ObjectShell.
+
+ // plug the document into the frame
+ impl_createDocumentView( xModel, _rTargetFrame, aViewCreationArgs, sViewName );
+ bLoadSuccess = sal_True;
+ }
+ catch ( Exception& )
+ {
+ const Any aError( ::cppu::getCaughtException() );
+ if ( !aDescriptor.getOrDefault( "Silent", sal_False ) )
+ impl_handleCaughtError_nothrow( aError, aDescriptor );
+ }
+
+ // if loading was not successful, close the document
+ if ( !bLoadSuccess && !bExternalModel )
+ {
+ try
+ {
+ const Reference< XCloseable > xCloseable( xModel, UNO_QUERY_THROW );
+ xCloseable->close( sal_True );
+ }
+ catch ( Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+
+ return bLoadSuccess;
+}
+
+void SfxFrameLoader_Impl::cancel() throw( RuntimeException )
+{
+}
+
+SFX_IMPL_SINGLEFACTORY( SfxFrameLoader_Impl )
+
+/* XServiceInfo */
+UNOOUSTRING SAL_CALL SfxFrameLoader_Impl::getImplementationName() throw( RuntimeException )
+{
+ return impl_getStaticImplementationName();
+}
+ \
+/* XServiceInfo */
+sal_Bool SAL_CALL SfxFrameLoader_Impl::supportsService( const UNOOUSTRING& sServiceName ) throw( RuntimeException )
+{
+ UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames();
+ const UNOOUSTRING* pArray = seqServiceNames.getConstArray();
+ for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ )
+ {
+ if ( pArray[nCounter] == sServiceName )
+ {
+ return sal_True ;
+ }
+ }
+ return sal_False ;
+}
+
+/* XServiceInfo */
+UNOSEQUENCE< UNOOUSTRING > SAL_CALL SfxFrameLoader_Impl::getSupportedServiceNames() throw( RuntimeException )
+{
+ return impl_getStaticSupportedServiceNames();
+}
+
+/* Helper for XServiceInfo */
+UNOSEQUENCE< UNOOUSTRING > SfxFrameLoader_Impl::impl_getStaticSupportedServiceNames()
+{
+ UNOMUTEXGUARD aGuard( UNOMUTEX::getGlobalMutex() );
+ UNOSEQUENCE< UNOOUSTRING > seqServiceNames( 1 );
+ seqServiceNames.getArray() [0] = UNOOUSTRING::createFromAscii( "com.sun.star.frame.SynchronousFrameLoader" );
+ return seqServiceNames ;
+}
+
+/* Helper for XServiceInfo */
+UNOOUSTRING SfxFrameLoader_Impl::impl_getStaticImplementationName()
+{
+ return UNOOUSTRING::createFromAscii( "com.sun.star.comp.office.FrameLoader" );
+}
+
+/* Helper for registry */
+UNOREFERENCE< UNOXINTERFACE > SAL_CALL SfxFrameLoader_Impl::impl_createInstance( const UNOREFERENCE< UNOXMULTISERVICEFACTORY >& xServiceManager ) throw( UNOEXCEPTION )
+{
+ return UNOREFERENCE< UNOXINTERFACE >( *new SfxFrameLoader_Impl( xServiceManager ) );
+}
+
diff --git a/sfx2/source/view/impframe.hxx b/sfx2/source/view/impframe.hxx
new file mode 100644
index 000000000000..72f322036efb
--- /dev/null
+++ b/sfx2/source/view/impframe.hxx
@@ -0,0 +1,100 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SFX_IMPFRAME_HXX
+#define _SFX_IMPFRAME_HXX
+
+#include <sfx2/frame.hxx>
+#include <sfx2/viewfrm.hxx> // SvBorder
+
+class SfxViewFrame;
+class SfxObjectShell;
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/awt/XTopWindow.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/awt/PosSize.hpp>
+#include <cppuhelper/weak.hxx>
+
+#include <sfx2/viewsh.hxx>
+#include <sfx2/sfxuno.hxx>
+
+#ifndef FRAME_SEARCH_PARENT
+#define FRAME_SEARCH_PARENT 0x00000001
+#define FRAME_SEARCH_SELF 0x00000002
+#define FRAME_SEARCH_CHILDREN 0x00000004
+#define FRAME_SEARCH_CREATE 0x00000008
+#endif
+
+class SfxFrame_Impl : public SfxBroadcaster, public SvCompatWeakBase
+{
+public:
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame;
+ sal_uInt32 nType;
+ SfxViewFrame* pCurrentViewFrame;
+ SfxFrameDescriptor* pDescr;
+ sal_uInt16 nLocks;
+ sal_Bool bClosing : 1;
+ sal_Bool bPrepClosing : 1;
+ sal_Bool bInCancelTransfers : 1;
+ sal_Bool bOwnsBindings : 1;
+ sal_Bool bReleasingComponent : 1;
+ sal_Bool bInPlace : 1;
+ SfxFrame* pFrame;
+ SfxWorkWindow* pWorkWin;
+ SvBorder aBorder;
+ // formerly SfxTopFrame
+ Window* pExternalContainerWindow;
+ bool bHidden;
+ bool bLockResize;
+ bool bMenuBarOn;
+
+ SfxFrame_Impl( SfxFrame* pAntiImplP )
+ :SvCompatWeakBase( pAntiImplP )
+ ,nType( 0L )
+ ,pCurrentViewFrame( NULL )
+ ,pDescr( NULL )
+ ,nLocks( 0 )
+ ,bClosing(sal_False)
+ ,bPrepClosing(sal_False)
+ ,bInCancelTransfers( sal_False )
+ ,bOwnsBindings( sal_False )
+ ,bReleasingComponent( sal_False )
+ ,bInPlace( sal_False )
+ ,pFrame( pAntiImplP )
+ ,pWorkWin( 0 )
+ ,pExternalContainerWindow( NULL )
+ ,bHidden( false )
+ ,bLockResize( false )
+ ,bMenuBarOn( true )
+ {
+ }
+
+ virtual ~SfxFrame_Impl() { }
+};
+
+#endif
+
diff --git a/sfx2/source/view/impviewframe.hxx b/sfx2/source/view/impviewframe.hxx
new file mode 100644
index 000000000000..abe4cb6852d9
--- /dev/null
+++ b/sfx2/source/view/impviewframe.hxx
@@ -0,0 +1,98 @@
+/*************************************************************************
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2009 by Sun Microsystems, Inc.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
+
+#ifndef SFX2_IMPVIEWFRAME_HXX
+#define SFX2_IMPVIEWFRAME_HXX
+
+#include "sfx2/viewfrm.hxx"
+
+#include <svtools/asynclink.hxx>
+#include <vcl/window.hxx>
+
+#include <boost/optional.hpp>
+
+struct SfxViewFrame_Impl
+{
+ SvBorder aBorder;
+ Size aMargin;
+ Size aSize;
+ String aFrameTitle;
+ TypeId aLastType;
+ String aActualURL;
+ SfxFrame& rFrame;
+ svtools::AsynchronLink* pReloader;
+ Window* pWindow;
+ SfxViewFrame* pActiveChild;
+ Window* pFocusWin;
+ sal_uInt16 nDocViewNo;
+ sal_uInt16 nCurViewId;
+ sal_Bool bResizeInToOut:1;
+ sal_Bool bDontOverwriteResizeInToOut:1;
+ sal_Bool bObjLocked:1;
+ sal_Bool bReloading:1;
+ sal_Bool bIsDowning:1;
+ sal_Bool bModal:1;
+ sal_Bool bEnabled:1;
+ sal_Bool bWindowWasEnabled:1;
+ sal_Bool bActive;
+ String aFactoryName;
+ ::boost::optional< bool >
+ aHasToolPanels;
+
+ SfxViewFrame_Impl( SfxFrame& i_rFrame )
+ : rFrame( i_rFrame )
+ , pReloader(0 )
+ , pWindow( 0 )
+ , bWindowWasEnabled(sal_True)
+ , bActive( sal_False )
+ {
+ }
+
+ ~SfxViewFrame_Impl()
+ {
+ delete pReloader;
+ }
+};
+
+class SfxFrameViewWindow_Impl : public Window
+{
+ BOOL bActive;
+ SfxViewFrame* pFrame;
+
+public:
+ SfxFrameViewWindow_Impl( SfxViewFrame* p, Window& rParent, WinBits nBits=0 ) :
+ Window( &rParent, nBits | WB_BORDER | WB_CLIPCHILDREN ),
+ bActive( FALSE ),
+ pFrame( p )
+ {
+ p->GetFrame().GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
+ }
+
+ virtual void Resize();
+ virtual void StateChanged( StateChangedType nStateChange );
+};
+
+#endif // SFX2_IMPVIEWFRAME_HXX
+
diff --git a/sfx2/source/view/ipclient.cxx b/sfx2/source/view/ipclient.cxx
new file mode 100644
index 000000000000..997cb584f83d
--- /dev/null
+++ b/sfx2/source/view/ipclient.cxx
@@ -0,0 +1,1169 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/XVisualObject.hpp>
+#include <com/sun/star/embed/XEmbeddedClient.hpp>
+#include <com/sun/star/embed/XInplaceClient.hpp>
+#include <com/sun/star/embed/XInplaceObject.hpp>
+#include <com/sun/star/embed/XComponentSupplier.hpp>
+#include <com/sun/star/embed/XWindowSupplier.hpp>
+#include <com/sun/star/embed/XEmbedPersist.hpp>
+#include <com/sun/star/embed/EmbedVerbs.hpp>
+#include <com/sun/star/container/XChild.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/embed/XStateChangeListener.hpp>
+#include <com/sun/star/embed/StateChangeInProgressException.hpp>
+#include <com/sun/star/embed/XLinkageSupport.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
+#include <com/sun/star/task/XStatusIndicator.hpp>
+
+#include <com/sun/star/embed/EmbedMisc.hpp>
+#include <svtools/embedhlp.hxx>
+#include <vcl/svapp.hxx>
+
+#include <sfx2/ipclient.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/dispatch.hxx>
+#include "workwin.hxx"
+#include "guisaveas.hxx"
+#include <sfx2/viewfrm.hxx>
+#include <cppuhelper/implbase5.hxx>
+#include <vcl/salbtype.hxx>
+#include <svtools/ehdl.hxx>
+
+#include <vcl/timer.hxx>
+#include <vcl/window.hxx>
+#include <toolkit/awt/vclxwindow.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <toolkit/helper/convert.hxx>
+#include <tools/fract.hxx>
+#include <tools/gen.hxx>
+#include <svl/rectitem.hxx>
+#include <svtools/soerr.hxx>
+#include <comphelper/processfactory.hxx>
+
+#define SFX_CLIENTACTIVATE_TIMEOUT 100
+
+using namespace com::sun::star;
+
+//====================================================================
+// SfxEmbedResizeGuard
+class SfxBooleanFlagGuard
+{
+ sal_Bool& m_rFlag;
+ sal_Bool m_bLifeValue;
+public:
+ SfxBooleanFlagGuard( sal_Bool& bFlag, sal_Bool bLifeValue )
+ : m_rFlag( bFlag )
+ , m_bLifeValue( bLifeValue )
+ {
+ m_rFlag = m_bLifeValue;
+ }
+
+ ~SfxBooleanFlagGuard()
+ {
+ m_rFlag = !m_bLifeValue;
+ }
+};
+
+//====================================================================
+// SfxInPlaceClient_Impl
+
+//--------------------------------------------------------------------
+class SfxInPlaceClient_Impl : public ::cppu::WeakImplHelper5< embed::XEmbeddedClient,
+ embed::XInplaceClient,
+ document::XEventListener,
+ embed::XStateChangeListener,
+ embed::XWindowSupplier >
+{
+public:
+ Timer m_aTimer; // activation timeout, starts after object connection
+ Rectangle m_aObjArea; // area of object in coordinate system of the container (without scaling)
+ Fraction m_aScaleWidth; // scaling that was applied to the object when it was not active
+ Fraction m_aScaleHeight;
+ SfxInPlaceClient* m_pClient;
+ sal_Int64 m_nAspect; // ViewAspect that is assigned from the container
+ Rectangle m_aLastObjAreaPixel; // area of object in coordinate system of the container (without scaling)
+ sal_Bool m_bStoreObject;
+ sal_Bool m_bUIActive; // set and cleared when notification for UI (de)activation is sent
+ sal_Bool m_bResizeNoScale;
+
+ uno::Reference < embed::XEmbeddedObject > m_xObject;
+ uno::Reference < embed::XEmbeddedClient > m_xClient;
+
+
+ SfxInPlaceClient_Impl()
+ : m_pClient( NULL )
+ , m_nAspect( 0 )
+ , m_bStoreObject( sal_True )
+ , m_bUIActive( sal_False )
+ , m_bResizeNoScale( sal_False )
+ {}
+
+ ~SfxInPlaceClient_Impl();
+
+ void SizeHasChanged();
+ DECL_LINK (TimerHdl, Timer*);
+ uno::Reference < frame::XFrame > GetFrame() const;
+
+ // XEmbeddedClient
+ virtual void SAL_CALL saveObject() throw ( embed::ObjectSaveVetoException, uno::Exception, uno::RuntimeException );
+ virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) throw ( embed::WrongStateException, uno::RuntimeException );
+
+ // XInplaceClient
+ virtual sal_Bool SAL_CALL canInplaceActivate() throw ( uno::RuntimeException );
+ virtual void SAL_CALL activatingInplace() throw ( embed::WrongStateException, uno::RuntimeException );
+ virtual void SAL_CALL activatingUI() throw ( embed::WrongStateException, uno::RuntimeException );
+ virtual void SAL_CALL deactivatedInplace() throw ( embed::WrongStateException, uno::RuntimeException );
+ virtual void SAL_CALL deactivatedUI() throw ( embed::WrongStateException, uno::RuntimeException );
+ virtual uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL getLayoutManager() throw ( embed::WrongStateException, uno::RuntimeException );
+ virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() throw ( embed::WrongStateException, uno::RuntimeException );
+ virtual awt::Rectangle SAL_CALL getPlacement() throw ( embed::WrongStateException, uno::RuntimeException );
+ virtual awt::Rectangle SAL_CALL getClipRectangle() throw ( embed::WrongStateException, uno::RuntimeException );
+ virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) throw ( embed::WrongStateException, uno::RuntimeException );
+ virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) throw ( embed::WrongStateException, uno::RuntimeException );
+ virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) throw ( embed::WrongStateException, uno::Exception, uno::RuntimeException );
+
+ // XComponentSupplier
+ virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() throw ( uno::RuntimeException );
+
+ // XWindowSupplier
+ virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() throw ( uno::RuntimeException );
+
+ // document::XEventListener
+ virtual void SAL_CALL notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException );
+
+ // XStateChangeListener
+ virtual void SAL_CALL changingState( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL stateChanged( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
+};
+
+SfxInPlaceClient_Impl::~SfxInPlaceClient_Impl()
+{
+}
+
+void SAL_CALL SfxInPlaceClient_Impl::changingState(
+ const ::com::sun::star::lang::EventObject& /*aEvent*/,
+ ::sal_Int32 /*nOldState*/,
+ ::sal_Int32 /*nNewState*/ )
+throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException)
+{
+}
+
+void SAL_CALL SfxInPlaceClient_Impl::stateChanged(
+ const ::com::sun::star::lang::EventObject& /*aEvent*/,
+ ::sal_Int32 nOldState,
+ ::sal_Int32 nNewState )
+throw (::com::sun::star::uno::RuntimeException)
+{
+ if ( m_pClient && nOldState != embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
+ {
+ // deactivation of object
+ uno::Reference< frame::XModel > xDocument;
+ if ( m_pClient->GetViewShell()->GetObjectShell() )
+ xDocument = m_pClient->GetViewShell()->GetObjectShell()->GetModel();
+ SfxObjectShell::SetCurrentComponent( xDocument );
+ }
+ else if ( m_pClient && nNewState == embed::EmbedStates::UI_ACTIVE )
+ {
+/*
+ uno::Reference < lang::XUnoTunnel > xObj( m_xObject->getComponent(), uno::UNO_QUERY );
+ uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
+ sal_Int64 nHandle = xObj.is() ? xObj->getSomething( aSeq ) : 0;
+ if ( nHandle )
+ {
+ // currently needs SFX code
+ SfxObjectShell* pDoc = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
+ SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDoc );
+ SfxWorkWindow *pWorkWin = pFrame->GetFrame().GetWorkWindow_Impl();
+ pWorkWin->UpdateObjectBars_Impl();
+ }
+*/
+ }
+}
+
+void SAL_CALL SfxInPlaceClient_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ if ( m_pClient && aEvent.EventName.equalsAscii("OnVisAreaChanged") && m_nAspect != embed::Aspects::MSOLE_ICON )
+ {
+ m_pClient->FormatChanged(); // for Writer when format of the object is changed with the area
+ m_pClient->ViewChanged();
+ m_pClient->Invalidate();
+ }
+}
+
+void SAL_CALL SfxInPlaceClient_Impl::disposing( const ::com::sun::star::lang::EventObject& /*aEvent*/ )
+throw (::com::sun::star::uno::RuntimeException)
+{
+ DELETEZ( m_pClient );
+}
+
+// XEmbeddedClient
+//--------------------------------------------------------------------
+uno::Reference < frame::XFrame > SfxInPlaceClient_Impl::GetFrame() const
+{
+ if ( !m_pClient )
+ throw uno::RuntimeException();
+ return m_pClient->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
+}
+
+void SAL_CALL SfxInPlaceClient_Impl::saveObject()
+ throw ( embed::ObjectSaveVetoException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ if ( !m_bStoreObject )
+ // client wants to discard the object (usually it means the container document is closed while an object is active
+ // and the user didn't request saving the changes
+ return;
+
+ // the common persistance is supported by objects and links
+ uno::Reference< embed::XCommonEmbedPersist > xPersist( m_xObject, uno::UNO_QUERY );
+ if ( !xPersist.is() )
+ throw uno::RuntimeException();
+
+ uno::Reference< frame::XFrame > xFrame;
+ uno::Reference< task::XStatusIndicator > xStatusIndicator;
+ uno::Reference< frame::XModel > xModel( m_xObject->getComponent(), uno::UNO_QUERY );
+ uno::Reference< lang::XMultiServiceFactory > xSrvMgr( ::comphelper::getProcessServiceFactory() );
+
+ if ( xModel.is() )
+ {
+ uno::Reference< frame::XController > xController = xModel->getCurrentController();
+ if ( xController.is() )
+ xFrame = xController->getFrame();
+ }
+
+ if ( xSrvMgr.is() && xFrame.is() )
+ {
+ // set non-reschedule progress to prevent problems when asynchronous calls are made
+ // during storing of the embedded object
+ uno::Reference< lang::XInitialization > xInit(
+ xSrvMgr->createInstance(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.framework.StatusIndicatorFactory" ))),
+ uno::UNO_QUERY_THROW );
+ beans::PropertyValue aProperty;
+ uno::Sequence< uno::Any > aArgs( 2 );
+ aProperty.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableReschedule" ));
+ aProperty.Value = uno::makeAny( sal_True );
+ aArgs[0] = uno::makeAny( aProperty );
+ aProperty.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
+ aProperty.Value = uno::makeAny( xFrame );
+ aArgs[1] = uno::makeAny( aProperty );
+
+ xInit->initialize( aArgs );
+
+ uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ uno::Reference< task::XStatusIndicatorFactory > xStatusIndicatorFactory( xInit, uno::UNO_QUERY_THROW );
+ xStatusIndicator = xStatusIndicatorFactory->createStatusIndicator();
+ xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IndicatorInterception" )), uno::makeAny( xStatusIndicator ));
+ }
+ catch ( uno::RuntimeException& e )
+ {
+ throw e;
+ }
+ catch ( uno::Exception& )
+ {
+ }
+ }
+ }
+
+ try
+ {
+ xPersist->storeOwn();
+ m_xObject->update();
+ }
+ catch ( uno::Exception& )
+ {
+ //TODO/LATER: what should happen if object can't be saved?!
+ }
+
+ // reset status indicator interception after storing
+ try
+ {
+ uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
+ if ( xPropSet.is() )
+ {
+ xStatusIndicator.clear();
+ xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IndicatorInterception" )), uno::makeAny( xStatusIndicator ));
+ }
+ }
+ catch ( uno::RuntimeException& e )
+ {
+ throw e;
+ }
+ catch ( uno::Exception& )
+ {
+ }
+
+ // the client can exist only in case there is a view shell
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ SfxObjectShell* pDocShell = m_pClient->GetViewShell()->GetObjectShell();
+ if ( !pDocShell )
+ throw uno::RuntimeException();
+
+ pDocShell->SetModified( sal_True );
+
+ //TODO/LATER: invalidation might be necessary when object was modified, but is not
+ //saved through this method
+ // m_pClient->Invalidate();
+}
+
+//--------------------------------------------------------------------
+void SAL_CALL SfxInPlaceClient_Impl::visibilityChanged( sal_Bool bVisible )
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ m_pClient->GetViewShell()->OutplaceActivated( bVisible, m_pClient );
+ m_pClient->Invalidate();
+}
+
+
+// XInplaceClient
+//--------------------------------------------------------------------
+sal_Bool SAL_CALL SfxInPlaceClient_Impl::canInplaceActivate()
+ throw ( uno::RuntimeException )
+{
+ if ( !m_xObject.is() )
+ throw uno::RuntimeException();
+
+ // we don't want to switch directly from outplace to inplace mode
+ if ( m_xObject->getCurrentState() == embed::EmbedStates::ACTIVE || m_nAspect == embed::Aspects::MSOLE_ICON )
+ return sal_False;
+
+ return sal_True;
+}
+
+//--------------------------------------------------------------------
+void SAL_CALL SfxInPlaceClient_Impl::activatingInplace()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ m_pClient->GetViewShell()->InplaceActivating( m_pClient );
+}
+
+//--------------------------------------------------------------------
+void SAL_CALL SfxInPlaceClient_Impl::activatingUI()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ m_pClient->GetViewShell()->ResetAllClients_Impl(m_pClient);
+ m_bUIActive = TRUE;
+ m_pClient->GetViewShell()->UIActivating( m_pClient );
+}
+
+//--------------------------------------------------------------------
+void SAL_CALL SfxInPlaceClient_Impl::deactivatedInplace()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ m_pClient->GetViewShell()->InplaceDeactivated( m_pClient );
+}
+
+//--------------------------------------------------------------------
+void SAL_CALL SfxInPlaceClient_Impl::deactivatedUI()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ m_pClient->GetViewShell()->UIDeactivated( m_pClient );
+ m_bUIActive = FALSE;
+}
+
+//--------------------------------------------------------------------
+uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL SfxInPlaceClient_Impl::getLayoutManager()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ uno::Reference < beans::XPropertySet > xFrame( GetFrame(), uno::UNO_QUERY );
+ if ( !xFrame.is() )
+ throw uno::RuntimeException();
+
+ uno::Reference< ::com::sun::star::frame::XLayoutManager > xMan;
+ try
+ {
+ uno::Any aAny = xFrame->getPropertyValue( ::rtl::OUString::createFromAscii("LayoutManager") );
+ aAny >>= xMan;
+ }
+ catch ( uno::Exception& )
+ {
+ throw uno::RuntimeException();
+ }
+
+ return xMan;
+}
+
+//--------------------------------------------------------------------
+uno::Reference< frame::XDispatchProvider > SAL_CALL SfxInPlaceClient_Impl::getInplaceDispatchProvider()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ return uno::Reference < frame::XDispatchProvider >( GetFrame(), uno::UNO_QUERY_THROW );
+}
+
+//--------------------------------------------------------------------
+awt::Rectangle SAL_CALL SfxInPlaceClient_Impl::getPlacement()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ // apply scaling to object area and convert to pixels
+ Rectangle aRealObjArea( m_aObjArea );
+ aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_aScaleWidth,
+ Fraction( aRealObjArea.GetHeight() ) * m_aScaleHeight ) );
+
+ aRealObjArea = m_pClient->GetEditWin()->LogicToPixel( aRealObjArea );
+ return AWTRectangle( aRealObjArea );
+}
+
+//--------------------------------------------------------------------
+awt::Rectangle SAL_CALL SfxInPlaceClient_Impl::getClipRectangle()
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ // currently(?) same as placement
+ Rectangle aRealObjArea( m_aObjArea );
+ aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_aScaleWidth,
+ Fraction( aRealObjArea.GetHeight() ) * m_aScaleHeight ) );
+
+ aRealObjArea = m_pClient->GetEditWin()->LogicToPixel( aRealObjArea );
+ return AWTRectangle( aRealObjArea );
+}
+
+//--------------------------------------------------------------------
+void SAL_CALL SfxInPlaceClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ // TODO/MBA: keyboard accelerators
+}
+
+//--------------------------------------------------------------------
+void SAL_CALL SfxInPlaceClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
+ throw ( embed::WrongStateException,
+ uno::RuntimeException )
+{
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+}
+
+//--------------------------------------------------------------------
+void SAL_CALL SfxInPlaceClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
+ throw ( embed::WrongStateException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ uno::Reference< embed::XInplaceObject > xInplace( m_xObject, uno::UNO_QUERY );
+ if ( !xInplace.is() || !m_pClient || !m_pClient->GetEditWin() || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ // check if the change is at least one pixel in size
+ awt::Rectangle aOldRect = getPlacement();
+ Rectangle aNewPixelRect = VCLRectangle( aPosRect );
+ Rectangle aOldPixelRect = VCLRectangle( aOldRect );
+ if ( aOldPixelRect == aNewPixelRect )
+ // nothing has changed
+ return;
+
+ // new scaled object area
+ Rectangle aNewLogicRect = m_pClient->GetEditWin()->PixelToLogic( aNewPixelRect );
+
+ // all the size changes in this method should happen without scaling
+ // SfxBooleanFlagGuard aGuard( m_bResizeNoScale, sal_True );
+
+ // allow container to apply restrictions on the requested new area;
+ // the container might change the object view during size calculation;
+ // currently only writer does it
+ m_pClient->RequestNewObjectArea( aNewLogicRect);
+
+ if ( aNewLogicRect != m_pClient->GetScaledObjArea() )
+ {
+ // the calculation of the object area has not changed the object size
+ // it should be done here then
+ SfxBooleanFlagGuard aGuard( m_bResizeNoScale, sal_True );
+
+ // new size of the object area without scaling
+ Size aNewObjSize( Fraction( aNewLogicRect.GetWidth() ) / m_aScaleWidth,
+ Fraction( aNewLogicRect.GetHeight() ) / m_aScaleHeight );
+
+ // now remove scaling from new placement and keep this a the new object area
+ aNewLogicRect.SetSize( aNewObjSize );
+ m_aObjArea = aNewLogicRect;
+
+ // let the window size be recalculated
+ SizeHasChanged();
+ }
+
+ // notify container view about changes
+ m_pClient->ObjectAreaChanged();
+}
+
+// XComponentSupplier
+//--------------------------------------------------------------------
+uno::Reference< util::XCloseable > SAL_CALL SfxInPlaceClient_Impl::getComponent()
+ throw ( uno::RuntimeException )
+{
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ SfxObjectShell* pDocShell = m_pClient->GetViewShell()->GetObjectShell();
+ if ( !pDocShell )
+ throw uno::RuntimeException();
+
+ // all the components must implement XCloseable
+ uno::Reference< util::XCloseable > xComp( pDocShell->GetModel(), uno::UNO_QUERY );
+ if ( !xComp.is() )
+ throw uno::RuntimeException();
+
+ return xComp;
+}
+
+
+// XWindowSupplier
+//--------------------------------------------------------------------
+uno::Reference< awt::XWindow > SAL_CALL SfxInPlaceClient_Impl::getWindow()
+ throw ( uno::RuntimeException )
+{
+ if ( !m_pClient || !m_pClient->GetEditWin() )
+ throw uno::RuntimeException();
+
+ uno::Reference< awt::XWindow > xWin( m_pClient->GetEditWin()->GetComponentInterface(), uno::UNO_QUERY );
+ return xWin;
+}
+
+//--------------------------------------------------------------------
+// notification to the client implementation that either the object area or the scaling has been changed
+// as a result the logical size of the window has changed also
+void SfxInPlaceClient_Impl::SizeHasChanged()
+{
+ if ( !m_pClient || !m_pClient->GetViewShell() )
+ throw uno::RuntimeException();
+
+ try {
+ if ( m_xObject.is()
+ && ( m_xObject->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
+ || m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE ) )
+ {
+ // only possible in active states
+ uno::Reference< embed::XInplaceObject > xInplace( m_xObject, uno::UNO_QUERY );
+ if ( !xInplace.is() )
+ throw uno::RuntimeException();
+
+ if ( m_bResizeNoScale )
+ {
+ // the resizing should be done without scaling
+ // set the correct size to the object to avoid the scaling
+ MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( m_xObject->getMapUnit( m_nAspect ) ) );
+ MapMode aClientMap( m_pClient->GetEditWin()->GetMapMode().GetMapUnit() );
+
+ // convert to logical coordinates of the embedded object
+ Size aNewSize = m_pClient->GetEditWin()->LogicToLogic( m_aObjArea.GetSize(), &aClientMap, &aObjectMap );
+ m_xObject->setVisualAreaSize( m_nAspect, awt::Size( aNewSize.Width(), aNewSize.Height() ) );
+ }
+
+ xInplace->setObjectRectangles( getPlacement(), getClipRectangle() );
+ }
+ }
+ catch( uno::Exception& )
+ {
+ // TODO/LATER: handle error
+ }
+}
+
+//--------------------------------------------------------------------
+IMPL_LINK( SfxInPlaceClient_Impl, TimerHdl, Timer*, EMPTYARG )
+{
+ if ( m_pClient && m_xObject.is() )
+ m_pClient->GetViewShell()->CheckIPClient_Impl( m_pClient, m_pClient->GetViewShell()->GetObjectShell()->GetVisArea() );
+ return 0;
+}
+
+
+//====================================================================
+// SfxInPlaceClient
+
+//--------------------------------------------------------------------
+SfxInPlaceClient::SfxInPlaceClient( SfxViewShell* pViewShell, Window *pDraw, sal_Int64 nAspect ) :
+ m_pImp( new SfxInPlaceClient_Impl ),
+ m_pViewSh( pViewShell ),
+ m_pEditWin( pDraw )
+{
+ m_pImp->acquire();
+ m_pImp->m_pClient = this;
+ m_pImp->m_nAspect = nAspect;
+ m_pImp->m_aScaleWidth = m_pImp->m_aScaleHeight = Fraction(1,1);
+ m_pImp->m_xClient = static_cast< embed::XEmbeddedClient* >( m_pImp );
+ pViewShell->NewIPClient_Impl(this);
+ m_pImp->m_aTimer.SetTimeout( SFX_CLIENTACTIVATE_TIMEOUT );
+ m_pImp->m_aTimer.SetTimeoutHdl( LINK( m_pImp, SfxInPlaceClient_Impl, TimerHdl ) );
+}
+
+//--------------------------------------------------------------------
+
+SfxInPlaceClient::~SfxInPlaceClient()
+{
+ m_pViewSh->IPClientGone_Impl(this);
+
+ // deleting the client before storing the object means discarding all changes
+ m_pImp->m_bStoreObject = sal_False;
+ SetObject(0);
+
+ m_pImp->m_pClient = NULL;
+
+ // the next call will destroy m_pImp if no other reference to it exists
+ m_pImp->m_xClient = uno::Reference < embed::XEmbeddedClient >();
+ m_pImp->release();
+
+ // TODO/LATER:
+ // the class is not intended to be used in multithreaded environment;
+ // if it will this disconnection and all the parts that use the m_pClient
+ // must be guarded with mutex
+}
+
+//--------------------------------------------------------------------
+void SfxInPlaceClient::SetObjectState( sal_Int32 nState )
+{
+ if ( GetObject().is() )
+ {
+ if ( m_pImp->m_nAspect == embed::Aspects::MSOLE_ICON
+ && ( nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::INPLACE_ACTIVE ) )
+ {
+ OSL_ENSURE( sal_False, "Iconified object should not be activated inplace!\n" );
+ return;
+ }
+
+ try
+ {
+ GetObject()->changeState( nState );
+ }
+ catch ( uno::Exception& )
+ {}
+ }
+}
+
+//--------------------------------------------------------------------
+sal_Int64 SfxInPlaceClient::GetObjectMiscStatus() const
+{
+ if ( GetObject().is() )
+ return GetObject()->getStatus( m_pImp->m_nAspect );
+ return 0;
+}
+
+//--------------------------------------------------------------------
+uno::Reference < embed::XEmbeddedObject > SfxInPlaceClient::GetObject() const
+{
+ return m_pImp->m_xObject;
+}
+
+//--------------------------------------------------------------------
+void SfxInPlaceClient::SetObject( const uno::Reference < embed::XEmbeddedObject >& rObject )
+{
+ if ( m_pImp->m_xObject.is() && rObject != m_pImp->m_xObject )
+ {
+ DBG_ASSERT( GetObject()->getClientSite() == m_pImp->m_xClient, "Wrong ClientSite!" );
+ if ( GetObject()->getClientSite() == m_pImp->m_xClient )
+ {
+ if ( GetObject()->getCurrentState() != embed::EmbedStates::LOADED )
+ SetObjectState( embed::EmbedStates::RUNNING );
+ m_pImp->m_xObject->removeEventListener( uno::Reference < document::XEventListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
+ m_pImp->m_xObject->removeStateChangeListener( uno::Reference < embed::XStateChangeListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
+ try
+ {
+ m_pImp->m_xObject->setClientSite( 0 );
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Can not clean the client site!\n" );
+ }
+ }
+ }
+
+ if ( !m_pViewSh || m_pViewSh->GetViewFrame()->GetFrame().IsClosing_Impl() )
+ // sometimes applications reconnect clients on shutting down because it happens in their Paint methods
+ return;
+
+ m_pImp->m_xObject = rObject;
+
+ if ( rObject.is() )
+ {
+ // as soon as an object was connected to a client it has to be checked wether the object wants
+ // to be activated
+ rObject->addStateChangeListener( uno::Reference < embed::XStateChangeListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
+ rObject->addEventListener( uno::Reference < document::XEventListener >( m_pImp->m_xClient, uno::UNO_QUERY ) );
+
+ try
+ {
+ rObject->setClientSite( m_pImp->m_xClient );
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ENSURE( sal_False, "Can not set the client site!\n" );
+ }
+
+ m_pImp->m_aTimer.Start();
+ }
+ else
+ m_pImp->m_aTimer.Stop();
+}
+
+//--------------------------------------------------------------------
+BOOL SfxInPlaceClient::SetObjArea( const Rectangle& rArea )
+{
+ if( rArea != m_pImp->m_aObjArea )
+ {
+ m_pImp->m_aObjArea = rArea;
+ m_pImp->SizeHasChanged();
+
+ Invalidate();
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+//--------------------------------------------------------------------
+Rectangle SfxInPlaceClient::GetObjArea() const
+{
+ return m_pImp->m_aObjArea;
+}
+
+Rectangle SfxInPlaceClient::GetScaledObjArea() const
+{
+ Rectangle aRealObjArea( m_pImp->m_aObjArea );
+ aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_pImp->m_aScaleWidth,
+ Fraction( aRealObjArea.GetHeight() ) * m_pImp->m_aScaleHeight ) );
+ return aRealObjArea;
+}
+
+//--------------------------------------------------------------------
+void SfxInPlaceClient::SetSizeScale( const Fraction & rScaleWidth, const Fraction & rScaleHeight )
+{
+ if ( m_pImp->m_aScaleWidth != rScaleWidth || m_pImp->m_aScaleHeight != rScaleHeight )
+ {
+ m_pImp->m_aScaleWidth = rScaleWidth;
+ m_pImp->m_aScaleHeight = rScaleHeight;
+
+ m_pImp->SizeHasChanged();
+
+ // TODO/LATER: Invalidate seems to trigger (wrong) recalculations of the ObjArea, so it's better
+ // not to call it here, but maybe it sounds reasonable to do so.
+ //Invalidate();
+ }
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxInPlaceClient::SetObjAreaAndScale( const Rectangle& rArea, const Fraction& rScaleWidth, const Fraction& rScaleHeight )
+{
+ if( rArea != m_pImp->m_aObjArea || m_pImp->m_aScaleWidth != rScaleWidth || m_pImp->m_aScaleHeight != rScaleHeight )
+ {
+ m_pImp->m_aObjArea = rArea;
+ m_pImp->m_aScaleWidth = rScaleWidth;
+ m_pImp->m_aScaleHeight = rScaleHeight;
+
+ m_pImp->SizeHasChanged();
+
+ Invalidate();
+ return sal_True;
+ }
+
+ return sal_False;
+}
+
+//--------------------------------------------------------------------
+const Fraction& SfxInPlaceClient::GetScaleWidth() const
+{
+ return m_pImp->m_aScaleWidth;
+}
+
+//--------------------------------------------------------------------
+const Fraction& SfxInPlaceClient::GetScaleHeight() const
+{
+ return m_pImp->m_aScaleHeight;
+}
+
+//--------------------------------------------------------------------
+void SfxInPlaceClient::Invalidate()
+{
+ // TODO/LATER: do we need both?
+
+ // the object area is provided in logical coordinates of the window but without scaling applied
+ Rectangle aRealObjArea( m_pImp->m_aObjArea );
+ aRealObjArea.SetSize( Size( Fraction( aRealObjArea.GetWidth() ) * m_pImp->m_aScaleWidth,
+ Fraction( aRealObjArea.GetHeight() ) * m_pImp->m_aScaleHeight ) );
+ m_pEditWin->Invalidate( aRealObjArea );
+
+ ViewChanged();
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxInPlaceClient::IsObjectUIActive() const
+{
+ try {
+ return ( m_pImp->m_xObject.is() && ( m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE ) );
+ }
+ catch( uno::Exception& )
+ {}
+
+ return sal_False;
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxInPlaceClient::IsObjectInPlaceActive() const
+{
+ try {
+ return(
+ (
+ m_pImp->m_xObject.is() &&
+ (m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE)
+ ) ||
+ (
+ m_pImp->m_xObject.is() &&
+ (m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE)
+ )
+ );
+ }
+ catch( uno::Exception& )
+ {}
+
+ return sal_False;
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxInPlaceClient::IsObjectActive() const
+{
+ try {
+ return ( m_pImp->m_xObject.is() && ( m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::ACTIVE ) );
+ }
+ catch( uno::Exception& )
+ {}
+
+ return sal_False;
+}
+
+//--------------------------------------------------------------------
+Window* SfxInPlaceClient::GetActiveWindow( SfxObjectShell* pDoc, const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& xObject )
+{
+ SfxInPlaceClient* pClient = GetClient( pDoc, xObject );
+ if ( pClient )
+ return pClient->GetEditWin();
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+SfxInPlaceClient* SfxInPlaceClient::GetClient( SfxObjectShell* pDoc, const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& xObject )
+{
+ for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(pDoc); pFrame; pFrame=SfxViewFrame::GetNext(*pFrame,pDoc) )
+ {
+ if( pFrame->GetViewShell() )
+ {
+ SfxInPlaceClient* pClient = pFrame->GetViewShell()->FindIPClient( xObject, NULL );
+ if ( pClient )
+ return pClient;
+ }
+ }
+
+ return NULL;
+}
+
+sal_Int64 SfxInPlaceClient::GetAspect() const
+{
+ return m_pImp->m_nAspect;
+}
+
+ErrCode SfxInPlaceClient::DoVerb( long nVerb )
+{
+ SfxErrorContext aEc( ERRCTX_SO_DOVERB, m_pViewSh->GetWindow(), RID_SO_ERRCTX );
+ ErrCode nError = ERRCODE_NONE;
+
+ if ( m_pImp->m_xObject.is() )
+ {
+ sal_Bool bSaveCopyAs = sal_False;
+ if ( nVerb == -8 ) // "Save Copy as..."
+ {
+ svt::EmbeddedObjectRef::TryRunningState( m_pImp->m_xObject );
+ // TODO/LATER: this special verb should disappear when outplace activation is completely available
+ uno::Reference< frame::XModel > xEmbModel( m_pImp->m_xObject->getComponent(), uno::UNO_QUERY );
+ if ( xEmbModel.is() )
+ {
+ bSaveCopyAs = sal_True;
+
+ try
+ {
+ uno::Reference< lang::XMultiServiceFactory > xEmptyFactory;
+ SfxStoringHelper aHelper( xEmptyFactory );
+ uno::Sequence< beans::PropertyValue > aDispatchArgs( 1 );
+ aDispatchArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SaveTo" ) );
+ aDispatchArgs[0].Value <<= (sal_Bool)sal_True;
+
+ aHelper.GUIStoreModel( xEmbModel,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SaveAs" ) ),
+ aDispatchArgs,
+ sal_False,
+ ::rtl::OUString() );
+ }
+ catch( task::ErrorCodeIOException& aErrorEx )
+ {
+ nError = (sal_uInt32)aErrorEx.ErrCode;
+ }
+ catch( uno::Exception& )
+ {
+ nError = ERRCODE_IO_GENERAL;
+ // TODO/LATER: better error handling
+ }
+ }
+ }
+
+ if ( !bSaveCopyAs )
+ {
+ if ( m_pImp->m_nAspect == embed::Aspects::MSOLE_ICON )
+ {
+ if ( nVerb == embed::EmbedVerbs::MS_OLEVERB_PRIMARY || nVerb == embed::EmbedVerbs::MS_OLEVERB_SHOW )
+ nVerb = embed::EmbedVerbs::MS_OLEVERB_OPEN; // outplace activation
+ else if ( nVerb == embed::EmbedVerbs::MS_OLEVERB_UIACTIVATE
+ || nVerb == embed::EmbedVerbs::MS_OLEVERB_IPACTIVATE )
+ nError = ERRCODE_SO_GENERALERROR;
+ }
+
+ if ( !nError )
+ {
+
+ if ( m_pViewSh )
+ m_pViewSh->GetViewFrame()->GetTopFrame().LockResize_Impl(TRUE);
+ try
+ {
+ m_pImp->m_xObject->setClientSite( m_pImp->m_xClient );
+
+ m_pImp->m_xObject->doVerb( nVerb );
+ }
+ catch ( embed::UnreachableStateException& )
+ {
+ if ( nVerb == 0 || nVerb == embed::EmbedVerbs::MS_OLEVERB_OPEN )
+ {
+ // a workaround for the default verb, usually makes sence for alien objects
+ try
+ {
+ m_pImp->m_xObject->doVerb( -9 ); // open own view, a workaround verb that is not visible
+
+ if ( m_pImp->m_xObject->getCurrentState() == embed::EmbedStates::UI_ACTIVE )
+ {
+ // the object was converted to OOo object
+ awt::Size aSize = m_pImp->m_xObject->getVisualAreaSize( m_pImp->m_nAspect );
+ MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( m_pImp->m_xObject->getMapUnit( m_pImp->m_nAspect ) ) );
+ MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
+ Size aNewSize = GetEditWin()->LogicToLogic( Size( aSize.Width, aSize.Height ), &aObjectMap, &aClientMap );
+
+ Rectangle aScaledArea = GetScaledObjArea();
+ m_pImp->m_aObjArea.SetSize( aNewSize );
+ m_pImp->m_aScaleWidth = Fraction( aScaledArea.GetWidth(), aNewSize.Width() );
+ m_pImp->m_aScaleHeight = Fraction( aScaledArea.GetHeight(), aNewSize.Height() );
+ }
+ }
+ catch ( uno::Exception& )
+ {
+ nError = ERRCODE_SO_GENERALERROR;
+ }
+ }
+ }
+ catch ( embed::StateChangeInProgressException& )
+ {
+ // TODO/LATER: it would be nice to be able to provide the current target state outside
+ nError = ERRCODE_SO_CANNOT_DOVERB_NOW;
+ }
+ catch ( uno::Exception& )
+ {
+ nError = ERRCODE_SO_GENERALERROR;
+ //TODO/LATER: better error handling
+ }
+
+ if ( m_pViewSh )
+ {
+ SfxViewFrame* pFrame = m_pViewSh->GetViewFrame();
+ pFrame->GetTopFrame().LockResize_Impl(FALSE);
+ pFrame->GetTopFrame().Resize();
+ }
+ }
+ }
+ }
+
+ if( nError )
+ ErrorHandler::HandleError( nError );
+
+ return nError;
+}
+
+void SfxInPlaceClient::VisAreaChanged()
+{
+ uno::Reference < embed::XInplaceObject > xObj( m_pImp->m_xObject, uno::UNO_QUERY );
+ uno::Reference < embed::XInplaceClient > xClient( m_pImp->m_xClient, uno::UNO_QUERY );
+ if ( xObj.is() && xClient.is() )
+ m_pImp->SizeHasChanged();
+}
+
+void SfxInPlaceClient::ObjectAreaChanged()
+{
+ // dummy implementation
+}
+
+void SfxInPlaceClient::RequestNewObjectArea( Rectangle& )
+{
+ // dummy implementation
+}
+
+void SfxInPlaceClient::ViewChanged()
+{
+ // dummy implementation
+}
+
+void SfxInPlaceClient::MakeVisible()
+{
+ // dummy implementation
+}
+
+void SfxInPlaceClient::FormatChanged()
+{
+ // dummy implementation
+}
+
+void SfxInPlaceClient::DeactivateObject()
+{
+ if ( GetObject().is() )
+ {
+ try
+ {
+ m_pImp->m_bUIActive = FALSE;
+ BOOL bHasFocus = FALSE;
+ uno::Reference< frame::XModel > xModel( m_pImp->m_xObject->getComponent(), uno::UNO_QUERY );
+ if ( xModel.is() )
+ {
+ uno::Reference< frame::XController > xController = xModel->getCurrentController();
+ if ( xController.is() )
+ {
+ Window* pWindow = VCLUnoHelper::GetWindow( xController->getFrame()->getContainerWindow() );
+ bHasFocus = pWindow->HasChildPathFocus( TRUE );
+ }
+ }
+
+ if ( m_pViewSh )
+ m_pViewSh->GetViewFrame()->GetTopFrame().LockResize_Impl(TRUE);
+
+ if ( m_pImp->m_xObject->getStatus( m_pImp->m_nAspect ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
+ {
+ m_pImp->m_xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
+ if ( bHasFocus && m_pViewSh )
+ m_pViewSh->GetWindow()->GrabFocus();
+ }
+ else
+ {
+ // the links should not stay in running state for long time because of locking
+ uno::Reference< embed::XLinkageSupport > xLink( m_pImp->m_xObject, uno::UNO_QUERY );
+ if ( xLink.is() && xLink->isLink() )
+ m_pImp->m_xObject->changeState( embed::EmbedStates::LOADED );
+ else
+ m_pImp->m_xObject->changeState( embed::EmbedStates::RUNNING );
+ }
+
+ if ( m_pViewSh )
+ {
+ SfxViewFrame* pFrame = m_pViewSh->GetViewFrame();
+ SfxViewFrame::SetViewFrame( pFrame );
+ pFrame->GetTopFrame().LockResize_Impl(FALSE);
+ pFrame->GetTopFrame().Resize();
+ }
+ }
+ catch (com::sun::star::uno::Exception& )
+ {}
+ }
+}
+
+void SfxInPlaceClient::ResetObject()
+{
+ if ( GetObject().is() )
+ {
+ try
+ {
+ m_pImp->m_bUIActive = FALSE;
+ if ( m_pImp->m_xObject->getStatus( m_pImp->m_nAspect ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
+ m_pImp->m_xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
+ else
+ {
+ // the links should not stay in running state for long time because of locking
+ uno::Reference< embed::XLinkageSupport > xLink( m_pImp->m_xObject, uno::UNO_QUERY );
+ if ( xLink.is() && xLink->isLink() )
+ m_pImp->m_xObject->changeState( embed::EmbedStates::LOADED );
+ else
+ m_pImp->m_xObject->changeState( embed::EmbedStates::RUNNING );
+ }
+ }
+ catch (com::sun::star::uno::Exception& )
+ {}
+ }
+}
+
+BOOL SfxInPlaceClient::IsUIActive()
+{
+ return m_pImp->m_bUIActive;
+}
diff --git a/sfx2/source/view/orgmgr.cxx b/sfx2/source/view/orgmgr.cxx
new file mode 100644
index 000000000000..6c92cd448adf
--- /dev/null
+++ b/sfx2/source/view/orgmgr.cxx
@@ -0,0 +1,832 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
+#include <tools/urlobj.hxx>
+#ifndef GCC
+#endif
+
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+#include <unotools/intlwrapper.hxx>
+
+#include <comphelper/storagehelper.hxx>
+
+#include <sfx2/app.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/doctempl.hxx>
+#include "docvor.hxx"
+#include "orgmgr.hxx"
+#include "sfxtypes.hxx"
+#include "sfx2/sfxresid.hxx"
+#include "view.hrc"
+#include <sfx2/docfilt.hxx>
+#include "fltfnc.hxx"
+
+using namespace ::com::sun::star;
+
+//=========================================================================
+
+/* [Beschreibung]
+
+ Implementierungsklasse; einzelner Eintrag in der Dateiansicht
+
+*/
+
+struct _FileListEntry
+{
+ String aFileName; // Dateiname mit komplettem Pfad
+ String aBaseName; // Dateiname
+ const CollatorWrapper* pCollator;
+ SfxObjectShellLock aDocShell; // ObjectShell als Ref-Klasse
+
+//REMOVE SvStorageRef aStor; // Referenz auf Storage, wenn wir diesen geoeffnet haben
+ //uno::Reference< embed::XStorage > xStorage;
+
+ BOOL bFile; // als Datei auf Platte
+ // (!= unbenannt1, nicht als Dok. geladen;
+ // diese werden nicht gespeichert!)
+ BOOL bOwner; // selbst erzeugt
+ BOOL bNoName;
+ BOOL bOwnFormat;
+
+ _FileListEntry( const String& rFileName,
+ const CollatorWrapper* pColl, const String* pTitle = NULL );
+ ~_FileListEntry();
+
+ int operator==( const _FileListEntry &rCmp) const;
+ int operator< ( const _FileListEntry &rCmp) const;
+ BOOL DeleteObjectShell();
+};
+
+//-------------------------------------------------------------------------
+
+inline int _FileListEntry::operator==(const _FileListEntry &rCmp) const
+{
+ DBG_ASSERT( pCollator, "invalid CollatorWrapper" );
+ return COMPARE_EQUAL == pCollator->compareString(aBaseName, rCmp.aBaseName);
+}
+
+//-------------------------------------------------------------------------
+
+inline int _FileListEntry::operator< (const _FileListEntry &rCmp) const
+{
+ DBG_ASSERT( pCollator, "invalid CollatorWrapper" );
+ return COMPARE_LESS == pCollator->compareString(aBaseName, rCmp.aBaseName);
+}
+
+//-------------------------------------------------------------------------
+
+_FileListEntry::_FileListEntry( const String& rFileName,
+ const CollatorWrapper* pColl, const String* pTitle ) :
+
+ aFileName ( rFileName ),
+ pCollator ( pColl ),
+ bFile ( FALSE ),
+ bOwner ( FALSE ),
+ bNoName ( TRUE ),
+ bOwnFormat ( TRUE )
+{
+ if ( pTitle )
+ aBaseName = *pTitle;
+ else
+ {
+ INetURLObject aObj( rFileName, INET_PROT_FILE );
+ aBaseName = aObj.getName( INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+_FileListEntry::~_FileListEntry()
+{
+ DeleteObjectShell();
+}
+
+//-------------------------------------------------------------------------
+
+SV_IMPL_OP_PTRARR_SORT(_SfxObjectList, _FileListEntry*)
+
+//=========================================================================
+
+BOOL _FileListEntry::DeleteObjectShell()
+
+/* [Beschreibung]
+
+ Freigabe der DokumentShell
+
+ [Returnwert] TRUE: alles Ok
+ FALSE: es ist ein Fehler aufgetreten (das
+ Dokument konnte nicht gesichert werden)
+
+*/
+
+{
+ BOOL bRet = TRUE;
+ //Falls wir die Shell angelegt haben und sie veraendert wurde
+ if(bOwner && aDocShell.Is() && aDocShell->IsModified())
+ {
+ //Mussten wir konvertieren?
+ if( bOwnFormat )
+ {
+ if(!aDocShell->Save() )
+ bRet = FALSE;
+ else
+ {
+ try {
+ uno::Reference< embed::XTransactedObject > xTransact( aDocShell->GetStorage(), uno::UNO_QUERY );
+ OSL_ENSURE( xTransact.is(), "Storage must implement XTransactedObject!\n" );
+ if ( !xTransact.is() )
+ throw uno::RuntimeException();
+
+ xTransact->commit();
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+// aDocShell->SfxObjectShell::DoSaveCompleted();
+ }
+ }
+ else
+ {
+ // Falls konvertiert im eigenen Format speichern
+ INetURLObject aObj( aFileName );
+ String aTitle = aObj.getName( INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DECODE_WITH_CHARSET );
+ bRet = aDocShell->PreDoSaveAs_Impl(
+ aTitle, aDocShell->GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT )->GetFilterName(), 0 );
+ }
+ }
+
+ if( bOwner)
+ {
+ aDocShell.Clear();
+ }
+
+ return bRet;
+}
+
+//-------------------------------------------------------------------------
+
+SfxObjectList::SfxObjectList()
+{
+}
+
+//-------------------------------------------------------------------------
+
+SfxObjectList::~SfxObjectList()
+{
+ DeleteAndDestroy(0, Count());
+}
+
+//-------------------------------------------------------------------------
+
+const String &SfxObjectList::GetBaseName(USHORT i) const
+{
+ return (*this)[i]->aBaseName;
+}
+
+//-------------------------------------------------------------------------
+
+const String& SfxObjectList::GetFileName( USHORT i ) const
+{
+ return (*this)[i]->aFileName;
+}
+
+//-------------------------------------------------------------------------
+
+SfxOrganizeMgr::SfxOrganizeMgr( SfxOrganizeListBox_Impl *pLeft,
+ SfxOrganizeListBox_Impl *pRight,
+ SfxDocumentTemplates *pTempl) :
+ pImpl(new SfxOrganizeMgr_Impl),
+ pTemplates(pTempl? pTempl: new SfxDocumentTemplates),
+ pLeftBox(pLeft),
+ pRightBox(pRight),
+ bDeleteTemplates(pTempl == 0),
+ bModified(0)
+
+/* [Beschreibung]
+
+ Konstruktor
+
+ Das aktuelle Dokument wird in die Liste der Dokumente
+ aufgenommen.
+
+*/
+{
+ pImpl->pDocList = new SfxObjectList;
+ pImpl->pIntlWrapper = new IntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
+ const CollatorWrapper* pCollator = pImpl->pIntlWrapper->getCaseCollator();
+ for ( SfxObjectShell* pTmp = SfxObjectShell::GetFirst(); pTmp; pTmp = SfxObjectShell::GetNext(*pTmp) )
+ {
+ if ( pTmp->GetCreateMode() != SFX_CREATE_MODE_STANDARD ||
+ !( pTmp->GetFlags() & SFXOBJECTSHELL_HASOPENDOC ) || !pTmp->GetStyleSheetPool() )
+ continue;
+ _FileListEntry* pNewEntry = NULL;
+ String aTitle = pTmp->GetTitle( SFX_TITLE_TITLE );
+ pNewEntry = new _FileListEntry( pTmp->GetMedium()->GetName(), pCollator, &aTitle );
+ pNewEntry->aDocShell = pTmp;
+ pImpl->pDocList->C40_PTR_INSERT( _FileListEntry, pNewEntry );
+ }
+}
+
+//-------------------------------------------------------------------------
+
+SfxOrganizeMgr::~SfxOrganizeMgr()
+{
+ if ( bDeleteTemplates )
+ delete pTemplates;
+ delete pImpl->pDocList;
+ delete pImpl->pIntlWrapper;
+ delete pImpl;
+ pLeftBox = pRightBox = NULL;
+}
+
+//-------------------------------------------------------------------------
+
+SfxObjectShellRef SfxOrganizeMgr::CreateObjectShell( USHORT nIdx )
+
+/* [Beschreibung]
+
+ Zugriff auf die DokumentShell an der Position nIdx
+
+ [Returnwert] Referenz auf die DokumentShell
+
+*/
+
+{
+ _FileListEntry* pEntry = (*pImpl->pDocList)[nIdx];
+ // andernfalls Doc-Shell anlegen
+ if ( !pEntry->aDocShell.Is() )
+ {
+//(mba)/task SfxWaitCursor aWaitCursor;
+ INetURLObject aFileObj( pEntry->aFileName );
+ BOOL bDum = FALSE;
+ SfxApplication* pSfxApp = SFX_APP();
+ String aFilePath = aFileObj.GetMainURL( INetURLObject::NO_DECODE );
+ pEntry->aDocShell = pSfxApp->DocAlreadyLoaded( aFilePath, FALSE, bDum );
+ if ( !pEntry->aDocShell.Is() )
+ {
+ pEntry->bOwner = TRUE;
+ SfxMedium* pMed = new SfxMedium(
+ aFilePath, ( STREAM_READ | STREAM_SHARE_DENYWRITE ), FALSE, 0 );
+ const SfxFilter* pFilter = NULL;
+ pMed->UseInteractionHandler(TRUE);
+ if (
+ pSfxApp->GetFilterMatcher().GuessFilter(*pMed, &pFilter, SFX_FILTER_TEMPLATE, 0) ||
+ (pFilter && !pFilter->IsOwnFormat()) ||
+ (pFilter && !pFilter->UsesStorage())
+ )
+ {
+ pSfxApp->LoadTemplate( pEntry->aDocShell, aFilePath );
+ pEntry->bOwnFormat = FALSE;
+ delete pMed;
+ if ( pEntry->aDocShell.Is() )
+ return (SfxObjectShellRef)(SfxObjectShell*)(pEntry->aDocShell);
+ }
+ else
+ {
+ if ( pFilter )
+ {
+ pEntry->bOwnFormat = TRUE;
+ pEntry->aDocShell = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_ORGANIZER );
+ if ( pEntry->aDocShell.Is() )
+ {
+ pEntry->aDocShell->DoInitNew(0);
+ pEntry->aDocShell->LoadFrom( *pMed );
+ // Medium is now owned by DocShell
+ pEntry->aDocShell->DoSaveCompleted( pMed );
+ }
+ }
+ }
+ }
+ }
+ return ( SfxObjectShellRef )(SfxObjectShell*)(pEntry->aDocShell);
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::DeleteObjectShell(USHORT nIdx)
+
+/* [Beschreibung]
+
+ Freigabe der DokumentShell an der Position nIdx
+
+ [Returnwert] TRUE: alles Ok
+ FALSE: es ist ein Fehler aufgetreten (das
+ Dokument konnte nicht gesichert werden)
+
+*/
+{
+ return (*pImpl->pDocList)[nIdx]->DeleteObjectShell();
+}
+
+//-------------------------------------------------------------------------
+
+SfxObjectShellRef SfxOrganizeMgr::CreateObjectShell(USHORT nRegion,
+ USHORT nIdx)
+/* [Beschreibung]
+
+ Zugriff auf die DokumentShell an der Position nIdx im Bereich
+ nRegion (Dokumentvorlage)
+
+ [Returnwert] Referenz auf die DokumentShell
+
+*/
+{
+//(mba)/task SfxWaitCursor aWaitCursor;
+ return pTemplates->CreateObjectShell(nRegion, nIdx);
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::DeleteObjectShell(USHORT nRegion, USHORT nIdx)
+
+/* [Beschreibung]
+
+ Freigabe der DokumentShell an der Position nIdx im Bereich
+ nRegion (Dokumentvorlage)
+
+ [Returnwert] TRUE: alles Ok
+ FALSE: es ist ein Fehler aufgetreten (das
+ Dokument konnte nicht gesichert werden)
+
+*/
+
+{
+ return pTemplates->DeleteObjectShell(nRegion, nIdx);
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::Copy(USHORT nTargetRegion,
+ USHORT nTargetIdx,
+ USHORT nSourceRegion,
+ USHORT nSourceIdx)
+
+/* [Beschreibung]
+
+ Kopieren einer Dokumentvorlage
+
+ [Parameter]
+
+ USHORT nTargetRegion Index des Zielbereiches
+ USHORT nTargetIdx Index Zielposition
+ USHORT nSourceRegion Index des Quellbereiches
+ USHORT nSourceIdx Index der zu kopierenden / z uverschiebenden
+ Dokumentvorlage
+
+ [R"uckgabewert] Erfolg (TRUE) oder Mi"serfolg (FALSE)
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::Copy(USHORT nTargetRegion,
+ USHORT nTargetIdx,
+ USHORT nSourceRegion,
+ USHORT nSourceIdx)>
+
+*/
+
+{
+ if(nSourceIdx == USHRT_MAX) // keine Verzeichnisse kopieren
+ return FALSE ;
+ const BOOL bOk = pTemplates->Copy(nTargetRegion, nTargetIdx,
+ nSourceRegion, nSourceIdx);
+ if(bOk)
+ bModified = 1;
+ return bOk;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::Move(USHORT nTargetRegion,
+ USHORT nTargetIdx,
+ USHORT nSourceRegion,
+ USHORT nSourceIdx)
+
+/* [Beschreibung]
+
+ Verschieben einer Dokumentvorlage
+
+ [Parameter]
+
+ USHORT nTargetRegion Index des Zielbereiches
+ USHORT nTargetIdx Index Zielposition
+ USHORT nSourceRegion Index des Quellbereiches
+ USHORT nSourceIdx Index der zu kopierenden / z uverschiebenden
+ Dokumentvorlage
+
+ [R"uckgabewert] Erfolg (TRUE) oder Mi"serfolg (FALSE)
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::Move(USHORT nTargetRegion,
+ USHORT nTargetIdx,
+ USHORT nSourceRegion,
+ USHORT nSourceIdx)>
+
+*/
+
+{
+ if(nSourceIdx == USHRT_MAX) // keine Verzeichnisse verschieben
+ return FALSE ;
+ const BOOL bOk = pTemplates->Move(nTargetRegion, nTargetIdx,
+ nSourceRegion, nSourceIdx);
+ if(bOk)
+ bModified = 1;
+ return bOk;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::Delete(SfxOrganizeListBox_Impl *pCaller,
+ USHORT nRegion, USHORT nIdx)
+
+/* [Beschreibung]
+
+ "oschen einer Dokumentvorlage
+
+ [Parameter]
+
+ SfxOrganizeListBox *pCaller rufende ListBox; da dieses
+ Event durch das Men"u oder
+ durch das Keyboard angetriggert wird,
+ mu"s das Model der ListBox anschlie"send
+ aktualisiert werden.
+ USHORT nRegion Index des Bereiches
+ USHORT nIdx Index der Dokumentvorlage
+
+ [R"uckgabewert] Erfolg (TRUE) oder Mi"serfolg (FALSE)
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::Delete(USHORT nRegion, USHORT nIdx)>
+
+*/
+
+{
+ BOOL bOk = FALSE;
+
+ if ( USHRT_MAX == nIdx )
+ {
+ // deleting of a group
+
+ SvLBoxEntry *pGroupToDelete = pCaller->SvLBox::GetEntry(nRegion);
+ if ( pGroupToDelete )
+ {
+ USHORT nItemNum = (USHORT)( pCaller->GetModel()->GetChildCount( pGroupToDelete ) );
+ USHORT nToDeleteNum = 0;
+ SvLBoxEntry **pEntriesToDelete = new SvLBoxEntry*[nItemNum];
+
+ USHORT nInd = 0;
+ for ( nInd = 0; nInd < nItemNum; nInd++ )
+ pEntriesToDelete[nInd] = NULL;
+
+ for ( nInd = 0; nInd < nItemNum; nInd++ )
+ {
+ // TODO/LATER: check that nInd is the same index that is used in pTemplates
+ if ( pTemplates->Delete( nRegion, nInd ) )
+ {
+ bModified = 1;
+ pEntriesToDelete[nToDeleteNum++] = pCaller->SvLBox::GetEntry( pGroupToDelete, nInd );
+ }
+ }
+
+ for ( nInd = 0; nInd < nToDeleteNum; nInd++ )
+ if ( pEntriesToDelete[nInd] )
+ pCaller->GetModel()->Remove( pEntriesToDelete[nInd] );
+
+ if ( !pCaller->GetModel()->GetChildCount( pGroupToDelete ) )
+ {
+ bOk = pTemplates->Delete( nRegion, nIdx );
+ if ( bOk )
+ pCaller->GetModel()->Remove( pGroupToDelete );
+ }
+ }
+ }
+ else
+ {
+ // deleting of a template
+ bOk = pTemplates->Delete(nRegion, nIdx);
+ if(bOk)
+ {
+ bModified = 1;
+ // zu loeschender Eintrag
+ SvLBoxEntry *pEntryToDelete = pCaller->SvLBox::GetEntry(pCaller->SvLBox::GetEntry(nRegion), nIdx);
+
+ pCaller->GetModel()->Remove(pEntryToDelete);
+ }
+ }
+
+ return bOk;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::InsertDir
+(
+ SfxOrganizeListBox_Impl* pCaller,/* rufende ListBox; da dieses Event
+ durch das Men"u oder durch das
+ Keyboard angetriggert wird,
+ mu\s das Model der ListBox
+ anschlie\send aktualisiert werden */
+ const String& rText, // logischer Name des Bereiches
+ USHORT nRegion // Index des Bereiches
+)
+
+/* [Beschreibung]
+
+ Einf"ugen eines Bereiches
+
+
+ [R"uckgabewert]
+
+ Erfolg (TRUE) oder Mi\serfolg (FALSE)
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::InsertDir(const String &, USHORT nRegion)>
+*/
+
+{
+ const BOOL bOk = pTemplates->InsertDir(rText, nRegion);
+ if(bOk)
+ {
+ bModified = 1;
+ SvLBoxEntry *pEntry = pCaller->InsertEntry(rText,
+ pCaller->GetOpenedBmp(0),
+ pCaller->GetClosedBmp(0),
+ 0, TRUE, nRegion);
+ pCaller->Update();
+ pCaller->EditEntry(pEntry);
+ }
+ return bOk;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::SetName(const String &rName,
+ USHORT nRegion, USHORT nIdx)
+
+/* [Beschreibung]
+
+ "Andern eines (logischen) Namens
+
+ [Parameter]
+
+ const String &rName der neue Name
+ USHORT nRegion Index des Bereiches
+ USHORT nIdx Index der Dokumentvorlage
+
+ [R"uckgabewert] Erfolg (TRUE) oder Mi"serfolg (FALSE)
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::SetName(const String &, USHORT nRegion, USHORT nIdx)>
+
+*/
+
+{
+ const BOOL bOk = pTemplates->SetName(rName, nRegion, nIdx);
+ if(bOk)
+ bModified = 1;
+ return bOk;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::CopyTo(USHORT nRegion, USHORT nIdx, const String &rName) const
+
+/* [Beschreibung]
+
+ Export einer Vorlage
+
+ [Parameter]
+
+ USHORT nRegion Index des Bereiches
+ USHORT nIdx Index der Dokumentvorlage
+ const String &rName Dateiname
+
+ [R"uckgabewert] Erfolg (TRUE) oder Mi"serfolg (FALSE)
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::CopyTo( USHORT nRegion, USHORT nIdx, const String &)>
+
+*/
+
+{
+ return pTemplates->CopyTo(nRegion, nIdx, rName);
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::CopyFrom(SfxOrganizeListBox_Impl *pCaller,
+ USHORT nRegion, USHORT nIdx, String &rName)
+
+/* [Beschreibung]
+
+ Import einer Vorlage
+
+ [Parameter]
+
+ SfxOrganizeListBox *pCaller rufende ListBox; da dieses
+ Event durch das Men"u angetriggert wird,
+ mu"s das Model der ListBox anschlie"send
+ aktualisiert werden.
+ USHORT nRegion Index des Bereiches
+ USHORT nIdx Index der Dokumentvorlage
+ String &rName Dateiname
+
+ [R"uckgabewert] Erfolg (TRUE) oder Mi"serfolg (FALSE)
+
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::CopyFrom( USHORT nRegion, USHORT nIdx, const String &)>
+
+*/
+
+{
+ SvLBoxEntry *pParent = pCaller->FirstSelected();
+ if( nIdx!=USHRT_MAX )
+ pParent = pCaller->GetParent(pParent);
+ if( pTemplates->CopyFrom( nRegion, nIdx, rName ) )
+ {
+ // pCaller aktualisieren
+ if( nIdx == USHRT_MAX )
+ nIdx = 0;
+ else nIdx++;
+
+ pCaller->InsertEntry( rName,
+ pCaller->GetOpenedBmp(1),
+ pCaller->GetClosedBmp(1),
+ pParent,
+ TRUE,
+ nIdx);
+ pCaller->Update();
+ // pCaller->EditEntry( pEntry );
+ pCaller->Expand( pParent );
+ bModified = TRUE;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::InsertFile( SfxOrganizeListBox_Impl* pCaller, const String& rFileName )
+
+/* [Beschreibung]
+
+ Eine Datei in der Dateiansicht hinzuf"ugen
+
+ [Parameter]
+
+ SfxOrganizeListBox *pCaller rufende ListBox; da dieses
+ Event durch das Men"u angetriggert wird,
+ mu"s das Model der ListBox anschlie"send
+ aktualisiert werden.
+ const String &rFileName Name der hinzuf"ugenden Datei
+
+ [R"uckgabewert] Erfolg (TRUE) oder Mi"serfolg (FALSE)
+
+*/
+
+{
+ const CollatorWrapper* pCollator = pImpl->pIntlWrapper->getCaseCollator();
+ _FileListEntry* pEntry = new _FileListEntry( rFileName, pCollator );
+ if ( pImpl->pDocList->C40_PTR_INSERT( _FileListEntry, pEntry ) )
+ {
+ USHORT nPos = 0;
+ pImpl->pDocList->Seek_Entry( pEntry, &nPos );
+ pCaller->InsertEntry( pEntry->aBaseName, pCaller->GetOpenedBmp(1),
+ pCaller->GetClosedBmp(1), 0, TRUE, nPos );
+ return TRUE;
+ }
+ return FALSE;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL SfxOrganizeMgr::Rescan()
+
+/* [Beschreibung]
+
+ Aktualisieren der Datenbasis
+
+ [R"uckgabewert]
+
+ TRUE es bestanden Unterschiede
+ FALSE keine "Anderung
+
+ [Querverweise]
+
+ <SfxDocumentTemplates::Rescan()>
+*/
+
+{
+ if(pTemplates->Rescan())
+ {
+ bModified = TRUE;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+//-------------------------------------------------------------------------
+
+void SfxOrganizeMgr::SaveAll(Window *pParent)
+
+/* [Beschreibung]
+
+ Schreiben aller ge"anderten Dokumente
+
+ [Parameter]
+
+ Window *pParent Parent der Boxen f"ur Fehlermeldungen
+
+*/
+
+{
+ USHORT nRangeCount = pTemplates->GetRegionCount();
+ USHORT i;
+ for(i = 0; i < nRangeCount; ++i)
+ {
+ if( pTemplates->IsRegionLoaded( i ))
+ {
+ const USHORT nCount = pTemplates->GetCount(i);
+ for(USHORT j = 0; j < nCount; ++j)
+ {
+ if(!pTemplates->DeleteObjectShell(i, j))
+ {
+ String aText = String(SfxResId(STR_ERROR_SAVE_TEMPLATE));
+ aText += pTemplates->GetName(i, j);
+ ErrorBox aBox(pParent,
+ WinBits(WB_OK_CANCEL | WB_DEF_CANCEL),
+ aText);
+ if(RET_CANCEL == aBox.Execute())
+ break;
+ }
+ }
+ }
+ }
+ nRangeCount = pImpl->pDocList->Count();
+ for(i = 0; i < nRangeCount; ++i)
+ {
+ _FileListEntry *pEntry = (*pImpl->pDocList)[i];
+ if(!pEntry->DeleteObjectShell())
+ {
+ String aText(SfxResId(STR_ERROR_SAVE_TEMPLATE));
+ aText += pEntry->aBaseName;
+ ErrorBox aBox(pParent, WinBits(WB_OK_CANCEL | WB_DEF_CANCEL), aText);
+ if(RET_CANCEL == aBox.Execute())
+ break;
+ }
+ }
+}
+
+
diff --git a/sfx2/source/view/printer.cxx b/sfx2/source/view/printer.cxx
new file mode 100644
index 000000000000..64bebccd60fd
--- /dev/null
+++ b/sfx2/source/view/printer.cxx
@@ -0,0 +1,312 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <vcl/virdev.hxx>
+#include <vcl/metric.hxx>
+#include <vcl/msgbox.hxx>
+#include <unotools/printwarningoptions.hxx>
+#include <svtools/printoptions.hxx>
+#include <vector>
+
+#ifndef GCC
+#endif
+
+#include <sfx2/printer.hxx>
+#include <sfx2/printopt.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/prnmon.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/tabdlg.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "view.hrc"
+
+// struct SfxPrinter_Impl ------------------------------------------------
+
+struct SfxPrinter_Impl
+{
+ BOOL mbAll;
+ BOOL mbSelection;
+ BOOL mbFromTo;
+ BOOL mbRange;
+
+ SfxPrinter_Impl() :
+ mbAll ( TRUE ),
+ mbSelection ( TRUE ),
+ mbFromTo ( TRUE ),
+ mbRange ( TRUE ) {}
+ ~SfxPrinter_Impl() {}
+};
+
+struct SfxPrintOptDlg_Impl
+{
+ sal_Bool mbHelpDisabled;
+
+ SfxPrintOptDlg_Impl() :
+ mbHelpDisabled ( sal_False ) {}
+};
+
+// class SfxPrinter ------------------------------------------------------
+
+SfxPrinter* SfxPrinter::Create( SvStream& rStream, SfxItemSet* pOptions )
+
+/* [Beschreibung]
+
+ Erzeugt einen <SfxPrinter> aus dem Stream. Geladen wird genaugenommen
+ nur ein JobSetup. Falls ein solcher Drucker auf dem System nicht
+ verf"augbar ist, wird das Original als Orig-JobSetup gemerkt und
+ ein "anhlicher exisitierender Drucker genommen.
+
+ Die 'pOptions' werden in den erzeugten SfxPrinter "ubernommen,
+ der Returnwert geh"ort dem Caller.
+*/
+
+{
+ // JobSetup laden
+ JobSetup aFileJobSetup;
+ rStream >> aFileJobSetup;
+
+ // Drucker erzeugen
+ SfxPrinter *pPrinter = new SfxPrinter( pOptions, aFileJobSetup );
+ return pPrinter;
+}
+
+//--------------------------------------------------------------------
+
+SvStream& SfxPrinter::Store( SvStream& rStream ) const
+
+/* [Beschreibung]
+
+ Speichert das verwendete JobSetup des <SfxPrinter>s.
+*/
+
+{
+ return ( rStream << GetJobSetup() );
+}
+
+//--------------------------------------------------------------------
+
+SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions ) :
+
+/* [Beschreibung]
+
+ Dieser Ctor erzeugt einen Standard-Drucker.
+*/
+
+ pOptions( pTheOptions ),
+ bKnown(sal_True)
+
+{
+ pImpl = new SfxPrinter_Impl;
+}
+
+//--------------------------------------------------------------------
+
+SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
+ const JobSetup& rTheOrigJobSetup ) :
+
+ Printer ( rTheOrigJobSetup.GetPrinterName() ),
+ pOptions ( pTheOptions )
+
+{
+ pImpl = new SfxPrinter_Impl;
+ bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
+
+ if ( bKnown )
+ SetJobSetup( rTheOrigJobSetup );
+}
+
+//--------------------------------------------------------------------
+
+SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
+ const String& rPrinterName ) :
+
+ Printer ( rPrinterName ),
+ pOptions ( pTheOptions ),
+ bKnown ( GetName() == rPrinterName )
+
+{
+ pImpl = new SfxPrinter_Impl;
+}
+
+//--------------------------------------------------------------------
+
+SfxPrinter::SfxPrinter( const SfxPrinter& rPrinter ) :
+
+ Printer ( rPrinter.GetName() ),
+ pOptions( rPrinter.GetOptions().Clone() ),
+ bKnown ( rPrinter.IsKnown() )
+{
+ SetJobSetup( rPrinter.GetJobSetup() );
+ SetPrinterProps( &rPrinter );
+ SetMapMode( rPrinter.GetMapMode() );
+
+ pImpl = new SfxPrinter_Impl;
+ pImpl->mbAll = rPrinter.pImpl->mbAll;
+ pImpl->mbSelection = rPrinter.pImpl->mbSelection;
+ pImpl->mbFromTo = rPrinter.pImpl->mbFromTo;
+ pImpl->mbRange = rPrinter.pImpl->mbRange;
+}
+
+//--------------------------------------------------------------------
+
+SfxPrinter* SfxPrinter::Clone() const
+{
+ if ( IsDefPrinter() )
+ {
+ SfxPrinter *pNewPrinter;
+ pNewPrinter = new SfxPrinter( GetOptions().Clone() );
+ pNewPrinter->SetJobSetup( GetJobSetup() );
+ pNewPrinter->SetPrinterProps( this );
+ pNewPrinter->SetMapMode( GetMapMode() );
+ pNewPrinter->pImpl->mbAll = pImpl->mbAll;
+ pNewPrinter->pImpl->mbSelection =pImpl->mbSelection;
+ pNewPrinter->pImpl->mbFromTo = pImpl->mbFromTo;
+ pNewPrinter->pImpl->mbRange =pImpl->mbRange;
+ return pNewPrinter;
+ }
+ else
+ return new SfxPrinter( *this );
+}
+
+//--------------------------------------------------------------------
+
+SfxPrinter::~SfxPrinter()
+{
+ delete pOptions;
+ delete pImpl;
+}
+
+//--------------------------------------------------------------------
+
+void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
+{
+ pOptions->Set(rNewOptions);
+}
+
+//--------------------------------------------------------------------
+
+SfxPrintOptionsDialog::SfxPrintOptionsDialog( Window *pParent,
+ SfxViewShell *pViewShell,
+ const SfxItemSet *pSet ) :
+
+ ModalDialog( pParent, WinBits( WB_STDMODAL | WB_3DLOOK ) ),
+
+ aOkBtn ( this ),
+ aCancelBtn ( this ),
+ aHelpBtn ( this ),
+ pDlgImpl ( new SfxPrintOptDlg_Impl ),
+ pViewSh ( pViewShell ),
+ pOptions ( pSet->Clone() ),
+ pPage ( NULL )
+
+{
+ SetText( SfxResId( STR_PRINT_OPTIONS_TITLE ) );
+
+ // TabPage einh"angen
+ pPage = pViewSh->CreatePrintOptionsPage( this, *pOptions );
+ DBG_ASSERT( pPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
+ if( pPage )
+ {
+ pPage->Reset( *pOptions );
+ SetHelpId( pPage->GetHelpId() );
+ pPage->Show();
+ }
+
+ // Dialoggr"o\se bestimmen
+ Size a6Sz = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
+ Size aBtnSz = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
+ Size aOutSz( pPage ? pPage->GetSizePixel() : Size() );
+ aOutSz.Height() += 6;
+ long nWidth = aBtnSz.Width();
+ nWidth += a6Sz.Width();
+ aOutSz.Width() += nWidth;
+ if ( aOutSz.Height() < 90 )
+ // mindestens die H"ohe der 3 Buttons
+ aOutSz.Height() = 90;
+ SetOutputSizePixel( aOutSz );
+
+ // set position and size of the buttons
+ Point aBtnPos( aOutSz.Width() - aBtnSz.Width() - a6Sz.Width(), a6Sz.Height() );
+ aOkBtn.SetPosSizePixel( aBtnPos, aBtnSz );
+ aBtnPos.Y() += aBtnSz.Height() + ( a6Sz.Height() / 2 );
+ aCancelBtn.SetPosSizePixel( aBtnPos, aBtnSz );
+ aBtnPos.Y() += aBtnSz.Height() + a6Sz.Height();
+ aHelpBtn.SetPosSizePixel( aBtnPos, aBtnSz );
+
+ aCancelBtn.Show();
+ aOkBtn.Show();
+ aHelpBtn.Show();
+}
+
+//--------------------------------------------------------------------
+
+SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
+{
+ delete pDlgImpl;
+ delete pPage;
+ delete pOptions;
+}
+
+//--------------------------------------------------------------------
+
+short SfxPrintOptionsDialog::Execute()
+{
+ if( ! pPage )
+ return RET_CANCEL;
+
+ short nRet = ModalDialog::Execute();
+ if ( nRet == RET_OK )
+ pPage->FillItemSet( *pOptions );
+ else
+ pPage->Reset( *pOptions );
+ return nRet;
+}
+
+//--------------------------------------------------------------------
+
+long SfxPrintOptionsDialog::Notify( NotifyEvent& rNEvt )
+{
+ if ( rNEvt.GetType() == EVENT_KEYINPUT )
+ {
+ if ( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1 && pDlgImpl->mbHelpDisabled )
+ return 1; // help disabled -> <F1> does nothing
+ }
+
+ return ModalDialog::Notify( rNEvt );
+}
+
+//--------------------------------------------------------------------
+
+void SfxPrintOptionsDialog::DisableHelp()
+{
+ pDlgImpl->mbHelpDisabled = sal_True;
+
+ aHelpBtn.Disable();
+}
+
diff --git a/sfx2/source/view/sfxbasecontroller.cxx b/sfx2/source/view/sfxbasecontroller.cxx
new file mode 100644
index 000000000000..b8ad1cfc61f7
--- /dev/null
+++ b/sfx2/source/view/sfxbasecontroller.cxx
@@ -0,0 +1,1542 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+//________________________________________________________________________________________________________
+// my own includes
+//________________________________________________________________________________________________________
+
+#include <time.h>
+#include <sfx2/sfxbasecontroller.hxx>
+
+//________________________________________________________________________________________________________
+// include of other projects
+//________________________________________________________________________________________________________
+#include <com/sun/star/awt/KeyEvent.hpp>
+#include <com/sun/star/awt/KeyModifier.hpp>
+#include <com/sun/star/awt/MouseEvent.hpp>
+#include <com/sun/star/awt/MouseButton.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/util/XCloseBroadcaster.hpp>
+#include <com/sun/star/util/XCloseListener.hpp>
+#include <com/sun/star/util/CloseVetoException.hpp>
+#include <com/sun/star/document/XViewDataSupplier.hpp>
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase2.hxx>
+#include <com/sun/star/frame/FrameActionEvent.hpp>
+#include <com/sun/star/frame/FrameAction.hpp>
+#include <com/sun/star/frame/CommandGroup.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XBorderResizeListener.hpp>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/lang/EventObject.hpp>
+#include <com/sun/star/lang/XEventListener.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/container/XIndexAccess.hpp>
+#include <cppuhelper/interfacecontainer.hxx>
+#include <cppuhelper/typeprovider.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <basic/sbstar.hxx>
+#include <uno/mapping.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/userinputinterception.hxx>
+
+#include <viewimp.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/childwin.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <workwin.hxx>
+#include <sfx2/objface.hxx>
+
+#include <vos/mutex.hxx>
+#include <osl/mutex.hxx>
+#include <tools/diagnose_ex.h>
+#include <comphelper/sequence.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <toolkit/helper/convert.hxx>
+#include <framework/titlehelper.hxx>
+#include <comphelper/processfactory.hxx>
+#include <tools/diagnose_ex.h>
+
+#include <hash_map>
+
+#include <sfx2/event.hxx>
+#include "sfx2/viewfac.hxx"
+
+#define OMULTITYPEINTERFACECONTAINERHELPER ::cppu::OMultiTypeInterfaceContainerHelper
+#define OINTERFACECONTAINERHELPER ::cppu::OInterfaceContainerHelper
+#define XFRAMEACTIONLISTENER ::com::sun::star::frame::XFrameActionListener
+#define XCLOSELISTENER ::com::sun::star::util::XCloseListener
+#define FRAMEACTIONEVENT ::com::sun::star::frame::FrameActionEvent
+#define EVENTOBJECT ::com::sun::star::lang::EventObject
+#define OTYPECOLLECTION ::cppu::OTypeCollection
+#define OIMPLEMENTATIONID ::cppu::OImplementationId
+#define MUTEXGUARD ::osl::MutexGuard
+#define UNOQUERY ::com::sun::star::uno::UNO_QUERY
+#define MAPPING ::com::sun::star::uno::Mapping
+#define XSTATUSINDICATORSUPPLIER ::com::sun::star::task::XStatusIndicatorSupplier
+#define XCOMPONENT ::com::sun::star::lang::XComponent
+#define XINTERFACE ::com::sun::star::uno::XInterface
+#define XKEYHANDLER ::com::sun::star::awt::XKeyHandler
+#define XMOUSECLICKHANDLER ::com::sun::star::awt::XMouseClickHandler
+
+#define TIMEOUT_START_RESCHEDULE 10L /* 10th s */
+
+using namespace ::com::sun::star;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::RuntimeException;
+using ::com::sun::star::uno::UNO_QUERY_THROW;
+using ::com::sun::star::uno::UNO_SET_THROW;
+using ::com::sun::star::lang::DisposedException;
+using ::com::sun::star::awt::XWindow;
+using ::com::sun::star::frame::XController;
+using ::com::sun::star::frame::XDispatchProvider;
+using ::com::sun::star::document::XViewDataSupplier;
+using ::com::sun::star::container::XIndexAccess;
+using ::com::sun::star::beans::PropertyValue;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::uno::UNO_QUERY;
+using ::com::sun::star::uno::Exception;
+using ::com::sun::star::frame::XFrame;
+using ::com::sun::star::frame::XFrameActionListener;
+using ::com::sun::star::util::XCloseListener;
+using ::com::sun::star::task::XStatusIndicator;
+using ::com::sun::star::frame::XTitle;
+namespace css = ::com::sun::star;
+
+struct GroupIDToCommandGroup
+{
+ sal_Int16 nGroupID;
+ sal_Int16 nCommandGroup;
+};
+
+// Please update when a new command group is added
+const sal_Int16 MAX_COMMANDGROUP = com::sun::star::frame::CommandGroup::CONTROLS;
+
+static sal_Bool bGroupIDMapInitialized = sal_False;
+static GroupIDToCommandGroup GroupIDCommandGroupMap[] =
+{
+ { GID_INTERN , com::sun::star::frame::CommandGroup::INTERNAL },
+ { GID_APPLICATION , com::sun::star::frame::CommandGroup::APPLICATION },
+ { GID_DOCUMENT , com::sun::star::frame::CommandGroup::DOCUMENT },
+ { GID_VIEW , com::sun::star::frame::CommandGroup::VIEW },
+ { GID_EDIT , com::sun::star::frame::CommandGroup::EDIT },
+ { GID_MACRO , com::sun::star::frame::CommandGroup::MACRO },
+ { GID_OPTIONS , com::sun::star::frame::CommandGroup::OPTIONS },
+ { GID_MATH , com::sun::star::frame::CommandGroup::MATH },
+ { GID_NAVIGATOR , com::sun::star::frame::CommandGroup::NAVIGATOR },
+ { GID_INSERT , com::sun::star::frame::CommandGroup::INSERT },
+ { GID_FORMAT , com::sun::star::frame::CommandGroup::FORMAT },
+ { GID_TEMPLATE , com::sun::star::frame::CommandGroup::TEMPLATE },
+ { GID_TEXT , com::sun::star::frame::CommandGroup::TEXT },
+ { GID_FRAME , com::sun::star::frame::CommandGroup::FRAME },
+ { GID_GRAPHIC , com::sun::star::frame::CommandGroup::GRAPHIC },
+ { GID_TABLE , com::sun::star::frame::CommandGroup::TABLE },
+ { GID_ENUMERATION , com::sun::star::frame::CommandGroup::ENUMERATION },
+ { GID_DATA , com::sun::star::frame::CommandGroup::DATA },
+ { GID_SPECIAL , com::sun::star::frame::CommandGroup::SPECIAL },
+ { GID_IMAGE , com::sun::star::frame::CommandGroup::IMAGE },
+ { GID_CHART , com::sun::star::frame::CommandGroup::CHART },
+ { GID_EXPLORER , com::sun::star::frame::CommandGroup::EXPLORER },
+ { GID_CONNECTOR , com::sun::star::frame::CommandGroup::CONNECTOR },
+ { GID_MODIFY , com::sun::star::frame::CommandGroup::MODIFY },
+ { GID_DRAWING , com::sun::star::frame::CommandGroup::DRAWING },
+ { GID_CONTROLS , com::sun::star::frame::CommandGroup::CONTROLS },
+ { 0 , 0 }
+};
+
+typedef std::hash_map< sal_Int16, sal_Int16 > GroupHashMap;
+
+
+sal_Int16 MapGroupIDToCommandGroup( sal_Int16 nGroupID )
+{
+ static GroupHashMap mHashMap;
+
+ if ( !bGroupIDMapInitialized )
+ {
+ sal_Int32 i = 0;
+ while ( GroupIDCommandGroupMap[i].nGroupID != 0 )
+ {
+ mHashMap.insert( GroupHashMap::value_type(
+ GroupIDCommandGroupMap[i].nGroupID,
+ GroupIDCommandGroupMap[i].nCommandGroup ));
+ ++i;
+ }
+ }
+
+ GroupHashMap::const_iterator pIter = mHashMap.find( nGroupID );
+ if ( pIter != mHashMap.end() )
+ return pIter->second;
+ else
+ return com::sun::star::frame::CommandGroup::INTERNAL;
+}
+
+sal_Int16 MapCommandGroupToGroupID( sal_Int16 nCommandGroup )
+{
+ sal_Int32 i = 0;
+ while ( GroupIDCommandGroupMap[i].nGroupID != 0 )
+ {
+ if ( GroupIDCommandGroupMap[i].nCommandGroup == nCommandGroup )
+ return GroupIDCommandGroupMap[i].nGroupID;
+ ++i;
+ }
+
+ return -1;
+}
+
+sal_Bool SupportsCommandGroup( sal_Int16 nCommandGroup )
+{
+ if (( nCommandGroup >= 0 ) && ( nCommandGroup <= MAX_COMMANDGROUP ))
+ return sal_True;
+ else
+ return sal_False;
+}
+
+sal_uInt32 Get10ThSec()
+{
+ sal_uInt32 n10Ticks = 10 * (sal_uInt32)clock();
+ return n10Ticks / CLOCKS_PER_SEC;
+}
+
+sal_Int32 m_nInReschedule = 0; /// static counter for rescheduling
+
+void reschedule()
+{
+ if ( m_nInReschedule == 0 )
+ {
+ ++m_nInReschedule;
+ Application::Reschedule();
+ --m_nInReschedule;
+ }
+}
+
+class SfxStatusIndicator : public ::cppu::WeakImplHelper2< ::com::sun::star::task::XStatusIndicator, ::com::sun::star::lang::XEventListener >
+{
+friend class SfxBaseController;
+ ::com::sun::star::uno::Reference < XController > xOwner;
+ ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator > xProgress;
+ SfxWorkWindow* pWorkWindow;
+ sal_Int32 _nRange;
+ sal_Int32 _nValue;
+ long _nStartTime;
+public:
+ SfxStatusIndicator(SfxBaseController* pController, SfxWorkWindow* pWork)
+ : xOwner( pController )
+ , pWorkWindow( pWork )
+ {
+ ++m_refCount;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComponent(
+ SAL_STATIC_CAST(::cppu::OWeakObject*, pController ), ::com::sun::star::uno::UNO_QUERY );
+ if (xComponent.is())
+ xComponent->addEventListener(this);
+ --m_refCount;
+ }
+
+ virtual void SAL_CALL start(const ::rtl::OUString& aText, sal_Int32 nRange) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL end(void) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setText(const ::rtl::OUString& aText) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setValue(sal_Int32 nValue) throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL reset() throw(::com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
+};
+
+void SAL_CALL SfxStatusIndicator::start(const ::rtl::OUString& aText, sal_Int32 nRange) throw(::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( xOwner.is() )
+ {
+ _nRange = nRange;
+ _nValue = 0;
+
+ if ( !xProgress.is() )
+ xProgress = pWorkWindow->GetStatusIndicator();
+
+ if ( xProgress.is() )
+ xProgress->start( aText, nRange );
+
+ _nStartTime = Get10ThSec();
+ reschedule();
+ }
+}
+
+void SAL_CALL SfxStatusIndicator::end(void) throw(::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( xOwner.is() )
+ {
+ if ( !xProgress.is() )
+ xProgress = pWorkWindow->GetStatusIndicator();
+
+ if ( xProgress.is() )
+ xProgress->end();
+
+ reschedule();
+ }
+}
+
+void SAL_CALL SfxStatusIndicator::setText(const ::rtl::OUString& aText) throw(::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( xOwner.is() )
+ {
+ if ( !xProgress.is() )
+ xProgress = pWorkWindow->GetStatusIndicator();
+
+ if ( xProgress.is() )
+ xProgress->setText( aText );
+
+ reschedule();
+ }
+}
+
+void SAL_CALL SfxStatusIndicator::setValue( sal_Int32 nValue ) throw(::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( xOwner.is() )
+ {
+ _nValue = nValue;
+
+ if ( !xProgress.is() )
+ xProgress = pWorkWindow->GetStatusIndicator();
+
+ if ( xProgress.is() )
+ xProgress->setValue( nValue );
+
+ sal_Bool bReschedule = (( Get10ThSec() - _nStartTime ) > TIMEOUT_START_RESCHEDULE );
+ if ( bReschedule )
+ reschedule();
+ }
+}
+
+void SAL_CALL SfxStatusIndicator::reset() throw(::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( xOwner.is() )
+ {
+ if ( !xProgress.is() )
+ xProgress = pWorkWindow->GetStatusIndicator();
+
+ if ( xProgress.is() )
+ xProgress->reset();
+
+ reschedule();
+ }
+}
+
+void SAL_CALL SfxStatusIndicator::disposing( const com::sun::star::lang::EventObject& /*Source*/ ) throw(::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ xOwner = 0;
+ xProgress.clear();
+}
+
+//________________________________________________________________________________________________________
+//________________________________________________________________________________________________________
+// declaration IMPL_SfxBaseController_ListenerHelper
+//________________________________________________________________________________________________________
+
+class IMPL_SfxBaseController_ListenerHelper : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XFrameActionListener >
+{
+public:
+ IMPL_SfxBaseController_ListenerHelper( MUTEX& aMutex ,
+ SfxBaseController* pController ) ;
+ virtual ~IMPL_SfxBaseController_ListenerHelper() ;
+ virtual void SAL_CALL frameAction( const FRAMEACTIONEVENT& aEvent ) throw (RUNTIMEEXCEPTION) ;
+ virtual void SAL_CALL disposing( const EVENTOBJECT& aEvent ) throw (RUNTIMEEXCEPTION) ;
+
+private:
+
+ MUTEX& m_aMutex ;
+ SfxBaseController* m_pController ;
+
+} ; // class IMPL_SfxBaseController_ListenerContainer
+
+class IMPL_SfxBaseController_CloseListenerHelper : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
+{
+public:
+ IMPL_SfxBaseController_CloseListenerHelper( MUTEX& aMutex ,
+ SfxBaseController* pController ) ;
+ virtual ~IMPL_SfxBaseController_CloseListenerHelper() ;
+ virtual void SAL_CALL queryClosing( const EVENTOBJECT& aEvent, sal_Bool bDeliverOwnership )
+ throw (RUNTIMEEXCEPTION, com::sun::star::util::CloseVetoException) ;
+ virtual void SAL_CALL notifyClosing( const EVENTOBJECT& aEvent ) throw (RUNTIMEEXCEPTION) ;
+ virtual void SAL_CALL disposing( const EVENTOBJECT& aEvent ) throw (RUNTIMEEXCEPTION) ;
+
+private:
+
+ MUTEX& m_aMutex;
+ SfxBaseController* m_pController;
+
+} ; // class IMPL_SfxBaseController_ListenerContainer
+
+IMPL_SfxBaseController_CloseListenerHelper::IMPL_SfxBaseController_CloseListenerHelper( MUTEX& aMutex ,
+ SfxBaseController* pController )
+ : m_aMutex ( aMutex )
+ , m_pController ( pController )
+{
+}
+
+IMPL_SfxBaseController_CloseListenerHelper::~IMPL_SfxBaseController_CloseListenerHelper()
+{
+}
+
+void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::disposing( const EVENTOBJECT& /*aEvent*/ ) throw( ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::queryClosing( const EVENTOBJECT& aEvent, sal_Bool bDeliverOwnership )
+ throw (RUNTIMEEXCEPTION, com::sun::star::util::CloseVetoException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ SfxViewShell* pShell = m_pController->GetViewShell_Impl();
+ if ( m_pController != NULL && pShell )
+ {
+ BOOL bCanClose = (BOOL) pShell->PrepareClose( FALSE );
+ if ( !bCanClose )
+ {
+ if ( bDeliverOwnership && ( !pShell->GetWindow() || !pShell->GetWindow()->IsReallyVisible() ) )
+ {
+ // ignore OwnerShip in case of visible frame (will be closed by user)
+ uno::Reference < frame::XModel > xModel( aEvent.Source, uno::UNO_QUERY );
+ if ( xModel.is() )
+ pShell->TakeOwnerShip_Impl();
+ else
+ pShell->TakeFrameOwnerShip_Impl();
+ }
+
+ throw com::sun::star::util::CloseVetoException(::rtl::OUString::createFromAscii("Controller disagree ..."),static_cast< ::cppu::OWeakObject*>(this));
+ }
+ }
+}
+
+void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::notifyClosing( const EVENTOBJECT& /*aEvent*/ ) throw (RUNTIMEEXCEPTION)
+{
+}
+
+//________________________________________________________________________________________________________
+// declaration IMPL_SfxBaseController_DataContainer
+//________________________________________________________________________________________________________
+
+struct IMPL_SfxBaseController_DataContainer
+{
+ Reference< XFrame > m_xFrame ;
+ Reference< XFrameActionListener > m_xListener ;
+ Reference< XCloseListener > m_xCloseListener ;
+ ::sfx2::UserInputInterception m_aUserInputInterception;
+ OMULTITYPEINTERFACECONTAINERHELPER m_aListenerContainer ;
+ OINTERFACECONTAINERHELPER m_aInterceptorContainer ;
+ Reference< XStatusIndicator > m_xIndicator ;
+ SfxViewShell* m_pViewShell ;
+ SfxBaseController* m_pController ;
+ sal_Bool m_bDisposing ;
+ sal_Bool m_bSuspendState ;
+ Reference< XTitle > m_xTitleHelper ;
+ Sequence< PropertyValue > m_aCreationArgs ;
+
+ IMPL_SfxBaseController_DataContainer( MUTEX& aMutex ,
+ SfxViewShell* pViewShell ,
+ SfxBaseController* pController )
+ : m_xListener ( new IMPL_SfxBaseController_ListenerHelper( aMutex, pController ) )
+ , m_xCloseListener ( new IMPL_SfxBaseController_CloseListenerHelper( aMutex, pController ) )
+ , m_aUserInputInterception ( *pController, aMutex )
+ , m_aListenerContainer ( aMutex )
+ , m_aInterceptorContainer ( aMutex )
+ , m_pViewShell ( pViewShell )
+ , m_pController ( pController )
+ , m_bDisposing ( sal_False )
+ , m_bSuspendState ( sal_False )
+ {
+ }
+
+} ; // struct IMPL_SfxBaseController_DataContainer
+
+//________________________________________________________________________________________________________
+// IMPL_SfxBaseController_ListenerHelper constructor
+//________________________________________________________________________________________________________
+
+IMPL_SfxBaseController_ListenerHelper::IMPL_SfxBaseController_ListenerHelper( MUTEX& aMutex ,
+ SfxBaseController* pController )
+ : m_aMutex ( aMutex )
+ , m_pController ( pController )
+{
+}
+
+//________________________________________________________________________________________________________
+// IMPL_SfxBaseController_ListenerHelper destructor
+//________________________________________________________________________________________________________
+
+IMPL_SfxBaseController_ListenerHelper::~IMPL_SfxBaseController_ListenerHelper()
+{
+}
+
+void SAL_CALL IMPL_SfxBaseController_ListenerHelper::frameAction( const FRAMEACTIONEVENT& aEvent ) throw( RUNTIMEEXCEPTION )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if (
+ ( m_pController != NULL ) &&
+ ( aEvent.Frame == m_pController->getFrame() ) &&
+ ( m_pController->GetViewShell_Impl() && m_pController->GetViewShell_Impl()->GetWindow() != NULL )
+ )
+ {
+ if ( aEvent.Action == ::com::sun::star::frame::FrameAction_FRAME_UI_ACTIVATED )
+ {
+ if ( !m_pController->GetViewShell_Impl()->GetUIActiveIPClient_Impl() )
+ m_pController->GetViewShell_Impl()->GetViewFrame()->MakeActive_Impl( FALSE );
+ }
+ else if ( aEvent.Action == ::com::sun::star::frame::FrameAction_CONTEXT_CHANGED )
+ {
+ m_pController->GetViewShell_Impl()->GetViewFrame()->GetBindings().ContextChanged_Impl();
+ }
+ }
+}
+
+//________________________________________________________________________________________________________
+// IMPL_SfxBaseController_ListenerHelper -> XEventListener
+//________________________________________________________________________________________________________
+
+void SAL_CALL IMPL_SfxBaseController_ListenerHelper::disposing( const EVENTOBJECT& /*aEvent*/ ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pController && m_pController->getFrame().is() )
+ m_pController->getFrame()->removeFrameActionListener( this ) ;
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> constructor
+//________________________________________________________________________________________________________
+DBG_NAME(sfx2_SfxBaseController)
+SfxBaseController::SfxBaseController( SfxViewShell* pViewShell )
+ : m_pData ( new IMPL_SfxBaseController_DataContainer( m_aMutex, pViewShell, this ))
+{
+ DBG_CTOR(sfx2_SfxBaseController,NULL);
+ m_pData->m_pViewShell->SetController( this );
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> destructor
+//________________________________________________________________________________________________________
+
+SfxBaseController::~SfxBaseController()
+{
+ DBG_DTOR(sfx2_SfxBaseController,NULL);
+ delete m_pData;
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XController2
+//________________________________________________________________________________________________________
+
+Reference< XWindow > SAL_CALL SfxBaseController::getComponentWindow() throw (RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( !m_pData->m_pViewShell )
+ throw DisposedException();
+
+ return Reference< XWindow >( GetViewFrame_Impl().GetFrame().GetWindow().GetComponentInterface(), UNO_QUERY_THROW );
+}
+
+::rtl::OUString SAL_CALL SfxBaseController::getViewControllerName() throw (RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( !m_pData->m_pViewShell || !m_pData->m_pViewShell->GetObjectShell() )
+ throw DisposedException();
+
+ const SfxObjectFactory& rDocFac( m_pData->m_pViewShell->GetObjectShell()->GetFactory() );
+ sal_uInt16 nViewNo = rDocFac.GetViewNo_Impl( GetViewFrame_Impl().GetCurViewId(), rDocFac.GetViewFactoryCount() );
+ OSL_ENSURE( nViewNo < rDocFac.GetViewFactoryCount(), "SfxBaseController::getViewControllerName: view ID not found in view factories!" );
+
+ ::rtl::OUString sViewName;
+ if ( nViewNo < rDocFac.GetViewFactoryCount() )
+ sViewName = rDocFac.GetViewFactory( nViewNo ).GetAPIViewName();
+
+ return sViewName;
+}
+
+Sequence< PropertyValue > SAL_CALL SfxBaseController::getCreationArguments() throw (RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( !m_pData->m_pViewShell || !m_pData->m_pViewShell->GetObjectShell() )
+ throw DisposedException();
+
+ return m_pData->m_aCreationArgs;
+}
+
+void SfxBaseController::SetCreationArguments_Impl( const Sequence< PropertyValue >& i_rCreationArgs )
+{
+ OSL_ENSURE( m_pData->m_aCreationArgs.getLength() == 0, "SfxBaseController::SetCreationArguments_Impl: not intended to be called twice!" );
+ m_pData->m_aCreationArgs = i_rCreationArgs;
+}
+
+SfxViewFrame& SfxBaseController::GetViewFrame_Impl() const
+{
+ ENSURE_OR_THROW( m_pData->m_pViewShell, "not to be called without a view shell" );
+ SfxViewFrame* pActFrame = m_pData->m_pViewShell->GetFrame();
+ ENSURE_OR_THROW( pActFrame, "a view shell without a view frame is pretty pathological" );
+ return *pActFrame;
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XController2 -> XController
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseController::attachFrame( const REFERENCE< XFRAME >& xFrame ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ REFERENCE< XFRAME > xTemp( getFrame() ) ;
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( xTemp.is() )
+ {
+ xTemp->removeFrameActionListener( m_pData->m_xListener ) ;
+ REFERENCE < ::com::sun::star::util::XCloseBroadcaster > xCloseable( xTemp, com::sun::star::uno::UNO_QUERY );
+ if ( xCloseable.is() )
+ xCloseable->removeCloseListener( m_pData->m_xCloseListener );
+ }
+
+ m_pData->m_xFrame = xFrame;
+
+ if ( xFrame.is() )
+ {
+ xFrame->addFrameActionListener( m_pData->m_xListener ) ;
+ REFERENCE < ::com::sun::star::util::XCloseBroadcaster > xCloseable( xFrame, com::sun::star::uno::UNO_QUERY );
+ if ( xCloseable.is() )
+ xCloseable->addCloseListener( m_pData->m_xCloseListener );
+
+ if ( m_pData->m_pViewShell )
+ {
+ ConnectSfxFrame_Impl( E_CONNECT );
+
+ // attaching the frame to the controller is the last step in the creation of a new view, so notify this
+ SfxViewEventHint aHint( SFX_EVENT_VIEWCREATED, GlobalEventConfig::GetEventName( STR_EVENT_VIEWCREATED ), m_pData->m_pViewShell->GetObjectShell(), uno::Reference< frame::XController2 >( this ) );
+ SFX_APP()->NotifyEvent( aHint );
+ }
+ }
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XController
+//________________________________________________________________________________________________________
+
+sal_Bool SAL_CALL SfxBaseController::attachModel( const REFERENCE< XMODEL >& xModel ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ if ( m_pData->m_pViewShell && xModel.is() && xModel != m_pData->m_pViewShell->GetObjectShell()->GetModel() )
+ {
+ // don't allow to reattach a model!
+ DBG_ERROR("Can't reattach model!");
+ return sal_False;
+ }
+
+ REFERENCE < ::com::sun::star::util::XCloseBroadcaster > xCloseable( xModel, com::sun::star::uno::UNO_QUERY );
+ if ( xCloseable.is() )
+ xCloseable->addCloseListener( m_pData->m_xCloseListener );
+ return sal_True;
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XController
+//________________________________________________________________________________________________________
+
+sal_Bool SAL_CALL SfxBaseController::suspend( sal_Bool bSuspend ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ // ignore dublicate calls, which doesnt change anything real
+ if (bSuspend == m_pData->m_bSuspendState)
+ return sal_True;
+
+ if ( bSuspend == sal_True )
+ {
+ if ( !m_pData->m_pViewShell )
+ {
+ m_pData->m_bSuspendState = sal_True;
+ return sal_True;
+ }
+
+ if ( !m_pData->m_pViewShell->PrepareClose() )
+ return sal_False;
+
+ if ( getFrame().is() )
+ getFrame()->removeFrameActionListener( m_pData->m_xListener ) ;
+ SfxViewFrame* pActFrame = m_pData->m_pViewShell->GetFrame() ;
+
+ // weitere View auf dasselbe Doc?
+ SfxObjectShell* pDocShell = m_pData->m_pViewShell->GetObjectShell() ;
+ sal_Bool bOther = sal_False ;
+
+ for ( const SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell ); !bOther && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell ) )
+ bOther = (pFrame != pActFrame);
+
+ BOOL bRet = bOther || pDocShell->PrepareClose();
+ if ( bRet )
+ {
+ ConnectSfxFrame_Impl( E_DISCONNECT );
+ m_pData->m_bSuspendState = sal_True;
+ }
+
+ return bRet;
+ }
+ else
+ {
+ if ( getFrame().is() )
+ getFrame()->addFrameActionListener( m_pData->m_xListener ) ;
+
+ if ( m_pData->m_pViewShell )
+ {
+ ConnectSfxFrame_Impl( E_RECONNECT );
+ }
+
+ m_pData->m_bSuspendState = sal_False;
+ return sal_True ;
+ }
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XController
+//________________________________________________________________________________________________________
+
+ANY SfxBaseController::getViewData() throw( ::com::sun::star::uno::RuntimeException )
+{
+ ANY aAny;
+ String sData1;
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pData->m_pViewShell )
+ {
+ m_pData->m_pViewShell->WriteUserData( sData1 ) ;
+ OUSTRING sData( sData1 );
+ aAny <<= sData ;
+ }
+
+ return aAny ;
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XController
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseController::restoreViewData( const ANY& aValue ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pData->m_pViewShell )
+ {
+ OUSTRING sData;
+ aValue >>= sData ;
+ m_pData->m_pViewShell->ReadUserData( sData ) ;
+ }
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XController
+//________________________________________________________________________________________________________
+
+REFERENCE< XFRAME > SAL_CALL SfxBaseController::getFrame() throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ return m_pData->m_xFrame;
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XController
+//________________________________________________________________________________________________________
+
+REFERENCE< XMODEL > SAL_CALL SfxBaseController::getModel() throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ return m_pData->m_pViewShell ? m_pData->m_pViewShell->GetObjectShell()->GetModel() : REFERENCE < XMODEL > () ;
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XDispatchProvider
+//________________________________________________________________________________________________________
+
+REFERENCE< XDISPATCH > SAL_CALL SfxBaseController::queryDispatch( const UNOURL& aURL ,
+ const OUSTRING& sTargetFrameName,
+ sal_Int32 eSearchFlags ) throw( RUNTIMEEXCEPTION )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ REFERENCE< XDISPATCH > xDisp;
+ if ( m_pData->m_pViewShell )
+ {
+ SfxViewFrame* pAct = m_pData->m_pViewShell->GetViewFrame() ;
+ if ( !m_pData->m_bDisposing )
+ {
+ if ( sTargetFrameName.compareToAscii( "_beamer" ) == COMPARE_EQUAL )
+ {
+ SfxViewFrame *pFrame = m_pData->m_pViewShell->GetViewFrame();
+ if ( eSearchFlags & ( ::com::sun::star::frame::FrameSearchFlag::CREATE ))
+ pFrame->SetChildWindow( SID_BROWSER, TRUE );
+ SfxChildWindow* pChildWin = pFrame->GetChildWindow( SID_BROWSER );
+ REFERENCE < XFRAME > xFrame;
+ if ( pChildWin )
+ xFrame = ( pChildWin->GetFrame() );
+ if ( xFrame.is() )
+ xFrame->setName( sTargetFrameName );
+
+ Reference< XDispatchProvider > xProv( xFrame, ::com::sun::star::uno::UNO_QUERY );
+ if ( xProv.is() )
+ return xProv->queryDispatch( aURL, sTargetFrameName, ::com::sun::star::frame::FrameSearchFlag::SELF );
+ }
+
+ if ( aURL.Protocol.compareToAscii( ".uno:" ) == COMPARE_EQUAL )
+ {
+ rtl::OUString aMasterCommand = SfxOfficeDispatch::GetMasterUnoCommand( aURL );
+ sal_Bool bMasterCommand( aMasterCommand.getLength() > 0 );
+
+ pAct = m_pData->m_pViewShell->GetViewFrame() ;
+ SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
+
+ const SfxSlot* pSlot( 0 );
+ if ( bMasterCommand )
+ pSlot = rSlotPool.GetUnoSlot( aMasterCommand );
+ else
+ pSlot = rSlotPool.GetUnoSlot( aURL.Path );
+ if ( pSlot && ( !pAct->GetFrame().IsInPlace() || !pSlot->IsMode( SFX_SLOT_CONTAINER ) ) )
+ return pAct->GetBindings().GetDispatch( pSlot, aURL, bMasterCommand );
+ else
+ {
+ // try to find parent SfxViewFrame
+ uno::Reference< frame::XFrame > xParentFrame;
+ uno::Reference< frame::XFrame > xOwnFrame = pAct->GetFrame().GetFrameInterface();
+ if ( xOwnFrame.is() )
+ xParentFrame = uno::Reference< frame::XFrame >( xOwnFrame->getCreator(), uno::UNO_QUERY );
+
+ if ( xParentFrame.is() )
+ {
+ // TODO/LATER: in future probably SfxViewFrame hirarchy should be the same as XFrame hirarchy
+ // SfxViewFrame* pParentFrame = pAct->GetParentViewFrame();
+
+ // search the related SfxViewFrame
+ SfxViewFrame* pParentFrame = NULL;
+ for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst();
+ pFrame;
+ pFrame = SfxViewFrame::GetNext( *pFrame ) )
+ {
+ if ( pFrame->GetFrame().GetFrameInterface() == xParentFrame )
+ {
+ pParentFrame = pFrame;
+ break;
+ }
+ }
+
+ if ( pParentFrame )
+ {
+ SfxSlotPool& rFrameSlotPool = SfxSlotPool::GetSlotPool( pParentFrame );
+ const SfxSlot* pSlot2( 0 );
+ if ( bMasterCommand )
+ pSlot2 = rFrameSlotPool.GetUnoSlot( aMasterCommand );
+ else
+ pSlot2 = rFrameSlotPool.GetUnoSlot( aURL.Path );
+
+ if ( pSlot2 )
+ return pParentFrame->GetBindings().GetDispatch( pSlot2, aURL, bMasterCommand );
+ }
+ }
+ }
+ }
+ else if ( aURL.Protocol.compareToAscii( "slot:" ) == COMPARE_EQUAL )
+ {
+ USHORT nId = (USHORT) aURL.Path.toInt32();
+
+ pAct = m_pData->m_pViewShell->GetViewFrame() ;
+ if (nId >= SID_VERB_START && nId <= SID_VERB_END)
+ {
+ const SfxSlot* pSlot = m_pData->m_pViewShell->GetVerbSlot_Impl(nId);
+ if ( pSlot )
+ return pAct->GetBindings().GetDispatch( pSlot, aURL, sal_False );
+ }
+
+ SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
+ const SfxSlot* pSlot = rSlotPool.GetSlot( nId );
+ if ( pSlot && ( !pAct->GetFrame().IsInPlace() || !pSlot->IsMode( SFX_SLOT_CONTAINER ) ) )
+ return pAct->GetBindings().GetDispatch( pSlot, aURL, sal_False );
+ else
+ {
+ // try to find parent SfxViewFrame
+ uno::Reference< frame::XFrame > xParentFrame;
+ uno::Reference< frame::XFrame > xOwnFrame = pAct->GetFrame().GetFrameInterface();
+ if ( xOwnFrame.is() )
+ xParentFrame = uno::Reference< frame::XFrame >( xOwnFrame->getCreator(), uno::UNO_QUERY );
+
+ if ( xParentFrame.is() )
+ {
+ // TODO/LATER: in future probably SfxViewFrame hirarchy should be the same as XFrame hirarchy
+ // SfxViewFrame* pParentFrame = pAct->GetParentViewFrame();
+
+ // search the related SfxViewFrame
+ SfxViewFrame* pParentFrame = NULL;
+ for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst();
+ pFrame;
+ pFrame = SfxViewFrame::GetNext( *pFrame ) )
+ {
+ if ( pFrame->GetFrame().GetFrameInterface() == xParentFrame )
+ {
+ pParentFrame = pFrame;
+ break;
+ }
+ }
+
+ if ( pParentFrame )
+ {
+ SfxSlotPool& rSlotPool2 = SfxSlotPool::GetSlotPool( pParentFrame );
+ const SfxSlot* pSlot2 = rSlotPool2.GetUnoSlot( aURL.Path );
+ if ( pSlot2 )
+ return pParentFrame->GetBindings().GetDispatch( pSlot2, aURL, sal_False );
+ }
+ }
+ }
+ }
+ else if( sTargetFrameName.compareToAscii( "_self" )==COMPARE_EQUAL || sTargetFrameName.getLength()==0 )
+ {
+ // check for already loaded URL ... but with additional jumpmark!
+ REFERENCE< XMODEL > xModel = getModel();
+ if( xModel.is() && aURL.Mark.getLength() )
+ {
+ SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
+ const SfxSlot* pSlot = rSlotPool.GetSlot( SID_JUMPTOMARK );
+ if( aURL.Main.getLength() && aURL.Main == xModel->getURL() && pSlot )
+ return REFERENCE< XDISPATCH >( new SfxOfficeDispatch( pAct->GetBindings(), pAct->GetDispatcher(), pSlot, aURL) );
+ }
+ }
+ }
+ }
+
+ return xDisp;
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XDispatchProvider
+//________________________________________________________________________________________________________
+
+SEQUENCE< REFERENCE< XDISPATCH > > SAL_CALL SfxBaseController::queryDispatches( const SEQUENCE< DISPATCHDESCRIPTOR >& seqDescripts ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ // Create return list - which must have same size then the given descriptor
+ // It's not allowed to pack it!
+ sal_Int32 nCount = seqDescripts.getLength();
+ SEQUENCE< REFERENCE< XDISPATCH > > lDispatcher( nCount );
+
+ for( sal_Int32 i=0; i<nCount; ++i )
+ {
+ lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL ,
+ seqDescripts[i].FrameName ,
+ seqDescripts[i].SearchFlags );
+ }
+
+ return lDispatcher;
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XControllerBorder
+//________________________________________________________________________________________________________
+
+frame::BorderWidths SAL_CALL SfxBaseController::getBorder()
+ throw ( uno::RuntimeException )
+{
+ frame::BorderWidths aResult;
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pData->m_pViewShell )
+ {
+ SvBorder aBorder = m_pData->m_pViewShell->GetBorderPixel();
+ aResult.Left = aBorder.Left();
+ aResult.Top = aBorder.Top();
+ aResult.Right = aBorder.Right();
+ aResult.Bottom = aBorder.Bottom();
+ }
+
+ return aResult;
+}
+
+void SAL_CALL SfxBaseController::addBorderResizeListener( const uno::Reference< frame::XBorderResizeListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ m_pData->m_aListenerContainer.addInterface( ::getCppuType((const uno::Reference< frame::XBorderResizeListener >*)0),
+ xListener );
+}
+
+void SAL_CALL SfxBaseController::removeBorderResizeListener( const uno::Reference< frame::XBorderResizeListener >& xListener )
+ throw ( uno::RuntimeException )
+{
+ m_pData->m_aListenerContainer.removeInterface( ::getCppuType((const uno::Reference< frame::XBorderResizeListener >*)0),
+ xListener );
+}
+
+awt::Rectangle SAL_CALL SfxBaseController::queryBorderedArea( const awt::Rectangle& aPreliminaryRectangle )
+ throw ( uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pData->m_pViewShell )
+ {
+ Rectangle aTmpRect = VCLRectangle( aPreliminaryRectangle );
+ m_pData->m_pViewShell->QueryObjAreaPixel( aTmpRect );
+ return AWTRectangle( aTmpRect );
+ }
+
+ return aPreliminaryRectangle;
+}
+
+void SfxBaseController::BorderWidthsChanged_Impl()
+{
+ ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aListenerContainer.getContainer(
+ ::getCppuType( ( const uno::Reference< frame::XBorderResizeListener >*) NULL ) );
+ if ( pContainer )
+ {
+ frame::BorderWidths aBWidths = getBorder();
+ uno::Reference< uno::XInterface > xThis( static_cast< ::cppu::OWeakObject* >(this), uno::UNO_QUERY );
+
+ ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
+ while (pIterator.hasMoreElements())
+ {
+ try
+ {
+ ((frame::XBorderResizeListener*)pIterator.next())->borderWidthsChanged( xThis, aBWidths );
+ }
+ catch( uno::RuntimeException& )
+ {
+ pIterator.remove();
+ }
+ }
+ }
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XComponent
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseController::dispose() throw( ::com::sun::star::uno::RuntimeException )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ Reference< XController > xTmp( this );
+ m_pData->m_bDisposing = sal_True ;
+
+ EVENTOBJECT aEventObject;
+ aEventObject.Source = *this ;
+ m_pData->m_aListenerContainer.disposeAndClear( aEventObject ) ;
+
+ if ( m_pData->m_pController && m_pData->m_pController->getFrame().is() )
+ m_pData->m_pController->getFrame()->removeFrameActionListener( m_pData->m_xListener ) ;
+
+ if ( m_pData->m_pViewShell )
+ {
+ SfxViewFrame* pFrame = m_pData->m_pViewShell->GetViewFrame() ;
+ if ( pFrame && pFrame->GetViewShell() == m_pData->m_pViewShell )
+ pFrame->GetFrame().SetIsClosing_Impl();
+ m_pData->m_pViewShell->DiscardClients_Impl();
+ m_pData->m_pViewShell->pImp->m_bControllerSet = false;
+
+ if ( pFrame )
+ {
+ EVENTOBJECT aObject;
+ aObject.Source = *this ;
+
+ SfxObjectShell* pDoc = pFrame->GetObjectShell() ;
+ SfxViewFrame *pView = SfxViewFrame::GetFirst(pDoc);
+ while( pView )
+ {
+ // if there is another ViewFrame or currently the ViewShell in my ViewFrame is switched (PagePreview)
+ if ( pView != pFrame || pView->GetViewShell() != m_pData->m_pViewShell )
+ break;
+ pView = SfxViewFrame::GetNext( *pView, pDoc );
+ }
+
+ SFX_APP()->NotifyEvent( SfxViewEventHint(SFX_EVENT_CLOSEVIEW, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEVIEW ), pDoc, uno::Reference< frame::XController2 >( this ) ) );
+ if ( !pView )
+ SFX_APP()->NotifyEvent( SfxEventHint(SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ), pDoc) );
+
+ REFERENCE< XMODEL > xModel = pDoc->GetModel();
+ REFERENCE < ::com::sun::star::util::XCloseable > xCloseable( xModel, com::sun::star::uno::UNO_QUERY );
+ if ( xModel.is() )
+ {
+ xModel->disconnectController( this );
+ if ( xCloseable.is() )
+ xCloseable->removeCloseListener( m_pData->m_xCloseListener );
+ }
+
+ REFERENCE < XFRAME > aXFrame;
+ attachFrame( aXFrame );
+
+ m_pData->m_xListener->disposing( aObject );
+ SfxViewShell *pShell = m_pData->m_pViewShell;
+ m_pData->m_pViewShell = NULL;
+ if ( pFrame->GetViewShell() == pShell )
+ {
+ // Enter registrations only allowed if we are the owner!
+ if ( pFrame->GetFrame().OwnsBindings_Impl() )
+ pFrame->GetBindings().ENTERREGISTRATIONS();
+ pFrame->GetFrame().SetFrameInterface_Impl( aXFrame );
+ pFrame->GetFrame().DoClose_Impl();
+ }
+ }
+ }
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XComponent
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseController::addEventListener( const REFERENCE< XEVENTLISTENER >& aListener ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ m_pData->m_aListenerContainer.addInterface( ::getCppuType((const REFERENCE< XEVENTLISTENER >*)0), aListener );
+}
+
+//________________________________________________________________________________________________________
+// SfxBaseController -> XComponent
+//________________________________________________________________________________________________________
+
+void SAL_CALL SfxBaseController::removeEventListener( const REFERENCE< XEVENTLISTENER >& aListener ) throw( ::com::sun::star::uno::RuntimeException )
+{
+ m_pData->m_aListenerContainer.removeInterface( ::getCppuType((const REFERENCE< XEVENTLISTENER >*)0), aListener );
+}
+
+void SfxBaseController::ReleaseShell_Impl()
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pData->m_pViewShell )
+ {
+ SfxObjectShell* pDoc = m_pData->m_pViewShell->GetObjectShell() ;
+ REFERENCE< XMODEL > xModel = pDoc->GetModel();
+ REFERENCE < ::com::sun::star::util::XCloseable > xCloseable( xModel, com::sun::star::uno::UNO_QUERY );
+ if ( xModel.is() )
+ {
+ xModel->disconnectController( this );
+ if ( xCloseable.is() )
+ xCloseable->removeCloseListener( m_pData->m_xCloseListener );
+ }
+ m_pData->m_pViewShell = 0;
+
+ REFERENCE < XFRAME > aXFrame;
+ attachFrame( aXFrame );
+ }
+}
+
+SfxViewShell* SfxBaseController::GetViewShell_Impl() const
+{
+ return m_pData->m_pViewShell;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator > SAL_CALL SfxBaseController::getStatusIndicator( ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pData->m_pViewShell && !m_pData->m_xIndicator.is() )
+ m_pData->m_xIndicator = new SfxStatusIndicator( this, m_pData->m_pViewShell->GetViewFrame()->GetFrame().GetWorkWindow_Impl() );
+ return m_pData->m_xIndicator;
+}
+
+void SAL_CALL SfxBaseController::registerContextMenuInterceptor( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor ) throw( RUNTIMEEXCEPTION )
+
+{
+ m_pData->m_aInterceptorContainer.addInterface( xInterceptor );
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pData->m_pViewShell )
+ m_pData->m_pViewShell->AddContextMenuInterceptor_Impl( xInterceptor );
+}
+
+void SAL_CALL SfxBaseController::releaseContextMenuInterceptor( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor ) throw( RUNTIMEEXCEPTION )
+
+{
+ m_pData->m_aInterceptorContainer.removeInterface( xInterceptor );
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pData->m_pViewShell )
+ m_pData->m_pViewShell->RemoveContextMenuInterceptor_Impl( xInterceptor );
+}
+
+void SAL_CALL SfxBaseController::addKeyHandler( const ::com::sun::star::uno::Reference< XKEYHANDLER >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ m_pData->m_aUserInputInterception.addKeyHandler( xHandler );
+}
+
+void SAL_CALL SfxBaseController::removeKeyHandler( const ::com::sun::star::uno::Reference< XKEYHANDLER >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ m_pData->m_aUserInputInterception.removeKeyHandler( xHandler );
+}
+
+void SAL_CALL SfxBaseController::addMouseClickHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseClickHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ m_pData->m_aUserInputInterception.addMouseClickHandler( xHandler );
+}
+
+void SAL_CALL SfxBaseController::removeMouseClickHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseClickHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ m_pData->m_aUserInputInterception.removeMouseClickHandler( xHandler );
+}
+
+::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL SfxBaseController::getSupportedCommandGroups()
+throw (::com::sun::star::uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ std::list< sal_Int16 > aGroupList;
+ SfxViewFrame* pViewFrame( m_pData->m_pViewShell->GetFrame() );
+ SfxSlotPool* pPool = &SfxSlotPool::GetSlotPool( pViewFrame );
+
+ SfxSlotPool* pSlotPool = pPool ? pPool : &SFX_SLOTPOOL();
+ const ULONG nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
+
+ // Gruppe anw"ahlen ( Gruppe 0 ist intern )
+ for ( USHORT i=0; i<pSlotPool->GetGroupCount(); i++ )
+ {
+ String aName = pSlotPool->SeekGroup( i );
+ const SfxSlot* pSfxSlot = pSlotPool->FirstSlot();
+ while ( pSfxSlot )
+ {
+ if ( pSfxSlot->GetMode() & nMode )
+ {
+ sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
+ aGroupList.push_back( nCommandGroup );
+ break;
+ }
+ pSfxSlot = pSlotPool->NextSlot();
+ }
+ }
+
+ ::com::sun::star::uno::Sequence< sal_Int16 > aSeq =
+ comphelper::containerToSequence< sal_Int16 >( aGroupList );
+ return aSeq;
+}
+
+::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > SAL_CALL SfxBaseController::getConfigurableDispatchInformation( sal_Int16 nCmdGroup )
+throw (::com::sun::star::uno::RuntimeException)
+{
+ std::list< ::com::sun::star::frame::DispatchInformation > aCmdList;
+
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( m_pData->m_pViewShell )
+ {
+ const ULONG nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
+
+ SfxViewFrame* pViewFrame( m_pData->m_pViewShell->GetFrame() );
+ SfxSlotPool* pPool( &SfxSlotPool::GetSlotPool( pViewFrame ));
+ rtl::OUString aCmdPrefix( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
+
+ SfxSlotPool* pSlotPool = pPool ? pPool : &SFX_SLOTPOOL();
+ for ( USHORT i=0; i<pSlotPool->GetGroupCount(); i++ )
+ {
+ String aName = pSlotPool->SeekGroup( i );
+ const SfxSlot* pSfxSlot = pSlotPool->FirstSlot();
+ if ( pSfxSlot )
+ {
+ sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
+ if ( nCommandGroup == nCmdGroup )
+ {
+ while ( pSfxSlot )
+ {
+ if ( pSfxSlot->GetMode() & nMode )
+ {
+ ::com::sun::star::frame::DispatchInformation aCmdInfo;
+ ::rtl::OUStringBuffer aBuf( aCmdPrefix );
+ aBuf.appendAscii( pSfxSlot->GetUnoName() );
+ aCmdInfo.Command = aBuf.makeStringAndClear();
+ aCmdInfo.GroupId = nCommandGroup;
+ aCmdList.push_back( aCmdInfo );
+ }
+ pSfxSlot = pSlotPool->NextSlot();
+ }
+ }
+ }
+ }
+ }
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > aSeq =
+ comphelper::containerToSequence< ::com::sun::star::frame::DispatchInformation, std::list< ::com::sun::star::frame::DispatchInformation > >( aCmdList );
+
+ return aSeq;
+}
+
+BOOL SfxBaseController::HandleEvent_Impl( NotifyEvent& rEvent )
+{
+ return m_pData->m_aUserInputInterception.handleNotifyEvent( rEvent );
+}
+
+BOOL SfxBaseController::HasKeyListeners_Impl()
+{
+ return m_pData->m_aUserInputInterception.hasKeyHandlers();
+}
+
+BOOL SfxBaseController::HasMouseClickListeners_Impl()
+{
+ return m_pData->m_aUserInputInterception.hasMouseClickListeners();
+}
+
+void SfxBaseController::ConnectSfxFrame_Impl( const ConnectSfxFrame i_eConnect )
+{
+ ENSURE_OR_THROW( m_pData->m_pViewShell, "not to be called without a view shell" );
+ SfxViewFrame* pViewFrame = m_pData->m_pViewShell->GetFrame();
+ ENSURE_OR_THROW( pViewFrame, "a view shell without a view frame is pretty pathological" );
+
+ const bool bConnect = ( i_eConnect != E_DISCONNECT );
+
+ // disable window and dispatcher
+ pViewFrame->Enable( bConnect );
+ pViewFrame->GetDispatcher()->Lock( !bConnect );
+
+ if ( bConnect )
+ {
+ if ( i_eConnect == E_CONNECT )
+ {
+ if ( ( m_pData->m_pViewShell->GetObjectShell() != NULL )
+ && ( m_pData->m_pViewShell->GetObjectShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
+ )
+ {
+ SfxViewFrame* pViewFrm = m_pData->m_pViewShell->GetViewFrame();
+ if ( !pViewFrm->GetFrame().IsInPlace() )
+ {
+ // for outplace embedded objects, we want the layout manager to keep the content window
+ // size constant, if possible
+ try
+ {
+ uno::Reference< beans::XPropertySet > xFrameProps( m_pData->m_xFrame, uno::UNO_QUERY_THROW );
+ uno::Reference< beans::XPropertySet > xLayouterProps(
+ xFrameProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) ), uno::UNO_QUERY_THROW );
+ xLayouterProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PreserveContentSize" ) ), uno::makeAny( sal_True ) );
+ }
+ catch( const uno::Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+ }
+ }
+
+ // upon DISCONNECT, we did *not* pop the shells from the stack (this is done elsewhere), so upon
+ // RECONNECT, we're not allowed to push them
+ if ( i_eConnect != E_RECONNECT )
+ {
+ pViewFrame->GetDispatcher()->Push( *m_pData->m_pViewShell );
+ if ( m_pData->m_pViewShell->GetSubShell() )
+ pViewFrame->GetDispatcher()->Push( *m_pData->m_pViewShell->GetSubShell() );
+ m_pData->m_pViewShell->PushSubShells_Impl();
+ pViewFrame->GetDispatcher()->Flush();
+ }
+
+ Window* pEditWin = m_pData->m_pViewShell->GetWindow();
+ if ( pEditWin && m_pData->m_pViewShell->IsShowView_Impl() )
+ pEditWin->Show();
+
+ if ( SfxViewFrame::Current() == pViewFrame )
+ pViewFrame->GetDispatcher()->Update_Impl( sal_True );
+
+ Window* pFrameWin = &pViewFrame->GetWindow();
+ if ( pFrameWin != &pViewFrame->GetFrame().GetWindow() )
+ pFrameWin->Show();
+
+ if ( i_eConnect == E_CONNECT )
+ {
+ ::comphelper::NamedValueCollection aDocumentArgs( getModel()->getArgs() );
+
+ const sal_Int16 nPluginMode = aDocumentArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
+ const bool bHasPluginMode = ( nPluginMode != 0 );
+
+ SfxFrame& rFrame = pViewFrame->GetFrame();
+ SfxObjectShell& rDoc = *m_pData->m_pViewShell->GetObjectShell();
+ if ( !rFrame.IsMarkedHidden_Impl() )
+ {
+ if ( rDoc.IsHelpDocument() || ( nPluginMode == 2 ) )
+ pViewFrame->GetDispatcher()->HideUI( TRUE );
+ else
+ pViewFrame->GetDispatcher()->HideUI( FALSE );
+
+ if ( rFrame.IsInPlace() )
+ pViewFrame->LockAdjustPosSizePixel();
+
+ if ( nPluginMode == 3 )
+ rFrame.GetWorkWindow_Impl()->SetInternalDockingAllowed( FALSE );
+
+ if ( !rFrame.IsInPlace() )
+ pViewFrame->GetDispatcher()->Update_Impl();
+ pViewFrame->Show();
+ rFrame.GetWindow().Show();
+ if ( !rFrame.IsInPlace() || ( nPluginMode == 3 ) )
+ pViewFrame->MakeActive_Impl( rFrame.GetFrameInterface()->isActive() );
+
+ if ( rFrame.IsInPlace() )
+ {
+ pViewFrame->UnlockAdjustPosSizePixel();
+ // force resize for OLE server to fix layout problems of writer and math
+ // see i53651
+ if ( nPluginMode == 3 )
+ pViewFrame->Resize( TRUE );
+ }
+ }
+ else
+ {
+ DBG_ASSERT( !rFrame.IsInPlace() && !bHasPluginMode, "Special modes not compatible with hidden mode!" );
+ rFrame.GetWindow().Show();
+ }
+
+ // Jetzt UpdateTitle, hidden TopFrames haben sonst keinen Namen!
+ pViewFrame->UpdateTitle();
+
+ if ( !rFrame.IsInPlace() )
+ pViewFrame->Resize( TRUE );
+
+ // if there's a JumpMark given, then, well, jump to it
+ ::comphelper::NamedValueCollection aViewArgs( getCreationArguments() );
+ const ::rtl::OUString sJumpMark = aViewArgs.getOrDefault( "JumpMark", ::rtl::OUString() );
+ const bool bHasJumpMark = ( sJumpMark.getLength() > 0 );
+ OSL_ENSURE( ( !m_pData->m_pViewShell->GetObjectShell()->IsLoading() )
+ || ( !sJumpMark.getLength() ),
+ "SfxBaseController::ConnectSfxFrame_Impl: so this code wasn't dead?" );
+ // Before CWS autorecovery, there was code which postponed jumping to the Mark to a later time
+ // (SfxObjectShell::PositionView_Impl), but it seems this branch was never used, since this method
+ // here is never called before the load process finished. At least not with a non-empty jump mark
+ if ( sJumpMark.getLength() )
+ m_pData->m_pViewShell->JumpToMark( sJumpMark );
+
+ // if no plugin mode and no jump mark was supplied, check whether the document itself can provide view data, and
+ // if so, forward it to the view/shell.
+ if ( !bHasPluginMode && !bHasJumpMark )
+ {
+ // Note that this might not be the ideal place here. Restoring view data should, IMO, be the
+ // responsibility of the loader, not an implementation detail burried here deep within the controller's
+ // implementation.
+ // What I think should be done to replace the below code:
+ // - change SfxBaseController::restoreViewData to also accept a PropertyValue[] (it currently accepts
+ // a string only), and forward it to its ViewShell's ReadUserDataSequence
+ // - change the frame loader so that when a new document is loaded (as opposed to an existing
+ // document being loaded into a new frame), the model's view data is examine the very same
+ // way as below, and the proper view data is set via XController::restoreViewData
+ // - extend SfxViewFrame::SwitchToViewShell_Impl. Currently, it cares for the case where a non-PrintPreview
+ // view is exchanged, and sets the old view's data at the model. It should also care for the other
+ // way, were the PrintPreview view is left: in this case, the new view should also be initialized
+ // with the model's view data
+ try
+ {
+ Reference< XViewDataSupplier > xViewDataSupplier( getModel(), UNO_QUERY_THROW );
+ Reference< XIndexAccess > xViewData( xViewDataSupplier->getViewData() );
+
+ // find the view data item whose ViewId matches the ID of the view we're just connecting to
+ const SfxObjectFactory& rDocFactory( rDoc.GetFactory() );
+ const sal_Int32 nCount = xViewData.is() ? xViewData->getCount() : 0;
+ sal_Int32 nViewDataIndex = 0;
+ for ( sal_Int32 i=0; i<nCount; ++i )
+ {
+ const ::comphelper::NamedValueCollection aViewData( xViewData->getByIndex(i) );
+ ::rtl::OUString sViewId( aViewData.getOrDefault( "ViewId", ::rtl::OUString() ) );
+ if ( sViewId.getLength() == 0 )
+ continue;
+
+ const SfxViewFactory* pViewFactory = rDocFactory.GetViewFactoryByViewName( sViewId );
+ if ( pViewFactory == NULL )
+ continue;
+
+ if ( pViewFactory->GetOrdinal() == pViewFrame->GetCurViewId() )
+ {
+ nViewDataIndex = i;
+ break;
+ }
+ }
+ if ( nViewDataIndex < nCount )
+ {
+ Sequence< PropertyValue > aViewData;
+ OSL_VERIFY( xViewData->getByIndex( nViewDataIndex ) >>= aViewData );
+ if ( aViewData.getLength() > 0 )
+ m_pData->m_pViewShell->ReadUserDataSequence( aViewData, TRUE );
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+ }
+ }
+
+ // invalidate slot corresponding to the view shell
+ const sal_uInt16 nViewNo = m_pData->m_pViewShell->GetObjectShell()->GetFactory().GetViewNo_Impl( pViewFrame->GetCurViewId(), USHRT_MAX );
+ DBG_ASSERT( nViewNo != USHRT_MAX, "view shell id not found" );
+ if ( nViewNo != USHRT_MAX )
+ pViewFrame->GetBindings().Invalidate( nViewNo + SID_VIEWSHELL0 );
+}
+
+//=============================================================================
+css::uno::Reference< css::frame::XTitle > SfxBaseController::impl_getTitleHelper ()
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ if ( ! m_pData->m_xTitleHelper.is ())
+ {
+ css::uno::Reference< css::frame::XModel > xModel = getModel ();
+ css::uno::Reference< css::frame::XUntitledNumbers > xUntitledProvider(xModel , css::uno::UNO_QUERY );
+ css::uno::Reference< css::frame::XController > xThis (static_cast< css::frame::XController* >(this), css::uno::UNO_QUERY_THROW);
+
+ ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(::comphelper::getProcessServiceFactory());
+ m_pData->m_xTitleHelper = css::uno::Reference< css::frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
+
+ pHelper->setOwner (xThis );
+ pHelper->connectWithUntitledNumbers (xUntitledProvider);
+ }
+
+ return m_pData->m_xTitleHelper;
+}
+
+//=============================================================================
+// css::frame::XTitle
+::rtl::OUString SAL_CALL SfxBaseController::getTitle()
+ throw (css::uno::RuntimeException)
+{
+ return impl_getTitleHelper()->getTitle ();
+}
+
+//=============================================================================
+// css::frame::XTitle
+void SAL_CALL SfxBaseController::setTitle(const ::rtl::OUString& sTitle)
+ throw (css::uno::RuntimeException)
+{
+ impl_getTitleHelper()->setTitle (sTitle);
+}
+
+//=============================================================================
+// css::frame::XTitleChangeBroadcaster
+void SAL_CALL SfxBaseController::addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
+ throw (css::uno::RuntimeException)
+{
+ css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
+ if (xBroadcaster.is ())
+ xBroadcaster->addTitleChangeListener (xListener);
+}
+
+//=============================================================================
+// css::frame::XTitleChangeBroadcaster
+void SAL_CALL SfxBaseController::removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
+ throw (css::uno::RuntimeException)
+{
+ css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
+ if (xBroadcaster.is ())
+ xBroadcaster->removeTitleChangeListener (xListener);
+}
diff --git a/sfx2/source/view/userinputinterception.cxx b/sfx2/source/view/userinputinterception.cxx
new file mode 100644
index 000000000000..ad910a944e0f
--- /dev/null
+++ b/sfx2/source/view/userinputinterception.cxx
@@ -0,0 +1,278 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ***********************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "sfx2/userinputinterception.hxx"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/awt/MouseButton.hpp>
+#include <com/sun/star/awt/KeyModifier.hpp>
+/** === end UNO includes === **/
+
+#include <cppuhelper/interfacecontainer.hxx>
+#include <cppuhelper/weak.hxx>
+#include <vcl/event.hxx>
+#include <vcl/window.hxx>
+
+//........................................................................
+namespace sfx2
+{
+//........................................................................
+
+ /** === begin UNO using === **/
+ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::uno::XInterface;
+ using ::com::sun::star::uno::UNO_QUERY;
+ using ::com::sun::star::uno::UNO_QUERY_THROW;
+ using ::com::sun::star::uno::UNO_SET_THROW;
+ using ::com::sun::star::uno::Exception;
+ using ::com::sun::star::uno::RuntimeException;
+ using ::com::sun::star::uno::Any;
+ using ::com::sun::star::uno::makeAny;
+ using ::com::sun::star::awt::MouseEvent;
+ using ::com::sun::star::awt::KeyEvent;
+ using ::com::sun::star::awt::InputEvent;
+ using ::com::sun::star::awt::XKeyHandler;
+ using ::com::sun::star::awt::XMouseClickHandler;
+ using ::com::sun::star::lang::DisposedException;
+ /** === end UNO using === **/
+ namespace MouseButton = ::com::sun::star::awt::MouseButton;
+ namespace KeyModifier = ::com::sun::star::awt::KeyModifier;
+
+ struct UserInputInterception_Data
+ {
+ public:
+ ::cppu::OWeakObject& m_rControllerImpl;
+ ::cppu::OInterfaceContainerHelper m_aKeyHandlers;
+ ::cppu::OInterfaceContainerHelper m_aMouseClickHandlers;
+
+ public:
+ UserInputInterception_Data( ::cppu::OWeakObject& _rControllerImpl, ::osl::Mutex& _rMutex )
+ :m_rControllerImpl( _rControllerImpl )
+ ,m_aKeyHandlers( _rMutex )
+ ,m_aMouseClickHandlers( _rMutex )
+ {
+ }
+ };
+
+ namespace
+ {
+ template< class VLCEVENT >
+ void lcl_initModifiers( InputEvent& _rEvent, const VLCEVENT& _rVclEvent )
+ {
+ _rEvent.Modifiers = 0;
+
+ if ( _rVclEvent.IsShift() )
+ _rEvent.Modifiers |= KeyModifier::SHIFT;
+ if ( _rVclEvent.IsMod1() )
+ _rEvent.Modifiers |= KeyModifier::MOD1;
+ if ( _rVclEvent.IsMod2() )
+ _rEvent.Modifiers |= KeyModifier::MOD2;
+ if ( _rVclEvent.IsMod3() )
+ _rEvent.Modifiers |= KeyModifier::MOD3;
+ }
+
+ void lcl_initKeyEvent( KeyEvent& rEvent, const ::KeyEvent& rEvt )
+ {
+ lcl_initModifiers( rEvent, rEvt.GetKeyCode() );
+
+ rEvent.KeyCode = rEvt.GetKeyCode().GetCode();
+ rEvent.KeyChar = rEvt.GetCharCode();
+ rEvent.KeyFunc = sal::static_int_cast< sal_Int16 >( rEvt.GetKeyCode().GetFunction());
+ }
+
+ void lcl_initMouseEvent( MouseEvent& rEvent, const ::MouseEvent& rEvt )
+ {
+ lcl_initModifiers( rEvent, rEvt );
+
+ rEvent.Buttons = 0;
+ if ( rEvt.IsLeft() )
+ rEvent.Buttons |= MouseButton::LEFT;
+ if ( rEvt.IsRight() )
+ rEvent.Buttons |= MouseButton::RIGHT;
+ if ( rEvt.IsMiddle() )
+ rEvent.Buttons |= MouseButton::MIDDLE;
+
+ rEvent.X = rEvt.GetPosPixel().X();
+ rEvent.Y = rEvt.GetPosPixel().Y();
+ rEvent.ClickCount = rEvt.GetClicks();
+ rEvent.PopupTrigger = sal_False;
+ }
+
+ }
+
+ //====================================================================
+ //= UserInputInterception
+ //====================================================================
+ //--------------------------------------------------------------------
+ UserInputInterception::UserInputInterception( ::cppu::OWeakObject& _rControllerImpl, ::osl::Mutex& _rMutex )
+ :m_pData( new UserInputInterception_Data( _rControllerImpl, _rMutex ) )
+ {
+ }
+
+ //--------------------------------------------------------------------
+ UserInputInterception::~UserInputInterception()
+ {
+ }
+
+ //--------------------------------------------------------------------
+ void UserInputInterception::addKeyHandler( const Reference< XKeyHandler >& _rxHandler ) throw (RuntimeException)
+ {
+ if ( _rxHandler.is() )
+ m_pData->m_aKeyHandlers.addInterface( _rxHandler );
+ }
+
+ //--------------------------------------------------------------------
+ void UserInputInterception::removeKeyHandler( const Reference< XKeyHandler >& _rxHandler ) throw (RuntimeException)
+ {
+ m_pData->m_aKeyHandlers.removeInterface( _rxHandler );
+ }
+
+ //--------------------------------------------------------------------
+ void UserInputInterception::addMouseClickHandler( const Reference< XMouseClickHandler >& _rxHandler ) throw (RuntimeException)
+ {
+ if ( _rxHandler.is() )
+ m_pData->m_aMouseClickHandlers.addInterface( _rxHandler );
+ }
+
+ //--------------------------------------------------------------------
+ void UserInputInterception::removeMouseClickHandler( const Reference< XMouseClickHandler >& _rxHandler ) throw (RuntimeException)
+ {
+ m_pData->m_aMouseClickHandlers.removeInterface( _rxHandler );
+ }
+
+ //--------------------------------------------------------------------
+ bool UserInputInterception::hasKeyHandlers() const
+ {
+ return m_pData->m_aKeyHandlers.getLength() > 0;
+ }
+
+ //--------------------------------------------------------------------
+ bool UserInputInterception::hasMouseClickListeners() const
+ {
+ return m_pData->m_aMouseClickHandlers.getLength() > 0;
+ }
+
+ //--------------------------------------------------------------------
+ bool UserInputInterception::handleNotifyEvent( const NotifyEvent& _rEvent )
+ {
+ Reference < XInterface > xHoldAlive( m_pData->m_rControllerImpl );
+
+ USHORT nType = _rEvent.GetType();
+ bool bHandled = false;
+
+ switch ( nType )
+ {
+ case EVENT_KEYINPUT:
+ case EVENT_KEYUP:
+ {
+ KeyEvent aEvent;
+ lcl_initKeyEvent( aEvent, *_rEvent.GetKeyEvent() );
+ if ( _rEvent.GetWindow() )
+ aEvent.Source = _rEvent.GetWindow()->GetComponentInterface();
+
+ ::cppu::OInterfaceIteratorHelper aIterator( m_pData->m_aKeyHandlers );
+ while ( aIterator.hasMoreElements() )
+ {
+ Reference< XKeyHandler > xHandler( static_cast< XKeyHandler* >( aIterator.next() ) );
+ if ( !xHandler.is() )
+ continue;
+
+ try
+ {
+ if ( nType == EVENT_KEYINPUT )
+ bHandled = xHandler->keyPressed( aEvent );
+ else
+ bHandled = xHandler->keyReleased( aEvent );
+ }
+ catch( const DisposedException& e )
+ {
+ if ( e.Context == xHandler )
+ aIterator.remove();
+ }
+ catch( const RuntimeException& )
+ {
+ throw;
+ }
+ catch( const Exception& )
+ {
+ }
+ }
+ }
+ break;
+
+ case EVENT_MOUSEBUTTONDOWN:
+ case EVENT_MOUSEBUTTONUP:
+ {
+ MouseEvent aEvent;
+ lcl_initMouseEvent( aEvent, *_rEvent.GetMouseEvent() );
+ if ( _rEvent.GetWindow() )
+ aEvent.Source = _rEvent.GetWindow()->GetComponentInterface();
+
+ ::cppu::OInterfaceIteratorHelper aIterator( m_pData->m_aMouseClickHandlers );
+ while ( aIterator.hasMoreElements() )
+ {
+ Reference< XMouseClickHandler > xHandler( static_cast< XMouseClickHandler* >( aIterator.next() ) );
+ if ( !xHandler.is() )
+ continue;
+
+ try
+ {
+ if ( nType == EVENT_MOUSEBUTTONDOWN )
+ bHandled = xHandler->mousePressed( aEvent );
+ else
+ bHandled = xHandler->mouseReleased( aEvent );
+ }
+ catch( const DisposedException& e )
+ {
+ if ( e.Context == xHandler )
+ aIterator.remove();
+ }
+ catch( const RuntimeException& )
+ {
+ throw;
+ }
+ catch( const Exception& )
+ {
+ }
+ }
+ }
+ break;
+
+ default:
+ OSL_ENSURE( false, "UserInputInterception::handleNotifyEvent: illegal event type!" );
+ break;
+ }
+
+ return bHandled;
+ }
+
+//........................................................................
+} // namespace sfx2
+//........................................................................
diff --git a/sfx2/source/view/view.hrc b/sfx2/source/view/view.hrc
new file mode 100644
index 000000000000..3dce1ec795bb
--- /dev/null
+++ b/sfx2/source/view/view.hrc
@@ -0,0 +1,120 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _SFX_VIEW_HRC
+#define _SFX_VIEW_HRC
+
+#include <sfx2/sfx.hrc>
+
+// #defines *****************************************************************
+
+#define STR_NODEFPRINTER (RID_SFX_VIEW_START+ 0)
+#define STR_PRINTER_NOTAVAIL (RID_SFX_VIEW_START+ 1)
+
+
+#define STR_PRINT_OPTIONS (RID_SFX_VIEW_START+ 6)
+#define STR_PRINT_OPTIONS_TITLE (RID_SFX_VIEW_START+ 7)
+#define STR_ERROR_PRINTER_BUSY (RID_SFX_VIEW_START+ 8)
+#define STR_NOSTARTPRINTER (RID_SFX_VIEW_START+ 9)
+#define STR_PRINTING (RID_SFX_VIEW_START+10)
+
+#define DLG_PRINTMONITOR (RID_SFX_VIEW_START)
+#define FT_DOCNAME 1
+#define FT_PRINTING 2
+#define FT_PRINTER 3
+#define FT_PRINTINFO 4
+#define PB_CANCELPRNMON 5
+#define STR_FT_PREPARATION 6
+#define STR_PAGE (RID_SFX_VIEW_START+20)
+#define STR_ERROR_PRINT (RID_SFX_VIEW_START+21)
+#define STR_PRINT_NEWORI (RID_SFX_VIEW_START+22)
+#define STR_PRINT_NEWSIZE (RID_SFX_VIEW_START+23)
+#define STR_PRINT_NEWORISIZE (RID_SFX_VIEW_START+24)
+
+#define STR_PREVIEW_DOCINFO (RID_SFX_VIEW_START+25)
+#define STR_PREVIEW_NODOCINFO (RID_SFX_VIEW_START+26)
+
+#define MSG_ERROR_SEND_MAIL (RID_SFX_VIEW_START+31)
+
+#define STR_ERROR_SAVE_TEMPLATE (RID_SFX_VIEW_START+33)
+
+#define MSG_QUERY_OPENASTEMPLATE (RID_SFX_VIEW_START+41)
+#define MSG_CANT_CLOSE (RID_SFX_VIEW_START+42)
+#define MSG_ERROR_NO_WEBBROWSER_FOUND (RID_SFX_VIEW_START+43)
+#define TP_FRAMEPROPERTIES (RID_SFX_VIEW_START+44)
+
+#define FT_FRAMENAME 3
+#define ED_FRAMENAME 4
+#define FT_URL 5
+#define ED_URL 6
+#define BT_FILEOPEN 7
+#define NM_MARGINHEIGHT 8
+#define FT_MARGINHEIGHT 9
+#define NM_MARGINWIDTH 10
+#define FT_MARGINWIDTH 11
+#define GB_MARGIN 12
+#define RB_SCROLLINGON 13
+#define RB_SCROLLINGOFF 14
+#define RB_SCROLLINGAUTO 15
+#define GB_SCROLLING 16
+#define GB_BORDER 17
+#define RB_FRMBORDER_ON 18
+#define RB_FRMBORDER_INHERIT 19
+#define RB_FRMBORDER_OFF 20
+#define CB_MARGINWIDTHDEFAULT 21
+#define CB_MARGINHEIGHTDEFAULT 22
+
+#define GB_WIDTH 23
+#define GB_HEIGHT 24
+#define RB_PIXELWIDTH 25
+#define RB_PERCENTWIDTH 26
+#define RB_RELATIVEWIDTH 27
+#define RB_PIXELHEIGHT 28
+#define RB_PERCENTHEIGHT 29
+#define RB_RELATIVEHEIGHT 30
+#define FT_WIDTHCOMMENT 31
+#define FT_HEIGHTCOMMENT 32
+#define FT_WIDTH 33
+#define NM_WIDTH 34
+#define CB_WIDTHFIXED 35
+#define CB_HEIGHTFIXED 36
+#define FT_HEIGHT 37
+#define NM_HEIGHT 38
+
+#define FT_FRAMESPACING 39
+#define NM_FRAMESPACING 40
+#define CB_FRAMESPACING_INHERIT 41
+#define FT_FRAMESPACINGCOLOR 42
+#define ED_FRAMESPACINGCOLOR 43
+#define CB_FRAMESPACINGCOLOR_INHERIT 44
+#define GB_FRAMESET 45
+#define FL_SEP_LEFT 46
+#define FL_SEP_RIGHT 47
+
+#define STR_FRAME_FILEDLG (RID_SFX_VIEW_START+46)
+
+#endif
+
diff --git a/sfx2/source/view/view.src b/sfx2/source/view/view.src
new file mode 100644
index 000000000000..b4c09a0677ed
--- /dev/null
+++ b/sfx2/source/view/view.src
@@ -0,0 +1,190 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+ // include ---------------------------------------------------------------
+#include "view.hrc"
+#include <sfx2/sfx.hrc>
+#include "helpid.hrc"
+#include "sfxlocal.hrc"
+
+ // Strings ---------------------------------------------------------------
+String STR_NODEFPRINTER
+{
+ Text [ en-US ] = "No default printer found.\nPlease choose a printer and try again." ;
+};
+String STR_NOSTARTPRINTER
+{
+ Text [ en-US ] = "Could not start printer.\nPlease check your printer configuration." ;
+};
+String STR_PRINTER_NOTAVAIL
+{
+ Text [ en-US ] = "This document has been formatted for the printer $1. The specified printer is not available. \nDo you want to use the standard printer $2 ?" ;
+};
+String STR_PRINT_OPTIONS
+{
+ Text [ en-US ] = "Options..." ;
+};
+String STR_PRINT_OPTIONS_TITLE
+{
+ Text [ en-US ] = "Printer Options" ;
+};
+String STR_ERROR_PRINTER_BUSY
+{
+ Text [ en-US ] = "Printer busy" ;
+};
+String STR_ERROR_PRINT
+{
+ Text [ en-US ] = "Error while printing" ;
+};
+String STR_PRINTING
+{
+ Text [ en-US ] = "Printing" ;
+};
+String STR_PAGE
+{
+ Text [ en-US ] = "Page " ;
+};
+String STR_ERROR_SAVE_TEMPLATE
+{
+ Text [ en-US ] = "Error saving template " ;
+};
+String STR_READONLY
+{
+ Text [ en-US ] = " (read-only)" ;
+};
+String STR_PRINT_NEWORI
+{
+ Text [ en-US ] = "The page size and orientation have been modified.\nWould you like to save the new settings in the\nactive document?" ;
+};
+String STR_PRINT_NEWSIZE
+{
+ Text [ en-US ] = "The page size has been modified.\nShould the new settings be saved\nin the active document?" ;
+};
+String STR_PRINT_NEWORISIZE
+{
+ Text [ en-US ] = "The page size and orientation have been modified.\nWould you like to save the new settings in the\nactive document?" ;
+};
+String STR_PREVIEW_DOCINFO
+{
+ Text [ en-US ] = "<html><body BGCOLOR=\"#c0c0c0\"><font FACE=\"Arial\"><dl><dt><b>Title:</b><dd>$(TITEL)<dt><b>Subject:</b><dd>$(THEME)<dt><b>Keywords:</b><dd>$(KEYWORDS)<dt><b>Description:</b><dd>$(TEXT)</dl></font></body></html>" ;
+};
+String STR_PREVIEW_NODOCINFO
+{
+ Text [ en-US ] = "<HTML><BODY BGCOLOR=\"#c0c0c0\"><BR><BR><P><FONT FACE=\"Arial\"><B>No document properties found.</B></FONT></P></BODY></HTML>" ;
+};
+ // -----------------------------------------------------------------------
+InfoBox MSG_CANT_CLOSE
+{
+ Message [ en-US ] = "The document cannot be closed because a\n print job is being carried out." ;
+};
+ // DLG_PRINTMONITOR ------------------------------------------------------
+
+#define DLG_PRINTMONITOR_TEXT \
+ Text [ en-US ] = "Print Monitor" ; \
+
+ModelessDialog DLG_PRINTMONITOR
+{
+ HelpID = HID_PRINTMONITOR ;
+ OutputSize = TRUE ;
+ SVLook = TRUE ;
+ Hide = TRUE ;
+ Moveable = TRUE;
+ Size = MAP_APPFONT ( 112 , 81 ) ;
+ DLG_PRINTMONITOR_TEXT
+ FixedText FT_DOCNAME
+ {
+ Pos = MAP_APPFONT ( 6 , 6 ) ;
+ Size = MAP_APPFONT ( 100 , 10 ) ;
+ Center = TRUE ;
+ };
+ FixedText FT_PRINTING
+ {
+ Pos = MAP_APPFONT ( 6 , 19 ) ;
+ Size = MAP_APPFONT ( 100 , 10 ) ;
+ Center = TRUE ;
+ Text [ en-US ] = "is being printed on" ;
+ };
+ FixedText FT_PRINTER
+ {
+ Pos = MAP_APPFONT ( 6 , 32 ) ;
+ Size = MAP_APPFONT ( 100 , 10 ) ;
+ Center = TRUE ;
+ };
+ FixedText FT_PRINTINFO
+ {
+ Pos = MAP_APPFONT ( 6 , 45 ) ;
+ Size = MAP_APPFONT ( 100 , 10 ) ;
+ Center = TRUE ;
+ };
+ CancelButton PB_CANCELPRNMON
+ {
+ Pos = MAP_APPFONT ( 31 , 61 ) ;
+ Size = MAP_APPFONT ( 50 , 14 ) ;
+ };
+ String STR_FT_PREPARATION
+ {
+ Text [ en-US ] = "is being prepared for printing";
+ };
+};
+
+ // MSG_ERROR_SEND_MAIL ---------------------------------------------------
+
+InfoBox MSG_ERROR_SEND_MAIL
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message [ en-US ] = "An error occurred in sending the message. Possible errors could be a missing user account or a defective setup.\nPlease check the %PRODUCTNAME settings or your e-mail program settings." ;
+};
+
+ // QueryBoxen ------------------------------------------------------------
+QueryBox MSG_QUERY_OPENASTEMPLATE
+{
+ Buttons = WB_YES_NO ;
+ DefButton = WB_DEF_NO ;
+ Message [ en-US ] = "This document cannot be edited, possibly due to missing access rights. Do you want to edit a copy of the document?" ;
+};
+String STR_REPAIREDDOCUMENT
+{
+ Text [ en-US ] = " (repaired document)" ;
+};
+
+ErrorBox MSG_ERROR_NO_WEBBROWSER_FOUND
+{
+ BUTTONS = WB_OK ;
+ DEFBUTTON = WB_DEF_OK ;
+ Message[ en-US ] = "%PRODUCTNAME could not find a web browser on your system. Please check your Desktop Preferences or install a web browser (for example, Mozilla) in the default location requested during the browser installation." ;
+};
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sfx2/source/view/viewfac.cxx b/sfx2/source/view/viewfac.cxx
new file mode 100644
index 000000000000..3eed678420dd
--- /dev/null
+++ b/sfx2/source/view/viewfac.cxx
@@ -0,0 +1,88 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+// INCLUDE ---------------------------------------------------------------
+
+#include <sfx2/app.hxx>
+#include "sfx2/viewfac.hxx"
+#include <rtl/ustrbuf.hxx>
+
+// STATIC DATA -----------------------------------------------------------
+
+DBG_NAME(SfxViewFactory)
+
+SfxViewShell *SfxViewFactory::CreateInstance(SfxViewFrame *pFrame, SfxViewShell *pOldSh )
+{
+ DBG_CHKTHIS(SfxViewFactory, 0);
+ return (*fnCreate)(pFrame, pOldSh);
+}
+
+void SfxViewFactory::InitFactory()
+{
+ DBG_CHKTHIS(SfxViewFactory, 0);
+ (*fnInit)();
+}
+
+String SfxViewFactory::GetLegacyViewName() const
+{
+ ::rtl::OUStringBuffer aViewName;
+ aViewName.appendAscii( "view" );
+ aViewName.append( sal_Int32( GetOrdinal() ) );
+ return aViewName.makeStringAndClear();
+}
+
+String SfxViewFactory::GetAPIViewName() const
+{
+ if ( m_sViewName.Len() > 0 )
+ return m_sViewName;
+
+ if ( GetOrdinal() == 0 )
+ return String::CreateFromAscii( "Default" );
+
+ return GetLegacyViewName();
+}
+
+// CTOR / DTOR -----------------------------------------------------------
+
+SfxViewFactory::SfxViewFactory( SfxViewCtor fnC, SfxViewInit fnI,
+ USHORT nOrdinal, const sal_Char* asciiViewName ):
+ fnCreate(fnC),
+ fnInit(fnI),
+ nOrd(nOrdinal),
+ m_sViewName( String::CreateFromAscii( asciiViewName ) )
+{
+ DBG_CTOR(SfxViewFactory, 0);
+}
+
+SfxViewFactory::~SfxViewFactory()
+{
+ DBG_DTOR(SfxViewFactory, 0);
+}
+
+
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
new file mode 100644
index 000000000000..dbadbc54ebd4
--- /dev/null
+++ b/sfx2/source/view/viewfrm.cxx
@@ -0,0 +1,3599 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <stdio.h>
+
+#include <sfx2/viewfrm.hxx>
+#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/frame/XLoadable.hpp>
+#include <com/sun/star/frame/XLayoutManager.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+
+#include <toolkit/unohlp.hxx>
+#include <vcl/splitwin.hxx>
+#include <unotools/moduleoptions.hxx>
+#include <svl/intitem.hxx>
+#include <svl/visitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/slstitm.hxx>
+#include <svl/whiter.hxx>
+#include <svl/undo.hxx>
+#include <vcl/msgbox.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+#include <tools/diagnose_ex.h>
+#include <com/sun/star/container/XIndexAccess.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <com/sun/star/frame/FrameSearchFlag.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XFrames.hpp>
+#include <com/sun/star/frame/XFramesSupplier.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/frame/XModel2.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
+#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/document/UpdateDocMode.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/uri/XUriReferenceFactory.hpp>
+#include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/document/XViewDataSupplier.hpp>
+#include <com/sun/star/container/XIndexContainer.hpp>
+#include <rtl/ustrbuf.hxx>
+
+#include <unotools/localfilehelper.hxx>
+#include <unotools/ucbhelper.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/componentcontext.hxx>
+#include <comphelper/namedvaluecollection.hxx>
+#include <comphelper/configurationhelper.hxx>
+#include <comphelper/docpasswordrequest.hxx>
+#include <comphelper/docpasswordhelper.hxx>
+
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/ucb/XContent.hpp>
+
+#include <basic/basmgr.hxx>
+#include <basic/sbmod.hxx>
+#include <basic/sbmeth.hxx>
+#include <basic/sbx.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <svtools/asynclink.hxx>
+#include <svl/sharecontrolfile.hxx>
+#include <svtools/svtools.hrc>
+#include <svtools/svtdata.hxx>
+#include <framework/framelistanalyzer.hxx>
+
+#include <boost/optional.hpp>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::lang;
+using ::com::sun::star::awt::XWindow;
+using ::com::sun::star::beans::PropertyValue;
+using ::com::sun::star::document::XViewDataSupplier;
+using ::com::sun::star::container::XIndexContainer;
+namespace css = ::com::sun::star;
+
+// wg. ViewFrame::Current
+#include "appdata.hxx"
+#include <sfx2/taskpane.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/objface.hxx>
+#include "openflag.hxx"
+#include "objshimp.hxx"
+#include <sfx2/viewsh.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
+#include "arrdecl.hxx"
+#include "sfxtypes.hxx"
+#include <sfx2/request.hxx>
+#include <sfx2/docfac.hxx>
+#include <sfx2/ipclient.hxx>
+#include "sfx2/sfxresid.hxx"
+#include "appbas.hxx"
+#include <sfx2/objitem.hxx>
+#include "sfx2/viewfac.hxx"
+#include <sfx2/event.hxx>
+#include "fltfnc.hxx"
+#include <sfx2/docfile.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/viewfrm.hxx>
+#include "viewimp.hxx"
+#include <sfx2/sfxbasecontroller.hxx>
+#include <sfx2/sfx.hrc>
+#include "view.hrc"
+#include <sfx2/frmdescr.hxx>
+#include <sfx2/sfxuno.hxx>
+#include <sfx2/progress.hxx>
+#include "workwin.hxx"
+#include "helper.hxx"
+#include "macro.hxx"
+#include "sfx2/minfitem.hxx"
+#include "../appl/app.hrc"
+#include "impviewframe.hxx"
+
+//-------------------------------------------------------------------------
+DBG_NAME(SfxViewFrame)
+
+#define SfxViewFrame
+#include "sfxslots.hxx"
+#undef SfxViewFrame
+
+//-------------------------------------------------------------------------
+
+SFX_IMPL_INTERFACE(SfxViewFrame,SfxShell,SfxResId(0))
+{
+ SFX_CHILDWINDOW_REGISTRATION( SID_BROWSER );
+ SFX_CHILDWINDOW_REGISTRATION( SID_RECORDING_FLOATWINDOW );
+
+ SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_FULLSCREEN | SFX_VISIBILITY_FULLSCREEN, SfxResId(RID_FULLSCREENTOOLBOX) );
+ SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_STANDARD, SfxResId(RID_ENVTOOLBOX) );
+}
+
+TYPEINIT2(SfxViewFrame,SfxShell,SfxListener);
+TYPEINIT1(SfxViewFrameItem, SfxPoolItem);
+
+//=========================================================================
+
+//-------------------------------------------------------------------------
+namespace
+{
+ bool moduleHasToolPanels( SfxViewFrame_Impl& i_rViewFrameImpl )
+ {
+ if ( !i_rViewFrameImpl.aHasToolPanels )
+ {
+ i_rViewFrameImpl.aHasToolPanels.reset( ::sfx2::ModuleTaskPane::ModuleHasToolPanels(
+ i_rViewFrameImpl.rFrame.GetFrameInterface() ) );
+ }
+ return *i_rViewFrameImpl.aHasToolPanels;
+ }
+}
+
+//-------------------------------------------------------------------------
+static sal_Bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const ::rtl::OUString& aPath, const SfxFilter* pFilter, sal_uInt32 nPasswordHash, const uno::Sequence< beans::PropertyValue > aInfo )
+{
+ // TODO/LATER: In future the info should replace the direct hash completely
+ sal_Bool bResult = ( !nPasswordHash && !aInfo.getLength() );
+
+ OSL_ENSURE( pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ), "PasswordToModify feature is active for a filter that does not support it!" );
+
+ if ( pFilter && xHandler.is() )
+ {
+ sal_Bool bCancel = sal_False;
+ sal_Bool bFirstTime = sal_True;
+
+ while ( !bResult && !bCancel )
+ {
+ sal_Bool bMSType = !pFilter->IsOwnFormat();
+
+ ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest(
+ new ::comphelper::DocPasswordRequest(
+ bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD,
+ bFirstTime ? ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER : ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER,
+ aPath,
+ sal_True ) );
+
+ uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
+ xHandler->handle( rRequest );
+
+ if ( pPasswordRequest->isPassword() )
+ {
+ if ( aInfo.getLength() )
+ {
+ bResult = ::comphelper::DocPasswordHelper::IsModifyPasswordCorrect( pPasswordRequest->getPasswordToModify(), aInfo );
+ }
+ else
+ {
+ // the binary format
+ bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pFilter->GetServiceName() ) ) == nPasswordHash );
+ }
+ }
+ else
+ bCancel = sal_True;
+
+ bFirstTime = sal_False;
+ }
+ }
+
+ return bResult;
+}
+
+//-------------------------------------------------------------------------
+void SfxViewFrame::SetDowning_Impl()
+{
+ pImp->bIsDowning = sal_True;
+}
+
+//-------------------------------------------------------------------------
+sal_Bool SfxViewFrame::IsDowning_Impl() const
+{
+ return pImp->bIsDowning;
+}
+
+
+//--------------------------------------------------------------------
+class SfxViewNotificatedFrameList_Impl :
+ public SfxListener, public SfxViewFrameArr_Impl
+{
+public:
+
+ void InsertViewFrame( SfxViewFrame* pFrame )
+ {
+ StartListening( *pFrame );
+ C40_INSERT( SfxViewFrame, pFrame, Count() );
+ }
+ void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
+};
+
+//-------------------------------------------------------------------------
+void SfxViewNotificatedFrameList_Impl::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
+{
+ if ( rHint.IsA(TYPE(SfxSimpleHint)) )
+ {
+ switch( ( (SfxSimpleHint&) rHint ).GetId() )
+ {
+ case SFX_HINT_DYING:
+ SfxViewFrame* pFrame = (SfxViewFrame*) &rBC;
+ if( pFrame )
+ {
+ sal_uInt16 nPos = C40_GETPOS( SfxViewFrame, pFrame );
+ if( nPos != USHRT_MAX )
+ Remove( nPos );
+ }
+ break;
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+long ReloadDecouple_Impl( void* pObj, void* pArg )
+{
+ ((SfxViewFrame*) pObj)->ExecReload_Impl( *(SfxRequest*)pArg );
+ return 0;
+}
+
+void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq, sal_Bool bAsync )
+{
+ if( bAsync )
+ {
+ if( !pImp->pReloader )
+ pImp->pReloader = new svtools::AsynchronLink(
+ Link( this, ReloadDecouple_Impl ) );
+ pImp->pReloader->Call( new SfxRequest( rReq ) );
+ }
+ else ExecReload_Impl( rReq );
+}
+
+void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
+{
+ SfxFrame *pParent = GetFrame().GetParentFrame();
+ if ( rReq.GetSlot() == SID_RELOAD )
+ {
+ // Bei CTRL-Reload den aktiven Frame reloaden
+ SfxViewFrame* pActFrame = this;
+ while ( pActFrame )
+ pActFrame = pActFrame->GetActiveChildFrame_Impl();
+
+ if ( pActFrame )
+ {
+ sal_uInt16 nModifier = rReq.GetModifier();
+ if ( nModifier & KEY_MOD1 )
+ {
+ pActFrame->ExecReload_Impl( rReq );
+ return;
+ }
+ }
+
+ // Wenn nur ein Reload der Graphiken eines oder mehrerer ChildFrames
+ // gemacht werden soll
+ SfxFrame& rFrame = GetFrame();
+ if ( pParent == &rFrame && rFrame.GetChildFrameCount() )
+ {
+ sal_Bool bReloadAvailable = sal_False;
+ SfxFrameIterator aIter( rFrame, sal_False );
+ SfxFrame *pChild = aIter.FirstFrame();
+ while ( pChild )
+ {
+ SfxFrame *pNext = aIter.NextFrame( *pChild );
+ SfxObjectShell *pShell = pChild->GetCurrentDocument();
+ if( pShell && pShell->Get_Impl()->bReloadAvailable )
+ {
+ bReloadAvailable = sal_True;
+ pChild->GetCurrentViewFrame()->ExecuteSlot( rReq );
+ }
+ pChild = pNext;
+ }
+
+ // Der TopLevel-Frame selbst het keine Graphiken!
+ if ( bReloadAvailable )
+ return;
+ }
+ }
+ else
+ {
+ // Bei CTRL-Edit den TopFrame bearbeiten
+ sal_uInt16 nModifier = rReq.GetModifier();
+
+ if ( ( nModifier & KEY_MOD1 ) && pParent )
+ {
+ SfxViewFrame *pTop = GetTopViewFrame();
+ pTop->ExecReload_Impl( rReq );
+ return;
+ }
+ }
+
+ SfxObjectShell* pSh = GetObjectShell();
+ switch ( rReq.GetSlot() )
+ {
+ case SID_EDITDOC:
+ {
+ if ( GetFrame().HasComponent() )
+ break;
+
+ // Wg. Doppeltbelegung in Toolboxen (mit/ohne Ctrl) ist es auch
+ // m"oglich, da\s der Slot zwar enabled ist, aber Ctrl-Click
+ // trotzdem nicht geht!
+ if( !pSh || !pSh->HasName() || !(pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ))
+ break;
+
+ SfxMedium* pMed = pSh->GetMedium();
+
+ SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_VIEWONLY, sal_False );
+ if ( pItem && pItem->GetValue() )
+ {
+ SfxApplication* pApp = SFX_APP();
+ SfxAllItemSet aSet( pApp->GetPool() );
+ aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetURLObject().GetMainURL(INetURLObject::NO_DECODE) ) );
+ aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
+ aSet.Put( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_blank") ) );
+ SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False );
+ if ( pReferer )
+ aSet.Put( *pReferer );
+ SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pVersionItem, SfxInt16Item, SID_VERSION, sal_False );
+ if ( pVersionItem )
+ aSet.Put( *pVersionItem );
+
+ if( pMed->GetFilter() )
+ {
+ aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
+ SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
+ if ( pOptions )
+ aSet.Put( *pOptions );
+ }
+
+ GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
+ return;
+ }
+
+ sal_uInt16 nOpenMode;
+ sal_Bool bNeedsReload = sal_False;
+ if ( !pSh->IsReadOnly() )
+ {
+ // Speichern und Readonly Reloaden
+ if( pSh->IsModified() )
+ {
+ if ( pSh->PrepareClose() )
+ {
+ // the storing could let the medium be changed
+ pMed = pSh->GetMedium();
+ bNeedsReload = sal_True;
+ }
+ else
+ {
+ rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) );
+ return;
+ }
+ }
+ nOpenMode = SFX_STREAM_READONLY;
+ }
+ else
+ {
+ if ( pSh->IsReadOnlyMedium()
+ && ( pSh->GetModifyPasswordHash() || pSh->GetModifyPasswordInfo().getLength() )
+ && !pSh->IsModifyPasswordEntered() )
+ {
+ ::rtl::OUString aDocumentName = INetURLObject( pMed->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
+ if( !AskPasswordToModify_Impl( pMed->GetInteractionHandler(), aDocumentName, pMed->GetOrigFilter(), pSh->GetModifyPasswordHash(), pSh->GetModifyPasswordInfo() ) )
+ {
+ // this is a read-only document, if it has "Password to modify"
+ // the user should enter password before he can edit the document
+ rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) );
+ return;
+ }
+
+ pSh->SetModifyPasswordEntered();
+ }
+
+ nOpenMode = SFX_STREAM_READWRITE;
+ pSh->SetReadOnlyUI( sal_False );
+
+ // if only the view was in the readonly mode then there is no need to do the reload
+ if ( !pSh->IsReadOnly() )
+ return;
+ }
+
+ // Parameter auswerten
+ // sal_Bool bReload = sal_True;
+ if ( rReq.IsAPI() )
+ {
+ // per API steuern ob r/w oder r/o
+ SFX_REQUEST_ARG(rReq, pEditItem, SfxBoolItem, SID_EDITDOC, sal_False);
+ if ( pEditItem )
+ nOpenMode = pEditItem->GetValue() ? SFX_STREAM_READWRITE : SFX_STREAM_READONLY;
+ }
+
+ // doing
+
+ String aTemp;
+ utl::LocalFileHelper::ConvertPhysicalNameToURL( pMed->GetPhysicalName(), aTemp );
+ INetURLObject aPhysObj( aTemp );
+ SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(),
+ pVersionItem, SfxInt16Item, SID_VERSION, sal_False );
+
+ INetURLObject aMedObj( pMed->GetName() );
+
+ // the logic below is following, if the document seems not to need to be reloaded and the physical name is different
+ // to the logical one, then on file system it can be checked that the copy is still newer than the original and no document reload is required
+ if ( ( !bNeedsReload && ( (aMedObj.GetProtocol() == INET_PROT_FILE &&
+ aMedObj.getFSysPath(INetURLObject::FSYS_DETECT) != aPhysObj.getFSysPath(INetURLObject::FSYS_DETECT) &&
+ !::utl::UCBContentHelper::IsYounger( aMedObj.GetMainURL( INetURLObject::NO_DECODE ), aPhysObj.GetMainURL( INetURLObject::NO_DECODE ) ))
+ || pMed->IsRemote() ) )
+ || pVersionItem )
+ {
+ sal_Bool bOK = sal_False;
+ if ( !pVersionItem )
+ {
+ sal_Bool bHasStorage = pMed->HasStorage_Impl();
+ // switching edit mode could be possible without reload
+ if ( bHasStorage && pMed->GetStorage() == pSh->GetStorage() )
+ {
+ // TODO/LATER: faster creation of copy
+ if ( !pSh->ConnectTmpStorage_Impl( pMed->GetStorage(), pMed ) )
+ return;
+ }
+
+ pMed->CloseAndRelease();
+ pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) );
+ pMed->SetOpenMode( nOpenMode, pMed->IsDirect() );
+
+ pMed->CompleteReOpen();
+ if ( nOpenMode & STREAM_WRITE )
+ pMed->LockOrigFileOnDemand( sal_False, sal_True );
+
+ // LockOrigFileOnDemand might set the readonly flag itself, it should be set back
+ pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) );
+
+ if ( !pMed->GetErrorCode() )
+ bOK = sal_True;
+ }
+
+ if( !bOK )
+ {
+ ErrCode nErr = pMed->GetErrorCode();
+ if ( pVersionItem )
+ nErr = ERRCODE_IO_ACCESSDENIED;
+ else
+ {
+ pMed->ResetError();
+ pMed->SetOpenMode( SFX_STREAM_READONLY, pMed->IsDirect() );
+ pMed->ReOpen();
+ pSh->DoSaveCompleted( pMed );
+ }
+
+ // r/o-Doc kann nicht in Editmode geschaltet werden?
+ rReq.Done( sal_False );
+
+ if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() )
+ {
+ // dem ::com::sun::star::sdbcx::User anbieten, als Vorlage zu oeffnen
+ QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) );
+ if ( RET_YES == aBox.Execute() )
+ {
+ SfxApplication* pApp = SFX_APP();
+ SfxAllItemSet aSet( pApp->GetPool() );
+ aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
+ SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False );
+ if ( pReferer )
+ aSet.Put( *pReferer );
+ aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
+ if ( pVersionItem )
+ aSet.Put( *pVersionItem );
+
+ if( pMed->GetFilter() )
+ {
+ aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
+ SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions,
+ SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
+ if ( pOptions )
+ aSet.Put( *pOptions );
+ }
+
+ GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
+ return;
+ }
+ else
+ nErr = 0;
+ }
+
+ ErrorHandler::HandleError( nErr );
+ rReq.SetReturnValue(
+ SfxBoolItem( rReq.GetSlot(), sal_False ) );
+ return;
+ }
+ else
+ {
+ pSh->DoSaveCompleted( pMed );
+ pSh->Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
+ rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_True ) );
+ rReq.Done( sal_True );
+ // if( nOpenMode == SFX_STREAM_READONLY )
+ // pMed->Close();
+ return;
+ }
+ }
+
+ rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, sal_True) );
+ rReq.AppendItem( SfxBoolItem( SID_SILENT, sal_True ));
+ }
+
+ case SID_RELOAD:
+ {
+ // Wg. Doppeltbelegung in Toolboxen (mit/ohne Ctrl) ist es auch
+ // m"oglich, da\s der Slot zwar enabled ist, aber Ctrl-Click
+ // trotzdem nicht geht!
+ if ( !pSh || !pSh->CanReload_Impl() )
+ break;
+ SfxApplication* pApp = SFX_APP();
+ SFX_REQUEST_ARG(rReq, pForceReloadItem, SfxBoolItem,
+ SID_FORCERELOAD, sal_False);
+ if( pForceReloadItem && !pForceReloadItem->GetValue() &&
+ !pSh->GetMedium()->IsExpired() )
+ return;
+ if( pImp->bReloading || pSh->IsInModalMode() )
+ return;
+
+ // AutoLoad ist ggf. verboten
+ SFX_REQUEST_ARG(rReq, pAutoLoadItem, SfxBoolItem, SID_AUTOLOAD, sal_False);
+ if ( pAutoLoadItem && pAutoLoadItem->GetValue() &&
+ GetFrame().IsAutoLoadLocked_Impl() )
+ return;
+
+ SfxObjectShellLock xOldObj( pSh );
+ pImp->bReloading = sal_True;
+ SFX_REQUEST_ARG(rReq, pURLItem, SfxStringItem,
+ SID_FILE_NAME, sal_False);
+ // editierbar "offnen?
+ sal_Bool bForEdit = !pSh->IsReadOnly();
+ if ( rReq.GetSlot() == SID_EDITDOC )
+ bForEdit = !bForEdit;
+
+ // ggf. beim User nachfragen
+ sal_Bool bDo = ( GetViewShell()->PrepareClose() != FALSE );
+ SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
+ if ( bDo && GetFrame().DocIsModified_Impl() &&
+ !rReq.IsAPI() && ( !pSilentItem || !pSilentItem->GetValue() ) )
+ {
+ QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_LASTVERSION) );
+ bDo = ( RET_YES == aBox.Execute() );
+ }
+
+ if ( bDo )
+ {
+ SfxMedium *pMedium = xOldObj->GetMedium();
+
+ // Frameset abziehen, bevor FramesetView evtl. verschwindet
+ String aURL = pURLItem ? pURLItem->GetValue() :
+ pMedium->GetName();
+
+ sal_Bool bHandsOff =
+ ( pMedium->GetURLObject().GetProtocol() == INET_PROT_FILE && !xOldObj->IsDocShared() );
+
+ // bestehende SfxMDIFrames f"ur dieses Doc leeren
+ // eigenes Format oder R/O jetzt editierbar "offnen?
+ SfxObjectShellLock xNewObj;
+
+ // collect the views of the document
+ // TODO: when UNO ViewFactories are available for SFX-based documents, the below code should
+ // be UNOized, too
+ typedef ::std::pair< Reference< XFrame >, USHORT > ViewDescriptor;
+ ::std::list< ViewDescriptor > aViewFrames;
+ SfxViewFrame *pView = GetFirst( xOldObj );
+ while ( pView )
+ {
+ Reference< XFrame > xFrame( pView->GetFrame().GetFrameInterface() );
+ OSL_ENSURE( xFrame.is(), "SfxViewFrame::ExecReload_Impl: no XFrame?!" );
+ aViewFrames.push_back( ViewDescriptor( xFrame, pView->GetCurViewId() ) );
+
+ pView = GetNext( *pView, xOldObj );
+ }
+
+ DELETEZ( xOldObj->Get_Impl()->pReloadTimer );
+
+ SfxItemSet* pNewSet = 0;
+ const SfxFilter *pFilter = pMedium->GetFilter();
+ if( pURLItem )
+ {
+ pNewSet = new SfxAllItemSet( pApp->GetPool() );
+ pNewSet->Put( *pURLItem );
+
+ // Filter Detection
+ SfxMedium aMedium( pURLItem->GetValue(), SFX_STREAM_READWRITE );
+ SfxFilterMatcher().GuessFilter( aMedium, &pFilter );
+ if ( pFilter )
+ pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
+ pNewSet->Put( *aMedium.GetItemSet() );
+ }
+ else
+ {
+ pNewSet = new SfxAllItemSet( *pMedium->GetItemSet() );
+ pNewSet->ClearItem( SID_VIEW_ID );
+ pNewSet->ClearItem( SID_STREAM );
+ pNewSet->ClearItem( SID_INPUTSTREAM );
+ pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pMedium->GetFilter()->GetName() ) );
+
+ // let the current security settings be checked again
+ pNewSet->Put( SfxUInt16Item( SID_MACROEXECMODE, document::MacroExecMode::USE_CONFIG ) );
+
+ if ( rReq.GetSlot() == SID_EDITDOC || !bForEdit )
+ // edit mode is switched or reload of readonly document
+ pNewSet->Put( SfxBoolItem( SID_DOC_READONLY, !bForEdit ) );
+ else
+ // Reload of file opened for writing
+ pNewSet->ClearItem( SID_DOC_READONLY );
+ }
+
+ // Falls eine salvagede Datei vorliegt, nicht nochmals die
+ // OrigURL mitschicken, denn die Tempdate ist nach Reload
+ // ungueltig
+ SFX_ITEMSET_ARG( pNewSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
+ if( pSalvageItem )
+ {
+ aURL = pSalvageItem->GetValue();
+ pNewSet->ClearItem( SID_DOC_SALVAGE );
+ }
+
+ // TODO/LATER: Temporary solution, the SfxMedium must know the original URL as aLogicName
+ // SfxMedium::Transfer_Impl() will be vorbidden then.
+ if ( xOldObj->IsDocShared() )
+ pNewSet->Put( SfxStringItem( SID_FILE_NAME, xOldObj->GetSharedFileURL() ) );
+
+ //pNewMedium = new SfxMedium( aURL, nMode, pMedium->IsDirect(), bUseFilter ? pMedium->GetFilter() : 0, pNewSet );
+ //pNewSet = pNewMedium->GetItemSet();
+ if ( pURLItem )
+ pNewSet->Put( SfxStringItem( SID_REFERER, pMedium->GetName() ) );
+ else
+ pNewSet->Put( SfxStringItem( SID_REFERER, String() ) );
+
+ xOldObj->CancelTransfers();
+
+ // eigentliches Reload
+ //pNewSet->Put( SfxFrameItem ( SID_DOCFRAME, GetFrame() ) );
+
+ if ( pSilentItem && pSilentItem->GetValue() )
+ pNewSet->Put( SfxBoolItem( SID_SILENT, sal_True ) );
+
+ SFX_ITEMSET_ARG(pNewSet, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, FALSE);
+ SFX_ITEMSET_ARG(pNewSet, pMacroExecItem , SfxUInt16Item, SID_MACROEXECMODE , FALSE);
+ SFX_ITEMSET_ARG(pNewSet, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE , FALSE);
+
+ if (!pInteractionItem)
+ {
+ Reference < ::com::sun::star::task::XInteractionHandler > xHdl( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY );
+ if (xHdl.is())
+ pNewSet->Put( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) );
+ }
+
+ if (!pMacroExecItem)
+ pNewSet->Put( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) );
+ if (!pDocTemplateItem)
+ pNewSet->Put( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) );
+
+ xOldObj->SetModified( sal_False );
+ // Altes Dok nicht cachen! Gilt nicht, wenn anderes
+ // Doc geladen wird.
+
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False);
+ SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedReferer, SfxStringItem, SID_REFERER, sal_False);
+
+ sal_Bool bHasStorage = pMedium->HasStorage_Impl();
+ if( bHandsOff )
+ {
+ if ( bHasStorage && pMedium->GetStorage() == xOldObj->GetStorage() )
+ {
+ // TODO/LATER: faster creation of copy
+ if ( !xOldObj->ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
+ return;
+ }
+
+ pMedium->CloseAndRelease();
+ }
+
+ xNewObj = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_STANDARD );
+
+ if ( xOldObj->IsModifyPasswordEntered() )
+ xNewObj->SetModifyPasswordEntered();
+
+ uno::Sequence < beans::PropertyValue > aLoadArgs;
+ TransformItems( SID_OPENDOC, *pNewSet, aLoadArgs );
+ try
+ {
+ uno::Reference < frame::XLoadable > xLoad( xNewObj->GetModel(), uno::UNO_QUERY );
+ xLoad->load( aLoadArgs );
+ }
+ catch ( uno::Exception& )
+ {
+ xNewObj->DoClose();
+ xNewObj = 0;
+ }
+
+ DELETEZ( pNewSet );
+
+ if( !xNewObj.Is() )
+ {
+ if( bHandsOff )
+ {
+ // back to old medium
+ pMedium->ReOpen();
+ pMedium->LockOrigFileOnDemand( sal_False, sal_True );
+
+ xOldObj->DoSaveCompleted( pMedium );
+ }
+
+ // r/o-Doc couldn't be switched to writing mode
+ if ( bForEdit && SID_EDITDOC == rReq.GetSlot() )
+ {
+ // ask user for opening as template
+ QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) );
+ if ( RET_YES == aBox.Execute() )
+ {
+ SfxAllItemSet aSet( pApp->GetPool() );
+ aSet.Put( SfxStringItem( SID_FILE_NAME, pMedium->GetName() ) );
+ aSet.Put( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_blank") ) );
+ if ( pSavedOptions )
+ aSet.Put( *pSavedOptions );
+ if ( pSavedReferer )
+ aSet.Put( *pSavedReferer );
+ aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
+ if( pFilter )
+ aSet.Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetFilterName() ) );
+ GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
+ }
+ }
+ else
+ {
+ // an error handling should be done here?!
+ // if ( !pSilentItem || !pSilentItem->GetValue() )
+ // ErrorHandler::HandleError( nLoadError );
+ }
+ }
+ else
+ {
+ if ( xNewObj->GetModifyPasswordHash() && xNewObj->GetModifyPasswordHash() != xOldObj->GetModifyPasswordHash() )
+ {
+ xNewObj->SetModifyPasswordEntered( sal_False );
+ xNewObj->SetReadOnly();
+ }
+ else if ( rReq.GetSlot() == SID_EDITDOC && bForEdit && !xNewObj->IsReadOnlyMedium() )
+ {
+ // the filter might request setting of the document to readonly state
+ // but in case of SID_EDITDOC it should not happen if the document
+ // can be opened for editing
+ xNewObj->SetReadOnlyUI( sal_False );
+ }
+
+ if ( xNewObj->IsDocShared() )
+ {
+ // the file is shared but the closing can change the sharing control file
+ xOldObj->DoNotCleanShareControlFile();
+ }
+
+ // the Reload and Silent items were only temporary, remove them
+ xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_RELOAD );
+ xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_SILENT );
+ TransformItems( SID_OPENDOC, *xNewObj->GetMedium()->GetItemSet(), aLoadArgs );
+
+ UpdateDocument_Impl();
+
+ try
+ {
+ while ( !aViewFrames.empty() )
+ {
+ LoadViewIntoFrame_Impl( *xNewObj, aViewFrames.front().first, aLoadArgs, aViewFrames.front().second, false );
+ aViewFrames.pop_front();
+ }
+ }
+ catch( const Exception& )
+ {
+ // close the remaining frames
+ // Don't catch exceptions herein, if this fails, then we're left in an indetermined state, and
+ // crashing is better than trying to proceed
+ while ( !aViewFrames.empty() )
+ {
+ Reference< util::XCloseable > xClose( aViewFrames.front().first, UNO_QUERY_THROW );
+ xClose->close( sal_True );
+ aViewFrames.pop_front();
+ }
+ }
+
+ // Propagate document closure.
+ SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ), xOldObj ) );
+ }
+
+ // als erledigt recorden
+ rReq.Done( sal_True );
+ rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_True));
+ return;
+ }
+ else
+ {
+ // als nicht erledigt recorden
+ rReq.Done();
+ rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_False));
+ pImp->bReloading = sal_False;
+ return;
+ }
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+void SfxViewFrame::StateReload_Impl( SfxItemSet& rSet )
+{
+ SfxObjectShell* pSh = GetObjectShell();
+ if ( !pSh )
+ // Ich bin gerade am Reloaden und Yielde so vor mich hin ...
+ return;
+
+ GetFrame().GetParentFrame();
+ SfxWhichIter aIter( rSet );
+ for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() )
+ {
+ if ( GetFrame().HasComponent() )
+ {
+ // Wenn die Komponente es nicht selbst dispatched, dann
+ // macht es auch keinen Sinn!
+ rSet.DisableItem( nWhich );
+ continue;
+ }
+
+ switch ( nWhich )
+ {
+ case SID_EDITDOC:
+ {
+ if ( !pSh || !pSh->HasName() || !( pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
+ || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
+ rSet.DisableItem( SID_EDITDOC );
+ else
+ {
+ SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, sal_False );
+ if ( pItem && !pItem->GetValue() )
+ rSet.DisableItem( SID_EDITDOC );
+ else
+ rSet.Put( SfxBoolItem( nWhich, !pSh->IsReadOnly() ) );
+ }
+ break;
+ }
+
+ case SID_RELOAD:
+ {
+ SfxFrame* pFrame = &GetTopFrame();
+
+ if ( !pSh || !pSh->CanReload_Impl() || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
+ rSet.DisableItem(nWhich);
+ else
+ {
+ // Wenn irgendein ChildFrame reloadable ist, wird der Slot
+ // enabled, damit man CTRL-Reload machen kann
+ sal_Bool bReloadAvailable = sal_False;
+ SfxFrameIterator aFrameIter( *pFrame, sal_True );
+ for( SfxFrame* pNextFrame = aFrameIter.FirstFrame();
+ pFrame;
+ pNextFrame = pNextFrame ?
+ aFrameIter.NextFrame( *pNextFrame ) : 0 )
+ {
+ SfxObjectShell *pShell = pFrame->GetCurrentDocument();
+ if( pShell && pShell->Get_Impl()->bReloadAvailable )
+ {
+ bReloadAvailable = sal_True;
+ break;
+ }
+ pFrame = pNextFrame;
+ }
+
+ rSet.Put( SfxBoolItem( nWhich, bReloadAvailable));
+ }
+
+ break;
+ }
+ }
+ }
+}
+
+
+//--------------------------------------------------------------------
+void SfxViewFrame::ExecHistory_Impl( SfxRequest &rReq )
+{
+ // gibt es an der obersten Shell einen Undo-Manager?
+ SfxShell *pSh = GetDispatcher()->GetShell(0);
+ SfxUndoManager* pShUndoMgr = pSh->GetUndoManager();
+ sal_Bool bOK = sal_False;
+ if ( pShUndoMgr )
+ {
+ switch ( rReq.GetSlot() )
+ {
+ case SID_CLEARHISTORY:
+ pShUndoMgr->Clear();
+ bOK = sal_True;
+ break;
+
+ case SID_UNDO:
+ pShUndoMgr->Undo(0);
+ GetBindings().InvalidateAll(sal_False);
+ bOK = sal_True;
+ break;
+
+ case SID_REDO:
+ pShUndoMgr->Redo(0);
+ GetBindings().InvalidateAll(sal_False);
+ bOK = sal_True;
+ break;
+
+ case SID_REPEAT:
+ if ( pSh->GetRepeatTarget() )
+ pShUndoMgr->Repeat( *pSh->GetRepeatTarget(), 0);
+ bOK = sal_True;
+ break;
+ }
+ }
+ else if ( GetViewShell() )
+ {
+ // der SW hat eigenes Undo an der View
+ const SfxPoolItem *pRet = GetViewShell()->ExecuteSlot( rReq );
+ if ( pRet )
+ bOK = ((SfxBoolItem*)pRet)->GetValue();
+ }
+
+ rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bOK ) );
+ rReq.Done();
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::StateHistory_Impl( SfxItemSet &rSet )
+{
+ // Undo-Manager suchen
+ SfxShell *pSh = GetDispatcher()->GetShell(0);
+ if ( !pSh )
+ // Ich bin gerade am Reloaden und Yielde so vor mich hin ...
+ return;
+
+ SfxUndoManager *pShUndoMgr = pSh->GetUndoManager();
+ if ( !pShUndoMgr )
+ {
+ // der SW hat eigenes Undo an der View
+ SfxWhichIter aIter( rSet );
+ SfxViewShell *pViewSh = GetViewShell();
+ if( !pViewSh ) return;
+ for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
+ pViewSh->GetSlotState( nSID, 0, &rSet );
+ return;
+ }
+
+ if ( pShUndoMgr->GetUndoActionCount() == 0 &&
+ pShUndoMgr->GetRedoActionCount() == 0 &&
+ pShUndoMgr->GetRepeatActionCount() == 0 )
+ rSet.DisableItem( SID_CLEARHISTORY );
+
+ if ( pShUndoMgr && pShUndoMgr->GetUndoActionCount() )
+ {
+ String aTmp( SvtResId( STR_UNDO ) );
+ aTmp+= pShUndoMgr->GetUndoActionComment(0);
+ rSet.Put( SfxStringItem( SID_UNDO, aTmp ) );
+ }
+ else
+ rSet.DisableItem( SID_UNDO );
+
+ if ( pShUndoMgr && pShUndoMgr->GetRedoActionCount() )
+ {
+ String aTmp( SvtResId(STR_REDO) );
+ aTmp += pShUndoMgr->GetRedoActionComment(0);
+ rSet.Put( SfxStringItem( SID_REDO, aTmp ) );
+ }
+ else
+ rSet.DisableItem( SID_REDO );
+ SfxRepeatTarget *pTarget = pSh->GetRepeatTarget();
+ if ( pShUndoMgr && pTarget && pShUndoMgr->GetRepeatActionCount() &&
+ pShUndoMgr->CanRepeat(*pTarget, 0) )
+ {
+ String aTmp( SvtResId(STR_REPEAT) );
+ aTmp += pShUndoMgr->GetRepeatActionComment(*pTarget, 0);
+ rSet.Put( SfxStringItem( SID_REPEAT, aTmp ) );
+ }
+ else
+ rSet.DisableItem( SID_REPEAT );
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::PopShellAndSubShells_Impl( SfxViewShell& i_rViewShell )
+{
+ i_rViewShell.PopSubShells_Impl();
+ sal_uInt16 nLevel = pDispatcher->GetShellLevel( i_rViewShell );
+ if ( nLevel != USHRT_MAX )
+ {
+ if ( nLevel )
+ {
+ // more sub shells on the stack, which were not affected by PopSubShells_Impl
+ SfxShell *pSubShell = pDispatcher->GetShell( nLevel-1 );
+ if ( pSubShell == i_rViewShell.GetSubShell() )
+ // "real" sub shells will be deleted elsewhere
+ pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL );
+ else
+ pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL | SFX_SHELL_POP_DELETE );
+ }
+ pDispatcher->Pop( i_rViewShell );
+ pDispatcher->Flush();
+ }
+
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::ReleaseObjectShell_Impl()
+
+/* [Beschreibung]
+
+ Diese Methode entleert den SfxViewFrame, d.h. nimmt die <SfxObjectShell>
+ vom Dispatcher und beendet seine <SfxListener>-Beziehung zu dieser
+ SfxObjectShell (wodurch sie sich ggf. selbst zerst"ort).
+
+ Somit kann durch Aufruf von ReleaseObjectShell() und SetObjectShell()
+ die SfxObjectShell ausgetauscht werden.
+
+ Zwischen RealeaseObjectShell() und SetObjectShell() darf die Kontrolle
+ nicht an das System abgegeben werden.
+
+
+ [Querverweise]
+
+ <SfxViewFrame::SetObjectShell(SfxObjectShell&)>
+*/
+{
+ DBG_CHKTHIS(SfxViewFrame, 0);
+ DBG_ASSERT( xObjSh.Is(), "no SfxObjectShell to release!" );
+
+ GetFrame().ReleasingComponent_Impl( sal_True );
+ if ( GetWindow().HasChildPathFocus( sal_True ) )
+ {
+ DBG_ASSERT( !GetActiveChildFrame_Impl(), "Wrong active child frame!" );
+ GetWindow().GrabFocus();
+ }
+
+ SfxViewShell *pDyingViewSh = GetViewShell();
+ if ( pDyingViewSh )
+ {
+ PopShellAndSubShells_Impl( *pDyingViewSh );
+ pDyingViewSh->DisconnectAllClients();
+ SetViewShell_Impl(0);
+ delete pDyingViewSh;
+ }
+#ifdef DBG_UTIL
+ else
+ DBG_ERROR("Keine Shell");
+#endif
+
+ if ( xObjSh.Is() )
+ {
+ pImp->aLastType = xObjSh->Type();
+ pDispatcher->Pop( *xObjSh );
+ SfxModule* pModule = xObjSh->GetModule();
+ if( pModule )
+ pDispatcher->RemoveShell_Impl( *pModule );
+ pDispatcher->Flush();
+ EndListening( *xObjSh );
+
+ Notify( *xObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
+ Notify( *xObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
+
+ if ( 1 == xObjSh->GetOwnerLockCount() && pImp->bObjLocked && xObjSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
+ xObjSh->DoClose();
+ SfxObjectShellRef xDyingObjSh = xObjSh;
+ xObjSh.Clear();
+ if( ( GetFrameType() & SFXFRAME_HASTITLE ) && pImp->nDocViewNo )
+ xDyingObjSh->GetNoSet_Impl().ReleaseIndex(pImp->nDocViewNo-1);
+ if ( pImp->bObjLocked )
+ {
+ xDyingObjSh->OwnerLock( sal_False );
+ pImp->bObjLocked = sal_False;
+ }
+ }
+
+ GetDispatcher()->SetDisableFlags( 0 );
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxViewFrame::Close()
+{
+ DBG_CHKTHIS(SfxViewFrame, 0);
+
+ DBG_ASSERT( GetFrame().IsClosing_Impl() || !GetFrame().GetFrameInterface().is(), "ViewFrame closed too early!" );
+
+ // Wenn bis jetzt noch nicht gespeichert wurde, sollen eingebettete Objekte
+ // auch nicht mehr automatisch gespeichert werden!
+ if ( GetViewShell() )
+ GetViewShell()->DiscardClients_Impl();
+ Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
+
+ if (SfxViewFrame::Current() == this)
+ SfxViewFrame::SetViewFrame( NULL );
+
+ // Da der Dispatcher leer ger"aumt wird, kann man ihn auch nicht mehr
+ // vern"unftig verwenden - also besser still legen
+ GetDispatcher()->Lock(sal_True);
+ delete this;
+
+ return sal_True;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewFrame::DoActivate( sal_Bool bUI, SfxViewFrame* pOldFrame )
+{
+ DBG_CHKTHIS(SfxViewFrame, 0);
+ SFX_APP();
+
+ pDispatcher->DoActivate_Impl( bUI, pOldFrame );
+
+ // Wenn ich einen parent habe und dieser ist kein parent des alten
+ // ViewFrames, erh"alt er ein ParentActivate
+ if ( bUI )
+ {
+/*
+ SfxMedium* pMed = GetObjectShell() ? GetObjectShell()->GetMedium() : NULL;
+ if( pMed )
+ {
+ SFX_ITEMSET_ARG(
+ pMed->GetItemSet(), pInterceptorItem, SfxSlotInterceptorItem,
+ SID_INTERCEPTOR, sal_False );
+ if( pInterceptorItem )
+ {
+ SfxSlotInterceptor* pInter = pInterceptorItem->GetValue();
+ if( !pInter->GetBindings() )
+ pInter->SetBindings( &GetBindings() );
+ pInter->Activate( sal_True );
+ }
+ }
+ */
+ SfxViewFrame *pFrame = GetParentViewFrame();
+ while ( pFrame )
+ {
+ if ( !pOldFrame || !pOldFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
+ pFrame->pDispatcher->DoParentActivate_Impl();
+ pFrame = pFrame->GetParentViewFrame();
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::DoDeactivate(sal_Bool bUI, SfxViewFrame* pNewFrame )
+{
+ DBG_CHKTHIS(SfxViewFrame, 0);
+ SFX_APP();
+ pDispatcher->DoDeactivate_Impl( bUI, pNewFrame );
+
+ // Wenn ich einen parent habe und dieser ist kein parent des neuen
+ // ViewFrames, erh"alt er ein ParentDeactivate
+ if ( bUI )
+ {
+// if ( GetFrame().GetWorkWindow_Impl() )
+// GetFrame().GetWorkWindow_Impl()->SaveStatus_Impl();
+/*
+ SfxMedium* pMed = GetObjectShell() ? GetObjectShell()->GetMedium() : NULL;
+ if( pMed )
+ {
+ SFX_ITEMSET_ARG(
+ pMed->GetItemSet(), pInterceptorItem, SfxSlotInterceptorItem,
+ SID_INTERCEPTOR, sal_False );
+ if( pInterceptorItem )
+ pInterceptorItem->GetValue()->Activate( sal_False );
+ }
+*/
+ SfxViewFrame *pFrame = GetParentViewFrame();
+ while ( pFrame )
+ {
+ if ( !pNewFrame || !pNewFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
+ pFrame->pDispatcher->DoParentDeactivate_Impl();
+ pFrame = pFrame->GetParentViewFrame();
+ }
+ }
+}
+
+//------------------------------------------------------------------------
+void SfxViewFrame::InvalidateBorderImpl( const SfxViewShell* pSh )
+{
+ if( pSh && !nAdjustPosPixelLock )
+ {
+ if ( GetViewShell() && GetWindow().IsVisible() )
+ {
+ if ( GetFrame().IsInPlace() )
+ {
+ /*
+ Size aSize( GetViewShell()->GetWindow()->GetSizePixel() );
+
+ //Size aBorderSz( pEnv->GetBorderWin()->GetHatchBorderPixel() );
+ Point aOfs; //( aBorderSz.Width(), aBorderSz.Height() );
+
+ DoAdjustPosSizePixel( GetViewShell(), aOfs, aSize );*/
+ return;
+ }
+
+ DoAdjustPosSizePixel( (SfxViewShell *) GetViewShell(), Point(),
+ GetWindow().GetOutputSizePixel() );
+ }
+ }
+}
+
+//------------------------------------------------------------------------
+sal_Bool SfxViewFrame::SetBorderPixelImpl
+(
+ const SfxViewShell* pVSh,
+ const SvBorder& rBorder
+)
+
+{
+ pImp->aBorder = rBorder;
+
+ if ( IsResizeInToOut_Impl() && !GetFrame().IsInPlace() )
+ {
+ Size aSize = pVSh->GetWindow()->GetOutputSizePixel();
+ if ( aSize.Width() && aSize.Height() )
+ {
+ aSize.Width() += rBorder.Left() + rBorder.Right();
+ aSize.Height() += rBorder.Top() + rBorder.Bottom();
+
+ Size aOldSize = GetWindow().GetOutputSizePixel();
+ GetWindow().SetOutputSizePixel( aSize );
+ Window* pParent = &GetWindow();
+ while ( pParent->GetParent() )
+ pParent = pParent->GetParent();
+ Size aOuterSize = pParent->GetOutputSizePixel();
+ aOuterSize.Width() += ( aSize.Width() - aOldSize.Width() );
+ aOuterSize.Height() += ( aSize.Height() - aOldSize.Height() );
+ pParent->SetOutputSizePixel( aOuterSize );
+ }
+ }
+ else
+ {
+ Point aPoint;
+ Rectangle aEditArea( aPoint, GetWindow().GetOutputSizePixel() );
+ aEditArea.Left() += rBorder.Left();
+ aEditArea.Right() -= rBorder.Right();
+ aEditArea.Top() += rBorder.Top();
+ aEditArea.Bottom() -= rBorder.Bottom();
+ pVSh->GetWindow()->SetPosSizePixel( aEditArea.TopLeft(), aEditArea.GetSize() );
+ }
+
+ return sal_True;
+}
+
+//------------------------------------------------------------------------
+const SvBorder& SfxViewFrame::GetBorderPixelImpl
+(
+ const SfxViewShell* /*pSh*/
+) const
+
+{
+ return pImp->aBorder;
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
+{
+ {DBG_CHKTHIS(SfxViewFrame, 0);}
+
+ if( IsDowning_Impl())
+ return;
+
+ // we know only SimpleHints
+ if ( rHint.IsA(TYPE(SfxSimpleHint)) )
+ {
+ switch( ( (SfxSimpleHint&) rHint ).GetId() )
+ {
+ case SFX_HINT_MODECHANGED:
+ {
+ UpdateTitle();
+
+ if ( !xObjSh.Is() )
+ break;
+
+ // r/o Umschaltung?
+ SfxBindings& rBind = GetBindings();
+ rBind.Invalidate( SID_RELOAD );
+ SfxDispatcher *pDispat = GetDispatcher();
+ sal_Bool bWasReadOnly = pDispat->GetReadOnly_Impl();
+ sal_Bool bIsReadOnly = xObjSh->IsReadOnly();
+ if ( !bWasReadOnly != !bIsReadOnly )
+ {
+ // Dann auch TITLE_CHANGED
+ UpdateTitle();
+ rBind.Invalidate( SID_FILE_NAME );
+ rBind.Invalidate( SID_DOCINFO_TITLE );
+ rBind.Invalidate( SID_EDITDOC );
+
+ pDispat->GetBindings()->InvalidateAll(sal_True);
+ pDispat->SetReadOnly_Impl( bIsReadOnly );
+
+ // Dispatcher-Update nur erzwingen, wenn es nicht sowieso
+ // demn"achst kommt, anderenfalls ist Zappelei oder gar
+ // GPF m"oglich, da Writer z.B. gerne mal im Resize irgendwelche
+ // Aktionen t"atigt, die ein SetReadOnlyUI am Dispatcher zur
+ // Folge haben!
+ if ( pDispat->IsUpdated_Impl() )
+ pDispat->Update_Impl(sal_True);
+ }
+
+ Enable( !xObjSh->IsInModalMode() );
+ break;
+ }
+
+ case SFX_HINT_TITLECHANGED:
+ {
+ UpdateTitle();
+ SfxBindings& rBind = GetBindings();
+ rBind.Invalidate( SID_FILE_NAME );
+ rBind.Invalidate( SID_DOCINFO_TITLE );
+ rBind.Invalidate( SID_EDITDOC );
+ rBind.Invalidate( SID_RELOAD );
+ break;
+ }
+
+ case SFX_HINT_DEINITIALIZING:
+ GetFrame().DoClose();
+ break;
+ case SFX_HINT_DYING:
+ // when the Object is being deleted, destroy the view too
+ if ( xObjSh.Is() )
+ ReleaseObjectShell_Impl();
+ else
+ GetFrame().DoClose();
+ break;
+
+ }
+ }
+ else if ( rHint.IsA(TYPE(SfxEventHint)) )
+ {
+ // Wenn das Document asynchron geladen wurde, wurde der Dispatcher
+ // auf ReadOnly gesetzt, was zur"?ckgenommen werden mu\s, wenn
+ // das Document selbst nicht ReadOnly ist und das Laden fertig ist.
+ switch ( ((SfxEventHint&)rHint).GetEventId() )
+ {
+ case SFX_EVENT_MODIFYCHANGED:
+ {
+ SfxBindings& rBind = GetBindings();
+ rBind.Invalidate( SID_DOC_MODIFIED );
+ rBind.Invalidate( SID_SAVEDOC );
+ rBind.Invalidate( SID_RELOAD );
+ rBind.Invalidate( SID_EDITDOC );
+ break;
+ }
+
+ case SFX_EVENT_OPENDOC:
+ case SFX_EVENT_CREATEDOC:
+ {
+ if ( !xObjSh.Is() )
+ break;
+
+ SfxBindings& rBind = GetBindings();
+ rBind.Invalidate( SID_RELOAD );
+ rBind.Invalidate( SID_EDITDOC );
+ if ( !xObjSh->IsReadOnly() )
+ {
+ // Im Gegensatz zu oben (TITLE_CHANGED) mu\s das UI nicht
+ // upgedated werden, da es nicht gehidet war!
+
+ // #i21560# InvalidateAll() causes the assertion
+ // 'SfxBindings::Invalidate while in update" when
+ // the sfx slot SID_BASICIDE_APPEAR is executed
+ // via API from another thread (Java).
+ // According to MBA this call is not necessary anymore,
+ // because each document has its own SfxBindings.
+ //
+ //GetDispatcher()->GetBindings()->InvalidateAll(sal_True);
+ }
+
+ break;
+ }
+
+ case SFX_EVENT_TOGGLEFULLSCREENMODE:
+ {
+ if ( GetFrame().OwnsBindings_Impl() )
+ GetBindings().GetDispatcher_Impl()->Update_Impl( sal_True );
+ break;
+ }
+ }
+ }
+}
+
+//------------------------------------------------------------------------
+void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh )
+{
+ pImp->bResizeInToOut = sal_True;
+ pImp->bDontOverwriteResizeInToOut = sal_False;
+ pImp->bObjLocked = sal_False;
+ pImp->pFocusWin = 0;
+ pImp->pActiveChild = NULL;
+ pImp->nCurViewId = 0;
+ pImp->bReloading = sal_False;
+ pImp->bIsDowning = sal_False;
+ pImp->bModal = sal_False;
+ pImp->bEnabled = sal_True;
+ pImp->nDocViewNo = 0;
+ pImp->aMargin = Size( -1, -1 );
+ pImp->pWindow = 0;
+
+ SetPool( &SFX_APP()->GetPool() );
+ pDispatcher = new SfxDispatcher(this);
+ if ( !GetBindings().GetDispatcher() )
+ GetBindings().SetDispatcher( pDispatcher );
+
+ xObjSh = pObjSh;
+ if ( xObjSh.Is() && xObjSh->IsPreview() )
+ SetQuietMode_Impl( sal_True );
+
+ if ( pObjSh )
+ {
+ pDispatcher->Push( *SFX_APP() );
+ SfxModule* pModule = xObjSh->GetModule();
+ if( pModule )
+ pDispatcher->Push( *pModule );
+ pDispatcher->Push( *this );
+ pDispatcher->Push( *pObjSh );
+ pDispatcher->Flush();
+ StartListening( *pObjSh );
+ pObjSh->ViewAssigned();
+ Notify( *pObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
+ Notify( *pObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
+ pDispatcher->SetReadOnly_Impl( pObjSh->IsReadOnly() );
+ }
+ else
+ {
+ pDispatcher->Push( *SFX_APP() );
+ pDispatcher->Push( *this );
+ pDispatcher->Flush();
+ }
+
+ SfxViewFrame *pThis = this; // wegen der kranken Array-Syntax
+ SfxViewFrameArr_Impl &rViewArr = SFX_APP()->GetViewFrames_Impl();
+ rViewArr.C40_INSERT(SfxViewFrame, pThis, rViewArr.Count() );
+}
+
+SfxViewFrame::SfxViewFrame
+(
+ SfxFrame& rFrame,
+ SfxObjectShell* pObjShell
+)
+
+/* [Beschreibung]
+
+ Ctor des SfxViewFrame f"ur eine <SfxObjectShell> aus der Ressource.
+ Die 'nViewId' der zu erzeugenden <SfxViewShell> kann angegeben werden
+ (default ist die zuerst registrierte SfxViewShell-Subklasse).
+*/
+
+ : pImp( new SfxViewFrame_Impl( rFrame ) )
+ , pDispatcher(0)
+ , pBindings( new SfxBindings )
+ , nAdjustPosPixelLock( 0 )
+{
+ DBG_CTOR( SfxViewFrame, NULL );
+
+ rFrame.SetCurrentViewFrame_Impl( this );
+ rFrame.SetFrameType_Impl( GetFrameType() | SFXFRAME_HASTITLE );
+ Construct_Impl( pObjShell );
+
+ pImp->pWindow = new SfxFrameViewWindow_Impl( this, rFrame.GetWindow() );
+ pImp->pWindow->SetSizePixel( rFrame.GetWindow().GetOutputSizePixel() );
+ rFrame.SetOwnsBindings_Impl( sal_True );
+ rFrame.CreateWorkWindow_Impl();
+}
+
+//------------------------------------------------------------------------
+SfxViewFrame::~SfxViewFrame()
+{
+ DBG_DTOR(SfxViewFrame, 0);
+
+ SetDowning_Impl();
+
+ if ( SfxViewFrame::Current() == this )
+ SfxViewFrame::SetViewFrame( NULL );
+
+ ReleaseObjectShell_Impl();
+
+ if ( GetFrame().OwnsBindings_Impl() )
+ // Die Bindings l"oscht der Frame!
+ KillDispatcher_Impl();
+
+ delete pImp->pWindow;
+
+ if ( GetFrame().GetCurrentViewFrame() == this )
+ GetFrame().SetCurrentViewFrame_Impl( NULL );
+
+ // von Frame-Liste abmelden
+ SfxApplication *pSfxApp = SFX_APP();
+ SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
+ const SfxViewFrame *pThis = this;
+ rFrames.Remove( rFrames.GetPos(pThis) );
+
+ // Member l"oschen
+ KillDispatcher_Impl();
+
+ delete pImp;
+}
+
+//------------------------------------------------------------------------
+void SfxViewFrame::KillDispatcher_Impl()
+
+// Dispatcher abr"aumen und l"oschen
+
+{
+ DBG_CHKTHIS(SfxViewFrame, 0);
+
+ SfxModule* pModule = xObjSh.Is() ? xObjSh->GetModule() : 0;
+ if ( xObjSh.Is() )
+ ReleaseObjectShell_Impl();
+ if ( pDispatcher )
+ {
+ if( pModule )
+ pDispatcher->Pop( *pModule, SFX_SHELL_POP_UNTIL );
+ else
+ pDispatcher->Pop( *this );
+ DELETEZ(pDispatcher);
+ }
+}
+
+//------------------------------------------------------------------------
+SfxViewFrame* SfxViewFrame::Current()
+{
+ return SfxApplication::Get() ? SFX_APP()->Get_Impl()->pViewFrame : NULL;
+}
+
+//--------------------------------------------------------------------
+sal_uInt16 SfxViewFrame::Count()
+
+/* [Beschreibung]
+
+ Liefert die Anzahl der sichtbaren <SfxViewFrame>-Instanzen.
+*/
+
+{
+ SfxApplication *pSfxApp = SFX_APP();
+ SfxViewFrameArr_Impl& rFrames = pSfxApp->GetViewFrames_Impl();
+ const sal_uInt16 nCount = rFrames.Count();
+ sal_uInt16 nFound = 0;
+ for ( sal_uInt16 i = 0; i < nCount; ++i )
+ {
+ SfxViewFrame *pFrame = rFrames[i];
+ if ( pFrame->IsVisible() )
+ ++nFound;
+ }
+ return nFound;
+}
+
+//--------------------------------------------------------------------
+// returns the first window of spec. type viewing the specified doc.
+SfxViewFrame* SfxViewFrame::GetFirst
+(
+ const SfxObjectShell* pDoc,
+ sal_Bool bOnlyIfVisible
+)
+{
+ SfxApplication *pSfxApp = SFX_APP();
+ SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
+
+ // search for a SfxDocument of the specified type
+ for ( sal_uInt16 nPos = 0; nPos < rFrames.Count(); ++nPos )
+ {
+ SfxViewFrame *pFrame = rFrames.GetObject(nPos);
+ if ( ( !pDoc || pDoc == pFrame->GetObjectShell() )
+ && ( !bOnlyIfVisible || pFrame->IsVisible() )
+ )
+ return pFrame;
+ }
+
+ return 0;
+}
+//--------------------------------------------------------------------
+
+// returns thenext window of spec. type viewing the specified doc.
+SfxViewFrame* SfxViewFrame::GetNext
+(
+ const SfxViewFrame& rPrev,
+ const SfxObjectShell* pDoc,
+ sal_Bool bOnlyIfVisible
+)
+{
+ SfxApplication *pSfxApp = SFX_APP();
+ SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
+
+ // refind the specified predecessor
+ sal_uInt16 nPos;
+ for ( nPos = 0; nPos < rFrames.Count(); ++nPos )
+ if ( rFrames.GetObject(nPos) == &rPrev )
+ break;
+
+ // search for a Frame of the specified type
+ for ( ++nPos; nPos < rFrames.Count(); ++nPos )
+ {
+ SfxViewFrame *pFrame = rFrames.GetObject(nPos);
+ if ( ( !pDoc || pDoc == pFrame->GetObjectShell() )
+ && ( !bOnlyIfVisible || pFrame->IsVisible() )
+ )
+ return pFrame;
+ }
+ return 0;
+}
+
+void SfxViewFrame::CloseHiddenFrames_Impl()
+{
+ SfxApplication *pSfxApp = SFX_APP();
+ SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
+ for ( sal_uInt16 nPos=0; nPos<rFrames.Count(); )
+ {
+ SfxViewFrame *pFrame = rFrames.GetObject(nPos);
+ if ( !pFrame->IsVisible() )
+ pFrame->DoClose();
+ else
+ nPos++;
+ }
+}
+
+//--------------------------------------------------------------------
+SfxProgress* SfxViewFrame::GetProgress() const
+{
+ SfxObjectShell *pObjSh = GetObjectShell();
+ return pObjSh ? pObjSh->GetProgress() : 0;
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::ShowStatusText( const String& /*rText*/)
+{
+/* OBSOLETE: If this is used, framework/uielement/progressbarwrapper.[h|c]xx &
+ framework/uielement/statusindicatorinterfacewrapper.[h|c]xx must be
+ extended to support a new interface to support ShowStatusText/HideStatusText
+ SfxWorkWindow* pWorkWin = GetFrame().GetWorkWindow_Impl();
+ SfxStatusBarManager *pMgr = pWorkWin->GetStatusBarManager_Impl();
+ if ( pMgr )
+ {
+ pMgr->GetStatusBar()->HideItems();
+ pMgr->GetStatusBar()->SetText( rText );
+ }
+*/
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::HideStatusText()
+{
+/* OBSOLETE: If this is used, framework/uielement/progressbarwrapper.[h|c]xx &
+ framework/uielement/statusindicatorinterfacewrapper.[h|c]xx must be
+ extended to support a new interface to support ShowStatusText/HideStatusText
+ SfxWorkWindow* pWorkWin = GetFrame().GetWorkWindow_Impl();
+ SfxStatusBarManager *pMgr = pWorkWin->GetStatusBarManager_Impl();
+ if ( pMgr )
+ pMgr->GetStatusBar()->ShowItems();
+*/
+}
+
+
+//--------------------------------------------------------------------
+#ifdef ENABLE_INIMANAGER//MUSTINI
+SfxIniManager* SfxViewFrame::GetIniManager() const
+{
+/* SfxIniManager *pIniMgr = GetObjectShell()
+ ? GetObjectShell()->GetFactory().GetIniManager()
+ : 0;
+ if ( !pIniMgr )*/ //!
+ return SFX_APP()->GetAppIniManager();
+// return pIniMgr;
+}
+#endif
+
+//--------------------------------------------------------------------
+void SfxViewFrame::DoAdjustPosSizePixel //! teilen in Inner.../Outer...
+(
+ SfxViewShell* pSh,
+ const Point& rPos,
+ const Size& rSize
+)
+{
+ DBG_CHKTHIS(SfxViewFrame, 0);
+
+ // Components benutzen diese Methode nicht!
+ if( pSh && pSh->GetWindow() && !nAdjustPosPixelLock )
+ {
+ nAdjustPosPixelLock++;
+ if ( pImp->bResizeInToOut )
+ pSh->InnerResizePixel( rPos, rSize );
+ else
+ pSh->OuterResizePixel( rPos, rSize );
+ nAdjustPosPixelLock--;
+ }
+}
+
+//========================================================================
+
+int SfxViewFrameItem::operator==( const SfxPoolItem &rItem ) const
+{
+ return PTR_CAST(SfxViewFrameItem, &rItem)->pFrame== pFrame;
+}
+
+//--------------------------------------------------------------------
+String SfxViewFrameItem::GetValueText() const
+{
+ return String();
+}
+
+//--------------------------------------------------------------------
+SfxPoolItem* SfxViewFrameItem::Clone( SfxItemPool *) const
+{
+ return new SfxViewFrameItem( pFrame);
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::SetViewShell_Impl( SfxViewShell *pVSh )
+
+/* [Beschreibung]
+
+ Interne Methode zum setzen der jeweils aktuellen <SfxViewShell>-Instanz,
+ die in diesem SfxViewFrame aktiv ist.
+*/
+
+{
+ SfxShell::SetViewShell_Impl( pVSh );
+
+ // Hack: InPlaceMode
+ if ( pVSh )
+ pImp->bResizeInToOut = sal_False;
+}
+
+//--------------------------------------------------------------------
+/*
+ Beschreibung:
+ Der ParentViewFrame ist der ViewFrame des Containers bei internem InPlace
+*/
+
+//TODO/LATER: is it still necessary? is there a replacement for GetParentViewFrame_Impl?
+SfxViewFrame* SfxViewFrame::GetParentViewFrame_Impl() const
+{
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::ForceOuterResize_Impl(sal_Bool bOn)
+{
+ if ( !pImp->bDontOverwriteResizeInToOut )
+ pImp->bResizeInToOut = !bOn;
+}
+
+void SfxViewFrame::ForceInnerResize_Impl(sal_Bool bOn)
+{
+ pImp->bDontOverwriteResizeInToOut = bOn;
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxViewFrame::IsResizeInToOut_Impl() const
+{
+ return pImp->bResizeInToOut;
+}
+//--------------------------------------------------------------------
+void SfxViewFrame::DoAdjustPosSize( SfxViewShell *pSh,
+ const Point rPos, const Size &rSize )
+{
+ DBG_CHKTHIS(SfxViewFrame, 0);
+ if( pSh && !nAdjustPosPixelLock )
+ {
+ Window *pWindow = pSh->GetWindow();
+ Point aPos = pWindow->LogicToPixel(rPos);
+ Size aSize = pWindow->LogicToPixel(rSize);
+ DoAdjustPosSizePixel(pSh, aPos, aSize);
+ }
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::GetDocNumber_Impl()
+{
+ DBG_ASSERT( GetObjectShell(), "Kein Dokument!" );
+ GetObjectShell()->SetNamedVisibility_Impl();
+ pImp->nDocViewNo = GetObjectShell()->GetNoSet_Impl().GetFreeIndex()+1;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewFrame::Enable( sal_Bool bEnable )
+{
+ if ( bEnable != pImp->bEnabled )
+ {
+ pImp->bEnabled = bEnable;
+
+ // e.g. InPlace-Frames have a parent...
+ SfxViewFrame *pParent = GetParentViewFrame_Impl();
+ if ( pParent )
+ {
+ pParent->Enable( bEnable );
+ }
+ else
+ {
+ Window *pWindow = &GetFrame().GetTopFrame().GetWindow();
+ if ( !bEnable )
+ pImp->bWindowWasEnabled = pWindow->IsInputEnabled();
+ if ( !bEnable || pImp->bWindowWasEnabled )
+ pWindow->EnableInput( bEnable, TRUE );
+ }
+
+ // cursor and focus
+ SfxViewShell* pViewSh = GetViewShell();
+ if ( bEnable )
+ {
+ // show cursor
+ if ( pViewSh )
+ pViewSh->ShowCursor();
+ }
+ else
+ {
+ // hide cursor
+ if ( pViewSh )
+ pViewSh->ShowCursor(sal_False);
+ }
+/*
+ if ( !bEnable )
+ GetBindings().ENTERREGISTRATIONS();
+ GetDispatcher()->Lock( !bEnable );
+ if ( bEnable )
+ GetBindings().LEAVEREGISTRATIONS();
+*/
+ }
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::Show()
+
+/* [Beschreibung]
+
+ Diese Methode macht das Frame-Window sichtbar und ermittelt vorher
+ den Fenstername. Au\serdem wird das Dokument festgehalten. Man darf
+ i.d.R. nie das Window direkt showen!
+*/
+
+{
+ // zuerst locken damit in UpdateTitle() gilt: IsVisible() == sal_True (:#)
+ if ( xObjSh.Is() )
+ {
+ xObjSh->GetMedium()->GetItemSet()->ClearItem( SID_HIDDEN );
+ if ( !pImp->bObjLocked )
+ LockObjectShell_Impl( sal_True );
+
+ // Doc-Shell Titel-Nummer anpassen, get unique view-no
+ if ( 0 == pImp->nDocViewNo )
+ {
+ GetDocNumber_Impl();
+ UpdateTitle();
+ }
+ }
+ else
+ UpdateTitle();
+
+ // Frame-Window anzeigen, aber nur wenn der ViewFrame kein eigenes Window
+ // hat oder wenn er keine Component enth"alt
+ if ( &GetWindow() == &GetFrame().GetWindow() || !GetFrame().HasComponent() )
+ GetWindow().Show();
+ GetFrame().GetWindow().Show();
+
+/* SfxViewFrame* pCurrent = SfxViewFrame::Current();
+ if ( GetFrame().GetFrameInterface()->isActive() &&
+ pCurrent != this &&
+ ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) &&
+ !GetActiveChildFrame_Impl() )
+ MakeActive_Impl( FALSE );*/
+ if ( xObjSh.Is() && xObjSh->Get_Impl()->bHiddenLockedByAPI )
+ {
+ xObjSh->Get_Impl()->bHiddenLockedByAPI = FALSE;
+ xObjSh->OwnerLock(FALSE);
+ }
+}
+
+//--------------------------------------------------------------------
+sal_Bool SfxViewFrame::IsVisible() const
+{
+ return pImp->bObjLocked;
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::Hide()
+{
+ GetWindow().Hide();
+ if ( pImp->bObjLocked )
+ LockObjectShell_Impl( sal_False );
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::LockObjectShell_Impl( sal_Bool bLock )
+{
+ DBG_ASSERT( pImp->bObjLocked != bLock, "Falscher Locked-Status!" );
+
+ DBG_ASSERT( GetObjectShell(), "Kein Dokument!" );
+ GetObjectShell()->OwnerLock(bLock);
+ pImp->bObjLocked = bLock;
+}
+
+//--------------------------------------------------------------------
+void SfxViewFrame::MakeActive_Impl( BOOL bGrabFocus )
+{
+ if ( GetViewShell() && !GetFrame().IsClosing_Impl() )
+ {
+ if ( IsVisible() )
+ {
+ if ( GetViewShell() )
+ {
+ BOOL bPreview = FALSE;
+ if ( GetObjectShell()->IsPreview() )
+ {
+ bPreview = TRUE;
+ }
+ else
+ {
+ SfxViewFrame* pParent = GetParentViewFrame();
+ if ( pParent )
+ pParent->SetActiveChildFrame_Impl( this );
+ }
+
+ SfxViewFrame* pCurrent = SfxViewFrame::Current();
+ css::uno::Reference< css::frame::XFrame > xFrame = GetFrame().GetFrameInterface();
+ if ( !bPreview )
+ {
+ SetViewFrame( this );
+ GetBindings().SetActiveFrame( css::uno::Reference< css::frame::XFrame >() );
+ uno::Reference< frame::XFramesSupplier > xSupp( xFrame, uno::UNO_QUERY );
+ if ( xSupp.is() )
+ xSupp->setActiveFrame( uno::Reference < frame::XFrame >() );
+
+ css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
+ Window* pWindow = VCLUnoHelper::GetWindow(xContainerWindow);
+ if (pWindow && pWindow->HasChildPathFocus() && bGrabFocus)
+ {
+ SfxInPlaceClient *pCli = GetViewShell()->GetUIActiveClient();
+ if ( ( !pCli || !pCli->IsObjectUIActive() ) &&
+ ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) )
+ GetFrame().GrabFocusOnComponent_Impl();
+ }
+ }
+ else
+ {
+ GetBindings().SetDispatcher( GetDispatcher() );
+ GetBindings().SetActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () );
+ GetDispatcher()->Update_Impl( FALSE );
+ }
+ }
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+
+void SfxViewFrame::SetQuietMode_Impl( sal_Bool bOn )
+{
+ GetDispatcher()->SetQuietMode_Impl( bOn );
+}
+
+//-------------------------------------------------------------------------
+
+SfxObjectShell* SfxViewFrame::GetObjectShell()
+{
+ return xObjSh;
+}
+
+const Size& SfxViewFrame::GetMargin_Impl() const
+{
+ return pImp->aMargin;
+}
+
+void SfxViewFrame::SetActiveChildFrame_Impl( SfxViewFrame *pViewFrame )
+{
+ if ( pViewFrame != pImp->pActiveChild )
+ {
+ if ( !pImp->pActiveChild )
+ GetDispatcher()->LockUI_Impl( sal_False );
+
+ pImp->pActiveChild = pViewFrame;
+
+ Reference< XFramesSupplier > xFrame( GetFrame().GetFrameInterface(), UNO_QUERY );
+ Reference< XFrame > xActive;
+ if ( pViewFrame )
+ xActive = pViewFrame->GetFrame().GetFrameInterface();
+
+ if ( xFrame.is() ) // PB: #74432# xFrame cann be NULL
+ xFrame->setActiveFrame( xActive );
+ }
+}
+
+SfxViewFrame* SfxViewFrame::GetActiveChildFrame_Impl() const
+{
+ SfxViewFrame *pViewFrame = pImp->pActiveChild;
+/*
+ if ( !pViewFrame )
+ {
+ // Wenn es keinen aktiven ChildFrame gibt, irgendeinen nehmen
+ for ( sal_uInt16 n=0; n<GetChildFrameCount(); n++ )
+ {
+ pViewFrame =
+ PTR_CAST( SfxViewFrame, GetChildFrame(n)->GetChildFrame(0) );
+ if ( pViewFrame )
+ break;
+ }
+ }
+
+ pImp->pActiveChild = pViewFrame;
+*/
+ return pViewFrame;
+}
+
+//--------------------------------------------------------------------
+SfxViewFrame* SfxViewFrame::LoadViewIntoFrame_Impl_NoThrow( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
+ const USHORT i_nViewId, const bool i_bHidden )
+{
+ Reference< XFrame > xFrame( i_rFrame );
+ bool bOwnFrame = false;
+ SfxViewShell* pSuccessView = NULL;
+ try
+ {
+ if ( !xFrame.is() )
+ {
+ ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
+ Reference < XFrame > xDesktop( aContext.createComponent( "com.sun.star.frame.Desktop" ), UNO_QUERY_THROW );
+
+ if ( !i_bHidden )
+ {
+ try
+ {
+ // if there is a backing component, use it
+ Reference< XFramesSupplier > xTaskSupplier( xDesktop , css::uno::UNO_QUERY_THROW );
+ ::framework::FrameListAnalyzer aAnalyzer( xTaskSupplier, Reference< XFrame >(), ::framework::FrameListAnalyzer::E_BACKINGCOMPONENT );
+
+ if ( aAnalyzer.m_xBackingComponent.is() )
+ xFrame = aAnalyzer.m_xBackingComponent;
+ }
+ catch( uno::Exception& )
+ {}
+ }
+
+ if ( !xFrame.is() )
+ xFrame.set( xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 ), UNO_SET_THROW );
+
+ bOwnFrame = true;
+ }
+
+ pSuccessView = LoadViewIntoFrame_Impl(
+ i_rDoc,
+ xFrame,
+ Sequence< PropertyValue >(), // means "reuse existing model's args"
+ i_nViewId,
+ i_bHidden
+ );
+
+ if ( bOwnFrame && !i_bHidden )
+ {
+ // ensure the frame/window is visible
+ Reference< XWindow > xContainerWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
+ xContainerWindow->setVisible( sal_True );
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
+ if ( pSuccessView )
+ return pSuccessView->GetViewFrame();
+
+ if ( bOwnFrame )
+ {
+ try
+ {
+ xFrame->dispose();
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+SfxViewShell* SfxViewFrame::LoadViewIntoFrame_Impl( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
+ const Sequence< PropertyValue >& i_rLoadArgs, const USHORT i_nViewId,
+ const bool i_bHidden )
+{
+ Reference< XModel > xDocument( i_rDoc.GetModel(), UNO_SET_THROW );
+
+ ::comphelper::NamedValueCollection aTransformLoadArgs( i_rLoadArgs.getLength() ? i_rLoadArgs : xDocument->getArgs() );
+ aTransformLoadArgs.put( "Model", xDocument );
+ if ( i_nViewId )
+ aTransformLoadArgs.put( "ViewId", sal_Int16( i_nViewId ) );
+ if ( i_bHidden )
+ aTransformLoadArgs.put( "Hidden", i_bHidden );
+ else
+ aTransformLoadArgs.remove( "Hidden" );
+
+ ::rtl::OUString sURL( RTL_CONSTASCII_USTRINGPARAM( "private:object" ) );
+ if ( !sURL.getLength() )
+ sURL = i_rDoc.GetFactory().GetFactoryURL();
+
+ Reference< XComponentLoader > xLoader( i_rFrame, UNO_QUERY_THROW );
+ xLoader->loadComponentFromURL( sURL, ::rtl::OUString::createFromAscii( "_self" ), 0,
+ aTransformLoadArgs.getPropertyValues() );
+
+ SfxViewShell* pViewShell = SfxViewShell::Get( i_rFrame->getController() );
+ ENSURE_OR_THROW( pViewShell,
+ "SfxViewFrame::LoadViewIntoFrame_Impl: loading an SFX doc into a frame resulted in a non-SFX view - quite impossible" );
+ return pViewShell;
+}
+
+//--------------------------------------------------------------------
+
+SfxViewFrame* SfxViewFrame::LoadHiddenDocument( SfxObjectShell& i_rDoc, const USHORT i_nViewId )
+{
+ return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, true );
+}
+
+//--------------------------------------------------------------------
+
+SfxViewFrame* SfxViewFrame::LoadDocument( SfxObjectShell& i_rDoc, const USHORT i_nViewId )
+{
+ return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, false );
+}
+
+//--------------------------------------------------------------------
+
+SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rTargetFrame, const USHORT i_nViewId )
+{
+ return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_rTargetFrame, i_nViewId, false );
+}
+
+//--------------------------------------------------------------------
+
+SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const SfxFrameItem* i_pFrameItem, const USHORT i_nViewId )
+{
+ return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_pFrameItem && i_pFrameItem->GetFrame() ? i_pFrameItem->GetFrame()->GetFrameInterface() : NULL, i_nViewId, false );
+}
+
+//--------------------------------------------------------------------
+SfxViewFrame* SfxViewFrame::DisplayNewDocument( SfxObjectShell& i_rDoc, const SfxRequest& i_rCreateDocRequest, const USHORT i_nViewId )
+{
+ SFX_REQUEST_ARG( i_rCreateDocRequest, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, FALSE );
+ SFX_REQUEST_ARG( i_rCreateDocRequest, pHiddenItem, SfxBoolItem, SID_HIDDEN, FALSE );
+
+ return LoadViewIntoFrame_Impl_NoThrow(
+ i_rDoc,
+ pFrameItem ? pFrameItem->GetFrame() : NULL,
+ i_nViewId,
+ pHiddenItem ? pHiddenItem->GetValue() : false
+ );
+}
+
+//--------------------------------------------------------------------
+
+SfxViewFrame* SfxViewFrame::Get( const Reference< XController>& i_rController, const SfxObjectShell* i_pDoc )
+{
+ if ( !i_rController.is() )
+ return NULL;
+
+ const SfxObjectShell* pDoc = i_pDoc;
+ if ( !pDoc )
+ {
+ Reference< XModel > xDocument( i_rController->getModel() );
+ for ( pDoc = SfxObjectShell::GetFirst( 0, false );
+ pDoc;
+ pDoc = SfxObjectShell::GetNext( *pDoc, 0, false )
+ )
+ {
+ if ( pDoc->GetModel() == xDocument )
+ break;
+ }
+ }
+
+ SfxViewFrame* pViewFrame = NULL;
+ for ( pViewFrame = SfxViewFrame::GetFirst( pDoc, FALSE );
+ pViewFrame;
+ pViewFrame = SfxViewFrame::GetNext( *pViewFrame, pDoc, FALSE )
+ )
+ {
+ if ( pViewFrame->GetViewShell()->GetController() == i_rController )
+ break;
+ }
+
+ return pViewFrame;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewFrame::SaveCurrentViewData_Impl( const USHORT i_nNewViewId )
+{
+ SfxViewShell* pCurrentShell = GetViewShell();
+ ENSURE_OR_RETURN_VOID( pCurrentShell != NULL, "SfxViewFrame::SaveCurrentViewData_Impl: no current view shell -> no current view data!" );
+
+ // determine the logical (API) view name
+ const SfxObjectFactory& rDocFactory( pCurrentShell->GetObjectShell()->GetFactory() );
+ const sal_uInt16 nCurViewNo = rDocFactory.GetViewNo_Impl( GetCurViewId(), 0 );
+ const String sCurrentViewName = rDocFactory.GetViewFactory( nCurViewNo ).GetAPIViewName();
+ const sal_uInt16 nNewViewNo = rDocFactory.GetViewNo_Impl( i_nNewViewId, 0 );
+ const String sNewViewName = rDocFactory.GetViewFactory( nNewViewNo ).GetAPIViewName();
+ if ( ( sCurrentViewName.Len() == 0 ) || ( sNewViewName.Len() == 0 ) )
+ {
+ // can't say anything about the view, the respective application did not yet migrate its code to
+ // named view factories => bail out
+ OSL_ENSURE( false, "SfxViewFrame::SaveCurrentViewData_Impl: views without API names? Shouldn't happen anymore?" );
+ return;
+ }
+ OSL_ENSURE( !sNewViewName.Equals( sCurrentViewName ), "SfxViewFrame::SaveCurrentViewData_Impl: suspicious: new and old view name are identical!" );
+
+ // save the view data only when we're moving from a non-print-preview to the print-preview view
+ if ( !sNewViewName.EqualsAscii( "PrintPreview" ) )
+ return;
+
+ // retrieve the view data from the view
+ Sequence< PropertyValue > aViewData;
+ pCurrentShell->WriteUserDataSequence( aViewData );
+
+ try
+ {
+ // retrieve view data (for *all* views) from the model
+ const Reference< XController > xController( pCurrentShell->GetController(), UNO_SET_THROW );
+ const Reference< XViewDataSupplier > xViewDataSupplier( xController->getModel(), UNO_QUERY_THROW );
+ const Reference< XIndexContainer > xViewData( xViewDataSupplier->getViewData(), UNO_QUERY_THROW );
+
+ // look up the one view data item which corresponds to our current view, and remove it
+ const sal_Int32 nCount = xViewData->getCount();
+ for ( sal_Int32 i=0; i<nCount; ++i )
+ {
+ const ::comphelper::NamedValueCollection aCurViewData( xViewData->getByIndex(i) );
+ ::rtl::OUString sViewId( aCurViewData.getOrDefault( "ViewId", ::rtl::OUString() ) );
+ if ( sViewId.getLength() == 0 )
+ continue;
+
+ const SfxViewFactory* pViewFactory = rDocFactory.GetViewFactoryByViewName( sViewId );
+ if ( pViewFactory == NULL )
+ continue;
+
+ if ( pViewFactory->GetOrdinal() == GetCurViewId() )
+ {
+ xViewData->removeByIndex(i);
+ break;
+ }
+ }
+
+ // then replace it with the most recent view data we just obtained
+ xViewData->insertByIndex( 0, makeAny( aViewData ) );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+}
+
+//--------------------------------------------------------------------
+
+sal_Bool SfxViewFrame::SwitchToViewShell_Impl
+(
+ sal_uInt16 nViewIdOrNo, /* > 0
+ Registrierungs-Id der View, auf die umge-
+ schaltet werden soll, bzw. die erstmalig
+ erzeugt werden soll.
+
+ == 0
+ Es soll die Default-View verwendet werden. */
+
+ sal_Bool bIsIndex /* sal_True
+ 'nViewIdOrNo' ist keine Registrations-Id sondern
+ ein Index in die f"ur die in diesem
+ <SfxViewFrame> dargestellte <SfxObjectShell>.
+ */
+)
+
+/* [Beschreibung]
+
+ Interne Methode zum Umschalten auf eine andere <SfxViewShell>-Subklasse,
+ die in diesem SfxMDIFrame erzeugt werden soll. Existiert noch
+ keine SfxViewShell in diesem SfxMDIFrame, so wird erstmalig eine
+ erzeugt.
+
+
+ [R"uckgabewert]
+
+ sal_Bool sal_True
+ die angeforderte SfxViewShell wurde erzeugt
+ und eine ggf. bestehende gel"oscht
+
+ sal_False
+ die angeforderte SfxViewShell konnte nicht
+ erzeugt werden, die bestehende SfxViewShell
+ existiert daher weiterhin
+*/
+
+{
+ try
+ {
+ ENSURE_OR_THROW( GetObjectShell() != NULL, "not possible without a document" );
+
+ // if we already have a view shell, remove it
+ SfxViewShell* pOldSh = GetViewShell();
+ OSL_PRECOND( pOldSh, "SfxViewFrame::SwitchToViewShell_Impl: that's called *switch* (not for *initial-load*) for a reason" );
+ if ( pOldSh )
+ {
+ // ask wether it can be closed
+ if ( !pOldSh->PrepareClose( TRUE ) )
+ return sal_False;
+
+ // remove sub shells from Dispatcher before switching to new ViewShell
+ PopShellAndSubShells_Impl( *pOldSh );
+ }
+
+ GetBindings().ENTERREGISTRATIONS();
+ LockAdjustPosSizePixel();
+
+ // ID of the new view
+ SfxObjectFactory& rDocFact = GetObjectShell()->GetFactory();
+ const USHORT nViewId = ( bIsIndex || !nViewIdOrNo ) ? rDocFact.GetViewFactory( nViewIdOrNo ).GetOrdinal() : nViewIdOrNo;
+
+ // save the view data of the old view, so it can be restored later on (when needed)
+ SaveCurrentViewData_Impl( nViewId );
+
+ // create and load new ViewShell
+ SfxViewShell* pNewSh = LoadViewIntoFrame_Impl(
+ *GetObjectShell(),
+ GetFrame().GetFrameInterface(),
+ Sequence< PropertyValue >(), // means "reuse existing model's args"
+ nViewId,
+ false
+ );
+
+ // allow resize events to be processed
+ UnlockAdjustPosSizePixel();
+
+ if ( GetWindow().IsReallyVisible() )
+ DoAdjustPosSizePixel( pNewSh, Point(), GetWindow().GetOutputSizePixel() );
+
+ GetBindings().LEAVEREGISTRATIONS();
+ delete pOldSh;
+ }
+ catch ( const com::sun::star::uno::Exception& )
+ {
+ // the SfxCode is not able to cope with exceptions thrown while creating views
+ // the code will crash in the stack unwinding procedure, so we shouldn't let exceptions go through here
+ DBG_UNHANDLED_EXCEPTION();
+ return sal_False;
+ }
+
+ DBG_ASSERT( SFX_APP()->GetViewFrames_Impl().Count() == SFX_APP()->GetViewShells_Impl().Count(), "Inconsistent view arrays!" );
+ return sal_True;
+}
+
+//-------------------------------------------------------------------------
+void SfxViewFrame::SetCurViewId_Impl( const USHORT i_nID )
+{
+ pImp->nCurViewId = i_nID;
+}
+
+//-------------------------------------------------------------------------
+sal_uInt16 SfxViewFrame::GetCurViewId() const
+{
+ return pImp->nCurViewId;
+}
+
+//-------------------------------------------------------------------------
+void SfxViewFrame::ExecView_Impl
+(
+ SfxRequest& rReq // der auszuf"uhrende <SfxRequest>
+)
+
+/* [Beschreibung]
+
+ Interne Methode zum Ausf"uhren der f"ur die <SfxShell> Subklasse
+ SfxViewFrame in der <SVIDL> beschriebenen Slots.
+*/
+
+{
+ DBG_CHKTHIS(SfxViewFrame, 0);
+
+ // Wenn gerade die Shells ausgetauscht werden...
+ if ( !GetObjectShell() || !GetViewShell() )
+ return;
+
+ switch ( rReq.GetSlot() )
+ {
+ case SID_TERMINATE_INPLACEACTIVATION :
+ {
+ SfxInPlaceClient* pClient = GetViewShell()->GetUIActiveClient();
+ if ( pClient )
+ pClient->DeactivateObject();
+ break;
+ }
+
+ case SID_VIEWSHELL:
+ {
+ const SfxPoolItem *pItem = 0;
+ if ( rReq.GetArgs()
+ && SFX_ITEM_SET == rReq.GetArgs()->GetItemState( SID_VIEWSHELL, sal_False, &pItem )
+ )
+ {
+ const sal_uInt16 nViewId = static_cast< const SfxUInt16Item* >( pItem )->GetValue();
+ BOOL bSuccess = SwitchToViewShell_Impl( nViewId );
+ rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
+ }
+ break;
+ }
+
+ case SID_VIEWSHELL0:
+ case SID_VIEWSHELL1:
+ case SID_VIEWSHELL2:
+ case SID_VIEWSHELL3:
+ case SID_VIEWSHELL4:
+ {
+ const sal_uInt16 nViewNo = rReq.GetSlot() - SID_VIEWSHELL0;
+ BOOL bSuccess = SwitchToViewShell_Impl( nViewNo, sal_True );
+ rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
+ break;
+ }
+
+ case SID_NEWWINDOW:
+ {
+ // Hack. demnaechst virtuelle Funktion
+ if ( !GetViewShell()->NewWindowAllowed() )
+ {
+ OSL_ENSURE( false, "You should have disabled the 'Window/New Window' slot!" );
+ return;
+ }
+
+ // ViewData bei FrameSets rekursiv holen
+ GetFrame().GetViewData_Impl();
+ SfxMedium* pMed = GetObjectShell()->GetMedium();
+
+ // do not open the new window hidden
+ pMed->GetItemSet()->ClearItem( SID_HIDDEN );
+
+ // the view ID (optional arg. TODO: this is currently not supported in the slot definition ...)
+ SFX_REQUEST_ARG( rReq, pViewIdItem, SfxUInt16Item, SID_VIEW_ID, sal_False );
+ const USHORT nViewId = pViewIdItem ? pViewIdItem->GetValue() : GetCurViewId();
+
+ Reference < XFrame > xFrame;
+ // the frame (optional arg. TODO: this is currently not supported in the slot definition ...)
+ SFX_REQUEST_ARG( rReq, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
+ if ( pFrameItem )
+ xFrame = pFrameItem->GetFrame();
+
+ LoadViewIntoFrame_Impl_NoThrow( *GetObjectShell(), xFrame, nViewId, false );
+
+ rReq.Done();
+ break;
+ }
+
+ case SID_OBJECT:
+ {
+ SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, SID_OBJECT, sal_False );
+
+ SfxViewShell *pViewShell = GetViewShell();
+ if ( pViewShell && pItem )
+ {
+ pViewShell->DoVerb( pItem->GetValue() );
+ rReq.Done();
+ break;;
+ }
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+/* TODO as96863:
+ This method try to collect informations about the count of currently open documents.
+ But the algorithm is implemented very simple ...
+ E.g. hidden documents should be ignored here ... but they are counted.
+ TODO: export special helper "framework::FrameListAnalyzer" within the framework module
+ and use it here.
+*/
+sal_Bool impl_maxOpenDocCountReached()
+{
+ static ::rtl::OUString SERVICE_DESKTOP = ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop");
+
+ try
+ {
+ css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
+ css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
+ xSMGR,
+ ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/"),
+ ::rtl::OUString::createFromAscii("Misc"),
+ ::rtl::OUString::createFromAscii("MaxOpenDocuments"),
+ ::comphelper::ConfigurationHelper::E_READONLY);
+
+ // NIL means: count of allowed documents = infinite !
+ if ( ! aVal.hasValue())
+ return sal_False;
+
+ sal_Int32 nOpenDocs = 0;
+ sal_Int32 nMaxDocs = 0;
+ aVal >>= nMaxDocs;
+
+ css::uno::Reference< css::frame::XFramesSupplier > xDesktop(xSMGR->createInstance(SERVICE_DESKTOP), css::uno::UNO_QUERY_THROW);
+ css::uno::Reference< css::container::XIndexAccess > xCont (xDesktop->getFrames() , css::uno::UNO_QUERY_THROW);
+
+ sal_Int32 c = xCont->getCount();
+ sal_Int32 i = 0;
+
+ for (i=0; i<c; ++i)
+ {
+ try
+ {
+ css::uno::Reference< css::frame::XFrame > xFrame;
+ xCont->getByIndex(i) >>= xFrame;
+ if ( ! xFrame.is())
+ continue;
+
+ // a) do not count the help window
+ if (xFrame->getName().equalsAscii("OFFICE_HELP_TASK"))
+ continue;
+
+ // b) count all other frames
+ ++nOpenDocs;
+ }
+ catch(const css::uno::Exception&)
+ // A IndexOutOfBoundException can happen in multithreaded environments,
+ // where any other thread can change this container !
+ { continue; }
+ }
+
+ return (nOpenDocs >= nMaxDocs);
+ }
+ catch(const css::uno::Exception&)
+ {}
+
+ // Any internal error is no reason to stop opening documents !
+ // Limitation of opening documents is a special "nice to have" feature.
+ // Otherwhise it can happen, that NO document will be opened ...
+ return sal_False;
+}
+
+//-------------------------------------------------------------------------
+void SfxViewFrame::StateView_Impl
+(
+ SfxItemSet& rSet /* leeres <SfxItemSet> mit <Which-Ranges>,
+ welche die Ids der zu erfragenden
+ Slots beschreiben. */
+)
+
+/* [Beschreibung]
+
+ Diese interne Methode liefert in 'rSet' die Status der f"ur die
+ <SfxShell> Subklasse SfxViewFrame in der <SVIDL> beschriebenen <Slots>.
+
+ In 'rSet' sind dabei genau die vom SFx als ung"ultig erkannten
+ Slot-Ids als Which-ranges enthalten. Falls der an dieser Shell gesetzte
+ <SfxItemPool> f"ur einzelne Slot-Ids ein Mapping hat, werden die
+ entsprechenden Which-Ids verwendet, so da\s Items ggf. direkt mit
+ einer mit Which-Ids arbeitenden Core-::com::sun::star::script::Engine ausgetauscht werden
+ k"onnen.
+*/
+
+{
+ DBG_CHKTHIS(SfxViewFrame, 0);
+
+ SfxObjectShell *pDocSh = GetObjectShell();
+
+ if ( !pDocSh )
+ // Ich bin gerade am Reloaden und Yielde so vor mich hin ...
+ return;
+
+ const sal_uInt16 *pRanges = rSet.GetRanges();
+ DBG_ASSERT(pRanges, "Set ohne Bereich");
+ while ( *pRanges )
+ {
+ for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
+ {
+ switch(nWhich)
+ {
+ case SID_VIEWSHELL:
+ {
+ rSet.Put( SfxUInt16Item( nWhich, pImp->nCurViewId ) );
+ break;
+ }
+
+ case SID_VIEWSHELL0:
+ case SID_VIEWSHELL1:
+ case SID_VIEWSHELL2:
+ case SID_VIEWSHELL3:
+ case SID_VIEWSHELL4:
+ {
+ sal_uInt16 nViewNo = nWhich - SID_VIEWSHELL0;
+ if ( GetObjectShell()->GetFactory().GetViewFactoryCount() >
+ nViewNo && !GetObjectShell()->IsInPlaceActive() )
+ {
+ SfxViewFactory &rViewFactory =
+ GetObjectShell()->GetFactory().GetViewFactory(nViewNo);
+ rSet.Put( SfxBoolItem(
+ nWhich, pImp->nCurViewId == rViewFactory.GetOrdinal() ) );
+ }
+ else
+ rSet.DisableItem( nWhich );
+ break;
+ }
+ case SID_FRAMETITLE:
+ {
+ if( GetFrameType() & SFXFRAME_HASTITLE )
+ rSet.Put( SfxStringItem(
+ SID_FRAMETITLE, pImp->aFrameTitle) );
+ else
+ rSet.DisableItem( nWhich );
+ break;
+ }
+
+ case SID_NEWWINDOW:
+ {
+ if ( !GetViewShell()->NewWindowAllowed()
+ || impl_maxOpenDocCountReached()
+ )
+ rSet.DisableItem( nWhich );
+ break;
+ }
+ }
+ }
+ }
+}
+
+//-------------------------------------------------------------------------
+void SfxViewFrame::ToTop()
+{
+ GetFrame().Appear();
+}
+
+//-------------------------------------------------------------------------
+SfxViewFrame* SfxViewFrame::GetParentViewFrame() const
+/*
+ Beschreibung:
+ Der ParentViewFrame ist der ViewFrame des ParentFrames
+*/
+{
+ SfxFrame *pFrame = GetFrame().GetParentFrame();
+ return pFrame ? pFrame->GetCurrentViewFrame() : NULL;
+}
+
+//-------------------------------------------------------------------------
+SfxFrame& SfxViewFrame::GetFrame() const
+/*
+ Beschreibung:
+ GetFrame liefert den Frame, in dem sich der ViewFrame befindet
+*/
+{
+ return pImp->rFrame;
+}
+
+//-------------------------------------------------------------------------
+SfxViewFrame* SfxViewFrame::GetTopViewFrame() const
+{
+ return GetFrame().GetTopFrame().GetCurrentViewFrame();
+}
+
+Window& SfxViewFrame::GetWindow() const
+{
+ return pImp->pWindow ? *pImp->pWindow : GetFrame().GetWindow();
+}
+
+sal_Bool SfxViewFrame::DoClose()
+{
+ return GetFrame().DoClose();
+}
+
+String SfxViewFrame::GetActualPresentationURL_Impl() const
+{
+ if ( xObjSh.Is() )
+ return xObjSh->GetMedium()->GetName();
+ return String();
+}
+
+void SfxViewFrame::SetModalMode( sal_Bool bModal )
+{
+ pImp->bModal = bModal;
+ if ( xObjSh.Is() )
+ {
+ for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( xObjSh );
+ !bModal && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, xObjSh ) )
+ bModal = pFrame->pImp->bModal;
+ xObjSh->SetModalMode_Impl( bModal );
+ }
+}
+
+BOOL SfxViewFrame::IsInModalMode() const
+{
+ return pImp->bModal || GetFrame().GetWindow().IsInModalMode();
+}
+
+void SfxViewFrame::Resize( BOOL bForce )
+{
+ Size aSize = GetWindow().GetOutputSizePixel();
+ if ( bForce || aSize != pImp->aSize )
+ {
+ pImp->aSize = aSize;
+ SfxViewShell *pShell = GetViewShell();
+ if ( pShell )
+ {
+ if ( GetFrame().IsInPlace() )
+ {
+ Point aPoint = GetWindow().GetPosPixel();
+ DoAdjustPosSizePixel( pShell, aPoint, aSize );
+ }
+ else
+ {
+ DoAdjustPosSizePixel( pShell, Point(), aSize );
+ }
+ }
+ }
+}
+
+#define LINE_SEP 0x0A
+
+void CutLines( ::rtl::OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, BOOL bEraseTrailingEmptyLines )
+{
+ sal_Int32 nStartPos = 0;
+ sal_Int32 nEndPos = 0;
+ sal_Int32 nLine = 0;
+ while ( nLine < nStartLine )
+ {
+ nStartPos = rStr.indexOf( LINE_SEP, nStartPos );
+ if( nStartPos == -1 )
+ break;
+ nStartPos++; // nicht das \n.
+ nLine++;
+ }
+
+ DBG_ASSERTWARNING( nStartPos != STRING_NOTFOUND, "CutLines: Startzeile nicht gefunden!" );
+
+ if ( nStartPos != -1 )
+ {
+ nEndPos = nStartPos;
+ for ( sal_Int32 i = 0; i < nLines; i++ )
+ nEndPos = rStr.indexOf( LINE_SEP, nEndPos+1 );
+
+ if ( nEndPos == -1 ) // kann bei letzter Zeile passieren
+ nEndPos = rStr.getLength();
+ else
+ nEndPos++;
+
+ ::rtl::OUString aEndStr = rStr.copy( nEndPos );
+ rStr = rStr.copy( 0, nStartPos );
+ rStr += aEndStr;
+ }
+ if ( bEraseTrailingEmptyLines )
+ {
+ sal_Int32 n = nStartPos;
+ sal_Int32 nLen = rStr.getLength();
+ while ( ( n < nLen ) && ( rStr.getStr()[ n ] == LINE_SEP ) )
+ n++;
+
+ if ( n > nStartPos )
+ {
+ ::rtl::OUString aEndStr = rStr.copy( n );
+ rStr = rStr.copy( 0, nStartPos );
+ rStr += aEndStr;
+ }
+ }
+}
+
+/*
+ add new recorded dispatch macro script into the application global basic lib container
+ It generates a new unique id for it and insert the macro by using this number as name for
+ the modul
+ */
+void SfxViewFrame::AddDispatchMacroToBasic_Impl( const ::rtl::OUString& sMacro )
+{
+ /*
+ // get lib and modul name from dialog
+ SfxModule *pMod = GetObjectShell()->GetModule();
+ SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pMod->GetPool() );
+ const SfxPoolItem* pRet = pMod->ExecuteSlot( aReq );
+ if ( pRet )
+ ::rtl::OUString = ((SfxStringItem*)pRet)->GetValue();
+ */
+ if ( !sMacro.getLength() )
+ return;
+
+ SfxApplication* pSfxApp = SFX_APP();
+ SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pSfxApp->GetPool() );
+ aReq.AppendItem( SfxBoolItem(SID_RECORDMACRO,TRUE) );
+ const SfxPoolItem* pRet = SFX_APP()->ExecuteSlot( aReq );
+ String aScriptURL;
+ if ( pRet )
+ aScriptURL = ((SfxStringItem*)pRet)->GetValue();
+ if ( aScriptURL.Len() )
+ {
+ // parse scriptURL
+ String aLibName;
+ String aModuleName;
+ String aMacroName;
+ String aLocation;
+ Reference< XMultiServiceFactory > xSMgr = ::comphelper::getProcessServiceFactory();
+ Reference< com::sun::star::uri::XUriReferenceFactory > xFactory( xSMgr->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.uri.UriReferenceFactory" ) ), UNO_QUERY );
+ if ( xFactory.is() )
+ {
+ Reference< com::sun::star::uri::XVndSunStarScriptUrl > xUrl( xFactory->parse( aScriptURL ), UNO_QUERY );
+ if ( xUrl.is() )
+ {
+ // get name
+ ::rtl::OUString aName = xUrl->getName();
+ sal_Unicode cTok = '.';
+ sal_Int32 nIndex = 0;
+ aLibName = aName.getToken( 0, cTok, nIndex );
+ if ( nIndex != -1 )
+ aModuleName = aName.getToken( 0, cTok, nIndex );
+ if ( nIndex != -1 )
+ aMacroName = aName.getToken( 0, cTok, nIndex );
+
+ // get location
+ ::rtl::OUString aLocKey = ::rtl::OUString::createFromAscii( "location" );
+ if ( xUrl->hasParameter( aLocKey ) )
+ aLocation = xUrl->getParameter( aLocKey );
+ }
+ }
+
+ pSfxApp->EnterBasicCall();
+
+ BasicManager* pBasMgr = 0;
+ if ( aLocation.EqualsIgnoreCaseAscii( "application" ) )
+ {
+ // application basic
+ pBasMgr = pSfxApp->GetBasicManager();
+ }
+ else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) )
+ {
+ pBasMgr = GetObjectShell()->GetBasicManager();
+ }
+
+ ::rtl::OUString aOUSource;
+ if ( pBasMgr)
+ {
+ StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
+ if ( pBasic )
+ {
+ SbModule* pModule = pBasic->FindModule( aModuleName );
+ if ( pModule )
+ {
+ SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD );
+ aOUSource = pModule->GetSource32();
+ USHORT nStart, nEnd;
+ pMethod->GetLineRange( nStart, nEnd );
+ ULONG nlStart = nStart;
+ ULONG nlEnd = nEnd;
+ CutLines( aOUSource, nlStart-1, nlEnd-nlStart+1, TRUE );
+ }
+ }
+ }
+
+ // open lib container and break operation if it couldn't be opened
+ com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibCont;
+ if ( aLocation.EqualsIgnoreCaseAscii( "application" ) )
+ {
+ xLibCont = SFX_APP()->GetBasicContainer();
+ }
+ else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) )
+ {
+ xLibCont = GetObjectShell()->GetBasicContainer();
+ }
+
+ if(!xLibCont.is())
+ {
+ DBG_ERRORFILE("couldn't get access to the basic lib container. Adding of macro isn't possible.");
+ return;
+ }
+
+ // get LibraryContainer
+ com::sun::star::uno::Any aTemp;
+ com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xRoot(
+ xLibCont,
+ com::sun::star::uno::UNO_QUERY);
+
+ ::rtl::OUString sLib( aLibName );
+ com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xLib;
+ if(xRoot->hasByName(sLib))
+ {
+ // library must be loaded
+ aTemp = xRoot->getByName(sLib);
+ xLibCont->loadLibrary(sLib);
+ aTemp >>= xLib;
+ }
+ else
+ {
+ xLib = com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >(
+ xLibCont->createLibrary(sLib),
+ com::sun::star::uno::UNO_QUERY);
+ }
+
+ // pack the macro as direct usable "sub" routine
+ ::rtl::OUString sCode;
+ ::rtl::OUStringBuffer sRoutine(10000);
+ ::rtl::OUString sMacroName( aMacroName );
+ BOOL bReplace = FALSE;
+
+ // get module
+ ::rtl::OUString sModule( aModuleName );
+ if(xLib->hasByName(sModule))
+ {
+ if ( aOUSource.getLength() )
+ {
+ sRoutine.append( aOUSource );
+ }
+ else
+ {
+ aTemp = xLib->getByName(sModule);
+ aTemp >>= sCode;
+ sRoutine.append( sCode );
+ }
+
+ bReplace = TRUE;
+ }
+
+ // append new method
+ sRoutine.appendAscii("\nsub " );
+ sRoutine.append (sMacroName );
+ sRoutine.appendAscii("\n" );
+ sRoutine.append (sMacro );
+ sRoutine.appendAscii("\nend sub\n");
+
+ // create the modul inside the library and insert the macro routine
+ aTemp <<= sRoutine.makeStringAndClear();
+ if ( bReplace )
+ {
+ com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
+ xLib,
+ com::sun::star::uno::UNO_QUERY);
+ xModulCont->replaceByName(sModule,aTemp);
+ }
+ else
+ {
+ com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
+ xLib,
+ com::sun::star::uno::UNO_QUERY);
+ xModulCont->insertByName(sModule,aTemp);
+ }
+
+ // #i17355# update the Basic IDE
+ for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst(); pViewShell; pViewShell = SfxViewShell::GetNext( *pViewShell ) )
+ {
+ if ( pViewShell->GetName().EqualsAscii( "BasicIDE" ) )
+ {
+ SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
+ SfxDispatcher* pDispat = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
+ if ( pDispat )
+ {
+ SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLibName, aModuleName, String(), String() );
+ pDispat->Execute( SID_BASICIDE_UPDATEMODULESOURCE, SFX_CALLMODE_SYNCHRON, &aInfoItem, 0L );
+ }
+ }
+ }
+
+ pSfxApp->LeaveBasicCall();
+ }
+ else
+ {
+ // add code for "session only" macro
+ }
+
+ /*
+ FILE* pFile = fopen( "macro.bas", "a" );
+ fprintf( pFile, "%s", ::rtl::OUStringToOString(sBuffer.makeStringAndClear(),RTL_TEXTENCODING_UTF8).getStr() );
+ fclose ( pFile );
+ */
+}
+
+void SfxViewFrame::MiscExec_Impl( SfxRequest& rReq )
+{
+ DBG_MEMTEST();
+ FASTBOOL bDone = FALSE;
+ switch ( rReq.GetSlot() )
+ {
+ case SID_STOP_RECORDING :
+ case SID_RECORDMACRO :
+ {
+ // try to find any active recorder on this frame
+ ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier");
+ com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
+ GetFrame().GetFrameInterface(),
+ com::sun::star::uno::UNO_QUERY);
+
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(xFrame,com::sun::star::uno::UNO_QUERY);
+ com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
+ aProp >>= xSupplier;
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
+ if (xSupplier.is())
+ xRecorder = xSupplier->getDispatchRecorder();
+
+ BOOL bIsRecording = xRecorder.is();
+ SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, SID_RECORDMACRO, sal_False);
+ if ( pItem && pItem->GetValue() == bIsRecording )
+ return;
+
+ if ( xRecorder.is() )
+ {
+ // disable active recording
+ aProp <<= com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >();
+ xSet->setPropertyValue(sProperty,aProp);
+
+ SFX_REQUEST_ARG( rReq, pRecordItem, SfxBoolItem, FN_PARAM_1, sal_False);
+ if ( !pRecordItem || !pRecordItem->GetValue() )
+ // insert script into basic library container of application
+ AddDispatchMacroToBasic_Impl(xRecorder->getRecordedMacro());
+
+ xRecorder->endRecording();
+ xRecorder = NULL;
+ GetBindings().SetRecorder_Impl( xRecorder );
+
+ SetChildWindow( SID_RECORDING_FLOATWINDOW, FALSE );
+ if ( rReq.GetSlot() != SID_RECORDMACRO )
+ GetBindings().Invalidate( SID_RECORDMACRO );
+ }
+ else if ( rReq.GetSlot() == SID_RECORDMACRO )
+ {
+ // enable recording
+ com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xFactory(
+ ::comphelper::getProcessServiceFactory(),
+ com::sun::star::uno::UNO_QUERY);
+
+ xRecorder = com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder >(
+ xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.frame.DispatchRecorder")),
+ com::sun::star::uno::UNO_QUERY);
+
+ xSupplier = com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >(
+ xFactory->createInstance(rtl::OUString::createFromAscii("com.sun.star.frame.DispatchRecorderSupplier")),
+ com::sun::star::uno::UNO_QUERY);
+
+ xSupplier->setDispatchRecorder(xRecorder);
+ xRecorder->startRecording(xFrame);
+ aProp <<= xSupplier;
+ xSet->setPropertyValue(sProperty,aProp);
+ GetBindings().SetRecorder_Impl( xRecorder );
+ SetChildWindow( SID_RECORDING_FLOATWINDOW, TRUE );
+ }
+
+ rReq.Done();
+ break;
+ }
+
+ case SID_TOGGLESTATUSBAR:
+ {
+ com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
+ GetFrame().GetFrameInterface(),
+ com::sun::star::uno::UNO_QUERY);
+
+ Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
+ Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
+ aValue >>= xLayoutManager;
+ }
+ catch ( Exception& )
+ {
+ }
+ }
+
+ if ( xLayoutManager.is() )
+ {
+ rtl::OUString aStatusbarResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" ));
+ // Parameter auswerten
+ SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, rReq.GetSlot(), FALSE);
+ BOOL bShow( TRUE );
+ if ( !pShowItem )
+ bShow = xLayoutManager->isElementVisible( aStatusbarResString );
+ else
+ bShow = pShowItem->GetValue();
+
+ if ( bShow )
+ {
+ xLayoutManager->createElement( aStatusbarResString );
+ xLayoutManager->showElement( aStatusbarResString );
+ }
+ else
+ xLayoutManager->hideElement( aStatusbarResString );
+
+ if ( !pShowItem )
+ rReq.AppendItem( SfxBoolItem( SID_TOGGLESTATUSBAR, bShow ) );
+ }
+ rReq.Done();
+ break;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_WIN_FULLSCREEN:
+ {
+ SFX_REQUEST_ARG(rReq, pItem, SfxBoolItem, rReq.GetSlot(), FALSE);
+ SfxViewFrame *pTop = GetTopViewFrame();
+ if ( pTop )
+ {
+ WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl();
+ if ( pWork )
+ {
+ com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
+ GetFrame().GetFrameInterface(),
+ com::sun::star::uno::UNO_QUERY);
+
+ Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
+ Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
+ aValue >>= xLayoutManager;
+ }
+ catch ( Exception& )
+ {
+ }
+ }
+
+ BOOL bNewFullScreenMode = pItem ? pItem->GetValue() : !pWork->IsFullScreenMode();
+ if ( bNewFullScreenMode != pWork->IsFullScreenMode() )
+ {
+ Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet( xLayoutManager, UNO_QUERY );
+ if ( xLMPropSet.is() )
+ {
+ try
+ {
+ xLMPropSet->setPropertyValue(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HideCurrentUI" )),
+ makeAny( bNewFullScreenMode ));
+ }
+ catch ( ::com::sun::star::beans::UnknownPropertyException& )
+ {
+ }
+ }
+ pWork->ShowFullScreenMode( bNewFullScreenMode );
+ pWork->SetMenuBarMode( bNewFullScreenMode ? MENUBAR_MODE_HIDE : MENUBAR_MODE_NORMAL );
+ GetFrame().GetWorkWindow_Impl()->SetFullScreen_Impl( bNewFullScreenMode );
+ if ( !pItem )
+ rReq.AppendItem( SfxBoolItem( SID_WIN_FULLSCREEN, bNewFullScreenMode ) );
+ rReq.Done();
+ }
+ else
+ rReq.Ignore();
+ }
+ }
+ else
+ rReq.Ignore();
+
+ GetDispatcher()->Update_Impl( TRUE );
+ break;
+ }
+ }
+
+ if ( bDone )
+ rReq.Done();
+}
+
+void SfxViewFrame::MiscState_Impl(SfxItemSet &rSet)
+{
+ DBG_MEMTEST();
+
+ const USHORT *pRanges = rSet.GetRanges();
+ DBG_ASSERT(pRanges && *pRanges, "Set ohne Bereich");
+ while ( *pRanges )
+ {
+ for(USHORT nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
+ {
+ switch(nWhich)
+ {
+ case SID_CURRENT_URL:
+ {
+ // Bei internem InPlace den ContainerFrame nehmen
+ SfxViewFrame *pFrame = this;
+ if ( pFrame->GetParentViewFrame_Impl() )
+ pFrame = pFrame->GetParentViewFrame_Impl();
+ rSet.Put( SfxStringItem( nWhich, pFrame->GetActualPresentationURL_Impl() ) );
+ break;
+ }
+
+ case SID_RECORDMACRO :
+ {
+ const char* pName = GetObjectShell()->GetFactory().GetShortName();
+ if ( strcmp(pName,"swriter") && strcmp(pName,"scalc") )
+ {
+ rSet.DisableItem( nWhich );
+ break;
+ }
+
+ ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier");
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
+ GetFrame().GetFrameInterface(),
+ com::sun::star::uno::UNO_QUERY);
+
+ com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
+ if ( aProp >>= xSupplier )
+ rSet.Put( SfxBoolItem( nWhich, xSupplier.is() ) );
+ else
+ rSet.DisableItem( nWhich );
+ break;
+ }
+
+ case SID_STOP_RECORDING :
+ {
+ const char* pName = GetObjectShell()->GetFactory().GetShortName();
+ if ( strcmp(pName,"swriter") && strcmp(pName,"scalc") )
+ {
+ rSet.DisableItem( nWhich );
+ break;
+ }
+
+ ::rtl::OUString sProperty = rtl::OUString::createFromAscii("DispatchRecorderSupplier");
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
+ GetFrame().GetFrameInterface(),
+ com::sun::star::uno::UNO_QUERY);
+
+ com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
+ com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
+ if ( !(aProp >>= xSupplier) || !xSupplier.is() )
+ rSet.DisableItem( nWhich );
+ break;
+ }
+
+ case SID_TOGGLESTATUSBAR:
+ {
+ com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
+ GetFrame().GetFrameInterface(),
+ com::sun::star::uno::UNO_QUERY);
+ com::sun::star::uno::Any aProp = xSet->getPropertyValue(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )) );
+
+ if ( !( aProp >>= xLayoutManager ))
+ rSet.Put( SfxBoolItem( nWhich, FALSE ));
+ else
+ {
+ rtl::OUString aStatusbarResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" ));
+ BOOL bShow = xLayoutManager->isElementVisible( aStatusbarResString );
+ rSet.Put( SfxBoolItem( nWhich, bShow ));
+ }
+ break;
+ }
+
+ case SID_WIN_FULLSCREEN:
+ {
+ SfxViewFrame* pTop = GetTopViewFrame();
+ if ( pTop )
+ {
+ WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl();
+ if ( pWork )
+ {
+ rSet.Put( SfxBoolItem( nWhich, pWork->IsFullScreenMode() ) );
+ break;
+ }
+ }
+
+ rSet.DisableItem( nWhich );
+ break;
+ }
+
+ case SID_FORMATMENUSTATE :
+ {
+ DBG_ERROR("Outdated slot!");
+ rSet.DisableItem( nWhich );
+ break;
+ }
+
+ default:
+ //! DBG_ASSERT(FALSE, "Falscher Server fuer GetState");
+ break;
+ }
+ }
+
+ ++pRanges;
+ }
+}
+
+void SfxViewFrame::ChildWindowExecute( SfxRequest &rReq )
+
+/* [Beschreibung]
+
+ Diese Methode kann in der Execute-Methode f"ur das ein- und ausschalten
+ von Child-Windows eingesetzt werden, um dieses inkl. API-Anbindung zu
+ implementieren.
+
+ Einfach in der IDL als 'ExecuteMethod' eintragen.
+*/
+
+{
+ // Parameter auswerten
+ USHORT nSID = rReq.GetSlot();
+
+ SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSID, FALSE);
+ if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
+ {
+ if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE))
+ return;
+ Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface();
+ Reference < XFrame > xBeamer( xFrame->findFrame( DEFINE_CONST_UNICODE("_beamer"), FrameSearchFlag::CHILDREN ) );
+ BOOL bShow = FALSE;
+ BOOL bHasChild = xBeamer.is();
+ bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
+ if ( pShowItem )
+ {
+ if( bShow == bHasChild )
+ return;
+ }
+ else
+ rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
+
+ if ( !bShow )
+ {
+ SetChildWindow( SID_BROWSER, FALSE );
+ }
+ else
+ {
+ ::com::sun::star::util::URL aTargetURL;
+ aTargetURL.Complete = ::rtl::OUString::createFromAscii(".component:DB/DataSourceBrowser");
+ Reference < ::com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
+ xTrans->parseStrict( aTargetURL );
+
+ Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
+ Reference < ::com::sun::star::frame::XDispatch > xDisp;
+ if ( xProv.is() )
+ xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_beamer"), 31 );
+ if ( xDisp.is() )
+ {
+ Sequence < ::com::sun::star::beans::PropertyValue > aArgs(1);
+ ::com::sun::star::beans::PropertyValue* pArg = aArgs.getArray();
+ pArg[0].Name = rtl::OUString::createFromAscii("Referer");
+ pArg[0].Value <<= ::rtl::OUString::createFromAscii("private:user");
+ xDisp->dispatch( aTargetURL, aArgs );
+ }
+ }
+
+ rReq.Done();
+ return;
+ }
+
+ BOOL bShow = FALSE;
+ BOOL bHasChild = HasChildWindow(nSID);
+ bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
+
+ // ausf"uhren
+ if ( !pShowItem || bShow != bHasChild )
+ ToggleChildWindow( nSID );
+
+ GetBindings().Invalidate( nSID );
+ GetDispatcher()->Update_Impl( TRUE );
+
+ // ggf. recorden
+ if ( nSID == SID_HYPERLINK_DIALOG || nSID == SID_SEARCH_DLG )
+ {
+ rReq.Ignore();
+ }
+ else
+ {
+ rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
+ rReq.Done();
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewFrame::ChildWindowState( SfxItemSet& rState )
+
+/* [Beschreibung]
+
+ Diese Methode kann in der Status-Methode f"ur das Ein- und Ausschalt-
+ Zustand von Child-Windows eingesetzt werden, um dieses zu implementieren.
+
+ Einfach in der IDL als 'StateMethod' eintragen.
+*/
+
+{
+ SfxWhichIter aIter( rState );
+ for ( USHORT nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
+ {
+ if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
+ {
+ rState.Put( SfxBoolItem( nSID, HasChildWindow( SID_BROWSER ) ) );
+ }
+ else if ( nSID == SID_HYPERLINK_DIALOG )
+ {
+ const SfxPoolItem* pDummy = NULL;
+ SfxItemState eState = GetDispatcher()->QueryState( SID_HYPERLINK_SETLINK, pDummy );
+ if ( SFX_ITEM_DISABLED == eState )
+ rState.DisableItem(nSID);
+ else
+ {
+ if ( KnowsChildWindow(nSID) )
+ rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID)) );
+ else
+ rState.DisableItem(nSID);
+ }
+ }
+ else if ( nSID == SID_BROWSER )
+ {
+ Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface()->
+ findFrame( DEFINE_CONST_UNICODE("_beamer"), FrameSearchFlag::CHILDREN );
+ if ( !xFrame.is() )
+ rState.DisableItem( nSID );
+ else if ( KnowsChildWindow(nSID) )
+ rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
+ }
+ else if ( nSID == SID_TASKPANE )
+ {
+ if ( !KnowsChildWindow( nSID ) )
+ {
+ OSL_ENSURE( false, "SID_TASKPANE state requested, but no task pane child window exists for this ID!" );
+ rState.DisableItem( nSID );
+ }
+ else if ( !moduleHasToolPanels( *pImp ) )
+ {
+ rState.Put( SfxVisibilityItem( nSID, sal_False ) );
+ }
+ else
+ {
+ rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) );
+ }
+ }
+ else if ( KnowsChildWindow(nSID) )
+ rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
+ else
+ rState.DisableItem(nSID);
+ }
+}
+
+//--------------------------------------------------------------------
+SfxWorkWindow* SfxViewFrame::GetWorkWindow_Impl( USHORT /*nId*/ )
+{
+ SfxWorkWindow* pWork = 0;
+ pWork = GetFrame().GetWorkWindow_Impl();
+ return pWork;
+}
+
+/*
+void SfxViewFrame::SetChildWindow(USHORT nId, BOOL bOn)
+{
+ SetChildWindow( nId, bOn, TRUE );
+}*/
+
+void SfxViewFrame::SetChildWindow(USHORT nId, BOOL bOn, BOOL bSetFocus )
+{
+ SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
+ if ( pWork )
+ pWork->SetChildWindow_Impl( nId, bOn, bSetFocus );
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewFrame::ToggleChildWindow(USHORT nId)
+{
+ SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
+ if ( pWork )
+ pWork->ToggleChildWindow_Impl( nId, TRUE );
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxViewFrame::HasChildWindow( USHORT nId )
+{
+ SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
+ return pWork ? pWork->HasChildWindow_Impl(nId) : FALSE;
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxViewFrame::KnowsChildWindow( USHORT nId )
+{
+ SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
+ return pWork ? pWork->KnowsChildWindow_Impl(nId) : FALSE;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewFrame::ShowChildWindow( USHORT nId, BOOL bVisible )
+{
+ SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
+ if ( pWork )
+ {
+ GetDispatcher()->Update_Impl(sal_True);
+ pWork->ShowChildWindow_Impl(nId, bVisible, TRUE );
+ }
+}
+
+//--------------------------------------------------------------------
+
+SfxChildWindow* SfxViewFrame::GetChildWindow(USHORT nId)
+{
+ SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
+ return pWork ? pWork->GetChildWindow_Impl(nId) : NULL;
+}
+
+void SfxViewFrame::UpdateDocument_Impl()
+{
+ SfxObjectShell* pDoc = GetObjectShell();
+ if ( pDoc->IsLoadingFinished() )
+ pDoc->CheckSecurityOnLoading_Impl();
+
+ // check if document depends on a template
+ pDoc->UpdateFromTemplate_Impl();
+}
+
+void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame )
+{
+ SFX_APP()->SetViewFrame_Impl( pFrame );
+}
+
+// ---------------------------------------------------------------------------------------------------------------------
+void SfxViewFrame::ActivateToolPanel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame, const ::rtl::OUString& i_rPanelURL )
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+
+ // look up the SfxFrame for the given XFrame
+ SfxFrame* pFrame = NULL;
+ for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) )
+ {
+ if ( pFrame->GetFrameInterface() == i_rFrame )
+ break;
+ }
+ SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : NULL;
+ ENSURE_OR_RETURN_VOID( pViewFrame != NULL, "SfxViewFrame::ActivateToolPanel: did not find an SfxFrame for the given XFrame!" );
+
+ pViewFrame->ActivateToolPanel_Impl( i_rPanelURL );
+}
+
+// ---------------------------------------------------------------------------------------------------------------------
+void SfxViewFrame::ActivateToolPanel_Impl( const ::rtl::OUString& i_rPanelURL )
+{
+ // ensure the task pane is visible
+ ENSURE_OR_RETURN_VOID( KnowsChildWindow( SID_TASKPANE ), "SfxViewFrame::ActivateToolPanel: this frame/module does not allow for a task pane!" );
+ if ( !HasChildWindow( SID_TASKPANE ) )
+ ToggleChildWindow( SID_TASKPANE );
+
+ SfxChildWindow* pTaskPaneChildWindow = GetChildWindow( SID_TASKPANE );
+ ENSURE_OR_RETURN_VOID( pTaskPaneChildWindow, "SfxViewFrame::ActivateToolPanel_Impl: just switched it on, but it is not there!" );
+
+ ::sfx2::ITaskPaneToolPanelAccess* pPanelAccess = dynamic_cast< ::sfx2::ITaskPaneToolPanelAccess* >( pTaskPaneChildWindow );
+ ENSURE_OR_RETURN_VOID( pPanelAccess, "SfxViewFrame::ActivateToolPanel_Impl: task pane child window does not implement a required interface!" );
+ pPanelAccess->ActivateToolPanel( i_rPanelURL );
+}
diff --git a/sfx2/source/view/viewfrm2.cxx b/sfx2/source/view/viewfrm2.cxx
new file mode 100644
index 000000000000..05ce981a51b6
--- /dev/null
+++ b/sfx2/source/view/viewfrm2.cxx
@@ -0,0 +1,523 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include "impviewframe.hxx"
+#include "statcach.hxx"
+#include "sfx2/viewfac.hxx"
+#include "workwin.hxx"
+
+#include "sfx2/app.hxx"
+#include "sfx2/bindings.hxx"
+#include "sfx2/ctrlitem.hxx"
+#include "sfx2/dispatch.hxx"
+#include "sfx2/docfac.hxx"
+#include "sfx2/docfile.hxx"
+#include "sfx2/objitem.hxx"
+#include "sfx2/objsh.hxx"
+#include "sfx2/request.hxx"
+#include "sfx2/viewfrm.hxx"
+#include "sfx2/viewsh.hxx"
+
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/beans/XMaterialHolder.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+
+#include <comphelper/componentcontext.hxx>
+#include <comphelper/namedvaluecollection.hxx>
+#include <comphelper/processfactory.hxx>
+#include <svtools/asynclink.hxx>
+#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/rectitem.hxx>
+#include <svl/stritem.hxx>
+#include <tools/diagnose_ex.h>
+#include <tools/urlobj.hxx>
+#include <unotools/bootstrap.hxx>
+#include <unotools/configmgr.hxx>
+#include <vcl/window.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::beans;
+using ::com::sun::star::lang::XMultiServiceFactory;
+using ::com::sun::star::lang::XComponent;
+
+//------------------------------------------------------------------------
+
+static ::rtl::OUString GetModuleName_Impl( const ::rtl::OUString& sDocService )
+{
+ uno::Reference< container::XNameAccess > xMM( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager")), uno::UNO_QUERY );
+ ::rtl::OUString sVar;
+ if ( !xMM.is() )
+ return sVar;
+
+ try
+ {
+ ::comphelper::NamedValueCollection aAnalyzer( xMM->getByName( sDocService ) );
+ sVar = aAnalyzer.getOrDefault( "ooSetupFactoryUIName", ::rtl::OUString() );
+ }
+ catch( uno::Exception& )
+ {
+ sVar = ::rtl::OUString();
+ }
+
+ return sVar;
+}
+
+//--------------------------------------------------------------------
+void SfxFrameViewWindow_Impl::StateChanged( StateChangedType nStateChange )
+{
+ if ( nStateChange == STATE_CHANGE_INITSHOW )
+ {
+ SfxObjectShell* pDoc = pFrame->GetObjectShell();
+ if ( pDoc && !pFrame->IsVisible() )
+ pFrame->Show();
+
+ pFrame->Resize();
+ }
+ else
+ Window::StateChanged( nStateChange );
+}
+
+void SfxFrameViewWindow_Impl::Resize()
+{
+ if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
+ pFrame->Resize();
+}
+
+static String _getTabString()
+{
+ String result;
+
+ Reference < XMaterialHolder > xHolder(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.tab.tabreg") ), UNO_QUERY );
+ if (xHolder.is())
+ {
+ rtl::OUString aTabString;
+ Sequence< NamedValue > sMaterial;
+ if (xHolder->getMaterial() >>= sMaterial) {
+ for (int i=0; i < sMaterial.getLength(); i++) {
+ if ((sMaterial[i].Name.equalsAscii("title")) &&
+ (sMaterial[i].Value >>= aTabString))
+ {
+ result += ' ';
+ result += String(aTabString);
+ }
+ }
+ }
+ }
+ return result;
+}
+
+//========================================================================
+
+//--------------------------------------------------------------------
+String SfxViewFrame::UpdateTitle()
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann der SfxViewFrame gezwungen werden, sich sofort
+ den neuen Titel vom der <SfxObjectShell> zu besorgen.
+
+ [Anmerkung]
+
+ Dies ist z.B. dann notwendig, wenn man der SfxObjectShell als SfxListener
+ zuh"ort und dort auf den <SfxSimpleHint> SFX_HINT_TITLECHANGED reagieren
+ m"ochte, um dann die Titel seiner Views abzufragen. Diese Views (SfxTopViewFrames)
+ jedoch sind ebenfalls SfxListener und da die Reihenfolge der Benachrichtigung
+ nicht feststeht, mu\s deren Titel-Update vorab erzwungen werden.
+
+
+ [Beispiel]
+
+ void SwDocShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
+ {
+ if ( rHint.IsA(TYPE(SfxSimpleHint)) )
+ {
+ switch( ( (SfxSimpleHint&) rHint ).GetId() )
+ {
+ case SFX_HINT_TITLECHANGED:
+ for ( SfxViewFrame *pTop = SfxViewFrame::GetFirst( this );
+ pTop;
+ pTop = SfxViewFrame::GetNext( this );
+ {
+ pTop->UpdateTitle();
+ ... pTop->GetName() ...
+ }
+ break;
+ ...
+ }
+ }
+ }
+*/
+
+{
+ DBG_CHKTHIS(SfxViewFrame, 0);
+
+ const SfxObjectFactory &rFact = GetObjectShell()->GetFactory();
+ pImp->aFactoryName = String::CreateFromAscii( rFact.GetShortName() );
+
+ SfxObjectShell *pObjSh = GetObjectShell();
+ if ( !pObjSh )
+ return String();
+
+// if ( pObjSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
+// // kein UpdateTitle mit Embedded-ObjectShell
+// return String();
+
+ const SfxMedium *pMedium = pObjSh->GetMedium();
+ String aURL;
+ GetFrame(); // -Wall required??
+ if ( pObjSh->HasName() )
+ {
+ INetURLObject aTmp( pMedium->GetName() );
+ aURL = aTmp.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
+ }
+
+ if ( aURL != pImp->aActualURL )
+ // URL hat sich ge"andert
+ pImp->aActualURL = aURL;
+
+ // gibt es noch eine weitere View?
+ sal_uInt16 nViews=0;
+ for ( SfxViewFrame *pView= GetFirst(pObjSh);
+ pView && nViews<2;
+ pView = GetNext(*pView,pObjSh) )
+ if ( ( pView->GetFrameType() & SFXFRAME_HASTITLE ) &&
+ !IsDowning_Impl())
+ nViews++;
+
+ // Titel des Fensters
+ String aTitle;
+ if ( nViews == 2 || pImp->nDocViewNo > 1 )
+ // dann die Nummer dranh"angen
+ aTitle = pObjSh->UpdateTitle( NULL, pImp->nDocViewNo );
+ else
+ aTitle = pObjSh->UpdateTitle();
+
+ // Name des SbxObjects
+ String aSbxName = pObjSh->SfxShell::GetName();
+ if ( IsVisible() )
+ {
+ aSbxName += ':';
+ aSbxName += String::CreateFromInt32(pImp->nDocViewNo);
+ }
+
+ SetName( aSbxName );
+ pImp->aFrameTitle = aTitle;
+ GetBindings().Invalidate( SID_FRAMETITLE );
+ GetBindings().Invalidate( SID_CURRENT_URL );
+
+ ::rtl::OUString aProductName;
+ ::utl::ConfigManager::GetDirectConfigProperty(::utl::ConfigManager::PRODUCTNAME) >>= aProductName;
+
+ aTitle += String::CreateFromAscii( " - " );
+ aTitle += String(aProductName);
+ aTitle += ' ';
+ ::rtl::OUString aDocServiceName( GetObjectShell()->GetFactory().GetDocumentServiceName() );
+ aTitle += String( GetModuleName_Impl( aDocServiceName ) );
+#ifdef DBG_UTIL
+ ::rtl::OUString aDefault;
+ aTitle += DEFINE_CONST_UNICODE(" [");
+ String aVerId( utl::Bootstrap::getBuildIdData( aDefault ));
+ aTitle += aVerId;
+ aTitle += ']';
+#endif
+
+ // append TAB string if available
+ aTitle += _getTabString();
+
+ GetBindings().Invalidate( SID_NEWDOCDIRECT );
+
+ /* AS_TITLE
+ Window* pWindow = GetFrame()->GetTopWindow_Impl();
+ if ( pWindow && pWindow->GetText() != aTitle )
+ pWindow->SetText( aTitle );
+ */
+ return aTitle;
+}
+
+void SfxViewFrame::Exec_Impl(SfxRequest &rReq )
+{
+ // Wenn gerade die Shells ausgetauscht werden...
+ if ( !GetObjectShell() || !GetViewShell() )
+ return;
+
+ switch ( rReq.GetSlot() )
+ {
+ case SID_SHOWPOPUPS :
+ {
+ SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, SID_SHOWPOPUPS, FALSE);
+ BOOL bShow = pShowItem ? pShowItem->GetValue() : TRUE;
+ SFX_REQUEST_ARG(rReq, pIdItem, SfxUInt16Item, SID_CONFIGITEMID, FALSE);
+ USHORT nId = pIdItem ? pIdItem->GetValue() : 0;
+
+ // ausfuehren
+ SfxWorkWindow *pWorkWin = GetFrame().GetWorkWindow_Impl();
+ if ( bShow )
+ {
+ // Zuerst die Floats auch anzeigbar machen
+ pWorkWin->MakeChildsVisible_Impl( bShow );
+ GetDispatcher()->Update_Impl( TRUE );
+
+ // Dann anzeigen
+ GetBindings().HidePopups( !bShow );
+ }
+ else
+ {
+ // Alles hiden
+ SfxBindings *pBind = &GetBindings();
+ while ( pBind )
+ {
+ pBind->HidePopupCtrls_Impl( !bShow );
+ pBind = pBind->GetSubBindings_Impl();
+ }
+
+ pWorkWin->HidePopups_Impl( !bShow, TRUE, nId );
+ pWorkWin->MakeChildsVisible_Impl( bShow );
+ }
+
+ Invalidate( rReq.GetSlot() );
+ rReq.Done();
+ break;
+ }
+
+ case SID_ACTIVATE:
+ {
+ MakeActive_Impl( TRUE );
+ rReq.SetReturnValue( SfxObjectItem( 0, this ) );
+ break;
+ }
+
+ case SID_NEWDOCDIRECT :
+ {
+ SFX_REQUEST_ARG( rReq, pFactoryItem, SfxStringItem, SID_NEWDOCDIRECT, FALSE);
+ String aFactName;
+ if ( pFactoryItem )
+ aFactName = pFactoryItem->GetValue();
+ else if ( pImp->aFactoryName.Len() )
+ aFactName = pImp->aFactoryName;
+ else
+ {
+ DBG_ERROR("Missing argument!");
+ break;
+ }
+
+ SfxRequest aReq( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, GetPool() );
+ String aFact = String::CreateFromAscii("private:factory/");
+ aFact += aFactName;
+ aReq.AppendItem( SfxStringItem( SID_FILE_NAME, aFact ) );
+ aReq.AppendItem( SfxFrameItem( SID_DOCFRAME, &GetFrame() ) );
+ aReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii( "_blank" ) ) );
+ SFX_APP()->ExecuteSlot( aReq );
+ const SfxViewFrameItem* pItem = PTR_CAST( SfxViewFrameItem, aReq.GetReturnValue() );
+ if ( pItem )
+ rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) );
+ break;
+ }
+
+ case SID_CLOSEWIN:
+ {
+ // disable CloseWin, if frame is not a task
+ Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
+ if ( !xTask.is() )
+ break;
+
+ if ( GetViewShell()->PrepareClose() )
+ {
+ // weitere Views auf dasselbe Doc?
+ SfxObjectShell *pDocSh = GetObjectShell();
+ int bOther = sal_False;
+ for ( const SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocSh );
+ !bOther && pFrame;
+ pFrame = SfxViewFrame::GetNext( *pFrame, pDocSh ) )
+ bOther = (pFrame != this);
+
+ // Doc braucht nur gefragt zu werden, wenn keine weitere View
+ sal_Bool bClosed = sal_False;
+ sal_Bool bUI = TRUE;
+ if ( ( bOther || pDocSh->PrepareClose( bUI ) ) )
+ {
+ if ( !bOther )
+ pDocSh->SetModified( FALSE );
+ rReq.Done(); // unbedingt vor Close() rufen!
+ bClosed = sal_False;
+ try
+ {
+ xTask->close(sal_True);
+ bClosed = sal_True;
+ }
+ catch( CloseVetoException& )
+ {
+ bClosed = sal_False;
+ }
+ }
+
+ rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bClosed ));
+ }
+ return;
+ }
+ }
+
+ rReq.Done();
+}
+
+void SfxViewFrame::GetState_Impl( SfxItemSet &rSet )
+{
+ SfxObjectShell *pDocSh = GetObjectShell();
+
+ if ( !pDocSh )
+ return;
+
+ const sal_uInt16 *pRanges = rSet.GetRanges();
+ DBG_ASSERT(pRanges, "Set ohne Bereich");
+ while ( *pRanges )
+ {
+ for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
+ {
+ switch(nWhich)
+ {
+ case SID_NEWDOCDIRECT :
+ {
+ if ( pImp->aFactoryName.Len() )
+ {
+ String aFact = String::CreateFromAscii("private:factory/");
+ aFact += pImp->aFactoryName;
+ rSet.Put( SfxStringItem( nWhich, aFact ) );
+ }
+ break;
+ }
+
+ case SID_NEWWINDOW:
+ rSet.DisableItem(nWhich);
+ break;
+
+ case SID_CLOSEWIN:
+ {
+ // disable CloseWin, if frame is not a task
+ Reference < XCloseable > xTask( GetFrame().GetFrameInterface(), UNO_QUERY );
+ if ( !xTask.is() )
+ rSet.DisableItem(nWhich);
+ break;
+ }
+
+ case SID_SHOWPOPUPS :
+ break;
+
+ case SID_OBJECT:
+ if ( GetViewShell() && GetViewShell()->GetVerbs().getLength() && !GetObjectShell()->IsInPlaceActive() )
+ {
+ uno::Any aAny;
+ aAny <<= GetViewShell()->GetVerbs();
+ rSet.Put( SfxUnoAnyItem( USHORT( SID_OBJECT ), aAny ) );
+ }
+ else
+ rSet.DisableItem( SID_OBJECT );
+ break;
+
+ default:
+ DBG_ERROR( "invalid message-id" );
+ }
+ }
+ ++pRanges;
+ }
+}
+
+void SfxViewFrame::INetExecute_Impl( SfxRequest &rRequest )
+{
+ sal_uInt16 nSlotId = rRequest.GetSlot();
+ switch( nSlotId )
+ {
+ case SID_BROWSE_FORWARD:
+ case SID_BROWSE_BACKWARD:
+ OSL_ENSURE( false, "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
+ break;
+ case SID_CREATELINK:
+ {
+/*! (pb) we need new implementation to create a link
+*/
+ break;
+ }
+ case SID_FOCUSURLBOX:
+ {
+ SfxStateCache *pCache = GetBindings().GetAnyStateCache_Impl( SID_OPENURL );
+ if( pCache )
+ {
+ SfxControllerItem* pCtrl = pCache->GetItemLink();
+ while( pCtrl )
+ {
+ pCtrl->StateChanged( SID_FOCUSURLBOX, SFX_ITEM_UNKNOWN, 0 );
+ pCtrl = pCtrl->GetItemLink();
+ }
+ }
+ }
+ }
+
+ // Recording
+ rRequest.Done();
+}
+
+void SfxViewFrame::INetState_Impl( SfxItemSet &rItemSet )
+{
+ rItemSet.DisableItem( SID_BROWSE_FORWARD );
+ rItemSet.DisableItem( SID_BROWSE_BACKWARD );
+
+ // Add/SaveToBookmark bei BASIC-IDE, QUERY-EDITOR etc. disablen
+ SfxObjectShell *pDocSh = GetObjectShell();
+ sal_Bool bPseudo = pDocSh && !( pDocSh->GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC );
+ sal_Bool bEmbedded = pDocSh && pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED;
+ if ( !pDocSh || bPseudo || bEmbedded || !pDocSh->HasName() )
+ rItemSet.DisableItem( SID_CREATELINK );
+}
+
+void SfxViewFrame::SetZoomFactor( const Fraction &rZoomX, const Fraction &rZoomY )
+{
+ GetViewShell()->SetZoomFactor( rZoomX, rZoomY );
+}
+
+void SfxViewFrame::Activate( sal_Bool bMDI )
+{
+ DBG_ASSERT(GetViewShell(), "Keine Shell");
+ if ( bMDI )
+ pImp->bActive = sal_True;
+//(mba): hier evtl. wie in Beanframe NotifyEvent ?!
+}
+
+void SfxViewFrame::Deactivate( sal_Bool bMDI )
+{
+ DBG_ASSERT(GetViewShell(), "Keine Shell");
+ if ( bMDI )
+ pImp->bActive = sal_False;
+//(mba): hier evtl. wie in Beanframe NotifyEvent ?!
+}
diff --git a/sfx2/source/view/viewimp.hxx b/sfx2/source/view/viewimp.hxx
new file mode 100644
index 000000000000..0826e78870bb
--- /dev/null
+++ b/sfx2/source/view/viewimp.hxx
@@ -0,0 +1,85 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef SFX_VIEWIMP_HXX
+#define SFX_VIEWIMP_HXX
+
+// include ---------------------------------------------------------------
+
+#include <basic/sbxobj.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/viewfrm.hxx> // SvBorder
+#include <osl/mutex.hxx>
+#include <cppuhelper/interfacecontainer.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <svtools/acceleratorexecute.hxx>
+#include <rtl/ref.hxx>
+#include <vcl/print.hxx>
+#include <queue>
+
+// forward ---------------------------------------------------------------
+
+class SfxOfficeDispatch;
+class SfxBaseController;
+
+typedef SfxShell* SfxShellPtr_Impl;
+SV_DECL_PTRARR( SfxShellArr_Impl, SfxShellPtr_Impl, 4, 4 )
+
+class SfxClipboardChangeListener;
+
+struct SfxViewShell_Impl
+{
+ ::osl::Mutex aMutex;
+ ::cppu::OInterfaceContainerHelper aInterceptorContainer;
+ bool m_bControllerSet;
+ SfxShellArr_Impl aArr;
+ SvBorder aBorder;
+ Size aOptimalSize;
+ Size aMargin;
+ USHORT m_nPrinterLocks;
+ bool m_bCanPrint;
+ bool m_bHasPrintOptions;
+ bool m_bPlugInsActive;
+ bool m_bIsShowView;
+ // FIXME UNUSED ???
+ //bool m_bOwnsMenu;
+ bool m_bGotOwnership;
+ bool m_bGotFrameOwnership;
+ SfxScrollingMode m_eScroll;
+ USHORT m_nFamily;
+ ::rtl::Reference<SfxBaseController> m_pController;
+ ::std::auto_ptr< ::svt::AcceleratorExecute > m_pAccExec;
+ com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aPrintOpts;
+ ::rtl::Reference< SfxClipboardChangeListener > xClipboardListener;
+ ::boost::shared_ptr< vcl::PrinterController > m_pPrinterController;
+
+ SfxViewShell_Impl(USHORT const nFlags);
+};
+
+#endif
+
diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
new file mode 100644
index 000000000000..24ed85556466
--- /dev/null
+++ b/sfx2/source/view/viewprn.cxx
@@ -0,0 +1,914 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+
+#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/view/PrintableState.hpp>
+#include "com/sun/star/view/XRenderable.hpp"
+
+#include <svl/itempool.hxx>
+#include <vcl/msgbox.hxx>
+#include <svtools/prnsetup.hxx>
+#include <svl/flagitem.hxx>
+#include <svl/stritem.hxx>
+#include <svl/intitem.hxx>
+#include <svl/eitem.hxx>
+#include <sfx2/app.hxx>
+#include <unotools/useroptions.hxx>
+#include <unotools/printwarningoptions.hxx>
+#include <tools/datetime.hxx>
+#include <sfx2/bindings.hxx>
+#include <sfx2/objface.hxx>
+#include <sfx2/viewsh.hxx>
+#include "viewimp.hxx"
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/prnmon.hxx>
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/request.hxx>
+#include <sfx2/objsh.hxx>
+#include "sfxtypes.hxx"
+#include <sfx2/event.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+
+#include "toolkit/awt/vclxdevice.hxx"
+
+#include "view.hrc"
+#include "helpid.hrc"
+
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+
+TYPEINIT1(SfxPrintingHint, SfxHint);
+
+// -----------------------------------------------------------------------
+class SfxPrinterController : public vcl::PrinterController, public SfxListener
+{
+ Any maCompleteSelection;
+ Any maSelection;
+ Reference< view::XRenderable > mxRenderable;
+ mutable Printer* mpLastPrinter;
+ mutable Reference<awt::XDevice> mxDevice;
+ SfxViewShell* mpViewShell;
+ SfxObjectShell* mpObjectShell;
+ sal_Bool m_bOrigStatus;
+ sal_Bool m_bNeedsChange;
+ sal_Bool m_bApi;
+ util::DateTime m_aLastPrinted;
+ ::rtl::OUString m_aLastPrintedBy;
+
+ Sequence< beans::PropertyValue > getMergedOptions() const;
+ const Any& getSelectionObject() const;
+public:
+ SfxPrinterController( const Any& i_rComplete,
+ const Any& i_rSelection,
+ const Any& i_rViewProp,
+ const Reference< view::XRenderable >& i_xRender,
+ sal_Bool i_bApi, sal_Bool i_bDirect,
+ SfxViewShell* pView,
+ const uno::Sequence< beans::PropertyValue >& rProps
+ );
+
+ virtual ~SfxPrinterController();
+ virtual void Notify( SfxBroadcaster&, const SfxHint& );
+
+ virtual int getPageCount() const;
+ virtual Sequence< beans::PropertyValue > getPageParameters( int i_nPage ) const;
+ virtual void printPage( int i_nPage ) const;
+ virtual void jobStarted();
+ virtual void jobFinished( com::sun::star::view::PrintableState );
+};
+
+SfxPrinterController::SfxPrinterController( const Any& i_rComplete,
+ const Any& i_rSelection,
+ const Any& i_rViewProp,
+ const Reference< view::XRenderable >& i_xRender,
+ sal_Bool i_bApi, sal_Bool i_bDirect,
+ SfxViewShell* pView,
+ const uno::Sequence< beans::PropertyValue >& rProps
+ )
+ : maCompleteSelection( i_rComplete )
+ , maSelection( i_rSelection )
+ , mxRenderable( i_xRender )
+ , mpLastPrinter( NULL )
+ , mpViewShell( pView )
+ , mpObjectShell(0)
+ , m_bOrigStatus( sal_False )
+ , m_bNeedsChange( sal_False )
+ , m_bApi(i_bApi)
+{
+ if ( mpViewShell )
+ {
+ StartListening( *mpViewShell );
+ mpObjectShell = mpViewShell->GetObjectShell();
+ StartListening( *mpObjectShell );
+ }
+
+ // initialize extra ui options
+ if( mxRenderable.is() )
+ {
+ for (sal_Int32 nProp=0; nProp<rProps.getLength(); nProp++)
+ setValue( rProps[nProp].Name, rProps[nProp].Value );
+
+ Sequence< beans::PropertyValue > aRenderOptions( 3 );
+ aRenderOptions[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ExtraPrintUIOptions" ) );
+ aRenderOptions[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "View" ) );
+ aRenderOptions[1].Value = i_rViewProp;
+ aRenderOptions[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsPrinter" ) );
+ aRenderOptions[2].Value <<= sal_True;
+ try
+ {
+ Sequence< beans::PropertyValue > aRenderParms( mxRenderable->getRenderer( 0 , getSelectionObject(), aRenderOptions ) );
+ int nProps = aRenderParms.getLength();
+ for( int i = 0; i < nProps; i++ )
+ {
+ if( aRenderParms[i].Name.equalsAscii( "ExtraPrintUIOptions" ) )
+ {
+ Sequence< beans::PropertyValue > aUIProps;
+ aRenderParms[i].Value >>= aUIProps;
+ setUIOptions( aUIProps );
+ break;
+ }
+ }
+ }
+ catch( lang::IllegalArgumentException& )
+ {
+ // the first renderer should always be available for the UI options,
+ // but catch the exception to be safe
+ }
+ }
+
+ // set some job parameters
+ setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsApi" ) ), makeAny( i_bApi ) );
+ setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDirect" ) ), makeAny( i_bDirect ) );
+ setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsPrinter" ) ), makeAny( sal_True ) );
+ setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "View" ) ), i_rViewProp );
+}
+
+void SfxPrinterController::Notify( SfxBroadcaster& , const SfxHint& rHint )
+{
+ if ( rHint.IsA(TYPE(SfxSimpleHint)) )
+ {
+ if ( ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
+ {
+ EndListening(*mpViewShell);
+ EndListening(*mpObjectShell);
+ mpViewShell = 0;
+ mpObjectShell = 0;
+ }
+ }
+}
+
+SfxPrinterController::~SfxPrinterController()
+{
+}
+
+const Any& SfxPrinterController::getSelectionObject() const
+{
+ sal_Int32 nChoice = 0;
+ sal_Bool bSel = sal_False;
+ const beans::PropertyValue* pVal = getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintContent" ) ) );
+ if( pVal )
+ pVal->Value >>= nChoice;
+ pVal = getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintSelectionOnly" ) ) );
+ if( pVal )
+ pVal->Value >>= bSel;
+ return (nChoice > 1 || bSel) ? maSelection : maCompleteSelection;
+}
+
+Sequence< beans::PropertyValue > SfxPrinterController::getMergedOptions() const
+{
+ boost::shared_ptr<Printer> pPrinter( getPrinter() );
+ if( pPrinter.get() != mpLastPrinter )
+ {
+ mpLastPrinter = pPrinter.get();
+ VCLXDevice* pXDevice = new VCLXDevice();
+ pXDevice->SetOutputDevice( mpLastPrinter );
+ mxDevice = Reference< awt::XDevice >( pXDevice );
+ }
+
+ Sequence< beans::PropertyValue > aRenderOptions( 1 );
+ aRenderOptions[ 0 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RenderDevice" ) );
+ aRenderOptions[ 0 ].Value <<= mxDevice;
+
+ aRenderOptions = getJobProperties( aRenderOptions );
+ return aRenderOptions;
+}
+
+int SfxPrinterController::getPageCount() const
+{
+ int nPages = 0;
+ boost::shared_ptr<Printer> pPrinter( getPrinter() );
+ if( mxRenderable.is() && pPrinter )
+ {
+ Sequence< beans::PropertyValue > aJobOptions( getMergedOptions() );
+ nPages = mxRenderable->getRendererCount( getSelectionObject(), aJobOptions );
+ }
+ return nPages;
+}
+
+Sequence< beans::PropertyValue > SfxPrinterController::getPageParameters( int i_nPage ) const
+{
+ boost::shared_ptr<Printer> pPrinter( getPrinter() );
+ Sequence< beans::PropertyValue > aResult;
+
+ if( mxRenderable.is() && pPrinter )
+ {
+ Sequence< beans::PropertyValue > aJobOptions( getMergedOptions() );
+ try
+ {
+ aResult = mxRenderable->getRenderer( i_nPage, getSelectionObject(), aJobOptions );
+ }
+ catch( lang::IllegalArgumentException& )
+ {
+ }
+ }
+ return aResult;
+}
+
+void SfxPrinterController::printPage( int i_nPage ) const
+{
+ boost::shared_ptr<Printer> pPrinter( getPrinter() );
+ if( mxRenderable.is() && pPrinter )
+ {
+ Sequence< beans::PropertyValue > aJobOptions( getMergedOptions() );
+ try
+ {
+ mxRenderable->render( i_nPage, getSelectionObject(), aJobOptions );
+ }
+ catch( lang::IllegalArgumentException& )
+ {
+ // don't care enough about nonexistant page here
+ // to provoke a crash
+ }
+ }
+}
+
+void SfxPrinterController::jobStarted()
+{
+ if ( mpObjectShell )
+ {
+ m_bOrigStatus = mpObjectShell->IsEnableSetModified();
+
+ // check configuration: shall update of printing information in DocInfo set the document to "modified"?
+ if ( m_bOrigStatus && !SvtPrintWarningOptions().IsModifyDocumentOnPrintingAllowed() )
+ {
+ mpObjectShell->EnableSetModified( sal_False );
+ m_bNeedsChange = sal_True;
+ }
+
+ // refresh document info
+ uno::Reference<document::XDocumentProperties> xDocProps(mpObjectShell->getDocProperties());
+ m_aLastPrintedBy = xDocProps->getPrintedBy();
+ m_aLastPrinted = xDocProps->getPrintDate();
+
+ xDocProps->setPrintedBy( mpObjectShell->IsUseUserData()
+ ? ::rtl::OUString( SvtUserOptions().GetFullName() )
+ : ::rtl::OUString() );
+ ::DateTime now;
+
+ xDocProps->setPrintDate( util::DateTime(
+ now.Get100Sec(), now.GetSec(), now.GetMin(), now.GetHour(),
+ now.GetDay(), now.GetMonth(), now.GetYear() ) );
+
+ // FIXME: how to get all print options incl. AdditionalOptions easily?
+ uno::Sequence < beans::PropertyValue > aOpts;
+ mpObjectShell->Broadcast( SfxPrintingHint( view::PrintableState_JOB_STARTED, aOpts ) );
+ }
+}
+
+void SfxPrinterController::jobFinished( com::sun::star::view::PrintableState nState )
+{
+ if ( mpObjectShell )
+ {
+ mpObjectShell->Broadcast( SfxPrintingHint( nState ) );
+ switch ( nState )
+ {
+ case view::PrintableState_JOB_FAILED :
+ {
+ // "real" problem (not simply printing cancelled by user)
+ String aMsg( SfxResId( STR_NOSTARTPRINTER ) );
+ if ( !m_bApi )
+ ErrorBox( mpViewShell->GetWindow(), WB_OK | WB_DEF_OK, aMsg ).Execute();
+ // intentionally no break
+ }
+ case view::PrintableState_JOB_ABORTED :
+ {
+ // printing not succesful, reset DocInfo
+ uno::Reference<document::XDocumentProperties> xDocProps(mpObjectShell->getDocProperties());
+ xDocProps->setPrintedBy(m_aLastPrintedBy);
+ xDocProps->setPrintDate(m_aLastPrinted);
+ break;
+ }
+
+ case view::PrintableState_JOB_SPOOLED :
+ case view::PrintableState_JOB_COMPLETED :
+ {
+ SfxBindings& rBind = mpViewShell->GetViewFrame()->GetBindings();
+ rBind.Invalidate( SID_PRINTDOC );
+ rBind.Invalidate( SID_PRINTDOCDIRECT );
+ rBind.Invalidate( SID_SETUPPRINTER );
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ if ( m_bNeedsChange )
+ mpObjectShell->EnableSetModified( m_bOrigStatus );
+
+ if ( mpViewShell )
+ {
+ mpViewShell->pImp->m_pPrinterController.reset();
+ }
+ }
+}
+
+//====================================================================
+
+class SfxDialogExecutor_Impl
+
+/* [Beschreibung]
+
+ Eine Instanz dieser Klasse wird f"ur die Laufzeit des Printer-Dialogs
+ erzeugt, um im dessen Click-Handler f"ur die Zus"atze den per
+ virtueller Methode von der abgeleiteten SfxViewShell erzeugten
+ Print-Options-Dialog zu erzeugen und die dort eingestellten Optionen
+ als SfxItemSet zu zwischenzuspeichern.
+*/
+
+{
+private:
+ SfxViewShell* _pViewSh;
+ PrinterSetupDialog* _pSetupParent;
+ SfxItemSet* _pOptions;
+ sal_Bool _bModified;
+ sal_Bool _bHelpDisabled;
+
+ DECL_LINK( Execute, void * );
+
+public:
+ SfxDialogExecutor_Impl( SfxViewShell* pViewSh, PrinterSetupDialog* pParent );
+ ~SfxDialogExecutor_Impl() { delete _pOptions; }
+
+ Link GetLink() const { return LINK( this, SfxDialogExecutor_Impl, Execute); }
+ const SfxItemSet* GetOptions() const { return _pOptions; }
+ void DisableHelp() { _bHelpDisabled = sal_True; }
+};
+
+//--------------------------------------------------------------------
+
+SfxDialogExecutor_Impl::SfxDialogExecutor_Impl( SfxViewShell* pViewSh, PrinterSetupDialog* pParent ) :
+
+ _pViewSh ( pViewSh ),
+ _pSetupParent ( pParent ),
+ _pOptions ( NULL ),
+ _bModified ( sal_False ),
+ _bHelpDisabled ( sal_False )
+
+{
+}
+
+//--------------------------------------------------------------------
+
+IMPL_LINK( SfxDialogExecutor_Impl, Execute, void *, EMPTYARG )
+{
+ // Options lokal merken
+ if ( !_pOptions )
+ {
+ DBG_ASSERT( _pSetupParent, "no dialog parent" );
+ if( _pSetupParent )
+ _pOptions = ( (SfxPrinter*)_pSetupParent->GetPrinter() )->GetOptions().Clone();
+ }
+
+ // Dialog ausf"uhren
+ SfxPrintOptionsDialog* pDlg = new SfxPrintOptionsDialog( static_cast<Window*>(_pSetupParent),
+ _pViewSh, _pOptions );
+ if ( _bHelpDisabled )
+ pDlg->DisableHelp();
+ if ( pDlg->Execute() == RET_OK )
+ {
+ delete _pOptions;
+ _pOptions = pDlg->GetOptions().Clone();
+
+ }
+ delete pDlg;
+
+ return 0;
+}
+
+//-------------------------------------------------------------------------
+
+BOOL UseStandardPrinter_Impl( Window* /*pParent*/, SfxPrinter* pDocPrinter )
+{
+ // Optionen abfragen, ob gewarnt werden soll (Doc uebersteuert App)
+ BOOL bWarn = FALSE;
+ const SfxItemSet *pDocOptions = &pDocPrinter->GetOptions();
+ if ( pDocOptions )
+ {
+ USHORT nWhich = pDocOptions->GetPool()->GetWhich(SID_PRINTER_NOTFOUND_WARN);
+ const SfxBoolItem* pBoolItem = NULL;
+ pDocPrinter->GetOptions().GetItemState( nWhich, FALSE, (const SfxPoolItem**) &pBoolItem );
+ if ( pBoolItem )
+ bWarn = pBoolItem->GetValue();
+ }
+/*
+ // ggf. den User fragen
+ if ( bWarn )
+ {
+ // Geht nicht mehr ohne OrigJobSetup!
+ String aTmp( SfxResId( STR_PRINTER_NOTAVAIL ) );
+ QueryBox aBox( pParent, WB_OK_CANCEL | WB_DEF_OK, aTmp );
+ return RET_OK == aBox.Execute();
+ }
+*/
+ // nicht gewarnt => einfach so den StandardDrucker nehmen
+ return TRUE;
+}
+//-------------------------------------------------------------------------
+
+SfxPrinter* SfxViewShell::SetPrinter_Impl( SfxPrinter *pNewPrinter )
+
+/* Interne Methode zum Setzen der Unterschiede von 'pNewPrinter' zum
+ aktuellen Printer. pNewPrinter wird entweder "ubernommen oder gel"oscht.
+*/
+
+{
+ // aktuellen Printer holen
+ SfxPrinter *pDocPrinter = GetPrinter();
+
+ // Printer-Options auswerten
+ FASTBOOL bOriToDoc = FALSE;
+ FASTBOOL bSizeToDoc = FALSE;
+ if ( &pDocPrinter->GetOptions() )
+ {
+ USHORT nWhich = GetPool().GetWhich(SID_PRINTER_CHANGESTODOC);
+ const SfxFlagItem *pFlagItem = 0;
+ pDocPrinter->GetOptions().GetItemState( nWhich, FALSE, (const SfxPoolItem**) &pFlagItem );
+ bOriToDoc = pFlagItem ? (pFlagItem->GetValue() & SFX_PRINTER_CHG_ORIENTATION) : FALSE;
+ bSizeToDoc = pFlagItem ? (pFlagItem->GetValue() & SFX_PRINTER_CHG_SIZE) : FALSE;
+ }
+
+ // vorheriges Format und Size feststellen
+ Orientation eOldOri = pDocPrinter->GetOrientation();
+ Size aOldPgSz = pDocPrinter->GetPaperSizePixel();
+
+ // neues Format und Size feststellen
+ Orientation eNewOri = pNewPrinter->GetOrientation();
+ Size aNewPgSz = pNewPrinter->GetPaperSizePixel();
+
+ // "Anderungen am Seitenformat feststellen
+ BOOL bOriChg = (eOldOri != eNewOri) && bOriToDoc;
+ BOOL bPgSzChg = ( aOldPgSz.Height() !=
+ ( bOriChg ? aNewPgSz.Width() : aNewPgSz.Height() ) ||
+ aOldPgSz.Width() !=
+ ( bOriChg ? aNewPgSz.Height() : aNewPgSz.Width() ) ) &&
+ bSizeToDoc;
+
+ // Message und Flags f"ur Seitenformat-"Anderung zusammenstellen
+ String aMsg;
+ USHORT nNewOpt=0;
+ if( bOriChg && bPgSzChg )
+ {
+ aMsg = String(SfxResId(STR_PRINT_NEWORISIZE));
+ nNewOpt = SFX_PRINTER_CHG_ORIENTATION | SFX_PRINTER_CHG_SIZE;
+ }
+ else if (bOriChg )
+ {
+ aMsg = String(SfxResId(STR_PRINT_NEWORI));
+ nNewOpt = SFX_PRINTER_CHG_ORIENTATION;
+ }
+ else if (bPgSzChg)
+ {
+ aMsg = String(SfxResId(STR_PRINT_NEWSIZE));
+ nNewOpt = SFX_PRINTER_CHG_SIZE;
+ }
+
+ // in dieser Variable sammeln, was sich so ge"aendert hat
+ USHORT nChangedFlags = 0;
+
+ // ggf. Nachfrage, ob Seitenformat vom Drucker "ubernommen werden soll
+ if ( ( bOriChg || bPgSzChg ) &&
+ RET_YES == QueryBox(0, WB_YES_NO | WB_DEF_OK, aMsg).Execute() )
+ // Flags mit "Anderungen f"ur <SetPrinter(SfxPrinter*)> mitpflegen
+ nChangedFlags |= nNewOpt;
+
+ // fuer den MAC sein "temporary of class String" im naechsten if()
+ String aTempPrtName = pNewPrinter->GetName();
+ String aDocPrtName = pDocPrinter->GetName();
+
+ // Wurde der Drucker gewechselt oder von Default auf Specific
+ // oder umgekehrt geaendert?
+ if ( (aTempPrtName != aDocPrtName) || (pDocPrinter->IsDefPrinter() != pNewPrinter->IsDefPrinter()) )
+ {
+ // neuen Printer "ubernehmen
+ // pNewPrinter->SetOrigJobSetup( pNewPrinter->GetJobSetup() );
+ nChangedFlags |= SFX_PRINTER_PRINTER|SFX_PRINTER_JOBSETUP;
+ pDocPrinter = pNewPrinter;
+ }
+ else
+ {
+ // Extra-Optionen vergleichen
+ if ( ! (pNewPrinter->GetOptions() == pDocPrinter->GetOptions()) )
+ {
+ // Options haben sich geaendert
+ pDocPrinter->SetOptions( pNewPrinter->GetOptions() );
+ nChangedFlags |= SFX_PRINTER_OPTIONS;
+ }
+
+ // JobSetups vergleichen
+ JobSetup aNewJobSetup = pNewPrinter->GetJobSetup();
+ JobSetup aOldJobSetup = pDocPrinter->GetJobSetup();
+ if ( aNewJobSetup != aOldJobSetup )
+ {
+ // JobSetup hat sich geaendert (=> App mu\s neu formatieren)
+ // pDocPrinter->SetOrigJobSetup( aNewJobSetup );
+ nChangedFlags |= SFX_PRINTER_JOBSETUP;
+ }
+
+ // alten, ver"anderten Printer behalten
+ pDocPrinter->SetPrinterProps( pNewPrinter );
+ delete pNewPrinter;
+ }
+
+ if ( 0 != nChangedFlags )
+ // SetPrinter will delete the old printer if it changes
+ SetPrinter( pDocPrinter, nChangedFlags );
+ return pDocPrinter;
+}
+
+//-------------------------------------------------------------------------
+// Unter WIN32 tritt leider das Problem auf, dass nichts gedruckt
+// wird, wenn SID_PRINTDOCDIRECT auflaueft; bisher bekannte,
+// einzige Abhilfe ist in diesem Fall das Abschalten der Optimierungen
+// (KA 17.12.95)
+#ifdef _MSC_VER
+#pragma optimize ( "", off )
+#endif
+
+void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rProps, sal_Bool bIsAPI, sal_Bool bIsDirect )
+{
+ // get the current selection; our controller should know it
+ Reference< frame::XController > xController( GetController() );
+ Reference< view::XSelectionSupplier > xSupplier( xController, UNO_QUERY );
+
+ Any aSelection;
+ if( xSupplier.is() )
+ aSelection = xSupplier->getSelection();
+ else
+ aSelection <<= GetObjectShell()->GetModel();
+ Any aComplete( makeAny( GetObjectShell()->GetModel() ) );
+ Any aViewProp( makeAny( xController ) );
+
+ boost::shared_ptr<vcl::PrinterController> pController( new SfxPrinterController( aComplete,
+ aSelection,
+ aViewProp,
+ GetRenderable(),
+ bIsAPI,
+ bIsDirect,
+ this,
+ rProps
+ ) );
+ pImp->m_pPrinterController = pController;
+
+ SfxObjectShell *pObjShell = GetObjectShell();
+ pController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "JobName" ) ),
+ makeAny( rtl::OUString( pObjShell->GetTitle(0) ) ) );
+
+ // FIXME: job setup
+ SfxPrinter* pDocPrt = GetPrinter(FALSE);
+ JobSetup aJobSetup = pDocPrt ? pDocPrt->GetJobSetup() : GetJobSetup();
+ if( bIsDirect )
+ aJobSetup.SetValue( String( RTL_CONSTASCII_USTRINGPARAM( "IsQuickJob" ) ),
+ String( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) );
+
+ Printer::PrintJob( pController, aJobSetup );
+}
+
+Printer* SfxViewShell::GetActivePrinter() const
+{
+ return (pImp->m_pPrinterController)
+ ? pImp->m_pPrinterController->getPrinter().get() : 0;
+}
+
+void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
+{
+ // USHORT nCopies=1;
+ USHORT nDialogRet = RET_CANCEL;
+ // BOOL bCollate=FALSE;
+ SfxPrinter* pPrinter = 0;
+ SfxDialogExecutor_Impl* pExecutor = 0;
+ bool bSilent = false;
+ BOOL bIsAPI = rReq.GetArgs() && rReq.GetArgs()->Count();
+ if ( bIsAPI )
+ {
+ SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, FALSE);
+ bSilent = pSilentItem && pSilentItem->GetValue();
+ }
+
+ //FIXME: how to transport "bPrintOnHelp"?
+
+ // no help button in dialogs if called from the help window
+ // (pressing help button would exchange the current page inside the help document that is going to be printed!)
+ String aHelpFilterName( DEFINE_CONST_UNICODE("writer_web_HTML_help") );
+ SfxMedium* pMedium = GetViewFrame()->GetObjectShell()->GetMedium();
+ const SfxFilter* pFilter = pMedium ? pMedium->GetFilter() : NULL;
+ sal_Bool bPrintOnHelp = ( pFilter && pFilter->GetFilterName() == aHelpFilterName );
+
+ const USHORT nId = rReq.GetSlot();
+ switch( nId )
+ {
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_PRINTDOC:
+ case SID_PRINTDOCDIRECT:
+ {
+ SfxObjectShell* pDoc = GetObjectShell();
+
+ // derived class may decide to abort this
+ if( !pDoc->QuerySlotExecutable( nId ) )
+ {
+ rReq.SetReturnValue( SfxBoolItem( 0, FALSE ) );
+ return;
+ }
+
+ bool bDetectHidden = ( !bSilent && pDoc );
+ if ( bDetectHidden && pDoc->QueryHiddenInformation( WhenPrinting, NULL ) != RET_YES )
+ break;
+
+ SFX_REQUEST_ARG(rReq, pSelectItem, SfxBoolItem, SID_SELECTION, FALSE);
+ sal_Bool bSelection = pSelectItem && pSelectItem->GetValue();
+ if( pSelectItem && rReq.GetArgs()->Count() == 1 )
+ bIsAPI = FALSE;
+
+ uno::Sequence < beans::PropertyValue > aProps;
+ if ( bIsAPI )
+ {
+ // supported properties:
+ // String PrinterName
+ // String FileName
+ // Int16 From
+ // Int16 To
+ // In16 Copies
+ // String RangeText
+ // bool Selection
+ // bool Asynchron
+ // bool Collate
+ // bool Silent
+ TransformItems( nId, *rReq.GetArgs(), aProps, GetInterface()->GetSlot(nId) );
+ for ( sal_Int32 nProp=0; nProp<aProps.getLength(); nProp++ )
+ {
+ if ( aProps[nProp].Name.equalsAscii("Copies") )
+ aProps[nProp]. Name = rtl::OUString::createFromAscii("CopyCount");
+ else if ( aProps[nProp].Name.equalsAscii("RangeText") )
+ aProps[nProp]. Name = rtl::OUString::createFromAscii("Pages");
+ if ( aProps[nProp].Name.equalsAscii("Asynchron") )
+ {
+ aProps[nProp]. Name = rtl::OUString::createFromAscii("Wait");
+ sal_Bool bAsynchron = sal_False;
+ aProps[nProp].Value >>= bAsynchron;
+ aProps[nProp].Value <<= (sal_Bool) (!bAsynchron);
+ }
+ if ( aProps[nProp].Name.equalsAscii("Silent") )
+ {
+ aProps[nProp]. Name = rtl::OUString::createFromAscii("MonitorVisible");
+ sal_Bool bPrintSilent = sal_False;
+ aProps[nProp].Value >>= bPrintSilent;
+ aProps[nProp].Value <<= (sal_Bool) (!bPrintSilent);
+ }
+ }
+ }
+ sal_Int32 nLen = aProps.getLength();
+ aProps.realloc( nLen + 1 );
+ aProps[nLen].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintSelectionOnly" ) );
+ aProps[nLen].Value = makeAny( bSelection );
+
+ ExecPrint( aProps, bIsAPI, (nId == SID_PRINTDOCDIRECT) );
+
+ // FIXME: Recording
+ rReq.Done();
+ break;
+ }
+
+ case SID_SETUPPRINTER :
+ case SID_PRINTER_NAME : // only for recorded macros
+ {
+ // get printer and printer settings from the document
+ SfxPrinter *pDocPrinter = GetPrinter(TRUE);
+
+ // look for printer in parameters
+ SFX_REQUEST_ARG( rReq, pPrinterItem, SfxStringItem, SID_PRINTER_NAME, FALSE );
+ if ( pPrinterItem )
+ {
+ // use PrinterName parameter to create a printer
+ pPrinter = new SfxPrinter( pDocPrinter->GetOptions().Clone(), ((const SfxStringItem*) pPrinterItem)->GetValue() );
+
+ // if printer is unknown, it can't be used - now printer from document will be used
+ if ( !pPrinter->IsOriginal() )
+ DELETEZ(pPrinter);
+ }
+
+ if ( SID_PRINTER_NAME == nId )
+ {
+ // just set a recorded printer name
+ if ( pPrinter )
+ SetPrinter( pPrinter, SFX_PRINTER_PRINTER );
+ break;
+ }
+
+ // no PrinterName parameter in ItemSet or the PrinterName points to an unknown printer
+ if ( !pPrinter )
+ // use default printer from document
+ pPrinter = pDocPrinter;
+
+ if( !pPrinter || !pPrinter->IsValid() )
+ {
+ // no valid printer either in ItemSet or at the document
+ if ( bSilent )
+ {
+ rReq.SetReturnValue(SfxBoolItem(0,FALSE));
+ break;
+ }
+ else
+ ErrorBox( NULL, WB_OK | WB_DEF_OK, String( SfxResId( STR_NODEFPRINTER ) ) ).Execute();
+ }
+
+ if ( !pPrinter->IsOriginal() && rReq.GetArgs() && !UseStandardPrinter_Impl( NULL, pPrinter ) )
+ {
+ // printer is not available, but standard printer should not be used
+ rReq.SetReturnValue(SfxBoolItem(0,FALSE));
+ break;
+ }
+
+ // FIXME: printer isn't used for printing anymore!
+ if( pPrinter->IsPrinting() )
+ {
+ // if printer is busy, abort printing
+ if ( !bSilent )
+ InfoBox( NULL, String( SfxResId( STR_ERROR_PRINTER_BUSY ) ) ).Execute();
+ rReq.SetReturnValue(SfxBoolItem(0,FALSE));
+ break;
+ }
+
+ // if no arguments are given, retrieve them from a dialog
+ if ( !bIsAPI )
+ {
+ // PrinterDialog needs a temporary printer
+ SfxPrinter* pDlgPrinter = pPrinter->Clone();
+ nDialogRet = 0;
+
+ // execute PrinterSetupDialog
+ PrinterSetupDialog* pPrintSetupDlg = new PrinterSetupDialog( GetWindow() );
+
+ if (pImp->m_bHasPrintOptions)
+ {
+ // additional controls for dialog
+ pExecutor = new SfxDialogExecutor_Impl( this, pPrintSetupDlg );
+ if ( bPrintOnHelp )
+ pExecutor->DisableHelp();
+ pPrintSetupDlg->SetOptionsHdl( pExecutor->GetLink() );
+ }
+
+ pPrintSetupDlg->SetPrinter( pDlgPrinter );
+ nDialogRet = pPrintSetupDlg->Execute();
+
+ if ( pExecutor && pExecutor->GetOptions() )
+ {
+ if ( nDialogRet == RET_OK )
+ // remark: have to be recorded if possible!
+ pDlgPrinter->SetOptions( *pExecutor->GetOptions() );
+ else
+ {
+ pPrinter->SetOptions( *pExecutor->GetOptions() );
+ SetPrinter( pPrinter, SFX_PRINTER_OPTIONS );
+ }
+ }
+
+ DELETEZ( pPrintSetupDlg );
+
+ // no recording of PrinterSetup except printer name (is printer dependent)
+ rReq.Ignore();
+
+ if ( nDialogRet == RET_OK )
+ {
+ if ( pPrinter->GetName() != pDlgPrinter->GetName() )
+ {
+ // user has changed the printer -> macro recording
+ SfxRequest aReq( GetViewFrame(), SID_PRINTER_NAME );
+ aReq.AppendItem( SfxStringItem( SID_PRINTER_NAME, pDlgPrinter->GetName() ) );
+ aReq.Done();
+ }
+
+ // take the changes made in the dialog
+ pPrinter = SetPrinter_Impl( pDlgPrinter );
+
+ // forget new printer, it was taken over (as pPrinter) or deleted
+ pDlgPrinter = NULL;
+
+ }
+ else
+ {
+ // PrinterDialog is used to transfer information on printing,
+ // so it will only be deleted here if dialog was cancelled
+ DELETEZ( pDlgPrinter );
+ rReq.Ignore();
+ if ( SID_PRINTDOC == nId )
+ rReq.SetReturnValue(SfxBoolItem(0,FALSE));
+ }
+ }
+ }
+
+ break;
+ }
+}
+
+// Optimierungen wieder einschalten
+#ifdef _MSC_VER
+#pragma optimize ( "", on )
+#endif
+
+//--------------------------------------------------------------------
+
+BOOL SfxViewShell::IsPrinterLocked() const
+{
+ return pImp->m_nPrinterLocks > 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::LockPrinter( BOOL bLock)
+{
+ BOOL bChanged = FALSE;
+ if ( bLock )
+ {
+ bChanged = 1 == ++pImp->m_nPrinterLocks;
+ }
+ else
+ {
+ bChanged = 0 == --pImp->m_nPrinterLocks;
+ }
+
+ if ( bChanged )
+ {
+ Invalidate( SID_PRINTDOC );
+ Invalidate( SID_PRINTDOCDIRECT );
+ Invalidate( SID_SETUPPRINTER );
+ }
+}
+
+//--------------------------------------------------------------------
+
+SfxPrinter* SfxViewShell::GetPrinter( BOOL /*bCreate*/ )
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+USHORT SfxViewShell::SetPrinter( SfxPrinter* /*pNewPrinter*/, USHORT /*nDiffFlags*/, bool )
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+SfxTabPage* SfxViewShell::CreatePrintOptionsPage
+(
+ Window* /*pParent*/,
+ const SfxItemSet& /*rOptions*/
+)
+{
+ return 0;
+}
+
+JobSetup SfxViewShell::GetJobSetup() const
+{
+ return JobSetup();
+}
+
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
new file mode 100644
index 000000000000..ca3452e24168
--- /dev/null
+++ b/sfx2/source/view/viewsh.cxx
@@ -0,0 +1,2326 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include <svl/stritem.hxx>
+#include <svl/eitem.hxx>
+#include <svl/whiter.hxx>
+#include <vcl/msgbox.hxx>
+#include <vcl/toolbox.hxx>
+#include <svl/intitem.hxx>
+#include <svtools/sfxecode.hxx>
+#include <svtools/ehdl.hxx>
+#include <com/sun/star/frame/XLayoutManager.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/EmbedMisc.hpp>
+#include <com/sun/star/system/XSystemShellExecute.hpp>
+#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
+#include <com/sun/star/container/XContainerQuery.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
+#include <cppuhelper/implbase1.hxx>
+
+#include <osl/file.hxx>
+#include <vos/mutex.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/tempfile.hxx>
+#include <unotools/pathoptions.hxx>
+#include <svtools/miscopt.hxx>
+#include <svtools/soerr.hxx>
+#include <unotools/internaloptions.hxx>
+
+#include <unotools/javaoptions.hxx>
+#include <basic/basmgr.hxx>
+#include <basic/sbuno.hxx>
+#include <framework/actiontriggerhelper.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <toolkit/unohlp.hxx>
+
+
+#include <sfx2/app.hxx>
+#include "view.hrc"
+#include <sfx2/viewsh.hxx>
+#include "viewimp.hxx"
+#include "sfx2/sfxresid.hxx"
+#include <sfx2/request.hxx>
+#include <sfx2/templdlg.hxx>
+#include <sfx2/printer.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/dispatch.hxx>
+#include "arrdecl.hxx"
+#include <sfx2/docfac.hxx>
+#include "view.hrc"
+#include "sfxlocal.hrc"
+#include <sfx2/sfxbasecontroller.hxx>
+#include "sfx2/mailmodelapi.hxx"
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/event.hxx>
+#include <sfx2/fcontnr.hxx>
+#include <sfx2/ipclient.hxx>
+#include "workwin.hxx"
+#include <sfx2/objface.hxx>
+#include <sfx2/docfilt.hxx>
+
+// #110897#
+#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
+#include <comphelper/processfactory.hxx>
+#endif
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::system;
+using namespace ::cppu;
+namespace css = ::com::sun::star;
+
+//=========================================================================
+DBG_NAME(SfxViewShell)
+
+#define SfxViewShell
+#include "sfxslots.hxx"
+
+//=========================================================================
+
+class SfxClipboardChangeListener : public ::cppu::WeakImplHelper1<
+ datatransfer::clipboard::XClipboardListener >
+{
+public:
+ SfxClipboardChangeListener( SfxViewShell* pView, const uno::Reference< datatransfer::clipboard::XClipboardNotifier >& xClpbrdNtfr );
+ virtual ~SfxClipboardChangeListener();
+
+ // XEventListener
+ virtual void SAL_CALL disposing( const lang::EventObject& rEventObject )
+ throw ( uno::RuntimeException );
+
+ // XClipboardListener
+ virtual void SAL_CALL changedContents( const datatransfer::clipboard::ClipboardEvent& rEventObject )
+ throw ( uno::RuntimeException );
+
+ void DisconnectViewShell() { m_pViewShell = NULL; }
+ void ChangedContents();
+
+ enum AsyncExecuteCmd
+ {
+ ASYNCEXECUTE_CMD_DISPOSING,
+ ASYNCEXECUTE_CMD_CHANGEDCONTENTS
+ };
+
+ struct AsyncExecuteInfo
+ {
+ AsyncExecuteInfo( AsyncExecuteCmd eCmd, uno::Reference< datatransfer::clipboard::XClipboardListener > xThis, SfxClipboardChangeListener* pListener ) :
+ m_eCmd( eCmd ), m_xThis( xThis ), m_pListener( pListener ) {}
+
+ AsyncExecuteCmd m_eCmd;
+ uno::Reference< datatransfer::clipboard::XClipboardListener > m_xThis;
+ SfxClipboardChangeListener* m_pListener;
+ };
+
+private:
+ SfxViewShell* m_pViewShell;
+ uno::Reference< datatransfer::clipboard::XClipboardNotifier > m_xClpbrdNtfr;
+ uno::Reference< lang::XComponent > m_xCtrl;
+
+ DECL_STATIC_LINK( SfxClipboardChangeListener, AsyncExecuteHdl_Impl, AsyncExecuteInfo* );
+};
+
+SfxClipboardChangeListener::SfxClipboardChangeListener( SfxViewShell* pView, const uno::Reference< datatransfer::clipboard::XClipboardNotifier >& xClpbrdNtfr )
+ : m_pViewShell( 0 ), m_xClpbrdNtfr( xClpbrdNtfr )
+{
+ m_xCtrl = uno::Reference < lang::XComponent >( pView->GetController(), uno::UNO_QUERY );
+ if ( m_xCtrl.is() )
+ {
+ m_xCtrl->addEventListener( uno::Reference < lang::XEventListener > ( static_cast < lang::XEventListener* >( this ) ) );
+ m_pViewShell = pView;
+ }
+ if ( m_xClpbrdNtfr.is() )
+ {
+ m_xClpbrdNtfr->addClipboardListener( uno::Reference< datatransfer::clipboard::XClipboardListener >(
+ static_cast< datatransfer::clipboard::XClipboardListener* >( this )));
+ }
+}
+
+SfxClipboardChangeListener::~SfxClipboardChangeListener()
+{
+}
+
+void SfxClipboardChangeListener::ChangedContents()
+{
+ const ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if( m_pViewShell )
+ {
+ SfxBindings& rBind = m_pViewShell->GetViewFrame()->GetBindings();
+ rBind.Invalidate( SID_PASTE );
+ rBind.Invalidate( SID_PASTE_SPECIAL );
+ rBind.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
+ }
+}
+
+IMPL_STATIC_LINK_NOINSTANCE( SfxClipboardChangeListener, AsyncExecuteHdl_Impl, AsyncExecuteInfo*, pAsyncExecuteInfo )
+{
+ if ( pAsyncExecuteInfo )
+ {
+ uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( pAsyncExecuteInfo->m_xThis );
+ if ( pAsyncExecuteInfo->m_pListener )
+ {
+ if ( pAsyncExecuteInfo->m_eCmd == ASYNCEXECUTE_CMD_DISPOSING )
+ pAsyncExecuteInfo->m_pListener->DisconnectViewShell();
+ else if ( pAsyncExecuteInfo->m_eCmd == ASYNCEXECUTE_CMD_CHANGEDCONTENTS )
+ pAsyncExecuteInfo->m_pListener->ChangedContents();
+ }
+ }
+ delete pAsyncExecuteInfo;
+
+ return 0;
+}
+
+void SAL_CALL SfxClipboardChangeListener::disposing( const lang::EventObject& /*rEventObject*/ )
+throw ( uno::RuntimeException )
+{
+ // Either clipboard or ViewShell is going to be destroyed -> no interest in listening anymore
+ uno::Reference< lang::XComponent > xCtrl( m_xCtrl );
+ uno::Reference< datatransfer::clipboard::XClipboardNotifier > xNotify( m_xClpbrdNtfr );
+
+ uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( static_cast< datatransfer::clipboard::XClipboardListener* >( this ));
+ if ( xCtrl.is() )
+ xCtrl->removeEventListener( uno::Reference < lang::XEventListener > ( static_cast < lang::XEventListener* >( this )));
+ if ( xNotify.is() )
+ xNotify->removeClipboardListener( xThis );
+
+ // Make asynchronous call to avoid locking SolarMutex which is the
+ // root for many deadlocks, especially in conjuction with the "Windows"
+ // based single thread apartment clipboard code!
+ AsyncExecuteInfo* pInfo = new AsyncExecuteInfo( ASYNCEXECUTE_CMD_DISPOSING, xThis, this );
+ Application::PostUserEvent( STATIC_LINK( 0, SfxClipboardChangeListener, AsyncExecuteHdl_Impl ), pInfo );
+}
+
+void SAL_CALL SfxClipboardChangeListener::changedContents( const datatransfer::clipboard::ClipboardEvent& )
+ throw ( RuntimeException )
+{
+ // Make asynchronous call to avoid locking SolarMutex which is the
+ // root for many deadlocks, especially in conjuction with the "Windows"
+ // based single thread apartment clipboard code!
+ uno::Reference< datatransfer::clipboard::XClipboardListener > xThis( static_cast< datatransfer::clipboard::XClipboardListener* >( this ));
+ AsyncExecuteInfo* pInfo = new AsyncExecuteInfo( ASYNCEXECUTE_CMD_CHANGEDCONTENTS, xThis, this );
+ Application::PostUserEvent( STATIC_LINK( 0, SfxClipboardChangeListener, AsyncExecuteHdl_Impl ), pInfo );
+}
+
+//=========================================================================
+
+static ::rtl::OUString RetrieveLabelFromCommand(
+ const ::rtl::OUString& rCommandURL,
+ const css::uno::Reference< css::frame::XFrame >& rFrame )
+{
+ static css::uno::WeakReference< frame::XModuleManager > s_xModuleManager;
+ static css::uno::WeakReference< container::XNameAccess > s_xNameAccess;
+
+ ::rtl::OUString aLabel;
+ css::uno::Reference< css::frame::XModuleManager > xModuleManager( s_xModuleManager );
+ css::uno::Reference< css::container::XNameAccess > xNameAccess( s_xNameAccess );
+ css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR(
+ ::comphelper::getProcessServiceFactory(), css::uno::UNO_QUERY_THROW);
+
+ try
+ {
+ if ( !xModuleManager.is() )
+ {
+ xModuleManager = css::uno::Reference< css::frame::XModuleManager >(
+ xSMGR->createInstance(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ))),
+ css::uno::UNO_QUERY_THROW );
+ s_xModuleManager = xModuleManager;
+ }
+
+ ::rtl::OUString aModuleIdentifier = xModuleManager->identify( rFrame );
+
+ if ( !xNameAccess.is() )
+ {
+ xNameAccess = css::uno::Reference< css::container::XNameAccess >(
+ xSMGR->createInstance(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.UICommandDescription" ))),
+ css::uno::UNO_QUERY_THROW );
+ s_xNameAccess = xNameAccess;
+ }
+
+ css::uno::Any a = xNameAccess->getByName( aModuleIdentifier );
+ css::uno::Reference< css::container::XNameAccess > xUICommands;
+ a >>= xUICommands;
+
+ rtl::OUString aStr;
+ css::uno::Sequence< css::beans::PropertyValue > aPropSeq;
+
+ a = xUICommands->getByName( rCommandURL );
+ if ( a >>= aPropSeq )
+ {
+ for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
+ {
+ if ( aPropSeq[i].Name.equalsAscii( "Label" ))
+ {
+ aPropSeq[i].Value >>= aStr;
+ break;
+ }
+ }
+ aLabel = aStr;
+ }
+ }
+ catch ( css::uno::Exception& )
+ {
+ }
+
+ return aLabel;
+}
+
+//=========================================================================
+SfxViewShell_Impl::SfxViewShell_Impl(USHORT const nFlags)
+: aInterceptorContainer( aMutex )
+, m_bControllerSet(false)
+, m_nPrinterLocks(0)
+, m_bCanPrint(SFX_VIEW_CAN_PRINT == (nFlags & SFX_VIEW_CAN_PRINT))
+, m_bHasPrintOptions(
+ SFX_VIEW_HAS_PRINTOPTIONS == (nFlags & SFX_VIEW_HAS_PRINTOPTIONS))
+, m_bPlugInsActive(true)
+, m_bIsShowView(SFX_VIEW_NO_SHOW != (nFlags & SFX_VIEW_NO_SHOW))
+, m_bGotOwnership(false)
+, m_bGotFrameOwnership(false)
+, m_eScroll(SCROLLING_DEFAULT)
+, m_nFamily(0xFFFF) // undefined, default set by TemplateDialog
+, m_pController(0)
+, m_pAccExec(0)
+{}
+
+//=========================================================================
+SFX_IMPL_INTERFACE(SfxViewShell,SfxShell,SfxResId(0))
+{
+ SFX_CHILDWINDOW_REGISTRATION( SID_MAIL_CHILDWIN );
+}
+
+TYPEINIT2(SfxViewShell,SfxShell,SfxListener);
+
+//--------------------------------------------------------------------
+/** search for a filter name dependent on type and module
+ */
+
+static ::rtl::OUString impl_retrieveFilterNameFromTypeAndModule(
+ const css::uno::Reference< css::container::XContainerQuery >& rContainerQuery,
+ const ::rtl::OUString& rType,
+ const ::rtl::OUString& rModuleIdentifier,
+ const sal_Int32 nFlags )
+{
+ // Retrieve filter from type
+ css::uno::Sequence< css::beans::NamedValue > aQuery( 2 );
+ aQuery[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ));
+ aQuery[0].Value = css::uno::makeAny( rType );
+ aQuery[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" ));
+ aQuery[1].Value = css::uno::makeAny( rModuleIdentifier );
+
+ css::uno::Reference< css::container::XEnumeration > xEnumeration =
+ rContainerQuery->createSubSetEnumerationByProperties( aQuery );
+
+ ::rtl::OUString aFoundFilterName;
+ while ( xEnumeration->hasMoreElements() )
+ {
+ ::comphelper::SequenceAsHashMap aFilterPropsHM( xEnumeration->nextElement() );
+ ::rtl::OUString aFilterName = aFilterPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "Name" ),
+ ::rtl::OUString() );
+
+ sal_Int32 nFilterFlags = aFilterPropsHM.getUnpackedValueOrDefault(
+ ::rtl::OUString::createFromAscii( "Flags" ),
+ sal_Int32( 0 ) );
+
+ if ( nFilterFlags & nFlags )
+ {
+ aFoundFilterName = aFilterName;
+ break;
+ }
+ }
+
+ return aFoundFilterName;
+}
+
+//--------------------------------------------------------------------
+/** search for an internal typename, which map to the current app module
+ and map also to a "family" of file formats as e.g. PDF/MS Doc/OOo Doc.
+ */
+enum ETypeFamily
+{
+ E_MS_DOC,
+ E_OOO_DOC
+};
+
+::rtl::OUString impl_searchFormatTypeForApp(const css::uno::Reference< css::frame::XFrame >& xFrame ,
+ ETypeFamily eTypeFamily)
+{
+ static ::rtl::OUString SERVICENAME_MODULEMANAGER = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
+
+ try
+ {
+ css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR (::comphelper::getProcessServiceFactory() , css::uno::UNO_QUERY_THROW);
+ css::uno::Reference< css::frame::XModuleManager > xModuleManager(xSMGR->createInstance(SERVICENAME_MODULEMANAGER), css::uno::UNO_QUERY_THROW);
+
+ ::rtl::OUString sModule = xModuleManager->identify(xFrame);
+ ::rtl::OUString sType ;
+
+ switch(eTypeFamily)
+ {
+ case E_MS_DOC:
+ {
+ if (sModule.equalsAscii( "com.sun.star.text.TextDocument" ))
+ sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "writer_MS_Word_97" ));
+ else
+ if (sModule.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ))
+ sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc_MS_Excel_97" ));
+ else
+ if (sModule.equalsAscii( "com.sun.star.drawing.DrawingDocument" ))
+ sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress_MS_PowerPoint_97" ));
+ else
+ if (sModule.equalsAscii( "com.sun.star.presentation.PresentationDocument" ))
+ sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress_MS_PowerPoint_97" ));
+ }
+ break;
+
+ case E_OOO_DOC:
+ {
+ if (sModule.equalsAscii( "com.sun.star.text.TextDocument" ))
+ sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "writer8" ));
+ else
+ if (sModule.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ))
+ sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc8" ));
+ else
+ if (sModule.equalsAscii( "com.sun.star.drawing.DrawingDocument" ))
+ sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "draw8" ));
+ else
+ if (sModule.equalsAscii( "com.sun.star.presentation.PresentationDocument" ))
+ sType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress8" ));
+ }
+ break;
+ }
+
+ return sType;
+ }
+ catch(const css::uno::RuntimeException& exRun)
+ { throw exRun; }
+ catch(const css::uno::Exception&)
+ {}
+
+ return ::rtl::OUString();
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::ExecMisc_Impl( SfxRequest &rReq )
+{
+ const USHORT nId = rReq.GetSlot();
+ switch( nId )
+ {
+ case SID_STYLE_FAMILY :
+ {
+ SFX_REQUEST_ARG(rReq, pItem, SfxUInt16Item, nId, FALSE);
+ if (pItem)
+ {
+ pImp->m_nFamily = pItem->GetValue();
+ }
+ break;
+ }
+
+ case SID_STYLE_CATALOG:
+ {
+ SfxTemplateCatalog aCatalog(
+ SFX_APP()->GetTopWindow(), &GetViewFrame()->GetBindings());
+ aCatalog.Execute();
+ rReq.Ignore();
+ break;
+ }
+ case SID_ACTIVATE_STYLE_APPLY:
+ {
+ com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
+ GetViewFrame()->GetFrame().GetFrameInterface(),
+ com::sun::star::uno::UNO_QUERY);
+
+ Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
+ Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
+ if ( xPropSet.is() )
+ {
+ try
+ {
+ Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
+ aValue >>= xLayoutManager;
+ if ( xLayoutManager.is() )
+ {
+ rtl::OUString aTextResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/textobjectbar" ));
+ uno::Reference< ui::XUIElement > xElement = xLayoutManager->getElement( aTextResString );
+ if(!xElement.is())
+ {
+ rtl::OUString aFrameResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/frameobjectbar" ));
+ xElement = xLayoutManager->getElement( aFrameResString );
+ }
+ if(!xElement.is())
+ {
+ rtl::OUString aOleResString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/oleobjectbar" ));
+ xElement = xLayoutManager->getElement( aOleResString );
+ }
+ if(xElement.is())
+ {
+ uno::Reference< awt::XWindow > xWin( xElement->getRealInterface(), uno::UNO_QUERY_THROW );
+ Window* pWin = VCLUnoHelper::GetWindow( xWin );
+ ToolBox* pTextToolbox = dynamic_cast< ToolBox* >( pWin );
+ if( pTextToolbox )
+ {
+ USHORT nItemCount = pTextToolbox->GetItemCount();
+ for( USHORT nItem = 0; nItem < nItemCount; ++nItem )
+ {
+ USHORT nItemId = pTextToolbox->GetItemId( nItem );
+ const XubString& rCommand = pTextToolbox->GetItemCommand( nItemId );
+ if( rCommand.EqualsAscii( ".uno:StyleApply" ) )
+ {
+ Window* pItemWin = pTextToolbox->GetItemWindow( nItemId );
+ if( pItemWin )
+ pItemWin->GrabFocus();
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ catch ( Exception& )
+ {
+ }
+ }
+ rReq.Done();
+ }
+ break;
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ case SID_MAIL_SENDDOCASMS:
+ case SID_MAIL_SENDDOCASOOO:
+ case SID_MAIL_SENDDOCASPDF:
+ case SID_MAIL_SENDDOC:
+ case SID_MAIL_SENDDOCASFORMAT:
+ {
+ SfxObjectShell* pDoc = GetObjectShell();
+ if ( pDoc && pDoc->QueryHiddenInformation(
+ WhenSaving, &GetViewFrame()->GetWindow() ) != RET_YES )
+ break;
+
+ if ( SvtInternalOptions().MailUIEnabled() )
+ {
+ GetViewFrame()->SetChildWindow( SID_MAIL_CHILDWIN, TRUE );
+ }
+ else
+ {
+ SfxMailModel aModel;
+ rtl::OUString aDocType;
+
+ SFX_REQUEST_ARG(rReq, pMailSubject, SfxStringItem, SID_MAIL_SUBJECT, FALSE );
+ if ( pMailSubject )
+ aModel.SetSubject( pMailSubject->GetValue() );
+
+ SFX_REQUEST_ARG(rReq, pMailRecipient, SfxStringItem, SID_MAIL_RECIPIENT, FALSE );
+ if ( pMailRecipient )
+ {
+ String aRecipient( pMailRecipient->GetValue() );
+ String aMailToStr( String::CreateFromAscii( "mailto:" ));
+
+ if ( aRecipient.Search( aMailToStr ) == 0 )
+ aRecipient = aRecipient.Erase( 0, aMailToStr.Len() );
+ aModel.AddAddress( aRecipient, SfxMailModel::ROLE_TO );
+ }
+ SFX_REQUEST_ARG(rReq, pMailDocType, SfxStringItem, SID_TYPE_NAME, FALSE );
+ if ( pMailDocType )
+ aDocType = pMailDocType->GetValue();
+
+ uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() );
+ SfxMailModel::SendMailResult eResult = SfxMailModel::SEND_MAIL_ERROR;
+
+ if ( nId == SID_MAIL_SENDDOC )
+ eResult = aModel.SaveAndSend( xFrame, rtl::OUString() );
+ else
+ if ( nId == SID_MAIL_SENDDOCASPDF )
+ eResult = aModel.SaveAndSend( xFrame, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "pdf_Portable_Document_Format" )));
+ else
+ if ( nId == SID_MAIL_SENDDOCASMS )
+ {
+ aDocType = impl_searchFormatTypeForApp(xFrame, E_MS_DOC);
+ if (aDocType.getLength() > 0)
+ eResult = aModel.SaveAndSend( xFrame, aDocType );
+ }
+ else
+ if ( nId == SID_MAIL_SENDDOCASOOO )
+ {
+ aDocType = impl_searchFormatTypeForApp(xFrame, E_OOO_DOC);
+ if (aDocType.getLength() > 0)
+ eResult = aModel.SaveAndSend( xFrame, aDocType );
+ }
+
+ if ( eResult == SfxMailModel::SEND_MAIL_ERROR )
+ {
+ InfoBox aBox( SFX_APP()->GetTopWindow(), SfxResId( MSG_ERROR_SEND_MAIL ));
+ aBox.Execute();
+ rReq.Ignore();
+ }
+ else
+ rReq.Done();
+ }
+
+ break;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_WEBHTML:
+ {
+ static const char HTML_DOCUMENT_TYPE[] = "writer_web_HTML";
+ static const char HTML_GRAPHIC_TYPE[] = "graphic_HTML";
+ const sal_Int32 FILTERFLAG_EXPORT = 0x00000002;
+
+ css::uno::Reference< lang::XMultiServiceFactory > xSMGR(::comphelper::getProcessServiceFactory(), css::uno::UNO_QUERY_THROW);
+ css::uno::Reference < css::frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() );
+ css::uno::Reference< css::frame::XModel > xModel;
+
+ const rtl::OUString aModuleManager( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ));
+ css::uno::Reference< css::frame::XModuleManager > xModuleManager( xSMGR->createInstance( aModuleManager ), css::uno::UNO_QUERY_THROW );
+ if ( !xModuleManager.is() )
+ {
+ rReq.Done(FALSE);
+ return;
+ }
+
+ rtl::OUString aModule;
+ try
+ {
+ aModule = xModuleManager->identify( xFrame );
+ }
+ catch ( css::uno::RuntimeException& )
+ {
+ throw;
+ }
+ catch ( css::uno::Exception& )
+ {
+ }
+
+ if ( xFrame.is() )
+ {
+ css::uno::Reference< css::frame::XController > xController = xFrame->getController();
+ if ( xController.is() )
+ xModel = xController->getModel();
+ }
+
+ // We need at least a valid module name and model reference
+ css::uno::Reference< css::frame::XStorable > xStorable( xModel, css::uno::UNO_QUERY );
+ if ( xModel.is() && xStorable.is() )
+ {
+ rtl::OUString aFilterName;
+ rtl::OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM( HTML_DOCUMENT_TYPE ));
+ rtl::OUString aFileName;
+ rtl::OUString aExtension( RTL_CONSTASCII_USTRINGPARAM( "htm" ));
+
+ rtl::OUString aLocation = xStorable->getLocation();
+ INetURLObject aFileObj( aLocation );
+
+ bool bPrivateProtocol = ( aFileObj.GetProtocol() == INET_PROT_PRIV_SOFFICE );
+ bool bHasLocation = ( aLocation.getLength() > 0 ) && !bPrivateProtocol;
+
+ css::uno::Reference< css::container::XContainerQuery > xContainerQuery(
+ xSMGR->createInstance( rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ))),
+ css::uno::UNO_QUERY_THROW );
+
+ // Retrieve filter from type
+ sal_Int32 nFilterFlags = FILTERFLAG_EXPORT;
+ aFilterName = impl_retrieveFilterNameFromTypeAndModule( xContainerQuery, aTypeName, aModule, nFilterFlags );
+ if ( aFilterName.getLength() == 0 )
+ {
+ // Draw/Impress uses a different type. 2nd chance try to use alternative type name
+ aFilterName = impl_retrieveFilterNameFromTypeAndModule(
+ xContainerQuery, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( HTML_GRAPHIC_TYPE )), aModule, nFilterFlags );
+ }
+
+ // No filter found => error
+ // No type and no location => error
+ if (( aFilterName.getLength() == 0 ) || ( aTypeName.getLength() == 0 ))
+ {
+ rReq.Done(FALSE);
+ return;
+ }
+
+ // Use provided save file name. If empty determine file name
+ if ( !bHasLocation )
+ {
+ // Create a default file name with the correct extension
+ const rtl::OUString aPreviewFileName( RTL_CONSTASCII_USTRINGPARAM( "webpreview" ));
+ aFileName = aPreviewFileName;
+ }
+ else
+ {
+ // Determine file name from model
+ INetURLObject aFObj( xStorable->getLocation() );
+ aFileName = aFObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::NO_DECODE );
+ }
+
+ OSL_ASSERT( aFilterName.getLength() > 0 );
+ OSL_ASSERT( aFileName.getLength() > 0 );
+
+ // Creates a temporary directory to store our predefined file into it.
+ ::utl::TempFile aTempDir( NULL, sal_True );
+
+ INetURLObject aFilePathObj( aTempDir.GetURL() );
+ aFilePathObj.insertName( aFileName );
+ aFilePathObj.setExtension( aExtension );
+
+ rtl::OUString aFileURL = aFilePathObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
+ aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
+ aArgs[0].Value = css::uno::makeAny( aFilterName );
+
+ // Store document in the html format
+ try
+ {
+ xStorable->storeToURL( aFileURL, aArgs );
+ }
+ catch ( com::sun::star::io::IOException& )
+ {
+ rReq.Done(FALSE);
+ return;
+ }
+
+ ::com::sun::star::uno::Reference< XSystemShellExecute > xSystemShellExecute( xSMGR->createInstance(
+ ::rtl::OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" )),
+ css::uno::UNO_QUERY );
+
+ BOOL bRet( TRUE );
+ if ( xSystemShellExecute.is() )
+ {
+ try
+ {
+ xSystemShellExecute->execute(
+ aFileURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
+ }
+ catch ( uno::Exception& )
+ {
+ vos::OGuard aGuard( Application::GetSolarMutex() );
+ Window *pParent = SFX_APP()->GetTopWindow();
+ ErrorBox( pParent, SfxResId( MSG_ERROR_NO_WEBBROWSER_FOUND )).Execute();
+ bRet = FALSE;
+ }
+ }
+
+ rReq.Done(bRet);
+ break;
+ }
+ else
+ {
+ rReq.Done(FALSE);
+ return;
+ }
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ case SID_PLUGINS_ACTIVE:
+ {
+ SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nId, FALSE);
+ bool const bActive = (pShowItem)
+ ? pShowItem->GetValue()
+ : !pImp->m_bPlugInsActive;
+ // ggf. recorden
+ if ( !rReq.IsAPI() )
+ rReq.AppendItem( SfxBoolItem( nId, bActive ) );
+
+ // Jetzt schon DONE aufrufen, da die Argumente evtl. einen Pool
+ // benutzen, der demn"achst weg ist
+ rReq.Done(TRUE);
+
+ // ausfuehren
+ if (!pShowItem || (bActive != pImp->m_bPlugInsActive))
+ {
+ SfxFrame* pTopFrame = &GetFrame()->GetTopFrame();
+ if ( pTopFrame != &GetFrame()->GetFrame() )
+ {
+ // FramesetDocument
+ SfxViewShell *pShell = pTopFrame->GetCurrentViewFrame()->GetViewShell();
+ if ( pShell->GetInterface()->GetSlot( nId ) )
+ pShell->ExecuteSlot( rReq );
+ break;
+ }
+
+ SfxFrameIterator aIter( *pTopFrame );
+ while ( pTopFrame )
+ {
+ if ( pTopFrame->GetCurrentViewFrame() )
+ {
+ SfxViewShell *pView = pTopFrame->GetCurrentViewFrame()->GetViewShell();
+ if ( pView )
+ {
+ pView->pImp->m_bPlugInsActive = bActive;
+ Rectangle aVisArea = GetObjectShell()->GetVisArea();
+ VisAreaChanged(aVisArea);
+
+ // the plugins might need change in their state
+ SfxInPlaceClientList *pClients = pView->GetIPClientList_Impl(FALSE);
+ if ( pClients )
+ {
+ for (USHORT n=0; n < pClients->Count(); n++)
+ {
+ SfxInPlaceClient* pIPClient = pClients->GetObject(n);
+ if ( pIPClient )
+ pView->CheckIPClient_Impl( pIPClient, aVisArea );
+ }
+ }
+ }
+ }
+
+ if ( !pTopFrame->GetParentFrame() )
+ pTopFrame = aIter.FirstFrame();
+ else
+ pTopFrame = aIter.NextFrame( *pTopFrame );
+ }
+ }
+
+ break;
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::GetState_Impl( SfxItemSet &rSet )
+{
+ DBG_CHKTHIS(SfxViewShell, 0);
+
+ SfxWhichIter aIter( rSet );
+ for ( USHORT nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
+ {
+ switch ( nSID )
+ {
+ case SID_STYLE_CATALOG:
+ {
+ if ( !GetViewFrame()->KnowsChildWindow( SID_STYLE_DESIGNER ) )
+ rSet.DisableItem( nSID );
+ break;
+ }
+
+ // Printer-Funktionen
+ case SID_PRINTDOC:
+ case SID_PRINTDOCDIRECT:
+ case SID_SETUPPRINTER:
+ case SID_PRINTER_NAME:
+ {
+ bool bEnabled = pImp->m_bCanPrint && !pImp->m_nPrinterLocks;
+ bEnabled = bEnabled && !Application::GetSettings().GetMiscSettings().GetDisablePrinting();
+ if ( bEnabled )
+ {
+ SfxPrinter *pPrinter = GetPrinter(FALSE);
+
+ if ( SID_PRINTDOCDIRECT == nSID )
+ {
+ rtl::OUString aPrinterName;
+ if ( pPrinter != NULL )
+ aPrinterName = pPrinter->GetName();
+ else
+ aPrinterName = Printer::GetDefaultPrinterName();
+ if ( aPrinterName.getLength() > 0 )
+ {
+ uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() );
+
+ ::rtl::OUStringBuffer aBuffer( 60 );
+ aBuffer.append( RetrieveLabelFromCommand(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PrintDefault" )),
+ xFrame ));
+ aBuffer.appendAscii( " (" );
+ aBuffer.append( aPrinterName );
+ aBuffer.appendAscii( ")" );
+
+ rSet.Put( SfxStringItem( SID_PRINTDOCDIRECT, aBuffer.makeStringAndClear() ) );
+ }
+ }
+ bEnabled = !pPrinter || !pPrinter->IsPrinting();
+ }
+ if ( !bEnabled )
+ {
+ // will now be handled by requeing the request
+ /* rSet.DisableItem( SID_PRINTDOC );
+ rSet.DisableItem( SID_PRINTDOCDIRECT );
+ rSet.DisableItem( SID_SETUPPRINTER ); */
+ }
+ break;
+ }
+
+ // Mail-Funktionen
+ case SID_MAIL_SENDDOCASPDF:
+ case SID_MAIL_SENDDOC:
+ case SID_MAIL_SENDDOCASFORMAT:
+ {
+ BOOL bEnable = !GetViewFrame()->HasChildWindow( SID_MAIL_CHILDWIN );
+ if ( !bEnable )
+ rSet.DisableItem( nSID );
+ break;
+ }
+
+ // PlugIns running
+ case SID_PLUGINS_ACTIVE:
+ {
+ rSet.Put( SfxBoolItem( SID_PLUGINS_ACTIVE,
+ !pImp->m_bPlugInsActive) );
+ break;
+ }
+/*
+ // SelectionText
+ case SID_SELECTION_TEXT:
+ {
+ rSet.Put( SfxStringItem( SID_SELECTION_TEXT, GetSelectionText() ) );
+ break;
+ }
+
+ // SelectionTextExt
+ case SID_SELECTION_TEXT_EXT:
+ {
+ rSet.Put( SfxStringItem( SID_SELECTION_TEXT_EXT, GetSelectionText(TRUE) ) );
+ break;
+ }
+*/
+ case SID_STYLE_FAMILY :
+ {
+ rSet.Put( SfxUInt16Item( SID_STYLE_FAMILY, pImp->m_nFamily ) );
+ break;
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::SetZoomFactor( const Fraction &rZoomX,
+ const Fraction &rZoomY )
+{
+ DBG_ASSERT( GetWindow(), "no window" );
+ MapMode aMap( GetWindow()->GetMapMode() );
+ aMap.SetScaleX( rZoomX );
+ aMap.SetScaleY( rZoomY );
+ GetWindow()->SetMapMode( aMap );
+}
+
+//--------------------------------------------------------------------
+ErrCode SfxViewShell::DoVerb(long /*nVerb*/)
+
+/* [Beschreibung]
+
+ Virtuelle Methode, um am selektierten Objekt ein Verb auszuf"uhren.
+ Da dieses Objekt nur den abgeleiteten Klassen bekannt ist, muss DoVerb
+ dort "uberschrieben werden.
+
+*/
+
+{
+ return ERRCODE_SO_NOVERBS;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::OutplaceActivated( sal_Bool bActive, SfxInPlaceClient* /*pClient*/ )
+{
+ if ( !bActive )
+ GetFrame()->GetFrame().Appear();
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::InplaceActivating( SfxInPlaceClient* /*pClient*/ )
+{
+ // TODO/LATER: painting of the bitmap can be stopped, it is required if CLIPCHILDREN problem #i25788# is not solved,
+ // but may be the bug will not affect the real office vcl windows, then it is not required
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::InplaceDeactivated( SfxInPlaceClient* /*pClient*/ )
+{
+ // TODO/LATER: paint the replacement image in normal way if the painting was stopped
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::UIActivating( SfxInPlaceClient* /*pClient*/ )
+{
+ uno::Reference < frame::XFrame > xOwnFrame( pFrame->GetFrame().GetFrameInterface() );
+ uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
+ if ( xParentFrame.is() )
+ xParentFrame->setActiveFrame( xOwnFrame );
+
+ pFrame->GetBindings().HidePopups(TRUE);
+ pFrame->GetDispatcher()->Update_Impl( TRUE );
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::UIDeactivated( SfxInPlaceClient* /*pClient*/ )
+{
+ if ( !pFrame->GetFrame().IsClosing_Impl() ||
+ SfxViewFrame::Current() != pFrame )
+ pFrame->GetDispatcher()->Update_Impl( TRUE );
+ pFrame->GetBindings().HidePopups(FALSE);
+
+ // uno::Reference < frame::XFrame > xOwnFrame( pFrame->GetFrame().GetFrameInterface() );
+ // uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
+ // if ( xParentFrame.is() )
+ // xParentFrame->setActiveFrame( uno::Reference < frame::XFrame >() );
+}
+
+//--------------------------------------------------------------------
+
+SfxInPlaceClient* SfxViewShell::FindIPClient
+(
+ const uno::Reference < embed::XEmbeddedObject >& xObj,
+ Window* pObjParentWin
+) const
+{
+ SfxInPlaceClientList *pClients = GetIPClientList_Impl(FALSE);
+ if ( !pClients )
+ return 0;
+
+ if( !pObjParentWin )
+ pObjParentWin = GetWindow();
+ for (USHORT n=0; n < pClients->Count(); n++)
+ {
+ SfxInPlaceClient *pIPClient = (SfxInPlaceClient*) pClients->GetObject(n);
+ if ( pIPClient->GetObject() == xObj && pIPClient->GetEditWin() == pObjParentWin )
+ return pIPClient;
+ }
+
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+SfxInPlaceClient* SfxViewShell::GetIPClient() const
+{
+ return GetUIActiveClient();
+}
+
+//--------------------------------------------------------------------
+
+SfxInPlaceClient* SfxViewShell::GetUIActiveIPClient_Impl() const
+{
+ // this method is needed as long as SFX still manages the border space for ChildWindows (see SfxFrame::Resize)
+ SfxInPlaceClientList *pClients = GetIPClientList_Impl(FALSE);
+ if ( !pClients )
+ return 0;
+
+ for (USHORT n=0; n < pClients->Count(); n++)
+ {
+ SfxInPlaceClient* pIPClient = pClients->GetObject(n);
+ if ( pIPClient->IsUIActive() )
+ return pIPClient;
+ }
+
+ return NULL;
+}
+
+SfxInPlaceClient* SfxViewShell::GetUIActiveClient() const
+{
+ SfxInPlaceClientList *pClients = GetIPClientList_Impl(FALSE);
+ if ( !pClients )
+ return 0;
+
+ for (USHORT n=0; n < pClients->Count(); n++)
+ {
+ SfxInPlaceClient* pIPClient = pClients->GetObject(n);
+ if ( pIPClient->IsObjectUIActive() )
+ return pIPClient;
+ }
+
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::Activate( BOOL bMDI )
+{
+ DBG_CHKTHIS(SfxViewShell, 0);
+ if ( bMDI )
+ {
+ SfxObjectShell *pSh = GetViewFrame()->GetObjectShell();
+ if ( pSh->GetModel().is() )
+ pSh->GetModel()->setCurrentController( GetViewFrame()->GetFrame().GetController() );
+
+ SetCurrentDocument();
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::Deactivate(BOOL /*bMDI*/)
+{
+ DBG_CHKTHIS(SfxViewShell, 0);
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::AdjustPosSizePixel
+(
+ const Point& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window
+ const Size& /*rSize*/ // gesamte zur Verf"ugung stehende Gr"o\se
+)
+
+{
+ DBG_CHKTHIS(SfxViewShell, 0);
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::Move()
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode wird gerufen, wenn das Fenster, in dem die
+ SfxViewShell dargestellt wird eine StarView-Move() Nachricht erh"alt.
+
+ Die Basisimplementierung braucht nicht gerufen zu werden.
+
+
+ [Anmerkung]
+
+ Diese Methode kann dazu verwendet werden, eine Selektion abzubrechen,
+ um durch das Moven des Fensters erzeugte Maus-Bewegungen anzufangen.
+
+ Zur Zeit funktioniert die Benachrichtigung nicht In-Place.
+*/
+
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::OuterResizePixel
+(
+ const Point& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window
+ const Size& /*rSize*/ // gesamte zur Verf"ugung stehende Gr"o\se
+)
+
+/* [Beschreibung]
+
+ Diese Methode muss ueberladen werden, um auf "Anderungen der Groesse
+ der View zu reagieren. Dabei definieren wir die View als das Edit-Window
+ zuz"uglich der um das Edit-Window angeordnenten Tools (z.B. Lineale).
+
+ Das Edit-Window darf weder in Gr"o\se noch Position ver"andert werden.
+
+ Die Vis-Area der SfxObjectShell, dessen Skalierung und Position
+ d"urfen hier ver"andert werden. Der Hauptanwendungsfall ist dabei,
+ das Ver"andern der Gr"o\se der Vis-Area.
+
+ "Andert sich durch die neue Berechnung der Border, so mu\s dieser
+ mit <SfxViewShell::SetBorderPixel(const SvBorder&)> gesetzt werden.
+ Erst nach Aufruf von 'SetBorderPixel' ist das Positionieren von
+ Tools erlaubt.
+
+
+ [Beispiel]
+
+ void AppViewSh::OuterViewResizePixel( const Point &rOfs, const Size &rSz )
+ {
+ // Tool-Positionen und Gr"o\sen von au\sen berechnen, NICHT setzen!
+ // (wegen folgender Border-Berechnung)
+ Point aHLinPos...; Size aHLinSz...;
+ ...
+
+ // Border f"ur Tools passend zu rSize berechnen und setzen
+ SvBorder aBorder...
+ SetBorderPixel( aBorder ); // ab jetzt sind Positionierungen erlaubt
+
+ // Tools anordnen
+ pHLin->SetPosSizePixel( aHLinPos, aHLinSz );
+ ...
+ }
+
+
+ [Querverweise]
+
+ <SfxViewShell::InnerResizePixel(const Point&,const Size& rSize)>
+*/
+
+{
+ DBG_CHKTHIS(SfxViewShell, 0);
+ SetBorderPixel( SvBorder() );
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::InnerResizePixel
+(
+ const Point& /*rToolOffset*/,// linke obere Ecke der Tools im Frame-Window
+ const Size& /*rSize*/ // dem Edit-Win zur Verf"ugung stehende Gr"o\se
+)
+
+/* [Beschreibung]
+
+ Diese Methode muss ueberladen werden, um auf "Anderungen der Groesse
+ des Edit-Windows zu reagieren.
+
+ Das Edit-Window darf weder in Gr"o\se noch Position ver"andert werden.
+ Weder die Vis-Area der SfxObjectShell noch dessen Skalierung oder
+ Position d"urfen ver"andert werden.
+
+ "Andert sich durch die neue Berechnung der Border, so mu\s dieser
+ mit <SfxViewShell::SetBorderPixel(const SvBorder&)> gesetzt werden.
+ Erst nach Aufruf von 'SetBorderPixel' ist das Positionieren von
+ Tools erlaubt.
+
+
+ [Beispiel]
+
+ void AppViewSh::InnerViewResizePixel( const Point &rOfs, const Size &rSz )
+ {
+ // Tool-Positionen und Gr"o\sen von innen berechnen, NICHT setzen!
+ // (wegen folgender Border-Berechnung)
+ Point aHLinPos...; Size aHLinSz...;
+ ...
+
+ // Border f"ur Tools passend zu rSz berechnen und setzen
+ SvBorder aBorder...
+ SetBorderPixel( aBorder ); // ab jetzt sind Positionierungen erlaubt
+
+ // Tools anordnen
+ pHLin->SetPosSizePixel( aHLinPos, aHLinSz );
+ ...
+ }
+
+
+ [Querverweise]
+
+ <SfxViewShell::OuterResizePixel(const Point&,const Size& rSize)>
+*/
+
+{
+ DBG_CHKTHIS(SfxViewShell, 0);
+ SetBorderPixel( SvBorder() );
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::InvalidateBorder()
+{
+ DBG_CHKTHIS(SfxViewShell, 0);
+ DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
+
+ GetViewFrame()->InvalidateBorderImpl( this );
+ if (pImp->m_pController.is())
+ {
+ pImp->m_pController->BorderWidthsChanged_Impl();
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::SetBorderPixel( const SvBorder &rBorder )
+{
+ DBG_CHKTHIS(SfxViewShell, 0);
+ DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
+
+ //if ( rBorder != GetBorderPixel())
+ {
+ GetViewFrame()->SetBorderPixelImpl( this, rBorder );
+
+ // notify related controller that border size is changed
+ if (pImp->m_pController.is())
+ {
+ pImp->m_pController->BorderWidthsChanged_Impl();
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+const SvBorder& SfxViewShell::GetBorderPixel() const
+{
+ DBG_CHKTHIS(SfxViewShell, 0);
+ DBG_ASSERT( GetViewFrame(), "SfxViewShell without SfxViewFrame" );
+
+ return GetViewFrame()->GetBorderPixelImpl( this );
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::SetWindow
+(
+ Window* pViewPort // Pointer auf das Datenfenster bzw. 0 im Destruktor
+)
+
+/* [Beschreibung]
+
+ Mit dieser Methode wird der SfxViewShell das Datenfenster mitgeteilt.
+ Dieses wird f"ur den In-Place-Container und f"ur das korrekte
+ Wiederherstellen des Focus ben"otigt.
+
+ Selbst In-Place-aktiv ist das Umsetzen des ViewPort-Windows verboten.
+*/
+
+{
+ if( pWindow == pViewPort )
+ return;
+
+ // ggf. vorhandene IP-Clients disconnecten
+ DisconnectAllClients();
+
+ //TODO: should we have a "ReconnectAllClients" method?
+ DiscardClients_Impl();
+
+ // View-Port austauschen
+ BOOL bHadFocus = pWindow ? pWindow->HasChildPathFocus( TRUE ) : FALSE;
+ pWindow = pViewPort;
+
+ if( pWindow )
+ {
+ // Disable automatic GUI mirroring (right-to-left) for document windows
+ pWindow->EnableRTL( FALSE );
+ }
+
+ if ( bHadFocus && pWindow )
+ pWindow->GrabFocus();
+ //TODO/CLEANUP
+ //brauchen wir die Methode doch noch?!
+ //SFX_APP()->GrabFocus( pWindow );
+}
+
+//--------------------------------------------------------------------
+
+Size SfxViewShell::GetOptimalSizePixel() const
+{
+ DBG_ERROR( "Useless call!" );
+ return Size();
+}
+
+//------------------------------------------------------------------------
+
+SfxViewShell::SfxViewShell
+(
+ SfxViewFrame* pViewFrame, /* <SfxViewFrame>, in dem diese View dargestellt wird */
+ USHORT nFlags /* siehe <SfxViewShell-Flags> */
+)
+
+: SfxShell(this)
+, pImp( new SfxViewShell_Impl(nFlags) )
+ ,pIPClientList( 0 )
+ ,pFrame(pViewFrame)
+ ,pSubShell(0)
+ ,pWindow(0)
+ ,bNoNewWindow( 0 != (nFlags & SFX_VIEW_NO_NEWWINDOW) )
+{
+ DBG_CTOR(SfxViewShell, 0);
+
+ //pImp->pPrinterCommandQueue = new SfxAsyncPrintExec_Impl( this );
+
+ if ( pViewFrame->GetParentViewFrame() )
+ {
+ pImp->m_bPlugInsActive = pViewFrame->GetParentViewFrame()
+ ->GetViewShell()->pImp->m_bPlugInsActive;
+ }
+ SetMargin( pViewFrame->GetMargin_Impl() );
+
+ SetPool( &pViewFrame->GetObjectShell()->GetPool() );
+ StartListening(*pViewFrame->GetObjectShell());
+
+ // in Liste eintragen
+ const SfxViewShell *pThis = this; // wegen der kranken Array-Syntax
+ SfxViewShellArr_Impl &rViewArr = SFX_APP()->GetViewShells_Impl();
+ rViewArr.Insert(pThis, rViewArr.Count() );
+}
+
+//--------------------------------------------------------------------
+
+SfxViewShell::~SfxViewShell()
+{
+ DBG_DTOR(SfxViewShell, 0);
+
+ // aus Liste austragen
+ const SfxViewShell *pThis = this;
+ SfxViewShellArr_Impl &rViewArr = SFX_APP()->GetViewShells_Impl();
+ rViewArr.Remove( rViewArr.GetPos(pThis) );
+
+ if ( pImp->xClipboardListener.is() )
+ {
+ pImp->xClipboardListener->DisconnectViewShell();
+ pImp->xClipboardListener = NULL;
+ }
+
+ if (pImp->m_pController.is())
+ {
+ pImp->m_pController->ReleaseShell_Impl();
+ pImp->m_pController.clear();
+ }
+
+ //DELETEZ( pImp->pPrinterCommandQueue );
+ DELETEZ( pImp );
+ DELETEZ( pIPClientList );
+}
+
+//--------------------------------------------------------------------
+
+USHORT SfxViewShell::PrepareClose
+(
+ BOOL bUI, // TRUE: Dialoge etc. erlaubt, FALSE: silent-mode
+ BOOL /*bForBrowsing*/
+)
+{
+ SfxPrinter *pPrinter = GetPrinter();
+ if ( pPrinter && pPrinter->IsPrinting() )
+ {
+ if ( bUI )
+ {
+ InfoBox aInfoBox( &GetViewFrame()->GetWindow(), SfxResId( MSG_CANT_CLOSE ) );
+ aInfoBox.Execute();
+ }
+
+ return FALSE;
+ }
+
+ if( GetViewFrame()->IsInModalMode() )
+ return FALSE;
+
+ if( bUI && GetViewFrame()->GetDispatcher()->IsLocked() )
+ return FALSE;
+
+ return TRUE;
+}
+
+//--------------------------------------------------------------------
+
+SfxViewShell* SfxViewShell::Current()
+{
+ SfxViewFrame *pCurrent = SfxViewFrame::Current();
+ return pCurrent ? pCurrent->GetViewShell() : NULL;
+}
+
+//--------------------------------------------------------------------
+
+SfxViewShell* SfxViewShell::Get( const Reference< XController>& i_rController )
+{
+ if ( !i_rController.is() )
+ return NULL;
+
+ for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst( NULL, FALSE );
+ pViewShell;
+ pViewShell = SfxViewShell::GetNext( *pViewShell, NULL, FALSE )
+ )
+ {
+ if ( pViewShell->GetController() == i_rController )
+ return pViewShell;
+ }
+ return NULL;
+}
+
+//--------------------------------------------------------------------
+
+SdrView* SfxViewShell::GetDrawView() const
+
+/* [Beschreibung]
+
+ Diese virtuelle Methode mu\s von den Subklassen "uberladen werden, wenn
+ der Property-Editor zur Verf"ugung stehen soll.
+
+ Die Default-Implementierung liefert immer 0.
+*/
+
+{
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+String SfxViewShell::GetSelectionText
+(
+ BOOL /*bCompleteWords*/ /* FALSE (default)
+ Nur der tats"achlich selektierte Text wird
+ zur"uckgegeben.
+
+ TRUE
+ Der selektierte Text wird soweit erweitert,
+ da\s nur ganze W"orter zur"uckgegeben werden.
+ Als Worttrenner gelten White-Spaces und die
+ Satzzeichen ".,;" sowie einfache und doppelte
+ Anf"uhrungszeichen.
+ */
+)
+
+/* [Beschreibung]
+
+ Diese Methode kann von Anwendungsprogrammierer "uberladen werden,
+ um einen Text zur"uckzuliefern, der in der aktuellen Selektion
+ steht. Dieser wird z.B. beim Versenden (email) verwendet.
+
+ Mit "CompleteWords == TRUE" ger"ufen, reicht z.B. auch der Cursor,
+ der in einer URL steht, um die gesamte URL zu liefern.
+*/
+
+{
+ return String();
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxViewShell::HasSelection( BOOL ) const
+
+/* [Beschreibung]
+
+ Mit dieser virtuellen Methode kann z.B. ein Dialog abfragen, ob in der
+ aktuellen View etwas selektiert ist. Wenn der Parameter <BOOL> TRUE ist,
+ wird abgefragt, ob Text selektiert ist.
+*/
+
+{
+ return FALSE;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::SetSubShell( SfxShell *pShell )
+
+/* [Beschreibung]
+
+ Mit dieser Methode kann eine Selektions- oder Cursor-Shell angemeldet
+ werden, die automatisch unmittelbar nach der SfxViewShell auf den
+ SfxDispatcher gepusht wird, und automatisch umittelbar vor ihr
+ gepoppt wird.
+
+ Ist die SfxViewShell-Instanz bereits gepusht, dann wird pShell
+ sofort ebenfalls gepusht. Wird mit SetSubShell eine andere SfxShell
+ Instanz angemeldet, als vorher angemeldet war, wird die zuvor angemeldete
+ ggf. automatisch gepoppt. Mit pShell==0 kann daher die aktuelle
+ Sub-Shell abgemeldet werden.
+*/
+
+{
+ // ist diese ViewShell "uberhaupt aktiv?
+ SfxDispatcher *pDisp = pFrame->GetDispatcher();
+ if ( pDisp->IsActive(*this) )
+ {
+ // Dispatcher updaten
+ if ( pSubShell )
+ pDisp->Pop(*pSubShell);
+ if ( pShell )
+ pDisp->Push(*pShell);
+ pDisp->Flush();
+ }
+
+ pSubShell = pShell;
+}
+
+void SfxViewShell::AddSubShell( SfxShell& rShell )
+{
+ pImp->aArr.Insert( &rShell, pImp->aArr.Count() );
+ SfxDispatcher *pDisp = pFrame->GetDispatcher();
+ if ( pDisp->IsActive(*this) )
+ {
+ pDisp->Push(rShell);
+ pDisp->Flush();
+ }
+}
+
+void SfxViewShell::RemoveSubShell( SfxShell* pShell )
+{
+ SfxDispatcher *pDisp = pFrame->GetDispatcher();
+ if ( !pShell )
+ {
+ USHORT nCount = pImp->aArr.Count();
+ if ( pDisp->IsActive(*this) )
+ {
+ for ( USHORT n=nCount; n>0; n-- )
+ pDisp->Pop( *pImp->aArr[n-1] );
+ pDisp->Flush();
+ }
+
+ pImp->aArr.Remove(0, nCount);
+ }
+ else
+ {
+ USHORT nPos = pImp->aArr.GetPos( pShell );
+ if ( nPos != 0xFFFF )
+ {
+ pImp->aArr.Remove( nPos );
+ if ( pDisp->IsActive(*this) )
+ {
+ pDisp->RemoveShell_Impl( *pShell );
+ pDisp->Flush();
+ }
+ }
+ }
+}
+
+SfxShell* SfxViewShell::GetSubShell( USHORT nNo )
+{
+ USHORT nCount = pImp->aArr.Count();
+ if ( nNo<nCount )
+ return pImp->aArr[nCount-nNo-1];
+ return NULL;
+}
+
+void SfxViewShell::PushSubShells_Impl( BOOL bPush )
+{
+ USHORT nCount = pImp->aArr.Count();
+ SfxDispatcher *pDisp = pFrame->GetDispatcher();
+ if ( bPush )
+ {
+ for ( USHORT n=0; n<nCount; n++ )
+ pDisp->Push( *pImp->aArr[n] );
+ }
+ else if ( nCount )
+ {
+ SfxShell& rPopUntil = *pImp->aArr[0];
+ if ( pDisp->GetShellLevel( rPopUntil ) != USHRT_MAX )
+ pDisp->Pop( rPopUntil, SFX_SHELL_POP_UNTIL );
+ }
+
+ pDisp->Flush();
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::WriteUserData( String&, BOOL )
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::ReadUserData(const String&, BOOL )
+{
+}
+
+void SfxViewShell::ReadUserDataSequence ( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool )
+{
+}
+
+void SfxViewShell::WriteUserDataSequence ( ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool )
+{
+}
+
+
+//--------------------------------------------------------------------
+// returns the first shell of spec. type viewing the specified doc.
+
+SfxViewShell* SfxViewShell::GetFirst
+(
+ const TypeId* pType,
+ BOOL bOnlyVisible
+)
+{
+ // search for a SfxViewShell of the specified type
+ SfxViewShellArr_Impl &rShells = SFX_APP()->GetViewShells_Impl();
+ SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl();
+ for ( USHORT nPos = 0; nPos < rShells.Count(); ++nPos )
+ {
+ SfxViewShell *pShell = rShells.GetObject(nPos);
+ if ( pShell )
+ {
+ // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame
+ // these ViewShells shouldn't be accessible anymore
+ // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps
+ for ( sal_uInt16 n=0; n<rFrames.Count(); ++n )
+ {
+ SfxViewFrame *pFrame = rFrames.GetObject(n);
+ if ( pFrame == pShell->GetViewFrame() )
+ {
+ // only ViewShells with a valid ViewFrame will be returned
+ if ( ( !bOnlyVisible || pFrame->IsVisible() ) && ( !pType || pShell->IsA(*pType) ) )
+ return pShell;
+ break;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+//--------------------------------------------------------------------
+// returns the next shell of spec. type viewing the specified doc.
+
+SfxViewShell* SfxViewShell::GetNext
+(
+ const SfxViewShell& rPrev,
+ const TypeId* pType,
+ BOOL bOnlyVisible
+)
+{
+ SfxViewShellArr_Impl &rShells = SFX_APP()->GetViewShells_Impl();
+ SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl();
+ USHORT nPos;
+ for ( nPos = 0; nPos < rShells.Count(); ++nPos )
+ if ( rShells.GetObject(nPos) == &rPrev )
+ break;
+
+ for ( ++nPos; nPos < rShells.Count(); ++nPos )
+ {
+ SfxViewShell *pShell = rShells.GetObject(nPos);
+ if ( pShell )
+ {
+ // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame
+ // these ViewShells shouldn't be accessible anymore
+ // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps
+ for ( sal_uInt16 n=0; n<rFrames.Count(); ++n )
+ {
+ SfxViewFrame *pFrame = rFrames.GetObject(n);
+ if ( pFrame == pShell->GetViewFrame() )
+ {
+ // only ViewShells with a valid ViewFrame will be returned
+ if ( ( !bOnlyVisible || pFrame->IsVisible() ) && ( !pType || pShell->IsA(*pType) ) )
+ return pShell;
+ break;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::Notify( SfxBroadcaster& rBC,
+ const SfxHint& rHint )
+{
+ if ( rHint.IsA(TYPE(SfxEventHint)) )
+ {
+ switch ( ((SfxEventHint&)rHint).GetEventId() )
+ {
+ case SFX_EVENT_LOADFINISHED:
+ {
+ if ( GetController().is() )
+ {
+ // avoid access to dangling ViewShells
+ SfxViewFrameArr_Impl &rFrames = SFX_APP()->GetViewFrames_Impl();
+ for ( sal_uInt16 n=0; n<rFrames.Count(); ++n )
+ {
+ SfxViewFrame *frame = rFrames.GetObject(n);
+ if ( frame == GetViewFrame() && &rBC == GetObjectShell() )
+ {
+ SfxItemSet* pSet = GetObjectShell()->GetMedium()->GetItemSet();
+ SFX_ITEMSET_ARG( pSet, pItem, SfxUnoAnyItem, SID_VIEW_DATA, sal_False );
+ if ( pItem )
+ {
+ pImp->m_pController->restoreViewData(
+ pItem->GetValue() );
+ pSet->ClearItem( SID_VIEW_DATA );
+ }
+
+ break;
+ }
+ }
+ }
+
+ break;
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxViewShell::ExecKey_Impl(const KeyEvent& aKey)
+{
+ if (!pImp->m_pAccExec.get())
+ {
+ pImp->m_pAccExec.reset(
+ ::svt::AcceleratorExecute::createAcceleratorHelper() );
+ pImp->m_pAccExec->init(::comphelper::getProcessServiceFactory(),
+ pFrame->GetFrame().GetFrameInterface());
+ }
+
+ return pImp->m_pAccExec->execute(aKey.GetKeyCode());
+}
+
+//--------------------------------------------------------------------
+
+FASTBOOL SfxViewShell::KeyInput( const KeyEvent &rKeyEvent )
+
+/* [Beschreibung]
+
+ Diese Methode f"uhrt das KeyEvent 'rKeyEvent' "uber die an dieser
+ SfxViewShell direkt oder indirekt (z.B. via Applikation) konfigurierten
+ Tasten (Accelerator) aus.
+
+
+ [R"uckgabewert]
+
+ FASTBOOL TRUE
+ die Taste ist konfiguriert, der betreffende
+ Handler wurde gerufen
+
+ FALSE
+ die Taste ist nicht konfiguriert, es konnte
+ also kein Handler gerufen werden
+
+
+ [Querverweise]
+ <SfxApplication::KeyInput(const KeyEvent&)>
+*/
+{
+ return ExecKey_Impl(rKeyEvent);
+}
+
+FASTBOOL SfxViewShell::GlobalKeyInput_Impl( const KeyEvent &rKeyEvent )
+{
+ return ExecKey_Impl(rKeyEvent);
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::ShowCursor( FASTBOOL /*bOn*/ )
+
+/* [Beschreibung]
+
+ Diese Methode mu\s von Subklassen "uberladen werden, damit vom SFx
+ aus der Cursor ein- und ausgeschaltet werden kann. Dies geschieht
+ z.B. bei laufendem <SfxProgress>.
+*/
+
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::GotFocus() const
+
+/* [Beschreibung]
+
+ Diese Methode mu\s vom Applikationsentwickler gerufen werden, wenn
+ das Edit-Window den Focus erhalten hat. Der SFx hat so z.B. die
+ M"oglichkeit, den Accelerator einzuschalten.
+
+
+ [Anmerkung]
+
+ <StarView> liefert leider keine M"oglichkeit, solche Events
+ 'von der Seite' einzuh"angen.
+*/
+
+{
+}
+
+//--------------------------------------------------------------------
+void SfxViewShell::ResetAllClients_Impl( SfxInPlaceClient *pIP )
+{
+
+ SfxInPlaceClientList *pClients = GetIPClientList_Impl(FALSE);
+ if ( !pClients )
+ return;
+
+ for ( USHORT n=0; n < pClients->Count(); n++ )
+ {
+ SfxInPlaceClient* pIPClient = pClients->GetObject(n);
+ if( pIPClient != pIP )
+ pIPClient->ResetObject();
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::DisconnectAllClients()
+{
+ SfxInPlaceClientList *pClients = GetIPClientList_Impl(FALSE);
+ if ( !pClients )
+ return;
+
+ for ( USHORT n=0; n<pClients->Count(); )
+ // clients will remove themselves from the list
+ delete pClients->GetObject(n);
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::QueryObjAreaPixel( Rectangle& ) const
+{
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::AdjustVisArea(const Rectangle& rRect)
+{
+ DBG_ASSERT (pFrame, "Kein Frame?");
+ GetObjectShell()->SetVisArea( rRect );
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::VisAreaChanged(const Rectangle& /*rVisArea*/)
+{
+ SfxInPlaceClientList *pClients = GetIPClientList_Impl(FALSE);
+ if ( !pClients )
+ return;
+
+ for (USHORT n=0; n < pClients->Count(); n++)
+ {
+ SfxInPlaceClient* pIPClient = pClients->GetObject(n);
+ if ( pIPClient->IsObjectInPlaceActive() )
+ // client is active, notify client that the VisArea might have changed
+ pIPClient->VisAreaChanged();
+ }
+}
+
+//--------------------------------------------------------------------
+void SfxViewShell::CheckIPClient_Impl( SfxInPlaceClient *pIPClient, const Rectangle& rVisArea )
+{
+ if ( GetObjectShell()->IsInClose() )
+ return;
+
+ sal_Bool bAlwaysActive =
+ ( ( pIPClient->GetObjectMiscStatus() & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) != 0 );
+ sal_Bool bActiveWhenVisible =
+ ( ( pIPClient->GetObjectMiscStatus() & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE ) != 0 );
+
+ // this method is called when either a client is created or the "Edit/Plugins" checkbox is checked
+ if ( !pIPClient->IsObjectInPlaceActive() && pImp->m_bPlugInsActive )
+ {
+ // object in client is currently not active
+ // check if the object wants to be activated always or when it becomes at least partially visible
+ // TODO/LATER: maybe we should use the scaled area instead of the ObjArea?!
+ if ( bAlwaysActive || (bActiveWhenVisible && rVisArea.IsOver(pIPClient->GetObjArea())) )
+ {
+ try
+ {
+ pIPClient->GetObject()->changeState( embed::EmbedStates::INPLACE_ACTIVE );
+ }
+ catch ( uno::Exception& )
+ {
+ }
+ }
+ }
+ else if (!pImp->m_bPlugInsActive)
+ {
+ // object in client is currently active and "Edit/Plugins" checkbox is selected
+ // check if the object wants to be activated always or when it becomes at least partially visible
+ // in this case selecting of the "Edit/Plugin" checkbox should let such objects deactivate
+ if ( bAlwaysActive || bActiveWhenVisible )
+ pIPClient->GetObject()->changeState( embed::EmbedStates::RUNNING );
+ }
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxViewShell::PlugInsActive() const
+{
+ return pImp->m_bPlugInsActive;
+}
+
+//--------------------------------------------------------------------
+void SfxViewShell::DiscardClients_Impl()
+
+/* [Beschreibung]
+
+ Diese Methode dient dazu, vor dem Schlie\sen eines Dokuments das
+ Speichern der Objekte zu verhindern, wenn der Benutzer Schlie\en ohne
+ Speichern gew"ahlt hatte.
+*/
+
+{
+ SfxInPlaceClientList *pClients = GetIPClientList_Impl(FALSE);
+ if ( !pClients )
+ return;
+
+ for (USHORT n=0; n < pClients->Count(); )
+ delete pClients->GetObject(n);
+}
+
+//--------------------------------------------------------------------
+
+SfxScrollingMode SfxViewShell::GetScrollingMode() const
+{
+ return pImp->m_eScroll;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::SetScrollingMode( SfxScrollingMode eMode )
+{
+ pImp->m_eScroll = eMode;
+}
+
+//--------------------------------------------------------------------
+
+SfxObjectShell* SfxViewShell::GetObjectShell()
+{
+ return pFrame ? pFrame->GetObjectShell() : NULL;
+}
+
+//--------------------------------------------------------------------
+
+Reference< XModel > SfxViewShell::GetCurrentDocument() const
+{
+ Reference< XModel > xDocument;
+
+ const SfxObjectShell* pDocShell( const_cast< SfxViewShell* >( this )->GetObjectShell() );
+ OSL_ENSURE( pDocShell, "SfxViewFrame::GetCurrentDocument: no DocShell!?" );
+ if ( pDocShell )
+ xDocument = pDocShell->GetModel();
+ return xDocument;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::SetCurrentDocument() const
+{
+ uno::Reference< frame::XModel > xDocument( GetCurrentDocument() );
+ if ( xDocument.is() )
+ SfxObjectShell::SetCurrentComponent( xDocument );
+}
+
+//--------------------------------------------------------------------
+
+const Size& SfxViewShell::GetMargin() const
+{
+ return pImp->aMargin;
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::SetMargin( const Size& rSize )
+{
+ // Der default-Margin wurde "geeicht" mit www.apple.com !!
+ Size aMargin = rSize;
+ if ( aMargin.Width() == -1 )
+ aMargin.Width() = DEFAULT_MARGIN_WIDTH;
+ if ( aMargin.Height() == -1 )
+ aMargin.Height() = DEFAULT_MARGIN_HEIGHT;
+
+ if ( aMargin != pImp->aMargin )
+ {
+ pImp->aMargin = aMargin;
+ MarginChanged();
+ }
+}
+
+//--------------------------------------------------------------------
+
+void SfxViewShell::MarginChanged()
+{
+}
+
+//--------------------------------------------------------------------
+
+BOOL SfxViewShell::IsShowView_Impl() const
+{
+ return pImp->m_bIsShowView;
+}
+
+//--------------------------------------------------------------------
+
+SfxFrame* SfxViewShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ )
+{
+ return pSelf;
+}
+
+//------------------------------------------------------------------------
+
+void SfxViewShell::JumpToMark( const String& rMark )
+{
+ SfxStringItem aMarkItem( SID_JUMPTOMARK, rMark );
+ GetViewFrame()->GetDispatcher()->Execute(
+ SID_JUMPTOMARK,
+ SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
+ &aMarkItem, 0L );
+}
+
+//------------------------------------------------------------------------
+
+SfxInPlaceClientList* SfxViewShell::GetIPClientList_Impl( BOOL bCreate ) const
+{
+ if ( !pIPClientList && bCreate )
+ ( (SfxViewShell*) this )->pIPClientList = new SfxInPlaceClientList;
+ return pIPClientList;
+}
+
+void SfxViewShell::SetController( SfxBaseController* pController )
+{
+ pImp->m_pController = pController;
+ pImp->m_bControllerSet = true;
+
+ // there should be no old listener, but if there is one, it should be disconnected
+ if ( pImp->xClipboardListener.is() )
+ pImp->xClipboardListener->DisconnectViewShell();
+
+ pImp->xClipboardListener = new SfxClipboardChangeListener( this, GetClipboardNotifier() );
+}
+
+Reference < XController > SfxViewShell::GetController()
+{
+ return pImp->m_pController.get();
+}
+
+SfxBaseController* SfxViewShell::GetBaseController_Impl() const
+{
+ return pImp->m_pController.get();
+}
+
+void SfxViewShell::AddContextMenuInterceptor_Impl( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor )
+{
+ pImp->aInterceptorContainer.addInterface( xInterceptor );
+}
+
+void SfxViewShell::RemoveContextMenuInterceptor_Impl( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor )
+{
+ pImp->aInterceptorContainer.removeInterface( xInterceptor );
+}
+
+::cppu::OInterfaceContainerHelper& SfxViewShell::GetContextMenuInterceptors() const
+{
+ return pImp->aInterceptorContainer;
+}
+
+void Change( Menu* pMenu, SfxViewShell* pView )
+{
+ SfxDispatcher *pDisp = pView->GetViewFrame()->GetDispatcher();
+ USHORT nCount = pMenu->GetItemCount();
+ for ( USHORT nPos=0; nPos<nCount; ++nPos )
+ {
+ USHORT nId = pMenu->GetItemId(nPos);
+ String aCmd = pMenu->GetItemCommand(nId);
+ PopupMenu* pPopup = pMenu->GetPopupMenu(nId);
+ if ( pPopup )
+ {
+ Change( pPopup, pView );
+ }
+ else if ( nId < 5000 )
+ {
+ if ( aCmd.CompareToAscii(".uno:", 5) == 0 )
+ {
+ for (USHORT nIdx=0;;)
+ {
+ SfxShell *pShell=pDisp->GetShell(nIdx++);
+ if (pShell == NULL)
+ break;
+ const SfxInterface *pIFace = pShell->GetInterface();
+ const SfxSlot* pSlot = pIFace->GetSlot( aCmd );
+ if ( pSlot )
+ {
+ pMenu->InsertItem( pSlot->GetSlotId(), pMenu->GetItemText( nId ), pMenu->GetItemBits( nId ), nPos );
+ pMenu->SetItemCommand( pSlot->GetSlotId(), aCmd );
+ pMenu->RemoveItem( nPos+1 );
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
+
+BOOL SfxViewShell::TryContextMenuInterception( Menu& rIn, const ::rtl::OUString& rMenuIdentifier, Menu*& rpOut, ui::ContextMenuExecuteEvent aEvent )
+{
+ rpOut = NULL;
+ BOOL bModified = FALSE;
+
+ // create container from menu
+ // #110897#
+ // aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu( &rIn );
+ aEvent.ActionTriggerContainer = ::framework::ActionTriggerHelper::CreateActionTriggerContainerFromMenu(
+ ::comphelper::getProcessServiceFactory(), &rIn, &rMenuIdentifier );
+
+ // get selection from controller
+ aEvent.Selection = uno::Reference < view::XSelectionSupplier > ( GetController(), uno::UNO_QUERY );
+
+ // call interceptors
+ ::cppu::OInterfaceIteratorHelper aIt( pImp->aInterceptorContainer );
+ while( aIt.hasMoreElements() )
+ {
+ try
+ {
+ ui::ContextMenuInterceptorAction eAction =
+ ((ui::XContextMenuInterceptor*)aIt.next())->notifyContextMenuExecute( aEvent );
+ switch ( eAction )
+ {
+ case ui::ContextMenuInterceptorAction_CANCELLED :
+ // interceptor does not want execution
+ return FALSE;
+ case ui::ContextMenuInterceptorAction_EXECUTE_MODIFIED :
+ // interceptor wants his modified menu to be executed
+ bModified = TRUE;
+ break;
+ case ui::ContextMenuInterceptorAction_CONTINUE_MODIFIED :
+ // interceptor has modified menu, but allows for calling other interceptors
+ bModified = TRUE;
+ continue;
+ case ui::ContextMenuInterceptorAction_IGNORED :
+ // interceptor is indifferent
+ continue;
+ default:
+ DBG_ERROR("Wrong return value of ContextMenuInterceptor!");
+ continue;
+ }
+ }
+ catch( uno::RuntimeException& )
+ {
+ aIt.remove();
+ }
+
+ break;
+ }
+
+ if ( bModified )
+ {
+ // container was modified, create a new window out of it
+ rpOut = new PopupMenu;
+ ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer( rpOut, aEvent.ActionTriggerContainer );
+
+ Change( rpOut, this );
+ }
+
+ return TRUE;
+}
+
+void SfxViewShell::TakeOwnerShip_Impl()
+{
+ // currently there is only one reason to take OwnerShip: a hidden frame is printed
+ // so the ViewShell will check this on EndPrint (->prnmon.cxx)
+ pImp->m_bGotOwnership = true;
+}
+
+void SfxViewShell::TakeFrameOwnerShip_Impl()
+{
+ // currently there is only one reason to take OwnerShip: a hidden frame is printed
+ // so the ViewShell will check this on EndPrint (->prnmon.cxx)
+ pImp->m_bGotFrameOwnership = true;
+}
+
+void SfxViewShell::CheckOwnerShip_Impl()
+{
+ BOOL bSuccess = FALSE;
+ if (pImp->m_bGotOwnership)
+ {
+ uno::Reference < util::XCloseable > xModel(
+ GetObjectShell()->GetModel(), uno::UNO_QUERY );
+ if ( xModel.is() )
+ {
+ try
+ {
+ // this call will destroy this object in case of success!
+ xModel->close( sal_True );
+ bSuccess = TRUE;
+ }
+ catch ( util::CloseVetoException& )
+ {
+ }
+ }
+ }
+
+ if (!bSuccess && pImp->m_bGotFrameOwnership)
+ {
+ // document couldn't be closed or it shouldn't, now try at least to close the frame
+ uno::Reference < util::XCloseable > xFrame(
+ GetViewFrame()->GetFrame().GetFrameInterface(), com::sun::star::uno::UNO_QUERY );
+ if ( xFrame.is() )
+ {
+ try
+ {
+ xFrame->close( sal_True );
+ }
+ catch ( util::CloseVetoException& )
+ {
+ }
+ }
+ }
+}
+
+long SfxViewShell::HandleNotifyEvent_Impl( NotifyEvent& rEvent )
+{
+ if (pImp->m_pController.is())
+ return pImp->m_pController->HandleEvent_Impl( rEvent );
+ return 0;
+}
+
+BOOL SfxViewShell::HasKeyListeners_Impl()
+{
+ return (pImp->m_pController.is())
+ ? pImp->m_pController->HasKeyListeners_Impl() : FALSE;
+}
+
+BOOL SfxViewShell::HasMouseClickListeners_Impl()
+{
+ return (pImp->m_pController.is())
+ ? pImp->m_pController->HasMouseClickListeners_Impl() : FALSE;
+}
+
+void SfxViewShell::SetAdditionalPrintOptions( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& rOpts )
+{
+ pImp->aPrintOpts = rOpts;
+// GetObjectShell()->Broadcast( SfxPrintingHint( -3, NULL, NULL, rOpts ) );
+}
+
+BOOL SfxViewShell::Escape()
+{
+ return GetViewFrame()->GetBindings().Execute( SID_TERMINATE_INPLACEACTIVATION );
+}
+
+Reference< view::XRenderable > SfxViewShell::GetRenderable()
+{
+ Reference< view::XRenderable >xRender;
+ SfxObjectShell* pObj = GetObjectShell();
+ if( pObj )
+ {
+ Reference< frame::XModel > xModel( pObj->GetModel() );
+ if( xModel.is() )
+ xRender = Reference< view::XRenderable >( xModel, UNO_QUERY );
+ }
+ return xRender;
+}
+
+uno::Reference< datatransfer::clipboard::XClipboardNotifier > SfxViewShell::GetClipboardNotifier()
+{
+ uno::Reference< datatransfer::clipboard::XClipboardNotifier > xClipboardNotifier;
+ if ( GetViewFrame() )
+ xClipboardNotifier = uno::Reference< datatransfer::clipboard::XClipboardNotifier >( GetViewFrame()->GetWindow().GetClipboard(), uno::UNO_QUERY );
+
+ return xClipboardNotifier;
+}
+
+void SfxViewShell::AddRemoveClipboardListener( const uno::Reference < datatransfer::clipboard::XClipboardListener >& rClp, BOOL bAdd )
+{
+ try
+ {
+ if ( GetViewFrame() )
+ {
+ uno::Reference< datatransfer::clipboard::XClipboard > xClipboard( GetViewFrame()->GetWindow().GetClipboard() );
+ if( xClipboard.is() )
+ {
+ uno::Reference< datatransfer::clipboard::XClipboardNotifier > xClpbrdNtfr( xClipboard, uno::UNO_QUERY );
+ if( xClpbrdNtfr.is() )
+ {
+ if( bAdd )
+ xClpbrdNtfr->addClipboardListener( rClp );
+ else
+ xClpbrdNtfr->removeClipboardListener( rClp );
+ }
+ }
+ }
+ }
+ catch( const uno::Exception& )
+ {
+ }
+}
+