GME  13
CertificateDlg.cpp
Go to the documentation of this file.
00001 // CertificateDlg.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include ".\CertificateDlg.h"
00006 
00007 
00008 // CCertificateDlg dialog
00009 
00010 IMPLEMENT_DYNAMIC(CCertificateDlg, CDialog)
00011 CCertificateDlg::CCertificateDlg( const std::string& p_cert, bool p_permAcceptEnabled, CWnd* pParent /*=NULL*/)
00012         : CDialog(CCertificateDlg::IDD, pParent)
00013         , m_certDetails( p_cert)
00014         , m_permAcceptEnabled( p_permAcceptEnabled)
00015         , m_leftPad( 20)
00016         , m_rightPad( 20)
00017 {
00018 
00019 }
00020 
00021 CCertificateDlg::~CCertificateDlg()
00022 {
00023 }
00024 
00025 void CCertificateDlg::DoDataExchange(CDataExchange* pDX)
00026 {
00027         CDialog::DoDataExchange(pDX);
00028         DDX_Control(pDX, IDC_EDITTEXT, m_textBox);
00029 }
00030 
00031 
00032 BEGIN_MESSAGE_MAP(CCertificateDlg, CDialog)
00033         ON_BN_CLICKED(IDOK, OnBnClickedOk)
00034         ON_WM_SIZE()
00035 END_MESSAGE_MAP()
00036 
00037 
00038 // CCertificateDlg message handlers
00039 
00040 BOOL CCertificateDlg::OnInitDialog()
00041 {
00042         CDialog::OnInitDialog();
00043 
00044         m_textBox.SetWindowText( m_certDetails.c_str());
00045         
00046         CRect box_rect;
00047         if( m_textBox.GetSafeHwnd()) {
00048                 m_textBox.GetWindowRect( &box_rect);
00049                 ScreenToClient( &box_rect);
00050 
00051                 CRect win_rect;
00052                 GetWindowRect( &win_rect);
00053                 ScreenToClient( &win_rect);
00054 
00055                 // initing m_leftPad, m_rightPad with the initial lf and rt margins
00056                 m_leftPad = box_rect.left - win_rect.left;
00057                 m_rightPad = win_rect.right - box_rect.right;
00058         }
00059         
00060         return TRUE;  // return TRUE unless you set the focus to a control
00061         // EXCEPTION: OCX Property Pages should return FALSE
00062 }
00063 
00064 void CCertificateDlg::OnBnClickedOk()
00065 {
00066         UpdateData();
00067 
00068         CButton* rdo1 = (CButton*) GetDlgItem( IDC_RADIO_PERMANENTLY);
00069         CButton* rdo2 = (CButton*) GetDlgItem( IDC_RADIO_TEMPORARILY);
00070         CButton* rdo3 = (CButton*) GetDlgItem( IDC_RADIO3);
00071 
00072         m_response = PermanentAccept;
00073         if( rdo1 && rdo1->GetCheck() == BST_CHECKED)
00074                 m_response = PermanentAccept;
00075         else if( rdo2 && rdo2->GetCheck() == BST_CHECKED)
00076                 m_response = TemoraryAccept;
00077         else if( rdo3 && rdo3->GetCheck() == BST_CHECKED)
00078                 m_response = Reject;
00079         else
00080         {
00081                 AfxMessageBox( "Before closing the dialog please select one option from Reject, Temporary Accept and Permanent Accept!"); 
00082                 return;
00083         }
00084         //"Would you like to reject the certificate? It will not allow connections to the server.", 
00085         if( m_response == Reject && IDNO == AfxMessageBox( "Warning: Rejecting the certificate will cause connections to this server to fail. Continue?", MB_YESNO))
00086                 return;
00087 
00088         if( !m_permAcceptEnabled && m_response == PermanentAccept)
00089         {
00090                 AfxMessageBox( "Permanent accept is not a valid option!"); 
00091                 return;
00092         }
00093 
00094         OnOK();
00095 }
00096 
00097 CCertificateDlg::Response CCertificateDlg::getResp()
00098 {
00099         return m_response;
00100 }
00101 
00102 void CCertificateDlg::OnSize(UINT nType, int cx, int cy)
00103 {
00104         CDialog::OnSize(nType, cx, cy);
00105 
00106         CButton* ok_btn = (CButton*) GetDlgItem( IDOK);
00107         CButton* ca_btn = (CButton*) GetDlgItem( IDCANCEL);
00108 
00109         CRect box_rect, ok_rect, ca_rect;
00110         if ( m_textBox.GetSafeHwnd()
00111                 && ok_btn && ok_btn->GetSafeHwnd()
00112                 && ca_btn && ca_btn->GetSafeHwnd()) 
00113         {
00114                 m_textBox.GetWindowRect( &box_rect);
00115                 ScreenToClient( &box_rect);
00116 
00117                 ok_btn->GetWindowRect( &ok_rect);
00118                 ScreenToClient( &ok_rect);
00119 
00120                 ca_btn->GetWindowRect( &ca_rect);
00121                 ScreenToClient( &ca_rect);
00122 
00123                 m_textBox.SetWindowPos( NULL, m_leftPad, box_rect.top, cx - m_leftPad - m_rightPad, box_rect.Height(), SWP_NOZORDER);
00124                 ok_btn->SetWindowPos( NULL, cx - ok_rect.Width() - m_leftPad, ok_rect.top, ok_rect.Width(), ok_rect.Height(), SWP_NOZORDER);
00125                 ca_btn->SetWindowPos( NULL, cx - ca_rect.Width() - m_leftPad, ca_rect.top, ca_rect.Width(), ca_rect.Height(), SWP_NOZORDER);
00126         }
00127 }