From bf6482c9af446035c292bbcc358f4fbcfa067103 Mon Sep 17 00:00:00 2001 From: "saari%netscape.com" Date: Fri, 23 Apr 1999 22:39:32 +0000 Subject: [PATCH] dynamic menu changes git-svn-id: svn://10.0.0.236/trunk@28973 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/public/nsIMenuBar.h | 2 ++ mozilla/widget/public/nsIMenuItem.h | 3 +- mozilla/widget/src/gtk/nsMenu.cpp | 20 ++++++------ mozilla/widget/src/gtk/nsMenuItem.cpp | 22 ++++++------- mozilla/widget/src/gtk/nsMenuItem.h | 7 ++-- mozilla/widget/src/mac/nsMenu.cpp | 3 +- mozilla/widget/src/mac/nsMenuItem.cpp | 2 +- mozilla/widget/src/mac/nsMenuItem.h | 2 +- mozilla/widget/src/windows/nsMenu.cpp | 40 +++++++++++------------ mozilla/widget/src/windows/nsMenuItem.cpp | 14 +++----- mozilla/widget/src/windows/nsMenuItem.h | 2 +- 11 files changed, 58 insertions(+), 59 deletions(-) diff --git a/mozilla/widget/public/nsIMenuBar.h b/mozilla/widget/public/nsIMenuBar.h index 943fbaf2ee4..0b15b8d5b0c 100644 --- a/mozilla/widget/public/nsIMenuBar.h +++ b/mozilla/widget/public/nsIMenuBar.h @@ -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 diff --git a/mozilla/widget/public/nsIMenuItem.h b/mozilla/widget/public/nsIMenuItem.h index 001c55bff70..16514cefaf0 100644 --- a/mozilla/widget/public/nsIMenuItem.h +++ b/mozilla/widget/public/nsIMenuItem.h @@ -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 diff --git a/mozilla/widget/src/gtk/nsMenu.cpp b/mozilla/widget/src/gtk/nsMenu.cpp index b1324b43652..6fc268f467c 100644 --- a/mozilla/widget/src/gtk/nsMenu.cpp +++ b/mozilla/widget/src/gtk/nsMenu.cpp @@ -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; } diff --git a/mozilla/widget/src/gtk/nsMenuItem.cpp b/mozilla/widget/src/gtk/nsMenuItem.cpp index daae52e06bf..710a7eff4a5 100644 --- a/mozilla/widget/src/gtk/nsMenuItem.cpp +++ b/mozilla/widget/src/gtk/nsMenuItem.cpp @@ -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; diff --git a/mozilla/widget/src/gtk/nsMenuItem.h b/mozilla/widget/src/gtk/nsMenuItem.h index bf4c4756f3c..ece8fd811c1 100644 --- a/mozilla/widget/src/gtk/nsMenuItem.h +++ b/mozilla/widget/src/gtk/nsMenuItem.h @@ -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; diff --git a/mozilla/widget/src/mac/nsMenu.cpp b/mozilla/widget/src/mac/nsMenu.cpp index 826a0a291de..ec7b3a55e0c 100644 --- a/mozilla/widget/src/mac/nsMenu.cpp +++ b/mozilla/widget/src/mac/nsMenu.cpp @@ -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; diff --git a/mozilla/widget/src/mac/nsMenuItem.cpp b/mozilla/widget/src/mac/nsMenuItem.cpp index d184615bc5e..77db3f40d58 100644 --- a/mozilla/widget/src/mac/nsMenuItem.cpp +++ b/mozilla/widget/src/mac/nsMenuItem.cpp @@ -189,7 +189,7 @@ nsIWidget * nsMenuItem::GetMenuBarParent(nsISupports * aParent) //------------------------------------------------------------------------- NS_METHOD nsMenuItem::Create(nsIMenu *aParent, const nsString &aLabel, - PRUint32 aCommand) + PRBool aIsSeparator) { /* diff --git a/mozilla/widget/src/mac/nsMenuItem.h b/mozilla/widget/src/mac/nsMenuItem.h index 9bb9edfffb6..1a961b96ea2 100644 --- a/mozilla/widget/src/mac/nsMenuItem.h +++ b/mozilla/widget/src/mac/nsMenuItem.h @@ -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, diff --git a/mozilla/widget/src/windows/nsMenu.cpp b/mozilla/widget/src/windows/nsMenu.cpp index 49e2f2bc7ca..152ba3a1ca4 100644 --- a/mozilla/widget/src/windows/nsMenu.cpp +++ b/mozilla/widget/src/windows/nsMenu.cpp @@ -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 domElement(do_QueryInterface(menuitemNode)); if (!domElement) { - //return NS_ERROR_FAILURE; return; } diff --git a/mozilla/widget/src/windows/nsMenuItem.cpp b/mozilla/widget/src/windows/nsMenuItem.cpp index abd547e087c..d542e3ca8cb 100644 --- a/mozilla/widget/src/windows/nsMenuItem.cpp +++ b/mozilla/widget/src/windows/nsMenuItem.cpp @@ -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); diff --git a/mozilla/widget/src/windows/nsMenuItem.h b/mozilla/widget/src/windows/nsMenuItem.h index 07356d56426..d9f3221b0fb 100644 --- a/mozilla/widget/src/windows/nsMenuItem.h +++ b/mozilla/widget/src/windows/nsMenuItem.h @@ -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);