]> git.saurik.com Git - wxWidgets.git/blame - include/wx/control.h
wrong move
[wxWidgets.git] / include / wx / control.h
CommitLineData
8d99be5f
VZ
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$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
8d99be5f
VZ
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_CONTROL_H_BASE_
13#define _WX_CONTROL_H_BASE_
c801d85f 14
8d99be5f
VZ
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
997176a3
VZ
19#include "wx/defs.h"
20
1e6feb95
VZ
21#if wxUSE_CONTROLS
22
8d99be5f
VZ
23#include "wx/window.h" // base class
24
53a2db12 25extern WXDLLIMPEXP_DATA_CORE(const char) wxControlNameStr[];
1e6feb95 26
5c87527c
FM
27enum wxEllipsizeMode
28{
29 wxELLIPSIZE_START,
30 wxELLIPSIZE_MIDDLE,
31 wxELLIPSIZE_END
32};
33
8d99be5f
VZ
34// ----------------------------------------------------------------------------
35// wxControl is the base class for all controls
36// ----------------------------------------------------------------------------
37
53a2db12 38class WXDLLIMPEXP_CORE wxControlBase : public wxWindow
8d99be5f
VZ
39{
40public:
c0e6c051 41 wxControlBase() { }
fc7a2a60 42
799ea011
GD
43 virtual ~wxControlBase();
44
1e6feb95
VZ
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
1e6feb95
VZ
53 // get the control alignment (left/right/centre, top/bottom/centre)
54 int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }
55
39bc0347
VZ
56 virtual void SetLabel(const wxString& label)
57 {
58 m_labelOrig = label;
59
60 InvalidateBestSize();
61
62 wxWindow::SetLabel(label);
63 }
64
65 virtual wxString GetLabel() const
66 {
67 // return the original string, as it was passed to SetLabel()
68 // (i.e. with wx-style mnemonics)
69 return m_labelOrig;
70 }
71
5b8b2c84
VZ
72 // get just the text of the label, without mnemonic characters ('&')
73 wxString GetLabelText() const { return GetLabelText(GetLabel()); }
74
75 void SetLabelText(const wxString& text)
76 {
440d3d2a 77 SetLabel(EscapeMnemonics(text));
5b8b2c84
VZ
78 }
79
39bc0347
VZ
80 // static utilities:
81
5c87527c
FM
82 // replaces parts of the string with ellipsis if needed
83 static wxString Ellipsize(const wxString& label, const wxDC& dc,
84 wxEllipsizeMode mode, int maxWidth);
85
74639764
VZ
86 // get the string without mnemonic characters ('&')
87 static wxString GetLabelText(const wxString& label);
88
39bc0347
VZ
89 // removes the mnemonics characters
90 static wxString RemoveMnemonics(const wxString& str);
91
5b8b2c84
VZ
92 // escapes (by doubling them) the mnemonics
93 static wxString EscapeMnemonics(const wxString& str);
94
916eabe6
VZ
95 // return the accel index in the string or -1 if none and puts the modified
96 // string into second parameter if non NULL
97 static int FindAccelIndex(const wxString& label,
98 wxString *labelOnly = NULL);
99
9f4b4671 100
d4864e97
VZ
101 // controls by default inherit the colours of their parents, if a
102 // particular control class doesn't want to do it, it can override
103 // ShouldInheritColours() to return false
104 virtual bool ShouldInheritColours() const { return true; }
105
9f4b4671
VZ
106
107 // WARNING: this doesn't work for all controls nor all platforms!
108 //
109 // simulates the event of given type (i.e. wxButton::Command() is just as
110 // if the button was clicked)
111 virtual void Command(wxCommandEvent &event);
112
9f884528
RD
113 virtual bool SetFont(const wxFont& font);
114
a3a4105d
VZ
115 // wxControl-specific processing after processing the update event
116 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
117
8d99be5f 118protected:
dc797d8e
JS
119 // choose the default border for this window
120 virtual wxBorder GetDefaultBorder() const;
121
3f2711d5
VZ
122 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
123 // to the list of parents children
8d99be5f
VZ
124 bool CreateControl(wxWindowBase *parent,
125 wxWindowID id,
126 const wxPoint& pos,
127 const wxSize& size,
128 long style,
129 const wxValidator& validator,
130 const wxString& name);
131
bfbd6dc1
VZ
132 // initialize the common fields of wxCommandEvent
133 void InitCommandEvent(wxCommandEvent& event) const;
fc7a2a60 134
39bc0347
VZ
135 // this field contains the label in wx format, i.e. with '&' mnemonics
136 wxString m_labelOrig;
137
fc7a2a60 138 DECLARE_NO_COPY_CLASS(wxControlBase)
8d99be5f
VZ
139};
140
141// ----------------------------------------------------------------------------
142// include platform-dependent wxControl declarations
143// ----------------------------------------------------------------------------
f03fc89f 144
1e6feb95
VZ
145#if defined(__WXUNIVERSAL__)
146 #include "wx/univ/control.h"
4055ed82 147#elif defined(__WXPALMOS__)
ffecfa5a 148 #include "wx/palmos/control.h"
1e6feb95 149#elif defined(__WXMSW__)
8d99be5f 150 #include "wx/msw/control.h"
2049ba38 151#elif defined(__WXMOTIF__)
8d99be5f 152 #include "wx/motif/control.h"
1be7a35c 153#elif defined(__WXGTK20__)
8d99be5f 154 #include "wx/gtk/control.h"
1be7a35c
MR
155#elif defined(__WXGTK__)
156 #include "wx/gtk1/control.h"
34138703 157#elif defined(__WXMAC__)
ef0e9220 158 #include "wx/osx/control.h"
e64df9bc
DE
159#elif defined(__WXCOCOA__)
160 #include "wx/cocoa/control.h"
1777b9bb
DW
161#elif defined(__WXPM__)
162 #include "wx/os2/control.h"
c801d85f
KB
163#endif
164
1e6feb95
VZ
165#endif // wxUSE_CONTROLS
166
c801d85f 167#endif
34138703 168 // _WX_CONTROL_H_BASE_