1*5900e8ecSAndrew Rist /**************************************************************
2*5900e8ecSAndrew Rist  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_svtools.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "wizardpagecontroller.hxx"
27cdf0e10cSrcweir #include "wizardshell.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir /** === begin UNO includes === **/
30cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
31cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp>
32cdf0e10cSrcweir /** === end UNO includes === **/
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
35cdf0e10cSrcweir #include <tools/diagnose_ex.h>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //......................................................................................................................
38cdf0e10cSrcweir namespace svt { namespace uno
39cdf0e10cSrcweir {
40cdf0e10cSrcweir //......................................................................................................................
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 	/** === begin UNO using === **/
43cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
44cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
45cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
46cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
47cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
48cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
49cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
50cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
51cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
52cdf0e10cSrcweir 	using ::com::sun::star::uno::Sequence;
53cdf0e10cSrcweir 	using ::com::sun::star::uno::Type;
54cdf0e10cSrcweir     using ::com::sun::star::ui::dialogs::XWizardController;
55cdf0e10cSrcweir     using ::com::sun::star::awt::XWindow;
56cdf0e10cSrcweir     using ::com::sun::star::lang::XComponent;
57cdf0e10cSrcweir     using ::com::sun::star::awt::XControl;
58cdf0e10cSrcweir 	/** === end UNO using === **/
59cdf0e10cSrcweir     using namespace ::com::sun::star;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	//==================================================================================================================
62cdf0e10cSrcweir 	//= WizardPageController
63cdf0e10cSrcweir 	//==================================================================================================================
64cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
WizardPageController(WizardShell & i_rParent,const Reference<XWizardController> & i_rController,const sal_Int16 i_nPageId)65cdf0e10cSrcweir     WizardPageController::WizardPageController( WizardShell& i_rParent, const Reference< XWizardController >& i_rController,
66cdf0e10cSrcweir             const sal_Int16 i_nPageId )
67cdf0e10cSrcweir         :m_xController( i_rController )
68cdf0e10cSrcweir         ,m_xWizardPage()
69cdf0e10cSrcweir         ,m_nPageId( i_nPageId )
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         ENSURE_OR_THROW( m_xController.is(), "no controller" );
72cdf0e10cSrcweir         try
73cdf0e10cSrcweir         {
74cdf0e10cSrcweir             m_xWizardPage.set( m_xController->createPage(
75cdf0e10cSrcweir                 Reference< XWindow >( i_rParent.GetComponentInterface( sal_True ), UNO_QUERY_THROW ),
76cdf0e10cSrcweir                 m_nPageId
77cdf0e10cSrcweir             ), UNO_SET_THROW );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir             Reference< XWindow > xPageWindow( m_xWizardPage->getWindow(), UNO_SET_THROW );
80cdf0e10cSrcweir             xPageWindow->setVisible( sal_True );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir             TabPage* pTabPage( getTabPage() );
83cdf0e10cSrcweir             if ( pTabPage )
84cdf0e10cSrcweir                 pTabPage->SetStyle( pTabPage->GetStyle() | WB_CHILDDLGCTRL | WB_DIALOGCONTROL );
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir         catch( const Exception& )
87cdf0e10cSrcweir         {
88cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
89cdf0e10cSrcweir         }
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
~WizardPageController()93cdf0e10cSrcweir     WizardPageController::~WizardPageController()
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         try
96cdf0e10cSrcweir         {
97cdf0e10cSrcweir             if ( m_xWizardPage.is() )
98cdf0e10cSrcweir                 m_xWizardPage->dispose();
99cdf0e10cSrcweir         }
100cdf0e10cSrcweir         catch( const Exception& )
101cdf0e10cSrcweir         {
102cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getTabPage() const107cdf0e10cSrcweir     TabPage* WizardPageController::getTabPage() const
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         ENSURE_OR_RETURN( m_xWizardPage.is(), "WizardPageController::getTabPage: no external wizard page!", NULL );
110cdf0e10cSrcweir         try
111cdf0e10cSrcweir         {
112cdf0e10cSrcweir             Reference< XWindow > xPageWindow( m_xWizardPage->getWindow(), UNO_SET_THROW );
113cdf0e10cSrcweir             Window* pPageWindow = VCLUnoHelper::GetWindow( xPageWindow );
114cdf0e10cSrcweir             if ( pPageWindow == NULL )
115cdf0e10cSrcweir             {
116cdf0e10cSrcweir                 // windows created via the XContainerWindowProvider might be controls, not real windows, so resolve
117cdf0e10cSrcweir                 // that one indirection
118cdf0e10cSrcweir                 const Reference< XControl > xPageControl( m_xWizardPage->getWindow(), UNO_QUERY_THROW );
119cdf0e10cSrcweir                 xPageWindow.set( xPageControl->getPeer(), UNO_QUERY_THROW );
120cdf0e10cSrcweir                 pPageWindow = VCLUnoHelper::GetWindow( xPageWindow );
121cdf0e10cSrcweir             }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir             OSL_ENSURE( pPageWindow != NULL, "WizardPageController::getTabPage: unable to find the Window implementation for the page's window!" );
124cdf0e10cSrcweir             return dynamic_cast< TabPage* >( pPageWindow );
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir         catch( const Exception& )
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir         return NULL;
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
initializePage()134cdf0e10cSrcweir 	void WizardPageController::initializePage()
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         if ( !m_xWizardPage.is() )
137cdf0e10cSrcweir             return;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         try
140cdf0e10cSrcweir         {
141cdf0e10cSrcweir             m_xWizardPage->activatePage();
142cdf0e10cSrcweir         }
143cdf0e10cSrcweir         catch( const Exception& )
144cdf0e10cSrcweir         {
145cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
commitPage(WizardTypes::CommitPageReason i_eReason)150cdf0e10cSrcweir     sal_Bool WizardPageController::commitPage( WizardTypes::CommitPageReason i_eReason )
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         if ( !m_xWizardPage.is() )
153cdf0e10cSrcweir             return sal_True;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         try
156cdf0e10cSrcweir         {
157cdf0e10cSrcweir             return m_xWizardPage->commitPage( WizardShell::convertCommitReasonToTravelType( i_eReason ) );
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir         catch( const Exception& )
160cdf0e10cSrcweir         {
161cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         return sal_True;
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
canAdvance() const168cdf0e10cSrcweir     bool WizardPageController::canAdvance() const
169cdf0e10cSrcweir     {
170cdf0e10cSrcweir         if ( !m_xWizardPage.is() )
171cdf0e10cSrcweir             return true;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         try
174cdf0e10cSrcweir         {
175cdf0e10cSrcweir             return m_xWizardPage->canAdvance();
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir         catch( const Exception& )
178cdf0e10cSrcweir         {
179cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
180cdf0e10cSrcweir         }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         return true;
183cdf0e10cSrcweir     }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir //......................................................................................................................
186cdf0e10cSrcweir } } // namespace svt::uno
187cdf0e10cSrcweir //......................................................................................................................
188