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 <afs/param.h>
19 #include "svr_window.h"
20 #include "propcache.h"
29 * RESIZING WINDOWS ___________________________________________________________
33 #define cxMIN_SERVER 100
34 #define cyMIN_SERVER 100
36 static rwWindowData awdServer
[] = {
37 { IDC_TABS
, raSizeX
| raSizeY
, MAKELONG(cxMIN_SERVER
,cyMIN_SERVER
), 0 },
38 { idENDLIST
, 0, 0, 0 }
41 static rwWindowData awdTabChild
[] = {
42 { 0, raSizeX
| raSizeY
, 0, 0 },
43 { idENDLIST
, 0, 0, 0 }
48 * CHILD TABS _________________________________________________________________
52 static struct // CHILDTABINFO
60 { tabFILESETS
, IDS_TAB_FILESETS
, imageFILESET
},
61 { tabAGGREGATES
, IDS_TAB_AGGREGATES
, imageAGGREGATE
},
62 { tabSERVICES
, IDS_TAB_SERVICES
, imageSERVICE
},
65 #define nCHILDTABS (sizeof(CHILDTABINFO)/sizeof(CHILDTABINFO[0]))
70 * PROTOTYPES _________________________________________________________________
74 BOOL CALLBACK
Server_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
76 void Server_SaveRect (HWND hDlg
, BOOL fOpen
);
78 BOOL
Server_HandleDialogKeys (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
82 * ROUTINES ___________________________________________________________________
86 void Server_Open (LPIDENT lpiServer
, LPRECT prWindow
)
90 if ((hServer
= PropCache_Search (pcSERVER
, lpiServer
)) != NULL
)
96 // First off, if this server isn't being monitored, we have
97 // to start monitoring it or we can't open a window (nothing to
101 if ((lpsp
= (LPSERVER_PREF
)lpiServer
->GetUserParam()) != NULL
)
103 BOOL fCanShowWindow
= (gr
.fOpenMonitors
|| lpsp
->fIsMonitored
);
105 if (gr
.fOpenMonitors
&& !lpsp
->fIsMonitored
)
107 StartTask (taskSVR_MONITOR_ONOFF
, NULL
, lpiServer
);
112 hServer
= ModelessDialogParam (IDD_SERVER
, NULL
, (DLGPROC
)Server_DlgProc
, (LPARAM
)lpiServer
);
113 Server_SelectServer (hServer
, lpiServer
);
115 if (prWindow
->right
!= 0)
117 SetWindowPos (hServer
, NULL
, prWindow
->left
, prWindow
->top
,
118 cxRECT(*prWindow
), cyRECT(*prWindow
),
119 SWP_NOZORDER
| SWP_NOACTIVATE
);
122 ShowWindow (hServer
, SW_NORMAL
);
129 void Server_Close (LPIDENT lpiServer
)
133 if ((hWnd
= PropCache_Search (pcSERVER
, lpiServer
)) != NULL
)
135 Server_SaveRect (hWnd
, FALSE
);
136 DestroyWindow (hWnd
);
138 // If there's a subset active, the user may want us to stop
139 // monitoring this server once its window is closed.
142 if ((lpsp
= (LPSERVER_PREF
)lpiServer
->GetUserParam()) != NULL
)
144 if (g
.sub
&& gr
.fCloseUnmonitors
&& lpsp
->fIsMonitored
&& !gr
.fPreview
)
146 StartTask (taskSVR_MONITOR_ONOFF
, NULL
, lpiServer
);
153 void Server_CloseAll (BOOL fUserRequested
)
157 while ((hWnd
= PropCache_Search (pcSERVER
, ANYVALUE
)) != NULL
)
159 LPIDENT lpiServer
= Server_GetServer (hWnd
);
161 Server_SaveRect (hWnd
, !fUserRequested
);
162 DestroyWindow (hWnd
);
164 if (lpiServer
&& fUserRequested
)
166 // If there's a subset active, the user may want us to stop
167 // monitoring this server once its window is closed.
170 if ((lpsp
= (LPSERVER_PREF
)lpiServer
->GetUserParam()) != NULL
)
172 if (g
.sub
&& gr
.fCloseUnmonitors
&& lpsp
->fIsMonitored
)
174 StartTask (taskSVR_MONITOR_ONOFF
, NULL
, lpiServer
);
182 HWND
Server_GetCurrentTab (HWND hWnd
)
184 return GetTabChild (GetDlgItem (hWnd
, IDC_TABS
));
187 CHILDTAB
Server_GetDisplayedTab (HWND hWnd
)
189 HWND hTabs
= GetDlgItem (hWnd
, IDC_TABS
);
190 return (hTabs
) ? (CHILDTAB
)TabCtrl_GetCurSel(hTabs
) : tabINVALID
;
193 HWND
Server_GetWindowForChild (HWND hChild
)
195 // hChild is the Filesets_DlgProc dialog (or whatever)
196 // Its parent is the tab control on the server window
197 // Its grandparent is the Popup HWND (may be g.hMain) that we want.
199 return GetParent (GetParent (hChild
));
202 void Server_SelectServer (HWND hDlg
, LPIDENT lpiNew
, BOOL fForceRedraw
)
204 LPIDENT lpiOld
= Server_GetServer (hDlg
);
205 if (lpiNew
!= lpiOld
)
207 SetWindowLongPtr (hDlg
, DWLP_USER
, (LONG_PTR
)lpiNew
);
212 PropCache_Delete (pcSERVER
, lpiOld
);
216 PropCache_Add (pcSERVER
, lpiNew
, hDlg
);
218 TCHAR szName
[ cchNAME
];
219 lpiNew
->GetServerName (szName
);
220 LPTSTR pszTitle
= FormatString (IDS_SERVER_TITLE
, TEXT("%s"), szName
);
221 SetWindowText (hDlg
, pszTitle
);
222 FreeString (pszTitle
);
231 Server_ForceRedraw (hDlg
);
235 LPIDENT
Server_GetServer (HWND hDlg
)
237 return (LPIDENT
)GetWindowLongPtr (hDlg
, DWLP_USER
);
240 LPIDENT
Server_GetServerForChild (HWND hChild
)
242 if (GetParent(hChild
) == NULL
)
243 return Server_GetServer (hChild
);
245 return Server_GetServer (GetParent(GetParent(hChild
)));
249 void Server_ForceRedraw (HWND hDlg
)
251 HWND hChild
= Server_GetCurrentTab (hDlg
);
253 if (hChild
&& IsWindow (hChild
))
255 PostMessage (hChild
, WM_SERVER_CHANGED
, 0, 0);
261 * SERVER DIALOG ______________________________________________________________
265 BOOL CALLBACK
Server_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
267 LPIDENT lpiServer
= Server_GetServer (hDlg
);
269 if (Server_HandleDialogKeys (hDlg
, msg
, wp
, lp
))
276 Server_PrepareTabControl (GetDlgItem (hDlg
, IDC_TABS
));
277 GetWindowRect (hDlg
, &rWindow
);
278 ResizeWindow (hDlg
, awdServer
, rwaMoveToHere
, &rWindow
);
282 WinHelp (hDlg
, cszHELPFILENAME
, HELP_FINDER
, 0);
286 GetWindowRect (hDlg
, &gr
.rServerLast
);
289 PropCache_Delete (pcSERVER
, lpiServer
);
293 // if (lp==0), we're minimizing--don't call ResizeWindow().
297 ResizeWindow (hDlg
, awdServer
, rwaFixupGuts
);
298 Server_SaveRect (hDlg
, TRUE
);
303 Server_SaveRect (hDlg
, TRUE
);
307 gr
.tabLast
= Server_GetDisplayedTab (hDlg
);
315 if ((lpi
= Server_GetServer (hDlg
)) != NULL
)
318 DestroyWindow (hDlg
);
324 switch (((LPNMHDR
)lp
)->code
)
328 HWND hTab
= GetDlgItem (hDlg
, IDC_TABS
);
329 int iPage
= TabCtrl_GetCurSel (hTab
);
331 Server_DisplayTab (hDlg
, (CHILDTAB
)iPage
);
332 gr
.tabLast
= (CHILDTAB
)iPage
;
343 static LONG_PTR procTabControl
= 0;
345 LRESULT CALLBACK
Server_SubclassTabControlProc (HWND hTab
, UINT msg
, WPARAM wp
, LPARAM lp
)
349 if (procTabControl
== 0)
350 rc
= DefWindowProc (hTab
, msg
, wp
, lp
);
352 rc
= (LRESULT
) CallWindowProc ((WNDPROC
)procTabControl
, hTab
, msg
, wp
, lp
);
356 // Since this is a subclass proc, it's not around when the window
357 // is created. Any WM_CREATE processing we'd ordinarily do here
358 // must therefore be done at the point where the tab control is
365 ResizeWindow (hTab
, awdTabChild
, rwaFixupGuts
);
369 if (procTabControl
!= 0)
370 SetWindowLongPtr (hTab
, GWLP_WNDPROC
, procTabControl
);
378 void Server_PrepareTabControl (HWND hTab
)
380 TabCtrl_SetImageList (hTab
, AfsAppLib_CreateImageList (FALSE
));
382 TCHAR szText
[ cchRESOURCE
];
384 tci
.mask
= TCIF_TEXT
| TCIF_PARAM
| TCIF_IMAGE
;
385 tci
.pszText
= szText
;
387 for (int iTab
= 0; iTab
< nCHILDTABS
; ++iTab
)
389 tci
.iImage
= CHILDTABINFO
[ iTab
].iImage
;
390 tci
.lParam
= (LPARAM
)CHILDTABINFO
[ iTab
].tab
;
391 GetString (tci
.pszText
, CHILDTABINFO
[ iTab
].idsTabTitle
);
392 TabCtrl_InsertItem (hTab
, iTab
, &tci
);
395 // subclass the TCN_ window, so that it will start sending WM_SIZE
396 // messages to its child window.
398 procTabControl
= GetWindowLongPtr (hTab
, GWLP_WNDPROC
);
399 SetWindowLongPtr (hTab
, GWLP_WNDPROC
, (LONG_PTR
)Server_SubclassTabControlProc
);
401 // Since we just subclassed this control, our new wndproc wasn't around
402 // when the window was created. Any WM_CREATE processing we'd ordinarily
403 // in that wndproc must therefore be done here.
407 GetRectInParent (hTab
, &rWindow
);
408 ResizeWindow (hTab
, awdTabChild
, rwaMoveToHere
, &rWindow
);
410 // Finally, select an appropriate tab and display it.
412 Server_DisplayTab (GetParent (hTab
), gr
.tabLast
);
416 void Server_DisplayTab (HWND hDlg
, CHILDTAB iTab
)
418 HWND hTab
= GetDlgItem (hDlg
, IDC_TABS
);
420 DLGPROC dlgproc
= NULL
;
426 dlgproc
= (DLGPROC
)Services_DlgProc
;
429 idd
= IDD_AGGREGATES
;
430 dlgproc
= (DLGPROC
)Aggregates_DlgProc
;
434 dlgproc
= (DLGPROC
)Filesets_DlgProc
;
440 HWND hDialogOld
= GetTabChild (hTab
);
441 HWND hDialogNew
= ModelessDialog (idd
, hTab
, dlgproc
);
443 if (hDialogNew
!= NULL
)
445 TabCtrl_SetCurSel (hTab
, iTab
);
446 ShowWindow (hDialogNew
, SW_SHOW
);
448 if (hDialogOld
!= NULL
)
450 DestroyWindow (hDialogOld
);
453 Server_ForceRedraw (hDlg
);
459 void Server_Uncover (HWND hWnd
)
461 if (hWnd
== g
.hMain
) // uncover the preview pane?
463 AfsAppLib_Uncover (GetDlgItem (g
.hMain
, IDC_TABS
));
465 else // uncover a standalone server window?
467 AfsAppLib_Uncover (hWnd
);
472 void Server_SaveRect (HWND hDlg
, BOOL fOpen
)
474 LPSVR_SETWINDOWPOS_PARAMS lpp
= New (SVR_SETWINDOWPOS_PARAMS
);
475 GetWindowRect (hDlg
, &lpp
->rWindow
);
476 lpp
->lpi
= Server_GetServer (hDlg
);
479 StartTask (taskSVR_SETWINDOWPOS
, NULL
, lpp
);
483 BOOL
Server_HandleDialogKeys (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
485 if (msg
== WM_COMMAND
)
490 Server_OnKey_Return();
494 Server_OnKey_CtrlTab (hDlg
, TRUE
);
497 case M_KEY_CTRLBACKTAB
:
498 Server_OnKey_CtrlTab (hDlg
, FALSE
);
502 Server_OnKey_Tab (hDlg
, TRUE
);
506 Server_OnKey_Tab (hDlg
, FALSE
);
517 case M_KEY_PROPERTIES
:
518 Server_OnKey_Properties();
527 void Server_OnKey_Return (void)
530 hdr
.hwndFrom
= GetFocus();
531 hdr
.idFrom
= GetWindowLong (GetFocus(), GWL_ID
);
532 hdr
.code
= FLN_LDBLCLICK
;
533 PostMessage (GetParent (GetFocus()), WM_NOTIFY
, 0, (LPARAM
)&hdr
);
537 void Server_OnKey_Menu (void)
539 HWND hFocus
= GetFocus();
540 if (fIsFastList (hFocus
))
542 POINT ptScreen
= { 0, 0 };
545 if ((hItem
= FastList_FindFirstSelected (hFocus
)) != NULL
)
547 FASTLISTITEMREGIONS reg
;
548 FastList_GetItemRegions (hFocus
, hItem
, ®
);
550 ptScreen
.x
= reg
.rItem
.left
+ (reg
.rItem
.right
-reg
.rItem
.left
) /2;
551 ptScreen
.y
= reg
.rItem
.top
+ (reg
.rItem
.bottom
-reg
.rItem
.top
) /2;
552 ClientToScreen (GetFocus(), &ptScreen
);
555 PostMessage (GetParent (GetFocus()), WM_CONTEXTMENU
, (WPARAM
)GetFocus(), MAKELONG(ptScreen
.x
,ptScreen
.y
));
560 void Server_OnKey_Esc (void)
562 HWND hFocus
= GetFocus();
563 if (fIsFastList (hFocus
))
565 FastList_SelectNone (hFocus
);
570 void Server_OnKey_Properties (void)
572 HWND hFocus
= GetFocus();
573 if (fIsFastList (hFocus
))
576 if ((lpi
= (LPIDENT
)FL_GetSelectedData (hFocus
)) != NULL
)
578 StartContextCommand (GetParent(hFocus
), NULL
, lpi
, M_PROPERTIES
);
584 void Server_OnKey_Tab (HWND hDlg
, BOOL fForward
)
586 // The tab-cycle should go:
587 // TabControl <-> TabChildControls
589 HWND hFocus
= GetFocus();
590 HWND hTabChild
= GetTabChild (GetDlgItem (hDlg
, IDC_TABS
));
594 if (hFocus
== GetDlgItem (hDlg
, IDC_TABS
))
596 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)GetNextDlgTabItem (hTabChild
, NULL
, FALSE
), TRUE
);
600 if (GetNextDlgTabItem (hTabChild
, hFocus
, FALSE
) == GetNextDlgTabItem (hTabChild
, NULL
, FALSE
))
601 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)GetDlgItem (hDlg
, IDC_TABS
), TRUE
);
603 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)GetNextDlgTabItem (hTabChild
, hFocus
, FALSE
), TRUE
);
608 if (hFocus
== GetDlgItem (hDlg
, IDC_TABS
))
610 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)GetLastDlgTabItem (hTabChild
), TRUE
);
614 if (hFocus
== GetNextDlgTabItem (hTabChild
, NULL
, FALSE
))
615 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)GetDlgItem (hDlg
, IDC_TABS
), TRUE
);
617 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)GetNextDlgTabItem (hTabChild
, hFocus
, TRUE
), TRUE
);
623 void Server_OnKey_CtrlTab (HWND hDlg
, BOOL fForward
)
625 HWND hTabs
= GetDlgItem (hDlg
, IDC_TABS
);
626 int iTab
= TabCtrl_GetCurSel(hTabs
);
629 iTab
= (iTab
== nCHILDTABS
-1) ? (0) : (iTab
+1);
631 iTab
= (iTab
== 0) ? (nCHILDTABS
-1) : (iTab
-1);
633 TabCtrl_SetCurSel (hTabs
, iTab
);
634 Server_DisplayTab (hDlg
, (CHILDTAB
)iTab
);
635 gr
.tabLast
= (CHILDTAB
)iTab
;
637 PostMessage (hDlg
, WM_NEXTDLGCTL
, (WPARAM
)hTabs
, TRUE
);