windows-vs2005b2-20050706
[openafs.git] / src / WINNT / afsusrmgr / winlist.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 "TaAfsUsrMgr.h"
16 #include "winlist.h"
17
18
19 /*
20  * DEFINITIONS ________________________________________________________________
21  *
22  */
23
24 typedef struct
25    {
26    HWND hWnd;
27    WINDOWLISTTYPE wlt;
28    ASID idObject;
29    } WINDOWLISTENTRY, *LPWINDOWLISTENTRY;
30
31 static WINDOWLISTENTRY *aWindowList = NULL;
32 static size_t cWindowList = 0;
33
34 #define cREALLOC_WINDOWLIST  4
35
36
37 /*
38  * ROUTINES ___________________________________________________________________
39  *
40  */
41
42 void WindowList_Add (HWND hWnd, WINDOWLISTTYPE wlt, ASID idObject)
43 {
44    // See if this window is already in the list
45    //
46    size_t ii;
47    for (ii = 0; ii < cWindowList; ++ii)
48       {
49       if (aWindowList[ ii ].hWnd == hWnd)
50          return;
51       }
52
53    // Add this window to the list
54    //
55    for (ii = 0; ii < cWindowList; ++ii)
56       {
57       if (!aWindowList[ ii ].hWnd)
58          break;
59       }
60    if (REALLOC (aWindowList, cWindowList, 1+ii, cREALLOC_WINDOWLIST))
61       {
62       aWindowList[ ii ].hWnd = hWnd;
63       aWindowList[ ii ].wlt = wlt;
64       aWindowList[ ii ].idObject = idObject;
65       AfsAppLib_RegisterModelessDialog (hWnd);
66       }
67 }
68
69
70 HWND WindowList_Search (WINDOWLISTTYPE wlt, ASID idObject)
71 {
72    for (size_t ii = 0; ii < cWindowList; ++ii)
73       {
74       if (!aWindowList[ ii ].hWnd)
75          continue;
76       if (aWindowList[ ii ].wlt != wlt)
77          continue;
78       if ((idObject != ASID_ANY) && (aWindowList[ ii ].idObject != idObject))
79          continue;
80       return aWindowList[ ii ].hWnd;
81       }
82    return NULL;
83 }
84
85
86 void WindowList_Remove (HWND hWnd)
87 {
88    for (size_t ii = 0; ii < cWindowList; ++ii)
89       {
90       if (aWindowList[ ii ].hWnd == hWnd)
91          aWindowList[ ii ].hWnd = NULL;
92       }
93 }
94