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"
27 * TABS _______________________________________________________________________
38 { ttUSERS, imageUSER, IDS_TAB_USERS, IDD_TAB_USERS, (DLGPROC)Users_DlgProc },
39 { ttGROUPS, imageGROUP, IDS_TAB_GROUPS, IDD_TAB_GROUPS, (DLGPROC)Groups_DlgProc },
40 { ttMACHINES, imageSERVER, IDS_TAB_MACHINES, IDD_TAB_MACHINES, (DLGPROC)Machines_DlgProc },
43 static size_t cTABS = sizeof(aTABS) / sizeof(aTABS[0]);
47 * DEFINITIONS ________________________________________________________________
51 #define cxMIN_TABS 150
52 #define cyMIN_TABS 100
54 rwWindowData awdMain[] = {
55 { IDC_TAB, raSizeX | raSizeY, MAKELONG(cxMIN_TABS,cyMIN_TABS), 0 },
56 { IDC_CELL, raSizeX | raRepaint, 0, 0 },
57 { IDC_CREDS, raSizeX | raRepaint, 0, 0 },
58 { IDC_ANIM, raMoveX, 0, 0 },
59 { IDC_BAR, raSizeX, 0, 0 },
60 { IDC_STATIC, raRepaint, 0, 0 },
61 { idENDLIST, 0, 0, 0 }
64 rwWindowData awdTabChild[] = {
65 { 0, raSizeX | raSizeY, 0, 0 },
66 { idENDLIST, 0, 0, 0 }
71 * PROTOTYPES _________________________________________________________________
75 void Main_OnInitDialog (HWND hDlg);
76 LRESULT CALLBACK Main_TabHookProc (HWND hTab, UINT msg, WPARAM wp, LPARAM lp);
80 * ROUTINES ___________________________________________________________________
84 BOOL CALLBACK Main_DialogProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
86 if (msg == WM_INITDIALOG)
89 AfsAppLib_SetMainWindow (g.hMain);
95 Main_OnInitDialog (hDlg);
98 case WM_SHOW_YOURSELF:
101 ShowWindow (g.hMain, SW_SHOW);
102 SetForegroundWindow (g.hMain);
103 Actions_WindowToTop (TRUE);
107 case WM_SHOW_ACTIONS:
109 Actions_OpenWindow();
113 Actions_WindowToTop ((wp) ? TRUE : FALSE);
115 StartTask (taskEXPIRED_CREDS);
118 case WM_EXPIRED_CREDENTIALS:
119 case WM_REFRESHED_CREDENTIALS:
120 g.hCreds = (PVOID)lp;
121 StartTask (taskUPD_CREDS);
125 // if (lp==0), we're minimizing--don't call ResizeWindow().
128 ResizeWindow (hDlg, awdMain, rwaFixupGuts);
133 if ((ptp = (LPTASKPACKET)lp) != NULL)
135 if (ptp->idTask == taskUPD_USERS)
136 Display_OnEndTask_UpdUsers (ptp);
137 else if (ptp->idTask == taskUPD_GROUPS)
138 Display_OnEndTask_UpdGroups (ptp);
139 else if (ptp->idTask == taskUPD_MACHINES)
140 Display_OnEndTask_UpdMachines (ptp);
141 FreeTaskPacket (ptp);
145 case WM_ASC_NOTIFY_ACTION:
146 Actions_OnNotify (wp, lp);
157 OnContextCommand (LOWORD(wp));
163 switch (((LPNMHDR)lp)->code)
166 Main_PrepareTabChild();
172 if ((lp == 0) || (IsAncestor (g.hMain, (HWND)(((LPHELPINFO)lp)->hItemHandle))))
174 WinHelp (hDlg, cszHELPFILENAME, HELP_FINDER, 0);
183 void Main_OnInitDialog (HWND hDlg)
185 // Resize and reposition the main window
187 RECT rWindow = gr.rMain;
189 GetWindowRect (hDlg, &rWindow);
190 ResizeWindow (hDlg, awdMain, rwaMoveToHere, &rWindow);
192 // Add tabs to the main window's tab control
194 HWND hTab = GetDlgItem (hDlg, IDC_TAB);
195 TabCtrl_SetImageList (hTab, AfsAppLib_CreateImageList (FALSE));
197 TCHAR szText[ cchRESOURCE ];
199 tci.mask = TCIF_TEXT | TCIF_PARAM | TCIF_IMAGE;
200 tci.pszText = szText;
202 for (size_t iTab = 0; iTab < cTABS; ++iTab)
204 tci.iImage = aTABS[ iTab ].idiImage;
205 tci.lParam = (LPARAM)aTABS[ iTab ].tt;
206 GetString (tci.pszText, aTABS[ iTab ].idsText);
207 TabCtrl_InsertItem (hTab, iTab, &tci);
210 // Subclass the tab control, so that we can make it forward any WM_SIZE
211 // messages to its child window.
213 Subclass_AddHook (hTab, Main_TabHookProc);
215 // Since we just subclassed this control, our new wndproc wasn't around
216 // when the window was created. Any WM_CREATE processing we'd ordinarily
217 // in that wndproc must therefore be done here.
221 GetRectInParent (hTab, &rTab);
222 ResizeWindow (hTab, awdTabChild, rwaMoveToHere, &rTab);
224 // Select an appropriate tab and display it.
226 Main_PrepareTabChild (gr.iTabLast);
228 // Tell the admin client that we're interested in any actions that occur
231 asc_ActionListen (g.idClient, g.hMain, &status);
235 LRESULT CALLBACK Main_TabHookProc (HWND hTab, UINT msg, WPARAM wp, LPARAM lp)
237 LRESULT rc = CallWindowProc ((WNDPROC)Subclass_FindNextHook (hTab, Main_TabHookProc), hTab, msg, wp, lp);
241 // Since this is a subclass proc, it's not around when the window
242 // is created. Any WM_CREATE processing we'd ordinarily do here
243 // must therefore be done at the point where the tab control is
250 ResizeWindow (hTab, awdTabChild, rwaFixupGuts);
254 Subclass_RemoveHook (hTab, Main_TabHookProc);
262 void Main_PrepareTabChild (int iTabNew)
264 HWND hTab = GetDlgItem (g.hMain, IDC_TAB);
265 int iTabOld = TabCtrl_GetCurSel (hTab);
270 if ((hDlg = GetTabChild (hTab)) != NULL)
271 DestroyWindow (hDlg);
272 if ((hDlg = ModelessDialog (aTABS[ iTabNew ].iddChild, hTab, aTABS[ iTabNew ].procChild)) != NULL)
274 if (iTabNew != iTabOld)
275 TabCtrl_SetCurSel (hTab, iTabNew);
276 ShowWindow (hDlg, SW_SHOW);
279 // Remember this tab as the last one the user saw, so that if the app gets
280 // closed we can re-open it to the same tab.
282 gr.iTabLast = iTabNew;
284 // Check/uncheck/enable/disable our dialog's menu items as appropriate.
285 // We do this whenever the current tab changes, because some of the
286 // menu items will change state depending on which tab is visible.
292 void Main_SetMenus (void)
294 HMENU hm = GetMenu (g.hMain);
295 LPASIDLIST pSel = Display_GetSelectedList();
297 Main_SetViewMenus (hm);
299 // Fix the Operations In Progress entry
301 CheckMenu (hm, M_ACTIONS, gr.fShowActions);
303 // Fix the CellProperties and Edit.* menu items. Many get disabled if there
306 BOOL fEnable = (pSel && pSel->cEntries) ? TRUE : FALSE;
307 EnableMenu (hm, M_DELETE, fEnable);
308 EnableMenu (hm, M_REFRESH, fEnable);
309 EnableMenu (hm, M_MEMBERSHIP, fEnable);
310 EnableMenu (hm, M_PROPERTIES, fEnable);
312 if ((fEnable = (pSel && (pSel->cEntries == 1))) == TRUE)
314 // Make sure it's a group
316 if (!asc_ObjectTypeGet_Fast (g.idClient, g.idCell, pSel->aEntries[0].idObject, &Type))
318 else if (Type != TYPE_GROUP)
322 EnableMenu (hm, M_RENAME, fEnable);
325 asc_AsidListFree (&pSel);
329 void Main_SetViewMenus (HMENU hm)
331 // Which tab is currently being displayed?
333 HWND hTab = GetDlgItem (g.hMain, IDC_TAB);
334 int iTab = TabCtrl_GetCurSel (hTab);
335 TABTYPE tt = aTABS[ iTab ].tt;
337 // Fix the Icons.Large/Small/Details entries
339 LPVIEWINFO pvi = (tt == ttUSERS) ? &gr.viewUsr : (tt == ttMACHINES) ? &gr.viewMch : &gr.viewGrp;
340 ICONVIEW iv = (tt == ttUSERS) ? gr.ivUsr : (tt == ttMACHINES) ? gr.ivMch : gr.ivGrp;
342 int idm = ((pvi->lvsView & FLS_VIEW_MASK) == FLS_VIEW_LARGE) ? M_VIEW_LARGE : ((pvi->lvsView & FLS_VIEW_MASK) == FLS_VIEW_SMALL) ? M_VIEW_SMALL : M_VIEW_DETAILS;
343 CheckMenuRadioItem (hm, M_VIEW_LARGE, M_VIEW_DETAILS, idm, MF_BYCOMMAND);
345 // Fix the Icons.One/Two/Status entries
347 BOOL fEnable = ((pvi->lvsView & FLS_VIEW_MASK) == FLS_VIEW_LIST) ? TRUE : FALSE;
348 EnableMenu (hm, M_VIEW_ONE, fEnable);
349 EnableMenu (hm, M_VIEW_TWO, fEnable);
350 EnableMenu (hm, M_VIEW_STATUS, fEnable);
352 idm = (iv == ivTWOICONS) ? M_VIEW_TWO : (iv == ivONEICON) ? M_VIEW_ONE : M_VIEW_STATUS;
353 CheckMenuRadioItem (hm, M_VIEW_ONE, M_VIEW_STATUS, idm, MF_BYCOMMAND);