more menu cleanup. Menus should no longer be holding on to WebShells in any way on GTK

This commit is contained in:
saari%netscape.com 1999-04-27 03:12:29 +00:00
Родитель 8f51f3a77b
Коммит 596de73a4d
6 изменённых файлов: 61 добавлений и 26 удалений

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

@ -99,7 +99,10 @@ nsMenu::nsMenu() : nsIMenu()
//-------------------------------------------------------------------------
nsMenu::~nsMenu()
{
g_print("nsMenu::~nsMenu called\n");
NS_IF_RELEASE(mListener);
// Free our menu items
//RemoveAll();
}
//-------------------------------------------------------------------------
@ -115,6 +118,7 @@ NS_METHOD nsMenu::Create(nsISupports *aParent, const nsString &aLabel)
if(menubar)
{
mMenuBarParent = menubar;
NS_RELEASE(menubar);
}
else
{
@ -123,6 +127,7 @@ NS_METHOD nsMenu::Create(nsISupports *aParent, const nsString &aLabel)
if(menu)
{
mMenuParent = menu;
NS_RELEASE(menu);
}
}
}

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

@ -38,7 +38,6 @@ static NS_DEFINE_IID(kMenuItemCID, NS_MENUITEM_CID);
static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID);
static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
//NS_IMPL_ISUPPORTS(nsMenuBar, kMenuBarIID)
nsresult nsMenuBar::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
@ -92,7 +91,9 @@ nsMenuBar::nsMenuBar() : nsIMenuBar(), nsIMenuListener()
//-------------------------------------------------------------------------
nsMenuBar::~nsMenuBar()
{
NS_IF_RELEASE(mParent);
g_print("nsMenuBar::~nsMenuBar() called\n");
// Release the menus
RemoveAll();
}
//-------------------------------------------------------------------------
@ -109,25 +110,19 @@ NS_METHOD nsMenuBar::Create(nsIWidget *aParent)
gtk_widget_show(mMenuBar);
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuBar::GetParent(nsIWidget *&aParent)
{
aParent = mParent;
// Bad monkey. Don't addref parent since we don't own the parent
//NS_IF_ADDREF(aParent);
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuBar::SetParent(nsIWidget *aParent)
{
// We don't own the parent, we shouldn't be addrefing it
//NS_IF_RELEASE(mParent);
mParent = aParent;
//NS_IF_ADDREF(mParent);
return NS_OK;
}
@ -139,6 +134,13 @@ NS_METHOD nsMenuBar::AddMenu(nsIMenu * aMenu)
char *labelStr;
void *voidData;
nsISupports * supports = nsnull;
aMenu->QueryInterface(kISupportsIID, (void**)&supports);
if(supports){
mMenusVoidArray.AppendElement(aMenu);
mNumMenus++;
}
aMenu->GetLabel(Label);
labelStr = Label.ToNewCString();
@ -184,6 +186,22 @@ NS_METHOD nsMenuBar::RemoveMenu(const PRUint32 aCount)
//-------------------------------------------------------------------------
NS_METHOD nsMenuBar::RemoveAll()
{
for (int i = mMenusVoidArray.Count(); i > 0; i--) {
if(nsnull != mMenusVoidArray[i-1]) {
nsIMenu * menu = nsnull;
((nsISupports*)mMenusVoidArray[i-1])->QueryInterface(kIMenuIID, (void**)&menu);
if(menu) {
//void * gtkmenu= nsnull;
//menu->GetNativeData(&gtkmenu);
//if(gtkmenu){
// gtk_container_remove (GTK_CONTAINER (mMenuBar), GTK_WIDGET(gtkmenu) );
//}
NS_RELEASE(menu);
((nsISupports*)mMenusVoidArray[i-1])->Release();
}
}
}
return NS_OK;
}
@ -270,8 +288,8 @@ nsEventStatus nsMenuBar::MenuConstruct(
pnsMenu->Create(supports, menuName);
NS_RELEASE(supports);
pnsMenu->SetDOMNode(menuNode);
pnsMenu->SetDOMElement(menuElement);
pnsMenu->SetDOMNode(menuNode);
pnsMenu->SetDOMElement(menuElement);
// Set nsMenu Name
pnsMenu->SetLabel(menuName);
@ -291,16 +309,13 @@ nsEventStatus nsMenuBar::MenuConstruct(
} // end while (nsnull != menuNode)
// Give the aParentWindow this nsMenuBar to hold onto.
// The parent window should take ownership at this point
aParentWindow->SetMenuBar(pnsMenuBar);
// HACK: force a paint for now
pnsMenuBar->Paint();
// HACK for M4, should be removed by M5
#ifdef XP_MAC
Handle tempMenuBar = ::GetMenuBar(); // Get a copy of the menu list
pnsMenuBar->SetNativeData((void*)tempMenuBar);
#endif
NS_RELEASE(pnsMenuBar);
} // end if ( nsnull != pnsMenuBar )
}

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

@ -68,13 +68,15 @@ public:
NS_IMETHOD Paint();
NS_IMETHOD SetNativeData(void* aData);
protected:
PRUint32 mNumMenus;
GtkWidget *mMenuBar;
nsIWidget *mParent;
GtkWidget * mMenuBar;
nsIWidget * mParent;
PRBool mIsMenuBarAdded;
nsIWebShell * mWebShell;
nsIDOMNode * mDOMNode;
nsVoidArray mMenusVoidArray;
PRUint32 mNumMenus;
};
#endif // nsMenuBar_h__

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

