Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenatl_ax.c
Go to the documentation of this file.
00001 /* 00002 * Active Template Library ActiveX functions (atl.dll) 00003 * 00004 * Copyright 2006 Andrey Turkin 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #include <stdarg.h> 00022 #include <stdio.h> 00023 00024 #define COBJMACROS 00025 00026 #include "windef.h" 00027 #include "winbase.h" 00028 #include "winerror.h" 00029 #include "winuser.h" 00030 #include "wine/debug.h" 00031 #include "objbase.h" 00032 #include "objidl.h" 00033 #include "ole2.h" 00034 #include "exdisp.h" 00035 #include "atlbase.h" 00036 #include "atliface.h" 00037 #include "atlwin.h" 00038 00039 #include "wine/unicode.h" 00040 00041 WINE_DEFAULT_DEBUG_CHANNEL(atl); 00042 00043 typedef struct IOCS { 00044 IOleClientSite IOleClientSite_iface; 00045 IOleContainer IOleContainer_iface; 00046 IOleInPlaceSiteWindowless IOleInPlaceSiteWindowless_iface; 00047 IOleInPlaceFrame IOleInPlaceFrame_iface; 00048 IOleControlSite IOleControlSite_iface; 00049 00050 LONG ref; 00051 HWND hWnd; 00052 IOleObject *control; 00053 RECT size; 00054 WNDPROC OrigWndProc; 00055 BOOL fActive, fInPlace, fWindowless; 00056 } IOCS; 00057 00058 /********************************************************************** 00059 * AtlAxWin class window procedure 00060 */ 00061 static LRESULT CALLBACK AtlAxWin_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam ) 00062 { 00063 if ( wMsg == WM_CREATE ) 00064 { 00065 DWORD len = GetWindowTextLengthW( hWnd ) + 1; 00066 WCHAR *ptr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); 00067 if (!ptr) 00068 return 1; 00069 GetWindowTextW( hWnd, ptr, len ); 00070 AtlAxCreateControlEx( ptr, hWnd, NULL, NULL, NULL, NULL, NULL ); 00071 HeapFree( GetProcessHeap(), 0, ptr ); 00072 return 0; 00073 } 00074 return DefWindowProcW( hWnd, wMsg, wParam, lParam ); 00075 } 00076 00077 /*********************************************************************** 00078 * AtlAxWinInit [ATL.@] 00079 * Initializes the control-hosting code: registering the AtlAxWin, 00080 * AtlAxWin7 and AtlAxWinLic7 window classes and some messages. 00081 * 00082 * RETURNS 00083 * TRUE or FALSE 00084 */ 00085 00086 BOOL WINAPI AtlAxWinInit(void) 00087 { 00088 WNDCLASSEXW wcex; 00089 const WCHAR AtlAxWin[] = {'A','t','l','A','x','W','i','n',0}; 00090 00091 FIXME("semi-stub\n"); 00092 00093 if ( FAILED( OleInitialize(NULL) ) ) 00094 return FALSE; 00095 00096 wcex.cbSize = sizeof(wcex); 00097 wcex.style = 0; 00098 wcex.cbClsExtra = 0; 00099 wcex.cbWndExtra = 0; 00100 wcex.hInstance = GetModuleHandleW( NULL ); 00101 wcex.hIcon = NULL; 00102 wcex.hCursor = NULL; 00103 wcex.hbrBackground = NULL; 00104 wcex.lpszMenuName = NULL; 00105 wcex.hIconSm = 0; 00106 00107 wcex.lpfnWndProc = AtlAxWin_wndproc; 00108 wcex.lpszClassName = AtlAxWin; 00109 if ( !RegisterClassExW( &wcex ) ) 00110 return FALSE; 00111 00112 return TRUE; 00113 } 00114 00115 /*********************************************************************** 00116 * Atl container component implementation 00117 */ 00118 00119 00120 static ULONG IOCS_AddRef(IOCS *This) 00121 { 00122 ULONG ref = InterlockedIncrement(&This->ref); 00123 00124 TRACE( "(%p) : AddRef from %d\n", This, ref - 1 ); 00125 00126 return ref; 00127 } 00128 00129 static HRESULT IOCS_QueryInterface(IOCS *This, REFIID riid, void **ppv) 00130 { 00131 *ppv = NULL; 00132 00133 if ( IsEqualIID( &IID_IUnknown, riid ) 00134 || IsEqualIID( &IID_IOleClientSite, riid ) ) 00135 { 00136 *ppv = &This->IOleClientSite_iface; 00137 } else if ( IsEqualIID( &IID_IOleContainer, riid ) ) 00138 { 00139 *ppv = &This->IOleContainer_iface; 00140 } else if ( IsEqualIID( &IID_IOleInPlaceSite, riid ) || IsEqualIID( &IID_IOleInPlaceSiteEx, riid ) || IsEqualIID( &IID_IOleInPlaceSiteWindowless, riid ) ) 00141 { 00142 *ppv = &This->IOleInPlaceSiteWindowless_iface; 00143 } else if ( IsEqualIID( &IID_IOleInPlaceFrame, riid ) ) 00144 { 00145 *ppv = &This->IOleInPlaceFrame_iface; 00146 } else if ( IsEqualIID( &IID_IOleControlSite, riid ) ) 00147 { 00148 *ppv = &This->IOleControlSite_iface; 00149 } 00150 00151 if (*ppv) 00152 { 00153 IOCS_AddRef( This ); 00154 return S_OK; 00155 } 00156 00157 WARN("unsupported interface %s\n", debugstr_guid( riid ) ); 00158 *ppv = NULL; 00159 return E_NOINTERFACE; 00160 } 00161 00162 static HRESULT IOCS_Detach( IOCS *This ); 00163 static ULONG IOCS_Release(IOCS *This) 00164 { 00165 ULONG ref = InterlockedDecrement(&This->ref); 00166 00167 TRACE( "(%p) : ReleaseRef to %d\n", This, ref ); 00168 00169 if (!ref) 00170 { 00171 IOCS_Detach( This ); 00172 HeapFree( GetProcessHeap(), 0, This ); 00173 } 00174 00175 return ref; 00176 } 00177 00178 /****** IOleClientSite *****/ 00179 static inline IOCS *impl_from_IOleClientSite(IOleClientSite *iface) 00180 { 00181 return CONTAINING_RECORD(iface, IOCS, IOleClientSite_iface); 00182 } 00183 00184 static HRESULT WINAPI OleClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv) 00185 { 00186 IOCS *This = impl_from_IOleClientSite(iface); 00187 return IOCS_QueryInterface(This, riid, ppv); 00188 } 00189 00190 static ULONG WINAPI OleClientSite_AddRef(IOleClientSite *iface) 00191 { 00192 IOCS *This = impl_from_IOleClientSite(iface); 00193 return IOCS_AddRef(This); 00194 } 00195 00196 static ULONG WINAPI OleClientSite_Release(IOleClientSite *iface) 00197 { 00198 IOCS *This = impl_from_IOleClientSite(iface); 00199 return IOCS_Release(This); 00200 } 00201 00202 static HRESULT WINAPI OleClientSite_SaveObject(IOleClientSite *iface) 00203 { 00204 IOCS *This = impl_from_IOleClientSite(iface); 00205 FIXME( "(%p) - stub\n", This ); 00206 return E_NOTIMPL; 00207 } 00208 00209 static HRESULT WINAPI OleClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk) 00210 { 00211 IOCS *This = impl_from_IOleClientSite(iface); 00212 00213 FIXME( "(%p, 0x%x, 0x%x, %p)\n", This, dwAssign, dwWhichMoniker, ppmk ); 00214 return E_NOTIMPL; 00215 } 00216 00217 static HRESULT WINAPI OleClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer) 00218 { 00219 IOCS *This = impl_from_IOleClientSite(iface); 00220 TRACE( "(%p, %p)\n", This, ppContainer ); 00221 return OleClientSite_QueryInterface( iface, &IID_IOleContainer, (void**)ppContainer ); 00222 } 00223 00224 static HRESULT WINAPI OleClientSite_ShowObject(IOleClientSite *iface) 00225 { 00226 IOCS *This = impl_from_IOleClientSite(iface); 00227 FIXME( "(%p) - stub\n", This ); 00228 return S_OK; 00229 } 00230 00231 static HRESULT WINAPI OleClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow) 00232 { 00233 IOCS *This = impl_from_IOleClientSite(iface); 00234 FIXME( "(%p, %s) - stub\n", This, fShow ? "TRUE" : "FALSE" ); 00235 return E_NOTIMPL; 00236 } 00237 00238 static HRESULT WINAPI OleClientSite_RequestNewObjectLayout(IOleClientSite *iface) 00239 { 00240 IOCS *This = impl_from_IOleClientSite(iface); 00241 FIXME( "(%p) - stub\n", This ); 00242 return E_NOTIMPL; 00243 } 00244 00245 00246 /****** IOleContainer *****/ 00247 static inline IOCS *impl_from_IOleContainer(IOleContainer *iface) 00248 { 00249 return CONTAINING_RECORD(iface, IOCS, IOleContainer_iface); 00250 } 00251 00252 static HRESULT WINAPI OleContainer_QueryInterface( IOleContainer* iface, REFIID riid, void** ppv) 00253 { 00254 IOCS *This = impl_from_IOleContainer(iface); 00255 return IOCS_QueryInterface( This, riid, ppv ); 00256 } 00257 00258 static ULONG WINAPI OleContainer_AddRef(IOleContainer* iface) 00259 { 00260 IOCS *This = impl_from_IOleContainer(iface); 00261 return IOCS_AddRef(This); 00262 } 00263 00264 static ULONG WINAPI OleContainer_Release(IOleContainer* iface) 00265 { 00266 IOCS *This = impl_from_IOleContainer(iface); 00267 return IOCS_Release(This); 00268 } 00269 00270 static HRESULT WINAPI OleContainer_ParseDisplayName(IOleContainer* iface, IBindCtx* pbc, 00271 LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut) 00272 { 00273 IOCS *This = impl_from_IOleContainer(iface); 00274 FIXME( "(%p,%p,%s,%p,%p) - stub\n", This, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut ); 00275 return E_NOTIMPL; 00276 } 00277 00278 static HRESULT WINAPI OleContainer_EnumObjects(IOleContainer* iface, DWORD grfFlags, IEnumUnknown** ppenum) 00279 { 00280 IOCS *This = impl_from_IOleContainer(iface); 00281 FIXME( "(%p, %u, %p) - stub\n", This, grfFlags, ppenum ); 00282 return E_NOTIMPL; 00283 } 00284 00285 static HRESULT WINAPI OleContainer_LockContainer(IOleContainer* iface, BOOL fLock) 00286 { 00287 IOCS *This = impl_from_IOleContainer(iface); 00288 FIXME( "(%p, %s) - stub\n", This, fLock?"TRUE":"FALSE" ); 00289 return E_NOTIMPL; 00290 } 00291 00292 00293 /****** IOleInPlaceSiteWindowless *******/ 00294 static inline IOCS *impl_from_IOleInPlaceSiteWindowless(IOleInPlaceSiteWindowless *iface) 00295 { 00296 return CONTAINING_RECORD(iface, IOCS, IOleInPlaceSiteWindowless_iface); 00297 } 00298 00299 static HRESULT WINAPI OleInPlaceSiteWindowless_QueryInterface(IOleInPlaceSiteWindowless *iface, REFIID riid, void **ppv) 00300 { 00301 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00302 return IOCS_QueryInterface(This, riid, ppv); 00303 } 00304 00305 static ULONG WINAPI OleInPlaceSiteWindowless_AddRef(IOleInPlaceSiteWindowless *iface) 00306 { 00307 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00308 return IOCS_AddRef(This); 00309 } 00310 00311 static ULONG WINAPI OleInPlaceSiteWindowless_Release(IOleInPlaceSiteWindowless *iface) 00312 { 00313 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00314 return IOCS_Release(This); 00315 } 00316 00317 static HRESULT WINAPI OleInPlaceSiteWindowless_GetWindow(IOleInPlaceSiteWindowless* iface, HWND* phwnd) 00318 { 00319 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00320 00321 TRACE("(%p,%p)\n", This, phwnd); 00322 *phwnd = This->hWnd; 00323 return S_OK; 00324 } 00325 00326 static HRESULT WINAPI OleInPlaceSiteWindowless_ContextSensitiveHelp(IOleInPlaceSiteWindowless* iface, BOOL fEnterMode) 00327 { 00328 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00329 FIXME("(%p,%d) - stub\n", This, fEnterMode); 00330 return E_NOTIMPL; 00331 } 00332 00333 static HRESULT WINAPI OleInPlaceSiteWindowless_CanInPlaceActivate(IOleInPlaceSiteWindowless *iface) 00334 { 00335 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00336 TRACE("(%p)\n", This); 00337 return S_OK; 00338 } 00339 00340 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceActivate(IOleInPlaceSiteWindowless *iface) 00341 { 00342 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00343 00344 TRACE("(%p)\n", This); 00345 00346 This->fInPlace = TRUE; 00347 return S_OK; 00348 } 00349 00350 static HRESULT WINAPI OleInPlaceSiteWindowless_OnUIActivate(IOleInPlaceSiteWindowless *iface) 00351 { 00352 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00353 00354 TRACE("(%p)\n", This); 00355 00356 return S_OK; 00357 } 00358 static HRESULT WINAPI OleInPlaceSiteWindowless_GetWindowContext(IOleInPlaceSiteWindowless *iface, 00359 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect, 00360 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo) 00361 { 00362 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00363 00364 TRACE("(%p,%p,%p,%p,%p,%p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, lpFrameInfo); 00365 00366 if ( lprcClipRect ) 00367 *lprcClipRect = This->size; 00368 if ( lprcPosRect ) 00369 *lprcPosRect = This->size; 00370 00371 if ( ppFrame ) 00372 { 00373 IOCS_QueryInterface( This, &IID_IOleInPlaceFrame, (void**) ppFrame ); 00374 } 00375 00376 if ( ppDoc ) 00377 *ppDoc = NULL; 00378 00379 if ( lpFrameInfo ) 00380 { 00381 lpFrameInfo->fMDIApp = FALSE; 00382 lpFrameInfo->hwndFrame = This->hWnd; 00383 lpFrameInfo->haccel = NULL; 00384 lpFrameInfo->cAccelEntries = 0; 00385 } 00386 00387 return S_OK; 00388 } 00389 00390 static HRESULT WINAPI OleInPlaceSiteWindowless_Scroll(IOleInPlaceSiteWindowless *iface, SIZE scrollExtent) 00391 { 00392 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00393 FIXME("(%p) - stub\n", This); 00394 return E_NOTIMPL; 00395 } 00396 00397 static HRESULT WINAPI OleInPlaceSiteWindowless_OnUIDeactivate(IOleInPlaceSiteWindowless *iface, BOOL fUndoable) 00398 { 00399 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00400 FIXME("(%p,%d) - stub\n", This, fUndoable); 00401 return E_NOTIMPL; 00402 } 00403 00404 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceDeactivate(IOleInPlaceSiteWindowless *iface) 00405 { 00406 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00407 00408 TRACE("(%p)\n", This); 00409 00410 This->fInPlace = This->fWindowless = FALSE; 00411 return S_OK; 00412 } 00413 00414 static HRESULT WINAPI OleInPlaceSiteWindowless_DiscardUndoState(IOleInPlaceSiteWindowless *iface) 00415 { 00416 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00417 FIXME("(%p) - stub\n", This); 00418 return E_NOTIMPL; 00419 } 00420 00421 static HRESULT WINAPI OleInPlaceSiteWindowless_DeactivateAndUndo(IOleInPlaceSiteWindowless *iface) 00422 { 00423 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00424 FIXME("(%p) - stub\n", This); 00425 return E_NOTIMPL; 00426 } 00427 00428 static HRESULT WINAPI OleInPlaceSiteWindowless_OnPosRectChange(IOleInPlaceSiteWindowless *iface, LPCRECT lprcPosRect) 00429 { 00430 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00431 FIXME("(%p,%p) - stub\n", This, lprcPosRect); 00432 return E_NOTIMPL; 00433 } 00434 00435 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceActivateEx( IOleInPlaceSiteWindowless *iface, BOOL* pfNoRedraw, DWORD dwFlags) 00436 { 00437 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00438 00439 TRACE("\n"); 00440 00441 This->fActive = This->fInPlace = TRUE; 00442 if ( dwFlags & ACTIVATE_WINDOWLESS ) 00443 This->fWindowless = TRUE; 00444 return S_OK; 00445 } 00446 00447 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceDeactivateEx( IOleInPlaceSiteWindowless *iface, BOOL fNoRedraw) 00448 { 00449 IOCS *This = impl_from_IOleInPlaceSiteWindowless(iface); 00450 00451 TRACE("\n"); 00452 00453 This->fActive = This->fInPlace = This->fWindowless = FALSE; 00454 return S_OK; 00455 } 00456 static HRESULT WINAPI OleInPlaceSiteWindowless_RequestUIActivate( IOleInPlaceSiteWindowless *iface) 00457 { 00458 FIXME("\n"); 00459 return E_NOTIMPL; 00460 } 00461 static HRESULT WINAPI OleInPlaceSiteWindowless_CanWindowlessActivate( IOleInPlaceSiteWindowless *iface) 00462 { 00463 FIXME("\n"); 00464 return S_OK; 00465 } 00466 static HRESULT WINAPI OleInPlaceSiteWindowless_GetCapture( IOleInPlaceSiteWindowless *iface) 00467 { 00468 FIXME("\n"); 00469 return E_NOTIMPL; 00470 } 00471 static HRESULT WINAPI OleInPlaceSiteWindowless_SetCapture( IOleInPlaceSiteWindowless *iface, BOOL fCapture) 00472 { 00473 FIXME("\n"); 00474 return E_NOTIMPL; 00475 } 00476 static HRESULT WINAPI OleInPlaceSiteWindowless_GetFocus( IOleInPlaceSiteWindowless *iface) 00477 { 00478 FIXME("\n"); 00479 return E_NOTIMPL; 00480 } 00481 static HRESULT WINAPI OleInPlaceSiteWindowless_SetFocus( IOleInPlaceSiteWindowless *iface, BOOL fFocus) 00482 { 00483 FIXME("\n"); 00484 return E_NOTIMPL; 00485 } 00486 static HRESULT WINAPI OleInPlaceSiteWindowless_GetDC( IOleInPlaceSiteWindowless *iface, LPCRECT pRect, DWORD grfFlags, HDC* phDC) 00487 { 00488 FIXME("\n"); 00489 return E_NOTIMPL; 00490 } 00491 static HRESULT WINAPI OleInPlaceSiteWindowless_ReleaseDC( IOleInPlaceSiteWindowless *iface, HDC hDC) 00492 { 00493 FIXME("\n"); 00494 return E_NOTIMPL; 00495 } 00496 static HRESULT WINAPI OleInPlaceSiteWindowless_InvalidateRect( IOleInPlaceSiteWindowless *iface, LPCRECT pRect, BOOL fErase) 00497 { 00498 FIXME("\n"); 00499 return E_NOTIMPL; 00500 } 00501 static HRESULT WINAPI OleInPlaceSiteWindowless_InvalidateRgn( IOleInPlaceSiteWindowless *iface, HRGN hRGN, BOOL fErase) 00502 { 00503 FIXME("\n"); 00504 return E_NOTIMPL; 00505 } 00506 static HRESULT WINAPI OleInPlaceSiteWindowless_ScrollRect( IOleInPlaceSiteWindowless *iface, INT dx, INT dy, LPCRECT pRectScroll, LPCRECT pRectClip) 00507 { 00508 FIXME("\n"); 00509 return E_NOTIMPL; 00510 } 00511 static HRESULT WINAPI OleInPlaceSiteWindowless_AdjustRect( IOleInPlaceSiteWindowless *iface, LPRECT prc) 00512 { 00513 FIXME("\n"); 00514 return E_NOTIMPL; 00515 } 00516 static HRESULT WINAPI OleInPlaceSiteWindowless_OnDefWindowMessage( IOleInPlaceSiteWindowless *iface, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult) 00517 { 00518 FIXME("\n"); 00519 return E_NOTIMPL; 00520 } 00521 00522 00523 /****** IOleInPlaceFrame *******/ 00524 static inline IOCS *impl_from_IOleInPlaceFrame(IOleInPlaceFrame *iface) 00525 { 00526 return CONTAINING_RECORD(iface, IOCS, IOleInPlaceFrame_iface); 00527 } 00528 00529 static HRESULT WINAPI OleInPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv) 00530 { 00531 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00532 return IOCS_QueryInterface(This, riid, ppv); 00533 } 00534 00535 static ULONG WINAPI OleInPlaceFrame_AddRef(IOleInPlaceFrame *iface) 00536 { 00537 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00538 return IOCS_AddRef(This); 00539 } 00540 00541 static ULONG WINAPI OleInPlaceFrame_Release(IOleInPlaceFrame *iface) 00542 { 00543 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00544 return IOCS_Release(This); 00545 } 00546 00547 static HRESULT WINAPI OleInPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phWnd) 00548 { 00549 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00550 00551 TRACE( "(%p,%p)\n", This, phWnd ); 00552 00553 *phWnd = This->hWnd; 00554 return S_OK; 00555 } 00556 00557 static HRESULT WINAPI OleInPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode) 00558 { 00559 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00560 00561 FIXME( "(%p,%d) - stub\n", This, fEnterMode ); 00562 return E_NOTIMPL; 00563 } 00564 00565 static HRESULT WINAPI OleInPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder) 00566 { 00567 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00568 00569 FIXME( "(%p,%p) - stub\n", This, lprectBorder ); 00570 return E_NOTIMPL; 00571 } 00572 00573 static HRESULT WINAPI OleInPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths) 00574 { 00575 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00576 00577 FIXME( "(%p,%p) - stub\n", This, pborderwidths ); 00578 return E_NOTIMPL; 00579 } 00580 00581 static HRESULT WINAPI OleInPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths) 00582 { 00583 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00584 00585 FIXME( "(%p,%p) - stub\n", This, pborderwidths ); 00586 return E_NOTIMPL; 00587 } 00588 00589 static HRESULT WINAPI OleInPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface, IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName) 00590 { 00591 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00592 00593 FIXME( "(%p,%p,%s) - stub\n", This, pActiveObject, debugstr_w(pszObjName) ); 00594 return S_OK; 00595 } 00596 00597 static HRESULT WINAPI OleInPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths) 00598 { 00599 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00600 00601 FIXME( "(%p,%p,%p) - stub\n", This, hmenuShared, lpMenuWidths ); 00602 return E_NOTIMPL; 00603 } 00604 00605 static HRESULT WINAPI OleInPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject) 00606 { 00607 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00608 00609 FIXME( "(%p,%p,%p,%p) - stub\n", This, hmenuShared, holemenu, hwndActiveObject ); 00610 return E_NOTIMPL; 00611 } 00612 00613 static HRESULT WINAPI OleInPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared) 00614 { 00615 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00616 00617 FIXME( "(%p, %p) - stub\n", This, hmenuShared ); 00618 return E_NOTIMPL; 00619 } 00620 00621 static HRESULT WINAPI OleInPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText) 00622 { 00623 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00624 00625 FIXME( "(%p, %s) - stub\n", This, debugstr_w( pszStatusText ) ); 00626 return E_NOTIMPL; 00627 } 00628 00629 static HRESULT WINAPI OleInPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable) 00630 { 00631 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00632 00633 FIXME( "(%p, %d) - stub\n", This, fEnable ); 00634 return E_NOTIMPL; 00635 } 00636 00637 static HRESULT WINAPI OleInPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID) 00638 { 00639 IOCS *This = impl_from_IOleInPlaceFrame(iface); 00640 00641 FIXME( "(%p, %p, %x) - stub\n", This, lpmsg, wID ); 00642 return E_NOTIMPL; 00643 } 00644 00645 00646 /****** IOleControlSite *******/ 00647 static inline IOCS *impl_from_IOleControlSite(IOleControlSite *iface) 00648 { 00649 return CONTAINING_RECORD(iface, IOCS, IOleControlSite_iface); 00650 } 00651 00652 static HRESULT WINAPI OleControlSite_QueryInterface(IOleControlSite *iface, REFIID riid, void **ppv) 00653 { 00654 IOCS *This = impl_from_IOleControlSite(iface); 00655 return IOCS_QueryInterface(This, riid, ppv); 00656 } 00657 00658 static ULONG WINAPI OleControlSite_AddRef(IOleControlSite *iface) 00659 { 00660 IOCS *This = impl_from_IOleControlSite(iface); 00661 return IOCS_AddRef(This); 00662 } 00663 00664 static ULONG WINAPI OleControlSite_Release(IOleControlSite *iface) 00665 { 00666 IOCS *This = impl_from_IOleControlSite(iface); 00667 return IOCS_Release(This); 00668 } 00669 00670 static HRESULT WINAPI OleControlSite_OnControlInfoChanged( IOleControlSite* This) 00671 { 00672 FIXME( "\n" ); 00673 return E_NOTIMPL; 00674 } 00675 static HRESULT WINAPI OleControlSite_LockInPlaceActive( IOleControlSite* This, BOOL fLock) 00676 { 00677 FIXME( "\n" ); 00678 return E_NOTIMPL; 00679 } 00680 static HRESULT WINAPI OleControlSite_GetExtendedControl( IOleControlSite* This, IDispatch** ppDisp) 00681 { 00682 FIXME( "\n" ); 00683 return E_NOTIMPL; 00684 } 00685 static HRESULT WINAPI OleControlSite_TransformCoords( IOleControlSite* This, POINTL* pPtlHimetric, POINTF* pPtfContainer, DWORD dwFlags) 00686 { 00687 FIXME( "\n" ); 00688 return E_NOTIMPL; 00689 } 00690 static HRESULT WINAPI OleControlSite_TranslateAccelerator( IOleControlSite* This, MSG* pMsg, DWORD grfModifiers) 00691 { 00692 FIXME( "\n" ); 00693 return E_NOTIMPL; 00694 } 00695 static HRESULT WINAPI OleControlSite_OnFocus( IOleControlSite* This, BOOL fGotFocus) 00696 { 00697 FIXME( "\n" ); 00698 return E_NOTIMPL; 00699 } 00700 static HRESULT WINAPI OleControlSite_ShowPropertyFrame( IOleControlSite* This) 00701 { 00702 FIXME( "\n" ); 00703 return E_NOTIMPL; 00704 } 00705 00706 00707 static const IOleClientSiteVtbl OleClientSite_vtbl = { 00708 OleClientSite_QueryInterface, 00709 OleClientSite_AddRef, 00710 OleClientSite_Release, 00711 OleClientSite_SaveObject, 00712 OleClientSite_GetMoniker, 00713 OleClientSite_GetContainer, 00714 OleClientSite_ShowObject, 00715 OleClientSite_OnShowWindow, 00716 OleClientSite_RequestNewObjectLayout 00717 }; 00718 static const IOleContainerVtbl OleContainer_vtbl = { 00719 OleContainer_QueryInterface, 00720 OleContainer_AddRef, 00721 OleContainer_Release, 00722 OleContainer_ParseDisplayName, 00723 OleContainer_EnumObjects, 00724 OleContainer_LockContainer 00725 }; 00726 static const IOleInPlaceSiteWindowlessVtbl OleInPlaceSiteWindowless_vtbl = { 00727 OleInPlaceSiteWindowless_QueryInterface, 00728 OleInPlaceSiteWindowless_AddRef, 00729 OleInPlaceSiteWindowless_Release, 00730 OleInPlaceSiteWindowless_GetWindow, 00731 OleInPlaceSiteWindowless_ContextSensitiveHelp, 00732 OleInPlaceSiteWindowless_CanInPlaceActivate, 00733 OleInPlaceSiteWindowless_OnInPlaceActivate, 00734 OleInPlaceSiteWindowless_OnUIActivate, 00735 OleInPlaceSiteWindowless_GetWindowContext, 00736 OleInPlaceSiteWindowless_Scroll, 00737 OleInPlaceSiteWindowless_OnUIDeactivate, 00738 OleInPlaceSiteWindowless_OnInPlaceDeactivate, 00739 OleInPlaceSiteWindowless_DiscardUndoState, 00740 OleInPlaceSiteWindowless_DeactivateAndUndo, 00741 OleInPlaceSiteWindowless_OnPosRectChange, 00742 OleInPlaceSiteWindowless_OnInPlaceActivateEx, 00743 OleInPlaceSiteWindowless_OnInPlaceDeactivateEx, 00744 OleInPlaceSiteWindowless_RequestUIActivate, 00745 OleInPlaceSiteWindowless_CanWindowlessActivate, 00746 OleInPlaceSiteWindowless_GetCapture, 00747 OleInPlaceSiteWindowless_SetCapture, 00748 OleInPlaceSiteWindowless_GetFocus, 00749 OleInPlaceSiteWindowless_SetFocus, 00750 OleInPlaceSiteWindowless_GetDC, 00751 OleInPlaceSiteWindowless_ReleaseDC, 00752 OleInPlaceSiteWindowless_InvalidateRect, 00753 OleInPlaceSiteWindowless_InvalidateRgn, 00754 OleInPlaceSiteWindowless_ScrollRect, 00755 OleInPlaceSiteWindowless_AdjustRect, 00756 OleInPlaceSiteWindowless_OnDefWindowMessage 00757 }; 00758 static const IOleInPlaceFrameVtbl OleInPlaceFrame_vtbl = 00759 { 00760 OleInPlaceFrame_QueryInterface, 00761 OleInPlaceFrame_AddRef, 00762 OleInPlaceFrame_Release, 00763 OleInPlaceFrame_GetWindow, 00764 OleInPlaceFrame_ContextSensitiveHelp, 00765 OleInPlaceFrame_GetBorder, 00766 OleInPlaceFrame_RequestBorderSpace, 00767 OleInPlaceFrame_SetBorderSpace, 00768 OleInPlaceFrame_SetActiveObject, 00769 OleInPlaceFrame_InsertMenus, 00770 OleInPlaceFrame_SetMenu, 00771 OleInPlaceFrame_RemoveMenus, 00772 OleInPlaceFrame_SetStatusText, 00773 OleInPlaceFrame_EnableModeless, 00774 OleInPlaceFrame_TranslateAccelerator 00775 }; 00776 static const IOleControlSiteVtbl OleControlSite_vtbl = 00777 { 00778 OleControlSite_QueryInterface, 00779 OleControlSite_AddRef, 00780 OleControlSite_Release, 00781 OleControlSite_OnControlInfoChanged, 00782 OleControlSite_LockInPlaceActive, 00783 OleControlSite_GetExtendedControl, 00784 OleControlSite_TransformCoords, 00785 OleControlSite_TranslateAccelerator, 00786 OleControlSite_OnFocus, 00787 OleControlSite_ShowPropertyFrame 00788 }; 00789 00790 static HRESULT IOCS_Detach( IOCS *This ) /* remove subclassing */ 00791 { 00792 if ( This->hWnd ) 00793 { 00794 SetWindowLongPtrW( This->hWnd, GWLP_WNDPROC, (ULONG_PTR) This->OrigWndProc ); 00795 SetWindowLongPtrW( This->hWnd, GWLP_USERDATA, 0 ); 00796 This->hWnd = NULL; 00797 } 00798 if ( This->control ) 00799 { 00800 IOleObject *control = This->control; 00801 00802 This->control = NULL; 00803 IOleObject_SetClientSite( control, NULL ); 00804 IOleObject_Release( control ); 00805 } 00806 return S_OK; 00807 } 00808 00809 static void IOCS_OnSize( IOCS* This, LPCRECT rect ) 00810 { 00811 SIZEL inPix, inHi; 00812 00813 This->size.left = rect->left; This->size.right = rect->right; This->size.top = rect->top; This->size.bottom = rect->bottom; 00814 00815 if ( !This->control ) 00816 return; 00817 00818 inPix.cx = rect->right - rect->left; 00819 inPix.cy = rect->bottom - rect->top; 00820 AtlPixelToHiMetric( &inPix, &inHi ); 00821 IOleObject_SetExtent( This->control, DVASPECT_CONTENT, &inHi ); 00822 00823 if ( This->fInPlace ) 00824 { 00825 IOleInPlaceObject *wl; 00826 00827 if ( SUCCEEDED( IOleObject_QueryInterface( This->control, &IID_IOleInPlaceObject, (void**)&wl ) ) ) 00828 { 00829 IOleInPlaceObject_SetObjectRects( wl, rect, rect ); 00830 IOleInPlaceObject_Release( wl ); 00831 } 00832 } 00833 } 00834 00835 static void IOCS_OnShow( IOCS *This, BOOL fShow ) 00836 { 00837 if (!This->control || This->fActive || !fShow ) 00838 return; 00839 00840 This->fActive = TRUE; 00841 } 00842 00843 static void IOCS_OnDraw( IOCS *This ) 00844 { 00845 IViewObject *view; 00846 00847 if ( !This->control || !This->fWindowless ) 00848 return; 00849 00850 if ( SUCCEEDED( IOleObject_QueryInterface( This->control, &IID_IViewObject, (void**)&view ) ) ) 00851 { 00852 HDC dc = GetDC( This->hWnd ); 00853 RECTL rect; 00854 00855 rect.left = This->size.left; rect.top = This->size.top; 00856 rect.bottom = This->size.bottom; rect.right = This->size.right; 00857 00858 IViewObject_Draw( view, DVASPECT_CONTENT, ~0, NULL, NULL, 0, dc, &rect, &rect, NULL, 0 ); 00859 IViewObject_Release( view ); 00860 ReleaseDC( This->hWnd, dc ); 00861 } 00862 } 00863 00864 static LRESULT IOCS_OnWndProc( IOCS *This, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 00865 { 00866 WNDPROC OrigWndProc = This->OrigWndProc; 00867 00868 switch( uMsg ) 00869 { 00870 case WM_DESTROY: 00871 IOCS_Detach( This ); 00872 break; 00873 case WM_SIZE: 00874 { 00875 RECT r; 00876 r.left = r.top = 0; 00877 r.right = LOWORD( lParam ); 00878 r.bottom = HIWORD( lParam ); 00879 IOCS_OnSize( This, &r ); 00880 } 00881 break; 00882 case WM_SHOWWINDOW: 00883 IOCS_OnShow( This, (BOOL) wParam ); 00884 break; 00885 case WM_PAINT: 00886 IOCS_OnDraw( This ); 00887 break; 00888 } 00889 00890 return CallWindowProcW( OrigWndProc, hWnd, uMsg, wParam, lParam ); 00891 } 00892 00893 static LRESULT CALLBACK AtlHost_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam ) 00894 { 00895 IOCS *This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA ); 00896 return IOCS_OnWndProc( This, hWnd, wMsg, wParam, lParam ); 00897 } 00898 00899 static HRESULT IOCS_Attach( IOCS *This, HWND hWnd, IUnknown *pUnkControl ) /* subclass hWnd */ 00900 { 00901 This->hWnd = hWnd; 00902 IUnknown_QueryInterface( pUnkControl, &IID_IOleObject, (void**)&This->control ); 00903 IOleObject_SetClientSite( This->control, &This->IOleClientSite_iface ); 00904 SetWindowLongPtrW( hWnd, GWLP_USERDATA, (ULONG_PTR) This ); 00905 This->OrigWndProc = (WNDPROC)SetWindowLongPtrW( hWnd, GWLP_WNDPROC, (ULONG_PTR) AtlHost_wndproc ); 00906 00907 return S_OK; 00908 } 00909 00910 static HRESULT IOCS_Init( IOCS *This ) 00911 { 00912 RECT rect; 00913 static const WCHAR AXWIN[] = {'A','X','W','I','N',0}; 00914 00915 IOleObject_SetHostNames( This->control, AXWIN, AXWIN ); 00916 00917 GetClientRect( This->hWnd, &rect ); 00918 IOCS_OnSize( This, &rect ); 00919 IOleObject_DoVerb( This->control, OLEIVERB_INPLACEACTIVATE, NULL, &This->IOleClientSite_iface, 00920 0, This->hWnd, &rect ); 00921 00922 return S_OK; 00923 } 00924 00925 /********************************************************************** 00926 * Create new instance of Atl host component and attach it to window * 00927 */ 00928 static HRESULT IOCS_Create( HWND hWnd, IUnknown *pUnkControl, IOCS **ppSite ) 00929 { 00930 HRESULT hr; 00931 IOCS *This; 00932 00933 *ppSite = NULL; 00934 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IOCS)); 00935 00936 if (!This) 00937 return E_OUTOFMEMORY; 00938 00939 This->IOleClientSite_iface.lpVtbl = &OleClientSite_vtbl; 00940 This->IOleContainer_iface.lpVtbl = &OleContainer_vtbl; 00941 This->IOleInPlaceSiteWindowless_iface.lpVtbl = &OleInPlaceSiteWindowless_vtbl; 00942 This->IOleInPlaceFrame_iface.lpVtbl = &OleInPlaceFrame_vtbl; 00943 This->IOleControlSite_iface.lpVtbl = &OleControlSite_vtbl; 00944 This->ref = 1; 00945 00946 This->OrigWndProc = NULL; 00947 This->hWnd = NULL; 00948 This->fWindowless = This->fActive = This->fInPlace = FALSE; 00949 00950 hr = IOCS_Attach( This, hWnd, pUnkControl ); 00951 if ( SUCCEEDED( hr ) ) 00952 hr = IOCS_Init( This ); 00953 if ( SUCCEEDED( hr ) ) 00954 *ppSite = This; 00955 else 00956 IOCS_Release( This ); 00957 00958 return hr; 00959 } 00960 00961 00962 /*********************************************************************** 00963 * AtlAxCreateControl [ATL.@] 00964 */ 00965 HRESULT WINAPI AtlAxCreateControl(LPCOLESTR lpszName, HWND hWnd, 00966 IStream *pStream, IUnknown **ppUnkContainer) 00967 { 00968 return AtlAxCreateControlEx( lpszName, hWnd, pStream, ppUnkContainer, 00969 NULL, NULL, NULL ); 00970 } 00971 00972 /*********************************************************************** 00973 * AtlAxCreateControlEx [ATL.@] 00974 * 00975 * REMARKS 00976 * See http://www.codeproject.com/com/cwebpage.asp for some background 00977 * 00978 */ 00979 HRESULT WINAPI AtlAxCreateControlEx(LPCOLESTR lpszName, HWND hWnd, 00980 IStream *pStream, IUnknown **ppUnkContainer, IUnknown **ppUnkControl, 00981 REFIID iidSink, IUnknown *punkSink) 00982 { 00983 CLSID controlId; 00984 HRESULT hRes; 00985 IOleObject *pControl; 00986 IUnknown *pUnkControl; 00987 IPersistStreamInit *pPSInit; 00988 IUnknown *pContainer; 00989 enum {IsGUID=0,IsHTML=1,IsURL=2} content; 00990 00991 TRACE("(%s %p %p %p %p %p %p)\n", debugstr_w(lpszName), hWnd, pStream, 00992 ppUnkContainer, ppUnkControl, iidSink, punkSink); 00993 00994 hRes = CLSIDFromString( lpszName, &controlId ); 00995 if ( FAILED(hRes) ) 00996 hRes = CLSIDFromProgID( lpszName, &controlId ); 00997 if ( SUCCEEDED( hRes ) ) 00998 content = IsGUID; 00999 else { 01000 /* FIXME - check for MSHTML: prefix! */ 01001 content = IsURL; 01002 controlId = CLSID_WebBrowser; 01003 } 01004 01005 hRes = CoCreateInstance( &controlId, 0, CLSCTX_ALL, &IID_IOleObject, 01006 (void**) &pControl ); 01007 if ( FAILED( hRes ) ) 01008 { 01009 WARN( "cannot create ActiveX control %s instance - error 0x%08x\n", 01010 debugstr_guid( &controlId ), hRes ); 01011 return hRes; 01012 } 01013 01014 hRes = IOleObject_QueryInterface( pControl, &IID_IPersistStreamInit, (void**) &pPSInit ); 01015 if ( SUCCEEDED( hRes ) ) 01016 { 01017 if (!pStream) 01018 IPersistStreamInit_InitNew( pPSInit ); 01019 else 01020 IPersistStreamInit_Load( pPSInit, pStream ); 01021 IPersistStreamInit_Release( pPSInit ); 01022 } else 01023 WARN("cannot get IID_IPersistStreamInit out of control\n"); 01024 01025 IOleObject_QueryInterface( pControl, &IID_IUnknown, (void**) &pUnkControl ); 01026 IOleObject_Release( pControl ); 01027 01028 01029 hRes = AtlAxAttachControl( pUnkControl, hWnd, &pContainer ); 01030 if ( FAILED( hRes ) ) 01031 WARN("cannot attach control to window\n"); 01032 01033 if ( content == IsURL ) 01034 { 01035 IWebBrowser2 *browser; 01036 01037 hRes = IOleObject_QueryInterface( pControl, &IID_IWebBrowser2, (void**) &browser ); 01038 if ( !browser ) 01039 WARN( "Cannot query IWebBrowser2 interface: %08x\n", hRes ); 01040 else { 01041 VARIANT url; 01042 01043 IWebBrowser2_put_Visible( browser, VARIANT_TRUE ); /* it seems that native does this on URL (but do not on MSHTML:! why? */ 01044 01045 V_VT(&url) = VT_BSTR; 01046 V_BSTR(&url) = SysAllocString( lpszName ); 01047 01048 hRes = IWebBrowser2_Navigate2( browser, &url, NULL, NULL, NULL, NULL ); 01049 if ( FAILED( hRes ) ) 01050 WARN( "IWebBrowser2::Navigate2 failed: %08x\n", hRes ); 01051 SysFreeString( V_BSTR(&url) ); 01052 01053 IWebBrowser2_Release( browser ); 01054 } 01055 } 01056 01057 if (ppUnkContainer) 01058 { 01059 *ppUnkContainer = pContainer; 01060 if ( pContainer ) 01061 IUnknown_AddRef( pContainer ); 01062 } 01063 if (ppUnkControl) 01064 { 01065 *ppUnkControl = pUnkControl; 01066 if ( pUnkControl ) 01067 IUnknown_AddRef( pUnkControl ); 01068 } 01069 01070 if ( pUnkControl ) 01071 IUnknown_Release( pUnkControl ); 01072 if ( pContainer ) 01073 IUnknown_Release( pContainer ); 01074 01075 return S_OK; 01076 } 01077 01078 /*********************************************************************** 01079 * AtlAxAttachControl [ATL.@] 01080 */ 01081 HRESULT WINAPI AtlAxAttachControl(IUnknown* pControl, HWND hWnd, IUnknown** ppUnkContainer) 01082 { 01083 IOCS *pUnkContainer; 01084 HRESULT hr; 01085 01086 TRACE( "%p %p %p\n", pControl, hWnd, ppUnkContainer ); 01087 01088 if (!pControl) 01089 return E_INVALIDARG; 01090 01091 hr = IOCS_Create( hWnd, pControl, &pUnkContainer ); 01092 if ( SUCCEEDED( hr ) && ppUnkContainer) 01093 { 01094 *ppUnkContainer = (IUnknown*) pUnkContainer; 01095 } 01096 01097 if(!hWnd) 01098 return S_FALSE; 01099 01100 return hr; 01101 } 01102 01103 /********************************************************************** 01104 * Helper function for AX_ConvertDialogTemplate 01105 */ 01106 static inline BOOL advance_array(WORD **pptr, DWORD *palloc, DWORD *pfilled, const WORD *data, DWORD size) 01107 { 01108 if ( (*pfilled + size) > *palloc ) 01109 { 01110 *palloc = ((*pfilled+size) + 0xFF) & ~0xFF; 01111 *pptr = HeapReAlloc( GetProcessHeap(), 0, *pptr, *palloc * sizeof(WORD) ); 01112 if (!*pptr) 01113 return FALSE; 01114 } 01115 RtlMoveMemory( *pptr+*pfilled, data, size * sizeof(WORD) ); 01116 *pfilled += size; 01117 return TRUE; 01118 } 01119 01120 /********************************************************************** 01121 * Convert ActiveX control templates to AtlAxWin class instances 01122 */ 01123 static LPDLGTEMPLATEW AX_ConvertDialogTemplate(LPCDLGTEMPLATEW src_tmpl) 01124 { 01125 #define GET_WORD(x) (*(const WORD *)(x)) 01126 #define GET_DWORD(x) (*(const DWORD *)(x)) 01127 #define PUT_BLOCK(x,y) do {if (!advance_array(&output, &allocated, &filled, (x), (y))) return NULL;} while (0) 01128 #define PUT_WORD(x) do {WORD w = (x);PUT_BLOCK(&w, 1);} while(0) 01129 #define PUT_DWORD(x) do {DWORD w = (x);PUT_BLOCK(&w, 2);} while(0) 01130 const WORD *tmp, *src = (const WORD *)src_tmpl; 01131 WORD *output; 01132 DWORD allocated, filled; /* in WORDs */ 01133 BOOL ext; 01134 WORD signature, dlgver, rescount; 01135 DWORD style; 01136 01137 filled = 0; allocated = 256; 01138 output = HeapAlloc( GetProcessHeap(), 0, allocated * sizeof(WORD) ); 01139 if (!output) 01140 return NULL; 01141 01142 /* header */ 01143 tmp = src; 01144 signature = GET_WORD(src); 01145 dlgver = GET_WORD(src + 1); 01146 if (signature == 1 && dlgver == 0xFFFF) 01147 { 01148 ext = TRUE; 01149 src += 6; 01150 style = GET_DWORD(src); 01151 src += 2; 01152 rescount = GET_WORD(src++); 01153 src += 4; 01154 if ( GET_WORD(src) == 0xFFFF ) /* menu */ 01155 src += 2; 01156 else 01157 src += strlenW(src) + 1; 01158 if ( GET_WORD(src) == 0xFFFF ) /* class */ 01159 src += 2; 01160 else 01161 src += strlenW(src) + 1; 01162 src += strlenW(src) + 1; /* title */ 01163 if ( style & (DS_SETFONT | DS_SHELLFONT) ) 01164 { 01165 src += 3; 01166 src += strlenW(src) + 1; 01167 } 01168 } else { 01169 ext = FALSE; 01170 style = GET_DWORD(src); 01171 src += 4; 01172 rescount = GET_WORD(src++); 01173 src += 4; 01174 if ( GET_WORD(src) == 0xFFFF ) /* menu */ 01175 src += 2; 01176 else 01177 src += strlenW(src) + 1; 01178 if ( GET_WORD(src) == 0xFFFF ) /* class */ 01179 src += 2; 01180 else 01181 src += strlenW(src) + 1; 01182 src += strlenW(src) + 1; /* title */ 01183 if ( style & DS_SETFONT ) 01184 { 01185 src++; 01186 src += strlenW(src) + 1; 01187 } 01188 } 01189 PUT_BLOCK(tmp, src-tmp); 01190 01191 while(rescount--) 01192 { 01193 src = (const WORD *)( ( ((ULONG_PTR)src) + 3) & ~3); /* align on DWORD boundary */ 01194 filled = (filled + 1) & ~1; /* depends on DWORD-aligned allocation unit */ 01195 01196 tmp = src; 01197 if (ext) 01198 src += 12; 01199 else 01200 src += 9; 01201 PUT_BLOCK(tmp, src-tmp); 01202 01203 tmp = src; 01204 if ( GET_WORD(src) == 0xFFFF ) /* class */ 01205 { 01206 src += 2; 01207 } else 01208 { 01209 src += strlenW(src) + 1; 01210 } 01211 src += strlenW(src) + 1; /* title */ 01212 if ( GET_WORD(tmp) == '{' ) /* all this mess created because of this line */ 01213 { 01214 static const WCHAR AtlAxWin[] = {'A','t','l','A','x','W','i','n', 0}; 01215 PUT_BLOCK(AtlAxWin, sizeof(AtlAxWin)/sizeof(WCHAR)); 01216 PUT_BLOCK(tmp, strlenW(tmp)+1); 01217 } else 01218 PUT_BLOCK(tmp, src-tmp); 01219 01220 if ( GET_WORD(src) ) 01221 { 01222 WORD size = (GET_WORD(src)+sizeof(WORD)-1) / sizeof(WORD); /* quite ugly :( Maybe use BYTE* instead of WORD* everywhere ? */ 01223 PUT_BLOCK(src, size); 01224 src+=size; 01225 } 01226 else 01227 { 01228 PUT_WORD(0); 01229 src++; 01230 } 01231 } 01232 return (LPDLGTEMPLATEW) output; 01233 } 01234 01235 /*********************************************************************** 01236 * AtlAxCreateDialogA [ATL.@] 01237 * 01238 * Creates a dialog window 01239 * 01240 * PARAMS 01241 * hInst [I] Application instance 01242 * name [I] Dialog box template name 01243 * owner [I] Dialog box parent HWND 01244 * dlgProc [I] Dialog box procedure 01245 * param [I] This value will be passed to dlgProc as WM_INITDIALOG's message lParam 01246 * 01247 * RETURNS 01248 * Window handle of dialog window. 01249 */ 01250 HWND WINAPI AtlAxCreateDialogA(HINSTANCE hInst, LPCSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param) 01251 { 01252 HWND res = NULL; 01253 int length; 01254 WCHAR *nameW; 01255 01256 if (IS_INTRESOURCE(name)) 01257 return AtlAxCreateDialogW( hInst, (LPCWSTR) name, owner, dlgProc, param ); 01258 01259 length = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 ); 01260 nameW = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) ); 01261 if (nameW) 01262 { 01263 MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, length ); 01264 res = AtlAxCreateDialogW( hInst, nameW, owner, dlgProc, param ); 01265 HeapFree( GetProcessHeap(), 0, nameW ); 01266 } 01267 return res; 01268 } 01269 01270 /*********************************************************************** 01271 * AtlAxCreateDialogW [ATL.@] 01272 * 01273 * See AtlAxCreateDialogA 01274 * 01275 */ 01276 HWND WINAPI AtlAxCreateDialogW(HINSTANCE hInst, LPCWSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param) 01277 { 01278 HRSRC hrsrc; 01279 HGLOBAL hgl; 01280 LPCDLGTEMPLATEW ptr; 01281 LPDLGTEMPLATEW newptr; 01282 HWND res; 01283 01284 TRACE("(%p %s %p %p %lx)\n", hInst, debugstr_w(name), owner, dlgProc, param); 01285 01286 hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ); 01287 if ( !hrsrc ) 01288 return NULL; 01289 hgl = LoadResource (hInst, hrsrc); 01290 if ( !hgl ) 01291 return NULL; 01292 ptr = LockResource ( hgl ); 01293 if (!ptr) 01294 { 01295 FreeResource( hgl ); 01296 return NULL; 01297 } 01298 newptr = AX_ConvertDialogTemplate( ptr ); 01299 if ( newptr ) 01300 { 01301 res = CreateDialogIndirectParamW( hInst, newptr, owner, dlgProc, param ); 01302 HeapFree( GetProcessHeap(), 0, newptr ); 01303 } else 01304 res = NULL; 01305 FreeResource ( hrsrc ); 01306 return res; 01307 } 01308 01309 /*********************************************************************** 01310 * AtlAxGetHost [ATL.@] 01311 * 01312 */ 01313 HRESULT WINAPI AtlAxGetHost(HWND hWnd, IUnknown **pUnk) 01314 { 01315 IOCS *This; 01316 01317 TRACE( "(%p, %p)\n", hWnd, pUnk ); 01318 01319 *pUnk = NULL; 01320 01321 This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA ); 01322 if ( !This ) 01323 { 01324 WARN("No container attached to %p\n", hWnd ); 01325 return E_FAIL; 01326 } 01327 01328 return IOCS_QueryInterface( This, &IID_IUnknown, (void**) pUnk ); 01329 } 01330 01331 /*********************************************************************** 01332 * AtlAxGetControl [ATL.@] 01333 * 01334 */ 01335 HRESULT WINAPI AtlAxGetControl(HWND hWnd, IUnknown **pUnk) 01336 { 01337 IOCS *This; 01338 01339 TRACE( "(%p, %p)\n", hWnd, pUnk ); 01340 01341 *pUnk = NULL; 01342 01343 This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA ); 01344 if ( !This || !This->control ) 01345 { 01346 WARN("No control attached to %p\n", hWnd ); 01347 return E_FAIL; 01348 } 01349 01350 return IOleObject_QueryInterface( This->control, &IID_IUnknown, (void**) pUnk ); 01351 } Generated on Sun May 27 2012 04:22:47 for ReactOS by
1.7.6.1
|