Changing Mac Help menu to be non-dynamic to prevent crashing on some machines.

This commit is contained in:
saari%netscape.com 1999-09-01 03:26:03 +00:00
Родитель 3159cc6efa
Коммит c01eb0253d
3 изменённых файлов: 127 добавлений и 27 удалений

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

@ -230,16 +230,6 @@ NS_METHOD nsMenu::SetLabel(const nsString &aText)
::HMGetHelpMenuHandle(&mMacMenuHandle);
mMacMenuID = kHMHelpMenuID;
if(mMacMenuHandle) {
SInt8 state = ::HGetState((Handle)mMacMenuHandle);
::HLock((Handle)mMacMenuHandle);
//gSystemMDEFHandle = (**mMacMenuHandle).menuProc;
(**mMacMenuHandle).menuProc = gMDEF;
(**mMacMenuHandle).menuWidth = -1;
(**mMacMenuHandle).menuHeight = -1;
::HSetState((Handle)mMacMenuHandle, state);
}
int numHelpItems = ::CountMItems(mMacMenuHandle);
for(int i=0; i<numHelpItems; ++i) {
mMenuItemVoidArray.AppendElement(nsnull);
@ -325,8 +315,13 @@ NS_METHOD nsMenu::AddMenuItem(nsIMenuItem * aMenuItem)
aMenuItem->GetLabel(label);
//printf("%s \n", label.ToNewCString());
mNumMenuItems++;
::InsertMenuItem(mMacMenuHandle, "\pa", mMenuItemVoidArray.Count());
NSStringSetMenuItemText(mMacMenuHandle, mMenuItemVoidArray.Count(), label);
if(mIsHelpMenu) {
::InsertMenuItem(mMacMenuHandle, c2pstr(label.ToNewCString()), mMenuItemVoidArray.Count());
} else {
::InsertMenuItem(mMacMenuHandle, "\pa", mMenuItemVoidArray.Count());
NSStringSetMenuItemText(mMacMenuHandle, mMenuItemVoidArray.Count(), label);
}
// I want to be internationalized too!
nsString keyEquivalent = " ";
@ -586,12 +581,24 @@ nsEventStatus nsMenu::MenuSelected(const nsMenuEvent & aMenuEvent)
if(mMacMenuHandle == selectedMenuHandle)
{
if(!mConstructed) {
MenuConstruct(
aMenuEvent,
nsnull, //mParentWindow
mDOMNode,
mWebShell);
mConstructed = true;
if(mIsHelpMenu) {
if( mConstructed )
RemoveAll();
HelpMenuConstruct(
aMenuEvent,
nsnull, //mParentWindow
mDOMNode,
mWebShell);
} else {
MenuConstruct(
aMenuEvent,
nsnull, //mParentWindow
mDOMNode,
mWebShell);
mConstructed = true;
}
} else {
//printf("Menu already constructed \n");
}
@ -717,6 +724,89 @@ nsEventStatus nsMenu::MenuConstruct(
return nsEventStatus_eIgnore;
}
//-------------------------------------------------------------------------
nsEventStatus nsMenu::HelpMenuConstruct(
const nsMenuEvent & aMenuEvent,
nsIWidget * aParentWindow,
void * menuNode,
void * aWebShell)
{
//printf("nsMenu::MenuConstruct called for %s = %d \n", mLabel.ToNewCString(), mMacMenuHandle);
// Begin menuitem inner loop
int numHelpItems = ::CountMItems(mMacMenuHandle);
for(int i=0; i<numHelpItems; ++i) {
mMenuItemVoidArray.AppendElement(nsnull);
}
// Open the node.
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(mDOMNode);
if (domElement)
domElement->SetAttribute("open", "true");
gCurrentMenuDepth++;
// Now get the kids. Retrieve our menupopup child.
nsCOMPtr<nsIDOMNode> menuPopupNode;
mDOMNode->GetFirstChild(getter_AddRefs(menuPopupNode));
while (menuPopupNode) {
nsCOMPtr<nsIDOMElement> menuPopupElement(do_QueryInterface(menuPopupNode));
if (menuPopupElement) {
nsString menuPopupNodeType;
menuPopupElement->GetNodeName(menuPopupNodeType);
if (menuPopupNodeType.Equals("menupopup"))
break;
}
nsCOMPtr<nsIDOMNode> oldMenuPopupNode(menuPopupNode);
oldMenuPopupNode->GetNextSibling(getter_AddRefs(menuPopupNode));
}
if (!menuPopupNode)
return nsEventStatus_eIgnore;
// Now get the kids
nsCOMPtr<nsIDOMNode> menuitemNode;
menuPopupNode->GetFirstChild(getter_AddRefs(menuitemNode));
unsigned short menuIndex = 0;
while (menuitemNode) {
nsCOMPtr<nsIDOMElement> menuitemElement(do_QueryInterface(menuitemNode));
if (menuitemElement) {
nsString menuitemNodeType;
nsString menuitemName;
nsString label;
menuitemElement->GetAttribute("value", label);
//printf("label = %s \n", label.ToNewCString());
menuitemElement->GetNodeName(menuitemNodeType);
if (menuitemNodeType.Equals("menuitem")) {
// LoadMenuItem
LoadMenuItem(this, menuitemElement, menuitemNode, menuIndex, (nsIWebShell*)aWebShell);
} else if (menuitemNodeType.Equals("menuseparator")) {
AddSeparator();
} else if (menuitemNodeType.Equals("menu")) {
// Load a submenu
LoadSubMenu(this, menuitemElement, menuitemNode);
}
}
++menuIndex;
nsCOMPtr<nsIDOMNode> oldmenuitemNode(menuitemNode);
oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode));
} // end menu item innner loop
//printf(" Done building, mMenuItemVoidArray.Count() = %d \n", mMenuItemVoidArray.Count());
gCurrentMenuDepth--;
//PreviousMenuStackUnwind(this, mMacMenuHandle);
//PushMenu(this);
return nsEventStatus_eIgnore;
}
//-------------------------------------------------------------------------
nsEventStatus nsMenu::MenuDestruct(const nsMenuEvent & aMenuEvent)
{

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

@ -126,6 +126,12 @@ void LoadSubMenu(
nsIDOMElement * menuElement,
nsIDOMNode * menuNode);
nsEventStatus HelpMenuConstruct(
const nsMenuEvent & aMenuEvent,
nsIWidget * aParentWindow,
void * menuNode,
void * aWebShell);
void NSStringSetMenuItemText(MenuHandle macMenuHandle, short menuItem, nsString& nsString);
MenuHandle NSStringNewMenu(short menuID, nsString& menuTitle);
MenuHandle NSStringNewChildMenu(short menuID, nsString& menuTitle);

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

@ -292,6 +292,15 @@ nsEventStatus nsMenuBar::MenuConstruct(
pnsMenu->SetAccessKey(menuAccessKey);
// Make nsMenu a child of nsMenuBar. nsMenuBar takes ownership
pnsMenuBar->AddMenu(pnsMenu);
if(menuName == "Help") {
nsMenuEvent event;
MenuHandle handle;
::HMGetHelpMenuHandle(&handle);
event.mCommand = (unsigned int) handle;
nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(pnsMenu));
listener->MenuSelected(event);
}
// Release the menu now that the menubar owns it
NS_RELEASE(pnsMenu);
@ -514,15 +523,10 @@ NS_METHOD nsMenuBar::Paint()
::HMGetHelpMenuHandle(&helpMenuHandle);
((nsIMenu*)mMenuVoidArray[i])->SetNativeData((void*)helpMenuHandle);
if(helpMenuHandle) {
SInt8 state = ::HGetState((Handle)helpMenuHandle);
::HLock((Handle)helpMenuHandle);
//gSystemMDEFHandle = (**mMacMenuHandle).menuProc;
(**helpMenuHandle).menuProc = gMDEF;
(**helpMenuHandle).menuWidth = -1;
(**helpMenuHandle).menuHeight = -1;
::HSetState((Handle)helpMenuHandle, state);
}
nsMenuEvent event;
event.mCommand = (unsigned int) helpMenuHandle;
nsCOMPtr<nsIMenuListener> listener(do_QueryInterface((nsIMenu*)mMenuVoidArray[i]));
listener->MenuSelected(event);
}
}
::DrawMenuBar();