From 00b9ad8b357bd2b99a1e21f4c83fc0346092a2be Mon Sep 17 00:00:00 2001 From: rods Date: Mon, 1 Jun 1998 20:56:12 +0000 Subject: [PATCH] initial --- widget/tests/widget/Makefile | 60 +++++++++++++ widget/tests/widget/main.cpp | 7 +- widget/tests/widget/nsWidgetTest.cpp | 130 +++++++++++++++++---------- 3 files changed, 149 insertions(+), 48 deletions(-) create mode 100644 widget/tests/widget/Makefile diff --git a/widget/tests/widget/Makefile b/widget/tests/widget/Makefile new file mode 100644 index 00000000000..b9164b107f8 --- /dev/null +++ b/widget/tests/widget/Makefile @@ -0,0 +1,60 @@ +#!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=../../.. + +include $(DEPTH)/config/config.mk + +CPPSRCS = \ + nsWidgetTest.cpp \ + $(NULL) + +INCLUDES+= -I$(PUBLIC)/raptor -I$(PUBLIC)/xpcom -I$(PUBLIC)/shell + +DIRS = + +OBJS = $(CPPSRCS:.cpp=.o) + +EX_LIBS = \ + $(DIST)/lib/libraptorbase.a \ + $(DIST)/lib/libraptorgfx.a \ + $(DIST)/lib/libxpcom.a \ + $(DIST)/lib/libreg.a \ + $(DIST)/lib/libplc21.a \ + $(DIST)/lib/libplds21.a \ + $(DIST)/lib/libnspr21.a \ + $(NULL) + +PROGS = $(addprefix $(OBJDIR)/, $(CPPSRCS:.cpp=)) + +TARGETS = $(PROGS) + +include $(DEPTH)/config/rules.mk + +$(OBJDIR)/%.o: %.cpp + @$(MAKE_OBJDIR) + $(CCC) -o $@ $(CFLAGS) -c $*.cpp + +$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(EX_LIBS) + @$(MAKE_OBJDIR) + $(CCC) -o $@ $@.o $(LDFLAGS) $(EX_LIBS) $(OS_LIBS) -lXm -lXt -lX11 + +export:: + +install:: $(TARGETS) + $(INSTALL) $(PROGS) $(DIST)/bin + diff --git a/widget/tests/widget/main.cpp b/widget/tests/widget/main.cpp index d15a853f3c6..30f96394836 100644 --- a/widget/tests/widget/main.cpp +++ b/widget/tests/widget/main.cpp @@ -15,19 +15,20 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +#include "nsWidgetTest.cpp" + #include "nsIWidget.h" extern nsresult WidgetTest(); -#ifdef XP_PC - -#include void main(int argc, char **argv) { WidgetTest(); } +#ifdef XP_PC +#include int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { diff --git a/widget/tests/widget/nsWidgetTest.cpp b/widget/tests/widget/nsWidgetTest.cpp index 9e4099be88f..c8c52535b39 100644 --- a/widget/tests/widget/nsWidgetTest.cpp +++ b/widget/tests/widget/nsWidgetTest.cpp @@ -15,9 +15,15 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +#define DEBUG 1 +#define NS_DEBUG 1 + +#include "nsDebug.h" + #include #include + //---- Factory Includes & Stuff -----// #include "nsIFactory.h" #include "nsRepository.h" @@ -79,8 +85,14 @@ char * gFailedMsg = NULL; -#define WIDGET_DLL "raptorwidget.dll" -#define GFXWIN_DLL "raptorgfxwin.dll" +#ifdef XP_PC +#define RAPTORWIDGET_LIB "raptorwidget.dll" +#define RAPTORGFX_LIB "raptorgfxwin.dll" +#else +#define RAPTORWIDGET_LIB "libwidgetunix.so" +#define RAPTORGFX_LIB "libgfxunix.so" +#endif + #define DEBUG_MOUSE 0 @@ -680,7 +692,6 @@ nsEventStatus PR_CALLBACK GenericTextTestHandleEvent(char *aTitle, */ nsEventStatus PR_CALLBACK ButtonTestHandleEvent(nsGUIEvent *aEvent) { - nsIButton * btn; if (aEvent->message != NS_MOUSE_LEFT_BUTTON_UP) { return nsEventStatus_eIgnore; @@ -688,7 +699,7 @@ nsEventStatus PR_CALLBACK ButtonTestHandleEvent(nsGUIEvent *aEvent) if (NS_OK == aEvent->widget->QueryInterface(kIButtonIID, (void**)&btn)) { nsAutoString strBuf; - nsString str("Tesing "); + nsString str("Testing "); btn->GetLabel(strBuf); char * title = strBuf.ToNewCString(); @@ -757,7 +768,7 @@ void DumpRects() */ nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent) { - // printf("aEvent->message %d\n", aEvent->message); + printf("aEvent->message %d\n", aEvent->message); nsEventStatus result = nsEventStatus_eIgnore; switch(aEvent->message) { @@ -825,8 +836,10 @@ nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent) // paint the background if (aEvent->widget == window) { nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext; - drawCtx->SetColor(aEvent->widget->GetBackgroundColor()); - drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect)); + if (nsnull != drawCtx) { + drawCtx->SetColor(aEvent->widget->GetBackgroundColor()); + drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect)); + } return nsEventStatus_eIgnore; } @@ -1015,11 +1028,10 @@ nsEventStatus PR_CALLBACK TooltipPos2(nsGUIEvent *aEvent) return(MoveTooltip(2, aEvent)); } - /**-------------------------------------------------------------------------------- * */ -nsresult WidgetTest() +nsresult WidgetTest(int* argc, char **argv) { // Open global test log file gFD = fopen(gLogFileName, "w"); @@ -1029,22 +1041,22 @@ nsresult WidgetTest() } // register widget classes - NSRepository::RegisterFactory(kCWindowCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCChildCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCButtonCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCCheckButtonCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCComboBoxCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCFileWidgetCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCListBoxCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCRadioButtonCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCRadioGroupCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCHorzScrollbarCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCVertScrollbarCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCTextAreaCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCTextFieldCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCTabWidgetCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCTooltipWidgetCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCAppShellCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCWindowCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCChildCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCButtonCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCCheckButtonCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCComboBoxCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCFileWidgetCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCListBoxCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCRadioButtonCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCRadioGroupCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCHorzScrollbarCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCVertScrollbarCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCTextAreaCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCTextFieldCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCTabWidgetCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCTooltipWidgetCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCAppShellCID, RAPTORWIDGET_LIB, PR_FALSE, PR_FALSE); static NS_DEFINE_IID(kCRenderingContextIID, NS_RENDERING_CONTEXT_CID); @@ -1053,20 +1065,28 @@ nsresult WidgetTest() static NS_DEFINE_IID(kCImageIID, NS_IMAGE_CID); - NSRepository::RegisterFactory(kCRenderingContextIID, "raptorgfxwin.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCDeviceContextIID, "raptorgfxwin.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCFontMetricsIID, "raptorgfxwin.dll", PR_FALSE, PR_FALSE); - NSRepository::RegisterFactory(kCImageIID, "raptorgfxwin.dll", PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCRenderingContextIID, RAPTORGFX_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCDeviceContextIID, RAPTORGFX_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCFontMetricsIID, RAPTORGFX_LIB, PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCImageIID, RAPTORGFX_LIB, PR_FALSE, PR_FALSE); + + nsresult res; // Create a application shell nsIAppShell *appShell; - NSRepository::CreateInstance(kCAppShellCID, nsnull, kIAppShellIID, (void**)&appShell); - appShell->Create(); + res = NSRepository::CreateInstance(kCAppShellCID, nsnull, kIAppShellIID, (void**)&appShell); + if (NS_OK == res) + { + appShell->Create(argc, argv); + } else { + fprintf(stderr, "Couldn't Create and Instance of AppShell!\n"); + return res; + } +fprintf(stderr, "Before device context stuff\n"); nsIDeviceContext* deviceContext = 0; // Create a device context for the widgets - nsresult res; static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); @@ -1084,11 +1104,11 @@ nsresult WidgetTest() // NSRepository::CreateInstance(kCWindowCID, nsnull, kIWidgetIID, (void**)&window); nsRect rect(100, 100, 600, 700); - - window->Create((nsIWidget*)NULL, rect, HandleEvent, NULL); + window->Create((nsIWidget*)NULL, rect, HandleEvent, NULL, NULL, + (nsWidgetInitData *)appShell->GetNativeData(NS_NATIVE_SHELL)); window->SetTitle("TOP-LEVEL window"); - tooltipWindow = createTooltipWindow(window, "INSERT here", 0, 0, 150, 0); + /*tooltipWindow = createTooltipWindow(window, "INSERT here", 0, 0, 150, 0); tooltipWindow->Show(PR_FALSE); toolTipButton1 = createSimpleButton(window, "Tooltip \\/\\/",400, 100, 100, 0); toolTipButton2 = createSimpleButton(window, "Tooltip /\\/\\",500, 200, 100, 0); @@ -1119,7 +1139,9 @@ nsresult WidgetTest() NS_RELEASE(child); // the parent keeps a reference on this child y += rect.height + 5; - +*/ + int x = 10; + int y = 10; // // create a button @@ -1146,7 +1168,7 @@ nsresult WidgetTest() x = createTestButton(window, kBrowseBtn, x, y, 75, HandleFileButtonEvent); x = 10; y += rect.height + 5; - +/* // // create a check button // @@ -1200,7 +1222,7 @@ nsresult WidgetTest() passwordText = ptextWidget; textShelfTest(gFD, "Password Text", passwordText); - +*/ x = createTestButton(window, kSetCaret, x+180, y, 75, PasswordTextTestHandleEvent); x = createTestButton(window, kGetCaret, x+5, y, 75, PasswordTextTestHandleEvent); x = createTestButton(window, kSetText, x+5, y, 75, PasswordTextTestHandleEvent); @@ -1212,7 +1234,7 @@ nsresult WidgetTest() // // create a readonly text widget // - +/* nsITextWidget * rtextWidget; rect.SetRect(x, y, 100, 25); NSRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void**)&rtextWidget); @@ -1256,7 +1278,7 @@ nsresult WidgetTest() rect.SetRect(x+25, 10, 350, 25); NSRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void**)&statusText); statusText->Create(window, rect, HandleEvent, deviceContext); - +*/ // // create a Failed Button // @@ -1287,7 +1309,7 @@ nsresult WidgetTest() // // create a listbox widget // - +/* rect.SetRect(x, y, 150, 100); NSRepository::CreateInstance(kCListBoxCID, nsnull, kIListBoxIID, (void**)&listBox); listBox->Create(window, rect, HandleEvent, NULL); @@ -1298,7 +1320,7 @@ nsresult WidgetTest() listBox->AddItemAt(listStr1, i); } listSelfTest(gFD, "ListBox", listBox); - +*/ x = createTestButton(window, kSetSelection, x+150, y, 125, ListBoxTestHandleEvent); x = createTestButton(window, kRemoveSelection, x+5, y, 125, ListBoxTestHandleEvent); x = 10; @@ -1308,7 +1330,7 @@ nsresult WidgetTest() // // create a multi-selection listbox widget // - +/* rect.SetRect(x, y, 150, 100); NSRepository::CreateInstance(kCListBoxCID, nsnull, kIListBoxIID, (void**)&gMultiListBox); // Notice the extra agrument PR_TRUE below which indicates that @@ -1397,7 +1419,7 @@ nsresult WidgetTest() } listSelfTest(gFD, "ComboBox", comboBox); NS_RELEASE(comboBox); - +*/ x = createTestButton(window, kSetSelection, x+125, y, 125, ComboTestHandleEvent); x = createTestButton(window, kRemoveSelection, x+5, y, 125, ComboTestHandleEvent); @@ -1409,7 +1431,7 @@ nsresult WidgetTest() status.Append(eval(gOverallStatus)); gNonVisualStatus = gOverallStatus; - statusText->SetText(status); + //statusText->SetText(status); // show window->Show(PR_TRUE); @@ -1419,3 +1441,21 @@ nsresult WidgetTest() } + +#ifdef XP_PC +#include +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, + int nCmdShow) +{ + return(WidgetTest(0, NULL)); +} +#else +void main(int argc, char **argv) +{ + int argC = argc; + //NS_WARNING("Need to force the Shared Library to load!"); + WidgetTest(&argC, argv); +} + +#endif +