00001
00002
00003
00004 #include "stdafx.h"
00005 #include "Options.h"
00006 #include "EventsDial.h"
00007 #include "BON.h"
00008 #include "BONImpl.h"
00009 #include <afxdlgs.h>
00010
00011 #ifdef _DEBUG
00012 #define new DEBUG_NEW
00013 #undef THIS_FILE
00014 static char THIS_FILE[] = __FILE__;
00015 #endif
00016
00017 const std::string Options::OptionsRegistrySubNode_str = "MetaGME_Options/GeneratedConstraints";
00018 const std::string Options::RegContMask_str = "RegularContainmentEventMask";
00019 const std::string Options::FolContMask_str = "FolderContainmentEventMask";
00020 const std::string Options::ConnectMask_str = "ConnectionEndEventMask";
00021 const std::string Options::Priority_str = "Priority";
00022 const std::string Options::DontAsk_str = "skip_dialog";
00023
00025
00026
00027 Options::Options(CWnd* pParent )
00028 : CDialog(Options::IDD, pParent)
00029 , m_valRegContMask( 0 )
00030 , m_valFolContMask( 0 )
00031 , m_valConnectMask( 0 )
00032 , m_valPriority ( 1 )
00033
00034 {
00035
00036 m_strRegCont = _T("");
00037 m_strFolCont = _T("");
00038 m_strConnect = _T("");
00039 m_dontask = FALSE;
00040 m_strPriority = _T("");
00041
00042 }
00043
00044
00045 void Options::DoDataExchange(CDataExchange* pDX)
00046 {
00047 CDialog::DoDataExchange(pDX);
00048
00049 DDX_Control(pDX, IDC_SPIN1, m_spin);
00050 DDX_Text(pDX, IDC_EDIT1, m_strRegCont);
00051 DDV_HexNumber(pDX, m_strRegCont);
00052 DDV_MaxChars(pDX, m_strRegCont, 10);
00053 DDX_Text(pDX, IDC_EDIT2, m_strFolCont);
00054 DDV_HexNumber(pDX, m_strFolCont);
00055 DDV_MaxChars(pDX, m_strFolCont, 10);
00056 DDX_Text(pDX, IDC_EDIT3, m_strConnect);
00057 DDV_HexNumber(pDX, m_strConnect);
00058 DDV_MaxChars(pDX, m_strConnect, 10);
00059 DDX_Check(pDX, IDC_CHECK1, m_dontask);
00060 DDX_Text(pDX, IDC_EDIT4, m_strPriority);
00061 DDV_MaxChars(pDX, m_strPriority, 2);
00062 DDV_MinMaxInt(pDX, atoi( m_strPriority), 1, 10);
00063
00064 }
00065
00066 void PASCAL Options::DDV_HexNumber(CDataExchange* pDX, const CString& nmb)
00067 {
00068 if( !pDX->m_bSaveAndValidate) return;
00069
00070 CString whitespace = " \t\n";
00071 CString digits = "0123456789";
00072 CString hexadigits = "0123456789abcdefABCDEF";
00073 bool fail = false;
00074 int i = 0;
00075
00076
00077 while( i < nmb.GetLength() && whitespace.Find( nmb.GetAt( i)) != -1) ++i;
00078
00079 if( i == nmb.GetLength())
00080 {
00081 return;
00082 }
00083
00084 bool hex = false;
00085 if( i + 1 < nmb.GetLength() && nmb.GetAt(i) == '0' && (nmb.GetAt(i + 1) == 'x' || nmb.GetAt(i + 1) == 'X'))
00086 {
00087 i += 2;
00088 hex = true;
00089 digits = hexadigits;
00090 }
00091
00092 while( i < nmb.GetLength() && digits.Find( nmb.GetAt(i)) != -1) ++i;
00093
00094 fail = i < nmb.GetLength();
00095
00096 if( fail)
00097 {
00098 AfxMessageBox("Enter a hexadecimal value please!", MB_ICONERROR);
00099 pDX->Fail();
00100 }
00101 }
00102
00103 BEGIN_MESSAGE_MAP(Options, CDialog)
00104
00105 ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
00106 ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
00107 ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
00108 ON_BN_CLICKED(IDC_CHECK1, OnDontAskClick)
00109
00110 END_MESSAGE_MAP()
00111
00113
00114 BOOL Options::OnInitDialog()
00115 {
00116 CDialog::OnInitDialog();
00117
00118 char buff[32];
00119 sprintf( buff, "0x%08X", m_valRegContMask);
00120 m_strRegCont = buff;
00121 sprintf( buff, "0x%08X", m_valFolContMask);
00122 m_strFolCont = buff;
00123 sprintf( buff, "0x%08X", m_valConnectMask);
00124 m_strConnect = buff;
00125 sprintf( buff, "%d", m_valPriority);
00126 m_strPriority = buff;
00127
00128 m_spin.SetRange( 1, 10);
00129 m_spin.SetPos( m_valPriority);
00130
00131 UpdateData( FALSE);
00132
00133 return TRUE;
00134 }
00135
00136 void Options::OnButton1()
00137 {
00138 UpdateData( TRUE);
00139 EventsDial d;
00140
00141 int val = 0;
00142 if( sscanf( m_strRegCont, "%X", &val) == 1)
00143 d.m_sumAll = val;
00144
00145 if( d.DoModal() == IDOK)
00146 {
00147 char buff[32];
00148 sprintf( buff, "0x%08X", d.m_sumAll);
00149 m_strRegCont = buff;
00150 m_valRegContMask = d.m_sumAll;
00151 }
00152
00153 UpdateData( FALSE);
00154 }
00155
00156 void Options::OnButton2()
00157 {
00158 UpdateData( TRUE);
00159 EventsDial d;
00160
00161 int val = 0;
00162 if( sscanf( m_strFolCont, "%X", &val) == 1)
00163 d.m_sumAll = val;
00164
00165 if( d.DoModal() == IDOK)
00166 {
00167 char buff[32];
00168 sprintf( buff, "0x%08X", d.m_sumAll);
00169 m_strFolCont = buff;
00170 m_valFolContMask = d.m_sumAll;
00171 }
00172
00173 UpdateData( FALSE);
00174 }
00175
00176 void Options::OnButton3()
00177 {
00178 UpdateData( TRUE);
00179 EventsDial d;
00180
00181 int val = 0;
00182 if( sscanf( m_strConnect, "%X", &val) == 1)
00183 d.m_sumAll = val;
00184
00185 if( d.DoModal() == IDOK)
00186 {
00187 char buff[32];
00188 sprintf( buff, "0x%08X", d.m_sumAll);
00189 m_strConnect = buff;
00190 m_valConnectMask = d.m_sumAll;
00191 }
00192
00193 UpdateData( FALSE);
00194 }
00195
00196 void Options::setDefs( int reg_cont, int fol_cont, int conn_msk, int prior)
00197 {
00198 m_valRegContMask = reg_cont;
00199 m_valFolContMask = fol_cont;
00200 m_valConnectMask = conn_msk;
00201 m_valPriority = prior;
00202 }
00203
00204
00205 void Options::getResults( int* v1, int* v2, int* v3, int* vp, bool* dont_ask)
00206 {
00207 *v1 = m_valRegContMask;
00208 *v2 = m_valFolContMask;
00209 *v3 = m_valConnectMask;
00210 *vp = m_valPriority;
00211
00212 *dont_ask = m_dontask == TRUE;
00213 }
00214
00215
00216 bool Options::fetchOpts( const BON::Project& proj, int* v1, int* v2, int* v3, int *pr)
00217 {
00218 BON::RegistryNode rn = proj->getRootFolder()->getRegistry()->getChild( OptionsRegistrySubNode_str);
00219 if( !rn) return true;
00220
00221 if( rn->getValue() == DontAsk_str)
00222 {
00223 return false;
00224 }
00225 else
00226 {
00227 int status = 0;
00228 BON::RegistryNode ch1 = rn->getChild( RegContMask_str);
00229 if( ch1 && ch1->getStatus() == BON::RNS_Here)
00230 status = sscanf( ch1->getValue().c_str(), "%x", v1);
00231
00232 BON::RegistryNode ch2 = rn->getChild( FolContMask_str);
00233 if( ch2 && ch2->getStatus() == BON::RNS_Here)
00234 status = sscanf( ch2->getValue().c_str(), "%x", v2);
00235
00236 BON::RegistryNode ch3 = rn->getChild( ConnectMask_str);
00237 if( ch3 && ch3->getStatus() == BON::RNS_Here)
00238 status = sscanf( ch3->getValue().c_str(), "%x", v3);
00239
00240 BON::RegistryNode ch4 = rn->getChild( Priority_str);
00241 if( ch4 && ch4->getStatus() == BON::RNS_Here)
00242 {
00243 *pr = ch4->getIntegerValue();
00244 }
00245 }
00246 return true;
00247 }
00248
00249
00250 void Options::saveOpts( const BON::Project& proj, int v1, int v2, int v3, int vp, bool dont_ask)
00251 {
00252 char buff[ 10 + 1 ];
00253
00254 BON::RegistryNode rn = proj->getRootFolder()->getRegistry();
00255
00256 sprintf( buff, "0x%08X", v1);
00257 rn->setValueByPath( "/" + OptionsRegistrySubNode_str + "/" + RegContMask_str, buff);
00258
00259 sprintf( buff, "0x%08X", v2);
00260 rn->setValueByPath( "/" + OptionsRegistrySubNode_str + "/" + FolContMask_str, buff);
00261
00262 sprintf( buff, "0x%08X", v3);
00263 rn->setValueByPath( "/" + OptionsRegistrySubNode_str + "/" + ConnectMask_str, buff);
00264
00265 sprintf( buff, "%d", vp);
00266 rn->setValueByPath( "/" + OptionsRegistrySubNode_str + "/" + Priority_str, buff);
00267
00268 if( dont_ask) rn->setValueByPath( "/" + OptionsRegistrySubNode_str, DontAsk_str);
00269 }
00270
00271
00272 void Options::OnOK()
00273 {
00274 CDialog::OnOK();
00275
00276 if( m_strRegCont.IsEmpty() || !sscanf( (LPCTSTR) m_strRegCont, "%x", &m_valRegContMask)) m_valRegContMask = 0;
00277 if( m_strFolCont.IsEmpty() || !sscanf( (LPCTSTR) m_strFolCont, "%x", &m_valFolContMask)) m_valFolContMask = 0;
00278 if( m_strConnect.IsEmpty() || !sscanf( (LPCTSTR) m_strConnect, "%x", &m_valConnectMask)) m_valConnectMask = 0;
00279
00280 m_valPriority = atoi( m_strPriority);
00281 if( !m_valPriority) m_valPriority = 1;
00282
00283 }
00284
00285 void Options::OnDontAskClick()
00286 {
00287 if( ((CButton * ) GetDlgItem( IDC_CHECK1))->GetCheck())
00288 if( IDCANCEL == MessageBox( CString("To modify these options at a later time, set the \"") + OptionsRegistrySubNode_str.c_str() + "\" value in the RootFolder's registry to something else than \"" + DontAsk_str.c_str() + "\".", "MetaInterpreter - Options", MB_OKCANCEL))
00289 ((CButton *) GetDlgItem( IDC_CHECK1))->SetCheck( 0);
00290
00291 }