1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/pickerbase.h
3 // Purpose: wxPickerBase definition
4 // Author: Francesco Montorsi (based on Vadim Zeitlin's code)
7 // Copyright: (c) Vadim Zeitlin, Francesco Montorsi
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PICKERBASE_H_BASE_
13 #define _WX_PICKERBASE_H_BASE_
15 #include "wx/control.h"
18 class WXDLLIMPEXP_CORE wxTextCtrl
;
20 extern WXDLLEXPORT_DATA(const wxChar
) wxButtonNameStr
[];
22 // ----------------------------------------------------------------------------
23 // wxPickerBase is the base class for the picker controls which support
24 // a wxPB_USE_TEXTCTRL style; i.e. for those pickers which can use an auxiliary
25 // text control next to the 'real' picker.
27 // The wxTextPickerHelper class manages enabled/disabled state of the text control,
28 // its sizing and positioning.
29 // ----------------------------------------------------------------------------
31 #define wxPB_USE_TEXTCTRL 0x0002
33 class WXDLLIMPEXP_CORE wxPickerBase
: public wxControl
36 // ctor: text is the associated text control
37 wxPickerBase() : m_text(NULL
), m_picker(NULL
), m_sizer(NULL
)
38 { m_container
.SetContainerWindow(this); }
39 virtual ~wxPickerBase() {}
42 // if present, intercepts wxPB_USE_TEXTCTRL style and creates the text control
43 // The 3rd argument is the initial wxString to display in the text control
44 bool CreateBase(wxWindow
*parent
, wxWindowID id
,
45 const wxString
& text
= wxEmptyString
,
46 const wxPoint
& pos
= wxDefaultPosition
,
47 const wxSize
& size
= wxDefaultSize
, long style
= 0,
48 const wxValidator
& validator
= wxDefaultValidator
,
49 const wxString
& name
= wxButtonNameStr
);
54 // margin between the text control and the picker
55 void SetInternalMargin(int newmargin
)
56 { GetTextCtrlItem()->SetBorder(newmargin
); m_sizer
->Layout(); }
57 int GetInternalMargin() const
58 { return GetTextCtrlItem()->GetBorder(); }
60 // proportion of the text control
61 void SetTextCtrlProportion(int prop
)
62 { GetTextCtrlItem()->SetProportion(prop
); m_sizer
->Layout(); }
63 int GetTextCtrlProportion() const
64 { return GetTextCtrlItem()->GetProportion(); }
66 // proportion of the picker control
67 void SetPickerCtrlProportion(int prop
)
68 { GetPickerCtrlItem()->SetProportion(prop
); m_sizer
->Layout(); }
69 int GetPickerCtrlProportion() const
70 { return GetPickerCtrlItem()->GetProportion(); }
72 bool IsTextCtrlGrowable() const
73 { return (GetTextCtrlItem()->GetFlag() & wxGROW
) != 0; }
74 void SetTextCtrlGrowable(bool grow
= true)
76 int f
= GetDefaultTextCtrlFlag();
82 GetTextCtrlItem()->SetFlag(f
);
85 bool IsPickerCtrlGrowable() const
86 { return (GetPickerCtrlItem()->GetFlag() & wxGROW
) != 0; }
87 void SetPickerCtrlGrowable(bool grow
= true)
89 int f
= GetDefaultPickerCtrlFlag();
95 GetPickerCtrlItem()->SetFlag(f
);
98 bool HasTextCtrl() const
99 { return m_text
!= NULL
; }
100 wxTextCtrl
*GetTextCtrl()
102 wxControl
*GetPickerCtrl()
105 public: // methods that derived class must/may override
107 virtual void UpdatePickerFromTextCtrl() = 0;
108 virtual void UpdateTextCtrlFromPicker() = 0;
110 protected: // utility functions
113 void OnTextCtrlDelete(wxWindowDestroyEvent
&);
114 void OnTextCtrlUpdate(wxCommandEvent
&);
115 void OnTextCtrlKillFocus(wxFocusEvent
&);
117 void OnSize(wxSizeEvent
&);
119 // returns the set of styles for the attached wxTextCtrl
120 // from given wxPickerBase's styles
121 virtual long GetTextCtrlStyle(long style
) const
122 { return (style
& wxWINDOW_STYLE_MASK
); }
124 // returns the set of styles for the m_picker
125 virtual long GetPickerStyle(long style
) const
126 { return (style
& wxWINDOW_STYLE_MASK
); }
129 wxSizerItem
*GetPickerCtrlItem() const
131 if (this->HasTextCtrl())
132 return m_sizer
->GetItem((size_t)1);
133 return m_sizer
->GetItem((size_t)0);
136 wxSizerItem
*GetTextCtrlItem() const
138 wxASSERT(this->HasTextCtrl());
139 return m_sizer
->GetItem((size_t)0);
142 int GetDefaultPickerCtrlFlag() const
144 // on macintosh, without additional borders
145 // there's not enough space for focus rect
146 return wxALIGN_CENTER_VERTICAL
|wxGROW
148 | wxTOP
| wxRIGHT
| wxBOTTOM
153 int GetDefaultTextCtrlFlag() const
155 // on macintosh, without wxALL there's not enough space for focus rect
156 return wxALIGN_CENTER_VERTICAL
168 wxTextCtrl
*m_text
; // can be NULL
173 DECLARE_ABSTRACT_CLASS(wxPickerBase
)
174 DECLARE_EVENT_TABLE()
176 // This class must be something just like a panel...
177 WX_DECLARE_CONTROL_CONTAINER();
182 // _WX_PICKERBASE_H_BASE_