Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.8 KiB

  1. #include "priv.h"
  2. #include "wvcoord.h"
  3. HRESULT GetObjectFromContainer(IDispatch *pdispContainer, LPOLESTR poleName, IDispatch **ppdisp)
  4. {
  5. HRESULT hr = E_FAIL;
  6. *ppdisp = NULL;
  7. if (pdispContainer && poleName)
  8. {
  9. DISPID dispID;
  10. // Get the object dispid from the container
  11. if (SUCCEEDED(pdispContainer->GetIDsOfNames(IID_NULL, &poleName, 1, 0, &dispID)))
  12. {
  13. DISPPARAMS dp = {0};
  14. EXCEPINFO ei = {0};
  15. VARIANTARG va;
  16. if (SUCCEEDED((pdispContainer->Invoke(dispID, IID_NULL, 0, DISPATCH_PROPERTYGET, &dp, &va, &ei, NULL))
  17. && va.vt == VT_DISPATCH))
  18. {
  19. *ppdisp = va.pdispVal;
  20. hr = S_OK;
  21. }
  22. }
  23. }
  24. return hr;
  25. }
  26. // Get punkObject.style property
  27. HRESULT FindObjectStyle(IUnknown *punkObject, CComPtr<IHTMLStyle>& spStyle)
  28. {
  29. HRESULT hr = E_FAIL;
  30. CComPtr<IDispatch> spdispObject, spdispObjectOuter, spdispObjectStyle;
  31. if (SUCCEEDED(punkObject->QueryInterface(IID_PPV_ARG(IDispatch, &spdispObject)))
  32. && SUCCEEDED(spdispObject->QueryInterface(IID_PPV_ARG(IDispatch, &spdispObjectOuter)))
  33. && SUCCEEDED(GetObjectFromContainer(spdispObjectOuter, OLESTR("style"), &spdispObjectStyle))
  34. && SUCCEEDED(spdispObjectStyle->QueryInterface(IID_PPV_ARG(IHTMLStyle, &spStyle))))
  35. {
  36. hr = S_OK;
  37. }
  38. return hr;
  39. }
  40. BOOL IsRTLDocument(CComPtr<IHTMLDocument2>& spHTMLDocument)
  41. {
  42. BOOL bRet = FALSE;
  43. CComPtr<IHTMLDocument3> spHTMLDocument3;
  44. CComBSTR bstrDir;
  45. if (spHTMLDocument && SUCCEEDED(spHTMLDocument->QueryInterface(IID_IHTMLDocument3, (void **)&spHTMLDocument3))
  46. && SUCCEEDED(spHTMLDocument3->get_dir(&bstrDir)) && bstrDir && (StrCmpIW(bstrDir, L"RTL") == 0))
  47. {
  48. bRet = TRUE;
  49. }
  50. return bRet;
  51. }
  52. //
  53. // How many ways are there to get a DC?
  54. //
  55. // 1. If the site supports IOleInPlaceSiteWindowless, we can get the DC
  56. // via IOleInPlaceSiteWindowless::GetDC and give it back with ReleaseDC.
  57. //
  58. // 2. If the site supports any of the GetWindow interfaces, we get its
  59. // window and ask USER for the DC.
  60. //
  61. // 3. If we can't get any of that stuff, then we just get a screen DC
  62. // (special case where the associated window is NULL).
  63. //
  64. // Note! This function tries really really hard to get the DC. You
  65. // should use it only for informational purposes, not for drawing.
  66. //
  67. STDAPI_(HDC) IUnknown_GetDC(IUnknown *punk, LPCRECT prc, PGETDCSTATE pdcs)
  68. {
  69. HRESULT hr = E_FAIL;
  70. HDC hdc = NULL;
  71. ZeroMemory(pdcs, sizeof(PGETDCSTATE));
  72. if (punk &&
  73. SUCCEEDED(punk->QueryInterface(IID_PPV_ARG(IOleInPlaceSiteWindowless, &pdcs->pipsw))))
  74. {
  75. hr = pdcs->pipsw->GetDC(prc, OLEDC_NODRAW, &hdc);
  76. if (FAILED(hr))
  77. {
  78. ATOMICRELEASE(pdcs->pipsw);
  79. }
  80. }
  81. if (FAILED(hr))
  82. {
  83. // This will null out the hwnd on failure, which is what we want!
  84. IUnknown_GetWindow(punk, &pdcs->hwnd);
  85. hdc = GetDC(pdcs->hwnd);
  86. }
  87. return hdc;
  88. }
  89. STDAPI_(void) IUnknown_ReleaseDC(HDC hdc, PGETDCSTATE pdcs)
  90. {
  91. if (pdcs->pipsw)
  92. {
  93. pdcs->pipsw->ReleaseDC(hdc);
  94. ATOMICRELEASE(pdcs->pipsw);
  95. }
  96. else
  97. ReleaseDC(pdcs->hwnd, hdc);
  98. }
  99. DWORD FormatMessageWrapW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageID, DWORD dwLangID, LPWSTR pwzBuffer, DWORD cchSize, ...)
  100. {
  101. va_list vaParamList;
  102. va_start(vaParamList, cchSize);
  103. DWORD dwResult = FormatMessageW(dwFlags, lpSource, dwMessageID, dwLangID, pwzBuffer, cchSize, &vaParamList);
  104. va_end(vaParamList);
  105. return dwResult;
  106. }
  107. // for LoadLibrary/GetProcAddress on SHGetDiskFreeSpaceA
  108. typedef BOOL (__stdcall * PFNSHGETDISKFREESPACEA)(LPCSTR pszVolume, ULARGE_INTEGER *pqwFreeCaller, ULARGE_INTEGER *pqwTot,
  109. ULARGE_INTEGER *pqwFree);
  110. HRESULT _ComputeFreeSpace(LPCWSTR pszFileName, ULONGLONG& ullFreeSpace,
  111. ULONGLONG& ullUsedSpace, ULONGLONG& ullTotalSpace)
  112. {
  113. ULARGE_INTEGER qwFreeCaller; // use this for free space -- this will take into account disk quotas and such on NT
  114. ULARGE_INTEGER qwTotal;
  115. ULARGE_INTEGER qwFree; // unused
  116. CHAR szFileNameA[MAX_PATH];
  117. static PFNSHGETDISKFREESPACEA pfnSHGetDiskFreeSpaceA = NULL;
  118. SHUnicodeToAnsi(pszFileName, szFileNameA, MAX_PATH);
  119. // Load the function the first time
  120. if (pfnSHGetDiskFreeSpaceA == NULL)
  121. {
  122. HINSTANCE hinstShell32 = LoadLibrary(TEXT("SHELL32.DLL"));
  123. if (hinstShell32)
  124. pfnSHGetDiskFreeSpaceA = (PFNSHGETDISKFREESPACEA)GetProcAddress(hinstShell32, "SHGetDiskFreeSpaceA");
  125. }
  126. // Compute free & total space and check for valid results.
  127. // If you have a function pointer call SHGetDiskFreeSpaceA
  128. if (pfnSHGetDiskFreeSpaceA && pfnSHGetDiskFreeSpaceA(szFileNameA, &qwFreeCaller, &qwTotal, &qwFree))
  129. {
  130. ullFreeSpace = qwFreeCaller.QuadPart;
  131. ullTotalSpace = qwTotal.QuadPart;
  132. ullUsedSpace = ullTotalSpace - ullFreeSpace;
  133. if (EVAL((ullTotalSpace > 0) && (ullFreeSpace <= ullTotalSpace)))
  134. return S_OK;
  135. }
  136. return E_FAIL;
  137. }
  138. //--------------- Win95 Wraps for W versions of functions used by ATL -----//
  139. //-------------------------------------------------------------------------//
  140. #ifdef wsprintfWrapW
  141. #undef wsprintfWrapW
  142. #endif //wsprintfWrapW
  143. int WINAPIV wsprintfWrapW(OUT LPWSTR pwszOut, IN LPCWSTR pwszFormat, ...)
  144. {
  145. int cchRet;
  146. va_list arglist;
  147. va_start( arglist, pwszFormat );
  148. cchRet = wvsprintfWrapW( pwszOut, pwszFormat, arglist );
  149. va_end( arglist );
  150. return cchRet;
  151. }