filepicker.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/filedirpicker.h
  3. // Purpose: wxFileButton, wxDirButton header
  4. // Author: Francesco Montorsi
  5. // Modified by:
  6. // Created: 14/4/2006
  7. // Copyright: (c) Francesco Montorsi
  8. // Licence: wxWindows Licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GTK_FILEPICKER_H_
  11. #define _WX_GTK_FILEPICKER_H_
  12. // since GtkColorButton is available only for GTK+ >= 2.4,
  13. // we need to use generic versions if we detect (at runtime)
  14. // that GTK+ < 2.4
  15. #include "wx/generic/filepickerg.h"
  16. //-----------------------------------------------------------------------------
  17. // wxFileButton and wxDirButton shared code
  18. // (cannot be a base class since they need to derive from wxGenericFileButton
  19. // and from wxGenericDirButton classes !)
  20. //-----------------------------------------------------------------------------
  21. #define FILEDIRBTN_OVERRIDES \
  22. /* NULL is because of a problem with destruction order which happens */ \
  23. /* if we pass GetParent(): in fact, this GTK native implementation */ \
  24. /* needs to create the dialog in ::Create() and not for each user */ \
  25. /* request in response to the user click as the generic implementation */ \
  26. /* does. */ \
  27. virtual wxWindow *GetDialogParent() \
  28. { \
  29. return NULL; \
  30. } \
  31. \
  32. /* even if wx derive from wxGenericFileButton, i.e. from wxButton, our */ \
  33. /* native GTK+ widget does not derive from GtkButton thus *all* uses */ \
  34. /* GTK_BUTTON(m_widget) macro done by wxButton must be bypassed to */ \
  35. /* avoid bunch of GTK+ warnings like: */ \
  36. /* invalid cast from `GtkFileChooserButton' to `GtkButton' */ \
  37. /* so, override wxButton::GTKGetWindow and return NULL as GTK+ doesn't */ \
  38. /* give us access to the internal GdkWindow of a GtkFileChooserButton */ \
  39. protected: \
  40. virtual GdkWindow * \
  41. GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const \
  42. { return NULL; }
  43. //-----------------------------------------------------------------------------
  44. // wxFileButton
  45. //-----------------------------------------------------------------------------
  46. class WXDLLIMPEXP_CORE wxFileButton : public wxGenericFileButton
  47. {
  48. public:
  49. wxFileButton() { Init(); }
  50. wxFileButton(wxWindow *parent,
  51. wxWindowID id,
  52. const wxString& label = wxFilePickerWidgetLabel,
  53. const wxString &path = wxEmptyString,
  54. const wxString &message = wxFileSelectorPromptStr,
  55. const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
  56. const wxPoint& pos = wxDefaultPosition,
  57. const wxSize& size = wxDefaultSize,
  58. long style = wxFILEBTN_DEFAULT_STYLE,
  59. const wxValidator& validator = wxDefaultValidator,
  60. const wxString& name = wxFilePickerWidgetNameStr)
  61. {
  62. Init();
  63. m_pickerStyle = style;
  64. Create(parent, id, label, path, message, wildcard,
  65. pos, size, style, validator, name);
  66. }
  67. virtual ~wxFileButton();
  68. public: // overrides
  69. bool Create(wxWindow *parent,
  70. wxWindowID id,
  71. const wxString& label = wxFilePickerWidgetLabel,
  72. const wxString &path = wxEmptyString,
  73. const wxString &message = wxFileSelectorPromptStr,
  74. const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
  75. const wxPoint& pos = wxDefaultPosition,
  76. const wxSize& size = wxDefaultSize,
  77. long style = 0,
  78. const wxValidator& validator = wxDefaultValidator,
  79. const wxString& name = wxFilePickerWidgetNameStr);
  80. // event handler for the click
  81. void OnDialogOK(wxCommandEvent &);
  82. virtual void SetPath(const wxString &str);
  83. virtual void SetInitialDirectory(const wxString& dir);
  84. // see macro defined above
  85. FILEDIRBTN_OVERRIDES
  86. protected:
  87. wxDialog *m_dialog;
  88. private:
  89. // common part of all ctors
  90. void Init() { m_dialog = NULL; }
  91. DECLARE_DYNAMIC_CLASS(wxFileButton)
  92. };
  93. //-----------------------------------------------------------------------------
  94. // wxDirButton
  95. //-----------------------------------------------------------------------------
  96. class WXDLLIMPEXP_CORE wxDirButton : public wxGenericDirButton
  97. {
  98. public:
  99. wxDirButton() { Init(); }
  100. wxDirButton(wxWindow *parent,
  101. wxWindowID id,
  102. const wxString& label = wxFilePickerWidgetLabel,
  103. const wxString &path = wxEmptyString,
  104. const wxString &message = wxFileSelectorPromptStr,
  105. const wxPoint& pos = wxDefaultPosition,
  106. const wxSize& size = wxDefaultSize,
  107. long style = wxDIRBTN_DEFAULT_STYLE,
  108. const wxValidator& validator = wxDefaultValidator,
  109. const wxString& name = wxFilePickerWidgetNameStr)
  110. {
  111. Init();
  112. m_pickerStyle = style;
  113. Create(parent, id, label, path, message, wxEmptyString,
  114. pos, size, style, validator, name);
  115. }
  116. virtual ~wxDirButton();
  117. public: // overrides
  118. bool Create(wxWindow *parent,
  119. wxWindowID id,
  120. const wxString& label = wxFilePickerWidgetLabel,
  121. const wxString &path = wxEmptyString,
  122. const wxString &message = wxFileSelectorPromptStr,
  123. const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
  124. const wxPoint& pos = wxDefaultPosition,
  125. const wxSize& size = wxDefaultSize,
  126. long style = 0,
  127. const wxValidator& validator = wxDefaultValidator,
  128. const wxString& name = wxFilePickerWidgetNameStr);
  129. // GtkFileChooserButton does not support GTK_FILE_CHOOSER_CREATE_FOLDER
  130. // thus we must ensure that the wxDD_DIR_MUST_EXIST style was given
  131. long GetDialogStyle() const
  132. {
  133. return (wxGenericDirButton::GetDialogStyle() | wxDD_DIR_MUST_EXIST);
  134. }
  135. virtual void SetPath(const wxString &str);
  136. virtual void SetInitialDirectory(const wxString& dir);
  137. // see macro defined above
  138. FILEDIRBTN_OVERRIDES
  139. protected:
  140. wxDialog *m_dialog;
  141. public: // used by the GTK callback only
  142. bool m_bIgnoreNextChange;
  143. void GTKUpdatePath(const char *gtkpath);
  144. private:
  145. void Init()
  146. {
  147. m_dialog = NULL;
  148. m_bIgnoreNextChange = false;
  149. }
  150. DECLARE_DYNAMIC_CLASS(wxDirButton)
  151. };
  152. #undef FILEDIRBTN_OVERRIDES
  153. #endif // _WX_GTK_FILEPICKER_H_