1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/control.cpp
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"
28 #include "wx/dcclient.h"
32 #include "wx/control.h"
34 #include "wx/msw/private.h"
36 #if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
40 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
42 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
43 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
47 wxControl::wxControl()
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 // want3D tells us whether or not the style specified a 3D border.
83 // If so, under WIN16 we can use Ctl3D to give it an appropriate style.
84 // Sometimes want3D is used to indicate that the non-extended style should have
88 // if no extended style given, determine it ourselves
89 if ( exstyle
== (WXDWORD
)-1 )
91 exstyle
= GetExStyle(style
, &want3D
);
94 // all controls have these styles (wxWindows creates all controls visible
96 style
|= WS_CHILD
| WS_VISIBLE
;
98 int x
= pos
.x
== -1 ? 0 : pos
.x
,
99 y
= pos
.y
== -1 ? 0 : pos
.y
,
100 w
= size
.x
== -1 ? 0 : size
.x
,
101 h
= size
.y
== -1 ? 0 : size
.y
;
103 m_hWnd
= (WXHWND
)::CreateWindowEx
105 exstyle
, // extended style
106 classname
, // the kind of control to create
107 label
, // the window name
108 style
, // the window style
109 x
, y
, w
, h
, // the window position and size
110 GetHwndOf(GetParent()), // parent
111 (HMENU
)GetId(), // child id
112 wxGetInstance(), // app instance
113 NULL
// creation parameters
118 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname
);
119 wxFAIL_MSG(_T("something is very wrong"));
127 Ctl3dSubclassCtl(GetHwnd());
130 #endif // wxUSE_CTL3D
132 // install wxWindows window proc for this window
135 // controls use the same font and colours as their parent dialog by default
138 // set the size now if no initial size specified
139 if ( w
== 0 || h
== 0 )
147 wxSize
wxControl::DoGetBestSize() const
149 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
152 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
154 #if WXWIN_COMPATIBILITY
157 (void)(*m_callback
)(*this, event
);
162 #endif // WXWIN_COMPATIBILITY
164 return GetEventHandler()->ProcessEvent(event
);
168 bool wxControl::MSWOnNotify(int idCtrl
,
172 wxEventType eventType
= wxEVT_NULL
;
174 NMHDR
*hdr
= (NMHDR
*) lParam
;
178 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
182 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
186 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
190 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
194 eventType
= wxEVT_COMMAND_SET_FOCUS
;
198 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
202 eventType
= wxEVT_COMMAND_ENTER
;
206 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
209 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
210 event
.SetEventType(eventType
);
211 event
.SetEventObject(this);
213 return GetEventHandler()->ProcessEvent(event
);
217 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
219 // notice that this 'dumb' implementation may cause flicker for some of the
220 // controls in which case they should intercept wxEraseEvent and process it
221 // themselves somehow
224 ::GetClientRect(GetHwnd(), &rect
);
226 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
228 HDC hdc
= GetHdcOf((*event
.GetDC()));
229 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
231 ::FillRect(hdc
, &rect
, hBrush
);
232 ::DeleteObject(hBrush
);
233 ::SetMapMode(hdc
, mode
);
236 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
242 WXUINT
WXUNUSED(message
),
243 WXWPARAM
WXUNUSED(wParam
),
244 WXLPARAM
WXUNUSED(lParam
)
251 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
252 return (WXHBRUSH
) hbrush
;
254 #endif // wxUSE_CTL3D
257 if (GetParent()->GetTransparentBackground())
258 SetBkMode(hdc
, TRANSPARENT
);
260 SetBkMode(hdc
, OPAQUE
);
262 wxColour colBack
= GetBackgroundColour();
264 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
265 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
267 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
269 return (WXHBRUSH
)brush
->GetResourceHandle();
272 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
, bool *want3D
) const
274 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, want3D
);
276 // Even with extended styles, need to combine with WS_BORDER for them to
278 if ( *want3D
|| wxStyleHasBorder(m_windowStyle
) )
284 // ---------------------------------------------------------------------------
286 // ---------------------------------------------------------------------------
288 // Call this repeatedly for several wnds to find the overall size
290 // Call it initially with -1 for all values in rect.
291 // Keep calling for other widgets, and rect will be modified
292 // to calculate largest bounding rectangle.
293 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
295 int left
= rect
->left
;
296 int right
= rect
->right
;
298 int bottom
= rect
->bottom
;
300 GetWindowRect((HWND
) wnd
, rect
);
305 if (left
< rect
->left
)
308 if (right
> rect
->right
)
314 if (bottom
> rect
->bottom
)
315 rect
->bottom
= bottom
;
318 #endif // wxUSE_CONTROLS