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
30 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(atl
);
44 const IOleClientSiteVtbl
*lpOleClientSiteVtbl
;
45 const IOleContainerVtbl
*lpOleContainerVtbl
;
46 const IOleInPlaceSiteWindowlessVtbl
*lpOleInPlaceSiteWindowlessVtbl
;
47 const IOleInPlaceFrameVtbl
*lpOleInPlaceFrameVtbl
;
48 const IOleControlSiteVtbl
*lpOleControlSiteVtbl
;
55 BOOL fActive
, fInPlace
, fWindowless
;
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
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
69 GetWindowTextW( hWnd
, ptr
, len
);
70 AtlAxCreateControlEx( ptr
, hWnd
, NULL
, NULL
, NULL
, NULL
, NULL
);
71 HeapFree( GetProcessHeap(), 0, ptr
);
74 return DefWindowProcW( hWnd
, wMsg
, wParam
, lParam
);
77 /***********************************************************************
78 * AtlAxWinInit [ATL.@]
79 * Initializes the control-hosting code: registering the AtlAxWin,
80 * AtlAxWin7 and AtlAxWinLic7 window classes and some messages.
86 BOOL WINAPI
AtlAxWinInit(void)
89 const WCHAR AtlAxWin
[] = {'A','t','l','A','x','W','i','n',0};
93 if ( FAILED( OleInitialize(NULL
) ) )
96 wcex
.cbSize
= sizeof(wcex
);
100 wcex
.hInstance
= GetModuleHandleW( NULL
);
103 wcex
.hbrBackground
= NULL
;
104 wcex
.lpszMenuName
= NULL
;
107 wcex
.lpfnWndProc
= AtlAxWin_wndproc
;
108 wcex
.lpszClassName
= AtlAxWin
;
109 if ( !RegisterClassExW( &wcex
) )
115 /***********************************************************************
116 * Atl container component implementation
120 static ULONG WINAPI
IOCS_AddRef(IOCS
*This
)
122 ULONG ref
= InterlockedIncrement(&This
->ref
);
124 TRACE( "(%p) : AddRef from %d\n", This
, ref
- 1 );
129 #define THIS2IOLECLIENTSITE(This) ((IOleClientSite*)&This->lpOleClientSiteVtbl)
130 #define THIS2IOLECONTAINER(This) ((IOleContainer*)&This->lpOleContainerVtbl)
131 #define THIS2IOLEINPLACESITEWINDOWLESS(This) ((IOleInPlaceSiteWindowless*)&This->lpOleInPlaceSiteWindowlessVtbl)
132 #define THIS2IOLEINPLACEFRAME(This) ((IOleInPlaceFrame*)&This->lpOleInPlaceFrameVtbl)
133 #define THIS2IOLECONTROLSITE(This) ((IOleControlSite*)&This->lpOleControlSiteVtbl)
135 static HRESULT WINAPI
IOCS_QueryInterface(IOCS
*This
, REFIID riid
, void **ppv
)
139 if ( IsEqualIID( &IID_IUnknown
, riid
)
140 || IsEqualIID( &IID_IOleClientSite
, riid
) )
142 *ppv
= THIS2IOLECLIENTSITE(This
);
143 } else if ( IsEqualIID( &IID_IOleContainer
, riid
) )
145 *ppv
= THIS2IOLECONTAINER(This
);
146 } else if ( IsEqualIID( &IID_IOleInPlaceSite
, riid
) || IsEqualIID( &IID_IOleInPlaceSiteEx
, riid
) || IsEqualIID( &IID_IOleInPlaceSiteWindowless
, riid
) )
148 *ppv
= THIS2IOLEINPLACESITEWINDOWLESS(This
);
149 } else if ( IsEqualIID( &IID_IOleInPlaceFrame
, riid
) )
151 *ppv
= THIS2IOLEINPLACEFRAME(This
);
152 } else if ( IsEqualIID( &IID_IOleControlSite
, riid
) )
154 *ppv
= THIS2IOLECONTROLSITE(This
);
163 WARN("unsupported interface %s\n", debugstr_guid( riid
) );
165 return E_NOINTERFACE
;
168 static HRESULT
IOCS_Detach( IOCS
*This
);
169 static ULONG WINAPI
IOCS_Release(IOCS
*This
)
171 ULONG ref
= InterlockedDecrement(&This
->ref
);
173 TRACE( "(%p) : ReleaseRef to %d\n", This
, ref
);
178 HeapFree( GetProcessHeap(), 0, This
);
184 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
186 /****** IOleClientSite *****/
188 #define IFACE2THIS(iface) DEFINE_THIS(IOCS,OleClientSite, iface)
189 static HRESULT WINAPI
OleClientSite_QueryInterface(IOleClientSite
*iface
, REFIID riid
, void **ppv
)
191 IOCS
*This
= IFACE2THIS(iface
);
192 return IOCS_QueryInterface(This
, riid
, ppv
);
194 static ULONG WINAPI
OleClientSite_AddRef(IOleClientSite
*iface
)
196 IOCS
*This
= IFACE2THIS(iface
);
197 return IOCS_AddRef(This
);
199 static ULONG WINAPI
OleClientSite_Release(IOleClientSite
*iface
)
201 IOCS
*This
= IFACE2THIS(iface
);
202 return IOCS_Release(This
);
204 static HRESULT WINAPI
OleClientSite_SaveObject(IOleClientSite
*iface
)
206 IOCS
*This
= IFACE2THIS(iface
);
207 FIXME( "(%p) - stub\n", This
);
210 static HRESULT WINAPI
OleClientSite_GetMoniker(IOleClientSite
*iface
, DWORD dwAssign
, DWORD dwWhichMoniker
, IMoniker
**ppmk
)
212 IOCS
*This
= IFACE2THIS(iface
);
214 FIXME( "(%p, 0x%x, 0x%x, %p)\n", This
, dwAssign
, dwWhichMoniker
, ppmk
);
217 static HRESULT WINAPI
OleClientSite_GetContainer(IOleClientSite
*iface
, IOleContainer
**ppContainer
)
219 IOCS
*This
= IFACE2THIS(iface
);
220 TRACE( "(%p, %p)\n", This
, ppContainer
);
221 return OleClientSite_QueryInterface( iface
, &IID_IOleContainer
, (void**)ppContainer
);
223 static HRESULT WINAPI
OleClientSite_ShowObject(IOleClientSite
*iface
)
225 IOCS
*This
= IFACE2THIS(iface
);
226 FIXME( "(%p) - stub\n", This
);
229 static HRESULT WINAPI
OleClientSite_OnShowWindow(IOleClientSite
*iface
, BOOL fShow
)
231 IOCS
*This
= IFACE2THIS(iface
);
232 FIXME( "(%p, %s) - stub\n", This
, fShow
? "TRUE" : "FALSE" );
235 static HRESULT WINAPI
OleClientSite_RequestNewObjectLayout(IOleClientSite
*iface
)
237 IOCS
*This
= IFACE2THIS(iface
);
238 FIXME( "(%p) - stub\n", This
);
244 /****** IOleContainer *****/
245 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleContainer, iface)
246 static HRESULT WINAPI
OleContainer_QueryInterface( IOleContainer
* iface
, REFIID riid
, void** ppv
)
248 IOCS
*This
= IFACE2THIS(iface
);
249 return IOCS_QueryInterface( This
, riid
, ppv
);
251 static ULONG WINAPI
OleContainer_AddRef(IOleContainer
* iface
)
253 IOCS
*This
= IFACE2THIS(iface
);
254 return IOCS_AddRef(This
);
256 static ULONG WINAPI
OleContainer_Release(IOleContainer
* iface
)
258 IOCS
*This
= IFACE2THIS(iface
);
259 return IOCS_Release(This
);
261 static HRESULT WINAPI
OleContainer_ParseDisplayName(IOleContainer
* iface
, IBindCtx
* pbc
,
262 LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
)
264 IOCS
*This
= IFACE2THIS(iface
);
265 FIXME( "(%p,%p,%s,%p,%p) - stub\n", This
, pbc
, debugstr_w(pszDisplayName
), pchEaten
, ppmkOut
);
268 static HRESULT WINAPI
OleContainer_EnumObjects(IOleContainer
* iface
, DWORD grfFlags
, IEnumUnknown
** ppenum
)
270 IOCS
*This
= IFACE2THIS(iface
);
271 FIXME( "(%p, %u, %p) - stub\n", This
, grfFlags
, ppenum
);
274 static HRESULT WINAPI
OleContainer_LockContainer(IOleContainer
* iface
, BOOL fLock
)
276 IOCS
*This
= IFACE2THIS(iface
);
277 FIXME( "(%p, %s) - stub\n", This
, fLock
?"TRUE":"FALSE" );
283 /****** IOleInPlaceSiteWindowless *******/
284 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleInPlaceSiteWindowless, iface)
285 static HRESULT WINAPI
OleInPlaceSiteWindowless_QueryInterface(IOleInPlaceSiteWindowless
*iface
, REFIID riid
, void **ppv
)
287 IOCS
*This
= IFACE2THIS(iface
);
288 return IOCS_QueryInterface(This
, riid
, ppv
);
290 static ULONG WINAPI
OleInPlaceSiteWindowless_AddRef(IOleInPlaceSiteWindowless
*iface
)
292 IOCS
*This
= IFACE2THIS(iface
);
293 return IOCS_AddRef(This
);
295 static ULONG WINAPI
OleInPlaceSiteWindowless_Release(IOleInPlaceSiteWindowless
*iface
)
297 IOCS
*This
= IFACE2THIS(iface
);
298 return IOCS_Release(This
);
300 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetWindow(IOleInPlaceSiteWindowless
* iface
, HWND
* phwnd
)
302 IOCS
*This
= IFACE2THIS(iface
);
304 TRACE("(%p,%p)\n", This
, phwnd
);
308 static HRESULT WINAPI
OleInPlaceSiteWindowless_ContextSensitiveHelp(IOleInPlaceSiteWindowless
* iface
, BOOL fEnterMode
)
310 IOCS
*This
= IFACE2THIS(iface
);
311 FIXME("(%p,%d) - stub\n", This
, fEnterMode
);
314 static HRESULT WINAPI
OleInPlaceSiteWindowless_CanInPlaceActivate(IOleInPlaceSiteWindowless
*iface
)
316 IOCS
*This
= IFACE2THIS(iface
);
317 TRACE("(%p)\n", This
);
320 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceActivate(IOleInPlaceSiteWindowless
*iface
)
322 IOCS
*This
= IFACE2THIS(iface
);
324 TRACE("(%p)\n", This
);
326 This
->fInPlace
= TRUE
;
329 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnUIActivate(IOleInPlaceSiteWindowless
*iface
)
331 IOCS
*This
= IFACE2THIS(iface
);
333 TRACE("(%p)\n", This
);
337 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetWindowContext(IOleInPlaceSiteWindowless
*iface
,
338 IOleInPlaceFrame
**ppFrame
, IOleInPlaceUIWindow
**ppDoc
, LPRECT lprcPosRect
,
339 LPRECT lprcClipRect
, LPOLEINPLACEFRAMEINFO lpFrameInfo
)
341 IOCS
*This
= IFACE2THIS(iface
);
343 TRACE("(%p,%p,%p,%p,%p,%p)\n", This
, ppFrame
, ppDoc
, lprcPosRect
, lprcClipRect
, lpFrameInfo
);
346 *lprcClipRect
= This
->size
;
348 *lprcPosRect
= This
->size
;
352 IOCS_QueryInterface( This
, &IID_IOleInPlaceFrame
, (void**) ppFrame
);
360 lpFrameInfo
->fMDIApp
= FALSE
;
361 lpFrameInfo
->hwndFrame
= This
->hWnd
;
362 lpFrameInfo
->haccel
= NULL
;
363 lpFrameInfo
->cAccelEntries
= 0;
368 static HRESULT WINAPI
OleInPlaceSiteWindowless_Scroll(IOleInPlaceSiteWindowless
*iface
, SIZE scrollExtent
)
370 IOCS
*This
= IFACE2THIS(iface
);
371 FIXME("(%p) - stub\n", This
);
374 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnUIDeactivate(IOleInPlaceSiteWindowless
*iface
, BOOL fUndoable
)
376 IOCS
*This
= IFACE2THIS(iface
);
377 FIXME("(%p,%d) - stub\n", This
, fUndoable
);
380 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceDeactivate(IOleInPlaceSiteWindowless
*iface
)
382 IOCS
*This
= IFACE2THIS(iface
);
384 TRACE("(%p)\n", This
);
386 This
->fInPlace
= This
->fWindowless
= FALSE
;
389 static HRESULT WINAPI
OleInPlaceSiteWindowless_DiscardUndoState(IOleInPlaceSiteWindowless
*iface
)
391 IOCS
*This
= IFACE2THIS(iface
);
392 FIXME("(%p) - stub\n", This
);
395 static HRESULT WINAPI
OleInPlaceSiteWindowless_DeactivateAndUndo(IOleInPlaceSiteWindowless
*iface
)
397 IOCS
*This
= IFACE2THIS(iface
);
398 FIXME("(%p) - stub\n", This
);
401 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnPosRectChange(IOleInPlaceSiteWindowless
*iface
, LPCRECT lprcPosRect
)
403 IOCS
*This
= IFACE2THIS(iface
);
404 FIXME("(%p,%p) - stub\n", This
, lprcPosRect
);
407 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceActivateEx( IOleInPlaceSiteWindowless
*iface
, BOOL
* pfNoRedraw
, DWORD dwFlags
)
409 IOCS
*This
= IFACE2THIS(iface
);
413 This
->fActive
= This
->fInPlace
= TRUE
;
414 if ( dwFlags
& ACTIVATE_WINDOWLESS
)
415 This
->fWindowless
= TRUE
;
418 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceDeactivateEx( IOleInPlaceSiteWindowless
*iface
, BOOL fNoRedraw
)
420 IOCS
*This
= IFACE2THIS(iface
);
424 This
->fActive
= This
->fInPlace
= This
->fWindowless
= FALSE
;
427 static HRESULT WINAPI
OleInPlaceSiteWindowless_RequestUIActivate( IOleInPlaceSiteWindowless
*iface
)
432 static HRESULT WINAPI
OleInPlaceSiteWindowless_CanWindowlessActivate( IOleInPlaceSiteWindowless
*iface
)
437 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetCapture( IOleInPlaceSiteWindowless
*iface
)
442 static HRESULT WINAPI
OleInPlaceSiteWindowless_SetCapture( IOleInPlaceSiteWindowless
*iface
, BOOL fCapture
)
447 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetFocus( IOleInPlaceSiteWindowless
*iface
)
452 static HRESULT WINAPI
OleInPlaceSiteWindowless_SetFocus( IOleInPlaceSiteWindowless
*iface
, BOOL fFocus
)
457 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetDC( IOleInPlaceSiteWindowless
*iface
, LPCRECT pRect
, DWORD grfFlags
, HDC
* phDC
)
462 static HRESULT WINAPI
OleInPlaceSiteWindowless_ReleaseDC( IOleInPlaceSiteWindowless
*iface
, HDC hDC
)
467 static HRESULT WINAPI
OleInPlaceSiteWindowless_InvalidateRect( IOleInPlaceSiteWindowless
*iface
, LPCRECT pRect
, BOOL fErase
)
472 static HRESULT WINAPI
OleInPlaceSiteWindowless_InvalidateRgn( IOleInPlaceSiteWindowless
*iface
, HRGN hRGN
, BOOL fErase
)
477 static HRESULT WINAPI
OleInPlaceSiteWindowless_ScrollRect( IOleInPlaceSiteWindowless
*iface
, INT dx
, INT dy
, LPCRECT pRectScroll
, LPCRECT pRectClip
)
482 static HRESULT WINAPI
OleInPlaceSiteWindowless_AdjustRect( IOleInPlaceSiteWindowless
*iface
, LPRECT prc
)
487 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnDefWindowMessage( IOleInPlaceSiteWindowless
*iface
, UINT msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
* plResult
)
495 /****** IOleInPlaceFrame *******/
496 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleInPlaceFrame, iface)
497 static HRESULT WINAPI
OleInPlaceFrame_QueryInterface(IOleInPlaceFrame
*iface
, REFIID riid
, void **ppv
)
499 IOCS
*This
= IFACE2THIS(iface
);
500 return IOCS_QueryInterface(This
, riid
, ppv
);
502 static ULONG WINAPI
OleInPlaceFrame_AddRef(IOleInPlaceFrame
*iface
)
504 IOCS
*This
= IFACE2THIS(iface
);
505 return IOCS_AddRef(This
);
507 static ULONG WINAPI
OleInPlaceFrame_Release(IOleInPlaceFrame
*iface
)
509 IOCS
*This
= IFACE2THIS(iface
);
510 return IOCS_Release(This
);
512 static HRESULT WINAPI
OleInPlaceFrame_GetWindow(IOleInPlaceFrame
*iface
, HWND
*phWnd
)
514 IOCS
*This
= IFACE2THIS(iface
);
516 TRACE( "(%p,%p)\n", This
, phWnd
);
522 static HRESULT WINAPI
OleInPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame
*iface
, BOOL fEnterMode
)
524 IOCS
*This
= IFACE2THIS(iface
);
526 FIXME( "(%p,%d) - stub\n", This
, fEnterMode
);
530 static HRESULT WINAPI
OleInPlaceFrame_GetBorder(IOleInPlaceFrame
*iface
, LPRECT lprectBorder
)
532 IOCS
*This
= IFACE2THIS(iface
);
534 FIXME( "(%p,%p) - stub\n", This
, lprectBorder
);
538 static HRESULT WINAPI
OleInPlaceFrame_RequestBorderSpace(IOleInPlaceFrame
*iface
, LPCBORDERWIDTHS pborderwidths
)
540 IOCS
*This
= IFACE2THIS(iface
);
542 FIXME( "(%p,%p) - stub\n", This
, pborderwidths
);
546 static HRESULT WINAPI
OleInPlaceFrame_SetBorderSpace(IOleInPlaceFrame
*iface
, LPCBORDERWIDTHS pborderwidths
)
548 IOCS
*This
= IFACE2THIS(iface
);
550 FIXME( "(%p,%p) - stub\n", This
, pborderwidths
);
554 static HRESULT WINAPI
OleInPlaceFrame_SetActiveObject(IOleInPlaceFrame
*iface
, IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR pszObjName
)
556 IOCS
*This
= IFACE2THIS(iface
);
558 FIXME( "(%p,%p,%s) - stub\n", This
, pActiveObject
, debugstr_w(pszObjName
) );
562 static HRESULT WINAPI
OleInPlaceFrame_InsertMenus(IOleInPlaceFrame
*iface
, HMENU hmenuShared
, LPOLEMENUGROUPWIDTHS lpMenuWidths
)
564 IOCS
*This
= IFACE2THIS(iface
);
566 FIXME( "(%p,%p,%p) - stub\n", This
, hmenuShared
, lpMenuWidths
);
570 static HRESULT WINAPI
OleInPlaceFrame_SetMenu(IOleInPlaceFrame
*iface
, HMENU hmenuShared
, HOLEMENU holemenu
, HWND hwndActiveObject
)
572 IOCS
*This
= IFACE2THIS(iface
);
574 FIXME( "(%p,%p,%p,%p) - stub\n", This
, hmenuShared
, holemenu
, hwndActiveObject
);
577 static HRESULT WINAPI
OleInPlaceFrame_RemoveMenus(IOleInPlaceFrame
*iface
, HMENU hmenuShared
)
579 IOCS
*This
= IFACE2THIS(iface
);
581 FIXME( "(%p, %p) - stub\n", This
, hmenuShared
);
585 static HRESULT WINAPI
OleInPlaceFrame_SetStatusText(IOleInPlaceFrame
*iface
, LPCOLESTR pszStatusText
)
587 IOCS
*This
= IFACE2THIS(iface
);
589 FIXME( "(%p, %s) - stub\n", This
, debugstr_w( pszStatusText
) );
593 static HRESULT WINAPI
OleInPlaceFrame_EnableModeless(IOleInPlaceFrame
*iface
, BOOL fEnable
)
595 IOCS
*This
= IFACE2THIS(iface
);
597 FIXME( "(%p, %d) - stub\n", This
, fEnable
);
601 static HRESULT WINAPI
OleInPlaceFrame_TranslateAccelerator(IOleInPlaceFrame
*iface
, LPMSG lpmsg
, WORD wID
)
603 IOCS
*This
= IFACE2THIS(iface
);
605 FIXME( "(%p, %p, %x) - stub\n", This
, lpmsg
, wID
);
611 /****** IOleControlSite *******/
612 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleControlSite, iface)
613 static HRESULT WINAPI
OleControlSite_QueryInterface(IOleControlSite
*iface
, REFIID riid
, void **ppv
)
615 IOCS
*This
= IFACE2THIS(iface
);
616 return IOCS_QueryInterface(This
, riid
, ppv
);
618 static ULONG WINAPI
OleControlSite_AddRef(IOleControlSite
*iface
)
620 IOCS
*This
= IFACE2THIS(iface
);
621 return IOCS_AddRef(This
);
623 static ULONG WINAPI
OleControlSite_Release(IOleControlSite
*iface
)
625 IOCS
*This
= IFACE2THIS(iface
);
626 return IOCS_Release(This
);
628 static HRESULT WINAPI
OleControlSite_OnControlInfoChanged( IOleControlSite
* This
)
633 static HRESULT WINAPI
OleControlSite_LockInPlaceActive( IOleControlSite
* This
, BOOL fLock
)
638 static HRESULT WINAPI
OleControlSite_GetExtendedControl( IOleControlSite
* This
, IDispatch
** ppDisp
)
643 static HRESULT WINAPI
OleControlSite_TransformCoords( IOleControlSite
* This
, POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD dwFlags
)
648 static HRESULT WINAPI
OleControlSite_TranslateAccelerator( IOleControlSite
* This
, MSG
* pMsg
, DWORD grfModifiers
)
653 static HRESULT WINAPI
OleControlSite_OnFocus( IOleControlSite
* This
, BOOL fGotFocus
)
658 static HRESULT WINAPI
OleControlSite_ShowPropertyFrame( IOleControlSite
* This
)
667 static const IOleClientSiteVtbl OleClientSite_vtbl
= {
668 OleClientSite_QueryInterface
,
669 OleClientSite_AddRef
,
670 OleClientSite_Release
,
671 OleClientSite_SaveObject
,
672 OleClientSite_GetMoniker
,
673 OleClientSite_GetContainer
,
674 OleClientSite_ShowObject
,
675 OleClientSite_OnShowWindow
,
676 OleClientSite_RequestNewObjectLayout
678 static const IOleContainerVtbl OleContainer_vtbl
= {
679 OleContainer_QueryInterface
,
681 OleContainer_Release
,
682 OleContainer_ParseDisplayName
,
683 OleContainer_EnumObjects
,
684 OleContainer_LockContainer
686 static const IOleInPlaceSiteWindowlessVtbl OleInPlaceSiteWindowless_vtbl
= {
687 OleInPlaceSiteWindowless_QueryInterface
,
688 OleInPlaceSiteWindowless_AddRef
,
689 OleInPlaceSiteWindowless_Release
,
690 OleInPlaceSiteWindowless_GetWindow
,
691 OleInPlaceSiteWindowless_ContextSensitiveHelp
,
692 OleInPlaceSiteWindowless_CanInPlaceActivate
,
693 OleInPlaceSiteWindowless_OnInPlaceActivate
,
694 OleInPlaceSiteWindowless_OnUIActivate
,
695 OleInPlaceSiteWindowless_GetWindowContext
,
696 OleInPlaceSiteWindowless_Scroll
,
697 OleInPlaceSiteWindowless_OnUIDeactivate
,
698 OleInPlaceSiteWindowless_OnInPlaceDeactivate
,
699 OleInPlaceSiteWindowless_DiscardUndoState
,
700 OleInPlaceSiteWindowless_DeactivateAndUndo
,
701 OleInPlaceSiteWindowless_OnPosRectChange
,
702 OleInPlaceSiteWindowless_OnInPlaceActivateEx
,
703 OleInPlaceSiteWindowless_OnInPlaceDeactivateEx
,
704 OleInPlaceSiteWindowless_RequestUIActivate
,
705 OleInPlaceSiteWindowless_CanWindowlessActivate
,
706 OleInPlaceSiteWindowless_GetCapture
,
707 OleInPlaceSiteWindowless_SetCapture
,
708 OleInPlaceSiteWindowless_GetFocus
,
709 OleInPlaceSiteWindowless_SetFocus
,
710 OleInPlaceSiteWindowless_GetDC
,
711 OleInPlaceSiteWindowless_ReleaseDC
,
712 OleInPlaceSiteWindowless_InvalidateRect
,
713 OleInPlaceSiteWindowless_InvalidateRgn
,
714 OleInPlaceSiteWindowless_ScrollRect
,
715 OleInPlaceSiteWindowless_AdjustRect
,
716 OleInPlaceSiteWindowless_OnDefWindowMessage
718 static const IOleInPlaceFrameVtbl OleInPlaceFrame_vtbl
=
720 OleInPlaceFrame_QueryInterface
,
721 OleInPlaceFrame_AddRef
,
722 OleInPlaceFrame_Release
,
723 OleInPlaceFrame_GetWindow
,
724 OleInPlaceFrame_ContextSensitiveHelp
,
725 OleInPlaceFrame_GetBorder
,
726 OleInPlaceFrame_RequestBorderSpace
,
727 OleInPlaceFrame_SetBorderSpace
,
728 OleInPlaceFrame_SetActiveObject
,
729 OleInPlaceFrame_InsertMenus
,
730 OleInPlaceFrame_SetMenu
,
731 OleInPlaceFrame_RemoveMenus
,
732 OleInPlaceFrame_SetStatusText
,
733 OleInPlaceFrame_EnableModeless
,
734 OleInPlaceFrame_TranslateAccelerator
736 static const IOleControlSiteVtbl OleControlSite_vtbl
=
738 OleControlSite_QueryInterface
,
739 OleControlSite_AddRef
,
740 OleControlSite_Release
,
741 OleControlSite_OnControlInfoChanged
,
742 OleControlSite_LockInPlaceActive
,
743 OleControlSite_GetExtendedControl
,
744 OleControlSite_TransformCoords
,
745 OleControlSite_TranslateAccelerator
,
746 OleControlSite_OnFocus
,
747 OleControlSite_ShowPropertyFrame
750 static HRESULT
IOCS_Detach( IOCS
*This
) /* remove subclassing */
754 SetWindowLongPtrW( This
->hWnd
, GWLP_WNDPROC
, (ULONG_PTR
) This
->OrigWndProc
);
755 SetWindowLongPtrW( This
->hWnd
, GWLP_USERDATA
, (LONG_PTR
) NULL
);
760 IOleObject
*control
= This
->control
;
762 This
->control
= NULL
;
763 IOleObject_SetClientSite( control
, NULL
);
764 IOleObject_Release( control
);
769 static void IOCS_OnSize( IOCS
* This
, LPCRECT rect
)
773 This
->size
.left
= rect
->left
; This
->size
.right
= rect
->right
; This
->size
.top
= rect
->top
; This
->size
.bottom
= rect
->bottom
;
775 if ( !This
->control
)
778 inPix
.cx
= rect
->right
- rect
->left
;
779 inPix
.cy
= rect
->bottom
- rect
->top
;
780 AtlPixelToHiMetric( &inPix
, &inHi
);
781 IOleObject_SetExtent( This
->control
, DVASPECT_CONTENT
, &inHi
);
783 if ( This
->fInPlace
)
785 IOleInPlaceObject
*wl
;
787 if ( SUCCEEDED( IOleObject_QueryInterface( This
->control
, &IID_IOleInPlaceObject
, (void**)&wl
) ) )
789 IOleInPlaceObject_SetObjectRects( wl
, rect
, rect
);
790 IOleInPlaceObject_Release( wl
);
795 static void IOCS_OnShow( IOCS
*This
, BOOL fShow
)
797 if (!This
->control
|| This
->fActive
|| !fShow
)
800 This
->fActive
= TRUE
;
803 static void IOCS_OnDraw( IOCS
*This
)
807 if ( !This
->control
|| !This
->fWindowless
)
810 if ( SUCCEEDED( IOleObject_QueryInterface( This
->control
, &IID_IViewObject
, (void**)&view
) ) )
812 HDC dc
= GetDC( This
->hWnd
);
815 rect
.left
= This
->size
.left
; rect
.top
= This
->size
.top
;
816 rect
.bottom
= This
->size
.bottom
; rect
.right
= This
->size
.right
;
818 IViewObject_Draw( view
, DVASPECT_CONTENT
, ~0, NULL
, NULL
, 0, dc
, &rect
, &rect
, NULL
, 0 );
819 IViewObject_Release( view
);
820 ReleaseDC( This
->hWnd
, dc
);
824 static LRESULT
IOCS_OnWndProc( IOCS
*This
, HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
826 WNDPROC OrigWndProc
= This
->OrigWndProc
;
837 r
.right
= LOWORD( lParam
);
838 r
.bottom
= HIWORD( lParam
);
839 IOCS_OnSize( This
, &r
);
843 IOCS_OnShow( This
, (BOOL
) wParam
);
850 return CallWindowProcW( OrigWndProc
, hWnd
, uMsg
, wParam
, lParam
);
853 static LRESULT CALLBACK
AtlHost_wndproc( HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
855 IOCS
*This
= (IOCS
*) GetWindowLongPtrW( hWnd
, GWLP_USERDATA
);
856 return IOCS_OnWndProc( This
, hWnd
, wMsg
, wParam
, lParam
);
859 static HRESULT
IOCS_Attach( IOCS
*This
, HWND hWnd
, IUnknown
*pUnkControl
) /* subclass hWnd */
862 IUnknown_QueryInterface( pUnkControl
, &IID_IOleObject
, (void**)&This
->control
);
863 IOleObject_SetClientSite( This
->control
, THIS2IOLECLIENTSITE( This
) );
864 SetWindowLongPtrW( hWnd
, GWLP_USERDATA
, (ULONG_PTR
) This
);
865 This
->OrigWndProc
= (WNDPROC
)SetWindowLongPtrW( hWnd
, GWLP_WNDPROC
, (ULONG_PTR
) AtlHost_wndproc
);
870 static HRESULT
IOCS_Init( IOCS
*This
)
873 static const WCHAR AXWIN
[] = {'A','X','W','I','N',0};
875 IOleObject_SetHostNames( This
->control
, AXWIN
, AXWIN
);
877 GetClientRect( This
->hWnd
, &rect
);
878 IOCS_OnSize( This
, &rect
);
879 IOleObject_DoVerb( This
->control
, OLEIVERB_INPLACEACTIVATE
, NULL
, THIS2IOLECLIENTSITE( This
), 0, This
->hWnd
, &rect
);
884 /**********************************************************************
885 * Create new instance of Atl host component and attach it to window *
887 static HRESULT
IOCS_Create( HWND hWnd
, IUnknown
*pUnkControl
, IOCS
**ppSite
)
893 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(IOCS
));
896 return E_OUTOFMEMORY
;
898 This
->lpOleClientSiteVtbl
= &OleClientSite_vtbl
;
899 This
->lpOleContainerVtbl
= &OleContainer_vtbl
;
900 This
->lpOleInPlaceSiteWindowlessVtbl
= &OleInPlaceSiteWindowless_vtbl
;
901 This
->lpOleInPlaceFrameVtbl
= &OleInPlaceFrame_vtbl
;
902 This
->lpOleControlSiteVtbl
= &OleControlSite_vtbl
;
905 This
->OrigWndProc
= NULL
;
907 This
->fWindowless
= This
->fActive
= This
->fInPlace
= FALSE
;
909 hr
= IOCS_Attach( This
, hWnd
, pUnkControl
);
910 if ( SUCCEEDED( hr
) )
911 hr
= IOCS_Init( This
);
912 if ( SUCCEEDED( hr
) )
915 IOCS_Release( This
);
921 /***********************************************************************
922 * AtlAxCreateControl [ATL.@]
924 HRESULT WINAPI
AtlAxCreateControl(LPCOLESTR lpszName
, HWND hWnd
,
925 IStream
*pStream
, IUnknown
**ppUnkContainer
)
927 return AtlAxCreateControlEx( lpszName
, hWnd
, pStream
, ppUnkContainer
,
931 /***********************************************************************
932 * AtlAxCreateControlEx [ATL.@]
935 * See http://www.codeproject.com/com/cwebpage.asp for some background
938 HRESULT WINAPI
AtlAxCreateControlEx(LPCOLESTR lpszName
, HWND hWnd
,
939 IStream
*pStream
, IUnknown
**ppUnkContainer
, IUnknown
**ppUnkControl
,
940 REFIID iidSink
, IUnknown
*punkSink
)
944 IOleObject
*pControl
;
945 IUnknown
*pUnkControl
;
946 IPersistStreamInit
*pPSInit
;
947 IUnknown
*pContainer
;
948 enum {IsGUID
=0,IsHTML
=1,IsURL
=2} content
;
950 TRACE("(%s %p %p %p %p %p %p)\n", debugstr_w(lpszName
), hWnd
, pStream
,
951 ppUnkContainer
, ppUnkControl
, iidSink
, punkSink
);
953 hRes
= CLSIDFromString( (LPOLESTR
) lpszName
, &controlId
);
955 hRes
= CLSIDFromProgID( lpszName
, &controlId
);
956 if ( SUCCEEDED( hRes
) )
959 /* FIXME - check for MSHTML: prefix! */
961 controlId
= CLSID_WebBrowser
;
964 hRes
= CoCreateInstance( &controlId
, 0, CLSCTX_ALL
, &IID_IOleObject
,
965 (void**) &pControl
);
966 if ( FAILED( hRes
) )
968 WARN( "cannot create ActiveX control %s instance - error 0x%08x\n",
969 debugstr_guid( &controlId
), hRes
);
973 hRes
= IOleObject_QueryInterface( pControl
, &IID_IPersistStreamInit
, (void**) &pPSInit
);
974 if ( SUCCEEDED( hRes
) )
977 IPersistStreamInit_InitNew( pPSInit
);
979 IPersistStreamInit_Load( pPSInit
, pStream
);
980 IPersistStreamInit_Release( pPSInit
);
982 WARN("cannot get IID_IPersistStreamInit out of control\n");
984 IOleObject_QueryInterface( pControl
, &IID_IUnknown
, (void**) &pUnkControl
);
985 IOleObject_Release( pControl
);
988 hRes
= AtlAxAttachControl( pUnkControl
, hWnd
, &pContainer
);
989 if ( FAILED( hRes
) )
990 WARN("cannot attach control to window\n");
992 if ( content
== IsURL
)
994 IWebBrowser2
*browser
;
996 hRes
= IOleObject_QueryInterface( pControl
, &IID_IWebBrowser2
, (void**) &browser
);
998 WARN( "Cannot query IWebBrowser2 interface: %08x\n", hRes
);
1002 IWebBrowser2_put_Visible( browser
, VARIANT_TRUE
); /* it seems that native does this on URL (but do not on MSHTML:! why? */
1004 V_VT(&url
) = VT_BSTR
;
1005 V_BSTR(&url
) = SysAllocString( lpszName
);
1007 hRes
= IWebBrowser2_Navigate2( browser
, &url
, NULL
, NULL
, NULL
, NULL
);
1008 if ( FAILED( hRes
) )
1009 WARN( "IWebBrowser2::Navigate2 failed: %08x\n", hRes
);
1010 SysFreeString( V_BSTR(&url
) );
1012 IWebBrowser2_Release( browser
);
1018 *ppUnkContainer
= pContainer
;
1020 IUnknown_AddRef( pContainer
);
1024 *ppUnkControl
= pUnkControl
;
1026 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
);