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.

338 lines
13 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. getfname.hxx
  7. Header file for GET_FNAME_BASE_DLG class.
  8. The class hierarchy is the following:
  9. BASE
  10. |
  11. GET_FNAME_BASE_DLG
  12. / \
  13. GET_OPEN_FILENAME_DLG GET_SAVE_FILENAME_DLG
  14. COMMON_DLG - provide GetError methods
  15. GET_FNAME_BASE_DLG - provide methods to set up the OPENFILENAME
  16. data structure
  17. GET_OPEN_FILENAME_DLG - call GetOpenFileName API
  18. GET_SAVE_FILENAME_DLG - call GetSaveFileName API
  19. FILE HISTORY:
  20. terryk 03-Dec-1991 Created
  21. terryk 06-Jan-1992 Code review changed
  22. chuckc 08-Aug-1992 fixed for Unicode (commdlg now Unicode)
  23. */
  24. #ifndef _GETFNAME_HXX_
  25. #define _GETFNAME_HXX_
  26. #include <commdlg.h>
  27. #include <dlgs.h> // for cmb1 ( Type Combo CID )
  28. // for comdlg32.dll
  29. typedef BOOL (*PF_GetOpenFileNameA) (LPOPENFILENAMEA);
  30. typedef BOOL (*PF_GetOpenFileNameW) (LPOPENFILENAMEW);
  31. typedef BOOL (*PF_GetSaveFileNameA) (LPOPENFILENAMEA);
  32. typedef BOOL (*PF_GetSaveFileNameW) (LPOPENFILENAMEW);
  33. typedef DWORD (*PF_ExtendedError) (VOID);
  34. #ifdef UNICODE
  35. #define PF_GetOpenFileName PF_GetOpenFileNameW
  36. #define PF_GetSaveFileName PF_GetSaveFileNameW
  37. #define GETOPENFILENAME_NAME "GetOpenFileNameW"
  38. #define GETSAVEFILENAME_NAME "GetSaveFileNameW"
  39. #else
  40. #define PF_GetOpenFileName PF_GetOpenFileNameA
  41. #define PF_GetSaveFileName PF_GetSaveFileNameA
  42. #define GETOPENFILENAME_NAME "GetOpenFileNameA"
  43. #define GETSAVEFILENAME_NAME "GetSaveFileNameA"
  44. #endif
  45. #define EXTENDEDERROR_NAME "CommDlgExtendedError"
  46. #define COMDLG32_DLL_NAME SZ("COMDLG32.DLL")
  47. /* Turn on/off the FIELD on VAR depended on the FLAG */
  48. #define SET_FLAG( VAR, FLAG, FIELD ) \
  49. VAR = (( FLAG ) ? VAR | FIELD : VAR & ~( FIELD ))
  50. /*************************************************************************
  51. NAME: GET_FNAME_BASE_DLG
  52. SYNOPSIS: Base class for GET_OPEN_FILENAME_DLG and
  53. GET_SAVE_FILENAME_DLG.
  54. It provides a set of functions for the callers to set up
  55. the OPENFILENAME data structure.
  56. INTERFACE:
  57. GET_FNAME_BASE_DLG() - constructor
  58. SetFilter() - set the dialog filter strings. It must
  59. follows this format:
  60. { "Write Files(*.TXT)","*.txt",
  61. "Word Files(*.TXT)","*.doc;*.txt",
  62. "" }
  63. SetCustomFIlter() - custom filter string list. It must
  64. follow the same format as in SetFilter function.
  65. SetInitialDir() - set the initial directory
  66. SetText() - set the dialog box title
  67. SetMultiSelect() - allow multiple selection
  68. SetCreatePrompt() - if file does not exist, it will
  69. popup a create prompt.
  70. SetFileMustExist() - Display a warning message if the
  71. file does not exist.
  72. SetDisplayReadOnlyBox() - display the read only box and
  73. let the user check the check box.
  74. SetNoChangeDir() - no change directory after dismiss the
  75. dialog box.
  76. SetPathMustExist() - display a warning message if the
  77. path does not exist.
  78. SetShowHelpButton() - display the help button
  79. SetFileExtension() - Set the default extension. The
  80. GetOpenFileName and GetSaveFileName functions append
  81. this extension to the filename if the user fails to
  82. enter an extension. This string may be any length
  83. but only the first three characters are appended.
  84. The string should not contain a period ".". If this
  85. member is NULL and the user fails to enter an
  86. extension, no extension is appended.
  87. SetHookProc() - specifies the hooked call back function
  88. and set the enable hook flag in the OPENFILENAME data
  89. structure.
  90. CheckReadOnlyBox() - set the check box in the read only
  91. box.
  92. QueryFilterIndex() - Specifies an index into the buffer
  93. pointed to by the lpstrFilter member. The system
  94. uses the index value to obtain a pair of strings to
  95. use as the initial filter description and filter
  96. pattern for the dialog box. The first pair of
  97. strings has an index value of 1. When the user
  98. dismisses the dialog box, the system copies the
  99. index of the selected filter strings into his
  100. location. If the nFilterIndex member is 0, the
  101. custom filter will be used. If the nFilterIndex
  102. member is 0 and the Custom filter is NULL, the
  103. system uses the first filter in the buffer
  104. identified by the Filter member. If all three
  105. members are 0 or NULL, the system does not use any
  106. filters and does not show any files in the file list
  107. control of the dialog box.
  108. QueryFilename() - return the user selected filename.
  109. QueryFileTitle() - return the user selected file title (
  110. filename without drive and path information. )
  111. IsCheckReadOnlyBox() - return TRUE if the read only box
  112. is checked.
  113. QueryFileOffset() -specifies a zero-based offset from
  114. the beginning of the pathname to the filename in the
  115. string at which filename points. For example, if
  116. filename points to the following strings,
  117. "c:\dir1\dir2\file.ext", this member will contain
  118. the value 13.
  119. QueryFileExtensionOffset() - specifies a zero base
  120. offset from the beginning of the pathname to the
  121. filename extension in the string at which filename
  122. points. For example, if filename points to the
  123. following string, "c:\dir1\dir2\file.ext", this
  124. member will contain the value 18. If the user did
  125. not enter an extension and the default extension is
  126. NULL, this member specifies an offset to the NULL
  127. terminator. If the user entered "." as the last
  128. character in the filename, this member will specify
  129. 0.
  130. PARENT: BASE
  131. USES: OPENFILENAME, BUFFER
  132. NOTES:
  133. It is the parent class of GET_OPEN_FILENAME_DLG and
  134. GET_SAVE_FILENAME_DLG.
  135. (beng, 31 jul 92) Terry wrote this class so that you could
  136. specify an alternate template name. Since that code was never
  137. used and never tested, and since it makes correct dllization
  138. more difficult, I've disabled it (and removed the option from
  139. all ctors).
  140. HISTORY:
  141. terryk 04-Dec-1991 Created
  142. beng 30-Mar-1992 CHAR/TCHAR mapping
  143. beng 31-Jul-1992 Hacked out template arg
  144. **************************************************************************/
  145. DLL_CLASS GET_FNAME_BASE_DLG : public BASE
  146. {
  147. private:
  148. HINSTANCE _hComdlg32Dll;
  149. PF_GetOpenFileName _pfGetOpenFileName; // for load dll.
  150. PF_GetSaveFileName _pfGetSaveFileName;
  151. PF_ExtendedError _pfExtendedError;
  152. BUFFER _bufFilename; // buffer for receiving the filename
  153. BUFFER _bufFilenameTitle; // buffer for receiving the file title (
  154. // filename without the path and drive
  155. // information )
  156. BUFFER _bufFilter;
  157. BUFFER _bufCustomFilter;
  158. NLS_STR _nlsHelpFile;
  159. ULONG _ulHelpContext;
  160. BOOL _fHelpActive;
  161. APIERR SetStringField(TCHAR **ppszDest, const NLS_STR & nlsArg);
  162. protected:
  163. OPENFILENAME _ofn; // Open Filename data structure
  164. BOOL _fInitOfn; // mark whether init'd
  165. TCHAR _szFileExt[MAXPATHLEN+1]; // Place to store the file extension
  166. VOID SetEnableHook( BOOL fEnableHook = TRUE )
  167. { SET_FLAG( _ofn.Flags, fEnableHook, OFN_ENABLEHOOK ); }
  168. #if 0
  169. VOID SetEnableTemplate( BOOL fEnableTemplate = TRUE )
  170. { SET_FLAG( _ofn.Flags, fEnableTemplate, OFN_ENABLETEMPLATEHANDLE ); }
  171. #endif
  172. VOID InitialOFN();
  173. APIERR SetBuffer( BUFFER * pBuf, STRLIST & strFilter );
  174. GET_FNAME_BASE_DLG( OWNER_WINDOW *pow,
  175. const TCHAR *pszHelpFile = NULL,
  176. ULONG ulHelpContext = 0 );
  177. ~GET_FNAME_BASE_DLG();
  178. OPENFILENAME *QueryOFN()
  179. { return &_ofn; }
  180. APIERR QueryErrorCode() const;
  181. public:
  182. PF_GetOpenFileName pfGetOpenFileName () const
  183. { return _pfGetOpenFileName; }
  184. PF_GetSaveFileName pfGetSaveFileName () const
  185. { return _pfGetSaveFileName; }
  186. PF_ExtendedError pfExtendedError () const
  187. { return _pfExtendedError;}
  188. APIERR SetFilter( STRLIST & slFilter, DWORD nFilterIndex = 0 );
  189. APIERR SetCustomFilter( STRLIST & slFilter, DWORD nFilterIndex = 0 );
  190. APIERR SetInitialDir( const NLS_STR &nlsDir );
  191. APIERR SetText( const NLS_STR &nlsText );
  192. APIERR SetFileExtension( const NLS_STR & nlsExt );
  193. VOID SetMultiSelect( BOOL fMultiSelect = TRUE )
  194. { SET_FLAG( _ofn.Flags, fMultiSelect, OFN_ALLOWMULTISELECT ); }
  195. VOID SetCreatePrompt( BOOL fCreatePrompt = TRUE )
  196. { SET_FLAG( _ofn.Flags, fCreatePrompt, OFN_CREATEPROMPT ); }
  197. VOID SetFileMustExist( BOOL fMustExist = TRUE )
  198. { SET_FLAG( _ofn.Flags, fMustExist, OFN_FILEMUSTEXIST ); }
  199. VOID SetDisplayReadOnlyBox( BOOL fDisplay = FALSE )
  200. { SET_FLAG( _ofn.Flags, !fDisplay, OFN_HIDEREADONLY ); }
  201. VOID SetNoChangeDir( BOOL fNoChange =TRUE )
  202. { SET_FLAG( _ofn.Flags, fNoChange, OFN_NOCHANGEDIR ); }
  203. VOID SetPathMustExist( BOOL fMustExist = TRUE )
  204. { SET_FLAG( _ofn.Flags, fMustExist, OFN_PATHMUSTEXIST ); }
  205. VOID SetShowHelpButton( BOOL fHelp = TRUE )
  206. { SET_FLAG( _ofn.Flags, fHelp, OFN_SHOWHELP ); }
  207. VOID SetHookProc( MFARPROC lpfnHook );
  208. VOID CheckReadOnlyBox( BOOL fCheck = TRUE )
  209. { SET_FLAG( _ofn.Flags, fCheck, OFN_READONLY ); }
  210. DWORD QueryFilterIndex() const
  211. { return _ofn.nFilterIndex; }
  212. APIERR QueryFilename( NLS_STR *pnlsFilename ) const;
  213. APIERR QueryFileTitle( NLS_STR *pnlsFileTitle ) const;
  214. BOOL IsCheckReadOnlyBox() const
  215. { return ( _ofn.Flags | OFN_READONLY ) != 0 ; }
  216. WORD QueryFileOffset() const
  217. { return _ofn.nFileOffset; }
  218. WORD QueryFileExtensionOffset() const
  219. { return _ofn.nFileExtension; }
  220. NLS_STR *QueryHelpFile( VOID )
  221. { return &_nlsHelpFile; }
  222. ULONG QueryHelpContext( VOID )
  223. { return _ulHelpContext; }
  224. VOID SetHelpActive( BOOL fActive )
  225. { _fHelpActive = fActive; }
  226. BOOL IsHelpActive( VOID )
  227. { return _fHelpActive; }
  228. virtual APIERR Process( BOOL *pfRetVal ) = 0;
  229. VOID OnHelp( HWND hwnd );
  230. };
  231. /*************************************************************************
  232. NAME: GET_OPEN_FILENAME_DLG
  233. SYNOPSIS: call windows' GetOpenFileName API and get the filename.
  234. INTERFACE:
  235. GET_OPEN_FILENAME_DLG() - constructor
  236. Process() - start the dialog box
  237. PARENT: GET_FNAME_BASE_DLG
  238. HISTORY:
  239. terryk 04-Dec-1991 Created
  240. beng 31-Jul-1992 Hacked out template arg
  241. **************************************************************************/
  242. DLL_CLASS GET_OPEN_FILENAME_DLG: public GET_FNAME_BASE_DLG
  243. {
  244. public:
  245. GET_OPEN_FILENAME_DLG( OWNER_WINDOW *pow,
  246. const TCHAR *pszHelpFile = NULL,
  247. ULONG ulHelpContext = 0 );
  248. virtual APIERR Process( BOOL *pfRetVal = NULL );
  249. };
  250. /*************************************************************************
  251. NAME: GET_SAVE_FILENAME_DLG
  252. SYNOPSIS: call windows' API GetSaveFileName and return the user
  253. selected filename.
  254. INTERFACE:
  255. GET_SAVE_FILENAME_DLG() - constructor
  256. Process() - start the dialog box
  257. SetOverWritePrompt() - cause the dialog box to generate
  258. a message box if the selected file already exists.
  259. The user must confirm whether to overwrite the
  260. file.
  261. PARENT: GET_FNAME_BASE_DLG
  262. HISTORY:
  263. terryk 04-Dec-1991 Created
  264. beng 31-Jul-1992 Hacked out template arg
  265. **************************************************************************/
  266. DLL_CLASS GET_SAVE_FILENAME_DLG: public GET_FNAME_BASE_DLG
  267. {
  268. public:
  269. GET_SAVE_FILENAME_DLG( OWNER_WINDOW *pow,
  270. const TCHAR *pszHelpFile = NULL,
  271. ULONG ulHelpContext = 0 );
  272. virtual APIERR Process( BOOL *pfRetVal = NULL );
  273. VOID SetOverWritePrompt( BOOL fOverWrite = TRUE )
  274. { SET_FLAG( _ofn.Flags, fOverWrite, OFN_OVERWRITEPROMPT ); }
  275. };
  276. #endif // _GETFNAME_HXX_