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__)
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 wxSize
wxControl::DoGetBestSize()
63 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
66 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
68 #if WXWIN_COMPATIBILITY
71 (void)(*m_callback
)(this, event
);
76 #endif // WXWIN_COMPATIBILITY
78 return GetEventHandler()->ProcessEvent(event
);
82 bool wxControl::MSWOnNotify(int idCtrl
,
86 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
87 wxEventType eventType
= wxEVT_NULL
;
88 NMHDR
*hdr1
= (NMHDR
*) lParam
;
92 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
96 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
100 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
104 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
108 eventType
= wxEVT_COMMAND_SET_FOCUS
;
112 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
116 eventType
= wxEVT_COMMAND_ENTER
;
120 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
123 event
.SetEventType(eventType
);
124 event
.SetEventObject(this);
126 return GetEventHandler()->ProcessEvent(event
);
130 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
132 // In general, you don't want to erase the background of a control,
133 // or you'll get a flicker.
134 // TODO: move this 'null' function into each control that
138 ::GetClientRect((HWND
) GetHWND(), &rect
);
140 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
141 GetBackgroundColour().Green(),
142 GetBackgroundColour().Blue()));
143 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
145 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
146 ::DeleteObject(hBrush
);
147 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
150 // ---------------------------------------------------------------------------
152 // ---------------------------------------------------------------------------
154 // Call this repeatedly for several wnds to find the overall size
156 // Call it initially with -1 for all values in rect.
157 // Keep calling for other widgets, and rect will be modified
158 // to calculate largest bounding rectangle.
159 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
161 int left
= rect
->left
;
162 int right
= rect
->right
;
164 int bottom
= rect
->bottom
;
166 GetWindowRect((HWND
) wnd
, rect
);
171 if (left
< rect
->left
)
174 if (right
> rect
->right
)
180 if (bottom
> rect
->bottom
)
181 rect
->bottom
= bottom
;