summaryrefslogtreecommitdiff
path: root/include/vcl/wizardmachine.hxx
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-08-05 17:26:53 +0100
committerCaolán McNamara <caolanm@redhat.com>2019-08-22 16:37:16 +0200
commit69057064d8957804c76e623d57c103c3413b7cbc (patch)
tree8026201f2750300a3b9f831a04dcc34016d54a95 /include/vcl/wizardmachine.hxx
parente724f245e9652230d4c1f58c353be150006affcd (diff)
weld ODbTypeWizDialogSetup
split up RoadmapWizard to sit its wizard logic on top of a a native GtkAssistant a) awkwardly GtkAssistant is not a GtkDialog, but derives directly from GtkWindow so some shuffling around required due to that b) hidden/unused pages are shuffled to the end of the list of pages and their titles turned off in order to hide them from the roadmap c) some nonstandard hackery required to get the gtk roadmap titles to wrap Change-Id: I0d2346c489fef744136a2785f33c846d97bd8dc6 Reviewed-on: https://gerrit.libreoffice.org/76876 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'include/vcl/wizardmachine.hxx')
-rw-r--r--include/vcl/wizardmachine.hxx251
1 files changed, 228 insertions, 23 deletions
diff --git a/include/vcl/wizardmachine.hxx b/include/vcl/wizardmachine.hxx
index 0b0afbce1576..c840af3f0745 100644
--- a/include/vcl/wizardmachine.hxx
+++ b/include/vcl/wizardmachine.hxx
@@ -31,20 +31,6 @@ namespace weld {
class Container;
}
-enum class WizardButtonFlags
-{
- NONE = 0x0000,
- NEXT = 0x0001,
- PREVIOUS = 0x0002,
- FINISH = 0x0004,
- CANCEL = 0x0008,
- HELP = 0x0010,
-};
-namespace o3tl
-{
- template<> struct typed_flags<WizardButtonFlags> : is_typed_flags<WizardButtonFlags, 0x001f> {};
-}
-
namespace vcl
{
@@ -152,9 +138,6 @@ namespace vcl
class VCL_DLLPUBLIC OWizardMachine : public WizardDialog, public WizardTypes
{
private:
- // restrict access to some aspects of our base class
- using WizardDialog::AddPage;
- using WizardDialog::SetPage;
// TabPage* GetPage( sal_uInt16 nLevel ) const { return WizardDialog::GetPage(nLevel); }
// TODO: probably the complete page handling (next, previous etc.) should be prohibited ...
@@ -163,7 +146,7 @@ namespace vcl
// 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:
+ public:
VclPtr<OKButton> m_pFinish;
VclPtr<CancelButton> m_pCancel;
VclPtr<PushButton> m_pNextPage;
@@ -358,23 +341,245 @@ namespace vcl
VCL_DLLPRIVATE void implConstruct( const WizardButtonFlags _nButtonFlags );
};
+ class VCL_DLLPUBLIC WizardMachine : public weld::AssistantController, public WizardTypes
+ {
+ private:
+ VclPtr<TabPage> m_xCurTabPage;
+
+ WizardState m_nCurState;
+ ImplWizPageData* m_pFirstPage;
+
+ protected:
+ std::unique_ptr<weld::Button> m_xFinish;
+ std::unique_ptr<weld::Button> m_xCancel;
+ std::unique_ptr<weld::Button> m_xNextPage;
+ std::unique_ptr<weld::Button> m_xPrevPage;
+ std::unique_ptr<weld::Button> m_xHelp;
+
+ private:
+ // hold members in this structure to allow keeping compatible when members are added
+ std::unique_ptr<WizardMachineImplData> m_pImpl;
+
+ public:
+ WizardMachine(weld::Window* _pParent, WizardButtonFlags _nButtonFlags );
+ virtual ~WizardMachine() override;
+
+ bool Finish(short nResult = RET_CANCEL);
+ bool ShowPage(WizardState nState);
+
+ void AddPage( TabPage* pPage );
+ void SetPage( WizardState nLevel, TabPage* pPage );
+ TabPage* GetPage( WizardState eState ) const;
+
+ /// 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(weld::Button* _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:
+ // WizardDialog overridables
+ virtual void ActivatePage();
+ virtual bool DeactivatePage();
+
+ // our own overridables
+
+ /// to override to create new pages
+ virtual VclPtr<TabPage> createPage(WizardState _nState) = 0;
+
+ /// will be called when a new page is about to be displayed
+ virtual void enterState(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( 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( 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 WizardState determineNextState( 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( 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( 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( WizardState _nTargetState );
+
+ /** returns the current state of the machine
+
+ Vulgo, this is the identifier of the current tab page :)
+ */
+ WizardState getCurrentState() const { return m_nCurState; }
+
+ virtual IWizardPageController*
+ getPageController( TabPage* _pCurrentPage ) const;
+
+ /** retrieves a copy of the state history, i.e. all states we already visited
+ */
+ void getStateHistory( ::std::vector< WizardState >& _out_rHistory );
+
+ public:
+ class AccessGuard
+ {
+ friend class WizardTravelSuspension;
+ private:
+ AccessGuard() { }
+ };
+
+ void suspendTraveling( AccessGuard );
+ void resumeTraveling( AccessGuard );
+ bool isTravelingSuspended() const;
+
+ protected:
+ TabPage* GetOrCreatePage( const WizardState i_nState );
+
+ private:
+ DECL_DLLPRIVATE_LINK(OnNextPage, weld::Button&, void);
+ DECL_DLLPRIVATE_LINK(OnPrevPage, weld::Button&, void);
+ DECL_DLLPRIVATE_LINK(OnFinish, weld::Button&, void);
+ DECL_DLLPRIVATE_LINK(OnCancel, weld::Button&, void);
+
+ VCL_DLLPRIVATE void implUpdateTitle();
+ VCL_DLLPRIVATE void implConstruct( const WizardButtonFlags _nButtonFlags );
+ };
+
+
/// helper class to temporarily suspend any traveling in the wizard
class WizardTravelSuspension
{
public:
- WizardTravelSuspension( OWizardMachine& _rWizard )
- :m_rWizard( _rWizard )
+ WizardTravelSuspension(OWizardMachine& rWizard)
+ : m_pOWizard(&rWizard)
+ , m_pWizard(nullptr)
+ {
+ m_pOWizard->suspendTraveling(OWizardMachine::AccessGuard());
+ }
+
+ WizardTravelSuspension(WizardMachine& rWizard)
+ : m_pOWizard(nullptr)
+ , m_pWizard(&rWizard)
{
- m_rWizard.suspendTraveling( OWizardMachine::AccessGuard() );
+ m_pWizard->suspendTraveling(WizardMachine::AccessGuard());
}
~WizardTravelSuspension()
{
- m_rWizard.resumeTraveling( OWizardMachine::AccessGuard() );
+ if (m_pOWizard)
+ m_pOWizard->resumeTraveling(OWizardMachine::AccessGuard());
+ if (m_pWizard)
+ m_pWizard->resumeTraveling(WizardMachine::AccessGuard());
}
private:
- OWizardMachine& m_rWizard;
+ VclPtr<OWizardMachine> m_pOWizard;
+ WizardMachine* m_pWizard;
};