update dev300-m58
[ooovba.git] / dbaccess / source / ext / macromigration / macromigrationpages.cxx
blobcbd4156b274eab53d675a032bf6eb8edc4eaa0b3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: macromigrationpages.cxx,v $
10 * $Revision: 1.3.2.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "dbaccess_helpid.hrc"
35 #include "dbmm_module.hxx"
36 #include "dbmm_global.hrc"
37 #include "macromigration.hrc"
38 #include "macromigrationpages.hxx"
39 #include "macromigrationdialog.hxx"
41 /** === begin UNO includes === **/
42 #include <com/sun/star/frame/XModel.hpp>
43 /** === end UNO includes === **/
45 #include <tools/urlobj.hxx>
46 #include <tools/diagnose_ex.h>
47 #include <vcl/metric.hxx>
49 //........................................................................
50 namespace dbmm
52 //........................................................................
54 /** === begin UNO using === **/
55 using ::com::sun::star::uno::Reference;
56 using ::com::sun::star::uno::XInterface;
57 using ::com::sun::star::uno::UNO_QUERY;
58 using ::com::sun::star::uno::UNO_QUERY_THROW;
59 using ::com::sun::star::uno::UNO_SET_THROW;
60 using ::com::sun::star::uno::Exception;
61 using ::com::sun::star::uno::RuntimeException;
62 using ::com::sun::star::uno::Any;
63 using ::com::sun::star::uno::makeAny;
64 using ::com::sun::star::uno::Sequence;
65 using ::com::sun::star::frame::XModel;
66 /** === end UNO using === **/
68 //====================================================================
69 //= MacroMigrationPage
70 //====================================================================
71 //--------------------------------------------------------------------
72 MacroMigrationPage::MacroMigrationPage( MacroMigrationDialog& _rParentDialog, const ResId& _rRes )
73 :MacroMigrationPage_Base( &_rParentDialog, _rRes )
74 ,m_aHeader( this, MacroMigrationResId( FT_HEADER ) )
76 Font aFont( m_aHeader.GetFont() );
77 aFont.SetWeight( WEIGHT_BOLD );
78 m_aHeader.SetFont( aFont );
81 //--------------------------------------------------------------------
82 MacroMigrationPage::~MacroMigrationPage()
86 //--------------------------------------------------------------------
87 const MacroMigrationDialog& MacroMigrationPage::getDialog() const
89 return *dynamic_cast< const MacroMigrationDialog* >( GetParent() );
92 //--------------------------------------------------------------------
93 MacroMigrationDialog& MacroMigrationPage::getDialog()
95 return *dynamic_cast< MacroMigrationDialog* >( GetParent() );
98 //====================================================================
99 //= PreparationPage
100 //====================================================================
101 //--------------------------------------------------------------------
102 PreparationPage::PreparationPage( MacroMigrationDialog& _rParentDialog )
103 :MacroMigrationPage( _rParentDialog, MacroMigrationResId( TP_PREPARE ) )
104 ,m_aIntroduction ( this, MacroMigrationResId( FT_INTRODUCTION ) )
105 ,m_aCloseDocError( this, MacroMigrationResId( FT_CLOSE_DOC_ERROR ) )
107 FreeResource();
110 //--------------------------------------------------------------------
111 void PreparationPage::showCloseDocsError( bool _bShow )
113 m_aCloseDocError.Show( _bShow );
116 //--------------------------------------------------------------------
117 TabPage* PreparationPage::Create( ::svt::RoadmapWizard& _rParentDialog )
119 return new PreparationPage( dynamic_cast< MacroMigrationDialog& >( _rParentDialog ) );
122 //====================================================================
123 //= SaveDBDocPage
124 //====================================================================
125 //--------------------------------------------------------------------
126 SaveDBDocPage::SaveDBDocPage( MacroMigrationDialog& _rParentDialog )
127 :MacroMigrationPage( _rParentDialog, MacroMigrationResId( TP_SAVE_DBDOC_AS ) )
128 ,m_aExplanation ( this, MacroMigrationResId( FT_EXPLANATION ) )
129 ,m_aSaveAsLabel ( this, MacroMigrationResId( FT_SAVE_AS_LABEL ) )
130 ,m_aSaveAsLocation ( this, MacroMigrationResId( ED_SAVE_AS_LOCATION ) )
131 ,m_aBrowseSaveAsLocation( this, MacroMigrationResId( PB_BROWSE_SAVE_AS_LOCATION ) )
132 ,m_aStartMigration ( this, MacroMigrationResId( FT_START_MIGRATION ) )
133 ,m_aLocationController( _rParentDialog.getComponentContext(), m_aSaveAsLocation, m_aBrowseSaveAsLocation )
135 FreeResource();
137 m_aSaveAsLocation.SetModifyHdl( LINK( this, SaveDBDocPage, OnLocationModified ) );
138 m_aSaveAsLocation.SetDropDownLineCount( 20 );
140 m_aSaveAsLocation.SetHelpId( HID_MACRO_MIGRATION_BACKUP_LOCATION );
142 impl_updateLocationDependentItems();
145 //--------------------------------------------------------------------
146 void SaveDBDocPage::impl_updateLocationDependentItems()
148 updateDialogTravelUI();
149 m_aStartMigration.Show( m_aSaveAsLocation.GetText().Len() > 0 );
152 //--------------------------------------------------------------------
153 IMPL_LINK( SaveDBDocPage, OnLocationModified, Edit*, /**/ )
155 impl_updateLocationDependentItems();
156 return 0L;
159 //--------------------------------------------------------------------
160 void SaveDBDocPage::initializePage()
162 OWizardPage::initializePage();
166 // get the document's current URL
167 Reference< XModel > xDocument( getDialog().getDocument(), UNO_QUERY_THROW );
168 INetURLObject aURLParser( xDocument->getURL() );
169 OSL_ENSURE( aURLParser.GetProtocol() != INET_PROT_NOT_VALID, "SaveDBDocPage::initializePage: illegal document URL!" );
171 ::rtl::OUStringBuffer aBaseName( aURLParser.getBase() );
172 aBaseName.appendAscii( ".backup" );
173 aURLParser.setBase( aBaseName.makeStringAndClear() );
175 m_aLocationController.setURL( aURLParser.GetMainURL( INetURLObject::NO_DECODE ) );
176 impl_updateLocationDependentItems();
178 catch( const Exception& )
180 DBG_UNHANDLED_EXCEPTION();
184 //--------------------------------------------------------------------
185 bool SaveDBDocPage::canAdvance() const
187 if ( !MacroMigrationPage::canAdvance() )
188 return false;
190 return m_aSaveAsLocation.GetText().Len() > 0;
193 //--------------------------------------------------------------------
194 sal_Bool SaveDBDocPage::commitPage( CommitPageReason _eReason )
196 if ( !MacroMigrationPage::commitPage( _eReason ) )
197 return sal_False;
199 if ( eTravelBackward == _eReason )
200 return sal_True;
202 if ( !m_aLocationController.prepareCommit() )
203 return sal_False;
205 return sal_True;
208 //--------------------------------------------------------------------
209 TabPage* SaveDBDocPage::Create( ::svt::RoadmapWizard& _rParentDialog )
211 return new SaveDBDocPage( dynamic_cast< MacroMigrationDialog& >( _rParentDialog ) );
214 //====================================================================
215 //= ProgressPage
216 //====================================================================
217 //--------------------------------------------------------------------
218 ProgressPage::ProgressPage( MacroMigrationDialog& _rParentDialog )
219 :MacroMigrationPage( _rParentDialog, MacroMigrationResId( TP_MIGRATE ) )
220 ,m_aObjectCount ( this, MacroMigrationResId( FT_OBJECT_COUNT ) )
221 ,m_aCurrentObjectLabel ( this, MacroMigrationResId( FT_CURRENT_OBJECT_LABEL ) )
222 ,m_aCurrentObject ( this, MacroMigrationResId( FT_CURRENT_OBJECT ) )
223 ,m_aCurrentActionLabel ( this, MacroMigrationResId( FT_CURRENT_PROGRESS_LABEL ) )
224 ,m_aCurrentAction ( this, MacroMigrationResId( FT_CURRENT_PROGRESS ) )
225 ,m_aCurrentProgress ( this, MacroMigrationResId( WND_CURRENT_PROGRESS ) )
226 ,m_aAllProgressLabel ( this, MacroMigrationResId( FT_ALL_PROGRESS_LABEL ) )
227 ,m_aAllProgressText ( this, MacroMigrationResId( FT_OBJECT_COUNT_PROGRESS ) )
228 ,m_aAllProgress ( this, MacroMigrationResId( WND_ALL_PROGRESS ) )
229 ,m_aMigrationDone ( this, MacroMigrationResId( FT_MIGRATION_DONE ) )
231 FreeResource();
234 //--------------------------------------------------------------------
235 TabPage* ProgressPage::Create( ::svt::RoadmapWizard& _rParentDialog )
237 return new ProgressPage( dynamic_cast< MacroMigrationDialog& >( _rParentDialog ) );
240 //--------------------------------------------------------------------
241 void ProgressPage::setDocumentCounts( const sal_Int32 _nForms, const sal_Int32 _nReports )
243 String sText( m_aObjectCount.GetText() );
244 sText.SearchAndReplaceAscii( "$forms$", String::CreateFromInt32( _nForms ) );
245 sText.SearchAndReplaceAscii( "$reports$", String::CreateFromInt32( _nReports ) );
246 m_aObjectCount.SetText( sText );
249 //--------------------------------------------------------------------
250 void ProgressPage::onFinishedSuccessfully()
252 m_aMigrationDone.Show();
255 //--------------------------------------------------------------------
256 void ProgressPage::startObject( const ::rtl::OUString& _rObjectName, const ::rtl::OUString& _rCurrentAction, const sal_uInt32 _nRange )
258 m_aCurrentObject.SetText( _rObjectName );
259 m_aCurrentAction.SetText( _rCurrentAction );
260 m_aCurrentProgress.SetRange( _nRange );
261 m_aCurrentProgress.SetValue( (sal_uInt32)0 );
263 // since this is currently called from the main thread, which does not have the chance
264 // to re-schedule, we need to explicitly update the display
265 m_aCurrentObject.Update();
266 m_aCurrentAction.Update();
267 Update();
270 //--------------------------------------------------------------------
271 void ProgressPage::setObjectProgressText( const ::rtl::OUString& _rText )
273 m_aCurrentAction.SetText( _rText );
274 m_aCurrentAction.Update();
275 Update();
278 //--------------------------------------------------------------------
279 void ProgressPage::setObjectProgressValue( const sal_uInt32 _nValue )
281 m_aCurrentProgress.SetValue( _nValue );
282 Update();
285 //--------------------------------------------------------------------
286 void ProgressPage::endObject()
288 m_aCurrentAction.SetText( String() );
289 m_aCurrentProgress.SetValue( m_aCurrentProgress.GetRange() );
290 m_aCurrentAction.Update();
291 Update();
294 //--------------------------------------------------------------------
295 void ProgressPage::start( const sal_uInt32 _nOverallRange )
297 m_aAllProgress.SetRange( _nOverallRange );
298 Update();
301 //--------------------------------------------------------------------
302 void ProgressPage::setOverallProgressText( const ::rtl::OUString& _rText )
304 m_aAllProgressText.SetText( _rText );
305 Update();
308 //--------------------------------------------------------------------
309 void ProgressPage::setOverallProgressValue( const sal_uInt32 _nValue )
311 m_aAllProgress.SetValue( _nValue );
312 Update();
315 //====================================================================
316 //= ResultPage
317 //====================================================================
318 //--------------------------------------------------------------------
319 ResultPage::ResultPage( MacroMigrationDialog& _rParentDialog )
320 :MacroMigrationPage( _rParentDialog, MacroMigrationResId( TP_SUMMARY ) )
321 ,m_aChangesLabel( this, MacroMigrationResId( FT_CHANGES_LABEL ) )
322 ,m_aChanges ( this, MacroMigrationResId( ED_CHANGES ) )
323 ,m_aSuccessful ( MacroMigrationResId( STR_SUCCESSFUL ) )
324 ,m_aUnsuccessful( MacroMigrationResId( STR_UNSUCCESSFUL ) )
326 FreeResource();
329 //--------------------------------------------------------------------
330 TabPage* ResultPage::Create( ::svt::RoadmapWizard& _rParentDialog )
332 return new ResultPage( dynamic_cast< MacroMigrationDialog& >( _rParentDialog ) );
335 //--------------------------------------------------------------------
336 void ResultPage::displayMigrationLog( const bool _bSuccessful, const String& _rSummary )
338 m_aChangesLabel.SetText( _bSuccessful ? m_aSuccessful : m_aUnsuccessful );
339 m_aChanges.SetText( _rSummary );
341 // resize m_aChangesLabel and m_aChances as needed for the label text to fit
342 Rectangle aOriginalLabelSize( m_aChangesLabel.GetPosPixel(), m_aChangesLabel.GetSizePixel() );
343 // assume 3 lines, at most
344 Rectangle aNewLabelSize( aOriginalLabelSize );
345 aNewLabelSize.Bottom() = aNewLabelSize.Top() + m_aChangesLabel.LogicToPixel( Size( 0, 3*8 ), MAP_APPFONT ).Height();
346 TextRectInfo aInfo;
347 aNewLabelSize = m_aChangesLabel.GetTextRect( aNewLabelSize, m_aChangesLabel.GetText(), TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK, &aInfo );
348 aNewLabelSize.Bottom() = aNewLabelSize.Top() + m_aChangesLabel.LogicToPixel( Size( 0, aInfo.GetLineCount() * 8 ), MAP_APPFONT ).Height();
350 m_aChangesLabel.SetSizePixel( aNewLabelSize.GetSize() );
352 long nChangesDiff = aNewLabelSize.GetHeight() - aOriginalLabelSize.GetHeight();
353 Size aChangesSize( m_aChanges.GetSizePixel() );
354 aChangesSize.Height() -= nChangesDiff;
355 m_aChanges.SetSizePixel( aChangesSize );
357 Point aChangesPos( m_aChanges.GetPosPixel() );
358 aChangesPos.Y() += nChangesDiff;
359 m_aChanges.SetPosPixel( aChangesPos );
362 //........................................................................
363 } // namespace dbmm
364 //........................................................................