diff --git a/webshell/tests/viewer/nsSetupRegistry.cpp b/webshell/tests/viewer/nsSetupRegistry.cpp index 92539bf616a..b8260810a7f 100644 --- a/webshell/tests/viewer/nsSetupRegistry.cpp +++ b/webshell/tests/viewer/nsSetupRegistry.cpp @@ -76,7 +76,7 @@ // Class ID's // WIDGET -#ifndef XP_UNIX +#if !defined(XP_UNIX) && !defined(XP_OS2) static NS_DEFINE_IID(kCLookAndFeelCID, NS_LOOKANDFEEL_CID); static NS_DEFINE_IID(kCWindowCID, NS_WINDOW_CID); static NS_DEFINE_IID(kCVScrollbarCID, NS_VERTSCROLLBAR_CID); @@ -155,7 +155,7 @@ NS_SetupRegistry() #endif /* defined(XP_UNIX) */ // WIDGET -#ifndef XP_UNIX +#if !defined(XP_UNIX) && !defined(XP_OS2) nsComponentManager::RegisterComponentLib(kCLookAndFeelCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCWindowCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCVScrollbarCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); diff --git a/widget/src/os2/Makefile.in b/widget/src/os2/Makefile.in index 43a78db812e..e625e36db7e 100644 --- a/widget/src/os2/Makefile.in +++ b/widget/src/os2/Makefile.in @@ -24,6 +24,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk LIBRARY_NAME = wdgtos2 +IS_COMPONENT = 1 EXTRA_DSO_LIBS = gkgfx @@ -32,7 +33,7 @@ REQUIRES = util img xpcom raptor netlib DIRS = res ifdef ENABLE_TESTS -DIRS += tests +#DIRS += tests endif CPPSRCS = \ diff --git a/widget/src/os2/nsWidgetFactory.cpp b/widget/src/os2/nsWidgetFactory.cpp index 14e31cab021..fd9a3295464 100644 --- a/widget/src/os2/nsWidgetFactory.cpp +++ b/widget/src/os2/nsWidgetFactory.cpp @@ -26,31 +26,34 @@ * Modifications to Mozilla code or documentation * identified per MPL Section 3.3 * - * Date Modified by Description of modification - * 03/23/2000 IBM Corp. Added support for directory picker dialog. - * 03/24/2000 IBM Corp. Updated based on nsWinWidgetFactory.cpp. - * 05/31/2000 IBM Corp. Enabled timer stuff + * Date Modified by Description of modification + * 03/23/2000 IBM Corp. Added support for directory picker dialog. + * 03/24/2000 IBM Corp. Updated based on nsWinWidgetFactory.cpp. + * 05/31/2000 IBM Corp. Enabled timer stuff * 06/30/2000 sobotka@axess.com Added nsFilePicker + * 03/11/2001 achimha@innotek.de converted to XPCOM module */ -#include "nsIFactory.h" -#include "nsISupports.h" -// OS2TODO #include "nsdefs.h" +#include "nsIGenericFactory.h" +#include "nsIModule.h" +#include "nsCOMPtr.h" #include "nsWidgetsCID.h" -#include "nsWidgetDefs.h" // OS/2 only +//#include "nsWidgetDefs.h" +// class definition headers +#include "nsAppShell.h" +#include "nsBidiKeyboard.h" +#include "nsCanvas.h" +#include "nsDragService.h" #include "nsFilePicker.h" #include "nsFileWidget.h" -#include "nsFileSpecWithUIImpl.h" +#include "nsFontRetrieverService.h" +#include "nsFontSizeIterator.h" #include "nsLookAndFeel.h" #include "nsScrollbar.h" -#include "nsToolkit.h" -#include "nsWindow.h" -#include "nsAppShell.h" -#include "nsIServiceManager.h" -#include "nsFontRetrieverService.h" #include "nsSound.h" +#include "nsToolkit.h" #include "nsWindowsTimer.h" #include "nsTimerManager.h" @@ -61,240 +64,209 @@ #include "nsHTMLFormatConverter.h" // OS2TODO #include "nsDragService.h" -#include "nsFrameWindow.h" // OS/2 only +#include "nsFrameWindow.h" // OS/2 only -#ifdef IBMBIDI -#include "nsBidiKeyboard.h" -#endif - -static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID); -static NS_DEFINE_IID(kCChild, NS_CHILD_CID); -static NS_DEFINE_IID(kCFileOpen, NS_FILEWIDGET_CID); -static NS_DEFINE_IID(kCFilePicker, NS_FILEPICKER_CID); -static NS_DEFINE_IID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID); -static NS_DEFINE_IID(kCVertScrollbar, NS_VERTSCROLLBAR_CID); -static NS_DEFINE_IID(kCAppShell, NS_APPSHELL_CID); -static NS_DEFINE_IID(kCToolkit, NS_TOOLKIT_CID); -static NS_DEFINE_IID(kCLookAndFeel, NS_LOOKANDFEEL_CID); -static NS_DEFINE_IID(kCFontRetrieverService, NS_FONTRETRIEVERSERVICE_CID); - -static NS_DEFINE_IID(kCTimer, NS_TIMER_CID); -static NS_DEFINE_IID(kCTimerManager, NS_TIMERMANAGER_CID); - -// Drag & Drop, Clipboard -static NS_DEFINE_IID(kCDataObj, NS_DATAOBJ_CID); -static NS_DEFINE_IID(kCClipboard, NS_CLIPBOARD_CID); -static NS_DEFINE_IID(kCTransferable, NS_TRANSFERABLE_CID); -static NS_DEFINE_IID(kCHTMLFormatConverter, NS_HTMLFORMATCONVERTER_CID); -static NS_DEFINE_IID(kCDragService, NS_DRAGSERVICE_CID); - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +// objects that just require generic constructors +NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCanvas) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsFileWidget) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontRetrieverService) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsFrameWindow) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimer) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerManager) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) +// OS2TODO NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) -// Sound services (just Beep for now) -static NS_DEFINE_CID(kCSound, NS_SOUND_CID); -static NS_DEFINE_CID(kCFileSpecWithUI, NS_FILESPECWITHUI_CID); +// custom "contructor" methods -#ifdef IBMBIDI -static NS_DEFINE_IID(kCBidiKeyboard, NS_BIDIKEYBOARD_CID); -#endif - -class nsWidgetFactory : public nsIFactory -{ -public: - // nsISupports methods - NS_DECL_ISUPPORTS - - // nsIFactory methods - NS_IMETHOD CreateInstance(nsISupports *aOuter, - const nsIID &aIID, - void **aResult); - - - NS_IMETHOD LockFactory(PRBool aLock); - - nsWidgetFactory(const nsCID &aClass); - ~nsWidgetFactory(); - -private: - nsCID mClassID; -}; - -NS_IMPL_ADDREF(nsWidgetFactory) -NS_IMPL_RELEASE(nsWidgetFactory) - -nsWidgetFactory::nsWidgetFactory(const nsCID &aClass) -{ - NS_INIT_REFCNT(); - mClassID = aClass; -} - - -nsWidgetFactory::~nsWidgetFactory() -{ -} - -nsresult nsWidgetFactory::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; -} - - - - - -nsresult nsWidgetFactory::CreateInstance( nsISupports* aOuter, - const nsIID &aIID, - void **aResult) -{ - if (aResult == NULL) { - return NS_ERROR_NULL_POINTER; - } - - *aResult = NULL; - if (nsnull != aOuter) { - return NS_ERROR_NO_AGGREGATION; - } - - nsISupports *inst = nsnull; - if (mClassID.Equals(kCWindow)) { -#ifdef XP_OS2 - inst = (nsISupports*)(nsBaseWidget*) new nsFrameWindow; -#else - inst = (nsISupports*)(nsBaseWidget*)new nsWindow(); -#endif - } - else if (mClassID.Equals(kCChild)) { -#ifdef XP_OS2 - inst = (nsISupports*)(nsBaseWidget*)new nsCanvas(); -#else - inst = (nsISupports*)(nsBaseWidget*)new ChildWindow(); -#endif - } - else if (mClassID.Equals(kCFileOpen)) { - inst = (nsISupports*)new nsFileWidget(); - } - else if (mClassID.Equals(kCFilePicker)) { - inst = (nsISupports*)(nsBaseFilePicker*)new nsFilePicker(); - } - else if (mClassID.Equals(kCHorzScrollbar)) { - inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsScrollbar(PR_FALSE); - } - else if (mClassID.Equals(kCVertScrollbar)) { - inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsScrollbar(PR_TRUE); - } - else if (mClassID.Equals(kCAppShell)) { -#ifdef XP_OS2 // need to do it this was to keep initial window on the screen & be able to close browser - nsIAppShell *pShell = nsnull; - NS_CreateAppshell( &pShell); - inst = (nsISupports*)pShell; - // inst = new nsAppShell -#else - inst = (nsISupports*)new nsAppShell(); -#endif - } - else if (mClassID.Equals(kCToolkit)) { - inst = (nsISupports*)new nsToolkit(); - } - else if (mClassID.Equals(kCLookAndFeel)) { - inst = (nsISupports*)new nsLookAndFeel(); - } - else if (mClassID.Equals(kCSound)) { - inst = (nsISupports*)(nsISound*)new nsSound(); - } - else if (mClassID.Equals(kCFileSpecWithUI)) { - inst = (nsISupports*) (nsIFileSpecWithUI *) new nsFileSpecWithUIImpl; - } - else if (mClassID.Equals(kCTransferable)) { - inst = (nsISupports*)new nsTransferable(); - } - else if (mClassID.Equals(kCHTMLFormatConverter)) { - inst = (nsISupports*)new nsHTMLFormatConverter(); - } - else if (mClassID.Equals(kCTimer)) { - inst = (nsISupports*)(nsITimer*) new nsTimer(); - } - else if (mClassID.Equals(kCTimerManager)) { - inst = (nsISupports*)(nsITimerQueue*) new nsTimerManager(); - } - else if (mClassID.Equals(kCFontRetrieverService)) { - inst = (nsISupports*)(nsIFontRetrieverService *)new nsFontRetrieverService(); - } -#ifdef IBMBIDI - else if (mClassID.Equals(kCBidiKeyboard)) { - inst = (nsISupports*)(nsIBidiKeyboard*) new nsBidiKeyboard(); - } -#endif // IBMBIDI - - else if (mClassID.Equals(kCClipboard)) { - inst = (nsISupports*)(nsBaseClipboard *)new nsClipboard(); - } -#if 0 // OS2TODO - else if (mClassID.Equals(kCDragService)) { - inst = (nsISupports*)(nsIDragService *)new nsDragService(); - } -#endif - if (inst == NULL) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(inst); // Stabilize - nsresult res = inst->QueryInterface(aIID, aResult); - NS_RELEASE(inst); // Destabilize and avoid leaks. Avoid calling delete - - return res; -} - -nsresult nsWidgetFactory::LockFactory(PRBool aLock) - -{ - // Not implemented in simplest case. - return NS_OK; - -} - - - -// return the proper factory to the caller -extern "C" NS_WIDGET nsresult -NSGetFactory(nsISupports* serviceMgr, - const nsCID &aClass, - const char *aClassName, - const char *aContractID, - nsIFactory **aFactory) +static nsresult nsAppShellConstructor (nsISupports *aOuter, REFNSIID aIID, void **aResult) { - if (nsnull == aFactory) { - return NS_ERROR_NULL_POINTER; + nsresult rv; + nsISupports *inst = nsnull; + + if ( NULL == aResult ) + { + rv = NS_ERROR_NULL_POINTER; + return rv; + } + *aResult = NULL; + if (NULL != aOuter) + { + rv = NS_ERROR_NO_AGGREGATION; + return rv; } - *aFactory = new nsWidgetFactory(aClass); - if (nsnull == aFactory) { + // need to do this in order to keep initial window on the screen + // and be able to close browser + nsIAppShell *pShell = nsnull; + NS_CreateAppshell(&pShell); + inst = (nsISupports*)pShell; + + if (inst == NULL) + { return NS_ERROR_OUT_OF_MEMORY; } + NS_ADDREF(inst); + rv = inst->QueryInterface(aIID, aResult); + NS_RELEASE(inst); - return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory); + return rv; +} +static nsresult nsHorizScrollbarConstructor (nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + nsresult rv; + nsISupports *inst = nsnull; + + if ( NULL == aResult ) + { + rv = NS_ERROR_NULL_POINTER; + return rv; + } + *aResult = NULL; + if (NULL != aOuter) + { + rv = NS_ERROR_NO_AGGREGATION; + return rv; + } + + inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsScrollbar(PR_FALSE); + if (inst == NULL) + { + return NS_ERROR_OUT_OF_MEMORY; + } + NS_ADDREF(inst); + rv = inst->QueryInterface(aIID, aResult); + NS_RELEASE(inst); + + return rv; +} + +static nsresult nsVertScrollbarConstructor (nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + nsresult rv; + nsISupports *inst = nsnull; + + if ( NULL == aResult ) + { + rv = NS_ERROR_NULL_POINTER; + return rv; + } + *aResult = NULL; + if (NULL != aOuter) + { + rv = NS_ERROR_NO_AGGREGATION; + return rv; + } + + inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsScrollbar(PR_TRUE); + if (inst == NULL) + { + return NS_ERROR_OUT_OF_MEMORY; + } + NS_ADDREF(inst); + rv = inst->QueryInterface(aIID, aResult); + NS_RELEASE(inst); + + return rv; } +// component definition, will be exported using XPCOM +static nsModuleComponentInfo components[] = +{ + { "OS/2 AppShell", + NS_APPSHELL_CID, + "@mozilla.org/widget/appshell/os2;1", + nsAppShellConstructor }, + { "OS/2 Bidi Keyboard", + NS_BIDIKEYBOARD_CID, + "@mozilla.org/widget/bidikeyboard;1", + nsBidiKeyboardConstructor }, + { "OS/2 Canvas", + NS_CHILD_CID, + "@mozilla.org/widget/child_window/os2;1", + nsCanvasConstructor }, + { "OS/2 Clipboard", + NS_CLIPBOARD_CID, + "@mozilla.org/widget/clipboard;1", + nsClipboardConstructor }, +// OS2TODO +#if 0 + { "OS/2 Drag Service", + NS_DRAGSERVICE_CID, + "@mozilla.org/widget/dragservice;1", + nsDragServiceConstructor }, +#endif + + { "OS/2 File Picker", + NS_FILEPICKER_CID, + "@mozilla.org/widget/filepicker/os2;1", + nsFilePickerConstructor }, + { "OS/2 File Widget", + NS_FILEWIDGET_CID, + "@mozilla.org/widget/filewidget/os2;1", + nsFileWidgetConstructor }, + { "OS/2 Font Retriever Service", + NS_FONTRETRIEVERSERVICE_CID, + "@mozilla.org/widget/fontretrieverservice/os2;1", + nsFontRetrieverServiceConstructor }, + { "OS/2 Look And Feel", + NS_LOOKANDFEEL_CID, + "@mozilla.org/widget/lookandfeel/os2;1", + nsLookAndFeelConstructor }, + { "OS/2 Horiz Scrollbar", + NS_HORZSCROLLBAR_CID, + "@mozilla.org/widget/horizscroll/os2;1", + nsHorizScrollbarConstructor }, + { "OS/2 Vert Scrollbar", + NS_VERTSCROLLBAR_CID, + "@mozilla.org/widget/vertscroll/os2;1", + nsHorizScrollbarConstructor }, + { "OS/2 Sound", + NS_SOUND_CID, + "@mozilla.org/widget/sound;1", + nsSoundConstructor }, + { "OS/2 Toolkit", + NS_TOOLKIT_CID, + "@mozilla.org/widget/toolkit/os2;1", + nsToolkitConstructor }, + { "OS/2 Frame Window", + NS_WINDOW_CID, + "@mozilla.org/widget/window/os2;1", + nsFrameWindowConstructor }, + { "OS/2 Timer", + NS_TIMER_CID, + "@mozilla.org/timer;1", + nsTimerConstructor }, + { "OS/2 Timer Manager", + NS_TIMERMANAGER_CID, + "@mozilla.org/widget/timermanager/os2;1", + nsTimerManagerConstructor }, + { "OS/2 Transferable", + NS_TRANSFERABLE_CID, + "@mozilla.org/widget/transferable;1", + nsTransferableConstructor }, + { "OS/2 HTML Format Converter", + NS_HTMLFORMATCONVERTER_CID, + "@mozilla.org/widget/htmlformatconverter/os2;1", + nsHTMLFormatConverterConstructor } +}; + +PR_STATIC_CALLBACK(void) +nsWidgetOS2ModuleDtor(nsIModule *self) +{ + // what shall we do here? +} + +NS_IMPL_NSGETMODULE_WITH_DTOR("nsWidgetOS2Module", + components, + nsWidgetOS2ModuleDtor)