Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afsapplib / al_cover.cpp
blob320f48aaf9be7f897b7cf23c4ddc80e45cb67437
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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
8 */
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
15 #include <WINNT/afsapplib.h>
19 * RESIZING WINDOWS ___________________________________________________________
23 rwWindowData awdCover[] = {
24 { IDC_COVER_BORDER, raSizeX | raSizeY, 0, 0 },
25 { IDC_COVER_DESC, raSizeX | raSizeY | raRepaint, 0, 0 },
26 { IDC_COVER_BUTTON, raMoveX | raMoveY | raRepaint, 0, 0 },
27 { idENDLIST, 0, 0, 0 }
30 #define WS_EX_HIDDENBYCOVER 0x10000000L
34 * DEFINITIONS ________________________________________________________________
38 #define dwCOVER_SIGNATURE 0xC0E0C0E0 // SetWindowLongPtr(hDlgCover,DWLP_USER,#)
40 typedef struct // COVERPARAMS
42 BOOL fClient;
43 HWND hWnd;
44 LPTSTR pszDesc;
45 LPTSTR pszButton;
46 } COVERPARAMS, *LPCOVERPARAMS;
50 * PROTOTYPES _________________________________________________________________
54 void OnCoverWindow (WPARAM wp, LPARAM lp);
56 HRESULT CALLBACK Cover_DialogProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
60 * ROUTINES ___________________________________________________________________
64 void AfsAppLib_CoverClient (HWND hWnd, LPTSTR pszDesc, LPTSTR pszButton)
66 AfsAppLib_Uncover (hWnd);
68 LPCOVERPARAMS lpcp = New (COVERPARAMS);
70 lpcp->fClient = TRUE;
71 lpcp->hWnd = hWnd;
72 lpcp->pszDesc = CloneString (pszDesc);
73 lpcp->pszButton = CloneString (pszButton);
75 if (!AfsAppLib_GetMainWindow())
76 OnCoverWindow (0, (LPARAM)lpcp);
77 else
78 PostMessage (AfsAppLib_GetMainWindow(), WM_COVER_WINDOW, 0, (LPARAM)lpcp);
82 void AfsAppLib_CoverWindow (HWND hWnd, LPTSTR pszDesc, LPTSTR pszButton)
84 AfsAppLib_Uncover (hWnd);
86 LPCOVERPARAMS lpcp = New (COVERPARAMS);
88 lpcp->fClient = FALSE;
89 lpcp->hWnd = hWnd;
90 lpcp->pszDesc = CloneString (pszDesc);
91 lpcp->pszButton = CloneString (pszButton);
93 if (!AfsAppLib_GetMainWindow())
94 OnCoverWindow (0, (LPARAM)lpcp);
95 else
96 PostMessage (AfsAppLib_GetMainWindow(), WM_COVER_WINDOW, 0, (LPARAM)lpcp);
100 void AfsAppLib_Uncover (HWND hDlg)
102 if (!AfsAppLib_GetMainWindow())
103 OnCoverWindow ((WPARAM)hDlg, 0);
104 else
105 PostMessage (AfsAppLib_GetMainWindow(), WM_COVER_WINDOW, (WPARAM)hDlg, 0);
109 void OnCoverWindow (WPARAM wp, LPARAM lp)
111 LPCOVERPARAMS lpcp;
112 if ((lpcp = (LPCOVERPARAMS)lp) == NULL)
114 HWND hDlg = (HWND)wp;
116 if (!IsWindowVisible (hDlg)) // did we create it as a sibling?
118 ShowWindow (hDlg, TRUE);
119 EnableWindow (hDlg, TRUE);
120 hDlg = GetParent(hDlg);
123 for (HWND hChild = GetWindow (hDlg, GW_CHILD);
124 hChild != NULL;
125 hChild = GetWindow (hChild, GW_HWNDNEXT))
127 TCHAR szClassName[ cchRESOURCE ];
129 if (GetClassName (hChild, szClassName, cchRESOURCE))
131 if (!lstrcmp (szClassName, TEXT("#32770"))) // WC_DIALOG
133 if (GetWindowLongPtr (hChild, DWLP_USER) == dwCOVER_SIGNATURE)
135 DestroyWindow (hChild);
136 break;
142 else
144 HWND hCover = ModelessDialogParam (IDD_APPLIB_COVER,
145 (lpcp->fClient) ? lpcp->hWnd : GetParent(lpcp->hWnd),
146 (DLGPROC)Cover_DialogProc,
147 (LPARAM)lp);
149 ShowWindow (hCover, TRUE);
150 SetWindowLongPtr (hCover, DWLP_USER, dwCOVER_SIGNATURE);
152 FreeString (lpcp->pszDesc);
153 FreeString (lpcp->pszButton);
154 Delete (lpcp);
159 HRESULT CALLBACK Cover_DialogProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
161 switch (msg)
163 case WM_INITDIALOG:
164 LPCOVERPARAMS lpcp;
165 lpcp = (LPCOVERPARAMS)lp;
167 SetDlgItemText (hDlg, IDC_COVER_DESC, (lpcp && lpcp->pszDesc) ? lpcp->pszDesc : TEXT(""));
169 if (lpcp && lpcp->pszButton)
171 SetDlgItemText (hDlg, IDC_COVER_BUTTON, lpcp->pszButton);
173 else
175 DestroyWindow (GetDlgItem (hDlg, IDC_COVER_BUTTON));
178 RECT rCover;
179 if (lpcp->fClient)
181 // If we're covering a window's client area, we've been created
182 // as a child of that window. Hide its other children, and we'll
183 // be done.
185 GetClientRect (lpcp->hWnd, &rCover);
187 for (HWND hChild = GetWindow (lpcp->hWnd, GW_CHILD);
188 hChild != NULL;
189 hChild = GetWindow (hChild, GW_HWNDNEXT))
191 if (hChild == hDlg)
192 continue;
194 if (IsWindowVisible (hChild))
196 LONG dwStyleEx = GetWindowLong (hChild, GWL_EXSTYLE);
197 SetWindowLong (hChild, GWL_EXSTYLE, dwStyleEx | WS_EX_HIDDENBYCOVER);
198 ShowWindow (hChild, FALSE);
202 else
204 // If we're covering a window's complete area, we've been created
205 // as a sibling of that window. Hide that window.
207 GetRectInParent (lpcp->hWnd, &rCover);
208 ShowWindow (lpcp->hWnd, FALSE);
209 EnableWindow (lpcp->hWnd, FALSE);
212 if (lpcp && lpcp->pszButton)
214 RECT rDesc; // give the button's space to the Description window
215 RECT rButton;
216 GetRectInParent (GetDlgItem (hDlg, IDC_COVER_DESC), &rDesc);
217 GetRectInParent (GetDlgItem (hDlg, IDC_COVER_BUTTON), &rButton);
219 // If the window is higher than it is wide, put the description
220 // above the button. Otherwise, put it to the right of the button.
222 if (cyRECT(rCover) > cxRECT(rCover))
224 // shrink description vertically
225 SetWindowPos (GetDlgItem (hDlg, IDC_COVER_DESC), NULL,
226 0, 0,
227 cxRECT(rDesc),
228 cyRECT(rDesc) - rDesc.bottom + rButton.top -5,
229 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE);
231 else
233 // shrink description horizontally
234 SetWindowPos (GetDlgItem (hDlg, IDC_COVER_DESC), NULL,
235 0, 0,
236 cxRECT(rDesc) - rDesc.right + rButton.left -5,
237 cyRECT(rDesc),
238 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE);
242 ResizeWindow (hDlg, awdCover, rwaMoveToHere, &rCover);
243 break;
245 case WM_DESTROY:
246 // Show all of our parent's other children, in preparation for
247 // our going away.
249 HWND hChild;
250 for (hChild = GetWindow (GetParent (hDlg), GW_CHILD);
251 hChild != NULL;
252 hChild = GetWindow (hChild, GW_HWNDNEXT))
254 if (hChild == hDlg)
255 continue;
257 LONG dwStyleEx = GetWindowLong (hChild, GWL_EXSTYLE);
258 if (dwStyleEx & WS_EX_HIDDENBYCOVER)
260 SetWindowLong (hChild, GWL_EXSTYLE, dwStyleEx & (~WS_EX_HIDDENBYCOVER));
261 ShowWindow (hChild, TRUE);
264 break;
266 case WM_SIZE:
267 // if (lp==0), we're minimizing--don't call ResizeWindow().
269 if (lp != 0)
270 ResizeWindow (hDlg, awdCover, rwaFixupGuts);
271 break;
273 case WM_COMMAND:
274 switch (LOWORD(wp))
276 case IDC_COVER_BUTTON:
277 PostMessage (GetParent(hDlg), WM_COMMAND, wp, lp);
278 break;
280 break;
283 return FALSE;