Changes implementation to match the new Widget interfaces. This involves

many calls to QueryInterface because many of the instance members
no longer derive from nsIWidget.
Also, using helper functions in nsWidgetHelper for standard Create calls.
This commit is contained in:
kostello%netscape.com 1998-09-14 20:46:42 +00:00
Родитель fec8dc255c
Коммит 334f544d61
11 изменённых файлов: 567 добавлений и 297 удалений

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

@ -33,6 +33,7 @@
#include "nsIPref.h"
#include "nsIViewObserver.h"
static PRBool gsNoisyRefs = PR_FALSE;
#undef NOISY
#if 0
@ -285,8 +286,29 @@ PresShell::PresShell()
{
}
#ifdef NS_DEBUG
// for debugging only
nsrefcnt PresShell::AddRef(void)
{
if (gsNoisyRefs) printf("PresShell: AddRef: %x, cnt = %d \n",this, mRefCnt+1);
return ++mRefCnt;
}
// for debugging only
nsrefcnt PresShell::Release(void)
{
if (gsNoisyRefs==PR_TRUE) printf("PresShell Release: %x, cnt = %d \n",this, mRefCnt-1);
if (--mRefCnt == 0) {
if (gsNoisyRefs==PR_TRUE) printf("PresShell Delete: %x, \n",this);
delete this;
return 0;
}
return mRefCnt;
}
#else
NS_IMPL_ADDREF(PresShell)
NS_IMPL_RELEASE(PresShell)
#endif
nsresult
PresShell::QueryInterface(const nsIID& aIID, void** aInstancePtr)

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

