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
;
60 // If we delete an item, we should initialize the parent panel,
61 // because it could now be invalid.
62 wxWindow
*parent
= (wxWindow
*)GetParent();
65 if (parent
->GetDefaultItem() == (wxButton
*) this)
66 parent
->SetDefaultItem(NULL
);
70 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
72 #if WXWIN_COMPATIBILITY
75 (void)(*m_callback
)(this, event
);
80 #endif // WXWIN_COMPATIBILITY
82 return GetEventHandler()->ProcessEvent(event
);
86 bool wxControl::MSWOnNotify(int idCtrl
,
90 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
91 wxEventType eventType
= wxEVT_NULL
;
92 NMHDR
*hdr1
= (NMHDR
*) lParam
;
96 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
100 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
104 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
108 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
112 eventType
= wxEVT_COMMAND_SET_FOCUS
;
116 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
120 eventType
= wxEVT_COMMAND_ENTER
;
124 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
127 event
.SetEventType(eventType
);
128 event
.SetEventObject(this);
130 return GetEventHandler()->ProcessEvent(event
);
134 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
136 // In general, you don't want to erase the background of a control,
137 // or you'll get a flicker.
138 // TODO: move this 'null' function into each control that
142 ::GetClientRect((HWND
) GetHWND(), &rect
);
144 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
145 GetBackgroundColour().Green(),
146 GetBackgroundColour().Blue()));
147 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
149 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
150 ::DeleteObject(hBrush
);
151 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
154 // ---------------------------------------------------------------------------
156 // ---------------------------------------------------------------------------
158 // Call this repeatedly for several wnds to find the overall size
160 // Call it initially with -1 for all values in rect.
161 // Keep calling for other widgets, and rect will be modified
162 // to calculate largest bounding rectangle.
163 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
165 int left
= rect
->left
;
166 int right
= rect
->right
;
168 int bottom
= rect
->bottom
;
170 GetWindowRect((HWND
) wnd
, rect
);
175 if (left
< rect
->left
)
178 if (right
> rect
->right
)
184 if (bottom
> rect
->bottom
)
185 rect
->bottom
= bottom
;