1/*
2 * Copyright 2008-2011, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Michael Pfeiffer <laplace@users.sourceforge.net>
7 *		Axel Dörfler, axeld@pinc-software.de
8 */
9
10
11#include "WizardView.h"
12
13#include <LayoutBuilder.h>
14#include <Button.h>
15#include <Catalog.h>
16#include <SeparatorView.h>
17
18#include "WizardPageView.h"
19
20
21#undef B_TRANSLATION_CONTEXT
22#define B_TRANSLATION_CONTEXT "WizardView"
23
24
25WizardView::WizardView(const char* name)
26	:
27	BGroupView(name, B_VERTICAL, 0),
28	fPrevious(NULL),
29	fNext(NULL),
30	fPage(NULL)
31{
32	_BuildUI();
33	SetPreviousButtonHidden(true);
34}
35
36
37WizardView::~WizardView()
38{
39}
40
41
42void
43WizardView::SetPage(WizardPageView* page)
44{
45	if (fPage == page)
46		return;
47
48	if (fPage != NULL) {
49		fPageContainer->RemoveChild(fPage);
50		delete fPage;
51	}
52
53	fPage = page;
54	if (page == NULL)
55		return;
56
57	fPageContainer->AddChild(page);
58}
59
60
61void
62WizardView::PageCompleted()
63{
64	if (fPage != NULL)
65		fPage->PageCompleted();
66
67	// Restore initial state
68	SetNextButtonLabel(B_TRANSLATE_COMMENT("Next", "Button"));
69	SetPreviousButtonLabel(B_TRANSLATE_COMMENT("Previous", "Button"));
70	SetNextButtonEnabled(true);
71	SetPreviousButtonEnabled(true);
72	SetPreviousButtonHidden(false);
73}
74
75
76void
77WizardView::SetPreviousButtonEnabled(bool enabled)
78{
79	fPrevious->SetEnabled(enabled);
80}
81
82
83void
84WizardView::SetNextButtonEnabled(bool enabled)
85{
86	fNext->SetEnabled(enabled);
87}
88
89
90void
91WizardView::SetPreviousButtonLabel(const char* text)
92{
93	fPrevious->SetLabel(text);
94}
95
96
97void
98WizardView::SetNextButtonLabel(const char* text)
99{
100	fNext->SetLabel(text);
101}
102
103
104void
105WizardView::SetPreviousButtonHidden(bool hide)
106{
107	if (hide) {
108		if (!fPrevious->IsHidden())
109			fPrevious->Hide();
110	} else {
111		if (fPrevious->IsHidden())
112			fPrevious->Show();
113	}
114}
115
116
117void
118WizardView::_BuildUI()
119{
120	fPageContainer = new BGroupView("page container");
121	fPageContainer->GroupLayout()->SetInsets(B_USE_WINDOW_SPACING,
122		B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING);
123	fPrevious = new BButton("previous",
124		B_TRANSLATE_COMMENT("Previous", "Button"),
125		new BMessage(kMessagePrevious));
126	fNext = new BButton("next", B_TRANSLATE_COMMENT("Next", "Button"),
127		new BMessage(kMessageNext));
128	BButton* quit = new BButton("quit", B_TRANSLATE_COMMENT("Quit", "Button"),
129		new BMessage(B_QUIT_REQUESTED));
130
131	BLayoutBuilder::Group<>(this)
132		.Add(fPageContainer)
133		.Add(new BSeparatorView(B_HORIZONTAL))
134		.AddGroup(B_HORIZONTAL)
135			.SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING,
136				B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING)
137			.Add(quit)
138			.AddGlue()
139			.Add(fPrevious)
140			.Add(fNext)
141			.End()
142		.End();
143}
144