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__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
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
,
64 const wxValidator
& validator
,
68 bool rval
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
71 SetValidator(validator
);
77 bool wxControl::MSWCreateControl(const wxChar
*classname
,
81 const wxString
& label
,
84 // VZ: if someone could put a comment here explaining what exactly this is
85 // needed for, it would be nice...
88 // if no extended style given, determine it ourselves
89 if ( exstyle
== (WXDWORD
)-1 )
91 exstyle
= GetExStyle(style
, &want3D
);
94 // all controls have these childs (wxWindows creates all controls visible
96 style
|= WS_CHILD
| WS_VISIBLE
;
98 m_hWnd
= (WXHWND
)::CreateWindowEx
100 exstyle
, // extended style
101 classname
, // the kind of control to create
102 label
, // the window name
103 style
, // the window style
104 pos
.x
, pos
.y
, // the window position
105 size
.x
, size
.y
, // and size
106 GetHwndOf(GetParent()), // parent
107 (HMENU
)GetId(), // child id
108 wxGetInstance(), // app instance
109 NULL
// creation parameters
115 wxLogError(wxT("Failed to create a control of class '%s'"), classname
);
124 Ctl3dSubclassCtl(GetHwnd());
127 #endif // wxUSE_CTL3D
129 // subclass again for purposes of dialog editing mode
132 // controls use the same font and colours as their parent dialog by default
138 wxSize
wxControl::DoGetBestSize() const
140 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
143 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
145 #if WXWIN_COMPATIBILITY
148 (void)(*m_callback
)(this, event
);
153 #endif // WXWIN_COMPATIBILITY
155 return GetEventHandler()->ProcessEvent(event
);
159 bool wxControl::MSWOnNotify(int idCtrl
,
163 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
164 wxEventType eventType
= wxEVT_NULL
;
165 NMHDR
*hdr1
= (NMHDR
*) lParam
;
166 switch ( hdr1
->code
)
169 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
173 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
177 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
181 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
185 eventType
= wxEVT_COMMAND_SET_FOCUS
;
189 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
193 eventType
= wxEVT_COMMAND_ENTER
;
197 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
200 event
.SetEventType(eventType
);
201 event
.SetEventObject(this);
203 return GetEventHandler()->ProcessEvent(event
);
207 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
209 // In general, you don't want to erase the background of a control,
210 // or you'll get a flicker.
211 // TODO: move this 'null' function into each control that
215 ::GetClientRect(GetHwnd(), &rect
);
217 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
219 HDC hdc
= GetHdcOf((*event
.GetDC()));
220 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
222 ::FillRect(hdc
, &rect
, hBrush
);
223 ::DeleteObject(hBrush
);
224 ::SetMapMode(hdc
, mode
);
227 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
235 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
236 return (WXHBRUSH
) hbrush
;
238 #endif // wxUSE_CTL3D
241 if (GetParent()->GetTransparentBackground())
242 SetBkMode(hdc
, TRANSPARENT
);
244 SetBkMode(hdc
, OPAQUE
);
246 const wxColour
& colBack
= GetBackgroundColour();
247 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
248 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
250 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
252 return (WXHBRUSH
)brush
->GetResourceHandle();
255 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
, bool *want3D
) const
257 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, want3D
);
259 // Even with extended styles, need to combine with WS_BORDER for them to
261 if ( *want3D
|| wxStyleHasBorder(m_windowStyle
) )
267 // ---------------------------------------------------------------------------
269 // ---------------------------------------------------------------------------
271 // Call this repeatedly for several wnds to find the overall size
273 // Call it initially with -1 for all values in rect.
274 // Keep calling for other widgets, and rect will be modified
275 // to calculate largest bounding rectangle.
276 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
278 int left
= rect
->left
;
279 int right
= rect
->right
;
281 int bottom
= rect
->bottom
;
283 GetWindowRect((HWND
) wnd
, rect
);
288 if (left
< rect
->left
)
291 if (right
> rect
->right
)
297 if (bottom
> rect
->bottom
)
298 rect
->bottom
= bottom
;