diff --git a/embedding/tests/mfcembed/components/Dialogs.rc b/embedding/tests/mfcembed/components/Dialogs.rc index 24db6273d206..863f6a5cc67c 100644 --- a/embedding/tests/mfcembed/components/Dialogs.rc +++ b/embedding/tests/mfcembed/components/Dialogs.rc @@ -132,6 +132,45 @@ BEGIN DEFPUSHBUTTON "Btn3",IDC_BTN3,224,89,50,14 END +IDD_PROGRESS_DIALOG DIALOG DISCARDABLE 0, 0, 285, 95 +STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "Saving File" +FONT 8, "MS Sans Serif" +BEGIN + PUSHBUTTON "Cancel",IDCANCEL,115,73,50,14 + LTEXT "Action:",IDC_STATIC,27,23,26,9 + CONTROL "",IDC_ACTION,"Static",SS_LEFTNOWORDWRAP | + WS_GROUP,59,23,211,8 + LTEXT "Saving From:",IDC_STATIC,7,6,42,8 + LTEXT "",IDC_SAVING_FROM,59,6,213,8 + LTEXT "Progress:",IDC_STATIC,19,41,30,8 + CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH | + WS_BORDER,59,41,166,10 + LTEXT "100%",IDC_STATIC,229,42,18,8 +END + +IDD_CHOOSE_ACTION_DIALOG DIALOG DISCARDABLE 0, 0, 285, 114 +STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "Choose An Action" +FONT 8, "MS Sans Serif" +BEGIN + LTEXT "You have chosen to download a file of type: ", + IDC_STATIC,8,9,142,8 + LTEXT "Static",IDC_CONTENT_TYPE,152,10,123,8 + GROUPBOX "What would you like MfcEmbed to do with this file?", + IDC_STATIC,8,24,268,61 + CONTROL "O&pen using",IDC_OPEN_USING,"Button",BS_AUTORADIOBUTTON | + WS_TABSTOP,19,41,60,10 + CONTROL "&Save this file to disk",IDC_SAVE_TO_DISK,"Button", + BS_AUTORADIOBUTTON | WS_TABSTOP,19,69,103,10 + LTEXT "Static",IDC_APP_NAME,31,53,186,9,SS_SUNKEN + PUSHBUTTON "&Choose...",IDC_CHOOSE_APP,222,51,50,12 + PUSHBUTTON "Ok",IDOK,94,94,50,14 + PUSHBUTTON "Cancel",IDCANCEL,150,94,50,14 +END + #endif // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/embedding/tests/mfcembed/components/HelperAppDlg.cpp b/embedding/tests/mfcembed/components/HelperAppDlg.cpp new file mode 100644 index 000000000000..d9ed7e250a09 --- /dev/null +++ b/embedding/tests/mfcembed/components/HelperAppDlg.cpp @@ -0,0 +1,612 @@ +/* -*- 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 "HelperAppService.h" +#include "HelperAppDlg.h" +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsILocalFile.h" +#include "nsIURI.h" +#include "nsIMIMEInfo.h" +#include "nsIDOMWindow.h" +#include "nsIEmbeddingSiteWindow.h" +#include "nsIServiceManager.h" +#include "nsIWebBrowserChrome.h" +#include "nsIInterfaceRequestor.h" + +// This file contains code which overrides the default +// Gecko implementation for helper app dialog handling +// +// General Overview: +// +// We register the factory object for overriding helper app dialogs +// [See OverrideComponents() in mfcembed.cpp] +// +// +// When Gecko encounters content it cannot handle it will: +// 1. Call CHelperAppLauncherDialog::Show() method +// +// 2. If the user chooses SaveToDisk in the dialog presented by +// step 1, then CHelperAppLauncherDialog::PromptForSaveToFile() +// will be called to get the filename to save the content to +// +// If the user chooses OpenUsingAnExternalApp option in the +// dialog box(and subsequnetly specifies the app to use by +// clicking on the "Choose..." button), the specified app +// is run after the content is downloaded +// +// 3. In either case, CHelperAppLauncherDialog::ShowProgressDialog() +// will be called which is used to display a download progress +// dialog box. This dialog box registers itself as a +// WebProgressListener so that it can receive the progress change +// messages, using which it can update the progress bar +// +// 4. The downloads can be cancelled by clicking on the "Cancel" button +// at anytime during the download. + +static HINSTANCE gInstance; + +//***************************************************************************** +// ResourceState +//***************************************************************************** + +class ResourceState { +public: + ResourceState() { + mPreviousInstance = ::AfxGetResourceHandle(); + ::AfxSetResourceHandle(gInstance); + } + ~ResourceState() { + ::AfxSetResourceHandle(mPreviousInstance); + } +private: + HINSTANCE mPreviousInstance; +}; + +//***************************************************************************** +// CHelperAppLauncherDialogFactory Creation and Init Functions +//***************************************************************************** + +void InitHelperAppDlg(HINSTANCE instance) +{ + gInstance = instance; +} + +nsresult NS_NewHelperAppDlgFactory(nsIFactory** aFactory) +{ + NS_ENSURE_ARG_POINTER(aFactory); + *aFactory = nsnull; + + CHelperAppLauncherDialogFactory *result = new CHelperAppLauncherDialogFactory; + if (!result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + *aFactory = result; + + return NS_OK; +} + +//***************************************************************************** +// CHelperAppLauncherDialogFactory +//***************************************************************************** + +NS_IMPL_ISUPPORTS1(CHelperAppLauncherDialogFactory, nsIFactory) + +CHelperAppLauncherDialogFactory::CHelperAppLauncherDialogFactory() +{ + NS_INIT_ISUPPORTS(); +} + +CHelperAppLauncherDialogFactory::~CHelperAppLauncherDialogFactory() { +} + +NS_IMETHODIMP CHelperAppLauncherDialogFactory::CreateInstance(nsISupports *aOuter, const nsIID & aIID, void **aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + *aResult = NULL; + CHelperAppLauncherDialog *inst = new CHelperAppLauncherDialog; + 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 CHelperAppLauncherDialogFactory::LockFactory(PRBool lock) +{ + return NS_OK; +} + +//******************************************************************************* +// CHelperAppLauncherDialog - Implements the nsIHelperAppLauncherDialog interface +//******************************************************************************* + +NS_IMPL_ISUPPORTS1(CHelperAppLauncherDialog, nsIHelperAppLauncherDialog) + +CHelperAppLauncherDialog::CHelperAppLauncherDialog() : + mWWatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")) +{ + NS_INIT_REFCNT(); +} + +CHelperAppLauncherDialog::~CHelperAppLauncherDialog() +{ +} + +// Returns a CWnd given aWindowContext - the returned CWnd is mainly used as +// a parent window for the dialog boxes we display +// +CWnd* CHelperAppLauncherDialog::GetParentFromContext(nsISupports *aWindowContext) +{ + nsCOMPtr domWnd(do_GetInterface(aWindowContext)); + if(!domWnd) + return NULL; + + CWnd *retWnd = NULL; + + nsCOMPtr chrome; + if(mWWatch) + { + nsCOMPtr fosterParent; + if (!domWnd) + { // it will be a dependent window. try to find a foster parent. + mWWatch->GetActiveWindow(getter_AddRefs(fosterParent)); + domWnd = fosterParent; + } + mWWatch->GetChromeForWindow(domWnd, getter_AddRefs(chrome)); + } + + if (chrome) + { + nsCOMPtr site(do_QueryInterface(chrome)); + if (site) + { + HWND w; + site->GetSiteWindow(reinterpret_cast(&w)); + retWnd = CWnd::FromHandle(w); + } + } + + return retWnd; +} + +// Displays the "Save To Disk" or "Open Using..." dialog box +// when Gecko encounters a mime type it cannot handle +// +NS_IMETHODIMP CHelperAppLauncherDialog::Show(nsIHelperAppLauncher *aLauncher, + nsISupports *aContext) +{ + ResourceState setState; + + NS_ENSURE_ARG_POINTER(aLauncher); + + CChooseActionDlg dlg(aLauncher, GetParentFromContext(aContext)); + if(dlg.DoModal() == IDCANCEL) + { + // User chose Cancel - just cancel the download + + aLauncher->Cancel(); + + return NS_OK; + } + + // User did not cancel out of the dialog box i.e. OK was chosen + + if(dlg.m_ActionChosen == CONTENT_SAVE_TO_DISK) + { + m_HandleContentOp = CONTENT_SAVE_TO_DISK; + + return aLauncher->SaveToDisk(nsnull, PR_FALSE); + } + else + { + m_HandleContentOp = CONTENT_LAUNCH_WITH_APP; + + m_FileName = dlg.m_OpenWithAppName; + + nsCOMPtr openWith; + nsresult rv = NS_NewLocalFile(m_FileName, PR_FALSE, getter_AddRefs(openWith)); + if (NS_FAILED(rv)) + return aLauncher->LaunchWithApplication(nsnull, PR_FALSE); + else + return aLauncher->LaunchWithApplication(openWith, PR_FALSE); + } +} + +// User chose the "Save To Disk" option in the dialog before +// We prompt the user for the filename to which the content +// will be saved into +// +NS_IMETHODIMP CHelperAppLauncherDialog::PromptForSaveToFile(nsISupports *aWindowContext, + const PRUnichar *aDefaultFile, + const PRUnichar *aSuggestedFileExtension, + nsILocalFile **_retval) +{ + USES_CONVERSION; + + NS_ENSURE_ARG_POINTER(_retval); + + char *lpszFilter = "All Files (*.*)|*.*||"; + CFileDialog cf(FALSE, W2T(aSuggestedFileExtension), W2T(aDefaultFile), + OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, + lpszFilter, GetParentFromContext(aWindowContext)); + if(cf.DoModal() == IDOK) + { + m_FileName = cf.GetPathName(); // Will be like: c:\tmp\junk.exe + + return NS_NewLocalFile(m_FileName, PR_FALSE, _retval); + } + else + return NS_ERROR_FAILURE; +} + +// Displays a download progress dialog whether the user chose a +// "Save To Disk" or an "Open Using An App" option earlier +// +NS_IMETHODIMP CHelperAppLauncherDialog::ShowProgressDialog(nsIHelperAppLauncher *aLauncher, + nsISupports *aContext) +{ + ResourceState setState; + + NS_ENSURE_ARG_POINTER(aLauncher); + + CProgressDlg *pProgressDlg = new CProgressDlg(aLauncher, m_HandleContentOp, m_FileName); + if(!pProgressDlg) + return NS_ERROR_OUT_OF_MEMORY; + + nsCOMPtr listener = NS_STATIC_CAST(nsIWebProgressListener*, pProgressDlg); + aLauncher->SetWebProgressListener(listener); + + pProgressDlg->Create(IDD_PROGRESS_DIALOG); + + return NS_OK; +} + +//***************************************************************************** +// CChooseActionDlg +//***************************************************************************** + +CChooseActionDlg::CChooseActionDlg(nsIHelperAppLauncher *aLauncher, CWnd* pParent /*=NULL*/) + : CDialog(CChooseActionDlg::IDD, pParent) +{ + m_HelperAppLauncher = aLauncher; +} + +void CChooseActionDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + + DDX_Control(pDX, IDC_CONTENT_TYPE, m_ContentType); +} + +BOOL CChooseActionDlg::OnInitDialog() +{ + CDialog::OnInitDialog(); + + // Get the mimeInfo from nsIHelperAppLauncher + // + nsCOMPtr mimeInfo; + if(m_HelperAppLauncher) + m_HelperAppLauncher->GetMIMEInfo(getter_AddRefs(mimeInfo)); + + if(mimeInfo) + { + // Retrieve and set the Mime type of the content we're downloading + // in the content type field of the dialog box + // + nsXPIDLCString mimeType; + nsresult rv = mimeInfo->GetMIMEType(getter_Copies(mimeType)); + if(NS_SUCCEEDED(rv)) + { + CStatic *pMimeType = (CStatic *)GetDlgItem(IDC_CONTENT_TYPE); + if(pMimeType) + pMimeType->SetWindowText(mimeType.get()); + } + + // See if we can get the preferred action from the mime info + // and init the controls accordingly + // + InitWithPreferredAction(mimeInfo); + } + else + SelectSaveToDiskOption(); + + return FALSE; // return TRUE unless you set the focus to a control +} + +// See if we can determine the default handling action, if any, +// from aMimeInfo +// If not, simply select SaveToDisk as the default +// +void CChooseActionDlg::InitWithPreferredAction(nsIMIMEInfo* aMimeInfo) +{ + // Retrieve and set the specified default action + // + nsMIMEInfoHandleAction prefAction = nsIMIMEInfo::saveToDisk; + aMimeInfo->GetPreferredAction(&prefAction); + if(prefAction == nsIMIMEInfo::saveToDisk) + { + SelectSaveToDiskOption(); + return; + } + + // OpenWithApp is the preferred action - select it + // + SelectOpenUsingAppOption(); + + // See if we can get the appname + // + nsXPIDLString appDesc; + nsresult rv = aMimeInfo->GetApplicationDescription(getter_Copies(appDesc)); + if(NS_SUCCEEDED(rv)) + { + USES_CONVERSION; + m_OpenWithAppName = W2T(appDesc.get()); + + // Update with the app name + // + UpdateAppNameField(m_OpenWithAppName); + } +} + +void CChooseActionDlg::UpdateAppNameField(CString& appName) +{ + CStatic *pAppName = (CStatic *)GetDlgItem(IDC_APP_NAME); + if(pAppName) + pAppName->SetWindowText(appName); +} + +void CChooseActionDlg::SelectSaveToDiskOption() +{ + CButton *pRadioSaveToDisk = (CButton *)GetDlgItem(IDC_SAVE_TO_DISK); + if(pRadioSaveToDisk) + { + pRadioSaveToDisk->SetCheck(1); + + pRadioSaveToDisk->SetFocus(); + + OnSaveToDiskRadioBtnClicked(); + } +} + +void CChooseActionDlg::SelectOpenUsingAppOption() +{ + CButton *pRadioOpenUsing = (CButton *)GetDlgItem(IDC_OPEN_USING); + if(pRadioOpenUsing) + { + pRadioOpenUsing->SetCheck(1); + + pRadioOpenUsing->SetFocus(); + + OnOpenUsingRadioBtnClicked(); + } +} + +void CChooseActionDlg::EnableChooseBtn(BOOL bEnable) +{ + CButton *pChooseBtn = (CButton *)GetDlgItem(IDC_CHOOSE_APP); + if(pChooseBtn) + { + pChooseBtn->EnableWindow(bEnable); + } +} + +void CChooseActionDlg::EnableAppName(BOOL bEnable) +{ + CStatic *pAppName = (CStatic *)GetDlgItem(IDC_APP_NAME); + if(pAppName) + { + pAppName->EnableWindow(bEnable); + } +} + +void CChooseActionDlg::OnOpenUsingRadioBtnClicked() +{ + EnableChooseBtn(TRUE); + EnableAppName(TRUE); +} + +void CChooseActionDlg::OnSaveToDiskRadioBtnClicked() +{ + EnableChooseBtn(FALSE); + EnableAppName(FALSE); +} + +void CChooseActionDlg::OnChooseAppClicked() +{ + char *lpszFilter = + "EXE Files Only (*.exe)|*.exe|" + "All Files (*.*)|*.*||"; + + CFileDialog cf(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, + lpszFilter, this); + if(cf.DoModal() == IDOK) + { + m_OpenWithAppName = cf.GetPathName(); // Will be like: c:\tmp\junk.exe + + UpdateAppNameField(m_OpenWithAppName); + } +} + +void CChooseActionDlg::OnOK() +{ + CButton *pRadioOpenWithApp = (CButton *)GetDlgItem(IDC_OPEN_USING); + + if(pRadioOpenWithApp->GetCheck()) + { + // Do not allow to leave the dialog if the OpenWithAnApp option + // is selected and the the name of the app is unknown/empty + // + if(m_OpenWithAppName.IsEmpty()) + { + ::MessageBox(this->m_hWnd, "You have chosen to open the content with an external application, but,\nno application has been specified.\n\nPlease click the Choose... button to select an application", + "MfcEmbed", MB_OK); + return; + } + else + m_ActionChosen = CONTENT_LAUNCH_WITH_APP; + } + else + m_ActionChosen = CONTENT_SAVE_TO_DISK; + + CDialog::OnOK(); +} + +void CChooseActionDlg::OnCancel() +{ + CDialog::OnCancel(); +} + +BEGIN_MESSAGE_MAP(CChooseActionDlg, CDialog) + ON_BN_CLICKED(IDC_CHOOSE_APP, OnChooseAppClicked) + ON_BN_CLICKED(IDC_SAVE_TO_DISK, OnSaveToDiskRadioBtnClicked) + ON_BN_CLICKED(IDC_OPEN_USING, OnOpenUsingRadioBtnClicked) +END_MESSAGE_MAP() + +//***************************************************************************** +// CProgressDlg +//***************************************************************************** + +NS_IMPL_ISUPPORTS2(CProgressDlg, nsIWebProgressListener, nsISupportsWeakReference) + +CProgressDlg::CProgressDlg(nsIHelperAppLauncher *aLauncher, int aHandleContentOp, + CString& aFileName, CWnd* pParent /*=NULL*/) + : CDialog(CProgressDlg::IDD, pParent) +{ + NS_INIT_REFCNT(); + + m_HelperAppLauncher = aLauncher; + m_HandleContentOp = aHandleContentOp; + m_FileName = aFileName; +} + +CProgressDlg::~CProgressDlg() +{ +} + +NS_IMETHODIMP CProgressDlg::OnStateChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, PRInt32 aStateFlags, + PRUint32 aStatus) +{ + if((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_DOCUMENT)) + { + // We've completed the download - close the progress window + + if(m_HelperAppLauncher) + m_HelperAppLauncher->CloseProgressWindow(); + + DestroyWindow(); + } + + return NS_OK; +} + +NS_IMETHODIMP CProgressDlg::OnProgressChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, + PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) +{ + // Update the progress control + + if(::IsWindow(m_ProgressCtrl.m_hWnd)) + { + m_ProgressCtrl.SetRange32(0, aMaxTotalProgress); + m_ProgressCtrl.SetPos(aCurTotalProgress); + } + + return NS_OK; +} + +NS_IMETHODIMP CProgressDlg::OnLocationChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, nsIURI *location) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP CProgressDlg::OnStatusChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, nsresult aStatus, + const PRUnichar *aMessage) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP CProgressDlg::OnSecurityChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, PRInt32 state) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +BOOL CProgressDlg::OnInitDialog() +{ + CDialog::OnInitDialog(); + + // Set the "SavingFrom" field + if(m_HelperAppLauncher) + { + nsCOMPtr srcUri; + nsresult rv = m_HelperAppLauncher->GetSource(getter_AddRefs(srcUri)); + if(NS_SUCCEEDED(rv)) + { + nsXPIDLCString uriString; + srcUri->GetSpec(getter_Copies(uriString)); + + m_SavingFrom.SetWindowText(uriString.get()); + } + } + + // Set the "Action" field + if(m_HandleContentOp == CONTENT_SAVE_TO_DISK) + m_Action.SetWindowText("[Saving file to:] " + m_FileName); + else if(m_HandleContentOp == CONTENT_LAUNCH_WITH_APP) + m_Action.SetWindowText("[Opening file with:] " + m_FileName); + + return TRUE; +} + +void CProgressDlg::OnCancel() +{ + if(m_HelperAppLauncher) + m_HelperAppLauncher->Cancel(); + + DestroyWindow(); +} + +void CProgressDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + + DDX_Control(pDX, IDC_PROGRESS, m_ProgressCtrl); + DDX_Control(pDX, IDC_SAVING_FROM, m_SavingFrom); + DDX_Control(pDX, IDC_ACTION, m_Action); +} + +BEGIN_MESSAGE_MAP(CProgressDlg, CDialog) +END_MESSAGE_MAP() diff --git a/embedding/tests/mfcembed/components/HelperAppDlg.h b/embedding/tests/mfcembed/components/HelperAppDlg.h new file mode 100644 index 000000000000..e96c0225c3bf --- /dev/null +++ b/embedding/tests/mfcembed/components/HelperAppDlg.h @@ -0,0 +1,143 @@ +/* -*- 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 + */ + +#ifndef __HelperAppDlg_h +#define __HelperAppDlg_h + +#include "nsError.h" +#include "resource.h" +#include "nsIFactory.h" +#include "nsIExternalHelperAppService.h" +#include "nsIHelperAppLauncherDialog.h" +#include "nsIWebProgressListener.h" +#include "nsWeakReference.h" +#include "nsIWindowWatcher.h" + +// this component is for an MFC app; it's Windows. make sure this is defined. +#ifndef XP_WIN +#define XP_WIN +#endif + +class CHelperAppLauncherDialogFactory : public nsIFactory { +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIFACTORY + + CHelperAppLauncherDialogFactory(); + virtual ~CHelperAppLauncherDialogFactory(); +}; + +enum { + CONTENT_SAVE_TO_DISK, + CONTENT_LAUNCH_WITH_APP +}; + +// This class implements the nsIHelperAppLauncherDialog interface +// +class CHelperAppLauncherDialog : public nsIHelperAppLauncherDialog { +public: + CHelperAppLauncherDialog(); + virtual ~CHelperAppLauncherDialog(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIHELPERAPPLAUNCHERDIALOG + + int m_HandleContentOp; + CString m_FileName; + +private: + nsCOMPtr mWWatch; + CWnd* GetParentFromContext(nsISupports *aWindowContext); +}; + +// This class implements a download progress dialog +// which displays the progress of a file download +// +class CProgressDlg : public CDialog, + public nsIWebProgressListener, + public nsSupportsWeakReference +{ +public: + enum { IDD = IDD_PROGRESS_DIALOG }; + + CProgressDlg(nsIHelperAppLauncher *aLauncher, int aHandleContentOp, + CString& aFileName, CWnd* pParent = NULL); + virtual ~CProgressDlg(); + + int m_HandleContentOp; + CString m_FileName; + CStatic m_SavingFrom; + CStatic m_Action; + CProgressCtrl m_ProgressCtrl; + + nsCOMPtr m_HelperAppLauncher; + + NS_DECL_ISUPPORTS + NS_DECL_NSIWEBPROGRESSLISTENER + +protected: + virtual void DoDataExchange(CDataExchange* pDX); + virtual BOOL OnInitDialog(); + virtual void OnCancel(); + + DECLARE_MESSAGE_MAP() +}; + +// This class implements a dialog box which gives the user +// a choice of saving the content being downloaded to disk +// or to open with an external application +// +class CChooseActionDlg : public CDialog +{ +public: + CChooseActionDlg(nsIHelperAppLauncher* aLauncher, CWnd* pParent = NULL); + + enum { IDD = IDD_CHOOSE_ACTION_DIALOG }; + CStatic m_ContentType; + + int m_ActionChosen; + CString m_OpenWithAppName; + nsCOMPtr m_HelperAppLauncher; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); + +protected: + virtual BOOL OnInitDialog(); + afx_msg void OnChooseAppClicked(); + virtual void OnOK(); + virtual void OnCancel(); + afx_msg void OnOpenUsingRadioBtnClicked(); + afx_msg void OnSaveToDiskRadioBtnClicked(); + + void EnableAppName(BOOL bEnable); + void EnableChooseBtn(BOOL bEnable); + void InitWithPreferredAction(nsIMIMEInfo* aMimeInfo); + void SelectSaveToDiskOption(); + void SelectOpenUsingAppOption(); + void UpdateAppNameField(CString& appName); + + DECLARE_MESSAGE_MAP() +}; + +#endif diff --git a/embedding/tests/mfcembed/components/HelperAppService.h b/embedding/tests/mfcembed/components/HelperAppService.h new file mode 100644 index 000000000000..3c6a40308edc --- /dev/null +++ b/embedding/tests/mfcembed/components/HelperAppService.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): + * Chak Nanga + */ +#ifndef __HelperAppService_h +#define __HelperAppService_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_NewHelperAppDlgFactory(nsIFactory** aFactory); +typedef nsresult (__cdecl *MakeFactoryType)(nsIFactory **); +#define kHelperAppDlgFactoryFuncName "NS_NewHelperAppDlgFactory" + +// initialization function, in hard and soft link formats +extern "C" NS_EXPORT void InitHelperAppDlg(HINSTANCE instance); +typedef nsresult (__cdecl *InitHelperAppDlgType)(HINSTANCE instance); +#define kHelperAppDlgInitFuncName "InitHelperAppDlg" + +#endif diff --git a/embedding/tests/mfcembed/components/makefile.win b/embedding/tests/mfcembed/components/makefile.win index 13a80334d210..a20d49a60b94 100644 --- a/embedding/tests/mfcembed/components/makefile.win +++ b/embedding/tests/mfcembed/components/makefile.win @@ -33,6 +33,7 @@ LLFLAGS=-SUBSYSTEM:windows CPP_OBJS= \ .\$(OBJDIR)\Dialogs.obj \ .\$(OBJDIR)\PromptService.obj \ + .\$(OBJDIR)\HelperAppDlg.obj \ $(NULL) LLIBS= \ diff --git a/embedding/tests/mfcembed/components/resource.h b/embedding/tests/mfcembed/components/resource.h index 75602cb52b35..df2de370eb32 100644 --- a/embedding/tests/mfcembed/components/resource.h +++ b/embedding/tests/mfcembed/components/resource.h @@ -7,6 +7,8 @@ #define IDD_PROMPT_USERPASS_DIALOG 130 #define IDD_ALERT_CHECK_DIALOG 131 #define IDD_CONFIRM_CHECK_DIALOG 132 +#define IDD_PROGRESS_DIALOG 133 +#define IDD_CHOOSE_ACTION_DIALOG 134 #define IDC_PROMPT_ANSWER 1001 #define IDC_PROMPT_TEXT 1002 #define IDC_USERNAME 1003 @@ -19,6 +21,14 @@ #define IDC_BTN1 1010 #define IDC_BTN2 1011 #define IDC_BTN3 1012 +#define IDC_ACTION 1013 +#define IDC_SAVING_FROM 1014 +#define IDC_PROGRESS 1015 +#define IDC_CONTENT_TYPE 1016 +#define IDC_SAVE_TO_DISK 1017 +#define IDC_OPEN_USING 1018 +#define IDC_CHOOSE_APP 1019 +#define IDC_APP_NAME 1020 // Next default values for new objects //