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.

132 lines
4.5 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: amcdocmg.cpp
  7. *
  8. * Contents: Implementation file for CAMCDocManager
  9. *
  10. * History: 01-Jan-98 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #include "stdafx.h"
  14. #include "amcdocmg.h"
  15. #include "amc.h" // for AMCGetApp
  16. #include "filedlgex.h"
  17. void AppendFilterSuffix(CString& filter, OPENFILENAME_NT4& ofn,
  18. CDocTemplate* pTemplate, CString* pstrDefaultExt);
  19. /*--------------------------------------------------------------------------*
  20. * CAMCDocManager::DoPromptFileName
  21. *
  22. * We need to override this so we can set the default directory. The MFC
  23. * implementation lets the system choose the default, which due to a NT5.0
  24. * change, is not always the current directory. This implementation specifically
  25. * requests the current directory.
  26. *--------------------------------------------------------------------------*/
  27. // This and the following method were copied from MFC sources because we needed
  28. // to modify the internal handling of the file dialog options. The added code
  29. // sections are commented (MMC change).
  30. BOOL CAMCDocManager::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate)
  31. {
  32. //
  33. // MMC change: Set the default directory (sets to admin tools the first time called)
  34. //
  35. CAMCApp* pApp = AMCGetApp();
  36. pApp->SetDefaultDirectory ();
  37. CFileDialogEx dlgFile(bOpenFileDialog);
  38. CString title;
  39. VERIFY(title.LoadString(nIDSTitle)); // this uses MFC's LoadString because that is where the string resides.
  40. dlgFile.m_ofn.Flags |= (lFlags | OFN_ENABLESIZING);
  41. CString strFilter;
  42. CString strDefault;
  43. if (pTemplate != NULL)
  44. {
  45. ASSERT_VALID(pTemplate);
  46. AppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate, &strDefault);
  47. }
  48. else
  49. {
  50. // do for all doc template
  51. POSITION pos = m_templateList.GetHeadPosition();
  52. BOOL bFirst = TRUE;
  53. while (pos != NULL)
  54. {
  55. CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
  56. AppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate,
  57. bFirst ? &strDefault : NULL);
  58. bFirst = FALSE;
  59. }
  60. }
  61. // append the "*.*" all files filter
  62. CString allFilter;
  63. VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER)); // this uses MFC's LoadString because that is where the string resides.
  64. strFilter += allFilter;
  65. strFilter += (TCHAR)'\0'; // next string please
  66. strFilter += _T("*.*");
  67. strFilter += (TCHAR)'\0'; // last string
  68. dlgFile.m_ofn.nMaxCustFilter++;
  69. dlgFile.m_ofn.lpstrFilter = strFilter;
  70. dlgFile.m_ofn.lpstrTitle = title;
  71. dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH);
  72. //
  73. // MMC change: Set the initial dir to the current dir
  74. //
  75. TCHAR szDir[_MAX_PATH];
  76. GetCurrentDirectory(countof(szDir), szDir);
  77. dlgFile.m_ofn.lpstrInitialDir = szDir;
  78. BOOL bResult = dlgFile.DoModal() == IDOK ? TRUE : FALSE;
  79. fileName.ReleaseBuffer();
  80. return bResult;
  81. }
  82. void AppendFilterSuffix(CString& filter, OPENFILENAME_NT4& ofn,
  83. CDocTemplate* pTemplate, CString* pstrDefaultExt)
  84. {
  85. ASSERT_VALID(pTemplate);
  86. ASSERT_KINDOF(CDocTemplate, pTemplate);
  87. CString strFilterExt, strFilterName;
  88. if (pTemplate->GetDocString(strFilterExt, CDocTemplate::filterExt) &&
  89. !strFilterExt.IsEmpty() &&
  90. pTemplate->GetDocString(strFilterName, CDocTemplate::filterName) &&
  91. !strFilterName.IsEmpty())
  92. {
  93. // a file based document template - add to filter list
  94. ASSERT(strFilterExt[0] == '.');
  95. if (pstrDefaultExt != NULL)
  96. {
  97. // set the default extension
  98. *pstrDefaultExt = ((LPCTSTR)strFilterExt) + 1; // skip the '.'
  99. ofn.lpstrDefExt = (LPTSTR)(LPCTSTR)(*pstrDefaultExt);
  100. ofn.nFilterIndex = ofn.nMaxCustFilter + 1; // 1 based number
  101. }
  102. // add to filter
  103. filter += strFilterName;
  104. ASSERT(!filter.IsEmpty()); // must have a file type name
  105. filter += (TCHAR)'\0'; // next string please
  106. filter += (TCHAR)'*';
  107. filter += strFilterExt;
  108. filter += (TCHAR)'\0'; // next string please
  109. ofn.nMaxCustFilter++;
  110. }
  111. }