Source code of Windows XP (NT5)
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.

1713 lines
53 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // File: o2base.hxx
  4. //
  5. // Contents: Compound Document Object helper library definitions
  6. //
  7. // Classes:
  8. // OLEBorder
  9. // InPlaceBorder
  10. // StdClassFactory
  11. // ViewAdviseHolder
  12. //
  13. // ---
  14. //
  15. // Functions:
  16. // HimetricFromHPix
  17. // HimetricFromVPix
  18. // HPixFromHimetric
  19. // VPixFromHimetric
  20. //
  21. // WatchInterface
  22. //
  23. // OleAllocMem
  24. // OleFreeMem
  25. // OleAllocString
  26. // OleFreeString
  27. //
  28. // IsCompatibleOleVersion
  29. // IsDraggingDistance
  30. //
  31. // TraceIID
  32. // TraceHRESULT
  33. //
  34. // RECTtoRECTL
  35. // RECTLtoRECT
  36. // ProportionateRectl
  37. // RectToScreen
  38. // RectToClient
  39. // IsRectInRect
  40. // lMulDiv
  41. //
  42. // LeadResourceData
  43. // GetChildWindowRect
  44. // SizeClientRect
  45. //
  46. // RegisterOleClipFormats
  47. // IsCompatibleDevice
  48. // IsCompatibleFormat
  49. // FindCompatibleFormat
  50. // GetObjectDescriptor
  51. // UpdateObjectDescriptor
  52. // DrawMetafile
  53. //
  54. // InsertServerMenus
  55. // RemoteServerMenus
  56. //
  57. // RegisterAsRunning
  58. // RevokeAsRunning
  59. //
  60. // CreateStreamOnFile
  61. //
  62. // CreateOLEVERBEnum
  63. // CreateFORMATETCEnum
  64. // CreateStaticEnum
  65. //
  66. // GetMonikerDisplayName
  67. // CreateStorageOnHGlobal
  68. // ConvertToMemoryStream
  69. // StmReadString
  70. // StmWriteString
  71. //
  72. // CreateViewAdviseHolder
  73. //
  74. // ---
  75. //
  76. // Macros: WATCHINTERFACE
  77. // IsSameIID
  78. //
  79. // TaskAllocMem
  80. // TaskFreeMem
  81. // TaskAllocString
  82. // TaskFreeString
  83. //
  84. // OK
  85. // NOTOK
  86. //
  87. // DECLARE_IUNKNOWN_METHODS
  88. // DECLARE_PURE_IUNKNOWN_METHODS
  89. // DECLARE_STANDARD_IUNKNOWN
  90. // IMPLEMENT_STANDARD_IUNKNOWN
  91. // DECLARE_DELEGATING_IUNKNOWN
  92. // IMPLEMENT_DELEGATING_IUNKNOWN
  93. // DECLARE_PRIVATE_IUNKNOWN
  94. // IMPLEMENT_PRIVATE_IUNKNOWN
  95. //
  96. // DECLARE_CODE_TIMER
  97. // IMPLEMENT_CODE_TIMER
  98. // START_CODE_TIMER
  99. // STOP_CODE_TIMER
  100. //
  101. // Enums:
  102. // OLE_SERVER_STATE
  103. //
  104. // OBPARTS
  105. // OLECLIPFORMAT
  106. //
  107. // ---
  108. //
  109. //----------------------------------------------------------------------------
  110. #ifndef _O2BASE_HXX_
  111. #define _O2BASE_HXX_
  112. // resource ID offsets for class descriptor information
  113. #define IDOFF_CLASSID 1 // was 0
  114. #define IDOFF_USERTYPEFULL 2 // was 1
  115. #define IDOFF_USERTYPESHORT 3 // was 2
  116. #define IDOFF_USERTYPEAPP 4 // was 3
  117. #define IDOFF_DOCFEXT 5 // was 5
  118. #define IDOFF_ICON 10 // was 10
  119. #define IDOFF_ACCELS 11 // was 11
  120. #define IDOFF_MENU 12 // was 12
  121. #define IDOFF_MGW 13 // was 13
  122. #define IDOFF_MISCSTATUS 14 // was 14
  123. #ifndef RC_INVOKED // the resource compiler is not interested in the rest
  124. #if DBG
  125. extern "C" void FAR PASCAL AssertSFL(
  126. LPSTR lpszClause,
  127. LPSTR lpszFileName,
  128. int nLine);
  129. #define Assert(f) ((f)? (void)0 : AssertSFL(#f, __FILE__, __LINE__))
  130. #else // !DBG
  131. #define Assert(x)
  132. #endif // DBG
  133. //+---------------------------------------------------------------------
  134. //
  135. // Windows helper functions
  136. //
  137. //----------------------------------------------------------------------
  138. LPVOID LoadResourceData(HINSTANCE hinst,
  139. LPCTSTR lpstrId,
  140. LPVOID lpvBuf,
  141. int cbBuf);
  142. void GetChildWindowRect(HWND hwndChild, LPRECT lprect);
  143. void SizeClientRect(HWND hwnd, RECT& rc, BOOL fMove);
  144. //+---------------------------------------------------------------------
  145. //
  146. // Generally useful #defines and inline functions for OLE2.
  147. //
  148. //------------------------------------------------------------------------
  149. // this macro can be used to put string constants in a read-only code segment
  150. // usage: char CODE_BASED szFoo[] = "Bar";
  151. #define CODE_BASED __based(__segname("_CODE"))
  152. // These are the major and minor version returned by OleBuildVersion
  153. #define OLE_MAJ_VER 0x0003
  154. #define OLE_MIN_VER 0x003A
  155. //---------------------------------------------------------------
  156. // SCODE and HRESULT macros
  157. //---------------------------------------------------------------
  158. #define OK(r) (SUCCEEDED(r))
  159. #define NOTOK(r) (FAILED(r))
  160. //---------------------------------------------------------------
  161. // GUIDs, CLSIDs, IIDs
  162. //---------------------------------------------------------------
  163. #define IsSameIID(iid1, iid2) ((iid1)==(iid2))
  164. //---------------------------------------------------------------
  165. // IUnknown
  166. //---------------------------------------------------------------
  167. //
  168. // This declares the set of IUnknown methods and is for general-purpose
  169. // use inside classes that inherit from IUnknown
  170. #define DECLARE_IUNKNOWN_METHODS \
  171. STDMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj); \
  172. STDMETHOD_(ULONG,AddRef) (void); \
  173. STDMETHOD_(ULONG,Release) (void)
  174. //
  175. // This declares the set of IUnknown methods as pure virtual methods
  176. //
  177. #define DECLARE_PURE_IUNKNOWN_METHODS \
  178. STDMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj) = 0; \
  179. STDMETHOD_(ULONG,AddRef) (void) = 0; \
  180. STDMETHOD_(ULONG,Release) (void) = 0
  181. //
  182. // This is for use in declaring non-aggregatable objects. It declares the
  183. // IUnknown methods and reference counter, _ulRefs.
  184. // _ulRefs should be initialized to 1 in the constructor of the object
  185. #define DECLARE_STANDARD_IUNKNOWN(cls) \
  186. DECLARE_IUNKNOWN_METHODS; \
  187. ULONG _ulRefs
  188. // note: this does NOT implement QueryInterface, which must be
  189. // implemented by each object
  190. #define IMPLEMENT_STANDARD_IUNKNOWN(cls) \
  191. STDMETHODIMP_(ULONG) cls##::AddRef(void) \
  192. { ++_ulRefs; \
  193. return _ulRefs;} \
  194. STDMETHODIMP_(ULONG) cls##::Release(void) \
  195. { ULONG ulRet = --_ulRefs; \
  196. if (ulRet == 0) delete this; \
  197. return ulRet; }
  198. // This is for use in declaring aggregatable objects. It declares the IUnknown
  199. // methods and a member pointer to the aggregate controlling unknown, _pUnkOuter,
  200. // that all IUnknowns delegate to except the controlling unknown of the object
  201. // itself.
  202. // _pUnkOuter must be initialized to point to either an external controlling
  203. // unknown or the object's own controlling unknown, depending on whether the
  204. // object is being created as part of an aggregate or not.
  205. #define DECLARE_DELEGATING_IUNKNOWN(cls) \
  206. DECLARE_IUNKNOWN_METHODS; \
  207. LPUNKNOWN _pUnkOuter
  208. // This, correspondingly, is for use in implementing aggregatable objects.
  209. // It implements the IUnknown methods by trivially delegating to the controlling
  210. // unknown described by _pUnkOuter.
  211. #define IMPLEMENT_DELEGATING_IUNKNOWN(cls) \
  212. STDMETHODIMP cls##::QueryInterface (REFIID riid, LPVOID FAR* ppvObj) \
  213. { return _pUnkOuter->QueryInterface(riid, ppvObj); } \
  214. STDMETHODIMP_(ULONG) cls##::AddRef (void) \
  215. { return _pUnkOuter->AddRef(); } \
  216. STDMETHODIMP_(ULONG) cls##::Release (void) \
  217. { return _pUnkOuter->Release(); }
  218. // This declares a nested class that is the private unknown of the object
  219. #define DECLARE_PRIVATE_IUNKNOWN(cls) \
  220. class PrivateUnknown: public IUnknown { \
  221. public: \
  222. PrivateUnknown(cls* p##cls); \
  223. DECLARE_IUNKNOWN_METHODS; \
  224. private: \
  225. ULONG _ulRefs; \
  226. cls* _p##cls; }; \
  227. friend class PrivateUnknown; \
  228. PrivateUnknown _PrivUnk
  229. //
  230. // note: this does NOT implement QueryInterface, which must be
  231. // implemented by each object
  232. #define IMPLEMENT_PRIVATE_IUNKNOWN(cls) \
  233. cls##::PrivateUnknown::PrivateUnknown(cls* p##cls) \
  234. { _p##cls = p##cls; _ulRefs = 1; } \
  235. STDMETHODIMP_(ULONG) cls##::PrivateUnknown::AddRef(void) \
  236. { ++_ulRefs; \
  237. return _ulRefs; } \
  238. STDMETHODIMP_(ULONG) cls##::PrivateUnknown::Release(void) \
  239. { ULONG ulRet = --_ulRefs; \
  240. if (ulRet == 0) delete _p##cls; \
  241. return ulRet; }
  242. //+---------------------------------------------------------------------
  243. //
  244. // Miscellaneous useful OLE helper and debugging functions
  245. //
  246. //----------------------------------------------------------------------
  247. #if !defined(UNICODE) && !defined(OLE2ANSI)
  248. LPOLESTR ConvertMBToOLESTR(LPCSTR lpStr, int cchStr);
  249. LPTSTR ConvertOLESTRToMB(LPCOLESTR lpStr, int cchStr);
  250. #endif
  251. #if defined(OLE2ANSI)
  252. #define OLETEXT(x) x
  253. #define ostrlen lstrlen
  254. #define ostrcpy lstrcpy
  255. #define ostrcat lstrcat
  256. #else
  257. #define OLETEXT(x) L##x
  258. # if defined(UNICODE)
  259. #define ostrlen lstrlenW
  260. #define ostrcat lstrcatW
  261. #define ostrcpy lstrcpyW
  262. # else
  263. #define ostrlen wcslen
  264. #define ostrcat wcscat
  265. #define ostrcpy wcscpy
  266. # endif
  267. #endif
  268. //
  269. // Some convenient OLE-related definitions and declarations
  270. //
  271. typedef unsigned short far * LPUSHORT;
  272. //REVIEW we are experimenting with a non-standard OLEMISC flag.
  273. #define OLEMISC_STREAMABLE 1024
  274. IsCompatibleOleVersion(WORD wMaj, WORD wMin);
  275. inline BOOL IsDraggingDistance(POINT pt1, POINT pt2)
  276. {
  277. #define MIN_DRAG_DIST 12
  278. return (abs(pt1.x - pt2.x) >= MIN_DRAG_DIST ||
  279. abs(pt1.y - pt2.y) >= MIN_DRAG_DIST);
  280. #undef MIN_DRAG_DIST
  281. }
  282. #if ENABLED_DBG == 1
  283. void TraceIID(REFIID riid);
  284. HRESULT TraceHRESULT(HRESULT r);
  285. #define TRACEIID(iid) TraceIID(iid)
  286. #define TRACEHRESULT(r) TraceHRESULT(r)
  287. #else // DBG == 0
  288. #define TRACEIID(iid)
  289. #define TRACEHRESULT(r)
  290. #endif // DBG
  291. //+---------------------------------------------------------------------
  292. //
  293. // Routines to convert Pixels to Himetric and vice versa
  294. //
  295. //----------------------------------------------------------------------
  296. long HimetricFromHPix(int iPix);
  297. long HimetricFromVPix(int iPix);
  298. int HPixFromHimetric(long lHi);
  299. int VPixFromHimetric(long lHi);
  300. //+---------------------------------------------------------------------
  301. //
  302. // Timing helpers
  303. //
  304. //------------------------------------------------------------------------
  305. #ifdef _TIMING
  306. #define DECLARE_CODE_TIMER(t) extern CTimer t
  307. #define IMPLEMENT_CODE_TIMER(t,s) CTimer t(s)
  308. #define START_CODE_TIMER(t) t.Start()
  309. #define STOP_CODE_TIMER(t) t.Stop()
  310. #else // !_TIMING
  311. #define DECLARE_CODE_TIMER(t)
  312. #define IMPLEMENT_CODE_TIMER(t,s)
  313. #define START_CODE_TIMER(t)
  314. #define STOP_CODE_TIMER(t)
  315. #endif // _TIMING
  316. //+---------------------------------------------------------------------
  317. //
  318. // Rectangle helper functions
  319. //
  320. //----------------------------------------------------------------------
  321. //+---------------------------------------------------------------
  322. //
  323. // Function: RECTtoRECTL
  324. //
  325. // Synopsis: Converts a RECT structure to a RECTL
  326. //
  327. //----------------------------------------------------------------
  328. inline void RECTtoRECTL(RECT& rc, LPRECTL lprcl)
  329. {
  330. lprcl->left = (long)rc.left;
  331. lprcl->top = (long)rc.top;
  332. lprcl->bottom = (long)rc.bottom;
  333. lprcl->right = (long)rc.right;
  334. }
  335. //+---------------------------------------------------------------
  336. //
  337. // Function: RECTLtoRECT
  338. //
  339. // Synopsis: Converts a RECTL structure to a RECT
  340. //
  341. //----------------------------------------------------------------
  342. inline void RECTLtoRECT(RECTL& rcl, LPRECT lprc)
  343. {
  344. lprc->left = (int)rcl.left;
  345. lprc->top = (int)rcl.top;
  346. lprc->bottom = (int)rcl.bottom;
  347. lprc->right = (int)rcl.right;
  348. }
  349. //+---------------------------------------------------------------
  350. //
  351. // Function: RectToScreen
  352. //
  353. // Synopsis: Converts a rectangle in client coordinates of a window
  354. // to screen coordinates.
  355. //
  356. // Arguments: [hwnd] -- the window defining the client coordinate space
  357. // [lprect] -- the rectangle to be converted
  358. //
  359. //----------------------------------------------------------------
  360. inline void RectToScreen(HWND hwnd, LPRECT lprect)
  361. {
  362. POINT ptUL = { lprect->left, lprect->top };
  363. ClientToScreen(hwnd,&ptUL);
  364. POINT ptLR = { lprect->right, lprect->bottom };
  365. ClientToScreen(hwnd,&ptLR);
  366. lprect->left = ptUL.x;
  367. lprect->top = ptUL.y;
  368. lprect->right = ptLR.x;
  369. lprect->bottom = ptLR.y;
  370. }
  371. //+---------------------------------------------------------------
  372. //
  373. // Function: RectToClient
  374. //
  375. // Synopsis: Converts a rectangle in screen coordinates to client
  376. // coordinates of a window.
  377. //
  378. // Arguments: [hwnd] -- the window defining the client coordinate space
  379. // [lprect] -- the rectangle to be converted
  380. //
  381. //----------------------------------------------------------------
  382. inline void RectToClient(HWND hwnd, LPRECT lprect)
  383. {
  384. POINT ptUL = { lprect->left, lprect->top };
  385. ScreenToClient(hwnd,&ptUL);
  386. POINT ptLR = { lprect->right, lprect->bottom };
  387. ScreenToClient(hwnd,&ptLR);
  388. lprect->left = ptUL.x;
  389. lprect->top = ptUL.y;
  390. lprect->right = ptLR.x;
  391. lprect->bottom = ptLR.y;
  392. }
  393. //+---------------------------------------------------------------
  394. //
  395. // Function: IsRectInRect
  396. //
  397. // Synopsis: Determines whether one rectangle is wholly contained within
  398. // another rectangle.
  399. //
  400. // Arguments: [rcOuter] -- the containing rectangle
  401. // [lprect] -- the contained rectangle
  402. //
  403. //----------------------------------------------------------------
  404. inline BOOL IsRectInRect(RECT& rcOuter, RECT& rcInner)
  405. {
  406. POINT pt1 = { rcInner.left, rcInner.top };
  407. POINT pt2 = { rcInner.right, rcInner.bottom };
  408. return PtInRect(&rcOuter, pt1) && PtInRect(&rcOuter, pt2);
  409. }
  410. //+---------------------------------------------------------------------
  411. //
  412. // IMalloc-related helpers
  413. //
  414. //----------------------------------------------------------------------
  415. //REVIEW: We may want to cache the IMalloc pointer for efficiency
  416. #ifdef WIN16
  417. //
  418. // C++ new/delete replacements that use OLE's allocators
  419. //
  420. void FAR* operator new(size_t size);
  421. void FAR* operator new(size_t size, MEMCTX memctx);
  422. void operator delete(void FAR* lpv);
  423. #endif //WIN16
  424. //
  425. // inline IMalloc memory allocation functions
  426. //
  427. HRESULT OleAllocMem(MEMCTX ctx, ULONG cb, LPVOID FAR* ppv);
  428. void OleFreeMem(MEMCTX ctx, LPVOID pv);
  429. HRESULT OleAllocString(MEMCTX ctx, LPCOLESTR lpstrSrc, LPOLESTR FAR* ppstr);
  430. void OleFreeString(MEMCTX ctx, LPOLESTR lpstr);
  431. #define TaskAllocMem(cb, ppv) OleAllocMem(MEMCTX_TASK, cb, ppv)
  432. #define TaskFreeMem(pv) OleFreeMem(MEMCTX_TASK, pv)
  433. #define TaskAllocString(lpstr, ppstr) OleAllocString(MEMCTX_TASK, lpstr, ppstr)
  434. #define TaskFreeString(lpstr) OleFreeString(MEMCTX_TASK, lpstr)
  435. //+---------------------------------------------------------------------
  436. //
  437. // Border definitions and helper class
  438. //
  439. //------------------------------------------------------------------------
  440. // Default value for border thickness unless over-ridden via SetThickness
  441. #define FBORDER_THICKNESS 4
  442. // Default values for border minimums (customize via SetMinimums)
  443. #define FBORDER_MINHEIGHT (FBORDER_THICKNESS*2 + 8);
  444. #define FBORDER_MINWIDTH (FBORDER_THICKNESS*2 + 8);
  445. #define OBSTYLE_MODMASK 0xff00 /* Mask style modifier bits */
  446. #define OBSTYLE_TYPEMASK 0x00ff /* Mask basic type definition bits */
  447. #define OBSTYLE_RESERVED 0x8000 /* bit reserved for internal use */
  448. #define OBSTYLE_INSIDE 0x4000 /* Inside or Outside rect? */
  449. #define OBSTYLE_HANDLED 0x2000 /* Size Handles Drawn? */
  450. #define OBSTYLE_ACTIVE 0x1000 /* Active Border Shading? */
  451. #define OBSTYLE_XOR 0x0800 /* Draw with XOR? */
  452. #define OBSTYLE_THICK 0x0400 /* double up lines? */
  453. #define OBSTYLE_DIAGONAL_FILL 0x0001 /* Open editing */
  454. #define OBSTYLE_SOLID_PEN 0x0002 /* Simple Outline */
  455. #define FB_HANDLED (OBSTYLE_HANDLED | OBSTYLE_SOLID_PEN)
  456. #define FB_OPEN OBSTYLE_DIAGONAL_FILL
  457. #define FB_OUTLINED OBSTYLE_SOLID_PEN
  458. #define FB_HIDDEN 0
  459. #define MAX_OBPART 13
  460. enum OBPARTS
  461. {
  462. BP_NOWHERE,
  463. BP_TOP, BP_RIGHT, BP_BOTTOM, BP_LEFT,
  464. BP_TOPRIGHT, BP_BOTTOMRIGHT, BP_BOTTOMLEFT, BP_TOPLEFT,
  465. BP_TOPHAND, BP_RIGHTHAND, BP_BOTTOMHAND, BP_LEFTHAND,
  466. BP_INSIDE
  467. };
  468. class OLEBorder
  469. {
  470. public:
  471. OLEBorder(RECT& r);
  472. OLEBorder(void);
  473. ~OLEBorder(void);
  474. void SetMinimums( SHORT sMinHeight, SHORT sMinWidth );
  475. int SetThickness(int sBorderThickness);
  476. int GetThickness(void);
  477. USHORT SetState(HDC hdc, HWND hwnd, USHORT usBorderState);
  478. USHORT GetState(void);
  479. void Draw(HDC hdc, HWND hwnd);
  480. void Erase(HWND hwnd);
  481. USHORT QueryHit(POINT point);
  482. HCURSOR MapPartToCursor(USHORT usPart);
  483. HCURSOR QueryMoveCursor(POINT ptCurrent, BOOL fMustMove);
  484. HCURSOR BeginMove(HDC hdc, HWND hwnd, POINT ptStart, BOOL fMustMove);
  485. RECT& UpdateMove(HDC hdc, HWND hwnd, POINT ptCurrent, BOOL fNewRegion);
  486. RECT& EndMove(HDC hdc, HWND hwnd, POINT ptCurrent, USHORT usBorderState);
  487. void SwitchCoords( HWND hwndFrom, HWND hwndTo );
  488. //
  489. //OLEBorder exposes it's RECT as a public data member
  490. //
  491. RECT rect;
  492. private:
  493. enum ICURS
  494. {
  495. ICURS_STD,
  496. ICURS_NWSE,
  497. ICURS_NESW,
  498. ICURS_NS,
  499. ICURS_WE
  500. };
  501. static BOOL fInit;
  502. static HCURSOR ahc[5];
  503. static int iPartMap[14];
  504. void InitClass(void);
  505. void GetBorderRect(RECT& rDest, int iEdge);
  506. void GetInsideBorder(RECT& rDest, int iEdge);
  507. void GetOutsideBorder(RECT& rDest, int iEdge);
  508. USHORT _state;
  509. int _sMinHeight;
  510. int _sMinWidth;
  511. int _sThickness;
  512. USHORT _usPart; //which portion of border was hit?
  513. POINT _pt; //last known point
  514. BOOL _fErased;
  515. };
  516. inline void OLEBorder::SetMinimums( SHORT sMinHeight, SHORT sMinWidth )
  517. {
  518. _sMinHeight = sMinHeight;
  519. _sMinWidth = sMinWidth;
  520. }
  521. inline int OLEBorder::GetThickness(void)
  522. {
  523. return(_sThickness);
  524. }
  525. inline int OLEBorder::SetThickness(int sBorderThickness)
  526. {
  527. if(sBorderThickness > 0)
  528. {
  529. _sThickness = sBorderThickness;
  530. }
  531. return(_sThickness);
  532. }
  533. inline USHORT OLEBorder::GetState(void)
  534. {
  535. return(_state);
  536. }
  537. //+---------------------------------------------------------------------
  538. //
  539. // Helper functions for implementing IDataObject and IViewObject
  540. //
  541. //----------------------------------------------------------------------
  542. //
  543. // Useful #defines
  544. //
  545. #define DVASPECT_ALL \
  546. DVASPECT_CONTENT|DVASPECT_THUMBNAIL|DVASPECT_ICON|DVASPECT_DOCPRINT
  547. //
  548. // Standard OLE Clipboard formats
  549. //
  550. enum OLECLIPFORMAT
  551. {
  552. OCF_OBJECTLINK,
  553. OCF_OWNERLINK,
  554. OCF_NATIVE,
  555. OCF_FILENAME,
  556. OCF_NETWORKNAME,
  557. OCF_DATAOBJECT,
  558. OCF_EMBEDDEDOBJECT,
  559. OCF_EMBEDSOURCE,
  560. OCF_LINKSOURCE,
  561. OCF_LINKSRCDESCRIPTOR,
  562. OCF_OBJECTDESCRIPTOR,
  563. OCF_OLEDRAW, OCF_LAST = OCF_OLEDRAW
  564. };
  565. extern UINT OleClipFormat[OCF_LAST+1]; // array of OLE standard clipboard formats
  566. // indexed by OLECLIPFORMAT enumeration.
  567. void RegisterOleClipFormats(void); // initializes OleClipFormat table.
  568. //
  569. // FORMATETC helpers
  570. //
  571. #define DVTARGETIGNORE (DVTARGETDEVICE FAR*)(LPVOID)ULongToPtr((DWORD)-1L)
  572. BOOL IsCompatibleDevice(DVTARGETDEVICE FAR* ptdLeft, DVTARGETDEVICE FAR* ptdRight);
  573. BOOL IsCompatibleFormat(FORMATETC& f1, FORMATETC& f2);
  574. int FindCompatibleFormat(FORMATETC FmtTable[], int iSize, FORMATETC& formatetc);
  575. //
  576. // OBJECTDESCRIPTOR clipboard format helpers
  577. //
  578. HRESULT GetObjectDescriptor(LPDATAOBJECT pDataObj, LPOBJECTDESCRIPTOR pDescOut);
  579. HRESULT UpdateObjectDescriptor(LPDATAOBJECT pDataObj, POINTL& ptl, DWORD dwAspect);
  580. //
  581. // Other helper functions
  582. //
  583. HRESULT DrawMetafile(LPVIEWOBJECT pVwObj, RECT& rc, DWORD dwAspect,
  584. HMETAFILE FAR* pHMF);
  585. //+---------------------------------------------------------------------
  586. //
  587. // IStream on top of a DOS (non-docfile) file
  588. //
  589. //----------------------------------------------------------------------
  590. HRESULT CreateStreamOnFile(LPCSTR lpstrFile, DWORD stgm, LPSTREAM FAR* ppstrm);
  591. //+---------------------------------------------------------------------
  592. //
  593. // Class: InPlaceBorder Class (IP)
  594. //
  595. // Synopsis: Helper Class to draw inplace activation borders around an
  596. // object.
  597. //
  598. // Notes: Use of this class limits windows to the use of the
  599. // non-client region for UIAtive borders only: Standard
  600. // (non-control window) scroll bars are specifically NOT
  601. // supported.
  602. //
  603. // History: 14-May-93 CliffG Created.
  604. //
  605. //------------------------------------------------------------------------
  606. #define IPBORDER_THICKNESS 6
  607. class InPlaceBorder
  608. {
  609. public:
  610. InPlaceBorder(void);
  611. ~InPlaceBorder(void);
  612. //
  613. //Substitute for standard windows API: identical signature & semantics
  614. //
  615. LRESULT DefWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  616. //
  617. //Change the server state: reflected in the nonclient window border
  618. //
  619. void SetUIActive(BOOL fUIActive);
  620. BOOL GetUIActive(void);
  621. //
  622. //Force border state to OS_LOADED, managing the cooresponding change
  623. //in border appearance: guaranteed redraw
  624. //
  625. void Erase(void);
  626. void SetBorderSize( int cx, int cy );
  627. void GetBorderSize( LPINT pcx, LPINT pcy );
  628. void Bind(LPOLEINPLACESITE pSite, HWND hwnd, BOOL fUIActive );
  629. void Attach( HWND hwnd, BOOL fUIActive );
  630. void Detach(void);
  631. void SetSize(HWND hwnd, RECT& rc);
  632. void SetParentActive( BOOL fActive );
  633. private:
  634. BOOL _fUIActive; //current state of border
  635. BOOL _fParentActive; //shade as active border?
  636. HWND _hwnd; //attached window (if any)
  637. LPOLEINPLACESITE _pSite; //InPlace site we are bound to
  638. int _cxFrame; //border horizontal thickness
  639. int _cyFrame; //border vertical thickness
  640. int _cResizing; //reentrancy control flag
  641. static WORD _cUsage; //refcount for static resources
  642. static HBRUSH _hbrActiveCaption;
  643. static HBRUSH _hbrInActiveCaption;
  644. void DrawFrame(HWND hwnd);
  645. void CalcClientRect(HWND hwnd, LPRECT lprc);
  646. LONG HitTest(HWND hwnd, int x, int y);
  647. void InvalidateFrame(void);
  648. void RedrawFrame(void);
  649. };
  650. inline void
  651. InPlaceBorder::Detach(void)
  652. {
  653. _pSite = NULL;
  654. _hwnd = NULL;
  655. }
  656. inline void
  657. InPlaceBorder::InvalidateFrame(void)
  658. {
  659. //cause a WM_NCCALCRECT to be generated
  660. if(_hwnd != NULL)
  661. {
  662. ++_cResizing;
  663. SetWindowPos( _hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED |
  664. SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
  665. _cResizing--;
  666. }
  667. }
  668. inline void
  669. InPlaceBorder::RedrawFrame(void)
  670. {
  671. if(_hwnd != NULL)
  672. {
  673. ++_cResizing;
  674. UINT afuRedraw = RDW_INVALIDATE | RDW_UPDATENOW;
  675. RedrawWindow(_hwnd, NULL, NULL, afuRedraw);
  676. _cResizing--;
  677. }
  678. }
  679. inline void
  680. InPlaceBorder::SetParentActive( BOOL fActive )
  681. {
  682. _fParentActive = fActive;
  683. RedrawFrame();
  684. }
  685. inline void
  686. InPlaceBorder::CalcClientRect(HWND hwnd, LPRECT lprc)
  687. {
  688. if(_fUIActive)
  689. InflateRect(lprc, -_cxFrame, -_cyFrame);
  690. }
  691. inline BOOL
  692. InPlaceBorder::GetUIActive(void)
  693. {
  694. return _fUIActive;
  695. }
  696. //+---------------------------------------------------------------------
  697. //
  698. // Helper functions for in-place activation
  699. //
  700. //----------------------------------------------------------------------
  701. HRESULT InsertServerMenus(HMENU hmenuShared, HMENU hmenuObject,
  702. LPOLEMENUGROUPWIDTHS lpmgw);
  703. void RemoveServerMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpmgw);
  704. //---------------------------------------------------------------
  705. // IStorage
  706. //---------------------------------------------------------------
  707. #define STGM_SHARE 0x000000F0
  708. //+---------------------------------------------------------------------
  709. //
  710. // Running Object Table helper functions
  711. //
  712. //----------------------------------------------------------------------
  713. void RegisterAsRunning(LPUNKNOWN lpUnk, LPMONIKER lpmkFull,
  714. DWORD FAR* lpdwRegister);
  715. void RevokeAsRunning(DWORD FAR* lpdwRegister);
  716. //+---------------------------------------------------------------------
  717. //
  718. // Standard implementations of common enumerators
  719. //
  720. //----------------------------------------------------------------------
  721. HRESULT CreateOLEVERBEnum(LPOLEVERB pVerbs, ULONG cVerbs,
  722. LPENUMOLEVERB FAR* ppenum);
  723. HRESULT CreateFORMATETCEnum(LPFORMATETC pFormats, ULONG cFormats,
  724. LPENUMFORMATETC FAR* ppenum);
  725. #if 0 // currently not used but useful in the future.
  726. // we ifdef it out so it doesn't take up space
  727. // in our servers.
  728. HRESULT CreateStaticEnum(REFIID riid, LPVOID pStart, ULONG cSize, ULONG cCount,
  729. LPVOID FAR* ppenum);
  730. #endif //0
  731. //+---------------------------------------------------------------------
  732. //
  733. // Standard IClassFactory implementation
  734. //
  735. //----------------------------------------------------------------------
  736. //+---------------------------------------------------------------
  737. //
  738. // Class: StdClassFactory
  739. //
  740. // Purpose: Standard implementation of a class factory object
  741. //
  742. // Notes: *
  743. //
  744. //---------------------------------------------------------------
  745. class StdClassFactory: public IClassFactory
  746. {
  747. public:
  748. StdClassFactory(void);
  749. DECLARE_IUNKNOWN_METHODS;
  750. STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter,
  751. REFIID iid,
  752. LPVOID FAR* ppv) PURE;
  753. STDMETHOD(LockServer) (BOOL fLock);
  754. BOOL CanUnload(void);
  755. private:
  756. ULONG _ulRefs;
  757. ULONG _ulLocks;
  758. };
  759. //+---------------------------------------------------------------------
  760. //
  761. // IStorage and IStream Helper functions
  762. //
  763. //----------------------------------------------------------------------
  764. #define STGM_DFRALL (STGM_READWRITE|STGM_TRANSACTED|STGM_SHARE_DENY_WRITE)
  765. #define STGM_DFALL (STGM_READWRITE | STGM_TRANSACTED | STGM_SHARE_EXCLUSIVE)
  766. #define STGM_SALL (STGM_READWRITE | STGM_SHARE_EXCLUSIVE)
  767. #define STGM_SRO (STGM_READ | STGM_SHARE_EXCLUSIVE)
  768. HRESULT GetMonikerDisplayName(LPMONIKER pmk, LPOLESTR FAR* ppstr);
  769. HRESULT CreateStorageOnHGlobal(HGLOBAL hgbl, LPSTORAGE FAR* ppStg);
  770. LPSTREAM ConvertToMemoryStream(LPSTREAM pStrmFrom);
  771. //+---------------------------------------------------------------
  772. //
  773. // Function: StmReadString
  774. //
  775. // Synopsis: Reads a string from a stream
  776. //
  777. // Arguments: [pStrm] -- the stream to read from
  778. // [ppstr] -- where the string read is returned
  779. //
  780. // Returns: Success if the string was read successfully
  781. //
  782. // Notes: The string is allocated with the task allocator
  783. // and needs to be freed by the same.
  784. // This is an inline function.
  785. //
  786. //----------------------------------------------------------------
  787. inline HRESULT StmReadString(LPSTREAM pStrm, LPSTR FAR *ppstr)
  788. {
  789. HRESULT r;
  790. USHORT cb;
  791. LPSTR lpstr = NULL;
  792. if (OK(r = pStrm->Read(&cb, sizeof(cb), NULL)))
  793. {
  794. if (OK(r = TaskAllocMem(cb+1, (LPVOID FAR*)&lpstr)))
  795. {
  796. r = pStrm->Read(lpstr, cb, NULL);
  797. *(lpstr+cb) = '\0';
  798. }
  799. }
  800. *ppstr = lpstr;
  801. return r;
  802. }
  803. //+---------------------------------------------------------------
  804. //
  805. // Function: StmWriteString
  806. //
  807. // Synopsis: Writes a string to a stream
  808. //
  809. // Arguments: [pStrm] -- the stream to write to
  810. // [lpstr] -- the string to write
  811. //
  812. // Returns: Success iff the string was written successfully
  813. //
  814. // Notes: This is an inline function.
  815. //
  816. //----------------------------------------------------------------
  817. inline HRESULT StmWriteString(LPSTREAM pStrm, LPSTR lpstr)
  818. {
  819. HRESULT r;
  820. USHORT cb = strlen(lpstr);
  821. if (OK(r = pStrm->Write(&cb, sizeof(cb), NULL)))
  822. r = pStrm->Write(lpstr, cb, NULL);
  823. return r;
  824. }
  825. //+---------------------------------------------------------------------
  826. //
  827. // View advise holder
  828. //
  829. //----------------------------------------------------------------------
  830. //
  831. // forward declaration
  832. //
  833. class ViewAdviseHolder;
  834. typedef ViewAdviseHolder FAR* LPVIEWADVISEHOLDER;
  835. //+---------------------------------------------------------------
  836. //
  837. // Class: ViewAdviseHolder
  838. //
  839. // Purpose: Manages the view advises on behalf of a IViewObject object
  840. //
  841. // Notes: This is analogous to the standard DataAdviseHolder provided
  842. // by OLE. c.f. CreateViewAdviseHolder.
  843. //
  844. //---------------------------------------------------------------
  845. class ViewAdviseHolder: public IUnknown
  846. {
  847. friend HRESULT CreateViewAdviseHolder(LPVIEWADVISEHOLDER FAR*);
  848. public:
  849. //*** IUnknown methods ***/
  850. STDMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj);
  851. STDMETHOD_(ULONG,AddRef) (void);
  852. STDMETHOD_(ULONG,Release) (void);
  853. //*** ViewAdviseHolder methods
  854. STDMETHOD(SetAdvise) (DWORD aspects, DWORD advf, LPADVISESINK pAdvSink);
  855. STDMETHOD(GetAdvise) (DWORD FAR* pAspects, DWORD FAR* pAdvf,
  856. LPADVISESINK FAR* ppAdvSink);
  857. void SendOnViewChange(DWORD dwAspect);
  858. private:
  859. ViewAdviseHolder();
  860. ~ViewAdviseHolder();
  861. ULONG _refs;
  862. LPADVISESINK _pAdvSink; // THE view advise sink
  863. DWORD _dwAdviseAspects; // view aspects of interest to advise sink
  864. DWORD _dwAdviseFlags; // view advise flags
  865. };
  866. HRESULT CreateViewAdviseHolder(LPVIEWADVISEHOLDER FAR* ppViewHolder);
  867. //+------------------------------------------------------------------------
  868. //
  869. // Macro that calculates the number of elements in a statically-defined
  870. // array.
  871. //
  872. //-------------------------------------------------------------------------
  873. #define ARRAY_SIZE(_a) (sizeof(_a) / sizeof(_a[0]))
  874. //======================================================================
  875. //
  876. // The base class stuff...
  877. //
  878. //
  879. // Classes: ClassDescriptor
  880. // SrvrCtrl
  881. // SrvrDV
  882. // SrvrInPlace
  883. //
  884. //----------------------------------------------------------------------------
  885. enum OLE_SERVER_STATE
  886. {
  887. OS_PASSIVE,
  888. OS_LOADED, // handler but no server
  889. OS_RUNNING, // server running, invisible
  890. OS_INPLACE, // server running, inplace-active, no U.I.
  891. OS_UIACTIVE, // server running, inplace-active, w/ U.I.
  892. OS_OPEN // server running, open-edited
  893. };
  894. // forward declarations of classes
  895. class ClassDescriptor;
  896. typedef ClassDescriptor FAR* LPCLASSDESCRIPTOR;
  897. class SrvrCtrl;
  898. typedef SrvrCtrl FAR* LPSRVRCTRL;
  899. class SrvrDV;
  900. typedef SrvrDV FAR* LPSRVRDV;
  901. class SrvrInPlace;
  902. typedef SrvrInPlace FAR* LPSRVRINPLACE;
  903. //+---------------------------------------------------------------
  904. //
  905. // Class: ClassDescriptor
  906. //
  907. // Purpose: Global, static information about a server class
  908. //
  909. // Notes: This allows the base classes to implement a lot of
  910. // OLE functionality with requiring additional virtual
  911. // method calls on the derived classes.
  912. //
  913. //---------------------------------------------------------------
  914. class ClassDescriptor
  915. {
  916. public:
  917. ClassDescriptor(void);
  918. BOOL Init(HINSTANCE hinst, WORD wBaseID);
  919. HMENU LoadMenu(void);
  920. HINSTANCE _hinst; // instance handle of module serving this class
  921. WORD _wBaseResID; // base resource identifier (see IDOFF_ )
  922. CLSID _clsid; // class's unique identifier
  923. HICON _hicon; // iconic representation of class
  924. HACCEL _haccel; // accelerators for those menus
  925. OLEMENUGROUPWIDTHS _mgw; // the number of Edit, Object, and Help menus
  926. OLECHAR _szUserClassType[4][64];// [0] unused
  927. // [1] the string assigned to classid key in reg db.
  928. // [2] reg db: \CLSID\<clsid>\AuxUserType\2
  929. // [3] reg db: \CLSID\<clsid>\AuxUserType\3
  930. OLECHAR _szDocfileExt[8]; // extension for docfile files
  931. DWORD _dwMiscStatus; // reg db: \CLSID\<clsid>\MiscStatus
  932. //DERIVED: The derived class must supply these tables.
  933. //REVIEW: These could be loaded from resources, too!
  934. LPOLEVERB _pVerbTable; // pointer to list of verbs available
  935. int _cVerbTable; // number of entries in the verb table
  936. LPFORMATETC _pGetFmtTable; // format table for IDataObject::GetData[Here]
  937. int _cGetFmtTable; // number of entries in the table
  938. LPFORMATETC _pSetFmtTable; // format table for IDataObject::SetData
  939. int _cSetFmtTable; // number of entries in the table
  940. };
  941. //+---------------------------------------------------------------
  942. //
  943. // Class: SrvrCtrl
  944. //
  945. // Purpose: Control subobject of OLE compound document server
  946. //
  947. // Notes: This class supports the IOleObject interface.
  948. //
  949. //---------------------------------------------------------------
  950. class SrvrCtrl : public IOleObject
  951. {
  952. public:
  953. // standard verb implementations
  954. typedef HRESULT (*LPFNDOVERB) (LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  955. static HRESULT DoShow(LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  956. static HRESULT DoOpen(LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  957. static HRESULT DoHide(LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  958. static HRESULT DoUIActivate(LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  959. static HRESULT DoInPlaceActivate(LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  960. //DERIVED: IUnknown methods are left pure virtual and must be implemented
  961. // by the derived class
  962. // IOleObject interface methods
  963. STDMETHOD(SetClientSite) (LPOLECLIENTSITE pClientSite);
  964. STDMETHOD(GetClientSite) (LPOLECLIENTSITE FAR* ppClientSite);
  965. STDMETHOD(SetHostNames) (LPCOLESTR szContainerApp, LPCOLESTR szContainerObj);
  966. STDMETHOD(Close) (DWORD dwSaveOption);
  967. STDMETHOD(SetMoniker) (DWORD dwWhichMoniker, LPMONIKER pmk);
  968. STDMETHOD(GetMoniker) (DWORD dwAssign, DWORD dwWhichMoniker,
  969. LPMONIKER FAR* ppmk);
  970. STDMETHOD(InitFromData) (LPDATAOBJECT pDataObject,BOOL fCreation,
  971. DWORD dwReserved);
  972. STDMETHOD(GetClipboardData) (DWORD dwReserved, LPDATAOBJECT FAR* ppDataObject);
  973. STDMETHOD(DoVerb) (LONG iVerb, LPMSG lpmsg, LPOLECLIENTSITE pActiveSite,
  974. LONG lindex, HWND hwndParent, LPCRECT lprcPosRect);
  975. STDMETHOD(EnumVerbs) (LPENUMOLEVERB FAR* ppenumOleVerb);
  976. STDMETHOD(Update) (void);
  977. STDMETHOD(IsUpToDate) (void);
  978. STDMETHOD(GetUserClassID) (CLSID FAR* pClsid);
  979. STDMETHOD(GetUserType) (DWORD dwFormOfType, LPOLESTR FAR* pszUserType);
  980. STDMETHOD(SetExtent) (DWORD dwDrawAspect, LPSIZEL lpsizel);
  981. STDMETHOD(GetExtent) (DWORD dwDrawAspect, LPSIZEL lpsizel);
  982. STDMETHOD(Advise)(IAdviseSink FAR* pAdvSink, DWORD FAR* pdwConnection);
  983. STDMETHOD(Unadvise)(DWORD dwConnection);
  984. STDMETHOD(EnumAdvise) (LPENUMSTATDATA FAR* ppenumAdvise);
  985. STDMETHOD(GetMiscStatus) (DWORD dwAspect, DWORD FAR* pdwStatus);
  986. STDMETHOD(SetColorScheme) (LPLOGPALETTE lpLogpal);
  987. // pointers to our data/view and inplace subobjects
  988. LPSRVRDV _pDV; // our persistent data/view subobject
  989. LPSRVRINPLACE _pInPlace; // our inplace-active subobject
  990. // pointers to those objects' private unknowns
  991. LPUNKNOWN _pPrivUnkDV;
  992. LPUNKNOWN _pPrivUnkIP;
  993. // methods and members required by our data/view and inplace subobjects.
  994. OLE_SERVER_STATE State(void);
  995. void SetState(OLE_SERVER_STATE state)
  996. {
  997. _state = state;
  998. };
  999. HRESULT TransitionTo(OLE_SERVER_STATE state);
  1000. LPOLECLIENTSITE _pClientSite;
  1001. void OnSave(void);
  1002. void EnableIPB(BOOL fEnabled);
  1003. BOOL IsIPBEnabled(void);
  1004. virtual HRESULT Init(LPCLASSDESCRIPTOR pClass);
  1005. // IOleObject-related members
  1006. DWORD _dwRegROT; // our R.O.T. registration value
  1007. LPOLEADVISEHOLDER _pOleAdviseHolder;// for collection our advises
  1008. LPOLESTR _lpstrCntrApp; // top-level container application
  1009. LPOLESTR _lpstrCntrObj; // and object names
  1010. #if !defined(UNICODE) && !defined(OLE2ANSI)
  1011. LPSTR _lpstrCntrAppA; // (ANSI) top-level container application
  1012. LPSTR _lpstrCntrObjA; // (ANSI) and object names
  1013. #endif
  1014. protected:
  1015. //
  1016. // DERIVED: Each of these correspond to a unique state transition.
  1017. // The derived class may want to override to do additional processing.
  1018. //
  1019. virtual HRESULT PassiveToLoaded();
  1020. virtual HRESULT LoadedToPassive();
  1021. virtual HRESULT LoadedToRunning();
  1022. virtual HRESULT RunningToLoaded();
  1023. virtual HRESULT RunningToInPlace();
  1024. virtual HRESULT InPlaceToRunning();
  1025. virtual HRESULT InPlaceToUIActive();
  1026. virtual HRESULT UIActiveToInPlace();
  1027. virtual HRESULT RunningToOpened();
  1028. virtual HRESULT OpenedToRunning();
  1029. // constructors, initializers, and destructors
  1030. SrvrCtrl(void);
  1031. virtual ~SrvrCtrl(void);
  1032. LPCLASSDESCRIPTOR _pClass; // global info about our OLE server
  1033. OLE_SERVER_STATE _state; // our current state
  1034. BOOL _fEnableIPB; // FALSE turns off built-in border
  1035. //DERIVED: The derived class must supply table of verb functions
  1036. // parallel to the table of verbs in the class descriptor
  1037. LPFNDOVERB FAR* _pVerbFuncs; // verb function table
  1038. };
  1039. //+---------------------------------------------------------------
  1040. //
  1041. // Member: SrvrCtrl::State, public
  1042. //
  1043. // Synopsis: Returns the current state of the object
  1044. //
  1045. // Notes: The valid object states are closed, loaded, inplace,
  1046. // U.I. active, and open. These states are defined
  1047. // by the OLE_SERVER_STATE enumeration.
  1048. //
  1049. //---------------------------------------------------------------
  1050. inline OLE_SERVER_STATE
  1051. SrvrCtrl::State(void)
  1052. {
  1053. return _state;
  1054. }
  1055. //+---------------------------------------------------------------
  1056. //
  1057. // Member: SrvrCtrl::EnableIPB, public
  1058. //
  1059. // Synopsis: Enables/Disables built in InPlace border
  1060. //
  1061. //---------------------------------------------------------------
  1062. inline void
  1063. SrvrCtrl::EnableIPB(BOOL fEnabled)
  1064. {
  1065. _fEnableIPB = fEnabled;
  1066. }
  1067. //+---------------------------------------------------------------
  1068. //
  1069. // Member: SrvrCtrl::IsIPBEnabled, public
  1070. //
  1071. // Synopsis: Answers whether built-in InPlace border is enabled
  1072. //
  1073. //---------------------------------------------------------------
  1074. inline BOOL
  1075. SrvrCtrl::IsIPBEnabled(void)
  1076. {
  1077. return _fEnableIPB;
  1078. }
  1079. //+---------------------------------------------------------------
  1080. //
  1081. // Class: SrvrDV
  1082. //
  1083. // Purpose: Data/View subobject of OLE compound document server
  1084. //
  1085. // Notes: This class supports the IDataObject and IViewObject interfaces.
  1086. // It also supports the IPersist-derived interfaces.
  1087. // Objects of this class can operate as part of a complete
  1088. // server aggregation or independently as a transfer data
  1089. // object.
  1090. //
  1091. //---------------------------------------------------------------
  1092. class SrvrDV: public IDataObject,
  1093. public IViewObject,
  1094. public IPersistStorage,
  1095. public IPersistStream,
  1096. public IPersistFile
  1097. {
  1098. public:
  1099. typedef HRESULT (*LPFNGETDATA) (LPSRVRDV, LPFORMATETC, LPSTGMEDIUM, BOOL);
  1100. typedef HRESULT (*LPFNSETDATA) (LPSRVRDV, LPFORMATETC, LPSTGMEDIUM);
  1101. // standard format Get/Set implementations
  1102. static HRESULT GetEMBEDDEDOBJECT(LPSRVRDV, LPFORMATETC, LPSTGMEDIUM, BOOL);
  1103. static HRESULT GetMETAFILEPICT(LPSRVRDV, LPFORMATETC, LPSTGMEDIUM, BOOL);
  1104. static HRESULT GetOBJECTDESCRIPTOR(LPSRVRDV, LPFORMATETC, LPSTGMEDIUM, BOOL);
  1105. static HRESULT GetLINKSOURCE(LPSRVRDV, LPFORMATETC, LPSTGMEDIUM, BOOL);
  1106. //
  1107. //DERIVED: IUnknown methods are left pure virtual and must be implemented
  1108. // by the derived class
  1109. //
  1110. // IDataObject interface methods
  1111. //
  1112. STDMETHOD(GetData) (LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium);
  1113. STDMETHOD(GetDataHere) (LPFORMATETC pformatetc, LPSTGMEDIUM pmedium);
  1114. STDMETHOD(QueryGetData) (LPFORMATETC pformatetc);
  1115. STDMETHOD(GetCanonicalFormatEtc) (LPFORMATETC pformatetc,
  1116. LPFORMATETC pformatetcOut);
  1117. STDMETHOD(SetData) (LPFORMATETC pformatetc, LPSTGMEDIUM pmedium,
  1118. BOOL fRelease);
  1119. STDMETHOD(EnumFormatEtc) (DWORD dwDirection, LPENUMFORMATETC FAR* ppenum);
  1120. STDMETHOD(DAdvise) (FORMATETC FAR* pFormatetc, DWORD advf,
  1121. LPADVISESINK pAdvSink, DWORD FAR* pdwConnection);
  1122. STDMETHOD(DUnadvise) (DWORD dwConnection);
  1123. STDMETHOD(EnumDAdvise) (LPENUMSTATDATA FAR* ppenumAdvise);
  1124. //
  1125. // IViewObject interface methods
  1126. //
  1127. STDMETHOD(Draw) (DWORD dwDrawAspect, LONG lindex,
  1128. void FAR* pvAspect, DVTARGETDEVICE FAR * ptd,
  1129. HDC hicTargetDev,
  1130. HDC hdcDraw,
  1131. LPCRECTL lprcBounds,
  1132. LPCRECTL lprcWBounds,
  1133. BOOL (CALLBACK * pfnContinue) (ULONG_PTR),
  1134. ULONG_PTR dwContinue);
  1135. STDMETHOD(GetColorSet) (DWORD dwDrawAspect, LONG lindex,
  1136. void FAR* pvAspect, DVTARGETDEVICE FAR * ptd,
  1137. HDC hicTargetDev,
  1138. LPLOGPALETTE FAR* ppColorSet);
  1139. STDMETHOD(Freeze)(DWORD dwDrawAspect, LONG lindex, void FAR* pvAspect,
  1140. DWORD FAR* pdwFreeze);
  1141. STDMETHOD(Unfreeze) (DWORD dwFreeze);
  1142. STDMETHOD(SetAdvise) (DWORD aspects, DWORD advf, LPADVISESINK pAdvSink);
  1143. STDMETHOD(GetAdvise) (DWORD FAR* pAspects, DWORD FAR* pAdvf,
  1144. LPADVISESINK FAR* ppAdvSink);
  1145. //
  1146. // IPersist interface methods
  1147. //
  1148. STDMETHOD(GetClassID) (LPCLSID lpClassID);
  1149. STDMETHOD(IsDirty) (void);
  1150. //
  1151. // IPersistStream interface methods
  1152. //
  1153. STDMETHOD(Load) (LPSTREAM pStm);
  1154. STDMETHOD(Save) (LPSTREAM pStm, BOOL fClearDirty);
  1155. STDMETHOD(GetSizeMax) (ULARGE_INTEGER FAR * pcbSize);
  1156. //
  1157. // IPersistStorage interface methods
  1158. //
  1159. STDMETHOD(InitNew) (LPSTORAGE pStg);
  1160. STDMETHOD(Load) (LPSTORAGE pStg);
  1161. STDMETHOD(Save) (LPSTORAGE pStgSave, BOOL fSameAsLoad);
  1162. STDMETHOD(SaveCompleted) (LPSTORAGE pStgNew);
  1163. STDMETHOD(HandsOffStorage) (void);
  1164. //
  1165. // IPersistFile interface methods
  1166. //
  1167. STDMETHOD(Load) (LPCOLESTR lpszFileName, DWORD grfMode);
  1168. STDMETHOD(Save) (LPCOLESTR lpszFileName, BOOL fRemember);
  1169. STDMETHOD(SaveCompleted) (LPCOLESTR lpszFileName);
  1170. STDMETHOD(GetCurFile) (LPOLESTR FAR * lplpszFileName);
  1171. //
  1172. // DERIVED: methods required by the control
  1173. //
  1174. virtual HRESULT GetClipboardCopy(LPSRVRDV FAR* ppDV) = 0;
  1175. virtual HRESULT GetExtent(DWORD dwAspect, LPSIZEL lpsizel);
  1176. virtual HRESULT SetExtent(DWORD dwAspect, SIZEL& sizel);
  1177. virtual void SetMoniker(LPMONIKER pmk);
  1178. HRESULT GetMoniker(DWORD dwAssign, LPMONIKER FAR* ppmk);
  1179. LPOLESTR GetMonikerDisplayName(DWORD dwAssign = OLEGETMONIKER_ONLYIFTHERE);
  1180. //
  1181. //DERIVED: The derived class should call this base class method whenever
  1182. // the data changes. This launches all appropriate advises.
  1183. //
  1184. void OnDataChange(DWORD dwAdvf = 0);
  1185. //
  1186. //DERIVED: The derived class should override these methods to perform
  1187. // rendering of its native data. These are used in the implementation of
  1188. // the IViewObject interface
  1189. //
  1190. virtual HRESULT RenderContent(DWORD dwDrawAspect,
  1191. LONG lindex,
  1192. void FAR* pvAspect,
  1193. DVTARGETDEVICE FAR * ptd,
  1194. HDC hicTargetDev,
  1195. HDC hdcDraw,
  1196. LPCRECTL lprectl,
  1197. LPCRECTL lprcWBounds,
  1198. BOOL (CALLBACK * pfnContinue) (ULONG_PTR),
  1199. ULONG_PTR dwContinue);
  1200. virtual HRESULT RenderPrint(DWORD dwDrawAspect,
  1201. LONG lindex,
  1202. void FAR* pvAspect,
  1203. DVTARGETDEVICE FAR * ptd,
  1204. HDC hicTargetDev,
  1205. HDC hdcDraw,
  1206. LPCRECTL lprectl,
  1207. LPCRECTL lprcWBounds,
  1208. BOOL (CALLBACK * pfnContinue) (ULONG_PTR),
  1209. ULONG_PTR dwContinue);
  1210. virtual HRESULT RenderThumbnail(DWORD dwDrawAspect,
  1211. LONG lindex,
  1212. void FAR* pvAspect,
  1213. DVTARGETDEVICE FAR * ptd,
  1214. HDC hicTargetDev,
  1215. HDC hdcDraw,
  1216. LPCRECTL lprectl,
  1217. LPCRECTL lprcWBounds,
  1218. BOOL (CALLBACK * pfnContinue) (ULONG_PTR),
  1219. ULONG_PTR dwContinue);
  1220. BOOL IsInNoScrible(void);
  1221. virtual HRESULT Init(LPCLASSDESCRIPTOR pClass, LPSRVRCTRL pCtrl);
  1222. virtual HRESULT Init(LPCLASSDESCRIPTOR pClass, LPSRVRDV pDV);
  1223. protected:
  1224. //
  1225. //DERIVED: The derived class should override these methods to perform
  1226. // persistent serialization and deserialization. These are used in the
  1227. // implementation of IPersistStream/Storage/File
  1228. //
  1229. virtual HRESULT LoadFromStream(LPSTREAM pStrm);
  1230. virtual HRESULT SaveToStream(LPSTREAM pStrm);
  1231. virtual DWORD GetStreamSizeMax(void);
  1232. virtual HRESULT LoadFromStorage(LPSTORAGE pStg);
  1233. virtual HRESULT SaveToStorage(LPSTORAGE pStg, BOOL fSameAsLoad);
  1234. //
  1235. // constructors, initializers, and destructors
  1236. //
  1237. SrvrDV(void);
  1238. virtual ~SrvrDV(void);
  1239. LPCLASSDESCRIPTOR _pClass; // global info about our OLE server
  1240. LPSRVRCTRL _pCtrl; // control of server aggregate or
  1241. // NULL if transfer object
  1242. //
  1243. // IDataObject-related members
  1244. //
  1245. LPMONIKER _pmk; // moniker used for LINKSOURCE
  1246. LPOLESTR _lpstrDisplayName; // cached display name of moniker
  1247. SIZEL _sizel; // used for OBJECTDESCRIPTOR and Extent
  1248. LPDATAADVISEHOLDER _pDataAdviseHolder;
  1249. //
  1250. //DERIVED: The derived class must supply table of Get functions
  1251. // and a table of Set functions parallel to the FORMATETC tables
  1252. // in the class descriptor.
  1253. //
  1254. LPFNGETDATA FAR* _pGetFuncs; // GetData(Here) function table
  1255. LPFNSETDATA FAR* _pSetFuncs; // SetData function table
  1256. LPVIEWADVISEHOLDER _pViewAdviseHolder;
  1257. unsigned _fFrozen: 1; // blocked from updating
  1258. unsigned _fDirty: 1; // TRUE iff persistent data has changed
  1259. unsigned _fNoScribble: 1; // between save and save completed
  1260. // IPersistStorage-related members
  1261. LPSTORAGE _pStg; // our home IStorage instance
  1262. };
  1263. //+---------------------------------------------------------------
  1264. //
  1265. // Member: SrvrDV::IsInNoScrible, public
  1266. //
  1267. // Synopsis: Answers wether we are currently in no-scribble mode
  1268. //
  1269. //---------------------------------------------------------------
  1270. inline BOOL
  1271. SrvrDV::IsInNoScrible(void)
  1272. {
  1273. return _fNoScribble;
  1274. }
  1275. //+---------------------------------------------------------------
  1276. //
  1277. // Class: SrvrInPlace
  1278. //
  1279. // Purpose: Inplace subobject of OLE compound document server
  1280. //
  1281. // Notes: This class supports the IOleInPlaceObject and
  1282. // IOleInPlaceActiveObject interfaces.
  1283. //
  1284. //---------------------------------------------------------------
  1285. class SrvrInPlace: public IOleInPlaceObject,
  1286. public IOleInPlaceActiveObject
  1287. {
  1288. public:
  1289. //DERIVED: IUnknown methods are left pure virtual and must be implemented
  1290. // by the derived class
  1291. // IOleWindow interface methods
  1292. STDMETHOD(GetWindow) (HWND FAR* lphwnd);
  1293. STDMETHOD(ContextSensitiveHelp) (BOOL fEnterMode);
  1294. // IOleInPlaceObject interface methods
  1295. STDMETHOD(InPlaceDeactivate) (void);
  1296. STDMETHOD(UIDeactivate) (void);
  1297. STDMETHOD(SetObjectRects) (LPCRECT lprcPosRect, LPCRECT lprcClipRect);
  1298. STDMETHOD(ReactivateAndUndo) (void);
  1299. // IOleInPlaceActiveObject methods
  1300. STDMETHOD(TranslateAccelerator) (LPMSG lpmsg);
  1301. STDMETHOD(OnFrameWindowActivate) (BOOL fActivate);
  1302. STDMETHOD(OnDocWindowActivate) (BOOL fActivate);
  1303. STDMETHOD(ResizeBorder) (LPCRECT lprectBorder,
  1304. LPOLEINPLACEUIWINDOW lpUIWindow,
  1305. BOOL fFrameWindow);
  1306. STDMETHOD(EnableModeless) (BOOL fEnable);
  1307. // methods and members required by the other subobjects.
  1308. HWND WindowHandle(void);
  1309. void SetChildActivating(BOOL fGoingActive);
  1310. BOOL GetChildActivating(void);
  1311. BOOL IsDeactivating(void);
  1312. void ReflectState(BOOL fUIActive);
  1313. LPOLEINPLACEFRAME _pFrame; // our in-place active frame
  1314. LPOLEINPLACEUIWINDOW _pDoc; // our in-place active document
  1315. //DERIVED: These methods are called by the control to effect a
  1316. // state transition. The derived class can override these methods if
  1317. // it requires additional processing.
  1318. virtual HRESULT ActivateInPlace(IOleClientSite *pClientSite);
  1319. virtual HRESULT DeactivateInPlace(void);
  1320. virtual HRESULT ActivateUI(void);
  1321. virtual HRESULT DeactivateUI(void);
  1322. //DERIVED: These methods are related to U.I. activation. The derived
  1323. // class should override these to perform additional processing for
  1324. // any frame, document, or floating toolbars or palettes.
  1325. virtual void InstallUI(void);
  1326. virtual void RemoveUI(void);
  1327. LPOLEINPLACESITE _pInPlaceSite; // our in-place client site
  1328. virtual HRESULT Init(LPCLASSDESCRIPTOR pClass, LPSRVRCTRL pCtrl);
  1329. protected:
  1330. //DERIVED: More U.I. activation-related methods.
  1331. virtual void CreateUI(void);
  1332. virtual void DestroyUI(void);
  1333. virtual void InstallFrameUI(void);
  1334. virtual void RemoveFrameUI(void);
  1335. virtual void InstallDocUI(void);
  1336. virtual void RemoveDocUI(void);
  1337. virtual void ClearSelection(void);
  1338. virtual void SetFocus(HWND hwnd);
  1339. //DERIVED: The derived class must override this function to
  1340. // attach the servers in-place active window.
  1341. virtual HWND AttachWin(HWND hwndParent) = 0;
  1342. virtual void DetachWin(void);
  1343. SrvrInPlace(void);
  1344. virtual ~SrvrInPlace(void);
  1345. LPCLASSDESCRIPTOR _pClass; // global info about our class
  1346. LPSRVRCTRL _pCtrl; // the control we are part of.
  1347. // IOleInPlaceObject-related members
  1348. unsigned _fUIDown: 1; // menu/tools integrated with container?
  1349. unsigned _fChildActivating: 1; // site going UIActive?
  1350. unsigned _fDeactivating: 1; // being deactivated from the outside?
  1351. unsigned _fCSHelpMode: 1; // in context-sensitive help state?
  1352. OLEINPLACEFRAMEINFO _frameInfo; // accelerator information from our container
  1353. InPlaceBorder _IPB; // our In-Place border when UIActive
  1354. RECT _rcFrame; // our frame rect
  1355. HWND _hwnd; // our InPlace window
  1356. HMENU _hmenu;
  1357. HOLEMENU _hOleMenu; // menu registered w/ OLE
  1358. HMENU _hmenuShared; // the shared menu when we are UI active
  1359. OLEMENUGROUPWIDTHS _mgw; // menu interleaving information
  1360. BOOL _fClientResize; // TRUE during calls to SetObjectRects
  1361. };
  1362. //+---------------------------------------------------------------
  1363. //
  1364. // Member: SrvrInPlace::IsDeactivating, public
  1365. //
  1366. // Synopsis: Gets value of a flag indicating deactivation
  1367. // (from the outside) in progress
  1368. //
  1369. //---------------------------------------------------------------
  1370. inline BOOL
  1371. SrvrInPlace::IsDeactivating(void)
  1372. {
  1373. return _fDeactivating;
  1374. }
  1375. //+---------------------------------------------------------------
  1376. //
  1377. // Member: SrvrInPlace::GetChildActivating, public
  1378. //
  1379. // Synopsis: Gets value of a flag indicating that a child is
  1380. // activating to prevent menu flashing
  1381. //
  1382. //---------------------------------------------------------------
  1383. inline BOOL
  1384. SrvrInPlace::GetChildActivating(void)
  1385. {
  1386. return _fChildActivating;
  1387. }
  1388. //+---------------------------------------------------------------
  1389. //
  1390. // Member: SrvrInPlace::SetChildActivating, public
  1391. //
  1392. // Synopsis: Sets or clears a flag indicating that a child is
  1393. // activating to prevent menu flashing
  1394. //
  1395. //---------------------------------------------------------------
  1396. inline void
  1397. SrvrInPlace::SetChildActivating(BOOL fGoingActive)
  1398. {
  1399. _fChildActivating = fGoingActive;
  1400. }
  1401. //+---------------------------------------------------------------
  1402. //
  1403. // Member: SrvrInPlace::WindowHandle, public
  1404. //
  1405. // Synopsis: Returns object window handle
  1406. //
  1407. //---------------------------------------------------------------
  1408. inline HWND
  1409. SrvrInPlace::WindowHandle(void)
  1410. {
  1411. return _hwnd;
  1412. }
  1413. //+---------------------------------------------------------------
  1414. //
  1415. // Member: SrvrInPlace::ReflectState, public
  1416. //
  1417. // Synopsis: TBD
  1418. //
  1419. //---------------------------------------------------------------
  1420. inline void
  1421. SrvrInPlace::ReflectState(BOOL fActive)
  1422. {
  1423. if(_pCtrl->IsIPBEnabled())
  1424. {
  1425. _IPB.SetUIActive(fActive);
  1426. }
  1427. }
  1428. #endif // !RC_INVOKED
  1429. #endif //_O2BASE_HXX_
  1430.