3 #include <Application.h>
7 #include <MessageRunner.h>
16 class Window
: public BWindow
{
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)
26 BView
* background
= new BView(frame
, "bg", B_FOLLOW_ALL
, 0);
27 background
->SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
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/");
38 while (fHomeFolder
.GetNextEntry(&entry
) == B_OK
)
39 fHomeFolderEntryCount
++;
41 fPulse
= new BMessageRunner(BMessenger(this),
42 new BMessage(MSG_PULSE
), 1000000);
50 virtual void MessageReceived(BMessage
* message
)
52 switch (message
->what
) {
55 if (fHomeFolder
.GetNextEntry(&entry
) < B_OK
) {
56 fHomeFolderCurrentEntry
= 0;
58 fStatusBar
->Reset("Label: ", "-Trailing");
59 if (fHomeFolder
.GetNextEntry(&entry
) < B_OK
)
62 fHomeFolderCurrentEntry
++;
63 char name
[B_FILE_NAME_LENGTH
];
64 if (entry
.GetName(name
) < B_OK
)
66 float value
= 100.0 * fHomeFolderCurrentEntry
67 / (fHomeFolderEntryCount
- 1);
68 fStatusBar
->SetTo(value
, "Text", name
);
72 BWindow::MessageReceived(message
);
76 BStatusBar
* fStatusBar
;
77 BDirectory fHomeFolder
;
78 int32 fHomeFolderEntryCount
;
79 int32 fHomeFolderCurrentEntry
;
80 BMessageRunner
* fPulse
;
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
);