xref: /haiku/src/tests/kits/interface/ChannelSliderTest.cpp (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 #include <Application.h>
2 #include <ChannelSlider.h>
3 #include <Window.h>
4 
5 #include <string>
6 
7 
8 struct limit_label {
9 	std::string min_label;
10 	std::string max_label;
11 };
12 
13 
14 const struct limit_label kLabels[] = {
15 	{ "min_label_1", "max_label_1" },
16 	{ "min_label_2", "max_label_2" },
17 	{ "min_label_3", "max_label_3" },
18 };
19 
20 
21 class MainWindow : public BWindow {
22 public:
23 	MainWindow()
24 		:BWindow(BRect(50, 50, 250, 360), "window", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
25 	{
26 		BChannelSlider *slider = new BChannelSlider(BRect(10, 10, 20, 20),
27 			"vertical slider", "Verticalp", new BMessage('test'), 4);
28 		slider->SetOrientation(B_VERTICAL);
29 		AddChild(slider);
30 		slider->ResizeToPreferred();
31 
32 		slider = new BChannelSlider(BRect(10, 10, 20, 20), "vertical slider",
33 			"Verticalp", new BMessage('test'), B_VERTICAL,  4);
34 		AddChild(slider);
35 		slider->SetLimitLabels("Wminp", "Wmaxp");
36 		slider->ResizeToPreferred();
37 		slider->MoveBy(slider->Bounds().Width() + 10.0, 0.0);
38 
39 		BChannelSlider *horizontal = new BChannelSlider(BRect(150, 10, 160, 20),
40 			 "horizontal slider", "Horizontal", new BMessage('test'), 3);
41 		AddChild(horizontal);
42 		horizontal->ResizeToPreferred();
43 
44 		horizontal = new BChannelSlider(BRect(150, 10, 160, 20),
45 			 "horizontal slider", "Horizontalp", new BMessage('test'),
46 			 B_HORIZONTAL, 3);
47 		AddChild(horizontal);
48 		horizontal->SetLimitLabels("Wminp", "Wmaxp");
49 		horizontal->ResizeToPreferred();
50 		horizontal->MoveBy(0.0, horizontal->Bounds().Height() + 10.0);
51 
52 		ResizeTo(horizontal->Frame().right + 10, slider->Frame().bottom + 10);
53 
54 		for (int32 i = 0; i < horizontal->CountChannels(); i++) {
55 			horizontal->SetLimitLabelsFor(i, kLabels[i].min_label.c_str(),
56 												kLabels[i].max_label.c_str());
57 		}
58 
59 		for (int32 i = 0; i < horizontal->CountChannels(); i++) {
60 			if (strcmp(horizontal->MinLimitLabelFor(i), kLabels[i].min_label.c_str()) != 0)
61 				printf("wrong min label for channel %ld\n", i);
62 			if (strcmp(horizontal->MaxLimitLabelFor(i), kLabels[i].max_label.c_str()) != 0)
63 				printf("wrong max label for channel %ld\n", i);
64 		}
65 	}
66 
67 	virtual bool QuitRequested() { be_app->PostMessage(B_QUIT_REQUESTED); return BWindow::QuitRequested() ; }
68 };
69 
70 
71 class App : public BApplication {
72 public:
73 	App() : BApplication("application/x-vnd.channelslidertest")
74 	{
75 	}
76 
77 	virtual void ReadyToRun()
78 	{
79 		(new MainWindow())->Show();
80 	}
81 
82 };
83 
84 int main()
85 {
86 	App app;
87 
88 	app.Run();
89 
90 	return 0;
91 }
92