@ -60,10 +60,11 @@ enum nsButtonType {
kButton_Submit,
kButton_Image,
kButton_Hidden,
kButton_Browse,
kButton_Browse
};
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
typedef nsInput nsInputButtonSuper;
class nsInputButton : public nsInputButtonSuper {
@ -583,8 +584,12 @@ nsInputButtonFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aVie
nsInputButton* content;
GetContent((nsIContent*&) content);
nsIButton* button;
if (NS_OK == GetWidget(aView, (nsIWidget **)&button)) {
nsIWidget* widget = nsnull;
nsIButton* button = nsnull;
nsresult result = GetWidget(aView, &widget);
if (result == NS_OK) {
widget->QueryInterface(kIButtonIID,(void**)&button);
if (kButton_Browse != content->GetButtonType()) { // browse button always uses default
const nsStyleFont* styleFont = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
if ((styleFont->mFlags & NS_STYLE_FONT_FACE_EXPLICIT) ||
@ -595,7 +600,7 @@ nsInputButtonFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aVie
if (0 == (styleFont->mFlags & NS_STYLE_FONT_FACE_EXPLICIT)) {
widgetFont.name = "Arial"; // XXX windows specific font
}
button->SetFont(widgetFont);
widget->SetFont(widgetFont);
}
else {
// use arial, scaled down one HTML size
@ -608,7 +613,7 @@ nsInputButtonFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aVie
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
PRInt32 fontIndex = nsStyleUtil::FindNextSmallerFontSize(widgetFont.size, (PRInt32)normal.size, scaleFactor);
widgetFont.size = nsStyleUtil::CalcFontPointSize(fontIndex, (PRInt32)normal.size, scaleFactor);
button->SetFont(widgetFont);
widget->SetFont(widgetFont);
}
}
}
@ -618,17 +623,20 @@ nsInputButtonFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aVie
nsString value;
nsresult status = ((nsHTMLTagContent*)content)->GetAttribute(nsHTMLAtoms::value, value);
if (NS_CONTENT_ATTR_HAS_VALUE == status) {
button->SetLabel(value);
}
else {
nsAutoString label;
content->GetDefaultLabel(label);
button->SetLabel(label);
}
NS_RELEASE(content);
NS_RELEASE(button);
if (button != nsnull)
{
if (NS_CONTENT_ATTR_HAS_VALUE == status) {
button->SetLabel(value);
}
else {
nsAutoString label;
content->GetDefaultLabel(label);
button->SetLabel(label);
}
}
NS_IF_RELEASE(button);
NS_IF_RELEASE(content);
}
const nsIID&

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

@ -33,6 +33,16 @@
#include "nsIStyleContext.h"
#include "nsStyleUtil.h"
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
// Prototypes
nsresult
NS_NewHTMLInputCheckbox(nsIHTMLContent** aInstancePtrResult,
nsIAtom* aTag, nsIFormManager* aManager);
class nsInputCheckboxFrame : public nsInputFrame {
public:
nsInputCheckboxFrame(nsIContent* aContent, nsIFrame* aParentFrame);
@ -119,34 +129,43 @@ nsInputCheckboxFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aV
PRBool checked = (result != NS_CONTENT_ATTR_NOT_THERE) ? PR_TRUE : PR_FALSE;
// set the widget to the initial state
nsICheckButton* checkbox;
if (NS_OK == GetWidget(aView, (nsIWidget **)&checkbox)) {
nsIWidget* widget = nsnull;
nsICheckButton* checkbox = nsnull;
if (NS_OK == GetWidget(aView, &widget)) {
widget->QueryInterface(GetIID(),(void**)&checkbox);
checkbox->SetState(checked);
const nsStyleColor* color =
nsStyleUtil::FindNonTransparentBackground(mStyleContext);
if (nsnull != color) {
checkbox->SetBackgroundColor(color->mBackgroundColor);
widget->SetBackgroundColor(color->mBackgroundColor);
}
else {
checkbox->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
widget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
}
NS_RELEASE(checkbox);
NS_IF_RELEASE(checkbox);
NS_IF_RELEASE(widget);
}
}
void
nsInputCheckboxFrame::MouseClicked(nsIPresContext* aPresContext)
{
nsICheckButton* checkbox;
nsIWidget* widget = nsnull;
nsICheckButton* checkbox = nsnull;
nsIView* view;
GetView(view);
if (NS_OK == GetWidget(view, (nsIWidget **)&checkbox)) {
PRBool newState = (checkbox->GetState()) ? PR_FALSE : PR_TRUE;
checkbox->SetState(newState);
NS_RELEASE(checkbox);
if (NS_OK == GetWidget(view, &widget)) {
widget->QueryInterface(GetIID(),(void**)&checkbox);
PRBool oldState;
checkbox->GetState(oldState);
PRBool newState = oldState ? PR_FALSE : PR_TRUE;
checkbox->SetState(newState);
NS_IF_RELEASE(checkbox);
NS_IF_RELEASE(widget);
}
}
@ -218,29 +237,39 @@ nsInputCheckbox::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
if ((aMaxNumValues <= 0) || (nsnull == mName)) {
return PR_FALSE;
}
nsICheckButton* checkBox = (nsICheckButton *)GetWidget();
PRBool state = checkBox->GetState();
if(PR_TRUE != state) {
return PR_FALSE;
}
if (nsnull == mValue) {
aValues[0] = "on";
} else {
aValues[0] = *mValue;
}
aNames[0] = *mName;
aNumValues = 1;
nsIWidget* widget = GetWidget();
nsICheckButton* checkBox = nsnull;
if (widget != nsnull && NS_OK == widget->QueryInterface(kICheckButtonIID,(void**)&checkBox))
{
PRBool state = PR_FALSE;
checkBox->GetState(state);
if(PR_TRUE != state) {
return PR_FALSE;
}
return PR_TRUE;
if (nsnull == mValue) {
aValues[0] = "on";
} else {
aValues[0] = *mValue;
}
aNames[0] = *mName;
aNumValues = 1;
NS_RELEASE(checkBox);
return PR_TRUE;
}
return PR_FALSE;
}
void
nsInputCheckbox::Reset()
{
nsICheckButton* checkbox = (nsICheckButton *)GetWidget();
if (nsnull != checkbox) {
checkbox->SetState(mChecked);
{
nsIWidget* widget = GetWidget();
nsICheckButton* checkBox = nsnull;
if (widget != nsnull && NS_OK == widget->QueryInterface(kICheckButtonIID,(void**)&checkBox))
{
checkBox->SetState(mChecked);
NS_RELEASE(checkBox);
}
}

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

@ -77,6 +77,7 @@ GetWindowTemp(nsIView *aView)
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID);
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
// this is in response to the MouseClick from the containing browse button
// XXX still need to get filters from accept attribute
@ -109,9 +110,10 @@ void nsInputFileFrame::MouseClicked(nsIPresContext* aPresContext)
PRUint32 result = fileWidget->Show();
if (result) {
PRUint32 size;
nsString fileName;
fileWidget->GetFile(fileName);
((nsITextWidget *)textWidget)->SetText(fileName);
((nsITextWidget *)textWidget)->SetText(fileName,size);
}
NS_RELEASE(fileWidget);
NS_RELEASE(parentWidget);
@ -266,12 +268,19 @@ nsInputFile::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
}
// use our name and the text widgets value
aNames[0] = *mName;
nsITextWidget* textWidget = (nsITextWidget *)mTextField->GetWidget();
textWidget->GetText(aValues[0], 0); // the last parm is not used
nsIWidget* widget = mTextField->GetWidget();
nsITextWidget* textWidget = nsnull;
aNumValues = 1;
return PR_TRUE;
if (widget != nsnull && NS_OK == widget->QueryInterface(kITextWidgetIID,(void**)textWidget))
{
PRUint32 actualSize;
textWidget->GetText(aValues[0], 0, actualSize);
aNumValues = 1;
NS_RELEASE(textWidget);
return PR_TRUE;
}
return PR_FALSE;
}
NS_IMETHODIMP

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

@ -50,6 +50,10 @@
#include "nsCSSLayout.h"
#include "nsStyleUtil.h"
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
nsInputFrame::nsInputFrame(nsIContent* aContent, nsIFrame* aParentFrame)
: nsInputFrameSuper(aContent, aParentFrame)
{
@ -352,7 +356,7 @@ nsInputFrame::GetWidget(nsIView* aView, nsIWidget** aWidget)
} else {
const nsIID id = GetIID();
result = widget->QueryInterface(id, (void**)aWidget);
result = widget->QueryInterface(kIWidgetIID, (void**)aWidget);
if (NS_FAILED(result)) {
NS_ASSERTION(0, "The widget interface is invalid"); // need to print out more details of the widget
}

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

@ -35,6 +35,16 @@
#include "nsIStyleContext.h"
#include "nsStyleUtil.h"
// prototypes
nsresult
NS_NewHTMLInputRadio(nsIHTMLContent** aInstancePtrResult,
nsIAtom* aTag, nsIFormManager* aManager);
static NS_DEFINE_IID(kRadioIID, NS_IRADIOBUTTON_IID);
class nsInputRadioFrame : public nsInputFrame {
public:
nsInputRadioFrame(nsIContent* aContent, nsIFrame* aParentFrame);
@ -81,7 +91,6 @@ nsInputRadioFrame::~nsInputRadioFrame()
const nsIID&
nsInputRadioFrame::GetIID()
{
static NS_DEFINE_IID(kRadioIID, NS_IRADIOBUTTON_IID);
return kRadioIID;
}
@ -114,21 +123,27 @@ nsInputRadioFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView
//PRInt32 checkedAttr;
//nsContentAttr result = ((nsInput *)content)->GetAttribute(nsHTMLAtoms::checked, checkedAttr);
//if ((result == eContentAttr_HasValue) && (PR_FALSE != checkedAttr)) {
nsIRadioButton* radio;
if (NS_OK == GetWidget(aView, (nsIWidget **)&radio)) {
radio->SetState(content->mForcedChecked);
nsIWidget* widget = nsnull;
nsIRadioButton* radio = nsnull;
nsresult result = GetWidget(aView, &widget);
if (NS_OK == result) {
result = widget->QueryInterface(GetIID(),(void**)&radio);
if (result == NS_OK)
{
radio->SetState(content->mForcedChecked);
const nsStyleColor* color =
nsStyleUtil::FindNonTransparentBackground(mStyleContext);
const nsStyleColor* color =
nsStyleUtil::FindNonTransparentBackground(mStyleContext);
if (nsnull != color) {
radio->SetBackgroundColor(color->mBackgroundColor);
}
else {
radio->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
}
NS_RELEASE(radio);
if (nsnull != color) {
widget->SetBackgroundColor(color->mBackgroundColor);
}
else {
widget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
}
NS_RELEASE(radio);
}
NS_RELEASE(widget);
}
}
@ -221,7 +236,15 @@ nsInputRadio::GetChecked(PRBool aGetInitialValue) const
}
else {
if (mWidget) {
return ((nsIRadioButton *)mWidget)->GetState();
PRBool state = PR_FALSE;
nsIRadioButton* radio = nsnull;
nsresult result = mWidget->QueryInterface(kRadioIID,(void**)&radio);
if (result == NS_OK)
{
radio->GetState(state);
NS_IF_RELEASE(radio);
}
return state;
}
else {
return mForcedChecked;
@ -294,8 +317,17 @@ nsInputRadio::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
if ((aMaxNumValues <= 0) || (nsnull == mName)) {
return PR_FALSE;
}
nsIRadioButton* radio = (nsIRadioButton *)GetWidget();
PRBool state = radio->GetState();
nsIWidget* widget = GetWidget();
nsIRadioButton* radio = nsnull;
PRBool state = PR_FALSE;
if (widget != nsnull)
{
widget->QueryInterface(kRadioIID,(void**)&radio);
radio->GetState(state);
NS_IF_RELEASE(radio);
}
if(PR_TRUE != state) {
return PR_FALSE;
}
@ -314,9 +346,12 @@ nsInputRadio::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
void
nsInputRadio::Reset()
{
nsIRadioButton* radio = (nsIRadioButton *)GetWidget();
if (nsnull != radio) {
nsIWidget* widget = GetWidget();
nsIRadioButton* radio = nsnull;
if (widget != nsnull && NS_OK == widget->QueryInterface(kRadioIID,(void**)&radio))
{
radio->SetState(mInitialChecked);
NS_RELEASE(radio);
}
}

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

@ -148,11 +148,13 @@ nscoord nsInputTextFrame::GetHorizontalInsidePadding(float aPixToTwip,
#endif
}
static NS_DEFINE_IID(kTextIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kTextAreaIID, NS_ITEXTAREAWIDGET_IID);
const nsIID&
nsInputTextFrame::GetIID()
{
static NS_DEFINE_IID(kTextIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kTextAreaIID, NS_ITEXTAREAWIDGET_IID);
if (kInputText_Area == GetTextType()) {
return kTextAreaIID;
@ -292,22 +294,48 @@ nsInputTextFrame::GetWidgetInitData(nsIPresContext& aPresContext)
void
nsInputTextFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
{
nsITextWidget* text;
if (NS_OK == GetWidget(aView, (nsIWidget **)&text)) {
const nsStyleFont* fontStyle = (const nsStyleFont*)(mStyleContext->GetStyleData(eStyleStruct_Font));
text->SetFont(fontStyle->mFixedFont);
nsInputText* content;
GetContent((nsIContent *&) content);
nsAutoString valAttr;
nsresult valStatus = ((nsHTMLTagContent *)content)->GetAttribute(nsHTMLAtoms::value, valAttr);
text->SetText(valAttr);
PRInt32 maxLength = content->GetMaxLength();
if (ATTR_NOTSET != maxLength) {
text->SetMaxTextLength(maxLength);
nsIWidget* widget = nsnull;
if (NS_OK == GetWidget(aView, &widget)) {
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
// This is replicated code for both text interfaces -- this should be factored
if (widget != nsnull && NS_OK == widget->QueryInterface(kTextIID,(void**)&text))
{
const nsStyleFont* fontStyle = (const nsStyleFont*)(mStyleContext->GetStyleData(eStyleStruct_Font));
widget->SetFont(fontStyle->mFixedFont);
nsInputText* content;
GetContent((nsIContent *&) content);
nsAutoString valAttr;
nsresult valStatus = ((nsHTMLTagContent *)content)->GetAttribute(nsHTMLAtoms::value, valAttr);
PRUint32 size;
text->SetText(valAttr,size);
PRInt32 maxLength = content->GetMaxLength();
if (ATTR_NOTSET != maxLength) {
text->SetMaxTextLength(maxLength);
}
widget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
NS_RELEASE(content);
NS_RELEASE(text);
}
else if (widget != nsnull && NS_OK == widget->QueryInterface(kTextAreaIID,(void**)&textArea))
{
const nsStyleFont* fontStyle = (const nsStyleFont*)(mStyleContext->GetStyleData(eStyleStruct_Font));
widget->SetFont(fontStyle->mFixedFont);
nsInputText* content;
GetContent((nsIContent *&) content);
nsAutoString valAttr;
nsresult valStatus = ((nsHTMLTagContent *)content)->GetAttribute(nsHTMLAtoms::value, valAttr);
PRUint32 size;
textArea->SetText(valAttr,size);
PRInt32 maxLength = content->GetMaxLength();
if (ATTR_NOTSET != maxLength) {
textArea->SetMaxTextLength(maxLength);
}
widget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
NS_RELEASE(content);
NS_RELEASE(textArea);
}
text->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
NS_RELEASE(text);
NS_RELEASE(content);
}
}
@ -360,26 +388,63 @@ nsInputText::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
if ((aMaxNumValues <= 0) || (nsnull == mName)) {
return PR_FALSE;
}
nsITextWidget* text = (nsITextWidget *)GetWidget();
nsString value;
text->GetText(aValues[0], 0); // the last parm is not used
aNames[0] = *mName;
aNumValues = 1;
nsIWidget* widget = GetWidget();
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
return PR_TRUE;
if (widget != nsnull && NS_OK == widget->QueryInterface(kTextIID,(void**)text))
{
nsString value;
PRUint32 size;
text->GetText(aValues[0],0,size); // the last parm is not used
aNames[0] = *mName;
aNumValues = 1;
NS_RELEASE(text);
return PR_TRUE;
}
else if (widget != nsnull && NS_OK == widget->QueryInterface(kTextAreaIID,(void**)textArea))
{
nsString value;
PRUint32 size;
textArea->GetText(aValues[0],0,size); // the last parm is not used
aNames[0] = *mName;
aNumValues = 1;
NS_RELEASE(textArea);
return PR_TRUE;
}
return PR_FALSE;
}
void
nsInputText::Reset()
{
nsITextWidget* text = (nsITextWidget *)GetWidget();
if (nsnull == mValue) {
text->SetText("");
} else {
text->SetText(*mValue);
nsIWidget* widget = GetWidget();
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
if (widget != nsnull && NS_OK == widget->QueryInterface(kTextIID,(void**)text))
{
PRUint32 size;
if (nsnull == mValue) {
text->SetText("",size);
} else {
text->SetText(*mValue,size);
}
NS_RELEASE(text);
}
else if (widget != nsnull && NS_OK == widget->QueryInterface(kTextAreaIID,(void**)textArea))
{
PRUint32 size;
if (nsnull == mValue) {
textArea->SetText("",size);
} else {
textArea->SetText(*mValue,size);
}
NS_RELEASE(textArea);
}
}
void nsInputText::GetType(nsString& aResult) const

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

@ -367,8 +367,7 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
NS_ASSERTION(PR_FALSE, "invalid widget");
return;
}
NS_RELEASE(widget);
list->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
widget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
const nsStyleFont* styleFont = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
if ((styleFont->mFlags & NS_STYLE_FONT_FACE_EXPLICIT) ||
@ -379,7 +378,7 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
if (0 == (styleFont->mFlags & NS_STYLE_FONT_FACE_EXPLICIT)) {
widgetFont.name = "Arial"; // XXX windows specific font
}
list->SetFont(widgetFont);
widget->SetFont(widgetFont);
}
else {
// use arial, scaled down one HTML size
@ -392,7 +391,7 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
PRInt32 fontIndex = nsStyleUtil::FindNextSmallerFontSize(widgetFont.size, (PRInt32)normal.size, scaleFactor);
widgetFont.size = nsStyleUtil::CalcFontPointSize(fontIndex, (PRInt32)normal.size, scaleFactor);
list->SetFont(widgetFont);
widget->SetFont(widgetFont);
}
PRInt32 numChildren;
@ -416,6 +415,7 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
}
NS_RELEASE(list);
NS_RELEASE(widget);
select->Reset(); // initializes selections
}

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

@ -56,6 +56,7 @@ MYLIBS= \
$(DIST)\lib\raptorgfxwin.lib \
$(DIST)\lib\raptorhtml.lib \
$(DIST)\lib\raptorweb.lib \
$(DIST)\lib\raptorwidget.lib \
$(DIST)\lib\raptorhtmlpars.lib \
$(DIST)\lib\DebugRobot.lib \
$(DIST)\lib\xpcom32.lib \

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

@ -60,6 +60,8 @@
#include "nsICheckButton.h"
#include "nsIRadioButton.h"
#include "nsILabel.h"
#include "nsWidgetSupport.h"
#include "resources.h"
@ -136,7 +138,10 @@ static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID);
static const char* gsAOLFormat = "AOLMAIL";
static const char* gsHTMLFormat = "text/html";
// prototypes
static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent);
static void* GetItemsNativeData(nsISupports* aObject);
//----------------------------------------------------------------------
@ -287,7 +292,8 @@ HandleLocationEvent(nsGUIEvent *aEvent)
case NS_KEY_UP:
if (NS_VK_RETURN == ((nsKeyEvent*)aEvent)->keyCode) {
nsAutoString text;
bw->mLocation->GetText(text, 1000);
PRUint32 size;
bw->mLocation->GetText(text, 1000,size);
bw->GoTo(text);
}
break;
@ -497,10 +503,28 @@ nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent)
return result;
}
static void* GetItemsNativeData(nsISupports* aObject)
{
void* result = nsnull;
nsIWidget* widget;
if (NS_OK == aObject->QueryInterface(kIWidgetIID,(void**)&widget))
{
result = widget->GetNativeData(NS_NATIVE_WIDGET);
NS_RELEASE(widget);
}
return result;
}
/**--------------------------------------------------------------------------------
* Main Handler
*--------------------------------------------------------------------------------
*/
nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent)
{
nsEventStatus result = nsEventStatus_eIgnore;
@ -511,10 +535,13 @@ nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent)
case NS_KEY_DOWN: {
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
if (NS_VK_RETURN == keyEvent->keyCode) {
PRBool matchCase = mMatchCheckBtn->GetState();
PRBool findDwn = mDwnRadioBtn->GetState();
PRBool matchCase = PR_FALSE;
mMatchCheckBtn->GetState(matchCase);
PRBool findDwn = PR_FALSE;
mDwnRadioBtn->GetState(findDwn);
nsString searchStr;
mTextField->GetText(searchStr, 255);
PRUint32 actualSize;
mTextField->GetText(searchStr, 255,actualSize);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
@ -534,14 +561,21 @@ nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent)
} break;
case NS_MOUSE_LEFT_BUTTON_UP: {
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mCancelBtn->GetNativeData(NS_NATIVE_WIDGET)) {
mDialog->Show(PR_FALSE);
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mFindBtn->GetNativeData(NS_NATIVE_WIDGET)) {
nsIWidget* dialogWidget = nsnull;
if (NS_OK != mDialog->QueryInterface(kIWidgetIID,(void**)&dialogWidget))
break;
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mCancelBtn)) {
dialogWidget->Show(PR_FALSE);
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mFindBtn)) {
PRBool matchCase = mMatchCheckBtn->GetState();
PRBool findDwn = mDwnRadioBtn->GetState();
PRBool matchCase = PR_FALSE;
mMatchCheckBtn->GetState(matchCase);
PRBool findDwn = PR_FALSE;
mDwnRadioBtn->GetState(findDwn);
PRUint32 actualSize;
nsString searchStr;
mTextField->GetText(searchStr, 255);
mTextField->GetText(searchStr, 255,actualSize);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
@ -558,21 +592,23 @@ nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent)
NS_RELEASE(shell);
}
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mUpRadioBtn->GetNativeData(NS_NATIVE_WIDGET)) {
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mUpRadioBtn)) {
mUpRadioBtn->SetState(PR_TRUE);
mDwnRadioBtn->SetState(PR_FALSE);
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mDwnRadioBtn->GetNativeData(NS_NATIVE_WIDGET)) {
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mDwnRadioBtn)) {
mDwnRadioBtn->SetState(PR_TRUE);
mUpRadioBtn->SetState(PR_FALSE);
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mMatchCheckBtn->GetNativeData(NS_NATIVE_WIDGET)) {
mMatchCheckBtn->SetState(!mMatchCheckBtn->GetState());
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mMatchCheckBtn)) {
PRBool state = PR_FALSE;
mMatchCheckBtn->GetState(state);
mMatchCheckBtn->SetState(!state);
}
} break;
case NS_PAINT:
#ifndef XP_UNIX
// paint the background
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mDialog->GetNativeData(NS_NATIVE_WIDGET) ) {
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mDialog)) {
nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext;
drawCtx->SetColor(aEvent->widget->GetBackgroundColor());
drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect));
@ -621,31 +657,41 @@ nsBrowserWindow::DoFind()
rect.SetRect(0, 0, 380, 110);
nsRepository::CreateInstance(kDialogCID, nsnull, kIDialogIID, (void**)&mDialog);
mDialog->Create(mWindow, rect, HandleEvent, NULL);
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");
mDialog->SetClientData(this);
nscoord xx = 5;
// Create Label
rect.SetRect(xx, 8, 75, 24);
nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&mLabel);
mLabel->SetAlignment(eAlign_Right);
mLabel->Create(mDialog, rect, HandleEvent, NULL);
mLabel->SetLabel("Find what:");
mLabel->Show(PR_TRUE);
mLabel->SetFont(font);
mLabel->SetClientData(this);
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);
mTextField->Create(mDialog, rect, HandleEvent, NULL);
mTextField->SetBackgroundColor(textBGColor);
mTextField->SetForegroundColor(textFGColor);
mTextField->SetFont(font);
mTextField->Show(PR_TRUE);
mTextField->SetClientData(this);
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;
@ -656,30 +702,36 @@ nsBrowserWindow::DoFind()
// Create Up RadioButton
rect.SetRect(x, y, w, h);
nsRepository::CreateInstance(kRadioButtonCID, nsnull, kIRadioButtonIID, (void**)&mUpRadioBtn);
mUpRadioBtn->Create(mDialog, rect, HandleEvent, NULL);
mUpRadioBtn->SetLabel("Up");
mUpRadioBtn->SetFont(font);
mUpRadioBtn->Show(PR_TRUE);
mUpRadioBtn->SetClientData(this);
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);
mDwnRadioBtn->Create(mDialog, rect, HandleEvent, NULL);
mDwnRadioBtn->SetLabel("Down");
mDwnRadioBtn->SetFont(font);
mDwnRadioBtn->Show(PR_TRUE);
mDwnRadioBtn->SetClientData(this);
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);
mMatchCheckBtn->Create(mDialog, rect, HandleEvent, NULL);
mMatchCheckBtn->SetLabel("Match Case");
mMatchCheckBtn->SetFont(font);
mMatchCheckBtn->Show(PR_TRUE);
mMatchCheckBtn->SetClientData(this);
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);
@ -687,24 +739,25 @@ nsBrowserWindow::DoFind()
// Create Find Next Button
rect.SetRect(xx, 5, 75, 24);
nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mFindBtn);
mFindBtn->Create(mDialog, rect, HandleEvent, NULL);
mFindBtn->SetLabel("Find Next");
mFindBtn->SetFont(font);
mFindBtn->Show(PR_TRUE);
mFindBtn->SetClientData(this);
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);
mCancelBtn->Create(mDialog, rect, HandleEvent, NULL);
mCancelBtn->SetLabel("Cancel");
mCancelBtn->SetFont(font);
mCancelBtn->Show(PR_TRUE);
mCancelBtn->SetClientData(this);
NS_CreateButton(mDialog,mCancelBtn,rect,HandleEvent,&font);
if (NS_OK == mCancelBtn->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetClientData(this);
mCancelBtn->SetLabel("Cancel");
NS_RELEASE(widget);
}
}
mDialog->Show(PR_TRUE);
mTextField->SetFocus();
mTextField->SelectAll();
}
@ -893,10 +946,16 @@ nsBrowserWindow::CreateToolBar(PRInt32 aWidth)
return rv;
}
nsRect r(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
mBack->Create(mWindow, r, HandleBackEvent, NULL);
mBack->SetLabel("Back");
mBack->SetFont(font);
mBack->Show(PR_TRUE);
nsIWidget* widget = nsnull;
NS_CreateButton(mWindow,mBack,r,HandleBackEvent,&font);
if (NS_OK == mBack->QueryInterface(kIWidgetIID,(void**)&widget))
{
mBack->SetLabel("Back");
NS_RELEASE(widget);
}
// Create and place forward button
r.SetRect(BUTTON_WIDTH, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
@ -905,10 +964,15 @@ nsBrowserWindow::CreateToolBar(PRInt32 aWidth)
if (NS_OK != rv) {
return rv;
}
mForward->Create(mWindow, r, HandleForwardEvent, NULL);
mForward->SetLabel("Forward");
mForward->SetFont(font);
mForward->Show(PR_TRUE);
if (NS_OK == mForward->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->Create(mWindow, r, HandleBackEvent, NULL);
widget->SetFont(font);
widget->Show(PR_TRUE);
mForward->SetLabel("Forward");
NS_RELEASE(widget);
}
// Create and place location bar
r.SetRect(2*BUTTON_WIDTH, 0,
@ -919,12 +983,16 @@ nsBrowserWindow::CreateToolBar(PRInt32 aWidth)
if (NS_OK != rv) {
return rv;
}
mLocation->Create(mWindow, r, HandleLocationEvent, NULL);
mLocation->SetText("");
mLocation->SetForegroundColor(NS_RGB(0, 0, 0));
mLocation->SetBackgroundColor(NS_RGB(255, 255, 255));
mLocation->Show(PR_TRUE);
mLocation->SetFont(font);
NS_CreateTextWidget(mWindow,mLocation,r,HandleLocationEvent,&font);
if (NS_OK == mLocation->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetForegroundColor(NS_RGB(0, 0, 0));
widget->SetBackgroundColor(NS_RGB(255, 255, 255));
PRUint32 size;
mLocation->SetText("",size);
NS_RELEASE(widget);
}
// Create and place throbber
r.SetRect(aWidth - THROBBER_WIDTH, 0,
@ -959,11 +1027,16 @@ nsBrowserWindow::CreateStatusBar(PRInt32 aWidth)
if (NS_OK != rv) {
return rv;
}
mStatus->Create(mWindow, r, HandleLocationEvent, NULL);
mStatus->SetText("");
mStatus->SetForegroundColor(NS_RGB(0, 0, 0));
mStatus->SetFont(font);
mStatus->Show(PR_TRUE);
nsIWidget* widget = nsnull;
NS_CreateTextWidget(mWindow,mStatus,r,HandleLocationEvent,&font);
if (NS_OK == mStatus->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetForegroundColor(NS_RGB(0, 0, 0));
PRUint32 size;
mStatus->SetText("",size);
NS_RELEASE(widget);
}
return NS_OK;
}
@ -980,47 +1053,56 @@ nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
txtHeight = 24;
}
nsIWidget* locationWidget = nsnull;
if (NS_OK == mLocation->QueryInterface(kIWidgetIID,(void**)&locationWidget))
{
// position location bar (it's stretchy)
if (mLocation) {
if (mThrobber) {
locationWidget->Resize(2*BUTTON_WIDTH, 0,
aWidth - (2*BUTTON_WIDTH + THROBBER_WIDTH),
BUTTON_HEIGHT,
PR_TRUE);
}
else {
locationWidget->Resize(2*BUTTON_WIDTH, 0,
aWidth - 2*BUTTON_WIDTH,
BUTTON_HEIGHT,
PR_TRUE);
}
}
// position location bar (it's stretchy)
if (mLocation) {
if (mThrobber) {
mLocation->Resize(2*BUTTON_WIDTH, 0,
aWidth - (2*BUTTON_WIDTH + THROBBER_WIDTH),
BUTTON_HEIGHT,
PR_TRUE);
mThrobber->MoveTo(aWidth - THROBBER_WIDTH, 0);
}
else {
mLocation->Resize(2*BUTTON_WIDTH, 0,
aWidth - 2*BUTTON_WIDTH,
BUTTON_HEIGHT,
PR_TRUE);
nsRect rr(0, 0, aWidth, aHeight);
if (mLocation) {
rr.y += BUTTON_HEIGHT;
rr.height -= BUTTON_HEIGHT;
}
nsIWidget* statusWidget = nsnull;
if (NS_OK == mStatus->QueryInterface(kIWidgetIID,(void**)&statusWidget))
{
if (mStatus) {
statusWidget->Resize(0, aHeight - txtHeight,
aWidth, txtHeight,
PR_TRUE);
rr.height -= txtHeight;
}
}
// inset the web widget
rr.x += WEBSHELL_LEFT_INSET;
rr.y += WEBSHELL_TOP_INSET;
rr.width -= WEBSHELL_LEFT_INSET + WEBSHELL_RIGHT_INSET;
rr.height -= WEBSHELL_TOP_INSET + WEBSHELL_BOTTOM_INSET;
mWebShell->SetBounds(rr.x, rr.y, rr.width, rr.height);
NS_RELEASE(locationWidget);
}
if (mThrobber) {
mThrobber->MoveTo(aWidth - THROBBER_WIDTH, 0);
}
nsRect rr(0, 0, aWidth, aHeight);
if (mLocation) {
rr.y += BUTTON_HEIGHT;
rr.height -= BUTTON_HEIGHT;
}
if (mStatus) {
mStatus->Resize(0, aHeight - txtHeight,
aWidth, txtHeight,
PR_TRUE);
rr.height -= txtHeight;
}
// inset the web widget
rr.x += WEBSHELL_LEFT_INSET;
rr.y += WEBSHELL_TOP_INSET;
rr.width -= WEBSHELL_LEFT_INSET + WEBSHELL_RIGHT_INSET;
rr.height -= WEBSHELL_TOP_INSET + WEBSHELL_BOTTOM_INSET;
mWebShell->SetBounds(rr.x, rr.y, rr.width, rr.height);
}
NS_IMETHODIMP
@ -1073,6 +1155,7 @@ nsBrowserWindow::Close()
return NS_OK;
}
NS_IMETHODIMP
nsBrowserWindow::SetChrome(PRUint32 aChromeMask)
{
@ -1118,7 +1201,8 @@ NS_IMETHODIMP
nsBrowserWindow::SetStatus(const PRUnichar* aStatus)
{
if (nsnull != mStatus) {
mStatus->SetText(aStatus);
PRUint32 size;
mStatus->SetText(aStatus,size);
}
return NS_OK;
}
@ -1141,7 +1225,8 @@ nsBrowserWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadT
if (mStatus) {
nsAutoString url("Connecting to ");
url.Append(aURL);
mStatus->SetText(url);
PRUint32 size;
mStatus->SetText(url,size);
}
return NS_OK;
}
@ -1151,7 +1236,8 @@ nsBrowserWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
{
if (mThrobber) {
mThrobber->Start();
mLocation->SetText(aURL);
PRUint32 size;
mLocation->SetText(aURL,size);
}
return NS_OK;
}
@ -1171,6 +1257,7 @@ nsBrowserWindow::EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32
return NS_OK;
}
NS_IMETHODIMP
nsBrowserWindow::NewWebShell(nsIWebShell *&aNewWebShell)
{
@ -1224,7 +1311,8 @@ nsBrowserWindow::OnProgress(nsIURL* aURL,
url.Append(aProgressMax, 10);
url.Append(")");
}
mStatus->SetText(url);
PRUint32 size;
mStatus->SetText(url,size);
}
return NS_OK;
}
@ -1233,7 +1321,8 @@ NS_IMETHODIMP
nsBrowserWindow::OnStatus(nsIURL* aURL, const nsString& aMsg)
{
if (mStatus) {
mStatus->SetText(aMsg);
PRUint32 size;
mStatus->SetText(aMsg,size);
}
return NS_OK;
}
@ -1247,7 +1336,8 @@ nsBrowserWindow::OnStartBinding(nsIURL* aURL, const char *aContentType)
aURL->ToString(url);
}
url.Append(": start");
mStatus->SetText(url);
PRUint32 size;
mStatus->SetText(url,size);
}
return NS_OK;
}
@ -1266,7 +1356,8 @@ nsBrowserWindow::OnStopBinding(nsIURL* aURL,
aURL->ToString(url);
}
url.Append(": stop");
mStatus->SetText(url);
PRUint32 size;
mStatus->SetText(url,size);
}
return NS_OK;
}

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

