diff --git a/embedding/tests/mfcembed/BrowserFrameGlue.cpp b/embedding/tests/mfcembed/BrowserFrameGlue.cpp index 32e094ec999..397134052d0 100644 --- a/embedding/tests/mfcembed/BrowserFrameGlue.cpp +++ b/embedding/tests/mfcembed/BrowserFrameGlue.cpp @@ -386,134 +386,8 @@ void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags, } } -void CBrowserFrame::BrowserFrameGlueObj::Alert(const PRUnichar *dialogTitle, const PRUnichar *text) +HWND CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameNativeWnd() { METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) - - USES_CONVERSION; - - pThis->MessageBox(W2T(text), W2T(dialogTitle), MB_OK | MB_ICONEXCLAMATION); -} - -void CBrowserFrame::BrowserFrameGlueObj::Confirm(const PRUnichar *dialogTitle, const PRUnichar *text, PRBool *retval) -{ - METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) - - USES_CONVERSION; - - int iChoice = pThis->MessageBox(W2T(text), W2T(dialogTitle), MB_YESNO | MB_ICONEXCLAMATION); - - *retval = (iChoice == IDYES) ? PR_TRUE : PR_FALSE; -} - -void CBrowserFrame::BrowserFrameGlueObj::Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, - PRUnichar **promptText, - const PRUnichar *checkboxMsg, PRBool *checkboxState, - PRBool *retval) -{ - METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) - - USES_CONVERSION; - - CPromptDialog dlg(pThis, W2T(dialogTitle), W2T(text), - (promptText && *promptText) ? W2T(*promptText) : nsnull, - (checkboxState != nsnull), W2T(checkboxMsg), checkboxState ? *checkboxState : 0); - if(dlg.DoModal() == IDOK) - { - // Get the value entered in the editbox of the PromptDlg - if (promptText && *promptText) { - nsMemory::Free(*promptText); - *promptText = nsnull; - } - nsString csPromptEditValue; - csPromptEditValue.AssignWithConversion(dlg.m_csPromptAnswer.GetBuffer(0)); - - *promptText = csPromptEditValue.ToNewUnicode(); - - *retval = PR_TRUE; - } - else - { - *retval = PR_FALSE; - } -} - -void CBrowserFrame::BrowserFrameGlueObj::PromptPassword(const PRUnichar *dialogTitle, const PRUnichar *text, - PRUnichar **password, - const PRUnichar *checkboxMsg, PRBool *checkboxState, - PRBool *retval) -{ - METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) - - USES_CONVERSION; - - CPromptPasswordDialog dlg(pThis, W2T(dialogTitle), W2T(text), - (password && *password) ? W2T(*password) : nsnull, - (checkboxState != nsnull), W2T(checkboxMsg), checkboxState ? *checkboxState : 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(checkboxState) - *checkboxState = dlg.m_bCheckBoxValue; - - *retval = PR_TRUE; - } - else - { - *retval = PR_FALSE; - } -} - -void CBrowserFrame::BrowserFrameGlueObj::PromptUserNamePassword(const PRUnichar *dialogTitle, const PRUnichar *text, - PRUnichar **username, PRUnichar **password, - const PRUnichar *checkboxMsg, PRBool *checkboxState, - PRBool *retval) -{ - METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) - - USES_CONVERSION; - - CPromptUsernamePasswordDialog dlg(pThis, W2T(dialogTitle), W2T(text), - (username && *username) ? W2T(*username) : nsnull, - (password && *password) ? W2T(*password) : nsnull, - (checkboxState != nsnull), W2T(checkboxMsg), checkboxState ? *checkboxState : 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(checkboxState) - *checkboxState = dlg.m_bCheckBoxValue; - - *retval = PR_TRUE; - - } - else - { - *retval = PR_FALSE; - } + return pThis->m_hWnd; } diff --git a/embedding/tests/mfcembed/BrowserImpl.cpp b/embedding/tests/mfcembed/BrowserImpl.cpp index b655bdedca6..10de6cf98c5 100644 --- a/embedding/tests/mfcembed/BrowserImpl.cpp +++ b/embedding/tests/mfcembed/BrowserImpl.cpp @@ -35,8 +35,8 @@ // This file currently has the implementation for all the interfaces // which are required of an app embedding Gecko // Implementation of other optional interfaces are in separate files -// so as to avoid cluttering this one. For ex, implementation of -// nsIPrompt is in BrowserImplPrompt.cpp etc. +// to avoid cluttering this one and to demonstrate other embedding +// principles. For example, nsIPrompt is implemented in a separate DLL. // // nsIWebBrowserChrome - This is a required interface to be implemented // by embeddors @@ -84,7 +84,7 @@ CBrowserImpl::~CBrowserImpl() // Call on this Init() method with proper values after creation // NS_METHOD CBrowserImpl::Init(PBROWSERFRAMEGLUE pBrowserFrameGlue, - nsIWebBrowser* aWebBrowser) + nsIWebBrowser* aWebBrowser) { m_pBrowserFrameGlue = pBrowserFrameGlue; @@ -107,7 +107,6 @@ NS_INTERFACE_MAP_BEGIN(CBrowserImpl) NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow) NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener) - NS_INTERFACE_MAP_ENTRY(nsIPrompt) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_END @@ -292,7 +291,15 @@ NS_IMETHODIMP CBrowserImpl::GetDimensions(PRUint32 aFlags, PRInt32 *x, PRInt32 * NS_IMETHODIMP CBrowserImpl::GetSiteWindow(void** aSiteWindow) { - return NS_ERROR_NOT_IMPLEMENTED; + if (!aSiteWindow) + return NS_ERROR_NULL_POINTER; + + *aSiteWindow = 0; + if (m_pBrowserFrameGlue) { + HWND w = m_pBrowserFrameGlue->GetBrowserFrameNativeWnd(); + *aSiteWindow = NS_REINTERPRET_CAST(void *, w); + } + return NS_OK; } NS_IMETHODIMP CBrowserImpl::SetFocus() diff --git a/embedding/tests/mfcembed/BrowserImpl.h b/embedding/tests/mfcembed/BrowserImpl.h index 7d71808585c..b974b18dc69 100644 --- a/embedding/tests/mfcembed/BrowserImpl.h +++ b/embedding/tests/mfcembed/BrowserImpl.h @@ -31,28 +31,26 @@ class CBrowserImpl : public nsIInterfaceRequestor, public nsIEmbeddingSiteWindow, public nsIWebProgressListener, public nsIContextMenuListener, - public nsIPrompt, public nsSupportsWeakReference { public: CBrowserImpl(); ~CBrowserImpl(); - NS_METHOD Init(PBROWSERFRAMEGLUE pBrowserFrameGlue, - nsIWebBrowser* aWebBrowser); + NS_METHOD Init(PBROWSERFRAMEGLUE pBrowserFrameGlue, + nsIWebBrowser* aWebBrowser); NS_DECL_ISUPPORTS - NS_DECL_NSIINTERFACEREQUESTOR + NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSIWEBBROWSERCHROME NS_DECL_NSIEMBEDDINGSITEWINDOW NS_DECL_NSIWEBPROGRESSLISTENER - NS_DECL_NSICONTEXTMENULISTENER - NS_DECL_NSIPROMPT + NS_DECL_NSICONTEXTMENULISTENER protected: - PBROWSERFRAMEGLUE m_pBrowserFrameGlue; + PBROWSERFRAMEGLUE m_pBrowserFrameGlue; - nsCOMPtr mWebBrowser; + nsCOMPtr mWebBrowser; }; -#endif //_BROWSERIMPL_H \ No newline at end of file +#endif //_BROWSERIMPL_H diff --git a/embedding/tests/mfcembed/Dialogs.cpp b/embedding/tests/mfcembed/Dialogs.cpp index eed36248c4f..a77f9c97ac2 100644 --- a/embedding/tests/mfcembed/Dialogs.cpp +++ b/embedding/tests/mfcembed/Dialogs.cpp @@ -27,235 +27,9 @@ // File overview.... // -// Mainly contains dialog box code to support Alerts, Prompts such as -// Password prompt and username/password prompts +// contains Find dialog box code // -//--------------------------------------------------------------------------// -// 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; -} - //--------------------------------------------------------------------------// // CFindDialog Stuff //--------------------------------------------------------------------------// diff --git a/embedding/tests/mfcembed/Dialogs.h b/embedding/tests/mfcembed/Dialogs.h index 34aaf75cf4a..98b257ea3ee 100644 --- a/embedding/tests/mfcembed/Dialogs.h +++ b/embedding/tests/mfcembed/Dialogs.h @@ -26,103 +26,6 @@ #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() -}; - class CBrowserView; class CFindDialog : public CFindReplaceDialog diff --git a/embedding/tests/mfcembed/IBrowserFrameGlue.h b/embedding/tests/mfcembed/IBrowserFrameGlue.h index ddec6bc355a..c4e5af4685e 100644 --- a/embedding/tests/mfcembed/IBrowserFrameGlue.h +++ b/embedding/tests/mfcembed/IBrowserFrameGlue.h @@ -65,22 +65,7 @@ struct IBrowserFrameGlue { // ContextMenu Related Methods virtual void ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode) = 0; - //Prompt Related Methods - virtual void Alert(const PRUnichar *dialogTitle, const PRUnichar *text) = 0; - virtual void Confirm(const PRUnichar *dialogTitle, const PRUnichar *text, PRBool *_retval) = 0; - virtual void Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, - PRUnichar **promptText, - const PRUnichar *checkboxMsg, PRBool *checkboxState, - PRBool *retval) = 0; - virtual void PromptPassword(const PRUnichar *dialogTitle, const PRUnichar *text, - PRUnichar **password, - const PRUnichar *checkboxMsg, PRBool *checkboxState, - PRBool *retval) = 0; - virtual void PromptUserNamePassword(const PRUnichar *dialogTitle, const PRUnichar *text, - PRUnichar **username, PRUnichar **password, - const PRUnichar *checkboxMsg, PRBool *checkboxState, - PRBool *retval) = 0; - + virtual HWND GetBrowserFrameNativeWnd() = 0; }; #define NS_DECL_BROWSERFRAMEGLUE \ @@ -103,12 +88,8 @@ struct IBrowserFrameGlue { virtual void SetFocus(); \ virtual void FocusAvailable(PRBool *aFocusAvail); \ virtual void GetBrowserFrameVisibility(PRBool *aVisible); \ - virtual void ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode); \ - virtual void Alert(const PRUnichar *dialogTitle, const PRUnichar *text); \ - virtual void Confirm(const PRUnichar *dialogTitle, const PRUnichar *text, PRBool *_retval); \ - virtual void Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, PRUnichar **promptText, const PRUnichar *checkboxMsg, PRBool *checkboxState, PRBool *retval); \ - virtual void PromptPassword(const PRUnichar *dialogTitle, const PRUnichar *text, PRUnichar **password, const PRUnichar *checkboxMsg, PRBool *checkboxState, PRBool *retval); \ - virtual void PromptUserNamePassword(const PRUnichar *dialogTitle, const PRUnichar *text, PRUnichar **username, PRUnichar **password, const PRUnichar *checkboxMsg, PRBool *checkboxState, PRBool *retval); + virtual void ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode); \ + virtual HWND GetBrowserFrameNativeWnd(); typedef IBrowserFrameGlue *PBROWSERFRAMEGLUE; diff --git a/embedding/tests/mfcembed/MfcEmbed.cpp b/embedding/tests/mfcembed/MfcEmbed.cpp index 336066e8331..49c04005e97 100644 --- a/embedding/tests/mfcembed/MfcEmbed.cpp +++ b/embedding/tests/mfcembed/MfcEmbed.cpp @@ -58,6 +58,13 @@ static char THIS_FILE[] = __FILE__; #endif +// this is for overriding the Mozilla default PromptService component +#include "PromptService.h" +#define kComponentsLibname "mfcEmbedComponents.dll" +#define NS_PROMPTSERVICE_CID \ + {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}} +static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID); + BEGIN_MESSAGE_MAP(CMfcEmbedApp, CWinApp) //{{AFX_MSG_MAP(CMfcEmbedApp) ON_COMMAND(ID_NEW_BROWSER, OnNewBrowser) @@ -122,6 +129,49 @@ void CMfcEmbedApp::ParseCmdLine() ShowDebugConsole(); } +/* Some Gecko interfaces are implemented as components, automatically + registered at application initialization. nsIPrompt is an example: + the default implementation uses XUL, not native windows. Embedding + apps can override the default implementation by implementing the + nsIPromptService interface and registering a factory for it with + the same CID and Contract ID as the default's. + + Note that this example implements the service in a separate DLL, + replacing the default if the override DLL is present. This could + also have been done in the same module, without a separate DLL. + See the PowerPlant example for, well, an example. +*/ +nsresult CMfcEmbedApp::OverrideComponents() +{ + nsresult rv = NS_OK; + + // replace Mozilla's default PromptService with our own, if the + // expected override DLL is present + HMODULE overlib = ::LoadLibrary(kComponentsLibname); + if (overlib) { + InitPromptServiceType InitLib; + MakeFactoryType MakeFactory; + InitLib = reinterpret_cast(::GetProcAddress(overlib, kPromptServiceInitFuncName)); + MakeFactory = reinterpret_cast(::GetProcAddress(overlib, kPromptServiceFactoryFuncName)); + + if (InitLib && MakeFactory) { + InitLib(overlib); + + nsCOMPtr promptFactory; + rv = MakeFactory(getter_AddRefs(promptFactory)); + if (NS_SUCCEEDED(rv)) + nsComponentManager::RegisterFactory(kPromptServiceCID, + "Prompt Service", + "@mozilla.org/embedcomp/prompt-service;1", + promptFactory, + PR_TRUE); // replace existing + } else + ::FreeLibrary(overlib); + } + + return rv; +} + void CMfcEmbedApp::ShowDebugConsole() { #ifdef _DEBUG @@ -189,13 +239,21 @@ BOOL CMfcEmbedApp::InitInstance() } nsresult rv; - rv = NS_InitEmbedding(nsnull, provider); + rv = NS_InitEmbedding(nsnull, provider); if(NS_FAILED(rv)) { ASSERT(FALSE); return FALSE; } + rv = OverrideComponents(); + if(NS_FAILED(rv)) + { + ASSERT(FALSE); + return FALSE; + } + + rv = InitializeWindowCreator(); if (NS_FAILED(rv)) { diff --git a/embedding/tests/mfcembed/MfcEmbed.h b/embedding/tests/mfcembed/MfcEmbed.h index 6458d2ea927..1f763ab8413 100644 --- a/embedding/tests/mfcembed/MfcEmbed.h +++ b/embedding/tests/mfcembed/MfcEmbed.h @@ -66,6 +66,7 @@ public: void ShowDebugConsole(); BOOL IsCmdLineSwitch(const char *pSwitch, BOOL bRemove = TRUE); void ParseCmdLine(); + nsresult OverrideComponents(); // Overrides // ClassWizard generated virtual function overrides diff --git a/embedding/tests/mfcembed/MfcEmbed.rc b/embedding/tests/mfcembed/MfcEmbed.rc index 780b7b2a233..6d7b8097aae 100644 --- a/embedding/tests/mfcembed/MfcEmbed.rc +++ b/embedding/tests/mfcembed/MfcEmbed.rc @@ -257,50 +257,6 @@ BEGIN DEFPUSHBUTTON "OK",IDOK,178,7,50,14,WS_GROUP END -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 - IDD_PROFILES DIALOG DISCARDABLE 0, 0, 196, 95 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Manage Profiles" diff --git a/embedding/tests/mfcembed/components/Dialogs.cpp b/embedding/tests/mfcembed/components/Dialogs.cpp new file mode 100644 index 00000000000..b8b37022e35 --- /dev/null +++ b/embedding/tests/mfcembed/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/embedding/tests/mfcembed/components/Dialogs.h b/embedding/tests/mfcembed/components/Dialogs.h new file mode 100644 index 00000000000..f76a05da45a --- /dev/null +++ b/embedding/tests/mfcembed/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/embedding/tests/mfcembed/components/Dialogs.rc b/embedding/tests/mfcembed/components/Dialogs.rc new file mode 100644 index 00000000000..0b030c40838 --- /dev/null +++ b/embedding/tests/mfcembed/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\\mfcembed.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/embedding/tests/mfcembed/components/PromptService.cpp b/embedding/tests/mfcembed/components/PromptService.cpp new file mode 100644 index 00000000000..d91e0ee9f4b --- /dev/null +++ b/embedding/tests/mfcembed/components/PromptService.cpp @@ -0,0 +1,381 @@ +/* -*- 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 button0And1Flags, + 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/embedding/tests/mfcembed/components/PromptService.h b/embedding/tests/mfcembed/components/PromptService.h new file mode 100644 index 00000000000..6edda216fc8 --- /dev/null +++ b/embedding/tests/mfcembed/components/PromptService.h @@ -0,0 +1,40 @@ +/* -*- 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" + +class nsIFactory; + +// factory creator, in hard and soft link formats +extern "C" NS_EXPORT nsresult NS_NewPromptServiceFactory(nsIFactory** aFactory); +typedef nsresult (CALLBACK *MakeFactoryType)(nsIFactory **); +#define kPromptServiceFactoryFuncName "NS_NewPromptServiceFactory" + +// initialization function, in hard and soft link formats +extern "C" NS_EXPORT void InitPromptService(HINSTANCE instance); +typedef nsresult (CALLBACK *InitPromptServiceType)(HINSTANCE instance); +#define kPromptServiceInitFuncName "InitPromptService" + +#endif diff --git a/embedding/tests/mfcembed/components/makefile.win b/embedding/tests/mfcembed/components/makefile.win new file mode 100644 index 00000000000..a5bd91978c4 --- /dev/null +++ b/embedding/tests/mfcembed/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/embedding/tests/mfcembed/components/resource.h b/embedding/tests/mfcembed/components/resource.h new file mode 100644 index 00000000000..d81b9958ac6 --- /dev/null +++ b/embedding/tests/mfcembed/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/embedding/tests/mfcembed/components/stdafx.h b/embedding/tests/mfcembed/components/stdafx.h new file mode 100644 index 00000000000..20678001f74 --- /dev/null +++ b/embedding/tests/mfcembed/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 diff --git a/embedding/tests/mfcembed/makefile.win b/embedding/tests/mfcembed/makefile.win index 859a3e1fe9a..cda9a2053c9 100644 --- a/embedding/tests/mfcembed/makefile.win +++ b/embedding/tests/mfcembed/makefile.win @@ -21,19 +21,24 @@ DEPTH=..\..\.. +DIRS=components \ + $(NULL) + MAKE_OBJ_TYPE = EXE MODULE = mfcembed PROGRAM = .\$(OBJDIR)\$(MODULE).exe RESFILE = $(MODULE).res +LINCS = -Icomponents \ + $(NULL) + OBJS = \ .\$(OBJDIR)\MfcEmbed.obj \ .\$(OBJDIR)\BrowserFrm.obj \ .\$(OBJDIR)\BrowserFrameGlue.obj \ .\$(OBJDIR)\BrowserView.obj \ .\$(OBJDIR)\BrowserImpl.obj \ - .\$(OBJDIR)\BrowserImplPrompt.obj \ .\$(OBJDIR)\BrowserImplWebPrgrsLstnr.obj \ .\$(OBJDIR)\BrowserImplCtxMenuLstnr.obj \ .\$(OBJDIR)\Dialogs.obj \ @@ -42,7 +47,7 @@ OBJS = \ .\$(OBJDIR)\winEmbedFileLocProvider.obj \ .\$(OBJDIR)\MostRecentUrls.obj \ .\$(OBJDIR)\PrintProgressDialog.obj \ - .\$(OBJDIR)\Preferences.obj \ + .\$(OBJDIR)\Preferences.obj \ .\$(OBJDIR)\StdAfx.obj \ $(NULL) @@ -50,6 +55,7 @@ LLIBS= \ $(DIST)\lib\baseembed_s.lib \ $(DIST)\lib\gkgfxwin.lib \ $(DIST)\lib\xpcom.lib \ + $(DIST)\lib\mfcEmbedComponents.lib \ $(LIBNSPR) \ $(NULL)