windows-build-updates-20030314
[openafs.git] / src / WINNT / afssvrmgr / propcache.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 "svrmgr.h"
16 #include "propcache.h"
17
18
19 /*
20  * PROPERTIES-DIALOG CACHE ____________________________________________________
21  *
22  */
23
24 typedef struct
25    {
26    BOOL fInUse;
27    PropCache pcType;
28    PVOID pv;
29    HWND hDialog;
30    } PropCacheEntry;
31
32 static size_t PropCache_nEntries = 0;
33 static PropCacheEntry *PropCache_apce = NULL;
34
35 void PropCache_Add (PropCache pcType, PVOID pv, HWND hDialog)
36 {
37    if (!PropCache_Search (pcType, pv))
38       {
39       for (size_t iEntry = 0; iEntry < PropCache_nEntries; ++iEntry)
40          {
41          if (!PropCache_apce[ iEntry ].fInUse)
42             break;
43          }
44
45       if (iEntry == PropCache_nEntries)
46          {
47          if (!REALLOC (PropCache_apce, PropCache_nEntries, 1+iEntry, 16))
48             return;
49          }
50
51       PropCache_apce[ iEntry ].fInUse = TRUE;
52       PropCache_apce[ iEntry ].pcType = pcType;
53       PropCache_apce[ iEntry ].pv = pv;
54       PropCache_apce[ iEntry ].hDialog = hDialog;
55
56       if (pcType != pcSERVER)
57          AfsAppLib_RegisterModelessDialog (hDialog);
58       }
59 }
60
61
62 HWND PropCache_Search (PropCache pcType, PVOID pv, HWND hwndStart)
63 {
64    size_t iEntry = 0;
65
66    if (hwndStart != NULL)
67       {
68       for ( ; iEntry < PropCache_nEntries; ++iEntry)
69          {
70          if (!PropCache_apce[ iEntry ].fInUse)
71             continue;
72          if (PropCache_apce[ iEntry ].hDialog == hwndStart)
73             {
74             ++iEntry;
75             break;
76             }
77          }
78       }
79
80    for ( ; iEntry < PropCache_nEntries; ++iEntry)
81       {
82       if (!PropCache_apce[ iEntry ].fInUse)
83          continue;
84
85       if ( (PropCache_apce[ iEntry ].pcType == pcType) &&
86            ((pv == ANYVALUE) || (PropCache_apce[ iEntry ].pv == pv)) )
87          {
88          if (!IsWindow (PropCache_apce[ iEntry ].hDialog))
89             {
90             PropCache_apce[ iEntry ].fInUse = FALSE;
91             continue;
92             }
93
94          return PropCache_apce[ iEntry ].hDialog;
95          }
96       }
97
98    return NULL;
99 }
100
101
102 void PropCache_Delete (PropCache pcType, PVOID pv)
103 {
104    for (size_t iEntry = 0; iEntry < PropCache_nEntries; ++iEntry)
105       {
106       if (!PropCache_apce[ iEntry ].fInUse)
107          continue;
108
109       if ( (PropCache_apce[ iEntry ].pcType == pcType) &&
110            ((pv == ANYVALUE) || (PropCache_apce[ iEntry ].pv == pv)) )
111          {
112          PropCache_apce[ iEntry ].fInUse = FALSE;
113          }
114       }
115 }
116
117
118 void PropCache_Delete (HWND hDialog)
119 {
120    for (size_t iEntry = 0; iEntry < PropCache_nEntries; ++iEntry)
121       {
122       if (!PropCache_apce[ iEntry ].fInUse)
123          continue;
124
125       if (PropCache_apce[ iEntry ].hDialog == hDialog)
126          {
127          PropCache_apce[ iEntry ].fInUse = FALSE;
128          }
129       }
130 }
131