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