1 /////////////////////////////////////////////////////////////////////////////
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"
26 #include "wx/dcclient.h"
29 #include "wx/control.h"
31 #include "wx/msw/private.h"
33 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__))
37 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
39 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
40 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
44 wxControl::wxControl()
46 m_backgroundColour
= *wxWHITE
;
47 m_foregroundColour
= *wxBLACK
;
49 #if WXWIN_COMPATIBILITY
51 #endif // WXWIN_COMPATIBILITY
54 wxControl::~wxControl()
56 m_isBeingDeleted
= TRUE
;
60 bool wxControl::Create(wxWindow
*parent
, wxWindowID id
,
62 const wxSize
& size
, long style
,
63 const wxValidator
& validator
,
66 bool rval
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
69 SetValidator(validator
);
75 bool wxControl::MSWCreateControl(const wxChar
*classname
,
79 const wxString
& label
,
82 // want3D tells us whether or not the style specified a 3D border.
83 // If so, under WIN16 we can use Ctl3D to give it an appropriate style.
84 // Sometimes want3D is used to indicate that the non-extended style should have
88 // if no extended style given, determine it ourselves
89 if ( exstyle
== (WXDWORD
)-1 )
91 exstyle
= GetExStyle(style
, &want3D
);
94 // all controls have these styles (wxWindows creates all controls visible
96 style
|= WS_CHILD
| WS_VISIBLE
;
98 m_hWnd
= (WXHWND
)::CreateWindowEx
100 exstyle
, // extended style
101 classname
, // the kind of control to create
102 label
, // the window name
103 style
, // the window style
104 pos
.x
, pos
.y
, // the window position
105 size
.x
, size
.y
, // and size
106 GetHwndOf(GetParent()), // parent
107 (HMENU
)GetId(), // child id
108 wxGetInstance(), // app instance
109 NULL
// creation parameters
114 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname
);
115 wxFAIL_MSG(_T("something is very wrong"));
123 Ctl3dSubclassCtl(GetHwnd());
126 #endif // wxUSE_CTL3D
128 // subclass again for purposes of dialog editing mode
131 // controls use the same font and colours as their parent dialog by default
137 wxSize
wxControl::DoGetBestSize() const
139 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
142 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
144 #if WXWIN_COMPATIBILITY
147 (void)(*m_callback
)(*this, event
);
152 #endif // WXWIN_COMPATIBILITY
154 return GetEventHandler()->ProcessEvent(event
);
158 bool wxControl::MSWOnNotify(int idCtrl
,
162 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
163 wxEventType eventType
= wxEVT_NULL
;
164 NMHDR
*hdr1
= (NMHDR
*) lParam
;
165 switch ( hdr1
->code
)
168 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
172 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
176 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
180 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
184 eventType
= wxEVT_COMMAND_SET_FOCUS
;
188 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
192 eventType
= wxEVT_COMMAND_ENTER
;
196 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
199 event
.SetEventType(eventType
);
200 event
.SetEventObject(this);
202 return GetEventHandler()->ProcessEvent(event
);
206 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
208 // notice that this 'dumb' implementation may cause flicker for some of the
209 // controls in which case they should intercept wxEraseEvent and process it
210 // themselves somehow
213 ::GetClientRect(GetHwnd(), &rect
);
215 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
217 HDC hdc
= GetHdcOf((*event
.GetDC()));
218 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
220 ::FillRect(hdc
, &rect
, hBrush
);
221 ::DeleteObject(hBrush
);
222 ::SetMapMode(hdc
, mode
);
225 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
233 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
234 return (WXHBRUSH
) hbrush
;
236 #endif // wxUSE_CTL3D
239 if (GetParent()->GetTransparentBackground())
240 SetBkMode(hdc
, TRANSPARENT
);
242 SetBkMode(hdc
, OPAQUE
);
244 wxColour colBack
= GetBackgroundColour();
246 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
247 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
249 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
251 return (WXHBRUSH
)brush
->GetResourceHandle();
254 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
, bool *want3D
) const
256 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, want3D
);
258 // Even with extended styles, need to combine with WS_BORDER for them to
260 if ( *want3D
|| wxStyleHasBorder(m_windowStyle
) )
266 // ---------------------------------------------------------------------------
268 // ---------------------------------------------------------------------------
270 // Call this repeatedly for several wnds to find the overall size
272 // Call it initially with -1 for all values in rect.
273 // Keep calling for other widgets, and rect will be modified
274 // to calculate largest bounding rectangle.
275 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
277 int left
= rect
->left
;
278 int right
= rect
->right
;
280 int bottom
= rect
->bottom
;
282 GetWindowRect((HWND
) wnd
, rect
);
287 if (left
< rect
->left
)
290 if (right
> rect
->right
)
296 if (bottom
> rect
->bottom
)
297 rect
->bottom
= bottom
;