2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/listview.c
5 * PURPOSE: service listview manipulation functions
6 * COPYRIGHT: Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
12 typedef struct _COLUMN_LIST
19 static const COLUMN_LIST Columns
[] =
22 { LVNAME
, 150, IDS_FIRSTCOLUMN
},
24 { LVDESC
, 240, IDS_SECONDCOLUMN
},
26 { LVSTATUS
, 55, IDS_THIRDCOLUMN
},
28 { LVSTARTUP
, 80, IDS_FOURTHCOLUMN
},
30 { LVLOGONAS
, 100, IDS_FITHCOLUMN
},
34 SetListViewStyle(HWND hListView
,
37 DWORD Style
= GetWindowLongPtr(hListView
, GWL_STYLE
);
39 if ((Style
& LVS_TYPEMASK
) != View
)
41 SetWindowLongPtr(hListView
,
43 (Style
& ~LVS_TYPEMASK
) | View
);
48 ListViewSelectionChanged(PMAIN_WND_INFO Info
,
53 /* get handle to menu */
54 hMainMenu
= GetMenu(Info
->hMainWnd
);
56 /* activate properties menu item, if not already */
57 if (GetMenuState(hMainMenu
,
59 MF_BYCOMMAND
) != MF_ENABLED
)
61 EnableMenuItem(hMainMenu
,
64 EnableMenuItem(GetSubMenu(Info
->hShortcutMenu
, 0),
67 SetMenuDefaultItem(GetSubMenu(Info
->hShortcutMenu
, 0),
72 /* activate delete menu item, if not already */
73 if (GetMenuState(hMainMenu
,
75 MF_BYCOMMAND
) != MF_ENABLED
)
77 EnableMenuItem(hMainMenu
,
80 EnableMenuItem(GetSubMenu(Info
->hShortcutMenu
, 0),
85 /* set selected service */
86 Info
->SelectedItem
= pnmv
->iItem
;
88 /* get pointer to selected service */
89 Info
->pCurrentService
= GetSelectedService(Info
);
91 /* set current selected service in the status bar */
92 SendMessage(Info
->hStatus
,
95 (LPARAM
)Info
->pCurrentService
->lpDisplayName
);
97 /* show the properties button */
98 SendMessage(Info
->hTool
,
101 (LPARAM
)MAKELONG(TBSTATE_ENABLED
, 0));
105 ChangeListViewText(PMAIN_WND_INFO Info
,
106 ENUM_SERVICE_STATUS_PROCESS
* pService
,
113 lvfi
.flags
= LVFI_PARAM
;
114 lvfi
.lParam
= (LPARAM
)pService
;
115 index
= ListView_FindItem(Info
->hListView
,
120 lvItem
.iItem
= index
;
121 lvItem
.iSubItem
= Column
;
127 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
129 lpServiceConfig
= GetServiceConfig(pService
->lpServiceName
);
132 lvItem
.pszText
= lpServiceConfig
->lpDisplayName
;
133 SendMessage(Info
->hListView
,
138 HeapFree(ProcessHeap
,
147 LPWSTR lpDescription
;
149 lpDescription
= GetServiceDescription(pService
->lpServiceName
);
151 lvItem
.pszText
= lpDescription
;
152 SendMessage(Info
->hListView
,
157 HeapFree(ProcessHeap
,
167 if (pService
->ServiceStatusProcess
.dwCurrentState
== SERVICE_RUNNING
)
169 LoadStringW(hInstance
,
170 IDS_SERVICES_STARTED
,
172 sizeof(szStatus
) / sizeof(WCHAR
));
179 lvItem
.pszText
= szStatus
;
180 SendMessageW(Info
->hListView
,
189 LPQUERY_SERVICE_CONFIGW lpServiceConfig
;
190 LPWSTR lpStartup
= NULL
;
193 lpServiceConfig
= GetServiceConfig(pService
->lpServiceName
);
197 switch (lpServiceConfig
->dwStartType
)
199 case 2: StringId
= IDS_SERVICES_AUTO
; break;
200 case 3: StringId
= IDS_SERVICES_MAN
; break;
201 case 4: StringId
= IDS_SERVICES_DIS
; break;
206 AllocAndLoadString(&lpStartup
,
210 lvItem
.pszText
= lpStartup
;
211 SendMessageW(Info
->hListView
,
216 LocalFree(lpStartup
);
217 HeapFree(ProcessHeap
,
225 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
227 lpServiceConfig
= GetServiceConfig(pService
->lpServiceName
);
230 lvItem
.pszText
= lpServiceConfig
->lpServiceStartName
;
231 SendMessageW(Info
->hListView
,
236 HeapFree(ProcessHeap
,
247 RefreshServiceList(PMAIN_WND_INFO Info
)
249 ENUM_SERVICE_STATUS_PROCESS
*pService
;
254 SendMessage (Info
->hListView
,
259 (void)ListView_DeleteAllItems(Info
->hListView
);
261 if (GetServiceList(Info
, &NumServices
))
263 for (Index
= 0; Index
< NumServices
; Index
++)
267 pService
= &Info
->pAllServices
[Index
];
269 /* set the display name */
270 ZeroMemory(&lvItem
, sizeof(LVITEMW
));
271 lvItem
.mask
= LVIF_TEXT
| LVIF_PARAM
;
272 lvItem
.pszText
= pService
->lpDisplayName
;
274 /* Add the service pointer */
275 lvItem
.lParam
= (LPARAM
)pService
;
277 /* add it to the listview */
278 lvItem
.iItem
= ListView_InsertItem(Info
->hListView
, &lvItem
);
280 /* fill out all the column data */
281 for (i
= LVDESC
; i
<= LVLOGONAS
; i
++)
283 ChangeListViewText(Info
, pService
, i
);
287 UpdateServiceCount(Info
);
290 /* turn redraw flag on. */
291 SendMessageW(Info
->hListView
,
300 InitListViewImage(PMAIN_WND_INFO Info
)
302 HICON hSmIconItem
, hLgIconItem
;
303 HIMAGELIST hSmall
, hLarge
;
305 hSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
306 GetSystemMetrics(SM_CYSMICON
),
307 ILC_MASK
| ILC_COLOR32
,
312 hSmIconItem
= LoadImageW(hInstance
,
313 MAKEINTRESOURCE(IDI_SM_ICON
),
320 ImageList_AddIcon(hSmall
,
322 (void)ListView_SetImageList(Info
->hListView
,
326 DestroyIcon(hSmIconItem
);
330 hLarge
= ImageList_Create(GetSystemMetrics(SM_CXICON
),
331 GetSystemMetrics(SM_CYICON
),
332 ILC_MASK
| ILC_COLOR32
,
337 hLgIconItem
= LoadImageW(hInstance
,
338 MAKEINTRESOURCE(IDI_SM_ICON
),
345 ImageList_AddIcon(hLarge
,
347 (void)ListView_SetImageList(Info
->hListView
,
350 DestroyIcon(hLgIconItem
);
356 CreateListView(PMAIN_WND_INFO Info
)
358 LVCOLUMNW lvc
= { 0 };
363 Info
->hListView
= CreateWindowExW(WS_EX_CLIENTEDGE
,
366 WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| WS_BORDER
|
367 LBS_NOTIFY
| LVS_SORTASCENDING
| LBS_NOREDRAW
,
370 (HMENU
) IDC_SERVLIST
,
373 if (Info
->hListView
== NULL
)
375 MessageBoxW(Info
->hMainWnd
,
376 L
"Could not create List View.",
378 MB_OK
| MB_ICONERROR
);
382 Info
->hHeader
= ListView_GetHeader(Info
->hListView
);
384 (void)ListView_SetExtendedListViewStyle(Info
->hListView
,
385 LVS_EX_FULLROWSELECT
| LVS_EX_HEADERDRAGDROP
);/*LVS_EX_GRIDLINES |*/
387 lvc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
| LVCF_FMT
;
388 lvc
.fmt
= LVCFMT_LEFT
;
389 lvc
.pszText
= szTemp
;
391 /* Add columns to the list-view */
392 for (n
= 0; n
< sizeof(Columns
) / sizeof(Columns
[0]); n
++)
394 lvc
.iSubItem
= Columns
[n
].iSubItem
;
395 lvc
.cx
= Columns
[n
].cx
;
397 LoadStringW(hInstance
,
400 sizeof(szTemp
) / sizeof(szTemp
[0]));
402 i
= ListView_InsertColumn(Info
->hListView
, Columns
[n
].iSubItem
, &lvc
);
404 hdi
.mask
= HDI_LPARAM
;
405 hdi
.lParam
= ORD_ASCENDING
;
406 (void)Header_SetItem(Info
->hHeader
, i
, &hdi
);
409 InitListViewImage(Info
);
411 /* check the details view menu item */
412 CheckMenuRadioItem(GetMenu(Info
->hMainWnd
),