Added HTML dialog support for "Find" and "PrintSetup"

git-svn-id: svn://10.0.0.236/trunk@16567 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rods%netscape.com
1998-12-17 15:52:48 +00:00
parent 53c8b2569f
commit 6a3999f05a
21 changed files with 2504 additions and 137 deletions

View File

@@ -20,6 +20,8 @@ topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
DIRS=public
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
@@ -57,7 +59,11 @@ endif
endif
CPPSRCS = \
$(TOOLKIT_CPPSRCS) \
$(TOOLKIT_CPPSRCS) \
nsBaseDialog.cpp \
nsFindDialog.cpp \
nsXPBaseWindow.cpp \
nsPrintSetupDialog.cpp \
nsBrowserWindow.cpp \
nsEditorMode.cpp \
nsEditorInterfaces.cpp \
@@ -160,6 +166,8 @@ export::
install:: $(TARGETS)
$(INSTALL) $(PROGS) $(DIST)/bin
$(INSTALL) $(srcdir)/resources/find.html $(DIST)/bin/res/samples
$(INSTALL) $(srcdir)/resources/printsetup.html $(DIST)/bin/res/samples
$(INSTALL) $(srcdir)/samples/test0.html $(DIST)/bin/res/samples
$(INSTALL) $(srcdir)/samples/test1.html $(DIST)/bin/res/samples
$(INSTALL) $(srcdir)/samples/test2.html $(DIST)/bin/res/samples
@@ -198,6 +206,8 @@ install:: $(TARGETS)
clobber::
rm -f $(DIST)/bin/viewer.exe
rm -f $(DIST)/bin/res/samples/find.html
rm -f $(DIST)/bin/res/samples/printsetup.html
rm -f $(DIST)/bin/res/samples/test0.html
rm -f $(DIST)/bin/res/samples/test1.html
rm -f $(DIST)/bin/res/samples/test2.html

View File

@@ -18,6 +18,8 @@
DEPTH=..\..\..
IGNORE_MANIFEST=1
DIRS=public
MAKE_OBJ_TYPE = EXE
PROGRAM = .\$(OBJDIR)\viewer.exe
RESFILE = viewer.res
@@ -34,6 +36,10 @@ MISCDEP= \
OBJS = \
.\$(OBJDIR)\nsBaseDialog.obj \
.\$(OBJDIR)\nsFindDialog.obj \
.\$(OBJDIR)\nsPrintSetupDialog.obj \
.\$(OBJDIR)\nsXPBaseWindow.obj \
.\$(OBJDIR)\nsBrowserWindow.obj \
.\$(OBJDIR)\nsEditorInterfaces.obj \
.\$(OBJDIR)\nsEditorMode.obj \
@@ -102,6 +108,8 @@ OS_CFLAGS = $(OS_CFLAGS) -DNGPREFS
install:: $(PROGRAM)
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
$(MAKE_INSTALL) resources\find.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) resources\printsetup.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test0.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test1.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\test2.html $(DIST)\bin\res\samples
@@ -143,6 +151,8 @@ install:: $(PROGRAM)
clobber::
rm -f $(DIST)\bin\viewer.exe
rm -f $(DIST)\bin\res\samples\find.html
rm -f $(DIST)\bin\res\samples\printsetup.html
rm -f $(DIST)\bin\res\samples\test0.html
rm -f $(DIST)\bin\res\samples\test1.html
rm -f $(DIST)\bin\res\samples\test2.html

View File

@@ -0,0 +1,223 @@
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsBaseDialog.h"
#include "nsIDOMEvent.h"
#include "nsIXPBaseWindow.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLDocument.h"
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
//-------------------------------------------------------------------------
//
// nsBaseDialog constructor
//
//-------------------------------------------------------------------------
//-----------------------------------------------------------------
nsBaseDialog::nsBaseDialog(nsBrowserWindow * aBrowserWindow) :
mBrowserWindow(aBrowserWindow),
mCancelBtn(nsnull),
mWindow(nsnull)
{
}
//-----------------------------------------------------------------
nsBaseDialog::~nsBaseDialog()
{
NS_IF_RELEASE(mWindow);
}
//---------------------------------------------------------------
void nsBaseDialog::Initialize(nsIXPBaseWindow * aWindow)
{
mWindow = aWindow;
NS_ADDREF(mWindow);
nsIDOMHTMLDocument *doc = nsnull;
mWindow->GetDocument(doc);
if (nsnull != doc) {
doc->GetElementById("cancel", &mCancelBtn);
if (nsnull != mCancelBtn) {
mWindow->AddEventListener(mCancelBtn);
}
NS_RELEASE(doc);
}
}
//-----------------------------------------------------------------
void nsBaseDialog::Destroy(nsIXPBaseWindow * aWindow)
{
// Unregister event listeners that were registered in the
// Initialize here.
// XXX: Should change code in XPBaseWindow to automatically unregister
// all event listening, That way this code will not be necessary.
if (nsnull != mCancelBtn) {
aWindow->RemoveEventListener(mCancelBtn);
}
}
//-----------------------------------------------------------------
void nsBaseDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow, PRBool &aStatus)
{
// Event Dispatch. This method should not contain
// anything but calls to methods. This idea is that this dispatch
// mechanism may be replaced by JavaScript EventHandlers which call the idl'ed
// interfaces to perform the same operation that is currently being handled by
// this C++ code.
aStatus = PR_FALSE;
nsIDOMNode * node;
aMouseEvent->GetTarget(&node);
if (node == mCancelBtn) {
DoClose();
aStatus = PR_TRUE;
}
NS_RELEASE(node);
}
//---------------------------------------------------------------
void
nsBaseDialog::DoClose()
{
mWindow->SetVisible(PR_FALSE);
}
//---------------------------------------------------------------
PRBool
nsBaseDialog::IsChecked(nsIDOMElement * aNode)
{
nsIDOMHTMLInputElement * element;
if (NS_OK == aNode->QueryInterface(kIDOMHTMLInputElementIID, (void**) &element)) {
PRBool checked;
element->GetChecked(&checked);
NS_RELEASE(element);
return checked;
}
return PR_FALSE;
}
//-----------------------------------------------------------------
PRBool
nsBaseDialog::IsChecked(const nsString & aName)
{
nsIDOMElement * node;
nsIDOMHTMLDocument * doc = nsnull;
mWindow->GetDocument(doc);
if (nsnull != doc) {
if (NS_OK == doc->GetElementById(aName, &node)) {
PRBool value = IsChecked(node);
NS_RELEASE(node);
NS_RELEASE(doc);
return value;
}
NS_RELEASE(doc);
}
return PR_FALSE;
}
//---------------------------------------------------------------
void
nsBaseDialog::SetChecked(nsIDOMElement * aNode, PRBool aValue)
{
nsIDOMHTMLInputElement * element;
if (NS_OK == aNode->QueryInterface(kIDOMHTMLInputElementIID, (void**) &element)) {
element->SetChecked(aValue);
NS_RELEASE(element);
}
}
//---------------------------------------------------------------
void
nsBaseDialog::SetChecked(const nsString & aName, PRBool aValue)
{
nsIDOMElement * node;
nsIDOMHTMLDocument * doc = nsnull;
mWindow->GetDocument(doc);
if (nsnull != doc) {
if (NS_OK == doc->GetElementById(aName, &node)) {
SetChecked(node, aValue);
NS_RELEASE(node);
}
NS_RELEASE(doc);
}
}
//-----------------------------------------------------------------
void nsBaseDialog::GetText(nsIDOMElement * aNode, nsString & aStr)
{
nsIDOMHTMLInputElement * element;
if (NS_OK == aNode->QueryInterface(kIDOMHTMLInputElementIID, (void**) &element)) {
element->GetValue(aStr);
NS_RELEASE(element);
}
}
//-----------------------------------------------------------------
void nsBaseDialog::GetText(const nsString & aName, nsString & aStr)
{
nsIDOMElement * node;
nsIDOMHTMLDocument * doc = nsnull;
mWindow->GetDocument(doc);
if (nsnull != doc) {
if (NS_OK == doc->GetElementById(aName, &node)) {
GetText(node, aStr);
NS_RELEASE(node);
}
NS_RELEASE(doc);
}
}
//---------------------------------------------------------------
void
nsBaseDialog::SetText(nsIDOMElement * aNode, const nsString &aValue)
{
nsIDOMHTMLInputElement * element;
if (NS_OK == aNode->QueryInterface(kIDOMHTMLInputElementIID, (void**) &element)) {
element->SetValue(aValue);
NS_RELEASE(element);
}
}
//-----------------------------------------------------------------
void nsBaseDialog::SetText(const nsString & aName, const nsString & aStr)
{
nsIDOMElement * node;
nsIDOMHTMLDocument * doc = nsnull;
mWindow->GetDocument(doc);
if (nsnull != doc) {
if (NS_OK == doc->GetElementById(aName, &node)) {
SetText(node, aStr);
NS_RELEASE(node);
}
NS_RELEASE(doc);
}
}
//-----------------------------------------------------------------
float nsBaseDialog::GetFloat(nsString & aStr)
{
return (float)0.0;
}

View File

