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	Window()->ResizeToPreferred();
59}
60
61
62void
63WizardView::PageCompleted()
64{
65	if (fPage != NULL)
66		fPage->PageCompleted();
67
68	// Restore initial state
69	SetNextButtonLabel(B_TRANSLATE_COMMENT("Next", "Button"));
70	SetPreviousButtonLabel(B_TRANSLATE_COMMENT("Previous", "Button"));
71	SetNextButtonEnabled(true);
72	SetPreviousButtonEnabled(true);
73	SetPreviousButtonHidden(false);
74}
75
76
77void
78WizardView::SetPreviousButtonEnabled(bool enabled)
79{
80	fPrevious->SetEnabled(enabled);
81}
82
83
84void
85WizardView::SetNextButtonEnabled(bool enabled)
86{
87	fNext->SetEnabled(enabled);
88}
89
90
91void
92WizardView::SetPreviousButtonLabel(const char* text)
93{
94	fPrevious->SetLabel(text);
95}
96
97
98void
99WizardView::SetNextButtonLabel(const char* text)
100{
101	fNext->SetLabel(text);
102}
103
104
105void
106WizardView::SetPreviousButtonHidden(bool hide)
107{
108	if (hide) {
109		if (!fPrevious->IsHidden())
110			fPrevious->Hide();
111	} else {
112		if (fPrevious->IsHidden())
113			fPrevious->Show();
114	}
115}
116
117
118void
119WizardView::_BuildUI()
120{
121	fPageContainer = new BGroupView("page container");
122	fPageContainer->GroupLayout()->SetInsets(B_USE_WINDOW_SPACING,
123		B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING);
124	fPrevious = new BButton("previous",
125		B_TRANSLATE_COMMENT("Previous", "Button"),
126		new BMessage(kMessagePrevious));
127	fNext = new BButton("next", B_TRANSLATE_COMMENT("Next", "Button"),
128		new BMessage(kMessageNext));
129	BButton* quit = new BButton("quit", B_TRANSLATE_COMMENT("Quit", "Button"),
130		new BMessage(B_QUIT_REQUESTED));
131
132	BLayoutBuilder::Group<>(this)
133		.Add(fPageContainer)
134		.Add(new BSeparatorView(B_HORIZONTAL))
135		.AddGroup(B_HORIZONTAL)
136			.SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING,
137				B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING)
138			.Add(quit)
139			.AddGlue()
140			.Add(fPrevious)
141			.Add(fNext)
142			.End()
143		.End();
144}
145