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.

631 lines
18 KiB

  1. //+-------------------------------------------------------------------
  2. // File: ioleobj.cxx
  3. //
  4. // Contents: IOleObject methods of COleObject class.
  5. //
  6. // Classes: COleObject - IOleObject implementation
  7. //
  8. // History: 7-Dec-92 DeanE Created
  9. //---------------------------------------------------------------------
  10. #pragma optimize("",off)
  11. #include <pch.cxx>
  12. #pragma hdrstop
  13. #include <embed.hxx>
  14. #include <oleobj.hxx>
  15. //+-------------------------------------------------------------------
  16. // Member: COleObject::COleObject()
  17. //
  18. // Synopsis: The constructor for COleObject.
  19. //
  20. // Arguments: None
  21. //
  22. // History: 7-Dec-92 DeanE Created
  23. //--------------------------------------------------------------------
  24. COleObject::COleObject(CTestEmbed *pteObject)
  25. {
  26. _cRef = 1;
  27. _pOAHolder = NULL;
  28. _pocs = NULL;
  29. _pteObject = pteObject;
  30. _pmkContainer = NULL;
  31. }
  32. //+-------------------------------------------------------------------
  33. // Member: COleObject::~COleObject()
  34. //
  35. // Synopsis: The destructor for COleObject.
  36. //
  37. // History: 7-Dec-92 DeanE Created
  38. //--------------------------------------------------------------------
  39. COleObject::~COleObject()
  40. {
  41. // _cRef should be 1
  42. if (1 != _cRef)
  43. {
  44. // BUGBUG - Log error - someone hasn't released
  45. }
  46. if (_pocs != NULL)
  47. {
  48. _pocs->Release();
  49. }
  50. if (_pmkContainer != NULL)
  51. {
  52. _pmkContainer->Release();
  53. }
  54. }
  55. //+-------------------------------------------------------------------
  56. // Method: COleObject::QueryInterface
  57. //
  58. // Synopsis: Forward this to the object we're associated with
  59. //
  60. // Parameters: [iid] - Interface ID to return.
  61. // [ppv] - Pointer to pointer to object.
  62. //
  63. // Returns: S_OK if iid is supported, or E_NOINTERFACE if not.
  64. //
  65. // History: 7-Dec-92 DeanE Created
  66. //--------------------------------------------------------------------
  67. STDMETHODIMP COleObject::QueryInterface(REFIID iid, void FAR * FAR *ppv)
  68. {
  69. return(_pteObject->QueryInterface(iid, ppv));
  70. }
  71. //+-------------------------------------------------------------------
  72. // Method: COleObject::AddRef
  73. //
  74. // Synopsis: Forward this to the object we're associated with
  75. //
  76. // Returns: New reference count.
  77. //
  78. // History: 7-Dec-92 DeanE Created
  79. //--------------------------------------------------------------------
  80. STDMETHODIMP_(ULONG) COleObject::AddRef(void)
  81. {
  82. ++_cRef;
  83. return(_pteObject->AddRef());
  84. }
  85. //+-------------------------------------------------------------------
  86. // Method: COleObject::Release
  87. //
  88. // Synopsis: Forward this to the object we're associated with
  89. //
  90. // Returns: New reference count.
  91. //
  92. // History: 7-Dec-92 DeanE Created
  93. //--------------------------------------------------------------------
  94. STDMETHODIMP_(ULONG) COleObject::Release(void)
  95. {
  96. --_cRef;
  97. return(_pteObject->Release());
  98. }
  99. //+-------------------------------------------------------------------
  100. // Method: COleObject::SetClientSite
  101. //
  102. // Synopsis: Save the IOleClientSite pointer passed - it's this
  103. // object's client site object.
  104. //
  105. // Parameters: [pClientSite] - Pointer to the new client site object.
  106. //
  107. // Returns: S_OK
  108. //
  109. // History: 7-Dec-92 DeanE Created
  110. //--------------------------------------------------------------------
  111. STDMETHODIMP COleObject::SetClientSite(LPOLECLIENTSITE pClientSite)
  112. {
  113. if (_pocs != NULL)
  114. {
  115. _pocs->Release();
  116. }
  117. _pocs = pClientSite;
  118. if (pClientSite)
  119. {
  120. _pocs->AddRef();
  121. }
  122. return(S_OK);
  123. }
  124. //+-------------------------------------------------------------------
  125. // Method: COleObject::GetClientSite
  126. //
  127. // Synopsis: Return this objects current client site - NULL indicates
  128. // it hasn't been set yet.
  129. //
  130. // Parameters: [ppClientSite] - Save current client site pointer here.
  131. //
  132. // Returns: S_OK
  133. //
  134. // History: 7-Dec-92 DeanE Created
  135. //--------------------------------------------------------------------
  136. STDMETHODIMP COleObject::GetClientSite(LPOLECLIENTSITE FAR *ppClientSite)
  137. {
  138. *ppClientSite = _pocs;
  139. _pocs->AddRef();
  140. return(S_OK);
  141. }
  142. //+-------------------------------------------------------------------
  143. // Method: COleObject::SetHostNames
  144. //
  145. // Synopsis: See spec 2.00.09 p99. Returns names the caller can use
  146. // to display our object name (in window titles and such).
  147. //
  148. // Parameters: [szContainerApp] - Name of container application.
  149. // [szContainerObj] - Name of this object.
  150. //
  151. // Returns: S_OK
  152. //
  153. // History: 7-Dec-92 DeanE Created
  154. //--------------------------------------------------------------------
  155. STDMETHODIMP COleObject::SetHostNames(
  156. LPCOLESTR szContainerApp,
  157. LPCOLESTR szContainerObj)
  158. {
  159. szContainerApp = OLESTR("Test Server");
  160. szContainerObj = OLESTR("Test Server:Test Object");
  161. return(S_OK);
  162. }
  163. //+-------------------------------------------------------------------
  164. // Method: COleObject::Close
  165. //
  166. // Synopsis: See spec 2.00.09 p104. Short story is: if fMerelyHide,
  167. // turn off the UI of this object, else return to the
  168. // "loaded" state, which for us means to shut down (since we
  169. // don't do any caching).
  170. //
  171. // Parameters: [dwSaveOption] - ???
  172. //
  173. // Returns: S_OK
  174. //
  175. // History: 7-Dec-92 DeanE Created
  176. //
  177. // Notes: BUGBUG - what if we have multiple instances? Do we
  178. // return the server app to the loaded state or do we
  179. // return this object to the loaded state?
  180. //--------------------------------------------------------------------
  181. STDMETHODIMP COleObject::Close(DWORD dwSaveOption)
  182. {
  183. // BUGBUG - NYI
  184. return(S_OK);
  185. }
  186. //+-------------------------------------------------------------------
  187. // Method: COleObject::SetMoniker
  188. //
  189. // Synopsis: See spec 2.00.09 p99. The moniker for this object
  190. // (or it's container) has been changed to that passed
  191. // in. Take appropriate actions (de-register old object
  192. // and register new, inform contained objects, etc).
  193. //
  194. // Parameters: [dwWhichMoniker] - Moniker type being sent.
  195. // [pmk] - The new moniker.
  196. //
  197. // Returns: S_OK
  198. //
  199. // History: 7-Dec-92 DeanE Created
  200. //--------------------------------------------------------------------
  201. STDMETHODIMP COleObject::SetMoniker(DWORD dwWhichMoniker, LPMONIKER pmk)
  202. {
  203. if (_pmkContainer)
  204. {
  205. _pmkContainer->Release();
  206. }
  207. _pmkContainer = pmk;
  208. pmk->AddRef();
  209. // Set moniker in container
  210. IOleObject *pobj;
  211. HRESULT hresult = _pocs->QueryInterface(IID_IOleObject, (void **) &pobj);
  212. pobj->SetMoniker(dwWhichMoniker, pmk);
  213. pobj->Release();
  214. return S_OK;
  215. }
  216. //+-------------------------------------------------------------------
  217. // Method: COleObject::GetMoniker
  218. //
  219. // Synopsis: See spec 2.00.09 p100. Return either this objects
  220. // container moniker, this objects relative moniker, or
  221. // this objects full moniker.
  222. //
  223. // Parameters: [dwAssign] - Condition to get moniker.
  224. // [dwWhichMoniker] - Kind of moniker being requested.
  225. // [ppmk] - Return moniker here.
  226. //
  227. // Returns: S_OK
  228. //
  229. // History: 7-Dec-92 DeanE Created
  230. //--------------------------------------------------------------------
  231. STDMETHODIMP COleObject::GetMoniker(
  232. DWORD dwAssign,
  233. DWORD dwWhichMoniker,
  234. LPMONIKER FAR *ppmk)
  235. {
  236. *ppmk = _pmkContainer;
  237. _pmkContainer->AddRef();
  238. return S_OK;
  239. }
  240. //+-------------------------------------------------------------------
  241. // Method: COleObject::InitFromData
  242. //
  243. // Synopsis: See spec 2.00.09 p100. Initialize this object from
  244. // the format passed in.
  245. //
  246. // Parameters: [pDataObject] - IDataObject providing data.
  247. // [fCreation] - TRUE if this is the initial creation.
  248. // [dwReserved] - Ignored.
  249. //
  250. // Returns: S_OK if we attempt to initialize, S_FALSE if we don't
  251. // want to.
  252. //
  253. // History: 7-Dec-92 DeanE Created
  254. //--------------------------------------------------------------------
  255. STDMETHODIMP COleObject::InitFromData(
  256. LPDATAOBJECT pDataObject,
  257. BOOL fCreation,
  258. DWORD dwReserved)
  259. {
  260. // BUGBUG - NYI
  261. return(S_FALSE);
  262. }
  263. //+-------------------------------------------------------------------
  264. // Method: COleObject::GetClipboardData
  265. //
  266. // Synopsis: See spec 2.00.09 p101. Return clipboard object that would
  267. // be created if Edit/Copy were done to this item.
  268. //
  269. // Parameters: [dwReserved] - Ignored.
  270. // [ppDataObject] - IDataObject return locale.
  271. //
  272. // Returns: S_OK or ???
  273. //
  274. // History: 7-Dec-92 DeanE Created
  275. //--------------------------------------------------------------------
  276. STDMETHODIMP COleObject::GetClipboardData(
  277. DWORD dwReserved,
  278. LPDATAOBJECT FAR *ppDataObject)
  279. {
  280. // BUGBUG - NYI
  281. *ppDataObject = NULL;
  282. return(S_OK);
  283. }
  284. //+-------------------------------------------------------------------
  285. // Method: COleObject::DoVerb
  286. //
  287. // Synopsis: See spec 2.00.09 p101. Execute the verb passed in.
  288. //
  289. // Parameters: [iVerb] - Verb being requested.
  290. // [pMsg] - Message that triggered the request.
  291. // [pActiveSite] - IOleClientSite for this object.
  292. // [lReserved] - Ignored.
  293. //
  294. // Returns: S_OK, or other ones specified but not defined yet...
  295. //
  296. // History: 7-Dec-92 DeanE Created
  297. //--------------------------------------------------------------------
  298. STDMETHODIMP COleObject::DoVerb(
  299. LONG iVerb,
  300. LPMSG pMsg,
  301. LPOLECLIENTSITE pActiveSite,
  302. LONG lReserved,
  303. HWND hwndParent,
  304. LPCRECT lprcPosRect)
  305. {
  306. // HWND hwndObj;
  307. if (OLEIVERB_SHOW == iVerb)
  308. {
  309. // BUGBUG - NYI
  310. // Display the object (we're not in-place yet)
  311. // PostMessage(g_hwndMain, WM_REPORT, MB_SHOWVERB, 0);
  312. // PostMessage(0xFFFF, WM_REPORT, MB_SHOWVERB, 0);
  313. // MessageBox(g_hwndMain, L"Received OLEIVERB_SHOW", L"OLE Server", MB_ICONINFORMATION | MB_OK);
  314. // Get hwndObj
  315. //_pteObject->GetWindow(&hwndObj);
  316. //MessageBox(hwndObj, L"Received OLEIVERB_SHOW", L"OLE Server", MB_ICONINFORMATION | MB_OK);
  317. }
  318. else
  319. {
  320. // Return alternate error code?
  321. }
  322. return(S_OK);
  323. }
  324. //+-------------------------------------------------------------------
  325. // Method: COleObject::EnumVerbs
  326. //
  327. // Synopsis: See spec 2.00.09 p103. Enumerate all the verbs available
  328. // on this object in increasing numerical order.
  329. //
  330. // Parameters: [ppenmOleVerb] - Enumeration object return locale.
  331. //
  332. // Returns: S_OK or ???
  333. //
  334. // History: 7-Dec-92 DeanE Created
  335. //--------------------------------------------------------------------
  336. STDMETHODIMP COleObject::EnumVerbs(IEnumOLEVERB FAR* FAR *ppenmOleVerb)
  337. {
  338. // BUGBUG - NYI
  339. *ppenmOleVerb = NULL;
  340. return(S_OK);
  341. }
  342. //+-------------------------------------------------------------------
  343. // Method: COleObject::Update
  344. //
  345. // Synopsis: See spec 2.00.09 p105. Ensure any data or view caches
  346. // maintained inside the object are up to date.
  347. //
  348. // Parameters: None
  349. //
  350. // Returns: S_OK
  351. //
  352. // History: 7-Dec-92 DeanE Created
  353. //--------------------------------------------------------------------
  354. STDMETHODIMP COleObject::Update()
  355. {
  356. // We don't use any caches, so we don't have to do anything
  357. return(S_OK);
  358. }
  359. //+-------------------------------------------------------------------
  360. // Method: COleObject::IsUpToDate
  361. //
  362. // Synopsis: See spec 2.00.09 p105. Check to see if this object is
  363. // up to date - including embedded children, etc.
  364. //
  365. // Parameters: None
  366. //
  367. // Returns: S_OK, S_FALSE, or ???
  368. //
  369. // History: 7-Dec-92 DeanE Created
  370. //--------------------------------------------------------------------
  371. STDMETHODIMP COleObject::IsUpToDate()
  372. {
  373. // We should always be up to date as we don't have any caches
  374. // or children or links
  375. return(S_OK);
  376. }
  377. //+-------------------------------------------------------------------
  378. // Method: COleObject::GetUserClassID
  379. //
  380. // Synopsis: I have little idea what this does. It's not in the
  381. // spec 2.00.09.
  382. //
  383. // Parameters: [dwFormOfType] -
  384. // [pszUserType] -
  385. //
  386. // Returns: S_OK?
  387. //
  388. // History: 16-Dec-92 DeanE Created
  389. //--------------------------------------------------------------------
  390. STDMETHODIMP COleObject::GetUserClassID(
  391. CLSID FAR *pClsid)
  392. {
  393. // BUGBUG - NYI
  394. return(E_FAIL);
  395. }
  396. //+-------------------------------------------------------------------
  397. // Method: COleObject::GetUserType
  398. //
  399. // Synopsis: I have little idea what this does. It's not in the
  400. // spec 2.00.09.
  401. //
  402. // Parameters: [dwFormOfType] -
  403. // [pszUserType] -
  404. //
  405. // Returns: S_OK?
  406. //
  407. // History: 16-Dec-92 DeanE Created
  408. //--------------------------------------------------------------------
  409. STDMETHODIMP COleObject::GetUserType(
  410. DWORD dwFormOfType,
  411. LPOLESTR FAR *pszUserType)
  412. {
  413. // BUGBUG - NYI
  414. return(E_FAIL);
  415. }
  416. //+-------------------------------------------------------------------
  417. // Method: COleObject::SetExtent
  418. //
  419. // Synopsis: See spec 2.00.09 p106. Set the rectangular extent of
  420. // this object. Container will call us with the size
  421. // it will give us; we must fit accordingly.
  422. //
  423. // Parameters: [dwDrawAspect] - DVASPECT specified for this object.
  424. // [lpsizel] - Extent structure.
  425. //
  426. // Returns: S_OK
  427. //
  428. // History: 7-Dec-92 DeanE Created
  429. //--------------------------------------------------------------------
  430. STDMETHODIMP COleObject::SetExtent(DWORD dwDrawAspect, LPSIZEL lpsizel)
  431. {
  432. // BUGBUG - NYI
  433. return(S_OK);
  434. }
  435. //+-------------------------------------------------------------------
  436. // Method: COleObject::GetExtent
  437. //
  438. // Synopsis: See spec 2.00.09 p106. Size of the object given in the
  439. // the last SetExtent call is returned. If SetExtent has
  440. // not been called, the natural size of the object is
  441. // returned.
  442. //
  443. // Parameters: [dwDrawAspect] - DVASPECT specified for this object.
  444. // [lpsizel] - Extent structure to set.
  445. //
  446. // Returns: S_OK
  447. //
  448. // History: 7-Dec-92 DeanE Created
  449. //--------------------------------------------------------------------
  450. STDMETHODIMP COleObject::GetExtent(DWORD dwDrawAspect, LPSIZEL lpsizel)
  451. {
  452. // BUGBUG - NYI
  453. return(S_OK);
  454. }
  455. //+-------------------------------------------------------------------
  456. // Method: COleObject::Advise
  457. //
  458. // Synopsis: See spec 2.00.09 p121. Set up an advisory connection
  459. // between this object and an advisory sink; when certain
  460. // events happen (birthdays?) this sink should be informed
  461. // by this object. Use the OleAdviseHolder object as a
  462. // helper (see p122).
  463. //
  464. // Parameters: [pAdvSink] - Sink that should be informed of changes.
  465. // [pdwConnection] - Pass advisory token returned so our
  466. // caller can shut down the link.
  467. //
  468. // Returns: S_OK
  469. //
  470. // History: 7-Dec-92 DeanE Created
  471. //--------------------------------------------------------------------
  472. STDMETHODIMP COleObject::Advise(
  473. IAdviseSink FAR *pAdvSink,
  474. DWORD FAR *pdwConnection)
  475. {
  476. // if (NULL == _pOAHolder)
  477. // {
  478. // if (S_OK != CreateOleAdviseHolder(&_pOAHolder))
  479. // {
  480. // return(E_OUTOFMEMORY);
  481. // }
  482. // }
  483. //
  484. // return(_pOAHolder->Advise(pAdvSink, pdwConnection));
  485. *pdwConnection = 0;
  486. return S_OK;
  487. }
  488. //+-------------------------------------------------------------------
  489. // Method: COleObject::Unadvise
  490. //
  491. // Synopsis: See spec 2.00.09 p121. Tear down an advisory connection
  492. // set up previously.
  493. //
  494. // Parameters: [dwConnection] - Connection established earlier.
  495. //
  496. // Returns: S_OK or ???
  497. //
  498. // History: 7-Dec-92 DeanE Created
  499. //--------------------------------------------------------------------
  500. STDMETHODIMP COleObject::Unadvise(DWORD dwConnection)
  501. {
  502. if (NULL == _pOAHolder)
  503. {
  504. // No one is registered - see ellipswt.cpp for this
  505. return(E_INVALIDARG);
  506. }
  507. return(_pOAHolder->Unadvise(dwConnection));
  508. }
  509. //+-------------------------------------------------------------------
  510. // Method: COleObject::EnumAdvise
  511. //
  512. // Synopsis: See spec 2.00.09 p122. Enumerate the advisory connections
  513. // currently attached to this object.
  514. //
  515. // Parameters: [ppenmAdvise] - Enumeration object to return.
  516. //
  517. // Returns: S_OK
  518. //
  519. // History: 7-Dec-92 DeanE Created
  520. //--------------------------------------------------------------------
  521. STDMETHODIMP COleObject::EnumAdvise(LPENUMSTATDATA FAR *ppenmAdvise)
  522. {
  523. if (NULL == _pOAHolder)
  524. {
  525. return(E_FAIL);
  526. }
  527. return(_pOAHolder->EnumAdvise(ppenmAdvise));
  528. }
  529. //+-------------------------------------------------------------------
  530. // Method: COleObject::GetMiscStatus
  531. //
  532. // Synopsis: I have little idea what this does. It's not in the
  533. // spec 2.00.09.
  534. //
  535. // Returns: S_OK?
  536. //
  537. // History: 7-Dec-92 DeanE Created
  538. //--------------------------------------------------------------------
  539. STDMETHODIMP COleObject::GetMiscStatus(
  540. DWORD dwAspect,
  541. DWORD FAR *pdwStatus)
  542. {
  543. // BUGBUG - NYI
  544. return(E_FAIL);
  545. }
  546. //+-------------------------------------------------------------------
  547. // Method: COleObject::SetColorScheme
  548. //
  549. // Synopsis: I have little idea what this does. It's not in the
  550. // spec 2.00.09.
  551. //
  552. // Returns: S_OK?
  553. //
  554. // History: 7-Dec-92 DeanE Created
  555. //--------------------------------------------------------------------
  556. STDMETHODIMP COleObject::SetColorScheme(LPLOGPALETTE lpLogpal)
  557. {
  558. // BUGBUG - NYI
  559. return(S_OK);
  560. }