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
,
46 const wxString
& text
= wxEmptyString
,
47 const wxPoint
& pos
= wxDefaultPosition
,
48 const wxSize
& size
= wxDefaultSize
,
50 const wxValidator
& validator
= wxDefaultValidator
,
51 const wxString
& name
= wxButtonNameStr
,
57 // margin between the text control and the picker
58 void SetInternalMargin(int newmargin
)
59 { GetTextCtrlItem()->SetBorder(newmargin
); m_sizer
->Layout(); }
60 int GetInternalMargin() const
61 { return GetTextCtrlItem()->GetBorder(); }
63 // proportion of the text control
64 void SetTextCtrlProportion(int prop
)
65 { GetTextCtrlItem()->SetProportion(prop
); m_sizer
->Layout(); }
66 int GetTextCtrlProportion() const
67 { return GetTextCtrlItem()->GetProportion(); }
69 // proportion of the picker control
70 void SetPickerCtrlProportion(int prop
)
71 { GetPickerCtrlItem()->SetProportion(prop
); m_sizer
->Layout(); }
72 int GetPickerCtrlProportion() const
73 { return GetPickerCtrlItem()->GetProportion(); }
75 bool IsTextCtrlGrowable() const
76 { return (GetTextCtrlItem()->GetFlag() & wxGROW
) != 0; }
77 void SetTextCtrlGrowable(bool grow
= true)
79 int f
= GetDefaultTextCtrlFlag();
85 GetTextCtrlItem()->SetFlag(f
);
88 bool IsPickerCtrlGrowable() const
89 { return (GetPickerCtrlItem()->GetFlag() & wxGROW
) != 0; }
90 void SetPickerCtrlGrowable(bool grow
= true)
92 int f
= GetDefaultPickerCtrlFlag();
98 GetPickerCtrlItem()->SetFlag(f
);
101 bool HasTextCtrl() const
102 { return m_text
!= NULL
; }
103 wxTextCtrl
*GetTextCtrl()
105 wxControl
*GetPickerCtrl()
108 public: // methods that derived class must/may override
110 virtual void UpdatePickerFromTextCtrl() = 0;
111 virtual void UpdateTextCtrlFromPicker() = 0;
113 protected: // utility functions
116 void OnTextCtrlDelete(wxWindowDestroyEvent
&);
117 void OnTextCtrlUpdate(wxCommandEvent
&);
118 void OnTextCtrlKillFocus(wxFocusEvent
&);
120 void OnSize(wxSizeEvent
&);
122 // returns the set of styles for the attached wxTextCtrl
123 // from given wxPickerBase's styles
124 virtual long GetTextCtrlStyle(long style
) const
125 { return (style
& wxWINDOW_STYLE_MASK
); }
127 // returns the set of styles for the m_picker
128 virtual long GetPickerStyle(long style
) const
129 { return (style
& wxWINDOW_STYLE_MASK
); }
132 wxSizerItem
*GetPickerCtrlItem() const
134 if (this->HasTextCtrl())
135 return m_sizer
->GetItem((size_t)1);
136 return m_sizer
->GetItem((size_t)0);
139 wxSizerItem
*GetTextCtrlItem() const
141 wxASSERT(this->HasTextCtrl());
142 return m_sizer
->GetItem((size_t)0);
145 int GetDefaultPickerCtrlFlag() const
147 // on macintosh, without additional borders
148 // there's not enough space for focus rect
149 return wxALIGN_CENTER_VERTICAL
|wxGROW
151 | wxTOP
| wxRIGHT
| wxBOTTOM
156 int GetDefaultTextCtrlFlag() const
158 // on macintosh, without wxALL there's not enough space for focus rect
159 return wxALIGN_CENTER_VERTICAL
171 wxTextCtrl
*m_text
; // can be NULL
176 DECLARE_ABSTRACT_CLASS(wxPickerBase
)
177 DECLARE_EVENT_TABLE()
179 // This class must be something just like a panel...
180 WX_DECLARE_CONTROL_CONTAINER();
185 // _WX_PICKERBASE_H_BASE_