]> git.saurik.com Git - wxWidgets.git/blame - include/wx/pickerbase.h
Escape underscores
[wxWidgets.git] / include / wx / pickerbase.h
CommitLineData
ec376c8f
VZ
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
c757b5fe 15#include "wx/control.h"
1bc79697 16#include "wx/sizer.h"
c757b5fe
PC
17
18class WXDLLIMPEXP_CORE wxTextCtrl;
19
20extern WXDLLEXPORT_DATA(const wxChar) wxButtonNameStr[];
ec376c8f
VZ
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
33class WXDLLIMPEXP_CORE wxPickerBase : public wxControl
34{
35public:
36 // ctor: text is the associated text control
a65ffcb2
VZ
37 wxPickerBase() : m_text(NULL), m_picker(NULL), m_sizer(NULL)
38 { m_container.SetContainerWindow(this); }
39 virtual ~wxPickerBase() {}
ec376c8f
VZ
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
52public: // public API
53
54 // margin between the text control and the picker
a65ffcb2
VZ
55 void SetInternalMargin(int newmargin)
56 { GetTextCtrlItem()->SetBorder(newmargin); m_sizer->Layout(); }
57 int GetInternalMargin() const
58 { return GetTextCtrlItem()->GetBorder(); }
ec376c8f
VZ
59
60 // proportion of the text control respect the picker
61 // (which has a fixed proportion value of 1)
a65ffcb2
VZ
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
57b49e94 68 { return (GetTextCtrlItem()->GetFlag() & wxGROW) != 0; }
a65ffcb2
VZ
69 void SetTextCtrlGrowable(bool grow = true)
70 {
71 int f = GetDefaultTextCtrlFlag();
57b49e94
VZ
72 if ( grow )
73 f |= wxGROW;
a65ffcb2 74 else
57b49e94
VZ
75 f &= ~wxGROW;
76
77 GetTextCtrlItem()->SetFlag(f);
a65ffcb2
VZ
78 }
79
80 bool IsPickerCtrlGrowable() const
57b49e94 81 { return (GetPickerCtrlItem()->GetFlag() & wxGROW) != 0; }
a65ffcb2
VZ
82 void SetPickerCtrlGrowable(bool grow = true)
83 {
84 int f = GetDefaultPickerCtrlFlag();
57b49e94
VZ
85 if ( grow )
86 f |= wxGROW;
a65ffcb2 87 else
57b49e94
VZ
88 f &= ~wxGROW;
89
90 GetPickerCtrlItem()->SetFlag(f);
a65ffcb2 91 }
ec376c8f
VZ
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
ec376c8f
VZ
100public: // methods that derived class must/may override
101
102 virtual void UpdatePickerFromTextCtrl() = 0;
103 virtual void UpdateTextCtrlFromPicker() = 0;
104
105protected: // utility functions
106
ec376c8f
VZ
107 // event handlers
108 void OnTextCtrlDelete(wxWindowDestroyEvent &);
109 void OnTextCtrlUpdate(wxCommandEvent &);
110 void OnTextCtrlKillFocus(wxFocusEvent &);
111
a65ffcb2
VZ
112 void OnSize(wxSizeEvent &);
113
ec376c8f
VZ
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
a65ffcb2
VZ
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
ec376c8f
VZ
162protected:
163 wxTextCtrl *m_text; // can be NULL
164 wxControl *m_picker;
a65ffcb2 165 wxBoxSizer *m_sizer;
ec376c8f
VZ
166
167private:
168 DECLARE_ABSTRACT_CLASS(wxPickerBase)
a65ffcb2
VZ
169 DECLARE_EVENT_TABLE()
170
171 // This class must be something just like a panel...
172 WX_DECLARE_CONTROL_CONTAINER();
ec376c8f
VZ
173};
174
175
176#endif
177 // _WX_PICKERBASE_H_BASE_