1 //***************************************************************************** 2 // 3 // File: PulseWindow.cpp 4 // 5 // Written by: Daniel Switkin 6 // 7 // Copyright 1999, Be Incorporated 8 // 9 //***************************************************************************** 10 11 12 #include "PulseWindow.h" 13 #include "PulseApp.h" 14 #include "Common.h" 15 #include "DeskbarPulseView.h" 16 17 #include <Alert.h> 18 #include <Catalog.h> 19 #include <Deskbar.h> 20 #include <Screen.h> 21 #include <TextView.h> 22 23 #include <stdlib.h> 24 #include <string.h> 25 26 #undef B_TRANSLATION_CONTEXT 27 #define B_TRANSLATION_CONTEXT "PulseWindow" 28 29 30 PulseWindow::PulseWindow(BRect rect) 31 : 32 BWindow(rect, B_TRANSLATE_SYSTEM_NAME("Pulse"), B_TITLED_WINDOW, 33 B_NOT_RESIZABLE | B_NOT_ZOOMABLE) 34 { 35 SetPulseRate(200000); 36 37 PulseApp *pulseapp = (PulseApp *)be_app; 38 BRect bounds = Bounds(); 39 fNormalPulseView = new NormalPulseView(bounds); 40 AddChild(fNormalPulseView); 41 42 fMiniPulseView = new MiniPulseView(bounds, "MiniPulseView", 43 pulseapp->prefs); 44 AddChild(fMiniPulseView); 45 46 fMode = pulseapp->prefs->window_mode; 47 if (fMode == MINI_WINDOW_MODE) { 48 SetLook(B_MODAL_WINDOW_LOOK); 49 SetFeel(B_NORMAL_WINDOW_FEEL); 50 SetFlags(B_NOT_ZOOMABLE); 51 fNormalPulseView->Hide(); 52 SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096); 53 ResizeTo(rect.Width(), rect.Height()); 54 } else 55 fMiniPulseView->Hide(); 56 57 fPrefsWindow = NULL; 58 } 59 60 61 PulseWindow::~PulseWindow() 62 { 63 PulseApp *pulseapp = (PulseApp *)be_app; 64 65 if (fMode == NORMAL_WINDOW_MODE) 66 pulseapp->prefs->normal_window_rect = Frame(); 67 else if (fMode == MINI_WINDOW_MODE) 68 pulseapp->prefs->mini_window_rect = Frame(); 69 } 70 71 72 void 73 PulseWindow::MessageReceived(BMessage *message) 74 { 75 switch (message->what) { 76 case PV_NORMAL_MODE: 77 case PV_MINI_MODE: 78 case PV_DESKBAR_MODE: 79 SetMode(message->what); 80 break; 81 case PRV_NORMAL_FADE_COLORS: 82 case PRV_NORMAL_CHANGE_COLOR: 83 fNormalPulseView->UpdateColors(message); 84 break; 85 case PRV_MINI_CHANGE_COLOR: 86 fMiniPulseView->UpdateColors(message); 87 break; 88 case PRV_QUIT: 89 fPrefsWindow = NULL; 90 break; 91 case PV_PREFERENCES: { 92 // If the window is already open, bring it to the front 93 if (fPrefsWindow != NULL) { 94 fPrefsWindow->Activate(true); 95 break; 96 } 97 // Otherwise launch a new preferences window 98 PulseApp *pulseapp = (PulseApp *)be_app; 99 fPrefsWindow = new PrefsWindow(pulseapp->prefs->prefs_window_rect, 100 B_TRANSLATE("Pulse settings"), new BMessenger(this), 101 pulseapp->prefs); 102 fPrefsWindow->Show(); 103 break; 104 } 105 case PV_ABOUT: { 106 PulseApp::ShowAbout(true); 107 break; 108 } 109 case PV_QUIT: 110 PostMessage(B_QUIT_REQUESTED); 111 break; 112 case PV_CPU_MENU_ITEM: 113 // Call the correct version based on whose menu sent the message 114 if (fMiniPulseView->IsHidden()) 115 fNormalPulseView->ChangeCPUState(message); 116 else 117 fMiniPulseView->ChangeCPUState(message); 118 break; 119 default: 120 BWindow::MessageReceived(message); 121 break; 122 } 123 } 124 125 126 void 127 PulseWindow::SetMode(int newmode) 128 { 129 PulseApp *pulseapp = (PulseApp *)be_app; 130 131 switch (newmode) { 132 case PV_NORMAL_MODE: 133 if (fMode == MINI_WINDOW_MODE) { 134 pulseapp->prefs->mini_window_rect = Frame(); 135 pulseapp->prefs->window_mode = NORMAL_WINDOW_MODE; 136 pulseapp->prefs->Save(); 137 } 138 fMiniPulseView->Hide(); 139 fNormalPulseView->Show(); 140 fMode = NORMAL_WINDOW_MODE; 141 SetType(B_TITLED_WINDOW); 142 SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE); 143 ResizeTo(pulseapp->prefs->normal_window_rect.IntegerWidth(), 144 pulseapp->prefs->normal_window_rect.IntegerHeight()); 145 MoveTo(pulseapp->prefs->normal_window_rect.left, 146 pulseapp->prefs->normal_window_rect.top); 147 MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN); 148 break; 149 150 case PV_MINI_MODE: 151 if (fMode == NORMAL_WINDOW_MODE) { 152 pulseapp->prefs->normal_window_rect = Frame(); 153 pulseapp->prefs->window_mode = MINI_WINDOW_MODE; 154 pulseapp->prefs->Save(); 155 } 156 fNormalPulseView->Hide(); 157 fMiniPulseView->Show(); 158 fMode = MINI_WINDOW_MODE; 159 SetLook(B_MODAL_WINDOW_LOOK); 160 SetFeel(B_NORMAL_WINDOW_FEEL); 161 SetFlags(B_NOT_ZOOMABLE); 162 SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096); 163 ResizeTo(pulseapp->prefs->mini_window_rect.IntegerWidth(), 164 pulseapp->prefs->mini_window_rect.IntegerHeight()); 165 MoveTo(pulseapp->prefs->mini_window_rect.left, 166 pulseapp->prefs->mini_window_rect.top); 167 MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN); 168 break; 169 170 case PV_DESKBAR_MODE: 171 // Do not set window's mode to DESKBAR_MODE because the 172 // destructor needs to save the correct BRect. ~PulseApp() 173 // will handle launching the replicant after our prefs are saved. 174 pulseapp->prefs->window_mode = DESKBAR_MODE; 175 PostMessage(B_QUIT_REQUESTED); 176 break; 177 } 178 } 179 180 181 bool 182 PulseWindow::QuitRequested() 183 { 184 be_app->PostMessage(B_QUIT_REQUESTED); 185 return true; 186 } 187