Cleanup the widget api some. Move initialization of evil stuff to the gfx

end.  Dont leak the widget name.  Carry around Display* and friends in the
appshell.
This commit is contained in:
ramiro%netscape.com 1999-07-06 23:28:58 +00:00
Родитель 606004f808
Коммит b9d9e64b07
8 изменённых файлов: 172 добавлений и 127 удалений

Просмотреть файл

@ -34,6 +34,10 @@ static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
static PRLogModuleInfo *DeviceContextXlibLM = PR_NewLogModule("DeviceContextXlib");
static PRUint8 _ConvertMaskToCount(unsigned long val);
static PRUint8 _GetShiftForMask(unsigned long val);
static void _EvilInitilizeGlobals();
nsDeviceContextXlib::nsDeviceContextXlib()
: DeviceContextImpl()
{
@ -65,6 +69,25 @@ extern Display * gDisplay;
extern Screen * gScreen;
extern Visual * gVisual;
extern int gDepth;
extern XVisualInfo *gVisualInfo;
extern PRUint32 gRedZeroMask; //red color mask in zero position
extern PRUint32 gGreenZeroMask; //green color mask in zero position
extern PRUint32 gBlueZeroMask; //blue color mask in zero position
extern PRUint32 gAlphaZeroMask; //alpha data mask in zero position
extern PRUint32 gRedMask; //red color mask
extern PRUint32 gGreenMask; //green color mask
extern PRUint32 gBlueMask; //blue color mask
extern PRUint32 gAlphaMask; //alpha data mask
extern PRUint8 gRedCount; //number of red color bits
extern PRUint8 gGreenCount; //number of green color bits
extern PRUint8 gBlueCount; //number of blue color bits
extern PRUint8 gAlphaCount; //number of alpha data bits
extern PRUint8 gRedShift; //number to shift value into red position
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
NS_IMETHODIMP nsDeviceContextXlib::Init(nsNativeWidget aNativeWidget)
{
@ -78,11 +101,21 @@ NS_IMETHODIMP nsDeviceContextXlib::Init(nsNativeWidget aNativeWidget)
mVisual = gVisual;
mDepth = gDepth;
printf("nsDeviceContextXlib::Init(dpy=%p screen=%p visual=%p depth=%d)\n",
mDisplay,
mScreen,
mVisual,
mDepth);
static PRBool firstTime = TRUE;
if (firstTime)
{
firstTime = PR_FALSE;
_EvilInitilizeGlobals();
printf("nsDeviceContextXlib::Init(dpy=%p screen=%p visual=%p depth=%d)\n",
mDisplay,
mScreen,
mVisual,
mDepth);
}
CommonInit();
@ -397,3 +430,52 @@ NS_IMETHODIMP nsDeviceContextXlib::EndPage(void)
PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::EndPage()\n"));
return NS_OK;
}
static void _EvilInitilizeGlobals()
{
// set up the color info for this display
// set up the masks
gRedMask = gVisualInfo->red_mask;
gGreenMask = gVisualInfo->green_mask;
gBlueMask = gVisualInfo->blue_mask;
gAlphaMask = 0;
// set up the number of bits in each
gRedCount = _ConvertMaskToCount(gVisualInfo->red_mask);
gGreenCount = _ConvertMaskToCount(gVisualInfo->green_mask);
gBlueCount = _ConvertMaskToCount(gVisualInfo->blue_mask);
gAlphaCount = 0;
// set up the number of bits that you need to shift to get to
// a specific mask
gRedShift = _GetShiftForMask(gVisualInfo->red_mask);
gGreenShift = _GetShiftForMask(gVisualInfo->green_mask);
gBlueShift = _GetShiftForMask(gVisualInfo->blue_mask);
gAlphaShift = 0;
}
static PRUint8 _ConvertMaskToCount(unsigned long val)
{
PRUint8 retval = 0;
PRUint8 cur_bit = 0;
// walk through the number, incrementing the value if
// the bit in question is set.
while (cur_bit < (sizeof(unsigned long) * 8)) {
if ((val >> cur_bit) & 0x1) {
retval++;
}
cur_bit++;
}
return retval;
}
static PRUint8 _GetShiftForMask(unsigned long val)
{
PRUint8 cur_bit = 0;
// walk through the number, looking for the first 1
while (cur_bit < (sizeof(unsigned long) * 8)) {
if ((val >> cur_bit) & 0x1) {
return cur_bit;
}
cur_bit++;
}
return cur_bit;
}

Просмотреть файл

@ -150,23 +150,7 @@ NS_METHOD nsAppShell::Create(int* argc, char ** argv)
}
// get the depth for this display
gDepth = gVisualInfo->depth;
// set up the color info for this display
// set up the masks
gRedMask = gVisualInfo->red_mask;
gGreenMask = gVisualInfo->green_mask;
gBlueMask = gVisualInfo->blue_mask;
gAlphaMask = 0;
// set up the number of bits in each
gRedCount = convertMaskToCount(gVisualInfo->red_mask);
gGreenCount = convertMaskToCount(gVisualInfo->green_mask);
gBlueCount = convertMaskToCount(gVisualInfo->blue_mask);
gAlphaCount = 0;
// set up the number of bits that you need to shift to get to
// a specific mask
gRedShift = getShiftForMask(gVisualInfo->red_mask);
gGreenShift = getShiftForMask(gVisualInfo->green_mask);
gBlueShift = getShiftForMask(gVisualInfo->blue_mask);
gAlphaShift = 0;
return NS_OK;
}
@ -316,7 +300,7 @@ void
nsAppShell::DispatchEvent(XEvent *event)
{
nsWidget *widget;
widget = nsWidget::getWidgetForWindow(event->xany.window);
widget = nsWidget::GetWidgetForWindow(event->xany.window);
// switch on the type of event
switch (event->type) {
case Expose:
@ -448,31 +432,3 @@ nsAppShell::HandleConfigureNotifyEvent(XEvent *event, nsWidget *aWidget)
NS_RELEASE(aWidget);
delete sevent.windowSize;
}
static PRUint8 convertMaskToCount(unsigned long val)
{
PRUint8 retval = 0;
PRUint8 cur_bit = 0;
// walk through the number, incrementing the value if
// the bit in question is set.
while (cur_bit < (sizeof(unsigned long) * 8)) {
if ((val >> cur_bit) & 0x1) {
retval++;
}
cur_bit++;
}
return retval;
}
static PRUint8 getShiftForMask(unsigned long val)
{
PRUint8 cur_bit = 0;
// walk through the number, looking for the first 1
while (cur_bit < (sizeof(unsigned long) * 8)) {
if ((val >> cur_bit) & 0x1) {
return cur_bit;
}
cur_bit++;
}
return cur_bit;
}

Просмотреть файл

@ -24,7 +24,7 @@ NS_IMPL_RELEASE(nsButton)
nsButton::nsButton() : nsWidget() , nsIButton()
{
NS_INIT_REFCNT();
name = "nsButton";
mName = "nsButton";
}
nsButton::~nsButton()

Просмотреть файл

@ -31,8 +31,8 @@ nsScrollbar::nsScrollbar(PRBool aIsVertical) : nsWidget(), nsIScrollbar()
mLineIncrement = 1;
mIsVertical = aIsVertical;
mBackground = NS_RGB(100,100,100);
bg_pixel = xlib_rgb_xpixel_from_rgb(mBackground);
border_pixel = xlib_rgb_xpixel_from_rgb(mBackground);
mBackgroundPixel = xlib_rgb_xpixel_from_rgb(mBackground);
mBorderPixel = xlib_rgb_xpixel_from_rgb(mBackground);
mBar = 0;
mBarBounds.x = mBarBounds.y = mBarBounds.width = mBarBounds.height = 0;
};
@ -40,7 +40,7 @@ nsScrollbar::nsScrollbar(PRBool aIsVertical) : nsWidget(), nsIScrollbar()
nsScrollbar::~nsScrollbar()
{
if (mBar) {
XDestroyWindow(gDisplay, mBar);
XDestroyWindow(mDisplay, mBar);
DeleteWindowCallback(mBar);
}
}
@ -213,8 +213,8 @@ void nsScrollbar::CreateNative(Window aParent, nsRect aRect)
// make sure that we listen for events
attr.event_mask = StructureNotifyMask | ButtonPressMask | ButtonReleaseMask;
// set the default background color and border to that awful gray
attr.background_pixel = bg_pixel;
attr.border_pixel = border_pixel;
attr.background_pixel = mBackgroundPixel;
attr.border_pixel = mBorderPixel;
// set the colormap
attr.colormap = xlib_rgb_get_cmap();
// here's what's in the struct
@ -231,14 +231,14 @@ void nsScrollbar::CreateNative(Window aParent, nsRect aRect)
attr.border_pixel = xlib_rgb_xpixel_from_rgb(NS_RGB(100,100,100));
// set up the size
CalcBarBounds();
mBar = XCreateWindow(gDisplay,
mBar = XCreateWindow(mDisplay,
mBaseWindow,
mBarBounds.x, mBarBounds.y,
mBarBounds.width, mBarBounds.height,
2, // border width
gDepth,
InputOutput,
gVisual,
mVisual,
attr_mask,
&attr);
AddWindowCallback(mBar, this);
@ -248,7 +248,7 @@ NS_IMETHODIMP nsScrollbar::Show(PRBool bState)
{
nsWidget::Show(bState);
if (mBar) {
XMapWindow(gDisplay, mBar);
XMapWindow(mDisplay, mBar);
}
CalcBarBounds();
LayoutBar();
@ -376,7 +376,7 @@ void nsScrollbar::CalcBarBounds(void)
void nsScrollbar::LayoutBar(void)
{
XMoveResizeWindow(gDisplay, mBar,
XMoveResizeWindow(mDisplay, mBar,
mBarBounds.x, mBarBounds.y,
mBarBounds.width, mBarBounds.height);
}

Просмотреть файл

@ -24,7 +24,7 @@ NS_IMPL_RELEASE(nsTextWidget)
nsTextWidget::nsTextWidget() : nsTextHelper()
{
NS_INIT_REFCNT();
name = "nsTextWidget";
mName = "nsTextWidget";
}
nsTextWidget::~nsTextWidget()

Просмотреть файл

@ -51,14 +51,19 @@ nsWidget::nsWidget() : nsBaseWidget()
{
mPreferredWidth = 0;
mPreferredHeight = 0;
mDisplay = 0;
mScreen = 0;
mVisual = 0;
mBaseWindow = 0;
mBackground = NS_RGB(192, 192, 192);
bg_pixel = xlib_rgb_xpixel_from_rgb(mBackground);
mBackgroundPixel = xlib_rgb_xpixel_from_rgb(mBackground);
mBackground = NS_RGB(192, 192, 192);
border_pixel = xlib_rgb_xpixel_from_rgb(border_rgb);
mBorderPixel = xlib_rgb_xpixel_from_rgb(mBorderRGB);
mGC = 0;
parentWidget = nsnull;
name = "unnamed";
mParentWidget = nsnull;
mName = "unnamed";
}
nsWidget::~nsWidget()
@ -70,9 +75,10 @@ void
nsWidget::DestroyNative(void)
{
if (mGC)
XFreeGC(gDisplay, mGC);
XFreeGC(mDisplay, mGC);
if (mBaseWindow) {
XDestroyWindow(gDisplay, mBaseWindow);
XDestroyWindow(mDisplay, mBaseWindow);
DeleteWindowCallback(mBaseWindow);
}
}
@ -85,7 +91,8 @@ NS_IMETHODIMP nsWidget::Create(nsIWidget *aParent,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
parentWidget = aParent;
mParentWidget = aParent;
return(StandardWidgetCreate(aParent, aRect, aHandleEventFunction,
aContext, aAppShell, aToolkit, aInitData,
nsnull));
@ -117,6 +124,10 @@ nsWidget::StandardWidgetCreate(nsIWidget *aParent,
Window parent;
mDisplay = gDisplay;
mScreen = gScreen;
mVisual = gVisual;
// set up the BaseWidget parts.
BaseCreate(aParent, aRect, aHandleEventFunction, aContext,
aAppShell, aToolkit, aInitData);
@ -128,13 +139,13 @@ nsWidget::StandardWidgetCreate(nsIWidget *aParent,
}
// if there's no parent, make the parent the root window.
if (parent == 0) {
parent = RootWindow(gDisplay, gScreenNum);
parent = RootWindowOfScreen(mScreen);
}
// set the bounds
mBounds = aRect;
// call the native create function
CreateNative(parent, mBounds);
XSync(gDisplay, False);
XSync(mDisplay, False);
return NS_OK;
}
@ -155,7 +166,7 @@ NS_IMETHODIMP nsWidget::Move(PRUint32 aX, PRUint32 aY)
aY = 0;
}
printf("Moving window 0x%lx to %d, %d\n", mBaseWindow, aX, aY);
XMoveWindow(gDisplay, mBaseWindow, aX, aY);
XMoveWindow(mDisplay, mBaseWindow, aX, aY);
return NS_OK;
}
@ -175,7 +186,7 @@ NS_IMETHODIMP nsWidget::Resize(PRUint32 aWidth,
printf("Resizing window 0x%lx to %d, %d\n", mBaseWindow, aWidth, aHeight);
mBounds.width = aWidth;
mBounds.height = aHeight;
XResizeWindow(gDisplay, mBaseWindow, aWidth, aHeight);
XResizeWindow(mDisplay, mBaseWindow, aWidth, aHeight);
return NS_OK;
}
@ -206,7 +217,7 @@ NS_IMETHODIMP nsWidget::Resize(PRUint32 aX,
printf("Moving window 0x%lx to %d, %d\n", mBaseWindow, aX, aY);
mBounds.width = aWidth;
mBounds.height = aHeight;
XMoveResizeWindow(gDisplay, mBaseWindow, aX, aY, aWidth, aHeight);
XMoveResizeWindow(mDisplay, mBaseWindow, aX, aY, aWidth, aHeight);
return NS_OK;
}
@ -265,7 +276,7 @@ void * nsWidget::GetNativeData(PRUint32 aDataType)
return (void *)mBaseWindow;
break;
case NS_NATIVE_DISPLAY:
return (void *)gDisplay;
return (void *)mDisplay;
break;
case NS_NATIVE_GRAPHIC:
// XXX implement this...
@ -323,7 +334,7 @@ NS_IMETHODIMP nsWidget::SetColorMap(nsColorMap *aColorMap)
NS_IMETHODIMP nsWidget::Show(PRBool bState)
{
if (mBaseWindow) {
XMapWindow(gDisplay, mBaseWindow);
XMapWindow(mDisplay, mBaseWindow);
}
return NS_OK;
}
@ -348,9 +359,9 @@ NS_IMETHODIMP nsWidget::SetBackgroundColor(const nscolor &aColor)
{
printf("nsWidget::SetBackgroundColor()\n");
nsBaseWidget::SetBackgroundColor(aColor);
bg_pixel = xlib_rgb_xpixel_from_rgb(mBackground);
mBackgroundPixel = xlib_rgb_xpixel_from_rgb(mBackground);
// set the window attrib
XSetWindowBackground(gDisplay, mBaseWindow, bg_pixel);
XSetWindowBackground(mDisplay, mBaseWindow, mBackgroundPixel);
return NS_OK;
}
@ -392,8 +403,8 @@ void nsWidget::CreateNative(Window aParent, nsRect aRect)
// make sure that we listen for events
attr.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
// set the default background color and border to that awful gray
attr.background_pixel = bg_pixel;
attr.border_pixel = border_pixel;
attr.background_pixel = mBackgroundPixel;
attr.border_pixel = mBorderPixel;
// set the colormap
attr.colormap = xlib_rgb_get_cmap();
// here's what's in the struct
@ -414,8 +425,10 @@ void nsWidget::CreateNativeWindow(Window aParent, nsRect aRect,
int width;
int height;
printf("*** Warning: nsWidget::CreateNative falling back to sane default for widget type \"%s\"\n", name);
if (!strcmp(name, "unnamed")) {
printf("*** Warning: nsWidget::CreateNative falling back to sane default for widget type \"%s\"\n",
(const char *) nsAutoCString(mName));
if (mName == "unnamed") {
printf("What freaking widget is this, anyway?\n");
}
printf("Creating XWindow: x %d y %d w %d h %d\n",
@ -435,18 +448,20 @@ void nsWidget::CreateNativeWindow(Window aParent, nsRect aRect,
height = aRect.height;
}
mBaseWindow = XCreateWindow(gDisplay,
mBaseWindow = XCreateWindow(mDisplay,
aParent,
aRect.x, aRect.y,
width, height,
0, // border width
0, // border width
gDepth,
InputOutput, // class
gVisual, // visual
InputOutput, // class
mVisual, // visual
aMask,
&aAttr);
printf("nsWidget: Created window 0x%lx with parent 0x%lx\n",
mBaseWindow, aParent);
// XXX when we stop getting lame values for this remove it.
// sometimes the dimensions have been corrected by the code above.
mBounds.height = height;
@ -456,7 +471,7 @@ void nsWidget::CreateNativeWindow(Window aParent, nsRect aRect,
}
nsWidget *
nsWidget::getWidgetForWindow(Window aWindow)
nsWidget::GetWidgetForWindow(Window aWindow)
{
if (window_list == nsnull) {
return nsnull;
@ -605,5 +620,5 @@ PRBool nsWidget::ConvertStatus(nsEventStatus aStatus)
void nsWidget::CreateGC(void)
{
mGC = XCreateGC(gDisplay, mBaseWindow, 0, NULL);
mGC = XCreateGC(mDisplay, mBaseWindow, 0, NULL);
}

Просмотреть файл

@ -100,8 +100,15 @@ public:
virtual PRBool OnPaint(nsPaintEvent &event);
virtual PRBool OnResize(nsSizeEvent &event);
virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent);
static nsWidget *getWidgetForWindow(Window aWindow);
static nsWidget * GetWidgetForWindow(Window aWindow);
protected:
// private event functions
PRBool DispatchWindowEvent(nsGUIEvent* event);
PRBool ConvertStatus(nsEventStatus aStatus);
// create the native window for this class
virtual void CreateNativeWindow(Window aParent, nsRect aRect,
XSetWindowAttributes aAttr, unsigned long aMask);
@ -113,21 +120,23 @@ protected:
static void AddWindowCallback (Window aWindow, nsWidget *aWidget);
static void DeleteWindowCallback(Window aWindow);
static nsHashtable *window_list;
PRUint32 mPreferredWidth;
PRUint32 mPreferredHeight;
nsIWidget *parentWidget;
// private event functions
PRBool nsWidget::DispatchWindowEvent(nsGUIEvent* event);
PRBool nsWidget::ConvertStatus(nsEventStatus aStatus);
PRUint32 mPreferredWidth;
PRUint32 mPreferredHeight;
nsIWidget * mParentWidget;
// All widgets have at least these items.
Window mBaseWindow;
unsigned long bg_pixel;
PRUint32 border_rgb;
unsigned long border_pixel;
GC mGC; // until we get gc pooling working...
const char *name; // name of the type of widget
Display * mDisplay;
Screen * mScreen;
Window mBaseWindow;
Visual * mVisual;
unsigned long mBackgroundPixel;
PRUint32 mBorderRGB;
unsigned long mBorderPixel;
GC mGC; // until we get gc pooling working...
nsString mName; // name of the type of widget
};
extern Display *gDisplay;
@ -137,23 +146,6 @@ extern int gDepth;
extern Visual *gVisual;
extern XVisualInfo *gVisualInfo;
extern PRUint32 gRedZeroMask; //red color mask in zero position
extern PRUint32 gGreenZeroMask; //green color mask in zero position
extern PRUint32 gBlueZeroMask; //blue color mask in zero position
extern PRUint32 gAlphaZeroMask; //alpha data mask in zero position
extern PRUint32 gRedMask; //red color mask
extern PRUint32 gGreenMask; //green color mask
extern PRUint32 gBlueMask; //blue color mask
extern PRUint32 gAlphaMask; //alpha data mask
extern PRUint8 gRedCount; //number of red color bits
extern PRUint8 gGreenCount; //number of green color bits
extern PRUint8 gBlueCount; //number of blue color bits
extern PRUint8 gAlphaCount; //number of alpha data bits
extern PRUint8 gRedShift; //number to shift value into red position
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"

Просмотреть файл

@ -23,11 +23,11 @@
nsWindow::nsWindow() : nsWidget()
{
NS_INIT_REFCNT();
name = "nsWindow";
mName = "nsWindow";
mBackground = NS_RGB(255, 255, 255);
bg_pixel = xlib_rgb_xpixel_from_rgb(mBackground);
mBackgroundPixel = xlib_rgb_xpixel_from_rgb(mBackground);
mBackground = NS_RGB(255, 255, 255);
border_pixel = xlib_rgb_xpixel_from_rgb(border_rgb);
mBorderPixel = xlib_rgb_xpixel_from_rgb(mBorderRGB);
}
nsWindow::~nsWindow()
@ -38,9 +38,9 @@ void
nsWindow::DestroyNative(void)
{
if (mGC)
XFreeGC(gDisplay, mGC);
XFreeGC(mDisplay, mGC);
if (mBaseWindow) {
XDestroyWindow(gDisplay, mBaseWindow);
XDestroyWindow(mDisplay, mBaseWindow);
DeleteWindowCallback(mBaseWindow);
}
}
@ -56,8 +56,8 @@ void nsWindow::CreateNative(Window aParent, nsRect aRect)
// make sure that we listen for events
attr.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
// set the default background color and border to that awful gray
attr.background_pixel = bg_pixel;
attr.border_pixel = border_pixel;
attr.background_pixel = mBackgroundPixel;
attr.border_pixel = mBorderPixel;
// set the colormap
attr.colormap = xlib_rgb_get_cmap();
// here's what's in the struct
@ -141,12 +141,12 @@ NS_IMETHODIMP nsWindow::SetTitle(const nsString& aTitle)
return NS_ERROR_FAILURE;
const char *text = aTitle.ToNewCString();
XStoreName(gDisplay, mBaseWindow, text);
XStoreName(mDisplay, mBaseWindow, text);
delete [] text;
return NS_OK;
}
ChildWindow::ChildWindow(): nsWindow()
{
name = "nsChildWindow";
mName = "nsChildWindow";
}