xref: /haiku/src/apps/bootmanager/WizardView.cpp (revision 83b1a68c52ba3e0e8796282759f694b7fdddf06d)
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 
25 WizardView::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 
37 WizardView::~WizardView()
38 {
39 }
40 
41 
42 void
43 WizardView::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 
61 void
62 WizardView::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 
76 void
77 WizardView::SetPreviousButtonEnabled(bool enabled)
78 {
79 	fPrevious->SetEnabled(enabled);
80 }
81 
82 
83 void
84 WizardView::SetNextButtonEnabled(bool enabled)
85 {
86 	fNext->SetEnabled(enabled);
87 }
88 
89 
90 void
91 WizardView::SetPreviousButtonLabel(const char* text)
92 {
93 	fPrevious->SetLabel(text);
94 }
95 
96 
97 void
98 WizardView::SetNextButtonLabel(const char* text)
99 {
100 	fNext->SetLabel(text);
101 }
102 
103 
104 void
105 WizardView::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 
117 void
118 WizardView::_BuildUI()
119 {
120 	fPageContainer = new BGroupView("page container");
121 	fPageContainer->GroupLayout()->SetInsets(B_USE_DEFAULT_SPACING,
122 		B_USE_DEFAULT_SPACING, B_USE_DEFAULT_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 
129 	BLayoutBuilder::Group<>(this)
130 		.Add(fPageContainer)
131 		.Add(new BSeparatorView(B_HORIZONTAL))
132 		.AddGroup(B_HORIZONTAL)
133 			.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
134 				B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
135 			.AddGlue()
136 			.Add(fPrevious)
137 			.Add(fNext)
138 			.End()
139 		.End();
140 }
141