mozilla/widget/src/xpwidgets/nsBaseWidget.cpp

This commit is contained in:
saari%netscape.com 1999-02-05 02:19:46 +00:00
Родитель b8256d5831
Коммит dce538a2bb
8 изменённых файлов: 192 добавлений и 10 удалений

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

@ -21,6 +21,7 @@
#include "nsISupports.h"
#include "nsString.h"
#include "nsIXULCommand.h"
// {7F045771-4BEB-11d2-8DBB-00609703C14E}
#define NS_IMENUITEM_IID \
@ -84,7 +85,11 @@ class nsIMenuItem : public nsISupports {
*/
NS_IMETHOD GetNativeData(void*& aData) = 0;
/**
* Set the comamnd for this menu item
*
*/
NS_IMETHOD SetXULCommand(nsIXULCommand * aXULCommand) = 0;
};
#endif

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

@ -30,8 +30,36 @@ static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIPopUpMenuIID, NS_IPOPUPMENU_IID);
static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID);
NS_IMPL_ISUPPORTS(nsMenuItem, kIMenuItemIID)
//NS_IMPL_ISUPPORTS(nsMenuItem, kIMenuItemIID)
nsresult nsMenuItem::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
if (aIID.Equals(kIMenuItemIID)) {
*aInstancePtr = (void*)(nsIMenuItem*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)(nsIMenuItem*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIMenuListenerIID)) {
*aInstancePtr = (void*)(nsIMenuListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsMenuItem)
NS_IMPL_RELEASE(nsMenuItem)
//-------------------------------------------------------------------------
//
@ -45,6 +73,7 @@ nsMenuItem::nsMenuItem() : nsIMenuItem()
mMenuParent = nsnull;
mPopUpParent = nsnull;
mTarget = nsnull;
mXULCommand = nsnull;
}
//-------------------------------------------------------------------------
@ -66,6 +95,7 @@ void nsMenuItem::Create(nsIWidget *aMBParent,
const nsString &aLabel,
PRUint32 aCommand)
{
/*
mTarget = aMBParent;
mCommand = aCommand;
mLabel = aLabel;
@ -87,6 +117,7 @@ void nsMenuItem::Create(nsIWidget *aMBParent,
(nsIMenuItem *)this);
delete[] nameStr;
*/
}
//-------------------------------------------------------------------------
@ -158,6 +189,7 @@ NS_METHOD nsMenuItem::Create(nsIMenu *aParent,
PRUint32 aCommand)
{
/*
if (nsnull == aParent) {
return NS_ERROR_FAILURE;
}
@ -174,7 +206,7 @@ NS_METHOD nsMenuItem::Create(nsIMenu *aParent,
// Create(widget, GetNativeParent(), aLabel, aCommand);
aParent->AddMenuItem(this);
*/
return NS_OK;
}
@ -235,3 +267,29 @@ NS_METHOD nsMenuItem::GetNativeData(void *& aData)
return NS_OK;
}
//-------------------------------------------------------------------------
// nsIMenuListener interface
//-------------------------------------------------------------------------
nsEventStatus nsMenuItem::MenuSelected(const nsMenuEvent & aMenuEvent)
{
// Execute the XULCommand
if(mXULCommand)
{
mXULCommand->DoCommand();
return nsEventStatus_eConsumeNoDefault;
}
else
return nsEventStatus_eIgnore;
}
//-------------------------------------------------------------------------
// Set the nsIXULCommand to poke when we get a nsMenuEvent from the user
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::SetXULCommand(nsIXULCommand * aXULCommand)
{
// We may support more than one XULCommand later, but not at this moment
NS_IF_RELEASE(mXULCommand);
NS_IF_ADDREF(aXULCommand);
mXULCommand = aXULCommand;
return NS_OK;
}

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

@ -22,6 +22,9 @@
#include "nsIMenuItem.h"
#include "nsString.h"
#include "nsIMenuListener.h"
#include "nsIXULCommand.h"
class nsIMenu;
class nsIPopUpMenu;
@ -31,7 +34,7 @@ class nsIWidget;
* Native Motif MenuItem wrapper
*/
class nsMenuItem : public nsIMenuItem
class nsMenuItem : public nsIMenuItem, public nsIMenuListener
{
public:
@ -56,7 +59,11 @@ public:
NS_IMETHOD GetTarget(nsIWidget *& aTarget);
NS_IMETHOD GetNativeData(void*& aData);
// nsIMenuListener interface
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
NS_IMETHOD SetXULCommand(nsIXULCommand * aXULCommand);
protected:
//void Create(nsIWidget * aMBParent, Widget aParent,
//const nsString &aLabel, PRUint32 aCommand);
@ -70,6 +77,7 @@ protected:
nsIPopUpMenu * mPopUpParent;
nsIWidget * mTarget;
nsIXULCommand * mXULCommand;
//Widget mMenu; // native cascade widget
};

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

