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"
21 #include "cell_prop.h"
25 #include "usr_create.h"
26 #include "usr_delete.h"
28 #include "grp_rename.h"
29 #include "grp_create.h"
30 #include "grp_delete.h"
31 #include "mch_create.h"
32 #include "mch_delete.h"
36 * PROTOTYPES _________________________________________________________________
40 void ShowContextMenu (POPUPMENU pm, HWND hList, LPASIDLIST pAsidList, POINT *pptScreen);
42 void Command_OnView (WORD wCmd);
43 void Command_OnShowActions (void);
44 void Command_OnRefresh (void);
45 void Command_OnUnlock (void);
46 void Command_OnProperties (void);
47 void Command_OnMembership (void);
48 void Command_OnChangePassword (void);
49 void Command_OnRename (void);
50 void Command_OnCreateUser (void);
51 void Command_OnCreateGroup (void);
52 void Command_OnCreateMachine (void);
53 void Command_OnDelete (void);
55 void Command_OnKey_CtrlTab (BOOL fForward);
56 void Command_OnKey_Tab (BOOL fForward);
57 void Command_OnKey_Return (void);
58 void Command_OnKey_Menu (void);
59 void Command_OnKey_Esc (void);
60 void Command_OnKey_Properties (void);
64 * POPUP-MENU SUPPORT _________________________________________________________
68 void OnRightClick (POPUPMENU pm, HWND hList, POINT *pptScreen)
72 // Which items are selected in the given list? (Note: if we're
73 // responding to a WM_CONTEXTMENU, then the act of clicking the
74 // mouse button has already changed the selection as appropriate.)
77 if ((pAsidList = Display_GetSelectedList()) != NULL)
79 if (pAsidList->cEntries == 0)
81 asc_AsidListFree (&pAsidList);
86 // If we don't have screen coordinates, the user must have clicked
87 // the Menu key on the keyboard. Pick the center of the first
88 // selected item's region (or the center of the list if none),
89 // and display the appropriate menu.
94 GetWindowRect (hList, &rWindow);
96 HLISTITEM hItemSelected = NULL;
98 hItemSelected = FastList_FindItem (hList, (LPARAM)(pAsidList->aEntries[0].idObject));
103 ptScreen.x = rWindow.left + (rWindow.right - rWindow.left)/2;
104 ptScreen.y = rWindow.top + (rWindow.bottom - rWindow.top)/2;
108 FASTLISTITEMREGIONS Reg;
109 FastList_GetItemRegions (hList, hItemSelected, &Reg);
110 ptScreen.x = rWindow.left + Reg.rLabel.left + (Reg.rLabel.right - Reg.rLabel.left)/2;
111 ptScreen.y = rWindow.top + Reg.rLabel.top + (Reg.rLabel.bottom - Reg.rLabel.top)/2;
112 ptScreen.x = min (max (ptScreen.x, rWindow.left), rWindow.right);
113 ptScreen.y = min (max (ptScreen.y, rWindow.top), rWindow.bottom);
116 ShowContextMenu (pm, hList, pAsidList, &ptScreen);
120 POINT ptClient = *pptScreen;
121 ScreenToClient (hList, &ptClient);
123 // Did the user click on the header bar for the list?
125 if (FL_HitTestForHeaderBar (hList, ptClient))
127 HMENU hm = TaLocale_LoadMenu (MENU_COLUMNS);
128 DisplayContextMenu (hm, *pptScreen, GetParent(hList));
132 ShowContextMenu (pm, hList, pAsidList, pptScreen);
137 asc_AsidListFree (&pAsidList);
142 void ShowContextMenu (POPUPMENU pm, HWND hList, LPASIDLIST pAsidList, POINT *pptScreen)
151 hm = TaLocale_LoadMenu (MENU_USER);
152 if (pAsidList->cEntries > 1)
153 EnableMenu (hm, M_CPW, FALSE);
157 hm = TaLocale_LoadMenu (MENU_USER_NONE);
158 Main_SetViewMenus (hm);
165 hm = TaLocale_LoadMenu (MENU_GROUP);
166 if (pAsidList->cEntries > 1)
167 EnableMenu (hm, M_RENAME, FALSE);
171 hm = TaLocale_LoadMenu (MENU_GROUP_NONE);
172 Main_SetViewMenus (hm);
179 hm = TaLocale_LoadMenu (MENU_MACHINE);
183 hm = TaLocale_LoadMenu (MENU_MACHINE_NONE);
184 Main_SetViewMenus (hm);
191 DisplayContextMenu (hm, *pptScreen, GetParent(hList));
197 * ROUTINES ___________________________________________________________________
201 void OnContextCommand (WORD wCmd)
208 (void)OpenCellDialog();
212 (void)NewCredsDialog();
225 Command_OnView (wCmd);
229 Command_OnShowActions();
233 ShowColumnsDialog (g.hMain);
237 ShowOptionsDialog (g.hMain);
241 Command_OnCreateUser();
245 Command_OnCreateGroup();
248 case M_MACHINE_CREATE:
249 Command_OnCreateMachine();
261 Command_OnChangePassword();
273 Command_OnMembership();
281 Command_OnProperties();
284 case M_CELL_PROPERTIES:
285 Cell_ShowProperties();
289 StartTask (taskREFRESH, NULL, (PVOID)g.idCell);
293 WinHelp (g.hMain, cszHELPFILENAME, HELP_FINDER, 0);
308 // Keyboard handlers (we use accelerator table entries to catch
309 // tab/return/esc/etc, and mimic a normal dialog box's behavior)
312 Command_OnKey_Return();
316 Command_OnKey_CtrlTab (TRUE);
319 case M_KEY_CTRLBACKTAB:
320 Command_OnKey_CtrlTab (FALSE);
324 Command_OnKey_Tab (TRUE);
328 Command_OnKey_Tab (FALSE);
332 Command_OnKey_Menu();
339 case M_KEY_PROPERTIES:
340 Command_OnKey_Properties();
347 * COMMAND HANDLERS _______________________________________________________________________________
351 void Command_OnView (WORD wCmd)
353 // Which tab is currently being displayed?
355 HWND hTab = GetDlgItem (g.hMain, IDC_TAB);
356 int iTab = TabCtrl_GetCurSel (hTab);
358 // Find the appropriate current view settings for this tab
360 LPVIEWINFO pvi = (iTab == 0) ? &gr.viewUsr : (iTab == 1) ? &gr.viewGrp : &gr.viewMch;
361 ICONVIEW iv = (iTab == 0) ? gr.ivUsr : (iTab == 1) ? gr.ivGrp : gr.ivMch;
363 // ...and prepare modified versions of them
365 VIEWINFO viNew = *pvi;
371 viNew.lvsView = (viNew.lvsView & (~FLS_VIEW_MASK)) | FLS_VIEW_LARGE;
374 viNew.lvsView = (viNew.lvsView & (~FLS_VIEW_MASK)) | FLS_VIEW_SMALL;
377 viNew.lvsView = (viNew.lvsView & (~FLS_VIEW_MASK)) | FLS_VIEW_LIST;
390 if ((viNew.lvsView & FLS_VIEW_MASK) != FLS_VIEW_LIST)
392 viNew.iSort = 0; // sort alphabetically by name
395 // Apply the changes, and update the main window's menu items
397 Display_RefreshView (&viNew, ivNew);
402 void Command_OnShowActions (void)
404 if ((gr.fShowActions = !gr.fShowActions) == TRUE)
405 Actions_OpenWindow();
407 Actions_CloseWindow();
412 void Command_OnRefresh (void)
414 LPASIDLIST pAsidList;
415 if ((pAsidList = Display_GetSelectedList()) != NULL)
417 StartTask (taskREFRESHMULT, NULL, pAsidList);
422 void Command_OnUnlock (void)
424 LPASIDLIST pAsidList;
425 if ((pAsidList = Display_GetSelectedList()) != NULL)
427 StartTask (taskUSER_UNLOCK, NULL, pAsidList);
432 void Command_OnProperties (void)
434 LPASIDLIST pAsidList;
435 if ((pAsidList = Display_GetSelectedList()) != NULL)
437 // See what kind of objects are selected
439 BOOL fAnyUsers = FALSE;
440 BOOL fAnyGroups = FALSE;
442 for (size_t ii = 0; ii < pAsidList->cEntries; ++ii)
445 if (!asc_ObjectTypeGet_Fast (g.idClient, g.idCell, pAsidList->aEntries[ ii ].idObject, &Type))
458 // If they're homogenous, display the appropriate properties dialog
460 if (fAnyUsers && !fAnyGroups)
461 User_ShowProperties (pAsidList);
462 else if (fAnyGroups && !fAnyUsers)
463 Group_ShowProperties (pAsidList);
465 asc_AsidListFree (&pAsidList);
470 void Command_OnMembership (void)
472 LPASIDLIST pAsidList;
473 if ((pAsidList = Display_GetSelectedList()) != NULL)
475 // See what kind of objects are selected
477 BOOL fAnyUsers = FALSE;
478 BOOL fAnyGroups = FALSE;
480 for (size_t ii = 0; ii < pAsidList->cEntries; ++ii)
483 if (!asc_ObjectTypeGet_Fast (g.idClient, g.idCell, pAsidList->aEntries[ ii ].idObject, &Type))
496 // If they're homogenous, display the appropriate membership dialog
498 if (fAnyUsers && !fAnyGroups)
499 User_ShowProperties (pAsidList, uptMEMBERSHIP);
500 else if (fAnyGroups && !fAnyUsers)
501 Group_ShowProperties (pAsidList, gptMEMBERS);
503 asc_AsidListFree (&pAsidList);
508 void Command_OnChangePassword (void)
510 LPASIDLIST pAsidList;
511 if ((pAsidList = Display_GetSelectedList()) != NULL)
513 if (pAsidList->cEntries == 1)
516 if (asc_ObjectTypeGet_Fast (g.idClient, g.idCell, pAsidList->aEntries[0].idObject, &Type))
518 if (Type == TYPE_USER)
519 User_ShowChangePassword (g.hMain, pAsidList->aEntries[0].idObject);
526 void Command_OnRename (void)
528 LPASIDLIST pAsidList;
529 if ((pAsidList = Display_GetSelectedList()) != NULL)
531 if (pAsidList->cEntries == 1)
534 if (asc_ObjectTypeGet_Fast (g.idClient, g.idCell, pAsidList->aEntries[0].idObject, &Type))
536 if (Type == TYPE_GROUP)
537 Group_ShowRename (g.hMain, pAsidList->aEntries[0].idObject);
544 void Command_OnCreateUser (void)
546 User_ShowCreate (g.hMain);
550 void Command_OnCreateGroup (void)
552 Group_ShowCreate (g.hMain);
556 void Command_OnCreateMachine (void)
558 Machine_ShowCreate (g.hMain);
562 void Command_OnDelete (void)
564 LPASIDLIST pAsidList;
565 if ((pAsidList = Display_GetSelectedList()) != NULL)
567 // See what kind of objects are selected
569 BOOL fAnyUsers = FALSE;
570 BOOL fAnyGroups = FALSE;
571 BOOL fAnyMachines = FALSE;
573 for (size_t ii = 0; ii < pAsidList->cEntries; ++ii)
576 if (!asc_ObjectTypeGet_Fast (g.idClient, g.idCell, pAsidList->aEntries[ ii ].idObject, &Type))
581 if (fIsMachineAccount (pAsidList->aEntries[ ii ].idObject))
592 // If they're homogenous, display a matching delete confirmation dialog
594 if (fAnyUsers && !fAnyGroups && !fAnyMachines)
595 User_ShowDelete (pAsidList);
596 else if (fAnyGroups && !fAnyUsers && !fAnyMachines)
597 Group_ShowDelete (pAsidList);
598 else if (fAnyMachines && !fAnyUsers && !fAnyGroups)
599 Machine_ShowDelete (pAsidList);
601 asc_AsidListFree (&pAsidList);
607 * KEYBOARD HANDLERS ______________________________________________________________________________
611 void Command_OnKey_Tab (BOOL fForward)
613 // The tab-cycle should go:
614 // TabControl <-> TabChildControls
616 HWND hFocus = GetFocus();
617 HWND hTabChild = GetTabChild (GetDlgItem (g.hMain, IDC_TAB));
621 if (hFocus == GetDlgItem (g.hMain, IDC_TAB))
623 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, NULL, FALSE), TRUE);
627 if (GetNextDlgTabItem (hTabChild, hFocus, FALSE) == GetNextDlgTabItem (hTabChild, NULL, FALSE))
628 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (g.hMain, IDC_TAB), TRUE);
630 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, hFocus, FALSE), TRUE);
635 if (hFocus == GetDlgItem (g.hMain, IDC_TAB))
637 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetLastDlgTabItem (hTabChild), TRUE);
641 if (hFocus == GetNextDlgTabItem (hTabChild, NULL, FALSE))
642 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (g.hMain, IDC_TAB), TRUE);
644 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, hFocus, TRUE), TRUE);
650 void Command_OnKey_CtrlTab (BOOL fForward)
652 HWND hTabs = GetDlgItem (g.hMain, IDC_TAB);
653 size_t iTab = TabCtrl_GetCurSel (hTabs);
654 size_t cTabs = TabCtrl_GetItemCount (hTabs);
657 iTab = (iTab == cTabs-1) ? (0) : (iTab+1);
659 iTab = (iTab == 0) ? (cTabs-1) : (iTab-1);
661 Main_PrepareTabChild (iTab);
663 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)hTabs, TRUE);
667 void Command_OnKey_Return (void)
670 hdr.hwndFrom = GetFocus();
671 hdr.idFrom = GetWindowLong (GetFocus(), GWL_ID);
672 hdr.code = FLN_LDBLCLICK;
673 PostMessage (GetParent (GetFocus()), WM_NOTIFY, 0, (LPARAM)&hdr);
677 void Command_OnKey_Menu (void)
679 HWND hFocus = GetFocus();
680 if (fIsFastList (hFocus))
682 // Is the user or group tab showing?
684 HWND hDlg = GetTabChild (GetDlgItem (g.hMain, IDC_TAB));
685 HWND hList = GetDlgItem (hDlg, IDC_GROUPS_LIST);
686 POPUPMENU pm = pmGROUP;
687 if (!IsWindow (hList))
689 hList = GetDlgItem (hDlg, IDC_USERS_LIST);
692 if (!IsWindow (hList))
694 hList = GetDlgItem (hDlg, IDC_MACHINES_LIST);
698 if (IsWindow (hList))
700 // Pretend the user right-clicked
702 OnRightClick (pm, hList);
708 void Command_OnKey_Esc (void)
710 HWND hFocus = GetFocus();
711 if (fIsFastList (hFocus))
713 FastList_SelectNone (hFocus);
718 void Command_OnKey_Properties (void)
720 OnContextCommand (M_PROPERTIES);