From ae4d160a1148ad7804527b2c565ce6bd8a2be837 Mon Sep 17 00:00:00 2001 From: "pavlov%pavlov.net" Date: Sun, 20 Jun 1999 17:34:06 +0000 Subject: [PATCH] context menus almost work now. git-svn-id: svn://10.0.0.236/trunk@35983 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/gtk/nsContextMenu.cpp | 96 +++++++++++++----------- mozilla/widget/src/gtk/nsContextMenu.h | 86 ++++++++++----------- 2 files changed, 98 insertions(+), 84 deletions(-) diff --git a/mozilla/widget/src/gtk/nsContextMenu.cpp b/mozilla/widget/src/gtk/nsContextMenu.cpp index f7e48426fd8..31763b8490f 100644 --- a/mozilla/widget/src/gtk/nsContextMenu.cpp +++ b/mozilla/widget/src/gtk/nsContextMenu.cpp @@ -18,7 +18,7 @@ #include -#include "nsMenu.h" +#include "nsContextMenu.h" #include "nsIComponentManager.h" #include "nsIDOMElement.h" #include "nsIDOMNode.h" @@ -36,7 +36,7 @@ static NS_DEFINE_CID(kMenuItemCID, NS_MENUITEM_CID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); //------------------------------------------------------------------------- -nsresult nsContextMenu::QueryInterface(REFNSIID aIID, void** aInstancePtr) +nsresult nsContextMenu::QueryInterface(REFNSIID aIID, void** aInstancePtr) { if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; @@ -74,13 +74,16 @@ NS_IMPL_RELEASE(nsContextMenu) nsContextMenu::nsContextMenu() { NS_INIT_REFCNT(); - mMenu = nsnull; - mListener = nsnull; - nsresult result = NS_NewISupportsArray(&mItems); - mDOMNode = nsnull; - mDOMElement = nsnull; - mWebShell = nsnull; - mConstructed = false; + mNumMenuItems = 0; + mMenu = nsnull; + mParent = nsnull; + mListener = nsnull; + mConstructCalled = PR_FALSE; + + mDOMNode = nsnull; + mWebShell = nsnull; + mDOMElement = nsnull; + mAlignment = "topleft"; mAnchorAlignment = "none"; } @@ -101,31 +104,24 @@ nsContextMenu::~nsContextMenu() // Create the proper widget // //------------------------------------------------------------------------- -NS_METHOD nsContextMenu::Create(nsISupports *aParent, const nsString& anAlignment, +NS_METHOD nsContextMenu::Create(nsISupports *aParent, + const nsString& anAlignment, const nsString& anAnchorAlignment) { if(aParent) { - nsIMenuBar * menubar = nsnull; - aParent->QueryInterface(nsIMenuBar::GetIID(), (void**) &menubar); - if(menubar) + nsIWidget *parent = nsnull; + aParent->QueryInterface(nsIWidget::GetIID(), (void**) &parent); + if(parent) { - mMenuBarParent = menubar; - NS_RELEASE(menubar); - } - else - { - nsIMenu * menu = nsnull; - aParent->QueryInterface(nsIMenu::GetIID(), (void**) &menu); - if(menu) - { - mMenuParent = menu; - NS_RELEASE(menu); - } + mParent = parent; + NS_RELEASE(parent); } } - mLabel = aLabel; + mAlignment = anAlignment; + mAnchorAlignment = anAnchorAlignment; + mMenu = gtk_menu_new(); gtk_signal_connect (GTK_OBJECT (mMenu), "map", @@ -141,12 +137,9 @@ NS_METHOD nsContextMenu::Create(nsISupports *aParent, const nsString& anAlignmen NS_METHOD nsContextMenu::GetParent(nsISupports*& aParent) { aParent = nsnull; - if (nsnull != mMenuParent) { - return mMenuParent->QueryInterface(kISupportsIID, - (void**)&aParent); - } else if (nsnull != mMenuBarParent) { - return mMenuBarParent->QueryInterface(kISupportsIID, - (void**)&aParent); + if (nsnull != mParent) { + return mParent->QueryInterface(kISupportsIID, + (void**)&aParent); } return NS_ERROR_FAILURE; @@ -181,15 +174,6 @@ NS_METHOD nsContextMenu::AddItem(nsISupports * aItem) return NS_OK; } -//------------------------------------------------------------------------- -// This does not return a ref counted object -// This is NOT an nsIMenu method -nsIWidget *nsContextMenu::GetParentWidget() -{ - return mParentWindow; -} - - //------------------------------------------------------------------------- NS_METHOD nsContextMenu::AddMenuItem(nsIMenuItem * aMenuItem) { @@ -338,6 +322,7 @@ NS_METHOD nsContextMenu::RemoveItem(const PRUint32 aCount) NS_METHOD nsContextMenu::RemoveAll() { //g_print("nsMenu::RemoveAll()\n"); +#undef DEBUG_pavlov #ifdef DEBUG_pavlov // this doesn't work quite right, but this is about all that should really be needed int i=0; @@ -452,9 +437,24 @@ nsEventStatus nsContextMenu::MenuItemSelected(const nsMenuEvent & aMenuEvent) return nsEventStatus_eIgnore; } +void nsContextMenu::MenuPosFunc(GtkMenu *menu, + gint *x, + gint *y, + gpointer data) +{ + nsContextMenu *cm = (nsContextMenu*)data; + *x = cm->GetX(); + *y = cm->GetY(); +} nsEventStatus nsContextMenu::MenuSelected(const nsMenuEvent & aMenuEvent) { + GtkWidget *parent = GTK_WIDGET(mParent->GetNativeData(NS_NATIVE_WIDGET)); + gtk_menu_popup (GTK_MENU(mMenu), + parent, NULL, + nsContextMenu::MenuPosFunc, + this, 1, GDK_CURRENT_TIME); + if (nsnull != mListener) { mListener->MenuSelected(aMenuEvent); } @@ -464,7 +464,7 @@ nsEventStatus nsContextMenu::MenuSelected(const nsMenuEvent & aMenuEvent) //------------------------------------------------------------------------- nsIMenuItem * nsContextMenu::FindMenuItem(nsIContextMenu * aMenu, PRUint32 aId) { - + return nsnull; } //------------------------------------------------------------------------- @@ -700,6 +700,18 @@ NS_METHOD nsContextMenu::SetLocation(PRInt32 aX, PRInt32 aY) } +// local methods +gint nsContextMenu::GetX(void) +{ + return mX; +} + +gint nsContextMenu::GetY(void) +{ + return mY; +} +// end silly local methods + //------------------------------------------------------------------------- NS_METHOD nsContextMenu::SetDOMNode(nsIDOMNode *aMenuNode) { diff --git a/mozilla/widget/src/gtk/nsContextMenu.h b/mozilla/widget/src/gtk/nsContextMenu.h index 534b8a2ea4e..922864552ae 100644 --- a/mozilla/widget/src/gtk/nsContextMenu.h +++ b/mozilla/widget/src/gtk/nsContextMenu.h @@ -19,12 +19,9 @@ #ifndef nsContextMenu_h__ #define nsContextMenu_h__ -#include "nsdefs.h" -#include "nsWindow.h" -#include "nsSwitchToUIThread.h" - #include "nsIContextMenu.h" #include "nsISupportsArray.h" +#include "nsVoidArray.h" #include "nsIDOMElement.h" #include "nsIWebShell.h" @@ -48,15 +45,16 @@ public: nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent); nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); - nsEventStatus MenuConstruct( - const nsMenuEvent & aMenuEvent, - nsIWidget * aParentWindow, - void * menubarNode, - void * aWebShell); + nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, + nsIWidget * aParentWindow, + void * menubarNode, + void * aWebShell); nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent); // nsIMenu Methods - NS_IMETHOD Create(nsISupports * aParent, const nsString& anAlignment, const nsString& aAnchorAlign); + NS_IMETHOD Create(nsISupports * aParent, + const nsString& anAlignment, + const nsString& aAnchorAlign); NS_IMETHOD GetParent(nsISupports *&aParent); NS_IMETHOD AddItem(nsISupports * aItem); @@ -82,51 +80,55 @@ public: NS_IMETHOD SetWebShell(nsIWebShell * aWebShell); NS_IMETHOD SetLocation(PRInt32 aX, PRInt32 aY); - // Native Impl Methods - // These are not ref counted - HMENU GetNativeMenu() { return mMenu; } + gint GetX(void); + gint GetY(void); + protected: nsIMenuBar * GetMenuBar(nsIMenu * aMenu); nsIWidget * GetParentWidget(); char* GetACPString(nsString& aStr); - - void LoadMenuItem( - nsIMenu * pParentMenu, - nsIDOMElement * menuitemElement, - nsIDOMNode * menuitemNode, - unsigned short menuitemIndex, - nsIWebShell * aWebShell); - - void LoadSubMenu( - nsIMenu * pParentMenu, - nsIDOMElement * menuElement, - nsIDOMNode * menuNode); - void LoadMenuItem( - nsIContextMenu * pParentMenu, - nsIDOMElement * menuitemElement, - nsIDOMNode * menuitemNode, - unsigned short menuitemIndex, - nsIWebShell * aWebShell); + void MenuPosFunc(GtkMenu *menu, + gint *x, + gint *y, + gpointer data); + + void LoadMenuItem(nsIMenu * pParentMenu, + nsIDOMElement * menuitemElement, + nsIDOMNode * menuitemNode, + unsigned short menuitemIndex, + nsIWebShell * aWebShell); - void LoadSubMenu( - nsIContextMenu * pParentMenu, - nsIDOMElement * menuElement, - nsIDOMNode * menuNode); + void LoadSubMenu(nsIMenu * pParentMenu, + nsIDOMElement * menuElement, + nsIDOMNode * menuNode); + + void LoadMenuItem(nsIContextMenu * pParentMenu, + nsIDOMElement * menuitemElement, + nsIDOMNode * menuitemNode, + unsigned short menuitemIndex, + nsIWebShell * aWebShell); + + void LoadSubMenu(nsIContextMenu * pParentMenu, + nsIDOMElement * menuElement, + nsIDOMNode * menuNode); nsIMenuItem * FindMenuItem(nsIContextMenu * aMenu, PRUint32 aId); - HMENU mMenu; + nsString mLabel; + PRUint32 mNumMenuItems; + GtkWidget *mMenu; + + nsVoidArray mMenuItemVoidArray; - nsISupportsArray * mItems; - nsIMenuListener * mListener; - - nsIWidget * mParentWindow; + nsIWidget *mParent; + nsIMenuListener * mListener; + + PRBool mConstructCalled; nsIDOMNode * mDOMNode; - nsIDOMElement * mDOMElement; nsIWebShell * mWebShell; - bool mConstructed; + nsIDOMElement * mDOMElement; nsString mAlignment; nsString mAnchorAlignment;