xref: /haiku/src/apps/pulse/PulseWindow.cpp (revision 836100d5058d2034874afeaf0a47799cf735ad02)
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 
PulseWindow(BRect rect)3071302e7cSJonas Sundström PulseWindow::PulseWindow(BRect rect)
3171302e7cSJonas Sundström 	:
32560ff447SJonas Sundström 	BWindow(rect, B_TRANSLATE_SYSTEM_NAME("Pulse"), B_TITLED_WINDOW,
33e04f6f31SAdrien 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",
43e04f6f31SAdrien Destugues 		pulseapp->fPrefs);
4480f47570SAxel Dörfler 	AddChild(fMiniPulseView);
4552a38012Sejakowatz 
46e04f6f31SAdrien 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());
54*836100d5SAdrien Destugues 	} else {
5580f47570SAxel Dörfler 		fMiniPulseView->Hide();
56*836100d5SAdrien Destugues 		BRect r = fNormalPulseView->Bounds();
57*836100d5SAdrien Destugues 		ResizeTo(r.Width(), r.Height());
58*836100d5SAdrien Destugues 	}
5952a38012Sejakowatz }
6052a38012Sejakowatz 
6180f47570SAxel Dörfler 
~PulseWindow()6280f47570SAxel Dörfler PulseWindow::~PulseWindow()
6380f47570SAxel Dörfler {
6480f47570SAxel Dörfler 	PulseApp *pulseapp = (PulseApp *)be_app;
6580f47570SAxel Dörfler 
6680f47570SAxel Dörfler 	if (fMode == NORMAL_WINDOW_MODE)
67e04f6f31SAdrien Destugues 		pulseapp->fPrefs->normal_window_rect = Frame();
6880f47570SAxel Dörfler 	else if (fMode == MINI_WINDOW_MODE)
69e04f6f31SAdrien Destugues 		pulseapp->fPrefs->mini_window_rect = Frame();
7080f47570SAxel Dörfler }
7180f47570SAxel Dörfler 
7280f47570SAxel Dörfler 
7380f47570SAxel Dörfler void
MessageReceived(BMessage * message)7480f47570SAxel Dörfler PulseWindow::MessageReceived(BMessage *message)
7580f47570SAxel Dörfler {
7652a38012Sejakowatz 	switch (message->what) {
7752a38012Sejakowatz 		case PV_NORMAL_MODE:
7852a38012Sejakowatz 		case PV_MINI_MODE:
7952a38012Sejakowatz 		case PV_DESKBAR_MODE:
8052a38012Sejakowatz 			SetMode(message->what);
8152a38012Sejakowatz 			break;
8252a38012Sejakowatz 		case PRV_NORMAL_FADE_COLORS:
8352a38012Sejakowatz 		case PRV_NORMAL_CHANGE_COLOR:
8480f47570SAxel Dörfler 			fNormalPulseView->UpdateColors(message);
8552a38012Sejakowatz 			break;
8652a38012Sejakowatz 		case PRV_MINI_CHANGE_COLOR:
8780f47570SAxel Dörfler 			fMiniPulseView->UpdateColors(message);
8852a38012Sejakowatz 			break;
8952a38012Sejakowatz 		case PV_PREFERENCES: {
90e04f6f31SAdrien Destugues 			DetachCurrentMessage();
91e04f6f31SAdrien Destugues 			message->AddMessenger("settingsListener", this);
92e04f6f31SAdrien Destugues 			be_app->PostMessage(message);
9352a38012Sejakowatz 			break;
9452a38012Sejakowatz 		}
9552a38012Sejakowatz 		case PV_ABOUT: {
96e04f6f31SAdrien Destugues 			be_app->PostMessage(B_ABOUT_REQUESTED);
9752a38012Sejakowatz 			break;
9852a38012Sejakowatz 		}
9952a38012Sejakowatz 		case PV_QUIT:
10052a38012Sejakowatz 			PostMessage(B_QUIT_REQUESTED);
10152a38012Sejakowatz 			break;
10252a38012Sejakowatz 		case PV_CPU_MENU_ITEM:
10352a38012Sejakowatz 			// Call the correct version based on whose menu sent the message
10480f47570SAxel Dörfler 			if (fMiniPulseView->IsHidden())
10580f47570SAxel Dörfler 				fNormalPulseView->ChangeCPUState(message);
10680f47570SAxel Dörfler 			else
10780f47570SAxel Dörfler 				fMiniPulseView->ChangeCPUState(message);
10852a38012Sejakowatz 			break;
10952a38012Sejakowatz 		default:
11052a38012Sejakowatz 			BWindow::MessageReceived(message);
11152a38012Sejakowatz 			break;
11252a38012Sejakowatz 	}
11352a38012Sejakowatz }
11452a38012Sejakowatz 
11580f47570SAxel Dörfler 
11680f47570SAxel Dörfler void
SetMode(int newmode)11780f47570SAxel Dörfler PulseWindow::SetMode(int newmode)
11880f47570SAxel Dörfler {
11952a38012Sejakowatz 	PulseApp *pulseapp = (PulseApp *)be_app;
1200a7d4d99SAxel Dörfler 
12152a38012Sejakowatz 	switch (newmode) {
12252a38012Sejakowatz 		case PV_NORMAL_MODE:
123*836100d5SAdrien Destugues 		{
12480f47570SAxel Dörfler 			if (fMode == MINI_WINDOW_MODE) {
125e04f6f31SAdrien Destugues 				pulseapp->fPrefs->mini_window_rect = Frame();
126e04f6f31SAdrien Destugues 				pulseapp->fPrefs->window_mode = NORMAL_WINDOW_MODE;
127e04f6f31SAdrien Destugues 				pulseapp->fPrefs->Save();
12852a38012Sejakowatz 			}
12980f47570SAxel Dörfler 			fMiniPulseView->Hide();
13080f47570SAxel Dörfler 			fNormalPulseView->Show();
13180f47570SAxel Dörfler 			fMode = NORMAL_WINDOW_MODE;
13252a38012Sejakowatz 			SetType(B_TITLED_WINDOW);
13352a38012Sejakowatz 			SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
134*836100d5SAdrien Destugues 			BRect r = fNormalPulseView->Bounds();
135*836100d5SAdrien Destugues 			ResizeTo(r.Width(), r.Height());
136e04f6f31SAdrien Destugues 			MoveTo(pulseapp->fPrefs->normal_window_rect.left,
137e04f6f31SAdrien Destugues 				pulseapp->fPrefs->normal_window_rect.top);
1388e96ec34SAxel Dörfler 			MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN);
13952a38012Sejakowatz 			break;
140*836100d5SAdrien Destugues 		}
1410a7d4d99SAxel Dörfler 
14252a38012Sejakowatz 		case PV_MINI_MODE:
14380f47570SAxel Dörfler 			if (fMode == NORMAL_WINDOW_MODE) {
144e04f6f31SAdrien Destugues 				pulseapp->fPrefs->normal_window_rect = Frame();
145e04f6f31SAdrien Destugues 				pulseapp->fPrefs->window_mode = MINI_WINDOW_MODE;
146e04f6f31SAdrien Destugues 				pulseapp->fPrefs->Save();
14752a38012Sejakowatz 			}
14880f47570SAxel Dörfler 			fNormalPulseView->Hide();
14980f47570SAxel Dörfler 			fMiniPulseView->Show();
15080f47570SAxel Dörfler 			fMode = MINI_WINDOW_MODE;
15152a38012Sejakowatz 			SetLook(B_MODAL_WINDOW_LOOK);
15252a38012Sejakowatz 			SetFeel(B_NORMAL_WINDOW_FEEL);
15352a38012Sejakowatz 			SetFlags(B_NOT_ZOOMABLE);
15452a38012Sejakowatz 			SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096);
155e04f6f31SAdrien Destugues 			ResizeTo(pulseapp->fPrefs->mini_window_rect.IntegerWidth(),
156e04f6f31SAdrien Destugues 				pulseapp->fPrefs->mini_window_rect.IntegerHeight());
157e04f6f31SAdrien Destugues 			MoveTo(pulseapp->fPrefs->mini_window_rect.left,
158e04f6f31SAdrien Destugues 				pulseapp->fPrefs->mini_window_rect.top);
1598e96ec34SAxel Dörfler 			MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN);
16052a38012Sejakowatz 			break;
1610a7d4d99SAxel Dörfler 
16252a38012Sejakowatz 		case PV_DESKBAR_MODE:
16352a38012Sejakowatz 			// Do not set window's mode to DESKBAR_MODE because the
16452a38012Sejakowatz 			// destructor needs to save the correct BRect. ~PulseApp()
16552a38012Sejakowatz 			// will handle launching the replicant after our prefs are saved.
166e04f6f31SAdrien Destugues 			pulseapp->fPrefs->window_mode = DESKBAR_MODE;
167e04f6f31SAdrien Destugues 			LoadInDeskbar();
16852a38012Sejakowatz 			break;
16952a38012Sejakowatz 	}
17052a38012Sejakowatz }
17152a38012Sejakowatz 
17252a38012Sejakowatz 
17380f47570SAxel Dörfler bool
QuitRequested()17480f47570SAxel Dörfler PulseWindow::QuitRequested()
17580f47570SAxel Dörfler {
17652a38012Sejakowatz 	return true;
17752a38012Sejakowatz }
178