show a reasonable menu bar on app startup in case no window becomes main immediately. b=333088 r=mento

This commit is contained in:
joshmoz%gmail.com 2006-04-07 04:51:16 +00:00
parent c947dd04da
commit 7a12a01b41
2 changed files with 13 additions and 3 deletions

View File

@ -49,7 +49,7 @@
#include "nsGUIEvent.h"
#include "nsMacResources.h"
#include "nsIRollupListener.h"
#include "nsChildView.h"
#include "nsChildView.h"
#include "nsIAppShell.h"
#include "nsIAppShellService.h"
#include "nsIBaseWindow.h"
@ -64,11 +64,12 @@ static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID);
// externs defined in nsChildView.mm
extern nsIRollupListener * gRollupListener;
extern nsIWidget * gRollupWidget;
extern BOOL gSomeMenuBarPainted;
#define NS_APPSHELLSERVICE_CONTRACTID "@mozilla.org/appshell/appShellService;1"
// call getHiddenWindowNativeMenu, don't use this directly
static nsIMenuBar* gHiddenWindowMenuBar = nsnull;
static nsIMenuBar* gHiddenWindowMenuBar;
NS_IMPL_ISUPPORTS_INHERITED0(nsCocoaWindow, Inherited)
@ -728,6 +729,12 @@ NS_IMETHODIMP nsCocoaWindow::SetMenuBar(nsIMenuBar *aMenuBar)
if (mMenuBar)
mMenuBar->SetParent(nsnull);
mMenuBar = aMenuBar;
// We paint the hidden window menu bar if no other menu bar has been painted
// yet so that some reasonable menu bar is displayed when the app starts up.
if (!gSomeMenuBarPainted && mMenuBar && (GetHiddenWindowMenuBar() == mMenuBar))
mMenuBar->Paint();
return NS_OK;
}

View File

@ -75,7 +75,7 @@ NSMenu* nsMenuBarX::sApplicationMenu = nsnull;
EventHandlerUPP nsMenuBarX::sCommandEventHandler = nsnull;
NativeMenuItemTarget* nsMenuBarX::sNativeEventTarget = nil;
NSWindow* nsMenuBarX::sEventTargetWindow = nil;
BOOL gSomeMenuBarPainted = NO;
nsMenuBarX::nsMenuBarX()
: mNumMenus(0), mParent(nsnull), mIsMenuBarAdded(PR_FALSE), mCurrentCommandID(1), mDocument(nsnull)
@ -812,6 +812,9 @@ NS_IMETHODIMP nsMenuBarX::Paint()
[NSApp setMainMenu:mRootMenu];
nsMenuBarX::sEventTargetWindow = (NSWindow*)mParent->GetNativeData(NS_NATIVE_WINDOW);
gSomeMenuBarPainted = YES;
return NS_OK;
}