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>
16 #include "svr_window.h"
17 #include "propcache.h"
26 * RESIZING WINDOWS ___________________________________________________________
30 #define cxMIN_SERVER 100
31 #define cyMIN_SERVER 100
33 static rwWindowData awdServer[] = {
34 { IDC_TABS, raSizeX | raSizeY, MAKELONG(cxMIN_SERVER,cyMIN_SERVER), 0 },
35 { idENDLIST, 0, 0, 0 }
38 static rwWindowData awdTabChild[] = {
39 { 0, raSizeX | raSizeY, 0, 0 },
40 { idENDLIST, 0, 0, 0 }
45 * CHILD TABS _________________________________________________________________
49 static struct // CHILDTABINFO
57 { tabFILESETS, IDS_TAB_FILESETS, imageFILESET },
58 { tabAGGREGATES, IDS_TAB_AGGREGATES, imageAGGREGATE },
59 { tabSERVICES, IDS_TAB_SERVICES, imageSERVICE },
62 #define nCHILDTABS (sizeof(CHILDTABINFO)/sizeof(CHILDTABINFO[0]))
67 * PROTOTYPES _________________________________________________________________
71 BOOL CALLBACK Server_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
73 void Server_SaveRect (HWND hDlg, BOOL fOpen);
75 BOOL Server_HandleDialogKeys (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
79 * ROUTINES ___________________________________________________________________
83 void Server_Open (LPIDENT lpiServer, LPRECT prWindow)
87 if ((hServer = PropCache_Search (pcSERVER, lpiServer)) != NULL)
93 // First off, if this server isn't being monitored, we have
94 // to start monitoring it or we can't open a window (nothing to
98 if ((lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) != NULL)
100 BOOL fCanShowWindow = (gr.fOpenMonitors || lpsp->fIsMonitored);
102 if (gr.fOpenMonitors && !lpsp->fIsMonitored)
104 StartTask (taskSVR_MONITOR_ONOFF, NULL, lpiServer);
109 hServer = ModelessDialogParam (IDD_SERVER, NULL, (DLGPROC)Server_DlgProc, (LPARAM)lpiServer);
110 Server_SelectServer (hServer, lpiServer);
112 if (prWindow->right != 0)
114 SetWindowPos (hServer, NULL, prWindow->left, prWindow->top,
115 cxRECT(*prWindow), cyRECT(*prWindow),
116 SWP_NOZORDER | SWP_NOACTIVATE);
119 ShowWindow (hServer, SW_NORMAL);
126 void Server_Close (LPIDENT lpiServer)
130 if ((hWnd = PropCache_Search (pcSERVER, lpiServer)) != NULL)
132 Server_SaveRect (hWnd, FALSE);
133 DestroyWindow (hWnd);
135 // If there's a subset active, the user may want us to stop
136 // monitoring this server once its window is closed.
139 if ((lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) != NULL)
141 if (g.sub && gr.fCloseUnmonitors && lpsp->fIsMonitored && !gr.fPreview)
143 StartTask (taskSVR_MONITOR_ONOFF, NULL, lpiServer);
150 void Server_CloseAll (BOOL fUserRequested)
154 while ((hWnd = PropCache_Search (pcSERVER, ANYVALUE)) != NULL)
156 LPIDENT lpiServer = Server_GetServer (hWnd);
158 Server_SaveRect (hWnd, !fUserRequested);
159 DestroyWindow (hWnd);
161 if (lpiServer && fUserRequested)
163 // If there's a subset active, the user may want us to stop
164 // monitoring this server once its window is closed.
167 if ((lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) != NULL)
169 if (g.sub && gr.fCloseUnmonitors && lpsp->fIsMonitored)
171 StartTask (taskSVR_MONITOR_ONOFF, NULL, lpiServer);
179 HWND Server_GetCurrentTab (HWND hWnd)
181 return GetTabChild (GetDlgItem (hWnd, IDC_TABS));
184 CHILDTAB Server_GetDisplayedTab (HWND hWnd)
186 HWND hTabs = GetDlgItem (hWnd, IDC_TABS);
187 return (hTabs) ? (CHILDTAB)TabCtrl_GetCurSel(hTabs) : tabINVALID;
190 HWND Server_GetWindowForChild (HWND hChild)
192 // hChild is the Filesets_DlgProc dialog (or whatever)
193 // Its parent is the tab control on the server window
194 // Its grandparent is the Popup HWND (may be g.hMain) that we want.
196 return GetParent (GetParent (hChild));
199 void Server_SelectServer (HWND hDlg, LPIDENT lpiNew, BOOL fForceRedraw)
201 LPIDENT lpiOld = Server_GetServer (hDlg);
202 if (lpiNew != lpiOld)
204 SetWindowLong (hDlg, DWL_USER, (LONG)lpiNew);
209 PropCache_Delete (pcSERVER, lpiOld);
213 PropCache_Add (pcSERVER, lpiNew, hDlg);
215 TCHAR szName[ cchNAME ];
216 lpiNew->GetServerName (szName);
217 LPTSTR pszTitle = FormatString (IDS_SERVER_TITLE, TEXT("%s"), szName);
218 SetWindowText (hDlg, pszTitle);
219 FreeString (pszTitle);
228 Server_ForceRedraw (hDlg);
232 LPIDENT Server_GetServer (HWND hDlg)
234 return (LPIDENT)GetWindowLong (hDlg, DWL_USER);
237 LPIDENT Server_GetServerForChild (HWND hChild)
239 if (GetParent(hChild) == NULL)
240 return Server_GetServer (hChild);
242 return Server_GetServer (GetParent(GetParent(hChild)));
246 void Server_ForceRedraw (HWND hDlg)
248 HWND hChild = Server_GetCurrentTab (hDlg);
250 if (hChild && IsWindow (hChild))
252 PostMessage (hChild, WM_SERVER_CHANGED, 0, 0);
258 * SERVER DIALOG ______________________________________________________________
262 BOOL CALLBACK Server_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
264 LPIDENT lpiServer = Server_GetServer (hDlg);
266 if (Server_HandleDialogKeys (hDlg, msg, wp, lp))
273 Server_PrepareTabControl (GetDlgItem (hDlg, IDC_TABS));
274 GetWindowRect (hDlg, &rWindow);
275 ResizeWindow (hDlg, awdServer, rwaMoveToHere, &rWindow);
279 WinHelp (hDlg, cszHELPFILENAME, HELP_FINDER, 0);
283 GetWindowRect (hDlg, &gr.rServerLast);
286 PropCache_Delete (pcSERVER, lpiServer);
290 // if (lp==0), we're minimizing--don't call ResizeWindow().
294 ResizeWindow (hDlg, awdServer, rwaFixupGuts);
295 Server_SaveRect (hDlg, TRUE);
300 Server_SaveRect (hDlg, TRUE);
304 gr.tabLast = Server_GetDisplayedTab (hDlg);
312 if ((lpi = Server_GetServer (hDlg)) != NULL)
315 DestroyWindow (hDlg);
321 switch (((LPNMHDR)lp)->code)
325 HWND hTab = GetDlgItem (hDlg, IDC_TABS);
326 int iPage = TabCtrl_GetCurSel (hTab);
328 Server_DisplayTab (hDlg, (CHILDTAB)iPage);
329 gr.tabLast = (CHILDTAB)iPage;
340 static LONG procTabControl = 0;
342 LRESULT CALLBACK Server_SubclassTabControlProc (HWND hTab, UINT msg, WPARAM wp, LPARAM lp)
346 if (procTabControl == 0)
347 rc = DefWindowProc (hTab, msg, wp, lp);
349 rc = CallWindowProc ((WNDPROC)procTabControl, hTab, msg, wp, lp);
353 // Since this is a subclass proc, it's not around when the window
354 // is created. Any WM_CREATE processing we'd ordinarily do here
355 // must therefore be done at the point where the tab control is
362 ResizeWindow (hTab, awdTabChild, rwaFixupGuts);
366 if (procTabControl != 0)
367 SetWindowLong (hTab, GWL_WNDPROC, procTabControl);
375 void Server_PrepareTabControl (HWND hTab)
377 TabCtrl_SetImageList (hTab, AfsAppLib_CreateImageList (FALSE));
379 TCHAR szText[ cchRESOURCE ];
381 tci.mask = TCIF_TEXT | TCIF_PARAM | TCIF_IMAGE;
382 tci.pszText = szText;
384 for (int iTab = 0; iTab < nCHILDTABS; ++iTab)
386 tci.iImage = CHILDTABINFO[ iTab ].iImage;
387 tci.lParam = (LPARAM)CHILDTABINFO[ iTab ].tab;
388 GetString (tci.pszText, CHILDTABINFO[ iTab ].idsTabTitle);
389 TabCtrl_InsertItem (hTab, iTab, &tci);
392 // subclass the TCN_ window, so that it will start sending WM_SIZE
393 // messages to its child window.
395 procTabControl = GetWindowLong (hTab, GWL_WNDPROC);
396 SetWindowLong (hTab, GWL_WNDPROC, (LONG)Server_SubclassTabControlProc);
398 // Since we just subclassed this control, our new wndproc wasn't around
399 // when the window was created. Any WM_CREATE processing we'd ordinarily
400 // in that wndproc must therefore be done here.
404 GetRectInParent (hTab, &rWindow);
405 ResizeWindow (hTab, awdTabChild, rwaMoveToHere, &rWindow);
407 // Finally, select an appropriate tab and display it.
409 Server_DisplayTab (GetParent (hTab), gr.tabLast);
413 void Server_DisplayTab (HWND hDlg, CHILDTAB iTab)
415 HWND hTab = GetDlgItem (hDlg, IDC_TABS);
417 DLGPROC dlgproc = NULL;
423 dlgproc = (DLGPROC)Services_DlgProc;
426 idd = IDD_AGGREGATES;
427 dlgproc = (DLGPROC)Aggregates_DlgProc;
431 dlgproc = (DLGPROC)Filesets_DlgProc;
437 HWND hDialogOld = GetTabChild (hTab);
438 HWND hDialogNew = ModelessDialog (idd, hTab, dlgproc);
440 if (hDialogNew != NULL)
442 TabCtrl_SetCurSel (hTab, iTab);
443 ShowWindow (hDialogNew, SW_SHOW);
445 if (hDialogOld != NULL)
447 DestroyWindow (hDialogOld);
450 Server_ForceRedraw (hDlg);
456 void Server_Uncover (HWND hWnd)
458 if (hWnd == g.hMain) // uncover the preview pane?
460 AfsAppLib_Uncover (GetDlgItem (g.hMain, IDC_TABS));
462 else // uncover a standalone server window?
464 AfsAppLib_Uncover (hWnd);
469 void Server_SaveRect (HWND hDlg, BOOL fOpen)
471 LPSVR_SETWINDOWPOS_PARAMS lpp = New (SVR_SETWINDOWPOS_PARAMS);
472 GetWindowRect (hDlg, &lpp->rWindow);
473 lpp->lpi = Server_GetServer (hDlg);
476 StartTask (taskSVR_SETWINDOWPOS, NULL, lpp);
480 BOOL Server_HandleDialogKeys (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
482 if (msg == WM_COMMAND)
487 Server_OnKey_Return();
491 Server_OnKey_CtrlTab (hDlg, TRUE);
494 case M_KEY_CTRLBACKTAB:
495 Server_OnKey_CtrlTab (hDlg, FALSE);
499 Server_OnKey_Tab (hDlg, TRUE);
503 Server_OnKey_Tab (hDlg, FALSE);
514 case M_KEY_PROPERTIES:
515 Server_OnKey_Properties();
524 void Server_OnKey_Return (void)
527 hdr.hwndFrom = GetFocus();
528 hdr.idFrom = GetWindowLong (GetFocus(), GWL_ID);
529 hdr.code = FLN_LDBLCLICK;
530 PostMessage (GetParent (GetFocus()), WM_NOTIFY, 0, (LPARAM)&hdr);
534 void Server_OnKey_Menu (void)
536 HWND hFocus = GetFocus();
537 if (fIsFastList (hFocus))
539 POINT ptScreen = { 0, 0 };
542 if ((hItem = FastList_FindFirstSelected (hFocus)) != NULL)
544 FASTLISTITEMREGIONS reg;
545 FastList_GetItemRegions (hFocus, hItem, ®);
547 ptScreen.x = reg.rItem.left + (reg.rItem.right -reg.rItem.left) /2;
548 ptScreen.y = reg.rItem.top + (reg.rItem.bottom -reg.rItem.top) /2;
549 ClientToScreen (GetFocus(), &ptScreen);
552 PostMessage (GetParent (GetFocus()), WM_CONTEXTMENU, (WPARAM)GetFocus(), MAKELONG(ptScreen.x,ptScreen.y));
557 void Server_OnKey_Esc (void)
559 HWND hFocus = GetFocus();
560 if (fIsFastList (hFocus))
562 FastList_SelectNone (hFocus);
567 void Server_OnKey_Properties (void)
569 HWND hFocus = GetFocus();
570 if (fIsFastList (hFocus))
573 if ((lpi = (LPIDENT)FL_GetSelectedData (hFocus)) != NULL)
575 StartContextCommand (GetParent(hFocus), NULL, lpi, M_PROPERTIES);
581 void Server_OnKey_Tab (HWND hDlg, BOOL fForward)
583 // The tab-cycle should go:
584 // TabControl <-> TabChildControls
586 HWND hFocus = GetFocus();
587 HWND hTabChild = GetTabChild (GetDlgItem (hDlg, IDC_TABS));
591 if (hFocus == GetDlgItem (hDlg, IDC_TABS))
593 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, NULL, FALSE), TRUE);
597 if (GetNextDlgTabItem (hTabChild, hFocus, FALSE) == GetNextDlgTabItem (hTabChild, NULL, FALSE))
598 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (hDlg, IDC_TABS), TRUE);
600 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, hFocus, FALSE), TRUE);
605 if (hFocus == GetDlgItem (hDlg, IDC_TABS))
607 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetLastDlgTabItem (hTabChild), TRUE);
611 if (hFocus == GetNextDlgTabItem (hTabChild, NULL, FALSE))
612 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (hDlg, IDC_TABS), TRUE);
614 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, hFocus, TRUE), TRUE);
620 void Server_OnKey_CtrlTab (HWND hDlg, BOOL fForward)
622 HWND hTabs = GetDlgItem (hDlg, IDC_TABS);
623 int iTab = TabCtrl_GetCurSel(hTabs);
626 iTab = (iTab == nCHILDTABS-1) ? (0) : (iTab+1);
628 iTab = (iTab == 0) ? (nCHILDTABS-1) : (iTab-1);
630 TabCtrl_SetCurSel (hTabs, iTab);
631 Server_DisplayTab (hDlg, (CHILDTAB)iTab);
632 gr.tabLast = (CHILDTAB)iTab;
634 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)hTabs, TRUE);