2 * Copyright 2000, International Business Machines Corporation and others.
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
14 #include <afs/param.h>
20 #include "svr_window.h"
21 #include "propcache.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 _____________________________________________________________
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
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]))
83 LPVIEWINFO lpviDefault
;
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
));
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
;
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
))
140 if (msg
== WM_INITDIALOG
)
141 SetWindowLongPtr (hDlg
, DWLP_USER
, ((LPPROPSHEETPAGE
)lp
)->lParam
);
143 ShowColumnsParams
*pscp
;
144 pscp
= (ShowColumnsParams
*)GetWindowLongPtr (hDlg
, DWLP_USER
);
148 case WM_INITDIALOG_SHEET
:
149 PropCache_Add (pcGENERAL
, NULL
, hDlg
);
152 case WM_DESTROY_SHEET
:
153 PropCache_Delete (hDlg
);
157 Columns_OnInitDialog (hDlg
, (pscp
) ? pscp
->lpviDefault
: NULL
);
164 if (Columns_OnApply (hDlg
, (pscp
) ? pscp
->lpviDefault
: NULL
))
168 PostMessage (pscp
->hParent
, WM_COLUMNS_CHANGED
, 0, 0);
175 EndDialog (hDlg
, LOWORD(wp
));
179 if (HIWORD(wp
) == CBN_SELCHANGE
)
181 Columns_OnSelect (hDlg
);
186 if (HIWORD(wp
) == LBN_SELCHANGE
)
188 Columns_OnSelAvail (hDlg
);
193 if (HIWORD(wp
) == LBN_SELCHANGE
)
195 Columns_OnSelShown (hDlg
);
200 Columns_OnInsert (hDlg
);
204 Columns_OnDelete (hDlg
);
208 Columns_OnMoveUp (hDlg
);
212 Columns_OnMoveDown (hDlg
);
222 void Columns_OnInitDialog (HWND hDlg
, LPVIEWINFO 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
))
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
)
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
);
258 for (iAvail
= 0; iAvail
< lpvi
->nColsAvail
; ++iAvail
)
260 for (iShown
= 0; iShown
< lpvi
->nColsShown
; ++iShown
)
262 if (lpvi
->aColumns
[ iShown
] == iAvail
)
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
);
306 EnableWindow (GetDlgItem (hDlg
, IDC_COL_DELETE
), FALSE
);
307 EnableWindow (GetDlgItem (hDlg
, IDC_COL_UP
), FALSE
);
308 EnableWindow (GetDlgItem (hDlg
, IDC_COL_DOWN
), FALSE
);
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
);
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
;
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
);
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 ];
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
);
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
);
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;
457 memcpy (&vi
, &COLUMNS
[ iCol
].vi
, sizeof(VIEWINFO
));
459 LPVIEWINFO lpviTarget
= NULL
;
464 if (gr
.fPreview
&& !gr
.fVert
)
465 lpviTarget
= &gr
.diHorz
.viewSvr
;
467 lpviTarget
= &gr
.diVert
.viewSvr
;
468 FL_RestoreView (GetDlgItem (g
.hMain
, IDC_SERVERS
), &COLUMNS
[ iCol
].vi
);
469 UpdateDisplay_Servers (FALSE
, NULL
, 0);
473 lpviTarget
= &gr
.viewSet
;
475 idcList
= IDC_SET_LIST
;
479 lpviTarget
= &gr
.viewAgg
;
480 iTab
= tabAGGREGATES
;
481 idcList
= IDC_AGG_LIST
;
485 lpviTarget
= &gr
.viewSvc
;
487 idcList
= IDC_SVC_LIST
;
491 lpviTarget
= &gr
.viewRep
;
495 lpviTarget
= &gr
.viewAggMove
;
499 lpviTarget
= &gr
.viewAggCreate
;
503 lpviTarget
= &gr
.viewAggRestore
;
507 if (lpviTarget
!= NULL
)
509 memcpy (lpviTarget
, &COLUMNS
[ iCol
].vi
, sizeof(VIEWINFO
));
510 if (lpviDefault
== &COLUMNS
[ iCol
].vi
)
514 if (iTab
!= (CHILDTAB
)-1)
516 for (HWND hServer
= g
.hMain
;
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
))
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
)