1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp> 32*cdf0e10cSrcweir #include <unotools/historyoptions.hxx> 33*cdf0e10cSrcweir #include <unotools/useroptions.hxx> 34*cdf0e10cSrcweir #include <tools/urlobj.hxx> 35*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx> 36*cdf0e10cSrcweir #include <svl/inethist.hxx> 37*cdf0e10cSrcweir #include <svl/stritem.hxx> 38*cdf0e10cSrcweir #include <svl/eitem.hxx> 39*cdf0e10cSrcweir #include <osl/file.hxx> 40*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx> 41*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #include <sfx2/app.hxx> 46*cdf0e10cSrcweir #include "sfxpicklist.hxx" 47*cdf0e10cSrcweir #include <sfx2/sfxuno.hxx> 48*cdf0e10cSrcweir #include "sfxtypes.hxx" 49*cdf0e10cSrcweir #include <sfx2/request.hxx> 50*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc> 51*cdf0e10cSrcweir #include <sfx2/sfx.hrc> 52*cdf0e10cSrcweir #include <sfx2/event.hxx> 53*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 54*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 55*cdf0e10cSrcweir #include "referers.hxx" 56*cdf0e10cSrcweir #include <sfx2/docfile.hxx> 57*cdf0e10cSrcweir #include "objshimp.hxx" 58*cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #include <algorithm> 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 65*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 66*cdf0e10cSrcweir using namespace ::com::sun::star::util; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir osl::Mutex* SfxPickList::pMutex = 0; 71*cdf0e10cSrcweir SfxPickList* SfxPickList::pUniqueInstance = 0; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir class StringLength : public ::cppu::WeakImplHelper1< XStringWidth > 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir public: 78*cdf0e10cSrcweir StringLength() {} 79*cdf0e10cSrcweir virtual ~StringLength() {} 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // XStringWidth 82*cdf0e10cSrcweir sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString ) 83*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir return aString.getLength(); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir }; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir osl::Mutex* SfxPickList::GetOrCreateMutex() 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir if ( !pMutex ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 96*cdf0e10cSrcweir if ( !pMutex ) 97*cdf0e10cSrcweir pMutex = new osl::Mutex; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir return pMutex; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir void SfxPickList::CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const String& aURLString, sal_uInt32 nNo ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir String aPickEntry; 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir if ( nNo < 9 ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir aPickEntry += '~'; 110*cdf0e10cSrcweir aPickEntry += String::CreateFromInt32( nNo + 1 ); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir else if ( nNo == 9 ) 113*cdf0e10cSrcweir aPickEntry += DEFINE_CONST_UNICODE("1~0"); 114*cdf0e10cSrcweir else 115*cdf0e10cSrcweir aPickEntry += String::CreateFromInt32( nNo + 1 ); 116*cdf0e10cSrcweir aPickEntry += DEFINE_CONST_UNICODE(": "); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir INetURLObject aURL( aURLString ); 119*cdf0e10cSrcweir rtl::OUString aTipHelpText; 120*cdf0e10cSrcweir rtl::OUString aAccessibleName( aPickEntry ); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir if ( aURL.GetProtocol() == INET_PROT_FILE ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir // Do handle file URL differently => convert it to a system 125*cdf0e10cSrcweir // path and abbreviate it with a special function: 126*cdf0e10cSrcweir String aFileSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) ); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // ::utl::LocalFileHelper::ConvertURLToPhysicalName( aURLString, aPhysicalName ); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir ::rtl::OUString aSystemPath( aFileSystemPath ); 131*cdf0e10cSrcweir ::rtl::OUString aCompactedSystemPath; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir aTipHelpText = aSystemPath; 134*cdf0e10cSrcweir aAccessibleName += aSystemPath; 135*cdf0e10cSrcweir oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, NULL ); 136*cdf0e10cSrcweir if ( !nError ) 137*cdf0e10cSrcweir aPickEntry += String( aCompactedSystemPath ); 138*cdf0e10cSrcweir else 139*cdf0e10cSrcweir aPickEntry += aFileSystemPath; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir if ( aPickEntry.Len() > 50 ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir aPickEntry.Erase( 47 ); 144*cdf0e10cSrcweir aPickEntry += DEFINE_CONST_UNICODE("..."); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir else 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir // Use INetURLObject to abbreviate all other URLs 150*cdf0e10cSrcweir String aShortURL; 151*cdf0e10cSrcweir aShortURL = aURL.getAbbreviated( m_xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS ); 152*cdf0e10cSrcweir aPickEntry += aShortURL; 153*cdf0e10cSrcweir aTipHelpText = aURLString; 154*cdf0e10cSrcweir aAccessibleName += aURLString; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // Set menu item text, tip help and accessible name 158*cdf0e10cSrcweir pMenu->SetItemText( nItemId, aPickEntry ); 159*cdf0e10cSrcweir pMenu->SetTipHelpText( nItemId, aTipHelpText ); 160*cdf0e10cSrcweir pMenu->SetAccessibleName( nItemId, aAccessibleName ); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir void SfxPickList::RemovePickListEntries() 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir ::osl::MutexGuard aGuard( GetOrCreateMutex() ); 166*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < m_aPicklistVector.size(); i++ ) 167*cdf0e10cSrcweir delete m_aPicklistVector[i]; 168*cdf0e10cSrcweir m_aPicklistVector.clear(); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir SfxPickList::PickListEntry* SfxPickList::GetPickListEntry( sal_uInt32 nIndex ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir OSL_ASSERT( m_aPicklistVector.size() > nIndex ); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir if ( nIndex < m_aPicklistVector.size() ) 176*cdf0e10cSrcweir return m_aPicklistVector[ nIndex ]; 177*cdf0e10cSrcweir else 178*cdf0e10cSrcweir return 0; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir SfxPickList* SfxPickList::GetOrCreate( const sal_uInt32 nMenuSize ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir if ( !pUniqueInstance ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir ::osl::MutexGuard aGuard( GetOrCreateMutex() ); 186*cdf0e10cSrcweir if ( !pUniqueInstance ) 187*cdf0e10cSrcweir pUniqueInstance = new SfxPickList( nMenuSize ); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir return pUniqueInstance; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir SfxPickList* SfxPickList::Get() 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir ::osl::MutexGuard aGuard( GetOrCreateMutex() ); 196*cdf0e10cSrcweir return pUniqueInstance; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir void SfxPickList::Delete() 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir ::osl::MutexGuard aGuard( GetOrCreateMutex() ); 202*cdf0e10cSrcweir DELETEZ( pUniqueInstance ); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir SfxPickList::SfxPickList( sal_uInt32 nAllowedMenuSize ) : 206*cdf0e10cSrcweir m_nAllowedMenuSize( nAllowedMenuSize ) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir m_xStringLength = new StringLength; 209*cdf0e10cSrcweir m_nAllowedMenuSize = ::std::min( m_nAllowedMenuSize, (sal_uInt32)PICKLIST_MAXSIZE ); 210*cdf0e10cSrcweir StartListening( *SFX_APP() ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir SfxPickList::~SfxPickList() 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir RemovePickListEntries(); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir void SfxPickList::CreatePickListEntries() 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir RemovePickListEntries(); 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir // Einlesen der Pickliste 223*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > seqPicklist = SvtHistoryOptions().GetList( ePICKLIST ); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir sal_uInt32 nCount = seqPicklist.getLength(); 226*cdf0e10cSrcweir sal_uInt32 nEntries = ::std::min( m_nAllowedMenuSize, nCount ); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir for( sal_uInt32 nItem=0; nItem < nEntries; ++nItem ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir Sequence< PropertyValue > seqPropertySet = seqPicklist[ nItem ]; 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir INetURLObject aURL; 233*cdf0e10cSrcweir ::rtl::OUString sURL; 234*cdf0e10cSrcweir ::rtl::OUString sFilter; 235*cdf0e10cSrcweir ::rtl::OUString sTitle; 236*cdf0e10cSrcweir ::rtl::OUString sPassword; 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir sal_uInt32 nPropertyCount = seqPropertySet.getLength(); 239*cdf0e10cSrcweir for( sal_uInt32 nProperty=0; nProperty<nPropertyCount; ++nProperty ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir if( seqPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_URL ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir seqPropertySet[nProperty].Value >>= sURL; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir else if( seqPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_FILTER ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir seqPropertySet[nProperty].Value >>= sFilter; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir else if( seqPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_TITLE ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir seqPropertySet[nProperty].Value >>= sTitle; 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir else if( seqPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_PASSWORD ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir seqPropertySet[nProperty].Value >>= sPassword; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir aURL.SetSmartURL( sURL ); 260*cdf0e10cSrcweir aURL.SetPass( SfxStringDecode( sPassword ) ); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir PickListEntry *pPick = new PickListEntry( aURL.GetMainURL( INetURLObject::NO_DECODE ), sFilter, sTitle ); 263*cdf0e10cSrcweir m_aPicklistVector.push_back( pPick ); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir void SfxPickList::CreateMenuEntries( Menu* pMenu ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir static sal_Bool bPickListMenuInitializing = sal_False; 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir ::osl::MutexGuard aGuard( GetOrCreateMutex() ); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir if ( bPickListMenuInitializing ) // method is not reentrant! 274*cdf0e10cSrcweir return; 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir bPickListMenuInitializing = sal_True; 277*cdf0e10cSrcweir CreatePickListEntries(); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir for ( sal_uInt16 nId = START_ITEMID_PICKLIST; nId <= END_ITEMID_PICKLIST; ++nId ) 280*cdf0e10cSrcweir pMenu->RemoveItem( pMenu->GetItemPos( nId ) ); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR ) 283*cdf0e10cSrcweir pMenu->RemoveItem( pMenu->GetItemCount()-1 ); 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir if ( m_aPicklistVector.size() > 0 && 286*cdf0e10cSrcweir pMenu->GetItemType( pMenu->GetItemCount()-1 ) 287*cdf0e10cSrcweir != MENUITEM_SEPARATOR && m_nAllowedMenuSize ) 288*cdf0e10cSrcweir pMenu->InsertSeparator(); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir rtl::OUString aEmptyString; 291*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < m_aPicklistVector.size(); i++ ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir PickListEntry* pEntry = GetPickListEntry( i ); 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir pMenu->InsertItem( (sal_uInt16)(START_ITEMID_PICKLIST + i), aEmptyString ); 296*cdf0e10cSrcweir CreatePicklistMenuTitle( pMenu, (sal_uInt16)(START_ITEMID_PICKLIST + i), pEntry->aName, i ); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir bPickListMenuInitializing = sal_False; 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir void SfxPickList::ExecuteEntry( sal_uInt32 nIndex ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( GetOrCreateMutex() ); 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir PickListEntry *pPick = SfxPickList::Get()->GetPickListEntry( nIndex ); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir if ( pPick ) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir SfxRequest aReq( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, SFX_APP()->GetPool() ); 311*cdf0e10cSrcweir aReq.AppendItem( SfxStringItem( SID_FILE_NAME, pPick->aName )); 312*cdf0e10cSrcweir aReq.AppendItem( SfxStringItem( SID_REFERER, DEFINE_CONST_UNICODE( SFX_REFERER_USER ) ) ); 313*cdf0e10cSrcweir aReq.AppendItem( SfxStringItem( SID_TARGETNAME, DEFINE_CONST_UNICODE("_default") ) ); 314*cdf0e10cSrcweir String aFilter( pPick->aFilter ); 315*cdf0e10cSrcweir aGuard.clear(); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir sal_uInt16 nPos=aFilter.Search('|'); 318*cdf0e10cSrcweir if( nPos != STRING_NOTFOUND ) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir String aOptions(aFilter.Copy( nPos ).GetBuffer()+1); 321*cdf0e10cSrcweir aFilter.Erase( nPos ); 322*cdf0e10cSrcweir aReq.AppendItem( SfxStringItem(SID_FILE_FILTEROPTIONS, aOptions)); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir aReq.AppendItem(SfxStringItem( SID_FILTER_NAME, aFilter )); 326*cdf0e10cSrcweir aReq.AppendItem( SfxBoolItem( SID_TEMPLATE, sal_False ) ); 327*cdf0e10cSrcweir SFX_APP()->ExecuteSlot( aReq ); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir void SfxPickList::ExecuteMenuEntry( sal_uInt16 nId ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir ExecuteEntry( (sal_uInt32)( nId - START_ITEMID_PICKLIST ) ); 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir String SfxPickList::GetMenuEntryTitle( sal_uInt32 nIndex ) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir PickListEntry *pPick = SfxPickList::Get()->GetPickListEntry( nIndex ); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir if ( pPick ) 341*cdf0e10cSrcweir return pPick->aTitle; 342*cdf0e10cSrcweir else 343*cdf0e10cSrcweir return String(); 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir void SfxPickList::Notify( SfxBroadcaster&, const SfxHint& rHint ) 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir if ( rHint.IsA( TYPE( SfxStringHint ))) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir SfxStringHint* pStringHint = (SfxStringHint*) &rHint; 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir if ( pStringHint->GetId() == SID_OPENURL ) 353*cdf0e10cSrcweir INetURLHistory::GetOrCreate()->PutUrl( INetURLObject( pStringHint->GetObject() )); 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir if ( rHint.IsA( TYPE( SfxEventHint ))) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir SfxEventHint* pEventHint = PTR_CAST(SfxEventHint,&rHint); 359*cdf0e10cSrcweir // nur ObjectShell-bezogene Events mit Medium interessieren 360*cdf0e10cSrcweir SfxObjectShell* pDocSh = pEventHint->GetObjShell(); 361*cdf0e10cSrcweir if( !pDocSh ) 362*cdf0e10cSrcweir return; 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir switch ( pEventHint->GetEventId() ) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir case SFX_EVENT_CREATEDOC: 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir sal_Bool bAllowModif = pDocSh->IsEnableSetModified(); 369*cdf0e10cSrcweir if ( bAllowModif ) 370*cdf0e10cSrcweir pDocSh->EnableSetModified( sal_False ); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir using namespace ::com::sun::star; 373*cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xDocProps( 374*cdf0e10cSrcweir pDocSh->getDocProperties()); 375*cdf0e10cSrcweir if (xDocProps.is()) { 376*cdf0e10cSrcweir xDocProps->setAuthor( SvtUserOptions().GetFullName() ); 377*cdf0e10cSrcweir ::DateTime now; 378*cdf0e10cSrcweir xDocProps->setCreationDate( util::DateTime( 379*cdf0e10cSrcweir now.Get100Sec(), now.GetSec(), now.GetMin(), 380*cdf0e10cSrcweir now.GetHour(), now.GetDay(), now.GetMonth(), 381*cdf0e10cSrcweir now.GetYear() ) ); 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir if ( bAllowModif ) 385*cdf0e10cSrcweir pDocSh->EnableSetModified( bAllowModif ); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir break; 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir case SFX_EVENT_OPENDOC: 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir SfxMedium *pMed = pDocSh->GetMedium(); 392*cdf0e10cSrcweir if( !pMed ) 393*cdf0e10cSrcweir return; 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir // unbenannt-Docs und embedded-Docs nicht in History 396*cdf0e10cSrcweir if ( !pDocSh->HasName() || 397*cdf0e10cSrcweir SFX_CREATE_MODE_STANDARD != pDocSh->GetCreateMode() ) 398*cdf0e10cSrcweir return; 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir // Hilfe nicht in History 401*cdf0e10cSrcweir INetURLObject aURL( pDocSh->IsDocShared() ? pDocSh->GetSharedFileURL() : ::rtl::OUString( pMed->GetOrigURL() ) ); 402*cdf0e10cSrcweir if ( aURL.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP ) 403*cdf0e10cSrcweir return; 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir ::rtl::OUString aTitle = pDocSh->GetTitle(SFX_TITLE_PICKLIST); 406*cdf0e10cSrcweir ::rtl::OUString aFilter; 407*cdf0e10cSrcweir const SfxFilter* pFilter = pMed->GetOrigFilter(); 408*cdf0e10cSrcweir if ( pFilter ) 409*cdf0e10cSrcweir aFilter = pFilter->GetFilterName(); 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir // add to svtool history options 412*cdf0e10cSrcweir SvtHistoryOptions().AppendItem( eHISTORY, 413*cdf0e10cSrcweir aURL.GetURLNoPass( INetURLObject::NO_DECODE ), 414*cdf0e10cSrcweir aFilter, 415*cdf0e10cSrcweir aTitle, 416*cdf0e10cSrcweir SfxStringEncode( aURL.GetPass() ) ); 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir break; 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir case SFX_EVENT_CLOSEDOC: 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir SfxMedium *pMed = pDocSh->GetMedium(); 423*cdf0e10cSrcweir if( !pMed ) 424*cdf0e10cSrcweir return; 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir // unbenannt-Docs und embedded-Docs nicht in Pickliste 427*cdf0e10cSrcweir if ( !pDocSh->HasName() || 428*cdf0e10cSrcweir SFX_CREATE_MODE_STANDARD != pDocSh->GetCreateMode() ) 429*cdf0e10cSrcweir return; 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir // Hilfe nicht in History 432*cdf0e10cSrcweir INetURLObject aURL( pDocSh->IsDocShared() ? pDocSh->GetSharedFileURL() : ::rtl::OUString( pMed->GetOrigURL() ) ); 433*cdf0e10cSrcweir if ( aURL.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP ) 434*cdf0e10cSrcweir return; 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir // only add r/w document into picklist 437*cdf0e10cSrcweir if ( pDocSh->IsReadOnly() || !pMed->IsUpdatePickList() ) 438*cdf0e10cSrcweir return; 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir // add no document that forbids this (for example Message-Body) 441*cdf0e10cSrcweir SFX_ITEMSET_ARG( pMed->GetItemSet(), pPicklistItem, SfxBoolItem, SID_PICKLIST, sal_False ); 442*cdf0e10cSrcweir if ( 443*cdf0e10cSrcweir (pPicklistItem && !pPicklistItem->GetValue()) || 444*cdf0e10cSrcweir (!(pDocSh->Get_Impl()->bWaitingForPicklist) ) 445*cdf0e10cSrcweir ) 446*cdf0e10cSrcweir return; 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir // ignore hidden documents 449*cdf0e10cSrcweir if ( !SfxViewFrame::GetFirst( pDocSh, sal_True ) ) 450*cdf0e10cSrcweir return; 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir ::rtl::OUString aTitle = pDocSh->GetTitle(SFX_TITLE_PICKLIST); 453*cdf0e10cSrcweir ::rtl::OUString aFilter; 454*cdf0e10cSrcweir const SfxFilter* pFilter = pMed->GetOrigFilter(); 455*cdf0e10cSrcweir if ( pFilter ) 456*cdf0e10cSrcweir aFilter = pFilter->GetFilterName(); 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir // add to svtool history options 459*cdf0e10cSrcweir SvtHistoryOptions().AppendItem( ePICKLIST, 460*cdf0e10cSrcweir aURL.GetURLNoPass( INetURLObject::NO_DECODE ), 461*cdf0e10cSrcweir aFilter, 462*cdf0e10cSrcweir aTitle, 463*cdf0e10cSrcweir SfxStringEncode( aURL.GetPass() ) ); 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir pDocSh->Get_Impl()->bWaitingForPicklist = sal_False; 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir if ( aURL.GetProtocol() == INET_PROT_FILE ) 468*cdf0e10cSrcweir Application::AddToRecentDocumentList( aURL.GetURLNoPass( INetURLObject::NO_DECODE ), (pFilter) ? pFilter->GetMimeType() : String() ); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir break; 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir } 474