Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / columns.cpp
blob5b90d8aef21b8937f7e0becc18ac10a7388f45a5
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "svrmgr.h"
19 #include "columns.h"
20 #include "svr_window.h"
21 #include "propcache.h"
22 #include "display.h"
26 * PROTOTYPES _________________________________________________________________
30 BOOL CALLBACK Columns_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
31 void Columns_OnInitDialog (HWND hDlg, LPVIEWINFO lpviDefault);
32 void Columns_OnSelect (HWND hDlg);
33 void Columns_OnSelAvail (HWND hDlg);
34 void Columns_OnSelShown (HWND hDlg);
35 void Columns_OnInsert (HWND hDlg);
36 void Columns_OnDelete (HWND hDlg);
37 void Columns_OnMoveUp (HWND hDlg);
38 void Columns_OnMoveDown (HWND hDlg);
39 BOOL Columns_OnApply (HWND hDlg, LPVIEWINFO lpviDefault);
43 * COLUMNS DIALOG _____________________________________________________________
47 typedef enum
49 ceSERVERS = 0, // gr.di*.viewSvr
50 ceFILESETS, // gr.viewSet
51 ceAGGREGATES, // gr.viewAgg
52 ceSERVICES, // gr.viewSvc
53 ceREPLICAS, // gr.viewRep
54 ceAGGS_MOVE, // gr.viewAggMove
55 ceAGGS_CREATE, // gr.viewAggCreate
56 ceAGGS_RESTORE // gr.viewAggRestore
57 } COLUMNS_ENTRY;
59 static struct
61 int ids;
62 BOOL fUsuallyHidden;
63 VIEWINFO vi;
64 BOOL fChanged;
66 COLUMNS[] =
68 { IDS_COL_SERVERS, FALSE, {0}, FALSE }, // ceSERVERS
69 { IDS_COL_FILESETS, FALSE, {0}, FALSE }, // ceFILESETS
70 { IDS_COL_AGGREGATES, FALSE, {0}, FALSE }, // ceAGGREGATES
71 { IDS_COL_SERVICES, FALSE, {0}, FALSE }, // ceSERVICES
72 { IDS_COL_REPLICAS, FALSE, {0}, FALSE }, // ceREPLICAS
73 { IDS_COL_AGGS_MOVE, TRUE, {0}, FALSE }, // ceAGG_MOVE
74 { IDS_COL_AGGS_CREATE, TRUE, {0}, FALSE }, // ceAGG_CREATE
75 { IDS_COL_AGGS_RESTORE, TRUE, {0}, FALSE } // ceAGG_RESTORE
78 #define nCOLUMNS (sizeof(COLUMNS)/sizeof(COLUMNS[0]))
80 typedef struct
82 HWND hParent;
83 LPVIEWINFO lpviDefault;
84 } ShowColumnsParams;
86 void ShowColumnsDialog (HWND hParent, LPVIEWINFO lpvi)
88 for (size_t iCol = 0; iCol < nCOLUMNS; ++iCol)
90 COLUMNS[ iCol ].fChanged = FALSE;
93 if (gr.fPreview && !gr.fVert)
94 memcpy (&COLUMNS[ ceSERVERS ].vi, &gr.diHorz.viewSvr, sizeof(VIEWINFO));
95 else
96 memcpy (&COLUMNS[ ceSERVERS ].vi, &gr.diVert.viewSvr, sizeof(VIEWINFO));
98 memcpy (&COLUMNS[ ceFILESETS ].vi, &gr.viewSet, sizeof(VIEWINFO));
99 memcpy (&COLUMNS[ ceAGGREGATES ].vi, &gr.viewAgg, sizeof(VIEWINFO));
100 memcpy (&COLUMNS[ ceSERVICES ].vi, &gr.viewSvc, sizeof(VIEWINFO));
101 memcpy (&COLUMNS[ ceREPLICAS ].vi, &gr.viewRep, sizeof(VIEWINFO));
102 memcpy (&COLUMNS[ ceAGGS_MOVE ].vi, &gr.viewAggMove, sizeof(VIEWINFO));
103 memcpy (&COLUMNS[ ceAGGS_CREATE ].vi, &gr.viewAggCreate, sizeof(VIEWINFO));
104 memcpy (&COLUMNS[ ceAGGS_RESTORE ].vi, &gr.viewAggRestore, sizeof(VIEWINFO));
106 if (lpvi == &gr.viewSet)
107 lpvi = &COLUMNS[ ceFILESETS ].vi;
108 else if (lpvi == &gr.viewAgg)
109 lpvi = &COLUMNS[ ceAGGREGATES ].vi;
110 else if (lpvi == &gr.viewSvc)
111 lpvi = &COLUMNS[ ceSERVICES ].vi;
112 else if (lpvi == &gr.viewRep)
113 lpvi = &COLUMNS[ ceREPLICAS ].vi;
114 else if (lpvi == &gr.viewAggMove)
115 lpvi = &COLUMNS[ ceAGGS_MOVE ].vi;
116 else if (lpvi == &gr.viewAggCreate)
117 lpvi = &COLUMNS[ ceAGGS_CREATE ].vi;
118 else if (lpvi == &gr.viewAggRestore)
119 lpvi = &COLUMNS[ ceAGGS_RESTORE ].vi;
120 else
121 lpvi = &COLUMNS[ ceSERVERS ].vi;
123 LPPROPSHEET psh = PropSheet_Create (IDS_COLUMNS_TITLE, FALSE);
124 psh->sh.hwndParent = hParent;
126 ShowColumnsParams *pscp = New (ShowColumnsParams);
127 pscp->hParent = hParent;
128 pscp->lpviDefault = lpvi;
130 PropSheet_AddTab (psh, 0, IDD_COLUMNS, (DLGPROC)Columns_DlgProc, (LPARAM)pscp, TRUE);
131 PropSheet_ShowModal (psh, PumpMessage);
135 BOOL CALLBACK Columns_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
137 if (AfsAppLib_HandleHelp (IDD_COLUMNS, hDlg, msg, wp, lp))
138 return TRUE;
140 if (msg == WM_INITDIALOG)
141 SetWindowLongPtr (hDlg, DWLP_USER, ((LPPROPSHEETPAGE)lp)->lParam);
143 ShowColumnsParams *pscp;
144 pscp = (ShowColumnsParams *)GetWindowLongPtr (hDlg, DWLP_USER);
146 switch (msg)
148 case WM_INITDIALOG_SHEET:
149 PropCache_Add (pcGENERAL, NULL, hDlg);
150 break;
152 case WM_DESTROY_SHEET:
153 PropCache_Delete (hDlg);
154 break;
156 case WM_INITDIALOG:
157 Columns_OnInitDialog (hDlg, (pscp) ? pscp->lpviDefault : NULL);
158 break;
160 case WM_COMMAND:
161 switch (LOWORD(wp))
163 case IDAPPLY:
164 if (Columns_OnApply (hDlg, (pscp) ? pscp->lpviDefault : NULL))
166 if (pscp)
168 PostMessage (pscp->hParent, WM_COLUMNS_CHANGED, 0, 0);
171 break;
173 case IDOK:
174 case IDCANCEL:
175 EndDialog (hDlg, LOWORD(wp));
176 break;
178 case IDC_COLUMNS:
179 if (HIWORD(wp) == CBN_SELCHANGE)
181 Columns_OnSelect (hDlg);
183 break;
185 case IDC_COL_AVAIL:
186 if (HIWORD(wp) == LBN_SELCHANGE)
188 Columns_OnSelAvail (hDlg);
190 break;
192 case IDC_COL_SHOWN:
193 if (HIWORD(wp) == LBN_SELCHANGE)
195 Columns_OnSelShown (hDlg);
197 break;
199 case IDC_COL_INSERT:
200 Columns_OnInsert (hDlg);
201 break;
203 case IDC_COL_DELETE:
204 Columns_OnDelete (hDlg);
205 break;
207 case IDC_COL_UP:
208 Columns_OnMoveUp (hDlg);
209 break;
211 case IDC_COL_DOWN:
212 Columns_OnMoveDown (hDlg);
213 break;
215 break;
218 return FALSE;
222 void Columns_OnInitDialog (HWND hDlg, LPVIEWINFO lpviDefault)
224 if (!lpviDefault)
226 lpviDefault = (gr.fPreview && !gr.fVert) ? &gr.diHorz.viewSvr : &gr.diVert.viewSvr;
229 HWND hList = GetDlgItem (hDlg, IDC_COLUMNS);
230 CB_StartChange (hList);
232 for (size_t iCol = 0; iCol < nCOLUMNS; ++iCol)
234 if ((COLUMNS[iCol].fUsuallyHidden) && (lpviDefault != &COLUMNS[iCol].vi))
235 continue;
237 CB_AddItem (hList, COLUMNS[iCol].ids, (LPARAM)&COLUMNS[iCol].vi);
240 CB_EndChange (hList, (LPARAM)lpviDefault);
242 Columns_OnSelect (hDlg);
246 void Columns_OnSelect (HWND hDlg)
248 HWND hList;
249 LPVIEWINFO lpvi = (LPVIEWINFO)CB_GetSelectedData (GetDlgItem(hDlg,IDC_COLUMNS));
251 // Fill in the Available list...
253 hList = GetDlgItem (hDlg, IDC_COL_AVAIL);
254 LB_StartChange (hList);
256 size_t iAvail;
257 size_t iShown;
258 for (iAvail = 0; iAvail < lpvi->nColsAvail; ++iAvail)
260 for (iShown = 0; iShown < lpvi->nColsShown; ++iShown)
262 if (lpvi->aColumns[ iShown ] == iAvail)
263 break;
265 if (iShown == lpvi->nColsShown)
267 LB_AddItem (hList, lpvi->idsColumns[ iAvail ], (LPARAM)iAvail);
271 LB_EndChange (hList);
272 Columns_OnSelAvail (hDlg);
274 // Fill in the Shown list...
276 hList = GetDlgItem (hDlg, IDC_COL_SHOWN);
277 LB_StartChange (hList);
279 for (iShown = 0; iShown < lpvi->nColsShown; ++iShown)
281 iAvail = lpvi->aColumns[ iShown ];
282 LB_AddItem (hList, lpvi->idsColumns[ iAvail ], (LPARAM)iAvail);
285 LB_EndChange (hList);
286 Columns_OnSelShown (hDlg);
290 void Columns_OnSelAvail (HWND hDlg)
292 HWND hList = GetDlgItem (hDlg, IDC_COL_AVAIL);
293 int ii = LB_GetSelected (hList);
295 EnableWindow (GetDlgItem (hDlg, IDC_COL_INSERT), (ii != -1));
299 void Columns_OnSelShown (HWND hDlg)
301 HWND hList = GetDlgItem (hDlg, IDC_COL_SHOWN);
302 int ii = LB_GetSelected (hList);
304 if (ii == -1)
306 EnableWindow (GetDlgItem (hDlg, IDC_COL_DELETE), FALSE);
307 EnableWindow (GetDlgItem (hDlg, IDC_COL_UP), FALSE);
308 EnableWindow (GetDlgItem (hDlg, IDC_COL_DOWN), FALSE);
310 else
312 int iAvail = (int) LB_GetData (hList, ii);
313 EnableWindow (GetDlgItem (hDlg, IDC_COL_DELETE), (iAvail != 0));
315 int ci = (int)SendMessage (hList, LB_GETCOUNT, 0, 0);
316 EnableWindow (GetDlgItem (hDlg, IDC_COL_UP), (ii > 1));
317 EnableWindow (GetDlgItem (hDlg, IDC_COL_DOWN), (ii > 0 && ii < ci-1));
322 void Columns_OnInsert (HWND hDlg)
324 LPVIEWINFO lpvi = (LPVIEWINFO)CB_GetSelectedData (GetDlgItem (hDlg, IDC_COLUMNS));
325 HWND hAvail = GetDlgItem (hDlg, IDC_COL_AVAIL);
326 HWND hShown = GetDlgItem (hDlg, IDC_COL_SHOWN);
327 int ii = LB_GetSelected (hAvail);
329 if (ii != -1)
331 size_t iAvail = LB_GetData (hAvail, ii);
332 int iShown = 1+ LB_GetSelected (hShown);
334 TCHAR szText[ cchRESOURCE ];
335 SendMessage (hAvail, LB_GETTEXT, ii, (LPARAM)szText);
337 LB_AddItem (hShown, szText, iAvail);
338 SendMessage (hAvail, LB_DELETESTRING, ii, 0);
340 lpvi->aColumns[ lpvi->nColsShown ] = iAvail;
341 lpvi->nColsShown ++;
343 for (size_t iCol = 0; iCol < nCOLUMNS; ++iCol)
345 if (lpvi == &COLUMNS[ iCol ].vi)
346 COLUMNS[ iCol ].fChanged = TRUE;
349 Columns_OnSelAvail (hDlg);
350 Columns_OnSelShown (hDlg);
351 PropSheetChanged (hDlg);
356 void Columns_OnDelete (HWND hDlg)
358 LPVIEWINFO lpvi = (LPVIEWINFO)CB_GetSelectedData (GetDlgItem (hDlg, IDC_COLUMNS));
359 HWND hAvail = GetDlgItem (hDlg, IDC_COL_AVAIL);
360 HWND hShown = GetDlgItem (hDlg, IDC_COL_SHOWN);
361 int ii = LB_GetSelected (hShown);
363 if (ii != -1)
365 TCHAR szText[ cchRESOURCE ];
366 SendMessage (hShown, LB_GETTEXT, ii, (LPARAM)szText);
368 size_t iAvail = (size_t)LB_GetData (hShown, ii);
369 LB_AddItem (hAvail, szText, iAvail);
370 SendMessage (hShown, LB_DELETESTRING, ii, 0);
372 for ( ; ii < (int)lpvi->nColsShown-1; ++ii)
374 lpvi->aColumns[ ii ] = lpvi->aColumns[ ii+1 ];
376 lpvi->nColsShown --;
378 for (size_t iCol = 0; iCol < nCOLUMNS; ++iCol)
380 if (lpvi == &COLUMNS[ iCol ].vi)
381 COLUMNS[ iCol ].fChanged = TRUE;
384 Columns_OnSelAvail (hDlg);
385 Columns_OnSelShown (hDlg);
386 PropSheetChanged (hDlg);
391 void Columns_OnMoveUp (HWND hDlg)
393 LPVIEWINFO lpvi = (LPVIEWINFO)CB_GetSelectedData (GetDlgItem (hDlg, IDC_COLUMNS));
394 HWND hAvail = GetDlgItem (hDlg, IDC_COL_AVAIL);
395 HWND hShown = GetDlgItem (hDlg, IDC_COL_SHOWN);
396 int ii = LB_GetSelected (hShown);
398 if (ii > 0)
400 size_t iAvail = (size_t)LB_GetData (hShown, ii);
401 lpvi->aColumns[ ii ] = lpvi->aColumns[ ii-1 ];
402 lpvi->aColumns[ ii-1 ] = iAvail;
404 for (size_t iCol = 0; iCol < nCOLUMNS; ++iCol)
406 if (lpvi == &COLUMNS[ iCol ].vi)
407 COLUMNS[ iCol ].fChanged = TRUE;
410 Columns_OnSelect (hDlg);
411 LB_SetSelectedByData (hShown, (LPARAM)iAvail);
412 Columns_OnSelShown (hDlg);
413 PropSheetChanged (hDlg);
418 void Columns_OnMoveDown (HWND hDlg)
420 LPVIEWINFO lpvi = (LPVIEWINFO)CB_GetSelectedData (GetDlgItem (hDlg, IDC_COLUMNS));
421 HWND hAvail = GetDlgItem (hDlg, IDC_COL_AVAIL);
422 HWND hShown = GetDlgItem (hDlg, IDC_COL_SHOWN);
423 int ii = LB_GetSelected (hShown);
425 if (ii != -1)
427 size_t iAvail = (size_t)LB_GetData (hShown, ii);
428 lpvi->aColumns[ ii ] = lpvi->aColumns[ ii+1 ];
429 lpvi->aColumns[ ii+1 ] = iAvail;
431 for (size_t iCol = 0; iCol < nCOLUMNS; ++iCol)
433 if (lpvi == &COLUMNS[ iCol ].vi)
434 COLUMNS[ iCol ].fChanged = TRUE;
437 Columns_OnSelect (hDlg);
438 LB_SetSelectedByData (hShown, (LPARAM)iAvail);
439 Columns_OnSelShown (hDlg);
440 PropSheetChanged (hDlg);
445 BOOL Columns_OnApply (HWND hDlg, LPVIEWINFO lpviDefault)
447 BOOL fPostMessage = FALSE;
449 for (size_t iCol = 0; iCol < nCOLUMNS; ++iCol)
451 if (COLUMNS[ iCol ].fChanged)
453 CHILDTAB iTab = (CHILDTAB)-1;
454 int idcList;
456 VIEWINFO vi;
457 memcpy (&vi, &COLUMNS[ iCol ].vi, sizeof(VIEWINFO));
459 LPVIEWINFO lpviTarget = NULL;
461 switch (iCol)
463 case ceSERVERS:
464 if (gr.fPreview && !gr.fVert)
465 lpviTarget = &gr.diHorz.viewSvr;
466 else
467 lpviTarget = &gr.diVert.viewSvr;
468 FL_RestoreView (GetDlgItem (g.hMain, IDC_SERVERS), &COLUMNS[ iCol ].vi);
469 UpdateDisplay_Servers (FALSE, NULL, 0);
470 break;
472 case ceFILESETS:
473 lpviTarget = &gr.viewSet;
474 iTab = tabFILESETS;
475 idcList = IDC_SET_LIST;
476 break;
478 case ceAGGREGATES:
479 lpviTarget = &gr.viewAgg;
480 iTab = tabAGGREGATES;
481 idcList = IDC_AGG_LIST;
482 break;
484 case ceSERVICES:
485 lpviTarget = &gr.viewSvc;
486 iTab = tabSERVICES;
487 idcList = IDC_SVC_LIST;
488 break;
490 case ceREPLICAS:
491 lpviTarget = &gr.viewRep;
492 break;
494 case ceAGGS_MOVE:
495 lpviTarget = &gr.viewAggMove;
496 break;
498 case ceAGGS_CREATE:
499 lpviTarget = &gr.viewAggCreate;
500 break;
502 case ceAGGS_RESTORE:
503 lpviTarget = &gr.viewAggRestore;
504 break;
507 if (lpviTarget != NULL)
509 memcpy (lpviTarget, &COLUMNS[ iCol ].vi, sizeof(VIEWINFO));
510 if (lpviDefault == &COLUMNS[ iCol ].vi)
511 fPostMessage = TRUE;
514 if (iTab != (CHILDTAB)-1)
516 for (HWND hServer = g.hMain;
517 hServer != NULL;
518 hServer = PropCache_Search (pcSERVER, ANYVALUE, hServer))
520 HWND hTab = GetDlgItem (hServer, IDC_TABS);
521 int iTabShown = TabCtrl_GetCurSel (hTab);
523 if (iTab == iTabShown)
525 HWND hChild = Server_GetCurrentTab (hServer);
526 HWND hList = GetDlgItem (hChild, idcList);
528 TCHAR szClassName[ cchRESOURCE ];
529 if (GetClassName (hList, szClassName, cchRESOURCE))
531 if (lstrcmp (szClassName, WC_FASTLIST))
532 continue;
535 FL_StoreView (hList, &vi);
536 COLUMNS[ iCol ].vi.lvsView = vi.lvsView;
537 FL_RestoreView (hList, &COLUMNS[ iCol ].vi);
538 Server_ForceRedraw (hServer);
541 if (hServer == g.hMain)
542 hServer = NULL;
548 return fPostMessage;