@@ -0,0 +1,65 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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 Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsBaseDialog_h___
#define nsBaseDialog_h___
//#include "nsBrowserWindow.h"
#include "nsIWindowListener.h"
#include "nsIDOMElement.h"
class nsIXPBaseWindow;
class nsBrowserWindow;
/**
* Implement Navigator Find Dialog
*/
class nsBaseDialog : public nsIWindowListener
{
public:
nsBaseDialog(nsBrowserWindow * aBrowserWindow);
virtual ~nsBaseDialog();
virtual void DoClose();
// nsIWindowListener Methods
virtual void MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow, PRBool &aStatus);
virtual void Initialize(nsIXPBaseWindow * aWindow);
virtual void Destroy(nsIXPBaseWindow * aWindow);
protected:
PRBool IsChecked(const nsString & aName);
PRBool IsChecked(nsIDOMElement * aNode);
void SetChecked(nsIDOMElement * aNode, PRBool aValue);
void SetChecked(const nsString & aName, PRBool aValue);
void GetText(nsIDOMElement * aNode, nsString & aStr);
void GetText(const nsString & aName, nsString & aStr);
float GetFloat(nsString & aStr);
void SetText(nsIDOMElement * aNode, const nsString &aValue);
void SetText(const nsString & aName, const nsString & aStr);
nsBrowserWindow * mBrowserWindow;
nsIXPBaseWindow * mWindow;
nsIDOMElement * mCancelBtn;
};
#endif /* nsBaseDialog_h___ */

View File

@@ -66,6 +66,9 @@
#include "nsILabel.h"
#include "nsWidgetSupport.h"
#include "nsXPBaseWindow.h"
#include "nsFindDialog.h"
#include "nsIContentConnector.h"
#include "resources.h"
@@ -130,6 +133,7 @@ static NS_DEFINE_IID(kDialogCID, NS_DIALOG_CID);
static NS_DEFINE_IID(kCheckButtonCID, NS_CHECKBUTTON_CID);
static NS_DEFINE_IID(kRadioButtonCID, NS_RADIOBUTTON_CID);
static NS_DEFINE_IID(kLabelCID, NS_LABEL_CID);
static NS_DEFINE_IID(kIXPBaseWindowIID, NS_IXPBASE_WINDOW_IID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
@@ -153,6 +157,7 @@ static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID);
static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID);
static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
static NS_DEFINE_IID(kXPBaseWindowCID, NS_XPBASE_WINDOW_CID);
static const char* gsAOLFormat = "AOLMAIL";
@@ -462,6 +467,11 @@ nsBrowserWindow::DispatchMenuItem(PRInt32 aID)
case VIEWER_PRINT:
DoPrint();
break;
case VIEWER_PRINT_SETUP:
DoPrintSetup();
break;
#if defined(XP_WIN) || defined(XP_MAC)
case VIEWER_TREEVIEW:
// Instantiate a tree widget
@@ -920,144 +930,34 @@ nsBrowserWindow::DoTreeView()
void
nsBrowserWindow::DoFind()
{
if (mDialog == nsnull) {
nscoord txtHeight = 24;
nscolor textBGColor = NS_RGB(0, 0, 0);
nscolor textFGColor = NS_RGB(255, 255, 255);
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextFieldHeight, txtHeight);
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, textBGColor);
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, textFGColor);
NS_RELEASE(lookAndFeel);
}
nsIDeviceContext* dc = mWindow->GetDeviceContext();
float t2d;
dc->GetTwipsToDevUnits(t2d);
nsFont font(DIALOG_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, 0,
nscoord(t2d * NSIntPointsToTwips(DIALOG_FONT_SIZE)));
NS_RELEASE(dc);
// create a Dialog
//
nsRect rect;
rect.SetRect(0, 0, 380, 110);
nsRepository::CreateInstance(kDialogCID, nsnull, kIDialogIID, (void**)&mDialog);
if (nsnull == mDialog)
return; // why no error value?
nsIWidget* widget = nsnull;
NS_CreateDialog(mWindow,mDialog,rect,HandleEvent,&font);
if (NS_OK == mDialog->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetClientData(this);
NS_RELEASE(widget);
}
mDialog->SetLabel("Find");
nscoord xx = 5;
// Create Label
rect.SetRect(xx, 8, 75, 24);
nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&mLabel);
NS_CreateLabel(mDialog,mLabel,rect,HandleEvent,&font);
if (NS_OK == mLabel->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetClientData(this);
mLabel->SetAlignment(eAlign_Right);
mLabel->SetLabel("Find what:");
NS_RELEASE(widget);
}
xx += 75 + 5;
// Create TextField
rect.SetRect(xx, 5, 200, txtHeight);
nsRepository::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID, (void**)&mTextField);
NS_CreateTextWidget(mDialog,mTextField,rect,HandleEvent,&font);
if (NS_OK == mTextField->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetBackgroundColor(textBGColor);
widget->SetForegroundColor(textFGColor);
widget->SetClientData(this);
widget->SetFocus();
NS_RELEASE(widget);
}
xx += 200 + 5;
nscoord w = 65;
nscoord x = 205+80-w;
nscoord y = txtHeight + 10;
nscoord h = 19;
// Create Up RadioButton
rect.SetRect(x, y, w, h);
nsRepository::CreateInstance(kRadioButtonCID, nsnull, kIRadioButtonIID, (void**)&mUpRadioBtn);
NS_CreateRadioButton(mDialog,mUpRadioBtn,rect,HandleEvent,&font);
if (NS_OK == mUpRadioBtn->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetClientData(this);
mUpRadioBtn->SetLabel("Up");
NS_RELEASE(widget);
}
y += h + 2;
// Create Up RadioButton
rect.SetRect(x, y, w, h);
nsRepository::CreateInstance(kRadioButtonCID, nsnull, kIRadioButtonIID, (void**)&mDwnRadioBtn);
NS_CreateRadioButton(mDialog,mDwnRadioBtn,rect,HandleEvent,&font);
if (NS_OK == mDwnRadioBtn->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetClientData(this);
mDwnRadioBtn->SetLabel("Down");
NS_RELEASE(widget);
}
// Create Match CheckButton
rect.SetRect(5, y, 125, 24);
nsRepository::CreateInstance(kCheckButtonCID, nsnull, kICheckButtonIID, (void**)&mMatchCheckBtn);
NS_CreateCheckButton(mDialog,mMatchCheckBtn,rect,HandleEvent,&font);
if (NS_OK == mMatchCheckBtn->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetClientData(this);
mMatchCheckBtn->SetLabel("Match Case");
NS_RELEASE(widget);
}
mUpRadioBtn->SetState(PR_FALSE);
mDwnRadioBtn->SetState(PR_TRUE);
// Create Find Next Button
rect.SetRect(xx, 5, 75, 24);
nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mFindBtn);
NS_CreateButton(mDialog,mFindBtn,rect,HandleEvent,&font);
if (NS_OK == mFindBtn->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetClientData(this);
mFindBtn->SetLabel("Find Next");
NS_RELEASE(widget);
}
// Create Cancel Button
rect.SetRect(xx, 35, 75, 24);
nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mCancelBtn);
NS_CreateButton(mDialog,mCancelBtn,rect,HandleEvent,&font);
if (NS_OK == mCancelBtn->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetClientData(this);
mCancelBtn->SetLabel("Cancel");
NS_RELEASE(widget);
}
if (mXPDialog) {
NS_RELEASE(mXPDialog);
//mXPDialog->SetVisible(PR_TRUE);
//return;
}
else {
nsIWidget* dialogWidget = nsnull;
if (NS_OK == mDialog->QueryInterface(kIWidgetIID,(void**)&dialogWidget)) {
dialogWidget->Show(PR_TRUE);
}
nsString findHTML("resource:/res/samples/find.html");
//nsString findHTML("resource:/res/samples/find-table.html");
nsRect rect(0, 0, 510, 170);
//nsRect rect(0, 0, 470, 126);
nsString title("Find");
nsXPBaseWindow * dialog = nsnull;
nsresult rv = nsRepository::CreateInstance(kXPBaseWindowCID, nsnull,
kIXPBaseWindowIID,
(void**) &dialog);
if (rv == NS_OK) {
dialog->Init(eXPBaseWindowType_dialog, mAppShell, nsnull, findHTML, title, rect, PRUint32(~0), PR_FALSE);
dialog->SetVisible(PR_TRUE);
if (NS_OK == dialog->QueryInterface(kIXPBaseWindowIID, (void**) &mXPDialog)) {
}
}
mTextField->SelectAll();
nsFindDialog * findDialog = new nsFindDialog(this);
if (nsnull != findDialog) {
dialog->AddWindowListener(findDialog);
}
//NS_IF_RELEASE(dialog);
}
@@ -2190,6 +2090,60 @@ void nsBrowserWindow::DoPrint(void)
}
}
//---------------------------------------------------------------
void nsBrowserWindow::DoPrintSetup()
{
if (mXPDialog) {
NS_RELEASE(mXPDialog);
//mXPDialog->SetVisible(PR_TRUE);
//return;
}
nsString printHTML("resource:/res/samples/printsetup.html");
nsRect rect(0, 0, 375, 510);
nsString title("Print Setup");
nsXPBaseWindow * dialog = nsnull;
nsresult rv = nsRepository::CreateInstance(kXPBaseWindowCID, nsnull,
kIXPBaseWindowIID,
(void**) &dialog);
if (rv == NS_OK) {
dialog->Init(eXPBaseWindowType_dialog, mAppShell, nsnull, printHTML, title, rect, PRUint32(~0), PR_FALSE);
dialog->SetVisible(PR_TRUE);
if (NS_OK == dialog->QueryInterface(kIXPBaseWindowIID, (void**) &mXPDialog)) {
}
}
mPrintSetupInfo.mPortrait = PR_TRUE;
mPrintSetupInfo.mBevelLines = PR_TRUE;
mPrintSetupInfo.mBlackText = PR_FALSE;
mPrintSetupInfo.mBlackLines = PR_FALSE;
mPrintSetupInfo.mLastPageFirst = PR_FALSE;
mPrintSetupInfo.mPrintBackgrounds = PR_FALSE;
mPrintSetupInfo.mTopMargin = 0.50;
mPrintSetupInfo.mBottomMargin = 0.50;
mPrintSetupInfo.mLeftMargin = 0.50;
mPrintSetupInfo.mRightMargin = 0.50;
mPrintSetupInfo.mDocTitle = PR_TRUE;
mPrintSetupInfo.mDocLocation = PR_TRUE;
mPrintSetupInfo.mHeaderText = "Header Text";
mPrintSetupInfo.mFooterText = "Footer Text";
mPrintSetupInfo.mPageNum = PR_TRUE;
mPrintSetupInfo.mPageTotal = PR_TRUE;
mPrintSetupInfo.mDatePrinted = PR_TRUE;
nsPrintSetupDialog * printSetupDialog = new nsPrintSetupDialog(this);
if (nsnull != printSetupDialog) {
dialog->AddWindowListener(printSetupDialog);
}
printSetupDialog->SetSetupInfo(mPrintSetupInfo);
//NS_IF_RELEASE(dialog);
}
//----------------------------------------------------------------------
void

