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 )
99 // exstyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
101 (void) MSWGetStyle(GetWindowStyle(), & exstyle
) ;
104 // all controls should have this style
107 // create the control visible if it's currently shown for wxWindows
113 int x
= pos
.x
== -1 ? 0 : pos
.x
,
114 y
= pos
.y
== -1 ? 0 : pos
.y
,
115 w
= size
.x
== -1 ? 0 : size
.x
,
116 h
= size
.y
== -1 ? 0 : size
.y
;
118 m_hWnd
= (WXHWND
)::CreateWindowEx
120 exstyle
, // extended style
121 classname
, // the kind of control to create
122 label
, // the window name
123 style
, // the window style
124 x
, y
, w
, h
, // the window position and size
125 GetHwndOf(GetParent()), // parent
126 (HMENU
)GetId(), // child id
127 wxGetInstance(), // app instance
128 NULL
// creation parameters
133 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname
);
134 wxFAIL_MSG(_T("something is very wrong"));
142 Ctl3dSubclassCtl(GetHwnd());
145 #endif // wxUSE_CTL3D
147 // install wxWindows window proc for this window
150 // controls use the same font and colours as their parent dialog by default
153 // set the size now if no initial size specified
154 if ( w
<= 0 || h
<= 0 )
162 wxSize
wxControl::DoGetBestSize() const
164 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
167 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
169 #if WXWIN_COMPATIBILITY
172 (void)(*m_callback
)(*this, event
);
177 #endif // WXWIN_COMPATIBILITY
179 return GetEventHandler()->ProcessEvent(event
);
183 bool wxControl::MSWOnNotify(int idCtrl
,
187 wxEventType eventType
= wxEVT_NULL
;
189 NMHDR
*hdr
= (NMHDR
*) lParam
;
193 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
197 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
201 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
205 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
209 eventType
= wxEVT_COMMAND_SET_FOCUS
;
213 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
217 eventType
= wxEVT_COMMAND_ENTER
;
221 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
224 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
225 event
.SetEventType(eventType
);
226 event
.SetEventObject(this);
228 return GetEventHandler()->ProcessEvent(event
);
232 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
234 // notice that this 'dumb' implementation may cause flicker for some of the
235 // controls in which case they should intercept wxEraseEvent and process it
236 // themselves somehow
239 ::GetClientRect(GetHwnd(), &rect
);
241 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
243 HDC hdc
= GetHdcOf((*event
.GetDC()));
244 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
246 ::FillRect(hdc
, &rect
, hBrush
);
247 ::DeleteObject(hBrush
);
248 ::SetMapMode(hdc
, mode
);
251 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
257 WXUINT
WXUNUSED(message
),
258 WXWPARAM
WXUNUSED(wParam
),
259 WXLPARAM
WXUNUSED(lParam
)
266 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
267 return (WXHBRUSH
) hbrush
;
269 #endif // wxUSE_CTL3D
272 if (GetParent()->GetTransparentBackground())
273 SetBkMode(hdc
, TRANSPARENT
);
275 SetBkMode(hdc
, OPAQUE
);
277 wxColour colBack
= GetBackgroundColour();
279 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
280 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
282 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
284 return (WXHBRUSH
)brush
->GetResourceHandle();
287 WXDWORD
wxControl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
289 long msStyle
= wxWindow::MSWGetStyle(style
, exstyle
);
291 if ( AcceptsFocus() )
293 msStyle
|= WS_TABSTOP
;
299 // ---------------------------------------------------------------------------
301 // ---------------------------------------------------------------------------
303 // Call this repeatedly for several wnds to find the overall size
305 // Call it initially with -1 for all values in rect.
306 // Keep calling for other widgets, and rect will be modified
307 // to calculate largest bounding rectangle.
308 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
310 int left
= rect
->left
;
311 int right
= rect
->right
;
313 int bottom
= rect
->bottom
;
315 GetWindowRect((HWND
) wnd
, rect
);
320 if (left
< rect
->left
)
323 if (right
> rect
->right
)
329 if (bottom
> rect
->bottom
)
330 rect
->bottom
= bottom
;
333 #endif // wxUSE_CONTROLS