| <<< Event Handling Within A Module | Chapters | The PS/Workshop Interfaces >>> |
This chapter describes the module structure that is created for you automatically when you use the PS/Workshop AppWizard as a basis for a new module. The relationships between the classes produced are detailed in Figure 5-1. A more in-depth description of each class is given in the rest of this chapter. See Appendix A, "Interface Functions" for a description of the interfaces that each class supports.
Figure 5-1 Overview of the structure of a module created using the AppWizard
The CAddinImpl class receives all events and messages from PS/Workshop and passes them to the encapsulated CAddonMain class.
It is also responsible for instantiating the class itself (IPSWAddIn::OnConnection) and deleting the class (IPSWAddIn::OnDisconnection).
This class supports both the IPSWAddIn and IPSWEvents interfaces. During the initial IPSWAddIn::OnConnection event, CAddinImpl creates an instance of the CAddonMain class. Subsequent messages from PS/Workshop are passed to this encapsulated CAddonMain object.
CAddinImpl has a single data member:
CAddonMain *m_pMain |
The CXXXApp class is an MFC-generated module application object, and is provided as part of the MFC framework of the module. You should place any initialisation code for a module in either the CAddinImpl or CAddonMain classes, rather than this class.
CXXXApp contains the following functions.
BOOL InitInstance() |
Performs initialisation of the module.
int ExitInstance() |
Performs clean-up of the application.
The CAddonMain class receives all events and messages from the CAddinImpl class. These can either be handled by the appropriate message handler in CAddonMain, or passed on to CAddonDoc for handling.
The following is a summary of the CAddonMain class.
CComQIPtr<IPSWApp> m_pAppInterface |
|
CMap<IPSWDoc*, IPSWDoc*, CAddonDoc*, CAddonDoc* > m_InterfaceVsDocMap |
Maintains a mapping between the list of the IPSWDoc interface pointer and the associated CAddonDoc class |
OnDocClose |
Handles the IPSWEvents::OnDocClose message |
OnDocOpen |
Handles the IPSWEvents::OnDocOpen message |
OnPartChange |
Handles the IPSWEvents::OnPartChange message |
OnSelectTopols |
Handles the IPSWEvents::OnSelectTopols message |
OnViewClose |
Handles the IPSWEvents::OnViewClose message |
OnViewOpen |
Handles the IPSWEvents::OnViewOpen message |
OnCmdMsg |
Handles the IPSWEvents::OnCommand message |
GetActiveDocument |
CAddonDoc* |
StartModule |
Handles the IPSWAddIn::OnConnection event |
OnAppDestroy |
Handles the IPSWAddIn::OnDisconnection event |
CAddonMain contains the following functions.
CAddonMain ( --- received arguments --- IDispatch *pIPSWApp ) |
Constructs a CAddonMain object.
pIPSWApp |
|
HRESULT OnDocClose ( --- received arguments --- IPSWDoc *pDoc ) |
Handles the IPSWEvents::OnDocClose event.
pDoc |
|
This function traverses the interface/document map (m_pInterfaceVsDocMap) and passes the event to the correct document to handle.
HRESULT OnDocOpen ( --- received arguments --- IPSWDoc *pDoc ) |
Handles the IPSWEvents::OnDocOpen event.
pDoc |
|
This function creates a new CAddonDoc object and adds this to the interface/document map (m_pInterfaceVsDocMap).
HRESULT OnPartChange() |
Handles the IPSWEvents::OnPartChange event.
This function passes the event to each of the documents.
HRESULT OnSelectTopols() |
Handles the IPSWEvents::OnSelectTopols event.
This function passes the event to each of the documents.
HRESULT OnViewClose ( --- received arguments --- IPSWDoc *pDoc, IPSWView *pView ) |
Handles the IPSWEvents::OnViewClose event.
pDoc |
|
pView |
|
This function traverses the interface/document map (m_pInterfaceVsDocMap) for the associated document and passes the event to it.
HRESULT OnViewOpen ( --- received arguments --- IPSWDoc *pDoc, IPSWView *pView ) |
Handles the IPSWEvents::OnViewOpen event.
pDoc |
|
pView |
|
This function traverses the interface/document map (m_pInterfaceVsDocMap) and passes the event to the correct CAddonDoc.
HRESULT OnCmdMsg ( --- received arguments --- UINT nID, void *lpparam = NULL ) |
Handles the IPSWEvents::OnCommand event.
nID |
|
lpparam |
|
The OnCmdMsg function looks for the function associated with the ID in the CAddonMain class. If it fails to find one, the event is passed to the CAddonDoc class to handle.
CAddonDoc* GetActiveDocument() |
This function returns the currently active CAddonDoc class. If there is no currently active document it returns NULL.
HRESULT StartModule ( --- received arguments --- IPSWAddIn *pApp ) |
This function handles initialisation of the PS/Workshop module. It is called as a result of IPSWAddIn::OnConnection.
pApp |
|
You should add any one-time initialisation code for your module here. This includes code for adding menu items, as well as registering any callback functions.
If this function returns a failure code then the CAddinImpl::OnConnection deletes the CAddonMain class and itself returns a failure which forces PS/Workshop to unload the module.
HRESULT OnAppDestroy() |
This function handles destruction of the module. It is called as a result of IPSWAddIn::OnDisconnection.
OnAppDestroy traverses the interface/document map (m_pInterfaceVsDocMap) deleting each document.
The CAddonDoc class represents a module document that shadows the current PS/Workshop document.
The following is a summary of the CAddonDoc class.
CAddonMain *m_addonMain |
|
int m_nParts |
|
PK_PART_t *m_pkParts |
|
CComPtr<IPSWDoc> m_pDocInterface |
|
CComPtr<IPSWParts> m_pPartList |
|
CComPtr<IPSWSelectionList> m_pSelectionList |
|
CComPtr<IPSWDrawList> m_pDrawList |
|
CcomPtr<IPSWRollback> m_pRollback |
|
CMap< IPSWView*, IPSWView*, CAddonView*, CAddonView* > m_InterfaceVsViewMap |
Maintains a list of the IPSWView interfaces and the associated CAddonView class |
CAddonDoc |
OnDocClose |
Handles the CAddonMain::OnDocClose message |
OnPartChange |
Handles the CAddonMain::OnPartChange message |
OnSelectTopols |
Handles the CAddonMain::OnSelectTopols message |
OnViewClose |
Handles the CAddonMain::OnViewClose message |
OnViewOpen |
Handles the CAddonMain::OnViewOpen message |
OnCmdMsg |
Handles the CAddonMain::OnCmdMsg message |
CComPtr<IPSWDoc>& GetDocumentInterface |
|
CComPtr<IPSWSelectionList>& GetSelectionInterface |
|
CComPtr<IPSWDrawList>& GetDrawInterface |
|
CComPtr<IPSWParts>& GetPartInterface |
|
CComPtr<IPSWRollback>& GetRollbackInterface |
GetActiveView |
CAddonView* |
|
GetParts |
HRESULT |
OnMyFunction |
CAddonDoc contains the following functions.
CAddonDoc ( --- received arguments --- IPSWDoc *pDoc, CAddonMain *pMain ) |
This function constructs a CAddonDoc object and sets the values of the following interfaces:
pDoc |
|
pMain |
|
The CAddonDoc constructor also queries and sets the correct values for m_nParts and m_pkParts.
HRESULT OnDocClose ( --- received arguments --- IPSWDoc *pDoc ) |
This function handles any CAddonMain::OnDocClose events passed to it from CAddonMain.
pDoc |
|
It traverses the view/interface map (m_InterfaceVsViewMap) and deletes the associated view.
HRESULT OnPartChange() |
This function handles the CAddonMain::OnPartChange events passed to it from CAddonMain.
m_pkParts
array, which stores a copy of the parts in the document.
m_nparts
(the length of
m_pkParts
) to zero.
m_pkParts
.
m_nparts
accordingly.
HRESULT OnSelectTopols() |
This function handles the CAddonMain::OnSelectTopols events passed to it from CAddonMain.
Events can either be handled here or passed to the active view using the CAddonView class.
HRESULT OnViewClose ( --- received arguments --- IPSWDoc *pDoc, IPSWView *pView ) |
This function handles the CAddonMain::OnViewClose events passed to it from CAddonMain.
pDoc |
|
pView |
|
It traverses the view/interface map (m_InterfaceVsViewMap) and deletes the associated view.
HRESULT OnViewOpen ( --- received arguments --- IPSWDoc *pDoc, IPSWView *pView ) |
This function handles the CAddonMain::OnViewOpen events passed to it from CAddonMain.
pDoc |
|
pView |
|
It traverses the view/interface map (m_InterfaceVsViewMap) and opens the associated view.
HRESULT OnCmdMsg ( --- received arguments --- UINT nID, void *lpparam = NULL ) |
This function handles CAddonMain::OnCmdMsg events passed to it from CAddonMain.
nID |
|
lpparam |
|
It looks for a handler for the
nID
message in the CAddonDoc class. If it is unable to find a handler then the event is passed to the CAddonView class.
CComPtr<IPSWDoc>& GetDocumentInterface() |
This function returns the IPSWDoc interface.
CComPtr<IPSWSelectionList>& GetSelectionInterface() |
This function returns the IPSWSelectionList interface.
CComPtr<IPSWDrawList>& GetDrawInterface() |
This function returns the IPSWDrawList interface.
CComPtr<IPSWParts>& GetPartInterface() |
This function returns the IPSWParts interface.
CComPtr<IPSWRollback>& GetRollbackInterface() |
This function returns the IPSWRollback interface.
CAddonView* GetActiveView() |
This function returns the currently active view. If there is no active view then this will return NULL.
HRESULT GetParts ( --- returned arguments --- int &nParts, PK_PART_t *&pkParts ) |
This function returns the number of parts in the document. It interrogates and returns a copy of the parts in the PS/Workshop document.
&nParts |
|
&pkParts |
|
This function allocates an array of the parts in PS/Workshop. It is up to the module to correctly free the returned array, using
delete[]
.
|
Note: This function does not return m_nPart and m_pkParts variables defined in the CAddonDoc class |
HRESULT OnMyFunction() |
This function is supplied to demonstrate the message handling functionality.
When the module as created by the AppWizard is compiled and built, a new menu item is added to PS/Workshop. OnMyFunction is called when the user clicks on this new menu item. OnMyFunction simply displays a message indicating that this function has been reached.
The CAddonView class represents a module view that shadows the current PS/Workshop view.
The following is a summary of the CAddonView class.
CAddonDoc* m_doc |
|
CComQIPtr<IPSWView2> m_pViewInterface |
CAddonView |
OnCmdMsg |
Handles the CAddonDoc::OnCmdMsg message |
CComQIPtr<IPSWView2>& GetViewInterface |
CAddonView contains the following functions.
CAddonView ( --- received arguments --- IPSWView *pView, CAddonDoc *pDoc ) |
This function constructs the CAddonView object.
pView |
|
pDoc |
|
HRESULT OnCmdMsg ( --- received arguments --- UINT nID, void *lpparam ) |
This function handles the CAddonDoc::OnCmdMsg message.
nID |
|
lpparam |
|
CComQIPtr<IPSWView2>& GetViewInterface() |
This function returns the encapsulated IPSWView2 interface.
| <<< Event Handling Within A Module | Chapters | The PS/Workshop Interfaces >>> |