GME  13
CredentialDlg.cpp
Go to the documentation of this file.
00001 // CredentialDlg.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include ".\CredentialDlg.h"
00006 
00007 
00008 // CCredentialDlg dialog
00009 
00010 IMPLEMENT_DYNAMIC(CCredentialDlg, CDialog)
00011 CCredentialDlg::CCredentialDlg( bool p_userNameOnly, bool p_visibleMaySave, bool p_maySave, const std::string& p_uName, const char* p_realmStr, CWnd* pParent /*=NULL*/)
00012         : CDialog(CCredentialDlg::IDD, pParent)
00013         , m_userNameOnly( p_userNameOnly)
00014         , m_visibleMaySave( p_visibleMaySave)
00015         , m_maySave( p_maySave)
00016         , m_suggestedName( p_uName)
00017         , m_realmStrPtr( p_realmStr)
00018         , m_leftPad( 20)
00019         , m_rightPad( 20)
00020 {
00021 }
00022 
00023 CCredentialDlg::~CCredentialDlg()
00024 {
00025 }
00026 
00027 std::string CCredentialDlg::name()
00028 {
00029         return m_resName;
00030 }
00031 
00032 std::string CCredentialDlg::word()
00033 {
00034         return m_resWord;
00035 }
00036 
00037 bool CCredentialDlg::maySave()
00038 {
00039         return m_resMaySave;
00040 }
00041 
00042 void CCredentialDlg::DoDataExchange(CDataExchange* pDX)
00043 {
00044         CDialog::DoDataExchange(pDX);
00045         DDX_Control(pDX, IDC_MAYBESAVED, m_btnMaySave);
00046         DDX_Control(pDX, IDC_EDITNAME, m_edtName);
00047         DDX_Control(pDX, IDC_EDITWORD, m_edtWord);
00048         DDX_Control(pDX, IDC_EDIT_REALM, m_edtRealm);
00049         DDX_Control(pDX, IDC_STATIC1, m_msgAtTheTop);
00050 }
00051 
00052 
00053 BEGIN_MESSAGE_MAP(CCredentialDlg, CDialog)
00054         ON_BN_CLICKED(IDOK, OnBnClickedOk)
00055         ON_WM_SIZE()
00056 END_MESSAGE_MAP()
00057 
00058 
00059 // CCredentialDlg message handlers
00060 
00061 BOOL CCredentialDlg::OnInitDialog()
00062 {
00063         CDialog::OnInitDialog();
00064 
00065         m_edtName.SetWindowText( m_suggestedName.c_str());
00066         m_edtWord.EnableWindow( !m_userNameOnly);
00067 
00068         if( m_userNameOnly)
00069                 m_msgAtTheTop.SetWindowText( "Please specify your username:");
00070         else if( m_realmStrPtr)
00071         {
00072                 m_edtRealm.ShowWindow( SW_SHOW);
00073                 m_edtRealm.SetWindowText( CString( "Realm: ") + m_realmStrPtr);//m_msgAtTheTop.SetWindowText( CString( "Please authenticate yourself for realm: \n") + m_realmStrPtr);
00074         }
00075 
00076         m_btnMaySave.ShowWindow( m_visibleMaySave? SW_SHOW: SW_HIDE);
00077         m_btnMaySave.EnableWindow( m_maySave);
00078         // maySave checked initially (if allowed)
00079         m_btnMaySave.SetCheck( m_maySave? BST_CHECKED: BST_UNCHECKED);
00080 
00081         // size related calc
00082         CRect rm_rect;
00083         if( m_edtRealm.GetSafeHwnd()) {
00084                 m_edtRealm.GetWindowRect( &rm_rect);
00085                 ScreenToClient( &rm_rect);
00086 
00087                 CRect win_rect;
00088                 GetWindowRect( &win_rect);
00089                 ScreenToClient( &win_rect);
00090 
00091                 // initing m_leftPad, m_rightPad with the initial lf and rt margins
00092                 m_leftPad = rm_rect.left - win_rect.left;
00093                 m_rightPad = win_rect.right - rm_rect.right;
00094         }
00095 
00096         return TRUE;  // return TRUE unless you set the focus to a control
00097         // EXCEPTION: OCX Property Pages should return FALSE
00098 }
00099 
00100 void CCredentialDlg::OnBnClickedOk()
00101 {
00102         CString res;
00103         
00104         m_edtName.GetWindowText( res);
00105         m_resName = (LPCTSTR) res;
00106 
00107         m_edtWord.GetWindowText( res);
00108         m_resWord = (LPCTSTR) res;
00109 
00110         m_resMaySave = m_btnMaySave.GetCheck() == BST_CHECKED;
00111 
00112         OnOK();
00113 }
00114 
00115 void CCredentialDlg::OnSize(UINT nType, int cx, int cy)
00116 {
00117         CDialog::OnSize(nType, cx, cy);
00118 
00119         CButton* ok_btn = (CButton*) GetDlgItem( IDOK);
00120         CButton* ca_btn = (CButton*) GetDlgItem( IDCANCEL);
00121 
00122         CRect rm_rect, ok_rect, ca_rect;
00123         if ( m_edtRealm.GetSafeHwnd()
00124                 && ok_btn && ok_btn->GetSafeHwnd()
00125                 && ca_btn && ca_btn->GetSafeHwnd())
00126         {
00127                 m_edtRealm.GetWindowRect( &rm_rect);
00128                 ScreenToClient( &rm_rect);
00129 
00130                 ok_btn->GetWindowRect( &ok_rect);
00131                 ScreenToClient( &ok_rect);
00132 
00133                 ca_btn->GetWindowRect( &ca_rect);
00134                 ScreenToClient( &ca_rect);
00135 
00136                 m_edtRealm.SetWindowPos( NULL, rm_rect.left, rm_rect.top, cx - m_leftPad - m_rightPad, rm_rect.Height(), SWP_NOZORDER);
00137                 ok_btn->SetWindowPos( NULL, cx - ok_rect.Width() - m_leftPad, ok_rect.top, ok_rect.Width(), ok_rect.Height(), SWP_NOZORDER);
00138                 ca_btn->SetWindowPos( NULL, cx - ca_rect.Width() - m_leftPad, ca_rect.top, ca_rect.Width(), ca_rect.Height(), SWP_NOZORDER);
00139         }
00140 
00141 }