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