1 //*****************************************************************************
3 // File: PulseWindow.cpp
5 // Written by: Daniel Switkin
7 // Copyright 1999, Be Incorporated
9 //*****************************************************************************
12 #include "PulseWindow.h"
15 #include "DeskbarPulseView.h"
26 #undef B_TRANSLATION_CONTEXT
27 #define B_TRANSLATION_CONTEXT "PulseWindow"
30 PulseWindow::PulseWindow(BRect rect
)
32 BWindow(rect
, B_TRANSLATE_SYSTEM_NAME("Pulse"), B_TITLED_WINDOW
,
33 B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
)
37 PulseApp
*pulseapp
= (PulseApp
*)be_app
;
38 BRect bounds
= Bounds();
39 fNormalPulseView
= new NormalPulseView(bounds
);
40 AddChild(fNormalPulseView
);
42 fMiniPulseView
= new MiniPulseView(bounds
, "MiniPulseView",
44 AddChild(fMiniPulseView
);
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());
55 fMiniPulseView
->Hide();
61 PulseWindow::~PulseWindow()
63 PulseApp
*pulseapp
= (PulseApp
*)be_app
;
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();
73 PulseWindow::MessageReceived(BMessage
*message
)
75 switch (message
->what
) {
79 SetMode(message
->what
);
81 case PRV_NORMAL_FADE_COLORS
:
82 case PRV_NORMAL_CHANGE_COLOR
:
83 fNormalPulseView
->UpdateColors(message
);
85 case PRV_MINI_CHANGE_COLOR
:
86 fMiniPulseView
->UpdateColors(message
);
91 case PV_PREFERENCES
: {
92 // If the window is already open, bring it to the front
93 if (fPrefsWindow
!= NULL
) {
94 fPrefsWindow
->Activate(true);
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),
102 fPrefsWindow
->Show();
106 PulseApp::ShowAbout(true);
110 PostMessage(B_QUIT_REQUESTED
);
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
);
117 fMiniPulseView
->ChangeCPUState(message
);
120 BWindow::MessageReceived(message
);
127 PulseWindow::SetMode(int newmode
)
129 PulseApp
*pulseapp
= (PulseApp
*)be_app
;
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();
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
);
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();
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
);
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
);
182 PulseWindow::QuitRequested()
184 be_app
->PostMessage(B_QUIT_REQUESTED
);