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>
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
51 TCHAR szField
[ cchNAME
];
53 static size_t cFields
= 0;
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
)
82 LeaveCriticalSection (pcsPump
);
83 Subclass_RemoveHook (hDlg
, Modeless_HookProc
);
87 return CallWindowProc ((WNDPROC
)oldProc
, hDlg
, msg
, wp
, lp
);
89 return DefWindowProc (hDlg
, msg
, wp
, lp
);
93 BOOL
AfsAppLib_IsModelessDialogMessage (MSG
*lpm
)
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
))
114 if (IsDialogMessage (aModeless
[ ii
], lpm
))
120 LeaveCriticalSection (pcsPump
);
127 void AfsAppLib_RegisterModelessDialog (HWND hDlg
)
131 pcsPump
= New (CRITICAL_SECTION
);
132 InitializeCriticalSection (pcsPump
);
135 EnterCriticalSection (pcsPump
);
138 for (ii
= 0; ii
< cModeless
; ++ii
)
140 if (aModeless
[ ii
] == hDlg
)
145 for (ii
= 0; ii
< cModeless
; ++ii
)
147 if (aModeless
[ ii
] == 0)
152 (void)REALLOC (aModeless
, cModeless
, 1+ii
, cREALLOC_MODELESS
);
156 aModeless
[ ii
] = hDlg
;
157 Subclass_AddHook (hDlg
, Modeless_HookProc
);
161 LeaveCriticalSection (pcsPump
);
165 void AfsAppLib_SetPumpRoutine (void (*fnPump
)(MSG
*lpm
))
171 void AfsAppLib_MainPump (void)
175 while (GetMessage (&msg
, NULL
, 0, 0))
177 if (AfsAppLib_IsModelessDialogMessage (&msg
))
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
);
217 return CallWindowProc ((WNDPROC
)oldProc
, hWnd
, msg
, wp
, lp
);
219 return DefWindowProc (hWnd
, msg
, wp
, lp
);
223 size_t GetWindowDataField (LPTSTR pszField
)
225 size_t rc
= (size_t)-1;
229 pcsData
= New (CRITICAL_SECTION
);
230 InitializeCriticalSection (pcsData
);
232 EnterCriticalSection (pcsData
);
235 for (ii
= 0; ii
< cFields
; ++ii
)
237 if (!lstrcmpi (aFields
[ ii
].szField
, pszField
))
242 for (ii
= 0; ii
< cFields
; ++ii
)
244 if (aFields
[ ii
].szField
[0] == TEXT('\0'))
249 (void)REALLOC (aFields
, cFields
, 1+ii
, cREALLOC_WINDOWDATA_FIELDS
);
253 lstrcpy (aFields
[ ii
].szField
, pszField
);
261 LeaveCriticalSection (pcsData
);
266 UINT_PTR
GetWindowData (HWND hWnd
, LPTSTR pszField
)
272 pcsData
= New (CRITICAL_SECTION
);
273 InitializeCriticalSection (pcsData
);
275 EnterCriticalSection (pcsData
);
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
];
291 LeaveCriticalSection (pcsData
);
296 UINT_PTR
SetWindowData (HWND hWnd
, LPTSTR pszField
, UINT_PTR dwNewData
)
302 pcsData
= New (CRITICAL_SECTION
);
303 InitializeCriticalSection (pcsData
);
305 EnterCriticalSection (pcsData
);
308 if ((iField
= GetWindowDataField (pszField
)) != (size_t)-1)
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
];
322 for (ii
= 0; ii
< cWindows
; ++ii
)
324 if (aWindows
[ ii
].hWnd
== 0)
329 (void)REALLOC (aWindows
, cWindows
, 1+ii
, cREALLOC_WINDOWDATA_WINDOWS
);
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
);