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