1/*
2 * Copyright 2001-2009, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Rafael Romo
7 *		Stefano Ceccherini (burton666@libero.it)
8 *		Axel D��rfler, axeld@pinc-software.de
9 */
10
11
12#include <StorageKit.h>
13#include <Screen.h>
14
15#include "ScreenSettings.h"
16
17
18static const char* kSettingsFileName = "Screen_data";
19
20
21ScreenSettings::ScreenSettings()
22{
23	BScreen screen(B_MAIN_SCREEN_ID);
24	BRect screenFrame = screen.Frame();
25
26	fWindowFrame.Set(0, 0, 450, 250);
27
28	BPath path;
29	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
30		path.Append(kSettingsFileName);
31
32		BFile file(path.Path(), B_READ_ONLY);
33		if (file.InitCheck() == B_OK) {
34			file.Read(&fWindowFrame, sizeof(BRect));
35
36			// make sure the window is visible on screen
37			if (fWindowFrame.Width() > screenFrame.Width())
38				fWindowFrame.right = fWindowFrame.left + 450;
39			if (fWindowFrame.Height() > screenFrame.Height())
40				fWindowFrame.bottom = fWindowFrame.top + 250;
41
42			if (screenFrame.right >= fWindowFrame.left + 40
43				&& screenFrame.bottom >= fWindowFrame.top + 40
44				&& screenFrame.left <= fWindowFrame.right - 40
45				&& screenFrame.top <= fWindowFrame.bottom - 40)
46				return;
47		}
48	}
49
50	// Center on screen
51	fWindowFrame.OffsetTo(
52		screenFrame.left + (screenFrame.Width() - fWindowFrame.Width()) / 2,
53		screenFrame.top + (screenFrame.Height() - fWindowFrame.Height()) /2);
54}
55
56
57ScreenSettings::~ScreenSettings()
58{
59	BPath path;
60	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
61		return;
62
63	path.Append(kSettingsFileName);
64
65	BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
66	if (file.InitCheck() == B_OK)
67		file.Write(&fWindowFrame, sizeof(BRect));
68}
69
70
71void
72ScreenSettings::SetWindowFrame(BRect frame)
73{
74	fWindowFrame = frame;
75}
76