Skip to content

Commit

Permalink
* NotificationViewer: Add mark all as read button.
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Jun 15, 2024
1 parent 9df03d5 commit 71bd260
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@
#define IDC_COMBO_GUI_SCALE 890
#define IDC_NOTIFICATION_HINT 891
#define IDC_TOGGLE_XSUPERPROPS 892
#define IDC_BUTTON1 893
#define IDC_NOTIFS_MARK_AS_READ 893
#define ID_FILE_PREFERENCES 1001
#define ID_FILE_STOPALLSPEECH 1002
#define ID_FILE_EXIT 1003
Expand Down Expand Up @@ -469,7 +471,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 1069
#define _APS_NEXT_CONTROL_VALUE 893
#define _APS_NEXT_CONTROL_VALUE 894
#define _APS_NEXT_SYMED_VALUE 40000
#endif
#endif
4 changes: 3 additions & 1 deletion src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,8 @@ CAPTION "Notifications"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_MESSAGE_LIST,"Static",SS_BLACKRECT,7,27,335,205
LTEXT "Here are your recent notifications for this session.\nClick on a message to jump to it.",IDC_NOTIFICATION_HINT,7,7,335,17
LTEXT "Here are your recent notifications for this session.\nClick on a message to jump to it.",IDC_NOTIFICATION_HINT,7,7,315,17
DEFPUSHBUTTON "",IDC_NOTIFS_MARK_AS_READ,324,7,18,15,BS_ICON
END


Expand Down Expand Up @@ -872,6 +873,7 @@ IDD_DIALOG_NOTIFICATIONS AFX_DIALOG_LAYOUT
BEGIN
0,
0, 0, 100, 100,
0, 0, 0, 0,
0, 0, 0, 0
END

Expand Down
42 changes: 40 additions & 2 deletions src/windows/NotificationViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ void NotificationViewer::Initialize(HWND hWnd)

SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(g_hInstance, MAKEINTRESOURCE(DMIC(IDI_NOTIFICATION))));

HWND child = GetDlgItem(hWnd, IDC_MESSAGE_LIST);
HWND child = GetDlgItem(hWnd, IDC_NOTIFS_MARK_AS_READ);
int sm = GetSystemMetrics(SM_CXSMICON);
HICON hico = (HICON)LoadImage(g_hInstance, MAKEINTRESOURCE(DMIC(IDI_MARK_READ)), IMAGE_ICON, sm, sm, LR_SHARED | LR_CREATEDIBSECTION);
SendMessage(child, BM_SETIMAGE, IMAGE_ICON, (LPARAM) hico);

child = GetDlgItem(hWnd, IDC_MESSAGE_LIST);

GetWindowRect(child, &rect);
ScreenToClientRect(hWnd, &rect);
Expand Down Expand Up @@ -108,14 +113,34 @@ void NotificationViewer::Initialize(HWND hWnd)
void NotificationViewer::OnResize(HWND hWnd, int newWidth, int newHeight)
{
HWND hLabel = GetDlgItem(hWnd, IDC_NOTIFICATION_HINT);
HWND hButton = GetDlgItem(hWnd, IDC_NOTIFS_MARK_AS_READ);
HWND hList = GetDlgItem(hWnd, CID_MESSAGELIST);

RECT rcLabel{};
GetChildRect(hWnd, hLabel, &rcLabel);
RECT rcList{};
GetChildRect(hWnd, hList, &rcList);
RECT rcButton{};
GetChildRect(hWnd, hButton, &rcButton);

MoveWindow(hLabel, rcLabel.left, rcLabel.top, newWidth - rcLabel.left * 2, rcLabel.bottom - rcLabel.top, TRUE);
MoveWindow(
hButton,
newWidth - rcLabel.left - (rcButton.right - rcButton.left),
rcButton.top,
rcButton.right - rcButton.left,
rcButton.bottom - rcButton.top,
TRUE
);
InvalidateRect(hLabel, NULL, FALSE);

MoveWindow(
hLabel,
rcLabel.left,
rcLabel.top,
newWidth - rcLabel.left * 2 - (rcButton.right - rcButton.left),
rcLabel.bottom - rcLabel.top,
TRUE
);
InvalidateRect(hLabel, NULL, FALSE);

MoveWindow(
Expand Down Expand Up @@ -151,6 +176,13 @@ void NotificationViewer::OnClickMessage(Snowflake sf)
}
}

void NotificationViewer::MarkAllAsRead()
{
auto& notifs = GetNotificationManager()->GetNotifications();
for (auto& notif : notifs)
notif.m_bRead = true;
}

BOOL NotificationViewer::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
Expand All @@ -171,6 +203,12 @@ BOOL NotificationViewer::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
}

case WM_COMMAND:
if (wParam == IDC_NOTIFS_MARK_AS_READ) {
// Mark all notifications as read and exit.
MarkAllAsRead();
EndDialog(hWnd, 0);
return TRUE;
}
if (wParam == IDCANCEL) {
EndDialog(hWnd, 0);
return TRUE;
Expand Down
1 change: 1 addition & 0 deletions src/windows/NotificationViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class NotificationViewer
static void Initialize(HWND hWnd);
static void OnResize(HWND hWnd, int newWidth, int newHeight);
static void OnClickMessage(Snowflake sf);
static void MarkAllAsRead();
static BOOL CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

static POINT m_appearXY;
Expand Down

0 comments on commit 71bd260

Please sign in to comment.