filedlg.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/filedlg.h
  3. // Purpose: wxFileDialog base header
  4. // Author: Robert Roebling
  5. // Modified by:
  6. // Created: 8/17/99
  7. // Copyright: (c) Robert Roebling
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_FILEDLG_H_BASE_
  11. #define _WX_FILEDLG_H_BASE_
  12. #include "wx/defs.h"
  13. #if wxUSE_FILEDLG
  14. #include "wx/dialog.h"
  15. #include "wx/arrstr.h"
  16. // this symbol is defined for the platforms which support multiple
  17. // ('|'-separated) filters in the file dialog
  18. #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
  19. #define wxHAS_MULTIPLE_FILEDLG_FILTERS
  20. #endif
  21. //----------------------------------------------------------------------------
  22. // wxFileDialog data
  23. //----------------------------------------------------------------------------
  24. /*
  25. The flags below must coexist with the following flags in m_windowStyle
  26. #define wxCAPTION 0x20000000
  27. #define wxMAXIMIZE 0x00002000
  28. #define wxCLOSE_BOX 0x00001000
  29. #define wxSYSTEM_MENU 0x00000800
  30. wxBORDER_NONE = 0x00200000
  31. #define wxRESIZE_BORDER 0x00000040
  32. */
  33. enum
  34. {
  35. wxFD_OPEN = 0x0001,
  36. wxFD_SAVE = 0x0002,
  37. wxFD_OVERWRITE_PROMPT = 0x0004,
  38. wxFD_FILE_MUST_EXIST = 0x0010,
  39. wxFD_MULTIPLE = 0x0020,
  40. wxFD_CHANGE_DIR = 0x0080,
  41. wxFD_PREVIEW = 0x0100
  42. };
  43. #if WXWIN_COMPATIBILITY_2_6
  44. enum
  45. {
  46. wxOPEN = wxFD_OPEN,
  47. wxSAVE = wxFD_SAVE,
  48. wxOVERWRITE_PROMPT = wxFD_OVERWRITE_PROMPT,
  49. wxFILE_MUST_EXIST = wxFD_FILE_MUST_EXIST,
  50. wxMULTIPLE = wxFD_MULTIPLE,
  51. wxCHANGE_DIR = wxFD_CHANGE_DIR
  52. };
  53. #endif
  54. #define wxFD_DEFAULT_STYLE wxFD_OPEN
  55. extern WXDLLIMPEXP_DATA_CORE(const char) wxFileDialogNameStr[];
  56. extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorPromptStr[];
  57. extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr[];
  58. //----------------------------------------------------------------------------
  59. // wxFileDialogBase
  60. //----------------------------------------------------------------------------
  61. class WXDLLIMPEXP_CORE wxFileDialogBase: public wxDialog
  62. {
  63. public:
  64. wxFileDialogBase () { Init(); }
  65. wxFileDialogBase(wxWindow *parent,
  66. const wxString& message = wxFileSelectorPromptStr,
  67. const wxString& defaultDir = wxEmptyString,
  68. const wxString& defaultFile = wxEmptyString,
  69. const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
  70. long style = wxFD_DEFAULT_STYLE,
  71. const wxPoint& pos = wxDefaultPosition,
  72. const wxSize& sz = wxDefaultSize,
  73. const wxString& name = wxFileDialogNameStr)
  74. {
  75. Init();
  76. Create(parent, message, defaultDir, defaultFile, wildCard, style, pos, sz, name);
  77. }
  78. virtual ~wxFileDialogBase() {}
  79. bool Create(wxWindow *parent,
  80. const wxString& message = wxFileSelectorPromptStr,
  81. const wxString& defaultDir = wxEmptyString,
  82. const wxString& defaultFile = wxEmptyString,
  83. const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
  84. long style = wxFD_DEFAULT_STYLE,
  85. const wxPoint& pos = wxDefaultPosition,
  86. const wxSize& sz = wxDefaultSize,
  87. const wxString& name = wxFileDialogNameStr);
  88. bool HasFdFlag(int flag) const { return HasFlag(flag); }
  89. virtual void SetMessage(const wxString& message) { m_message = message; }
  90. virtual void SetPath(const wxString& path);
  91. virtual void SetDirectory(const wxString& dir);
  92. virtual void SetFilename(const wxString& name);
  93. virtual void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
  94. virtual void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
  95. virtual wxString GetMessage() const { return m_message; }
  96. virtual wxString GetPath() const { return m_path; }
  97. virtual void GetPaths(wxArrayString& paths) const { paths.Empty(); paths.Add(m_path); }
  98. virtual wxString GetDirectory() const { return m_dir; }
  99. virtual wxString GetFilename() const { return m_fileName; }
  100. virtual void GetFilenames(wxArrayString& files) const { files.Empty(); files.Add(m_fileName); }
  101. virtual wxString GetWildcard() const { return m_wildCard; }
  102. virtual int GetFilterIndex() const { return m_filterIndex; }
  103. virtual wxString GetCurrentlySelectedFilename() const
  104. { return m_currentlySelectedFilename; }
  105. // this function is called with wxFileDialog as parameter and should
  106. // create the window containing the extra controls we want to show in it
  107. typedef wxWindow *(*ExtraControlCreatorFunction)(wxWindow*);
  108. virtual bool SupportsExtraControl() const { return false; }
  109. bool SetExtraControlCreator(ExtraControlCreatorFunction creator);
  110. wxWindow *GetExtraControl() const { return m_extraControl; }
  111. // Utility functions
  112. #if WXWIN_COMPATIBILITY_2_6
  113. wxDEPRECATED( long GetStyle() const );
  114. wxDEPRECATED( void SetStyle(long style) );
  115. #endif // WXWIN_COMPATIBILITY_2_6
  116. // Append first extension to filePath from a ';' separated extensionList
  117. // if filePath = "path/foo.bar" just return it as is
  118. // if filePath = "foo[.]" and extensionList = "*.jpg;*.png" return "foo.jpg"
  119. // if the extension is "*.j?g" (has wildcards) or "jpg" then return filePath
  120. static wxString AppendExtension(const wxString &filePath,
  121. const wxString &extensionList);
  122. protected:
  123. wxString m_message;
  124. wxString m_dir;
  125. wxString m_path; // Full path
  126. wxString m_fileName;
  127. wxString m_wildCard;
  128. int m_filterIndex;
  129. // Currently selected, but not yet necessarily accepted by the user, file.
  130. // This should be updated whenever the selection in the control changes by
  131. // the platform-specific code to provide a useful implementation of
  132. // GetCurrentlySelectedFilename().
  133. wxString m_currentlySelectedFilename;
  134. wxWindow* m_extraControl;
  135. // returns true if control is created (if it already exists returns false)
  136. bool CreateExtraControl();
  137. // return true if SetExtraControlCreator() was called
  138. bool HasExtraControlCreator() const
  139. { return m_extraControlCreator != NULL; }
  140. // get the size of the extra control by creating and deleting it
  141. wxSize GetExtraControlSize();
  142. private:
  143. ExtraControlCreatorFunction m_extraControlCreator;
  144. void Init();
  145. DECLARE_DYNAMIC_CLASS(wxFileDialogBase)
  146. wxDECLARE_NO_COPY_CLASS(wxFileDialogBase);
  147. };
  148. //----------------------------------------------------------------------------
  149. // wxFileDialog convenience functions
  150. //----------------------------------------------------------------------------
  151. // File selector - backward compatibility
  152. WXDLLIMPEXP_CORE wxString
  153. wxFileSelector(const wxString& message = wxFileSelectorPromptStr,
  154. const wxString& default_path = wxEmptyString,
  155. const wxString& default_filename = wxEmptyString,
  156. const wxString& default_extension = wxEmptyString,
  157. const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
  158. int flags = 0,
  159. wxWindow *parent = NULL,
  160. int x = wxDefaultCoord, int y = wxDefaultCoord);
  161. // An extended version of wxFileSelector
  162. WXDLLIMPEXP_CORE wxString
  163. wxFileSelectorEx(const wxString& message = wxFileSelectorPromptStr,
  164. const wxString& default_path = wxEmptyString,
  165. const wxString& default_filename = wxEmptyString,
  166. int *indexDefaultExtension = NULL,
  167. const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
  168. int flags = 0,
  169. wxWindow *parent = NULL,
  170. int x = wxDefaultCoord, int y = wxDefaultCoord);
  171. // Ask for filename to load
  172. WXDLLIMPEXP_CORE wxString
  173. wxLoadFileSelector(const wxString& what,
  174. const wxString& extension,
  175. const wxString& default_name = wxEmptyString,
  176. wxWindow *parent = NULL);
  177. // Ask for filename to save
  178. WXDLLIMPEXP_CORE wxString
  179. wxSaveFileSelector(const wxString& what,
  180. const wxString& extension,
  181. const wxString& default_name = wxEmptyString,
  182. wxWindow *parent = NULL);
  183. #if defined (__WXUNIVERSAL__)
  184. #define wxHAS_GENERIC_FILEDIALOG
  185. #include "wx/generic/filedlgg.h"
  186. #elif defined(__WXMSW__)
  187. #include "wx/msw/filedlg.h"
  188. #elif defined(__WXMOTIF__)
  189. #include "wx/motif/filedlg.h"
  190. #elif defined(__WXGTK20__)
  191. #include "wx/gtk/filedlg.h" // GTK+ > 2.4 has native version
  192. #elif defined(__WXGTK__)
  193. #include "wx/gtk1/filedlg.h"
  194. #elif defined(__WXMAC__)
  195. #include "wx/osx/filedlg.h"
  196. #elif defined(__WXCOCOA__)
  197. #include "wx/cocoa/filedlg.h"
  198. #elif defined(__WXPM__)
  199. #include "wx/os2/filedlg.h"
  200. #endif
  201. #endif // wxUSE_FILEDLG
  202. #endif // _WX_FILEDLG_H_BASE_