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.

437 lines
16 KiB

  1. // Document.h : Declaration of the CTriEditDocument
  2. // Copyright (c)1997-1999 Microsoft Corporation, All Rights Reserved
  3. #ifndef __DOCUMENT_H_
  4. #define __DOCUMENT_H_
  5. #include "resource.h" // main symbols
  6. #include "token.h"
  7. #include "triedcid.h"
  8. #include "trixacc.h"
  9. #include <mshtmhst.h>
  10. #define grfInSingleRow 0x00000001 // selection is in any number of cells within a single row
  11. #define grfSelectOneCell 0x00000002 // only one single cell is selected
  12. #define grpSelectEntireRow 0x00000004 // selection is any number of whole rows being selected
  13. #define IE5_SPACING
  14. #ifdef IE5_SPACING
  15. class CTridentEventSink;
  16. #endif //IE5_SPACING
  17. typedef enum {
  18. CONSTRAIN_NONE,
  19. CONSTRAIN_HORIZONTAL,
  20. CONSTRAIN_VERTICAL
  21. } ENUMCONSTRAINDIRECTION;
  22. DEFINE_GUID(GUID_TriEditCommandGroup,
  23. 0x2582f1c0, 0x84e, 0x11d1, 0x9a, 0xe, 0x0, 0x60, 0x97, 0xc9, 0xb3, 0x44);
  24. //for use with IDM_TRIED_LOCK_ELEMENT
  25. #define DESIGN_TIME_LOCK L"Design_Time_Lock"
  26. // The following definition is used in LockElement while invalidating the element.
  27. // This size is dependent on Trident's grab handle size.
  28. // This value should be atleast as big as Trident's grab handle size.
  29. #define ELEMENT_GRAB_SIZE 12
  30. #ifndef SAFERELEASE
  31. #define SAFERELEASE(a) if (a) {a->Release();a=NULL;}
  32. #endif //SAFERELEASE
  33. #include "zorder.h"
  34. #ifdef IE5_SPACING
  35. // move followign defines in a new header file - uniqueid,h
  36. #define INDEX_NIL 0
  37. #define INDEX_DSP 1
  38. #define INDEX_COMMENT 2
  39. #define INDEX_AIMGLINK 3
  40. #define INDEX_OBJ_COMMENT 4
  41. #define INDEX_MAX 5
  42. #define MIN_MAP 20
  43. #define cchID 20
  44. struct MAPSTRUCT
  45. {
  46. WCHAR szUniqueID[cchID];
  47. WCHAR szDspID[cchID];
  48. int ichNonDSP;
  49. BOOL fLowerCase;
  50. int iType;
  51. };
  52. #define MIN_SP_NONDSP 0x800
  53. #endif //IE5_SPACING
  54. class CTriEditUIHandler;
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CTriEditDocument
  57. class ATL_NO_VTABLE CTriEditDocument :
  58. public CComObjectRootEx<CComSingleThreadModel>,
  59. public CComCoClass<CTriEditDocument, &CLSID_TriEditDocument>,
  60. public IDispatchImpl<ITriEditDocument, &IID_ITriEditDocument, &LIBID_TRIEDITLib>,
  61. public IOleObject,
  62. public IOleCommandTarget,
  63. public IDropTarget,
  64. public ITriEditExtendedAccess
  65. #ifdef IE5_SPACING
  66. ,
  67. public IPersistStreamInit,
  68. public IPersistStream
  69. #endif //IE5_SPACING
  70. {
  71. public:
  72. // IOleObject
  73. STDMETHOD(SetClientSite)(IOleClientSite *pClientSite);
  74. STDMETHOD(GetClientSite)(IOleClientSite **ppClientSite);
  75. STDMETHOD(SetHostNames)(LPCOLESTR /* szContainerApp */, LPCOLESTR /* szContainerObj */);
  76. STDMETHOD(Close)(DWORD dwSaveOption);
  77. STDMETHOD(SetMoniker)(DWORD /* dwWhichMoniker */, IMoniker* /* pmk */);
  78. STDMETHOD(GetMoniker)(DWORD /* dwAssign */, DWORD /* dwWhichMoniker */, IMoniker** /* ppmk */);
  79. STDMETHOD(InitFromData)(IDataObject* /* pDataObject */, BOOL /* fCreation */, DWORD /* dwReserved */);
  80. STDMETHOD(GetClipboardData)(DWORD /* dwReserved */, IDataObject** /* ppDataObject */);
  81. STDMETHOD(DoVerb)(LONG iVerb, LPMSG /* lpmsg */, IOleClientSite* /* pActiveSite */, LONG /* lindex */, HWND hwndParent, LPCRECT lprcPosRect);
  82. STDMETHOD(EnumVerbs)(IEnumOLEVERB **ppEnumOleVerb);
  83. STDMETHOD(Update)(void);
  84. STDMETHOD(IsUpToDate)(void);
  85. STDMETHOD(GetUserClassID)(CLSID *pClsid);
  86. STDMETHOD(GetUserType)(DWORD dwFormOfType, LPOLESTR *pszUserType);
  87. STDMETHOD(SetExtent)(DWORD dwDrawAspect, SIZEL *psizel);
  88. STDMETHOD(GetExtent)(DWORD dwDrawAspect, SIZEL *psizel);
  89. STDMETHOD(Advise)(IAdviseSink *pAdvSink, DWORD *pdwConnection);
  90. STDMETHOD(Unadvise)(DWORD dwConnection);
  91. STDMETHOD(EnumAdvise)(IEnumSTATDATA **ppenumAdvise);
  92. STDMETHOD(GetMiscStatus)(DWORD dwAspect, DWORD *pdwStatus);
  93. STDMETHOD(SetColorScheme)(LOGPALETTE* /* pLogpal */);
  94. // IOleCommandTarget
  95. STDMETHOD(QueryStatus)(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText);
  96. STDMETHOD(Exec)(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt, VARIANTARG *pvaIn, VARIANTARG *pvaOut);
  97. // IDropTarget
  98. STDMETHOD(DragEnter)(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  99. STDMETHOD(DragOver)(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  100. STDMETHOD(DragLeave)(void);
  101. STDMETHOD(Drop)(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  102. #ifdef IE5_SPACING
  103. // IPersistStreamInit, IPersistStream
  104. //
  105. STDMETHOD(IsDirty)();
  106. STDMETHOD(Load)(LPSTREAM pStm);
  107. STDMETHOD(Save)(LPSTREAM pStm, BOOL fClearDirty);
  108. STDMETHOD(GetSizeMax)(ULARGE_INTEGER * pcbSize);
  109. STDMETHOD(InitNew)();
  110. STDMETHOD(GetClassID)(CLSID *pClassID);
  111. #endif //IE5_SPACING
  112. // ITriEditDocument
  113. STDMETHOD(FilterIn)(IUnknown *pUnkOld, IUnknown **ppUnkNew, DWORD dwFlags, BSTR bstrBaseURL);
  114. STDMETHOD(FilterOut)(IUnknown *pUnkOld, IUnknown **ppUnkNew, DWORD dwFlags, BSTR bstrBaseURL);
  115. // ITriEditExtendedAccess
  116. STDMETHOD(GetCharsetFromStream)(IStream* piStream, BSTR* pbstrCodePage);
  117. DECLARE_GET_CONTROLLING_UNKNOWN()
  118. // ATL helper functions override
  119. DECLARE_PROTECT_FINAL_CONSTRUCT()
  120. HRESULT FinalConstruct(); // for aggregation
  121. void FinalRelease(); // for aggregation
  122. #ifdef IE5_SPACING
  123. // methods for mapping unique IDs and designtimesp's
  124. void MapUniqueID(BOOL fGet);
  125. void FillUniqueID(BSTR bstrUniqueID, BSTR bstrDspVal, int ichNonDSP, MAPSTRUCT *pMap, int iMapCur, BOOL fLowerCase, int iType);
  126. BOOL FGetSavedDSP(BSTR bstrUniqueID, BSTR *pbstrDspVal, int *pichNonDSP, MAPSTRUCT *pMap, BOOL *pfLowerCase, int *pIndex);
  127. BOOL FIsFilterInDone() {return(m_fFilterInDone);}
  128. void SetFilterInDone(BOOL fSet) {m_fFilterInDone = fSet;}
  129. void FillNonDSPData(BSTR pOuterTag);
  130. void SetinnerHTMLComment(IHTMLCommentElement *pCommentElement, IHTMLElement *pElement, BSTR pOuterTag);
  131. void ReSetinnerHTMLComment(IHTMLCommentElement *pCommentElement, IHTMLElement *pElement, int ichspNonDSP);
  132. void RemoveEPComment(IHTMLObjectElement *pObjectElement, BSTR bstrAlt, int cch, BSTR *pbstrAltComment, BSTR *pbstrAltNew);
  133. HRESULT SetObjectComment(IHTMLObjectElement *pObjectElement, BSTR bstrAltNew);
  134. void AppendEPComment(IHTMLObjectElement *pObjectElement, int ichspNonDSP);
  135. #endif //IE5_SPACING
  136. protected:
  137. // Trident interface pointers
  138. IUnknown *m_pUnkTrident;
  139. IOleObject *m_pOleObjTrident;
  140. IOleCommandTarget *m_pCmdTgtTrident;
  141. IDropTarget *m_pDropTgtTrident;
  142. #ifdef IE5_SPACING
  143. IPersistStreamInit *m_pTridentPersistStreamInit;
  144. #endif //IE5_SPACING
  145. // Host interface pointers
  146. IOleClientSite *m_pClientSiteHost;
  147. IDocHostUIHandler *m_pUIHandlerHost;
  148. IDocHostDragDropHandler *m_pDragDropHandlerHost;
  149. // Pointer to our UI handler sub-object
  150. CTriEditUIHandler *m_pUIHandler;
  151. // General hosting related data
  152. BOOL m_fUIHandlerSet;
  153. BOOL m_fInContextMenu;
  154. // 2D editing data
  155. IHTMLElement* m_pihtmlElement;
  156. IHTMLStyle* m_pihtmlStyle;
  157. RECT m_rcElement;
  158. RECT m_rcElementOrig;
  159. RECT m_rcElementParent;
  160. BOOL m_fConstrain;
  161. ENUMCONSTRAINDIRECTION m_eDirection;
  162. HWND m_hwndTrident;
  163. HBRUSH m_hbrDragRect;
  164. BOOL m_fDragRectVisible;
  165. RECT m_rcDragRect;
  166. POINT m_ptClickOrig;
  167. POINT m_ptClickLast;
  168. POINT m_ptConstrain;
  169. POINT m_ptScroll;
  170. POINT m_ptAlign;
  171. BOOL m_fLocked;
  172. //for 2D drop mode.
  173. BOOL m_f2dDropMode;
  174. #ifdef IE5_SPACING
  175. CTridentEventSink *m_pTridentEventSink;
  176. IHTMLDocument2 *m_pHTMLDocument2;
  177. MAPSTRUCT *m_pMapArray;
  178. HGLOBAL m_hgMap;
  179. int m_cMapMax;
  180. int m_iMapCur;
  181. WCHAR *m_pspNonDSP;
  182. HGLOBAL m_hgSpacingNonDSP;
  183. int m_ichspNonDSPMax;
  184. int m_ichspNonDSP;
  185. #endif //IE5_SPACING
  186. private:
  187. // Filtering related members
  188. ITokenGen *m_pTokenizer;
  189. HGLOBAL m_hgDocRestore;
  190. HRESULT DoFilter(HGLOBAL hOld, HGLOBAL *phNew, IStream *pStmNew, DWORD dwFlags, FilterMode mode, int cbSizeIn, UINT* pcbSizeOut, BSTR bstrBaseURL);
  191. //Stubs for IOleCommandTarget commands
  192. HRESULT Is2DElement(IHTMLElement* pihtmlElement, BOOL* pf2D);
  193. HRESULT NudgeElement(IHTMLElement* pihtmlElement, LPPOINT ptNudge);
  194. HRESULT SetAlignment(LPPOINT pptAlign);
  195. HRESULT LockElement(IHTMLElement* pihtmlElement, BOOL fLock);
  196. HRESULT Make1DElement(IHTMLElement* pihtmlElement);
  197. HRESULT Make2DElement(IHTMLElement* pihtmlElement, POINT *ppt = NULL);
  198. HRESULT Constrain(BOOL fConstrain);
  199. HRESULT DoVerb(VARIANTARG *pvarargIn, BOOL fQueryStatus);
  200. //Z-Ordering related functions
  201. static int _cdecl CompareProc(const void* arg1, const void* arg2);
  202. HRESULT GetZIndex(IHTMLElement* pihtmlElement, LONG* plZindex);
  203. HRESULT SetZIndex(IHTMLElement* pihtmlElement, LONG lZindex);
  204. HRESULT AssignZIndex(IHTMLElement *pihtmlElement, int nZIndexMode);
  205. HRESULT PropagateZIndex(CZOrder* pczOrder, LONG lZIndex, BOOL fZindexNegative = FALSE);
  206. BOOL IsEqualZIndex(CZOrder* pczOrder,LONG lIndex);
  207. // table editing
  208. HRESULT IsSelectionInTable(IDispatch **ppTable=NULL);
  209. HRESULT FillInSelectionCellsInfo(struct SELCELLINFO * pselStart, struct SELCELLINFO *pselEnd);
  210. ULONG GetSelectionTypeInTable(void);
  211. HRESULT CopyStyle(IDispatch *pFrom, IDispatch *pTo);
  212. HRESULT CopyProperty(IDispatch *pFrom, IDispatch *pTo);
  213. HRESULT DeleteTableRows(void);
  214. HRESULT InsertTableRow(void);
  215. HRESULT DeleteTableCols(void);
  216. HRESULT InsertTableCol(void);
  217. HRESULT InsertTableCell(void);
  218. HRESULT DeleteTableCells(void);
  219. HRESULT MergeTableCells(void);
  220. HRESULT SplitTableCell(void);
  221. HRESULT SplitTableCell(IDispatch *srpTable, INT iRow, INT index);
  222. HRESULT MergeTableCells(IDispatch* srpTable, INT iRow, INT iIndexStart, INT iIndexEnd);
  223. HRESULT InsertTable(VARIANTARG *pvarargIn=NULL);
  224. HRESULT MapCellToFirstRowCell(IDispatch *srpTable, struct SELCELLINFO *pselinfo);
  225. HRESULT GetTableRowElementAndTableFromCell(IDispatch *srpCell, LONG *pindexRow = NULL, IDispatch **srpRow=NULL,IDispatch **srpTable=NULL);
  226. BOOL FEnableInsertTable(void);
  227. HRESULT DeleteTable(IHTMLElement *pTable);
  228. inline HRESULT DeleteRowEx(IHTMLElement *pTable, LONG index);
  229. inline HRESULT DeleteCellEx(IHTMLElement *pTable, IDispatch *pRow, LONG indexRow, LONG indexCell);
  230. //Helpers
  231. void SetUpDefaults(void);
  232. void SetUpGlyphTable(BOOL);
  233. HRESULT MapTriEditCommand(ULONG cmdTriEdit, ULONG *pcmdTrident);
  234. void Draw2DDragRect(BOOL fDraw);
  235. HRESULT GetElement(BOOL fDragDrop = FALSE);
  236. void ReleaseElement(void);
  237. HRESULT GetScrollPosition(void);
  238. HRESULT DragScroll(POINT pt);
  239. HRESULT CalculateNewDropPosition(POINT *pt);
  240. BOOL IsDragSource(void);
  241. BOOL IsDesignMode(void);
  242. HRESULT IsLocked(IHTMLElement* pihtmlElement, BOOL* pfLocked);
  243. HRESULT ConstrainXY(LPPOINT lppt);
  244. HRESULT SnapToGrid(LPPOINT lppt);
  245. HRESULT GetElementPosition(IHTMLElement* pihtmlElement, LPRECT prc);
  246. STDMETHOD (GetDocument)(IHTMLDocument2** ppihtmlDoc2);
  247. STDMETHOD (GetAllCollection)(IHTMLElementCollection** ppihtmlCollection);
  248. STDMETHOD (GetCollectionElement)(IHTMLElementCollection* ppihtmlCollection,
  249. LONG iIndex,
  250. IHTMLElement** ppihtmlElem);
  251. STDMETHOD (Is2DCapable)(IHTMLElement* pihtmlElement, BOOL* pfBool);
  252. STDMETHOD (GetTridentWindow)();
  253. STDMETHOD (SelectElement)(IHTMLElement* pihtmlElement, IHTMLElement* pihtmlElementParent);
  254. HRESULT IsElementDTC(IHTMLElement *pihtmlElement);
  255. HRESULT GetCharset(HGLOBAL hgUHTML, int cbSizeIn, BSTR* pbstrCharset);
  256. #ifdef IE5_SPACING
  257. BOOL m_fFilterInDone;
  258. #endif //IE5_SPACING
  259. // utility inlines
  260. inline BOOL IsIE5OrBetterInstalled()
  261. {
  262. BOOL fIsIE5AndBeyond = FALSE;
  263. CComPtr<IHTMLDocument3> pHTMLDoc3 = NULL;
  264. // check if we have IE5 or better installed
  265. if ( m_pUnkTrident != NULL
  266. && S_OK == m_pUnkTrident->QueryInterface(IID_IHTMLDocument3, (void **) &pHTMLDoc3)
  267. && pHTMLDoc3 != NULL
  268. )
  269. {
  270. fIsIE5AndBeyond = TRUE;
  271. }
  272. return(fIsIE5AndBeyond);
  273. }
  274. public:
  275. CTriEditDocument();
  276. DECLARE_AGGREGATABLE(CTriEditDocument)
  277. DECLARE_REGISTRY_RESOURCEID(IDR_TRIEDITDOCUMENT)
  278. BEGIN_COM_MAP(CTriEditDocument)
  279. COM_INTERFACE_ENTRY(ITriEditDocument)
  280. COM_INTERFACE_ENTRY(IOleObject)
  281. COM_INTERFACE_ENTRY(IOleCommandTarget)
  282. COM_INTERFACE_ENTRY(IDropTarget)
  283. COM_INTERFACE_ENTRY(ITriEditExtendedAccess)
  284. #ifdef IE5_SPACING
  285. COM_INTERFACE_ENTRY(IPersistStreamInit)
  286. COM_INTERFACE_ENTRY(IPersistStream)
  287. #endif //IE5_SPACING
  288. COM_INTERFACE_ENTRY_AGGREGATE_BLIND(m_pUnkTrident)
  289. END_COM_MAP()
  290. friend class CTriEditUIHandler;
  291. };
  292. class CTriEditUIHandler : public IDocHostUIHandler
  293. {
  294. public:
  295. ULONG m_cRef;
  296. CTriEditDocument *m_pDoc;
  297. CTriEditUIHandler(CTriEditDocument *pDoc) { m_cRef = 1; m_pDoc = pDoc; }
  298. ~CTriEditUIHandler(void) {}
  299. // IUnknown
  300. STDMETHODIMP QueryInterface(REFIID, void **);
  301. STDMETHODIMP_(ULONG) AddRef(void);
  302. STDMETHODIMP_(ULONG) Release(void);
  303. // IDocHostUIHandler
  304. STDMETHOD(GetHostInfo)(DOCHOSTUIINFO* pInfo);
  305. STDMETHOD(ShowUI)(DWORD dwID, IOleInPlaceActiveObject* pActiveObject,
  306. IOleCommandTarget* pCommandTarget, IOleInPlaceFrame* pFrame,
  307. IOleInPlaceUIWindow* pDoc);
  308. STDMETHOD(HideUI)();
  309. STDMETHOD(UpdateUI)();
  310. STDMETHOD(EnableModeless)(BOOL fEnable);
  311. STDMETHOD(OnDocWindowActivate)(BOOL fActivate);
  312. STDMETHOD(OnFrameWindowActivate)(BOOL fActivate);
  313. STDMETHOD(ResizeBorder)(LPCRECT prcBorder, IOleInPlaceUIWindow* pUIWindow, BOOL fFrameWindow);
  314. STDMETHOD(ShowContextMenu)(DWORD dwID, POINT* pptPosition, IUnknown* pCommandTarget,
  315. IDispatch* pDispatchObjectHit);
  316. STDMETHOD(TranslateAccelerator)(LPMSG lpMsg, const GUID __RPC_FAR *pguidCmdGroup, DWORD nCmdID);
  317. STDMETHOD(GetOptionKeyPath)(LPOLESTR* pbstrKey, DWORD dw);
  318. STDMETHOD(GetDropTarget)(IDropTarget __RPC_FAR *pDropTarget,
  319. IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget);
  320. STDMETHOD(GetExternal)(IDispatch **ppDispatch);
  321. STDMETHOD(TranslateUrl)(DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut);
  322. STDMETHOD(FilterDataObject)(IDataObject *pDO, IDataObject **ppDORet);
  323. };
  324. #ifdef IE5_SPACING
  325. /////////////////////////////////////////////////////////////////////
  326. //
  327. class ATL_NO_VTABLE CBaseTridentEventSink :
  328. public CComObjectRootEx<CComSingleThreadModel>,
  329. public IDispatch
  330. {
  331. public:
  332. BEGIN_COM_MAP(CBaseTridentEventSink)
  333. COM_INTERFACE_ENTRY(IDispatch)
  334. END_COM_MAP()
  335. public:
  336. // IDispatch
  337. STDMETHOD(GetTypeInfoCount)(UINT *)
  338. { return E_NOTIMPL;}
  339. STDMETHOD(GetTypeInfo)(UINT, LCID, ITypeInfo **)
  340. { return E_NOTIMPL;}
  341. STDMETHOD(GetIDsOfNames)(REFIID, OLECHAR**, UINT, LCID, DISPID*)
  342. { return E_NOTIMPL;}
  343. STDMETHOD(Invoke)(DISPID, REFIID, LCID, USHORT, DISPPARAMS*, VARIANT*, EXCEPINFO*, UINT*)
  344. { return S_OK; }
  345. public:
  346. HRESULT Advise(IUnknown* pUnkSource, REFIID riidEventInterface);
  347. void Unadvise(void);
  348. CBaseTridentEventSink()
  349. {
  350. m_dwCookie = 0;
  351. m_pUnkSource = NULL;
  352. ::ZeroMemory(&m_iidEventInterface, sizeof(m_iidEventInterface));
  353. }
  354. protected:
  355. DWORD m_dwCookie;
  356. IUnknown* m_pUnkSource;
  357. GUID m_iidEventInterface;
  358. public:
  359. IHTMLDocument2* m_pHTMLDocument2;
  360. CTriEditDocument* m_pTriEditDocument;
  361. };
  362. class CTridentEventSink: public CBaseTridentEventSink
  363. {
  364. public:
  365. // IDispatch
  366. STDMETHOD(Invoke)(DISPID dispid, REFIID, LCID, USHORT, DISPPARAMS*, VARIANT*, EXCEPINFO*, UINT*);
  367. };
  368. #endif //IE5_SPACING
  369. #endif //__DOCUMENT_H_