xref: /aoo42x/main/sfx2/source/dialog/versdlg.cxx (revision d119d52d)
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 #include <unotools/localedatawrapper.hxx>
27cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
28cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <svl/eitem.hxx>
31cdf0e10cSrcweir #include <svl/intitem.hxx>
32cdf0e10cSrcweir #include <svl/stritem.hxx>
33cdf0e10cSrcweir #include <svl/itemset.hxx>
34cdf0e10cSrcweir #include <unotools/useroptions.hxx>
35cdf0e10cSrcweir #include <vcl/msgbox.hxx>
36cdf0e10cSrcweir #include <vcl/svapp.hxx>
37cdf0e10cSrcweir #include <tools/datetime.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
40cdf0e10cSrcweir #include <svl/svstdarr.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include "versdlg.hrc"
43cdf0e10cSrcweir #include "versdlg.hxx"
44cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
45cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
46cdf0e10cSrcweir #include <sfx2/docfile.hxx>
47cdf0e10cSrcweir #include <sfx2/objsh.hxx>
48cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
49cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
50cdf0e10cSrcweir #include <sfx2/request.hxx>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir using namespace com::sun::star;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // **************************************************************************
57cdf0e10cSrcweir struct SfxVersionInfo
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	String					aName;
60cdf0e10cSrcweir 	String					aComment;
61cdf0e10cSrcweir 	String					aAuthor;
62cdf0e10cSrcweir 	DateTime				aCreationDate;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 							SfxVersionInfo();
SfxVersionInfoSfxVersionInfo65cdf0e10cSrcweir 							SfxVersionInfo( const SfxVersionInfo& rInfo )
66cdf0e10cSrcweir 							{ *this = rInfo; }
67cdf0e10cSrcweir 
operator =SfxVersionInfo68cdf0e10cSrcweir 	SfxVersionInfo& 		operator=( const SfxVersionInfo &rInfo )
69cdf0e10cSrcweir 							{
70cdf0e10cSrcweir 								aName = rInfo.aName;
71cdf0e10cSrcweir 								aComment = rInfo.aComment;
72cdf0e10cSrcweir 								aAuthor = rInfo.aAuthor;
73cdf0e10cSrcweir 								aCreationDate = rInfo.aCreationDate;
74cdf0e10cSrcweir 								return *this;
75cdf0e10cSrcweir 							}
76cdf0e10cSrcweir };
77cdf0e10cSrcweir DECLARE_LIST( _SfxVersionTable, SfxVersionInfo* )
78cdf0e10cSrcweir class SfxVersionTableDtor : public _SfxVersionTable
79cdf0e10cSrcweir {
80cdf0e10cSrcweir public:
SfxVersionTableDtor(const sal_uInt16 nInitSz=0,const sal_uInt16 nReSz=1)81cdf0e10cSrcweir 							SfxVersionTableDtor( const sal_uInt16 nInitSz=0, const sal_uInt16 nReSz=1 )
82cdf0e10cSrcweir 								: _SfxVersionTable( nInitSz, nReSz )
83cdf0e10cSrcweir 							{}
84cdf0e10cSrcweir 
SfxVersionTableDtor(const SfxVersionTableDtor & rCpy)85cdf0e10cSrcweir                             SfxVersionTableDtor( const SfxVersionTableDtor &rCpy ) :
86cdf0e10cSrcweir                                 _SfxVersionTable( rCpy )
87cdf0e10cSrcweir 							{ *this = rCpy; }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir                             SfxVersionTableDtor( const uno::Sequence < util::RevisionTag >& rInfo );
90cdf0e10cSrcweir 
~SfxVersionTableDtor()91cdf0e10cSrcweir 							~SfxVersionTableDtor()
92cdf0e10cSrcweir 							{ DelDtor(); }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	SfxVersionTableDtor& 	operator=( const SfxVersionTableDtor &rCpy );
95cdf0e10cSrcweir 	void 					DelDtor();
96cdf0e10cSrcweir 	SvStream&				Read( SvStream & );
97cdf0e10cSrcweir 	SvStream&				Write( SvStream & ) const;
98cdf0e10cSrcweir 	SvStringsDtor*			GetVersions() const;
99cdf0e10cSrcweir };
100cdf0e10cSrcweir 
SfxVersionTableDtor(const uno::Sequence<util::RevisionTag> & rInfo)101cdf0e10cSrcweir SfxVersionTableDtor::SfxVersionTableDtor( const uno::Sequence < util::RevisionTag >& rInfo )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     for ( sal_Int32 n=0; n<(sal_Int32)rInfo.getLength(); n++ )
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         SfxVersionInfo* pInfo = new SfxVersionInfo;
106cdf0e10cSrcweir         pInfo->aName = rInfo[n].Identifier;
107cdf0e10cSrcweir         pInfo->aComment = rInfo[n].Comment;
108cdf0e10cSrcweir         pInfo->aAuthor = rInfo[n].Author;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         Date aDate ( rInfo[n].TimeStamp.Day, rInfo[n].TimeStamp.Month, rInfo[n].TimeStamp.Year );
111cdf0e10cSrcweir         Time aTime ( rInfo[n].TimeStamp.Hours, rInfo[n].TimeStamp.Minutes, rInfo[n].TimeStamp.Seconds, rInfo[n].TimeStamp.HundredthSeconds );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         pInfo->aCreationDate = DateTime( aDate, aTime );
114cdf0e10cSrcweir         Insert( pInfo, Count() );
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
DelDtor()118cdf0e10cSrcweir void SfxVersionTableDtor::DelDtor()
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     SfxVersionInfo* pTmp = First();
121cdf0e10cSrcweir     while( pTmp )
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir         delete pTmp;
124cdf0e10cSrcweir         pTmp = Next();
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir     Clear();
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
operator =(const SfxVersionTableDtor & rTbl)129cdf0e10cSrcweir SfxVersionTableDtor& SfxVersionTableDtor::operator=( const SfxVersionTableDtor& rTbl )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir     DelDtor();
132cdf0e10cSrcweir     SfxVersionInfo* pTmp = ((SfxVersionTableDtor&)rTbl).First();
133cdf0e10cSrcweir     while( pTmp )
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         SfxVersionInfo *pNew = new SfxVersionInfo( *pTmp );
136cdf0e10cSrcweir         Insert( pNew, LIST_APPEND );
137cdf0e10cSrcweir         pTmp = ((SfxVersionTableDtor&)rTbl).Next();
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir     return *this;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir //----------------------------------------------------------------
143cdf0e10cSrcweir //----------------------------------------------------------------
144cdf0e10cSrcweir //----------------------------------------------------------------
SfxVersionInfo()145cdf0e10cSrcweir SfxVersionInfo::SfxVersionInfo()
146cdf0e10cSrcweir {
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
ConvertDateTime_Impl(const DateTime & rTime,const LocaleDataWrapper & rWrapper)149cdf0e10cSrcweir static String ConvertDateTime_Impl(const DateTime& rTime, const LocaleDataWrapper& rWrapper)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir 	 const String pDelim ( DEFINE_CONST_UNICODE( ", "));
152cdf0e10cSrcweir 	 String aStr(rWrapper.getDate(rTime));
153cdf0e10cSrcweir 	 aStr += pDelim;
154cdf0e10cSrcweir 	 aStr += rWrapper.getTime(rTime, sal_True, sal_False);
155cdf0e10cSrcweir 	 return aStr;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
GetVersions() const158cdf0e10cSrcweir SvStringsDtor* SfxVersionTableDtor::GetVersions() const
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     SvStringsDtor *pList = new SvStringsDtor;
161cdf0e10cSrcweir     SfxVersionInfo* pInfo = ((SfxVersionTableDtor*) this)->First();
162cdf0e10cSrcweir 	LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
163cdf0e10cSrcweir     while ( pInfo )
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         String *pString = new String( pInfo->aComment );
166cdf0e10cSrcweir         (*pString) += DEFINE_CONST_UNICODE( "; " );
167cdf0e10cSrcweir         (*pString) += ConvertDateTime_Impl( pInfo->aCreationDate, aLocaleWrapper );
168cdf0e10cSrcweir         pList->Insert( pString, pList->Count() );
169cdf0e10cSrcweir         pInfo = ((SfxVersionTableDtor*) this)->Next();
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     return pList;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir // Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert
176cdf0e10cSrcweir static long nTabs_Impl[] =
177cdf0e10cSrcweir {
178cdf0e10cSrcweir 	3, // Number of Tabs
179cdf0e10cSrcweir     0, 62, 124
180cdf0e10cSrcweir };
181cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKeyEvent)182cdf0e10cSrcweir void SfxVersionsTabListBox_Impl::KeyInput( const KeyEvent& rKeyEvent )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	const KeyCode& rCode = rKeyEvent.GetKeyCode();
185cdf0e10cSrcweir 	switch ( rCode.GetCode() )
186cdf0e10cSrcweir 	{
187cdf0e10cSrcweir 		case KEY_RETURN :
188cdf0e10cSrcweir 		case KEY_ESCAPE :
189cdf0e10cSrcweir 		case KEY_TAB :
190cdf0e10cSrcweir 			Window::GetParent()->KeyInput( rKeyEvent );
191cdf0e10cSrcweir 			break;
192cdf0e10cSrcweir 		default:
193cdf0e10cSrcweir 			SvTabListBox::KeyInput( rKeyEvent );
194cdf0e10cSrcweir 			break;
195cdf0e10cSrcweir 	}
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
SfxVersionsTabListBox_Impl(Window * pParent,const ResId & rResId)198cdf0e10cSrcweir SfxVersionsTabListBox_Impl::SfxVersionsTabListBox_Impl( Window* pParent, const ResId& rResId )
199cdf0e10cSrcweir 	: SvTabListBox( pParent, rResId )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
SfxVersionDialog(SfxViewFrame * pVwFrame,sal_Bool bIsSaveVersionOnClose)203cdf0e10cSrcweir SfxVersionDialog::SfxVersionDialog ( SfxViewFrame* pVwFrame, sal_Bool bIsSaveVersionOnClose )
204cdf0e10cSrcweir     : SfxModalDialog( NULL, SfxResId( DLG_VERSIONS ) )
205cdf0e10cSrcweir 	, aNewGroup( this, SfxResId( GB_NEWVERSIONS ) )
206cdf0e10cSrcweir 	, aSaveButton( this, SfxResId( PB_SAVE ) )
207cdf0e10cSrcweir 	, aSaveCheckBox( this, SfxResId( CB_SAVEONCLOSE ) )
208cdf0e10cSrcweir 	, aExistingGroup( this, SfxResId( GB_OLDVERSIONS ) )
209cdf0e10cSrcweir 	, aDateTimeText( this, SfxResId( FT_DATETIME ) )
210cdf0e10cSrcweir 	, aSavedByText( this, SfxResId( FT_SAVEDBY ) )
211cdf0e10cSrcweir 	, aCommentText( this, SfxResId( FT_COMMENTS ) )
212cdf0e10cSrcweir 	, aVersionBox( this, SfxResId( TLB_VERSIONS ) )
213cdf0e10cSrcweir 	, aCloseButton( this, SfxResId( PB_CLOSE ) )
214cdf0e10cSrcweir 	, aOpenButton( this, SfxResId( PB_OPEN ) )
215cdf0e10cSrcweir 	, aViewButton( this, SfxResId( PB_VIEW ) )
216cdf0e10cSrcweir 	, aDeleteButton( this, SfxResId( PB_DELETE ) )
217cdf0e10cSrcweir 	, aCompareButton( this, SfxResId( PB_COMPARE ) )
218cdf0e10cSrcweir 	, aHelpButton( this, SfxResId( PB_HELP ) )
219cdf0e10cSrcweir 	, pViewFrame( pVwFrame )
220cdf0e10cSrcweir     , mpTable( NULL )
221cdf0e10cSrcweir     , mpLocaleWrapper( NULL )
222cdf0e10cSrcweir 	, mbIsSaveVersionOnClose( bIsSaveVersionOnClose )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir 	FreeResource();
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     Link aClickLink = LINK( this, SfxVersionDialog, ButtonHdl_Impl );
227cdf0e10cSrcweir     aViewButton.SetClickHdl ( aClickLink );
228cdf0e10cSrcweir     aSaveButton.SetClickHdl ( aClickLink );
229cdf0e10cSrcweir     aDeleteButton.SetClickHdl ( aClickLink );
230cdf0e10cSrcweir     aCompareButton.SetClickHdl ( aClickLink );
231cdf0e10cSrcweir     aOpenButton.SetClickHdl ( aClickLink );
232cdf0e10cSrcweir     aSaveCheckBox.SetClickHdl ( aClickLink );
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     aVersionBox.SetSelectHdl( LINK( this, SfxVersionDialog, SelectHdl_Impl ) );
235cdf0e10cSrcweir 	aVersionBox.SetDoubleClickHdl( LINK( this, SfxVersionDialog, DClickHdl_Impl ) );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	aVersionBox.GrabFocus();
238cdf0e10cSrcweir 	aVersionBox.SetStyle( aVersionBox.GetStyle() | WB_HSCROLL | WB_CLIPCHILDREN );
239cdf0e10cSrcweir 	aVersionBox.SetSelectionMode( SINGLE_SELECTION );
240cdf0e10cSrcweir 	aVersionBox.SetTabs( &nTabs_Impl[0], MAP_APPFONT );
241cdf0e10cSrcweir 	aVersionBox.Resize();	// OS: Hack fuer richtige Selektion
242cdf0e10cSrcweir     RecalcDateColumn();
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     // set dialog title (filename or docinfo title)
245cdf0e10cSrcweir     String sText = GetText();
246cdf0e10cSrcweir     ( sText += ' ' ) += pViewFrame->GetObjectShell()->GetTitle();
247cdf0e10cSrcweir     SetText( sText );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     Init_Impl();
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
ConvertWhiteSpaces_Impl(const String & rText)252cdf0e10cSrcweir String ConvertWhiteSpaces_Impl( const String& rText )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	// converted linebreaks and tabs to blanks; it's necessary for the display
255cdf0e10cSrcweir 	String sConverted;
256cdf0e10cSrcweir 	const sal_Unicode* pChars = rText.GetBuffer();
257cdf0e10cSrcweir 	while ( *pChars )
258cdf0e10cSrcweir 	{
259cdf0e10cSrcweir 		switch ( *pChars )
260cdf0e10cSrcweir 		{
261cdf0e10cSrcweir 			case '\n' :
262cdf0e10cSrcweir 			case '\t' :
263cdf0e10cSrcweir 				sConverted += ' ';
264cdf0e10cSrcweir 				break;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 			default:
267cdf0e10cSrcweir 				sConverted += *pChars;
268cdf0e10cSrcweir 		}
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 		++pChars;
271cdf0e10cSrcweir 	}
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 	return sConverted;
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
Init_Impl()276cdf0e10cSrcweir void SfxVersionDialog::Init_Impl()
277cdf0e10cSrcweir {
278cdf0e10cSrcweir 	SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
279cdf0e10cSrcweir 	SfxMedium* pMedium = pObjShell->GetMedium();
280cdf0e10cSrcweir     uno::Sequence < util::RevisionTag > aVersions = pMedium->GetVersionList( true );
281cdf0e10cSrcweir     delete mpTable;
282cdf0e10cSrcweir     mpTable = new SfxVersionTableDtor( aVersions );
283cdf0e10cSrcweir 	{
284cdf0e10cSrcweir         for ( sal_uInt16 n = 0; n < mpTable->Count(); ++n )
285cdf0e10cSrcweir 		{
286cdf0e10cSrcweir             SfxVersionInfo *pInfo = mpTable->GetObject(n);
287cdf0e10cSrcweir             String aEntry = ConvertDateTime_Impl( pInfo->aCreationDate, *mpLocaleWrapper );
288cdf0e10cSrcweir 			aEntry += '\t';
289cdf0e10cSrcweir 			aEntry += pInfo->aAuthor;
290cdf0e10cSrcweir 			aEntry += '\t';
291cdf0e10cSrcweir 			aEntry += ConvertWhiteSpaces_Impl( pInfo->aComment );
292cdf0e10cSrcweir 			SvLBoxEntry *pEntry = aVersionBox.InsertEntry( aEntry );
293cdf0e10cSrcweir 			pEntry->SetUserData( pInfo );
294cdf0e10cSrcweir 		}
295cdf0e10cSrcweir 	}
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 	aSaveCheckBox.Check( mbIsSaveVersionOnClose );
298cdf0e10cSrcweir 
299cdf0e10cSrcweir     sal_Bool bEnable = !pObjShell->IsReadOnly();
300cdf0e10cSrcweir     aSaveButton.Enable( bEnable );
301cdf0e10cSrcweir     aSaveCheckBox.Enable( bEnable );
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     aOpenButton.Disable();
304cdf0e10cSrcweir     aViewButton.Disable();
305cdf0e10cSrcweir     aDeleteButton.Disable();
306cdf0e10cSrcweir     aCompareButton.Disable();
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     SelectHdl_Impl( &aVersionBox );
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
~SfxVersionDialog()311cdf0e10cSrcweir SfxVersionDialog::~SfxVersionDialog ()
312cdf0e10cSrcweir {
313cdf0e10cSrcweir     delete mpTable;
314cdf0e10cSrcweir     delete mpLocaleWrapper;
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
Open_Impl()317cdf0e10cSrcweir void SfxVersionDialog::Open_Impl()
318cdf0e10cSrcweir {
319cdf0e10cSrcweir 	SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 	SvLBoxEntry *pEntry = aVersionBox.FirstSelected();
322cdf0e10cSrcweir 	sal_uIntPtr nPos = aVersionBox.GetModel()->GetRelPos( pEntry );
323cdf0e10cSrcweir 	SfxInt16Item aItem( SID_VERSION, (short)nPos+1 );
324cdf0e10cSrcweir 	SfxStringItem aTarget( SID_TARGETNAME, DEFINE_CONST_UNICODE("_blank") );
325cdf0e10cSrcweir 	SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE("private:user") );
326cdf0e10cSrcweir 	SfxStringItem aFile( SID_FILE_NAME, pObjShell->GetMedium()->GetName() );
327cdf0e10cSrcweir 
328cdf0e10cSrcweir     uno::Sequence< beans::NamedValue > aEncryptionData;
329cdf0e10cSrcweir 	if ( GetEncryptionData_Impl( pObjShell->GetMedium()->GetItemSet(), aEncryptionData ) )
330cdf0e10cSrcweir 	{
331cdf0e10cSrcweir 		// there is a password, it should be used during the opening
332cdf0e10cSrcweir 		SfxUnoAnyItem aEncryptionDataItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) );
333cdf0e10cSrcweir 		pViewFrame->GetDispatcher()->Execute(
334cdf0e10cSrcweir 			SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aFile, &aItem, &aTarget, &aReferer, &aEncryptionDataItem, 0L );
335cdf0e10cSrcweir 	}
336cdf0e10cSrcweir 	else
337cdf0e10cSrcweir 		pViewFrame->GetDispatcher()->Execute(
338cdf0e10cSrcweir 			SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aFile, &aItem, &aTarget, &aReferer, 0L );
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 	Close();
341cdf0e10cSrcweir }
342cdf0e10cSrcweir 
RecalcDateColumn()343cdf0e10cSrcweir void SfxVersionDialog::RecalcDateColumn()
344cdf0e10cSrcweir {
345cdf0e10cSrcweir     // recalculate the datetime column width
346cdf0e10cSrcweir     DateTime aNow;
347cdf0e10cSrcweir     mpLocaleWrapper = new LocaleDataWrapper(
348cdf0e10cSrcweir         ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
349cdf0e10cSrcweir     String sDateTime = ConvertDateTime_Impl( aNow, *mpLocaleWrapper );
350cdf0e10cSrcweir     long nWidth = aVersionBox.GetTextWidth( sDateTime );
351cdf0e10cSrcweir     nWidth += 15; // a little offset
352cdf0e10cSrcweir     long nTab = aVersionBox.GetTab(1);
353cdf0e10cSrcweir     if ( nWidth > nTab )
354cdf0e10cSrcweir     {
355cdf0e10cSrcweir         // resize columns
356cdf0e10cSrcweir         long nDelta = nWidth - nTab;
357cdf0e10cSrcweir         aVersionBox.SetTab( 1, nTab + nDelta, MAP_PIXEL );
358cdf0e10cSrcweir         nTab = aVersionBox.GetTab(2);
359cdf0e10cSrcweir         aVersionBox.SetTab( 2, nTab + nDelta, MAP_PIXEL );
360cdf0e10cSrcweir 
361cdf0e10cSrcweir         // resize and move header
362cdf0e10cSrcweir         Size aSize = aDateTimeText.GetSizePixel();
363cdf0e10cSrcweir         aSize.Width() += nDelta;
364cdf0e10cSrcweir         aDateTimeText.SetSizePixel( aSize );
365cdf0e10cSrcweir         Point aPos = aSavedByText.GetPosPixel();
366cdf0e10cSrcweir         aPos.X() += nDelta;
367cdf0e10cSrcweir         aSavedByText.SetPosPixel( aPos );
368cdf0e10cSrcweir         aPos = aCommentText.GetPosPixel();
369cdf0e10cSrcweir         aPos.X() += nDelta;
370cdf0e10cSrcweir         aCommentText.SetPosPixel( aPos );
371cdf0e10cSrcweir     }
372cdf0e10cSrcweir }
373cdf0e10cSrcweir 
IMPL_LINK(SfxVersionDialog,DClickHdl_Impl,Control *,EMPTYARG)374cdf0e10cSrcweir IMPL_LINK( SfxVersionDialog, DClickHdl_Impl, Control*, EMPTYARG )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir     Open_Impl();
377cdf0e10cSrcweir 	return 0L;
378cdf0e10cSrcweir }
379cdf0e10cSrcweir 
IMPL_LINK(SfxVersionDialog,SelectHdl_Impl,Control *,EMPTYARG)380cdf0e10cSrcweir IMPL_LINK( SfxVersionDialog, SelectHdl_Impl, Control*, EMPTYARG )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir     bool bEnable = ( aVersionBox.FirstSelected() != NULL );
383cdf0e10cSrcweir     SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
384cdf0e10cSrcweir     aDeleteButton.Enable( bEnable!= false && !pObjShell->IsReadOnly() );
385cdf0e10cSrcweir     aOpenButton.Enable( bEnable!= false );
386cdf0e10cSrcweir     aViewButton.Enable( bEnable!= false );
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     const SfxPoolItem *pDummy=NULL;
389cdf0e10cSrcweir     SfxItemState eState = pViewFrame->GetDispatcher()->QueryState( SID_DOCUMENT_MERGE, pDummy );
390cdf0e10cSrcweir     eState = pViewFrame->GetDispatcher()->QueryState( SID_DOCUMENT_COMPARE, pDummy );
391cdf0e10cSrcweir     aCompareButton.Enable( bEnable!= false && eState >= SFX_ITEM_AVAILABLE );
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     return 0L;
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
IMPL_LINK(SfxVersionDialog,ButtonHdl_Impl,Button *,pButton)396cdf0e10cSrcweir IMPL_LINK( SfxVersionDialog, ButtonHdl_Impl, Button*, pButton )
397cdf0e10cSrcweir {
398cdf0e10cSrcweir 	SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
399cdf0e10cSrcweir 	SvLBoxEntry *pEntry = aVersionBox.FirstSelected();
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 	if ( pButton == &aSaveCheckBox )
402cdf0e10cSrcweir 	{
403cdf0e10cSrcweir 		mbIsSaveVersionOnClose = aSaveCheckBox.IsChecked();
404cdf0e10cSrcweir 	}
405cdf0e10cSrcweir 	else if ( pButton == &aSaveButton )
406cdf0e10cSrcweir 	{
407cdf0e10cSrcweir 		SfxVersionInfo aInfo;
408cdf0e10cSrcweir 		aInfo.aAuthor = SvtUserOptions().GetFullName();
409cdf0e10cSrcweir 		SfxViewVersionDialog_Impl* pDlg = new SfxViewVersionDialog_Impl( this, aInfo, sal_True );
410cdf0e10cSrcweir 		short nRet = pDlg->Execute();
411cdf0e10cSrcweir 		if ( nRet == RET_OK )
412cdf0e10cSrcweir 		{
413cdf0e10cSrcweir             SfxStringItem aComment( SID_DOCINFO_COMMENTS, aInfo.aComment );
414cdf0e10cSrcweir 			pObjShell->SetModified( sal_True );
415cdf0e10cSrcweir             const SfxPoolItem* aItems[2];
416cdf0e10cSrcweir             aItems[0] = &aComment;
417cdf0e10cSrcweir             aItems[1] = NULL;
418cdf0e10cSrcweir             pViewFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, aItems, 0 );
419cdf0e10cSrcweir 			aVersionBox.SetUpdateMode( sal_False );
420cdf0e10cSrcweir 			aVersionBox.Clear();
421cdf0e10cSrcweir 			Init_Impl();
422cdf0e10cSrcweir 			aVersionBox.SetUpdateMode( sal_True );
423cdf0e10cSrcweir 		}
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 		delete pDlg;
426cdf0e10cSrcweir 	}
427cdf0e10cSrcweir 	if ( pButton == &aDeleteButton && pEntry )
428cdf0e10cSrcweir 	{
429cdf0e10cSrcweir         pObjShell->GetMedium()->RemoveVersion_Impl( ((SfxVersionInfo*) pEntry->GetUserData())->aName );
430cdf0e10cSrcweir 		pObjShell->SetModified( sal_True );
431cdf0e10cSrcweir         aVersionBox.SetUpdateMode( sal_False );
432cdf0e10cSrcweir 		aVersionBox.Clear();
433cdf0e10cSrcweir 		Init_Impl();
434cdf0e10cSrcweir         aVersionBox.SetUpdateMode( sal_True );
435cdf0e10cSrcweir 	}
436cdf0e10cSrcweir 	else if ( pButton == &aOpenButton && pEntry )
437cdf0e10cSrcweir 	{
438cdf0e10cSrcweir 		Open_Impl();
439cdf0e10cSrcweir 	}
440cdf0e10cSrcweir 	else if ( pButton == &aViewButton && pEntry )
441cdf0e10cSrcweir 	{
442cdf0e10cSrcweir 		SfxVersionInfo* pInfo = (SfxVersionInfo*) pEntry->GetUserData();
443cdf0e10cSrcweir 		SfxViewVersionDialog_Impl* pDlg = new SfxViewVersionDialog_Impl( this, *pInfo, sal_False );
444cdf0e10cSrcweir 		pDlg->Execute();
445cdf0e10cSrcweir 		delete pDlg;
446cdf0e10cSrcweir 	}
447cdf0e10cSrcweir 	else if ( pEntry && pButton == &aCompareButton )
448cdf0e10cSrcweir 	{
449cdf0e10cSrcweir 		SfxAllItemSet aSet( pObjShell->GetPool() );
450cdf0e10cSrcweir 		sal_uIntPtr nPos = aVersionBox.GetModel()->GetRelPos( pEntry );
451cdf0e10cSrcweir 		aSet.Put( SfxInt16Item( SID_VERSION, (short)nPos+1 ) );
452cdf0e10cSrcweir 		aSet.Put( SfxStringItem( SID_FILE_NAME, pObjShell->GetMedium()->GetName() ) );
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 		SfxItemSet* pSet = pObjShell->GetMedium()->GetItemSet();
455cdf0e10cSrcweir 		SFX_ITEMSET_ARG( pSet, pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False );
456cdf0e10cSrcweir 		SFX_ITEMSET_ARG( pSet, pFilterOptItem, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
457cdf0e10cSrcweir 		if ( pFilterItem )
458cdf0e10cSrcweir 			aSet.Put( *pFilterItem );
459cdf0e10cSrcweir 		if ( pFilterOptItem )
460cdf0e10cSrcweir 			aSet.Put( *pFilterOptItem );
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 		pViewFrame->GetDispatcher()->Execute( SID_DOCUMENT_COMPARE, SFX_CALLMODE_ASYNCHRON, aSet );
463cdf0e10cSrcweir 		Close();
464cdf0e10cSrcweir 	}
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 	return 0L;
467cdf0e10cSrcweir }
468cdf0e10cSrcweir 
SfxViewVersionDialog_Impl(Window * pParent,SfxVersionInfo & rInfo,sal_Bool bEdit)469cdf0e10cSrcweir SfxViewVersionDialog_Impl::SfxViewVersionDialog_Impl ( Window *pParent, SfxVersionInfo& rInfo, sal_Bool bEdit )
470cdf0e10cSrcweir 	: SfxModalDialog( pParent, SfxResId( DLG_COMMENTS ) )
471cdf0e10cSrcweir 	, aDateTimeText( this, SfxResId( FT_DATETIME ) )
472cdf0e10cSrcweir 	, aSavedByText( this, SfxResId( FT_SAVEDBY ) )
473cdf0e10cSrcweir 	, aEdit( this, SfxResId( ME_VERSIONS ) )
474cdf0e10cSrcweir 	, aOKButton( this, SfxResId( PB_OK ) )
475cdf0e10cSrcweir 	, aCancelButton( this, SfxResId( PB_CANCEL ) )
476cdf0e10cSrcweir 	, aCloseButton( this, SfxResId( PB_CLOSE ) )
477cdf0e10cSrcweir 	, aHelpButton( this, SfxResId( PB_HELP ) )
478cdf0e10cSrcweir 	, pInfo( &rInfo )
479cdf0e10cSrcweir {
480cdf0e10cSrcweir 	FreeResource();
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 	LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
483cdf0e10cSrcweir 	aDateTimeText.SetText( aDateTimeText.GetText().Append(ConvertDateTime_Impl( pInfo->aCreationDate, aLocaleWrapper )) );
484cdf0e10cSrcweir 	aSavedByText.SetText( aSavedByText.GetText().Append(pInfo->aAuthor) );
485cdf0e10cSrcweir 	aEdit.SetText( rInfo.aComment );
486cdf0e10cSrcweir 
487cdf0e10cSrcweir 	aCloseButton.SetClickHdl ( LINK( this, SfxViewVersionDialog_Impl, ButtonHdl ) );
488cdf0e10cSrcweir 	aOKButton.SetClickHdl ( LINK( this, SfxViewVersionDialog_Impl, ButtonHdl ) );
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 	aEdit.GrabFocus();
491cdf0e10cSrcweir 	if ( !bEdit )
492cdf0e10cSrcweir 	{
493cdf0e10cSrcweir 		aOKButton.Hide();
494cdf0e10cSrcweir 		aCancelButton.Hide();
495cdf0e10cSrcweir 		aEdit.SetReadOnly( sal_True );
496cdf0e10cSrcweir 	}
497cdf0e10cSrcweir 	else
498cdf0e10cSrcweir 		aCloseButton.Hide();
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
IMPL_LINK(SfxViewVersionDialog_Impl,ButtonHdl,Button *,pButton)501cdf0e10cSrcweir IMPL_LINK( SfxViewVersionDialog_Impl, ButtonHdl, Button*, pButton )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir 	if ( pButton == &aCloseButton )
504cdf0e10cSrcweir 	{
505cdf0e10cSrcweir 		EndDialog( RET_CANCEL );
506cdf0e10cSrcweir 	}
507cdf0e10cSrcweir 	else if ( pButton == &aOKButton )
508cdf0e10cSrcweir 	{
509cdf0e10cSrcweir 		pInfo->aComment = aEdit.GetText();
510cdf0e10cSrcweir 		EndDialog( RET_OK );
511cdf0e10cSrcweir 	}
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 	return 0L;
514cdf0e10cSrcweir }
515cdf0e10cSrcweir 
516