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 #ifndef SVT_UNO_WIZARD_SHELL
25 #define SVT_UNO_WIZARD_SHELL
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/ui/dialogs/XWizardController.hpp>
29 #include <com/sun/star/ui/dialogs/XWizard.hpp>
30 /** === end UNO includes === **/
31 
32 #include <svtools/roadmapwizard.hxx>
33 
34 #include <boost/shared_ptr.hpp>
35 #include <map>
36 
37 //......................................................................................................................
38 namespace svt { namespace uno
39 {
40 //......................................................................................................................
41 
42     class WizardPageController;
43     typedef ::boost::shared_ptr< WizardPageController > PWizardPageController;
44 
45 	//==================================================================================================================
46 	//= WizardShell
47 	//==================================================================================================================
48     typedef ::svt::RoadmapWizard    WizardShell_Base;
49     class WizardShell : public WizardShell_Base
50 	{
51     public:
52         WizardShell(
53             Window* _pParent,
54             const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController >& i_rController,
55             const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_Int16 > >& i_rPaths
56         );
57         virtual ~WizardShell();
58 
59         // Dialog overridables
60 	    virtual short	Execute();
61 
62         // OWizardMachine overridables
63 		virtual TabPage*	createPage( WizardState i_nState );
64 	    virtual void        enterState( WizardState i_nState );
65 		virtual	sal_Bool	leaveState( WizardState i_nState );
66         virtual String      getStateDisplayName( WizardState i_nState ) const;
67         virtual bool        canAdvance() const;
68 		virtual sal_Bool    onFinish();
69 		virtual IWizardPageController*
70                             getPageController( TabPage* _pCurrentPage ) const;
71 
72         static sal_Int16 convertCommitReasonToTravelType( const CommitPageReason i_eReason );
73 
74         // operations
advanceTo(const sal_Int16 i_nPageId)75         sal_Bool    advanceTo( const sal_Int16 i_nPageId )
76         {
77             return skipUntil( impl_pageIdToState( i_nPageId ) );
78         }
goBackTo(const sal_Int16 i_nPageId)79         sal_Bool    goBackTo( const sal_Int16 i_nPageId )
80         {
81             return skipBackwardUntil( impl_pageIdToState( i_nPageId ) );
82         }
travelNext()83 		sal_Bool    travelNext()        { return WizardShell_Base::travelNext(); }
travelPrevious()84 		sal_Bool    travelPrevious()    { return WizardShell_Base::travelPrevious(); }
85 
activatePath(const sal_Int16 i_nPathID,const sal_Bool i_bFinal)86         void        activatePath( const sal_Int16 i_nPathID, const sal_Bool i_bFinal )
87         {
88             WizardShell_Base::activatePath( PathId( i_nPathID ), i_bFinal );
89         }
90 
91         ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardPage >
92                     getCurrentWizardPage() const;
93 
getCurrentPage() const94         sal_Int16   getCurrentPage() const
95         {
96             return impl_stateToPageId( getCurrentState() );
97         }
98 
99         void        enablePage( const sal_Int16 i_PageID, const sal_Bool i_Enable );
100 
knowsPage(const sal_Int16 i_nPageID) const101         bool        knowsPage( const sal_Int16 i_nPageID ) const
102         {
103             return knowsState( impl_pageIdToState( i_nPageID ) );
104         }
105 
106     private:
impl_stateToPageId(const WizardTypes::WizardState i_nState) const107         sal_Int16   impl_stateToPageId( const WizardTypes::WizardState i_nState ) const
108         {
109             return static_cast< sal_Int16 >( i_nState + m_nFirstPageID );
110         }
111 
impl_pageIdToState(const sal_Int16 i_nPageId) const112         WizardState impl_pageIdToState( const sal_Int16 i_nPageId ) const
113         {
114             return static_cast< WizardState >( i_nPageId - m_nFirstPageID );
115         }
116 
117         PWizardPageController impl_getController( TabPage* i_pPage ) const;
118 
119         // prevent outside access to some base class members
120         using WizardShell_Base::skip;
121         using WizardShell_Base::skipUntil;
122         using WizardShell_Base::skipBackwardUntil;
123         using WizardShell_Base::getCurrentState;
124         using WizardShell_Base::activatePath;
125 
126     private:
127         typedef ::std::map< TabPage*, PWizardPageController > Page2ControllerMap;
128 
129         const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController >  m_xController;
130         const sal_Int16                                                                             m_nFirstPageID;
131         Page2ControllerMap                                                                          m_aPageControllers;
132 	};
133 
134 //......................................................................................................................
135 } } // namespace svt::uno
136 //......................................................................................................................
137 
138 #endif // SVT_UNO_WIZARD_SHELL
139