diff --git a/mozilla/widget/src/xlib/nsAppShell.cpp b/mozilla/widget/src/xlib/nsAppShell.cpp index fdd21d04125..be519d886db 100644 --- a/mozilla/widget/src/xlib/nsAppShell.cpp +++ b/mozilla/widget/src/xlib/nsAppShell.cpp @@ -83,18 +83,20 @@ static NS_DEFINE_IID(kWindowServiceIID,NS_XLIB_WINDOW_SERVICE_IID); extern "C" int NS_TimeToNextTimeout(struct timeval *); extern "C" void NS_ProcessTimeouts(void); -PRBool nsAppShell::DieAppShellDie = PR_FALSE; -PRBool nsAppShell::mClicked = PR_FALSE; +Display *nsAppShell::mDisplay = nsnull; +XlibRgbHandle *nsAppShell::mXlib_rgb_handle = nsnull; +XtAppContext nsAppShell::mAppContext; PRTime nsAppShell::mClickTime = 0; PRInt16 nsAppShell::mClicks = 1; PRUint16 nsAppShell::mClickedButton = 0; -Display *nsAppShell::mDisplay = nsnull; -PRBool nsAppShell::mDragging = PR_FALSE; -PRBool nsAppShell::mAltDown = PR_FALSE; -PRBool nsAppShell::mShiftDown = PR_FALSE; -PRBool nsAppShell::mCtrlDown = PR_FALSE; -PRBool nsAppShell::mMetaDown = PR_FALSE; -XlibRgbHandle *nsAppShell::mXlib_rgb_handle = nsnull; +PRPackedBool nsAppShell::mClicked = PR_FALSE; +PRPackedBool nsAppShell::mDragging = PR_FALSE; +PRPackedBool nsAppShell::mAltDown = PR_FALSE; +PRPackedBool nsAppShell::mShiftDown = PR_FALSE; +PRPackedBool nsAppShell::mCtrlDown = PR_FALSE; +PRPackedBool nsAppShell::mMetaDown = PR_FALSE; +PRPackedBool nsAppShell::DieAppShellDie = PR_FALSE; + // For debugging. @@ -151,7 +153,7 @@ static nsXlibTimeToNextTimeoutFunc GetTimeToNextTimeoutFunc(void) NS_ASSERTION(NS_SUCCEEDED(rv),"Couldn't obtain window service."); - if (NS_OK == rv && nsnull != xlibWindowService) + if (NS_SUCCEEDED(rv) && nsnull != xlibWindowService) { xlibWindowService->GetTimeToNextTimeoutFunc(&sFunc); @@ -189,7 +191,7 @@ static nsXlibProcessTimeoutsProc GetProcessTimeoutsProc(void) NS_ASSERTION(NS_SUCCEEDED(rv),"Couldn't obtain window service."); - if (NS_OK == rv && nsnull != xlibWindowService) + if (NS_SUCCEEDED(rv) && nsnull != xlibWindowService) { xlibWindowService->GetProcessTimeoutsProc(&sProc); @@ -225,13 +227,13 @@ static int CallTimeToNextTimeoutFunc(struct timeval * aTimeval) return 0; } -static void CallProcessTimeoutsProc(Display *aDisplay) +static void CallProcessTimeoutsProc(XtAppContext app_context) { nsXlibProcessTimeoutsProc proc = GetProcessTimeoutsProc(); if (proc) { - (*proc)(aDisplay); + (*proc)(app_context); } } @@ -255,13 +257,13 @@ nsAppShell::nsAppShell() NS_INIT_ISUPPORTS(); mDispatchListener = 0; - mScreen = nsnull; mEventQueue = nsnull; xlib_fd = -1; } NS_IMPL_ISUPPORTS1(nsAppShell, nsIAppShell) +PR_BEGIN_EXTERN_C static int xerror_handler( Display *display, XErrorEvent *ev ) { @@ -273,12 +275,12 @@ int xerror_handler( Display *display, XErrorEvent *ev ) return 0; } +PR_END_EXTERN_C NS_METHOD nsAppShell::Create(int* bac, char ** bav) { char *mArgv[1]; int mArgc = 0; - XtAppContext app_context; int argc = bac ? *bac : 0; char **argv = bav; @@ -331,12 +333,12 @@ NS_METHOD nsAppShell::Create(int* bac, char ** bav) NS_WARNING("can not set locale modifiers"); // Open the display - if (mDisplay == nsnull) { + if (mAppContext == nsnull) { XtToolkitInitialize(); - app_context = XtCreateApplicationContext(); + mAppContext = XtCreateApplicationContext(); - if (!(mDisplay = XtOpenDisplay (app_context, displayName, - "Mozilla5", "Mozilla5", NULL, 0, + if (!(mDisplay = XtOpenDisplay (mAppContext, displayName, + "Mozilla5", "Mozilla5", nsnull, 0, &mArgc, mArgv))) { fprintf (stderr, "%s: unable to open display \"%s\"\n", mArgv[0], XDisplayName(displayName)); @@ -355,15 +357,13 @@ NS_METHOD nsAppShell::Create(int* bac, char ** bav) XSynchronize(mDisplay, True); } - mScreen = XDefaultScreenOfDisplay(mDisplay); - mXlib_rgb_handle = xxlib_rgb_create_handle(XXLIBRGB_DEFAULT_HANDLE, mDisplay, mScreen); + mXlib_rgb_handle = xxlib_rgb_create_handle(XXLIBRGB_DEFAULT_HANDLE, mDisplay, XDefaultScreenOfDisplay(mDisplay)); if (!mXlib_rgb_handle) abort(); } - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsAppShell::Create(dpy=%p screen=%p)\n", - mDisplay, - mScreen)); + PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsAppShell::Create(dpy=%p)\n", + mDisplay)); return NS_OK; } @@ -384,7 +384,7 @@ NS_METHOD nsAppShell::Spinup() rv = nsServiceManager::GetService(kEventQueueServiceCID, kIEventQueueServiceIID, (nsISupports **) &mEventQueueService); - if (NS_OK != rv) { + if (NS_FAILED(rv)) { NS_WARNING("Could not obtain event queue service"); return rv; } @@ -394,12 +394,13 @@ NS_METHOD nsAppShell::Spinup() // Create the event queue for the thread rv = mEventQueueService->CreateThreadEventQueue(); - if (NS_OK != rv) { + if (NS_FAILED(rv)) { NS_WARNING("Could not create the thread event queue"); return rv; } //Get the event queue for the thread - rv = mEventQueueService->GetThreadEventQueue(NS_CURRENT_THREAD, &mEventQueue); if (NS_OK != rv) { + rv = mEventQueueService->GetThreadEventQueue(NS_CURRENT_THREAD, &mEventQueue); + if (NS_FAILED(rv)) { NS_WARNING("Could not obtain the thread event queue"); return rv; } @@ -410,13 +411,13 @@ NS_METHOD nsAppShell::Spinup() static void CallProcessTimeoutsXtProc( XtPointer dummy1, XtIntervalId *dummy2 ) { - CallProcessTimeoutsProc(nsAppShell::mDisplay); + XtAppContext *app_context = (XtAppContext *) dummy1; + CallProcessTimeoutsProc(*app_context); // Flush the nsWindow's drawing queue nsWindow::UpdateIdle(nsnull); // reset timer - XtAppContext *app_context = (XtAppContext *) dummy1; #define CALLPROCESSTIMEOUTSVAL (10) XtAppAddTimeOut(*app_context, CALLPROCESSTIMEOUTSVAL, @@ -436,10 +437,7 @@ nsresult nsAppShell::Run() { nsresult rv = NS_OK; XtInputMask mask; - XtAppContext app_context = XtDisplayToApplicationContext(mDisplay); - NS_ASSERTION(app_context!=nsnull, "XtDisplayToApplicationContext returned nsnull. BAD."); - if (mEventQueue == nsnull) Spinup(); @@ -449,23 +447,23 @@ nsresult nsAppShell::Run() } // set up our fds callbacks - XtAppAddInput(app_context, + XtAppAddInput(mAppContext, mEventQueue->GetEventQueueSelectFD(), (XtPointer)(long)(XtInputReadMask), HandleQueueXtProc, (XtPointer)mEventQueue); // set initial timer - XtAppAddTimeOut(app_context, + XtAppAddTimeOut(mAppContext, CALLPROCESSTIMEOUTSVAL, CallProcessTimeoutsXtProc, - &app_context); + &mAppContext); // process events. - while (DieAppShellDie == PR_FALSE) + while (!DieAppShellDie) { XEvent event; - XtAppNextEvent(app_context, &event); + XtAppNextEvent(mAppContext, &event); if (XtDispatchEvent(&event) == False) DispatchXEvent(&event); @@ -516,7 +514,7 @@ nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *&aEvent) DelayTime.tv_sec = 0; DelayTime.tv_usec = 100; - select_retval = select(max_fd, &select_set, NULL, NULL, &DelayTime); + select_retval = select(max_fd, &select_set, nsnull, nsnull, &DelayTime); if (select_retval == -1) return NS_ERROR_FAILURE; @@ -549,7 +547,7 @@ nsresult nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent) free(event); } - CallProcessTimeoutsProc(mDisplay); + CallProcessTimeoutsProc(mAppContext); nsWindow::UpdateIdle(nsnull); return rv; @@ -589,7 +587,7 @@ nsAppShell::DispatchXEvent(XEvent *event) HandleExposeEvent(event, widget); break; - case ConfigureNotify: + case ConfigureNotify: // we need to make sure that this is the LAST of the // config events. PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("DispatchEvent: ConfigureNotify event for window 0x%lx %d %d %d %d\n", @@ -1216,7 +1214,9 @@ void nsAppShell::HandleClientMessageEvent(XEvent *event, nsWidget *aWidget) #endif if (nsWidget::WMProtocolsInitialized) { if ((Atom)event->xclient.data.l[0] == nsWidget::WMDeleteWindow) { +#ifdef DEBUG printf("got a delete window event\n"); +#endif /* DEBUG */ aWidget->OnDeleteWindow(); } } diff --git a/mozilla/widget/src/xlib/nsAppShell.h b/mozilla/widget/src/xlib/nsAppShell.h index d7e87056ddb..0a07ee4cb39 100644 --- a/mozilla/widget/src/xlib/nsAppShell.h +++ b/mozilla/widget/src/xlib/nsAppShell.h @@ -20,7 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Roland.Mainz + * Roland Mainz * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -44,6 +44,7 @@ #include "nsWidget.h" #include "prtime.h" #include "xlibrgb.h" +#include class nsAppShell : public nsIAppShell { @@ -71,8 +72,9 @@ class nsAppShell : public nsIAppShell /* |xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE)| would be the official * way - but |nsAppShell::GetXlibRgbHandle()| one is little bit faster... :-) */ + static XtAppContext mAppContext; static XlibRgbHandle *GetXlibRgbHandle() { return mXlib_rgb_handle; } - static Display * mDisplay; + static Display *mDisplay; private: static XlibRgbHandle *mXlib_rgb_handle; int xlib_fd; @@ -97,22 +99,20 @@ class nsAppShell : public nsIAppShell static void HandleDragLeaveEvent(XEvent *event, nsWidget *aWidget); static void HandleDragDropEvent(XEvent *event, nsWidget *aWidget); static void ForwardEvent(XEvent *event, nsWidget *aWidget); - static PRBool DieAppShellDie; - static PRBool mClicked; - static PRTime mClickTime; - static PRInt16 mClicks; - static PRUint16 mClickedButton; - static PRBool mDragging; - static PRBool mAltDown; - static PRBool mShiftDown; - static PRBool mCtrlDown; - static PRBool mMetaDown; - + static PRInt16 mClicks; + static PRUint16 mClickedButton; + static PRTime mClickTime; + static PRPackedBool mClicked; + static PRPackedBool mDragging; + static PRPackedBool mAltDown; + static PRPackedBool mShiftDown; + static PRPackedBool mCtrlDown; + static PRPackedBool mMetaDown; + static PRPackedBool DieAppShellDie; protected: - nsIEventQueueService * mEventQueueService; - nsIEventQueue *mEventQueue; - Screen *mScreen; + nsIEventQueueService *mEventQueueService; + nsIEventQueue *mEventQueue; }; -#endif // nsAppShell_h__ +#endif /* !nsAppShell_h__ */ diff --git a/mozilla/widget/src/xlib/nsButton.h b/mozilla/widget/src/xlib/nsButton.h index c243afd4172..291447ad709 100644 --- a/mozilla/widget/src/xlib/nsButton.h +++ b/mozilla/widget/src/xlib/nsButton.h @@ -42,7 +42,7 @@ #include "nsIButton.h" class nsButton : public nsWidget, - public nsIButton + public nsIButton { public: nsButton(); @@ -59,7 +59,7 @@ class nsButton : public nsWidget, // nsBaseWidget NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); + const nsRect& aDirtyRect); protected: nsString mLabel; diff --git a/mozilla/widget/src/xlib/nsDragService.cpp b/mozilla/widget/src/xlib/nsDragService.cpp index 6680e13f2e0..76af2475fe7 100644 --- a/mozilla/widget/src/xlib/nsDragService.cpp +++ b/mozilla/widget/src/xlib/nsDragService.cpp @@ -18,8 +18,8 @@ * are Copyright (C) 1998 Christopher Blizzard. All Rights Reserved. * * Contributor(s): - * Christopher Blizzard - * Peter Hartshorn + * Christopher Blizzard + * Peter Hartshorn */ #include "nsAppShell.h" @@ -283,8 +283,8 @@ void nsDragService::CreateDragCursor(PRUint32 aActionType) wmHints.flags = StateHint; wmHints.initial_state = NormalState; - XSetWMProperties(sDisplay, sWindow, NULL, NULL, NULL, 0, NULL, - &wmHints, NULL); + XSetWMProperties(sDisplay, sWindow, nsnull, nsnull, nsnull, 0, nsnull, + &wmHints, nsnull); XSetTransientForHint(sDisplay, sWindow, sWindow); XShapeCombineMask(sDisplay, sWindow, ShapeClip, 0, 0, aShapeMask, ShapeSet); diff --git a/mozilla/widget/src/xlib/nsDragService.h b/mozilla/widget/src/xlib/nsDragService.h index 3af244cc698..51dd3f5c86c 100644 --- a/mozilla/widget/src/xlib/nsDragService.h +++ b/mozilla/widget/src/xlib/nsDragService.h @@ -47,7 +47,7 @@ public: // nsIDragService NS_IMETHOD InvokeDragSession (nsIDOMNode *aDOMNode, - nsISupportsArray * anArrayTransferables, + nsISupportsArray * anArrayTransferables, nsIScriptableRegion * aRegion, PRUint32 aActionType); NS_IMETHOD StartDragSession(); diff --git a/mozilla/widget/src/xlib/nsKeyCode.cpp b/mozilla/widget/src/xlib/nsKeyCode.cpp index 900b246d653..75ae3d20714 100644 --- a/mozilla/widget/src/xlib/nsKeyCode.cpp +++ b/mozilla/widget/src/xlib/nsKeyCode.cpp @@ -182,26 +182,25 @@ nsKeyCode::ConvertKeySymToVirtualKey(KeySym keysym) /* static */ PRBool nsKeyCode::KeyCodeIsModifier(KeyCode aKeyCode) { - if (aKeyCode == XK_Shift_L || - aKeyCode == XK_Shift_R || - aKeyCode == XK_Control_L || - aKeyCode == XK_Control_R || - aKeyCode == XK_Caps_Lock || - aKeyCode == XK_Shift_Lock || - aKeyCode == XK_Meta_L || - aKeyCode == XK_Meta_R || - aKeyCode == XK_Alt_L || - aKeyCode == XK_Alt_R) + if (aKeyCode == XK_Shift_L || + aKeyCode == XK_Shift_R || + aKeyCode == XK_Control_L || + aKeyCode == XK_Control_R || + aKeyCode == XK_Caps_Lock || + aKeyCode == XK_Shift_Lock || + aKeyCode == XK_Meta_L || + aKeyCode == XK_Meta_R || + aKeyCode == XK_Alt_L || + aKeyCode == XK_Alt_R) { - return PR_TRUE; + return PR_TRUE; } return PR_FALSE; } ////////////////////////////////////////////////////////////////////////// /* static */ KeySym -nsKeyCode::ConvertKeyCodeToKeySym(Display * aDisplay, - KeyCode aKeyCode) +nsKeyCode::ConvertKeyCodeToKeySym(Display * aDisplay, KeyCode aKeyCode) { KeySym keysym = 0; diff --git a/mozilla/widget/src/xlib/nsScrollBar.h b/mozilla/widget/src/xlib/nsScrollBar.h index 5c55cfcf665..e78c06da621 100644 --- a/mozilla/widget/src/xlib/nsScrollBar.h +++ b/mozilla/widget/src/xlib/nsScrollBar.h @@ -79,7 +79,7 @@ public: NS_IMETHOD SetLineIncrement(PRUint32 aSize); NS_IMETHOD GetLineIncrement(PRUint32& aSize); NS_IMETHOD SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, - PRUint32 aPosition, PRUint32 aLineIncrement); + PRUint32 aPosition, PRUint32 aLineIncrement); PRBool OnScroll(PRUint32 scrollCode, int cPos); void CreateNative(Window aParent, nsRect aRect); diff --git a/mozilla/widget/src/xlib/nsSound.cpp b/mozilla/widget/src/xlib/nsSound.cpp index 396b2dbada4..9ecb4e90bf9 100644 --- a/mozilla/widget/src/xlib/nsSound.cpp +++ b/mozilla/widget/src/xlib/nsSound.cpp @@ -27,6 +27,7 @@ #include "prlink.h" #include "nsSound.h" +#include "nsAppShell.h" #include "nsIURL.h" #include "nsNetUtil.h" @@ -73,8 +74,10 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader, NS_METHOD nsSound::Beep() { #ifdef DEBUG_faulkner - fprintf(stderr, "\n////////// nsSound::Beep() in xlib called //////////\n"); + fprintf(stderr, "\n////////// nsSound::Beep() in xlib called //////////\n"); #endif /* DEBUG_faulkner */ + + XBell(nsAppShell::mDisplay, 80); return NS_OK; } @@ -83,7 +86,7 @@ NS_METHOD nsSound::Play(nsIURL *aURL) #ifdef DEBUG_faulkner fprintf(stderr, "\n////////// nsSound::Play() in xlib called //////////\n"); #endif /* DEBUG_faulkner */ - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsSound::PlaySystemSound(const char *aSoundAlias) diff --git a/mozilla/widget/src/xlib/nsTextWidget.h b/mozilla/widget/src/xlib/nsTextWidget.h index 3ccf507d196..39029bf9d9a 100644 --- a/mozilla/widget/src/xlib/nsTextWidget.h +++ b/mozilla/widget/src/xlib/nsTextWidget.h @@ -55,7 +55,7 @@ public: NS_IMETHOD_(nsrefcnt) Release(void); NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); + const nsRect& aDirtyRect); }; diff --git a/mozilla/widget/src/xlib/nsWidget.cpp b/mozilla/widget/src/xlib/nsWidget.cpp index c2c6c100b9d..8abeaa4fb39 100644 --- a/mozilla/widget/src/xlib/nsWidget.cpp +++ b/mozilla/widget/src/xlib/nsWidget.cpp @@ -66,7 +66,7 @@ static NS_DEFINE_CID(kRegionCID, NS_REGION_CID); -PRLogModuleInfo *XlibWidgetsLM = PR_NewLogModule("XlibWidgets"); +PRLogModuleInfo *XlibWidgetsLM = PR_NewLogModule("XlibWidgets"); PRLogModuleInfo *XlibScrollingLM = PR_NewLogModule("XlibScrolling"); // set up our static members here. @@ -90,7 +90,7 @@ nsXlibEventDispatcher nsWidget::gsEventDispatcher = nsnull; // this is for implemention the WM_PROTOCOL code PRBool nsWidget::WMProtocolsInitialized = PR_FALSE; Atom nsWidget::WMDeleteWindow = 0; -Atom nsWidget::WMTakeFocus = 0; +Atom nsWidget::WMTakeFocus = 0; Atom nsWidget::WMSaveYourself = 0; // this is the window that has the focus @@ -154,7 +154,7 @@ nsWidget::nsWidget() // : nsBaseWidget() // added KenF mIsDestroying = PR_FALSE; mOnDestroyCalled = PR_FALSE; - mListenForResizes = PR_FALSE; // If we're native we need to listen. + mListenForResizes = PR_FALSE; // If we're native we need to listen. mMapped = PR_FALSE; @@ -163,8 +163,6 @@ nsWidget::nsWidget() // : nsBaseWidget() mUpdateArea->Init(); mUpdateArea->SetTo(0, 0, 0, 0); } - - } // FIXME: @@ -175,7 +173,6 @@ nsWidget::~nsWidget() if (mBaseWindow) Destroy(); - } // Borrowed heavily from GTK. This should go through heirarchy of XWindow @@ -235,7 +232,7 @@ NS_IMETHODIMP nsWidget::Create(nsIWidget *aParent, { // Do adding in SWC() KenF //mParentWidget = aParent; - //NS_IF_ADDREF(mParentWidget); // KenF FIXME + //NS_IF_ADDREF(mParentWidget); // KenF FIXME return StandardWidgetCreate(aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData, @@ -387,7 +384,7 @@ NS_IMETHODIMP nsWidget::Destroy() mIsDestroying = PR_TRUE; nsBaseWidget::Destroy(); - NS_IF_RELEASE(mParentWidget); //???? + NS_IF_RELEASE(mParentWidget); //???? if (mBaseWindow) { @@ -612,7 +609,7 @@ void * nsWidget::GetNativeData(PRUint32 aDataType) default: fprintf(stderr, "nsWidget::GetNativeData(%d) called with crap value.\n", aDataType); - return NULL; + return nsnull; break; } } @@ -911,33 +908,33 @@ nsWidget::OnPaint(nsPaintEvent &event) } #ifdef TRACE_PAINT - static PRInt32 sPrintCount = 0; + static PRInt32 sPrintCount = 0; - if (event.rect) - { - printf("%4d nsWidget::OnPaint (this=%p,name=%s,xid=%p,rect=%d,%d,%d,%d)\n", - sPrintCount++, - (void *) this, - (const char *) nsCAutoString(mName), - (void *) mBaseWindow, - event.rect->x, - event.rect->y, - event.rect->width, - event.rect->height); - } - else - { - printf("%4d nsWidget::OnPaint (this=%p,name=%s,xid=%p,rect=none)\n", - sPrintCount++, - (void *) this, - (const char *) nsCAutoString(mName), - (void *) mBaseWindow); - } + if (event.rect) + { + printf("%4d nsWidget::OnPaint (this=%p,name=%s,xid=%p,rect=%d,%d,%d,%d)\n", + sPrintCount++, + (void *) this, + (const char *) nsCAutoString(mName), + (void *) mBaseWindow, + event.rect->x, + event.rect->y, + event.rect->width, + event.rect->height); + } + else + { + printf("%4d nsWidget::OnPaint (this=%p,name=%s,xid=%p,rect=none)\n", + sPrintCount++, + (void *) this, + (const char *) nsCAutoString(mName), + (void *) mBaseWindow); + } #endif #ifdef TRACE_PAINT_FLASH XRectangle ar; - XRectangle * area = NULL; + XRectangle * area = nsnull; if (event.rect) { @@ -957,48 +954,53 @@ nsWidget::OnPaint(nsPaintEvent &event) return result; } -PRBool nsWidget::IsMouseInWindow(Window window, PRInt32 inMouseX, PRInt32 inMouseY){ - - XWindowAttributes inWindowAttributes; +PRBool nsWidget::IsMouseInWindow(Window window, PRInt32 inMouseX, PRInt32 inMouseY) +{ + XWindowAttributes inWindowAttributes; /* sometimes we get NULL window */ if (!window) return PR_FALSE; - // Get the origin (top left corner) coordinate and size - if (XGetWindowAttributes(mDisplay, window, &inWindowAttributes) == 0) { - fprintf(stderr, "Failed calling XGetWindowAttributes in nsWidget::IsMouseInWindow"); - return PR_FALSE; - } - - // Note: These coordinates are now relative to the root window as popups are now created - // with the root window as parent - - // Must get mouse click coordinates relative to root window - int root_inMouse_x; - int root_inMouse_y; - Window returnedChild; - Window rootWindow; - rootWindow = XRootWindow(mDisplay, DefaultScreen(mDisplay)); - if (!XTranslateCoordinates(mDisplay, mBaseWindow, rootWindow, - inMouseX, inMouseY, - &root_inMouse_x, &root_inMouse_y, &returnedChild)){ - fprintf(stderr, "Could not get coordinates for origin coordinates for mouseclick\n"); - // should we return true or false?????? - return PR_FALSE; - } - //fprintf(stderr, "Here are the mouse click coordinates x:%i y%i\n", root_inMouse_x, root_inMouse_y); - - // Test using coordinates relative to root window if click was inside passed popup window - if (root_inMouse_x > inWindowAttributes.x && - root_inMouse_x < (inWindowAttributes.x + inWindowAttributes.width) && + /* Get the origin (top left corner) coordinate and window's size */ + if (XGetWindowAttributes(mDisplay, window, &inWindowAttributes) == 0) { + fprintf(stderr, "Failed calling XGetWindowAttributes in nsWidget::IsMouseInWindow"); + return PR_FALSE; + } + + // Note: These coordinates are now relative to the root window as popups are now created + // with the root window as parent + + // Must get mouse click coordinates relative to root window + int root_inMouse_x, + root_inMouse_y; + Window returnedChild; + Window rootWindow; + rootWindow = XRootWindow(mDisplay, XDefaultScreen(mDisplay)); + if (!XTranslateCoordinates(mDisplay, mBaseWindow, rootWindow, + inMouseX, inMouseY, + &root_inMouse_x, &root_inMouse_y, &returnedChild)){ + fprintf(stderr, "Could not get coordinates for origin coordinates for mouseclick\n"); + // should we return true or false?????? + return PR_FALSE; + } + //fprintf(stderr, "Here are the mouse click coordinates x:%i y%i\n", root_inMouse_x, root_inMouse_y); + + // Test using coordinates relative to root window if click was inside passed popup window + if (root_inMouse_x > inWindowAttributes.x && + root_inMouse_x < (inWindowAttributes.x + inWindowAttributes.width) && root_inMouse_y > inWindowAttributes.y && - root_inMouse_y < (inWindowAttributes.y + inWindowAttributes.height)){ + root_inMouse_y < (inWindowAttributes.y + inWindowAttributes.height)) { +#ifdef DEBUG_whoemeveraddedthatprintforginally //fprintf(stderr, "Mouse click INSIDE passed popup\n"); - return PR_TRUE; - } - //fprintf(stderr, "Mouse click OUTSIDE of passed popup\n"); - return PR_FALSE; +#endif + return PR_TRUE; + } + +#ifdef DEBUG_whoemeveraddedthatprintforginally + //fprintf(stderr, "Mouse click OUTSIDE of passed popup\n"); +#endif + return PR_FALSE; } @@ -1009,20 +1011,21 @@ PRBool nsWidget::IsMouseInWindow(Window window, PRInt32 inMouseX, PRInt32 inMous // PRBool nsWidget::HandlePopup ( PRInt32 inMouseX, PRInt32 inMouseY ) { - PRBool retVal = PR_FALSE; - PRBool rollup = PR_FALSE; - - // The gRollupListener and gRollupWidget are both set to nsnull when a popup is no - // longer visible - + PRBool retVal = PR_FALSE; + PRBool rollup = PR_FALSE; + + // The gRollupListener and gRollupWidget are both set to nsnull when a popup is no + // longer visible + nsCOMPtr rollupWidget = do_QueryReferent(gRollupWidget); - + if (rollupWidget && gRollupListener) { Window currentPopup = (Window)rollupWidget->GetNativeData(NS_NATIVE_WINDOW); if (!IsMouseInWindow(currentPopup, inMouseX, inMouseY)) { - rollup = PR_TRUE; - nsCOMPtr menuRollup ( do_QueryInterface(gRollupListener) ); + rollup = PR_TRUE; + nsCOMPtr menuRollup ( do_QueryInterface(gRollupListener) ); + if ( menuRollup ) { nsCOMPtr widgetChain; menuRollup->GetSubmenuWidgetChain ( getter_AddRefs(widgetChain) ); @@ -1042,15 +1045,15 @@ PRBool nsWidget::HandlePopup ( PRInt32 inMouseX, PRInt32 inMouseY ) } } // foreach parent menu widget } - } - } - } - - if (rollup){ - gRollupListener->Rollup(); - retVal = PR_TRUE; - } - return retVal; + } + } + } + + if (rollup) { + gRollupListener->Rollup(); + retVal = PR_TRUE; + } + return retVal; } @@ -1069,7 +1072,9 @@ void nsWidget::OnDestroy() PRBool nsWidget::OnDeleteWindow(void) { +#ifdef DEBUG printf("nsWidget::OnDeleteWindow()\n"); +#endif /* DEBUUG */ nsBaseWidget::OnDestroy(); // emit a destroy signal return DispatchDestroyEvent(); @@ -1100,18 +1105,18 @@ PRBool nsWidget::DispatchMouseEvent(nsMouseEvent& aEvent) return result; } - // If there was a mouse down event, check if any popups need to be informed - switch (aEvent.message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: + /* If there was a mouse down event, check if any popups need to be notified */ + switch (aEvent.message) { + case NS_MOUSE_LEFT_BUTTON_DOWN: case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - if (HandlePopup(aEvent.point.x, aEvent.point.y)){ - // Should we return here as GTK does? - return PR_TRUE; - } - break; - } - + case NS_MOUSE_RIGHT_BUTTON_DOWN: + if (HandlePopup(aEvent.point.x, aEvent.point.y)){ + // Should we return here as GTK does? + return PR_TRUE; + } + break; + } + if (nsnull != mEventCallback) { result = DispatchWindowEvent(aEvent); return result; @@ -1140,7 +1145,6 @@ PRBool nsWidget::DispatchMouseEvent(nsMouseEvent& aEvent) PRBool nsWidget::OnResize(nsSizeEvent &event) { - mBounds.width = event.mWinWidth; mBounds.height = event.mWinHeight; @@ -1270,7 +1274,7 @@ PRBool nsWidget::ConvertStatus(nsEventStatus aStatus) case nsEventStatus_eConsumeDoDefault: return(PR_FALSE); default: - NS_ASSERTION(0, "Illegal nsEventStatus enumeration value"); + NS_WARNING("Illegal nsEventStatus enumeration value\n"); break; } return(PR_FALSE); @@ -1278,7 +1282,6 @@ PRBool nsWidget::ConvertStatus(nsEventStatus aStatus) void nsWidget::WidgetPut(nsWidget *aWidget) { - } void nsWidget::WidgetMove(nsWidget *aWidget) @@ -1561,12 +1564,11 @@ NS_METHOD nsWidget::GetRequestedBounds(nsRect &aRect) NS_IMETHODIMP nsWidget::SetTitle(const nsString& title) { - return NS_OK; } NS_IMETHODIMP nsWidget::CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent) { - return NS_OK; } + diff --git a/mozilla/widget/src/xlib/nsWidget.h b/mozilla/widget/src/xlib/nsWidget.h index e7c2896b8dd..9d4521ff4e3 100644 --- a/mozilla/widget/src/xlib/nsWidget.h +++ b/mozilla/widget/src/xlib/nsWidget.h @@ -23,7 +23,7 @@ * Ken Faulkner * Quy Tonthat * B.J. Rossiter - * Roland.Mainz + * Roland Mainz * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -145,7 +145,7 @@ public: virtual PRBool OnDeleteWindow(void); // KenF Added FIXME: - virtual void OnDestroy(void); + virtual void OnDestroy(void); virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent); virtual PRBool DispatchKeyEvent(nsKeyEvent &aKeyEvent); virtual PRBool DispatchDestroyEvent(void); @@ -173,9 +173,9 @@ public: // thing. KenF void *CheckParent(long ThisWindow); - // Deal with rollup for popups - PRBool IsMouseInWindow(Window window, PRInt32 inMouseX, PRInt32 inMouseY); - PRBool HandlePopup( PRInt32 inMouseX, PRInt32 inMouseY); + // Deal with rollup for popups + PRBool IsMouseInWindow(Window window, PRInt32 inMouseX, PRInt32 inMouseY); + PRBool HandlePopup( PRInt32 inMouseX, PRInt32 inMouseY); void WidgetShow (nsWidget *aWidget); protected: @@ -232,14 +232,13 @@ protected: unsigned long mBackgroundPixel; PRUint32 mBorderRGB; unsigned long mBorderPixel; - // GC mGC; // until we get gc pooling working... nsString mName; // name of the type of widget - PRBool mIsToplevel; nsRect mRequestedSize; - PRBool mMapped; - PRBool mLastGrabFailed; + PRPackedBool mIsToplevel; + PRPackedBool mMapped; + PRPackedBool mLastGrabFailed; - static Window mFocusWindow; + static Window mFocusWindow; // Changed to protected so nsWindow has access to it. KenF protected: @@ -254,18 +253,13 @@ protected: // Variables for infomation about the current popup window and its listener static nsCOMPtr gRollupListener; static nsWeakPtr gRollupWidget; - static PRBool gRollupConsumeRollupEvent; - + static PRBool gRollupConsumeRollupEvent; }; extern PRLogModuleInfo *XlibWidgetsLM; extern PRLogModuleInfo *XlibScrollingLM; -#endif - - - - +#endif /* !nsWidget_h__ */ diff --git a/mozilla/widget/src/xlib/nsWidgetFactory.cpp b/mozilla/widget/src/xlib/nsWidgetFactory.cpp index 32db9aa9992..f78365455c4 100644 --- a/mozilla/widget/src/xlib/nsWidgetFactory.cpp +++ b/mozilla/widget/src/xlib/nsWidgetFactory.cpp @@ -87,20 +87,18 @@ static nsresult nsHorizScrollbarConstructor (nsISupports *aOuter, REFNSIID aIID, nsresult rv; nsISupports *inst = nsnull; - if ( NULL == aResult ) + if ( nsnull == aResult ) { - rv = NS_ERROR_NULL_POINTER; - return rv; + return NS_ERROR_NULL_POINTER; } - *aResult = NULL; - if (NULL != aOuter) + *aResult = nsnull; + if (nsnull != aOuter) { - rv = NS_ERROR_NO_AGGREGATION; - return rv; + return NS_ERROR_NO_AGGREGATION; } inst = (nsISupports *)(nsBaseWidget *)(nsWidget *)new nsScrollbar(PR_FALSE); - if (inst == NULL) + if (inst == nsnull) { return NS_ERROR_OUT_OF_MEMORY; } @@ -116,20 +114,18 @@ static nsresult nsVertScrollbarConstructor (nsISupports *aOuter, REFNSIID aIID, nsresult rv; nsISupports *inst = nsnull; - if ( NULL == aResult ) + if ( nsnull == aResult ) { - rv = NS_ERROR_NULL_POINTER; - return rv; + return NS_ERROR_NULL_POINTER; } - *aResult = NULL; - if (NULL != aOuter) + *aResult = nsnull; + if (nsnull != aOuter) { - rv = NS_ERROR_NO_AGGREGATION; - return rv; + return NS_ERROR_NO_AGGREGATION; } inst = (nsISupports *)(nsBaseWidget *)(nsWidget *)new nsScrollbar(PR_TRUE); - if (inst == NULL) + if (inst == nsnull) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/widget/src/xlib/nsWindow.cpp b/mozilla/widget/src/xlib/nsWindow.cpp index 73fb036a0c0..f0ad4dddc24 100644 --- a/mozilla/widget/src/xlib/nsWindow.cpp +++ b/mozilla/widget/src/xlib/nsWindow.cpp @@ -43,6 +43,8 @@ #include "nsWindow.h" #include "xlibrgb.h" +#include "nsIRenderingContext.h" + /* for window title unicode->locale conversion */ #include "nsICharsetConverterManager.h" #include "nsIPlatformCharset.h" @@ -52,7 +54,7 @@ // Variables for grabbing PRBool nsWindow::sIsGrabbing = PR_FALSE; -nsWindow *nsWindow::sGrabWindow = NULL; +nsWindow *nsWindow::sGrabWindow = nsnull; // Routines implementing an update queue. // We keep a single queue for all widgets because it is @@ -235,7 +237,7 @@ nsWindow::~nsWindow() if (sGrabWindow == this) { sIsGrabbing = PR_FALSE; - sGrabWindow = NULL; + sGrabWindow = nsnull; } // Should get called from ~nsWidget() anyway. KenF @@ -348,13 +350,13 @@ NS_IMETHODIMP nsWindow::CaptureRollupEvents(nsIRollupListener * aListener, sIsGrabbing = PR_TRUE; sGrabWindow = this; - gRollupConsumeRollupEvent = PR_TRUE; + gRollupConsumeRollupEvent = PR_TRUE; gRollupListener = aListener; gRollupWidget = getter_AddRefs(NS_GetWeakReference(NS_STATIC_CAST(nsIWidget*, this))); }else{ // Release Grab if (sGrabWindow == this) - sGrabWindow = NULL; + sGrabWindow = nsnull; sIsGrabbing = PR_FALSE; @@ -520,9 +522,9 @@ NS_IMETHODIMP nsWindow::Resize(PRInt32 aX, /* virtual */ long nsWindow::GetEventMask() { - long event_mask; + long event_mask; - event_mask = + event_mask = ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | @@ -568,84 +570,97 @@ NS_IMETHODIMP nsWindow::Invalidate(const nsRect & aRect, PRBool aIsSynchronous) return NS_OK; } -NS_IMETHODIMP nsWindow::Update() +void +nsWindow::DoPaint (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, + nsIRegion *aClipRegion) +{ + if (mEventCallback) { + nsPaintEvent event; + nsRect rect(aX, aY, aWidth, aHeight); + event.message = NS_PAINT; + event.widget = this; + event.eventStructType = NS_PAINT_EVENT; + event.point.x = aX; + event.point.y = aY; + event.time = PR_Now(); /* No time in EXPOSE events */ + event.rect = ▭ + event.region = nsnull; + + event.renderingContext = GetRenderingContext(); + if (event.renderingContext) { + DispatchWindowEvent(event); + NS_RELEASE(event.renderingContext); + } + } +} + +NS_IMETHODIMP nsWindow::Update(void) { if (mIsUpdating) UnqueueDraw(); - nsPaintEvent pevent; - pevent.message = NS_PAINT; - pevent.eventStructType = NS_PAINT_EVENT; - pevent.rect = new nsRect (0,0,0,0); - pevent.time = 0; - pevent.region = mUpdateArea; - if (!mUpdateArea->IsEmpty()) { PRUint32 numRects; mUpdateArea->GetNumRects(&numRects); - if (numRects != 1 && numRects < 10) { + /* We paint the rects by themselves if we have 2 to 15 rects, + * otherwise we will just paint the bounding box. */ + if (numRects != 1 && numRects < 16) { nsRegionRectSet *regionRectSet = nsnull; - if (NS_FAILED(mUpdateArea->GetRects(®ionRectSet))) { - delete pevent.rect; + if (NS_FAILED(mUpdateArea->GetRects(®ionRectSet))) return NS_ERROR_FAILURE; - } PRUint32 len; PRUint32 i; - + len = regionRectSet->mRectsLen; - for (i=0; imRects[i]); - - pevent.widget = this; - pevent.rect->SetRect(r->x, r->y, r->width, r->height); - - pevent.time = PR_Now(); - AddRef(); - OnPaint(pevent); - Release(); + DoPaint (r->x, r->y, r->width, r->height, mUpdateArea); } + mUpdateArea->FreeRects(regionRectSet); - mUpdateArea->SetTo(0,0,0,0); - - delete pevent.rect; + + mUpdateArea->SetTo(0, 0, 0, 0); return NS_OK; } else { - PRInt32 x,y,w,h; - mUpdateArea->GetBoundingBox(&x,&y,&w,&h); - pevent.widget = this; - pevent.rect->SetRect(x,y,w,h); - AddRef(); - OnPaint(pevent); - Release(); - mUpdateArea->SetTo(0,0,0,0); + PRInt32 x, y, w, h; + mUpdateArea->GetBoundingBox(&x, &y, &w, &h); + DoPaint (x, y, w, h, mUpdateArea); + mUpdateArea->SetTo(0, 0, 0, 0); } - } - - delete pevent.rect; + } // The view manager also expects us to force our // children to update too! - nsCOMPtr children ( getter_AddRefs(GetChildren()) ); - if (children) - { - children->First(); - do - { - nsISupports* child; - if (NS_SUCCEEDED(children->CurrentItem(&child))) - { - nsWindow *childWindow = NS_STATIC_CAST(nsWindow*, NS_STATIC_CAST(nsIWidget*, child)); - NS_RELEASE(child); + nsCOMPtr children; - childWindow->Update(); + children = dont_AddRef(GetChildren()); + + if (children) { + nsCOMPtr isupp; + + nsCOMPtr child; + while (NS_SUCCEEDED(children->CurrentItem(getter_AddRefs(isupp))) && isupp) { + + child = do_QueryInterface(isupp); + + if (child) { + child->Update(); } - } while (NS_SUCCEEDED(children->Next())); + + if (NS_FAILED(children->Next())) { + break; + } + } } + + // While I'd think you should NS_RELEASE(aPaintEvent.widget) here, + // if you do, it is a NULL pointer. Not sure where it is getting + // released. return NS_OK; } @@ -754,7 +769,7 @@ NS_IMETHODIMP nsWindow::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) } } } - if (needToUpdate == PR_TRUE) + if (needToUpdate) Update(); } return NS_OK; @@ -817,7 +832,7 @@ NS_IMETHODIMP nsWindow::SetTitle(const nsString& aTitle) if (status == Success) { XSetWMProperties(mDisplay, mBaseWindow, - &prop, &prop, NULL, 0, NULL, NULL, NULL); + &prop, &prop, nsnull, 0, nsnull, nsnull, nsnull); if (prop.value) XFree(prop.value); @@ -840,3 +855,5 @@ ChildWindow::ChildWindow(): nsWindow() { mName.AssignWithConversion("nsChildWindow"); } + + diff --git a/mozilla/widget/src/xlib/nsWindow.h b/mozilla/widget/src/xlib/nsWindow.h index ebf6c980954..e07c4e630cc 100644 --- a/mozilla/widget/src/xlib/nsWindow.h +++ b/mozilla/widget/src/xlib/nsWindow.h @@ -94,7 +94,7 @@ class nsWindow : public nsWidget PRBool aConsumeRollupEvent); NS_IMETHOD Invalidate(PRBool aIsSynchronous); NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous); - NS_IMETHOD InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSynchronous); + NS_IMETHOD InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSynchronous); NS_IMETHOD Update(); NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect); NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy); @@ -123,6 +123,9 @@ protected: // Keyboard and Pointer Grabbing void NativeGrab(PRBool aGrab); + void DoPaint (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, + nsIRegion *aClipRegion); + void QueueDraw(); void UnqueueDraw(); PRBool mIsUpdating; diff --git a/mozilla/widget/src/xlib/nsXUtils.cpp b/mozilla/widget/src/xlib/nsXUtils.cpp index 363fcbbbe7b..9d6498b032d 100644 --- a/mozilla/widget/src/xlib/nsXUtils.cpp +++ b/mozilla/widget/src/xlib/nsXUtils.cpp @@ -91,7 +91,7 @@ nsXUtils::XFlashWindow(Display * aDisplay, memset(&gcv, 0, sizeof(XGCValues)); gcv.function = GXxor; - gcv.foreground = WhitePixel(aDisplay, DefaultScreen(aDisplay)); + gcv.foreground = XWhitePixel(aDisplay, XDefaultScreen(aDisplay)); gcv.subwindow_mode = IncludeInferiors; if (gcv.foreground == 0) diff --git a/mozilla/widget/src/xlib/window_service/nsIXlibWindowService.h b/mozilla/widget/src/xlib/window_service/nsIXlibWindowService.h index a583cad0520..47eb7c06086 100644 --- a/mozilla/widget/src/xlib/window_service/nsIXlibWindowService.h +++ b/mozilla/widget/src/xlib/window_service/nsIXlibWindowService.h @@ -27,6 +27,7 @@ #include #include +#include // Interface id for the XlibWindow service // { bd39ccb0-3f08-11d3-b419-00805f6d4c2a } @@ -54,7 +55,7 @@ typedef void (*nsXlibEventDispatcher)(nsXlibNativeEvent aNativeEvent); typedef int (*nsXlibTimeToNextTimeoutFunc)(struct timeval *aTimer); -typedef void (*nsXlibProcessTimeoutsProc)(Display *aDisplay); +typedef void (*nsXlibProcessTimeoutsProc)(XtAppContext app_context); class nsIXlibWindowService : public nsISupports { diff --git a/mozilla/widget/src/xlib/window_service/nsXlibWindowServiceFactory.cpp b/mozilla/widget/src/xlib/window_service/nsXlibWindowServiceFactory.cpp index ddea1e87edd..24a62c3e096 100644 --- a/mozilla/widget/src/xlib/window_service/nsXlibWindowServiceFactory.cpp +++ b/mozilla/widget/src/xlib/window_service/nsXlibWindowServiceFactory.cpp @@ -82,7 +82,7 @@ nsXlibWindowServiceFactory::CreateInstance(nsISupports *aOuter, return NS_ERROR_OUT_OF_MEMORY; nsresult rv = inst->QueryInterface(aIID, aResult); - if (rv != NS_OK) + if (NS_FAILED(rv)) delete inst; return rv; } diff --git a/mozilla/widget/timer/src/unix/xlib/Makefile.in b/mozilla/widget/timer/src/unix/xlib/Makefile.in index e449f848509..cfc22fed64c 100644 --- a/mozilla/widget/timer/src/unix/xlib/Makefile.in +++ b/mozilla/widget/timer/src/unix/xlib/Makefile.in @@ -49,5 +49,7 @@ endif include $(topsrcdir)/config/rules.mk +EXTRA_DSO_LDOPTS += -lXt + INCLUDES += $(MOZ_XLIB_CFLAGS) -I$(srcdir)/.. diff --git a/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.cpp b/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.cpp index bd485fd0fca..a46b4af5563 100644 --- a/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.cpp +++ b/mozilla/widget/timer/src/unix/xlib/nsTimerXlib.cpp @@ -20,7 +20,8 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Tony Tsui + * Tony Tsui + * Roland Mainz * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -52,7 +53,7 @@ static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); static int NS_TimeToNextTimeout(struct timeval *aTimer); -static void NS_ProcessTimeouts(Display *aDisplay); +static void NS_ProcessTimeouts(XtAppContext app_context); nsVoidArray *nsTimerXlib::gHighestList = (nsVoidArray *)nsnull; nsVoidArray *nsTimerXlib::gHighList = (nsVoidArray *)nsnull; @@ -69,10 +70,10 @@ nsTimerXlib::nsTimerXlib() #endif NS_INIT_REFCNT(); - mFunc = NULL; - mCallback = NULL; + mFunc = nsnull; + mCallback = nsnull; mDelay = 0; - mClosure = NULL; + mClosure = nsnull; mPriority = 0; mType = NS_TYPE_ONE_SHOT; } @@ -146,7 +147,7 @@ nsTimerXlib::Init(PRUint32 aDelay, PRUint32 aPriority) mPriority = aPriority; // get the cuurent time - gettimeofday(&Now, NULL); + gettimeofday(&Now, nsnull); mFireTime.tv_sec = Now.tv_sec + (aDelay / 1000); mFireTime.tv_usec = Now.tv_usec + ((aDelay%1000) * 1000); @@ -205,17 +206,17 @@ nsTimerXlib::Fire() #endif timeval aNow; - gettimeofday(&aNow, NULL); + gettimeofday(&aNow, nsnull); #ifdef TIMER_DEBUG fprintf(stderr, "nsTimerXlib::Fire (%p) called at %ld / %ld\n", this, aNow.tv_sec, aNow.tv_usec); #endif - if (mFunc != NULL) { + if (mFunc != nsnull) { (*mFunc)(this, mClosure); } - else if (mCallback != NULL) { + else if (mCallback != nsnull) { mCallback->Notify(this); } @@ -225,7 +226,6 @@ nsTimerXlib::Fire() void nsTimerXlib::Cancel() { - switch(mPriority) { case NS_PRIORITY_HIGHEST: @@ -253,54 +253,56 @@ nsTimerXlib::ProcessTimeouts(nsVoidArray *array) if (count == 0) return; - - nsTimerXlib *timer; - + struct timeval aNow; struct timeval ntv; int res; - gettimeofday(&aNow, NULL); + gettimeofday(&aNow, nsnull); #ifdef TIMER_DEBUG fprintf(stderr, "nsTimerXlib::ProcessTimeouts called at %ld / %ld\n", aNow.tv_sec, aNow.tv_usec); #endif + nsCOMPtr timer; + for (int i = count; i >=0; i--) { - timer = (nsTimerXlib*)array->ElementAt(i); + /* Make sure that the timer cannot be deleted during the + * Fire(...) call which may release *all* other references + * to p... + */ + timer = NS_STATIC_CAST(nsTimerXlib *, array->ElementAt(i)); if (timer) { - if ((timer->mFireTime.tv_sec < aNow.tv_sec) || ((timer->mFireTime.tv_sec == aNow.tv_sec) && (timer->mFireTime.tv_usec <= aNow.tv_usec))) { - // Make sure that the timer cannot be deleted during the - // Fire(...) call which may release *all* other references - // to p... #ifdef TIMER_DEBUG fprintf(stderr, "Firing timeout for (%p)\n", timer); -#endif -// NS_ADDREF(timer); //FIXME: Does this still apply??? TonyT - +#endif res = timer->Fire(); if (res == 0) { array->RemoveElement(timer); -// NS_RELEASE(timer); //FIXME: Ditto to above. } else { - gettimeofday(&ntv, NULL); + gettimeofday(&ntv, nsnull); timer->mFireTime.tv_sec = ntv.tv_sec + (timer->mDelay / 1000); timer->mFireTime.tv_usec = ntv.tv_usec + ((timer->mDelay%1000) * 1000); } } } + + /* force destruction of timers (via nsCOMPtr magic) which do not + * have other references anymore ! + */ + timer = nsnull; } } @@ -332,9 +334,9 @@ nsTimerXlib::EnsureWindowService() kWindowServiceIID, (nsISupports **)&xlibWindowService); - NS_ASSERTION(NS_SUCCEEDED(rv),"Couldn't obtain window service."); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't obtain window service."); - if (NS_OK == rv && nsnull != xlibWindowService) + if (NS_SUCCEEDED(rv) && (nsnull != xlibWindowService)) { xlibWindowService->SetTimeToNextTimeoutFunc(NS_TimeToNextTimeout); xlibWindowService->SetProcessTimeoutsProc(NS_ProcessTimeouts); @@ -348,6 +350,7 @@ nsTimerXlib::EnsureWindowService() static int NS_TimeToNextTimeout(struct timeval *aTimer) { +#ifdef DEBUG static int once = 1; if (once) @@ -356,6 +359,7 @@ int NS_TimeToNextTimeout(struct timeval *aTimer) printf("NS_TimeToNextTimeout() lives!\n"); } +#endif /* DEBUG */ nsTimerXlib *timer; @@ -376,7 +380,7 @@ int NS_TimeToNextTimeout(struct timeval *aTimer) if (nsTimerXlib::gLowestList->Count() > 0) timer = (nsTimerXlib*)nsTimerXlib::gLowestList->ElementAt(0); else - timer = NULL; + timer = nsnull; if (timer) { if ((timer->mFireTime.tv_sec < aTimer->tv_sec) || @@ -411,8 +415,9 @@ int NS_TimeToNextTimeout(struct timeval *aTimer) static void -NS_ProcessTimeouts(Display *aDisplay) +NS_ProcessTimeouts(XtAppContext app_context) { +#ifdef DEBUG static int once = 1; if (once) @@ -421,14 +426,16 @@ NS_ProcessTimeouts(Display *aDisplay) printf("NS_ProcessTimeouts() lives!\n"); } +#endif /* DEBUG */ nsTimerXlib::gProcessingTimer = PR_TRUE; nsTimerXlib::ProcessTimeouts(nsTimerXlib::gHighestList); nsTimerXlib::ProcessTimeouts(nsTimerXlib::gHighList); nsTimerXlib::ProcessTimeouts(nsTimerXlib::gNormalList); - - if (XPending(aDisplay) == 0) + + /* no X events anymore ? then crawl the low priority timers ... */ + if ((XtAppPending(app_context) & XtIMXEvent) == 0) { #ifdef TIMER_DEBUG fprintf(stderr, "\n Handling Low Priority Stuff!!! Display is 0x%x\n", aDisplay);