2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/param.h>
15 #include "TaAfsUsrMgr.h"
23 * DEFINITIONS ________________________________________________________________
27 #define GWD_ASIDLIST_MEMBER TEXT("AsidList - Members")
28 #define GWD_ASIDLIST_OWNER TEXT("AsidList - Owned")
32 * PROTOTYPES _________________________________________________________________
36 BOOL CALLBACK GroupProp_General_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
37 void GroupProp_General_OnInitDialog (HWND hDlg);
38 void GroupProp_General_OnDestroy (HWND hDlg);
39 void GroupProp_General_OnApply (HWND hDlg);
40 void GroupProp_General_OnBrowse (HWND hDlg);
41 void GroupProp_General_UpdateDialog (HWND hDlg);
42 void GroupProp_General_UpdateDialog_Perm (HWND hDlg, int idc, ACCOUNTACCESS aa, BOOL fMixed);
44 BOOL CALLBACK GroupProp_Member_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
45 void GroupProp_Member_OnInitDialog (HWND hDlg);
46 void GroupProp_Member_OnDestroy (HWND hDlg);
47 void GroupProp_Member_OnShowType (HWND hDlg);
48 void GroupProp_Member_OnSelect (HWND hDlg);
49 void GroupProp_Member_OnApply (HWND hDlg);
50 void GroupProp_Member_OnAdd (HWND hDlg);
51 void GroupProp_Member_OnRemove (HWND hDlg);
52 void GroupProp_Member_OnEndTask_GetMembers (HWND hDlg, LPTASKPACKET ptp);
53 void GroupProp_Member_OnEndTask_GetOwned (HWND hDlg, LPTASKPACKET ptp);
54 void GroupProp_Member_PopulateList (HWND hDlg);
58 * ROUTINES ___________________________________________________________________
62 void Group_FreeProperties (LPGROUPPROPINFO lpp)
66 if (lpp->fApplyGeneral && lpp->pGroupList)
68 for (size_t ii = 0; ii < lpp->pGroupList->cEntries; ++ii)
72 if (!asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, lpp->pGroupList->aEntries[ ii ].idObject, &Properties, &status))
75 LPGROUP_CHANGE_PARAMS pTask = New (GROUP_CHANGE_PARAMS);
76 memset (pTask, 0x00, sizeof(GROUP_CHANGE_PARAMS));
77 pTask->idGroup = lpp->pGroupList->aEntries[ ii ].idObject;
81 if (!lpp->fApplyGeneral || lpp->fStatus_Mixed)
82 pTask->NewProperties.aaListStatus = Properties.u.GroupProperties.aaListStatus;
84 pTask->NewProperties.aaListStatus = lpp->aaStatus;
86 if (!lpp->fApplyGeneral || lpp->fGroups_Mixed)
87 pTask->NewProperties.aaListGroupsOwned = Properties.u.GroupProperties.aaListGroupsOwned;
89 pTask->NewProperties.aaListGroupsOwned = lpp->aaGroups;
91 if (!lpp->fApplyGeneral || lpp->fMembers_Mixed)
92 pTask->NewProperties.aaListMembers = Properties.u.GroupProperties.aaListMembers;
94 pTask->NewProperties.aaListMembers = lpp->aaMembers;
96 if (!lpp->fApplyGeneral || lpp->fAdd_Mixed)
97 pTask->NewProperties.aaAddMember = Properties.u.GroupProperties.aaAddMember;
99 pTask->NewProperties.aaAddMember = lpp->aaAdd;
101 if (!lpp->fApplyGeneral || lpp->fRemove_Mixed)
102 pTask->NewProperties.aaDeleteMember = Properties.u.GroupProperties.aaDeleteMember;
104 pTask->NewProperties.aaDeleteMember = lpp->aaRemove;
106 if (!lpp->fApplyGeneral || lpp->fOwner_Mixed)
107 lstrcpy (pTask->NewProperties.szOwner, Properties.u.GroupProperties.szOwner);
109 lstrcpy (pTask->NewProperties.szOwner, lpp->szOwner);
111 StartTask (taskGROUP_CHANGE, NULL, pTask);
116 asc_AsidListFree (&lpp->pMembers);
117 if (lpp->pGroupsOwner)
118 asc_AsidListFree (&lpp->pGroupsOwner);
120 asc_AsidListFree (&lpp->pGroupList);
121 memset (lpp, 0x00, sizeof(GROUPPROPINFO));
127 void Group_ShowProperties (LPASIDLIST pGroupList, GROUPPROPTAB gptTarget)
129 LPGROUPPROPINFO lpp = New (GROUPPROPINFO);
130 memset (lpp, 0x00, sizeof(GROUPPROPINFO));
131 lpp->pGroupList = pGroupList;
132 lpp->fDeleteMeOnClose = TRUE;
133 lpp->fShowModal = FALSE;
134 Group_ShowProperties (lpp, gptTarget);
138 void Group_ShowProperties (LPGROUPPROPINFO lpp, GROUPPROPTAB gptTarget)
142 // If we've been asked to view properties for only one group, and there is
143 // already a window open for that group, switch to it.
147 if (lpp->pGroupList->cEntries == 1)
149 ASID idGroup = lpp->pGroupList->aEntries[0].idObject;
151 if ((hSheet = WindowList_Search (wltGROUP_PROPERTIES, idGroup)) != NULL)
153 SetForegroundWindow (hSheet);
154 if (gptTarget != gptANY)
156 HWND hTab = GetDlgItem (hSheet, IDC_PROPSHEET_TABCTRL);
157 int nTabs = TabCtrl_GetItemCount (hTab);
158 if (nTabs < nGROUPPROPTAB_MAX)
159 gptTarget = (GROUPPROPTAB)( ((int)gptTarget-1) );
160 TabCtrl_SwitchToTab (hTab, gptTarget);
166 // Otherwise, make sure there are no Properties windows open for any
167 // of the selected groups
169 for (size_t iGroup = 0; iGroup < lpp->pGroupList->cEntries; ++iGroup)
171 ASID idGroup = lpp->pGroupList->aEntries[ iGroup ].idObject;
173 // See if there's a Properties window open that is dedicated to
176 if ((hSheet = WindowList_Search (wltGROUP_PROPERTIES, idGroup)) != NULL)
178 ErrorDialog (0, IDS_ERROR_GROUP_MULTIPROP);
182 // See if there is a multiple-group properties window open; if so,
183 // test it to see if it covers this group
185 if ((hSheet = WindowList_Search (wltGROUP_PROPERTIES, 0)) != NULL)
187 LPGROUPPROPINFO pInfo = (LPGROUPPROPINFO)PropSheet_FindTabParam (hSheet);
188 if (pInfo && pInfo->pGroupList && asc_AsidListTest (&pInfo->pGroupList, idGroup))
190 ErrorDialog (0, IDS_ERROR_GROUP_MULTIPROP);
197 // Okay, we're clear to create the new properties window.
200 if (!lpp->pGroupList)
202 pszTitle = FormatString (IDS_NEWGROUP_PROPERTIES_TITLE);
204 else if (lpp->pGroupList->cEntries > 1)
206 pszTitle = FormatString (IDS_GROUP_PROPERTIES_TITLE_MULTIPLE);
210 TCHAR szGroup[ cchRESOURCE ];
211 asc_ObjectNameGet_Fast (g.idClient, g.idCell, lpp->pGroupList->aEntries[0].idObject, szGroup);
212 pszTitle = FormatString (IDS_GROUP_PROPERTIES_TITLE, TEXT("%s"), szGroup);
215 LPPROPSHEET psh = PropSheet_Create (pszTitle, TRUE, NULL, (LPARAM)lpp);
216 PropSheet_AddTab (psh, 0, (lpp->pGroupList) ? IDD_GROUP_GENERAL : IDD_NEWGROUP_GENERAL, (DLGPROC)GroupProp_General_DlgProc, (LPARAM)lpp, TRUE, (gptTarget == gptGENERAL) ? TRUE : FALSE);
217 PropSheet_AddTab (psh, 0, (lpp->pGroupList) ? IDD_GROUP_MEMBER : IDD_NEWGROUP_MEMBER, (DLGPROC)GroupProp_Member_DlgProc, (LPARAM)lpp, TRUE, (gptTarget == gptMEMBERS) ? TRUE : FALSE);
220 PropSheet_ShowModal (psh, PumpMessage);
222 PropSheet_ShowModeless (psh, SW_SHOW);
226 BOOL CALLBACK GroupProp_General_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
228 if (AfsAppLib_HandleHelp (IDD_GROUP_GENERAL, hDlg, msg, wp, lp))
231 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
235 case WM_INITDIALOG_SHEET:
236 if (lpp && lpp->pGroupList && !lpp->fShowModal)
238 if (lpp->pGroupList->cEntries == 1)
239 WindowList_Add (hDlg, wltGROUP_PROPERTIES, lpp->pGroupList->aEntries[0].idObject);
240 else // (lpp->pGroupList->cEntries > 1)
241 WindowList_Add (hDlg, wltGROUP_PROPERTIES, 0);
245 case WM_DESTROY_SHEET:
246 WindowList_Remove (hDlg);
247 if (lpp && lpp->fDeleteMeOnClose)
248 Group_FreeProperties (lpp);
252 GroupProp_General_OnInitDialog (hDlg);
256 GroupProp_General_OnDestroy (hDlg);
259 case WM_ASC_NOTIFY_OBJECT:
260 GroupProp_General_UpdateDialog (hDlg);
267 GroupProp_General_OnApply (hDlg);
270 case IDC_GROUP_CHANGEOWNER:
271 GroupProp_General_OnBrowse (hDlg);
274 case IDC_GROUP_PERM_STATUS:
275 case IDC_GROUP_PERM_GROUPS:
276 case IDC_GROUP_PERM_MEMBERS:
277 case IDC_GROUP_PERM_ADD:
278 case IDC_GROUP_PERM_REMOVE:
279 if (HIWORD(wp) == CBN_SELCHANGE)
280 PropSheetChanged (hDlg);
290 void GroupProp_General_OnInitDialog (HWND hDlg)
292 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
294 // Indicate we want to know if anything changes with these groups
298 LPOBJECT_LISTEN_PARAMS pTask = New (OBJECT_LISTEN_PARAMS);
299 memset (pTask, 0x00, sizeof(OBJECT_LISTEN_PARAMS));
300 pTask->hNotify = hDlg;
301 asc_AsidListCopy (&pTask->pAsidList, &lpp->pGroupList);
302 StartTask (taskOBJECT_LISTEN, NULL, pTask);
305 // Fill in the information about the selected groups
307 GroupProp_General_UpdateDialog (hDlg);
311 void GroupProp_General_OnDestroy (HWND hDlg)
313 // Indicate we no longer care if anything changes with these groups
315 LPOBJECT_LISTEN_PARAMS pTask = New (OBJECT_LISTEN_PARAMS);
316 memset (pTask, 0x00, sizeof(OBJECT_LISTEN_PARAMS));
317 pTask->hNotify = hDlg;
318 StartTask (taskOBJECT_LISTEN, NULL, pTask);
322 void GroupProp_General_UpdateDialog (HWND hDlg)
324 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
326 // Fix the name shown on the dialog
328 if (!lpp->pGroupList || (lpp->pGroupList->cEntries == 1))
331 TCHAR szName[ cchRESOURCE ];
332 asc_ObjectNameGet_Fast (g.idClient, g.idCell, (lpp->pGroupList) ? (lpp->pGroupList->aEntries[ 0 ].idObject) : g.idCell, szName, &status);
336 ASOBJPROP Properties;
337 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, lpp->pGroupList->aEntries[ 0 ].idObject, &Properties, &status))
338 AppendUID (szName, Properties.u.GroupProperties.uidName);
341 LPTSTR pszText = FormatString (IDS_GROUP_TITLE, TEXT("%s"), szName);
342 SetDlgItemText (hDlg, IDC_GROUP_NAME, pszText);
343 FreeString (pszText);
345 else // More than one name?
347 LPTSTR pszText = CreateNameList (lpp->pGroupList, IDS_GROUP_NAME_MULTIPLE);
348 SetDlgItemText (hDlg, IDC_GROUP_NAME, pszText);
349 FreeString (pszText);
352 // Fill in the rest of the dialog
354 BOOL fGotAnyData = FALSE;
356 for (size_t ii = 0; lpp->pGroupList && (ii < lpp->pGroupList->cEntries); ++ii)
359 ASOBJPROP Properties;
360 if (!asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, lpp->pGroupList->aEntries[ ii ].idObject, &Properties, &status))
365 lpp->aaStatus = Properties.u.GroupProperties.aaListStatus;
366 lpp->aaGroups = Properties.u.GroupProperties.aaListGroupsOwned;
367 lpp->aaMembers = Properties.u.GroupProperties.aaListMembers;
368 lpp->aaAdd = Properties.u.GroupProperties.aaAddMember;
369 lpp->aaRemove = Properties.u.GroupProperties.aaDeleteMember;
370 lstrcpy (lpp->szOwner, Properties.u.GroupProperties.szOwner);
371 AppendUID (lpp->szOwner, Properties.u.GroupProperties.uidOwner);
372 lstrcpy (lpp->szCreator, Properties.u.GroupProperties.szCreator);
373 AppendUID (lpp->szCreator, Properties.u.GroupProperties.uidCreator);
376 else // (fGotAnyData)
378 if (lpp->aaStatus != Properties.u.GroupProperties.aaListStatus)
379 lpp->fStatus_Mixed = TRUE;
380 if (lpp->aaGroups != Properties.u.GroupProperties.aaListGroupsOwned)
381 lpp->fGroups_Mixed = TRUE;
382 if (lpp->aaMembers != Properties.u.GroupProperties.aaListMembers)
383 lpp->fMembers_Mixed = TRUE;
384 if (lpp->aaAdd != Properties.u.GroupProperties.aaAddMember)
385 lpp->fAdd_Mixed = TRUE;
386 if (lpp->aaRemove != Properties.u.GroupProperties.aaDeleteMember)
387 lpp->fRemove_Mixed = TRUE;
389 TCHAR szThisOwner[ cchNAME ];
390 lstrcpy (szThisOwner, Properties.u.GroupProperties.szOwner);
391 AppendUID (szThisOwner, Properties.u.GroupProperties.uidOwner);
392 if (lstrcmpi (lpp->szOwner, szThisOwner))
393 lpp->fOwner_Mixed = TRUE;
395 TCHAR szThisCreator[ cchNAME ];
396 lstrcpy (szThisCreator, Properties.u.GroupProperties.szCreator);
397 AppendUID (szThisCreator, Properties.u.GroupProperties.uidCreator);
398 if (lstrcmpi (lpp->szCreator, szThisCreator))
399 lpp->fCreator_Mixed = TRUE;
403 // Fill in the dialog's controls
405 GroupProp_General_UpdateDialog_Perm (hDlg, IDC_GROUP_PERM_STATUS, lpp->aaStatus, lpp->fStatus_Mixed);
406 GroupProp_General_UpdateDialog_Perm (hDlg, IDC_GROUP_PERM_GROUPS, lpp->aaGroups, lpp->fGroups_Mixed);
407 GroupProp_General_UpdateDialog_Perm (hDlg, IDC_GROUP_PERM_MEMBERS, lpp->aaMembers, lpp->fMembers_Mixed);
408 GroupProp_General_UpdateDialog_Perm (hDlg, IDC_GROUP_PERM_ADD, lpp->aaAdd, lpp->fAdd_Mixed);
409 GroupProp_General_UpdateDialog_Perm (hDlg, IDC_GROUP_PERM_REMOVE, lpp->aaRemove, lpp->fRemove_Mixed);
411 if (lpp->fOwner_Mixed)
412 GetString (lpp->szOwner, IDS_OWNER_MIXED);
413 if (lpp->fCreator_Mixed)
414 GetString (lpp->szCreator, IDS_CREATOR_MIXED);
415 SetDlgItemText (hDlg, IDC_GROUP_OWNER, lpp->szOwner);
416 SetDlgItemText (hDlg, IDC_GROUP_CREATOR, lpp->szCreator);
420 void GroupProp_General_UpdateDialog_Perm (HWND hDlg, int idc, ACCOUNTACCESS aa, BOOL fMixed)
422 CB_StartChange (GetDlgItem (hDlg, idc), TRUE);
423 CB_AddItem (GetDlgItem (hDlg, idc), IDS_ACCOUNTACCESS_OWNGROUP, aaOWNER_ONLY);
424 if (idc != IDC_GROUP_PERM_GROUPS)
425 CB_AddItem (GetDlgItem (hDlg, idc), IDS_ACCOUNTACCESS_GROUP, aaGROUP_ONLY);
426 if (idc != IDC_GROUP_PERM_REMOVE)
427 CB_AddItem (GetDlgItem (hDlg, idc), IDS_ACCOUNTACCESS_ANYONE, aaANYONE);
429 CB_AddItem (GetDlgItem (hDlg, idc), IDS_ACCOUNTACCESS_MIXED, (LPARAM)-1);
430 CB_EndChange (GetDlgItem (hDlg, idc), TRUE);
432 LPARAM lpSelect = (fMixed) ? ((LPARAM)-1) : (LPARAM)aa;
433 CB_SetSelectedByData (GetDlgItem (hDlg, idc), lpSelect);
437 void GroupProp_General_OnApply (HWND hDlg)
439 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
441 lpp->fApplyGeneral = TRUE;
443 GetDlgItemText (hDlg, IDC_GROUP_OWNER, lpp->szOwner, cchNAME);
445 TCHAR szOwnerMixed[ cchNAME ];
446 GetString (szOwnerMixed, IDS_OWNER_MIXED);
447 if (!lstrcmpi (lpp->szOwner, szOwnerMixed))
449 lpp->szOwner[0] = TEXT('\0');
450 lpp->fOwner_Mixed = TRUE;
455 if ((pch = (LPTSTR)lstrchr (lpp->szOwner, TEXT(' '))) != NULL)
456 *pch = TEXT('\0'); // strip off any displayed UID
457 lpp->fOwner_Mixed = FALSE;
460 lpp->aaStatus = (ACCOUNTACCESS)CB_GetSelectedData (GetDlgItem (hDlg, IDC_GROUP_PERM_STATUS));
461 lpp->fStatus_Mixed = (lpp->aaStatus == (ACCOUNTACCESS)-1);
462 lpp->aaGroups = (ACCOUNTACCESS)CB_GetSelectedData (GetDlgItem (hDlg, IDC_GROUP_PERM_GROUPS));
463 lpp->fGroups_Mixed = (lpp->aaGroups == (ACCOUNTACCESS)-1);
464 lpp->aaMembers = (ACCOUNTACCESS)CB_GetSelectedData (GetDlgItem (hDlg, IDC_GROUP_PERM_MEMBERS));
465 lpp->fMembers_Mixed = (lpp->aaMembers == (ACCOUNTACCESS)-1);
466 lpp->aaAdd = (ACCOUNTACCESS)CB_GetSelectedData (GetDlgItem (hDlg, IDC_GROUP_PERM_ADD));
467 lpp->fAdd_Mixed = (lpp->aaAdd == (ACCOUNTACCESS)-1);
468 lpp->aaRemove = (ACCOUNTACCESS)CB_GetSelectedData (GetDlgItem (hDlg, IDC_GROUP_PERM_REMOVE));
469 lpp->fRemove_Mixed = (lpp->aaRemove == (ACCOUNTACCESS)-1);
473 void GroupProp_General_OnBrowse (HWND hDlg)
476 memset (&pp, 0x00, sizeof(pp));
478 pp.iddForHelp = IDD_BROWSE_OWNER;
479 pp.idsTitle = IDS_GROUP_CHANGEOWNER_TITLE;
480 pp.idsPrompt = IDS_GROUP_CHANGEOWNER_PROMPT;
482 pp.TypeToShow = (ASOBJTYPE)( (ULONG)TYPE_USER | (ULONG)TYPE_GROUP );
483 pp.fAllowMultiple = FALSE;
484 GetDlgItemText (hDlg, IDC_GROUP_OWNER, pp.szName, cchNAME);
486 TCHAR szOwnerMixed[ cchNAME ];
487 GetString (szOwnerMixed, IDS_OWNER_MIXED);
489 if (!lstrcmpi (pp.szName, szOwnerMixed))
490 pp.szName[0] = TEXT('\0');
491 else if ((pch = (LPTSTR)lstrchr (pp.szName, TEXT(' '))) != NULL)
494 if (ShowBrowseDialog (&pp))
496 TCHAR szName[ cchNAME ];
497 lstrcpy (szName, pp.szName);
499 if (pp.pObjectsSelected && (pp.pObjectsSelected->cEntries == 1))
502 ASOBJPROP Properties;
503 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pp.pObjectsSelected->aEntries[0].idObject, &Properties, &status))
505 if (Properties.Type == TYPE_USER)
506 AppendUID (szName, Properties.u.UserProperties.PTSINFO.uidName);
507 else if (Properties.Type == TYPE_GROUP)
508 AppendUID (szName, Properties.u.GroupProperties.uidName);
512 SetDlgItemText (hDlg, IDC_GROUP_OWNER, szName);
515 if (pp.pObjectsSelected)
516 asc_AsidListFree (&pp.pObjectsSelected);
520 BOOL CALLBACK GroupProp_Member_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
522 if (AfsAppLib_HandleHelp (IDD_GROUP_MEMBER, hDlg, msg, wp, lp))
528 GroupProp_Member_OnInitDialog (hDlg);
532 GroupProp_Member_OnDestroy (hDlg);
537 if ((ptp = (LPTASKPACKET)lp) != NULL)
539 if (ptp->idTask == taskGROUP_MEMBERS_GET)
540 GroupProp_Member_OnEndTask_GetMembers (hDlg, ptp);
541 else if (ptp->idTask == taskGROUP_OWNED_GET)
542 GroupProp_Member_OnEndTask_GetOwned (hDlg, ptp);
543 FreeTaskPacket (ptp);
551 GroupProp_Member_OnApply (hDlg);
554 case IDC_GROUP_SHOW_MEMBER:
555 case IDC_GROUP_SHOW_OWNER:
556 GroupProp_Member_OnShowType (hDlg);
560 GroupProp_Member_OnAdd (hDlg);
563 case IDC_MEMBER_REMOVE:
564 GroupProp_Member_OnRemove (hDlg);
570 switch (((LPNMHDR)lp)->code)
573 GroupProp_Member_OnSelect (hDlg);
582 void GroupProp_Member_OnInitDialog (HWND hDlg)
584 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
586 // If we've come in here with a valid set of groups to display,
587 // copy those. We'll need the copies if the user cancels the dialog.
589 SetWindowData (hDlg, GWD_ASIDLIST_MEMBER, (LPARAM)(lpp->pMembers));
590 SetWindowData (hDlg, GWD_ASIDLIST_OWNER, (LPARAM)(lpp->pGroupsOwner));
593 if ((pList = lpp->pMembers) != NULL)
594 asc_AsidListCopy (&lpp->pMembers, &pList);
595 if ((pList = lpp->pGroupsOwner) != NULL)
596 asc_AsidListCopy (&lpp->pGroupsOwner, &pList);
598 // If this prop sheet reflects more than one group, disable the
599 // Ownership button (we do this primarily because the Add/Remove
600 // buttons have no straight-forward semantic for that case).
601 // Actually, instead of disabling the thing, we'll hide the buttons
602 // entirely and resize the list/move the title.
604 if (lpp->pGroupList && (lpp->pGroupList->cEntries > 1))
606 ShowWindow (GetDlgItem (hDlg, IDC_GROUP_SHOW_MEMBER), SW_HIDE);
607 ShowWindow (GetDlgItem (hDlg, IDC_GROUP_SHOW_OWNER), SW_HIDE);
610 GetRectInParent (GetDlgItem (hDlg, IDC_GROUP_SHOW_MEMBER), &rButton);
613 GetRectInParent (GetDlgItem (hDlg, IDC_USERS_TITLE), &rTitle);
616 GetRectInParent (GetDlgItem (hDlg, IDC_USERS_LIST), &rList);
618 LONG cyDelta = rTitle.top - rButton.top;
620 SetWindowPos (GetDlgItem (hDlg, IDC_USERS_TITLE), NULL,
621 rTitle.left, rTitle.top-cyDelta,
622 rTitle.right-rTitle.left, rTitle.bottom-rTitle.top,
623 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
625 SetWindowPos (GetDlgItem (hDlg, IDC_USERS_LIST), NULL,
626 rList.left, rList.top-cyDelta,
627 rList.right-rList.left, rList.bottom-rList.top+cyDelta,
628 SWP_NOZORDER | SWP_NOACTIVATE);
631 // Apply an imagelist to the dialog's fastlist
633 FastList_SetImageLists (GetDlgItem (hDlg, IDC_USERS_LIST), AfsAppLib_CreateImageList (FALSE), NULL);
635 // Select a checkbox and pretend that the user clicked it; that will
636 // make the dialog automatically re-populate the list of groups
638 CheckDlgButton (hDlg, IDC_GROUP_SHOW_MEMBER, TRUE);
639 GroupProp_Member_OnShowType (hDlg);
643 void GroupProp_Member_OnDestroy (HWND hDlg)
645 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
648 if ((pList = (LPASIDLIST)GetWindowData (hDlg, GWD_ASIDLIST_MEMBER)) != NULL)
649 lpp->pMembers = pList;
650 if ((pList = (LPASIDLIST)GetWindowData (hDlg, GWD_ASIDLIST_OWNER)) != NULL)
651 lpp->pGroupsOwner = pList;
655 void GroupProp_Member_OnShowType (HWND hDlg)
657 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
659 // If we've already obtained the list of users we should be displaying,
662 if (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER))
666 GroupProp_Member_PopulateList (hDlg);
670 else // (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_OWNER))
672 if (lpp->pGroupsOwner)
674 GroupProp_Member_PopulateList (hDlg);
679 // Otherwise, we'll have to start a background task to do the querying.
680 // Change the text above the list to "Querying...", disable the buttons,
681 // and remove any items in the list
683 if (!lpp->pGroupList)
685 // Generate a few empty ASID list; this is a new group account we're
686 // displaying, and the caller hasn't yet added any members to it.
690 if (!asc_AsidListCreate (&lpp->pMembers))
693 if (!lpp->pGroupsOwner)
695 if (!asc_AsidListCreate (&lpp->pGroupsOwner))
698 GroupProp_Member_OnShowType (hDlg);
700 else // (lpp->pUserList)
702 TCHAR szTitle[ cchRESOURCE ];
703 GetString (szTitle, IDS_QUERYING_LONG);
704 SetDlgItemText (hDlg, IDC_USERS_TITLE, szTitle);
706 EnableWindow (GetDlgItem (hDlg, IDC_MEMBER_ADD), FALSE);
707 EnableWindow (GetDlgItem (hDlg, IDC_MEMBER_REMOVE), FALSE);
709 FastList_RemoveAll (GetDlgItem (hDlg, IDC_USERS_LIST));
711 // Then start a background task to grab an ASIDLIST of users which
712 // match the specified search criteria.
714 if (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER))
717 asc_AsidListCopy (&pGroups, &lpp->pGroupList);
718 StartTask (taskGROUP_MEMBERS_GET, hDlg, pGroups);
720 else // (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_OWNER))
722 StartTask (taskGROUP_OWNED_GET, hDlg, (PVOID)(lpp->pGroupList->aEntries[0].idObject));
728 void GroupProp_Member_OnEndTask_GetMembers (HWND hDlg, LPTASKPACKET ptp)
730 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
732 // The search is complete. If we've just obtained an ASIDLIST successfully,
733 // associate it with the dialog and repopulate the display.
735 if (ptp->rc && TASKDATA(ptp)->pAsidList)
739 asc_AsidListCopy (&lpp->pMembers, &TASKDATA(ptp)->pAsidList);
740 GroupProp_Member_PopulateList (hDlg);
746 void GroupProp_Member_OnEndTask_GetOwned (HWND hDlg, LPTASKPACKET ptp)
748 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
750 // The search is complete. If we've just obtained an ASIDLIST successfully,
751 // associate it with the dialog and repopulate the display.
753 if (ptp->rc && TASKDATA(ptp)->pAsidList)
755 if (!lpp->pGroupsOwner)
757 asc_AsidListCopy (&lpp->pGroupsOwner, &TASKDATA(ptp)->pAsidList);
758 GroupProp_Member_PopulateList (hDlg);
764 void GroupProp_Member_PopulateList (HWND hDlg)
766 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
768 // Clear the list of members/owned groups
770 HWND hList = GetDlgItem (hDlg, IDC_USERS_LIST);
771 FastList_Begin (hList);
772 FastList_RemoveAll (hList);
774 // We should have an ASIDLIST associated with the dialog to reflect
775 // which objects to display. Find it, and repopulate the list on
779 if (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER))
780 pDisplay = lpp->pMembers;
781 else // (!IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_OWNER))
782 pDisplay = lpp->pGroupsOwner;
786 TCHAR szMixed[ cchRESOURCE ];
787 GetString (szMixed, IDS_MEMBER_MIXED);
789 for (size_t ii = 0; ii < pDisplay->cEntries; ++ii)
792 ASOBJPROP Properties;
793 if (!asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pDisplay->aEntries[ ii ].idObject, &Properties, &status))
796 TCHAR szName[ cchNAME ];
797 if (Properties.Type == TYPE_USER)
798 User_GetDisplayName (szName, &Properties);
800 lstrcpy (szName, Properties.szName);
802 if (!pDisplay->aEntries[ ii ].lParam)
803 lstrcat (szName, szMixed);
805 FASTLISTADDITEM flai;
806 memset (&flai, 0x00, sizeof(flai));
807 flai.iFirstImage = (Properties.Type == TYPE_USER) ? imageUSER : imageGROUP;
808 flai.iSecondImage = IMAGE_NOIMAGE;
809 flai.pszText = szName;
810 flai.lParam = (LPARAM)(pDisplay->aEntries[ ii ].idObject);
811 FastList_AddItem (hList, &flai);
815 FastList_End (hList);
817 // Fix the buttons, and the text at the top of the list
819 TCHAR szTitle[ cchRESOURCE ];
820 if (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER))
821 GetString (szTitle, (!lpp->pGroupList) ? IDS_NEWGROUP_SHOW_MEMBER_TITLE : (lpp->pGroupList->cEntries == 1) ? IDS_GROUP_SHOW_MEMBER_TITLE : IDS_GROUP_SHOW_MEMBER_TITLE_MULTIPLE);
823 GetString (szTitle, (!lpp->pGroupList) ? IDS_NEWGROUP_SHOW_OWNED_TITLE : IDS_GROUP_SHOW_OWNED_TITLE);
825 SetDlgItemText (hDlg, IDC_USERS_TITLE, szTitle);
827 EnableWindow (GetDlgItem (hDlg, IDC_MEMBER_ADD), TRUE);
828 GroupProp_Member_OnSelect (hDlg);
832 void GroupProp_Member_OnSelect (HWND hDlg)
834 BOOL fEnable = IsWindowEnabled (GetDlgItem (hDlg, IDC_MEMBER_ADD));
835 if (fEnable && !FastList_FindFirstSelected (GetDlgItem (hDlg, IDC_USERS_LIST)))
837 EnableWindow (GetDlgItem (hDlg, IDC_MEMBER_REMOVE), fEnable);
841 void GroupProp_Member_OnAdd (HWND hDlg)
843 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
845 LPBROWSE_PARAMS pParams = New (BROWSE_PARAMS);
846 memset (pParams, 0x00, sizeof(BROWSE_PARAMS));
847 pParams->hParent = GetParent(hDlg);
848 pParams->iddForHelp = IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER) ? IDD_BROWSE_MEMBER : IDD_BROWSE_OWNED;
849 pParams->idsTitle = IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER) ? IDS_BROWSE_TITLE_MEMBER : IDS_BROWSE_TITLE_OWNED;
850 pParams->idsPrompt = IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER) ? IDS_BROWSE_PROMPT_MEMBER : IDS_BROWSE_PROMPT_OWNED;
851 pParams->idsCheck = IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER) ? IDS_BROWSE_CHECK_MEMBER : IDS_BROWSE_CHECK_OWNED;
852 pParams->fAllowMultiple = TRUE;
853 if (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER))
854 pParams->TypeToShow = (ASOBJTYPE)( (ULONG)TYPE_USER | (ULONG)TYPE_GROUP );
855 else // (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_OWNER))
856 pParams->TypeToShow = TYPE_GROUP;
858 // First prepare an ASIDLIST which reflects only the groups which
859 // all selected users own/are members in.
862 if (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER))
863 pDisplay = lpp->pMembers;
864 else // (!IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_OWNER))
865 pDisplay = lpp->pGroupsOwner;
869 asc_AsidListCreate (&pParams->pObjectsToSkip);
870 for (size_t ii = 0; ii < pDisplay->cEntries; ++ii)
872 if (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_OWNER) || pDisplay->aEntries[ ii ].lParam) // all groups have this member?
873 asc_AsidListAddEntry (&pParams->pObjectsToSkip, pDisplay->aEntries[ ii ].idObject, 0);
877 if (ShowBrowseDialog (pParams))
879 // The user added some entries; modify pDisplay (and the dialog,
880 // at the same time).
882 HWND hList = GetDlgItem (hDlg, IDC_USERS_LIST);
883 FastList_Begin (hList);
885 for (size_t ii = 0; ii < pParams->pObjectsSelected->cEntries; ++ii)
887 ASID idMember = pParams->pObjectsSelected->aEntries[ ii ].idObject;
889 // The user has chosen to add member {idMember}. If it's not in our
890 // list at all, add it (and a new entry for the display). If it
891 // *is* in our list, make sure its lParam is 1--indicating all users
892 // get it--and modify the display's entry to remove the "(some)"
896 if (!asc_AsidListTest (&pDisplay, idMember, &lParam))
899 ASOBJPROP Properties;
900 if (!asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, idMember, &Properties, &status))
903 asc_AsidListAddEntry (&pDisplay, idMember, TRUE);
905 FASTLISTADDITEM flai;
906 memset (&flai, 0x00, sizeof(flai));
907 flai.iFirstImage = (Properties.Type == TYPE_USER) ? imageUSER : imageGROUP;
908 flai.iSecondImage = IMAGE_NOIMAGE;
909 flai.pszText = Properties.szName;
910 flai.lParam = (LPARAM)idMember;
911 FastList_AddItem (hList, &flai);
912 PropSheetChanged (hDlg);
916 TCHAR szName[ cchNAME ];
917 if (!User_GetDisplayName (szName, idMember))
920 asc_AsidListSetEntryParam (&pDisplay, idMember, TRUE);
923 if ((hItem = FastList_FindItem (hList, (LPARAM)idMember)) != NULL)
924 FastList_SetItemText (hList, hItem, 0, szName);
925 PropSheetChanged (hDlg);
929 if (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER))
930 lpp->pMembers = pDisplay;
931 else // (!IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_OWNER))
932 lpp->pGroupsOwner = pDisplay;
934 FastList_End (hList);
937 if (pParams->pObjectsToSkip)
938 asc_AsidListFree (&pParams->pObjectsToSkip);
939 if (pParams->pObjectsSelected)
940 asc_AsidListFree (&pParams->pObjectsSelected);
945 void GroupProp_Member_OnRemove (HWND hDlg)
947 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
949 // Find which list-of-members is currently being displayed.
952 if (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER))
953 pDisplay = lpp->pMembers;
954 else // (!IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_OWNER))
955 pDisplay = lpp->pGroupsOwner;
957 // The user wants to remove some members/owned groups; modify pDisplay
958 // (and the dialog, at the same time).
960 HWND hList = GetDlgItem (hDlg, IDC_USERS_LIST);
961 FastList_Begin (hList);
964 while ((hItem = FastList_FindFirstSelected (hList)) != NULL)
966 ASID idMember = (ASID)FastList_GetItemParam (hList, hItem);
967 FastList_RemoveItem (hList, hItem);
968 asc_AsidListRemoveEntry (&pDisplay, idMember);
969 PropSheetChanged (hDlg);
972 if (IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_MEMBER))
973 lpp->pMembers = pDisplay;
974 else // (!IsDlgButtonChecked (hDlg, IDC_GROUP_SHOW_OWNER))
975 lpp->pGroupsOwner = pDisplay;
977 FastList_End (hList);
981 void GroupProp_Member_OnApply (HWND hDlg)
983 LPGROUPPROPINFO lpp = (LPGROUPPROPINFO)PropSheet_FindTabParam (hDlg);
985 // Free the old backup ASIDLIST copies we attached to the dialog during
986 // WM_INITDIALOG processing.
989 if ((pList = (LPASIDLIST)GetWindowData (hDlg, GWD_ASIDLIST_MEMBER)) != NULL)
990 asc_AsidListFree (&pList);
991 if ((pList = (LPASIDLIST)GetWindowData (hDlg, GWD_ASIDLIST_OWNER)) != NULL)
992 asc_AsidListFree (&pList);
993 SetWindowData (hDlg, GWD_ASIDLIST_MEMBER, 0);
994 SetWindowData (hDlg, GWD_ASIDLIST_OWNER, 0);
998 // Start a background task to update the member-list etc
1002 LPGROUP_MEMBERS_SET_PARAMS pTask = New (GROUP_MEMBERS_SET_PARAMS);
1003 memset (pTask, 0x00, sizeof(GROUP_MEMBERS_SET_PARAMS));
1004 asc_AsidListCopy (&pTask->pGroups, &lpp->pGroupList);
1005 asc_AsidListCopy (&pTask->pMembers, &lpp->pMembers);
1006 StartTask (taskGROUP_MEMBERS_SET, NULL, pTask);
1008 if (lpp->pGroupsOwner)
1010 LPGROUP_OWNED_SET_PARAMS pTask = New (GROUP_OWNED_SET_PARAMS);
1011 memset (pTask, 0x00, sizeof(GROUP_OWNED_SET_PARAMS));
1012 pTask->idGroup = lpp->pGroupList->aEntries[0].idObject;
1013 asc_AsidListCopy (&pTask->pOwnedGroups, &lpp->pGroupsOwner);
1014 StartTask (taskGROUP_OWNED_SET, NULL, pTask);