diff --git a/mozilla/widget/src/xlib/nsAppShell.cpp b/mozilla/widget/src/xlib/nsAppShell.cpp index 47c8952093f..157e5e77baf 100644 --- a/mozilla/widget/src/xlib/nsAppShell.cpp +++ b/mozilla/widget/src/xlib/nsAppShell.cpp @@ -25,6 +25,31 @@ #include "nsIServiceManager.h" #include "nsITimer.h" +Display *gDisplay; +Screen *gScreen; +int gScreenNum; +int gDepth; +Visual *gVisual; +XVisualInfo *gVisualInfo; + +PRUint32 gRedZeroMask; //red color mask in zero position +PRUint32 gGreenZeroMask; //green color mask in zero position +PRUint32 gBlueZeroMask; //blue color mask in zero position +PRUint32 gAlphaZeroMask; //alpha data mask in zero position +PRUint32 gRedMask; //red color mask +PRUint32 gGreenMask; //green color mask +PRUint32 gBlueMask; //blue color mask +PRUint32 gAlphaMask; //alpha data mask +PRUint8 gRedCount; //number of red color bits +PRUint8 gGreenCount; //number of green color bits +PRUint8 gBlueCount; //number of blue color bits +PRUint8 gAlphaCount; //number of alpha data bits +PRUint8 gRedShift; //number to shift value into red position +PRUint8 gGreenShift; //number to shift value into green position +PRUint8 gBlueShift; //number to shift value into blue position +PRUint8 gAlphaShift; //number to shift value into alpha position + + static PRUint8 convertMaskToCount(unsigned long val); static PRUint8 getShiftForMask(unsigned long val); diff --git a/mozilla/widget/src/xlib/nsButton.cpp b/mozilla/widget/src/xlib/nsButton.cpp index 2e8c354111b..ef6273649b8 100644 --- a/mozilla/widget/src/xlib/nsButton.cpp +++ b/mozilla/widget/src/xlib/nsButton.cpp @@ -24,6 +24,7 @@ NS_IMPL_RELEASE(nsButton) nsButton::nsButton() : nsWidget() , nsIButton() { NS_INIT_REFCNT(); + name = "nsButton"; } nsButton::~nsButton() diff --git a/mozilla/widget/src/xlib/nsTextWidget.cpp b/mozilla/widget/src/xlib/nsTextWidget.cpp index 211ff779dcc..557fc9f3065 100644 --- a/mozilla/widget/src/xlib/nsTextWidget.cpp +++ b/mozilla/widget/src/xlib/nsTextWidget.cpp @@ -24,6 +24,7 @@ NS_IMPL_RELEASE(nsTextWidget) nsTextWidget::nsTextWidget() : nsTextHelper() { NS_INIT_REFCNT(); + name = "nsTextWidget"; } nsTextWidget::~nsTextWidget() diff --git a/mozilla/widget/src/xlib/nsWidget.cpp b/mozilla/widget/src/xlib/nsWidget.cpp index 27eea9f9097..13ac878eeb6 100644 --- a/mozilla/widget/src/xlib/nsWidget.cpp +++ b/mozilla/widget/src/xlib/nsWidget.cpp @@ -18,48 +18,22 @@ #include "nsWidget.h" -Display *gDisplay; -Screen *gScreen; -int gScreenNum; -int gDepth; -Visual *gVisual; -XVisualInfo *gVisualInfo; - -PRUint32 gRedZeroMask; //red color mask in zero position -PRUint32 gGreenZeroMask; //green color mask in zero position -PRUint32 gBlueZeroMask; //blue color mask in zero position -PRUint32 gAlphaZeroMask; //alpha data mask in zero position -PRUint32 gRedMask; //red color mask -PRUint32 gGreenMask; //green color mask -PRUint32 gBlueMask; //blue color mask -PRUint32 gAlphaMask; //alpha data mask -PRUint8 gRedCount; //number of red color bits -PRUint8 gGreenCount; //number of green color bits -PRUint8 gBlueCount; //number of blue color bits -PRUint8 gAlphaCount; //number of alpha data bits -PRUint8 gRedShift; //number to shift value into red position -PRUint8 gGreenShift; //number to shift value into green position -PRUint8 gBlueShift; //number to shift value into blue position -PRUint8 gAlphaShift; //number to shift value into alpha position - -extern "C" -unsigned long -xlib_rgb_xpixel_from_rgb (unsigned int rgb); - nsWidget::nsWidget() : nsBaseWidget() { mPreferredWidth = 0; mPreferredHeight = 0; - mWindow = 0; + mBaseWindow = 0; bg_rgb = NS_RGB(192,192,192); bg_pixel = xlib_rgb_xpixel_from_rgb(bg_rgb); mGC = 0; + parentWidget = nsnull; + name = "unnamed"; } nsWidget::~nsWidget() { XFreeGC(gDisplay, mGC); - XDestroyWindow(gDisplay, mWindow); + XDestroyWindow(gDisplay, mBaseWindow); } NS_IMETHODIMP nsWidget::Create(nsIWidget *aParent, @@ -70,7 +44,8 @@ NS_IMETHODIMP nsWidget::Create(nsIWidget *aParent, nsIToolkit *aToolkit, nsWidgetInitData *aInitData) { - return(StandardWindowCreate(aParent, aRect, aHandleEventFunction, + parentWidget = aParent; + return(StandardWidgetCreate(aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData, nsnull)); } @@ -83,13 +58,13 @@ NS_IMETHODIMP nsWidget::Create(nsNativeWidget aParent, nsIToolkit *aToolkit, nsWidgetInitData *aInitData) { - return(StandardWindowCreate(nsnull, aRect, aHandleEventFunction, + return(StandardWidgetCreate(nsnull, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData, aParent)); } nsresult -nsWidget::StandardWindowCreate(nsIWidget *aParent, +nsWidget::StandardWidgetCreate(nsIWidget *aParent, const nsRect &aRect, EVENT_CALLBACK aHandleEventFunction, nsIDeviceContext *aContext, @@ -99,15 +74,11 @@ nsWidget::StandardWindowCreate(nsIWidget *aParent, nsNativeWidget aNativeParent) { - XSetWindowAttributes attr; - unsigned long attr_mask; Window parent; - int width; - int height; - + // set up the BaseWidget parts. BaseCreate(aParent, aRect, aHandleEventFunction, aContext, - aAppShell, aToolkit, aInitData); + aAppShell, aToolkit, aInitData); // check to see if the parent is there... if (nsnull != aParent) { parent = ((aParent) ? (Window)aParent->GetNativeData(NS_NATIVE_WINDOW) : nsnull); @@ -120,50 +91,12 @@ nsWidget::StandardWindowCreate(nsIWidget *aParent, } // set the bounds mBounds = aRect; - // on a window resize, we don't want to window contents to - // be discarded... - attr.bit_gravity = NorthWestGravity; - // make sure that we listen for events - attr.event_mask = SubstructureNotifyMask | StructureNotifyMask | ExposureMask; - // set the default background color to that awful gray - attr.background_pixel = bg_pixel; - // here's what's in the struct - attr_mask = CWBitGravity | CWEventMask | CWBackPixel; - - printf("Creating XWindow: x %d y %d w %d h %d\n", - aRect.x, aRect.y, aRect.width, aRect.height); - if (aRect.width == 0) { - printf("*** Fixing width...\n"); - width = 1; - } - else { - width = aRect.width; - } - if (aRect.height == 0) { - printf("*** Fixing height...\n"); - height = 1; - } - else { - height = aRect.height; - } - - mWindow = XCreateWindow(gDisplay, - parent, - aRect.x, aRect.y, - width, height, - 0, // border width - gDepth, - InputOutput, // class - CopyFromParent, // visual - attr_mask, - &attr); - // map this window and flush the connection. we want to see this - // thing now. - XMapWindow(gDisplay, - mWindow); - XSync(gDisplay, False); + // call the native create function + CreateNative(parent, mBounds); // set up the GC for this window. - mGC = XCreateGC(gDisplay, mWindow, 0, NULL); + if (!mBaseWindow) + printf("*** warning: this is about to fail...\n"); + mGC = XCreateGC(gDisplay, mBaseWindow, 0, NULL); XSync(gDisplay, False); return NS_OK; } @@ -234,7 +167,7 @@ void * nsWidget::GetNativeData(PRUint32 aDataType) switch (aDataType) { case NS_NATIVE_WIDGET: case NS_NATIVE_WINDOW: - return (void *)mWindow; + return (void *)mBaseWindow; break; case NS_NATIVE_DISPLAY: return (void *)gDisplay; @@ -326,7 +259,7 @@ NS_IMETHODIMP nsWidget::SetBackgroundColor(const nscolor &aColor) NS_GET_B(aColor)); bg_pixel = xlib_rgb_xpixel_from_rgb(bg_rgb); // set the window attrib - XSetWindowBackground(gDisplay, mWindow, bg_pixel); + XSetWindowBackground(gDisplay, mBaseWindow, bg_pixel); return NS_OK; } @@ -356,3 +289,58 @@ nsIWidget *nsWidget::GetParent(void) { return nsnull; } + +void nsWidget::CreateNative(Window aParent, nsRect aRect) +{ + XSetWindowAttributes attr; + unsigned long attr_mask; + int width; + int height; + + printf("*** Warning: nsWidget::CreateNative falling back to sane default for widget type \"%s\"\n", name); + if (!strcmp(name, "unnamed")) { + printf("What freaking widget is this, anyway?\n"); + } + // on a window resize, we don't want to window contents to + // be discarded... + attr.bit_gravity = NorthWestGravity; + // make sure that we listen for events + attr.event_mask = SubstructureNotifyMask | StructureNotifyMask | ExposureMask; + // set the default background color to that awful gray + attr.background_pixel = bg_pixel; + // here's what's in the struct + attr_mask = CWBitGravity | CWEventMask | CWBackPixel; + + printf("Creating XWindow: x %d y %d w %d h %d\n", + aRect.x, aRect.y, aRect.width, aRect.height); + if (aRect.width == 0) { + printf("*** Fixing width...\n"); + width = 1; + } + else { + width = aRect.width; + } + if (aRect.height == 0) { + printf("*** Fixing height...\n"); + height = 1; + } + else { + height = aRect.height; + } + + mBaseWindow = XCreateWindow(gDisplay, + aParent, + aRect.x, aRect.y, + width, height, + 0, // border width + gDepth, + InputOutput, // class + CopyFromParent, // visual + attr_mask, + &attr); + // map this window and flush the connection. we want to see this + // thing now. + XMapWindow(gDisplay, + mBaseWindow); + XSync(gDisplay, False); +} diff --git a/mozilla/widget/src/xlib/nsWidget.h b/mozilla/widget/src/xlib/nsWidget.h index 72fdd389806..746128c31c2 100644 --- a/mozilla/widget/src/xlib/nsWidget.h +++ b/mozilla/widget/src/xlib/nsWidget.h @@ -46,7 +46,7 @@ public: nsIToolkit *aToolkit = nsnull, nsWidgetInitData *aInitData = nsnull); - virtual nsresult StandardWindowCreate(nsIWidget *aParent, + virtual nsresult StandardWidgetCreate(nsIWidget *aParent, const nsRect &aRect, EVENT_CALLBACK aHandleEventFunction, nsIDeviceContext *aContext, @@ -95,12 +95,17 @@ public: NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus); protected: - PRUint32 mPreferredWidth; - PRUint32 mPreferredHeight; - Window mWindow; + virtual void CreateNative(Window aParent, nsRect aRect); + PRUint32 mPreferredWidth; + PRUint32 mPreferredHeight; + nsIWidget *parentWidget; + + // All widgets have at least these items. + Window mBaseWindow; PRUint32 bg_rgb; unsigned long bg_pixel; GC mGC; // until we get gc pooling working... + const char *name; // name of the type of widget }; extern Display *gDisplay; @@ -127,5 +132,11 @@ extern PRUint8 gGreenShift; //number to shift value into green position extern PRUint8 gBlueShift; //number to shift value into blue position extern PRUint8 gAlphaShift; //number to shift value into alpha position +// this is from the xlibrgb code. + +extern "C" +unsigned long +xlib_rgb_xpixel_from_rgb (unsigned int rgb); + #endif diff --git a/mozilla/widget/src/xlib/nsWindow.cpp b/mozilla/widget/src/xlib/nsWindow.cpp index 4ac259c8ca7..c946b04c3b4 100644 --- a/mozilla/widget/src/xlib/nsWindow.cpp +++ b/mozilla/widget/src/xlib/nsWindow.cpp @@ -18,15 +18,69 @@ #include "nsWindow.h" -nsWindow::nsWindow() +nsWindow::nsWindow() : nsWidget() { - + NS_INIT_REFCNT(); + name = "nsWindow"; } nsWindow::~nsWindow() { } -ChildWindow::ChildWindow() +void +nsWindow::CreateNative(Window aParent, nsRect aRect) { + XSetWindowAttributes attr; + unsigned long attr_mask; + int width; + int height; + // on a window resize, we don't want to window contents to + // be discarded... + attr.bit_gravity = NorthWestGravity; + // make sure that we listen for events + attr.event_mask = SubstructureNotifyMask | StructureNotifyMask | ExposureMask; + // set the default background color to that awful gray + attr.background_pixel = bg_pixel; + // here's what's in the struct + attr_mask = CWBitGravity | CWEventMask | CWBackPixel; + + printf("Creating XWindow: x %d y %d w %d h %d\n", + aRect.x, aRect.y, aRect.width, aRect.height); + if (aRect.width == 0) { + printf("*** Fixing width...\n"); + width = 1; + } + else { + width = aRect.width; + } + if (aRect.height == 0) { + printf("*** Fixing height...\n"); + height = 1; + } + else { + height = aRect.height; + } + + mBaseWindow = XCreateWindow(gDisplay, + aParent, + aRect.x, aRect.y, + width, height, + 0, // border width + gDepth, + InputOutput, // class + CopyFromParent, // visual + attr_mask, + &attr); + // map this window and flush the connection. we want to see this + // thing now. + XMapWindow(gDisplay, + mBaseWindow); + XSync(gDisplay, False); + +} + +ChildWindow::ChildWindow(): nsWindow() +{ + name = "nsChildWindow"; } diff --git a/mozilla/widget/src/xlib/nsWindow.h b/mozilla/widget/src/xlib/nsWindow.h index 1d6748d9186..d2739b5fb22 100644 --- a/mozilla/widget/src/xlib/nsWindow.h +++ b/mozilla/widget/src/xlib/nsWindow.h @@ -26,6 +26,8 @@ class nsWindow : public nsWidget public: nsWindow(); ~nsWindow(); +protected: + void CreateNative(Window aParent, nsRect aRect); }; class ChildWindow : public nsWindow