From 201d199cd210a944ac87e66e20d1f089fd8aee22 Mon Sep 17 00:00:00 2001 From: "blizzard%redhat.com" Date: Mon, 31 May 1999 03:05:33 +0000 Subject: [PATCH] more fixes for displays that have more than one visual. expose events threaten to work now. git-svn-id: svn://10.0.0.236/trunk@33289 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/xlib/nsAppShell.cpp | 32 +++- mozilla/widget/src/xlib/nsAppShell.h | 3 +- mozilla/widget/src/xlib/nsButton.cpp | 15 -- mozilla/widget/src/xlib/nsButton.h | 4 - mozilla/widget/src/xlib/nsCheckButton.cpp | 15 -- mozilla/widget/src/xlib/nsCheckButton.h | 4 - mozilla/widget/src/xlib/nsComboBox.cpp | 15 -- mozilla/widget/src/xlib/nsComboBox.h | 5 - mozilla/widget/src/xlib/nsFileWidget.h | 2 - mozilla/widget/src/xlib/nsLabel.cpp | 15 -- mozilla/widget/src/xlib/nsLabel.h | 4 - mozilla/widget/src/xlib/nsListBox.cpp | 15 -- mozilla/widget/src/xlib/nsListBox.h | 4 - mozilla/widget/src/xlib/nsRadioButton.cpp | 15 -- mozilla/widget/src/xlib/nsRadioButton.h | 4 - mozilla/widget/src/xlib/nsScrollBar.cpp | 12 -- mozilla/widget/src/xlib/nsScrollBar.h | 2 - mozilla/widget/src/xlib/nsTabWidget.cpp | 9 -- mozilla/widget/src/xlib/nsTabWidget.h | 4 - mozilla/widget/src/xlib/nsTextAreaWidget.cpp | 15 -- mozilla/widget/src/xlib/nsTextAreaWidget.h | 3 - mozilla/widget/src/xlib/nsTextWidget.cpp | 16 -- mozilla/widget/src/xlib/nsTextWidget.h | 4 - mozilla/widget/src/xlib/nsTooltipWidget.cpp | 5 - mozilla/widget/src/xlib/nsTooltipWidget.h | 1 - mozilla/widget/src/xlib/nsWidget.cpp | 160 ++++++++++++++++++- mozilla/widget/src/xlib/nsWidget.h | 22 ++- mozilla/widget/src/xlib/nsWindow.cpp | 14 ++ mozilla/widget/src/xlib/nsWindow.h | 1 + 29 files changed, 216 insertions(+), 204 deletions(-) diff --git a/mozilla/widget/src/xlib/nsAppShell.cpp b/mozilla/widget/src/xlib/nsAppShell.cpp index 65b866bfc70..00b78976957 100644 --- a/mozilla/widget/src/xlib/nsAppShell.cpp +++ b/mozilla/widget/src/xlib/nsAppShell.cpp @@ -299,8 +299,36 @@ void* nsAppShell::GetNativeData(PRUint32 aDataType) void nsAppShell::DispatchEvent(XEvent *event) { - printf("Window %ld Got a %s event\n", - event->xany.window, event_names[event->type]); + nsWidget *widget; + widget = nsWidget::getWidgetForWindow(event->xany.window); + // switch on the type of event + switch (event->type) { + case Expose: + printf("Handling expose event for window %ld\n", event->xany.window); + HandleExposeEvent(event, widget); + break; + default: + printf("Unhandled window event: Window %ld Got a %s event\n", + event->xany.window, event_names[event->type]); + break; + } +} + +void +nsAppShell::HandleExposeEvent(XEvent *event, nsWidget *aWidget) +{ + nsPaintEvent pevent; + pevent.message = NS_PAINT; + pevent.widget = aWidget; + pevent.eventStructType = NS_PAINT_EVENT; + pevent.rect = new nsRect (event->xexpose.x, event->xexpose.y, + event->xexpose.width, event->xexpose.height); + // XXX fix this + pevent.time = 0; + NS_ADDREF(aWidget); + aWidget->OnPaint(pevent); + NS_RELEASE(aWidget); + delete pevent.rect; } static PRUint8 convertMaskToCount(unsigned long val) diff --git a/mozilla/widget/src/xlib/nsAppShell.h b/mozilla/widget/src/xlib/nsAppShell.h index 002463da5c1..44f69f6207c 100644 --- a/mozilla/widget/src/xlib/nsAppShell.h +++ b/mozilla/widget/src/xlib/nsAppShell.h @@ -30,8 +30,6 @@ class nsAppShell : public nsIAppShell NS_DECL_ISUPPORTS - PRBool OnPaint(); - // nsIAppShellInterface NS_IMETHOD Create(int* argc, char ** argv); @@ -50,6 +48,7 @@ class nsAppShell : public nsIAppShell private: nsDispatchListener* mDispatchListener; void DispatchEvent(XEvent *event); + static void HandleExposeEvent(XEvent *event, nsWidget *aWidget); protected: nsIEventQueueService * mEventQueueService; diff --git a/mozilla/widget/src/xlib/nsButton.cpp b/mozilla/widget/src/xlib/nsButton.cpp index ef6273649b8..a9df9bd1d22 100644 --- a/mozilla/widget/src/xlib/nsButton.cpp +++ b/mozilla/widget/src/xlib/nsButton.cpp @@ -57,21 +57,6 @@ NS_METHOD nsButton::GetLabel (nsString &aBuffer) return NS_OK; } -PRBool nsButton::OnMove(PRInt32, PRInt32) -{ - return PR_FALSE; -} - -PRBool nsButton::OnPaint() -{ - return PR_FALSE; -} - -PRBool nsButton::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} - NS_METHOD nsButton::Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect) { diff --git a/mozilla/widget/src/xlib/nsButton.h b/mozilla/widget/src/xlib/nsButton.h index 368ce6f9780..95edc4d9e15 100644 --- a/mozilla/widget/src/xlib/nsButton.h +++ b/mozilla/widget/src/xlib/nsButton.h @@ -42,10 +42,6 @@ class nsButton : public nsWidget, NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect); - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - virtual PRBool OnPaint(); - virtual PRBool OnResize(nsRect &aWindowRect); - protected: nsString mLabel; }; diff --git a/mozilla/widget/src/xlib/nsCheckButton.cpp b/mozilla/widget/src/xlib/nsCheckButton.cpp index bb5ad9fbc1f..012d9b33f69 100644 --- a/mozilla/widget/src/xlib/nsCheckButton.cpp +++ b/mozilla/widget/src/xlib/nsCheckButton.cpp @@ -66,21 +66,6 @@ NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer) return NS_OK; } -PRBool nsCheckButton::OnMove(PRInt32, PRInt32) -{ - return PR_FALSE; -} - -PRBool nsCheckButton::OnPaint() -{ - return PR_FALSE; -} - -PRBool nsCheckButton::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} - NS_METHOD nsCheckButton::Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect) { diff --git a/mozilla/widget/src/xlib/nsCheckButton.h b/mozilla/widget/src/xlib/nsCheckButton.h index 68229d2b8d3..157c6210c6a 100644 --- a/mozilla/widget/src/xlib/nsCheckButton.h +++ b/mozilla/widget/src/xlib/nsCheckButton.h @@ -45,10 +45,6 @@ public: NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect); - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - virtual PRBool OnPaint(); - virtual PRBool OnResize(nsRect &aWindowRect); - protected: PRBool mState; diff --git a/mozilla/widget/src/xlib/nsComboBox.cpp b/mozilla/widget/src/xlib/nsComboBox.cpp index 0ab14d5bd58..42646dd61a9 100644 --- a/mozilla/widget/src/xlib/nsComboBox.cpp +++ b/mozilla/widget/src/xlib/nsComboBox.cpp @@ -94,21 +94,6 @@ nsresult nsComboBox::QueryInterface(const nsIID& aIID, void** aInstancePtr) return nsWidget::QueryInterface(aIID,aInstancePtr); } -PRBool nsComboBox::OnMove(PRInt32, PRInt32) -{ - return PR_FALSE; -} - -PRBool nsComboBox::OnPaint() -{ - return PR_FALSE; -} - -PRBool nsComboBox::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} - NS_METHOD nsComboBox::PreCreateWidget(nsWidgetInitData *aInitData) { return NS_OK; diff --git a/mozilla/widget/src/xlib/nsComboBox.h b/mozilla/widget/src/xlib/nsComboBox.h index 96ad32e76d0..2720d32ad77 100644 --- a/mozilla/widget/src/xlib/nsComboBox.h +++ b/mozilla/widget/src/xlib/nsComboBox.h @@ -36,11 +36,6 @@ public: NS_IMETHOD_(nsrefcnt) AddRef(void); NS_IMETHOD_(nsrefcnt) Release(void); - // nsIWidget overrides - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - virtual PRBool OnPaint(); - virtual PRBool OnResize(nsRect &aWindowRect); - // nsIComboBox interface NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition); virtual PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos); diff --git a/mozilla/widget/src/xlib/nsFileWidget.h b/mozilla/widget/src/xlib/nsFileWidget.h index 5a202b3afa9..200c5737bcb 100644 --- a/mozilla/widget/src/xlib/nsFileWidget.h +++ b/mozilla/widget/src/xlib/nsFileWidget.h @@ -34,8 +34,6 @@ class nsFileWidget : public nsIFileWidget NS_DECL_ISUPPORTS - PRBool OnPaint(); - // nsIWidget interface NS_IMETHOD Create( nsIWidget *aParent, diff --git a/mozilla/widget/src/xlib/nsLabel.cpp b/mozilla/widget/src/xlib/nsLabel.cpp index c88941bcd36..32824d358e5 100644 --- a/mozilla/widget/src/xlib/nsLabel.cpp +++ b/mozilla/widget/src/xlib/nsLabel.cpp @@ -64,21 +64,6 @@ NS_METHOD nsLabel::GetLabel(nsString& aBuffer) return NS_OK; } -PRBool nsLabel::OnMove(PRInt32, PRInt32) -{ - return PR_FALSE; -} - -PRBool nsLabel::OnPaint() -{ - return PR_FALSE; -} - -PRBool nsLabel::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} - NS_METHOD nsLabel::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) { return NS_OK; diff --git a/mozilla/widget/src/xlib/nsLabel.h b/mozilla/widget/src/xlib/nsLabel.h index c8c352473dd..8c93837a3d8 100644 --- a/mozilla/widget/src/xlib/nsLabel.h +++ b/mozilla/widget/src/xlib/nsLabel.h @@ -44,10 +44,6 @@ public: NS_IMETHOD GetLabel(nsString &aBuffer); NS_IMETHOD SetAlignment(nsLabelAlignment aAlignment); - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - virtual PRBool OnPaint(); - virtual PRBool OnResize(nsRect &aWindowRect); - NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); diff --git a/mozilla/widget/src/xlib/nsListBox.cpp b/mozilla/widget/src/xlib/nsListBox.cpp index f11538bb0ee..b19e5be424b 100644 --- a/mozilla/widget/src/xlib/nsListBox.cpp +++ b/mozilla/widget/src/xlib/nsListBox.cpp @@ -122,21 +122,6 @@ nsresult nsListBox::QueryInterface(const nsIID& aIID, void** aInstancePtr) return result; } -PRBool nsListBox::OnMove(PRInt32, PRInt32) -{ - return PR_FALSE; -} - -PRBool nsListBox::OnPaint() -{ - return PR_FALSE; -} - -PRBool nsListBox::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} - PRBool nsListBox::AutoErase() { return(PR_TRUE); diff --git a/mozilla/widget/src/xlib/nsListBox.h b/mozilla/widget/src/xlib/nsListBox.h index 7054acb5638..966fc00028d 100644 --- a/mozilla/widget/src/xlib/nsListBox.h +++ b/mozilla/widget/src/xlib/nsListBox.h @@ -40,10 +40,6 @@ public: NS_IMETHOD_(nsrefcnt) AddRef(void); NS_IMETHOD_(nsrefcnt) Release(void); - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - virtual PRBool OnPaint(); - virtual PRBool OnResize(nsRect &aWindowRect); - // nsIListBox interface NS_IMETHOD SetMultipleSelection(PRBool aMultipleSelections); diff --git a/mozilla/widget/src/xlib/nsRadioButton.cpp b/mozilla/widget/src/xlib/nsRadioButton.cpp index 18f76cb4f32..b8419eedd2f 100644 --- a/mozilla/widget/src/xlib/nsRadioButton.cpp +++ b/mozilla/widget/src/xlib/nsRadioButton.cpp @@ -63,21 +63,6 @@ NS_METHOD nsRadioButton::GetLabel(nsString& aBuffer) return NS_OK; } -PRBool nsRadioButton::OnMove(PRInt32, PRInt32) -{ - return PR_FALSE; -} - -PRBool nsRadioButton::OnPaint() -{ - return PR_FALSE; -} - -PRBool nsRadioButton::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} - NS_METHOD nsRadioButton::Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect) { diff --git a/mozilla/widget/src/xlib/nsRadioButton.h b/mozilla/widget/src/xlib/nsRadioButton.h index 184197cbf1c..ce7e18cac4b 100644 --- a/mozilla/widget/src/xlib/nsRadioButton.h +++ b/mozilla/widget/src/xlib/nsRadioButton.h @@ -49,10 +49,6 @@ public: NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect); - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - virtual PRBool OnPaint(); - virtual PRBool OnResize(nsRect &aWindowRect); - protected: diff --git a/mozilla/widget/src/xlib/nsScrollBar.cpp b/mozilla/widget/src/xlib/nsScrollBar.cpp index 2e23f310382..e5e1ab5fd6b 100644 --- a/mozilla/widget/src/xlib/nsScrollBar.cpp +++ b/mozilla/widget/src/xlib/nsScrollBar.cpp @@ -90,18 +90,6 @@ NS_METHOD nsScrollbar::SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, return NS_OK; } -PRBool nsScrollbar::OnPaint() -{ - return PR_FALSE; -} - - -PRBool nsScrollbar::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} - - PRBool nsScrollbar::OnScroll(PRUint32 scrollCode, int cPos) { return PR_FALSE; diff --git a/mozilla/widget/src/xlib/nsScrollBar.h b/mozilla/widget/src/xlib/nsScrollBar.h index bffec4bea0b..aa34a134ae2 100644 --- a/mozilla/widget/src/xlib/nsScrollBar.h +++ b/mozilla/widget/src/xlib/nsScrollBar.h @@ -47,9 +47,7 @@ public: NS_IMETHOD SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, PRUint32 aPosition, PRUint32 aLineIncrement); - virtual PRBool OnPaint(); virtual PRBool OnScroll(PRUint32 scrollCode, int cPos); - virtual PRBool OnResize(nsRect &aWindowRect); }; diff --git a/mozilla/widget/src/xlib/nsTabWidget.cpp b/mozilla/widget/src/xlib/nsTabWidget.cpp index 7bc049b006e..bcfa0fb2b6b 100644 --- a/mozilla/widget/src/xlib/nsTabWidget.cpp +++ b/mozilla/widget/src/xlib/nsTabWidget.cpp @@ -54,15 +54,6 @@ PRUint32 nsTabWidget::GetSelectedTab(PRUint32& aTabNumber) return 0; } -PRBool nsTabWidget::OnPaint() -{ - return PR_FALSE; -} - -PRBool nsTabWidget::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} diff --git a/mozilla/widget/src/xlib/nsTabWidget.h b/mozilla/widget/src/xlib/nsTabWidget.h index 14661fde32b..bf9d68cc1b5 100644 --- a/mozilla/widget/src/xlib/nsTabWidget.h +++ b/mozilla/widget/src/xlib/nsTabWidget.h @@ -39,10 +39,6 @@ public: NS_IMETHOD SetTabs(PRUint32 aNumberOfTabs, const nsString aTabLabels[]); NS_IMETHOD GetSelectedTab(PRUint32& aTabNumber); - // nsIWidget overrides - virtual PRBool OnPaint(); - virtual PRBool OnResize(nsRect &aWindowRect); - }; #endif // nsTabWidget_h__ diff --git a/mozilla/widget/src/xlib/nsTextAreaWidget.cpp b/mozilla/widget/src/xlib/nsTextAreaWidget.cpp index 18c0f976bd2..5c768c7b214 100644 --- a/mozilla/widget/src/xlib/nsTextAreaWidget.cpp +++ b/mozilla/widget/src/xlib/nsTextAreaWidget.cpp @@ -51,21 +51,6 @@ nsresult nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr return nsWidget::QueryInterface(aIID, aInstancePtr); } -PRBool nsTextAreaWidget::OnMove(PRInt32, PRInt32) -{ - return PR_FALSE; -} - -PRBool nsTextAreaWidget::OnPaint() -{ - return PR_FALSE; -} - -PRBool nsTextAreaWidget::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} - NS_METHOD nsTextAreaWidget::Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect) { diff --git a/mozilla/widget/src/xlib/nsTextAreaWidget.h b/mozilla/widget/src/xlib/nsTextAreaWidget.h index 52506682456..15783345ba2 100644 --- a/mozilla/widget/src/xlib/nsTextAreaWidget.h +++ b/mozilla/widget/src/xlib/nsTextAreaWidget.h @@ -41,9 +41,6 @@ public: NS_IMETHOD_(nsrefcnt) Release(void); // nsIWidget Overrides - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - virtual PRBool OnPaint(); - virtual PRBool OnResize(nsRect &aWindowRect); NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect); diff --git a/mozilla/widget/src/xlib/nsTextWidget.cpp b/mozilla/widget/src/xlib/nsTextWidget.cpp index 557fc9f3065..efd95501107 100644 --- a/mozilla/widget/src/xlib/nsTextWidget.cpp +++ b/mozilla/widget/src/xlib/nsTextWidget.cpp @@ -45,22 +45,6 @@ nsresult nsTextWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr) return result; } -PRBool nsTextWidget::OnMove(PRInt32, PRInt32) -{ - return PR_FALSE; -} - -PRBool nsTextWidget::OnPaint() -{ - return PR_FALSE; -} - - -PRBool nsTextWidget::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} - NS_METHOD nsTextWidget::Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect) { diff --git a/mozilla/widget/src/xlib/nsTextWidget.h b/mozilla/widget/src/xlib/nsTextWidget.h index 8c3fd91014a..2a8b059b037 100644 --- a/mozilla/widget/src/xlib/nsTextWidget.h +++ b/mozilla/widget/src/xlib/nsTextWidget.h @@ -35,10 +35,6 @@ public: NS_IMETHOD_(nsrefcnt) AddRef(void); NS_IMETHOD_(nsrefcnt) Release(void); - virtual PRBool OnPaint(); - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - virtual PRBool OnResize(nsRect &aWindowRect); - NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect); diff --git a/mozilla/widget/src/xlib/nsTooltipWidget.cpp b/mozilla/widget/src/xlib/nsTooltipWidget.cpp index 3fb67c772fd..ba52f52ac18 100644 --- a/mozilla/widget/src/xlib/nsTooltipWidget.cpp +++ b/mozilla/widget/src/xlib/nsTooltipWidget.cpp @@ -50,11 +50,6 @@ PRBool nsTooltipWidget::OnPaint() return PR_FALSE; } -PRBool nsTooltipWidget::OnResize(nsRect &aWindowRect) -{ - return PR_FALSE; -} - PRBool nsTooltipWidget::AutoErase() { return(PR_TRUE); diff --git a/mozilla/widget/src/xlib/nsTooltipWidget.h b/mozilla/widget/src/xlib/nsTooltipWidget.h index a4806a5829f..c9e9a1f0b3b 100644 --- a/mozilla/widget/src/xlib/nsTooltipWidget.h +++ b/mozilla/widget/src/xlib/nsTooltipWidget.h @@ -40,7 +40,6 @@ public: NS_IMETHOD_(nsrefcnt) Release(void); virtual PRBool OnPaint(); - virtual PRBool OnResize(nsRect &aWindowRect); virtual PRBool AutoErase(); diff --git a/mozilla/widget/src/xlib/nsWidget.cpp b/mozilla/widget/src/xlib/nsWidget.cpp index ff63de5e467..2d9b22ae913 100644 --- a/mozilla/widget/src/xlib/nsWidget.cpp +++ b/mozilla/widget/src/xlib/nsWidget.cpp @@ -17,6 +17,35 @@ */ #include "nsWidget.h" +#include "nsGfxCIID.h" +// set up our static members here. +nsHashtable *nsWidget::window_list = nsnull; + +// this is a class for generating keys for +// the list of windows managed by mozilla. + +class nsWindowKey : public nsHashKey { +protected: + Window mKey; + +public: + nsWindowKey(Window key) { + mKey = key; + } + ~nsWindowKey(void) { + } + PRUint32 HashValue(void) const { + return (PRUint32)mKey; + } + + PRBool Equals(const nsHashKey *aKey) const { + return (mKey == ((nsWindowKey *)aKey)->mKey); + } + + nsHashKey *Clone(void) const { + return new nsWindowKey(mKey); + } +}; nsWidget::nsWidget() : nsBaseWidget() { @@ -31,11 +60,19 @@ nsWidget::nsWidget() : nsBaseWidget() } nsWidget::~nsWidget() +{ + DestroyNative(); +} + +void +nsWidget::DestroyNative(void) { if (mGC) XFreeGC(gDisplay, mGC); - if (mBaseWindow) + if (mBaseWindow) { XDestroyWindow(gDisplay, mBaseWindow); + DeleteWindowCallback(mBaseWindow); + } } NS_IMETHODIMP nsWidget::Create(nsIWidget *aParent, @@ -247,12 +284,6 @@ NS_IMETHODIMP nsWidget::Update() return NS_OK; } -NS_IMETHODIMP nsWidget::DispatchEvent(nsGUIEvent* event, - nsEventStatus & aStatus) -{ - return NS_OK; -} - NS_IMETHODIMP nsWidget::SetBackgroundColor(const nscolor &aColor) { printf("nsWidget::SetBackgroundColor()\n"); @@ -310,8 +341,13 @@ void nsWidget::CreateNative(Window aParent, nsRect aRect) attr.event_mask = SubstructureNotifyMask | StructureNotifyMask | ExposureMask; // set the default background color to that awful gray attr.background_pixel = bg_pixel; + // set the colormap + attr.colormap = xlib_rgb_get_cmap(); // here's what's in the struct attr_mask = CWBitGravity | CWEventMask | CWBackPixel; + // check to see if there was actually a colormap. + if (attr.colormap) + attr_mask |= CWColormap; printf("Creating XWindow: x %d y %d w %d h %d\n", aRect.x, aRect.y, aRect.width, aRect.height); @@ -337,12 +373,120 @@ void nsWidget::CreateNative(Window aParent, nsRect aRect) 0, // border width gDepth, InputOutput, // class - CopyFromParent, // visual + gVisual, // visual attr_mask, &attr); + // add the callback for this + AddWindowCallback(mBaseWindow, this); // map this window and flush the connection. we want to see this // thing now. XMapWindow(gDisplay, mBaseWindow); XSync(gDisplay, False); } + +nsWidget * +nsWidget::getWidgetForWindow(Window aWindow) +{ + if (window_list == nsnull) { + return nsnull; + } + nsWindowKey *window_key = new nsWindowKey(aWindow); + nsWidget *retval = (nsWidget *)window_list->Get(window_key); + return retval; +} + +void +nsWidget::AddWindowCallback(Window aWindow, nsWidget *aWidget) +{ + // make sure that the list has been initialized + if (window_list == nsnull) { + window_list = new nsHashtable(); + } + nsWindowKey *window_key = new nsWindowKey(aWindow); + window_list->Put(window_key, aWidget); + // add a new ref to this widget + NS_ADDREF(aWidget); + delete window_key; +} + +void +nsWidget::DeleteWindowCallback(Window aWindow) +{ + nsWindowKey *window_key = new nsWindowKey(aWindow); + nsWidget *widget = (nsWidget *)window_list->Get(window_key); + NS_RELEASE(widget); + window_list->Remove(window_key); + delete window_key; +} + +PRBool +nsWidget::OnPaint(nsPaintEvent &event) +{ + nsresult result = PR_FALSE; + if (mEventCallback) { + event.renderingContext = nsnull; + static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID); + static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID); + if (NS_OK == nsComponentManager::CreateInstance(kRenderingContextCID, + nsnull, + kRenderingContextIID, + (void **)&event.renderingContext)) { + event.renderingContext->Init(mContext, this); + result = DispatchWindowEvent(&event); + NS_RELEASE(event.renderingContext); + } + else { + result = PR_FALSE; + } + } + return result; +} + +PRBool nsWidget::DispatchWindowEvent(nsGUIEvent* event) +{ + nsEventStatus status; + DispatchEvent(event, status); + return ConvertStatus(status); +} + + +NS_IMETHODIMP nsWidget::DispatchEvent(nsGUIEvent *event, + nsEventStatus &aStatus) +{ + NS_ADDREF(event->widget); + + if (nsnull != mMenuListener) { + if (NS_MENU_EVENT == event->eventStructType) + aStatus = mMenuListener->MenuSelected(NS_STATIC_CAST(nsMenuEvent&, *event)); + } + + aStatus = nsEventStatus_eIgnore; + if (nsnull != mEventCallback) { + aStatus = (*mEventCallback)(event); + } + + // Dispatch to event listener if event was not consumed + if ((aStatus != nsEventStatus_eIgnore) && (nsnull != mEventListener)) { + aStatus = mEventListener->ProcessEvent(*event); + } + NS_RELEASE(event->widget); + + return NS_OK; +} + +PRBool nsWidget::ConvertStatus(nsEventStatus aStatus) +{ + switch(aStatus) { + case nsEventStatus_eIgnore: + return(PR_FALSE); + case nsEventStatus_eConsumeNoDefault: + return(PR_TRUE); + case nsEventStatus_eConsumeDoDefault: + return(PR_FALSE); + default: + NS_ASSERTION(0, "Illegal nsEventStatus enumeration value"); + break; + } + return(PR_FALSE); +} diff --git a/mozilla/widget/src/xlib/nsWidget.h b/mozilla/widget/src/xlib/nsWidget.h index 0c621431dd2..3f0d6209fdc 100644 --- a/mozilla/widget/src/xlib/nsWidget.h +++ b/mozilla/widget/src/xlib/nsWidget.h @@ -23,6 +23,7 @@ #include #include #include "nsBaseWidget.h" +#include "nsHashtable.h" class nsWidget : public nsBaseWidget { @@ -94,14 +95,27 @@ public: NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight); NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus); + PRBool OnPaint(nsPaintEvent &event); + static nsWidget *getWidgetForWindow(Window aWindow); protected: + // create the native window for this class virtual void CreateNative(Window aParent, nsRect aRect); - PRUint32 mPreferredWidth; - PRUint32 mPreferredHeight; - nsIWidget *parentWidget; + virtual void DestroyNative(void); + + // these will add and delete a window + 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); // All widgets have at least these items. - Window mBaseWindow; + Window mBaseWindow; PRUint32 bg_rgb; unsigned long bg_pixel; GC mGC; // until we get gc pooling working... diff --git a/mozilla/widget/src/xlib/nsWindow.cpp b/mozilla/widget/src/xlib/nsWindow.cpp index 42e1a2e5362..977b4066806 100644 --- a/mozilla/widget/src/xlib/nsWindow.cpp +++ b/mozilla/widget/src/xlib/nsWindow.cpp @@ -30,6 +30,18 @@ nsWindow::~nsWindow() { } +void +nsWindow::DestroyNative(void) +{ + if (mGC) + XFreeGC(gDisplay, mGC); + if (mBaseWindow) { + XDestroyWindow(gDisplay, mBaseWindow); + DeleteWindowCallback(mBaseWindow); + } +} + + void nsWindow::CreateNative(Window aParent, nsRect aRect) { @@ -79,6 +91,8 @@ nsWindow::CreateNative(Window aParent, nsRect aRect) gVisual, // get the visual from xlibrgb attr_mask, &attr); + // add the callback for this + AddWindowCallback(mBaseWindow, this); // map this window and flush the connection. we want to see this // thing now. XMapWindow(gDisplay, diff --git a/mozilla/widget/src/xlib/nsWindow.h b/mozilla/widget/src/xlib/nsWindow.h index d2739b5fb22..3d5cfe2ec97 100644 --- a/mozilla/widget/src/xlib/nsWindow.h +++ b/mozilla/widget/src/xlib/nsWindow.h @@ -28,6 +28,7 @@ class nsWindow : public nsWidget ~nsWindow(); protected: void CreateNative(Window aParent, nsRect aRect); + void DestroyNative(void); }; class ChildWindow : public nsWindow