Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / WINNT / afssvrmgr / agg_tab.cpp
1 extern "C" {
2 #include <afs/param.h>
3 #include <afs/stds.h>
4 }
5
6 #include "svrmgr.h"
7 #include "agg_tab.h"
8 #include "agg_general.h"
9 #include "svr_window.h"
10 #include "svr_general.h"
11 #include "display.h"
12 #include "command.h"
13
14
15 /*
16  * RESIZING WINDOWS ___________________________________________________________
17  *
18  */
19
20 rwWindowData awdAggregates[] = {
21     { IDC_AGG_DESC,        raSizeX           },
22     { IDC_AGG_LIST,        raSizeX | raSizeY },
23     { IDC_AGG_CREATESET,   raMoveX | raMoveY },
24     { idENDLIST,           0                 }
25  };
26
27
28 /*
29  * PROTOTYPES _________________________________________________________________
30  *
31  */
32
33 void Aggregates_OnNotifyFromDispatch (LPNOTIFYSTRUCT lpns);
34
35 void Aggregates_SubclassList (HWND hDlg);
36
37
38 /*
39  * ROUTINES ___________________________________________________________________
40  *
41  */
42
43 BOOL CALLBACK Aggregates_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
44 {
45    if (HandleColumnNotify (hDlg, msg, wp, lp, &gr.viewAgg))
46       return FALSE;
47
48    switch (msg)
49       {
50       case WM_INITDIALOG:
51          {
52          RECT rTab;
53          GetClientRect (GetParent(hDlg), &rTab);
54          TabCtrl_AdjustRect (GetParent (hDlg), FALSE, &rTab); 
55          ResizeWindow (hDlg, awdAggregates, rwaMoveToHere, &rTab);
56
57          FL_RestoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAgg);
58          FastList_SetTextCallback (GetDlgItem (hDlg, IDC_AGG_LIST), GetItemText, (DWORD)&gr.viewAgg);
59
60          Aggregates_SubclassList (hDlg);
61          }
62          break;
63
64       case WM_HELP:
65          WinHelp (hDlg, cszHELPFILENAME, HELP_FINDER, 0);
66          break;
67
68       case WM_DESTROY:
69          DontNotifyMeEver (hDlg);
70          FL_StoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAgg);
71          break;
72
73       case WM_SIZE:
74          // if (lp==0), we're minimizing--don't call ResizeWindow().
75          //
76          if (lp != 0)
77             ResizeWindow (hDlg, awdAggregates, rwaFixupGuts);
78          break;
79
80       case WM_SERVER_CHANGED:
81          {
82          LPIDENT lpiServer = Server_GetServerForChild (hDlg);
83          DontNotifyMeEver (hDlg);
84          NotifyMe (WHEN_AGGS_CHANGE, lpiServer, hDlg, 0);
85
86          // Fix the text at the top of the Aggregates tab:
87          //
88          TCHAR szName[ cchRESOURCE ];
89          LPTSTR pszText;
90
91          if (lpiServer != NULL)
92             {
93             LPSERVER_PREF lpsp = (LPSERVER_PREF)lpiServer->GetUserParam();
94             lpiServer->GetServerName (szName);
95             if (lpsp && !lpsp->fIsMonitored)
96                pszText = FormatString (IDS_AGGREGATE_UNMON, TEXT("%s"), szName);
97             else
98                pszText = FormatString (IDS_AGGREGATES_IN_SERVER, TEXT("%s"), szName);
99             }
100          else if (g.lpiCell != NULL)
101             {
102             g.lpiCell->GetCellName (szName);
103             if (g.sub)
104                pszText = FormatString (IDS_AGGREGATE_SOME, TEXT("%s"), szName);
105             else
106                pszText = FormatString (IDS_AGGREGATES_IN_CELL, TEXT("%s"), szName);
107             }
108          else
109             {
110             pszText = FormatString (IDS_AGGREGATES_IN_NOTHING);
111             }
112
113          SetDlgItemText (hDlg, IDC_AGG_DESC, pszText);
114          FreeString (pszText);
115
116          UpdateDisplay_Aggregates (FALSE, GetDlgItem (hDlg, IDC_AGG_LIST), NULL, 0, NULL, NULL, NULL);
117          }
118          break;
119
120       case WM_NOTIFY_FROM_DISPATCH:
121          Aggregates_OnNotifyFromDispatch ((LPNOTIFYSTRUCT)lp);
122          Delete ((LPNOTIFYSTRUCT)lp);
123          break;
124
125       case WM_NOTIFY: 
126          switch (((LPNMHDR)lp)->code)
127             { 
128             case FLN_LDBLCLICK:
129                if (((LPNMHDR)lp)->hwndFrom == GetDlgItem (hDlg, IDC_AGG_LIST))
130                   {
131                   if (FL_GetSelectedData (GetDlgItem (hDlg, IDC_AGG_LIST)))
132                      PostMessage (GetDlgItem (hDlg, IDC_AGG_LIST), WM_COMMAND, M_PROPERTIES, 0);
133                   return TRUE;
134                   }
135                break;
136             }
137          break;
138
139       case WM_CONTEXTMENU: 
140          {
141          POINT ptScreen;
142          POINT ptClient;
143          ptScreen.x = LOWORD(lp);
144          ptScreen.y = HIWORD(lp);
145
146          ptClient = ptScreen;
147          ScreenToClient ((HWND)wp, &ptClient);
148
149          if ((HWND)wp == GetDlgItem (hDlg, IDC_AGG_LIST))
150             Aggregates_ShowPopupMenu ((HWND)wp, ptClient, ptScreen);
151          }
152          break; 
153
154       case WM_COMMAND:
155          switch (LOWORD(wp))
156             {
157             case IDC_AGG_CREATESET:
158                SendMessage (GetDlgItem (hDlg, IDC_AGG_LIST), WM_COMMAND, M_SET_CREATE, 0);
159                break;
160             }
161          break;
162       }
163
164    return FALSE;
165 }
166
167
168 void Aggregates_OnNotifyFromDispatch (LPNOTIFYSTRUCT lpns)
169 {
170    switch (lpns->evt)
171       {
172       case evtRefreshAggregatesEnd:
173       case evtRefreshStatusEnd:
174       case evtAlertsChanged:
175       case evtDestroy:
176          UpdateDisplay_Aggregates (FALSE, GetDlgItem (lpns->hwndTarget, IDC_AGG_LIST), lpns->Params.lpi1, lpns->Params.status, NULL, NULL, NULL);
177          break;
178       }
179 }
180
181
182 static LONG procAggregatesList = 0;
183
184 LRESULT CALLBACK Aggregates_SubclassListProc (HWND hList, UINT msg, WPARAM wp, LPARAM lp)
185 {
186    LRESULT rc;
187
188    if (procAggregatesList == 0)
189       rc = DefWindowProc (hList, msg, wp, lp);
190    else
191       rc = CallWindowProc ((WNDPROC)procAggregatesList, hList, msg, wp, lp);
192
193    switch (msg)
194       {
195       case WM_DESTROY:
196          if (procAggregatesList != 0)
197             SetWindowLong (hList, GWL_WNDPROC, procAggregatesList);
198          break;
199
200       case WM_COMMAND:
201          StartContextCommand (Server_GetWindowForChild (GetParent(hList)),
202                               Server_GetServerForChild (GetParent(hList)),
203                               Aggregates_GetFocused (GetParent(hList)),
204                               LOWORD(wp));
205          break;
206       }
207
208    return rc;
209 }
210
211
212 void Aggregates_SubclassList (HWND hDlg)
213 {
214    HWND hList = GetDlgItem (hDlg, IDC_AGG_LIST);
215    procAggregatesList = GetWindowLong (hList, GWL_WNDPROC);
216    SetWindowLong (hList, GWL_WNDPROC, (LONG)Aggregates_SubclassListProc);
217 }
218
219
220 void Aggregates_ShowPopupMenu (HWND hList, POINT ptList, POINT ptScreen)
221 {
222    if (!ptScreen.x && !ptScreen.y)
223       {
224       RECT rWindow;
225       GetWindowRect (hList, &rWindow);
226       ptScreen.x = rWindow.left + (rWindow.right -rWindow.left)/2;
227       ptScreen.y = rWindow.top + (rWindow.bottom -rWindow.top)/2;
228       Aggregates_ShowParticularPopupMenu (hList, ptScreen, NULL);
229       }
230    else if (FL_HitTestForHeaderBar (hList, ptList))
231       {
232       HMENU hm = TaLocale_LoadMenu (MENU_COLUMNS);
233       DisplayContextMenu (hm, ptScreen, hList);
234       }
235    else
236       {
237       LPIDENT lpiSelected = NULL;
238
239       HLISTITEM hItem;
240       if ((hItem = FastList_ItemFromPoint (hList, &ptList, TRUE)) != NULL)
241          lpiSelected = (LPIDENT)FastList_GetItemParam (hList, hItem);
242
243       if (lpiSelected && (lpiSelected != (LPIDENT)FL_GetSelectedData (hList)))
244          lpiSelected = NULL;
245
246       if (lpiSelected && lpiSelected->fIsServer())
247          Server_ShowParticularPopupMenu (hList, ptScreen, lpiSelected);
248       else
249          Aggregates_ShowParticularPopupMenu (hList, ptScreen, lpiSelected);
250       }
251 }
252
253
254 void Aggregates_ShowParticularPopupMenu (HWND hParent, POINT ptScreen, LPIDENT lpiAggregate)
255 {
256    HMENU hm;
257
258    if (lpiAggregate == NULL)
259       hm = TaLocale_LoadMenu (MENU_AGG_NONE);
260    else
261       hm = TaLocale_LoadMenu (MENU_AGG);
262
263    if (hm != NULL)
264       {
265       if (lpiAggregate == NULL)
266          {
267          HMENU hmView = GetSubMenu (hm, 0);
268
269          CheckMenuRadioItem (hmView,
270                              M_VIEW_ONEICON, M_VIEW_STATUS,
271                              (gr.ivAgg == ivTWOICONS) ? M_VIEW_TWOICONS :
272                              (gr.ivAgg == ivONEICON)  ? M_VIEW_ONEICON : M_VIEW_STATUS,
273                              MF_BYCOMMAND);
274          }
275
276       DisplayContextMenu (hm, ptScreen, hParent);
277       }
278 }
279