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