1/*
2 * Copyright 2005, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include <Application.h>
8#include <Window.h>
9#include <Box.h>
10#include <StringView.h>
11
12// include Be's and our version (see Jamfile)
13#include <CheckBox.h>
14#define BCheckBox HCheckBox
15#undef _CHECK_BOX_H
16#include <CheckBox.h>
17#undef BCheckBox
18
19#include <stdio.h>
20
21
22class DividedBackgroundView : public BView {
23	public:
24		DividedBackgroundView(BRect rect);
25
26		virtual void Draw(BRect updateRect);
27};
28
29
30DividedBackgroundView::DividedBackgroundView(BRect rect)
31	: BView(rect, NULL, B_FOLLOW_NONE, B_WILL_DRAW)
32{
33	SetViewColor(80, 120, 80);
34}
35
36
37void
38DividedBackgroundView::Draw(BRect updateRect)
39{
40	PushState();
41
42	BRect bounds = Bounds();
43	BRect rect = bounds;
44	rect.right = rect.left + bounds.Width() / 2;
45
46	SetLowColor(120, 0, 0);
47	FillRect(rect, B_SOLID_LOW);
48
49	rect.left = rect.right + 1;
50	rect.right = bounds.right;
51
52	SetLowColor(0, 0, 120);
53	FillRect(rect, B_SOLID_LOW);
54}
55
56
57//	#pragma mark -
58
59
60class Window : public BWindow {
61	public:
62		Window();
63
64		virtual bool QuitRequested();
65};
66
67
68Window::Window()
69	: BWindow(BRect(100, 100, 520, 430), "CheckBox-Test",
70			B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
71{
72	BRect rect(20, 10, 200, 30);
73	BStringView *stringView = new BStringView(rect, NULL, "Be's BCheckBox");
74	stringView->SetFont(be_bold_font);
75	AddChild(stringView);
76
77	rect.OffsetBy(0, 40);
78	BView *checkBox = new BCheckBox(rect, NULL, "Test 1", NULL);
79	AddChild(checkBox);
80
81	rect.OffsetBy(0, 60);
82	BView *view = new BView(rect.InsetByCopy(-15, -15), NULL, B_FOLLOW_NONE, B_WILL_DRAW);
83	view->SetViewColor(240, 180, 20);
84	AddChild(view);
85
86	checkBox = new BCheckBox(rect.OffsetToCopy(15, 15), NULL, "Test 2", NULL);
87	view->AddChild(checkBox);
88	checkBox->SetViewColor(220, 170, 20);
89
90	rect.OffsetBy(0, 60);
91	BBox *box = new BBox(rect.InsetByCopy(-15, -15), NULL);
92	AddChild(box);
93
94	checkBox = new BCheckBox(rect.OffsetToCopy(15, 15), NULL, "Test 3", NULL);
95	checkBox->SetViewColor(220, 170, 20);
96		// is ignored...
97	box->AddChild(checkBox);
98
99	rect.OffsetBy(0, 60);
100	view = new DividedBackgroundView(rect.InsetByCopy(-15, -15));
101	AddChild(view);
102
103	checkBox = new BCheckBox(rect.OffsetToCopy(15, 15), NULL, "Test 4", NULL);
104	view->AddChild(checkBox);
105
106	rect.OffsetBy(0, 60);
107	view = new DividedBackgroundView(rect.InsetByCopy(-15, -15));
108	AddChild(view);
109
110	checkBox = new BCheckBox(rect.OffsetToCopy(15, 15), NULL, "Test 5", NULL);
111	checkBox->ResizeToPreferred();
112	view->AddChild(checkBox);
113
114	// Haiku's BCheckBox
115
116	rect.Set(240, 10, 400, 30);
117	stringView = new BStringView(rect, NULL, "Haiku's BCheckBox");
118	stringView->SetFont(be_bold_font);
119	AddChild(stringView);
120
121	rect.OffsetBy(0, 40);
122	checkBox = new HCheckBox(rect, NULL, "Test 1", NULL);
123	AddChild(checkBox);
124
125	rect.OffsetBy(0, 60);
126	view = new BView(rect.InsetByCopy(-15, -15), NULL, B_FOLLOW_NONE, B_WILL_DRAW);
127	view->SetViewColor(240, 180, 20);
128	AddChild(view);
129
130	checkBox = new HCheckBox(rect.OffsetToCopy(15, 15), NULL, "Test 2", NULL);
131	view->AddChild(checkBox);
132	checkBox->SetViewColor(220, 170, 20);
133
134	rect.OffsetBy(0, 60);
135	box = new BBox(rect.InsetByCopy(-15, -15), NULL);
136	AddChild(box);
137
138	checkBox = new HCheckBox(rect.OffsetToCopy(15, 15), NULL, "Test 3", NULL);
139	checkBox->SetViewColor(220, 170, 20);
140		// is ignored...
141	box->AddChild(checkBox);
142
143	rect.OffsetBy(0, 60);
144	view = new DividedBackgroundView(rect.InsetByCopy(-15, -15));
145	AddChild(view);
146
147	checkBox = new HCheckBox(rect.OffsetToCopy(15, 15), NULL, "Test 4", NULL);
148	view->AddChild(checkBox);
149
150	rect.OffsetBy(0, 60);
151	view = new DividedBackgroundView(rect.InsetByCopy(-15, -15));
152	AddChild(view);
153
154	checkBox = new HCheckBox(rect.OffsetToCopy(15, 15), NULL, "Test 5", NULL);
155	checkBox->ResizeToPreferred();
156	view->AddChild(checkBox);
157}
158
159
160bool
161Window::QuitRequested()
162{
163	be_app->PostMessage(B_QUIT_REQUESTED);
164	return true;
165}
166
167
168//	#pragma mark -
169
170
171class Application : public BApplication {
172	public:
173		Application();
174
175		virtual void ReadyToRun(void);
176};
177
178
179Application::Application()
180	: BApplication("application/x-vnd.obos-test")
181{
182}
183
184
185void
186Application::ReadyToRun(void)
187{
188	BWindow *window = new Window();
189	window->Show();
190}
191
192
193//	#pragma mark -
194
195
196int
197main(int argc, char **argv)
198{
199	Application app;
200
201	app.Run();
202	return 0;
203}
204
205