зеркало из https://github.com/mozilla/gecko-dev.git
Have the Model support the Observable interfaces
This commit is contained in:
Родитель
6f0645cf11
Коммит
b84668b9ab
|
@ -23,9 +23,15 @@
|
|||
#include "nsIModel.h"
|
||||
#include "nsICalendarModel.h"
|
||||
#include "nsICalendarUser.h"
|
||||
#include "nsIXPFCObserver.h"
|
||||
#include "nsIXPFCCommandReceiver.h"
|
||||
#include "nsIXPFCSubject.h"
|
||||
|
||||
class nsCalendarModel : public nsICalendarModel,
|
||||
public nsIModel
|
||||
public nsIModel,
|
||||
public nsIXPFCObserver,
|
||||
public nsIXPFCSubject,
|
||||
public nsIXPFCCommandReceiver
|
||||
{
|
||||
|
||||
public:
|
||||
|
@ -39,6 +45,17 @@ public:
|
|||
NS_IMETHOD GetCalendarUser(nsICalendarUser *& aCalendarUser);
|
||||
NS_IMETHOD SetCalendarUser(nsICalendarUser* aCalendarUser);
|
||||
|
||||
// nsIXPFCObserver methods
|
||||
NS_IMETHOD_(nsEventStatus) Update(nsIXPFCSubject * aSubject, nsIXPFCCommand * aCommand);
|
||||
|
||||
// nsIXPFCCommandReceiver methods
|
||||
NS_IMETHOD_(nsEventStatus) Action(nsIXPFCCommand * aCommand);
|
||||
|
||||
// nsIXPFCSubject methods
|
||||
NS_IMETHOD Attach(nsIXPFCObserver * aObserver);
|
||||
NS_IMETHOD Detach(nsIXPFCObserver * aObserver);
|
||||
NS_IMETHOD Notify(nsIXPFCCommand * aCommand);
|
||||
|
||||
protected:
|
||||
nsICalendarUser * mCalendarUser;
|
||||
|
||||
|
|
|
@ -22,10 +22,21 @@
|
|||
#include "nsCoreCIID.h"
|
||||
#include "nsxpfcCIID.h"
|
||||
#include "nsICalendarUser.h"
|
||||
#include "nsxpfcCIID.h"
|
||||
#include "nsIXPFCCommand.h"
|
||||
#include "nsIXPFCObserverManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kICalendarModelIID, NS_ICALENDAR_MODEL_IID);
|
||||
static NS_DEFINE_IID(kIModelIID, NS_IMODEL_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kXPFCSubjectIID, NS_IXPFC_SUBJECT_IID);
|
||||
static NS_DEFINE_IID(kXPFCCommandIID, NS_IXPFC_COMMAND_IID);
|
||||
static NS_DEFINE_IID(kXPFCCommandCID, NS_XPFC_COMMAND_CID);
|
||||
static NS_DEFINE_IID(kCXPFCObserverManagerCID, NS_XPFC_OBSERVERMANAGER_CID);
|
||||
static NS_DEFINE_IID(kIXPFCObserverManagerIID, NS_IXPFC_OBSERVERMANAGER_IID);
|
||||
static NS_DEFINE_IID(kXPFCObserverIID, NS_IXPFC_OBSERVER_IID);
|
||||
static NS_DEFINE_IID(kXPFCCommandReceiverIID, NS_IXPFC_COMMANDRECEIVER_IID);
|
||||
|
||||
nsCalendarModel::nsCalendarModel(nsISupports* outer)
|
||||
{
|
||||
|
@ -56,6 +67,21 @@ nsresult nsCalendarModel::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kXPFCObserverIID)) {
|
||||
*aInstancePtr = (void*)(nsIXPFCObserver *) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kXPFCSubjectIID)) {
|
||||
*aInstancePtr = (void*) (nsIXPFCSubject *)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kXPFCCommandReceiverIID)) {
|
||||
*aInstancePtr = (void*)(nsIXPFCCommandReceiver *) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return (NS_NOINTERFACE);
|
||||
|
||||
|
@ -88,3 +114,56 @@ NS_IMETHODIMP nsCalendarModel :: SetCalendarUser(nsICalendarUser* aCalendarUser)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsEventStatus nsCalendarModel::Update(nsIXPFCSubject * aSubject, nsIXPFCCommand * aCommand)
|
||||
{
|
||||
|
||||
/*
|
||||
* Update our internal structure based on this update
|
||||
*/
|
||||
|
||||
Action(aCommand);
|
||||
|
||||
/*
|
||||
* Tell others we are updated
|
||||
*/
|
||||
|
||||
Notify(aCommand);
|
||||
|
||||
return (nsEventStatus_eIgnore);
|
||||
}
|
||||
|
||||
nsEventStatus nsCalendarModel::Action(nsIXPFCCommand * aCommand)
|
||||
{
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
nsresult nsCalendarModel :: Attach(nsIXPFCObserver * aObserver)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsCalendarModel :: Detach(nsIXPFCObserver * aObserver)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsCalendarModel :: Notify(nsIXPFCCommand * aCommand)
|
||||
{
|
||||
nsIXPFCSubject * subject;
|
||||
|
||||
nsresult res = QueryInterface(kXPFCSubjectIID,(void **)&subject);
|
||||
|
||||
if (res != NS_OK)
|
||||
return res;
|
||||
|
||||
nsIXPFCObserverManager* om;
|
||||
|
||||
nsServiceManager::GetService(kCXPFCObserverManagerCID, kIXPFCObserverManagerIID, (nsISupports**)&om);
|
||||
|
||||
res = om->Notify(subject,aCommand);
|
||||
|
||||
nsServiceManager::ReleaseService(kCXPFCObserverManagerCID, om);
|
||||
|
||||
return(res);
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ nsresult nsCalTimeContext::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
return (NS_OK);
|
||||
return (NS_NOINTERFACE);
|
||||
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче