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