]> git.saurik.com Git - wxWidgets.git/blob - include/wx/control.h
build fixes for wxUSE_IPV6==1 under Windows
[wxWidgets.git] / include / wx / control.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/control.h
3 // Purpose: wxControl common interface
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 26.07.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CONTROL_H_BASE_
13 #define _WX_CONTROL_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/defs.h"
20
21 #if wxUSE_CONTROLS
22
23 #include "wx/window.h" // base class
24
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxControlNameStr[];
26
27 enum wxEllipsizeMode
28 {
29 wxELLIPSIZE_START,
30 wxELLIPSIZE_MIDDLE,
31 wxELLIPSIZE_END
32 };
33
34 // ----------------------------------------------------------------------------
35 // wxControl is the base class for all controls
36 // ----------------------------------------------------------------------------
37
38 class WXDLLIMPEXP_CORE wxControlBase : public wxWindow
39 {
40 public:
41 wxControlBase() { }
42
43 virtual ~wxControlBase();
44
45 // Create() function adds the validator parameter
46 bool Create(wxWindow *parent, wxWindowID id,
47 const wxPoint& pos = wxDefaultPosition,
48 const wxSize& size = wxDefaultSize,
49 long style = 0,
50 const wxValidator& validator = wxDefaultValidator,
51 const wxString& name = wxControlNameStr);
52
53 // get the control alignment (left/right/centre, top/bottom/centre)
54 int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }
55
56 // get just the text of the label, without mnemonic characters ('&')
57 wxString GetLabelText() const { return GetLabelText(GetLabel()); }
58
59 virtual void SetLabel(const wxString& label)
60 {
61 m_labelOrig = label;
62
63 InvalidateBestSize();
64
65 wxWindow::SetLabel(label);
66 }
67
68 virtual wxString GetLabel() const
69 {
70 // return the original string, as it was passed to SetLabel()
71 // (i.e. with wx-style mnemonics)
72 return m_labelOrig;
73 }
74
75 // static utilities:
76
77 // replaces parts of the string with ellipsis if needed
78 static wxString Ellipsize(const wxString& label, const wxDC& dc,
79 wxEllipsizeMode mode, int maxWidth);
80
81 // get the string without mnemonic characters ('&')
82 static wxString GetLabelText(const wxString& label);
83
84 // removes the mnemonics characters
85 static wxString RemoveMnemonics(const wxString& str);
86
87 // return the accel index in the string or -1 if none and puts the modified
88 // string into second parameter if non NULL
89 static int FindAccelIndex(const wxString& label,
90 wxString *labelOnly = NULL);
91
92
93 // controls by default inherit the colours of their parents, if a
94 // particular control class doesn't want to do it, it can override
95 // ShouldInheritColours() to return false
96 virtual bool ShouldInheritColours() const { return true; }
97
98
99 // WARNING: this doesn't work for all controls nor all platforms!
100 //
101 // simulates the event of given type (i.e. wxButton::Command() is just as
102 // if the button was clicked)
103 virtual void Command(wxCommandEvent &event);
104
105 virtual bool SetFont(const wxFont& font);
106
107 // wxControl-specific processing after processing the update event
108 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
109
110 protected:
111 // choose the default border for this window
112 virtual wxBorder GetDefaultBorder() const;
113
114 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
115 // to the list of parents children
116 bool CreateControl(wxWindowBase *parent,
117 wxWindowID id,
118 const wxPoint& pos,
119 const wxSize& size,
120 long style,
121 const wxValidator& validator,
122 const wxString& name);
123
124 // initialize the common fields of wxCommandEvent
125 void InitCommandEvent(wxCommandEvent& event) const;
126
127 // this field contains the label in wx format, i.e. with '&' mnemonics
128 wxString m_labelOrig;
129
130 DECLARE_NO_COPY_CLASS(wxControlBase)
131 };
132
133 // ----------------------------------------------------------------------------
134 // include platform-dependent wxControl declarations
135 // ----------------------------------------------------------------------------
136
137 #if defined(__WXUNIVERSAL__)
138 #include "wx/univ/control.h"
139 #elif defined(__WXPALMOS__)
140 #include "wx/palmos/control.h"
141 #elif defined(__WXMSW__)
142 #include "wx/msw/control.h"
143 #elif defined(__WXMOTIF__)
144 #include "wx/motif/control.h"
145 #elif defined(__WXGTK20__)
146 #include "wx/gtk/control.h"
147 #elif defined(__WXGTK__)
148 #include "wx/gtk1/control.h"
149 #elif defined(__WXMAC__)
150 #include "wx/osx/control.h"
151 #elif defined(__WXCOCOA__)
152 #include "wx/cocoa/control.h"
153 #elif defined(__WXPM__)
154 #include "wx/os2/control.h"
155 #endif
156
157 #endif // wxUSE_CONTROLS
158
159 #endif
160 // _WX_CONTROL_H_BASE_