]> git.saurik.com Git - wxWidgets.git/blame - include/wx/pickerbase.h
Add support for VK_OEM_102 key under wxMSW.
[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"
4107600f 17#include "wx/containr.h"
c757b5fe 18
b5dbe15d
VS
19class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
20class WXDLLIMPEXP_FWD_CORE wxToolTip;
c757b5fe 21
53a2db12 22extern WXDLLIMPEXP_DATA_CORE(const char) wxButtonNameStr[];
ec376c8f
VZ
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
75bc8b34 34#define wxPB_SMALL 0x8000
ec376c8f 35
90230407 36class WXDLLIMPEXP_CORE wxPickerBase : public wxNavigationEnabled<wxControl>
ec376c8f
VZ
37{
38public:
39 // ctor: text is the associated text control
a65ffcb2 40 wxPickerBase() : m_text(NULL), m_picker(NULL), m_sizer(NULL)
90230407 41 { }
a65ffcb2 42 virtual ~wxPickerBase() {}
ec376c8f
VZ
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
5f6475c1
VZ
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,
55b43eaa 54 const wxString& name = wxButtonNameStr);
ec376c8f 55
ec376c8f
VZ
56public: // public API
57
58 // margin between the text control and the picker
a65ffcb2
VZ
59 void SetInternalMargin(int newmargin)
60 { GetTextCtrlItem()->SetBorder(newmargin); m_sizer->Layout(); }
61 int GetInternalMargin() const
62 { return GetTextCtrlItem()->GetBorder(); }
ec376c8f 63
ecd87e5b 64 // proportion of the text control
a65ffcb2
VZ
65 void SetTextCtrlProportion(int prop)
66 { GetTextCtrlItem()->SetProportion(prop); m_sizer->Layout(); }
67 int GetTextCtrlProportion() const
68 { return GetTextCtrlItem()->GetProportion(); }
69
ecd87e5b
VZ
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
a65ffcb2 76 bool IsTextCtrlGrowable() const
57b49e94 77 { return (GetTextCtrlItem()->GetFlag() & wxGROW) != 0; }
a65ffcb2
VZ
78 void SetTextCtrlGrowable(bool grow = true)
79 {
80 int f = GetDefaultTextCtrlFlag();
57b49e94
VZ
81 if ( grow )
82 f |= wxGROW;
a65ffcb2 83 else
57b49e94
VZ
84 f &= ~wxGROW;
85
86 GetTextCtrlItem()->SetFlag(f);
a65ffcb2
VZ
87 }
88
89 bool IsPickerCtrlGrowable() const
57b49e94 90 { return (GetPickerCtrlItem()->GetFlag() & wxGROW) != 0; }
a65ffcb2
VZ
91 void SetPickerCtrlGrowable(bool grow = true)
92 {
93 int f = GetDefaultPickerCtrlFlag();
57b49e94
VZ
94 if ( grow )
95 f |= wxGROW;
a65ffcb2 96 else
57b49e94
VZ
97 f &= ~wxGROW;
98
99 GetPickerCtrlItem()->SetFlag(f);
a65ffcb2 100 }
ec376c8f
VZ
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
8ef74b15 109 // methods that derived class must/may override
ec376c8f
VZ
110 virtual void UpdatePickerFromTextCtrl() = 0;
111 virtual void UpdateTextCtrlFromPicker() = 0;
112
8ef74b15
VZ
113protected:
114 // overridden base class methods
115#if wxUSE_TOOLTIPS
116 virtual void DoSetToolTip(wxToolTip *tip);
117#endif // wxUSE_TOOLTIPS
118
ec376c8f 119
ec376c8f
VZ
120 // event handlers
121 void OnTextCtrlDelete(wxWindowDestroyEvent &);
122 void OnTextCtrlUpdate(wxCommandEvent &);
123 void OnTextCtrlKillFocus(wxFocusEvent &);
124
125 // returns the set of styles for the attached wxTextCtrl
126 // from given wxPickerBase's styles
127 virtual long GetTextCtrlStyle(long style) const
128 { return (style & wxWINDOW_STYLE_MASK); }
129
130 // returns the set of styles for the m_picker
131 virtual long GetPickerStyle(long style) const
132 { return (style & wxWINDOW_STYLE_MASK); }
133
a65ffcb2
VZ
134
135 wxSizerItem *GetPickerCtrlItem() const
136 {
137 if (this->HasTextCtrl())
138 return m_sizer->GetItem((size_t)1);
139 return m_sizer->GetItem((size_t)0);
140 }
141
142 wxSizerItem *GetTextCtrlItem() const
143 {
144 wxASSERT(this->HasTextCtrl());
145 return m_sizer->GetItem((size_t)0);
146 }
147
148 int GetDefaultPickerCtrlFlag() const
149 {
150 // on macintosh, without additional borders
151 // there's not enough space for focus rect
152 return wxALIGN_CENTER_VERTICAL|wxGROW
153#ifdef __WXMAC__
154 | wxTOP | wxRIGHT | wxBOTTOM
155#endif
156 ;
157 }
158
159 int GetDefaultTextCtrlFlag() const
160 {
161 // on macintosh, without wxALL there's not enough space for focus rect
162 return wxALIGN_CENTER_VERTICAL
163#ifdef __WXMAC__
164 | wxALL
165#else
166 | wxRIGHT
167#endif
168 ;
169 }
170
171 void PostCreation();
172
ec376c8f
VZ
173protected:
174 wxTextCtrl *m_text; // can be NULL
175 wxControl *m_picker;
a65ffcb2 176 wxBoxSizer *m_sizer;
ec376c8f
VZ
177
178private:
179 DECLARE_ABSTRACT_CLASS(wxPickerBase)
180};
181
182
183#endif
184 // _WX_PICKERBASE_H_BASE_