pickerbase.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: pickerbase.h
  3. // Purpose: interface of wxPickerBase
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. #define wxPB_USE_TEXTCTRL 0x0002
  8. #define wxPB_SMALL 0x8000
  9. /**
  10. @class wxPickerBase
  11. Base abstract class for all pickers which support an auxiliary text control.
  12. This class handles all positioning and sizing of the text control like a
  13. an horizontal wxBoxSizer would do, with the text control on the left of the
  14. picker button.
  15. The proportion (see wxSizer documentation for more info about proportion values)
  16. of the picker control defaults to 1 when there isn't a text control associated
  17. (see @c wxPB_USE_TEXTCTRL style) and to 0 otherwise.
  18. @beginStyleTable
  19. @style{wxPB_USE_TEXTCTRL}
  20. Creates a text control to the left of the picker which is
  21. completely managed by this wxPickerBase class.
  22. @endStyleTable
  23. @library{wxcore}
  24. @category{pickers}
  25. @see wxColourPickerCtrl
  26. */
  27. class wxPickerBase : public wxControl
  28. {
  29. public:
  30. wxPickerBase();
  31. virtual ~wxPickerBase();
  32. // if present, intercepts wxPB_USE_TEXTCTRL style and creates the text control
  33. // The 3rd argument is the initial wxString to display in the text control
  34. bool CreateBase(wxWindow *parent,
  35. wxWindowID id,
  36. const wxString& text = wxEmptyString,
  37. const wxPoint& pos = wxDefaultPosition,
  38. const wxSize& size = wxDefaultSize,
  39. long style = 0,
  40. const wxValidator& validator = wxDefaultValidator,
  41. const wxString& name = wxButtonNameStr);
  42. /**
  43. Returns the margin (in pixel) between the picker and the text control.
  44. This function can be used only when HasTextCtrl() returns @true.
  45. */
  46. int GetInternalMargin() const;
  47. /**
  48. Returns the proportion value of the picker.
  49. */
  50. int GetPickerCtrlProportion() const;
  51. /**
  52. Returns a pointer to the text control handled by this window or @NULL if the
  53. @c wxPB_USE_TEXTCTRL style was not specified when this control was created.
  54. @remarks
  55. The contents of the text control could be an invalid representation of
  56. the entity which can be chosen through the picker
  57. (e.g. when the user enters an invalid colour syntax because of a typo).
  58. Thus you should never parse the content of the textctrl to get the
  59. user's input; rather use the derived-class getter
  60. (e.g. wxColourPickerCtrl::GetColour(), wxFilePickerCtrl::GetPath(), etc).
  61. */
  62. wxTextCtrl* GetTextCtrl();
  63. /**
  64. Returns the native implementation of the real picker control.
  65. @note
  66. The returned control in the generic implementation of wxFilePickerCtrl,
  67. wxDirPickerCtrl, wxFontPickerCtrl and wxColourPickerCtrl is a specialized
  68. wxButton class so that you can change its label doing, e.g.:
  69. @code
  70. #ifdef __WXMSW__
  71. // wxMSW is one of the platforms where the generic implementation
  72. // of wxFilePickerCtrl is used...
  73. wxButton *pButt = wx_static_cast(wxButton*, myFilePickerCtrl->GetPickerCtrl());
  74. if (pButt)
  75. pButt->SetLabel("Custom browse string");
  76. #endif
  77. @endcode
  78. */
  79. wxControl* GetPickerCtrl();
  80. /**
  81. Returns the proportion value of the text control.
  82. This function can be used only when HasTextCtrl() returns @true.
  83. */
  84. int GetTextCtrlProportion() const;
  85. /**
  86. Returns @true if this window has a valid text control (i.e.\ if the @c
  87. wxPB_USE_TEXTCTRL style was given when creating this control).
  88. */
  89. bool HasTextCtrl() const;
  90. /**
  91. Returns @true if the picker control is growable.
  92. */
  93. bool IsPickerCtrlGrowable() const;
  94. /**
  95. Returns @true if the text control is growable.
  96. This function can be used only when HasTextCtrl() returns @true.
  97. */
  98. bool IsTextCtrlGrowable() const;
  99. /**
  100. Sets the margin (in pixel) between the picker and the text control.
  101. This function can be used only when HasTextCtrl() returns @true.
  102. */
  103. void SetInternalMargin(int margin);
  104. /**
  105. Sets the picker control as growable when @c grow is @true.
  106. */
  107. void SetPickerCtrlGrowable(bool grow = true);
  108. /**
  109. Sets the proportion value of the picker.
  110. Look at the detailed description of wxPickerBase for more info.
  111. */
  112. void SetPickerCtrlProportion(int prop);
  113. /**
  114. Sets the text control as growable when @c grow is @true.
  115. This function can be used only when HasTextCtrl() returns @true.
  116. */
  117. void SetTextCtrlGrowable(bool grow = true);
  118. /**
  119. Sets the proportion value of the text control.
  120. Look at the detailed description of wxPickerBase for more info.
  121. This function can be used only when HasTextCtrl() returns @true.
  122. */
  123. void SetTextCtrlProportion(int prop);
  124. void SetTextCtrl(wxTextCtrl* text);
  125. void SetPickerCtrl(wxControl* picker);
  126. virtual void UpdatePickerFromTextCtrl() = 0;
  127. virtual void UpdateTextCtrlFromPicker() = 0;
  128. protected:
  129. virtual long GetTextCtrlStyle(long style) const;
  130. virtual long GetPickerStyle(long style) const;
  131. void PostCreation();
  132. };