1 /* 2 3 Clock.cpp 4 5 13 apr 94 elr new today 6 7 */ 8 9 /* 10 Copyright 1999, Be Incorporated. All Rights Reserved. 11 This file may be used under the terms of the Be Sample Code License. 12 */ 13 14 #include <Debug.h> 15 16 #include "clock.h" 17 #include <fcntl.h> 18 #include <unistd.h> 19 #include <string.h> 20 21 #include <MenuItem.h> 22 #include <PopUpMenu.h> 23 #include <Path.h> 24 #include <Screen.h> 25 #include <FindDirectory.h> 26 #include <Dragger.h> 27 28 int main(int argc, char* argv[]) 29 { 30 THelloApplication *myApplication; 31 32 myApplication = new THelloApplication(); 33 myApplication->Run(); 34 35 delete myApplication; 36 return 0; 37 } 38 39 const char *app_signature = "application/x-vnd.Haiku-Clock"; 40 41 THelloApplication::THelloApplication() 42 :BApplication(app_signature) 43 { 44 BRect windowRect, viewRect; 45 BPoint wind_loc; 46 int ref; 47 short face; 48 bool secs; 49 BPath path; 50 51 viewRect.Set(0, 0, 82, 82); 52 myView = new TOnscreenView(viewRect, "Clock",22,15,41); 53 windowRect.Set(100, 100, 182, 182); 54 myWindow = new TClockWindow(windowRect, "Clock"); 55 face = 1; 56 if (find_directory (B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { 57 path.Append("Clock_settings"); 58 ref = open(path.Path(), O_RDONLY); 59 if (ref >= 0) { 60 read(ref, (char *)&wind_loc, sizeof(wind_loc)); 61 read(ref, (char *)&face, sizeof(short)); 62 read(ref, (char *)&secs, sizeof(bool)); 63 close(ref); 64 myWindow->MoveTo(wind_loc); 65 66 BRect frame = myWindow->Frame(); 67 frame.InsetBy(-4, -4); 68 if (!frame.Intersects(BScreen(myWindow).Frame())) { 69 // it's not visible so reposition. I'm not going to get 70 // fancy here, just place in the default location 71 myWindow->MoveTo(100, 100); 72 } 73 } 74 } 75 76 //+ BPopUpMenu *menu = MainMenu(); 77 //+ BMenuItem *item = new BMenuItem("Show Seconds", new BMessage(SHOW_SECONDS)); 78 //+ item->SetTarget(this); 79 //+ item->SetMarked(secs); 80 //+ 81 //+ menu->AddItem(new BSeparatorItem(), 1); 82 //+ menu->AddItem(item, 2); 83 //+ menu->AddItem(new BSeparatorItem(), 3); 84 85 myWindow->Lock(); 86 myWindow->AddChild(myView); 87 myWindow->theOnscreenView = myView; 88 89 //+ BRect r = myView->Frame(); 90 //+ r.top = r.bottom - 7; 91 //+ r.left = r.right - 7; 92 //+ BDragger *dw = new BDragger(r, myView, 0); 93 //+ myWindow->AddChild(dw); 94 95 myView->UseFace( face ); 96 myView->ShowSecs( secs ); 97 myView->Pulse(); // Force update 98 myWindow->Show(); 99 myWindow->Unlock(); 100 } 101 102 void THelloApplication::MessageReceived(BMessage *msg) 103 { 104 if (msg->what == SHOW_SECONDS) { 105 //+ if (myWindow->Lock()) { 106 //+ BMenuItem *item = MainMenu()->FindItem(SHOW_SECONDS); 107 //+ item->SetMarked(!item->IsMarked()); 108 //+//+ myView->ShowSecs(item->IsMarked()); 109 //+ myWindow->Unlock(); 110 //+ } 111 } else { 112 BApplication::MessageReceived(msg); 113 } 114 } 115