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
31 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(atl);
45 const IOleClientSiteVtbl *lpOleClientSiteVtbl;
46 const IOleContainerVtbl *lpOleContainerVtbl;
47 const IOleInPlaceSiteWindowlessVtbl *lpOleInPlaceSiteWindowlessVtbl;
48 const IOleInPlaceFrameVtbl *lpOleInPlaceFrameVtbl;
49 const IOleControlSiteVtbl *lpOleControlSiteVtbl;
56 BOOL fActive, fInPlace, fWindowless;
59 /**********************************************************************
60 * AtlAxWin class window procedure
62 static LRESULT CALLBACK AtlAxWin_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
64 if ( wMsg == WM_CREATE )
66 DWORD len = GetWindowTextLengthW( hWnd ) + 1;
67 WCHAR *ptr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
70 GetWindowTextW( hWnd, ptr, len );
71 AtlAxCreateControlEx( ptr, hWnd, NULL, NULL, NULL, NULL, NULL );
72 HeapFree( GetProcessHeap(), 0, ptr );
75 return DefWindowProcW( hWnd, wMsg, wParam, lParam );
78 /***********************************************************************
79 * AtlAxWinInit [ATL.@]
80 * Initializes the control-hosting code: registering the AtlAxWin,
81 * AtlAxWin7 and AtlAxWinLic7 window classes and some messages.
87 BOOL WINAPI AtlAxWinInit(void)
90 const WCHAR AtlAxWin[] = {'A','t','l','A','x','W','i','n',0};
94 if ( FAILED( OleInitialize(NULL) ) )
97 wcex.cbSize = sizeof(wcex);
101 wcex.hInstance = GetModuleHandleW( NULL );
104 wcex.hbrBackground = NULL;
105 wcex.lpszMenuName = NULL;
108 wcex.lpfnWndProc = AtlAxWin_wndproc;
109 wcex.lpszClassName = AtlAxWin;
110 if ( !RegisterClassExW( &wcex ) )
116 /***********************************************************************
117 * Atl container component implementation
121 static ULONG WINAPI IOCS_AddRef(IOCS *This)
123 ULONG ref = InterlockedIncrement(&This->ref);
125 TRACE( "(%p) : AddRef from %d\n", This, ref - 1 );
130 #define THIS2IOLECLIENTSITE(This) ((IOleClientSite*)&This->lpOleClientSiteVtbl)
131 #define THIS2IOLECONTAINER(This) ((IOleContainer*)&This->lpOleContainerVtbl)
132 #define THIS2IOLEINPLACESITEWINDOWLESS(This) ((IOleInPlaceSiteWindowless*)&This->lpOleInPlaceSiteWindowlessVtbl)
133 #define THIS2IOLEINPLACEFRAME(This) ((IOleInPlaceFrame*)&This->lpOleInPlaceFrameVtbl)
134 #define THIS2IOLECONTROLSITE(This) ((IOleControlSite*)&This->lpOleControlSiteVtbl)
136 static HRESULT WINAPI IOCS_QueryInterface(IOCS *This, REFIID riid, void **ppv)
140 if ( IsEqualIID( &IID_IUnknown, riid )
141 || IsEqualIID( &IID_IOleClientSite, riid ) )
143 *ppv = THIS2IOLECLIENTSITE(This);
144 } else if ( IsEqualIID( &IID_IOleContainer, riid ) )
146 *ppv = THIS2IOLECONTAINER(This);
147 } else if ( IsEqualIID( &IID_IOleInPlaceSite, riid ) || IsEqualIID( &IID_IOleInPlaceSiteEx, riid ) || IsEqualIID( &IID_IOleInPlaceSiteWindowless, riid ) )
149 *ppv = THIS2IOLEINPLACESITEWINDOWLESS(This);
150 } else if ( IsEqualIID( &IID_IOleInPlaceFrame, riid ) )
152 *ppv = THIS2IOLEINPLACEFRAME(This);
153 } else if ( IsEqualIID( &IID_IOleControlSite, riid ) )
155 *ppv = THIS2IOLECONTROLSITE(This);
164 WARN("unsupported interface %s\n", debugstr_guid( riid ) );
166 return E_NOINTERFACE;
169 static HRESULT IOCS_Detach( IOCS *This );
170 static ULONG WINAPI IOCS_Release(IOCS *This)
172 ULONG ref = InterlockedDecrement(&This->ref);
174 TRACE( "(%p) : ReleaseRef to %d\n", This, ref );
179 HeapFree( GetProcessHeap(), 0, This );
185 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
187 /****** IOleClientSite *****/
189 #define IFACE2THIS(iface) DEFINE_THIS(IOCS,OleClientSite, iface)
190 static HRESULT WINAPI OleClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
192 IOCS *This = IFACE2THIS(iface);
193 return IOCS_QueryInterface(This, riid, ppv);
195 static ULONG WINAPI OleClientSite_AddRef(IOleClientSite *iface)
197 IOCS *This = IFACE2THIS(iface);
198 return IOCS_AddRef(This);
200 static ULONG WINAPI OleClientSite_Release(IOleClientSite *iface)
202 IOCS *This = IFACE2THIS(iface);
203 return IOCS_Release(This);
205 static HRESULT WINAPI OleClientSite_SaveObject(IOleClientSite *iface)
207 IOCS *This = IFACE2THIS(iface);
208 FIXME( "(%p) - stub\n", This );
211 static HRESULT WINAPI OleClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
213 IOCS *This = IFACE2THIS(iface);
215 FIXME( "(%p, 0x%x, 0x%x, %p)\n", This, dwAssign, dwWhichMoniker, ppmk );
218 static HRESULT WINAPI OleClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
220 IOCS *This = IFACE2THIS(iface);
221 TRACE( "(%p, %p)\n", This, ppContainer );
222 return OleClientSite_QueryInterface( iface, &IID_IOleContainer, (void**)ppContainer );
224 static HRESULT WINAPI OleClientSite_ShowObject(IOleClientSite *iface)
226 IOCS *This = IFACE2THIS(iface);
227 FIXME( "(%p) - stub\n", This );
230 static HRESULT WINAPI OleClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
232 IOCS *This = IFACE2THIS(iface);
233 FIXME( "(%p, %s) - stub\n", This, fShow ? "TRUE" : "FALSE" );
236 static HRESULT WINAPI OleClientSite_RequestNewObjectLayout(IOleClientSite *iface)
238 IOCS *This = IFACE2THIS(iface);
239 FIXME( "(%p) - stub\n", This );
245 /****** IOleContainer *****/
246 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleContainer, iface)
247 static HRESULT WINAPI OleContainer_QueryInterface( IOleContainer* iface, REFIID riid, void** ppv)
249 IOCS *This = IFACE2THIS(iface);
250 return IOCS_QueryInterface( This, riid, ppv );
252 static ULONG WINAPI OleContainer_AddRef(IOleContainer* iface)
254 IOCS *This = IFACE2THIS(iface);
255 return IOCS_AddRef(This);
257 static ULONG WINAPI OleContainer_Release(IOleContainer* iface)
259 IOCS *This = IFACE2THIS(iface);
260 return IOCS_Release(This);
262 static HRESULT WINAPI OleContainer_ParseDisplayName(IOleContainer* iface, IBindCtx* pbc,
263 LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut)
265 IOCS *This = IFACE2THIS(iface);
266 FIXME( "(%p,%p,%s,%p,%p) - stub\n", This, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut );
269 static HRESULT WINAPI OleContainer_EnumObjects(IOleContainer* iface, DWORD grfFlags, IEnumUnknown** ppenum)
271 IOCS *This = IFACE2THIS(iface);
272 FIXME( "(%p, %u, %p) - stub\n", This, grfFlags, ppenum );
275 static HRESULT WINAPI OleContainer_LockContainer(IOleContainer* iface, BOOL fLock)
277 IOCS *This = IFACE2THIS(iface);
278 FIXME( "(%p, %s) - stub\n", This, fLock?"TRUE":"FALSE" );
284 /****** IOleInPlaceSiteWindowless *******/
285 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleInPlaceSiteWindowless, iface)
286 static HRESULT WINAPI OleInPlaceSiteWindowless_QueryInterface(IOleInPlaceSiteWindowless *iface, REFIID riid, void **ppv)
288 IOCS *This = IFACE2THIS(iface);
289 return IOCS_QueryInterface(This, riid, ppv);
291 static ULONG WINAPI OleInPlaceSiteWindowless_AddRef(IOleInPlaceSiteWindowless *iface)
293 IOCS *This = IFACE2THIS(iface);
294 return IOCS_AddRef(This);
296 static ULONG WINAPI OleInPlaceSiteWindowless_Release(IOleInPlaceSiteWindowless *iface)
298 IOCS *This = IFACE2THIS(iface);
299 return IOCS_Release(This);
301 static HRESULT WINAPI OleInPlaceSiteWindowless_GetWindow(IOleInPlaceSiteWindowless* iface, HWND* phwnd)
303 IOCS *This = IFACE2THIS(iface);
305 TRACE("(%p,%p)\n", This, phwnd);
309 static HRESULT WINAPI OleInPlaceSiteWindowless_ContextSensitiveHelp(IOleInPlaceSiteWindowless* iface, BOOL fEnterMode)
311 IOCS *This = IFACE2THIS(iface);
312 FIXME("(%p,%d) - stub\n", This, fEnterMode);
315 static HRESULT WINAPI OleInPlaceSiteWindowless_CanInPlaceActivate(IOleInPlaceSiteWindowless *iface)
317 IOCS *This = IFACE2THIS(iface);
318 TRACE("(%p)\n", This);
321 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceActivate(IOleInPlaceSiteWindowless *iface)
323 IOCS *This = IFACE2THIS(iface);
325 TRACE("(%p)\n", This);
327 This->fInPlace = TRUE;
330 static HRESULT WINAPI OleInPlaceSiteWindowless_OnUIActivate(IOleInPlaceSiteWindowless *iface)
332 IOCS *This = IFACE2THIS(iface);
334 TRACE("(%p)\n", This);
338 static HRESULT WINAPI OleInPlaceSiteWindowless_GetWindowContext(IOleInPlaceSiteWindowless *iface,
339 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
340 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
342 IOCS *This = IFACE2THIS(iface);
344 TRACE("(%p,%p,%p,%p,%p,%p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, lpFrameInfo);
347 memcpy(lprcClipRect, &This->size, sizeof(RECT));
349 memcpy(lprcPosRect, &This->size, sizeof(RECT));
353 IOCS_QueryInterface( This, &IID_IOleInPlaceFrame, (void**) ppFrame );
361 lpFrameInfo->fMDIApp = FALSE;
362 lpFrameInfo->hwndFrame = This->hWnd;
363 lpFrameInfo->haccel = NULL;
364 lpFrameInfo->cAccelEntries = 0;
369 static HRESULT WINAPI OleInPlaceSiteWindowless_Scroll(IOleInPlaceSiteWindowless *iface, SIZE scrollExtent)
371 IOCS *This = IFACE2THIS(iface);
372 FIXME("(%p) - stub\n", This);
375 static HRESULT WINAPI OleInPlaceSiteWindowless_OnUIDeactivate(IOleInPlaceSiteWindowless *iface, BOOL fUndoable)
377 IOCS *This = IFACE2THIS(iface);
378 FIXME("(%p,%d) - stub\n", This, fUndoable);
381 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceDeactivate(IOleInPlaceSiteWindowless *iface)
383 IOCS *This = IFACE2THIS(iface);
385 TRACE("(%p)\n", This);
387 This->fInPlace = This->fWindowless = FALSE;
390 static HRESULT WINAPI OleInPlaceSiteWindowless_DiscardUndoState(IOleInPlaceSiteWindowless *iface)
392 IOCS *This = IFACE2THIS(iface);
393 FIXME("(%p) - stub\n", This);
396 static HRESULT WINAPI OleInPlaceSiteWindowless_DeactivateAndUndo(IOleInPlaceSiteWindowless *iface)
398 IOCS *This = IFACE2THIS(iface);
399 FIXME("(%p) - stub\n", This);
402 static HRESULT WINAPI OleInPlaceSiteWindowless_OnPosRectChange(IOleInPlaceSiteWindowless *iface, LPCRECT lprcPosRect)
404 IOCS *This = IFACE2THIS(iface);
405 FIXME("(%p,%p) - stub\n", This, lprcPosRect);
408 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceActivateEx( IOleInPlaceSiteWindowless *iface, BOOL* pfNoRedraw, DWORD dwFlags)
410 IOCS *This = IFACE2THIS(iface);
414 This->fActive = This->fInPlace = TRUE;
415 if ( dwFlags & ACTIVATE_WINDOWLESS )
416 This->fWindowless = TRUE;
419 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceDeactivateEx( IOleInPlaceSiteWindowless *iface, BOOL fNoRedraw)
421 IOCS *This = IFACE2THIS(iface);
425 This->fActive = This->fInPlace = This->fWindowless = FALSE;
428 static HRESULT WINAPI OleInPlaceSiteWindowless_RequestUIActivate( IOleInPlaceSiteWindowless *iface)
433 static HRESULT WINAPI OleInPlaceSiteWindowless_CanWindowlessActivate( IOleInPlaceSiteWindowless *iface)
438 static HRESULT WINAPI OleInPlaceSiteWindowless_GetCapture( IOleInPlaceSiteWindowless *iface)
443 static HRESULT WINAPI OleInPlaceSiteWindowless_SetCapture( IOleInPlaceSiteWindowless *iface, BOOL fCapture)
448 static HRESULT WINAPI OleInPlaceSiteWindowless_GetFocus( IOleInPlaceSiteWindowless *iface)
453 static HRESULT WINAPI OleInPlaceSiteWindowless_SetFocus( IOleInPlaceSiteWindowless *iface, BOOL fFocus)
458 static HRESULT WINAPI OleInPlaceSiteWindowless_GetDC( IOleInPlaceSiteWindowless *iface, LPCRECT pRect, DWORD grfFlags, HDC* phDC)
463 static HRESULT WINAPI OleInPlaceSiteWindowless_ReleaseDC( IOleInPlaceSiteWindowless *iface, HDC hDC)
468 static HRESULT WINAPI OleInPlaceSiteWindowless_InvalidateRect( IOleInPlaceSiteWindowless *iface, LPCRECT pRect, BOOL fErase)
473 static HRESULT WINAPI OleInPlaceSiteWindowless_InvalidateRgn( IOleInPlaceSiteWindowless *iface, HRGN hRGN, BOOL fErase)
478 static HRESULT WINAPI OleInPlaceSiteWindowless_ScrollRect( IOleInPlaceSiteWindowless *iface, INT dx, INT dy, LPCRECT pRectScroll, LPCRECT pRectClip)
483 static HRESULT WINAPI OleInPlaceSiteWindowless_AdjustRect( IOleInPlaceSiteWindowless *iface, LPRECT prc)
488 static HRESULT WINAPI OleInPlaceSiteWindowless_OnDefWindowMessage( IOleInPlaceSiteWindowless *iface, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult)
496 /****** IOleInPlaceFrame *******/
497 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleInPlaceFrame, iface)
498 static HRESULT WINAPI OleInPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
500 IOCS *This = IFACE2THIS(iface);
501 return IOCS_QueryInterface(This, riid, ppv);
503 static ULONG WINAPI OleInPlaceFrame_AddRef(IOleInPlaceFrame *iface)
505 IOCS *This = IFACE2THIS(iface);
506 return IOCS_AddRef(This);
508 static ULONG WINAPI OleInPlaceFrame_Release(IOleInPlaceFrame *iface)
510 IOCS *This = IFACE2THIS(iface);
511 return IOCS_Release(This);
513 static HRESULT WINAPI OleInPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phWnd)
515 IOCS *This = IFACE2THIS(iface);
517 TRACE( "(%p,%p)\n", This, phWnd );
523 static HRESULT WINAPI OleInPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
525 IOCS *This = IFACE2THIS(iface);
527 FIXME( "(%p,%d) - stub\n", This, fEnterMode );
531 static HRESULT WINAPI OleInPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
533 IOCS *This = IFACE2THIS(iface);
535 FIXME( "(%p,%p) - stub\n", This, lprectBorder );
539 static HRESULT WINAPI OleInPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths)
541 IOCS *This = IFACE2THIS(iface);
543 FIXME( "(%p,%p) - stub\n", This, pborderwidths );
547 static HRESULT WINAPI OleInPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths)
549 IOCS *This = IFACE2THIS(iface);
551 FIXME( "(%p,%p) - stub\n", This, pborderwidths );
555 static HRESULT WINAPI OleInPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface, IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
557 IOCS *This = IFACE2THIS(iface);
559 FIXME( "(%p,%p,%s) - stub\n", This, pActiveObject, debugstr_w(pszObjName) );
563 static HRESULT WINAPI OleInPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
565 IOCS *This = IFACE2THIS(iface);
567 FIXME( "(%p,%p,%p) - stub\n", This, hmenuShared, lpMenuWidths );
571 static HRESULT WINAPI OleInPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
573 IOCS *This = IFACE2THIS(iface);
575 FIXME( "(%p,%p,%p,%p) - stub\n", This, hmenuShared, holemenu, hwndActiveObject );
578 static HRESULT WINAPI OleInPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
580 IOCS *This = IFACE2THIS(iface);
582 FIXME( "(%p, %p) - stub\n", This, hmenuShared );
586 static HRESULT WINAPI OleInPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
588 IOCS *This = IFACE2THIS(iface);
590 FIXME( "(%p, %s) - stub\n", This, debugstr_w( pszStatusText ) );
594 static HRESULT WINAPI OleInPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
596 IOCS *This = IFACE2THIS(iface);
598 FIXME( "(%p, %d) - stub\n", This, fEnable );
602 static HRESULT WINAPI OleInPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
604 IOCS *This = IFACE2THIS(iface);
606 FIXME( "(%p, %p, %x) - stub\n", This, lpmsg, wID );
612 /****** IOleControlSite *******/
613 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleControlSite, iface)
614 static HRESULT WINAPI OleControlSite_QueryInterface(IOleControlSite *iface, REFIID riid, void **ppv)
616 IOCS *This = IFACE2THIS(iface);
617 return IOCS_QueryInterface(This, riid, ppv);
619 static ULONG WINAPI OleControlSite_AddRef(IOleControlSite *iface)
621 IOCS *This = IFACE2THIS(iface);
622 return IOCS_AddRef(This);
624 static ULONG WINAPI OleControlSite_Release(IOleControlSite *iface)
626 IOCS *This = IFACE2THIS(iface);
627 return IOCS_Release(This);
629 static HRESULT WINAPI OleControlSite_OnControlInfoChanged( IOleControlSite* This)
634 static HRESULT WINAPI OleControlSite_LockInPlaceActive( IOleControlSite* This, BOOL fLock)
639 static HRESULT WINAPI OleControlSite_GetExtendedControl( IOleControlSite* This, IDispatch** ppDisp)
644 static HRESULT WINAPI OleControlSite_TransformCoords( IOleControlSite* This, POINTL* pPtlHimetric, POINTF* pPtfContainer, DWORD dwFlags)
649 static HRESULT WINAPI OleControlSite_TranslateAccelerator( IOleControlSite* This, MSG* pMsg, DWORD grfModifiers)
654 static HRESULT WINAPI OleControlSite_OnFocus( IOleControlSite* This, BOOL fGotFocus)
659 static HRESULT WINAPI OleControlSite_ShowPropertyFrame( IOleControlSite* This)
668 static const IOleClientSiteVtbl OleClientSite_vtbl = {
669 OleClientSite_QueryInterface,
670 OleClientSite_AddRef,
671 OleClientSite_Release,
672 OleClientSite_SaveObject,
673 OleClientSite_GetMoniker,
674 OleClientSite_GetContainer,
675 OleClientSite_ShowObject,
676 OleClientSite_OnShowWindow,
677 OleClientSite_RequestNewObjectLayout
679 static const IOleContainerVtbl OleContainer_vtbl = {
680 OleContainer_QueryInterface,
682 OleContainer_Release,
683 OleContainer_ParseDisplayName,
684 OleContainer_EnumObjects,
685 OleContainer_LockContainer
687 static const IOleInPlaceSiteWindowlessVtbl OleInPlaceSiteWindowless_vtbl = {
688 OleInPlaceSiteWindowless_QueryInterface,
689 OleInPlaceSiteWindowless_AddRef,
690 OleInPlaceSiteWindowless_Release,
691 OleInPlaceSiteWindowless_GetWindow,
692 OleInPlaceSiteWindowless_ContextSensitiveHelp,
693 OleInPlaceSiteWindowless_CanInPlaceActivate,
694 OleInPlaceSiteWindowless_OnInPlaceActivate,
695 OleInPlaceSiteWindowless_OnUIActivate,
696 OleInPlaceSiteWindowless_GetWindowContext,
697 OleInPlaceSiteWindowless_Scroll,
698 OleInPlaceSiteWindowless_OnUIDeactivate,
699 OleInPlaceSiteWindowless_OnInPlaceDeactivate,
700 OleInPlaceSiteWindowless_DiscardUndoState,
701 OleInPlaceSiteWindowless_DeactivateAndUndo,
702 OleInPlaceSiteWindowless_OnPosRectChange,
703 OleInPlaceSiteWindowless_OnInPlaceActivateEx,
704 OleInPlaceSiteWindowless_OnInPlaceDeactivateEx,
705 OleInPlaceSiteWindowless_RequestUIActivate,
706 OleInPlaceSiteWindowless_CanWindowlessActivate,
707 OleInPlaceSiteWindowless_GetCapture,
708 OleInPlaceSiteWindowless_SetCapture,
709 OleInPlaceSiteWindowless_GetFocus,
710 OleInPlaceSiteWindowless_SetFocus,
711 OleInPlaceSiteWindowless_GetDC,
712 OleInPlaceSiteWindowless_ReleaseDC,
713 OleInPlaceSiteWindowless_InvalidateRect,
714 OleInPlaceSiteWindowless_InvalidateRgn,
715 OleInPlaceSiteWindowless_ScrollRect,
716 OleInPlaceSiteWindowless_AdjustRect,
717 OleInPlaceSiteWindowless_OnDefWindowMessage
719 static const IOleInPlaceFrameVtbl OleInPlaceFrame_vtbl =
721 OleInPlaceFrame_QueryInterface,
722 OleInPlaceFrame_AddRef,
723 OleInPlaceFrame_Release,
724 OleInPlaceFrame_GetWindow,
725 OleInPlaceFrame_ContextSensitiveHelp,
726 OleInPlaceFrame_GetBorder,
727 OleInPlaceFrame_RequestBorderSpace,
728 OleInPlaceFrame_SetBorderSpace,
729 OleInPlaceFrame_SetActiveObject,
730 OleInPlaceFrame_InsertMenus,
731 OleInPlaceFrame_SetMenu,
732 OleInPlaceFrame_RemoveMenus,
733 OleInPlaceFrame_SetStatusText,
734 OleInPlaceFrame_EnableModeless,
735 OleInPlaceFrame_TranslateAccelerator
737 static const IOleControlSiteVtbl OleControlSite_vtbl =
739 OleControlSite_QueryInterface,
740 OleControlSite_AddRef,
741 OleControlSite_Release,
742 OleControlSite_OnControlInfoChanged,
743 OleControlSite_LockInPlaceActive,
744 OleControlSite_GetExtendedControl,
745 OleControlSite_TransformCoords,
746 OleControlSite_TranslateAccelerator,
747 OleControlSite_OnFocus,
748 OleControlSite_ShowPropertyFrame
751 static HRESULT IOCS_Detach( IOCS *This ) /* remove subclassing */
755 SetWindowLongPtrW( This->hWnd, GWLP_WNDPROC, (ULONG_PTR) This->OrigWndProc );
756 SetWindowLongPtrW( This->hWnd, GWLP_USERDATA, (LONG_PTR) NULL );
761 IOleObject *control = This->control;
763 This->control = NULL;
764 IOleObject_SetClientSite( control, NULL );
765 IOleObject_Release( control );
770 static void IOCS_OnSize( IOCS* This, LPCRECT rect )
774 This->size.left = rect->left; This->size.right = rect->right; This->size.top = rect->top; This->size.bottom = rect->bottom;
776 if ( !This->control )
779 inPix.cx = rect->right - rect->left;
780 inPix.cy = rect->bottom - rect->top;
781 AtlPixelToHiMetric( &inPix, &inHi );
782 IOleObject_SetExtent( This->control, DVASPECT_CONTENT, &inHi );
784 if ( This->fInPlace )
786 IOleInPlaceObject *wl;
788 if ( SUCCEEDED( IOleObject_QueryInterface( This->control, &IID_IOleInPlaceObject, (void**)&wl ) ) )
790 IOleInPlaceObject_SetObjectRects( wl, rect, rect );
791 IOleInPlaceObject_Release( wl );
796 static void IOCS_OnShow( IOCS *This, BOOL fShow )
798 if (!This->control || This->fActive || !fShow )
801 This->fActive = TRUE;
804 static void IOCS_OnDraw( IOCS *This )
808 if ( !This->control || !This->fWindowless )
811 if ( SUCCEEDED( IOleObject_QueryInterface( This->control, &IID_IViewObject, (void**)&view ) ) )
813 HDC dc = GetDC( This->hWnd );
816 rect.left = This->size.left; rect.top = This->size.top;
817 rect.bottom = This->size.bottom; rect.right = This->size.right;
819 IViewObject_Draw( view, DVASPECT_CONTENT, ~0, NULL, NULL, 0, dc, &rect, &rect, NULL, 0 );
820 IViewObject_Release( view );
821 ReleaseDC( This->hWnd, dc );
825 static LRESULT IOCS_OnWndProc( IOCS *This, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
827 WNDPROC OrigWndProc = This->OrigWndProc;
838 r.right = LOWORD( lParam );
839 r.bottom = HIWORD( lParam );
840 IOCS_OnSize( This, &r );
844 IOCS_OnShow( This, (BOOL) wParam );
851 return CallWindowProcW( OrigWndProc, hWnd, uMsg, wParam, lParam );
854 static LRESULT CALLBACK AtlHost_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
856 IOCS *This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA );
857 return IOCS_OnWndProc( This, hWnd, wMsg, wParam, lParam );
860 static HRESULT IOCS_Attach( IOCS *This, HWND hWnd, IUnknown *pUnkControl ) /* subclass hWnd */
863 IUnknown_QueryInterface( pUnkControl, &IID_IOleObject, (void**)&This->control );
864 IOleObject_SetClientSite( This->control, THIS2IOLECLIENTSITE( This ) );
865 SetWindowLongPtrW( hWnd, GWLP_USERDATA, (ULONG_PTR) This );
866 This->OrigWndProc = (WNDPROC)SetWindowLongPtrW( hWnd, GWLP_WNDPROC, (ULONG_PTR) AtlHost_wndproc );
871 static HRESULT IOCS_Init( IOCS *This )
874 static const WCHAR AXWIN[] = {'A','X','W','I','N',0};
876 IOleObject_SetHostNames( This->control, AXWIN, AXWIN );
878 GetClientRect( This->hWnd, &rect );
879 IOCS_OnSize( This, &rect );
880 IOleObject_DoVerb( This->control, OLEIVERB_INPLACEACTIVATE, NULL, THIS2IOLECLIENTSITE( This ), 0, This->hWnd, &rect );
885 /**********************************************************************
886 * Create new instance of Atl host component and attach it to window *
888 static HRESULT IOCS_Create( HWND hWnd, IUnknown *pUnkControl, IOCS **ppSite )
894 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IOCS));
897 return E_OUTOFMEMORY;
899 This->lpOleClientSiteVtbl = &OleClientSite_vtbl;
900 This->lpOleContainerVtbl = &OleContainer_vtbl;
901 This->lpOleInPlaceSiteWindowlessVtbl = &OleInPlaceSiteWindowless_vtbl;
902 This->lpOleInPlaceFrameVtbl = &OleInPlaceFrame_vtbl;
903 This->lpOleControlSiteVtbl = &OleControlSite_vtbl;
906 This->OrigWndProc = NULL;
908 This->fWindowless = This->fActive = This->fInPlace = FALSE;
910 hr = IOCS_Attach( This, hWnd, pUnkControl );
911 if ( SUCCEEDED( hr ) )
912 hr = IOCS_Init( This );
913 if ( SUCCEEDED( hr ) )
916 IOCS_Release( This );
922 /***********************************************************************
923 * AtlAxCreateControl [ATL.@]
925 HRESULT WINAPI AtlAxCreateControl(LPCOLESTR lpszName, HWND hWnd,
926 IStream *pStream, IUnknown **ppUnkContainer)
928 return AtlAxCreateControlEx( lpszName, hWnd, pStream, ppUnkContainer,
932 /***********************************************************************
933 * AtlAxCreateControlEx [ATL.@]
936 * See http://www.codeproject.com/com/cwebpage.asp for some background
939 HRESULT WINAPI AtlAxCreateControlEx(LPCOLESTR lpszName, HWND hWnd,
940 IStream *pStream, IUnknown **ppUnkContainer, IUnknown **ppUnkControl,
941 REFIID iidSink, IUnknown *punkSink)
945 IOleObject *pControl;
946 IUnknown *pUnkControl;
947 IPersistStreamInit *pPSInit;
948 IUnknown *pContainer;
949 enum {IsGUID=0,IsHTML=1,IsURL=2} content;
951 TRACE("(%s %p %p %p %p %p %p)\n", debugstr_w(lpszName), hWnd, pStream,
952 ppUnkContainer, ppUnkControl, iidSink, punkSink);
954 hRes = CLSIDFromString( (LPOLESTR) lpszName, &controlId );
956 hRes = CLSIDFromProgID( lpszName, &controlId );
957 if ( SUCCEEDED( hRes ) )
960 /* FIXME - check for MSHTML: prefix! */
962 memcpy( &controlId, &CLSID_WebBrowser, sizeof(controlId) );
965 hRes = CoCreateInstance( &controlId, 0, CLSCTX_ALL, &IID_IOleObject,
966 (void**) &pControl );
967 if ( FAILED( hRes ) )
969 WARN( "cannot create ActiveX control %s instance - error 0x%08x\n",
970 debugstr_guid( &controlId ), hRes );
974 hRes = IOleObject_QueryInterface( pControl, &IID_IPersistStreamInit, (void**) &pPSInit );
975 if ( SUCCEEDED( hRes ) )
978 IPersistStreamInit_InitNew( pPSInit );
980 IPersistStreamInit_Load( pPSInit, pStream );
981 IPersistStreamInit_Release( pPSInit );
983 WARN("cannot get IID_IPersistStreamInit out of control\n");
985 IOleObject_QueryInterface( pControl, &IID_IUnknown, (void**) &pUnkControl );
986 IOleObject_Release( pControl );
989 hRes = AtlAxAttachControl( pUnkControl, hWnd, &pContainer );
990 if ( FAILED( hRes ) )
991 WARN("cannot attach control to window\n");
993 if ( content == IsURL )
995 IWebBrowser2 *browser;
997 hRes = IOleObject_QueryInterface( pControl, &IID_IWebBrowser2, (void**) &browser );
999 WARN( "Cannot query IWebBrowser2 interface: %08x\n", hRes );
1003 IWebBrowser2_put_Visible( browser, VARIANT_TRUE ); /* it seems that native does this on URL (but do not on MSHTML:! why? */
1005 V_VT(&url) = VT_BSTR;
1006 V_BSTR(&url) = SysAllocString( lpszName );
1008 hRes = IWebBrowser2_Navigate2( browser, &url, NULL, NULL, NULL, NULL );
1009 if ( FAILED( hRes ) )
1010 WARN( "IWebBrowser2::Navigate2 failed: %08x\n", hRes );
1011 SysFreeString( V_BSTR(&url) );
1013 IWebBrowser2_Release( browser );
1019 *ppUnkContainer = pContainer;
1021 IUnknown_AddRef( pContainer );
1025 *ppUnkControl = pUnkControl;
1027 IUnknown_AddRef( pUnkControl );
1030 IUnknown_Release( pUnkControl );
1032 IUnknown_Release( pContainer );
1037 /***********************************************************************
1038 * AtlAxAttachControl [ATL.@]
1040 HRESULT WINAPI AtlAxAttachControl(IUnknown* pControl, HWND hWnd, IUnknown** ppUnkContainer)
1042 IOCS *pUnkContainer;
1045 TRACE( "%p %p %p\n", pControl, hWnd, ppUnkContainer );
1047 *ppUnkContainer = NULL;
1049 hr = IOCS_Create( hWnd, pControl, &pUnkContainer );
1050 if ( SUCCEEDED( hr ) )
1052 *ppUnkContainer = (IUnknown*) pUnkContainer;
1058 /**********************************************************************
1059 * Helper function for AX_ConvertDialogTemplate
1061 static inline BOOL advance_array(WORD **pptr, DWORD *palloc, DWORD *pfilled, const WORD *data, DWORD size)
1063 if ( (*pfilled + size) > *palloc )
1065 *palloc = ((*pfilled+size) + 0xFF) & ~0xFF;
1066 *pptr = HeapReAlloc( GetProcessHeap(), 0, *pptr, *palloc * sizeof(WORD) );
1070 RtlMoveMemory( *pptr+*pfilled, data, size * sizeof(WORD) );
1075 /**********************************************************************
1076 * Convert ActiveX control templates to AtlAxWin class instances
1078 static LPDLGTEMPLATEW AX_ConvertDialogTemplate(LPCDLGTEMPLATEW src_tmpl)
1080 #define GET_WORD(x) (*(const WORD *)(x))
1081 #define GET_DWORD(x) (*(const DWORD *)(x))
1082 #define PUT_BLOCK(x,y) do {if (!advance_array(&output, &allocated, &filled, (x), (y))) return NULL;} while (0)
1083 #define PUT_WORD(x) do {WORD w = (x);PUT_BLOCK(&w, 1);} while(0)
1084 #define PUT_DWORD(x) do {DWORD w = (x);PUT_BLOCK(&w, 2);} while(0)
1085 const WORD *tmp, *src = (const WORD *)src_tmpl;
1087 DWORD allocated, filled; /* in WORDs */
1089 WORD signature, dlgver, rescount;
1092 filled = 0; allocated = 256;
1093 output = HeapAlloc( GetProcessHeap(), 0, allocated * sizeof(WORD) );
1099 signature = GET_WORD(src);
1100 dlgver = GET_WORD(src + 1);
1101 if (signature == 1 && dlgver == 0xFFFF)
1105 style = GET_DWORD(src);
1107 rescount = GET_WORD(src++);
1109 if ( GET_WORD(src) == 0xFFFF ) /* menu */
1112 src += strlenW(src) + 1;
1113 if ( GET_WORD(src) == 0xFFFF ) /* class */
1116 src += strlenW(src) + 1;
1117 src += strlenW(src) + 1; /* title */
1118 if ( style & (DS_SETFONT | DS_SHELLFONT) )
1121 src += strlenW(src) + 1;
1125 style = GET_DWORD(src);
1127 rescount = GET_WORD(src++);
1129 if ( GET_WORD(src) == 0xFFFF ) /* menu */
1132 src += strlenW(src) + 1;
1133 if ( GET_WORD(src) == 0xFFFF ) /* class */
1136 src += strlenW(src) + 1;
1137 src += strlenW(src) + 1; /* title */
1138 if ( style & DS_SETFONT )
1141 src += strlenW(src) + 1;
1144 PUT_BLOCK(tmp, src-tmp);
1148 src = (const WORD *)( ( ((ULONG_PTR)src) + 3) & ~3); /* align on DWORD boundary */
1149 filled = (filled + 1) & ~1; /* depends on DWORD-aligned allocation unit */
1156 PUT_BLOCK(tmp, src-tmp);
1159 if ( GET_WORD(src) == 0xFFFF ) /* class */
1164 src += strlenW(src) + 1;
1166 src += strlenW(src) + 1; /* title */
1167 if ( GET_WORD(tmp) == '{' ) /* all this mess created because of this line */
1169 static const WCHAR AtlAxWin[9]={'A','t','l','A','x','W','i','n',0};
1170 PUT_BLOCK(AtlAxWin, sizeof(AtlAxWin)/sizeof(WCHAR));
1171 PUT_BLOCK(tmp, strlenW(tmp)+1);
1173 PUT_BLOCK(tmp, src-tmp);
1175 if ( GET_WORD(src) )
1177 WORD size = (GET_WORD(src)+sizeof(WORD)-1) / sizeof(WORD); /* quite ugly :( Maybe use BYTE* instead of WORD* everywhere ? */
1178 PUT_BLOCK(src, size);
1187 return (LPDLGTEMPLATEW) output;
1190 /***********************************************************************
1191 * AtlAxCreateDialogA [ATL.@]
1193 * Creates a dialog window
1196 * hInst [I] Application instance
1197 * name [I] Dialog box template name
1198 * owner [I] Dialog box parent HWND
1199 * dlgProc [I] Dialog box procedure
1200 * param [I] This value will be passed to dlgProc as WM_INITDIALOG's message lParam
1203 * Window handle of dialog window.
1205 HWND WINAPI AtlAxCreateDialogA(HINSTANCE hInst, LPCSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param)
1211 if ( HIWORD(name) == 0 )
1212 return AtlAxCreateDialogW( hInst, (LPCWSTR) name, owner, dlgProc, param );
1214 length = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
1215 nameW = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) );
1218 MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, length );
1219 res = AtlAxCreateDialogW( hInst, nameW, owner, dlgProc, param );
1220 HeapFree( GetProcessHeap(), 0, nameW );
1225 /***********************************************************************
1226 * AtlAxCreateDialogW [ATL.@]
1228 * See AtlAxCreateDialogA
1231 HWND WINAPI AtlAxCreateDialogW(HINSTANCE hInst, LPCWSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param)
1235 LPCDLGTEMPLATEW ptr;
1236 LPDLGTEMPLATEW newptr;
1239 FIXME("(%p %s %p %p %lx) - not tested\n", hInst, debugstr_w(name), owner, dlgProc, param);
1241 hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG );
1244 hgl = LoadResource (hInst, hrsrc);
1247 ptr = (LPCDLGTEMPLATEW)LockResource ( hgl );
1250 FreeResource( hgl );
1253 newptr = AX_ConvertDialogTemplate( ptr );
1256 res = CreateDialogIndirectParamW( hInst, newptr, owner, dlgProc, param );
1257 HeapFree( GetProcessHeap(), 0, newptr );
1260 FreeResource ( hrsrc );
1264 /***********************************************************************
1265 * AtlAxGetHost [ATL.@]
1268 HRESULT WINAPI AtlAxGetHost(HWND hWnd, IUnknown **pUnk)
1272 TRACE( "(%p, %p)\n", hWnd, pUnk );
1276 This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA );
1279 WARN("No container attached to %p\n", hWnd );
1283 return IOCS_QueryInterface( This, &IID_IUnknown, (void**) pUnk );
1286 /***********************************************************************
1287 * AtlAxGetControl [ATL.@]
1290 HRESULT WINAPI AtlAxGetControl(HWND hWnd, IUnknown **pUnk)
1294 TRACE( "(%p, %p)\n", hWnd, pUnk );
1298 This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA );
1299 if ( !This || !This->control )
1301 WARN("No control attached to %p\n", hWnd );
1305 return IOleObject_QueryInterface( This->control, &IID_IUnknown, (void**) pUnk );