forked from henrypp/simplewall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listview.c
1218 lines (990 loc) · 23 KB
/
listview.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// simplewall
// Copyright (c) 2016-2022 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;
}
_Success_ (return != 0)
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
)
{
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
)
{
ULONG_PTR current_code;
INT item_count;
if ((listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_LOG) ||
listview_id == IDC_RULE_APPS_ID || listview_id == IDC_APP_RULES_ID)
{
item_count = _r_listview_getitemcount (hwnd, listview_id);
for (INT i = 0; i < item_count; i++)
{
current_code = _app_listview_getitemcontext (hwnd, listview_id, i);
if (current_code == id_code)
return i;
}
}
else
{
return _r_listview_finditem (hwnd, listview_id, -1, id_code);
}
return -1;
}
VOID _app_listview_removeitem (
_In_ HWND hwnd,
_In_ ULONG_PTR id_code,
_In_ ENUM_TYPE_DATA type
)
{
INT listview_id;
INT item_id;
if (!hwnd)
return;
listview_id = _app_listview_getbytype (type);
if (!listview_id)
return;
item_id = _app_listview_finditem (hwnd, listview_id, id_code);
if (item_id != -1)
_r_listview_deleteitem (hwnd, listview_id, 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);
}
// restore scroll position
if (scroll_pos > 0)
SendDlgItemMessage (hwnd, listview_id, LVM_SCROLL, 0, (LPARAM)scroll_pos);
}
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)
{
_app_getappinfobyhash (lparam, INFO_LISTVIEW_ID, (PVOID_PTR)&listview_id);
}
else
{
_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID, (PVOID_PTR)&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)
{
_app_getappinfobyhash (lparam, INFO_LISTVIEW_ID, (PVOID_PTR)&listview_id);
}
else
{
_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID, (PVOID_PTR)&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)
{
_app_getappinfobyhash (lparam, INFO_LISTVIEW_ID, (PVOID_PTR)&listview_id);
}
else
{
_app_getruleinfobyid (lparam, INFO_LISTVIEW_ID, (PVOID_PTR)&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
)
{
WCHAR buffer[128];
UINT group1_title;
UINT group2_title;
UINT group3_title;
UINT group4_title;
UINT group5_title;
INT total_count;
INT group1_count;
INT group2_count;
INT group3_count;
INT group4_count;
INT group5_count;
INT group_id;
BOOLEAN is_rules;
if (!_r_listview_isgroupviewenabled (hwnd, listview_id))
return;
is_rules = (listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM);
if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP)
{
group1_title = IDS_GROUP_ALLOWED;
group2_title = IDS_GROUP_TIMER;
group3_title = IDS_GROUP_SPECIAL_APPS;
group4_title = IDS_GROUP_BLOCKED;
group5_title = IDS_GROUP_BLOCKED;
}
else if (is_rules)
{
group1_title = IDS_GROUP_ENABLED;
group2_title = IDS_GROUP_ENABLED;
group3_title = IDS_GROUP_DISABLED;
group4_title = 0;
group5_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;
group5_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;
group5_title = 0;
}
else
{
return;
}
group1_count = 0;
group2_count = 0;
group3_count = 0;
group4_count = 0;
group5_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 == 4)
{
group5_count += 1;
}
else 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;
}
}
}
if (total_count)
{
// set group #1 title
_r_str_printf (
buffer,
RTL_NUMBER_OF (buffer),
is_rules ? L"%s (%d/%d) [for all]" : L"%s (%d/%d)",
_r_locale_getstring (group1_title),
group1_count,
total_count
);
_r_listview_setgroup (hwnd, listview_id, 0, buffer, 0, 0);
// set group #2 title
_r_str_printf (
buffer,
RTL_NUMBER_OF (buffer),
is_rules ? L"%s (%d/%d) [for apps]" : L"%s (%d/%d)",
_r_locale_getstring (group2_title),
group2_count,
total_count
);
_r_listview_setgroup (hwnd, listview_id, 1, buffer, 0, 0);
// set group #3 title
if (group3_title)
{
_r_str_printf (
buffer,
RTL_NUMBER_OF (buffer),
L"%s (%d/%d)",
_r_locale_getstring (group3_title),
group3_count,
total_count
);
_r_listview_setgroup (hwnd, listview_id, 2, buffer, 0, 0);
}
// set group #4 title
if (group4_title)
{
_r_str_printf (
buffer,
RTL_NUMBER_OF (buffer),
L"%s (%d/%d)",
_r_locale_getstring (group4_title),
group4_count,
total_count
);
_r_listview_setgroup (hwnd, listview_id, 3, buffer, 0, 0);
}
// set group #5 title
if (group5_title)
{
_r_str_printf (
buffer,
RTL_NUMBER_OF (buffer),
L"%s (%d/%d) [silent]",
_r_locale_getstring (group5_title),
group5_count,
total_count
);
_r_listview_setgroup (hwnd, listview_id, 4, buffer, 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_resize (
_In_ HWND hwnd,
_In_ INT listview_id
)
{
_app_listview_resize_ex (hwnd, listview_id, FALSE);
}
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_clamp (_r_config_getlong (L"ViewType", LV_VIEW_DETAILS), LV_VIEW_ICON, LV_VIEW_MAX) : LV_VIEW_DETAILS;
icons_size = is_mainview ? _r_calc_clamp (_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);
}