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 <toolkit/helper/vclunohelper.hxx>
25 #include <tools/diagnose_ex.h>
26 
27 
28 namespace svt::uno
29 {
30 
31 
32     using css::uno::Reference;
33     using css::uno::UNO_SET_THROW;
34     using css::uno::Exception;
35     using css::ui::dialogs::XWizardController;
36     using css::awt::XWindow;
37 
38     using namespace ::com::sun::star;
39 
40 
41     //= WizardPageController
42 
43 
WizardPageController(weld::Container * pParent,const Reference<XWizardController> & i_rController,const sal_Int16 i_nPageId)44     WizardPageController::WizardPageController(weld::Container* pParent, const Reference< XWizardController >& i_rController,
45             const sal_Int16 i_nPageId )
46         :m_xController( i_rController )
47         ,m_xWizardPage()
48     {
49         ENSURE_OR_THROW( m_xController.is(), "no controller" );
50         try
51         {
52             // Plug a toplevel SalFrame into the native page which can host our awt widgetry
53             m_xWizardPage.set(m_xController->createPage(pParent->CreateChildFrame(), i_nPageId), UNO_SET_THROW);
54 
55             Reference< XWindow > xPageWindow(m_xWizardPage->getWindow(), UNO_SET_THROW);
56             xPageWindow->setVisible( true );
57         }
58         catch( const Exception& )
59         {
60             DBG_UNHANDLED_EXCEPTION("svtools.uno");
61         }
62     }
63 
~WizardPageController()64     WizardPageController::~WizardPageController()
65     {
66         try
67         {
68             if ( m_xWizardPage.is() )
69                 m_xWizardPage->dispose();
70         }
71         catch( const Exception& )
72         {
73             DBG_UNHANDLED_EXCEPTION("svtools.uno");
74         }
75     }
76 
initializePage()77     void WizardPageController::initializePage()
78     {
79         if ( !m_xWizardPage.is() )
80             return;
81 
82         try
83         {
84             m_xWizardPage->activatePage();
85         }
86         catch( const Exception& )
87         {
88             DBG_UNHANDLED_EXCEPTION("svtools.uno");
89         }
90     }
91 
commitPage(vcl::WizardTypes::CommitPageReason i_eReason)92     bool WizardPageController::commitPage( vcl::WizardTypes::CommitPageReason i_eReason )
93     {
94         if ( !m_xWizardPage.is() )
95             return true;
96 
97         try
98         {
99             return m_xWizardPage->commitPage( WizardShell::convertCommitReasonToTravelType( i_eReason ) );
100         }
101         catch( const Exception& )
102         {
103             DBG_UNHANDLED_EXCEPTION("svtools.uno");
104         }
105 
106         return true;
107     }
108 
canAdvance() const109     bool WizardPageController::canAdvance() const
110     {
111         if ( !m_xWizardPage.is() )
112             return true;
113 
114         try
115         {
116             return m_xWizardPage->canAdvance();
117         }
118         catch( const Exception& )
119         {
120             DBG_UNHANDLED_EXCEPTION("svtools.uno");
121         }
122 
123         return true;
124     }
125 
126 
127 } // namespace svt::uno
128 
129 
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
131