View File

@@ -29,6 +29,10 @@
#include "nsCRT.h"
//#include "nsIPref.h"
#include "nsIXPBaseWindow.h"
#include "nsPrintSetupDialog.h"
#include "nsFindDialog.h"
class nsILabel;
class nsICheckButton;
class nsIRadioButton;
@@ -144,6 +148,7 @@ public:
void ShowPrintPreview(PRInt32 aID);
void DoPrint(void);
void DoPrintSetup(void);
#ifdef NS_DEBUG
void DumpContent(FILE *out = stdout);
@@ -210,6 +215,9 @@ public:
nsIRadioButton * mDwnRadioBtn;
nsILabel * mLabel;
nsIXPBaseWindow * mXPDialog;
PrintSetupInfo mPrintSetupInfo;
//for creating more instances
nsIAppShell* mAppShell;
nsIPref* mPrefs;

View File

@@ -0,0 +1,139 @@
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsFindDialog.h"
#include "nsIDOMEvent.h"
#include "nsIXPBaseWindow.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLDocument.h"
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
//-------------------------------------------------------------------------
//
// nsFindDialog constructor
//
//-------------------------------------------------------------------------
//-----------------------------------------------------------------
nsFindDialog::nsFindDialog(nsBrowserWindow * aBrowserWindow) :
nsBaseDialog(aBrowserWindow),
mFindBtn(nsnull),
mSearchDown(PR_TRUE)
{
}
//-----------------------------------------------------------------
nsFindDialog::~nsFindDialog()
{
}
//---------------------------------------------------------------
void nsFindDialog::Initialize(nsIXPBaseWindow * aWindow)
{
nsBaseDialog::Initialize(aWindow);
nsIDOMHTMLDocument *doc = nsnull;
mWindow->GetDocument(doc);
if (nsnull != doc) {
doc->GetElementById("find", &mFindBtn);
doc->GetElementById("searchup", &mUpRB);
doc->GetElementById("searchdown", &mDwnRB);
doc->GetElementById("matchcase", &mMatchCaseCB);
// XXX: Register event listening on each dom element. We should change this so
// all DOM events are automatically passed through.
aWindow->AddEventListener(mFindBtn);
aWindow->AddEventListener(mUpRB);
aWindow->AddEventListener(mDwnRB);
SetChecked(mMatchCaseCB, PR_FALSE);
NS_RELEASE(doc);
}
}
//-----------------------------------------------------------------
void nsFindDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow, PRBool &aStatus)
{
// Event Dispatch. This method should not contain
// anything but calls to methods. This idea is that this dispatch
// mechanism may be replaced by JavaScript EventHandlers which call the idl'ed
// interfaces to perform the same operation that is currently being handled by
// this C++ code.
nsBaseDialog::MouseClick(aMouseEvent, aWindow, aStatus);
if (!aStatus) { // is not consumed
nsIDOMNode * node;
aMouseEvent->GetTarget(&node);
if (node == mFindBtn) {
DoFind();
}
NS_RELEASE(node);
}
}
//-----------------------------------------------------------------
void nsFindDialog::Destroy(nsIXPBaseWindow * aWindow)
{
// Unregister event listeners that were registered in the
// Initialize here.
// XXX: Should change code in XPBaseWindow to automatically unregister
// all event listening, That way this code will not be necessary.
aWindow->RemoveEventListener(mFindBtn);
}
//---------------------------------------------------------------
void
nsFindDialog::DoFind()
{
// Now we have the content tree, lets find the
// widgets holding the info.
nsIDOMElement * textNode = nsnull;
nsIDOMHTMLDocument *doc = nsnull;
mWindow->GetDocument(doc);
if (nsnull != doc) {
if (NS_OK == doc->GetElementById("query", &textNode)) {
nsIDOMHTMLInputElement * element;
if (NS_OK == textNode->QueryInterface(kIDOMHTMLInputElementIID, (void**) &element)) {
nsString str;
PRBool foundIt = PR_FALSE;
element->GetValue(str);
PRBool searchDown = IsChecked(mDwnRB);
PRBool matchcase = IsChecked(mMatchCaseCB);
mBrowserWindow->FindNext(str, matchcase, searchDown, foundIt);
if (foundIt) {
mBrowserWindow->ForceRefresh();
}
NS_RELEASE(element);
}
NS_RELEASE(textNode);
}
NS_RELEASE(doc);
}
}
//---------------------------------------------------------------
void
nsFindDialog::DoClose()
{
mWindow->SetVisible(PR_FALSE);
}

View File

@@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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 Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsFindDialog_h___
#define nsFindDialog_h___
#include "nsBrowserWindow.h"
#include "nsBaseDialog.h"
#include "nsIDOMElement.h"
/**
* Implement Navigator Find Dialog
*/
class nsFindDialog : public nsBaseDialog
{
public:
nsFindDialog(nsBrowserWindow * aBrowserWindow);
virtual ~nsFindDialog();
// nsIWindowListener Methods
virtual void MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow, PRBool &aStatus);
virtual void Initialize(nsIXPBaseWindow * aWindow);
virtual void Destroy(nsIXPBaseWindow * aWindow);
virtual void DoClose();
// new methods
virtual void DoFind();
protected:
nsIDOMElement * mFindBtn;
nsIDOMElement * mUpRB;
nsIDOMElement * mDwnRB;
nsIDOMElement * mMatchCaseCB;
PRBool mSearchDown;
};
#endif /* nsFindDialog_h___ */

View File

