[ATL][ATL80][ATL100]
[reactos.git] / reactos / dll / win32 / atl / atl_ax.c
1 /*
2 * Active Template Library ActiveX functions (atl.dll)
3 *
4 * Copyright 2006 Andrey Turkin
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 #include <precomp.h>
22
23 #include <ole2.h>
24 #include <exdisp.h>
25 #include <wine/atlwin.h>
26
27 typedef struct IOCS {
28 IOleClientSite IOleClientSite_iface;
29 IOleContainer IOleContainer_iface;
30 IOleInPlaceSiteWindowless IOleInPlaceSiteWindowless_iface;
31 IOleInPlaceFrame IOleInPlaceFrame_iface;
32 IOleControlSite IOleControlSite_iface;
33
34 LONG ref;
35 HWND hWnd;
36 IOleObject *control;
37 RECT size;
38 WNDPROC OrigWndProc;
39 BOOL fActive, fInPlace, fWindowless;
40 } IOCS;
41
42 /**********************************************************************
43 * AtlAxWin class window procedure
44 */
45 static LRESULT CALLBACK AtlAxWin_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
46 {
47 if ( wMsg == WM_CREATE )
48 {
49 DWORD len = GetWindowTextLengthW( hWnd ) + 1;
50 WCHAR *ptr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
51 if (!ptr)
52 return 1;
53 GetWindowTextW( hWnd, ptr, len );
54 AtlAxCreateControlEx( ptr, hWnd, NULL, NULL, NULL, NULL, NULL );
55 HeapFree( GetProcessHeap(), 0, ptr );
56 return 0;
57 }
58 return DefWindowProcW( hWnd, wMsg, wParam, lParam );
59 }
60
61 /***********************************************************************
62 * AtlAxWinInit [atl100.@]
63 * Initializes the control-hosting code: registering the AtlAxWin,
64 * AtlAxWin7 and AtlAxWinLic7 window classes and some messages.
65 *
66 * RETURNS
67 * TRUE or FALSE
68 */
69
70 BOOL WINAPI AtlAxWinInit(void)
71 {
72 WNDCLASSEXW wcex;
73
74 #if _ATL_VER <= _ATL_VER_30
75 #define ATL_NAME_SUFFIX 0
76 #elif _ATL_VER == _ATL_VER_80
77 #define ATL_NAME_SUFFIX '8','0',0
78 #elif _ATL_VER == _ATL_VER_90
79 #define ATL_NAME_SUFFIX '9','0',0
80 #elif _ATL_VER == _ATL_VER_100
81 #define ATL_NAME_SUFFIX '1','0','0',0
82 #elif _ATL_VER == _ATL_VER_110
83 #define ATL_NAME_SUFFIX '1','1','0',0
84 #else
85 #error Unsupported version
86 #endif
87
88 const WCHAR AtlAxWinW[] = {'A','t','l','A','x','W','i','n',ATL_NAME_SUFFIX};
89
90 FIXME("version %04x semi-stub\n", _ATL_VER);
91
92 if ( FAILED( OleInitialize(NULL) ) )
93 return FALSE;
94
95 wcex.cbSize = sizeof(wcex);
96 wcex.style = CS_GLOBALCLASS | (_ATL_VER > _ATL_VER_30 ? CS_DBLCLKS : 0);
97 wcex.cbClsExtra = 0;
98 wcex.cbWndExtra = 0;
99 wcex.hInstance = GetModuleHandleW( NULL );
100 wcex.hIcon = NULL;
101 wcex.hCursor = NULL;
102 wcex.hbrBackground = NULL;
103 wcex.lpszMenuName = NULL;
104 wcex.hIconSm = 0;
105
106 wcex.lpfnWndProc = AtlAxWin_wndproc;
107 wcex.lpszClassName = AtlAxWinW;
108 if ( !RegisterClassExW( &wcex ) )
109 return FALSE;
110
111 if(_ATL_VER > _ATL_VER_30) {
112 const WCHAR AtlAxWinLicW[] = {'A','t','l','A','x','W','i','n','L','i','c',ATL_NAME_SUFFIX};
113
114 wcex.lpszClassName = AtlAxWinLicW;
115 if ( !RegisterClassExW( &wcex ) )
116 return FALSE;
117 }
118
119 return TRUE;
120 }
121
122 /***********************************************************************
123 * Atl container component implementation
124 */
125
126 /****** IOleClientSite *****/
127 static inline IOCS *impl_from_IOleClientSite(IOleClientSite *iface)
128 {
129 return CONTAINING_RECORD(iface, IOCS, IOleClientSite_iface);
130 }
131
132 static HRESULT IOCS_Detach( IOCS *This ) /* remove subclassing */
133 {
134 if ( This->hWnd )
135 {
136 SetWindowLongPtrW( This->hWnd, GWLP_WNDPROC, (ULONG_PTR) This->OrigWndProc );
137 SetWindowLongPtrW( This->hWnd, GWLP_USERDATA, 0 );
138 This->hWnd = NULL;
139 }
140 if ( This->control )
141 {
142 IOleObject *control = This->control;
143
144 This->control = NULL;
145 IOleObject_Close( control, OLECLOSE_NOSAVE );
146 IOleObject_SetClientSite( control, NULL );
147 IOleObject_Release( control );
148 }
149 return S_OK;
150 }
151
152 static HRESULT WINAPI OleClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
153 {
154 IOCS *This = impl_from_IOleClientSite(iface);
155
156 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
157
158 *ppv = NULL;
159
160 if (IsEqualIID(&IID_IUnknown, riid) ||
161 IsEqualIID(&IID_IOleClientSite, riid))
162 {
163 *ppv = iface;
164 }
165 else if (IsEqualIID(&IID_IOleContainer, riid))
166 {
167 *ppv = &This->IOleContainer_iface;
168 }
169 else if (IsEqualIID(&IID_IOleInPlaceSite, riid) ||
170 IsEqualIID(&IID_IOleInPlaceSiteEx, riid) ||
171 IsEqualIID(&IID_IOleInPlaceSiteWindowless, riid))
172 {
173 *ppv = &This->IOleInPlaceSiteWindowless_iface;
174 }
175 else if (IsEqualIID(&IID_IOleInPlaceFrame, riid))
176 {
177 *ppv = &This->IOleInPlaceFrame_iface;
178 }
179 else if (IsEqualIID(&IID_IOleControlSite, riid))
180 {
181 *ppv = &This->IOleControlSite_iface;
182 }
183
184 if (*ppv)
185 {
186 IOleClientSite_AddRef(iface);
187 return S_OK;
188 }
189
190 WARN("unsupported interface %s\n", debugstr_guid(riid));
191 return E_NOINTERFACE;
192 }
193
194 static ULONG WINAPI OleClientSite_AddRef(IOleClientSite *iface)
195 {
196 IOCS *This = impl_from_IOleClientSite(iface);
197 ULONG ref = InterlockedIncrement(&This->ref);
198 TRACE("(%p)->(%d)\n", This, ref);
199 return ref;
200 }
201
202 static ULONG WINAPI OleClientSite_Release(IOleClientSite *iface)
203 {
204 IOCS *This = impl_from_IOleClientSite(iface);
205 ULONG ref = InterlockedDecrement(&This->ref);
206
207 TRACE("(%p)->(%d)\n", This, ref);
208
209 if (!ref)
210 {
211 IOCS_Detach( This );
212 HeapFree( GetProcessHeap(), 0, This );
213 }
214
215 return ref;
216 }
217
218 static HRESULT WINAPI OleClientSite_SaveObject(IOleClientSite *iface)
219 {
220 IOCS *This = impl_from_IOleClientSite(iface);
221 FIXME( "(%p) - stub\n", This );
222 return E_NOTIMPL;
223 }
224
225 static HRESULT WINAPI OleClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
226 {
227 IOCS *This = impl_from_IOleClientSite(iface);
228
229 FIXME( "(%p, 0x%x, 0x%x, %p)\n", This, dwAssign, dwWhichMoniker, ppmk );
230 return E_NOTIMPL;
231 }
232
233 static HRESULT WINAPI OleClientSite_GetContainer(IOleClientSite *iface, IOleContainer **container)
234 {
235 IOCS *This = impl_from_IOleClientSite(iface);
236 TRACE("(%p, %p)\n", This, container);
237 return IOleClientSite_QueryInterface(iface, &IID_IOleContainer, (void**)container);
238 }
239
240 static HRESULT WINAPI OleClientSite_ShowObject(IOleClientSite *iface)
241 {
242 IOCS *This = impl_from_IOleClientSite(iface);
243 FIXME( "(%p) - stub\n", This );
244 return S_OK;
245 }
246
247 static HRESULT WINAPI OleClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
248 {
249 IOCS *This = impl_from_IOleClientSite(iface);
250 FIXME( "(%p, %s) - stub\n", This, fShow ? "TRUE" : "FALSE" );
251 return E_NOTIMPL;
252 }
253
254 static HRESULT WINAPI OleClientSite_RequestNewObjectLayout(IOleClientSite *iface)
255 {
256 IOCS *This = impl_from_IOleClientSite(iface);
257 FIXME( "(%p) - stub\n", This );
258 return E_NOTIMPL;
259 }
260
261
262 /****** IOleContainer *****/
263 static inline IOCS *impl_from_IOleContainer(IOleContainer *iface)
264 {
265 return CONTAINING_RECORD(iface, IOCS, IOleContainer_iface);
266 }
267
268 static HRESULT WINAPI OleContainer_QueryInterface( IOleContainer* iface, REFIID riid, void** ppv)
269 {
270 IOCS *This = impl_from_IOleContainer(iface);
271 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
272 }
273
274 static ULONG WINAPI OleContainer_AddRef(IOleContainer* iface)
275 {
276 IOCS *This = impl_from_IOleContainer(iface);
277 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
278 }
279
280 static ULONG WINAPI OleContainer_Release(IOleContainer* iface)
281 {
282 IOCS *This = impl_from_IOleContainer(iface);
283 return IOleClientSite_Release(&This->IOleClientSite_iface);
284 }
285
286 static HRESULT WINAPI OleContainer_ParseDisplayName(IOleContainer* iface, IBindCtx* pbc,
287 LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut)
288 {
289 IOCS *This = impl_from_IOleContainer(iface);
290 FIXME( "(%p,%p,%s,%p,%p) - stub\n", This, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut );
291 return E_NOTIMPL;
292 }
293
294 static HRESULT WINAPI OleContainer_EnumObjects(IOleContainer* iface, DWORD grfFlags, IEnumUnknown** ppenum)
295 {
296 IOCS *This = impl_from_IOleContainer(iface);
297 FIXME( "(%p, %u, %p) - stub\n", This, grfFlags, ppenum );
298 return E_NOTIMPL;
299 }
300
301 static HRESULT WINAPI OleContainer_LockContainer(IOleContainer* iface, BOOL fLock)
302 {
303 IOCS *This = impl_from_IOleContainer(iface);
304 FIXME( "(%p, %s) - stub\n", This, fLock?"TRUE":"FALSE" );
305 return E_NOTIMPL;
306 }
307
308
309 /****** IOleInPlaceSiteWindowless *******/
310 static inline IOCS *impl_from_IOleInPlaceSiteWindowless(IOleInPlaceSiteWindowless *iface)
311 {
312 return CONTAINING_RECORD(iface, IOCS, IOleInPlaceSiteWindowless_iface);
313 }
314
315 static HRESULT WINAPI OleInPlaceSiteWindowless_QueryInterface(IOleInPlaceSiteWindowless *iface, REFIID riid, void **ppv)
316 {
317 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
318 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
319 }
320
321 static ULONG WINAPI OleInPlaceSiteWindowless_AddRef(IOleInPlaceSiteWindowless *iface)
322 {
323 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
324 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
325 }
326
327 static ULONG WINAPI OleInPlaceSiteWindowless_Release(IOleInPlaceSiteWindowless *iface)
328 {
329 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
330 return IOleClientSite_Release(&This->IOleClientSite_iface);
331 }
332
333 static HRESULT WINAPI OleInPlaceSiteWindowless_GetWindow(IOleInPlaceSiteWindowless* iface, HWND* phwnd)
334 {
335 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
336
337 TRACE("(%p,%p)\n", This, phwnd);
338 *phwnd = This->hWnd;
339 return S_OK;
340 }
341
342 static HRESULT WINAPI OleInPlaceSiteWindowless_ContextSensitiveHelp(IOleInPlaceSiteWindowless* iface, BOOL fEnterMode)
343 {
344 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
345 FIXME("(%p,%d) - stub\n", This, fEnterMode);
346 return E_NOTIMPL;
347 }
348
349 static HRESULT WINAPI OleInPlaceSiteWindowless_CanInPlaceActivate(IOleInPlaceSiteWindowless *iface)
350 {
351 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
352 TRACE("(%p)\n", This);
353 return S_OK;
354 }
355
356 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceActivate(IOleInPlaceSiteWindowless *iface)
357 {
358 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
359
360 TRACE("(%p)\n", This);
361
362 This->fInPlace = TRUE;
363 return S_OK;
364 }
365
366 static HRESULT WINAPI OleInPlaceSiteWindowless_OnUIActivate(IOleInPlaceSiteWindowless *iface)
367 {
368 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
369
370 TRACE("(%p)\n", This);
371
372 return S_OK;
373 }
374 static HRESULT WINAPI OleInPlaceSiteWindowless_GetWindowContext(IOleInPlaceSiteWindowless *iface,
375 IOleInPlaceFrame **frame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
376 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
377 {
378 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
379
380 TRACE("(%p,%p,%p,%p,%p,%p)\n", This, frame, ppDoc, lprcPosRect, lprcClipRect, lpFrameInfo);
381
382 if ( lprcClipRect )
383 *lprcClipRect = This->size;
384 if ( lprcPosRect )
385 *lprcPosRect = This->size;
386
387 if ( frame )
388 {
389 *frame = &This->IOleInPlaceFrame_iface;
390 IOleInPlaceFrame_AddRef(*frame);
391 }
392
393 if ( ppDoc )
394 *ppDoc = NULL;
395
396 if ( lpFrameInfo )
397 {
398 lpFrameInfo->fMDIApp = FALSE;
399 lpFrameInfo->hwndFrame = This->hWnd;
400 lpFrameInfo->haccel = NULL;
401 lpFrameInfo->cAccelEntries = 0;
402 }
403
404 return S_OK;
405 }
406
407 static HRESULT WINAPI OleInPlaceSiteWindowless_Scroll(IOleInPlaceSiteWindowless *iface, SIZE scrollExtent)
408 {
409 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
410 FIXME("(%p) - stub\n", This);
411 return E_NOTIMPL;
412 }
413
414 static HRESULT WINAPI OleInPlaceSiteWindowless_OnUIDeactivate(IOleInPlaceSiteWindowless *iface, BOOL fUndoable)
415 {
416 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
417 FIXME("(%p,%d) - stub\n", This, fUndoable);
418 return E_NOTIMPL;
419 }
420
421 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceDeactivate(IOleInPlaceSiteWindowless *iface)
422 {
423 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
424
425 TRACE("(%p)\n", This);
426
427 This->fInPlace = This->fWindowless = FALSE;
428 return S_OK;
429 }
430
431 static HRESULT WINAPI OleInPlaceSiteWindowless_DiscardUndoState(IOleInPlaceSiteWindowless *iface)
432 {
433 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
434 FIXME("(%p) - stub\n", This);
435 return E_NOTIMPL;
436 }
437
438 static HRESULT WINAPI OleInPlaceSiteWindowless_DeactivateAndUndo(IOleInPlaceSiteWindowless *iface)
439 {
440 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
441 FIXME("(%p) - stub\n", This);
442 return E_NOTIMPL;
443 }
444
445 static HRESULT WINAPI OleInPlaceSiteWindowless_OnPosRectChange(IOleInPlaceSiteWindowless *iface, LPCRECT lprcPosRect)
446 {
447 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
448 FIXME("(%p,%p) - stub\n", This, lprcPosRect);
449 return E_NOTIMPL;
450 }
451
452 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceActivateEx( IOleInPlaceSiteWindowless *iface, BOOL* pfNoRedraw, DWORD dwFlags)
453 {
454 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
455
456 TRACE("\n");
457
458 This->fActive = This->fInPlace = TRUE;
459 if ( dwFlags & ACTIVATE_WINDOWLESS )
460 This->fWindowless = TRUE;
461 return S_OK;
462 }
463
464 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceDeactivateEx( IOleInPlaceSiteWindowless *iface, BOOL fNoRedraw)
465 {
466 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
467
468 TRACE("\n");
469
470 This->fActive = This->fInPlace = This->fWindowless = FALSE;
471 return S_OK;
472 }
473 static HRESULT WINAPI OleInPlaceSiteWindowless_RequestUIActivate( IOleInPlaceSiteWindowless *iface)
474 {
475 FIXME("\n");
476 return E_NOTIMPL;
477 }
478 static HRESULT WINAPI OleInPlaceSiteWindowless_CanWindowlessActivate( IOleInPlaceSiteWindowless *iface)
479 {
480 FIXME("\n");
481 return S_OK;
482 }
483 static HRESULT WINAPI OleInPlaceSiteWindowless_GetCapture( IOleInPlaceSiteWindowless *iface)
484 {
485 FIXME("\n");
486 return E_NOTIMPL;
487 }
488 static HRESULT WINAPI OleInPlaceSiteWindowless_SetCapture( IOleInPlaceSiteWindowless *iface, BOOL fCapture)
489 {
490 FIXME("\n");
491 return E_NOTIMPL;
492 }
493 static HRESULT WINAPI OleInPlaceSiteWindowless_GetFocus( IOleInPlaceSiteWindowless *iface)
494 {
495 FIXME("\n");
496 return E_NOTIMPL;
497 }
498 static HRESULT WINAPI OleInPlaceSiteWindowless_SetFocus( IOleInPlaceSiteWindowless *iface, BOOL fFocus)
499 {
500 FIXME("\n");
501 return E_NOTIMPL;
502 }
503 static HRESULT WINAPI OleInPlaceSiteWindowless_GetDC( IOleInPlaceSiteWindowless *iface, LPCRECT pRect, DWORD grfFlags, HDC* phDC)
504 {
505 FIXME("\n");
506 return E_NOTIMPL;
507 }
508 static HRESULT WINAPI OleInPlaceSiteWindowless_ReleaseDC( IOleInPlaceSiteWindowless *iface, HDC hDC)
509 {
510 FIXME("\n");
511 return E_NOTIMPL;
512 }
513 static HRESULT WINAPI OleInPlaceSiteWindowless_InvalidateRect( IOleInPlaceSiteWindowless *iface, LPCRECT pRect, BOOL fErase)
514 {
515 FIXME("\n");
516 return E_NOTIMPL;
517 }
518 static HRESULT WINAPI OleInPlaceSiteWindowless_InvalidateRgn( IOleInPlaceSiteWindowless *iface, HRGN hRGN, BOOL fErase)
519 {
520 FIXME("\n");
521 return E_NOTIMPL;
522 }
523 static HRESULT WINAPI OleInPlaceSiteWindowless_ScrollRect( IOleInPlaceSiteWindowless *iface, INT dx, INT dy, LPCRECT pRectScroll, LPCRECT pRectClip)
524 {
525 FIXME("\n");
526 return E_NOTIMPL;
527 }
528 static HRESULT WINAPI OleInPlaceSiteWindowless_AdjustRect( IOleInPlaceSiteWindowless *iface, LPRECT prc)
529 {
530 FIXME("\n");
531 return E_NOTIMPL;
532 }
533 static HRESULT WINAPI OleInPlaceSiteWindowless_OnDefWindowMessage( IOleInPlaceSiteWindowless *iface, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult)
534 {
535 FIXME("\n");
536 return E_NOTIMPL;
537 }
538
539
540 /****** IOleInPlaceFrame *******/
541 static inline IOCS *impl_from_IOleInPlaceFrame(IOleInPlaceFrame *iface)
542 {
543 return CONTAINING_RECORD(iface, IOCS, IOleInPlaceFrame_iface);
544 }
545
546 static HRESULT WINAPI OleInPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
547 {
548 IOCS *This = impl_from_IOleInPlaceFrame(iface);
549 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
550 }
551
552 static ULONG WINAPI OleInPlaceFrame_AddRef(IOleInPlaceFrame *iface)
553 {
554 IOCS *This = impl_from_IOleInPlaceFrame(iface);
555 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
556 }
557
558 static ULONG WINAPI OleInPlaceFrame_Release(IOleInPlaceFrame *iface)
559 {
560 IOCS *This = impl_from_IOleInPlaceFrame(iface);
561 return IOleClientSite_Release(&This->IOleClientSite_iface);
562 }
563
564 static HRESULT WINAPI OleInPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phWnd)
565 {
566 IOCS *This = impl_from_IOleInPlaceFrame(iface);
567
568 TRACE( "(%p,%p)\n", This, phWnd );
569
570 *phWnd = This->hWnd;
571 return S_OK;
572 }
573
574 static HRESULT WINAPI OleInPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
575 {
576 IOCS *This = impl_from_IOleInPlaceFrame(iface);
577
578 FIXME( "(%p,%d) - stub\n", This, fEnterMode );
579 return E_NOTIMPL;
580 }
581
582 static HRESULT WINAPI OleInPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
583 {
584 IOCS *This = impl_from_IOleInPlaceFrame(iface);
585
586 FIXME( "(%p,%p) - stub\n", This, lprectBorder );
587 return E_NOTIMPL;
588 }
589
590 static HRESULT WINAPI OleInPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths)
591 {
592 IOCS *This = impl_from_IOleInPlaceFrame(iface);
593
594 FIXME( "(%p,%p) - stub\n", This, pborderwidths );
595 return E_NOTIMPL;
596 }
597
598 static HRESULT WINAPI OleInPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths)
599 {
600 IOCS *This = impl_from_IOleInPlaceFrame(iface);
601
602 FIXME( "(%p,%p) - stub\n", This, pborderwidths );
603 return E_NOTIMPL;
604 }
605
606 static HRESULT WINAPI OleInPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface, IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
607 {
608 IOCS *This = impl_from_IOleInPlaceFrame(iface);
609
610 FIXME( "(%p,%p,%s) - stub\n", This, pActiveObject, debugstr_w(pszObjName) );
611 return S_OK;
612 }
613
614 static HRESULT WINAPI OleInPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
615 {
616 IOCS *This = impl_from_IOleInPlaceFrame(iface);
617
618 FIXME( "(%p,%p,%p) - stub\n", This, hmenuShared, lpMenuWidths );
619 return E_NOTIMPL;
620 }
621
622 static HRESULT WINAPI OleInPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
623 {
624 IOCS *This = impl_from_IOleInPlaceFrame(iface);
625
626 FIXME( "(%p,%p,%p,%p) - stub\n", This, hmenuShared, holemenu, hwndActiveObject );
627 return E_NOTIMPL;
628 }
629
630 static HRESULT WINAPI OleInPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
631 {
632 IOCS *This = impl_from_IOleInPlaceFrame(iface);
633
634 FIXME( "(%p, %p) - stub\n", This, hmenuShared );
635 return E_NOTIMPL;
636 }
637
638 static HRESULT WINAPI OleInPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
639 {
640 IOCS *This = impl_from_IOleInPlaceFrame(iface);
641
642 FIXME( "(%p, %s) - stub\n", This, debugstr_w( pszStatusText ) );
643 return E_NOTIMPL;
644 }
645
646 static HRESULT WINAPI OleInPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
647 {
648 IOCS *This = impl_from_IOleInPlaceFrame(iface);
649
650 FIXME( "(%p, %d) - stub\n", This, fEnable );
651 return E_NOTIMPL;
652 }
653
654 static HRESULT WINAPI OleInPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
655 {
656 IOCS *This = impl_from_IOleInPlaceFrame(iface);
657
658 FIXME( "(%p, %p, %x) - stub\n", This, lpmsg, wID );
659 return E_NOTIMPL;
660 }
661
662
663 /****** IOleControlSite *******/
664 static inline IOCS *impl_from_IOleControlSite(IOleControlSite *iface)
665 {
666 return CONTAINING_RECORD(iface, IOCS, IOleControlSite_iface);
667 }
668
669 static HRESULT WINAPI OleControlSite_QueryInterface(IOleControlSite *iface, REFIID riid, void **ppv)
670 {
671 IOCS *This = impl_from_IOleControlSite(iface);
672 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
673 }
674
675 static ULONG WINAPI OleControlSite_AddRef(IOleControlSite *iface)
676 {
677 IOCS *This = impl_from_IOleControlSite(iface);
678 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
679 }
680
681 static ULONG WINAPI OleControlSite_Release(IOleControlSite *iface)
682 {
683 IOCS *This = impl_from_IOleControlSite(iface);
684 return IOleClientSite_Release(&This->IOleClientSite_iface);
685 }
686
687 static HRESULT WINAPI OleControlSite_OnControlInfoChanged( IOleControlSite* This)
688 {
689 FIXME( "\n" );
690 return E_NOTIMPL;
691 }
692 static HRESULT WINAPI OleControlSite_LockInPlaceActive( IOleControlSite* This, BOOL fLock)
693 {
694 FIXME( "\n" );
695 return E_NOTIMPL;
696 }
697 static HRESULT WINAPI OleControlSite_GetExtendedControl( IOleControlSite* This, IDispatch** ppDisp)
698 {
699 FIXME( "\n" );
700 return E_NOTIMPL;
701 }
702 static HRESULT WINAPI OleControlSite_TransformCoords( IOleControlSite* This, POINTL* pPtlHimetric, POINTF* pPtfContainer, DWORD dwFlags)
703 {
704 FIXME( "\n" );
705 return E_NOTIMPL;
706 }
707 static HRESULT WINAPI OleControlSite_TranslateAccelerator( IOleControlSite* This, MSG* pMsg, DWORD grfModifiers)
708 {
709 FIXME( "\n" );
710 return E_NOTIMPL;
711 }
712 static HRESULT WINAPI OleControlSite_OnFocus( IOleControlSite* This, BOOL fGotFocus)
713 {
714 FIXME( "\n" );
715 return E_NOTIMPL;
716 }
717 static HRESULT WINAPI OleControlSite_ShowPropertyFrame( IOleControlSite* This)
718 {
719 FIXME( "\n" );
720 return E_NOTIMPL;
721 }
722
723
724 static const IOleClientSiteVtbl OleClientSite_vtbl = {
725 OleClientSite_QueryInterface,
726 OleClientSite_AddRef,
727 OleClientSite_Release,
728 OleClientSite_SaveObject,
729 OleClientSite_GetMoniker,
730 OleClientSite_GetContainer,
731 OleClientSite_ShowObject,
732 OleClientSite_OnShowWindow,
733 OleClientSite_RequestNewObjectLayout
734 };
735 static const IOleContainerVtbl OleContainer_vtbl = {
736 OleContainer_QueryInterface,
737 OleContainer_AddRef,
738 OleContainer_Release,
739 OleContainer_ParseDisplayName,
740 OleContainer_EnumObjects,
741 OleContainer_LockContainer
742 };
743 static const IOleInPlaceSiteWindowlessVtbl OleInPlaceSiteWindowless_vtbl = {
744 OleInPlaceSiteWindowless_QueryInterface,
745 OleInPlaceSiteWindowless_AddRef,
746 OleInPlaceSiteWindowless_Release,
747 OleInPlaceSiteWindowless_GetWindow,
748 OleInPlaceSiteWindowless_ContextSensitiveHelp,
749 OleInPlaceSiteWindowless_CanInPlaceActivate,
750 OleInPlaceSiteWindowless_OnInPlaceActivate,
751 OleInPlaceSiteWindowless_OnUIActivate,
752 OleInPlaceSiteWindowless_GetWindowContext,
753 OleInPlaceSiteWindowless_Scroll,
754 OleInPlaceSiteWindowless_OnUIDeactivate,
755 OleInPlaceSiteWindowless_OnInPlaceDeactivate,
756 OleInPlaceSiteWindowless_DiscardUndoState,
757 OleInPlaceSiteWindowless_DeactivateAndUndo,
758 OleInPlaceSiteWindowless_OnPosRectChange,
759 OleInPlaceSiteWindowless_OnInPlaceActivateEx,
760 OleInPlaceSiteWindowless_OnInPlaceDeactivateEx,
761 OleInPlaceSiteWindowless_RequestUIActivate,
762 OleInPlaceSiteWindowless_CanWindowlessActivate,
763 OleInPlaceSiteWindowless_GetCapture,
764 OleInPlaceSiteWindowless_SetCapture,
765 OleInPlaceSiteWindowless_GetFocus,
766 OleInPlaceSiteWindowless_SetFocus,
767 OleInPlaceSiteWindowless_GetDC,
768 OleInPlaceSiteWindowless_ReleaseDC,
769 OleInPlaceSiteWindowless_InvalidateRect,
770 OleInPlaceSiteWindowless_InvalidateRgn,
771 OleInPlaceSiteWindowless_ScrollRect,
772 OleInPlaceSiteWindowless_AdjustRect,
773 OleInPlaceSiteWindowless_OnDefWindowMessage
774 };
775 static const IOleInPlaceFrameVtbl OleInPlaceFrame_vtbl =
776 {
777 OleInPlaceFrame_QueryInterface,
778 OleInPlaceFrame_AddRef,
779 OleInPlaceFrame_Release,
780 OleInPlaceFrame_GetWindow,
781 OleInPlaceFrame_ContextSensitiveHelp,
782 OleInPlaceFrame_GetBorder,
783 OleInPlaceFrame_RequestBorderSpace,
784 OleInPlaceFrame_SetBorderSpace,
785 OleInPlaceFrame_SetActiveObject,
786 OleInPlaceFrame_InsertMenus,
787 OleInPlaceFrame_SetMenu,
788 OleInPlaceFrame_RemoveMenus,
789 OleInPlaceFrame_SetStatusText,
790 OleInPlaceFrame_EnableModeless,
791 OleInPlaceFrame_TranslateAccelerator
792 };
793 static const IOleControlSiteVtbl OleControlSite_vtbl =
794 {
795 OleControlSite_QueryInterface,
796 OleControlSite_AddRef,
797 OleControlSite_Release,
798 OleControlSite_OnControlInfoChanged,
799 OleControlSite_LockInPlaceActive,
800 OleControlSite_GetExtendedControl,
801 OleControlSite_TransformCoords,
802 OleControlSite_TranslateAccelerator,
803 OleControlSite_OnFocus,
804 OleControlSite_ShowPropertyFrame
805 };
806
807 static void IOCS_OnSize( IOCS* This, LPCRECT rect )
808 {
809 SIZEL inPix, inHi;
810
811 This->size.left = rect->left; This->size.right = rect->right; This->size.top = rect->top; This->size.bottom = rect->bottom;
812
813 if ( !This->control )
814 return;
815
816 inPix.cx = rect->right - rect->left;
817 inPix.cy = rect->bottom - rect->top;
818 AtlPixelToHiMetric( &inPix, &inHi );
819 IOleObject_SetExtent( This->control, DVASPECT_CONTENT, &inHi );
820
821 if ( This->fInPlace )
822 {
823 IOleInPlaceObject *wl;
824
825 if ( SUCCEEDED( IOleObject_QueryInterface( This->control, &IID_IOleInPlaceObject, (void**)&wl ) ) )
826 {
827 IOleInPlaceObject_SetObjectRects( wl, rect, rect );
828 IOleInPlaceObject_Release( wl );
829 }
830 }
831 }
832
833 static void IOCS_OnShow( IOCS *This, BOOL fShow )
834 {
835 if (!This->control || This->fActive || !fShow )
836 return;
837
838 This->fActive = TRUE;
839 }
840
841 static void IOCS_OnDraw( IOCS *This )
842 {
843 IViewObject *view;
844
845 if ( !This->control || !This->fWindowless )
846 return;
847
848 if ( SUCCEEDED( IOleObject_QueryInterface( This->control, &IID_IViewObject, (void**)&view ) ) )
849 {
850 HDC dc = GetDC( This->hWnd );
851 RECTL rect;
852
853 rect.left = This->size.left; rect.top = This->size.top;
854 rect.bottom = This->size.bottom; rect.right = This->size.right;
855
856 IViewObject_Draw( view, DVASPECT_CONTENT, ~0, NULL, NULL, 0, dc, &rect, &rect, NULL, 0 );
857 IViewObject_Release( view );
858 ReleaseDC( This->hWnd, dc );
859 }
860 }
861
862 static LRESULT IOCS_OnWndProc( IOCS *This, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
863 {
864 WNDPROC OrigWndProc = This->OrigWndProc;
865
866 switch( uMsg )
867 {
868 case WM_DESTROY:
869 IOCS_Detach( This );
870 break;
871 case WM_SIZE:
872 {
873 RECT r;
874 r.left = r.top = 0;
875 r.right = LOWORD( lParam );
876 r.bottom = HIWORD( lParam );
877 IOCS_OnSize( This, &r );
878 }
879 break;
880 case WM_SHOWWINDOW:
881 IOCS_OnShow( This, (BOOL) wParam );
882 break;
883 case WM_PAINT:
884 IOCS_OnDraw( This );
885 break;
886 }
887
888 return CallWindowProcW( OrigWndProc, hWnd, uMsg, wParam, lParam );
889 }
890
891 static LRESULT CALLBACK AtlHost_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
892 {
893 IOCS *This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA );
894 return IOCS_OnWndProc( This, hWnd, wMsg, wParam, lParam );
895 }
896
897 static HRESULT IOCS_Attach( IOCS *This, HWND hWnd, IUnknown *pUnkControl ) /* subclass hWnd */
898 {
899 This->hWnd = hWnd;
900 IUnknown_QueryInterface( pUnkControl, &IID_IOleObject, (void**)&This->control );
901 IOleObject_SetClientSite( This->control, &This->IOleClientSite_iface );
902 SetWindowLongPtrW( hWnd, GWLP_USERDATA, (ULONG_PTR) This );
903 This->OrigWndProc = (WNDPROC)SetWindowLongPtrW( hWnd, GWLP_WNDPROC, (ULONG_PTR) AtlHost_wndproc );
904
905 return S_OK;
906 }
907
908 static HRESULT IOCS_Init( IOCS *This )
909 {
910 RECT rect;
911 static const WCHAR AXWIN[] = {'A','X','W','I','N',0};
912
913 IOleObject_SetHostNames( This->control, AXWIN, AXWIN );
914
915 GetClientRect( This->hWnd, &rect );
916 IOCS_OnSize( This, &rect );
917 IOleObject_DoVerb( This->control, OLEIVERB_INPLACEACTIVATE, NULL, &This->IOleClientSite_iface,
918 0, This->hWnd, &rect );
919
920 return S_OK;
921 }
922
923 /**********************************************************************
924 * Create new instance of Atl host component and attach it to window *
925 */
926 static HRESULT IOCS_Create( HWND hWnd, IUnknown *pUnkControl, IUnknown **container )
927 {
928 HRESULT hr;
929 IOCS *This;
930
931 if (!container)
932 return S_OK;
933
934 *container = NULL;
935 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IOCS));
936
937 if (!This)
938 return E_OUTOFMEMORY;
939
940 This->IOleClientSite_iface.lpVtbl = &OleClientSite_vtbl;
941 This->IOleContainer_iface.lpVtbl = &OleContainer_vtbl;
942 This->IOleInPlaceSiteWindowless_iface.lpVtbl = &OleInPlaceSiteWindowless_vtbl;
943 This->IOleInPlaceFrame_iface.lpVtbl = &OleInPlaceFrame_vtbl;
944 This->IOleControlSite_iface.lpVtbl = &OleControlSite_vtbl;
945 This->ref = 1;
946
947 This->OrigWndProc = NULL;
948 This->hWnd = NULL;
949 This->fWindowless = This->fActive = This->fInPlace = FALSE;
950
951 hr = IOCS_Attach( This, hWnd, pUnkControl );
952 if ( SUCCEEDED( hr ) )
953 hr = IOCS_Init( This );
954 if ( SUCCEEDED( hr ) )
955 *container = (IUnknown*)&This->IOleClientSite_iface;
956 else
957 {
958 IOCS_Detach( This );
959 HeapFree(GetProcessHeap(), 0, This);
960 }
961
962 return hr;
963 }
964
965
966 /***********************************************************************
967 * AtlAxCreateControl [atl100.@]
968 */
969 HRESULT WINAPI AtlAxCreateControl(LPCOLESTR lpszName, HWND hWnd,
970 IStream *pStream, IUnknown **ppUnkContainer)
971 {
972 return AtlAxCreateControlEx( lpszName, hWnd, pStream, ppUnkContainer,
973 NULL, NULL, NULL );
974 }
975
976 /***********************************************************************
977 * AtlAxCreateControlEx [atl100.@]
978 *
979 * REMARKS
980 * See http://www.codeproject.com/com/cwebpage.asp for some background
981 *
982 */
983 HRESULT WINAPI AtlAxCreateControlEx(LPCOLESTR lpszName, HWND hWnd,
984 IStream *pStream, IUnknown **ppUnkContainer, IUnknown **ppUnkControl,
985 REFIID iidSink, IUnknown *punkSink)
986 {
987 CLSID controlId;
988 HRESULT hRes;
989 IOleObject *pControl;
990 IUnknown *pUnkControl;
991 IPersistStreamInit *pPSInit;
992 IUnknown *pContainer;
993 enum {IsGUID=0,IsHTML=1,IsURL=2} content;
994
995 TRACE("(%s %p %p %p %p %p %p)\n", debugstr_w(lpszName), hWnd, pStream,
996 ppUnkContainer, ppUnkControl, iidSink, punkSink);
997
998 hRes = CLSIDFromString( lpszName, &controlId );
999 if ( FAILED(hRes) )
1000 hRes = CLSIDFromProgID( lpszName, &controlId );
1001 if ( SUCCEEDED( hRes ) )
1002 content = IsGUID;
1003 else {
1004 /* FIXME - check for MSHTML: prefix! */
1005 content = IsURL;
1006 controlId = CLSID_WebBrowser;
1007 }
1008
1009 hRes = CoCreateInstance( &controlId, 0, CLSCTX_ALL, &IID_IOleObject,
1010 (void**) &pControl );
1011 if ( FAILED( hRes ) )
1012 {
1013 WARN( "cannot create ActiveX control %s instance - error 0x%08x\n",
1014 debugstr_guid( &controlId ), hRes );
1015 return hRes;
1016 }
1017
1018 hRes = IOleObject_QueryInterface( pControl, &IID_IPersistStreamInit, (void**) &pPSInit );
1019 if ( SUCCEEDED( hRes ) )
1020 {
1021 if (!pStream)
1022 IPersistStreamInit_InitNew( pPSInit );
1023 else
1024 IPersistStreamInit_Load( pPSInit, pStream );
1025 IPersistStreamInit_Release( pPSInit );
1026 } else
1027 WARN("cannot get IID_IPersistStreamInit out of control\n");
1028
1029 IOleObject_QueryInterface( pControl, &IID_IUnknown, (void**) &pUnkControl );
1030 IOleObject_Release( pControl );
1031
1032
1033 hRes = AtlAxAttachControl( pUnkControl, hWnd, &pContainer );
1034 if ( FAILED( hRes ) )
1035 WARN("cannot attach control to window\n");
1036
1037 if ( content == IsURL )
1038 {
1039 IWebBrowser2 *browser;
1040
1041 hRes = IOleObject_QueryInterface( pControl, &IID_IWebBrowser2, (void**) &browser );
1042 if ( !browser )
1043 WARN( "Cannot query IWebBrowser2 interface: %08x\n", hRes );
1044 else {
1045 VARIANT url;
1046
1047 IWebBrowser2_put_Visible( browser, VARIANT_TRUE ); /* it seems that native does this on URL (but do not on MSHTML:! why? */
1048
1049 V_VT(&url) = VT_BSTR;
1050 V_BSTR(&url) = SysAllocString( lpszName );
1051
1052 hRes = IWebBrowser2_Navigate2( browser, &url, NULL, NULL, NULL, NULL );
1053 if ( FAILED( hRes ) )
1054 WARN( "IWebBrowser2::Navigate2 failed: %08x\n", hRes );
1055 SysFreeString( V_BSTR(&url) );
1056
1057 IWebBrowser2_Release( browser );
1058 }
1059 }
1060
1061 if (ppUnkContainer)
1062 {
1063 *ppUnkContainer = pContainer;
1064 if ( pContainer )
1065 IUnknown_AddRef( pContainer );
1066 }
1067 if (ppUnkControl)
1068 {
1069 *ppUnkControl = pUnkControl;
1070 if ( pUnkControl )
1071 IUnknown_AddRef( pUnkControl );
1072 }
1073
1074 if ( pUnkControl )
1075 IUnknown_Release( pUnkControl );
1076 if ( pContainer )
1077 IUnknown_Release( pContainer );
1078
1079 return S_OK;
1080 }
1081
1082 /***********************************************************************
1083 * AtlAxAttachControl [atl100.@]
1084 */
1085 HRESULT WINAPI AtlAxAttachControl(IUnknown *control, HWND hWnd, IUnknown **container)
1086 {
1087 HRESULT hr;
1088
1089 TRACE("(%p %p %p)\n", control, hWnd, container);
1090
1091 if (!control)
1092 return E_INVALIDARG;
1093
1094 hr = IOCS_Create( hWnd, control, container );
1095 return hWnd ? hr : S_FALSE;
1096 }
1097
1098 /**********************************************************************
1099 * Helper function for AX_ConvertDialogTemplate
1100 */
1101 static inline BOOL advance_array(WORD **pptr, DWORD *palloc, DWORD *pfilled, const WORD *data, DWORD size)
1102 {
1103 if ( (*pfilled + size) > *palloc )
1104 {
1105 *palloc = ((*pfilled+size) + 0xFF) & ~0xFF;
1106 *pptr = HeapReAlloc( GetProcessHeap(), 0, *pptr, *palloc * sizeof(WORD) );
1107 if (!*pptr)
1108 return FALSE;
1109 }
1110 RtlMoveMemory( *pptr+*pfilled, data, size * sizeof(WORD) );
1111 *pfilled += size;
1112 return TRUE;
1113 }
1114
1115 /**********************************************************************
1116 * Convert ActiveX control templates to AtlAxWin class instances
1117 */
1118 static LPDLGTEMPLATEW AX_ConvertDialogTemplate(LPCDLGTEMPLATEW src_tmpl)
1119 {
1120 #define GET_WORD(x) (*(const WORD *)(x))
1121 #define GET_DWORD(x) (*(const DWORD *)(x))
1122 #define PUT_BLOCK(x,y) do {if (!advance_array(&output, &allocated, &filled, (x), (y))) return NULL;} while (0)
1123 #define PUT_WORD(x) do {WORD w = (x);PUT_BLOCK(&w, 1);} while(0)
1124 #define PUT_DWORD(x) do {DWORD w = (x);PUT_BLOCK(&w, 2);} while(0)
1125 const WORD *tmp, *src = (const WORD *)src_tmpl;
1126 WORD *output;
1127 DWORD allocated, filled; /* in WORDs */
1128 BOOL ext;
1129 WORD signature, dlgver, rescount;
1130 DWORD style;
1131
1132 filled = 0; allocated = 256;
1133 output = HeapAlloc( GetProcessHeap(), 0, allocated * sizeof(WORD) );
1134 if (!output)
1135 return NULL;
1136
1137 /* header */
1138 tmp = src;
1139 signature = GET_WORD(src);
1140 dlgver = GET_WORD(src + 1);
1141 if (signature == 1 && dlgver == 0xFFFF)
1142 {
1143 ext = TRUE;
1144 src += 6;
1145 style = GET_DWORD(src);
1146 src += 2;
1147 rescount = GET_WORD(src++);
1148 src += 4;
1149 if ( GET_WORD(src) == 0xFFFF ) /* menu */
1150 src += 2;
1151 else
1152 src += strlenW(src) + 1;
1153 if ( GET_WORD(src) == 0xFFFF ) /* class */
1154 src += 2;
1155 else
1156 src += strlenW(src) + 1;
1157 src += strlenW(src) + 1; /* title */
1158 if ( style & (DS_SETFONT | DS_SHELLFONT) )
1159 {
1160 src += 3;
1161 src += strlenW(src) + 1;
1162 }
1163 } else {
1164 ext = FALSE;
1165 style = GET_DWORD(src);
1166 src += 4;
1167 rescount = GET_WORD(src++);
1168 src += 4;
1169 if ( GET_WORD(src) == 0xFFFF ) /* menu */
1170 src += 2;
1171 else
1172 src += strlenW(src) + 1;
1173 if ( GET_WORD(src) == 0xFFFF ) /* class */
1174 src += 2;
1175 else
1176 src += strlenW(src) + 1;
1177 src += strlenW(src) + 1; /* title */
1178 if ( style & DS_SETFONT )
1179 {
1180 src++;
1181 src += strlenW(src) + 1;
1182 }
1183 }
1184 PUT_BLOCK(tmp, src-tmp);
1185
1186 while(rescount--)
1187 {
1188 src = (const WORD *)( ( ((ULONG_PTR)src) + 3) & ~3); /* align on DWORD boundary */
1189 filled = (filled + 1) & ~1; /* depends on DWORD-aligned allocation unit */
1190
1191 tmp = src;
1192 if (ext)
1193 src += 12;
1194 else
1195 src += 9;
1196 PUT_BLOCK(tmp, src-tmp);
1197
1198 tmp = src;
1199 if ( GET_WORD(src) == 0xFFFF ) /* class */
1200 {
1201 src += 2;
1202 } else
1203 {
1204 src += strlenW(src) + 1;
1205 }
1206 src += strlenW(src) + 1; /* title */
1207 if ( GET_WORD(tmp) == '{' ) /* all this mess created because of this line */
1208 {
1209 static const WCHAR AtlAxWin[] = {'A','t','l','A','x','W','i','n', 0};
1210 PUT_BLOCK(AtlAxWin, sizeof(AtlAxWin)/sizeof(WCHAR));
1211 PUT_BLOCK(tmp, strlenW(tmp)+1);
1212 } else
1213 PUT_BLOCK(tmp, src-tmp);
1214
1215 if ( GET_WORD(src) )
1216 {
1217 WORD size = (GET_WORD(src)+sizeof(WORD)-1) / sizeof(WORD); /* quite ugly :( Maybe use BYTE* instead of WORD* everywhere ? */
1218 PUT_BLOCK(src, size);
1219 src+=size;
1220 }
1221 else
1222 {
1223 PUT_WORD(0);
1224 src++;
1225 }
1226 }
1227 return (LPDLGTEMPLATEW) output;
1228 }
1229
1230 /***********************************************************************
1231 * AtlAxCreateDialogA [atl100.@]
1232 *
1233 * Creates a dialog window
1234 *
1235 * PARAMS
1236 * hInst [I] Application instance
1237 * name [I] Dialog box template name
1238 * owner [I] Dialog box parent HWND
1239 * dlgProc [I] Dialog box procedure
1240 * param [I] This value will be passed to dlgProc as WM_INITDIALOG's message lParam
1241 *
1242 * RETURNS
1243 * Window handle of dialog window.
1244 */
1245 HWND WINAPI AtlAxCreateDialogA(HINSTANCE hInst, LPCSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param)
1246 {
1247 HWND res = NULL;
1248 int length;
1249 WCHAR *nameW;
1250
1251 if (IS_INTRESOURCE(name))
1252 return AtlAxCreateDialogW( hInst, (LPCWSTR) name, owner, dlgProc, param );
1253
1254 length = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
1255 nameW = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) );
1256 if (nameW)
1257 {
1258 MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, length );
1259 res = AtlAxCreateDialogW( hInst, nameW, owner, dlgProc, param );
1260 HeapFree( GetProcessHeap(), 0, nameW );
1261 }
1262 return res;
1263 }
1264
1265 /***********************************************************************
1266 * AtlAxCreateDialogW [atl100.@]
1267 *
1268 * See AtlAxCreateDialogA
1269 *
1270 */
1271 HWND WINAPI AtlAxCreateDialogW(HINSTANCE hInst, LPCWSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param)
1272 {
1273 HRSRC hrsrc;
1274 HGLOBAL hgl;
1275 LPCDLGTEMPLATEW ptr;
1276 LPDLGTEMPLATEW newptr;
1277 HWND res;
1278
1279 TRACE("(%p %s %p %p %lx)\n", hInst, debugstr_w(name), owner, dlgProc, param);
1280
1281 hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG );
1282 if ( !hrsrc )
1283 return NULL;
1284 hgl = LoadResource (hInst, hrsrc);
1285 if ( !hgl )
1286 return NULL;
1287 ptr = LockResource ( hgl );
1288 if (!ptr)
1289 {
1290 FreeResource( hgl );
1291 return NULL;
1292 }
1293 newptr = AX_ConvertDialogTemplate( ptr );
1294 if ( newptr )
1295 {
1296 res = CreateDialogIndirectParamW( hInst, newptr, owner, dlgProc, param );
1297 HeapFree( GetProcessHeap(), 0, newptr );
1298 } else
1299 res = NULL;
1300 FreeResource ( hrsrc );
1301 return res;
1302 }
1303
1304 /***********************************************************************
1305 * AtlAxGetHost [atl100.@]
1306 *
1307 */
1308 HRESULT WINAPI AtlAxGetHost(HWND hWnd, IUnknown **host)
1309 {
1310 IOCS *This;
1311
1312 TRACE("(%p, %p)\n", hWnd, host);
1313
1314 *host = NULL;
1315
1316 This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA );
1317 if ( !This )
1318 {
1319 WARN("No container attached to %p\n", hWnd );
1320 return E_FAIL;
1321 }
1322
1323 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, &IID_IUnknown, (void**)host);
1324 }
1325
1326 /***********************************************************************
1327 * AtlAxGetControl [atl100.@]
1328 *
1329 */
1330 HRESULT WINAPI AtlAxGetControl(HWND hWnd, IUnknown **pUnk)
1331 {
1332 IOCS *This;
1333
1334 TRACE( "(%p, %p)\n", hWnd, pUnk );
1335
1336 *pUnk = NULL;
1337
1338 This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA );
1339 if ( !This || !This->control )
1340 {
1341 WARN("No control attached to %p\n", hWnd );
1342 return E_FAIL;
1343 }
1344
1345 return IOleObject_QueryInterface( This->control, &IID_IUnknown, (void**) pUnk );
1346 }
1347
1348 /***********************************************************************
1349 * AtlAxDialogBoxW [atl100.35]
1350 *
1351 */
1352 INT_PTR WINAPI AtlAxDialogBoxW(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogProc,
1353 LPARAM dwInitParam)
1354 {
1355 FIXME("(%p %s %p %p %lx)\n", hInstance, debugstr_w(lpTemplateName), hWndParent, lpDialogProc, dwInitParam);
1356 return 0;
1357 }
1358
1359 /***********************************************************************
1360 * AtlAxDialogBoxA [atl100.36]
1361 *
1362 */
1363 INT_PTR WINAPI AtlAxDialogBoxA(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogProc,
1364 LPARAM dwInitParam)
1365 {
1366 FIXME("(%p %s %p %p %lx)\n", hInstance, debugstr_a(lpTemplateName), hWndParent, lpDialogProc, dwInitParam);
1367 return 0;
1368 }
1369
1370 #if _ATL_VER >= _ATL_VER_80
1371
1372 /***********************************************************************
1373 * AtlAxCreateControlLic [atl100.59]
1374 *
1375 */
1376 HRESULT WINAPI AtlAxCreateControlLic(const WCHAR *lpTricsData, HWND hwnd, IStream *stream, IUnknown **container, BSTR lic)
1377 {
1378 FIXME("(%s %p %p %p %s)\n", debugstr_w(lpTricsData), hwnd, stream, container, debugstr_w(lic));
1379 return E_NOTIMPL;
1380 }
1381
1382 /***********************************************************************
1383 * AtlAxCreateControlLicEx [atl100.60]
1384 *
1385 */
1386 HRESULT WINAPI AtlAxCreateControlLicEx(const WCHAR *lpTricsData, HWND hwnd, IStream *stream,
1387 IUnknown **container, IUnknown **control, REFIID iidSink, IUnknown *punkSink, BSTR lic)
1388 {
1389 FIXME("(%s %p %p %p %p %s %p %s)\n", debugstr_w(lpTricsData), hwnd, stream, container, control,
1390 debugstr_guid(iidSink), punkSink, debugstr_w(lic));
1391 return E_NOTIMPL;
1392 }
1393
1394 #endif