ntmakefile-clean-20040401
[openafs.git] / src / WINNT / afssvrmgr / svr_execute.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 "svr_execute.h"
17 #include "propcache.h"
18
19 /*
20  * PROTOTYPES _________________________________________________________________
21  *
22  */
23
24 BOOL WINAPI Server_Execute_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
25
26 void Server_Execute_OnInitDialog (HWND hDlg, LPSVR_EXECUTE_PARAMS lpp);
27 void Server_Execute_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPSVR_EXECUTE_PARAMS lpp);
28 void Server_Execute_EnableOK (HWND hDlg);
29 void Server_Execute_OnOK (HWND hDlg);
30
31
32 /*
33  * ROUTINES ___________________________________________________________________
34  *
35  */
36
37 void Server_Execute (LPIDENT lpiServer)
38 {
39    HWND hCurrent;
40
41    if ((hCurrent = PropCache_Search (pcSVR_EXECUTE, NULL)) != NULL)
42       {
43       SetFocus (hCurrent);
44       }
45    else
46       {
47       LPSVR_EXECUTE_PARAMS lpp = New (SVR_EXECUTE_PARAMS);
48       lpp->lpiServer = lpiServer;
49       lpp->szCommand[0] = TEXT('\0');
50
51       HWND hDlg = ModelessDialogParam (IDD_SVR_EXECUTE, NULL, (DLGPROC)Server_Execute_DlgProc, (LPARAM)lpp);
52       ShowWindow (hDlg, SW_SHOW);
53       }
54 }
55
56
57 BOOL WINAPI Server_Execute_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
58 {
59    if (AfsAppLib_HandleHelp (IDD_SVR_EXECUTE, hDlg, msg, wp, lp))
60       return TRUE;
61
62    LPSVR_EXECUTE_PARAMS lpp;
63
64    if (msg == WM_INITDIALOG)
65       SetWindowLong (hDlg, DWL_USER, lp);
66
67    if ((lpp = (LPSVR_EXECUTE_PARAMS)GetWindowLong(hDlg,DWL_USER)) != NULL)
68       {
69       switch (msg)
70          {
71          case WM_INITDIALOG:
72             PropCache_Add (pcSVR_EXECUTE, NULL, hDlg);
73             Server_Execute_OnInitDialog (hDlg, lpp);
74             break;
75
76          case WM_ENDTASK:
77             LPTASKPACKET ptp;
78             if ((ptp = (LPTASKPACKET)lp) != NULL)
79                {
80                if (ptp->idTask == taskSVR_ENUM_TO_COMBOBOX)
81                   Server_Execute_OnEndTask_InitDialog (hDlg, ptp, lpp);
82                FreeTaskPacket (ptp);
83                }
84             break;
85
86          case WM_COMMAND:
87             switch (LOWORD(wp))
88                {
89                case IDOK:
90                   Server_Execute_OnOK (hDlg);
91                   DestroyWindow (hDlg);
92                   break;
93
94                case IDCANCEL:
95                   DestroyWindow (hDlg);
96                   break;
97
98                case IDC_SERVER:
99                case IDC_COMMAND:
100                   Server_Execute_EnableOK (hDlg);
101                   break;
102                }
103             break;
104
105          case WM_DESTROY:
106             Delete (lpp);
107             SetWindowLong (hDlg, DWL_USER, 0);
108             PropCache_Delete (pcSVR_EXECUTE, NULL);
109             break;
110          }
111       }
112
113    return FALSE;
114 }
115
116
117 void Server_Execute_OnInitDialog (HWND hDlg, LPSVR_EXECUTE_PARAMS lpp)
118 {
119    LPSVR_ENUM_TO_COMBOBOX_PACKET lppEnum = New (SVR_ENUM_TO_COMBOBOX_PACKET);
120    lppEnum->hCombo = GetDlgItem (hDlg, IDC_SERVER);
121    lppEnum->lpiSelect = lpp->lpiServer;
122    StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lppEnum);
123
124    EnableWindow (GetDlgItem (hDlg, IDC_SERVER), FALSE);
125    EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
126 }
127
128
129 void Server_Execute_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPSVR_EXECUTE_PARAMS lpp)
130 {
131    EnableWindow (GetDlgItem (hDlg, IDC_SERVER), TRUE);
132    Server_Execute_EnableOK (hDlg);
133 }
134
135
136 void Server_Execute_EnableOK (HWND hDlg)
137 {
138    LPIDENT lpiServer = NULL;
139
140    if (IsWindowEnabled (GetDlgItem (hDlg, IDC_SERVER)))
141       lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SERVER));
142
143    BOOL fEnable = (lpiServer != NULL) ? TRUE : FALSE;
144
145    if (fEnable)
146       {
147       TCHAR szCommand[ MAX_PATH ];
148       GetDlgItemText (hDlg, IDC_COMMAND, szCommand, MAX_PATH);
149       if (szCommand[0] == TEXT('\0'))
150          fEnable = FALSE;
151       }
152
153    EnableWindow (GetDlgItem (hDlg, IDOK), fEnable);
154 }
155
156
157 void Server_Execute_OnOK (HWND hDlg)
158 {
159    LPSVR_EXECUTE_PARAMS lpp = New (SVR_EXECUTE_PARAMS);
160    lpp->lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SERVER));
161    GetDlgItemText (hDlg, IDC_COMMAND, lpp->szCommand, MAX_PATH);
162
163    StartTask (taskSVR_EXECUTE, NULL, lpp);
164 }
165