@@ -0,0 +1,217 @@
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsPrintSetupDialog.h"
#include "nsIDOMEvent.h"
#include "nsIXPBaseWindow.h"
#include "nsBrowserWindow.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLDocument.h"
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
PrintSetupInfo::PrintSetupInfo(const PrintSetupInfo & aPSI) :
mPortrait(aPSI.mPortrait),
mBevelLines(aPSI.mBevelLines),
mBlackText(aPSI.mBlackText),
mBlackLines(aPSI.mBlackLines),
mLastPageFirst(aPSI.mLastPageFirst),
mPrintBackgrounds(aPSI.mPrintBackgrounds),
mTopMargin(aPSI.mTopMargin),
mBottomMargin(aPSI.mBottomMargin),
mLeftMargin(aPSI.mLeftMargin),
mRightMargin(aPSI.mRightMargin),
mDocTitle(aPSI.mDocTitle),
mDocLocation(aPSI.mDocLocation),
mHeaderText(aPSI.mHeaderText),
mPageNum(aPSI.mPageNum),
mPageTotal(aPSI.mPageTotal),
mDatePrinted(aPSI.mDatePrinted),
mFooterText(aPSI.mFooterText)
{
}
//-------------------------------------------------------------------------
//
// nsPrintSetupDialog constructor
//
//-------------------------------------------------------------------------
//-----------------------------------------------------------------
nsPrintSetupDialog::nsPrintSetupDialog(nsBrowserWindow * aBrowserWindow) :
nsBaseDialog(aBrowserWindow),
mOKBtn(nsnull),
mPrinterSetupInfo(nsnull)
{
}
//-----------------------------------------------------------------
nsPrintSetupDialog::~nsPrintSetupDialog()
{
}
//---------------------------------------------------------------
void nsPrintSetupDialog::Initialize(nsIXPBaseWindow * aWindow)
{
nsBaseDialog::Initialize(aWindow);
nsIDOMHTMLDocument *doc = nsnull;
mWindow->GetDocument(doc);
if (nsnull != doc) {
doc->GetElementById("ok", &mOKBtn);
// XXX: Register event listening on each dom element. We should change this so
// all DOM events are automatically passed through.
mWindow->AddEventListener(mOKBtn);
//SetChecked(mMatchCaseCB, PR_FALSE);
NS_RELEASE(doc);
if (nsnull != mPrinterSetupInfo) {
SetSetupInfoInternal(*mPrinterSetupInfo);
delete mPrinterSetupInfo;
mPrinterSetupInfo = nsnull;
}
}
}
//-----------------------------------------------------------------
void nsPrintSetupDialog::GetSetupInfo(PrintSetupInfo & aPSI)
{
aPSI.mPortrait = IsChecked("portrait");
aPSI.mBevelLines = IsChecked("bevellines");
aPSI.mBlackText = IsChecked("blacktext");
aPSI.mBlackLines = IsChecked("blacklines");
aPSI.mLastPageFirst = IsChecked("lastpagefirst");
aPSI.mPrintBackgrounds = IsChecked("printbg");
nsString str;
GetText("toptext", str);
aPSI.mTopMargin = GetFloat(str);
GetText("lefttext", str);
aPSI.mLeftMargin = GetFloat(str);
GetText("bottomtext", str);
aPSI.mBottomMargin = GetFloat(str);
GetText("righttext", str);
aPSI.mRightMargin = GetFloat(str);
GetText("lefttext", str);
GetText("bottomtext", str);
GetText("righttext", str);
nsString header("");
nsString footer("");
GetText("headertext", header);
GetText("footertext", footer);
aPSI.mHeaderText = header;
aPSI.mFooterText = footer;
//GetText("headertext", aPSI.mHeaderText);
//GetText("footertext", aPSI.mFooterText);
aPSI.mDocTitle = IsChecked("doctitle");
aPSI.mDocLocation = IsChecked("docloc");
aPSI.mPageNum = IsChecked("pagenum");
aPSI.mPageTotal = IsChecked("pagetotal");
aPSI.mDatePrinted = IsChecked("dateprinted");
}
//-----------------------------------------------------------------
void nsPrintSetupDialog::SetSetupInfo(const PrintSetupInfo & aPSI)
{
if (nsnull == mWindow) {
mPrinterSetupInfo = new PrintSetupInfo(aPSI);
} else {
SetSetupInfoInternal(aPSI);
}
}
//-----------------------------------------------------------------
void nsPrintSetupDialog::SetSetupInfoInternal(const PrintSetupInfo & aPSI)
{
SetChecked("portrait", aPSI.mPortrait);
SetChecked("bevellines", aPSI.mBevelLines);
SetChecked("blacktext", aPSI.mBlackText);
SetChecked("blacklines", aPSI.mBlackLines);
SetChecked("lastpagefirst", aPSI.mLastPageFirst);
SetChecked("printbg", aPSI.mPrintBackgrounds);
char str[64];
sprintf(str, "%5.2f", aPSI.mTopMargin);
SetText("toptext", str);
sprintf(str, "%5.2f", aPSI.mLeftMargin);
SetText("lefttext", str);
sprintf(str, "%5.2f", aPSI.mBottomMargin);
SetText("bottomtext", str);
sprintf(str, "%5.2f", aPSI.mRightMargin);
SetText("righttext", str);
SetText("headertext", aPSI.mHeaderText);
SetText("footertext", aPSI.mFooterText);
SetChecked("doctitle", aPSI.mDocTitle);
SetChecked("docloc", aPSI.mDocLocation);
SetChecked("pagenum", aPSI.mPageNum);
SetChecked("pagetotal", aPSI.mPageTotal);
SetChecked("dateprinted", aPSI.mDatePrinted);
}
//-----------------------------------------------------------------
void nsPrintSetupDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow, PRBool &aStatus)
{
// Event Dispatch. This method should not contain
// anything but calls to methods. This idea is that this dispatch
// mechanism may be replaced by JavaScript EventHandlers which call the idl'ed
// interfaces to perform the same operation that is currently being handled by
// this C++ code.
nsBaseDialog::MouseClick(aMouseEvent, aWindow, aStatus);
if (!aStatus) { // is not consumed
nsIDOMNode * node;
aMouseEvent->GetTarget(&node);
if (node == mOKBtn) {
GetSetupInfo(mBrowserWindow->mPrintSetupInfo);
DoClose();
}
NS_RELEASE(node);
}
}
//-----------------------------------------------------------------
void nsPrintSetupDialog::Destroy(nsIXPBaseWindow * aWindow)
{
// Unregister event listeners that were registered in the
// Initialize here.
// XXX: Should change code in XPBaseWindow to automatically unregister
// all event listening, That way this code will not be necessary.
aWindow->RemoveEventListener(mOKBtn);
}
void
nsPrintSetupDialog::DoClose()
{
mWindow->SetVisible(PR_FALSE);
}

View File

@@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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 Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsPrintSetupDialog_h___
#define nsPrintSetupDialog_h___
#include "nsBaseDialog.h"
#include "nsIDOMElement.h"
class PrintSetupInfo {
public:
PRBool mPortrait;
PRBool mBevelLines;
PRBool mBlackText;
PRBool mBlackLines;
PRBool mLastPageFirst;
PRBool mPrintBackgrounds;
float mTopMargin;
float mBottomMargin;
float mLeftMargin;
float mRightMargin;
PRBool mDocTitle;
PRBool mDocLocation;
nsString mHeaderText;
PRBool mPageNum;
PRBool mPageTotal;
PRBool mDatePrinted;
nsString mFooterText;
PrintSetupInfo() : mHeaderText(""), mFooterText("") {}
PrintSetupInfo(const PrintSetupInfo & aPSI);
};
class nsBrowserWindow;
/**
* Implement Navigator Find Dialog
*/
class nsPrintSetupDialog : public nsBaseDialog
{
public:
nsPrintSetupDialog(nsBrowserWindow * aBrowserWindow);
virtual ~nsPrintSetupDialog();
virtual void DoClose();
// nsIWindowListener Methods
virtual void MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow, PRBool &aStatus);
virtual void Initialize(nsIXPBaseWindow * aWindow);
virtual void Destroy(nsIXPBaseWindow * aWindow);
// new methods
virtual void GetSetupInfo(PrintSetupInfo & anInfo);
virtual void SetSetupInfo(const PrintSetupInfo & anInfo);
protected:
void SetSetupInfoInternal(const PrintSetupInfo & anInfo);
nsIDOMElement * mOKBtn;
PrintSetupInfo * mPrinterSetupInfo;
};
#endif /* nsPrintSetupDialog_h___ */

View File

@@ -20,6 +20,7 @@
#ifdef NGPREFS
#define INITGUID
#endif
#include "nsXPBaseWindow.h"
#include "nsViewerApp.h"
#include "nsBrowserWindow.h"
#include "nsWidgetsCID.h"
@@ -66,14 +67,17 @@
#endif
extern nsresult NS_NewBrowserWindowFactory(nsIFactory** aFactory);
extern nsresult NS_NewXPBaseWindowFactory(nsIFactory** aFactory);
extern "C" void NS_SetupRegistry();
static NS_DEFINE_IID(kAppShellCID, NS_APPSHELL_CID);
static NS_DEFINE_IID(kBrowserWindowCID, NS_BROWSER_WINDOW_CID);
static NS_DEFINE_IID(kXPBaseWindowCID, NS_XPBASE_WINDOW_CID);
static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIXPBaseWindowIID, NS_IXPBASE_WINDOW_IID);
@@ -159,6 +163,9 @@ nsViewerApp::SetupRegistry()
NS_NewBrowserWindowFactory(&bwf);
nsRepository::RegisterFactory(kBrowserWindowCID, bwf, PR_FALSE);
NS_NewXPBaseWindowFactory(&bwf);
nsRepository::RegisterFactory(kXPBaseWindowCID, bwf, PR_FALSE);
return NS_OK;
}

View File

