From ceff93db2355ddb23a5ab954a0c67ec40e0aa971 Mon Sep 17 00:00:00 2001 From: henrypp Date: Sun, 27 Oct 2019 16:45:46 +0600 Subject: [PATCH] window resizing fix --- src/helper.hpp | 2 +- src/log.cpp | 8 ++-- src/main.cpp | 89 +++++++++++++++++++++++-------------------- src/notifications.cpp | 11 ++++-- src/notifications.hpp | 1 + src/profile.cpp | 2 +- src/timer.cpp | 2 +- 7 files changed, 64 insertions(+), 51 deletions(-) diff --git a/src/helper.hpp b/src/helper.hpp index e4235773..2bfc0508 100644 --- a/src/helper.hpp +++ b/src/helper.hpp @@ -53,7 +53,7 @@ bool _app_item_get (EnumDataType type, size_t app_hash, rstring* display_name, r INT CALLBACK _app_listviewcompare_callback (LPARAM lparam1, LPARAM lparam2, LPARAM lparam); void _app_listviewsort (HWND hwnd, INT listview_id, INT column_id = INVALID_INT, bool is_notifycode = false); -void _app_refreshstatus (HWND hwnd, bool is_groups = true); +void _app_refreshstatus (HWND hwnd, INT listview_id = INVALID_INT); rstring _app_parsehostaddress_dns (LPCWSTR hostname, USHORT port); rstring _app_parsehostaddress_wsa (LPCWSTR hostname, USHORT port); diff --git a/src/log.cpp b/src/log.cpp index 7c68ad67..ca2d1679 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -861,18 +861,20 @@ UINT WINAPI LogThread (LPVOID lparam) { _r_fastlock_acquireshared (&lock_logbusy); - _r_fastlock_acquireexclusive (&lock_access); + _r_fastlock_acquireshared (&lock_access); const size_t app_hash = _app_addapplication (hwnd, ptr_log->path, 0, 0, 0, false, false, true); - _r_fastlock_releaseexclusive (&lock_access); + _r_fastlock_releaseshared (&lock_access); _r_fastlock_releaseshared (&lock_logbusy); INT app_listview_id = 0; if (_app_getappinfo (app_hash, InfoListviewId, &app_listview_id, sizeof (app_listview_id)) && app_listview_id == _app_gettab_id (hwnd)) + { _app_listviewsort (hwnd, app_listview_id); + _app_refreshstatus (hwnd, app_listview_id); + } - _app_refreshstatus (hwnd); _app_profile_save (); } diff --git a/src/main.cpp b/src/main.cpp index e7e3566f..e4b76787 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2506,26 +2506,29 @@ void _app_listviewsetpos (HWND hwnd, INT tab_id, INT listview_id) _r_wnd_resize (nullptr, hlistview, nullptr, rc_listview.left, rc_listview.top, _R_RECT_WIDTH (&rc_listview), _R_RECT_HEIGHT (&rc_listview), 0); } -void _app_resizewindow (HWND hwnd, INT width, INT height) +void _app_resizewindow (HWND hwnd, LPARAM lparam) { + SendDlgItemMessage (config.hrebar, IDC_TOOLBAR, TB_AUTOSIZE, 0, 0); + SendDlgItemMessage (hwnd, IDC_STATUSBAR, WM_SIZE, 0, 0); + RECT rc = {0}; SendDlgItemMessage (hwnd, IDC_STATUSBAR, SB_GETRECT, 0, (LPARAM)&rc); - const UINT statusbar_height = _R_RECT_HEIGHT (&rc); - const UINT rebar_height = (UINT)SendDlgItemMessage (hwnd, IDC_REBAR, RB_GETBARHEIGHT, 0, 0); + const INT listview_id = _app_gettab_id (hwnd); + const INT statusbar_height = _R_RECT_HEIGHT (&rc); + const INT rebar_height = (INT)SendDlgItemMessage (hwnd, IDC_REBAR, RB_GETBARHEIGHT, 0, 0); HDWP hdefer = BeginDeferWindowPos (2); - _r_wnd_resize (&hdefer, config.hrebar, nullptr, 0, 0, width, rebar_height, 0); - _r_wnd_resize (&hdefer, GetDlgItem (hwnd, IDC_TAB), nullptr, 0, rebar_height, width, height - rebar_height - statusbar_height, 0); + _r_wnd_resize (&hdefer, config.hrebar, nullptr, 0, 0, LOWORD (lparam), rebar_height, 0); + _r_wnd_resize (&hdefer, GetDlgItem (hwnd, IDC_TAB), nullptr, 0, rebar_height, LOWORD (lparam), HIWORD (lparam) - rebar_height - statusbar_height, 0); EndDeferWindowPos (hdefer); - _app_listviewsetpos (hwnd, IDC_TAB, _app_gettab_id (hwnd)); + _app_listviewsetpos (hwnd, IDC_TAB, listview_id); + _app_listviewresize (hwnd, listview_id); - // resize statusbar - SendDlgItemMessage (config.hrebar, IDC_TOOLBAR, TB_AUTOSIZE, 0, 0); - SendDlgItemMessage (hwnd, IDC_STATUSBAR, WM_SIZE, 0, 0); + _app_refreshstatus (hwnd, 0); } void _app_imagelist_init (HWND hwnd) @@ -3321,8 +3324,10 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) app.LocaleEnum ((HWND)GetSubMenu (hmenu, 2), LANG_MENU, true, IDX_LANGUAGE); // enum localizations - _app_listviewresize (hwnd, _app_gettab_id (hwnd)); - _app_refreshstatus (hwnd); + const INT listview_id = _app_gettab_id (hwnd); + + _app_listviewresize (hwnd, listview_id); + _app_refreshstatus (hwnd, listview_id); // refresh notification _r_wnd_addstyle (config.hnotification, IDC_RULES_BTN, app.IsClassicUI () ? WS_EX_STATICEDGE : 0, WS_EX_STATICEDGE, GWL_EXSTYLE); @@ -3378,7 +3383,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _app_listviewsetfont (hwnd, listview_id, true); _app_listviewresize (hwnd, listview_id); - _app_refreshstatus (hwnd, false); + _app_refreshstatus (hwnd, 0); break; } @@ -3550,7 +3555,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _app_listviewsetfont (hwnd, listview_id, false); _app_listviewresize (hwnd, listview_id); - _app_refreshstatus (hwnd); + _app_refreshstatus (hwnd, listview_id); _r_listview_redraw (hwnd, listview_id); @@ -3698,9 +3703,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (is_changed) { _app_listviewsort (hwnd, listview_id); + _app_refreshstatus (hwnd, listview_id); _app_profile_save (); - _app_refreshstatus (hwnd); } } @@ -3961,13 +3966,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case WM_SIZE: { - _app_resizewindow (hwnd, LOWORD (lparam), HIWORD (lparam)); - - _app_refreshstatus (hwnd, false); - - if (wparam == SIZE_RESTORED || wparam == SIZE_MAXIMIZED) - _app_listviewresize (hwnd, _app_gettab_id (hwnd)); - + _app_resizewindow (hwnd, lparam); break; } @@ -4121,10 +4120,12 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (_wfp_isfiltersapplying ()) break; + const INT listview_id = _app_gettab_id (hwnd); + app.ConfigInit (); _app_profile_load (hwnd); - _app_refreshstatus (hwnd); + _app_refreshstatus (hwnd, listview_id); if (_wfp_isfiltersinstalled ()) { @@ -4133,7 +4134,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else { - _r_listview_redraw (hwnd, _app_gettab_id (hwnd)); + _r_listview_redraw (hwnd, listview_id); } SetWindowLongPtr (hwnd, DWLP_MSGRESULT, TRUE); @@ -4200,9 +4201,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else if ((LOWORD (wparam) >= IDX_RULES_SPECIAL && LOWORD (wparam) <= IDX_RULES_SPECIAL + rules_arr.size ())) { - const INT app_listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); - if (!SendDlgItemMessage (hwnd, app_listview_id, LVM_GETSELECTEDCOUNT, 0, 0)) + if (!SendDlgItemMessage (hwnd, listview_id, LVM_GETSELECTEDCOUNT, 0, 0)) return FALSE; INT item = INVALID_INT; @@ -4218,9 +4219,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_rule) { - while ((item = (INT)SendDlgItemMessage (hwnd, app_listview_id, LVM_GETNEXTITEM, (WPARAM)item, LVNI_SELECTED)) != INVALID_INT) + while ((item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, (WPARAM)item, LVNI_SELECTED)) != INVALID_INT) { - const size_t app_hash = _r_listview_getitemlparam (hwnd, app_listview_id, item); + const size_t app_hash = _r_listview_getitemlparam (hwnd, listview_id, item); if (ptr_rule->is_forservices && (app_hash == config.ntoskrnl_hash || app_hash == config.svchost_hash)) continue; @@ -4254,7 +4255,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } _r_fastlock_acquireshared (&lock_checkbox); - _app_setappiteminfo (hwnd, app_listview_id, item, app_hash, ptr_app); + _app_setappiteminfo (hwnd, listview_id, item, app_hash, ptr_app); _r_fastlock_releaseshared (&lock_checkbox); } @@ -4283,9 +4284,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_obj_dereference (ptr_rule_object); - _app_listviewsort (hwnd, app_listview_id); + _app_listviewsort (hwnd, listview_id); + _app_refreshstatus (hwnd, listview_id); - _app_refreshstatus (hwnd); _app_profile_save (); return FALSE; @@ -4330,8 +4331,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _app_freeobjects_vec (rules); _app_listviewsort (hwnd, listview_id); + _app_refreshstatus (hwnd, listview_id); - _app_refreshstatus (hwnd); _app_profile_save (); return FALSE; @@ -4598,8 +4599,10 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_fastlock_releaseshared (&lock_access); - _app_listviewsort (hwnd, _app_gettab_id (hwnd)); - _app_refreshstatus (hwnd); + const INT listview_id = _app_gettab_id (hwnd); + + _app_listviewsort (hwnd, listview_id); + _app_refreshstatus (hwnd, listview_id); break; } @@ -5126,8 +5129,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) ) { _app_listviewsort (hwnd, listview_id); + _app_refreshstatus (hwnd, listview_id); - _app_refreshstatus (hwnd); _app_profile_save (); } @@ -5271,8 +5274,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (is_changed) { _app_listviewsort (hwnd, listview_id); + _app_refreshstatus (hwnd, listview_id); - _app_refreshstatus (hwnd); _app_profile_save (); } @@ -5345,7 +5348,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _app_addapplication (hwnd, ptr_network->path, 0, 0, 0, false, false, true); _r_fastlock_releaseexclusive (&lock_access); - _app_refreshstatus (hwnd); + _app_refreshstatus (hwnd, listview_id); _app_profile_save (); } @@ -5400,8 +5403,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } _app_listviewsort (hwnd, listview_id); + _app_refreshstatus (hwnd, listview_id); - _app_refreshstatus (hwnd); _app_profile_save (); } else @@ -5444,8 +5447,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } _app_listviewsort (hwnd, listview_id); + _app_refreshstatus (hwnd, listview_id); - _app_refreshstatus (hwnd); _app_profile_save (); } @@ -5471,7 +5474,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _app_addapplication (hwnd, ptr_network->path, 0, 0, 0, false, false, true); _r_fastlock_releaseshared (&lock_access); - _app_refreshstatus (hwnd); + _app_refreshstatus (hwnd, listview_id); _app_profile_save (); } @@ -5764,11 +5767,13 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _wfp_create3filters (_wfp_getenginehandle (), rules, __LINE__); _app_freeobjects_vec (rules); - _app_listviewsort (hwnd, _app_gettab_id (hwnd)); - - _app_refreshstatus (hwnd); _app_profile_save (); + const INT listview_id = _app_gettab_id (hwnd); + + _app_listviewsort (hwnd, listview_id); + _app_refreshstatus (hwnd, listview_id); + break; } diff --git a/src/notifications.cpp b/src/notifications.cpp index 8dc3d1a9..27520847 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -7,6 +7,11 @@ HFONT hfont_title = nullptr; HFONT hfont_link = nullptr; HFONT hfont_text = nullptr; +void _app_notifycreatewindow (HWND hwnd) +{ + config.hnotification = CreateDialog (app.GetHINSTANCE (), MAKEINTRESOURCE (IDD_NOTIFICATION), hwnd, &NotificationProc); +} + bool _app_notifycommand (HWND hwnd, INT button_id, time_t seconds) { size_t app_hash = _app_notifyget_id (hwnd, 0); @@ -66,7 +71,7 @@ bool _app_notifycommand (HWND hwnd, INT button_id, time_t seconds) _r_obj_dereference (ptr_app_object); - _app_refreshstatus (app.GetHWND ()); + _app_refreshstatus (app.GetHWND (), listview_id); _app_profile_save (); if (listview_id && _app_gettab_id (app.GetHWND ()) == listview_id) @@ -903,7 +908,7 @@ INT_PTR CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp _r_listview_redraw (app.GetHWND (), listview_id); } - _app_refreshstatus (app.GetHWND ()); + _app_refreshstatus (app.GetHWND (), listview_id); _app_profile_save (); } @@ -1134,7 +1139,7 @@ INT_PTR CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp } } - _app_refreshstatus (app.GetHWND ()); + _app_refreshstatus (app.GetHWND (), listview_id); _app_profile_save (); } else diff --git a/src/notifications.hpp b/src/notifications.hpp index 15115356..27f92098 100644 --- a/src/notifications.hpp +++ b/src/notifications.hpp @@ -3,6 +3,7 @@ #pragma once +void _app_notifycreatewindow (HWND hwnd); bool _app_notifycommand (HWND hwnd, INT button_id, time_t seconds); bool _app_notifyadd (HWND hwnd, PR_OBJECT ptr_log_object, PITEM_APP ptr_app); diff --git a/src/profile.cpp b/src/profile.cpp index d4361da0..8c6f6467 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -825,7 +825,7 @@ void _app_ruleblocklistset (HWND hwnd, INT spy_state, INT update_state, INT extr if (_app_gettab_id (hwnd) == listview_id) _app_listviewsort (hwnd, listview_id); - _app_refreshstatus (hwnd); + _app_refreshstatus (hwnd, listview_id); } if (is_instantapply) diff --git a/src/timer.cpp b/src/timer.cpp index 7a9ae155..c46877c6 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -166,7 +166,7 @@ void CALLBACK _app_timer_callback (PVOID lparam, BOOLEAN) _app_listviewsort (hwnd, listview_id); - _app_refreshstatus (hwnd); + _app_refreshstatus (hwnd, listview_id); _app_profile_save (); _r_listview_redraw (hwnd, listview_id);