Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / set_createrep.cpp
blob3ffc8376bac4d7a49c5d244bf3bb4d0dd696fa6a
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 "set_createrep.h"
20 #include "columns.h"
21 #include "svr_window.h"
22 #include "display.h"
26 * PROTOTYPES _________________________________________________________________
30 BOOL CALLBACK Filesets_CreateReplica_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
31 void Filesets_CreateReplica_OnInitDialog (HWND hDlg, LPSET_CREATEREP_PARAMS pscp);
32 void Filesets_CreateReplica_OnSelectServer (HWND hDlg, LPIDENT *plpiTarget);
33 void Filesets_CreateReplica_OnEndTask_EnumAggregates (HWND hDlg, LPSET_CREATEREP_PARAMS pscp);
34 void Filesets_CreateReplica_EnableOK (HWND hDlg, LPSET_CREATEREP_PARAMS pscp);
35 void Filesets_CreateReplica_StartDisplay_Aggregates (HWND hDlg, LPIDENT lpiTarget);
39 * ROUTINES ___________________________________________________________________
43 void Filesets_CreateReplica (LPIDENT lpiSource, LPIDENT lpiTarget)
45 LPSET_CREATEREP_PARAMS pscp = New (SET_CREATEREP_PARAMS);
46 pscp->lpiSource = lpiSource;
47 pscp->lpiTarget = lpiTarget;
49 INT_PTR rc = ModalDialogParam (IDD_SET_CREATEREP, NULL, (DLGPROC)Filesets_CreateReplica_DlgProc, (LPARAM)pscp);
50 if (rc != IDOK)
52 Delete (pscp);
54 else if (!ASSERT( pscp->lpiTarget && pscp->lpiTarget->fIsAggregate() ))
56 Delete (pscp);
58 else
60 StartTask (taskSET_CREATEREP, NULL, pscp);
65 BOOL CALLBACK Filesets_CreateReplica_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
67 static LPSET_CREATEREP_PARAMS pscp = NULL;
68 if (msg == WM_INITDIALOG)
69 pscp = (LPSET_CREATEREP_PARAMS)lp;
71 if (HandleColumnNotify (hDlg, msg, wp, lp, &gr.viewAggMove))
72 return FALSE;
74 if (AfsAppLib_HandleHelp (IDD_SET_CREATEREP, hDlg, msg, wp, lp))
75 return TRUE;
77 if (pscp != NULL)
79 switch (msg)
81 case WM_INITDIALOG:
82 FastList_SetTextCallback (GetDlgItem (hDlg, IDC_AGG_LIST), GetItemText, &gr.viewAggMove);
83 Filesets_CreateReplica_OnInitDialog (hDlg, pscp);
84 break;
86 case WM_ENDTASK:
87 LPTASKPACKET ptp;
88 if ((ptp = (LPTASKPACKET)lp) != NULL)
90 if (ptp->idTask == taskAGG_ENUM_TO_LISTVIEW)
91 Filesets_CreateReplica_OnEndTask_EnumAggregates (hDlg, pscp);
92 else if (ptp->idTask == taskSVR_ENUM_TO_COMBOBOX)
94 EnableWindow (GetDlgItem (hDlg, IDC_SET_SERVER), TRUE);
95 Filesets_CreateReplica_OnSelectServer (hDlg, &pscp->lpiTarget);
97 FreeTaskPacket (ptp);
99 break;
101 case WM_CONTEXTMENU:
102 HWND hList;
103 hList = GetDlgItem (hDlg, IDC_AGG_LIST);
105 POINT ptScreen;
106 POINT ptClient;
107 ptScreen.x = LOWORD(lp);
108 ptScreen.y = HIWORD(lp);
110 ptClient = ptScreen;
111 ScreenToClient (hList, &ptClient);
113 if (FL_HitTestForHeaderBar (hList, ptClient))
115 HMENU hm = TaLocale_LoadMenu (MENU_COLUMNS);
116 DisplayContextMenu (hm, ptScreen, hList);
118 break;
120 case WM_COLUMNS_CHANGED:
121 LPARAM lpSel;
122 lpSel = FL_GetSelectedData (GetDlgItem (hDlg, IDC_AGG_LIST));
123 FL_RestoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAggMove);
124 Filesets_CreateReplica_OnSelectServer (hDlg, (LPIDENT*)&lpSel);
125 break;
127 case WM_COMMAND:
128 switch (LOWORD(wp))
130 case IDOK:
131 if (pscp->lpiTarget)
132 EndDialog (hDlg, LOWORD(wp));
133 break;
135 case IDCANCEL:
136 EndDialog (hDlg, LOWORD(wp));
137 break;
139 case IDC_SET_SERVER:
140 if (HIWORD(wp) == CBN_SELCHANGE)
141 Filesets_CreateReplica_OnSelectServer (hDlg, &pscp->lpiTarget);
142 break;
144 break;
146 case WM_DESTROY:
147 FL_StoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAggMove);
148 pscp = NULL;
149 break;
151 case WM_NOTIFY:
152 switch (((LPNMHDR)lp)->code)
154 case FLN_ITEMSELECT:
155 LPIDENT lpi;
156 if ((lpi = (LPIDENT)FL_GetSelectedData (GetDlgItem (hDlg, IDC_AGG_LIST))) != NULL)
158 pscp->lpiTarget = lpi;
159 Filesets_CreateReplica_EnableOK (hDlg, pscp);
161 break;
163 break;
167 return FALSE;
171 static LONG_PTR procFilesetsCreateReplicaList = 0;
173 LRESULT CALLBACK Filesets_CreateReplica_SubclassListProc (HWND hList, UINT msg, WPARAM wp, LPARAM lp)
175 LRESULT rc;
177 if (procFilesetsCreateReplicaList == 0)
178 rc = DefWindowProc (hList, msg, wp, lp);
179 else
180 rc = (LRESULT) CallWindowProc ((WNDPROC)procFilesetsCreateReplicaList, hList, msg, wp, lp);
182 switch (msg)
184 case WM_DESTROY:
185 if (procFilesetsCreateReplicaList != 0)
186 SetWindowLongPtr (hList, GWLP_WNDPROC, (LONG_PTR)procFilesetsCreateReplicaList);
187 break;
189 case WM_COMMAND:
190 switch (LOWORD(wp))
192 case M_COLUMNS:
193 ShowColumnsDialog (GetParent (hList), &gr.viewAggMove);
194 break;
196 break;
199 return rc;
203 void Filesets_CreateReplica_OnInitDialog (HWND hDlg, LPSET_CREATEREP_PARAMS pscp)
205 TCHAR szServer[ cchNAME ];
206 TCHAR szAggregate[ cchNAME ];
207 TCHAR szFileset[ cchNAME ];
208 pscp->lpiSource->GetServerName (szServer);
209 pscp->lpiSource->GetAggregateName (szAggregate);
210 pscp->lpiSource->GetFilesetName (szFileset);
212 TCHAR szText[ cchRESOURCE ];
213 GetDlgItemText (hDlg, IDC_SET_NAME, szText, cchRESOURCE);
214 LPTSTR pszText = FormatString (szText, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
215 SetDlgItemText (hDlg, IDC_SET_NAME, pszText);
216 FreeString (pszText);
218 HWND hList = GetDlgItem (hDlg, IDC_AGG_LIST);
219 if (procFilesetsCreateReplicaList == 0)
220 procFilesetsCreateReplicaList = GetWindowLongPtr (hList, GWLP_WNDPROC);
221 SetWindowLongPtr (hList, GWLP_WNDPROC, (LONG_PTR)Filesets_CreateReplica_SubclassListProc);
223 if (gr.viewAggMove.lvsView == 0) // never initialized this?
225 if (gr.viewAggCreate.lvsView == 0)
226 memcpy (&gr.viewAggMove, &gr.viewAgg, sizeof(VIEWINFO));
227 else
228 memcpy (&gr.viewAggMove, &gr.viewAggCreate, sizeof(VIEWINFO));
230 FL_RestoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAggMove);
232 EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
233 EnableWindow (GetDlgItem (hDlg, IDC_SET_SERVER), FALSE);
234 EnableWindow (GetDlgItem (hDlg, IDC_AGG_LIST), FALSE);
236 // Fill in the Servers combobox, and select the default server
237 // (if one was specified).
239 LPSVR_ENUM_TO_COMBOBOX_PACKET lpp = New (SVR_ENUM_TO_COMBOBOX_PACKET);
240 lpp->hCombo = GetDlgItem (hDlg, IDC_SET_SERVER);
241 lpp->lpiSelect = (pscp->lpiTarget) ? pscp->lpiTarget->GetServer() : NULL;
242 StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lpp);
246 void Filesets_CreateReplica_OnSelectServer (HWND hDlg, LPIDENT *plpiTarget)
248 LPIDENT lpiServerNew = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SET_SERVER));
250 SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR)lpiServerNew);
252 if (*plpiTarget && (*plpiTarget)->fIsServer())
253 *plpiTarget = NULL;
254 if (*plpiTarget && ((*plpiTarget)->GetServer() != lpiServerNew))
255 *plpiTarget = NULL;
257 Filesets_CreateReplica_StartDisplay_Aggregates (hDlg, *plpiTarget);
261 void Filesets_CreateReplica_OnEndTask_EnumAggregates (HWND hDlg, LPSET_CREATEREP_PARAMS pscp)
263 EnableWindow (GetDlgItem (hDlg, IDC_AGG_LIST), TRUE);
264 Filesets_CreateReplica_EnableOK (hDlg, pscp);
268 void Filesets_CreateReplica_EnableOK (HWND hDlg, LPSET_CREATEREP_PARAMS pscp)
270 EnableWindow (GetDlgItem (hDlg, IDOK), (pscp->lpiTarget) ? TRUE : FALSE);
274 void Filesets_CreateReplica_StartDisplay_Aggregates (HWND hDlg, LPIDENT lpiTarget)
276 LPIDENT lpiServerNew = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SET_SERVER));
278 EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
280 LPAGG_ENUM_TO_LISTVIEW_PACKET lpp = New (AGG_ENUM_TO_LISTVIEW_PACKET);
281 lpp->hList = GetDlgItem (hDlg, IDC_AGG_LIST);
282 lpp->lpiServer = lpiServerNew;
283 lpp->lpiSelect = lpiTarget;
284 lpp->lpvi = &gr.viewAggMove;
285 StartTask (taskAGG_ENUM_TO_LISTVIEW, hDlg, lpp);