Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

428 lines
16 KiB

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