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

697 lines
15 KiB

  1. /* virtable.c - This module contains the OLE virtual table/private routines.
  2. *
  3. * Created by Microsoft Corporation.
  4. */
  5. #include "packager.h"
  6. #include "dialogs.h"
  7. //#define OLESVR_SUPPORT /* enable support for OLE server files */
  8. static CHAR szLink[] = "/Link"; // Appended to end of link packages
  9. /**************************** Server functions *****************************/
  10. /* SrvrOpen() - Wraps a filename that is passed into a command line.
  11. */
  12. OLESTATUS
  13. SrvrOpen(
  14. LPOLESERVER lpolesrvr,
  15. LHSERVERDOC lhdoc,
  16. LPSTR lpdocname,
  17. LPOLESERVERDOC *lplpoledoc
  18. )
  19. {
  20. LPSAMPDOC lpdoc;
  21. LPSTR lpstrLink = NULL;
  22. OLESTATUS retval = OLE_OK;
  23. LPOLEOBJECT lpObject = NULL;
  24. DPRINT("pkg: SrvrOpen");
  25. if (lpstrLink = Contains(lpdocname, szLink))
  26. *lpstrLink = '\0';
  27. if (!(lpdoc = (LPSAMPDOC)CreateDocFromFile(
  28. (LPSAMPSRVR)lpolesrvr, lhdoc, lpdocname)))
  29. return OLE_ERROR_GENERIC;
  30. // Generate a command line
  31. BringWindowToTop(ghwndPane[CONTENT]);
  32. if (gpty[CONTENT])
  33. DeletePane(CONTENT, TRUE);
  34. #ifdef OLESVR_SUPPORT
  35. if (IsOleServerDoc (lpdocname))
  36. {
  37. gpty[CONTENT] = PICTURE;
  38. if (lpstrLink)
  39. {
  40. if (Error(OleCreateLinkFromFile(gszProtocol, glpclient, NULL,
  41. lpdocname, NULL, glhcdoc, gszCaption[CONTENT], &lpObject,
  42. olerender_draw, 0)))
  43. retval = OLE_ERROR_OPEN;
  44. }
  45. else
  46. {
  47. if (Error(OleCreateFromFile(gszProtocol, glpclient, NULL, lpdocname,
  48. glhcdoc, gszCaption[CONTENT], &lpObject, olerender_draw, 0)))
  49. retval = OLE_ERROR_OPEN;
  50. }
  51. if (retval == OLE_OK)
  52. {
  53. glpobj[CONTENT] = PicCreate(lpObject, NULL);
  54. ((LPPICT)glpobj[CONTENT])->fNotReady = TRUE;
  55. OleBlockServer(((LPSAMPSRVR)lpolesrvr)->lhsrvr);
  56. gfBlocked = TRUE;
  57. }
  58. else
  59. {
  60. DeregisterDoc();
  61. return retval;
  62. }
  63. }
  64. else
  65. {
  66. #endif
  67. if (lpstrLink)
  68. {
  69. if (glpobj[CONTENT] = CmlCreateFromFilename(lpdocname, TRUE))
  70. gpty[CONTENT] = CMDLINK;
  71. }
  72. else
  73. {
  74. if (glpobj[CONTENT] = (LPVOID)EmbCreate(lpdocname))
  75. gpty[CONTENT] = PEMBED;
  76. }
  77. if (glpobj[CONTENT] == NULL)
  78. retval = OLE_ERROR_OPEN;
  79. #ifdef OLESVR_SUPPORT
  80. }
  81. #endif
  82. // If no appearance pane (which should be always), try to make one
  83. if (!gpty[APPEARANCE])
  84. {
  85. if (glpobj[APPEARANCE] = IconCreateFromFile(lpdocname))
  86. {
  87. gpty[APPEARANCE] = ICON;
  88. InvalidateRect(ghwndPane[APPEARANCE], NULL, TRUE);
  89. }
  90. }
  91. // Restore the character we so rudely mashed
  92. if (lpstrLink)
  93. *lpstrLink = szLink[0];
  94. // Save the document and change the menus
  95. InitEmbedded(FALSE);
  96. *lplpoledoc = (LPOLESERVERDOC)lpdoc;
  97. return retval;
  98. }
  99. /* SrvrCreate() - Create a new (embedded) object.
  100. */
  101. OLESTATUS
  102. SrvrCreate(
  103. LPOLESERVER lpolesrvr,
  104. LHSERVERDOC lhdoc,
  105. LPSTR lpclassname,
  106. LPSTR lpdocname,
  107. LPOLESERVERDOC *lplpoledoc
  108. )
  109. {
  110. DPRINT("pkg: SrvrCreate");
  111. // Initialize the new image
  112. InitFile();
  113. if (!(*lplpoledoc = (LPOLESERVERDOC)CreateNewDoc((LPSAMPSRVR)lpolesrvr,
  114. lhdoc, lpdocname)))
  115. return OLE_ERROR_GENERIC;
  116. InitEmbedded(TRUE);
  117. return OLE_OK;
  118. }
  119. /* SrvrCreateFromTemplate() - Create a new (embedded) object from a file.
  120. */
  121. OLESTATUS
  122. SrvrCreateFromTemplate(
  123. LPOLESERVER lpolesrvr,
  124. LHSERVERDOC lhdoc,
  125. LPSTR lpclassname,
  126. LPSTR lpdocname,
  127. LPSTR lptemplatename,
  128. LPOLESERVERDOC *lplpoledoc
  129. )
  130. {
  131. LPSAMPDOC lpdoc;
  132. DPRINT("pkg: SrvrCreateFromTemplate");
  133. if (!(lpdoc = (LPSAMPDOC)CreateDocFromFile((LPSAMPSRVR)lpolesrvr, lhdoc,
  134. lptemplatename)))
  135. return OLE_ERROR_GENERIC;
  136. // Save the document and change the menus
  137. *lplpoledoc = (LPOLESERVERDOC)lpdoc;
  138. InitEmbedded(FALSE);
  139. StringCchCopy(szUntitled, ARRAYSIZE(szUntitled), lpdocname);
  140. SetTitle(TRUE);
  141. return OLE_OK;
  142. }
  143. /* SrvrEdit() - Open an (embedded) object for editing.
  144. */
  145. OLESTATUS
  146. SrvrEdit(
  147. LPOLESERVER lpolesrvr,
  148. LHSERVERDOC lhdoc,
  149. LPSTR lpclassname,
  150. LPSTR lpdocname,
  151. LPOLESERVERDOC *lplpoledoc
  152. )
  153. {
  154. DPRINT("pkg: SrvrEdit");
  155. if (!(*lplpoledoc = (LPOLESERVERDOC)CreateNewDoc((LPSAMPSRVR)lpolesrvr,
  156. lhdoc, lpdocname)))
  157. return OLE_ERROR_MEMORY;
  158. InitEmbedded(FALSE);
  159. return OLE_OK;
  160. }
  161. /* SrvrExit() - Called to cause the OLE server to be revoked.
  162. */
  163. OLESTATUS
  164. SrvrExit(
  165. LPOLESERVER lpolesrvr
  166. )
  167. {
  168. DPRINT("pkg: SrvrExit");
  169. DeleteServer((LPSAMPSRVR)lpolesrvr);
  170. return OLE_OK;
  171. }
  172. /* SrvrRelease() - Called so that the server memory can be freed.
  173. *
  174. * Note: This call may occur in isolation without a SrvrExit()
  175. * call. If this occurs, we still revoke the server.
  176. */
  177. OLESTATUS
  178. SrvrRelease(
  179. LPOLESERVER lpolesrvr
  180. )
  181. {
  182. DPRINT("pkg: SrvrRelease");
  183. if (gvlptempdoc)
  184. return OLE_OK;
  185. if (gfInvisible || (gfEmbeddedFlag && !gfDocExists))
  186. DeleteServer((LPSAMPSRVR)lpolesrvr);
  187. if (ghServer)
  188. DestroyServer();
  189. return OLE_OK;
  190. }
  191. /* SrvrExecute() - Called to execute DDE commands
  192. */
  193. OLESTATUS
  194. SrvrExecute(
  195. LPOLESERVER lpolesrvr,
  196. HANDLE hCmds
  197. )
  198. {
  199. DPRINT("pkg: SrvrExecute");
  200. return OLE_ERROR_PROTOCOL;
  201. }
  202. /************************** Document functions *************************/
  203. /* DocSave() - OLE callback to save the document.
  204. */
  205. OLESTATUS
  206. DocSave(
  207. LPOLESERVERDOC lpoledoc
  208. )
  209. {
  210. DPRINT("pkg: DocSave");
  211. return OLE_OK;
  212. }
  213. /* DocClose() - OLE callback when the document is to be closed.
  214. *
  215. * This command has no additional effects; since we are not an MDI application
  216. * we don't close the child window. The window is destroyed when the server
  217. * function "Release" is called.
  218. */
  219. OLESTATUS
  220. DocClose(
  221. LPOLESERVERDOC lpoledoc
  222. )
  223. {
  224. DPRINT("pkg: DocClose");
  225. DeregisterDoc();
  226. return OLE_OK;
  227. }
  228. /* DocRelease() - Deallocate document memory.
  229. */
  230. OLESTATUS
  231. DocRelease(
  232. LPOLESERVERDOC lpoledoc
  233. )
  234. {
  235. LPSAMPDOC lpdoc = (LPSAMPDOC)lpoledoc;
  236. HANDLE hdoc;
  237. DPRINT("pkg: DocRelase");
  238. if (lpdoc)
  239. {
  240. if (!gfDocCleared)
  241. {
  242. glpdoc = NULL;
  243. DeregisterDoc();
  244. }
  245. GlobalDeleteAtom(lpdoc->aName);
  246. LocalUnlock(hdoc = lpdoc->hdoc);
  247. LocalFree(hdoc);
  248. gfDocExists = FALSE;
  249. }
  250. return OLE_OK;
  251. }
  252. /* DocGetObject() - Create a new object within the current document
  253. */
  254. OLESTATUS
  255. DocGetObject(
  256. LPOLESERVERDOC lpoledoc,
  257. LPSTR lpitemname,
  258. LPOLEOBJECT *lplpoleobject,
  259. LPOLECLIENT lpoleclient
  260. )
  261. {
  262. LPSAMPITEM lpitem;
  263. DPRINT("pkg: DocGetObject");
  264. //
  265. // Always create a new item in this case, it's much easier than
  266. // worrying about the sub-rectangle bitmap.
  267. //
  268. lpitem = CreateNewItem((LPSAMPDOC)lpoledoc);
  269. lpitem->lpoleclient = lpoleclient;
  270. if (*lpitemname)
  271. {
  272. lpitem->aName = AddAtom(lpitemname);
  273. }
  274. else
  275. {
  276. lpitem->aName = 0;
  277. }
  278. if (!(*lplpoleobject = (LPOLEOBJECT)AddItem(lpitem)))
  279. return OLE_ERROR_GENERIC;
  280. return OLE_OK;
  281. }
  282. /* DocSetHostNames() - Sets the title bar to the correct document name.
  283. *
  284. * Note: The format is "<lpclientName> <app name> - <lpdocName>".
  285. */
  286. OLESTATUS
  287. DocSetHostNames(
  288. LPOLESERVERDOC lpoledoc,
  289. LPSTR lpclientName,
  290. LPSTR lpdocName
  291. )
  292. {
  293. DPRINT("pkg: DocSetHostnames");
  294. StringCchCopy(szUntitled, ARRAYSIZE(szUntitled), lpdocName);
  295. StringCchCopy(gszClientName, ARRAYSIZE(gszClientName), lpclientName);
  296. SetTitle(TRUE);
  297. return OLE_OK;
  298. }
  299. /* DocSetDocDimensions() - OLE callback to change the document dimensions.
  300. *
  301. * Note: This command is unsupported. It is the client application's
  302. * responsibility to report errors (as needed).
  303. */
  304. OLESTATUS
  305. DocSetDocDimensions(
  306. LPOLESERVERDOC lpoledoc,
  307. LPRECT lprc
  308. )
  309. {
  310. DPRINT("pkg: DocSetDocDimensions");
  311. return OLE_ERROR_GENERIC;
  312. }
  313. /* DocSetColorScheme() - OLE callback to change the document colors.
  314. *
  315. * Note: This command is unsupported. It is the client application's
  316. * responsibility to report errors (as needed).
  317. */
  318. OLESTATUS
  319. DocSetColorScheme(
  320. LPOLESERVERDOC lpoledoc,
  321. LPLOGPALETTE lppal
  322. )
  323. {
  324. DPRINT("pkg: DocSetColorScheme");
  325. return OLE_ERROR_GENERIC;
  326. }
  327. /* DocExecute() - Called to execute DDE commands
  328. */
  329. OLESTATUS
  330. DocExecute(
  331. LPOLESERVERDOC lpoledoc,
  332. HANDLE hCmds
  333. )
  334. {
  335. DPRINT("pkg: DocExecute");
  336. return OLE_ERROR_PROTOCOL;
  337. }
  338. /**************************** Item functions ***************************/
  339. /* ItemDelete() - Free memory associated with the current item.
  340. */
  341. OLESTATUS
  342. ItemDelete(
  343. LPOLEOBJECT lpoleobject
  344. )
  345. {
  346. DPRINT("pkg: ItemDelete");
  347. DeleteItem((LPSAMPITEM)lpoleobject);
  348. return OLE_OK; /* Add error checking later */
  349. }
  350. /* ItemGetData() - Used by the client to obtain the item data.
  351. */
  352. OLESTATUS
  353. ItemGetData(
  354. LPOLEOBJECT lpoleobject,
  355. OLECLIPFORMAT cfFormat,
  356. LPHANDLE lphandle
  357. )
  358. {
  359. DPRINT("pkg: ItemGetData");
  360. if ((gpty[CONTENT] == PICTURE) && ((LPPICT)glpobj[CONTENT])->fNotReady)
  361. return OLE_BUSY;
  362. if (cfFormat == gcfNative)
  363. {
  364. if (*lphandle = GetNative(FALSE))
  365. return OLE_OK;
  366. }
  367. else if (cfFormat == CF_METAFILEPICT)
  368. {
  369. if (*lphandle = GetMF())
  370. return OLE_OK;
  371. }
  372. else if (cfFormat == gcfOwnerLink)
  373. {
  374. if (*lphandle = GetLink())
  375. return OLE_OK;
  376. }
  377. // Clipboard format not supported
  378. return OLE_ERROR_GENERIC;
  379. }
  380. /* ItemSetData() - Used by the client to paste data into a server.
  381. *
  382. * Read in the embedded object data in Native format. This will
  383. * not be called unless we are editing the correct document.
  384. */
  385. OLESTATUS
  386. ItemSetData(
  387. LPOLEOBJECT lpoleobject,
  388. OLECLIPFORMAT cfFormat,
  389. HANDLE hdata
  390. )
  391. {
  392. LPSAMPITEM lpitem = (LPSAMPITEM)lpoleobject;
  393. DPRINT("pkg: ItemSetData");
  394. if (cfFormat == gcfNative && !PutNative(hdata))
  395. {
  396. SendMessage(ghwndFrame, WM_COMMAND, IDM_NEW, 0L);
  397. GlobalFree(hdata);
  398. return OLE_ERROR_GENERIC;
  399. }
  400. GlobalFree(hdata);
  401. return OLE_OK;
  402. }
  403. /* ItemDoVerb() - Play/Edit the object.
  404. *
  405. * This routine is called when the user tries to run an object that
  406. * is wrapped by the packager.
  407. */
  408. OLESTATUS
  409. ItemDoVerb(
  410. LPOLEOBJECT lpoleobject,
  411. UINT wVerb,
  412. BOOL fShow,
  413. BOOL fActivate
  414. )
  415. {
  416. DPRINT("pkg: ItemDoVerb");
  417. switch (wVerb)
  418. {
  419. case OLE_PLAY:
  420. if (fShow)
  421. return (*(lpoleobject->lpvtbl->Show))(lpoleobject, fActivate);
  422. break;
  423. case OLE_EDIT:
  424. if (fShow && fActivate)
  425. {
  426. if (gfInvisible)
  427. {
  428. ShowWindow(ghwndFrame, gnCmdShowSave);
  429. gfInvisible = FALSE;
  430. }
  431. // If iconic, restore the window; then give it the focus.
  432. if (IsIconic(ghwndFrame))
  433. SendMessage(ghwndFrame, WM_SYSCOMMAND, SC_RESTORE, 0L);
  434. BringWindowToTop(ghwndFrame);
  435. }
  436. default:
  437. break;
  438. }
  439. return OLE_OK;
  440. }
  441. /* ItemShow() - Show the item.
  442. *
  443. * This routine is called when the user tries to edit an object in a
  444. * client application, and the server is already active.
  445. */
  446. OLESTATUS
  447. ItemShow(
  448. LPOLEOBJECT lpoleobject,
  449. BOOL fActivate
  450. )
  451. {
  452. HWND hwndItem;
  453. DPRINT("pkg: ItemShow");
  454. if (fActivate
  455. && (hwndItem = GetTopWindow(ghwndFrame))
  456. && (gpty[(hwndItem == ghwndPane[CONTENT])] == NOTHING))
  457. {
  458. //
  459. // Lets assume that in this case the client has
  460. // attempted an InsertObject operation with
  461. // the Package class. (5.30.91) v-dougk
  462. //
  463. if (gfInvisible)
  464. {
  465. ShowWindow(ghwndFrame, SW_SHOW);
  466. gfInvisible = FALSE;
  467. }
  468. BringWindowToTop(ghwndFrame);
  469. }
  470. else
  471. {
  472. PostMessage(hwndItem, WM_COMMAND, IDD_PLAY, 0L);
  473. }
  474. return OLE_OK;
  475. }
  476. /* ItemSetBounds() - Set the item's size.
  477. *
  478. * Note: This command is not supported.
  479. */
  480. OLESTATUS
  481. ItemSetBounds(
  482. LPOLEOBJECT lpoleobject,
  483. LPRECT lprc
  484. )
  485. {
  486. DPRINT("pkg: ItemSetBounds");
  487. return OLE_ERROR_GENERIC;
  488. }
  489. /* ItemSetTargetDevice() - Changes the target device for item display.
  490. *
  491. * Note: This command is not supported.
  492. */
  493. OLESTATUS
  494. ItemSetTargetDevice(
  495. LPOLEOBJECT lpoleobject,
  496. HANDLE h
  497. )
  498. {
  499. DPRINT("pkg: ItemSetTargetDevice");
  500. if (h)
  501. GlobalFree(h);
  502. return OLE_ERROR_GENERIC;
  503. }
  504. /* ItemEnumFormats() - Enumerate formats which are renderable.
  505. *
  506. * This is called by the OLE libraries to get a format for screen display.
  507. * Currently, only Metafile and Native are supported.
  508. */
  509. OLECLIPFORMAT
  510. ItemEnumFormats(
  511. LPOLEOBJECT lpobject,
  512. OLECLIPFORMAT cfFormat
  513. )
  514. {
  515. DPRINT("pkg: ItemEnumFormats");
  516. if (!cfFormat)
  517. return CF_METAFILEPICT;
  518. if (cfFormat == CF_METAFILEPICT)
  519. return gcfNative;
  520. return 0;
  521. }
  522. /* ItemQueryProtocol() - Tells whether the given protocol is supported.
  523. *
  524. * Returns: lpoleobject iff the protocol is "StdFileEditing".
  525. */
  526. LPVOID
  527. ItemQueryProtocol(
  528. LPOLEOBJECT lpoleobject,
  529. LPSTR lpprotocol
  530. )
  531. {
  532. DPRINT("pkg: ItemQueryProtocol");
  533. return (!lstrcmpi(lpprotocol, "StdFileEditing") ? lpoleobject : NULL);
  534. }
  535. /* ItemSetColorScheme() - Denotes the palette to be used for item display.
  536. *
  537. * Note: This command is not supported.
  538. */
  539. OLESTATUS
  540. ItemSetColorScheme(
  541. LPOLEOBJECT lpoleobject,
  542. LPLOGPALETTE lppal
  543. )
  544. {
  545. DPRINT("pkg: ItemSetColorScheme");
  546. return OLE_ERROR_GENERIC;
  547. }
  548. BOOL IsOleServerDoc(LPSTR lpdocname)
  549. {
  550. // 06/11/02 The OLE code path does not execute in XPSP1. Further, we want to ensure that we are going
  551. // through the ShellExecute path so that we get the new ShellExecute security warning for
  552. // the termporary internet directory. Therefore, we will always return FALSE here, a least for now.
  553. return FALSE;
  554. }