5a02c71fe38978c6a708137b39ba3886b23b31cc
[openafs.git] / src / WINNT / afsapplib / al_cover.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include <WINNT/afsapplib.h>
16
17
18 /*
19  * RESIZING WINDOWS ___________________________________________________________
20  *
21  */
22
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 }
28  };
29
30 #define WS_EX_HIDDENBYCOVER       0x10000000L
31
32
33 /*
34  * DEFINITIONS ________________________________________________________________
35  *
36  */
37
38 #define dwCOVER_SIGNATURE  0xC0E0C0E0  // SetWindowLong(hDlgCover,DWL_USER,#)
39
40 typedef struct // COVERPARAMS
41    {
42    BOOL fClient;
43    HWND hWnd;
44    LPTSTR pszDesc;
45    LPTSTR pszButton;
46    } COVERPARAMS, *LPCOVERPARAMS;
47
48
49 /*
50  * PROTOTYPES _________________________________________________________________
51  *
52  */
53
54 void OnCoverWindow (WPARAM wp, LPARAM lp);
55
56 BOOL CALLBACK Cover_DialogProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
57
58
59 /*
60  * ROUTINES ___________________________________________________________________
61  *
62  */
63
64 void AfsAppLib_CoverClient (HWND hWnd, LPTSTR pszDesc, LPTSTR pszButton)
65 {
66    AfsAppLib_Uncover (hWnd);
67
68    LPCOVERPARAMS lpcp = New (COVERPARAMS);
69
70    lpcp->fClient = TRUE;
71    lpcp->hWnd = hWnd;
72    lpcp->pszDesc = CloneString (pszDesc);
73    lpcp->pszButton = CloneString (pszButton);
74
75    if (!AfsAppLib_GetMainWindow())
76       OnCoverWindow (0, (LPARAM)lpcp);
77    else
78       PostMessage (AfsAppLib_GetMainWindow(), WM_COVER_WINDOW, 0, (LPARAM)lpcp);
79 }
80
81
82 void AfsAppLib_CoverWindow (HWND hWnd, LPTSTR pszDesc, LPTSTR pszButton)
83 {
84    AfsAppLib_Uncover (hWnd);
85
86    LPCOVERPARAMS lpcp = New (COVERPARAMS);
87
88    lpcp->fClient = FALSE;
89    lpcp->hWnd = hWnd;
90    lpcp->pszDesc = CloneString (pszDesc);
91    lpcp->pszButton = CloneString (pszButton);
92
93    if (!AfsAppLib_GetMainWindow())
94       OnCoverWindow (0, (LPARAM)lpcp);
95    else
96       PostMessage (AfsAppLib_GetMainWindow(), WM_COVER_WINDOW, 0, (LPARAM)lpcp);
97 }
98
99
100 void AfsAppLib_Uncover (HWND hDlg)
101 {
102    if (!AfsAppLib_GetMainWindow())
103       OnCoverWindow ((WPARAM)hDlg, 0);
104    else
105       PostMessage (AfsAppLib_GetMainWindow(), WM_COVER_WINDOW, (WPARAM)hDlg, 0);
106 }
107
108
109 void OnCoverWindow (WPARAM wp, LPARAM lp)
110 {
111    LPCOVERPARAMS lpcp;
112    if ((lpcp = (LPCOVERPARAMS)lp) == NULL)
113       {
114       HWND hDlg = (HWND)wp;
115
116       if (!IsWindowVisible (hDlg))      // did we create it as a sibling?
117          {
118          ShowWindow (hDlg, TRUE);
119          EnableWindow (hDlg, TRUE);
120          hDlg = GetParent(hDlg);
121          }
122
123       for (HWND hChild = GetWindow (hDlg, GW_CHILD);
124            hChild != NULL;
125            hChild = GetWindow (hChild, GW_HWNDNEXT))
126          {
127          TCHAR szClassName[ cchRESOURCE ];
128
129          if (GetClassName (hChild, szClassName, cchRESOURCE))
130             {
131             if (!lstrcmp (szClassName, TEXT("#32770"))) // WC_DIALOG
132                {
133                if (GetWindowLong (hChild, DWL_USER) == dwCOVER_SIGNATURE)
134                   {
135                   DestroyWindow (hChild);
136                   break;
137                   }
138                }
139             }
140          }
141       }
142    else
143       {
144       HWND hCover = ModelessDialogParam (IDD_APPLIB_COVER,
145                                          (lpcp->fClient) ? lpcp->hWnd : GetParent(lpcp->hWnd),
146                                          (DLGPROC)Cover_DialogProc,
147                                          (LPARAM)lp);
148
149       ShowWindow (hCover, TRUE);
150       SetWindowLong (hCover, DWL_USER, dwCOVER_SIGNATURE);
151
152       FreeString (lpcp->pszDesc);
153       FreeString (lpcp->pszButton);
154       Delete (lpcp);
155       }
156 }
157
158
159 BOOL CALLBACK Cover_DialogProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
160 {
161    switch (msg)
162       {
163       case WM_INITDIALOG:
164          LPCOVERPARAMS lpcp;
165          lpcp = (LPCOVERPARAMS)lp;
166
167          SetDlgItemText (hDlg, IDC_COVER_DESC, (lpcp && lpcp->pszDesc) ? lpcp->pszDesc : TEXT(""));
168
169          if (lpcp && lpcp->pszButton)
170             {
171             SetDlgItemText (hDlg, IDC_COVER_BUTTON, lpcp->pszButton);
172             }
173          else
174             {
175             DestroyWindow (GetDlgItem (hDlg, IDC_COVER_BUTTON));
176             }
177
178          RECT rCover;
179          if (lpcp->fClient)
180             {
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.
184             //
185             GetClientRect (lpcp->hWnd, &rCover);
186
187             for (HWND hChild = GetWindow (lpcp->hWnd, GW_CHILD);
188                  hChild != NULL;
189                  hChild = GetWindow (hChild, GW_HWNDNEXT))
190                {
191                if (hChild == hDlg)
192                   continue;
193
194                if (IsWindowVisible (hChild))
195                   {
196                   LONG dwStyleEx = GetWindowLong (hChild, GWL_EXSTYLE);
197                   SetWindowLong (hChild, GWL_EXSTYLE, dwStyleEx | WS_EX_HIDDENBYCOVER);
198                   ShowWindow (hChild, FALSE);
199                   }
200                }
201             }
202          else
203             {
204             // If we're covering a window's complete area, we've been created
205             // as a sibling of that window.  Hide that window.
206             //
207             GetRectInParent (lpcp->hWnd, &rCover);
208             ShowWindow (lpcp->hWnd, FALSE);
209             EnableWindow (lpcp->hWnd, FALSE);
210             }
211
212          if (lpcp && lpcp->pszButton)
213             {
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);
218
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.
221             //
222             if (cyRECT(rCover) > cxRECT(rCover))
223                {
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);
230                }
231             else
232                {
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);
239                }
240             }
241
242          ResizeWindow (hDlg, awdCover, rwaMoveToHere, &rCover);
243          break;
244
245       case WM_DESTROY:
246          // Show all of our parent's other children, in preparation for
247          // our going away.
248          //
249          HWND hChild;
250          for (hChild = GetWindow (GetParent (hDlg), GW_CHILD);
251               hChild != NULL;
252               hChild = GetWindow (hChild, GW_HWNDNEXT))
253             {
254             if (hChild == hDlg)
255                continue;
256
257             LONG dwStyleEx = GetWindowLong (hChild, GWL_EXSTYLE);
258             if (dwStyleEx & WS_EX_HIDDENBYCOVER)
259                {
260                SetWindowLong (hChild, GWL_EXSTYLE, dwStyleEx & (~WS_EX_HIDDENBYCOVER));
261                ShowWindow (hChild, TRUE);
262                }
263             }
264          break;
265
266       case WM_SIZE:
267          // if (lp==0), we're minimizing--don't call ResizeWindow().
268          //
269          if (lp != 0)
270             ResizeWindow (hDlg, awdCover, rwaFixupGuts);
271          break;
272
273       case WM_COMMAND:
274          switch (LOWORD(wp))
275             {
276             case IDC_COVER_BUTTON:
277                PostMessage (GetParent(hDlg), WM_COMMAND, wp, lp);
278                break;
279             }
280          break;
281       }
282
283    return FALSE;
284 }
285