Skip to content

Commit

Permalink
Add show/hide functionality to deskbar replicant, create GroupHeaderV…
Browse files Browse the repository at this point in the history
…iew class to fix

drawing issues with AddGroupView, add scrollbar to notification center (not functional
yet)
  • Loading branch information
Brian Hill committed Jan 21, 2017
1 parent ee321d2 commit 1e379c5
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 241 deletions.
199 changes: 49 additions & 150 deletions src/servers/notification/AppGroupView.cpp
Expand Up @@ -14,7 +14,6 @@
#include <algorithm>

#include <Application.h>
#include <ControlLook.h>
#include <GroupLayout.h>
#include <GroupView.h>

Expand All @@ -24,153 +23,14 @@
#include "NotificationView.h"


static const int kHeaderSize = 23;


AppGroupView::AppGroupView(NotificationWindow* win, const char* label)
:
BGroupView("appGroup", B_VERTICAL, 0),
fLabel(label),
fParent(win),
fCollapsed(false),
fCloseClicked(false)
{
SetFlags(Flags() | B_WILL_DRAW);

static_cast<BGroupLayout*>(GetLayout())->SetInsets(0, kHeaderSize, 0, 0);
}


void
AppGroupView::Draw(BRect updateRect)
fParent(win)
{
rgb_color menuColor = ViewColor();
BRect bounds = Bounds();
rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT);
rgb_color vlight = tint_color(menuColor, B_LIGHTEN_2_TINT);
bounds.bottom = bounds.top + kHeaderSize;

// Draw the header background
SetHighColor(tint_color(menuColor, 1.22));
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
if (fParent->Type() == SHELVED_NOTIFICATIONS_WINDOW) {
SetLowColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_2_TINT));
SetViewColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_2_TINT));
Invalidate();
}
StrokeLine(bounds.LeftTop(), bounds.LeftBottom());
uint32 borders = BControlLook::B_TOP_BORDER
| BControlLook::B_BOTTOM_BORDER | BControlLook::B_RIGHT_BORDER;

be_control_look->DrawButtonBackground(this, bounds, bounds, menuColor,
0, borders);

// Draw the buttons
fCollapseRect.top = (kHeaderSize - kExpandSize) / 2;
fCollapseRect.left = kEdgePadding * 3;
fCollapseRect.right = fCollapseRect.left + 1.5 * kExpandSize;
fCollapseRect.bottom = fCollapseRect.top + kExpandSize;

fCloseRect = bounds;
fCloseRect.top = (kHeaderSize - kCloseSize) / 2;
// Take off the 1 to line this up with the close button on the
// notification view
fCloseRect.right -= kEdgePadding * 3 - 1;
fCloseRect.left = fCloseRect.right - kCloseSize;
fCloseRect.bottom = fCloseRect.top + kCloseSize;

uint32 arrowDirection = fCollapsed
? BControlLook::B_DOWN_ARROW : BControlLook::B_UP_ARROW;
be_control_look->DrawArrowShape(this, fCollapseRect, fCollapseRect,
LowColor(), arrowDirection, 0, B_DARKEN_3_TINT);

SetPenSize(kPenSize);

// Draw the dismiss widget
_DrawCloseButton(updateRect);

// Draw the label
SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
BString label = fLabel;
if (fCollapsed)
label << " (" << fInfo.size() << ")";

SetFont(be_bold_font);
font_height fontHeight;
GetFontHeight(&fontHeight);
float y = (bounds.top + bounds.bottom - ceilf(fontHeight.ascent)
- ceilf(fontHeight.descent)) / 2.0 + ceilf(fontHeight.ascent);

DrawString(label.String(),
BPoint(fCollapseRect.right + 4 * kEdgePadding, y));
}


void
AppGroupView::_DrawCloseButton(const BRect& updateRect)
{
PushState();
BRect closeRect = fCloseRect;

rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
float tint = B_DARKEN_2_TINT;

if (fCloseClicked) {
BRect buttonRect(closeRect.InsetByCopy(-4, -4));
be_control_look->DrawButtonFrame(this, buttonRect, updateRect,
base, base,
BControlLook::B_ACTIVATED | BControlLook::B_BLEND_FRAME);
be_control_look->DrawButtonBackground(this, buttonRect, updateRect,
base, BControlLook::B_ACTIVATED);
tint *= 1.2;
closeRect.OffsetBy(1, 1);
}

base = tint_color(base, tint);
SetHighColor(base);
SetPenSize(2);
StrokeLine(closeRect.LeftTop(), closeRect.RightBottom());
StrokeLine(closeRect.LeftBottom(), closeRect.RightTop());
PopState();
}


