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: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org Code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Chak Nanga <chak@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "stdafx.h"
00040 #include "Dialogs.h"
00041 
00042 // File overview....
00043 //
00044 // Contains dialog box code to support Alerts, Prompts such as
00045 // password prompt and username/password prompts
00046 //
00047 
00048 //--------------------------------------------------------------------------//
00049 //                          CPromptDialog Stuff
00050 //--------------------------------------------------------------------------//
00051 
00052 CPromptDialog::CPromptDialog(CWnd* pParent, const char* pTitle, const char* pText,
00053                              const char* pInitPromptText,
00054                              BOOL bHasCheck, const char* pCheckText, int initCheckVal)
00055     : CDialog(CPromptDialog::IDD, pParent),
00056     m_bHasCheckBox(bHasCheck)
00057 {   
00058     if(pTitle)
00059         m_csDialogTitle = pTitle;
00060     if(pText)
00061         m_csPromptText = pText;
00062     if(pInitPromptText)
00063         m_csPromptAnswer = pInitPromptText;
00064     if(pCheckText)
00065         m_csCheckBoxText = pCheckText; 
00066 }
00067 
00068 void CPromptDialog::DoDataExchange(CDataExchange* pDX)
00069 {
00070     CDialog::DoDataExchange(pDX);
00071     //{{AFX_DATA_MAP(CPromptDialog)
00072     DDX_Text(pDX, IDC_PROMPT_ANSWER, m_csPromptAnswer);
00073     DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue);
00074     //}}AFX_DATA_MAP
00075 }
00076 
00077 BEGIN_MESSAGE_MAP(CPromptDialog, CDialog)
00078     //{{AFX_MSG_MAP(CPromptDialog)
00079         // NOTE: the ClassWizard will add message map macros here
00080     //}}AFX_MSG_MAP
00081 END_MESSAGE_MAP()
00082 
00083 int CPromptDialog::OnInitDialog()
00084 {   
00085     SetWindowText(m_csDialogTitle);
00086   
00087     CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT);
00088     if(pWnd)
00089         pWnd->SetWindowText(m_csPromptText);
00090 
00091     CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD);
00092     if(pChk)
00093     {
00094         if (m_bHasCheckBox)
00095         {
00096             if(!m_csCheckBoxText.IsEmpty())
00097                 pChk->SetWindowText(m_csCheckBoxText);
00098             pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
00099         }
00100         else
00101         {
00102             // Hide the check box control if there's no label text
00103             // This will be the case when we're not using single sign-on
00104             pChk->ShowWindow(SW_HIDE); 
00105         }
00106     }
00107 
00108     CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PROMPT_ANSWER);
00109     if(pEdit) 
00110     {
00111         pEdit->SetWindowText(m_csPromptAnswer);
00112         pEdit->SetFocus();
00113         pEdit->SetSel(0, -1);
00114 
00115         return 0; // Returning "0" since we're explicitly setting focus
00116     }
00117 
00118     return TRUE;
00119 }
00120 
00121 //--------------------------------------------------------------------------//
00122 //                          CPromptPasswordDialog Stuff
00123 //--------------------------------------------------------------------------//
00124 
00125 CPromptPasswordDialog::CPromptPasswordDialog(CWnd* pParent, const char* pTitle, const char* pText,
00126                                              const char* pInitPasswordText,
00127                                              BOOL bHasCheck, const char* pCheckText, int initCheckVal)
00128     : CDialog(CPromptPasswordDialog::IDD, pParent),
00129     m_bHasCheckBox(bHasCheck), m_bCheckBoxValue(initCheckVal)
00130 {   
00131        if(pTitle)
00132               m_csDialogTitle = pTitle;
00133        if(pText)
00134               m_csPromptText = pText;
00135        if(pInitPasswordText)
00136            m_csPassword = pInitPasswordText;
00137        if(pCheckText)
00138               m_csCheckBoxText = pCheckText;
00139 }
00140 
00141 void CPromptPasswordDialog::DoDataExchange(CDataExchange* pDX)
00142 {
00143     CDialog::DoDataExchange(pDX);
00144     //{{AFX_DATA_MAP(CPromptPasswordDialog)
00145     DDX_Text(pDX, IDC_PASSWORD, m_csPassword);
00146     DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue);
00147     //}}AFX_DATA_MAP
00148 }
00149 
00150 BEGIN_MESSAGE_MAP(CPromptPasswordDialog, CDialog)
00151     //{{AFX_MSG_MAP(CPromptPasswordDialog)
00152         // NOTE: the ClassWizard will add message map macros here
00153     //}}AFX_MSG_MAP
00154 END_MESSAGE_MAP()
00155 
00156 int CPromptPasswordDialog::OnInitDialog()
00157 {   
00158     SetWindowText(m_csDialogTitle);
00159   
00160     CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT);
00161     if(pWnd)
00162         pWnd->SetWindowText(m_csPromptText);
00163 
00164     CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD);
00165     if(pChk)
00166     {
00167         if (m_bHasCheckBox)
00168         {
00169             if(!m_csCheckBoxText.IsEmpty())
00170                 pChk->SetWindowText(m_csCheckBoxText);
00171             pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
00172         }
00173         else
00174         {
00175             // Hide the check box control if there's no label text
00176             // This will be the case when we're not using single sign-on
00177             pChk->ShowWindow(SW_HIDE); 
00178         }
00179     }
00180 
00181     CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PASSWORD);
00182     if(pEdit) 
00183     {
00184         pEdit->SetFocus();
00185 
00186         return 0; // Returning "0" since we're explicitly setting focus
00187     }
00188 
00189     return TRUE;
00190 }
00191 
00192 //--------------------------------------------------------------------------//
00193 //                          CPromptUsernamePasswordDialog Stuff
00194 //--------------------------------------------------------------------------//
00195 
00196 CPromptUsernamePasswordDialog::CPromptUsernamePasswordDialog(CWnd* pParent, const char* pTitle, const char* pText,
00197                                   const char* pInitUsername, const char* pInitPassword, 
00198                                         BOOL bHasCheck, const char* pCheckText, int initCheckVal)
00199     : CDialog(CPromptUsernamePasswordDialog::IDD, pParent),
00200     m_bHasCheckBox(bHasCheck), m_bCheckBoxValue(initCheckVal)
00201 {
00202     if(pTitle)
00203         m_csDialogTitle = pTitle;
00204     if(pText)
00205         m_csPromptText = pText;
00206     if(pInitUsername)
00207         m_csUserName = pInitUsername;
00208     if(pInitPassword)
00209         m_csPassword = pInitPassword;
00210     if(pCheckText)
00211         m_csCheckBoxText = pCheckText;
00212 }
00213 
00214 void CPromptUsernamePasswordDialog::DoDataExchange(CDataExchange* pDX)
00215 {
00216     CDialog::DoDataExchange(pDX);
00217     //{{AFX_DATA_MAP(CPromptUsernamePasswordDialog)
00218     DDX_Text(pDX, IDC_USERNAME, m_csUserName);
00219     DDX_Text(pDX, IDC_PASSWORD, m_csPassword);
00220     DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue);
00221     //}}AFX_DATA_MAP
00222 }
00223 
00224 BEGIN_MESSAGE_MAP(CPromptUsernamePasswordDialog, CDialog)
00225     //{{AFX_MSG_MAP(CPromptUsernamePasswordDialog)
00226         // NOTE: the ClassWizard will add message map macros here
00227     //}}AFX_MSG_MAP
00228 END_MESSAGE_MAP()
00229 
00230 int CPromptUsernamePasswordDialog::OnInitDialog()
00231 {   
00232        SetWindowText(m_csDialogTitle);
00233   
00234     CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT);
00235     if(pWnd)
00236         pWnd->SetWindowText(m_csPromptText);
00237 
00238     CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD);
00239     if(pChk)
00240     {
00241         if(m_bHasCheckBox)
00242         {
00243             if (!m_csCheckBoxText.IsEmpty())
00244                 pChk->SetWindowText(m_csCheckBoxText);
00245             pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
00246         }
00247         else
00248         {
00249             pChk->ShowWindow(SW_HIDE);
00250         }
00251     }
00252 
00253     CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PASSWORD);
00254     if(pEdit) 
00255     {
00256         pEdit->SetWindowText(m_csPassword);
00257     }
00258 
00259     pEdit = (CEdit *)GetDlgItem(IDC_USERNAME);
00260     if(pEdit) 
00261     {
00262         pEdit->SetWindowText(m_csUserName);
00263         pEdit->SetSel(0, -1);
00264 
00265         pEdit->SetFocus();
00266 
00267         return 0; // Returning "0" since we're explicitly setting focus
00268     }
00269 
00270     return TRUE;
00271 }
00272 
00273 //--------------------------------------------------------------------------//
00274 //                          CAlertCheckDialog Stuff
00275 //--------------------------------------------------------------------------//
00276 
00277 CAlertCheckDialog::CAlertCheckDialog(CWnd* pParent, const char* pTitle, const char* pText,
00278                              const char* pCheckText, int initCheckVal)
00279         : CDialog(CAlertCheckDialog::IDD, pParent)
00280 {   
00281     if(pTitle)
00282         m_csDialogTitle = pTitle;
00283     if(pText)
00284         m_csMsgText = pText;
00285     if(pCheckText)
00286         m_csCheckBoxText = pCheckText; 
00287 
00288     m_bCheckBoxValue = initCheckVal;
00289 }
00290 
00291 void CAlertCheckDialog::DoDataExchange(CDataExchange* pDX)
00292 {
00293     CDialog::DoDataExchange(pDX);
00294     //{{AFX_DATA_MAP(CAlertCheckDialog)
00295     DDX_Check(pDX, IDC_CHECKBOX, m_bCheckBoxValue);
00296     //}}AFX_DATA_MAP
00297 }
00298 
00299 BEGIN_MESSAGE_MAP(CAlertCheckDialog, CDialog)
00300     //{{AFX_MSG_MAP(CAlertCheckDialog)
00301         // NOTE: the ClassWizard will add message map macros here
00302     //}}AFX_MSG_MAP
00303 END_MESSAGE_MAP()
00304 
00305 int CAlertCheckDialog::OnInitDialog()
00306 {
00307     SetWindowText(m_csDialogTitle);
00308 
00309     CWnd *pWnd = GetDlgItem(IDC_MSG_TEXT);
00310     if(pWnd)
00311         pWnd->SetWindowText(m_csMsgText);
00312 
00313     CButton *pChk = (CButton *)GetDlgItem(IDC_CHECKBOX);
00314     if(pChk)
00315     {
00316         pChk->SetWindowText(m_csCheckBoxText);
00317         pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
00318     }
00319 
00320     return TRUE;
00321 }
00322 
00323 //--------------------------------------------------------------------------//
00324 //                          CConfirmCheckDialog Stuff
00325 //--------------------------------------------------------------------------//
00326 
00327 CConfirmCheckDialog::CConfirmCheckDialog(CWnd* pParent, const char* pTitle, const char* pText,
00328                             const char* pCheckText, int initCheckVal,
00329                             const char *pBtn1Text, const char *pBtn2Text, 
00330                             const char *pBtn3Text)
00331             : CDialog(CConfirmCheckDialog::IDD, pParent)
00332 {   
00333     if(pTitle)
00334         m_csDialogTitle = pTitle;
00335     if(pText)
00336         m_csMsgText = pText;
00337     if(pCheckText)
00338         m_csCheckBoxText = pCheckText; 
00339 
00340     m_bCheckBoxValue = initCheckVal;
00341 
00342     if(pBtn1Text)
00343         m_csBtn1Text = pBtn1Text;
00344     if(pBtn2Text)
00345         m_csBtn2Text = pBtn2Text;
00346     if(pBtn3Text)
00347         m_csBtn3Text = pBtn3Text;
00348 }
00349 
00350 void CConfirmCheckDialog::DoDataExchange(CDataExchange* pDX)
00351 {
00352     CDialog::DoDataExchange(pDX);
00353     //{{AFX_DATA_MAP(CConfirmCheckDialog)
00354     DDX_Check(pDX, IDC_CHECKBOX, m_bCheckBoxValue);
00355     //}}AFX_DATA_MAP
00356 }
00357 
00358 BEGIN_MESSAGE_MAP(CConfirmCheckDialog, CDialog)
00359     //{{AFX_MSG_MAP(CConfirmCheckDialog)
00360     ON_BN_CLICKED(IDC_BTN1, OnBtn1Clicked)
00361     ON_BN_CLICKED(IDC_BTN2, OnBtn2Clicked)
00362     ON_BN_CLICKED(IDC_BTN3, OnBtn3Clicked)
00363     //}}AFX_MSG_MAP
00364 END_MESSAGE_MAP()
00365 
00366 int CConfirmCheckDialog::OnInitDialog()
00367 {   
00368        SetWindowText(m_csDialogTitle);
00369   
00370     CWnd *pWnd = GetDlgItem(IDC_MSG_TEXT);
00371     if(pWnd)
00372         pWnd->SetWindowText(m_csMsgText);
00373 
00374     CButton *pChk = (CButton *)GetDlgItem(IDC_CHECKBOX);
00375     if(pChk)
00376     {
00377         if(m_csCheckBoxText.IsEmpty())
00378         {
00379             pChk->ShowWindow(SW_HIDE);
00380         }
00381         else
00382         {
00383             pChk->SetWindowText(m_csCheckBoxText);
00384             pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED);
00385         }
00386     }
00387 
00388     CButton *pBtn1 = (CButton *)GetDlgItem(IDC_BTN1);
00389     if(pBtn1)
00390     {
00391         if(m_csBtn1Text.IsEmpty())
00392             pBtn1->ShowWindow(SW_HIDE);
00393         else
00394             pBtn1->SetWindowText(m_csBtn1Text);
00395     }
00396 
00397     CButton *pBtn2 = (CButton *)GetDlgItem(IDC_BTN2);
00398     if(pBtn2)
00399     {
00400         if(m_csBtn2Text.IsEmpty())
00401             pBtn2->ShowWindow(SW_HIDE);
00402         else
00403             pBtn2->SetWindowText(m_csBtn2Text);
00404     }
00405 
00406     CButton *pBtn3 = (CButton *)GetDlgItem(IDC_BTN3);
00407     if(pBtn3)
00408     {
00409         if(m_csBtn3Text.IsEmpty())
00410             pBtn3->ShowWindow(SW_HIDE);
00411         else
00412             pBtn3->SetWindowText(m_csBtn3Text);
00413     }
00414 
00415     return TRUE;
00416 }
00417 
00418 void CConfirmCheckDialog::OnBtn1Clicked()
00419 {
00420     UpdateData();
00421 
00422     EndDialog(0); // where 0 indicates that the btn pressed was at index 0
00423 }
00424 
00425 void CConfirmCheckDialog::OnBtn2Clicked()
00426 {
00427     UpdateData();
00428 
00429     EndDialog(1); // where 1 indicates that the btn pressed was at index 1
00430 }
00431 
00432 void CConfirmCheckDialog::OnBtn3Clicked()
00433 {
00434     UpdateData();
00435 
00436     EndDialog(2); // where 2 indicates that the btn pressed was at index 2
00437 }