1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxControl class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CONTROL_H_
13 #define _WX_CONTROL_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "control.h"
19 #include "wx/dynarray.h"
22 class WXDLLEXPORT wxControl
: public wxControlBase
27 wxControl(wxWindow
*parent
, wxWindowID id
,
28 const wxPoint
& pos
= wxDefaultPosition
,
29 const wxSize
& size
= wxDefaultSize
, long style
= 0,
30 const wxValidator
& validator
= wxDefaultValidator
,
31 const wxString
& name
= wxControlNameStr
)
33 Create(parent
, id
, pos
, size
, style
, validator
, name
);
36 bool Create(wxWindow
*parent
, wxWindowID id
,
37 const wxPoint
& pos
= wxDefaultPosition
,
38 const wxSize
& size
= wxDefaultSize
, long style
= 0,
39 const wxValidator
& validator
= wxDefaultValidator
,
40 const wxString
& name
= wxControlNameStr
);
45 virtual void Command(wxCommandEvent
& event
) { ProcessCommand(event
); }
48 // implementation from now on
49 // --------------------------
51 virtual wxVisualAttributes
GetDefaultAttributes() const
53 return GetClassDefaultAttributes(GetWindowVariant());
56 static wxVisualAttributes
57 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
59 // Calls the callback and appropriate event handlers
60 bool ProcessCommand(wxCommandEvent
& event
);
64 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
67 // For ownerdraw items
68 virtual bool MSWOnDraw(WXDRAWITEMSTRUCT
*WXUNUSED(item
)) { return false; };
69 virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT
*WXUNUSED(item
)) { return false; };
71 const wxArrayLong
& GetSubcontrols() const { return m_subControls
; }
74 // choose the default border for this window
75 virtual wxBorder
GetDefaultBorder() const;
77 // return default best size (doesn't really make any sense, override this)
78 virtual wxSize
DoGetBestSize() const;
80 // This is a helper for all wxControls made with UPDOWN native control.
81 // In wxMSW it was only wxSpinCtrl derived from wxSpinButton but in
82 // WinCE of Smartphones this happens also for native wxTextCtrl,
83 // wxChoice and others.
84 virtual wxSize
GetBestSpinnerSize(const bool is_vertical
) const;
86 // create the control of the given Windows class: this is typically called
87 // from Create() method of the derived class passing its label, pos and
88 // size parameter (style parameter is not needed because m_windowStyle is
89 // supposed to had been already set and so is used instead when this
90 // function is called)
91 bool MSWCreateControl(const wxChar
*classname
,
92 const wxString
& label
,
96 // NB: the method below is deprecated now, with MSWGetStyle() the method
97 // above should be used instead! Once all the controls are updated to
98 // implement MSWGetStyle() this version will disappear.
100 // create the control of the given class with the given style (combination
101 // of WS_XXX flags, i.e. Windows style, not wxWidgets one), returns
102 // false if creation failed
104 // All parameters except classname and style are optional, if the
105 // size/position are not given, they should be set later with SetSize()
106 // and, label (the title of the window), of course, is left empty. The
107 // extended style is determined from the style and the app 3D settings
108 // automatically if it's not specified explicitly.
109 bool MSWCreateControl(const wxChar
*classname
,
111 const wxPoint
& pos
= wxDefaultPosition
,
112 const wxSize
& size
= wxDefaultSize
,
113 const wxString
& label
= wxEmptyString
,
114 WXDWORD exstyle
= (WXDWORD
)-1);
116 // default style for the control include WS_TABSTOP if it AcceptsFocus()
117 virtual WXDWORD
MSWGetStyle(long style
, WXDWORD
*exstyle
) const;
119 // default handling of WM_CTLCOLORxxx
120 virtual WXHBRUSH
MSWControlColor(WXHDC pDC
);
122 // call this from the derived class MSWControlColor() if you want to show
123 // the control greyed out (and opaque)
124 WXHBRUSH
MSWControlColorDisabled(WXHDC pDC
);
126 // call this from the derived class MSWControlColor() if you want to always
127 // paint the background (as all opaque controls do)
128 WXHBRUSH
MSWControlColorSolid(WXHDC pDC
)
130 return DoMSWControlColor(pDC
, GetBackgroundColour());
133 // common part of the 3 functions above: pass wxNullColour to use the
134 // appropriate background colour (meaning ours or our parents) or a fixed
136 WXHBRUSH
DoMSWControlColor(WXHDC pDC
, wxColour colBg
);
138 // another WM_CTLCOLOR-related function: override this to return the brush
139 // which should be used to paint the control background by default
141 // for most controls, the default behaviour of returning 0 and letting the
142 // system do it is correct, but for some -- e.g. checkboxes -- we actually
143 // have to return transparent brush from here to prevent the system from
144 // overwriting background with solid colour
145 virtual WXHBRUSH
MSWGetDefaultBgBrush() { return 0; }
147 // this is a helper for the derived class GetClassDefaultAttributes()
148 // implementation: it returns the right colours for the classes which
149 // contain something else (e.g. wxListBox, wxTextCtrl, ...) instead of
150 // being simple controls (such as wxButton, wxCheckBox, ...)
151 static wxVisualAttributes
152 GetCompositeControlsDefaultAttributes(wxWindowVariant variant
);
154 // for controls like radiobuttons which are really composite this array
155 // holds the ids (not HWNDs!) of the sub controls
156 wxArrayLong m_subControls
;
159 DECLARE_DYNAMIC_CLASS_NO_COPY(wxControl
)
162 #endif // _WX_CONTROL_H_