void
AppGroupView::MouseDown(BPoint point)
{
if (BRect(fCloseRect).InsetBySelf(-5, -5).Contains(point)) {
int32 children = fInfo.size();
for (int32 i = 0; i < children; i++) {
fInfo[i]->RemoveSelf();
delete fInfo[i];
}

fInfo.clear();

// Remove ourselves from the parent view
BMessage message(kRemoveGroupView);
message.AddPointer("view", this);
fParent->PostMessage(&message);
} else if (BRect(fCollapseRect).InsetBySelf(-5, -5).Contains(point)) {
fCollapsed = !fCollapsed;
int32 children = fInfo.size();
if (fCollapsed) {
for (int32 i = 0; i < children; i++) {
if (!fInfo[i]->IsHidden())
fInfo[i]->Hide();
}
GetLayout()->SetExplicitMaxSize(GetLayout()->MinSize());
} else {
for (int32 i = 0; i < children; i++) {
if (fInfo[i]->IsHidden())
fInfo[i]->Show();
}
GetLayout()->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNSET));
}

InvalidateLayout();
Invalidate(); // Need to redraw the collapse indicator and title
}
fHeaderView = new GroupHeaderView(this, label, fParent->Type());
GetLayout()->AddView(fHeaderView);
}


Expand All @@ -191,7 +51,7 @@ AppGroupView::MessageReceived(BMessage* msg)

fInfo.erase(vIt);
view->RemoveSelf();

if (msg->what != kTimeoutExpired)
delete view;

Expand All @@ -203,13 +63,52 @@ AppGroupView::MessageReceived(BMessage* msg)
removeSelfMessage.AddPointer("view", this);
fParent->PostMessage(&removeSelfMessage);
}

// Send message to add view to notification center
if (msg->what == kTimeoutExpired) {
msg->what = kAddView;
msg->what = kAddViewToCenter;
be_app->PostMessage(msg);
}


break;
}

case kHeaderClosed:
{
int32 children = fInfo.size();
for (int32 i = 0; i < children; i++) {
fInfo[i]->RemoveSelf();
delete fInfo[i];
}
fInfo.clear();

// Remove ourselves from the parent view
BMessage message(kRemoveGroupView);
message.AddPointer("view", this);
fParent->PostMessage(&message);
break;
}

case kHeaderCollapsed:
{
int32 children = fInfo.size();
if (fHeaderView->Collapsed()) {
for (int32 i = 0; i < children; i++) {
if (!fInfo[i]->IsHidden())
fInfo[i]->Hide();
}
// GetLayout()->SetExplicitMaxSize(BSize(B_SIZE_UNSET,
// GetLayout()->MinSize().Height()));
} else {
for (int32 i = 0; i < children; i++) {
if (fInfo[i]->IsHidden())
fInfo[i]->Show();
}
// GetLayout()->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNSET));
}

InvalidateLayout();
Invalidate(); // Need to redraw the collapse indicator and title
break;
}
default:
Expand All @@ -233,10 +132,10 @@ AppGroupView::AddInfo(NotificationView* view)
fParent->NotificationViewSwapped(oldView, view);
oldView->RemoveSelf();
delete oldView;

fInfo[i] = view;
found = true;

break;
}
}
Expand All @@ -256,7 +155,7 @@ AppGroupView::AddInfo(NotificationView* view)

if (IsHidden())
Show();
if (view->IsHidden(view) && !fCollapsed)
if (view->IsHidden(view) && !fHeaderView->Collapsed())
view->Show();
}

Expand Down
10 changes: 3 additions & 7 deletions src/servers/notification/AppGroupView.h
Expand Up @@ -13,6 +13,8 @@
#include <GroupView.h>
#include <String.h>

#include "GroupHeaderView.h"

class BGroupView;

class NotificationWindow;
Expand All @@ -24,9 +26,7 @@ class AppGroupView : public BGroupView {
public:
AppGroupView(NotificationWindow* win, const char* label);

virtual void MouseDown(BPoint point);
virtual void MessageReceived(BMessage* msg);
void Draw(BRect updateRect);

bool HasChildren();
int32 ChildrenCount();
Expand All @@ -36,15 +36,11 @@ class AppGroupView : public BGroupView {
const BString& Group() const;

private:
void _DrawCloseButton(const BRect& updateRect);

BString fLabel;
NotificationWindow* fParent;
infoview_t fInfo;
bool fCollapsed;
BRect fCloseRect;
BRect fCollapseRect;
bool fCloseClicked;
GroupHeaderView* fHeaderView;
};

#endif // _APP_GROUP_VIEW_H

0 comments on commit 1e379c5

Please sign in to comment.