merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / lib / aclui / aclui.c
1 /*
2 * ReactOS Access Control List Editor
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS Access Control List Editor
22 * FILE: lib/aclui/aclui.c
23 * PURPOSE: Access Control List Editor
24 * PROGRAMMER: Thomas Weidenmueller (w3seek@users.sourceforge.net)
25 *
26 * UPDATE HISTORY:
27 * 08/10/2004 Created
28 */
29 #define INITGUID
30 #include <windows.h>
31 #include <commctrl.h>
32 #include <prsht.h>
33 #include <aclui.h>
34 #include <rosrtl/resstr.h>
35 #include "internal.h"
36 #include "resource.h"
37
38 HINSTANCE hDllInstance;
39
40 UINT CALLBACK
41 SecurityPageCallback(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
42 {
43 switch(uMsg)
44 {
45 case PSPCB_CREATE:
46 {
47 PSECURITY_PAGE sp;
48
49 sp = LocalAlloc(LHND, sizeof(SECURITY_PAGE));
50 if(sp != NULL)
51 {
52 /* save the pointer to the ISecurityInformation interface */
53 sp->psi = (LPSECURITYINFO)ppsp->lParam;
54 /* set the lParam to the allocated structure */
55 ppsp->lParam = (LPARAM)sp;
56 return TRUE;
57 }
58 return FALSE;
59 }
60 case PSPCB_RELEASE:
61 {
62 if(ppsp->lParam != 0)
63 {
64 PSECURITY_PAGE sp = (PSECURITY_PAGE)ppsp->lParam;
65 if(sp->hiUsrs != NULL)
66 {
67 ImageList_Destroy(sp->hiUsrs);
68 }
69 LocalFree((HLOCAL)sp);
70 }
71 return FALSE;
72 }
73 }
74
75 return FALSE;
76 }
77
78
79 INT_PTR CALLBACK
80 SecurityPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
81 {
82 PSECURITY_PAGE sp;
83
84 switch(uMsg)
85 {
86 case WM_INITDIALOG:
87 {
88 sp = (PSECURITY_PAGE)lParam;
89 if(sp != NULL)
90 {
91 LV_COLUMN lvc;
92 RECT rcLvClient;
93
94 sp->hWnd = hwndDlg;
95 sp->hWndUsrList = GetDlgItem(hwndDlg, IDC_ACELIST);
96 sp->hiUsrs = ImageList_LoadBitmap(hDllInstance, MAKEINTRESOURCE(IDB_USRGRPIMAGES), 16, 3, 0);
97
98 /* save the pointer to the structure */
99 SetWindowLongPtr(hwndDlg, DWL_USER, (DWORD_PTR)sp);
100
101 GetClientRect(sp->hWndUsrList, &rcLvClient);
102
103 /* setup the listview control */
104 ListView_SetExtendedListViewStyleEx(sp->hWndUsrList, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
105 ListView_SetImageList(sp->hWndUsrList, sp->hiUsrs, LVSIL_SMALL);
106
107 /* add a column to the list view */
108 lvc.mask = LVCF_FMT | LVCF_WIDTH;
109 lvc.fmt = LVCFMT_LEFT;
110 lvc.cx = rcLvClient.right;
111 ListView_InsertColumn(sp->hWndUsrList, 0, &lvc);
112
113 /* FIXME - hide controls in case the flags aren't present */
114 }
115 break;
116 }
117 }
118 return 0;
119 }
120
121
122 /*
123 * CreateSecurityPage EXPORTED
124 *
125 * @implemented
126 */
127 HPROPSHEETPAGE
128 WINAPI
129 CreateSecurityPage(LPSECURITYINFO psi)
130 {
131 PROPSHEETPAGE psp;
132 SI_OBJECT_INFO ObjectInfo;
133 HRESULT hRet;
134
135 if(psi == NULL)
136 {
137 SetLastError(ERROR_INVALID_PARAMETER);
138
139 DPRINT("No ISecurityInformation class passed!\n");
140 return NULL;
141 }
142
143 /* get the object information from the server interface */
144 hRet = psi->lpVtbl->GetObjectInformation(psi, &ObjectInfo);
145
146 if(FAILED(hRet))
147 {
148 SetLastError(hRet);
149
150 DPRINT("CreateSecurityPage() failed!\n");
151 return NULL;
152 }
153
154 psp.dwSize = sizeof(PROPSHEETPAGE);
155 psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK;
156 psp.hInstance = hDllInstance;
157 psp.pszTemplate = MAKEINTRESOURCE(IDD_SECPAGE);
158 psp.pfnDlgProc = SecurityPageProc;
159 psp.lParam = (LPARAM)psi;
160 psp.pfnCallback = SecurityPageCallback;
161
162 if((ObjectInfo.dwFlags & SI_PAGE_TITLE) != 0 &&
163 ObjectInfo.pszPageTitle != NULL && ObjectInfo.pszPageTitle[0] != L'\0')
164 {
165 /* Set the page title if the flag is present and the string isn't empty */
166 psp.pszTitle = ObjectInfo.pszPageTitle;
167 psp.dwFlags |= PSP_USETITLE;
168 }
169
170 return CreatePropertySheetPage(&psp);
171 }
172
173
174 /*
175 * EditSecurity EXPORTED
176 *
177 * @implemented
178 */
179 BOOL
180 WINAPI
181 EditSecurity(HWND hwndOwner, LPSECURITYINFO psi)
182 {
183 HRESULT hRet;
184 SI_OBJECT_INFO ObjectInfo;
185 PROPSHEETHEADER psh;
186 HPROPSHEETPAGE hPages[1];
187 LPWSTR lpCaption;
188 BOOL Ret;
189
190 if(psi == NULL)
191 {
192 SetLastError(ERROR_INVALID_PARAMETER);
193
194 DPRINT("No ISecurityInformation class passed!\n");
195 return FALSE;
196 }
197
198 /* get the object information from the server interface */
199 hRet = psi->lpVtbl->GetObjectInformation(psi, &ObjectInfo);
200
201 if(FAILED(hRet))
202 {
203 SetLastError(hRet);
204
205 DPRINT("GetObjectInformation() failed!\n");
206 return FALSE;
207 }
208
209 /* create the page */
210 hPages[0] = CreateSecurityPage(psi);
211 if(hPages[0] == NULL)
212 {
213 DPRINT("CreateSecurityPage(), couldn't create property sheet!\n");
214 return FALSE;
215 }
216
217 psh.dwSize = sizeof(PROPSHEETHEADER);
218 psh.dwFlags = PSH_DEFAULT;
219 psh.hwndParent = hwndOwner;
220 psh.hInstance = hDllInstance;
221 if((ObjectInfo.dwFlags & SI_PAGE_TITLE) != 0 &&
222 ObjectInfo.pszPageTitle != NULL && ObjectInfo.pszPageTitle[0] != L'\0')
223 {
224 /* Set the page title if the flag is present and the string isn't empty */
225 psh.pszCaption = ObjectInfo.pszPageTitle;
226 lpCaption = NULL;
227 }
228 else
229 {
230 /* Set the page title to the object name, make sure the format string
231 has "%1" NOT "%s" because it uses FormatMessage() to automatically
232 allocate the right amount of memory. */
233 RosLoadAndFormatStr(hDllInstance, IDS_PSP_TITLE, &lpCaption, ObjectInfo.pszObjectName);
234 psh.pszCaption = lpCaption;
235 }
236 psh.nPages = sizeof(hPages) / sizeof(HPROPSHEETPAGE);
237 psh.nStartPage = 0;
238 psh.phpage = hPages;
239
240 Ret = (PropertySheet(&psh) != -1);
241
242 if(lpCaption != NULL)
243 {
244 LocalFree((HLOCAL)lpCaption);
245 }
246
247 return Ret;
248 }
249
250 BOOL STDCALL
251 DllMain(HINSTANCE hinstDLL,
252 DWORD dwReason,
253 LPVOID lpvReserved)
254 {
255 switch (dwReason)
256 {
257 case DLL_PROCESS_ATTACH:
258 hDllInstance = hinstDLL;
259 break;
260 case DLL_THREAD_ATTACH:
261 break;
262 case DLL_THREAD_DETACH:
263 break;
264 case DLL_PROCESS_DETACH:
265 break;
266 }
267 return TRUE;
268 }
269