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 #include "precompiled_svtools.hxx"
25 
26 #include "wizardpagecontroller.hxx"
27 #include "wizardshell.hxx"
28 
29 /** === begin UNO includes === **/
30 #include <com/sun/star/lang/XComponent.hpp>
31 #include <com/sun/star/awt/XControl.hpp>
32 /** === end UNO includes === **/
33 
34 #include <toolkit/helper/vclunohelper.hxx>
35 #include <tools/diagnose_ex.h>
36 
37 //......................................................................................................................
38 namespace svt { namespace uno
39 {
40 //......................................................................................................................
41 
42 	/** === begin UNO using === **/
43 	using ::com::sun::star::uno::Reference;
44 	using ::com::sun::star::uno::XInterface;
45 	using ::com::sun::star::uno::UNO_QUERY;
46 	using ::com::sun::star::uno::UNO_QUERY_THROW;
47 	using ::com::sun::star::uno::UNO_SET_THROW;
48 	using ::com::sun::star::uno::Exception;
49 	using ::com::sun::star::uno::RuntimeException;
50 	using ::com::sun::star::uno::Any;
51 	using ::com::sun::star::uno::makeAny;
52 	using ::com::sun::star::uno::Sequence;
53 	using ::com::sun::star::uno::Type;
54     using ::com::sun::star::ui::dialogs::XWizardController;
55     using ::com::sun::star::awt::XWindow;
56     using ::com::sun::star::lang::XComponent;
57     using ::com::sun::star::awt::XControl;
58 	/** === end UNO using === **/
59     using namespace ::com::sun::star;
60 
61 	//==================================================================================================================
62 	//= WizardPageController
63 	//==================================================================================================================
64 	//------------------------------------------------------------------------------------------------------------------
WizardPageController(WizardShell & i_rParent,const Reference<XWizardController> & i_rController,const sal_Int16 i_nPageId)65     WizardPageController::WizardPageController( WizardShell& i_rParent, const Reference< XWizardController >& i_rController,
66             const sal_Int16 i_nPageId )
67         :m_xController( i_rController )
68         ,m_xWizardPage()
69         ,m_nPageId( i_nPageId )
70     {
71         ENSURE_OR_THROW( m_xController.is(), "no controller" );
72         try
73         {
74             m_xWizardPage.set( m_xController->createPage(
75                 Reference< XWindow >( i_rParent.GetComponentInterface( sal_True ), UNO_QUERY_THROW ),
76                 m_nPageId
77             ), UNO_SET_THROW );
78 
79             Reference< XWindow > xPageWindow( m_xWizardPage->getWindow(), UNO_SET_THROW );
80             xPageWindow->setVisible( sal_True );
81 
82             TabPage* pTabPage( getTabPage() );
83             if ( pTabPage )
84                 pTabPage->SetStyle( pTabPage->GetStyle() | WB_CHILDDLGCTRL | WB_DIALOGCONTROL );
85         }
86         catch( const Exception& )
87         {
88         	DBG_UNHANDLED_EXCEPTION();
89         }
90     }
91 
92 	//------------------------------------------------------------------------------------------------------------------
~WizardPageController()93     WizardPageController::~WizardPageController()
94     {
95         try
96         {
97             if ( m_xWizardPage.is() )
98                 m_xWizardPage->dispose();
99         }
100         catch( const Exception& )
101         {
102         	DBG_UNHANDLED_EXCEPTION();
103         }
104     }
105 
106 	//------------------------------------------------------------------------------------------------------------------
getTabPage() const107     TabPage* WizardPageController::getTabPage() const
108     {
109         ENSURE_OR_RETURN( m_xWizardPage.is(), "WizardPageController::getTabPage: no external wizard page!", NULL );
110         try
111         {
112             Reference< XWindow > xPageWindow( m_xWizardPage->getWindow(), UNO_SET_THROW );
113             Window* pPageWindow = VCLUnoHelper::GetWindow( xPageWindow );
114             if ( pPageWindow == NULL )
115             {
116                 // windows created via the XContainerWindowProvider might be controls, not real windows, so resolve
117                 // that one indirection
118                 const Reference< XControl > xPageControl( m_xWizardPage->getWindow(), UNO_QUERY_THROW );
119                 xPageWindow.set( xPageControl->getPeer(), UNO_QUERY_THROW );
120                 pPageWindow = VCLUnoHelper::GetWindow( xPageWindow );
121             }
122 
123             OSL_ENSURE( pPageWindow != NULL, "WizardPageController::getTabPage: unable to find the Window implementation for the page's window!" );
124             return dynamic_cast< TabPage* >( pPageWindow );
125         }
126         catch( const Exception& )
127         {
128         	DBG_UNHANDLED_EXCEPTION();
129         }
130         return NULL;
131     }
132 
133 	//------------------------------------------------------------------------------------------------------------------
initializePage()134 	void WizardPageController::initializePage()
135     {
136         if ( !m_xWizardPage.is() )
137             return;
138 
139         try
140         {
141             m_xWizardPage->activatePage();
142         }
143         catch( const Exception& )
144         {
145         	DBG_UNHANDLED_EXCEPTION();
146         }
147     }
148 
149     //------------------------------------------------------------------------------------------------------------------
commitPage(WizardTypes::CommitPageReason i_eReason)150     sal_Bool WizardPageController::commitPage( WizardTypes::CommitPageReason i_eReason )
151     {
152         if ( !m_xWizardPage.is() )
153             return sal_True;
154 
155         try
156         {
157             return m_xWizardPage->commitPage( WizardShell::convertCommitReasonToTravelType( i_eReason ) );
158         }
159         catch( const Exception& )
160         {
161         	DBG_UNHANDLED_EXCEPTION();
162         }
163 
164         return sal_True;
165     }
166 
167     //------------------------------------------------------------------------------------------------------------------
canAdvance() const168     bool WizardPageController::canAdvance() const
169     {
170         if ( !m_xWizardPage.is() )
171             return true;
172 
173         try
174         {
175             return m_xWizardPage->canAdvance();
176         }
177         catch( const Exception& )
178         {
179         	DBG_UNHANDLED_EXCEPTION();
180         }
181 
182         return true;
183     }
184 
185 //......................................................................................................................
186 } } // namespace svt::uno
187 //......................................................................................................................
188