From b84668b9abb07d50b7922d8b5a492fcc402fd740 Mon Sep 17 00:00:00 2001 From: "spider%netscape.com" Date: Mon, 12 Oct 1998 21:29:16 +0000 Subject: [PATCH] Have the Model support the Observable interfaces --- calendar/modules/core/inc/nsCalendarModel.h | 19 ++++- calendar/modules/core/src/nsCalendarModel.cpp | 79 +++++++++++++++++++ .../ui/context/src/nsCalTimeContext.cpp | 2 +- 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/calendar/modules/core/inc/nsCalendarModel.h b/calendar/modules/core/inc/nsCalendarModel.h index a8a083279985..75154e8db82f 100644 --- a/calendar/modules/core/inc/nsCalendarModel.h +++ b/calendar/modules/core/inc/nsCalendarModel.h @@ -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; diff --git a/calendar/modules/core/src/nsCalendarModel.cpp b/calendar/modules/core/src/nsCalendarModel.cpp index 5985a6c13992..de7d9058b2ce 100644 --- a/calendar/modules/core/src/nsCalendarModel.cpp +++ b/calendar/modules/core/src/nsCalendarModel.cpp @@ -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); +} diff --git a/calendar/modules/ui/context/src/nsCalTimeContext.cpp b/calendar/modules/ui/context/src/nsCalTimeContext.cpp index 4291a528d1bc..1e6a6447b8aa 100644 --- a/calendar/modules/ui/context/src/nsCalTimeContext.cpp +++ b/calendar/modules/ui/context/src/nsCalTimeContext.cpp @@ -124,7 +124,7 @@ nsresult nsCalTimeContext::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_OK; } - return (NS_OK); + return (NS_NOINTERFACE); }