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
, WXDWORD style
)
63 m_hWnd
= (WXHWND
)::CreateWindowEx
65 GetExStyle(style
), // extended style
66 classname
, // the kind of control to create
67 NULL
, // the window name
68 style
, // the window style
69 0, 0, 0, 0, // the window position and size
70 GetHwndOf(GetParent()), // parent
71 (HMENU
)GetId(), // child id
72 wxGetInstance(), // app instance
73 NULL
// creation parameters
79 wxLogError(T("Failed to create a control of class '%s'"), classname
);
85 // subclass again for purposes of dialog editing mode
88 // controls use the same font and colours as their parent dialog by default
94 wxSize
wxControl::DoGetBestSize()
96 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
99 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
101 #if WXWIN_COMPATIBILITY
104 (void)(*m_callback
)(this, event
);
109 #endif // WXWIN_COMPATIBILITY
111 return GetEventHandler()->ProcessEvent(event
);
115 bool wxControl::MSWOnNotify(int idCtrl
,
119 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
120 wxEventType eventType
= wxEVT_NULL
;
121 NMHDR
*hdr1
= (NMHDR
*) lParam
;
122 switch ( hdr1
->code
)
125 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
129 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
133 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
137 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
141 eventType
= wxEVT_COMMAND_SET_FOCUS
;
145 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
149 eventType
= wxEVT_COMMAND_ENTER
;
153 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
156 event
.SetEventType(eventType
);
157 event
.SetEventObject(this);
159 return GetEventHandler()->ProcessEvent(event
);
163 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
165 // In general, you don't want to erase the background of a control,
166 // or you'll get a flicker.
167 // TODO: move this 'null' function into each control that
171 ::GetClientRect((HWND
) GetHWND(), &rect
);
173 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
174 GetBackgroundColour().Green(),
175 GetBackgroundColour().Blue()));
176 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
178 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
179 ::DeleteObject(hBrush
);
180 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
183 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
) const
186 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
188 // Even with extended styles, need to combine with WS_BORDER
189 // for them to look right.
190 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
196 // ---------------------------------------------------------------------------
198 // ---------------------------------------------------------------------------
200 // Call this repeatedly for several wnds to find the overall size
202 // Call it initially with -1 for all values in rect.
203 // Keep calling for other widgets, and rect will be modified
204 // to calculate largest bounding rectangle.
205 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
207 int left
= rect
->left
;
208 int right
= rect
->right
;
210 int bottom
= rect
->bottom
;
212 GetWindowRect((HWND
) wnd
, rect
);
217 if (left
< rect
->left
)
220 if (right
> rect
->right
)
226 if (bottom
> rect
->bottom
)
227 rect
->bottom
= bottom
;