@ -113,7 +113,6 @@ void nsMenuItem::Create(nsIWidget *aMBParent,
return;
}
mTarget = aMBParent;
char * nameStr = mLabel.ToNewCString();
if(aIsSeparator) {
mIsSeparator = PR_TRUE;
@ -171,6 +170,7 @@ nsIWidget * nsMenuItem::GetMenuBarParent(nsISupports * aParent)
while(1) {
if (NS_OK == parent->QueryInterface(kIMenuIID,(void**)&menu)) {
NS_RELEASE(parent);
if (NS_OK != menu->GetParent(parent)) {
NS_RELEASE(menu);
return nsnull;
@ -182,6 +182,7 @@ nsIWidget * nsMenuItem::GetMenuBarParent(nsISupports * aParent)
widget = nsnull;
}
NS_RELEASE(popup);
NS_RELEASE(parent);
return widget;
} else if (NS_OK == parent->QueryInterface(kIMenuBarIID,(void**)&menuBar)) {
@ -189,8 +190,10 @@ nsIWidget * nsMenuItem::GetMenuBarParent(nsISupports * aParent)
widget = nsnull;
}
NS_RELEASE(menuBar);
NS_RELEASE(parent);
return widget;
} else {
NS_RELEASE(parent);
return nsnull;
}
}
@ -213,7 +216,8 @@ NS_METHOD nsMenuItem::Create(nsIMenu * aParent,
nsISupports * sups;
if (NS_OK == aParent->QueryInterface(kISupportsIID,(void**)&sups)) {
widget = GetMenuBarParent(sups);
NS_RELEASE(sups);
//GetMenuBarParent will call release for us
//NS_RELEASE(sups);
}
Create(widget, GetNativeParent(), aLabel, aIsSeparator);
@ -228,7 +232,6 @@ NS_METHOD nsMenuItem::Create(nsIPopUpMenu *aParent,
PRUint32 aCommand)
{
mPopUpParent = aParent;
//NS_ADDREF(mPopUpParent);
nsIWidget * widget = nsnull;
if (NS_OK != aParent->GetParent(widget)) {
@ -236,7 +239,6 @@ NS_METHOD nsMenuItem::Create(nsIPopUpMenu *aParent,
}
Create(widget, GetNativeParent(), aLabel, PR_FALSE);
// aParent->AddItem(this);
return NS_OK;
}
@ -305,7 +307,7 @@ NS_METHOD nsMenuItem::GetNativeData(void *& aData)
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::AddMenuListener(nsIMenuListener * aMenuListener)
{
NS_ASSERTION(PR_FALSE, "we should never get here");
NS_IF_RELEASE(mXULCommandListener);
NS_IF_ADDREF(aMenuListener);
mXULCommandListener = aMenuListener;
@ -358,7 +360,7 @@ nsEventStatus nsMenuItem::MenuConstruct(
const nsMenuEvent & aMenuEvent,
nsIWidget * aParentWindow,
void * menuNode,
void * aWebShell)
void * aWebShell)
{
g_print("nsMenuItem::MenuConstruct\n");
return nsEventStatus_eIgnore;
@ -378,7 +380,7 @@ nsEventStatus nsMenuItem::MenuDestruct(const nsMenuEvent & aMenuEvent)
*/
NS_METHOD nsMenuItem::SetCommand(const nsString & aStrCmd)
{
return NS_OK;
return NS_OK;
}
//-------------------------------------------------------------------------

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

@ -83,6 +83,8 @@ nsWindow::nsWindow()
mIsDestroyingWindow = PR_FALSE;
mOnDestroyCalled = PR_FALSE;
mFont = nsnull;
m_nsIMenuBar = nsnull;
}
//-------------------------------------------------------------------------
@ -96,6 +98,7 @@ nsWindow::~nsWindow()
if (nsnull != mShell) {
Destroy();
}
NS_IF_RELEASE(m_nsIMenuBar);
}
PRBool nsWindow::IsChild() const
@ -143,6 +146,8 @@ NS_METHOD nsWindow::RemoveTooltips()
NS_METHOD nsWindow::Destroy()
{
NS_IF_RELEASE(m_nsIMenuBar);
// Call base class first... we need to ensure that upper management
// knows about the close so that if this is the main application
// window, for example, the application will exit as it should.
@ -165,7 +170,7 @@ gint handle_delete_event(GtkWidget *w, GdkEventAny *e, nsWindow *win)
{
win->SetIsDestroying( PR_TRUE );
win->Destroy();
return PR_TRUE;
return TRUE;
}
NS_METHOD nsWindow::PreCreateWidget(nsWidgetInitData *aInitData)
@ -545,6 +550,10 @@ PRBool nsWindow::OnScroll(nsScrollbarEvent &aEvent, PRUint32 cPos)
NS_METHOD nsWindow::SetMenuBar(nsIMenuBar * aMenuBar)
{
NS_IF_RELEASE(m_nsIMenuBar);
m_nsIMenuBar = aMenuBar;
NS_IF_ADDREF(m_nsIMenuBar);
GtkWidget *menubar;
void *voidData;
aMenuBar->GetNativeData(voidData);

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

@ -134,6 +134,8 @@ protected:
GtkWidget *mShell; /* used for toplevel windows */
GtkWidget *mVBox;
nsIMenuBar * m_nsIMenuBar;
};
//