Skip to content

Commit

Permalink
upd code
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypp committed Jan 7, 2025
1 parent dffc8ef commit ff2fd4a
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 121 deletions.
8 changes: 4 additions & 4 deletions src/controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ VOID _app_settab_id (

hctrl = GetDlgItem (hwnd, page_id);

if (!hctrl || (_app_listview_getcurrent (hwnd) == page_id && _r_wnd_isvisible (hctrl, FALSE)))
if (!hctrl || (_app_listview_getcontext (hwnd, INT_ERROR)->listview_id == page_id && _r_wnd_isvisible (hctrl, FALSE)))
return;

for (INT i = 0; i < _r_tab_getitemcount (hwnd, IDC_TAB) - 1; i++)
{
context = _app_listview_getbytab (hwnd, i);
context = _app_listview_getcontext (hwnd, i);

if (context->listview_id == page_id)
{
Expand Down Expand Up @@ -1019,7 +1019,7 @@ VOID _app_window_resize (
_r_wnd_sendmessage (config.hrebar, 0, WM_SIZE, 0, 0);
_r_wnd_sendmessage (hwnd, IDC_STATUSBAR, WM_SIZE, 0, 0);

context = _app_listview_getbytab (hwnd, INT_ERROR);
context = _app_listview_getcontext (hwnd, INT_ERROR);

rebar_height = _r_rebar_getheight (hwnd, IDC_REBAR);
statusbar_height = _r_status_getheight (hwnd, IDC_STATUSBAR);
Expand Down Expand Up @@ -1055,7 +1055,7 @@ VOID _app_window_resize (

for (INT i = 0; i < _r_tab_getitemcount (hwnd, IDC_TAB) - 1; i++)
{
new_context = _app_listview_getbytab (hwnd, i);
new_context = _app_listview_getcontext (hwnd, i);

_r_tab_adjustchild (hwnd, IDC_TAB, GetDlgItem (hwnd, new_context->listview_id));

Expand Down
4 changes: 2 additions & 2 deletions src/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ VOID NTAPI _app_queue_fileinformation (
// redraw listview
if (_r_wnd_isvisible (hwnd, FALSE))
{
if (ptr_app_info->listview_id == _app_listview_getcurrent (hwnd))
if (ptr_app_info->listview_id == _app_listview_getcontext (hwnd, INT_ERROR)->listview_id)
_r_listview_redraw (hwnd, ptr_app_info->listview_id);
}

Expand Down Expand Up @@ -2043,7 +2043,7 @@ VOID NTAPI _app_queue_resolveinformation (
// redraw listview
if (_r_wnd_isvisible (context->hwnd, FALSE))
{
if (_app_listview_getcurrent (context->hwnd) == context->listview_id)
if (_app_listview_getcontext (context->hwnd, INT_ERROR)->listview_id == context->listview_id)
_r_listview_redraw (context->hwnd, context->listview_id);
}

Expand Down
24 changes: 8 additions & 16 deletions src/listview.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@

#include "global.h"

INT _app_listview_getcurrent (
_In_ HWND hwnd
)
{
PITEM_TAB_CONTEXT context;

context = _app_listview_getbytab (hwnd, INT_ERROR);

return context->listview_id;
}

PITEM_TAB_CONTEXT _app_listview_getbytab (
PITEM_TAB_CONTEXT _app_listview_getcontext (
_In_ HWND hwnd,
_In_ INT tab_id
)
Expand Down Expand Up @@ -438,7 +427,7 @@ VOID _app_listview_showitemby_param (
if (!listview_id)
return;

if (listview_id != _app_listview_getcurrent (hwnd))
if (listview_id != _app_listview_getcontext (hwnd, INT_ERROR)->listview_id)
{
_app_listview_sort (hwnd, listview_id, INT_ERROR, FALSE);

Expand All @@ -461,16 +450,19 @@ VOID _app_listview_updateby_id (
_In_ ULONG flags
)
{
PITEM_TAB_CONTEXT context;
ENUM_TYPE_DATA type;
INT listview_id;

context = _app_listview_getcontext (hwnd, INT_ERROR);

if (flags & PR_UPDATE_TYPE)
{
type = lparam;

if (type == DATA_LISTVIEW_CURRENT)
{
listview_id = _app_listview_getcurrent (hwnd);
listview_id = context->listview_id;
}
else
{
Expand All @@ -482,7 +474,7 @@ VOID _app_listview_updateby_id (
listview_id = lparam;
}

if ((flags & PR_UPDATE_FORCE) || (listview_id == _app_listview_getcurrent (hwnd)))
if ((flags & PR_UPDATE_FORCE) || (listview_id == context->listview_id))
{
if (!(flags & PR_UPDATE_NOREDRAW))
_r_listview_redraw (hwnd, listview_id);
Expand Down Expand Up @@ -533,7 +525,7 @@ VOID _app_listview_updateby_param (

if ((flags & PR_SETITEM_REDRAW))
{
if (listview_id == _app_listview_getcurrent (hwnd))
if (listview_id == _app_listview_getcontext (hwnd, INT_ERROR)->listview_id)
_r_listview_redraw (hwnd, listview_id);
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/listview.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ typedef struct _ITEM_LISTVIEW_CONTEXT
#define PR_UPDATE_NOREDRAW 0x0020
#define PR_UPDATE_NOSETVIEW 0x0040

INT _app_listview_getcurrent (
_In_ HWND hwnd
);

PITEM_TAB_CONTEXT _app_listview_getbytab (
PITEM_TAB_CONTEXT _app_listview_getcontext (
_In_ HWND hwnd,
_In_ INT tab_id
);
Expand Down
70 changes: 19 additions & 51 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// simplewall
// Copyright (c) 2016-2025 Henry++

#include "global.h"

BOOLEAN _app_changefilters (
Expand All @@ -9,7 +12,7 @@ BOOLEAN _app_changefilters (
PITEM_CONTEXT context;
INT listview_id;

listview_id = _app_listview_getcurrent (hwnd);
listview_id = _app_listview_getcontext (hwnd, INT_ERROR)->listview_id;

_app_listview_sort (hwnd, listview_id, INT_ERROR, FALSE);

Expand Down Expand Up @@ -1277,7 +1280,7 @@ INT_PTR CALLBACK SettingsProc (

_r_config_setboolean_ex (ptr_clr->config_name->buffer, is_enabled, L"colors");

_r_listview_redraw (_r_app_gethwnd (), _app_listview_getcurrent (_r_app_gethwnd ()));
_r_listview_redraw (_r_app_gethwnd (), _app_listview_getcontext (_r_app_gethwnd (), INT_ERROR)->listview_id);
}
}

Expand Down Expand Up @@ -1339,7 +1342,7 @@ INT_PTR CALLBACK SettingsProc (

_r_listview_redraw (hwnd, IDC_COLORS);

_r_listview_redraw (_r_app_gethwnd (), _app_listview_getcurrent (_r_app_gethwnd ()));
_r_listview_redraw (_r_app_gethwnd (), _app_listview_getcontext (_r_app_gethwnd (), INT_ERROR)->listview_id);
}

break;
Expand Down Expand Up @@ -1940,7 +1943,7 @@ VOID _app_tabs_init (

for (INT i = 0; i < _r_tab_getitemcount (hwnd, IDC_TAB) - 1; i++)
{
context = _app_listview_getbytab (hwnd, i);
context = _app_listview_getcontext (hwnd, i);

hlistview = GetDlgItem (hwnd, context->listview_id);

Expand Down Expand Up @@ -2405,8 +2408,6 @@ INT_PTR CALLBACK DlgProc (

_app_loginit (FALSE);

_r_config_setlong (L"CurrentTab", _app_listview_getcurrent (hwnd));

if (_r_queuedlock_islocked (&lock_apply))
{
_r_workqueue_waitforfinish (&wfp_queue);
Expand Down Expand Up @@ -2543,7 +2544,7 @@ INT_PTR CALLBACK DlgProc (
HWND hlistview;
INT listview_id;

listview_id = _app_listview_getcurrent (hwnd);
listview_id = _app_listview_getcontext (hwnd, INT_ERROR)->listview_id;

if (!listview_id)
break;
Expand All @@ -2563,7 +2564,7 @@ INT_PTR CALLBACK DlgProc (
HWND hlistview;
INT listview_id;

listview_id = _app_listview_getcurrent (hwnd);
listview_id = _app_listview_getcontext (hwnd, INT_ERROR)->listview_id;

if (!listview_id)
break;
Expand All @@ -2584,6 +2585,8 @@ INT_PTR CALLBACK DlgProc (

_app_listview_resize (hwnd, listview_id, FALSE);

_r_config_setlong (L"CurrentTab", listview_id);

break;
}

Expand All @@ -2600,8 +2603,8 @@ INT_PTR CALLBACK DlgProc (

case LVN_INSERTITEM:
{
LPNMLISTVIEW lpnmlv;
PITEM_LISTVIEW_CONTEXT context;
LPNMLISTVIEW lpnmlv;
INT listview_id;

lpnmlv = (LPNMLISTVIEW)lparam;
Expand All @@ -2625,8 +2628,8 @@ INT_PTR CALLBACK DlgProc (

case LVN_DELETEITEM:
{
LPNMLISTVIEW lpnmlv;
PITEM_LISTVIEW_CONTEXT context;
LPNMLISTVIEW lpnmlv;
INT listview_id;

lpnmlv = (LPNMLISTVIEW)lparam;
Expand Down Expand Up @@ -3036,7 +3039,7 @@ INT_PTR CALLBACK DlgProc (
if (ctrl_id != IDC_SEARCH)
break;

listview_id = _app_listview_getcurrent (hwnd);
listview_id = _app_listview_getcontext (hwnd, INT_ERROR)->listview_id;
string = _r_ctrl_getstring (config.hrebar, IDC_SEARCH);

_r_obj_movereference (&config.search_string, string);
Expand Down Expand Up @@ -3253,7 +3256,7 @@ INT_PTR CALLBACK DlgProc (
_r_config_setboolean (L"AutoSizeColumns", new_val);

if (new_val)
_app_listview_resize (hwnd, _app_listview_getcurrent (hwnd), FALSE);
_app_listview_resize (hwnd, _app_listview_getcontext (hwnd, INT_ERROR)->listview_id, FALSE);

break;
}
Expand All @@ -3268,7 +3271,7 @@ INT_PTR CALLBACK DlgProc (
_r_menu_checkitem (GetMenu (hwnd), ctrl_id, 0, MF_BYCOMMAND, new_val);
_r_config_setboolean (L"ShowFilenames", new_val);

listview_id = _app_listview_getcurrent (hwnd);
listview_id = _app_listview_getcontext (hwnd, INT_ERROR)->listview_id;

_r_listview_redraw (hwnd, listview_id);
_app_listview_sort (hwnd, listview_id, INT_ERROR, FALSE);
Expand Down Expand Up @@ -3681,7 +3684,7 @@ INT_PTR CALLBACK DlgProc (
INT item_id = INT_ERROR;
HRESULT status;

listview_id = _app_listview_getcurrent (hwnd);
listview_id = _app_listview_getcontext (hwnd, INT_ERROR)->listview_id;

if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP)
{
Expand Down Expand Up @@ -3800,7 +3803,7 @@ INT_PTR CALLBACK DlgProc (
{
INT listview_id;

listview_id = _app_listview_getcurrent (hwnd);
listview_id = _app_listview_getcontext (hwnd, INT_ERROR)->listview_id;

if (!listview_id)
break;
Expand Down Expand Up @@ -3883,7 +3886,6 @@ BOOLEAN NTAPI _app_parseargs (
L"simplewall.exe -install -temp - enable filtering until reboot.\r\n"
L"simplewall.exe -install -silent - enable filtering without prompt.\r\n"
L"simplewall.exe -uninstall - remove all installed filters.\r\n"
L"simplewall.exe -import <path> - import profile from specified path.\r\n"
L"simplewall.exe -help - show this message."
);

Expand All @@ -3897,19 +3899,8 @@ BOOLEAN NTAPI _app_parseargs (
if (_r_sys_getopt (_r_sys_getcommandline (), L"temp", NULL))
config.is_filterstemporary = TRUE;

PR_STRING import_path = _r_sys_getopt (_r_sys_getcommandline (), L"import", NULL);

_app_profile_initialize ();

if (import_path)
{
_app_profile_load (NULL, import_path);
_r_obj_dereference (import_path);
}
else
{
_app_profile_load (NULL, NULL);
}
_app_profile_load (NULL, NULL);

if (_wfp_initialize (NULL, hengine))
_wfp_installfilters (hengine);
Expand All @@ -3930,29 +3921,6 @@ BOOLEAN NTAPI _app_parseargs (

return TRUE;
}

case CmdlineImport:
{
PR_STRING path;
NTSTATUS status;

path = _r_sys_getopt (_r_sys_getcommandline (), L"import", NULL);

if (path)
{
status = _app_profile_load (NULL, path);

if (NT_SUCCESS (status))
{
_app_profile_save (NULL);
_app_changefilters (NULL, TRUE, FALSE);
}

_r_obj_dereference (path);
}

return TRUE;
}
}

return FALSE;
Expand Down
Loading

0 comments on commit ff2fd4a

Please sign in to comment.