]>
Commit | Line | Data |
---|---|---|
ec376c8f VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/pickerbase.h | |
3 | // Purpose: wxPickerBase definition | |
4 | // Author: Francesco Montorsi (based on Vadim Zeitlin's code) | |
5 | // Modified by: | |
6 | // Created: 14/4/2006 | |
7 | // Copyright: (c) Vadim Zeitlin, Francesco Montorsi | |
8 | // RCS-ID: $Id$ | |
9 | // Licence: wxWindows Licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_PICKERBASE_H_BASE_ | |
13 | #define _WX_PICKERBASE_H_BASE_ | |
14 | ||
c757b5fe | 15 | #include "wx/control.h" |
1bc79697 | 16 | #include "wx/sizer.h" |
4107600f | 17 | #include "wx/containr.h" |
c757b5fe PC |
18 | |
19 | class WXDLLIMPEXP_CORE wxTextCtrl; | |
20 | ||
21 | extern WXDLLEXPORT_DATA(const wxChar) wxButtonNameStr[]; | |
ec376c8f VZ |
22 | |
23 | // ---------------------------------------------------------------------------- | |
24 | // wxPickerBase is the base class for the picker controls which support | |
25 | // a wxPB_USE_TEXTCTRL style; i.e. for those pickers which can use an auxiliary | |
26 | // text control next to the 'real' picker. | |
27 | // | |
28 | // The wxTextPickerHelper class manages enabled/disabled state of the text control, | |
29 | // its sizing and positioning. | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
32 | #define wxPB_USE_TEXTCTRL 0x0002 | |
33 | ||
34 | class WXDLLIMPEXP_CORE wxPickerBase : public wxControl | |
35 | { | |
36 | public: | |
37 | // ctor: text is the associated text control | |
a65ffcb2 VZ |
38 | wxPickerBase() : m_text(NULL), m_picker(NULL), m_sizer(NULL) |
39 | { m_container.SetContainerWindow(this); } | |
40 | virtual ~wxPickerBase() {} | |
ec376c8f VZ |
41 | |
42 | ||
43 | // if present, intercepts wxPB_USE_TEXTCTRL style and creates the text control | |
44 | // The 3rd argument is the initial wxString to display in the text control | |
5f6475c1 VZ |
45 | bool CreateBase(wxWindow *parent, |
46 | wxWindowID id, | |
47 | const wxString& text = wxEmptyString, | |
48 | const wxPoint& pos = wxDefaultPosition, | |
49 | const wxSize& size = wxDefaultSize, | |
50 | long style = 0, | |
51 | const wxValidator& validator = wxDefaultValidator, | |
55b43eaa | 52 | const wxString& name = wxButtonNameStr); |
ec376c8f VZ |
53 | |
54 | ||
55 | public: // public API | |
56 | ||
57 | // margin between the text control and the picker | |
a65ffcb2 VZ |
58 | void SetInternalMargin(int newmargin) |
59 | { GetTextCtrlItem()->SetBorder(newmargin); m_sizer->Layout(); } | |
60 | int GetInternalMargin() const | |
61 | { return GetTextCtrlItem()->GetBorder(); } | |
ec376c8f | 62 | |
ecd87e5b | 63 | // proportion of the text control |
a65ffcb2 VZ |
64 | void SetTextCtrlProportion(int prop) |
65 | { GetTextCtrlItem()->SetProportion(prop); m_sizer->Layout(); } | |
66 | int GetTextCtrlProportion() const | |
67 | { return GetTextCtrlItem()->GetProportion(); } | |
68 | ||
ecd87e5b VZ |
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(); } | |
74 | ||
a65ffcb2 | 75 | bool IsTextCtrlGrowable() const |
57b49e94 | 76 | { return (GetTextCtrlItem()->GetFlag() & wxGROW) != 0; } |
a65ffcb2 VZ |
77 | void SetTextCtrlGrowable(bool grow = true) |
78 | { | |
79 | int f = GetDefaultTextCtrlFlag(); | |
57b49e94 VZ |
80 | if ( grow ) |
81 | f |= wxGROW; | |
a65ffcb2 | 82 | else |
57b49e94 VZ |
83 | f &= ~wxGROW; |
84 | ||
85 | GetTextCtrlItem()->SetFlag(f); | |
a65ffcb2 VZ |
86 | } |
87 | ||
88 | bool IsPickerCtrlGrowable() const | |
57b49e94 | 89 | { return (GetPickerCtrlItem()->GetFlag() & wxGROW) != 0; } |
a65ffcb2 VZ |
90 | void SetPickerCtrlGrowable(bool grow = true) |
91 | { | |
92 | int f = GetDefaultPickerCtrlFlag(); | |
57b49e94 VZ |
93 | if ( grow ) |
94 | f |= wxGROW; | |
a65ffcb2 | 95 | else |
57b49e94 VZ |
96 | f &= ~wxGROW; |
97 | ||
98 | GetPickerCtrlItem()->SetFlag(f); | |
a65ffcb2 | 99 | } |
ec376c8f VZ |
100 | |
101 | bool HasTextCtrl() const | |
102 | { return m_text != NULL; } | |
103 | wxTextCtrl *GetTextCtrl() | |
104 | { return m_text; } | |
105 | wxControl *GetPickerCtrl() | |
106 | { return m_picker; } | |
107 | ||
ec376c8f VZ |
108 | public: // methods that derived class must/may override |
109 | ||
110 | virtual void UpdatePickerFromTextCtrl() = 0; | |
111 | virtual void UpdateTextCtrlFromPicker() = 0; | |
112 | ||
113 | protected: // utility functions | |
114 | ||
ec376c8f VZ |
115 | // event handlers |
116 | void OnTextCtrlDelete(wxWindowDestroyEvent &); | |
117 | void OnTextCtrlUpdate(wxCommandEvent &); | |
118 | void OnTextCtrlKillFocus(wxFocusEvent &); | |
119 | ||
a65ffcb2 VZ |
120 | void OnSize(wxSizeEvent &); |
121 | ||
ec376c8f VZ |
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); } | |
126 | ||
127 | // returns the set of styles for the m_picker | |
128 | virtual long GetPickerStyle(long style) const | |
129 | { return (style & wxWINDOW_STYLE_MASK); } | |
130 | ||
a65ffcb2 VZ |
131 | |
132 | wxSizerItem *GetPickerCtrlItem() const | |
133 | { | |
134 | if (this->HasTextCtrl()) | |
135 | return m_sizer->GetItem((size_t)1); | |
136 | return m_sizer->GetItem((size_t)0); | |
137 | } | |
138 | ||
139 | wxSizerItem *GetTextCtrlItem() const | |
140 | { | |
141 | wxASSERT(this->HasTextCtrl()); | |
142 | return m_sizer->GetItem((size_t)0); | |
143 | } | |
144 | ||
145 | int GetDefaultPickerCtrlFlag() const | |
146 | { | |
147 | // on macintosh, without additional borders | |
148 | // there's not enough space for focus rect | |
149 | return wxALIGN_CENTER_VERTICAL|wxGROW | |
150 | #ifdef __WXMAC__ | |
151 | | wxTOP | wxRIGHT | wxBOTTOM | |
152 | #endif | |
153 | ; | |
154 | } | |
155 | ||
156 | int GetDefaultTextCtrlFlag() const | |
157 | { | |
158 | // on macintosh, without wxALL there's not enough space for focus rect | |
159 | return wxALIGN_CENTER_VERTICAL | |
160 | #ifdef __WXMAC__ | |
161 | | wxALL | |
162 | #else | |
163 | | wxRIGHT | |
164 | #endif | |
165 | ; | |
166 | } | |
167 | ||
168 | void PostCreation(); | |
169 | ||
ec376c8f VZ |
170 | protected: |
171 | wxTextCtrl *m_text; // can be NULL | |
172 | wxControl *m_picker; | |
a65ffcb2 | 173 | wxBoxSizer *m_sizer; |
ec376c8f VZ |
174 | |
175 | private: | |
176 | DECLARE_ABSTRACT_CLASS(wxPickerBase) | |
a65ffcb2 VZ |
177 | DECLARE_EVENT_TABLE() |
178 | ||
179 | // This class must be something just like a panel... | |
180 | WX_DECLARE_CONTROL_CONTAINER(); | |
ec376c8f VZ |
181 | }; |
182 | ||
183 | ||
184 | #endif | |
185 | // _WX_PICKERBASE_H_BASE_ |