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 respect the picker
61 // (which has a fixed proportion value of 1)
62 void SetTextCtrlProportion(int prop
)
63 { GetTextCtrlItem()->SetProportion(prop
); m_sizer
->Layout(); }
64 int GetTextCtrlProportion() const
65 { return GetTextCtrlItem()->GetProportion(); }
67 bool IsTextCtrlGrowable() const
68 { return (GetTextCtrlItem()->GetFlag() & wxGROW
) != 0; }
69 void SetTextCtrlGrowable(bool grow
= true)
71 int f
= GetDefaultTextCtrlFlag();
77 GetTextCtrlItem()->SetFlag(f
);
80 bool IsPickerCtrlGrowable() const
81 { return (GetPickerCtrlItem()->GetFlag() & wxGROW
) != 0; }
82 void SetPickerCtrlGrowable(bool grow
= true)
84 int f
= GetDefaultPickerCtrlFlag();
90 GetPickerCtrlItem()->SetFlag(f
);
93 bool HasTextCtrl() const
94 { return m_text
!= NULL
; }
95 wxTextCtrl
*GetTextCtrl()
97 wxControl
*GetPickerCtrl()
100 public: // methods that derived class must/may override
102 virtual void UpdatePickerFromTextCtrl() = 0;
103 virtual void UpdateTextCtrlFromPicker() = 0;
105 protected: // utility functions
108 void OnTextCtrlDelete(wxWindowDestroyEvent
&);
109 void OnTextCtrlUpdate(wxCommandEvent
&);
110 void OnTextCtrlKillFocus(wxFocusEvent
&);
112 void OnSize(wxSizeEvent
&);
114 // returns the set of styles for the attached wxTextCtrl
115 // from given wxPickerBase's styles
116 virtual long GetTextCtrlStyle(long style
) const
117 { return (style
& wxWINDOW_STYLE_MASK
); }
119 // returns the set of styles for the m_picker
120 virtual long GetPickerStyle(long style
) const
121 { return (style
& wxWINDOW_STYLE_MASK
); }
124 wxSizerItem
*GetPickerCtrlItem() const
126 if (this->HasTextCtrl())
127 return m_sizer
->GetItem((size_t)1);
128 return m_sizer
->GetItem((size_t)0);
131 wxSizerItem
*GetTextCtrlItem() const
133 wxASSERT(this->HasTextCtrl());
134 return m_sizer
->GetItem((size_t)0);
137 int GetDefaultPickerCtrlFlag() const
139 // on macintosh, without additional borders
140 // there's not enough space for focus rect
141 return wxALIGN_CENTER_VERTICAL
|wxGROW
143 | wxTOP
| wxRIGHT
| wxBOTTOM
148 int GetDefaultTextCtrlFlag() const
150 // on macintosh, without wxALL there's not enough space for focus rect
151 return wxALIGN_CENTER_VERTICAL
163 wxTextCtrl
*m_text
; // can be NULL
168 DECLARE_ABSTRACT_CLASS(wxPickerBase
)
169 DECLARE_EVENT_TABLE()
171 // This class must be something just like a panel...
172 WX_DECLARE_CONTROL_CONTAINER();
177 // _WX_PICKERBASE_H_BASE_