Source code of Windows XP (NT5)
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.

178 lines
3.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 2000.
  5. //
  6. // File: CommonDialog.cpp
  7. //
  8. // Contents: implementation of CCommonDialog
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "commondialog.h"
  13. HWND _VariantToHWND(const VARIANT& varOwner); // passportmanager.cpp
  14. //
  15. // ICommonDialog Interface
  16. //
  17. STDMETHODIMP CCommonDialog::get_Filter(BSTR* pbstrFilter)
  18. {
  19. if (!pbstrFilter)
  20. return E_POINTER;
  21. *pbstrFilter = _strFilter.Copy();
  22. return S_OK;
  23. }
  24. STDMETHODIMP CCommonDialog::put_Filter(BSTR bstrFilter)
  25. {
  26. _strFilter = bstrFilter;
  27. return S_OK;
  28. }
  29. STDMETHODIMP CCommonDialog::get_FilterIndex(UINT *puiFilterIndex)
  30. {
  31. if (!puiFilterIndex)
  32. return E_POINTER;
  33. *puiFilterIndex = _dwFilterIndex;
  34. return S_OK;
  35. }
  36. STDMETHODIMP CCommonDialog::put_FilterIndex(UINT uiFilterIndex)
  37. {
  38. _dwFilterIndex = uiFilterIndex;
  39. return S_OK;
  40. }
  41. STDMETHODIMP CCommonDialog::get_FileName(BSTR* pbstrFileName)
  42. {
  43. if (!pbstrFileName)
  44. return E_POINTER;
  45. *pbstrFileName = _strFileName.Copy();
  46. return S_OK;
  47. }
  48. STDMETHODIMP CCommonDialog::put_FileName(BSTR bstrFileName)
  49. {
  50. _strFileName = bstrFileName;
  51. return S_OK;
  52. }
  53. STDMETHODIMP CCommonDialog::get_Flags(UINT *puiFlags)
  54. {
  55. if (!puiFlags)
  56. return E_POINTER;
  57. *puiFlags = _dwFlags;
  58. return S_OK;
  59. }
  60. STDMETHODIMP CCommonDialog::put_Flags(UINT uiFlags)
  61. {
  62. _dwFlags = uiFlags;
  63. return S_OK;
  64. }
  65. STDMETHODIMP CCommonDialog::put_Owner(VARIANT varOwner)
  66. {
  67. HRESULT hr = E_INVALIDARG;
  68. _hwndOwner = _VariantToHWND(varOwner);
  69. if (_hwndOwner)
  70. hr = S_OK;
  71. return hr;
  72. }
  73. STDMETHODIMP CCommonDialog::get_InitialDir(BSTR* pbstrInitialDir)
  74. {
  75. if (!pbstrInitialDir)
  76. return E_POINTER;
  77. *pbstrInitialDir = _strInitialDir.Copy();
  78. return S_OK;
  79. }
  80. STDMETHODIMP CCommonDialog::put_InitialDir(BSTR bstrInitialDir)
  81. {
  82. _strInitialDir = bstrInitialDir;
  83. return S_OK;
  84. }
  85. STDMETHODIMP CCommonDialog::ShowOpen(VARIANT_BOOL *pbSuccess)
  86. {
  87. OPENFILENAMEW ofn = { 0 };
  88. WCHAR szFileName[MAX_PATH];
  89. // Null characters can't be passed through script, so we separated
  90. // name filter string combinations with the '|' character.
  91. // The CommDlg32 api expects name/filter pairs to be separated by
  92. // a null character, and the entire string to be double
  93. // null terminated.
  94. // copy the filter string (plus one for double null at the end)
  95. CComBSTR strFilter(_strFilter.Length()+1, _strFilter);
  96. if (strFilter)
  97. {
  98. LPWSTR pch;
  99. int cch = lstrlenW(strFilter);
  100. for (pch = strFilter; cch > 0; ++pch, --cch)
  101. {
  102. if ( *pch == L'|' )
  103. {
  104. *pch = L'\0';
  105. }
  106. }
  107. // Double null terminate the string
  108. ++pch;
  109. *pch = L'\0';
  110. }
  111. // copy the initial file name, if any
  112. if (_strFileName)
  113. {
  114. lstrcpynW(szFileName, _strFileName, ARRAYSIZE(szFileName));
  115. }
  116. else
  117. {
  118. szFileName[0] = L'\0';
  119. }
  120. // set the struct members
  121. ofn.lStructSize = SIZEOF(ofn);
  122. ofn.hwndOwner = _hwndOwner;
  123. ofn.lpstrFilter = strFilter;
  124. ofn.nFilterIndex = _dwFilterIndex;
  125. ofn.lpstrFile = szFileName;
  126. ofn.nMaxFile = ARRAYSIZE(szFileName);
  127. ofn.lpstrInitialDir = _strInitialDir;
  128. ofn.Flags = _dwFlags;
  129. // make the call
  130. if (GetOpenFileNameW(&ofn))
  131. {
  132. _strFileName = szFileName;
  133. *pbSuccess = VARIANT_TRUE;
  134. }
  135. else
  136. {
  137. *pbSuccess = VARIANT_FALSE;
  138. }
  139. return S_OK;
  140. }