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
,
65 const wxValidator
& validator
,
68 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
72 SetValidator(validator
);
78 bool wxControl::MSWCreateControl(const wxChar
*classname
,
79 const wxString
& label
,
84 WXDWORD msStyle
= MSWGetStyle(GetWindowStyle(), &exstyle
);
86 return MSWCreateControl(classname
, msStyle
, pos
, size
, label
, exstyle
);
89 bool wxControl::MSWCreateControl(const wxChar
*classname
,
93 const wxString
& label
,
96 // want3D tells us whether or not the style specified a 3D border.
97 // If so, under WIN16 we can use Ctl3D to give it an appropriate style.
98 // Sometimes want3D is used to indicate that the non-extended style should have
102 // if no extended style given, determine it ourselves
103 if ( exstyle
== (WXDWORD
)-1 )
105 exstyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
108 // all controls should have this style
111 // create the control visible if it's currently shown for wxWindows
117 int x
= pos
.x
== -1 ? 0 : pos
.x
,
118 y
= pos
.y
== -1 ? 0 : pos
.y
,
119 w
= size
.x
== -1 ? 0 : size
.x
,
120 h
= size
.y
== -1 ? 0 : size
.y
;
122 m_hWnd
= (WXHWND
)::CreateWindowEx
124 exstyle
, // extended style
125 classname
, // the kind of control to create
126 label
, // the window name
127 style
, // the window style
128 x
, y
, w
, h
, // the window position and size
129 GetHwndOf(GetParent()), // parent
130 (HMENU
)GetId(), // child id
131 wxGetInstance(), // app instance
132 NULL
// creation parameters
137 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname
);
138 wxFAIL_MSG(_T("something is very wrong"));
146 Ctl3dSubclassCtl(GetHwnd());
149 #endif // wxUSE_CTL3D
151 // install wxWindows window proc for this window
154 // controls use the same font and colours as their parent dialog by default
157 // set the size now if no initial size specified
158 if ( w
<= 0 || h
<= 0 )
166 wxSize
wxControl::DoGetBestSize() const
168 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
171 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
173 #if WXWIN_COMPATIBILITY
176 (void)(*m_callback
)(*this, event
);
181 #endif // WXWIN_COMPATIBILITY
183 return GetEventHandler()->ProcessEvent(event
);
187 bool wxControl::MSWOnNotify(int idCtrl
,
191 wxEventType eventType
= wxEVT_NULL
;
193 NMHDR
*hdr
= (NMHDR
*) lParam
;
197 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
201 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
205 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
209 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
213 eventType
= wxEVT_COMMAND_SET_FOCUS
;
217 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
221 eventType
= wxEVT_COMMAND_ENTER
;
225 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
228 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
229 event
.SetEventType(eventType
);
230 event
.SetEventObject(this);
232 return GetEventHandler()->ProcessEvent(event
);
236 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
238 // notice that this 'dumb' implementation may cause flicker for some of the
239 // controls in which case they should intercept wxEraseEvent and process it
240 // themselves somehow
243 ::GetClientRect(GetHwnd(), &rect
);
245 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
247 HDC hdc
= GetHdcOf((*event
.GetDC()));
248 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
250 ::FillRect(hdc
, &rect
, hBrush
);
251 ::DeleteObject(hBrush
);
252 ::SetMapMode(hdc
, mode
);
255 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
261 WXUINT
WXUNUSED(message
),
262 WXWPARAM
WXUNUSED(wParam
),
263 WXLPARAM
WXUNUSED(lParam
)
270 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
271 return (WXHBRUSH
) hbrush
;
273 #endif // wxUSE_CTL3D
276 if (GetParent()->GetTransparentBackground())
277 SetBkMode(hdc
, TRANSPARENT
);
279 SetBkMode(hdc
, OPAQUE
);
281 wxColour colBack
= GetBackgroundColour();
283 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
284 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
286 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
288 return (WXHBRUSH
)brush
->GetResourceHandle();
291 WXDWORD
wxControl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
293 long msStyle
= wxWindow::MSWGetStyle(style
, exstyle
);
295 if ( AcceptsFocus() )
297 msStyle
|= WS_TABSTOP
;
303 // ---------------------------------------------------------------------------
305 // ---------------------------------------------------------------------------
307 // Call this repeatedly for several wnds to find the overall size
309 // Call it initially with -1 for all values in rect.
310 // Keep calling for other widgets, and rect will be modified
311 // to calculate largest bounding rectangle.
312 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
314 int left
= rect
->left
;
315 int right
= rect
->right
;
317 int bottom
= rect
->bottom
;
319 GetWindowRect((HWND
) wnd
, rect
);
324 if (left
< rect
->left
)
327 if (right
> rect
->right
)
333 if (bottom
> rect
->bottom
)
334 rect
->bottom
= bottom
;
337 #endif // wxUSE_CONTROLS