diff --git a/mozilla/gfx/src/Makefile.in b/mozilla/gfx/src/Makefile.in index 56c236121af..9886f360b94 100644 --- a/mozilla/gfx/src/Makefile.in +++ b/mozilla/gfx/src/Makefile.in @@ -26,10 +26,22 @@ include $(topsrcdir)/config/config.mk ifneq (,$(filter gtk xlib motif,$(MOZ_WIDGET_TOOLKIT))) XLIB_RGB_DIRS = xlibrgb +else + +ifdef TOOLKIT_EXORCISM +XLIB_RGB_DIRS = xlibrgb +endif + endif DIRS = ps $(XLIB_RGB_DIRS) $(MOZ_GFX_TOOLKIT) +ifdef TOOLKIT_EXORCISM +DIRS = ps $(XLIB_RGB_DIRS) xlib gtk motif +else +DIRS = ps $(XLIB_RGB_DIRS) $(MOZ_GFX_TOOLKIT) +endif + LIBRARY_NAME = raptorgfx MODULE=raptor diff --git a/mozilla/gfx/src/gtk/Makefile.in b/mozilla/gfx/src/gtk/Makefile.in index 29e5b8bc555..065d525315d 100644 --- a/mozilla/gfx/src/gtk/Makefile.in +++ b/mozilla/gfx/src/gtk/Makefile.in @@ -50,6 +50,10 @@ CPPSRCS = \ CSRCS = \ nsPrintdGTK.c +ifdef TOOLKIT_EXORCISM +EXTRA_DSO_LDOPTS += $(TK_LIBS) +endif + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/gfx/src/motif/Makefile.in b/mozilla/gfx/src/motif/Makefile.in index db455a2a762..a82f08d49d7 100644 --- a/mozilla/gfx/src/motif/Makefile.in +++ b/mozilla/gfx/src/motif/Makefile.in @@ -36,6 +36,8 @@ CPPSRCS = \ nsImageMotif.cpp \ $(NULL) +EXTRA_DSO_LDOPTS += -L$(DIST)/bin -lxlibrgb -L/usr/X11R6/lib -lXm -lXt -lXext -lX11 + include $(topsrcdir)/config/rules.mk LIBS += \ diff --git a/mozilla/gfx/src/xlib/Makefile.in b/mozilla/gfx/src/xlib/Makefile.in index e40d79f2718..16ea5227c8f 100644 --- a/mozilla/gfx/src/xlib/Makefile.in +++ b/mozilla/gfx/src/xlib/Makefile.in @@ -33,7 +33,8 @@ REQUIRES=util img xpcom raptor netlib ps DEFINES += -D_IMPL_NS_GFXONXP -DUSE_MOZILLA_TYPES CXXFLAGS += $(TK_CFLAGS) INCLUDES += $(TK_CFLAGS) -EXTRA_DSO_LDOPTS += $(TOOLKIT_LIBS) $(XLDFLAGS) $(XLIBS) + +EXTRA_DSO_LDOPTS += -L$(DIST)/bin -lxlibrgb -L/usr/X11R6/lib -lXext -lX11 CPPSRCS =\ nsDeviceContextSpecFactoryX.cpp \ diff --git a/mozilla/webshell/tests/viewer/nsSetupRegistry.cpp b/mozilla/webshell/tests/viewer/nsSetupRegistry.cpp index 0689c73eafc..8e7f1e0d400 100644 --- a/mozilla/webshell/tests/viewer/nsSetupRegistry.cpp +++ b/mozilla/webshell/tests/viewer/nsSetupRegistry.cpp @@ -56,6 +56,10 @@ #include "nsISound.h" #include "nsIFileSpecWithUI.h" +#if defined(XP_UNIX) && defined(TOOLKIT_EXORCISM) +#include "nsIUnixToolkitService.h" +#endif + #include "prprf.h" #include "prmem.h" #include "prlog.h" // PR_ASSERT @@ -208,6 +212,123 @@ static NS_DEFINE_CID(kCJVMManagerCID, NS_JVMMANAGER_CID); extern "C" void NS_SetupRegistry() { +#if defined(XP_UNIX) && defined(TOOLKIT_EXORCISM) + // On unix, the widget and gfx toolkit are not linked into the app. + // + // Instead, they are loaded at runtime courtesy of xpcom. + // + // Loading the toolkit specific dlls at runtime has many benefits: + // + // o Simplifies linking of the "app" since it no longer needs to + // pull in the toolkit world. + // + // o Makes it possible to embed the xlib gfx/widget backends into + // other high level x toolkit such as motif and gtk. This is + // highly desirable in the long run as a means to increase code + // reuse and eyeball focus. + // + // o Makes it possible to run X Mozilla using different toolkits + // without having to hack the application bits. This in turn + // simplifies everyone's life, since only one binary is needed. + // The only platform specific bits are: + // + // mozilla/gfx/src + // mozilla/widget/src/ + // mozilla/widget/timer/ + // + // o It bypasses (yeah right) the toolkit inquisitions and crusades. + // + // o It makes you breakfast, lunch and dinner. + // + + + // + // Note1: + // + // The following code assumes that: + // + // + Some kind of auto registration has occurred for components. + // For example, NS_AutoRegister() or nsComponentManager::AutoRegister(). + // + // -or- + // + // + The "app" was installed and a registry with information on the + // toolkit_service component has been populated. The master plan + // is that this occurs at install time. Otherwise bad things will + // happen. + // + // During the development of mozilla, this usually occurs in the + // main() of the "app" (viewer/apprunner). It is always the first + // thing that happens on the NS_SetupRegistry() function. + // + // If for some reason that changes in the future, the following code + // might have to be moved. + // + // Note2: + // + // The WIDGET_DLL and GFX_DLL macros will be redefined from the + // hard coded values set in this file above. They will point + // to strings valid only in the scope of this function. + // + // If for some reason, the nsComponentManager::RegisterComponentLib() + // calls below are moved to a different scope, this unix specific code + // will have to deal. + + static NS_DEFINE_CID(kCUnixToolkitServiceCID, NS_UNIX_TOOLKIT_SERVICE_CID); + + nsresult rv; + + nsIUnixToolkitService * unixToolkitService = nsnull; + + rv = nsComponentManager::CreateInstance(kCUnixToolkitServiceCID, + nsnull, + nsIUnixToolkitService::GetIID(), + (void **) &unixToolkitService); + + NS_ASSERTION(rv == NS_OK,"Cannot obtain unix toolkit service."); + + nsString unixToolkitName = "error"; + nsString unixWidgetDllName = "error"; + nsString unixGfxDllName = "error"; + + if (NS_OK == rv && nsnull != unixToolkitService) + { + nsresult rv2; + + rv2 = unixToolkitService->GetToolkitName(unixToolkitName); + + NS_ASSERTION(rv2 == NS_OK,"Cannot get unix toolkit name context."); + + rv2 = unixToolkitService->GetWidgetDllName(unixWidgetDllName); + + NS_ASSERTION(rv2 == NS_OK,"Cannot get unix toolkit widget dll name."); + + rv2 = unixToolkitService->GetGfxDllName(unixGfxDllName); + + NS_ASSERTION(rv2 == NS_OK,"Cannot get unix toolkit gfx dll name."); + + NS_RELEASE(unixToolkitService); + } + +#ifdef NS_DEBUG + printf("NS_SetupRegistry() MOZ_TOOLKIT=%s, WIDGET_DLL=%s, GFX_DLL=%s\n", + (const char *) nsAutoCString(unixToolkitName), + (const char *) nsAutoCString(unixWidgetDllName), + (const char *) nsAutoCString(unixGfxDllName)); +#endif + +#undef WIDGET_DLL +#undef GFXWIN_DLL + +#define WIDGET_DLL (const char *) nsAutoCString(unixWidgetDllName) +#define GFXWIN_DLL (const char *) nsAutoCString(unixGfxDllName) + +#endif /* defined(XP_UNIX) && defined(TOOLKIT_EXORCISM) */ + + + + + // WIDGET nsComponentManager::RegisterComponentLib(kCLookAndFeelCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); nsComponentManager::RegisterComponentLib(kCWindowCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE); @@ -289,3 +410,4 @@ NS_SetupRegistry() nsComponentManager::RegisterComponentLib(kCJVMManagerCID, NULL, NULL, OJI_DLL, PR_FALSE, PR_FALSE); #endif } + diff --git a/mozilla/widget/public/nsIXlibWindowService.h b/mozilla/widget/public/nsIXlibWindowService.h index 2f470ecd0cd..aa1b22b0dbc 100644 --- a/mozilla/widget/public/nsIXlibWindowService.h +++ b/mozilla/widget/public/nsIXlibWindowService.h @@ -22,6 +22,8 @@ #include "nsISupports.h" +#include + // Interface id for the XlibWindow service // { bd39ccb0-3f08-11d3-b419-00805f6d4c2a } #define NS_XLIB_WINDOW_SERVICE_IID \ @@ -40,46 +42,69 @@ #define NS_XLIB_WINDOW_SERVICE_PROGID "component://netscape/widget/xlib/window_service" -/** - * This is an interface for getting access to the construction - * and destruction of native windows in xlib. - * @created 20/Jul/1999 - * @author Christopher Blizzard - */ +// /** +// * This is an interface for getting access to the construction +// * and destruction of native windows in xlib. +// * @created 20/Jul/1999 +// * @author Christopher Blizzard +// */ -class nsXlibWindowCallback { - public: - virtual void WindowCreated (PRUint32 aID) = 0; - virtual void WindowDestroyed(PRUint32 aID) = 0; -}; - +// class nsXlibWindowCallback { +// public: +// virtual void WindowCreated (PRUint32 aID) = 0; +// virtual void WindowDestroyed(PRUint32 aID) = 0; +// }; + +typedef void (*nsXlibWindowCallback)(PRUint32 aWindowID); + +typedef void * nsXlibNativeEvent; + +typedef void (*nsXlibEventDispatcher)(nsXlibNativeEvent aNativeEvent); + +typedef int (*nsXlibTimeToNextTimeoutFunc)(struct timeval *aTimer); + +typedef void (*nsXlibProcessTimeoutsProc)(void); class nsIXlibWindowService : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_XLIB_WINDOW_SERVICE_IID); - /** - * Register your function for window creation and destruction. - * This function will get called whenever a new native X window - * is created. or destroyed. - * - * @param [IN] the function that you would like to register - * @return NS_OK if ok, NS_ERROR_FAILURE if you pass in 0 - */ +// /** +// * Register your function for window creation and destruction. +// * This function will get called whenever a new native X window +// * is created. or destroyed. +// * +// * @param [IN] the function that you would like to register +// * @return NS_OK if ok, NS_ERROR_FAILURE if you pass in 0 +// */ - NS_IMETHOD SetCreateCallback(nsXlibWindowCallback *aFunc) = 0; +// NS_IMETHOD SetCreateCallback(nsXlibWindowCallback *aFunc) = 0; - /** - * This function will dispatch a native X event ( cast to a void * - * here ) to the event handler on the inside of the widget - * toolkit - * @param [IN] a pointer to an XEvent, cast to a void * - * @return NS_OK if ok, NS_ERROR_FAILURE if you pass in an - * invalid window id - */ +// /** +// * This function will dispatch a native X event ( cast to a void * +// * here ) to the event handler on the inside of the widget +// * toolkit +// * @param [IN] a pointer to an XEvent, cast to a void * +// * @return NS_OK if ok, NS_ERROR_FAILURE if you pass in an +// * invalid window id +// */ - NS_IMETHOD DispatchNativeXlibEvent(void *aNativeEvent) = 0; +// NS_IMETHOD DispatchNativeXlibEvent(void *aNativeEvent) = 0; + + NS_IMETHOD SetWindowCreateCallback(nsXlibWindowCallback aCallback) = 0; + NS_IMETHOD SetWindowDestroyCallback(nsXlibWindowCallback aCallback) = 0; + NS_IMETHOD GetWindowCreateCallback(nsXlibWindowCallback * aCallbackOut) = 0; + NS_IMETHOD GetWindowDestroyCallback(nsXlibWindowCallback * aCallbackOut) = 0; + + NS_IMETHOD SetEventDispatcher(nsXlibEventDispatcher aDispatcher) = 0; + NS_IMETHOD GetEventDispatcher(nsXlibEventDispatcher * aDispatcherOut) = 0; + + NS_IMETHOD SetTimeToNextTimeoutFunc(nsXlibTimeToNextTimeoutFunc aFunc) = 0; + NS_IMETHOD GetTimeToNextTimeoutFunc(nsXlibTimeToNextTimeoutFunc * aFuncOut) = 0; + + NS_IMETHOD SetProcessTimeoutsProc(nsXlibProcessTimeoutsProc aProc) = 0; + NS_IMETHOD GetProcessTimeoutsProc(nsXlibProcessTimeoutsProc * aProcOut) = 0; }; diff --git a/mozilla/widget/src/Makefile.in b/mozilla/widget/src/Makefile.in index 603dde94eee..4b00c3ce688 100644 --- a/mozilla/widget/src/Makefile.in +++ b/mozilla/widget/src/Makefile.in @@ -29,7 +29,11 @@ include $(DEPTH)/config/autoconf.mk ## multiple implementations of widget can be built on the same ## source tree. ## +ifdef TOOLKIT_EXORCISM +DIRS = xpwidgets gtk xlib motif unix_services +else DIRS = xpwidgets $(MOZ_WIDGET_TOOLKIT) +endif include $(topsrcdir)/config/config.mk diff --git a/mozilla/widget/src/motif/Makefile.in b/mozilla/widget/src/motif/Makefile.in index 5e6d057a216..e3f1b00e969 100644 --- a/mozilla/widget/src/motif/Makefile.in +++ b/mozilla/widget/src/motif/Makefile.in @@ -79,7 +79,9 @@ EXTRA_DSO_LDOPTS+= \ $(MKSHLIB_UNFORCE_ALL) \ $(NULL) -EXTRA_DSO_LDOPTS += -L$(DIST)/bin -lxlibrgb $(TK_LIBS) +ifdef TOOLKIT_EXORCISM +EXTRA_DSO_LDOPTS += -L$(DIST)/bin -lxlibrgb -L/usr/X11R6/lib -lXm -lXmu -lXt -lXext -lX11 +endif include $(topsrcdir)/config/rules.mk diff --git a/mozilla/widget/src/xlib/Makefile.in b/mozilla/widget/src/xlib/Makefile.in index 099aa6f8a7f..edcbadfcc20 100644 --- a/mozilla/widget/src/xlib/Makefile.in +++ b/mozilla/widget/src/xlib/Makefile.in @@ -65,6 +65,10 @@ ifdef DEBUG_ramiro DEFINES += -DXLIB_WIDGET_NOISY endif +DIRS =\ + window_service \ + $(NULL) + include $(topsrcdir)/config/config.mk CXXFLAGS += $(TK_CFLAGS) @@ -80,7 +84,11 @@ EXTRA_DSO_LDOPTS+= \ $(MKSHLIB_UNFORCE_ALL) \ $(NULL) +ifdef TOOLKIT_EXORCISM +EXTRA_DSO_LDOPTS += -L$(DIST)/bin -lxlibrgb -L/usr/X11R6/lib -lXext -lX11 +else EXTRA_DSO_LDOPTS += $(TK_LIBS) +endif include $(topsrcdir)/config/rules.mk diff --git a/mozilla/widget/src/xlib/nsAppShell.cpp b/mozilla/widget/src/xlib/nsAppShell.cpp index 48cde4f820a..4e88d31944b 100644 --- a/mozilla/widget/src/xlib/nsAppShell.cpp +++ b/mozilla/widget/src/xlib/nsAppShell.cpp @@ -29,6 +29,10 @@ #include "nsIServiceManager.h" #include "nsITimer.h" +#ifdef TOOLKIT_EXORCISM +#include "nsIXlibWindowService.h" +#endif /* TOOLKIT_EXORCISM */ + #include "xlibrgb.h" #define CHAR_BUF_SIZE 40 @@ -36,11 +40,18 @@ static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); -// this is so that we can get the timers in the base. most widget -// toolkits do this through some set of globals. not here though. we -// don't have that luxury +#ifdef TOOLKIT_EXORCISM +static NS_DEFINE_IID(kWindowServiceCID,NS_XLIB_WINDOW_SERVICE_CID); +static NS_DEFINE_IID(kWindowServiceIID,NS_XLIB_WINDOW_SERVICE_IID); +#endif /* TOOLKIT_EXORCISM */ + +#ifndef TOOLKIT_EXORCISM +// // this is so that we can get the timers in the base. most widget +// // toolkits do this through some set of globals. not here though. we +// // don't have that luxury extern "C" int NS_TimeToNextTimeout(struct timeval *); extern "C" void NS_ProcessTimeouts(void); +#endif /* TOOLKIT_EXORCISM */ PRBool nsAppShell::DieAppShellDie = PR_FALSE; @@ -83,6 +94,110 @@ static char *event_names[] = { "MappingNotify" }; +#ifdef TOOLKIT_EXORCISM +static nsXlibTimeToNextTimeoutFunc GetTimeToNextTimeoutFunc(void) +{ + static nsXlibTimeToNextTimeoutFunc sFunc = nsnull; + + if (!sFunc) + { + nsIXlibWindowService * xlibWindowService = nsnull; + + nsresult rv = nsServiceManager::GetService(kWindowServiceCID, + kWindowServiceIID, + (nsISupports **)&xlibWindowService); + + NS_ASSERTION(NS_SUCCEEDED(rv),"Couldn't obtain window service."); + + if (NS_OK == rv && nsnull != xlibWindowService) + { + xlibWindowService->GetTimeToNextTimeoutFunc(&sFunc); + + NS_ASSERTION(nsnull != sFunc,"Time to next timeout func is null."); + + static int once = 1; + + if (once && sFunc) + { + once = 0; + + printf("YES! Time to next timeout func is good.\n"); + } + + NS_RELEASE(xlibWindowService); + } + } + + return sFunc; +} + +static nsXlibProcessTimeoutsProc GetProcessTimeoutsProc(void) +{ + static nsXlibProcessTimeoutsProc sProc = nsnull; + + if (!sProc) + { + nsIXlibWindowService * xlibWindowService = nsnull; + + nsresult rv = nsServiceManager::GetService(kWindowServiceCID, + kWindowServiceIID, + (nsISupports **)&xlibWindowService); + + NS_ASSERTION(NS_SUCCEEDED(rv),"Couldn't obtain window service."); + + if (NS_OK == rv && nsnull != xlibWindowService) + { + xlibWindowService->GetProcessTimeoutsProc(&sProc); + + NS_ASSERTION(nsnull != sProc,"process timeout proc is null."); + + static int once = 1; + + if (once && sProc) + { + once = 0; + + printf("YES! Process timeout proc is good.\n"); + } + + NS_RELEASE(xlibWindowService); + } + } + + return sProc; +} +#endif + +static int CallTimeToNextTimeoutFunc(struct timeval * aTimeval) +{ +#ifndef TOOLKIT_EXORCISM + return NS_TimeToNextTimeout(aTimeval); +#else + nsXlibTimeToNextTimeoutFunc func = GetTimeToNextTimeoutFunc(); + + if (func) + { + return (*func)(aTimeval); + } + + return 0; +#endif /* TOOLKIT_EXORCISM */ +} + +static void CallProcessTimeoutsProc(void) +{ +#ifndef TOOLKIT_EXORCISM + NS_ProcessTimeouts(); +#else + nsXlibProcessTimeoutsProc proc = GetProcessTimeoutsProc(); + + if (proc) + { + (*proc)(); + } +#endif /* TOOLKIT_EXORCISM */ +} + #define ALL_EVENTS ( KeyPressMask | KeyReleaseMask | ButtonPressMask | \ ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | \ PointerMotionMask | PointerMotionHintMask | Button1MotionMask | \ @@ -208,7 +323,8 @@ nsresult nsAppShell::Run() // add the queue and the xlib connection to the select set FD_SET(queue_fd, &select_set); FD_SET(xlib_fd, &select_set); - if (NS_TimeToNextTimeout(&cur_time) == 0) { + + if (CallTimeToNextTimeoutFunc(&cur_time) == 0) { cur_time_ptr = NULL; } else { @@ -246,7 +362,7 @@ nsresult nsAppShell::Run() } if (please_run_timer_queue) { //printf("Running timer queue...\n"); - NS_ProcessTimeouts(); + CallProcessTimeoutsProc(); } // make sure that any pending X requests are flushed. XFlush(mDisplay); diff --git a/mozilla/widget/src/xlib/nsWidget.cpp b/mozilla/widget/src/xlib/nsWidget.cpp index f12e08497b6..6c517a48b04 100644 --- a/mozilla/widget/src/xlib/nsWidget.cpp +++ b/mozilla/widget/src/xlib/nsWidget.cpp @@ -16,10 +16,14 @@ * Reserved. */ -#include -#include "nsIXlibWindowService.h" - #include "nsWidget.h" + +#include "nsIServiceManager.h" + +#include "nsAppShell.h" + +#include + #include "nsIEventListener.h" #include "nsIMenuListener.h" #include "nsIMouseListener.h" @@ -31,7 +35,7 @@ PRLogModuleInfo *XlibWidgetsLM = PR_NewLogModule("XlibWidgets"); PRLogModuleInfo *XlibScrollingLM = PR_NewLogModule("XlibScrolling"); // set up our static members here. -nsHashtable *nsWidget::window_list = nsnull; +nsHashtable *nsWidget::gsWindowList = nsnull; // this is a class for generating keys for // the list of windows managed by mozilla. @@ -39,7 +43,11 @@ nsHashtable *nsWidget::window_list = nsnull; // this is possibly the class impl that will be // called whenever a new window is created/destroyed -nsXlibWindowCallback *nsWidget::mWindowCallback = nsnull; +//nsXlibWindowCallback *nsWidget::mWindowCallback = nsnull; + +/* static */ nsXlibWindowCallback nsWidget::gsWindowCreateCallback = nsnull; +/* static */ nsXlibWindowCallback nsWidget::gsWindowDestroyCallback = nsnull; +/* static */ nsXlibEventDispatcher nsWidget::gsEventDispatcher = nsnull; // this is for implemention the WM_PROTOCOL code PRBool nsWidget::WMProtocolsInitialized = PR_FALSE; @@ -140,6 +148,9 @@ NS_IMETHODIMP nsWidget::Create(nsNativeWidget aParent, aParent)); } +static NS_DEFINE_IID(kWindowServiceCID,NS_XLIB_WINDOW_SERVICE_CID); +static NS_DEFINE_IID(kWindowServiceIID,NS_XLIB_WINDOW_SERVICE_IID); + nsresult nsWidget::StandardWidgetCreate(nsIWidget *aParent, const nsRect &aRect, @@ -174,6 +185,31 @@ nsWidget::StandardWidgetCreate(nsIWidget *aParent, } // set the bounds mBounds = aRect; + + +#ifdef TOOLKIT_EXORCISM + nsIXlibWindowService * xlibWindowService = nsnull; + + nsresult rv = nsServiceManager::GetService(kWindowServiceCID, + kWindowServiceIID, + (nsISupports **)&xlibWindowService); + + NS_ASSERTION(NS_SUCCEEDED(rv),"Couldn't obtain window service."); + + if (NS_OK == rv && nsnull != xlibWindowService) + { + xlibWindowService->GetWindowCreateCallback(&gsWindowCreateCallback); + xlibWindowService->GetWindowDestroyCallback(&gsWindowDestroyCallback); + +// NS_ASSERTION(nsnull != gsWindowCreateCallback,"Window create callback is null."); +// NS_ASSERTION(nsnull != gsWindowDestroyCallback,"Window destroy callback is null."); + + xlibWindowService->SetEventDispatcher((nsXlibEventDispatcher) nsAppShell::DispatchXEvent); + + NS_RELEASE(xlibWindowService); + } +#endif /* TOOLKIT_EXORCISM */ + // call the native create function CreateNative(parent, mBounds); // set up our wm hints if it's appropriate @@ -647,11 +683,11 @@ void nsWidget::CreateNativeWindow(Window aParent, nsRect aRect, nsWidget * nsWidget::GetWidgetForWindow(Window aWindow) { - if (window_list == nsnull) { + if (gsWindowList == nsnull) { return nsnull; } nsWindowKey *window_key = new nsWindowKey(aWindow); - nsWidget *retval = (nsWidget *)window_list->Get(window_key); + nsWidget *retval = (nsWidget *)gsWindowList->Get(window_key); delete window_key; return retval; } @@ -660,18 +696,21 @@ void nsWidget::AddWindowCallback(Window aWindow, nsWidget *aWidget) { // make sure that the list has been initialized - if (window_list == nsnull) { - window_list = new nsHashtable(); + if (gsWindowList == nsnull) { + gsWindowList = new nsHashtable(); } nsWindowKey *window_key = new nsWindowKey(aWindow); - window_list->Put(window_key, aWidget); + gsWindowList->Put(window_key, aWidget); // add a new ref to this widget NS_ADDREF(aWidget); + // make sure that if someone is listening that we inform // them of the new window - if (mWindowCallback) { - mWindowCallback->WindowCreated(aWindow); + if (gsWindowCreateCallback) + { + (*gsWindowCreateCallback)(aWindow); } + delete window_key; } @@ -679,12 +718,15 @@ void nsWidget::DeleteWindowCallback(Window aWindow) { nsWindowKey *window_key = new nsWindowKey(aWindow); - nsWidget *widget = (nsWidget *)window_list->Get(window_key); + nsWidget *widget = (nsWidget *)gsWindowList->Get(window_key); NS_RELEASE(widget); - window_list->Remove(window_key); - if (mWindowCallback) { - mWindowCallback->WindowDestroyed(aWindow); + gsWindowList->Remove(window_key); + + if (gsWindowDestroyCallback) + { + (*gsWindowDestroyCallback)(aWindow); } + delete window_key; } @@ -1020,33 +1062,33 @@ void nsWidget::SetMapStatus(PRBool aState) mIsMapped = aState; } -nsresult -nsWidget::SetXlibWindowCallback(nsXlibWindowCallback *aCallback) -{ - if (aCallback == nsnull) { - return NS_ERROR_FAILURE; - } - else { - mWindowCallback = aCallback; - } - return NS_OK; -} +// nsresult +// nsWidget::SetXlibWindowCallback(nsXlibWindowCallback *aCallback) +// { +// if (aCallback == nsnull) { +// return NS_ERROR_FAILURE; +// } +// else { +// mWindowCallback = aCallback; +// } +// return NS_OK; +// } -nsresult -nsWidget::XWindowCreated(Window aWindow) { - if (mWindowCallback) { - mWindowCallback->WindowCreated(aWindow); - } - return NS_OK; -} +// nsresult +// nsWidget::XWindowCreated(Window aWindow) { +// if (mWindowCallback) { +// mWindowCallback->WindowCreated(aWindow); +// } +// return NS_OK; +// } -nsresult -nsWidget::XWindowDestroyed(Window aWindow) { - if (mWindowCallback) { - mWindowCallback->WindowDestroyed(aWindow); - } - return NS_OK; -} +// nsresult +// nsWidget::XWindowDestroyed(Window aWindow) { +// if (mWindowCallback) { +// mWindowCallback->WindowDestroyed(aWindow); +// } +// return NS_OK; +// } void nsWidget::SetUpWMHints(void) { diff --git a/mozilla/widget/src/xlib/nsWidget.h b/mozilla/widget/src/xlib/nsWidget.h index a13ae64252e..b3f6c8cf98c 100644 --- a/mozilla/widget/src/xlib/nsWidget.h +++ b/mozilla/widget/src/xlib/nsWidget.h @@ -22,10 +22,12 @@ #include #include #include + #include "nsBaseWidget.h" #include "nsHashtable.h" #include "prlog.h" -#include + +#include "nsIXlibWindowService.h" #ifdef DEBUG_blizzard #define XLIB_WIDGET_NOISY @@ -118,9 +120,9 @@ public: PRBool DispatchWindowEvent(nsGUIEvent & aEvent); - static nsresult SetXlibWindowCallback(nsXlibWindowCallback *aCallback); - static nsresult XWindowCreated(Window aWindow); - static nsresult XWindowDestroyed(Window aWindow); +// static nsresult SetXlibWindowCallback(nsXlibWindowCallback *aCallback); +// static nsresult XWindowCreated(Window aWindow); +// static nsresult XWindowDestroyed(Window aWindow); // these are for the wm protocols static Atom WMDeleteWindow; @@ -148,8 +150,6 @@ protected: // these will add and delete a window static void AddWindowCallback (Window aWindow, nsWidget *aWidget); static void DeleteWindowCallback(Window aWindow); - static nsHashtable *window_list; - static nsXlibWindowCallback *mWindowCallback; // set up our wm hints void SetUpWMHints(void); @@ -185,6 +185,13 @@ protected: GC mGC; // until we get gc pooling working... nsString mName; // name of the type of widget PRBool mIsToplevel; + +private: + static nsHashtable * gsWindowList; + + static nsXlibWindowCallback gsWindowCreateCallback; + static nsXlibWindowCallback gsWindowDestroyCallback; + static nsXlibEventDispatcher gsEventDispatcher; }; extern PRLogModuleInfo *XlibWidgetsLM; diff --git a/mozilla/widget/src/xlib/window_service/nsXlibWindowService.cpp b/mozilla/widget/src/xlib/window_service/nsXlibWindowService.cpp index 763e2a6bb33..fe63394a8a6 100644 --- a/mozilla/widget/src/xlib/window_service/nsXlibWindowService.cpp +++ b/mozilla/widget/src/xlib/window_service/nsXlibWindowService.cpp @@ -18,9 +18,13 @@ */ #include "nsXlibWindowService.h" -// yes, these are from the parent directory. -#include "nsWidget.h" -#include "nsAppShell.h" + +// +// NO! This is evil. It creates a link time dependency with libwidget_xlib.so. +// +// // yes, these are from the parent directory. +// #include "nsWidget.h" +// #include "nsAppShell.h" nsXlibWindowService::nsXlibWindowService() { @@ -34,16 +38,123 @@ NS_IMPL_ADDREF(nsXlibWindowService) NS_IMPL_RELEASE(nsXlibWindowService) NS_IMPL_QUERY_INTERFACE(nsXlibWindowService, nsCOMTypeInfo::GetIID()) -NS_IMETHODIMP -nsXlibWindowService::SetCreateCallback(nsXlibWindowCallback *aFunc) -{ - nsWidget::SetXlibWindowCallback(aFunc); - return NS_OK; -} +/* static */ nsXlibWindowCallback nsXlibWindowService::gsWindowCreateCallback = nsnull; +/* static */ nsXlibWindowCallback nsXlibWindowService::gsWindowDestroyCallback = nsnull; +/* static */ nsXlibEventDispatcher nsXlibWindowService::gsEventDispatcher = nsnull; +/* static */ nsXlibTimeToNextTimeoutFunc nsXlibWindowService::gsTimeToNextTimeoutFunc = nsnull; +/* static */ nsXlibProcessTimeoutsProc nsXlibWindowService::gsProcessTimeoutsProc = nsnull; + +// NS_IMETHODIMP +// nsXlibWindowService::SetCreateCallback(nsXlibWindowCallback *aFunc) +// { +// nsWidget::SetXlibWindowCallback(aFunc); +// return NS_OK; +// } + +// NS_IMETHODIMP +// nsXlibWindowService::DispatchNativeXlibEvent(void *aNativeEvent) +// { +// nsAppShell::DispatchXEvent((XEvent *)aNativeEvent); +// return NS_OK; +// } NS_IMETHODIMP -nsXlibWindowService::DispatchNativeXlibEvent(void *aNativeEvent) +nsXlibWindowService::SetWindowCreateCallback(nsXlibWindowCallback aCallback) { - nsAppShell::DispatchXEvent((XEvent *)aNativeEvent); + NS_ASSERTION(nsnull != aCallback,"null in ptr."); + + gsWindowCreateCallback = aCallback; + return NS_OK; } +////////////////////////////////////////////////////////////////////////// +NS_IMETHODIMP +nsXlibWindowService::SetWindowDestroyCallback(nsXlibWindowCallback aCallback) +{ + NS_ASSERTION(nsnull != aCallback,"null in ptr."); + + gsWindowDestroyCallback = aCallback; + + return NS_OK; +} +////////////////////////////////////////////////////////////////////////// +NS_IMETHODIMP +nsXlibWindowService::SetEventDispatcher(nsXlibEventDispatcher aDispatcher) +{ + NS_ASSERTION(nsnull != aDispatcher,"null in ptr."); + + gsEventDispatcher = aDispatcher; + + return NS_OK; +} +////////////////////////////////////////////////////////////////////////// +NS_IMETHODIMP +nsXlibWindowService::GetWindowCreateCallback(nsXlibWindowCallback * aCallbackOut) +{ + NS_ASSERTION(nsnull != aCallbackOut,"null out ptr."); + + *aCallbackOut = gsWindowCreateCallback; + + return NS_OK; +} +////////////////////////////////////////////////////////////////////////// +NS_IMETHODIMP +nsXlibWindowService::GetWindowDestroyCallback(nsXlibWindowCallback * aCallbackOut) +{ + NS_ASSERTION(nsnull != aCallbackOut,"null out ptr."); + + *aCallbackOut = gsWindowDestroyCallback; + + return NS_OK; +} +////////////////////////////////////////////////////////////////////////// +NS_IMETHODIMP +nsXlibWindowService::GetEventDispatcher(nsXlibEventDispatcher * aDispatcherOut) +{ + NS_ASSERTION(nsnull != aDispatcherOut,"null out ptr."); + + *aDispatcherOut = gsEventDispatcher; + + return NS_OK; +} +////////////////////////////////////////////////////////////////////////// +NS_IMETHODIMP +nsXlibWindowService::SetTimeToNextTimeoutFunc(nsXlibTimeToNextTimeoutFunc aFunc) +{ + NS_ASSERTION(nsnull != aFunc,"null in ptr."); + + gsTimeToNextTimeoutFunc = aFunc; + + return NS_OK; +} +////////////////////////////////////////////////////////////////////////// +NS_IMETHODIMP +nsXlibWindowService::GetTimeToNextTimeoutFunc(nsXlibTimeToNextTimeoutFunc * aFuncOut) +{ + NS_ASSERTION(nsnull != aFuncOut,"null out ptr."); + + *aFuncOut = gsTimeToNextTimeoutFunc; + + return NS_OK; +} +////////////////////////////////////////////////////////////////////////// +NS_IMETHODIMP +nsXlibWindowService::SetProcessTimeoutsProc(nsXlibProcessTimeoutsProc aProc) +{ + NS_ASSERTION(nsnull != aProc,"null in ptr."); + + gsProcessTimeoutsProc = aProc; + + return NS_OK; +} +////////////////////////////////////////////////////////////////////////// +NS_IMETHODIMP +nsXlibWindowService::GetProcessTimeoutsProc(nsXlibProcessTimeoutsProc * aProcOut) +{ + NS_ASSERTION(nsnull != aProcOut,"null out ptr."); + + *aProcOut = gsProcessTimeoutsProc; + + return NS_OK; +} +////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/widget/src/xlib/window_service/nsXlibWindowService.h b/mozilla/widget/src/xlib/window_service/nsXlibWindowService.h index 8292b6c1936..beced22a980 100644 --- a/mozilla/widget/src/xlib/window_service/nsXlibWindowService.h +++ b/mozilla/widget/src/xlib/window_service/nsXlibWindowService.h @@ -27,6 +27,29 @@ class nsXlibWindowService : public nsIXlibWindowService NS_DECL_ISUPPORTS - NS_IMETHOD SetCreateCallback(nsXlibWindowCallback *aFunc); - NS_IMETHOD DispatchNativeXlibEvent(void *aNativeEvent); +// NS_IMETHOD SetCreateCallback(nsXlibWindowCallback *aFunc); +// NS_IMETHOD DispatchNativeXlibEvent(void *aNativeEvent); + + NS_IMETHOD SetWindowCreateCallback(nsXlibWindowCallback aCallback); + NS_IMETHOD SetWindowDestroyCallback(nsXlibWindowCallback aCallback); + NS_IMETHOD GetWindowCreateCallback(nsXlibWindowCallback * aCallbackOut); + NS_IMETHOD GetWindowDestroyCallback(nsXlibWindowCallback * aCallbackOut); + + + NS_IMETHOD SetEventDispatcher(nsXlibEventDispatcher aDispatcher); + NS_IMETHOD GetEventDispatcher(nsXlibEventDispatcher * aDispatcherOut); + + NS_IMETHOD SetTimeToNextTimeoutFunc(nsXlibTimeToNextTimeoutFunc aFunc); + NS_IMETHOD GetTimeToNextTimeoutFunc(nsXlibTimeToNextTimeoutFunc * aFuncOut); + + NS_IMETHOD SetProcessTimeoutsProc(nsXlibProcessTimeoutsProc aProc); + NS_IMETHOD GetProcessTimeoutsProc(nsXlibProcessTimeoutsProc * aProcOut); + +private: + + static nsXlibWindowCallback gsWindowCreateCallback; + static nsXlibWindowCallback gsWindowDestroyCallback; + static nsXlibEventDispatcher gsEventDispatcher; + static nsXlibTimeToNextTimeoutFunc gsTimeToNextTimeoutFunc; + static nsXlibProcessTimeoutsProc gsProcessTimeoutsProc; }; diff --git a/mozilla/widget/timer/src/unix/Makefile.in b/mozilla/widget/timer/src/unix/Makefile.in index e3596b78db0..31f4e389dfb 100644 --- a/mozilla/widget/timer/src/unix/Makefile.in +++ b/mozilla/widget/timer/src/unix/Makefile.in @@ -24,19 +24,30 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/config.mk +ifdef TOOLKIT_EXORCISM + DIRS = $(MOZ_WIDGET_TOOLKIT) -### XXX ### DIRS = gtk motif xlib -### XXX ### -### XXX ### LIBRARY_NAME = timer_s -### XXX ### -### XXX ### REQUIRES=xpcom -### XXX ### -### XXX ### CPPSRCS =\ -### XXX ### nsNewTimer.cpp \ -### XXX ### $(NULL) -### XXX ### -### XXX ### MKSHLIB = -### XXX ### override NO_SHARED_LIB=1 -### XXX ### override NO_STATIC_LIB= +DIRS = gtk motif xlib + +LIBRARY_NAME = timer_s + +REQUIRES=xpcom + +CPPSRCS =\ + nsNewTimer.cpp \ + $(NULL) + +EXPORTS =\ + nsUnixTimerCIID.h \ + $(NULL) + +MKSHLIB = +override NO_SHARED_LIB=1 +override NO_STATIC_LIB= + +else +DIRS = $(MOZ_WIDGET_TOOLKIT) + +endif # TOOLKIT_EXORCISM include $(topsrcdir)/config/rules.mk diff --git a/mozilla/widget/timer/src/unix/gtk/Makefile.in b/mozilla/widget/timer/src/unix/gtk/Makefile.in index d192b92d800..fe0396bfe9a 100644 --- a/mozilla/widget/timer/src/unix/gtk/Makefile.in +++ b/mozilla/widget/timer/src/unix/gtk/Makefile.in @@ -24,24 +24,32 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/config.mk -LIBRARY_NAME = $(TIMER_LIB_NAME) -### XXX ### IS_COMPONENT=1 +ifdef TOOLKIT_EXORCISM +LIBRARY_NAME = timer_gtk +IS_COMPONENT=1 REQUIRES=xpcom - -DEFINES += -D_IMPL_NS_TIMER CXXFLAGS += $(TK_CFLAGS) INCLUDES += $(TK_CFLAGS) -I$(srcdir)/.. CPPSRCS = \ nsTimerGtk.cpp \ -### XXX ### nsTimerGtkFactory.cpp \ + nsTimerGtkFactory.cpp \ $(NULL) -### XXX ### EXTRA_DSO_LDOPTS += $(TK_LIBS) +EXTRA_DSO_LDOPTS += $(TK_LIBS) +else + +LIBRARY_NAME = $(TIMER_LIB_NAME) +REQUIRES = xpcom +CXXFLAGS += $(TK_CFLAGS) +INCLUDES += $(TK_CFLAGS) -I$(srcdir)/.. +CPPSRCS = nsTimerGtk.cpp MKSHLIB = override NO_SHARED_LIB=1 override NO_STATIC_LIB= +endif # TOOLKIT_EXORCISM + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/widget/timer/src/unix/gtk/nsTimerGtk.cpp b/mozilla/widget/timer/src/unix/gtk/nsTimerGtk.cpp index b0deda491e2..753f0ce4b12 100644 --- a/mozilla/widget/timer/src/unix/gtk/nsTimerGtk.cpp +++ b/mozilla/widget/timer/src/unix/gtk/nsTimerGtk.cpp @@ -20,8 +20,8 @@ static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); -extern "C" int NS_TimeToNextTimeout(struct timeval *aTimer); -extern "C" void NS_ProcessTimeouts(void); +// extern "C" int NS_TimeToNextTimeout(struct timeval *aTimer); +// extern "C" void NS_ProcessTimeouts(void); extern "C" gint nsTimerExpired(gpointer aCallData); @@ -146,6 +146,7 @@ gint nsTimerExpired(gpointer aCallData) return 0; } +#ifndef TOOLKIT_EXORCISM nsresult NS_NewTimer(nsITimer** aInstancePtrResult) { NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); @@ -161,8 +162,12 @@ nsresult NS_NewTimer(nsITimer** aInstancePtrResult) return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); } -int NS_TimeToNextTimeout(struct timeval *aTimer) { +int NS_TimeToNextTimeout(struct timeval *aTimer) +{ return 0; } -void NS_ProcessTimeouts(void) { + +void NS_ProcessTimeouts(void) +{ } +#endif /* TOOLKIT_EXORCISM */ diff --git a/mozilla/widget/timer/src/unix/gtk/nsTimerGtkFactory.cpp b/mozilla/widget/timer/src/unix/gtk/nsTimerGtkFactory.cpp index 184a1f57469..2b64613f448 100644 --- a/mozilla/widget/timer/src/unix/gtk/nsTimerGtkFactory.cpp +++ b/mozilla/widget/timer/src/unix/gtk/nsTimerGtkFactory.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 2; indentT-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in @@ -19,7 +19,7 @@ #include "nsTimerGtk.h" -#include "nsTimerCIID.h" +#include "nsUnixTimerCIID.h" #include "nsIFactory.h" #include "nsIComponentManager.h" diff --git a/mozilla/widget/timer/src/unix/motif/Makefile.in b/mozilla/widget/timer/src/unix/motif/Makefile.in index 3d65da9d7a3..a22559d92d3 100644 --- a/mozilla/widget/timer/src/unix/motif/Makefile.in +++ b/mozilla/widget/timer/src/unix/motif/Makefile.in @@ -24,24 +24,33 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/config.mk -LIBRARY_NAME = $(TIMER_LIB_NAME) -### XXX ### IS_COMPONENT=1 +ifdef TOOLKIT_EXORCISM +LIBRARY_NAME = timer_motif +IS_COMPONENT=1 REQUIRES=xpcom - -DEFINES += -D_IMPL_NS_TIMER CXXFLAGS += $(TK_CFLAGS) INCLUDES += $(TK_CFLAGS) -I$(srcdir)/.. CPPSRCS = \ nsTimerMotif.cpp \ -### XXX ### nsTimerMotifFactory.cpp \ + nsTimerMotifFactory.cpp \ $(NULL) -### XXX ### EXTRA_DSO_LDOPTS += $(TK_LIBS) +#EXTRA_DSO_LDOPTS += $(TK_LIBS) +EXTRA_DSO_LDOPTS += -L/usr/X11R6/lib -lXt -lX11 +else + +LIBRARY_NAME = $(TIMER_LIB_NAME) +REQUIRES = xpcom +CXXFLAGS += $(TK_CFLAGS) +INCLUDES += $(TK_CFLAGS) -I$(srcdir)/.. +CPPSRCS = nsTimerMotif.cpp MKSHLIB = override NO_SHARED_LIB=1 override NO_STATIC_LIB= +endif # TOOLKIT_EXORCISM + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/widget/timer/src/unix/motif/nsTimerMotif.cpp b/mozilla/widget/timer/src/unix/motif/nsTimerMotif.cpp index 59e51fc6648..dbf6e6f70fc 100644 --- a/mozilla/widget/timer/src/unix/motif/nsTimerMotif.cpp +++ b/mozilla/widget/timer/src/unix/motif/nsTimerMotif.cpp @@ -75,7 +75,7 @@ nsTimerMotif::Init(nsTimerCallbackFunc aFunc, mClosure = aClosure; // mRepeat = aRepeat; - InitAppContext(); + EnsureAppContext(); mTimerId = XtAppAddTimeOut(mAppContext, aDelay, @@ -92,7 +92,7 @@ nsTimerMotif::Init(nsITimerCallback *aCallback, mCallback = aCallback; // mRepeat = aRepeat; - InitAppContext(); + EnsureAppContext(); mTimerId = XtAppAddTimeOut(mAppContext, aDelay, @@ -105,7 +105,7 @@ nsTimerMotif::Init(nsITimerCallback *aCallback, nsresult nsTimerMotif::Init(PRUint32 aDelay) { - InitAppContext(); + EnsureAppContext(); mDelay = aDelay; NS_ADDREF(this); @@ -129,7 +129,7 @@ void nsTimerExpired(XtPointer aCallData) } nsresult -nsTimerMotif::InitAppContext() +nsTimerMotif::EnsureAppContext() { static XtAppContext gsAppContext = nsnull; @@ -149,7 +149,7 @@ nsTimerMotif::InitAppContext() if (ac_service) { - printf("nsTimerMotif::InitAppContext() ac_service = %p\n",ac_service); + printf("nsTimerMotif::EnsureAppContext() ac_service = %p\n",ac_service); nsresult rv2 = ac_service->GetAppContext(&gsAppContext); @@ -159,7 +159,7 @@ nsTimerMotif::InitAppContext() NS_RELEASE(ac_service); - printf("nsTimerMotif::InitAppContext() gsAppContext = %p\n",gsAppContext); + printf("nsTimerMotif::EnsureAppContext() gsAppContext = %p\n",gsAppContext); } } @@ -168,6 +168,7 @@ nsTimerMotif::InitAppContext() return NS_OK; } +#ifndef TOOLKIT_EXORCISM nsresult NS_NewTimer(nsITimer** aInstancePtrResult) { NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); @@ -182,3 +183,4 @@ nsresult NS_NewTimer(nsITimer** aInstancePtrResult) return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); } +#endif /* TOOLKIT_EXORCISM */ diff --git a/mozilla/widget/timer/src/unix/motif/nsTimerMotif.h b/mozilla/widget/timer/src/unix/motif/nsTimerMotif.h index 630a921e884..92da9a0a37e 100644 --- a/mozilla/widget/timer/src/unix/motif/nsTimerMotif.h +++ b/mozilla/widget/timer/src/unix/motif/nsTimerMotif.h @@ -53,7 +53,7 @@ public: private: nsresult Init(PRUint32 aDelay); - nsresult InitAppContext(); + nsresult EnsureAppContext(); PRUint32 mDelay; nsTimerCallbackFunc mFunc; diff --git a/mozilla/widget/timer/src/unix/motif/nsTimerMotifFactory.cpp b/mozilla/widget/timer/src/unix/motif/nsTimerMotifFactory.cpp index 3ac8068e091..677cfa29a79 100644 --- a/mozilla/widget/timer/src/unix/motif/nsTimerMotifFactory.cpp +++ b/mozilla/widget/timer/src/unix/motif/nsTimerMotifFactory.cpp @@ -19,7 +19,7 @@ #include "nsTimerMotif.h" -#include "nsTimerCIID.h" +#include "nsUnixTimerCIID.h" #include "nsIFactory.h" #include "nsIComponentManager.h" diff --git a/mozilla/widget/timer/src/unix/nsNewTimer.cpp b/mozilla/widget/timer/src/unix/nsNewTimer.cpp index e3a6e3240f4..16092e515a2 100644 --- a/mozilla/widget/timer/src/unix/nsNewTimer.cpp +++ b/mozilla/widget/timer/src/unix/nsNewTimer.cpp @@ -18,6 +18,8 @@ #include "nsITimer.h" #include "nsUnixTimerCIID.h" #include "nsIComponentManager.h" +#include "nsIUnixToolkitService.h" + #include "nsCRT.h" #include "prenv.h" @@ -51,7 +53,7 @@ static nsresult NewTimer(const nsCID & aClass,nsITimer ** aInstancePtrResult) rv = nsComponentManager::CreateInstance(aClass, nsnull, - nsITimer::GetIID(), + kITimerIID, (void **)& timer); @@ -72,126 +74,48 @@ static nsresult NewTimer(const nsCID & aClass,nsITimer ** aInstancePtrResult) NS_ASSERTION(NS_SUCCEEDED(rv), (const char *) nsAutoCString(message)); #endif + if (nsnull == timer) return NS_ERROR_OUT_OF_MEMORY; return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); } ////////////////////////////////////////////////////////////////////////// -static nsAutoString GetToolkitName() +static const nsCID * +GetTimerCID() { - static const char * sMozillaToolkit = nsnull; - static PRBool sFirstTime = PR_TRUE; + static const nsCID * sgTimerCID = nsnull; - // Execute the following code only once. - if ((nsnull == sMozillaToolkit) && !sFirstTime) + static NS_DEFINE_CID(kCUnixToolkitServiceCID, NS_UNIX_TOOLKIT_SERVICE_CID); + + // For obvious efficiency reasons, do this only once + if (nsnull == sgTimerCID) { - sFirstTime = PR_FALSE; + nsIUnixToolkitService * unixToolkitService = nsnull; - // Look in the invironment for MOZ_TOOLKIT. A variable - // that controls the toolkit the user wants to use. - sMozillaToolkit = PR_GetEnv("MOZ_TOOLKIT"); + nsresult rv = + nsComponentManager::CreateInstance(kCUnixToolkitServiceCID, + nsnull, + nsIUnixToolkitService::GetIID(), + (void **) &unixToolkitService); + + NS_ASSERTION(rv == NS_OK,"Cannot obtain unix toolkit service."); + + if (NS_OK == rv && nsnull != unixToolkitService) + { + nsresult rv2; - // If MOZ_TOOLKIT is not set, assume gtk - if (!sMozillaToolkit) - return nsAutoString("gtk"); - - // Gtk - if (nsCRT::strcasecmp(sMozillaToolkit,"gtk") == 0) - return nsAutoString("gtk"); - - // Motif - if (nsCRT::strcasecmp(sMozillaToolkit,"motif") == 0) - return nsAutoString("motif"); - - // Xlib - if (nsCRT::strcasecmp(sMozillaToolkit,"xlib") == 0) - return nsAutoString("xlib"); + rv2 = unixToolkitService->GetTimerCID((nsCID **) &sgTimerCID); + + NS_ASSERTION(rv2 == NS_OK,"Cannot get timer cid."); + + NS_RELEASE(unixToolkitService); + } } -#ifdef NS_DEBUG - printf("Toolkit '%s' is unknown. Assumming Gtk.\n",sMozillaToolkit); -#endif - - return nsAutoString("gtk"); + return sgTimerCID; } ////////////////////////////////////////////////////////////////////////// -static const nsCID * GetTimerCID() -{ - static const char * sMozillaToolkit = nsnull; - static const nsCID * sTimerClassID = 0; - static PRBool sDone = PR_FALSE; - - // The following code should execute only once. If the environment - // variable is not set, then 'sMozillaToolkit' will still be null - // in the second iteration. So, we use the sDone flag to make - // sure it executes only once. - if ((nsnull == sMozillaToolkit) && !sDone) - { - sDone = PR_TRUE; - - // Look in the invironment for MOZ_TOOLKIT. A variable - // that controls the toolkit the user wants to use. - sMozillaToolkit = PR_GetEnv("MOZ_TOOLKIT"); - - // If MOZ_TOOLKIT is not set, assume gtk - if (!sMozillaToolkit) - { - sTimerClassID = &kCTimerGtk; -#ifdef DEBUG_ramiro - sToolkitName = "gtk"; -#endif - } - // Otherwise check MOZ_TOOLKIT for the toolkit name - else - { - // Gtk - if (nsCRT::strcasecmp(sMozillaToolkit,"gtk") == 0) - { - sTimerClassID = &kCTimerGtk; -#ifdef DEBUG_ramiro - sToolkitName = "gtk"; -#endif - } - // Motif - else if (nsCRT::strcasecmp(sMozillaToolkit,"motif") == 0) - { - sTimerClassID = &kCTimerMotif; -#ifdef DEBUG_ramiro - sToolkitName = "motif"; -#endif - } - // Xlib - else if (nsCRT::strcasecmp(sMozillaToolkit,"xlib") == 0) - { - sTimerClassID = &kCTimerXlib; -#ifdef DEBUG_ramiro - sToolkitName = "xlib"; -#endif - } - // Default to Gtk - else - { -#ifdef NS_DEBUG - printf("Toolkit '%s' is unknown. Assumming Gtk.\n", - sMozillaToolkit); -#endif - - sTimerClassID = &kCTimerGtk; -#ifdef DEBUG_ramiro - sToolkitName = "gtk"; -#endif - } - } - -#ifdef DEBUG_ramiro - printf("NS_NewTimer() - Using '%s' for the X toolkit.\n", - sMozillaToolkit); -#endif - } - - return sTimerClassID; -} static PRTime sStartTime = 0; static PRTime sEndTime = 0; @@ -204,8 +128,6 @@ nsresult NS_NewTimer(nsITimer ** aInstancePtrResult) NS_ASSERTION(nsnull != cid,"Dude! Trying to make a timer with a null CID."); -// printf("NS_NewTimer(%s)\n",(const char *) nsAutoCString(GetToolkitName())); - nsresult rv = NewTimer(*cid,aInstancePtrResult); sEndTime = PR_Now(); diff --git a/mozilla/widget/timer/src/unix/nsUnixTimerCIID.h b/mozilla/widget/timer/src/unix/nsUnixTimerCIID.h index 8fad686274f..190795c242b 100644 --- a/mozilla/widget/timer/src/unix/nsUnixTimerCIID.h +++ b/mozilla/widget/timer/src/unix/nsUnixTimerCIID.h @@ -21,18 +21,19 @@ #include "nsISupports.h" -// {90F55E53-40EB-11d3-B219-000064657374} +// {48B62AD1-48D3-11d3-B224-000064657374} #define NS_TIMER_MOTIF_CID \ -{ 0x90f55e53, 0x40eb, 0x11d3, \ - { 0xb2, 0x19, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } +{ 0x48b62ad1, 0x48d3, 0x11d3, \ + { 0xb2, 0x24, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } -// {90F55E54-40EB-11d3-B219-000064657374} +// {48B62AD2-48D3-11d3-B224-000064657374} #define NS_TIMER_GTK_CID \ -{ 0x90f55e54, 0x40eb, 0x11d3, \ - { 0xb2, 0x19, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } +{ 0x48b62ad2, 0x48d3, 0x11d3, \ + { 0xb2, 0x24, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } -// {90F55E57-40EB-11d3-B219-000064657374} +// {48B62AD3-48D3-11d3-B224-000064657374} #define NS_TIMER_XLIB_CID \ -{ 0x90f55e57, 0x40eb, 0x11d3, \ - { 0xb2, 0x19, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } +{ 0x48b62ad3, 0x48d3, 0x11d3, + { 0xb2, 0x24, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } + #endif // nsUnixTimerCIID_h__ diff --git a/mozilla/widget/timer/src/unix/xlib/Makefile.in b/mozilla/widget/timer/src/unix/xlib/Makefile.in index 3a4265d7201..f2785c26022 100644 --- a/mozilla/widget/timer/src/unix/xlib/Makefile.in +++ b/mozilla/widget/timer/src/unix/xlib/Makefile.in @@ -24,24 +24,33 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/config.mk -LIBRARY_NAME = $(TIMER_LIB_NAME) -### XXX ### IS_COMPONENT=1 +ifdef TOOLKIT_EXORCISM +LIBRARY_NAME = timer_xlib +IS_COMPONENT=1 REQUIRES=xpcom - -DEFINES += -D_IMPL_NS_TIMER CXXFLAGS += $(TK_CFLAGS) INCLUDES += $(TK_CFLAGS) -I$(srcdir)/.. CPPSRCS = \ nsTimerXlib.cpp \ -### XXX ### nsTimerXlibFactory.cpp \ + nsTimerXlibFactory.cpp \ $(NULL) -### XXX ### EXTRA_DSO_LDOPTS += $(TK_LIBS) +#EXTRA_DSO_LDOPTS += $(TK_LIBS) +EXTRA_DSO_LDOPTS += -L/usr/X11R6/lib -lX11 +else + +LIBRARY_NAME = $(TIMER_LIB_NAME) +REQUIRES = xpcom +CXXFLAGS += $(TK_CFLAGS) +INCLUDES += $(TK_CFLAGS) -I$(srcdir)/.. +CPPSRCS = nsTimerXlib.cpp MKSHLIB = override NO_SHARED_LIB=1 override NO_STATIC_LIB= +endif # TOOLKIT_EXORCISM + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.cpp b/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.cpp index 093c3fdf316..cd0ebe6a0c3 100644 --- a/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.cpp +++ b/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.cpp @@ -18,6 +18,11 @@ #include "nsTimerXlib.h" +#ifdef TOOLKIT_EXORCISM +#include "nsIXlibWindowService.h" +#include "nsIServiceManager.h" +#endif /* TOOLKIT_EXORCISM */ + #include #include @@ -25,8 +30,13 @@ static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); +#ifdef TOOLKIT_EXORCISM +static int NS_TimeToNextTimeout(struct timeval *aTimer); +static void NS_ProcessTimeouts(void); +#else extern "C" int NS_TimeToNextTimeout(struct timeval *aTimer); extern "C" void NS_ProcessTimeouts(void); +#endif /* TOOLKIT_EXORCISM */ nsTimerXlib *nsTimerXlib::gTimerList = NULL; struct timeval nsTimerXlib::gTimer = {0, 0}; @@ -117,6 +127,9 @@ nsTimerXlib::Init(PRUint32 aDelay) } } NS_ADDREF(this); + + EnsureWindowService(); + return NS_OK; } @@ -200,7 +213,53 @@ nsTimerXlib::ProcessTimeouts(struct timeval *aNow) } } -int NS_TimeToNextTimeout(struct timeval *aTimer) { +#ifdef TOOLKIT_EXORCISM +static NS_DEFINE_IID(kWindowServiceCID,NS_XLIB_WINDOW_SERVICE_CID); +static NS_DEFINE_IID(kWindowServiceIID,NS_XLIB_WINDOW_SERVICE_IID); +#endif /* TOOLKIT_EXORCISM */ + +nsresult +nsTimerXlib::EnsureWindowService() +{ +#ifdef TOOLKIT_EXORCISM + nsIXlibWindowService * xlibWindowService = nsnull; + + nsresult rv = nsServiceManager::GetService(kWindowServiceCID, + kWindowServiceIID, + (nsISupports **)&xlibWindowService); + + NS_ASSERTION(NS_SUCCEEDED(rv),"Couldn't obtain window service."); + + if (NS_OK == rv && nsnull != xlibWindowService) + { + xlibWindowService->SetTimeToNextTimeoutFunc(NS_TimeToNextTimeout); + xlibWindowService->SetProcessTimeoutsProc(NS_ProcessTimeouts); + + NS_RELEASE(xlibWindowService); + } +#endif /* TOOLKIT_EXORCISM */ + + return NS_OK; +} + +#ifdef TOOLKIT_EXORCISM +static +#else +extern "C" +#endif /* TOOLKIT_EXORCISM */ +int NS_TimeToNextTimeout(struct timeval *aTimer) +{ +#ifdef TOOLKIT_EXORCISM + static int once = 1; + + if (once) + { + once = 0; + + printf("NS_TimeToNextTimeout() lives!\n"); + } +#endif /* TOOLKIT_EXORCISM */ + nsTimerXlib *timer; timer = nsTimerXlib::gTimerList; if (timer) { @@ -231,24 +290,44 @@ int NS_TimeToNextTimeout(struct timeval *aTimer) { } } -void NS_ProcessTimeouts(void) { +#ifdef TOOLKIT_EXORCISM +static +#else +extern "C" +#endif /* TOOLKIT_EXORCISM */ +void +NS_ProcessTimeouts(void) +{ +#ifdef TOOLKIT_EXORCISM + static int once = 1; + + if (once) + { + once = 0; + + printf("NS_ProcessTimeouts() lives!\n"); + } +#endif /* TOOLKIT_EXORCISM */ + struct timeval now; now.tv_sec = 0; now.tv_usec = 0; nsTimerXlib::ProcessTimeouts(&now); } +#ifndef TOOLKIT_EXORCISM nsresult NS_NewTimer(nsITimer** aInstancePtrResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - - nsTimerXlib *timer = new nsTimerXlib(); - if (nsnull == timer) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); + NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + + nsTimerXlib *timer = new nsTimerXlib(); + if (nsnull == timer) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); } +#endif /* TOOLKIT_EXORCISM */ diff --git a/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.h b/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.h index 5017374b087..7494fdf1cdb 100644 --- a/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.h +++ b/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.h @@ -57,6 +57,7 @@ public: private: nsresult Init(PRUint32 aDelay); + nsresult EnsureWindowService(); nsTimerCallbackFunc mFunc; void * mClosure; diff --git a/mozilla/widget/timer/src/unix/xlib/nsTimerXlibFactory.cpp b/mozilla/widget/timer/src/unix/xlib/nsTimerXlibFactory.cpp index 238b90e4856..cd289f2a029 100644 --- a/mozilla/widget/timer/src/unix/xlib/nsTimerXlibFactory.cpp +++ b/mozilla/widget/timer/src/unix/xlib/nsTimerXlibFactory.cpp @@ -19,7 +19,7 @@ #include "nsTimerXlib.h" -#include "nsTimerCIID.h" +#include "nsUnixTimerCIID.h" #include "nsIFactory.h" #include "nsIComponentManager.h" diff --git a/mozilla/xpfe/bootstrap/Makefile.in b/mozilla/xpfe/bootstrap/Makefile.in index c70b7ce249f..ea09a1dd012 100644 --- a/mozilla/xpfe/bootstrap/Makefile.in +++ b/mozilla/xpfe/bootstrap/Makefile.in @@ -55,12 +55,21 @@ ifeq ($(MOZ_WIDGET_TOOLKIT),beos) BEOS_PROGRAM_RESOURCE = $(srcdir)/apprunner-beos.rsrc endif +ifndef TOOLKIT_EXORCISM + UN_EXORCISED_WIDGET_FLAGS=$(MOZ_WIDGET_TOOLKIT_LDFLAGS) + UN_EXORCISED_GFX_FLAGS=$(MOZ_GFX_TOOLKIT_LDFLAGS) +endif + +ifndef TOOLKIT_EXORCISM + UN_EXORCISED_TK_FLAGS=$(TK_LIBS) +endif + LIBS += \ -lnsappshell \ -lxpcom \ - $(MOZ_WIDGET_TOOLKIT_LDFLAGS) \ + $(UN_EXORCISED_WIDGET_FLAGS) \ -lraptorgfx \ - $(MOZ_GFX_TOOLKIT_LDFLAGS) \ + $(UN_EXORCISED_GFX_FLAGS) \ $(TIMER_LIBS) \ -lmozreg \ -lraptorwebwidget \ @@ -80,7 +89,7 @@ LIBS += \ -lxpcom \ $(ZLIB_LIBS) \ $(NSPR_LIBS) \ - $(TK_LIBS) \ + $(UN_EXORCISED_TK_FLAGS) \ $(NULL) include $(topsrcdir)/config/rules.mk