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"
17 class WXDLLIMPEXP_CORE wxTextCtrl
;
19 extern WXDLLEXPORT_DATA(const wxChar
) wxButtonNameStr
[];
21 // ----------------------------------------------------------------------------
22 // wxPickerBase is the base class for the picker controls which support
23 // a wxPB_USE_TEXTCTRL style; i.e. for those pickers which can use an auxiliary
24 // text control next to the 'real' picker.
26 // The wxTextPickerHelper class manages enabled/disabled state of the text control,
27 // its sizing and positioning.
28 // ----------------------------------------------------------------------------
30 #define wxPB_USE_TEXTCTRL 0x0002
32 class WXDLLIMPEXP_CORE wxPickerBase
: public wxControl
35 // ctor: text is the associated text control
36 wxPickerBase() : m_text(NULL
), m_picker(NULL
), m_sizer(NULL
)
37 { m_container
.SetContainerWindow(this); }
38 virtual ~wxPickerBase() {}
41 // if present, intercepts wxPB_USE_TEXTCTRL style and creates the text control
42 // The 3rd argument is the initial wxString to display in the text control
43 bool CreateBase(wxWindow
*parent
, wxWindowID id
,
44 const wxString
& text
= wxEmptyString
,
45 const wxPoint
& pos
= wxDefaultPosition
,
46 const wxSize
& size
= wxDefaultSize
, long style
= 0,
47 const wxValidator
& validator
= wxDefaultValidator
,
48 const wxString
& name
= wxButtonNameStr
);
53 // margin between the text control and the picker
54 void SetInternalMargin(int newmargin
)
55 { GetTextCtrlItem()->SetBorder(newmargin
); m_sizer
->Layout(); }
56 int GetInternalMargin() const
57 { return GetTextCtrlItem()->GetBorder(); }
59 // proportion of the text control respect the picker
60 // (which has a fixed proportion value of 1)
61 void SetTextCtrlProportion(int prop
)
62 { GetTextCtrlItem()->SetProportion(prop
); m_sizer
->Layout(); }
63 int GetTextCtrlProportion() const
64 { return GetTextCtrlItem()->GetProportion(); }
66 bool IsTextCtrlGrowable() const
67 { return (GetTextCtrlItem()->GetFlag() & wxGROW
) != 0; }
68 void SetTextCtrlGrowable(bool grow
= true)
70 int f
= GetDefaultTextCtrlFlag();
76 GetTextCtrlItem()->SetFlag(f
);
79 bool IsPickerCtrlGrowable() const
80 { return (GetPickerCtrlItem()->GetFlag() & wxGROW
) != 0; }
81 void SetPickerCtrlGrowable(bool grow
= true)
83 int f
= GetDefaultPickerCtrlFlag();
89 GetPickerCtrlItem()->SetFlag(f
);
92 bool HasTextCtrl() const
93 { return m_text
!= NULL
; }
94 wxTextCtrl
*GetTextCtrl()
96 wxControl
*GetPickerCtrl()
99 public: // methods that derived class must/may override
101 virtual void UpdatePickerFromTextCtrl() = 0;
102 virtual void UpdateTextCtrlFromPicker() = 0;
104 protected: // utility functions
107 void OnTextCtrlDelete(wxWindowDestroyEvent
&);
108 void OnTextCtrlUpdate(wxCommandEvent
&);
109 void OnTextCtrlKillFocus(wxFocusEvent
&);
111 void OnSize(wxSizeEvent
&);
113 // returns the set of styles for the attached wxTextCtrl
114 // from given wxPickerBase's styles
115 virtual long GetTextCtrlStyle(long style
) const
116 { return (style
& wxWINDOW_STYLE_MASK
); }
118 // returns the set of styles for the m_picker
119 virtual long GetPickerStyle(long style
) const
120 { return (style
& wxWINDOW_STYLE_MASK
); }
123 wxSizerItem
*GetPickerCtrlItem() const
125 if (this->HasTextCtrl())
126 return m_sizer
->GetItem((size_t)1);
127 return m_sizer
->GetItem((size_t)0);
130 wxSizerItem
*GetTextCtrlItem() const
132 wxASSERT(this->HasTextCtrl());
133 return m_sizer
->GetItem((size_t)0);
136 int GetDefaultPickerCtrlFlag() const
138 // on macintosh, without additional borders
139 // there's not enough space for focus rect
140 return wxALIGN_CENTER_VERTICAL
|wxGROW
142 | wxTOP
| wxRIGHT
| wxBOTTOM
147 int GetDefaultTextCtrlFlag() const
149 // on macintosh, without wxALL there's not enough space for focus rect
150 return wxALIGN_CENTER_VERTICAL
162 wxTextCtrl
*m_text
; // can be NULL
167 DECLARE_ABSTRACT_CLASS(wxPickerBase
)
168 DECLARE_EVENT_TABLE()
170 // This class must be something just like a panel...
171 WX_DECLARE_CONTROL_CONTAINER();
176 // _WX_PICKERBASE_H_BASE_