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 IOleClientSite IOleClientSite_iface
;
45 IOleContainer IOleContainer_iface
;
46 IOleInPlaceSiteWindowless IOleInPlaceSiteWindowless_iface
;
47 IOleInPlaceFrame IOleInPlaceFrame_iface
;
48 IOleControlSite IOleControlSite_iface
;
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 [atl100.@]
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 AtlAxWin100
[] = {'A','t','l','A','x','W','i','n','1','0','0',0};
90 const WCHAR AtlAxWinLic100
[] = {'A','t','l','A','x','W','i','n','L','i','c','1','0','0',0};
94 if ( FAILED( OleInitialize(NULL
) ) )
97 wcex
.cbSize
= sizeof(wcex
);
98 wcex
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
101 wcex
.hInstance
= GetModuleHandleW( NULL
);
104 wcex
.hbrBackground
= NULL
;
105 wcex
.lpszMenuName
= NULL
;
108 wcex
.lpfnWndProc
= AtlAxWin_wndproc
;
109 wcex
.lpszClassName
= AtlAxWin100
;
110 if ( !RegisterClassExW( &wcex
) )
113 wcex
.lpszClassName
= AtlAxWinLic100
;
114 if ( !RegisterClassExW( &wcex
) )
120 /***********************************************************************
121 * Atl container component implementation
125 static ULONG
IOCS_AddRef(IOCS
*This
)
127 ULONG ref
= InterlockedIncrement(&This
->ref
);
129 TRACE( "(%p) : AddRef from %d\n", This
, ref
- 1 );
134 static HRESULT
IOCS_QueryInterface(IOCS
*This
, REFIID riid
, void **ppv
)
138 if ( IsEqualIID( &IID_IUnknown
, riid
)
139 || IsEqualIID( &IID_IOleClientSite
, riid
) )
141 *ppv
= &This
->IOleClientSite_iface
;
142 } else if ( IsEqualIID( &IID_IOleContainer
, riid
) )
144 *ppv
= &This
->IOleContainer_iface
;
145 } else if ( IsEqualIID( &IID_IOleInPlaceSite
, riid
) || IsEqualIID( &IID_IOleInPlaceSiteEx
, riid
) || IsEqualIID( &IID_IOleInPlaceSiteWindowless
, riid
) )
147 *ppv
= &This
->IOleInPlaceSiteWindowless_iface
;
148 } else if ( IsEqualIID( &IID_IOleInPlaceFrame
, riid
) )
150 *ppv
= &This
->IOleInPlaceFrame_iface
;
151 } else if ( IsEqualIID( &IID_IOleControlSite
, riid
) )
153 *ppv
= &This
->IOleControlSite_iface
;
162 WARN("unsupported interface %s\n", debugstr_guid( riid
) );
164 return E_NOINTERFACE
;
167 static HRESULT
IOCS_Detach( IOCS
*This
);
168 static ULONG
IOCS_Release(IOCS
*This
)
170 ULONG ref
= InterlockedDecrement(&This
->ref
);
172 TRACE( "(%p) : ReleaseRef to %d\n", This
, ref
);
177 HeapFree( GetProcessHeap(), 0, This
);
183 /****** IOleClientSite *****/
184 static inline IOCS
*impl_from_IOleClientSite(IOleClientSite
*iface
)
186 return CONTAINING_RECORD(iface
, IOCS
, IOleClientSite_iface
);
189 static HRESULT WINAPI
OleClientSite_QueryInterface(IOleClientSite
*iface
, REFIID riid
, void **ppv
)
191 IOCS
*This
= impl_from_IOleClientSite(iface
);
192 return IOCS_QueryInterface(This
, riid
, ppv
);
195 static ULONG WINAPI
OleClientSite_AddRef(IOleClientSite
*iface
)
197 IOCS
*This
= impl_from_IOleClientSite(iface
);
198 return IOCS_AddRef(This
);
201 static ULONG WINAPI
OleClientSite_Release(IOleClientSite
*iface
)
203 IOCS
*This
= impl_from_IOleClientSite(iface
);
204 return IOCS_Release(This
);
207 static HRESULT WINAPI
OleClientSite_SaveObject(IOleClientSite
*iface
)
209 IOCS
*This
= impl_from_IOleClientSite(iface
);
210 FIXME( "(%p) - stub\n", This
);
214 static HRESULT WINAPI
OleClientSite_GetMoniker(IOleClientSite
*iface
, DWORD dwAssign
, DWORD dwWhichMoniker
, IMoniker
**ppmk
)
216 IOCS
*This
= impl_from_IOleClientSite(iface
);
218 FIXME( "(%p, 0x%x, 0x%x, %p)\n", This
, dwAssign
, dwWhichMoniker
, ppmk
);
222 static HRESULT WINAPI
OleClientSite_GetContainer(IOleClientSite
*iface
, IOleContainer
**ppContainer
)
224 IOCS
*This
= impl_from_IOleClientSite(iface
);
225 TRACE( "(%p, %p)\n", This
, ppContainer
);
226 return OleClientSite_QueryInterface( iface
, &IID_IOleContainer
, (void**)ppContainer
);
229 static HRESULT WINAPI
OleClientSite_ShowObject(IOleClientSite
*iface
)
231 IOCS
*This
= impl_from_IOleClientSite(iface
);
232 FIXME( "(%p) - stub\n", This
);
236 static HRESULT WINAPI
OleClientSite_OnShowWindow(IOleClientSite
*iface
, BOOL fShow
)
238 IOCS
*This
= impl_from_IOleClientSite(iface
);
239 FIXME( "(%p, %s) - stub\n", This
, fShow
? "TRUE" : "FALSE" );
243 static HRESULT WINAPI
OleClientSite_RequestNewObjectLayout(IOleClientSite
*iface
)
245 IOCS
*This
= impl_from_IOleClientSite(iface
);
246 FIXME( "(%p) - stub\n", This
);
251 /****** IOleContainer *****/
252 static inline IOCS
*impl_from_IOleContainer(IOleContainer
*iface
)
254 return CONTAINING_RECORD(iface
, IOCS
, IOleContainer_iface
);
257 static HRESULT WINAPI
OleContainer_QueryInterface( IOleContainer
* iface
, REFIID riid
, void** ppv
)
259 IOCS
*This
= impl_from_IOleContainer(iface
);
260 return IOCS_QueryInterface( This
, riid
, ppv
);
263 static ULONG WINAPI
OleContainer_AddRef(IOleContainer
* iface
)
265 IOCS
*This
= impl_from_IOleContainer(iface
);
266 return IOCS_AddRef(This
);
269 static ULONG WINAPI
OleContainer_Release(IOleContainer
* iface
)
271 IOCS
*This
= impl_from_IOleContainer(iface
);
272 return IOCS_Release(This
);
275 static HRESULT WINAPI
OleContainer_ParseDisplayName(IOleContainer
* iface
, IBindCtx
* pbc
,
276 LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
)
278 IOCS
*This
= impl_from_IOleContainer(iface
);
279 FIXME( "(%p,%p,%s,%p,%p) - stub\n", This
, pbc
, debugstr_w(pszDisplayName
), pchEaten
, ppmkOut
);
283 static HRESULT WINAPI
OleContainer_EnumObjects(IOleContainer
* iface
, DWORD grfFlags
, IEnumUnknown
** ppenum
)
285 IOCS
*This
= impl_from_IOleContainer(iface
);
286 FIXME( "(%p, %u, %p) - stub\n", This
, grfFlags
, ppenum
);
290 static HRESULT WINAPI
OleContainer_LockContainer(IOleContainer
* iface
, BOOL fLock
)
292 IOCS
*This
= impl_from_IOleContainer(iface
);
293 FIXME( "(%p, %s) - stub\n", This
, fLock
?"TRUE":"FALSE" );
298 /****** IOleInPlaceSiteWindowless *******/
299 static inline IOCS
*impl_from_IOleInPlaceSiteWindowless(IOleInPlaceSiteWindowless
*iface
)
301 return CONTAINING_RECORD(iface
, IOCS
, IOleInPlaceSiteWindowless_iface
);
304 static HRESULT WINAPI
OleInPlaceSiteWindowless_QueryInterface(IOleInPlaceSiteWindowless
*iface
, REFIID riid
, void **ppv
)
306 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
307 return IOCS_QueryInterface(This
, riid
, ppv
);
310 static ULONG WINAPI
OleInPlaceSiteWindowless_AddRef(IOleInPlaceSiteWindowless
*iface
)
312 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
313 return IOCS_AddRef(This
);
316 static ULONG WINAPI
OleInPlaceSiteWindowless_Release(IOleInPlaceSiteWindowless
*iface
)
318 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
319 return IOCS_Release(This
);
322 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetWindow(IOleInPlaceSiteWindowless
* iface
, HWND
* phwnd
)
324 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
326 TRACE("(%p,%p)\n", This
, phwnd
);
331 static HRESULT WINAPI
OleInPlaceSiteWindowless_ContextSensitiveHelp(IOleInPlaceSiteWindowless
* iface
, BOOL fEnterMode
)
333 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
334 FIXME("(%p,%d) - stub\n", This
, fEnterMode
);
338 static HRESULT WINAPI
OleInPlaceSiteWindowless_CanInPlaceActivate(IOleInPlaceSiteWindowless
*iface
)
340 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
341 TRACE("(%p)\n", This
);
345 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceActivate(IOleInPlaceSiteWindowless
*iface
)
347 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
349 TRACE("(%p)\n", This
);
351 This
->fInPlace
= TRUE
;
355 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnUIActivate(IOleInPlaceSiteWindowless
*iface
)
357 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
359 TRACE("(%p)\n", This
);
363 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetWindowContext(IOleInPlaceSiteWindowless
*iface
,
364 IOleInPlaceFrame
**ppFrame
, IOleInPlaceUIWindow
**ppDoc
, LPRECT lprcPosRect
,
365 LPRECT lprcClipRect
, LPOLEINPLACEFRAMEINFO lpFrameInfo
)
367 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
369 TRACE("(%p,%p,%p,%p,%p,%p)\n", This
, ppFrame
, ppDoc
, lprcPosRect
, lprcClipRect
, lpFrameInfo
);
372 *lprcClipRect
= This
->size
;
374 *lprcPosRect
= This
->size
;
378 IOCS_QueryInterface( This
, &IID_IOleInPlaceFrame
, (void**) ppFrame
);
386 lpFrameInfo
->fMDIApp
= FALSE
;
387 lpFrameInfo
->hwndFrame
= This
->hWnd
;
388 lpFrameInfo
->haccel
= NULL
;
389 lpFrameInfo
->cAccelEntries
= 0;
395 static HRESULT WINAPI
OleInPlaceSiteWindowless_Scroll(IOleInPlaceSiteWindowless
*iface
, SIZE scrollExtent
)
397 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
398 FIXME("(%p) - stub\n", This
);
402 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnUIDeactivate(IOleInPlaceSiteWindowless
*iface
, BOOL fUndoable
)
404 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
405 FIXME("(%p,%d) - stub\n", This
, fUndoable
);
409 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceDeactivate(IOleInPlaceSiteWindowless
*iface
)
411 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
413 TRACE("(%p)\n", This
);
415 This
->fInPlace
= This
->fWindowless
= FALSE
;
419 static HRESULT WINAPI
OleInPlaceSiteWindowless_DiscardUndoState(IOleInPlaceSiteWindowless
*iface
)
421 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
422 FIXME("(%p) - stub\n", This
);
426 static HRESULT WINAPI
OleInPlaceSiteWindowless_DeactivateAndUndo(IOleInPlaceSiteWindowless
*iface
)
428 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
429 FIXME("(%p) - stub\n", This
);
433 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnPosRectChange(IOleInPlaceSiteWindowless
*iface
, LPCRECT lprcPosRect
)
435 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
436 FIXME("(%p,%p) - stub\n", This
, lprcPosRect
);
440 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceActivateEx( IOleInPlaceSiteWindowless
*iface
, BOOL
* pfNoRedraw
, DWORD dwFlags
)
442 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
446 This
->fActive
= This
->fInPlace
= TRUE
;
447 if ( dwFlags
& ACTIVATE_WINDOWLESS
)
448 This
->fWindowless
= TRUE
;
452 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceDeactivateEx( IOleInPlaceSiteWindowless
*iface
, BOOL fNoRedraw
)
454 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
458 This
->fActive
= This
->fInPlace
= This
->fWindowless
= FALSE
;
461 static HRESULT WINAPI
OleInPlaceSiteWindowless_RequestUIActivate( IOleInPlaceSiteWindowless
*iface
)
466 static HRESULT WINAPI
OleInPlaceSiteWindowless_CanWindowlessActivate( IOleInPlaceSiteWindowless
*iface
)
471 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetCapture( IOleInPlaceSiteWindowless
*iface
)
476 static HRESULT WINAPI
OleInPlaceSiteWindowless_SetCapture( IOleInPlaceSiteWindowless
*iface
, BOOL fCapture
)
481 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetFocus( IOleInPlaceSiteWindowless
*iface
)
486 static HRESULT WINAPI
OleInPlaceSiteWindowless_SetFocus( IOleInPlaceSiteWindowless
*iface
, BOOL fFocus
)
491 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetDC( IOleInPlaceSiteWindowless
*iface
, LPCRECT pRect
, DWORD grfFlags
, HDC
* phDC
)
496 static HRESULT WINAPI
OleInPlaceSiteWindowless_ReleaseDC( IOleInPlaceSiteWindowless
*iface
, HDC hDC
)
501 static HRESULT WINAPI
OleInPlaceSiteWindowless_InvalidateRect( IOleInPlaceSiteWindowless
*iface
, LPCRECT pRect
, BOOL fErase
)
506 static HRESULT WINAPI
OleInPlaceSiteWindowless_InvalidateRgn( IOleInPlaceSiteWindowless
*iface
, HRGN hRGN
, BOOL fErase
)
511 static HRESULT WINAPI
OleInPlaceSiteWindowless_ScrollRect( IOleInPlaceSiteWindowless
*iface
, INT dx
, INT dy
, LPCRECT pRectScroll
, LPCRECT pRectClip
)
516 static HRESULT WINAPI
OleInPlaceSiteWindowless_AdjustRect( IOleInPlaceSiteWindowless
*iface
, LPRECT prc
)
521 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnDefWindowMessage( IOleInPlaceSiteWindowless
*iface
, UINT msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
* plResult
)
528 /****** IOleInPlaceFrame *******/
529 static inline IOCS
*impl_from_IOleInPlaceFrame(IOleInPlaceFrame
*iface
)
531 return CONTAINING_RECORD(iface
, IOCS
, IOleInPlaceFrame_iface
);
534 static HRESULT WINAPI
OleInPlaceFrame_QueryInterface(IOleInPlaceFrame
*iface
, REFIID riid
, void **ppv
)
536 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
537 return IOCS_QueryInterface(This
, riid
, ppv
);
540 static ULONG WINAPI
OleInPlaceFrame_AddRef(IOleInPlaceFrame
*iface
)
542 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
543 return IOCS_AddRef(This
);
546 static ULONG WINAPI
OleInPlaceFrame_Release(IOleInPlaceFrame
*iface
)
548 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
549 return IOCS_Release(This
);
552 static HRESULT WINAPI
OleInPlaceFrame_GetWindow(IOleInPlaceFrame
*iface
, HWND
*phWnd
)
554 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
556 TRACE( "(%p,%p)\n", This
, phWnd
);
562 static HRESULT WINAPI
OleInPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame
*iface
, BOOL fEnterMode
)
564 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
566 FIXME( "(%p,%d) - stub\n", This
, fEnterMode
);
570 static HRESULT WINAPI
OleInPlaceFrame_GetBorder(IOleInPlaceFrame
*iface
, LPRECT lprectBorder
)
572 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
574 FIXME( "(%p,%p) - stub\n", This
, lprectBorder
);
578 static HRESULT WINAPI
OleInPlaceFrame_RequestBorderSpace(IOleInPlaceFrame
*iface
, LPCBORDERWIDTHS pborderwidths
)
580 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
582 FIXME( "(%p,%p) - stub\n", This
, pborderwidths
);
586 static HRESULT WINAPI
OleInPlaceFrame_SetBorderSpace(IOleInPlaceFrame
*iface
, LPCBORDERWIDTHS pborderwidths
)
588 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
590 FIXME( "(%p,%p) - stub\n", This
, pborderwidths
);
594 static HRESULT WINAPI
OleInPlaceFrame_SetActiveObject(IOleInPlaceFrame
*iface
, IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR pszObjName
)
596 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
598 FIXME( "(%p,%p,%s) - stub\n", This
, pActiveObject
, debugstr_w(pszObjName
) );
602 static HRESULT WINAPI
OleInPlaceFrame_InsertMenus(IOleInPlaceFrame
*iface
, HMENU hmenuShared
, LPOLEMENUGROUPWIDTHS lpMenuWidths
)
604 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
606 FIXME( "(%p,%p,%p) - stub\n", This
, hmenuShared
, lpMenuWidths
);
610 static HRESULT WINAPI
OleInPlaceFrame_SetMenu(IOleInPlaceFrame
*iface
, HMENU hmenuShared
, HOLEMENU holemenu
, HWND hwndActiveObject
)
612 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
614 FIXME( "(%p,%p,%p,%p) - stub\n", This
, hmenuShared
, holemenu
, hwndActiveObject
);
618 static HRESULT WINAPI
OleInPlaceFrame_RemoveMenus(IOleInPlaceFrame
*iface
, HMENU hmenuShared
)
620 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
622 FIXME( "(%p, %p) - stub\n", This
, hmenuShared
);
626 static HRESULT WINAPI
OleInPlaceFrame_SetStatusText(IOleInPlaceFrame
*iface
, LPCOLESTR pszStatusText
)
628 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
630 FIXME( "(%p, %s) - stub\n", This
, debugstr_w( pszStatusText
) );
634 static HRESULT WINAPI
OleInPlaceFrame_EnableModeless(IOleInPlaceFrame
*iface
, BOOL fEnable
)
636 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
638 FIXME( "(%p, %d) - stub\n", This
, fEnable
);
642 static HRESULT WINAPI
OleInPlaceFrame_TranslateAccelerator(IOleInPlaceFrame
*iface
, LPMSG lpmsg
, WORD wID
)
644 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
646 FIXME( "(%p, %p, %x) - stub\n", This
, lpmsg
, wID
);
651 /****** IOleControlSite *******/
652 static inline IOCS
*impl_from_IOleControlSite(IOleControlSite
*iface
)
654 return CONTAINING_RECORD(iface
, IOCS
, IOleControlSite_iface
);
657 static HRESULT WINAPI
OleControlSite_QueryInterface(IOleControlSite
*iface
, REFIID riid
, void **ppv
)
659 IOCS
*This
= impl_from_IOleControlSite(iface
);
660 return IOCS_QueryInterface(This
, riid
, ppv
);
663 static ULONG WINAPI
OleControlSite_AddRef(IOleControlSite
*iface
)
665 IOCS
*This
= impl_from_IOleControlSite(iface
);
666 return IOCS_AddRef(This
);
669 static ULONG WINAPI
OleControlSite_Release(IOleControlSite
*iface
)
671 IOCS
*This
= impl_from_IOleControlSite(iface
);
672 return IOCS_Release(This
);
675 static HRESULT WINAPI
OleControlSite_OnControlInfoChanged( IOleControlSite
* This
)
680 static HRESULT WINAPI
OleControlSite_LockInPlaceActive( IOleControlSite
* This
, BOOL fLock
)
685 static HRESULT WINAPI
OleControlSite_GetExtendedControl( IOleControlSite
* This
, IDispatch
** ppDisp
)
690 static HRESULT WINAPI
OleControlSite_TransformCoords( IOleControlSite
* This
, POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD dwFlags
)
695 static HRESULT WINAPI
OleControlSite_TranslateAccelerator( IOleControlSite
* This
, MSG
* pMsg
, DWORD grfModifiers
)
700 static HRESULT WINAPI
OleControlSite_OnFocus( IOleControlSite
* This
, BOOL fGotFocus
)
705 static HRESULT WINAPI
OleControlSite_ShowPropertyFrame( IOleControlSite
* This
)
712 static const IOleClientSiteVtbl OleClientSite_vtbl
= {
713 OleClientSite_QueryInterface
,
714 OleClientSite_AddRef
,
715 OleClientSite_Release
,
716 OleClientSite_SaveObject
,
717 OleClientSite_GetMoniker
,
718 OleClientSite_GetContainer
,
719 OleClientSite_ShowObject
,
720 OleClientSite_OnShowWindow
,
721 OleClientSite_RequestNewObjectLayout
723 static const IOleContainerVtbl OleContainer_vtbl
= {
724 OleContainer_QueryInterface
,
726 OleContainer_Release
,
727 OleContainer_ParseDisplayName
,
728 OleContainer_EnumObjects
,
729 OleContainer_LockContainer
731 static const IOleInPlaceSiteWindowlessVtbl OleInPlaceSiteWindowless_vtbl
= {
732 OleInPlaceSiteWindowless_QueryInterface
,
733 OleInPlaceSiteWindowless_AddRef
,
734 OleInPlaceSiteWindowless_Release
,
735 OleInPlaceSiteWindowless_GetWindow
,
736 OleInPlaceSiteWindowless_ContextSensitiveHelp
,
737 OleInPlaceSiteWindowless_CanInPlaceActivate
,
738 OleInPlaceSiteWindowless_OnInPlaceActivate
,
739 OleInPlaceSiteWindowless_OnUIActivate
,
740 OleInPlaceSiteWindowless_GetWindowContext
,
741 OleInPlaceSiteWindowless_Scroll
,
742 OleInPlaceSiteWindowless_OnUIDeactivate
,
743 OleInPlaceSiteWindowless_OnInPlaceDeactivate
,
744 OleInPlaceSiteWindowless_DiscardUndoState
,
745 OleInPlaceSiteWindowless_DeactivateAndUndo
,
746 OleInPlaceSiteWindowless_OnPosRectChange
,
747 OleInPlaceSiteWindowless_OnInPlaceActivateEx
,
748 OleInPlaceSiteWindowless_OnInPlaceDeactivateEx
,
749 OleInPlaceSiteWindowless_RequestUIActivate
,
750 OleInPlaceSiteWindowless_CanWindowlessActivate
,
751 OleInPlaceSiteWindowless_GetCapture
,
752 OleInPlaceSiteWindowless_SetCapture
,
753 OleInPlaceSiteWindowless_GetFocus
,
754 OleInPlaceSiteWindowless_SetFocus
,
755 OleInPlaceSiteWindowless_GetDC
,
756 OleInPlaceSiteWindowless_ReleaseDC
,
757 OleInPlaceSiteWindowless_InvalidateRect
,
758 OleInPlaceSiteWindowless_InvalidateRgn
,
759 OleInPlaceSiteWindowless_ScrollRect
,
760 OleInPlaceSiteWindowless_AdjustRect
,
761 OleInPlaceSiteWindowless_OnDefWindowMessage
763 static const IOleInPlaceFrameVtbl OleInPlaceFrame_vtbl
=
765 OleInPlaceFrame_QueryInterface
,
766 OleInPlaceFrame_AddRef
,
767 OleInPlaceFrame_Release
,
768 OleInPlaceFrame_GetWindow
,
769 OleInPlaceFrame_ContextSensitiveHelp
,
770 OleInPlaceFrame_GetBorder
,
771 OleInPlaceFrame_RequestBorderSpace
,
772 OleInPlaceFrame_SetBorderSpace
,
773 OleInPlaceFrame_SetActiveObject
,
774 OleInPlaceFrame_InsertMenus
,
775 OleInPlaceFrame_SetMenu
,
776 OleInPlaceFrame_RemoveMenus
,
777 OleInPlaceFrame_SetStatusText
,
778 OleInPlaceFrame_EnableModeless
,
779 OleInPlaceFrame_TranslateAccelerator
781 static const IOleControlSiteVtbl OleControlSite_vtbl
=
783 OleControlSite_QueryInterface
,
784 OleControlSite_AddRef
,
785 OleControlSite_Release
,
786 OleControlSite_OnControlInfoChanged
,
787 OleControlSite_LockInPlaceActive
,
788 OleControlSite_GetExtendedControl
,
789 OleControlSite_TransformCoords
,
790 OleControlSite_TranslateAccelerator
,
791 OleControlSite_OnFocus
,
792 OleControlSite_ShowPropertyFrame
795 static HRESULT
IOCS_Detach( IOCS
*This
) /* remove subclassing */
799 SetWindowLongPtrW( This
->hWnd
, GWLP_WNDPROC
, (ULONG_PTR
) This
->OrigWndProc
);
800 SetWindowLongPtrW( This
->hWnd
, GWLP_USERDATA
, 0 );
805 IOleObject
*control
= This
->control
;
807 This
->control
= NULL
;
808 IOleObject_Close( control
, OLECLOSE_NOSAVE
);
809 IOleObject_SetClientSite( control
, NULL
);
810 IOleObject_Release( control
);
815 static void IOCS_OnSize( IOCS
* This
, LPCRECT rect
)
819 This
->size
.left
= rect
->left
; This
->size
.right
= rect
->right
; This
->size
.top
= rect
->top
; This
->size
.bottom
= rect
->bottom
;
821 if ( !This
->control
)
824 inPix
.cx
= rect
->right
- rect
->left
;
825 inPix
.cy
= rect
->bottom
- rect
->top
;
826 AtlPixelToHiMetric( &inPix
, &inHi
);
827 IOleObject_SetExtent( This
->control
, DVASPECT_CONTENT
, &inHi
);
829 if ( This
->fInPlace
)
831 IOleInPlaceObject
*wl
;
833 if ( SUCCEEDED( IOleObject_QueryInterface( This
->control
, &IID_IOleInPlaceObject
, (void**)&wl
) ) )
835 IOleInPlaceObject_SetObjectRects( wl
, rect
, rect
);
836 IOleInPlaceObject_Release( wl
);
841 static void IOCS_OnShow( IOCS
*This
, BOOL fShow
)
843 if (!This
->control
|| This
->fActive
|| !fShow
)
846 This
->fActive
= TRUE
;
849 static void IOCS_OnDraw( IOCS
*This
)
853 if ( !This
->control
|| !This
->fWindowless
)
856 if ( SUCCEEDED( IOleObject_QueryInterface( This
->control
, &IID_IViewObject
, (void**)&view
) ) )
858 HDC dc
= GetDC( This
->hWnd
);
861 rect
.left
= This
->size
.left
; rect
.top
= This
->size
.top
;
862 rect
.bottom
= This
->size
.bottom
; rect
.right
= This
->size
.right
;
864 IViewObject_Draw( view
, DVASPECT_CONTENT
, ~0, NULL
, NULL
, 0, dc
, &rect
, &rect
, NULL
, 0 );
865 IViewObject_Release( view
);
866 ReleaseDC( This
->hWnd
, dc
);
870 static LRESULT
IOCS_OnWndProc( IOCS
*This
, HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
872 WNDPROC OrigWndProc
= This
->OrigWndProc
;
883 r
.right
= LOWORD( lParam
);
884 r
.bottom
= HIWORD( lParam
);
885 IOCS_OnSize( This
, &r
);
889 IOCS_OnShow( This
, (BOOL
) wParam
);
896 return CallWindowProcW( OrigWndProc
, hWnd
, uMsg
, wParam
, lParam
);
899 static LRESULT CALLBACK
AtlHost_wndproc( HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
901 IOCS
*This
= (IOCS
*) GetWindowLongPtrW( hWnd
, GWLP_USERDATA
);
902 return IOCS_OnWndProc( This
, hWnd
, wMsg
, wParam
, lParam
);
905 static HRESULT
IOCS_Attach( IOCS
*This
, HWND hWnd
, IUnknown
*pUnkControl
) /* subclass hWnd */
908 IUnknown_QueryInterface( pUnkControl
, &IID_IOleObject
, (void**)&This
->control
);
909 IOleObject_SetClientSite( This
->control
, &This
->IOleClientSite_iface
);
910 SetWindowLongPtrW( hWnd
, GWLP_USERDATA
, (ULONG_PTR
) This
);
911 This
->OrigWndProc
= (WNDPROC
)SetWindowLongPtrW( hWnd
, GWLP_WNDPROC
, (ULONG_PTR
) AtlHost_wndproc
);
916 static HRESULT
IOCS_Init( IOCS
*This
)
919 static const WCHAR AXWIN
[] = {'A','X','W','I','N',0};
921 IOleObject_SetHostNames( This
->control
, AXWIN
, AXWIN
);
923 GetClientRect( This
->hWnd
, &rect
);
924 IOCS_OnSize( This
, &rect
);
925 IOleObject_DoVerb( This
->control
, OLEIVERB_INPLACEACTIVATE
, NULL
, &This
->IOleClientSite_iface
,
926 0, This
->hWnd
, &rect
);
931 /**********************************************************************
932 * Create new instance of Atl host component and attach it to window *
934 static HRESULT
IOCS_Create( HWND hWnd
, IUnknown
*pUnkControl
, IOCS
**ppSite
)
940 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(IOCS
));
943 return E_OUTOFMEMORY
;
945 This
->IOleClientSite_iface
.lpVtbl
= &OleClientSite_vtbl
;
946 This
->IOleContainer_iface
.lpVtbl
= &OleContainer_vtbl
;
947 This
->IOleInPlaceSiteWindowless_iface
.lpVtbl
= &OleInPlaceSiteWindowless_vtbl
;
948 This
->IOleInPlaceFrame_iface
.lpVtbl
= &OleInPlaceFrame_vtbl
;
949 This
->IOleControlSite_iface
.lpVtbl
= &OleControlSite_vtbl
;
952 This
->OrigWndProc
= NULL
;
954 This
->fWindowless
= This
->fActive
= This
->fInPlace
= FALSE
;
956 hr
= IOCS_Attach( This
, hWnd
, pUnkControl
);
957 if ( SUCCEEDED( hr
) )
958 hr
= IOCS_Init( This
);
959 if ( SUCCEEDED( hr
) )
962 IOCS_Release( This
);
968 /***********************************************************************
969 * AtlAxCreateControl [atl100.@]
971 HRESULT WINAPI
AtlAxCreateControl(LPCOLESTR lpszName
, HWND hWnd
,
972 IStream
*pStream
, IUnknown
**ppUnkContainer
)
974 return AtlAxCreateControlEx( lpszName
, hWnd
, pStream
, ppUnkContainer
,
978 /***********************************************************************
979 * AtlAxCreateControlEx [atl100.@]
982 * See http://www.codeproject.com/com/cwebpage.asp for some background
985 HRESULT WINAPI
AtlAxCreateControlEx(LPCOLESTR lpszName
, HWND hWnd
,
986 IStream
*pStream
, IUnknown
**ppUnkContainer
, IUnknown
**ppUnkControl
,
987 REFIID iidSink
, IUnknown
*punkSink
)
991 IOleObject
*pControl
;
992 IUnknown
*pUnkControl
;
993 IPersistStreamInit
*pPSInit
;
994 IUnknown
*pContainer
;
995 enum {IsGUID
=0,IsHTML
=1,IsURL
=2} content
;
997 TRACE("(%s %p %p %p %p %p %p)\n", debugstr_w(lpszName
), hWnd
, pStream
,
998 ppUnkContainer
, ppUnkControl
, iidSink
, punkSink
);
1000 hRes
= CLSIDFromString( lpszName
, &controlId
);
1002 hRes
= CLSIDFromProgID( lpszName
, &controlId
);
1003 if ( SUCCEEDED( hRes
) )
1006 /* FIXME - check for MSHTML: prefix! */
1008 controlId
= CLSID_WebBrowser
;
1011 hRes
= CoCreateInstance( &controlId
, 0, CLSCTX_ALL
, &IID_IOleObject
,
1012 (void**) &pControl
);
1013 if ( FAILED( hRes
) )
1015 WARN( "cannot create ActiveX control %s instance - error 0x%08x\n",
1016 debugstr_guid( &controlId
), hRes
);
1020 hRes
= IOleObject_QueryInterface( pControl
, &IID_IPersistStreamInit
, (void**) &pPSInit
);
1021 if ( SUCCEEDED( hRes
) )
1024 IPersistStreamInit_InitNew( pPSInit
);
1026 IPersistStreamInit_Load( pPSInit
, pStream
);
1027 IPersistStreamInit_Release( pPSInit
);
1029 WARN("cannot get IID_IPersistStreamInit out of control\n");
1031 IOleObject_QueryInterface( pControl
, &IID_IUnknown
, (void**) &pUnkControl
);
1032 IOleObject_Release( pControl
);
1035 hRes
= AtlAxAttachControl( pUnkControl
, hWnd
, &pContainer
);
1036 if ( FAILED( hRes
) )
1037 WARN("cannot attach control to window\n");
1039 if ( content
== IsURL
)
1041 IWebBrowser2
*browser
;
1043 hRes
= IOleObject_QueryInterface( pControl
, &IID_IWebBrowser2
, (void**) &browser
);
1045 WARN( "Cannot query IWebBrowser2 interface: %08x\n", hRes
);
1049 IWebBrowser2_put_Visible( browser
, VARIANT_TRUE
); /* it seems that native does this on URL (but do not on MSHTML:! why? */
1051 V_VT(&url
) = VT_BSTR
;
1052 V_BSTR(&url
) = SysAllocString( lpszName
);
1054 hRes
= IWebBrowser2_Navigate2( browser
, &url
, NULL
, NULL
, NULL
, NULL
);
1055 if ( FAILED( hRes
) )
1056 WARN( "IWebBrowser2::Navigate2 failed: %08x\n", hRes
);
1057 SysFreeString( V_BSTR(&url
) );
1059 IWebBrowser2_Release( browser
);
1065 *ppUnkContainer
= pContainer
;
1067 IUnknown_AddRef( pContainer
);
1071 *ppUnkControl
= pUnkControl
;
1073 IUnknown_AddRef( pUnkControl
);
1077 IUnknown_Release( pUnkControl
);
1079 IUnknown_Release( pContainer
);
1084 /***********************************************************************
1085 * AtlAxAttachControl [atl100.@]
1087 HRESULT WINAPI
AtlAxAttachControl(IUnknown
* pControl
, HWND hWnd
, IUnknown
** ppUnkContainer
)
1089 IOCS
*pUnkContainer
;
1092 TRACE( "%p %p %p\n", pControl
, hWnd
, ppUnkContainer
);
1095 return E_INVALIDARG
;
1097 hr
= IOCS_Create( hWnd
, pControl
, &pUnkContainer
);
1098 if ( SUCCEEDED( hr
) && ppUnkContainer
)
1100 *ppUnkContainer
= (IUnknown
*) pUnkContainer
;
1109 /**********************************************************************
1110 * Helper function for AX_ConvertDialogTemplate
1112 static inline BOOL
advance_array(WORD
**pptr
, DWORD
*palloc
, DWORD
*pfilled
, const WORD
*data
, DWORD size
)
1114 if ( (*pfilled
+ size
) > *palloc
)
1116 *palloc
= ((*pfilled
+size
) + 0xFF) & ~0xFF;
1117 *pptr
= HeapReAlloc( GetProcessHeap(), 0, *pptr
, *palloc
* sizeof(WORD
) );
1121 RtlMoveMemory( *pptr
+*pfilled
, data
, size
* sizeof(WORD
) );
1126 /**********************************************************************
1127 * Convert ActiveX control templates to AtlAxWin class instances
1129 static LPDLGTEMPLATEW
AX_ConvertDialogTemplate(LPCDLGTEMPLATEW src_tmpl
)
1131 #define GET_WORD(x) (*(const WORD *)(x))
1132 #define GET_DWORD(x) (*(const DWORD *)(x))
1133 #define PUT_BLOCK(x,y) do {if (!advance_array(&output, &allocated, &filled, (x), (y))) return NULL;} while (0)
1134 #define PUT_WORD(x) do {WORD w = (x);PUT_BLOCK(&w, 1);} while(0)
1135 #define PUT_DWORD(x) do {DWORD w = (x);PUT_BLOCK(&w, 2);} while(0)
1136 const WORD
*tmp
, *src
= (const WORD
*)src_tmpl
;
1138 DWORD allocated
, filled
; /* in WORDs */
1140 WORD signature
, dlgver
, rescount
;
1143 filled
= 0; allocated
= 256;
1144 output
= HeapAlloc( GetProcessHeap(), 0, allocated
* sizeof(WORD
) );
1150 signature
= GET_WORD(src
);
1151 dlgver
= GET_WORD(src
+ 1);
1152 if (signature
== 1 && dlgver
== 0xFFFF)
1156 style
= GET_DWORD(src
);
1158 rescount
= GET_WORD(src
++);
1160 if ( GET_WORD(src
) == 0xFFFF ) /* menu */
1163 src
+= strlenW(src
) + 1;
1164 if ( GET_WORD(src
) == 0xFFFF ) /* class */
1167 src
+= strlenW(src
) + 1;
1168 src
+= strlenW(src
) + 1; /* title */
1169 if ( style
& (DS_SETFONT
| DS_SHELLFONT
) )
1172 src
+= strlenW(src
) + 1;
1176 style
= GET_DWORD(src
);
1178 rescount
= GET_WORD(src
++);
1180 if ( GET_WORD(src
) == 0xFFFF ) /* menu */
1183 src
+= strlenW(src
) + 1;
1184 if ( GET_WORD(src
) == 0xFFFF ) /* class */
1187 src
+= strlenW(src
) + 1;
1188 src
+= strlenW(src
) + 1; /* title */
1189 if ( style
& DS_SETFONT
)
1192 src
+= strlenW(src
) + 1;
1195 PUT_BLOCK(tmp
, src
-tmp
);
1199 src
= (const WORD
*)( ( ((ULONG_PTR
)src
) + 3) & ~3); /* align on DWORD boundary */
1200 filled
= (filled
+ 1) & ~1; /* depends on DWORD-aligned allocation unit */
1207 PUT_BLOCK(tmp
, src
-tmp
);
1210 if ( GET_WORD(src
) == 0xFFFF ) /* class */
1215 src
+= strlenW(src
) + 1;
1217 src
+= strlenW(src
) + 1; /* title */
1218 if ( GET_WORD(tmp
) == '{' ) /* all this mess created because of this line */
1220 static const WCHAR AtlAxWin
[] = {'A','t','l','A','x','W','i','n', 0};
1221 PUT_BLOCK(AtlAxWin
, sizeof(AtlAxWin
)/sizeof(WCHAR
));
1222 PUT_BLOCK(tmp
, strlenW(tmp
)+1);
1224 PUT_BLOCK(tmp
, src
-tmp
);
1226 if ( GET_WORD(src
) )
1228 WORD size
= (GET_WORD(src
)+sizeof(WORD
)-1) / sizeof(WORD
); /* quite ugly :( Maybe use BYTE* instead of WORD* everywhere ? */
1229 PUT_BLOCK(src
, size
);
1238 return (LPDLGTEMPLATEW
) output
;
1241 /***********************************************************************
1242 * AtlAxCreateDialogA [atl100.@]
1244 * Creates a dialog window
1247 * hInst [I] Application instance
1248 * name [I] Dialog box template name
1249 * owner [I] Dialog box parent HWND
1250 * dlgProc [I] Dialog box procedure
1251 * param [I] This value will be passed to dlgProc as WM_INITDIALOG's message lParam
1254 * Window handle of dialog window.
1256 HWND WINAPI
AtlAxCreateDialogA(HINSTANCE hInst
, LPCSTR name
, HWND owner
, DLGPROC dlgProc
,LPARAM param
)
1262 if (IS_INTRESOURCE(name
))
1263 return AtlAxCreateDialogW( hInst
, (LPCWSTR
) name
, owner
, dlgProc
, param
);
1265 length
= MultiByteToWideChar( CP_ACP
, 0, name
, -1, NULL
, 0 );
1266 nameW
= HeapAlloc( GetProcessHeap(), 0, length
* sizeof(WCHAR
) );
1269 MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, length
);
1270 res
= AtlAxCreateDialogW( hInst
, nameW
, owner
, dlgProc
, param
);
1271 HeapFree( GetProcessHeap(), 0, nameW
);
1276 /***********************************************************************
1277 * AtlAxCreateDialogW [atl100.@]
1279 * See AtlAxCreateDialogA
1282 HWND WINAPI
AtlAxCreateDialogW(HINSTANCE hInst
, LPCWSTR name
, HWND owner
, DLGPROC dlgProc
,LPARAM param
)
1286 LPCDLGTEMPLATEW ptr
;
1287 LPDLGTEMPLATEW newptr
;
1290 TRACE("(%p %s %p %p %lx)\n", hInst
, debugstr_w(name
), owner
, dlgProc
, param
);
1292 hrsrc
= FindResourceW( hInst
, name
, (LPWSTR
)RT_DIALOG
);
1295 hgl
= LoadResource (hInst
, hrsrc
);
1298 ptr
= LockResource ( hgl
);
1301 FreeResource( hgl
);
1304 newptr
= AX_ConvertDialogTemplate( ptr
);
1307 res
= CreateDialogIndirectParamW( hInst
, newptr
, owner
, dlgProc
, param
);
1308 HeapFree( GetProcessHeap(), 0, newptr
);
1311 FreeResource ( hrsrc
);
1315 /***********************************************************************
1316 * AtlAxGetHost [atl100.@]
1319 HRESULT WINAPI
AtlAxGetHost(HWND hWnd
, IUnknown
**pUnk
)
1323 TRACE( "(%p, %p)\n", hWnd
, pUnk
);
1327 This
= (IOCS
*) GetWindowLongPtrW( hWnd
, GWLP_USERDATA
);
1330 WARN("No container attached to %p\n", hWnd
);
1334 return IOCS_QueryInterface( This
, &IID_IUnknown
, (void**) pUnk
);
1337 /***********************************************************************
1338 * AtlAxGetControl [atl100.@]
1341 HRESULT WINAPI
AtlAxGetControl(HWND hWnd
, IUnknown
**pUnk
)
1345 TRACE( "(%p, %p)\n", hWnd
, pUnk
);
1349 This
= (IOCS
*) GetWindowLongPtrW( hWnd
, GWLP_USERDATA
);
1350 if ( !This
|| !This
->control
)
1352 WARN("No control attached to %p\n", hWnd
);
1356 return IOleObject_QueryInterface( This
->control
, &IID_IUnknown
, (void**) pUnk
);
1359 /***********************************************************************
1360 * AtlAxDialogBoxW [atl100.35]
1363 INT_PTR WINAPI
AtlAxDialogBoxW(HINSTANCE hInstance
, LPCWSTR lpTemplateName
, HWND hWndParent
, DLGPROC lpDialogProc
,
1366 FIXME("(%p %s %p %p %lx)\n", hInstance
, debugstr_w(lpTemplateName
), hWndParent
, lpDialogProc
, dwInitParam
);
1370 /***********************************************************************
1371 * AtlAxDialogBoxA [atl100.36]
1374 INT_PTR WINAPI
AtlAxDialogBoxA(HINSTANCE hInstance
, LPCSTR lpTemplateName
, HWND hWndParent
, DLGPROC lpDialogProc
,
1377 FIXME("(%p %s %p %p %lx)\n", hInstance
, debugstr_a(lpTemplateName
), hWndParent
, lpDialogProc
, dwInitParam
);