@@ -0,0 +1,888 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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 Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIPref.h"
#include "prmem.h"
#ifdef XP_MAC
#include "nsXPBaseWindow.h"
#define NS_IMPL_IDS
#else
#define NS_IMPL_IDS
#include "nsXPBaseWindow.h"
#endif
#include "nsINetSupport.h"
#include "nsIAppShell.h"
#include "nsIWidget.h"
#include "nsIDOMDocument.h"
#include "nsIURL.h"
#include "nsRepository.h"
#include "nsIFactory.h"
#include "nsCRT.h"
#include "nsWidgetsCID.h"
#include "nsViewerApp.h"
#include "nsIDocument.h"
#include "nsIPresContext.h"
#include "nsIDocumentViewer.h"
#include "nsIContentViewer.h"
#include "nsIPresShell.h"
#include "nsIDocument.h"
#include "nsHTMLContentSinkStream.h"
#include "nsIDocument.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMElement.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIWindowListener.h"
#if defined(WIN32)
#include <strstrea.h>
#else
#include <strstream.h>
#endif
// XXX For font setting below
#include "nsFont.h"
//#include "nsUnitConversion.h"
//#include "nsIDeviceContext.h"
static NS_DEFINE_IID(kXPBaseWindowCID, NS_XPBASE_WINDOW_CID);
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID);
static NS_DEFINE_IID(kDialogCID, NS_DIALOG_CID);
static NS_DEFINE_IID(kIXPBaseWindowIID, NS_IXPBASE_WINDOW_IID);
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
//----------------------------------------------------------------------
nsXPBaseWindow::nsXPBaseWindow() :
mContentRoot(nsnull),
mPrefs(nsnull),
mAppShell(nsnull),
mDocIsLoaded(PR_FALSE)
{
}
//----------------------------------------------------------------------
nsXPBaseWindow::~nsXPBaseWindow()
{
NS_IF_RELEASE(mContentRoot);
NS_IF_RELEASE(mPrefs);
NS_IF_RELEASE(mAppShell);
}
//----------------------------------------------------------------------
NS_IMPL_ADDREF(nsXPBaseWindow)
NS_IMPL_RELEASE(nsXPBaseWindow)
//----------------------------------------------------------------------
nsresult nsXPBaseWindow::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtrResult = NULL;
if (aIID.Equals(kIXPBaseWindowIID)) {
*aInstancePtrResult = (void*) ((nsIXPBaseWindow*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIStreamObserverIID)) {
*aInstancePtrResult = (void*) ((nsIStreamObserver*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIWebShellContainerIID)) {
*aInstancePtrResult = (void*) ((nsIWebShellContainer*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kINetSupportIID)) {
*aInstancePtrResult = (void*) ((nsINetSupport*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMMouseListenerIID)) {
NS_ADDREF_THIS(); // Increase reference count for caller
*aInstancePtrResult = (void *)((nsIDOMMouseListener*)this);
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
NS_ADDREF_THIS();
*aInstancePtrResult = (void*) ((nsISupports*)((nsIXPBaseWindow*)this));
return NS_OK;
}
return NS_NOINTERFACE;
}
//----------------------------------------------------------------------
static nsEventStatus PR_CALLBACK
HandleXPDialogEvent(nsGUIEvent *aEvent)
{
nsEventStatus result = nsEventStatus_eIgnore;
nsXPBaseWindow* baseWin;
aEvent->widget->GetClientData(((void*&)baseWin));
if (nsnull != baseWin) {
nsSizeEvent* sizeEvent;
switch(aEvent->message) {
case NS_SIZE:
sizeEvent = (nsSizeEvent*)aEvent;
baseWin->Layout(sizeEvent->windowSize->width,
sizeEvent->windowSize->height);
result = nsEventStatus_eConsumeNoDefault;
break;
case NS_DESTROY: {
//nsViewerApp* app = baseWin->mApp;
result = nsEventStatus_eConsumeDoDefault;
baseWin->Close();
NS_RELEASE(baseWin);
}
return result;
default:
break;
}
//NS_RELEASE(baseWin);
}
return result;
}
//----------------------------------------------------------------------
nsresult nsXPBaseWindow::Init(nsXPBaseWindowType aType,
nsIAppShell* aAppShell,
nsIPref* aPrefs,
const nsString& aDialogURL,
const nsString& aTitle,
const nsRect& aBounds,
PRUint32 aChromeMask,
PRBool aAllowPlugins)
{
mAllowPlugins = aAllowPlugins;
mWindowType = aType;
mAppShell = aAppShell;
NS_IF_ADDREF(mAppShell);
mPrefs = aPrefs;
NS_IF_ADDREF(mPrefs);
// Create top level window
nsresult rv;
if (aType == eXPBaseWindowType_window) {
rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWidgetIID,
(void**)&mWindow);
} else {
rv= nsRepository::CreateInstance(kDialogCID, nsnull, kIWidgetIID,
(void**)&mWindow);
}
if (NS_OK != rv) {
return rv;
}
mWindow->SetClientData(this);
nsWidgetInitData initData;
initData.mBorderStyle = eBorderStyle_dialog;
nsRect r(0, 0, aBounds.width, aBounds.height);
mWindow->Create((nsIWidget*)NULL, r, HandleXPDialogEvent,
nsnull, aAppShell, nsnull, &initData);
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;
rv = mWebShell->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET),
r.x, r.y, r.width, r.height,
nsScrollPreference_kNeverScroll, //nsScrollPreference_kAuto,
aAllowPlugins, PR_FALSE);
mWebShell->SetContainer((nsIWebShellContainer*) this);
mWebShell->SetObserver((nsIStreamObserver*)this);
mWebShell->SetPrefs(aPrefs);
mWebShell->Show();
// Now lay it all out
Layout(r.width, r.height);
// Load URL to Load GUI
mDialogURL = aDialogURL;
LoadURL(mDialogURL);
SetTitle(aTitle);
return NS_OK;
}
//----------------------------------------------------------------------
void nsXPBaseWindow::ForceRefresh()
{
nsIPresShell* shell;
GetPresShell(shell);
if (nsnull != shell) {
nsIViewManager* vm = shell->GetViewManager();
if (nsnull != vm) {
nsIView* root;
vm->GetRootView(root);
if (nsnull != root) {
vm->UpdateView(root, (nsIRegion*)nsnull, NS_VMREFRESH_IMMEDIATE |
NS_VMREFRESH_AUTO_DOUBLE_BUFFER);
}
NS_RELEASE(vm);
}
NS_RELEASE(shell);
}
}
//----------------------------------------------------------------------
void nsXPBaseWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
{
nsRect rr(0, 0, aWidth, aHeight);
mWebShell->SetBounds(rr.x, rr.y, rr.width, rr.height);
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::SetLocation(PRInt32 aX, PRInt32 aY)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
mWindow->Move(aX, aY);
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::SetDimensions(PRInt32 aWidth, PRInt32 aHeight)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
// XXX We want to do this in one shot
mWindow->Resize(aWidth, aHeight, PR_FALSE);
Layout(aWidth, aHeight);
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::GetBounds(nsRect& aBounds)
{
mWindow->GetBounds(aBounds);
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP
nsXPBaseWindow::GetWindowBounds(nsRect& aBounds)
{
//XXX This needs to be non-client bounds when it exists.
mWindow->GetBounds(aBounds);
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::SetVisible(PRBool aIsVisible)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
mWindow->Show(aIsVisible);
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::Close()
{
if (nsnull != mWindowListener) {
mWindowListener->Destroy(this);
}
if (nsnull != mWebShell) {
mWebShell->Destroy();
NS_RELEASE(mWebShell);
}
if (nsnull != mWindow) {
nsIWidget* w = mWindow;
NS_RELEASE(w);
}
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::GetWebShell(nsIWebShell*& aResult)
{
aResult = mWebShell;
NS_IF_ADDREF(mWebShell);
return NS_OK;
}
//---------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::SetTitle(const PRUnichar* aTitle)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
mTitle = aTitle;
nsAutoString newTitle(aTitle);
mWindow->SetTitle(newTitle.GetUnicode());
return NS_OK;
}
//---------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::GetTitle(PRUnichar** aResult)
{
*aResult = mTitle;
return NS_OK;
}
//---------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::LoadURL(const nsString& aURL)
{
mWebShell->LoadURL(aURL);
return NS_OK;
}
//---------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason)
{
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
{
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax)
{
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aStatus)
{
// Find the Root Conent Node for this Window
nsIPresShell* shell;
GetPresShell(shell);
if (nsnull != shell) {
nsIDocument* doc = shell->GetDocument();
if (nsnull != doc) {
mContentRoot = doc->GetRootContent();
mDocIsLoaded = PR_TRUE;
if (nsnull != mWindowListener) {
mWindowListener->Initialize(this);
}
NS_RELEASE(doc);
}
NS_RELEASE(shell);
}
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult)
{
aResult = nsnull;
nsString aNameStr(aName);
nsIWebShell *ws;
if (NS_OK == GetWebShell(ws)) {
PRUnichar *name;
if (NS_OK == ws->GetName(&name)) {
if (aNameStr.Equals(name)) {
aResult = ws;
NS_ADDREF(aResult);
return NS_OK;
}
}
}
if (NS_OK == ws->FindChildWithName(aName, aResult)) {
if (nsnull != aResult) {
return NS_OK;
}
}
return NS_OK;
}
NS_IMETHODIMP nsXPBaseWindow::FocusAvailable(nsIWebShell* aFocusedWebShell)
{
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::AddEventListener(nsIDOMNode * aNode)
{
nsIDOMEventReceiver * receiver;
if (NS_OK == aNode->QueryInterface(kIDOMEventReceiverIID, (void**) &receiver)) {
receiver->AddEventListener((nsIDOMMouseListener*)this, kIDOMMouseListenerIID);
NS_RELEASE(receiver);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::RemoveEventListener(nsIDOMNode * aNode)
{
nsIDOMEventReceiver * receiver;
if (NS_OK == aNode->QueryInterface(kIDOMEventReceiverIID, (void**) &receiver)) {
receiver->RemoveEventListener(this, kIDOMMouseListenerIID);
NS_RELEASE(receiver);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::AddWindowListener(nsIWindowListener * aWindowListener)
{
mWindowListener = aWindowListener;
if (mDocIsLoaded && nsnull != mWindowListener) {
mWindowListener->Initialize(this);
}
return NS_OK;
}
//-----------------------------------------------------
// Get the HTML Document
NS_IMETHODIMP nsXPBaseWindow::GetDocument(nsIDOMHTMLDocument *& aDocument)
{
nsIDOMHTMLDocument *htmlDoc = nsnull;
nsIPresShell *shell = nsnull;
GetPresShell(shell);
if (nsnull != shell) {
nsIDocument* doc = shell->GetDocument();
if (nsnull != doc) {
nsresult result = doc->QueryInterface(kIDOMHTMLDocumentIID,(void **)&htmlDoc);
NS_RELEASE(doc);
}
NS_RELEASE(shell);
}
aDocument = htmlDoc;
return NS_OK;
}
//-----------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::NewWebShell(PRUint32 aChromeMask,
PRBool aVisible,
nsIWebShell*& aNewWebShell)
{
nsresult rv = NS_OK;
// Create new window. By default, the refcnt will be 1 because of
// the registration of the browser window in gBrowsers.
nsXPBaseWindow* dialogWindow;
NS_NEWXPCOM(dialogWindow, nsXPBaseWindow);
if (nsnull != dialogWindow) {
nsRect bounds;
GetBounds(bounds);
rv = dialogWindow->Init(mWindowType, mAppShell, mPrefs, mDialogURL, mTitle, bounds, aChromeMask, mAllowPlugins);
if (NS_OK == rv) {
if (aVisible) {
dialogWindow->SetVisible(PR_TRUE);
}
nsIWebShell *shell;
rv = dialogWindow->GetWebShell(shell);
aNewWebShell = shell;
} else {
dialogWindow->Close();
}
} else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
return rv;
}
//----------------------------------------
// Stream observer implementation
NS_IMETHODIMP
nsXPBaseWindow::OnProgress(nsIURL* aURL,
PRUint32 aProgress,
PRUint32 aProgressMax)
{
return NS_OK;
}
//----------------------------------------
NS_IMETHODIMP nsXPBaseWindow::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
{
return NS_OK;
}
//----------------------------------------
NS_IMETHODIMP nsXPBaseWindow::OnStartBinding(nsIURL* aURL, const char *aContentType)
{
return NS_OK;
}
//----------------------------------------
NS_IMETHODIMP nsXPBaseWindow::OnStopBinding(nsIURL* aURL, nsresult status, const PRUnichar* aMsg)
{
return NS_OK;
}
//----------------------------------------
NS_IMETHODIMP_(void) nsXPBaseWindow::Alert(const nsString &aText)
{
char *str;
str = aText.ToNewCString();
printf("%cBrowser Window Alert: %s\n", '\007', str);
PR_Free(str);
}
//----------------------------------------
NS_IMETHODIMP_(PRBool) nsXPBaseWindow::Confirm(const nsString &aText)
{
char *str;
str = aText.ToNewCString();
printf("%cBrowser Window Confirm: %s (y/n)? \n", '\007', str);
PR_Free(str);
char c;
for (;;) {
c = getchar();
if (tolower(c) == 'y') {
return PR_TRUE;
}
if (tolower(c) == 'n') {
return PR_FALSE;
}
}
}
//----------------------------------------
NS_IMETHODIMP_(PRBool) nsXPBaseWindow::Prompt(const nsString &aText,
const nsString &aDefault,
nsString &aResult)
{
char *str;
char buf[256];
str = aText.ToNewCString();
printf("Browser Window: %s\n", str);
PR_Free(str);
printf("%cPrompt: ", '\007');
scanf("%s", buf);
aResult = buf;
return (aResult.Length() > 0);
}
//----------------------------------------
NS_IMETHODIMP_(PRBool) nsXPBaseWindow::PromptUserAndPassword(const nsString &aText,
nsString &aUser,
nsString &aPassword)
{
char *str;
char buf[256];
str = aText.ToNewCString();
printf("Browser Window: %s\n", str);
PR_Free(str);
printf("%cUser: ", '\007');
scanf("%s", buf);
aUser = buf;
printf("%cPassword: ", '\007');
scanf("%s", buf);
aPassword = buf;
return (aUser.Length() > 0);
}
//----------------------------------------
NS_IMETHODIMP_(PRBool) nsXPBaseWindow::PromptPassword(const nsString &aText,
nsString &aPassword)
{
char *str;
char buf[256];
str = aText.ToNewCString();
printf("Browser Window: %s\n", str);
PR_Free(str);
printf("%cPassword: ", '\007');
scanf("%s", buf);
aPassword = buf;
return PR_TRUE;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXPBaseWindow::GetPresShell(nsIPresShell*& aPresShell)
{
aPresShell = nsnull;
nsIPresShell* shell = nsnull;
if (nsnull != mWebShell) {
nsIContentViewer* cv = nsnull;
mWebShell->GetContentViewer(cv);
if (nsnull != cv) {
nsIDocumentViewer* docv = nsnull;
cv->QueryInterface(kIDocumentViewerIID, (void**) &docv);
if (nsnull != docv) {
nsIPresContext* cx;
docv->GetPresContext(cx);
if (nsnull != cx) {
shell = cx->GetShell(); // does an add ref
aPresShell = shell;
NS_RELEASE(cx);
}
NS_RELEASE(docv);
}
NS_RELEASE(cv);
}
}
return NS_OK;
}
//-----------------------------------------------------------------
//-- nsIDOMMouseListener
//-----------------------------------------------------------------
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::ProcessEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseUp(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseDown(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseClick(nsIDOMEvent* aMouseEvent)
{
if (nsnull != mWindowListener) {
PRBool status;
mWindowListener->MouseClick(aMouseEvent, this, status);
}
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseDblClick(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseOver(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXPBaseWindow::MouseOut(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//----------------------------------------------------------------------
// Factory code for creating nsXPBaseWindow's
//----------------------------------------------------------------------
class nsXPBaseWindowFactory : public nsIFactory
{
public:
nsXPBaseWindowFactory();
~nsXPBaseWindowFactory();
// nsISupports methods
NS_IMETHOD QueryInterface(const nsIID &aIID, void **aResult);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
private:
nsrefcnt mRefCnt;
};
//----------------------------------------------------------------------
nsXPBaseWindowFactory::nsXPBaseWindowFactory()
{
mRefCnt = 0;
}
//----------------------------------------------------------------------
nsXPBaseWindowFactory::~nsXPBaseWindowFactory()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
//----------------------------------------------------------------------
nsresult
nsXPBaseWindowFactory::QueryInterface(const nsIID &aIID, void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aResult = NULL;
if (aIID.Equals(kISupportsIID)) {
*aResult = (void *)(nsISupports*)this;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = (void *)(nsIFactory*)this;
}
if (*aResult == NULL) {
return NS_NOINTERFACE;
}
NS_ADDREF_THIS(); // Increase reference count for caller
return NS_OK;
}
//----------------------------------------------------------------------
nsrefcnt
nsXPBaseWindowFactory::AddRef()
{
return ++mRefCnt;
}
//----------------------------------------------------------------------
nsrefcnt
nsXPBaseWindowFactory::Release()
{
if (--mRefCnt == 0) {
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
//----------------------------------------------------------------------
nsresult
nsXPBaseWindowFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
nsresult rv;
nsXPBaseWindow *inst;
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
if (nsnull != aOuter) {
rv = NS_ERROR_NO_AGGREGATION;
goto done;
}
NS_NEWXPCOM(inst, nsXPBaseWindow);
if (inst == NULL) {
rv = NS_ERROR_OUT_OF_MEMORY;
goto done;
}
NS_ADDREF(inst);
rv = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
done:
return rv;
}
//----------------------------------------------------------------------
nsresult
nsXPBaseWindowFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
//----------------------------------------------------------------------
nsresult
NS_NewXPBaseWindowFactory(nsIFactory** aFactory)
{
nsresult rv = NS_OK;
nsXPBaseWindowFactory* inst;
NS_NEWXPCOM(inst, nsXPBaseWindowFactory);
if (nsnull == inst) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
NS_ADDREF(inst);
}
*aFactory = inst;
return rv;
}

View File

@@ -0,0 +1,185 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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 Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsXPBaseWindow_h___
#define nsXPBaseWindow_h___
#include "nsIXPBaseWindow.h"
#include "nsIStreamListener.h"
#include "nsINetSupport.h"
#include "nsIWebShell.h"
#include "nsIScriptContextOwner.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsCRT.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDocumentLoaderObserver.h"
#include "nsIDOMMouseListener.h"
class nsViewerApp;
class nsIPresShell;
class nsIPref;
/**
*
*/
class nsXPBaseWindow : public nsIXPBaseWindow,
public nsIStreamObserver,
public nsINetSupport,
public nsIWebShellContainer,
public nsIDOMMouseListener
{
public:
void* operator new(size_t sz) {
void* rv = new char[sz];
nsCRT::zero(rv, sz);
return rv;
}
nsXPBaseWindow();
virtual ~nsXPBaseWindow();
// nsISupports
NS_DECL_ISUPPORTS
// nsIBrowserWindow
NS_IMETHOD Init(nsXPBaseWindowType aType,
nsIAppShell* aAppShell,
nsIPref* aPrefs,
const nsString& aDialogURL,
const nsString& aTitle,
const nsRect& aBounds,
PRUint32 aChromeMask,
PRBool aAllowPlugins = PR_TRUE);
NS_IMETHOD SetLocation(PRInt32 aX, PRInt32 aY);
NS_IMETHOD SetDimensions(PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD GetWindowBounds(nsRect& aBounds);
NS_IMETHOD GetBounds(nsRect& aBounds);
NS_IMETHOD SetVisible(PRBool aIsVisible);
NS_IMETHOD Close();
NS_IMETHOD SetTitle(const PRUnichar* aTitle);
NS_IMETHOD GetTitle(PRUnichar** aResult);
NS_IMETHOD GetWebShell(nsIWebShell*& aResult);
NS_IMETHOD GetPresShell(nsIPresShell*& aPresShell);
//NS_IMETHOD HandleEvent(nsGUIEvent * anEvent);
NS_IMETHOD LoadURL(const nsString &aURL);
// nsIStreamObserver
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult status, const PRUnichar* aMsg);
// nsIWebShellContainer
NS_IMETHOD WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason);
NS_IMETHOD BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL);
NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax);
NS_IMETHOD EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aStatus);
NS_IMETHOD NewWebShell(PRUint32 aChromeMask,
PRBool aVisible,
nsIWebShell *&aNewWebShell);
NS_IMETHOD FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult);
NS_IMETHOD FocusAvailable(nsIWebShell* aFocusedWebShell);
// nsINetSupport
NS_IMETHOD_(void) Alert(const nsString &aText);
NS_IMETHOD_(PRBool) Confirm(const nsString &aText);
NS_IMETHOD_(PRBool) Prompt(const nsString &aText,
const nsString &aDefault,
nsString &aResult);
NS_IMETHOD_(PRBool) PromptUserAndPassword(const nsString &aText,
nsString &aUser,
nsString &aPassword);
NS_IMETHOD_(PRBool) PromptPassword(const nsString &aText,
nsString &aPassword);
void Layout(PRInt32 aWidth, PRInt32 aHeight);
void ForceRefresh();
//nsEventStatus ProcessDialogEvent(nsGUIEvent *aEvent);
void SetApp(nsViewerApp* aApp) {
mApp = aApp;
}
// DOM Element & Node Interfaces
NS_IMETHOD GetDocument(nsIDOMHTMLDocument *& aDocument);
NS_IMETHOD AddEventListener(nsIDOMNode * aNode);
NS_IMETHOD RemoveEventListener(nsIDOMNode * aNode);
NS_IMETHOD AddWindowListener(nsIWindowListener * aWindowListener);
// nsIDOMEventListener
virtual nsresult ProcessEvent(nsIDOMEvent* aEvent);
// nsIDOMMouseListener (is derived from nsIDOMEventListener)
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent);
protected:
void GetContentRoot(); //Gets the Root Content node after Doc is loaded
nsIContent * mContentRoot; // Points at the Root Content Node
protected:
nsViewerApp* mApp;
nsString mTitle;
nsString mDialogURL;
nsIWidget* mWindow;
nsIWebShell* mWebShell;
nsIWindowListener * mWindowListener; // XXX Someday this will be a list
PRBool mDocIsLoaded;
//for creating more instances
nsIAppShell* mAppShell; //not addref'ed!
nsIPref* mPrefs; //not addref'ed!
PRBool mAllowPlugins;
nsXPBaseWindowType mWindowType;
};
// XXX This is bad; because we can't hang a closure off of the event
// callback we have no way to store our This pointer; therefore we
// have to hunt to find the browswer that events belong too!!!
// aWhich for FindBrowserFor
#define FIND_WINDOW 0
#define FIND_BACK 1
#define FIND_FORWARD 2
#define FIND_LOCATION 3
#endif /* nsXPBaseWindow_h___ */

View File

@@ -0,0 +1,32 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
EXPORTS = \
nsIXPBaseWindow.h \
nsIWindowListener.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

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

View File

@@ -0,0 +1,65 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIWindowListener_h__
#define nsIWindowListener_h__
#include "prtypes.h"
class nsIDOMEvent;
class nsIXPBaseWindow;
/**
* Listens for window mouse events, key clicks etc.
* Also initializes the contents for form elements.
*/
class nsIWindowListener {
public:
/**
* Method called when the user clicks the mouse.
* Clicks are only generated when the mouse-up event happens
* over a widget.
*
* @param aMouseEvent DOM event holding mouse click info.
* @param aWindow Window which generated the mouse click event
*/
virtual void MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow, PRBool &aStatus) = 0;
/**
* Method called After the URL passed to the dialog box or window has
* completed loading. Usually it is used to set place the initial settings
* in form elements.
* @param aWindow the window to initialize form element settings for.
*/
virtual void Initialize(nsIXPBaseWindow * aWindow) = 0;
/**
* Method called when dialog box or window is no longer visibleg
* @param aWindow the window which is about to be destroyed
*/
virtual void Destroy(nsIXPBaseWindow * aWindow) = 0;
};
#endif // nsIWindowListener_h__

View File

@@ -0,0 +1,143 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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 Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsIXPBaseWindow_h___
#define nsIXPBaseWindow_h___
#include "nsweb.h"
#include "nsISupports.h"
class nsIAppShell;
class nsIPref;
class nsIFactory;
class nsIWebShell;
class nsString;
class nsIPresShell;
class nsIDocumentLoaderObserver;
class nsIDOMElement;
class nsIDOMNode;
class nsIWindowListener;
class nsIDOMHTMLDocument;
struct nsRect;
#define NS_IXPBASE_WINDOW_IID \
{ 0x36c1fe51, 0x6f3e, 0x11d2, { 0x8d, 0xca, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
#define NS_XPBASE_WINDOW_CID \
{ 0x36c1fe51, 0x6f3e, 0x11d2, { 0x8d, 0xca, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
enum nsXPBaseWindowType {
///creates a window
eXPBaseWindowType_window,
///creates a dialog
eXPBaseWindowType_dialog,
///creates a modal dialog
eXPBaseWindowType_modalDialog,
};
/**
* BaseWindow for HTML Dialog Boxes and Windows. The desciption of the dialog box
* or window is encoded in a HTML File. The Contents of the HTML file and the current
* settings for form elements are accessed through the W3C DOM interfaces.
* Access to the nsIDOM classes is done through C++ rather than JavaScript. However,
* JavaScript event handlers can be used with the HTML File as well.
* The BaseWindow contains methods for:
*
* 1) loading a HTML file
* 2) Initializing the default values for form elements.
* 3) attaching an event listener to process click events.
* 4) Getting a handle to the HTMLDocumentElement to access nsIDOMElements.
*/
class nsIXPBaseWindow : public nsISupports {
public:
/**
* Initialize the window or dialog box.
* @param aType see nsXPBaseWindowType's above
* @param aAppShell application shell
* @param aPref Preferences
* @param aDialogURL URL of HTML file describing the dialog or window
* @param aTitle Title of the dialog box or window
* @param aBounds x, y, width, and height of the window or dialog box
* XXX: aChrome is probably not needed for dialog boxes and windows, this is a holdover
* from the nsBrowserWindow.
* @param aChrome Chrome mask for toolbars and statusbars.
* @param aAllowPlugins if TRUE then plugins can be referenced in the HTML file.
*/
NS_IMETHOD Init(nsXPBaseWindowType aType,
nsIAppShell* aAppShell,
nsIPref* aPrefs,
const nsString& aDialogURL,
const nsString& aTitle,
const nsRect& aBounds,
PRUint32 aChromeMask,
PRBool aAllowPlugins = PR_TRUE) = 0;
/**
* Set the location the window or dialog box on the screen
* @param aX horizontal location of the upper left
* corner of the window in pixels from the screen.
* @param aY vertical location of the upper left
* corner of the window in pixels from the screen.
*/
NS_IMETHOD SetLocation(PRInt32 aX, PRInt32 aY) = 0;
/**
* Set the width and height of the window or dialog box in pixels
* @param aWidth width of the window or dialog box in pixels.
* @param aHeight height of the window or dialog box in pixels.
*/
NS_IMETHOD SetDimensions(PRInt32 aWidth, PRInt32 aHeight) = 0;
NS_IMETHOD GetBounds(nsRect& aResult) = 0;
NS_IMETHOD GetWindowBounds(nsRect& aResult) = 0;
NS_IMETHOD SetVisible(PRBool aIsVisible) = 0;
NS_IMETHOD Close() = 0;
NS_IMETHOD SetTitle(const PRUnichar* aTitle) = 0;
NS_IMETHOD GetTitle(PRUnichar** aResult) = 0;
NS_IMETHOD GetWebShell(nsIWebShell*& aResult) = 0;
NS_IMETHOD LoadURL(const nsString &aURL) = 0;
NS_IMETHOD GetPresShell(nsIPresShell*& aPresShell) = 0;
NS_IMETHOD GetDocument(nsIDOMHTMLDocument *& aDocument) = 0;
NS_IMETHOD AddEventListener(nsIDOMNode * aNode) = 0;
NS_IMETHOD RemoveEventListener(nsIDOMNode * aNode) = 0;
NS_IMETHOD AddWindowListener(nsIWindowListener * aWindowListener) = 0;
// XXX minimize, maximize
// XXX event control: enable/disable window close box, stick to glass, modal
};
#endif /* nsIXPBaseWindow_h___ */

View File

@@ -64,6 +64,7 @@
#define VIEWER_THREE_COLUMN 40042
#define VIEWER_PRINT 40050
#define VIEWER_PRINT_SETUP 40051
#define JS_CONSOLE 40100
#define EDITOR_MODE 40120

View File

@@ -0,0 +1,72 @@
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#C0C0C0">
<style type="text/css">
/* This style sheet should be in a seperate file */
BODY,TD {
font-family: Sans-Serif;
background-color: #C0C0C0;
}
BODY,TD,INPUT {
font-size: 9pt;
}
BODY {
margin: 0px 0px 0px 0px;
}
</style>
<FORM>
<table border="0" bgcolor="#C0C0C0">
<tr>
<td NOWRAP width="30" align="LEFT">
<div align="LEFT">
Find what:
</div>
</td>
<td width="134">
<input type="text" id="query">
</td>
<td width="137">
<input type="button" id="find" value="Find Next" style="width:100;">
</td>
</tr>
<tr>
<td NOWRAP width="30" align="LEFT">&nbsp;
<div align="RIGHT">
<table border="0" width="100%">
<tr>
<td width="27%">
<div align="LEFT">
<input type="checkbox" id="matchcase" value="checkbox" style="background-color: rgb(192,192,192);">
</div>
</td>
<td width="73%" NOWRAP>Match Case</td>
</tr>
</table>
</div>
</td>
<td width="134">&nbsp; <fieldset style="background-color: rgb(192, 192, 192); display: inline; border: 2px groove white; margin-left: 10px; padding: 10px;">
<legend style="background-color:rgb(192, 192, 192); border: none ; padding: 0px;" align=left>&nbsp;Direction
&nbsp;</legend>
<input type=radio name="search" id="searchup" size=15 maxlength=80 style="margin-right:10px; background-color: rgb(190, 190, 190);">
<u>U</u>p
<input type=radio checked name="search" id="searchdown">
<u>D</u>own
<input type="HIDDEN" id="a" value="n">
</fieldset> </td>
<td width="137">
<input type="button" id="cancel" value="Cancel" style="width:100;">
</td>
</tr>
</table>
</FORM>
<p>&nbsp; </p>
</body>
</html>

View File

@@ -0,0 +1,176 @@
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#C0C0C0" style="overflow: hidden;">
<style type="text/css">
/* This style sheet should be in a seperate file */
FIELDSET {
background-color: rgb(192, 192, 192);
border: 2px groove rgb(192, 192, 192);
display: inline;
margin-left: 10px;
padding: 2px;
}
LEGEND {
background-color:rgb(192, 192, 192);
border: none ;
padding: 2px;
}
BODY,TD {
font-family: Sans-Serif;
background-color: #C0C0C0;
}
LABEL {
background-color: #C0C0C0;
margin: 0px 0px 0px 0px;
padding-left: 0px;
padding-right: 0px;
}
BODY,TD,INPUT {
font-size: 9pt;
}
BODY {
margin: 0px 0px 0px 0px;
}
</style>
<FORM>
<TABLE bgcolor="#C0C0C0">
<tr>
<td NOWRAP >
<fieldset >
<legend align=left>&nbsp;Page Options&nbsp;</legend>
<TABLE width="100%">
<TR>
<TD NOWRAP>
<LABEL><input type=checkbox id="bevellines" size=15 maxlength=80 style="margin-right:5px; background-color: rgb(190, 190, 190);">Bevel Lines</LABEL>
</TD>
</TR>
<TR>
<TD NOWRAP>
<input type=checkbox id="blacktext" size=15 maxlength=80 style="margin-right:5px; background-color: rgb(190, 190, 190);">Black Text</TD>
</TR>
<TR>
<TD NOWRAP>
<input type=checkbox id="blacklines" size=15 maxlength=80 style="margin-right:5px; background-color: rgb(190, 190, 190);">Black Lines</TD>
</TR>
<TR>
<TD NOWRAP>
<input type=checkbox id="lastpagefirst" size=15 maxlength=80 style="margin-right:5px; background-color: rgb(190, 190, 190);">Last Page First</TD>
</TR>
<TR>
<TD NOWRAP>
<input type=checkbox id="printbg" size=15 maxlength=80 style="margin-right:5px; background-color: rgb(190, 190, 190);">Print Backgrounds</TD>
</TR>
</TABLE>
</fieldset>
</td>
<td>
<fieldset >
<legend align=left>&nbsp;Sample (8.5 x 11.00)&nbsp;</legend>
<P style="width:100%;height:70px;">&nbsp;</P>
</fieldset>
</td>
</tr>
<tr> <TD colspan=2>
<TABLE width="100%" height="100%" bgcolor="#C0C0C0">
<TR>
<TD>
<fieldset >
<legend align=left>&nbsp;Orientation&nbsp;</legend>
<TABLE width="100%" height="100%">
<TR>
<TD NOWRAP><input type=radio name="orientation" id="portrait" size=15 maxlength=80 style="margin-right:5px; background-color: rgb(190, 190, 190);">Portrait</TD>
</TR>
<TR>
<TD NOWRAP><input type=radio name="orientation" id="landscape" size=15 maxlength=80 style="margin-right:5px; background-color: rgb(190, 190, 190);">Landscape</TD>
</TR>
</TABLE>
</fieldset>
</TD>
<TD>
<fieldset width="100%" height="100%" >
<legend align=left>&nbsp;Margins&nbsp;</legend>
<TABLE width="100%" height="100%">
<TR>
<TD>Top:</TD>
<TD width="30" ><input type="text" id="toptext" style="width:40;"></TD>
<TD><P style="width:5px;">&nbsp;</P></TD>
<TD>Left:</TD>
<TD><input type="text" id="lefttext" style="width:40;"></TD>
</TR>
<TR>
<TD>Bottom:</TD>
<TD><input type="text" id="bottomtext" style="width:40;"></TD>
<TD><P style="width:5px;">&nbsp;</P></TD>
<TD>Right:</TD>
<TD><input type="text" id="righttext" style="width:40;"></TD>
</TR>
</TABLE>
</fieldset>
</TD>
</TR>
</TABLE>
</TD>
</tr>
<tr>
<td NOWRAP colspan=2>
<fieldset >
<legend align=left>&nbsp;Header&nbsp;</legend>
<TABLE width="100%">
<TR>
<TD NOWRAP><input type=checkbox id="doctitle" size=15 maxlength=80 style="margin-right:0px; background-color: rgb(190, 190, 190);">Document Title&nbsp;&nbsp;</TD>
<TD NOWRAP><input type=checkbox id="docloc" size=15 maxlength=80 style="margin-right:0px; background-color: rgb(190, 190, 190);">Document Location (URL)&nbsp;&nbsp;</TD>
</TR>
<TR>
<TD colspan=2><input type="text" id="headertext" width="100%"></TD>
</TR>
</TABLE>
</fieldset>
</td>
</tr>
<tr>
<td NOWRAP colspan=2>
<fieldset >
<legend align=left>&nbsp;Footer&nbsp;</legend>
<TABLE width="100%">
<TR>
<TD NOWRAP style="vertical-align:middle;"><input type=checkbox id="pagenum" size=15 maxlength=80 style="margin-right:0px; background-color: rgb(190, 190, 190);">Page Number&nbsp;&nbsp;</TD>
<TD NOWRAP><input type=checkbox id="pagetotal" size=15 maxlength=80 style="margin-right:0px; background-color: rgb(190, 190, 190);">Page Total&nbsp;&nbsp;</TD>
<TD NOWRAP><input type=checkbox id="dateprinted" size=15 maxlength=80 style="margin-right:0px; background-color: rgb(190, 190, 190);">Date Printed&nbsp;&nbsp;</TD>
</TR>
<TR>
<TD colspan=3><input type="text" id="footertext" width="100%"></TD>
</TR>
</TABLE>
</fieldset>
</td>
</tr>
</TABLE>
<TABLE WIDTH="100%"><TR>
<TD><P style="width:40px;">&nbsp;</P></TD>
<TD><CENTER><input type="button" id="ok" value="OK" style="width:80;"></CENTER></TD>
<TD><CENTER><input type="button" id="cancel" value="Cancel" style="width:80;"></CENTER></TD>
<TD><P style="width:40px;">&nbsp;</P></TD>
</TR>
</TABLE>
</FORM>
<p>&nbsp; </p>
</body>
</html>

View File

@@ -46,6 +46,7 @@ VIEWER MENU DISCARDABLE
{
MENUITEM "&Tree View", VIEWER_TREEVIEW
}
MENUITEM SEPARATOR
POPUP "Print &Preview"
{
MENUITEM "One Column", VIEWER_ONE_COLUMN
@@ -53,6 +54,8 @@ VIEWER MENU DISCARDABLE
MENUITEM "Three Column", VIEWER_THREE_COLUMN
}
MENUITEM "Print", VIEWER_PRINT
MENUITEM "Print Setup", VIEWER_PRINT_SETUP
MENUITEM SEPARATOR
MENUITEM "&Exit", VIEWER_EXIT
}
POPUP "&Edit"