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 m_backgroundColour
= *wxWHITE
;
50 m_foregroundColour
= *wxBLACK
;
52 #if WXWIN_COMPATIBILITY
54 #endif // WXWIN_COMPATIBILITY
57 wxControl::~wxControl()
59 m_isBeingDeleted
= TRUE
;
63 bool wxControl::Create(wxWindow
*parent
, wxWindowID id
,
65 const wxSize
& size
, long style
,
66 const wxValidator
& validator
,
69 bool rval
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
72 SetValidator(validator
);
78 bool wxControl::MSWCreateControl(const wxChar
*classname
,
82 const wxString
& label
,
85 // want3D tells us whether or not the style specified a 3D border.
86 // If so, under WIN16 we can use Ctl3D to give it an appropriate style.
87 // Sometimes want3D is used to indicate that the non-extended style should have
91 // if no extended style given, determine it ourselves
92 if ( exstyle
== (WXDWORD
)-1 )
94 exstyle
= GetExStyle(style
, &want3D
);
97 // all controls have these styles (wxWindows creates all controls visible
99 style
|= WS_CHILD
| WS_VISIBLE
;
101 int x
= pos
.x
== -1 ? 0 : pos
.x
,
102 y
= pos
.y
== -1 ? 0 : pos
.y
,
103 w
= size
.x
== -1 ? 0 : size
.x
,
104 h
= size
.y
== -1 ? 0 : size
.y
;
106 m_hWnd
= (WXHWND
)::CreateWindowEx
108 exstyle
, // extended style
109 classname
, // the kind of control to create
110 label
, // the window name
111 style
, // the window style
112 x
, y
, w
, h
, // the window position and size
113 GetHwndOf(GetParent()), // parent
114 (HMENU
)GetId(), // child id
115 wxGetInstance(), // app instance
116 NULL
// creation parameters
121 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname
);
122 wxFAIL_MSG(_T("something is very wrong"));
130 Ctl3dSubclassCtl(GetHwnd());
133 #endif // wxUSE_CTL3D
135 // install wxWindows window proc for this window
138 // controls use the same font and colours as their parent dialog by default
141 // set the size now if no initial size specified
142 if ( w
== 0 || h
== 0 )
150 wxSize
wxControl::DoGetBestSize() const
152 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
155 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
157 #if WXWIN_COMPATIBILITY
160 (void)(*m_callback
)(*this, event
);
165 #endif // WXWIN_COMPATIBILITY
167 return GetEventHandler()->ProcessEvent(event
);
171 bool wxControl::MSWOnNotify(int idCtrl
,
175 wxEventType eventType
= wxEVT_NULL
;
177 NMHDR
*hdr
= (NMHDR
*) lParam
;
181 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
185 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
189 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
193 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
197 eventType
= wxEVT_COMMAND_SET_FOCUS
;
201 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
205 eventType
= wxEVT_COMMAND_ENTER
;
209 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
212 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
213 event
.SetEventType(eventType
);
214 event
.SetEventObject(this);
216 return GetEventHandler()->ProcessEvent(event
);
220 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
222 // notice that this 'dumb' implementation may cause flicker for some of the
223 // controls in which case they should intercept wxEraseEvent and process it
224 // themselves somehow
227 ::GetClientRect(GetHwnd(), &rect
);
229 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
231 HDC hdc
= GetHdcOf((*event
.GetDC()));
232 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
234 ::FillRect(hdc
, &rect
, hBrush
);
235 ::DeleteObject(hBrush
);
236 ::SetMapMode(hdc
, mode
);
239 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
245 WXUINT
WXUNUSED(message
),
246 WXWPARAM
WXUNUSED(wParam
),
247 WXLPARAM
WXUNUSED(lParam
)
254 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
255 return (WXHBRUSH
) hbrush
;
257 #endif // wxUSE_CTL3D
260 if (GetParent()->GetTransparentBackground())
261 SetBkMode(hdc
, TRANSPARENT
);
263 SetBkMode(hdc
, OPAQUE
);
265 wxColour colBack
= GetBackgroundColour();
267 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
268 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
270 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
272 return (WXHBRUSH
)brush
->GetResourceHandle();
275 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
, bool *want3D
) const
277 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, want3D
);
279 // Even with extended styles, need to combine with WS_BORDER for them to
281 if ( *want3D
|| wxStyleHasBorder(m_windowStyle
) )
287 // ---------------------------------------------------------------------------
289 // ---------------------------------------------------------------------------
291 // Call this repeatedly for several wnds to find the overall size
293 // Call it initially with -1 for all values in rect.
294 // Keep calling for other widgets, and rect will be modified
295 // to calculate largest bounding rectangle.
296 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
298 int left
= rect
->left
;
299 int right
= rect
->right
;
301 int bottom
= rect
->bottom
;
303 GetWindowRect((HWND
) wnd
, rect
);
308 if (left
< rect
->left
)
311 if (right
> rect
->right
)
317 if (bottom
> rect
->bottom
)
318 rect
->bottom
= bottom
;
321 #endif // wxUSE_CONTROLS