10255f411SMichael Pfeiffer/*
25b788d58SAxel Dörfler * Copyright 2008-2010, Haiku, Inc. All rights reserved.
30255f411SMichael Pfeiffer * Distributed under the terms of the MIT License.
45b788d58SAxel Dörfler *
51059b4e7SMichael Pfeiffer * Authors:
61059b4e7SMichael Pfeiffer *		Michael Pfeiffer <laplace@users.sourceforge.net>
70255f411SMichael Pfeiffer */
80255f411SMichael Pfeiffer
90255f411SMichael Pfeiffer
100255f411SMichael Pfeiffer#include "WizardController.h"
110255f411SMichael Pfeiffer
120255f411SMichael Pfeiffer#include "WizardView.h"
130255f411SMichael Pfeiffer#include "WizardPageView.h"
140255f411SMichael Pfeiffer
155b788d58SAxel Dörfler
160255f411SMichael Pfeiffervoid
170255f411SMichael PfeifferWizardController::StateStack::MakeEmpty()
180255f411SMichael Pfeiffer{
195b788d58SAxel Dörfler	StateStack* stack = this;
205b788d58SAxel Dörfler	StateStack* next;
215b788d58SAxel Dörfler	do {
225b788d58SAxel Dörfler		next = stack->Next();
235b788d58SAxel Dörfler		delete stack;
245b788d58SAxel Dörfler		stack = next;
255b788d58SAxel Dörfler	} while (next != NULL);
260255f411SMichael Pfeiffer}
270255f411SMichael Pfeiffer
280255f411SMichael Pfeiffer
290255f411SMichael PfeifferWizardController::WizardController()
305b788d58SAxel Dörfler	:
315b788d58SAxel Dörfler	fStack(NULL)
320255f411SMichael Pfeiffer{
330255f411SMichael Pfeiffer}
340255f411SMichael Pfeiffer
350255f411SMichael Pfeiffer
360255f411SMichael PfeifferWizardController::~WizardController()
370255f411SMichael Pfeiffer{
380255f411SMichael Pfeiffer	if (fStack != NULL) {
390255f411SMichael Pfeiffer		fStack->MakeEmpty();
400255f411SMichael Pfeiffer		fStack = NULL;
410255f411SMichael Pfeiffer	}
420255f411SMichael Pfeiffer}
430255f411SMichael Pfeiffer
440255f411SMichael Pfeiffer
450255f411SMichael Pfeiffervoid
460255f411SMichael PfeifferWizardController::Initialize(WizardView* view)
470255f411SMichael Pfeiffer{
480255f411SMichael Pfeiffer	if (fStack == NULL)
490255f411SMichael Pfeiffer		_PushState(InitialState());
500255f411SMichael Pfeiffer	_ShowPage(view);
510255f411SMichael Pfeiffer}
520255f411SMichael Pfeiffer
530255f411SMichael Pfeiffer
540255f411SMichael Pfeiffervoid
550255f411SMichael PfeifferWizardController::Next(WizardView* wizard)
560255f411SMichael Pfeiffer{
570255f411SMichael Pfeiffer	wizard->PageCompleted();
585b788d58SAxel Dörfler
590255f411SMichael Pfeiffer	if (fStack == NULL)
600255f411SMichael Pfeiffer		return;
615b788d58SAxel Dörfler
620255f411SMichael Pfeiffer	int state = NextState(fStack->State());
630255f411SMichael Pfeiffer	if (state < 0)
640255f411SMichael Pfeiffer		return;
655b788d58SAxel Dörfler
660255f411SMichael Pfeiffer	_PushState(state);
670255f411SMichael Pfeiffer	_ShowPage(wizard);
680255f411SMichael Pfeiffer}
690255f411SMichael Pfeiffer
700255f411SMichael Pfeiffer
710255f411SMichael Pfeiffervoid
720255f411SMichael PfeifferWizardController::Previous(WizardView* wizard)
730255f411SMichael Pfeiffer{
740255f411SMichael Pfeiffer	wizard->PageCompleted();
750255f411SMichael Pfeiffer
760255f411SMichael Pfeiffer	if (fStack != NULL) {
770255f411SMichael Pfeiffer		StateStack* stack = fStack;
780255f411SMichael Pfeiffer		fStack = fStack->Next();
790255f411SMichael Pfeiffer		delete stack;
800255f411SMichael Pfeiffer	}
810255f411SMichael Pfeiffer	_ShowPage(wizard);
820255f411SMichael Pfeiffer}
830255f411SMichael Pfeiffer
840255f411SMichael Pfeiffer
855675f44eSAxel Dörflerint32
865675f44eSAxel DörflerWizardController::CurrentState() const
875675f44eSAxel Dörfler{
885675f44eSAxel Dörfler	if (fStack == NULL)
895675f44eSAxel Dörfler		return -1;
905675f44eSAxel Dörfler
915675f44eSAxel Dörfler	return fStack->State();
925675f44eSAxel Dörfler}
935675f44eSAxel Dörfler
945675f44eSAxel Dörfler
950255f411SMichael Pfeiffervoid
960255f411SMichael PfeifferWizardController::_PushState(int32 state)
970255f411SMichael Pfeiffer{
980255f411SMichael Pfeiffer	fStack = new StateStack(state, fStack);
990255f411SMichael Pfeiffer}
1000255f411SMichael Pfeiffer
1010255f411SMichael Pfeiffer
1020255f411SMichael Pfeiffervoid
1030255f411SMichael PfeifferWizardController::_ShowPage(WizardView* wizard)
1040255f411SMichael Pfeiffer{
1050255f411SMichael Pfeiffer	if (fStack == NULL)
1060255f411SMichael Pfeiffer		return;
1070255f411SMichael Pfeiffer
1080255f411SMichael Pfeiffer	WizardPageView* page = CreatePage(fStack->State(), wizard);
1090255f411SMichael Pfeiffer	wizard->SetPage(page);
1100255f411SMichael Pfeiffer}
111