Chages to nsIMenu and nsIMenuItem for checkbox support and a more general way of IDing the Help menu (necessary for MacOS).

This commit is contained in:
saari%netscape.com 1999-09-02 23:48:39 +00:00
Родитель bdda0f539f
Коммит c903641346
16 изменённых файлов: 222 добавлений и 16 удалений

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

@ -86,6 +86,18 @@ class nsIMenu : public nsISupports {
*/
NS_IMETHOD SetEnabled(PRBool aIsEnabled) = 0;
/**
* Get the Menu enabled state
*
*/
NS_IMETHOD GetEnabled(PRBool* aIsEnabled) = 0;
/**
* Query if this is the help menu. Mostly for MacOS voodoo.
*
*/
NS_IMETHOD IsHelpMenu(PRBool* aIsHelpMenu) = 0;
/**
* Adds a Menu Item
*

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

@ -97,17 +97,29 @@ class nsIMenuItem : public nsISupports {
NS_IMETHOD GetEnabled(PRBool *aIsEnabled) = 0;
/**
* Sets whether the item is enabled or disabled
* Sets whether the item is checked or not
*
*/
NS_IMETHOD SetChecked(PRBool aIsEnabled) = 0;
/**
* Gets whether the item is enabled or disabled
* Gets whether the item is checked or not
*
*/
NS_IMETHOD GetChecked(PRBool *aIsEnabled) = 0;
/**
* Sets whether the item is a checkbox type
*
*/
NS_IMETHOD SetCheckboxType(PRBool aIsCheckbox) = 0;
/**
* Gets whether the item is a checkbox type
*
*/
NS_IMETHOD GetCheckboxType(PRBool *aIsCheckbox) = 0;
/**
* Gets the MenuItem Command identifier
*

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

@ -209,6 +209,26 @@ NS_METHOD nsMenu::SetEnabled(PRBool aIsEnabled)
return NS_OK;
}
//-------------------------------------------------------------------------
/**
* Get enabled state
*
*/
NS_METHOD nsMenu::GetEnabled(PRBool* aIsEnabled)
{
return NS_OK;
}
//-------------------------------------------------------------------------
/**
* Query if this is the help menu
*
*/
NS_METHOD nsMenu::IsHelpMenu(PRBool* aIsHelpMenu)
{
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenu::AddItem(nsISupports * aItem)
{

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

@ -74,7 +74,9 @@ public:
NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener);
NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener);
NS_IMETHOD SetEnabled(PRBool aIsEnabled);
NS_IMETHOD GetEnabled(PRBool* aIsEnabled);
NS_IMETHOD IsHelpMenu(PRBool* aIsHelp);
NS_IMETHOD SetDOMNode(nsIDOMNode * aMenuNode);
NS_IMETHOD SetDOMElement(nsIDOMElement * aMenuElement);
NS_IMETHOD SetWebShell(nsIWebShell * aWebShell);

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

@ -314,6 +314,18 @@ NS_METHOD nsMenuItem::GetChecked(PRBool *aIsEnabled)
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::SetCheckboxType(PRBool aIsCheckbox)
{
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::GetCheckboxType(PRBool *aIsCheckbox)
{
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::GetCommand(PRUint32 & aCommand)
{

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

@ -54,6 +54,8 @@ public:
NS_IMETHOD GetEnabled(PRBool *aIsEnabled);
NS_IMETHOD SetChecked(PRBool aIsEnabled);
NS_IMETHOD GetChecked(PRBool *aIsEnabled);
NS_IMETHOD SetCheckboxType(PRBool aIsCheckbox);
NS_IMETHOD GetCheckboxType(PRBool *aIsCheckbox);
NS_IMETHOD GetCommand(PRUint32 & aCommand);
NS_IMETHOD GetTarget(nsIWidget *& aTarget);
NS_IMETHOD GetNativeData(void*& aData);

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

@ -153,8 +153,46 @@ pascal void nsDynamicMDEFMain(
//printf(" Point.v = %d Point.h = %d \n", hitPt.v, hitPt.h);
//printf(" whichItem = %d \n", *whichItem);
//printf(" theMenu.menuID = %d \n", (**theMenu).menuID);
nsCheckDestroy(theMenu, whichItem);
// Need to make sure that we rebuild the menu every time...
if (gPreviousMenuHandleStack.Count()) {
nsIMenu * menu = (nsIMenu *) gPreviousMenuStack[gPreviousMenuStack.Count() - 1];
MenuHandle menuHandle = (MenuHandle) gPreviousMenuHandleStack[gPreviousMenuHandleStack.Count() - 1];
//printf(" gPreviousMenuStack.Count() = %d \n", gPreviousMenuStack.Count());
//printf(" gPreviousMenuHandleStack.Count() = %d \n", gPreviousMenuHandleStack.Count());
if( menu && menuHandle ) {
if( menuHandle == theMenu ) {
nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(menu));
if(listener) {
//printf("MenuPop \n");
nsMenuEvent mevent;
mevent.message = NS_MENU_SELECTED;
mevent.eventStructType = NS_MENU_EVENT;
mevent.point.x = 0;
mevent.point.y = 0;
mevent.widget = nsnull;
mevent.time = PR_IntervalNow();
mevent.mCommand = (PRUint32) nsnull;
// UNDO
listener->MenuDeselected(mevent);
gPreviousMenuStack.RemoveElementAt(gPreviousMenuStack.Count() - 1);
//printf("%d items now on gPreviousMenuStack \n", gPreviousMenuStack.Count());
gPreviousMenuHandleStack.RemoveElementAt(gPreviousMenuHandleStack.Count() - 1);
}
}
}
}
nsDynamicSizeTheMenu(theMenu);
break;
}

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

@ -123,6 +123,7 @@ nsMenu::nsMenu() : nsIMenu()
mMacMenuID = 0;
mMacMenuHandle = nsnull;
mIsHelpMenu = PR_FALSE;
mIsEnabled = PR_TRUE;
mListener = nsnull;
mConstructed = nsnull;
@ -869,6 +870,8 @@ nsEventStatus nsMenu::MenuDestruct(const nsMenuEvent & aMenuEvent)
*/
NS_METHOD nsMenu::SetEnabled(PRBool aIsEnabled)
{
mIsEnabled = aIsEnabled;
if(aIsEnabled)
::EnableItem(mMacMenuHandle, 0);
else
@ -877,6 +880,29 @@ NS_METHOD nsMenu::SetEnabled(PRBool aIsEnabled)
return NS_OK;
}
//-------------------------------------------------------------------------
/**
* Get enabled state
*
*/
NS_METHOD nsMenu::GetEnabled(PRBool* aIsEnabled)
{
*aIsEnabled = mIsEnabled;
return NS_OK;
}
//-------------------------------------------------------------------------
/**
* Query if this is the help menu
*
*/
NS_METHOD nsMenu::IsHelpMenu(PRBool* aIsHelpMenu)
{
*aIsHelpMenu = mIsHelpMenu;
return NS_OK;
}
//-------------------------------------------------------------------------
/**
@ -1113,11 +1139,13 @@ void nsMenu::LoadMenuItem(
static const char* NS_STRING_TRUE = "true";
nsString disabled;
nsString checked;
nsString type;
nsString menuitemName;
nsString menuitemCmd;
menuitemElement->GetAttribute(nsAutoString("disabled"), disabled);
menuitemElement->GetAttribute(nsAutoString("checked"), checked);
menuitemElement->GetAttribute(nsAutoString("type"), type);
menuitemElement->GetAttribute(nsAutoString("value"), menuitemName);
menuitemElement->GetAttribute(nsAutoString("cmd"), menuitemCmd);
// Create nsMenuItem
@ -1220,6 +1248,11 @@ void nsMenu::LoadMenuItem(
else
pnsMenuItem->SetChecked(PR_FALSE);
if(type == "checkbox")
pnsMenuItem->SetCheckboxType(PR_TRUE);
else
pnsMenuItem->SetCheckboxType(PR_FALSE);
nsISupports * supports = nsnull;
pnsMenuItem->QueryInterface(kISupportsIID, (void**) &supports);
pParentMenu->AddItem(supports); // Parent should now own menu item

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

@ -84,6 +84,8 @@ public:
NS_IMETHOD SetDOMElement(nsIDOMElement * aMenuElement);
NS_IMETHOD SetWebShell(nsIWebShell * aWebShell);
NS_IMETHOD SetEnabled(PRBool aIsEnabled);
NS_IMETHOD GetEnabled(PRBool* aIsEnabled);
NS_IMETHOD IsHelpMenu(PRBool* aIsEnabled);
//
NS_IMETHOD AddMenuItem(nsIMenuItem * aMenuItem);
@ -166,6 +168,7 @@ protected:
nsIMenuListener * mListener;
UnicodeToTextRunInfo mUnicodeTextRunConverter;
PRBool mIsHelpMenu;
PRBool mIsEnabled;
void LoadMenuItem(
nsIMenu * pParentMenu,

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

@ -363,6 +363,7 @@ nsMenuBar::nsMenuBar() : nsIMenuBar(), nsIMenuListener()
mOriginalMacMBarHandle = nsnull;
mMacMBarHandle = nsnull;
mOriginalMacMBarHandle = ::GetMenuBar();
Handle tmp = ::GetMenuBar();
::SetMenuBar(tmp);
this->SetNativeData((void*)tmp);
@ -386,6 +387,9 @@ nsMenuBar::~nsMenuBar()
nsISupports* menu = (nsISupports*)mMenuVoidArray[mNumMenus];
NS_IF_RELEASE( menu );
}
::SetMenuBar(mOriginalMacMBarHandle);
::DisposeHandle(mMacMBarHandle);
::DisposeHandle(mOriginalMacMBarHandle);
}
//-------------------------------------------------------------------------
@ -447,7 +451,10 @@ NS_METHOD nsMenuBar::AddMenu(nsIMenu * aMenu)
aMenu->GetNativeData(&menuHandle);
mNumMenus++;
::InsertMenu(menuHandle, 0);
PRBool helpMenu;
aMenu->IsHelpMenu(&helpMenu);
if(!helpMenu)
::InsertMenu(menuHandle, 0);
return NS_OK;
}
@ -503,6 +510,7 @@ NS_METHOD nsMenuBar::GetNativeData(void *& aData)
//-------------------------------------------------------------------------
NS_METHOD nsMenuBar::SetNativeData(void* aData)
{
if(mMacMBarHandle) ::DisposeHandle(mMacMBarHandle);
mMacMBarHandle = (Handle) aData;
return NS_OK;
}

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

@ -75,17 +75,18 @@ nsMenuItem::nsMenuItem() : nsIMenuItem()
{
NS_INIT_REFCNT();
//mMenu = nsnull;
mMenuParent = nsnull;
mPopUpParent = nsnull;
mTarget = nsnull;
mMenuParent = nsnull;
mPopUpParent = nsnull;
mTarget = nsnull;
mXULCommandListener = nsnull;
mIsSeparator = PR_FALSE;
mWebShell = nsnull;
mDOMElement = nsnull;
mDOMNode = nsnull;
mKeyEquivalent = " ";
mEnabled = PR_TRUE;
mIsChecked = PR_FALSE;
mIsSeparator = PR_FALSE;
mWebShell = nsnull;
mDOMElement = nsnull;
mDOMNode = nsnull;
mKeyEquivalent = " ";
mEnabled = PR_TRUE;
mIsChecked = PR_FALSE;
mIsCheckboxType = PR_FALSE;
}
//-------------------------------------------------------------------------
@ -268,6 +269,13 @@ NS_METHOD nsMenuItem::GetEnabled(PRBool *aIsEnabled)
NS_METHOD nsMenuItem::SetChecked(PRBool aIsEnabled)
{
mIsChecked = aIsEnabled;
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(mDOMNode);
if (domElement) {
if(mIsChecked)
domElement->SetAttribute("checked", "true");
else
domElement->SetAttribute("checked", "false");
}
return NS_OK;
}
@ -278,6 +286,20 @@ NS_METHOD nsMenuItem::GetChecked(PRBool *aIsEnabled)
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::SetCheckboxType(PRBool aIsCheckbox)
{
mIsCheckboxType = aIsCheckbox;
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::GetCheckboxType(PRBool *aIsCheckbox)
{
*aIsCheckbox = mIsCheckboxType;
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::GetCommand(PRUint32 & aCommand)
{
@ -326,6 +348,9 @@ NS_METHOD nsMenuItem::IsSeparator(PRBool & aIsSep)
//-------------------------------------------------------------------------
nsEventStatus nsMenuItem::MenuItemSelected(const nsMenuEvent & aMenuEvent)
{
if(mIsCheckboxType) {
SetChecked(!mIsChecked);
}
DoCommand();
return nsEventStatus_eConsumeNoDefault;
}

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

@ -54,6 +54,8 @@ public:
NS_IMETHOD GetEnabled(PRBool *aIsEnabled);
NS_IMETHOD SetChecked(PRBool aIsEnabled);
NS_IMETHOD GetChecked(PRBool *aIsEnabled);
NS_IMETHOD SetCheckboxType(PRBool aIsCheckbox);
NS_IMETHOD GetCheckboxType(PRBool *aIsCheckbox);
NS_IMETHOD GetCommand(PRUint32 & aCommand);
NS_IMETHOD GetTarget(nsIWidget *& aTarget);
NS_IMETHOD GetNativeData(void*& aData);
@ -113,6 +115,7 @@ protected:
PRUint8 mModifiers;
PRBool mEnabled;
PRBool mIsChecked;
PRBool mIsCheckboxType;
};
#endif // nsMenuItem_h__

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

@ -207,6 +207,26 @@ NS_METHOD nsMenu::SetEnabled(PRBool aIsEnabled)
return NS_OK;
}
//-------------------------------------------------------------------------
/**
* Get enabled state
*
*/
NS_METHOD nsMenu::GetEnabled(PRBool* aIsEnabled)
{
return NS_OK;
}
//-------------------------------------------------------------------------
/**
* Query if this is the help menu
*
*/
NS_METHOD nsMenu::IsHelpMenu(PRBool* aIsHelpMenu)
{
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenu::AddItem(nsISupports * aItem)

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

@ -63,7 +63,9 @@ public:
NS_IMETHOD GetAccessKey(nsString &aText);
NS_IMETHOD SetAccessKey(const nsString &aText);
NS_IMETHOD SetEnabled(PRBool aIsEnabled);
NS_IMETHOD GetEnabled(PRBool* aIsEnabled);
NS_IMETHOD IsHelpMenu(PRBool* aIsHelp);
NS_IMETHOD AddItem(nsISupports * aItem);
NS_IMETHOD AddSeparator();

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

@ -301,6 +301,18 @@ NS_METHOD nsMenuItem::GetChecked(PRBool *aIsEnabled)
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::SetCheckboxType(PRBool aIsCheckbox)
{
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::GetCheckboxType(PRBool *aIsCheckbox)
{
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsMenuItem::GetDOMNode(nsIDOMNode ** aDOMNode)
{

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

@ -64,6 +64,8 @@ public:
NS_IMETHOD GetEnabled(PRBool *aIsEnabled);
NS_IMETHOD SetChecked(PRBool aIsEnabled);
NS_IMETHOD GetChecked(PRBool *aIsEnabled);
NS_IMETHOD SetCheckboxType(PRBool aIsCheckbox);
NS_IMETHOD GetCheckboxType(PRBool *aIsCheckbox);
NS_IMETHOD GetCommand(PRUint32 & aCommand);
NS_IMETHOD GetTarget(nsIWidget *& aTarget);
NS_IMETHOD GetNativeData(void*& aData);