1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/control.cpp
3 // Purpose: wxControl class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
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(__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 // if no extended style given, determine it ourselves
97 if ( exstyle
== (WXDWORD
)-1 )
100 (void) MSWGetStyle(GetWindowStyle(), &exstyle
);
103 // all controls should have this style
106 // create the control visible if it's currently shown for wxWindows
112 int x
= pos
.x
== -1 ? 0 : pos
.x
,
113 y
= pos
.y
== -1 ? 0 : pos
.y
,
114 w
= size
.x
== -1 ? 0 : size
.x
,
115 h
= size
.y
== -1 ? 0 : size
.y
;
117 m_hWnd
= (WXHWND
)::CreateWindowEx
119 exstyle
, // extended style
120 classname
, // the kind of control to create
121 label
, // the window name
122 style
, // the window style
123 x
, y
, w
, h
, // the window position and size
124 GetHwndOf(GetParent()), // parent
125 (HMENU
)GetId(), // child id
126 wxGetInstance(), // app instance
127 NULL
// creation parameters
132 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname
);
133 wxFAIL_MSG(_T("something is very wrong"));
141 Ctl3dSubclassCtl(GetHwnd());
144 #endif // wxUSE_CTL3D
146 // install wxWindows window proc for this window
149 // controls use the same font and colours as their parent dialog by default
152 // set the size now if no initial size specified
153 if ( w
<= 0 || h
<= 0 )
161 wxBorder
wxControl::GetDefaultBorder() const
163 // we want to automatically give controls a sunken style (confusingly,
164 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
165 // which is not sunken at all under Windows XP -- rather, just the default)
166 return wxBORDER_SUNKEN
;
169 wxSize
wxControl::DoGetBestSize() const
171 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
174 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
176 #if WXWIN_COMPATIBILITY
179 (void)(*m_callback
)(*this, event
);
184 #endif // WXWIN_COMPATIBILITY
186 return GetEventHandler()->ProcessEvent(event
);
190 bool wxControl::MSWOnNotify(int idCtrl
,
194 wxEventType eventType
= wxEVT_NULL
;
196 NMHDR
*hdr
= (NMHDR
*) lParam
;
200 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
204 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
208 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
212 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
216 eventType
= wxEVT_COMMAND_SET_FOCUS
;
220 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
224 eventType
= wxEVT_COMMAND_ENTER
;
228 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
231 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
232 event
.SetEventType(eventType
);
233 event
.SetEventObject(this);
235 return GetEventHandler()->ProcessEvent(event
);
239 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
241 // notice that this 'dumb' implementation may cause flicker for some of the
242 // controls in which case they should intercept wxEraseEvent and process it
243 // themselves somehow
246 ::GetClientRect(GetHwnd(), &rect
);
248 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
250 HDC hdc
= GetHdcOf((*event
.GetDC()));
251 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
253 ::FillRect(hdc
, &rect
, hBrush
);
254 ::DeleteObject(hBrush
);
255 ::SetMapMode(hdc
, mode
);
258 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
264 WXUINT
WXUNUSED(message
),
265 WXWPARAM
WXUNUSED(wParam
),
266 WXLPARAM
WXUNUSED(lParam
)
273 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
274 return (WXHBRUSH
) hbrush
;
276 #endif // wxUSE_CTL3D
279 wxColour colBack
= GetBackgroundColour();
281 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
282 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
284 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
286 return (WXHBRUSH
)brush
->GetResourceHandle();
289 WXDWORD
wxControl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
291 long msStyle
= wxWindow::MSWGetStyle(style
, exstyle
);
293 if ( AcceptsFocus() )
295 msStyle
|= WS_TABSTOP
;
301 // ---------------------------------------------------------------------------
303 // ---------------------------------------------------------------------------
305 // Call this repeatedly for several wnds to find the overall size
307 // Call it initially with -1 for all values in rect.
308 // Keep calling for other widgets, and rect will be modified
309 // to calculate largest bounding rectangle.
310 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
312 int left
= rect
->left
;
313 int right
= rect
->right
;
315 int bottom
= rect
->bottom
;
317 GetWindowRect((HWND
) wnd
, rect
);
322 if (left
< rect
->left
)
325 if (right
> rect
->right
)
331 if (bottom
> rect
->bottom
)
332 rect
->bottom
= bottom
;
335 #endif // wxUSE_CONTROLS