]> git.saurik.com Git - wxWidgets.git/blob - include/wx/pickerbase.h
Include wx/dataobj.h according to precompiled headers of wx/wx.h (with other minor...
[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
61 void SetTextCtrlProportion(int prop)
62 { GetTextCtrlItem()->SetProportion(prop); m_sizer->Layout(); }
63 int GetTextCtrlProportion() const
64 { return GetTextCtrlItem()->GetProportion(); }
65
66 // proportion of the picker control
67 void SetPickerCtrlProportion(int prop)
68 { GetPickerCtrlItem()->SetProportion(prop); m_sizer->Layout(); }
69 int GetPickerCtrlProportion() const
70 { return GetPickerCtrlItem()->GetProportion(); }
71
72 bool IsTextCtrlGrowable() const
73 { return (GetTextCtrlItem()->GetFlag() & wxGROW) != 0; }
74 void SetTextCtrlGrowable(bool grow = true)
75 {
76 int f = GetDefaultTextCtrlFlag();
77 if ( grow )
78 f |= wxGROW;
79 else
80 f &= ~wxGROW;
81
82 GetTextCtrlItem()->SetFlag(f);
83 }
84
85 bool IsPickerCtrlGrowable() const
86 { return (GetPickerCtrlItem()->GetFlag() & wxGROW) != 0; }
87 void SetPickerCtrlGrowable(bool grow = true)
88 {
89 int f = GetDefaultPickerCtrlFlag();
90 if ( grow )
91 f |= wxGROW;
92 else
93 f &= ~wxGROW;
94
95 GetPickerCtrlItem()->SetFlag(f);
96 }
97
98 bool HasTextCtrl() const
99 { return m_text != NULL; }
100 wxTextCtrl *GetTextCtrl()
101 { return m_text; }
102 wxControl *GetPickerCtrl()
103 { return m_picker; }
104
105 public: // methods that derived class must/may override
106
107 virtual void UpdatePickerFromTextCtrl() = 0;
108 virtual void UpdateTextCtrlFromPicker() = 0;
109
110 protected: // utility functions
111
112 // event handlers
113 void OnTextCtrlDelete(wxWindowDestroyEvent &);
114 void OnTextCtrlUpdate(wxCommandEvent &);
115 void OnTextCtrlKillFocus(wxFocusEvent &);
116
117 void OnSize(wxSizeEvent &);
118
119 // returns the set of styles for the attached wxTextCtrl
120 // from given wxPickerBase's styles
121 virtual long GetTextCtrlStyle(long style) const
122 { return (style & wxWINDOW_STYLE_MASK); }
123
124 // returns the set of styles for the m_picker
125 virtual long GetPickerStyle(long style) const
126 { return (style & wxWINDOW_STYLE_MASK); }
127
128
129 wxSizerItem *GetPickerCtrlItem() const
130 {
131 if (this->HasTextCtrl())
132 return m_sizer->GetItem((size_t)1);
133 return m_sizer->GetItem((size_t)0);
134 }
135
136 wxSizerItem *GetTextCtrlItem() const
137 {
138 wxASSERT(this->HasTextCtrl());
139 return m_sizer->GetItem((size_t)0);
140 }
141
142 int GetDefaultPickerCtrlFlag() const
143 {
144 // on macintosh, without additional borders
145 // there's not enough space for focus rect
146 return wxALIGN_CENTER_VERTICAL|wxGROW
147 #ifdef __WXMAC__
148 | wxTOP | wxRIGHT | wxBOTTOM
149 #endif
150 ;
151 }
152
153 int GetDefaultTextCtrlFlag() const
154 {
155 // on macintosh, without wxALL there's not enough space for focus rect
156 return wxALIGN_CENTER_VERTICAL
157 #ifdef __WXMAC__
158 | wxALL
159 #else
160 | wxRIGHT
161 #endif
162 ;
163 }
164
165 void PostCreation();
166
167 protected:
168 wxTextCtrl *m_text; // can be NULL
169 wxControl *m_picker;
170 wxBoxSizer *m_sizer;
171
172 private:
173 DECLARE_ABSTRACT_CLASS(wxPickerBase)
174 DECLARE_EVENT_TABLE()
175
176 // This class must be something just like a panel...
177 WX_DECLARE_CONTROL_CONTAINER();
178 };
179
180
181 #endif
182 // _WX_PICKERBASE_H_BASE_