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
14 #include <afsconfig.h>
15 #include <afs/param.h>
20 #include "svr_window.h"
21 #include "propcache.h"
30 * RESIZING WINDOWS ___________________________________________________________
34 #define cxMIN_SERVER 100
35 #define cyMIN_SERVER 100
37 static rwWindowData awdServer[] = {
38 { IDC_TABS, raSizeX | raSizeY, MAKELONG(cxMIN_SERVER,cyMIN_SERVER), 0 },
39 { idENDLIST, 0, 0, 0 }
42 static rwWindowData awdTabChild[] = {
43 { 0, raSizeX | raSizeY, 0, 0 },
44 { idENDLIST, 0, 0, 0 }
49 * CHILD TABS _________________________________________________________________
53 static struct // CHILDTABINFO
61 { tabFILESETS, IDS_TAB_FILESETS, imageFILESET },
62 { tabAGGREGATES, IDS_TAB_AGGREGATES, imageAGGREGATE },
63 { tabSERVICES, IDS_TAB_SERVICES, imageSERVICE },
66 #define nCHILDTABS (sizeof(CHILDTABINFO)/sizeof(CHILDTABINFO[0]))
71 * PROTOTYPES _________________________________________________________________
75 BOOL CALLBACK Server_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
77 void Server_SaveRect (HWND hDlg, BOOL fOpen);
79 BOOL Server_HandleDialogKeys (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
83 * ROUTINES ___________________________________________________________________
87 void Server_Open (LPIDENT lpiServer, LPRECT prWindow)
91 if ((hServer = PropCache_Search (pcSERVER, lpiServer)) != NULL)
97 // First off, if this server isn't being monitored, we have
98 // to start monitoring it or we can't open a window (nothing to
102 if ((lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) != NULL)
104 BOOL fCanShowWindow = (gr.fOpenMonitors || lpsp->fIsMonitored);
106 if (gr.fOpenMonitors && !lpsp->fIsMonitored)
108 StartTask (taskSVR_MONITOR_ONOFF, NULL, lpiServer);
113 hServer = ModelessDialogParam (IDD_SERVER, NULL, (DLGPROC)Server_DlgProc, (LPARAM)lpiServer);
114 Server_SelectServer (hServer, lpiServer);
116 if (prWindow->right != 0)
118 SetWindowPos (hServer, NULL, prWindow->left, prWindow->top,
119 cxRECT(*prWindow), cyRECT(*prWindow),
120 SWP_NOZORDER | SWP_NOACTIVATE);
123 ShowWindow (hServer, SW_NORMAL);
130 void Server_Close (LPIDENT lpiServer)
134 if ((hWnd = PropCache_Search (pcSERVER, lpiServer)) != NULL)
136 Server_SaveRect (hWnd, FALSE);
137 DestroyWindow (hWnd);
139 // If there's a subset active, the user may want us to stop
140 // monitoring this server once its window is closed.
143 if ((lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) != NULL)
145 if (g.sub && gr.fCloseUnmonitors && lpsp->fIsMonitored && !gr.fPreview)
147 StartTask (taskSVR_MONITOR_ONOFF, NULL, lpiServer);
154 void Server_CloseAll (BOOL fUserRequested)
158 while ((hWnd = PropCache_Search (pcSERVER, ANYVALUE)) != NULL)
160 LPIDENT lpiServer = Server_GetServer (hWnd);
162 Server_SaveRect (hWnd, !fUserRequested);
163 DestroyWindow (hWnd);
165 if (lpiServer && fUserRequested)
167 // If there's a subset active, the user may want us to stop
168 // monitoring this server once its window is closed.
171 if ((lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) != NULL)
173 if (g.sub && gr.fCloseUnmonitors && lpsp->fIsMonitored)
175 StartTask (taskSVR_MONITOR_ONOFF, NULL, lpiServer);
183 HWND Server_GetCurrentTab (HWND hWnd)
185 return GetTabChild (GetDlgItem (hWnd, IDC_TABS));
188 CHILDTAB Server_GetDisplayedTab (HWND hWnd)
190 HWND hTabs = GetDlgItem (hWnd, IDC_TABS);
191 return (hTabs) ? (CHILDTAB)TabCtrl_GetCurSel(hTabs) : tabINVALID;
194 HWND Server_GetWindowForChild (HWND hChild)
196 // hChild is the Filesets_DlgProc dialog (or whatever)
197 // Its parent is the tab control on the server window
198 // Its grandparent is the Popup HWND (may be g.hMain) that we want.
200 return GetParent (GetParent (hChild));
203 void Server_SelectServer (HWND hDlg, LPIDENT lpiNew, BOOL fForceRedraw)
205 LPIDENT lpiOld = Server_GetServer (hDlg);
206 if (lpiNew != lpiOld)
208 SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR)lpiNew);
213 PropCache_Delete (pcSERVER, lpiOld);
217 PropCache_Add (pcSERVER, lpiNew, hDlg);
219 TCHAR szName[ cchNAME ];
220 lpiNew->GetServerName (szName);
221 LPTSTR pszTitle = FormatString (IDS_SERVER_TITLE, TEXT("%s"), szName);
222 SetWindowText (hDlg, pszTitle);
223 FreeString (pszTitle);
232 Server_ForceRedraw (hDlg);
236 LPIDENT Server_GetServer (HWND hDlg)
238 return (LPIDENT)GetWindowLongPtr (hDlg, DWLP_USER);
241 LPIDENT Server_GetServerForChild (HWND hChild)
243 if (GetParent(hChild) == NULL)
244 return Server_GetServer (hChild);
246 return Server_GetServer (GetParent(GetParent(hChild)));
250 void Server_ForceRedraw (HWND hDlg)
252 HWND hChild = Server_GetCurrentTab (hDlg);
254 if (hChild && IsWindow (hChild))
256 PostMessage (hChild, WM_SERVER_CHANGED, 0, 0);
262 * SERVER DIALOG ______________________________________________________________
266 BOOL CALLBACK Server_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
268 LPIDENT lpiServer = Server_GetServer (hDlg);
270 if (Server_HandleDialogKeys (hDlg, msg, wp, lp))
277 Server_PrepareTabControl (GetDlgItem (hDlg, IDC_TABS));
278 GetWindowRect (hDlg, &rWindow);
279 ResizeWindow (hDlg, awdServer, rwaMoveToHere, &rWindow);
283 WinHelp (hDlg, cszHELPFILENAME, HELP_FINDER, 0);
287 GetWindowRect (hDlg, &gr.rServerLast);
290 PropCache_Delete (pcSERVER, lpiServer);
294 // if (lp==0), we're minimizing--don't call ResizeWindow().
298 ResizeWindow (hDlg, awdServer, rwaFixupGuts);
299 Server_SaveRect (hDlg, TRUE);
304 Server_SaveRect (hDlg, TRUE);
308 gr.tabLast = Server_GetDisplayedTab (hDlg);
316 if ((lpi = Server_GetServer (hDlg)) != NULL)
319 DestroyWindow (hDlg);
325 switch (((LPNMHDR)lp)->code)
329 HWND hTab = GetDlgItem (hDlg, IDC_TABS);
330 int iPage = TabCtrl_GetCurSel (hTab);
332 Server_DisplayTab (hDlg, (CHILDTAB)iPage);
333 gr.tabLast = (CHILDTAB)iPage;
344 static LONG_PTR procTabControl = 0;
346 LRESULT CALLBACK Server_SubclassTabControlProc (HWND hTab, UINT msg, WPARAM wp, LPARAM lp)
350 if (procTabControl == 0)
351 rc = DefWindowProc (hTab, msg, wp, lp);
353 rc = (LRESULT) CallWindowProc ((WNDPROC)procTabControl, hTab, msg, wp, lp);
357 // Since this is a subclass proc, it's not around when the window
358 // is created. Any WM_CREATE processing we'd ordinarily do here
359 // must therefore be done at the point where the tab control is
366 ResizeWindow (hTab, awdTabChild, rwaFixupGuts);
370 if (procTabControl != 0)
371 SetWindowLongPtr (hTab, GWLP_WNDPROC, procTabControl);
379 void Server_PrepareTabControl (HWND hTab)
381 TabCtrl_SetImageList (hTab, AfsAppLib_CreateImageList (FALSE));
383 TCHAR szText[ cchRESOURCE ];
385 tci.mask = TCIF_TEXT | TCIF_PARAM | TCIF_IMAGE;
386 tci.pszText = szText;
388 for (int iTab = 0; iTab < nCHILDTABS; ++iTab)
390 tci.iImage = CHILDTABINFO[ iTab ].iImage;
391 tci.lParam = (LPARAM)CHILDTABINFO[ iTab ].tab;
392 GetString (tci.pszText, CHILDTABINFO[ iTab ].idsTabTitle);
393 TabCtrl_InsertItem (hTab, iTab, &tci);
396 // subclass the TCN_ window, so that it will start sending WM_SIZE
397 // messages to its child window.
399 procTabControl = GetWindowLongPtr (hTab, GWLP_WNDPROC);
400 SetWindowLongPtr (hTab, GWLP_WNDPROC, (LONG_PTR)Server_SubclassTabControlProc);
402 // Since we just subclassed this control, our new wndproc wasn't around
403 // when the window was created. Any WM_CREATE processing we'd ordinarily
404 // in that wndproc must therefore be done here.
408 GetRectInParent (hTab, &rWindow);
409 ResizeWindow (hTab, awdTabChild, rwaMoveToHere, &rWindow);
411 // Finally, select an appropriate tab and display it.
413 Server_DisplayTab (GetParent (hTab), gr.tabLast);
417 void Server_DisplayTab (HWND hDlg, CHILDTAB iTab)
419 HWND hTab = GetDlgItem (hDlg, IDC_TABS);
421 DLGPROC dlgproc = NULL;
427 dlgproc = (DLGPROC)Services_DlgProc;
430 idd = IDD_AGGREGATES;
431 dlgproc = (DLGPROC)Aggregates_DlgProc;
435 dlgproc = (DLGPROC)Filesets_DlgProc;
441 HWND hDialogOld = GetTabChild (hTab);
442 HWND hDialogNew = ModelessDialog (idd, hTab, dlgproc);
444 if (hDialogNew != NULL)
446 TabCtrl_SetCurSel (hTab, iTab);
447 ShowWindow (hDialogNew, SW_SHOW);
449 if (hDialogOld != NULL)
451 DestroyWindow (hDialogOld);
454 Server_ForceRedraw (hDlg);
460 void Server_Uncover (HWND hWnd)
462 if (hWnd == g.hMain) // uncover the preview pane?
464 AfsAppLib_Uncover (GetDlgItem (g.hMain, IDC_TABS));
466 else // uncover a standalone server window?
468 AfsAppLib_Uncover (hWnd);
473 void Server_SaveRect (HWND hDlg, BOOL fOpen)
475 LPSVR_SETWINDOWPOS_PARAMS lpp = New (SVR_SETWINDOWPOS_PARAMS);
476 GetWindowRect (hDlg, &lpp->rWindow);
477 lpp->lpi = Server_GetServer (hDlg);
480 StartTask (taskSVR_SETWINDOWPOS, NULL, lpp);
484 BOOL Server_HandleDialogKeys (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
486 if (msg == WM_COMMAND)
491 Server_OnKey_Return();
495 Server_OnKey_CtrlTab (hDlg, TRUE);
498 case M_KEY_CTRLBACKTAB:
499 Server_OnKey_CtrlTab (hDlg, FALSE);
503 Server_OnKey_Tab (hDlg, TRUE);
507 Server_OnKey_Tab (hDlg, FALSE);
518 case M_KEY_PROPERTIES:
519 Server_OnKey_Properties();
528 void Server_OnKey_Return (void)
531 hdr.hwndFrom = GetFocus();
532 hdr.idFrom = GetWindowLong (GetFocus(), GWL_ID);
533 hdr.code = FLN_LDBLCLICK;
534 PostMessage (GetParent (GetFocus()), WM_NOTIFY, 0, (LPARAM)&hdr);
538 void Server_OnKey_Menu (void)
540 HWND hFocus = GetFocus();
541 if (fIsFastList (hFocus))
543 POINT ptScreen = { 0, 0 };
546 if ((hItem = FastList_FindFirstSelected (hFocus)) != NULL)
548 FASTLISTITEMREGIONS reg;
549 FastList_GetItemRegions (hFocus, hItem, ®);
551 ptScreen.x = reg.rItem.left + (reg.rItem.right -reg.rItem.left) /2;
552 ptScreen.y = reg.rItem.top + (reg.rItem.bottom -reg.rItem.top) /2;
553 ClientToScreen (GetFocus(), &ptScreen);
556 PostMessage (GetParent (GetFocus()), WM_CONTEXTMENU, (WPARAM)GetFocus(), MAKELONG(ptScreen.x,ptScreen.y));
561 void Server_OnKey_Esc (void)
563 HWND hFocus = GetFocus();
564 if (fIsFastList (hFocus))
566 FastList_SelectNone (hFocus);
571 void Server_OnKey_Properties (void)
573 HWND hFocus = GetFocus();
574 if (fIsFastList (hFocus))
577 if ((lpi = (LPIDENT)FL_GetSelectedData (hFocus)) != NULL)
579 StartContextCommand (GetParent(hFocus), NULL, lpi, M_PROPERTIES);
585 void Server_OnKey_Tab (HWND hDlg, BOOL fForward)
587 // The tab-cycle should go:
588 // TabControl <-> TabChildControls
590 HWND hFocus = GetFocus();
591 HWND hTabChild = GetTabChild (GetDlgItem (hDlg, IDC_TABS));
595 if (hFocus == GetDlgItem (hDlg, IDC_TABS))
597 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, NULL, FALSE), TRUE);
601 if (GetNextDlgTabItem (hTabChild, hFocus, FALSE) == GetNextDlgTabItem (hTabChild, NULL, FALSE))
602 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (hDlg, IDC_TABS), TRUE);
604 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, hFocus, FALSE), TRUE);
609 if (hFocus == GetDlgItem (hDlg, IDC_TABS))
611 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetLastDlgTabItem (hTabChild), TRUE);
615 if (hFocus == GetNextDlgTabItem (hTabChild, NULL, FALSE))
616 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (hDlg, IDC_TABS), TRUE);
618 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, hFocus, TRUE), TRUE);
624 void Server_OnKey_CtrlTab (HWND hDlg, BOOL fForward)
626 HWND hTabs = GetDlgItem (hDlg, IDC_TABS);
627 int iTab = TabCtrl_GetCurSel(hTabs);
630 iTab = (iTab == nCHILDTABS-1) ? (0) : (iTab+1);
632 iTab = (iTab == 0) ? (nCHILDTABS-1) : (iTab-1);
634 TabCtrl_SetCurSel (hTabs, iTab);
635 Server_DisplayTab (hDlg, (CHILDTAB)iTab);
636 gr.tabLast = (CHILDTAB)iTab;
638 PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)hTabs, TRUE);