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