ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

listview.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     ReactOS Services
00003  * LICENSE:     GPL - See COPYING in the top level directory
00004  * FILE:        base/applications/mscutils/servman/listview.c
00005  * PURPOSE:     service listview manipulation functions
00006  * COPYRIGHT:   Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
00007  *
00008  */
00009 
00010 #include "precomp.h"
00011 
00012 
00013 VOID
00014 SetListViewStyle(HWND hListView,
00015                  DWORD View)
00016 {
00017     DWORD Style = GetWindowLongPtr(hListView, GWL_STYLE);
00018 
00019     if ((Style & LVS_TYPEMASK) != View)
00020     {
00021         SetWindowLongPtr(hListView,
00022                          GWL_STYLE,
00023                          (Style & ~LVS_TYPEMASK) | View);
00024     }
00025 }
00026 
00027 
00028 VOID
00029 ListViewSelectionChanged(PMAIN_WND_INFO Info,
00030                          LPNMLISTVIEW pnmv)
00031 {
00032     HMENU hMainMenu;
00033 
00034     /* get handle to menu */
00035     hMainMenu = GetMenu(Info->hMainWnd);
00036 
00037     /* activate properties menu item, if not already */
00038     if (GetMenuState(hMainMenu,
00039                      ID_PROP,
00040                      MF_BYCOMMAND) != MF_ENABLED)
00041     {
00042         EnableMenuItem(hMainMenu,
00043                        ID_PROP,
00044                        MF_ENABLED);
00045         EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0),
00046                        ID_PROP,
00047                        MF_ENABLED);
00048         SetMenuDefaultItem(GetSubMenu(Info->hShortcutMenu, 0),
00049                            ID_PROP,
00050                            MF_BYCOMMAND);
00051     }
00052 
00053     /* activate delete menu item, if not already */
00054     if (GetMenuState(hMainMenu,
00055                      ID_DELETE,
00056                      MF_BYCOMMAND) != MF_ENABLED)
00057     {
00058         EnableMenuItem(hMainMenu,
00059                        ID_DELETE,
00060                        MF_ENABLED);
00061         EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0),
00062                        ID_DELETE,
00063                        MF_ENABLED);
00064     }
00065 
00066     /* set selected service */
00067     Info->SelectedItem = pnmv->iItem;
00068 
00069     /* get pointer to selected service */
00070     Info->pCurrentService = GetSelectedService(Info);
00071 
00072     /* set current selected service in the status bar */
00073     SendMessage(Info->hStatus,
00074                 SB_SETTEXT,
00075                 1,
00076                 (LPARAM)Info->pCurrentService->lpDisplayName);
00077 
00078     /* show the properties button */
00079     SendMessage(Info->hTool,
00080                 TB_SETSTATE,
00081                 ID_PROP,
00082                 (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
00083 }
00084 
00085 
00086 VOID
00087 ChangeListViewText(PMAIN_WND_INFO Info,
00088                    ENUM_SERVICE_STATUS_PROCESS* pService,
00089                    UINT Column)
00090 {
00091     LVFINDINFO lvfi;
00092     LVITEM lvItem;
00093     INT index;
00094 
00095     lvfi.flags = LVFI_PARAM;
00096     lvfi.lParam = (LPARAM)pService;
00097     index = ListView_FindItem(Info->hListView,
00098                               -1,
00099                               &lvfi);
00100     if (index != -1)
00101     {
00102         lvItem.iItem = index;
00103         lvItem.iSubItem = Column;
00104 
00105         switch (Column)
00106         {
00107             case LVNAME:
00108             {
00109                 LPQUERY_SERVICE_CONFIG lpServiceConfig;
00110 
00111                 lpServiceConfig = GetServiceConfig(pService->lpServiceName);
00112                 if (lpServiceConfig)
00113                 {
00114                     lvItem.pszText = lpServiceConfig->lpDisplayName;
00115                     SendMessage(Info->hListView,
00116                                 LVM_SETITEMTEXT,
00117                                 lvItem.iItem,
00118                                 (LPARAM)&lvItem);
00119 
00120                     HeapFree(ProcessHeap,
00121                              0,
00122                              lpServiceConfig);
00123                 }
00124             }
00125             break;
00126 
00127             case LVDESC:
00128             {
00129                 LPTSTR lpDescription;
00130 
00131                 lpDescription = GetServiceDescription(pService->lpServiceName);
00132 
00133                 lvItem.pszText = lpDescription;
00134                 SendMessage(Info->hListView,
00135                             LVM_SETITEMTEXT,
00136                             lvItem.iItem,
00137                             (LPARAM) &lvItem);
00138 
00139                 HeapFree(ProcessHeap,
00140                          0,
00141                          lpDescription);
00142             }
00143             break;
00144 
00145             case LVSTATUS:
00146             {
00147                 TCHAR szStatus[64];
00148 
00149                 if (pService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
00150                 {
00151                     LoadString(hInstance,
00152                                IDS_SERVICES_STARTED,
00153                                szStatus,
00154                                sizeof(szStatus) / sizeof(TCHAR));
00155                 }
00156                 else
00157                 {
00158                     szStatus[0] = 0;
00159                 }
00160 
00161                 lvItem.pszText = szStatus;
00162                 SendMessage(Info->hListView,
00163                             LVM_SETITEMTEXT,
00164                             lvItem.iItem,
00165                             (LPARAM) &lvItem);
00166             }
00167             break;
00168 
00169             case LVSTARTUP:
00170             {
00171                 LPQUERY_SERVICE_CONFIG lpServiceConfig;
00172                 LPTSTR lpStartup = NULL;
00173                 DWORD StringId = 0;
00174 
00175                 lpServiceConfig = GetServiceConfig(pService->lpServiceName);
00176 
00177                 if (lpServiceConfig)
00178                 {
00179                     switch (lpServiceConfig->dwStartType)
00180                     {
00181                         case 2: StringId = IDS_SERVICES_AUTO; break;
00182                         case 3: StringId = IDS_SERVICES_MAN; break;
00183                         case 4: StringId = IDS_SERVICES_DIS; break;
00184                     }
00185                 }
00186 
00187                 if (StringId)
00188                     AllocAndLoadString(&lpStartup,
00189                                        hInstance,
00190                                        StringId);
00191 
00192                 lvItem.pszText = lpStartup;
00193                 SendMessage(Info->hListView,
00194                             LVM_SETITEMTEXT,
00195                             lvItem.iItem,
00196                             (LPARAM)&lvItem);
00197 
00198                 HeapFree(ProcessHeap,
00199                          0,
00200                          lpStartup);
00201                 HeapFree(ProcessHeap,
00202                          0,
00203                          lpServiceConfig);
00204             }
00205             break;
00206 
00207             case LVLOGONAS:
00208             {
00209                 LPQUERY_SERVICE_CONFIG lpServiceConfig;
00210 
00211                 lpServiceConfig = GetServiceConfig(pService->lpServiceName);
00212                 if (lpServiceConfig)
00213                 {
00214                     lvItem.pszText = lpServiceConfig->lpServiceStartName;
00215                     SendMessage(Info->hListView,
00216                                 LVM_SETITEMTEXT,
00217                                 lvItem.iItem,
00218                                 (LPARAM)&lvItem);
00219 
00220                     HeapFree(ProcessHeap,
00221                              0,
00222                              lpServiceConfig);
00223                 }
00224             }
00225             break;
00226         }
00227     }
00228 }
00229 
00230 
00231 BOOL
00232 RefreshServiceList(PMAIN_WND_INFO Info)
00233 {
00234     ENUM_SERVICE_STATUS_PROCESS *pService;
00235     LVITEM lvItem;
00236     DWORD NumServices;
00237     DWORD Index;
00238 
00239     SendMessage (Info->hListView,
00240                  WM_SETREDRAW,
00241                  FALSE,
00242                  0);
00243 
00244     (void)ListView_DeleteAllItems(Info->hListView);
00245 
00246     if (GetServiceList(Info, &NumServices))
00247     {
00248         for (Index = 0; Index < NumServices; Index++)
00249         {
00250             INT i;
00251 
00252             pService = &Info->pAllServices[Index];
00253 
00254             /* set the display name */
00255             ZeroMemory(&lvItem, sizeof(LVITEM));
00256             lvItem.mask = LVIF_TEXT | LVIF_PARAM;
00257             lvItem.pszText = pService->lpDisplayName;
00258 
00259             /* Add the service pointer */
00260             lvItem.lParam = (LPARAM)pService;
00261 
00262             /* add it to the listview */
00263             lvItem.iItem = ListView_InsertItem(Info->hListView, &lvItem);
00264 
00265             /* fill out all the column data */
00266             for (i = LVDESC; i <= LVLOGONAS; i++)
00267             {
00268                 ChangeListViewText(Info, pService, i);
00269             }
00270         }
00271 
00272         UpdateServiceCount(Info);
00273     }
00274 
00275     /* turn redraw flag on. */
00276     SendMessage (Info->hListView,
00277                  WM_SETREDRAW,
00278                  TRUE,
00279                  0);
00280 
00281     return TRUE;
00282 }
00283 
00284 
00285 static VOID
00286 InitListViewImage(PMAIN_WND_INFO Info)
00287 {
00288     HICON hSmIconItem, hLgIconItem;
00289     HIMAGELIST hSmall, hLarge;
00290 
00291     hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
00292                               GetSystemMetrics(SM_CYSMICON),
00293                               ILC_MASK | ILC_COLOR32,
00294                               1,
00295                               1);
00296     if (hSmall)
00297     {
00298         hSmIconItem = LoadImage(hInstance,
00299                                 MAKEINTRESOURCE(IDI_SM_ICON),
00300                                 IMAGE_ICON,
00301                                 16,
00302                                 16,
00303                                 0);
00304         if (hSmIconItem)
00305         {
00306             ImageList_AddIcon(hSmall,
00307                               hSmIconItem);
00308             (void)ListView_SetImageList(Info->hListView,
00309                                         hSmall,
00310                                         LVSIL_SMALL);
00311 
00312             DestroyIcon(hSmIconItem);
00313         }
00314     }
00315 
00316     hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
00317                               GetSystemMetrics(SM_CYICON),
00318                               ILC_MASK | ILC_COLOR32,
00319                               1,
00320                               1);
00321     if (hLarge)
00322     {
00323         hLgIconItem = LoadImage(hInstance,
00324                                 MAKEINTRESOURCE(IDI_SM_ICON),
00325                                 IMAGE_ICON,
00326                                 32,
00327                                 32,
00328                                 0);
00329         if (hLgIconItem)
00330         {
00331             ImageList_AddIcon(hLarge,
00332                               hLgIconItem);
00333             (void)ListView_SetImageList(Info->hListView,
00334                                         hLarge,
00335                                         LVSIL_NORMAL);
00336             DestroyIcon(hLgIconItem);
00337         }
00338     }
00339 }
00340 
00341 
00342 BOOL
00343 CreateListView(PMAIN_WND_INFO Info)
00344 {
00345     LVCOLUMN lvc = { 0 };
00346     TCHAR szTemp[256];
00347 
00348     Info->hListView = CreateWindowEx(WS_EX_CLIENTEDGE,
00349                                      WC_LISTVIEW,
00350                                      NULL,
00351                                      WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER |
00352                                         LBS_NOTIFY | LVS_SORTASCENDING | LBS_NOREDRAW,
00353                                      0, 0, 0, 0,
00354                                      Info->hMainWnd,
00355                                      (HMENU) IDC_SERVLIST,
00356                                      hInstance,
00357                                      NULL);
00358     if (Info->hListView == NULL)
00359     {
00360         MessageBox(Info->hMainWnd,
00361                    _T("Could not create List View."),
00362                    _T("Error"),
00363                    MB_OK | MB_ICONERROR);
00364         return FALSE;
00365     }
00366 
00367     (void)ListView_SetExtendedListViewStyle(Info->hListView,
00368                                             LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);/*LVS_EX_GRIDLINES |*/
00369 
00370     lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH  | LVCF_FMT;
00371     lvc.fmt  = LVCFMT_LEFT;
00372 
00373     /* Add columns to the list-view */
00374     /* name */
00375     lvc.iSubItem = LVNAME;
00376     lvc.cx       = 150;
00377     LoadString(hInstance,
00378                IDS_FIRSTCOLUMN,
00379                szTemp,
00380                sizeof(szTemp) / sizeof(TCHAR));
00381     lvc.pszText  = szTemp;
00382     (void)ListView_InsertColumn(Info->hListView,
00383                                 0,
00384                                 &lvc);
00385 
00386     /* description */
00387     lvc.iSubItem = LVDESC;
00388     lvc.cx       = 240;
00389     LoadString(hInstance,
00390                IDS_SECONDCOLUMN,
00391                szTemp,
00392                sizeof(szTemp) / sizeof(TCHAR));
00393     lvc.pszText  = szTemp;
00394     (void)ListView_InsertColumn(Info->hListView,
00395                                 1,
00396                                 &lvc);
00397 
00398     /* status */
00399     lvc.iSubItem = LVSTATUS;
00400     lvc.cx       = 55;
00401     LoadString(hInstance,
00402                IDS_THIRDCOLUMN,
00403                szTemp,
00404                sizeof(szTemp) / sizeof(TCHAR));
00405     lvc.pszText  = szTemp;
00406     (void)ListView_InsertColumn(Info->hListView,
00407                                 2,
00408                                 &lvc);
00409 
00410     /* startup type */
00411     lvc.iSubItem = LVSTARTUP;
00412     lvc.cx       = 80;
00413     LoadString(hInstance,
00414                IDS_FOURTHCOLUMN,
00415                szTemp,
00416                sizeof(szTemp) / sizeof(TCHAR));
00417     lvc.pszText  = szTemp;
00418     (void)ListView_InsertColumn(Info->hListView,
00419                                 3,
00420                                 &lvc);
00421 
00422     /* logon as */
00423     lvc.iSubItem = LVLOGONAS;
00424     lvc.cx       = 100;
00425     LoadString(hInstance,
00426                IDS_FITHCOLUMN,
00427                szTemp,
00428                sizeof(szTemp) / sizeof(TCHAR));
00429     lvc.pszText  = szTemp;
00430     (void)ListView_InsertColumn(Info->hListView,
00431                                 4,
00432                                 &lvc);
00433 
00434     InitListViewImage(Info);
00435 
00436     /* check the details view menu item */
00437     CheckMenuRadioItem(GetMenu(Info->hMainWnd),
00438                        ID_VIEW_LARGE,
00439                        ID_VIEW_DETAILS,
00440                        ID_VIEW_DETAILS,
00441                        MF_BYCOMMAND);
00442 
00443     return TRUE;
00444 }

Generated on Sun May 27 2012 04:16:59 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.