Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "wizardpagecontroller.hxx"
22 : #include "wizardshell.hxx"
23 :
24 : #include <com/sun/star/lang/XComponent.hpp>
25 : #include <com/sun/star/awt/XControl.hpp>
26 :
27 : #include <toolkit/helper/vclunohelper.hxx>
28 : #include <tools/diagnose_ex.h>
29 :
30 :
31 : namespace svt { namespace uno
32 : {
33 :
34 :
35 : using ::com::sun::star::uno::Reference;
36 : using ::com::sun::star::uno::XInterface;
37 : using ::com::sun::star::uno::UNO_QUERY;
38 : using ::com::sun::star::uno::UNO_QUERY_THROW;
39 : using ::com::sun::star::uno::UNO_SET_THROW;
40 : using ::com::sun::star::uno::Exception;
41 : using ::com::sun::star::uno::RuntimeException;
42 : using ::com::sun::star::uno::Any;
43 : using ::com::sun::star::uno::makeAny;
44 : using ::com::sun::star::uno::Sequence;
45 : using ::com::sun::star::uno::Type;
46 : using ::com::sun::star::ui::dialogs::XWizardController;
47 : using ::com::sun::star::awt::XWindow;
48 : using ::com::sun::star::lang::XComponent;
49 : using ::com::sun::star::awt::XControl;
50 :
51 : using namespace ::com::sun::star;
52 :
53 :
54 : //= WizardPageController
55 :
56 :
57 0 : WizardPageController::WizardPageController( WizardShell& i_rParent, const Reference< XWizardController >& i_rController,
58 : const sal_Int16 i_nPageId )
59 : :m_xController( i_rController )
60 : ,m_xWizardPage()
61 0 : ,m_nPageId( i_nPageId )
62 : {
63 0 : ENSURE_OR_THROW( m_xController.is(), "no controller" );
64 : try
65 : {
66 0 : m_xWizardPage.set( m_xController->createPage(
67 0 : Reference< XWindow >( i_rParent.GetComponentInterface( true ), UNO_QUERY_THROW ),
68 : m_nPageId
69 0 : ), UNO_SET_THROW );
70 :
71 0 : Reference< XWindow > xPageWindow( m_xWizardPage->getWindow(), UNO_SET_THROW );
72 0 : xPageWindow->setVisible( sal_True );
73 :
74 0 : TabPage* pTabPage( getTabPage() );
75 0 : if ( pTabPage )
76 0 : pTabPage->SetStyle( pTabPage->GetStyle() | WB_CHILDDLGCTRL | WB_DIALOGCONTROL );
77 : }
78 0 : catch( const Exception& )
79 : {
80 : DBG_UNHANDLED_EXCEPTION();
81 : }
82 0 : }
83 :
84 :
85 0 : WizardPageController::~WizardPageController()
86 : {
87 : try
88 : {
89 0 : if ( m_xWizardPage.is() )
90 0 : m_xWizardPage->dispose();
91 : }
92 0 : catch( const Exception& )
93 : {
94 : DBG_UNHANDLED_EXCEPTION();
95 : }
96 0 : }
97 :
98 :
99 0 : TabPage* WizardPageController::getTabPage() const
100 : {
101 0 : ENSURE_OR_RETURN( m_xWizardPage.is(), "WizardPageController::getTabPage: no external wizard page!", NULL );
102 : try
103 : {
104 0 : Reference< XWindow > xPageWindow( m_xWizardPage->getWindow(), UNO_SET_THROW );
105 0 : vcl::Window* pPageWindow = VCLUnoHelper::GetWindow( xPageWindow );
106 0 : if ( pPageWindow == NULL )
107 : {
108 : // windows created via the XContainerWindowProvider might be controls, not real windows, so resolve
109 : // that one indirection
110 0 : const Reference< XControl > xPageControl( m_xWizardPage->getWindow(), UNO_QUERY_THROW );
111 0 : xPageWindow.set( xPageControl->getPeer(), UNO_QUERY_THROW );
112 0 : pPageWindow = VCLUnoHelper::GetWindow( xPageWindow );
113 : }
114 :
115 : OSL_ENSURE( pPageWindow != NULL, "WizardPageController::getTabPage: unable to find the Window implementation for the page's window!" );
116 0 : return dynamic_cast< TabPage* >( pPageWindow );
117 : }
118 0 : catch( const Exception& )
119 : {
120 : DBG_UNHANDLED_EXCEPTION();
121 : }
122 0 : return NULL;
123 : }
124 :
125 :
126 0 : void WizardPageController::initializePage()
127 : {
128 0 : if ( !m_xWizardPage.is() )
129 0 : return;
130 :
131 : try
132 : {
133 0 : m_xWizardPage->activatePage();
134 : }
135 0 : catch( const Exception& )
136 : {
137 : DBG_UNHANDLED_EXCEPTION();
138 : }
139 : }
140 :
141 :
142 0 : bool WizardPageController::commitPage( WizardTypes::CommitPageReason i_eReason )
143 : {
144 0 : if ( !m_xWizardPage.is() )
145 0 : return true;
146 :
147 : try
148 : {
149 0 : return m_xWizardPage->commitPage( WizardShell::convertCommitReasonToTravelType( i_eReason ) );
150 : }
151 0 : catch( const Exception& )
152 : {
153 : DBG_UNHANDLED_EXCEPTION();
154 : }
155 :
156 0 : return true;
157 : }
158 :
159 :
160 0 : bool WizardPageController::canAdvance() const
161 : {
162 0 : if ( !m_xWizardPage.is() )
163 0 : return true;
164 :
165 : try
166 : {
167 0 : return m_xWizardPage->canAdvance();
168 : }
169 0 : catch( const Exception& )
170 : {
171 : DBG_UNHANDLED_EXCEPTION();
172 : }
173 :
174 0 : return true;
175 : }
176 :
177 :
178 1227 : } } // namespace svt::uno
179 :
180 :
181 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|