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