dynamic menu changes

git-svn-id: svn://10.0.0.236/trunk@28973 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
saari%netscape.com 1999-04-23 22:39:32 +00:00
parent f41540d314
commit bf6482c9af
11 changed files with 58 additions and 59 deletions

View File

@ -22,6 +22,7 @@
#include "nsISupports.h"
#include "nsString.h"
#include "nsIMenu.h"
#include "nsIWebShell.h"
class nsIWidget;
@ -109,6 +110,7 @@ class nsIMenuBar : public nsISupports {
*
*/
NS_IMETHOD Paint() = 0;
};
#endif

View File

@ -19,6 +19,7 @@
#ifndef nsIMenuItem_h__
#define nsIMenuItem_h__
#include "prtypes.h"
#include "nsISupports.h"
#include "nsString.h"
@ -49,7 +50,7 @@ class nsIMenuItem : public nsISupports {
*/
NS_IMETHOD Create(nsIMenu *aParent,
const nsString &aLabel,
PRUint32 aCommand) = 0;
PRBool isSeparator) = 0;
/**
* Creates the MenuItem

View File

@ -284,7 +284,7 @@ NS_METHOD nsMenu::AddSeparator()
if (NS_OK == rv) {
// This is gross and I'll make it go away ASAP -cps
nsString tmp = "separator";
pnsMenuItem->Create(this, tmp, 0);
pnsMenuItem->Create(this, tmp, PR_TRUE);
nsISupports * supports = nsnull;
pnsMenuItem->QueryInterface(kISupportsIID, (void**) &supports);
AddItem(supports); // Parent should now own menu item
@ -532,7 +532,7 @@ NS_METHOD nsMenu::SetWebShell(nsIWebShell * aWebShell)
//----------------------------------------
void nsMenu::LoadMenuItem(
nsIMenu * pParentMenu,
nsIMenu * pParentMenu,
nsIDOMElement * menuitemElement,
nsIDOMNode * menuitemNode,
unsigned short menuitemIndex,
@ -546,11 +546,15 @@ void nsMenu::LoadMenuItem(
menuitemElement->GetAttribute(nsAutoString("disabled"), disabled);
menuitemElement->GetAttribute(nsAutoString("name"), menuitemName);
menuitemElement->GetAttribute(nsAutoString("cmd"), menuitemCmd);
if(disabled == NS_STRING_TRUE ) {
}
// Create nsMenuItem
nsIMenuItem * pnsMenuItem = nsnull;
nsresult rv = nsComponentManager::CreateInstance(kMenuItemCID, nsnull, kIMenuItemIID, (void**)&pnsMenuItem);
if (NS_OK == rv) {
pnsMenuItem->Create(pParentMenu, menuitemName, 0);
pnsMenuItem->Create(pParentMenu, menuitemName, PR_FALSE);
nsISupports * supports = nsnull;
pnsMenuItem->QueryInterface(kISupportsIID, (void**) &supports);
pParentMenu->AddItem(supports); // Parent should now own menu item
@ -573,18 +577,14 @@ void nsMenu::LoadMenuItem(
domElement->GetAttribute(cmdAtom, cmdName);
pnsMenuItem->SetCommand(cmdName);
// DO NOT use passed in wehshell because of messed up windows dynamic loading
// code.
// DO NOT use passed in webshell because of messed up windows dynamic loading
// code.
pnsMenuItem->SetWebShell(mWebShell);
pnsMenuItem->SetDOMElement(domElement);
if(disabled == NS_STRING_TRUE )
//::EnableMenuItem(mMenu, menuitemIndex, MF_BYPOSITION | MF_GRAYED);
NS_RELEASE(pnsMenuItem);
NS_RELEASE(pnsMenuItem);
}
//return NS_OK;
return;
}

View File

@ -86,7 +86,7 @@ nsMenuItem::nsMenuItem() : nsIMenuItem()
mPopUpParent = nsnull;
mTarget = nsnull;
mXULCommandListener = nsnull;
mIsSeparator = false;
mIsSeparator = PR_FALSE;
mWebShell = nsnull;
mDOMElement = nsnull;
}
@ -107,10 +107,10 @@ nsMenuItem::~nsMenuItem()
void nsMenuItem::Create(nsIWidget *aMBParent,
GtkWidget *aParent,
const nsString &aLabel,
PRUint32 aCommand)
PRBool aIsSeparator)
{
mTarget = aMBParent;
mCommand = aCommand;
//mCommand = aCommand;
mLabel = aLabel;
if (NULL == aParent || nsnull == aMBParent) {
@ -119,11 +119,11 @@ void nsMenuItem::Create(nsIWidget *aMBParent,
mTarget = aMBParent;
char * nameStr = mLabel.ToNewCString();
if(!strcmp(nameStr, "separator")) {
mIsSeparator = true;
if(aIsSeparator) {
mIsSeparator = PR_TRUE;
mMenuItem = gtk_menu_item_new();
}else{
mIsSeparator = false;
mIsSeparator = PR_FALSE;
mMenuItem = gtk_menu_item_new_with_label(nameStr);
}
gtk_widget_show(mMenuItem);
@ -208,9 +208,9 @@ nsIWidget * nsMenuItem::GetMenuBarParent(nsISupports * aParent)
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::Create(nsIMenu *aParent,
const nsString &aLabel,
PRUint32 aCommand)
NS_METHOD nsMenuItem::Create(nsIMenu * aParent,
const nsString & aLabel,
PRBool aIsSeparator)
{
if (nsnull == aParent) {
@ -227,7 +227,7 @@ NS_METHOD nsMenuItem::Create(nsIMenu *aParent,
NS_RELEASE(sups);
}
Create(widget, GetNativeParent(), aLabel, aCommand);
Create(widget, GetNativeParent(), aLabel, aIsSeparator);
// aParent->AddMenuItem(this);
return NS_OK;
@ -246,7 +246,7 @@ NS_METHOD nsMenuItem::Create(nsIPopUpMenu *aParent,
widget = nsnull;
}
Create(widget, GetNativeParent(), aLabel, aCommand);
Create(widget, GetNativeParent(), aLabel, false);
// aParent->AddItem(this);
return NS_OK;

View File

@ -19,6 +19,7 @@
#ifndef nsMenuItem_h__
#define nsMenuItem_h__
#include "prtypes.h"
#include "nsIMenuItem.h"
#include "nsString.h"
#include "nsIMenuListener.h"
@ -46,7 +47,7 @@ public:
NS_IMETHOD Create(nsIMenu *aParent,
const nsString &aLabel,
PRUint32 aCommand);
PRBool aIsSeparator);
NS_IMETHOD Create(nsIPopUpMenu *aParent,
const nsString &aLabel,
@ -87,7 +88,7 @@ public:
protected:
void Create(nsIWidget * aMBParent, GtkWidget *aParent,
const nsString &aLabel, PRUint32 aCommand);
const nsString &aLabel, PRBool aIsSeparator);
nsIWidget *GetMenuBarParent(nsISupports * aParentSupports);
GtkWidget *GetNativeParent();
@ -99,7 +100,7 @@ protected:
nsIWidget *mTarget;
GtkWidget *mMenuItem; // native cascade widget
bool mIsSeparator;
PRBool mIsSeparator;
nsIWebShell * mWebShell;
nsIDOMElement * mDOMElement;

View File

@ -247,7 +247,8 @@ NS_METHOD nsMenu::AddMenu(nsIMenu * aMenu)
aMenu->GetLabel(label);
char* menuLabel = label.ToNewCString();
mNumMenuItems++;
::InsertMenuItem(mMacMenuHandle, c2pstr(menuLabel), mNumMenuItems);
::InsertMenuItem(mMacMenuHandle, c2pstr("a"), mNumMenuItems);
::SetMenuItemText(mMacMenuHandle, mNumMenuItems, c2pstr(menuLabel));
delete[] menuLabel;
MenuHandle menuHandle;

View File

@ -189,7 +189,7 @@ nsIWidget * nsMenuItem::GetMenuBarParent(nsISupports * aParent)
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::Create(nsIMenu *aParent,
const nsString &aLabel,
PRUint32 aCommand)
PRBool aIsSeparator)
{
/*

View File

@ -44,7 +44,7 @@ public:
NS_IMETHOD Create(nsIMenu *aParent,
const nsString &aLabel,
PRUint32 aCommand);
PRBool aIsSeparator);
NS_IMETHOD Create(nsIPopUpMenu *aParent,
const nsString &aLabel,

View File

@ -120,30 +120,29 @@ nsMenu::~nsMenu()
NS_METHOD nsMenu::Create(nsISupports *aParent, const nsString &aLabel)
{
if(aParent)
if(aParent)
{
nsIMenuBar * menubar = nsnull;
aParent->QueryInterface(kIMenuBarIID, (void**) &menubar);
if(menubar)
{
nsIMenuBar * menubar = nsnull;
aParent->QueryInterface(kIMenuBarIID, (void**) &menubar);
if(menubar)
{
mMenuBarParent = menubar;
//NS_ADDREF(mMenuBarParent);
mMenuBarParent = menubar;
//NS_ADDREF(mMenuBarParent);
NS_RELEASE(menubar); // Balance the QI
}
else
{
nsIMenu * menu = nsnull;
aParent->QueryInterface(kIMenuIID, (void**) &menu);
if(menu)
{
mMenuParent = menu;
//NS_ADDREF(mMenuParent);
NS_RELEASE(menubar); // Balance the QI
} else {
nsIMenu * menu = nsnull;
aParent->QueryInterface(kIMenuIID, (void**) &menu);
if(menu)
{
mMenuParent = menu;
//NS_ADDREF(mMenuParent);
NS_RELEASE(menu); // Balance the QI
}
}
NS_RELEASE(menu); // Balance the QI
}
}
}
mLabel = aLabel;
mMenu = CreateMenu();
return NS_OK;
@ -565,7 +564,6 @@ void nsMenu::LoadMenuItem(
// the appropriate nsMenuDelegate object
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(menuitemNode));
if (!domElement) {
//return NS_ERROR_FAILURE;
return;
}

View File

@ -97,11 +97,8 @@ nsMenuItem::nsMenuItem() : nsIMenuItem()
nsMenuItem::~nsMenuItem()
{
//NS_IF_RELEASE(mMenu);
//NS_IF_RELEASE(mTarget);
//NS_IF_RELEASE(mListener);
}
//-------------------------------------------------------------------------
@ -149,17 +146,16 @@ nsIWidget * nsMenuItem::GetMenuBarParent(nsISupports * aParent)
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::Create(nsIMenu * aParent, const nsString &aLabel, PRUint32 aCommand)
NS_METHOD nsMenuItem::Create(
nsIMenu * aParent,
const nsString &aLabel,
PRBool aIsSeparator)
{
mCommand = aCommand;
//mCommand = aCommand;
mLabel = aLabel;
mMenu = aParent;
//NS_ADDREF(mMenu);
//NS_ASSERTION(false,"get debugger");
nsISupports * sups;
if (NS_OK == aParent->QueryInterface(kISupportsIID,(void**)&sups)) {
//mTarget = GetMenuBarParent(sups);

View File

@ -47,7 +47,7 @@ public:
// nsISupports
NS_DECL_ISUPPORTS
NS_IMETHOD Create(nsIMenu * aParent, const nsString &aLabel, PRUint32 aCommand);
NS_IMETHOD Create(nsIMenu * aParent, const nsString &aLabel, PRBool aIsSeparator);
NS_IMETHOD Create(nsIPopUpMenu * aParent, const nsString &aLabel, PRUint32 aCommand);
NS_IMETHOD Create(nsIMenu * aParent);
NS_IMETHOD Create(nsIPopUpMenu * aParent);