Carbon menu code cleanup. b=312208 r=bent r=mento sr=pinkerton

This commit is contained in:
joshmoz%gmail.com 2005-10-14 22:44:39 +00:00
Родитель f5a9929b44
Коммит 251123170c
4 изменённых файлов: 46 добавлений и 112 удалений

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

@ -58,12 +58,6 @@
#include "nsIDOMDocument.h"
#include "nsWidgetAtoms.h"
#include <Menus.h>
#include <TextUtils.h>
#include <Balloons.h>
#include <Resources.h>
#include <Appearance.h>
#include "nsMacResources.h"
#include "nsGUIEvent.h"
@ -119,12 +113,10 @@ nsMenuBarX::MenuItemSelected(const nsMenuEvent & aMenuEvent)
PRUint32 numItems;
mMenusArray.Count(&numItems);
for (PRUint32 i = numItems; i > 0; --i)
{
for (PRUint32 i = numItems; i > 0; --i) {
nsCOMPtr<nsISupports> menuSupports = getter_AddRefs(mMenusArray.ElementAt(i - 1));
nsCOMPtr<nsIMenuListener> menuListener = do_QueryInterface(menuSupports);
if(menuListener)
{
if (menuListener) {
eventStatus = menuListener->MenuItemSelected(aMenuEvent);
if (nsEventStatus_eIgnore != eventStatus)
return eventStatus;
@ -140,34 +132,24 @@ nsMenuBarX::MenuSelected(const nsMenuEvent & aMenuEvent)
// Dispatch event
nsEventStatus eventStatus = nsEventStatus_eIgnore;
nsCOMPtr<nsIMenuListener> menuListener;
//((nsISupports*)mMenuVoidArray[i-1])->QueryInterface(NS_GET_IID(nsIMenuListener), (void**)&menuListener);
//printf("gPreviousMenuStack.Count() = %d \n", gPreviousMenuStack.Count());
if (menuListener) {
//TODO: MenuSelected is the right thing to call...
//eventStatus = menuListener->MenuSelected(aMenuEvent);
eventStatus = menuListener->MenuItemSelected(aMenuEvent);
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
PRUint32 numItems;
mMenusArray.Count(&numItems);
for (PRUint32 i = numItems; i > 0; --i)
// 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
PRUint32 numItems;
mMenusArray.Count(&numItems);
for (PRUint32 i = numItems; i > 0; --i)
{
nsCOMPtr<nsISupports> menuSupports = getter_AddRefs(mMenusArray.ElementAt(i - 1));
nsCOMPtr<nsIMenuListener> thisListener = do_QueryInterface(menuSupports);
if (thisListener)
{
nsCOMPtr<nsISupports> menuSupports = getter_AddRefs(mMenusArray.ElementAt(i - 1));
nsCOMPtr<nsIMenuListener> thisListener = do_QueryInterface(menuSupports);
if (thisListener)
{
//TODO: MenuSelected is the right thing to call...
//eventStatus = menuListener->MenuSelected(aMenuEvent);
eventStatus = thisListener->MenuItemSelected(aMenuEvent);
if(nsEventStatus_eIgnore != eventStatus)
return eventStatus;
}
//TODO: MenuSelected is the right thing to call...
//eventStatus = menuListener->MenuSelected(aMenuEvent);
eventStatus = thisListener->MenuItemSelected(aMenuEvent);
if(nsEventStatus_eIgnore != eventStatus)
return eventStatus;
}
}
return eventStatus;
}
@ -213,8 +195,6 @@ nsMenuBarX :: GetDocument ( nsIDocShell* inDocShell, nsIDocument** outDocument )
//
// RegisterAsDocumentObserver
//
// Name says it all.
//
void
nsMenuBarX :: RegisterAsDocumentObserver ( nsIDocShell* inDocShell )
{
@ -471,8 +451,6 @@ nsMenuBarX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWin
menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::id, menuIDstring);
if ( menuIDstring.EqualsLiteral("menu_Help") ) {
nsMenuEvent event(PR_TRUE, 0, nsnull);
MenuHandle handle = nsnull;
event.mCommand = (unsigned int) handle;
nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(pnsMenu));
listener->MenuSelected(event);
}
@ -655,27 +633,20 @@ NS_METHOD nsMenuBarX::RemoveMenu(const PRUint32 aCount)
NS_METHOD nsMenuBarX::RemoveAll()
{
NS_ASSERTION(0, "Not implemented!");
// mMenusArray.Clear(); // maybe?
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuBarX::GetNativeData(void *& aData)
{
aData = (void *) mRootMenu;
return NS_OK;
aData = (void *) mRootMenu;
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuBarX::SetNativeData(void* aData)
{
#if 0
Handle menubarHandle = (Handle)aData;
if (mMacMBarHandle && mMacMBarHandle != menubarHandle)
::DisposeHandle(mMacMBarHandle);
mMacMBarHandle = menubarHandle;
#endif
return NS_OK;
return NS_OK;
}
//-------------------------------------------------------------------------
@ -720,21 +691,17 @@ void
nsMenuBarX::ContentAppended( nsIDocument * aDocument, nsIContent * aContainer,
PRInt32 aNewIndexInContainer)
{
if ( aContainer == mMenuBarContent ) {
//Register(aContainer, );
//InsertMenu ( aNewIndexInContainer );
}
else {
if (aContainer != mMenuBarContent) {
nsCOMPtr<nsIChangeObserver> obs;
Lookup ( aContainer, getter_AddRefs(obs) );
if ( obs )
obs->ContentInserted ( aDocument, aContainer, aNewIndexInContainer );
Lookup(aContainer, getter_AddRefs(obs));
if (obs)
obs->ContentInserted(aDocument, aContainer, aNewIndexInContainer);
else {
nsCOMPtr<nsIContent> parent = aContainer->GetParent();
if(parent) {
Lookup ( parent, getter_AddRefs(obs) );
if ( obs )
obs->ContentInserted ( aDocument, aContainer, aNewIndexInContainer );
if (parent) {
Lookup(parent, getter_AddRefs(obs));
if (obs)
obs->ContentInserted(aDocument, aContainer, aNewIndexInContainer);
}
}
}
@ -787,21 +754,17 @@ void
nsMenuBarX::ContentInserted( nsIDocument * aDocument, nsIContent * aContainer,
nsIContent * aChild, PRInt32 aIndexInContainer )
{
if ( aContainer == mMenuBarContent ) {
//Register(aChild, );
//InsertMenu ( aIndexInContainer );
}
else {
if (aContainer != mMenuBarContent) {
nsCOMPtr<nsIChangeObserver> obs;
Lookup ( aContainer, getter_AddRefs(obs) );
if ( obs )
obs->ContentInserted ( aDocument, aChild, aIndexInContainer );
Lookup (aContainer, getter_AddRefs(obs));
if (obs)
obs->ContentInserted(aDocument, aChild, aIndexInContainer);
else {
nsCOMPtr<nsIContent> parent = aContainer->GetParent();
if(parent) {
Lookup ( parent, getter_AddRefs(obs) );
if ( obs )
obs->ContentInserted ( aDocument, aChild, aIndexInContainer );
if (parent) {
Lookup(parent, getter_AddRefs(obs));
if (obs)
obs->ContentInserted(aDocument, aChild, aIndexInContainer);
}
}
}

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

@ -49,12 +49,7 @@
#include "nsWeakReference.h"
#include "nsIContent.h"
#include <MacTypes.h>
#include <UnicodeConverter.h>
#include <Menus.h>
#include <CarbonEvents.h>
extern nsWeakPtr gMacMenubarX;
#include <Carbon/Carbon.h>
class nsIWidget;
class nsIDocument;

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

@ -64,10 +64,6 @@
#include "nsIXBLService.h"
#include "nsIServiceManager.h"
#include <Appearance.h>
#include <ToolUtils.h>
#include <UnicodeConverter.h>
#include "nsGUIEvent.h"
#include "nsCRT.h"
@ -75,13 +71,7 @@
static OSStatus InstallMyMenuEventHandler(MenuRef menuRef, void* userData, EventHandlerRef* outHandler) ;
// keep track of the menuID of the menu the mouse is currently over. Yes, this is ugly,
// but necessary to work around bugs in Carbon with ::MenuSelect() sometimes returning
// the wrong menuID.
static MenuID gCurrentlyTrackedMenuID = 0;
const PRInt16 kMacMenuIDX = nsMenuBarX::kAppleMenuID + 1;
static PRInt16 gMacMenuIDCountX = kMacMenuIDX;
static PRInt16 gMacMenuIDCountX = nsMenuBarX::kAppleMenuID + 1;
static PRBool gConstructingMenu = PR_FALSE;
#if DEBUG
@ -754,20 +744,12 @@ static pascal OSStatus MyMenuEventHandler(EventHandlerCallRef myHandler, EventRe
nsMenuEvent menuEvent(PR_TRUE, NS_MENU_SELECTED, nsnull);
menuEvent.time = PR_IntervalNow();
menuEvent.mCommand = (PRUint32) menuRef;
if (kind == kEventMenuOpening) {
gCurrentlyTrackedMenuID = ::GetMenuID(menuRef); // remember which menu ID we're over for later
if (kind == kEventMenuOpening)
listener->MenuSelected(menuEvent);
}
else
listener->MenuDeselected(menuEvent);
}
}
else if ( kind == kEventMenuTargetItem ) {
// remember which menu ID we're over for later
MenuRef menuRef;
::GetEventParameter(event, kEventParamDirectObject, typeMenuRef, NULL, sizeof(menuRef), NULL, &menuRef);
gCurrentlyTrackedMenuID = ::GetMenuID(menuRef);
}
return result;
}
@ -1269,19 +1251,19 @@ nsMenuX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIAtom
nsCOMPtr<nsIMenuBar> menubarParent = do_QueryInterface(mParent);
if(aAttribute == nsWidgetAtoms::disabled) {
if (aAttribute == nsWidgetAtoms::disabled) {
SetRebuild(PR_TRUE);
nsAutoString valueString;
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, valueString);
if(valueString.EqualsLiteral("true"))
if (valueString.EqualsLiteral("true"))
SetEnabled(PR_FALSE);
else
SetEnabled(PR_TRUE);
::DrawMenuBar();
}
else if(aAttribute == nsWidgetAtoms::label) {
else if (aAttribute == nsWidgetAtoms::label) {
SetRebuild(PR_TRUE);
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, mLabel);
@ -1305,7 +1287,7 @@ nsMenuX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIAtom
::DrawMenuBar();
}
}
else if(aAttribute == nsWidgetAtoms::hidden || aAttribute == nsWidgetAtoms::collapsed) {
else if (aAttribute == nsWidgetAtoms::hidden || aAttribute == nsWidgetAtoms::collapsed) {
SetRebuild(PR_TRUE);
nsAutoString hiddenValue, collapsedValue;

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

@ -45,17 +45,12 @@
#include "nsIChangeManager.h"
#include "nsWeakReference.h"
#include <Menus.h>
#include <UnicodeConverter.h>
#include <CarbonEvents.h>
#include <Carbon/Carbon.h>
class nsIMenuBar;
class nsIMenuListener;
//static PRInt16 mMacMenuIDCount; // use GetUniqueMenuID()
extern PRInt16 mMacMenuIDCount;// = kMacMenuID;
extern PRInt16 mMacMenuIDCount;
#if DEBUG
// utility instance counter class
@ -70,7 +65,7 @@ public:
~nsInstanceCounter()
{
printf("%s %ld\n", mDescription, mInstanceCount);
printf("%s %d\n", mDescription, mInstanceCount);
}
nsInstanceCounter& operator ++() // prefix
@ -140,7 +135,6 @@ public:
NS_IMETHOD GetEnabled(PRBool* aIsEnabled);
NS_IMETHOD IsHelpMenu(PRBool* aIsEnabled);
//
NS_IMETHOD AddMenuItem(nsIMenuItem * aMenuItem);
NS_IMETHOD AddMenu(nsIMenu * aMenu);