diff options
author | Bjoern Michaelsen <b_michaelsen@openoffice.org> | 2010-07-13 14:36:24 +0200 |
---|---|---|
committer | Bjoern Michaelsen <b_michaelsen@openoffice.org> | 2010-07-13 14:36:24 +0200 |
commit | 9bea5fdbf9ac1ce9d6118a63e8f98d7264872cc8 (patch) | |
tree | 577b47340d556419e4b8e690f0c841c4d69f97fc /sfx2/source | |
parent | 4f19a2d4af8de4cb23e0a9e74d8df6ba27cdf5e1 (diff) | |
parent | 871f924d559017fcf06a4c691fae6bcd9a82491e (diff) |
CWS gnumake2: resync to DEV300_m84
Diffstat (limited to 'sfx2/source')
70 files changed, 4358 insertions, 1621 deletions
diff --git a/sfx2/source/appl/app.cxx b/sfx2/source/appl/app.cxx index 2e2074013d..e1028de7d0 100644 --- a/sfx2/source/appl/app.cxx +++ b/sfx2/source/appl/app.cxx @@ -311,6 +311,7 @@ SfxApplication* SfxApplication::GetOrCreate() ::framework::SetStatusBarControllerCreator( SfxStatusBarControllerFactory ); ::framework::SetDockingWindowCreator( SfxDockingWindowFactory ); ::framework::SetIsDockingWindowVisible( IsDockingWindowVisible ); + ::framework::SetActivateToolPanel( &SfxViewFrame::ActivateToolPanel ); SfxHelp* pSfxHelp = new SfxHelp; Application::SetHelp( pSfxHelp ); diff --git a/sfx2/source/appl/appdata.cxx b/sfx2/source/appl/appdata.cxx index 0691d5e762..e48ffcc037 100644 --- a/sfx2/source/appl/appdata.cxx +++ b/sfx2/source/appl/appdata.cxx @@ -89,7 +89,7 @@ void SfxBasicManagerCreationListener::onBasicManagerCreated( const Reference< XM m_rAppData.OnApplicationBasicManagerCreated( _rBasicManager ); } -SfxAppData_Impl::SfxAppData_Impl( SfxApplication* pApp ) : +SfxAppData_Impl::SfxAppData_Impl( SfxApplication* ) : pDdeService( 0 ), pDocTopics( 0 ), pTriggerTopic(0), @@ -116,8 +116,7 @@ SfxAppData_Impl::SfxAppData_Impl( SfxApplication* pApp ) : nRescheduleLocks(0), nInReschedule(0), nAsynchronCalls(0), - m_xImeStatusWindow(new sfx2::appl::ImeStatusWindow( - *pApp, comphelper::getProcessServiceFactory())) + m_xImeStatusWindow(new sfx2::appl::ImeStatusWindow(comphelper::getProcessServiceFactory())) , pTbxCtrlFac(0) , pStbCtrlFac(0) , pViewFrames(0) diff --git a/sfx2/source/appl/appinit.cxx b/sfx2/source/appl/appinit.cxx index 6917ef9071..a1035f6339 100644 --- a/sfx2/source/appl/appinit.cxx +++ b/sfx2/source/appl/appinit.cxx @@ -35,7 +35,7 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <svtools/soerr.hxx> -#include <svl/svtools.hrc> +#include <svtools/svtools.hrc> #include <unotools/saveopt.hxx> #include <unotools/localisationoptions.hxx> #include <tools/config.hxx> diff --git a/sfx2/source/appl/appmain.cxx b/sfx2/source/appl/appmain.cxx index ea79690e02..ded60743dc 100644 --- a/sfx2/source/appl/appmain.cxx +++ b/sfx2/source/appl/appmain.cxx @@ -93,9 +93,6 @@ static SfxItemInfo __READONLY_DATA aItemInfos[] = //=================================================================== -typedef Link* LinkPtr; -SV_DECL_PTRARR(SfxInitLinkList, LinkPtr, 4, 4) - TYPEINIT2(SfxApplication,SfxShell,SfxBroadcaster); //-------------------------------------------------------------------- diff --git a/sfx2/source/appl/appquit.cxx b/sfx2/source/appl/appquit.cxx index f2068c91f0..a82d42a510 100644 --- a/sfx2/source/appl/appquit.cxx +++ b/sfx2/source/appl/appquit.cxx @@ -74,57 +74,11 @@ using ::basic::BasicManagerRepository; -#ifdef DBG_UTIL -DECLARE_LIST( SfxFrameWindowFactoryArray_Impl, SfxFrameWindowFactory* ) -SV_DECL_PTRARR(SfxInitLinkList, Link*, 2, 2) -#endif - //=================================================================== BOOL SfxApplication::QueryExit_Impl() { BOOL bQuit = TRUE; -/* - BOOL bPrinting = FALSE; - for ( SfxViewShell *pViewSh = SfxViewShell::GetFirst(); - !bPrinting && pViewSh; - pViewSh = SfxViewShell::GetNext(*pViewSh) ) - { - SfxPrinter *pPrinter = pViewSh->GetPrinter(); - bPrinting = pPrinter && pPrinter->IsPrinting(); - } - - if ( bPrinting ) - { - // Benutzer fragen, ob abgebrochen werden soll - if ( RET_OK == QueryBox( 0, SfxResId( MSG_ISPRINTING_QUERYABORT ) ).Execute() ) - { - // alle Jobs canceln - for ( SfxViewShell *pViewSh = SfxViewShell::GetFirst(); - !bPrinting && pViewSh; - pViewSh = SfxViewShell::GetNext(*pViewSh) ) - { - SfxPrinter *pPrinter = pViewSh->GetPrinter(); - if ( pPrinter && pPrinter->IsPrinting() ) - pPrinter->AbortJob(); - } - - // da das Canceln asynchron ist, Quit erstmal wieder verlassen - GetDispatcher_Impl()->Execute( SID_QUITAPP, SFX_CALLMODE_ASYNCHRON ); - DBG_TRACE( "QueryExit => FALSE (printing)" ); - return FALSE; - } - } -*/ -/* - SfxObjectShell *pLastDocSh = SfxObjectShell::GetFirst(); - if ( bQuit ) - { - // Jetzt zur Sicherheit auch hidden Frames abr"aumen - SfxViewFrame::CloseHiddenFrames_Impl(); - pLastDocSh = SfxObjectShell::GetFirst(); - } -*/ // will trotzdem noch jemand, den man nicht abschiessen kann, die App haben? if ( !bQuit ) { @@ -197,22 +151,18 @@ void SfxApplication::Deinitialize() delete pAppData_Impl->pLabelResMgr; -#ifdef DBG_UTIL DELETEX(pAppData_Impl->pSlotPool); DELETEX(pAppData_Impl->pEventConfig); SfxMacroConfig::Release_Impl(); DELETEX(pAppData_Impl->pFactArr); DELETEX(pAppData_Impl->pInitLinkList); -#endif -#ifdef DBG_UTIL DELETEX(pAppData_Impl->pTbxCtrlFac); DELETEX(pAppData_Impl->pStbCtrlFac); DELETEX(pAppData_Impl->pMenuCtrlFac); DELETEX(pAppData_Impl->pViewFrames); DELETEX(pAppData_Impl->pViewShells); DELETEX(pAppData_Impl->pObjShells); -#endif //TODO/CLEANTUP //ReleaseArgs could be used instead! diff --git a/sfx2/source/appl/appreg.cxx b/sfx2/source/appl/appreg.cxx index a08405a073..ec0ee9e975 100644 --- a/sfx2/source/appl/appreg.cxx +++ b/sfx2/source/appl/appreg.cxx @@ -42,6 +42,7 @@ #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" diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index 18df405f8e..e51364b6fb 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -51,20 +51,15 @@ #include <com/sun/star/system/SystemShellExecuteFlags.hpp> #include <com/sun/star/system/SystemShellExecuteException.hpp> -#ifndef _UNOTOOLS_PROCESSFACTORY_HXX #include <comphelper/processfactory.hxx> -#endif #include <comphelper/storagehelper.hxx> +#include "comphelper/configurationhelper.hxx" -#ifndef _SVT_DOC_ADDRESSTEMPLATE_HXX_ #include <svtools/addresstemplate.hxx> -#endif #include <svl/visitem.hxx> #include <unotools/intlwrapper.hxx> -#ifndef _UNOTOOLS_CONFIGMGR_HXX_ #include <unotools/configmgr.hxx> -#endif #include <tools/config.hxx> #include <tools/diagnose_ex.h> #include <vcl/msgbox.hxx> @@ -90,6 +85,7 @@ #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> @@ -879,6 +875,31 @@ namespace } } +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(); @@ -924,8 +945,34 @@ void SfxApplication::OfaExec_Impl( SfxRequest& rReq ) uno::Reference< css::system::XSystemShellExecute > xSystemShell( xSMGR->createInstance( DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute" ) ), uno::UNO_QUERY_THROW ); - if ( xSystemShell.is() ) - xSystemShell->execute( DEFINE_CONST_UNICODE("http://extensions.services.openoffice.org/dictionary?cid=926385"), ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS ); + + // 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& ) { diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index 7bbd4c22a3..7bbd4c22a3 100644..100755 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx diff --git a/sfx2/source/appl/imagemgr.cxx b/sfx2/source/appl/imagemgr.cxx index 18cfedd112..59714d0570 100644 --- a/sfx2/source/appl/imagemgr.cxx +++ b/sfx2/source/appl/imagemgr.cxx @@ -71,7 +71,7 @@ static WeakReference< XModuleUIConfigurationManagerSupplier > m_xModuleCfgMgrSup static WeakReference< XURLTransformer > m_xURLTransformer; static ModuleIdToImagegMgr m_aModuleIdToImageMgrMap; -Image SAL_CALL GetImage( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, const ::rtl::OUString& aURL, BOOL bBig, BOOL bHiContrast ) +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() ) diff --git a/sfx2/source/appl/imestatuswindow.cxx b/sfx2/source/appl/imestatuswindow.cxx index 2885f60bb9..53639a65df 100644 --- a/sfx2/source/appl/imestatuswindow.cxx +++ b/sfx2/source/appl/imestatuswindow.cxx @@ -57,10 +57,8 @@ namespace css = com::sun::star; using sfx2::appl::ImeStatusWindow; ImeStatusWindow::ImeStatusWindow( - SfxApplication & rApplication, css::uno::Reference< css::lang::XMultiServiceFactory > const & rServiceFactory): - m_rApplication(rApplication), m_xServiceFactory(rServiceFactory), m_bDisposed(false) {} @@ -161,7 +159,9 @@ ImeStatusWindow::propertyChange(css::beans::PropertyChangeEvent const & ) throw (css::uno::RuntimeException) { vos::OGuard aGuard(Application::GetSolarMutex()); - m_rApplication.Invalidate(SID_SHOW_IME_STATUS_WINDOW); + SfxApplication* pApp = SfxApplication::Get(); + if (pApp) + pApp->Invalidate(SID_SHOW_IME_STATUS_WINDOW); } css::uno::Reference< css::beans::XPropertySet > ImeStatusWindow::getConfig() diff --git a/sfx2/source/appl/imestatuswindow.hxx b/sfx2/source/appl/imestatuswindow.hxx index cbfe2c4748..2d310c60c7 100644 --- a/sfx2/source/appl/imestatuswindow.hxx +++ b/sfx2/source/appl/imestatuswindow.hxx @@ -37,7 +37,6 @@ namespace com { namespace sun { namespace star { namespace beans { class XPropertySet; } namespace lang { class XMultiServiceFactory; } } } } -class SfxApplication; namespace sfx2 { namespace appl { @@ -56,10 +55,7 @@ ImeStatusWindow_Impl; class ImeStatusWindow: private ImeStatusWindow_Impl { public: - ImeStatusWindow(SfxApplication & rApplication, - com::sun::star::uno::Reference< - com::sun::star::lang::XMultiServiceFactory > const & - rServiceFactory); + ImeStatusWindow( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > const& rServiceFactory ); /** Set up VCL according to the configuration. @@ -115,7 +111,6 @@ private: com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > getConfig(); - SfxApplication & m_rApplication; com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xServiceFactory; diff --git a/sfx2/source/appl/module.cxx b/sfx2/source/appl/module.cxx index aaa300b5a7..a02e3128f9 100644 --- a/sfx2/source/appl/module.cxx +++ b/sfx2/source/appl/module.cxx @@ -49,6 +49,8 @@ #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" @@ -400,6 +402,17 @@ BOOL SfxModule::IsActive() const 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 ) diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx index a90172aa6b..31c2ce7693 100644 --- a/sfx2/source/appl/sfxhelp.cxx +++ b/sfx2/source/appl/sfxhelp.cxx @@ -714,9 +714,6 @@ String SfxHelp::CreateHelpURL_Impl( const String& aCommandURL, const String& rMo return aHelpURL; } -static ::rtl::OUString OFFICE_HELP_TASK = ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP_TASK")); -static ::rtl::OUString OFFICE_HELP = ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP" )); - SfxHelpWindow_Impl* impl_createHelp(Reference< XFrame >& rHelpTask , Reference< XFrame >& rHelpContent) { @@ -725,7 +722,7 @@ SfxHelpWindow_Impl* impl_createHelp(Reference< XFrame >& rHelpTask , // otherwhise - create new help task Reference< XFrame > xHelpTask = xDesktop->findFrame( - OFFICE_HELP_TASK, + ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP_TASK")), FrameSearchFlag::TASKS | FrameSearchFlag::CREATE); if (!xHelpTask.is()) return 0; @@ -740,7 +737,7 @@ SfxHelpWindow_Impl* impl_createHelp(Reference< XFrame >& rHelpTask , if (xHelpTask->setComponent( xHelpWindow, Reference< XController >() )) { // Customize UI ... - xHelpTask->setName( OFFICE_HELP_TASK ); + xHelpTask->setName( ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP_TASK")) ); Reference< XPropertySet > xProps(xHelpTask, UNO_QUERY); if (xProps.is()) @@ -754,13 +751,13 @@ SfxHelpWindow_Impl* impl_createHelp(Reference< XFrame >& rHelpTask , // This sub frame is created internaly (if we called new SfxHelpWindow_Impl() ...) // It should exist :-) - xHelpContent = xHelpTask->findFrame(OFFICE_HELP, FrameSearchFlag::CHILDREN); + xHelpContent = xHelpTask->findFrame(::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP")), FrameSearchFlag::CHILDREN); } if (!xHelpContent.is()) delete pHelpWindow; - xHelpContent->setName(OFFICE_HELP); + xHelpContent->setName(::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP"))); rHelpTask = xHelpTask; rHelpContent = xHelpContent; @@ -830,10 +827,10 @@ BOOL SfxHelp::Start( const String& rURL, const Window* pWindow ) // in both cases)! Reference< XFrame > xHelp = xDesktop->findFrame( - OFFICE_HELP_TASK, + ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP_TASK")), FrameSearchFlag::CHILDREN); Reference< XFrame > xHelpContent = xDesktop->findFrame( - OFFICE_HELP, + ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP")), FrameSearchFlag::CHILDREN); SfxHelpWindow_Impl* pHelpWindow = 0; diff --git a/sfx2/source/appl/shutdownicon.cxx b/sfx2/source/appl/shutdownicon.cxx index 9e3c5eee4b..b6f12aecbc 100644 --- a/sfx2/source/appl/shutdownicon.cxx +++ b/sfx2/source/appl/shutdownicon.cxx @@ -33,6 +33,7 @@ #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> @@ -239,6 +240,7 @@ 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 ), @@ -247,6 +249,7 @@ ShutdownIcon::ShutdownIcon( Reference< XMultiServiceFactory > aSMgr ) : m_pPlugin( 0 ), m_bInitialized( false ) { + m_bSystemDialogs = SvtMiscOptions().UseSystemFileDialog(); } ShutdownIcon::~ShutdownIcon() @@ -380,6 +383,16 @@ 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 ) ); @@ -516,8 +529,14 @@ IMPL_STATIC_LINK( ShutdownIcon, DialogClosedHdl_Impl, FileDialogHelper*, EMPTYAR #ifdef WNT // #103346 Destroy dialog to prevent problems with custom controls - delete pThis->m_pFileDlg; - pThis->m_pFileDlg = NULL; + // 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(); diff --git a/sfx2/source/appl/shutdownicon.hxx b/sfx2/source/appl/shutdownicon.hxx index a1c836cbea..cc18016e33 100644 --- a/sfx2/source/appl/shutdownicon.hxx +++ b/sfx2/source/appl/shutdownicon.hxx @@ -52,6 +52,7 @@ 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; diff --git a/sfx2/source/appl/shutdowniconw32.cxx b/sfx2/source/appl/shutdowniconw32.cxx index e9e5ba6123..9e260fdc85 100644 --- a/sfx2/source/appl/shutdowniconw32.cxx +++ b/sfx2/source/appl/shutdowniconw32.cxx @@ -109,7 +109,7 @@ using namespace ::osl; #define ICON_TEMPLATE 16 #define ICON_MACROLIBRARY 17 #define ICON_CONFIGURATION 18 -#define ICON_OPEN 19 +#define ICON_OPEN 5 // See index of open folder icon in shell32.dll #define ICON_SETUP 500 #define SFX_TASKBAR_NOTIFICATION WM_USER+1 @@ -124,6 +124,7 @@ static void OnDrawItem(HWND hwnd, LPDRAWITEMSTRUCT lpdis); typedef struct tagMYITEM { OUString text; + OUString module; UINT iconId; } MYITEM; @@ -152,7 +153,7 @@ static bool isNT() // ------------------------------- -static void addMenuItem( HMENU hMenu, UINT id, UINT iconId, const OUString& text, int& pos, int bOwnerdraw ) +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 ) ); @@ -175,6 +176,7 @@ static void addMenuItem( HMENU hMenu, UINT id, UINT iconId, const OUString& text MYITEM *pMyItem = new MYITEM; pMyItem->text = text; pMyItem->iconId = iconId; + pMyItem->module = module; mi.dwItemData = (DWORD) pMyItem; } else @@ -245,6 +247,8 @@ static HMENU createSystrayMenu( ) { 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 ) { @@ -260,19 +264,21 @@ static HMENU createSystrayMenu( ) continue; addMenuItem( hMenu, aMenuItems[i].nMenuItemID, aMenuItems[i].nMenuIconID, - pShutdownIcon->GetUrlDescription( sURL ), pos, true ); + pShutdownIcon->GetUrlDescription( sURL ), pos, true, aEmpty ); } + + // insert the remaining menu entries addMenuItem( hMenu, IDM_TEMPLATE, ICON_TEMPLATE, - pShutdownIcon->GetResString( STR_QUICKSTART_FROMTEMPLATE ), pos, true); - addMenuItem( hMenu, static_cast< UINT >( -1 ), 0, OUString(), pos, false ); - addMenuItem( hMenu, IDM_OPEN, ICON_OPEN, pShutdownIcon->GetResString( STR_QUICKSTART_FILEOPEN ), pos, true ); - addMenuItem( hMenu, static_cast< UINT >( -1 ), 0, OUString(), pos, false ); + 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 ); - addMenuItem( hMenu, static_cast< UINT >( -1 ), 0, OUString(), pos, false ); - addMenuItem( hMenu, IDM_EXIT, 0, pShutdownIcon->GetResString( STR_QUICKSTART_EXIT ), pos, false ); + 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) ); @@ -736,11 +742,25 @@ void OnDrawItem(HWND /*hwnd*/, LPDRAWITEMSTRUCT lpdis) x = aRect.left; y = aRect.top; - int cx = GetSystemMetrics( SM_CXSMICON ); - int cy = GetSystemMetrics( SM_CYSMICON ); - HICON hIcon = (HICON) LoadImageA( GetModuleHandle( NULL ), MAKEINTRESOURCE( pMyItem->iconId ), - IMAGE_ICON, cx, cy, - LR_DEFAULTCOLOR | LR_SHARED ); + 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 ); diff --git a/sfx2/source/appl/workwin.cxx b/sfx2/source/appl/workwin.cxx index 290645a39e..06083e5013 100644 --- a/sfx2/source/appl/workwin.cxx +++ b/sfx2/source/appl/workwin.cxx @@ -53,6 +53,7 @@ #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> @@ -1538,6 +1539,16 @@ void SfxWorkWindow::UpdateObjectBars_Impl() } } +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 @@ -1550,7 +1561,7 @@ void SfxWorkWindow::UpdateChildWindows_Impl() { // Im Kontext ist ein geeignetes ChildWindow erlaubt; // ist es auch eingeschaltet ? - if ( pChildWin == 0 && pCW->bCreate ) + if ( pChildWin == NULL && pCW->bCreate ) { // Internal docking is only used for embedding into another // container. We force the floating state of all floatable @@ -1571,6 +1582,9 @@ void SfxWorkWindow::UpdateChildWindows_Impl() else bCreate = TRUE; + if ( bCreate ) + bCreate = AllowChildWindowCreation_Impl( *pCW ); + // Momentan kein Fenster da, aber es ist eingeschaltet; Fenster // und ggf. Context erzeugen if ( bCreate ) @@ -1588,19 +1602,25 @@ void SfxWorkWindow::UpdateChildWindows_Impl() if ( ( !bIsFullScreen || pChildWin->GetAlignment() == SFX_ALIGN_NOALIGNMENT ) && bAllChildsVisible ) { // Updatemode ist kompatibel; auf jeden Fall wieder einschalten - bCreate = TRUE; - if ( pCW->pCli ) + bCreate = AllowChildWindowCreation_Impl( *pCW ); + if ( bCreate ) { - // Fenster ist direktes Child - if ( bAllChildsVisible && ( (IsDockingAllowed() && bInternalDockingAllowed) || pCW->pCli->eAlign == SFX_ALIGN_NOALIGNMENT ) ) - pCW->pCli->nVisible |= CHILD_NOT_HIDDEN; + 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() ); } - 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() ); } } } @@ -2225,7 +2245,7 @@ void SfxWorkWindow::ToggleChildWindow_Impl(USHORT nId, BOOL bSetFocus) SfxChildWin_Impl *pCW = (*pChildWins)[n]; SfxChildWindow *pChild = pCW->pWin; - bool bCreationAllowed( sal_True ); + bool bCreationAllowed( true ); if ( !bInternalDockingAllowed ) { // Special case for all non-floatable child windows. We have @@ -2233,43 +2253,51 @@ void SfxWorkWindow::ToggleChildWindow_Impl(USHORT nId, BOOL bSetFocus) bCreationAllowed = !( pCW->aInfo.nFlags & SFX_CHILDWIN_FORCEDOCK ); } - if ( pChild && pCW->bCreate && bCreationAllowed ) + if ( bCreationAllowed ) { - if ( pChild->QueryClose() ) + if ( pCW->bCreate ) { - if ( pChild && pChild->IsHideAtToggle() ) + if ( pChild ) { - pCW->bCreate = !pCW->bCreate; - ShowChildWindow_Impl( nId, pCW->bCreate, bSetFocus ); + 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 { - // Fenster soll ausgeschaltet werdem + // no actual Window exists, yet => just remember the "switched off" state pCW->bCreate = FALSE; - pChild->SetVisible_Impl( FALSE ); - RemoveChildWin_Impl( pCW ); } } - } - else if ( pCW->bCreate && bCreationAllowed ) - { - pCW->bCreate = FALSE; - } - else if ( bCreationAllowed ) - { - pCW->bCreate = TRUE; - - if ( pChild ) - { - ShowChildWindow_Impl( nId, pCW->bCreate, bSetFocus ); - } else { - // Fenster erzeugen - CreateChildWin_Impl( pCW, bSetFocus ); - if ( !pCW->pWin ) - // Erzeugung war erfolglos - pCW->bCreate = FALSE; + 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; + } + } } } @@ -2488,7 +2516,6 @@ void SfxWorkWindow::ShowChildWindow_Impl(USHORT nId, BOOL bVisible, BOOL bSetFoc SfxChildWindow *pChildWin = pCW->pWin; if ( pChildWin ) { -// pCW->bCreate = bVisible; if ( bVisible ) { if ( pCW->pCli ) diff --git a/sfx2/source/bastyp/progress.cxx b/sfx2/source/bastyp/progress.cxx index 300f060865..f7d4737113 100644 --- a/sfx2/source/bastyp/progress.cxx +++ b/sfx2/source/bastyp/progress.cxx @@ -706,7 +706,7 @@ SfxProgress* SfxProgress::GetActiveProgress */ { - if ( !SfxApplication::Is_Impl() ) + if ( !SfxApplication::Get() ) return 0; SfxProgress *pProgress = 0; diff --git a/sfx2/source/bastyp/sfxhtml.cxx b/sfx2/source/bastyp/sfxhtml.cxx index eb73fee75a..b649d9d925 100644 --- a/sfx2/source/bastyp/sfxhtml.cxx +++ b/sfx2/source/bastyp/sfxhtml.cxx @@ -62,11 +62,7 @@ sal_Char __FAR_DATA sHTML_MIME_application[] = "application/"; sal_Char __FAR_DATA sHTML_MIME_experimental[] = "x-"; // <INPUT TYPE=xxx> -#ifdef __MINGW32__ // for runtime pseudo reloc -static HTMLOptionEnum aAreaShapeOptEnums[] = -#else static HTMLOptionEnum __READONLY_DATA aAreaShapeOptEnums[] = -#endif { { OOO_STRING_SVTOOLS_HTML_SH_rect, IMAP_OBJ_RECTANGLE }, { OOO_STRING_SVTOOLS_HTML_SH_rectangle, IMAP_OBJ_RECTANGLE }, diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index 5ffd01cd4a..dc856786da 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -823,7 +823,7 @@ void SAL_CALL SfxDispatchController_Impl::dispatch( const ::com::sun::star::util pItem = pDispatcher->Execute( GetId(), nCall, 0, &aInternalSet, nModifier ); // no bindings, no invalidate ( usually done in SfxDispatcher::Call_Impl()! ) - if ( SfxApplication::Is_Impl() ) + if ( SfxApplication::Get() ) { SfxDispatcher* pAppDispat = SFX_APP()->GetAppDispatcher_Impl(); if ( pAppDispat ) diff --git a/sfx2/source/dialog/about.cxx b/sfx2/source/dialog/about.cxx index c5f410f70e..6f171e1ee8 100644 --- a/sfx2/source/dialog/about.cxx +++ b/sfx2/source/dialog/about.cxx @@ -29,8 +29,16 @@ #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> @@ -40,11 +48,13 @@ #include <unotools/configmgr.hxx> #include <vcl/graph.hxx> #include <svtools/filter.hxx> + #include <sfx2/sfxuno.hxx> #include "about.hxx" -#include "sfx2/sfxresid.hxx" +#include "sfxresid.hxx" #include <sfx2/sfxdefs.hxx> #include <sfx2/app.hxx> + #include "dialog.hrc" // defines --------------------------------------------------------------- @@ -98,49 +108,12 @@ static bool impl_loadBitmap( return false; } -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 ) +/** loads the application logo as used in the about dialog and impress slideshow pause screen */ +Image SfxApplication::GetApplicationLogo() { - rtl::OUString sProduct; - utl::ConfigManager::GetDirectConfigProperty(utl::ConfigManager::PRODUCTNAME) >>= sProduct; - - if ( sProduct.equals( rtl::OUString::createFromAscii("StarOffice") ) || - sProduct.equals( rtl::OUString::createFromAscii("StarSuite") ) ) - { - // --> PB 2004-11-18 #118455# new copyright text (only in french version show a french text) - ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale(); - ::rtl::OUString sFrenchLang( DEFINE_CONST_OUSTRING( "fr" ) ); - if ( aLocale.Language.equals( sFrenchLang ) ) - { - String sNewCopyrightText( ResId( ABOUT_STR_FRENCH_COPYRIGHT, *rId.GetResMgr() ) ); - aCopyrightText.SetText( sNewCopyrightText ); - } - // <-- - } + Image aAppLogo; - // load image from module path -// rtl::OUString aAbouts( RTL_CONSTASCII_USTRINGPARAM( ABOUT_BITMAP_STRINGLIST ) ); -#ifdef ABOUTBMPNAMES - rtl::OUString aAbouts( RTL_CONSTASCII_USTRINGPARAM( "ABOUTBMPNAMES" ) ); -#else rtl::OUString aAbouts; -#endif - bool bLoaded = false; sal_Int32 nIndex = 0; do @@ -174,6 +147,33 @@ AboutDialog::AboutDialog( Window* pParent, const ResId& rId, const String& rVerS 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 ); @@ -284,22 +284,6 @@ AboutDialog::AboutDialog( Window* pParent, const ResId& rId, const String& rVerS // explizite Help-Id SetHelpId( SID_ABOUT ); - - //#112429# replace occurences of "StarOffice" in the "StarSuite" version - String sCopyright( aCopyrightText.GetText() ); - if(sProduct.equals(rtl::OUString::createFromAscii("StarSuite"))) - { - String sSO(String::CreateFromAscii("StarOffice")); - sCopyright.SearchAndReplaceAll(sSO, sProduct); - } - - String sNewYear( DEFINE_CONST_UNICODE("2005") ); - xub_StrLen nIdx = sCopyright.SearchAndReplace( DEFINE_CONST_UNICODE("2002"), sNewYear ); - if ( STRING_NOTFOUND == nIdx ) - nIdx = sCopyright.SearchAndReplace( DEFINE_CONST_UNICODE("2003"), sNewYear ); - if ( STRING_NOTFOUND == nIdx ) - nIdx = sCopyright.SearchAndReplace( DEFINE_CONST_UNICODE("2004"), sNewYear ); - aCopyrightText.SetText( sCopyright ); } // ----------------------------------------------------------------------- diff --git a/sfx2/source/dialog/dialog.hrc b/sfx2/source/dialog/dialog.hrc index 9bf64ae1e7..9664ff19ef 100644 --- a/sfx2/source/dialog/dialog.hrc +++ b/sfx2/source/dialog/dialog.hrc @@ -39,54 +39,24 @@ #define RID_DLG_ALIEN_WARNING ( RC_DIALOG_BEGIN + 0) #define STR_RESET ( RC_DIALOG_BEGIN + 0) -#define STR_BASEFMT ( RC_DIALOG_BEGIN + 1) -#define CB_USE_PASSWD ( RC_DIALOG_BEGIN + 2) -#define CB_READ_ONLY ( RC_DIALOG_BEGIN + 3) -#define BTN_MANAGER ( RC_DIALOG_BEGIN + 4) -#define BTN_STANDARD ( RC_DIALOG_BEGIN + 5) #define DLG_PASSWD ( RC_DIALOG_BEGIN + 8) -#define STR_FILEDLG_INSERT ( RC_DIALOG_BEGIN + 10) #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_OVERWRITE_STYLE ( RC_DIALOG_BEGIN + 17) #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 LOGO_IMAGELIST ( RC_DIALOG_BEGIN + 45) #define MN_CONTEXT_TEMPLDLG ( RC_DIALOG_BEGIN + 46) -#define MSG_LAYOUT_NOT_LOADING ( RC_DIALOG_BEGIN + 49) -#define ACC_LAYOUT_NOT_LOADING ( RC_DIALOG_BEGIN + 50) - -#define MSG_ERR_CANT_EDIT_OLD_FORMAT ( RC_DIALOG_BEGIN + 60 ) -#define MSG_ERR_CANT_EDIT_OPEN_DOCS ( RC_DIALOG_BEGIN + 61 ) - -#define RID_URLOPEN ( RC_DIALOG_BEGIN + 62 ) -#define RID_URLOPEN_OK 1 -#define RID_URLOPEN_CANCEL 2 -#define RID_URLOPEN_URL 3 - -#define CB_FILE ( RC_DIALOG_BEGIN + 63 ) -#define CB_URL ( RC_DIALOG_BEGIN + 64 ) - -#define STR_INTERNET ( RC_DIALOG_BEGIN + 65 ) -#define RID_AUTOHIDE ( RC_DIALOG_BEGIN + 66 ) - -#define DLG_ONLINE_REGISTER ( RC_DIALOG_BEGIN + 68 ) #define DLG_VERSIONS ( RC_DIALOG_BEGIN + 69 ) #define DLG_COMMENTS ( RC_DIALOG_BEGIN + 70 ) -#define RID_REGISTER_DLG ( RC_DIALOG_BEGIN + 73 ) -#define DLG_PHONE_CONFIGURATION ( RC_DIALOG_BEGIN + 74 ) -#define DLG_RECOGNIZER_ENGINEMODE ( RC_DIALOG_BEGIN + 75 ) #define MSG_ERROR_WRONG_CONFIRM ( RC_DIALOG_BEGIN + 76 ) -#define DLG_RECOGNIZER_SPEAKER ( RC_DIALOG_BEGIN + 77 ) #define STR_APPLY ( RC_DIALOG_BEGIN + 87 ) @@ -104,7 +74,6 @@ #define RID_DLG_SEARCH ( RC_DIALOG_BEGIN + 109 ) #define STR_PDF_EXPORT_SEND ( RC_DIALOG_BEGIN + 120 ) -#define STR_RECHECK_DOCUMENT ( RC_DIALOG_BEGIN + 121 ) #define IMG_INFO ( RC_DIALOG_BEGIN + 122 ) #define RID_EDIT_DURATIONS ( RC_DIALOG_BEGIN + 123 ) #define SFX_PB_EDIT ( RC_DIALOG_BEGIN + 124 ) diff --git a/sfx2/source/dialog/dialog.src b/sfx2/source/dialog/dialog.src index 7f0aec0106..d6b195855f 100644 --- a/sfx2/source/dialog/dialog.src +++ b/sfx2/source/dialog/dialog.src @@ -31,30 +31,6 @@ #include "helpid.hrc" #include "sfxlocal.hrc" - // Imageliste fuer die AboutBox -ImageList LOGO_IMAGELIST -{ - Prefix = "an"; - MaskColor = Color - { - Red = 0xFFFF ; - Green = 0x0000 ; - Blue = 0xFFFF ; - }; - IdList = - { - 1 ; - 2 ; - 3 ; - 4 ; - 5 ; - 6 ; - }; - IdCount = - { - 6 ; - }; -}; String STR_RESET { Text [ en-US ] = "~Reset" ; @@ -63,48 +39,6 @@ String STR_APPLY { Text [ en-US ] = "Apply"; }; -String STR_INTERNET -{ - Text [ en-US ] = "(Internet)" ; -}; -String STR_BASEFMT -{ - Text [ en-US ] = "Base format" ; -}; -CheckBox CB_USE_PASSWD -{ - HelpId = HID_FILEDLG_USE_PASSWD ; - Text [ en-US ] = "~Password" ; -}; -CheckBox CB_READ_ONLY -{ - HelpId = HID_FILEDLG_READ_ONLY ; - Text [ en-US ] = "~Read-only" ; -}; -PushButton CB_FILE -{ - HelpId = HID_FILEDLG_FILE ; - Text [ en-US ] = "~File System" ; -}; -PushButton CB_URL -{ - HelpId = HID_FILEDLG_URL ; - Text [ en-US ] = "Int~ernet" ; -}; -PushButton BTN_MANAGER -{ - HelpId = HID_FILEDLG_MANAGER ; - Text [ en-US ] = "~Manager..." ; -}; -PushButton BTN_STANDARD -{ - HelpId = HID_FILEDLG_STANDARD ; - Text [ en-US ] = "~Home" ; -}; -String STR_FILEDLG_INSERT -{ - Text [ en-US ] = "Insert File" ; -}; String STR_TABPAGE_MANAGESTYLES { Text [ en-US ] = "Organizer" ; @@ -131,12 +65,6 @@ InfoBox MSG_POOL_STYLE_NAME { Message [ en-US ] = "Name already exists as a default Style.\nPlease choose another name." ; }; -QueryBox MSG_OVERWRITE_STYLE -{ - Buttons = WB_YES_NO ; - DefButton = WB_DEF_NO ; - Message [ en-US ] = "Style already exists. Overwrite?" ; -}; String STR_DELETE_STYLE { Text [ en-US ] = "Do you really want to delete Style $1?" ; @@ -170,87 +98,15 @@ Menu MN_CONTEXT_TEMPLDLG }; }; -InfoBox MSG_LAYOUT_NOT_LOADING -{ - BUTTONS = WB_OK ; - DEFBUTTON = WB_DEF_OK ; - Message [ en-US ] = "Loading document without layout." ; -}; -Accelerator ACC_LAYOUT_NOT_LOADING -{ - ItemList = - { - AcceleratorItem - { - Key = KeyCode - { - Code = KEY_L ; - Shift = FALSE ; Modifier1 = TRUE ; Modifier2 = TRUE ; - }; - Identifier = 1 ; - }; - }; -}; //------------------------------------------------------------------------ -ErrorBox MSG_ERR_CANT_EDIT_OLD_FORMAT -{ - Message [ en-US ] = "Cannot edit document info for documents\n in this file format." ; -}; - //------------------------------------------------------------------------ -ErrorBox MSG_ERR_CANT_EDIT_OPEN_DOCS -{ - Message [ en-US ] = "Document info of documents\n being currently edited cannot be modified from within the document manager." ; -}; -ModalDialog RID_URLOPEN -{ - OutputSize = TRUE ; - SVLook = TRUE ; - Size = MAP_APPFONT ( 204 , 44 ) ; - Moveable = TRUE ; - Text [ en-US ] = "Enter URL" ; - Moveable = TRUE ; - OKButton RID_URLOPEN_OK - { - Pos = MAP_APPFONT ( 148 , 6 ) ; - Size = MAP_APPFONT ( 50 , 14 ) ; - TabStop = TRUE ; - DefButton = TRUE ; - }; - CancelButton RID_URLOPEN_CANCEL - { - Pos = MAP_APPFONT ( 148 , 24 ) ; - Size = MAP_APPFONT ( 50 , 14 ) ; - TabStop = TRUE ; - }; - Edit RID_URLOPEN_URL - { - Border = TRUE ; - Pos = MAP_APPFONT ( 6 , 16 ) ; - Size = MAP_APPFONT ( 138 , 12 ) ; - TabStop = TRUE ; - Left = TRUE ; - }; -}; -Menu RID_AUTOHIDE -{ - ItemList = - { - MenuItem - { - Identifier = SID_AUTOHIDE ; - HelpID = SID_AUTOHIDE ; - Text [ en-US ] = "Hide" ; - }; - }; -}; -String RID_AUTOHIDE -{ - Text [ en-US ] = "Don't Hide" ; -}; String SID_NAVIGATOR { Text [ en-US ] = "Navigator"; }; +String SID_TASKPANE +{ + Text [ en-US ] = "Task Pane"; +}; ErrorBox MSG_ERROR_WRONG_CONFIRM { @@ -264,11 +120,6 @@ String STR_PDF_EXPORT_SEND Text [ en-US ] = "Send" ; }; -String STR_RECHECK_DOCUMENT -{ - Text [ en-US ] = "Recheck Document" ; -}; - Image IMG_INFO { ImageBitmap = Bitmap diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx index 2936dd0d1c..521a6c3257 100644..100755 --- a/sfx2/source/dialog/dinfdlg.cxx +++ b/sfx2/source/dialog/dinfdlg.cxx @@ -27,12 +27,14 @@ // 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> @@ -58,9 +60,10 @@ #include <com/sun/star/document/XDocumentProperties.hpp> #include <vcl/timer.hxx> -#include <sfx2/dinfdlg.hxx> -#include "sfx2/sfxresid.hxx" -#include "sfx2/dinfedt.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> @@ -119,6 +122,8 @@ 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 ) @@ -858,6 +863,13 @@ SfxDocumentPage::SfxDocumentPage( Window* pParent, const SfxItemSet& rItemSet ) 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(); } //------------------------------------------------------------------------ @@ -1554,6 +1566,7 @@ SfxDocumentInfoDialog::SfxDocumentInfoDialog( Window* pParent, AddTabPage(TP_DOCINFODOC, SfxDocumentPage::Create, 0); AddTabPage(TP_CUSTOMPROPERTIES, SfxCustomPropertiesPage::Create, 0); AddTabPage(TP_DOCINFORELOAD, SfxInternetPage::Create, 0); + AddTabPage(TP_DOCINFOSECURITY, SfxSecurityPage::Create, 0); } // ----------------------------------------------------------------------- diff --git a/sfx2/source/dialog/dinfdlg.src b/sfx2/source/dialog/dinfdlg.src index c8c7d09099..3290983c5b 100644..100755 --- a/sfx2/source/dialog/dinfdlg.src +++ b/sfx2/source/dialog/dinfdlg.src @@ -27,11 +27,11 @@ // include --------------------------------------------------------------- -#include <sfx2/sfx.hrc> +#include "sfx2/sfx.hrc" #include "helpid.hrc" #include "sfxlocal.hrc" #include "dinfdlg.hrc" -#include <dialog.hrc> +#include "dialog.hrc" // TP_DOCINFODESC -------------------------------------------------------- String STR_SFX_NEWOFFICEDOC @@ -685,8 +685,6 @@ QueryBox SFX_QB_WRONG_TYPE Message [ en-US ] = "The value entered does not match the specified type.\nThe value will be stored as text." ; }; - // SID_DOCINFO ----------------------------------------------------------- - TabDialog SID_DOCINFO { OutputSize = TRUE ; @@ -718,6 +716,11 @@ TabDialog SID_DOCINFO Identifier = TP_DOCINFORELOAD ; Text [ en-US ] = "Internet" ; }; + PageItem + { + Identifier = TP_DOCINFOSECURITY ; + Text [ en-US ] = "Security" ; + }; }; }; }; diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index 2b391afc9e..ee7ff5459d 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -57,6 +57,7 @@ #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> @@ -80,11 +81,13 @@ #include <svtools/helpid.hrc> #include <svl/pickerhelper.hxx> #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" @@ -464,31 +467,6 @@ sal_Bool FileDialogHelper_Impl::isInOpenMode() const // ------------------------------------------------------------------------ -namespace { - -bool lclCheckODFPasswordCapability( const SfxFilter* pFilter ) -{ - return pFilter && pFilter->IsOwnFormat() && pFilter->UsesStorage() && (pFilter->GetVersion() >= SOFFICE_FILEFORMAT_60); -} - -bool lclCheckMSPasswordCapability( const SfxFilter* pFilter ) -{ - // TODO #i105076# this should be in the filter configuration!!! - return pFilter && CheckMSPasswordCapabilityForExport( pFilter->GetFilterName() ); -} - -bool lclCheckPasswordCapability( const SfxFilter* pFilter ) -{ - return - lclCheckODFPasswordCapability( pFilter ) || - // TODO #i105076# this should be in the filter configuration!!! - lclCheckMSPasswordCapability( pFilter ); -} - -} - -// ------------------------------------------------------------------------ - void FileDialogHelper_Impl::updateFilterOptionsBox() { if ( !m_bHaveFilterOptions ) @@ -542,11 +520,11 @@ void FileDialogHelper_Impl::updateExportButton() // ------------------------------------------------------------------------ void FileDialogHelper_Impl::updateSelectionBox() { - if ( !mbExport ) + if ( !mbHasSelectionBox ) return; // Does the selection box exist? - bool bSelectionBoxFound = false; + sal_Bool bSelectionBoxFound = sal_False; uno::Reference< XControlInformation > xCtrlInfo( mxFileDlg, UNO_QUERY ); if ( xCtrlInfo.is() ) { @@ -555,7 +533,7 @@ void FileDialogHelper_Impl::updateSelectionBox() for ( sal_uInt32 nCtrl = 0; nCtrl < nCount; ++nCtrl ) if ( aCtrlList[ nCtrl ].equalsAscii("SelectionBox") ) { - bSelectionBoxFound = true; + bSelectionBoxFound = sal_False; break; } } @@ -563,7 +541,7 @@ void FileDialogHelper_Impl::updateSelectionBox() if ( bSelectionBoxFound ) { const SfxFilter* pFilter = getCurentSfxFilter(); - updateExtendedControl( + mbSelectionFltrEnabled = updateExtendedControl( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, ( mbSelectionEnabled && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_SUPPORTSSELECTION ) != 0 ) ); uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); @@ -579,9 +557,10 @@ void FileDialogHelper_Impl::enablePasswordBox( sal_Bool bInit ) sal_Bool bWasEnabled = mbIsPwdEnabled; + const SfxFilter* pCurrentFilter = getCurentSfxFilter(); mbIsPwdEnabled = updateExtendedControl( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, - lclCheckPasswordCapability( getCurentSfxFilter() ) + pCurrentFilter && ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_ENCRYPTION ) ); if( bInit ) @@ -956,6 +935,8 @@ FileDialogHelper_Impl::FileDialogHelper_Impl( 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; @@ -1025,6 +1006,7 @@ FileDialogHelper_Impl::FileDialogHelper_Impl( nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION; mbHasAutoExt = sal_True; mbIsSaveDlg = sal_True; + mbHasSelectionBox = sal_True; if ( mbExport && !mxFilterCFG.is() && xFactory.is() ) { mxFilterCFG = uno::Reference< XNameAccess >( @@ -1550,6 +1532,10 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, { SFX_ITEMSET_ARG( rpSet, pPassItem, SfxStringItem, SID_PASSWORD, FALSE ); mbPwdCheckBoxState = ( pPassItem != NULL ); + + // 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 ); @@ -1560,6 +1546,9 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, // the password will be set in case user decide so rpSet->ClearItem( SID_PASSWORD ); + rpSet->ClearItem( SID_RECOMMENDREADONLY ); + rpSet->ClearItem( SID_MODIFYPASSWORDINFO ); + } if ( mbHasPassword && !mbPwdCheckBoxState ) @@ -1636,13 +1625,15 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, // set the filter getRealFilter( rFilter ); + const SfxFilter* pCurrentFilter = getCurentSfxFilter(); + // fill the rpURLList - implGetAndCacheFiles(mxFileDlg, rpURLList, getCurentSfxFilter()); + 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 ( mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() ) + if ( pCurrentFilter && mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() ) { try { @@ -1656,18 +1647,38 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, if( xInteractionHandler.is() ) { // TODO: need a save way to distinguish MS filters from other filters - bool bMSType = CheckMSPasswordCapabilityForExport( rFilter ); + // 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; - ::comphelper::DocPasswordRequest* pPasswordRequest = new ::comphelper::DocPasswordRequest( - eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)) ); + ::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 ); + uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() ); xInteractionHandler->handle( rRequest ); if ( pPasswordRequest->isPassword() ) - rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) ); + { + if ( pPasswordRequest->getPassword().getLength() ) + rpSet->Put( SfxStringItem( SID_PASSWORD, 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; } @@ -2072,6 +2083,21 @@ void FileDialogHelper_Impl::saveConfig() 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 ) ) ); @@ -2205,6 +2231,17 @@ void FileDialogHelper_Impl::loadConfig() } 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() ); @@ -2664,10 +2701,12 @@ static int impl_isFolder( const OUString& rPath ) { } + ::rtl::Reference< ::comphelper::StillReadWriteInteraction > aHandler = new ::comphelper::StillReadWriteInteraction( xHandler ); + try { ::ucbhelper::Content aContent( - rPath, new ::ucbhelper::CommandEnvironment( xHandler, uno::Reference< ucb::XProgressHandler >() ) ); + rPath, new ::ucbhelper::CommandEnvironment( static_cast< task::XInteractionHandler* > ( aHandler.get() ), uno::Reference< ucb::XProgressHandler >() ) ); if ( aContent.isFolder() ) return 1; diff --git a/sfx2/source/dialog/filedlgimpl.hxx b/sfx2/source/dialog/filedlgimpl.hxx index 2d20b2eca6..f7b6f8d41c 100644 --- a/sfx2/source/dialog/filedlgimpl.hxx +++ b/sfx2/source/dialog/filedlgimpl.hxx @@ -107,6 +107,8 @@ namespace sfx2 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, diff --git a/sfx2/source/dialog/makefile.mk b/sfx2/source/dialog/makefile.mk index 5382eb92e3..26acd12c14 100644..100755 --- a/sfx2/source/dialog/makefile.mk +++ b/sfx2/source/dialog/makefile.mk @@ -45,7 +45,8 @@ EXCEPTIONSFILES=\ $(SLO)$/recfloat.obj \ $(SLO)$/templdlg.obj \ $(SLO)$/dinfdlg.obj \ - $(SLO)$/dockwin.obj + $(SLO)$/dockwin.obj \ + $(SLO)$/taskpane.obj SLOFILES =\ $(EXCEPTIONSFILES) \ @@ -60,7 +61,6 @@ SLOFILES =\ $(SLO)$/passwd.obj \ $(SLO)$/printopt.obj \ $(SLO)$/sfxdlg.obj \ - $(SLO)$/sfxurl.obj \ $(SLO)$/splitwin.obj \ $(SLO)$/srchdlg.obj \ $(SLO)$/styfitem.obj \ @@ -68,7 +68,9 @@ SLOFILES =\ $(SLO)$/tabdlg.obj \ $(SLO)$/tplcitem.obj \ $(SLO)$/tplpitem.obj \ - $(SLO)$/versdlg.obj + $(SLO)$/versdlg.obj \ + $(SLO)$/securitypage.obj \ + $(SLO)$/titledockwin.obj SRS1NAME=$(TARGET) SRC1FILES =\ @@ -85,7 +87,10 @@ SRC1FILES =\ templdlg.src \ versdlg.src \ printopt.src \ - srchdlg.src + srchdlg.src \ + securitypage.src \ + titledockwin.src \ + taskpane.src .IF "$(BUILD_VER_STRING)"!="" .IF "$(GUI)"=="UNX" diff --git a/sfx2/source/dialog/securitypage.cxx b/sfx2/source/dialog/securitypage.cxx new file mode 100755 index 0000000000..5577170c90 --- /dev/null +++ b/sfx2/source/dialog/securitypage.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 "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 ) ); +} + + +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 0000000000..4890b8e54a --- /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 100755 index 0000000000..4818068990 --- /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/taskpane.cxx b/sfx2/source/dialog/taskpane.cxx new file mode 100644 index 0000000000..35da8e2593 --- /dev/null +++ b/sfx2/source/dialog/taskpane.cxx @@ -0,0 +1,1283 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General 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 <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 ) ); + pWindow->Show(); + + dynamic_cast< SfxDockingWindow* >( pWindow )->Initialize( i_pInfo ); + SetHideNotDelete( TRUE ); + } + + //------------------------------------------------------------------------------------------------------------------ + 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 SmartId 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; + } + + //------------------------------------------------------------------------------------------------------------------ + SmartId CustomToolPanel::GetHelpID() const + { + return SmartId( 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; + + 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; + + ::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() ) + { + ::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/sfxurl.cxx b/sfx2/source/dialog/taskpane.src index 42905ae486..4d1a991c0c 100644 --- a/sfx2/source/dialog/sfxurl.cxx +++ b/sfx2/source/dialog/taskpane.src @@ -1,5 +1,4 @@ /************************************************************************* - * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. @@ -25,17 +24,24 @@ * ************************************************************************/ -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_sfx2.hxx" -#include <sfx2/filedlghelper.hxx> -#include <sfx2/sfxresid.hxx> -#include <dialog.hrc> +#include <sfx2/sfx.hrc> +#include "sfxlocal.hrc" + +String STR_SFX_DOCK +{ + Text [ en-US ] = "Dock"; +}; + +String STR_SFX_UNDOCK +{ + Text [ en-US ] = "Undock"; +}; -SfxUrlDialog::SfxUrlDialog( Window *pParent ) - : ModalDialog( pParent, SfxResId( RID_URLOPEN ) ), - aEdit( this, SfxResId(RID_URLOPEN_URL) ), - aOk( this, SfxResId(RID_URLOPEN_OK) ), - aCancel( this, SfxResId(RID_URLOPEN_CANCEL) ) +String STR_SFX_TASK_PANE_VIEW +{ + Text [ en-US ] = "View"; +}; +String STR_SFX_TASKS { - FreeResource(); -} + Text [ en-US ] = "Tasks"; +}; diff --git a/sfx2/source/dialog/titledockwin.cxx b/sfx2/source/dialog/titledockwin.cxx new file mode 100644 index 0000000000..b264561275 --- /dev/null +++ b/sfx2/source/dialog/titledockwin.cxx @@ -0,0 +1,364 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General 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 ) + { + 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 + int nTitleBarHeight( GetSettings().GetStyleSettings().GetTitleHeight() ); + if ( aToolBoxSize.Height() > nTitleBarHeight ) + nTitleBarHeight = aToolBoxSize.Height(); + m_aToolbox.SetPosSizePixel( + Point( + aWindowSize.Width() - aToolBoxSize.Width(), + ( nTitleBarHeight - aToolBoxSize.Height() ) / 2 + ), + aToolBoxSize + ); + + // Place the content window. + if ( nTitleBarHeight < aToolBoxSize.Height() ) + nTitleBarHeight = aToolBoxSize.Height(); + aWindowSize.Height() -= nTitleBarHeight; + m_aContentWindow.SetPosSizePixel( + Point( m_aBorder.Left(), 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 ); + + int nTitleBarHeight( GetSettings().GetStyleSettings().GetTitleHeight() ); + const Size aToolBoxSize = m_aToolbox.CalcWindowSizePixel(); + if ( aToolBoxSize.Height() > nTitleBarHeight ) + nTitleBarHeight = aToolBoxSize.Height(); + + 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 = 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, ULONG 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/view/view.hxx b/sfx2/source/dialog/titledockwin.src index e6daf9484d..4abd7184a8 100644 --- a/sfx2/source/view/view.hxx +++ b/sfx2/source/dialog/titledockwin.src @@ -1,5 +1,4 @@ /************************************************************************* - * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. @@ -25,3 +24,16 @@ * ************************************************************************/ +#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/doc/Metadatable.cxx b/sfx2/source/doc/Metadatable.cxx index f14be1db2c..f77883555c 100644 --- a/sfx2/source/doc/Metadatable.cxx +++ b/sfx2/source/doc/Metadatable.cxx @@ -33,6 +33,8 @@ #include <vos/mutex.hxx> #include <vcl/svapp.hxx> // solarmutex +#include <rtl/random.h> + #include <boost/bind.hpp> #include <memory> @@ -401,14 +403,16 @@ 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 { - const int n( rand() ); - id = prefix + ::rtl::OUString::valueOf(static_cast<sal_Int64>(n)); + 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()); @@ -1488,8 +1492,7 @@ Metadatable::RegisterAsCopyOf(Metadatable const & i_rSource, } } -::boost::shared_ptr<MetadatableUndo> Metadatable::CreateUndo( - const bool i_isDelete) +::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?"); @@ -1503,11 +1506,6 @@ Metadatable::RegisterAsCopyOf(Metadatable const & i_rSource, pRegDoc->CreateUndo(*this) ); pRegDoc->RegisterCopy(*this, *pUndo, false); pUndo->m_pReg = pRegDoc; - - if (i_isDelete) - { - RemoveMetadataReference(); - } return pUndo; } } @@ -1518,6 +1516,13 @@ Metadatable::RegisterAsCopyOf(Metadatable const & i_rSource, 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) { @@ -1624,15 +1629,16 @@ MetadatableMixin::getMetadataReference() throw (uno::RuntimeException) { ::vos::OGuard aGuard( Application::GetSolarMutex() ); - Metadatable* pObject( GetCoreObject() ); - if (pObject) - { - return pObject->GetMetadataReference(); - } - else + + Metadatable *const pObject( GetCoreObject() ); + if (!pObject) { - throw uno::RuntimeException(); + throw uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "MetadatableMixin: cannot get core object; not inserted?")), + *this); } + return pObject->GetMetadataReference(); } void SAL_CALL @@ -1641,30 +1647,32 @@ MetadatableMixin::setMetadataReference( throw (uno::RuntimeException, lang::IllegalArgumentException) { ::vos::OGuard aGuard( Application::GetSolarMutex() ); - Metadatable* pObject( GetCoreObject() ); - if (pObject) - { - return pObject->SetMetadataReference(i_rReference); - } - else + + Metadatable *const pObject( GetCoreObject() ); + if (!pObject) { - throw uno::RuntimeException(); + 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* pObject( GetCoreObject() ); - if (pObject) - { - return pObject->EnsureMetadataReference(); - } - else + + Metadatable *const pObject( GetCoreObject() ); + if (!pObject) { - throw uno::RuntimeException(); + throw uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "MetadatableMixin: cannot get core object; not inserted?")), + *this); } + return pObject->EnsureMetadataReference(); } } // namespace sfx2 @@ -1674,168 +1682,6 @@ throw (uno::RuntimeException) #if OSL_DEBUG_LEVEL > 1 -static ::sfx2::XmlIdRegistryDocument s_Reg; -static ::sfx2::XmlIdRegistryClipboard s_RegClip; - -class MockMetadatable : public ::sfx2::Metadatable -{ -public: - MockMetadatable(bool i_isInClip = false) : - m_bInClipboard(i_isInClip), m_bInUndo(false), m_bInContent(true) {} - bool m_bInClipboard; - bool m_bInUndo; - bool m_bInContent; - virtual bool IsInClipboard() const { return m_bInClipboard; } - virtual bool IsInUndo() const { return m_bInUndo; } - virtual bool IsInContent() const { return m_bInContent; } - virtual ::sfx2::XmlIdRegistry& GetRegistry() { return m_bInClipboard ? static_cast< ::sfx2::XmlIdRegistry&>(s_RegClip) : static_cast< ::sfx2::XmlIdRegistry&>(s_Reg); } - virtual ::com::sun::star::uno::Reference< - ::com::sun::star::rdf::XMetadatable > MakeUnoObject() { return 0; } -}; - -bool operator==(beans::StringPair p1, beans::StringPair p2) -{ - return p1.First == p2.First && p1.Second == p2.Second; -} - -void test() -{ - OSL_TRACE("SwMetadatable test(): start\n"); - MockMetadatable m1; - MockMetadatable m2; - MockMetadatable m3; - MockMetadatable m4; - MockMetadatable m5; - ::rtl::OUString empty; - ::rtl::OUString content( ::rtl::OUString::createFromAscii("content.xml") ); - ::rtl::OUString styles ( ::rtl::OUString::createFromAscii("styles.xml") ); - ::rtl::OUString sid1( ::rtl::OUString::createFromAscii("id1") ); - ::rtl::OUString sid2( ::rtl::OUString::createFromAscii("id2") ); - ::rtl::OUString sid3( ::rtl::OUString::createFromAscii("id3") ); - ::rtl::OUString sid4( ::rtl::OUString::createFromAscii("id4") ); - beans::StringPair id1(content, sid1); - beans::StringPair id2(content, sid2); - beans::StringPair id3(content, sid3); - beans::StringPair id4(styles, sid4); - beans::StringPair id3e(empty, sid3); - beans::StringPair id4e(empty, sid4); - m1.SetMetadataReference(id1); - OSL_ENSURE(m1.GetMetadataReference() == id1, "set failed"); - try { - m2.SetMetadataReference(id1); - OSL_ENSURE(false, "set duplicate succeeded"); - } catch (lang::IllegalArgumentException) { } - m1.SetMetadataReference(id1); - OSL_ENSURE(m1.GetMetadataReference() == id1, "set failed (existing)"); - m1.EnsureMetadataReference(); - OSL_ENSURE(m1.GetMetadataReference() == id1, "ensure failed (existing)"); - - m2.EnsureMetadataReference(); - beans::StringPair m2id(m2.GetMetadataReference()); - OSL_ENSURE(m2id.Second.getLength(), "ensure failed"); - m2.EnsureMetadataReference(); - OSL_ENSURE(m2.GetMetadataReference() == m2id, "ensure failed (idempotent)"); - - m1.m_bInUndo = true; - OSL_ENSURE(!m1.GetMetadataReference().Second.getLength(), "move to undo failed"); - - m1.m_bInUndo = false; - OSL_ENSURE(m1.GetMetadataReference() == id1, "move from undo failed"); - - m1.m_bInUndo = true; - try { - m2.SetMetadataReference(id1); // steal! - } catch (lang::IllegalArgumentException &) { - OSL_ENSURE(false, "set duplicate to undo failed"); - } - m1.m_bInUndo = false; - OSL_ENSURE(!m1.GetMetadataReference().Second.getLength(), "move from undo: duplicate"); - - m3.RegisterAsCopyOf(m2); - OSL_ENSURE(m2.GetMetadataReference() == id1, "copy: source"); - OSL_ENSURE(!m3.GetMetadataReference().Second.getLength(), "copy: duplicate"); - m4.RegisterAsCopyOf(m3); - OSL_ENSURE(m2.GetMetadataReference() == id1, "copy: source"); - OSL_ENSURE(!m3.GetMetadataReference().Second.getLength(), "copy: duplicate"); - OSL_ENSURE(!m4.GetMetadataReference().Second.getLength(), "copy: duplicate"); - m2.m_bInUndo = true; - OSL_ENSURE(m3.GetMetadataReference() == id1, "duplicate to undo"); - OSL_ENSURE(!m2.GetMetadataReference().Second.getLength(), "duplicate to undo"); - m2.m_bInUndo = false; - OSL_ENSURE(m2.GetMetadataReference() == id1, "duplicate from undo"); - OSL_ENSURE(!m3.GetMetadataReference().Second.getLength(), "duplicate from undo"); - - m4.EnsureMetadataReference(); // new! - beans::StringPair m4id(m4.GetMetadataReference()); - OSL_ENSURE(m4id.Second.getLength() && !(m4id == id1), "ensure on duplicate"); - - MockMetadatable mc1(true); // in clipboard - MockMetadatable mc2(true); - MockMetadatable mc3(true); - MockMetadatable mc4(true); - MockMetadatable m2p; - MockMetadatable m3p; - - mc1.SetMetadataReference(id2); - OSL_ENSURE(mc1.GetMetadataReference() == id2, "set failed"); - try { - mc2.SetMetadataReference(id2); - OSL_ENSURE(false, "set duplicate succeeded"); - } catch (lang::IllegalArgumentException) { } - mc1.SetMetadataReference(id2); - OSL_ENSURE(mc1.GetMetadataReference() == id2, "set failed (existing)"); - mc1.EnsureMetadataReference(); - OSL_ENSURE(mc1.GetMetadataReference() == id2, "ensure failed (existing)"); - mc2.EnsureMetadataReference(); - beans::StringPair mc2id(mc2.GetMetadataReference()); - OSL_ENSURE(mc2id.Second.getLength(), "ensure failed"); - mc2.EnsureMetadataReference(); - OSL_ENSURE(mc2.GetMetadataReference() == mc2id, "ensure failed (idempotent)"); - mc2.RemoveMetadataReference(); - OSL_ENSURE(!mc2.GetMetadataReference().Second.getLength(), "remove failed"); - - // set up mc2 as copy of m2 and mc3 as copy of m3 - mc3.RegisterAsCopyOf(m3); - OSL_ENSURE(!mc3.GetMetadataReference().Second.getLength() , "copy to clipboard (latent)"); - mc2.RegisterAsCopyOf(m2); - OSL_ENSURE(mc2.GetMetadataReference() == id1, "copy to clipboard (non-latent)"); - // paste mc2 to m2p and mc3 to m3p - m2p.RegisterAsCopyOf(mc2); - OSL_ENSURE(!m2p.GetMetadataReference().Second.getLength() , "paste from clipboard (non-latent)"); - m3p.RegisterAsCopyOf(mc3); - OSL_ENSURE(!m3p.GetMetadataReference().Second.getLength() , "paste from clipboard (latent)"); - // delete m2, m2p, m3 - m2.RemoveMetadataReference(); - OSL_ENSURE(!m2.GetMetadataReference().Second.getLength(), "remove failed"); - OSL_ENSURE(m2p.GetMetadataReference() == id1, "paste-remove (non-latent)"); - m2p.RemoveMetadataReference(); - OSL_ENSURE(!m2p.GetMetadataReference().Second.getLength(), "remove failed"); - OSL_ENSURE(m3.GetMetadataReference() == id1, "paste-remove2 (non-latent)"); - m3.RemoveMetadataReference(); - OSL_ENSURE(!m3.GetMetadataReference().Second.getLength(), "remove failed"); - OSL_ENSURE(m3p.GetMetadataReference() == id1, "paste-remove (latent)"); - // delete mc2 - mc2.SetMetadataReference(beans::StringPair()); - OSL_ENSURE(!mc3.GetMetadataReference().Second.getLength() , "in clipboard becomes non-latent"); - // paste mc2 - m2p.RegisterAsCopyOf(mc2); - OSL_ENSURE(!m2p.GetMetadataReference().Second.getLength(), "remove-paste"); - OSL_ENSURE(m3p.GetMetadataReference() == id1, "remove-paste (stolen)"); - - // auto-detect stream - m5.SetMetadataReference(id3e); - OSL_ENSURE(m5.GetMetadataReference() == id3, "auto-detect (content)"); - m5.m_bInContent = false; - m5.SetMetadataReference(id4e); - OSL_ENSURE(m5.GetMetadataReference() == id4, "auto-detect (styles)"); - - OSL_TRACE("sfx2::Metadatable test(): finished\n"); -} - -struct Test { Test() { test(); } }; -static Test s_test; - - #include <stdio.h> static void dump(sfx2::XmlIdList_t * pList) diff --git a/sfx2/source/doc/SfxDocumentMetaData.cxx b/sfx2/source/doc/SfxDocumentMetaData.cxx index 6f9c9d0bd5..95fe000709 100644 --- a/sfx2/source/doc/SfxDocumentMetaData.cxx +++ b/sfx2/source/doc/SfxDocumentMetaData.cxx @@ -38,7 +38,6 @@ #include "com/sun/star/util/XModifiable.hpp" #include "com/sun/star/xml/sax/XSAXSerializable.hpp" -#include "com/sun/star/lang/NullPointerException.hpp" #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp" #include "com/sun/star/lang/EventObject.hpp" #include "com/sun/star/beans/XPropertySet.hpp" @@ -248,25 +247,21 @@ public: const css::uno::Sequence< css::beans::PropertyValue > & Medium) throw (css::uno::RuntimeException, css::lang::IllegalArgumentException, css::io::WrongFormatException, - css::lang::WrappedTargetException, css::io::IOException, - css::uno::Exception); + 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, - css::uno::Exception); + 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, - css::uno::Exception); + 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, - css::uno::Exception); + css::lang::WrappedTargetException, css::io::IOException); // ::com::sun::star::lang::XInitialization: virtual void SAL_CALL initialize( @@ -1869,8 +1864,7 @@ SfxDocumentMetaData::loadFromStorage( const css::uno::Sequence< css::beans::PropertyValue > & Medium) throw (css::uno::RuntimeException, css::lang::IllegalArgumentException, css::io::WrongFormatException, - css::lang::WrappedTargetException, css::io::IOException, - css::uno::Exception) + css::lang::WrappedTargetException, css::io::IOException) { if (!xStorage.is()) throw css::lang::IllegalArgumentException( ::rtl::OUString::createFromAscii("SfxDocumentMetaData::loadFromStorage:" @@ -1882,10 +1876,10 @@ SfxDocumentMetaData::loadFromStorage( xStorage->openStreamElement( ::rtl::OUString::createFromAscii(s_metaXml), css::embed::ElementModes::READ) ); - if (!xStream.is()) throw css::lang::NullPointerException(); + if (!xStream.is()) throw css::uno::RuntimeException(); css::uno::Reference<css::io::XInputStream> xInStream = xStream->getInputStream(); - if (!xInStream.is()) throw css::lang::NullPointerException(); + if (!xInStream.is()) throw css::uno::RuntimeException(); // create DOM parser service css::uno::Reference<css::lang::XMultiComponentFactory> xMsf ( @@ -1949,8 +1943,7 @@ 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, - css::uno::Exception) + css::lang::WrappedTargetException, css::io::IOException) { if (!xStorage.is()) throw css::lang::IllegalArgumentException( ::rtl::OUString::createFromAscii("SfxDocumentMetaData::storeToStorage:" @@ -1966,7 +1959,7 @@ SfxDocumentMetaData::storeToStorage( xStorage->openStreamElement(::rtl::OUString::createFromAscii(s_metaXml), css::embed::ElementModes::WRITE | css::embed::ElementModes::TRUNCATE); - if (!xStream.is()) throw css::lang::NullPointerException(); + if (!xStream.is()) throw css::uno::RuntimeException(); css::uno::Reference< css::beans::XPropertySet > xStreamProps(xStream, css::uno::UNO_QUERY_THROW); xStreamProps->setPropertyValue( @@ -1980,7 +1973,7 @@ SfxDocumentMetaData::storeToStorage( css::uno::makeAny(static_cast<sal_Bool> (sal_False))); css::uno::Reference<css::io::XOutputStream> xOutStream = xStream->getOutputStream(); - if (!xOutStream.is()) throw css::lang::NullPointerException(); + if (!xOutStream.is()) throw css::uno::RuntimeException(); css::uno::Reference<css::lang::XMultiComponentFactory> xMsf ( m_xContext->getServiceManager()); css::uno::Reference<css::io::XActiveDataSource> xSaxWriter( @@ -2028,8 +2021,7 @@ 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::Exception) + css::lang::WrappedTargetException, css::io::IOException) { css::uno::Reference<css::io::XInputStream> xIn; ::comphelper::MediaDescriptor md(Medium); @@ -2063,7 +2055,7 @@ SfxDocumentMetaData::loadFromMedium(const ::rtl::OUString & URL, css::uno::makeAny(e)); } if (!xStorage.is()) { - throw css::lang::NullPointerException(::rtl::OUString::createFromAscii( + throw css::uno::RuntimeException(::rtl::OUString::createFromAscii( "SfxDocumentMetaData::loadFromMedium: cannot get Storage"), *this); } @@ -2074,8 +2066,7 @@ 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, - css::uno::Exception) + css::lang::WrappedTargetException, css::io::IOException) { ::comphelper::MediaDescriptor md(Medium); if (!URL.equalsAscii("")) { @@ -2087,7 +2078,7 @@ SfxDocumentMetaData::storeToMedium(const ::rtl::OUString & URL, if (!xStorage.is()) { - throw css::lang::NullPointerException(::rtl::OUString::createFromAscii( + throw css::uno::RuntimeException(::rtl::OUString::createFromAscii( "SfxDocumentMetaData::storeToMedium: cannot get Storage"), *this); } diff --git a/sfx2/source/doc/commitlistener.hxx b/sfx2/source/doc/commitlistener.hxx deleted file mode 100644 index bffcd508d4..0000000000 --- a/sfx2/source/doc/commitlistener.hxx +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General 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 __COMMITLISTENER_HXX_ -#define __COMMITLISTENER_HXX_ - -#include <com/sun/star/embed/XTransactionListener.hpp> -#include <cppuhelper/implbase1.hxx> -#include <osl/mutex.hxx> - -#include <sfx2/sfxbasemodel.hxx> - -class OChildCommitListen_Impl : public ::cppu::WeakImplHelper1 < ::com::sun::star::embed::XTransactionListener > -{ - ::osl::Mutex m_aMutex; - SfxBaseModel* m_pModel; - -public: - OChildCommitListen_Impl( SfxBaseModel& aStorage ); - virtual ~OChildCommitListen_Impl(); - - void OwnerIsDisposed(); - - virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& 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); -}; - -#endif - diff --git a/sfx2/source/doc/docfac.cxx b/sfx2/source/doc/docfac.cxx index f7ee4a5509..9041d386d0 100644 --- a/sfx2/source/doc/docfac.cxx +++ b/sfx2/source/doc/docfac.cxx @@ -30,13 +30,19 @@ #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> @@ -49,9 +55,15 @@ #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; //======================================================================== @@ -182,13 +194,130 @@ 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 ) diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index d89a59c0a3..f95da331c2 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -116,6 +116,7 @@ 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> @@ -134,7 +135,6 @@ using namespace ::com::sun::star::io; #include <unotools/saveopt.hxx> #include <svl/documentlockfile.hxx> -#include "opostponedtruncationstream.hxx" #include "helper.hxx" #include <sfx2/request.hxx> // SFX_ITEMSET_SET #include <sfx2/app.hxx> // GetFilterMatcher @@ -2560,18 +2560,72 @@ 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() diff --git a/sfx2/source/doc/docfilt.cxx b/sfx2/source/doc/docfilt.cxx index b4ae994786..202140a15b 100644 --- a/sfx2/source/doc/docfilt.cxx +++ b/sfx2/source/doc/docfilt.cxx @@ -49,20 +49,6 @@ using namespace ::com::sun::star; -namespace sfx2 { - -// TODO #i105076# this should be in the filter configuration!!! -bool CheckMSPasswordCapabilityForExport( const String& rFilterName ) -{ - return - rFilterName.EqualsAscii( "MS Word 97" ) || - rFilterName.EqualsAscii( "MS Word 97 Vorlage" ) || - rFilterName.EqualsAscii( "MS Excel 97" ) || - rFilterName.EqualsAscii( "MS Excel 97 Vorlage/Template" ); -} - -} // namespace sfx2 - // STATIC DATA ----------------------------------------------------------- DBG_NAME(SfxFilter) diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index 50aec55499..f925c0bb2f 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -62,6 +62,9 @@ #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> @@ -80,6 +83,7 @@ #include <sfx2/app.hxx> #include <sfx2/objsh.hxx> #include <sfx2/dinfdlg.hxx> +#include <sfx2/request.hxx> #include <sfxtypes.hxx> #include "alienwarn.hxx" @@ -108,6 +112,7 @@ const ::rtl::OUString aFilterFlagsString = ::rtl::OUString::createFromAscii( " using namespace ::com::sun::star; +namespace { //------------------------------------------------------------------------- static sal_uInt16 getSlotIDFromMode( sal_Int8 nStoreMode ) { @@ -168,6 +173,69 @@ static sal_Int32 getDontFlags( sal_Int8 nStoreMode ) } //========================================================================= +// 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 @@ -184,6 +252,8 @@ class ModelData_Impl ::comphelper::SequenceAsHashMap m_aMediaDescrHM; + sal_Bool m_bRecommendReadOnly; + public: ModelData_Impl( SfxStoringHelper& aOwner, const uno::Reference< frame::XModel >& xModel, @@ -200,6 +270,8 @@ public: ::comphelper::SequenceAsHashMap& GetMediaDescr() { return m_aMediaDescrHM; } + sal_Bool IsRecommendReadOnly() { return m_bRecommendReadOnly; } + const ::comphelper::SequenceAsHashMap& GetDocProps(); ::rtl::OUString GetModuleName(); @@ -252,6 +324,7 @@ ModelData_Impl::ModelData_Impl( SfxStoringHelper& aOwner, , m_pDocumentPropsHM( NULL ) , m_pModulePropsHM( NULL ) , m_aMediaDescrHM( aMediaDescr ) +, m_bRecommendReadOnly( sal_False ) { CheckInteractionHandler(); } @@ -836,9 +909,16 @@ sal_Bool ModelData_Impl::OutputFileDialog( sal_Int8 nStoreMode, ::rtl::OUString aAdjustToType; - // bSetStandardName == true means that user agreed to store document in the default (default default ;-)) format - if ( !(( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED )) && - ( bSetStandardName || GetStorable()->hasLocation() )) + 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( @@ -915,6 +995,12 @@ sal_Bool ModelData_Impl::OutputFileDialog( sal_Int8 nStoreMode, } ::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 ); @@ -1238,6 +1324,7 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& // parse the slot name sal_Int8 nStoreMode = getStoreModeFromSlotName( aSlotName ); + sal_Int8 nStatusSave = STATUS_NO_ACTION; // handle the special cases if ( nStoreMode & SAVEAS_REQUESTED ) @@ -1259,7 +1346,7 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& else if ( nStoreMode & SAVE_REQUESTED ) { // if saving is not acceptable by the configuration the warning must be shown - sal_Int8 nStatusSave = aModelData.CheckSaveAcceptable( STATUS_SAVE ); + nStatusSave = aModelData.CheckSaveAcceptable( STATUS_SAVE ); if ( nStatusSave == STATUS_NO_ACTION ) throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT ); @@ -1273,32 +1360,7 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& { throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT ); } - else if ( 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; - } - else + else if ( nStatusSave != STATUS_SAVE ) { // this should be a usual SaveAs operation nStoreMode = SAVEAS_REQUESTED; @@ -1325,6 +1387,32 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& } } + 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 ); @@ -1419,13 +1507,13 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& ::rtl::OUString aSelFilterName = aModelData.GetMediaDescr().getUnpackedValueOrDefault( aFilterNameString, ::rtl::OUString() ); - sal_Int8 nStatusSave = aModelData.CheckFilter( aSelFilterName ); - if ( nStatusSave == STATUS_SAVEAS_STANDARDNAME ) + sal_Int8 nStatusFilterSave = aModelData.CheckFilter( aSelFilterName ); + if ( nStatusFilterSave == STATUS_SAVEAS_STANDARDNAME ) { // switch to best filter bSetStandardName = sal_True; } - else if ( nStatusSave == STATUS_SAVE ) + else if ( nStatusFilterSave == STATUS_SAVE ) { // user confirmed alien filter or "good" filter is used bExit = sal_True; @@ -1500,6 +1588,8 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& // store the document and handle it's docinfo SvtSaveOptions aOptions; + DocumentSettingsGuard aSettingsGuard( aModelData.GetModel(), aModelData.IsRecommendReadOnly(), nStoreMode & EXPORT_REQUESTED ); + if ( aOptions.IsDocInfoSave() && ( !aModelData.GetStorable()->hasLocation() || INetURLObject( aModelData.GetStorable()->getLocation() ) != aURL ) ) @@ -1570,8 +1660,10 @@ uno::Sequence< beans::PropertyValue > SfxStoringHelper::SearchForFilter( uno::Reference< container::XEnumeration > xFilterEnum = xFilterQuery->createSubSetEnumerationByProperties( aSearchRequest ); - // use the first filter that is found + // the first default filter will be taken, + // if there is no filter with flag default the first acceptable filter will be taken if ( xFilterEnum.is() ) + { while ( xFilterEnum->hasMoreElements() ) { uno::Sequence< beans::PropertyValue > aProps; @@ -1582,11 +1674,17 @@ uno::Sequence< beans::PropertyValue > SfxStoringHelper::SearchForFilter( (sal_Int32)0 ); if ( ( ( nFlags & nMustFlags ) == nMustFlags ) && !( nFlags & nDontFlags ) ) { - aFilterProps = aProps; - break; + if ( ( nFlags & SFX_FILTER_DEFAULT ) == SFX_FILTER_DEFAULT ) + { + aFilterProps = aProps; + break; + } + else if ( !aFilterProps.getLength() ) + aFilterProps = aProps; } } } + } return aFilterProps; } diff --git a/sfx2/source/doc/makefile.mk b/sfx2/source/doc/makefile.mk index 7da456ebaa..b1bddf82e4 100644 --- a/sfx2/source/doc/makefile.mk +++ b/sfx2/source/doc/makefile.mk @@ -75,7 +75,6 @@ SLOFILES = \ $(SLO)$/objembed.obj\ $(SLO)$/graphhelp.obj \ $(SLO)$/QuerySaveDocument.obj \ - $(SLO)$/opostponedtruncationstream.obj \ $(SLO)$/docinsert.obj \ $(SLO)$/docmacromode.obj \ $(SLO)$/SfxDocumentMetaData.obj \ @@ -84,7 +83,9 @@ SLOFILES = \ $(SLO)$/sfxmodelfactory.obj \ $(SLO)$/sfxacldetect.obj \ $(SLO)$/docstoragemodifylistener.obj \ - $(SLO)$/querytemplate.obj + $(SLO)$/querytemplate.obj \ + $(SLO)$/syspath.obj \ + $(SLO)$/syspathw32.obj # $(SLO)$/applet.obj \ @@ -92,7 +93,8 @@ SLOFILES = \ #HACK TO DISABLE PCH NOOPTFILES= \ - $(SLO)$/sfxacldetect.obj + $(SLO)$/sfxacldetect.obj \ + $(SLO)$/syspathw32.obj .ENDIF diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx index 9a48df8711..3a2e777c1e 100644 --- a/sfx2/source/doc/objcont.cxx +++ b/sfx2/source/doc/objcont.cxx @@ -1242,3 +1242,51 @@ void SfxObjectShell::SetSaveVersionOnClose( sal_Bool bNew ) 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/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index bb78df3b70..ba2ad9c3c3 100644..100755 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -471,6 +471,32 @@ void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly ) //------------------------------------------------------------------------- +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(); @@ -1364,6 +1390,9 @@ void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags ) if( !IsAbortingImport() ) PositionView_Impl(); + if ( ( GetModifyPasswordHash() || GetModifyPasswordInfo().getLength() ) && !IsModifyPasswordEntered() ) + SetReadOnly(); + // Salvage if ( pSalvageItem ) bSetModifiedTRUE = sal_True; @@ -1682,7 +1711,7 @@ namespace } ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptContext, const ::rtl::OUString& _rScriptURL, - const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) + const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam, bool bRaiseError ) { OSL_TRACE( "in CallXScript" ); ErrCode nErr = ERRCODE_NONE; @@ -1723,7 +1752,7 @@ ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptCon nErr = ERRCODE_BASIC_INTERNAL_ERROR; } - if ( bCaughtException ) + if ( bCaughtException && bRaiseError ) { ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg; SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); @@ -1746,10 +1775,10 @@ ErrCode SfxObjectShell::CallXScript( const String& rScriptURL, 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) + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam + , bool bRaiseError ) { - return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam ); + return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError ); } //------------------------------------------------------------------------- diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 7374b25f4b..7943e95222 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -1332,7 +1332,6 @@ sal_Bool SfxObjectShell::SaveTo_Impl { if ( pFilt->GetServiceName() != rMedium.GetFilter()->GetServiceName() ) { -//REMOVE rMedium.GetStorage()->SetClass( SvFactory::GetServerName( nFormat ), nFormat, pFilt->GetTypeName() ); datatransfer::DataFlavor aDataFlavor; SotExchange::GetFormatDataFlavor( nFormat, aDataFlavor ); @@ -2049,9 +2048,6 @@ sal_Bool SfxObjectShell::DoSaveCompleted( SfxMedium* pNewMed ) } else { -//REMOVE if( pFilter->UsesStorage() ) -//REMOVE pMedium->GetStorage(); -//REMOVE else if( pMedium->GetOpenMode() & STREAM_WRITE ) if( pMedium->GetOpenMode() & STREAM_WRITE ) pMedium->GetInStream(); xStorage = GetStorage(); @@ -2548,6 +2544,7 @@ sal_Bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs ) // 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 ) @@ -2588,9 +2585,6 @@ sal_Bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs ) SetError(pMediumTmp->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); -//REMOVE if ( !IsHandsOff() ) -//REMOVE pMediumTmp->Close(); - sal_Bool bOpen( sal_False ); bOpen = DoSaveCompleted( pMediumTmp ); DBG_ASSERT(bOpen,"Fehlerbehandlung fuer DoSaveCompleted nicht implementiert"); @@ -2601,13 +2595,7 @@ sal_Bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs ) SetError( pMediumTmp->GetError(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); // reconnect to object storage -//REMOVE if ( IsHandsOff() ) -//REMOVE { -//REMOVE if ( !DoSaveCompleted( pRetrMedium ) ) -//REMOVE DBG_ERROR("Case not handled - no way to get a storage!"); -//REMOVE } -//REMOVE else - DoSaveCompleted( 0 ); + DoSaveCompleted( 0 ); if( pRetrMedium->GetItemSet() ) { @@ -2833,6 +2821,7 @@ sal_Bool SfxObjectShell::PreDoSaveAs_Impl pMergedParams->ClearItem( SID_STREAM ); pMergedParams->ClearItem( SID_CONTENT ); pMergedParams->ClearItem( SID_DOC_READONLY ); + pMergedParams->ClearItem( SID_DOC_BASEURL ); pMergedParams->ClearItem( SID_REPAIRPACKAGE ); @@ -2865,8 +2854,6 @@ sal_Bool SfxObjectShell::PreDoSaveAs_Impl else pNewFile->SetFilter( GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT ) ); -//REMOVE // saving is alway done using a temporary file -//REMOVE pNewFile->CreateTempFileNoCopy(); if ( pNewFile->GetErrorCode() != ERRCODE_NONE ) { // creating temporary file failed ( f.e. floppy disk not inserted! ) @@ -2903,18 +2890,8 @@ sal_Bool SfxObjectShell::PreDoSaveAs_Impl SetError( pNewFile->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); // notify the document that saving was done successfully -//REMOVE if ( bCopyTo ) -//REMOVE { -//REMOVE if ( IsHandsOff() ) -//REMOVE bOk = DoSaveCompleted( pMedium ); -//REMOVE } -//REMOVE else if ( !bCopyTo ) { - // Muss !!! -//REMOVE if ( bToOwnFormat ) -//REMOVE SetFileName( pNewFile->GetPhysicalName() ); - bOk = DoSaveCompleted( pNewFile ); } else @@ -2946,31 +2923,12 @@ sal_Bool SfxObjectShell::PreDoSaveAs_Impl // by the storage DELETEZ( pNewFile ); } - - // TODO/LATER: there is no need in the following code in case HandsOff is not used, - // hope we will not have to introduce it back -//REMOVE String aPasswd; -//REMOVE if ( IsOwnStorageFormat_Impl( *GetMedium() ) && GetPasswd_Impl( GetMedium()->GetItemSet(), aPasswd ) ) -//REMOVE { -//REMOVE try -//REMOVE { -//REMOVE // the following code must throw an exception in case of failure -//REMOVE ::comphelper::OStorageHelper::SetCommonStoragePassword( GetMedium->GetStorage(), aPasswd ); -//REMOVE } -//REMOVE catch( uno::Exception& ) -//REMOVE { -//REMOVE // TODO: handle the error -//REMOVE } -//REMOVE } } else { SetError( pNewFile->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); -//REMOVE // reconnect to the old storage -//REMOVE if ( IsHandsOff() ) -//REMOVE DoSaveCompleted( pMedium ); -//REMOVE else + // reconnect to the old storage DoSaveCompleted( 0 ); DELETEZ( pNewFile ); @@ -3151,9 +3109,6 @@ sal_Bool SfxObjectShell::LoadOwnFormat( SfxMedium& rMedium ) uno::Reference< embed::XStorage > xStorage = rMedium.GetStorage(); if ( xStorage.is() ) { -//REMOVE if ( rMedium.GetFileVersion() ) -//REMOVE xStor->SetVersion( rMedium.GetFileVersion() ); - // Password SFX_ITEMSET_ARG( rMedium.GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False ); if ( pPasswdItem || ERRCODE_IO_ABORT != CheckPasswd_Impl( this, SFX_APP()->GetPool(), pMedium ) ) diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index 3f30c4b1d3..00e82898ae 100644..100755 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -247,6 +247,8 @@ SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell ) ,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(); @@ -1074,3 +1076,43 @@ void SfxObjectShell::SetInitialized_Impl( const bool i_fromInitNew ) 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/opostponedtruncationstream.cxx b/sfx2/source/doc/opostponedtruncationstream.cxx deleted file mode 100644 index 364a4d5a65..0000000000 --- a/sfx2/source/doc/opostponedtruncationstream.cxx +++ /dev/null @@ -1,491 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General 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 <osl/diagnose.h> - -#include <opostponedtruncationstream.hxx> - -using namespace ::com::sun::star; - -// ======================================================================== -struct PTFStreamData_Impl -{ - uno::Reference< ucb::XSimpleFileAccess > m_xFileAccess; - sal_Bool m_bDelete; - ::rtl::OUString m_aURL; - - // the streams below are not visible from outside so there is no need to remember position - - // original stream related members - uno::Reference< io::XStream > m_xOrigStream; - uno::Reference< io::XTruncate > m_xOrigTruncate; - uno::Reference< io::XSeekable > m_xOrigSeekable; - uno::Reference< io::XInputStream > m_xOrigInStream; - uno::Reference< io::XOutputStream > m_xOrigOutStream; - - sal_Bool m_bInOpen; - sal_Bool m_bOutOpen; - - sal_Bool m_bPostponedTruncate; - - - PTFStreamData_Impl( - const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess, - sal_Bool bDelete, - const ::rtl::OUString& aURL, - const uno::Reference< io::XStream >& xOrigStream, - const uno::Reference< io::XTruncate >& xOrigTruncate, - const uno::Reference< io::XSeekable >& xOrigSeekable, - const uno::Reference< io::XInputStream >& xOrigInStream, - const uno::Reference< io::XOutputStream >& xOrigOutStream ) - : m_xFileAccess( xFileAccess ) - , m_bDelete( bDelete ) - , m_aURL( aURL ) - , m_xOrigStream( xOrigStream ) - , m_xOrigTruncate( xOrigTruncate ) - , m_xOrigSeekable( xOrigSeekable ) - , m_xOrigInStream( xOrigInStream ) - , m_xOrigOutStream( xOrigOutStream ) - , m_bInOpen( sal_False ) - , m_bOutOpen( sal_False ) - , m_bPostponedTruncate( sal_True ) - {} - - void NoPostponing() - { - m_bDelete = sal_False; - m_bPostponedTruncate = sal_False; - } -}; - -// ======================================================================== -// ------------------------------------------------------------------------ -OPostponedTruncationFileStream::OPostponedTruncationFileStream( - const ::rtl::OUString& aURL, - const uno::Reference< lang::XMultiServiceFactory >& /*xFactory*/, - const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess, - const uno::Reference< io::XStream >& xOrigStream, - sal_Bool bDelete ) -: m_pStreamData( NULL ) -{ - if ( !xFileAccess.is() || !xOrigStream.is() ) - throw uno::RuntimeException(); - - uno::Reference< io::XTruncate > xOrigTruncate( xOrigStream, uno::UNO_QUERY_THROW ); - uno::Reference< io::XSeekable > xOrigSeekable( xOrigStream, uno::UNO_QUERY_THROW ); - uno::Reference< io::XInputStream > xOrigInStream = xOrigStream->getInputStream(); - uno::Reference< io::XOutputStream > xOrigOutStream = xOrigStream->getOutputStream(); - if ( !xOrigInStream.is() || !xOrigOutStream.is() ) - throw uno::RuntimeException(); - - m_pStreamData = new PTFStreamData_Impl( xFileAccess, bDelete, aURL, - xOrigStream, xOrigTruncate, xOrigSeekable, xOrigInStream, xOrigOutStream ); -} - -// ------------------------------------------------------------------------ -OPostponedTruncationFileStream::~OPostponedTruncationFileStream() -{ - CloseAll_Impl(); -} - -// ------------------------------------------------------------------------ -void OPostponedTruncationFileStream::CloseAll_Impl() -{ - if ( m_pStreamData ) - { - sal_Bool bDelete = m_pStreamData->m_bDelete; - ::rtl::OUString aURL = m_pStreamData->m_aURL; - uno::Reference< ucb::XSimpleFileAccess > xFileAccess = m_pStreamData->m_xFileAccess; - - delete m_pStreamData; - m_pStreamData = NULL; - - if ( bDelete && xFileAccess.is() && aURL.getLength() ) - { - // delete the file - try - { - xFileAccess->kill( aURL ); - } catch( uno::Exception& ) - { - OSL_ENSURE( sal_False, "Could not remove the file!" ); - } - } - } -} - -// ------------------------------------------------------------------------ -void OPostponedTruncationFileStream::CheckScheduledTruncation_Impl() -{ - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bPostponedTruncate ) - { - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigTruncate.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigTruncate->truncate(); - m_pStreamData->NoPostponing(); - } -} - -// com::sun::star::io::XStream -// ------------------------------------------------------------------------ -uno::Reference< io::XInputStream > SAL_CALL OPostponedTruncationFileStream::getInputStream( ) - throw (uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pStreamData ) - m_pStreamData->m_bInOpen = sal_True; - return static_cast< io::XInputStream* >( this ); -} - - -// ------------------------------------------------------------------------ -uno::Reference< io::XOutputStream > SAL_CALL OPostponedTruncationFileStream::getOutputStream( ) - throw (uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pStreamData ) - m_pStreamData->m_bOutOpen = sal_True; - return static_cast< io::XOutputStream* >( this ); -} - - - -// com::sun::star::io::XInputStream -// ------------------------------------------------------------------------ -::sal_Int32 SAL_CALL OPostponedTruncationFileStream::readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bPostponedTruncate ) - { - // the stream must behave as truncated one - aData.realloc( 0 ); - return 0; - } - else - { - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigInStream->readBytes( aData, nBytesToRead ); - } -} - - -// ------------------------------------------------------------------------ -::sal_Int32 SAL_CALL OPostponedTruncationFileStream::readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bPostponedTruncate ) - { - // the stream must behave as truncated one - aData.realloc( 0 ); - return 0; - } - else - { - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigInStream->readBytes( aData, nMaxBytesToRead ); - } -} - -// ------------------------------------------------------------------------ -void SAL_CALL OPostponedTruncationFileStream::skipBytes( ::sal_Int32 nBytesToSkip ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bPostponedTruncate ) - { - // the stream must behave as truncated one - if ( nBytesToSkip > 0 ) - throw io::BufferSizeExceededException(); - - return; - } - else - { - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigInStream->skipBytes( nBytesToSkip ); - } -} - - -// ------------------------------------------------------------------------ -::sal_Int32 SAL_CALL OPostponedTruncationFileStream::available( ) - throw (io::NotConnectedException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bPostponedTruncate ) - { - // the stream must behave as truncated one - return 0; - } - else - { - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigInStream->available(); - } -} - - -// ------------------------------------------------------------------------ -void SAL_CALL OPostponedTruncationFileStream::closeInput() - throw (io::NotConnectedException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - m_pStreamData->m_bInOpen = sal_False; - if ( !m_pStreamData->m_bOutOpen ) - CloseAll_Impl(); -} - - - -// com::sun::star::io::XOutputStream -// ------------------------------------------------------------------------ -void SAL_CALL OPostponedTruncationFileStream::writeBytes( const uno::Sequence< ::sal_Int8 >& aData ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // writing method must check the truncation - CheckScheduledTruncation_Impl(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigOutStream.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigOutStream->writeBytes( aData ); -} - - -// ------------------------------------------------------------------------ -void SAL_CALL OPostponedTruncationFileStream::flush( ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - { - OSL_ENSURE( sal_False, "flush() call on closed stream!\n" ); - return; - // in future throw exception, for now some code might call flush() on closed stream - // since file ucp implementation allows it - // throw io::NotConnectedException(); - } - - if ( m_pStreamData->m_bPostponedTruncate ) - { - // it is no writing call, thus must be ignored - return; - } - else - { - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigOutStream.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigOutStream->flush(); - } -} - - -// ------------------------------------------------------------------------ -void SAL_CALL OPostponedTruncationFileStream::closeOutput( ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - m_pStreamData->m_bOutOpen = sal_False; - if ( !m_pStreamData->m_bInOpen ) - CloseAll_Impl(); -} - - - -// com::sun::star::io::XTruncate -// ------------------------------------------------------------------------ -void SAL_CALL OPostponedTruncationFileStream::truncate( ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bPostponedTruncate ) - { - // the truncation is already scheduled, ignore - return; - } - else - { - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigTruncate.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigTruncate->truncate(); - } -} - - - -// com::sun::star::io::XSeekable -// ------------------------------------------------------------------------ -void SAL_CALL OPostponedTruncationFileStream::seek( ::sal_Int64 location ) - throw (lang::IllegalArgumentException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bPostponedTruncate ) - { - if ( location > 0 ) - throw lang::IllegalArgumentException(); - - return; - } - else - { - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigSeekable->seek( location ); - } -} - - -// ------------------------------------------------------------------------ -::sal_Int64 SAL_CALL OPostponedTruncationFileStream::getPosition( ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bPostponedTruncate ) - { - return 0; - } - else - { - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigSeekable->getPosition(); - } -} - - -// ------------------------------------------------------------------------ -::sal_Int64 SAL_CALL OPostponedTruncationFileStream::getLength( ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bPostponedTruncate ) - { - return 0; - } - else - { - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigSeekable->getLength(); - } -} - -// ------------------------------------------------------------------------ -void SAL_CALL OPostponedTruncationFileStream::waitForCompletion() - throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) -{ - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bPostponedTruncate ) - return; - - uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( m_pStreamData->m_xOrigOutStream, uno::UNO_QUERY ); - if ( asyncOutputMonitor.is() ) - asyncOutputMonitor->waitForCompletion(); -} - diff --git a/sfx2/source/doc/opostponedtruncationstream.hxx b/sfx2/source/doc/opostponedtruncationstream.hxx deleted file mode 100644 index ce60cdf2e0..0000000000 --- a/sfx2/source/doc/opostponedtruncationstream.hxx +++ /dev/null @@ -1,122 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General 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_OPOSTPONEDTRUNCATIONFILESTREAM_HXX -#define _SFX_OPOSTPONEDTRUNCATIONFILESTREAM_HXX - -#include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XTruncate.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> -#include <com/sun/star/beans/XPropertySetInfo.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/io/XAsyncOutputMonitor.hpp> -#include <osl/mutex.hxx> -#include <cppuhelper/implbase6.hxx> -#include "sfx2/dllapi.h" - -//================================================================== -// OPostponedTruncationFileStream -// -// Allows to get stream access to a file, where the first truncation -// of the file is postponed till the first writing. If no writing happens -// after the first truncation/creation, it has no effect. ( The postponing of -// the creation can be switched off during initialization. Here the postponing -// of the creation means that the file will be created immediatelly, but -// if nothing is written into it, it will be removed during destruction -// of the object. ) -// -// On creation of this object the target file is scheduled for -// creation/truncation. But the action happens only during the first -// write access. After the first write access the object behaves -// itself as the original stream. -//================================================================== - -struct PTFStreamData_Impl; -class SFX2_DLLPUBLIC OPostponedTruncationFileStream - : public ::cppu::WeakImplHelper6 < - ::com::sun::star::io::XStream, - ::com::sun::star::io::XInputStream, - ::com::sun::star::io::XOutputStream, - ::com::sun::star::io::XTruncate, - ::com::sun::star::io::XSeekable, - ::com::sun::star::io::XAsyncOutputMonitor > -{ - ::osl::Mutex m_aMutex; - PTFStreamData_Impl* m_pStreamData; - - void CloseAll_Impl(); - - void CheckScheduledTruncation_Impl(); - -public: - - OPostponedTruncationFileStream( - const ::rtl::OUString& aURL, - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, - const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xFileAccess, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream, - sal_Bool bDelete ); - - ~OPostponedTruncationFileStream(); - -// com::sun::star::io::XStream - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XInputStream - virtual ::sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int32 SAL_CALL available( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XOutputStream - virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL flush( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeOutput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XTruncate - virtual void SAL_CALL truncate( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XSeekable - virtual void SAL_CALL seek( ::sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int64 SAL_CALL getPosition( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int64 SAL_CALL getLength( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// ::com::sun::star::io::XAsyncOutputMonitor - virtual void SAL_CALL waitForCompletion( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -}; - -#endif //_SFX_OPOSTPONEDTRUNCATIONFILESTREAM_HXX - - diff --git a/sfx2/source/doc/printhelper.cxx b/sfx2/source/doc/printhelper.cxx index b446b11777..fee1e4df3c 100755 --- a/sfx2/source/doc/printhelper.cxx +++ b/sfx2/source/doc/printhelper.cxx @@ -266,17 +266,23 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SfxPrintHelper::getPrinter() thro // object already disposed? ::vos::OGuard aGuard( Application::GetSolarMutex() ); - // Printer beschaffen - SfxViewFrame *pViewFrm = m_pData->m_pObjectShell.Is() ? - SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False ) : 0; - if ( !pViewFrm ) - return uno::Sequence< beans::PropertyValue >(); - - const SfxPrinter *pPrinter = pViewFrm->GetViewShell()->GetPrinter(sal_True); + // 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 >(); - // Printer Eigenschaften uebertragen uno::Sequence< beans::PropertyValue > aPrinter(8); aPrinter.getArray()[7].Name = DEFINE_CONST_UNICODE( "CanSetPaperSize" ); diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 842f48332a..6663944c38 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -74,6 +74,7 @@ #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> @@ -2729,6 +2730,24 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL 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 @@ -2807,10 +2826,15 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL 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 ) ); } } @@ -2820,6 +2844,10 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL 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 ) ); diff --git a/sfx2/source/doc/syspath.cxx b/sfx2/source/doc/syspath.cxx new file mode 100644 index 0000000000..f12f5abf46 --- /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 0000000000..cc1a1ef2ed --- /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 100644 index 0000000000..51dc9d8d66 --- /dev/null +++ b/sfx2/source/doc/syspathw32.cxx @@ -0,0 +1,83 @@ +/************************************************************************* +* +* 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. +* +************************************************************************/ + +#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, pFolder, nSize ); +#else + (void)pFolder; + (void)nSize; + return false; +#endif +} diff --git a/sfx2/source/inc/appdata.hxx b/sfx2/source/inc/appdata.hxx index 96aafcfbf7..eff70fb605 100644 --- a/sfx2/source/inc/appdata.hxx +++ b/sfx2/source/inc/appdata.hxx @@ -82,6 +82,9 @@ class SfxBasicManagerCreationListener; namespace sfx2 { namespace appl { class ImeStatusWindow; } } +typedef Link* LinkPtr; +SV_DECL_PTRARR(SfxInitLinkList, LinkPtr, 4, 4) + //========================================================================= // SfxAppData_Impl //========================================================================= diff --git a/sfx2/source/inc/helpid.hrc b/sfx2/source/inc/helpid.hrc index 618b61b54c..b1c39a2cef 100644..100755 --- a/sfx2/source/inc/helpid.hrc +++ b/sfx2/source/inc/helpid.hrc @@ -46,6 +46,7 @@ #define HID_DOCINFODESC (HID_SFX_START + 8) #define HID_DOCINFODOC (HID_SFX_START + 9) #define HID_DOCINFOUSER (HID_SFX_START + 10) +#define HID_DOCINFOSECURITY (HID_SFX_START + 11) #define HID_BOOKMARKPROPS (HID_SFX_START + 14) #define HID_BOOKGROUPPROPS (HID_SFX_START + 15) #define HID_BOOKFILEPROPS (HID_SFX_START + 16) @@ -330,7 +331,8 @@ #define HID_CONFIG_SAVE (HID_SFX_START + 310) #define HID_SEARCHDIALOG (HID_SFX_START + 311) - +#define HID_TASKPANE_WINDOW (HID_SFX_START + 312) +#define HID_TASKPANE_VIEW_MENU (HID_SFX_START + 313) #define HID_XMLSEC_WARNING_BROKENSIGNATURE (HID_SFX_START + 314) #define HID_XMLSEC_QUERY_LOSINGSIGNATURE (HID_SFX_START + 315) #define HID_XMLSEC_QUERY_SAVEBEFORESIGN (HID_SFX_START + 316) @@ -345,7 +347,15 @@ #define HID_CTRL_CUSTOMPROPS_YES_NO (HID_SFX_START + 326) #define HID_DLG_CUSTOMPROPS_DURATION (HID_SFX_START + 327) -#define ACT_SFX_HID_END HID_DLG_CUSTOMPROPS_DURATION +#define HID_SECURITYTAB_PASSWORD_TO_OPEN (HID_SFX_START + 328) +#define HID_SECURITYTAB_CONFIRM_PASSWORD_TO_OPEN (HID_SFX_START + 329) +#define HID_SECURITYTAB_PASSWORD_TO_MODIFY (HID_SFX_START + 330) +#define HID_SECURITYTAB_CONFIRM_PASSWORD_TO_MODIFY (HID_SFX_START + 331) +#define HID_SECURITYTAB_OPEN_FILE_READONLY (HID_SFX_START + 332) +#define HID_SECURITYTAB_RECORD_CHANGES (HID_SFX_START + 333) +#define HID_SECURITYTAB_PROTECTION (HID_SFX_START + 334) + +#define ACT_SFX_HID_END HID_SECURITYTAB_PROTECTION // "Uberlaufpr"ufung -------------------------------------------------------- diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx index e0220316f7..c31a671f90 100644 --- a/sfx2/source/inc/objshimp.hxx +++ b/sfx2/source/inc/objshimp.hxx @@ -149,6 +149,10 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess 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(); diff --git a/sfx2/source/inc/sfxlocal.hrc b/sfx2/source/inc/sfxlocal.hrc index b1bd94dce0..5ce33ed036 100644 --- a/sfx2/source/inc/sfxlocal.hrc +++ b/sfx2/source/inc/sfxlocal.hrc @@ -44,6 +44,10 @@ #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 -------------------------------------------------------------- @@ -55,13 +59,17 @@ #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_IMG_PROPERTY_REMOVE (RID_SFX_SFXLOCAL_START + 8) -#define SFX_IMG_PROPERTY_REMOVE_HC (RID_SFX_SFXLOCAL_START + 9) #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/workwin.hxx b/sfx2/source/inc/workwin.hxx index 65aa99d822..9e652cfef9 100644 --- a/sfx2/source/inc/workwin.hxx +++ b/sfx2/source/inc/workwin.hxx @@ -365,6 +365,7 @@ public: 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 ); diff --git a/sfx2/source/menu/makefile.mk b/sfx2/source/menu/makefile.mk index d3b209fc4a..8b55bd0840 100644 --- a/sfx2/source/menu/makefile.mk +++ b/sfx2/source/menu/makefile.mk @@ -43,10 +43,11 @@ SRS1NAME=$(TARGET) SRC1FILES = menu.src SLOFILES = \ + $(SLO)$/mnuitem.obj \ $(SLO)$/mnumgr.obj \ - $(SLO)$/virtmenu.obj \ $(SLO)$/objmnctl.obj \ - $(SLO)$/mnuitem.obj + $(SLO)$/thessubmenu.obj \ + $(SLO)$/virtmenu.obj # --- Tagets ------------------------------------------------------- diff --git a/sfx2/source/menu/menu.hrc b/sfx2/source/menu/menu.hrc index 71f5b60507..3b89f474c3 100644 --- a/sfx2/source/menu/menu.hrc +++ b/sfx2/source/menu/menu.hrc @@ -64,6 +64,10 @@ #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 index a84198917d..cf13af67c3 100644 --- a/sfx2/source/menu/menu.src +++ b/sfx2/source/menu/menu.src @@ -72,6 +72,21 @@ 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/mnumgr.cxx b/sfx2/source/menu/mnumgr.cxx index 559c71b86b..f987bf9908 100644 --- a/sfx2/source/menu/mnumgr.cxx +++ b/sfx2/source/menu/mnumgr.cxx @@ -27,8 +27,10 @@ // 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 @@ -50,9 +52,14 @@ #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 <sfx2/mnumgr.hxx> @@ -76,10 +83,15 @@ #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; //========================================================================= @@ -166,6 +178,101 @@ void InsertVerbs_Impl( SfxBindings* pBindings, const com::sun::star::uno::Sequen } +//-------------------------------------------------------------------- + + +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( GetThesaurusReplaceText_Impl( 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; +} + //-------------------------------------------------------------------- @@ -305,7 +412,9 @@ void SfxPopupMenuManager::RemoveDisabledEntries() USHORT SfxPopupMenuManager::Execute( const Point& rPos, Window* pWindow ) { DBG_MEMTEST(); - return ( (PopupMenu*) GetMenu()->GetSVMenu() )->Execute( pWindow, rPos ); + USHORT nVal = ( (PopupMenu*) GetMenu()->GetSVMenu() )->Execute( pWindow, rPos ); + delete pStaticThesSubMenu; pStaticThesSubMenu = NULL; + return nVal; } //-------------------------------------------------------------------- @@ -429,6 +538,10 @@ SfxPopupMenuManager* SfxPopupMenuManager::Popup( const ResId& rResId, SfxViewFra break; } + PopupMenu* pThesSubMenu = InsertThesaurusSubmenu_Impl( &pFrame->GetBindings(), pSVMenu ); + // #i107205# (see comment in header file) + pStaticThesSubMenu = pThesSubMenu; + if ( n == nCount ) { PopupMenu aPop( SfxResId( MN_CLIPBOARDFUNCS ) ); @@ -461,6 +574,7 @@ SfxPopupMenuManager* SfxPopupMenuManager::Popup( const ResId& rResId, SfxViewFra aMgr->RemoveDisabledEntries(); return aMgr; } + return 0; } @@ -475,6 +589,8 @@ void SfxPopupMenuManager::ExecutePopup( const ResId& rResId, SfxViewFrame* pFram break; } + PopupMenu* pThesSubMenu = InsertThesaurusSubmenu_Impl( &pFrame->GetBindings(), pSVMenu ); + if ( n == nCount ) { PopupMenu aPop( SfxResId( MN_CLIPBOARDFUNCS ) ); @@ -507,6 +623,8 @@ void SfxPopupMenuManager::ExecutePopup( const ResId& rResId, SfxViewFrame* pFram aPop.RemoveDisabledEntries(); aPop.Execute( rPoint, pWindow ); } + + delete pThesSubMenu; } Menu* SfxPopupMenuManager::GetSVMenu() diff --git a/sfx2/source/menu/thessubmenu.cxx b/sfx2/source/menu/thessubmenu.cxx new file mode 100644 index 0000000000..a47e1b18a4 --- /dev/null +++ b/sfx2/source/menu/thessubmenu.cxx @@ -0,0 +1,274 @@ +/************************************************************************* + * + * 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); + +//////////////////////////////////////////////////////////// + +String GetThesaurusReplaceText_Impl( const ::rtl::OUString &rText ) +{ + // The strings returned by the thesaurus sometimes have some + // explanation text put in between '(' and ')' or a trailing '*'. + // These parts should not be put in the ReplaceEdit Text that may get + // inserted into the document. Thus we strip them from the text. + + String aText( rText ); + + xub_StrLen nPos = aText.Search( sal_Unicode('(') ); + while (STRING_NOTFOUND != nPos) + { + xub_StrLen nEnd = aText.Search( sal_Unicode(')'), nPos ); + if (STRING_NOTFOUND != nEnd) + aText.Erase( nPos, nEnd-nPos+1 ); + else + break; + nPos = aText.Search( sal_Unicode('(') ); + } + + nPos = aText.Search( sal_Unicode('*') ); + if (STRING_NOTFOUND != nPos) + aText.Erase( nPos ); + + // remove any possible remaining ' ' that may confuse the thesaurus + // when it gets called with the text + aText.EraseLeadingAndTrailingChars( sal_Unicode(' ') ); + + return aText; +} + +//////////////////////////////////////////////////////////// + + +/* + 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 0000000000..13438a917a --- /dev/null +++ b/sfx2/source/menu/thessubmenu.hxx @@ -0,0 +1,107 @@ +/************************************************************************* + * + * 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; + +//////////////////////////////////////////////////////////// + +String GetThesaurusReplaceText_Impl( const ::rtl::OUString &rText ); + +//////////////////////////////////////////////////////////// + +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/view/impviewframe.hxx b/sfx2/source/view/impviewframe.hxx index 6d5326f887..97db7ed27d 100644 --- a/sfx2/source/view/impviewframe.hxx +++ b/sfx2/source/view/impviewframe.hxx @@ -31,6 +31,8 @@ #include <svtools/asynclink.hxx> #include <vcl/window.hxx> +#include <boost/optional.hpp> + struct SfxViewFrame_Impl { SvBorder aBorder; @@ -56,6 +58,8 @@ struct SfxViewFrame_Impl sal_Bool bWindowWasEnabled:1; sal_Bool bActive; String aFactoryName; + ::boost::optional< bool > + aHasToolPanels; SfxViewFrame_Impl( SfxFrame& i_rFrame ) : rFrame( i_rFrame ) diff --git a/sfx2/source/view/ipclient.cxx b/sfx2/source/view/ipclient.cxx index eb41088cd1..ff1d963ab5 100644 --- a/sfx2/source/view/ipclient.cxx +++ b/sfx2/source/view/ipclient.cxx @@ -131,6 +131,8 @@ public: , m_bResizeNoScale( sal_False ) {} + ~SfxInPlaceClient_Impl(); + void SizeHasChanged(); DECL_LINK (TimerHdl, Timer*); uno::Reference < frame::XFrame > GetFrame() const; @@ -168,6 +170,10 @@ public: 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*/, @@ -645,6 +651,7 @@ SfxInPlaceClient::SfxInPlaceClient( SfxViewShell* pViewShell, Window *pDraw, sal 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); @@ -668,6 +675,7 @@ SfxInPlaceClient::~SfxInPlaceClient() // 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; diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index de37f031b4..b02f775fce 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -40,6 +40,7 @@ #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> @@ -76,6 +77,8 @@ #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> @@ -87,9 +90,11 @@ #include <comphelper/storagehelper.hxx> #include <svtools/asynclink.hxx> #include <svl/sharecontrolfile.hxx> -#include <svl/svtools.hrc> +#include <svtools/svtools.hrc> #include <svtools/svtdata.hxx> +#include <boost/optional.hpp> + using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::ucb; @@ -104,6 +109,7 @@ 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" @@ -165,6 +171,69 @@ 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; @@ -303,10 +372,11 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) 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() ) { - SfxMedium* pMed = pSh->GetMedium(); SfxApplication* pApp = SFX_APP(); SfxAllItemSet aSet( pApp->GetPool() ); aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetURLObject().GetMainURL(INetURLObject::NO_DECODE) ) ); @@ -338,17 +408,38 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) // Speichern und Readonly Reloaden if( pSh->IsModified() ) { - if ( !pSh->PrepareClose() ) + 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; } - else bNeedsReload = sal_True; } 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 ); @@ -368,130 +459,113 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) } // doing - if( pSh ) + + 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 ) { - SfxMedium* pMed = pSh->GetMedium(); - 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 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() ) { - 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; - } + // 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->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 ); + 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 ) ) ); + // 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 ( !pMed->GetErrorCode() ) + bOK = sal_True; + } - if( !bOK ) + if( !bOK ) + { + ErrCode nErr = pMed->GetErrorCode(); + if ( pVersionItem ) + nErr = ERRCODE_IO_ACCESSDENIED; + else { - 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 ); - } + 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 ); + // r/o-Doc kann nicht in Editmode geschaltet werden? + rReq.Done( sal_False ); - if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() ) + 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() ) { - // 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() ) { - 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; + 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 ); } - 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; + GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet ); + return; + } + else + nErr = 0; } - } - /* - if ( !bReload ) - { - // Es soll nicht reloaded werden - SfxErrorContext aEc( ERRCODE_SFX_NODOCRELOAD ); - ErrorHandler::HandleError( ERRCODE_SFX_NODOCRELOAD ); + ErrorHandler::HandleError( nErr ); rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) ); return; } - */ - // Ansonsten ( lokal und arbeiten auf Kopie ) muss gereloaded - // werden. + 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) ); @@ -671,6 +745,10 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) } 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 @@ -726,6 +804,12 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) } else { + if ( xNewObj->GetModifyPasswordHash() && xNewObj->GetModifyPasswordHash() != xOldObj->GetModifyPasswordHash() ) + { + xNewObj->SetModifyPasswordEntered( sal_False ); + xNewObj->SetReadOnly(); + } + if ( xNewObj->IsDocShared() ) { // the file is shared but the closing can change the sharing control file @@ -738,10 +822,7 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) TransformItems( SID_OPENDOC, *xNewObj->GetMedium()->GetItemSet(), aLoadArgs ); UpdateDocument_Impl(); - } - if ( xNewObj.Is() ) - { try { while ( !aViewFrames.empty() ) @@ -934,7 +1015,7 @@ void SfxViewFrame::StateHistory_Impl( SfxItemSet &rSet ) if ( pShUndoMgr && pShUndoMgr->GetUndoActionCount() ) { String aTmp( SvtResId( STR_UNDO ) ); - aTmp += pShUndoMgr->GetUndoActionComment(0); + aTmp+= pShUndoMgr->GetUndoActionComment(0); rSet.Put( SfxStringItem( SID_UNDO, aTmp ) ); } else @@ -1506,7 +1587,7 @@ void SfxViewFrame::KillDispatcher_Impl() //------------------------------------------------------------------------ SfxViewFrame* SfxViewFrame::Current() { - return SfxApplication::Is_Impl() ? SFX_APP()->Get_Impl()->pViewFrame : NULL; + return SfxApplication::Get() ? SFX_APP()->Get_Impl()->pViewFrame : NULL; } //-------------------------------------------------------------------- @@ -2058,9 +2139,7 @@ SfxViewShell* SfxViewFrame::LoadViewIntoFrame_Impl( const SfxObjectShell& i_rDoc else aTransformLoadArgs.remove( "Hidden" ); - ::rtl::OUString sURL( xDocument->getURL() ); - if ( !sURL.getLength() ) - sURL = i_rDoc.GetFactory().GetFactoryURL(); + ::rtl::OUString sURL( RTL_CONSTASCII_USTRINGPARAM( "private:object" ) ); Reference< XComponentLoader > xLoader( i_rFrame, UNO_QUERY_THROW ); xLoader->loadComponentFromURL( sURL, ::rtl::OUString::createFromAscii( "_self" ), 0, @@ -3290,6 +3369,22 @@ void SfxViewFrame::ChildWindowState( SfxItemSet& rState ) 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 @@ -3377,3 +3472,37 @@ 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/viewimp.hxx b/sfx2/source/view/viewimp.hxx index 1622cf5443..1f7607ac0b 100644 --- a/sfx2/source/view/viewimp.hxx +++ b/sfx2/source/view/viewimp.hxx @@ -30,20 +30,16 @@ // include --------------------------------------------------------------- -#ifndef __SBX_SBXOBJ_HXX #include <basic/sbxobj.hxx> -#endif #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 --------------------------------------------------------------- @@ -54,24 +50,6 @@ class SfxBaseController; typedef SfxShell* SfxShellPtr_Impl; SV_DECL_PTRARR( SfxShellArr_Impl, SfxShellPtr_Impl, 4, 4 ) -// struct SfxViewShell_Impl ---------------------------------------------- -#if 0 -class SfxAsyncPrintExec_Impl : public SfxListener -{ - SfxViewShell* pView; - ::std::queue < SfxRequest*> aReqs; - - virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); - -public: - SfxAsyncPrintExec_Impl( SfxViewShell* pShell) - : pView( pShell ) - {} - - void AddRequest( SfxRequest& rReq ); -}; -#endif - class SfxClipboardChangeListener; struct SfxViewShell_Impl @@ -95,10 +73,10 @@ struct SfxViewShell_Impl USHORT nFamily; SfxBaseController* pController; ::svt::AcceleratorExecute* pAccExec; -// SfxAsyncPrintExec_Impl* pPrinterCommandQueue; com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aPrintOpts; ::rtl::Reference< SfxClipboardChangeListener > xClipboardListener; - + vcl::PrinterController* pPrinterController; + SfxViewShell_Impl(); }; diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx index 1f47a36dcb..1a38fa34fc 100644 --- a/sfx2/source/view/viewprn.cxx +++ b/sfx2/source/view/viewprn.cxx @@ -129,28 +129,6 @@ SfxPrinterController::SfxPrinterController( const Any& i_rComplete, StartListening( *mpViewShell ); mpObjectShell = mpViewShell->GetObjectShell(); StartListening( *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() ) ); } // initialize extra ui options @@ -283,6 +261,29 @@ 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 ) ); @@ -329,6 +330,9 @@ void SfxPrinterController::jobFinished( com::sun::star::view::PrintableState nSt if ( m_bNeedsChange ) mpObjectShell->EnableSetModified( m_bOrigStatus ); + + if ( mpViewShell ) + mpViewShell->pImp->pPrinterController = 0; } } @@ -639,6 +643,8 @@ void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rPro this, rProps ) ); + pImp->pPrinterController = pController.get(); + SfxObjectShell *pObjShell = GetObjectShell(); pController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "JobName" ) ), makeAny( rtl::OUString( pObjShell->GetTitle(0) ) ) ); @@ -653,6 +659,11 @@ void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rPro Printer::PrintJob( pController, aJobSetup ); } +Printer* SfxViewShell::GetActivePrinter() const +{ + return pImp->pPrinterController ? pImp->pPrinterController->getPrinter().get() : 0; +} + void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq ) { // USHORT nCopies=1; |