fix menu bar for menubarless dialogs. b=355138 r=hwaara r=mento sr=pinkerton

This commit is contained in:
joshmoz%gmail.com 2006-12-19 19:26:41 +00:00
Родитель d6d8c693f4
Коммит a02ce87de5
4 изменённых файлов: 80 добавлений и 14 удалений

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

@ -57,6 +57,7 @@ class nsChildView;
- (void)windowDidResize:(NSNotification*)aNotification;
- (void)sendGotFocusAndActivate;
- (void)sendLostFocusAndDeactivate;
- (nsCocoaWindow*)geckoWidget;
@end

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

@ -49,7 +49,10 @@
#include "nsIInterfaceRequestorUtils.h"
#include "nsIXULWindow.h"
// externs defined in nsChildView.mm
// defined in nsMenuBarX.mm
extern NSMenu* sApplicationMenu; // Application menu shared by all menubars
// defined in nsChildView.mm
extern nsIRollupListener * gRollupListener;
extern nsIWidget * gRollupWidget;
extern BOOL gSomeMenuBarPainted;
@ -1038,6 +1041,52 @@ NS_IMETHODIMP nsCocoaWindow::GetAttention(PRInt32 aCycleCount)
@implementation WindowDelegate
// We try to find a gecko menu bar to paint. If one does not exist, just paint
// the application menu by itself so that a window doesn't have some other
// window's menu bar.
+ (void)paintMenubarForWindow:(NSWindow*)aWindow
{
// make sure we only act on windows that have this kind of
// object as a delegate
id windowDelegate = [aWindow delegate];
if ([windowDelegate class] != [self class])
return;
nsCocoaWindow* geckoWidget = [windowDelegate geckoWidget];
NS_ASSERTION(geckoWidget, "Window delegate not returning a gecko widget!");
nsIMenuBar* geckoMenuBar = geckoWidget->GetMenuBar();
if (geckoMenuBar) {
geckoMenuBar->Paint();
}
else {
// we are definitely going to need an application menu here, and we can't
// create one ourselves
NS_ASSERTION(sApplicationMenu, "No native application menu and we need one!");
// create a new menu bar with one item
NSMenu* newMenuBar = [[NSMenu alloc] init];
NSMenuItem* newMenuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[newMenuBar addItem:newMenuItem];
[newMenuItem release];
// Attach application menu as submenu for our one menu item. If the application
// menu has a supermenu, we need to disconnect it from its parent before hooking
// it up to the new menu bar
NSMenu* appMenuSupermenu = [sApplicationMenu supermenu];
if (appMenuSupermenu) {
int appMenuItemIndex = [appMenuSupermenu indexOfItemWithSubmenu:sApplicationMenu];
[[appMenuSupermenu itemAtIndex:appMenuItemIndex] setSubmenu:nil];
}
[newMenuItem setSubmenu:sApplicationMenu];
// set our new menu bar as the main menu
[NSApp setMainMenu:newMenuBar];
[newMenuBar release];
}
}
- (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind
{
[super init];
@ -1070,14 +1119,9 @@ NS_IMETHODIMP nsCocoaWindow::GetAttention(PRInt32 aCycleCount)
- (void)windowDidBecomeMain:(NSNotification *)aNotification
{
if (!mGeckoWindow)
return;
nsIMenuBar* myMenuBar = mGeckoWindow->GetMenuBar();
if (myMenuBar) {
// printf("painting window menu bar due to window becoming main\n");
myMenuBar->Paint();
}
NSWindow* window = [aNotification object];
if (window)
[WindowDelegate paintMenubarForWindow:window];
}
@ -1095,6 +1139,24 @@ NS_IMETHODIMP nsCocoaWindow::GetAttention(PRInt32 aCycleCount)
}
- (void)windowDidBecomeKey:(NSNotification *)aNotification
{
NSWindow* window = [aNotification object];
if ([window isSheet])
[WindowDelegate paintMenubarForWindow:window];
}
- (void)windowDidResignKey:(NSNotification *)aNotification
{
// If a sheet just resigned key then we should paint the menu bar
// for whatever window is now main.
NSWindow* window = [aNotification object];
if ([window isSheet])
[WindowDelegate paintMenubarForWindow:[NSApp mainWindow]];
}
- (void)windowWillMove:(NSNotification *)aNotification
{
// roll up any popups
@ -1175,4 +1237,10 @@ NS_IMETHODIMP nsCocoaWindow::GetAttention(PRInt32 aCycleCount)
}
- (nsCocoaWindow*)geckoWidget;
{
return mGeckoWindow;
}
@end

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

@ -164,9 +164,7 @@ protected:
nsWeakPtr mDocShellWeakRef; // weak ref to docshell
nsIDocument* mDocument; // pointer to document
NSMenu* mRootMenu; // root menu, representing entire menu bar.
static NSMenu* sApplicationMenu; // Application menu shared by all menubars
NSMenu* mRootMenu; // root menu, representing entire menu bar
static EventHandlerUPP sCommandEventHandler; // carbon event handler for commands, shared
};

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

@ -69,11 +69,10 @@ static NS_DEFINE_CID(kMenuCID, NS_MENU_CID);
NS_IMPL_ISUPPORTS6(nsMenuBarX, nsIMenuBar, nsIMenuListener, nsIMutationObserver,
nsIChangeManager, nsIMenuCommandDispatcher, nsISupportsWeakReference)
NSMenu* nsMenuBarX::sApplicationMenu = nsnull;
EventHandlerUPP nsMenuBarX::sCommandEventHandler = nsnull;
NativeMenuItemTarget* nsMenuBarX::sNativeEventTarget = nil;
NSWindow* nsMenuBarX::sEventTargetWindow = nil;
NSMenu* sApplicationMenu = nil;
BOOL gSomeMenuBarPainted = NO;