From ca8b8dba385e290b91bf01b0c48baced56728bbf Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Wed, 9 Feb 2000 19:28:24 +0000 Subject: [PATCH] cleaning up viewer to use local versions widget files and support bug 17027, carpool a=leaf, r=kmcclusk --- webshell/tests/viewer/makefile.win | 4 +- webshell/tests/viewer/nsBrowserWindow.cpp | 96 ------- webshell/tests/viewer/nsBrowserWindow.h | 12 - webshell/tests/viewer/nsSetupRegistry.cpp | 67 +++-- webshell/tests/viewer/nsWidgetSupport.cpp | 246 ++++++++++++++++++ webshell/tests/viewer/nsWidgetSupport.h | 113 ++++++++ .../tests/viewer/windows/nsTextHelper.cpp | 2 +- webshell/tests/viewer/windows/nsTextHelper.h | 2 - 8 files changed, 403 insertions(+), 139 deletions(-) create mode 100644 webshell/tests/viewer/nsWidgetSupport.cpp create mode 100644 webshell/tests/viewer/nsWidgetSupport.h diff --git a/webshell/tests/viewer/makefile.win b/webshell/tests/viewer/makefile.win index f9b229a28d3b..9970b8beb815 100644 --- a/webshell/tests/viewer/makefile.win +++ b/webshell/tests/viewer/makefile.win @@ -41,7 +41,6 @@ LCFLAGS = $(LCFLAGS) -DUSE_LOCAL_WIDGETS OBJS = \ .\$(OBJDIR)\nsBaseDialog.obj \ - .\$(OBJDIR)\nsFindDialog.obj \ .\$(OBJDIR)\nsImageInspectorDialog.obj \ .\$(OBJDIR)\nsTableInspectorDialog.obj \ .\$(OBJDIR)\nsPrintSetupDialog.obj \ @@ -55,6 +54,7 @@ OBJS = \ .\$(OBJDIR)\nsWebBrowserChrome.obj \ .\$(OBJDIR)\nsWinMain.obj \ .\$(OBJDIR)\JSConsole.obj \ + .\$(OBJDIR)\nsWidgetSupport.obj \ $(NULL) LINCS= \ @@ -96,7 +96,7 @@ LLIBS= \ $(DIST)\lib\raptornativewidgets_s.lib \ $(DIST)\lib\raptorbasewidget_s.lib \ $(DIST)\lib\raptorwidget_s.lib \ - $(DIST)\lib\widgetsupport_s.lib \ +# $(DIST)\lib\widgetsupport_s.lib \ $(DIST)\lib\DebugRobot.lib \ $(DIST)\lib\xpcom.lib \ $(DIST)\lib\js32$(VERSION_NUMBER).lib \ diff --git a/webshell/tests/viewer/nsBrowserWindow.cpp b/webshell/tests/viewer/nsBrowserWindow.cpp index e75e32599615..889539bebe3d 100644 --- a/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/webshell/tests/viewer/nsBrowserWindow.cpp @@ -76,12 +76,10 @@ // Needed for "Find" GUI #include "nsICheckButton.h" -#include "nsIRadioButton.h" #include "nsILabel.h" #include "nsWidgetSupport.h" #include "nsXPBaseWindow.h" -#include "nsFindDialog.h" #include "resources.h" @@ -174,7 +172,6 @@ static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID); static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID); static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID); -static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID); static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID); static NS_DEFINE_IID(kIPromptIID, NS_IPROMPT_IID); static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID); @@ -933,76 +930,12 @@ nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent) switch(aEvent->message) { case NS_KEY_DOWN: { - nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; - if (NS_VK_RETURN == keyEvent->keyCode) { - PRBool matchCase = PR_FALSE; - mMatchCheckBtn->GetState(matchCase); - PRBool findDwn = PR_FALSE; - mDwnRadioBtn->GetState(findDwn); - nsString searchStr; - PRUint32 actualSize; - mTextField->GetText(searchStr, 255,actualSize); - PRBool foundIt; - FindNext(searchStr, matchCase, findDwn, foundIt); - } } break; case NS_MOUSE_LEFT_BUTTON_UP: { - 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 = PR_FALSE; - mMatchCheckBtn->GetState(matchCase); - PRBool findDwn = PR_FALSE; - mDwnRadioBtn->GetState(findDwn); - PRUint32 actualSize; - nsString searchStr; - mTextField->GetText(searchStr, 255,actualSize); - - nsIPresShell* shell = GetPresShell(); - if (nsnull != shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); - if (doc) { - PRBool foundIt = PR_FALSE; - doc->FindNext(searchStr, matchCase, findDwn, foundIt); - if (!foundIt) { - // Display Dialog here - } - ForceRefresh(); - } - NS_RELEASE(shell); - } - - } 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) == GetItemsNativeData(mDwnRadioBtn)) { - mDwnRadioBtn->SetState(PR_TRUE); - mUpRadioBtn->SetState(PR_FALSE); - } 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) == GetItemsNativeData(mDialog)) { - nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext; - drawCtx->SetColor(aEvent->widget->GetBackgroundColor()); - drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect)); - - return nsEventStatus_eIgnore; - } -#endif break; default: result = nsEventStatus_eIgnore; @@ -1015,35 +948,6 @@ nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent) void nsBrowserWindow::DoFind() { - if (mXPDialog) { - NS_RELEASE(mXPDialog); - //mXPDialog->SetVisible(PR_TRUE); - //return; - } - - 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 = nsComponentManager::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)) { - } - } - - nsFindDialog * findDialog = new nsFindDialog(this); - if (nsnull != findDialog) { - dialog->AddWindowListener(findDialog); - } - //NS_IF_RELEASE(dialog); - } diff --git a/webshell/tests/viewer/nsBrowserWindow.h b/webshell/tests/viewer/nsBrowserWindow.h index 1bec761982d4..31b276b54de6 100644 --- a/webshell/tests/viewer/nsBrowserWindow.h +++ b/webshell/tests/viewer/nsBrowserWindow.h @@ -40,14 +40,12 @@ #include "nsIXPBaseWindow.h" #include "nsPrintSetupDialog.h" -#include "nsFindDialog.h" #include "nsTableInspectorDialog.h" #include "nsImageInspectorDialog.h" #include "nsIPrompt.h" class nsILabel; class nsICheckButton; -class nsIRadioButton; class nsITextWidget; class nsIButton; class nsThrobber; @@ -260,16 +258,6 @@ public: // "Status bar" nsITextWidget* mStatus; - // Find Dialog - nsIBrowserWindow * mDialog; - nsIButton * mCancelBtn; - nsIButton * mFindBtn; - nsITextWidget * mTextField; - nsICheckButton * mMatchCheckBtn; - nsIRadioButton * mUpRadioBtn; - nsIRadioButton * mDwnRadioBtn; - nsILabel * mLabel; - nsIXPBaseWindow * mXPDialog; nsIXPBaseWindow * mTableInspectorDialog; nsIXPBaseWindow * mImageInspectorDialog; diff --git a/webshell/tests/viewer/nsSetupRegistry.cpp b/webshell/tests/viewer/nsSetupRegistry.cpp index c9085b93998f..9697c3d1c6a2 100644 --- a/webshell/tests/viewer/nsSetupRegistry.cpp +++ b/webshell/tests/viewer/nsSetupRegistry.cpp @@ -109,17 +109,7 @@ static NS_DEFINE_IID(kCWindowCID, NS_WINDOW_CID); static NS_DEFINE_IID(kCVScrollbarCID, NS_VERTSCROLLBAR_CID); static NS_DEFINE_IID(kCHScrollbarCID, NS_HORZSCROLLBAR_CID); static NS_DEFINE_IID(kCDialogCID, NS_DIALOG_CID); -static NS_DEFINE_IID(kCLabelCID, NS_LABEL_CID); -static NS_DEFINE_IID(kCButtonCID, NS_BUTTON_CID); -static NS_DEFINE_IID(kCComboBoxCID, NS_COMBOBOX_CID); -static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID); -static NS_DEFINE_IID(kCListBoxCID, NS_LISTBOX_CID); -static NS_DEFINE_IID(kCRadioButtonCID, NS_RADIOBUTTON_CID); -static NS_DEFINE_IID(kCTextAreaCID, NS_TEXTAREA_CID); -static NS_DEFINE_IID(kCTextFieldCID, NS_TEXTFIELD_CID); -static NS_DEFINE_IID(kCCheckButtonCID, NS_CHECKBUTTON_CID); static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID); -static NS_DEFINE_IID(kCPopUpCID,NS_POPUP_CID); static NS_DEFINE_IID(kCAppShellCID, NS_APPSHELL_CID); static NS_DEFINE_IID(kCToolkitCID, NS_TOOLKIT_CID); static NS_DEFINE_IID(kClipboardCID, NS_CLIPBOARD_CID); @@ -127,17 +117,27 @@ static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID); static NS_DEFINE_IID(kDataFlavorCID, NS_DATAFLAVOR_CID); static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID); static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID); -//static NS_DEFINE_IID(kCFileListTransferableCID, NS_FILELISTTRANSFERABLE_CID); static NS_DEFINE_IID(kCFontRetrieverServiceCID, NS_FONTRETRIEVERSERVICE_CID); -static NS_DEFINE_IID(kCMenuBarCID, NS_MENUBAR_CID); -static NS_DEFINE_IID(kCMenuCID, NS_MENU_CID); -static NS_DEFINE_IID(kCMenuItemCID, NS_MENUITEM_CID); -static NS_DEFINE_IID(kCContextMenuCID, NS_CONTEXTMENU_CID); static NS_DEFINE_IID(kCTimerCID, NS_TIMER_CID); static NS_DEFINE_IID(kCTimerManagerCID, NS_TIMERMANAGER_CID); -//static NS_DEFINE_IID(kCXULCommandCID, NS_XULCOMMAND_CID); static NS_DEFINE_IID(kSoundCID, NS_SOUND_CID); static NS_DEFINE_CID(kFileSpecWithUICID, NS_FILESPECWITHUI_CID); +static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID); +static NS_DEFINE_IID(kCPopUpCID,NS_POPUP_CID); + +// widgets +static NS_DEFINE_IID(kCLabelCID, NS_LABEL_CID); +static NS_DEFINE_IID(kCButtonCID, NS_BUTTON_CID); +static NS_DEFINE_IID(kCTextFieldCID, NS_TEXTFIELD_CID); +static NS_DEFINE_IID(kCCheckButtonCID, NS_CHECKBUTTON_CID); + +// unneeded widgets +#if 0 +static NS_DEFINE_IID(kCListBoxCID, NS_LISTBOX_CID); +static NS_DEFINE_IID(kCRadioButtonCID, NS_RADIOBUTTON_CID); +static NS_DEFINE_IID(kCComboBoxCID, NS_COMBOBOX_CID); +static NS_DEFINE_IID(kCTextAreaCID, NS_TEXTAREA_CID); +#endif // GFXWIN static NS_DEFINE_CID(kCRenderingContextCID, NS_RENDERING_CONTEXT_CID); @@ -305,15 +305,7 @@ NS_SetupRegistry() nsComponentManager::RegisterComponentLib(kCVScrollbarCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCHScrollbarCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCDialogCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kCLabelCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kCButtonCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kCComboBoxCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCFileWidgetCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kCListBoxCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kCRadioButtonCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kCTextAreaCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kCTextFieldCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kCCheckButtonCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCChildCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCPopUpCID,NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCAppShellCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); @@ -328,12 +320,35 @@ NS_SetupRegistry() nsComponentManager::RegisterComponentLib(kCTimerCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCTimerManagerCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); #endif + nsComponentManager::RegisterComponentLib(kSoundCID, "Sound Services", "component://netscape/sound", WIDGET_DLL, PR_FALSE, PR_FALSE); + nsComponentManager::RegisterComponentLib(kFileSpecWithUICID, NS_FILESPECWITHUI_CLASSNAME, NS_FILESPECWITHUI_PROGID, WIDGET_DLL, PR_FALSE, PR_FALSE); + + // WIDGETS + nsComponentManager::RegisterComponentLib(kCLabelCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsComponentManager::RegisterComponentLib(kCButtonCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsComponentManager::RegisterComponentLib(kCTextFieldCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsComponentManager::RegisterComponentLib(kCCheckButtonCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); + + // MAC ONLY WIDGETS +#ifdef XP_MAC + static NS_DEFINE_IID(kCMenuBarCID, NS_MENUBAR_CID); + static NS_DEFINE_IID(kCMenuCID, NS_MENU_CID); + static NS_DEFINE_IID(kCMenuItemCID, NS_MENUITEM_CID); + static NS_DEFINE_IID(kCContextMenuCID, NS_CONTEXTMENU_CID); + nsComponentManager::RegisterComponentLib(kCMenuBarCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCMenuCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCMenuItemCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); +#endif + + // UNNEEDED WIDGETS +#if 0 + nsComponentManager::RegisterComponentLib(kCComboBoxCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCContextMenuCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kSoundCID, "Sound Services", "component://netscape/sound", WIDGET_DLL, PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponentLib(kFileSpecWithUICID, NS_FILESPECWITHUI_CLASSNAME, NS_FILESPECWITHUI_PROGID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsComponentManager::RegisterComponentLib(kCListBoxCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsComponentManager::RegisterComponentLib(kCRadioButtonCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsComponentManager::RegisterComponentLib(kCTextAreaCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); +#endif // GFXWIN nsComponentManager::RegisterComponentLib(kCRenderingContextCID, "Rendering Context", "component://netscape/gfx/renderingcontext", GFXWIN_DLL, PR_FALSE, PR_FALSE); diff --git a/webshell/tests/viewer/nsWidgetSupport.cpp b/webshell/tests/viewer/nsWidgetSupport.cpp new file mode 100644 index 000000000000..d96610818111 --- /dev/null +++ b/webshell/tests/viewer/nsWidgetSupport.cpp @@ -0,0 +1,246 @@ +/* -*- 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.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + + +#include "nsWidgetSupport.h" +#include "nsRect.h" +#include "nsIButton.h" +#include "nsILabel.h" +#include "nsIWidget.h" +#include "nsICheckButton.h" +#include "nsITextWidget.h" +#include "nsIScrollbar.h" + + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); +static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID); +static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID); +static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID); +static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID); +static NS_DEFINE_IID(kIScrollBarIID, NS_ISCROLLBAR_IID); + +#ifdef XP_MAC + #define WIDGET_SUPPORT_EXPORT(returnType) PR_PUBLIC_API(returnType) +#else + #define WIDGET_SUPPORT_EXPORT(returnType) returnType +#endif + +WIDGET_SUPPORT_EXPORT(nsresult) +NS_CreateButton(nsISupports* aParent, + nsIButton* aButton, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget; + if (NS_OK == aButton->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + + if (aParent != nsnull) + NS_IF_RELEASE(parent); + return NS_OK; +} + +WIDGET_SUPPORT_EXPORT(nsresult) +NS_CreateCheckButton(nsISupports* aParent, + nsICheckButton* aCheckButton, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget; + if (NS_OK == aCheckButton->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + if (aParent != nsnull) + NS_IF_RELEASE(parent); + return NS_OK; +} + + + + +WIDGET_SUPPORT_EXPORT(nsresult) +NS_CreateLabel( nsISupports* aParent, + nsILabel* aLabel, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (NS_OK == aParent->QueryInterface(kIWidgetIID,(void**)&parent)) + { + nsIWidget* widget; + if (NS_OK == aLabel->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + NS_IF_RELEASE(parent); + } + return NS_OK; +} + + +WIDGET_SUPPORT_EXPORT(nsresult) +NS_CreateTextWidget(nsISupports* aParent, + nsITextWidget* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + else + { + NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object"); + } + + if (aParent) + NS_IF_RELEASE(parent); + + return NS_OK; +} + + + +WIDGET_SUPPORT_EXPORT(nsresult) +NS_CreateScrollBar(nsISupports* aParent, + nsIScrollbar* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + NS_IF_RELEASE(widget); + } + else + { + NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object"); + } + + if (aParent) + NS_IF_RELEASE(parent); + + return NS_OK; +} + +WIDGET_SUPPORT_EXPORT(nsresult) +NS_ShowWidget(nsISupports* aWidget, PRBool aShow) +{ + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Show(aShow); + NS_IF_RELEASE(widget); + } + + return NS_OK; +} + +WIDGET_SUPPORT_EXPORT(nsresult) +NS_MoveWidget(nsISupports* aWidget, PRUint32 aX, PRUint32 aY) +{ + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Move(aX,aY); + NS_IF_RELEASE(widget); + } + return NS_OK; +} + +WIDGET_SUPPORT_EXPORT(nsresult) +NS_EnableWidget(nsISupports* aWidget, PRBool aEnable) +{ + nsIWidget* widget; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) + { + widget->Enable(aEnable); + NS_RELEASE(widget); + } + return NS_OK; +} + + +WIDGET_SUPPORT_EXPORT(nsresult) +NS_SetFocusToWidget(nsISupports* aWidget) +{ + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetFocus(); + NS_IF_RELEASE(widget); + } + return NS_OK; +} + +WIDGET_SUPPORT_EXPORT(nsresult) +NS_GetWidgetNativeData(nsISupports* aWidget, void** aNativeData) +{ + void* result = nsnull; + nsIWidget* widget; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) + { + result = widget->GetNativeData(NS_NATIVE_WIDGET); + NS_RELEASE(widget); + } + *aNativeData = result; + return NS_OK; + +} diff --git a/webshell/tests/viewer/nsWidgetSupport.h b/webshell/tests/viewer/nsWidgetSupport.h new file mode 100644 index 000000000000..7db367618fa0 --- /dev/null +++ b/webshell/tests/viewer/nsWidgetSupport.h @@ -0,0 +1,113 @@ +/* -*- 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.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef nsWidgetSupport_h__ +#define nsWidgetSupport_h__ + +#include "nscore.h" +#include "nsISupports.h" +#include "nsIWidget.h" + + +struct nsRect; +class nsIFileWidget; +class nsIAppShell; +class nsIButton; +class nsIEventListener; +class nsILabel; +class nsILookAndFeel; +class nsIMouseListener; +class nsIToolkit; +class nsIWidget; +class nsICheckButton; +class nsIScrollbar; +class nsITooltipWidget; +class nsITextWidget; +class nsIBrowserWindow; + +// These are a series of support methods which help in the creation +// of widgets. They are not needed, but are provided as a convenience +// mechanism when creating widgets + +extern nsresult +NS_CreateButton( nsISupports* aParent, + nsIButton* aButton, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont = nsnull); + +extern nsresult +NS_CreateCheckButton( nsISupports* aParent, + nsICheckButton* aCheckButton, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont = nsnull); + +extern nsresult +NS_CreateLabel( nsISupports* aParent, + nsILabel* aLabel, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont = nsnull); + +extern nsresult +NS_CreateTextWidget(nsISupports* aParent, + nsITextWidget* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont = nsnull); + +extern nsresult +NS_CreateTooltipWidget(nsISupports* aParent, + nsITooltipWidget* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont = nsnull); + + +extern nsresult +NS_CreateScrollBar(nsISupports* aParent, + nsIScrollbar* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction); + + +extern nsresult +NS_ShowWidget(nsISupports* aWidget, PRBool aShow); + +extern nsresult +NS_MoveWidget(nsISupports* aWidget, PRUint32 aX, PRUint32 aY); + +extern nsresult +NS_EnableWidget(nsISupports* aWidget, PRBool aEnable); + +extern nsresult +NS_SetFocusToWidget(nsISupports* aWidget); + +extern nsresult +NS_GetWidgetNativeData(nsISupports* aWidget, void** aNativeData); + + + + + +#endif diff --git a/webshell/tests/viewer/windows/nsTextHelper.cpp b/webshell/tests/viewer/windows/nsTextHelper.cpp index cd47780d4688..52c6d5d162b9 100644 --- a/webshell/tests/viewer/windows/nsTextHelper.cpp +++ b/webshell/tests/viewer/windows/nsTextHelper.cpp @@ -148,7 +148,7 @@ NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPos) // //------------------------------------------------------------------------- -nsTextHelper::nsTextHelper() : nsWindow(), nsITextAreaWidget(), nsITextWidget() +nsTextHelper::nsTextHelper() : nsWindow(), nsITextWidget() { mIsReadOnly = PR_FALSE; mIsPassword = PR_FALSE; diff --git a/webshell/tests/viewer/windows/nsTextHelper.h b/webshell/tests/viewer/windows/nsTextHelper.h index c0f4e9963234..d851dd10dc0d 100644 --- a/webshell/tests/viewer/windows/nsTextHelper.h +++ b/webshell/tests/viewer/windows/nsTextHelper.h @@ -24,7 +24,6 @@ #include "nsdefs.h" #include "nsITextWidget.h" -#include "nsITextAreaWidget.h" #include "nsWindow.h" /** @@ -32,7 +31,6 @@ */ class nsTextHelper : public nsWindow, - public nsITextAreaWidget, public nsITextWidget {