Pulse : Couldn't close Pulse CPUButton replicants
* It nows leave enough room to display the dragger into the replicant in most cases... * ...excepts in deskbar. Then it instead allows you to right click to access a popup menu allowing you to close the replicant. The dragger isn't shown due to space constraints. Fixing ticket #4244. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35110 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2a94c3b35b
commit
e20b156868
|
@ -14,6 +14,10 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
|
#include <Dragger.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
|
|
||||||
|
#include <ViewPrivate.h>
|
||||||
|
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
|
|
||||||
|
@ -37,6 +41,13 @@ CPUButton::CPUButton(BMessage *message)
|
||||||
: BControl(message)
|
: BControl(message)
|
||||||
{
|
{
|
||||||
fReplicant = true;
|
fReplicant = true;
|
||||||
|
|
||||||
|
/* We remove the dragger if we are in deskbar */
|
||||||
|
if (CountChildren() > 1)
|
||||||
|
RemoveChild(ChildAt(1));
|
||||||
|
|
||||||
|
ResizeBy(-7, -7);
|
||||||
|
|
||||||
_InitData();
|
_InitData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +67,18 @@ CPUButton::_InitData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CPUButton::_AddDragger()
|
||||||
|
{
|
||||||
|
BRect rect(Bounds());
|
||||||
|
rect.top = rect.bottom - 7;
|
||||||
|
rect.left = rect.right - 7;
|
||||||
|
BDragger* dragger = new BDragger(rect, this,
|
||||||
|
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||||
|
AddChild(dragger);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Redraw the button depending on whether it's up or down
|
//! Redraw the button depending on whether it's up or down
|
||||||
void
|
void
|
||||||
CPUButton::Draw(BRect rect)
|
CPUButton::Draw(BRect rect)
|
||||||
|
@ -63,7 +86,16 @@ CPUButton::Draw(BRect rect)
|
||||||
bool value = (bool)Value();
|
bool value = (bool)Value();
|
||||||
SetHighColor(value ? fOnColor : fOffColor);
|
SetHighColor(value ? fOnColor : fOffColor);
|
||||||
|
|
||||||
|
if (!fReplicant) {
|
||||||
|
SetLowColor(Parent()->LowColor());
|
||||||
|
FillRect(Bounds(), B_SOLID_LOW);
|
||||||
|
}
|
||||||
|
|
||||||
BRect bounds = Bounds();
|
BRect bounds = Bounds();
|
||||||
|
if (!fReplicantInDeskbar) {
|
||||||
|
bounds.bottom -= 7;
|
||||||
|
bounds.right -= 7;
|
||||||
|
}
|
||||||
BRect color_rect(bounds);
|
BRect color_rect(bounds);
|
||||||
color_rect.InsetBy(2, 2);
|
color_rect.InsetBy(2, 2);
|
||||||
if (value) {
|
if (value) {
|
||||||
|
@ -148,19 +180,40 @@ CPUButton::Draw(BRect rect)
|
||||||
void
|
void
|
||||||
CPUButton::MouseDown(BPoint point)
|
CPUButton::MouseDown(BPoint point)
|
||||||
{
|
{
|
||||||
SetValue(!Value());
|
BPoint mousePosition;
|
||||||
SetTracking(true);
|
uint32 mouseButtons;
|
||||||
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
|
||||||
|
GetMouse(&mousePosition, &mouseButtons);
|
||||||
|
|
||||||
|
if ((B_PRIMARY_MOUSE_BUTTON & mouseButtons) != 0) {
|
||||||
|
SetValue(!Value());
|
||||||
|
SetTracking(true);
|
||||||
|
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
||||||
|
} else if ((B_SECONDARY_MOUSE_BUTTON & mouseButtons) != 0
|
||||||
|
&& fReplicantInDeskbar) {
|
||||||
|
BPopUpMenu *menu = new BPopUpMenu("Deskbar menu");
|
||||||
|
menu->AddItem(new BMenuItem("About Pulse" B_UTF8_ELLIPSIS,
|
||||||
|
new BMessage(B_ABOUT_REQUESTED)));
|
||||||
|
menu->AddSeparatorItem();
|
||||||
|
menu->AddItem(new BMenuItem("Remove replicant",
|
||||||
|
new BMessage(kDeleteReplicant)));
|
||||||
|
menu->SetTargetForItems(this);
|
||||||
|
|
||||||
|
ConvertToScreen(&point);
|
||||||
|
menu->Go(point, true, true, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CPUButton::MouseUp(BPoint point)
|
CPUButton::MouseUp(BPoint point)
|
||||||
{
|
{
|
||||||
if (Bounds().Contains(point))
|
if (IsTracking()) {
|
||||||
Invoke();
|
if (Bounds().Contains(point))
|
||||||
|
Invoke();
|
||||||
|
|
||||||
SetTracking(false);
|
SetTracking(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,6 +278,10 @@ CPUButton::MessageReceived(BMessage *message)
|
||||||
SetValue(!Value());
|
SetValue(!Value());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case kDeleteReplicant: {
|
||||||
|
Window()->PostMessage(kDeleteReplicant, this, NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
BControl::MessageReceived(message);
|
BControl::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
|
@ -248,14 +305,24 @@ CPUButton::AttachedToWindow()
|
||||||
SetTarget(this);
|
SetTarget(this);
|
||||||
SetFont(be_plain_font);
|
SetFont(be_plain_font);
|
||||||
SetFontSize(10);
|
SetFontSize(10);
|
||||||
|
|
||||||
|
fReplicantInDeskbar = false;
|
||||||
|
|
||||||
if (fReplicant) {
|
if (fReplicant) {
|
||||||
|
if (strcmp(Window()->Title(), "Deskbar")) {
|
||||||
|
// return to original size
|
||||||
|
ResizeBy(7, 7);
|
||||||
|
_AddDragger();
|
||||||
|
} else
|
||||||
|
fReplicantInDeskbar = true;
|
||||||
|
|
||||||
Prefs *prefs = new Prefs();
|
Prefs *prefs = new Prefs();
|
||||||
UpdateColors(prefs->normal_bar_color);
|
UpdateColors(prefs->normal_bar_color);
|
||||||
delete prefs;
|
delete prefs;
|
||||||
} else {
|
} else {
|
||||||
PulseApp *pulseapp = (PulseApp *)be_app;
|
PulseApp *pulseapp = (PulseApp *)be_app;
|
||||||
UpdateColors(pulseapp->prefs->normal_bar_color);
|
UpdateColors(pulseapp->prefs->normal_bar_color);
|
||||||
|
_AddDragger();
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessenger messenger(this);
|
BMessenger messenger(this);
|
||||||
|
@ -269,4 +336,3 @@ CPUButton::DetachedFromWindow()
|
||||||
{
|
{
|
||||||
delete fPulseRunner;
|
delete fPulseRunner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,13 @@ class CPUButton : public BControl {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _InitData();
|
void _InitData();
|
||||||
|
void _AddDragger();
|
||||||
|
|
||||||
rgb_color fOnColor, fOffColor;
|
rgb_color fOnColor, fOffColor;
|
||||||
bool fReplicant;
|
bool fReplicant;
|
||||||
int32 fCPU;
|
int32 fCPU;
|
||||||
BMessageRunner *fPulseRunner;
|
BMessageRunner *fPulseRunner;
|
||||||
|
bool fReplicantInDeskbar;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CPUBUTTON_H
|
#endif // CPUBUTTON_H
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
SubDir HAIKU_TOP src apps pulse ;
|
SubDir HAIKU_TOP src apps pulse ;
|
||||||
|
|
||||||
UsePrivateSystemHeaders ;
|
UsePrivateSystemHeaders ;
|
||||||
UsePrivateHeaders shared ;
|
UsePrivateHeaders shared interface app ;
|
||||||
if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
|
if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
|
||||||
UseHeaders [ FDirName $(HAIKU_TOP) headers os kernel ] : true ;
|
UseHeaders [ FDirName $(HAIKU_TOP) headers os kernel ] : true ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,27 +73,12 @@ NormalPulseView::NormalPulseView(BRect rect)
|
||||||
AddChild(fProgressBars[x]);
|
AddChild(fProgressBars[x]);
|
||||||
|
|
||||||
r.Set(CPUBUTTON_MLEFT, CPUBUTTON_MTOP + ITEM_OFFSET * x,
|
r.Set(CPUBUTTON_MLEFT, CPUBUTTON_MTOP + ITEM_OFFSET * x,
|
||||||
CPUBUTTON_MLEFT + CPUBUTTON_WIDTH,
|
CPUBUTTON_MLEFT + CPUBUTTON_WIDTH + 7,
|
||||||
CPUBUTTON_MTOP + ITEM_OFFSET * x + CPUBUTTON_HEIGHT);
|
CPUBUTTON_MTOP + ITEM_OFFSET * x + CPUBUTTON_HEIGHT + 7);
|
||||||
char temp[4];
|
char temp[4];
|
||||||
sprintf(temp, "%d", x + 1);
|
sprintf(temp, "%d", x + 1);
|
||||||
fCpuButtons[x] = new CPUButton(r, "CPUButton", temp, NULL);
|
fCpuButtons[x] = new CPUButton(r, "CPUButton", temp, NULL);
|
||||||
AddChild(fCpuButtons[x]);
|
AddChild(fCpuButtons[x]);
|
||||||
|
|
||||||
// If there is only 1 cpu it will be hidden below
|
|
||||||
// thus, no need to add the dragger as it will still
|
|
||||||
// be visible when replicants are turned on
|
|
||||||
if (fCpuCount > 1) {
|
|
||||||
BRect dragger_rect;
|
|
||||||
dragger_rect = r;
|
|
||||||
dragger_rect.top = dragger_rect.bottom;
|
|
||||||
dragger_rect.left = dragger_rect.right;
|
|
||||||
dragger_rect.bottom += 7;
|
|
||||||
dragger_rect.right += 7;
|
|
||||||
dragger_rect.OffsetBy(-1, -1);
|
|
||||||
BDragger *dragger = new BDragger(dragger_rect, fCpuButtons[x], 0);
|
|
||||||
AddChild(dragger);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fCpuCount == 1) {
|
if (fCpuCount == 1) {
|
||||||
|
|
Loading…
Reference in New Issue