Rought support for the print-preview window

git-svn-id: svn://10.0.0.236/trunk@12942 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kipp%netscape.com
1998-10-15 23:23:04 +00:00
parent e289ce98a1
commit a256ceff0e
2 changed files with 142 additions and 2 deletions

View File

@@ -394,6 +394,12 @@ nsBrowserWindow::DispatchMenuItem(PRInt32 aID)
case EDITOR_MODE:
DoEditorMode(mWebShell);
break;
case VIEWER_ONE_COLUMN:
case VIEWER_TWO_COLUMN:
case VIEWER_THREE_COLUMN:
ShowPrintPreview(aID);
break;
}
return nsEventStatus_eIgnore;
@@ -820,6 +826,8 @@ nsBrowserWindow::nsBrowserWindow()
nsBrowserWindow::~nsBrowserWindow()
{
NS_IF_RELEASE(mPrefs);
NS_IF_RELEASE(mAppShell);
}
NS_IMPL_ADDREF(nsBrowserWindow)
@@ -872,10 +880,14 @@ nsBrowserWindow::Init(nsIAppShell* aAppShell,
PRBool aAllowPlugins)
{
mChromeMask = aChromeMask;
mAppShell = aAppShell;
mPrefs = aPrefs;
mAllowPlugins = aAllowPlugins;
mAppShell = aAppShell;
NS_IF_ADDREF(mAppShell);
mPrefs = aPrefs;
NS_IF_ADDREF(mPrefs);
// Create top level window
nsresult rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWidgetIID,
(void**)&mWindow);
@@ -933,6 +945,83 @@ nsBrowserWindow::Init(nsIAppShell* aAppShell,
return NS_OK;
}
nsresult
nsBrowserWindow::Init(nsIAppShell* aAppShell,
nsIPref* aPrefs,
const nsRect& aBounds,
PRUint32 aChromeMask,
PRBool aAllowPlugins,
nsIDocumentViewer* aDocumentViewer,
nsIPresContext* aPresContext)
{
mChromeMask = aChromeMask;
mAppShell = aAppShell;
mPrefs = aPrefs;
mAllowPlugins = aAllowPlugins;
// Create top level window
nsresult rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWidgetIID,
(void**)&mWindow);
if (NS_OK != rv) {
return rv;
}
nsRect r(0, 0, aBounds.width, aBounds.height);
mWindow->Create((nsIWidget*)NULL, r, HandleBrowserEvent,
nsnull, aAppShell);
mWindow->GetBounds(r);
// Create web shell
rv = nsRepository::CreateInstance(kWebShellCID, nsnull,
kIWebShellIID,
(void**)&mWebShell);
if (NS_OK != rv) {
return rv;
}
r.x = r.y = 0;
nsRect ws = r;
rv = mWebShell->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET),
r.x, r.y, r.width, r.height,
nsScrollPreference_kAuto, aAllowPlugins);
mWebShell->SetContainer((nsIWebShellContainer*) this);
mWebShell->SetObserver((nsIStreamObserver*)this);
mWebShell->SetPrefs(aPrefs);
if (NS_CHROME_MENU_BAR_ON & aChromeMask) {
rv = CreateMenuBar(r.width);
if (NS_OK != rv) {
return rv;
}
mWindow->GetBounds(r);
r.x = r.y = 0;
}
if (NS_CHROME_TOOL_BAR_ON & aChromeMask) {
rv = CreateToolBar(r.width);
if (NS_OK != rv) {
return rv;
}
}
if (NS_CHROME_STATUS_BAR_ON & aChromeMask) {
rv = CreateStatusBar(r.width);
if (NS_OK != rv) {
return rv;
}
}
// Now lay it all out
Layout(r.width, r.height);
// Create a document viewer and bind it to the webshell
nsIDocumentViewer* docv;
aDocumentViewer->CreateDocumentViewerUsing(aPresContext, docv);
mWebShell->Embed(docv, "duh", nsnull);
mWebShell->Show();
NS_RELEASE(docv);
return NS_OK;
}
// XXX This sort of thing should be in a resource
#define TOOL_BAR_FONT "Helvetica"
#define TOOL_BAR_FONT_SIZE 12
@@ -1714,6 +1803,44 @@ nsBrowserWindow::DoCopy()
//----------------------------------------------------------------------
void
nsBrowserWindow::ShowPrintPreview(PRInt32 aID)
{
nsIContentViewer* cv = nsnull;
if (nsnull != mWebShell) {
if ((NS_OK == mWebShell->GetContentViewer(cv)) && (nsnull != cv)) {
nsIDocumentViewer* docv = nsnull;
if (NS_OK == cv->QueryInterface(kIDocumentViewerIID, (void**)&docv)) {
nsIPresContext* printContext;
if (NS_OK == NS_NewPrintPreviewContext(&printContext)) {
// Prepare new printContext for print-preview
nsIDeviceContext* dc;
nsIPresContext* presContext;
docv->GetPresContext(presContext);
dc = presContext->GetDeviceContext();
printContext->Init(dc, mPrefs);
NS_RELEASE(presContext);
NS_RELEASE(dc);
// Make a window using that content viewer
nsBrowserWindow* bw = new nsNativeBrowserWindow();
bw->Init(mAppShell, mPrefs, nsRect(0, 0, 600, 400),
NS_CHROME_MENU_BAR_ON, PR_TRUE,
docv, printContext);
bw->Show();
NS_RELEASE(printContext);
}
NS_RELEASE(docv);
}
NS_RELEASE(cv);
}
}
}
//----------------------------------------------------------------------
void
nsBrowserWindow::DoJSConsole()
{

View File

@@ -37,6 +37,8 @@ class nsITextWidget;
class nsIButton;
class nsIThrobber;
class nsViewerApp;
class nsIDocumentViewer;
class nsIPresContext;
class nsIPresShell;
class nsIPref;
@@ -133,6 +135,8 @@ public:
void DoSelectAll();
void ForceRefresh();
void ShowPrintPreview(PRInt32 aID);
#ifdef NS_DEBUG
void DumpContent(FILE *out = stdout);
void DumpFrames(FILE *out = stdout, nsString *aFilter = nsnull);
@@ -154,6 +158,15 @@ public:
nsEventStatus ProcessDialogEvent(nsGUIEvent *aEvent);
// Initialize a second view on a different browser windows document
// viewer.
nsresult Init(nsIAppShell* aAppShell,
nsIPref* aPrefs,
const nsRect& aBounds,
PRUint32 aChromeMask,
PRBool aAllowPlugins,
nsIDocumentViewer* aDocViewer,
nsIPresContext* aPresContext);
void SetApp(nsViewerApp* aApp) {
mApp = aApp;