core/vgui/impl/win32/vgui_win32_cmdtarget.h
Go to the documentation of this file.
00001 // This is core/vgui/impl/win32/vgui_win32_cmdtarget.h
00002 
00003 // To simplify the message handling code in globalWndProc(in vgui_win32.cxx),
00004 // which is usually a long switch-case statement, We structure that code
00005 // using message-mapping technique employed by Microsoft Foundation Class.
00006 // To do this, a number of macros (DECLARE_MESSAGE_MAP, BEGIN_MESSAGE_MAP,
00007 // END_MESSAGE_MAP, ON_COMMAND), structures (WIN32_MSGMAP, 
00008 // WIN32_MSGMAP_ENTRY), and the class vgui_win32_cmdtarget (whose MFC 
00009 // counterpart is CCmdTarget) are defined here. In particular 
00010 // vgui_win32_cmdtarget is the final stop of message processing.
00011 
00012 // TODO: vgui_win32_cmdtarget is not fully developed yet and for now not
00013 // used in the Win32 SDK implementation of VGUI.
00014 
00015 #ifndef vgui_win32_cmdtarget_h_
00016 #define vgui_win32_cmdtarget_h_
00017 
00018 #include <windows.h>
00019 
00020 struct AFX_MSGMAP_ENTRY;
00021 
00022 struct AFX_MSGMAP
00023 {
00024   const AFX_MSGMAP* pBaseMessageMap;
00025   const AFX_MSGMAP_ENTRY* lpEntries;
00026 };
00027 
00028 #define DECLARE_MESSAGE_MAP() \
00029 private: \
00030   static const AFX_MSGMAP_ENTRY messageEntries_[]; \
00031 protected: \
00032   static const AFX_MSGMAP messageMap; \
00033   virtual const AFX_MSGMAP* GetMessageMap() const;
00034 
00035 #define BEGIN_MESSAGE_MAP(theClass, baseClass) \
00036   const AFX_MSGMAP* theClass::GetMessageMap() const \
00037   { return &theClass::messageMap; } \
00038   const AFX_MSGMAP theClass::messageMap = \
00039   { &(baseClass::messageMap), \
00040    (AFX_MSGMAP_ENTRY*) &(theClass::messageEntries_) }; \
00041   const AFX_MSGMAP_ENTRY theClass::messageEntries_[] = \
00042   {
00043 
00044 #define END_MESSAGE_MAP() \
00045     { 0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } \
00046   };
00047 
00048 enum AfxSig
00049 {
00050    AfxSig_end = 0,     // [marks end of message map]
00051    AfxSig_vv,
00052 };
00053 
00054 #define ON_COMMAND(id, memberFxn) \
00055     { WM_COMMAND, 0, (WORD)id, (WORD)id, AfxSig_vv, (AFX_PMSG)memberFxn },
00056 #define ON_WM_CREATE() \
00057     { WM_CREATE, 0, 0, 0, AfxSig_is, \
00058      (AFX_PMSG)(AFX_PMSGW)(int AFX_MSG_CALL CWnd::*)(LPCREATESTRUCT)OnCreate},
00059 
00060 class vgui_win32_cmdtarget
00061 {
00062 public:
00063   vgui_win32_cmdtarget() {}
00064   ~vgui_win32_cmdtarget() {}
00065 
00066   // Message handling function
00067   virtual BOOL OnCmdMsg(UINT message, WPARAM wParam, LPARAM lParam);
00068 
00069   DECLARE_MESSAGE_MAP()
00070 };
00071 
00072 typedef void (vgui_win32_cmdtarget::*AFX_PMSG)(void);
00073 
00074 struct AFX_MSGMAP_ENTRY  // MFC 4.0 format
00075 {
00076   UINT nMessage; // windows message
00077   UINT nCode;    // control code or WM_NOTIFY code
00078   UINT nID;      // control ID (or 0 for windows messages)
00079   UINT nLastID;  // used for entries specifying a range of control id's
00080   UINT nSig;     // signature type (action) or pointer to message #
00081   AFX_PMSG pfn;  // routine to call (or special value)
00082 };
00083 
00084 #endif // vgui_win32_cmdtarget_h_