From 39b7be24c14408e1ccb13090bc8a2b7f97014c32 Mon Sep 17 00:00:00 2001 From: "amasri%netscape.com" Date: Wed, 20 Jun 2001 00:19:53 +0000 Subject: [PATCH] Created new tree structure for qa embedding tool (testembed). Adding files needed for testembed c++ project. Not part of the build. git-svn-id: svn://10.0.0.236/trunk@97498 18797224-902f-48f8-a5cc-f745e15eee43 --- .../qa/testembed/components/Dialogs.cpp | 256 ++++++++++++ .../qa/testembed/components/Dialogs.h | 126 ++++++ .../qa/testembed/components/Dialogs.rc | 136 +++++++ .../qa/testembed/components/PromptService.cpp | 383 ++++++++++++++++++ .../qa/testembed/components/PromptService.h | 45 ++ .../qa/testembed/components/makefile.win | 53 +++ .../qa/testembed/components/resource.h | 26 ++ .../qa/testembed/components/stdafx.h | 45 ++ 8 files changed, 1070 insertions(+) create mode 100644 mozilla/embedding/qa/testembed/components/Dialogs.cpp create mode 100644 mozilla/embedding/qa/testembed/components/Dialogs.h create mode 100644 mozilla/embedding/qa/testembed/components/Dialogs.rc create mode 100644 mozilla/embedding/qa/testembed/components/PromptService.cpp create mode 100644 mozilla/embedding/qa/testembed/components/PromptService.h create mode 100644 mozilla/embedding/qa/testembed/components/makefile.win create mode 100644 mozilla/embedding/qa/testembed/components/resource.h create mode 100644 mozilla/embedding/qa/testembed/components/stdafx.h diff --git a/mozilla/embedding/qa/testembed/components/Dialogs.cpp b/mozilla/embedding/qa/testembed/components/Dialogs.cpp new file mode 100644 index 00000000000..b8b37022e35 --- /dev/null +++ b/mozilla/embedding/qa/testembed/components/Dialogs.cpp @@ -0,0 +1,256 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2001 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +#include "stdafx.h" +#include "Dialogs.h" + +// File overview.... +// +// Contains dialog box code to support Alerts, Prompts such as +// password prompt and username/password prompts +// + +//--------------------------------------------------------------------------// +// CPromptDialog Stuff +//--------------------------------------------------------------------------// + +CPromptDialog::CPromptDialog(CWnd* pParent, const char* pTitle, const char* pText, + const char* pInitPromptText, + BOOL bHasCheck, const char* pCheckText, int initCheckVal) + : CDialog(CPromptDialog::IDD, pParent), + m_bHasCheckBox(bHasCheck) +{ + if(pTitle) + m_csDialogTitle = pTitle; + if(pText) + m_csPromptText = pText; + if(pInitPromptText) + m_csPromptAnswer = pInitPromptText; + if(pCheckText) + m_csCheckBoxText = pCheckText; +} + +void CPromptDialog::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CPromptDialog) + DDX_Text(pDX, IDC_PROMPT_ANSWER, m_csPromptAnswer); + DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue); + //}}AFX_DATA_MAP +} + +BEGIN_MESSAGE_MAP(CPromptDialog, CDialog) + //{{AFX_MSG_MAP(CPromptDialog) + // NOTE: the ClassWizard will add message map macros here + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +int CPromptDialog::OnInitDialog() +{ + SetWindowText(m_csDialogTitle); + + CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT); + if(pWnd) + pWnd->SetWindowText(m_csPromptText); + + CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD); + if(pChk) + { + if (m_bHasCheckBox) + { + if(!m_csCheckBoxText.IsEmpty()) + pChk->SetWindowText(m_csCheckBoxText); + pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED); + } + else + { + // Hide the check box control if there's no label text + // This will be the case when we're not using single sign-on + pChk->ShowWindow(SW_HIDE); + } + } + + CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PROMPT_ANSWER); + if(pEdit) + { + pEdit->SetWindowText(m_csPromptAnswer); + pEdit->SetFocus(); + pEdit->SetSel(0, -1); + + return 0; // Returning "0" since we're explicitly setting focus + } + + return TRUE; +} + +//--------------------------------------------------------------------------// +// CPromptPasswordDialog Stuff +//--------------------------------------------------------------------------// + +CPromptPasswordDialog::CPromptPasswordDialog(CWnd* pParent, const char* pTitle, const char* pText, + const char* pInitPasswordText, + BOOL bHasCheck, const char* pCheckText, int initCheckVal) + : CDialog(CPromptPasswordDialog::IDD, pParent), + m_bHasCheckBox(bHasCheck), m_bCheckBoxValue(initCheckVal) +{ + if(pTitle) + m_csDialogTitle = pTitle; + if(pText) + m_csPromptText = pText; + if(pInitPasswordText) + m_csPassword = pInitPasswordText; + if(pCheckText) + m_csCheckBoxText = pCheckText; +} + +void CPromptPasswordDialog::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CPromptPasswordDialog) + DDX_Text(pDX, IDC_PASSWORD, m_csPassword); + DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue); + //}}AFX_DATA_MAP +} + +BEGIN_MESSAGE_MAP(CPromptPasswordDialog, CDialog) + //{{AFX_MSG_MAP(CPromptPasswordDialog) + // NOTE: the ClassWizard will add message map macros here + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +int CPromptPasswordDialog::OnInitDialog() +{ + SetWindowText(m_csDialogTitle); + + CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT); + if(pWnd) + pWnd->SetWindowText(m_csPromptText); + + CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD); + if(pChk) + { + if (m_bHasCheckBox) + { + if(!m_csCheckBoxText.IsEmpty()) + pChk->SetWindowText(m_csCheckBoxText); + pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED); + } + else + { + // Hide the check box control if there's no label text + // This will be the case when we're not using single sign-on + pChk->ShowWindow(SW_HIDE); + } + } + + CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PASSWORD); + if(pEdit) + { + pEdit->SetFocus(); + + return 0; // Returning "0" since we're explicitly setting focus + } + + return TRUE; +} + +//--------------------------------------------------------------------------// +// CPromptUsernamePasswordDialog Stuff +//--------------------------------------------------------------------------// + +CPromptUsernamePasswordDialog::CPromptUsernamePasswordDialog(CWnd* pParent, const char* pTitle, const char* pText, + const char* pInitUsername, const char* pInitPassword, + BOOL bHasCheck, const char* pCheckText, int initCheckVal) + : CDialog(CPromptUsernamePasswordDialog::IDD, pParent), + m_bHasCheckBox(bHasCheck), m_bCheckBoxValue(initCheckVal) +{ + if(pTitle) + m_csDialogTitle = pTitle; + if(pText) + m_csPromptText = pText; + if(pInitUsername) + m_csUserName = pInitUsername; + if(pInitPassword) + m_csPassword = pInitPassword; + if(pCheckText) + m_csCheckBoxText = pCheckText; +} + +void CPromptUsernamePasswordDialog::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CPromptUsernamePasswordDialog) + DDX_Text(pDX, IDC_USERNAME, m_csUserName); + DDX_Text(pDX, IDC_PASSWORD, m_csPassword); + DDX_Check(pDX, IDC_CHECK_SAVE_PASSWORD, m_bCheckBoxValue); + //}}AFX_DATA_MAP +} + +BEGIN_MESSAGE_MAP(CPromptUsernamePasswordDialog, CDialog) + //{{AFX_MSG_MAP(CPromptUsernamePasswordDialog) + // NOTE: the ClassWizard will add message map macros here + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +int CPromptUsernamePasswordDialog::OnInitDialog() +{ + SetWindowText(m_csDialogTitle); + + CWnd *pWnd = GetDlgItem(IDC_PROMPT_TEXT); + if(pWnd) + pWnd->SetWindowText(m_csPromptText); + + CButton *pChk = (CButton *)GetDlgItem(IDC_CHECK_SAVE_PASSWORD); + if(pChk) + { + if(m_bHasCheckBox) + { + if (!m_csCheckBoxText.IsEmpty()) + pChk->SetWindowText(m_csCheckBoxText); + pChk->SetCheck(m_bCheckBoxValue ? BST_CHECKED : BST_UNCHECKED); + } + else + { + pChk->ShowWindow(SW_HIDE); + } + } + + CEdit *pEdit = (CEdit *)GetDlgItem(IDC_PASSWORD); + if(pEdit) + { + pEdit->SetWindowText(m_csPassword); + } + + pEdit = (CEdit *)GetDlgItem(IDC_USERNAME); + if(pEdit) + { + pEdit->SetWindowText(m_csUserName); + pEdit->SetSel(0, -1); + + pEdit->SetFocus(); + + return 0; // Returning "0" since we're explicitly setting focus + } + + return TRUE; +} diff --git a/mozilla/embedding/qa/testembed/components/Dialogs.h b/mozilla/embedding/qa/testembed/components/Dialogs.h new file mode 100644 index 00000000000..f76a05da45a --- /dev/null +++ b/mozilla/embedding/qa/testembed/components/Dialogs.h @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +#ifndef _DIALOGS_H_ +#define _DIALOGS_H_ + +#include "resource.h" + +class CPromptDialog : public CDialog +{ +public: + CPromptDialog(CWnd* pParent, const char* pTitle, const char* pText, + const char* pInitPromptText, + BOOL bHasCheck, const char* pCheckText, int initCheckVal); + + // Dialog Data + //{{AFX_DATA(CPromptDialog) + enum { IDD = IDD_PROMPT_DIALOG }; + CString m_csPromptAnswer; + //}}AFX_DATA + + CString m_csDialogTitle; + CString m_csPromptText; + BOOL m_bHasCheckBox; + CString m_csCheckBoxText; + int m_bCheckBoxValue; + + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CPromptDialog) + protected: + virtual void DoDataExchange(CDataExchange* pDX); + //}}AFX_VIRTUAL + + //{{AFX_MSG(CPromptDialog) + virtual BOOL OnInitDialog(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +class CPromptPasswordDialog : public CDialog +{ +public: + CPromptPasswordDialog(CWnd* pParent, const char* pTitle, const char* pText, + const char* pInitPasswordText, + BOOL bHasCheck, const char* pCheckText, int initCheckVal); + + // Dialog Data + //{{AFX_DATA(CPromptPasswordDialog) + enum { IDD = IDD_PROMPT_PASSWORD_DIALOG }; + //}}AFX_DATA + + CString m_csDialogTitle; + CString m_csPromptText; + CString m_csPassword; + BOOL m_bHasCheckBox; + CString m_csCheckBoxText; + int m_bCheckBoxValue; + + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CPromptPasswordDialog) + protected: + virtual void DoDataExchange(CDataExchange* pDX); + //}}AFX_VIRTUAL + + //{{AFX_MSG(CPromptPasswordDialog) + virtual BOOL OnInitDialog(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +class CPromptUsernamePasswordDialog : public CDialog +{ +public: + CPromptUsernamePasswordDialog(CWnd* pParent, const char* pTitle, const char* pText, + const char* pInitUsername, const char* pInitPassword, + BOOL bHasCheck, const char* pCheckText, int initCheckVal); + + // Dialog Data + //{{AFX_DATA(CPromptUsernamePasswordDialog) + enum { IDD = IDD_PROMPT_USERPASS_DIALOG }; + //}}AFX_DATA + + CString m_csDialogTitle; + CString m_csPromptText; + CString m_csUserNameLabel; + CString m_csPasswordLabel; + CString m_csPassword; + CString m_csUserName; + BOOL m_bHasCheckBox; + CString m_csCheckBoxText; + int m_bCheckBoxValue; + + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CPromptUsernamePasswordDialog) + protected: + virtual void DoDataExchange(CDataExchange* pDX); + //}}AFX_VIRTUAL + + //{{AFX_MSG(CPromptUsernamePasswordDialog) + virtual BOOL OnInitDialog(); + //}}AFX_MSG + + DECLARE_MESSAGE_MAP() +}; + +#endif //_DIALOG_H_ diff --git a/mozilla/embedding/qa/testembed/components/Dialogs.rc b/mozilla/embedding/qa/testembed/components/Dialogs.rc new file mode 100644 index 00000000000..0162cbf641c --- /dev/null +++ b/mozilla/embedding/qa/testembed/components/Dialogs.rc @@ -0,0 +1,136 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "#define _AFX_NO_SPLITTER_RESOURCES\r\n" + "#define _AFX_NO_OLE_RESOURCES\r\n" + "#define _AFX_NO_TRACKER_RESOURCES\r\n" + "#define _AFX_NO_PROPERTY_RESOURCES\r\n" + "\r\n" + "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n" + "#ifdef _WIN32\r\n" + "LANGUAGE 9, 1\r\n" + "#pragma code_page(1252)\r\n" + "#endif //_WIN32\r\n" + "#include ""res\\testembed.rc2"" // non-Microsoft Visual C++ edited resources\r\n" + "#include ""afxres.rc"" // Standard components\r\n" + "#endif\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_PROMPT_DIALOG DIALOG DISCARDABLE 0, 0, 249, 92 +STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Prompt Dialog" +FONT 8, "MS Sans Serif" +BEGIN + DEFPUSHBUTTON "OK",IDOK,130,69,50,14 + PUSHBUTTON "Cancel",IDCANCEL,189,69,50,14 + LTEXT "Please enter something....",IDC_PROMPT_TEXT,10,7,229,29 + EDITTEXT IDC_PROMPT_ANSWER,7,39,232,13,ES_AUTOHSCROLL + CONTROL "Save Answer",IDC_CHECK_SAVE_PASSWORD,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,57,229,10 +END + +IDD_PROMPT_PASSWORD_DIALOG DIALOG DISCARDABLE 0, 0, 248, 93 +STYLE DS_SYSMODAL | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "Password Entry Dialog" +FONT 8, "MS Sans Serif" +BEGIN + LTEXT "Please enter your password:",IDC_PROMPT_TEXT,5,7,232,20 + DEFPUSHBUTTON "OK",IDOK,129,75,50,14 + PUSHBUTTON "Cancel",IDCANCEL,188,75,50,14 + EDITTEXT IDC_PASSWORD,5,37,233,12,ES_PASSWORD | ES_AUTOHSCROLL + CONTROL "Save Password",IDC_CHECK_SAVE_PASSWORD,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,57,229,10 +END + +IDD_PROMPT_USERPASS_DIALOG DIALOG DISCARDABLE 0, 0, 214, 123 +STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Username and Password Required" +FONT 8, "MS Sans Serif" +BEGIN + LTEXT "This operation requires authentication. Please enter your user name and password:", + IDC_PROMPT_TEXT,6,9,171,25 + LTEXT "User Name:",IDC_USERNAME_LABEL,6,39,39,9 + EDITTEXT IDC_USERNAME,49,39,153,12,ES_AUTOHSCROLL + LTEXT "Password:",IDC_PASSWORD_LABEL,6,58,36,8 + EDITTEXT IDC_PASSWORD,49,56,153,12,ES_PASSWORD | ES_AUTOHSCROLL + CONTROL "Save User Name and Password",IDC_CHECK_SAVE_PASSWORD, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,78,201,10 + DEFPUSHBUTTON "OK",IDOK,40,101,50,14 + PUSHBUTTON "Cancel",IDCANCEL,95,101,50,14 +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// +#define _AFX_NO_SPLITTER_RESOURCES +#define _AFX_NO_OLE_RESOURCES +#define _AFX_NO_TRACKER_RESOURCES +#define _AFX_NO_PROPERTY_RESOURCES + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE 9, 1 +#pragma code_page(1252) +#endif //_WIN32 +#include "afxres.rc" // Standard components +#endif + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/mozilla/embedding/qa/testembed/components/PromptService.cpp b/mozilla/embedding/qa/testembed/components/PromptService.cpp new file mode 100644 index 00000000000..75199912442 --- /dev/null +++ b/mozilla/embedding/qa/testembed/components/PromptService.cpp @@ -0,0 +1,383 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2001 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +/* PromptService is intended to override the default Mozilla PromptService, + giving nsIPrompt implementations of our own design, rather than using + Mozilla's. Do this by building this into a component and registering the + factory with the same CID/ContractID as Mozilla's (see MfcEmbed.cpp). +*/ + +#include "stdafx.h" +#include "Dialogs.h" +#include "PromptService.h" +#include "nsCOMPtr.h" +#include "nsMemory.h" +#include "nsString.h" +#include "nsIDOMWindow.h" +#include "nsIEmbeddingSiteWindow.h" +#include "nsIFactory.h" +#include "nsIPromptService.h" +#include "nsIServiceManager.h" +#include "nsIWebBrowserChrome.h" +#include "nsIWindowWatcher.h" + +static HINSTANCE gInstance; + +//***************************************************************************** +// ResourceState +//***************************************************************************** + +class ResourceState { +public: + ResourceState() { + mPreviousInstance = ::AfxGetResourceHandle(); + ::AfxSetResourceHandle(gInstance); + } + ~ResourceState() { + ::AfxSetResourceHandle(mPreviousInstance); + } +private: + HINSTANCE mPreviousInstance; +}; + + +//***************************************************************************** +// CPromptService +//***************************************************************************** + +class CPromptService: public nsIPromptService { +public: + CPromptService(); + virtual ~CPromptService(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIPROMPTSERVICE + +private: + nsCOMPtr mWWatch; + CWnd *CWndForDOMWindow(nsIDOMWindow *aWindow); +}; + +//***************************************************************************** + +NS_IMPL_ISUPPORTS1(CPromptService, nsIPromptService) + +CPromptService::CPromptService() : + mWWatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")) +{ + NS_INIT_REFCNT(); +} + +CPromptService::~CPromptService() { +} + +CWnd * +CPromptService::CWndForDOMWindow(nsIDOMWindow *aWindow) +{ + nsCOMPtr chrome; + CWnd *val = 0; + + if (mWWatch) { + nsCOMPtr fosterParent; + if (!aWindow) { // it will be a dependent window. try to find a foster parent. + mWWatch->GetActiveWindow(getter_AddRefs(fosterParent)); + aWindow = fosterParent; + } + mWWatch->GetChromeForWindow(aWindow, getter_AddRefs(chrome)); + } + + if (chrome) { + nsCOMPtr site(do_QueryInterface(chrome)); + if (site) { + HWND w; + site->GetSiteWindow(reinterpret_cast(&w)); + val = CWnd::FromHandle(w); + } + } + + return val; +} + +NS_IMETHODIMP CPromptService::Alert(nsIDOMWindow *parent, const PRUnichar *dialogTitle, + const PRUnichar *text) +{ + USES_CONVERSION; + CWnd *wnd = CWndForDOMWindow(parent); + if (wnd) + wnd->MessageBox(W2T(text), W2T(dialogTitle), MB_OK | MB_ICONEXCLAMATION); + else + ::MessageBox(0, W2T(text), W2T(dialogTitle), MB_OK | MB_ICONEXCLAMATION); + + return NS_OK; +} + +NS_IMETHODIMP CPromptService::AlertCheck(nsIDOMWindow *parent, + const PRUnichar *dialogTitle, + const PRUnichar *text, + const PRUnichar *checkboxMsg, + PRBool *checkValue) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP CPromptService::Confirm(nsIDOMWindow *parent, + const PRUnichar *dialogTitle, + const PRUnichar *text, + PRBool *_retval) +{ + USES_CONVERSION; + CWnd *wnd = CWndForDOMWindow(parent); + int choice; + + if (wnd) + choice = wnd->MessageBox(W2T(text), W2T(dialogTitle), + MB_YESNO | MB_ICONEXCLAMATION); + else + choice = ::MessageBox(0, W2T(text), W2T(dialogTitle), + MB_YESNO | MB_ICONEXCLAMATION); + + *_retval = choice == IDYES ? PR_TRUE : PR_FALSE; + + return NS_OK; +} + +NS_IMETHODIMP CPromptService::ConfirmCheck(nsIDOMWindow *parent, + const PRUnichar *dialogTitle, + const PRUnichar *text, + const PRUnichar *checkboxMsg, + PRBool *checkValue, + PRBool *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP CPromptService::Prompt(nsIDOMWindow *parent, + const PRUnichar *dialogTitle, + const PRUnichar *text, + PRUnichar **value, + const PRUnichar *checkboxMsg, + PRBool *checkValue, + PRBool *_retval) +{ + ResourceState setState; + USES_CONVERSION; + + CWnd *wnd = CWndForDOMWindow(parent); + CPromptDialog dlg(wnd, W2T(dialogTitle), W2T(text), + text && *text ? W2T(text) : 0, + checkValue != nsnull, W2T(checkboxMsg), + checkValue ? *checkValue : 0); + if(dlg.DoModal() == IDOK) { + // Get the value entered in the editbox of the PromptDlg + if (value && *value) { + nsMemory::Free(*value); + *value = nsnull; + } + nsString csPromptEditValue; + csPromptEditValue.AssignWithConversion(dlg.m_csPromptAnswer.GetBuffer(0)); + + *value = csPromptEditValue.ToNewUnicode(); + + *_retval = PR_TRUE; + } else + *_retval = PR_FALSE; + + return NS_OK; +} + +NS_IMETHODIMP CPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent, + const PRUnichar *dialogTitle, + const PRUnichar *text, + PRUnichar **username, + PRUnichar **password, + const PRUnichar *checkboxMsg, + PRBool *checkValue, + PRBool *_retval) +{ + ResourceState setState; + USES_CONVERSION; + + CWnd *wnd = CWndForDOMWindow(parent); + CPromptUsernamePasswordDialog dlg(wnd, W2T(dialogTitle), W2T(text), + username && *username ? W2T(*username) : 0, + password && *password ? W2T(*password) : 0, + checkValue != nsnull, W2T(checkboxMsg), + checkValue ? *checkValue : 0); + + if (dlg.DoModal() == IDOK) { + // Get the username entered + if (username && *username) { + nsMemory::Free(*username); + *username = nsnull; + } + nsString csUserName; + csUserName.AssignWithConversion(dlg.m_csUserName.GetBuffer(0)); + *username = csUserName.ToNewUnicode(); + + // Get the password entered + if (password && *password) { + nsMemory::Free(*password); + *password = nsnull; + } + nsString csPassword; + csPassword.AssignWithConversion(dlg.m_csPassword.GetBuffer(0)); + *password = csPassword.ToNewUnicode(); + + if(checkValue) + *checkValue = dlg.m_bCheckBoxValue; + + *_retval = PR_TRUE; + } else + *_retval = PR_FALSE; + + return NS_OK; +} + +NS_IMETHODIMP CPromptService::PromptPassword(nsIDOMWindow *parent, + const PRUnichar *dialogTitle, + const PRUnichar *text, + PRUnichar **password, + const PRUnichar *checkboxMsg, + PRBool *checkValue, + PRBool *_retval) +{ + ResourceState setState; + USES_CONVERSION; + + CWnd *wnd = CWndForDOMWindow(parent); + CPromptPasswordDialog dlg(wnd, W2T(dialogTitle), W2T(text), + password && *password ? W2T(*password) : 0, + checkValue != nsnull, W2T(checkboxMsg), + checkValue ? *checkValue : 0); + if(dlg.DoModal() == IDOK) { + // Get the password entered + if (password && *password) { + nsMemory::Free(*password); + *password = nsnull; + } + nsString csPassword; + csPassword.AssignWithConversion(dlg.m_csPassword.GetBuffer(0)); + *password = csPassword.ToNewUnicode(); + + if(checkValue) + *checkValue = dlg.m_bCheckBoxValue; + + *_retval = PR_TRUE; + } else + *_retval = PR_FALSE; + + return NS_OK; +} + +NS_IMETHODIMP CPromptService::Select(nsIDOMWindow *parent, + const PRUnichar *dialogTitle, + const PRUnichar *text, PRUint32 count, + const PRUnichar **selectList, + PRInt32 *outSelection, + PRBool *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP CPromptService::ConfirmEx(nsIDOMWindow *parent, + const PRUnichar *dialogTitle, + const PRUnichar *text, + PRUint32 buttonFlags, + const PRUnichar *button0Title, + const PRUnichar *button1Title, + const PRUnichar *button2Title, + const PRUnichar *checkMsg, + PRBool *checkValue, + PRInt32 *buttonPressed) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +//***************************************************************************** +// CPromptServiceFactory +//***************************************************************************** + +class CPromptServiceFactory : public nsIFactory { +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIFACTORY + + CPromptServiceFactory(); + virtual ~CPromptServiceFactory(); +}; + +//***************************************************************************** + +NS_IMPL_ISUPPORTS1(CPromptServiceFactory, nsIFactory) + +CPromptServiceFactory::CPromptServiceFactory() { + + NS_INIT_ISUPPORTS(); +} + +CPromptServiceFactory::~CPromptServiceFactory() { +} + +NS_IMETHODIMP CPromptServiceFactory::CreateInstance(nsISupports *aOuter, const nsIID & aIID, void **aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + *aResult = NULL; + CPromptService *inst = new CPromptService; + if (!inst) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv = inst->QueryInterface(aIID, aResult); + if (rv != NS_OK) { + // We didn't get the right interface, so clean up + delete inst; + } + + return rv; +} + +NS_IMETHODIMP CPromptServiceFactory::LockFactory(PRBool lock) +{ + return NS_OK; +} + +//***************************************************************************** + +void InitPromptService(HINSTANCE instance) { + + gInstance = instance; +} + +nsresult NS_NewPromptServiceFactory(nsIFactory** aFactory) +{ + NS_ENSURE_ARG_POINTER(aFactory); + *aFactory = nsnull; + + CPromptServiceFactory *result = new CPromptServiceFactory; + if (!result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + *aFactory = result; + + return NS_OK; +} diff --git a/mozilla/embedding/qa/testembed/components/PromptService.h b/mozilla/embedding/qa/testembed/components/PromptService.h new file mode 100644 index 00000000000..7cde2e01a3b --- /dev/null +++ b/mozilla/embedding/qa/testembed/components/PromptService.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2001 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef __PromptService_h +#define __PromptService_h + +#include "nsError.h" + +// this component is for an MFC app; it's Windows. make sure this is defined. +#ifndef XP_WIN +#define XP_WIN +#endif + +class nsIFactory; + +// factory creator, in hard and soft link formats +extern "C" NS_EXPORT nsresult NS_NewPromptServiceFactory(nsIFactory** aFactory); +typedef nsresult (__cdecl *MakeFactoryType)(nsIFactory **); +#define kPromptServiceFactoryFuncName "NS_NewPromptServiceFactory" + +// initialization function, in hard and soft link formats +extern "C" NS_EXPORT void InitPromptService(HINSTANCE instance); +typedef nsresult (__cdecl *InitPromptServiceType)(HINSTANCE instance); +#define kPromptServiceInitFuncName "InitPromptService" + +#endif diff --git a/mozilla/embedding/qa/testembed/components/makefile.win b/mozilla/embedding/qa/testembed/components/makefile.win new file mode 100644 index 00000000000..a5bd91978c4 --- /dev/null +++ b/mozilla/embedding/qa/testembed/components/makefile.win @@ -0,0 +1,53 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications, Inc. Portions created by Netscape are +# Copyright (C) 2001, Mozilla. All Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\..\.. + +MAKE_OBJ_TYPE=DLL +DLLNAME=mfcEmbedComponents +DLL=.\$(OBJDIR)\$(DLLNAME).dll +RESFILE=Dialogs.res + +LCFLAGS=/D "WIN32_LEAN_AND_MEAN" /D "_AFXDLL" /D "USE_SINGLE_SIGN_ON" \ + /D "_USRDLL" /D "_WINDLL" + +LLFLAGS=-SUBSYSTEM:windows + +CPP_OBJS= \ + .\$(OBJDIR)\Dialogs.obj \ + .\$(OBJDIR)\PromptService.obj \ + $(NULL) + +LLIBS= \ + $(LIBNSPR) \ + $(DIST)\lib\xpcom.lib \ + $(NULL) + +include <$(DEPTH)\config\rules.mak> + +Dialogs.res: Dialogs.rc resource.h + +install:: $(DLL) + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib + +clobber:: + $(RM) $(DIST)\bin\$(DLL_NAME).dll + $(RM) $(DIST)\lib\$(DLL_NAME).lib diff --git a/mozilla/embedding/qa/testembed/components/resource.h b/mozilla/embedding/qa/testembed/components/resource.h new file mode 100644 index 00000000000..d81b9958ac6 --- /dev/null +++ b/mozilla/embedding/qa/testembed/components/resource.h @@ -0,0 +1,26 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by Dialogs.rc +// +#define IDD_PROMPT_DIALOG 128 +#define IDD_PROMPT_PASSWORD_DIALOG 129 +#define IDD_PROMPT_USERPASS_DIALOG 130 +#define IDC_PROMPT_ANSWER 1001 +#define IDC_PROMPT_TEXT 1002 +#define IDC_USERNAME 1003 +#define IDC_PASSWORD 1004 +#define IDC_CHECK_SAVE_PASSWORD 1005 +#define IDC_USERNAME_LABEL 1006 +#define IDC_PASSWORD_LABEL 1007 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_3D_CONTROLS 1 +#define _APS_NEXT_RESOURCE_VALUE 143 +#define _APS_NEXT_COMMAND_VALUE 32789 +#define _APS_NEXT_CONTROL_VALUE 1022 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/mozilla/embedding/qa/testembed/components/stdafx.h b/mozilla/embedding/qa/testembed/components/stdafx.h new file mode 100644 index 00000000000..20678001f74 --- /dev/null +++ b/mozilla/embedding/qa/testembed/components/stdafx.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#ifndef _STDAFX_H +#define _STDAFX_H + +#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers + +#include // MFC core and standard components +#include // MFC extensions +#include // MFC support for Internet Explorer 4 Common Controls +#include // Needed for MFC MBCS/Unicode Conversion Macros +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC support for Windows Common Controls +#endif // _AFX_NO_AFXCMN_SUPPORT + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif //_STDAFX_H