1 // PrintProgressDialog.cpp : implementation file
6 #include "PrintProgressDialog.h"
7 #include "BrowserView.h"
8 #include "nsIWebBrowser.h"
9 #include "nsIWebBrowserPrint.h"
14 static char THIS_FILE
[] = __FILE__
;
17 /////////////////////////////////////////////////////////////////////////////
18 // CPrintProgressDialog dialog
20 class CDlgPrintListener
: public nsIWebProgressListener
24 CDlgPrintListener(CPrintProgressDialog
* aDlg
);
27 NS_DECL_NSIWEBPROGRESSLISTENER
29 void ClearDlg() { m_PrintDlg
= NULL
; } // weak reference
33 CPrintProgressDialog
* m_PrintDlg
;
36 NS_IMPL_ADDREF(CDlgPrintListener
)
37 NS_IMPL_RELEASE(CDlgPrintListener
)
39 NS_INTERFACE_MAP_BEGIN(CDlgPrintListener
)
40 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIWebProgressListener
)
41 NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener
)
45 CDlgPrintListener::CDlgPrintListener(CPrintProgressDialog
* aDlg
) :
51 /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */
53 CDlgPrintListener::OnStateChange(nsIWebProgress
*aWebProgress
, nsIRequest
*aRequest
, PRUint32 aStateFlags
, nsresult aStatus
)
56 if (aStateFlags
== (nsIWebProgressListener::STATE_START
|nsIWebProgressListener::STATE_IS_DOCUMENT
)) {
57 return m_PrintDlg
->OnStartPrinting();
59 } else if (aStateFlags
== (nsIWebProgressListener::STATE_STOP
|nsIWebProgressListener::STATE_IS_DOCUMENT
)) {
60 return m_PrintDlg
->OnEndPrinting(aStatus
);
66 /* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
68 CDlgPrintListener::OnProgressChange(nsIWebProgress
*aWebProgress
, nsIRequest
*aRequest
, PRInt32 aCurSelfProgress
, PRInt32 aMaxSelfProgress
, PRInt32 aCurTotalProgress
, PRInt32 aMaxTotalProgress
)
71 return m_PrintDlg
->OnProgressPrinting(aCurSelfProgress
, aMaxSelfProgress
);
76 /* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
78 CDlgPrintListener::OnLocationChange(nsIWebProgress
*aWebProgress
, nsIRequest
*aRequest
, nsIURI
*location
)
83 /* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
85 CDlgPrintListener::OnStatusChange(nsIWebProgress
*aWebProgress
, nsIRequest
*aRequest
, nsresult aStatus
, const PRUnichar
*aMessage
)
90 /* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
92 CDlgPrintListener::OnSecurityChange(nsIWebProgress
*aWebProgress
, nsIRequest
*aRequest
, PRUint32 state
)
98 /////////////////////////////////////////////////////////////////////////////
99 // CPrintProgressDialog dialog
102 CPrintProgressDialog::CPrintProgressDialog(nsIWebBrowser
* aWebBrowser
,
103 nsIPrintSettings
* aPrintSettings
,
104 CWnd
* pParent
/*=NULL*/)
105 : CDialog(CPrintProgressDialog::IDD
, pParent
),
106 m_WebBrowser(aWebBrowser
),
107 m_PrintListener(nsnull
),
108 m_PrintSettings(aPrintSettings
),
109 m_InModalMode(PR_FALSE
)
111 //{{AFX_DATA_INIT(CPrintProgressDialog)
112 // NOTE: the ClassWizard will add member initialization here
116 CPrintProgressDialog::~CPrintProgressDialog()
118 CDlgPrintListener
* pl
= (CDlgPrintListener
*)m_PrintListener
.get();
125 void CPrintProgressDialog::DoDataExchange(CDataExchange
* pDX
)
127 CDialog::DoDataExchange(pDX
);
128 //{{AFX_DATA_MAP(CPrintProgressDialog)
129 // NOTE: the ClassWizard will add DDX and DDV calls here
134 BEGIN_MESSAGE_MAP(CPrintProgressDialog
, CDialog
)
135 //{{AFX_MSG_MAP(CPrintProgressDialog)
139 /////////////////////////////////////////////////////////////////////////////
140 // CPrintProgressDialog message handlers
141 static void GetLocalRect(CWnd
* aWnd
, CRect
& aRect
, CWnd
* aParent
)
144 aParent
->GetWindowRect(wr
);
147 aParent
->GetClientRect(cr
);
149 aWnd
->GetWindowRect(aRect
);
151 int borderH
= wr
.Height() - cr
.Height();
152 int borderW
= (wr
.Width() - cr
.Width())/2;
153 aRect
.top
-= wr
.top
+borderH
-borderW
;
154 aRect
.left
-= wr
.left
+borderW
;
155 aRect
.right
-= wr
.left
+borderW
;
156 aRect
.bottom
-= wr
.top
+borderH
-borderW
;
160 BOOL
CPrintProgressDialog::OnInitDialog()
162 CDialog::OnInitDialog();
165 GetClientRect(&clientRect
);
168 GetLocalRect(GetDlgItem(IDC_PPD_DOC_TITLE_STATIC
), titleRect
, this);
171 GetLocalRect(GetDlgItem(IDC_PPD_DOC_TXT
), itemRect
, this);
174 progRect
.left
= titleRect
.left
;
175 progRect
.top
= itemRect
.top
+itemRect
.Height()+5;
176 progRect
.right
= clientRect
.Width()-(2*titleRect
.left
);
177 progRect
.bottom
= progRect
.top
+titleRect
.Height();
180 m_wndProgress
.Create (WS_CHILD
| WS_VISIBLE
, progRect
, this, -1);
181 m_wndProgress
.SetPos (0);
183 return TRUE
; // return TRUE unless you set the focus to a control
184 // EXCEPTION: OCX Property Pages should return FALSE
188 int CPrintProgressDialog::DoModal( )
190 PRBool doModal
= PR_FALSE
;
191 nsCOMPtr
<nsIWebBrowserPrint
> print(do_GetInterface(m_WebBrowser
));
194 m_PrintListener
= new CDlgPrintListener(this); // constructor addrefs
195 if (m_PrintListener
) {
196 // doModal will be set to false if the print job was cancelled
197 nsIWebProgressListener
* wpl
= static_cast<nsIWebProgressListener
*>(m_PrintListener
);
198 doModal
= NS_SUCCEEDED(print
->Print(m_PrintSettings
, wpl
)) == PR_TRUE
;
203 m_InModalMode
= PR_TRUE
;
204 return CDialog::DoModal();
210 /* void OnStartPrinting (); */
212 CPrintProgressDialog::OnStartPrinting()
217 /* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */
219 CPrintProgressDialog::OnProgressPrinting(PRUint32 aProgress
, PRUint32 aProgressMax
)
221 if (m_wndProgress
.m_hWnd
== NULL
) return NS_OK
;
223 // Initialize the progress meter we we get the "zero" progress
224 // which also tells us the max progress
225 if (aProgress
== 0) {
226 CWnd
*pWnd
= GetDlgItem(IDC_PPD_DOC_TXT
);
228 pWnd
->SetWindowText(m_URL
);
230 m_wndProgress
.SetRange(0, aProgressMax
);
231 m_wndProgress
.SetPos(0);
233 m_wndProgress
.SetPos(aProgress
);
234 RedrawWindow(NULL
, NULL
, RDW_INVALIDATE
| RDW_UPDATENOW
);
239 /* void OnEndPrinting (in PRUint32 aStatus); */
241 CPrintProgressDialog::OnEndPrinting(PRUint32 aStatus
)
243 // Here we need to know whether we have gone "modal"
244 // because we could get notified here if the user cancels
245 // before we ever get a chance to go into the modal loop
252 void CPrintProgressDialog::OnCancel()
254 nsCOMPtr
<nsIWebBrowserPrint
> print(do_GetInterface(m_WebBrowser
));
262 void CPrintProgressDialog::SetURI(const char* aTitle
)