diff --git a/simplewall.vcxproj b/simplewall.vcxproj index 2873dea5..0c8fd425 100644 --- a/simplewall.vcxproj +++ b/simplewall.vcxproj @@ -357,6 +357,7 @@ + @@ -382,6 +383,7 @@ + diff --git a/simplewall.vcxproj.filters b/simplewall.vcxproj.filters index be55c0e9..9b9ce9eb 100644 --- a/simplewall.vcxproj.filters +++ b/simplewall.vcxproj.filters @@ -69,6 +69,9 @@ Source Files + + Source Files + @@ -143,6 +146,9 @@ Header Files + + Header Files + diff --git a/src/controls.c b/src/controls.c index 2da2b1ee..d12bc597 100644 --- a/src/controls.c +++ b/src/controls.c @@ -3,324 +3,6 @@ #include "global.h" -BOOLEAN _app_ischeckboxlocked (_In_ HWND hwnd, _In_ INT ctrl_id) -{ - ULONG property_id; - PVOID context; - - property_id = (USHORT_MAX - ctrl_id); - - context = _r_wnd_getcontext (hwnd, property_id); - - return (context != NULL); -} - -VOID _app_setcheckboxlock (_In_ HWND hwnd, _In_ INT ctrl_id, _In_ BOOLEAN is_lock) -{ - ULONG property_id; - - property_id = (USHORT_MAX - ctrl_id); - - if (is_lock) - { - _r_wnd_setcontext (hwnd, property_id, INVALID_HANDLE_VALUE); - } - else - { - _r_wnd_removecontext (hwnd, property_id); - } -} - -INT _app_getlistviewbytab_id (_In_ HWND hwnd, _In_ INT tab_id) -{ - INT listview_id; - - if (tab_id == -1) - tab_id = _r_tab_getcurrentitem (hwnd, IDC_TAB); - - listview_id = (INT)_r_tab_getitemlparam (hwnd, IDC_TAB, tab_id); - - return listview_id; -} - -INT _app_getlistviewbytype_id (_In_ ENUM_TYPE_DATA type) -{ - if (type == DATA_APP_REGULAR || type == DATA_APP_DEVICE || type == DATA_APP_NETWORK || type == DATA_APP_PICO) - { - return IDC_APPS_PROFILE; - } - else if (type == DATA_APP_SERVICE) - { - return IDC_APPS_SERVICE; - } - else if (type == DATA_APP_UWP) - { - return IDC_APPS_UWP; - } - else if (type == DATA_RULE_BLOCKLIST) - { - return IDC_RULES_BLOCKLIST; - } - else if (type == DATA_RULE_SYSTEM) - { - return IDC_RULES_SYSTEM; - } - else if (type == DATA_RULE_SYSTEM_USER || type == DATA_RULE_USER) - { - return IDC_RULES_CUSTOM; - } - - return 0; -} - -VOID _app_setlistviewbylparam (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ ULONG flags, _In_ BOOLEAN is_app) -{ - INT listview_id; - - if (is_app) - { - listview_id = PtrToInt (_app_getappinfobyhash (lparam, INFO_LISTVIEW_ID)); - } - else - { - listview_id = PtrToInt (_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID)); - } - - if (listview_id) - { - if ((flags & PR_SETITEM_UPDATE)) - { - _app_updatelistviewbylparam (hwnd, listview_id, 0); - } - - if ((flags & PR_SETITEM_REDRAW)) - { - if (listview_id == _app_getcurrentlistview_id (hwnd)) - { - _r_listview_redraw (hwnd, listview_id, -1); - } - } - } -} - -VOID _app_updatelistviewbylparam (_In_ HWND hwnd, _In_ INT lparam, _In_ ULONG flags) -{ - INT listview_id; - ENUM_TYPE_DATA type; - - if (flags & PR_UPDATE_TYPE) - { - type = lparam; - - if (type == DATA_LISTVIEW_CURRENT) - { - listview_id = _app_getcurrentlistview_id (hwnd); - } - else - { - listview_id = _app_getlistviewbytype_id (type); - } - } - else - { - listview_id = lparam; - } - - if ((flags & PR_UPDATE_FORCE) || (listview_id == _app_getcurrentlistview_id (hwnd))) - { - if (!(flags & PR_UPDATE_NOREDRAW)) - _r_listview_redraw (hwnd, listview_id, -1); - - if (!(flags & PR_UPDATE_NOSETVIEW)) - { - _app_listviewsetfont (hwnd, listview_id); - _app_listviewsetview (hwnd, listview_id); - } - - if (!(flags & PR_UPDATE_NOREFRESH)) - _app_refreshgroups (hwnd, listview_id); - - if (!(flags & PR_UPDATE_NOSORT)) - _app_listviewsort (hwnd, listview_id, -1, FALSE); - - if (!(flags & PR_UPDATE_NORESIZE)) - _app_listviewresize (hwnd, listview_id, FALSE); - } - - _app_refreshstatus (hwnd); -} - -VOID _app_addlistviewapp (_In_ HWND hwnd, _In_ PITEM_APP ptr_app) -{ - INT listview_id; - INT item_id; - - listview_id = _app_getlistviewbytype_id (ptr_app->type); - - if (listview_id) - { - item_id = _r_listview_getitemcount (hwnd, listview_id); - - _app_setcheckboxlock (hwnd, listview_id, TRUE); - - _r_listview_additem_ex (hwnd, listview_id, item_id, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_createlistviewcontext (ptr_app->app_hash)); - _app_setappiteminfo (hwnd, listview_id, item_id, ptr_app); - - _app_setcheckboxlock (hwnd, listview_id, FALSE); - } -} - -VOID _app_addlistviewrule (_In_ HWND hwnd, _In_ PITEM_RULE ptr_rule, _In_ SIZE_T rule_idx, _In_ BOOLEAN is_forapp) -{ - INT listview_id; - INT item_id; - - listview_id = _app_getlistviewbytype_id (ptr_rule->type); - - if (listview_id) - { - item_id = _r_listview_getitemcount (hwnd, listview_id); - - _app_setcheckboxlock (hwnd, listview_id, TRUE); - - _r_listview_additem_ex (hwnd, listview_id, item_id, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_createlistviewcontext (rule_idx)); - _app_setruleiteminfo (hwnd, listview_id, item_id, ptr_rule, is_forapp); - - _app_setcheckboxlock (hwnd, listview_id, FALSE); - } -} - -VOID _app_showitembylparam (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ BOOLEAN is_app) -{ - INT listview_id; - INT item_id; - - if (is_app) - { - listview_id = PtrToInt (_app_getappinfobyhash (lparam, INFO_LISTVIEW_ID)); - } - else - { - listview_id = PtrToInt (_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID)); - } - - if (listview_id) - { - if (listview_id != _app_getcurrentlistview_id (hwnd)) - { - _app_listviewsort (hwnd, listview_id, -1, FALSE); - _app_listviewresize (hwnd, listview_id, FALSE); - } - - item_id = _app_getposition (hwnd, listview_id, lparam); - - if (item_id != -1) - { - _app_showitem (hwnd, listview_id, item_id, -1); - _r_wnd_toggle (hwnd, TRUE); - } - } -} - -VOID _app_updateitembyidx (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id) -{ - _r_listview_setitem_ex (hwnd, listview_id, item_id, 0, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, 0); -} - -VOID _app_updateitembylparam (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ BOOLEAN is_app) -{ - INT listview_id; - INT item_id; - - if (is_app) - { - listview_id = PtrToInt (_app_getappinfobyhash (lparam, INFO_LISTVIEW_ID)); - } - else - { - listview_id = PtrToInt (_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID)); - } - - if (listview_id) - { - item_id = _app_getposition (hwnd, listview_id, lparam); - - if (item_id != -1) - { - if (is_app) - { - PITEM_APP ptr_app = _app_getappitem (lparam); - - if (ptr_app) - { - _app_setcheckboxlock (hwnd, listview_id, TRUE); - _app_setappiteminfo (hwnd, listview_id, item_id, ptr_app); - _app_setcheckboxlock (hwnd, listview_id, FALSE); - - _r_obj_dereference (ptr_app); - } - } - else - { - PITEM_RULE ptr_rule = _app_getrulebyid (lparam); - - if (ptr_rule) - { - _app_setcheckboxlock (hwnd, listview_id, TRUE); - _app_setruleiteminfo (hwnd, listview_id, item_id, ptr_rule, FALSE); - _app_setcheckboxlock (hwnd, listview_id, FALSE); - - _r_obj_dereference (ptr_rule); - } - } - } - } -} - -LPARAM _app_createlistviewcontext (_In_ ULONG_PTR id_code) -{ - PITEM_LISTVIEW_CONTEXT context; - - context = _r_freelist_allocateitem (&listview_free_list); - - context->id_code = id_code; - - return (LPARAM)context; -} - -ULONG_PTR _app_getlistviewparam_id (_In_ LPARAM lparam) -{ - PITEM_LISTVIEW_CONTEXT context; - - context = (PITEM_LISTVIEW_CONTEXT)lparam; - - return context->id_code; -} - -ULONG_PTR _app_getlistviewitemcontext (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id) -{ - LPARAM lparam; - - lparam = _r_listview_getitemlparam (hwnd, listview_id, item_id); - - if (!lparam) - return 0; - - return _app_getlistviewparam_id (lparam); -} - -BOOLEAN _app_islistviewitemhidden (_In_ LPARAM lparam) -{ - PITEM_LISTVIEW_CONTEXT context; - - context = (PITEM_LISTVIEW_CONTEXT)lparam; - - if (!context) - return FALSE; - - return context->is_hidden; -} - VOID _app_getapptooltipstring (_Inout_ PR_STRINGBUILDER buffer, _In_ ULONG_PTR app_hash, _In_opt_ PITEM_NETWORK ptr_network, _In_opt_ PITEM_LOG ptr_log) { PITEM_APP_INFO ptr_app_info; @@ -556,8 +238,11 @@ _Ret_maybenull_ PR_STRING _app_gettooltipbylparam (_In_ HWND hwnd, _In_ INT listview_id, _In_ ULONG_PTR lparam) { R_STRINGBUILDER sr; - PR_STRING string; - PR_STRING string_tmp; + PR_STRING string1; + PR_STRING string2; + PITEM_RULE ptr_rule; + PITEM_NETWORK ptr_network; + PITEM_LOG ptr_log; UNREFERENCED_PARAMETER (hwnd); @@ -569,17 +254,12 @@ PR_STRING _app_gettooltipbylparam (_In_ HWND hwnd, _In_ INT listview_id, _In_ UL } else if ((listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM) || listview_id == IDC_APP_RULES_ID) { - PITEM_RULE ptr_rule; - ptr_rule = _app_getrulebyid (lparam); if (ptr_rule) { - PR_STRING rule_remote_string; - PR_STRING rule_local_string; - - rule_remote_string = _app_rulesexpandrules (ptr_rule->rule_remote, L"\r\n" SZ_TAB); - rule_local_string = _app_rulesexpandrules (ptr_rule->rule_local, L"\r\n" SZ_TAB); + string1 = _app_rulesexpandrules (ptr_rule->rule_remote, L"\r\n" SZ_TAB); + string2 = _app_rulesexpandrules (ptr_rule->rule_local, L"\r\n" SZ_TAB); // rule information _r_obj_appendstringbuilderformat (&sr, L"%s (#%" TEXT (PR_ULONG_PTR) L")\r\n%s (" SZ_DIRECTION_REMOTE L"):\r\n%s%s\r\n%s (" SZ_DIRECTION_LOCAL L"):\r\n%s%s", @@ -587,42 +267,42 @@ PR_STRING _app_gettooltipbylparam (_In_ HWND hwnd, _In_ INT listview_id, _In_ UL lparam, _r_locale_getstring (IDS_RULE), SZ_TAB, - _r_obj_getstringordefault (rule_remote_string, SZ_EMPTY), + _r_obj_getstringordefault (string1, SZ_EMPTY), _r_locale_getstring (IDS_RULE), SZ_TAB, - _r_obj_getstringordefault (rule_local_string, SZ_EMPTY) + _r_obj_getstringordefault (string2, SZ_EMPTY) ); - if (rule_remote_string) - _r_obj_dereference (rule_remote_string); + if (string1) + _r_obj_dereference (string1); - if (rule_local_string) - _r_obj_dereference (rule_local_string); + if (string2) + _r_obj_dereference (string2); // rule apps if (ptr_rule->is_forservices || !_r_obj_ishashtableempty (ptr_rule->apps)) { - string = _app_rulesexpandapps (ptr_rule, TRUE, SZ_TAB_CRLF); + string1 = _app_rulesexpandapps (ptr_rule, TRUE, SZ_TAB_CRLF); - if (string) + if (string1) { - string_tmp = _r_obj_concatstrings (4, L"\r\n", _r_locale_getstring (IDS_TAB_APPS), L":\r\n" SZ_TAB, string->buffer); + string2 = _r_obj_concatstrings (4, L"\r\n", _r_locale_getstring (IDS_TAB_APPS), L":\r\n" SZ_TAB, string1->buffer); - _r_obj_appendstringbuilder2 (&sr, string_tmp); + _r_obj_appendstringbuilder2 (&sr, string2); - _r_obj_dereference (string_tmp); - _r_obj_dereference (string); + _r_obj_dereference (string1); + _r_obj_dereference (string2); } } // rule notes if (ptr_rule->is_readonly && ptr_rule->type == DATA_RULE_USER) { - string_tmp = _r_obj_concatstrings (4, L"\r\n", _r_locale_getstring (IDS_NOTES), L":\r\n" SZ_TAB, SZ_RULE_INTERNAL_TITLE); + string2 = _r_obj_concatstrings (4, L"\r\n", _r_locale_getstring (IDS_NOTES), L":\r\n" SZ_TAB, SZ_RULE_INTERNAL_TITLE); - _r_obj_appendstringbuilder2 (&sr, string_tmp); + _r_obj_appendstringbuilder2 (&sr, string2); - _r_obj_dereference (string_tmp); + _r_obj_dereference (string2); } _r_obj_dereference (ptr_rule); @@ -630,8 +310,6 @@ PR_STRING _app_gettooltipbylparam (_In_ HWND hwnd, _In_ INT listview_id, _In_ UL } else if (listview_id == IDC_NETWORK) { - PITEM_NETWORK ptr_network; - ptr_network = _app_network_getitem (lparam); if (ptr_network) @@ -643,7 +321,6 @@ PR_STRING _app_gettooltipbylparam (_In_ HWND hwnd, _In_ INT listview_id, _In_ UL } else if (listview_id == IDC_LOG) { - PITEM_LOG ptr_log; ptr_log = _app_getlogitem (lparam); @@ -655,10 +332,10 @@ PR_STRING _app_gettooltipbylparam (_In_ HWND hwnd, _In_ INT listview_id, _In_ UL } } - string = _r_obj_finalstringbuilder (&sr); + string1 = _r_obj_finalstringbuilder (&sr); - if (!_r_obj_isstringempty2 (string)) - return string; + if (!_r_obj_isstringempty2 (string1)) + return string1; _r_obj_deletestringbuilder (&sr); @@ -676,7 +353,7 @@ VOID _app_settab_id (_In_ HWND hwnd, _In_ INT page_id) hctrl = GetDlgItem (hwnd, page_id); - if (!hctrl || (_app_getcurrentlistview_id (hwnd) == page_id && _r_wnd_isvisible (hctrl))) + if (!hctrl || (_app_listview_getcurrent (hwnd) == page_id && _r_wnd_isvisible (hctrl))) return; item_count = _r_tab_getitemcount (hwnd, IDC_TAB); @@ -686,7 +363,7 @@ VOID _app_settab_id (_In_ HWND hwnd, _In_ INT page_id) for (INT i = 0; i < item_count; i++) { - listview_id = _app_getlistviewbytab_id (hwnd, i); + listview_id = _app_listview_getbytab (hwnd, i); if (listview_id == page_id) { @@ -920,179 +597,6 @@ VOID _app_imagelist_init (_In_opt_ HWND hwnd, _In_ LONG dpi_value) } } -VOID _app_listviewresize (_In_ HWND hwnd, _In_ INT listview_id, _In_ BOOLEAN is_forced) -{ - if (!is_forced && !_r_config_getboolean (L"AutoSizeColumns", TRUE)) - return; - - PR_STRING column_text; - PR_STRING item_text; - HWND hlistview; - HWND hheader = NULL; - HDC hdc_listview = NULL; - HDC hdc_header = NULL; - LONG dpi_value; - INT column_count; - INT item_count; - INT column_width; - INT text_width; - INT calculated_width; - INT column_general_id; - INT total_width; - INT max_width; - INT spacing; - BOOLEAN is_tableview; - - hlistview = GetDlgItem (hwnd, listview_id); - - if (!hlistview) - return; - - column_count = _r_listview_getcolumncount (hwnd, listview_id); - - if (!column_count) - return; - - // get device context and fix font set - hdc_listview = GetDC (hlistview); - - if (!hdc_listview) - goto CleanupExit; - - hheader = (HWND)SendMessage (hlistview, LVM_GETHEADER, 0, 0); - - hdc_header = GetDC (hheader); - - if (!hdc_header) - goto CleanupExit; - - _r_dc_fixwindowfont (hdc_listview, hlistview); // fix - _r_dc_fixwindowfont (hdc_header, hheader); // fix - - calculated_width = 0; - column_general_id = 0; // set general column id - - is_tableview = (_r_listview_getview (hwnd, listview_id) == LV_VIEW_DETAILS); - - dpi_value = _r_dc_getwindowdpi (hwnd); - - max_width = _r_dc_getdpi (158, dpi_value); - spacing = _r_dc_getsystemmetrics (SM_CXSMICON, dpi_value); - - total_width = _r_ctrl_getwidth (hwnd, listview_id); - item_count = _r_listview_getitemcount (hwnd, listview_id); - - for (INT i = 0; i < column_count; i++) - { - if (i == column_general_id) - continue; - - // get column text width - column_text = _r_listview_getcolumntext (hwnd, listview_id, i); - - if (!column_text) - continue; - - column_width = _r_dc_getfontwidth (hdc_header, &column_text->sr) + spacing; - - if (column_width >= max_width) - { - column_width = max_width; - } - else - { - // calculate max width of listview subitems (only for details view) - if (is_tableview) - { - for (INT j = 0; j < item_count; j++) - { - item_text = _r_listview_getitemtext (hwnd, listview_id, j, i); - - if (item_text) - { - text_width = _r_dc_getfontwidth (hdc_listview, &item_text->sr) + spacing; - - _r_obj_dereference (item_text); - - // do not continue reaching higher and higher values for performance reason! - if (text_width >= max_width) - { - column_width = max_width; - break; - } - - if (text_width > column_width) - column_width = text_width; - } - } - } - } - - _r_listview_setcolumn (hwnd, listview_id, i, NULL, column_width); - - calculated_width += column_width; - - _r_obj_dereference (column_text); - } - - // set general column width - _r_listview_setcolumn (hwnd, listview_id, column_general_id, NULL, max (total_width - calculated_width, max_width)); - -CleanupExit: - - if (hdc_listview) - ReleaseDC (hlistview, hdc_listview); - - if (hdc_header) - ReleaseDC (hheader, hdc_header); -} - -VOID _app_listviewsetview (_In_ HWND hwnd, _In_ INT listview_id) -{ - HIMAGELIST himg; - LONG view_type; - LONG icons_size; - BOOLEAN is_mainview; - - is_mainview = (listview_id >= IDC_APPS_PROFILE) && (listview_id <= IDC_RULES_CUSTOM); - view_type = is_mainview ? _r_calc_clamp32 (_r_config_getlong (L"ViewType", LV_VIEW_DETAILS), LV_VIEW_ICON, LV_VIEW_MAX) : LV_VIEW_DETAILS; - icons_size = is_mainview ? _r_calc_clamp32 (_r_config_getlong (L"IconSize", SHIL_SMALL), SHIL_LARGE, SHIL_LAST) : SHIL_SMALL; - - if (listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM || listview_id == IDC_APP_RULES_ID) - { - himg = (icons_size == SHIL_SMALL || icons_size == SHIL_SYSSMALL) ? config.himg_rules_small : config.himg_rules_large; - } - else - { - SHGetImageList (icons_size, &IID_IImageList2, &himg); - } - - if (himg) - _r_listview_setimagelist (hwnd, listview_id, himg); - - _r_listview_setview (hwnd, listview_id, view_type); -} - -VOID _app_listviewloadfont (_In_ LONG dpi_value, _In_ BOOLEAN is_forced) -{ - LOGFONT logfont = {0}; - - if (is_forced || !config.hfont) - { - SAFE_DELETE_OBJECT (config.hfont); - - _r_config_getfont (L"Font", &logfont, dpi_value); - - config.hfont = _app_createfont (&logfont, 0, FALSE, 0); - } -} - -VOID _app_listviewsetfont (_In_ HWND hwnd, _In_ INT listview_id) -{ - if (config.hfont) - SendDlgItemMessage (hwnd, listview_id, WM_SETFONT, (WPARAM)config.hfont, TRUE); -} - HFONT _app_createfont (_Inout_ PLOGFONT logfont, _In_ LONG size, _In_ BOOLEAN is_underline, _In_ LONG dpi_value) { if (size) @@ -1119,181 +623,6 @@ VOID _app_windowloadfont (_In_ LONG dpi_value) config.wnd_font = _app_createfont (&ncm.lfMessageFont, 0, FALSE, 0); } -INT CALLBACK _app_listviewcompare_callback (_In_ LPARAM lparam1, _In_ LPARAM lparam2, _In_ LPARAM lparam) -{ - WCHAR config_name[128]; - HWND hwnd; - LONG column_id; - INT listview_id; - INT result; - INT item_id1; - INT item_id2; - BOOLEAN is_descend; - - hwnd = GetParent ((HWND)lparam); - - if (!hwnd) - return 0; - - listview_id = GetDlgCtrlID ((HWND)lparam); - - if (!listview_id) - return 0; - - item_id1 = (INT)(INT_PTR)lparam1; - item_id2 = (INT)(INT_PTR)lparam2; - - _r_str_printf (config_name, RTL_NUMBER_OF (config_name), L"listview\\%04" TEXT (PRIX32), listview_id); - - column_id = _r_config_getlong_ex (L"SortColumn", 0, config_name); - is_descend = _r_config_getboolean_ex (L"SortIsDescending", FALSE, config_name); - - result = 0; - - if ((_r_listview_getexstyle (hwnd, listview_id) & LVS_EX_CHECKBOXES) != 0) - { - BOOLEAN is_checked1; - BOOLEAN is_checked2; - - is_checked1 = _r_listview_isitemchecked (hwnd, listview_id, item_id1); - is_checked2 = _r_listview_isitemchecked (hwnd, listview_id, item_id2); - - if (is_checked1 != is_checked2) - { - if (is_checked1 && !is_checked2) - { - result = is_descend ? 1 : -1; - } - else if (!is_checked1 && is_checked2) - { - result = is_descend ? -1 : 1; - } - } - } - - if (!result) - { - // timestamp sorting - if ((listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) && column_id == 1) - { - PVOID timer1_ptr; - PVOID timer2_ptr; - - timer1_ptr = _app_getappinfobyhash (_app_getlistviewitemcontext (hwnd, listview_id, item_id1), INFO_TIMESTAMP_PTR); - timer2_ptr = _app_getappinfobyhash (_app_getlistviewitemcontext (hwnd, listview_id, item_id2), INFO_TIMESTAMP_PTR); - - if (timer1_ptr && timer2_ptr) - { - LONG64 timestamp1 = *((PLONG64)timer1_ptr); - LONG64 timestamp2 = *((PLONG64)timer2_ptr); - - if (timestamp1 < timestamp2) - { - result = -1; - } - else if (timestamp1 > timestamp2) - { - result = 1; - } - } - } - else if (listview_id == IDC_LOG && column_id == 11) - { - PITEM_LOG ptr_log1; - PITEM_LOG ptr_log2; - - ptr_log1 = _app_getlogitem (_app_getlistviewitemcontext (hwnd, listview_id, item_id1)); - ptr_log2 = _app_getlogitem (_app_getlistviewitemcontext (hwnd, listview_id, item_id2)); - - if (ptr_log1 && ptr_log2) - { - if (ptr_log1->timestamp < ptr_log2->timestamp) - { - result = -1; - } - else if (ptr_log1->timestamp > ptr_log2->timestamp) - { - result = 1; - } - } - - if (ptr_log1) - _r_obj_dereference (ptr_log1); - - if (ptr_log2) - _r_obj_dereference (ptr_log2); - } - } - - if (!result) - { - PR_STRING item_text_1; - PR_STRING item_text_2; - - item_text_1 = _r_listview_getitemtext (hwnd, listview_id, item_id1, column_id); - item_text_2 = _r_listview_getitemtext (hwnd, listview_id, item_id2, column_id); - - if (item_text_1 && item_text_2) - { - result = _r_str_compare_logical (item_text_1, item_text_2); - } - - if (item_text_1) - _r_obj_dereference (item_text_1); - - if (item_text_2) - _r_obj_dereference (item_text_2); - } - - return is_descend ? -result : result; -} - -VOID _app_listviewsort (_In_ HWND hwnd, _In_ INT listview_id, _In_ LONG column_id, _In_ BOOLEAN is_notifycode) -{ - HWND hlistview; - INT column_count; - BOOLEAN is_descend; - - hlistview = GetDlgItem (hwnd, listview_id); - - if (!hlistview) - return; - - if ((GetWindowLongPtr (hlistview, GWL_STYLE) & (LVS_NOSORTHEADER | LVS_OWNERDATA)) != 0) - return; - - column_count = _r_listview_getcolumncount (hwnd, listview_id); - - if (!column_count) - return; - - WCHAR config_name[128]; - _r_str_printf (config_name, RTL_NUMBER_OF (config_name), L"listview\\%04" TEXT (PRIX32), listview_id); - - is_descend = _r_config_getboolean_ex (L"SortIsDescending", FALSE, config_name); - - if (is_notifycode) - is_descend = !is_descend; - - if (column_id == -1) - column_id = _r_config_getlong_ex (L"SortColumn", 0, config_name); - - column_id = _r_calc_clamp32 (column_id, 0, column_count - 1); // set range - - if (is_notifycode) - { - _r_config_setboolean_ex (L"SortIsDescending", is_descend, config_name); - _r_config_setlong_ex (L"SortColumn", column_id, config_name); - } - - for (INT i = 0; i < column_count; i++) - _r_listview_setcolumnsortindex (hwnd, listview_id, i, 0); - - _r_listview_setcolumnsortindex (hwnd, listview_id, column_id, is_descend ? -1 : 1); - - SendMessage (hlistview, LVM_SORTITEMSEX, (WPARAM)hlistview, (LPARAM)&_app_listviewcompare_callback); -} - VOID _app_toolbar_init (_In_ HWND hwnd, _In_ LONG dpi_value) { ULONG button_size; @@ -1480,7 +809,7 @@ VOID _app_window_resize (_In_ HWND hwnd, _In_ LPCRECT rect, _In_ LONG dpi_value) SendMessage (config.hrebar, WM_SIZE, 0, 0); SendDlgItemMessage (hwnd, IDC_STATUSBAR, WM_SIZE, 0, 0); - current_listview_id = _app_getlistviewbytab_id (hwnd, -1); + current_listview_id = _app_listview_getbytab (hwnd, -1); rebar_height = _r_rebar_getheight (hwnd, IDC_REBAR); statusbar_height = _r_status_getheight (hwnd, IDC_STATUSBAR); @@ -1499,139 +828,20 @@ VOID _app_window_resize (_In_ HWND hwnd, _In_ LPCRECT rect, _In_ LONG dpi_value) for (INT i = 0; i < tab_count; i++) { - listview_id = _app_getlistviewbytab_id (hwnd, i); + listview_id = _app_listview_getbytab (hwnd, i); if (listview_id) { _r_tab_adjustchild (hwnd, IDC_TAB, GetDlgItem (hwnd, listview_id)); if (listview_id == current_listview_id) - _app_listviewresize (hwnd, listview_id, FALSE); + _app_listview_resize (hwnd, listview_id); } } _app_refreshstatus (hwnd); } -VOID _app_refreshgroups (_In_ HWND hwnd, _In_ INT listview_id) -{ - UINT group1_title; - UINT group2_title; - UINT group3_title; - UINT group4_title; - - INT total_count; - - INT group1_count; - INT group2_count; - INT group3_count; - INT group4_count; - - INT group_id; - - if (!_r_listview_isgroupviewenabled (hwnd, listview_id)) - return; - - if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) - { - group1_title = IDS_GROUP_ALLOWED; - group2_title = IDS_GROUP_SPECIAL_APPS; - group3_title = IDS_GROUP_BLOCKED; - group4_title = IDS_GROUP_BLOCKED; - } - else if (listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM) - { - group1_title = IDS_GROUP_ENABLED; - group2_title = 0; - group3_title = IDS_GROUP_DISABLED; - group4_title = 0; - } - else if (listview_id == IDC_RULE_APPS_ID || listview_id == IDC_NETWORK) - { - group1_title = IDS_TAB_APPS; - group2_title = IDS_TAB_SERVICES; - group3_title = IDS_TAB_PACKAGES; - group4_title = 0; - } - else if (listview_id == IDC_APP_RULES_ID) - { - group1_title = IDS_TRAY_SYSTEM_RULES; - group2_title = IDS_TRAY_USER_RULES; - group3_title = 0; - group4_title = 0; - } - else - { - return; - } - - group1_count = 0; - group2_count = 0; - group3_count = 0; - group4_count = 0; - - total_count = _r_listview_getitemcount (hwnd, listview_id); - - for (INT i = 0; i < total_count; i++) - { - if (listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID) - { - if (_r_listview_isitemchecked (hwnd, listview_id, i)) - group1_count = group2_count = group3_count += 1; - } - else - { - group_id = _r_listview_getitemgroup (hwnd, listview_id, i); - - if (group_id == 3) - { - group4_count += 1; - } - else if (group_id == 2) - { - group3_count += 1; - } - else if (group_id == 1) - { - group2_count += 1; - } - else if (group_id == 0) - { - group1_count += 1; - } - } - } - - WCHAR group1_string[128] = {0}; - WCHAR group2_string[128] = {0}; - WCHAR group3_string[128] = {0}; - WCHAR group4_string[128] = {0}; - - if (total_count) - { - if (group1_title) - _r_str_printf (group1_string, RTL_NUMBER_OF (group1_string), L"%s (%d/%d)", _r_locale_getstring (group1_title), group1_count, total_count); - - if (group2_title) - _r_str_printf (group2_string, RTL_NUMBER_OF (group2_string), L"%s (%d/%d)", _r_locale_getstring (group2_title), group2_count, total_count); - - if (group3_title) - _r_str_printf (group3_string, RTL_NUMBER_OF (group3_string), L"%s (%d/%d)", _r_locale_getstring (group3_title), group3_count, total_count); - - if (group4_title) - _r_str_printf (group4_string, RTL_NUMBER_OF (group4_string), L"%s (%d/%d) [silent]", _r_locale_getstring (group4_title), group4_count, total_count); - } - - _r_listview_setgroup (hwnd, listview_id, 0, group1_string, 0, 0); - _r_listview_setgroup (hwnd, listview_id, 1, group2_string, 0, 0); - - if (group3_title) - _r_listview_setgroup (hwnd, listview_id, 2, group3_string, 0, 0); - - if (group4_title) - _r_listview_setgroup (hwnd, listview_id, 3, group4_string, 0, 0); -} - VOID _app_refreshstatus (_In_ HWND hwnd) { ITEM_STATUS status; @@ -1706,66 +916,3 @@ VOID _app_refreshstatus (_In_ HWND hwnd) ReleaseDC (hstatus, hdc); } - -_Success_ (return != -1) -INT _app_getposition (_In_ HWND hwnd, _In_ INT listview_id, _In_ ULONG_PTR lparam) -{ - PITEM_LISTVIEW_CONTEXT context; - INT item_count; - INT item_id; - - if ((listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_LOG) || listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID) - { - item_id = -1; - - item_count = _r_listview_getitemcount (hwnd, listview_id); - - if (item_count) - { - for (INT i = 0; i < item_count; i++) - { - context = (PITEM_LISTVIEW_CONTEXT)_r_listview_getitemlparam (hwnd, listview_id, i); - - if (!context) - continue; - - if (context->id_code == lparam) - { - item_id = i; - break; - } - } - } - } - else - { - item_id = _r_listview_finditem (hwnd, listview_id, -1, lparam); - } - - return item_id; -} - -VOID _app_showitem (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id, _In_ INT scroll_pos) -{ - INT total_count; - - _app_settab_id (hwnd, listview_id); - - total_count = _r_listview_getitemcount (hwnd, listview_id); - - if (!total_count) - return; - - if (item_id != -1) - { - item_id = _r_calc_clamp (item_id, 0, total_count - 1); - - _r_listview_setitemvisible (hwnd, listview_id, item_id); - } - - if (scroll_pos > 0) - { - SendDlgItemMessage (hwnd, listview_id, LVM_SCROLL, 0, (LPARAM)scroll_pos); // restore scroll position - } -} - diff --git a/src/controls.h b/src/controls.h index 94e239be..7e190b2e 100644 --- a/src/controls.h +++ b/src/controls.h @@ -5,31 +5,6 @@ EXTERN_C const IID IID_IImageList2; -#define PR_SETITEM_REDRAW 0x0001 -#define PR_SETITEM_UPDATE 0x0002 - -#define PR_UPDATE_TYPE 0x0001 -#define PR_UPDATE_FORCE 0x0002 -#define PR_UPDATE_NOREFRESH 0x0004 -#define PR_UPDATE_NOSORT 0x0008 -#define PR_UPDATE_NORESIZE 0x0010 -#define PR_UPDATE_NOREDRAW 0x0020 -#define PR_UPDATE_NOSETVIEW 0x0040 - -BOOLEAN _app_ischeckboxlocked (_In_ HWND hwnd, _In_ INT ctrl_id); -VOID _app_setcheckboxlock (_In_ HWND hwnd, _In_ INT ctrl_id, _In_ BOOLEAN is_lock); - - -INT _app_getlistviewbytab_id (_In_ HWND hwnd, _In_ INT tab_id); -INT _app_getlistviewbytype_id (_In_ ENUM_TYPE_DATA type); - -VOID _app_setlistviewbylparam (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ ULONG flags, _In_ BOOLEAN is_app); - -VOID _app_updatelistviewbylparam (_In_ HWND hwnd, _In_ INT lparam, _In_ ULONG flags); - -VOID _app_addlistviewapp (_In_ HWND hwnd, _In_ PITEM_APP ptr_app); -VOID _app_addlistviewrule (_In_ HWND hwnd, _In_ PITEM_RULE ptr_rule, _In_ SIZE_T rule_idx, _In_ BOOLEAN is_forapp); - _Ret_maybenull_ PR_STRING _app_gettooltipbylparam (_In_ HWND hwnd, _In_ INT listview_id, _In_ ULONG_PTR lparam); @@ -42,47 +17,13 @@ VOID _app_setinterfacestate (_In_ HWND hwnd, _In_ LONG dpi_value); VOID _app_imagelist_init (_In_opt_ HWND hwnd, _In_ LONG dpi_value); -VOID _app_listviewresize (_In_ HWND hwnd, _In_ INT listview_id, _In_ BOOLEAN is_forced); -VOID _app_listviewsetview (_In_ HWND hwnd, _In_ INT listview_id); - -VOID _app_listviewloadfont (_In_ LONG dpi_value, _In_ BOOLEAN is_forced); -VOID _app_listviewsetfont (_In_ HWND hwnd, _In_ INT listview_id); - HFONT _app_createfont (_Inout_ PLOGFONT logfont, _In_ LONG size, _In_ BOOLEAN is_underline, _In_ LONG dpi_value); VOID _app_windowloadfont (_In_ LONG dpi_value); -INT CALLBACK _app_listviewcompare_callback (_In_ LPARAM lparam1, _In_ LPARAM lparam2, _In_ LPARAM lparam); -VOID _app_listviewsort (_In_ HWND hwnd, _In_ INT listview_id, _In_ LONG column_id, _In_ BOOLEAN is_notifycode); - VOID _app_toolbar_init (_In_ HWND hwnd, _In_ LONG dpi_value); VOID _app_toolbar_resize (_In_ HWND hwnd, _In_ LONG dpi_value); VOID _app_toolbar_setfont (); VOID _app_window_resize (_In_ HWND hwnd, _In_ LPCRECT rect, _In_ LONG dpi_value); -VOID _app_refreshgroups (_In_ HWND hwnd, _In_ INT listview_id); VOID _app_refreshstatus (_In_ HWND hwnd); - -_Success_ (return != -1) -INT _app_getposition (_In_ HWND hwnd, _In_ INT listview_id, _In_ ULONG_PTR lparam); - -VOID _app_showitem (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id, _In_ INT scroll_pos); -VOID _app_showitembylparam (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ BOOLEAN is_app); - -VOID _app_updateitembyidx (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id); -VOID _app_updateitembylparam (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ BOOLEAN is_app); - -LPARAM _app_createlistviewcontext (_In_ ULONG_PTR id_code); -ULONG_PTR _app_getlistviewparam_id (_In_ LPARAM lparam); -ULONG_PTR _app_getlistviewitemcontext (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id); -BOOLEAN _app_islistviewitemhidden (_In_ LPARAM lparam); - -FORCEINLINE VOID _app_destroylistviewcontext (_In_ PITEM_LISTVIEW_CONTEXT context) -{ - _r_freelist_deleteitem (&listview_free_list, context); -} - -FORCEINLINE INT _app_getcurrentlistview_id (_In_ HWND hwnd) -{ - return _app_getlistviewbytab_id (hwnd, -1); -} diff --git a/src/editor.c b/src/editor.c index f4f867b6..aeb4cdd0 100644 --- a/src/editor.c +++ b/src/editor.c @@ -165,9 +165,9 @@ VOID _app_editor_setrulestolistview (_In_ HWND hwnd, _In_ INT ctrl_id, _In_ PR_S rule_string = _r_obj_createstring3 (&first_part); - _app_setcheckboxlock (hwnd, ctrl_id, TRUE); + _app_listview_lock (hwnd, ctrl_id, TRUE); _r_listview_additem (hwnd, ctrl_id, item_id, rule_string->buffer); - _app_setcheckboxlock (hwnd, ctrl_id, FALSE); + _app_listview_lock (hwnd, ctrl_id, FALSE); item_id += 1; @@ -581,7 +581,7 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa // apps if (GetDlgItem (hwnd, IDC_RULE_APPS_ID)) { - _app_listviewsetview (hwnd, IDC_RULE_APPS_ID); + _app_listview_setview (hwnd, IDC_RULE_APPS_ID); _r_listview_setstyle (hwnd, IDC_RULE_APPS_ID, LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_CHECKBOXES, TRUE); @@ -606,12 +606,12 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa // check for services is_enabled = (_r_obj_findhashtable (context->ptr_rule->apps, ptr_app->app_hash)) || (context->ptr_rule->is_forservices && _app_issystemhash (ptr_app->app_hash)); - _app_setcheckboxlock (hwnd, IDC_RULE_APPS_ID, TRUE); + _app_listview_lock (hwnd, IDC_RULE_APPS_ID, TRUE); - _r_listview_additem_ex (hwnd, IDC_RULE_APPS_ID, 0, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_createlistviewcontext (ptr_app->app_hash)); + _r_listview_additem_ex (hwnd, IDC_RULE_APPS_ID, 0, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_listview_createcontext (ptr_app->app_hash)); _r_listview_setitemcheck (hwnd, IDC_RULE_APPS_ID, 0, is_enabled); - _app_setcheckboxlock (hwnd, IDC_RULE_APPS_ID, FALSE); + _app_listview_lock (hwnd, IDC_RULE_APPS_ID, FALSE); } _r_queuedlock_releaseshared (&lock_apps); @@ -622,10 +622,10 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa _r_listview_setcolumn (hwnd, IDC_RULE_APPS_ID, 0, NULL, -100); // localize groups - _app_refreshgroups (hwnd, IDC_RULE_APPS_ID); + _app_listview_refreshgroups (hwnd, IDC_RULE_APPS_ID); // sort column - _app_listviewsort (hwnd, IDC_RULE_APPS_ID, -1, FALSE); + _app_listview_sort (hwnd, IDC_RULE_APPS_ID); } // app group @@ -679,7 +679,7 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa if (GetDlgItem (hwnd, IDC_APP_RULES_ID)) { // configure listview - _app_listviewsetview (hwnd, IDC_APP_RULES_ID); + _app_listview_setview (hwnd, IDC_APP_RULES_ID); _r_listview_setstyle (hwnd, IDC_APP_RULES_ID, LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_CHECKBOXES, TRUE); @@ -706,12 +706,12 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa // check for services is_enabled = ((ptr_rule->is_forservices && _app_issystemhash (context->ptr_app->app_hash)) || _r_obj_findhashtable (ptr_rule->apps, context->ptr_app->app_hash)); - _app_setcheckboxlock (hwnd, IDC_APP_RULES_ID, TRUE); + _app_listview_lock (hwnd, IDC_APP_RULES_ID, TRUE); - _r_listview_additem_ex (hwnd, IDC_APP_RULES_ID, 0, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_createlistviewcontext (i)); + _r_listview_additem_ex (hwnd, IDC_APP_RULES_ID, 0, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_listview_createcontext (i)); _r_listview_setitemcheck (hwnd, IDC_APP_RULES_ID, 0, is_enabled); - _app_setcheckboxlock (hwnd, IDC_APP_RULES_ID, FALSE); + _app_listview_lock (hwnd, IDC_APP_RULES_ID, FALSE); } _r_queuedlock_releaseshared (&lock_rules); @@ -720,10 +720,10 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa _r_listview_setcolumn (hwnd, IDC_APP_RULES_ID, 0, NULL, -100); // localize groups - _app_refreshgroups (hwnd, IDC_APP_RULES_ID); + _app_listview_refreshgroups (hwnd, IDC_APP_RULES_ID); // sort column - _app_listviewsort (hwnd, IDC_APP_RULES_ID, -1, FALSE); + _app_listview_sort (hwnd, IDC_APP_RULES_ID); } // hints @@ -969,7 +969,7 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa if (!listview_context) break; - _app_destroylistviewcontext (listview_context); + _app_listview_destroycontext (listview_context); break; } @@ -995,7 +995,7 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa lpnmlv = (LPNMLISTVIEW)lparam; listview_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom; - _app_listviewsort (hwnd, listview_id, lpnmlv->iSubItem, TRUE); + _app_listview_sort_ex (hwnd, listview_id, lpnmlv->iSubItem, TRUE); break; } @@ -1019,7 +1019,7 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa { if ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (1) || ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2))) { - if (!_app_ischeckboxlocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom) && context->ptr_rule->type != DATA_RULE_USER) + if (!_app_listview_islocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom) && context->ptr_rule->type != DATA_RULE_USER) { SetWindowLongPtr (hwnd, DWLP_MSGRESULT, TRUE); return TRUE; @@ -1051,13 +1051,13 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa { if ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (1) || ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2))) { - if (_app_ischeckboxlocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom)) + if (_app_listview_islocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom)) break; _app_editor_settabtitle (hwnd, listview_id); - _app_refreshgroups (hwnd, listview_id); - _app_listviewsort (hwnd, listview_id, -1, FALSE); + _app_listview_refreshgroups (hwnd, listview_id); + _app_listview_sort (hwnd, listview_id); } } else if (listview_id == IDC_RULE_REMOTE_ID || listview_id == IDC_RULE_LOCAL_ID) @@ -1098,7 +1098,7 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa if (listview_id != IDC_RULE_APPS_ID && listview_id != IDC_APP_RULES_ID) break; - string = _app_gettooltipbylparam (hwnd, listview_id, _app_getlistviewitemcontext (hwnd, listview_id, lpnmlv->iItem)); + string = _app_gettooltipbylparam (hwnd, listview_id, _app_listview_getitemcontext (hwnd, listview_id, lpnmlv->iItem)); if (string) { @@ -1273,17 +1273,17 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa new_val = (ctrl_id == IDM_CHECK); item_id = -1; - _app_setcheckboxlock (hwnd, listview_id, TRUE); + _app_listview_lock (hwnd, listview_id, TRUE); while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != -1) { _r_listview_setitemcheck (hwnd, listview_id, item_id, new_val); } - _app_setcheckboxlock (hwnd, listview_id, FALSE); + _app_listview_lock (hwnd, listview_id, FALSE); - _app_refreshgroups (hwnd, listview_id); - _app_listviewsort (hwnd, listview_id, -1, FALSE); + _app_listview_refreshgroups (hwnd, listview_id); + _app_listview_sort (hwnd, listview_id); break; } @@ -1327,9 +1327,9 @@ INT_PTR CALLBACK EditorPagesProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wpa if (item_id != -1) { - index = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + index = _app_listview_getitemcontext (hwnd, listview_id, item_id); - _app_showitembylparam (_r_app_gethwnd (), index, (listview_id == IDC_RULE_APPS_ID)); + _app_listview_showitemby_param (_r_app_gethwnd (), index, (listview_id == IDC_RULE_APPS_ID)); } break; @@ -1673,7 +1673,7 @@ INT_PTR CALLBACK EditorProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, if (!_r_listview_isitemchecked (hpage_apps, IDC_RULE_APPS_ID, i)) continue; - app_hash = _app_getlistviewitemcontext (hpage_apps, IDC_RULE_APPS_ID, i); + app_hash = _app_listview_getitemcontext (hpage_apps, IDC_RULE_APPS_ID, i); if (context->ptr_rule->is_forservices && _app_issystemhash (app_hash)) continue; @@ -1713,14 +1713,14 @@ INT_PTR CALLBACK EditorProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, for (INT i = 0; i < _r_listview_getitemcount (hpage_rule, IDC_APP_RULES_ID); i++) { - rule_idx = _app_getlistviewitemcontext (hpage_rule, IDC_APP_RULES_ID, i); + rule_idx = _app_listview_getitemcontext (hpage_rule, IDC_APP_RULES_ID, i); ptr_rule = _r_obj_getlistitem (rules_list, rule_idx); if (!ptr_rule) continue; - listview_id = _app_getlistviewbytype_id (ptr_rule->type); - item_id = _app_getposition (_r_app_gethwnd (), listview_id, rule_idx); + listview_id = _app_listview_getbytype (ptr_rule->type); + item_id = _app_listview_finditem (_r_app_gethwnd (), listview_id, rule_idx); if (item_id != -1) { diff --git a/src/global.h b/src/global.h index a926c567..cb42ca76 100644 --- a/src/global.h +++ b/src/global.h @@ -90,6 +90,7 @@ DECLSPEC_SELECTANY const LONG64 timer_array[] = #include "editor.h" #include "helper.h" #include "icons.h" +#include "listview.h" #include "log.h" #include "messages.h" #include "network.h" diff --git a/src/listview.c b/src/listview.c new file mode 100644 index 00000000..606b22f0 --- /dev/null +++ b/src/listview.c @@ -0,0 +1,962 @@ +// simplewall +// Copyright (c) 2016-2021 Henry++ + +#include "global.h" + +INT _app_listview_getcurrent (_In_ HWND hwnd) +{ + INT listview_id; + + listview_id = _app_listview_getbytab (hwnd, -1); + + return listview_id; +} + +INT _app_listview_getbytab (_In_ HWND hwnd, _In_ INT tab_id) +{ + INT listview_id; + + if (tab_id == -1) + tab_id = _r_tab_getcurrentitem (hwnd, IDC_TAB); + + listview_id = (INT)_r_tab_getitemlparam (hwnd, IDC_TAB, tab_id); + + return listview_id; +} + +INT _app_listview_getbytype (_In_ ENUM_TYPE_DATA type) +{ + switch (type) + { + case DATA_APP_REGULAR: + case DATA_APP_DEVICE: + case DATA_APP_NETWORK: + case DATA_APP_PICO: + { + return IDC_APPS_PROFILE; + } + + case DATA_APP_SERVICE: + { + return IDC_APPS_SERVICE; + } + + case DATA_APP_UWP: + { + return IDC_APPS_UWP; + } + + case DATA_RULE_BLOCKLIST: + { + return IDC_RULES_BLOCKLIST; + } + + case DATA_RULE_SYSTEM: + { + return IDC_RULES_SYSTEM; + } + + case DATA_RULE_SYSTEM_USER: + case DATA_RULE_USER: + { + return IDC_RULES_CUSTOM; + } + } + + return 0; +} + +VOID _app_listview_additems (_In_ HWND hwnd) +{ + PITEM_APP ptr_app; + PITEM_RULE ptr_rule; + LONG64 current_time; + SIZE_T enum_key; + + current_time = _r_unixtime_now (); + + enum_key = 0; + + // add apps + _r_queuedlock_acquireshared (&lock_apps); + + while (_r_obj_enumhashtablepointer (apps_table, &ptr_app, NULL, &enum_key)) + { + _app_listview_addappitem (hwnd, ptr_app); + + // install timer + if (ptr_app->timer) + _app_timer_set (hwnd, ptr_app, ptr_app->timer - current_time); + } + + _r_queuedlock_releaseshared (&lock_apps); + + // add rules + _r_queuedlock_acquireshared (&lock_rules); + + for (SIZE_T i = 0; i < _r_obj_getlistsize (rules_list); i++) + { + ptr_rule = _r_obj_getlistitem (rules_list, i); + + if (ptr_rule) + _app_listview_addruleitem (hwnd, ptr_rule, i, FALSE); + } + + _r_queuedlock_releaseshared (&lock_rules); +} + +VOID _app_listview_clearitems (_In_ HWND hwnd) +{ + INT listview_id; + + listview_id = _app_listview_getcurrent (hwnd); + + if (!listview_id) + return; + + for (INT i = IDC_APPS_PROFILE; i <= IDC_RULES_CUSTOM; i++) + _r_listview_deleteallitems (hwnd, i); +} + +VOID _app_listview_addappitem (_In_ HWND hwnd, _In_ PITEM_APP ptr_app) +{ + LPARAM listview_context; + INT listview_id; + INT item_id; + + listview_id = _app_listview_getbytype (ptr_app->type); + + if (listview_id) + { + item_id = _r_listview_getitemcount (hwnd, listview_id); + + _app_listview_lock (hwnd, listview_id, TRUE); + + listview_context = _app_listview_createcontext (ptr_app->app_hash); + + _r_listview_additem_ex (hwnd, listview_id, item_id, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, listview_context); + _app_setappiteminfo (hwnd, listview_id, item_id, ptr_app); + + _app_listview_lock (hwnd, listview_id, FALSE); + } +} + +VOID _app_listview_addruleitem (_In_ HWND hwnd, _In_ PITEM_RULE ptr_rule, _In_ SIZE_T rule_idx, _In_ BOOLEAN is_forapp) +{ + LPARAM listview_context; + INT listview_id; + INT item_id; + + listview_id = _app_listview_getbytype (ptr_rule->type); + + if (listview_id) + { + item_id = _r_listview_getitemcount (hwnd, listview_id); + + _app_listview_lock (hwnd, listview_id, TRUE); + + listview_context = _app_listview_createcontext (rule_idx); + + _r_listview_additem_ex (hwnd, listview_id, item_id, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, listview_context); + _app_setruleiteminfo (hwnd, listview_id, item_id, ptr_rule, is_forapp); + + _app_listview_lock (hwnd, listview_id, FALSE); + } +} + +VOID _app_listview_addnetworkitem (_In_ HWND hwnd, _In_ PITEM_NETWORK ptr_network, _In_ ULONG_PTR network_hash) +{ + LPARAM listview_context; + INT item_id; + + UNREFERENCED_PARAMETER (ptr_network); + + item_id = _r_listview_getitemcount (hwnd, IDC_NETWORK); + + listview_context = _app_listview_createcontext (network_hash); + + _r_listview_additem_ex (hwnd, IDC_NETWORK, item_id, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, listview_context); +} + +VOID _app_listview_addlogitem (_In_ HWND hwnd, _In_ PITEM_LOG ptr_log, _In_ ULONG_PTR log_hash) +{ + LPARAM listview_context; + INT item_id; + + UNREFERENCED_PARAMETER (ptr_log); + + item_id = _r_listview_getitemcount (hwnd, IDC_LOG); + + listview_context = _app_listview_createcontext (log_hash); + + _r_listview_additem_ex (hwnd, IDC_LOG, item_id, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, 0, listview_context); +} + +BOOLEAN _app_listview_islocked (_In_ HWND hwnd, _In_ INT ctrl_id) +{ + PVOID context; + ULONG property_id; + + property_id = (USHORT_MAX - ctrl_id); + + context = _r_wnd_getcontext (hwnd, property_id); + + return (context != NULL); +} + +VOID _app_listview_lock (_In_ HWND hwnd, _In_ INT ctrl_id, _In_ BOOLEAN is_lock) +{ + ULONG property_id; + + property_id = (USHORT_MAX - ctrl_id); + + if (is_lock) + { + _r_wnd_setcontext (hwnd, property_id, INVALID_HANDLE_VALUE); + } + else + { + _r_wnd_removecontext (hwnd, property_id); + } +} + +LPARAM _app_listview_createcontext (_In_ ULONG_PTR id_code) +{ + PITEM_LISTVIEW_CONTEXT context; + + context = _r_freelist_allocateitem (&listview_free_list); + + context->id_code = id_code; + + return (LPARAM)context; +} + +VOID _app_listview_destroycontext (_In_ PITEM_LISTVIEW_CONTEXT context) +{ + _r_freelist_deleteitem (&listview_free_list, context); +} + +ULONG_PTR _app_listview_getcontextcode (_In_ LPARAM lparam) +{ + PITEM_LISTVIEW_CONTEXT context; + + context = (PITEM_LISTVIEW_CONTEXT)lparam; + + return context->id_code; +} + +ULONG_PTR _app_listview_getitemcontext (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id) +{ + LPARAM lparam; + + lparam = _r_listview_getitemlparam (hwnd, listview_id, item_id); + + if (!lparam) + return 0; + + return _app_listview_getcontextcode (lparam); +} + +BOOLEAN _app_listview_isitemhidden (_In_ LPARAM lparam) +{ + PITEM_LISTVIEW_CONTEXT context; + + context = (PITEM_LISTVIEW_CONTEXT)lparam; + + if (!context) + return FALSE; + + return !!context->is_hidden; +} + +_Success_ (return != -1) +INT _app_listview_finditem (_In_ HWND hwnd, _In_ INT listview_id, _In_ ULONG_PTR id_code) +{ + PITEM_LISTVIEW_CONTEXT context; + INT item_count; + INT item_id; + + if ((listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_LOG) || listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID) + { + item_id = -1; + + item_count = _r_listview_getitemcount (hwnd, listview_id); + + if (item_count) + { + for (INT i = 0; i < item_count; i++) + { + context = (PITEM_LISTVIEW_CONTEXT)_r_listview_getitemlparam (hwnd, listview_id, i); + + if (!context) + continue; + + if (context->id_code == id_code) + { + item_id = i; + break; + } + } + } + } + else + { + item_id = _r_listview_finditem (hwnd, listview_id, -1, id_code); + } + + return item_id; +} + +VOID _app_listview_showitemby_id (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id, _In_ INT scroll_pos) +{ + INT total_count; + + _app_settab_id (hwnd, listview_id); + + total_count = _r_listview_getitemcount (hwnd, listview_id); + + if (!total_count) + return; + + if (item_id != -1) + { + item_id = _r_calc_clamp (item_id, 0, total_count - 1); + + _r_listview_setitemvisible (hwnd, listview_id, item_id); + } + + if (scroll_pos > 0) + SendDlgItemMessage (hwnd, listview_id, LVM_SCROLL, 0, (LPARAM)scroll_pos); // restore scroll position +} + +VOID _app_listview_showitemby_param (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ BOOLEAN is_app) +{ + INT listview_id; + INT item_id; + + if (is_app) + { + listview_id = PtrToInt (_app_getappinfobyhash (lparam, INFO_LISTVIEW_ID)); + } + else + { + listview_id = PtrToInt (_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID)); + } + + if (listview_id) + { + if (listview_id != _app_listview_getcurrent (hwnd)) + { + _app_listview_sort (hwnd, listview_id); + _app_listview_resize (hwnd, listview_id); + } + + item_id = _app_listview_finditem (hwnd, listview_id, lparam); + + if (item_id != -1) + { + _app_listview_showitemby_id (hwnd, listview_id, item_id, -1); + _r_wnd_toggle (hwnd, TRUE); + } + } +} + +VOID _app_listview_updateby_id (_In_ HWND hwnd, _In_ INT lparam, _In_ ULONG flags) +{ + INT listview_id; + ENUM_TYPE_DATA type; + + if (flags & PR_UPDATE_TYPE) + { + type = lparam; + + if (type == DATA_LISTVIEW_CURRENT) + { + listview_id = _app_listview_getcurrent (hwnd); + } + else + { + listview_id = _app_listview_getbytype (type); + } + } + else + { + listview_id = lparam; + } + + if ((flags & PR_UPDATE_FORCE) || (listview_id == _app_listview_getcurrent (hwnd))) + { + if (!(flags & PR_UPDATE_NOREDRAW)) + _r_listview_redraw (hwnd, listview_id, -1); + + if (!(flags & PR_UPDATE_NOSETVIEW)) + { + _app_listview_setfont (hwnd, listview_id); + _app_listview_setview (hwnd, listview_id); + } + + if (!(flags & PR_UPDATE_NOREFRESH)) + _app_listview_refreshgroups (hwnd, listview_id); + + if (!(flags & PR_UPDATE_NOSORT)) + _app_listview_sort (hwnd, listview_id); + + if (!(flags & PR_UPDATE_NORESIZE)) + _app_listview_resize (hwnd, listview_id); + } + + _app_refreshstatus (hwnd); +} + +VOID _app_listview_updateby_param (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ ULONG flags, _In_ BOOLEAN is_app) +{ + INT listview_id; + + if (is_app) + { + listview_id = PtrToInt (_app_getappinfobyhash (lparam, INFO_LISTVIEW_ID)); + } + else + { + listview_id = PtrToInt (_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID)); + } + + if (listview_id) + { + if ((flags & PR_SETITEM_UPDATE)) + _app_listview_updateby_id (hwnd, listview_id, 0); + + if ((flags & PR_SETITEM_REDRAW)) + { + if (listview_id == _app_listview_getcurrent (hwnd)) + _r_listview_redraw (hwnd, listview_id, -1); + } + } +} + +VOID _app_listview_updateitemby_param (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ BOOLEAN is_app) +{ + PITEM_APP ptr_app; + PITEM_RULE ptr_rule; + INT listview_id; + INT item_id; + + if (is_app) + { + listview_id = PtrToInt (_app_getappinfobyhash (lparam, INFO_LISTVIEW_ID)); + } + else + { + listview_id = PtrToInt (_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID)); + } + + if (listview_id) + { + item_id = _app_listview_finditem (hwnd, listview_id, lparam); + + if (item_id != -1) + { + if (is_app) + { + ptr_app = _app_getappitem (lparam); + + if (ptr_app) + { + _app_listview_lock (hwnd, listview_id, TRUE); + _app_setappiteminfo (hwnd, listview_id, item_id, ptr_app); + _app_listview_lock (hwnd, listview_id, FALSE); + + _r_obj_dereference (ptr_app); + } + } + else + { + ptr_rule = _app_getrulebyid (lparam); + + if (ptr_rule) + { + _app_listview_lock (hwnd, listview_id, TRUE); + _app_setruleiteminfo (hwnd, listview_id, item_id, ptr_rule, FALSE); + _app_listview_lock (hwnd, listview_id, FALSE); + + _r_obj_dereference (ptr_rule); + } + } + } + } +} + +VOID _app_listview_updateitemby_id (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id) +{ + _r_listview_setitem_ex (hwnd, listview_id, item_id, 0, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, 0); +} + +VOID _app_listview_loadfont (_In_ LONG dpi_value, _In_ BOOLEAN is_forced) +{ + LOGFONT logfont = {0}; + + if (is_forced || !config.hfont) + { + SAFE_DELETE_OBJECT (config.hfont); + + _r_config_getfont (L"Font", &logfont, dpi_value); + + config.hfont = _app_createfont (&logfont, 0, FALSE, 0); + } +} + +VOID _app_listview_refreshgroups (_In_ HWND hwnd, _In_ INT listview_id) +{ + UINT group1_title; + UINT group2_title; + UINT group3_title; + UINT group4_title; + + INT total_count; + + INT group1_count; + INT group2_count; + INT group3_count; + INT group4_count; + + INT group_id; + + if (!_r_listview_isgroupviewenabled (hwnd, listview_id)) + return; + + if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) + { + group1_title = IDS_GROUP_ALLOWED; + group2_title = IDS_GROUP_SPECIAL_APPS; + group3_title = IDS_GROUP_BLOCKED; + group4_title = IDS_GROUP_BLOCKED; + } + else if (listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM) + { + group1_title = IDS_GROUP_ENABLED; + group2_title = 0; + group3_title = IDS_GROUP_DISABLED; + group4_title = 0; + } + else if (listview_id == IDC_RULE_APPS_ID || listview_id == IDC_NETWORK) + { + group1_title = IDS_TAB_APPS; + group2_title = IDS_TAB_SERVICES; + group3_title = IDS_TAB_PACKAGES; + group4_title = 0; + } + else if (listview_id == IDC_APP_RULES_ID) + { + group1_title = IDS_TRAY_SYSTEM_RULES; + group2_title = IDS_TRAY_USER_RULES; + group3_title = 0; + group4_title = 0; + } + else + { + return; + } + + group1_count = 0; + group2_count = 0; + group3_count = 0; + group4_count = 0; + + total_count = _r_listview_getitemcount (hwnd, listview_id); + + for (INT i = 0; i < total_count; i++) + { + if (listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID) + { + if (_r_listview_isitemchecked (hwnd, listview_id, i)) + group1_count = group2_count = group3_count += 1; + } + else + { + group_id = _r_listview_getitemgroup (hwnd, listview_id, i); + + if (group_id == 3) + { + group4_count += 1; + } + else if (group_id == 2) + { + group3_count += 1; + } + else if (group_id == 1) + { + group2_count += 1; + } + else if (group_id == 0) + { + group1_count += 1; + } + } + } + + WCHAR group1_string[128] = {0}; + WCHAR group2_string[128] = {0}; + WCHAR group3_string[128] = {0}; + WCHAR group4_string[128] = {0}; + + if (total_count) + { + if (group1_title) + _r_str_printf (group1_string, RTL_NUMBER_OF (group1_string), L"%s (%d/%d)", _r_locale_getstring (group1_title), group1_count, total_count); + + if (group2_title) + _r_str_printf (group2_string, RTL_NUMBER_OF (group2_string), L"%s (%d/%d)", _r_locale_getstring (group2_title), group2_count, total_count); + + if (group3_title) + _r_str_printf (group3_string, RTL_NUMBER_OF (group3_string), L"%s (%d/%d)", _r_locale_getstring (group3_title), group3_count, total_count); + + if (group4_title) + _r_str_printf (group4_string, RTL_NUMBER_OF (group4_string), L"%s (%d/%d) [silent]", _r_locale_getstring (group4_title), group4_count, total_count); + } + + _r_listview_setgroup (hwnd, listview_id, 0, group1_string, 0, 0); + _r_listview_setgroup (hwnd, listview_id, 1, group2_string, 0, 0); + + if (group3_title) + _r_listview_setgroup (hwnd, listview_id, 2, group3_string, 0, 0); + + if (group4_title) + _r_listview_setgroup (hwnd, listview_id, 3, group4_string, 0, 0); +} + +VOID _app_listview_resize_ex (_In_ HWND hwnd, _In_ INT listview_id, _In_ BOOLEAN is_forced) +{ + PR_STRING column_text; + PR_STRING item_text; + HWND hlistview; + HWND hheader; + HDC hdc_listview; + HDC hdc_header; + LONG dpi_value; + INT column_count; + INT item_count; + INT column_width; + INT text_width; + INT calculated_width; + INT column_general_id; + INT total_width; + INT max_width; + INT spacing; + BOOLEAN is_tableview; + + if (!is_forced && !_r_config_getboolean (L"AutoSizeColumns", TRUE)) + return; + + hheader = NULL; + hdc_listview = NULL; + hdc_header = NULL; + + hlistview = GetDlgItem (hwnd, listview_id); + + if (!hlistview) + return; + + column_count = _r_listview_getcolumncount (hwnd, listview_id); + + if (!column_count) + return; + + // get device context and fix font set + hdc_listview = GetDC (hlistview); + + if (!hdc_listview) + goto CleanupExit; + + hheader = (HWND)SendMessage (hlistview, LVM_GETHEADER, 0, 0); + + hdc_header = GetDC (hheader); + + if (!hdc_header) + goto CleanupExit; + + _r_dc_fixwindowfont (hdc_listview, hlistview); // fix + _r_dc_fixwindowfont (hdc_header, hheader); // fix + + calculated_width = 0; + column_general_id = 0; // set general column id + + is_tableview = (_r_listview_getview (hwnd, listview_id) == LV_VIEW_DETAILS); + + dpi_value = _r_dc_getwindowdpi (hwnd); + + max_width = _r_dc_getdpi (158, dpi_value); + spacing = _r_dc_getsystemmetrics (SM_CXSMICON, dpi_value); + + total_width = _r_ctrl_getwidth (hwnd, listview_id); + item_count = _r_listview_getitemcount (hwnd, listview_id); + + for (INT i = 0; i < column_count; i++) + { + if (i == column_general_id) + continue; + + // get column text width + column_text = _r_listview_getcolumntext (hwnd, listview_id, i); + + if (!column_text) + continue; + + column_width = _r_dc_getfontwidth (hdc_header, &column_text->sr) + spacing; + + if (column_width >= max_width) + { + column_width = max_width; + } + else + { + // calculate max width of listview subitems (only for details view) + if (is_tableview) + { + for (INT j = 0; j < item_count; j++) + { + item_text = _r_listview_getitemtext (hwnd, listview_id, j, i); + + if (item_text) + { + text_width = _r_dc_getfontwidth (hdc_listview, &item_text->sr) + spacing; + + _r_obj_dereference (item_text); + + // do not continue reaching higher and higher values for performance reason! + if (text_width >= max_width) + { + column_width = max_width; + break; + } + + if (text_width > column_width) + column_width = text_width; + } + } + } + } + + _r_listview_setcolumn (hwnd, listview_id, i, NULL, column_width); + + calculated_width += column_width; + + _r_obj_dereference (column_text); + } + + // set general column width + _r_listview_setcolumn (hwnd, listview_id, column_general_id, NULL, max (total_width - calculated_width, max_width)); + +CleanupExit: + + if (hdc_listview) + ReleaseDC (hlistview, hdc_listview); + + if (hdc_header) + ReleaseDC (hheader, hdc_header); +} + +VOID _app_listview_setfont (_In_ HWND hwnd, _In_ INT listview_id) +{ + if (config.hfont) + SendDlgItemMessage (hwnd, listview_id, WM_SETFONT, (WPARAM)config.hfont, TRUE); +} + +VOID _app_listview_setview (_In_ HWND hwnd, _In_ INT listview_id) +{ + HIMAGELIST himg; + LONG view_type; + LONG icons_size; + BOOLEAN is_mainview; + + is_mainview = (listview_id >= IDC_APPS_PROFILE) && (listview_id <= IDC_RULES_CUSTOM); + view_type = is_mainview ? _r_calc_clamp32 (_r_config_getlong (L"ViewType", LV_VIEW_DETAILS), LV_VIEW_ICON, LV_VIEW_MAX) : LV_VIEW_DETAILS; + icons_size = is_mainview ? _r_calc_clamp32 (_r_config_getlong (L"IconSize", SHIL_SMALL), SHIL_LARGE, SHIL_LAST) : SHIL_SMALL; + + if (listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM || listview_id == IDC_APP_RULES_ID) + { + himg = (icons_size == SHIL_SMALL || icons_size == SHIL_SYSSMALL) ? config.himg_rules_small : config.himg_rules_large; + } + else + { + SHGetImageList (icons_size, &IID_IImageList2, &himg); + } + + if (himg) + _r_listview_setimagelist (hwnd, listview_id, himg); + + _r_listview_setview (hwnd, listview_id, view_type); +} + +INT CALLBACK _app_listview_compare_callback (_In_ LPARAM lparam1, _In_ LPARAM lparam2, _In_ LPARAM lparam) +{ + WCHAR config_name[128]; + HWND hwnd; + LONG column_id; + INT listview_id; + INT result; + INT item_id1; + INT item_id2; + BOOLEAN is_descend; + + PR_STRING item_text_1; + PR_STRING item_text_2; + PITEM_LOG ptr_log1; + PITEM_LOG ptr_log2; + PVOID timer1_ptr; + PVOID timer2_ptr; + LONG64 timestamp1; + LONG64 timestamp2; + BOOLEAN is_checked1; + BOOLEAN is_checked2; + + hwnd = GetParent ((HWND)lparam); + + if (!hwnd) + return 0; + + listview_id = GetDlgCtrlID ((HWND)lparam); + + if (!listview_id) + return 0; + + item_id1 = (INT)(INT_PTR)lparam1; + item_id2 = (INT)(INT_PTR)lparam2; + + _r_str_printf (config_name, RTL_NUMBER_OF (config_name), L"listview\\%04" TEXT (PRIX32), listview_id); + + column_id = _r_config_getlong_ex (L"SortColumn", 0, config_name); + is_descend = _r_config_getboolean_ex (L"SortIsDescending", FALSE, config_name); + + result = 0; + + if ((_r_listview_getexstyle (hwnd, listview_id) & LVS_EX_CHECKBOXES) != 0) + { + is_checked1 = _r_listview_isitemchecked (hwnd, listview_id, item_id1); + is_checked2 = _r_listview_isitemchecked (hwnd, listview_id, item_id2); + + if (is_checked1 != is_checked2) + { + if (is_checked1 && !is_checked2) + { + result = is_descend ? 1 : -1; + } + else if (!is_checked1 && is_checked2) + { + result = is_descend ? -1 : 1; + } + } + } + + if (!result) + { + // timestamp sorting + if ((listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) && column_id == 1) + { + timer1_ptr = _app_getappinfobyhash (_app_listview_getitemcontext (hwnd, listview_id, item_id1), INFO_TIMESTAMP_PTR); + timer2_ptr = _app_getappinfobyhash (_app_listview_getitemcontext (hwnd, listview_id, item_id2), INFO_TIMESTAMP_PTR); + + if (timer1_ptr && timer2_ptr) + { + timestamp1 = *((PLONG64)timer1_ptr); + timestamp2 = *((PLONG64)timer2_ptr); + + if (timestamp1 < timestamp2) + { + result = -1; + } + else if (timestamp1 > timestamp2) + { + result = 1; + } + } + } + else if (listview_id == IDC_LOG && column_id == 11) + { + ptr_log1 = _app_getlogitem (_app_listview_getitemcontext (hwnd, listview_id, item_id1)); + ptr_log2 = _app_getlogitem (_app_listview_getitemcontext (hwnd, listview_id, item_id2)); + + if (ptr_log1 && ptr_log2) + { + if (ptr_log1->timestamp < ptr_log2->timestamp) + { + result = -1; + } + else if (ptr_log1->timestamp > ptr_log2->timestamp) + { + result = 1; + } + } + + if (ptr_log1) + _r_obj_dereference (ptr_log1); + + if (ptr_log2) + _r_obj_dereference (ptr_log2); + } + } + + if (!result) + { + item_text_1 = _r_listview_getitemtext (hwnd, listview_id, item_id1, column_id); + item_text_2 = _r_listview_getitemtext (hwnd, listview_id, item_id2, column_id); + + if (item_text_1 && item_text_2) + { + result = _r_str_compare_logical (item_text_1, item_text_2); + } + + if (item_text_1) + _r_obj_dereference (item_text_1); + + if (item_text_2) + _r_obj_dereference (item_text_2); + } + + return is_descend ? -result : result; +} + +VOID _app_listview_sort_ex (_In_ HWND hwnd, _In_ INT listview_id, _In_ LONG column_id, _In_ BOOLEAN is_notifycode) +{ + HWND hlistview; + INT column_count; + BOOLEAN is_descend; + + hlistview = GetDlgItem (hwnd, listview_id); + + if (!hlistview) + return; + + if ((GetWindowLongPtr (hlistview, GWL_STYLE) & (LVS_NOSORTHEADER | LVS_OWNERDATA)) != 0) + return; + + column_count = _r_listview_getcolumncount (hwnd, listview_id); + + if (!column_count) + return; + + WCHAR config_name[128]; + _r_str_printf (config_name, RTL_NUMBER_OF (config_name), L"listview\\%04" TEXT (PRIX32), listview_id); + + is_descend = _r_config_getboolean_ex (L"SortIsDescending", FALSE, config_name); + + if (is_notifycode) + is_descend = !is_descend; + + if (column_id == -1) + column_id = _r_config_getlong_ex (L"SortColumn", 0, config_name); + + column_id = _r_calc_clamp32 (column_id, 0, column_count - 1); // set range + + if (is_notifycode) + { + _r_config_setboolean_ex (L"SortIsDescending", is_descend, config_name); + _r_config_setlong_ex (L"SortColumn", column_id, config_name); + } + + for (INT i = 0; i < column_count; i++) + _r_listview_setcolumnsortindex (hwnd, listview_id, i, 0); + + _r_listview_setcolumnsortindex (hwnd, listview_id, column_id, is_descend ? -1 : 1); + + SendMessage (hlistview, LVM_SORTITEMSEX, (WPARAM)hlistview, (LPARAM)&_app_listview_compare_callback); +} diff --git a/src/listview.h b/src/listview.h new file mode 100644 index 00000000..59dba585 --- /dev/null +++ b/src/listview.h @@ -0,0 +1,78 @@ +// simplewall +// Copyright (c) 2016-2021 Henry++ + +#pragma once + +typedef struct _ITEM_LISTVIEW_CONTEXT +{ + ULONG_PTR id_code; + + struct + { + ULONG is_hidden : 1; + ULONG spare_bits : 31; + } DUMMYSTRUCTNAME; +} ITEM_LISTVIEW_CONTEXT, *PITEM_LISTVIEW_CONTEXT; + +#define PR_SETITEM_REDRAW 0x0001 +#define PR_SETITEM_UPDATE 0x0002 + +#define PR_UPDATE_TYPE 0x0001 +#define PR_UPDATE_FORCE 0x0002 +#define PR_UPDATE_NOREFRESH 0x0004 +#define PR_UPDATE_NOSORT 0x0008 +#define PR_UPDATE_NORESIZE 0x0010 +#define PR_UPDATE_NOREDRAW 0x0020 +#define PR_UPDATE_NOSETVIEW 0x0040 + +INT _app_listview_getcurrent (_In_ HWND hwnd); +INT _app_listview_getbytab (_In_ HWND hwnd, _In_ INT tab_id); +INT _app_listview_getbytype (_In_ ENUM_TYPE_DATA type); + +VOID _app_listview_additems (_In_ HWND hwnd); +VOID _app_listview_clearitems (_In_ HWND hwnd); + +VOID _app_listview_addappitem (_In_ HWND hwnd, _In_ PITEM_APP ptr_app); +VOID _app_listview_addruleitem (_In_ HWND hwnd, _In_ PITEM_RULE ptr_rule, _In_ SIZE_T rule_idx, _In_ BOOLEAN is_forapp); +VOID _app_listview_addnetworkitem (_In_ HWND hwnd, _In_ PITEM_NETWORK ptr_network, _In_ ULONG_PTR network_hash); +VOID _app_listview_addlogitem (_In_ HWND hwnd, _In_ PITEM_LOG ptr_log, _In_ ULONG_PTR log_hash); + +BOOLEAN _app_listview_islocked (_In_ HWND hwnd, _In_ INT ctrl_id); +VOID _app_listview_lock (_In_ HWND hwnd, _In_ INT ctrl_id, _In_ BOOLEAN is_lock); + +LPARAM _app_listview_createcontext (_In_ ULONG_PTR id_code); +VOID _app_listview_destroycontext (_In_ PITEM_LISTVIEW_CONTEXT context); +ULONG_PTR _app_listview_getcontextcode (_In_ LPARAM lparam); +ULONG_PTR _app_listview_getitemcontext (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id); +BOOLEAN _app_listview_isitemhidden (_In_ LPARAM lparam); + +_Success_ (return != -1) +INT _app_listview_finditem (_In_ HWND hwnd, _In_ INT listview_id, _In_ ULONG_PTR id_code); + +VOID _app_listview_showitemby_id (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id, _In_ INT scroll_pos); +VOID _app_listview_showitemby_param (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ BOOLEAN is_app); + +VOID _app_listview_updateby_id (_In_ HWND hwnd, _In_ INT lparam, _In_ ULONG flags); +VOID _app_listview_updateby_param (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ ULONG flags, _In_ BOOLEAN is_app); + +VOID _app_listview_updateitemby_param (_In_ HWND hwnd, _In_ ULONG_PTR lparam, _In_ BOOLEAN is_app); +VOID _app_listview_updateitemby_id (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id); + +VOID _app_listview_loadfont (_In_ LONG dpi_value, _In_ BOOLEAN is_forced); +VOID _app_listview_refreshgroups (_In_ HWND hwnd, _In_ INT listview_id); +VOID _app_listview_resize_ex (_In_ HWND hwnd, _In_ INT listview_id, _In_ BOOLEAN is_forced); +VOID _app_listview_setfont (_In_ HWND hwnd, _In_ INT listview_id); +VOID _app_listview_setview (_In_ HWND hwnd, _In_ INT listview_id); + +INT CALLBACK _app_listview_compare_callback (_In_ LPARAM lparam1, _In_ LPARAM lparam2, _In_ LPARAM lparam); +VOID _app_listview_sort_ex (_In_ HWND hwnd, _In_ INT listview_id, _In_ LONG column_id, _In_ BOOLEAN is_notifycode); + +FORCEINLINE VOID _app_listview_resize (_In_ HWND hwnd, _In_ INT listview_id) +{ + _app_listview_resize_ex (hwnd, listview_id, FALSE); +} + +FORCEINLINE VOID _app_listview_sort (_In_ HWND hwnd, _In_ INT listview_id) +{ + _app_listview_sort_ex (hwnd, listview_id, -1, FALSE); +} diff --git a/src/log.c b/src/log.c index 7dc37aff..7c445daa 100644 --- a/src/log.c +++ b/src/log.c @@ -130,7 +130,7 @@ VOID _app_logclear_ui (_In_ HWND hwnd) SendDlgItemMessage (hwnd, IDC_LOG, LVM_DELETEALLITEMS, 0, 0); //SendDlgItemMessage (hwnd, IDC_LOG, LVM_SETITEMCOUNT, 0, 0); - _app_listviewresize (hwnd, IDC_LOG, FALSE); + _app_listview_resize (hwnd, IDC_LOG); _r_queuedlock_acquireexclusive (&lock_loglist); @@ -219,9 +219,8 @@ VOID _app_logwrite (_In_ PITEM_LOG ptr_log) VOID _app_logwrite_ui (_In_ HWND hwnd, _In_ PITEM_LOG ptr_log) { - PITEM_CONTEXT context; - PITEM_APP ptr_app; ULONG_PTR log_hash; + ULONG_PTR hash_code; SIZE_T table_size; INT item_id; @@ -242,46 +241,25 @@ VOID _app_logwrite_ui (_In_ HWND hwnd, _In_ PITEM_LOG ptr_log) if (table_size >= MAP_CACHE_MAX) { - ULONG_PTR hash_code; - item_id = _r_listview_getitemcount (hwnd, IDC_LOG) - 1; - hash_code = _app_getlistviewitemcontext (hwnd, IDC_LOG, item_id); + hash_code = _app_listview_getitemcontext (hwnd, IDC_LOG, item_id); _r_listview_deleteitem (hwnd, IDC_LOG, item_id); _r_queuedlock_acquireexclusive (&lock_loglist); - _r_obj_removehashtablepointer (log_table, hash_code); - _r_queuedlock_releaseexclusive (&lock_loglist); } _r_queuedlock_acquireexclusive (&lock_loglist); - _r_obj_addhashtablepointer (log_table, log_hash, _r_obj_reference (ptr_log)); - _r_queuedlock_releaseexclusive (&lock_loglist); - ptr_app = _app_getappitem (ptr_log->app_hash); + _app_listview_addlogitem (hwnd, ptr_log, log_hash); - item_id = _r_listview_getitemcount (hwnd, IDC_LOG); + _app_queue_resolver (hwnd, IDC_LOG, log_hash, ptr_log); - _r_listview_additem_ex (hwnd, IDC_LOG, item_id, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, 0, _app_createlistviewcontext (log_hash)); - - // resolve network address - context = _r_freelist_allocateitem (&context_free_list); - - context->hwnd = hwnd; - context->listview_id = IDC_LOG; - context->lparam = log_hash; - context->ptr_log = _r_obj_reference (ptr_log); - - _r_workqueue_queueitem (&resolver_queue, &_app_queueresolveinformation, context); - - if (ptr_app) - _r_obj_dereference (ptr_app); - - _app_updatelistviewbylparam (hwnd, IDC_LOG, 0); + _app_listview_updateby_id (hwnd, IDC_LOG, 0); } VOID _wfp_logsubscribe (_In_ HANDLE engine_handle) @@ -1251,7 +1229,7 @@ VOID NTAPI _app_logthread (_In_ PVOID arglist, _In_ ULONG busy_count) ptr_app = _app_getappitem (ptr_log->app_hash); if (ptr_app) - _app_updatelistviewbylparam (hwnd, ptr_app->type, PR_UPDATE_TYPE); + _app_listview_updateby_id (hwnd, ptr_app->type, PR_UPDATE_TYPE); _app_profile_save (); } diff --git a/src/main.c b/src/main.c index dcd0a78b..3e1bfc58 100644 --- a/src/main.c +++ b/src/main.c @@ -8,9 +8,9 @@ BOOLEAN _app_changefilters (_In_ HWND hwnd, _In_ BOOLEAN is_install, _In_ BOOLEA PITEM_CONTEXT context; INT listview_id; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); - _app_listviewsort (hwnd, listview_id, -1, FALSE); + _app_listview_sort (hwnd, listview_id); if (is_forced || _wfp_isfiltersinstalled ()) { @@ -401,7 +401,7 @@ VOID _app_config_apply (_In_ HWND hwnd, _In_opt_ HWND hsettings, _In_ INT ctrl_i while (_r_obj_enumhashtablepointer (apps_table, &ptr_app, NULL, &enum_key)) { if (ptr_app->real_path) - _app_queryfileinformation (ptr_app->real_path, ptr_app->app_hash, ptr_app->type, _app_getlistviewbytype_id (ptr_app->type)); + _app_queue_fileinformation (ptr_app->real_path, ptr_app->app_hash, ptr_app->type, _app_listview_getbytype (ptr_app->type)); } _r_queuedlock_releaseshared (&lock_apps); @@ -546,7 +546,7 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam // configure listview _r_listview_setstyle (hwnd, IDC_COLORS, LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_CHECKBOXES, FALSE); - _app_listviewsetview (hwnd, IDC_COLORS); + _app_listview_setview (hwnd, IDC_COLORS); _r_listview_deleteallitems (hwnd, IDC_COLORS); _r_listview_deleteallcolumns (hwnd, IDC_COLORS); @@ -560,7 +560,7 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam icon_id = _app_icons_getdefaultapp_id (); - _app_setcheckboxlock (hwnd, IDC_COLORS, TRUE); + _app_listview_lock (hwnd, IDC_COLORS, TRUE); enum_key = 0; item_id = 0; @@ -575,7 +575,7 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam item_id += 1; } - _app_setcheckboxlock (hwnd, IDC_COLORS, FALSE); + _app_listview_lock (hwnd, IDC_COLORS, FALSE); break; } @@ -905,7 +905,7 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam if ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (1) || ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2))) { - if (_app_ischeckboxlocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom)) + if (_app_listview_islocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom)) break; PITEM_COLOR ptr_clr; @@ -919,7 +919,7 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam _r_config_setboolean_ex (_r_obj_getstring (ptr_clr->config_name), is_enabled, L"colors"); - _r_listview_redraw (_r_app_gethwnd (), _app_getcurrentlistview_id (_r_app_gethwnd ()), -1); + _r_listview_redraw (_r_app_gethwnd (), _app_listview_getcurrent (_r_app_gethwnd ()), -1); } } @@ -984,7 +984,7 @@ INT_PTR CALLBACK SettingsProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam _r_config_setulong_ex (_r_obj_getstring (ptr_clr_current->config_value), cc.rgbResult, L"colors"); _r_listview_redraw (hwnd, IDC_COLORS, -1); - _r_listview_redraw (_r_app_gethwnd (), _app_getcurrentlistview_id (_r_app_gethwnd ()), -1); + _r_listview_redraw (_r_app_gethwnd (), _app_listview_getcurrent (_r_app_gethwnd ()), -1); } } } @@ -1476,14 +1476,14 @@ VOID _app_tabs_init (_In_ HWND hwnd, _In_ LONG dpi_value) SetWindowPos (config.hrebar, NULL, 0, 0, rect.right, rebar_height, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER); SetWindowPos (GetDlgItem (hwnd, IDC_TAB), NULL, 0, rebar_height, rect.right, rect.bottom - rebar_height - statusbar_height, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER); - _app_listviewloadfont (dpi_value, TRUE); + _app_listview_loadfont (dpi_value, TRUE); style = LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_HEADERINALLVIEWS | LVS_EX_HEADERDRAGDROP; tabs_count = _app_addwindowtabs (hwnd); for (INT i = 0; i < tabs_count; i++) { - listview_id = _app_getlistviewbytab_id (hwnd, i); + listview_id = _app_listview_getbytab (hwnd, i); hlistview = GetDlgItem (hwnd, listview_id); if (!hlistview) @@ -1552,7 +1552,7 @@ VOID _app_tabs_init (_In_ HWND hwnd, _In_ LONG dpi_value) // add filter group _r_listview_addgroup (hwnd, listview_id, LV_HIDDEN_GROUP_ID, L"", 0, LVGS_HIDDEN | LVGS_NOHEADER | LVGS_COLLAPSED, LVGS_HIDDEN | LVGS_NOHEADER | LVGS_COLLAPSED); - _app_listviewsetfont (hwnd, listview_id); + _app_listview_setfont (hwnd, listview_id); BringWindowToTop (hlistview); // HACK!!! } @@ -1615,7 +1615,7 @@ VOID _app_initialize () // initialize free list _r_freelist_initialize (&context_free_list, sizeof (ITEM_CONTEXT), 32); - _r_freelist_initialize (&listview_free_list, sizeof (ITEM_LISTVIEW_CONTEXT), 512); + _r_freelist_initialize (&listview_free_list, sizeof (ITEM_LISTVIEW_CONTEXT), 2048); // initialize colors array if (!colors_table) @@ -1911,7 +1911,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In { HANDLE hengine; - _r_config_setlong (L"CurrentTab", _app_getcurrentlistview_id (hwnd)); + _r_config_setlong (L"CurrentTab", _app_listview_getcurrent (hwnd)); _app_network_uninitialize (); @@ -1974,8 +1974,8 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In if (app_hash) { - _app_setlistviewbylparam (hwnd, app_hash, PR_SETITEM_UPDATE, TRUE); - _app_showitembylparam (hwnd, app_hash, TRUE); + _app_listview_updateby_param (hwnd, app_hash, PR_SETITEM_UPDATE, TRUE); + _app_listview_showitemby_param (hwnd, app_hash, TRUE); } break; @@ -1994,9 +1994,9 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In dpi_value = _r_dc_getwindowdpi (hwnd); _app_windowloadfont (dpi_value); - _app_listviewloadfont (dpi_value, TRUE); + _app_listview_loadfont (dpi_value, TRUE); - _app_updatelistviewbylparam (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); + _app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); SendMessage (hwnd, WM_SIZE, 0, 0); @@ -2052,7 +2052,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In HWND hlistview; INT listview_id; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); if (!listview_id) break; @@ -2072,7 +2072,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In HWND hlistview; INT listview_id; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); if (!listview_id) break; @@ -2084,14 +2084,14 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In _app_search_applyfilter (hwnd, listview_id, config.search_string); - _app_updatelistviewbylparam (hwnd, listview_id, PR_UPDATE_FORCE | PR_UPDATE_NORESIZE); + _app_listview_updateby_id (hwnd, listview_id, PR_UPDATE_FORCE | PR_UPDATE_NORESIZE); ShowWindow (hlistview, SW_SHOWNA); if (_r_wnd_isvisiblefull (hwnd)) // HACK!!! SetFocus (hlistview); - _app_listviewresize (hwnd, listview_id, FALSE); + _app_listview_resize (hwnd, listview_id); break; } @@ -2148,7 +2148,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In if (!context) break; - _app_destroylistviewcontext (context); + _app_listview_destroycontext (context); break; } @@ -2161,7 +2161,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In lpnmlv = (LPNMLISTVIEW)lparam; ctrl_id = (INT)(INT_PTR)lpnmlv->hdr.idFrom; - _app_listviewsort (hwnd, ctrl_id, lpnmlv->iSubItem, TRUE); + _app_listview_sort_ex (hwnd, ctrl_id, lpnmlv->iSubItem, TRUE); break; } @@ -2175,7 +2175,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In lpnmlv = (LPNMLVGETINFOTIP)lparam; listview_id = (INT)lpnmlv->hdr.idFrom; - string = _app_gettooltipbylparam (hwnd, listview_id, _app_getlistviewitemcontext (hwnd, listview_id, lpnmlv->iItem)); + string = _app_gettooltipbylparam (hwnd, listview_id, _app_listview_getitemcontext (hwnd, listview_id, lpnmlv->iItem)); if (string) { @@ -2195,7 +2195,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In lpnmlv = (LPNMLISTVIEW)lparam; - if (_app_ischeckboxlocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom)) + if (_app_listview_islocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom)) break; if (!(lpnmlv->uChanged & LVIF_STATE)) @@ -2208,7 +2208,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In if ((listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP)) { - app_hash = _app_getlistviewparam_id (lpnmlv->lParam); + app_hash = _app_listview_getcontextcode (lpnmlv->lParam); if ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (1)) { @@ -2257,7 +2257,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In { if ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (1) || ((lpnmlv->uNewState & LVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK (2))) { - if (_app_ischeckboxlocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom)) + if (_app_listview_islocked (hwnd, (INT)(INT_PTR)lpnmlv->hdr.idFrom)) break; ULONG_PTR app_hash; @@ -2271,7 +2271,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) { - app_hash = _app_getlistviewparam_id (lpnmlv->lParam); + app_hash = _app_listview_getcontextcode (lpnmlv->lParam); ptr_app = _app_getappitem (app_hash); if (!ptr_app) @@ -2281,9 +2281,9 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In { ptr_app->is_enabled = is_enabled; - _app_setcheckboxlock (hwnd, listview_id, TRUE); + _app_listview_lock (hwnd, listview_id, TRUE); _app_setappiteminfo (hwnd, listview_id, lpnmlv->iItem, ptr_app); - _app_setcheckboxlock (hwnd, listview_id, FALSE); + _app_listview_lock (hwnd, listview_id, FALSE); if (is_enabled) _app_notify_freeobject (ptr_app); @@ -2317,7 +2317,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In SIZE_T rule_idx; PITEM_RULE ptr_rule; - rule_idx = _app_getlistviewparam_id (lpnmlv->lParam); + rule_idx = _app_listview_getcontextcode (lpnmlv->lParam); ptr_rule = _app_getrulebyid (rule_idx); if (!ptr_rule) @@ -2325,12 +2325,12 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In if (ptr_rule->is_enabled != is_enabled) { - _app_setcheckboxlock (hwnd, listview_id, TRUE); + _app_listview_lock (hwnd, listview_id, TRUE); _app_ruleenable (ptr_rule, is_enabled, TRUE); _app_setruleiteminfo (hwnd, listview_id, lpnmlv->iItem, ptr_rule, TRUE); - _app_setcheckboxlock (hwnd, listview_id, FALSE); + _app_listview_lock (hwnd, listview_id, FALSE); if (_wfp_isfiltersinstalled ()) { @@ -2356,7 +2356,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In if (is_changed) { - _app_updatelistviewbylparam (hwnd, listview_id, 0); + _app_listview_updateby_id (hwnd, listview_id, 0); _app_profile_save (); } @@ -2538,7 +2538,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In if (ctrl_id != IDC_SEARCH) break; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); string = _r_ctrl_getstring (config.hrebar, IDC_SEARCH); _r_obj_swapreference (&config.search_string, string); @@ -2747,7 +2747,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In _r_config_setboolean (L"AutoSizeColumns", new_val); if (new_val) - _app_listviewresize (hwnd, _app_getcurrentlistview_id (hwnd), FALSE); + _app_listview_resize (hwnd, _app_listview_getcurrent (hwnd)); break; } @@ -2762,10 +2762,10 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In _r_menu_checkitem (GetMenu (hwnd), ctrl_id, 0, MF_BYCOMMAND, new_val); _r_config_setboolean (L"ShowFilenames", new_val); - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); _r_listview_redraw (hwnd, listview_id, -1); - _app_listviewsort (hwnd, listview_id, -1, FALSE); + _app_listview_sort (hwnd, listview_id); break; } @@ -2811,7 +2811,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In _r_menu_checkitem (GetMenu (hwnd), IDM_VIEW_DETAILS, IDM_VIEW_TILE, MF_BYCOMMAND, ctrl_id); _r_config_setlong (L"ViewType", view_type); - _app_updatelistviewbylparam (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE); + _app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE); break; } @@ -2838,7 +2838,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In _r_menu_checkitem (GetMenu (hwnd), IDM_SIZE_SMALL, IDM_SIZE_EXTRALARGE, MF_BYCOMMAND, ctrl_id); _r_config_setlong (L"IconSize", icon_size); - _app_updatelistviewbylparam (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE); + _app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE); break; } @@ -2863,7 +2863,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In while (_r_obj_enumhashtablepointer (apps_table, &ptr_app, NULL, &enum_key)) { if (ptr_app->real_path) - _app_queryfileinformation (ptr_app->real_path, ptr_app->app_hash, ptr_app->type, _app_getlistviewbytype_id (ptr_app->type)); + _app_queue_fileinformation (ptr_app->real_path, ptr_app->app_hash, ptr_app->type, _app_listview_getbytype (ptr_app->type)); } _r_queuedlock_releaseshared (&lock_apps); @@ -3111,8 +3111,8 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In if (app_hash) { - _app_setlistviewbylparam (hwnd, app_hash, PR_SETITEM_UPDATE, TRUE); - _app_showitembylparam (hwnd, app_hash, TRUE); + _app_listview_updateby_param (hwnd, app_hash, PR_SETITEM_UPDATE, TRUE); + _app_listview_showitemby_param (hwnd, app_hash, TRUE); _app_profile_save (); } @@ -3141,18 +3141,23 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In case IDM_EXPLORE: { + PITEM_APP ptr_app; + PITEM_NETWORK ptr_network; + PITEM_LOG ptr_log; + ULONG_PTR hash_code; - INT listview_id = _app_getcurrentlistview_id (hwnd); - INT item_id = -1; + INT listview_id; + INT item_id; + + listview_id = _app_listview_getcurrent (hwnd); + item_id = -1; if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) { - PITEM_APP ptr_app; - while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != -1) { - hash_code = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + hash_code = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_app = _app_getappitem (hash_code); if (ptr_app) @@ -3169,11 +3174,9 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In } else if (listview_id == IDC_NETWORK) { - PITEM_NETWORK ptr_network; - while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != -1) { - hash_code = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + hash_code = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_network = _app_network_getitem (hash_code); if (ptr_network) @@ -3190,11 +3193,9 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In } else if (listview_id == IDC_LOG) { - PITEM_LOG ptr_log; - while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != -1) { - hash_code = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + hash_code = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_log = _app_getlogitem (hash_code); if (ptr_log) @@ -3254,7 +3255,7 @@ INT_PTR CALLBACK DlgProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wparam, _In { INT listview_id; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); if (listview_id) { diff --git a/src/messages.c b/src/messages.c index e492436c..f5bda18e 100644 --- a/src/messages.c +++ b/src/messages.c @@ -42,7 +42,7 @@ VOID _app_message_contextmenu (_In_ HWND hwnd, _In_ LPNMITEMACTIVATE lpnmlv) localized_string = NULL; column_text = NULL; - hash_code = _app_getlistviewitemcontext (hwnd, listview_id, lpnmlv->iItem); + hash_code = _app_listview_getitemcontext (hwnd, listview_id, lpnmlv->iItem); lv_column_current = lpnmlv->iSubItem; if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) @@ -434,8 +434,8 @@ VOID _app_message_dpichanged (_In_ HWND hwnd, _In_ LONG dpi_value) _r_toolbar_setbutton (config.hrebar, IDC_TOOLBAR, IDM_DONATE, _r_locale_getstring (IDS_DONATE), BTNS_BUTTON | BTNS_AUTOSIZE, 0, I_IMAGENONE); - _app_listviewloadfont (dpi_value, TRUE); - _app_updatelistviewbylparam (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); + _app_listview_loadfont (dpi_value, TRUE); + _app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); SendMessage (hwnd, WM_SIZE, 0, 0); @@ -557,7 +557,7 @@ LONG_PTR _app_message_custdraw (_In_ HWND hwnd, _In_ LPNMLVCUSTOMDRAW lpnmlv) if ((ctrl_id >= IDC_APPS_PROFILE && ctrl_id <= IDC_APPS_UWP) || ctrl_id == IDC_RULE_APPS_ID || ctrl_id == IDC_NETWORK || ctrl_id == IDC_LOG) { app_hash = 0; - index = _app_getlistviewparam_id (lpnmlv->nmcd.lItemlParam); + index = _app_listview_getcontextcode (lpnmlv->nmcd.lItemlParam); if (ctrl_id == IDC_NETWORK) { @@ -607,7 +607,7 @@ LONG_PTR _app_message_custdraw (_In_ HWND hwnd, _In_ LPNMLVCUSTOMDRAW lpnmlv) } else if (ctrl_id >= IDC_RULES_BLOCKLIST && ctrl_id <= IDC_RULES_CUSTOM || ctrl_id == IDC_APP_RULES_ID) { - index = _app_getlistviewparam_id (lpnmlv->nmcd.lItemlParam); + index = _app_listview_getcontextcode (lpnmlv->nmcd.lItemlParam); new_clr = _app_getrulecolor (ctrl_id, index); } @@ -682,7 +682,7 @@ VOID _app_displayinfoapp_callback (_In_ INT listview_id, _In_ PITEM_APP ptr_app, // set group id if ((lpnmlv->item.mask & LVIF_GROUPID)) { - if (_app_islistviewitemhidden (lpnmlv->item.lParam)) + if (_app_listview_isitemhidden (lpnmlv->item.lParam)) { lpnmlv->item.iGroupId = LV_HIDDEN_GROUP_ID; } @@ -799,7 +799,7 @@ VOID _app_displayinforule_callback (_In_ INT listview_id, _In_ PITEM_RULE ptr_ru // set group id if ((lpnmlv->item.mask & LVIF_GROUPID)) { - if (_app_islistviewitemhidden (lpnmlv->item.lParam)) + if (_app_listview_isitemhidden (lpnmlv->item.lParam)) { lpnmlv->item.iGroupId = LV_HIDDEN_GROUP_ID; } @@ -955,7 +955,7 @@ VOID _app_displayinfonetwork_callback (_In_ PITEM_NETWORK ptr_network, _Inout_ L // set group id if ((lpnmlv->item.mask & LVIF_GROUPID)) { - if (_app_islistviewitemhidden (lpnmlv->item.lParam)) + if (_app_listview_isitemhidden (lpnmlv->item.lParam)) { lpnmlv->item.iGroupId = LV_HIDDEN_GROUP_ID; } @@ -1151,7 +1151,7 @@ VOID _app_displayinfolog_callback (_Inout_ LPNMLVDISPINFOW lpnmlv, _In_opt_ PITE // set group id if ((lpnmlv->item.mask & LVIF_GROUPID)) { - if (_app_islistviewitemhidden (lpnmlv->item.lParam)) + if (_app_listview_isitemhidden (lpnmlv->item.lParam)) { lpnmlv->item.iGroupId = LV_HIDDEN_GROUP_ID; } @@ -1170,7 +1170,7 @@ BOOLEAN _app_message_displayinfo (_In_ HWND hwnd, _In_ INT listview_id, _Inout_ PITEM_LOG ptr_log; ULONG_PTR index; - index = _app_getlistviewitemcontext (hwnd, listview_id, lpnmlv->item.iItem); + index = _app_listview_getitemcontext (hwnd, listview_id, lpnmlv->item.iItem); if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP || listview_id == IDC_RULE_APPS_ID) { @@ -1486,7 +1486,7 @@ VOID _app_message_localize (_In_ HWND hwnd) for (INT i = 0; i < _r_tab_getitemcount (hwnd, IDC_TAB); i++) { - listview_id = _app_getlistviewbytab_id (hwnd, i); + listview_id = _app_listview_getbytab (hwnd, i); if (listview_id == IDC_APPS_PROFILE) { @@ -1592,7 +1592,7 @@ VOID _app_message_localize (_In_ HWND hwnd) } } - _app_updatelistviewbylparam (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); + _app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); if (localized_string) _r_obj_dereference (localized_string); @@ -1609,7 +1609,7 @@ VOID _app_command_idtorules (_In_ HWND hwnd, _In_ INT ctrl_id) INT item_id; BOOL is_remove; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); if (!_r_listview_getselectedcount (hwnd, listview_id)) return; @@ -1625,7 +1625,7 @@ VOID _app_command_idtorules (_In_ HWND hwnd, _In_ INT ctrl_id) while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != -1) { - app_hash = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + app_hash = _app_listview_getitemcontext (hwnd, listview_id, item_id); if (ptr_rule->is_forservices && _app_issystemhash (app_hash)) continue; @@ -1659,8 +1659,8 @@ VOID _app_command_idtorules (_In_ HWND hwnd, _In_ INT ctrl_id) } } - _app_updatelistviewbylparam (hwnd, listview_id, 0); - _app_updateitembylparam (hwnd, rule_idx, FALSE); + _app_listview_updateby_id (hwnd, listview_id, 0); + _app_listview_updateitemby_param (hwnd, rule_idx, FALSE); _r_obj_dereference (rules); _r_obj_dereference (ptr_rule); @@ -1675,7 +1675,7 @@ VOID _app_command_idtotimers (_In_ HWND hwnd, _In_ INT ctrl_id) INT listview_id; INT item_id; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); if (!listview_id || !_r_listview_getselectedcount (hwnd, listview_id)) return; @@ -1698,7 +1698,7 @@ VOID _app_command_idtotimers (_In_ HWND hwnd, _In_ INT ctrl_id) while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != -1) { - app_hash = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + app_hash = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_app = _app_getappitem (app_hash); if (ptr_app) @@ -1715,7 +1715,7 @@ VOID _app_command_idtotimers (_In_ HWND hwnd, _In_ INT ctrl_id) } } - _app_updatelistviewbylparam (hwnd, listview_id, PR_UPDATE_FORCE); + _app_listview_updateby_id (hwnd, listview_id, PR_UPDATE_FORCE); _app_profile_save (); } @@ -1873,7 +1873,7 @@ VOID _app_command_copy (_In_ HWND hwnd, _In_ INT ctrl_id, _In_ INT column_id) INT column_count; INT item_id; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); item_id = -1; column_count = _r_listview_getcolumncount (hwnd, listview_id); @@ -1935,7 +1935,7 @@ VOID _app_command_checkbox (_In_ HWND hwnd, _In_ INT ctrl_id) rules = _r_obj_createlist_ex (8, &_r_obj_dereference); - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); item_id = -1; new_val = (ctrl_id == IDM_CHECK); @@ -1948,7 +1948,7 @@ VOID _app_command_checkbox (_In_ HWND hwnd, _In_ INT ctrl_id) while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != -1) { - app_hash = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + app_hash = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_app = _app_getappitem (app_hash); if (!ptr_app) @@ -1967,9 +1967,9 @@ VOID _app_command_checkbox (_In_ HWND hwnd, _In_ INT ctrl_id) ptr_app->is_enabled = new_val; - _app_setcheckboxlock (hwnd, listview_id, TRUE); + _app_listview_lock (hwnd, listview_id, TRUE); _app_setappiteminfo (hwnd, listview_id, item_id, ptr_app); - _app_setcheckboxlock (hwnd, listview_id, FALSE); + _app_listview_lock (hwnd, listview_id, FALSE); _r_obj_addlistitem (rules, ptr_app); @@ -2001,7 +2001,7 @@ VOID _app_command_checkbox (_In_ HWND hwnd, _In_ INT ctrl_id) while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != -1) { - rule_idx = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + rule_idx = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_rule = _app_getrulebyid (rule_idx); if (!ptr_rule) @@ -2011,9 +2011,9 @@ VOID _app_command_checkbox (_In_ HWND hwnd, _In_ INT ctrl_id) { _app_ruleenable (ptr_rule, new_val, TRUE); - _app_setcheckboxlock (hwnd, listview_id, TRUE); + _app_listview_lock (hwnd, listview_id, TRUE); _app_setruleiteminfo (hwnd, listview_id, item_id, ptr_rule, TRUE); - _app_setcheckboxlock (hwnd, listview_id, FALSE); + _app_listview_lock (hwnd, listview_id, FALSE); _r_obj_addlistitem (rules, ptr_rule); @@ -2043,7 +2043,7 @@ VOID _app_command_checkbox (_In_ HWND hwnd, _In_ INT ctrl_id) if (is_changed) { - _app_updatelistviewbylparam (hwnd, listview_id, PR_UPDATE_FORCE); + _app_listview_updateby_id (hwnd, listview_id, PR_UPDATE_FORCE); _app_profile_save (); } @@ -2057,7 +2057,7 @@ VOID _app_command_delete (_In_ HWND hwnd) INT selected_count; INT item_count; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); if (listview_id != IDC_APPS_PROFILE && listview_id != IDC_RULES_CUSTOM && listview_id != IDC_NETWORK) return; @@ -2133,7 +2133,7 @@ VOID _app_command_delete (_In_ HWND hwnd) ULONG_PTR app_hash; PITEM_APP ptr_app; - app_hash = _app_getlistviewitemcontext (hwnd, listview_id, i); + app_hash = _app_listview_getitemcontext (hwnd, listview_id, i); ptr_app = _app_getappitem (app_hash); if (!ptr_app) @@ -2166,7 +2166,7 @@ VOID _app_command_delete (_In_ HWND hwnd) ULONG_PTR hash_code; SIZE_T enum_key; - rule_idx = _app_getlistviewitemcontext (hwnd, listview_id, i); + rule_idx = _app_listview_getitemcontext (hwnd, listview_id, i); ptr_rule = _app_getrulebyid (rule_idx); if (!ptr_rule) @@ -2202,7 +2202,7 @@ VOID _app_command_delete (_In_ HWND hwnd) while (_r_obj_enumhashtable (apps_checker, NULL, &hash_code, &enum_key)) { - _app_updateitembylparam (hwnd, hash_code, TRUE); + _app_listview_updateitemby_param (hwnd, hash_code, TRUE); } } @@ -2213,7 +2213,7 @@ VOID _app_command_delete (_In_ HWND hwnd) ULONG_PTR network_hash; PITEM_NETWORK ptr_network; - network_hash = _app_getlistviewitemcontext (hwnd, listview_id, i); + network_hash = _app_listview_getitemcontext (hwnd, listview_id, i); ptr_network = _app_network_getitem (network_hash); if (!ptr_network) @@ -2257,7 +2257,7 @@ VOID _app_command_delete (_In_ HWND hwnd) _r_obj_dereference (guids); } - _app_updatelistviewbylparam (hwnd, listview_id, 0); + _app_listview_updateby_id (hwnd, listview_id, 0); _app_profile_save (); } @@ -2270,7 +2270,7 @@ VOID _app_command_disable (_In_ HWND hwnd, _In_ INT ctrl_id) INT item_id; BOOL new_val; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); // note: these commands only for apps... if (!(listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP)) @@ -2281,7 +2281,7 @@ VOID _app_command_disable (_In_ HWND hwnd, _In_ INT ctrl_id) while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != -1) { - app_hash = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + app_hash = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_app = _app_getappitem (app_hash); if (!ptr_app) @@ -2299,12 +2299,12 @@ VOID _app_command_disable (_In_ HWND hwnd, _In_ INT ctrl_id) _app_timer_reset (hwnd, ptr_app); } - _app_updateitembyidx (hwnd, listview_id, item_id); + _app_listview_updateitemby_id (hwnd, listview_id, item_id); _r_obj_dereference (ptr_app); } - _app_updatelistviewbylparam (hwnd, listview_id, 0); + _app_listview_updateby_id (hwnd, listview_id, 0); _app_profile_save (); } @@ -2320,7 +2320,7 @@ VOID _app_command_openeditor (_In_ HWND hwnd) _app_ruleenable (ptr_rule, TRUE, FALSE); - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) { @@ -2328,7 +2328,7 @@ VOID _app_command_openeditor (_In_ HWND hwnd) while ((item_id = _r_listview_getnextselected (hwnd, listview_id, item_id)) != -1) { - app_hash = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + app_hash = _app_listview_getitemcontext (hwnd, listview_id, item_id); if (_app_isappfound (app_hash)) { @@ -2347,7 +2347,7 @@ VOID _app_command_openeditor (_In_ HWND hwnd) ULONG_PTR network_hash; PITEM_NETWORK ptr_network; - network_hash = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + network_hash = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_network = _app_network_getitem (network_hash); if (ptr_network) @@ -2365,7 +2365,7 @@ VOID _app_command_openeditor (_In_ HWND hwnd) if (ptr_network->app_hash) { - _app_setlistviewbylparam (hwnd, ptr_network->app_hash, PR_SETITEM_UPDATE, TRUE); + _app_listview_updateby_param (hwnd, ptr_network->app_hash, PR_SETITEM_UPDATE, TRUE); _app_profile_save (); } @@ -2392,7 +2392,7 @@ VOID _app_command_openeditor (_In_ HWND hwnd) SIZE_T log_idx; PITEM_LOG ptr_log; - log_idx = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + log_idx = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_log = _app_getlogitem (log_idx); if (ptr_log) @@ -2410,7 +2410,7 @@ VOID _app_command_openeditor (_In_ HWND hwnd) if (ptr_log->app_hash) { - _app_setlistviewbylparam (hwnd, ptr_log->app_hash, PR_SETITEM_UPDATE, TRUE); + _app_listview_updateby_param (hwnd, ptr_log->app_hash, PR_SETITEM_UPDATE, TRUE); _app_profile_save (); } @@ -2446,8 +2446,8 @@ VOID _app_command_openeditor (_In_ HWND hwnd) if (rule_idx != SIZE_MAX) { - _app_addlistviewrule (hwnd, ptr_rule, rule_idx, TRUE); - _app_updatelistviewbylparam (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE); + _app_listview_addruleitem (hwnd, ptr_rule, rule_idx, TRUE); + _app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE); _app_profile_save (); } @@ -2463,7 +2463,7 @@ VOID _app_command_properties (_In_ HWND hwnd) INT listview_id; INT item_id; - listview_id = _app_getcurrentlistview_id (hwnd); + listview_id = _app_listview_getcurrent (hwnd); item_id = _r_listview_getnextselected (hwnd, listview_id, -1); if (item_id == -1) @@ -2475,7 +2475,7 @@ VOID _app_command_properties (_In_ HWND hwnd) ULONG_PTR app_hash; PITEM_APP ptr_app; - app_hash = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + app_hash = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_app = _app_getappitem (app_hash); if (!ptr_app) @@ -2485,11 +2485,11 @@ VOID _app_command_properties (_In_ HWND hwnd) if (context) { - _app_setcheckboxlock (hwnd, listview_id, TRUE); + _app_listview_lock (hwnd, listview_id, TRUE); _app_setappiteminfo (hwnd, listview_id, item_id, ptr_app); - _app_setcheckboxlock (hwnd, listview_id, FALSE); + _app_listview_lock (hwnd, listview_id, FALSE); - _app_updatelistviewbylparam (hwnd, listview_id, 0); + _app_listview_updateby_id (hwnd, listview_id, 0); _app_profile_save (); @@ -2504,7 +2504,7 @@ VOID _app_command_properties (_In_ HWND hwnd) SIZE_T rule_idx; PITEM_RULE ptr_rule; - rule_idx = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + rule_idx = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_rule = _app_getrulebyid (rule_idx); if (!ptr_rule) @@ -2514,11 +2514,11 @@ VOID _app_command_properties (_In_ HWND hwnd) if (context) { - _app_setcheckboxlock (hwnd, listview_id, TRUE); + _app_listview_lock (hwnd, listview_id, TRUE); _app_setruleiteminfo (hwnd, listview_id, item_id, ptr_rule, TRUE); - _app_setcheckboxlock (hwnd, listview_id, FALSE); + _app_listview_lock (hwnd, listview_id, FALSE); - _app_updatelistviewbylparam (hwnd, listview_id, 0); + _app_listview_updateby_id (hwnd, listview_id, 0); _app_profile_save (); @@ -2532,7 +2532,7 @@ VOID _app_command_properties (_In_ HWND hwnd) PITEM_NETWORK ptr_network; ULONG_PTR network_hash; - network_hash = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + network_hash = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_network = _app_network_getitem (network_hash); if (!ptr_network) @@ -2546,7 +2546,7 @@ VOID _app_command_properties (_In_ HWND hwnd) if (ptr_network->app_hash) { - _app_setlistviewbylparam (hwnd, ptr_network->app_hash, PR_SETITEM_UPDATE, TRUE); + _app_listview_updateby_param (hwnd, ptr_network->app_hash, PR_SETITEM_UPDATE, TRUE); _app_profile_save (); } @@ -2554,7 +2554,7 @@ VOID _app_command_properties (_In_ HWND hwnd) if (ptr_network->app_hash) { - _app_showitembylparam (hwnd, ptr_network->app_hash, TRUE); + _app_listview_showitemby_param (hwnd, ptr_network->app_hash, TRUE); } } @@ -2565,7 +2565,7 @@ VOID _app_command_properties (_In_ HWND hwnd) SIZE_T log_idx; PITEM_LOG ptr_log; - log_idx = _app_getlistviewitemcontext (hwnd, listview_id, item_id); + log_idx = _app_listview_getitemcontext (hwnd, listview_id, item_id); ptr_log = _app_getlogitem (log_idx); if (!ptr_log) @@ -2579,7 +2579,7 @@ VOID _app_command_properties (_In_ HWND hwnd) if (ptr_log->app_hash) { - _app_setlistviewbylparam (hwnd, ptr_log->app_hash, PR_SETITEM_UPDATE, TRUE); + _app_listview_updateby_param (hwnd, ptr_log->app_hash, PR_SETITEM_UPDATE, TRUE); _app_profile_save (); } @@ -2587,7 +2587,7 @@ VOID _app_command_properties (_In_ HWND hwnd) if (ptr_log->app_hash) { - _app_showitembylparam (hwnd, ptr_log->app_hash, TRUE); + _app_listview_showitemby_param (hwnd, ptr_log->app_hash, TRUE); } } @@ -2620,11 +2620,11 @@ VOID _app_command_purgeunused (_In_ HWND hwnd) if (!_app_isappunused (ptr_app)) continue; - listview_id = _app_getlistviewbytype_id (ptr_app->type); + listview_id = _app_listview_getbytype (ptr_app->type); if (listview_id) { - item_id = _app_getposition (hwnd, listview_id, hash_code); + item_id = _app_listview_finditem (hwnd, listview_id, hash_code); if (item_id != -1) _r_listview_deleteitem (hwnd, listview_id, item_id); @@ -2664,7 +2664,7 @@ VOID _app_command_purgeunused (_In_ HWND hwnd) _wfp_destroyfilters_array (hengine, guids, __LINE__); } - _app_updatelistviewbylparam (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); + _app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); _app_profile_save (); } @@ -2715,7 +2715,7 @@ VOID _app_command_purgetimers (_In_ HWND hwnd) _r_obj_dereference (rules); } - _app_updatelistviewbylparam (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); + _app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); _app_profile_save (); } @@ -2741,8 +2741,8 @@ VOID _app_command_selectfont (_In_ HWND hwnd) { _r_config_setfont (L"Font", &lf, dpi_value); - _app_listviewloadfont (dpi_value, TRUE); - _app_updatelistviewbylparam (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); + _app_listview_loadfont (dpi_value, TRUE); + _app_listview_updateby_id (hwnd, DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE | PR_UPDATE_FORCE); RedrawWindow (hwnd, NULL, NULL, RDW_NOFRAME | RDW_NOINTERNALPAINT | RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN); } diff --git a/src/network.c b/src/network.c index 392837bc..d1a10f75 100644 --- a/src/network.c +++ b/src/network.c @@ -579,13 +579,11 @@ BOOLEAN _app_network_isvalidconnection (_In_ ADDRESS_FAMILY af, _In_ LPCVOID add VOID _app_network_printlistviewtable (_Inout_ PITEM_NETWORK_CONTEXT network_context) { PITEM_NETWORK ptr_network; - PITEM_CONTEXT context; PR_STRING string; ULONG_PTR app_hash; ULONG_PTR network_hash; SIZE_T enum_key; INT item_count; - INT item_id; BOOLEAN is_highlight; BOOLEAN is_refresh; @@ -606,22 +604,13 @@ VOID _app_network_printlistviewtable (_Inout_ PITEM_NETWORK_CONTEXT network_cont _r_obj_dereference (string); - item_id = _r_listview_getitemcount (network_context->hwnd, IDC_NETWORK); - - _r_listview_additem_ex (network_context->hwnd, IDC_NETWORK, item_id, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, _app_createlistviewcontext (network_hash)); + _app_listview_addnetworkitem (network_context->hwnd, ptr_network, network_hash); if (ptr_network->path && ptr_network->app_hash) - _app_queryfileinformation (ptr_network->path, ptr_network->app_hash, ptr_network->type, IDC_NETWORK); + _app_queue_fileinformation (ptr_network->path, ptr_network->app_hash, ptr_network->type, IDC_NETWORK); // resolve network address - context = _r_freelist_allocateitem (&context_free_list); - - context->hwnd = network_context->hwnd; - context->listview_id = IDC_NETWORK; - context->lparam = network_hash; - context->ptr_network = _r_obj_reference (ptr_network); - - _r_workqueue_queueitem (&resolver_queue, &_app_queueresolveinformation, context); + _app_queue_resolver (network_context->hwnd, IDC_NETWORK, network_hash, ptr_network); is_refresh = TRUE; } @@ -630,7 +619,7 @@ VOID _app_network_printlistviewtable (_Inout_ PITEM_NETWORK_CONTEXT network_cont // refresh network tab if (is_refresh) - _app_updatelistviewbylparam (network_context->hwnd, IDC_NETWORK, PR_UPDATE_NORESIZE); + _app_listview_updateby_id (network_context->hwnd, IDC_NETWORK, PR_UPDATE_NORESIZE); // remove closed connections from list item_count = _r_listview_getitemcount (network_context->hwnd, IDC_NETWORK); @@ -639,7 +628,7 @@ VOID _app_network_printlistviewtable (_Inout_ PITEM_NETWORK_CONTEXT network_cont { for (INT i = item_count - 1; i != -1; i--) { - network_hash = _app_getlistviewitemcontext (network_context->hwnd, IDC_NETWORK, i); + network_hash = _app_listview_getitemcontext (network_context->hwnd, IDC_NETWORK, i); if (_r_obj_findhashtable (network_context->checker_ptr, network_hash)) continue; @@ -654,7 +643,7 @@ VOID _app_network_printlistviewtable (_Inout_ PITEM_NETWORK_CONTEXT network_cont if (is_highlight) { if (app_hash) - _app_setlistviewbylparam (network_context->hwnd, app_hash, PR_SETITEM_REDRAW, TRUE); + _app_listview_updateby_param (network_context->hwnd, app_hash, PR_SETITEM_REDRAW, TRUE); } } } diff --git a/src/notifications.c b/src/notifications.c index 0fe1679b..cdf1d584 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -93,7 +93,7 @@ BOOLEAN _app_notify_command (_In_ HWND hwnd, _In_ INT button_id, _In_ LONG64 sec } else { - _app_updateitembylparam (_r_app_gethwnd (), app_hash, TRUE); + _app_listview_updateitemby_param (_r_app_gethwnd (), app_hash, TRUE); } _r_obj_addlistitem (rules, ptr_app); @@ -120,7 +120,7 @@ BOOLEAN _app_notify_command (_In_ HWND hwnd, _In_ INT button_id, _In_ LONG64 sec } } - _app_updatelistviewbylparam (_r_app_gethwnd (), ptr_app->type, PR_UPDATE_TYPE); + _app_listview_updateby_id (_r_app_gethwnd (), ptr_app->type, PR_UPDATE_TYPE); _r_obj_dereference (ptr_app); _r_obj_dereference (rules); @@ -1140,8 +1140,8 @@ INT_PTR CALLBACK NotificationProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wp _app_ruleenable (ptr_rule, TRUE, TRUE); } - _app_updateitembylparam (_r_app_gethwnd (), ptr_log->app_hash, TRUE); - _app_updateitembylparam (_r_app_gethwnd (), rule_idx, FALSE); + _app_listview_updateitemby_param (_r_app_gethwnd (), ptr_log->app_hash, TRUE); + _app_listview_updateitemby_param (_r_app_gethwnd (), rule_idx, FALSE); if (_wfp_isfiltersinstalled ()) { @@ -1159,7 +1159,7 @@ INT_PTR CALLBACK NotificationProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wp } } - _app_updatelistviewbylparam (_r_app_gethwnd (), DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE); + _app_listview_updateby_id (_r_app_gethwnd (), DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE); _r_obj_dereference (ptr_app); _r_obj_dereference (ptr_rule); @@ -1205,7 +1205,7 @@ INT_PTR CALLBACK NotificationProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wp if (app_hash) { - _app_showitembylparam (_r_app_gethwnd (), app_hash, TRUE); + _app_listview_showitemby_param (_r_app_gethwnd (), app_hash, TRUE); } break; @@ -1306,12 +1306,12 @@ INT_PTR CALLBACK NotificationProc (_In_ HWND hwnd, _In_ UINT msg, _In_ WPARAM wp _r_queuedlock_releaseexclusive (&lock_rules); // set rule information - _app_addlistviewrule (_r_app_gethwnd (), ptr_rule, rule_idx, TRUE); + _app_listview_addruleitem (_r_app_gethwnd (), ptr_rule, rule_idx, TRUE); // update app information - _app_updateitembylparam (_r_app_gethwnd (), app_hash, TRUE); + _app_listview_updateitemby_param (_r_app_gethwnd (), app_hash, TRUE); - _app_updatelistviewbylparam (_r_app_gethwnd (), DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE); + _app_listview_updateby_id (_r_app_gethwnd (), DATA_LISTVIEW_CURRENT, PR_UPDATE_TYPE); _app_profile_save (); diff --git a/src/profile.c b/src/profile.c index b99b1965..f0838f69 100644 --- a/src/profile.c +++ b/src/profile.c @@ -29,7 +29,7 @@ PVOID _app_getappinfo (_In_ PITEM_APP ptr_app, _In_ ENUM_INFO_DATA info_data) } else if (info_data == INFO_LISTVIEW_ID) { - return IntToPtr (_app_getlistviewbytype_id (ptr_app->type)); + return IntToPtr (_app_listview_getbytype (ptr_app->type)); } else if (info_data == INFO_IS_ENABLED) { @@ -93,7 +93,7 @@ VOID _app_setappinfo (_In_ PITEM_APP ptr_app, _In_ ENUM_INFO_DATA info_data, _In ptr_app->is_enabled = TRUE; } - _app_updateitembylparam (_r_app_gethwnd (), ptr_app->app_hash, TRUE); + _app_listview_updateitemby_param (_r_app_gethwnd (), ptr_app->app_hash, TRUE); } else if (info_data == INFO_IS_SILENT) { @@ -106,7 +106,7 @@ VOID _app_setappinfo (_In_ PITEM_APP ptr_app, _In_ ENUM_INFO_DATA info_data, _In { ptr_app->is_enabled = (PtrToInt (value) ? TRUE : FALSE); - _app_updateitembylparam (_r_app_gethwnd (), ptr_app->app_hash, TRUE); + _app_listview_updateitemby_param (_r_app_gethwnd (), ptr_app->app_hash, TRUE); } else if (info_data == INFO_IS_UNDELETABLE) { @@ -133,7 +133,7 @@ PVOID _app_getruleinfo (_In_ PITEM_RULE ptr_rule, _In_ ENUM_INFO_DATA info_data) { if (info_data == INFO_LISTVIEW_ID) { - return IntToPtr (_app_getlistviewbytype_id (ptr_rule->type)); + return IntToPtr (_app_listview_getbytype (ptr_rule->type)); } else if (info_data == INFO_IS_READONLY) { @@ -255,11 +255,11 @@ ULONG_PTR _app_addapplication (_In_opt_ HWND hwnd, _In_ ENUM_TYPE_DATA type, _In // insert item if (hwnd) - _app_addlistviewapp (hwnd, ptr_app); + _app_listview_addappitem (hwnd, ptr_app); // queue file information if (ptr_app->real_path) - _app_queryfileinformation (ptr_app->real_path, app_hash, ptr_app->type, _app_getlistviewbytype_id (ptr_app->type)); + _app_queue_fileinformation (ptr_app->real_path, app_hash, ptr_app->type, _app_listview_getbytype (ptr_app->type)); return app_hash; } @@ -535,7 +535,7 @@ VOID _app_freeapplication (_In_ ULONG_PTR app_hash) ptr_rule->is_haveerrors = FALSE; } - _app_updateitembylparam (_r_app_gethwnd (), i, FALSE); + _app_listview_updateitemby_param (_r_app_gethwnd (), i, FALSE); } } } @@ -549,7 +549,7 @@ VOID _app_getcount (_Out_ PITEM_STATUS status) { PITEM_APP ptr_app; PITEM_RULE ptr_rule; - SIZE_T enum_key = 0; + SIZE_T enum_key; BOOLEAN is_used; status->apps_count = 0; @@ -560,6 +560,8 @@ VOID _app_getcount (_Out_ PITEM_STATUS status) status->rules_predefined_count = 0; status->rules_user_count = 0; + enum_key = 0; + _r_queuedlock_acquireshared (&lock_apps); while (_r_obj_enumhashtablepointer (apps_table, &ptr_app, NULL, &enum_key)) @@ -642,17 +644,19 @@ VOID _app_setappiteminfo (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id VOID _app_setruleiteminfo (_In_ HWND hwnd, _In_ INT listview_id, _In_ INT item_id, _In_ PITEM_RULE ptr_rule, _In_ BOOLEAN include_apps) { + ULONG_PTR hash_code; + SIZE_T enum_key; + _r_listview_setitem_ex (hwnd, listview_id, item_id, 0, LPSTR_TEXTCALLBACK, I_IMAGECALLBACK, I_GROUPIDCALLBACK, 0); _r_listview_setitemcheck (hwnd, listview_id, item_id, !!ptr_rule->is_enabled); if (include_apps) { - ULONG_PTR hash_code; - SIZE_T enum_key = 0; + enum_key = 0; while (_r_obj_enumhashtable (ptr_rule->apps, NULL, &hash_code, &enum_key)) { - _app_updateitembylparam (hwnd, hash_code, TRUE); + _app_listview_updateitemby_param (hwnd, hash_code, TRUE); } } } @@ -762,7 +766,7 @@ VOID _app_ruleblocklistset (_In_opt_ HWND hwnd, _In_ INT spy_state, _In_ INT upd changes_count += 1; if (hwnd) - _app_updateitembylparam (hwnd, i, FALSE); + _app_listview_updateitemby_param (hwnd, i, FALSE); if (is_instantapply) _r_obj_addlistitem (rules, _r_obj_reference (ptr_rule)); // dereference later! @@ -773,7 +777,7 @@ VOID _app_ruleblocklistset (_In_opt_ HWND hwnd, _In_ INT spy_state, _In_ INT upd if (changes_count) { if (hwnd) - _app_updatelistviewbylparam (hwnd, DATA_RULE_BLOCKLIST, PR_UPDATE_TYPE | PR_UPDATE_NORESIZE); + _app_listview_updateby_id (hwnd, DATA_RULE_BLOCKLIST, PR_UPDATE_TYPE | PR_UPDATE_NORESIZE); if (is_instantapply) { @@ -963,9 +967,11 @@ BOOLEAN _app_isappfromsystem (_In_opt_ PR_STRING path, _In_ ULONG_PTR app_hash) BOOLEAN _app_isapphavedrive (_In_ INT letter) { PITEM_APP ptr_app; - SIZE_T enum_key = 0; + SIZE_T enum_key; INT drive_id; + enum_key = 0; + _r_queuedlock_acquireshared (&lock_apps); while (_r_obj_enumhashtablepointer (apps_table, &ptr_app, NULL, &enum_key)) @@ -1588,46 +1594,21 @@ VOID _app_profile_load_internal (_In_ PR_STRING path, _In_ LPCWSTR resource_name _r_xml_destroylibrary (&xml_resource); } -VOID _app_profile_load (_In_opt_ HWND hwnd, _In_opt_ LPCWSTR path_custom) +VOID _app_profile_refresh () { - R_XML_LIBRARY xml_library; - HRESULT hr; - - INT current_listview_id; - INT new_listview_id; - INT selected_item; - INT scroll_pos; - - // clean listview - if (hwnd) - { - current_listview_id = _app_getcurrentlistview_id (hwnd); - selected_item = _r_listview_getnextselected (hwnd, current_listview_id, -1); - scroll_pos = GetScrollPos (GetDlgItem (hwnd, current_listview_id), SB_VERT); - - for (INT i = IDC_APPS_PROFILE; i <= IDC_RULES_CUSTOM; i++) - _r_listview_deleteallitems (hwnd, i); - } - // clear apps _r_queuedlock_acquireexclusive (&lock_apps); - _r_obj_clearhashtable (apps_table); - _r_queuedlock_releaseexclusive (&lock_apps); // clear rules _r_queuedlock_acquireexclusive (&lock_rules); - _r_obj_clearlist (rules_list); - _r_queuedlock_releaseexclusive (&lock_rules); // clear rules config _r_queuedlock_acquireexclusive (&lock_rules_config); - _r_obj_clearhashtable (rules_config); - _r_queuedlock_releaseexclusive (&lock_rules_config); // generate uwp apps list (win8+) @@ -1636,6 +1617,35 @@ VOID _app_profile_load (_In_opt_ HWND hwnd, _In_opt_ LPCWSTR path_custom) // generate services list _app_package_getserviceslist (); +} + +VOID _app_profile_load (_In_opt_ HWND hwnd, _In_opt_ LPCWSTR path_custom) +{ + R_XML_LIBRARY xml_library; + HRESULT hr; + + LONG version; + + INT listview_id; + INT selected_item; + INT scroll_pos; + + // clean listview + if (hwnd) + { + // unused + listview_id = _app_listview_getcurrent (hwnd); + + if (listview_id) + { + selected_item = _r_listview_getnextselected (hwnd, listview_id, -1); + scroll_pos = GetScrollPos (GetDlgItem (hwnd, listview_id), SB_VERT); + } + + _app_listview_clearitems (hwnd); + } + + _app_profile_refresh (); // load profile _r_xml_initializelibrary (&xml_library, TRUE, NULL); @@ -1661,8 +1671,6 @@ VOID _app_profile_load (_In_opt_ HWND hwnd, _In_opt_ LPCWSTR path_custom) { if (_app_isprofilenodevalid (&xml_library, XML_VERSION_3, XML_TYPE_PROFILE)) { - LONG version; - version = _r_xml_getattribute_long (&xml_library, L"version"); // load apps @@ -1705,46 +1713,15 @@ VOID _app_profile_load (_In_opt_ HWND hwnd, _In_opt_ LPCWSTR path_custom) if (hwnd) { - PITEM_APP ptr_app; - PITEM_RULE ptr_rule; - SIZE_T enum_key = 0; - LONG64 current_time; + _app_listview_additems (hwnd); - current_time = _r_unixtime_now (); - - // add apps - _r_queuedlock_acquireshared (&lock_apps); - - while (_r_obj_enumhashtablepointer (apps_table, &ptr_app, NULL, &enum_key)) + if (listview_id) { - _app_addlistviewapp (hwnd, ptr_app); + _app_listview_updateby_id (hwnd, listview_id, 0); - // install timer - if (ptr_app->timer) - _app_timer_set (hwnd, ptr_app, ptr_app->timer - current_time); + if (_r_wnd_isvisible (hwnd) && (listview_id == _app_listview_getcurrent (hwnd))) + _app_listview_showitemby_id (hwnd, listview_id, selected_item, scroll_pos); } - - _r_queuedlock_releaseshared (&lock_apps); - - // add rules - _r_queuedlock_acquireshared (&lock_rules); - - for (SIZE_T i = 0; i < _r_obj_getlistsize (rules_list); i++) - { - ptr_rule = _r_obj_getlistitem (rules_list, i); - - if (ptr_rule) - _app_addlistviewrule (hwnd, ptr_rule, i, FALSE); - } - - _r_queuedlock_releaseshared (&lock_rules); - - new_listview_id = _app_getcurrentlistview_id (hwnd); - - _app_updatelistviewbylparam (hwnd, new_listview_id, 0); - - if (_r_wnd_isvisible (hwnd) && (current_listview_id == new_listview_id)) - _app_showitem (hwnd, current_listview_id, selected_item, scroll_pos); } } diff --git a/src/search.c b/src/search.c index 1ce2804f..ffcdcd3b 100644 --- a/src/search.c +++ b/src/search.c @@ -230,7 +230,7 @@ BOOLEAN _app_search_applyfiltercallback (_In_ HWND hwnd, _In_ INT listview_id, _ } if (is_changed) - _app_updatelistviewbylparam (hwnd, listview_id, PR_UPDATE_NOSETVIEW | PR_UPDATE_FORCE); + _app_listview_updateby_id (hwnd, listview_id, PR_UPDATE_NOSETVIEW | PR_UPDATE_FORCE); return is_changed; } diff --git a/src/timer.c b/src/timer.c index 61559518..1444ef7b 100644 --- a/src/timer.c +++ b/src/timer.c @@ -5,6 +5,11 @@ VOID _app_timer_set (_In_opt_ HWND hwnd, _Inout_ PITEM_APP ptr_app, _In_ LONG64 seconds) { + PTP_TIMER htimer; + FILETIME file_time; + LONG64 current_time; + BOOLEAN is_created; + if (seconds <= 0) { ptr_app->is_enabled = FALSE; @@ -13,15 +18,12 @@ VOID _app_timer_set (_In_opt_ HWND hwnd, _Inout_ PITEM_APP ptr_app, _In_ LONG64 ptr_app->timer = 0; if (_app_istimerset (ptr_app->htimer)) - { _app_timer_remove (&ptr_app->htimer); - } } else { - FILETIME file_time; - LONG64 current_time = _r_unixtime_now (); - BOOLEAN is_created = FALSE; + current_time = _r_unixtime_now (); + is_created = FALSE; _r_unixtime_to_filetime (current_time + seconds, &file_time); @@ -32,12 +34,13 @@ VOID _app_timer_set (_In_opt_ HWND hwnd, _Inout_ PITEM_APP ptr_app, _In_ LONG64 } else { - PTP_TIMER timer = CreateThreadpoolTimer (&_app_timer_callback, (PVOID)ptr_app->app_hash, NULL); + htimer = CreateThreadpoolTimer (&_app_timer_callback, (PVOID)ptr_app->app_hash, NULL); - if (timer) + if (htimer) { - SetThreadpoolTimer (timer, &file_time, 0, 0); - ptr_app->htimer = timer; + SetThreadpoolTimer (htimer, &file_time, 0, 0); + ptr_app->htimer = htimer; + is_created = TRUE; } } @@ -61,9 +64,7 @@ VOID _app_timer_set (_In_opt_ HWND hwnd, _Inout_ PITEM_APP ptr_app, _In_ LONG64 } if (hwnd) - { - _app_updateitembylparam (hwnd, ptr_app->app_hash, TRUE); - } + _app_listview_updateitemby_param (hwnd, ptr_app->app_hash, TRUE); } VOID _app_timer_reset (_In_opt_ HWND hwnd, _Inout_ PITEM_APP ptr_app) @@ -80,7 +81,7 @@ VOID _app_timer_reset (_In_opt_ HWND hwnd, _Inout_ PITEM_APP ptr_app) if (hwnd) { - _app_updateitembylparam (hwnd, ptr_app->app_hash, TRUE); + _app_listview_updateitemby_param (hwnd, ptr_app->app_hash, TRUE); } } @@ -147,7 +148,7 @@ VOID CALLBACK _app_timer_callback (_Inout_ PTP_CALLBACK_INSTANCE instance, _Inou _r_obj_dereference (rules); } - _app_updatelistviewbylparam (hwnd, ptr_app->type, PR_UPDATE_TYPE | PR_UPDATE_FORCE); + _app_listview_updateby_id (hwnd, ptr_app->type, PR_UPDATE_TYPE | PR_UPDATE_FORCE); _r_obj_dereference (ptr_app);