152a38012Sejakowatz //**************************************************************************************** 252a38012Sejakowatz // 352a38012Sejakowatz // File: PulseWindow.cpp 452a38012Sejakowatz // 552a38012Sejakowatz // Written by: Daniel Switkin 652a38012Sejakowatz // 752a38012Sejakowatz // Copyright 1999, Be Incorporated 852a38012Sejakowatz // 952a38012Sejakowatz //**************************************************************************************** 1052a38012Sejakowatz 11*80f47570SAxel Dörfler 1252a38012Sejakowatz #include "PulseWindow.h" 1352a38012Sejakowatz #include "PulseApp.h" 1452a38012Sejakowatz #include "Common.h" 15*80f47570SAxel Dörfler 1652a38012Sejakowatz #include "DeskbarPulseView.h" 1752a38012Sejakowatz #include <interface/Alert.h> 1852a38012Sejakowatz #include <interface/Deskbar.h> 19*80f47570SAxel Dörfler 2052a38012Sejakowatz #include <stdlib.h> 2152a38012Sejakowatz #include <string.h> 2252a38012Sejakowatz 2352a38012Sejakowatz 24*80f47570SAxel Dörfler PulseWindow::PulseWindow(BRect rect) : 25*80f47570SAxel Dörfler BWindow(rect, "Pulse", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) 26*80f47570SAxel Dörfler { 2752a38012Sejakowatz SetPulseRate(200000); 2852a38012Sejakowatz 2952a38012Sejakowatz PulseApp *pulseapp = (PulseApp *)be_app; 3052a38012Sejakowatz BRect bounds = Bounds(); 31*80f47570SAxel Dörfler fNormalPulseView = new NormalPulseView(bounds); 32*80f47570SAxel Dörfler AddChild(fNormalPulseView); 3352a38012Sejakowatz 34*80f47570SAxel Dörfler fMiniPulseView = new MiniPulseView(bounds, "MiniPulseView", pulseapp->prefs); 35*80f47570SAxel Dörfler AddChild(fMiniPulseView); 3652a38012Sejakowatz 37*80f47570SAxel Dörfler fMode = pulseapp->prefs->window_mode; 38*80f47570SAxel Dörfler if (fMode == MINI_WINDOW_MODE) { 3952a38012Sejakowatz SetLook(B_MODAL_WINDOW_LOOK); 4052a38012Sejakowatz SetFeel(B_NORMAL_WINDOW_FEEL); 4152a38012Sejakowatz SetFlags(B_NOT_ZOOMABLE); 42*80f47570SAxel Dörfler fNormalPulseView->Hide(); 4352a38012Sejakowatz SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096); 4452a38012Sejakowatz ResizeTo(rect.Width(), rect.Height()); 45*80f47570SAxel Dörfler } else 46*80f47570SAxel Dörfler fMiniPulseView->Hide(); 4752a38012Sejakowatz 48*80f47570SAxel Dörfler fPrefsWindow = NULL; 4952a38012Sejakowatz } 5052a38012Sejakowatz 51*80f47570SAxel Dörfler 52*80f47570SAxel Dörfler PulseWindow::~PulseWindow() 53*80f47570SAxel Dörfler { 54*80f47570SAxel Dörfler PulseApp *pulseapp = (PulseApp *)be_app; 55*80f47570SAxel Dörfler 56*80f47570SAxel Dörfler if (fMode == NORMAL_WINDOW_MODE) 57*80f47570SAxel Dörfler pulseapp->prefs->normal_window_rect = Frame(); 58*80f47570SAxel Dörfler else if (fMode == MINI_WINDOW_MODE) 59*80f47570SAxel Dörfler pulseapp->prefs->mini_window_rect = Frame(); 60*80f47570SAxel Dörfler } 61*80f47570SAxel Dörfler 62*80f47570SAxel Dörfler 63*80f47570SAxel Dörfler void 64*80f47570SAxel Dörfler PulseWindow::MessageReceived(BMessage *message) 65*80f47570SAxel Dörfler { 6652a38012Sejakowatz switch (message->what) { 6752a38012Sejakowatz case PV_NORMAL_MODE: 6852a38012Sejakowatz case PV_MINI_MODE: 6952a38012Sejakowatz case PV_DESKBAR_MODE: 7052a38012Sejakowatz SetMode(message->what); 7152a38012Sejakowatz break; 7252a38012Sejakowatz case PRV_NORMAL_FADE_COLORS: 7352a38012Sejakowatz case PRV_NORMAL_CHANGE_COLOR: 74*80f47570SAxel Dörfler fNormalPulseView->UpdateColors(message); 7552a38012Sejakowatz break; 7652a38012Sejakowatz case PRV_MINI_CHANGE_COLOR: 77*80f47570SAxel Dörfler fMiniPulseView->UpdateColors(message); 7852a38012Sejakowatz break; 7952a38012Sejakowatz case PRV_QUIT: 80*80f47570SAxel Dörfler fPrefsWindow = NULL; 8152a38012Sejakowatz break; 8252a38012Sejakowatz case PV_PREFERENCES: { 8352a38012Sejakowatz // If the window is already open, bring it to the front 84*80f47570SAxel Dörfler if (fPrefsWindow != NULL) { 85*80f47570SAxel Dörfler fPrefsWindow->Activate(true); 8652a38012Sejakowatz break; 8752a38012Sejakowatz } 8852a38012Sejakowatz // Otherwise launch a new preferences window 8952a38012Sejakowatz PulseApp *pulseapp = (PulseApp *)be_app; 90*80f47570SAxel Dörfler fPrefsWindow = new PrefsWindow(pulseapp->prefs->prefs_window_rect, 9152a38012Sejakowatz "Pulse Preferences", new BMessenger(this), pulseapp->prefs); 92*80f47570SAxel Dörfler fPrefsWindow->Show(); 9352a38012Sejakowatz break; 9452a38012Sejakowatz } 9552a38012Sejakowatz case PV_ABOUT: { 9652a38012Sejakowatz BAlert *alert = new BAlert("Info", "Pulse\n\nBy David Ramsey and Arve Hjønnevåg\nRevised by Daniel Switkin", "OK"); 9752a38012Sejakowatz // Use the asynchronous version so we don't block the window's thread 9852a38012Sejakowatz alert->Go(NULL); 9952a38012Sejakowatz break; 10052a38012Sejakowatz } 10152a38012Sejakowatz case PV_QUIT: 10252a38012Sejakowatz PostMessage(B_QUIT_REQUESTED); 10352a38012Sejakowatz break; 10452a38012Sejakowatz case PV_CPU_MENU_ITEM: 10552a38012Sejakowatz // Call the correct version based on whose menu sent the message 106*80f47570SAxel Dörfler if (fMiniPulseView->IsHidden()) 107*80f47570SAxel Dörfler fNormalPulseView->ChangeCPUState(message); 108*80f47570SAxel Dörfler else 109*80f47570SAxel Dörfler fMiniPulseView->ChangeCPUState(message); 11052a38012Sejakowatz break; 11152a38012Sejakowatz default: 11252a38012Sejakowatz BWindow::MessageReceived(message); 11352a38012Sejakowatz break; 11452a38012Sejakowatz } 11552a38012Sejakowatz } 11652a38012Sejakowatz 117*80f47570SAxel Dörfler 118*80f47570SAxel Dörfler void 119*80f47570SAxel Dörfler PulseWindow::SetMode(int newmode) 120*80f47570SAxel Dörfler { 12152a38012Sejakowatz PulseApp *pulseapp = (PulseApp *)be_app; 12252a38012Sejakowatz switch (newmode) { 12352a38012Sejakowatz case PV_NORMAL_MODE: 124*80f47570SAxel Dörfler if (fMode == MINI_WINDOW_MODE) { 12552a38012Sejakowatz pulseapp->prefs->mini_window_rect = Frame(); 12652a38012Sejakowatz pulseapp->prefs->window_mode = NORMAL_WINDOW_MODE; 12752a38012Sejakowatz pulseapp->prefs->Save(); 12852a38012Sejakowatz } 129*80f47570SAxel Dörfler fMiniPulseView->Hide(); 130*80f47570SAxel Dörfler fNormalPulseView->Show(); 131*80f47570SAxel Dörfler fMode = NORMAL_WINDOW_MODE; 13252a38012Sejakowatz SetType(B_TITLED_WINDOW); 13352a38012Sejakowatz SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE); 13452a38012Sejakowatz ResizeTo(pulseapp->prefs->normal_window_rect.IntegerWidth(), 13552a38012Sejakowatz pulseapp->prefs->normal_window_rect.IntegerHeight()); 13652a38012Sejakowatz MoveTo(pulseapp->prefs->normal_window_rect.left, 13752a38012Sejakowatz pulseapp->prefs->normal_window_rect.top); 13852a38012Sejakowatz break; 13952a38012Sejakowatz case PV_MINI_MODE: 140*80f47570SAxel Dörfler if (fMode == NORMAL_WINDOW_MODE) { 14152a38012Sejakowatz pulseapp->prefs->normal_window_rect = Frame(); 14252a38012Sejakowatz pulseapp->prefs->window_mode = MINI_WINDOW_MODE; 14352a38012Sejakowatz pulseapp->prefs->Save(); 14452a38012Sejakowatz } 145*80f47570SAxel Dörfler fNormalPulseView->Hide(); 146*80f47570SAxel Dörfler fMiniPulseView->Show(); 147*80f47570SAxel Dörfler fMode = MINI_WINDOW_MODE; 14852a38012Sejakowatz SetLook(B_MODAL_WINDOW_LOOK); 14952a38012Sejakowatz SetFeel(B_NORMAL_WINDOW_FEEL); 15052a38012Sejakowatz SetFlags(B_NOT_ZOOMABLE); 15152a38012Sejakowatz SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096); 15252a38012Sejakowatz ResizeTo(pulseapp->prefs->mini_window_rect.IntegerWidth(), 15352a38012Sejakowatz pulseapp->prefs->mini_window_rect.IntegerHeight()); 15452a38012Sejakowatz MoveTo(pulseapp->prefs->mini_window_rect.left, 15552a38012Sejakowatz pulseapp->prefs->mini_window_rect.top); 15652a38012Sejakowatz break; 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. 16152a38012Sejakowatz pulseapp->prefs->window_mode = DESKBAR_MODE; 16252a38012Sejakowatz PostMessage(B_QUIT_REQUESTED); 16352a38012Sejakowatz break; 16452a38012Sejakowatz } 16552a38012Sejakowatz } 16652a38012Sejakowatz 16752a38012Sejakowatz 168*80f47570SAxel Dörfler bool 169*80f47570SAxel Dörfler PulseWindow::QuitRequested() 170*80f47570SAxel Dörfler { 17152a38012Sejakowatz be_app->PostMessage(B_QUIT_REQUESTED); 17252a38012Sejakowatz return true; 17352a38012Sejakowatz } 174