olecallback.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * Wordpad implementation - Richedit OLE callback implementation
  3. *
  4. * Copyright 2010 by Dylan Smith <dylan.ah.smith@gmail.com>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #define COBJMACROS
  21. #include <windows.h>
  22. #include <richedit.h>
  23. #include <ole2.h>
  24. #include <richole.h>
  25. #include "wine/debug.h"
  26. #include "wordpad.h"
  27. WINE_DEFAULT_DEBUG_CHANNEL(wordpad);
  28. struct IRichEditOleCallbackImpl {
  29. IRichEditOleCallback IRichEditOleCallback_iface;
  30. IStorage *stg;
  31. int item_num;
  32. };
  33. struct IRichEditOleCallbackImpl olecallback;
  34. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_QueryInterface(
  35. IRichEditOleCallback* This,
  36. REFIID riid,
  37. void **ppvObject)
  38. {
  39. WINE_TRACE("(%p, %s, %p)\n", This, wine_dbgstr_guid(riid), ppvObject);
  40. if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IRichEditOleCallback))
  41. {
  42. *ppvObject = This;
  43. return S_OK;
  44. }
  45. WINE_FIXME("Unknown interface: %s\n", wine_dbgstr_guid(riid));
  46. return E_NOINTERFACE;
  47. }
  48. static ULONG STDMETHODCALLTYPE RichEditOleCallback_AddRef(
  49. IRichEditOleCallback* This)
  50. {
  51. WINE_TRACE("(%p)\n", This);
  52. /* singleton */
  53. return 1;
  54. }
  55. static ULONG STDMETHODCALLTYPE RichEditOleCallback_Release(
  56. IRichEditOleCallback* This)
  57. {
  58. WINE_TRACE("(%p)\n", This);
  59. return 1;
  60. }
  61. /*** IRichEditOleCallback methods ***/
  62. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_GetNewStorage(
  63. IRichEditOleCallback* This,
  64. LPSTORAGE *lplpstg)
  65. {
  66. WCHAR name[32];
  67. static const WCHAR template[] = {'R','E','O','L','E','_','%','u','\0'};
  68. WINE_TRACE("(%p, %p)\n", This, lplpstg);
  69. wsprintfW(name, template, olecallback.item_num++);
  70. return IStorage_CreateStorage(olecallback.stg, name,
  71. STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
  72. 0, 0, lplpstg);
  73. }
  74. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_GetInPlaceContext(
  75. IRichEditOleCallback* This,
  76. LPOLEINPLACEFRAME *lplpFrame,
  77. LPOLEINPLACEUIWINDOW *lplpDoc,
  78. LPOLEINPLACEFRAMEINFO lpFrameInfo)
  79. {
  80. WINE_FIXME("(%p, %p, %p, %p) stub\n", This, lplpFrame, lplpDoc, lpFrameInfo);
  81. return E_INVALIDARG;
  82. }
  83. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_ShowContainerUI(
  84. IRichEditOleCallback* This,
  85. BOOL fShow)
  86. {
  87. WINE_TRACE("(%p, %d)\n", This, fShow);
  88. return S_OK;
  89. }
  90. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_QueryInsertObject(
  91. IRichEditOleCallback* This,
  92. LPCLSID lpclsid,
  93. LPSTORAGE lpstg,
  94. LONG cp)
  95. {
  96. WINE_TRACE("(%p, %p, %p, %d)\n", This, lpclsid, lpstg, cp);
  97. return S_OK;
  98. }
  99. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_DeleteObject(
  100. IRichEditOleCallback* This,
  101. LPOLEOBJECT lpoleobj)
  102. {
  103. WINE_TRACE("(%p, %p)\n", This, lpoleobj);
  104. return S_OK;
  105. }
  106. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_QueryAcceptData(
  107. IRichEditOleCallback* This,
  108. LPDATAOBJECT lpdataobj,
  109. CLIPFORMAT *lpcfFormat,
  110. DWORD reco,
  111. BOOL fReally,
  112. HGLOBAL hMetaPict)
  113. {
  114. WINE_TRACE("(%p, %p, %p, %x, %d, %p)\n",
  115. This, lpdataobj, lpcfFormat, reco, fReally, hMetaPict);
  116. return S_OK;
  117. }
  118. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_ContextSensitiveHelp(
  119. IRichEditOleCallback* This,
  120. BOOL fEnterMode)
  121. {
  122. WINE_TRACE("(%p, %d)\n", This, fEnterMode);
  123. return S_OK;
  124. }
  125. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_GetClipboardData(
  126. IRichEditOleCallback* This,
  127. CHARRANGE *lpchrg,
  128. DWORD reco,
  129. LPDATAOBJECT *lplpdataobj)
  130. {
  131. WINE_TRACE("(%p, %p, %x, %p)\n", This, lpchrg, reco, lplpdataobj);
  132. return E_NOTIMPL;
  133. }
  134. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_GetDragDropEffect(
  135. IRichEditOleCallback* This,
  136. BOOL fDrag,
  137. DWORD grfKeyState,
  138. LPDWORD pdwEffect)
  139. {
  140. WINE_TRACE("(%p, %d, %x, %p)\n", This, fDrag, grfKeyState, pdwEffect);
  141. if (pdwEffect)
  142. *pdwEffect = DROPEFFECT_COPY;
  143. return S_OK;
  144. }
  145. static HRESULT STDMETHODCALLTYPE RichEditOleCallback_GetContextMenu(
  146. IRichEditOleCallback* This,
  147. WORD seltype,
  148. LPOLEOBJECT lpoleobj,
  149. CHARRANGE *lpchrg,
  150. HMENU *lphmenu)
  151. {
  152. HINSTANCE hInstance = GetModuleHandleW(0);
  153. HMENU hPopupMenu = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDM_POPUP));
  154. WINE_TRACE("(%p, %x, %p, %p, %p)\n",
  155. This, seltype, lpoleobj, lpchrg, lphmenu);
  156. *lphmenu = GetSubMenu(hPopupMenu, 0);
  157. return S_OK;
  158. }
  159. struct IRichEditOleCallbackVtbl olecallbackVtbl = {
  160. RichEditOleCallback_QueryInterface,
  161. RichEditOleCallback_AddRef,
  162. RichEditOleCallback_Release,
  163. RichEditOleCallback_GetNewStorage,
  164. RichEditOleCallback_GetInPlaceContext,
  165. RichEditOleCallback_ShowContainerUI,
  166. RichEditOleCallback_QueryInsertObject,
  167. RichEditOleCallback_DeleteObject,
  168. RichEditOleCallback_QueryAcceptData,
  169. RichEditOleCallback_ContextSensitiveHelp,
  170. RichEditOleCallback_GetClipboardData,
  171. RichEditOleCallback_GetDragDropEffect,
  172. RichEditOleCallback_GetContextMenu
  173. };
  174. struct IRichEditOleCallbackImpl olecallback = {
  175. { &olecallbackVtbl }, NULL, 0
  176. };
  177. HRESULT setup_richedit_olecallback(HWND hEditorWnd)
  178. {
  179. HRESULT hr = StgCreateDocfile(NULL,
  180. STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE,
  181. 0, &olecallback.stg);
  182. SendMessageW(hEditorWnd, EM_SETOLECALLBACK, 0, (LPARAM)&olecallback.IRichEditOleCallback_iface);
  183. return hr;
  184. }