home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / OCCIMPL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  14.9 KB  |  429 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #ifndef _AFX_NO_OCC_SUPPORT
  12.  
  13. #include "olebind.h"
  14. #include "ocdbid.h"
  15. #include "ocdb.h"
  16.  
  17. class CDataSourceControl;
  18. class CDataBoundProperty;
  19.  
  20. // CCmdTarget
  21.     class COleControlContainer;
  22.     class COleControlSite;
  23.  
  24. class COccManager;
  25. struct _AFX_OCC_DIALOG_INFO;
  26.  
  27. #define DISPID_DATASOURCE   0x80010001
  28. #define DISPID_DATAFIELD    0x80010002
  29.  
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // OLE Databinding support class for data sources
  33.  
  34. class CDataSourceControl
  35. {
  36. private:
  37.     CDataSourceControl() {};
  38. public:
  39.     struct METAROWTYPE
  40.     {
  41.         DBCOLUMNID idColumnID;
  42.         DWORD dwColumnID;
  43.         LPSTR lpstrName;
  44.         DWORD dwName;
  45.         CPtrList* m_pClientList;
  46.     };
  47.  
  48.     CDataSourceControl(COleControlSite *pClientSite);
  49.     ~CDataSourceControl();
  50.     HRESULT Initialize();
  51.     virtual ICursor* GetCursor();
  52.     HRESULT GetMetaData();
  53.     virtual void BindProp(COleControlSite* pClientSite, BOOL bBind = TRUE);
  54.     virtual void BindProp(CDataBoundProperty* pProperty, BOOL bBind = TRUE);
  55.     virtual void BindColumns();
  56.     BOOL CopyColumnID(DBCOLUMNID* pcidDst, DBCOLUMNID const *pcidSrc);
  57.     HRESULT GetBoundClientRow();
  58.     virtual HRESULT UpdateControls();
  59.     virtual HRESULT UpdateCursor();
  60.  
  61.     COleControlSite *m_pClientSite;  // Back ptr to containing site
  62.     ICursorMove* m_pCursorMove;
  63.     ICursorUpdateARow* m_pCursorUpdateARow;
  64.     int m_nColumns;
  65.     METAROWTYPE* m_pMetaRowData;
  66.     CPtrList m_CursorBoundProps;
  67.     void* m_pVarData;
  68.     int m_nBindings;
  69.     DBCOLUMNBINDING *m_pColumnBindings;
  70.     VARIANT* m_pValues;
  71.     BOOL m_bUpdateInProgress;
  72. };
  73.  
  74. /////////////////////////////////////////////////////////////////////////////
  75. // OLE Databinding support class for bound controls
  76.  
  77. class CDataBoundProperty
  78. {
  79. protected:
  80.     CDataBoundProperty() {};
  81. public:
  82.     CDataBoundProperty(CDataBoundProperty* pLast, DISPID dispid, WORD ctlid);
  83.     ~CDataBoundProperty() {};
  84.     void SetClientSite(COleControlSite *pClientSite);
  85.     void SetDSCSite(COleControlSite *pDSCSite);
  86.     void RemoveSource();
  87.     void Notify();
  88.     ICursor* GetCursor();
  89.     CDataBoundProperty* GetNext();
  90.  
  91.     COleControlSite *m_pClientSite;  // Back ptr to containing site
  92.     WORD m_ctlid;
  93.     DISPID m_dispid;
  94.     COleControlSite *m_pDSCSite;
  95.     BOOL m_bOwnXferOut;
  96.     BOOL m_bIsDirty;
  97.     CDataBoundProperty* m_pNext;
  98. };
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // Control containment helper functions
  102.  
  103. DLGTEMPLATE* _AfxSplitDialogTemplate(const DLGTEMPLATE* pTemplate,
  104.     CMapWordToPtr* pOleItemMap);
  105.  
  106. void _AfxZOrderOleControls(CWnd* pWnd, CMapWordToPtr* pOleItemMap);
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // COleControlContainer - implementation class
  110.  
  111. class COleControlContainer : public CCmdTarget
  112. {
  113. public:
  114. // Constructors/destructors
  115.     COleControlContainer(CWnd*  pWnd);
  116.     virtual ~COleControlContainer();
  117.  
  118. // Operations
  119.     BOOL CreateControl(CWnd* pWndCtrl, REFCLSID clsid,
  120.         LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, UINT nID,
  121.         CFile* pPersist=NULL, BOOL bStorage=FALSE, BSTR bstrLicKey=NULL,
  122.         COleControlSite** ppNewSite=NULL);
  123.     virtual COleControlSite* FindItem(UINT nID) const;
  124.     virtual BOOL GetAmbientProp(COleControlSite* pSite, DISPID dispid,
  125.         VARIANT* pvarResult);
  126.     void CreateOleFont(CFont* pFont);
  127.     void FreezeAllEvents(BOOL bFreeze);
  128.     virtual void ScrollChildren(int dx, int dy);
  129.     virtual void OnUIActivate(COleControlSite* pSite);
  130.     virtual void OnUIDeactivate(COleControlSite* pSite);
  131.  
  132.     virtual void CheckDlgButton(int nIDButton, UINT nCheck);
  133.     virtual void CheckRadioButton(int nIDFirstButton, int nIDLastButton,
  134.         int nIDCheckButton);
  135.     virtual CWnd* GetDlgItem(int nID) const;
  136.     virtual void GetDlgItem(int nID, HWND* phWnd) const;
  137.     virtual UINT GetDlgItemInt(int nID, BOOL* lpTrans, BOOL bSigned) const;
  138.     virtual int GetDlgItemText(int nID, LPTSTR lpStr, int nMaxCount) const;
  139.     virtual LRESULT SendDlgItemMessage(int nID, UINT message, WPARAM wParam,
  140.         LPARAM lParam);
  141.     virtual void SetDlgItemInt(int nID, UINT nValue, BOOL bSigned);
  142.     virtual void SetDlgItemText(int nID, LPCTSTR lpszString);
  143.     virtual UINT IsDlgButtonChecked(int nIDButton) const;
  144.  
  145. // Attributes
  146.     CWnd* m_pWnd;
  147.     CMapPtrToPtr m_siteMap;
  148.     COLORREF m_crBack;
  149.     COLORREF m_crFore;
  150.     LPFONTDISP m_pOleFont;
  151.     COleControlSite* m_pSiteUIActive;
  152.  
  153. public:
  154.     // Interface maps
  155.     BEGIN_INTERFACE_PART(OleIPFrame, IOleInPlaceFrame)
  156.         INIT_INTERFACE_PART(COleControlContainer, OleIPFrame)
  157.         STDMETHOD(GetWindow)(HWND*);
  158.         STDMETHOD(ContextSensitiveHelp)(BOOL);
  159.         STDMETHOD(GetBorder)(LPRECT);
  160.         STDMETHOD(RequestBorderSpace)(LPCBORDERWIDTHS);
  161.         STDMETHOD(SetBorderSpace)(LPCBORDERWIDTHS);
  162.         STDMETHOD(SetActiveObject)(LPOLEINPLACEACTIVEOBJECT, LPCOLESTR);
  163.         STDMETHOD(InsertMenus)(HMENU, LPOLEMENUGROUPWIDTHS);
  164.         STDMETHOD(SetMenu)(HMENU, HOLEMENU, HWND);
  165.         STDMETHOD(RemoveMenus)(HMENU);
  166.         STDMETHOD(SetStatusText)(LPCOLESTR);
  167.         STDMETHOD(EnableModeless)(BOOL);
  168.         STDMETHOD(TranslateAccelerator)(LPMSG, WORD);
  169.     END_INTERFACE_PART(OleIPFrame)
  170.  
  171.     BEGIN_INTERFACE_PART(OleContainer, IOleContainer)
  172.         INIT_INTERFACE_PART(COleControlContainer, OleContainer)
  173.         STDMETHOD(ParseDisplayName)(LPBINDCTX, LPOLESTR, ULONG*, LPMONIKER*);
  174.         STDMETHOD(EnumObjects)(DWORD, LPENUMUNKNOWN*);
  175.         STDMETHOD(LockContainer)(BOOL);
  176.     END_INTERFACE_PART(OleContainer)
  177.  
  178.     DECLARE_INTERFACE_MAP()
  179.     DECLARE_DISPATCH_MAP()
  180. };
  181.  
  182.  
  183. /////////////////////////////////////////////////////////////////////////////
  184. // COleControlSite - implementation class
  185.  
  186. class COleControlSite : public CCmdTarget
  187. {
  188. public:
  189. // Constructors/destructors
  190.     COleControlSite(COleControlContainer* pCtrlCont);
  191.     ~COleControlSite();
  192.  
  193. // Operations
  194.     HRESULT CreateControl(CWnd* pWndCtrl, REFCLSID clsid,
  195.         LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, UINT nID,
  196.         CFile* pPersist=NULL, BOOL bStorage=FALSE, BSTR bstrLicKey=NULL);
  197.     virtual BOOL DestroyControl();
  198.     UINT GetID();
  199.     BOOL GetEventIID(IID* piid);
  200.     virtual HRESULT DoVerb(LONG nVerb, LPMSG lpMsg = NULL);
  201.     BOOL IsDefaultButton();
  202.     DWORD GetDefBtnCode();
  203.     void SetDefaultButton(BOOL bDefault);
  204.     void GetControlInfo();
  205.     BOOL IsMatchingMnemonic(LPMSG lpMsg);
  206.     void SendMnemonic(LPMSG lpMsg);
  207.     void FreezeEvents(BOOL bFreeze);
  208.  
  209.     virtual void InvokeHelperV(DISPID dwDispID, WORD wFlags, VARTYPE vtRet,
  210.         void* pvRet, const BYTE* pbParamInfo, va_list argList);
  211.     virtual void SetPropertyV(DISPID dwDispID, VARTYPE vtProp,
  212.         va_list argList);
  213.     virtual void AFX_CDECL InvokeHelper(DISPID dwDispID, WORD wFlags, VARTYPE vtRet,
  214.         void* pvRet, const BYTE* pbParamInfo, ...);
  215.     virtual void GetProperty(DISPID dwDispID, VARTYPE vtProp, void* pvProp) const;
  216.     virtual void AFX_CDECL SetProperty(DISPID dwDispID, VARTYPE vtProp, ...);
  217.     virtual BOOL AFX_CDECL SafeSetProperty(DISPID dwDispID, VARTYPE vtProp, ...);
  218.  
  219.     virtual DWORD GetStyle() const;
  220.     virtual DWORD GetExStyle() const;
  221.     virtual BOOL ModifyStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags);
  222.     virtual BOOL ModifyStyleEx(DWORD dwRemove, DWORD dwAdd, UINT nFlags);
  223.     virtual void SetWindowText(LPCTSTR lpszString);
  224.     virtual void GetWindowText(CString& str) const;
  225.     virtual int GetWindowText(LPTSTR lpszStringBuf, int nMaxCount) const;
  226.     virtual int GetWindowTextLength() const;
  227.     virtual int GetDlgCtrlID() const;
  228.     virtual int SetDlgCtrlID(int nID);
  229.     virtual void MoveWindow(int x, int y, int nWidth, int nHeight,
  230.         BOOL bRepaint);
  231.     virtual BOOL SetWindowPos(const CWnd* pWndInsertAfter, int x, int y,
  232.         int cx, int cy, UINT nFlags);
  233.     virtual BOOL ShowWindow(int nCmdShow);
  234.     virtual BOOL IsWindowEnabled() const;
  235.     virtual BOOL EnableWindow(BOOL bEnable);
  236.     virtual CWnd* SetFocus();
  237.     virtual void EnableDSC();
  238.     virtual void BindDefaultProperty(DISPID dwDispID, VARTYPE vtProp, LPCTSTR szFieldName, CWnd* pDSCWnd);
  239.     virtual void BindProperty(DISPID dwDispId, CWnd* pWndDSC);
  240.  
  241. // Overridables
  242.     virtual BOOL QuickActivate();
  243.  
  244. // Attributes
  245.     COleControlContainer* m_pCtrlCont;
  246.     HWND m_hWnd;
  247.     CWnd* m_pWndCtrl;
  248.     UINT m_nID;
  249.     CRect m_rect;
  250.     IID m_iidEvents;
  251.     LPOLEOBJECT m_pObject;
  252.     LPOLEINPLACEOBJECT m_pInPlaceObject;
  253.     LPOLEINPLACEACTIVEOBJECT m_pActiveObject;
  254.     COleDispatchDriver m_dispDriver;
  255.     DWORD m_dwEventSink;
  256.     DWORD m_dwPropNotifySink;
  257.     DWORD m_dwStyleMask;
  258.     DWORD m_dwStyle;
  259.     DWORD m_dwMiscStatus;
  260.     CONTROLINFO m_ctlInfo;
  261.  
  262.     // Databound control stuff
  263.     DWORD m_dwNotifyDBEvents; // INotifyDBEvents sink cookie
  264.     CDataSourceControl* m_pDataSourceControl;
  265.     CDataBoundProperty* m_pBindings;
  266.     union {
  267.         COleControlSite *m_pDSCSite;
  268.         WORD m_ctlidRowSource;
  269.     };
  270.     DISPID m_defdispid;
  271.     UINT m_dwType;
  272.     CString m_strDataField;
  273.     BOOL m_bIgnoreNotify;
  274.     BOOL m_bIsDirty;
  275.     VARIANT m_varResult;
  276.  
  277. protected:
  278. // Implementation
  279.     BOOL SetExtent();
  280.     HRESULT CreateOrLoad(REFCLSID clsid, CFile* pPersist, BOOL bStorage,
  281.         BSTR bstrLicKey);
  282.     DWORD ConnectSink(REFIID iid, LPUNKNOWN punkSink);
  283.     void DisconnectSink(REFIID iid, DWORD dwCookie);
  284.     void AttachWindow();
  285.     void DetachWindow();
  286.     BOOL OnEvent(AFX_EVENT* pEvent);
  287.     HRESULT GetCursor(DISPID dispid, LPLPCURSOR ppcursorOut, LPVOID *ppcidOut);
  288.  
  289. public:
  290. // Interface maps
  291.     BEGIN_INTERFACE_PART(OleClientSite, IOleClientSite)
  292.         INIT_INTERFACE_PART(COleControlSite, OleClientSite)
  293.         STDMETHOD(SaveObject)();
  294.         STDMETHOD(GetMoniker)(DWORD, DWORD, LPMONIKER*);
  295.         STDMETHOD(GetContainer)(LPOLECONTAINER*);
  296.         STDMETHOD(ShowObject)();
  297.         STDMETHOD(OnShowWindow)(BOOL);
  298.         STDMETHOD(RequestNewObjectLayout)();
  299.     END_INTERFACE_PART(OleClientSite)
  300.  
  301.     BEGIN_INTERFACE_PART(OleIPSite, IOleInPlaceSite)
  302.         INIT_INTERFACE_PART(COleControlSite, OleIPSite)
  303.         STDMETHOD(GetWindow)(HWND*);
  304.         STDMETHOD(ContextSensitiveHelp)(BOOL);
  305.         STDMETHOD(CanInPlaceActivate)();
  306.         STDMETHOD(OnInPlaceActivate)();
  307.         STDMETHOD(OnUIActivate)();
  308.         STDMETHOD(GetWindowContext)(LPOLEINPLACEFRAME*,
  309.             LPOLEINPLACEUIWINDOW*, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO);
  310.         STDMETHOD(Scroll)(SIZE);
  311.         STDMETHOD(OnUIDeactivate)(BOOL);
  312.         STDMETHOD(OnInPlaceDeactivate)();
  313.         STDMETHOD(DiscardUndoState)();
  314.         STDMETHOD(DeactivateAndUndo)();
  315.         STDMETHOD(OnPosRectChange)(LPCRECT);
  316.     END_INTERFACE_PART(OleIPSite)
  317.  
  318.     BEGIN_INTERFACE_PART(OleControlSite, IOleControlSite)
  319.         INIT_INTERFACE_PART(COleControlSite, OleControlSite)
  320.         STDMETHOD(OnControlInfoChanged)();
  321.         STDMETHOD(LockInPlaceActive)(BOOL fLock);
  322.         STDMETHOD(GetExtendedControl)(LPDISPATCH* ppDisp);
  323.         STDMETHOD(TransformCoords)(POINTL* lpptlHimetric,
  324.             POINTF* lpptfContainer, DWORD flags);
  325.         STDMETHOD(TranslateAccelerator)(LPMSG lpMsg, DWORD grfModifiers);
  326.         STDMETHOD(OnFocus)(BOOL fGotFocus);
  327.         STDMETHOD(ShowPropertyFrame)();
  328.     END_INTERFACE_PART(OleControlSite)
  329.  
  330.     BEGIN_INTERFACE_PART(AmbientProps, IDispatch)
  331.         INIT_INTERFACE_PART(COleControlSite, AmbientProps)
  332.         STDMETHOD(GetTypeInfoCount)(unsigned int*);
  333.         STDMETHOD(GetTypeInfo)(unsigned int, LCID, ITypeInfo**);
  334.         STDMETHOD(GetIDsOfNames)(REFIID, LPOLESTR*, unsigned int, LCID, DISPID*);
  335.         STDMETHOD(Invoke)(DISPID, REFIID, LCID, unsigned short, DISPPARAMS*,
  336.                           VARIANT*, EXCEPINFO*, unsigned int*);
  337.     END_INTERFACE_PART(AmbientProps)
  338.  
  339.     BEGIN_INTERFACE_PART(PropertyNotifySink, IPropertyNotifySink)
  340.         INIT_INTERFACE_PART(COleControlSite, PropertyNotifySink)
  341.         STDMETHOD(OnChanged)(DISPID dispid);
  342.         STDMETHOD(OnRequestEdit)(DISPID dispid);
  343.     END_INTERFACE_PART(PropertyNotifySink)
  344.  
  345.     BEGIN_INTERFACE_PART(EventSink, IDispatch)
  346.         INIT_INTERFACE_PART(COleControlSite, EventSink)
  347.         STDMETHOD(GetTypeInfoCount)(unsigned int*);
  348.         STDMETHOD(GetTypeInfo)(unsigned int, LCID, ITypeInfo**);
  349.         STDMETHOD(GetIDsOfNames)(REFIID, LPOLESTR*, unsigned int, LCID, DISPID*);
  350.         STDMETHOD(Invoke)(DISPID, REFIID, LCID, unsigned short, DISPPARAMS*,
  351.                           VARIANT*, EXCEPINFO*, unsigned int*);
  352.     END_INTERFACE_PART(EventSink)
  353.  
  354.     BEGIN_INTERFACE_PART(BoundObjectSite, IBoundObjectSite)
  355.         STDMETHOD(GetCursor)(DISPID dispid, LPLPCURSOR ppcursorOut, LPVOID *ppcidOut);
  356.     END_INTERFACE_PART(BoundObjectSite)
  357.  
  358.     BEGIN_INTERFACE_PART(NotifyDBEvents, INotifyDBEvents)
  359.         STDMETHOD(OKToDo)(DWORD dwEventWhat, ULONG cReasons, DBNOTIFYREASON rgReasons[]);
  360.         STDMETHOD(Cancelled)(DWORD dwEventWhat, ULONG cReasons, DBNOTIFYREASON rgReasons[]);
  361.         STDMETHOD(SyncBefore)(DWORD dwEventWhat, ULONG cReasons, DBNOTIFYREASON rgReasons[]);
  362.         STDMETHOD(AboutToDo)(DWORD dwEventWhat, ULONG cReasons, DBNOTIFYREASON rgReasons[]);
  363.         STDMETHOD(FailedToDo)(DWORD dwEventWhat, ULONG cReasons, DBNOTIFYREASON rgReasons[]);
  364.         STDMETHOD(SyncAfter)(DWORD dwEventWhat, ULONG cReasons, DBNOTIFYREASON rgReasons[]);
  365.         STDMETHOD(DidEvent)(DWORD dwEventWhat, ULONG cReasons, DBNOTIFYREASON rgReasons[]);
  366.  
  367.         // Not part of i/f - just a helper
  368.         HRESULT FireEvent(DWORD dwEventWhat, ULONG cReasons,
  369.             DBNOTIFYREASON rgReasons[], DSCSTATE nState);
  370.     END_INTERFACE_PART(NotifyDBEvents)
  371.  
  372.     DECLARE_INTERFACE_MAP()
  373. };
  374.  
  375. /////////////////////////////////////////////////////////////////////////////
  376. // OLE control container manager
  377.  
  378. class COccManager : public CNoTrackObject
  379. {
  380. // Operations
  381. public:
  382.     // Event handling
  383.     virtual BOOL OnEvent(CCmdTarget* pCmdTarget, UINT idCtrl, AFX_EVENT* pEvent,
  384.         AFX_CMDHANDLERINFO* pHandlerInfo);
  385.  
  386.     // Internal object creation
  387.     virtual COleControlContainer* CreateContainer(CWnd* pWnd);
  388.     virtual COleControlSite* CreateSite(COleControlContainer* pCtrlCont);
  389.  
  390.     // Dialog creation
  391.     virtual const DLGTEMPLATE* PreCreateDialog(_AFX_OCC_DIALOG_INFO* pOccDialogInfo,
  392.         const DLGTEMPLATE* pOrigTemplate);
  393.     virtual void PostCreateDialog(_AFX_OCC_DIALOG_INFO* pOccDialogInfo);
  394.     virtual DLGTEMPLATE* SplitDialogTemplate(const DLGTEMPLATE* pTemplate,
  395.         DLGITEMTEMPLATE** ppOleDlgItems);
  396.     virtual BOOL CreateDlgControls(CWnd* pWndParent, LPCTSTR lpszResourceName,
  397.         _AFX_OCC_DIALOG_INFO* pOccDialogInfo);
  398.     virtual BOOL CreateDlgControls(CWnd* pWndParent, void* lpResource,
  399.         _AFX_OCC_DIALOG_INFO* pOccDialogInfo);
  400.  
  401.     // Dialog manager
  402.     virtual BOOL IsDialogMessage(CWnd* pWndDlg, LPMSG lpMsg);
  403.     static BOOL AFX_CDECL IsLabelControl(CWnd* pWnd);
  404.     static BOOL AFX_CDECL IsMatchingMnemonic(CWnd* pWnd, LPMSG lpMsg);
  405.     static void AFX_CDECL SetDefaultButton(CWnd* pWnd, BOOL bDefault);
  406.     static DWORD AFX_CDECL GetDefBtnCode(CWnd* pWnd);
  407.  
  408. // Implementation
  409. protected:
  410.     // Dialog creation
  411.     HWND CreateDlgControl(CWnd* pWndParent, HWND hwAfter, BOOL bDialogEx,
  412.         LPDLGITEMTEMPLATE pDlgItem, WORD nMsg, BYTE* lpData, DWORD cb);
  413.  
  414.     // Databinding
  415.     void BindControls(CWnd* pWndParent);
  416.  
  417.     // Dialog manager
  418.     static void AFX_CDECL UIActivateControl(CWnd* pWndNewFocus);
  419.     static void AFX_CDECL UIDeactivateIfNecessary(CWnd* pWndOldFocus, CWnd* pWndNewFocus);
  420. };
  421.  
  422. struct _AFX_OCC_DIALOG_INFO
  423. {
  424.     DLGTEMPLATE* m_pNewTemplate;
  425.     DLGITEMTEMPLATE** m_ppOleDlgItems;
  426. };
  427.  
  428. #endif // !_AFX_NO_OCC_SUPPORT
  429.