From e20b1568685a9ec4cff19ec424cbc5e0c67e1852 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Sun, 17 Jan 2010 05:12:09 +0000 Subject: [PATCH] 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 --- src/apps/pulse/CPUButton.cpp | 80 +++++++++++++++++++++++++++--- src/apps/pulse/CPUButton.h | 2 + src/apps/pulse/Jamfile | 2 +- src/apps/pulse/NormalPulseView.cpp | 19 +------ 4 files changed, 78 insertions(+), 25 deletions(-) diff --git a/src/apps/pulse/CPUButton.cpp b/src/apps/pulse/CPUButton.cpp index 574200a0f8..81bcdbe2bb 100644 --- a/src/apps/pulse/CPUButton.cpp +++ b/src/apps/pulse/CPUButton.cpp @@ -14,6 +14,10 @@ #include #include +#include +#include + +#include #include @@ -37,6 +41,13 @@ CPUButton::CPUButton(BMessage *message) : BControl(message) { fReplicant = true; + + /* We remove the dragger if we are in deskbar */ + if (CountChildren() > 1) + RemoveChild(ChildAt(1)); + + ResizeBy(-7, -7); + _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 void CPUButton::Draw(BRect rect) @@ -63,7 +86,16 @@ CPUButton::Draw(BRect rect) bool value = (bool)Value(); SetHighColor(value ? fOnColor : fOffColor); + if (!fReplicant) { + SetLowColor(Parent()->LowColor()); + FillRect(Bounds(), B_SOLID_LOW); + } + BRect bounds = Bounds(); + if (!fReplicantInDeskbar) { + bounds.bottom -= 7; + bounds.right -= 7; + } BRect color_rect(bounds); color_rect.InsetBy(2, 2); if (value) { @@ -148,19 +180,40 @@ CPUButton::Draw(BRect rect) void CPUButton::MouseDown(BPoint point) { - SetValue(!Value()); - SetTracking(true); - SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); + BPoint mousePosition; + uint32 mouseButtons; + + 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 CPUButton::MouseUp(BPoint point) { - if (Bounds().Contains(point)) - Invoke(); + if (IsTracking()) { + if (Bounds().Contains(point)) + Invoke(); - SetTracking(false); + SetTracking(false); + } } @@ -225,6 +278,10 @@ CPUButton::MessageReceived(BMessage *message) SetValue(!Value()); break; } + case kDeleteReplicant: { + Window()->PostMessage(kDeleteReplicant, this, NULL); + break; + } default: BControl::MessageReceived(message); break; @@ -248,14 +305,24 @@ CPUButton::AttachedToWindow() SetTarget(this); SetFont(be_plain_font); SetFontSize(10); + + fReplicantInDeskbar = false; if (fReplicant) { + if (strcmp(Window()->Title(), "Deskbar")) { + // return to original size + ResizeBy(7, 7); + _AddDragger(); + } else + fReplicantInDeskbar = true; + Prefs *prefs = new Prefs(); UpdateColors(prefs->normal_bar_color); delete prefs; } else { PulseApp *pulseapp = (PulseApp *)be_app; UpdateColors(pulseapp->prefs->normal_bar_color); + _AddDragger(); } BMessenger messenger(this); @@ -269,4 +336,3 @@ CPUButton::DetachedFromWindow() { delete fPulseRunner; } - diff --git a/src/apps/pulse/CPUButton.h b/src/apps/pulse/CPUButton.h index b4f89b2f7b..f436b40594 100644 --- a/src/apps/pulse/CPUButton.h +++ b/src/apps/pulse/CPUButton.h @@ -37,11 +37,13 @@ class CPUButton : public BControl { private: void _InitData(); + void _AddDragger(); rgb_color fOnColor, fOffColor; bool fReplicant; int32 fCPU; BMessageRunner *fPulseRunner; + bool fReplicantInDeskbar; }; #endif // CPUBUTTON_H diff --git a/src/apps/pulse/Jamfile b/src/apps/pulse/Jamfile index 6db294044a..0484e43261 100644 --- a/src/apps/pulse/Jamfile +++ b/src/apps/pulse/Jamfile @@ -1,7 +1,7 @@ SubDir HAIKU_TOP src apps pulse ; UsePrivateSystemHeaders ; -UsePrivateHeaders shared ; +UsePrivateHeaders shared interface app ; if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) { UseHeaders [ FDirName $(HAIKU_TOP) headers os kernel ] : true ; } diff --git a/src/apps/pulse/NormalPulseView.cpp b/src/apps/pulse/NormalPulseView.cpp index 9f4f863d4e..3cfd2b6a07 100644 --- a/src/apps/pulse/NormalPulseView.cpp +++ b/src/apps/pulse/NormalPulseView.cpp @@ -73,27 +73,12 @@ NormalPulseView::NormalPulseView(BRect rect) AddChild(fProgressBars[x]); r.Set(CPUBUTTON_MLEFT, CPUBUTTON_MTOP + ITEM_OFFSET * x, - CPUBUTTON_MLEFT + CPUBUTTON_WIDTH, - CPUBUTTON_MTOP + ITEM_OFFSET * x + CPUBUTTON_HEIGHT); + CPUBUTTON_MLEFT + CPUBUTTON_WIDTH + 7, + CPUBUTTON_MTOP + ITEM_OFFSET * x + CPUBUTTON_HEIGHT + 7); char temp[4]; sprintf(temp, "%d", x + 1); fCpuButtons[x] = new CPUButton(r, "CPUButton", temp, NULL); 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) {