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