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__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
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
;
59 bool wxControl::MSWCreateControl(const wxChar
*classname
,
63 const wxString
& label
,
66 // VZ: if someone could put a comment here explaining what exactly this is
67 // needed for, it would be nice...
70 // if no extended style given, determine it ourselves
71 if ( exstyle
== (WXDWORD
)-1 )
73 exstyle
= GetExStyle(style
, &want3D
);
76 // all controls have these childs (wxWindows creates all controls visible
78 style
|= WS_CHILD
| WS_VISIBLE
;
80 m_hWnd
= (WXHWND
)::CreateWindowEx
82 exstyle
, // extended style
83 classname
, // the kind of control to create
84 label
, // the window name
85 style
, // the window style
86 pos
.x
, pos
.y
, // the window position
87 size
.x
, size
.y
, // and size
88 GetHwndOf(GetParent()), // parent
89 (HMENU
)GetId(), // child id
90 wxGetInstance(), // app instance
91 NULL
// creation parameters
97 wxLogError(wxT("Failed to create a control of class '%s'"), classname
);
106 Ctl3dSubclassCtl(GetHwnd());
109 #endif // wxUSE_CTL3D
111 // subclass again for purposes of dialog editing mode
114 // controls use the same font and colours as their parent dialog by default
120 wxSize
wxControl::DoGetBestSize() const
122 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
125 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
127 #if WXWIN_COMPATIBILITY
130 (void)(*m_callback
)(this, event
);
135 #endif // WXWIN_COMPATIBILITY
137 return GetEventHandler()->ProcessEvent(event
);
141 bool wxControl::MSWOnNotify(int idCtrl
,
145 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
146 wxEventType eventType
= wxEVT_NULL
;
147 NMHDR
*hdr1
= (NMHDR
*) lParam
;
148 switch ( hdr1
->code
)
151 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
155 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
159 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
163 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
167 eventType
= wxEVT_COMMAND_SET_FOCUS
;
171 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
175 eventType
= wxEVT_COMMAND_ENTER
;
179 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
182 event
.SetEventType(eventType
);
183 event
.SetEventObject(this);
185 return GetEventHandler()->ProcessEvent(event
);
189 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
191 // In general, you don't want to erase the background of a control,
192 // or you'll get a flicker.
193 // TODO: move this 'null' function into each control that
197 ::GetClientRect(GetHwnd(), &rect
);
199 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
201 HDC hdc
= GetHdcOf((*event
.GetDC()));
202 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
204 ::FillRect(hdc
, &rect
, hBrush
);
205 ::DeleteObject(hBrush
);
206 ::SetMapMode(hdc
, mode
);
209 WXHBRUSH
wxControl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
217 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
218 return (WXHBRUSH
) hbrush
;
220 #endif // wxUSE_CTL3D
223 if (GetParent()->GetTransparentBackground())
224 SetBkMode(hdc
, TRANSPARENT
);
226 SetBkMode(hdc
, OPAQUE
);
228 const wxColour
& colBack
= GetBackgroundColour();
229 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
230 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
232 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
234 return (WXHBRUSH
)brush
->GetResourceHandle();
237 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
, bool *want3D
) const
239 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, want3D
);
241 // Even with extended styles, need to combine with WS_BORDER for them to
243 if ( *want3D
|| wxStyleHasBorder(m_windowStyle
) )
249 // ---------------------------------------------------------------------------
251 // ---------------------------------------------------------------------------
253 // Call this repeatedly for several wnds to find the overall size
255 // Call it initially with -1 for all values in rect.
256 // Keep calling for other widgets, and rect will be modified
257 // to calculate largest bounding rectangle.
258 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
260 int left
= rect
->left
;
261 int right
= rect
->right
;
263 int bottom
= rect
->bottom
;
265 GetWindowRect((HWND
) wnd
, rect
);
270 if (left
< rect
->left
)
273 if (right
> rect
->right
)
279 if (bottom
> rect
->bottom
)
280 rect
->bottom
= bottom
;