Import my Hybrid-CD stuff from last year.
[reactos.git] / reactos / base / applications / wordpad / olecallback.c
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
21 #define COBJMACROS
22
23 #include <windows.h>
24 #include <richedit.h>
25 #include <ole2.h>
26 #include <richole.h>
27
28 #include "wine/debug.h"
29 #include "wordpad.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(wordpad);
32
33 struct IRichEditOleCallbackImpl {
34 const IRichEditOleCallbackVtbl *vtbl;
35 IStorage *stg;
36 int item_num;
37 };
38
39 struct IRichEditOleCallbackImpl olecallback;
40
41 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_QueryInterface(
42 IRichEditOleCallback* This,
43 REFIID riid,
44 void **ppvObject)
45 {
46 WINE_TRACE("(%p, %s, %p)\n", This, wine_dbgstr_guid(riid), ppvObject);
47 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IRichEditOleCallback))
48 {
49 *ppvObject = This;
50 return S_OK;
51 }
52 WINE_FIXME("Unknown interface: %s\n", wine_dbgstr_guid(riid));
53 return E_NOINTERFACE;
54 }
55
56 static ULONG STDMETHODCALLTYPE RichEditOleCallback_AddRef(
57 IRichEditOleCallback* This)
58 {
59 WINE_TRACE("(%p)\n", This);
60 /* singleton */
61 return 1;
62 }
63
64 static ULONG STDMETHODCALLTYPE RichEditOleCallback_Release(
65 IRichEditOleCallback* This)
66 {
67 WINE_TRACE("(%p)\n", This);
68 return 1;
69 }
70
71 /*** IRichEditOleCallback methods ***/
72 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_GetNewStorage(
73 IRichEditOleCallback* This,
74 LPSTORAGE *lplpstg)
75 {
76 WCHAR name[32];
77 static const WCHAR template[] = {'R','E','O','L','E','_','%','u','\0'};
78
79 WINE_TRACE("(%p, %p)\n", This, lplpstg);
80 wsprintfW(name, template, olecallback.item_num++);
81 return IStorage_CreateStorage(olecallback.stg, name,
82 STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
83 0, 0, lplpstg);
84 }
85
86 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_GetInPlaceContext(
87 IRichEditOleCallback* This,
88 LPOLEINPLACEFRAME *lplpFrame,
89 LPOLEINPLACEUIWINDOW *lplpDoc,
90 LPOLEINPLACEFRAMEINFO lpFrameInfo)
91 {
92 WINE_FIXME("(%p, %p, %p, %p) stub\n", This, lplpFrame, lplpDoc, lpFrameInfo);
93 return E_INVALIDARG;
94 }
95
96 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_ShowContainerUI(
97 IRichEditOleCallback* This,
98 BOOL fShow)
99 {
100 WINE_TRACE("(%p, %d)\n", This, fShow);
101 return S_OK;
102 }
103
104 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_QueryInsertObject(
105 IRichEditOleCallback* This,
106 LPCLSID lpclsid,
107 LPSTORAGE lpstg,
108 LONG cp)
109 {
110 WINE_TRACE("(%p, %p, %p, %d)\n", This, lpclsid, lpstg, cp);
111 return S_OK;
112 }
113
114 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_DeleteObject(
115 IRichEditOleCallback* This,
116 LPOLEOBJECT lpoleobj)
117 {
118 WINE_TRACE("(%p, %p)\n", This, lpoleobj);
119 return S_OK;
120 }
121
122 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_QueryAcceptData(
123 IRichEditOleCallback* This,
124 LPDATAOBJECT lpdataobj,
125 CLIPFORMAT *lpcfFormat,
126 DWORD reco,
127 BOOL fReally,
128 HGLOBAL hMetaPict)
129 {
130 WINE_TRACE("(%p, %p, %p, %x, %d, %p)\n",
131 This, lpdataobj, lpcfFormat, reco, fReally, hMetaPict);
132 return S_OK;
133 }
134
135 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_ContextSensitiveHelp(
136 IRichEditOleCallback* This,
137 BOOL fEnterMode)
138 {
139 WINE_TRACE("(%p, %d)\n", This, fEnterMode);
140 return S_OK;
141 }
142
143 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_GetClipboardData(
144 IRichEditOleCallback* This,
145 CHARRANGE *lpchrg,
146 DWORD reco,
147 LPDATAOBJECT *lplpdataobj)
148 {
149 WINE_TRACE("(%p, %p, %x, %p)\n", This, lpchrg, reco, lplpdataobj);
150 return E_NOTIMPL;
151 }
152
153 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_GetDragDropEffect(
154 IRichEditOleCallback* This,
155 BOOL fDrag,
156 DWORD grfKeyState,
157 LPDWORD pdwEffect)
158 {
159 WINE_TRACE("(%p, %d, %x, %p)\n", This, fDrag, grfKeyState, pdwEffect);
160 if (pdwEffect)
161 *pdwEffect = DROPEFFECT_COPY;
162 return S_OK;
163 }
164
165 static HRESULT STDMETHODCALLTYPE RichEditOleCallback_GetContextMenu(
166 IRichEditOleCallback* This,
167 WORD seltype,
168 LPOLEOBJECT lpoleobj,
169 CHARRANGE *lpchrg,
170 HMENU *lphmenu)
171 {
172 HINSTANCE hInstance = GetModuleHandleW(0);
173 HMENU hPopupMenu = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDM_POPUP));
174
175 WINE_TRACE("(%p, %x, %p, %p, %p)\n",
176 This, seltype, lpoleobj, lpchrg, lphmenu);
177
178 *lphmenu = GetSubMenu(hPopupMenu, 0);
179 return S_OK;
180 }
181
182 struct IRichEditOleCallbackVtbl olecallbackVtbl = {
183 RichEditOleCallback_QueryInterface,
184 RichEditOleCallback_AddRef,
185 RichEditOleCallback_Release,
186 RichEditOleCallback_GetNewStorage,
187 RichEditOleCallback_GetInPlaceContext,
188 RichEditOleCallback_ShowContainerUI,
189 RichEditOleCallback_QueryInsertObject,
190 RichEditOleCallback_DeleteObject,
191 RichEditOleCallback_QueryAcceptData,
192 RichEditOleCallback_ContextSensitiveHelp,
193 RichEditOleCallback_GetClipboardData,
194 RichEditOleCallback_GetDragDropEffect,
195 RichEditOleCallback_GetContextMenu
196 };
197
198 struct IRichEditOleCallbackImpl olecallback = {
199 &olecallbackVtbl, NULL, 0
200 };
201
202 HRESULT setup_richedit_olecallback(HWND hEditorWnd)
203 {
204 HRESULT hr = StgCreateDocfile(NULL,
205 STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE,
206 0, &olecallback.stg);
207
208 SendMessageW(hEditorWnd, EM_SETOLECALLBACK, 0, (LPARAM)&olecallback);
209 return hr;
210 }