Release 9.12.
[wine.git] / dlls / atl / atl_ax.c
blob4ff0a796d3b409fea0f5fd76937a9bc7e5d585ef
1 /*
2 * Active Template Library ActiveX functions (atl.dll)
4 * Copyright 2006 Andrey Turkin
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.
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.
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winerror.h"
29 #include "winuser.h"
30 #include "wine/debug.h"
31 #include "objbase.h"
32 #include "objidl.h"
33 #include "ole2.h"
34 #include "exdisp.h"
35 #include "atlbase.h"
36 #include "atliface.h"
37 #include "atlwin.h"
38 #include "shlwapi.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(atl);
43 typedef struct IOCS {
44 IOleClientSite IOleClientSite_iface;
45 IOleContainer IOleContainer_iface;
46 IOleInPlaceSiteWindowless IOleInPlaceSiteWindowless_iface;
47 IOleInPlaceFrame IOleInPlaceFrame_iface;
48 IOleControlSite IOleControlSite_iface;
50 LONG ref;
51 HWND hWnd;
52 IOleObject *control;
53 RECT size;
54 WNDPROC OrigWndProc;
55 BOOL fActive, fInPlace, fWindowless;
56 } IOCS;
58 /**********************************************************************
59 * AtlAxWin class window procedure
61 static LRESULT CALLBACK AtlAxWin_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
63 if ( wMsg == WM_CREATE )
65 DWORD len = GetWindowTextLengthW( hWnd ) + 1;
66 WCHAR *ptr = malloc( len*sizeof(WCHAR) );
67 if (!ptr)
68 return 1;
69 GetWindowTextW( hWnd, ptr, len );
70 AtlAxCreateControlEx( ptr, hWnd, NULL, NULL, NULL, NULL, NULL );
71 free( ptr );
72 return 0;
74 return DefWindowProcW( hWnd, wMsg, wParam, lParam );
77 /***********************************************************************
78 * AtlAxWinInit [atl100.@]
79 * Initializes the control-hosting code: registering the AtlAxWin,
80 * AtlAxWin7 and AtlAxWinLic7 window classes and some messages.
82 * RETURNS
83 * TRUE or FALSE
86 BOOL WINAPI AtlAxWinInit(void)
88 WNDCLASSEXW wcex;
90 #if _ATL_VER <= _ATL_VER_30
91 #define ATL_NAME_SUFFIX
92 #elif _ATL_VER == _ATL_VER_80
93 #define ATL_NAME_SUFFIX L"80"
94 #elif _ATL_VER == _ATL_VER_90
95 #define ATL_NAME_SUFFIX L"90"
96 #elif _ATL_VER == _ATL_VER_100
97 #define ATL_NAME_SUFFIX L"100"
98 #elif _ATL_VER == _ATL_VER_110
99 #define ATL_NAME_SUFFIX L"110"
100 #else
101 #error Unsupported version
102 #endif
104 static const WCHAR AtlAxWinW[] = L"AtlAxWin" ATL_NAME_SUFFIX;
106 FIXME("version %04x semi-stub\n", _ATL_VER);
108 if ( FAILED( OleInitialize(NULL) ) )
109 return FALSE;
111 wcex.cbSize = sizeof(wcex);
112 wcex.style = CS_GLOBALCLASS | (_ATL_VER > _ATL_VER_30 ? CS_DBLCLKS : 0);
113 wcex.cbClsExtra = 0;
114 wcex.cbWndExtra = 0;
115 wcex.hInstance = GetModuleHandleW( NULL );
116 wcex.hIcon = NULL;
117 wcex.hCursor = NULL;
118 wcex.hbrBackground = NULL;
119 wcex.lpszMenuName = NULL;
120 wcex.hIconSm = 0;
122 wcex.lpfnWndProc = AtlAxWin_wndproc;
123 wcex.lpszClassName = AtlAxWinW;
124 if ( !RegisterClassExW( &wcex ) )
125 return FALSE;
127 if(_ATL_VER > _ATL_VER_30) {
128 static const WCHAR AtlAxWinLicW[] = L"AtlAxWinLic" ATL_NAME_SUFFIX;
130 wcex.lpszClassName = AtlAxWinLicW;
131 if ( !RegisterClassExW( &wcex ) )
132 return FALSE;
135 return TRUE;
138 /***********************************************************************
139 * Atl container component implementation
142 /****** IOleClientSite *****/
143 static inline IOCS *impl_from_IOleClientSite(IOleClientSite *iface)
145 return CONTAINING_RECORD(iface, IOCS, IOleClientSite_iface);
148 static HRESULT IOCS_Detach( IOCS *This ) /* remove subclassing */
150 if ( This->hWnd )
152 SetWindowLongPtrW( This->hWnd, GWLP_WNDPROC, (ULONG_PTR) This->OrigWndProc );
153 RemovePropW( This->hWnd, L"__WINE_ATL_IOCS" );
154 This->hWnd = NULL;
156 if ( This->control )
158 IOleObject *control = This->control;
160 This->control = NULL;
161 IOleObject_Close( control, OLECLOSE_NOSAVE );
162 IOleObject_SetClientSite( control, NULL );
163 IOleObject_Release( control );
165 return S_OK;
168 static HRESULT WINAPI OleClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
170 IOCS *This = impl_from_IOleClientSite(iface);
172 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
174 *ppv = NULL;
176 if (IsEqualIID(&IID_IUnknown, riid) ||
177 IsEqualIID(&IID_IOleClientSite, riid))
179 *ppv = iface;
181 else if (IsEqualIID(&IID_IOleContainer, riid))
183 *ppv = &This->IOleContainer_iface;
185 else if (IsEqualIID(&IID_IOleInPlaceSite, riid) ||
186 IsEqualIID(&IID_IOleInPlaceSiteEx, riid) ||
187 IsEqualIID(&IID_IOleInPlaceSiteWindowless, riid))
189 *ppv = &This->IOleInPlaceSiteWindowless_iface;
191 else if (IsEqualIID(&IID_IOleInPlaceFrame, riid))
193 *ppv = &This->IOleInPlaceFrame_iface;
195 else if (IsEqualIID(&IID_IOleControlSite, riid))
197 *ppv = &This->IOleControlSite_iface;
200 if (*ppv)
202 IOleClientSite_AddRef(iface);
203 return S_OK;
206 WARN("unsupported interface %s\n", debugstr_guid(riid));
207 return E_NOINTERFACE;
210 static ULONG WINAPI OleClientSite_AddRef(IOleClientSite *iface)
212 IOCS *This = impl_from_IOleClientSite(iface);
213 ULONG ref = InterlockedIncrement(&This->ref);
214 TRACE("(%p)->(%ld)\n", This, ref);
215 return ref;
218 static ULONG WINAPI OleClientSite_Release(IOleClientSite *iface)
220 IOCS *This = impl_from_IOleClientSite(iface);
221 ULONG ref = InterlockedDecrement(&This->ref);
223 TRACE("(%p)->(%ld)\n", This, ref);
225 if (!ref)
227 IOCS_Detach( This );
228 free( This );
231 return ref;
234 static HRESULT WINAPI OleClientSite_SaveObject(IOleClientSite *iface)
236 IOCS *This = impl_from_IOleClientSite(iface);
237 FIXME( "(%p) - stub\n", This );
238 return E_NOTIMPL;
241 static HRESULT WINAPI OleClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
243 IOCS *This = impl_from_IOleClientSite(iface);
245 FIXME( "(%p, 0x%lx, 0x%lx, %p)\n", This, dwAssign, dwWhichMoniker, ppmk );
246 return E_NOTIMPL;
249 static HRESULT WINAPI OleClientSite_GetContainer(IOleClientSite *iface, IOleContainer **container)
251 IOCS *This = impl_from_IOleClientSite(iface);
252 TRACE("(%p, %p)\n", This, container);
253 return IOleClientSite_QueryInterface(iface, &IID_IOleContainer, (void**)container);
256 static HRESULT WINAPI OleClientSite_ShowObject(IOleClientSite *iface)
258 IOCS *This = impl_from_IOleClientSite(iface);
259 FIXME( "(%p) - stub\n", This );
260 return S_OK;
263 static HRESULT WINAPI OleClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
265 IOCS *This = impl_from_IOleClientSite(iface);
266 FIXME( "(%p, %s) - stub\n", This, fShow ? "TRUE" : "FALSE" );
267 return E_NOTIMPL;
270 static HRESULT WINAPI OleClientSite_RequestNewObjectLayout(IOleClientSite *iface)
272 IOCS *This = impl_from_IOleClientSite(iface);
273 FIXME( "(%p) - stub\n", This );
274 return E_NOTIMPL;
278 /****** IOleContainer *****/
279 static inline IOCS *impl_from_IOleContainer(IOleContainer *iface)
281 return CONTAINING_RECORD(iface, IOCS, IOleContainer_iface);
284 static HRESULT WINAPI OleContainer_QueryInterface( IOleContainer* iface, REFIID riid, void** ppv)
286 IOCS *This = impl_from_IOleContainer(iface);
287 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
290 static ULONG WINAPI OleContainer_AddRef(IOleContainer* iface)
292 IOCS *This = impl_from_IOleContainer(iface);
293 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
296 static ULONG WINAPI OleContainer_Release(IOleContainer* iface)
298 IOCS *This = impl_from_IOleContainer(iface);
299 return IOleClientSite_Release(&This->IOleClientSite_iface);
302 static HRESULT WINAPI OleContainer_ParseDisplayName(IOleContainer* iface, IBindCtx* pbc,
303 LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut)
305 IOCS *This = impl_from_IOleContainer(iface);
306 FIXME( "(%p,%p,%s,%p,%p) - stub\n", This, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut );
307 return E_NOTIMPL;
310 static HRESULT WINAPI OleContainer_EnumObjects(IOleContainer* iface, DWORD grfFlags, IEnumUnknown** ppenum)
312 IOCS *This = impl_from_IOleContainer(iface);
313 FIXME( "(%p, %lu, %p) - stub\n", This, grfFlags, ppenum );
314 return E_NOTIMPL;
317 static HRESULT WINAPI OleContainer_LockContainer(IOleContainer* iface, BOOL fLock)
319 IOCS *This = impl_from_IOleContainer(iface);
320 FIXME( "(%p, %s) - stub\n", This, fLock?"TRUE":"FALSE" );
321 return E_NOTIMPL;
325 /****** IOleInPlaceSiteWindowless *******/
326 static inline IOCS *impl_from_IOleInPlaceSiteWindowless(IOleInPlaceSiteWindowless *iface)
328 return CONTAINING_RECORD(iface, IOCS, IOleInPlaceSiteWindowless_iface);
331 static HRESULT WINAPI OleInPlaceSiteWindowless_QueryInterface(IOleInPlaceSiteWindowless *iface, REFIID riid, void **ppv)
333 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
334 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
337 static ULONG WINAPI OleInPlaceSiteWindowless_AddRef(IOleInPlaceSiteWindowless *iface)
339 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
340 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
343 static ULONG WINAPI OleInPlaceSiteWindowless_Release(IOleInPlaceSiteWindowless *iface)
345 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
346 return IOleClientSite_Release(&This->IOleClientSite_iface);
349 static HRESULT WINAPI OleInPlaceSiteWindowless_GetWindow(IOleInPlaceSiteWindowless* iface, HWND* phwnd)
351 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
353 TRACE("(%p,%p)\n", This, phwnd);
354 *phwnd = This->hWnd;
355 return S_OK;
358 static HRESULT WINAPI OleInPlaceSiteWindowless_ContextSensitiveHelp(IOleInPlaceSiteWindowless* iface, BOOL fEnterMode)
360 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
361 FIXME("(%p,%d) - stub\n", This, fEnterMode);
362 return E_NOTIMPL;
365 static HRESULT WINAPI OleInPlaceSiteWindowless_CanInPlaceActivate(IOleInPlaceSiteWindowless *iface)
367 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
368 TRACE("(%p)\n", This);
369 return S_OK;
372 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceActivate(IOleInPlaceSiteWindowless *iface)
374 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
376 TRACE("(%p)\n", This);
378 This->fInPlace = TRUE;
379 return S_OK;
382 static HRESULT WINAPI OleInPlaceSiteWindowless_OnUIActivate(IOleInPlaceSiteWindowless *iface)
384 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
386 TRACE("(%p)\n", This);
388 return S_OK;
390 static HRESULT WINAPI OleInPlaceSiteWindowless_GetWindowContext(IOleInPlaceSiteWindowless *iface,
391 IOleInPlaceFrame **frame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
392 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
394 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
396 TRACE("(%p,%p,%p,%p,%p,%p)\n", This, frame, ppDoc, lprcPosRect, lprcClipRect, lpFrameInfo);
398 if ( lprcClipRect )
399 *lprcClipRect = This->size;
400 if ( lprcPosRect )
401 *lprcPosRect = This->size;
403 if ( frame )
405 *frame = &This->IOleInPlaceFrame_iface;
406 IOleInPlaceFrame_AddRef(*frame);
409 if ( ppDoc )
410 *ppDoc = NULL;
412 if ( lpFrameInfo )
414 lpFrameInfo->fMDIApp = FALSE;
415 lpFrameInfo->hwndFrame = This->hWnd;
416 lpFrameInfo->haccel = NULL;
417 lpFrameInfo->cAccelEntries = 0;
420 return S_OK;
423 static HRESULT WINAPI OleInPlaceSiteWindowless_Scroll(IOleInPlaceSiteWindowless *iface, SIZE scrollExtent)
425 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
426 FIXME("(%p) - stub\n", This);
427 return E_NOTIMPL;
430 static HRESULT WINAPI OleInPlaceSiteWindowless_OnUIDeactivate(IOleInPlaceSiteWindowless *iface, BOOL fUndoable)
432 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
433 FIXME("(%p,%d) - stub\n", This, fUndoable);
434 return E_NOTIMPL;
437 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceDeactivate(IOleInPlaceSiteWindowless *iface)
439 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
441 TRACE("(%p)\n", This);
443 This->fInPlace = This->fWindowless = FALSE;
444 return S_OK;
447 static HRESULT WINAPI OleInPlaceSiteWindowless_DiscardUndoState(IOleInPlaceSiteWindowless *iface)
449 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
450 FIXME("(%p) - stub\n", This);
451 return E_NOTIMPL;
454 static HRESULT WINAPI OleInPlaceSiteWindowless_DeactivateAndUndo(IOleInPlaceSiteWindowless *iface)
456 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
457 FIXME("(%p) - stub\n", This);
458 return E_NOTIMPL;
461 static HRESULT WINAPI OleInPlaceSiteWindowless_OnPosRectChange(IOleInPlaceSiteWindowless *iface, LPCRECT lprcPosRect)
463 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
464 FIXME("(%p,%p) - stub\n", This, lprcPosRect);
465 return E_NOTIMPL;
468 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceActivateEx( IOleInPlaceSiteWindowless *iface, BOOL* pfNoRedraw, DWORD dwFlags)
470 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
472 TRACE("\n");
474 This->fActive = This->fInPlace = TRUE;
475 if ( dwFlags & ACTIVATE_WINDOWLESS )
476 This->fWindowless = TRUE;
477 return S_OK;
480 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceDeactivateEx( IOleInPlaceSiteWindowless *iface, BOOL fNoRedraw)
482 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface);
484 TRACE("\n");
486 This->fActive = This->fInPlace = This->fWindowless = FALSE;
487 return S_OK;
489 static HRESULT WINAPI OleInPlaceSiteWindowless_RequestUIActivate( IOleInPlaceSiteWindowless *iface)
491 FIXME("\n");
492 return E_NOTIMPL;
494 static HRESULT WINAPI OleInPlaceSiteWindowless_CanWindowlessActivate( IOleInPlaceSiteWindowless *iface)
496 FIXME("\n");
497 return S_OK;
499 static HRESULT WINAPI OleInPlaceSiteWindowless_GetCapture( IOleInPlaceSiteWindowless *iface)
501 FIXME("\n");
502 return E_NOTIMPL;
504 static HRESULT WINAPI OleInPlaceSiteWindowless_SetCapture( IOleInPlaceSiteWindowless *iface, BOOL fCapture)
506 FIXME("\n");
507 return E_NOTIMPL;
509 static HRESULT WINAPI OleInPlaceSiteWindowless_GetFocus( IOleInPlaceSiteWindowless *iface)
511 FIXME("\n");
512 return E_NOTIMPL;
514 static HRESULT WINAPI OleInPlaceSiteWindowless_SetFocus( IOleInPlaceSiteWindowless *iface, BOOL fFocus)
516 FIXME("\n");
517 return E_NOTIMPL;
519 static HRESULT WINAPI OleInPlaceSiteWindowless_GetDC( IOleInPlaceSiteWindowless *iface, LPCRECT pRect, DWORD grfFlags, HDC* phDC)
521 FIXME("\n");
522 return E_NOTIMPL;
524 static HRESULT WINAPI OleInPlaceSiteWindowless_ReleaseDC( IOleInPlaceSiteWindowless *iface, HDC hDC)
526 FIXME("\n");
527 return E_NOTIMPL;
529 static HRESULT WINAPI OleInPlaceSiteWindowless_InvalidateRect( IOleInPlaceSiteWindowless *iface, LPCRECT pRect, BOOL fErase)
531 FIXME("\n");
532 return E_NOTIMPL;
534 static HRESULT WINAPI OleInPlaceSiteWindowless_InvalidateRgn( IOleInPlaceSiteWindowless *iface, HRGN hRGN, BOOL fErase)
536 FIXME("\n");
537 return E_NOTIMPL;
539 static HRESULT WINAPI OleInPlaceSiteWindowless_ScrollRect( IOleInPlaceSiteWindowless *iface, INT dx, INT dy, LPCRECT pRectScroll, LPCRECT pRectClip)
541 FIXME("\n");
542 return E_NOTIMPL;
544 static HRESULT WINAPI OleInPlaceSiteWindowless_AdjustRect( IOleInPlaceSiteWindowless *iface, LPRECT prc)
546 FIXME("\n");
547 return E_NOTIMPL;
549 static HRESULT WINAPI OleInPlaceSiteWindowless_OnDefWindowMessage( IOleInPlaceSiteWindowless *iface, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult)
551 FIXME("\n");
552 return E_NOTIMPL;
556 /****** IOleInPlaceFrame *******/
557 static inline IOCS *impl_from_IOleInPlaceFrame(IOleInPlaceFrame *iface)
559 return CONTAINING_RECORD(iface, IOCS, IOleInPlaceFrame_iface);
562 static HRESULT WINAPI OleInPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
564 IOCS *This = impl_from_IOleInPlaceFrame(iface);
565 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
568 static ULONG WINAPI OleInPlaceFrame_AddRef(IOleInPlaceFrame *iface)
570 IOCS *This = impl_from_IOleInPlaceFrame(iface);
571 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
574 static ULONG WINAPI OleInPlaceFrame_Release(IOleInPlaceFrame *iface)
576 IOCS *This = impl_from_IOleInPlaceFrame(iface);
577 return IOleClientSite_Release(&This->IOleClientSite_iface);
580 static HRESULT WINAPI OleInPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phWnd)
582 IOCS *This = impl_from_IOleInPlaceFrame(iface);
584 TRACE( "(%p,%p)\n", This, phWnd );
586 *phWnd = This->hWnd;
587 return S_OK;
590 static HRESULT WINAPI OleInPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
592 IOCS *This = impl_from_IOleInPlaceFrame(iface);
594 FIXME( "(%p,%d) - stub\n", This, fEnterMode );
595 return E_NOTIMPL;
598 static HRESULT WINAPI OleInPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
600 IOCS *This = impl_from_IOleInPlaceFrame(iface);
602 FIXME( "(%p,%p) - stub\n", This, lprectBorder );
603 return E_NOTIMPL;
606 static HRESULT WINAPI OleInPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths)
608 IOCS *This = impl_from_IOleInPlaceFrame(iface);
610 FIXME( "(%p,%p) - stub\n", This, pborderwidths );
611 return E_NOTIMPL;
614 static HRESULT WINAPI OleInPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths)
616 IOCS *This = impl_from_IOleInPlaceFrame(iface);
618 FIXME( "(%p,%p) - stub\n", This, pborderwidths );
619 return E_NOTIMPL;
622 static HRESULT WINAPI OleInPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface, IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
624 IOCS *This = impl_from_IOleInPlaceFrame(iface);
626 FIXME( "(%p,%p,%s) - stub\n", This, pActiveObject, debugstr_w(pszObjName) );
627 return S_OK;
630 static HRESULT WINAPI OleInPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
632 IOCS *This = impl_from_IOleInPlaceFrame(iface);
634 FIXME( "(%p,%p,%p) - stub\n", This, hmenuShared, lpMenuWidths );
635 return E_NOTIMPL;
638 static HRESULT WINAPI OleInPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
640 IOCS *This = impl_from_IOleInPlaceFrame(iface);
642 FIXME( "(%p,%p,%p,%p) - stub\n", This, hmenuShared, holemenu, hwndActiveObject );
643 return E_NOTIMPL;
646 static HRESULT WINAPI OleInPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
648 IOCS *This = impl_from_IOleInPlaceFrame(iface);
650 FIXME( "(%p, %p) - stub\n", This, hmenuShared );
651 return E_NOTIMPL;
654 static HRESULT WINAPI OleInPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
656 IOCS *This = impl_from_IOleInPlaceFrame(iface);
658 FIXME( "(%p, %s) - stub\n", This, debugstr_w( pszStatusText ) );
659 return E_NOTIMPL;
662 static HRESULT WINAPI OleInPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
664 IOCS *This = impl_from_IOleInPlaceFrame(iface);
666 FIXME( "(%p, %d) - stub\n", This, fEnable );
667 return E_NOTIMPL;
670 static HRESULT WINAPI OleInPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
672 IOCS *This = impl_from_IOleInPlaceFrame(iface);
674 FIXME( "(%p, %p, %x) - stub\n", This, lpmsg, wID );
675 return E_NOTIMPL;
679 /****** IOleControlSite *******/
680 static inline IOCS *impl_from_IOleControlSite(IOleControlSite *iface)
682 return CONTAINING_RECORD(iface, IOCS, IOleControlSite_iface);
685 static HRESULT WINAPI OleControlSite_QueryInterface(IOleControlSite *iface, REFIID riid, void **ppv)
687 IOCS *This = impl_from_IOleControlSite(iface);
688 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
691 static ULONG WINAPI OleControlSite_AddRef(IOleControlSite *iface)
693 IOCS *This = impl_from_IOleControlSite(iface);
694 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
697 static ULONG WINAPI OleControlSite_Release(IOleControlSite *iface)
699 IOCS *This = impl_from_IOleControlSite(iface);
700 return IOleClientSite_Release(&This->IOleClientSite_iface);
703 static HRESULT WINAPI OleControlSite_OnControlInfoChanged( IOleControlSite* This)
705 FIXME( "\n" );
706 return E_NOTIMPL;
708 static HRESULT WINAPI OleControlSite_LockInPlaceActive( IOleControlSite* This, BOOL fLock)
710 FIXME( "\n" );
711 return E_NOTIMPL;
713 static HRESULT WINAPI OleControlSite_GetExtendedControl( IOleControlSite* This, IDispatch** ppDisp)
715 FIXME( "\n" );
716 return E_NOTIMPL;
718 static HRESULT WINAPI OleControlSite_TransformCoords( IOleControlSite* This, POINTL* pPtlHimetric, POINTF* pPtfContainer, DWORD dwFlags)
720 FIXME( "\n" );
721 return E_NOTIMPL;
723 static HRESULT WINAPI OleControlSite_TranslateAccelerator( IOleControlSite* This, MSG* pMsg, DWORD grfModifiers)
725 FIXME( "\n" );
726 return E_NOTIMPL;
728 static HRESULT WINAPI OleControlSite_OnFocus( IOleControlSite* This, BOOL fGotFocus)
730 FIXME( "\n" );
731 return E_NOTIMPL;
733 static HRESULT WINAPI OleControlSite_ShowPropertyFrame( IOleControlSite* This)
735 FIXME( "\n" );
736 return E_NOTIMPL;
740 static const IOleClientSiteVtbl OleClientSite_vtbl = {
741 OleClientSite_QueryInterface,
742 OleClientSite_AddRef,
743 OleClientSite_Release,
744 OleClientSite_SaveObject,
745 OleClientSite_GetMoniker,
746 OleClientSite_GetContainer,
747 OleClientSite_ShowObject,
748 OleClientSite_OnShowWindow,
749 OleClientSite_RequestNewObjectLayout
751 static const IOleContainerVtbl OleContainer_vtbl = {
752 OleContainer_QueryInterface,
753 OleContainer_AddRef,
754 OleContainer_Release,
755 OleContainer_ParseDisplayName,
756 OleContainer_EnumObjects,
757 OleContainer_LockContainer
759 static const IOleInPlaceSiteWindowlessVtbl OleInPlaceSiteWindowless_vtbl = {
760 OleInPlaceSiteWindowless_QueryInterface,
761 OleInPlaceSiteWindowless_AddRef,
762 OleInPlaceSiteWindowless_Release,
763 OleInPlaceSiteWindowless_GetWindow,
764 OleInPlaceSiteWindowless_ContextSensitiveHelp,
765 OleInPlaceSiteWindowless_CanInPlaceActivate,
766 OleInPlaceSiteWindowless_OnInPlaceActivate,
767 OleInPlaceSiteWindowless_OnUIActivate,
768 OleInPlaceSiteWindowless_GetWindowContext,
769 OleInPlaceSiteWindowless_Scroll,
770 OleInPlaceSiteWindowless_OnUIDeactivate,
771 OleInPlaceSiteWindowless_OnInPlaceDeactivate,
772 OleInPlaceSiteWindowless_DiscardUndoState,
773 OleInPlaceSiteWindowless_DeactivateAndUndo,
774 OleInPlaceSiteWindowless_OnPosRectChange,
775 OleInPlaceSiteWindowless_OnInPlaceActivateEx,
776 OleInPlaceSiteWindowless_OnInPlaceDeactivateEx,
777 OleInPlaceSiteWindowless_RequestUIActivate,
778 OleInPlaceSiteWindowless_CanWindowlessActivate,
779 OleInPlaceSiteWindowless_GetCapture,
780 OleInPlaceSiteWindowless_SetCapture,
781 OleInPlaceSiteWindowless_GetFocus,
782 OleInPlaceSiteWindowless_SetFocus,
783 OleInPlaceSiteWindowless_GetDC,
784 OleInPlaceSiteWindowless_ReleaseDC,
785 OleInPlaceSiteWindowless_InvalidateRect,
786 OleInPlaceSiteWindowless_InvalidateRgn,
787 OleInPlaceSiteWindowless_ScrollRect,
788 OleInPlaceSiteWindowless_AdjustRect,
789 OleInPlaceSiteWindowless_OnDefWindowMessage
791 static const IOleInPlaceFrameVtbl OleInPlaceFrame_vtbl =
793 OleInPlaceFrame_QueryInterface,
794 OleInPlaceFrame_AddRef,
795 OleInPlaceFrame_Release,
796 OleInPlaceFrame_GetWindow,
797 OleInPlaceFrame_ContextSensitiveHelp,
798 OleInPlaceFrame_GetBorder,
799 OleInPlaceFrame_RequestBorderSpace,
800 OleInPlaceFrame_SetBorderSpace,
801 OleInPlaceFrame_SetActiveObject,
802 OleInPlaceFrame_InsertMenus,
803 OleInPlaceFrame_SetMenu,
804 OleInPlaceFrame_RemoveMenus,
805 OleInPlaceFrame_SetStatusText,
806 OleInPlaceFrame_EnableModeless,
807 OleInPlaceFrame_TranslateAccelerator
809 static const IOleControlSiteVtbl OleControlSite_vtbl =
811 OleControlSite_QueryInterface,
812 OleControlSite_AddRef,
813 OleControlSite_Release,
814 OleControlSite_OnControlInfoChanged,
815 OleControlSite_LockInPlaceActive,
816 OleControlSite_GetExtendedControl,
817 OleControlSite_TransformCoords,
818 OleControlSite_TranslateAccelerator,
819 OleControlSite_OnFocus,
820 OleControlSite_ShowPropertyFrame
823 static void IOCS_OnSize( IOCS* This, LPCRECT rect )
825 SIZEL inPix, inHi;
827 This->size = *rect;
829 if ( !This->control )
830 return;
832 inPix.cx = rect->right - rect->left;
833 inPix.cy = rect->bottom - rect->top;
834 AtlPixelToHiMetric( &inPix, &inHi );
835 IOleObject_SetExtent( This->control, DVASPECT_CONTENT, &inHi );
837 if ( This->fInPlace )
839 IOleInPlaceObject *wl;
841 if ( SUCCEEDED( IOleObject_QueryInterface( This->control, &IID_IOleInPlaceObject, (void**)&wl ) ) )
843 IOleInPlaceObject_SetObjectRects( wl, rect, rect );
844 IOleInPlaceObject_Release( wl );
849 static void IOCS_OnShow( IOCS *This, BOOL fShow )
851 if (!This->control || This->fActive || !fShow )
852 return;
854 This->fActive = TRUE;
857 static void IOCS_OnDraw( IOCS *This )
859 IViewObject *view;
861 if ( !This->control || !This->fWindowless )
862 return;
864 if ( SUCCEEDED( IOleObject_QueryInterface( This->control, &IID_IViewObject, (void**)&view ) ) )
866 HDC dc = GetDC( This->hWnd );
867 RECTL rect;
869 rect.left = This->size.left; rect.top = This->size.top;
870 rect.bottom = This->size.bottom; rect.right = This->size.right;
872 IViewObject_Draw( view, DVASPECT_CONTENT, ~0, NULL, NULL, 0, dc, &rect, &rect, NULL, 0 );
873 IViewObject_Release( view );
874 ReleaseDC( This->hWnd, dc );
878 static LRESULT IOCS_OnWndProc( IOCS *This, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
880 WNDPROC OrigWndProc = This->OrigWndProc;
882 switch( uMsg )
884 case WM_DESTROY:
885 IOCS_Detach( This );
886 break;
887 case WM_SIZE:
889 RECT r;
890 SetRect(&r, 0, 0, LOWORD(lParam), HIWORD(lParam));
891 IOCS_OnSize( This, &r );
893 break;
894 case WM_SHOWWINDOW:
895 IOCS_OnShow( This, (BOOL) wParam );
896 break;
897 case WM_PAINT:
898 IOCS_OnDraw( This );
899 break;
902 return CallWindowProcW( OrigWndProc, hWnd, uMsg, wParam, lParam );
905 static LRESULT CALLBACK AtlHost_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
907 IOCS *This = (IOCS*) GetPropW( hWnd, L"__WINE_ATL_IOCS" );
908 return IOCS_OnWndProc( This, hWnd, wMsg, wParam, lParam );
911 static HRESULT IOCS_Attach( IOCS *This, HWND hWnd, IUnknown *pUnkControl ) /* subclass hWnd */
913 This->hWnd = hWnd;
914 IUnknown_QueryInterface( pUnkControl, &IID_IOleObject, (void**)&This->control );
915 IOleObject_SetClientSite( This->control, &This->IOleClientSite_iface );
916 SetPropW( hWnd, L"__WINE_ATL_IOCS", This );
917 This->OrigWndProc = (WNDPROC)SetWindowLongPtrW( hWnd, GWLP_WNDPROC, (ULONG_PTR) AtlHost_wndproc );
919 return S_OK;
922 static HRESULT IOCS_Init( IOCS *This )
924 RECT rect;
926 IOleObject_SetHostNames( This->control, L"AXWIN", L"AXWIN" );
928 GetClientRect( This->hWnd, &rect );
929 IOCS_OnSize( This, &rect );
930 IOleObject_DoVerb( This->control, OLEIVERB_INPLACEACTIVATE, NULL, &This->IOleClientSite_iface,
931 0, This->hWnd, &rect );
933 return S_OK;
936 /**********************************************************************
937 * Create new instance of Atl host component and attach it to window *
939 static HRESULT IOCS_Create( HWND hWnd, IUnknown *pUnkControl, IUnknown **container )
941 HRESULT hr;
942 IOCS *This;
944 if (!container)
945 return S_OK;
947 *container = NULL;
948 This = malloc(sizeof(*This));
950 if (!This)
951 return E_OUTOFMEMORY;
953 This->IOleClientSite_iface.lpVtbl = &OleClientSite_vtbl;
954 This->IOleContainer_iface.lpVtbl = &OleContainer_vtbl;
955 This->IOleInPlaceSiteWindowless_iface.lpVtbl = &OleInPlaceSiteWindowless_vtbl;
956 This->IOleInPlaceFrame_iface.lpVtbl = &OleInPlaceFrame_vtbl;
957 This->IOleControlSite_iface.lpVtbl = &OleControlSite_vtbl;
958 This->ref = 1;
960 This->OrigWndProc = NULL;
961 This->hWnd = NULL;
962 This->fWindowless = This->fActive = This->fInPlace = FALSE;
964 hr = IOCS_Attach( This, hWnd, pUnkControl );
965 if ( SUCCEEDED( hr ) )
966 hr = IOCS_Init( This );
967 if ( SUCCEEDED( hr ) )
968 *container = (IUnknown*)&This->IOleClientSite_iface;
969 else
971 IOCS_Detach( This );
972 free(This);
975 return hr;
979 /***********************************************************************
980 * AtlAxCreateControl [atl100.@]
982 HRESULT WINAPI AtlAxCreateControl(LPCOLESTR lpszName, HWND hWnd,
983 IStream *pStream, IUnknown **ppUnkContainer)
985 return AtlAxCreateControlEx( lpszName, hWnd, pStream, ppUnkContainer,
986 NULL, NULL, NULL );
989 enum content
991 IsEmpty = 0,
992 IsGUID = 1,
993 IsHTML = 2,
994 IsURL = 3,
995 IsUnknown = 4
998 static enum content get_content_type(LPCOLESTR name, CLSID *control_id)
1000 WCHAR new_urlW[MAX_PATH];
1001 DWORD size = MAX_PATH;
1003 if (!name || !name[0])
1005 WARN("name %s\n", wine_dbgstr_w(name));
1006 return IsEmpty;
1009 if (CLSIDFromString(name, control_id) == S_OK ||
1010 CLSIDFromProgID(name, control_id) == S_OK)
1011 return IsGUID;
1013 if (PathIsURLW (name) ||
1014 UrlApplySchemeW(name, new_urlW, &size, URL_APPLY_GUESSSCHEME|URL_APPLY_GUESSFILE) == S_OK)
1016 *control_id = CLSID_WebBrowser;
1017 return IsURL;
1020 if (!wcsnicmp(name, L"mshtml:", 7))
1022 FIXME("mshtml prefix not implemented\n");
1023 *control_id = CLSID_WebBrowser;
1024 return IsHTML;
1027 return IsUnknown;
1030 /***********************************************************************
1031 * AtlAxCreateControlLicEx [atl100.@]
1033 * REMARKS
1034 * See http://www.codeproject.com/com/cwebpage.asp for some background
1037 HRESULT WINAPI AtlAxCreateControlLicEx(LPCOLESTR lpszName, HWND hWnd,
1038 IStream *pStream, IUnknown **ppUnkContainer, IUnknown **ppUnkControl,
1039 REFIID iidSink, IUnknown *punkSink, BSTR lic)
1041 CLSID controlId;
1042 HRESULT hRes;
1043 IOleObject *pControl;
1044 IUnknown *pUnkControl = NULL;
1045 IPersistStreamInit *pPSInit;
1046 IUnknown *pContainer = NULL;
1047 enum content content;
1049 TRACE("(%s %p %p %p %p %p %p %s)\n", debugstr_w(lpszName), hWnd, pStream,
1050 ppUnkContainer, ppUnkControl, iidSink, punkSink, debugstr_w(lic));
1052 if (lic)
1053 FIXME("semi stub\n");
1055 if (ppUnkContainer) *ppUnkContainer = NULL;
1056 if (ppUnkControl) *ppUnkControl = NULL;
1058 content = get_content_type(lpszName, &controlId);
1060 if (content == IsEmpty)
1061 return S_OK;
1063 if (content == IsUnknown)
1064 return CO_E_CLASSSTRING;
1066 hRes = CoCreateInstance( &controlId, 0, CLSCTX_ALL, &IID_IOleObject,
1067 (void**) &pControl );
1068 if ( FAILED( hRes ) )
1070 WARN( "cannot create ActiveX control %s instance - error 0x%08lx\n",
1071 debugstr_guid( &controlId ), hRes );
1072 return hRes;
1075 hRes = IOleObject_QueryInterface( pControl, &IID_IPersistStreamInit, (void**) &pPSInit );
1076 if ( SUCCEEDED( hRes ) )
1078 if (!pStream)
1079 IPersistStreamInit_InitNew( pPSInit );
1080 else
1081 IPersistStreamInit_Load( pPSInit, pStream );
1082 IPersistStreamInit_Release( pPSInit );
1083 } else
1084 WARN("cannot get IID_IPersistStreamInit out of control\n");
1086 IOleObject_QueryInterface( pControl, &IID_IUnknown, (void**) &pUnkControl );
1087 IOleObject_Release( pControl );
1090 hRes = AtlAxAttachControl( pUnkControl, hWnd, &pContainer );
1091 if ( FAILED( hRes ) )
1092 WARN("cannot attach control to window\n");
1094 if ( content == IsURL )
1096 IWebBrowser2 *browser;
1098 hRes = IOleObject_QueryInterface( pControl, &IID_IWebBrowser2, (void**) &browser );
1099 if ( !browser )
1100 WARN( "Cannot query IWebBrowser2 interface: %08lx\n", hRes );
1101 else {
1102 VARIANT url;
1104 IWebBrowser2_put_Visible( browser, VARIANT_TRUE ); /* it seems that native does this on URL (but do not on MSHTML:! why? */
1106 V_VT(&url) = VT_BSTR;
1107 V_BSTR(&url) = SysAllocString( lpszName );
1109 hRes = IWebBrowser2_Navigate2( browser, &url, NULL, NULL, NULL, NULL );
1110 if ( FAILED( hRes ) )
1111 WARN( "IWebBrowser2::Navigate2 failed: %08lx\n", hRes );
1112 SysFreeString( V_BSTR(&url) );
1114 IWebBrowser2_Release( browser );
1118 if (ppUnkContainer)
1120 *ppUnkContainer = pContainer;
1121 if ( pContainer )
1122 IUnknown_AddRef( pContainer );
1124 if (ppUnkControl)
1126 *ppUnkControl = pUnkControl;
1127 if ( pUnkControl )
1128 IUnknown_AddRef( pUnkControl );
1131 if ( pUnkControl )
1132 IUnknown_Release( pUnkControl );
1133 if ( pContainer )
1134 IUnknown_Release( pContainer );
1136 return S_OK;
1139 /***********************************************************************
1140 * AtlAxAttachControl [atl100.@]
1142 HRESULT WINAPI AtlAxAttachControl(IUnknown *control, HWND hWnd, IUnknown **container)
1144 HRESULT hr;
1146 TRACE("(%p %p %p)\n", control, hWnd, container);
1148 if (!control)
1149 return E_INVALIDARG;
1151 hr = IOCS_Create( hWnd, control, container );
1152 return hWnd ? hr : S_FALSE;
1155 /**********************************************************************
1156 * Helper function for AX_ConvertDialogTemplate
1158 static inline BOOL advance_array(WORD **pptr, DWORD *palloc, DWORD *pfilled, const WORD *data, DWORD size)
1160 if ( (*pfilled + size) > *palloc )
1162 *palloc = ((*pfilled+size) + 0xFF) & ~0xFF;
1163 *pptr = realloc( *pptr, *palloc * sizeof(WORD) );
1164 if (!*pptr)
1165 return FALSE;
1167 RtlMoveMemory( *pptr+*pfilled, data, size * sizeof(WORD) );
1168 *pfilled += size;
1169 return TRUE;
1172 /**********************************************************************
1173 * Convert ActiveX control templates to AtlAxWin class instances
1175 static LPDLGTEMPLATEW AX_ConvertDialogTemplate(LPCDLGTEMPLATEW src_tmpl)
1177 #define GET_WORD(x) (*(const WORD *)(x))
1178 #define GET_DWORD(x) (*(const DWORD *)(x))
1179 #define PUT_BLOCK(x,y) do {if (!advance_array(&output, &allocated, &filled, (x), (y))) return NULL;} while (0)
1180 #define PUT_WORD(x) do {WORD w = (x);PUT_BLOCK(&w, 1);} while(0)
1181 const WORD *tmp, *src = (const WORD *)src_tmpl;
1182 WORD *output;
1183 DWORD allocated, filled; /* in WORDs */
1184 BOOL ext;
1185 WORD signature, dlgver, rescount;
1186 DWORD style;
1188 filled = 0; allocated = 256;
1189 output = malloc( allocated * sizeof(WORD) );
1190 if (!output)
1191 return NULL;
1193 /* header */
1194 tmp = src;
1195 signature = GET_WORD(src);
1196 dlgver = GET_WORD(src + 1);
1197 if (signature == 1 && dlgver == 0xFFFF)
1199 ext = TRUE;
1200 src += 6;
1201 style = GET_DWORD(src);
1202 src += 2;
1203 rescount = GET_WORD(src++);
1204 src += 4;
1205 if ( GET_WORD(src) == 0xFFFF ) /* menu */
1206 src += 2;
1207 else
1208 src += lstrlenW(src) + 1;
1209 if ( GET_WORD(src) == 0xFFFF ) /* class */
1210 src += 2;
1211 else
1212 src += lstrlenW(src) + 1;
1213 src += lstrlenW(src) + 1; /* title */
1214 if ( style & (DS_SETFONT | DS_SHELLFONT) )
1216 src += 3;
1217 src += lstrlenW(src) + 1;
1219 } else {
1220 ext = FALSE;
1221 style = GET_DWORD(src);
1222 src += 4;
1223 rescount = GET_WORD(src++);
1224 src += 4;
1225 if ( GET_WORD(src) == 0xFFFF ) /* menu */
1226 src += 2;
1227 else
1228 src += lstrlenW(src) + 1;
1229 if ( GET_WORD(src) == 0xFFFF ) /* class */
1230 src += 2;
1231 else
1232 src += lstrlenW(src) + 1;
1233 src += lstrlenW(src) + 1; /* title */
1234 if ( style & DS_SETFONT )
1236 src++;
1237 src += lstrlenW(src) + 1;
1240 PUT_BLOCK(tmp, src-tmp);
1242 while(rescount--)
1244 src = (const WORD *)( ( ((ULONG_PTR)src) + 3) & ~3); /* align on DWORD boundary */
1245 filled = (filled + 1) & ~1; /* depends on DWORD-aligned allocation unit */
1247 tmp = src;
1248 if (ext)
1249 src += 12;
1250 else
1251 src += 9;
1252 PUT_BLOCK(tmp, src-tmp);
1254 tmp = src;
1255 if ( GET_WORD(src) == 0xFFFF ) /* class */
1257 src += 2;
1258 } else
1260 src += lstrlenW(src) + 1;
1262 src += lstrlenW(src) + 1; /* title */
1263 if ( GET_WORD(tmp) == '{' ) /* all this mess created because of this line */
1265 PUT_BLOCK(L"AtlAxWin", ARRAY_SIZE(L"AtlAxWin"));
1266 PUT_BLOCK(tmp, lstrlenW(tmp)+1);
1267 } else
1268 PUT_BLOCK(tmp, src-tmp);
1270 if ( GET_WORD(src) )
1272 WORD size = (GET_WORD(src)+sizeof(WORD)-1) / sizeof(WORD); /* quite ugly :( Maybe use BYTE* instead of WORD* everywhere ? */
1273 PUT_BLOCK(src, size);
1274 src+=size;
1276 else
1278 PUT_WORD(0);
1279 src++;
1282 return (LPDLGTEMPLATEW) output;
1285 /***********************************************************************
1286 * AtlAxCreateDialogA [atl100.@]
1288 * Creates a dialog window
1290 * PARAMS
1291 * hInst [I] Application instance
1292 * name [I] Dialog box template name
1293 * owner [I] Dialog box parent HWND
1294 * dlgProc [I] Dialog box procedure
1295 * param [I] This value will be passed to dlgProc as WM_INITDIALOG's message lParam
1297 * RETURNS
1298 * Window handle of dialog window.
1300 HWND WINAPI AtlAxCreateDialogA(HINSTANCE hInst, LPCSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param)
1302 HWND res = NULL;
1303 int length;
1304 WCHAR *nameW;
1306 if (IS_INTRESOURCE(name))
1307 return AtlAxCreateDialogW( hInst, (LPCWSTR) name, owner, dlgProc, param );
1309 length = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
1310 nameW = malloc( length * sizeof(WCHAR) );
1311 if (nameW)
1313 MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, length );
1314 res = AtlAxCreateDialogW( hInst, nameW, owner, dlgProc, param );
1315 free( nameW );
1317 return res;
1320 /***********************************************************************
1321 * AtlAxCreateDialogW [atl100.@]
1323 * See AtlAxCreateDialogA
1326 HWND WINAPI AtlAxCreateDialogW(HINSTANCE hInst, LPCWSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param)
1328 HRSRC hrsrc;
1329 HGLOBAL hgl;
1330 LPCDLGTEMPLATEW ptr;
1331 LPDLGTEMPLATEW newptr;
1332 HWND res;
1334 TRACE("(%p %s %p %p %Ix)\n", hInst, debugstr_w(name), owner, dlgProc, param);
1336 hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG );
1337 if ( !hrsrc )
1338 return NULL;
1339 hgl = LoadResource (hInst, hrsrc);
1340 if ( !hgl )
1341 return NULL;
1342 ptr = LockResource ( hgl );
1343 if (!ptr)
1345 FreeResource( hgl );
1346 return NULL;
1348 newptr = AX_ConvertDialogTemplate( ptr );
1349 if ( newptr )
1351 res = CreateDialogIndirectParamW( hInst, newptr, owner, dlgProc, param );
1352 free( newptr );
1353 } else
1354 res = NULL;
1355 FreeResource ( hrsrc );
1356 return res;
1359 /***********************************************************************
1360 * AtlAxGetHost [atl100.@]
1363 HRESULT WINAPI AtlAxGetHost(HWND hWnd, IUnknown **host)
1365 IOCS *This;
1367 TRACE("(%p, %p)\n", hWnd, host);
1369 *host = NULL;
1371 This = (IOCS*) GetPropW( hWnd, L"__WINE_ATL_IOCS" );
1372 if ( !This )
1374 WARN("No container attached to %p\n", hWnd );
1375 return E_FAIL;
1378 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, &IID_IUnknown, (void**)host);
1381 /***********************************************************************
1382 * AtlAxGetControl [atl100.@]
1385 HRESULT WINAPI AtlAxGetControl(HWND hWnd, IUnknown **pUnk)
1387 IOCS *This;
1389 TRACE( "(%p, %p)\n", hWnd, pUnk );
1391 *pUnk = NULL;
1393 This = (IOCS*) GetPropW( hWnd, L"__WINE_ATL_IOCS" );
1394 if ( !This || !This->control )
1396 WARN("No control attached to %p\n", hWnd );
1397 return E_FAIL;
1400 return IOleObject_QueryInterface( This->control, &IID_IUnknown, (void**) pUnk );
1403 /***********************************************************************
1404 * AtlAxDialogBoxW [atl100.35]
1407 INT_PTR WINAPI AtlAxDialogBoxW(HINSTANCE instance, const WCHAR *name,
1408 HWND owner, DLGPROC proc, LPARAM param)
1410 HRSRC resource;
1411 HGLOBAL global;
1412 DLGTEMPLATE *template;
1413 INT_PTR ret;
1415 TRACE("instance %p, name %s, owner %p, proc %p, param %#Ix\n",
1416 instance, debugstr_w(name), owner, proc, param);
1418 if (!(resource = FindResourceW(instance, name, (const WCHAR *)RT_DIALOG)))
1419 return 0;
1421 if (!(global = LoadResource(instance, resource)))
1422 return 0;
1424 if (!(template = AX_ConvertDialogTemplate(LockResource(global))))
1425 return 0;
1427 ret = DialogBoxIndirectParamW(instance, template, owner, proc, param);
1428 free(template);
1429 return ret;
1432 /***********************************************************************
1433 * AtlAxDialogBoxA [atl100.36]
1436 INT_PTR WINAPI AtlAxDialogBoxA(HINSTANCE instance, const char *name,
1437 HWND owner, DLGPROC proc, LPARAM param)
1439 WCHAR *nameW;
1440 int len;
1441 INT_PTR ret;
1443 if (IS_INTRESOURCE(name))
1444 return AtlAxDialogBoxW(instance, (const WCHAR *)name, owner, proc, param);
1446 len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
1447 if (!(nameW = malloc(len * sizeof(WCHAR))))
1448 return 0;
1449 MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, len);
1450 ret = AtlAxDialogBoxW(instance, nameW, owner, proc, param);
1451 free(nameW);
1452 return ret;
1455 /***********************************************************************
1456 * AtlAxCreateControlLic [atl100.59]
1459 HRESULT WINAPI AtlAxCreateControlLic(const WCHAR *lpTricsData, HWND hwnd, IStream *stream, IUnknown **container, BSTR lic)
1461 return AtlAxCreateControlLicEx(lpTricsData, hwnd, stream, container, NULL, NULL, NULL, lic);
1464 /***********************************************************************
1465 * AtlAxCreateControlEx [atl100.@]
1468 HRESULT WINAPI AtlAxCreateControlEx(const WCHAR *lpTricsData, HWND hwnd, IStream *stream,
1469 IUnknown **container, IUnknown **control, REFIID iidSink, IUnknown *punkSink)
1471 return AtlAxCreateControlLicEx(lpTricsData, hwnd, stream, container, control, iidSink, punkSink, NULL);