/* -*- 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 .
*/
constbool bHideHelp = comphelper::LibreOfficeKit::isActive() &&
officecfg::Office::Common::Help::HelpRootURL::get().isEmpty(); // create the buttons according to the wizard button flags // the help button if (nButtonFlags & WizardButtonFlags::HELP && !bHideHelp)
m_xHelp->show(); else
m_xHelp->hide();
// the previous button if (nButtonFlags & WizardButtonFlags::PREVIOUS)
{
m_xPrevPage->set_help_id( HID_WIZARD_PREVIOUS );
m_xPrevPage->show();
// fill up the page sequence of our base class (with dummies) while ( m_pImpl->nFirstUnknownPage < i_nState )
{
AddPage( nullptr );
++m_pImpl->nFirstUnknownPage;
}
if ( m_pImpl->nFirstUnknownPage == i_nState )
{ // encountered this page number the first time
AddPage(std::move(xNewPage));
++m_pImpl->nFirstUnknownPage;
} else // already had this page - just change it
SetPage(i_nState, std::move(xNewPage));
} return GetPage( i_nState );
}
void WizardMachine::defaultButton(WizardButtonFlags _nWizardButtonFlags)
{ // the new default button
weld::Button* pNewDefButton = nullptr; if (_nWizardButtonFlags & WizardButtonFlags::FINISH)
pNewDefButton = m_xFinish.get(); if (_nWizardButtonFlags & WizardButtonFlags::NEXT)
pNewDefButton = m_xNextPage.get(); if (_nWizardButtonFlags & WizardButtonFlags::PREVIOUS)
pNewDefButton = m_xPrevPage.get(); if (_nWizardButtonFlags & WizardButtonFlags::HELP)
pNewDefButton = m_xHelp.get(); if (_nWizardButtonFlags & WizardButtonFlags::CANCEL)
pNewDefButton = m_xCancel.get();
defaultButton(pNewDefButton);
}
void WizardMachine::defaultButton(weld::Button* _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 and set _pNewDefButton as the new // WB_DEFBUTTON
m_xAssistant->change_default_widget(nullptr, _pNewDefButton);
}
void WizardMachine::enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
{ if (_nWizardButtonFlags & WizardButtonFlags::FINISH)
m_xFinish->set_sensitive(_bEnable); if (_nWizardButtonFlags & WizardButtonFlags::NEXT)
m_xNextPage->set_sensitive(_bEnable); if (_nWizardButtonFlags & WizardButtonFlags::PREVIOUS)
m_xPrevPage->set_sensitive(_bEnable); if (_nWizardButtonFlags & WizardButtonFlags::HELP)
m_xHelp->set_sensitive(_bEnable); if (_nWizardButtonFlags & WizardButtonFlags::CANCEL)
m_xCancel->set_sensitive(_bEnable);
}
void WizardMachine::enterState(WizardTypes::WizardState _nState)
{ // tell the page
IWizardPageController* pController = getPageController( GetPage( _nState ) );
OSL_ENSURE( pController, "WizardMachine::enterState: no controller for the given page!" ); if ( pController )
pController->initializePage();
if ( isAutomaticNextButtonStateEnabled() )
enableButtons( WizardButtonFlags::NEXT, canAdvance() );
// set the new title - it depends on the current page (i.e. state)
implUpdateTitle();
}
bool WizardMachine::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, // and it was allowed to commit it's data
IMPL_LINK_NOARG(WizardMachine, OnFinish, weld::Button&, void)
{ if ( isTravelingSuspended() ) return;
// prevent WizardTravelSuspension from using this instance // after will be destructed due to onFinish and async response call
{
WizardTravelSuspension aTravelGuard( *this ); if (!prepareLeaveCurrentState(WizardTypes::eFinish))
{ return;
}
}
bool WizardMachine::prepareLeaveCurrentState( WizardTypes::CommitPageReason _eReason )
{
IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) );
ENSURE_OR_RETURN( pController != nullptr, "WizardMachine::prepareLeaveCurrentState: no controller for the current page!", true ); return pController->commitPage( _eReason );
}
bool WizardMachine::skipBackwardUntil(WizardTypes::WizardState _nTargetState)
{ // allowed to leave the current page? if ( !prepareLeaveCurrentState( WizardTypes::eTravelBackward ) ) returnfalse;
// 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;
WizardTypes::WizardState nCurrentRollbackState = getCurrentState(); while ( nCurrentRollbackState != _nTargetState )
{
DBG_ASSERT( !aTravelVirtually.empty(), "WizardMachine::skipBackwardUntil: this target state does not exist in the history!" );
nCurrentRollbackState = aTravelVirtually.top();
aTravelVirtually.pop();
}
m_pImpl->aStateHistory = std::move(aTravelVirtually); if ( !ShowPage( _nTargetState ) )
{
m_pImpl->aStateHistory = std::move(aOldStateHistory); returnfalse;
} returntrue;
}
// allowed to leave the current page? if ( !prepareLeaveCurrentState( nCurrentState < _nTargetState ? WizardTypes::eTravelForward : WizardTypes::eTravelBackward ) ) returnfalse;
// 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; while ( nCurrentState != _nTargetState )
{
WizardTypes::WizardState nNextState = determineNextState( nCurrentState ); if ( WZS_INVALID_STATE == nNextState )
{
OSL_FAIL( "WizardMachine::skipUntil: the given target state does not exist!" ); returnfalse;
}
// remember the skipped state in the history
aTravelVirtually.push( nCurrentState );
// get the next state
nCurrentState = nNextState;
}
m_pImpl->aStateHistory = std::move(aTravelVirtually); // show the target page if ( !ShowPage( nCurrentState ) )
{ // argh! prepareLeaveCurrentPage succeeded, determineNextState succeeded, // but ShowPage doesn't? Somebody behaves very strange here...
OSL_FAIL( "WizardMachine::skipUntil: very unpolite..." );
m_pImpl->aStateHistory = std::move(aOldStateHistory); returnfalse;
} returntrue;
}
void WizardMachine::skip()
{ // allowed to leave the current page? if ( !prepareLeaveCurrentState( WizardTypes::eTravelForward ) ) return;
// remember the skipped state in the history
m_pImpl->aStateHistory.push(nCurrentState);
// get the next state
nCurrentState = nNextState;
// show the (n+1)th page if (!ShowPage(nCurrentState))
{ // 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("WizardMachine::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 ...) return;
}
// all fine
}
bool WizardMachine::travelNext()
{ // allowed to leave the current page? if ( !prepareLeaveCurrentState( WizardTypes::eTravelForward ) ) returnfalse;
// determine the next state to travel to
WizardTypes::WizardState nCurrentState = getCurrentState();
WizardTypes::WizardState nNextState = determineNextState(nCurrentState); if (WZS_INVALID_STATE == nNextState) returnfalse;
// the state history is used by the enterState method // all fine
m_pImpl->aStateHistory.push(nCurrentState); if (!ShowPage(nNextState))
{
m_pImpl->aStateHistory.pop(); returnfalse;
}
bool WizardMachine::travelPrevious()
{
DBG_ASSERT(!m_pImpl->aStateHistory.empty(), "WizardMachine::travelPrevious: have no previous page!");
// allowed to leave the current page? if ( !prepareLeaveCurrentState( WizardTypes::eTravelBackward ) ) returnfalse;
// the next state to switch to
WizardTypes::WizardState nPreviousState = m_pImpl->aStateHistory.top();
// the state history is used by the enterState method
m_pImpl->aStateHistory.pop(); // show this page if (!ShowPage(nPreviousState))
{
m_pImpl->aStateHistory.push(nPreviousState); returnfalse;
}
void WizardMachine::updateTravelUI()
{ const IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) );
OSL_ENSURE( pController != nullptr, "WizardMachine::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 );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.