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