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