From 6c87171d9e261c9b946b54ab9c7e5ecfc0b10954 Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Mon, 1 Jul 2002 20:30:18 +0000 Subject: [PATCH] Implement nsPrintingPromptService for MfcEmbed Bug 154244 r=chak sr=rpotts git-svn-id: svn://10.0.0.236/trunk@124418 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/embedding/tests/mfcembed/MfcEmbed.cpp | 29 + .../tests/mfcembed/components/Dialogs.rc | 15 + .../tests/mfcembed/components/Makefile.in | 11 + .../components/PrintProgressDialog.cpp | 274 ++++ .../mfcembed/components/PrintProgressDialog.h | 73 + .../components/PrintingPromptService.cpp | 438 +++++ .../components/PrintingPromptService.h | 61 + .../tests/mfcembed/components/makefile.win | 12 +- .../mfcembed/components/nsPrintDialogUtil.cpp | 1427 +++++++++++++++++ .../mfcembed/components/nsPrintDialogUtil.h | 45 + .../components/nsPrintProgressParams.cpp | 83 + .../components/nsPrintProgressParams.h | 59 + .../tests/mfcembed/components/resource.h | 12 +- 13 files changed, 2536 insertions(+), 3 deletions(-) create mode 100644 mozilla/embedding/tests/mfcembed/components/PrintProgressDialog.cpp create mode 100644 mozilla/embedding/tests/mfcembed/components/PrintProgressDialog.h create mode 100644 mozilla/embedding/tests/mfcembed/components/PrintingPromptService.cpp create mode 100644 mozilla/embedding/tests/mfcembed/components/PrintingPromptService.h create mode 100644 mozilla/embedding/tests/mfcembed/components/nsPrintDialogUtil.cpp create mode 100644 mozilla/embedding/tests/mfcembed/components/nsPrintDialogUtil.h create mode 100644 mozilla/embedding/tests/mfcembed/components/nsPrintProgressParams.cpp create mode 100644 mozilla/embedding/tests/mfcembed/components/nsPrintProgressParams.h diff --git a/mozilla/embedding/tests/mfcembed/MfcEmbed.cpp b/mozilla/embedding/tests/mfcembed/MfcEmbed.cpp index 8ee294a8211..fa8165b0127 100644 --- a/mozilla/embedding/tests/mfcembed/MfcEmbed.cpp +++ b/mozilla/embedding/tests/mfcembed/MfcEmbed.cpp @@ -72,6 +72,12 @@ static char THIS_FILE[] = __FILE__; {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}} static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID); +// this is for overriding the Mozilla default PrintingPromptService component +#include "PrintingPromptService.h" +#define NS_PRINTINGPROMPTSERVICE_CID \ + {0xe042570c, 0x62de, 0x4bb6, { 0xa6, 0xe0, 0x79, 0x8e, 0x3c, 0x7, 0xb4, 0xdf}} +static NS_DEFINE_CID(kPrintingPromptServiceCID, NS_PRINTINGPROMPTSERVICE_CID); + // this is for overriding the Mozilla default HelperAppLauncherDialog #include "HelperAppService.h" #define NS_HELPERAPPLAUNCHERDIALOG_CID \ @@ -209,6 +215,29 @@ nsresult CMfcEmbedApp::OverrideComponents() ::FreeLibrary(overlib); } + // replace Mozilla's default PrintingPromptService with our own, if the + // expected override DLL is present + overlib = ::LoadLibrary(kComponentsLibname); + if (overlib) { + InitPrintingPromptServiceType InitLib; + MakeFactoryType MakeFactory; + InitLib = reinterpret_cast(::GetProcAddress(overlib, kPrintingPromptServiceInitFuncName)); + MakeFactory = reinterpret_cast(::GetProcAddress(overlib, kPrintingPromptServiceFactoryFuncName)); + + if (InitLib && MakeFactory) { + InitLib(overlib); + + nsCOMPtr printingPromptFactory; + rv = MakeFactory(getter_AddRefs(printingPromptFactory)); + if (NS_SUCCEEDED(rv)) + nsComponentManager::RegisterFactory(kPrintingPromptServiceCID, + "Printing Prompt Service", + "@mozilla.org/embedcomp/printingprompt-service;1", + printingPromptFactory, + PR_TRUE); // replace existing + } else + ::FreeLibrary(overlib); + } return rv; } diff --git a/mozilla/embedding/tests/mfcembed/components/Dialogs.rc b/mozilla/embedding/tests/mfcembed/components/Dialogs.rc index 863f6a5cc67..20972ea8e4e 100644 --- a/mozilla/embedding/tests/mfcembed/components/Dialogs.rc +++ b/mozilla/embedding/tests/mfcembed/components/Dialogs.rc @@ -171,6 +171,21 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,150,94,50,14 END +IDD_PRINT_PROGRESS_DIALOG DIALOG DISCARDABLE 0, 0, 294, 53 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Print Progress" +FONT 8, "MS Sans Serif" +BEGIN + PUSHBUTTON "Cancel",IDCANCEL,237,36,50,14 + RTEXT "URL:",IDC_PRINT_PROGRESS_URL_LABEL_TXT,7,7,30,8 + LTEXT "...",IDC_PRINT_PROGRESS_URL_TXT,41,7,231,8 + RTEXT "Progress:",IDC_STATIC,7,18,30,8 + CONTROL "Progress1",IDC_PRINT_PROGRESS_PRG,"msctls_progress32", + WS_BORDER,41,18,217,8 + LTEXT "Preparing...",IDC_PRINT_PROGRESS_TXT,41,18,217,8 + LTEXT "",IDC_PRINT_PROGRESS_PERCENT_TXT,264,18,19,8 +END + #endif // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/embedding/tests/mfcembed/components/Makefile.in b/mozilla/embedding/tests/mfcembed/components/Makefile.in index f596805bd17..4be056ef4bc 100644 --- a/mozilla/embedding/tests/mfcembed/components/Makefile.in +++ b/mozilla/embedding/tests/mfcembed/components/Makefile.in @@ -41,6 +41,11 @@ REQUIRES = \ xpcom \ string \ dom \ + content \ + gfx \ + widget \ + pref \ + intl \ webbrwsr \ windowwatcher \ exthandler \ @@ -51,11 +56,17 @@ REQUIRES = \ $(NULL) CPPSRCS = \ + nsPrintDialogUtil.cpp \ + nsPrintProgressParams.cpp \ + PrintingPromptService.cpp \ + PrintProgressDialog.cpp \ Dialogs.cpp \ PromptService.cpp \ HelperAppDlg.cpp \ $(NULL) +EXTRA_DSO_LIBS = gkgfx + EXTRA_DSO_LDOPTS += \ $(EXTRA_DSO_LIBS) \ $(XPCOM_LIBS) \ diff --git a/mozilla/embedding/tests/mfcembed/components/PrintProgressDialog.cpp b/mozilla/embedding/tests/mfcembed/components/PrintProgressDialog.cpp new file mode 100644 index 00000000000..41ecb13090e --- /dev/null +++ b/mozilla/embedding/tests/mfcembed/components/PrintProgressDialog.cpp @@ -0,0 +1,274 @@ +// PrintProgressDialog.cpp : implementation file +// + +#include "stdafx.h" +//#include "mfcembed.h" +#include "PrintProgressDialog.h" +//#include "BrowserView.h" +#include "nsIWebBrowser.h" +#include "nsIWebBrowserPrint.h" +#include "nsIInterfaceRequestorUtils.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CPrintProgressDialog dialog + +class CDlgPrintListener : public nsIWebProgressListener +{ +// Construction +public: + CDlgPrintListener(CPrintProgressDialog* aDlg); + + NS_DECL_ISUPPORTS + NS_DECL_NSIWEBPROGRESSLISTENER + + void ClearDlg() { m_PrintDlg = NULL; } // weak reference + +// Implementation +protected: + CPrintProgressDialog* m_PrintDlg; +}; + +NS_IMPL_ADDREF(CDlgPrintListener) +NS_IMPL_RELEASE(CDlgPrintListener) + +NS_INTERFACE_MAP_BEGIN(CDlgPrintListener) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebProgressListener) + NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) +NS_INTERFACE_MAP_END + + +CDlgPrintListener::CDlgPrintListener(CPrintProgressDialog* aDlg) : + m_PrintDlg(aDlg) +{ + NS_INIT_ISUPPORTS(); +} + +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */ +NS_IMETHODIMP +CDlgPrintListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus) +{ + if (m_PrintDlg) { + if (aStateFlags == (nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT)) { + return m_PrintDlg->OnStartPrinting(); + + } else if (aStateFlags == (nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT)) { + return m_PrintDlg->OnEndPrinting(aStatus); + } + } + return NS_OK; +} + +/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ +NS_IMETHODIMP +CDlgPrintListener::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) +{ + if (m_PrintDlg) { + return m_PrintDlg->OnProgressPrinting(aCurSelfProgress, aMaxSelfProgress); + } + return NS_OK; +} + +/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ +NS_IMETHODIMP +CDlgPrintListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) +{ + return NS_OK; +} + +/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ +NS_IMETHODIMP +CDlgPrintListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) +{ + return NS_OK; +} + +/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ +NS_IMETHODIMP +CDlgPrintListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) +{ + return NS_OK; +} + + +///////////////////////////////////////////////////////////////////////////// +// CPrintProgressDialog dialog + + +CPrintProgressDialog::CPrintProgressDialog(CWnd* pParent, + BOOL aIsForPrinting, + nsIPrintProgressParams* aPPParams, + nsIWebBrowserPrint* aWebBrowserPrint, + nsIPrintSettings* aPrintSettings) + : CDialog(CPrintProgressDialog::IDD, pParent), + m_WebBrowserPrint(aWebBrowserPrint), + m_PPParams(aPPParams), + m_PrintListener(nsnull), + m_PrintSettings(aPrintSettings), + m_HasStarted(FALSE), + m_IsForPrinting(aIsForPrinting) +{ + //{{AFX_DATA_INIT(CPrintProgressDialog) + // NOTE: the ClassWizard will add member initialization here + //}}AFX_DATA_INIT +} + +CPrintProgressDialog::~CPrintProgressDialog() +{ + CDlgPrintListener * pl = (CDlgPrintListener*)m_PrintListener.get(); + if (pl) { + pl->ClearDlg(); + } +} + + +void CPrintProgressDialog::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CPrintProgressDialog) + // NOTE: the ClassWizard will add DDX and DDV calls here + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CPrintProgressDialog, CDialog) + //{{AFX_MSG_MAP(CPrintProgressDialog) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CPrintProgressDialog message handlers + +BOOL CPrintProgressDialog::OnInitDialog() +{ + CDialog::OnInitDialog(); + + CWnd* cancelBtn = (CWnd*)GetDlgItem(IDCANCEL); + if (cancelBtn) + { + if (m_IsForPrinting) + { + cancelBtn->EnableWindow(FALSE); + } else { + cancelBtn->ShowWindow(SW_HIDE); + SetWindowText("Print Preview"); + } + } + + SetDocAndURL(); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + + +/* void OnStartPrinting (); */ +NS_IMETHODIMP +CPrintProgressDialog::OnStartPrinting() +{ + CProgressCtrl* progressCtrl = (CProgressCtrl *)GetDlgItem(IDC_PRINT_PROGRESS_PRG); + CWnd* progressText = (CWnd*)GetDlgItem(IDC_PRINT_PROGRESS_TXT); + if (!progressCtrl || !progressText) return NS_OK; + + m_HasStarted = TRUE; + progressCtrl->ShowWindow(SW_HIDE); + + SetDocAndURL(); + + return NS_OK; +} + +/* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */ +NS_IMETHODIMP +CPrintProgressDialog::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax) +{ + CProgressCtrl* progressCtrl = (CProgressCtrl *)GetDlgItem(IDC_PRINT_PROGRESS_PRG); + CWnd* progressText = (CWnd*)GetDlgItem(IDC_PRINT_PROGRESS_TXT); + if (!progressCtrl || !progressText) return NS_OK; + + if (m_HasStarted && aProgress != 100) + { + progressText->ShowWindow(SW_HIDE); + progressCtrl->ShowWindow(SW_SHOW); + progressCtrl->SetRange(0, aProgressMax); + m_HasStarted = FALSE; + progressText->UpdateWindow(); + } + + SetDocAndURL(); + + // Initialize the progress meter we we get the "zero" progress + // which also tells us the max progress + if (aProgress == 0) { + progressCtrl->SetRange(0, aProgressMax); + progressCtrl->SetPos(0); + + } + CWnd* cancelBtn = (CWnd*)GetDlgItem(IDCANCEL); + if (cancelBtn && m_IsForPrinting) + { + cancelBtn->EnableWindow(TRUE); + } + progressCtrl->SetPos(aProgress); + RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); + + return NS_OK; +} + +/* void OnEndPrinting (in PRUint32 aStatus); */ +NS_IMETHODIMP +CPrintProgressDialog::OnEndPrinting(PRUint32 aStatus) +{ + return NS_OK; +} + +void CPrintProgressDialog::OnCancel() +{ + if (m_WebBrowserPrint) { + m_WebBrowserPrint->Cancel(); + } + + CDialog::OnCancel(); +} + +void CPrintProgressDialog::SetDocAndURL() +{ + USES_CONVERSION; + + if (m_PPParams) + { + PRUnichar* docTitle = nsnull; + PRUnichar* urlStr = nsnull; + m_PPParams->GetDocTitle(&docTitle); + m_PPParams->GetDocURL(&urlStr); + + if (docTitle) + { + if (*docTitle && W2T(docTitle)) + { + SetWindowText(W2T(docTitle)); + } + nsMemory::Free(docTitle); + } + + if (urlStr) + { + if (*urlStr && W2T(urlStr)) + { + CWnd *pWnd = GetDlgItem(IDC_PRINT_PROGRESS_URL_TXT); + if (pWnd) + { + pWnd->SetWindowText(W2T(urlStr)); + } + } + nsMemory::Free(urlStr); + } + } + Invalidate(); + UpdateWindow(); +} diff --git a/mozilla/embedding/tests/mfcembed/components/PrintProgressDialog.h b/mozilla/embedding/tests/mfcembed/components/PrintProgressDialog.h new file mode 100644 index 00000000000..a65a7d8a896 --- /dev/null +++ b/mozilla/embedding/tests/mfcembed/components/PrintProgressDialog.h @@ -0,0 +1,73 @@ +#if !defined(AFX_PRINTPROGRESSDIALOG_H__1E3AA1B5_B8BB_4B25_86A5_A90E663D137F__INCLUDED_) +#define AFX_PRINTPROGRESSDIALOG_H__1E3AA1B5_B8BB_4B25_86A5_A90E663D137F__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 +// PrintProgressDialog.h : header file +// + +#include "resource.h" +#include "nsIWebProgressListener.h" +#include "nsIWebBrowserPrint.h" +#include "nsIPrintSettings.h" +#include "nsIPrintProgressParams.h" + +///////////////////////////////////////////////////////////////////////////// +// CPrintProgressDialog dialog + +class CPrintProgressDialog : public CDialog +{ +// Construction +public: + CPrintProgressDialog(CWnd* pParent, + BOOL aIsForPrinting, + nsIPrintProgressParams* aPPParams, + nsIWebBrowserPrint* aWebBrowserPrint, + nsIPrintSettings* aPrintSettings); + virtual ~CPrintProgressDialog(); + + // Helper + void SetDocAndURL(); + + NS_IMETHOD OnStartPrinting(void); + NS_IMETHOD OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax); + NS_IMETHOD OnEndPrinting(PRUint32 aStatus); + +// Dialog Data + //{{AFX_DATA(CPrintProgressDialog) + enum { IDD = IDD_PRINT_PROGRESS_DIALOG }; + // NOTE: the ClassWizard will add data members here + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CPrintProgressDialog) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + CProgressCtrl m_wndProgress; + CString m_URL; + nsCOMPtr m_WebBrowserPrint; + nsCOMPtr m_PPParams; + nsCOMPtr m_PrintListener; + nsCOMPtr m_PrintSettings; + BOOL m_HasStarted; + BOOL m_IsForPrinting; + + // Generated message map functions + //{{AFX_MSG(CPrintProgressDialog) + virtual BOOL OnInitDialog(); + virtual void OnCancel(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_PRINTPROGRESSDIALOG_H__1E3AA1B5_B8BB_4B25_86A5_A90E663D137F__INCLUDED_) diff --git a/mozilla/embedding/tests/mfcembed/components/PrintingPromptService.cpp b/mozilla/embedding/tests/mfcembed/components/PrintingPromptService.cpp new file mode 100644 index 00000000000..49e6b2092af --- /dev/null +++ b/mozilla/embedding/tests/mfcembed/components/PrintingPromptService.cpp @@ -0,0 +1,438 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 2001 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/* PrintingPromptService is intended to override the default Mozilla PrintingPromptService, + 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 "PrintingPromptService.h" +#include "nsCOMPtr.h" +#include "nsMemory.h" +#include "nsString.h" +#include "nsReadableUtils.h" +#include "nsIDOMWindow.h" +#include "nsIEmbeddingSiteWindow.h" +#include "nsIFactory.h" +#include "nsIPrintingPromptService.h" +#include "nsIServiceManager.h" +#include "nsIWebBrowserChrome.h" +#include "nsIWindowWatcher.h" +#include "nsIWebProgressListener.h" +#include "nsPrintProgressParams.h" +#include "nsPrintDialogUtil.h" +#include "PrintProgressDialog.h" + +// For PLEvent +#include "nsIEventQueueService.h" +#include "plevent.h" + +static HINSTANCE gInstance; + +//***************************************************************************** +// ResourceState +//***************************************************************************** + +class ResourceState { +public: + ResourceState() { + mPreviousInstance = ::AfxGetResourceHandle(); + ::AfxSetResourceHandle(gInstance); + } + ~ResourceState() { + ::AfxSetResourceHandle(mPreviousInstance); + } +private: + HINSTANCE mPreviousInstance; +}; + + +//***************************************************************************** +// CPrintingPromptService +//***************************************************************************** + +class CPrintingPromptService: public nsIPrintingPromptService, + public nsIWebProgressListener { +public: + CPrintingPromptService(); + virtual ~CPrintingPromptService(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIPRINTINGPROMPTSERVICE + NS_DECL_NSIWEBPROGRESSLISTENER + + void NotifyObserver(); + +private: + PRBool FirePauseEvent(); + CWnd *CWndForDOMWindow(nsIDOMWindow *aWindow); + + nsCOMPtr mWWatch; + nsCOMPtr mWebProgressListener; + nsCOMPtr mObserver; + CPrintProgressDialog* m_PPDlg; +}; + +// Define PL Callback Functions +static void PR_CALLBACK HandlePLEvent(PLEvent* aEvent); +static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent); + + +//***************************************************************************** + +NS_IMPL_ISUPPORTS2(CPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener) + +CPrintingPromptService::CPrintingPromptService() : + mWWatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")), + m_PPDlg(NULL) +{ + NS_INIT_REFCNT(); +} + +CPrintingPromptService::~CPrintingPromptService() { +} + +CWnd * +CPrintingPromptService::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; +} + +/////////////////////////////////////////////////////////////////////////////// +// nsIPrintingPrompt + +//----------------------------------------------------------- +NS_IMETHODIMP +CPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings) +{ + //NS_ENSURE_ARG(parent); + + CWnd* wnd = CWndForDOMWindow(parent); + + NS_ASSERTION(wnd && wnd->m_hWnd, "Couldn't get native window for PRint Dialog!"); + if (wnd && wnd->m_hWnd) { + return NativeShowPrintDialog(wnd->m_hWnd, webBrowserPrint, printSettings); + } else { + return NS_ERROR_FAILURE; + } +} + + +//----------------------------------------------------------- +PRBool +CPrintingPromptService::FirePauseEvent() +{ + static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); + + nsCOMPtr event_service = do_GetService(kEventQueueServiceCID); + + if (!event_service) + { + NS_WARNING("Failed to get event queue service"); + return PR_FALSE; + } + + nsCOMPtr event_queue; + + event_service->GetThreadEventQueue(NS_CURRENT_THREAD, + getter_AddRefs(event_queue)); + + if (!event_queue) + { + NS_WARNING("Failed to get event queue from service"); + return PR_FALSE; + } + + PLEvent *event = new PLEvent; + + if (!event) + { + NS_WARNING("Out of memory?"); + return PR_FALSE; + } + + PL_InitEvent(event, this, (PLHandleEventProc)::HandlePLEvent, (PLDestroyEventProc)::DestroyPLEvent); + + // The event owns the content pointer now. + NS_ADDREF_THIS(); + + event_queue->PostEvent(event); + return PR_TRUE; +} + +/* void showProgress (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings, in nsIObserver openDialogObserver, in boolean isForPrinting, out nsIWebProgressListener webProgressListener, out nsIPrintProgressParams printProgressParams, out boolean notifyOnOpen); */ +NS_IMETHODIMP +CPrintingPromptService::ShowProgress(nsIDOMWindow* parent, + nsIWebBrowserPrint* webBrowserPrint, // ok to be null + nsIPrintSettings* printSettings, // ok to be null + nsIObserver* openDialogObserver, // ok to be null + PRBool isForPrinting, + nsIWebProgressListener** webProgressListener, + nsIPrintProgressParams** printProgressParams, + PRBool* notifyOnOpen) +{ + NS_ENSURE_ARG(webProgressListener); + NS_ENSURE_ARG(printProgressParams); + NS_ENSURE_ARG(notifyOnOpen); + + ResourceState setState; + nsresult rv; + + nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams(); + rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams); + NS_ENSURE_SUCCESS(rv, rv); + + mObserver = openDialogObserver; + + *notifyOnOpen = PR_FALSE; + if (printProgressParams) + { + CWnd *wnd = CWndForDOMWindow(parent); + m_PPDlg = new CPrintProgressDialog(wnd, isForPrinting, *printProgressParams, webBrowserPrint, printSettings); + m_PPDlg->Create(IDD_PRINT_PROGRESS_DIALOG); + m_PPDlg->ShowWindow(SW_SHOW); + m_PPDlg->UpdateWindow(); + + *notifyOnOpen = FirePauseEvent(); + } + + *webProgressListener = NS_STATIC_CAST(nsIWebProgressListener*, this); + NS_ADDREF(*webProgressListener); + + return rv; +} + +/* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings); */ +NS_IMETHODIMP +CPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings, nsIObserver *aObs) +{ + NS_ENSURE_ARG(printSettings); + + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void showPrinterProperties (in nsIDOMWindow parent, in wstring printerName, in nsIPrintSettings printSettings); */ +NS_IMETHODIMP +CPrintingPromptService::ShowPrinterProperties(nsIDOMWindow *parent, const PRUnichar *printerName, nsIPrintSettings *printSettings) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +//------------------------------------------------------------------------ +void CPrintingPromptService::NotifyObserver() +{ + if (mObserver) { + mObserver->Observe(nsnull, nsnull, nsnull); + } +} + +//------------------------------------------------------------------------ +void PR_CALLBACK HandlePLEvent(PLEvent* aEvent) +{ + CPrintingPromptService *printingPromptService = (CPrintingPromptService*)PL_GetEventOwner(aEvent); + + NS_ASSERTION(printingPromptService, "The event owner is null."); + if (printingPromptService) { + printingPromptService->NotifyObserver(); + } +} + +//------------------------------------------------------------------------ +void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent) +{ + CPrintingPromptService *printingPromptService = (CPrintingPromptService*)PL_GetEventOwner(aEvent); + NS_IF_RELEASE(printingPromptService); + + delete aEvent; +} + +////////////////////////////////////////////////////////////////////// +// nsIWebProgressListener +////////////////////////////////////////////////////////////////////// + +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in nsresult aStatus); */ +NS_IMETHODIMP +CPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus) +{ + if (aStateFlags & STATE_START) + { + if (m_PPDlg) + { + m_PPDlg->OnStartPrinting(); + } + } + + if (aStateFlags & STATE_STOP) + { + if (m_PPDlg) + { + m_PPDlg->OnProgressPrinting(100, 100); + m_PPDlg->DestroyWindow(); + m_PPDlg = NULL; + } + } + return NS_OK; +} + +/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ +NS_IMETHODIMP +CPrintingPromptService::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) +{ + if (m_PPDlg) + { + m_PPDlg->OnProgressPrinting(aCurTotalProgress, aMaxTotalProgress); + } + return NS_OK; +} + +/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ +NS_IMETHODIMP +CPrintingPromptService::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) +{ + return NS_OK; +} + +/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ +NS_IMETHODIMP +CPrintingPromptService::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) +{ + return NS_OK; +} + +/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ +NS_IMETHODIMP +CPrintingPromptService::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) +{ + return NS_OK; +} + + + +//***************************************************************************** +// CPrintingPromptServiceFactory +//***************************************************************************** + +class CPrintingPromptServiceFactory : public nsIFactory { +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIFACTORY + + CPrintingPromptServiceFactory(); + virtual ~CPrintingPromptServiceFactory(); +}; + +//***************************************************************************** + +NS_IMPL_ISUPPORTS1(CPrintingPromptServiceFactory, nsIFactory) + +CPrintingPromptServiceFactory::CPrintingPromptServiceFactory() { + + NS_INIT_ISUPPORTS(); +} + +CPrintingPromptServiceFactory::~CPrintingPromptServiceFactory() { +} + +NS_IMETHODIMP CPrintingPromptServiceFactory::CreateInstance(nsISupports *aOuter, const nsIID & aIID, void **aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + *aResult = NULL; + CPrintingPromptService *inst = new CPrintingPromptService; + 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 CPrintingPromptServiceFactory::LockFactory(PRBool lock) +{ + return NS_OK; +} + +//***************************************************************************** + +void InitPrintingPromptService(HINSTANCE instance) { + + gInstance = instance; +} + +nsresult NS_NewPrintingPromptServiceFactory(nsIFactory** aFactory) +{ + NS_ENSURE_ARG_POINTER(aFactory); + *aFactory = nsnull; + + CPrintingPromptServiceFactory *result = new CPrintingPromptServiceFactory; + if (!result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + *aFactory = result; + + return NS_OK; +} diff --git a/mozilla/embedding/tests/mfcembed/components/PrintingPromptService.h b/mozilla/embedding/tests/mfcembed/components/PrintingPromptService.h new file mode 100644 index 00000000000..9b42dec9a92 --- /dev/null +++ b/mozilla/embedding/tests/mfcembed/components/PrintingPromptService.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 2001 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __PrintingPromptService_h +#define __PrintingPromptService_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_NewPrintingPromptServiceFactory(nsIFactory** aFactory); +typedef nsresult (__cdecl *MakeFactoryType)(nsIFactory **); +#define kPrintingPromptServiceFactoryFuncName "NS_NewPrintingPromptServiceFactory" + +// initialization function, in hard and soft link formats +extern "C" NS_EXPORT void InitPrintingPromptService(HINSTANCE instance); +typedef nsresult (__cdecl *InitPrintingPromptServiceType)(HINSTANCE instance); +#define kPrintingPromptServiceInitFuncName "InitPrintingPromptService" + +#endif diff --git a/mozilla/embedding/tests/mfcembed/components/makefile.win b/mozilla/embedding/tests/mfcembed/components/makefile.win index 698ee7440cb..21f6b49264e 100644 --- a/mozilla/embedding/tests/mfcembed/components/makefile.win +++ b/mozilla/embedding/tests/mfcembed/components/makefile.win @@ -32,6 +32,11 @@ REQUIRES = \ xpcom \ string \ dom \ + content \ + gfx \ + widget \ + pref \ + intl \ webBrowser_core \ windowwatcher \ exthandler \ @@ -47,11 +52,15 @@ DLL=.\$(OBJDIR)\$(DLLNAME).dll RESFILE=Dialogs.res LCFLAGS=/D "WIN32_LEAN_AND_MEAN" /D "_AFXDLL" /D "USE_SINGLE_SIGN_ON" \ - /D "_USRDLL" /D "_WINDLL" + /D "_WINDLL" LLFLAGS=-SUBSYSTEM:windows CPP_OBJS= \ + .\$(OBJDIR)\nsPrintDialogUtil.obj \ + .\$(OBJDIR)\nsPrintProgressParams.obj \ + .\$(OBJDIR)\PrintingPromptService.obj \ + .\$(OBJDIR)\PrintProgressDialog.obj \ .\$(OBJDIR)\Dialogs.obj \ .\$(OBJDIR)\PromptService.obj \ .\$(OBJDIR)\HelperAppDlg.obj \ @@ -60,6 +69,7 @@ CPP_OBJS= \ LLIBS= \ $(LIBNSPR) \ $(DIST)\lib\xpcom.lib \ + $(DIST)\lib\gkgfx.lib \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/embedding/tests/mfcembed/components/nsPrintDialogUtil.cpp b/mozilla/embedding/tests/mfcembed/components/nsPrintDialogUtil.cpp new file mode 100644 index 00000000000..41581291f6b --- /dev/null +++ b/mozilla/embedding/tests/mfcembed/components/nsPrintDialogUtil.cpp @@ -0,0 +1,1427 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifdef MOZ_REQUIRE_CURRENT_SDK +#undef WINVER +#define WINVER 0x0500 +#endif + +/* ------------------------------------------------------------------- +To Build This: + + You need to add this to the the makefile.win in mozilla/content/base/src: + + .\$(OBJDIR)\nsFlyOwnPrintDialog.obj \ + + + And this to the makefile.win in mozilla/content/build: + +WIN_LIBS= \ + winspool.lib \ + comctl32.lib \ + comdlg32.lib + +---------------------------------------------------------------------- */ + +#include "prmem.h" +#include "plstr.h" +#include +#include + +#include +#include + +#include "nsIWebBrowserPrint.h" +#include "nsString.h" +#include "nsIServiceManager.h" +#include "nsReadableUtils.h" +#include "nsIWidget.h" +#include "nsIPrintSettings.h" +#include "nsIPrintSettingsWin.h" +#include "nsUnitConversion.h" +#include "nsIPrintOptions.h" +#include "nsGfxCIID.h" +static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID); + +#include "nsRect.h" + +#include "nsIPref.h" +#include "nsCRT.h" +#include "prenv.h" /* for PR_GetEnv */ + +#include +#include + +// For Localization +#include "nsIStringBundle.h" + +// This is for extending the dialog +#include + +static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); + +// For PrintDlgEx +// needed because there are unicode/ansi versions of this routine +// and we need to make sure we get the correct one. +#ifdef UNICODE +#define GetPrintDlgExQuoted "PrintDlgExW" +#else +#define GetPrintDlgExQuoted "PrintDlgExA" +#endif + +// Default labels for the radio buttons +static const char* kAsLaidOutOnScreenStr = "As &laid out on the screen"; +static const char* kTheSelectedFrameStr = "The selected &frame"; +static const char* kEachFrameSeparately = "&Each frame separately"; + + +//----------------------------------------------- +// Global Data +//----------------------------------------------- +// Identifies which new radio btn was cliked on +static UINT gFrameSelectedRadioBtn = 0; + +// Indicates whether the native print dialog was successfully extended +static PRPackedBool gDialogWasExtended = PR_FALSE; + +#define PRINTDLG_PROPERTIES "chrome://global/locale/printdialog.properties" + +static HWND gParentWnd = NULL; + +//****************************************************** +// Define native paper sizes +//****************************************************** +typedef struct { + short mPaperSize; // native enum + double mWidth; + double mHeight; + PRBool mIsInches; +} NativePaperSizes; + +// There are around 40 default print sizes defined by Windows +const NativePaperSizes kPaperSizes[] = { + {DMPAPER_LETTER, 8.5, 11.0, PR_TRUE}, + {DMPAPER_LEGAL, 8.5, 14.0, PR_TRUE}, + {DMPAPER_A4, 210.0, 297.0, PR_FALSE}, + {DMPAPER_TABLOID, 11.0, 17.0, PR_TRUE}, + {DMPAPER_LEDGER, 17.0, 11.0, PR_TRUE}, + {DMPAPER_STATEMENT, 5.5, 8.5, PR_TRUE}, + {DMPAPER_EXECUTIVE, 7.25, 10.5, PR_TRUE}, + {DMPAPER_A3, 297.0, 420.0, PR_FALSE}, + {DMPAPER_A5, 148.0, 210.0, PR_FALSE}, + {DMPAPER_CSHEET, 17.0, 22.0, PR_TRUE}, + {DMPAPER_DSHEET, 22.0, 34.0, PR_TRUE}, + {DMPAPER_ESHEET, 34.0, 44.0, PR_TRUE}, + {DMPAPER_LETTERSMALL, 8.5, 11.0, PR_TRUE}, + {DMPAPER_A4SMALL, 210.0, 297.0, PR_FALSE}, + {DMPAPER_B4, 250.0, 354.0, PR_FALSE}, + {DMPAPER_B5, 182.0, 257.0, PR_FALSE}, + {DMPAPER_FOLIO, 8.5, 13.0, PR_TRUE}, + {DMPAPER_QUARTO, 215.0, 275.0, PR_FALSE}, + {DMPAPER_10X14, 10.0, 14.0, PR_TRUE}, + {DMPAPER_11X17, 11.0, 17.0, PR_TRUE}, + {DMPAPER_NOTE, 8.5, 11.0, PR_TRUE}, + {DMPAPER_ENV_9, 3.875, 8.875, PR_TRUE}, + {DMPAPER_ENV_10, 40.125, 9.5, PR_TRUE}, + {DMPAPER_ENV_11, 4.5, 10.375, PR_TRUE}, + {DMPAPER_ENV_12, 4.75, 11.0, PR_TRUE}, + {DMPAPER_ENV_14, 5.0, 11.5, PR_TRUE}, + {DMPAPER_ENV_DL, 110.0, 220.0, PR_FALSE}, + {DMPAPER_ENV_C5, 162.0, 229.0, PR_FALSE}, + {DMPAPER_ENV_C3, 324.0, 458.0, PR_FALSE}, + {DMPAPER_ENV_C4, 229.0, 324.0, PR_FALSE}, + {DMPAPER_ENV_C6, 114.0, 162.0, PR_FALSE}, + {DMPAPER_ENV_C65, 114.0, 229.0, PR_FALSE}, + {DMPAPER_ENV_B4, 250.0, 353.0, PR_FALSE}, + {DMPAPER_ENV_B5, 176.0, 250.0, PR_FALSE}, + {DMPAPER_ENV_B6, 176.0, 125.0, PR_FALSE}, + {DMPAPER_ENV_ITALY, 110.0, 230.0, PR_FALSE}, + {DMPAPER_ENV_MONARCH, 3.875, 7.5, PR_TRUE}, + {DMPAPER_ENV_PERSONAL, 3.625, 6.5, PR_TRUE}, + {DMPAPER_FANFOLD_US, 14.875, 11.0, PR_TRUE}, + {DMPAPER_FANFOLD_STD_GERMAN, 8.5, 12.0, PR_TRUE}, + {DMPAPER_FANFOLD_LGL_GERMAN, 8.5, 13.0, PR_TRUE}, +}; +const PRInt32 kNumPaperSizes = 41; + +//---------------------------------------------------------------------------------- +static PRBool +CheckForExtendedDialog() +{ +#ifdef MOZ_REQUIRE_CURRENT_SDK + HMODULE lib = GetModuleHandle("comdlg32.dll"); + if ( lib ) { + return GetProcAddress(lib, GetPrintDlgExQuoted); + } +#endif + return PR_FALSE; +} + +//---------------------------------------------------------------------------------- +// Map an incoming size to a Windows Native enum in the DevMode +static void +MapPaperSizeToNativeEnum(LPDEVMODE aDevMode, + PRInt16 aType, + double aW, + double aH) +{ + +#ifdef DEBUG_rods + BOOL doingOrientation = aDevMode->dmFields & DM_ORIENTATION; + BOOL doingPaperSize = aDevMode->dmFields & DM_PAPERSIZE; + BOOL doingPaperLength = aDevMode->dmFields & DM_PAPERLENGTH; + BOOL doingPaperWidth = aDevMode->dmFields & DM_PAPERWIDTH; +#endif + + const double kThreshold = 0.05; + PRBool foundEnum = PR_FALSE; + for (PRInt32 i=0;i width-kThreshold && + aH < height+kThreshold && aH > height-kThreshold) { + aDevMode->dmPaperSize = kPaperSizes[i].mPaperSize; + aDevMode->dmFields &= ~DM_PAPERLENGTH; + aDevMode->dmFields &= ~DM_PAPERWIDTH; + aDevMode->dmFields |= DM_PAPERSIZE; + return; + } + } + + short width = 0; + short height = 0; + if (aType == nsIPrintSettings::kPaperSizeInches) { + width = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aW))) / 10); + height = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aH))) / 10); + + } else if (aType == nsIPrintSettings::kPaperSizeMillimeters) { + width = short(aW / 10.0); + height = short(aH / 10.0); + } else { + return; // don't set anything + } + + // width and height is in + aDevMode->dmPaperSize = 0; + aDevMode->dmPaperWidth = width; + aDevMode->dmPaperLength = height; + + aDevMode->dmFields |= DM_PAPERSIZE; + aDevMode->dmFields |= DM_PAPERLENGTH; + aDevMode->dmFields |= DM_PAPERWIDTH; +} + +//---------------------------------------------------------------------------------- +// Setup Paper Size & Orientation options into the DevMode +// +static void +SetupDevModeFromSettings(LPDEVMODE aDevMode, nsIPrintSettings* aPrintSettings) +{ + // Setup paper size + if (aPrintSettings) { + PRInt16 type; + aPrintSettings->GetPaperSizeType(&type); + if (type == nsIPrintSettings::kPaperSizeNativeData) { + PRInt16 paperEnum; + aPrintSettings->GetPaperData(&paperEnum); + aDevMode->dmPaperSize = paperEnum; + aDevMode->dmFields &= ~DM_PAPERLENGTH; + aDevMode->dmFields &= ~DM_PAPERWIDTH; + aDevMode->dmFields |= DM_PAPERSIZE; + } else { + PRInt16 unit; + double width, height; + aPrintSettings->GetPaperSizeUnit(&unit); + aPrintSettings->GetPaperWidth(&width); + aPrintSettings->GetPaperHeight(&height); + MapPaperSizeToNativeEnum(aDevMode, unit, width, height); + } + + // Setup Orientation + PRInt32 orientation; + aPrintSettings->GetOrientation(&orientation); + aDevMode->dmOrientation = orientation == nsIPrintSettings::kPortraitOrientation?DMORIENT_PORTRAIT:DMORIENT_LANDSCAPE; + aDevMode->dmFields |= DM_ORIENTATION; + + // Setup Number of Copies + PRInt32 copies; + aPrintSettings->GetNumCopies(&copies); + aDevMode->dmCopies = copies; + aDevMode->dmFields |= DM_COPIES; + + } + +} + +//---------------------------------------------------------------------------------- +// Helper Function - Free and reallocate the string +static nsresult +SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings, + LPDEVMODE aDevMode) +{ + if (aPrintSettings == nsnull) { + return NS_ERROR_FAILURE; + } + + if (aDevMode->dmFields & DM_ORIENTATION) { + PRInt32 orientation = aDevMode->dmOrientation == DMORIENT_PORTRAIT? + nsIPrintSettings::kPortraitOrientation:nsIPrintSettings::kLandscapeOrientation; + aPrintSettings->SetOrientation(orientation); + } + + // Setup Number of Copies + if (aDevMode->dmFields & DM_COPIES) { + aPrintSettings->SetNumCopies(PRInt32(aDevMode->dmCopies)); + } + + // Scaling + // Since we do the scaling, grab their value and reset back to 100 + if (aDevMode->dmFields & DM_SCALE) { + double origScale = 1.0; + aPrintSettings->GetScaling(&origScale); + double scale = double(aDevMode->dmScale) / 100.0f; + if (origScale == 1.0 || scale != 1.0) { + aPrintSettings->SetScaling(scale); + } + aDevMode->dmScale = 100; + // To turn this on you must change where the mPrt->mShrinkToFit is being set in the DocumentViewer + //aPrintSettings->SetShrinkToFit(PR_FALSE); + } + + if (aDevMode->dmFields & DM_PAPERSIZE) { + aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeNativeData); + aPrintSettings->SetPaperData(aDevMode->dmPaperSize); + + } else if (aDevMode->dmFields & DM_PAPERLENGTH && aDevMode->dmFields & DM_PAPERWIDTH) { + PRBool found = PR_FALSE; + for (PRInt32 i=0;idmPaperSize) { + aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined); + aPrintSettings->SetPaperWidth(kPaperSizes[i].mWidth); + aPrintSettings->SetPaperHeight(kPaperSizes[i].mHeight); + aPrintSettings->SetPaperSizeUnit(kPaperSizes[i].mIsInches?nsIPrintSettings::kPaperSizeInches:nsIPrintSettings::kPaperSizeInches); + found = PR_TRUE; + break; + } + } + if (!found) { + return NS_ERROR_FAILURE; + } + } else { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +//---------------------------------------------------------------------------------- +// Return localized bundle for resource strings +static nsresult +GetLocalizedBundle(const char * aPropFileName, nsIStringBundle** aStrBundle) +{ + NS_ENSURE_ARG_POINTER(aPropFileName); + NS_ENSURE_ARG_POINTER(aStrBundle); + + nsresult rv; + nsCOMPtr bundle; + + + // Create bundle + nsCOMPtr stringService = + do_GetService(kStringBundleServiceCID, &rv); + if (NS_SUCCEEDED(rv) && stringService) { + rv = stringService->CreateBundle(aPropFileName, aStrBundle); + } + + return rv; +} + +//-------------------------------------------------------- +// Return localized string +static nsresult +GetLocalizedString(nsIStringBundle* aStrBundle, const char* aKey, nsString& oVal) +{ + NS_ENSURE_ARG_POINTER(aStrBundle); + NS_ENSURE_ARG_POINTER(aKey); + + // Determine default label from string bundle + nsXPIDLString valUni; + nsAutoString key; + key.AssignWithConversion(aKey); + nsresult rv = aStrBundle->GetStringFromName(key.get(), getter_Copies(valUni)); + if (NS_SUCCEEDED(rv) && valUni) { + oVal.Assign(valUni); + } else { + oVal.Truncate(); + } + return rv; +} + +//-------------------------------------------------------- +static char* +GetACPString(const nsAString& aStr) +{ + int acplen = aStr.Length() * 2 + 1; + char * acp = new char[acplen]; + if(acp) + { + int outlen = ::WideCharToMultiByte( CP_ACP, 0, + PromiseFlatString(aStr).get(), aStr.Length(), + acp, acplen, NULL, NULL); + if ( outlen > 0) + acp[outlen] = '\0'; // null terminate + } + return acp; +} + +//-------------------------------------------------------- +// Set a multi-byte string in the control +static void SetTextOnWnd(HWND aControl, const nsString& aStr) +{ + char* pStr = GetACPString(aStr); + if (pStr) { + ::SetWindowText(aControl, pStr); + delete [] pStr; + } +} + +//-------------------------------------------------------- +// Will get the control and localized string by "key" +static void SetText(HWND aParent, + UINT aId, + nsIStringBundle* aStrBundle, + const char* aKey) +{ + HWND wnd = GetDlgItem (aParent, aId); + if (!wnd) { + return; + } + nsAutoString str; + nsresult rv = GetLocalizedString(aStrBundle, aKey, str); + if (NS_SUCCEEDED(rv)) { + SetTextOnWnd(wnd, str); + } +} + +//-------------------------------------------------------- +static void SetRadio(HWND aParent, + UINT aId, + PRBool aIsSet, + PRBool isEnabled = PR_TRUE) +{ + HWND wnd = ::GetDlgItem (aParent, aId); + if (!wnd) { + return; + } + if (!isEnabled) { + ::EnableWindow(wnd, FALSE); + return; + } + ::EnableWindow(wnd, TRUE); + ::SendMessage(wnd, BM_SETCHECK, (WPARAM)aIsSet, (LPARAM)0); +} + +//-------------------------------------------------------- +static void SetRadioOfGroup(HWND aDlg, int aRadId) +{ + int radioIds[] = {rad4, rad5, rad6}; + int numRads = 3; + + for (int i=0;i strBundle; + if (NS_SUCCEEDED(GetLocalizedBundle(PRINTDLG_PROPERTIES, getter_AddRefs(strBundle)))) { + PRInt32 i = 0; + while (gAllPropKeys[i].mKeyStr != NULL) { + SetText(hdlg, gAllPropKeys[i].mKeyId, strBundle, gAllPropKeys[i].mKeyStr); + i++; + } + } + + // Set up radio buttons + if (aHowToEnableFrameUI == nsIPrintSettings::kFrameEnableAll) { + SetRadio(hdlg, rad4, PR_FALSE); + SetRadio(hdlg, rad5, PR_TRUE); + SetRadio(hdlg, rad6, PR_FALSE); + // set default so user doesn't have to actually press on it + gFrameSelectedRadioBtn = rad5; + + } else if (aHowToEnableFrameUI == nsIPrintSettings::kFrameEnableAsIsAndEach) { + SetRadio(hdlg, rad4, PR_FALSE); + SetRadio(hdlg, rad5, PR_FALSE, PR_FALSE); + SetRadio(hdlg, rad6, PR_TRUE); + // set default so user doesn't have to actually press on it + gFrameSelectedRadioBtn = rad6; + + + } else { // nsIPrintSettings::kFrameEnableNone + // we are using this function to disabe the group box + SetRadio(hdlg, grp3, PR_FALSE, PR_FALSE); + // now disable radiobuttons + SetRadio(hdlg, rad4, PR_FALSE, PR_FALSE); + SetRadio(hdlg, rad5, PR_FALSE, PR_FALSE); + SetRadio(hdlg, rad6, PR_FALSE, PR_FALSE); + } + +} + + +//-------------------------------------------------------- +// Special Hook Procedure for handling the print dialog messages +static UINT CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam) +{ + + if (uiMsg == WM_COMMAND) { + UINT id = LOWORD(wParam); + if (id == rad4 || id == rad5 || id == rad6) { + gFrameSelectedRadioBtn = id; + SetRadioOfGroup(hdlg, id); + } + + } else if (uiMsg == WM_INITDIALOG) { + PRINTDLG * printDlg = (PRINTDLG *)lParam; + if (printDlg == NULL) return 0L; + + PRInt16 howToEnableFrameUI = (PRInt16)printDlg->lCustData; + + HINSTANCE hInst = (HINSTANCE)::GetWindowLong(hdlg, GWL_HINSTANCE); + if (hInst == NULL) return 0L; + + // Start by getting the local rects of several of the controls + // so we can calculate where the new controls are + HWND wnd = ::GetDlgItem(hdlg, grp1); + if (wnd == NULL) return 0L; + RECT dlgRect; + GetLocalRect(wnd, dlgRect, hdlg); + + wnd = ::GetDlgItem(hdlg, rad1); // this is the top control "All" + if (wnd == NULL) return 0L; + RECT rad1Rect; + GetLocalRect(wnd, rad1Rect, hdlg); + + wnd = ::GetDlgItem(hdlg, rad2); // this is the bottom control "Selection" + if (wnd == NULL) return 0L; + RECT rad2Rect; + GetLocalRect(wnd, rad2Rect, hdlg); + + wnd = ::GetDlgItem(hdlg, rad3); // this is the middle control "Pages" + if (wnd == NULL) return 0L; + RECT rad3Rect; + GetLocalRect(wnd, rad3Rect, hdlg); + + HWND okWnd = ::GetDlgItem(hdlg, IDOK); + if (okWnd == NULL) return 0L; + RECT okRect; + GetLocalRect(okWnd, okRect, hdlg); + + wnd = ::GetDlgItem(hdlg, grp4); // this is the "Print range" groupbox + if (wnd == NULL) return 0L; + RECT prtRect; + GetLocalRect(wnd, prtRect, hdlg); + + + // calculate various different "gaps" for layout purposes + + int rbGap = rad3Rect.top - rad1Rect.bottom; // gap between radiobtns + int grpBotGap = dlgRect.bottom - rad2Rect.bottom; // gap from bottom rb to bottom of grpbox + int grpGap = dlgRect.top - prtRect.bottom ; // gap between group boxes + int top = dlgRect.bottom + grpGap; + int radHgt = rad1Rect.bottom - rad1Rect.top + 1; // top of new group box + int y = top+(rad1Rect.top-dlgRect.top); // starting pos of first radio + int rbWidth = dlgRect.right - rad1Rect.left - 5; // measure from rb left to the edge of the groupbox + // (5 is arbitrary) + nsRect rect; + + // Create and position the radio buttons + // + // If any one control cannot be created then + // hide the others and bail out + // + rect.SetRect(rad1Rect.left, y, rbWidth,radHgt); + HWND rad4Wnd = CreateRadioBtn(hInst, hdlg, rad4, kAsLaidOutOnScreenStr, rect); + if (rad4Wnd == NULL) return 0L; + y += radHgt + rbGap; + + rect.SetRect(rad1Rect.left, y, rbWidth, radHgt); + HWND rad5Wnd = CreateRadioBtn(hInst, hdlg, rad5, kTheSelectedFrameStr, rect); + if (rad5Wnd == NULL) { + Show(rad4Wnd, FALSE); // hide + return 0L; + } + y += radHgt + rbGap; + + rect.SetRect(rad1Rect.left, y, rbWidth, radHgt); + HWND rad6Wnd = CreateRadioBtn(hInst, hdlg, rad6, kEachFrameSeparately, rect); + if (rad6Wnd == NULL) { + Show(rad4Wnd, FALSE); // hide + Show(rad5Wnd, FALSE); // hide + return 0L; + } + y += radHgt + grpBotGap; + + // Create and position the group box + rect.SetRect (dlgRect.left, top, dlgRect.right-dlgRect.left+1, y-top+1); + HWND grpBoxWnd = CreateGroupBox(hInst, hdlg, grp3, NS_LITERAL_STRING("Print Frame"), rect); + if (grpBoxWnd == NULL) { + Show(rad4Wnd, FALSE); // hide + Show(rad5Wnd, FALSE); // hide + Show(rad6Wnd, FALSE); // hide + return 0L; + } + + // Here we figure out the old height of the dlg + // then figure it's gap from the old grpbx to the bottom + // then size the dlg + RECT pr, cr; + ::GetWindowRect(hdlg, &pr); + ::GetClientRect(hdlg, &cr); + + int dlgHgt = (cr.bottom - cr.top) + 1; + int bottomGap = dlgHgt - okRect.bottom; + pr.bottom += (dlgRect.bottom-dlgRect.top) + grpGap + 1 - (dlgHgt-dlgRect.bottom) + bottomGap; + + ::SetWindowPos(hdlg, NULL, pr.left, pr.top, pr.right-pr.left+1, pr.bottom-pr.top+1, + SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER); + + // figure out the new height of the dialog + ::GetClientRect(hdlg, &cr); + dlgHgt = (cr.bottom - cr.top) + 1; + + // Reposition the OK and Cancel btns + int okHgt = okRect.bottom - okRect.top + 1; + ::SetWindowPos(okWnd, NULL, okRect.left, dlgHgt-bottomGap-okHgt, 0, 0, + SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER); + + HWND cancelWnd = ::GetDlgItem(hdlg, IDCANCEL); + if (cancelWnd == NULL) return 0L; + + RECT cancelRect; + GetLocalRect(cancelWnd, cancelRect, hdlg); + int cancelHgt = cancelRect.bottom - cancelRect.top + 1; + ::SetWindowPos(cancelWnd, NULL, cancelRect.left, dlgHgt-bottomGap-cancelHgt, 0, 0, + SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER); + + // localize and initialize the groupbox and radiobuttons + InitializeExtendedDialog(hdlg, howToEnableFrameUI); + + // Looks like we were able to extend the dialog + gDialogWasExtended = PR_TRUE; + } + return 0L; +} + +//---------------------------------------------------------------------------------- +// Returns a Global Moveable Memory Handle to a DevMode +// from the Printer byt the name of aPrintName +static HGLOBAL CreateGlobalDevModeAndInit(LPTSTR aPrintName, nsIPrintSettings* aPS) +{ + HGLOBAL hGlobalDevMode = NULL; + + nsresult rv = NS_ERROR_FAILURE; + HANDLE hPrinter = NULL; + BOOL status = ::OpenPrinter(aPrintName, &hPrinter, NULL); + if (status) { + + LPDEVMODE pNewDevMode; + DWORD dwNeeded, dwRet; + + nsString prtName; +#ifdef UNICODE + prtName.AppendWithConversion((PRUnichar *)aPrintName); +#else + prtName.AssignWithConversion((char*)aPrintName); +#endif + + // Allocate a buffer of the correct size. + dwNeeded = ::DocumentProperties(gParentWnd, hPrinter, aPrintName, NULL, NULL, 0); + + pNewDevMode = (LPDEVMODE)malloc(dwNeeded); + if (!pNewDevMode) return NULL; + + hGlobalDevMode = (HGLOBAL)::GlobalAlloc(GHND, dwNeeded); + if (!hGlobalDevMode) { + free(pNewDevMode); + } + + dwRet = ::DocumentProperties(gParentWnd, hPrinter, aPrintName, pNewDevMode, NULL, DM_OUT_BUFFER); + + if (dwRet != IDOK) { + free(pNewDevMode); + ::GlobalFree(hGlobalDevMode); + ::ClosePrinter(hPrinter); + return NULL; + } + + // Lock memory and copy contents from DEVMODE (current printer) + // to Global Memory DEVMODE + LPDEVMODE devMode = (DEVMODE *)::GlobalLock(hGlobalDevMode); + if (devMode) { + memcpy(devMode, pNewDevMode, dwNeeded); + // Initialize values from the PrintSettings + SetupDevModeFromSettings(devMode, aPS); + ::GlobalUnlock(hGlobalDevMode); + } else { + ::GlobalFree(hGlobalDevMode); + hGlobalDevMode = NULL; + } + + free(pNewDevMode); + + ::ClosePrinter(hPrinter); + + } else { + return NULL; + } + + return hGlobalDevMode; +} + +//------------------------------------------------------------------ +// helper +static PRUnichar * GetDefaultPrinterNameFromGlobalPrinters() +{ + nsresult rv; + PRUnichar * printerName = nsnull; + nsCOMPtr prtEnum = do_GetService(kPrinterEnumeratorCID, &rv); + if (prtEnum) { + prtEnum->GetDefaultPrinterName(&printerName); + } + return printerName; +} + + +//------------------------------------------------------------------ +// Displays the native Print Dialog +static nsresult +ShowNativePrintDialog(HWND aHWnd, + nsIPrintSettings* aPrintSettings) +{ + //NS_ENSURE_ARG_POINTER(aHWnd); + NS_ENSURE_ARG_POINTER(aPrintSettings); + + nsresult rv = NS_ERROR_FAILURE; + gDialogWasExtended = PR_FALSE; + + HGLOBAL hGlobalDevMode = NULL; + HGLOBAL hDevNames = NULL; + + // Get the Print Name to be used + PRUnichar * printerName; + aPrintSettings->GetPrinterName(&printerName); + + // If there is no name then use the default printer + if (!printerName || (printerName && !*printerName)) { + printerName = GetDefaultPrinterNameFromGlobalPrinters(); + } + + NS_ASSERTION(printerName, "We have to have a printer name"); + if (!printerName) return NS_ERROR_FAILURE; + + // Now create a DEVNAMES struct so the the dialog is initialized correctly. + PRUint32 len = nsCRT::strlen(printerName); + hDevNames = (HGLOBAL)::GlobalAlloc(GHND, len+sizeof(DEVNAMES)+1); + DEVNAMES* pDevNames = (DEVNAMES*)::GlobalLock(hDevNames); + pDevNames->wDriverOffset = sizeof(DEVNAMES); + pDevNames->wDeviceOffset = sizeof(DEVNAMES); + pDevNames->wOutputOffset = sizeof(DEVNAMES)+len+1; + pDevNames->wDefault = 0; + char* device = &(((char*)pDevNames)[pDevNames->wDeviceOffset]); + strcpy(device, (char*)NS_ConvertUCS2toUTF8(printerName).get()); + ::GlobalUnlock(hDevNames); + + // Create a Moveable Memory Object that holds a new DevMode + // from the Printer Name + // The PRINTDLG.hDevMode requires that it be a moveable memory object + // NOTE: We only need to free hGlobalDevMode when the dialog is cancelled + // When the user prints, it comes back in the printdlg struct and + // is used and cleaned up later +#ifdef UNICODE + hGlobalDevMode = CreateGlobalDevModeAndInit(printerName, aPrintSettings); +#else + hGlobalDevMode = CreateGlobalDevModeAndInit((char*)NS_ConvertUCS2toUTF8(printerName).get(), aPrintSettings); +#endif + + // Prepare to Display the Print Dialog + PRINTDLG prntdlg; + memset(&prntdlg, 0, sizeof(PRINTDLG)); + + prntdlg.lStructSize = sizeof(prntdlg); + prntdlg.hwndOwner = aHWnd; + prntdlg.hDevMode = hGlobalDevMode; + prntdlg.hDevNames = hDevNames; + prntdlg.hDC = NULL; + prntdlg.Flags = PD_ALLPAGES | PD_RETURNIC | PD_HIDEPRINTTOFILE | PD_USEDEVMODECOPIESANDCOLLATE; + + // if there is a current selection then enable the "Selection" radio button + PRInt16 howToEnableFrameUI = nsIPrintSettings::kFrameEnableNone; + PRBool isOn; + aPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); + if (!isOn) { + prntdlg.Flags |= PD_NOSELECTION; + } + aPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); + + // Determine whether we have a completely native dialog + // or whether we cshould extend it + // true - do only the native + // false - extend the dialog + PRPackedBool doExtend = PR_FALSE; + nsCOMPtr strBundle; + if (NS_SUCCEEDED(GetLocalizedBundle(PRINTDLG_PROPERTIES, getter_AddRefs(strBundle)))) { + nsAutoString doExtendStr; + if (NS_SUCCEEDED(GetLocalizedString(strBundle, "extend", doExtendStr))) { + doExtend = doExtendStr.Equals(NS_LITERAL_STRING("true")); + } + } + + prntdlg.nFromPage = 0xFFFF; + prntdlg.nToPage = 0xFFFF; + prntdlg.nMinPage = 1; + prntdlg.nMaxPage = 0xFFFF; + prntdlg.nCopies = 1; + prntdlg.lpfnSetupHook = NULL; + prntdlg.lpSetupTemplateName = NULL; + prntdlg.hPrintTemplate = NULL; + prntdlg.hSetupTemplate = NULL; + + prntdlg.hInstance = NULL; + prntdlg.lpPrintTemplateName = NULL; + + if (!doExtend) { + prntdlg.lCustData = NULL; + prntdlg.lpfnPrintHook = NULL; + } else { + // Set up print dialog "hook" procedure for extending the dialog + prntdlg.lCustData = (DWORD)howToEnableFrameUI; + prntdlg.lpfnPrintHook = (LPPRINTHOOKPROC)PrintHookProc; + prntdlg.Flags |= PD_ENABLEPRINTHOOK; + } + + BOOL result = ::PrintDlg(&prntdlg); + + if (TRUE == result) { + if (aPrintSettings && prntdlg.hDevMode != NULL) { + // Transfer the settings from the native data to the PrintSettings + LPDEVMODE devMode = (LPDEVMODE)::GlobalLock(prntdlg.hDevMode); + SetPrintSettingsFromDevMode(aPrintSettings, devMode); + ::GlobalUnlock(prntdlg.hDevMode); + } + DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(prntdlg.hDevNames); + if ( NULL != devnames ) { + + char* device = &(((char *)devnames)[devnames->wDeviceOffset]); + char* driver = &(((char *)devnames)[devnames->wDriverOffset]); + + nsCOMPtr psWin(do_QueryInterface(aPrintSettings)); + // Setup local Data members + psWin->SetDeviceName(device); + psWin->SetDriverName(driver); + +#if defined(DEBUG_rods) || defined(DEBUG_dcone) + printf("printer: driver %s, device %s flags: %d\n", driver, device, prntdlg.Flags); +#endif + // fill the print options with the info from the dialog + if (aPrintSettings != nsnull) { + nsString printerName; + printerName.AssignWithConversion(device); + + aPrintSettings->SetPrinterName(printerName.get()); + + if (prntdlg.Flags & PD_SELECTION) { + aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSelection); + + } else if (prntdlg.Flags & PD_PAGENUMS) { + aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSpecifiedPageRange); + aPrintSettings->SetStartPageRange(prntdlg.nFromPage); + aPrintSettings->SetEndPageRange(prntdlg.nToPage); + + } else { // (prntdlg.Flags & PD_ALLPAGES) + aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages); + } + + if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { + // make sure the dialog got extended + if (gDialogWasExtended) { + // check to see about the frame radio buttons + switch (gFrameSelectedRadioBtn) { + case rad4: + aPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); + break; + case rad5: + aPrintSettings->SetPrintFrameType(nsIPrintSettings::kSelectedFrame); + break; + case rad6: + aPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep); + break; + } // switch + } else { + // if it didn't get extended then have it default to printing + // each frame separately + aPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep); + } + } else { + aPrintSettings->SetPrintFrameType(nsIPrintSettings::kNoFrames); + } + } + ::GlobalUnlock(prntdlg.hDevNames); + +#if defined(DEBUG_rods) || defined(DEBUG_dcone) + PRBool printSelection = prntdlg.Flags & PD_SELECTION; + PRBool printAllPages = prntdlg.Flags & PD_ALLPAGES; + PRBool printNumPages = prntdlg.Flags & PD_PAGENUMS; + PRInt32 fromPageNum = 0; + PRInt32 toPageNum = 0; + + if (printNumPages) { + fromPageNum = prntdlg.nFromPage; + toPageNum = prntdlg.nToPage; + } + if (printSelection) { + printf("Printing the selection\n"); + + } else if (printAllPages) { + printf("Printing all the pages\n"); + + } else { + printf("Printing from page no. %d to %d\n", fromPageNum, toPageNum); + } +#endif + + LPDEVMODE devMode = (LPDEVMODE)::GlobalLock(prntdlg.hDevMode); + psWin->SetDevMode(devMode); + SetPrintSettingsFromDevMode(aPrintSettings, devMode); + ::GlobalUnlock(prntdlg.hDevMode); + + } + } else { + aPrintSettings->SetIsCancelled(PR_TRUE); + ::GlobalFree(hGlobalDevMode); + return NS_ERROR_ABORT; + } + + return NS_OK; +} + + +#ifdef MOZ_REQUIRE_CURRENT_SDK +//------------------------------------------------------------------ +// Callback for Property Sheet +static BOOL APIENTRY PropSheetCallBack(HWND hdlg, UINT uiMsg, UINT wParam, LONG lParam) +{ + if (uiMsg == WM_COMMAND) { + UINT id = LOWORD(wParam); + if (id == rad4 || id == rad5 || id == rad6) { + gFrameSelectedRadioBtn = id; + SetRadioOfGroup(hdlg, id); + } + + } else if (uiMsg == WM_INITDIALOG) { + // Create the groupbox and Radiobuttons on the "Options" Property Sheet + + // We temporarily borrowed the global value for initialization + // now clear it before the dialog appears + PRInt16 howToEnableFrameUI = gFrameSelectedRadioBtn; + gFrameSelectedRadioBtn = 0; + + HINSTANCE hInst = (HINSTANCE)::GetWindowLong(hdlg, GWL_HINSTANCE); + if (hInst == NULL) return 0L; + + // Get default font for the dialog & then its font metrics + // we need the text height to determine the height of the radio buttons + TEXTMETRIC metrics; + HFONT hFont = (HFONT)::SendMessage(hdlg, WM_GETFONT, (WPARAM)0, (LPARAM)0); + HDC localDC = ::GetDC(hdlg); + ::SelectObject(localDC, (HGDIOBJ)hFont); + ::GetTextMetrics(localDC, &metrics); + ::ReleaseDC(hdlg, localDC); + + // calculate various different "gaps" for layout purposes + RECT dlgr; + ::GetWindowRect(hdlg, &dlgr); + + int horzGap = 5; // generic horz gap + int vertGap = 5; // generic vert gap + int rbGap = metrics.tmHeight / 2; // gap between radiobtns + int top = vertGap*2; // start at the top + int radHgt = metrics.tmHeight; // top of new group box + int y = top; // starting pos of first radio + int x = horzGap*2; + int rbWidth = dlgr.right - dlgr.left - (5*horzGap); + int grpWidth = dlgr.right - dlgr.left - (2*horzGap); + + nsRect rect; + + // Create and position the radio buttons + // + // If any one control cannot be created then + // hide the others and bail out + // + x += horzGap*2; + y += vertGap + metrics.tmHeight; + rect.SetRect(x, y, rbWidth,radHgt); + HWND rad4Wnd = CreateRadioBtn(hInst, hdlg, rad4, kAsLaidOutOnScreenStr, rect); + if (rad4Wnd == NULL) return 0L; + y += radHgt + rbGap; + + rect.SetRect(x, y, rbWidth, radHgt); + HWND rad5Wnd = CreateRadioBtn(hInst, hdlg, rad5, kTheSelectedFrameStr, rect); + if (rad5Wnd == NULL) { + Show(rad4Wnd, FALSE); // hide + return 0L; + } + y += radHgt + rbGap; + + rect.SetRect(x, y, rbWidth, radHgt); + HWND rad6Wnd = CreateRadioBtn(hInst, hdlg, rad6, kEachFrameSeparately, rect); + if (rad6Wnd == NULL) { + Show(rad4Wnd, FALSE); // hide + Show(rad5Wnd, FALSE); // hide + return 0L; + } + y += radHgt + (vertGap*2); + + x -= horzGap*2; + // Create and position the group box + rect.SetRect (x, top, grpWidth, y-top+1); + HWND grpBoxWnd = CreateGroupBox(hInst, hdlg, grp3, NS_LITERAL_STRING("Print Frame"), rect); + if (grpBoxWnd == NULL) { + Show(rad4Wnd, FALSE); // hide + Show(rad5Wnd, FALSE); // hide + Show(rad6Wnd, FALSE); // hide + return 0L; + } + + // localize and initialize the groupbox and radiobuttons + InitializeExtendedDialog(hdlg, howToEnableFrameUI); + + // Looks like we were able to extend the dialog + gDialogWasExtended = PR_TRUE; + } + return 0L; +} + +//------------------------------------------------------------------ +// Creates the "Options" Property Sheet +static HPROPSHEETPAGE ExtendPrintDialog(HWND aHWnd, char* aTitle) +{ + // The resource "OPTPROPSHEET" comes out of the widget/build/widget.rc file + HINSTANCE hInst = (HINSTANCE)::GetWindowLong(aHWnd, GWL_HINSTANCE); + PROPSHEETPAGE psp; + memset(&psp, 0, sizeof(PROPSHEETPAGE)); + psp.dwSize = sizeof(PROPSHEETPAGE); + psp.dwFlags = PSP_USETITLE | PSP_PREMATURE; + psp.hInstance = hInst; + psp.pszTemplate = "OPTPROPSHEET"; + psp.pfnDlgProc = PropSheetCallBack; + psp.pszTitle = aTitle?aTitle:"Options"; + + HPROPSHEETPAGE newPropSheet = ::CreatePropertySheetPage(&psp); + return newPropSheet; + +} + +//------------------------------------------------------------------ +// Displays the native Print Dialog +static nsresult +ShowNativePrintDialogEx(HWND aHWnd, + nsIPrintSettings* aPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aHWnd); + NS_ENSURE_ARG_POINTER(aPrintSettings); + + nsresult rv = NS_ERROR_FAILURE; + gDialogWasExtended = PR_FALSE; + + // Create a Moveable Memory Object that holds a new DevMode + // from the Printer Name + // The PRINTDLG.hDevMode requires that it be a moveable memory object + // NOTE: We only need to free hGlobalDevMode when the dialog is cancelled + // When the user prints, it comes back in the printdlg struct and + // is used and cleaned up later + PRUnichar * printerName; + aPrintSettings->GetPrinterName(&printerName); + HGLOBAL hGlobalDevMode = NULL; + if (printerName) { +#ifdef UNICODE + hGlobalDevMode = CreateGlobalDevModeAndInit(printerName, aPrintSettings); +#else + hGlobalDevMode = CreateGlobalDevModeAndInit((char*)NS_ConvertUCS2toUTF8(printerName).get(), aPrintSettings); +#endif + } + + // Prepare to Display the Print Dialog + PRINTDLGEX prntdlg; + memset(&prntdlg, 0, sizeof(PRINTDLGEX)); + + prntdlg.lStructSize = sizeof(prntdlg); + prntdlg.hwndOwner = aHWnd; + prntdlg.hDevMode = hGlobalDevMode; + prntdlg.Flags = PD_ALLPAGES | PD_RETURNDC | PD_HIDEPRINTTOFILE | PD_USEDEVMODECOPIESANDCOLLATE | + PD_NOCURRENTPAGE; + prntdlg.nStartPage = START_PAGE_GENERAL; + + // if there is a current selection then enable the "Selection" radio button + PRInt16 howToEnableFrameUI = nsIPrintSettings::kFrameEnableNone; + if (aPrintSettings != nsnull) { + PRBool isOn; + aPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); + if (!isOn) { + prntdlg.Flags |= PD_NOSELECTION; + } + aPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); + } + + // Determine whether we have a completely native dialog + // or whether we cshould extend it + // true - do only the native + // false - extend the dialog + PRPackedBool doExtend = PR_FALSE; + nsCOMPtr strBundle; + if (NS_SUCCEEDED(GetLocalizedBundle(PRINTDLG_PROPERTIES, getter_AddRefs(strBundle)))) { + nsAutoString doExtendStr; + if (NS_SUCCEEDED(GetLocalizedString(strBundle, "extend", doExtendStr))) { + doExtend = doExtendStr.EqualsIgnoreCase("true"); + } + } + + // At the moment we can only support one page range + // from all the documentation I can find, it appears that this + // will get cleanup automatically when the struct goes away + const int kNumPageRanges = 1; + LPPRINTPAGERANGE pPageRanges = (LPPRINTPAGERANGE) GlobalAlloc(GPTR, kNumPageRanges * sizeof(PRINTPAGERANGE)); + if (!pPageRanges) + return E_OUTOFMEMORY; + + prntdlg.nPageRanges = 0; + prntdlg.nMaxPageRanges = kNumPageRanges; + prntdlg.lpPageRanges = pPageRanges; + prntdlg.nMinPage = 1; + prntdlg.nMaxPage = 0xFFFF; + prntdlg.nCopies = 1; + + if (doExtend) { + // lLcalize the Property Sheet (Tab) title + char* pTitle = NULL; + nsString optionsStr; + if (NS_SUCCEEDED(GetLocalizedString(strBundle, "options", optionsStr))) { + pTitle = GetACPString(optionsStr); + } + + // Temporarily borrow this variable for setting up the radiobuttons + // if we don't use this, we will need to define a new global var + gFrameSelectedRadioBtn = howToEnableFrameUI; + HPROPSHEETPAGE psp[1]; + psp[0] = ExtendPrintDialog(aHWnd, pTitle); + prntdlg.nPropertyPages = 1; + prntdlg.lphPropertyPages = psp; + } + + HRESULT result = ::PrintDlgEx(&prntdlg); + + if (S_OK == result && (prntdlg.dwResultAction == PD_RESULT_PRINT)) { + if (aPrintSettings && prntdlg.hDevMode != NULL) { + LPDEVMODE devMode = (LPDEVMODE)::GlobalLock(prntdlg.hDevMode); + SetPrintSettingsFromDevMode(aPrintSettings, devMode); + ::GlobalUnlock(prntdlg.hDevMode); + } + DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(prntdlg.hDevNames); + if ( NULL != devnames ) { + + char* device = &(((char *)devnames)[devnames->wDeviceOffset]); + char* driver = &(((char *)devnames)[devnames->wDriverOffset]); + + nsCOMPtr psWin(do_QueryInterface(aPrintSettings)); + // Setup local Data members + psWin->SetDeviceName(device); + psWin->SetDriverName(driver); + +#if defined(DEBUG_rods) || defined(DEBUG_dcone) + printf("printer: driver %s, device %s flags: %d\n", driver, device, prntdlg.Flags); +#endif + ::GlobalUnlock(prntdlg.hDevNames); + + // fill the print options with the info from the dialog + if (aPrintSettings != nsnull) { + + if (prntdlg.Flags & PD_SELECTION) { + aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSelection); + + } else if (prntdlg.Flags & PD_PAGENUMS) { + aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSpecifiedPageRange); + aPrintSettings->SetStartPageRange(pPageRanges->nFromPage); + aPrintSettings->SetEndPageRange(pPageRanges->nToPage); + + } else { // (prntdlg.Flags & PD_ALLPAGES) + aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages); + } + + if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { + // make sure the dialog got extended + if (gDialogWasExtended) { + // check to see about the frame radio buttons + switch (gFrameSelectedRadioBtn) { + case rad4: + aPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); + break; + case rad5: + aPrintSettings->SetPrintFrameType(nsIPrintSettings::kSelectedFrame); + break; + case rad6: + aPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep); + break; + } // switch + } else { + // if it didn't get extended then have it default to printing + // each frame separately + aPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep); + } + } else { + aPrintSettings->SetPrintFrameType(nsIPrintSettings::kNoFrames); + } + } + + +#if defined(DEBUG_rods) || defined(DEBUG_dcone) + PRBool printSelection = prntdlg.Flags & PD_SELECTION; + PRBool printAllPages = prntdlg.Flags & PD_ALLPAGES; + PRBool printNumPages = prntdlg.Flags & PD_PAGENUMS; + PRInt32 fromPageNum = 0; + PRInt32 toPageNum = 0; + + if (printNumPages) { + fromPageNum = pPageRanges->nFromPage; + toPageNum = pPageRanges->nToPage; + } + if (printSelection) { + printf("Printing the selection\n"); + + } else if (printAllPages) { + printf("Printing all the pages\n"); + + } else { + printf("Printing from page no. %d to %d\n", fromPageNum, toPageNum); + } +#endif + + LPDEVMODE devMode = (LPDEVMODE)::GlobalLock(prntdlg.hDevMode); + psWin->SetDevMode(devMode); + SetPrintSettingsFromDevMode(aPrintSettings, devMode); + ::GlobalUnlock(prntdlg.hDevMode); + + } + } else { + if (hGlobalDevMode) ::GlobalFree(hGlobalDevMode); + return NS_ERROR_ABORT; + } + + ::GlobalFree(pPageRanges); + + return NS_OK; +} +#endif // MOZ_REQUIRE_CURRENT_SDK + +//------------------------------------------------------------------ +static void +PrepareForPrintDialog(nsIWebBrowserPrint* aWebBrowserPrint, nsIPrintSettings* aPS) +{ + NS_ASSERTION(aWebBrowserPrint, "Can't be null"); + NS_ASSERTION(aPS, "Can't be null"); + + PRBool isFramesetDocument; + PRBool isFramesetFrameSelected; + PRBool isIFrameSelected; + PRBool isRangeSelection; + + aWebBrowserPrint->GetIsFramesetDocument(&isFramesetDocument); + aWebBrowserPrint->GetIsFramesetFrameSelected(&isFramesetFrameSelected); + aWebBrowserPrint->GetIsIFrameSelected(&isIFrameSelected); + aWebBrowserPrint->GetIsRangeSelection(&isRangeSelection); + + // Setup print options for UI + if (isFramesetDocument) { + if (isFramesetFrameSelected) { + aPS->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAll); + } else { + aPS->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAsIsAndEach); + } + } else { + aPS->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableNone); + } + + // Now determine how to set up the Frame print UI + aPS->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB, isRangeSelection || isIFrameSelected); + +} + +//---------------------------------------------------------------------------------- +//-- Show Print Dialog +//---------------------------------------------------------------------------------- +nsresult NativeShowPrintDialog(HWND aHWnd, + nsIWebBrowserPrint* aWebBrowserPrint, + nsIPrintSettings* aPrintSettings) +{ + nsresult rv = NS_ERROR_FAILURE; + + PrepareForPrintDialog(aWebBrowserPrint, aPrintSettings); + +#ifdef MOZ_REQUIRE_CURRENT_SDK + if (CheckForExtendedDialog()) { + rv = ShowNativePrintDialogEx(aHWnd, aPrintSettings); + } else { + rv = ShowNativePrintDialog(aHWnd, aPrintSettings); + } +#else + rv = ShowNativePrintDialog(aHWnd, aPrintSettings); +#endif + + return rv; +} + diff --git a/mozilla/embedding/tests/mfcembed/components/nsPrintDialogUtil.h b/mozilla/embedding/tests/mfcembed/components/nsPrintDialogUtil.h new file mode 100644 index 00000000000..e1d37533dcd --- /dev/null +++ b/mozilla/embedding/tests/mfcembed/components/nsPrintDialogUtil.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#ifndef nsFlyOwnDialog_h___ +#define nsFlyOwnDialog_h___ + +nsresult NativeShowPrintDialog(HWND aHWnd, + nsIWebBrowserPrint* aWebBrowserPrint, + nsIPrintSettings* aPrintSettings); + +#endif /* nsFlyOwnDialog_h___ */ diff --git a/mozilla/embedding/tests/mfcembed/components/nsPrintProgressParams.cpp b/mozilla/embedding/tests/mfcembed/components/nsPrintProgressParams.cpp new file mode 100644 index 00000000000..6c686884840 --- /dev/null +++ b/mozilla/embedding/tests/mfcembed/components/nsPrintProgressParams.cpp @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Rod Spears + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsPrintProgressParams.h" +#include "nsReadableUtils.h" + + +NS_IMPL_ISUPPORTS1(nsPrintProgressParams, nsIPrintProgressParams) + +nsPrintProgressParams::nsPrintProgressParams() +{ + NS_INIT_ISUPPORTS(); +} + +nsPrintProgressParams::~nsPrintProgressParams() +{ +} + +/* attribute wstring docTitle; */ +NS_IMETHODIMP nsPrintProgressParams::GetDocTitle(PRUnichar * *aDocTitle) +{ + NS_ENSURE_ARG(aDocTitle); + + *aDocTitle = ToNewUnicode(mDocTitle); + return NS_OK; +} + +NS_IMETHODIMP nsPrintProgressParams::SetDocTitle(const PRUnichar * aDocTitle) +{ + mDocTitle = aDocTitle; + return NS_OK; +} + +/* attribute wstring docURL; */ +NS_IMETHODIMP nsPrintProgressParams::GetDocURL(PRUnichar * *aDocURL) +{ + NS_ENSURE_ARG(aDocURL); + + *aDocURL = ToNewUnicode(mDocURL); + return NS_OK; +} + +NS_IMETHODIMP nsPrintProgressParams::SetDocURL(const PRUnichar * aDocURL) +{ + mDocURL = aDocURL; + return NS_OK; +} + diff --git a/mozilla/embedding/tests/mfcembed/components/nsPrintProgressParams.h b/mozilla/embedding/tests/mfcembed/components/nsPrintProgressParams.h new file mode 100644 index 00000000000..046e9183e04 --- /dev/null +++ b/mozilla/embedding/tests/mfcembed/components/nsPrintProgressParams.h @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Rod Spears + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __nsPrintProgressParams_h +#define __nsPrintProgressParams_h + +#include "nsIPrintProgressParams.h" +#include "nsString.h" + +class nsPrintProgressParams : public nsIPrintProgressParams +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIPRINTPROGRESSPARAMS + + nsPrintProgressParams(); + virtual ~nsPrintProgressParams(); + +private: + nsString mDocTitle; + nsString mDocURL; +}; + +#endif diff --git a/mozilla/embedding/tests/mfcembed/components/resource.h b/mozilla/embedding/tests/mfcembed/components/resource.h index df2de370eb3..aa4d285c93b 100644 --- a/mozilla/embedding/tests/mfcembed/components/resource.h +++ b/mozilla/embedding/tests/mfcembed/components/resource.h @@ -9,6 +9,7 @@ #define IDD_CONFIRM_CHECK_DIALOG 132 #define IDD_PROGRESS_DIALOG 133 #define IDD_CHOOSE_ACTION_DIALOG 134 +#define IDD_PRINT_PROGRESS_DIALOG 143 #define IDC_PROMPT_ANSWER 1001 #define IDC_PROMPT_TEXT 1002 #define IDC_USERNAME 1003 @@ -29,15 +30,22 @@ #define IDC_OPEN_USING 1018 #define IDC_CHOOSE_APP 1019 #define IDC_APP_NAME 1020 +#define IDC_PRINT_PROGRESS_URL_TXT 1022 +#define IDC_PRINT_PROGRESS_PRG 1023 +#define IDC_PRINT_PROGRESS_PERCENT_TXT 1024 +#define IDC_PRINT_PROGRESS_URL_LABEL_TXT 1025 +#define IDC_PRINT_PROGRESS_TXT 1026 + + // 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_RESOURCE_VALUE 144 #define _APS_NEXT_COMMAND_VALUE 32789 -#define _APS_NEXT_CONTROL_VALUE 1022 +#define _APS_NEXT_CONTROL_VALUE 1027 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif