Add the new pluggable dialog work, in build, not used yet

BUg 135441 r=dcone,pink sr=attinasi
This commit is contained in:
rods%netscape.com 2002-05-02 11:50:36 +00:00
Родитель d7baafd64a
Коммит 3696eb1212
49 изменённых файлов: 11467 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,34 @@
#! gmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2000 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Stuart Parmenter <pavlov@netscape.com>
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = src
include $(topsrcdir)/config/rules.mk

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#if TARGET_CARBON
// We're not using the carbon printing session APIs in gfx
#define PM_USE_SESSION_APIS 0
#endif

Просмотреть файл

@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "MacPrefix.h"
#include "printingUIConfig.h"

Просмотреть файл

@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "MacPrefix_debug.h"
#include "printingUIConfig.h"

Просмотреть файл

@ -0,0 +1,6 @@
#!nmake
DEPTH=..\..\..
DIRS=src
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -0,0 +1,54 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
ifdef MOZ_ENABLE_GTK
DIRS += gtk
endif
ifdef MOZ_ENABLE_QT
DIRS += gtk
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
DIRS = os2
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
DIRS = win
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
DIRS = gtk
endif
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
DIRS = mac
endif
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,58 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = embedcomponents
LIBRARY_NAME = printingui_s
REQUIRES = xpcom \
string \
dom \
windowwatcher \
widget \
gfx \
js \
xpconnect \
caps \
content \
necko \
uriloader \
docshell \
webbrwsr \
embed_base \
intl \
$(NULL)
CPPSRCS = \
nsPrintingPromptService.cpp \
nsPrintProgressParams.cpp \
nsPrintProgress.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,57 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..\..
MODULE=printingui
REQUIRES = xpcom \
string \
dom \
widget \
gfx \
js \
xpconnect \
caps \
content \
necko \
uriloader \
docshell \
webBrowser_core \
embed_base \
intl \
windowwatcher \
pref \
$(NULL)
LIBRARY_NAME=printingui_s
CPP_OBJS= \
.\$(OBJDIR)\nsPrintingPromptService.obj \
.\$(OBJDIR)\nsPrintProgressParams.obj \
.\$(OBJDIR)\nsPrintProgress.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

Просмотреть файл

@ -0,0 +1,343 @@
/* -*- 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):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Rod Spears <rods@netscape.com>
*
* 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 "nsPrintProgress.h"
#include "nsIBaseWindow.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
NS_IMPL_THREADSAFE_ADDREF(nsPrintProgress);
NS_IMPL_THREADSAFE_RELEASE(nsPrintProgress);
NS_INTERFACE_MAP_BEGIN(nsPrintProgress)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrintStatusFeedback)
NS_INTERFACE_MAP_ENTRY(nsIPrintProgress)
NS_INTERFACE_MAP_ENTRY(nsIPrintStatusFeedback)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
NS_INTERFACE_MAP_END_THREADSAFE
nsPrintProgress::nsPrintProgress()
{
NS_INIT_ISUPPORTS();
m_closeProgress = PR_FALSE;
m_processCanceled = PR_FALSE;
m_pendingStateFlags = -1;
m_pendingStateValue = 0;
}
nsPrintProgress::~nsPrintProgress()
{
(void)ReleaseListeners();
}
/* void openProgressDialog (in nsIDOMWindowInternal parent, in string dialogURL, in nsISupports parameters); */
NS_IMETHODIMP nsPrintProgress::OpenProgressDialog(nsIDOMWindowInternal *parent,
const char *dialogURL,
nsISupports *parameters,
nsIObserver *openDialogObserver,
PRBool *notifyOnOpen)
{
*notifyOnOpen = PR_FALSE;
nsresult rv = NS_ERROR_FAILURE;
if (m_dialog)
return NS_ERROR_ALREADY_INITIALIZED;
if (!dialogURL || !*dialogURL)
return NS_ERROR_INVALID_ARG;
if (parent)
{
// Set up window.arguments[0]...
nsCOMPtr<nsISupportsArray> array;
rv = NS_NewISupportsArray(getter_AddRefs(array));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsInterfacePointer> ifptr =
do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
ifptr->SetData(NS_STATIC_CAST(nsIPrintProgress*, this));
ifptr->SetDataIID(&NS_GET_IID(nsIPrintProgress));
array->AppendElement(ifptr);
array->AppendElement(parameters);
// Open the dialog.
nsCOMPtr<nsIDOMWindow> newWindow;
rv = parent->OpenDialog(NS_ConvertASCIItoUCS2(dialogURL),
NS_LITERAL_STRING("_blank"),
NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
array, getter_AddRefs(newWindow));
}
return rv;
}
/* void closeProgressDialog (in boolean forceClose); */
NS_IMETHODIMP nsPrintProgress::CloseProgressDialog(PRBool forceClose)
{
m_closeProgress = PR_TRUE;
return OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, forceClose);
}
/* nsIPrompt GetPrompter (); */
NS_IMETHODIMP nsPrintProgress::GetPrompter(nsIPrompt **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
if (! m_closeProgress && m_dialog)
return m_dialog->GetPrompter(_retval);
return NS_ERROR_FAILURE;
}
/* attribute boolean processCanceledByUser; */
NS_IMETHODIMP nsPrintProgress::GetProcessCanceledByUser(PRBool *aProcessCanceledByUser)
{
NS_ENSURE_ARG_POINTER(aProcessCanceledByUser);
*aProcessCanceledByUser = m_processCanceled;
return NS_OK;
}
NS_IMETHODIMP nsPrintProgress::SetProcessCanceledByUser(PRBool aProcessCanceledByUser)
{
m_processCanceled = aProcessCanceledByUser;
OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, PR_FALSE);
return NS_OK;
}
/* void RegisterListener (in nsIWebProgressListener listener); */
NS_IMETHODIMP nsPrintProgress::RegisterListener(nsIWebProgressListener * listener)
{
nsresult rv = NS_OK;
if (!listener) //Nothing to do with a null listener!
return NS_OK;
if (!m_listenerList)
rv = NS_NewISupportsArray(getter_AddRefs(m_listenerList));
if (NS_SUCCEEDED(rv) && m_listenerList)
{
m_listenerList->AppendElement(listener);
if (m_closeProgress || m_processCanceled)
listener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, 0);
else
{
listener->OnStatusChange(nsnull, nsnull, 0, m_pendingStatus.get());
if (m_pendingStateFlags != -1)
listener->OnStateChange(nsnull, nsnull, m_pendingStateFlags, m_pendingStateValue);
}
}
return NS_OK;
}
/* void UnregisterListener (in nsIWebProgressListener listener); */
NS_IMETHODIMP nsPrintProgress::UnregisterListener(nsIWebProgressListener *listener)
{
if (m_listenerList && listener)
m_listenerList->RemoveElement(listener);
return NS_OK;
}
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP nsPrintProgress::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
nsresult rv = NS_OK;
m_pendingStateFlags = aStateFlags;
m_pendingStateValue = aStatus;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
}
}
return rv;
}
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP nsPrintProgress::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
nsresult rv = NS_OK;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
}
return rv;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP nsPrintProgress::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP nsPrintProgress::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
nsresult rv = NS_OK;
if (aMessage && *aMessage)
m_pendingStatus = aMessage;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
}
return rv;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP nsPrintProgress::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsPrintProgress::ReleaseListeners()
{
nsresult rv = NS_OK;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_SUCCEEDED(rv))
for (i = count - 1; i >= 0; i --)
m_listenerList->RemoveElementAt(i);
}
return rv;
}
NS_IMETHODIMP nsPrintProgress::ShowStatusString(const PRUnichar *status)
{
return OnStatusChange(nsnull, nsnull, NS_OK, status);
}
/* void startMeteors (); */
NS_IMETHODIMP nsPrintProgress::StartMeteors()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void stopMeteors (); */
NS_IMETHODIMP nsPrintProgress::StopMeteors()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void showProgress (in long percent); */
NS_IMETHODIMP nsPrintProgress::ShowProgress(PRInt32 percent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void setDocShell (in nsIDocShell shell, in nsIDOMWindowInternal window); */
NS_IMETHODIMP nsPrintProgress::SetDocShell(nsIDocShell *shell, nsIDOMWindowInternal *window)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void closeWindow (); */
NS_IMETHODIMP nsPrintProgress::CloseWindow()
{
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -0,0 +1,74 @@
/* -*- 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):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Rod Spears <rods@netscape.com>
*
* 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 __nsPrintProgress_h
#define __nsPrintProgress_h
#include "nsIPrintProgress.h"
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
#include "nsIDOMWindowInternal.h"
#include "nsIPrintStatusFeedback.h"
#include "nsString.h"
class nsPrintProgress : public nsIPrintProgress, public nsIPrintStatusFeedback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTPROGRESS
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIPRINTSTATUSFEEDBACK
nsPrintProgress();
virtual ~nsPrintProgress();
private:
nsresult ReleaseListeners(void);
PRBool m_closeProgress;
PRBool m_processCanceled;
nsString m_pendingStatus;
PRInt32 m_pendingStateFlags;
PRInt32 m_pendingStateValue;
nsCOMPtr<nsIDOMWindowInternal> m_dialog;
nsCOMPtr<nsISupportsArray> m_listenerList;
};
#endif

Просмотреть файл

@ -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 <rods@netscape.com>
*
* 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;
}

Просмотреть файл

@ -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 <rods@netscape.com>
*
* 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

Просмотреть файл

@ -0,0 +1,325 @@
/* -*- Mode: C++; tab-width: 2; 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 ***** */
#include "nsPrintingPromptService.h"
#include "nsXPComFactory.h"
#include "nsIComponentManager.h"
#include "nsIDialogParamBlock.h"
#include "nsIDOMWindow.h"
#include "nsIServiceManager.h"
#include "nsISupportsUtils.h"
#include "nsISupportsArray.h"
#include "nsString.h"
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
static const char *kPrintDialogURL = "chrome://global/content/printdialog.xul";
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
static const char *kPageSetupDialogURL = "chrome://communicator/content/printPageSetup.xul";
static const char *kPrinterPropertiesURL = "chrome://global/content/printjoboptions.xul";
#define NS_DIALOGPARAMBLOCK_CONTRACTID \
"@mozilla.org/embedcomp/dialogparam;1"
/****************************************************************
************************* ParamBlock ***************************
****************************************************************/
class ParamBlock {
public:
ParamBlock()
{
mBlock = 0;
}
~ParamBlock()
{
NS_IF_RELEASE(mBlock);
}
nsresult Init() {
return nsComponentManager::CreateInstance(
NS_DIALOGPARAMBLOCK_CONTRACTID,
0, NS_GET_IID(nsIDialogParamBlock),
(void**) &mBlock);
}
nsIDialogParamBlock * operator->() const { return mBlock; }
operator nsIDialogParamBlock * const () { return mBlock; }
private:
nsIDialogParamBlock *mBlock;
};
/****************************************************************
***************** nsPrintingPromptService **********************
****************************************************************/
NS_IMPL_ISUPPORTS2(nsPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener)
nsPrintingPromptService::nsPrintingPromptService()
{
NS_INIT_REFCNT();
}
nsPrintingPromptService::~nsPrintingPromptService()
{
}
nsresult
nsPrintingPromptService::Init()
{
nsresult rv;
mWatcher = do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv);
return rv;
}
/* void showPrintDialog (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings)
{
NS_ENSURE_ARG(webBrowserPrint);
NS_ENSURE_ARG(printSettings);
ParamBlock block;
nsresult rv = block.Init();
if (NS_FAILED(rv))
return rv;
block->SetInt(0, 0);
return DoDialog(parent, block, webBrowserPrint, printSettings, kPrintDialogURL);
}
/* void showProgress (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings, out nsIWebProgressListener webProgressListener); */
NS_IMETHODIMP
nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
nsIWebBrowserPrint* webBrowserPrint, // ok to be null
nsIPrintSettings* printSettings, // ok to be null
nsIObserver* openDialogObserver, // ok to be null
nsIWebProgressListener** webProgressListener,
nsIPrintProgressParams** printProgressParams,
PRBool* notifyOnOpen)
{
NS_ENSURE_ARG(webProgressListener);
NS_ENSURE_ARG(printProgressParams);
NS_ENSURE_ARG(notifyOnOpen);
nsPrintProgress* prtProgress = new nsPrintProgress();
nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrintProgress));
NS_ENSURE_SUCCESS(rv, rv);
rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mWebProgressListener));
NS_ENSURE_SUCCESS(rv, rv);
nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams();
rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams);
NS_ENSURE_SUCCESS(rv, rv);
if (printProgressParams)
{
nsCOMPtr<nsIDOMWindowInternal> parentDOMIntl(do_QueryInterface(parent));
if (mWatcher && !parentDOMIntl)
{
nsCOMPtr<nsIDOMWindow> active;
mWatcher->GetActiveWindow(getter_AddRefs(active));
parentDOMIntl = do_QueryInterface(active);
}
if (parentDOMIntl)
{
mPrintProgress->OpenProgressDialog(parentDOMIntl, kPrintProgressDialogURL, *printProgressParams, openDialogObserver, notifyOnOpen);
}
}
*webProgressListener = NS_STATIC_CAST(nsIWebProgressListener*, this);
NS_ADDREF(*webProgressListener);
return rv;
}
/* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings)
{
NS_ENSURE_ARG(printSettings);
ParamBlock block;
nsresult rv = block.Init();
if (NS_FAILED(rv))
return rv;
block->SetInt(0, 0);
return DoDialog(parent, block, nsnull, printSettings, kPageSetupDialogURL);
}
/* void showPrinterProperties (in nsIDOMWindow parent, in wstring printerName, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPrinterProperties(nsIDOMWindow *parent, const PRUnichar *printerName, nsIPrintSettings *printSettings)
{
/* fixme: We simply ignore the |aPrinter| argument here
* We should get the supported printer attributes from the printer and
* populate the print job options dialog with these data instead of using
* the "default set" here.
* However, this requires changes on all platforms and is another big chunk
* of patches ... ;-(
*/
NS_ENSURE_ARG(printerName);
NS_ENSURE_ARG(printSettings);
ParamBlock block;
nsresult rv = block.Init();
if (NS_FAILED(rv))
return rv;
block->SetInt(0, 0);
return DoDialog(parent, block, nsnull, printSettings, kPrinterPropertiesURL);
}
nsresult
nsPrintingPromptService::DoDialog(nsIDOMWindow *aParent,
nsIDialogParamBlock *aParamBlock,
nsIWebBrowserPrint *aWebBrowserPrint,
nsIPrintSettings* aPS,
const char *aChromeURL)
{
NS_ENSURE_ARG(aParamBlock);
NS_ENSURE_ARG(aPS);
NS_ENSURE_ARG(aChromeURL);
if (!mWatcher)
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
// get a parent, if at all possible
// (though we'd rather this didn't fail, it's OK if it does. so there's
// no failure or null check.)
nsCOMPtr<nsIDOMWindow> activeParent; // retain ownership for method lifetime
if (!aParent)
{
mWatcher->GetActiveWindow(getter_AddRefs(activeParent));
aParent = activeParent;
}
// create a nsISupportsArray of the parameters
// being passed to the window
nsCOMPtr<nsISupportsArray> array;
NS_NewISupportsArray(getter_AddRefs(array));
if (!array) return NS_ERROR_FAILURE;
nsCOMPtr<nsISupports> psSupports(do_QueryInterface(aPS));
NS_ASSERTION(psSupports, "PrintSettings must be a supports");
array->AppendElement(psSupports);
if (aWebBrowserPrint) {
nsCOMPtr<nsISupports> wbpSupports(do_QueryInterface(aWebBrowserPrint));
NS_ASSERTION(wbpSupports, "nsIWebBrowserPrint must be a supports");
array->AppendElement(wbpSupports);
}
nsCOMPtr<nsISupports> blkSupps(do_QueryInterface(aParamBlock));
NS_ASSERTION(blkSupps, "IOBlk must be a supports");
array->AppendElement(blkSupps);
nsCOMPtr<nsISupports> arguments(do_QueryInterface(array));
NS_ASSERTION(array, "array must be a supports");
nsCOMPtr<nsIDOMWindow> dialog;
rv = mWatcher->OpenWindow(aParent, aChromeURL, "_blank",
"centerscreen,chrome,modal,titlebar", arguments,
getter_AddRefs(dialog));
// if aWebBrowserPrint is not null then we are printing
// so we want to pass back NS_ERROR_ABORT on cancel
if (NS_SUCCEEDED(rv) && aWebBrowserPrint)
{
PRInt32 status;
aParamBlock->GetInt(0, &status);
return status == 0?NS_ERROR_ABORT:NS_OK;
}
return rv;
}
//////////////////////////////////////////////////////////////////////
// nsIWebProgressListener
//////////////////////////////////////////////////////////////////////
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP
nsPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
if (aStateFlags & STATE_STOP) {
mWebProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
mPrintProgress->CloseProgressDialog(PR_TRUE);
mPrintProgress = nsnull;
}
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
nsPrintingPromptService::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
return mWebProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP
nsPrintingPromptService::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return mWebProgressListener->OnLocationChange(aWebProgress, aRequest, location);
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP
nsPrintingPromptService::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
return mWebProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP
nsPrintingPromptService::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return mWebProgressListener->OnSecurityChange(aWebProgress, aRequest, state);
}

Просмотреть файл

@ -0,0 +1,89 @@
/* -*- 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 Communicator client 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 __nsPrintingPromptService_h
#define __nsPrintingPromptService_h
// {E042570C-62DE-4bb6-A6E0-798E3C07B4DF}
#define NS_PRINTINGPROMPTSERVICE_CID \
{0xe042570c, 0x62de, 0x4bb6, { 0xa6, 0xe0, 0x79, 0x8e, 0x3c, 0x7, 0xb4, 0xdf}}
#define NS_PRINTINGPROMPTSERVICE_CONTRACTID \
"@mozilla.org/embedcomp/printingprompt-service;1"
#include "nsCOMPtr.h"
#include "nsIPrintingPromptService.h"
#include "nsPIPromptService.h"
#include "nsIWindowWatcher.h"
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
#include "nsIWebProgressListener.h"
class nsIDOMWindow;
class nsIDialogParamBlock;
class nsPrintingPromptService: public nsIPrintingPromptService,
public nsIWebProgressListener
{
public:
nsPrintingPromptService();
virtual ~nsPrintingPromptService();
nsresult Init();
NS_DECL_NSIPRINTINGPROMPTSERVICE
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_ISUPPORTS
private:
nsresult DoDialog(nsIDOMWindow *aParent,
nsIDialogParamBlock *aParamBlock,
nsIWebBrowserPrint *aWebBrowserPrint,
nsIPrintSettings* aPS,
const char *aChromeURL);
nsCOMPtr<nsIWindowWatcher> mWatcher;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMPtr<nsIWebProgressListener> mWebProgressListener;
};
#endif

Просмотреть файл

@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the guts of the find algorithm.
*
* The Initial Developer of the Original Code is Akkana Peck.
*
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <Types.r>
resource 'DITL' (128) {
{ /* array DITLarray: 6 elements */
/* [1] */
{16, 32, 33, 168},
CheckBox {
enabled,
"Print Selection Only"
},
/* [2] */
{68, 32, 86, 186},
RadioButton {
enabled,
"As laid out on screen"
},
/* [3] */
{87, 32, 104, 189},
RadioButton {
enabled,
"The selected frame"
},
/* [4] */
{105, 32, 123, 202},
RadioButton {
enabled,
"Each frame separately"
},
/* [5] */
{54, 24, 131, 210},
UserItem {
disabled
},
/* [6] */
{45, 34, 62, 118},
StaticText {
disabled,
"Print Frames"
}
}
};

Просмотреть файл

@ -0,0 +1,343 @@
/* -*- 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):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Rod Spears <rods@netscape.com>
*
* 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 "nsPrintProgress.h"
#include "nsIBaseWindow.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
NS_IMPL_THREADSAFE_ADDREF(nsPrintProgress);
NS_IMPL_THREADSAFE_RELEASE(nsPrintProgress);
NS_INTERFACE_MAP_BEGIN(nsPrintProgress)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrintStatusFeedback)
NS_INTERFACE_MAP_ENTRY(nsIPrintProgress)
NS_INTERFACE_MAP_ENTRY(nsIPrintStatusFeedback)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
NS_INTERFACE_MAP_END_THREADSAFE
nsPrintProgress::nsPrintProgress()
{
NS_INIT_ISUPPORTS();
m_closeProgress = PR_FALSE;
m_processCanceled = PR_FALSE;
m_pendingStateFlags = -1;
m_pendingStateValue = 0;
}
nsPrintProgress::~nsPrintProgress()
{
(void)ReleaseListeners();
}
/* void openProgressDialog (in nsIDOMWindowInternal parent, in string dialogURL, in nsISupports parameters); */
NS_IMETHODIMP nsPrintProgress::OpenProgressDialog(nsIDOMWindowInternal *parent,
const char *dialogURL,
nsISupports *parameters,
nsIObserver *openDialogObserver,
PRBool *notifyOnOpen)
{
*notifyOnOpen = PR_FALSE;
nsresult rv = NS_ERROR_FAILURE;
if (m_dialog)
return NS_ERROR_ALREADY_INITIALIZED;
if (!dialogURL || !*dialogURL)
return NS_ERROR_INVALID_ARG;
if (parent)
{
// Set up window.arguments[0]...
nsCOMPtr<nsISupportsArray> array;
rv = NS_NewISupportsArray(getter_AddRefs(array));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsInterfacePointer> ifptr =
do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
ifptr->SetData(NS_STATIC_CAST(nsIPrintProgress*, this));
ifptr->SetDataIID(&NS_GET_IID(nsIPrintProgress));
array->AppendElement(ifptr);
array->AppendElement(parameters);
// Open the dialog.
nsCOMPtr<nsIDOMWindow> newWindow;
rv = parent->OpenDialog(NS_ConvertASCIItoUCS2(dialogURL),
NS_LITERAL_STRING("_blank"),
NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
array, getter_AddRefs(newWindow));
}
return rv;
}
/* void closeProgressDialog (in boolean forceClose); */
NS_IMETHODIMP nsPrintProgress::CloseProgressDialog(PRBool forceClose)
{
m_closeProgress = PR_TRUE;
return OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, forceClose);
}
/* nsIPrompt GetPrompter (); */
NS_IMETHODIMP nsPrintProgress::GetPrompter(nsIPrompt **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
if (! m_closeProgress && m_dialog)
return m_dialog->GetPrompter(_retval);
return NS_ERROR_FAILURE;
}
/* attribute boolean processCanceledByUser; */
NS_IMETHODIMP nsPrintProgress::GetProcessCanceledByUser(PRBool *aProcessCanceledByUser)
{
NS_ENSURE_ARG_POINTER(aProcessCanceledByUser);
*aProcessCanceledByUser = m_processCanceled;
return NS_OK;
}
NS_IMETHODIMP nsPrintProgress::SetProcessCanceledByUser(PRBool aProcessCanceledByUser)
{
m_processCanceled = aProcessCanceledByUser;
OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, PR_FALSE);
return NS_OK;
}
/* void RegisterListener (in nsIWebProgressListener listener); */
NS_IMETHODIMP nsPrintProgress::RegisterListener(nsIWebProgressListener * listener)
{
nsresult rv = NS_OK;
if (!listener) //Nothing to do with a null listener!
return NS_OK;
if (!m_listenerList)
rv = NS_NewISupportsArray(getter_AddRefs(m_listenerList));
if (NS_SUCCEEDED(rv) && m_listenerList)
{
m_listenerList->AppendElement(listener);
if (m_closeProgress || m_processCanceled)
listener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, 0);
else
{
listener->OnStatusChange(nsnull, nsnull, 0, m_pendingStatus.get());
if (m_pendingStateFlags != -1)
listener->OnStateChange(nsnull, nsnull, m_pendingStateFlags, m_pendingStateValue);
}
}
return NS_OK;
}
/* void UnregisterListener (in nsIWebProgressListener listener); */
NS_IMETHODIMP nsPrintProgress::UnregisterListener(nsIWebProgressListener *listener)
{
if (m_listenerList && listener)
m_listenerList->RemoveElement(listener);
return NS_OK;
}
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP nsPrintProgress::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
nsresult rv = NS_OK;
m_pendingStateFlags = aStateFlags;
m_pendingStateValue = aStatus;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
}
}
return rv;
}
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP nsPrintProgress::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
nsresult rv = NS_OK;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
}
return rv;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP nsPrintProgress::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP nsPrintProgress::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
nsresult rv = NS_OK;
if (aMessage && *aMessage)
m_pendingStatus = aMessage;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
}
return rv;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP nsPrintProgress::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsPrintProgress::ReleaseListeners()
{
nsresult rv = NS_OK;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_SUCCEEDED(rv))
for (i = count - 1; i >= 0; i --)
m_listenerList->RemoveElementAt(i);
}
return rv;
}
NS_IMETHODIMP nsPrintProgress::ShowStatusString(const PRUnichar *status)
{
return OnStatusChange(nsnull, nsnull, NS_OK, status);
}
/* void startMeteors (); */
NS_IMETHODIMP nsPrintProgress::StartMeteors()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void stopMeteors (); */
NS_IMETHODIMP nsPrintProgress::StopMeteors()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void showProgress (in long percent); */
NS_IMETHODIMP nsPrintProgress::ShowProgress(PRInt32 percent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void setDocShell (in nsIDocShell shell, in nsIDOMWindowInternal window); */
NS_IMETHODIMP nsPrintProgress::SetDocShell(nsIDocShell *shell, nsIDOMWindowInternal *window)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void closeWindow (); */
NS_IMETHODIMP nsPrintProgress::CloseWindow()
{
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -0,0 +1,74 @@
/* -*- 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):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Rod Spears <rods@netscape.com>
*
* 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 __nsPrintProgress_h
#define __nsPrintProgress_h
#include "nsIPrintProgress.h"
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
#include "nsIDOMWindowInternal.h"
#include "nsIPrintStatusFeedback.h"
#include "nsString.h"
class nsPrintProgress : public nsIPrintProgress, public nsIPrintStatusFeedback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTPROGRESS
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIPRINTSTATUSFEEDBACK
nsPrintProgress();
virtual ~nsPrintProgress();
private:
nsresult ReleaseListeners(void);
PRBool m_closeProgress;
PRBool m_processCanceled;
nsString m_pendingStatus;
PRInt32 m_pendingStateFlags;
PRInt32 m_pendingStateValue;
nsCOMPtr<nsIDOMWindowInternal> m_dialog;
nsCOMPtr<nsISupportsArray> m_listenerList;
};
#endif

Просмотреть файл

@ -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 <rods@netscape.com>
*
* 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;
}

Просмотреть файл

@ -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 <rods@netscape.com>
*
* 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

Просмотреть файл

@ -0,0 +1,541 @@
/* -*- Mode: C++; tab-width: 4; 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 <rods@netscape.com>
* Don Cone <dcone@netscape.com>
* Conrad Carlen <ccarlen@netscape.com>
*
* 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 "nsPrintingPromptService.h"
#include "nsCOMPtr.h"
#include "nsIPrintingPromptService.h"
#include "nsIFactory.h"
#include "nsIDOMWindow.h"
#include "nsReadableUtils.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIServiceManager.h"
#include "nsIWebBrowserChrome.h"
#include "nsIWindowWatcher.h"
#include "nsIPrintSettingsMac.h"
#include "nsComponentResContext.h"
#include "nsWatchTask.h"
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
#include "nsIWebProgressListener.h"
// OS Includes
#include <Printing.h>
#include <Dialogs.h>
#include <Appearance.h>
#include <Resources.h>
// Constants
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
//-----------------------------------------------------------------------------
// Dialog Extension Code
//-----------------------------------------------------------------------------
// Types and Defines
// items to support the additional items for the dialog
#define DITL_ADDITIONS 128
enum {
ePrintSelectionCheckboxID = 1,
ePrintFrameAsIsCheckboxID,
ePrintSelectedFrameCheckboxID,
ePrintAllFramesCheckboxID,
eDrawFrameID
};
typedef struct dialog_item_struct {
Handle handle; // handle or procedure pointer for this item */
Rect bounds; // display rectangle for this item */
char type; // item type - 1 */
char data[1]; // length byte of data */
} DialogItem, *DialogItemPtr, **DialogItemHandle;
typedef struct append_item_list_struct {
short max_index; // number of items - 1
DialogItem items[1]; // first item in the array
} ItemList, *ItemListPtr, **ItemListHandle;
// Static Variables - used by the dialog callbacks - no choice but globals
//static pascal TPPrDlg MyJobDlgInit(THPrint); // Our extention to PrJobInit
static TPPrDlg gPrtJobDialog; // pointer to job dialog
static long prFirstItem; // our first item in the extended dialog
static PItemUPP prPItemProc; // store the old item handler here
static PRBool gPrintSelection;
static PItemUPP gPrtJobDialogItemProc;
static UserItemUPP gDrawListUPP = nsnull;
static nsIPrintSettings *gPrintSettings = nsnull;
// Routines
/** -------------------------------------------------------
* this is a drawing procedure for the user item.. this draws a box around the frameset radio buttons
* @update dc 12/02/98
*/
static pascal void MyBBoxDraw(WindowPtr theWindow, short aItemNo)
{
short itemType;
Rect itemBox;
Handle itemH;
::GetDialogItem((DialogPtr)gPrtJobDialog, prFirstItem + eDrawFrameID-1, &itemType, &itemH, &itemBox);
// use appearance if possible
if ((long)DrawThemeSecondaryGroup != kUnresolvedCFragSymbolAddress)
::DrawThemeSecondaryGroup(&itemBox, kThemeStateActive);
else
::FrameRect(&itemBox);
}
/** -------------------------------------------------------
* this is the dialog hook, takes care of setting the dialog items
* @update dc 12/02/98
*/
static pascal void MyJobItems(DialogPtr aDialog, short aItemNo)
{
short myItem, firstItem, i, itemType;
short value;
Rect itemBox;
Handle itemH;
firstItem = prFirstItem;
myItem = aItemNo-firstItem+1;
if (myItem>0) {
switch (myItem) {
case ePrintSelectionCheckboxID:
::GetDialogItem(aDialog, firstItem, &itemType, &itemH, &itemBox);
gPrintSelection = !gPrintSelection;
::SetControlValue((ControlHandle)itemH, gPrintSelection);
break;
case ePrintFrameAsIsCheckboxID:
case ePrintSelectedFrameCheckboxID:
case ePrintAllFramesCheckboxID:
for (i=ePrintFrameAsIsCheckboxID; i<=ePrintAllFramesCheckboxID; i++){
::GetDialogItem(aDialog, firstItem+i-1, &itemType, &itemH, &itemBox);
::SetControlValue((ControlHandle)itemH, i==myItem);
}
break;
default:
break;
}
} else {
// chain to standard Item handler
CallPItemProc(prPItemProc, aDialog, aItemNo);
if (((TPPrDlg)aDialog)->fDone)
{
//nsCOMPtr<nsIPrintOptions> printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1");
// cleanup and set the print options to what we want
if (gPrintSettings)
{
// print selection
::GetDialogItem(aDialog, firstItem+ePrintSelectionCheckboxID-1, &itemType, &itemH, &itemBox);
value = ::GetControlValue((ControlHandle)itemH);
if (1==value){
gPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSelection);
} else {
gPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages);
}
// print frames as is
::GetDialogItem(aDialog, firstItem+ePrintFrameAsIsCheckboxID-1, &itemType, &itemH, &itemBox);
value = ::GetControlValue((ControlHandle)itemH);
if (1==value){
gPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs);
}
// selected frame
::GetDialogItem(aDialog, firstItem+ePrintSelectedFrameCheckboxID-1, &itemType, &itemH, &itemBox);
value = ::GetControlValue((ControlHandle)itemH);
if (1==value){
gPrintSettings->SetPrintFrameType(nsIPrintSettings::kSelectedFrame);
}
// print all frames
::GetDialogItem(aDialog, firstItem+ePrintAllFramesCheckboxID-1, &itemType, &itemH, &itemBox);
value = ::GetControlValue((ControlHandle)itemH);
if (1==value){
gPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep);
}
}
}
}
}
/** -------------------------------------------------------
* Append DITL items to the dialog
* @update dc 05/04/2001
*/
static PRInt32 AppendToDialog(TPPrDlg aDialog, PRInt32 aDITLID)
{
short firstItem;
ItemListHandle myAppendDITLH;
ItemListHandle dlg_Item_List;
dlg_Item_List = (ItemListHandle)((DialogPeek)aDialog)->items;
firstItem = (**dlg_Item_List).max_index+2;
nsComponentResourceContext resContext;
if (resContext.BecomeCurrent()) { // destructor restores
myAppendDITLH = (ItemListHandle)::GetResource('DITL', aDITLID);
NS_ASSERTION(myAppendDITLH, "Failed to get DITL items");
if (myAppendDITLH) {
::AppendDITL((DialogPtr)aDialog, (Handle)myAppendDITLH, appendDITLBottom);
::ReleaseResource((Handle) myAppendDITLH);
}
}
return firstItem;
}
/** -------------------------------------------------------
* Initialize the print dialogs additional items
* @update dc 05/04/2001
*/
static pascal TPPrDlg MyJobDlgInit(THPrint aHPrint)
{
PRInt32 i;
short itemType;
Handle itemH;
Rect itemBox;
PRBool isOn;
PRInt16 howToEnableFrameUI = nsIPrintSettings::kFrameEnableNone;
prFirstItem = AppendToDialog(gPrtJobDialog, DITL_ADDITIONS);
if (gPrintSettings) {
gPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn);
gPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI);
}
::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+ePrintSelectionCheckboxID-1, &itemType, &itemH, &itemBox);
if ( isOn ) {
::HiliteControl((ControlHandle)itemH, 0);
} else {
::HiliteControl((ControlHandle)itemH, 255);
}
gPrintSelection = PR_FALSE;
::SetControlValue((ControlHandle) itemH, gPrintSelection);
if (howToEnableFrameUI == nsIPrintSettings::kFrameEnableAll) {
for (i = ePrintFrameAsIsCheckboxID; i <= ePrintAllFramesCheckboxID; i++){
::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+i-1, &itemType, &itemH, &itemBox);
::SetControlValue((ControlHandle) itemH, (i==4));
::HiliteControl((ControlHandle)itemH, 0);
}
}
else if (howToEnableFrameUI == nsIPrintSettings::kFrameEnableAsIsAndEach) {
for (i = ePrintFrameAsIsCheckboxID; i <= ePrintAllFramesCheckboxID; i++){
::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+i-1, &itemType, &itemH, &itemBox);
::SetControlValue((ControlHandle) itemH, (i==4));
if ( i == 3){
::HiliteControl((ControlHandle)itemH, 255);
}
}
}
else {
for (i = ePrintFrameAsIsCheckboxID; i <= ePrintAllFramesCheckboxID; i++){
::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+i-1, &itemType, &itemH, &itemBox);
::SetControlValue((ControlHandle) itemH, FALSE);
::HiliteControl((ControlHandle)itemH, 255);
}
}
// attach our handler
prPItemProc = gPrtJobDialog->pItemProc;
gPrtJobDialog->pItemProc = gPrtJobDialogItemProc = NewPItemUPP(MyJobItems);
// attach a draw routine
gDrawListUPP = NewUserItemProc(MyBBoxDraw);
::GetDialogItem((DialogPtr)gPrtJobDialog, prFirstItem+eDrawFrameID-1, &itemType, &itemH, &itemBox);
::SetDialogItem((DialogPtr)gPrtJobDialog, prFirstItem+eDrawFrameID-1, itemType, (Handle)gDrawListUPP, &itemBox);
return gPrtJobDialog;
}
//*****************************************************************************
// nsPrintingPromptService
//*****************************************************************************
NS_IMPL_ISUPPORTS2(nsPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener)
nsPrintingPromptService::nsPrintingPromptService() :
mWatcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"))
{
NS_INIT_REFCNT();
}
nsPrintingPromptService::~nsPrintingPromptService()
{
}
nsresult nsPrintingPromptService::Init()
{
return NS_OK;
}
//*****************************************************************************
// nsPrintingPromptService::nsIPrintingPromptService
//*****************************************************************************
NS_IMETHODIMP
nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings)
{
THPrint printRecH = nsnull; // local copy of nsIPrintSettingsMac's data
GrafPtr oldport;
PDlgInitUPP theInitProcPtr;
gPrintSettings = printSettings;
::GetPort(&oldport);
nsresult rv;
nsCOMPtr<nsIPrintSettingsMac> printSettingsMac(do_QueryInterface(printSettings));
if (!printSettingsMac)
return NS_ERROR_NO_INTERFACE;
theInitProcPtr = NewPDlgInitProc(MyJobDlgInit);
if (!theInitProcPtr)
return NS_ERROR_FAILURE;
// Get the print record from the settings
rv = printSettingsMac->GetTHPrint(&printRecH);
if (NS_FAILED(rv))
return rv;
// open the printing manager
::PrOpen();
if (::PrError() != noErr) {
::DisposeHandle((Handle)printRecH);
return NS_ERROR_FAILURE;
}
// make sure the print record is valid
::PrValidate(printRecH);
if (::PrError() != noErr) {
::DisposeHandle((Handle)printRecH);
::PrClose();
return NS_ERROR_FAILURE;
}
// get pointer to invisible job dialog box
gPrtJobDialog = ::PrJobInit(printRecH);
if (::PrError() != noErr) {
::DisposeHandle((Handle)printRecH);
::PrClose();
return NS_ERROR_FAILURE;
}
// create a UUP for the dialog init procedure
theInitProcPtr = NewPDlgInitProc(MyJobDlgInit);
if (!theInitProcPtr)
return NS_ERROR_FAILURE;
nsWatchTask::GetTask().Suspend();
::InitCursor();
// put up the print dialog
if (::PrDlgMain(printRecH, theInitProcPtr))
{
// have the print record
rv = NS_OK;
printSettingsMac->SetTHPrint(printRecH);
}
else
{
// don't print
::SetPort(oldport);
rv = NS_ERROR_ABORT;
}
::DisposeHandle((Handle)printRecH);
// clean up our dialog routines
DisposePItemUPP(gPrtJobDialogItemProc);
gPrtJobDialogItemProc = nsnull;
DisposePItemUPP(theInitProcPtr);
DisposePItemUPP(gDrawListUPP);
gDrawListUPP = nsnull;
nsWatchTask::GetTask().Resume();
return rv;
}
NS_IMETHODIMP
nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
nsIWebBrowserPrint* webBrowserPrint, // ok to be null
nsIPrintSettings* printSettings, // ok to be null
nsIObserver* openDialogObserver, // ok to be null
nsIWebProgressListener** webProgressListener,
nsIPrintProgressParams** printProgressParams,
PRBool* notifyOnOpen)
{
NS_ENSURE_ARG(webProgressListener);
NS_ENSURE_ARG(printProgressParams);
NS_ENSURE_ARG(notifyOnOpen);
nsPrintProgress* prtProgress = new nsPrintProgress();
nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrintProgress));
NS_ENSURE_SUCCESS(rv, rv);
rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mWebProgressListener));
NS_ENSURE_SUCCESS(rv, rv);
nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams();
rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams);
NS_ENSURE_SUCCESS(rv, rv);
if (printProgressParams)
{
if (mWatcher)
{
nsCOMPtr<nsIDOMWindow> active;
mWatcher->GetActiveWindow(getter_AddRefs(active));
nsCOMPtr<nsIDOMWindowInternal> parent(do_QueryInterface(active));
mPrintProgress->OpenProgressDialog(parent, kPrintProgressDialogURL, *printProgressParams, openDialogObserver, notifyOnOpen);
}
}
*webProgressListener = NS_STATIC_CAST(nsIWebProgressListener*, this);
NS_ADDREF(*webProgressListener);
return rv;
}
NS_IMETHODIMP
nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings)
{
nsCOMPtr<nsIPrintSettingsMac> printSettingsMac(do_QueryInterface(printSettings));
if (!printSettingsMac)
return NS_ERROR_NO_INTERFACE;
// open the printing manager
::PrOpen();
if(::PrError() != noErr)
return NS_ERROR_FAILURE;
THPrint printRecH;
nsresult rv;
rv = printSettingsMac->GetTHPrint(&printRecH);
if (NS_FAILED(rv))
return rv;
::PrValidate(printRecH);
NS_ASSERTION(::PrError() == noErr, "PrValidate error");
nsWatchTask::GetTask().Suspend();
::InitCursor();
Boolean dialogOK = ::PrStlDialog(printRecH); // open up and process the style record
nsWatchTask::GetTask().Resume();
OSErr err = ::PrError();
::PrClose();
if (dialogOK)
rv = printSettingsMac->SetTHPrint(printRecH);
if (err != noErr)
return NS_ERROR_FAILURE;
if (!dialogOK)
return NS_ERROR_ABORT;
return rv;
}
NS_IMETHODIMP
nsPrintingPromptService::ShowPrinterProperties(nsIDOMWindow *parent, const PRUnichar *printerName, nsIPrintSettings *printSettings)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//*****************************************************************************
// nsPrintingPromptService::nsIWebProgressListener
//*****************************************************************************
NS_IMETHODIMP
nsPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
if (aStateFlags & STATE_STOP)
{
mWebProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
mPrintProgress->CloseProgressDialog(PR_TRUE);
mPrintProgress = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP
nsPrintingPromptService::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
return mWebProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
NS_IMETHODIMP
nsPrintingPromptService::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return mWebProgressListener->OnLocationChange(aWebProgress, aRequest, location);
}
NS_IMETHODIMP
nsPrintingPromptService::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
return mWebProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
NS_IMETHODIMP
nsPrintingPromptService::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return mWebProgressListener->OnSecurityChange(aWebProgress, aRequest, state);
}

Просмотреть файл

@ -0,0 +1,81 @@
/* -*- 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 Communicator client 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 __nsPrintingPromptService_h
#define __nsPrintingPromptService_h
// {E042570C-62DE-4bb6-A6E0-798E3C07B4DF}
#define NS_PRINTINGPROMPTSERVICE_CID \
{0xe042570c, 0x62de, 0x4bb6, { 0xa6, 0xe0, 0x79, 0x8e, 0x3c, 0x7, 0xb4, 0xdf}}
#define NS_PRINTINGPROMPTSERVICE_CONTRACTID \
"@mozilla.org/embedcomp/printingprompt-service;1"
#include "nsCOMPtr.h"
#include "nsIPrintingPromptService.h"
#include "nsPIPromptService.h"
#include "nsIWindowWatcher.h"
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
#include "nsIWebProgressListener.h"
class nsIDOMWindow;
class nsIDialogParamBlock;
class nsPrintingPromptService: public nsIPrintingPromptService,
public nsIWebProgressListener
{
public:
nsPrintingPromptService();
virtual ~nsPrintingPromptService();
nsresult Init();
NS_DECL_NSIPRINTINGPROMPTSERVICE
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_ISUPPORTS
private:
nsCOMPtr<nsIWindowWatcher> mWatcher;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMPtr<nsIWebProgressListener> mWebProgressListener;
};
#endif

Просмотреть файл

@ -0,0 +1,396 @@
/* -*- Mode: C++; tab-width: 4; 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 <rods@netscape.com>
* Conrad Carlen <ccarlen@netscape.com>
*
* 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 "nsPrintingPromptService.h"
#include "nsCOMPtr.h"
#include "nsIPrintingPromptService.h"
#include "nsIFactory.h"
#include "nsIDOMWindow.h"
#include "nsReadableUtils.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIServiceManager.h"
#include "nsIWebBrowserChrome.h"
#include "nsIWindowWatcher.h"
#include "nsIPrintSettingsX.h"
#include "nsIDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsPDECommon.h"
#ifndef XP_MACOSX
#include "nsILocalFIleMac.h"
#endif
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
#include "nsIWebProgressListener.h"
// OS includes
#include <PMApplication.h>
#include <CFPlugIn.h>
#include <Gestalt.h>
// Constants
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
// Globals
static CFPlugInRef gPDEPlugIn = nsnull;
//-----------------------------------------------------------------------------
// Static Helpers
//-----------------------------------------------------------------------------
static CFPlugInRef LoadPDEPlugIn()
{
#ifndef XP_MACOSX
if (!gPDEPlugIn) {
nsresult rv;
nsCOMPtr<nsIProperties> dirService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
if (!dirService)
return nsnull;
nsCOMPtr<nsILocalFileMac> pluginDir;
rv = dirService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFileMac), getter_AddRefs(pluginDir));
if (NS_FAILED(rv))
return nsnull;
pluginDir->Append(NS_LITERAL_CSTRING"Essential Files"));
pluginDir->Append(NS_LITERAL_CSTRING"PrintDialogPDE.plugin"));
FSSpec pluginSpec;
rv = pluginDir->GetFSSpec(&pluginSpec);
if (NS_FAILED(rv))
return nsnull;
OSErr err;
FSRef pluginFSRef;
char pathBuf[512];
err = ::FSpMakeFSRef(&pluginSpec, &pluginFSRef);
if (err)
return nsnull;
err = ::FSRefMakePath(&pluginFSRef, (UInt8 *)pathBuf, sizeof(pathBuf)-1);
if (err)
return nsnull;
CFStringRef pathRef = ::CFStringCreateWithCString(NULL, pathBuf, kCFStringEncodingUTF8);
if (!pathRef)
return nsnull;
CFURLRef url = ::CFURLCreateWithFileSystemPath(NULL, pathRef, kCFURLPOSIXPathStyle, TRUE);
if (url)
gPDEPlugIn = ::CFPlugInCreate(NULL, url);
::CFRelease(pathRef);
::CFRelease(url);
}
#endif
return gPDEPlugIn;
}
//*****************************************************************************
// nsPrintingPromptService
//*****************************************************************************
NS_IMPL_ISUPPORTS2(nsPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener)
nsPrintingPromptService::nsPrintingPromptService() :
mWatcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"))
{
NS_INIT_REFCNT();
}
nsPrintingPromptService::~nsPrintingPromptService()
{
}
nsresult nsPrintingPromptService::Init()
{
return NS_OK;
}
//*****************************************************************************
// nsPrintingPromptService::nsIPrintingPromptService
//*****************************************************************************
NS_IMETHODIMP
nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings)
{
nsresult rv;
OSStatus status;
nsCOMPtr<nsIPrintSettingsX> printSettingsX(do_QueryInterface(printSettings));
if (!printSettingsX)
return NS_ERROR_NO_INTERFACE;
PMPageFormat localPageFormat = kPMNoPageFormat;
rv = printSettingsX->GetPMPageFormat(&localPageFormat);
if (NS_FAILED(rv))
return rv;
PMPrintSettings localPrintSettings = kPMNoPrintSettings;
rv = printSettingsX->GetPMPrintSettings(&localPrintSettings);
if (NS_FAILED(rv))
return rv;
status = ::PMBegin();
if (status != noErr)
return NS_ERROR_FAILURE;
Boolean validated;
status = ::PMValidatePageFormat(localPageFormat, &validated);
::InitCursor();
PRBool isOn;
PRInt16 howToEnableFrameUI = nsIPrintSettings::kFrameEnableNone;
nsPrintExtensions printData = {false,false,false,false,false,false,false,false};
// set the values for the plugin here
printSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn);
printData.mHaveSelection = isOn;
printSettings->GetHowToEnableFrameUI(&howToEnableFrameUI);
if (howToEnableFrameUI == nsIPrintSettings::kFrameEnableAll) {
printData.mHaveFrames = true;
printData.mHaveFrameSelected = true;
}
if (howToEnableFrameUI == nsIPrintSettings::kFrameEnableAsIsAndEach) {
printData.mHaveFrames = true;
printData.mHaveFrameSelected = false;
}
printSettings->GetShrinkToFit(&isOn);
printData.mShrinkToFit = isOn;
CFPlugInRef pdePlugIn = ::LoadPDEPlugIn();
status = ::PMSetPrintSettingsExtendedData(localPrintSettings, kPDE_Creator, sizeof(printData),&printData);
Boolean accepted;
status = ::PMPrintDialog(localPrintSettings, localPageFormat, &accepted);
if (status == noErr && accepted) {
UInt32 bytesNeeded;
int pageRange = -1;
status = ::PMGetPrintSettingsExtendedData(localPrintSettings, kPDE_Creator, &bytesNeeded, NULL);
if (status == noErr && bytesNeeded == sizeof(printData)) {
status = ::PMGetPrintSettingsExtendedData(localPrintSettings, kPDE_Creator,&bytesNeeded, &printData);
// set the correct data fields
if (printData.mPrintSelection) {
printSettings->SetPrintRange(nsIPrintSettings::kRangeSelection);
pageRange = nsIPrintSettings::kRangeSelection;
}
else {
printSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages);
pageRange = nsIPrintSettings::kRangeAllPages;
}
if (printData.mPrintFrameAsIs)
printSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs);
if (printData.mPrintSelectedFrame)
printSettings->SetPrintFrameType(nsIPrintSettings::kSelectedFrame);
if (printData.mPrintFramesSeperatly)
printSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep);
printSettings->SetShrinkToFit(printData.mShrinkToFit);
}
if (pageRange == -1) {
printSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages);
pageRange = nsIPrintSettings::kRangeAllPages;
}
if (pageRange != nsIPrintSettings::kRangeSelection) {
UInt32 firstPage, lastPage;
status = ::PMGetFirstPage(localPrintSettings, &firstPage);
if (status == noErr) {
status = ::PMGetLastPage(localPrintSettings, &lastPage);
if (status == noErr && lastPage != LONG_MAX) {
printSettings->SetPrintRange(nsIPrintSettings::kRangeSpecifiedPageRange);
printSettings->SetStartPageRange(firstPage);
printSettings->SetEndPageRange(lastPage);
}
}
}
printSettingsX->SetPMPrintSettings(localPrintSettings);
}
::PMDisposePageFormat(localPageFormat);
::PMDisposePrintSettings(localPrintSettings);
::PMEnd();
if (!accepted)
return NS_ERROR_ABORT;
if (status != noErr)
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
nsIWebBrowserPrint* webBrowserPrint, // ok to be null
nsIPrintSettings* printSettings, // ok to be null
nsIObserver* openDialogObserver, // ok to be null
nsIWebProgressListener** webProgressListener,
nsIPrintProgressParams** printProgressParams,
PRBool* notifyOnOpen)
{
NS_ENSURE_ARG(webProgressListener);
NS_ENSURE_ARG(printProgressParams);
NS_ENSURE_ARG(notifyOnOpen);
// If running on OS X, the printing manager displays a nice progress dialog
// so we don't need to do this. Keeping this code here in order to support
// running TARGET_CARBON builds on OS 9.
long version;
if (::Gestalt(gestaltSystemVersion, &version) == noErr && version >= 0x00001000)
return NS_ERROR_NOT_IMPLEMENTED;
nsPrintProgress* prtProgress = new nsPrintProgress();
nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrintProgress));
NS_ENSURE_SUCCESS(rv, rv);
rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mWebProgressListener));
NS_ENSURE_SUCCESS(rv, rv);
nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams();
rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams);
NS_ENSURE_SUCCESS(rv, rv);
if (printProgressParams)
{
if (mWatcher)
{
nsCOMPtr<nsIDOMWindow> active;
mWatcher->GetActiveWindow(getter_AddRefs(active));
nsCOMPtr<nsIDOMWindowInternal> parent(do_QueryInterface(active));
mPrintProgress->OpenProgressDialog(parent, kPrintProgressDialogURL, *printProgressParams, openDialogObserver, notifyOnOpen);
}
}
*webProgressListener = NS_STATIC_CAST(nsIWebProgressListener*, this);
NS_ADDREF(*webProgressListener);
return rv;
}
NS_IMETHODIMP
nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings)
{
nsCOMPtr<nsIPrintSettingsX> printSettingsX(do_QueryInterface(printSettings));
if (!printSettingsX)
return NS_ERROR_NO_INTERFACE;
PMPageFormat pageFormat;
printSettingsX->GetPMPageFormat(&pageFormat);
if (pageFormat == kPMNoPageFormat)
return NS_ERROR_FAILURE;
OSStatus status = ::PMBegin();
if (status != noErr)
return NS_ERROR_FAILURE;
Boolean validated;
::PMValidatePageFormat(pageFormat, &validated);
::InitCursor();
Boolean accepted = false;
status = ::PMPageSetupDialog(pageFormat, &accepted);
if (accepted)
printSettingsX->SetPMPageFormat(pageFormat);
::PMDisposePageFormat(pageFormat);
::PMEnd();
if (status != noErr)
return NS_ERROR_FAILURE;
if (!accepted)
return NS_ERROR_ABORT;
return NS_OK;
}
NS_IMETHODIMP
nsPrintingPromptService::ShowPrinterProperties(nsIDOMWindow *parent, const PRUnichar *printerName, nsIPrintSettings *printSettings)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//*****************************************************************************
// nsPrintingPromptService::nsIWebProgressListener
//*****************************************************************************
NS_IMETHODIMP
nsPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
if (aStateFlags & STATE_STOP)
{
mWebProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
mPrintProgress->CloseProgressDialog(PR_TRUE);
mPrintProgress = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP
nsPrintingPromptService::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
return mWebProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
NS_IMETHODIMP
nsPrintingPromptService::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return mWebProgressListener->OnLocationChange(aWebProgress, aRequest, location);
}
NS_IMETHODIMP
nsPrintingPromptService::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
return mWebProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
NS_IMETHODIMP
nsPrintingPromptService::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return mWebProgressListener->OnSecurityChange(aWebProgress, aRequest, state);
}

Просмотреть файл

@ -0,0 +1,26 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..
DIRS= win
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -0,0 +1,58 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = embedcomponents
LIBRARY_NAME = printingui_s
REQUIRES = xpcom \
string \
dom \
windowwatcher \
widget \
gfx \
js \
xpconnect \
caps \
content \
necko \
uriloader \
docshell \
webbrwsr \
embed_base \
intl \
$(NULL)
CPPSRCS = \
nsPrintingPromptService.cpp \
nsPrintProgressParams.cpp \
nsPrintProgress.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,343 @@
/* -*- 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):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Rod Spears <rods@netscape.com>
*
* 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 "nsPrintProgress.h"
#include "nsIBaseWindow.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
NS_IMPL_THREADSAFE_ADDREF(nsPrintProgress);
NS_IMPL_THREADSAFE_RELEASE(nsPrintProgress);
NS_INTERFACE_MAP_BEGIN(nsPrintProgress)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrintStatusFeedback)
NS_INTERFACE_MAP_ENTRY(nsIPrintProgress)
NS_INTERFACE_MAP_ENTRY(nsIPrintStatusFeedback)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
NS_INTERFACE_MAP_END_THREADSAFE
nsPrintProgress::nsPrintProgress()
{
NS_INIT_ISUPPORTS();
m_closeProgress = PR_FALSE;
m_processCanceled = PR_FALSE;
m_pendingStateFlags = -1;
m_pendingStateValue = 0;
}
nsPrintProgress::~nsPrintProgress()
{
(void)ReleaseListeners();
}
/* void openProgressDialog (in nsIDOMWindowInternal parent, in string dialogURL, in nsISupports parameters); */
NS_IMETHODIMP nsPrintProgress::OpenProgressDialog(nsIDOMWindowInternal *parent,
const char *dialogURL,
nsISupports *parameters,
nsIObserver *openDialogObserver,
PRBool *notifyOnOpen)
{
*notifyOnOpen = PR_FALSE;
nsresult rv = NS_ERROR_FAILURE;
if (m_dialog)
return NS_ERROR_ALREADY_INITIALIZED;
if (!dialogURL || !*dialogURL)
return NS_ERROR_INVALID_ARG;
if (parent)
{
// Set up window.arguments[0]...
nsCOMPtr<nsISupportsArray> array;
rv = NS_NewISupportsArray(getter_AddRefs(array));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsInterfacePointer> ifptr =
do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
ifptr->SetData(NS_STATIC_CAST(nsIPrintProgress*, this));
ifptr->SetDataIID(&NS_GET_IID(nsIPrintProgress));
array->AppendElement(ifptr);
array->AppendElement(parameters);
// Open the dialog.
nsCOMPtr<nsIDOMWindow> newWindow;
rv = parent->OpenDialog(NS_ConvertASCIItoUCS2(dialogURL),
NS_LITERAL_STRING("_blank"),
NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
array, getter_AddRefs(newWindow));
}
return rv;
}
/* void closeProgressDialog (in boolean forceClose); */
NS_IMETHODIMP nsPrintProgress::CloseProgressDialog(PRBool forceClose)
{
m_closeProgress = PR_TRUE;
return OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, forceClose);
}
/* nsIPrompt GetPrompter (); */
NS_IMETHODIMP nsPrintProgress::GetPrompter(nsIPrompt **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
if (! m_closeProgress && m_dialog)
return m_dialog->GetPrompter(_retval);
return NS_ERROR_FAILURE;
}
/* attribute boolean processCanceledByUser; */
NS_IMETHODIMP nsPrintProgress::GetProcessCanceledByUser(PRBool *aProcessCanceledByUser)
{
NS_ENSURE_ARG_POINTER(aProcessCanceledByUser);
*aProcessCanceledByUser = m_processCanceled;
return NS_OK;
}
NS_IMETHODIMP nsPrintProgress::SetProcessCanceledByUser(PRBool aProcessCanceledByUser)
{
m_processCanceled = aProcessCanceledByUser;
OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, PR_FALSE);
return NS_OK;
}
/* void RegisterListener (in nsIWebProgressListener listener); */
NS_IMETHODIMP nsPrintProgress::RegisterListener(nsIWebProgressListener * listener)
{
nsresult rv = NS_OK;
if (!listener) //Nothing to do with a null listener!
return NS_OK;
if (!m_listenerList)
rv = NS_NewISupportsArray(getter_AddRefs(m_listenerList));
if (NS_SUCCEEDED(rv) && m_listenerList)
{
m_listenerList->AppendElement(listener);
if (m_closeProgress || m_processCanceled)
listener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, 0);
else
{
listener->OnStatusChange(nsnull, nsnull, 0, m_pendingStatus.get());
if (m_pendingStateFlags != -1)
listener->OnStateChange(nsnull, nsnull, m_pendingStateFlags, m_pendingStateValue);
}
}
return NS_OK;
}
/* void UnregisterListener (in nsIWebProgressListener listener); */
NS_IMETHODIMP nsPrintProgress::UnregisterListener(nsIWebProgressListener *listener)
{
if (m_listenerList && listener)
m_listenerList->RemoveElement(listener);
return NS_OK;
}
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP nsPrintProgress::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
nsresult rv = NS_OK;
m_pendingStateFlags = aStateFlags;
m_pendingStateValue = aStatus;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
}
}
return rv;
}
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP nsPrintProgress::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
nsresult rv = NS_OK;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
}
return rv;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP nsPrintProgress::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP nsPrintProgress::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
nsresult rv = NS_OK;
if (aMessage && *aMessage)
m_pendingStatus = aMessage;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
}
return rv;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP nsPrintProgress::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsPrintProgress::ReleaseListeners()
{
nsresult rv = NS_OK;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_SUCCEEDED(rv))
for (i = count - 1; i >= 0; i --)
m_listenerList->RemoveElementAt(i);
}
return rv;
}
NS_IMETHODIMP nsPrintProgress::ShowStatusString(const PRUnichar *status)
{
return OnStatusChange(nsnull, nsnull, NS_OK, status);
}
/* void startMeteors (); */
NS_IMETHODIMP nsPrintProgress::StartMeteors()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void stopMeteors (); */
NS_IMETHODIMP nsPrintProgress::StopMeteors()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void showProgress (in long percent); */
NS_IMETHODIMP nsPrintProgress::ShowProgress(PRInt32 percent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void setDocShell (in nsIDocShell shell, in nsIDOMWindowInternal window); */
NS_IMETHODIMP nsPrintProgress::SetDocShell(nsIDocShell *shell, nsIDOMWindowInternal *window)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void closeWindow (); */
NS_IMETHODIMP nsPrintProgress::CloseWindow()
{
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -0,0 +1,74 @@
/* -*- 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):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Rod Spears <rods@netscape.com>
*
* 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 __nsPrintProgress_h
#define __nsPrintProgress_h
#include "nsIPrintProgress.h"
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
#include "nsIDOMWindowInternal.h"
#include "nsIPrintStatusFeedback.h"
#include "nsString.h"
class nsPrintProgress : public nsIPrintProgress, public nsIPrintStatusFeedback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTPROGRESS
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIPRINTSTATUSFEEDBACK
nsPrintProgress();
virtual ~nsPrintProgress();
private:
nsresult ReleaseListeners(void);
PRBool m_closeProgress;
PRBool m_processCanceled;
nsString m_pendingStatus;
PRInt32 m_pendingStateFlags;
PRInt32 m_pendingStateValue;
nsCOMPtr<nsIDOMWindowInternal> m_dialog;
nsCOMPtr<nsISupportsArray> m_listenerList;
};
#endif

Просмотреть файл

@ -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 <rods@netscape.com>
*
* 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;
}

Просмотреть файл

@ -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 <rods@netscape.com>
*
* 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

Просмотреть файл

@ -0,0 +1,319 @@
/* -*- Mode: C++; tab-width: 2; 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 ***** */
#include "nsPrintingPromptService.h"
#include "nsXPComFactory.h"
#include "nsIComponentManager.h"
#include "nsIDialogParamBlock.h"
#include "nsIDOMWindow.h"
#include "nsIServiceManager.h"
#include "nsISupportsUtils.h"
#include "nsISupportsArray.h"
#include "nsString.h"
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
// Print Service Includes
#include "nsIPrintOptions.h"
#include "nsIServiceManager.h"
#include "nsGfxCIID.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static const char *kPrintDialogURL = "chrome://global/content/printdialog.xul";
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
static const char *kPageSetupDialogURL = "chrome://communicator/content/printPageSetup.xul";
#define NS_DIALOGPARAMBLOCK_CONTRACTID \
"@mozilla.org/embedcomp/dialogparam;1"
/****************************************************************
************************* ParamBlock ***************************
****************************************************************/
class ParamBlock {
public:
ParamBlock()
{
mBlock = 0;
}
~ParamBlock()
{
NS_IF_RELEASE(mBlock);
}
nsresult Init() {
return nsComponentManager::CreateInstance(
NS_DIALOGPARAMBLOCK_CONTRACTID,
0, NS_GET_IID(nsIDialogParamBlock),
(void**) &mBlock);
}
nsIDialogParamBlock * operator->() const { return mBlock; }
operator nsIDialogParamBlock * const () { return mBlock; }
private:
nsIDialogParamBlock *mBlock;
};
/****************************************************************
***************** nsPrintingPromptService **********************
****************************************************************/
NS_IMPL_ISUPPORTS2(nsPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener)
nsPrintingPromptService::nsPrintingPromptService()
{
NS_INIT_REFCNT();
}
nsPrintingPromptService::~nsPrintingPromptService()
{
}
nsresult
nsPrintingPromptService::Init()
{
nsresult rv;
mWatcher = do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv);
return rv;
}
/* void showPrintDialog (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings)
{
NS_ENSURE_ARG(webBrowserPrint);
NS_ENSURE_ARG(printSettings);
ParamBlock block;
nsresult rv = block.Init();
if (NS_FAILED(rv))
return rv;
block->SetInt(0, 0);
return DoDialog(parent, block, webBrowserPrint, printSettings, kPrintDialogURL);
}
/* void showProgress (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings, out nsIWebProgressListener webProgressListener); */
NS_IMETHODIMP
nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
nsIWebBrowserPrint* webBrowserPrint, // ok to be null
nsIPrintSettings* printSettings, // ok to be null
nsIObserver* openDialogObserver, // ok to be null
nsIWebProgressListener** webProgressListener,
nsIPrintProgressParams** printProgressParams,
PRBool* notifyOnOpen)
{
NS_ENSURE_ARG(webProgressListener);
NS_ENSURE_ARG(printProgressParams);
NS_ENSURE_ARG(notifyOnOpen);
nsPrintProgress* prtProgress = new nsPrintProgress();
nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrintProgress));
NS_ENSURE_SUCCESS(rv, rv);
rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mWebProgressListener));
NS_ENSURE_SUCCESS(rv, rv);
nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams();
rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams);
NS_ENSURE_SUCCESS(rv, rv);
if (printProgressParams)
{
nsCOMPtr<nsIDOMWindowInternal> parentDOMIntl(do_QueryInterface(parent));
if (mWatcher && !parentDOMIntl)
{
nsCOMPtr<nsIDOMWindow> active;
mWatcher->GetActiveWindow(getter_AddRefs(active));
parentDOMIntl = do_QueryInterface(active);
}
if (parentDOMIntl)
{
mPrintProgress->OpenProgressDialog(parentDOMIntl, kPrintProgressDialogURL, *printProgressParams, openDialogObserver, notifyOnOpen);
}
}
*webProgressListener = NS_STATIC_CAST(nsIWebProgressListener*, this);
NS_ADDREF(*webProgressListener);
return rv;
}
/* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings)
{
NS_ENSURE_ARG(printSettings);
ParamBlock block;
nsresult rv = block.Init();
if (NS_FAILED(rv))
return rv;
block->SetInt(0, 0);
return DoDialog(parent, block, nsnull, printSettings, kPageSetupDialogURL);
}
/* void showPrinterProperties (in nsIDOMWindow parent, in wstring printerName, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPrinterProperties(nsIDOMWindow *parent, const PRUnichar *printerName, nsIPrintSettings *printSettings)
{
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);
if (NS_SUCCEEDED(rv)) {
PRBool displayed;
rv = printService->DisplayJobProperties(printerName, printSettings, &displayed);
}
return rv;
}
nsresult
nsPrintingPromptService::DoDialog(nsIDOMWindow *aParent,
nsIDialogParamBlock *aParamBlock,
nsIWebBrowserPrint *aWebBrowserPrint,
nsIPrintSettings* aPS,
const char *aChromeURL)
{
NS_ENSURE_ARG(aParamBlock);
NS_ENSURE_ARG(aPS);
NS_ENSURE_ARG(aChromeURL);
if (!mWatcher)
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
// get a parent, if at all possible
// (though we'd rather this didn't fail, it's OK if it does. so there's
// no failure or null check.)
nsCOMPtr<nsIDOMWindow> activeParent; // retain ownership for method lifetime
if (!aParent)
{
mWatcher->GetActiveWindow(getter_AddRefs(activeParent));
aParent = activeParent;
}
// create a nsISupportsArray of the parameters
// being passed to the window
nsCOMPtr<nsISupportsArray> array;
NS_NewISupportsArray(getter_AddRefs(array));
if (!array) return NS_ERROR_FAILURE;
nsCOMPtr<nsISupports> psSupports(do_QueryInterface(aPS));
NS_ASSERTION(psSupports, "PrintSettings must be a supports");
array->AppendElement(psSupports);
if (aWebBrowserPrint) {
nsCOMPtr<nsISupports> wbpSupports(do_QueryInterface(aWebBrowserPrint));
NS_ASSERTION(wbpSupports, "nsIWebBrowserPrint must be a supports");
array->AppendElement(wbpSupports);
}
nsCOMPtr<nsISupports> blkSupps(do_QueryInterface(aParamBlock));
NS_ASSERTION(blkSupps, "IOBlk must be a supports");
array->AppendElement(blkSupps);
nsCOMPtr<nsISupports> arguments(do_QueryInterface(array));
NS_ASSERTION(array, "array must be a supports");
nsCOMPtr<nsIDOMWindow> dialog;
rv = mWatcher->OpenWindow(aParent, aChromeURL, "_blank",
"centerscreen,chrome,modal,titlebar", arguments,
getter_AddRefs(dialog));
// if aWebBrowserPrint is not null then we are printing
// so we want to pass back NS_ERROR_ABORT on cancel
if (NS_SUCCEEDED(rv) && aWebBrowserPrint)
{
PRInt32 status;
aParamBlock->GetInt(0, &status);
return status == 0?NS_ERROR_ABORT:NS_OK;
}
return rv;
}
//////////////////////////////////////////////////////////////////////
// nsIWebProgressListener
//////////////////////////////////////////////////////////////////////
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP
nsPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
if (aStateFlags & STATE_STOP) {
mWebProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
mPrintProgress->CloseProgressDialog(PR_TRUE);
mPrintProgress = nsnull;
}
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
nsPrintingPromptService::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
return mWebProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP
nsPrintingPromptService::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return mWebProgressListener->OnLocationChange(aWebProgress, aRequest, location);
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP
nsPrintingPromptService::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
return mWebProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP
nsPrintingPromptService::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return mWebProgressListener->OnSecurityChange(aWebProgress, aRequest, state);
}

Просмотреть файл

@ -0,0 +1,89 @@
/* -*- 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 Communicator client 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 __nsPrintingPromptService_h
#define __nsPrintingPromptService_h
// {E042570C-62DE-4bb6-A6E0-798E3C07B4DF}
#define NS_PRINTINGPROMPTSERVICE_CID \
{0xe042570c, 0x62de, 0x4bb6, { 0xa6, 0xe0, 0x79, 0x8e, 0x3c, 0x7, 0xb4, 0xdf}}
#define NS_PRINTINGPROMPTSERVICE_CONTRACTID \
"@mozilla.org/embedcomp/printingprompt-service;1"
#include "nsCOMPtr.h"
#include "nsIPrintingPromptService.h"
#include "nsPIPromptService.h"
#include "nsIWindowWatcher.h"
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
#include "nsIWebProgressListener.h"
class nsIDOMWindow;
class nsIDialogParamBlock;
class nsPrintingPromptService: public nsIPrintingPromptService,
public nsIWebProgressListener
{
public:
nsPrintingPromptService();
virtual ~nsPrintingPromptService();
nsresult Init();
NS_DECL_NSIPRINTINGPROMPTSERVICE
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_ISUPPORTS
private:
nsresult DoDialog(nsIDOMWindow *aParent,
nsIDialogParamBlock *aParamBlock,
nsIWebBrowserPrint *aWebBrowserPrint,
nsIPrintSettings* aPS,
const char *aChromeURL);
nsCOMPtr<nsIWindowWatcher> mWatcher;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMPtr<nsIWebProgressListener> mWebProgressListener;
};
#endif

Просмотреть файл

@ -0,0 +1,58 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = embedcomponents
LIBRARY_NAME = printingui_s
REQUIRES = xpcom \
string \
dom \
windowwatcher \
widget \
gfx \
js \
xpconnect \
caps \
content \
necko \
uriloader \
docshell \
webbrwsr \
embed_base \
intl \
$(NULL)
CPPSRCS = \
nsPrintingPromptService.cpp \
nsPrintProgressParams.cpp \
nsPrintProgress.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,57 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..\..
MODULE=printingui
REQUIRES = xpcom \
string \
dom \
widget \
gfx \
js \
xpconnect \
caps \
content \
necko \
uriloader \
docshell \
webBrowser_core \
embed_base \
intl \
windowwatcher \
pref \
$(NULL)
LIBRARY_NAME=printingui_s
CPP_OBJS= \
.\$(OBJDIR)\nsPrintingPromptService.obj \
.\$(OBJDIR)\nsPrintProgressParams.obj \
.\$(OBJDIR)\nsPrintProgress.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

Просмотреть файл

@ -0,0 +1,343 @@
/* -*- 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):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Rod Spears <rods@netscape.com>
*
* 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 "nsPrintProgress.h"
#include "nsIBaseWindow.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
NS_IMPL_THREADSAFE_ADDREF(nsPrintProgress);
NS_IMPL_THREADSAFE_RELEASE(nsPrintProgress);
NS_INTERFACE_MAP_BEGIN(nsPrintProgress)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrintStatusFeedback)
NS_INTERFACE_MAP_ENTRY(nsIPrintProgress)
NS_INTERFACE_MAP_ENTRY(nsIPrintStatusFeedback)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
NS_INTERFACE_MAP_END_THREADSAFE
nsPrintProgress::nsPrintProgress()
{
NS_INIT_ISUPPORTS();
m_closeProgress = PR_FALSE;
m_processCanceled = PR_FALSE;
m_pendingStateFlags = -1;
m_pendingStateValue = 0;
}
nsPrintProgress::~nsPrintProgress()
{
(void)ReleaseListeners();
}
/* void openProgressDialog (in nsIDOMWindowInternal parent, in string dialogURL, in nsISupports parameters); */
NS_IMETHODIMP nsPrintProgress::OpenProgressDialog(nsIDOMWindowInternal *parent,
const char *dialogURL,
nsISupports *parameters,
nsIObserver *openDialogObserver,
PRBool *notifyOnOpen)
{
*notifyOnOpen = PR_FALSE;
nsresult rv = NS_ERROR_FAILURE;
if (m_dialog)
return NS_ERROR_ALREADY_INITIALIZED;
if (!dialogURL || !*dialogURL)
return NS_ERROR_INVALID_ARG;
if (parent)
{
// Set up window.arguments[0]...
nsCOMPtr<nsISupportsArray> array;
rv = NS_NewISupportsArray(getter_AddRefs(array));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsInterfacePointer> ifptr =
do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
ifptr->SetData(NS_STATIC_CAST(nsIPrintProgress*, this));
ifptr->SetDataIID(&NS_GET_IID(nsIPrintProgress));
array->AppendElement(ifptr);
array->AppendElement(parameters);
// Open the dialog.
nsCOMPtr<nsIDOMWindow> newWindow;
rv = parent->OpenDialog(NS_ConvertASCIItoUCS2(dialogURL),
NS_LITERAL_STRING("_blank"),
NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
array, getter_AddRefs(newWindow));
}
return rv;
}
/* void closeProgressDialog (in boolean forceClose); */
NS_IMETHODIMP nsPrintProgress::CloseProgressDialog(PRBool forceClose)
{
m_closeProgress = PR_TRUE;
return OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, forceClose);
}
/* nsIPrompt GetPrompter (); */
NS_IMETHODIMP nsPrintProgress::GetPrompter(nsIPrompt **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
if (! m_closeProgress && m_dialog)
return m_dialog->GetPrompter(_retval);
return NS_ERROR_FAILURE;
}
/* attribute boolean processCanceledByUser; */
NS_IMETHODIMP nsPrintProgress::GetProcessCanceledByUser(PRBool *aProcessCanceledByUser)
{
NS_ENSURE_ARG_POINTER(aProcessCanceledByUser);
*aProcessCanceledByUser = m_processCanceled;
return NS_OK;
}
NS_IMETHODIMP nsPrintProgress::SetProcessCanceledByUser(PRBool aProcessCanceledByUser)
{
m_processCanceled = aProcessCanceledByUser;
OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, PR_FALSE);
return NS_OK;
}
/* void RegisterListener (in nsIWebProgressListener listener); */
NS_IMETHODIMP nsPrintProgress::RegisterListener(nsIWebProgressListener * listener)
{
nsresult rv = NS_OK;
if (!listener) //Nothing to do with a null listener!
return NS_OK;
if (!m_listenerList)
rv = NS_NewISupportsArray(getter_AddRefs(m_listenerList));
if (NS_SUCCEEDED(rv) && m_listenerList)
{
m_listenerList->AppendElement(listener);
if (m_closeProgress || m_processCanceled)
listener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, 0);
else
{
listener->OnStatusChange(nsnull, nsnull, 0, m_pendingStatus.get());
if (m_pendingStateFlags != -1)
listener->OnStateChange(nsnull, nsnull, m_pendingStateFlags, m_pendingStateValue);
}
}
return NS_OK;
}
/* void UnregisterListener (in nsIWebProgressListener listener); */
NS_IMETHODIMP nsPrintProgress::UnregisterListener(nsIWebProgressListener *listener)
{
if (m_listenerList && listener)
m_listenerList->RemoveElement(listener);
return NS_OK;
}
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP nsPrintProgress::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
nsresult rv = NS_OK;
m_pendingStateFlags = aStateFlags;
m_pendingStateValue = aStatus;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
}
}
return rv;
}
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP nsPrintProgress::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
nsresult rv = NS_OK;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
}
return rv;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP nsPrintProgress::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP nsPrintProgress::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
nsresult rv = NS_OK;
if (aMessage && *aMessage)
m_pendingStatus = aMessage;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
}
return rv;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP nsPrintProgress::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsPrintProgress::ReleaseListeners()
{
nsresult rv = NS_OK;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_SUCCEEDED(rv))
for (i = count - 1; i >= 0; i --)
m_listenerList->RemoveElementAt(i);
}
return rv;
}
NS_IMETHODIMP nsPrintProgress::ShowStatusString(const PRUnichar *status)
{
return OnStatusChange(nsnull, nsnull, NS_OK, status);
}
/* void startMeteors (); */
NS_IMETHODIMP nsPrintProgress::StartMeteors()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void stopMeteors (); */
NS_IMETHODIMP nsPrintProgress::StopMeteors()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void showProgress (in long percent); */
NS_IMETHODIMP nsPrintProgress::ShowProgress(PRInt32 percent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void setDocShell (in nsIDocShell shell, in nsIDOMWindowInternal window); */
NS_IMETHODIMP nsPrintProgress::SetDocShell(nsIDocShell *shell, nsIDOMWindowInternal *window)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void closeWindow (); */
NS_IMETHODIMP nsPrintProgress::CloseWindow()
{
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -0,0 +1,74 @@
/* -*- 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):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Rod Spears <rods@netscape.com>
*
* 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 __nsPrintProgress_h
#define __nsPrintProgress_h
#include "nsIPrintProgress.h"
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
#include "nsIDOMWindowInternal.h"
#include "nsIPrintStatusFeedback.h"
#include "nsString.h"
class nsPrintProgress : public nsIPrintProgress, public nsIPrintStatusFeedback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTPROGRESS
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIPRINTSTATUSFEEDBACK
nsPrintProgress();
virtual ~nsPrintProgress();
private:
nsresult ReleaseListeners(void);
PRBool m_closeProgress;
PRBool m_processCanceled;
nsString m_pendingStatus;
PRInt32 m_pendingStateFlags;
PRInt32 m_pendingStateValue;
nsCOMPtr<nsIDOMWindowInternal> m_dialog;
nsCOMPtr<nsISupportsArray> m_listenerList;
};
#endif

Просмотреть файл

@ -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 <rods@netscape.com>
*
* 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;
}

Просмотреть файл

@ -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 <rods@netscape.com>
*
* 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

Просмотреть файл

@ -0,0 +1,325 @@
/* -*- Mode: C++; tab-width: 2; 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 ***** */
#include "nsPrintingPromptService.h"
#include "nsXPComFactory.h"
#include "nsIComponentManager.h"
#include "nsIDialogParamBlock.h"
#include "nsIDOMWindow.h"
#include "nsIServiceManager.h"
#include "nsISupportsUtils.h"
#include "nsISupportsArray.h"
#include "nsString.h"
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
static const char *kPrintDialogURL = "chrome://global/content/printdialog.xul";
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
static const char *kPageSetupDialogURL = "chrome://communicator/content/printPageSetup.xul";
static const char *kPrinterPropertiesURL = "chrome://global/content/printjoboptions.xul";
#define NS_DIALOGPARAMBLOCK_CONTRACTID \
"@mozilla.org/embedcomp/dialogparam;1"
/****************************************************************
************************* ParamBlock ***************************
****************************************************************/
class ParamBlock {
public:
ParamBlock()
{
mBlock = 0;
}
~ParamBlock()
{
NS_IF_RELEASE(mBlock);
}
nsresult Init() {
return nsComponentManager::CreateInstance(
NS_DIALOGPARAMBLOCK_CONTRACTID,
0, NS_GET_IID(nsIDialogParamBlock),
(void**) &mBlock);
}
nsIDialogParamBlock * operator->() const { return mBlock; }
operator nsIDialogParamBlock * const () { return mBlock; }
private:
nsIDialogParamBlock *mBlock;
};
/****************************************************************
***************** nsPrintingPromptService **********************
****************************************************************/
NS_IMPL_ISUPPORTS2(nsPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener)
nsPrintingPromptService::nsPrintingPromptService()
{
NS_INIT_REFCNT();
}
nsPrintingPromptService::~nsPrintingPromptService()
{
}
nsresult
nsPrintingPromptService::Init()
{
nsresult rv;
mWatcher = do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv);
return rv;
}
/* void showPrintDialog (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings)
{
NS_ENSURE_ARG(webBrowserPrint);
NS_ENSURE_ARG(printSettings);
ParamBlock block;
nsresult rv = block.Init();
if (NS_FAILED(rv))
return rv;
block->SetInt(0, 0);
return DoDialog(parent, block, webBrowserPrint, printSettings, kPrintDialogURL);
}
/* void showProgress (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings, out nsIWebProgressListener webProgressListener); */
NS_IMETHODIMP
nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
nsIWebBrowserPrint* webBrowserPrint, // ok to be null
nsIPrintSettings* printSettings, // ok to be null
nsIObserver* openDialogObserver, // ok to be null
nsIWebProgressListener** webProgressListener,
nsIPrintProgressParams** printProgressParams,
PRBool* notifyOnOpen)
{
NS_ENSURE_ARG(webProgressListener);
NS_ENSURE_ARG(printProgressParams);
NS_ENSURE_ARG(notifyOnOpen);
nsPrintProgress* prtProgress = new nsPrintProgress();
nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrintProgress));
NS_ENSURE_SUCCESS(rv, rv);
rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mWebProgressListener));
NS_ENSURE_SUCCESS(rv, rv);
nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams();
rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams);
NS_ENSURE_SUCCESS(rv, rv);
if (printProgressParams)
{
nsCOMPtr<nsIDOMWindowInternal> parentDOMIntl(do_QueryInterface(parent));
if (mWatcher && !parentDOMIntl)
{
nsCOMPtr<nsIDOMWindow> active;
mWatcher->GetActiveWindow(getter_AddRefs(active));
parentDOMIntl = do_QueryInterface(active);
}
if (parentDOMIntl)
{
mPrintProgress->OpenProgressDialog(parentDOMIntl, kPrintProgressDialogURL, *printProgressParams, openDialogObserver, notifyOnOpen);
}
}
*webProgressListener = NS_STATIC_CAST(nsIWebProgressListener*, this);
NS_ADDREF(*webProgressListener);
return rv;
}
/* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings)
{
NS_ENSURE_ARG(printSettings);
ParamBlock block;
nsresult rv = block.Init();
if (NS_FAILED(rv))
return rv;
block->SetInt(0, 0);
return DoDialog(parent, block, nsnull, printSettings, kPageSetupDialogURL);
}
/* void showPrinterProperties (in nsIDOMWindow parent, in wstring printerName, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPrinterProperties(nsIDOMWindow *parent, const PRUnichar *printerName, nsIPrintSettings *printSettings)
{
/* fixme: We simply ignore the |aPrinter| argument here
* We should get the supported printer attributes from the printer and
* populate the print job options dialog with these data instead of using
* the "default set" here.
* However, this requires changes on all platforms and is another big chunk
* of patches ... ;-(
*/
NS_ENSURE_ARG(printerName);
NS_ENSURE_ARG(printSettings);
ParamBlock block;
nsresult rv = block.Init();
if (NS_FAILED(rv))
return rv;
block->SetInt(0, 0);
return DoDialog(parent, block, nsnull, printSettings, kPrinterPropertiesURL);
}
nsresult
nsPrintingPromptService::DoDialog(nsIDOMWindow *aParent,
nsIDialogParamBlock *aParamBlock,
nsIWebBrowserPrint *aWebBrowserPrint,
nsIPrintSettings* aPS,
const char *aChromeURL)
{
NS_ENSURE_ARG(aParamBlock);
NS_ENSURE_ARG(aPS);
NS_ENSURE_ARG(aChromeURL);
if (!mWatcher)
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
// get a parent, if at all possible
// (though we'd rather this didn't fail, it's OK if it does. so there's
// no failure or null check.)
nsCOMPtr<nsIDOMWindow> activeParent; // retain ownership for method lifetime
if (!aParent)
{
mWatcher->GetActiveWindow(getter_AddRefs(activeParent));
aParent = activeParent;
}
// create a nsISupportsArray of the parameters
// being passed to the window
nsCOMPtr<nsISupportsArray> array;
NS_NewISupportsArray(getter_AddRefs(array));
if (!array) return NS_ERROR_FAILURE;
nsCOMPtr<nsISupports> psSupports(do_QueryInterface(aPS));
NS_ASSERTION(psSupports, "PrintSettings must be a supports");
array->AppendElement(psSupports);
if (aWebBrowserPrint) {
nsCOMPtr<nsISupports> wbpSupports(do_QueryInterface(aWebBrowserPrint));
NS_ASSERTION(wbpSupports, "nsIWebBrowserPrint must be a supports");
array->AppendElement(wbpSupports);
}
nsCOMPtr<nsISupports> blkSupps(do_QueryInterface(aParamBlock));
NS_ASSERTION(blkSupps, "IOBlk must be a supports");
array->AppendElement(blkSupps);
nsCOMPtr<nsISupports> arguments(do_QueryInterface(array));
NS_ASSERTION(array, "array must be a supports");
nsCOMPtr<nsIDOMWindow> dialog;
rv = mWatcher->OpenWindow(aParent, aChromeURL, "_blank",
"centerscreen,chrome,modal,titlebar", arguments,
getter_AddRefs(dialog));
// if aWebBrowserPrint is not null then we are printing
// so we want to pass back NS_ERROR_ABORT on cancel
if (NS_SUCCEEDED(rv) && aWebBrowserPrint)
{
PRInt32 status;
aParamBlock->GetInt(0, &status);
return status == 0?NS_ERROR_ABORT:NS_OK;
}
return rv;
}
//////////////////////////////////////////////////////////////////////
// nsIWebProgressListener
//////////////////////////////////////////////////////////////////////
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP
nsPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
if (aStateFlags & STATE_STOP) {
mWebProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
mPrintProgress->CloseProgressDialog(PR_TRUE);
mPrintProgress = nsnull;
}
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
nsPrintingPromptService::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
return mWebProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP
nsPrintingPromptService::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return mWebProgressListener->OnLocationChange(aWebProgress, aRequest, location);
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP
nsPrintingPromptService::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
return mWebProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP
nsPrintingPromptService::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return mWebProgressListener->OnSecurityChange(aWebProgress, aRequest, state);
}

Просмотреть файл

@ -0,0 +1,89 @@
/* -*- 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 Communicator client 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 __nsPrintingPromptService_h
#define __nsPrintingPromptService_h
// {E042570C-62DE-4bb6-A6E0-798E3C07B4DF}
#define NS_PRINTINGPROMPTSERVICE_CID \
{0xe042570c, 0x62de, 0x4bb6, { 0xa6, 0xe0, 0x79, 0x8e, 0x3c, 0x7, 0xb4, 0xdf}}
#define NS_PRINTINGPROMPTSERVICE_CONTRACTID \
"@mozilla.org/embedcomp/printingprompt-service;1"
#include "nsCOMPtr.h"
#include "nsIPrintingPromptService.h"
#include "nsPIPromptService.h"
#include "nsIWindowWatcher.h"
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
#include "nsIWebProgressListener.h"
class nsIDOMWindow;
class nsIDialogParamBlock;
class nsPrintingPromptService: public nsIPrintingPromptService,
public nsIWebProgressListener
{
public:
nsPrintingPromptService();
virtual ~nsPrintingPromptService();
nsresult Init();
NS_DECL_NSIPRINTINGPROMPTSERVICE
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_ISUPPORTS
private:
nsresult DoDialog(nsIDOMWindow *aParent,
nsIDialogParamBlock *aParamBlock,
nsIWebBrowserPrint *aWebBrowserPrint,
nsIPrintSettings* aPS,
const char *aChromeURL);
nsCOMPtr<nsIWindowWatcher> mWatcher;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMPtr<nsIWebProgressListener> mWebProgressListener;
};
#endif

Просмотреть файл

@ -0,0 +1,66 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = embedcomponents
LIBRARY_NAME = printingui_s
REQUIRES = xpcom \
string \
dom \
windowwatcher \
widget \
gfx \
js \
xpconnect \
caps \
content \
necko \
uriloader \
docshell \
webbrwsr \
embed_base \
intl \
windowwatcher \
pref \
$(NULL)
CPPSRCS = \
nsPrintingPromptService.cpp \
nsPrintProgressParams.cpp \
nsPrintProgress.cpp \
nsPrintDialogUtil.cpp \
$(NULL)
OS_LIBS += \
comdlg32.lib \
winspool.lib \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,63 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications, Inc. Portions created by Netscape are
# Copyright (C) 2001, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..\..
MODULE=printingui
REQUIRES = xpcom \
string \
dom \
widget \
gfx \
js \
xpconnect \
caps \
content \
necko \
uriloader \
docshell \
webBrowser_core \
embed_base \
intl \
windowwatcher \
pref \
$(NULL)
LIBRARY_NAME=printingui_s
CPP_OBJS= \
.\$(OBJDIR)\nsPrintingPromptService.obj \
.\$(OBJDIR)\nsPrintProgressParams.obj \
.\$(OBJDIR)\nsPrintProgress.obj \
.\$(OBJDIR)\nsPrintDialogUtil.obj \
$(NULL)
WIN_LIBS = \
comdlg32.lib \
winspool.lib \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -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___ */

Просмотреть файл

@ -0,0 +1,343 @@
/* -*- 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):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Rod Spears <rods@netscape.com>
*
* 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 "nsPrintProgress.h"
#include "nsIBaseWindow.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
NS_IMPL_THREADSAFE_ADDREF(nsPrintProgress);
NS_IMPL_THREADSAFE_RELEASE(nsPrintProgress);
NS_INTERFACE_MAP_BEGIN(nsPrintProgress)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrintStatusFeedback)
NS_INTERFACE_MAP_ENTRY(nsIPrintProgress)
NS_INTERFACE_MAP_ENTRY(nsIPrintStatusFeedback)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
NS_INTERFACE_MAP_END_THREADSAFE
nsPrintProgress::nsPrintProgress()
{
NS_INIT_ISUPPORTS();
m_closeProgress = PR_FALSE;
m_processCanceled = PR_FALSE;
m_pendingStateFlags = -1;
m_pendingStateValue = 0;
}
nsPrintProgress::~nsPrintProgress()
{
(void)ReleaseListeners();
}
/* void openProgressDialog (in nsIDOMWindowInternal parent, in string dialogURL, in nsISupports parameters); */
NS_IMETHODIMP nsPrintProgress::OpenProgressDialog(nsIDOMWindowInternal *parent,
const char *dialogURL,
nsISupports *parameters,
nsIObserver *openDialogObserver,
PRBool *notifyOnOpen)
{
*notifyOnOpen = PR_FALSE;
nsresult rv = NS_ERROR_FAILURE;
if (m_dialog)
return NS_ERROR_ALREADY_INITIALIZED;
if (!dialogURL || !*dialogURL)
return NS_ERROR_INVALID_ARG;
if (parent)
{
// Set up window.arguments[0]...
nsCOMPtr<nsISupportsArray> array;
rv = NS_NewISupportsArray(getter_AddRefs(array));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsInterfacePointer> ifptr =
do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
ifptr->SetData(NS_STATIC_CAST(nsIPrintProgress*, this));
ifptr->SetDataIID(&NS_GET_IID(nsIPrintProgress));
array->AppendElement(ifptr);
array->AppendElement(parameters);
// Open the dialog.
nsCOMPtr<nsIDOMWindow> newWindow;
rv = parent->OpenDialog(NS_ConvertASCIItoUCS2(dialogURL),
NS_LITERAL_STRING("_blank"),
NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
array, getter_AddRefs(newWindow));
}
return rv;
}
/* void closeProgressDialog (in boolean forceClose); */
NS_IMETHODIMP nsPrintProgress::CloseProgressDialog(PRBool forceClose)
{
m_closeProgress = PR_TRUE;
return OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, forceClose);
}
/* nsIPrompt GetPrompter (); */
NS_IMETHODIMP nsPrintProgress::GetPrompter(nsIPrompt **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
if (! m_closeProgress && m_dialog)
return m_dialog->GetPrompter(_retval);
return NS_ERROR_FAILURE;
}
/* attribute boolean processCanceledByUser; */
NS_IMETHODIMP nsPrintProgress::GetProcessCanceledByUser(PRBool *aProcessCanceledByUser)
{
NS_ENSURE_ARG_POINTER(aProcessCanceledByUser);
*aProcessCanceledByUser = m_processCanceled;
return NS_OK;
}
NS_IMETHODIMP nsPrintProgress::SetProcessCanceledByUser(PRBool aProcessCanceledByUser)
{
m_processCanceled = aProcessCanceledByUser;
OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, PR_FALSE);
return NS_OK;
}
/* void RegisterListener (in nsIWebProgressListener listener); */
NS_IMETHODIMP nsPrintProgress::RegisterListener(nsIWebProgressListener * listener)
{
nsresult rv = NS_OK;
if (!listener) //Nothing to do with a null listener!
return NS_OK;
if (!m_listenerList)
rv = NS_NewISupportsArray(getter_AddRefs(m_listenerList));
if (NS_SUCCEEDED(rv) && m_listenerList)
{
m_listenerList->AppendElement(listener);
if (m_closeProgress || m_processCanceled)
listener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, 0);
else
{
listener->OnStatusChange(nsnull, nsnull, 0, m_pendingStatus.get());
if (m_pendingStateFlags != -1)
listener->OnStateChange(nsnull, nsnull, m_pendingStateFlags, m_pendingStateValue);
}
}
return NS_OK;
}
/* void UnregisterListener (in nsIWebProgressListener listener); */
NS_IMETHODIMP nsPrintProgress::UnregisterListener(nsIWebProgressListener *listener)
{
if (m_listenerList && listener)
m_listenerList->RemoveElement(listener);
return NS_OK;
}
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP nsPrintProgress::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
nsresult rv = NS_OK;
m_pendingStateFlags = aStateFlags;
m_pendingStateValue = aStatus;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
}
}
return rv;
}
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP nsPrintProgress::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
nsresult rv = NS_OK;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
}
return rv;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP nsPrintProgress::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP nsPrintProgress::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
nsresult rv = NS_OK;
if (aMessage && *aMessage)
m_pendingStatus = aMessage;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsISupports> aSupports;
nsCOMPtr<nsIWebProgressListener> aProgressListener;
for (i = count - 1; i >= 0; i --)
{
m_listenerList->GetElementAt(i, getter_AddRefs(aSupports));
aProgressListener = do_QueryInterface(aSupports);
if (aProgressListener)
aProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
}
return rv;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP nsPrintProgress::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsPrintProgress::ReleaseListeners()
{
nsresult rv = NS_OK;
if (m_listenerList)
{
PRUint32 count;
PRInt32 i;
rv = m_listenerList->Count(&count);
NS_ASSERTION(NS_SUCCEEDED(rv), "m_listenerList->Count() failed");
if (NS_SUCCEEDED(rv))
for (i = count - 1; i >= 0; i --)
m_listenerList->RemoveElementAt(i);
}
return rv;
}
NS_IMETHODIMP nsPrintProgress::ShowStatusString(const PRUnichar *status)
{
return OnStatusChange(nsnull, nsnull, NS_OK, status);
}
/* void startMeteors (); */
NS_IMETHODIMP nsPrintProgress::StartMeteors()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void stopMeteors (); */
NS_IMETHODIMP nsPrintProgress::StopMeteors()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void showProgress (in long percent); */
NS_IMETHODIMP nsPrintProgress::ShowProgress(PRInt32 percent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void setDocShell (in nsIDocShell shell, in nsIDOMWindowInternal window); */
NS_IMETHODIMP nsPrintProgress::SetDocShell(nsIDocShell *shell, nsIDOMWindowInternal *window)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void closeWindow (); */
NS_IMETHODIMP nsPrintProgress::CloseWindow()
{
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -0,0 +1,76 @@
/* -*- 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):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Rod Spears <rods@netscape.com>
*
* 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 __nsPrintProgress_h
#define __nsPrintProgress_h
#include "nsIPrintProgress.h"
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
#include "nsIDOMWindowInternal.h"
#include "nsIPrintStatusFeedback.h"
#include "nsString.h"
#include "nsIWindowWatcher.h"
#include "nsIObserver.h"
class nsPrintProgress : public nsIPrintProgress, public nsIPrintStatusFeedback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTPROGRESS
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIPRINTSTATUSFEEDBACK
nsPrintProgress();
virtual ~nsPrintProgress();
private:
nsresult ReleaseListeners(void);
PRBool m_closeProgress;
PRBool m_processCanceled;
nsString m_pendingStatus;
PRInt32 m_pendingStateFlags;
PRInt32 m_pendingStateValue;
nsCOMPtr<nsIDOMWindowInternal> m_dialog;
nsCOMPtr<nsISupportsArray> m_listenerList;
};
#endif

Просмотреть файл

@ -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 <rods@netscape.com>
*
* 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;
}

Просмотреть файл

@ -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 <rods@netscape.com>
*
* 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

Просмотреть файл

@ -0,0 +1,360 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsCOMPtr.h"
#include "nsPrintingPromptService.h"
#include "nsIPrintingPromptService.h"
#include "nsIFactory.h"
#include "nsIDOMWindow.h"
#include "nsReadableUtils.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIServiceManager.h"
#include "nsIWebBrowserChrome.h"
#include "nsIWindowWatcher.h"
#include "nsPrintDialogUtil.h"
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
#include "nsIWebProgressListener.h"
// XP Dialog includes
#include "nsIDialogParamBlock.h"
#include "nsISupportsUtils.h"
#include "nsISupportsArray.h"
// Includes need to locate the native Window
#include "nsIWidget.h"
#include "nsIBaseWindow.h"
#include "nsIWebBrowserChrome.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIDocShellTreeItem.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
#define NS_DIALOGPARAMBLOCK_CONTRACTID "@mozilla.org/embedcomp/dialogparam;1"
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
static const char *kPageSetupDialogURL = "chrome://communicator/content/printPageSetup.xul";
// Static Data
static HINSTANCE gInstance;
/****************************************************************
************************* ParamBlock ***************************
****************************************************************/
class ParamBlock {
public:
ParamBlock()
{
mBlock = 0;
}
~ParamBlock()
{
NS_IF_RELEASE(mBlock);
}
nsresult Init() {
return nsComponentManager::CreateInstance(
NS_DIALOGPARAMBLOCK_CONTRACTID,
0, NS_GET_IID(nsIDialogParamBlock),
(void**) &mBlock);
}
nsIDialogParamBlock * operator->() const { return mBlock; }
operator nsIDialogParamBlock * const () { return mBlock; }
private:
nsIDialogParamBlock *mBlock;
};
//*****************************************************************************
NS_IMPL_ISUPPORTS2(nsPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener)
nsPrintingPromptService::nsPrintingPromptService()
{
NS_INIT_REFCNT();
}
//-----------------------------------------------------------
nsPrintingPromptService::~nsPrintingPromptService()
{
}
//-----------------------------------------------------------
nsresult
nsPrintingPromptService::Init()
{
nsresult rv;
mWatcher = do_GetService("@mozilla.org/embedcomp/window-watcher;1", &rv);
return rv;
}
//-----------------------------------------------------------
HWND
nsPrintingPromptService::GetHWNDForDOMWindow(nsIDOMWindow *aWindow)
{
nsCOMPtr<nsIWebBrowserChrome> chrome;
HWND hWnd = NULL;
// We might be embedded so check this path first
if (mWatcher) {
nsCOMPtr<nsIDOMWindow> fosterParent;
if (!aWindow)
{ // it will be a dependent window. try to find a foster parent.
mWatcher->GetActiveWindow(getter_AddRefs(fosterParent));
aWindow = fosterParent;
}
mWatcher->GetChromeForWindow(aWindow, getter_AddRefs(chrome));
}
if (chrome) {
nsCOMPtr<nsIEmbeddingSiteWindow> site(do_QueryInterface(chrome));
if (site)
{
HWND w;
site->GetSiteWindow(reinterpret_cast<void **>(&w));
return w;
}
}
// Now we might be the Browser so check this path
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_QueryInterface(aWindow));
nsCOMPtr<nsIDocShell> docShell;
scriptGlobal->GetDocShell(getter_AddRefs(docShell));
if (!docShell) return nsnull;
nsCOMPtr<nsIDocShellTreeItem> treeItem;
treeItem = do_QueryInterface(docShell);
if (!treeItem) return nsnull;
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
if (!treeOwner) return nsnull;
nsCOMPtr<nsIWebBrowserChrome> webBrowserChrome(do_GetInterface(treeOwner));
if (!webBrowserChrome) return nsnull;
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(webBrowserChrome));
if (!baseWin) return nsnull;
nsCOMPtr<nsIWidget> widget;
baseWin->GetMainWidget(getter_AddRefs(widget));
if (!widget) return nsnull;
return (HWND)widget->GetNativeData(NS_NATIVE_WINDOW);
}
///////////////////////////////////////////////////////////////////////////////
// nsIPrintingPrompt
//-----------------------------------------------------------
NS_IMETHODIMP
nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings)
{
NS_ENSURE_ARG(parent);
HWND hWnd = GetHWNDForDOMWindow(parent);
NS_ASSERTION(hWnd, "Couldn't get native window for PRint Dialog!");
return NativeShowPrintDialog(hWnd, webBrowserPrint, printSettings);
}
//-----------------------------------------------------------
NS_IMETHODIMP
nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
nsIWebBrowserPrint* webBrowserPrint, // ok to be null
nsIPrintSettings* printSettings, // ok to be null
nsIObserver* openDialogObserver, // ok to be null
nsIWebProgressListener** webProgressListener,
nsIPrintProgressParams** printProgressParams,
PRBool* notifyOnOpen)
{
NS_ENSURE_ARG(webProgressListener);
NS_ENSURE_ARG(printProgressParams);
NS_ENSURE_ARG(notifyOnOpen);
nsPrintProgress* prtProgress = new nsPrintProgress();
nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrintProgress));
NS_ENSURE_SUCCESS(rv, rv);
rv = prtProgress->QueryInterface(NS_GET_IID(nsIWebProgressListener), (void**)getter_AddRefs(mWebProgressListener));
NS_ENSURE_SUCCESS(rv, rv);
nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams();
rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams);
NS_ENSURE_SUCCESS(rv, rv);
*notifyOnOpen = PR_FALSE;
if (printProgressParams)
{
nsCOMPtr<nsIDOMWindowInternal> parentDOMIntl(do_QueryInterface(parent));
if (mWatcher && !parentDOMIntl)
{
nsCOMPtr<nsIDOMWindow> active;
mWatcher->GetActiveWindow(getter_AddRefs(active));
parentDOMIntl = do_QueryInterface(active);
}
if (parentDOMIntl)
{
mPrintProgress->OpenProgressDialog(parentDOMIntl, kPrintProgressDialogURL, *printProgressParams, openDialogObserver, notifyOnOpen);
}
}
*webProgressListener = NS_STATIC_CAST(nsIWebProgressListener*, this);
NS_ADDREF(*webProgressListener);
return rv;
}
/* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings)
{
NS_ENSURE_ARG(printSettings);
ParamBlock block;
nsresult rv = block.Init();
if (NS_FAILED(rv))
return rv;
block->SetInt(0, 0);
rv = DoDialog(parent, block, printSettings, kPageSetupDialogURL);
return rv;
}
/* void showPrinterProperties (in nsIDOMWindow parent, in wstring printerName, in nsIPrintSettings printSettings); */
NS_IMETHODIMP
nsPrintingPromptService::ShowPrinterProperties(nsIDOMWindow *parent, const PRUnichar *printerName, nsIPrintSettings *printSettings)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//-----------------------------------------------------------
// Helper to Fly XP Dialog
nsresult
nsPrintingPromptService::DoDialog(nsIDOMWindow *aParent,
nsIDialogParamBlock *aParamBlock,
nsIPrintSettings* aPS,
const char *aChromeURL)
{
NS_ENSURE_ARG(aParamBlock);
NS_ENSURE_ARG(aPS);
NS_ENSURE_ARG(aChromeURL);
if (!mWatcher)
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
// get a parent, if at all possible
// (though we'd rather this didn't fail, it's OK if it does. so there's
// no failure or null check.)
nsCOMPtr<nsIDOMWindow> activeParent; // retain ownership for method lifetime
if (!aParent)
{
mWatcher->GetActiveWindow(getter_AddRefs(activeParent));
aParent = activeParent;
}
// create a nsISupportsArray of the parameters
// being passed to the window
nsCOMPtr<nsISupportsArray> array;
NS_NewISupportsArray(getter_AddRefs(array));
if (!array) return NS_ERROR_FAILURE;
nsCOMPtr<nsISupports> psSupports(do_QueryInterface(aPS));
NS_ASSERTION(psSupports, "PrintSettings must be a supports");
array->AppendElement(psSupports);
nsCOMPtr<nsISupports> blkSupps(do_QueryInterface(aParamBlock));
NS_ASSERTION(blkSupps, "IOBlk must be a supports");
array->AppendElement(blkSupps);
nsCOMPtr<nsISupports> arguments(do_QueryInterface(array));
NS_ASSERTION(array, "array must be a supports");
nsCOMPtr<nsIDOMWindow> dialog;
rv = mWatcher->OpenWindow(aParent, aChromeURL, "_blank",
"centerscreen,chrome,modal,titlebar", arguments,
getter_AddRefs(dialog));
return rv;
}
//////////////////////////////////////////////////////////////////////
// nsIWebProgressListener
//////////////////////////////////////////////////////////////////////
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP
nsPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus)
{
if (aStateFlags & STATE_STOP)
{
mWebProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
mPrintProgress->CloseProgressDialog(PR_TRUE);
mPrintProgress = nsnull;
}
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
nsPrintingPromptService::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
return mWebProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP
nsPrintingPromptService::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return mWebProgressListener->OnLocationChange(aWebProgress, aRequest, location);
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP
nsPrintingPromptService::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
return mWebProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP
nsPrintingPromptService::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state)
{
return mWebProgressListener->OnSecurityChange(aWebProgress, aRequest, state);
}

Просмотреть файл

@ -0,0 +1,90 @@
/* -*- 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 Communicator client 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 __nsPrintingPromptService_h
#define __nsPrintingPromptService_h
#include <windows.h>
// {E042570C-62DE-4bb6-A6E0-798E3C07B4DF}
#define NS_PRINTINGPROMPTSERVICE_CID \
{0xe042570c, 0x62de, 0x4bb6, { 0xa6, 0xe0, 0x79, 0x8e, 0x3c, 0x7, 0xb4, 0xdf}}
#define NS_PRINTINGPROMPTSERVICE_CONTRACTID \
"@mozilla.org/embedcomp/printingprompt-service;1"
#include "nsCOMPtr.h"
#include "nsIPrintingPromptService.h"
#include "nsPIPromptService.h"
#include "nsIWindowWatcher.h"
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
#include "nsIWebProgressListener.h"
class nsIDOMWindow;
class nsIDialogParamBlock;
class nsPrintingPromptService: public nsIPrintingPromptService,
public nsIWebProgressListener
{
public:
nsPrintingPromptService();
virtual ~nsPrintingPromptService();
nsresult Init();
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTINGPROMPTSERVICE
NS_DECL_NSIWEBPROGRESSLISTENER
private:
HWND GetHWNDForDOMWindow(nsIDOMWindow *parent);
nsresult DoDialog(nsIDOMWindow *aParent,
nsIDialogParamBlock *aParamBlock,
nsIPrintSettings* aPS,
const char *aChromeURL);
nsCOMPtr<nsIWindowWatcher> mWatcher;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMPtr<nsIWebProgressListener> mWebProgressListener;
};
#endif