]> git.saurik.com Git - wxWidgets.git/blob - include/wx/pickerbase.h
Implement monitoring of file descriptors in wxMotif event loop.
[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 // RCS-ID: $Id$
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PICKERBASE_H_BASE_
13 #define _WX_PICKERBASE_H_BASE_
14
15 #include "wx/control.h"
16 #include "wx/sizer.h"
17 #include "wx/containr.h"
18
19 class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
20 class WXDLLIMPEXP_FWD_CORE wxToolTip;
21
22 extern WXDLLIMPEXP_DATA_CORE(const char) wxButtonNameStr[];
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 #define wxPB_SMALL 0x8000
35
36 class WXDLLIMPEXP_CORE wxPickerBase : public wxNavigationEnabled<wxControl>
37 {
38 public:
39 // ctor: text is the associated text control
40 wxPickerBase() : m_text(NULL), m_picker(NULL), m_sizer(NULL)
41 { }
42 virtual ~wxPickerBase() {}
43
44
45 // if present, intercepts wxPB_USE_TEXTCTRL style and creates the text control
46 // The 3rd argument is the initial wxString to display in the text control
47 bool CreateBase(wxWindow *parent,
48 wxWindowID id,
49 const wxString& text = wxEmptyString,
50 const wxPoint& pos = wxDefaultPosition,
51 const wxSize& size = wxDefaultSize,
52 long style = 0,
53 const wxValidator& validator = wxDefaultValidator,
54 const wxString& name = wxButtonNameStr);
55
56 public: // public API
57
58 // margin between the text control and the picker
59 void SetInternalMargin(int newmargin)
60 { GetTextCtrlItem()->SetBorder(newmargin); m_sizer->Layout(); }
61 int GetInternalMargin() const
62 { return GetTextCtrlItem()->GetBorder(); }
63
64 // proportion of the text control
65 void SetTextCtrlProportion(int prop)
66 { GetTextCtrlItem()->SetProportion(prop); m_sizer->Layout(); }
67 int GetTextCtrlProportion() const
68 { return GetTextCtrlItem()->GetProportion(); }
69
70 // proportion of the picker control
71 void SetPickerCtrlProportion(int prop)
72 { GetPickerCtrlItem()->SetProportion(prop); m_sizer->Layout(); }
73 int GetPickerCtrlProportion() const
74 { return GetPickerCtrlItem()->GetProportion(); }
75
76 bool IsTextCtrlGrowable() const
77 { return (GetTextCtrlItem()->GetFlag() & wxGROW) != 0; }
78 void SetTextCtrlGrowable(bool grow = true)
79 {
80 int f = GetDefaultTextCtrlFlag();
81 if ( grow )
82 f |= wxGROW;
83 else
84 f &= ~wxGROW;
85
86 GetTextCtrlItem()->SetFlag(f);
87 }
88
89 bool IsPickerCtrlGrowable() const
90 { return (GetPickerCtrlItem()->GetFlag() & wxGROW) != 0; }
91 void SetPickerCtrlGrowable(bool grow = true)
92 {
93 int f = GetDefaultPickerCtrlFlag();
94 if ( grow )
95 f |= wxGROW;
96 else
97 f &= ~wxGROW;
98
99 GetPickerCtrlItem()->SetFlag(f);
100 }
101
102 bool HasTextCtrl() const
103 { return m_text != NULL; }
104 wxTextCtrl *GetTextCtrl()
105 { return m_text; }
106 wxControl *GetPickerCtrl()
107 { return m_picker; }
108
109 void SetTextCtrl(wxTextCtrl* text)
110 { m_text = text; }
111 void SetPickerCtrl(wxControl* picker)
112 { m_picker = picker; }
113
114 // methods that derived class must/may override
115 virtual void UpdatePickerFromTextCtrl() = 0;
116 virtual void UpdateTextCtrlFromPicker() = 0;
117
118 protected:
119 // overridden base class methods
120 #if wxUSE_TOOLTIPS
121 virtual void DoSetToolTip(wxToolTip *tip);
122 #endif // wxUSE_TOOLTIPS
123
124
125 // event handlers
126 void OnTextCtrlDelete(wxWindowDestroyEvent &);
127 void OnTextCtrlUpdate(wxCommandEvent &);
128 void OnTextCtrlKillFocus(wxFocusEvent &);
129
130 // returns the set of styles for the attached wxTextCtrl
131 // from given wxPickerBase's styles
132 virtual long GetTextCtrlStyle(long style) const
133 { return (style & wxWINDOW_STYLE_MASK); }
134
135 // returns the set of styles for the m_picker
136 virtual long GetPickerStyle(long style) const
137 { return (style & wxWINDOW_STYLE_MASK); }
138
139
140 wxSizerItem *GetPickerCtrlItem() const
141 {
142 if (this->HasTextCtrl())
143 return m_sizer->GetItem((size_t)1);
144 return m_sizer->GetItem((size_t)0);
145 }
146
147 wxSizerItem *GetTextCtrlItem() const
148 {
149 wxASSERT(this->HasTextCtrl());
150 return m_sizer->GetItem((size_t)0);
151 }
152
153 int GetDefaultPickerCtrlFlag() const
154 {
155 // on macintosh, without additional borders
156 // there's not enough space for focus rect
157 return wxALIGN_CENTER_VERTICAL|wxGROW
158 #ifdef __WXMAC__
159 | wxTOP | wxRIGHT | wxBOTTOM
160 #endif
161 ;
162 }
163
164 int GetDefaultTextCtrlFlag() const
165 {
166 // on macintosh, without wxALL there's not enough space for focus rect
167 return wxALIGN_CENTER_VERTICAL
168 #ifdef __WXMAC__
169 | wxALL
170 #else
171 | wxRIGHT
172 #endif
173 ;
174 }
175
176 void PostCreation();
177
178 protected:
179 wxTextCtrl *m_text; // can be NULL
180 wxControl *m_picker;
181 wxBoxSizer *m_sizer;
182
183 private:
184 DECLARE_ABSTRACT_CLASS(wxPickerBase)
185 };
186
187
188 #endif
189 // _WX_PICKERBASE_H_BASE_