Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afsapplib / al_pump.cpp
blob957031a1264b0b14ba36e32cf16eea040957e1d8
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 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include <WINNT/afsapplib.h>
22 * DEFINITIONS ________________________________________________________________
26 #define cREALLOC_MODELESS 16
27 #define cREALLOC_WINDOWDATA_FIELDS 4
28 #define cREALLOC_WINDOWDATA_WINDOWS 16
29 #define cREALLOC_WINDOWDATA_DATA 8
31 #define GWD_IS_MODELESS TEXT("afsapplib/al_pump.cpp - is window modeless?")
35 * VARIABLES __________________________________________________________________
39 // Modeless-dialog support
41 static HWND *aModeless = NULL;
42 static size_t cModeless = 0;
43 static LPCRITICAL_SECTION pcsPump = NULL;
45 static void (*g_fnPump)(MSG *lpm) = NULL;
47 // Window-data support
49 static struct
51 TCHAR szField[ cchNAME ];
52 } *aFields = NULL;
53 static size_t cFields = 0;
55 static struct
57 HWND hWnd;
58 UINT_PTR *adwData;
59 size_t cdwData;
60 } *aWindows = NULL;
61 static size_t cWindows = 0;
62 static LPCRITICAL_SECTION pcsData = NULL;
66 * DIALOG ROUTINES ____________________________________________________________
70 HRESULT CALLBACK Modeless_HookProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
72 PVOID oldProc = Subclass_FindNextHook (hDlg, Modeless_HookProc);
74 if (msg == WM_DESTROY)
76 EnterCriticalSection (pcsPump);
77 for (size_t ii = 0; ii < cModeless; ++ii)
79 if (aModeless[ ii ] == hDlg)
80 aModeless[ ii ] = 0;
82 LeaveCriticalSection (pcsPump);
83 Subclass_RemoveHook (hDlg, Modeless_HookProc);
86 if (oldProc)
87 return CallWindowProc ((WNDPROC)oldProc, hDlg, msg, wp, lp);
88 else
89 return DefWindowProc (hDlg, msg, wp, lp);
93 BOOL AfsAppLib_IsModelessDialogMessage (MSG *lpm)
95 BOOL rc = FALSE;
97 if (pcsPump)
99 EnterCriticalSection (pcsPump);
101 for (size_t ii = 0; (!rc) && (ii < cModeless); ++ii)
103 if (aModeless[ ii ] != 0)
105 if (IsPropSheet (aModeless[ ii ]))
107 if (!PropSheet_GetCurrentPageHwnd(aModeless[ ii ]))
108 DestroyWindow (aModeless[ ii ]);
109 if (PropSheet_IsDialogMessage(aModeless[ ii ], lpm))
110 rc = TRUE;
112 else
114 if (IsDialogMessage (aModeless[ ii ], lpm))
115 rc = TRUE;
120 LeaveCriticalSection (pcsPump);
123 return rc;
127 void AfsAppLib_RegisterModelessDialog (HWND hDlg)
129 if (pcsPump == NULL)
131 pcsPump = New (CRITICAL_SECTION);
132 InitializeCriticalSection (pcsPump);
135 EnterCriticalSection (pcsPump);
137 size_t ii;
138 for (ii = 0; ii < cModeless; ++ii)
140 if (aModeless[ ii ] == hDlg)
141 break;
143 if (ii == cModeless)
145 for (ii = 0; ii < cModeless; ++ii)
147 if (aModeless[ ii ] == 0)
148 break;
150 if (ii == cModeless)
152 (void)REALLOC (aModeless, cModeless, 1+ii, cREALLOC_MODELESS);
154 if (ii < cModeless)
156 aModeless[ ii ] = hDlg;
157 Subclass_AddHook (hDlg, Modeless_HookProc);
161 LeaveCriticalSection (pcsPump);
165 void AfsAppLib_SetPumpRoutine (void (*fnPump)(MSG *lpm))
167 g_fnPump = fnPump;
171 void AfsAppLib_MainPump (void)
173 MSG msg;
175 while (GetMessage (&msg, NULL, 0, 0))
177 if (AfsAppLib_IsModelessDialogMessage (&msg))
178 continue;
180 if (g_fnPump)
181 (*g_fnPump)(&msg);
182 else
184 TranslateMessage (&msg);
185 DispatchMessage (&msg);
192 * WINDOW-DATA ________________________________________________________________
196 HRESULT CALLBACK WindowData_HookProc (HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
198 PVOID oldProc = Subclass_FindNextHook (hWnd, WindowData_HookProc);
200 if (msg == WM_DESTROY)
202 EnterCriticalSection (pcsData);
203 for (size_t ii = 0; ii < cWindows; ++ii)
205 if (aWindows[ ii ].hWnd == hWnd)
207 if (aWindows[ ii ].adwData)
208 Free (aWindows[ ii ].adwData);
209 memset (&aWindows[ii], 0x00, sizeof(aWindows[ii]));
212 LeaveCriticalSection (pcsData);
213 Subclass_RemoveHook (hWnd, WindowData_HookProc);
216 if (oldProc)
217 return CallWindowProc ((WNDPROC)oldProc, hWnd, msg, wp, lp);
218 else
219 return DefWindowProc (hWnd, msg, wp, lp);
223 size_t GetWindowDataField (LPTSTR pszField)
225 size_t rc = (size_t)-1;
227 if (pcsData == NULL)
229 pcsData = New (CRITICAL_SECTION);
230 InitializeCriticalSection (pcsData);
232 EnterCriticalSection (pcsData);
234 size_t ii;
235 for (ii = 0; ii < cFields; ++ii)
237 if (!lstrcmpi (aFields[ ii ].szField, pszField))
238 break;
240 if (ii == cFields)
242 for (ii = 0; ii < cFields; ++ii)
244 if (aFields[ ii ].szField[0] == TEXT('\0'))
245 break;
247 if (ii == cFields)
249 (void)REALLOC (aFields, cFields, 1+ii, cREALLOC_WINDOWDATA_FIELDS);
251 if (ii < cFields)
253 lstrcpy (aFields[ ii ].szField, pszField);
256 if (ii < cFields)
258 rc = ii;
261 LeaveCriticalSection (pcsData);
262 return rc;
266 UINT_PTR GetWindowData (HWND hWnd, LPTSTR pszField)
268 UINT_PTR rc = 0;
270 if (pcsData == NULL)
272 pcsData = New (CRITICAL_SECTION);
273 InitializeCriticalSection (pcsData);
275 EnterCriticalSection (pcsData);
277 size_t iField;
278 if ((iField = GetWindowDataField (pszField)) != (size_t)-1)
280 for (size_t ii = 0; ii < cWindows; ++ii)
282 if (aWindows[ ii ].hWnd == hWnd)
284 if (iField < aWindows[ ii ].cdwData)
285 rc = aWindows[ ii ].adwData[ iField ];
286 break;
291 LeaveCriticalSection (pcsData);
292 return rc;
296 UINT_PTR SetWindowData (HWND hWnd, LPTSTR pszField, UINT_PTR dwNewData)
298 UINT_PTR rc = 0;
300 if (pcsData == NULL)
302 pcsData = New (CRITICAL_SECTION);
303 InitializeCriticalSection (pcsData);
305 EnterCriticalSection (pcsData);
307 size_t iField;
308 if ((iField = GetWindowDataField (pszField)) != (size_t)-1)
310 size_t ii;
311 for (ii = 0; ii < cWindows; ++ii)
313 if (aWindows[ ii ].hWnd == hWnd)
315 if (iField < aWindows[ ii ].cdwData)
316 rc = aWindows[ ii ].adwData[ iField ];
317 break;
320 if (ii == cWindows)
322 for (ii = 0; ii < cWindows; ++ii)
324 if (aWindows[ ii ].hWnd == 0)
325 break;
327 if (ii == cWindows)
329 (void)REALLOC (aWindows, cWindows, 1+ii, cREALLOC_WINDOWDATA_WINDOWS);
332 if (ii < cWindows)
334 if (aWindows[ ii ].hWnd == 0)
336 aWindows[ ii ].hWnd = hWnd;
337 Subclass_AddHook (hWnd, WindowData_HookProc);
339 if ((dwNewData) && (iField >= aWindows[ ii ].cdwData))
341 (void)REALLOC (aWindows[ ii ].adwData, aWindows[ ii ].cdwData, 1+iField, cREALLOC_WINDOWDATA_DATA);
343 if (iField < aWindows[ ii ].cdwData)
345 aWindows[ ii ].adwData[ iField ] = dwNewData;
350 LeaveCriticalSection (pcsData);
351 return rc;