Skip to content

Commit

Permalink
remove Wnd::OnEraseBkgnd()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Aug 8, 2024
1 parent 3bb9e5c commit 01d99b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 44 deletions.
45 changes: 19 additions & 26 deletions src/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@ struct NotificationWnd : Wnd {
void OnPaint(HDC hdc, PAINTSTRUCT* ps) override;
void OnTimer(UINT_PTR event_id) override;
LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) override;
bool OnEraseBkgnd(HDC) override;

void UpdateMessage(const char* msg, int timeoutMs = 0, bool highlight = false);

bool HasClose() const {
return true;
}

bool HasProgress() const {
return progressPerc >= 0;
}
Expand Down Expand Up @@ -220,9 +215,9 @@ void NotificationWnd::Layout(const char* message) {
int closeDx = DpiScale(hwnd, 16);
int leftMargin = DpiScale(hwnd, kCloseLeftMargin - padX);
rClose = {dx + leftMargin, padY, closeDx, closeDx + 2};
if (HasClose()) {
dx += leftMargin + closeDx + padX;
}

// close button
dx += leftMargin + closeDx + padX;
int progressDy = DpiScale(hwnd, kProgressDy);
rProgress = {padX, dy, szText.dx, progressDy};
if (HasProgress()) {
Expand Down Expand Up @@ -311,19 +306,17 @@ void NotificationWnd::OnPaint(HDC hdcIn, PAINTSTRUCT* ps) {
RECT rTmp = ToRECT(rTxt);
HdcDrawText(hdc, text, &rTmp, format);

if (HasClose()) {
Point curPos = HwndGetCursorPos(hwnd);
bool isHover = rClose.Contains(curPos);
DrawCloseButton(hdc, rClose, isHover);
Point curPos = HwndGetCursorPos(hwnd);
bool isHover = rClose.Contains(curPos);
DrawCloseButton(hdc, rClose, isHover);
#if 0
DrawCloseButtonArgs args;
args.hdc = hdc;
args.r = rClose;
args.r.Inflate(-5, -5);
args.isHover = isHover;
DrawCloseButton2(args);
DrawCloseButtonArgs args;
args.hdc = hdc;
args.r = rClose;
args.r.Inflate(-5, -5);
args.isHover = isHover;
DrawCloseButton2(args);
#endif
}

if (HasProgress()) {
rc = rProgress;
Expand Down Expand Up @@ -389,20 +382,20 @@ void NotificationWnd::OnTimer(UINT_PTR timerId) {
}
}

bool NotificationWnd::OnEraseBkgnd(HDC) {
// avoid flicker by telling we took care of erasing background
return true;
}

LRESULT NotificationWnd::WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
if (WM_SETCURSOR == msg && HasClose()) {
if (WM_SETCURSOR == msg) {
Point pt = HwndGetCursorPos(hwnd);
if (!pt.IsEmpty() && rClose.Contains(pt)) {
SetCursorCached(IDC_HAND);
return TRUE;
}
}

if (WM_ERASEBKGND == msg) {
// avoid flicker by telling we took care of erasing background
return TRUE;
}

if (WM_MOUSEMOVE == msg) {
HwndScheduleRepaint(hwnd);

Expand All @@ -417,7 +410,7 @@ LRESULT NotificationWnd::WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
return 0;
}

if (WM_LBUTTONUP == msg && HasClose()) {
if (WM_LBUTTONUP) {
Point pt = Point(GET_X_LPARAM(lp), GET_Y_LPARAM(lp));
if (rClose.Contains(pt)) {
// TODO a better way to delete myself
Expand Down
17 changes: 0 additions & 17 deletions src/wingui/WinGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,6 @@ int Wnd::OnCreate(CREATESTRUCT*) {
return 0;
}

// Called when the background of the window's client area needs to be erased.
// Override this function in your derived class to perform drawing tasks.
// Return Value: Return FALSE to also permit default erasure of the background
// Return TRUE to prevent default erasure of the background
bool Wnd::OnEraseBkgnd(HDC) {
return false;
}

void Wnd::OnContextMenu(Point ptScreen) {
if (!onContextMenu.IsValid()) {
return;
Expand Down Expand Up @@ -789,15 +781,6 @@ LRESULT Wnd::WndProcDefault(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
return 0;
}

case WM_ERASEBKGND: {
HDC dc = (HDC)(wparam);
BOOL preventErasure;

preventErasure = OnEraseBkgnd(dc);
if (preventErasure)
return TRUE;
} break;

// A set of messages to be reflected back to the control that generated them.
case WM_CTLCOLORBTN:
case WM_CTLCOLOREDIT:
Expand Down
1 change: 0 additions & 1 deletion src/wingui/WinGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ struct Wnd : ILayout {
virtual LRESULT OnMouseEvent(UINT msg, WPARAM wparam, LPARAM lparam);
virtual void OnMove(POINTS* pts);
virtual void OnPaint(HDC hdc, PAINTSTRUCT* ps);
virtual bool OnEraseBkgnd(HDC dc);
virtual void OnSize(UINT msg, UINT type, SIZE size);
virtual void OnTaskbarCallback(UINT msg, LPARAM lparam);
virtual void OnTimer(UINT_PTR event_id);
Expand Down

0 comments on commit 01d99b0

Please sign in to comment.