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