xref: /haiku/src/apps/pulse/PulseWindow.cpp (revision e04f6f31b08f57dfd8a75d3f399666b76f23b22a)
142f6e06fSWim van der Meer //*****************************************************************************
252a38012Sejakowatz //
352a38012Sejakowatz //	File:		PulseWindow.cpp
452a38012Sejakowatz //
552a38012Sejakowatz //	Written by:	Daniel Switkin
652a38012Sejakowatz //
752a38012Sejakowatz //	Copyright 1999, Be Incorporated
852a38012Sejakowatz //
942f6e06fSWim van der Meer //*****************************************************************************
1052a38012Sejakowatz 
1180f47570SAxel Dörfler 
1252a38012Sejakowatz #include "PulseWindow.h"
1352a38012Sejakowatz #include "PulseApp.h"
1452a38012Sejakowatz #include "Common.h"
1552a38012Sejakowatz #include "DeskbarPulseView.h"
160a7d4d99SAxel Dörfler 
170a7d4d99SAxel Dörfler #include <Alert.h>
1842f6e06fSWim van der Meer #include <Catalog.h>
190a7d4d99SAxel Dörfler #include <Deskbar.h>
200a7d4d99SAxel Dörfler #include <Screen.h>
2155f0b964SSiarzhuk Zharski #include <TextView.h>
2280f47570SAxel Dörfler 
2352a38012Sejakowatz #include <stdlib.h>
2452a38012Sejakowatz #include <string.h>
2552a38012Sejakowatz 
26546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
27546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "PulseWindow"
2842f6e06fSWim van der Meer 
2952a38012Sejakowatz 
3071302e7cSJonas Sundström PulseWindow::PulseWindow(BRect rect)
3171302e7cSJonas Sundström 	:
32560ff447SJonas Sundström 	BWindow(rect, B_TRANSLATE_SYSTEM_NAME("Pulse"), B_TITLED_WINDOW,
33*e04f6f31SAdrien Destugues 		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_QUIT_ON_WINDOW_CLOSE)
3480f47570SAxel Dörfler {
3552a38012Sejakowatz 	SetPulseRate(200000);
3652a38012Sejakowatz 
3752a38012Sejakowatz 	PulseApp *pulseapp = (PulseApp *)be_app;
3852a38012Sejakowatz 	BRect bounds = Bounds();
3980f47570SAxel Dörfler 	fNormalPulseView = new NormalPulseView(bounds);
4080f47570SAxel Dörfler 	AddChild(fNormalPulseView);
4152a38012Sejakowatz 
4242f6e06fSWim van der Meer 	fMiniPulseView = new MiniPulseView(bounds, "MiniPulseView",
43*e04f6f31SAdrien Destugues 		pulseapp->fPrefs);
4480f47570SAxel Dörfler 	AddChild(fMiniPulseView);
4552a38012Sejakowatz 
46*e04f6f31SAdrien Destugues 	fMode = pulseapp->fPrefs->window_mode;
4780f47570SAxel Dörfler 	if (fMode == MINI_WINDOW_MODE) {
4852a38012Sejakowatz 		SetLook(B_MODAL_WINDOW_LOOK);
4952a38012Sejakowatz 		SetFeel(B_NORMAL_WINDOW_FEEL);
5052a38012Sejakowatz 		SetFlags(B_NOT_ZOOMABLE);
5180f47570SAxel Dörfler 		fNormalPulseView->Hide();
5252a38012Sejakowatz 		SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096);
5352a38012Sejakowatz 		ResizeTo(rect.Width(), rect.Height());
5480f47570SAxel Dörfler 	} else
5580f47570SAxel Dörfler 		fMiniPulseView->Hide();
5652a38012Sejakowatz }
5752a38012Sejakowatz 
5880f47570SAxel Dörfler 
5980f47570SAxel Dörfler PulseWindow::~PulseWindow()
6080f47570SAxel Dörfler {
6180f47570SAxel Dörfler 	PulseApp *pulseapp = (PulseApp *)be_app;
6280f47570SAxel Dörfler 
6380f47570SAxel Dörfler 	if (fMode == NORMAL_WINDOW_MODE)
64*e04f6f31SAdrien Destugues 		pulseapp->fPrefs->normal_window_rect = Frame();
6580f47570SAxel Dörfler 	else if (fMode == MINI_WINDOW_MODE)
66*e04f6f31SAdrien Destugues 		pulseapp->fPrefs->mini_window_rect = Frame();
6780f47570SAxel Dörfler }
6880f47570SAxel Dörfler 
6980f47570SAxel Dörfler 
7080f47570SAxel Dörfler void
7180f47570SAxel Dörfler PulseWindow::MessageReceived(BMessage *message)
7280f47570SAxel Dörfler {
7352a38012Sejakowatz 	switch (message->what) {
7452a38012Sejakowatz 		case PV_NORMAL_MODE:
7552a38012Sejakowatz 		case PV_MINI_MODE:
7652a38012Sejakowatz 		case PV_DESKBAR_MODE:
7752a38012Sejakowatz 			SetMode(message->what);
7852a38012Sejakowatz 			break;
7952a38012Sejakowatz 		case PRV_NORMAL_FADE_COLORS:
8052a38012Sejakowatz 		case PRV_NORMAL_CHANGE_COLOR:
8180f47570SAxel Dörfler 			fNormalPulseView->UpdateColors(message);
8252a38012Sejakowatz 			break;
8352a38012Sejakowatz 		case PRV_MINI_CHANGE_COLOR:
8480f47570SAxel Dörfler 			fMiniPulseView->UpdateColors(message);
8552a38012Sejakowatz 			break;
8652a38012Sejakowatz 		case PV_PREFERENCES: {
87*e04f6f31SAdrien Destugues 			DetachCurrentMessage();
88*e04f6f31SAdrien Destugues 			message->AddMessenger("settingsListener", this);
89*e04f6f31SAdrien Destugues 			be_app->PostMessage(message);
9052a38012Sejakowatz 			break;
9152a38012Sejakowatz 		}
9252a38012Sejakowatz 		case PV_ABOUT: {
93*e04f6f31SAdrien Destugues 			be_app->PostMessage(B_ABOUT_REQUESTED);
9452a38012Sejakowatz 			break;
9552a38012Sejakowatz 		}
9652a38012Sejakowatz 		case PV_QUIT:
9752a38012Sejakowatz 			PostMessage(B_QUIT_REQUESTED);
9852a38012Sejakowatz 			break;
9952a38012Sejakowatz 		case PV_CPU_MENU_ITEM:
10052a38012Sejakowatz 			// Call the correct version based on whose menu sent the message
10180f47570SAxel Dörfler 			if (fMiniPulseView->IsHidden())
10280f47570SAxel Dörfler 				fNormalPulseView->ChangeCPUState(message);
10380f47570SAxel Dörfler 			else
10480f47570SAxel Dörfler 				fMiniPulseView->ChangeCPUState(message);
10552a38012Sejakowatz 			break;
10652a38012Sejakowatz 		default:
10752a38012Sejakowatz 			BWindow::MessageReceived(message);
10852a38012Sejakowatz 			break;
10952a38012Sejakowatz 	}
11052a38012Sejakowatz }
11152a38012Sejakowatz 
11280f47570SAxel Dörfler 
11380f47570SAxel Dörfler void
11480f47570SAxel Dörfler PulseWindow::SetMode(int newmode)
11580f47570SAxel Dörfler {
11652a38012Sejakowatz 	PulseApp *pulseapp = (PulseApp *)be_app;
1170a7d4d99SAxel Dörfler 
11852a38012Sejakowatz 	switch (newmode) {
11952a38012Sejakowatz 		case PV_NORMAL_MODE:
12080f47570SAxel Dörfler 			if (fMode == MINI_WINDOW_MODE) {
121*e04f6f31SAdrien Destugues 				pulseapp->fPrefs->mini_window_rect = Frame();
122*e04f6f31SAdrien Destugues 				pulseapp->fPrefs->window_mode = NORMAL_WINDOW_MODE;
123*e04f6f31SAdrien Destugues 				pulseapp->fPrefs->Save();
12452a38012Sejakowatz 			}
12580f47570SAxel Dörfler 			fMiniPulseView->Hide();
12680f47570SAxel Dörfler 			fNormalPulseView->Show();
12780f47570SAxel Dörfler 			fMode = NORMAL_WINDOW_MODE;
12852a38012Sejakowatz 			SetType(B_TITLED_WINDOW);
12952a38012Sejakowatz 			SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
130*e04f6f31SAdrien Destugues 			ResizeTo(pulseapp->fPrefs->normal_window_rect.IntegerWidth(),
131*e04f6f31SAdrien Destugues 				pulseapp->fPrefs->normal_window_rect.IntegerHeight());
132*e04f6f31SAdrien Destugues 			MoveTo(pulseapp->fPrefs->normal_window_rect.left,
133*e04f6f31SAdrien Destugues 				pulseapp->fPrefs->normal_window_rect.top);
1348e96ec34SAxel Dörfler 			MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN);
13552a38012Sejakowatz 			break;
1360a7d4d99SAxel Dörfler 
13752a38012Sejakowatz 		case PV_MINI_MODE:
13880f47570SAxel Dörfler 			if (fMode == NORMAL_WINDOW_MODE) {
139*e04f6f31SAdrien Destugues 				pulseapp->fPrefs->normal_window_rect = Frame();
140*e04f6f31SAdrien Destugues 				pulseapp->fPrefs->window_mode = MINI_WINDOW_MODE;
141*e04f6f31SAdrien Destugues 				pulseapp->fPrefs->Save();
14252a38012Sejakowatz 			}
14380f47570SAxel Dörfler 			fNormalPulseView->Hide();
14480f47570SAxel Dörfler 			fMiniPulseView->Show();
14580f47570SAxel Dörfler 			fMode = MINI_WINDOW_MODE;
14652a38012Sejakowatz 			SetLook(B_MODAL_WINDOW_LOOK);
14752a38012Sejakowatz 			SetFeel(B_NORMAL_WINDOW_FEEL);
14852a38012Sejakowatz 			SetFlags(B_NOT_ZOOMABLE);
14952a38012Sejakowatz 			SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096);
150*e04f6f31SAdrien Destugues 			ResizeTo(pulseapp->fPrefs->mini_window_rect.IntegerWidth(),
151*e04f6f31SAdrien Destugues 				pulseapp->fPrefs->mini_window_rect.IntegerHeight());
152*e04f6f31SAdrien Destugues 			MoveTo(pulseapp->fPrefs->mini_window_rect.left,
153*e04f6f31SAdrien Destugues 				pulseapp->fPrefs->mini_window_rect.top);
1548e96ec34SAxel Dörfler 			MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN);
15552a38012Sejakowatz 			break;
1560a7d4d99SAxel Dörfler 
15752a38012Sejakowatz 		case PV_DESKBAR_MODE:
15852a38012Sejakowatz 			// Do not set window's mode to DESKBAR_MODE because the
15952a38012Sejakowatz 			// destructor needs to save the correct BRect. ~PulseApp()
16052a38012Sejakowatz 			// will handle launching the replicant after our prefs are saved.
161*e04f6f31SAdrien Destugues 			pulseapp->fPrefs->window_mode = DESKBAR_MODE;
162*e04f6f31SAdrien Destugues 			LoadInDeskbar();
16352a38012Sejakowatz 			break;
16452a38012Sejakowatz 	}
16552a38012Sejakowatz }
16652a38012Sejakowatz 
16752a38012Sejakowatz 
16880f47570SAxel Dörfler bool
16980f47570SAxel Dörfler PulseWindow::QuitRequested()
17080f47570SAxel Dörfler {
17152a38012Sejakowatz 	return true;
17252a38012Sejakowatz }
173