1 /*
2 * PROJECT: ReactOS Task Manager
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Processes List Columns.
5 * COPYRIGHT: Copyright 1999-2001 Brian Palmer <brianp@reactos.org>
6 * Copyright 2005 Klemens Friedl <frik85@reactos.at>
7 */
8
9 #include "precomp.h"
10
11 UINT ColumnDataHints[COLUMN_NMAX];
12
13 #define DECLARE_COLUMN_PRESET(_name, _size, _state, _align) \
14 { IDS_TAB_##_name, IDC_##_name, _size, _state, _align },
15
16 const PresetColumnEntry ColumnPresets[COLUMN_NMAX] = {
17 DECLARE_COLUMN_PRESET(IMAGENAME, 105, TRUE, LVCFMT_LEFT)
18 DECLARE_COLUMN_PRESET(PID, 50, TRUE, LVCFMT_LEFT)
19 DECLARE_COLUMN_PRESET(USERNAME, 107, FALSE, LVCFMT_LEFT)
20 DECLARE_COLUMN_PRESET(SESSIONID, 70, FALSE, LVCFMT_LEFT)
21 DECLARE_COLUMN_PRESET(CPUUSAGE, 35, TRUE, LVCFMT_RIGHT)
22 DECLARE_COLUMN_PRESET(CPUTIME, 70, TRUE, LVCFMT_RIGHT)
23 DECLARE_COLUMN_PRESET(MEMORYUSAGE, 70, TRUE, LVCFMT_RIGHT)
24 DECLARE_COLUMN_PRESET(PEAKMEMORYUSAGE, 100, FALSE, LVCFMT_RIGHT)
25 DECLARE_COLUMN_PRESET(MEMORYUSAGEDELTA, 70, FALSE, LVCFMT_RIGHT)
26 DECLARE_COLUMN_PRESET(PAGEFAULTS, 70, FALSE, LVCFMT_RIGHT)
27 DECLARE_COLUMN_PRESET(PAGEFAULTSDELTA, 70, FALSE, LVCFMT_RIGHT)
28 DECLARE_COLUMN_PRESET(VIRTUALMEMORYSIZE, 70, FALSE, LVCFMT_RIGHT)
29 DECLARE_COLUMN_PRESET(PAGEDPOOL, 70, FALSE, LVCFMT_RIGHT)
30 DECLARE_COLUMN_PRESET(NONPAGEDPOOL, 70, FALSE, LVCFMT_RIGHT)
31 DECLARE_COLUMN_PRESET(BASEPRIORITY, 60, FALSE, LVCFMT_RIGHT)
32 DECLARE_COLUMN_PRESET(HANDLECOUNT, 60, FALSE, LVCFMT_RIGHT)
33 DECLARE_COLUMN_PRESET(THREADCOUNT, 60, FALSE, LVCFMT_RIGHT)
34 DECLARE_COLUMN_PRESET(USEROBJECTS, 60, FALSE, LVCFMT_RIGHT)
35 DECLARE_COLUMN_PRESET(GDIOBJECTS, 60, FALSE, LVCFMT_RIGHT)
36 DECLARE_COLUMN_PRESET(IOREADS, 70, FALSE, LVCFMT_RIGHT)
37 DECLARE_COLUMN_PRESET(IOWRITES, 70, FALSE, LVCFMT_RIGHT)
38 DECLARE_COLUMN_PRESET(IOOTHER, 70, FALSE, LVCFMT_RIGHT)
39 DECLARE_COLUMN_PRESET(IOREADBYTES, 70, FALSE, LVCFMT_RIGHT)
40 DECLARE_COLUMN_PRESET(IOWRITEBYTES, 70, FALSE, LVCFMT_RIGHT)
41 DECLARE_COLUMN_PRESET(IOOTHERBYTES, 70, FALSE, LVCFMT_RIGHT)
42 DECLARE_COLUMN_PRESET(COMMANDLINE, 450, FALSE, LVCFMT_LEFT)
43 };
44
45 static int InsertColumn(int nCol, LPCWSTR lpszColumnHeading, int nFormat, int nWidth, int nSubItem);
46 INT_PTR CALLBACK ColumnsDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
47
AddColumns(void)48 void AddColumns(void)
49 {
50 LRESULT size;
51 WCHAR szTemp[256];
52 unsigned int n;
53
54 for (n=0; n<COLUMN_NMAX; n++) {
55 if (TaskManagerSettings.Columns[n]) {
56 LoadStringW(hInst, ColumnPresets[n].dwIdsName, szTemp, _countof(szTemp));
57 InsertColumn(n, szTemp, ColumnPresets[n].dwAlign, TaskManagerSettings.ColumnSizeArray[n], -1);
58 }
59 }
60
61 size = SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0);
62 SendMessageW(hProcessPageHeaderCtrl, HDM_SETORDERARRAY, (WPARAM)size, (LPARAM)&TaskManagerSettings.ColumnOrderArray);
63
64 UpdateColumnDataHints();
65 }
66
InsertColumn(int nCol,LPCWSTR lpszColumnHeading,int nFormat,int nWidth,int nSubItem)67 static int InsertColumn(int nCol, LPCWSTR lpszColumnHeading, int nFormat, int nWidth, int nSubItem)
68 {
69 LVCOLUMN column;
70
71 column.mask = LVCF_TEXT|LVCF_FMT;
72 column.pszText = (LPWSTR)lpszColumnHeading;
73 column.fmt = nFormat;
74
75 if (nWidth != -1)
76 {
77 column.mask |= LVCF_WIDTH;
78 column.cx = nWidth;
79 }
80
81 if (nSubItem != -1)
82 {
83 column.mask |= LVCF_SUBITEM;
84 column.iSubItem = nSubItem;
85 }
86
87 return ListView_InsertColumn(hProcessPageListCtrl, nCol, &column);
88 }
89
SaveColumnSettings(void)90 void SaveColumnSettings(void)
91 {
92 HDITEM hditem;
93 int i, n;
94 WCHAR text[260];
95 WCHAR szTemp[256];
96 LRESULT size;
97
98 /* Reset column data */
99 for (i=0; i<COLUMN_NMAX; i++) {
100 TaskManagerSettings.ColumnOrderArray[i] = i;
101 TaskManagerSettings.Columns[i] = FALSE;
102 TaskManagerSettings.ColumnSizeArray[i] = ColumnPresets[i].size;
103 }
104
105 /* Get header order */
106 size = SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0);
107 SendMessageW(hProcessPageHeaderCtrl, HDM_GETORDERARRAY, (WPARAM)size, (LPARAM)&TaskManagerSettings.ColumnOrderArray);
108
109 /* Get visible columns */
110 for (i = 0; i < SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0); i++) {
111 memset(&hditem, 0, sizeof(HDITEM));
112
113 hditem.mask = HDI_TEXT|HDI_WIDTH;
114 hditem.pszText = text;
115 hditem.cchTextMax = 260;
116
117 SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEM, i, (LPARAM) &hditem);
118
119 for (n = 0; n < COLUMN_NMAX; n++) {
120 LoadStringW(hInst, ColumnPresets[n].dwIdsName, szTemp, _countof(szTemp));
121 if (_wcsicmp(text, szTemp) == 0)
122 {
123 TaskManagerSettings.Columns[n] = TRUE;
124 TaskManagerSettings.ColumnSizeArray[n] = hditem.cxy;
125 }
126 }
127 }
128 }
129
ProcessPage_OnViewSelectColumns(void)130 void ProcessPage_OnViewSelectColumns(void)
131 {
132 int i;
133
134 if (DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_COLUMNS_DIALOG), hMainWnd, ColumnsDialogWndProc) == IDOK)
135 {
136 for (i=Header_GetItemCount(hProcessPageHeaderCtrl)-1; i>=0; i--)
137 {
138 (void)ListView_DeleteColumn(hProcessPageListCtrl, i);
139 }
140
141 for (i=0; i<COLUMN_NMAX; i++) {
142 TaskManagerSettings.ColumnOrderArray[i] = i;
143 TaskManagerSettings.ColumnSizeArray[i] = ColumnPresets[i].size;
144 }
145
146 AddColumns();
147 }
148 }
149
150 INT_PTR CALLBACK
ColumnsDialogWndProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)151 ColumnsDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
152 {
153 unsigned int i;
154
155 switch (message)
156 {
157 case WM_INITDIALOG:
158 for (i=0; i<COLUMN_NMAX; i++) {
159 if (TaskManagerSettings.Columns[i])
160 CheckDlgButton(hDlg, ColumnPresets[i].dwIdcCtrl, BST_CHECKED);
161 }
162 return TRUE;
163
164 case WM_COMMAND:
165 if (LOWORD(wParam) == IDCANCEL)
166 {
167 EndDialog(hDlg, LOWORD(wParam));
168 return TRUE;
169 }
170
171 if (LOWORD(wParam) == IDOK)
172 {
173 for (i=0; i<COLUMN_NMAX; i++)
174 TaskManagerSettings.Columns[i] = (BOOL)IsDlgButtonChecked(hDlg, ColumnPresets[i].dwIdcCtrl);
175
176 EndDialog(hDlg, LOWORD(wParam));
177 return TRUE;
178 }
179
180 break;
181 }
182
183 return 0;
184 }
185
UpdateColumnDataHints(void)186 void UpdateColumnDataHints(void)
187 {
188 HDITEM hditem;
189 WCHAR text[260];
190 ULONG Index;
191 ULONG uItems;
192 WCHAR szTemp[256];
193 UINT i;
194
195 uItems = min(SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEMCOUNT, 0, 0), COLUMN_NMAX);
196
197 for (Index=0; Index<uItems; Index++)
198 {
199 memset(&hditem, 0, sizeof(HDITEM));
200
201 hditem.mask = HDI_TEXT;
202 hditem.pszText = text;
203 hditem.cchTextMax = 260;
204
205 SendMessageW(hProcessPageHeaderCtrl, HDM_GETITEM, Index, (LPARAM) &hditem);
206
207 for (i=0; i<COLUMN_NMAX; i++) {
208 LoadStringW(hInst, ColumnPresets[i].dwIdsName, szTemp, _countof(szTemp));
209 if (_wcsicmp(text, szTemp) == 0)
210 ColumnDataHints[Index] = i;
211 }
212 }
213 }
214