1 //**************************************************************************************** 2 // 3 // File: PulseWindow.cpp 4 // 5 // Written by: Daniel Switkin 6 // 7 // Copyright 1999, Be Incorporated 8 // 9 //**************************************************************************************** 10 11 #include "PulseWindow.h" 12 #include "PulseApp.h" 13 #include "Common.h" 14 #include "DeskbarPulseView.h" 15 #include <interface/Alert.h> 16 #include <interface/Deskbar.h> 17 #include <stdlib.h> 18 #include <string.h> 19 20 PulseWindow::PulseWindow(BRect rect) : 21 BWindow(rect, "Pulse", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) { 22 23 SetPulseRate(200000); 24 25 PulseApp *pulseapp = (PulseApp *)be_app; 26 BRect bounds = Bounds(); 27 normalpulseview = new NormalPulseView(bounds); 28 AddChild(normalpulseview); 29 30 minipulseview = new MiniPulseView(bounds, "MiniPulseView", pulseapp->prefs); 31 AddChild(minipulseview); 32 33 mode = pulseapp->prefs->window_mode; 34 if (mode == MINI_WINDOW_MODE) { 35 SetLook(B_MODAL_WINDOW_LOOK); 36 SetFeel(B_NORMAL_WINDOW_FEEL); 37 SetFlags(B_NOT_ZOOMABLE); 38 normalpulseview->Hide(); 39 SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096); 40 ResizeTo(rect.Width(), rect.Height()); 41 } else minipulseview->Hide(); 42 43 prefswindow = NULL; 44 } 45 46 void PulseWindow::MessageReceived(BMessage *message) { 47 switch(message->what) { 48 case PV_NORMAL_MODE: 49 case PV_MINI_MODE: 50 case PV_DESKBAR_MODE: 51 SetMode(message->what); 52 break; 53 case PRV_NORMAL_FADE_COLORS: 54 case PRV_NORMAL_CHANGE_COLOR: 55 normalpulseview->UpdateColors(message); 56 break; 57 case PRV_MINI_CHANGE_COLOR: 58 minipulseview->UpdateColors(message); 59 break; 60 case PRV_QUIT: 61 prefswindow = NULL; 62 break; 63 case PV_PREFERENCES: { 64 // If the window is already open, bring it to the front 65 if (prefswindow != NULL) { 66 prefswindow->Activate(true); 67 break; 68 } 69 // Otherwise launch a new preferences window 70 PulseApp *pulseapp = (PulseApp *)be_app; 71 prefswindow = new PrefsWindow(pulseapp->prefs->prefs_window_rect, 72 "Pulse Preferences", new BMessenger(this), pulseapp->prefs); 73 prefswindow->Show(); 74 break; 75 } 76 case PV_ABOUT: { 77 BAlert *alert = new BAlert("Info", "Pulse\n\nBy David Ramsey and Arve Hjønnevåg\nRevised by Daniel Switkin", "OK"); 78 // Use the asynchronous version so we don't block the window's thread 79 alert->Go(NULL); 80 break; 81 } 82 case PV_QUIT: 83 PostMessage(B_QUIT_REQUESTED); 84 break; 85 case PV_CPU_MENU_ITEM: 86 // Call the correct version based on whose menu sent the message 87 if (minipulseview->IsHidden()) normalpulseview->ChangeCPUState(message); 88 else minipulseview->ChangeCPUState(message); 89 break; 90 default: 91 BWindow::MessageReceived(message); 92 break; 93 } 94 } 95 96 void PulseWindow::SetMode(int newmode) { 97 PulseApp *pulseapp = (PulseApp *)be_app; 98 switch (newmode) { 99 case PV_NORMAL_MODE: 100 if (mode == MINI_WINDOW_MODE) { 101 pulseapp->prefs->mini_window_rect = Frame(); 102 pulseapp->prefs->window_mode = NORMAL_WINDOW_MODE; 103 pulseapp->prefs->Save(); 104 } 105 minipulseview->Hide(); 106 normalpulseview->Show(); 107 mode = NORMAL_WINDOW_MODE; 108 SetType(B_TITLED_WINDOW); 109 SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE); 110 ResizeTo(pulseapp->prefs->normal_window_rect.IntegerWidth(), 111 pulseapp->prefs->normal_window_rect.IntegerHeight()); 112 MoveTo(pulseapp->prefs->normal_window_rect.left, 113 pulseapp->prefs->normal_window_rect.top); 114 break; 115 case PV_MINI_MODE: 116 if (mode == NORMAL_WINDOW_MODE) { 117 pulseapp->prefs->normal_window_rect = Frame(); 118 pulseapp->prefs->window_mode = MINI_WINDOW_MODE; 119 pulseapp->prefs->Save(); 120 } 121 normalpulseview->Hide(); 122 minipulseview->Show(); 123 mode = MINI_WINDOW_MODE; 124 SetLook(B_MODAL_WINDOW_LOOK); 125 SetFeel(B_NORMAL_WINDOW_FEEL); 126 SetFlags(B_NOT_ZOOMABLE); 127 SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096); 128 ResizeTo(pulseapp->prefs->mini_window_rect.IntegerWidth(), 129 pulseapp->prefs->mini_window_rect.IntegerHeight()); 130 MoveTo(pulseapp->prefs->mini_window_rect.left, 131 pulseapp->prefs->mini_window_rect.top); 132 break; 133 case PV_DESKBAR_MODE: 134 // Do not set window's mode to DESKBAR_MODE because the 135 // destructor needs to save the correct BRect. ~PulseApp() 136 // will handle launching the replicant after our prefs are saved. 137 pulseapp->prefs->window_mode = DESKBAR_MODE; 138 PostMessage(B_QUIT_REQUESTED); 139 break; 140 } 141 } 142 143 PulseWindow::~PulseWindow() { 144 PulseApp *pulseapp = (PulseApp *)be_app; 145 if (mode == NORMAL_WINDOW_MODE) pulseapp->prefs->normal_window_rect = Frame(); 146 else if (mode == MINI_WINDOW_MODE) pulseapp->prefs->mini_window_rect = Frame(); 147 } 148 149 bool PulseWindow::QuitRequested() { 150 be_app->PostMessage(B_QUIT_REQUESTED); 151 return true; 152 } 153