@ -32,7 +32,36 @@ static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIPopUpMenuIID, NS_IPOPUPMENU_IID);
static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID);
NS_IMPL_ISUPPORTS(nsMenuItem, kIMenuItemIID)
//NS_IMPL_ISUPPORTS(nsMenuItem, kIMenuItemIID)
nsresult nsMenuItem::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
if (aIID.Equals(kIMenuItemIID)) {
*aInstancePtr = (void*)(nsIMenuItem*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)(nsIMenuItem*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIMenuListenerIID)) {
*aInstancePtr = (void*)(nsIMenuListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsMenuItem)
NS_IMPL_RELEASE(nsMenuItem)
//-------------------------------------------------------------------------
@ -226,3 +255,18 @@ NS_METHOD nsMenuItem::GetNativeData(void *& aData)
return NS_OK;
}
//-------------------------------------------------------------------------
// nsIMenuListener interface
//-------------------------------------------------------------------------
nsEventStatus nsMenuItem::MenuSelected(const nsMenuEvent & aMenuEvent)
{
return nsEventStatus_eIgnore;
}
//-------------------------------------------------------------------------
// Set the nsIXULCommand to poke when we get a nsMenuEvent from the user
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::SetXULCommand(nsIXULCommand * aXULCommand)
{
return NS_OK;
}

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

@ -23,6 +23,9 @@
#include "nsIMenuItem.h"
#include "nsString.h"
#include "nsIMenuListener.h"
#include "nsIXULCommand.h"
class nsIMenu;
class nsIPopUpMenu;
@ -32,7 +35,7 @@ class nsIWidget;
* Native Motif MenuItem wrapper
*/
class nsMenuItem : public nsIMenuItem
class nsMenuItem : public nsIMenuItem, public nsIMenuListener
{
public:
@ -57,6 +60,11 @@ public:
NS_IMETHOD GetTarget(nsIWidget *& aTarget);
NS_IMETHOD GetNativeData(void*& aData);
// nsIMenuListener interface
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
NS_IMETHOD SetXULCommand(nsIXULCommand * aXULCommand);
protected:
void Create(nsIWidget * aMBParent, Widget aParent,
const nsString &aLabel, PRUint32 aCommand);

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

@ -41,7 +41,36 @@ static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIPopUpMenuIID, NS_IPOPUPMENU_IID);
static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID);
NS_IMPL_ISUPPORTS(nsMenuItem, kIMenuItemIID)
//NS_IMPL_ISUPPORTS(nsMenuItem, kIMenuItemIID)
nsresult nsMenuItem::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
if (aIID.Equals(kIMenuItemIID)) {
*aInstancePtr = (void*)(nsIMenuItem*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)(nsIMenuItem*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIMenuListenerIID)) {
*aInstancePtr = (void*)(nsIMenuListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsMenuItem)
NS_IMPL_RELEASE(nsMenuItem)
//-------------------------------------------------------------------------
@ -179,3 +208,18 @@ NS_METHOD nsMenuItem::GetNativeData(void *& aData)
return NS_OK;
}
//-------------------------------------------------------------------------
// nsIMenuListener interface
//-------------------------------------------------------------------------
nsEventStatus nsMenuItem::MenuSelected(const nsMenuEvent & aMenuEvent)
{
return nsEventStatus_eIgnore;
}
//-------------------------------------------------------------------------
// Set the nsIXULCommand to poke when we get a nsMenuEvent from the user
//-------------------------------------------------------------------------
NS_METHOD nsMenuItem::SetXULCommand(nsIXULCommand * aXULCommand)
{
return NS_OK;
}

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

@ -25,6 +25,10 @@
#include "nsSwitchToUIThread.h"
#include "nsIMenuItem.h"
#include "nsIMenuListener.h"
#include "nsIXULCommand.h"
class nsIMenu;
class nsIPopUpMenu;
@ -32,7 +36,7 @@ class nsIPopUpMenu;
* Native Win32 MenuItem wrapper
*/
class nsMenuItem : public nsIMenuItem
class nsMenuItem : public nsIMenuItem, public nsIMenuListener
{
public:
@ -52,6 +56,10 @@ public:
NS_IMETHOD GetTarget(nsIWidget *& aTarget);
NS_IMETHOD GetNativeData(void*& aData);
// nsIMenuListener interface
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
NS_IMETHOD SetXULCommand(nsIXULCommand * aXULCommand);
protected:
nsIWidget * GetMenuBarParent(nsISupports * aParent);

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

@ -20,6 +20,7 @@
#include "nsIAppShell.h"
#include "nsIDeviceContext.h"
#include "nsCOMPtr.h"
#include "nsIMenuListener.h"
#include "nsGfxCIID.h"
#include "nsWidgetsCID.h"
@ -94,6 +95,7 @@ nsBaseWidget::nsBaseWidget() :
//-------------------------------------------------------------------------
nsBaseWidget::~nsBaseWidget()
{
NS_IF_RELEASE(mMenuListener);
}
//-------------------------------------------------------------------------
@ -599,13 +601,18 @@ NS_METHOD nsBaseWidget::AddEventListener(nsIEventListener * aListener)
}
/**
* Processes a menu event
* Add a menu listener
* This interface should only be called by the menu services manager
* This will AddRef() the menu listener
* This will Release() a previously set menu listener
*
**/
NS_METHOD nsBaseWidget::AddMenuListener(nsIMenuListener * aListener)
{
NS_PRECONDITION(mMenuListener == nsnull, "Null menu listener");
NS_IF_RELEASE(mMenuListener);
NS_IF_ADDREF(aListener);
mMenuListener = aListener;
return NS_OK;
}