Controls will readjust their size and minsize when SetLabel or SetFont
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "controlbase.h"
21 #endif
22
23 #include "wx/defs.h"
24
25 #if wxUSE_CONTROLS
26
27 #include "wx/window.h" // base class
28
29 WXDLLEXPORT_DATA(extern const wxChar*) wxControlNameStr;
30
31 // ----------------------------------------------------------------------------
32 // wxControl is the base class for all controls
33 // ----------------------------------------------------------------------------
34
35
36 class WXDLLEXPORT wxControlBase : public wxWindow
37 {
38 public:
39 wxControlBase() { Init(); }
40
41 virtual ~wxControlBase();
42
43 // Create() function adds the validator parameter
44 bool Create(wxWindow *parent, wxWindowID id,
45 const wxPoint& pos = wxDefaultPosition,
46 const wxSize& size = wxDefaultSize,
47 long style = 0,
48 const wxValidator& validator = wxDefaultValidator,
49 const wxString& name = wxControlNameStr);
50
51 // get the control alignment (left/right/centre, top/bottom/centre)
52 int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }
53
54
55 // controls by default inherit the colours of their parents, if a
56 // particular control class doesn't want to do it, it can override
57 // ShouldInheritColours() to return false
58 virtual bool ShouldInheritColours() const { return true; }
59
60
61 // WARNING: this doesn't work for all controls nor all platforms!
62 //
63 // simulates the event of given type (i.e. wxButton::Command() is just as
64 // if the button was clicked)
65 virtual void Command(wxCommandEvent &event);
66
67
68 virtual void SetLabel(const wxString& label);
69 virtual bool SetFont(const wxFont& font);
70 virtual bool GetAdjustMinSizeFlag() const { return m_adjustMinSize; }
71 void SetAdjustMinSizeFlag(bool adjust) { m_adjustMinSize = adjust; }
72
73
74 protected:
75 void Init();
76
77 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
78 // to the list of parents children
79 bool CreateControl(wxWindowBase *parent,
80 wxWindowID id,
81 const wxPoint& pos,
82 const wxSize& size,
83 long style,
84 const wxValidator& validator,
85 const wxString& name);
86
87 // initialize the common fields of wxCommandEvent
88 void InitCommandEvent(wxCommandEvent& event) const;
89
90 // set the initial window size if none is given (i.e. at least one of the
91 // components of the size passed to ctor/Create() is -1)
92 //
93 // normally just calls SetBestSize() but can be overridden not to do it for
94 // the controls which have to do some additional initialization (e.g. add
95 // strings to list box) before their best size can be accurately calculated
96 virtual void SetInitialBestSize(const wxSize& size)
97 {
98 SetBestSize(size);
99 }
100
101 // should minsize and size be adjusted when font or label change?
102 bool m_adjustMinSize;
103
104 DECLARE_NO_COPY_CLASS(wxControlBase)
105 };
106
107 // ----------------------------------------------------------------------------
108 // include platform-dependent wxControl declarations
109 // ----------------------------------------------------------------------------
110
111 #if defined(__WXUNIVERSAL__)
112 #include "wx/univ/control.h"
113 #elif defined(__WXMSW__)
114 #include "wx/msw/control.h"
115 #elif defined(__WXMOTIF__)
116 #include "wx/motif/control.h"
117 #elif defined(__WXGTK__)
118 #include "wx/gtk/control.h"
119 #elif defined(__WXMAC__)
120 #include "wx/mac/control.h"
121 #elif defined(__WXCOCOA__)
122 #include "wx/cocoa/control.h"
123 #elif defined(__WXPM__)
124 #include "wx/os2/control.h"
125 #endif
126
127 #endif // wxUSE_CONTROLS
128
129 #endif
130 // _WX_CONTROL_H_BASE_