windows-updates-20010819
[openafs.git] / src / WINNT / win9xpanel / Change.cpp
1 /* Copyright 2000, International Business Machines Corporation and others.
2         All Rights Reserved.
3  
4         This software has been released under the terms of the IBM Public
5         License.  For details, see the LICENSE file in the top-level source
6         directory or online at http://www.openafs.org/dl/license10.html
7 */
8 // Change.cpp : implementation file
9 //
10
11 #include "stdafx.h"
12 #include "WinAfsLoad.h"
13 #include "WinAfsLoadDlg.h"
14 #include "Change.h"
15
16 #ifdef _DEBUG
17 #define new DEBUG_NEW
18 #undef THIS_FILE
19 static char THIS_FILE[] = __FILE__;
20 #endif
21
22 /////////////////////////////////////////////////////////////////////////////
23 // CChange dialog
24
25
26 CChange::CChange(BOOL change,CWnd* pParent /*=NULL*/)
27         : CDialog(CChange::IDD, pParent)
28 {
29         //{{AFX_DATA_INIT(CChange)
30         m_sPath = _T("");
31         m_sDescription = _T("");
32         m_bAuto = FALSE;
33         //}}AFX_DATA_INIT
34         m_bChange=change;
35         m_pParent=(CWinAfsLoadDlg *)pParent;
36 }
37
38
39 void CChange::DoDataExchange(CDataExchange* pDX)
40 {
41         CDialog::DoDataExchange(pDX);
42         //{{AFX_DATA_MAP(CChange)
43         DDX_Control(pDX, IDC_DESCRIPTION, m_cShare);
44         DDX_Control(pDX, IDC_PERSISTENT, m_cAuto);
45         DDX_Control(pDX, IDC_PATH, m_cPath);
46         DDX_Control(pDX, IDC_DRIVE, m_cDrive);
47         DDX_Text(pDX, IDC_PATH, m_sPath);
48         DDV_MaxChars(pDX, m_sPath, 512);
49         DDX_Text(pDX, IDC_DESCRIPTION, m_sDescription);
50         DDV_MaxChars(pDX, m_sDescription, 12);
51         DDX_Check(pDX, IDC_PERSISTENT, m_bAuto);
52         //}}AFX_DATA_MAP
53 }
54
55
56 BEGIN_MESSAGE_MAP(CChange, CDialog)
57         //{{AFX_MSG_MAP(CChange)
58         ON_WM_HELPINFO()
59         ON_BN_CLICKED(IDC_HELPMAIN, OnHelpmain)
60         //}}AFX_MSG_MAP
61 END_MESSAGE_MAP()
62
63 /////////////////////////////////////////////////////////////////////////////
64 // CChange message handlers
65
66 void CChange::OnOK() 
67 {
68         // TODO: Add extra validation here
69         m_cDrive.GetLBText(m_cDrive.GetCurSel(),m_sDrive);
70         m_sDrive=m_sDrive.Left(2);
71         UpdateData(TRUE);
72         if (IsValidSubmountName(m_sPath)) 
73         {
74
75                 if (IsValidShareName(m_sDescription)) 
76                 {
77                         CDialog::OnOK();
78                         return;
79                 }
80                 MessageBox("Incorrect Share name","AFS Warning",MB_OK|MB_ICONWARNING);
81                 m_cShare.SetFocus();
82                 return;
83         }
84         MessageBox("Incorrect Path name","AFS Warning",MB_OK|MB_ICONWARNING);
85         m_cPath.SetFocus();
86 }
87
88 void CChange::OnCancel() 
89 {
90         // TODO: Add extra cleanup here
91         m_sDrive=m_sPath=m_sDescription="";
92         CDialog::OnCancel();
93 }
94
95 BOOL CChange::OnInitDialog() 
96 {
97         CDialog::OnInitDialog();
98         
99         // TODO: Add extra initialization here
100         CWnd *win=GetDlgItem(IDOK);
101         if (m_bChange)
102         {
103                 if (win)
104                         win->SetWindowText("Accept Change");
105                 SetWindowText("AFS Change Item");
106         } else {
107                 if (win)
108                         win->SetWindowText("Add Item");
109                 SetWindowText("AFS Add Item");
110         }
111         ListDrive();
112         UpdateData(FALSE);
113         TCHAR szDrive[] = TEXT("*:  ");
114         wsprintf(szDrive,"%2s  ",m_sDrive);
115         if (m_cDrive.FindString(0,szDrive)!=CB_ERR)
116                 m_cDrive.SetCurSel(m_cDrive.FindString(0,szDrive));
117         else {
118                 szDrive[3]='*';
119                 m_cDrive.SetCurSel(m_cDrive.FindString(0,szDrive));
120         }
121         return TRUE;  // return TRUE unless you set the focus to a control
122                       // EXCEPTION: OCX Property Pages should return FALSE
123 }
124
125 VOID CChange::ListDrive()
126 {
127         m_pParent->BuildDriveList();
128         POSITION pos=m_pParent->m_Drivelist.GetHeadPosition();
129         while (pos)
130         {
131                 m_cDrive.InsertString(-1,m_pParent->m_Drivelist.GetNext(pos));
132         }
133 }
134
135 BOOL CChange::IsValidShareName(LPCTSTR pszShare)
136 {
137    if (!*pszShare)
138       return FALSE;
139    if (stricmp(pszShare,"")==0)
140            return FALSE;                                        //disallow adding a share name of ""
141    for ( ; *pszShare; ++pszShare)
142       {
143       if (!isprint(*pszShare))
144          return FALSE;
145       if (*pszShare == TEXT(' '))
146          return FALSE;
147       if (*pszShare == TEXT('\t'))
148          return FALSE;
149       }
150
151    return TRUE;
152 }
153
154 BOOL CChange::IsValidSubmountName (LPCTSTR pszSubmount)
155 {
156    if (!*pszSubmount)
157       return FALSE;
158    for ( ; *pszSubmount; ++pszSubmount)
159       {
160       if (!isprint(*pszSubmount))
161          return FALSE;
162       if (*pszSubmount == TEXT(' '))
163          return FALSE;
164       if (*pszSubmount == TEXT('\t'))
165          return FALSE;
166       }
167
168    return TRUE;
169 }
170
171
172 BOOL CChange::OnHelpInfo(HELPINFO* pHelpInfo) 
173 {
174         // TODO: Add your message handler code here and/or call default
175
176         ::WinHelp(m_hWnd,CWINAFSLOADAPP->m_pszHelpFilePath,HELP_CONTEXT,(m_bChange)?IDH_CHANGE:IDH_ADD);
177         return TRUE;
178 //      return CDialog::OnHelpInfo(pHelpInfo);
179 }
180
181 void CChange::OnHelpmain() 
182 {
183         // TODO: Add your control notification handler code here
184         ::WinHelp(m_hWnd,CWINAFSLOADAPP->m_pszHelpFilePath,HELP_CONTEXT,(m_bChange)?IDH_CHANGE:IDH_ADD);
185         
186 }