fix for 14346, 21854, 24380 and other caret bugs. r= hyatt, brade for the mac menu stuff.

This commit is contained in:
saari%netscape.com 2000-01-26 22:41:43 +00:00
Родитель 40418ec739
Коммит 7ce4f57ec3
4 изменённых файлов: 123 добавлений и 29 удалений

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

@ -43,6 +43,10 @@ public:
NS_IMETHOD GetLocation(nsIDOMLocation** aLocation) = 0;
NS_IMETHOD GetWebShell(nsIWebShell **aWebShell) =0;// XXX This may be temporary - rods
// This is private because activate/deactivate events are not part of the DOM spec.
NS_IMETHOD Activate() = 0;
NS_IMETHOD Deactivate() = 0;
};
#endif // nsPIDOMWindow_h__

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

@ -59,6 +59,7 @@ const PRInt16 kAppleMenuID = 1;
PRInt16 gMenuDepth = 0;
PRInt16 gCurrentMenuDepth = 1;
extern nsIMenuBar * gMacMenubar;
extern Handle gMDEF; // Our stub MDEF
extern Handle gSystemMDEFHandle;
PRInt16 mMacMenuIDCount = kMacMenuID;
@ -127,6 +128,7 @@ nsMenu::nsMenu() : nsIMenu()
mMacMenuID = 0;
mMacMenuHandle = nsnull;
mIsHelpMenu = PR_FALSE;
mHelpMenuOSItemsCount = 0;
mIsEnabled = PR_TRUE;
mListener = nsnull;
mConstructed = nsnull;
@ -199,7 +201,7 @@ NS_METHOD nsMenu::Create(nsISupports *aParent, const nsString &aLabel)
aParent->QueryInterface(kIMenuBarIID, (void**) &menubar);
if(menubar)
{
mMenuBarParent = menubar;;
mMenuBarParent = menubar;
NS_RELEASE(menubar); // Balance the QI
}
else
@ -255,17 +257,24 @@ NS_METHOD nsMenu::SetLabel(const nsString &aText)
mMacMenuHandle = ::GetMenuHandle(mMacMenuID);
} else {
// Look at the label and figure out if it is the "Help" menu
if(mLabel == "Help"){
if(mDOMElement) {
nsString menuIDstring;
mDOMElement->GetAttribute(nsAutoString("id"), menuIDstring);
if(menuIDstring == "menu_Help") {
mIsHelpMenu = PR_TRUE;
::HMGetHelpMenuHandle(&mMacMenuHandle);
mMacMenuID = kHMHelpMenuID;
int numHelpItems = ::CountMItems(mMacMenuHandle);
for(int i=0; i<numHelpItems; ++i) {
mMenuItemVoidArray.AppendElement(nsnull);
}
if ( mHelpMenuOSItemsCount == 0)
mHelpMenuOSItemsCount = numHelpItems;
for(int i=0; i<numHelpItems; ++i) {
mMenuItemVoidArray.AppendElement(nsnull);
}
return NS_OK;
}
}
mMacMenuHandle = NSStringNewMenu(mMacMenuIDCount, mLabel);
@ -467,6 +476,13 @@ NS_METHOD nsMenu::RemoveItem(const PRUint32 aPos)
//-------------------------------------------------------------------------
NS_METHOD nsMenu::RemoveAll()
{
#ifdef notdef
MenuHandle helpmh;
::HMGetHelpMenuHandle(&helpmh);
if ( helpmh != mMacMenuHandle)
helpmh = nsnull;
#endif
while(mMenuItemVoidArray.Count())
{
--mNumMenuItems;
@ -493,7 +509,11 @@ NS_METHOD nsMenu::RemoveAll()
}
}
}
/* don't delete the actual Mac menu item if it's a MacOS item */
if ( (mMenuItemVoidArray.Count() - mHelpMenuOSItemsCount) > 0)
{
::DeleteMenuItem(mMacMenuHandle, mMenuItemVoidArray.Count());
}
mMenuItemVoidArray.RemoveElementAt(mMenuItemVoidArray.Count() - 1);
}
return NS_OK;
@ -558,9 +578,62 @@ nsEventStatus nsMenu::MenuItemSelected(const nsMenuEvent & aMenuEvent)
#endif
eventStatus = nsEventStatus_eConsumeNoDefault;
}
else if (menuItemID == 1)
{
/* handle about app here */
}
}
else
#endif
if ((kHMHelpMenuID == menuID) && (menuID != mMacMenuID))
{
/* 'this' is not correct; we need to find the help nsMenu */
nsIMenuBar *mb = mMenuBarParent;
if ( mb == nsnull )
{
mb = gMacMenubar;
if ( mb == nsnull )
{
return nsEventStatus_eIgnore;
}
}
/* set up a default event to query with */
nsMenuEvent event;
MenuHandle handle;
::HMGetHelpMenuHandle(&handle);
event.mCommand = (unsigned int) handle;
/* loop through the top-level menus in the menubar */
PRUint32 numMenus = 0;
mb->GetMenuCount(numMenus);
numMenus--;
for (PRInt32 i = numMenus; i >= 0; i--)
{
nsIMenu * menu = nsnull;
mb->GetMenuAt(i, menu);
if (menu)
{
nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(menu));
if (listener)
{
nsString label;
menu->GetLabel(label);
/* ask if this is the right menu */
eventStatus = listener->MenuSelected(event);
if(eventStatus != nsEventStatus_eIgnore)
{
/* call back into this method with the proper "this" */
eventStatus = listener->MenuItemSelected(aMenuEvent);
NS_RELEASE(menu);
return eventStatus;
}
}
NS_RELEASE(menu);
}
}
}
else
if(mMacMenuID == menuID)
{
@ -613,16 +686,19 @@ nsEventStatus nsMenu::MenuSelected(const nsMenuEvent & aMenuEvent)
if(mMacMenuHandle == selectedMenuHandle)
{
if (mIsHelpMenu && mConstructed){
RemoveAll();
mConstructed = false;
}
if(!mConstructed) {
if(mIsHelpMenu) {
if( mConstructed )
RemoveAll();
HelpMenuConstruct(
aMenuEvent,
nsnull, //mParentWindow
mDOMNode,
mWebShell);
mConstructed = true;
} else {
MenuConstruct(
aMenuEvent,

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

@ -172,6 +172,7 @@ protected:
MenuHandle mMacMenuHandle;
nsIMenuListener * mListener;
UnicodeToTextRunInfo mUnicodeTextRunConverter;
PRInt16 mHelpMenuOSItemsCount;
PRBool mIsHelpMenu;
PRBool mIsEnabled;

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

@ -145,22 +145,34 @@ nsEventStatus nsMenuBar::MenuSelected(const nsMenuEvent & aMenuEvent)
// Dispatch event
nsEventStatus eventStatus = nsEventStatus_eIgnore;
//for (int i = mMenuVoidArray.Count(); i > 0; --i)
//{
nsIMenuListener * menuListener = nsnull;
//((nsISupports*)mMenuVoidArray[i-1])->QueryInterface(kIMenuListenerIID, &menuListener);
//printf("gPreviousMenuStack.Count() = %d \n", gPreviousMenuStack.Count());
if(gPreviousMenuStack[gPreviousMenuStack.Count() - 1])
((nsIMenu*)gPreviousMenuStack[gPreviousMenuStack.Count() - 1])->QueryInterface(kIMenuListenerIID, &menuListener);
if(menuListener){
//TODO: MenuSelected is the right thing to call...
//eventStatus = menuListener->MenuSelected(aMenuEvent);
eventStatus = menuListener->MenuItemSelected(aMenuEvent);
NS_RELEASE(menuListener);
if(nsEventStatus_eIgnore != eventStatus)
return eventStatus;
nsIMenuListener * menuListener = nsnull;
//((nsISupports*)mMenuVoidArray[i-1])->QueryInterface(kIMenuListenerIID, &menuListener);
//printf("gPreviousMenuStack.Count() = %d \n", gPreviousMenuStack.Count());
if (gPreviousMenuStack[gPreviousMenuStack.Count() - 1])
((nsIMenu*)gPreviousMenuStack[gPreviousMenuStack.Count() - 1])->QueryInterface(kIMenuListenerIID, &menuListener);
if (menuListener) {
//TODO: MenuSelected is the right thing to call...
//eventStatus = menuListener->MenuSelected(aMenuEvent);
eventStatus = menuListener->MenuItemSelected(aMenuEvent);
NS_RELEASE(menuListener);
if (nsEventStatus_eIgnore != eventStatus)
return eventStatus;
} else {
// If it's the help menu, gPreviousMenuStack won't be accurate so we need to get the listener a different way
// We'll do it the old fashioned way of looping through and finding it
for (int i = mMenuVoidArray.Count(); i > 0; --i) {
((nsISupports*)mMenuVoidArray[i-1])->QueryInterface(kIMenuListenerIID, &menuListener);
if (menuListener) {
//TODO: MenuSelected is the right thing to call...
//eventStatus = menuListener->MenuSelected(aMenuEvent);
eventStatus = menuListener->MenuItemSelected(aMenuEvent);
NS_RELEASE(menuListener);
if(nsEventStatus_eIgnore != eventStatus)
return eventStatus;
}
}
//}
}
return eventStatus;
}
@ -297,7 +309,9 @@ nsEventStatus nsMenuBar::MenuConstruct(
// Make nsMenu a child of nsMenuBar. nsMenuBar takes ownership
pnsMenuBar->AddMenu(pnsMenu);
if(menuName == "Help") {
nsString menuIDstring;
menuElement->GetAttribute(nsAutoString("id"), menuIDstring);
if(menuIDstring == "menu_Help") {
nsMenuEvent event;
MenuHandle handle;
::HMGetHelpMenuHandle(&handle);
@ -443,7 +457,7 @@ NS_METHOD nsMenuBar::AddMenu(nsIMenu * aMenu)
if (appleMenu)
{
::AppendMenu(appleMenu, "\pAbout ApprunnerÉ");
::AppendMenu(appleMenu, "\pAbout Apprunner");
::AppendMenu(appleMenu, "\p-");
::AppendResMenu(appleMenu, 'DRVR');
::InsertMenu(appleMenu, 0);
@ -523,14 +537,13 @@ NS_METHOD nsMenuBar::SetNativeData(void* aData)
NS_METHOD nsMenuBar::Paint()
{
gMacMenubar = this;
PRBool isHelpMenu;
::SetMenuBar(mMacMBarHandle);
// Now we have blown away the merged Help menu, so we have to rebuild it
for(int i = mMenuVoidArray.Count()-1; i>=0; --i) {
nsString label;
((nsIMenu*)mMenuVoidArray[i])->GetLabel(label);
// Look at the label and figure out if it is the "Help" menu
if(label == "Help"){
((nsIMenu*)mMenuVoidArray[i])->IsHelpMenu(&isHelpMenu);
if(isHelpMenu){
MenuHandle helpMenuHandle;
::HMGetHelpMenuHandle(&helpMenuHandle);
((nsIMenu*)mMenuVoidArray[i])->SetNativeData((void*)helpMenuHandle);