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::XWizard >& i_rWizard,
55             const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController >& i_rController,
56             const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_Int16 > >& i_rPaths
57         );
58         virtual ~WizardShell();
59 
60         // Dialog overridables
61 	    virtual short	Execute();
62 
63         // OWizardMachine overridables
64 		virtual TabPage*	createPage( WizardState i_nState );
65 	    virtual void        enterState( WizardState i_nState );
66 		virtual	sal_Bool	leaveState( WizardState i_nState );
67         virtual String      getStateDisplayName( WizardState i_nState ) const;
68         virtual bool        canAdvance() const;
69 		virtual sal_Bool    onFinish();
70 		virtual IWizardPageController*
71                             getPageController( TabPage* _pCurrentPage ) const;
72 
73         // attribute access
74         const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizard >&
getWizard() const75             getWizard() const { return m_xWizard; }
76 
77         static sal_Int16 convertCommitReasonToTravelType( const CommitPageReason i_eReason );
78 
79         // operations
advanceTo(const sal_Int16 i_nPageId)80         sal_Bool    advanceTo( const sal_Int16 i_nPageId )
81         {
82             return skipUntil( impl_pageIdToState( i_nPageId ) );
83         }
goBackTo(const sal_Int16 i_nPageId)84         sal_Bool    goBackTo( const sal_Int16 i_nPageId )
85         {
86             return skipBackwardUntil( impl_pageIdToState( i_nPageId ) );
87         }
travelNext()88 		sal_Bool    travelNext()        { return WizardShell_Base::travelNext(); }
travelPrevious()89 		sal_Bool    travelPrevious()    { return WizardShell_Base::travelPrevious(); }
90 
activatePath(const sal_Int16 i_nPathID,const sal_Bool i_bFinal)91         void        activatePath( const sal_Int16 i_nPathID, const sal_Bool i_bFinal )
92         {
93             WizardShell_Base::activatePath( PathId( i_nPathID ), i_bFinal );
94         }
95 
96         ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardPage >
97                     getCurrentWizardPage() const;
98 
getCurrentPage() const99         sal_Int16   getCurrentPage() const
100         {
101             return impl_stateToPageId( getCurrentState() );
102         }
103 
104         void        enablePage( const sal_Int16 i_PageID, const sal_Bool i_Enable );
105 
knowsPage(const sal_Int16 i_nPageID) const106         bool        knowsPage( const sal_Int16 i_nPageID ) const
107         {
108             return knowsState( impl_pageIdToState( i_nPageID ) );
109         }
110 
111     private:
impl_stateToPageId(const WizardTypes::WizardState i_nState) const112         sal_Int16   impl_stateToPageId( const WizardTypes::WizardState i_nState ) const
113         {
114             return static_cast< sal_Int16 >( i_nState + m_nFirstPageID );
115         }
116 
impl_pageIdToState(const sal_Int16 i_nPageId) const117         WizardState impl_pageIdToState( const sal_Int16 i_nPageId ) const
118         {
119             return static_cast< WizardState >( i_nPageId - m_nFirstPageID );
120         }
121 
122         PWizardPageController impl_getController( TabPage* i_pPage ) const;
123 
124         // prevent outside access to some base class members
125         using WizardShell_Base::skip;
126         using WizardShell_Base::skipUntil;
127         using WizardShell_Base::skipBackwardUntil;
128         using WizardShell_Base::getCurrentState;
129         using WizardShell_Base::activatePath;
130 
131     private:
132         typedef ::std::map< TabPage*, PWizardPageController > Page2ControllerMap;
133 
134         const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizard >            m_xWizard;
135         const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController >  m_xController;
136         const sal_Int16                                                                             m_nFirstPageID;
137         Page2ControllerMap                                                                          m_aPageControllers;
138 	};
139 
140 //......................................................................................................................
141 } } // namespace svt::uno
142 //......................................................................................................................
143 
144 #endif // SVT_UNO_WIZARD_SHELL
145