diff --git a/mozilla/widget/public/nsIWidget.h b/mozilla/widget/public/nsIWidget.h index ebfb3d8c3a4..1f665edc6a7 100644 --- a/mozilla/widget/public/nsIWidget.h +++ b/mozilla/widget/public/nsIWidget.h @@ -297,8 +297,6 @@ class nsIWidget : public nsISupports { /** * Make the window modal * - * - * */ NS_IMETHOD SetModal(void) = 0; @@ -345,6 +343,16 @@ class nsIWidget : public nsISupports { PRInt32 aHeight, PRBool aRepaint) = 0; + /** + * Set's the widget's z-index. + */ + NS_IMETHOD SetZIndex(PRInt32 aZIndex) = 0; + + /** + * Get's the widget's z-index. + */ + NS_IMETHOD GetZIndex(PRInt32* aZIndex) = 0; + /** * Enable or disable this Widget * diff --git a/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp b/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp index e76ad888083..92b907dbc52 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp +++ b/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp @@ -61,6 +61,7 @@ nsBaseWidget::nsBaseWidget() , mOnDestroyCalled(PR_FALSE) , mBounds(0,0,0,0) , mVScrollbar(nsnull) +, mZIndex(0) { NS_NewISupportsArray(getter_AddRefs(mChildren)); @@ -245,7 +246,56 @@ void nsBaseWidget::RemoveChild(nsIWidget* aChild) { mChildren->RemoveElement(aChild); } - + + +//------------------------------------------------------------------------- +// +// Sets widget's position within its parent's child list. +// +//------------------------------------------------------------------------- +NS_IMETHODIMP nsBaseWidget::SetZIndex(PRInt32 aZIndex) +{ + mZIndex = aZIndex; + + // reorder this child in its parent's list. + nsBaseWidget* parent = NS_STATIC_CAST(nsBaseWidget*, GetParent()); + if (nsnull != parent) { + parent->mChildren->RemoveElement(this); + PRUint32 childCount, index; + if (NS_SUCCEEDED(parent->mChildren->Count(&childCount))) { + for (index = 0; index < childCount; index++) { + nsCOMPtr childWidget; + if (NS_SUCCEEDED(parent->mChildren->QueryElementAt(index, NS_GET_IID(nsIWidget), (void**)getter_AddRefs(childWidget)))) { + PRInt32 childZIndex; + if (NS_SUCCEEDED(childWidget->GetZIndex(&childZIndex))) { + if (aZIndex < childZIndex) { + parent->mChildren->InsertElementAt(this, index); + break; + } + } + } + } + // were we added to the list? + if (index == childCount) { + parent->mChildren->AppendElement(this); + } + } + NS_RELEASE(parent); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Gets widget's position within its parent's child list. +// +//------------------------------------------------------------------------- +NS_IMETHODIMP nsBaseWidget::GetZIndex(PRInt32* aZIndex) +{ + *aZIndex = mZIndex; + return NS_OK; +} + //------------------------------------------------------------------------- // // Get the foreground color diff --git a/mozilla/widget/src/xpwidgets/nsBaseWidget.h b/mozilla/widget/src/xpwidgets/nsBaseWidget.h index 7b0f5c827bf..318df2ac482 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseWidget.h +++ b/mozilla/widget/src/xpwidgets/nsBaseWidget.h @@ -61,6 +61,8 @@ public: virtual void AddChild(nsIWidget* aChild); virtual void RemoveChild(nsIWidget* aChild); + NS_IMETHOD SetZIndex(PRInt32 aZIndex); + NS_IMETHOD GetZIndex(PRInt32* aZIndex); virtual nscolor GetForegroundColor(void); NS_IMETHOD SetForegroundColor(const nscolor &aColor); @@ -129,13 +131,12 @@ protected: PRBool mIsAltDown; PRBool mIsDestroying; PRBool mOnDestroyCalled; - //PRInt32 mWidth; - //PRInt32 mHeight; nsRect mBounds; nsIWidget *mVScrollbar; + PRInt32 mZIndex; // keep the list of children - nsCOMPtr mChildren; + nsCOMPtr mChildren; class Enumerator : public nsIBidirectionalEnumerator { public: