xref: /haiku/src/apps/processcontroller/PCWindow.cpp (revision c237c4ce593ee823d9867fd997e51e4c447f5623)
1 /*
2  * Copyright 2000, Georges-Edouard Berenger. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "PCWorld.h"
8 #include "PCWindow.h"
9 #include "Preferences.h"
10 #include "ProcessController.h"
11 #include "Utilities.h"
12 
13 #include <Alert.h>
14 #include <Application.h>
15 #include <Catalog.h>
16 #include <Deskbar.h>
17 #include <Dragger.h>
18 #include <Roster.h>
19 #include <StringView.h>
20 
21 
22 PCWindow::PCWindow()
23 	:
24 	BWindow(BRect(100, 150, 131, 181),
25 		B_TRANSLATE_SYSTEM_NAME("ProcessController"), B_TITLED_WINDOW,
26 		B_NOT_H_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
27 {
28 	Preferences preferences(kPreferencesFileName);
29 	preferences.SaveInt32(kCurrentVersion, kVersionName);
30 	preferences.LoadWindowPosition(this, kPosPrefName);
31 
32 	system_info info;
33 	get_system_info(&info);
34 	int width = 4;
35 	if (info.cpu_count > 4)
36 		width = info.cpu_count;
37 	if (info.cpu_count <= 16)
38 		width *= 2;
39 
40 	// For the memory bar
41 	width += 8;
42 
43 	BRect rect = Bounds();
44 
45 	BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
46 	topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
47 	AddChild(topView);
48 
49 	// set up a rectangle && instantiate a new view
50 	// view rect should be same size as window rect but with left top at (0, 0)
51 	rect.Set(0, 0, width - 1, 15);
52 	SetSizeLimits(rect.Width() + 21, rect.Width() + 21, 15 + 21, 15 + 21);
53 
54 	rect.OffsetTo((Bounds().Width() - 16) / 2, (Bounds().Height() - 16) / 2);
55 
56 	topView->AddChild(new ProcessController(rect));
57 
58 	// make window visible
59 	Show();
60 	fDraggersAreDrawn = BDragger::AreDraggersDrawn();
61 	BDragger::ShowAllDraggers();
62 }
63 
64 
65 PCWindow::~PCWindow()
66 {
67 	if (!fDraggersAreDrawn)
68 		BDragger::HideAllDraggers();
69 }
70 
71 
72 bool
73 PCWindow::QuitRequested()
74 {
75 	Preferences tPreferences(kPreferencesFileName);
76 	tPreferences.SaveInt32(kCurrentVersion, kVersionName);
77 	tPreferences.SaveWindowPosition(this, kPosPrefName);
78 
79 	be_app->PostMessage(B_QUIT_REQUESTED);
80 	return true;
81 }
82