From ca940ca440544900aa2c3f2b8f2e3f3460618b88 Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Fri, 4 Jun 1999 04:00:30 +0000 Subject: [PATCH] adding ShowMenuBar --- widget/public/nsIWidget.h | 11 ++++++++- widget/src/gtk/nsWidget.cpp | 11 +++++++-- widget/src/gtk/nsWidget.h | 1 + widget/src/gtk/nsWindow.cpp | 5 ++++ widget/src/gtk/nsWindow.h | 1 + widget/src/mac/nsWindow.cpp | 26 ++++++++++++-------- widget/src/mac/nsWindow.h | 1 + widget/src/motif/nsWindow.cpp | 5 ++++ widget/src/motif/nsWindow.h | 1 + widget/src/photon/nsWindow.cpp | 5 ++++ widget/src/photon/nsWindow.h | 1 + widget/src/windows/nsWindow.cpp | 42 +++++++++++++++++++++------------ widget/src/windows/nsWindow.h | 1 + widget/src/xlib/nsWidget.cpp | 5 ++++ widget/src/xlib/nsWidget.h | 1 + 15 files changed, 89 insertions(+), 28 deletions(-) diff --git a/widget/public/nsIWidget.h b/widget/public/nsIWidget.h index c32502b28383..a6a9efcea257 100644 --- a/widget/public/nsIWidget.h +++ b/widget/public/nsIWidget.h @@ -518,11 +518,20 @@ class nsIWidget : public nsISupports { * Set the widget's MenuBar. * Must be called after Create. * - * @param aTitle string displayed as the title of the widget + * @param aMenuBar the menubar */ NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar) = 0; + /** + * Set the widget's MenuBar's visibility, without affecting ownership + * or any other sticky considerations. + * + * @param aShow PR_TRUE to show, PR_FALSE to hide + */ + + NS_IMETHOD ShowMenuBar(PRBool aShow) = 0; + /** * Set the collection of tooltip rectangles. * A NS_SHOW_TOOLTIP event is generated when the mouse hovers over one diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index 6709444d32bd..cff7464540ff 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -764,8 +764,15 @@ NS_METHOD nsWidget::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) NS_METHOD nsWidget::SetMenuBar(nsIMenuBar * aMenuBar) { g_print("bleh\n"); - NS_NOTYETIMPLEMENTED("nsWidget::SetMenuBar"); - return NS_OK; + NS_NOTYETIMPLEMENTED("nsWidget::SetMenuBar"); + return NS_OK; +} + +NS_METHOD nsWidget::ShowMenuBar(PRBool aShow) +{ + g_print("bleh\n"); + NS_NOTYETIMPLEMENTED("nsWidget::ShowMenuBar"); + return NS_OK; } nsresult nsWidget::CreateWidget(nsIWidget *aParent, diff --git a/widget/src/gtk/nsWidget.h b/widget/src/gtk/nsWidget.h index 321eeaa022bd..2606405cc27a 100644 --- a/widget/src/gtk/nsWidget.h +++ b/widget/src/gtk/nsWidget.h @@ -109,6 +109,7 @@ class nsWidget : public nsBaseWidget NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect); NS_IMETHOD SetMenuBar(nsIMenuBar *aMenuBar); + NS_IMETHOD ShowMenuBar(PRBool aShow); NS_IMETHOD Invalidate(PRBool aIsSynchronous); NS_IMETHOD Invalidate(const nsRect &aRect, PRBool aIsSynchronous); diff --git a/widget/src/gtk/nsWindow.cpp b/widget/src/gtk/nsWindow.cpp index 871613d1b0b8..ff2962f42d9a 100644 --- a/widget/src/gtk/nsWindow.cpp +++ b/widget/src/gtk/nsWindow.cpp @@ -595,6 +595,11 @@ NS_METHOD nsWindow::SetMenuBar(nsIMenuBar* aMenuBar) return NS_OK; } +NS_METHOD nsWindow::ShowMenuBar(PRBool aShow) +{ + return NS_ERROR_FAILURE; // DRaM +} + //---------------------------------------------------------------------- diff --git a/widget/src/gtk/nsWindow.h b/widget/src/gtk/nsWindow.h index 3ddd4fe51ab7..c33d750f4e93 100644 --- a/widget/src/gtk/nsWindow.h +++ b/widget/src/gtk/nsWindow.h @@ -61,6 +61,7 @@ public: nsresult SetIcon(GdkPixmap *window_pixmap, GdkBitmap *window_mask); NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar); + NS_IMETHOD ShowMenuBar(PRBool aShow); NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]); NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]); diff --git a/widget/src/mac/nsWindow.cpp b/widget/src/mac/nsWindow.cpp index cfca7fdca15a..6515279ba19a 100644 --- a/widget/src/mac/nsWindow.cpp +++ b/widget/src/mac/nsWindow.cpp @@ -56,23 +56,23 @@ nsWindow::nsWindow() : nsBaseWidget() , nsDeleteObserved(this) mResizingChildren = PR_FALSE; mVisible = PR_FALSE; mEnabled = PR_TRUE; - SetPreferredSize(0,0); + SetPreferredSize(0,0); - mFontMetrics = nsnull; - mMenuBar = nsnull; - mTempRenderingContext = nsnull; + mFontMetrics = nsnull; + mMenuBar = nsnull; + mTempRenderingContext = nsnull; mWindowRegion = nsnull; mVisRegion = nsnull; mWindowPtr = nsnull; mDrawing = PR_FALSE; - mDestroyCalled = PR_FALSE; - mDestructorCalled = PR_FALSE; + mDestroyCalled = PR_FALSE; + mDestructorCalled = PR_FALSE; - SetBackgroundColor(NS_RGB(255, 255, 255)); - SetForegroundColor(NS_RGB(0, 0, 0)); - - mPluginPort = nsnull; + SetBackgroundColor(NS_RGB(255, 255, 255)); + SetForegroundColor(NS_RGB(0, 0, 0)); + + mPluginPort = nsnull; } @@ -404,6 +404,12 @@ NS_IMETHODIMP nsWindow::SetMenuBar(nsIMenuBar * aMenuBar) return NS_OK; } +NS_IMETHODIMP nsWindow::ShowMenuBar(PRBool aShow) +{ + // this may never be implemented on the Mac + return NS_ERROR_FAILURE; +} + //------------------------------------------------------------------------- // // Get the widget's MenuBar. diff --git a/widget/src/mac/nsWindow.h b/widget/src/mac/nsWindow.h index d37639cfd5f6..5f680462c153 100644 --- a/widget/src/mac/nsWindow.h +++ b/widget/src/mac/nsWindow.h @@ -121,6 +121,7 @@ public: void LocalToWindowCoordinate(nsRect& aRect) {ConvertToDeviceCoordinates(aRect.x, aRect.y);} NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar); + NS_IMETHOD ShowMenuBar(PRBool aShow); virtual nsIMenuBar* GetMenuBar(); NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight); diff --git a/widget/src/motif/nsWindow.cpp b/widget/src/motif/nsWindow.cpp index deb15458f662..3c8243903a98 100644 --- a/widget/src/motif/nsWindow.cpp +++ b/widget/src/motif/nsWindow.cpp @@ -1592,6 +1592,11 @@ NS_METHOD nsWindow::SetMenuBar(nsIMenuBar * aMenuBar) return NS_ERROR_FAILURE; } +NS_METHOD nsWindow::ShowMenuBar(PRBool aShow) +{ + return NS_ERROR_FAILURE; +} + NS_METHOD nsWindow::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) { aWidth = mPreferredWidth; diff --git a/widget/src/motif/nsWindow.h b/widget/src/motif/nsWindow.h index 020a508417b7..33aa747f19d0 100644 --- a/widget/src/motif/nsWindow.h +++ b/widget/src/motif/nsWindow.h @@ -129,6 +129,7 @@ public: NS_IMETHOD BeginResizingChildren(void); NS_IMETHOD EndResizingChildren(void); NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar); + NS_IMETHOD ShowMenuBar(PRBool aShow); NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight); NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus); diff --git a/widget/src/photon/nsWindow.cpp b/widget/src/photon/nsWindow.cpp index e71a7bf27857..f989a215a162 100644 --- a/widget/src/photon/nsWindow.cpp +++ b/widget/src/photon/nsWindow.cpp @@ -823,6 +823,11 @@ NS_METHOD nsWindow::SetMenuBar( nsIMenuBar * aMenuBar ) return res; } +NS_METHOD nsWindow::ShowMenuBar( PRBool aShow) +{ + return NS_ERROR_FAILURE; +} + /////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// diff --git a/widget/src/photon/nsWindow.h b/widget/src/photon/nsWindow.h index a0f3ca3f56fd..07c0fc0f1805 100644 --- a/widget/src/photon/nsWindow.h +++ b/widget/src/photon/nsWindow.h @@ -61,6 +61,7 @@ public: NS_IMETHOD SetTitle(const nsString& aTitle); NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar); + NS_IMETHOD ShowMenuBar(PRBool aShow); NS_IMETHOD GetBounds( nsRect &aRect ); NS_IMETHOD GetClientBounds( nsRect &aRect ); diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 57c09e2bbb4d..10f58518456d 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -112,12 +112,12 @@ nsWindow::nsWindow() : nsBaseWidget() mHitSubMenus = new nsVoidArray(); mVScrollbar = nsnull; - mIMEProperty = 0; - mIMEIsComposing = PR_FALSE; - mIMECompositionString = NULL; - mIMECompositionStringSize = 0; - mIMECompositionStringSize = 0; - mIMECompositionUniString = NULL; + mIMEProperty = 0; + mIMEIsComposing = PR_FALSE; + mIMECompositionString = NULL; + mIMECompositionStringSize = 0; + mIMECompositionStringSize = 0; + mIMECompositionUniString = NULL; #ifdef NEW_DRAG_AND_DROP mNativeDragTarget = nsnull; @@ -3120,19 +3120,31 @@ NS_METHOD nsWindow::SetMenuBar(nsIMenuBar * aMenuBar) { mMenuBar = aMenuBar; NS_ADDREF(mMenuBar); + return ShowMenuBar(PR_TRUE); +} - HMENU nativeMenuHandle; - void * voidData; - aMenuBar->GetNativeData(voidData); - nativeMenuHandle = (HMENU)voidData; +NS_METHOD nsWindow::ShowMenuBar(PRBool aShow) +{ + nsresult rv = NS_ERROR_FAILURE; - if (nsnull != nativeMenuHandle) { - ::SetMenu(mWnd, nativeMenuHandle); - return NS_OK; + if (aShow) { + if (mMenuBar) { + HMENU nativeMenuHandle; + void *voidData; + mMenuBar->GetNativeData(voidData); + nativeMenuHandle = (HMENU)voidData; + + if (nativeMenuHandle) { + ::SetMenu(mWnd, nativeMenuHandle); + rv = NS_OK; + } + } } else { - return NS_ERROR_FAILURE; + ::SetMenu(mWnd, 0); + rv = NS_OK; } -} + return rv; +} NS_METHOD nsWindow::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) { diff --git a/widget/src/windows/nsWindow.h b/widget/src/windows/nsWindow.h index 7696e9969f81..bb55fe630ddb 100644 --- a/widget/src/windows/nsWindow.h +++ b/widget/src/windows/nsWindow.h @@ -115,6 +115,7 @@ public: NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect); NS_IMETHOD SetTitle(const nsString& aTitle); NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar); + NS_IMETHOD ShowMenuBar(PRBool aShow); NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]); NS_IMETHOD RemoveTooltips(); NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]); diff --git a/widget/src/xlib/nsWidget.cpp b/widget/src/xlib/nsWidget.cpp index 51d10a84eb88..6207091a5132 100644 --- a/widget/src/xlib/nsWidget.cpp +++ b/widget/src/xlib/nsWidget.cpp @@ -206,6 +206,11 @@ NS_IMETHODIMP nsWidget::SetMenuBar(nsIMenuBar * aMenuBar) return NS_OK; } +NS_IMETHODIMP nsWidget::ShowMenuBar(PRBool aShow) +{ + return NS_ERROR_FAILURE; +} + void * nsWidget::GetNativeData(PRUint32 aDataType) { switch (aDataType) { diff --git a/widget/src/xlib/nsWidget.h b/widget/src/xlib/nsWidget.h index 89604fbd4279..9a702792034a 100644 --- a/widget/src/xlib/nsWidget.h +++ b/widget/src/xlib/nsWidget.h @@ -84,6 +84,7 @@ public: NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect); NS_IMETHOD SetTitle(const nsString& aTitle); NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar); + NS_IMETHOD ShowMenuBar(PRBool aShow); NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]); NS_IMETHOD RemoveTooltips(); NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]);