headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / servers / app / statusbar / main.cpp
blobe605a659366ff117318ef317b0e122439c98ef19
1 #include <stdio.h>
3 #include <Application.h>
4 #include <Directory.h>
5 #include <Entry.h>
6 #include <Message.h>
7 #include <MessageRunner.h>
8 #include <Messenger.h>
9 #include <StatusBar.h>
10 #include <Window.h>
12 enum {
13 MSG_PULSE = 'puls'
16 class Window : public BWindow {
17 public:
18 Window(BRect frame)
19 : BWindow(frame, "BStatusBar Test", B_TITLED_WINDOW_LOOK,
20 B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS
21 | B_QUIT_ON_WINDOW_CLOSE | B_NOT_ZOOMABLE),
22 fHomeFolderEntryCount(0),
23 fHomeFolderCurrentEntry(0)
25 frame = Bounds();
26 BView* background = new BView(frame, "bg", B_FOLLOW_ALL, 0);
27 background->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
28 AddChild(background);
30 frame = background->Bounds();
31 frame.InsetBy(10, 10);
32 fStatusBar = new BStatusBar(frame, "status", "Label: ", "-Trailing");
33 fStatusBar->SetResizingMode(B_FOLLOW_ALL);
34 background->AddChild(fStatusBar);
36 fHomeFolder.SetTo("/boot/home/");
37 BEntry entry;
38 while (fHomeFolder.GetNextEntry(&entry) == B_OK)
39 fHomeFolderEntryCount++;
41 fPulse = new BMessageRunner(BMessenger(this),
42 new BMessage(MSG_PULSE), 1000000);
45 ~Window()
47 delete fPulse;
50 virtual void MessageReceived(BMessage* message)
52 switch (message->what) {
53 case MSG_PULSE: {
54 BEntry entry;
55 if (fHomeFolder.GetNextEntry(&entry) < B_OK) {
56 fHomeFolderCurrentEntry = 0;
57 fHomeFolder.Rewind();
58 fStatusBar->Reset("Label: ", "-Trailing");
59 if (fHomeFolder.GetNextEntry(&entry) < B_OK)
60 break;
61 } else
62 fHomeFolderCurrentEntry++;
63 char name[B_FILE_NAME_LENGTH];
64 if (entry.GetName(name) < B_OK)
65 break;
66 float value = 100.0 * fHomeFolderCurrentEntry
67 / (fHomeFolderEntryCount - 1);
68 fStatusBar->SetTo(value, "Text", name);
69 break;
71 default:
72 BWindow::MessageReceived(message);
75 private:
76 BStatusBar* fStatusBar;
77 BDirectory fHomeFolder;
78 int32 fHomeFolderEntryCount;
79 int32 fHomeFolderCurrentEntry;
80 BMessageRunner* fPulse;
84 int
85 main(int argc, char* argv[])
87 BApplication app("application/x-vnd.stippi.statusbar_test");
89 BRect frame(50, 50, 350, 350);
90 Window* window = new Window(frame);
91 window->Show();
93 app.Run();
94 return 0;