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
,
85 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
87 return MSWCreateControl(classname
, msStyle
, pos
, size
, label
, exstyle
);
90 bool wxControl::MSWCreateControl(const wxChar
*classname
,
94 const wxString
& label
,
97 // want3D tells us whether or not the style specified a 3D border.
98 // If so, under WIN16 we can use Ctl3D to give it an appropriate style.
99 // Sometimes want3D is used to indicate that the non-extended style should have
103 // if no extended style given, determine it ourselves
104 if ( exstyle
== (WXDWORD
)-1 )
106 exstyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
109 // all controls should have this style
112 // create the control visible if it's currently shown for wxWindows
118 int x
= pos
.x
== -1 ? 0 : pos
.x
,
119 y
= pos
.y
== -1 ? 0 : pos
.y
,
120 w
= size
.x
== -1 ? 0 : size
.x
,
121 h
= size
.y
== -1 ? 0 : size
.y
;
123 m_hWnd
= (WXHWND
)::CreateWindowEx
125 exstyle
, // extended style
126 classname
, // the kind of control to create
127 label
, // the window name
128 style
, // the window style
129 x
, y
, w
, h
, // the window position and size
130 GetHwndOf(GetParent()), // parent
131 (HMENU
)GetId(), // child id
132 wxGetInstance(), // app instance
133 NULL
// creation parameters
138 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname
);
139 wxFAIL_MSG(_T("something is very wrong"));
147 Ctl3dSubclassCtl(GetHwnd());
150 #endif // wxUSE_CTL3D
152 // install wxWindows window proc for this window
155 // controls use the same font and colours as their parent dialog by default
158 // set the size now if no initial size specified
159 if ( w
== 0 || h
== 0 )
167 wxSize
wxControl::DoGetBestSize() const
169 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
172 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
174 #if WXWIN_COMPATIBILITY
177 (void)(*m_callback
)(*this, event
);
182 #endif // WXWIN_COMPATIBILITY
184 return GetEventHandler()->ProcessEvent(event
);
188 bool wxControl::MSWOnNotify(int idCtrl
,
192 wxEventType eventType
= wxEVT_NULL
;
194 NMHDR
*hdr
= (NMHDR
*) lParam
;
198 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
202 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
206 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
210 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
214 eventType
= wxEVT_COMMAND_SET_FOCUS
;
218 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
222 eventType
= wxEVT_COMMAND_ENTER
;
226 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
229 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
230 event
.SetEventType(eventType
);
231 event
.SetEventObject(this);
233 return GetEventHandler()->ProcessEvent(event
);
237 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
239 // notice that this 'dumb' implementation may cause flicker for some of the
240 // controls in which case they should intercept wxEraseEvent and process it
241 // themselves somehow
244 ::GetClientRect(GetHwnd(), &rect
);
246 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
248 HDC hdc
= GetHdcOf((*event
.GetDC()));
249 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
251 ::FillRect(hdc
, &rect
, hBrush
);
252 ::DeleteObject(hBrush
);
253 ::SetMapMode(hdc
, mode
);
256 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
262 WXUINT
WXUNUSED(message
),
263 WXWPARAM
WXUNUSED(wParam
),
264 WXLPARAM
WXUNUSED(lParam
)
271 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
272 return (WXHBRUSH
) hbrush
;
274 #endif // wxUSE_CTL3D
277 if (GetParent()->GetTransparentBackground())
278 SetBkMode(hdc
, TRANSPARENT
);
280 SetBkMode(hdc
, OPAQUE
);
282 wxColour colBack
= GetBackgroundColour();
284 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
285 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
287 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
289 return (WXHBRUSH
)brush
->GetResourceHandle();
292 WXDWORD
wxControl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
294 long msStyle
= wxWindow::MSWGetStyle(style
, exstyle
);
296 if ( AcceptsFocus() )
298 msStyle
|= WS_TABSTOP
;
304 // ---------------------------------------------------------------------------
306 // ---------------------------------------------------------------------------
308 // Call this repeatedly for several wnds to find the overall size
310 // Call it initially with -1 for all values in rect.
311 // Keep calling for other widgets, and rect will be modified
312 // to calculate largest bounding rectangle.
313 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
315 int left
= rect
->left
;
316 int right
= rect
->right
;
318 int bottom
= rect
->bottom
;
320 GetWindowRect((HWND
) wnd
, rect
);
325 if (left
< rect
->left
)
328 if (right
> rect
->right
)
334 if (bottom
> rect
->bottom
)
335 rect
->bottom
= bottom
;
338 #endif // wxUSE_CONTROLS