]> git.saurik.com Git - wxWidgets.git/blob - include/wx/pickerbase.h
Don't check for tr1/type_traits in configure if type_traits was found.
[wxWidgets.git] / include / wx / pickerbase.h
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 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_PICKERBASE_H_BASE_
12 #define _WX_PICKERBASE_H_BASE_
13
14 #include "wx/control.h"
15 #include "wx/sizer.h"
16 #include "wx/containr.h"
17
18 class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
19 class WXDLLIMPEXP_FWD_CORE wxToolTip;
20
21 extern WXDLLIMPEXP_DATA_CORE(const char) wxButtonNameStr[];
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 #define wxPB_SMALL 0x8000
34
35 class WXDLLIMPEXP_CORE wxPickerBase : public wxNavigationEnabled<wxControl>
36 {
37 public:
38 // ctor: text is the associated text control
39 wxPickerBase() : m_text(NULL), m_picker(NULL), m_sizer(NULL)
40 { }
41 virtual ~wxPickerBase() {}
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
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,
53 const wxString& name = wxButtonNameStr);
54
55 public: // public API
56
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(); }
62
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(); }
68
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
75 bool IsTextCtrlGrowable() const
76 { return (GetTextCtrlItem()->GetFlag() & wxGROW) != 0; }
77 void SetTextCtrlGrowable(bool grow = true)
78 {
79 int f = GetDefaultTextCtrlFlag();
80 if ( grow )
81 f |= wxGROW;
82 else
83 f &= ~wxGROW;
84
85 GetTextCtrlItem()->SetFlag(f);
86 }
87
88 bool IsPickerCtrlGrowable() const
89 { return (GetPickerCtrlItem()->GetFlag() & wxGROW) != 0; }
90 void SetPickerCtrlGrowable(bool grow = true)
91 {
92 int f = GetDefaultPickerCtrlFlag();
93 if ( grow )
94 f |= wxGROW;
95 else
96 f &= ~wxGROW;
97
98 GetPickerCtrlItem()->SetFlag(f);
99 }
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
108 void SetTextCtrl(wxTextCtrl* text)
109 { m_text = text; }
110 void SetPickerCtrl(wxControl* picker)
111 { m_picker = picker; }
112
113 // methods that derived class must/may override
114 virtual void UpdatePickerFromTextCtrl() = 0;
115 virtual void UpdateTextCtrlFromPicker() = 0;
116
117 protected:
118 // overridden base class methods
119 #if wxUSE_TOOLTIPS
120 virtual void DoSetToolTip(wxToolTip *tip);
121 #endif // wxUSE_TOOLTIPS
122
123
124 // event handlers
125 void OnTextCtrlDelete(wxWindowDestroyEvent &);
126 void OnTextCtrlUpdate(wxCommandEvent &);
127 void OnTextCtrlKillFocus(wxFocusEvent &);
128
129 // returns the set of styles for the attached wxTextCtrl
130 // from given wxPickerBase's styles
131 virtual long GetTextCtrlStyle(long style) const
132 { return (style & wxWINDOW_STYLE_MASK); }
133
134 // returns the set of styles for the m_picker
135 virtual long GetPickerStyle(long style) const
136 { return (style & wxWINDOW_STYLE_MASK); }
137
138
139 wxSizerItem *GetPickerCtrlItem() const
140 {
141 if (this->HasTextCtrl())
142 return m_sizer->GetItem((size_t)1);
143 return m_sizer->GetItem((size_t)0);
144 }
145
146 wxSizerItem *GetTextCtrlItem() const
147 {
148 wxASSERT(this->HasTextCtrl());
149 return m_sizer->GetItem((size_t)0);
150 }
151
152 int GetDefaultPickerCtrlFlag() const
153 {
154 // on macintosh, without additional borders
155 // there's not enough space for focus rect
156 return wxALIGN_CENTER_VERTICAL|wxGROW
157 #ifdef __WXMAC__
158 | wxTOP | wxRIGHT | wxBOTTOM
159 #endif
160 ;
161 }
162
163 int GetDefaultTextCtrlFlag() const
164 {
165 // on macintosh, without wxALL there's not enough space for focus rect
166 return wxALIGN_CENTER_VERTICAL
167 #ifdef __WXMAC__
168 | wxALL
169 #else
170 | wxRIGHT
171 #endif
172 ;
173 }
174
175 void PostCreation();
176
177 protected:
178 wxTextCtrl *m_text; // can be NULL
179 wxControl *m_picker;
180 wxBoxSizer *m_sizer;
181
182 private:
183 DECLARE_ABSTRACT_CLASS(wxPickerBase)
184 };
185
186
187 #endif
188 // _WX_PICKERBASE_H_BASE_