Windows: roken.h ordering
[openafs.git] / src / WINNT / afssvrmgr / svr_general.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 "svr_general.h"
21 #include "propcache.h"
22 #include "display.h"
23
24
25 /*
26  * SERVER PREFERENCES _________________________________________________________
27  *
28  */
29
30 PVOID Server_LoadPreferences (LPIDENT lpiServer)
31 {
32    LPSERVER_PREF psp = New (SERVER_PREF);
33
34    if (!RestorePreferences (lpiServer, psp, sizeof(SERVER_PREF)))
35       {
36       Alert_SetDefaults (&psp->oa);
37
38       psp->perWarnAggFull = perDEFAULT_AGGFULL_WARNING;
39       psp->perWarnSetFull = perDEFAULT_SETFULL_WARNING;
40       psp->fWarnSvcStop = fDEFAULT_SVCSTOP_WARNING;
41       psp->fWarnSvrTimeout = TRUE;
42       psp->fWarnSetNoVLDB = TRUE;
43       psp->fWarnSetNoServ = TRUE;
44       psp->fWarnAggNoServ = TRUE;
45       psp->fWarnAggAlloc = FALSE;
46
47       psp->rLast.right = 0;
48       psp->fOpen = FALSE;
49       psp->fExpandTree = TRUE;
50       }
51
52    psp->fIsMonitored = TRUE; // until dispatch.cpp sets it otherwise
53
54    Alert_Initialize (&psp->oa);
55    return psp;
56 }
57
58
59 BOOL Server_SavePreferences (LPIDENT lpiServer)
60 {
61    BOOL rc = FALSE;
62
63    PVOID psp = lpiServer->GetUserParam();
64    if (psp != NULL)
65       {
66       rc = StorePreferences (lpiServer, psp, sizeof(SERVER_PREF));
67       }
68
69    return rc;
70 }
71
72
73 /*
74  * ROUTINES ___________________________________________________________________
75  *
76  */
77
78 void Server_ShowPopupMenu (HWND hList, POINT ptList, POINT ptScreen)
79 {
80    if (!ptScreen.x && !ptScreen.y)
81       {
82       RECT rWindow;
83       GetWindowRect (hList, &rWindow);
84       ptScreen.x = rWindow.left + (rWindow.right -rWindow.left)/2;
85       ptScreen.y = rWindow.top + (rWindow.bottom -rWindow.top)/2;
86       Server_ShowParticularPopupMenu (hList, ptScreen, NULL);
87       }
88    else if (FL_HitTestForHeaderBar (hList, ptList))
89       {
90       HMENU hm = TaLocale_LoadMenu (MENU_COLUMNS);
91       DisplayContextMenu (hm, ptScreen, hList);
92       }
93    else
94       {
95       LPIDENT lpiServer = NULL;
96
97       HLISTITEM hItem;
98       if ((hItem = FastList_ItemFromPoint (hList, &ptList, TRUE)) != NULL)
99          lpiServer = (LPIDENT)FL_GetData (hList, hItem);
100
101       if (lpiServer && (lpiServer != (LPIDENT)FL_GetSelectedData (hList)))
102          lpiServer = NULL;
103
104       Server_ShowParticularPopupMenu (hList, ptScreen, lpiServer);
105       }
106 }
107
108
109 void Server_ShowParticularPopupMenu (HWND hParent, POINT ptScreen, LPIDENT lpiServer)
110 {
111    HMENU hm;
112
113    if (lpiServer == NULL)
114       hm = TaLocale_LoadMenu (MENU_SVR_NONE);
115    else
116       hm = TaLocale_LoadMenu (MENU_SVR);
117
118    if (hm != NULL)
119       {
120       if (lpiServer == NULL)
121          {
122          int lvs = (gr.fPreview && !gr.fVert) ? gr.diHorz.viewSvr.lvsView : gr.diVert.viewSvr.lvsView;
123          HMENU hmView = GetSubMenu (hm, 0);
124
125          CheckMenuRadioItem (hmView,
126                              M_SVR_VIEW_LARGE, M_SVR_VIEW_REPORT,
127                              ( (lvs == FLS_VIEW_SMALL) ? M_SVR_VIEW_SMALL :
128                                (lvs == FLS_VIEW_LIST)  ? M_SVR_VIEW_REPORT :
129                                                          M_SVR_VIEW_LARGE ),
130                              MF_BYCOMMAND);
131
132          ICONVIEW ivSvr = Display_GetServerIconView();
133
134          CheckMenuRadioItem (hmView,
135                              M_SVR_VIEW_ONEICON, M_SVR_VIEW_STATUS,
136                              (ivSvr == ivTWOICONS) ? M_SVR_VIEW_TWOICONS :
137                              (ivSvr == ivONEICON)  ? M_SVR_VIEW_ONEICON : M_SVR_VIEW_STATUS,
138                              MF_BYCOMMAND);
139
140          if (lvs != FLS_VIEW_LIST)
141             {
142             EnableMenu (hmView, M_SVR_VIEW_ONEICON,  FALSE);
143             EnableMenu (hmView, M_SVR_VIEW_TWOICONS, FALSE);
144             EnableMenu (hmView, M_SVR_VIEW_STATUS,   FALSE);
145             }
146
147          if (!PropCache_Search (pcSERVER, ANYVALUE))
148             EnableMenu (hmView, M_SVR_CLOSEALL, FALSE);
149          }
150       else
151          {
152          BOOL fOpenNow = (BOOL)!!(PropCache_Search (pcSERVER, lpiServer));
153
154          LPSERVER_PREF lpsp;
155          if ( ((lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) == NULL) ||
156               (lpsp->fIsMonitored) )
157             {
158             EnableMenu (hm, M_SVR_OPEN,  !fOpenNow);
159             EnableMenu (hm, M_SVR_CLOSE,  fOpenNow);
160             CheckMenu (hm, M_SVR_MONITOR, TRUE);
161             }
162          else
163             {
164             if (!fOpenNow)
165                EnableMenu (hm, M_SVR_CLOSE, FALSE);
166             if (fOpenNow || !gr.fOpenMonitors)
167                EnableMenu (hm, M_SVR_OPEN, FALSE);
168
169             CheckMenu (hm, M_SVR_MONITOR, FALSE);
170
171             EnableMenu (hm, M_SVR_SECURITY,  FALSE);
172             EnableMenu (hm, M_SALVAGE,  FALSE);
173             EnableMenu (hm, M_SET_CLONE,  FALSE);
174             EnableMenu (hm, M_SET_UNLOCK, FALSE);
175             EnableMenu (hm, M_SYNCVLDB,   FALSE);
176             }
177          }
178
179       DisplayContextMenu (hm, ptScreen, hParent);
180       }
181 }
182