1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxControl class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "control.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/dcclient.h"
29 #include "wx/control.h"
31 #include "wx/msw/private.h"
33 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__))
37 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
39 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
40 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
44 wxControl::wxControl()
46 m_backgroundColour
= *wxWHITE
;
47 m_foregroundColour
= *wxBLACK
;
49 #if WXWIN_COMPATIBILITY
51 #endif // WXWIN_COMPATIBILITY
54 wxControl::~wxControl()
56 m_isBeingDeleted
= TRUE
;
60 bool wxControl::Create(wxWindow
*parent
, wxWindowID id
,
62 const wxSize
& size
, long style
,
63 const wxValidator
& validator
,
66 bool rval
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
69 SetValidator(validator
);
75 bool wxControl::MSWCreateControl(const wxChar
*classname
,
79 const wxString
& label
,
82 // VZ: if someone could put a comment here explaining what exactly this is
83 // needed for, it would be nice...
86 // if no extended style given, determine it ourselves
87 if ( exstyle
== (WXDWORD
)-1 )
89 exstyle
= GetExStyle(style
, &want3D
);
92 // all controls have these childs (wxWindows creates all controls visible
94 style
|= WS_CHILD
| WS_VISIBLE
;
96 m_hWnd
= (WXHWND
)::CreateWindowEx
98 exstyle
, // extended style
99 classname
, // the kind of control to create
100 label
, // the window name
101 style
, // the window style
102 pos
.x
, pos
.y
, // the window position
103 size
.x
, size
.y
, // and size
104 GetHwndOf(GetParent()), // parent
105 (HMENU
)GetId(), // child id
106 wxGetInstance(), // app instance
107 NULL
// creation parameters
113 wxLogError(wxT("Failed to create a control of class '%s'"), classname
);
122 Ctl3dSubclassCtl(GetHwnd());
125 #endif // wxUSE_CTL3D
127 // subclass again for purposes of dialog editing mode
130 // controls use the same font and colours as their parent dialog by default
136 wxSize
wxControl::DoGetBestSize() const
138 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
141 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
143 #if WXWIN_COMPATIBILITY
146 (void)(*m_callback
)(this, event
);
151 #endif // WXWIN_COMPATIBILITY
153 return GetEventHandler()->ProcessEvent(event
);
157 bool wxControl::MSWOnNotify(int idCtrl
,
161 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
162 wxEventType eventType
= wxEVT_NULL
;
163 NMHDR
*hdr1
= (NMHDR
*) lParam
;
164 switch ( hdr1
->code
)
167 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
171 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
175 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
179 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
183 eventType
= wxEVT_COMMAND_SET_FOCUS
;
187 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
191 eventType
= wxEVT_COMMAND_ENTER
;
195 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
198 event
.SetEventType(eventType
);
199 event
.SetEventObject(this);
201 return GetEventHandler()->ProcessEvent(event
);
205 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
207 // notice that this 'dumb' implementation may cause flicker for some of the
208 // controls in which case they should intercept wxEraseEvent and process it
209 // themselves somehow
212 ::GetClientRect(GetHwnd(), &rect
);
214 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
216 HDC hdc
= GetHdcOf((*event
.GetDC()));
217 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
219 ::FillRect(hdc
, &rect
, hBrush
);
220 ::DeleteObject(hBrush
);
221 ::SetMapMode(hdc
, mode
);
224 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
232 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
233 return (WXHBRUSH
) hbrush
;
235 #endif // wxUSE_CTL3D
238 if (GetParent()->GetTransparentBackground())
239 SetBkMode(hdc
, TRANSPARENT
);
241 SetBkMode(hdc
, OPAQUE
);
243 const wxColour
& colBack
= GetBackgroundColour();
244 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
245 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
247 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
249 return (WXHBRUSH
)brush
->GetResourceHandle();
252 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
, bool *want3D
) const
254 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, want3D
);
256 // Even with extended styles, need to combine with WS_BORDER for them to
258 if ( *want3D
|| wxStyleHasBorder(m_windowStyle
) )
264 // ---------------------------------------------------------------------------
266 // ---------------------------------------------------------------------------
268 // Call this repeatedly for several wnds to find the overall size
270 // Call it initially with -1 for all values in rect.
271 // Keep calling for other widgets, and rect will be modified
272 // to calculate largest bounding rectangle.
273 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
275 int left
= rect
->left
;
276 int right
= rect
->right
;
278 int bottom
= rect
->bottom
;
280 GetWindowRect((HWND
) wnd
, rect
);
285 if (left
< rect
->left
)
288 if (right
> rect
->right
)
294 if (bottom
> rect
->bottom
)
295 rect
->bottom
= bottom
;