btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / clock / cl_wind.cpp
blob6aa6b5f3987e5ddde98f2d0b9d683bc848f9971c
1 /*
2 * Copyright 1999, Be Incorporated. All Rights Reserved.
3 * This file may be used under the terms of the Be Sample Code License.
4 */
6 #include "cl_wind.h"
7 #include "cl_view.h"
9 #include <Application.h>
10 #include <FindDirectory.h>
11 #include <Path.h>
12 #include <Screen.h>
15 #include <fcntl.h>
16 #include <unistd.h>
17 #include <sys/stat.h>
20 TClockWindow::TClockWindow(BRect frame, const char* title)
21 : BWindow(frame, title, B_TITLED_WINDOW,
22 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT, B_ALL_WORKSPACES),
23 fOnScreenView(NULL)
25 _InitWindow();
29 TClockWindow::~TClockWindow()
34 bool
35 TClockWindow::QuitRequested()
37 BPath path;
38 if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) {
39 path.Append("Clock_settings");
40 int ref = creat(path.Path(), 0777);
41 if (ref >= 0) {
42 BPoint lefttop = Frame().LeftTop();
43 write(ref, (char *)&lefttop, sizeof(BPoint));
44 short face = fOnScreenView->ReturnFace();
45 write(ref, (char *)&face, sizeof(short));
46 bool seconds = fOnScreenView->ReturnSeconds();
47 write(ref, (char *)&seconds, sizeof(bool));
48 close(ref);
51 be_app->PostMessage(B_QUIT_REQUESTED);
52 return true;
56 void
57 TClockWindow::_InitWindow()
59 // half second pulse rate
60 SetPulseRate(500000);
62 fOnScreenView = new TOnscreenView(BRect(0, 0, 82, 82), "Clock", 22, 15, 41);
63 AddChild(fOnScreenView);
65 int ref;
66 BPath path;
67 if (find_directory (B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
68 path.Append("Clock_settings");
69 ref = open(path.Path(), O_RDONLY);
70 if (ref >= 0) {
71 BPoint leftTop;
72 read(ref, (char*)&leftTop, sizeof(leftTop));
74 short face;
75 read(ref, (char *)&face, sizeof(short));
76 fOnScreenView->UseFace(face);
78 bool secs;
79 read(ref, (char *)&secs, sizeof(bool));
80 fOnScreenView->ShowSecs(secs);
82 close(ref);
84 MoveTo(leftTop);
86 BRect frame = Frame();
87 frame.InsetBy(-4, -4);
88 // it's not visible so reposition. I'm not going to get
89 // fancy here, just place in the default location
90 if (!frame.Intersects(BScreen(this).Frame()))
91 MoveTo(100, 100);