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 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
40 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
41 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
46 wxControl::wxControl()
48 m_backgroundColour
= *wxWHITE
;
49 m_foregroundColour
= *wxBLACK
;
51 #if WXWIN_COMPATIBILITY
53 #endif // WXWIN_COMPATIBILITY
56 wxControl::~wxControl()
58 m_isBeingDeleted
= TRUE
;
61 bool wxControl::MSWCreateControl(const wxChar
*classname
,
65 const wxString
& label
,
68 // VZ: if someone could put a comment here explaining what exactly this is
69 // needed for, it would be nice...
72 // if no extended style given, determine it ourselves
73 if ( exstyle
== (WXDWORD
)-1 )
75 exstyle
= GetExStyle(style
, &want3D
);
78 // all controls have these childs (wxWindows creates all controls visible
80 style
|= WS_CHILD
| WS_VISIBLE
;
82 m_hWnd
= (WXHWND
)::CreateWindowEx
84 exstyle
, // extended style
85 classname
, // the kind of control to create
86 label
, // the window name
87 style
, // the window style
88 pos
.x
, pos
.y
, // the window position
89 size
.x
, size
.y
, // and size
90 GetHwndOf(GetParent()), // parent
91 (HMENU
)GetId(), // child id
92 wxGetInstance(), // app instance
93 NULL
// creation parameters
99 wxLogError(wxT("Failed to create a control of class '%s'"), classname
);
108 Ctl3dSubclassCtl(GetHwnd());
111 #endif // wxUSE_CTL3D
113 // subclass again for purposes of dialog editing mode
116 // controls use the same font and colours as their parent dialog by default
122 wxSize
wxControl::DoGetBestSize()
124 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
127 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
129 #if WXWIN_COMPATIBILITY
132 (void)(*m_callback
)(this, event
);
137 #endif // WXWIN_COMPATIBILITY
139 return GetEventHandler()->ProcessEvent(event
);
143 bool wxControl::MSWOnNotify(int idCtrl
,
147 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
148 wxEventType eventType
= wxEVT_NULL
;
149 NMHDR
*hdr1
= (NMHDR
*) lParam
;
150 switch ( hdr1
->code
)
153 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
157 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
161 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
165 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
169 eventType
= wxEVT_COMMAND_SET_FOCUS
;
173 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
177 eventType
= wxEVT_COMMAND_ENTER
;
181 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
184 event
.SetEventType(eventType
);
185 event
.SetEventObject(this);
187 return GetEventHandler()->ProcessEvent(event
);
191 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
193 // In general, you don't want to erase the background of a control,
194 // or you'll get a flicker.
195 // TODO: move this 'null' function into each control that
199 ::GetClientRect(GetHwnd(), &rect
);
201 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
203 HDC hdc
= GetHdcOf((*event
.GetDC()));
204 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
206 ::FillRect(hdc
, &rect
, hBrush
);
207 ::DeleteObject(hBrush
);
208 ::SetMapMode(hdc
, mode
);
211 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
, bool *want3D
) const
213 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, want3D
);
215 // Even with extended styles, need to combine with WS_BORDER for them to
217 if ( *want3D
|| wxStyleHasBorder(m_windowStyle
) )
223 // ---------------------------------------------------------------------------
225 // ---------------------------------------------------------------------------
227 // Call this repeatedly for several wnds to find the overall size
229 // Call it initially with -1 for all values in rect.
230 // Keep calling for other widgets, and rect will be modified
231 // to calculate largest bounding rectangle.
232 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
234 int left
= rect
->left
;
235 int right
= rect
->right
;
237 int bottom
= rect
->bottom
;
239 GetWindowRect((HWND
) wnd
, rect
);
244 if (left
< rect
->left
)
247 if (right
> rect
->right
)
253 if (bottom
> rect
->bottom
)
254 rect
->bottom
= bottom
;