Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / embedding / qa / testembed / PrintProgressDialog.cpp
blobbcc60910eed4f928964627cc56e4023f747fb859
1 // PrintProgressDialog.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "testembed.h"
6 #include "PrintProgressDialog.h"
7 #include "BrowserView.h"
8 #include "nsIWebBrowser.h"
9 #include "nsIWebBrowserPrint.h"
11 #ifdef _DEBUG
12 #define new DEBUG_NEW
13 #undef THIS_FILE
14 static char THIS_FILE[] = __FILE__;
15 #endif
17 /////////////////////////////////////////////////////////////////////////////
18 // CPrintProgressDialog dialog
20 class CDlgPrintListener : public nsIWebProgressListener
22 // Construction
23 public:
24 CDlgPrintListener(CPrintProgressDialog* aDlg);
26 NS_DECL_ISUPPORTS
27 NS_DECL_NSIWEBPROGRESSLISTENER
29 void ClearDlg() { m_PrintDlg = NULL; } // weak reference
31 // Implementation
32 protected:
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)
42 NS_INTERFACE_MAP_END
45 CDlgPrintListener::CDlgPrintListener(CPrintProgressDialog* aDlg) :
46 m_PrintDlg(aDlg)
48 //NS_ADDREF_THIS();
51 /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */
52 NS_IMETHODIMP
53 CDlgPrintListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus)
55 if (m_PrintDlg) {
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);
63 return NS_OK;
66 /* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
67 NS_IMETHODIMP
68 CDlgPrintListener::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
70 if (m_PrintDlg) {
71 return m_PrintDlg->OnProgressPrinting(aCurSelfProgress, aMaxSelfProgress);
73 return NS_OK;
76 /* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
77 NS_IMETHODIMP
78 CDlgPrintListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
80 return NS_OK;
83 /* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
84 NS_IMETHODIMP
85 CDlgPrintListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
87 return NS_OK;
90 /* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
91 NS_IMETHODIMP
92 CDlgPrintListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
94 return NS_OK;
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
113 //}}AFX_DATA_INIT
116 CPrintProgressDialog::~CPrintProgressDialog()
118 CDlgPrintListener * pl = (CDlgPrintListener*)m_PrintListener.get();
119 if (pl) {
120 pl->ClearDlg();
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
130 //}}AFX_DATA_MAP
134 BEGIN_MESSAGE_MAP(CPrintProgressDialog, CDialog)
135 //{{AFX_MSG_MAP(CPrintProgressDialog)
136 //}}AFX_MSG_MAP
137 END_MESSAGE_MAP()
139 /////////////////////////////////////////////////////////////////////////////
140 // CPrintProgressDialog message handlers
141 static void GetLocalRect(CWnd * aWnd, CRect& aRect, CWnd * aParent)
143 CRect wr;
144 aParent->GetWindowRect(wr);
146 CRect cr;
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();
164 CRect clientRect;
165 GetClientRect(&clientRect);
167 CRect titleRect;
168 GetLocalRect(GetDlgItem(IDC_PPD_DOC_TITLE_STATIC), titleRect, this);
170 CRect itemRect;
171 GetLocalRect(GetDlgItem(IDC_PPD_DOC_TXT), itemRect, this);
173 CRect progRect;
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));
192 if(print)
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;
202 if (doModal) {
203 m_InModalMode = PR_TRUE;
204 return CDialog::DoModal();
206 return 0;
210 /* void OnStartPrinting (); */
211 NS_IMETHODIMP
212 CPrintProgressDialog::OnStartPrinting()
214 return NS_OK;
217 /* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */
218 NS_IMETHODIMP
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);
227 if(pWnd)
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);
236 return NS_OK;
239 /* void OnEndPrinting (in PRUint32 aStatus); */
240 NS_IMETHODIMP
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
246 if (m_InModalMode) {
247 EndDialog(1);
249 return NS_OK;
252 void CPrintProgressDialog::OnCancel()
254 nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(m_WebBrowser));
255 if (print) {
256 print->Cancel();
259 CDialog::OnCancel();
262 void CPrintProgressDialog::SetURI(const char* aTitle)
264 m_URL = _T(aTitle);