@ -37,6 +37,7 @@
#include "nsITextWidget.h"
#include "nsILookAndFeel.h"
#include "nsColor.h"
#include "nsWidgetSupport.h"
// XXX For font setting below
#include "nsFont.h"
@ -63,6 +64,9 @@ static NS_DEFINE_IID(kINetContainerApplicationIID,
NS_INETCONTAINERAPPLICATION_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsViewerApp::nsViewerApp()
{
char * text = PR_GetEnv("NGLAYOUT_HOME");
@ -558,6 +562,20 @@ static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID);
static void* GetWidgetNativeData(nsISupports* aObject)
{
void* result = nsnull;
nsIWidget* widget;
if (NS_OK == aObject->QueryInterface(kIWidgetIID,(void**)&widget))
{
result = widget->GetNativeData(NS_NATIVE_WIDGET);
NS_RELEASE(widget);
}
return result;
}
#ifdef XP_PC
extern JSConsole *gConsole;
@ -601,12 +619,14 @@ nsEventStatus PR_CALLBACK HandleRobotEvent(nsGUIEvent *aEvent)
switch(aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_UP: {
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mCancelBtn->GetNativeData(NS_NATIVE_WIDGET)) {
mRobotDialog->Show(PR_FALSE);
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mStartBtn->GetNativeData(NS_NATIVE_WIDGET)) {
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mCancelBtn)) {
NS_ShowWidget(mRobotDialog,PR_FALSE);
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mStartBtn)) {
nsString str;
mStopAfterTxt->GetText(str, 255);
PRUint32 size;
mStopAfterTxt->GetText(str, 255, size);
char * cStr = str.ToNewCString();
sscanf(cStr, "%d", &gDebugRobotLoads);
if (gDebugRobotLoads <= 0) {
@ -614,12 +634,14 @@ nsEventStatus PR_CALLBACK HandleRobotEvent(nsGUIEvent *aEvent)
}
delete[] cStr;
mVerDirTxt->GetText(str, 255);
mVerDirTxt->GetText(str, 255, size);
str.ToCString(gVerifyDir, (PRInt32)_MAX_PATH);
if (!strcmp(gVerifyDir,DEBUG_EMPTY)) {
gVerifyDir[0] = '\0';
}
gVisualDebug = mUpdateChkBtn->GetState() ? TRUE: FALSE;
PRBool state = PR_FALSE;
mUpdateChkBtn->GetState(state);
gVisualDebug = state ? TRUE: FALSE;
}
@ -628,7 +650,7 @@ nsEventStatus PR_CALLBACK HandleRobotEvent(nsGUIEvent *aEvent)
case NS_PAINT:
#ifndef XP_UNIX
// paint the background
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mRobotDialog->GetNativeData(NS_NATIVE_WIDGET) ) {
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mRobotDialog ) {
nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext;
drawCtx->SetColor(aEvent->widget->GetBackgroundColor());
drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect));
@ -654,8 +676,8 @@ PRBool CreateRobotDialog(nsIWidget * aParent)
PRBool result = TRUE;
if (mRobotDialog != nsnull) {
mRobotDialog->Show(PR_TRUE);
mStartBtn->SetFocus();
NS_ShowWidget(mRobotDialog,PR_TRUE);
NS_SetFocusToWidget(mStartBtn);
return TRUE;
}
@ -676,7 +698,7 @@ PRBool CreateRobotDialog(nsIWidget * aParent)
rect.SetRect(0, 0, dialogWidth, 162);
nsRepository::CreateInstance(kDialogCID, nsnull, kIDialogIID, (void**)&mRobotDialog);
mRobotDialog->Create(aParent, rect, HandleRobotEvent, NULL);
NS_CreateDialog(aParent, mRobotDialog,rect,HandleRobotEvent,&font);
mRobotDialog->SetLabel("Debug Robot Options");
nscoord txtHeight = 24;
@ -698,10 +720,8 @@ PRBool CreateRobotDialog(nsIWidget * aParent)
// Create Update CheckButton
rect.SetRect(x, y, 150, 24);
nsRepository::CreateInstance(kCheckButtonCID, nsnull, kICheckButtonIID, (void**)&mUpdateChkBtn);
mUpdateChkBtn->Create(mRobotDialog, rect, HandleRobotEvent, NULL);
NS_CreateCheckButton(mRobotDialog, mUpdateChkBtn,rect,HandleRobotEvent,&font);
mUpdateChkBtn->SetLabel("Update Display (Visual)");
mUpdateChkBtn->SetFont(font);
mUpdateChkBtn->Show(PR_TRUE);
mUpdateChkBtn->SetState(PR_TRUE);
y += 24 + 2;
@ -709,25 +729,24 @@ PRBool CreateRobotDialog(nsIWidget * aParent)
w = 115;
rect.SetRect(x, y+3, w, 24);
nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&label);
NS_CreateLabel(mRobotDialog,label,rect,HandleRobotEvent,&font);
label->SetAlignment(eAlign_Right);
label->Create(mRobotDialog, rect, HandleRobotEvent, NULL);
label->SetLabel("Verfication Directory:");
label->Show(PR_TRUE);
label->SetFont(font);
x += w + 1;
// Create TextField
nsIWidget* widget = nsnull;
rect.SetRect(x, y, 225, txtHeight);
nsRepository::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID, (void**)&mVerDirTxt);
mVerDirTxt->Create(mRobotDialog, rect, HandleRobotEvent, NULL);
mVerDirTxt->SetBackgroundColor(textBGColor);
mVerDirTxt->SetForegroundColor(textFGColor);
mVerDirTxt->SetFont(font);
mVerDirTxt->SetText(DEBUG_EMPTY);
mVerDirTxt->Show(PR_TRUE);
NS_CreateTextWidget(mRobotDialog,mVerDirTxt,rect,HandleRobotEvent,&font);
if (mVerDirTxt && NS_OK == mVerDirTxt->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetBackgroundColor(textBGColor);
widget->SetForegroundColor(textFGColor);
}
nsString str(DEBUG_EMPTY);
mVerDirTxt->SetText(str);
PRUint32 size;
mVerDirTxt->SetText(str,size);
y += txtHeight + 2;
@ -735,33 +754,29 @@ PRBool CreateRobotDialog(nsIWidget * aParent)
w = 55;
rect.SetRect(x, y+4, w, 24);
nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&label);
NS_CreateLabel(mRobotDialog,label,rect,HandleRobotEvent,&font);
label->SetAlignment(eAlign_Right);
label->Create(mRobotDialog, rect, HandleRobotEvent, NULL);
label->SetLabel("Stop after:");
label->Show(PR_TRUE);
label->SetFont(font);
x += w + 2;
// Create TextField
rect.SetRect(x, y, 75, txtHeight);
nsRepository::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID, (void**)&mStopAfterTxt);
mStopAfterTxt->Create(mRobotDialog, rect, HandleRobotEvent, NULL);
mStopAfterTxt->SetBackgroundColor(textBGColor);
mStopAfterTxt->SetForegroundColor(textFGColor);
mStopAfterTxt->SetFont(font);
mStopAfterTxt->Show(PR_TRUE);
mStopAfterTxt->SetText("5000");
NS_CreateTextWidget(mRobotDialog,mStopAfterTxt,rect,HandleRobotEvent,&font);
if (mStopAfterTxt && NS_OK == mStopAfterTxt->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->SetBackgroundColor(textBGColor);
widget->SetForegroundColor(textFGColor);
mStopAfterTxt->SetText("5000",size);
}
x += 75 + 2;
w = 75;
rect.SetRect(x, y+4, w, 24);
nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&label);
NS_CreateLabel(mRobotDialog,label,rect,HandleRobotEvent,&font);
label->SetAlignment(eAlign_Left);
label->Create(mRobotDialog, rect, HandleRobotEvent, NULL);
label->SetLabel("(page loads)");
label->Show(PR_TRUE);
label->SetFont(font);
y += txtHeight + 2;
@ -771,22 +786,18 @@ PRBool CreateRobotDialog(nsIWidget * aParent)
// Create Find Start Button
rect.SetRect(xx, y, w, 24);
nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mStartBtn);
mStartBtn->Create(mRobotDialog, rect, HandleRobotEvent, NULL);
NS_CreateButton(mRobotDialog,mStartBtn,rect,HandleRobotEvent,&font);
mStartBtn->SetLabel("Start");
mStartBtn->SetFont(font);
mStartBtn->Show(PR_TRUE);
xx += w + xx;
// Create Cancel Button
rect.SetRect(xx, y, w, 24);
nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mCancelBtn);
mCancelBtn->Create(mRobotDialog, rect, HandleRobotEvent, NULL);
NS_CreateButton(mRobotDialog,mCancelBtn,rect,HandleRobotEvent,&font);
mCancelBtn->SetLabel("Cancel");
mCancelBtn->SetFont(font);
mCancelBtn->Show(PR_TRUE);
mRobotDialog->Show(PR_TRUE);
mStartBtn->SetFocus();
NS_ShowWidget(mRobotDialog,PR_TRUE);
NS_SetFocusToWidget(mStartBtn);
return result;
}
@ -969,22 +980,22 @@ nsEventStatus PR_CALLBACK HandleSiteEvent(nsGUIEvent *aEvent)
switch(aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_UP: {
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mSiteCancelBtn->GetNativeData(NS_NATIVE_WIDGET)) {
mSiteDialog->Show(PR_FALSE);
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mSitePrevBtn->GetNativeData(NS_NATIVE_WIDGET)) {
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mSiteCancelBtn)) {
NS_ShowWidget(mSiteDialog,PR_FALSE);
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mSitePrevBtn)) {
if (gTop100Pointer > 0) {
mSiteNextBtn->Enable(PR_TRUE);
NS_EnableWidget(mSiteNextBtn,PR_TRUE);
if (gWinData) {
nsString urlStr(gTop100List[--gTop100Pointer]);
mSiteLabel->SetLabel(urlStr);
gWinData->GoTo(urlStr);
}
} else {
mSitePrevBtn->Enable(PR_FALSE);
mSiteNextBtn->Enable(PR_TRUE);
NS_EnableWidget(mSitePrevBtn,PR_FALSE);
NS_EnableWidget(mSiteNextBtn,PR_TRUE);
}
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mSiteNextBtn->GetNativeData(NS_NATIVE_WIDGET)) {
} else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mSiteNextBtn)) {
char * p = gTop100List[++gTop100Pointer];
if (p) {
@ -993,10 +1004,10 @@ nsEventStatus PR_CALLBACK HandleSiteEvent(nsGUIEvent *aEvent)
mSiteLabel->SetLabel(urlStr);
gWinData->GoTo(urlStr);
}
mSitePrevBtn->Enable(PR_TRUE);
NS_EnableWidget(mSitePrevBtn,PR_TRUE);
} else {
mSitePrevBtn->Enable(PR_TRUE);
mSiteNextBtn->Enable(PR_FALSE);
NS_EnableWidget(mSitePrevBtn,PR_TRUE);
NS_EnableWidget(mSiteNextBtn,PR_FALSE);
mSiteLabel->SetLabel("[END OF LIST]");
}
}
@ -1005,7 +1016,7 @@ nsEventStatus PR_CALLBACK HandleSiteEvent(nsGUIEvent *aEvent)
case NS_PAINT:
#ifndef XP_UNIX
// paint the background
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mSiteDialog->GetNativeData(NS_NATIVE_WIDGET) ) {
if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mSiteDialog) ) {
nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext;
drawCtx->SetColor(aEvent->widget->GetBackgroundColor());
drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect));
@ -1058,9 +1069,13 @@ PRBool CreateSiteDialog(nsIWidget * aParent)
nsRect rect;
rect.SetRect(0, 0, dialogWidth, 125);
nsIWidget* widget = nsnull;
nsRepository::CreateInstance(kDialogCID, nsnull, kIDialogIID, (void**)&mSiteDialog);
mSiteDialog->Create(aParent, rect, HandleSiteEvent, NULL);
mSiteDialog->SetLabel("Top 100 Site Walker");
if (mSiteDialog && NS_OK == mSiteDialog->QueryInterface(kIWidgetIID,(void**)&widget))
{
widget->Create(aParent, rect, HandleSiteEvent, NULL);
mSiteDialog->SetLabel("Top 100 Site Walker");
}
//mSiteDialog->SetClientData(this);
nscoord w = 65;
@ -1072,21 +1087,17 @@ PRBool CreateSiteDialog(nsIWidget * aParent)
w = 50;
rect.SetRect(x, y+3, w, 24);
nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&label);
NS_CreateLabel(mSiteDialog,label,rect,HandleSiteEvent,&font);
label->SetAlignment(eAlign_Right);
label->Create(mSiteDialog, rect, HandleSiteEvent, NULL);
label->SetLabel("Site:");
label->Show(PR_TRUE);
label->SetFont(font);
x += w + 1;
w = 250;
rect.SetRect(x, y+3, w, 24);
nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&mSiteLabel);
NS_CreateLabel(mSiteDialog,mSiteLabel,rect,HandleSiteEvent,&font);
mSiteLabel->SetAlignment(eAlign_Left);
mSiteLabel->Create(mSiteDialog, rect, HandleSiteEvent, NULL);
mSiteLabel->SetLabel("");
mSiteLabel->Show(PR_TRUE);
mSiteLabel->SetFont(font);
y += 34;
w = 75;
@ -1095,35 +1106,30 @@ PRBool CreateSiteDialog(nsIWidget * aParent)
// Create Previous Button
rect.SetRect(x, y, w, 24);
nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mSitePrevBtn);
mSitePrevBtn->Create(mSiteDialog, rect, HandleSiteEvent, NULL);
NS_CreateButton(mSiteDialog,mSitePrevBtn,rect,HandleSiteEvent,&font);
mSitePrevBtn->SetLabel("<< Previous");
mSitePrevBtn->SetFont(font);
mSitePrevBtn->Show(PR_TRUE);
x += spacing + w;
// Create Next Button
rect.SetRect(x, y, w, 24);
nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mSiteNextBtn);
mSiteNextBtn->Create(mSiteDialog, rect, HandleSiteEvent, NULL);
NS_CreateButton(mSiteDialog,mSiteNextBtn,rect,HandleSiteEvent,&font);
mSiteNextBtn->SetLabel("Next >>");
mSiteNextBtn->SetFont(font);
mSiteNextBtn->Show(PR_TRUE);
x += spacing + w;
// Create Cancel Button
rect.SetRect(x, y, w, 24);
nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mSiteCancelBtn);
mSiteCancelBtn->Create(mSiteDialog, rect, HandleSiteEvent, NULL);
NS_CreateButton(mSiteDialog,mSiteCancelBtn,rect,HandleSiteEvent,&font);
mSiteCancelBtn->SetLabel("Cancel");
mSiteCancelBtn->SetFont(font);
mSiteCancelBtn->Show(PR_TRUE);
}
mSiteDialog->Show(PR_TRUE);
mSiteNextBtn->SetFocus();
NS_ShowWidget(mSiteDialog,PR_TRUE);
NS_SetFocusToWidget(mSiteNextBtn);
// Init
mSitePrevBtn->Enable(PR_FALSE);
NS_EnableWidget(mSitePrevBtn,PR_FALSE);
if (gWinData) {
nsString urlStr(gTop100List[gTop100Pointer]);
gWinData->GoTo(urlStr);