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.

2177 lines
68 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. // StatusBar // Included only if INC_STATUS_BAR defined
  16. //
  17. // Functions:
  18. // HimetricFromHPix
  19. // HimetricFromVPix
  20. // HPixFromHimetric
  21. // VPixFromHimetric
  22. //
  23. // WatchInterface
  24. //
  25. // OleAllocMem
  26. // OleFreeMem
  27. // OleAllocString
  28. // OleFreeString
  29. //
  30. // IsCompatibleOleVersion
  31. // IsDraggingDistance
  32. //
  33. // TraceIID
  34. // TraceHRESULT
  35. //
  36. // RECTtoRECTL
  37. // RECTLtoRECT
  38. // ProportionateRectl
  39. // RectToScreen
  40. // RectToClient
  41. // IsRectInRect
  42. // lMulDiv
  43. //
  44. // LeadResourceData
  45. // GetChildWindowRect
  46. // SizeClientRect
  47. //
  48. // RegisterOleClipFormats
  49. // IsCompatibleDevice
  50. // IsCompatibleFormat
  51. // FindCompatibleFormat
  52. // GetObjectDescriptor
  53. // UpdateObjectDescriptor
  54. // DrawMetafile
  55. //
  56. // InsertServerMenus
  57. // RemoteServerMenus
  58. //
  59. // RegisterAsRunning
  60. // RevokeAsRunning
  61. //
  62. // CreateStreamOnFile
  63. //
  64. // CreateOLEVERBEnum
  65. // CreateFORMATETCEnum
  66. // CreateStaticEnum
  67. //
  68. // GetMonikerDisplayName
  69. // CreateStorageOnHGlobal
  70. // ConvertToMemoryStream
  71. // StmReadString
  72. // StmWriteString
  73. //
  74. // CreateViewAdviseHolder
  75. //
  76. // ---
  77. //
  78. // Macros: WATCHINTERFACE
  79. // IsSameIID
  80. //
  81. // TaskAllocMem
  82. // TaskFreeMem
  83. // TaskAllocString
  84. // TaskFreeString
  85. //
  86. // OK
  87. // NOTOK
  88. //
  89. // DECLARE_IUNKNOWN_METHODS
  90. // DECLARE_PURE_IUNKNOWN_METHODS
  91. // DECLARE_STANDARD_IUNKNOWN
  92. // IMPLEMENT_STANDARD_IUNKNOWN
  93. // DECLARE_DELEGATING_IUNKNOWN
  94. // IMPLEMENT_DELEGATING_IUNKNOWN
  95. // DECLARE_PRIVATE_IUNKNOWN
  96. // IMPLEMENT_PRIVATE_IUNKNOWN
  97. //
  98. // DECLARE_CODE_TIMER
  99. // IMPLEMENT_CODE_TIMER
  100. // START_CODE_TIMER
  101. // STOP_CODE_TIMER
  102. //
  103. // Enums:
  104. // OLE_SERVER_STATE
  105. //
  106. // OBPARTS
  107. // OLECLIPFORMAT
  108. //
  109. // ---
  110. //
  111. // Notes: Define INC_STATUS_BAR to include the status bar
  112. // class definition.
  113. //
  114. //----------------------------------------------------------------------------
  115. #ifndef _O2BASE_HXX_
  116. #define _O2BASE_HXX_
  117. // resource ID offsets for class descriptor information
  118. #define IDOFF_CLASSID 0
  119. #define IDOFF_USERTYPEFULL 1
  120. #define IDOFF_USERTYPESHORT 2
  121. #define IDOFF_USERTYPEAPP 3
  122. #define IDOFF_DOCFEXT 5
  123. #define IDOFF_ICON 10
  124. #define IDOFF_ACCELS 11
  125. #define IDOFF_MENU 12
  126. #define IDOFF_MGW 13
  127. #define IDOFF_MISCSTATUS 14
  128. #ifndef RC_INVOKED // the resource compiler is not interested in the rest
  129. #if DBG
  130. extern "C" void FAR PASCAL AssertSFL(
  131. LPSTR lpszClause,
  132. LPSTR lpszFileName,
  133. int nLine);
  134. #define Assert(f) ((f)? (void)0 : AssertSFL(#f, __FILE__, __LINE__))
  135. #else // !DBG
  136. #define Assert(x)
  137. #endif // DBG
  138. //+---------------------------------------------------------------------
  139. //
  140. // Windows helper functions
  141. //
  142. //----------------------------------------------------------------------
  143. LPVOID LoadResourceData(HINSTANCE hinst,
  144. LPCWSTR lpstrId,
  145. LPVOID lpvBuf,
  146. int cbBuf);
  147. void GetChildWindowRect(HWND hwndChild, LPRECT lprect);
  148. void SizeClientRect(HWND hwnd, RECT& rc, BOOL fMove);
  149. //+---------------------------------------------------------------------
  150. //
  151. // Generally useful #defines and inline functions for OLE2.
  152. //
  153. //------------------------------------------------------------------------
  154. // this macro can be used to put string constants in a read-only code segment
  155. // usage: char CODE_BASED szFoo[] = "Bar";
  156. #define CODE_BASED __based(__segname("_CODE"))
  157. // These are the major and minor version returned by OleBuildVersion
  158. #define OLE_MAJ_VER 0x0003
  159. #define OLE_MIN_VER 0x003A
  160. //---------------------------------------------------------------
  161. // SCODE and HRESULT macros
  162. //---------------------------------------------------------------
  163. #define OK(r) (SUCCEEDED(r))
  164. #define NOTOK(r) (FAILED(r))
  165. //---------------------------------------------------------------
  166. // GUIDs, CLSIDs, IIDs
  167. //---------------------------------------------------------------
  168. #define IsSameIID(iid1, iid2) ((iid1)==(iid2))
  169. //---------------------------------------------------------------
  170. // IUnknown
  171. //---------------------------------------------------------------
  172. //
  173. // This declares the set of IUnknown methods and is for general-purpose
  174. // use inside classes that inherit from IUnknown
  175. #define DECLARE_IUNKNOWN_METHODS \
  176. STDMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj); \
  177. STDMETHOD_(ULONG,AddRef) (void); \
  178. STDMETHOD_(ULONG,Release) (void)
  179. //
  180. // This declares the set of IUnknown methods as pure virtual methods
  181. //
  182. #define DECLARE_PURE_IUNKNOWN_METHODS \
  183. STDMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj) = 0; \
  184. STDMETHOD_(ULONG,AddRef) (void) = 0; \
  185. STDMETHOD_(ULONG,Release) (void) = 0
  186. //
  187. // This is for use in declaring non-aggregatable objects. It declares the
  188. // IUnknown methods and reference counter, _ulRefs.
  189. // _ulRefs should be initialized to 1 in the constructor of the object
  190. #define DECLARE_STANDARD_IUNKNOWN(cls) \
  191. DECLARE_IUNKNOWN_METHODS; \
  192. ULONG _ulRefs
  193. // note: this does NOT implement QueryInterface, which must be
  194. // implemented by each object
  195. #define IMPLEMENT_STANDARD_IUNKNOWN(cls) \
  196. STDMETHODIMP_(ULONG) cls##::AddRef(void) \
  197. { ++_ulRefs; \
  198. return _ulRefs;} \
  199. STDMETHODIMP_(ULONG) cls##::Release(void) \
  200. { ULONG ulRet = --_ulRefs; \
  201. if (ulRet == 0) delete this; \
  202. return ulRet; }
  203. // This is for use in declaring aggregatable objects. It declares the IUnknown
  204. // methods and a member pointer to the aggregate controlling unknown, _pUnkOuter,
  205. // that all IUnknowns delegate to except the controlling unknown of the object
  206. // itself.
  207. // _pUnkOuter must be initialized to point to either an external controlling
  208. // unknown or the object's own controlling unknown, depending on whether the
  209. // object is being created as part of an aggregate or not.
  210. #define DECLARE_DELEGATING_IUNKNOWN(cls) \
  211. DECLARE_IUNKNOWN_METHODS; \
  212. LPUNKNOWN _pUnkOuter
  213. // This, correspondingly, is for use in implementing aggregatable objects.
  214. // It implements the IUnknown methods by trivially delegating to the controlling
  215. // unknown described by _pUnkOuter.
  216. #define IMPLEMENT_DELEGATING_IUNKNOWN(cls) \
  217. STDMETHODIMP cls##::QueryInterface (REFIID riid, LPVOID FAR* ppvObj) \
  218. { return _pUnkOuter->QueryInterface(riid, ppvObj); } \
  219. STDMETHODIMP_(ULONG) cls##::AddRef (void) \
  220. { return _pUnkOuter->AddRef(); } \
  221. STDMETHODIMP_(ULONG) cls##::Release (void) \
  222. { return _pUnkOuter->Release(); }
  223. // This declares a nested class that is the private unknown of the object
  224. #define DECLARE_PRIVATE_IUNKNOWN(cls) \
  225. class PrivateUnknown: public IUnknown { \
  226. public: \
  227. PrivateUnknown(cls* p##cls); \
  228. DECLARE_IUNKNOWN_METHODS; \
  229. private: \
  230. ULONG _ulRefs; \
  231. cls* _p##cls; }; \
  232. friend class PrivateUnknown; \
  233. PrivateUnknown _PrivUnk
  234. //
  235. // note: this does NOT implement QueryInterface, which must be
  236. // implemented by each object
  237. #define IMPLEMENT_PRIVATE_IUNKNOWN(cls) \
  238. cls##::PrivateUnknown::PrivateUnknown(cls* p##cls) \
  239. { _p##cls = p##cls; _ulRefs = 1; } \
  240. STDMETHODIMP_(ULONG) cls##::PrivateUnknown::AddRef(void) \
  241. { ++_ulRefs; \
  242. return _ulRefs; } \
  243. STDMETHODIMP_(ULONG) cls##::PrivateUnknown::Release(void) \
  244. { ULONG ulRet = --_ulRefs; \
  245. if (ulRet == 0) delete _p##cls; \
  246. return ulRet; }
  247. //+---------------------------------------------------------------------
  248. //
  249. // Miscellaneous useful OLE helper and debugging functions
  250. //
  251. //----------------------------------------------------------------------
  252. //
  253. // Some convenient OLE-related definitions and declarations
  254. //
  255. typedef unsigned short far * LPUSHORT;
  256. //REVIEW we are experimenting with a non-standard OLEMISC flag.
  257. #define OLEMISC_STREAMABLE 1024
  258. IsCompatibleOleVersion(WORD wMaj, WORD wMin);
  259. inline BOOL IsDraggingDistance(POINT pt1, POINT pt2)
  260. {
  261. #define MIN_DRAG_DIST 12
  262. return (abs(pt1.x - pt2.x) >= MIN_DRAG_DIST ||
  263. abs(pt1.y - pt2.y) >= MIN_DRAG_DIST);
  264. #undef MIN_DRAG_DIST
  265. }
  266. #if ENABLED_DBG == 1
  267. void TraceIID(REFIID riid);
  268. HRESULT TraceHRESULT(HRESULT r);
  269. #define TRACEIID(iid) TraceIID(iid)
  270. #define TRACEHRESULT(r) TraceHRESULT(r)
  271. #else // DBG == 0
  272. #define TRACEIID(iid)
  273. #define TRACEHRESULT(r)
  274. #endif // DBG
  275. //+---------------------------------------------------------------------
  276. //
  277. // Routines to convert Pixels to Himetric and vice versa
  278. //
  279. //----------------------------------------------------------------------
  280. long HimetricFromHPix(int iPix);
  281. long HimetricFromVPix(int iPix);
  282. int HPixFromHimetric(long lHi);
  283. int VPixFromHimetric(long lHi);
  284. //+---------------------------------------------------------------------
  285. //
  286. // Timing helpers
  287. //
  288. //------------------------------------------------------------------------
  289. #ifdef _TIMING
  290. #define DECLARE_CODE_TIMER(t) extern CTimer t
  291. #define IMPLEMENT_CODE_TIMER(t,s) CTimer t(s)
  292. #define START_CODE_TIMER(t) t.Start()
  293. #define STOP_CODE_TIMER(t) t.Stop()
  294. #else // !_TIMING
  295. #define DECLARE_CODE_TIMER(t)
  296. #define IMPLEMENT_CODE_TIMER(t,s)
  297. #define START_CODE_TIMER(t)
  298. #define STOP_CODE_TIMER(t)
  299. #endif // _TIMING
  300. //+---------------------------------------------------------------------
  301. //
  302. // Rectangle helper functions
  303. //
  304. //----------------------------------------------------------------------
  305. //+---------------------------------------------------------------
  306. //
  307. // Function: RECTtoRECTL
  308. //
  309. // Synopsis: Converts a RECT structure to a RECTL
  310. //
  311. //----------------------------------------------------------------
  312. inline void RECTtoRECTL(RECT& rc, LPRECTL lprcl)
  313. {
  314. lprcl->left = (long)rc.left;
  315. lprcl->top = (long)rc.top;
  316. lprcl->bottom = (long)rc.bottom;
  317. lprcl->right = (long)rc.right;
  318. }
  319. //+---------------------------------------------------------------
  320. //
  321. // Function: RECTLtoRECT
  322. //
  323. // Synopsis: Converts a RECTL structure to a RECT
  324. //
  325. //----------------------------------------------------------------
  326. inline void RECTLtoRECT(RECTL& rcl, LPRECT lprc)
  327. {
  328. lprc->left = (int)rcl.left;
  329. lprc->top = (int)rcl.top;
  330. lprc->bottom = (int)rcl.bottom;
  331. lprc->right = (int)rcl.right;
  332. }
  333. //+---------------------------------------------------------------
  334. //
  335. // Function: lMulDiv, private
  336. //
  337. // Synopsis: Does a long MulDiv operation
  338. //
  339. //----------------------------------------------------------------
  340. inline long lMulDiv(long lMultiplicand, long lMultiplier, long lDivisor)
  341. {
  342. return (lMultiplicand * lMultiplier)/lDivisor; //FEATURE: 64bit intermediate?
  343. }
  344. //+---------------------------------------------------------------
  345. //
  346. // Function: ProportionateRectl
  347. //
  348. // Synopsis: Calculates rectangle A that is proportionate to rectangle B
  349. // as rectangle C is to rectangle D,
  350. // i.e. determine A such that A's relation to B is the same as
  351. // C's relation to D.
  352. //
  353. // Arguments: [lprclA] -- rectangle A to be computed
  354. // [rclB] -- rectangle B
  355. // [rclC] -- rectangle C
  356. // [rclD] -- rectangle D
  357. //
  358. //----------------------------------------------------------------
  359. inline void ProportionateRectl(LPRECTL lprclA, RECTL& rclB,
  360. RECTL& rclC, RECTL& rclD)
  361. {
  362. // start with rectangle C
  363. *lprclA = rclC;
  364. // translate it so the UL corner of D is at the origin
  365. lprclA->left -= rclD.left;
  366. lprclA->top -= rclD.top;
  367. lprclA->right -= rclD.left;
  368. lprclA->bottom -= rclD.top;
  369. // scale it by the ratio of the size of B to D (each axis independently)
  370. SIZEL sizelB = { rclB.right - rclB.left, rclB.bottom - rclB.top };
  371. SIZEL sizelD = { rclD.right - rclD.left, rclD.bottom - rclD.top };
  372. lprclA->left = lMulDiv(lprclA->left, sizelB.cx, sizelD.cx);
  373. lprclA->top = lMulDiv(lprclA->top, sizelB.cy, sizelD.cy);
  374. lprclA->right = lMulDiv(lprclA->right, sizelB.cx, sizelD.cx);
  375. lprclA->bottom = lMulDiv(lprclA->bottom, sizelB.cy, sizelD.cy);
  376. // translate it to the coordinates represented by B
  377. lprclA->left += rclB.left;
  378. lprclA->top += rclB.top;
  379. lprclA->right += rclB.left;
  380. lprclA->bottom += rclB.top;
  381. }
  382. //+---------------------------------------------------------------
  383. //
  384. // Function: RectToScreen
  385. //
  386. // Synopsis: Converts a rectangle in client coordinates of a window
  387. // to screen coordinates.
  388. //
  389. // Arguments: [hwnd] -- the window defining the client coordinate space
  390. // [lprect] -- the rectangle to be converted
  391. //
  392. //----------------------------------------------------------------
  393. inline void RectToScreen(HWND hwnd, LPRECT lprect)
  394. {
  395. POINT ptUL = { lprect->left, lprect->top };
  396. ClientToScreen(hwnd,&ptUL);
  397. POINT ptLR = { lprect->right, lprect->bottom };
  398. ClientToScreen(hwnd,&ptLR);
  399. lprect->left = ptUL.x;
  400. lprect->top = ptUL.y;
  401. lprect->right = ptLR.x;
  402. lprect->bottom = ptLR.y;
  403. }
  404. //+---------------------------------------------------------------
  405. //
  406. // Function: RectToClient
  407. //
  408. // Synopsis: Converts a rectangle in screen coordinates to client
  409. // coordinates of a window.
  410. //
  411. // Arguments: [hwnd] -- the window defining the client coordinate space
  412. // [lprect] -- the rectangle to be converted
  413. //
  414. //----------------------------------------------------------------
  415. inline void RectToClient(HWND hwnd, LPRECT lprect)
  416. {
  417. POINT ptUL = { lprect->left, lprect->top };
  418. ScreenToClient(hwnd,&ptUL);
  419. POINT ptLR = { lprect->right, lprect->bottom };
  420. ScreenToClient(hwnd,&ptLR);
  421. lprect->left = ptUL.x;
  422. lprect->top = ptUL.y;
  423. lprect->right = ptLR.x;
  424. lprect->bottom = ptLR.y;
  425. }
  426. //+---------------------------------------------------------------
  427. //
  428. // Function: IsRectInRect
  429. //
  430. // Synopsis: Determines whether one rectangle is wholly contained within
  431. // another rectangle.
  432. //
  433. // Arguments: [rcOuter] -- the containing rectangle
  434. // [lprect] -- the contained rectangle
  435. //
  436. //----------------------------------------------------------------
  437. inline BOOL IsRectInRect(RECT& rcOuter, RECT& rcInner)
  438. {
  439. POINT pt1 = { rcInner.left, rcInner.top };
  440. POINT pt2 = { rcInner.right, rcInner.bottom };
  441. return PtInRect(&rcOuter, pt1) && PtInRect(&rcOuter, pt2);
  442. }
  443. //+---------------------------------------------------------------------
  444. //
  445. // IMalloc-related helpers
  446. //
  447. //----------------------------------------------------------------------
  448. //REVIEW: We may want to cache the IMalloc pointer for efficiency
  449. #ifdef WIN16
  450. //
  451. // C++ new/delete replacements that use OLE's allocators
  452. //
  453. void FAR* operator new(size_t size);
  454. void FAR* operator new(size_t size, MEMCTX memctx);
  455. void operator delete(void FAR* lpv);
  456. #endif //WIN16
  457. //
  458. // inline IMalloc memory allocation functions
  459. //
  460. HRESULT OleAllocMem(MEMCTX ctx, ULONG cb, LPVOID FAR* ppv);
  461. void OleFreeMem(MEMCTX ctx, LPVOID pv);
  462. HRESULT OleAllocString(MEMCTX ctx, LPCWSTR lpstrSrc, LPWSTR FAR* ppstr);
  463. void OleFreeString(MEMCTX ctx, LPWSTR lpstr);
  464. #define TaskAllocMem(cb, ppv) OleAllocMem(MEMCTX_TASK, cb, ppv)
  465. #define TaskFreeMem(pv) OleFreeMem(MEMCTX_TASK, pv)
  466. #define TaskAllocString(lpstr, ppstr) OleAllocString(MEMCTX_TASK, lpstr, ppstr)
  467. #define TaskFreeString(lpstr) OleFreeString(MEMCTX_TASK, lpstr)
  468. //+---------------------------------------------------------------------
  469. //
  470. // Border definitions and helper class
  471. //
  472. //------------------------------------------------------------------------
  473. // Default value for border thickness unless over-ridden via SetThickness
  474. #define FBORDER_THICKNESS 4
  475. // Default values for border minimums (customize via SetMinimums)
  476. #define FBORDER_MINHEIGHT (FBORDER_THICKNESS*2 + 8);
  477. #define FBORDER_MINWIDTH (FBORDER_THICKNESS*2 + 8);
  478. #define OBSTYLE_MODMASK 0xff00 /* Mask style modifier bits */
  479. #define OBSTYLE_TYPEMASK 0x00ff /* Mask basic type definition bits */
  480. #define OBSTYLE_RESERVED 0x8000 /* bit reserved for internal use */
  481. #define OBSTYLE_INSIDE 0x4000 /* Inside or Outside rect? */
  482. #define OBSTYLE_HANDLED 0x2000 /* Size Handles Drawn? */
  483. #define OBSTYLE_ACTIVE 0x1000 /* Active Border Shading? */
  484. #define OBSTYLE_XOR 0x0800 /* Draw with XOR? */
  485. #define OBSTYLE_THICK 0x0400 /* double up lines? */
  486. #define OBSTYLE_DIAGONAL_FILL 0x0001 /* Open editing */
  487. #define OBSTYLE_SOLID_PEN 0x0002 /* Simple Outline */
  488. #define FB_HANDLED (OBSTYLE_HANDLED | OBSTYLE_SOLID_PEN)
  489. #define FB_OPEN OBSTYLE_DIAGONAL_FILL
  490. #define FB_OUTLINED OBSTYLE_SOLID_PEN
  491. #define FB_HIDDEN 0
  492. #define MAX_OBPART 13
  493. enum OBPARTS
  494. {
  495. BP_NOWHERE,
  496. BP_TOP, BP_RIGHT, BP_BOTTOM, BP_LEFT,
  497. BP_TOPRIGHT, BP_BOTTOMRIGHT, BP_BOTTOMLEFT, BP_TOPLEFT,
  498. BP_TOPHAND, BP_RIGHTHAND, BP_BOTTOMHAND, BP_LEFTHAND,
  499. BP_INSIDE
  500. };
  501. class OLEBorder
  502. {
  503. public:
  504. OLEBorder(RECT& r);
  505. OLEBorder(void);
  506. ~OLEBorder(void);
  507. void SetMinimums( SHORT sMinHeight, SHORT sMinWidth );
  508. int SetThickness(int sBorderThickness);
  509. int GetThickness(void);
  510. USHORT SetState(HDC hdc, HWND hwnd, USHORT usBorderState);
  511. USHORT GetState(void);
  512. void Draw(HDC hdc, HWND hwnd);
  513. void Erase(HWND hwnd);
  514. USHORT QueryHit(POINT point);
  515. HCURSOR MapPartToCursor(USHORT usPart);
  516. HCURSOR QueryMoveCursor(POINT ptCurrent, BOOL fMustMove);
  517. HCURSOR BeginMove(HDC hdc, HWND hwnd, POINT ptStart, BOOL fMustMove);
  518. RECT& UpdateMove(HDC hdc, HWND hwnd, POINT ptCurrent, BOOL fNewRegion);
  519. RECT& EndMove(HDC hdc, HWND hwnd, POINT ptCurrent, USHORT usBorderState);
  520. void SwitchCoords( HWND hwndFrom, HWND hwndTo );
  521. //
  522. //OLEBorder exposes it's RECT as a public data member
  523. //
  524. RECT rect;
  525. private:
  526. enum ICURS
  527. {
  528. ICURS_STD,
  529. ICURS_NWSE,
  530. ICURS_NESW,
  531. ICURS_NS,
  532. ICURS_WE
  533. };
  534. static BOOL fInit;
  535. static HCURSOR ahc[5];
  536. static int iPartMap[14];
  537. void InitClass(void);
  538. void GetBorderRect(RECT& rDest, int iEdge);
  539. void GetInsideBorder(RECT& rDest, int iEdge);
  540. void GetOutsideBorder(RECT& rDest, int iEdge);
  541. USHORT _state;
  542. int _sMinHeight;
  543. int _sMinWidth;
  544. int _sThickness;
  545. USHORT _usPart; //which portion of border was hit?
  546. POINT _pt; //last known point
  547. BOOL _fErased;
  548. };
  549. inline void OLEBorder::SetMinimums( SHORT sMinHeight, SHORT sMinWidth )
  550. {
  551. _sMinHeight = sMinHeight;
  552. _sMinWidth = sMinWidth;
  553. }
  554. inline int OLEBorder::GetThickness(void)
  555. {
  556. return(_sThickness);
  557. }
  558. inline int OLEBorder::SetThickness(int sBorderThickness)
  559. {
  560. if(sBorderThickness > 0)
  561. {
  562. _sThickness = sBorderThickness;
  563. }
  564. return(_sThickness);
  565. }
  566. inline USHORT OLEBorder::GetState(void)
  567. {
  568. return(_state);
  569. }
  570. //+---------------------------------------------------------------------
  571. //
  572. // Helper functions for implementing IDataObject and IViewObject
  573. //
  574. //----------------------------------------------------------------------
  575. //
  576. // Useful #defines
  577. //
  578. #define DVASPECT_ALL \
  579. DVASPECT_CONTENT|DVASPECT_THUMBNAIL|DVASPECT_ICON|DVASPECT_DOCPRINT
  580. //
  581. // Standard OLE Clipboard formats
  582. //
  583. enum OLECLIPFORMAT
  584. {
  585. OCF_OBJECTLINK,
  586. OCF_OWNERLINK,
  587. OCF_NATIVE,
  588. OCF_FILENAME,
  589. OCF_NETWORKNAME,
  590. OCF_DATAOBJECT,
  591. OCF_EMBEDDEDOBJECT,
  592. OCF_EMBEDSOURCE,
  593. OCF_LINKSOURCE,
  594. OCF_LINKSRCDESCRIPTOR,
  595. OCF_OBJECTDESCRIPTOR,
  596. OCF_OLEDRAW, OCF_LAST = OCF_OLEDRAW
  597. };
  598. extern UINT OleClipFormat[OCF_LAST+1]; // array of OLE standard clipboard formats
  599. // indexed by OLECLIPFORMAT enumeration.
  600. void RegisterOleClipFormats(void); // initializes OleClipFormat table.
  601. //
  602. // FORMATETC helpers
  603. //
  604. BOOL IsCompatibleDevice(DVTARGETDEVICE FAR* ptdLeft, DVTARGETDEVICE FAR* ptdRight);
  605. BOOL IsCompatibleFormat(FORMATETC& f1, FORMATETC& f2);
  606. int FindCompatibleFormat(FORMATETC FmtTable[], int iSize, FORMATETC& formatetc);
  607. //
  608. // OBJECTDESCRIPTOR clipboard format helpers
  609. //
  610. HRESULT GetObjectDescriptor(LPDATAOBJECT pDataObj, LPOBJECTDESCRIPTOR pDescOut);
  611. HRESULT UpdateObjectDescriptor(LPDATAOBJECT pDataObj, POINTL& ptl, DWORD dwAspect);
  612. //
  613. // Other helper functions
  614. //
  615. HRESULT DrawMetafile(LPVIEWOBJECT pVwObj, RECT& rc, DWORD dwAspect,
  616. HMETAFILE FAR* pHMF);
  617. //+---------------------------------------------------------------------
  618. //
  619. // IStream on top of a DOS (non-docfile) file
  620. //
  621. //----------------------------------------------------------------------
  622. HRESULT CreateStreamOnFile(LPCSTR lpstrFile, DWORD stgm, LPSTREAM FAR* ppstrm);
  623. //+---------------------------------------------------------------------
  624. //
  625. // Class: InPlaceBorder Class (IP)
  626. //
  627. // Synopsis: Helper Class to draw inplace activation borders around an
  628. // object.
  629. //
  630. // Notes: Use of this class limits windows to the use of the
  631. // non-client region for UIAtive borders only: Standard
  632. // (non-control window) scroll bars are specifically NOT
  633. // supported.
  634. //
  635. // History: 14-May-93 CliffG Created.
  636. //
  637. //------------------------------------------------------------------------
  638. #define IPBORDER_THICKNESS 6
  639. class InPlaceBorder
  640. {
  641. public:
  642. InPlaceBorder(void);
  643. ~InPlaceBorder(void);
  644. //
  645. //Substitute for standard windows API: identical signature & semantics
  646. //
  647. LRESULT DefWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  648. //
  649. //Change the server state: reflected in the nonclient window border
  650. //
  651. void SetUIActive(BOOL fUIActive);
  652. BOOL GetUIActive(void);
  653. //
  654. //Force border state to OS_LOADED, managing the cooresponding change
  655. //in border appearance: guaranteed redraw
  656. //
  657. void Erase(void);
  658. void SetBorderSize( int cx, int cy );
  659. void GetBorderSize( LPINT pcx, LPINT pcy );
  660. void Bind(LPOLEINPLACESITE pSite, HWND hwnd, BOOL fUIActive );
  661. void Attach( HWND hwnd, BOOL fUIActive );
  662. void Detach(void);
  663. void SetSize(HWND hwnd, RECT& rc);
  664. void SetParentActive( BOOL fActive );
  665. private:
  666. BOOL _fUIActive; //current state of border
  667. BOOL _fParentActive; //shade as active border?
  668. HWND _hwnd; //attached window (if any)
  669. LPOLEINPLACESITE _pSite; //InPlace site we are bound to
  670. int _cxFrame; //border horizontal thickness
  671. int _cyFrame; //border vertical thickness
  672. int _cResizing; //reentrancy control flag
  673. static WORD _cUsage; //refcount for static resources
  674. static HBRUSH _hbrActiveCaption;
  675. static HBRUSH _hbrInActiveCaption;
  676. void DrawFrame(HWND hwnd);
  677. void CalcClientRect(HWND hwnd, LPRECT lprc);
  678. LONG HitTest(HWND hwnd, int x, int y);
  679. void InvalidateFrame(void);
  680. void RedrawFrame(void);
  681. };
  682. inline void
  683. InPlaceBorder::Detach(void)
  684. {
  685. _pSite = NULL;
  686. _hwnd = NULL;
  687. }
  688. inline void
  689. InPlaceBorder::InvalidateFrame(void)
  690. {
  691. //cause a WM_NCCALCRECT to be generated
  692. if(_hwnd != NULL)
  693. {
  694. ++_cResizing;
  695. SetWindowPos( _hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED |
  696. SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
  697. _cResizing--;
  698. }
  699. }
  700. inline void
  701. InPlaceBorder::RedrawFrame(void)
  702. {
  703. if(_hwnd != NULL)
  704. {
  705. ++_cResizing;
  706. UINT afuRedraw = RDW_INVALIDATE | RDW_UPDATENOW;
  707. RedrawWindow(_hwnd, NULL, NULL, afuRedraw);
  708. _cResizing--;
  709. }
  710. }
  711. inline void
  712. InPlaceBorder::SetParentActive( BOOL fActive )
  713. {
  714. _fParentActive = fActive;
  715. RedrawFrame();
  716. }
  717. inline void
  718. InPlaceBorder::CalcClientRect(HWND hwnd, LPRECT lprc)
  719. {
  720. if(_fUIActive)
  721. InflateRect(lprc, -_cxFrame, -_cyFrame);
  722. }
  723. inline BOOL
  724. InPlaceBorder::GetUIActive(void)
  725. {
  726. return _fUIActive;
  727. }
  728. //+---------------------------------------------------------------------
  729. //
  730. // Helper functions for in-place activation
  731. //
  732. //----------------------------------------------------------------------
  733. HRESULT InsertServerMenus(HMENU hmenuShared, HMENU hmenuObject,
  734. LPOLEMENUGROUPWIDTHS lpmgw);
  735. void RemoveServerMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpmgw);
  736. //---------------------------------------------------------------
  737. // IStorage
  738. //---------------------------------------------------------------
  739. #define STGM_SHARE 0x000000F0
  740. //+---------------------------------------------------------------------
  741. //
  742. // Running Object Table helper functions
  743. //
  744. //----------------------------------------------------------------------
  745. void RegisterAsRunning(LPUNKNOWN lpUnk, LPMONIKER lpmkFull,
  746. DWORD FAR* lpdwRegister);
  747. void RevokeAsRunning(DWORD FAR* lpdwRegister);
  748. //+---------------------------------------------------------------------
  749. //
  750. // Standard implementations of common enumerators
  751. //
  752. //----------------------------------------------------------------------
  753. HRESULT CreateOLEVERBEnum(LPOLEVERB pVerbs, ULONG cVerbs,
  754. LPENUMOLEVERB FAR* ppenum);
  755. HRESULT CreateFORMATETCEnum(LPFORMATETC pFormats, ULONG cFormats,
  756. LPENUMFORMATETC FAR* ppenum);
  757. #if 0 // currently not used but useful in the future.
  758. // we ifdef it out so it doesn't take up space
  759. // in our servers.
  760. HRESULT CreateStaticEnum(REFIID riid, LPVOID pStart, ULONG cSize, ULONG cCount,
  761. LPVOID FAR* ppenum);
  762. #endif //0
  763. //+---------------------------------------------------------------------
  764. //
  765. // Standard IClassFactory implementation
  766. //
  767. //----------------------------------------------------------------------
  768. //+---------------------------------------------------------------
  769. //
  770. // Class: StdClassFactory
  771. //
  772. // Purpose: Standard implementation of a class factory object
  773. //
  774. // Notes: *
  775. //
  776. //---------------------------------------------------------------
  777. class StdClassFactory: public IClassFactory
  778. {
  779. public:
  780. StdClassFactory(void);
  781. DECLARE_IUNKNOWN_METHODS;
  782. STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter,
  783. REFIID iid,
  784. LPVOID FAR* ppv) PURE;
  785. STDMETHOD(LockServer) (BOOL fLock);
  786. BOOL CanUnload(void);
  787. private:
  788. ULONG _ulRefs;
  789. ULONG _ulLocks;
  790. };
  791. //+---------------------------------------------------------------------
  792. //
  793. // IStorage and IStream Helper functions
  794. //
  795. //----------------------------------------------------------------------
  796. #define STGM_DFRALL (STGM_READWRITE|STGM_TRANSACTED|STGM_SHARE_DENY_WRITE)
  797. #define STGM_DFALL (STGM_READWRITE | STGM_TRANSACTED | STGM_SHARE_EXCLUSIVE)
  798. #define STGM_SALL (STGM_READWRITE | STGM_SHARE_EXCLUSIVE)
  799. #define STGM_SRO (STGM_READ | STGM_SHARE_EXCLUSIVE)
  800. HRESULT GetMonikerDisplayName(LPMONIKER pmk, LPWSTR FAR* ppstr);
  801. HRESULT CreateStorageOnHGlobal(HGLOBAL hgbl, LPSTORAGE FAR* ppStg);
  802. LPSTREAM ConvertToMemoryStream(LPSTREAM pStrmFrom);
  803. //+---------------------------------------------------------------
  804. //
  805. // Function: StmReadString
  806. //
  807. // Synopsis: Reads a string from a stream
  808. //
  809. // Arguments: [pStrm] -- the stream to read from
  810. // [ppstr] -- where the string read is returned
  811. //
  812. // Returns: Success if the string was read successfully
  813. //
  814. // Notes: The string is allocated with the task allocator
  815. // and needs to be freed by the same.
  816. // This is an inline function.
  817. //
  818. //----------------------------------------------------------------
  819. inline HRESULT StmReadString(LPSTREAM pStrm, LPSTR FAR *ppstr)
  820. {
  821. HRESULT r;
  822. USHORT cb;
  823. LPSTR lpstr = NULL;
  824. if (OK(r = pStrm->Read(&cb, sizeof(cb), NULL)))
  825. {
  826. if (OK(r = TaskAllocMem(cb+1, (LPVOID FAR*)&lpstr)))
  827. {
  828. r = pStrm->Read(lpstr, cb, NULL);
  829. *(lpstr+cb) = '\0';
  830. }
  831. }
  832. *ppstr = lpstr;
  833. return r;
  834. }
  835. //+---------------------------------------------------------------
  836. //
  837. // Function: StmWriteString
  838. //
  839. // Synopsis: Writes a string to a stream
  840. //
  841. // Arguments: [pStrm] -- the stream to write to
  842. // [lpstr] -- the string to write
  843. //
  844. // Returns: Success iff the string was written successfully
  845. //
  846. // Notes: This is an inline function.
  847. //
  848. //----------------------------------------------------------------
  849. inline HRESULT StmWriteString(LPSTREAM pStrm, LPSTR lpstr)
  850. {
  851. HRESULT r;
  852. USHORT cb = strlen(lpstr);
  853. if (OK(r = pStrm->Write(&cb, sizeof(cb), NULL)))
  854. r = pStrm->Write(lpstr, cb, NULL);
  855. return r;
  856. }
  857. //+---------------------------------------------------------------------
  858. //
  859. // View advise holder
  860. //
  861. //----------------------------------------------------------------------
  862. //
  863. // forward declaration
  864. //
  865. class ViewAdviseHolder;
  866. typedef ViewAdviseHolder FAR* LPVIEWADVISEHOLDER;
  867. //+---------------------------------------------------------------
  868. //
  869. // Class: ViewAdviseHolder
  870. //
  871. // Purpose: Manages the view advises on behalf of a IViewObject object
  872. //
  873. // Notes: This is analogous to the standard DataAdviseHolder provided
  874. // by OLE. c.f. CreateViewAdviseHolder.
  875. //
  876. //---------------------------------------------------------------
  877. class ViewAdviseHolder: public IUnknown
  878. {
  879. friend HRESULT CreateViewAdviseHolder(LPVIEWADVISEHOLDER FAR*);
  880. public:
  881. //*** IUnknown methods ***/
  882. STDMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj);
  883. STDMETHOD_(ULONG,AddRef) (void);
  884. STDMETHOD_(ULONG,Release) (void);
  885. //*** ViewAdviseHolder methods
  886. STDMETHOD(SetAdvise) (DWORD aspects, DWORD advf, LPADVISESINK pAdvSink);
  887. STDMETHOD(GetAdvise) (DWORD FAR* pAspects, DWORD FAR* pAdvf,
  888. LPADVISESINK FAR* ppAdvSink);
  889. void SendOnViewChange(DWORD dwAspect);
  890. private:
  891. ViewAdviseHolder();
  892. ~ViewAdviseHolder();
  893. ULONG _refs;
  894. LPADVISESINK _pAdvSink; // THE view advise sink
  895. DWORD _dwAdviseAspects; // view aspects of interest to advise sink
  896. DWORD _dwAdviseFlags; // view advise flags
  897. };
  898. HRESULT CreateViewAdviseHolder(LPVIEWADVISEHOLDER FAR* ppViewHolder);
  899. #ifdef INC_STATUS_BAR
  900. //
  901. // forward declarations
  902. //
  903. extern "C" LRESULT CALLBACK
  904. StatusWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  905. class StatusBar;
  906. typedef StatusBar FAR* LPSTATUSBAR;
  907. //+-------------------------------------------------------------------
  908. //
  909. // Class: StatusBar
  910. //
  911. // Purpose: A status bar.
  912. //
  913. // Notes: Of the guidelines laid down by the UI people, the
  914. // current implementation violates the following::
  915. // - height of status bar should equal the height of
  916. // the window's title bar.
  917. //
  918. //--------------------------------------------------------------------
  919. class StatusBar
  920. {
  921. friend LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM);
  922. public:
  923. static BOOL ClassInit(HINSTANCE hinst); // registers window class
  924. StatusBar();
  925. HWND Init(HINSTANCE hinst, HWND hwndParent);
  926. ~StatusBar();
  927. void OnSize(LPRECT lprc);
  928. void DisplayMessage(LPCWSTR);
  929. WORD GetHeight(void);
  930. private:
  931. void OnPaint(HWND hwnd); // handles WM_PAINT message
  932. HWND _hwnd; // our status bar window
  933. HFONT _hfont; // font used to display messages.
  934. WCHAR _lpstrString[128]; // string currently being displayed.
  935. // various metrics:
  936. WORD _wHeight; // current height, once computed.
  937. WORD _wUnitBorder; // border, based on _wHeight;
  938. WORD _wSpace; // space between controls on bar.
  939. WORD _wAboveBelow; // space above and below
  940. };
  941. //+---------------------------------------------------------------
  942. //
  943. // Member: StatusBar::GetHeight, public
  944. //
  945. // Synopsis: Returns the height of the status bar in pixels
  946. //
  947. //----------------------------------------------------------------
  948. inline WORD StatusBar::GetHeight(void)
  949. {
  950. return _wHeight;
  951. }
  952. #endif // INC_STATUS_BAR
  953. //+------------------------------------------------------------------------
  954. //
  955. // Macro that calculates the number of elements in a statically-defined
  956. // array.
  957. //
  958. //-------------------------------------------------------------------------
  959. #define ARRAY_SIZE(_a) (sizeof(_a) / sizeof(_a[0]))
  960. //+------------------------------------------------------------------------
  961. //
  962. // Class: CEnumGeneric (enum)
  963. //
  964. // Purpose: Implements an OLE2 enumerator for arrays of data. The CAry
  965. // class uses this class for its enumerator.
  966. //
  967. // Interface: Next Returns the next element[s] in the array
  968. // Skip Skips the next element[s] in the array
  969. // Reset Restarts at the beginning of the array
  970. // Clone Creates a copy of theis enumerator
  971. //
  972. // Create Creates a new instance of this enumerator, given
  973. // an interface ID, element size, count, and pointer
  974. //
  975. // Members: _refs Ref count
  976. // _iid Interface implemented by this enumerator
  977. // _cb Size of each element
  978. // _c Number of elements
  979. // _i Current index in the array
  980. // _pv Pointer to array data
  981. //
  982. //-------------------------------------------------------------------------
  983. class CEnumGeneric : public IUnknown
  984. {
  985. public:
  986. // IUnknown methods
  987. STDMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj);
  988. STDMETHOD_(ULONG,AddRef) (THIS);
  989. STDMETHOD_(ULONG,Release) (THIS);
  990. // IEnum methods
  991. STDMETHOD(Next) (ULONG celt, void FAR* reelt, ULONG FAR* pceltFetched);
  992. STDMETHOD(Skip) (ULONG celt);
  993. STDMETHOD(Reset) ();
  994. STDMETHOD(Clone) (CEnumGeneric FAR* FAR* ppenm);
  995. // CEnumGeneric methods
  996. static CEnumGeneric FAR* Create(REFIID, int cb, int c, void FAR* pv, BOOL fAddRef);
  997. protected:
  998. CEnumGeneric( REFIID, int cb, int c, void FAR* pv, BOOL fAddRef );
  999. CEnumGeneric( CEnumGeneric * );
  1000. ULONG _refs;
  1001. IID _iid;
  1002. BOOL _fAddRef;
  1003. int _cb;
  1004. int _c;
  1005. int _i;
  1006. void FAR* _pv;
  1007. };
  1008. //+------------------------------------------------------------------------
  1009. //
  1010. // Class: CAry (ary)
  1011. //
  1012. // Purpose: Generic resizeable array class
  1013. //
  1014. // Interface: CAry, ~CAry
  1015. // EnsureSize Ensures that the array is at least a certain
  1016. // size, allocating more memory if necessary.
  1017. // Note that the array size is measured in elements,
  1018. // rather than in bytes.
  1019. // Size Returns the current size of the array.
  1020. // SetSize Sets the array size; EnsureSize must be called
  1021. // first to reserve space if the array is growing
  1022. //
  1023. // operator LPVOID Allow the CAry class to be cast to a (void *)
  1024. //
  1025. // Append Adds a new pointer to the end of the array,
  1026. // growing the array if necessary. Only works
  1027. // for arrays of pointers.
  1028. // AppendIndirect As Append, for non-pointer arrays
  1029. //
  1030. // Insert Inserts a new pointer at the given index in
  1031. // the array, growing the array if necessary. Any
  1032. // elements at or following the index are moved
  1033. // out of the way.
  1034. // InsertIndirect As Insert, for non-pointer arrays
  1035. //
  1036. // Delete Deletes an element of the array, moving any
  1037. // elements that follow it to fill
  1038. // DeleteMultiple Deletes a range of elements from the array,
  1039. // moving to fill
  1040. // BringToFront Moves an element of the array to index 0,
  1041. // shuffling elements to make room
  1042. // SendToBack Moves an element to the end of the array,
  1043. // shuffling elements to make room
  1044. //
  1045. // Find Returns the index at which a given pointer
  1046. // is found
  1047. // FindIndirect As Find, for non-pointer arrays
  1048. //
  1049. // EnumElements Create an enumerator which supports the given
  1050. // interface ID for the contents of the array
  1051. //
  1052. // Deref [prot] Returns a pointer to an element of the array;
  1053. // normally used by type-safe methods in derived
  1054. // classes
  1055. //
  1056. // Members: _c Current size of the array
  1057. // _cMac Current number of elements allocated
  1058. // _cb Size of each element
  1059. // _pv Buffer storing the elements
  1060. //
  1061. // Note: The CAry class only supports arrays of elements whose size is
  1062. // less than CARY_MAXELEMSIZE (currently 32).
  1063. //
  1064. //-------------------------------------------------------------------------
  1065. class CAry
  1066. {
  1067. public:
  1068. CAry(size_t cb);
  1069. ~CAry();
  1070. HRESULT EnsureSize(int c);
  1071. int Size(void)
  1072. { return _c; }
  1073. void SetSize(int c)
  1074. { _c = c; }
  1075. operator LPVOID(void)
  1076. { return _pv; }
  1077. HRESULT Append(void *);
  1078. HRESULT AppendIndirect(void *);
  1079. HRESULT Insert(int, void *);
  1080. HRESULT InsertIndirect(int, void *);
  1081. void Delete(int);
  1082. void DeleteAll(void);
  1083. void DeleteMultiple(int, int);
  1084. void BringToFront(int);
  1085. void SendToBack(int);
  1086. int Find(void *);
  1087. int FindIndirect(void **);
  1088. HRESULT EnumElements(REFIID iid, LPVOID * ppv, BOOL fAddRef);
  1089. protected:
  1090. int _c;
  1091. int _cMac;
  1092. size_t _cb;
  1093. void * _pv;
  1094. void * Deref(int i);
  1095. };
  1096. #define CARY_MAXELEMSIZE 32
  1097. //+------------------------------------------------------------------------
  1098. //
  1099. // Macro: DECLARE_ARY
  1100. //
  1101. // Purpose: Declares a type-safe class derived from CAry.
  1102. //
  1103. // Arguments: _Cls -- Name of new array class
  1104. // _Ty -- Type of array element (e.g. FOO)
  1105. // _pTy -- Type which is a pointer to _Ty (e.g. LPFOO)
  1106. //
  1107. // Interface: operator [] Provides a type-safe pointer to an element
  1108. // of the array
  1109. // operator LPFOO Allows the array to be cast to a type-safe
  1110. // pointer to its first element
  1111. //
  1112. //-------------------------------------------------------------------------
  1113. #define DECLARE_ARY(_Cls, _Ty, _pTy) \
  1114. class _Cls : public CAry { public: \
  1115. _Cls(void) : CAry(sizeof(_Ty)) { ; } \
  1116. _Ty& operator[] (int i) { return * (_pTy) Deref(i); } \
  1117. operator _pTy(void) { return (_pTy) _pv; } };
  1118. //****************************************************************************
  1119. //
  1120. // IconBar Class
  1121. //
  1122. //****************************************************************************
  1123. // WM_COMMAND notification codes
  1124. #define IBI_NEWSELECTION 1
  1125. #define IBI_STATUSAVAIL 2
  1126. #define IBP_LEFTBELOW 0
  1127. #define IBP_RIGHTABOVE 1
  1128. #define IBP_RIGHTBELOW 2
  1129. #define IBP_LEFTABOVE 3
  1130. extern "C" LRESULT CALLBACK IconBarWndProc(HWND,UINT,WPARAM,LPARAM);
  1131. class IconBar;
  1132. typedef IconBar FAR* LPICONBAR;
  1133. class IconBar
  1134. {
  1135. friend LRESULT CALLBACK IconBarWndProc(HWND,UINT,WPARAM,LPARAM);
  1136. public:
  1137. static LPICONBAR Create(HINSTANCE hinst, HWND hwndParent, HWND hwndNotify,
  1138. SHORT sIdChild);
  1139. ~IconBar(void);
  1140. HWND GetHwnd(void);
  1141. void Position(int sTop, int sLeft, int sWhere);
  1142. HRESULT AddCellsFromRegDB(LPWSTR pszFilter);
  1143. void AddCell(CLSID& clsid, HICON hIcon, LPWSTR szTitle);
  1144. void SetCellAspect( int cWide, int cHigh );
  1145. void SelectCell(int iCell, BOOL fStick);
  1146. int GetSelectedCell(void);
  1147. CLSID& GetSelectedClassId(void);
  1148. LPWSTR GetStatusMessage(void);
  1149. BOOL IsStuck(void);
  1150. private:
  1151. #define MAX_CELLS 24
  1152. #define MAX_ICON_TITLE 64
  1153. struct IconCell {
  1154. CLSID clsid;
  1155. HICON hIcon;
  1156. HBITMAP hBmp;
  1157. WCHAR achTitle[MAX_ICON_TITLE];
  1158. };
  1159. typedef IconCell FAR *LPICONCELL;
  1160. IconBar(HWND hwndParent, HWND hwndNotify, SHORT sIDChild);
  1161. int AddCell(LPICONCELL pCells, int i,
  1162. CLSID& clsid, HICON hIcon, LPWSTR szTitle);
  1163. void AddCache(void);
  1164. void Draw(HDC hdc, POINT pt, BOOL fDown, int iCell);
  1165. void ncCalcRect(HWND hwnd, LPRECT lprc);
  1166. void ncDrawFrame(HWND hwnd);
  1167. LONG ncHitTest(HWND hwnd, POINT pt);
  1168. LRESULT ncMsgFilter(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  1169. static ATOM InitClass(HINSTANCE hinst);
  1170. static BOOL _fInit;
  1171. static ATOM _atomClass;
  1172. static HBRUSH hbrActiveCaption;
  1173. static HBRUSH hbrInActiveCaption;
  1174. static HBRUSH hbrWindowFrame;
  1175. static HBRUSH hbrSysBox;
  1176. static WORD wCnt;
  1177. static COLORREF crLtGray;
  1178. static COLORREF crGray;
  1179. static COLORREF crDkGray;
  1180. static COLORREF crBlack;
  1181. //windows message handling
  1182. BOOL OnCreate(HWND hwnd, CREATESTRUCT FAR* lpCreateStruct);
  1183. void OnDestroy(HWND hwnd);
  1184. void OnPaint(HWND hwnd);
  1185. void OnGetMinMaxInfo(HWND hwnd, LPMINMAXINFO lpMinMaxInfo);
  1186. void OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags);
  1187. void OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags);
  1188. SHORT _dxMargin; // horizontal margin between tray border and icon
  1189. SHORT _dyMargin; // vertical margin between tray border and icon
  1190. SHORT _dxCell; // horizontal size of icon
  1191. SHORT _dyCell; // vertical size of icon
  1192. SHORT _cyCaption; // title bar height
  1193. SHORT _cxFrame; // thickness of nc frame
  1194. SHORT _cyFrame;
  1195. SHORT _cxSize; // size of sizing corner
  1196. SHORT _cySize;
  1197. BOOL _fFloating; // free-floating window?
  1198. HWND _hwnd; // the icon toolbar window
  1199. HWND _hwndNotify; // the window to notify via WM_COMMAND
  1200. SHORT _sIdChild; // child identifier for WM_COMMAND
  1201. int _numCells; // the number of icon "cells" that have been loaded
  1202. IconCell _cell[MAX_CELLS]; // the array of icon cells
  1203. static int _cUsed; // outstanding users of cached cells
  1204. static int _cCache; // total cached cells
  1205. static IconCell _cache[MAX_CELLS]; // a cache array of icon cells
  1206. int _cellsPerRow;
  1207. int _selectedCell;
  1208. int _iCellAtCursor;
  1209. BOOL _fStuck;
  1210. // other private helper members
  1211. void GetCellPoint(LPPOINT lppt, int i);
  1212. void GetCellRect(LPRECT lprc, int i);
  1213. void InvalidateCell(HWND hwnd, int i);
  1214. int CellIndexFromPoint(POINT pt);
  1215. };
  1216. inline void
  1217. IconBar::OnDestroy(HWND hwnd)
  1218. {
  1219. _hwnd = NULL;
  1220. }
  1221. inline BOOL
  1222. IconBar::OnCreate(HWND hwnd, CREATESTRUCT FAR* lpCreateStruct)
  1223. {
  1224. return TRUE;
  1225. }
  1226. inline BOOL
  1227. IconBar::IsStuck(void)
  1228. {
  1229. return _fStuck;
  1230. }
  1231. inline int
  1232. IconBar::GetSelectedCell(void)
  1233. {
  1234. return _selectedCell;
  1235. }
  1236. inline HWND
  1237. IconBar::GetHwnd(void)
  1238. {
  1239. return _hwnd;
  1240. }
  1241. //****************************************************************************
  1242. //
  1243. // Macros
  1244. //
  1245. //****************************************************************************
  1246. //+------------------------------------------------------------------------
  1247. //
  1248. // Macro: DECLARE_ARY
  1249. //
  1250. // Purpose: Declares a type-safe class derived from CAry.
  1251. //
  1252. // Arguments: _Cls -- Name of new array class
  1253. // _Ty -- Type of array element (e.g. FOO)
  1254. // _pTy -- Type which is a pointer to _Ty (e.g. LPFOO)
  1255. //
  1256. // Interface: operator [] Provides a type-safe pointer to an element
  1257. // of the array
  1258. // operator LPFOO Allows the array to be cast to a type-safe
  1259. // pointer to its first element
  1260. //
  1261. //-------------------------------------------------------------------------
  1262. #define DECLARE_ARY(_Cls, _Ty, _pTy) \
  1263. class _Cls : public CAry { public: \
  1264. _Cls(void) : CAry(sizeof(_Ty)) { ; } \
  1265. _Ty& operator[] (int i) { return * (_pTy) Deref(i); } \
  1266. operator _pTy(void) { return (_pTy) _pv; } };
  1267. //======================================================================
  1268. //
  1269. // The base class stuff...
  1270. //
  1271. //
  1272. // Classes: ClassDescriptor
  1273. // SrvrCtrl
  1274. // SrvrDV
  1275. // SrvrInPlace
  1276. //
  1277. //----------------------------------------------------------------------------
  1278. enum OLE_SERVER_STATE
  1279. {
  1280. OS_PASSIVE,
  1281. OS_LOADED, // handler but no server
  1282. OS_RUNNING, // server running, invisible
  1283. OS_INPLACE, // server running, inplace-active, no U.I.
  1284. OS_UIACTIVE, // server running, inplace-active, w/ U.I.
  1285. OS_OPEN // server running, open-edited
  1286. };
  1287. // forward declarations of classes
  1288. class ClassDescriptor;
  1289. typedef ClassDescriptor FAR* LPCLASSDESCRIPTOR;
  1290. class SrvrCtrl;
  1291. typedef SrvrCtrl FAR* LPSRVRCTRL;
  1292. class SrvrDV;
  1293. typedef SrvrDV FAR* LPSRVRDV;
  1294. class SrvrInPlace;
  1295. typedef SrvrInPlace FAR* LPSRVRINPLACE;
  1296. //+---------------------------------------------------------------
  1297. //
  1298. // Class: ClassDescriptor
  1299. //
  1300. // Purpose: Global, static information about a server class
  1301. //
  1302. // Notes: This allows the base classes to implement a lot of
  1303. // OLE functionality with requiring additional virtual
  1304. // method calls on the derived classes.
  1305. //
  1306. //---------------------------------------------------------------
  1307. class ClassDescriptor
  1308. {
  1309. public:
  1310. ClassDescriptor(void);
  1311. BOOL Init(HINSTANCE hinst, WORD wBaseID);
  1312. HMENU LoadMenu(void);
  1313. HINSTANCE _hinst; // instance handle of module serving this class
  1314. WORD _wBaseResID; // base resource identifier (see IDOFF_ )
  1315. CLSID _clsid; // class's unique identifier
  1316. HICON _hicon; // iconic representation of class
  1317. HACCEL _haccel; // accelerators for those menus
  1318. OLEMENUGROUPWIDTHS _mgw; // the number of Edit, Object, and Help menus
  1319. WCHAR _szUserClassType[4][64];// [0] unused
  1320. // [1] the string assigned to classid key in reg db.
  1321. // [2] reg db: \CLSID\<clsid>\AuxUserType\2
  1322. // [3] reg db: \CLSID\<clsid>\AuxUserType\3
  1323. WCHAR _szDocfileExt[8]; // extension for docfile files
  1324. DWORD _dwMiscStatus; // reg db: \CLSID\<clsid>\MiscStatus
  1325. //DERIVED: The derived class must supply these tables.
  1326. //REVIEW: These could be loaded from resources, too!
  1327. LPOLEVERB _pVerbTable; // pointer to list of verbs available
  1328. int _cVerbTable; // number of entries in the verb table
  1329. LPFORMATETC _pGetFmtTable; // format table for IDataObject::GetData[Here]
  1330. int _cGetFmtTable; // number of entries in the table
  1331. LPFORMATETC _pSetFmtTable; // format table for IDataObject::SetData
  1332. int _cSetFmtTable; // number of entries in the table
  1333. };
  1334. //+---------------------------------------------------------------
  1335. //
  1336. // Class: SrvrCtrl
  1337. //
  1338. // Purpose: Control subobject of OLE compound document server
  1339. //
  1340. // Notes: This class supports the IOleObject interface.
  1341. //
  1342. //---------------------------------------------------------------
  1343. class SrvrCtrl : public IOleObject
  1344. {
  1345. public:
  1346. // standard verb implementations
  1347. typedef HRESULT (*LPFNDOVERB) (LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  1348. static HRESULT DoShow(LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  1349. static HRESULT DoOpen(LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  1350. static HRESULT DoHide(LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  1351. static HRESULT DoUIActivate(LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  1352. static HRESULT DoInPlaceActivate(LPVOID, LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  1353. //DERIVED: IUnknown methods are left pure virtual and must be implemented
  1354. // by the derived class
  1355. // IOleObject interface methods
  1356. STDMETHOD(SetClientSite) (LPOLECLIENTSITE pClientSite);
  1357. STDMETHOD(GetClientSite) (LPOLECLIENTSITE FAR* ppClientSite);
  1358. STDMETHOD(SetHostNames) (LPCWSTR szContainerApp, LPCWSTR szContainerObj);
  1359. STDMETHOD(Close) (DWORD dwSaveOption);
  1360. STDMETHOD(SetMoniker) (DWORD dwWhichMoniker, LPMONIKER pmk);
  1361. STDMETHOD(GetMoniker) (DWORD dwAssign, DWORD dwWhichMoniker,
  1362. LPMONIKER FAR* ppmk);
  1363. STDMETHOD(InitFromData) (LPDATAOBJECT pDataObject,BOOL fCreation,
  1364. DWORD dwReserved);
  1365. STDMETHOD(GetClipboardData) (DWORD dwReserved, LPDATAOBJECT FAR* ppDataObject);
  1366. STDMETHOD(DoVerb) (LONG iVerb, LPMSG lpmsg, LPOLECLIENTSITE pActiveSite,
  1367. LONG lindex, HWND hwndParent, LPCRECT lprcPosRect);
  1368. STDMETHOD(EnumVerbs) (LPENUMOLEVERB FAR* ppenumOleVerb);
  1369. STDMETHOD(Update) (void);
  1370. STDMETHOD(IsUpToDate) (void);
  1371. STDMETHOD(GetUserClassID) (CLSID FAR* pClsid);
  1372. STDMETHOD(GetUserType) (DWORD dwFormOfType, LPWSTR FAR* pszUserType);
  1373. STDMETHOD(SetExtent) (DWORD dwDrawAspect, LPSIZEL lpsizel);
  1374. STDMETHOD(GetExtent) (DWORD dwDrawAspect, LPSIZEL lpsizel);
  1375. STDMETHOD(Advise)(IAdviseSink FAR* pAdvSink, DWORD FAR* pdwConnection);
  1376. STDMETHOD(Unadvise)(DWORD dwConnection);
  1377. STDMETHOD(EnumAdvise) (LPENUMSTATDATA FAR* ppenumAdvise);
  1378. STDMETHOD(GetMiscStatus) (DWORD dwAspect, DWORD FAR* pdwStatus);
  1379. STDMETHOD(SetColorScheme) (LPLOGPALETTE lpLogpal);
  1380. // pointers to our data/view and inplace subobjects
  1381. LPSRVRDV _pDV; // our persistent data/view subobject
  1382. LPSRVRINPLACE _pInPlace; // our inplace-active subobject
  1383. // pointers to those objects' private unknowns
  1384. LPUNKNOWN _pPrivUnkDV;
  1385. LPUNKNOWN _pPrivUnkIP;
  1386. // methods and members required by our data/view and inplace subobjects.
  1387. OLE_SERVER_STATE State(void);
  1388. void SetState(OLE_SERVER_STATE state)
  1389. {
  1390. _state = state;
  1391. };
  1392. HRESULT TransitionTo(OLE_SERVER_STATE state);
  1393. LPOLECLIENTSITE _pClientSite;
  1394. void OnSave(void);
  1395. void EnableIPB(BOOL fEnabled);
  1396. BOOL IsIPBEnabled(void);
  1397. virtual HRESULT Init(LPCLASSDESCRIPTOR pClass);
  1398. // IOleObject-related members
  1399. DWORD _dwRegROT; // our R.O.T. registration value
  1400. LPOLEADVISEHOLDER _pOleAdviseHolder;// for collection our advises
  1401. LPWSTR _lpstrCntrApp; // top-level container application
  1402. LPWSTR _lpstrCntrObj; // and object names
  1403. protected:
  1404. //
  1405. // DERIVED: Each of these correspond to a unique state transition.
  1406. // The derived class may want to override to do additional processing.
  1407. //
  1408. virtual HRESULT PassiveToLoaded();
  1409. virtual HRESULT LoadedToPassive();
  1410. virtual HRESULT LoadedToRunning();
  1411. virtual HRESULT RunningToLoaded();
  1412. virtual HRESULT RunningToInPlace();
  1413. virtual HRESULT InPlaceToRunning();
  1414. virtual HRESULT InPlaceToUIActive();
  1415. virtual HRESULT UIActiveToInPlace();
  1416. virtual HRESULT RunningToOpened();
  1417. virtual HRESULT OpenedToRunning();
  1418. // constructors, initializers, and destructors
  1419. SrvrCtrl(void);
  1420. virtual ~SrvrCtrl(void);
  1421. LPCLASSDESCRIPTOR _pClass; // global info about our OLE server
  1422. OLE_SERVER_STATE _state; // our current state
  1423. BOOL _fEnableIPB; // FALSE turns off built-in border
  1424. //DERIVED: The derived class must supply table of verb functions
  1425. // parallel to the table of verbs in the class descriptor
  1426. LPFNDOVERB FAR* _pVerbFuncs; // verb function table
  1427. };
  1428. //+---------------------------------------------------------------
  1429. //
  1430. // Member: SrvrCtrl::State, public
  1431. //
  1432. // Synopsis: Returns the current state of the object
  1433. //
  1434. // Notes: The valid object states are closed, loaded, inplace,
  1435. // U.I. active, and open. These states are defined
  1436. // by the OLE_SERVER_STATE enumeration.
  1437. //
  1438. //---------------------------------------------------------------
  1439. inline OLE_SERVER_STATE
  1440. SrvrCtrl::State(void)
  1441. {
  1442. return _state;
  1443. }
  1444. //+---------------------------------------------------------------
  1445. //
  1446. // Member: SrvrCtrl::EnableIPB, public
  1447. //
  1448. // Synopsis: Enables/Disables built in InPlace border
  1449. //
  1450. //---------------------------------------------------------------
  1451. inline void
  1452. SrvrCtrl::EnableIPB(BOOL fEnabled)
  1453. {
  1454. _fEnableIPB = fEnabled;
  1455. }
  1456. //+---------------------------------------------------------------
  1457. //
  1458. // Member: SrvrCtrl::IsIPBEnabled, public
  1459. //
  1460. // Synopsis: Answers whether built-in InPlace border is enabled
  1461. //
  1462. //---------------------------------------------------------------
  1463. inline BOOL
  1464. SrvrCtrl::IsIPBEnabled(void)
  1465. {
  1466. return _fEnableIPB;
  1467. }
  1468. //+---------------------------------------------------------------
  1469. //
  1470. // Class: SrvrDV
  1471. //
  1472. // Purpose: Data/View subobject of OLE compound document server
  1473. //
  1474. // Notes: This class supports the IDataObject and IViewObject interfaces.
  1475. // It also supports the IPersist-derived interfaces.
  1476. // Objects of this class can operate as part of a complete
  1477. // server aggregation or independently as a transfer data
  1478. // object.
  1479. //
  1480. //---------------------------------------------------------------
  1481. class SrvrDV: public IDataObject,
  1482. public IViewObject,
  1483. public IPersistStorage,
  1484. public IPersistStream,
  1485. public IPersistFile
  1486. {
  1487. public:
  1488. typedef HRESULT (*LPFNGETDATA) (LPSRVRDV, LPFORMATETC, LPSTGMEDIUM, BOOL);
  1489. typedef HRESULT (*LPFNSETDATA) (LPSRVRDV, LPFORMATETC, LPSTGMEDIUM);
  1490. // standard format Get/Set implementations
  1491. static HRESULT GetEMBEDDEDOBJECT(LPSRVRDV, LPFORMATETC, LPSTGMEDIUM, BOOL);
  1492. static HRESULT GetMETAFILEPICT(LPSRVRDV, LPFORMATETC, LPSTGMEDIUM, BOOL);
  1493. static HRESULT GetOBJECTDESCRIPTOR(LPSRVRDV, LPFORMATETC, LPSTGMEDIUM, BOOL);
  1494. static HRESULT GetLINKSOURCE(LPSRVRDV, LPFORMATETC, LPSTGMEDIUM, BOOL);
  1495. //
  1496. //DERIVED: IUnknown methods are left pure virtual and must be implemented
  1497. // by the derived class
  1498. //
  1499. // IDataObject interface methods
  1500. //
  1501. STDMETHOD(GetData) (LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium);
  1502. STDMETHOD(GetDataHere) (LPFORMATETC pformatetc, LPSTGMEDIUM pmedium);
  1503. STDMETHOD(QueryGetData) (LPFORMATETC pformatetc);
  1504. STDMETHOD(GetCanonicalFormatEtc) (LPFORMATETC pformatetc,
  1505. LPFORMATETC pformatetcOut);
  1506. STDMETHOD(SetData) (LPFORMATETC pformatetc, LPSTGMEDIUM pmedium,
  1507. BOOL fRelease);
  1508. STDMETHOD(EnumFormatEtc) (DWORD dwDirection, LPENUMFORMATETC FAR* ppenum);
  1509. STDMETHOD(DAdvise) (FORMATETC FAR* pFormatetc, DWORD advf,
  1510. LPADVISESINK pAdvSink, DWORD FAR* pdwConnection);
  1511. STDMETHOD(DUnadvise) (DWORD dwConnection);
  1512. STDMETHOD(EnumDAdvise) (LPENUMSTATDATA FAR* ppenumAdvise);
  1513. //
  1514. // IViewObject interface methods
  1515. //
  1516. STDMETHOD(Draw) (DWORD dwDrawAspect, LONG lindex,
  1517. void FAR* pvAspect, DVTARGETDEVICE FAR * ptd,
  1518. HDC hicTargetDev,
  1519. HDC hdcDraw,
  1520. LPCRECTL lprcBounds,
  1521. LPCRECTL lprcWBounds,
  1522. BOOL (CALLBACK * pfnContinue) (DWORD),
  1523. DWORD dwContinue);
  1524. STDMETHOD(GetColorSet) (DWORD dwDrawAspect, LONG lindex,
  1525. void FAR* pvAspect, DVTARGETDEVICE FAR * ptd,
  1526. HDC hicTargetDev,
  1527. LPLOGPALETTE FAR* ppColorSet);
  1528. STDMETHOD(Freeze)(DWORD dwDrawAspect, LONG lindex, void FAR* pvAspect,
  1529. DWORD FAR* pdwFreeze);
  1530. STDMETHOD(Unfreeze) (DWORD dwFreeze);
  1531. STDMETHOD(SetAdvise) (DWORD aspects, DWORD advf, LPADVISESINK pAdvSink);
  1532. STDMETHOD(GetAdvise) (DWORD FAR* pAspects, DWORD FAR* pAdvf,
  1533. LPADVISESINK FAR* ppAdvSink);
  1534. //
  1535. // IPersist interface methods
  1536. //
  1537. STDMETHOD(GetClassID) (LPCLSID lpClassID);
  1538. STDMETHOD(IsDirty) (void);
  1539. //
  1540. // IPersistStream interface methods
  1541. //
  1542. STDMETHOD(Load) (LPSTREAM pStm);
  1543. STDMETHOD(Save) (LPSTREAM pStm, BOOL fClearDirty);
  1544. STDMETHOD(GetSizeMax) (ULARGE_INTEGER FAR * pcbSize);
  1545. //
  1546. // IPersistStorage interface methods
  1547. //
  1548. STDMETHOD(InitNew) (LPSTORAGE pStg);
  1549. STDMETHOD(Load) (LPSTORAGE pStg);
  1550. STDMETHOD(Save) (LPSTORAGE pStgSave, BOOL fSameAsLoad);
  1551. STDMETHOD(SaveCompleted) (LPSTORAGE pStgNew);
  1552. STDMETHOD(HandsOffStorage) (void);
  1553. //
  1554. // IPersistFile interface methods
  1555. //
  1556. STDMETHOD(Load) (LPCOLESTR lpszFileName, DWORD grfMode);
  1557. STDMETHOD(Save) (LPCOLESTR lpszFileName, BOOL fRemember);
  1558. STDMETHOD(SaveCompleted) (LPCOLESTR lpszFileName);
  1559. STDMETHOD(GetCurFile) (LPOLESTR FAR * lplpszFileName);
  1560. //
  1561. // DERIVED: methods required by the control
  1562. //
  1563. virtual HRESULT GetClipboardCopy(LPSRVRDV FAR* ppDV) = 0;
  1564. virtual HRESULT GetExtent(DWORD dwAspect, LPSIZEL lpsizel);
  1565. virtual HRESULT SetExtent(DWORD dwAspect, SIZEL& sizel);
  1566. virtual void SetMoniker(LPMONIKER pmk);
  1567. HRESULT GetMoniker(DWORD dwAssign, LPMONIKER FAR* ppmk);
  1568. LPWSTR GetMonikerDisplayName(DWORD dwAssign = OLEGETMONIKER_ONLYIFTHERE);
  1569. //
  1570. //DERIVED: The derived class should call this base class method whenever
  1571. // the data changes. This launches all appropriate advises.
  1572. //
  1573. void OnDataChange(DWORD dwAdvf = 0);
  1574. //
  1575. //DERIVED: The derived class should override these methods to perform
  1576. // rendering of its native data. These are used in the implementation of
  1577. // the IViewObject interface
  1578. //
  1579. virtual HRESULT RenderContent(DWORD dwDrawAspect,
  1580. LONG lindex,
  1581. void FAR* pvAspect,
  1582. DVTARGETDEVICE FAR * ptd,
  1583. HDC hicTargetDev,
  1584. HDC hdcDraw,
  1585. LPCRECTL lprectl,
  1586. LPCRECTL lprcWBounds,
  1587. BOOL (CALLBACK * pfnContinue) (DWORD),
  1588. DWORD dwContinue);
  1589. virtual HRESULT RenderPrint(DWORD dwDrawAspect,
  1590. LONG lindex,
  1591. void FAR* pvAspect,
  1592. DVTARGETDEVICE FAR * ptd,
  1593. HDC hicTargetDev,
  1594. HDC hdcDraw,
  1595. LPCRECTL lprectl,
  1596. LPCRECTL lprcWBounds,
  1597. BOOL (CALLBACK * pfnContinue) (DWORD),
  1598. DWORD dwContinue);
  1599. virtual HRESULT RenderThumbnail(DWORD dwDrawAspect,
  1600. LONG lindex,
  1601. void FAR* pvAspect,
  1602. DVTARGETDEVICE FAR * ptd,
  1603. HDC hicTargetDev,
  1604. HDC hdcDraw,
  1605. LPCRECTL lprectl,
  1606. LPCRECTL lprcWBounds,
  1607. BOOL (CALLBACK * pfnContinue) (DWORD),
  1608. DWORD dwContinue);
  1609. BOOL IsInNoScrible(void);
  1610. virtual HRESULT Init(LPCLASSDESCRIPTOR pClass, LPSRVRCTRL pCtrl);
  1611. virtual HRESULT Init(LPCLASSDESCRIPTOR pClass, LPSRVRDV pDV);
  1612. protected:
  1613. //
  1614. //DERIVED: The derived class should override these methods to perform
  1615. // persistent serialization and deserialization. These are used in the
  1616. // implementation of IPersistStream/Storage/File
  1617. //
  1618. virtual HRESULT LoadFromStream(LPSTREAM pStrm);
  1619. virtual HRESULT SaveToStream(LPSTREAM pStrm);
  1620. virtual DWORD GetStreamSizeMax(void);
  1621. virtual HRESULT LoadFromStorage(LPSTORAGE pStg);
  1622. virtual HRESULT SaveToStorage(LPSTORAGE pStg, BOOL fSameAsLoad);
  1623. //
  1624. // constructors, initializers, and destructors
  1625. //
  1626. SrvrDV(void);
  1627. virtual ~SrvrDV(void);
  1628. LPCLASSDESCRIPTOR _pClass; // global info about our OLE server
  1629. LPSRVRCTRL _pCtrl; // control of server aggregate or
  1630. // NULL if transfer object
  1631. //
  1632. // IDataObject-related members
  1633. //
  1634. LPMONIKER _pmk; // moniker used for LINKSOURCE
  1635. LPWSTR _lpstrDisplayName; // cached display name of moniker
  1636. SIZEL _sizel; // used for OBJECTDESCRIPTOR and Extent
  1637. LPDATAADVISEHOLDER _pDataAdviseHolder;
  1638. //
  1639. //DERIVED: The derived class must supply table of Get functions
  1640. // and a table of Set functions parallel to the FORMATETC tables
  1641. // in the class descriptor.
  1642. //
  1643. LPFNGETDATA FAR* _pGetFuncs; // GetData(Here) function table
  1644. LPFNSETDATA FAR* _pSetFuncs; // SetData function table
  1645. LPVIEWADVISEHOLDER _pViewAdviseHolder;
  1646. unsigned _fFrozen: 1; // blocked from updating
  1647. unsigned _fDirty: 1; // TRUE iff persistent data has changed
  1648. unsigned _fNoScribble: 1; // between save and save completed
  1649. // IPersistStorage-related members
  1650. LPSTORAGE _pStg; // our home IStorage instance
  1651. };
  1652. //+---------------------------------------------------------------
  1653. //
  1654. // Member: SrvrDV::IsInNoScrible, public
  1655. //
  1656. // Synopsis: Answers wether we are currently in no-scribble mode
  1657. //
  1658. //---------------------------------------------------------------
  1659. inline BOOL
  1660. SrvrDV::IsInNoScrible(void)
  1661. {
  1662. return _fNoScribble;
  1663. }
  1664. //+---------------------------------------------------------------
  1665. //
  1666. // Class: SrvrInPlace
  1667. //
  1668. // Purpose: Inplace subobject of OLE compound document server
  1669. //
  1670. // Notes: This class supports the IOleInPlaceObject and
  1671. // IOleInPlaceActiveObject interfaces.
  1672. //
  1673. //---------------------------------------------------------------
  1674. class SrvrInPlace: public IOleInPlaceObject,
  1675. public IOleInPlaceActiveObject
  1676. {
  1677. public:
  1678. //DERIVED: IUnknown methods are left pure virtual and must be implemented
  1679. // by the derived class
  1680. // IOleWindow interface methods
  1681. STDMETHOD(GetWindow) (HWND FAR* lphwnd);
  1682. STDMETHOD(ContextSensitiveHelp) (BOOL fEnterMode);
  1683. // IOleInPlaceObject interface methods
  1684. STDMETHOD(InPlaceDeactivate) (void);
  1685. STDMETHOD(UIDeactivate) (void);
  1686. STDMETHOD(SetObjectRects) (LPCRECT lprcPosRect, LPCRECT lprcClipRect);
  1687. STDMETHOD(ReactivateAndUndo) (void);
  1688. // IOleInPlaceActiveObject methods
  1689. STDMETHOD(TranslateAccelerator) (LPMSG lpmsg);
  1690. STDMETHOD(OnFrameWindowActivate) (BOOL fActivate);
  1691. STDMETHOD(OnDocWindowActivate) (BOOL fActivate);
  1692. STDMETHOD(ResizeBorder) (LPCRECT lprectBorder,
  1693. LPOLEINPLACEUIWINDOW lpUIWindow,
  1694. BOOL fFrameWindow);
  1695. STDMETHOD(EnableModeless) (BOOL fEnable);
  1696. // methods and members required by the other subobjects.
  1697. HWND WindowHandle(void);
  1698. void SetChildActivating(BOOL fGoingActive);
  1699. BOOL GetChildActivating(void);
  1700. BOOL IsDeactivating(void);
  1701. void ReflectState(BOOL fUIActive);
  1702. LPOLEINPLACEFRAME _pFrame; // our in-place active frame
  1703. LPOLEINPLACEUIWINDOW _pDoc; // our in-place active document
  1704. //DERIVED: These methods are called by the control to effect a
  1705. // state transition. The derived class can override these methods if
  1706. // it requires additional processing.
  1707. virtual HRESULT ActivateInPlace(IOleClientSite *pClientSite);
  1708. virtual HRESULT DeactivateInPlace(void);
  1709. virtual HRESULT ActivateUI(void);
  1710. virtual HRESULT DeactivateUI(void);
  1711. //DERIVED: These methods are related to U.I. activation. The derived
  1712. // class should override these to perform additional processing for
  1713. // any frame, document, or floating toolbars or palettes.
  1714. virtual void InstallUI(void);
  1715. virtual void RemoveUI(void);
  1716. LPOLEINPLACESITE _pInPlaceSite; // our in-place client site
  1717. virtual HRESULT Init(LPCLASSDESCRIPTOR pClass, LPSRVRCTRL pCtrl);
  1718. protected:
  1719. //DERIVED: More U.I. activation-related methods.
  1720. virtual void CreateUI(void);
  1721. virtual void DestroyUI(void);
  1722. virtual void InstallFrameUI(void);
  1723. virtual void RemoveFrameUI(void);
  1724. virtual void InstallDocUI(void);
  1725. virtual void RemoveDocUI(void);
  1726. virtual void ClearSelection(void);
  1727. virtual void SetFocus(HWND hwnd);
  1728. //DERIVED: The derived class must override this function to
  1729. // attach the servers in-place active window.
  1730. virtual HWND AttachWin(HWND hwndParent) = 0;
  1731. virtual void DetachWin(void);
  1732. SrvrInPlace(void);
  1733. virtual ~SrvrInPlace(void);
  1734. LPCLASSDESCRIPTOR _pClass; // global info about our class
  1735. LPSRVRCTRL _pCtrl; // the control we are part of.
  1736. // IOleInPlaceObject-related members
  1737. unsigned _fUIDown: 1; // menu/tools integrated with container?
  1738. unsigned _fChildActivating: 1; // site going UIActive?
  1739. unsigned _fDeactivating: 1; // being deactivated from the outside?
  1740. unsigned _fCSHelpMode: 1; // in context-sensitive help state?
  1741. OLEINPLACEFRAMEINFO _frameInfo; // accelerator information from our container
  1742. InPlaceBorder _IPB; // our In-Place border when UIActive
  1743. RECT _rcFrame; // our frame rect
  1744. HWND _hwnd; // our InPlace window
  1745. HMENU _hmenu;
  1746. HOLEMENU _hOleMenu; // menu registered w/ OLE
  1747. HMENU _hmenuShared; // the shared menu when we are UI active
  1748. OLEMENUGROUPWIDTHS _mgw; // menu interleaving information
  1749. BOOL _fClientResize; // TRUE during calls to SetObjectRects
  1750. };
  1751. //+---------------------------------------------------------------
  1752. //
  1753. // Member: SrvrInPlace::IsDeactivating, public
  1754. //
  1755. // Synopsis: Gets value of a flag indicating deactivation
  1756. // (from the outside) in progress
  1757. //
  1758. //---------------------------------------------------------------
  1759. inline BOOL
  1760. SrvrInPlace::IsDeactivating(void)
  1761. {
  1762. return _fDeactivating;
  1763. }
  1764. //+---------------------------------------------------------------
  1765. //
  1766. // Member: SrvrInPlace::GetChildActivating, public
  1767. //
  1768. // Synopsis: Gets value of a flag indicating that a child is
  1769. // activating to prevent menu flashing
  1770. //
  1771. //---------------------------------------------------------------
  1772. inline BOOL
  1773. SrvrInPlace::GetChildActivating(void)
  1774. {
  1775. return _fChildActivating;
  1776. }
  1777. //+---------------------------------------------------------------
  1778. //
  1779. // Member: SrvrInPlace::SetChildActivating, public
  1780. //
  1781. // Synopsis: Sets or clears a flag indicating that a child is
  1782. // activating to prevent menu flashing
  1783. //
  1784. //---------------------------------------------------------------
  1785. inline void
  1786. SrvrInPlace::SetChildActivating(BOOL fGoingActive)
  1787. {
  1788. _fChildActivating = fGoingActive;
  1789. }
  1790. //+---------------------------------------------------------------
  1791. //
  1792. // Member: SrvrInPlace::WindowHandle, public
  1793. //
  1794. // Synopsis: Returns object window handle
  1795. //
  1796. //---------------------------------------------------------------
  1797. inline HWND
  1798. SrvrInPlace::WindowHandle(void)
  1799. {
  1800. return _hwnd;
  1801. }
  1802. //+---------------------------------------------------------------
  1803. //
  1804. // Member: SrvrInPlace::ReflectState, public
  1805. //
  1806. // Synopsis: TBD
  1807. //
  1808. //---------------------------------------------------------------
  1809. inline void
  1810. SrvrInPlace::ReflectState(BOOL fActive)
  1811. {
  1812. if(_pCtrl->IsIPBEnabled())
  1813. {
  1814. _IPB.SetUIActive(fActive);
  1815. }
  1816. }
  1817. #endif // !RC_INVOKED
  1818. #endif //_O2BASE_HXX_
  1819.