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.0 KiB

  1. //
  2. // FileChooser.h
  3. //
  4. #ifndef _FILE_CHOOSER_H
  5. #define _FILE_CHOOSER_H
  6. #pragma warning(disable : 4275)
  7. #if _MSC_VER > 1000
  8. #pragma once
  9. #endif // _MSC_VER > 1000
  10. class CFileChooser;
  11. class CFileChooserEdit;
  12. class CFilterEntry
  13. {
  14. public:
  15. CFilterEntry()
  16. {
  17. }
  18. CFilterEntry(LPCTSTR text, LPCTSTR ext)
  19. : m_text(text), m_ext(ext)
  20. {
  21. }
  22. CString m_text;
  23. CString m_ext;
  24. };
  25. #define FC_UNDEFINED 0x00000000
  26. #define FC_FORWRITE 0x00000001
  27. #define FC_AUTOCOMPLETION 0x00000002
  28. // Put "*.ext" to edit initially if no file with default
  29. // extensions was found in the initial directory
  30. #define FC_WILDCARD_DEFAULT 0x00000004
  31. // Set "description (*.ext)" to FileDialog filter
  32. #define FC_WILDCARD_DESC 0x00000008
  33. // prefill the path edit with default file name
  34. #define FC_PREPARE_DEFAULT 0x00000010
  35. // supress file existance check
  36. #define FC_PATH_CHECK 0x00000020
  37. // Check if entered filename with any of default extensions
  38. // are available in the current directory. If yes, choose it
  39. #define FC_CHECK_FILENAME_ONLY 0x00000040
  40. #define FC_DIRECTORY_ONLY 0x00000080
  41. #define FC_HIDEREADONLY 0x00000100
  42. #define FC_COMMANDLINE 0x00000200
  43. #define FC_DEFAULT\
  44. FC_AUTOCOMPLETION | FC_WILDCARD_DESC | FC_WILDCARD_DEFAULT | FC_PATH_CHECK
  45. #define FC_DEFAULT_READ\
  46. FC_DEFAULT | FC_HIDEREADONLY
  47. #define FC_DEFAULT_WRITE\
  48. FC_DEFAULT | FC_FORWRITE
  49. #define FC_SUCCESS 0x00000000
  50. #define FC_FILE_DOES_NOT_EXIST 0x00000001
  51. #define FC_FILENAME_IS_DIRECTORY 0x00000002
  52. #define FC_FILENAME_IS_FILE 0x00000003
  53. #define FC_TEXT_IS_INVALID 0x00000004
  54. #define FC_WRONG_FORMAT 0x00000005
  55. #define FC_NO_CLOSING_QUOTE 0x00000006
  56. class _EXPORT CFileChooser :
  57. public CWindowImpl<CFileChooser>
  58. {
  59. friend class CFileChooserButton;
  60. public:
  61. CFileChooser()
  62. : m_pParent(NULL),
  63. m_bDoReplaceFile(FALSE),
  64. m_bEditDirty(FALSE),
  65. m_bTextValid(TRUE),
  66. m_bDialogActive(FALSE),
  67. m_bInternalChange(FALSE),
  68. m_dwStyle(FC_UNDEFINED),
  69. m_ofn_Flags(0),
  70. m_edit(this, 1),
  71. m_button(this, 2)
  72. {
  73. }
  74. ~CFileChooser()
  75. {
  76. }
  77. BEGIN_MSG_MAP(CFileChooser)
  78. ALT_MSG_MAP(1)
  79. MESSAGE_HANDLER(WM_CHAR, OnEditChar)
  80. MESSAGE_HANDLER(WM_SETFOCUS, OnEditSetFocus)
  81. MESSAGE_HANDLER(WM_KILLFOCUS, OnEditKillFocus)
  82. REFLECT_NOTIFICATIONS()
  83. ALT_MSG_MAP(2)
  84. MESSAGE_HANDLER(BM_SETSTATE, OnSetBrowseState)
  85. END_MSG_MAP()
  86. BOOL Init(CWindow * pParent, DWORD dwStyle, UINT idEdit, UINT idButton);
  87. DWORD GetStyle() const
  88. {
  89. return m_dwStyle;
  90. }
  91. DWORD SetStyle(DWORD dwStyle)
  92. {
  93. DWORD dw = m_dwStyle;
  94. m_dwStyle = dwStyle;
  95. return dw;
  96. }
  97. BOOL StyleBitSet(DWORD bit)
  98. {
  99. return 0 != (m_dwStyle & bit);
  100. }
  101. BOOL OpenForRead()
  102. {
  103. return !StyleBitSet(FC_FORWRITE);
  104. }
  105. void AddStyle(DWORD dwStyle)
  106. {
  107. m_dwStyle |= dwStyle;
  108. }
  109. void RemoveStyle(DWORD dwStyle)
  110. {
  111. m_dwStyle &= ~dwStyle;
  112. }
  113. void SetOfnFlags(DWORD flags)
  114. {
  115. m_ofn_Flags = flags;
  116. }
  117. DWORD GetOfnFlags()
  118. {
  119. return m_ofn_Flags;
  120. }
  121. void SetDialogTitle(LPCTSTR strTitle)
  122. {
  123. m_strTitle = strTitle;
  124. }
  125. DWORD GetFileName(CString& str);
  126. void SetPath(const CString& str);
  127. void AddExtension(LPCTSTR text, LPCTSTR ext);
  128. void AddExtension(HINSTANCE hInst, UINT idText, UINT idExt);
  129. int BrowseForFolderCallback(HWND hwnd, UINT uMsg, LPARAM lParam);
  130. void OnEditChange();
  131. void OnPaste();
  132. protected:
  133. void OnBrowseBtn();
  134. void CreateFilter(CString& strFilter, CString& strDefExt);
  135. void CreateDefaultPathForRead();
  136. BOOL BrowseForFile(CString& strPath, CString& strFile);
  137. BOOL BrowseForFolder(CString& strPath);
  138. LRESULT OnEditChar(UINT nMsg, WPARAM, LPARAM, BOOL&);
  139. LRESULT OnEditSetFocus(UINT nMsg, WPARAM, LPARAM, BOOL&);
  140. LRESULT OnEditKillFocus(UINT nMsg, WPARAM, LPARAM, BOOL&);
  141. LRESULT OnSetBrowseState(UINT nMsg, WPARAM, LPARAM, BOOL&);
  142. // LRESULT OnEditPaste(UINT nMsg, WPARAM, LPARAM, BOOL&);
  143. LRESULT OnEditCommand(UINT nMsg, WPARAM, LPARAM, BOOL&);
  144. BOOL HasEditFocus();
  145. BOOL IsValidChar(UINT nChar, BOOL bExcludeWildcards = TRUE);
  146. BOOL IsValidPath(LPCTSTR);
  147. void SetCompactedPath(LPCTSTR path);
  148. void SetPathToEdit(LPCTSTR path);
  149. int ExtractPath(LPTSTR path);
  150. int ExtractArgs(LPTSTR buf);
  151. void GetText(LPTSTR buf);
  152. int GetFilterIndex(const CString& fileName);
  153. protected:
  154. DWORD m_ofn_Flags;
  155. CWindow * m_pParent;
  156. CContainedWindow m_edit;
  157. CContainedWindow m_button;
  158. DWORD m_dwStyle;
  159. CString m_strPath;
  160. LPTSTR m_pPathTemp;
  161. CString m_strTitle;
  162. std::list<CFilterEntry> m_ext;
  163. BOOL m_bDoReplaceFile;
  164. BOOL m_bEditDirty;
  165. BOOL m_bTextValid;
  166. BOOL m_bDialogActive;
  167. BOOL m_bInternalChange;
  168. };
  169. #endif //_FILE_CHOOSER_H