1#include <stdio.h> 2 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> 11 12enum { 13 MSG_PULSE = 'puls' 14}; 15 16class Window : public BWindow { 17public: 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) 24 { 25 frame = Bounds(); 26 BView* background = new BView(frame, "bg", B_FOLLOW_ALL, 0); 27 background->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); 28 AddChild(background); 29 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); 35 36 fHomeFolder.SetTo("/boot/home/"); 37 BEntry entry; 38 while (fHomeFolder.GetNextEntry(&entry) == B_OK) 39 fHomeFolderEntryCount++; 40 41 fPulse = new BMessageRunner(BMessenger(this), 42 new BMessage(MSG_PULSE), 1000000); 43 } 44 45 ~Window() 46 { 47 delete fPulse; 48 } 49 50 virtual void MessageReceived(BMessage* message) 51 { 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; 70 } 71 default: 72 BWindow::MessageReceived(message); 73 } 74 } 75private: 76 BStatusBar* fStatusBar; 77 BDirectory fHomeFolder; 78 int32 fHomeFolderEntryCount; 79 int32 fHomeFolderCurrentEntry; 80 BMessageRunner* fPulse; 81}; 82 83 84int 85main(int argc, char* argv[]) 86{ 87 BApplication app("application/x-vnd.stippi.statusbar_test"); 88 89 BRect frame(50, 50, 350, 350); 90 Window* window = new Window(frame); 91 window->Show(); 92 93 app.Run(); 94 return 0; 95} 96 97 98