From 8b143ceb0407c3a5a95589d959ffc702a87728ce Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" <rods%netscape.com> Date: Wed, 17 Feb 1999 14:30:47 +0000 Subject: [PATCH] Added the dispatch to menu listeners --- widget/src/windows/nsWindow.cpp | 55 ++++++++++++++++++++++++++++++++- widget/src/windows/nsWindow.h | 5 +++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index bbd1cfd7604ac..d147952804e36 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -33,6 +33,11 @@ #include "prtime.h" #include "nsIRenderingContextWin.h" +#include "nsIMenu.h" +#include "nsIMenuItem.h" +#include "nsIMenuListener.h" +#include "nsMenuItem.h" + BOOL nsWindow::sIsRegistered = FALSE; nsWindow* nsWindow::gCurrentWindow = nsnull; @@ -43,7 +48,10 @@ nsWindow* nsWindow::gCurrentWindow = nsnull; // g_hinst - handle of the application instance extern HINSTANCE g_hinst; -static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); +static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); +static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID); +static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID); +//static NS_DEFINE_IID(kIMenuListenerIID, NS_IMENULISTENER_IID); //------------------------------------------------------------------------- // @@ -73,6 +81,9 @@ nsWindow::nsWindow() : nsBaseWidget() mFont = nsnull; mIsVisible = PR_FALSE; mHas3DBorder = PR_FALSE; + mMenuBar = nsnull; + mMenuCmdId = 0; + } @@ -1278,6 +1289,28 @@ void nsWindow::SetUpForPaint(HDC aHDC) ::SetBkMode (aHDC, TRANSPARENT); } +//------------------------------------------------------------------------- +nsIMenuItem * FindMenuItem(nsIMenu * aMenu, PRUint32 aId) +{ + PRUint32 i, count; + aMenu->GetItemCount(count); + for (i=0;i<count;i++) { + nsISupports * item; + aMenu->GetItemAt(i, item); + nsIMenuItem * menuItem; + nsIMenu * menu; + if (NS_OK == item->QueryInterface(kIMenuItemIID, (void **)&menuItem)) { + if (((nsMenuItem *)menuItem)->GetCmdId() == (PRInt32)aId) { + return menuItem; + } + } else if (NS_OK == item->QueryInterface(kIMenuIID, (void **)&menu)) { + return FindMenuItem(menu, aId); + } + } + return nsnull; +} + + //------------------------------------------------------------------------- // // Process all nsWindows messages @@ -1300,6 +1333,23 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT event.eventStructType = NS_MENU_EVENT; InitEvent(event, NS_MENU_SELECTED); result = DispatchWindowEvent(&event); + if (mMenuBar) { + PRUint32 i, count; + mMenuBar->GetMenuCount(count); + for (i=0;i<count;i++) { + nsIMenu * menu; + mMenuBar->GetMenuAt(i, menu); + nsIMenuItem * menuItem = FindMenuItem(menu, event.mCommand); + if (menuItem) { + nsIMenuListener * listener; + if (NS_OK == menuItem->QueryInterface(kIMenuListenerIID, (void **)&listener)) { + listener->MenuSelected(event); + NS_RELEASE(listener); + } + NS_RELEASE(menuItem); + } + } + } NS_RELEASE(event.widget); } } @@ -2038,6 +2088,9 @@ PRBool nsWindow::AutoErase() NS_METHOD nsWindow::SetMenuBar(nsIMenuBar * aMenuBar) { + mMenuBar = aMenuBar; + NS_ADDREF(mMenuBar); + HMENU nativeMenuHandle; void * voidData; aMenuBar->GetNativeData(voidData); diff --git a/widget/src/windows/nsWindow.h b/widget/src/windows/nsWindow.h index 8d9fce8c79ea2..936e21d530036 100644 --- a/widget/src/windows/nsWindow.h +++ b/widget/src/windows/nsWindow.h @@ -136,6 +136,8 @@ public: virtual PRBool AutoErase(); nsPoint* GetLastPoint() { return &mLastPoint; } + PRInt32 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId;} + protected: virtual PRBool ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue); @@ -197,6 +199,9 @@ protected: PRInt32 mPreferredWidth; PRInt32 mPreferredHeight; + nsIMenuBar * mMenuBar; + PRInt32 mMenuCmdId; + // Enumeration of the methods which are accessable on the "main GUI thread" // via the CallMethod(...) mechanism... -- GitLab