Back to index

lightning-sunbird  0.9+nobinonly
Dialogs.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: Mozilla-sample-code 1.0
00004  *
00005  * Copyright (c) 2002 Netscape Communications Corporation and
00006  * other contributors
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a
00009  * copy of this Mozilla sample software and associated documentation files
00010  * (the "Software"), to deal in the Software without restriction, including
00011  * without limitation the rights to use, copy, modify, merge, publish,
00012  * distribute, sublicense, and/or sell copies of the Software, and to permit
00013  * persons to whom the Software is furnished to do so, subject to the
00014  * following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included
00017  * in all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00020  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00022  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00025  * DEALINGS IN THE SOFTWARE.
00026  *
00027  * Contributor(s):
00028  *   Chak Nanga <chak@netscape.com>
00029  *
00030  * ***** END LICENSE BLOCK ***** */
00031 
00032 #include "stdafx.h"
00033 #include "Dialogs.h"
00034 
00035 // File overview....
00036 //
00037 // Contains dialog box code to support Alerts, Prompts such as
00038 // password prompt and username/password prompts
00039 //
00040 
00041 //--------------------------------------------------------------------------//
00042 //                          CPromptDialog Stuff
00043 //--------------------------------------------------------------------------//
00044 
00045 CPromptDialog::CPromptDialog(CWnd* pParent, const TCHAR* pTitle, const TCHAR* pText,
00046                              const TCHAR* pInitPromptText,
00047                              BOOL bHasCheck, const TCHAR* pCheckText, int initCheckVal)
00048     : CDialog(CPromptDialog::IDD, pParent),
00049     m_bHasCheckBox(bHasCheck)
00050 {   
00051     if(pTitle)
00052         m_csDialogTitle = pTitle;
00053     if(pText)
00054         m_csPromptText = pText;
00055     if(pInitPromptText)
00056         m_csPromptAnswer = pInitPromptText;
00057     if(pCheckText)
00058         m_csCheckBoxText = pCheckText; 
00059 }
00060 
00061 void CPromptDialog::DoDataExchange(CDataExchange* pDX)
00062 {
00063     CDialog::DoDataExchange(pDX);
00064     //{{AFX_DATA_MAP(CPromptDialog)
00065     DDX_Text(pDX, IDC_PROMPT_ANSWER, m_csPromptAnswer);
00066     DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue);
00067     //}}AFX_DATA_MAP
00068 }
00069 
00070 BEGIN_MESSAGE_MAP(CPromptDialog, CDialog)
00071     //{{AFX_MSG_MAP(CPromptDialog)
00072         // NOTE: the ClassWizard will add message map macros here
00073     //}}AFX_MSG_MAP
00074 END_MESSAGE_MAP()
00075 
00076 int CPromptDialog::OnInitDialog()
00077 {   
00078     SetWindowText(m_csDialogTitle);
00079   
00080     CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT);
00081     if(pWnd)
00082         pWnd->SetWindowText(m_csPromptText);
00083 
00084     CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD);
00085     if(pChk)
00086     {
00087         if (m_bHasCheckBox)
00088         {
00089             if(!m_csCheckBoxText.IsEmpty())
00090                 pChk->SetWindowText(m_csCheckBoxText);
00091             pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
00092         }
00093         else
00094         {
00095             // Hide the check box control if there's no label text
00096             // This will be the case when we're not using single sign-on
00097             pChk->ShowWindow(SW_HIDE); 
00098         }
00099     }
00100 
00101     CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PROMPT_ANSWER);
00102     if(pEdit) 
00103     {
00104         pEdit->SetWindowText(m_csPromptAnswer);
00105         pEdit->SetFocus();
00106         pEdit->SetSel(0, -1);
00107 
00108         return 0; // Returning "0" since we're explicitly setting focus
00109     }
00110 
00111     return TRUE;
00112 }
00113 
00114 //--------------------------------------------------------------------------//
00115 //                          CPromptPasswordDialog Stuff
00116 //--------------------------------------------------------------------------//
00117 
00118 CPromptPasswordDialog::CPromptPasswordDialog(CWnd* pParent, const TCHAR* pTitle, const TCHAR* pText,
00119                                              const TCHAR* pInitPasswordText,
00120                                              BOOL bHasCheck, const TCHAR* pCheckText, int initCheckVal)
00121     : CDialog(CPromptPasswordDialog::IDD, pParent),
00122     m_bHasCheckBox(bHasCheck), m_bCheckBoxValue(initCheckVal)
00123 {   
00124        if(pTitle)
00125               m_csDialogTitle = pTitle;
00126        if(pText)
00127               m_csPromptText = pText;
00128        if(pInitPasswordText)
00129            m_csPassword = pInitPasswordText;
00130        if(pCheckText)
00131               m_csCheckBoxText = pCheckText;
00132 }
00133 
00134 void CPromptPasswordDialog::DoDataExchange(CDataExchange* pDX)
00135 {
00136     CDialog::DoDataExchange(pDX);
00137     //{{AFX_DATA_MAP(CPromptPasswordDialog)
00138     DDX_Text(pDX, IDC_PASSWORD, m_csPassword);
00139     DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue);
00140     //}}AFX_DATA_MAP
00141 }
00142 
00143 BEGIN_MESSAGE_MAP(CPromptPasswordDialog, CDialog)
00144     //{{AFX_MSG_MAP(CPromptPasswordDialog)
00145         // NOTE: the ClassWizard will add message map macros here
00146     //}}AFX_MSG_MAP
00147 END_MESSAGE_MAP()
00148 
00149 int CPromptPasswordDialog::OnInitDialog()
00150 {   
00151     SetWindowText(m_csDialogTitle);
00152   
00153     CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT);
00154     if(pWnd)
00155         pWnd->SetWindowText(m_csPromptText);
00156 
00157     CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD);
00158     if(pChk)
00159     {
00160         if (m_bHasCheckBox)
00161         {
00162             if(!m_csCheckBoxText.IsEmpty())
00163                 pChk->SetWindowText(m_csCheckBoxText);
00164             pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
00165         }
00166         else
00167         {
00168             // Hide the check box control if there's no label text
00169             // This will be the case when we're not using single sign-on
00170             pChk->ShowWindow(SW_HIDE); 
00171         }
00172     }
00173 
00174     CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PASSWORD);
00175     if(pEdit) 
00176     {
00177         pEdit->SetFocus();
00178 
00179         return 0; // Returning "0" since we're explicitly setting focus
00180     }
00181 
00182     return TRUE;
00183 }
00184 
00185 //--------------------------------------------------------------------------//
00186 //                          CPromptUsernamePasswordDialog Stuff
00187 //--------------------------------------------------------------------------//
00188 
00189 CPromptUsernamePasswordDialog::CPromptUsernamePasswordDialog(CWnd* pParent, const TCHAR* pTitle, const TCHAR* pText,
00190                                   const TCHAR* pInitUsername, const TCHAR* pInitPassword, 
00191                                         BOOL bHasCheck, const TCHAR* pCheckText, int initCheckVal)
00192     : CDialog(CPromptUsernamePasswordDialog::IDD, pParent),
00193     m_bHasCheckBox(bHasCheck), m_bCheckBoxValue(initCheckVal)
00194 {
00195     if(pTitle)
00196         m_csDialogTitle = pTitle;
00197     if(pText)
00198         m_csPromptText = pText;
00199     if(pInitUsername)
00200         m_csUserName = pInitUsername;
00201     if(pInitPassword)
00202         m_csPassword = pInitPassword;
00203     if(pCheckText)
00204         m_csCheckBoxText = pCheckText;
00205 }
00206 
00207 void CPromptUsernamePasswordDialog::DoDataExchange(CDataExchange* pDX)
00208 {
00209     CDialog::DoDataExchange(pDX);
00210     //{{AFX_DATA_MAP(CPromptUsernamePasswordDialog)
00211     DDX_Text(pDX, IDC_USERNAME, m_csUserName);
00212     DDX_Text(pDX, IDC_PASSWORD, m_csPassword);
00213     DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue);
00214     //}}AFX_DATA_MAP
00215 }
00216 
00217 BEGIN_MESSAGE_MAP(CPromptUsernamePasswordDialog, CDialog)
00218     //{{AFX_MSG_MAP(CPromptUsernamePasswordDialog)
00219         // NOTE: the ClassWizard will add message map macros here
00220     //}}AFX_MSG_MAP
00221 END_MESSAGE_MAP()
00222 
00223 int CPromptUsernamePasswordDialog::OnInitDialog()
00224 {   
00225        SetWindowText(m_csDialogTitle);
00226   
00227     CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT);
00228     if(pWnd)
00229         pWnd->SetWindowText(m_csPromptText);
00230 
00231     CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD);
00232     if(pChk)
00233     {
00234         if(m_bHasCheckBox)
00235         {
00236             if (!m_csCheckBoxText.IsEmpty())
00237                 pChk->SetWindowText(m_csCheckBoxText);
00238             pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
00239         }
00240         else
00241         {
00242             pChk->ShowWindow(SW_HIDE);
00243         }
00244     }
00245 
00246     CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PASSWORD);
00247     if(pEdit) 
00248     {
00249         pEdit->SetWindowText(m_csPassword);
00250     }
00251 
00252     pEdit = (CEdit *)GetDlgItem(IDC_USERNAME);
00253     if(pEdit) 
00254     {
00255         pEdit->SetWindowText(m_csUserName);
00256         pEdit->SetSel(0, -1);
00257 
00258         pEdit->SetFocus();
00259 
00260         return 0; // Returning "0" since we're explicitly setting focus
00261     }
00262 
00263     return TRUE;
00264 }
00265 
00266 //--------------------------------------------------------------------------//
00267 //                          CAlertCheckDialog Stuff
00268 //--------------------------------------------------------------------------//
00269 
00270 CAlertCheckDialog::CAlertCheckDialog(CWnd* pParent, const TCHAR* pTitle, const TCHAR* pText,
00271                              const TCHAR* pCheckText, int initCheckVal)
00272         : CDialog(CAlertCheckDialog::IDD, pParent)
00273 {   
00274     if(pTitle)
00275         m_csDialogTitle = pTitle;
00276     if(pText)
00277         m_csMsgText = pText;
00278     if(pCheckText)
00279         m_csCheckBoxText = pCheckText; 
00280 
00281     m_bCheckBoxValue = initCheckVal;
00282 }
00283 
00284 void CAlertCheckDialog::DoDataExchange(CDataExchange* pDX)
00285 {
00286     CDialog::DoDataExchange(pDX);
00287     //{{AFX_DATA_MAP(CAlertCheckDialog)
00288     DDX_Check(pDX, IDC_CHECKBOX, m_bCheckBoxValue);
00289     //}}AFX_DATA_MAP
00290 }
00291 
00292 BEGIN_MESSAGE_MAP(CAlertCheckDialog, CDialog)
00293     //{{AFX_MSG_MAP(CAlertCheckDialog)
00294         // NOTE: the ClassWizard will add message map macros here
00295     //}}AFX_MSG_MAP
00296 END_MESSAGE_MAP()
00297 
00298 int CAlertCheckDialog::OnInitDialog()
00299 {
00300     SetWindowText(m_csDialogTitle);
00301 
00302     CWnd *pWnd = GetDlgItem(IDC_MSG_TEXT);
00303     if(pWnd)
00304         pWnd->SetWindowText(m_csMsgText);
00305 
00306     CButton *pChk = (CButton *)GetDlgItem(IDC_CHECKBOX);
00307     if(pChk)
00308     {
00309         pChk->SetWindowText(m_csCheckBoxText);
00310         pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
00311     }
00312 
00313     return TRUE;
00314 }
00315 
00316 //--------------------------------------------------------------------------//
00317 //                          CConfirmCheckDialog Stuff
00318 //--------------------------------------------------------------------------//
00319 
00320 CConfirmCheckDialog::CConfirmCheckDialog(CWnd* pParent, const TCHAR* pTitle, const TCHAR* pText,
00321                             const TCHAR* pCheckText, int initCheckVal,
00322                             const TCHAR *pBtn1Text, const TCHAR *pBtn2Text, 
00323                             const TCHAR *pBtn3Text)
00324             : CDialog(CConfirmCheckDialog::IDD, pParent)
00325 {   
00326     if(pTitle)
00327         m_csDialogTitle = pTitle;
00328     if(pText)
00329         m_csMsgText = pText;
00330     if(pCheckText)
00331         m_csCheckBoxText = pCheckText; 
00332 
00333     m_bCheckBoxValue = initCheckVal;
00334 
00335     if(pBtn1Text)
00336         m_csBtn1Text = pBtn1Text;
00337     if(pBtn2Text)
00338         m_csBtn2Text = pBtn2Text;
00339     if(pBtn3Text)
00340         m_csBtn3Text = pBtn3Text;
00341 }
00342 
00343 void CConfirmCheckDialog::DoDataExchange(CDataExchange* pDX)
00344 {
00345     CDialog::DoDataExchange(pDX);
00346     //{{AFX_DATA_MAP(CConfirmCheckDialog)
00347     DDX_Check(pDX, IDC_CHECKBOX, m_bCheckBoxValue);
00348     //}}AFX_DATA_MAP
00349 }
00350 
00351 BEGIN_MESSAGE_MAP(CConfirmCheckDialog, CDialog)
00352     //{{AFX_MSG_MAP(CConfirmCheckDialog)
00353     ON_BN_CLICKED(IDC_BTN1, OnBtn1Clicked)
00354     ON_BN_CLICKED(IDC_BTN2, OnBtn2Clicked)
00355     ON_BN_CLICKED(IDC_BTN3, OnBtn3Clicked)
00356     //}}AFX_MSG_MAP
00357 END_MESSAGE_MAP()
00358 
00359 int CConfirmCheckDialog::OnInitDialog()
00360 {   
00361        SetWindowText(m_csDialogTitle);
00362   
00363     CWnd *pWnd = GetDlgItem(IDC_MSG_TEXT);
00364     if(pWnd)
00365         pWnd->SetWindowText(m_csMsgText);
00366 
00367     CButton *pChk = (CButton *)GetDlgItem(IDC_CHECKBOX);
00368     if(pChk)
00369     {
00370         if(m_csCheckBoxText.IsEmpty())
00371         {
00372             pChk->ShowWindow(SW_HIDE);
00373         }
00374         else
00375         {
00376             pChk->SetWindowText(m_csCheckBoxText);
00377             pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
00378         }
00379     }
00380 
00381     CButton *pBtn1 = (CButton *)GetDlgItem(IDC_BTN1);
00382     if(pBtn1)
00383     {
00384         if(m_csBtn1Text.IsEmpty())
00385             pBtn1->ShowWindow(SW_HIDE);
00386         else
00387             pBtn1->SetWindowText(m_csBtn1Text);
00388     }
00389 
00390     CButton *pBtn2 = (CButton *)GetDlgItem(IDC_BTN2);
00391     if(pBtn2)
00392     {
00393         if(m_csBtn2Text.IsEmpty())
00394             pBtn2->ShowWindow(SW_HIDE);
00395         else
00396             pBtn2->SetWindowText(m_csBtn2Text);
00397     }
00398 
00399     CButton *pBtn3 = (CButton *)GetDlgItem(IDC_BTN3);
00400     if(pBtn3)
00401     {
00402         if(m_csBtn3Text.IsEmpty())
00403             pBtn3->ShowWindow(SW_HIDE);
00404         else
00405             pBtn3->SetWindowText(m_csBtn3Text);
00406     }
00407 
00408     return TRUE;
00409 }
00410 
00411 void CConfirmCheckDialog::OnBtn1Clicked()
00412 {
00413     UpdateData();
00414 
00415     EndDialog(0); // where 0 indicates that the btn pressed was at index 0
00416 }
00417 
00418 void CConfirmCheckDialog::OnBtn2Clicked()
00419 {
00420     UpdateData();
00421 
00422     EndDialog(1); // where 1 indicates that the btn pressed was at index 1
00423 }
00424 
00425 void CConfirmCheckDialog::OnBtn3Clicked()
00426 {
00427     UpdateData();
00428 
00429     EndDialog(2); // where 2 indicates that the btn pressed was at index 2
00430 }