2 * Active Template Library ActiveX functions (atl.dll)
4 * Copyright 2006 Andrey Turkin
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
32 //#include "winerror.h"
33 //#include "winuser.h"
34 #include <wine/debug.h>
35 //#include "objbase.h"
40 //#include "atliface.h"
43 #include <wine/unicode.h>
45 WINE_DEFAULT_DEBUG_CHANNEL(atl
);
48 IOleClientSite IOleClientSite_iface
;
49 IOleContainer IOleContainer_iface
;
50 IOleInPlaceSiteWindowless IOleInPlaceSiteWindowless_iface
;
51 IOleInPlaceFrame IOleInPlaceFrame_iface
;
52 IOleControlSite IOleControlSite_iface
;
59 BOOL fActive
, fInPlace
, fWindowless
;
62 /**********************************************************************
63 * AtlAxWin class window procedure
65 static LRESULT CALLBACK
AtlAxWin_wndproc( HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
67 if ( wMsg
== WM_CREATE
)
69 DWORD len
= GetWindowTextLengthW( hWnd
) + 1;
70 WCHAR
*ptr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
73 GetWindowTextW( hWnd
, ptr
, len
);
74 AtlAxCreateControlEx( ptr
, hWnd
, NULL
, NULL
, NULL
, NULL
, NULL
);
75 HeapFree( GetProcessHeap(), 0, ptr
);
78 return DefWindowProcW( hWnd
, wMsg
, wParam
, lParam
);
81 /***********************************************************************
82 * AtlAxWinInit [atl100.@]
83 * Initializes the control-hosting code: registering the AtlAxWin,
84 * AtlAxWin7 and AtlAxWinLic7 window classes and some messages.
90 BOOL WINAPI
AtlAxWinInit(void)
93 const WCHAR AtlAxWin
[] = {'A','t','l','A','x','W','i','n',0};
97 if ( FAILED( OleInitialize(NULL
) ) )
100 wcex
.cbSize
= sizeof(wcex
);
104 wcex
.hInstance
= GetModuleHandleW( NULL
);
107 wcex
.hbrBackground
= NULL
;
108 wcex
.lpszMenuName
= NULL
;
111 wcex
.lpfnWndProc
= AtlAxWin_wndproc
;
112 wcex
.lpszClassName
= AtlAxWin
;
113 if ( !RegisterClassExW( &wcex
) )
119 /***********************************************************************
120 * Atl container component implementation
124 static ULONG
IOCS_AddRef(IOCS
*This
)
126 ULONG ref
= InterlockedIncrement(&This
->ref
);
128 TRACE( "(%p) : AddRef from %d\n", This
, ref
- 1 );
133 static HRESULT
IOCS_QueryInterface(IOCS
*This
, REFIID riid
, void **ppv
)
137 if ( IsEqualIID( &IID_IUnknown
, riid
)
138 || IsEqualIID( &IID_IOleClientSite
, riid
) )
140 *ppv
= &This
->IOleClientSite_iface
;
141 } else if ( IsEqualIID( &IID_IOleContainer
, riid
) )
143 *ppv
= &This
->IOleContainer_iface
;
144 } else if ( IsEqualIID( &IID_IOleInPlaceSite
, riid
) || IsEqualIID( &IID_IOleInPlaceSiteEx
, riid
) || IsEqualIID( &IID_IOleInPlaceSiteWindowless
, riid
) )
146 *ppv
= &This
->IOleInPlaceSiteWindowless_iface
;
147 } else if ( IsEqualIID( &IID_IOleInPlaceFrame
, riid
) )
149 *ppv
= &This
->IOleInPlaceFrame_iface
;
150 } else if ( IsEqualIID( &IID_IOleControlSite
, riid
) )
152 *ppv
= &This
->IOleControlSite_iface
;
161 WARN("unsupported interface %s\n", debugstr_guid( riid
) );
163 return E_NOINTERFACE
;
166 static HRESULT
IOCS_Detach( IOCS
*This
);
167 static ULONG
IOCS_Release(IOCS
*This
)
169 ULONG ref
= InterlockedDecrement(&This
->ref
);
171 TRACE( "(%p) : ReleaseRef to %d\n", This
, ref
);
176 HeapFree( GetProcessHeap(), 0, This
);
182 /****** IOleClientSite *****/
183 static inline IOCS
*impl_from_IOleClientSite(IOleClientSite
*iface
)
185 return CONTAINING_RECORD(iface
, IOCS
, IOleClientSite_iface
);
188 static HRESULT WINAPI
OleClientSite_QueryInterface(IOleClientSite
*iface
, REFIID riid
, void **ppv
)
190 IOCS
*This
= impl_from_IOleClientSite(iface
);
191 return IOCS_QueryInterface(This
, riid
, ppv
);
194 static ULONG WINAPI
OleClientSite_AddRef(IOleClientSite
*iface
)
196 IOCS
*This
= impl_from_IOleClientSite(iface
);
197 return IOCS_AddRef(This
);
200 static ULONG WINAPI
OleClientSite_Release(IOleClientSite
*iface
)
202 IOCS
*This
= impl_from_IOleClientSite(iface
);
203 return IOCS_Release(This
);
206 static HRESULT WINAPI
OleClientSite_SaveObject(IOleClientSite
*iface
)
208 IOCS
*This
= impl_from_IOleClientSite(iface
);
209 FIXME( "(%p) - stub\n", This
);
213 static HRESULT WINAPI
OleClientSite_GetMoniker(IOleClientSite
*iface
, DWORD dwAssign
, DWORD dwWhichMoniker
, IMoniker
**ppmk
)
215 IOCS
*This
= impl_from_IOleClientSite(iface
);
217 FIXME( "(%p, 0x%x, 0x%x, %p)\n", This
, dwAssign
, dwWhichMoniker
, ppmk
);
221 static HRESULT WINAPI
OleClientSite_GetContainer(IOleClientSite
*iface
, IOleContainer
**ppContainer
)
223 IOCS
*This
= impl_from_IOleClientSite(iface
);
224 TRACE( "(%p, %p)\n", This
, ppContainer
);
225 return OleClientSite_QueryInterface( iface
, &IID_IOleContainer
, (void**)ppContainer
);
228 static HRESULT WINAPI
OleClientSite_ShowObject(IOleClientSite
*iface
)
230 IOCS
*This
= impl_from_IOleClientSite(iface
);
231 FIXME( "(%p) - stub\n", This
);
235 static HRESULT WINAPI
OleClientSite_OnShowWindow(IOleClientSite
*iface
, BOOL fShow
)
237 IOCS
*This
= impl_from_IOleClientSite(iface
);
238 FIXME( "(%p, %s) - stub\n", This
, fShow
? "TRUE" : "FALSE" );
242 static HRESULT WINAPI
OleClientSite_RequestNewObjectLayout(IOleClientSite
*iface
)
244 IOCS
*This
= impl_from_IOleClientSite(iface
);
245 FIXME( "(%p) - stub\n", This
);
250 /****** IOleContainer *****/
251 static inline IOCS
*impl_from_IOleContainer(IOleContainer
*iface
)
253 return CONTAINING_RECORD(iface
, IOCS
, IOleContainer_iface
);
256 static HRESULT WINAPI
OleContainer_QueryInterface( IOleContainer
* iface
, REFIID riid
, void** ppv
)
258 IOCS
*This
= impl_from_IOleContainer(iface
);
259 return IOCS_QueryInterface( This
, riid
, ppv
);
262 static ULONG WINAPI
OleContainer_AddRef(IOleContainer
* iface
)
264 IOCS
*This
= impl_from_IOleContainer(iface
);
265 return IOCS_AddRef(This
);
268 static ULONG WINAPI
OleContainer_Release(IOleContainer
* iface
)
270 IOCS
*This
= impl_from_IOleContainer(iface
);
271 return IOCS_Release(This
);
274 static HRESULT WINAPI
OleContainer_ParseDisplayName(IOleContainer
* iface
, IBindCtx
* pbc
,
275 LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
)
277 IOCS
*This
= impl_from_IOleContainer(iface
);
278 FIXME( "(%p,%p,%s,%p,%p) - stub\n", This
, pbc
, debugstr_w(pszDisplayName
), pchEaten
, ppmkOut
);
282 static HRESULT WINAPI
OleContainer_EnumObjects(IOleContainer
* iface
, DWORD grfFlags
, IEnumUnknown
** ppenum
)
284 IOCS
*This
= impl_from_IOleContainer(iface
);
285 FIXME( "(%p, %u, %p) - stub\n", This
, grfFlags
, ppenum
);
289 static HRESULT WINAPI
OleContainer_LockContainer(IOleContainer
* iface
, BOOL fLock
)
291 IOCS
*This
= impl_from_IOleContainer(iface
);
292 FIXME( "(%p, %s) - stub\n", This
, fLock
?"TRUE":"FALSE" );
297 /****** IOleInPlaceSiteWindowless *******/
298 static inline IOCS
*impl_from_IOleInPlaceSiteWindowless(IOleInPlaceSiteWindowless
*iface
)
300 return CONTAINING_RECORD(iface
, IOCS
, IOleInPlaceSiteWindowless_iface
);
303 static HRESULT WINAPI
OleInPlaceSiteWindowless_QueryInterface(IOleInPlaceSiteWindowless
*iface
, REFIID riid
, void **ppv
)
305 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
306 return IOCS_QueryInterface(This
, riid
, ppv
);
309 static ULONG WINAPI
OleInPlaceSiteWindowless_AddRef(IOleInPlaceSiteWindowless
*iface
)
311 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
312 return IOCS_AddRef(This
);
315 static ULONG WINAPI
OleInPlaceSiteWindowless_Release(IOleInPlaceSiteWindowless
*iface
)
317 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
318 return IOCS_Release(This
);
321 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetWindow(IOleInPlaceSiteWindowless
* iface
, HWND
* phwnd
)
323 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
325 TRACE("(%p,%p)\n", This
, phwnd
);
330 static HRESULT WINAPI
OleInPlaceSiteWindowless_ContextSensitiveHelp(IOleInPlaceSiteWindowless
* iface
, BOOL fEnterMode
)
332 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
333 FIXME("(%p,%d) - stub\n", This
, fEnterMode
);
337 static HRESULT WINAPI
OleInPlaceSiteWindowless_CanInPlaceActivate(IOleInPlaceSiteWindowless
*iface
)
339 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
340 TRACE("(%p)\n", This
);
344 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceActivate(IOleInPlaceSiteWindowless
*iface
)
346 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
348 TRACE("(%p)\n", This
);
350 This
->fInPlace
= TRUE
;
354 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnUIActivate(IOleInPlaceSiteWindowless
*iface
)
356 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
358 TRACE("(%p)\n", This
);
362 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetWindowContext(IOleInPlaceSiteWindowless
*iface
,
363 IOleInPlaceFrame
**ppFrame
, IOleInPlaceUIWindow
**ppDoc
, LPRECT lprcPosRect
,
364 LPRECT lprcClipRect
, LPOLEINPLACEFRAMEINFO lpFrameInfo
)
366 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
368 TRACE("(%p,%p,%p,%p,%p,%p)\n", This
, ppFrame
, ppDoc
, lprcPosRect
, lprcClipRect
, lpFrameInfo
);
371 *lprcClipRect
= This
->size
;
373 *lprcPosRect
= This
->size
;
377 IOCS_QueryInterface( This
, &IID_IOleInPlaceFrame
, (void**) ppFrame
);
385 lpFrameInfo
->fMDIApp
= FALSE
;
386 lpFrameInfo
->hwndFrame
= This
->hWnd
;
387 lpFrameInfo
->haccel
= NULL
;
388 lpFrameInfo
->cAccelEntries
= 0;
394 static HRESULT WINAPI
OleInPlaceSiteWindowless_Scroll(IOleInPlaceSiteWindowless
*iface
, SIZE scrollExtent
)
396 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
397 FIXME("(%p) - stub\n", This
);
401 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnUIDeactivate(IOleInPlaceSiteWindowless
*iface
, BOOL fUndoable
)
403 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
404 FIXME("(%p,%d) - stub\n", This
, fUndoable
);
408 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceDeactivate(IOleInPlaceSiteWindowless
*iface
)
410 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
412 TRACE("(%p)\n", This
);
414 This
->fInPlace
= This
->fWindowless
= FALSE
;
418 static HRESULT WINAPI
OleInPlaceSiteWindowless_DiscardUndoState(IOleInPlaceSiteWindowless
*iface
)
420 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
421 FIXME("(%p) - stub\n", This
);
425 static HRESULT WINAPI
OleInPlaceSiteWindowless_DeactivateAndUndo(IOleInPlaceSiteWindowless
*iface
)
427 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
428 FIXME("(%p) - stub\n", This
);
432 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnPosRectChange(IOleInPlaceSiteWindowless
*iface
, LPCRECT lprcPosRect
)
434 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
435 FIXME("(%p,%p) - stub\n", This
, lprcPosRect
);
439 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceActivateEx( IOleInPlaceSiteWindowless
*iface
, BOOL
* pfNoRedraw
, DWORD dwFlags
)
441 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
445 This
->fActive
= This
->fInPlace
= TRUE
;
446 if ( dwFlags
& ACTIVATE_WINDOWLESS
)
447 This
->fWindowless
= TRUE
;
451 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnInPlaceDeactivateEx( IOleInPlaceSiteWindowless
*iface
, BOOL fNoRedraw
)
453 IOCS
*This
= impl_from_IOleInPlaceSiteWindowless(iface
);
457 This
->fActive
= This
->fInPlace
= This
->fWindowless
= FALSE
;
460 static HRESULT WINAPI
OleInPlaceSiteWindowless_RequestUIActivate( IOleInPlaceSiteWindowless
*iface
)
465 static HRESULT WINAPI
OleInPlaceSiteWindowless_CanWindowlessActivate( IOleInPlaceSiteWindowless
*iface
)
470 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetCapture( IOleInPlaceSiteWindowless
*iface
)
475 static HRESULT WINAPI
OleInPlaceSiteWindowless_SetCapture( IOleInPlaceSiteWindowless
*iface
, BOOL fCapture
)
480 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetFocus( IOleInPlaceSiteWindowless
*iface
)
485 static HRESULT WINAPI
OleInPlaceSiteWindowless_SetFocus( IOleInPlaceSiteWindowless
*iface
, BOOL fFocus
)
490 static HRESULT WINAPI
OleInPlaceSiteWindowless_GetDC( IOleInPlaceSiteWindowless
*iface
, LPCRECT pRect
, DWORD grfFlags
, HDC
* phDC
)
495 static HRESULT WINAPI
OleInPlaceSiteWindowless_ReleaseDC( IOleInPlaceSiteWindowless
*iface
, HDC hDC
)
500 static HRESULT WINAPI
OleInPlaceSiteWindowless_InvalidateRect( IOleInPlaceSiteWindowless
*iface
, LPCRECT pRect
, BOOL fErase
)
505 static HRESULT WINAPI
OleInPlaceSiteWindowless_InvalidateRgn( IOleInPlaceSiteWindowless
*iface
, HRGN hRGN
, BOOL fErase
)
510 static HRESULT WINAPI
OleInPlaceSiteWindowless_ScrollRect( IOleInPlaceSiteWindowless
*iface
, INT dx
, INT dy
, LPCRECT pRectScroll
, LPCRECT pRectClip
)
515 static HRESULT WINAPI
OleInPlaceSiteWindowless_AdjustRect( IOleInPlaceSiteWindowless
*iface
, LPRECT prc
)
520 static HRESULT WINAPI
OleInPlaceSiteWindowless_OnDefWindowMessage( IOleInPlaceSiteWindowless
*iface
, UINT msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
* plResult
)
527 /****** IOleInPlaceFrame *******/
528 static inline IOCS
*impl_from_IOleInPlaceFrame(IOleInPlaceFrame
*iface
)
530 return CONTAINING_RECORD(iface
, IOCS
, IOleInPlaceFrame_iface
);
533 static HRESULT WINAPI
OleInPlaceFrame_QueryInterface(IOleInPlaceFrame
*iface
, REFIID riid
, void **ppv
)
535 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
536 return IOCS_QueryInterface(This
, riid
, ppv
);
539 static ULONG WINAPI
OleInPlaceFrame_AddRef(IOleInPlaceFrame
*iface
)
541 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
542 return IOCS_AddRef(This
);
545 static ULONG WINAPI
OleInPlaceFrame_Release(IOleInPlaceFrame
*iface
)
547 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
548 return IOCS_Release(This
);
551 static HRESULT WINAPI
OleInPlaceFrame_GetWindow(IOleInPlaceFrame
*iface
, HWND
*phWnd
)
553 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
555 TRACE( "(%p,%p)\n", This
, phWnd
);
561 static HRESULT WINAPI
OleInPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame
*iface
, BOOL fEnterMode
)
563 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
565 FIXME( "(%p,%d) - stub\n", This
, fEnterMode
);
569 static HRESULT WINAPI
OleInPlaceFrame_GetBorder(IOleInPlaceFrame
*iface
, LPRECT lprectBorder
)
571 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
573 FIXME( "(%p,%p) - stub\n", This
, lprectBorder
);
577 static HRESULT WINAPI
OleInPlaceFrame_RequestBorderSpace(IOleInPlaceFrame
*iface
, LPCBORDERWIDTHS pborderwidths
)
579 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
581 FIXME( "(%p,%p) - stub\n", This
, pborderwidths
);
585 static HRESULT WINAPI
OleInPlaceFrame_SetBorderSpace(IOleInPlaceFrame
*iface
, LPCBORDERWIDTHS pborderwidths
)
587 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
589 FIXME( "(%p,%p) - stub\n", This
, pborderwidths
);
593 static HRESULT WINAPI
OleInPlaceFrame_SetActiveObject(IOleInPlaceFrame
*iface
, IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR pszObjName
)
595 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
597 FIXME( "(%p,%p,%s) - stub\n", This
, pActiveObject
, debugstr_w(pszObjName
) );
601 static HRESULT WINAPI
OleInPlaceFrame_InsertMenus(IOleInPlaceFrame
*iface
, HMENU hmenuShared
, LPOLEMENUGROUPWIDTHS lpMenuWidths
)
603 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
605 FIXME( "(%p,%p,%p) - stub\n", This
, hmenuShared
, lpMenuWidths
);
609 static HRESULT WINAPI
OleInPlaceFrame_SetMenu(IOleInPlaceFrame
*iface
, HMENU hmenuShared
, HOLEMENU holemenu
, HWND hwndActiveObject
)
611 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
613 FIXME( "(%p,%p,%p,%p) - stub\n", This
, hmenuShared
, holemenu
, hwndActiveObject
);
617 static HRESULT WINAPI
OleInPlaceFrame_RemoveMenus(IOleInPlaceFrame
*iface
, HMENU hmenuShared
)
619 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
621 FIXME( "(%p, %p) - stub\n", This
, hmenuShared
);
625 static HRESULT WINAPI
OleInPlaceFrame_SetStatusText(IOleInPlaceFrame
*iface
, LPCOLESTR pszStatusText
)
627 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
629 FIXME( "(%p, %s) - stub\n", This
, debugstr_w( pszStatusText
) );
633 static HRESULT WINAPI
OleInPlaceFrame_EnableModeless(IOleInPlaceFrame
*iface
, BOOL fEnable
)
635 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
637 FIXME( "(%p, %d) - stub\n", This
, fEnable
);
641 static HRESULT WINAPI
OleInPlaceFrame_TranslateAccelerator(IOleInPlaceFrame
*iface
, LPMSG lpmsg
, WORD wID
)
643 IOCS
*This
= impl_from_IOleInPlaceFrame(iface
);
645 FIXME( "(%p, %p, %x) - stub\n", This
, lpmsg
, wID
);
650 /****** IOleControlSite *******/
651 static inline IOCS
*impl_from_IOleControlSite(IOleControlSite
*iface
)
653 return CONTAINING_RECORD(iface
, IOCS
, IOleControlSite_iface
);
656 static HRESULT WINAPI
OleControlSite_QueryInterface(IOleControlSite
*iface
, REFIID riid
, void **ppv
)
658 IOCS
*This
= impl_from_IOleControlSite(iface
);
659 return IOCS_QueryInterface(This
, riid
, ppv
);
662 static ULONG WINAPI
OleControlSite_AddRef(IOleControlSite
*iface
)
664 IOCS
*This
= impl_from_IOleControlSite(iface
);
665 return IOCS_AddRef(This
);
668 static ULONG WINAPI
OleControlSite_Release(IOleControlSite
*iface
)
670 IOCS
*This
= impl_from_IOleControlSite(iface
);
671 return IOCS_Release(This
);
674 static HRESULT WINAPI
OleControlSite_OnControlInfoChanged( IOleControlSite
* This
)
679 static HRESULT WINAPI
OleControlSite_LockInPlaceActive( IOleControlSite
* This
, BOOL fLock
)
684 static HRESULT WINAPI
OleControlSite_GetExtendedControl( IOleControlSite
* This
, IDispatch
** ppDisp
)
689 static HRESULT WINAPI
OleControlSite_TransformCoords( IOleControlSite
* This
, POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD dwFlags
)
694 static HRESULT WINAPI
OleControlSite_TranslateAccelerator( IOleControlSite
* This
, MSG
* pMsg
, DWORD grfModifiers
)
699 static HRESULT WINAPI
OleControlSite_OnFocus( IOleControlSite
* This
, BOOL fGotFocus
)
704 static HRESULT WINAPI
OleControlSite_ShowPropertyFrame( IOleControlSite
* This
)
711 static const IOleClientSiteVtbl OleClientSite_vtbl
= {
712 OleClientSite_QueryInterface
,
713 OleClientSite_AddRef
,
714 OleClientSite_Release
,
715 OleClientSite_SaveObject
,
716 OleClientSite_GetMoniker
,
717 OleClientSite_GetContainer
,
718 OleClientSite_ShowObject
,
719 OleClientSite_OnShowWindow
,
720 OleClientSite_RequestNewObjectLayout
722 static const IOleContainerVtbl OleContainer_vtbl
= {
723 OleContainer_QueryInterface
,
725 OleContainer_Release
,
726 OleContainer_ParseDisplayName
,
727 OleContainer_EnumObjects
,
728 OleContainer_LockContainer
730 static const IOleInPlaceSiteWindowlessVtbl OleInPlaceSiteWindowless_vtbl
= {
731 OleInPlaceSiteWindowless_QueryInterface
,
732 OleInPlaceSiteWindowless_AddRef
,
733 OleInPlaceSiteWindowless_Release
,
734 OleInPlaceSiteWindowless_GetWindow
,
735 OleInPlaceSiteWindowless_ContextSensitiveHelp
,
736 OleInPlaceSiteWindowless_CanInPlaceActivate
,
737 OleInPlaceSiteWindowless_OnInPlaceActivate
,
738 OleInPlaceSiteWindowless_OnUIActivate
,
739 OleInPlaceSiteWindowless_GetWindowContext
,
740 OleInPlaceSiteWindowless_Scroll
,
741 OleInPlaceSiteWindowless_OnUIDeactivate
,
742 OleInPlaceSiteWindowless_OnInPlaceDeactivate
,
743 OleInPlaceSiteWindowless_DiscardUndoState
,
744 OleInPlaceSiteWindowless_DeactivateAndUndo
,
745 OleInPlaceSiteWindowless_OnPosRectChange
,
746 OleInPlaceSiteWindowless_OnInPlaceActivateEx
,
747 OleInPlaceSiteWindowless_OnInPlaceDeactivateEx
,
748 OleInPlaceSiteWindowless_RequestUIActivate
,
749 OleInPlaceSiteWindowless_CanWindowlessActivate
,
750 OleInPlaceSiteWindowless_GetCapture
,
751 OleInPlaceSiteWindowless_SetCapture
,
752 OleInPlaceSiteWindowless_GetFocus
,
753 OleInPlaceSiteWindowless_SetFocus
,
754 OleInPlaceSiteWindowless_GetDC
,
755 OleInPlaceSiteWindowless_ReleaseDC
,
756 OleInPlaceSiteWindowless_InvalidateRect
,
757 OleInPlaceSiteWindowless_InvalidateRgn
,
758 OleInPlaceSiteWindowless_ScrollRect
,
759 OleInPlaceSiteWindowless_AdjustRect
,
760 OleInPlaceSiteWindowless_OnDefWindowMessage
762 static const IOleInPlaceFrameVtbl OleInPlaceFrame_vtbl
=
764 OleInPlaceFrame_QueryInterface
,
765 OleInPlaceFrame_AddRef
,
766 OleInPlaceFrame_Release
,
767 OleInPlaceFrame_GetWindow
,
768 OleInPlaceFrame_ContextSensitiveHelp
,
769 OleInPlaceFrame_GetBorder
,
770 OleInPlaceFrame_RequestBorderSpace
,
771 OleInPlaceFrame_SetBorderSpace
,
772 OleInPlaceFrame_SetActiveObject
,
773 OleInPlaceFrame_InsertMenus
,
774 OleInPlaceFrame_SetMenu
,
775 OleInPlaceFrame_RemoveMenus
,
776 OleInPlaceFrame_SetStatusText
,
777 OleInPlaceFrame_EnableModeless
,
778 OleInPlaceFrame_TranslateAccelerator
780 static const IOleControlSiteVtbl OleControlSite_vtbl
=
782 OleControlSite_QueryInterface
,
783 OleControlSite_AddRef
,
784 OleControlSite_Release
,
785 OleControlSite_OnControlInfoChanged
,
786 OleControlSite_LockInPlaceActive
,
787 OleControlSite_GetExtendedControl
,
788 OleControlSite_TransformCoords
,
789 OleControlSite_TranslateAccelerator
,
790 OleControlSite_OnFocus
,
791 OleControlSite_ShowPropertyFrame
794 static HRESULT
IOCS_Detach( IOCS
*This
) /* remove subclassing */
798 SetWindowLongPtrW( This
->hWnd
, GWLP_WNDPROC
, (ULONG_PTR
) This
->OrigWndProc
);
799 SetWindowLongPtrW( This
->hWnd
, GWLP_USERDATA
, 0 );
804 IOleObject
*control
= This
->control
;
806 This
->control
= NULL
;
807 IOleObject_Close( control
, OLECLOSE_NOSAVE
);
808 IOleObject_SetClientSite( control
, NULL
);
809 IOleObject_Release( control
);
814 static void IOCS_OnSize( IOCS
* This
, LPCRECT rect
)
818 This
->size
.left
= rect
->left
; This
->size
.right
= rect
->right
; This
->size
.top
= rect
->top
; This
->size
.bottom
= rect
->bottom
;
820 if ( !This
->control
)
823 inPix
.cx
= rect
->right
- rect
->left
;
824 inPix
.cy
= rect
->bottom
- rect
->top
;
825 AtlPixelToHiMetric( &inPix
, &inHi
);
826 IOleObject_SetExtent( This
->control
, DVASPECT_CONTENT
, &inHi
);
828 if ( This
->fInPlace
)
830 IOleInPlaceObject
*wl
;
832 if ( SUCCEEDED( IOleObject_QueryInterface( This
->control
, &IID_IOleInPlaceObject
, (void**)&wl
) ) )
834 IOleInPlaceObject_SetObjectRects( wl
, rect
, rect
);
835 IOleInPlaceObject_Release( wl
);
840 static void IOCS_OnShow( IOCS
*This
, BOOL fShow
)
842 if (!This
->control
|| This
->fActive
|| !fShow
)
845 This
->fActive
= TRUE
;
848 static void IOCS_OnDraw( IOCS
*This
)
852 if ( !This
->control
|| !This
->fWindowless
)
855 if ( SUCCEEDED( IOleObject_QueryInterface( This
->control
, &IID_IViewObject
, (void**)&view
) ) )
857 HDC dc
= GetDC( This
->hWnd
);
860 rect
.left
= This
->size
.left
; rect
.top
= This
->size
.top
;
861 rect
.bottom
= This
->size
.bottom
; rect
.right
= This
->size
.right
;
863 IViewObject_Draw( view
, DVASPECT_CONTENT
, ~0, NULL
, NULL
, 0, dc
, &rect
, &rect
, NULL
, 0 );
864 IViewObject_Release( view
);
865 ReleaseDC( This
->hWnd
, dc
);
869 static LRESULT
IOCS_OnWndProc( IOCS
*This
, HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
871 WNDPROC OrigWndProc
= This
->OrigWndProc
;
882 r
.right
= LOWORD( lParam
);
883 r
.bottom
= HIWORD( lParam
);
884 IOCS_OnSize( This
, &r
);
888 IOCS_OnShow( This
, (BOOL
) wParam
);
895 return CallWindowProcW( OrigWndProc
, hWnd
, uMsg
, wParam
, lParam
);
898 static LRESULT CALLBACK
AtlHost_wndproc( HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
900 IOCS
*This
= (IOCS
*) GetWindowLongPtrW( hWnd
, GWLP_USERDATA
);
901 return IOCS_OnWndProc( This
, hWnd
, wMsg
, wParam
, lParam
);
904 static HRESULT
IOCS_Attach( IOCS
*This
, HWND hWnd
, IUnknown
*pUnkControl
) /* subclass hWnd */
907 IUnknown_QueryInterface( pUnkControl
, &IID_IOleObject
, (void**)&This
->control
);
908 IOleObject_SetClientSite( This
->control
, &This
->IOleClientSite_iface
);
909 SetWindowLongPtrW( hWnd
, GWLP_USERDATA
, (ULONG_PTR
) This
);
910 This
->OrigWndProc
= (WNDPROC
)SetWindowLongPtrW( hWnd
, GWLP_WNDPROC
, (ULONG_PTR
) AtlHost_wndproc
);
915 static HRESULT
IOCS_Init( IOCS
*This
)
918 static const WCHAR AXWIN
[] = {'A','X','W','I','N',0};
920 IOleObject_SetHostNames( This
->control
, AXWIN
, AXWIN
);
922 GetClientRect( This
->hWnd
, &rect
);
923 IOCS_OnSize( This
, &rect
);
924 IOleObject_DoVerb( This
->control
, OLEIVERB_INPLACEACTIVATE
, NULL
, &This
->IOleClientSite_iface
,
925 0, This
->hWnd
, &rect
);
930 /**********************************************************************
931 * Create new instance of Atl host component and attach it to window *
933 static HRESULT
IOCS_Create( HWND hWnd
, IUnknown
*pUnkControl
, IOCS
**ppSite
)
939 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(IOCS
));
942 return E_OUTOFMEMORY
;
944 This
->IOleClientSite_iface
.lpVtbl
= &OleClientSite_vtbl
;
945 This
->IOleContainer_iface
.lpVtbl
= &OleContainer_vtbl
;
946 This
->IOleInPlaceSiteWindowless_iface
.lpVtbl
= &OleInPlaceSiteWindowless_vtbl
;
947 This
->IOleInPlaceFrame_iface
.lpVtbl
= &OleInPlaceFrame_vtbl
;
948 This
->IOleControlSite_iface
.lpVtbl
= &OleControlSite_vtbl
;
951 This
->OrigWndProc
= NULL
;
953 This
->fWindowless
= This
->fActive
= This
->fInPlace
= FALSE
;
955 hr
= IOCS_Attach( This
, hWnd
, pUnkControl
);
956 if ( SUCCEEDED( hr
) )
957 hr
= IOCS_Init( This
);
958 if ( SUCCEEDED( hr
) )
961 IOCS_Release( This
);
967 /***********************************************************************
968 * AtlAxCreateControl [atl100.@]
970 HRESULT WINAPI
AtlAxCreateControl(LPCOLESTR lpszName
, HWND hWnd
,
971 IStream
*pStream
, IUnknown
**ppUnkContainer
)
973 return AtlAxCreateControlEx( lpszName
, hWnd
, pStream
, ppUnkContainer
,
977 /***********************************************************************
978 * AtlAxCreateControlEx [atl100.@]
981 * See http://www.codeproject.com/com/cwebpage.asp for some background
984 HRESULT WINAPI
AtlAxCreateControlEx(LPCOLESTR lpszName
, HWND hWnd
,
985 IStream
*pStream
, IUnknown
**ppUnkContainer
, IUnknown
**ppUnkControl
,
986 REFIID iidSink
, IUnknown
*punkSink
)
990 IOleObject
*pControl
;
991 IUnknown
*pUnkControl
;
992 IPersistStreamInit
*pPSInit
;
993 IUnknown
*pContainer
;
994 enum {IsGUID
=0,IsHTML
=1,IsURL
=2} content
;
996 TRACE("(%s %p %p %p %p %p %p)\n", debugstr_w(lpszName
), hWnd
, pStream
,
997 ppUnkContainer
, ppUnkControl
, iidSink
, punkSink
);
999 hRes
= CLSIDFromString( lpszName
, &controlId
);
1001 hRes
= CLSIDFromProgID( lpszName
, &controlId
);
1002 if ( SUCCEEDED( hRes
) )
1005 /* FIXME - check for MSHTML: prefix! */
1007 controlId
= CLSID_WebBrowser
;
1010 hRes
= CoCreateInstance( &controlId
, 0, CLSCTX_ALL
, &IID_IOleObject
,
1011 (void**) &pControl
);
1012 if ( FAILED( hRes
) )
1014 WARN( "cannot create ActiveX control %s instance - error 0x%08x\n",
1015 debugstr_guid( &controlId
), hRes
);
1019 hRes
= IOleObject_QueryInterface( pControl
, &IID_IPersistStreamInit
, (void**) &pPSInit
);
1020 if ( SUCCEEDED( hRes
) )
1023 IPersistStreamInit_InitNew( pPSInit
);
1025 IPersistStreamInit_Load( pPSInit
, pStream
);
1026 IPersistStreamInit_Release( pPSInit
);
1028 WARN("cannot get IID_IPersistStreamInit out of control\n");
1030 IOleObject_QueryInterface( pControl
, &IID_IUnknown
, (void**) &pUnkControl
);
1031 IOleObject_Release( pControl
);
1034 hRes
= AtlAxAttachControl( pUnkControl
, hWnd
, &pContainer
);
1035 if ( FAILED( hRes
) )
1036 WARN("cannot attach control to window\n");
1038 if ( content
== IsURL
)
1040 IWebBrowser2
*browser
;
1042 hRes
= IOleObject_QueryInterface( pControl
, &IID_IWebBrowser2
, (void**) &browser
);
1044 WARN( "Cannot query IWebBrowser2 interface: %08x\n", hRes
);
1048 IWebBrowser2_put_Visible( browser
, VARIANT_TRUE
); /* it seems that native does this on URL (but do not on MSHTML:! why? */
1050 V_VT(&url
) = VT_BSTR
;
1051 V_BSTR(&url
) = SysAllocString( lpszName
);
1053 hRes
= IWebBrowser2_Navigate2( browser
, &url
, NULL
, NULL
, NULL
, NULL
);
1054 if ( FAILED( hRes
) )
1055 WARN( "IWebBrowser2::Navigate2 failed: %08x\n", hRes
);
1056 SysFreeString( V_BSTR(&url
) );
1058 IWebBrowser2_Release( browser
);
1064 *ppUnkContainer
= pContainer
;
1066 IUnknown_AddRef( pContainer
);
1070 *ppUnkControl
= pUnkControl
;
1072 IUnknown_AddRef( pUnkControl
);
1076 IUnknown_Release( pUnkControl
);
1078 IUnknown_Release( pContainer
);
1083 /***********************************************************************
1084 * AtlAxAttachControl [atl100.@]
1086 HRESULT WINAPI
AtlAxAttachControl(IUnknown
* pControl
, HWND hWnd
, IUnknown
** ppUnkContainer
)
1088 IOCS
*pUnkContainer
;
1091 TRACE( "%p %p %p\n", pControl
, hWnd
, ppUnkContainer
);
1094 return E_INVALIDARG
;
1096 hr
= IOCS_Create( hWnd
, pControl
, &pUnkContainer
);
1097 if ( SUCCEEDED( hr
) && ppUnkContainer
)
1099 *ppUnkContainer
= (IUnknown
*) pUnkContainer
;
1108 /**********************************************************************
1109 * Helper function for AX_ConvertDialogTemplate
1111 static inline BOOL
advance_array(WORD
**pptr
, DWORD
*palloc
, DWORD
*pfilled
, const WORD
*data
, DWORD size
)
1113 if ( (*pfilled
+ size
) > *palloc
)
1115 *palloc
= ((*pfilled
+size
) + 0xFF) & ~0xFF;
1116 *pptr
= HeapReAlloc( GetProcessHeap(), 0, *pptr
, *palloc
* sizeof(WORD
) );
1120 RtlMoveMemory( *pptr
+*pfilled
, data
, size
* sizeof(WORD
) );
1125 /**********************************************************************
1126 * Convert ActiveX control templates to AtlAxWin class instances
1128 static LPDLGTEMPLATEW
AX_ConvertDialogTemplate(LPCDLGTEMPLATEW src_tmpl
)
1130 #define GET_WORD(x) (*(const WORD *)(x))
1131 #define GET_DWORD(x) (*(const DWORD *)(x))
1132 #define PUT_BLOCK(x,y) do {if (!advance_array(&output, &allocated, &filled, (x), (y))) return NULL;} while (0)
1133 #define PUT_WORD(x) do {WORD w = (x);PUT_BLOCK(&w, 1);} while(0)
1134 #define PUT_DWORD(x) do {DWORD w = (x);PUT_BLOCK(&w, 2);} while(0)
1135 const WORD
*tmp
, *src
= (const WORD
*)src_tmpl
;
1137 DWORD allocated
, filled
; /* in WORDs */
1139 WORD signature
, dlgver
, rescount
;
1142 filled
= 0; allocated
= 256;
1143 output
= HeapAlloc( GetProcessHeap(), 0, allocated
* sizeof(WORD
) );
1149 signature
= GET_WORD(src
);
1150 dlgver
= GET_WORD(src
+ 1);
1151 if (signature
== 1 && dlgver
== 0xFFFF)
1155 style
= GET_DWORD(src
);
1157 rescount
= GET_WORD(src
++);
1159 if ( GET_WORD(src
) == 0xFFFF ) /* menu */
1162 src
+= strlenW(src
) + 1;
1163 if ( GET_WORD(src
) == 0xFFFF ) /* class */
1166 src
+= strlenW(src
) + 1;
1167 src
+= strlenW(src
) + 1; /* title */
1168 if ( style
& (DS_SETFONT
| DS_SHELLFONT
) )
1171 src
+= strlenW(src
) + 1;
1175 style
= GET_DWORD(src
);
1177 rescount
= GET_WORD(src
++);
1179 if ( GET_WORD(src
) == 0xFFFF ) /* menu */
1182 src
+= strlenW(src
) + 1;
1183 if ( GET_WORD(src
) == 0xFFFF ) /* class */
1186 src
+= strlenW(src
) + 1;
1187 src
+= strlenW(src
) + 1; /* title */
1188 if ( style
& DS_SETFONT
)
1191 src
+= strlenW(src
) + 1;
1194 PUT_BLOCK(tmp
, src
-tmp
);
1198 src
= (const WORD
*)( ( ((ULONG_PTR
)src
) + 3) & ~3); /* align on DWORD boundary */
1199 filled
= (filled
+ 1) & ~1; /* depends on DWORD-aligned allocation unit */
1206 PUT_BLOCK(tmp
, src
-tmp
);
1209 if ( GET_WORD(src
) == 0xFFFF ) /* class */
1214 src
+= strlenW(src
) + 1;
1216 src
+= strlenW(src
) + 1; /* title */
1217 if ( GET_WORD(tmp
) == '{' ) /* all this mess created because of this line */
1219 static const WCHAR AtlAxWin
[] = {'A','t','l','A','x','W','i','n', 0};
1220 PUT_BLOCK(AtlAxWin
, sizeof(AtlAxWin
)/sizeof(WCHAR
));
1221 PUT_BLOCK(tmp
, strlenW(tmp
)+1);
1223 PUT_BLOCK(tmp
, src
-tmp
);
1225 if ( GET_WORD(src
) )
1227 WORD size
= (GET_WORD(src
)+sizeof(WORD
)-1) / sizeof(WORD
); /* quite ugly :( Maybe use BYTE* instead of WORD* everywhere ? */
1228 PUT_BLOCK(src
, size
);
1237 return (LPDLGTEMPLATEW
) output
;
1240 /***********************************************************************
1241 * AtlAxCreateDialogA [atl100.@]
1243 * Creates a dialog window
1246 * hInst [I] Application instance
1247 * name [I] Dialog box template name
1248 * owner [I] Dialog box parent HWND
1249 * dlgProc [I] Dialog box procedure
1250 * param [I] This value will be passed to dlgProc as WM_INITDIALOG's message lParam
1253 * Window handle of dialog window.
1255 HWND WINAPI
AtlAxCreateDialogA(HINSTANCE hInst
, LPCSTR name
, HWND owner
, DLGPROC dlgProc
,LPARAM param
)
1261 if (IS_INTRESOURCE(name
))
1262 return AtlAxCreateDialogW( hInst
, (LPCWSTR
) name
, owner
, dlgProc
, param
);
1264 length
= MultiByteToWideChar( CP_ACP
, 0, name
, -1, NULL
, 0 );
1265 nameW
= HeapAlloc( GetProcessHeap(), 0, length
* sizeof(WCHAR
) );
1268 MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, length
);
1269 res
= AtlAxCreateDialogW( hInst
, nameW
, owner
, dlgProc
, param
);
1270 HeapFree( GetProcessHeap(), 0, nameW
);
1275 /***********************************************************************
1276 * AtlAxCreateDialogW [atl100.@]
1278 * See AtlAxCreateDialogA
1281 HWND WINAPI
AtlAxCreateDialogW(HINSTANCE hInst
, LPCWSTR name
, HWND owner
, DLGPROC dlgProc
,LPARAM param
)
1285 LPCDLGTEMPLATEW ptr
;
1286 LPDLGTEMPLATEW newptr
;
1289 TRACE("(%p %s %p %p %lx)\n", hInst
, debugstr_w(name
), owner
, dlgProc
, param
);
1291 hrsrc
= FindResourceW( hInst
, name
, (LPWSTR
)RT_DIALOG
);
1294 hgl
= LoadResource (hInst
, hrsrc
);
1297 ptr
= LockResource ( hgl
);
1300 FreeResource( hgl
);
1303 newptr
= AX_ConvertDialogTemplate( ptr
);
1306 res
= CreateDialogIndirectParamW( hInst
, newptr
, owner
, dlgProc
, param
);
1307 HeapFree( GetProcessHeap(), 0, newptr
);
1310 FreeResource ( hrsrc
);
1314 /***********************************************************************
1315 * AtlAxGetHost [atl100.@]
1318 HRESULT WINAPI
AtlAxGetHost(HWND hWnd
, IUnknown
**pUnk
)
1322 TRACE( "(%p, %p)\n", hWnd
, pUnk
);
1326 This
= (IOCS
*) GetWindowLongPtrW( hWnd
, GWLP_USERDATA
);
1329 WARN("No container attached to %p\n", hWnd
);
1333 return IOCS_QueryInterface( This
, &IID_IUnknown
, (void**) pUnk
);
1336 /***********************************************************************
1337 * AtlAxGetControl [atl100.@]
1340 HRESULT WINAPI
AtlAxGetControl(HWND hWnd
, IUnknown
**pUnk
)
1344 TRACE( "(%p, %p)\n", hWnd
, pUnk
);
1348 This
= (IOCS
*) GetWindowLongPtrW( hWnd
, GWLP_USERDATA
);
1349 if ( !This
|| !This
->control
)
1351 WARN("No control attached to %p\n", hWnd
);
1355 return IOleObject_QueryInterface( This
->control
, &IID_IUnknown
, (void**) pUnk
);