diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-09-14 18:40:21 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-09-15 16:25:57 +0200 |
commit | 04f326cee7678be86db3bb826f6f83918d7a239a (patch) | |
tree | 1f5093dab1883203594800325b01c694792395f3 | |
parent | bcaeebd98a697d6bcf891990c3b13de5da1790e7 (diff) |
merge RoadmapWizard and OWizardMachine
Change-Id: Ib8c68cb5e96f8bfa9b2398946b87f3b451b3a37e
Reviewed-on: https://gerrit.libreoffice.org/78912
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/vcl/roadmapwizard.hxx | 319 | ||||
-rw-r--r-- | include/vcl/wizardmachine.hxx | 301 | ||||
-rw-r--r-- | solenv/clang-format/blacklist | 1 | ||||
-rw-r--r-- | vcl/source/control/roadmapwizard.cxx | 219 | ||||
-rw-r--r-- | vcl/source/control/wizardmachine.cxx | 366 | ||||
-rw-r--r-- | vcl/source/control/wizimpldata.hxx | 64 |
6 files changed, 605 insertions, 665 deletions
diff --git a/include/vcl/roadmapwizard.hxx b/include/vcl/roadmapwizard.hxx index 9670c84dd13d..bae94ee05c1a 100644 --- a/include/vcl/roadmapwizard.hxx +++ b/include/vcl/roadmapwizard.hxx @@ -58,18 +58,118 @@ namespace vcl <code>n2</code>, which share at least the first <code>k</code> states (where <code>k</code> is at least 1), and an arbitrary number of other states. */ - class VCL_DLLPUBLIC RoadmapWizard : public vcl::OWizardMachine + class VCL_DLLPUBLIC RoadmapWizard : public ModalDialog { private: - std::unique_ptr<RoadmapWizardImpl> m_pImpl; + Idle maWizardLayoutIdle; + Size maPageSize; + ImplWizPageData* mpFirstPage; + ImplWizButtonData* mpFirstBtn; + VclPtr<TabPage> mpCurTabPage; + VclPtr<PushButton> mpPrevBtn; + VclPtr<PushButton> mpNextBtn; + VclPtr<vcl::Window> mpViewWindow; + sal_uInt16 mnCurLevel; + WindowAlign meViewAlign; + Link<RoadmapWizard*,void> maActivateHdl; + sal_Int16 mnLeftAlignCount; + bool mbEmptyViewMargin; + + DECL_DLLPRIVATE_LINK( ImplHandleWizardLayoutTimerHdl, Timer*, void ); + + // IMPORTANT: + // traveling pages should not be done by calling these base class member, some mechanisms of this class + // here (e.g. committing page data) depend on having full control over page traveling. + // So use the travelXXX methods if you need to travel + + protected: + long LogicalCoordinateToPixel(int iCoordinate); + /**sets the number of buttons which should be left-aligned. Normally, buttons are right-aligned. + + only to be used during construction, before any layouting happened + */ + void SetLeftAlignedButtonCount( sal_Int16 _nCount ); + /** declares the view area to have an empty margin + + Normally, the view area has a certain margin to the top/left/bottom/right of the + dialog. By calling this method, you can reduce this margin to 0. + */ + void SetEmptyViewMargin(); + + void CalcAndSetSize(); public: - RoadmapWizard( - vcl::Window* _pParent - ); + VclPtr<OKButton> m_pFinish; + VclPtr<CancelButton> m_pCancel; + VclPtr<PushButton> m_pNextPage; + VclPtr<PushButton> m_pPrevPage; + VclPtr<HelpButton> m_pHelp; + + private: + std::unique_ptr<WizardMachineImplData> m_xWizardImpl; + // hold members in this structure to allow keeping compatible when members are added + std::unique_ptr<RoadmapWizardImpl> m_xRoadmapImpl; + + public: + RoadmapWizard(vcl::Window* pParent); virtual ~RoadmapWizard( ) override; virtual void dispose() override; + virtual void Resize() override; + virtual void StateChanged( StateChangedType nStateChange ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + + virtual void ActivatePage(); + virtual bool DeactivatePage(); + + virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override; + + bool ShowPrevPage(); + bool ShowNextPage(); + bool ShowPage( sal_uInt16 nLevel ); + bool Finish( long nResult = 0 ); + sal_uInt16 GetCurLevel() const { return mnCurLevel; } + + void AddPage( TabPage* pPage ); + void RemovePage( TabPage* pPage ); + void SetPage( sal_uInt16 nLevel, TabPage* pPage ); + TabPage* GetPage( sal_uInt16 nLevel ) const; + + void AddButton( Button* pButton, long nOffset = 0 ); + void RemoveButton( Button* pButton ); + + void SetPrevButton( PushButton* pButton ) { mpPrevBtn = pButton; } + void SetNextButton( PushButton* pButton ) { mpNextBtn = pButton; } + + void SetViewWindow( vcl::Window* pWindow ) { mpViewWindow = pWindow; } + void SetViewAlign( WindowAlign eAlign ) { meViewAlign = eAlign; } + + void SetPageSizePixel( const Size& rSize ) { maPageSize = rSize; } + const Size& GetPageSizePixel() const { return maPageSize; } + + void SetActivatePageHdl( const Link<RoadmapWizard*,void>& rLink ) { maActivateHdl = rLink; } + + /// enable (or disable) buttons + void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable); + /// set the default style for a button + void defaultButton(WizardButtonFlags _nWizardButtonFlags); + /// set the default style for a button + void defaultButton(PushButton* _pNewDefButton); + + /// set the base of the title to use - the title of the current page is appended + void setTitleBase(const OUString& _rTitleBase); + + /// determines whether there is a next state to which we can advance + virtual bool canAdvance() const; + + /** updates the user interface which deals with traveling in the wizard + + The default implementation simply checks whether both the current page and the wizard + itself allow to advance to the next state (<code>canAdvance</code>), and enables the "Next" + button if and only if this is the case. + */ + virtual void updateTravelUI(); + void SetRoadmapHelpId( const OString& _rId ); void SetRoadmapInteractive( bool _bInteractive ); @@ -84,11 +184,136 @@ namespace vcl // returns whether a given state is enabled bool isStateEnabled( WizardTypes::WizardState _nState ) const; - // WizardDialog overridables - virtual bool canAdvance() const override; - virtual void updateTravelUI() override; - protected: + + /// to override to create new pages + virtual VclPtr<TabPage> createPage(WizardTypes::WizardState nState); + + /// will be called when a new page is about to be displayed + virtual void enterState(WizardTypes::WizardState _nState); + + /** will be called when the current state is about to be left for the given reason + + The base implementation in this class will simply call <member>OWizardPage::commitPage</member> + for the current page, and return whatever this call returns. + + @param _eReason + The reason why the state is to be left. + @return + <TRUE/> if and only if the page is allowed to be left + */ + virtual bool prepareLeaveCurrentState( WizardTypes::CommitPageReason eReason ); + + /** will be called when the given state is left + + This is the very last possibility for derived classes to veto the deactivation + of a page. + + @todo Normally, we would not need the return value here - derived classes now have + the possibility to veto page deactivations in <member>prepareLeaveCurrentState</member>. However, + changing this return type is too incompatible at the moment ... + + @return + <TRUE/> if and only if the page is allowed to be left + */ + virtual bool leaveState(WizardTypes::WizardState _nState); + + /** determine the next state to travel from the given one + + This method ensures that traveling happens along the active path. + + Return WZS_INVALID_STATE to prevent traveling. + + @see activatePath + */ + virtual WizardTypes::WizardState determineNextState(WizardTypes::WizardState nCurrentState) const; + + /** called when the finish button is pressed + <p>By default, only the base class' Finish method (which is not virtual) is called</p> + */ + virtual bool onFinish(); + + /// travel to the next state + bool travelNext(); + + /// travel to the previous state + bool travelPrevious(); + + /** enables the automatic enabled/disabled state of the "Next" button + + If this is <TRUE/>, then upon entering a new state, the "Next" button will automatically be + enabled if and only if determineNextState does not return WZS_INVALID_STATE. + */ + void enableAutomaticNextButtonState(); + bool isAutomaticNextButtonStateEnabled() const; + + /** removes a page from the history. Should be called when the page is being disabled + */ + void removePageFromHistory(WizardTypes::WizardState nToRemove); + + /** skip a state + + The method behaves as if from the current state, <arg>_nSteps</arg> <method>travelNext</method>s were + called, but without actually creating or displaying the \EDntermediate pages. Only the + (<arg>_nSteps</arg> + 1)th page is created. + + The skipped states appear in the state history, so <method>travelPrevious</method> will make use of them. + + A very essential precondition for using this method is that your <method>determineNextState</method> + method is able to determine the next state without actually having the page of the current state. + + @see skipUntil + @see skipBackwardUntil + */ + void skip(); + + /** skips one or more states, until a given state is reached + + The method behaves as if from the current state, <method>travelNext</method>s were called + successively, until <arg>_nTargetState</arg> is reached, but without actually creating or + displaying the \EDntermediate pages. + + The skipped states appear in the state history, so <method>travelPrevious</method> will make use of them. + + @return + <TRUE/> if and only if traveling was successful + + @see skip + @see skipBackwardUntil + */ + bool skipUntil(WizardTypes::WizardState nTargetState); + + /** moves back one or more states, until a given state is reached + + This method allows traveling backwards more than one state without actually showing the intermediate + states. + + For instance, if you want to travel two steps backward at a time, you could used + two travelPrevious calls, but this would <em>show</em> both pages, which is not necessary, + since you're interested in the target page only. Using <member>skipBackwardUntil</member> relieves + you of this. + + @return + <TRUE/> if and only if traveling was successful + + @see skipUntil + @see skip + */ + bool skipBackwardUntil(WizardTypes::WizardState nTargetState); + + /** returns the current state of the machine + + Vulgo, this is the identifier of the current tab page :) + */ + WizardTypes::WizardState getCurrentState() const { return GetCurLevel(); } + + virtual IWizardPageController* + getPageController( TabPage* _pCurrentPage ) const; + + /** retrieves a copy of the state history, i.e. all states we already visited + */ + void getStateHistory(std::vector<WizardTypes::WizardState>& out_rHistory); + /** declares a valid path in the wizard The very first path which is declared is automatically activated. @@ -141,15 +366,6 @@ namespace vcl */ void activatePath( RoadmapWizardTypes::PathId _nPathId, bool _bDecideForIt = false ); - /** determine the next state to travel from the given one - - This method (which is declared in OWizardMachine and overwritten here) - ensures that traveling happens along the active path. - - @see activatePath - */ - virtual WizardTypes::WizardState determineNextState(WizardTypes::WizardState nCurrentState) const override; - /** en- or disables a state In the wizard's roadmap, states to travel to can be freely chosen. To prevent @@ -176,9 +392,6 @@ namespace vcl */ bool knowsState(WizardTypes::WizardState nState) const; - // OWizardMachine overriables - virtual void enterState(WizardTypes::WizardState nState) override; - /** returns a human readable name for a given state There is a default implementation for this method, which returns the display name @@ -188,13 +401,6 @@ namespace vcl */ virtual OUString getStateDisplayName(WizardTypes::WizardState nState) const; - /** creates a page for a given state - - This member is inherited from OWizardMachine, and default-implemented in this class - for all states which have been described using describeState. - */ - virtual VclPtr<TabPage> createPage(WizardTypes::WizardState nState) override; - private: DECL_DLLPRIVATE_LINK( OnRoadmapItemSelected, LinkParamNone*, void ); @@ -203,8 +409,39 @@ namespace vcl */ VCL_DLLPRIVATE void implUpdateRoadmap( ); - private: VCL_DLLPRIVATE void impl_construct(); + + public: + class AccessGuard + { + friend class RoadmapWizardTravelSuspension; + private: + AccessGuard() { } + }; + + void suspendTraveling( AccessGuard ); + void resumeTraveling( AccessGuard ); + bool isTravelingSuspended() const; + + protected: + TabPage* GetOrCreatePage(const WizardTypes::WizardState i_nState); + + private: + VCL_DLLPRIVATE void ImplInitData(); + VCL_DLLPRIVATE void ImplCalcSize( Size& rSize ); + VCL_DLLPRIVATE void ImplPosCtrls(); + VCL_DLLPRIVATE void ImplPosTabPage(); + VCL_DLLPRIVATE void ImplShowTabPage( TabPage* pPage ); + VCL_DLLPRIVATE TabPage* ImplGetPage( sal_uInt16 nLevel ) const; + + + DECL_DLLPRIVATE_LINK(OnNextPage, Button*, void); + DECL_DLLPRIVATE_LINK(OnPrevPage, Button*, void); + DECL_DLLPRIVATE_LINK(OnFinish, Button*, void); + + VCL_DLLPRIVATE void implResetDefault(vcl::Window const * _pWindow); + VCL_DLLPRIVATE void implUpdateTitle(); + VCL_DLLPRIVATE void implConstruct( const WizardButtonFlags _nButtonFlags ); }; class VCL_DLLPUBLIC RoadmapWizardMachine : public vcl::WizardMachine @@ -280,7 +517,7 @@ namespace vcl /** determine the next state to travel from the given one - This method (which is declared in OWizardMachine and overwritten here) + This method (which is declared in WizardMachine and overwritten here) ensures that traveling happens along the active path. @see activatePath @@ -309,7 +546,7 @@ namespace vcl */ void enableState(WizardTypes::WizardState nState, bool _bEnable = true); - // OWizardMachine overriables + // WizardMachine overriables virtual void enterState(WizardTypes::WizardState nState) override; /** returns a human readable name for a given state @@ -330,6 +567,26 @@ namespace vcl VCL_DLLPRIVATE void implUpdateRoadmap( ); }; + /// helper class to temporarily suspend any traveling in the wizard + class RoadmapWizardTravelSuspension + { + public: + RoadmapWizardTravelSuspension(RoadmapWizard& rWizard) + : m_pOWizard(&rWizard) + { + m_pOWizard->suspendTraveling(RoadmapWizard::AccessGuard()); + } + + ~RoadmapWizardTravelSuspension() + { + if (m_pOWizard) + m_pOWizard->resumeTraveling(RoadmapWizard::AccessGuard()); + } + + private: + VclPtr<RoadmapWizard> m_pOWizard; + }; + } // namespace vcl diff --git a/include/vcl/wizardmachine.hxx b/include/vcl/wizardmachine.hxx index e3c4679953c2..b28d5c04123e 100644 --- a/include/vcl/wizardmachine.hxx +++ b/include/vcl/wizardmachine.hxx @@ -16,8 +16,8 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_SVTOOLS_WIZARDMACHINE_HXX -#define INCLUDED_SVTOOLS_WIZARDMACHINE_HXX +#ifndef INCLUDED_VCL_WIZARDMACHINE_HXX +#define INCLUDED_VCL_WIZARDMACHINE_HXX #include <memory> #include <vcl/dllapi.h> @@ -128,283 +128,6 @@ namespace vcl on the actual data presented in the wizard (e.g. checkboxes checked, or something like this), they can implement non-linear traveling this way. */ - class VCL_DLLPUBLIC OWizardMachine : public ModalDialog - { - private: - Idle maWizardLayoutIdle; - Size maPageSize; - ImplWizPageData* mpFirstPage; - ImplWizButtonData* mpFirstBtn; - VclPtr<TabPage> mpCurTabPage; - VclPtr<PushButton> mpPrevBtn; - VclPtr<PushButton> mpNextBtn; - VclPtr<vcl::Window> mpViewWindow; - sal_uInt16 mnCurLevel; - WindowAlign meViewAlign; - Link<OWizardMachine*,void> maActivateHdl; - sal_Int16 mnLeftAlignCount; - bool mbEmptyViewMargin; - - DECL_DLLPRIVATE_LINK( ImplHandleWizardLayoutTimerHdl, Timer*, void ); - - // TabPage* GetPage( sal_uInt16 nLevel ) const { return OWizardMachine::GetPage(nLevel); } - // TODO: probably the complete page handling (next, previous etc.) should be prohibited ... - - // IMPORTANT: - // traveling pages should not be done by calling these base class member, some mechanisms of this class - // here (e.g. committing page data) depend on having full control over page traveling. - // So use the travelXXX methods if you need to travel - - protected: - long LogicalCoordinateToPixel(int iCoordinate); - /**sets the number of buttons which should be left-aligned. Normally, buttons are right-aligned. - - only to be used during construction, before any layouting happened - */ - void SetLeftAlignedButtonCount( sal_Int16 _nCount ); - /** declares the view area to have an empty margin - - Normally, the view area has a certain margin to the top/left/bottom/right of the - dialog. By calling this method, you can reduce this margin to 0. - */ - void SetEmptyViewMargin(); - - void CalcAndSetSize(); - - - public: - VclPtr<OKButton> m_pFinish; - VclPtr<CancelButton> m_pCancel; - VclPtr<PushButton> m_pNextPage; - VclPtr<PushButton> m_pPrevPage; - VclPtr<HelpButton> m_pHelp; - - private: - // hold members in this structure to allow keeping compatible when members are added - std::unique_ptr<WizardMachineImplData> m_pImpl; - - public: - OWizardMachine(vcl::Window* _pParent, WizardButtonFlags _nButtonFlags ); - virtual ~OWizardMachine() override; - virtual void dispose() override; - - virtual void Resize() override; - virtual void StateChanged( StateChangedType nStateChange ) override; - virtual bool EventNotify( NotifyEvent& rNEvt ) override; - - virtual void ActivatePage(); - virtual bool DeactivatePage(); - - virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override; - - bool ShowPrevPage(); - bool ShowNextPage(); - bool ShowPage( sal_uInt16 nLevel ); - bool Finish( long nResult = 0 ); - sal_uInt16 GetCurLevel() const { return mnCurLevel; } - - void AddPage( TabPage* pPage ); - void RemovePage( TabPage* pPage ); - void SetPage( sal_uInt16 nLevel, TabPage* pPage ); - TabPage* GetPage( sal_uInt16 nLevel ) const; - - void AddButton( Button* pButton, long nOffset = 0 ); - void RemoveButton( Button* pButton ); - - void SetPrevButton( PushButton* pButton ) { mpPrevBtn = pButton; } - void SetNextButton( PushButton* pButton ) { mpNextBtn = pButton; } - - void SetViewWindow( vcl::Window* pWindow ) { mpViewWindow = pWindow; } - void SetViewAlign( WindowAlign eAlign ) { meViewAlign = eAlign; } - - void SetPageSizePixel( const Size& rSize ) { maPageSize = rSize; } - const Size& GetPageSizePixel() const { return maPageSize; } - - void SetActivatePageHdl( const Link<OWizardMachine*,void>& rLink ) { maActivateHdl = rLink; } - - /// enable (or disable) buttons - void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable); - /// set the default style for a button - void defaultButton(WizardButtonFlags _nWizardButtonFlags); - /// set the default style for a button - void defaultButton(PushButton* _pNewDefButton); - - /// set the base of the title to use - the title of the current page is appended - void setTitleBase(const OUString& _rTitleBase); - - /// determines whether there is a next state to which we can advance - virtual bool canAdvance() const; - - /** updates the user interface which deals with traveling in the wizard - - The default implementation simply checks whether both the current page and the wizard - itself allow to advance to the next state (<code>canAdvance</code>), and enables the "Next" - button if and only if this is the case. - */ - virtual void updateTravelUI(); - - protected: - // our own overridables - - /// to override to create new pages - virtual VclPtr<TabPage> createPage(WizardTypes::WizardState _nState) = 0; - - /// will be called when a new page is about to be displayed - virtual void enterState(WizardTypes::WizardState _nState); - - /** will be called when the current state is about to be left for the given reason - - The base implementation in this class will simply call <member>OWizardPage::commitPage</member> - for the current page, and return whatever this call returns. - - @param _eReason - The reason why the state is to be left. - @return - <TRUE/> if and only if the page is allowed to be left - */ - virtual bool prepareLeaveCurrentState( WizardTypes::CommitPageReason eReason ); - - /** will be called when the given state is left - - This is the very last possibility for derived classes to veto the deactivation - of a page. - - @todo Normally, we would not need the return value here - derived classes now have - the possibility to veto page deactivations in <member>prepareLeaveCurrentState</member>. However, - changing this return type is too incompatible at the moment ... - - @return - <TRUE/> if and only if the page is allowed to be left - */ - virtual bool leaveState(WizardTypes::WizardState _nState); - - /** determine the next state to travel from the given one - - The default behaviour is linear traveling, overwrite this to change it - - Return WZS_INVALID_STATE to prevent traveling. - */ - virtual WizardTypes::WizardState determineNextState(WizardTypes::WizardState nCurrentState) const; - - /** called when the finish button is pressed - <p>By default, only the base class' Finish method (which is not virtual) is called</p> - */ - virtual bool onFinish(); - - /// travel to the next state - bool travelNext(); - - /// travel to the previous state - bool travelPrevious(); - - /** enables the automatic enabled/disabled state of the "Next" button - - If this is <TRUE/>, then upon entering a new state, the "Next" button will automatically be - enabled if and only if determineNextState does not return WZS_INVALID_STATE. - */ - void enableAutomaticNextButtonState(); - bool isAutomaticNextButtonStateEnabled() const; - - /** removes a page from the history. Should be called when the page is being disabled - */ - void removePageFromHistory(WizardTypes::WizardState nToRemove); - - /** skip a state - - The method behaves as if from the current state, <arg>_nSteps</arg> <method>travelNext</method>s were - called, but without actually creating or displaying the \EDntermediate pages. Only the - (<arg>_nSteps</arg> + 1)th page is created. - - The skipped states appear in the state history, so <method>travelPrevious</method> will make use of them. - - A very essential precondition for using this method is that your <method>determineNextState</method> - method is able to determine the next state without actually having the page of the current state. - - @see skipUntil - @see skipBackwardUntil - */ - void skip(); - - /** skips one or more states, until a given state is reached - - The method behaves as if from the current state, <method>travelNext</method>s were called - successively, until <arg>_nTargetState</arg> is reached, but without actually creating or - displaying the \EDntermediate pages. - - The skipped states appear in the state history, so <method>travelPrevious</method> will make use of them. - - @return - <TRUE/> if and only if traveling was successful - - @see skip - @see skipBackwardUntil - */ - bool skipUntil(WizardTypes::WizardState nTargetState); - - /** moves back one or more states, until a given state is reached - - This method allows traveling backwards more than one state without actually showing the intermediate - states. - - For instance, if you want to travel two steps backward at a time, you could used - two travelPrevious calls, but this would <em>show</em> both pages, which is not necessary, - since you're interested in the target page only. Using <member>skipBackwardUntil</member> relieves - you of this. - - @return - <TRUE/> if and only if traveling was successful - - @see skipUntil - @see skip - */ - bool skipBackwardUntil(WizardTypes::WizardState nTargetState); - - /** returns the current state of the machine - - Vulgo, this is the identifier of the current tab page :) - */ - WizardTypes::WizardState getCurrentState() const { return GetCurLevel(); } - - virtual IWizardPageController* - getPageController( TabPage* _pCurrentPage ) const; - - /** retrieves a copy of the state history, i.e. all states we already visited - */ - void getStateHistory(std::vector<WizardTypes::WizardState>& out_rHistory); - - public: - class AccessGuard - { - friend class WizardTravelSuspension; - private: - AccessGuard() { } - }; - - void suspendTraveling( AccessGuard ); - void resumeTraveling( AccessGuard ); - bool isTravelingSuspended() const; - - protected: - TabPage* GetOrCreatePage(const WizardTypes::WizardState i_nState); - - private: - VCL_DLLPRIVATE void ImplInitData(); - VCL_DLLPRIVATE void ImplCalcSize( Size& rSize ); - VCL_DLLPRIVATE void ImplPosCtrls(); - VCL_DLLPRIVATE void ImplPosTabPage(); - VCL_DLLPRIVATE void ImplShowTabPage( TabPage* pPage ); - VCL_DLLPRIVATE TabPage* ImplGetPage( sal_uInt16 nLevel ) const; - - - DECL_DLLPRIVATE_LINK(OnNextPage, Button*, void); - DECL_DLLPRIVATE_LINK(OnPrevPage, Button*, void); - DECL_DLLPRIVATE_LINK(OnFinish, Button*, void); - - VCL_DLLPRIVATE void implResetDefault(vcl::Window const * _pWindow); - VCL_DLLPRIVATE void implUpdateTitle(); - VCL_DLLPRIVATE void implConstruct( const WizardButtonFlags _nButtonFlags ); - }; - class VCL_DLLPUBLIC WizardMachine : public weld::AssistantController { private: @@ -622,39 +345,25 @@ namespace vcl class WizardTravelSuspension { public: - WizardTravelSuspension(OWizardMachine& rWizard) - : m_pOWizard(&rWizard) - , m_pWizard(nullptr) - { - m_pOWizard->suspendTraveling(OWizardMachine::AccessGuard()); - } - WizardTravelSuspension(WizardMachine& rWizard) - : m_pOWizard(nullptr) - , m_pWizard(&rWizard) + : m_pWizard(&rWizard) { m_pWizard->suspendTraveling(WizardMachine::AccessGuard()); } ~WizardTravelSuspension() { - if (m_pOWizard) - m_pOWizard->resumeTraveling(OWizardMachine::AccessGuard()); - if (m_pWizard) - m_pWizard->resumeTraveling(WizardMachine::AccessGuard()); + m_pWizard->resumeTraveling(WizardMachine::AccessGuard()); } private: - VclPtr<OWizardMachine> m_pOWizard; WizardMachine* m_pWizard; }; - - } // namespace vcl #define WIZARDDIALOG_BUTTON_STDOFFSET_X 6 #define WIZARDDIALOG_BUTTON_SMALLSTDOFFSET_X 3 -#endif // INCLUDED_SVTOOLS_WIZARDMACHINE_HXX +#endif // INCLUDED_VCL_WIZARDMACHINE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist index eb44f9aeec41..510fdc225b1b 100644 --- a/solenv/clang-format/blacklist +++ b/solenv/clang-format/blacklist @@ -17762,6 +17762,7 @@ vcl/source/control/spinfld.cxx vcl/source/control/tabctrl.cxx vcl/source/control/throbber.cxx vcl/source/control/thumbpos.hxx +vcl/source/control/wizimpldata.hxx vcl/source/control/wizardmachine.cxx vcl/source/edit/textdat2.hxx vcl/source/edit/textdata.cxx diff --git a/vcl/source/control/roadmapwizard.cxx b/vcl/source/control/roadmapwizard.cxx index f1c49d546866..2e66d2ed4027 100644 --- a/vcl/source/control/roadmapwizard.cxx +++ b/vcl/source/control/roadmapwizard.cxx @@ -30,6 +30,7 @@ #include <map> #include <set> +#include "wizimpldata.hxx" namespace vcl { @@ -119,10 +120,20 @@ namespace vcl } //= RoadmapWizard - RoadmapWizard::RoadmapWizard( Window* _pParent ) - :OWizardMachine( _pParent, WizardButtonFlags::NEXT | WizardButtonFlags::PREVIOUS | WizardButtonFlags::FINISH | WizardButtonFlags::CANCEL | WizardButtonFlags::HELP ) - ,m_pImpl( new RoadmapWizardImpl ) + RoadmapWizard::RoadmapWizard(vcl::Window* pParent) + :ModalDialog(pParent, "WizardDialog", "svt/ui/wizarddialog.ui") + ,m_pFinish(nullptr) + ,m_pCancel(nullptr) + ,m_pNextPage(nullptr) + ,m_pPrevPage(nullptr) + ,m_pHelp(nullptr) + ,m_xWizardImpl(new WizardMachineImplData) + ,m_xRoadmapImpl(new RoadmapWizardImpl) { + ImplInitData(); + + implConstruct(WizardButtonFlags::NEXT | WizardButtonFlags::PREVIOUS | WizardButtonFlags::FINISH | WizardButtonFlags::CANCEL | WizardButtonFlags::HELP); + impl_construct(); } @@ -138,23 +149,23 @@ namespace vcl SetLeftAlignedButtonCount( 1 ); SetEmptyViewMargin(); - m_pImpl->pRoadmap.disposeAndReset( VclPtr<ORoadmap>::Create( this, WB_TABSTOP ) ); - m_pImpl->pRoadmap->SetText( VclResId( STR_WIZDLG_ROADMAP_TITLE ) ); - m_pImpl->pRoadmap->SetPosPixel( Point( 0, 0 ) ); - m_pImpl->pRoadmap->SetItemSelectHdl( LINK( this, RoadmapWizard, OnRoadmapItemSelected ) ); + m_xRoadmapImpl->pRoadmap.disposeAndReset( VclPtr<ORoadmap>::Create( this, WB_TABSTOP ) ); + m_xRoadmapImpl->pRoadmap->SetText( VclResId( STR_WIZDLG_ROADMAP_TITLE ) ); + m_xRoadmapImpl->pRoadmap->SetPosPixel( Point( 0, 0 ) ); + m_xRoadmapImpl->pRoadmap->SetItemSelectHdl( LINK( this, RoadmapWizard, OnRoadmapItemSelected ) ); Size aRoadmapSize = LogicToPixel(Size(85, 0), MapMode(MapUnit::MapAppFont)); aRoadmapSize.setHeight( GetSizePixel().Height() ); - m_pImpl->pRoadmap->SetSizePixel( aRoadmapSize ); + m_xRoadmapImpl->pRoadmap->SetSizePixel( aRoadmapSize ); - SetViewWindow( m_pImpl->pRoadmap ); + SetViewWindow( m_xRoadmapImpl->pRoadmap ); SetViewAlign( WindowAlign::Left ); - m_pImpl->pRoadmap->Show(); + m_xRoadmapImpl->pRoadmap->Show(); } void RoadmapWizard::ShowRoadmap(bool bShow) { - m_pImpl->pRoadmap->Show(bShow); + m_xRoadmapImpl->pRoadmap->Show(bShow); CalcAndSetSize(); } @@ -169,13 +180,45 @@ namespace vcl void RoadmapWizard::dispose() { - m_pImpl.reset(); - OWizardMachine::dispose(); + m_xRoadmapImpl.reset(); + + m_pFinish.disposeAndClear(); + m_pCancel.disposeAndClear(); + m_pNextPage.disposeAndClear(); + m_pPrevPage.disposeAndClear(); + m_pHelp.disposeAndClear(); + + if (m_xWizardImpl) + { + for (WizardTypes::WizardState i = 0; i < m_xWizardImpl->nFirstUnknownPage; ++i) + { + TabPage *pPage = GetPage(i); + if (pPage) + pPage->disposeOnce(); + } + m_xWizardImpl.reset(); + } + + maWizardLayoutIdle.Stop(); + + // Remove all buttons + while ( mpFirstBtn ) + RemoveButton( mpFirstBtn->mpButton ); + + // Remove all pages + while ( mpFirstPage ) + RemovePage( mpFirstPage->mpPage ); + + mpCurTabPage.clear(); + mpPrevBtn.clear(); + mpNextBtn.clear(); + mpViewWindow.clear(); + ModalDialog::dispose(); } void RoadmapWizard::SetRoadmapHelpId( const OString& _rId ) { - m_pImpl->pRoadmap->SetHelpId( _rId ); + m_xRoadmapImpl->pRoadmap->SetHelpId( _rId ); } void RoadmapWizardMachine::SetRoadmapHelpId(const OString& rId) @@ -185,15 +228,15 @@ namespace vcl void RoadmapWizard::SetRoadmapInteractive( bool _bInteractive ) { - m_pImpl->pRoadmap->SetRoadmapInteractive( _bInteractive ); + m_xRoadmapImpl->pRoadmap->SetRoadmapInteractive( _bInteractive ); } void RoadmapWizard::declarePath( PathId _nPathId, const WizardPath& _lWizardStates) { - m_pImpl->aPaths.emplace( _nPathId, _lWizardStates ); + m_xRoadmapImpl->aPaths.emplace( _nPathId, _lWizardStates ); - if ( m_pImpl->aPaths.size() == 1 ) + if ( m_xRoadmapImpl->aPaths.size() == 1 ) // the very first path -> activate it activatePath( _nPathId ); else @@ -202,7 +245,6 @@ namespace vcl void RoadmapWizardMachine::declarePath( PathId _nPathId, const WizardPath& _lWizardStates) { - m_pImpl->aPaths.emplace( _nPathId, _lWizardStates ); if ( m_pImpl->aPaths.size() == 1 ) @@ -215,20 +257,20 @@ namespace vcl void RoadmapWizard::activatePath( PathId _nPathId, bool _bDecideForIt ) { - if ( ( _nPathId == m_pImpl->nActivePath ) && ( _bDecideForIt == m_pImpl->bActivePathIsDefinite ) ) + if ( ( _nPathId == m_xRoadmapImpl->nActivePath ) && ( _bDecideForIt == m_xRoadmapImpl->bActivePathIsDefinite ) ) // nothing to do return; // does the given path exist? - Paths::const_iterator aNewPathPos = m_pImpl->aPaths.find( _nPathId ); - DBG_ASSERT( aNewPathPos != m_pImpl->aPaths.end(), "RoadmapWizard::activate: there is no such path!" ); - if ( aNewPathPos == m_pImpl->aPaths.end() ) + Paths::const_iterator aNewPathPos = m_xRoadmapImpl->aPaths.find( _nPathId ); + DBG_ASSERT( aNewPathPos != m_xRoadmapImpl->aPaths.end(), "RoadmapWizard::activate: there is no such path!" ); + if ( aNewPathPos == m_xRoadmapImpl->aPaths.end() ) return; // determine the index of the current state in the current path sal_Int32 nCurrentStatePathIndex = -1; - if ( m_pImpl->nActivePath != -1 ) - nCurrentStatePathIndex = m_pImpl->getStateIndexInPath( getCurrentState(), m_pImpl->nActivePath ); + if ( m_xRoadmapImpl->nActivePath != -1 ) + nCurrentStatePathIndex = m_xRoadmapImpl->getStateIndexInPath( getCurrentState(), m_xRoadmapImpl->nActivePath ); DBG_ASSERT( static_cast<sal_Int32>(aNewPathPos->second.size()) > nCurrentStatePathIndex, "RoadmapWizard::activate: you cannot activate a path which has less states than we've already advanced!" ); @@ -239,8 +281,8 @@ namespace vcl return; // assert that the current and the new path are equal, up to nCurrentStatePathIndex - Paths::const_iterator aActivePathPos = m_pImpl->aPaths.find( m_pImpl->nActivePath ); - if ( aActivePathPos != m_pImpl->aPaths.end() ) + Paths::const_iterator aActivePathPos = m_xRoadmapImpl->aPaths.find( m_xRoadmapImpl->nActivePath ); + if ( aActivePathPos != m_xRoadmapImpl->aPaths.end() ) { if ( RoadmapWizardImpl::getFirstDifferentIndex( aActivePathPos->second, aNewPathPos->second ) <= nCurrentStatePathIndex ) { @@ -249,8 +291,8 @@ namespace vcl } } - m_pImpl->nActivePath = _nPathId; - m_pImpl->bActivePathIsDefinite = _bDecideForIt; + m_xRoadmapImpl->nActivePath = _nPathId; + m_xRoadmapImpl->bActivePathIsDefinite = _bDecideForIt; implUpdateRoadmap( ); } @@ -299,10 +341,9 @@ namespace vcl void RoadmapWizard::implUpdateRoadmap( ) { - - DBG_ASSERT( m_pImpl->aPaths.find( m_pImpl->nActivePath ) != m_pImpl->aPaths.end(), + DBG_ASSERT( m_xRoadmapImpl->aPaths.find( m_xRoadmapImpl->nActivePath ) != m_xRoadmapImpl->aPaths.end(), "RoadmapWizard::implUpdateRoadmap: there is no such path!" ); - const WizardPath& rActivePath( m_pImpl->aPaths[ m_pImpl->nActivePath ] ); + const WizardPath& rActivePath( m_xRoadmapImpl->aPaths[ m_xRoadmapImpl->nActivePath ] ); sal_Int32 nCurrentStatePathIndex = RoadmapWizardImpl::getStateIndexInPath( getCurrentState(), rActivePath ); if (nCurrentStatePathIndex < 0) @@ -311,11 +352,11 @@ namespace vcl // determine up to which index (in the new path) we have to display the items RoadmapTypes::ItemIndex nUpperStepBoundary = static_cast<RoadmapTypes::ItemIndex>(rActivePath.size()); bool bIncompletePath = false; - if ( !m_pImpl->bActivePathIsDefinite ) + if ( !m_xRoadmapImpl->bActivePathIsDefinite ) { - for (auto const& path : m_pImpl->aPaths) + for (auto const& path : m_xRoadmapImpl->aPaths) { - if ( path.first == m_pImpl->nActivePath ) + if ( path.first == m_xRoadmapImpl->nActivePath ) // it's the path we are just activating -> no need to check anything continue; // the index from which on both paths differ @@ -344,10 +385,10 @@ namespace vcl // now, we have to remove all items after nCurrentStatePathIndex, and insert the items from the active // path, up to (excluding) nUpperStepBoundary - RoadmapTypes::ItemIndex nLoopUntil = ::std::max( nUpperStepBoundary, m_pImpl->pRoadmap->GetItemCount() ); + RoadmapTypes::ItemIndex nLoopUntil = ::std::max( nUpperStepBoundary, m_xRoadmapImpl->pRoadmap->GetItemCount() ); for ( RoadmapTypes::ItemIndex nItemIndex = nCurrentStatePathIndex; nItemIndex < nLoopUntil; ++nItemIndex ) { - bool bExistentItem = ( nItemIndex < m_pImpl->pRoadmap->GetItemCount() ); + bool bExistentItem = ( nItemIndex < m_xRoadmapImpl->pRoadmap->GetItemCount() ); bool bNeedItem = ( nItemIndex < nUpperStepBoundary ); bool bInsertItem = false; @@ -355,19 +396,19 @@ namespace vcl { if ( !bNeedItem ) { - while ( nItemIndex < m_pImpl->pRoadmap->GetItemCount() ) - m_pImpl->pRoadmap->DeleteRoadmapItem( nItemIndex ); + while ( nItemIndex < m_xRoadmapImpl->pRoadmap->GetItemCount() ) + m_xRoadmapImpl->pRoadmap->DeleteRoadmapItem( nItemIndex ); break; } else { // there is an item with this index in the roadmap - does it match what is requested by // the respective state in the active path? - RoadmapTypes::ItemId nPresentItemId = m_pImpl->pRoadmap->GetItemID( nItemIndex ); + RoadmapTypes::ItemId nPresentItemId = m_xRoadmapImpl->pRoadmap->GetItemID( nItemIndex ); WizardTypes::WizardState nRequiredState = rActivePath[ nItemIndex ]; if ( nPresentItemId != nRequiredState ) { - m_pImpl->pRoadmap->DeleteRoadmapItem( nItemIndex ); + m_xRoadmapImpl->pRoadmap->DeleteRoadmapItem( nItemIndex ); bInsertItem = true; } } @@ -381,7 +422,7 @@ namespace vcl WizardTypes::WizardState nState( rActivePath[ nItemIndex ] ); if ( bInsertItem ) { - m_pImpl->pRoadmap->InsertRoadmapItem( + m_xRoadmapImpl->pRoadmap->InsertRoadmapItem( nItemIndex, getStateDisplayName( nState ), nState, @@ -394,12 +435,12 @@ namespace vcl // from disabling all future states just because the current state does not // (yet) allow advancing. const bool bUnconditionedDisable = !bCurrentPageCanAdvance && ( nItemIndex > nCurrentStatePathIndex ); - const bool bEnable = !bUnconditionedDisable && ( m_pImpl->aDisabledStates.find( nState ) == m_pImpl->aDisabledStates.end() ); + const bool bEnable = !bUnconditionedDisable && ( m_xRoadmapImpl->aDisabledStates.find( nState ) == m_xRoadmapImpl->aDisabledStates.end() ); - m_pImpl->pRoadmap->EnableRoadmapItem( m_pImpl->pRoadmap->GetItemID( nItemIndex ), bEnable ); + m_xRoadmapImpl->pRoadmap->EnableRoadmapItem( m_xRoadmapImpl->pRoadmap->GetItemID( nItemIndex ), bEnable ); } - m_pImpl->pRoadmap->SetRoadmapComplete( !bIncompletePath ); + m_xRoadmapImpl->pRoadmap->SetRoadmapComplete( !bIncompletePath ); } void RoadmapWizardMachine::implUpdateRoadmap( ) @@ -509,11 +550,10 @@ namespace vcl WizardTypes::WizardState RoadmapWizard::determineNextState( WizardTypes::WizardState _nCurrentState ) const { - sal_Int32 nCurrentStatePathIndex = -1; - Paths::const_iterator aActivePathPos = m_pImpl->aPaths.find( m_pImpl->nActivePath ); - if ( aActivePathPos != m_pImpl->aPaths.end() ) + Paths::const_iterator aActivePathPos = m_xRoadmapImpl->aPaths.find( m_xRoadmapImpl->nActivePath ); + if ( aActivePathPos != m_xRoadmapImpl->aPaths.end() ) nCurrentStatePathIndex = RoadmapWizardImpl::getStateIndexInPath( _nCurrentState, aActivePathPos->second ); DBG_ASSERT( nCurrentStatePathIndex != -1, "RoadmapWizard::determineNextState: ehm - how can we travel if there is no (valid) active path?" ); @@ -523,7 +563,7 @@ namespace vcl sal_Int32 nNextStateIndex = nCurrentStatePathIndex + 1; while ( ( nNextStateIndex < static_cast<sal_Int32>(aActivePathPos->second.size()) ) - && ( m_pImpl->aDisabledStates.find( aActivePathPos->second[ nNextStateIndex ] ) != m_pImpl->aDisabledStates.end() ) + && ( m_xRoadmapImpl->aDisabledStates.find( aActivePathPos->second[ nNextStateIndex ] ) != m_xRoadmapImpl->aDisabledStates.end() ) ) { ++nNextStateIndex; @@ -566,14 +606,14 @@ namespace vcl bool RoadmapWizard::canAdvance() const { - if ( !m_pImpl->bActivePathIsDefinite ) + if ( !m_xRoadmapImpl->bActivePathIsDefinite ) { // check how many paths are still allowed - const WizardPath& rActivePath( m_pImpl->aPaths[ m_pImpl->nActivePath ] ); + const WizardPath& rActivePath( m_xRoadmapImpl->aPaths[ m_xRoadmapImpl->nActivePath ] ); sal_Int32 nCurrentStatePathIndex = RoadmapWizardImpl::getStateIndexInPath( getCurrentState(), rActivePath ); size_t nPossiblePaths(0); - for (auto const& path : m_pImpl->aPaths) + for (auto const& path : m_xRoadmapImpl->aPaths) { // the index from which on both paths differ sal_Int32 nDivergenceIndex = RoadmapWizardImpl::getFirstDifferentIndex( rActivePath, path.second ); @@ -590,7 +630,7 @@ namespace vcl return true; } - const WizardPath& rPath = m_pImpl->aPaths[ m_pImpl->nActivePath ]; + const WizardPath& rPath = m_xRoadmapImpl->aPaths[ m_xRoadmapImpl->nActivePath ]; return *rPath.rbegin() != getCurrentState(); } @@ -626,7 +666,13 @@ namespace vcl void RoadmapWizard::updateTravelUI() { - OWizardMachine::updateTravelUI(); + const IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) ); + OSL_ENSURE( pController != nullptr, "RoadmapWizard::updateTravelUI: no controller for the current page!" ); + + bool bCanAdvance = + ( !pController || pController->canAdvance() ) // the current page allows to advance + && canAdvance(); // the dialog as a whole allows to advance + enableButtons( WizardButtonFlags::NEXT, bCanAdvance ); // disable the "Previous" button if all states in our history are disabled std::vector< WizardTypes::WizardState > aHistory; @@ -670,8 +716,7 @@ namespace vcl IMPL_LINK_NOARG(RoadmapWizard, OnRoadmapItemSelected, LinkParamNone*, void) { - - RoadmapTypes::ItemId nCurItemId = m_pImpl->pRoadmap->GetCurrentRoadmapItemID(); + RoadmapTypes::ItemId nCurItemId = m_xRoadmapImpl->pRoadmap->GetCurrentRoadmapItemID(); if ( nCurItemId == getCurrentState() ) // nothing to do return; @@ -679,10 +724,10 @@ namespace vcl if ( isTravelingSuspended() ) return; - WizardTravelSuspension aTravelGuard( *this ); + RoadmapWizardTravelSuspension aTravelGuard( *this ); - sal_Int32 nCurrentIndex = m_pImpl->getStateIndexInPath( getCurrentState(), m_pImpl->nActivePath ); - sal_Int32 nNewIndex = m_pImpl->getStateIndexInPath( nCurItemId, m_pImpl->nActivePath ); + sal_Int32 nCurrentIndex = m_xRoadmapImpl->getStateIndexInPath( getCurrentState(), m_xRoadmapImpl->nActivePath ); + sal_Int32 nNewIndex = m_xRoadmapImpl->getStateIndexInPath( nCurItemId, m_xRoadmapImpl->nActivePath ); DBG_ASSERT( ( nCurrentIndex != -1 ) && ( nNewIndex != -1 ), "RoadmapWizard::OnRoadmapItemSelected: something's wrong here!" ); @@ -698,7 +743,7 @@ namespace vcl WizardTypes::WizardState nTemp = static_cast<WizardTypes::WizardState>(nCurItemId); while( nTemp ) { - if( m_pImpl->aDisabledStates.find( --nTemp ) != m_pImpl->aDisabledStates.end() ) + if( m_xRoadmapImpl->aDisabledStates.find( --nTemp ) != m_xRoadmapImpl->aDisabledStates.end() ) removePageFromHistory( nTemp ); } } @@ -706,7 +751,7 @@ namespace vcl bResult = skipBackwardUntil( static_cast<WizardTypes::WizardState>(nCurItemId) ); if ( !bResult ) - m_pImpl->pRoadmap->SelectRoadmapItemByID( getCurrentState() ); + m_xRoadmapImpl->pRoadmap->SelectRoadmapItemByID( getCurrentState() ); } IMPL_LINK(RoadmapWizardMachine, OnRoadmapItemSelected, const OString&, rCurItemId, bool) @@ -749,13 +794,26 @@ namespace vcl return bResult; } - void RoadmapWizard::enterState( WizardTypes::WizardState _nState ) + void RoadmapWizard::enterState(WizardTypes::WizardState nState) { - OWizardMachine::enterState( _nState ); + // tell the page + IWizardPageController* pController = getPageController( GetPage( nState ) ); + if (pController) + { + pController->initializePage(); + + if ( isAutomaticNextButtonStateEnabled() ) + enableButtons( WizardButtonFlags::NEXT, canAdvance() ); + + enableButtons( WizardButtonFlags::PREVIOUS, !m_xWizardImpl->aStateHistory.empty() ); + + // set the new title - it depends on the current page (i.e. state) + implUpdateTitle(); + } // synchronize the roadmap implUpdateRoadmap( ); - m_pImpl->pRoadmap->SelectRoadmapItemByID( getCurrentState() ); + m_xRoadmapImpl->pRoadmap->SelectRoadmapItemByID( getCurrentState() ); } void RoadmapWizardMachine::enterState( WizardTypes::WizardState _nState ) @@ -770,10 +828,10 @@ namespace vcl { OUString sDisplayName; - StateDescriptions::const_iterator pos = m_pImpl->aStateDescriptors.find( _nState ); - OSL_ENSURE( pos != m_pImpl->aStateDescriptors.end(), + StateDescriptions::const_iterator pos = m_xRoadmapImpl->aStateDescriptors.find( _nState ); + OSL_ENSURE( pos != m_xRoadmapImpl->aStateDescriptors.end(), "RoadmapWizard::getStateDisplayName: no default implementation available for this state!" ); - if ( pos != m_pImpl->aStateDescriptors.end() ) + if ( pos != m_xRoadmapImpl->aStateDescriptors.end() ) sDisplayName = pos->second.first; return sDisplayName; @@ -796,10 +854,10 @@ namespace vcl { VclPtr<TabPage> pPage; - StateDescriptions::const_iterator pos = m_pImpl->aStateDescriptors.find( _nState ); - OSL_ENSURE( pos != m_pImpl->aStateDescriptors.end(), + StateDescriptions::const_iterator pos = m_xRoadmapImpl->aStateDescriptors.find( _nState ); + OSL_ENSURE( pos != m_xRoadmapImpl->aStateDescriptors.end(), "RoadmapWizard::createPage: no default implementation available for this state!" ); - if ( pos != m_pImpl->aStateDescriptors.end() ) + if ( pos != m_xRoadmapImpl->aStateDescriptors.end() ) { RoadmapPageFactory pFactory = pos->second.second; pPage = (*pFactory)( *this ); @@ -810,18 +868,17 @@ namespace vcl void RoadmapWizard::enableState( WizardTypes::WizardState _nState, bool _bEnable ) { - // remember this (in case the state appears in the roadmap later on) if ( _bEnable ) - m_pImpl->aDisabledStates.erase( _nState ); + m_xRoadmapImpl->aDisabledStates.erase( _nState ); else { - m_pImpl->aDisabledStates.insert( _nState ); + m_xRoadmapImpl->aDisabledStates.insert( _nState ); removePageFromHistory( _nState ); } // if the state is currently in the roadmap, reflect it's new status - m_pImpl->pRoadmap->EnableRoadmapItem( static_cast<RoadmapTypes::ItemId>(_nState), _bEnable ); + m_xRoadmapImpl->pRoadmap->EnableRoadmapItem( static_cast<RoadmapTypes::ItemId>(_nState), _bEnable ); } void RoadmapWizardMachine::enableState( WizardTypes::WizardState _nState, bool _bEnable ) @@ -841,7 +898,7 @@ namespace vcl bool RoadmapWizard::knowsState( WizardTypes::WizardState i_nState ) const { - for (auto const& path : m_pImpl->aPaths) + for (auto const& path : m_xRoadmapImpl->aPaths) { for (auto const& state : path.second) { @@ -854,7 +911,7 @@ namespace vcl bool RoadmapWizard::isStateEnabled( WizardTypes::WizardState _nState ) const { - return m_pImpl->aDisabledStates.find( _nState ) == m_pImpl->aDisabledStates.end(); + return m_xRoadmapImpl->aDisabledStates.find( _nState ) == m_xRoadmapImpl->aDisabledStates.end(); } bool RoadmapWizardMachine::isStateEnabled( WizardTypes::WizardState _nState ) const @@ -864,28 +921,28 @@ namespace vcl void RoadmapWizard::InsertRoadmapItem(int nItemIndex, const OUString& rText, int nItemId, bool bEnable) { - m_pImpl->pRoadmap->InsertRoadmapItem(nItemIndex, rText, nItemId, bEnable); + m_xRoadmapImpl->pRoadmap->InsertRoadmapItem(nItemIndex, rText, nItemId, bEnable); } void RoadmapWizard::SelectRoadmapItemByID(int nItemId) { - m_pImpl->pRoadmap->SelectRoadmapItemByID(nItemId); + m_xRoadmapImpl->pRoadmap->SelectRoadmapItemByID(nItemId); } void RoadmapWizard::DeleteRoadmapItems() { - while (m_pImpl->pRoadmap->GetItemCount()) - m_pImpl->pRoadmap->DeleteRoadmapItem(0); + while (m_xRoadmapImpl->pRoadmap->GetItemCount()) + m_xRoadmapImpl->pRoadmap->DeleteRoadmapItem(0); } void RoadmapWizard::SetItemSelectHdl( const Link<LinkParamNone*,void>& _rHdl ) { - m_pImpl->pRoadmap->SetItemSelectHdl(_rHdl); + m_xRoadmapImpl->pRoadmap->SetItemSelectHdl(_rHdl); } int RoadmapWizard::GetCurrentRoadmapItemID() const { - return m_pImpl->pRoadmap->GetCurrentRoadmapItemID(); + return m_xRoadmapImpl->pRoadmap->GetCurrentRoadmapItemID(); } } // namespace vcl diff --git a/vcl/source/control/wizardmachine.cxx b/vcl/source/control/wizardmachine.cxx index e620fe731838..f8f6753074cd 100644 --- a/vcl/source/control/wizardmachine.cxx +++ b/vcl/source/control/wizardmachine.cxx @@ -19,12 +19,13 @@ #include <vcl/event.hxx> #include <vcl/svapp.hxx> -#include <vcl/wizardmachine.hxx> +#include <vcl/roadmapwizard.hxx> #include <tools/debug.hxx> #include <tools/diagnose_ex.h> #include <strings.hrc> #include <svdata.hxx> #include <stack> +#include "wizimpldata.hxx" #define HID_WIZARD_NEXT "SVT_HID_WIZARD_NEXT" #define HID_WIZARD_PREVIOUS "SVT_HID_WIZARD_PREVIOUS" @@ -34,19 +35,6 @@ #define WIZARDDIALOG_VIEW_DLGOFFSET_X 6 #define WIZARDDIALOG_VIEW_DLGOFFSET_Y 6 -struct ImplWizPageData -{ - ImplWizPageData* mpNext; - VclPtr<TabPage> mpPage; -}; - -struct ImplWizButtonData -{ - ImplWizButtonData* mpNext; - VclPtr<Button> mpButton; - long mnOffset; -}; - namespace vcl { //= WizardPageImplData @@ -87,7 +75,7 @@ namespace vcl void OWizardPage::updateDialogTravelUI() { - OWizardMachine* pWizardMachine = dynamic_cast< OWizardMachine* >( GetParent() ); + RoadmapWizard* pWizardMachine = dynamic_cast<RoadmapWizard*>(GetParent()); if ( pWizardMachine ) pWizardMachine->updateTravelUI(); } @@ -102,28 +90,7 @@ namespace vcl return true; } - struct WizardMachineImplData - { - OUString sTitleBase; // the base for the title - std::stack<WizardTypes::WizardState> aStateHistory; // the history of all states (used for implementing "Back") - - WizardTypes::WizardState nFirstUnknownPage; - // the WizardDialog does not allow non-linear transitions (e.g. it's - // not possible to add pages in a non-linear order), so we need some own maintenance data - - bool m_bAutoNextButtonState; - - bool m_bTravelingSuspended; - - WizardMachineImplData() - :nFirstUnknownPage( 0 ) - ,m_bAutoNextButtonState( false ) - ,m_bTravelingSuspended( false ) - { - } - }; - - void OWizardMachine::ImplInitData() + void RoadmapWizard::ImplInitData() { mpFirstPage = nullptr; mpFirstBtn = nullptr; @@ -137,20 +104,20 @@ namespace vcl mnLeftAlignCount = 0; maWizardLayoutIdle.SetPriority(TaskPriority::RESIZE); - maWizardLayoutIdle.SetInvokeHandler( LINK( this, OWizardMachine, ImplHandleWizardLayoutTimerHdl ) ); + maWizardLayoutIdle.SetInvokeHandler( LINK( this, RoadmapWizard, ImplHandleWizardLayoutTimerHdl ) ); } - void OWizardMachine::SetLeftAlignedButtonCount( sal_Int16 _nCount ) + void RoadmapWizard::SetLeftAlignedButtonCount( sal_Int16 _nCount ) { mnLeftAlignCount = _nCount; } - void OWizardMachine::SetEmptyViewMargin() + void RoadmapWizard::SetEmptyViewMargin() { mbEmptyViewMargin = true; } - void OWizardMachine::ImplCalcSize( Size& rSize ) + void RoadmapWizard::ImplCalcSize( Size& rSize ) { // calculate ButtonBar height long nMaxHeight = 0; @@ -181,7 +148,7 @@ namespace vcl } } - void OWizardMachine::queue_resize(StateChangedType /*eReason*/) + void RoadmapWizard::queue_resize(StateChangedType /*eReason*/) { if (maWizardLayoutIdle.IsActive()) return; @@ -190,13 +157,13 @@ namespace vcl maWizardLayoutIdle.Start(); } - IMPL_LINK_NOARG(OWizardMachine, ImplHandleWizardLayoutTimerHdl, Timer*, void) + IMPL_LINK_NOARG(RoadmapWizard, ImplHandleWizardLayoutTimerHdl, Timer*, void) { ImplPosCtrls(); ImplPosTabPage(); } - void OWizardMachine::ImplPosCtrls() + void RoadmapWizard::ImplPosCtrls() { Size aDlgSize = GetOutputSizePixel(); long nBtnWidth = 0; @@ -304,13 +271,13 @@ namespace vcl nViewPosFlags ); } - long OWizardMachine::LogicalCoordinateToPixel(int iCoordinate){ + long RoadmapWizard::LogicalCoordinateToPixel(int iCoordinate){ Size aLocSize = LogicToPixel(Size(iCoordinate, 0), MapMode(MapUnit::MapAppFont)); int iPixelCoordinate = aLocSize.Width(); return iPixelCoordinate; } - void OWizardMachine::ImplPosTabPage() + void RoadmapWizard::ImplPosTabPage() { if ( !mpCurTabPage ) return; @@ -364,7 +331,7 @@ namespace vcl mpCurTabPage->SetPosSizePixel( aPos, aDlgSize ); } - void OWizardMachine::ImplShowTabPage( TabPage* pTabPage ) + void RoadmapWizard::ImplShowTabPage( TabPage* pTabPage ) { if ( mpCurTabPage == pTabPage ) return; @@ -385,7 +352,7 @@ namespace vcl pOldTabPage->Hide(); } - TabPage* OWizardMachine::ImplGetPage( sal_uInt16 nLevel ) const + TabPage* RoadmapWizard::ImplGetPage( sal_uInt16 nLevel ) const { sal_uInt16 nTempLevel = 0; ImplWizPageData* pPageData = mpFirstPage; @@ -403,23 +370,9 @@ namespace vcl return nullptr; } - OWizardMachine::OWizardMachine(vcl::Window* pParent, WizardButtonFlags _nButtonFlags) - :ModalDialog(pParent, "WizardDialog", "svt/ui/wizarddialog.ui") - ,m_pFinish(nullptr) - ,m_pCancel(nullptr) - ,m_pNextPage(nullptr) - ,m_pPrevPage(nullptr) - ,m_pHelp(nullptr) - ,m_pImpl( new WizardMachineImplData ) - { - ImplInitData(); - - implConstruct( _nButtonFlags ); - } - - void OWizardMachine::implConstruct( const WizardButtonFlags _nButtonFlags ) + void RoadmapWizard::implConstruct( const WizardButtonFlags _nButtonFlags ) { - m_pImpl->sTitleBase = GetText(); + m_xWizardImpl->sTitleBase = GetText(); // create the buttons according to the wizard button flags // the help button @@ -446,7 +399,7 @@ namespace vcl else AddButton( m_pPrevPage, WIZARDDIALOG_BUTTON_STDOFFSET_X ); SetPrevButton( m_pPrevPage ); - m_pPrevPage->SetClickHdl( LINK( this, OWizardMachine, OnPrevPage ) ); + m_pPrevPage->SetClickHdl( LINK( this, RoadmapWizard, OnPrevPage ) ); } // the next button @@ -461,7 +414,7 @@ namespace vcl AddButton( m_pNextPage, WIZARDDIALOG_BUTTON_STDOFFSET_X ); SetNextButton( m_pNextPage ); - m_pNextPage->SetClickHdl( LINK( this, OWizardMachine, OnNextPage ) ); + m_pNextPage->SetClickHdl( LINK( this, RoadmapWizard, OnNextPage ) ); } // the finish button @@ -474,7 +427,7 @@ namespace vcl m_pFinish->set_id("finish"); AddButton( m_pFinish, WIZARDDIALOG_BUTTON_STDOFFSET_X ); - m_pFinish->SetClickHdl( LINK( this, OWizardMachine, OnFinish ) ); + m_pFinish->SetClickHdl( LINK( this, RoadmapWizard, OnFinish ) ); } // the cancel button @@ -488,49 +441,7 @@ namespace vcl } } - - OWizardMachine::~OWizardMachine() - { - disposeOnce(); - } - - void OWizardMachine::dispose() - { - m_pFinish.disposeAndClear(); - m_pCancel.disposeAndClear(); - m_pNextPage.disposeAndClear(); - m_pPrevPage.disposeAndClear(); - m_pHelp.disposeAndClear(); - - if (m_pImpl) - { - for (WizardTypes::WizardState i = 0; i < m_pImpl->nFirstUnknownPage; ++i) - { - TabPage *pPage = GetPage(i); - if (pPage) - pPage->disposeOnce(); - } - m_pImpl.reset(); - } - - maWizardLayoutIdle.Stop(); - - // Remove all buttons - while ( mpFirstBtn ) - RemoveButton( mpFirstBtn->mpButton ); - - // Remove all pages - while ( mpFirstPage ) - RemovePage( mpFirstPage->mpPage ); - - mpCurTabPage.clear(); - mpPrevBtn.clear(); - mpNextBtn.clear(); - mpViewWindow.clear(); - ModalDialog::dispose(); - } - - void OWizardMachine::Resize() + void RoadmapWizard::Resize() { if ( IsReallyShown() && !IsInInitShow() ) { @@ -541,9 +452,9 @@ namespace vcl ModalDialog::Resize(); } - void OWizardMachine::implUpdateTitle() + void RoadmapWizard::implUpdateTitle() { - OUString sCompleteTitle(m_pImpl->sTitleBase); + OUString sCompleteTitle(m_xWizardImpl->sTitleBase); // append the page title TabPage* pCurrentPage = GetPage(getCurrentState()); @@ -555,7 +466,7 @@ namespace vcl SetText(sCompleteTitle); } - void OWizardMachine::CalcAndSetSize() + void RoadmapWizard::CalcAndSetSize() { Size aDlgSize = GetPageSizePixel(); if ( !aDlgSize.Width() || !aDlgSize.Height() ) @@ -579,7 +490,7 @@ namespace vcl SetOutputSizePixel( aDlgSize ); } - void OWizardMachine::StateChanged( StateChangedType nType ) + void RoadmapWizard::StateChanged( StateChangedType nType ) { if ( nType == StateChangedType::InitShow ) { @@ -596,7 +507,7 @@ namespace vcl ModalDialog::StateChanged( nType ); } - bool OWizardMachine::EventNotify( NotifyEvent& rNEvt ) + bool RoadmapWizard::EventNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && mpPrevBtn && mpNextBtn ) { @@ -640,32 +551,31 @@ namespace vcl return ModalDialog::EventNotify( rNEvt ); } - void OWizardMachine::setTitleBase(const OUString& _rTitleBase) + void RoadmapWizard::setTitleBase(const OUString& _rTitleBase) { - m_pImpl->sTitleBase = _rTitleBase; + m_xWizardImpl->sTitleBase = _rTitleBase; implUpdateTitle(); } - - TabPage* OWizardMachine::GetOrCreatePage( const WizardTypes::WizardState i_nState ) + TabPage* RoadmapWizard::GetOrCreatePage( const WizardTypes::WizardState i_nState ) { if ( nullptr == GetPage( i_nState ) ) { VclPtr<TabPage> pNewPage = createPage( i_nState ); - DBG_ASSERT( pNewPage, "OWizardMachine::GetOrCreatePage: invalid new page (NULL)!" ); + DBG_ASSERT( pNewPage, "RoadmapWizard::GetOrCreatePage: invalid new page (NULL)!" ); // fill up the page sequence of our base class (with dummies) - while ( m_pImpl->nFirstUnknownPage < i_nState ) + while ( m_xWizardImpl->nFirstUnknownPage < i_nState ) { AddPage( nullptr ); - ++m_pImpl->nFirstUnknownPage; + ++m_xWizardImpl->nFirstUnknownPage; } - if ( m_pImpl->nFirstUnknownPage == i_nState ) + if ( m_xWizardImpl->nFirstUnknownPage == i_nState ) { // encountered this page number the first time AddPage( pNewPage ); - ++m_pImpl->nFirstUnknownPage; + ++m_xWizardImpl->nFirstUnknownPage; } else // already had this page - just change it @@ -674,7 +584,7 @@ namespace vcl return GetPage( i_nState ); } - void OWizardMachine::ActivatePage() + void RoadmapWizard::ActivatePage() { maActivateHdl.Call( this ); @@ -684,13 +594,13 @@ namespace vcl enterState( nCurrentLevel ); } - bool OWizardMachine::DeactivatePage() + bool RoadmapWizard::DeactivatePage() { WizardTypes::WizardState nCurrentState = getCurrentState(); return leaveState(nCurrentState); } - void OWizardMachine::defaultButton(WizardButtonFlags _nWizardButtonFlags) + void RoadmapWizard::defaultButton(WizardButtonFlags _nWizardButtonFlags) { // the new default button PushButton* pNewDefButton = nullptr; @@ -711,19 +621,19 @@ namespace vcl implResetDefault( this ); } - bool OWizardMachine::ShowNextPage() + bool RoadmapWizard::ShowNextPage() { return ShowPage( mnCurLevel+1 ); } - bool OWizardMachine::ShowPrevPage() + bool RoadmapWizard::ShowPrevPage() { if ( !mnCurLevel ) return false; return ShowPage( mnCurLevel-1 ); } - bool OWizardMachine::ShowPage( sal_uInt16 nLevel ) + bool RoadmapWizard::ShowPage( sal_uInt16 nLevel ) { if ( DeactivatePage() ) { @@ -736,7 +646,7 @@ namespace vcl return false; } - bool OWizardMachine::Finish( long nResult ) + bool RoadmapWizard::Finish( long nResult ) { if ( DeactivatePage() ) { @@ -753,7 +663,7 @@ namespace vcl return false; } - void OWizardMachine::AddPage( TabPage* pPage ) + void RoadmapWizard::AddPage( TabPage* pPage ) { ImplWizPageData* pNewPageData = new ImplWizPageData; pNewPageData->mpNext = nullptr; @@ -770,7 +680,7 @@ namespace vcl } } - void OWizardMachine::RemovePage( TabPage* pPage ) + void RoadmapWizard::RemovePage( TabPage* pPage ) { ImplWizPageData* pPrevPageData = nullptr; ImplWizPageData* pPageData = mpFirstPage; @@ -792,10 +702,10 @@ namespace vcl pPageData = pPageData->mpNext; } - OSL_FAIL( "OWizardMachine::RemovePage() - Page not in list" ); + OSL_FAIL( "RoadmapWizard::RemovePage() - Page not in list" ); } - void OWizardMachine::SetPage( sal_uInt16 nLevel, TabPage* pPage ) + void RoadmapWizard::SetPage( sal_uInt16 nLevel, TabPage* pPage ) { sal_uInt16 nTempLevel = 0; ImplWizPageData* pPageData = mpFirstPage; @@ -816,7 +726,7 @@ namespace vcl } } - TabPage* OWizardMachine::GetPage( sal_uInt16 nLevel ) const + TabPage* RoadmapWizard::GetPage( sal_uInt16 nLevel ) const { sal_uInt16 nTempLevel = 0; @@ -831,7 +741,7 @@ namespace vcl return nullptr; } - void OWizardMachine::AddButton( Button* pButton, long nOffset ) + void RoadmapWizard::AddButton( Button* pButton, long nOffset ) { ImplWizButtonData* pNewBtnData = new ImplWizButtonData; pNewBtnData->mpNext = nullptr; @@ -849,7 +759,7 @@ namespace vcl } } - void OWizardMachine::RemoveButton( Button* pButton ) + void RoadmapWizard::RemoveButton( Button* pButton ) { ImplWizButtonData* pPrevBtnData = nullptr; ImplWizButtonData* pBtnData = mpFirstBtn; @@ -869,10 +779,10 @@ namespace vcl pBtnData = pBtnData->mpNext; } - OSL_FAIL( "OWizardMachine::RemoveButton() - Button not in list" ); + OSL_FAIL( "RoadmapWizard::RemoveButton() - Button not in list" ); } - void OWizardMachine::implResetDefault(vcl::Window const * _pWindow) + void RoadmapWizard::implResetDefault(vcl::Window const * _pWindow) { vcl::Window* pChildLoop = _pWindow->GetWindow(GetWindowType::FirstChild); while (pChildLoop) @@ -900,8 +810,7 @@ namespace vcl } } - - void OWizardMachine::defaultButton(PushButton* _pNewDefButton) + void RoadmapWizard::defaultButton(PushButton* _pNewDefButton) { // loop through all (direct and indirect) descendants which participate in our tabbing order, and // reset the WB_DEFBUTTON for every window which is a button @@ -912,8 +821,7 @@ namespace vcl _pNewDefButton->SetStyle(_pNewDefButton->GetStyle() | WB_DEFBUTTON); } - - void OWizardMachine::enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable) + void RoadmapWizard::enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable) { if (m_pFinish && (_nWizardButtonFlags & WizardButtonFlags::FINISH)) m_pFinish->Enable(_bEnable); @@ -927,24 +835,7 @@ namespace vcl m_pCancel->Enable(_bEnable); } - void OWizardMachine::enterState(WizardTypes::WizardState nState) - { - // tell the page - IWizardPageController* pController = getPageController( GetPage( nState ) ); - if (!pController) - return; - pController->initializePage(); - - if ( isAutomaticNextButtonStateEnabled() ) - enableButtons( WizardButtonFlags::NEXT, canAdvance() ); - - enableButtons( WizardButtonFlags::PREVIOUS, !m_pImpl->aStateHistory.empty() ); - - // set the new title - it depends on the current page (i.e. state) - implUpdateTitle(); - } - - bool OWizardMachine::leaveState(WizardTypes::WizardState) + bool RoadmapWizard::leaveState(WizardTypes::WizardState) { // no need to ask the page here. // If we reach this point, we already gave the current page the chance to commit it's data, @@ -953,18 +844,16 @@ namespace vcl return true; } - - bool OWizardMachine::onFinish() + bool RoadmapWizard::onFinish() { return Finish( RET_OK ); } - - IMPL_LINK_NOARG(OWizardMachine, OnFinish, Button*, void) + IMPL_LINK_NOARG(RoadmapWizard, OnFinish, Button*, void) { if ( isTravelingSuspended() ) return; - WizardTravelSuspension aTravelGuard( *this ); + RoadmapWizardTravelSuspension aTravelGuard( *this ); if (!prepareLeaveCurrentState(WizardTypes::eFinish)) { return; @@ -972,47 +861,40 @@ namespace vcl onFinish(); } - WizardTypes::WizardState OWizardMachine::determineNextState( WizardTypes::WizardState _nCurrentState ) const - { - return _nCurrentState + 1; - } - - bool OWizardMachine::prepareLeaveCurrentState( WizardTypes::CommitPageReason _eReason ) + bool RoadmapWizard::prepareLeaveCurrentState( WizardTypes::CommitPageReason _eReason ) { IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) ); - ENSURE_OR_RETURN( pController != nullptr, "OWizardMachine::prepareLeaveCurrentState: no controller for the current page!", true ); + ENSURE_OR_RETURN( pController != nullptr, "RoadmapWizard::prepareLeaveCurrentState: no controller for the current page!", true ); return pController->commitPage( _eReason ); } - - bool OWizardMachine::skipBackwardUntil( WizardTypes::WizardState _nTargetState ) + bool RoadmapWizard::skipBackwardUntil( WizardTypes::WizardState _nTargetState ) { // allowed to leave the current page? if (!prepareLeaveCurrentState(WizardTypes::eTravelBackward)) return false; - // don't travel directly on m_pImpl->aStateHistory, in case something goes wrong - std::stack< WizardTypes::WizardState > aTravelVirtually = m_pImpl->aStateHistory; - std::stack< WizardTypes::WizardState > aOldStateHistory = m_pImpl->aStateHistory; + // don't travel directly on m_xWizardImpl->aStateHistory, in case something goes wrong + std::stack< WizardTypes::WizardState > aTravelVirtually = m_xWizardImpl->aStateHistory; + std::stack< WizardTypes::WizardState > aOldStateHistory = m_xWizardImpl->aStateHistory; WizardTypes::WizardState nCurrentRollbackState = getCurrentState(); while ( nCurrentRollbackState != _nTargetState ) { - DBG_ASSERT( !aTravelVirtually.empty(), "OWizardMachine::skipBackwardUntil: this target state does not exist in the history!" ); + DBG_ASSERT( !aTravelVirtually.empty(), "RoadmapWizard::skipBackwardUntil: this target state does not exist in the history!" ); nCurrentRollbackState = aTravelVirtually.top(); aTravelVirtually.pop(); } - m_pImpl->aStateHistory = aTravelVirtually; + m_xWizardImpl->aStateHistory = aTravelVirtually; if ( !ShowPage( _nTargetState ) ) { - m_pImpl->aStateHistory = aOldStateHistory; + m_xWizardImpl->aStateHistory = aOldStateHistory; return false; } return true; } - - bool OWizardMachine::skipUntil( WizardTypes::WizardState _nTargetState ) + bool RoadmapWizard::skipUntil( WizardTypes::WizardState _nTargetState ) { WizardTypes::WizardState nCurrentState = getCurrentState(); @@ -1020,15 +902,15 @@ namespace vcl if ( !prepareLeaveCurrentState( nCurrentState < _nTargetState ? WizardTypes::eTravelForward : WizardTypes::eTravelBackward ) ) return false; - // don't travel directly on m_pImpl->aStateHistory, in case something goes wrong - std::stack< WizardTypes::WizardState > aTravelVirtually = m_pImpl->aStateHistory; - std::stack< WizardTypes::WizardState > aOldStateHistory = m_pImpl->aStateHistory; + // don't travel directly on m_xWizardImpl->aStateHistory, in case something goes wrong + std::stack< WizardTypes::WizardState > aTravelVirtually = m_xWizardImpl->aStateHistory; + std::stack< WizardTypes::WizardState > aOldStateHistory = m_xWizardImpl->aStateHistory; while ( nCurrentState != _nTargetState ) { WizardTypes::WizardState nNextState = determineNextState( nCurrentState ); if ( WZS_INVALID_STATE == nNextState ) { - OSL_FAIL( "OWizardMachine::skipUntil: the given target state does not exist!" ); + OSL_FAIL( "RoadmapWizard::skipUntil: the given target state does not exist!" ); return false; } @@ -1038,21 +920,20 @@ namespace vcl // get the next state nCurrentState = nNextState; } - m_pImpl->aStateHistory = aTravelVirtually; + m_xWizardImpl->aStateHistory = aTravelVirtually; // show the target page if ( !ShowPage( nCurrentState ) ) { // argh! prepareLeaveCurrentPage succeeded, determineNextState succeeded, // but ShowPage doesn't? Somebody behaves very strange here... - OSL_FAIL( "OWizardMachine::skipUntil: very unpolite..." ); - m_pImpl->aStateHistory = aOldStateHistory; + OSL_FAIL( "RoadmapWizard::skipUntil: very unpolite..." ); + m_xWizardImpl->aStateHistory = aOldStateHistory; return false; } return true; } - - void OWizardMachine::skip() + void RoadmapWizard::skip() { // allowed to leave the current page? if ( !prepareLeaveCurrentState( WizardTypes::eTravelForward ) ) @@ -1065,7 +946,7 @@ namespace vcl return; // remember the skipped state in the history - m_pImpl->aStateHistory.push(nCurrentState); + m_xWizardImpl->aStateHistory.push(nCurrentState); // get the next state nCurrentState = nNextState; @@ -1075,7 +956,7 @@ namespace vcl { // TODO: this leaves us in a state where we have no current page and an inconsistent state history. // Perhaps we should rollback the skipping here... - OSL_FAIL("OWizardMachine::skip: very unpolite..."); + OSL_FAIL("RoadmapWizard::skip: very unpolite..."); // if somebody does a skip and then does not allow to leave... // (can't be a commit error, as we've already committed the current page. So if ShowPage fails here, // somebody behaves really strange...) @@ -1085,7 +966,7 @@ namespace vcl // all fine } - bool OWizardMachine::travelNext() + bool RoadmapWizard::travelNext() { // allowed to leave the current page? if ( !prepareLeaveCurrentState( WizardTypes::eTravelForward ) ) @@ -1099,34 +980,33 @@ namespace vcl // the state history is used by the enterState method // all fine - m_pImpl->aStateHistory.push(nCurrentState); + m_xWizardImpl->aStateHistory.push(nCurrentState); if (!ShowPage(nNextState)) { - m_pImpl->aStateHistory.pop(); + m_xWizardImpl->aStateHistory.pop(); return false; } return true; } - - bool OWizardMachine::travelPrevious() + bool RoadmapWizard::travelPrevious() { - DBG_ASSERT(!m_pImpl->aStateHistory.empty(), "OWizardMachine::travelPrevious: have no previous page!"); + DBG_ASSERT(!m_xWizardImpl->aStateHistory.empty(), "RoadmapWizard::travelPrevious: have no previous page!"); // allowed to leave the current page? if ( !prepareLeaveCurrentState( WizardTypes::eTravelBackward ) ) return false; // the next state to switch to - WizardTypes::WizardState nPreviousState = m_pImpl->aStateHistory.top(); + WizardTypes::WizardState nPreviousState = m_xWizardImpl->aStateHistory.top(); // the state history is used by the enterState method - m_pImpl->aStateHistory.pop(); + m_xWizardImpl->aStateHistory.pop(); // show this page if (!ShowPage(nPreviousState)) { - m_pImpl->aStateHistory.push(nPreviousState); + m_xWizardImpl->aStateHistory.push(nPreviousState); return false; } @@ -1134,15 +1014,14 @@ namespace vcl return true; } - - void OWizardMachine::removePageFromHistory( WizardTypes::WizardState nToRemove ) + void RoadmapWizard::removePageFromHistory( WizardTypes::WizardState nToRemove ) { std::stack< WizardTypes::WizardState > aTemp; - while(!m_pImpl->aStateHistory.empty()) + while(!m_xWizardImpl->aStateHistory.empty()) { - WizardTypes::WizardState nPreviousState = m_pImpl->aStateHistory.top(); - m_pImpl->aStateHistory.pop(); + WizardTypes::WizardState nPreviousState = m_xWizardImpl->aStateHistory.top(); + m_xWizardImpl->aStateHistory.pop(); if(nPreviousState != nToRemove) aTemp.push( nPreviousState ); else @@ -1150,52 +1029,46 @@ namespace vcl } while(!aTemp.empty()) { - m_pImpl->aStateHistory.push( aTemp.top() ); + m_xWizardImpl->aStateHistory.push( aTemp.top() ); aTemp.pop(); } } - - void OWizardMachine::enableAutomaticNextButtonState() + void RoadmapWizard::enableAutomaticNextButtonState() { - m_pImpl->m_bAutoNextButtonState = true; + m_xWizardImpl->m_bAutoNextButtonState = true; } - - bool OWizardMachine::isAutomaticNextButtonStateEnabled() const + bool RoadmapWizard::isAutomaticNextButtonStateEnabled() const { - return m_pImpl->m_bAutoNextButtonState; + return m_xWizardImpl->m_bAutoNextButtonState; } - - IMPL_LINK_NOARG(OWizardMachine, OnPrevPage, Button*, void) + IMPL_LINK_NOARG(RoadmapWizard, OnPrevPage, Button*, void) { if ( isTravelingSuspended() ) return; - WizardTravelSuspension aTravelGuard( *this ); + RoadmapWizardTravelSuspension aTravelGuard( *this ); travelPrevious(); } - - IMPL_LINK_NOARG(OWizardMachine, OnNextPage, Button*, void) + IMPL_LINK_NOARG(RoadmapWizard, OnNextPage, Button*, void) { if ( isTravelingSuspended() ) return; - WizardTravelSuspension aTravelGuard( *this ); + RoadmapWizardTravelSuspension aTravelGuard( *this ); travelNext(); } - - IWizardPageController* OWizardMachine::getPageController( TabPage* _pCurrentPage ) const + IWizardPageController* RoadmapWizard::getPageController( TabPage* _pCurrentPage ) const { IWizardPageController* pController = dynamic_cast< IWizardPageController* >( _pCurrentPage ); return pController; } - - void OWizardMachine::getStateHistory( std::vector< WizardTypes::WizardState >& _out_rHistory ) + void RoadmapWizard::getStateHistory( std::vector< WizardTypes::WizardState >& _out_rHistory ) { - std::stack< WizardTypes::WizardState > aHistoryCopy( m_pImpl->aStateHistory ); + std::stack< WizardTypes::WizardState > aHistoryCopy( m_xWizardImpl->aStateHistory ); while ( !aHistoryCopy.empty() ) { _out_rHistory.push_back( aHistoryCopy.top() ); @@ -1203,42 +1076,21 @@ namespace vcl } } - - bool OWizardMachine::canAdvance() const - { - return WZS_INVALID_STATE != determineNextState( getCurrentState() ); - } - - - void OWizardMachine::updateTravelUI() - { - const IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) ); - OSL_ENSURE( pController != nullptr, "RoadmapWizard::updateTravelUI: no controller for the current page!" ); - - bool bCanAdvance = - ( !pController || pController->canAdvance() ) // the current page allows to advance - && canAdvance(); // the dialog as a whole allows to advance - enableButtons( WizardButtonFlags::NEXT, bCanAdvance ); - } - - - bool OWizardMachine::isTravelingSuspended() const + bool RoadmapWizard::isTravelingSuspended() const { - return m_pImpl->m_bTravelingSuspended; + return m_xWizardImpl->m_bTravelingSuspended; } - - void OWizardMachine::suspendTraveling( AccessGuard ) + void RoadmapWizard::suspendTraveling( AccessGuard ) { - DBG_ASSERT( !m_pImpl->m_bTravelingSuspended, "OWizardMachine::suspendTraveling: already suspended!" ); - m_pImpl->m_bTravelingSuspended = true; + DBG_ASSERT( !m_xWizardImpl->m_bTravelingSuspended, "RoadmapWizard::suspendTraveling: already suspended!" ); + m_xWizardImpl->m_bTravelingSuspended = true; } - - void OWizardMachine::resumeTraveling( AccessGuard ) + void RoadmapWizard::resumeTraveling( AccessGuard ) { - DBG_ASSERT( m_pImpl->m_bTravelingSuspended, "OWizardMachine::resumeTraveling: nothing to resume!" ); - m_pImpl->m_bTravelingSuspended = false; + DBG_ASSERT( m_xWizardImpl->m_bTravelingSuspended, "RoadmapWizard::resumeTraveling: nothing to resume!" ); + m_xWizardImpl->m_bTravelingSuspended = false; } WizardMachine::WizardMachine(weld::Window* pParent, WizardButtonFlags nButtonFlags) @@ -1579,7 +1431,7 @@ namespace vcl { // TODO: this leaves us in a state where we have no current page and an inconsistent state history. // Perhaps we should rollback the skipping here... - OSL_FAIL("OWizardMachine::skip: very unpolite..."); + OSL_FAIL("RoadmapWizard::skip: very unpolite..."); // if somebody does a skip and then does not allow to leave... // (can't be a commit error, as we've already committed the current page. So if ShowPage fails here, // somebody behaves really strange ...) diff --git a/vcl/source/control/wizimpldata.hxx b/vcl/source/control/wizimpldata.hxx new file mode 100644 index 000000000000..d61805167576 --- /dev/null +++ b/vcl/source/control/wizimpldata.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_VCL_SOURCE_CONTROL_WIZIMPLDATA_HXX +#define INCLUDED_VCL_SOURCE_CONTROL_WIZIMPLDATA_HXX + +#include <stack> + +struct ImplWizPageData +{ + ImplWizPageData* mpNext; + VclPtr<TabPage> mpPage; +}; + +struct ImplWizButtonData +{ + ImplWizButtonData* mpNext; + VclPtr<Button> mpButton; + long mnOffset; +}; + +namespace vcl +{ + struct WizardMachineImplData + { + OUString sTitleBase; // the base for the title + std::stack<WizardTypes::WizardState> aStateHistory; // the history of all states (used for implementing "Back") + + WizardTypes::WizardState nFirstUnknownPage; + // the WizardDialog does not allow non-linear transitions (e.g. it's + // not possible to add pages in a non-linear order), so we need some own maintenance data + + bool m_bAutoNextButtonState; + + bool m_bTravelingSuspended; + + WizardMachineImplData() + :nFirstUnknownPage( 0 ) + ,m_bAutoNextButtonState( false ) + ,m_bTravelingSuspended( false ) + { + } + }; +} // namespace svt + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |