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 m_hWnd
= (WXHWND
)::CreateWindowEx
103 exstyle
, // extended style
104 classname
, // the kind of control to create
105 label
, // the window name
106 style
, // the window style
107 pos
.x
, pos
.y
, // the window position
108 size
.x
, size
.y
, // and size
109 GetHwndOf(GetParent()), // parent
110 (HMENU
)GetId(), // child id
111 wxGetInstance(), // app instance
112 NULL
// creation parameters
117 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname
);
118 wxFAIL_MSG(_T("something is very wrong"));
126 Ctl3dSubclassCtl(GetHwnd());
129 #endif // wxUSE_CTL3D
131 // install wxWindows window proc for this window
134 // controls use the same font and colours as their parent dialog by default
140 wxSize
wxControl::DoGetBestSize() const
142 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
145 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
147 #if WXWIN_COMPATIBILITY
150 (void)(*m_callback
)(*this, event
);
155 #endif // WXWIN_COMPATIBILITY
157 return GetEventHandler()->ProcessEvent(event
);
161 bool wxControl::MSWOnNotify(int idCtrl
,
165 wxEventType eventType
= wxEVT_NULL
;
167 NMHDR
*hdr
= (NMHDR
*) lParam
;
171 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
175 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
179 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
183 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
187 eventType
= wxEVT_COMMAND_SET_FOCUS
;
191 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
195 eventType
= wxEVT_COMMAND_ENTER
;
199 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
202 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
203 event
.SetEventType(eventType
);
204 event
.SetEventObject(this);
206 return GetEventHandler()->ProcessEvent(event
);
210 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
212 // notice that this 'dumb' implementation may cause flicker for some of the
213 // controls in which case they should intercept wxEraseEvent and process it
214 // themselves somehow
217 ::GetClientRect(GetHwnd(), &rect
);
219 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
221 HDC hdc
= GetHdcOf((*event
.GetDC()));
222 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
224 ::FillRect(hdc
, &rect
, hBrush
);
225 ::DeleteObject(hBrush
);
226 ::SetMapMode(hdc
, mode
);
229 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
235 WXUINT
WXUNUSED(message
),
236 WXWPARAM
WXUNUSED(wParam
),
237 WXLPARAM
WXUNUSED(lParam
)
244 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
245 return (WXHBRUSH
) hbrush
;
247 #endif // wxUSE_CTL3D
250 if (GetParent()->GetTransparentBackground())
251 SetBkMode(hdc
, TRANSPARENT
);
253 SetBkMode(hdc
, OPAQUE
);
255 wxColour colBack
= GetBackgroundColour();
257 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
258 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
260 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
262 return (WXHBRUSH
)brush
->GetResourceHandle();
265 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
, bool *want3D
) const
267 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, want3D
);
269 // Even with extended styles, need to combine with WS_BORDER for them to
271 if ( *want3D
|| wxStyleHasBorder(m_windowStyle
) )
277 // ---------------------------------------------------------------------------
279 // ---------------------------------------------------------------------------
281 // Call this repeatedly for several wnds to find the overall size
283 // Call it initially with -1 for all values in rect.
284 // Keep calling for other widgets, and rect will be modified
285 // to calculate largest bounding rectangle.
286 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
288 int left
= rect
->left
;
289 int right
= rect
->right
;
291 int bottom
= rect
->bottom
;
293 GetWindowRect((HWND
) wnd
, rect
);
298 if (left
< rect
->left
)
301 if (right
> rect
->right
)
307 if (bottom
> rect
->bottom
)
308 rect
->bottom
= bottom
;
311 #endif // wxUSE_CONTROLS