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